on master help sign in
Cleaner data constructor argument pointer storage in RTS
96db606Benjamin Saunders
rts/idris_gc.c+3−9
@@ -4,7 +4,6 @@
4
4
5VAL copy(VM* vm, VAL x) {
5VAL copy(VM* vm, VAL x) {
6 int i;
6 int i;
7− VAL* argptr;
8 Closure* cl = NULL;
7 Closure* cl = NULL;
9 if (x==NULL || ISINT(x)) {
8 if (x==NULL || ISINT(x)) {
10 return x;
9 return x;
@@ -15,11 +14,9 @@ VAL copy(VM* vm, VAL x) {
15 cl->info.c.tag = x->info.c.tag;
14 cl->info.c.tag = x->info.c.tag;
16 cl->info.c.arity = x->info.c.arity;
15 cl->info.c.arity = x->info.c.arity;
17
16
18− argptr = (VAL*)(cl->info.c.args);
19 for(i = 0; i < x->info.c.arity; ++i) {
17 for(i = 0; i < x->info.c.arity; ++i) {
20// *argptr = copy(vm, *((VAL*)(x->info.c.args)+i)); // recursive version
18// *argptr = copy(vm, *((VAL*)(x->info.c.args)+i)); // recursive version
21− *argptr = *((VAL*)(x->info.c.args)+i);
19+ cl->info.c.args[i] = x->info.c.args[i];
22− argptr++;
23 }
20 }
24 break;
21 break;
25 case FLOAT:
22 case FLOAT:
@@ -45,7 +42,6 @@ VAL copy(VM* vm, VAL x) {
45}
42}
46
43
47void cheney(VM *vm) {
44void cheney(VM *vm) {
48− VAL* argptr;
49 int i;
45 int i;
50 char* scan = vm->heap;
46 char* scan = vm->heap;
51
47
@@ -55,13 +51,11 @@ void cheney(VM *vm) {
55 // If it's a CON, copy its arguments
51 // If it's a CON, copy its arguments
56 switch(GETTY(heap_item)) {
52 switch(GETTY(heap_item)) {
57 case CON:
53 case CON:
58− argptr = (VAL*)(heap_item->info.c.args);
59 for(i = 0; i < heap_item->info.c.arity; ++i) {
54 for(i = 0; i < heap_item->info.c.arity; ++i) {
60 // printf("Copying %d %p\n", heap_item->info.c.tag, *argptr);
55 // 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]);
62 // printf("Got %p\t\t%p %p\n", newptr, scan, vm->heap_next);
57 // printf("Got %p\t\t%p %p\n", newptr, scan, vm->heap_next);
63− *argptr = newptr;
58+ heap_item->info.c.args[i] = newptr;
64− argptr++;
65 }
59 }
66 break;
60 break;
67 default: // Nothing to copy
61 default: // Nothing to copy
rts/idris_rts.c+5−14
@@ -111,11 +111,7 @@ void* allocCon(VM* vm, int arity, int outer) {
111 Closure* cl = allocate(vm, sizeof(Closure) + sizeof(VAL)*arity,
111 Closure* cl = allocate(vm, sizeof(Closure) + sizeof(VAL)*arity,
112 outer);
112 outer);
113 SETTY(cl, CON);
113 SETTY(cl, CON);
114− if (arity == 0) {
114+
115− cl -> info.c.args = NULL;
116− } else {
117− cl -> info.c.args = (void*)((char*)cl + sizeof(Closure));
118− }
119 cl -> info.c.arity = arity;
115 cl -> info.c.arity = arity;
120// cl -> info.c.tag = 42424242;
116// cl -> info.c.tag = 42424242;
121// printf("%p\n", cl);
117// printf("%p\n", cl);
@@ -179,13 +175,11 @@ VAL MKCON(VM* vm, VAL cl, int tag, int arity, ...) {
179// Closure* cl = allocCon(vm, arity);
175// Closure* cl = allocCon(vm, arity);
180 cl -> info.c.tag = tag;
176 cl -> info.c.tag = tag;
181 cl -> info.c.arity = arity;
177 cl -> info.c.arity = arity;
182− VAL* argptr = (VAL*)(cl -> info.c.args);
183 // printf("... %p %p\n", cl, argptr);
178 // printf("... %p %p\n", cl, argptr);
184
179
185 for (i = 0; i < arity; ++i) {
180 for (i = 0; i < arity; ++i) {
186− VAL v = va_arg(args, VAL);
181+ VAL v = va_arg(args, VAL);
187− *argptr = v;
182+ cl->info.c.args[i] = v;
188− argptr++;
189 }
183 }
190 va_end(args);
184 va_end(args);
191 return cl;
185 return cl;
@@ -193,10 +187,8 @@ VAL MKCON(VM* vm, VAL cl, int tag, int arity, ...) {
193
187
194void PROJECT(VM* vm, VAL r, int loc, int arity) {
188void PROJECT(VM* vm, VAL r, int loc, int arity) {
195 int i;
189 int i;
196− VAL* argptr = (VAL*)(r -> info.c.args);
197−
198 for(i = 0; i < arity; ++i) {
190 for(i = 0; i < arity; ++i) {
199− LOC(i+loc) = *argptr++;
191+ LOC(i+loc) = r->info.c.args[i];
200 }
192 }
201}
193}
202
194
@@ -233,8 +225,7 @@ void dumpVal(VAL v) {
233 case CON:
225 case CON:
234 printf("%d[", v->info.c.tag);
226 printf("%d[", v->info.c.tag);
235 for(i = 0; i < v->info.c.arity; ++i) {
227 for(i = 0; i < v->info.c.arity; ++i) {
236− VAL* args = (VAL*)v->info.c.args;
228+ dumpVal(v->info.c.args[i]);
237− dumpVal(args[i]);
238 }
229 }
239 printf("] ");
230 printf("] ");
240 break;
231 break;
rts/idris_rts.h+6−6
@@ -14,13 +14,15 @@ typedef enum {
14 CON, INT, BIGINT, FLOAT, STRING, UNIT, PTR, FWD
14 CON, INT, BIGINT, FLOAT, STRING, UNIT, PTR, FWD
15} ClosureType;
15} ClosureType;
16
16
17+typedef struct Closure *VAL;
18+
17typedef struct {
19typedef struct {
18 int tag;
20 int tag;
19 int arity;
21 int arity;
20− void* args;
22+ VAL args[];
21} con;
23} con;
22
24
23−typedef struct {
25+typedef struct Closure {
24// Use top 16 bits of ty for saying which heap value is in
26// Use top 16 bits of ty for saying which heap value is in
25// Bottom 16 bits for closure type
27// Bottom 16 bits for closure type
26 ClosureType ty;
28 ClosureType ty;
@@ -33,8 +35,6 @@ typedef struct {
33 } info;
35 } info;
34} Closure;
36} Closure;
35
37
36−typedef Closure* VAL;
37−
38typedef struct {
38typedef struct {
39 VAL* valstack;
39 VAL* valstack;
40 int* intstack;
40 int* intstack;
@@ -150,8 +150,8 @@ VAL MKPTRc(VM* vm, void* ptr);
150VAL MKCON(VM* vm, VAL cl, int tag, int arity, ...);
150VAL MKCON(VM* vm, VAL cl, int tag, int arity, ...);
151
151
152#define SETTAG(x, a) (x)->info.c.tag = (a)
152#define SETTAG(x, a) (x)->info.c.tag = (a)
153−#define SETARG(x, i, a) ((VAL*)((x)->info.c.args))[i] = ((VAL)(a))
153+#define SETARG(x, i, a) ((x)->info.c.args)[i] = ((VAL)(a))
154−#define GETARG(x, i) ((VAL*)((x)->info.c.args))[i]
154+#define GETARG(x, i) ((x)->info.c.args)[i]
155
155
156void PROJECT(VM* vm, VAL r, int loc, int arity);
156void PROJECT(VM* vm, VAL r, int loc, int arity);
157void SLIDE(VM* vm, int args);
157void SLIDE(VM* vm, int args);