last known issues...now waiting to test
[IRC.git] / Robust / src / Runtime / localobjects.c
1 #include "localobjects.h"
2 #include <string.h>
3
4 void REVERT_OBJ(struct ___Object___ * obj) {
5   int type=((int *)obj)[0];
6   struct ___Object___ * copyobj=obj->___localcopy___;
7   if(((int)copyobj)==1) {
8     obj->___localcopy___=NULL;
9     obj->___nextobject___=NULL;
10   } else if (type<NUMCLASSES) {
11     /* We have a normal object */
12     int size=classsize[type];
13     memcpy(obj, copyobj, size);
14   } else {
15     /* We have an array */
16     struct ArrayObject *ao=(struct ArrayObject *)obj;
17     int elementsize=classsize[type];
18     int length=ao->___length___;
19     int size=sizeof(struct ArrayObject)+length*elementsize;
20     memcpy(obj, copyobj, size);
21   }
22 }
23
24 #ifdef PRECISE_GC
25 void COPY_OBJ(struct garbagelist * gl, struct ___Object___ *obj) {
26 #else
27 void COPY_OBJ(struct ___Object___ *obj) {
28 #endif
29   int type=((int *)obj)[0];
30   if (type<NUMCLASSES) {
31     /* We have a normal object */
32     int size=classsize[type];
33 #ifdef PRECISE_GC
34     int ptrarray[]={1, (int) gl, (int) obj};
35     struct ___Object___ * newobj=mygcmalloc((struct garbagelist *)ptrarray, size);
36 #else
37     struct ___Object___ * newobj=FREEMALLOC(size);
38 #endif
39 #ifdef PRECISE_GC
40     memcpy(newobj, (struct ___Object___ *) ptrarray[2], size);
41     ((struct ___Object___*)ptrarray[2])->___localcopy___=newobj;
42 #else
43     memcpy(newobj, obj, size);
44     obj->___localcopy___=newobj;
45 #endif
46   } else {
47     /* We have an array */
48     struct ArrayObject *ao=(struct ArrayObject *)obj;
49     int elementsize=classsize[type];
50     int length=ao->___length___;
51     int size=sizeof(struct ArrayObject)+length*elementsize;
52 #ifdef PRECISE_GC
53     int ptrarray[]={1, (int) gl, (int) obj};
54     struct ___Object___ * newobj=mygcmalloc((struct garbagelist *)ptrarray, size);
55 #else
56     struct ___Object___ * newobj=FREEMALLOC(size);
57 #endif
58 #ifdef PRECISE_GC
59     memcpy(newobj, (struct ___Object___ *) ptrarray[2], size);
60     ((struct ___Object___*)ptrarray[2])->___localcopy___=newobj;
61 #else
62     memcpy(newobj, obj, size);
63     obj->___localcopy___=newobj;
64 #endif
65   }
66 }