on master help sign in
Use idris_alloc for GMP allocation

Now storing VM in a pthread_key (in environments which support pthreads) meaning that allocation doesn't need to be passed a VM pointer, and so we can safely use the idris allocator from GMP (and indeed any C library which wants to use it).

commitf7b72a6732e1d1a65d1ab35d83111ff2c89c6f2e authorEdwin Brady <ecb10@st-andrews.ac.uk> dateThu 18 Dec 2014, 00:09 (12 years ago) parent4108ad3
8 files changed+247−160
rts/idris_bitstring.c+86−86 rts/idris_gc.c+3−2 rts/idris_gmp.c+46−15 rts/idris_gmp.h+3 rts/idris_main.c+7−2 rts/idris_rts.c+82−35 rts/idris_rts.h+19−19 src/IRTS/CodegenC.hs+1−1
rts/idris_bitstring.c+86−86
@@ -2,7 +2,7 @@
22
33VAL idris_b8CopyForGC(VM *vm, VAL a) {
44 uint8_t A = a->info.bits8;
5− VAL cl = allocate(vm, sizeof(Closure), 1);
5+ VAL cl = allocate(sizeof(Closure), 1);
66 SETTY(cl, BITS8);
77 cl->info.bits8 = A;
88 return cl;
@@ -10,7 +10,7 @@ VAL idris_b8CopyForGC(VM *vm, VAL a) {
1010
1111VAL idris_b16CopyForGC(VM *vm, VAL a) {
1212 uint16_t A = a->info.bits16;
13− VAL cl = allocate(vm, sizeof(Closure), 1);
13+ VAL cl = allocate(sizeof(Closure), 1);
1414 SETTY(cl, BITS16);
1515 cl->info.bits16 = A;
1616 return cl;
@@ -18,7 +18,7 @@ VAL idris_b16CopyForGC(VM *vm, VAL a) {
1818
1919VAL idris_b32CopyForGC(VM *vm, VAL a) {
2020 uint32_t A = a->info.bits32;
21− VAL cl = allocate(vm, sizeof(Closure), 1);
21+ VAL cl = allocate(sizeof(Closure), 1);
2222 SETTY(cl, BITS32);
2323 cl->info.bits32 = A;
2424 return cl;
@@ -26,7 +26,7 @@ VAL idris_b32CopyForGC(VM *vm, VAL a) {
2626
2727VAL idris_b64CopyForGC(VM *vm, VAL a) {
2828 uint64_t A = a->info.bits64;
29− VAL cl = allocate(vm, sizeof(Closure), 1);
29+ VAL cl = allocate(sizeof(Closure), 1);
3030 SETTY(cl, BITS64);
3131 cl->info.bits64 = A;
3232 return cl;
@@ -34,7 +34,7 @@ VAL idris_b64CopyForGC(VM *vm, VAL a) {
3434
3535VAL idris_b8(VM *vm, VAL a) {
3636 uint8_t A = GETINT(a);
37− VAL cl = allocate(vm, sizeof(Closure), 0);
37+ VAL cl = allocate(sizeof(Closure), 0);
3838 SETTY(cl, BITS8);
3939 cl->info.bits8 = (uint8_t) A;
4040 return cl;
@@ -42,7 +42,7 @@ VAL idris_b8(VM *vm, VAL a) {
4242
4343VAL idris_b16(VM *vm, VAL a) {
4444 uint16_t A = GETINT(a);
45− VAL cl = allocate(vm, sizeof(Closure), 0);
45+ VAL cl = allocate(sizeof(Closure), 0);
4646 SETTY(cl, BITS16);
4747 cl->info.bits16 = (uint16_t) A;
4848 return cl;
@@ -50,7 +50,7 @@ VAL idris_b16(VM *vm, VAL a) {
5050
5151VAL idris_b32(VM *vm, VAL a) {
5252 uint32_t A = GETINT(a);
53− VAL cl = allocate(vm, sizeof(Closure), 0);
53+ VAL cl = allocate(sizeof(Closure), 0);
5454 SETTY(cl, BITS32);
5555 cl->info.bits32 = (uint32_t) A;
5656 return cl;
@@ -58,7 +58,7 @@ VAL idris_b32(VM *vm, VAL a) {
5858
5959VAL idris_b64(VM *vm, VAL a) {
6060 uint64_t A = GETINT(a);
61− VAL cl = allocate(vm, sizeof(Closure), 0);
61+ VAL cl = allocate(sizeof(Closure), 0);
6262 SETTY(cl, BITS64);
6363 cl->info.bits64 = (uint64_t) A;
6464 return cl;
@@ -69,28 +69,28 @@ VAL idris_castB32Int(VM *vm, VAL a) {
6969}
7070
7171VAL idris_b8const(VM *vm, uint8_t a) {
72− VAL cl = allocate(vm, sizeof(Closure), 0);
72+ VAL cl = allocate(sizeof(Closure), 0);
7373 SETTY(cl, BITS8);
7474 cl->info.bits8 = a;
7575 return cl;
7676}
7777
7878VAL idris_b16const(VM *vm, uint16_t a) {
79− VAL cl = allocate(vm, sizeof(Closure), 0);
79+ VAL cl = allocate(sizeof(Closure), 0);
8080 SETTY(cl, BITS16);
8181 cl->info.bits16 = a;
8282 return cl;
8383}
8484
8585VAL idris_b32const(VM *vm, uint32_t a) {
86− VAL cl = allocate(vm, sizeof(Closure), 0);
86+ VAL cl = allocate(sizeof(Closure), 0);
8787 SETTY(cl, BITS32);
8888 cl->info.bits32 = a;
8989 return cl;
9090}
9191
9292VAL idris_b64const(VM *vm, uint64_t a) {
93− VAL cl = allocate(vm, sizeof(Closure), 0);
93+ VAL cl = allocate(sizeof(Closure), 0);
9494 SETTY(cl, BITS64);
9595 cl->info.bits64 = a;
9696 return cl;
@@ -99,7 +99,7 @@ VAL idris_b64const(VM *vm, uint64_t a) {
9999VAL idris_b8Plus(VM *vm, VAL a, VAL b) {
100100 uint8_t A = a->info.bits8;
101101 uint8_t B = b->info.bits8;
102− VAL cl = allocate(vm, sizeof(Closure), 0);
102+ VAL cl = allocate(sizeof(Closure), 0);
103103 SETTY(cl, BITS8);
104104 cl->info.bits8 = A + B;
105105 return cl;
@@ -108,7 +108,7 @@ VAL idris_b8Plus(VM *vm, VAL a, VAL b) {
108108VAL idris_b8Minus(VM *vm, VAL a, VAL b) {
109109 uint8_t A = a->info.bits8;
110110 uint8_t B = b->info.bits8;
111− VAL cl = allocate(vm, sizeof(Closure), 0);
111+ VAL cl = allocate(sizeof(Closure), 0);
112112 SETTY(cl, BITS8);
113113 cl->info.bits8 = A - B;
114114 return cl;
@@ -117,7 +117,7 @@ VAL idris_b8Minus(VM *vm, VAL a, VAL b) {
117117VAL idris_b8Times(VM *vm, VAL a, VAL b) {
118118 uint8_t A = a->info.bits8;
119119 uint8_t B = b->info.bits8;
120− VAL cl = allocate(vm, sizeof(Closure), 0);
120+ VAL cl = allocate(sizeof(Closure), 0);
121121 SETTY(cl, BITS8);
122122 cl->info.bits8 = A * B;
123123 return cl;
@@ -126,7 +126,7 @@ VAL idris_b8Times(VM *vm, VAL a, VAL b) {
126126VAL idris_b8UDiv(VM *vm, VAL a, VAL b) {
127127 uint8_t A = a->info.bits8;
128128 uint8_t B = b->info.bits8;
129− VAL cl = allocate(vm, sizeof(Closure), 0);
129+ VAL cl = allocate(sizeof(Closure), 0);
130130 SETTY(cl, BITS8);
131131 cl->info.bits8 = A / B;
132132 return cl;
@@ -135,7 +135,7 @@ VAL idris_b8UDiv(VM *vm, VAL a, VAL b) {
135135VAL idris_b8SDiv(VM *vm, VAL a, VAL b) {
136136 uint8_t A = a->info.bits8;
137137 uint8_t B = b->info.bits8;
138− VAL cl = allocate(vm, sizeof(Closure), 0);
138+ VAL cl = allocate(sizeof(Closure), 0);
139139 SETTY(cl, BITS8);
140140 cl->info.bits8 = (uint8_t) (((int8_t) A) / ((int8_t) B));
141141 return cl;
@@ -144,7 +144,7 @@ VAL idris_b8SDiv(VM *vm, VAL a, VAL b) {
144144VAL idris_b8URem(VM *vm, VAL a, VAL b) {
145145 uint8_t A = a->info.bits8;
146146 uint8_t B = b->info.bits8;
147− VAL cl = allocate(vm, sizeof(Closure), 0);
147+ VAL cl = allocate(sizeof(Closure), 0);
148148 SETTY(cl, BITS8);
149149 cl->info.bits8 = A % B;
150150 return cl;
@@ -153,7 +153,7 @@ VAL idris_b8URem(VM *vm, VAL a, VAL b) {
153153VAL idris_b8SRem(VM *vm, VAL a, VAL b) {
154154 uint8_t A = a->info.bits8;
155155 uint8_t B = b->info.bits8;
156− VAL cl = allocate(vm, sizeof(Closure), 0);
156+ VAL cl = allocate(sizeof(Closure), 0);
157157 SETTY(cl, BITS8);
158158 cl->info.bits8 = (uint8_t) (((int8_t) A) % ((int8_t) B));
159159 return cl;
@@ -181,7 +181,7 @@ VAL idris_b8Gte(VM *vm, VAL a, VAL b) {
181181
182182VAL idris_b8Compl(VM *vm, VAL a) {
183183 uint8_t A = a->info.bits8;
184− VAL cl = allocate(vm, sizeof(Closure), 0);
184+ VAL cl = allocate(sizeof(Closure), 0);
185185 SETTY(cl, BITS8);
186186 cl->info.bits8 = ~ A;
187187 return cl;
@@ -190,7 +190,7 @@ VAL idris_b8Compl(VM *vm, VAL a) {
190190VAL idris_b8And(VM *vm, VAL a, VAL b) {
191191 uint8_t A = a->info.bits8;
192192 uint8_t B = b->info.bits8;
193− VAL cl = allocate(vm, sizeof(Closure), 0);
193+ VAL cl = allocate(sizeof(Closure), 0);
194194 SETTY(cl, BITS8);
195195 cl->info.bits8 = A & B;
196196 return cl;
@@ -199,7 +199,7 @@ VAL idris_b8And(VM *vm, VAL a, VAL b) {
199199VAL idris_b8Or(VM *vm, VAL a, VAL b) {
200200 uint8_t A = a->info.bits8;
201201 uint8_t B = b->info.bits8;
202− VAL cl = allocate(vm, sizeof(Closure), 0);
202+ VAL cl = allocate(sizeof(Closure), 0);
203203 SETTY(cl, BITS8);
204204 cl->info.bits8 = A | B;
205205 return cl;
@@ -208,7 +208,7 @@ VAL idris_b8Or(VM *vm, VAL a, VAL b) {
208208VAL idris_b8Xor(VM *vm, VAL a, VAL b) {
209209 uint8_t A = a->info.bits8;
210210 uint8_t B = b->info.bits8;
211− VAL cl = allocate(vm, sizeof(Closure), 0);
211+ VAL cl = allocate(sizeof(Closure), 0);
212212 SETTY(cl, BITS8);
213213 cl->info.bits8 = A ^ B;
214214 return cl;
@@ -217,7 +217,7 @@ VAL idris_b8Xor(VM *vm, VAL a, VAL b) {
217217VAL idris_b8Shl(VM *vm, VAL a, VAL b) {
218218 uint8_t A = a->info.bits8;
219219 uint8_t B = b->info.bits8;
220− VAL cl = allocate(vm, sizeof(Closure), 0);
220+ VAL cl = allocate(sizeof(Closure), 0);
221221 SETTY(cl, BITS8);
222222 cl->info.bits8 = A << B;
223223 return cl;
@@ -226,7 +226,7 @@ VAL idris_b8Shl(VM *vm, VAL a, VAL b) {
226226VAL idris_b8LShr(VM *vm, VAL a, VAL b) {
227227 uint8_t A = a->info.bits8;
228228 uint8_t B = b->info.bits8;
229− VAL cl = allocate(vm, sizeof(Closure), 0);
229+ VAL cl = allocate(sizeof(Closure), 0);
230230 SETTY(cl, BITS8);
231231 cl->info.bits8 = A >> B;
232232 return cl;
@@ -235,7 +235,7 @@ VAL idris_b8LShr(VM *vm, VAL a, VAL b) {
235235VAL idris_b8AShr(VM *vm, VAL a, VAL b) {
236236 uint8_t A = a->info.bits8;
237237 uint8_t B = b->info.bits8;
238− VAL cl = allocate(vm, sizeof(Closure), 0);
238+ VAL cl = allocate(sizeof(Closure), 0);
239239 SETTY(cl, BITS8);
240240 cl->info.bits8 = (uint8_t) (((int8_t) A) >> ((int8_t) B));
241241 return cl;
@@ -244,7 +244,7 @@ VAL idris_b8AShr(VM *vm, VAL a, VAL b) {
244244VAL idris_b16Plus(VM *vm, VAL a, VAL b) {
245245 uint16_t A = a->info.bits16;
246246 uint16_t B = b->info.bits16;
247− VAL cl = allocate(vm, sizeof(Closure), 0);
247+ VAL cl = allocate(sizeof(Closure), 0);
248248 SETTY(cl, BITS16);
249249 cl->info.bits16 = A + B;
250250 return cl;
@@ -253,7 +253,7 @@ VAL idris_b16Plus(VM *vm, VAL a, VAL b) {
253253VAL idris_b16Minus(VM *vm, VAL a, VAL b) {
254254 uint16_t A = a->info.bits16;
255255 uint16_t B = b->info.bits16;
256− VAL cl = allocate(vm, sizeof(Closure), 0);
256+ VAL cl = allocate(sizeof(Closure), 0);
257257 SETTY(cl, BITS16);
258258 cl->info.bits16 = A - B;
259259 return cl;
@@ -262,7 +262,7 @@ VAL idris_b16Minus(VM *vm, VAL a, VAL b) {
262262VAL idris_b16Times(VM *vm, VAL a, VAL b) {
263263 uint16_t A = a->info.bits16;
264264 uint16_t B = b->info.bits16;
265− VAL cl = allocate(vm, sizeof(Closure), 0);
265+ VAL cl = allocate(sizeof(Closure), 0);
266266 SETTY(cl, BITS16);
267267 cl->info.bits16 = A * B;
268268 return cl;
@@ -271,7 +271,7 @@ VAL idris_b16Times(VM *vm, VAL a, VAL b) {
271271VAL idris_b16UDiv(VM *vm, VAL a, VAL b) {
272272 uint16_t A = a->info.bits16;
273273 uint16_t B = b->info.bits16;
274− VAL cl = allocate(vm, sizeof(Closure), 0);
274+ VAL cl = allocate(sizeof(Closure), 0);
275275 SETTY(cl, BITS16);
276276 cl->info.bits16 = A / B;
277277 return cl;
@@ -280,7 +280,7 @@ VAL idris_b16UDiv(VM *vm, VAL a, VAL b) {
280280VAL idris_b16SDiv(VM *vm, VAL a, VAL b) {
281281 uint16_t A = a->info.bits16;
282282 uint16_t B = b->info.bits16;
283− VAL cl = allocate(vm, sizeof(Closure), 0);
283+ VAL cl = allocate(sizeof(Closure), 0);
284284 SETTY(cl, BITS16);
285285 cl->info.bits16 = (uint16_t) (((int16_t) A) / ((int16_t) B));
286286 return cl;
@@ -289,7 +289,7 @@ VAL idris_b16SDiv(VM *vm, VAL a, VAL b) {
289289VAL idris_b16URem(VM *vm, VAL a, VAL b) {
290290 uint16_t A = a->info.bits16;
291291 uint16_t B = b->info.bits16;
292− VAL cl = allocate(vm, sizeof(Closure), 0);
292+ VAL cl = allocate(sizeof(Closure), 0);
293293 SETTY(cl, BITS16);
294294 cl->info.bits16 = A % B;
295295 return cl;
@@ -298,7 +298,7 @@ VAL idris_b16URem(VM *vm, VAL a, VAL b) {
298298VAL idris_b16SRem(VM *vm, VAL a, VAL b) {
299299 uint16_t A = a->info.bits16;
300300 uint16_t B = b->info.bits16;
301− VAL cl = allocate(vm, sizeof(Closure), 0);
301+ VAL cl = allocate(sizeof(Closure), 0);
302302 SETTY(cl, BITS16);
303303 cl->info.bits16 = (uint16_t) (((int16_t) A) % ((int16_t) B));
304304 return cl;
@@ -326,7 +326,7 @@ VAL idris_b16Gte(VM *vm, VAL a, VAL b) {
326326
327327VAL idris_b16Compl(VM *vm, VAL a) {
328328 uint16_t A = a->info.bits16;
329− VAL cl = allocate(vm, sizeof(Closure), 0);
329+ VAL cl = allocate(sizeof(Closure), 0);
330330 SETTY(cl, BITS16);
331331 cl->info.bits16 = ~ A;
332332 return cl;
@@ -335,7 +335,7 @@ VAL idris_b16Compl(VM *vm, VAL a) {
335335VAL idris_b16And(VM *vm, VAL a, VAL b) {
336336 uint16_t A = a->info.bits16;
337337 uint16_t B = b->info.bits16;
338− VAL cl = allocate(vm, sizeof(Closure), 0);
338+ VAL cl = allocate(sizeof(Closure), 0);
339339 SETTY(cl, BITS16);
340340 cl->info.bits16 = A & B;
341341 return cl;
@@ -344,7 +344,7 @@ VAL idris_b16And(VM *vm, VAL a, VAL b) {
344344VAL idris_b16Or(VM *vm, VAL a, VAL b) {
345345 uint16_t A = a->info.bits16;
346346 uint16_t B = b->info.bits16;
347− VAL cl = allocate(vm, sizeof(Closure), 0);
347+ VAL cl = allocate(sizeof(Closure), 0);
348348 SETTY(cl, BITS16);
349349 cl->info.bits16 = A | B;
350350 return cl;
@@ -353,7 +353,7 @@ VAL idris_b16Or(VM *vm, VAL a, VAL b) {
353353VAL idris_b16Xor(VM *vm, VAL a, VAL b) {
354354 uint16_t A = a->info.bits16;
355355 uint16_t B = b->info.bits16;
356− VAL cl = allocate(vm, sizeof(Closure), 0);
356+ VAL cl = allocate(sizeof(Closure), 0);
357357 SETTY(cl, BITS16);
358358 cl->info.bits16 = A ^ B;
359359 return cl;
@@ -362,7 +362,7 @@ VAL idris_b16Xor(VM *vm, VAL a, VAL b) {
362362VAL idris_b16Shl(VM *vm, VAL a, VAL b) {
363363 uint16_t A = a->info.bits16;
364364 uint16_t B = b->info.bits16;
365− VAL cl = allocate(vm, sizeof(Closure), 0);
365+ VAL cl = allocate(sizeof(Closure), 0);
366366 SETTY(cl, BITS16);
367367 cl->info.bits16 = A << B;
368368 return cl;
@@ -371,7 +371,7 @@ VAL idris_b16Shl(VM *vm, VAL a, VAL b) {
371371VAL idris_b16LShr(VM *vm, VAL a, VAL b) {
372372 uint16_t A = a->info.bits16;
373373 uint16_t B = b->info.bits16;
374− VAL cl = allocate(vm, sizeof(Closure), 0);
374+ VAL cl = allocate(sizeof(Closure), 0);
375375 SETTY(cl, BITS16);
376376 cl->info.bits16 = A >> B;
377377 return cl;
@@ -380,7 +380,7 @@ VAL idris_b16LShr(VM *vm, VAL a, VAL b) {
380380VAL idris_b16AShr(VM *vm, VAL a, VAL b) {
381381 uint16_t A = a->info.bits16;
382382 uint16_t B = b->info.bits16;
383− VAL cl = allocate(vm, sizeof(Closure), 0);
383+ VAL cl = allocate(sizeof(Closure), 0);
384384 SETTY(cl, BITS16);
385385 cl->info.bits16 = (uint16_t) (((int16_t) A) >> ((int16_t) B));
386386 return cl;
@@ -389,7 +389,7 @@ VAL idris_b16AShr(VM *vm, VAL a, VAL b) {
389389VAL idris_b32Plus(VM *vm, VAL a, VAL b) {
390390 uint32_t A = a->info.bits32;
391391 uint32_t B = b->info.bits32;
392− VAL cl = allocate(vm, sizeof(Closure), 0);
392+ VAL cl = allocate(sizeof(Closure), 0);
393393 SETTY(cl, BITS32);
394394 cl->info.bits32 = A + B;
395395 return cl;
@@ -398,7 +398,7 @@ VAL idris_b32Plus(VM *vm, VAL a, VAL b) {
398398VAL idris_b32Minus(VM *vm, VAL a, VAL b) {
399399 uint32_t A = a->info.bits32;
400400 uint32_t B = b->info.bits32;
401− VAL cl = allocate(vm, sizeof(Closure), 0);
401+ VAL cl = allocate(sizeof(Closure), 0);
402402 SETTY(cl, BITS32);
403403 cl->info.bits32 = A - B;
404404 return cl;
@@ -407,7 +407,7 @@ VAL idris_b32Minus(VM *vm, VAL a, VAL b) {
407407VAL idris_b32Times(VM *vm, VAL a, VAL b) {
408408 uint32_t A = a->info.bits32;
409409 uint32_t B = b->info.bits32;
410− VAL cl = allocate(vm, sizeof(Closure), 0);
410+ VAL cl = allocate(sizeof(Closure), 0);
411411 SETTY(cl, BITS32);
412412 cl->info.bits32 = A * B;
413413 return cl;
@@ -416,7 +416,7 @@ VAL idris_b32Times(VM *vm, VAL a, VAL b) {
416416VAL idris_b32UDiv(VM *vm, VAL a, VAL b) {
417417 uint32_t A = a->info.bits32;
418418 uint32_t B = b->info.bits32;
419− VAL cl = allocate(vm, sizeof(Closure), 0);
419+ VAL cl = allocate(sizeof(Closure), 0);
420420 SETTY(cl, BITS32);
421421 cl->info.bits32 = A / B;
422422 return cl;
@@ -425,7 +425,7 @@ VAL idris_b32UDiv(VM *vm, VAL a, VAL b) {
425425VAL idris_b32SDiv(VM *vm, VAL a, VAL b) {
426426 uint32_t A = a->info.bits32;
427427 uint32_t B = b->info.bits32;
428− VAL cl = allocate(vm, sizeof(Closure), 0);
428+ VAL cl = allocate(sizeof(Closure), 0);
429429 SETTY(cl, BITS32);
430430 cl->info.bits32 = (uint32_t) (((int32_t) A) / ((int32_t) B));
431431 return cl;
@@ -434,7 +434,7 @@ VAL idris_b32SDiv(VM *vm, VAL a, VAL b) {
434434VAL idris_b32URem(VM *vm, VAL a, VAL b) {
435435 uint32_t A = a->info.bits32;
436436 uint32_t B = b->info.bits32;
437− VAL cl = allocate(vm, sizeof(Closure), 0);
437+ VAL cl = allocate(sizeof(Closure), 0);
438438 SETTY(cl, BITS32);
439439 cl->info.bits32 = A % B;
440440 return cl;
@@ -443,7 +443,7 @@ VAL idris_b32URem(VM *vm, VAL a, VAL b) {
443443VAL idris_b32SRem(VM *vm, VAL a, VAL b) {
444444 uint32_t A = a->info.bits32;
445445 uint32_t B = b->info.bits32;
446− VAL cl = allocate(vm, sizeof(Closure), 0);
446+ VAL cl = allocate(sizeof(Closure), 0);
447447 SETTY(cl, BITS32);
448448 cl->info.bits32 = (uint32_t) (((int32_t) A) % ((int32_t) B));
449449 return cl;
@@ -471,7 +471,7 @@ VAL idris_b32Gte(VM *vm, VAL a, VAL b) {
471471
472472VAL idris_b32Compl(VM *vm, VAL a) {
473473 uint32_t A = a->info.bits32;
474− VAL cl = allocate(vm, sizeof(Closure), 0);
474+ VAL cl = allocate(sizeof(Closure), 0);
475475 SETTY(cl, BITS32);
476476 cl->info.bits32 = ~ A;
477477 return cl;
@@ -480,7 +480,7 @@ VAL idris_b32Compl(VM *vm, VAL a) {
480480VAL idris_b32And(VM *vm, VAL a, VAL b) {
481481 uint32_t A = a->info.bits32;
482482 uint32_t B = b->info.bits32;
483− VAL cl = allocate(vm, sizeof(Closure), 0);
483+ VAL cl = allocate(sizeof(Closure), 0);
484484 SETTY(cl, BITS32);
485485 cl->info.bits32 = A & B;
486486 return cl;
@@ -489,7 +489,7 @@ VAL idris_b32And(VM *vm, VAL a, VAL b) {
489489VAL idris_b32Or(VM *vm, VAL a, VAL b) {
490490 uint32_t A = a->info.bits32;
491491 uint32_t B = b->info.bits32;
492− VAL cl = allocate(vm, sizeof(Closure), 0);
492+ VAL cl = allocate(sizeof(Closure), 0);
493493 SETTY(cl, BITS32);
494494 cl->info.bits32 = A | B;
495495 return cl;
@@ -498,7 +498,7 @@ VAL idris_b32Or(VM *vm, VAL a, VAL b) {
498498VAL idris_b32Xor(VM *vm, VAL a, VAL b) {
499499 uint32_t A = a->info.bits32;
500500 uint32_t B = b->info.bits32;
501− VAL cl = allocate(vm, sizeof(Closure), 0);
501+ VAL cl = allocate(sizeof(Closure), 0);
502502 SETTY(cl, BITS32);
503503 cl->info.bits32 = A ^ B;
504504 return cl;
@@ -507,7 +507,7 @@ VAL idris_b32Xor(VM *vm, VAL a, VAL b) {
507507VAL idris_b32Shl(VM *vm, VAL a, VAL b) {
508508 uint32_t A = a->info.bits32;
509509 uint32_t B = b->info.bits32;
510− VAL cl = allocate(vm, sizeof(Closure), 0);
510+ VAL cl = allocate(sizeof(Closure), 0);
511511 SETTY(cl, BITS32);
512512 cl->info.bits32 = A << B;
513513 return cl;
@@ -516,7 +516,7 @@ VAL idris_b32Shl(VM *vm, VAL a, VAL b) {
516516VAL idris_b32LShr(VM *vm, VAL a, VAL b) {
517517 uint32_t A = a->info.bits32;
518518 uint32_t B = b->info.bits32;
519− VAL cl = allocate(vm, sizeof(Closure), 0);
519+ VAL cl = allocate(sizeof(Closure), 0);
520520 SETTY(cl, BITS32);
521521 cl->info.bits32 = A >> B;
522522 return cl;
@@ -525,7 +525,7 @@ VAL idris_b32LShr(VM *vm, VAL a, VAL b) {
525525VAL idris_b32AShr(VM *vm, VAL a, VAL b) {
526526 uint32_t A = a->info.bits32;
527527 uint32_t B = b->info.bits32;
528− VAL cl = allocate(vm, sizeof(Closure), 0);
528+ VAL cl = allocate(sizeof(Closure), 0);
529529 SETTY(cl, BITS32);
530530 cl->info.bits32 = (uint32_t) (((int32_t)A) >> ((int32_t)B));
531531 return cl;
@@ -534,7 +534,7 @@ VAL idris_b32AShr(VM *vm, VAL a, VAL b) {
534534VAL idris_b64Plus(VM *vm, VAL a, VAL b) {
535535 uint64_t A = a->info.bits64;
536536 uint64_t B = b->info.bits64;
537− VAL cl = allocate(vm, sizeof(Closure), 0);
537+ VAL cl = allocate(sizeof(Closure), 0);
538538 SETTY(cl, BITS64);
539539 cl->info.bits64 = A + B;
540540 return cl;
@@ -543,7 +543,7 @@ VAL idris_b64Plus(VM *vm, VAL a, VAL b) {
543543VAL idris_b64Minus(VM *vm, VAL a, VAL b) {
544544 uint64_t A = a->info.bits64;
545545 uint64_t B = b->info.bits64;
546− VAL cl = allocate(vm, sizeof(Closure), 0);
546+ VAL cl = allocate(sizeof(Closure), 0);
547547 SETTY(cl, BITS64);
548548 cl->info.bits64 = A - B;
549549 return cl;
@@ -552,7 +552,7 @@ VAL idris_b64Minus(VM *vm, VAL a, VAL b) {
552552VAL idris_b64Times(VM *vm, VAL a, VAL b) {
553553 uint64_t A = a->info.bits64;
554554 uint64_t B = b->info.bits64;
555− VAL cl = allocate(vm, sizeof(Closure), 0);
555+ VAL cl = allocate(sizeof(Closure), 0);
556556 SETTY(cl, BITS64);
557557 cl->info.bits64 = A * B;
558558 return cl;
@@ -561,7 +561,7 @@ VAL idris_b64Times(VM *vm, VAL a, VAL b) {
561561VAL idris_b64UDiv(VM *vm, VAL a, VAL b) {
562562 uint64_t A = a->info.bits64;
563563 uint64_t B = b->info.bits64;
564− VAL cl = allocate(vm, sizeof(Closure), 0);
564+ VAL cl = allocate(sizeof(Closure), 0);
565565 SETTY(cl, BITS64);
566566 cl->info.bits64 = A / B;
567567 return cl;
@@ -570,7 +570,7 @@ VAL idris_b64UDiv(VM *vm, VAL a, VAL b) {
570570VAL idris_b64SDiv(VM *vm, VAL a, VAL b) {
571571 uint64_t A = a->info.bits64;
572572 uint64_t B = b->info.bits64;
573− VAL cl = allocate(vm, sizeof(Closure), 0);
573+ VAL cl = allocate(sizeof(Closure), 0);
574574 SETTY(cl, BITS64);
575575 cl->info.bits64 = (uint64_t) (((int64_t) A) / ((int64_t) B));
576576 return cl;
@@ -579,7 +579,7 @@ VAL idris_b64SDiv(VM *vm, VAL a, VAL b) {
579579VAL idris_b64URem(VM *vm, VAL a, VAL b) {
580580 uint64_t A = a->info.bits64;
581581 uint64_t B = b->info.bits64;
582− VAL cl = allocate(vm, sizeof(Closure), 0);
582+ VAL cl = allocate(sizeof(Closure), 0);
583583 SETTY(cl, BITS64);
584584 cl->info.bits64 = A % B;
585585 return cl;
@@ -588,7 +588,7 @@ VAL idris_b64URem(VM *vm, VAL a, VAL b) {
588588VAL idris_b64SRem(VM *vm, VAL a, VAL b) {
589589 uint64_t A = a->info.bits64;
590590 uint64_t B = b->info.bits64;
591− VAL cl = allocate(vm, sizeof(Closure), 0);
591+ VAL cl = allocate(sizeof(Closure), 0);
592592 SETTY(cl, BITS64);
593593 cl->info.bits64 = (uint64_t) (((int64_t) A) % ((int64_t) B));
594594 return cl;
@@ -616,7 +616,7 @@ VAL idris_b64Gte(VM *vm, VAL a, VAL b) {
616616
617617VAL idris_b64Compl(VM *vm, VAL a) {
618618 uint64_t A = a->info.bits64;
619− VAL cl = allocate(vm, sizeof(Closure), 0);
619+ VAL cl = allocate(sizeof(Closure), 0);
620620 SETTY(cl, BITS64);
621621 cl->info.bits64 = ~ A;
622622 return cl;
@@ -625,7 +625,7 @@ VAL idris_b64Compl(VM *vm, VAL a) {
625625VAL idris_b64And(VM *vm, VAL a, VAL b) {
626626 uint64_t A = a->info.bits64;
627627 uint64_t B = b->info.bits64;
628− VAL cl = allocate(vm, sizeof(Closure), 0);
628+ VAL cl = allocate(sizeof(Closure), 0);
629629 SETTY(cl, BITS64);
630630 cl->info.bits64 = A & B;
631631 return cl;
@@ -634,7 +634,7 @@ VAL idris_b64And(VM *vm, VAL a, VAL b) {
634634VAL idris_b64Or(VM *vm, VAL a, VAL b) {
635635 uint64_t A = a->info.bits64;
636636 uint64_t B = b->info.bits64;
637− VAL cl = allocate(vm, sizeof(Closure), 0);
637+ VAL cl = allocate(sizeof(Closure), 0);
638638 SETTY(cl, BITS64);
639639 cl->info.bits64 = A | B;
640640 return cl;
@@ -643,7 +643,7 @@ VAL idris_b64Or(VM *vm, VAL a, VAL b) {
643643VAL idris_b64Xor(VM *vm, VAL a, VAL b) {
644644 uint64_t A = a->info.bits64;
645645 uint64_t B = b->info.bits64;
646− VAL cl = allocate(vm, sizeof(Closure), 0);
646+ VAL cl = allocate(sizeof(Closure), 0);
647647 SETTY(cl, BITS64);
648648 cl->info.bits64 = A ^ B;
649649 return cl;
@@ -652,7 +652,7 @@ VAL idris_b64Xor(VM *vm, VAL a, VAL b) {
652652VAL idris_b64Shl(VM *vm, VAL a, VAL b) {
653653 uint64_t A = a->info.bits64;
654654 uint64_t B = b->info.bits64;
655− VAL cl = allocate(vm, sizeof(Closure), 0);
655+ VAL cl = allocate(sizeof(Closure), 0);
656656 SETTY(cl, BITS64);
657657 cl->info.bits64 = A << B;
658658 return cl;
@@ -661,7 +661,7 @@ VAL idris_b64Shl(VM *vm, VAL a, VAL b) {
661661VAL idris_b64LShr(VM *vm, VAL a, VAL b) {
662662 uint64_t A = a->info.bits64;
663663 uint64_t B = b->info.bits64;
664− VAL cl = allocate(vm, sizeof(Closure), 0);
664+ VAL cl = allocate(sizeof(Closure), 0);
665665 SETTY(cl, BITS64);
666666 cl->info.bits64 = A >> B;
667667 return cl;
@@ -670,7 +670,7 @@ VAL idris_b64LShr(VM *vm, VAL a, VAL b) {
670670VAL idris_b64AShr(VM *vm, VAL a, VAL b) {
671671 uint64_t A = a->info.bits64;
672672 uint64_t B = b->info.bits64;
673− VAL cl = allocate(vm, sizeof(Closure), 0);
673+ VAL cl = allocate(sizeof(Closure), 0);
674674 SETTY(cl, BITS64);
675675 cl->info.bits64 = (uint64_t) (((int64_t) A) >> ((int64_t) B));
676676 return cl;
@@ -678,7 +678,7 @@ VAL idris_b64AShr(VM *vm, VAL a, VAL b) {
678678
679679VAL idris_b8Z16(VM *vm, VAL a) {
680680 uint8_t A = a->info.bits8;
681− VAL cl = allocate(vm, sizeof(Closure), 0);
681+ VAL cl = allocate(sizeof(Closure), 0);
682682 SETTY(cl, BITS16);
683683 cl->info.bits16 = (uint16_t) A;
684684 return cl;
@@ -686,7 +686,7 @@ VAL idris_b8Z16(VM *vm, VAL a) {
686686
687687VAL idris_b8Z32(VM *vm, VAL a) {
688688 uint8_t A = a->info.bits8;
689− VAL cl = allocate(vm, sizeof(Closure), 0);
689+ VAL cl = allocate(sizeof(Closure), 0);
690690 SETTY(cl, BITS32);
691691 cl->info.bits32 = (uint32_t) A;
692692 return cl;
@@ -694,7 +694,7 @@ VAL idris_b8Z32(VM *vm, VAL a) {
694694
695695VAL idris_b8Z64(VM *vm, VAL a) {
696696 uint8_t A = a->info.bits8;
697− VAL cl = allocate(vm, sizeof(Closure), 0);
697+ VAL cl = allocate(sizeof(Closure), 0);
698698 SETTY(cl, BITS64);
699699 cl->info.bits64 = (uint64_t) A;
700700 return cl;
@@ -702,7 +702,7 @@ VAL idris_b8Z64(VM *vm, VAL a) {
702702
703703VAL idris_b8S16(VM *vm, VAL a) {
704704 uint8_t A = a->info.bits8;
705− VAL cl = allocate(vm, sizeof(Closure), 0);
705+ VAL cl = allocate(sizeof(Closure), 0);
706706 SETTY(cl, BITS16);
707707 cl->info.bits16 = (uint16_t) (int16_t) (int8_t) A;
708708 return cl;
@@ -710,7 +710,7 @@ VAL idris_b8S16(VM *vm, VAL a) {
710710
711711VAL idris_b8S32(VM *vm, VAL a) {
712712 uint8_t A = a->info.bits8;
713− VAL cl = allocate(vm, sizeof(Closure), 0);
713+ VAL cl = allocate(sizeof(Closure), 0);
714714 SETTY(cl, BITS32);
715715 cl->info.bits32 = (uint32_t) (int32_t) (int8_t) A;
716716 return cl;
@@ -718,7 +718,7 @@ VAL idris_b8S32(VM *vm, VAL a) {
718718
719719VAL idris_b8S64(VM *vm, VAL a) {
720720 uint8_t A = a->info.bits8;
721− VAL cl = allocate(vm, sizeof(Closure), 0);
721+ VAL cl = allocate(sizeof(Closure), 0);
722722 SETTY(cl, BITS64);
723723 cl->info.bits64 = (uint64_t) (int64_t) (int8_t) A;
724724 return cl;
@@ -726,7 +726,7 @@ VAL idris_b8S64(VM *vm, VAL a) {
726726
727727VAL idris_b16Z32(VM *vm, VAL a) {
728728 uint16_t A = a->info.bits16;
729− VAL cl = allocate(vm, sizeof(Closure), 0);
729+ VAL cl = allocate(sizeof(Closure), 0);
730730 SETTY(cl, BITS32);
731731 cl->info.bits32 = (uint32_t) A;
732732 return cl;
@@ -734,7 +734,7 @@ VAL idris_b16Z32(VM *vm, VAL a) {
734734
735735VAL idris_b16Z64(VM *vm, VAL a) {
736736 uint16_t A = a->info.bits16;
737− VAL cl = allocate(vm, sizeof(Closure), 0);
737+ VAL cl = allocate(sizeof(Closure), 0);
738738 SETTY(cl, BITS64);
739739 cl->info.bits64 = (uint64_t) A;
740740 return cl;
@@ -742,7 +742,7 @@ VAL idris_b16Z64(VM *vm, VAL a) {
742742
743743VAL idris_b16S32(VM *vm, VAL a) {
744744 uint16_t A = a->info.bits16;
745− VAL cl = allocate(vm, sizeof(Closure), 0);
745+ VAL cl = allocate(sizeof(Closure), 0);
746746 SETTY(cl, BITS32);
747747 cl->info.bits32 = (uint32_t) (int32_t) (int16_t) A;
748748 return cl;
@@ -750,7 +750,7 @@ VAL idris_b16S32(VM *vm, VAL a) {
750750
751751VAL idris_b16S64(VM *vm, VAL a) {
752752 uint16_t A = a->info.bits16;
753− VAL cl = allocate(vm, sizeof(Closure), 0);
753+ VAL cl = allocate(sizeof(Closure), 0);
754754 SETTY(cl, BITS64);
755755 cl->info.bits64 = (uint64_t) (int64_t) (int16_t) A;
756756 return cl;
@@ -758,7 +758,7 @@ VAL idris_b16S64(VM *vm, VAL a) {
758758
759759VAL idris_b16T8(VM *vm, VAL a) {
760760 uint16_t A = a->info.bits16;
761− VAL cl = allocate(vm, sizeof(Closure), 0);
761+ VAL cl = allocate(sizeof(Closure), 0);
762762 SETTY(cl, BITS8);
763763 cl->info.bits8 = (uint8_t) A;
764764 return cl;
@@ -766,7 +766,7 @@ VAL idris_b16T8(VM *vm, VAL a) {
766766
767767VAL idris_b32Z64(VM *vm, VAL a) {
768768 uint32_t A = a->info.bits32;
769− VAL cl = allocate(vm, sizeof(Closure), 0);
769+ VAL cl = allocate(sizeof(Closure), 0);
770770 SETTY(cl, BITS64);
771771 cl->info.bits64 = (uint64_t) A;
772772 return cl;
@@ -774,7 +774,7 @@ VAL idris_b32Z64(VM *vm, VAL a) {
774774
775775VAL idris_b32S64(VM *vm, VAL a) {
776776 uint32_t A = a->info.bits32;
777− VAL cl = allocate(vm, sizeof(Closure), 0);
777+ VAL cl = allocate(sizeof(Closure), 0);
778778 SETTY(cl, BITS64);
779779 cl->info.bits64 = (uint64_t) (int64_t) (int32_t) A;
780780 return cl;
@@ -782,7 +782,7 @@ VAL idris_b32S64(VM *vm, VAL a) {
782782
783783VAL idris_b32T8(VM *vm, VAL a) {
784784 uint32_t A = a->info.bits32;
785− VAL cl = allocate(vm, sizeof(Closure), 0);
785+ VAL cl = allocate(sizeof(Closure), 0);
786786 SETTY(cl, BITS8);
787787 cl->info.bits8 = (uint8_t) A;
788788 return cl;
@@ -790,7 +790,7 @@ VAL idris_b32T8(VM *vm, VAL a) {
790790
791791VAL idris_b32T16(VM *vm, VAL a) {
792792 uint32_t A = a->info.bits32;
793− VAL cl = allocate(vm, sizeof(Closure), 0);
793+ VAL cl = allocate(sizeof(Closure), 0);
794794 SETTY(cl, BITS16);
795795 cl->info.bits16 = (uint16_t) A;
796796 return cl;
@@ -798,7 +798,7 @@ VAL idris_b32T16(VM *vm, VAL a) {
798798
799799VAL idris_b64T8(VM *vm, VAL a) {
800800 uint64_t A = a->info.bits64;
801− VAL cl = allocate(vm, sizeof(Closure), 0);
801+ VAL cl = allocate(sizeof(Closure), 0);
802802 SETTY(cl, BITS8);
803803 cl->info.bits8 = (uint8_t) A;
804804 return cl;
@@ -806,7 +806,7 @@ VAL idris_b64T8(VM *vm, VAL a) {
806806
807807VAL idris_b64T16(VM *vm, VAL a) {
808808 uint64_t A = a->info.bits64;
809− VAL cl = allocate(vm, sizeof(Closure), 0);
809+ VAL cl = allocate(sizeof(Closure), 0);
810810 SETTY(cl, BITS16);
811811 cl->info.bits16 = (uint16_t) A;
812812 return cl;
@@ -814,7 +814,7 @@ VAL idris_b64T16(VM *vm, VAL a) {
814814
815815VAL idris_b64T32(VM *vm, VAL a) {
816816 uint64_t A = a->info.bits64;
817− VAL cl = allocate(vm, sizeof(Closure), 0);
817+ VAL cl = allocate(sizeof(Closure), 0);
818818 SETTY(cl, BITS32);
819819 cl->info.bits32 = (uint32_t) A;
820820 return cl;
rts/idris_gc.c+3−2
@@ -101,11 +101,12 @@ void idris_gc(VM* vm) {
101101 STATS_ENTER_GC(vm->stats, vm->heap.size)
102102 // printf("Collecting\n");
103103
104− char* newheap = malloc(vm->heap.size);
105− char* oldheap = vm->heap.heap;
106104 if (vm->heap.old != NULL)
107105 free(vm->heap.old);
108106
107+ char* newheap = malloc(vm->heap.size);
108+ char* oldheap = vm->heap.heap;
109+
109110 vm->heap.heap = newheap;
110111#ifdef FORCE_ALIGNMENT
111112 if (((i_int)(vm->heap.heap)&1) == 1) {
rts/idris_gmp.c+46−15
@@ -7,15 +7,26 @@
77#include <stdlib.h>
88#include <string.h>
99
10+// TMP HACK! Require this much space in the heap before a GMP operation
11+// so it doesn't garbage collect in the middle.
12+// This is highly dodgy and needs to be done better because who knows if
13+// GMP will need to allocate more than 64k... better to work out how
14+// much space is needed (or find another way of preventing copying)
15+#define IDRIS_MAXGMP 65536
16+
17+void init_gmpalloc() {
18+ mp_set_memory_functions(idris_alloc, idris_realloc, idris_free);
19+}
20+
1021VAL MKBIGI(int val) {
1122 return MKINT((i_int)val);
1223}
1324
1425VAL MKBIGC(VM* vm, char* val) {
26+ idris_requireAlloc(IDRIS_MAXGMP);
1527 mpz_t* bigint;
1628
17− VAL cl = allocate(vm, sizeof(Closure) +
18− sizeof(mpz_t), 0);
29+ VAL cl = allocate(sizeof(Closure) + sizeof(mpz_t), 0);
1930 bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
2031
2132 mpz_init(*bigint);
@@ -28,9 +39,10 @@ VAL MKBIGC(VM* vm, char* val) {
2839}
2940
3041VAL MKBIGM(VM* vm, void* big) {
42+ idris_requireAlloc(IDRIS_MAXGMP);
43+
3144 mpz_t* bigint;
32− VAL cl = allocate(vm, sizeof(Closure) +
33− sizeof(mpz_t), 0);
45+ VAL cl = allocate(sizeof(Closure) + sizeof(mpz_t), 0);
3446 bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
3547
3648 mpz_init(*bigint);
@@ -43,9 +55,10 @@ VAL MKBIGM(VM* vm, void* big) {
4355}
4456
4557VAL MKBIGMc(VM* vm, void* big) {
58+ idris_requireAlloc(IDRIS_MAXGMP);
59+
4660 mpz_t* bigint;
47− VAL cl = allocate(vm, sizeof(Closure) +
48− sizeof(mpz_t), 0);
61+ VAL cl = allocate(sizeof(Closure) + sizeof(mpz_t), 0);
4962 bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
5063
5164 mpz_init_set(*bigint, *((mpz_t*)big));
@@ -57,8 +70,10 @@ VAL MKBIGMc(VM* vm, void* big) {
5770}
5871
5972VAL MKBIGUI(VM* vm, unsigned long val) {
73+ idris_requireAlloc(IDRIS_MAXGMP);
74+
6075 mpz_t* bigint;
61− VAL cl = allocate(vm, sizeof(Closure) + sizeof(mpz_t), 0);
76+ VAL cl = allocate(sizeof(Closure) + sizeof(mpz_t), 0);
6277 bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
6378
6479 mpz_init_set_ui(*bigint, val);
@@ -70,8 +85,10 @@ VAL MKBIGUI(VM* vm, unsigned long val) {
7085}
7186
7287VAL MKBIGSI(VM* vm, signed long val) {
88+ idris_requireAlloc(IDRIS_MAXGMP);
89+
7390 mpz_t* bigint;
74− VAL cl = allocate(vm, sizeof(Closure) + sizeof(mpz_t), 0);
91+ VAL cl = allocate(sizeof(Closure) + sizeof(mpz_t), 0);
7592 bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
7693
7794 mpz_init_set_si(*bigint, val);
@@ -83,9 +100,11 @@ VAL MKBIGSI(VM* vm, signed long val) {
83100}
84101
85102VAL GETBIG(VM * vm, VAL x) {
103+ idris_requireAlloc(IDRIS_MAXGMP);
104+
86105 if (ISINT(x)) {
87106 mpz_t* bigint;
88− VAL cl = allocate(vm, sizeof(Closure) + sizeof(mpz_t), 0);
107+ VAL cl = allocate(sizeof(Closure) + sizeof(mpz_t), 0);
89108 bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
90109
91110 mpz_init(*bigint);
@@ -106,8 +125,10 @@ VAL GETBIG(VM * vm, VAL x) {
106125}
107126
108127VAL bigAdd(VM* vm, VAL x, VAL y) {
128+ idris_requireAlloc(IDRIS_MAXGMP);
129+
109130 mpz_t* bigint;
110− VAL cl = allocate(vm, sizeof(Closure) + sizeof(mpz_t), 0);
131+ VAL cl = allocate(sizeof(Closure) + sizeof(mpz_t), 0);
111132 bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
112133 mpz_add(*bigint, GETMPZ(GETBIG(vm,x)), GETMPZ(GETBIG(vm,y)));
113134 SETTY(cl, BIGINT);
@@ -116,8 +137,10 @@ VAL bigAdd(VM* vm, VAL x, VAL y) {
116137}
117138
118139VAL bigSub(VM* vm, VAL x, VAL y) {
140+ idris_requireAlloc(IDRIS_MAXGMP);
141+
119142 mpz_t* bigint;
120− VAL cl = allocate(vm, sizeof(Closure) + sizeof(mpz_t), 0);
143+ VAL cl = allocate(sizeof(Closure) + sizeof(mpz_t), 0);
121144 bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
122145 mpz_sub(*bigint, GETMPZ(GETBIG(vm,x)), GETMPZ(GETBIG(vm,y)));
123146 SETTY(cl, BIGINT);
@@ -126,8 +149,10 @@ VAL bigSub(VM* vm, VAL x, VAL y) {
126149}
127150
128151VAL bigMul(VM* vm, VAL x, VAL y) {
152+ idris_requireAlloc(IDRIS_MAXGMP);
153+
129154 mpz_t* bigint;
130− VAL cl = allocate(vm, sizeof(Closure) + sizeof(mpz_t), 0);
155+ VAL cl = allocate(sizeof(Closure) + sizeof(mpz_t), 0);
131156 bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
132157 mpz_mul(*bigint, GETMPZ(GETBIG(vm,x)), GETMPZ(GETBIG(vm,y)));
133158 SETTY(cl, BIGINT);
@@ -136,8 +161,10 @@ VAL bigMul(VM* vm, VAL x, VAL y) {
136161}
137162
138163VAL bigDiv(VM* vm, VAL x, VAL y) {
164+ idris_requireAlloc(IDRIS_MAXGMP);
165+
139166 mpz_t* bigint;
140− VAL cl = allocate(vm, sizeof(Closure) + sizeof(mpz_t), 0);
167+ VAL cl = allocate(sizeof(Closure) + sizeof(mpz_t), 0);
141168 bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
142169 mpz_tdiv_q(*bigint, GETMPZ(GETBIG(vm,x)), GETMPZ(GETBIG(vm,y)));
143170 SETTY(cl, BIGINT);
@@ -146,8 +173,10 @@ VAL bigDiv(VM* vm, VAL x, VAL y) {
146173}
147174
148175VAL bigMod(VM* vm, VAL x, VAL y) {
176+ idris_requireAlloc(IDRIS_MAXGMP);
177+
149178 mpz_t* bigint;
150− VAL cl = allocate(vm, sizeof(Closure) + sizeof(mpz_t), 0);
179+ VAL cl = allocate(sizeof(Closure) + sizeof(mpz_t), 0);
151180 bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
152181 mpz_mod(*bigint, GETMPZ(GETBIG(vm,x)), GETMPZ(GETBIG(vm,y)));
153182 SETTY(cl, BIGINT);
@@ -229,6 +258,8 @@ VAL idris_bigMod(VM* vm, VAL x, VAL y) {
229258}
230259
231260int bigEqConst(VAL x, int c) {
261+ idris_requireAlloc(IDRIS_MAXGMP);
262+
232263 if (ISINT(x)) { return (GETINT(x) == c); }
233264 else {
234265 int rv = mpz_cmp_si(GETMPZ(x), c);
@@ -321,7 +352,7 @@ VAL idris_castFloatBig(VM* vm, VAL f) {
321352 double val = GETFLOAT(f);
322353
323354 mpz_t* bigint;
324− VAL cl = allocate(vm, sizeof(Closure) + sizeof(mpz_t), 0);
355+ VAL cl = allocate(sizeof(Closure) + sizeof(mpz_t), 0);
325356 bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
326357
327358 mpz_init_set_d(*bigint, val);
rts/idris_gmp.h+3
@@ -7,6 +7,9 @@
77#include "mini-gmp.h"
88#endif
99
10+// Set memory allocation functions
11+void init_gmpalloc();
12+
1013VAL MKBIGI(int val);
1114VAL MKBIGC(VM* vm, char* bigint);
1215VAL MKBIGM(VM* vm, void* bigint);
rts/idris_main.c+7−2
@@ -1,6 +1,7 @@
11#include "idris_opts.h"
22#include "idris_stats.h"
33#include "idris_rts.h"
4+#include "idris_gmp.h"
45// The default options should give satisfactory results under many circumstances.
56RTSOpts opts = {
67 .init_heap_size = 4096000,
@@ -15,7 +16,11 @@ int main(int argc, char* argv[]) {
1516 __idris_argv = argv;
1617
1718 VM* vm = init_vm(opts.max_stack_size, opts.init_heap_size, 1);
18− initNullaries();
19+ init_threadkeys();
20+ init_threaddata(vm);
21+ init_gmpalloc();
22+
23+ init_nullaries();
1924
2025 _idris__123_runMain0_125_(vm, NULL);
2126
@@ -31,6 +36,6 @@ int main(int argc, char* argv[]) {
3136 print_stats(&stats);
3237 }
3338
34− freeNullaries();
39+ free_nullaries();
3540 return EXIT_SUCCESS;
3641}
rts/idris_rts.c+82−35
@@ -11,6 +11,15 @@
1111#include "idris_gc.h"
1212#include "idris_bitstring.h"
1313
14+#ifdef HAS_PTHREAD
15+static pthread_key_t vm_key;
16+#else
17+static VM* global_vm;
18+#endif
19+
20+void free_key(VM *vm) {
21+ // nothing to free, we just used the VM pointer which is freed elsewhere
22+}
1423
1524VM* init_vm(int stack_size, size_t heap_size,
1625 int max_threads // not implemented yet
@@ -54,11 +63,24 @@ VM* init_vm(int stack_size, size_t heap_size,
5463
5564 vm->max_threads = max_threads;
5665 vm->processes = 0;
66+
67+#else
68+ global_vm = vm;
5769#endif
5870 STATS_LEAVE_INIT(vm->stats)
5971 return vm;
6072}
6173
74+void init_threadkeys() {
75+ pthread_key_create(&vm_key, (void*)free_key);
76+}
77+
78+void init_threaddata(VM *vm) {
79+#ifdef HAS_PTHREAD
80+ pthread_setspecific(vm_key, vm);
81+#endif
82+}
83+
6284Stats terminate(VM* vm) {
6385 Stats stats = vm->stats;
6486 STATS_ENTER_EXIT(stats)
@@ -78,7 +100,13 @@ Stats terminate(VM* vm) {
78100 return stats;
79101}
80102
81−void idris_requireAlloc(VM* vm, size_t size) {
103+void idris_requireAlloc(size_t size) {
104+#ifdef HAS_PTHREAD
105+ VM* vm = pthread_getspecific(vm_key);
106+#else
107+ VM* vm = global_vm;
108+#endif
109+
82110 if (!(vm->heap.next + size < vm->heap.end)) {
83111 idris_gc(vm);
84112 }
@@ -90,8 +118,9 @@ void idris_requireAlloc(VM* vm, size_t size) {
90118#endif
91119}
92120
93−void idris_doneAlloc(VM* vm) {
121+void idris_doneAlloc() {
94122#ifdef HAS_PTHREAD
123+ VM* vm = pthread_getspecific(vm_key);
95124 int lock = vm->processes > 0;
96125 if (lock) { // We only need to lock if we're in concurrent mode
97126 pthread_mutex_unlock(&vm->alloc_lock);
@@ -103,14 +132,31 @@ int space(VM* vm, size_t size) {
103132 return (vm->heap.next + size + sizeof(size_t) < vm->heap.end);
104133}
105134
106−void* allocate(VM* vm, size_t size, int outerlock) {
135+void* idris_alloc(size_t size) {
136+ return allocate(size, 0);
137+}
138+
139+void* idris_realloc(void* old, size_t old_size, size_t size) {
140+ void* ptr = idris_alloc(size);
141+ memcpy(ptr, old, old_size);
142+ return ptr;
143+}
144+
145+void idris_free(void* ptr, size_t size) {
146+}
147+
148+void* allocate(size_t size, int outerlock) {
107149// return malloc(size);
150+
108151#ifdef HAS_PTHREAD
152+ VM* vm = pthread_getspecific(vm_key);
109153 int lock = vm->processes > 0 && !outerlock;
110154
111155 if (lock) { // not message passing
112156 pthread_mutex_lock(&vm->alloc_lock);
113157 }
158+#else
159+ VM* vm = global_vm;
114160#endif
115161
116162 if ((size & 7)!=0) {
@@ -141,7 +187,7 @@ void* allocate(VM* vm, size_t size, int outerlock) {
141187 pthread_mutex_unlock(&vm->alloc_lock);
142188 }
143189#endif
144− return allocate(vm, size, 0);
190+ return allocate(size, 0);
145191 }
146192
147193}
@@ -160,7 +206,7 @@ void* allocCon(VM* vm, int arity, int outer) {
160206*/
161207
162208VAL MKFLOAT(VM* vm, double val) {
163− Closure* cl = allocate(vm, sizeof(Closure), 0);
209+ Closure* cl = allocate(sizeof(Closure), 0);
164210 SETTY(cl, FLOAT);
165211 cl -> info.f = val;
166212 return cl;
@@ -173,8 +219,8 @@ VAL MKSTR(VM* vm, const char* str) {
173219 } else {
174220 len = strlen(str)+1;
175221 }
176− Closure* cl = allocate(vm, sizeof(Closure) + // Type) + sizeof(char*) +
177− sizeof(char)*len, 0);
222+ Closure* cl = allocate(sizeof(Closure) + // Type) + sizeof(char*) +
223+ sizeof(char)*len, 0);
178224 SETTY(cl, STRING);
179225 cl -> info.str = (char*)cl + sizeof(Closure);
180226 if (str == NULL) {
@@ -192,15 +238,15 @@ char* GETSTROFF(VAL stroff) {
192238}
193239
194240VAL MKPTR(VM* vm, void* ptr) {
195− Closure* cl = allocate(vm, sizeof(Closure), 0);
241+ Closure* cl = allocate(sizeof(Closure), 0);
196242 SETTY(cl, PTR);
197243 cl -> info.ptr = ptr;
198244 return cl;
199245}
200246
201247VAL MKMPTR(VM* vm, void* ptr, size_t size) {
202− Closure* cl = allocate(vm, sizeof(Closure) +
203− sizeof(ManagedPtr) + size, 0);
248+ Closure* cl = allocate(sizeof(Closure) +
249+ sizeof(ManagedPtr) + size, 0);
204250 SETTY(cl, MANAGEDPTR);
205251 cl->info.mptr = (ManagedPtr*)((char*)cl + sizeof(Closure));
206252 cl->info.mptr->data = (char*)cl + sizeof(Closure) + sizeof(ManagedPtr);
@@ -210,15 +256,15 @@ VAL MKMPTR(VM* vm, void* ptr, size_t size) {
210256}
211257
212258VAL MKFLOATc(VM* vm, double val) {
213− Closure* cl = allocate(vm, sizeof(Closure), 1);
259+ Closure* cl = allocate(sizeof(Closure), 1);
214260 SETTY(cl, FLOAT);
215261 cl -> info.f = val;
216262 return cl;
217263}
218264
219265VAL MKSTRc(VM* vm, char* str) {
220− Closure* cl = allocate(vm, sizeof(Closure) + // Type) + sizeof(char*) +
221− sizeof(char)*strlen(str)+1, 1);
266+ Closure* cl = allocate(sizeof(Closure) + // Type) + sizeof(char*) +
267+ sizeof(char)*strlen(str)+1, 1);
222268 SETTY(cl, STRING);
223269 cl -> info.str = (char*)cl + sizeof(Closure);
224270
@@ -227,15 +273,15 @@ VAL MKSTRc(VM* vm, char* str) {
227273}
228274
229275VAL MKPTRc(VM* vm, void* ptr) {
230− Closure* cl = allocate(vm, sizeof(Closure), 1);
276+ Closure* cl = allocate(sizeof(Closure), 1);
231277 SETTY(cl, PTR);
232278 cl -> info.ptr = ptr;
233279 return cl;
234280}
235281
236282VAL MKMPTRc(VM* vm, void* ptr, size_t size) {
237− Closure* cl = allocate(vm, sizeof(Closure) +
238− sizeof(ManagedPtr) + size, 1);
283+ Closure* cl = allocate(sizeof(Closure) +
284+ sizeof(ManagedPtr) + size, 1);
239285 SETTY(cl, MANAGEDPTR);
240286 cl->info.mptr = (ManagedPtr*)((char*)cl + sizeof(Closure));
241287 cl->info.mptr->data = (char*)cl + sizeof(Closure) + sizeof(ManagedPtr);
@@ -245,28 +291,28 @@ VAL MKMPTRc(VM* vm, void* ptr, size_t size) {
245291}
246292
247293VAL MKB8(VM* vm, uint8_t bits8) {
248− Closure* cl = allocate(vm, sizeof(Closure), 1);
294+ Closure* cl = allocate(sizeof(Closure), 1);
249295 SETTY(cl, BITS8);
250296 cl -> info.bits8 = bits8;
251297 return cl;
252298}
253299
254300VAL MKB16(VM* vm, uint16_t bits16) {
255− Closure* cl = allocate(vm, sizeof(Closure), 1);
301+ Closure* cl = allocate(sizeof(Closure), 1);
256302 SETTY(cl, BITS16);
257303 cl -> info.bits16 = bits16;
258304 return cl;
259305}
260306
261307VAL MKB32(VM* vm, uint32_t bits32) {
262− Closure* cl = allocate(vm, sizeof(Closure), 1);
308+ Closure* cl = allocate(sizeof(Closure), 1);
263309 SETTY(cl, BITS32);
264310 cl -> info.bits32 = bits32;
265311 return cl;
266312}
267313
268314VAL MKB64(VM* vm, uint64_t bits64) {
269− Closure* cl = allocate(vm, sizeof(Closure), 1);
315+ Closure* cl = allocate(sizeof(Closure), 1);
270316 SETTY(cl, BITS64);
271317 cl -> info.bits64 = bits64;
272318 return cl;
@@ -347,7 +393,7 @@ void idris_memmove(void* dest, void* src, i_int dest_offset, i_int src_offset, i
347393
348394VAL idris_castIntStr(VM* vm, VAL i) {
349395 int x = (int) GETINT(i);
350− Closure* cl = allocate(vm, sizeof(Closure) + sizeof(char)*16, 0);
396+ Closure* cl = allocate(sizeof(Closure) + sizeof(char)*16, 0);
351397 SETTY(cl, STRING);
352398 cl -> info.str = (char*)cl + sizeof(Closure);
353399 sprintf(cl -> info.str, "%d", x);
@@ -364,7 +410,7 @@ VAL idris_castStrInt(VM* vm, VAL i) {
364410}
365411
366412VAL idris_castFloatStr(VM* vm, VAL i) {
367− Closure* cl = allocate(vm, sizeof(Closure) + sizeof(char)*32, 0);
413+ Closure* cl = allocate(sizeof(Closure) + sizeof(char)*32, 0);
368414 SETTY(cl, STRING);
369415 cl -> info.str = (char*)cl + sizeof(Closure);
370416 sprintf(cl -> info.str, "%g", GETFLOAT(i));
@@ -380,8 +426,7 @@ VAL idris_concat(VM* vm, VAL l, VAL r) {
380426 char *ls = GETSTR(l);
381427 // dumpVal(l);
382428 // printf("\n");
383− Closure* cl = allocate(vm, sizeof(Closure) + strlen(ls) + strlen(rs) + 1,
384− 0);
429+ Closure* cl = allocate(sizeof(Closure) + strlen(ls) + strlen(rs) + 1, 0);
385430 SETTY(cl, STRING);
386431 cl -> info.str = (char*)cl + sizeof(Closure);
387432 strcpy(cl -> info.str, ls);
@@ -451,7 +496,7 @@ VAL idris_strHead(VM* vm, VAL str) {
451496}
452497
453498VAL MKSTROFFc(VM* vm, StrOffset* off) {
454− Closure* cl = allocate(vm, sizeof(Closure) + sizeof(StrOffset), 1);
499+ Closure* cl = allocate(sizeof(Closure) + sizeof(StrOffset), 1);
455500 SETTY(cl, STROFFSET);
456501 cl->info.str_offset = (StrOffset*)((char*)cl + sizeof(Closure));
457502
@@ -465,7 +510,7 @@ VAL idris_strTail(VM* vm, VAL str) {
465510 // If there's no room, just copy the string, or we'll have a problem after
466511 // gc moves str
467512 if (space(vm, sizeof(Closure) + sizeof(StrOffset))) {
468− Closure* cl = allocate(vm, sizeof(Closure) + sizeof(StrOffset), 0);
513+ Closure* cl = allocate(sizeof(Closure) + sizeof(StrOffset), 0);
469514 SETTY(cl, STROFFSET);
470515 cl->info.str_offset = (StrOffset*)((char*)cl + sizeof(Closure));
471516
@@ -489,8 +534,8 @@ VAL idris_strTail(VM* vm, VAL str) {
489534
490535VAL idris_strCons(VM* vm, VAL x, VAL xs) {
491536 char *xstr = GETSTR(xs);
492− Closure* cl = allocate(vm, sizeof(Closure) +
493− strlen(xstr) + 2, 0);
537+ Closure* cl = allocate(sizeof(Closure) +
538+ strlen(xstr) + 2, 0);
494539 SETTY(cl, STRING);
495540 cl -> info.str = (char*)cl + sizeof(Closure);
496541 cl -> info.str[0] = (char)(GETINT(x));
@@ -504,8 +549,8 @@ VAL idris_strIndex(VM* vm, VAL str, VAL i) {
504549
505550VAL idris_strRev(VM* vm, VAL str) {
506551 char *xstr = GETSTR(str);
507− Closure* cl = allocate(vm, sizeof(Closure) +
508− strlen(xstr) + 1, 0);
552+ Closure* cl = allocate(sizeof(Closure) +
553+ strlen(xstr) + 1, 0);
509554 SETTY(cl, STRING);
510555 cl -> info.str = (char*)cl + sizeof(Closure);
511556 int y = 0;
@@ -532,7 +577,7 @@ VAL idris_systemInfo(VM* vm, VAL index) {
532577}
533578
534579VAL MKBUFFERc(VM* vm, Buffer* buf) {
535− Closure* cl = allocate(vm, sizeof(Closure) + sizeof *buf + buf->cap, 1);
580+ Closure* cl = allocate(sizeof(Closure) + sizeof *buf + buf->cap, 1);
536581 SETTY(cl, BUFFER);
537582 cl->info.buf = (Buffer*)((void*)cl + sizeof(Closure));
538583 memmove(cl->info.buf, buf, sizeof *buf + buf->fill);
@@ -549,7 +594,7 @@ static VAL internal_allocate(VM *vm, size_t hint) {
549594 size |= size >> (1 << i);
550595 ++size;
551596
552− Closure* cl = allocate(vm, size, 0);
597+ Closure* cl = allocate(size, 0);
553598 SETTY(cl, BUFFER);
554599 cl->info.buf = (Buffer*)((void*)cl + sizeof(Closure));
555600 cl->info.buf->cap = size - (sizeof(Closure) + sizeof(Buffer));
@@ -557,7 +602,7 @@ static VAL internal_allocate(VM *vm, size_t hint) {
557602}
558603
559604// Following functions cast uint64_t to size_t, which may narrow!
560−VAL idris_allocate(VM* vm, VAL hint) {
605+VAL idris_buffer_allocate(VM* vm, VAL hint) {
561606 Closure* cl = internal_allocate(vm, hint->info.bits64);
562607 cl->info.buf->fill = 0;
563608 return cl;
@@ -778,6 +823,8 @@ void* runThread(void* arg) {
778823 VM* vm = td->vm;
779824 VM* callvm = td->callvm;
780825
826+ init_threaddata(vm);
827+
781828 TOP(0) = td->arg;
782829 BASETOP(0);
783830 ADDTOP(1);
@@ -970,7 +1017,7 @@ VAL idris_recvMessage(VM* vm) {
9701017
9711018VAL* nullary_cons;
9721019
973−void initNullaries() {
1020+void init_nullaries() {
9741021 int i;
9751022 VAL cl;
9761023 nullary_cons = malloc(256 * sizeof(VAL));
@@ -982,7 +1029,7 @@ void initNullaries() {
9821029 }
9831030}
9841031
985−void freeNullaries() {
1032+void free_nullaries() {
9861033 int i;
9871034 for(i = 0; i < 256; ++i) {
9881035 free(nullary_cons[i]);
rts/idris_rts.h+19−19
@@ -108,9 +108,14 @@ typedef struct {
108108// Create a new VM
109109VM* init_vm(int stack_size, size_t heap_size,
110110 int max_threads);
111+// Initialise thread-local data for this VM
112+void init_threaddata(VM *vm);
111113// Clean up a VM once it's no longer needed
112114Stats terminate(VM* vm);
113115
116+// Set up key for thread-local data - called once from idris_main
117+void init_threadkeys();
118+
114119// Functions all take a pointer to their VM, and previous stack base,
115120// and return nothing.
116121typedef void(*func)(VM*, VAL*);
@@ -201,7 +206,7 @@ char* GETSTROFF(VAL stroff);
201206void PROJECT(VM* vm, VAL r, int loc, int arity);
202207void SLIDE(VM* vm, int args);
203208
204−void* allocate(VM* vm, size_t size, int outerlock);
209+void* allocate(size_t size, int outerlock);
205210// void* allocCon(VM* vm, int arity, int outerlock);
206211
207212// When allocating from C, call 'idris_requireAlloc' with a size to
@@ -210,11 +215,18 @@ void* allocate(VM* vm, size_t size, int outerlock);
210215// idris_doneAlloc *must* be called when allocation from C is done (as it
211216// may take a lock if other threads are running).
212217
213−void idris_requireAlloc(VM* vm, size_t size);
214−void idris_doneAlloc(VM* vm);
218+void idris_requireAlloc(size_t size);
219+void idris_doneAlloc();
220+
221+// public interface to allocation (note that this may move other pointers
222+// if allocating beyond the limits given by idris_requireAlloc!)
223+// 'realloc' just calls alloc and copies; 'free' does nothing
224+void* idris_alloc(size_t size);
225+void* idris_realloc(void* old, size_t old_size, size_t size);
226+void idris_free(void* ptr, size_t size);
215227
216228#define allocCon(cl, vm, t, a, o) \
217− cl = allocate(vm, sizeof(Closure) + sizeof(VAL)*a, o); \
229+ cl = allocate(sizeof(Closure) + sizeof(VAL)*a, o); \
218230 SETTY(cl, CON); \
219231 cl->info.c.tag_arity = ((t) << 8) | (a);
220232
@@ -226,8 +238,8 @@ void idris_doneAlloc(VM* vm);
226238#define NULL_CON(x) nullary_cons[x]
227239
228240extern VAL* nullary_cons;
229−void initNullaries();
230−void freeNullaries();
241+void init_nullaries();
242+void free_nullaries();
231243
232244void* vmThread(VM* callvm, func f, VAL arg);
233245
@@ -275,7 +287,7 @@ VAL idris_strIndex(VM* vm, VAL str, VAL i);
275287VAL idris_strRev(VM* vm, VAL str);
276288
277289// Buffer primitives
278−VAL idris_allocate(VM* vm, VAL hint);
290+VAL idris_buffer_allocate(VM* vm, VAL hint);
279291VAL idris_appendBuffer(VM* vm, VAL fst, VAL fstLen, VAL cnt, VAL sndLen, VAL sndOff, VAL snd);
280292VAL idris_appendB8Native(VM* vm, VAL buf, VAL len, VAL cnt, VAL val);
281293VAL idris_appendB16Native(VM* vm, VAL buf, VAL len, VAL cnt, VAL val);
@@ -317,18 +329,6 @@ const char *idris_getArg(int i);
317329
318330void stackOverflow();
319331
320−// Some FFI help (functions and macros below are all which C code should
321−// use)
322−
323−// When allocating from C, call 'idris_requireAlloc' with a size to
324−// guarantee that no garbage collection will happen (and hence nothing
325−// will move) until at least size bytes have been allocated.
326−// idris_doneAlloc *must* be called when allocation from C is done (as it
327−// may take a lock if other threads are running).
328−
329−void idris_requireAlloc(VM* vm, size_t size);
330−void idris_doneAlloc(VM* vm);
331−
332332// I think these names are nicer for an API...
333333
334334#define idris_constructor allocCon
src/IRTS/CodegenC.hs+1−1
@@ -480,7 +480,7 @@ doOp v LStrCons [x, y] = v ++ "idris_strCons(vm, " ++ creg x ++ "," ++ creg y ++
480480doOp v LStrIndex [x, y] = v ++ "idris_strIndex(vm, " ++ creg x ++ "," ++ creg y ++ ")"
481481doOp v LStrRev [x] = v ++ "idris_strRev(vm, " ++ creg x ++ ")"
482482
483−doOp v LAllocate [x] = v ++ "idris_allocate(vm, " ++ creg x ++ ")"
483+doOp v LAllocate [x] = v ++ "idris_buffer_allocate(vm, " ++ creg x ++ ")"
484484doOp v LAppendBuffer [a, b, c, d, e, f] = v ++ "idris_appendBuffer(vm, " ++ creg a ++ "," ++ creg b ++ "," ++ creg c ++ "," ++ creg d ++ "," ++ creg e ++ "," ++ creg f ++ ")"
485485doOp v (LAppend ity en) [a, b, c, d] = v ++ "idris_append" ++ intTyName ity ++ show en ++ "(vm, " ++ creg a ++ "," ++ creg b ++ "," ++ creg c ++ "," ++ creg d ++ ")"
486486doOp v (LPeek ity en) [x, y] = v ++ "idris_peek" ++ intTyName ity ++ show en ++ "(vm, " ++ creg x ++ "," ++ creg y ++ ")"