on master help sign in
Smaller closure
commitd16e78f145c5ab249a455e718abd3091a4309876 authorJorge Acereda <jacereda@gmail.com> dateSun 18 Mar 2018, 23:52 (9 years ago) parent9fc97f9
7 files changed+320−403
rts/idris_bitstring.c+146−146 rts/idris_buffer.c+5−18 rts/idris_gc.c+21−21 rts/idris_heap.c+2−2 rts/idris_rts.c+95−141 rts/idris_rts.h+45−69 src/IRTS/CodegenC.hs+6−6
rts/idris_bitstring.c+146−146
@@ -3,7 +3,7 @@
33#include "idris_rts.h"
44
55VAL idris_b8CopyForGC(VM *vm, VAL a) {
6− uint8_t A = a->info.bits8;
6+ uint8_t A = GETBITS8(a);
77 VAL cl = allocate(sizeof(Closure), 1);
88 SETTY(cl, CT_BITS8);
99 cl->info.bits8 = A;
@@ -11,7 +11,7 @@ VAL idris_b8CopyForGC(VM *vm, VAL a) {
1111}
1212
1313VAL idris_b16CopyForGC(VM *vm, VAL a) {
14− uint16_t A = a->info.bits16;
14+ uint16_t A = GETBITS16(a);
1515 VAL cl = allocate(sizeof(Closure), 1);
1616 SETTY(cl, CT_BITS16);
1717 cl->info.bits16 = A;
@@ -19,7 +19,7 @@ VAL idris_b16CopyForGC(VM *vm, VAL a) {
1919}
2020
2121VAL idris_b32CopyForGC(VM *vm, VAL a) {
22− uint32_t A = a->info.bits32;
22+ uint32_t A = GETBITS32(a);
2323 VAL cl = allocate(sizeof(Closure), 1);
2424 SETTY(cl, CT_BITS32);
2525 cl->info.bits32 = A;
@@ -27,7 +27,7 @@ VAL idris_b32CopyForGC(VM *vm, VAL a) {
2727}
2828
2929VAL idris_b64CopyForGC(VM *vm, VAL a) {
30− uint64_t A = a->info.bits64;
30+ uint64_t A = GETBITS64(a);
3131 VAL cl = allocate(sizeof(Closure), 1);
3232 SETTY(cl, CT_BITS64);
3333 cl->info.bits64 = A;
@@ -67,7 +67,7 @@ VAL idris_b64(VM *vm, VAL a) {
6767}
6868
6969VAL idris_castB32Int(VM *vm, VAL a) {
70− return MKINT((i_int)a->info.bits32);
70+ return MKINT(GETBITS32(a));
7171}
7272
7373VAL idris_b8const(VM *vm, uint8_t a) {
@@ -99,8 +99,8 @@ VAL idris_b64const(VM *vm, uint64_t a) {
9999}
100100
101101VAL idris_b8Plus(VM *vm, VAL a, VAL b) {
102− uint8_t A = a->info.bits8;
103− uint8_t B = b->info.bits8;
102+ uint8_t A = GETBITS8(a);
103+ uint8_t B = GETBITS8(b);
104104 VAL cl = allocate(sizeof(Closure), 0);
105105 SETTY(cl, CT_BITS8);
106106 cl->info.bits8 = A + B;
@@ -108,8 +108,8 @@ VAL idris_b8Plus(VM *vm, VAL a, VAL b) {
108108}
109109
110110VAL idris_b8Minus(VM *vm, VAL a, VAL b) {
111− uint8_t A = a->info.bits8;
112− uint8_t B = b->info.bits8;
111+ uint8_t A = GETBITS8(a);
112+ uint8_t B = GETBITS8(b);
113113 VAL cl = allocate(sizeof(Closure), 0);
114114 SETTY(cl, CT_BITS8);
115115 cl->info.bits8 = A - B;
@@ -117,8 +117,8 @@ VAL idris_b8Minus(VM *vm, VAL a, VAL b) {
117117}
118118
119119VAL idris_b8Times(VM *vm, VAL a, VAL b) {
120− uint8_t A = a->info.bits8;
121− uint8_t B = b->info.bits8;
120+ uint8_t A = GETBITS8(a);
121+ uint8_t B = GETBITS8(b);
122122 VAL cl = allocate(sizeof(Closure), 0);
123123 SETTY(cl, CT_BITS8);
124124 cl->info.bits8 = A * B;
@@ -126,8 +126,8 @@ VAL idris_b8Times(VM *vm, VAL a, VAL b) {
126126}
127127
128128VAL idris_b8UDiv(VM *vm, VAL a, VAL b) {
129− uint8_t A = a->info.bits8;
130− uint8_t B = b->info.bits8;
129+ uint8_t A = GETBITS8(a);
130+ uint8_t B = GETBITS8(b);
131131 VAL cl = allocate(sizeof(Closure), 0);
132132 SETTY(cl, CT_BITS8);
133133 cl->info.bits8 = A / B;
@@ -135,8 +135,8 @@ VAL idris_b8UDiv(VM *vm, VAL a, VAL b) {
135135}
136136
137137VAL idris_b8SDiv(VM *vm, VAL a, VAL b) {
138− uint8_t A = a->info.bits8;
139− uint8_t B = b->info.bits8;
138+ uint8_t A = GETBITS8(a);
139+ uint8_t B = GETBITS8(b);
140140 VAL cl = allocate(sizeof(Closure), 0);
141141 SETTY(cl, CT_BITS8);
142142 cl->info.bits8 = (uint8_t) (((int8_t) A) / ((int8_t) B));
@@ -144,8 +144,8 @@ VAL idris_b8SDiv(VM *vm, VAL a, VAL b) {
144144}
145145
146146VAL idris_b8URem(VM *vm, VAL a, VAL b) {
147− uint8_t A = a->info.bits8;
148− uint8_t B = b->info.bits8;
147+ uint8_t A = GETBITS8(a);
148+ uint8_t B = GETBITS8(b);
149149 VAL cl = allocate(sizeof(Closure), 0);
150150 SETTY(cl, CT_BITS8);
151151 cl->info.bits8 = A % B;
@@ -153,8 +153,8 @@ VAL idris_b8URem(VM *vm, VAL a, VAL b) {
153153}
154154
155155VAL idris_b8SRem(VM *vm, VAL a, VAL b) {
156− uint8_t A = a->info.bits8;
157− uint8_t B = b->info.bits8;
156+ uint8_t A = GETBITS8(a);
157+ uint8_t B = GETBITS8(b);
158158 VAL cl = allocate(sizeof(Closure), 0);
159159 SETTY(cl, CT_BITS8);
160160 cl->info.bits8 = (uint8_t) (((int8_t) A) % ((int8_t) B));
@@ -162,27 +162,27 @@ VAL idris_b8SRem(VM *vm, VAL a, VAL b) {
162162}
163163
164164VAL idris_b8Lt(VM *vm, VAL a, VAL b) {
165− return MKINT((i_int) (a->info.bits8 < b->info.bits8));
165+ return MKINT((i_int) (GETBITS8(a) < GETBITS8(b)));
166166}
167167
168168VAL idris_b8Gt(VM *vm, VAL a, VAL b) {
169− return MKINT((i_int) (a->info.bits8 > b->info.bits8));
169+ return MKINT((i_int) (GETBITS8(a) > GETBITS8(b)));
170170}
171171
172172VAL idris_b8Eq(VM *vm, VAL a, VAL b) {
173− return MKINT((i_int) (a->info.bits8 == b->info.bits8));
173+ return MKINT((i_int) (GETBITS8(a) == GETBITS8(b)));
174174}
175175
176176VAL idris_b8Lte(VM *vm, VAL a, VAL b) {
177− return MKINT((i_int) (a->info.bits8 <= b->info.bits8));
177+ return MKINT((i_int) (GETBITS8(a) <= GETBITS8(b)));
178178}
179179
180180VAL idris_b8Gte(VM *vm, VAL a, VAL b) {
181− return MKINT((i_int) (a->info.bits8 >= b->info.bits8));
181+ return MKINT((i_int) (GETBITS8(a) >= GETBITS8(b)));
182182}
183183
184184VAL idris_b8Compl(VM *vm, VAL a) {
185− uint8_t A = a->info.bits8;
185+ uint8_t A = GETBITS8(a);
186186 VAL cl = allocate(sizeof(Closure), 0);
187187 SETTY(cl, CT_BITS8);
188188 cl->info.bits8 = ~ A;
@@ -190,8 +190,8 @@ VAL idris_b8Compl(VM *vm, VAL a) {
190190}
191191
192192VAL idris_b8And(VM *vm, VAL a, VAL b) {
193− uint8_t A = a->info.bits8;
194− uint8_t B = b->info.bits8;
193+ uint8_t A = GETBITS8(a);
194+ uint8_t B = GETBITS8(b);
195195 VAL cl = allocate(sizeof(Closure), 0);
196196 SETTY(cl, CT_BITS8);
197197 cl->info.bits8 = A & B;
@@ -199,8 +199,8 @@ VAL idris_b8And(VM *vm, VAL a, VAL b) {
199199}
200200
201201VAL idris_b8Or(VM *vm, VAL a, VAL b) {
202− uint8_t A = a->info.bits8;
203− uint8_t B = b->info.bits8;
202+ uint8_t A = GETBITS8(a);
203+ uint8_t B = GETBITS8(b);
204204 VAL cl = allocate(sizeof(Closure), 0);
205205 SETTY(cl, CT_BITS8);
206206 cl->info.bits8 = A | B;
@@ -208,8 +208,8 @@ VAL idris_b8Or(VM *vm, VAL a, VAL b) {
208208}
209209
210210VAL idris_b8Xor(VM *vm, VAL a, VAL b) {
211− uint8_t A = a->info.bits8;
212− uint8_t B = b->info.bits8;
211+ uint8_t A = GETBITS8(a);
212+ uint8_t B = GETBITS8(b);
213213 VAL cl = allocate(sizeof(Closure), 0);
214214 SETTY(cl, CT_BITS8);
215215 cl->info.bits8 = A ^ B;
@@ -217,8 +217,8 @@ VAL idris_b8Xor(VM *vm, VAL a, VAL b) {
217217}
218218
219219VAL idris_b8Shl(VM *vm, VAL a, VAL b) {
220− uint8_t A = a->info.bits8;
221− uint8_t B = b->info.bits8;
220+ uint8_t A = GETBITS8(a);
221+ uint8_t B = GETBITS8(b);
222222 VAL cl = allocate(sizeof(Closure), 0);
223223 SETTY(cl, CT_BITS8);
224224 cl->info.bits8 = A << B;
@@ -226,8 +226,8 @@ VAL idris_b8Shl(VM *vm, VAL a, VAL b) {
226226}
227227
228228VAL idris_b8LShr(VM *vm, VAL a, VAL b) {
229− uint8_t A = a->info.bits8;
230− uint8_t B = b->info.bits8;
229+ uint8_t A = GETBITS8(a);
230+ uint8_t B = GETBITS8(b);
231231 VAL cl = allocate(sizeof(Closure), 0);
232232 SETTY(cl, CT_BITS8);
233233 cl->info.bits8 = A >> B;
@@ -235,8 +235,8 @@ VAL idris_b8LShr(VM *vm, VAL a, VAL b) {
235235}
236236
237237VAL idris_b8AShr(VM *vm, VAL a, VAL b) {
238− uint8_t A = a->info.bits8;
239− uint8_t B = b->info.bits8;
238+ uint8_t A = GETBITS8(a);
239+ uint8_t B = GETBITS8(b);
240240 VAL cl = allocate(sizeof(Closure), 0);
241241 SETTY(cl, CT_BITS8);
242242 cl->info.bits8 = (uint8_t) (((int8_t) A) >> ((int8_t) B));
@@ -244,8 +244,8 @@ VAL idris_b8AShr(VM *vm, VAL a, VAL b) {
244244}
245245
246246VAL idris_b16Plus(VM *vm, VAL a, VAL b) {
247− uint16_t A = a->info.bits16;
248− uint16_t B = b->info.bits16;
247+ uint16_t A = GETBITS16(a);
248+ uint16_t B = GETBITS16(b);
249249 VAL cl = allocate(sizeof(Closure), 0);
250250 SETTY(cl, CT_BITS16);
251251 cl->info.bits16 = A + B;
@@ -253,8 +253,8 @@ VAL idris_b16Plus(VM *vm, VAL a, VAL b) {
253253}
254254
255255VAL idris_b16Minus(VM *vm, VAL a, VAL b) {
256− uint16_t A = a->info.bits16;
257− uint16_t B = b->info.bits16;
256+ uint16_t A = GETBITS16(a);
257+ uint16_t B = GETBITS16(b);
258258 VAL cl = allocate(sizeof(Closure), 0);
259259 SETTY(cl, CT_BITS16);
260260 cl->info.bits16 = A - B;
@@ -262,8 +262,8 @@ VAL idris_b16Minus(VM *vm, VAL a, VAL b) {
262262}
263263
264264VAL idris_b16Times(VM *vm, VAL a, VAL b) {
265− uint16_t A = a->info.bits16;
266− uint16_t B = b->info.bits16;
265+ uint16_t A = GETBITS16(a);
266+ uint16_t B = GETBITS16(b);
267267 VAL cl = allocate(sizeof(Closure), 0);
268268 SETTY(cl, CT_BITS16);
269269 cl->info.bits16 = A * B;
@@ -271,8 +271,8 @@ VAL idris_b16Times(VM *vm, VAL a, VAL b) {
271271}
272272
273273VAL idris_b16UDiv(VM *vm, VAL a, VAL b) {
274− uint16_t A = a->info.bits16;
275− uint16_t B = b->info.bits16;
274+ uint16_t A = GETBITS16(a);
275+ uint16_t B = GETBITS16(b);
276276 VAL cl = allocate(sizeof(Closure), 0);
277277 SETTY(cl, CT_BITS16);
278278 cl->info.bits16 = A / B;
@@ -280,8 +280,8 @@ VAL idris_b16UDiv(VM *vm, VAL a, VAL b) {
280280}
281281
282282VAL idris_b16SDiv(VM *vm, VAL a, VAL b) {
283− uint16_t A = a->info.bits16;
284− uint16_t B = b->info.bits16;
283+ uint16_t A = GETBITS16(a);
284+ uint16_t B = GETBITS16(b);
285285 VAL cl = allocate(sizeof(Closure), 0);
286286 SETTY(cl, CT_BITS16);
287287 cl->info.bits16 = (uint16_t) (((int16_t) A) / ((int16_t) B));
@@ -289,8 +289,8 @@ VAL idris_b16SDiv(VM *vm, VAL a, VAL b) {
289289}
290290
291291VAL idris_b16URem(VM *vm, VAL a, VAL b) {
292− uint16_t A = a->info.bits16;
293− uint16_t B = b->info.bits16;
292+ uint16_t A = GETBITS16(a);
293+ uint16_t B = GETBITS16(b);
294294 VAL cl = allocate(sizeof(Closure), 0);
295295 SETTY(cl, CT_BITS16);
296296 cl->info.bits16 = A % B;
@@ -298,8 +298,8 @@ VAL idris_b16URem(VM *vm, VAL a, VAL b) {
298298}
299299
300300VAL idris_b16SRem(VM *vm, VAL a, VAL b) {
301− uint16_t A = a->info.bits16;
302− uint16_t B = b->info.bits16;
301+ uint16_t A = GETBITS16(a);
302+ uint16_t B = GETBITS16(b);
303303 VAL cl = allocate(sizeof(Closure), 0);
304304 SETTY(cl, CT_BITS16);
305305 cl->info.bits16 = (uint16_t) (((int16_t) A) % ((int16_t) B));
@@ -307,27 +307,27 @@ VAL idris_b16SRem(VM *vm, VAL a, VAL b) {
307307}
308308
309309VAL idris_b16Lt(VM *vm, VAL a, VAL b) {
310− return MKINT((i_int) (a->info.bits16 < b->info.bits16));
310+ return MKINT((i_int) (GETBITS16(a) < GETBITS16(b)));
311311}
312312
313313VAL idris_b16Gt(VM *vm, VAL a, VAL b) {
314− return MKINT((i_int) (a->info.bits16 > b->info.bits16));
314+ return MKINT((i_int) (GETBITS16(a) > GETBITS16(b)));
315315}
316316
317317VAL idris_b16Eq(VM *vm, VAL a, VAL b) {
318− return MKINT((i_int) (a->info.bits16 == b->info.bits16));
318+ return MKINT((i_int) (GETBITS16(a) == GETBITS16(b)));
319319}
320320
321321VAL idris_b16Lte(VM *vm, VAL a, VAL b) {
322− return MKINT((i_int) (a->info.bits16 <= b->info.bits16));
322+ return MKINT((i_int) (GETBITS16(a) <= GETBITS16(b)));
323323}
324324
325325VAL idris_b16Gte(VM *vm, VAL a, VAL b) {
326− return MKINT((i_int) (a->info.bits16 >= b->info.bits16));
326+ return MKINT((i_int) (GETBITS16(a) >= GETBITS16(b)));
327327}
328328
329329VAL idris_b16Compl(VM *vm, VAL a) {
330− uint16_t A = a->info.bits16;
330+ uint16_t A = GETBITS16(a);
331331 VAL cl = allocate(sizeof(Closure), 0);
332332 SETTY(cl, CT_BITS16);
333333 cl->info.bits16 = ~ A;
@@ -335,8 +335,8 @@ VAL idris_b16Compl(VM *vm, VAL a) {
335335}
336336
337337VAL idris_b16And(VM *vm, VAL a, VAL b) {
338− uint16_t A = a->info.bits16;
339− uint16_t B = b->info.bits16;
338+ uint16_t A = GETBITS16(a);
339+ uint16_t B = GETBITS16(b);
340340 VAL cl = allocate(sizeof(Closure), 0);
341341 SETTY(cl, CT_BITS16);
342342 cl->info.bits16 = A & B;
@@ -344,8 +344,8 @@ VAL idris_b16And(VM *vm, VAL a, VAL b) {
344344}
345345
346346VAL idris_b16Or(VM *vm, VAL a, VAL b) {
347− uint16_t A = a->info.bits16;
348− uint16_t B = b->info.bits16;
347+ uint16_t A = GETBITS16(a);
348+ uint16_t B = GETBITS16(b);
349349 VAL cl = allocate(sizeof(Closure), 0);
350350 SETTY(cl, CT_BITS16);
351351 cl->info.bits16 = A | B;
@@ -353,8 +353,8 @@ VAL idris_b16Or(VM *vm, VAL a, VAL b) {
353353}
354354
355355VAL idris_b16Xor(VM *vm, VAL a, VAL b) {
356− uint16_t A = a->info.bits16;
357− uint16_t B = b->info.bits16;
356+ uint16_t A = GETBITS16(a);
357+ uint16_t B = GETBITS16(b);
358358 VAL cl = allocate(sizeof(Closure), 0);
359359 SETTY(cl, CT_BITS16);
360360 cl->info.bits16 = A ^ B;
@@ -362,8 +362,8 @@ VAL idris_b16Xor(VM *vm, VAL a, VAL b) {
362362}
363363
364364VAL idris_b16Shl(VM *vm, VAL a, VAL b) {
365− uint16_t A = a->info.bits16;
366− uint16_t B = b->info.bits16;
365+ uint16_t A = GETBITS16(a);
366+ uint16_t B = GETBITS16(b);
367367 VAL cl = allocate(sizeof(Closure), 0);
368368 SETTY(cl, CT_BITS16);
369369 cl->info.bits16 = A << B;
@@ -371,8 +371,8 @@ VAL idris_b16Shl(VM *vm, VAL a, VAL b) {
371371}
372372
373373VAL idris_b16LShr(VM *vm, VAL a, VAL b) {
374− uint16_t A = a->info.bits16;
375− uint16_t B = b->info.bits16;
374+ uint16_t A = GETBITS16(a);
375+ uint16_t B = GETBITS16(b);
376376 VAL cl = allocate(sizeof(Closure), 0);
377377 SETTY(cl, CT_BITS16);
378378 cl->info.bits16 = A >> B;
@@ -380,8 +380,8 @@ VAL idris_b16LShr(VM *vm, VAL a, VAL b) {
380380}
381381
382382VAL idris_b16AShr(VM *vm, VAL a, VAL b) {
383− uint16_t A = a->info.bits16;
384− uint16_t B = b->info.bits16;
383+ uint16_t A = GETBITS16(a);
384+ uint16_t B = GETBITS16(b);
385385 VAL cl = allocate(sizeof(Closure), 0);
386386 SETTY(cl, CT_BITS16);
387387 cl->info.bits16 = (uint16_t) (((int16_t) A) >> ((int16_t) B));
@@ -389,8 +389,8 @@ VAL idris_b16AShr(VM *vm, VAL a, VAL b) {
389389}
390390
391391VAL idris_b32Plus(VM *vm, VAL a, VAL b) {
392− uint32_t A = a->info.bits32;
393− uint32_t B = b->info.bits32;
392+ uint32_t A = GETBITS32(a);
393+ uint32_t B = GETBITS32(b);
394394 VAL cl = allocate(sizeof(Closure), 0);
395395 SETTY(cl, CT_BITS32);
396396 cl->info.bits32 = A + B;
@@ -398,8 +398,8 @@ VAL idris_b32Plus(VM *vm, VAL a, VAL b) {
398398}
399399
400400VAL idris_b32Minus(VM *vm, VAL a, VAL b) {
401− uint32_t A = a->info.bits32;
402− uint32_t B = b->info.bits32;
401+ uint32_t A = GETBITS32(a);
402+ uint32_t B = GETBITS32(b);
403403 VAL cl = allocate(sizeof(Closure), 0);
404404 SETTY(cl, CT_BITS32);
405405 cl->info.bits32 = A - B;
@@ -407,8 +407,8 @@ VAL idris_b32Minus(VM *vm, VAL a, VAL b) {
407407}
408408
409409VAL idris_b32Times(VM *vm, VAL a, VAL b) {
410− uint32_t A = a->info.bits32;
411− uint32_t B = b->info.bits32;
410+ uint32_t A = GETBITS32(a);
411+ uint32_t B = GETBITS32(b);
412412 VAL cl = allocate(sizeof(Closure), 0);
413413 SETTY(cl, CT_BITS32);
414414 cl->info.bits32 = A * B;
@@ -416,8 +416,8 @@ VAL idris_b32Times(VM *vm, VAL a, VAL b) {
416416}
417417
418418VAL idris_b32UDiv(VM *vm, VAL a, VAL b) {
419− uint32_t A = a->info.bits32;
420− uint32_t B = b->info.bits32;
419+ uint32_t A = GETBITS32(a);
420+ uint32_t B = GETBITS32(b);
421421 VAL cl = allocate(sizeof(Closure), 0);
422422 SETTY(cl, CT_BITS32);
423423 cl->info.bits32 = A / B;
@@ -425,8 +425,8 @@ VAL idris_b32UDiv(VM *vm, VAL a, VAL b) {
425425}
426426
427427VAL idris_b32SDiv(VM *vm, VAL a, VAL b) {
428− uint32_t A = a->info.bits32;
429− uint32_t B = b->info.bits32;
428+ uint32_t A = GETBITS32(a);
429+ uint32_t B = GETBITS32(b);
430430 VAL cl = allocate(sizeof(Closure), 0);
431431 SETTY(cl, CT_BITS32);
432432 cl->info.bits32 = (uint32_t) (((int32_t) A) / ((int32_t) B));
@@ -434,8 +434,8 @@ VAL idris_b32SDiv(VM *vm, VAL a, VAL b) {
434434}
435435
436436VAL idris_b32URem(VM *vm, VAL a, VAL b) {
437− uint32_t A = a->info.bits32;
438− uint32_t B = b->info.bits32;
437+ uint32_t A = GETBITS32(a);
438+ uint32_t B = GETBITS32(b);
439439 VAL cl = allocate(sizeof(Closure), 0);
440440 SETTY(cl, CT_BITS32);
441441 cl->info.bits32 = A % B;
@@ -443,8 +443,8 @@ VAL idris_b32URem(VM *vm, VAL a, VAL b) {
443443}
444444
445445VAL idris_b32SRem(VM *vm, VAL a, VAL b) {
446− uint32_t A = a->info.bits32;
447− uint32_t B = b->info.bits32;
446+ uint32_t A = GETBITS32(a);
447+ uint32_t B = GETBITS32(b);
448448 VAL cl = allocate(sizeof(Closure), 0);
449449 SETTY(cl, CT_BITS32);
450450 cl->info.bits32 = (uint32_t) (((int32_t) A) % ((int32_t) B));
@@ -452,27 +452,27 @@ VAL idris_b32SRem(VM *vm, VAL a, VAL b) {
452452}
453453
454454VAL idris_b32Lt(VM *vm, VAL a, VAL b) {
455− return MKINT((i_int) (a->info.bits32 < b->info.bits32));
455+ return MKINT((i_int) (GETBITS32(a) < GETBITS32(b)));
456456}
457457
458458VAL idris_b32Gt(VM *vm, VAL a, VAL b) {
459− return MKINT((i_int) (a->info.bits32 > b->info.bits32));
459+ return MKINT((i_int) (GETBITS32(a) > GETBITS32(b)));
460460}
461461
462462VAL idris_b32Eq(VM *vm, VAL a, VAL b) {
463− return MKINT((i_int) (a->info.bits32 == b->info.bits32));
463+ return MKINT((i_int) (GETBITS32(a) == GETBITS32(b)));
464464}
465465
466466VAL idris_b32Lte(VM *vm, VAL a, VAL b) {
467− return MKINT((i_int) (a->info.bits32 <= b->info.bits32));
467+ return MKINT((i_int) (GETBITS32(a) <= GETBITS32(b)));
468468}
469469
470470VAL idris_b32Gte(VM *vm, VAL a, VAL b) {
471− return MKINT((i_int) (a->info.bits32 >= b->info.bits32));
471+ return MKINT((i_int) (GETBITS32(a) >= GETBITS32(b)));
472472}
473473
474474VAL idris_b32Compl(VM *vm, VAL a) {
475− uint32_t A = a->info.bits32;
475+ uint32_t A = GETBITS32(a);
476476 VAL cl = allocate(sizeof(Closure), 0);
477477 SETTY(cl, CT_BITS32);
478478 cl->info.bits32 = ~ A;
@@ -480,8 +480,8 @@ VAL idris_b32Compl(VM *vm, VAL a) {
480480}
481481
482482VAL idris_b32And(VM *vm, VAL a, VAL b) {
483− uint32_t A = a->info.bits32;
484− uint32_t B = b->info.bits32;
483+ uint32_t A = GETBITS32(a);
484+ uint32_t B = GETBITS32(b);
485485 VAL cl = allocate(sizeof(Closure), 0);
486486 SETTY(cl, CT_BITS32);
487487 cl->info.bits32 = A & B;
@@ -489,8 +489,8 @@ VAL idris_b32And(VM *vm, VAL a, VAL b) {
489489}
490490
491491VAL idris_b32Or(VM *vm, VAL a, VAL b) {
492− uint32_t A = a->info.bits32;
493− uint32_t B = b->info.bits32;
492+ uint32_t A = GETBITS32(a);
493+ uint32_t B = GETBITS32(b);
494494 VAL cl = allocate(sizeof(Closure), 0);
495495 SETTY(cl, CT_BITS32);
496496 cl->info.bits32 = A | B;
@@ -498,8 +498,8 @@ VAL idris_b32Or(VM *vm, VAL a, VAL b) {
498498}
499499
500500VAL idris_b32Xor(VM *vm, VAL a, VAL b) {
501− uint32_t A = a->info.bits32;
502− uint32_t B = b->info.bits32;
501+ uint32_t A = GETBITS32(a);
502+ uint32_t B = GETBITS32(b);
503503 VAL cl = allocate(sizeof(Closure), 0);
504504 SETTY(cl, CT_BITS32);
505505 cl->info.bits32 = A ^ B;
@@ -507,8 +507,8 @@ VAL idris_b32Xor(VM *vm, VAL a, VAL b) {
507507}
508508
509509VAL idris_b32Shl(VM *vm, VAL a, VAL b) {
510− uint32_t A = a->info.bits32;
511− uint32_t B = b->info.bits32;
510+ uint32_t A = GETBITS32(a);
511+ uint32_t B = GETBITS32(b);
512512 VAL cl = allocate(sizeof(Closure), 0);
513513 SETTY(cl, CT_BITS32);
514514 cl->info.bits32 = A << B;
@@ -516,8 +516,8 @@ VAL idris_b32Shl(VM *vm, VAL a, VAL b) {
516516}
517517
518518VAL idris_b32LShr(VM *vm, VAL a, VAL b) {
519− uint32_t A = a->info.bits32;
520− uint32_t B = b->info.bits32;
519+ uint32_t A = GETBITS32(a);
520+ uint32_t B = GETBITS32(b);
521521 VAL cl = allocate(sizeof(Closure), 0);
522522 SETTY(cl, CT_BITS32);
523523 cl->info.bits32 = A >> B;
@@ -525,8 +525,8 @@ VAL idris_b32LShr(VM *vm, VAL a, VAL b) {
525525}
526526
527527VAL idris_b32AShr(VM *vm, VAL a, VAL b) {
528− uint32_t A = a->info.bits32;
529− uint32_t B = b->info.bits32;
528+ uint32_t A = GETBITS32(a);
529+ uint32_t B = GETBITS32(b);
530530 VAL cl = allocate(sizeof(Closure), 0);
531531 SETTY(cl, CT_BITS32);
532532 cl->info.bits32 = (uint32_t) (((int32_t)A) >> ((int32_t)B));
@@ -534,8 +534,8 @@ VAL idris_b32AShr(VM *vm, VAL a, VAL b) {
534534}
535535
536536VAL idris_b64Plus(VM *vm, VAL a, VAL b) {
537− uint64_t A = a->info.bits64;
538− uint64_t B = b->info.bits64;
537+ uint64_t A = GETBITS64(a);
538+ uint64_t B = GETBITS64(b);
539539 VAL cl = allocate(sizeof(Closure), 0);
540540 SETTY(cl, CT_BITS64);
541541 cl->info.bits64 = A + B;
@@ -543,8 +543,8 @@ VAL idris_b64Plus(VM *vm, VAL a, VAL b) {
543543}
544544
545545VAL idris_b64Minus(VM *vm, VAL a, VAL b) {
546− uint64_t A = a->info.bits64;
547− uint64_t B = b->info.bits64;
546+ uint64_t A = GETBITS64(a);
547+ uint64_t B = GETBITS64(b);
548548 VAL cl = allocate(sizeof(Closure), 0);
549549 SETTY(cl, CT_BITS64);
550550 cl->info.bits64 = A - B;
@@ -552,8 +552,8 @@ VAL idris_b64Minus(VM *vm, VAL a, VAL b) {
552552}
553553
554554VAL idris_b64Times(VM *vm, VAL a, VAL b) {
555− uint64_t A = a->info.bits64;
556− uint64_t B = b->info.bits64;
555+ uint64_t A = GETBITS64(a);
556+ uint64_t B = GETBITS64(b);
557557 VAL cl = allocate(sizeof(Closure), 0);
558558 SETTY(cl, CT_BITS64);
559559 cl->info.bits64 = A * B;
@@ -561,8 +561,8 @@ VAL idris_b64Times(VM *vm, VAL a, VAL b) {
561561}
562562
563563VAL idris_b64UDiv(VM *vm, VAL a, VAL b) {
564− uint64_t A = a->info.bits64;
565− uint64_t B = b->info.bits64;
564+ uint64_t A = GETBITS64(a);
565+ uint64_t B = GETBITS64(b);
566566 VAL cl = allocate(sizeof(Closure), 0);
567567 SETTY(cl, CT_BITS64);
568568 cl->info.bits64 = A / B;
@@ -570,8 +570,8 @@ VAL idris_b64UDiv(VM *vm, VAL a, VAL b) {
570570}
571571
572572VAL idris_b64SDiv(VM *vm, VAL a, VAL b) {
573− uint64_t A = a->info.bits64;
574− uint64_t B = b->info.bits64;
573+ uint64_t A = GETBITS64(a);
574+ uint64_t B = GETBITS64(b);
575575 VAL cl = allocate(sizeof(Closure), 0);
576576 SETTY(cl, CT_BITS64);
577577 cl->info.bits64 = (uint64_t) (((int64_t) A) / ((int64_t) B));
@@ -579,8 +579,8 @@ VAL idris_b64SDiv(VM *vm, VAL a, VAL b) {
579579}
580580
581581VAL idris_b64URem(VM *vm, VAL a, VAL b) {
582− uint64_t A = a->info.bits64;
583− uint64_t B = b->info.bits64;
582+ uint64_t A = GETBITS64(a);
583+ uint64_t B = GETBITS64(b);
584584 VAL cl = allocate(sizeof(Closure), 0);
585585 SETTY(cl, CT_BITS64);
586586 cl->info.bits64 = A % B;
@@ -588,8 +588,8 @@ VAL idris_b64URem(VM *vm, VAL a, VAL b) {
588588}
589589
590590VAL idris_b64SRem(VM *vm, VAL a, VAL b) {
591− uint64_t A = a->info.bits64;
592− uint64_t B = b->info.bits64;
591+ uint64_t A = GETBITS64(a);
592+ uint64_t B = GETBITS64(b);
593593 VAL cl = allocate(sizeof(Closure), 0);
594594 SETTY(cl, CT_BITS64);
595595 cl->info.bits64 = (uint64_t) (((int64_t) A) % ((int64_t) B));
@@ -617,7 +617,7 @@ VAL idris_b64Gte(VM *vm, VAL a, VAL b) {
617617}
618618
619619VAL idris_b64Compl(VM *vm, VAL a) {
620− uint64_t A = a->info.bits64;
620+ uint64_t A = GETBITS64(a);
621621 VAL cl = allocate(sizeof(Closure), 0);
622622 SETTY(cl, CT_BITS64);
623623 cl->info.bits64 = ~ A;
@@ -625,8 +625,8 @@ VAL idris_b64Compl(VM *vm, VAL a) {
625625}
626626
627627VAL idris_b64And(VM *vm, VAL a, VAL b) {
628− uint64_t A = a->info.bits64;
629− uint64_t B = b->info.bits64;
628+ uint64_t A = GETBITS64(a);
629+ uint64_t B = GETBITS64(b);
630630 VAL cl = allocate(sizeof(Closure), 0);
631631 SETTY(cl, CT_BITS64);
632632 cl->info.bits64 = A & B;
@@ -634,8 +634,8 @@ VAL idris_b64And(VM *vm, VAL a, VAL b) {
634634}
635635
636636VAL idris_b64Or(VM *vm, VAL a, VAL b) {
637− uint64_t A = a->info.bits64;
638− uint64_t B = b->info.bits64;
637+ uint64_t A = GETBITS64(a);
638+ uint64_t B = GETBITS64(b);
639639 VAL cl = allocate(sizeof(Closure), 0);
640640 SETTY(cl, CT_BITS64);
641641 cl->info.bits64 = A | B;
@@ -643,8 +643,8 @@ VAL idris_b64Or(VM *vm, VAL a, VAL b) {
643643}
644644
645645VAL idris_b64Xor(VM *vm, VAL a, VAL b) {
646− uint64_t A = a->info.bits64;
647− uint64_t B = b->info.bits64;
646+ uint64_t A = GETBITS64(a);
647+ uint64_t B = GETBITS64(b);
648648 VAL cl = allocate(sizeof(Closure), 0);
649649 SETTY(cl, CT_BITS64);
650650 cl->info.bits64 = A ^ B;
@@ -652,8 +652,8 @@ VAL idris_b64Xor(VM *vm, VAL a, VAL b) {
652652}
653653
654654VAL idris_b64Shl(VM *vm, VAL a, VAL b) {
655− uint64_t A = a->info.bits64;
656− uint64_t B = b->info.bits64;
655+ uint64_t A = GETBITS64(a);
656+ uint64_t B = GETBITS64(b);
657657 VAL cl = allocate(sizeof(Closure), 0);
658658 SETTY(cl, CT_BITS64);
659659 cl->info.bits64 = A << B;
@@ -661,8 +661,8 @@ VAL idris_b64Shl(VM *vm, VAL a, VAL b) {
661661}
662662
663663VAL idris_b64LShr(VM *vm, VAL a, VAL b) {
664− uint64_t A = a->info.bits64;
665− uint64_t B = b->info.bits64;
664+ uint64_t A = GETBITS64(a);
665+ uint64_t B = GETBITS64(b);
666666 VAL cl = allocate(sizeof(Closure), 0);
667667 SETTY(cl, CT_BITS64);
668668 cl->info.bits64 = A >> B;
@@ -670,8 +670,8 @@ VAL idris_b64LShr(VM *vm, VAL a, VAL b) {
670670}
671671
672672VAL idris_b64AShr(VM *vm, VAL a, VAL b) {
673− uint64_t A = a->info.bits64;
674− uint64_t B = b->info.bits64;
673+ uint64_t A = GETBITS64(a);
674+ uint64_t B = GETBITS64(b);
675675 VAL cl = allocate(sizeof(Closure), 0);
676676 SETTY(cl, CT_BITS64);
677677 cl->info.bits64 = (uint64_t) (((int64_t) A) >> ((int64_t) B));
@@ -679,7 +679,7 @@ VAL idris_b64AShr(VM *vm, VAL a, VAL b) {
679679}
680680
681681VAL idris_b8Z16(VM *vm, VAL a) {
682− uint8_t A = a->info.bits8;
682+ uint8_t A = GETBITS8(a);
683683 VAL cl = allocate(sizeof(Closure), 0);
684684 SETTY(cl, CT_BITS16);
685685 cl->info.bits16 = (uint16_t) A;
@@ -687,7 +687,7 @@ VAL idris_b8Z16(VM *vm, VAL a) {
687687}
688688
689689VAL idris_b8Z32(VM *vm, VAL a) {
690− uint8_t A = a->info.bits8;
690+ uint8_t A = GETBITS8(a);
691691 VAL cl = allocate(sizeof(Closure), 0);
692692 SETTY(cl, CT_BITS32);
693693 cl->info.bits32 = (uint32_t) A;
@@ -695,7 +695,7 @@ VAL idris_b8Z32(VM *vm, VAL a) {
695695}
696696
697697VAL idris_b8Z64(VM *vm, VAL a) {
698− uint8_t A = a->info.bits8;
698+ uint8_t A = GETBITS8(a);
699699 VAL cl = allocate(sizeof(Closure), 0);
700700 SETTY(cl, CT_BITS64);
701701 cl->info.bits64 = (uint64_t) A;
@@ -703,7 +703,7 @@ VAL idris_b8Z64(VM *vm, VAL a) {
703703}
704704
705705VAL idris_b8S16(VM *vm, VAL a) {
706− uint8_t A = a->info.bits8;
706+ uint8_t A = GETBITS8(a);
707707 VAL cl = allocate(sizeof(Closure), 0);
708708 SETTY(cl, CT_BITS16);
709709 cl->info.bits16 = (uint16_t) (int16_t) (int8_t) A;
@@ -711,7 +711,7 @@ VAL idris_b8S16(VM *vm, VAL a) {
711711}
712712
713713VAL idris_b8S32(VM *vm, VAL a) {
714− uint8_t A = a->info.bits8;
714+ uint8_t A = GETBITS8(a);
715715 VAL cl = allocate(sizeof(Closure), 0);
716716 SETTY(cl, CT_BITS32);
717717 cl->info.bits32 = (uint32_t) (int32_t) (int8_t) A;
@@ -719,7 +719,7 @@ VAL idris_b8S32(VM *vm, VAL a) {
719719}
720720
721721VAL idris_b8S64(VM *vm, VAL a) {
722− uint8_t A = a->info.bits8;
722+ uint8_t A = GETBITS8(a);
723723 VAL cl = allocate(sizeof(Closure), 0);
724724 SETTY(cl, CT_BITS64);
725725 cl->info.bits64 = (uint64_t) (int64_t) (int8_t) A;
@@ -727,7 +727,7 @@ VAL idris_b8S64(VM *vm, VAL a) {
727727}
728728
729729VAL idris_b16Z32(VM *vm, VAL a) {
730− uint16_t A = a->info.bits16;
730+ uint16_t A = GETBITS16(a);
731731 VAL cl = allocate(sizeof(Closure), 0);
732732 SETTY(cl, CT_BITS32);
733733 cl->info.bits32 = (uint32_t) A;
@@ -735,7 +735,7 @@ VAL idris_b16Z32(VM *vm, VAL a) {
735735}
736736
737737VAL idris_b16Z64(VM *vm, VAL a) {
738− uint16_t A = a->info.bits16;
738+ uint16_t A = GETBITS16(a);
739739 VAL cl = allocate(sizeof(Closure), 0);
740740 SETTY(cl, CT_BITS64);
741741 cl->info.bits64 = (uint64_t) A;
@@ -743,7 +743,7 @@ VAL idris_b16Z64(VM *vm, VAL a) {
743743}
744744
745745VAL idris_b16S32(VM *vm, VAL a) {
746− uint16_t A = a->info.bits16;
746+ uint16_t A = GETBITS16(a);
747747 VAL cl = allocate(sizeof(Closure), 0);
748748 SETTY(cl, CT_BITS32);
749749 cl->info.bits32 = (uint32_t) (int32_t) (int16_t) A;
@@ -751,7 +751,7 @@ VAL idris_b16S32(VM *vm, VAL a) {
751751}
752752
753753VAL idris_b16S64(VM *vm, VAL a) {
754− uint16_t A = a->info.bits16;
754+ uint16_t A = GETBITS16(a);
755755 VAL cl = allocate(sizeof(Closure), 0);
756756 SETTY(cl, CT_BITS64);
757757 cl->info.bits64 = (uint64_t) (int64_t) (int16_t) A;
@@ -759,7 +759,7 @@ VAL idris_b16S64(VM *vm, VAL a) {
759759}
760760
761761VAL idris_b16T8(VM *vm, VAL a) {
762− uint16_t A = a->info.bits16;
762+ uint16_t A = GETBITS16(a);
763763 VAL cl = allocate(sizeof(Closure), 0);
764764 SETTY(cl, CT_BITS8);
765765 cl->info.bits8 = (uint8_t) A;
@@ -767,7 +767,7 @@ VAL idris_b16T8(VM *vm, VAL a) {
767767}
768768
769769VAL idris_b32Z64(VM *vm, VAL a) {
770− uint32_t A = a->info.bits32;
770+ uint32_t A = GETBITS32(a);
771771 VAL cl = allocate(sizeof(Closure), 0);
772772 SETTY(cl, CT_BITS64);
773773 cl->info.bits64 = (uint64_t) A;
@@ -775,7 +775,7 @@ VAL idris_b32Z64(VM *vm, VAL a) {
775775}
776776
777777VAL idris_b32S64(VM *vm, VAL a) {
778− uint32_t A = a->info.bits32;
778+ uint32_t A = GETBITS32(a);
779779 VAL cl = allocate(sizeof(Closure), 0);
780780 SETTY(cl, CT_BITS64);
781781 cl->info.bits64 = (uint64_t) (int64_t) (int32_t) A;
@@ -783,7 +783,7 @@ VAL idris_b32S64(VM *vm, VAL a) {
783783}
784784
785785VAL idris_b32T8(VM *vm, VAL a) {
786− uint32_t A = a->info.bits32;
786+ uint32_t A = GETBITS32(a);
787787 VAL cl = allocate(sizeof(Closure), 0);
788788 SETTY(cl, CT_BITS8);
789789 cl->info.bits8 = (uint8_t) A;
@@ -791,7 +791,7 @@ VAL idris_b32T8(VM *vm, VAL a) {
791791}
792792
793793VAL idris_b32T16(VM *vm, VAL a) {
794− uint32_t A = a->info.bits32;
794+ uint32_t A = GETBITS32(a);
795795 VAL cl = allocate(sizeof(Closure), 0);
796796 SETTY(cl, CT_BITS16);
797797 cl->info.bits16 = (uint16_t) A;
@@ -799,7 +799,7 @@ VAL idris_b32T16(VM *vm, VAL a) {
799799}
800800
801801VAL idris_b64T8(VM *vm, VAL a) {
802− uint64_t A = a->info.bits64;
802+ uint64_t A = GETBITS64(a);
803803 VAL cl = allocate(sizeof(Closure), 0);
804804 SETTY(cl, CT_BITS8);
805805 cl->info.bits8 = (uint8_t) A;
@@ -807,7 +807,7 @@ VAL idris_b64T8(VM *vm, VAL a) {
807807}
808808
809809VAL idris_b64T16(VM *vm, VAL a) {
810− uint64_t A = a->info.bits64;
810+ uint64_t A = GETBITS64(a);
811811 VAL cl = allocate(sizeof(Closure), 0);
812812 SETTY(cl, CT_BITS16);
813813 cl->info.bits16 = (uint16_t) A;
@@ -815,7 +815,7 @@ VAL idris_b64T16(VM *vm, VAL a) {
815815}
816816
817817VAL idris_b64T32(VM *vm, VAL a) {
818− uint64_t A = a->info.bits64;
818+ uint64_t A = GETBITS64(a);
819819 VAL cl = allocate(sizeof(Closure), 0);
820820 SETTY(cl, CT_BITS32);
821821 cl->info.bits32 = (uint32_t) A;
rts/idris_buffer.c+5−18
@@ -82,9 +82,9 @@ uint8_t idris_getBufferByte(void* buffer, int loc) {
8282int idris_getBufferInt(void* buffer, int loc) {
8383 Buffer* b = buffer;
8484 if (loc >= 0 && loc+3 < b->size) {
85− return b->data[loc] +
85+ return b->data[loc] +
8686 (b->data[loc+1] << 8) +
87− (b->data[loc+2] << 16) +
87+ (b->data[loc+2] << 16) +
8888 (b->data[loc+3] << 24);
8989 } else {
9090 return 0;
@@ -111,21 +111,9 @@ double idris_getBufferDouble(void* buffer, int loc) {
111111VAL idris_getBufferString(void* buffer, int loc, int len) {
112112 Buffer* b = buffer;
113113
114− Closure* cl = allocate(sizeof(Closure) + // Type) + sizeof(char*) +
115− sizeof(char)*(len+1), 0);
116− SETTY(cl, CT_STRING);
117− cl->info.str.str = (char*)cl + sizeof(Closure);
118−
119− if (loc >= 0 && loc+len <= b->size) {
120− memcpy(cl->info.str.str, (b->data)+loc, len);
121− cl->info.str.str[len]='\0';
122− cl->info.str.len = len;
123− } else {
124− cl->info.str.str[0] = '\0';
125− cl->info.str.len = 0;
126− }
127−
128− return cl;
114+ char * s = (char*)(b->data + loc);
115+ size_t sz = loc >= 0 && loc+len <= b->size? len : 0;
116+ return MKSTRlen(NULL, s, sz);
129117}
130118
131119int idris_readBuffer(FILE* h, void* buffer, int loc, int max) {
@@ -153,4 +141,3 @@ void idris_writeBuffer(FILE* h, void* buffer, int loc, int len) {
153141 fwrite((b->data)+loc, sizeof(uint8_t), len, h);
154142 }
155143}
156−
rts/idris_gc.c+21−21
@@ -17,31 +17,31 @@ VAL copy(VM* vm, VAL x) {
1717 return x;
1818 } else {
1919 allocCon(cl, vm, CTAG(x), ar, 1);
20− memcpy(&(cl->info.c.args), &(x->info.c.args), sizeof(VAL)*ar);
20+ memcpy(cl->info.cargs, x->info.cargs, sizeof(VAL)*ar);
2121 }
2222 break;
2323 case CT_ARRAY:
24− len = x->info.arr.length;
24+ len = x->sz;
2525 allocArray(cl, vm, len, 1);
26− memcpy(&(cl->info.arr.content), &(x->info.arr.content), sizeof(VAL)*len);
26+ memcpy(cl->info.array, x->info.array, sizeof(VAL)*len);
2727 break;
2828 case CT_FLOAT:
29− cl = MKFLOATc(vm, x->info.f);
29+ cl = MKFLOATc(vm, GETFLOAT(x));
3030 break;
3131 case CT_STRING:
32− cl = MKSTRclen(vm, x->info.str.str, x->info.str.len);
32+ cl = MKSTRclen(vm, x->info.str, x->sz);
3333 break;
3434 case CT_STROFFSET:
3535 cl = MKSTROFFc(vm, x->info.str_offset);
3636 break;
3737 case CT_BIGINT:
38− cl = MKBIGMc(vm, x->info.ptr);
38+ cl = MKBIGMc(vm, GETPTR(x));
3939 break;
4040 case CT_PTR:
41− cl = MKPTRc(vm, x->info.ptr);
41+ cl = MKPTRc(vm, GETPTR(x));
4242 break;
4343 case CT_MANAGEDPTR:
44− cl = MKMPTRc(vm, x->info.mptr->data, x->info.mptr->size);
44+ cl = MKMPTRc(vm, x->info.managed_ptr, x->sz);
4545 break;
4646 case CT_BITS8:
4747 cl = idris_b8CopyForGC(vm, x);
@@ -56,20 +56,20 @@ VAL copy(VM* vm, VAL x) {
5656 cl = idris_b64CopyForGC(vm, x);
5757 break;
5858 case CT_REF:
59− cl = idris_newRefLock((VAL)(x->info.ptr), 1);
59+ cl = idris_newRefLock((VAL)(GETPTR(x)), 1);
6060 break;
6161 case CT_FWD:
62− return x->info.ptr;
62+ return GETPTR(x);
6363 case CT_RAWDATA:
6464 {
65− size_t size = x->info.size + sizeof(Closure);
65+ size_t size = x->sz + sizeof(Closure);
6666 cl = allocate(size, 1);
6767 memcpy(cl, x, size);
6868 }
6969 break;
7070 case CT_CDATA:
71− cl = MKCDATAc(vm, x->info.c_heap_item);
72− c_heap_mark_item(x->info.c_heap_item);
71+ cl = MKCDATAc(vm, GETCDATA(x));
72+ c_heap_mark_item(GETCDATA(x));
7373 break;
7474 default:
7575 break;
@@ -92,23 +92,23 @@ void cheney(VM *vm) {
9292 case CT_CON:
9393 ar = ARITY(heap_item);
9494 for(i = 0; i < ar; ++i) {
95− VAL newptr = copy(vm, heap_item->info.c.args[i]);
96− heap_item->info.c.args[i] = newptr;
95+ VAL newptr = copy(vm, heap_item->info.cargs[i]);
96+ heap_item->info.cargs[i] = newptr;
9797 }
9898 break;
9999 case CT_ARRAY:
100− len = heap_item->info.arr.length;
100+ len = heap_item->sz;
101101 for(i = 0; i < len; ++i) {
102− VAL newptr = copy(vm, heap_item->info.arr.content[i]);
103− heap_item->info.arr.content[i] = newptr;
102+ VAL newptr = copy(vm, heap_item->info.array[i]);
103+ heap_item->info.array[i] = newptr;
104104 }
105105 break;
106106 case CT_REF:
107− heap_item->info.ptr = copy(vm, (VAL)(heap_item->info.ptr));
107+ heap_item->info.ptr = copy(vm, (VAL)(GETPTR(heap_item)));
108108 break;
109109 case CT_STROFFSET:
110− heap_item->info.str_offset->str
111− = copy(vm, heap_item->info.str_offset->str);
110+ heap_item->info.str_offset
111+ = copy(vm, heap_item->info.str_offset);
112112 break;
113113 default: // Nothing to copy
114114 break;
rts/idris_heap.c+2−2
@@ -55,7 +55,7 @@ void c_heap_insert_if_needed(VM * vm, CHeap * heap, CHeapItem * item)
5555 heap->first = item;
5656
5757 // at this point, links are done; let's calculate sizes
58−
58+
5959 heap->size += item->size;
6060 if (heap->size >= heap->gc_trigger_size)
6161 {
@@ -195,7 +195,7 @@ void heap_check_pointers(Heap * heap) {
195195 int ar = ARITY(heap_item);
196196 int i = 0;
197197 for(i = 0; i < ar; ++i) {
198− VAL ptr = heap_item->info.c.args[i];
198+ VAL ptr = heap_item->info.cargs[i];
199199
200200 if (is_valid_ref(ptr)) {
201201 // Check for closure.
rts/idris_rts.c+95−141
@@ -7,6 +7,11 @@
77#include "idris_bitstring.h"
88#include "getline.h"
99
10+#define STATIC_ASSERT(COND,MSG) typedef char static_assertion_##MSG[(COND)?1:-1]
11+
12+
13+STATIC_ASSERT(sizeof(Closure) == 16, sizeofClosure);
14+
1015#ifdef HAS_PTHREAD
1116static pthread_key_t vm_key;
1217#else
@@ -190,8 +195,8 @@ int space(VM* vm, size_t size) {
190195void* idris_alloc(size_t size) {
191196 Closure* cl = (Closure*) allocate(sizeof(Closure)+size, 0);
192197 SETTY(cl, CT_RAWDATA);
193− cl->info.size = size;
194− return (void*)((char *)cl+sizeof(Closure));
198+ cl->sz = size;
199+ return (void*)(cl+1);
195200}
196201
197202void* idris_realloc(void* old, size_t old_size, size_t size) {
@@ -255,6 +260,14 @@ void* allocate(size_t size, int outerlock) {
255260
256261}
257262
263+static Closure * allocStr(size_t len, int outer) {
264+ Closure * cl = allocate(sizeof(*cl) + len + 1, outer);
265+ SETTY(cl, CT_STRING);
266+ cl->info.str = cl->data;
267+ cl->sz = len;
268+ return cl;
269+}
270+
258271/* Now a macro
259272void* allocCon(VM* vm, int arity, int outer) {
260273 Closure* cl = allocate(vm, sizeof(Closure) + sizeof(VAL)*arity,
@@ -275,37 +288,29 @@ VAL MKFLOAT(VM* vm, double val) {
275288 return cl;
276289}
277290
278−VAL MKSTR(VM* vm, const char* str) {
279− int len;
280− if (str == NULL) {
281− len = 0;
291+VAL MKSTRlen(VM* vm, const char * str, size_t len) {
292+ Closure* cl = allocStr(len, 0);
293+ if (str) {
294+ memcpy(cl->info.str, str, len);
282295 } else {
283− len = strlen(str)+1;
296+ cl->info.str = NULL;
284297 }
285− Closure* cl = allocate(sizeof(Closure) + // Type) + sizeof(char*) +
286− sizeof(char)*len, 0);
287− SETTY(cl, CT_STRING);
288− cl->info.str.str = (char*)cl + sizeof(Closure);
289− if (str == NULL) {
290− cl->info.str.str = NULL;
291− } else {
292− strcpy(cl->info.str.str, str);
293− }
294− cl->info.str.len = len > 0 ? len : 0;
295298 return cl;
296299}
297300
301+VAL MKSTR(VM* vm, const char* str) {
302+ return MKSTRlen(vm, str, str? strlen(str) : ~0);
303+}
304+
298305char* GETSTROFF(VAL stroff) {
299306 // Assume STROFF
300− StrOffset* root = stroff->info.str_offset;
301− return (root->str->info.str.str + root->offset);
307+ return stroff->info.str_offset->info.str + stroff->sz;
302308}
303309
304310size_t GETSTROFFLEN(VAL stroff) {
305311 // Assume STROFF
306312 // we're working in char* here so no worries about utf8 char length
307− StrOffset* root = stroff->info.str_offset;
308− return (root->str->info.str.len - root->offset);
313+ return stroff->info.str_offset->sz - stroff->sz;
309314}
310315
311316VAL MKCDATA(VM* vm, CHeapItem * item) {
@@ -332,13 +337,10 @@ VAL MKPTR(VM* vm, void* ptr) {
332337}
333338
334339VAL MKMPTR(VM* vm, void* ptr, size_t size) {
335− Closure* cl = allocate(sizeof(Closure) +
336− sizeof(ManagedPtr) + size, 0);
340+ Closure* cl = allocate(sizeof(Closure) + size, 0);
337341 SETTY(cl, CT_MANAGEDPTR);
338− cl->info.mptr = (ManagedPtr*)((char*)cl + sizeof(Closure));
339− cl->info.mptr->data = (char*)cl + sizeof(Closure) + sizeof(ManagedPtr);
340− memcpy(cl->info.mptr->data, ptr, size);
341− cl->info.mptr->size = size;
342+ memcpy(cl->info.managed_ptr, ptr, size);
343+ cl->sz = size;
342344 return cl;
343345}
344346
@@ -349,28 +351,14 @@ VAL MKFLOATc(VM* vm, double val) {
349351 return cl;
350352}
351353
352−VAL MKSTRc(VM* vm, char* str) {
353− int len = strlen(str);
354−
355− Closure* cl = allocate(sizeof(Closure) + // Type) + sizeof(char*) +
356− sizeof(char)*len+1, 1);
357− SETTY(cl, CT_STRING);
358− cl -> info.str.str = (char*)cl + sizeof(Closure);
359−
360− strcpy(cl->info.str.str, str);
361− cl->info.str.len = len;
354+VAL MKSTRclen(VM* vm, char* str, int len) {
355+ Closure* cl = allocStr(len, 1);
356+ memcpy(cl->info.str, str, len);
362357 return cl;
363358}
364359
365−VAL MKSTRclen(VM* vm, char* str, int len) {
366− Closure* cl = allocate(sizeof(Closure) + // Type) + sizeof(char*) +
367− sizeof(char)*len+1, 1);
368− SETTY(cl, CT_STRING);
369− cl -> info.str.str = (char*)cl + sizeof(Closure);
370−
371− strcpy(cl->info.str.str, str);
372− cl->info.str.len = len;
373− return cl;
360+VAL MKSTRc(VM* vm, char* str) {
361+ return MKSTRclen(vm, str, strlen(str));
374362}
375363
376364VAL MKPTRc(VM* vm, void* ptr) {
@@ -381,13 +369,10 @@ VAL MKPTRc(VM* vm, void* ptr) {
381369}
382370
383371VAL MKMPTRc(VM* vm, void* ptr, size_t size) {
384− Closure* cl = allocate(sizeof(Closure) +
385− sizeof(ManagedPtr) + size, 1);
372+ Closure* cl = allocate(sizeof(Closure) + size, 1);
386373 SETTY(cl, CT_MANAGEDPTR);
387− cl->info.mptr = (ManagedPtr*)((char*)cl + sizeof(Closure));
388− cl->info.mptr->data = (char*)cl + sizeof(Closure) + sizeof(ManagedPtr);
389− memcpy(cl->info.mptr->data, ptr, size);
390− cl->info.mptr->size = size;
374+ memcpy(cl->info.managed_ptr, ptr, size);
375+ cl->sz = size;
391376 return cl;
392377}
393378
@@ -451,18 +436,18 @@ void dumpVal(VAL v) {
451436 }
452437 switch(GETTY(v)) {
453438 case CT_CON:
454− printf("%d[", TAG(v));
439+ printf("%lu[", TAG(v));
455440 for(i = 0; i < ARITY(v); ++i) {
456− dumpVal(v->info.c.args[i]);
441+ dumpVal(v->info.cargs[i]);
457442 }
458443 printf("] ");
459444 break;
460445 case CT_STRING:
461− printf("STR[%s]", v->info.str.str);
446+ printf("STR[%s]", v->info.str);
462447 break;
463448 case CT_STROFFSET:
464449 printf("OFFSET[");
465− dumpVal((VAL)(v->info.str_offset->str));
450+ dumpVal((VAL)(v->info.str_offset));
466451 printf("]");
467452 break;
468453 case CT_FWD:
@@ -523,50 +508,40 @@ void idris_memmove(void* dest, void* src, i_int dest_offset, i_int src_offset, i
523508
524509VAL idris_castIntStr(VM* vm, VAL i) {
525510 int x = (int) GETINT(i);
526− Closure* cl = allocate(sizeof(Closure) + sizeof(char)*16, 0);
527− SETTY(cl, CT_STRING);
528− cl->info.str.str = (char*)cl + sizeof(Closure);
529− sprintf(cl->info.str.str, "%d", x);
530− cl->info.str.len = strlen(cl->info.str.str);
511+ Closure* cl = allocStr(16, 0);
512+ cl->sz = sprintf(cl->info.str, "%d", x);
531513 return cl;
532514}
533515
534516VAL idris_castBitsStr(VM* vm, VAL i) {
535517 Closure* cl;
536− ClosureType ty = i->ty;
518+ ClosureType ty = GETTY(i);
537519
538520 switch (ty) {
539521 case CT_BITS8:
540522 // max length 8 bit unsigned int str 3 chars (256)
541− cl = allocate(sizeof(Closure) + sizeof(char)*4, 0);
542− cl->info.str.str = (char*)cl + sizeof(Closure);
543− sprintf(cl->info.str.str, "%" PRIu8, (uint8_t)i->info.bits8);
523+ cl = allocStr(4, 0);
524+ cl->sz = sprintf(cl->info.str, "%" PRIu8, GETBITS8(i));
544525 break;
545526 case CT_BITS16:
546527 // max length 16 bit unsigned int str 5 chars (65,535)
547− cl = allocate(sizeof(Closure) + sizeof(char)*6, 0);
548− cl->info.str.str = (char*)cl + sizeof(Closure);
549− sprintf(cl->info.str.str, "%" PRIu16, (uint16_t)i->info.bits16);
528+ cl = allocStr(6, 0);
529+ cl->sz = sprintf(cl->info.str, "%" PRIu16, GETBITS16(i));
550530 break;
551531 case CT_BITS32:
552532 // max length 32 bit unsigned int str 10 chars (4,294,967,295)
553− cl = allocate(sizeof(Closure) + sizeof(char)*11, 0);
554− cl->info.str.str = (char*)cl + sizeof(Closure);
555− sprintf(cl->info.str.str, "%" PRIu32, (uint32_t)i->info.bits32);
533+ cl = allocStr(11, 0);
534+ cl->sz = sprintf(cl->info.str, "%" PRIu32, GETBITS32(i));
556535 break;
557536 case CT_BITS64:
558537 // max length 64 bit unsigned int str 20 chars (18,446,744,073,709,551,615)
559− cl = allocate(sizeof(Closure) + sizeof(char)*21, 0);
560− cl->info.str.str = (char*)cl + sizeof(Closure);
561− sprintf(cl->info.str.str, "%" PRIu64, (uint64_t)i->info.bits64);
538+ cl = allocStr(21, 0);
539+ cl->sz = sprintf(cl->info.str, "%" PRIu64, GETBITS64(i));
562540 break;
563541 default:
564542 fprintf(stderr, "Fatal Error: ClosureType %d, not an integer type", ty);
565543 exit(EXIT_FAILURE);
566544 }
567−
568− cl->info.str.len = strlen(cl->info.str.str);
569− SETTY(cl, CT_STRING);
570545 return cl;
571546}
572547
@@ -580,12 +555,8 @@ VAL idris_castStrInt(VM* vm, VAL i) {
580555}
581556
582557VAL idris_castFloatStr(VM* vm, VAL i) {
583− Closure* cl = allocate(sizeof(Closure) + sizeof(char)*32, 0);
584− SETTY(cl, CT_STRING);
585− cl->info.str.str = (char*)cl + sizeof(Closure);
586− snprintf(cl->info.str.str, 32, "%.16g", GETFLOAT(i));
587−
588− cl->info.str.len = strlen(cl->info.str.str);
558+ Closure* cl = allocStr(32, 0);
559+ cl->sz = snprintf(cl->info.str, 32, "%.16g", GETFLOAT(i));
589560 return cl;
590561}
591562
@@ -599,13 +570,9 @@ VAL idris_concat(VM* vm, VAL l, VAL r) {
599570 int llen = GETSTRLEN(l);
600571 int rlen = GETSTRLEN(r);
601572
602− Closure* cl = allocate(sizeof(Closure) + llen + rlen + 1, 0);
603− SETTY(cl, CT_STRING);
604− cl->info.str.str = (char*)cl + sizeof(Closure);
605− strcpy(cl->info.str.str, ls);
606− strcat(cl->info.str.str, rs);
607−
608− cl->info.str.len = llen + rlen;
573+ Closure* cl = allocStr(llen + rlen, 0);
574+ memcpy(cl->info.str, ls, llen);
575+ memcpy(cl->info.str + llen, rs, rlen);
609576 return cl;
610577}
611578
@@ -667,13 +634,11 @@ VAL idris_strHead(VM* vm, VAL str) {
667634 return idris_strIndex(vm, str, 0);
668635}
669636
670−VAL MKSTROFFc(VM* vm, StrOffset* off) {
671− Closure* cl = allocate(sizeof(Closure) + sizeof(StrOffset), 1);
637+VAL MKSTROFFc(VM* vm, VAL off) {
638+ Closure* cl = allocate(sizeof(Closure), 1);
672639 SETTY(cl, CT_STROFFSET);
673− cl->info.str_offset = (StrOffset*)((char*)cl + sizeof(Closure));
674−
675− cl->info.str_offset->str = off->str;
676− cl->info.str_offset->offset = off->offset;
640+ cl->info.str_offset = off->info.str_offset;
641+ cl->sz = off->sz;
677642
678643 return cl;
679644}
@@ -681,22 +646,22 @@ VAL MKSTROFFc(VM* vm, StrOffset* off) {
681646VAL idris_strShift(VM* vm, VAL str, int num) {
682647 // If there's no room, just copy the string, or we'll have a problem after
683648 // gc moves str
684− if (space(vm, sizeof(Closure) + sizeof(StrOffset))) {
685− Closure* cl = allocate(sizeof(Closure) + sizeof(StrOffset), 0);
649+ if (space(vm, sizeof(Closure))) {
650+ Closure* cl = allocate(sizeof(Closure), 0);
686651 SETTY(cl, CT_STROFFSET);
687− cl->info.str_offset = (StrOffset*)((char*)cl + sizeof(Closure));
652+ cl->info.str_offset = cl->info.str_offset;
688653
689654 int offset = 0;
690655 VAL root = str;
691656
692657 while(root!=NULL && !ISSTR(root)) { // find the root, carry on.
693658 // In theory, at most one step here!
694− offset += root->info.str_offset->offset;
695− root = root->info.str_offset->str;
659+ offset += root->sz;
660+ root = root->info.str_offset;
696661 }
697662
698− cl->info.str_offset->str = root;
699− cl->info.str_offset->offset = offset+idris_utf8_findOffset(GETSTR(str), num);
663+ cl->info.str_offset = root;
664+ cl->sz = offset+idris_utf8_findOffset(GETSTR(str), num);
700665
701666 return cl;
702667 } else {
@@ -715,23 +680,17 @@ VAL idris_strCons(VM* vm, VAL x, VAL xs) {
715680 int xlen = GETSTRLEN(xs);
716681
717682 if (xval < 0x80) { // ASCII char
718− Closure* cl = allocate(sizeof(Closure) +
719− xlen + 2, 0);
720− SETTY(cl, CT_STRING);
721− cl->info.str.str = (char*)cl + sizeof(Closure);
722− cl->info.str.str[0] = (char)(GETINT(x));
723− strcpy(cl->info.str.str+1, xstr);
724− cl->info.str.len = xlen + 1;
683+ Closure* cl = allocStr(xlen + 1, 0);
684+ cl->info.str[0] = (char)(GETINT(x));
685+ memcpy(cl->info.str+1, xstr, xlen);
725686 return cl;
726687 } else {
727688 char *init = idris_utf8_fromChar(xval);
728− int newlen = strlen(init) + xlen;
729− Closure* cl = allocate(sizeof(Closure) + newlen + 1, 0);
730− SETTY(cl, CT_STRING);
731− cl->info.str.str = (char*)cl + sizeof(Closure);
732− strcpy(cl->info.str.str, init);
733− strcat(cl->info.str.str, xstr);
734− cl->info.str.len = newlen;
689+ size_t ilen = strlen(init);
690+ int newlen = ilen + xlen;
691+ Closure* cl = allocStr(newlen, 0);
692+ memcpy(cl->info.str, init, ilen);
693+ memcpy(cl->info.str + ilen, xstr, xlen);
735694 free(init);
736695 return cl;
737696 }
@@ -754,12 +713,10 @@ VAL idris_substr(VM* vm, VAL offset, VAL length, VAL str) {
754713 else {
755714 char *start = idris_utf8_advance(str_val, offset_val);
756715 char *end = idris_utf8_advance(start, length_val);
757− Closure* newstr = allocate(sizeof(Closure) + (end - start) +1, 0);
758− SETTY(newstr, CT_STRING);
759− newstr->info.str.str = (char*)newstr + sizeof(Closure);
760− memcpy(newstr->info.str.str, start, end - start);
761− *(newstr->info.str.str + (end - start) + 1) = '\0';
762− newstr->info.str.len = strlen(newstr->info.str.str);
716+ size_t sz = end - start;
717+ Closure* newstr = allocStr(sz, 0);
718+ memcpy(newstr->info.str, start, sz);
719+ newstr->info.str[sz] = '\0';
763720 return newstr;
764721 }
765722}
@@ -768,11 +725,8 @@ VAL idris_strRev(VM* vm, VAL str) {
768725 char *xstr = GETSTR(str);
769726 int xlen = GETSTRLEN(str);
770727
771− Closure* cl = allocate(sizeof(Closure) + xlen + 1, 0);
772− SETTY(cl, CT_STRING);
773− cl->info.str.str = (char*)cl + sizeof(Closure);
774− cl->info.str.len = xlen;
775− idris_utf8_rev(xstr, cl->info.str.str);
728+ Closure* cl = allocStr(xlen, 0);
729+ idris_utf8_rev(xstr, cl->info.str);
776730 return cl;
777731}
778732
@@ -801,17 +755,17 @@ VAL idris_newArray(VM* vm, int size, VAL def) {
801755 int i;
802756 allocArray(cl, vm, size, 0);
803757 for(i=0; i<size; ++i) {
804− cl->info.arr.content[i] = def;
758+ cl->info.array[i] = def;
805759 }
806760 return cl;
807761}
808762
809763void idris_arraySet(VAL arr, int index, VAL newval) {
810− arr->info.arr.content[index] = newval;
764+ arr->info.array[index] = newval;
811765}
812766
813767VAL idris_arrayGet(VAL arr, int index) {
814− return arr->info.arr.content[index];
768+ return arr->info.array[index];
815769}
816770
817771VAL idris_systemInfo(VM* vm, VAL index) {
@@ -909,20 +863,20 @@ VAL doCopyTo(VM* vm, VAL x) {
909863 } else {
910864 allocCon(cl, vm, CTAG(x), ar, 1);
911865
912− argptr = (VAL*)(cl->info.c.args);
866+ argptr = cl->info.cargs;
913867 for(i = 0; i < ar; ++i) {
914− *argptr = doCopyTo(vm, *((VAL*)(x->info.c.args)+i)); // recursive version
868+ *argptr = doCopyTo(vm, x->info.cargs[i]); // recursive version
915869 argptr++;
916870 }
917871 }
918872 break;
919873 case CT_ARRAY:
920− len = x->info.arr.length;
874+ len = x->sz;
921875 allocArray(cl, vm, len, 1);
922876
923− argptr = (VAL*)(cl->info.arr.content);
877+ argptr = cl->info.array;
924878 for(i = 0; i < len; ++i) {
925− *argptr = doCopyTo(vm, *((VAL*)(x->info.arr.content)+i)); // recursive version
879+ *argptr = doCopyTo(vm, x->info.array[i]); // recursive version
926880 argptr++;
927881 }
928882 break;
@@ -930,7 +884,7 @@ VAL doCopyTo(VM* vm, VAL x) {
930884 cl = MKFLOATc(vm, x->info.f);
931885 break;
932886 case CT_STRING:
933− cl = MKSTRc(vm, x->info.str.str);
887+ cl = MKSTRc(vm, x->info.str);
934888 break;
935889 case CT_BIGINT:
936890 cl = MKBIGMc(vm, x->info.ptr);
@@ -939,7 +893,7 @@ VAL doCopyTo(VM* vm, VAL x) {
939893 cl = MKPTRc(vm, x->info.ptr);
940894 break;
941895 case CT_MANAGEDPTR:
942− cl = MKMPTRc(vm, x->info.mptr->data, x->info.mptr->size);
896+ cl = MKMPTRc(vm, x->info.managed_ptr, x->sz);
943897 break;
944898 case CT_CDATA:
945899 cl = MKCDATAc(vm, x->info.c_heap_item);
@@ -958,7 +912,7 @@ VAL doCopyTo(VM* vm, VAL x) {
958912 break;
959913 case CT_RAWDATA:
960914 {
961− size_t size = x->info.size + sizeof(Closure);
915+ size_t size = x->sz + sizeof(Closure);
962916 cl = allocate(size, 0);
963917 memcpy(cl, x, size);
964918 }
@@ -1112,7 +1066,7 @@ Msg* idris_recvMessageFrom(VM* vm, int channel_id, VM* sender) {
11121066
11131067 struct timespec timeout;
11141068 int status;
1115−
1069+
11161070 if (sender && sender->active == 0) { return NULL; } // No VM to receive from
11171071
11181072 pthread_mutex_lock(&vm->inbox_block);
@@ -1196,7 +1150,7 @@ void init_nullaries(void) {
11961150 for(i = 0; i < 256; ++i) {
11971151 cl = malloc(sizeof(Closure));
11981152 SETTY(cl, CT_CON);
1199− cl->info.c.tag_arity = i << 8;
1153+ cl->sz = i << 8;
12001154 nullary_cons[i] = cl;
12011155 }
12021156}
rts/idris_rts.h+45−69
@@ -32,60 +32,30 @@ typedef enum {
3232
3333typedef struct Closure *VAL;
3434
35−// A constructor, consisting of a tag, an arity (16 bits each of the
36−// tag_arity field) and arguments
37−typedef struct {
38− uint32_t tag_arity;
39− VAL args[];
40−} con;
41−
35+typedef struct Closure {
36+ ClosureType ty:8;
37+ size_t sz:56;
38+ union {
39+// A constructor, consisting of a tag (encoded in the sz field),
40+// an arity (encoded in 8 bits in the sz field), and arguments
41+ VAL cargs[0];
4242// An array; similar to a constructor but with a length, and contents
4343// initialised to NULL (high level Idris programs are responsible for
4444// initialising them properly)
45−typedef struct {
46− uint32_t length;
47− VAL content[];
48−} array;
49−
50−typedef struct {
51− VAL str;
52− size_t offset;
53−} StrOffset;
54−
55−typedef struct {
56− char* str;
57− size_t len; // Cached strlen (we do 'strlen' a lot)
58−} String;
59−
60−// A foreign pointer, managed by the idris GC
61−typedef struct {
62− size_t size;
63− void* data;
64−} ManagedPtr;
65−
66−typedef struct Closure {
67−// Use top 16 bits of ty for saying which heap value is in
68−// Bottom 16 bits for closure type
69−//
70−// NOTE: ty can not have type ClosureType because ty must be a
71−// uint32_t but enum is platform dependent
72− uint32_t ty;
73− union {
74− con c;
75− array arr;
45+ VAL array[0];
7646 int i;
7747 double f;
78− String str;
79− StrOffset* str_offset;
80− void* ptr;
48+ VAL str_offset;
49+ void * ptr;
50+ char * str;
8151 uint8_t bits8;
8252 uint16_t bits16;
8353 uint32_t bits32;
8454 uint64_t bits64;
85− ManagedPtr* mptr;
55+ char managed_ptr[0]; // A foreign pointer, managed by the idris GC
8656 CHeapItem* c_heap_item;
87− size_t size;
8857 } info;
58+ char data[0];
8959} Closure;
9060
9161struct VM;
@@ -195,10 +165,10 @@ typedef void(*func)(VM*, VAL*);
195165#define REG1 (vm->reg1)
196166
197167// Retrieving values
198−#define GETSTR(x) (ISSTR(x) ? (((VAL)(x))->info.str.str) : GETSTROFF(x))
199−#define GETSTRLEN(x) (ISSTR(x) ? (((VAL)(x))->info.str.len) : GETSTROFFLEN(x))
168+#define GETSTR(x) (ISSTR(x) ? (((VAL)(x))->info.str) : GETSTROFF(x))
169+#define GETSTRLEN(x) (ISSTR(x) ? (((VAL)(x))->sz) : GETSTROFFLEN(x))
200170#define GETPTR(x) (((VAL)(x))->info.ptr)
201−#define GETMPTR(x) (((VAL)(x))->info.mptr->data)
171+#define GETMPTR(x) (((VAL)(x))->info.managed_ptr)
202172#define GETFLOAT(x) (((VAL)(x))->info.f)
203173#define GETCDATA(x) (((VAL)(x))->info.c_heap_item)
204174
@@ -207,12 +177,12 @@ typedef void(*func)(VM*, VAL*);
207177#define GETBITS32(x) (((VAL)(x))->info.bits32)
208178#define GETBITS64(x) (((VAL)(x))->info.bits64)
209179
210−#define TAG(x) (ISINT(x) || x == NULL ? (-1) : ( GETTY(x) == CT_CON ? (x)->info.c.tag_arity >> 8 : (-1)) )
211−#define ARITY(x) (ISINT(x) || x == NULL ? (-1) : ( GETTY(x) == CT_CON ? (x)->info.c.tag_arity & 0x000000ff : (-1)) )
212−
213180// Already checked it's a CT_CON
214−#define CTAG(x) (((x)->info.c.tag_arity) >> 8)
215−#define CARITY(x) ((x)->info.c.tag_arity & 0x000000ff)
181+#define CTAG(x) (((x)->sz) >> 8)
182+#define CARITY(x) (((x)->sz) & 0xff)
183+
184+#define TAG(x) (ISINT(x) || x == NULL ? (-1) : ( GETTY(x) == CT_CON ? CTAG(x) : (-1)) )
185+#define ARITY(x) (ISINT(x) || x == NULL ? (-1) : ( GETTY(x) == CT_CON ? CARITY(x) : (-1)) )
216186
217187
218188#define GETTY(x) ((x)->ty)
@@ -241,15 +211,17 @@ typedef intptr_t i_int;
241211#ifdef IDRIS_TRACE
242212#define TRACE idris_trace(vm, __FUNCTION__, __LINE__);
243213#else
244−#define TRACE
214+#define TRACE
245215#endif
246216
247217#define INITFRAME TRACE\
248218 __attribute__((unused)) VAL* myoldbase
249219
250220#define REBASE vm->valstack_base = oldbase
251−#define RESERVE(x) if (vm->valstack_top+(x) > vm->stack_max) { stackOverflow(); } \
252− else { memset(vm->valstack_top, 0, (x)*sizeof(VAL)); }
221+#define RESERVE(x) do { \
222+ if (vm->valstack_top+(x) > vm->stack_max) { stackOverflow(); } \
223+ else { memset(vm->valstack_top, 0, (x)*sizeof(VAL)); } \
224+ } while(0)
253225#define ADDTOP(x) vm->valstack_top += (x)
254226#define TOPBASE(x) vm->valstack_top = vm->valstack_base + (x)
255227#define BASETOP(x) vm->valstack_base = vm->valstack_top + (x)
@@ -260,6 +232,7 @@ typedef intptr_t i_int;
260232// Creating new values (each value placed at the top of the stack)
261233VAL MKFLOAT(VM* vm, double val);
262234VAL MKSTR(VM* vm, const char* str);
235+VAL MKSTRlen(VM* vm, const char* str, size_t size);
263236VAL MKPTR(VM* vm, void* ptr);
264237VAL MKMPTR(VM* vm, void* ptr, size_t size);
265238VAL MKB8(VM* vm, uint8_t b);
@@ -270,7 +243,7 @@ VAL MKCDATA(VM* vm, CHeapItem * item);
270243
271244// following versions don't take a lock when allocating
272245VAL MKFLOATc(VM* vm, double val);
273−VAL MKSTROFFc(VM* vm, StrOffset* off);
246+VAL MKSTROFFc(VM* vm, VAL off);
274247VAL MKSTRc(VM* vm, char* str);
275248VAL MKSTRclen(VM* vm, char* str, int len);
276249VAL MKPTRc(VM* vm, void* ptr);
@@ -280,12 +253,11 @@ VAL MKCDATAc(VM* vm, CHeapItem * item);
280253char* GETSTROFF(VAL stroff);
281254size_t GETSTROFFLEN(VAL stroff);
282255
283−// #define SETTAG(x, a) (x)->info.c.tag = (a)
284−#define SETARG(x, i, a) ((x)->info.c.args)[i] = ((VAL)(a))
285−#define GETARG(x, i) ((x)->info.c.args)[i]
256+#define SETARG(x, i, a) ((x)->info.cargs)[i] = ((VAL)(a))
257+#define GETARG(x, i) ((x)->info.cargs[i])
286258
287259#define PROJECT(vm,r,loc,num) \
288− memcpy(&(LOC(loc)), &((r)->info.c.args), sizeof(VAL)*num)
260+ memcpy(&(LOC(loc)), (r)->info.cargs, sizeof(VAL)*num)
289261#define SLIDE(vm, args) \
290262 memcpy(&(LOC(0)), &(TOP(0)), sizeof(VAL)*args)
291263
@@ -308,22 +280,26 @@ void* idris_alloc(size_t size);
308280void* idris_realloc(void* old, size_t old_size, size_t size);
309281void idris_free(void* ptr, size_t size);
310282
311−#define allocCon(cl, vm, t, a, o) \
312− cl = allocate(sizeof(Closure) + sizeof(VAL)*a, o); \
313− SETTY(cl, CT_CON); \
314− cl->info.c.tag_arity = ((t) << 8) | (a);
283+#define allocCon(cl, vm, t, a, o) do { \
284+ cl = allocate(sizeof(Closure) + sizeof(VAL)*a, o); \
285+ SETTY(cl, CT_CON); \
286+ cl->sz = ((t) << 8) | (a); \
287+ } while (0)
288+
289+#define updateCon(cl, old, t, a) do { \
290+ cl = old; \
291+ SETTY(cl, CT_CON); \
292+ cl->sz = ((t) << 8) | (a); \
293+ } while (0)
315294
316−#define updateCon(cl, old, t, a) \
317− cl = old; \
318− SETTY(cl, CT_CON); \
319− cl->info.c.tag_arity = ((t) << 8) | (a);
320295
321296#define NULL_CON(x) nullary_cons[x]
322297
323−#define allocArray(cl, vm, len, o) \
298+#define allocArray(cl, vm, len, o) do { \
324299 cl = allocate(sizeof(Closure) + sizeof(VAL)*len, o); \
325300 SETTY(cl, CT_ARRAY); \
326− cl->info.arr.length = len;
301+ cl->sz = len; \
302+ } while (0)
327303
328304int idris_errno(void);
329305char* idris_showerror(int err);
src/IRTS/CodegenC.hs+6−6
@@ -396,7 +396,7 @@ c_irts FFunctionIO l x = error "Return of function from foreign call is not supp
396396irts_c (FArith (ATInt ITNative)) x = "GETINT(" ++ x ++ ")"
397397irts_c (FArith (ATInt ITChar)) x = irts_c (FArith (ATInt ITNative)) x
398398irts_c (FArith (ATInt (ITFixed ity))) x
399− = "(" ++ x ++ "->info.bits" ++ show (nativeTyWidth ity) ++ ")"
399+ = "GETBITS" ++ show (nativeTyWidth ity) ++ "(" ++ x ++ ")"
400400irts_c FString x = "GETSTR(" ++ x ++ ")"
401401irts_c FUnit x = x
402402irts_c FPtr x = "GETPTR(" ++ x ++ ")"
@@ -536,13 +536,13 @@ doOp v (LURem (ITFixed ty)) [x, y] = bitOp v "URem" ty [x, y]
536536doOp v (LSRem (ATInt (ITFixed ty))) [x, y] = bitOp v "SRem" ty [x, y]
537537
538538doOp v (LSExt (ITFixed from) ITBig) [x]
539− = v ++ "MKBIGSI(vm, (" ++ signedTy from ++ ")" ++ creg x ++ "->info.bits" ++ show (nativeTyWidth from) ++ ")"
539+ = v ++ "MKBIGSI(vm, (" ++ signedTy from ++ ") GETBITS" ++ show (nativeTyWidth from) ++ "(" ++ creg x ++ "))"
540540doOp v (LSExt ITNative (ITFixed to)) [x]
541541 = v ++ "idris_b" ++ show (nativeTyWidth to) ++ "const(vm, GETINT(" ++ creg x ++ "))"
542542doOp v (LSExt ITChar (ITFixed to)) [x]
543543 = doOp v (LSExt ITNative (ITFixed to)) [x]
544544doOp v (LSExt (ITFixed from) ITNative) [x]
545− = v ++ "MKINT((i_int)((" ++ signedTy from ++ ")" ++ creg x ++ "->info.bits" ++ show (nativeTyWidth from) ++ "))"
545+ = v ++ "MKINT((i_int)((" ++ signedTy from ++ ") GETBITS" ++ show (nativeTyWidth from) ++ "(" ++ creg x ++ ")))"
546546doOp v (LSExt (ITFixed from) ITChar) [x]
547547 = doOp v (LSExt (ITFixed from) ITNative) [x]
548548doOp v (LSExt (ITFixed from) (ITFixed to)) [x]
@@ -552,11 +552,11 @@ doOp v (LZExt ITNative (ITFixed to)) [x]
552552doOp v (LZExt ITChar (ITFixed to)) [x]
553553 = doOp v (LZExt ITNative (ITFixed to)) [x]
554554doOp v (LZExt (ITFixed from) ITNative) [x]
555− = v ++ "MKINT((i_int)" ++ creg x ++ "->info.bits" ++ show (nativeTyWidth from) ++ ")"
555+ = v ++ "MKINT((i_int)GETBITS" ++ show (nativeTyWidth from) ++ "(" ++ creg x ++ "))"
556556doOp v (LZExt (ITFixed from) ITChar) [x]
557557 = doOp v (LZExt (ITFixed from) ITNative) [x]
558558doOp v (LZExt (ITFixed from) ITBig) [x]
559− = v ++ "MKBIGUI(vm, " ++ creg x ++ "->info.bits" ++ show (nativeTyWidth from) ++ ")"
559+ = v ++ "MKBIGUI(vm, GETBITS" ++ show (nativeTyWidth from) ++ "(" ++ creg x ++ "))"
560560doOp v (LZExt ITNative ITBig) [x]
561561 = v ++ "MKBIGUI(vm, (uintptr_t)GETINT(" ++ creg x ++ "))"
562562doOp v (LZExt (ITFixed from) (ITFixed to)) [x]
@@ -566,7 +566,7 @@ doOp v (LTrunc ITNative (ITFixed to)) [x]
566566doOp v (LTrunc ITChar (ITFixed to)) [x]
567567 = doOp v (LTrunc ITNative (ITFixed to)) [x]
568568doOp v (LTrunc (ITFixed from) ITNative) [x]
569− = v ++ "MKINT((i_int)" ++ creg x ++ "->info.bits" ++ show (nativeTyWidth from) ++ ")"
569+ = v ++ "MKINT((i_int)GETBITS" ++ show (nativeTyWidth from) ++ "(" ++ creg x ++ "))"
570570doOp v (LTrunc (ITFixed from) ITChar) [x]
571571 = doOp v (LTrunc (ITFixed from) ITNative) [x]
572572doOp v (LTrunc ITBig (ITFixed IT64)) [x]