on master help sign in
Cleaner data constructor argument pointer storage in RTS
commit96db606dde63a41db119b65f470b357b86a22e52 authorBenjamin Saunders <besaunde@sfu.ca> dateWed 31 Oct 2012, 22:12 (14 years ago) parentf9a1dab
3 files changed+14−29
rts/idris_gc.c+3−9 rts/idris_rts.c+5−14 rts/idris_rts.h+6−6
rts/idris_gc.c+3−9
@@ -4,7 +4,6 @@
44
55VAL copy(VM* vm, VAL x) {
66 int i;
7− VAL* argptr;
87 Closure* cl = NULL;
98 if (x==NULL || ISINT(x)) {
109 return x;
@@ -15,11 +14,9 @@ VAL copy(VM* vm, VAL x) {
1514 cl->info.c.tag = x->info.c.tag;
1615 cl->info.c.arity = x->info.c.arity;
1716
18− argptr = (VAL*)(cl->info.c.args);
1917 for(i = 0; i < x->info.c.arity; ++i) {
2018// *argptr = copy(vm, *((VAL*)(x->info.c.args)+i)); // recursive version
21− *argptr = *((VAL*)(x->info.c.args)+i);
22− argptr++;
19+ cl->info.c.args[i] = x->info.c.args[i];
2320 }
2421 break;
2522 case FLOAT:
@@ -45,7 +42,6 @@ VAL copy(VM* vm, VAL x) {
4542}
4643
4744void cheney(VM *vm) {
48− VAL* argptr;
4945 int i;
5046 char* scan = vm->heap;
5147
@@ -55,13 +51,11 @@ void cheney(VM *vm) {
5551 // If it's a CON, copy its arguments
5652 switch(GETTY(heap_item)) {
5753 case CON:
58− argptr = (VAL*)(heap_item->info.c.args);
5954 for(i = 0; i < heap_item->info.c.arity; ++i) {
6055 // printf("Copying %d %p\n", heap_item->info.c.tag, *argptr);
61− VAL newptr = copy(vm, *argptr);
56+ VAL newptr = copy(vm, heap_item->info.c.args[i]);
6257 // printf("Got %p\t\t%p %p\n", newptr, scan, vm->heap_next);
63− *argptr = newptr;
64− argptr++;
58+ heap_item->info.c.args[i] = newptr;
6559 }
6660 break;
6761 default: // Nothing to copy
rts/idris_rts.c+5−14
@@ -111,11 +111,7 @@ void* allocCon(VM* vm, int arity, int outer) {
111111 Closure* cl = allocate(vm, sizeof(Closure) + sizeof(VAL)*arity,
112112 outer);
113113 SETTY(cl, CON);
114− if (arity == 0) {
115− cl -> info.c.args = NULL;
116− } else {
117− cl -> info.c.args = (void*)((char*)cl + sizeof(Closure));
118− }
114+
119115 cl -> info.c.arity = arity;
120116// cl -> info.c.tag = 42424242;
121117// printf("%p\n", cl);
@@ -179,13 +175,11 @@ VAL MKCON(VM* vm, VAL cl, int tag, int arity, ...) {
179175// Closure* cl = allocCon(vm, arity);
180176 cl -> info.c.tag = tag;
181177 cl -> info.c.arity = arity;
182− VAL* argptr = (VAL*)(cl -> info.c.args);
183178 // printf("... %p %p\n", cl, argptr);
184179
185180 for (i = 0; i < arity; ++i) {
186− VAL v = va_arg(args, VAL);
187− *argptr = v;
188− argptr++;
181+ VAL v = va_arg(args, VAL);
182+ cl->info.c.args[i] = v;
189183 }
190184 va_end(args);
191185 return cl;
@@ -193,10 +187,8 @@ VAL MKCON(VM* vm, VAL cl, int tag, int arity, ...) {
193187
194188void PROJECT(VM* vm, VAL r, int loc, int arity) {
195189 int i;
196− VAL* argptr = (VAL*)(r -> info.c.args);
197−
198190 for(i = 0; i < arity; ++i) {
199− LOC(i+loc) = *argptr++;
191+ LOC(i+loc) = r->info.c.args[i];
200192 }
201193}
202194
@@ -233,8 +225,7 @@ void dumpVal(VAL v) {
233225 case CON:
234226 printf("%d[", v->info.c.tag);
235227 for(i = 0; i < v->info.c.arity; ++i) {
236− VAL* args = (VAL*)v->info.c.args;
237− dumpVal(args[i]);
228+ dumpVal(v->info.c.args[i]);
238229 }
239230 printf("] ");
240231 break;
rts/idris_rts.h+6−6
@@ -14,13 +14,15 @@ typedef enum {
1414 CON, INT, BIGINT, FLOAT, STRING, UNIT, PTR, FWD
1515} ClosureType;
1616
17+typedef struct Closure *VAL;
18+
1719typedef struct {
1820 int tag;
1921 int arity;
20− void* args;
22+ VAL args[];
2123} con;
2224
23−typedef struct {
25+typedef struct Closure {
2426// Use top 16 bits of ty for saying which heap value is in
2527// Bottom 16 bits for closure type
2628 ClosureType ty;
@@ -33,8 +35,6 @@ typedef struct {
3335 } info;
3436} Closure;
3537
36−typedef Closure* VAL;
37−
3838typedef struct {
3939 VAL* valstack;
4040 int* intstack;
@@ -150,8 +150,8 @@ VAL MKPTRc(VM* vm, void* ptr);
150150VAL MKCON(VM* vm, VAL cl, int tag, int arity, ...);
151151
152152#define SETTAG(x, a) (x)->info.c.tag = (a)
153−#define SETARG(x, i, a) ((VAL*)((x)->info.c.args))[i] = ((VAL)(a))
154−#define GETARG(x, i) ((VAL*)((x)->info.c.args))[i]
153+#define SETARG(x, i, a) ((x)->info.c.args)[i] = ((VAL)(a))
154+#define GETARG(x, i) ((x)->info.c.args)[i]
155155
156156void PROJECT(VM* vm, VAL r, int loc, int arity);
157157void SLIDE(VM* vm, int args);