on master help sign in
Fix allocation size
13e17a4Edwin Brady
Makefile+1−1
@@ -19,7 +19,7 @@ relib: .PHONY
19 make -C lib IDRIS=../dist/build/idris/idris
19 make -C lib IDRIS=../dist/build/idris/idris
20
20
21linecount : .PHONY
21linecount : .PHONY
22− wc -l src/Idris/*.hs src/Core/*.hs src/RTS/*.hs
22+ wc -l src/Idris/*.hs src/Core/*.hs src/IRTS/*.hs
23
23
24.PHONY:
24.PHONY:
25
25
rts/idris_gmp.c+1−1
@@ -196,7 +196,7 @@ VAL idris_bigLt(VM* vm, VAL x, VAL y) {
196
196
197VAL idris_bigLe(VM* vm, VAL x, VAL y) {
197VAL idris_bigLe(VM* vm, VAL x, VAL y) {
198 if (ISINT(x) && ISINT(y)) {
198 if (ISINT(x) && ISINT(y)) {
199− return MKINT((i_int)GETINT(x) <= GETINT(y));
199+ return MKINT((i_int)(GETINT(x) <= GETINT(y)));
200 } else {
200 } else {
201 return bigLe(vm, x, y);
201 return bigLe(vm, x, y);
202 }
202 }
rts/idris_rts.c+13−15
@@ -50,36 +50,35 @@ void* allocate(VM* vm, size_t size) {
50}
50}
51
51
52void* allocCon(VM* vm, int arity) {
52void* allocCon(VM* vm, int arity) {
53− Closure* cl = allocate(vm, sizeof(ClosureType) +
53+ Closure* cl = allocate(vm, sizeof(Closure) + sizeof(VAL)*arity);
54− sizeof(con) + sizeof(VAL)*arity);
55 cl -> ty = CON;
54 cl -> ty = CON;
56 if (arity == 0) {
55 if (arity == 0) {
57 cl -> info.c.args = NULL;
56 cl -> info.c.args = NULL;
58 } else {
57 } else {
59− cl -> info.c.args = (void*)((char*)cl + sizeof(ClosureType)
58+ cl -> info.c.args = (void*)((char*)cl + sizeof(Closure));
60− + sizeof(con));
61 }
59 }
62 return (void*)cl;
60 return (void*)cl;
63}
61}
64
62
65VAL MKFLOAT(VM* vm, double val) {
63VAL MKFLOAT(VM* vm, double val) {
66− Closure* cl = allocate(vm, sizeof(ClosureType) + sizeof(double));
64+ Closure* cl = allocate(vm, sizeof(Closure));
67 cl -> ty = FLOAT;
65 cl -> ty = FLOAT;
68 cl -> info.f = val;
66 cl -> info.f = val;
69 return cl;
67 return cl;
70}
68}
71
69
72VAL MKSTR(VM* vm, char* str) {
70VAL MKSTR(VM* vm, char* str) {
73− Closure* cl = allocate(vm, sizeof(ClosureType) + sizeof(char*) +
71+ Closure* cl = allocate(vm, sizeof(Closure) + // Type) + sizeof(char*) +
74 sizeof(char)*strlen(str)+1);
72 sizeof(char)*strlen(str)+1);
75 cl -> ty = STRING;
73 cl -> ty = STRING;
76− cl -> info.str = (char*)cl + sizeof(ClosureType) + sizeof(char*);
74+ cl -> info.str = (char*)cl + sizeof(Closure);
75+
77 strcpy(cl -> info.str, str);
76 strcpy(cl -> info.str, str);
78 return cl;
77 return cl;
79}
78}
80
79
81VAL MKPTR(VM* vm, void* ptr) {
80VAL MKPTR(VM* vm, void* ptr) {
82− Closure* cl = allocate(vm, sizeof(ClosureType) + sizeof(void*));
81+ Closure* cl = allocate(vm, sizeof(Closure));
83 cl -> ty = PTR;
82 cl -> ty = PTR;
84 cl -> info.ptr = ptr;
83 cl -> info.ptr = ptr;
85 return cl;
84 return cl;
@@ -138,9 +137,9 @@ void dumpVal(VAL v) {
138}
137}
139
138
140VAL idris_castIntStr(VM* vm, VAL i) {
139VAL idris_castIntStr(VM* vm, VAL i) {
141− Closure* cl = allocate(vm, sizeof(ClosureType) + sizeof(char*) + sizeof(char)*16);
140+ Closure* cl = allocate(vm, sizeof(Closure) + sizeof(char)*16);
142 cl -> ty = STRING;
141 cl -> ty = STRING;
143− cl -> info.str = (char*)cl + sizeof(ClosureType) + sizeof(char*);
142+ cl -> info.str = (char*)cl + sizeof(Closure);
144 sprintf(cl -> info.str, "%ld", GETINT(i));
143 sprintf(cl -> info.str, "%ld", GETINT(i));
145 return cl;
144 return cl;
146}
145}
@@ -152,9 +151,9 @@ VAL idris_castStrInt(VM* vm, VAL i) {
152}
151}
153
152
154VAL idris_castFloatStr(VM* vm, VAL i) {
153VAL idris_castFloatStr(VM* vm, VAL i) {
155− Closure* cl = allocate(vm, sizeof(ClosureType) + sizeof(char*) + sizeof(char)*32);
154+ Closure* cl = allocate(vm, sizeof(Closure) + sizeof(char)*32);
156 cl -> ty = STRING;
155 cl -> ty = STRING;
157− cl -> info.str = (char*)cl + sizeof(ClosureType) + sizeof(char*);
156+ cl -> info.str = (char*)cl + sizeof(Closure);
158 sprintf(cl -> info.str, "%g", GETFLOAT(i));
157 sprintf(cl -> info.str, "%g", GETFLOAT(i));
159 return cl;
158 return cl;
160}
159}
@@ -166,15 +165,14 @@ VAL idris_castStrFloat(VM* vm, VAL i) {
166VAL idris_concat(VM* vm, VAL l, VAL r) {
165VAL idris_concat(VM* vm, VAL l, VAL r) {
167 char *ls = GETSTR(l);
166 char *ls = GETSTR(l);
168 char *rs = GETSTR(r);
167 char *rs = GETSTR(r);
169− Closure* cl = allocate(vm, sizeof(ClosureType) + sizeof(char*) +
168+ Closure* cl = allocate(vm, sizeof(Closure) + strlen(ls) + strlen(rs) + 1);
170− strlen(ls) + strlen(rs) + 1);
171 // Oops! problem if the second allocate triggers a gc because cl has
169 // Oops! problem if the second allocate triggers a gc because cl has
172 // to be a root. Fix by allocating all in one go.
170 // to be a root. Fix by allocating all in one go.
173
171
174 // Also note that l/r may be in from space, so don't delete after collection,
172 // Also note that l/r may be in from space, so don't delete after collection,
175 // rather, delete just before the next collection.
173 // rather, delete just before the next collection.
176 cl -> ty = STRING;
174 cl -> ty = STRING;
177− cl -> info.str = (char*)cl + sizeof(ClosureType) + sizeof(char*);
175+ cl -> info.str = (char*)cl + sizeof(Closure);
178 strcpy(cl -> info.str, ls);
176 strcpy(cl -> info.str, ls);
179 strcat(cl -> info.str, rs);
177 strcat(cl -> info.str, rs);
180 return cl;
178 return cl;