on master help sign in
Smaller closure
d16e78fJorge Acereda
rts/idris_bitstring.c+146−146
@@ -3,7 +3,7 @@
3#include "idris_rts.h"
3#include "idris_rts.h"
4
4
5VAL idris_b8CopyForGC(VM *vm, VAL a) {
5VAL idris_b8CopyForGC(VM *vm, VAL a) {
6− uint8_t A = a->info.bits8;
6+ uint8_t A = GETBITS8(a);
7 VAL cl = allocate(sizeof(Closure), 1);
7 VAL cl = allocate(sizeof(Closure), 1);
8 SETTY(cl, CT_BITS8);
8 SETTY(cl, CT_BITS8);
9 cl->info.bits8 = A;
9 cl->info.bits8 = A;
@@ -11,7 +11,7 @@ VAL idris_b8CopyForGC(VM *vm, VAL a) {
11}
11}
12
12
13VAL idris_b16CopyForGC(VM *vm, VAL a) {
13VAL idris_b16CopyForGC(VM *vm, VAL a) {
14− uint16_t A = a->info.bits16;
14+ uint16_t A = GETBITS16(a);
15 VAL cl = allocate(sizeof(Closure), 1);
15 VAL cl = allocate(sizeof(Closure), 1);
16 SETTY(cl, CT_BITS16);
16 SETTY(cl, CT_BITS16);
17 cl->info.bits16 = A;
17 cl->info.bits16 = A;
@@ -19,7 +19,7 @@ VAL idris_b16CopyForGC(VM *vm, VAL a) {
19}
19}
20
20
21VAL idris_b32CopyForGC(VM *vm, VAL a) {
21VAL idris_b32CopyForGC(VM *vm, VAL a) {
22− uint32_t A = a->info.bits32;
22+ uint32_t A = GETBITS32(a);
23 VAL cl = allocate(sizeof(Closure), 1);
23 VAL cl = allocate(sizeof(Closure), 1);
24 SETTY(cl, CT_BITS32);
24 SETTY(cl, CT_BITS32);
25 cl->info.bits32 = A;
25 cl->info.bits32 = A;
@@ -27,7 +27,7 @@ VAL idris_b32CopyForGC(VM *vm, VAL a) {
27}
27}
28
28
29VAL idris_b64CopyForGC(VM *vm, VAL a) {
29VAL idris_b64CopyForGC(VM *vm, VAL a) {
30− uint64_t A = a->info.bits64;
30+ uint64_t A = GETBITS64(a);
31 VAL cl = allocate(sizeof(Closure), 1);
31 VAL cl = allocate(sizeof(Closure), 1);
32 SETTY(cl, CT_BITS64);
32 SETTY(cl, CT_BITS64);
33 cl->info.bits64 = A;
33 cl->info.bits64 = A;
@@ -67,7 +67,7 @@ VAL idris_b64(VM *vm, VAL a) {
67}
67}
68
68
69VAL idris_castB32Int(VM *vm, VAL a) {
69VAL idris_castB32Int(VM *vm, VAL a) {
70− return MKINT((i_int)a->info.bits32);
70+ return MKINT(GETBITS32(a));
71}
71}
72
72
73VAL idris_b8const(VM *vm, uint8_t a) {
73VAL idris_b8const(VM *vm, uint8_t a) {
@@ -99,8 +99,8 @@ VAL idris_b64const(VM *vm, uint64_t a) {
99}
99}
100
100
101VAL idris_b8Plus(VM *vm, VAL a, VAL b) {
101VAL idris_b8Plus(VM *vm, VAL a, VAL b) {
102− uint8_t A = a->info.bits8;
102+ uint8_t A = GETBITS8(a);
103− uint8_t B = b->info.bits8;
103+ uint8_t B = GETBITS8(b);
104 VAL cl = allocate(sizeof(Closure), 0);
104 VAL cl = allocate(sizeof(Closure), 0);
105 SETTY(cl, CT_BITS8);
105 SETTY(cl, CT_BITS8);
106 cl->info.bits8 = A + B;
106 cl->info.bits8 = A + B;
@@ -108,8 +108,8 @@ VAL idris_b8Plus(VM *vm, VAL a, VAL b) {
108}
108}
109
109
110VAL idris_b8Minus(VM *vm, VAL a, VAL b) {
110VAL idris_b8Minus(VM *vm, VAL a, VAL b) {
111− uint8_t A = a->info.bits8;
111+ uint8_t A = GETBITS8(a);
112− uint8_t B = b->info.bits8;
112+ uint8_t B = GETBITS8(b);
113 VAL cl = allocate(sizeof(Closure), 0);
113 VAL cl = allocate(sizeof(Closure), 0);
114 SETTY(cl, CT_BITS8);
114 SETTY(cl, CT_BITS8);
115 cl->info.bits8 = A - B;
115 cl->info.bits8 = A - B;
@@ -117,8 +117,8 @@ VAL idris_b8Minus(VM *vm, VAL a, VAL b) {
117}
117}
118
118
119VAL idris_b8Times(VM *vm, VAL a, VAL b) {
119VAL idris_b8Times(VM *vm, VAL a, VAL b) {
120− uint8_t A = a->info.bits8;
120+ uint8_t A = GETBITS8(a);
121− uint8_t B = b->info.bits8;
121+ uint8_t B = GETBITS8(b);
122 VAL cl = allocate(sizeof(Closure), 0);
122 VAL cl = allocate(sizeof(Closure), 0);
123 SETTY(cl, CT_BITS8);
123 SETTY(cl, CT_BITS8);
124 cl->info.bits8 = A * B;
124 cl->info.bits8 = A * B;
@@ -126,8 +126,8 @@ VAL idris_b8Times(VM *vm, VAL a, VAL b) {
126}
126}
127
127
128VAL idris_b8UDiv(VM *vm, VAL a, VAL b) {
128VAL idris_b8UDiv(VM *vm, VAL a, VAL b) {
129− uint8_t A = a->info.bits8;
129+ uint8_t A = GETBITS8(a);
130− uint8_t B = b->info.bits8;
130+ uint8_t B = GETBITS8(b);
131 VAL cl = allocate(sizeof(Closure), 0);
131 VAL cl = allocate(sizeof(Closure), 0);
132 SETTY(cl, CT_BITS8);
132 SETTY(cl, CT_BITS8);
133 cl->info.bits8 = A / B;
133 cl->info.bits8 = A / B;
@@ -135,8 +135,8 @@ VAL idris_b8UDiv(VM *vm, VAL a, VAL b) {
135}
135}
136
136
137VAL idris_b8SDiv(VM *vm, VAL a, VAL b) {
137VAL idris_b8SDiv(VM *vm, VAL a, VAL b) {
138− uint8_t A = a->info.bits8;
138+ uint8_t A = GETBITS8(a);
139− uint8_t B = b->info.bits8;
139+ uint8_t B = GETBITS8(b);
140 VAL cl = allocate(sizeof(Closure), 0);
140 VAL cl = allocate(sizeof(Closure), 0);
141 SETTY(cl, CT_BITS8);
141 SETTY(cl, CT_BITS8);
142 cl->info.bits8 = (uint8_t) (((int8_t) A) / ((int8_t) B));
142 cl->info.bits8 = (uint8_t) (((int8_t) A) / ((int8_t) B));
@@ -144,8 +144,8 @@ VAL idris_b8SDiv(VM *vm, VAL a, VAL b) {
144}
144}
145
145
146VAL idris_b8URem(VM *vm, VAL a, VAL b) {
146VAL idris_b8URem(VM *vm, VAL a, VAL b) {
147− uint8_t A = a->info.bits8;
147+ uint8_t A = GETBITS8(a);
148− uint8_t B = b->info.bits8;
148+ uint8_t B = GETBITS8(b);
149 VAL cl = allocate(sizeof(Closure), 0);
149 VAL cl = allocate(sizeof(Closure), 0);
150 SETTY(cl, CT_BITS8);
150 SETTY(cl, CT_BITS8);
151 cl->info.bits8 = A % B;
151 cl->info.bits8 = A % B;
@@ -153,8 +153,8 @@ VAL idris_b8URem(VM *vm, VAL a, VAL b) {
153}
153}
154
154
155VAL idris_b8SRem(VM *vm, VAL a, VAL b) {
155VAL idris_b8SRem(VM *vm, VAL a, VAL b) {
156− uint8_t A = a->info.bits8;
156+ uint8_t A = GETBITS8(a);
157− uint8_t B = b->info.bits8;
157+ uint8_t B = GETBITS8(b);
158 VAL cl = allocate(sizeof(Closure), 0);
158 VAL cl = allocate(sizeof(Closure), 0);
159 SETTY(cl, CT_BITS8);
159 SETTY(cl, CT_BITS8);
160 cl->info.bits8 = (uint8_t) (((int8_t) A) % ((int8_t) B));
160 cl->info.bits8 = (uint8_t) (((int8_t) A) % ((int8_t) B));
@@ -162,27 +162,27 @@ VAL idris_b8SRem(VM *vm, VAL a, VAL b) {
162}
162}
163
163
164VAL idris_b8Lt(VM *vm, VAL a, VAL b) {
164VAL 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)));
166}
166}
167
167
168VAL idris_b8Gt(VM *vm, VAL a, VAL b) {
168VAL 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)));
170}
170}
171
171
172VAL idris_b8Eq(VM *vm, VAL a, VAL b) {
172VAL 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)));
174}
174}
175
175
176VAL idris_b8Lte(VM *vm, VAL a, VAL b) {
176VAL 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)));
178}
178}
179
179
180VAL idris_b8Gte(VM *vm, VAL a, VAL b) {
180VAL 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)));
182}
182}
183
183
184VAL idris_b8Compl(VM *vm, VAL a) {
184VAL idris_b8Compl(VM *vm, VAL a) {
185− uint8_t A = a->info.bits8;
185+ uint8_t A = GETBITS8(a);
186 VAL cl = allocate(sizeof(Closure), 0);
186 VAL cl = allocate(sizeof(Closure), 0);
187 SETTY(cl, CT_BITS8);
187 SETTY(cl, CT_BITS8);
188 cl->info.bits8 = ~ A;
188 cl->info.bits8 = ~ A;
@@ -190,8 +190,8 @@ VAL idris_b8Compl(VM *vm, VAL a) {
190}
190}
191
191
192VAL idris_b8And(VM *vm, VAL a, VAL b) {
192VAL idris_b8And(VM *vm, VAL a, VAL b) {
193− uint8_t A = a->info.bits8;
193+ uint8_t A = GETBITS8(a);
194− uint8_t B = b->info.bits8;
194+ uint8_t B = GETBITS8(b);
195 VAL cl = allocate(sizeof(Closure), 0);
195 VAL cl = allocate(sizeof(Closure), 0);
196 SETTY(cl, CT_BITS8);
196 SETTY(cl, CT_BITS8);
197 cl->info.bits8 = A & B;
197 cl->info.bits8 = A & B;
@@ -199,8 +199,8 @@ VAL idris_b8And(VM *vm, VAL a, VAL b) {
199}
199}
200
200
201VAL idris_b8Or(VM *vm, VAL a, VAL b) {
201VAL idris_b8Or(VM *vm, VAL a, VAL b) {
202− uint8_t A = a->info.bits8;
202+ uint8_t A = GETBITS8(a);
203− uint8_t B = b->info.bits8;
203+ uint8_t B = GETBITS8(b);
204 VAL cl = allocate(sizeof(Closure), 0);
204 VAL cl = allocate(sizeof(Closure), 0);
205 SETTY(cl, CT_BITS8);
205 SETTY(cl, CT_BITS8);
206 cl->info.bits8 = A | B;
206 cl->info.bits8 = A | B;
@@ -208,8 +208,8 @@ VAL idris_b8Or(VM *vm, VAL a, VAL b) {
208}
208}
209
209
210VAL idris_b8Xor(VM *vm, VAL a, VAL b) {
210VAL idris_b8Xor(VM *vm, VAL a, VAL b) {
211− uint8_t A = a->info.bits8;
211+ uint8_t A = GETBITS8(a);
212− uint8_t B = b->info.bits8;
212+ uint8_t B = GETBITS8(b);
213 VAL cl = allocate(sizeof(Closure), 0);
213 VAL cl = allocate(sizeof(Closure), 0);
214 SETTY(cl, CT_BITS8);
214 SETTY(cl, CT_BITS8);
215 cl->info.bits8 = A ^ B;
215 cl->info.bits8 = A ^ B;
@@ -217,8 +217,8 @@ VAL idris_b8Xor(VM *vm, VAL a, VAL b) {
217}
217}
218
218
219VAL idris_b8Shl(VM *vm, VAL a, VAL b) {
219VAL idris_b8Shl(VM *vm, VAL a, VAL b) {
220− uint8_t A = a->info.bits8;
220+ uint8_t A = GETBITS8(a);
221− uint8_t B = b->info.bits8;
221+ uint8_t B = GETBITS8(b);
222 VAL cl = allocate(sizeof(Closure), 0);
222 VAL cl = allocate(sizeof(Closure), 0);
223 SETTY(cl, CT_BITS8);
223 SETTY(cl, CT_BITS8);
224 cl->info.bits8 = A << B;
224 cl->info.bits8 = A << B;
@@ -226,8 +226,8 @@ VAL idris_b8Shl(VM *vm, VAL a, VAL b) {
226}
226}
227
227
228VAL idris_b8LShr(VM *vm, VAL a, VAL b) {
228VAL idris_b8LShr(VM *vm, VAL a, VAL b) {
229− uint8_t A = a->info.bits8;
229+ uint8_t A = GETBITS8(a);
230− uint8_t B = b->info.bits8;
230+ uint8_t B = GETBITS8(b);
231 VAL cl = allocate(sizeof(Closure), 0);
231 VAL cl = allocate(sizeof(Closure), 0);
232 SETTY(cl, CT_BITS8);
232 SETTY(cl, CT_BITS8);
233 cl->info.bits8 = A >> B;
233 cl->info.bits8 = A >> B;
@@ -235,8 +235,8 @@ VAL idris_b8LShr(VM *vm, VAL a, VAL b) {
235}
235}
236
236
237VAL idris_b8AShr(VM *vm, VAL a, VAL b) {
237VAL idris_b8AShr(VM *vm, VAL a, VAL b) {
238− uint8_t A = a->info.bits8;
238+ uint8_t A = GETBITS8(a);
239− uint8_t B = b->info.bits8;
239+ uint8_t B = GETBITS8(b);
240 VAL cl = allocate(sizeof(Closure), 0);
240 VAL cl = allocate(sizeof(Closure), 0);
241 SETTY(cl, CT_BITS8);
241 SETTY(cl, CT_BITS8);
242 cl->info.bits8 = (uint8_t) (((int8_t) A) >> ((int8_t) B));
242 cl->info.bits8 = (uint8_t) (((int8_t) A) >> ((int8_t) B));
@@ -244,8 +244,8 @@ VAL idris_b8AShr(VM *vm, VAL a, VAL b) {
244}
244}
245
245
246VAL idris_b16Plus(VM *vm, VAL a, VAL b) {
246VAL idris_b16Plus(VM *vm, VAL a, VAL b) {
247− uint16_t A = a->info.bits16;
247+ uint16_t A = GETBITS16(a);
248− uint16_t B = b->info.bits16;
248+ uint16_t B = GETBITS16(b);
249 VAL cl = allocate(sizeof(Closure), 0);
249 VAL cl = allocate(sizeof(Closure), 0);
250 SETTY(cl, CT_BITS16);
250 SETTY(cl, CT_BITS16);
251 cl->info.bits16 = A + B;
251 cl->info.bits16 = A + B;
@@ -253,8 +253,8 @@ VAL idris_b16Plus(VM *vm, VAL a, VAL b) {
253}
253}
254
254
255VAL idris_b16Minus(VM *vm, VAL a, VAL b) {
255VAL idris_b16Minus(VM *vm, VAL a, VAL b) {
256− uint16_t A = a->info.bits16;
256+ uint16_t A = GETBITS16(a);
257− uint16_t B = b->info.bits16;
257+ uint16_t B = GETBITS16(b);
258 VAL cl = allocate(sizeof(Closure), 0);
258 VAL cl = allocate(sizeof(Closure), 0);
259 SETTY(cl, CT_BITS16);
259 SETTY(cl, CT_BITS16);
260 cl->info.bits16 = A - B;
260 cl->info.bits16 = A - B;
@@ -262,8 +262,8 @@ VAL idris_b16Minus(VM *vm, VAL a, VAL b) {
262}
262}
263
263
264VAL idris_b16Times(VM *vm, VAL a, VAL b) {
264VAL idris_b16Times(VM *vm, VAL a, VAL b) {
265− uint16_t A = a->info.bits16;
265+ uint16_t A = GETBITS16(a);
266− uint16_t B = b->info.bits16;
266+ uint16_t B = GETBITS16(b);
267 VAL cl = allocate(sizeof(Closure), 0);
267 VAL cl = allocate(sizeof(Closure), 0);
268 SETTY(cl, CT_BITS16);
268 SETTY(cl, CT_BITS16);
269 cl->info.bits16 = A * B;
269 cl->info.bits16 = A * B;
@@ -271,8 +271,8 @@ VAL idris_b16Times(VM *vm, VAL a, VAL b) {
271}
271}
272
272
273VAL idris_b16UDiv(VM *vm, VAL a, VAL b) {
273VAL idris_b16UDiv(VM *vm, VAL a, VAL b) {
274− uint16_t A = a->info.bits16;
274+ uint16_t A = GETBITS16(a);
275− uint16_t B = b->info.bits16;
275+ uint16_t B = GETBITS16(b);
276 VAL cl = allocate(sizeof(Closure), 0);
276 VAL cl = allocate(sizeof(Closure), 0);
277 SETTY(cl, CT_BITS16);
277 SETTY(cl, CT_BITS16);
278 cl->info.bits16 = A / B;
278 cl->info.bits16 = A / B;
@@ -280,8 +280,8 @@ VAL idris_b16UDiv(VM *vm, VAL a, VAL b) {
280}
280}
281
281
282VAL idris_b16SDiv(VM *vm, VAL a, VAL b) {
282VAL idris_b16SDiv(VM *vm, VAL a, VAL b) {
283− uint16_t A = a->info.bits16;
283+ uint16_t A = GETBITS16(a);
284− uint16_t B = b->info.bits16;
284+ uint16_t B = GETBITS16(b);
285 VAL cl = allocate(sizeof(Closure), 0);
285 VAL cl = allocate(sizeof(Closure), 0);
286 SETTY(cl, CT_BITS16);
286 SETTY(cl, CT_BITS16);
287 cl->info.bits16 = (uint16_t) (((int16_t) A) / ((int16_t) B));
287 cl->info.bits16 = (uint16_t) (((int16_t) A) / ((int16_t) B));
@@ -289,8 +289,8 @@ VAL idris_b16SDiv(VM *vm, VAL a, VAL b) {
289}
289}
290
290
291VAL idris_b16URem(VM *vm, VAL a, VAL b) {
291VAL idris_b16URem(VM *vm, VAL a, VAL b) {
292− uint16_t A = a->info.bits16;
292+ uint16_t A = GETBITS16(a);
293− uint16_t B = b->info.bits16;
293+ uint16_t B = GETBITS16(b);
294 VAL cl = allocate(sizeof(Closure), 0);
294 VAL cl = allocate(sizeof(Closure), 0);
295 SETTY(cl, CT_BITS16);
295 SETTY(cl, CT_BITS16);
296 cl->info.bits16 = A % B;
296 cl->info.bits16 = A % B;
@@ -298,8 +298,8 @@ VAL idris_b16URem(VM *vm, VAL a, VAL b) {
298}
298}
299
299
300VAL idris_b16SRem(VM *vm, VAL a, VAL b) {
300VAL idris_b16SRem(VM *vm, VAL a, VAL b) {
301− uint16_t A = a->info.bits16;
301+ uint16_t A = GETBITS16(a);
302− uint16_t B = b->info.bits16;
302+ uint16_t B = GETBITS16(b);
303 VAL cl = allocate(sizeof(Closure), 0);
303 VAL cl = allocate(sizeof(Closure), 0);
304 SETTY(cl, CT_BITS16);
304 SETTY(cl, CT_BITS16);
305 cl->info.bits16 = (uint16_t) (((int16_t) A) % ((int16_t) B));
305 cl->info.bits16 = (uint16_t) (((int16_t) A) % ((int16_t) B));
@@ -307,27 +307,27 @@ VAL idris_b16SRem(VM *vm, VAL a, VAL b) {
307}
307}
308
308
309VAL idris_b16Lt(VM *vm, VAL a, VAL b) {
309VAL 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)));
311}
311}
312
312
313VAL idris_b16Gt(VM *vm, VAL a, VAL b) {
313VAL 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)));
315}
315}
316
316
317VAL idris_b16Eq(VM *vm, VAL a, VAL b) {
317VAL 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)));
319}
319}
320
320
321VAL idris_b16Lte(VM *vm, VAL a, VAL b) {
321VAL 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)));
323}
323}
324
324
325VAL idris_b16Gte(VM *vm, VAL a, VAL b) {
325VAL 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)));
327}
327}
328
328
329VAL idris_b16Compl(VM *vm, VAL a) {
329VAL idris_b16Compl(VM *vm, VAL a) {
330− uint16_t A = a->info.bits16;
330+ uint16_t A = GETBITS16(a);
331 VAL cl = allocate(sizeof(Closure), 0);
331 VAL cl = allocate(sizeof(Closure), 0);
332 SETTY(cl, CT_BITS16);
332 SETTY(cl, CT_BITS16);
333 cl->info.bits16 = ~ A;
333 cl->info.bits16 = ~ A;
@@ -335,8 +335,8 @@ VAL idris_b16Compl(VM *vm, VAL a) {
335}
335}
336
336
337VAL idris_b16And(VM *vm, VAL a, VAL b) {
337VAL idris_b16And(VM *vm, VAL a, VAL b) {
338− uint16_t A = a->info.bits16;
338+ uint16_t A = GETBITS16(a);
339− uint16_t B = b->info.bits16;
339+ uint16_t B = GETBITS16(b);
340 VAL cl = allocate(sizeof(Closure), 0);
340 VAL cl = allocate(sizeof(Closure), 0);
341 SETTY(cl, CT_BITS16);
341 SETTY(cl, CT_BITS16);
342 cl->info.bits16 = A & B;
342 cl->info.bits16 = A & B;
@@ -344,8 +344,8 @@ VAL idris_b16And(VM *vm, VAL a, VAL b) {
344}
344}
345
345
346VAL idris_b16Or(VM *vm, VAL a, VAL b) {
346VAL idris_b16Or(VM *vm, VAL a, VAL b) {
347− uint16_t A = a->info.bits16;
347+ uint16_t A = GETBITS16(a);
348− uint16_t B = b->info.bits16;
348+ uint16_t B = GETBITS16(b);
349 VAL cl = allocate(sizeof(Closure), 0);
349 VAL cl = allocate(sizeof(Closure), 0);
350 SETTY(cl, CT_BITS16);
350 SETTY(cl, CT_BITS16);
351 cl->info.bits16 = A | B;
351 cl->info.bits16 = A | B;
@@ -353,8 +353,8 @@ VAL idris_b16Or(VM *vm, VAL a, VAL b) {
353}
353}
354
354
355VAL idris_b16Xor(VM *vm, VAL a, VAL b) {
355VAL idris_b16Xor(VM *vm, VAL a, VAL b) {
356− uint16_t A = a->info.bits16;
356+ uint16_t A = GETBITS16(a);
357− uint16_t B = b->info.bits16;
357+ uint16_t B = GETBITS16(b);
358 VAL cl = allocate(sizeof(Closure), 0);
358 VAL cl = allocate(sizeof(Closure), 0);
359 SETTY(cl, CT_BITS16);
359 SETTY(cl, CT_BITS16);
360 cl->info.bits16 = A ^ B;
360 cl->info.bits16 = A ^ B;
@@ -362,8 +362,8 @@ VAL idris_b16Xor(VM *vm, VAL a, VAL b) {
362}
362}
363
363
364VAL idris_b16Shl(VM *vm, VAL a, VAL b) {
364VAL idris_b16Shl(VM *vm, VAL a, VAL b) {
365− uint16_t A = a->info.bits16;
365+ uint16_t A = GETBITS16(a);
366− uint16_t B = b->info.bits16;
366+ uint16_t B = GETBITS16(b);
367 VAL cl = allocate(sizeof(Closure), 0);
367 VAL cl = allocate(sizeof(Closure), 0);
368 SETTY(cl, CT_BITS16);
368 SETTY(cl, CT_BITS16);
369 cl->info.bits16 = A << B;
369 cl->info.bits16 = A << B;
@@ -371,8 +371,8 @@ VAL idris_b16Shl(VM *vm, VAL a, VAL b) {
371}
371}
372
372
373VAL idris_b16LShr(VM *vm, VAL a, VAL b) {
373VAL idris_b16LShr(VM *vm, VAL a, VAL b) {
374− uint16_t A = a->info.bits16;
374+ uint16_t A = GETBITS16(a);
375− uint16_t B = b->info.bits16;
375+ uint16_t B = GETBITS16(b);
376 VAL cl = allocate(sizeof(Closure), 0);
376 VAL cl = allocate(sizeof(Closure), 0);
377 SETTY(cl, CT_BITS16);
377 SETTY(cl, CT_BITS16);
378 cl->info.bits16 = A >> B;
378 cl->info.bits16 = A >> B;
@@ -380,8 +380,8 @@ VAL idris_b16LShr(VM *vm, VAL a, VAL b) {
380}
380}
381
381
382VAL idris_b16AShr(VM *vm, VAL a, VAL b) {
382VAL idris_b16AShr(VM *vm, VAL a, VAL b) {
383− uint16_t A = a->info.bits16;
383+ uint16_t A = GETBITS16(a);
384− uint16_t B = b->info.bits16;
384+ uint16_t B = GETBITS16(b);
385 VAL cl = allocate(sizeof(Closure), 0);
385 VAL cl = allocate(sizeof(Closure), 0);
386 SETTY(cl, CT_BITS16);
386 SETTY(cl, CT_BITS16);
387 cl->info.bits16 = (uint16_t) (((int16_t) A) >> ((int16_t) B));
387 cl->info.bits16 = (uint16_t) (((int16_t) A) >> ((int16_t) B));
@@ -389,8 +389,8 @@ VAL idris_b16AShr(VM *vm, VAL a, VAL b) {
389}
389}
390
390
391VAL idris_b32Plus(VM *vm, VAL a, VAL b) {
391VAL idris_b32Plus(VM *vm, VAL a, VAL b) {
392− uint32_t A = a->info.bits32;
392+ uint32_t A = GETBITS32(a);
393− uint32_t B = b->info.bits32;
393+ uint32_t B = GETBITS32(b);
394 VAL cl = allocate(sizeof(Closure), 0);
394 VAL cl = allocate(sizeof(Closure), 0);
395 SETTY(cl, CT_BITS32);
395 SETTY(cl, CT_BITS32);
396 cl->info.bits32 = A + B;
396 cl->info.bits32 = A + B;
@@ -398,8 +398,8 @@ VAL idris_b32Plus(VM *vm, VAL a, VAL b) {
398}
398}
399
399
400VAL idris_b32Minus(VM *vm, VAL a, VAL b) {
400VAL idris_b32Minus(VM *vm, VAL a, VAL b) {
401− uint32_t A = a->info.bits32;
401+ uint32_t A = GETBITS32(a);
402− uint32_t B = b->info.bits32;
402+ uint32_t B = GETBITS32(b);
403 VAL cl = allocate(sizeof(Closure), 0);
403 VAL cl = allocate(sizeof(Closure), 0);
404 SETTY(cl, CT_BITS32);
404 SETTY(cl, CT_BITS32);
405 cl->info.bits32 = A - B;
405 cl->info.bits32 = A - B;
@@ -407,8 +407,8 @@ VAL idris_b32Minus(VM *vm, VAL a, VAL b) {
407}
407}
408
408
409VAL idris_b32Times(VM *vm, VAL a, VAL b) {
409VAL idris_b32Times(VM *vm, VAL a, VAL b) {
410− uint32_t A = a->info.bits32;
410+ uint32_t A = GETBITS32(a);
411− uint32_t B = b->info.bits32;
411+ uint32_t B = GETBITS32(b);
412 VAL cl = allocate(sizeof(Closure), 0);
412 VAL cl = allocate(sizeof(Closure), 0);
413 SETTY(cl, CT_BITS32);
413 SETTY(cl, CT_BITS32);
414 cl->info.bits32 = A * B;
414 cl->info.bits32 = A * B;
@@ -416,8 +416,8 @@ VAL idris_b32Times(VM *vm, VAL a, VAL b) {
416}
416}
417
417
418VAL idris_b32UDiv(VM *vm, VAL a, VAL b) {
418VAL idris_b32UDiv(VM *vm, VAL a, VAL b) {
419− uint32_t A = a->info.bits32;
419+ uint32_t A = GETBITS32(a);
420− uint32_t B = b->info.bits32;
420+ uint32_t B = GETBITS32(b);
421 VAL cl = allocate(sizeof(Closure), 0);
421 VAL cl = allocate(sizeof(Closure), 0);
422 SETTY(cl, CT_BITS32);
422 SETTY(cl, CT_BITS32);
423 cl->info.bits32 = A / B;
423 cl->info.bits32 = A / B;
@@ -425,8 +425,8 @@ VAL idris_b32UDiv(VM *vm, VAL a, VAL b) {
425}
425}
426
426
427VAL idris_b32SDiv(VM *vm, VAL a, VAL b) {
427VAL idris_b32SDiv(VM *vm, VAL a, VAL b) {
428− uint32_t A = a->info.bits32;
428+ uint32_t A = GETBITS32(a);
429− uint32_t B = b->info.bits32;
429+ uint32_t B = GETBITS32(b);
430 VAL cl = allocate(sizeof(Closure), 0);
430 VAL cl = allocate(sizeof(Closure), 0);
431 SETTY(cl, CT_BITS32);
431 SETTY(cl, CT_BITS32);
432 cl->info.bits32 = (uint32_t) (((int32_t) A) / ((int32_t) B));
432 cl->info.bits32 = (uint32_t) (((int32_t) A) / ((int32_t) B));
@@ -434,8 +434,8 @@ VAL idris_b32SDiv(VM *vm, VAL a, VAL b) {
434}
434}
435
435
436VAL idris_b32URem(VM *vm, VAL a, VAL b) {
436VAL idris_b32URem(VM *vm, VAL a, VAL b) {
437− uint32_t A = a->info.bits32;
437+ uint32_t A = GETBITS32(a);
438− uint32_t B = b->info.bits32;
438+ uint32_t B = GETBITS32(b);
439 VAL cl = allocate(sizeof(Closure), 0);
439 VAL cl = allocate(sizeof(Closure), 0);
440 SETTY(cl, CT_BITS32);
440 SETTY(cl, CT_BITS32);
441 cl->info.bits32 = A % B;
441 cl->info.bits32 = A % B;
@@ -443,8 +443,8 @@ VAL idris_b32URem(VM *vm, VAL a, VAL b) {
443}
443}
444
444
445VAL idris_b32SRem(VM *vm, VAL a, VAL b) {
445VAL idris_b32SRem(VM *vm, VAL a, VAL b) {
446− uint32_t A = a->info.bits32;
446+ uint32_t A = GETBITS32(a);
447− uint32_t B = b->info.bits32;
447+ uint32_t B = GETBITS32(b);
448 VAL cl = allocate(sizeof(Closure), 0);
448 VAL cl = allocate(sizeof(Closure), 0);
449 SETTY(cl, CT_BITS32);
449 SETTY(cl, CT_BITS32);
450 cl->info.bits32 = (uint32_t) (((int32_t) A) % ((int32_t) B));
450 cl->info.bits32 = (uint32_t) (((int32_t) A) % ((int32_t) B));
@@ -452,27 +452,27 @@ VAL idris_b32SRem(VM *vm, VAL a, VAL b) {
452}
452}
453
453
454VAL idris_b32Lt(VM *vm, VAL a, VAL b) {
454VAL 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)));
456}
456}
457
457
458VAL idris_b32Gt(VM *vm, VAL a, VAL b) {
458VAL 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)));
460}
460}
461
461
462VAL idris_b32Eq(VM *vm, VAL a, VAL b) {
462VAL 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)));
464}
464}
465
465
466VAL idris_b32Lte(VM *vm, VAL a, VAL b) {
466VAL 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)));
468}
468}
469
469
470VAL idris_b32Gte(VM *vm, VAL a, VAL b) {
470VAL 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)));
472}
472}
473
473
474VAL idris_b32Compl(VM *vm, VAL a) {
474VAL idris_b32Compl(VM *vm, VAL a) {
475− uint32_t A = a->info.bits32;
475+ uint32_t A = GETBITS32(a);
476 VAL cl = allocate(sizeof(Closure), 0);
476 VAL cl = allocate(sizeof(Closure), 0);
477 SETTY(cl, CT_BITS32);
477 SETTY(cl, CT_BITS32);
478 cl->info.bits32 = ~ A;
478 cl->info.bits32 = ~ A;
@@ -480,8 +480,8 @@ VAL idris_b32Compl(VM *vm, VAL a) {
480}
480}
481
481
482VAL idris_b32And(VM *vm, VAL a, VAL b) {
482VAL idris_b32And(VM *vm, VAL a, VAL b) {
483− uint32_t A = a->info.bits32;
483+ uint32_t A = GETBITS32(a);
484− uint32_t B = b->info.bits32;
484+ uint32_t B = GETBITS32(b);
485 VAL cl = allocate(sizeof(Closure), 0);
485 VAL cl = allocate(sizeof(Closure), 0);
486 SETTY(cl, CT_BITS32);
486 SETTY(cl, CT_BITS32);
487 cl->info.bits32 = A & B;
487 cl->info.bits32 = A & B;
@@ -489,8 +489,8 @@ VAL idris_b32And(VM *vm, VAL a, VAL b) {
489}
489}
490
490
491VAL idris_b32Or(VM *vm, VAL a, VAL b) {
491VAL idris_b32Or(VM *vm, VAL a, VAL b) {
492− uint32_t A = a->info.bits32;
492+ uint32_t A = GETBITS32(a);
493− uint32_t B = b->info.bits32;
493+ uint32_t B = GETBITS32(b);
494 VAL cl = allocate(sizeof(Closure), 0);
494 VAL cl = allocate(sizeof(Closure), 0);
495 SETTY(cl, CT_BITS32);
495 SETTY(cl, CT_BITS32);
496 cl->info.bits32 = A | B;
496 cl->info.bits32 = A | B;
@@ -498,8 +498,8 @@ VAL idris_b32Or(VM *vm, VAL a, VAL b) {
498}
498}
499
499
500VAL idris_b32Xor(VM *vm, VAL a, VAL b) {
500VAL idris_b32Xor(VM *vm, VAL a, VAL b) {
501− uint32_t A = a->info.bits32;
501+ uint32_t A = GETBITS32(a);
502− uint32_t B = b->info.bits32;
502+ uint32_t B = GETBITS32(b);
503 VAL cl = allocate(sizeof(Closure), 0);
503 VAL cl = allocate(sizeof(Closure), 0);
504 SETTY(cl, CT_BITS32);
504 SETTY(cl, CT_BITS32);
505 cl->info.bits32 = A ^ B;
505 cl->info.bits32 = A ^ B;
@@ -507,8 +507,8 @@ VAL idris_b32Xor(VM *vm, VAL a, VAL b) {
507}
507}
508
508
509VAL idris_b32Shl(VM *vm, VAL a, VAL b) {
509VAL idris_b32Shl(VM *vm, VAL a, VAL b) {
510− uint32_t A = a->info.bits32;
510+ uint32_t A = GETBITS32(a);
511− uint32_t B = b->info.bits32;
511+ uint32_t B = GETBITS32(b);
512 VAL cl = allocate(sizeof(Closure), 0);
512 VAL cl = allocate(sizeof(Closure), 0);
513 SETTY(cl, CT_BITS32);
513 SETTY(cl, CT_BITS32);
514 cl->info.bits32 = A << B;
514 cl->info.bits32 = A << B;
@@ -516,8 +516,8 @@ VAL idris_b32Shl(VM *vm, VAL a, VAL b) {
516}
516}
517
517
518VAL idris_b32LShr(VM *vm, VAL a, VAL b) {
518VAL idris_b32LShr(VM *vm, VAL a, VAL b) {
519− uint32_t A = a->info.bits32;
519+ uint32_t A = GETBITS32(a);
520− uint32_t B = b->info.bits32;
520+ uint32_t B = GETBITS32(b);
521 VAL cl = allocate(sizeof(Closure), 0);
521 VAL cl = allocate(sizeof(Closure), 0);
522 SETTY(cl, CT_BITS32);
522 SETTY(cl, CT_BITS32);
523 cl->info.bits32 = A >> B;
523 cl->info.bits32 = A >> B;
@@ -525,8 +525,8 @@ VAL idris_b32LShr(VM *vm, VAL a, VAL b) {
525}
525}
526
526
527VAL idris_b32AShr(VM *vm, VAL a, VAL b) {
527VAL idris_b32AShr(VM *vm, VAL a, VAL b) {
528− uint32_t A = a->info.bits32;
528+ uint32_t A = GETBITS32(a);
529− uint32_t B = b->info.bits32;
529+ uint32_t B = GETBITS32(b);
530 VAL cl = allocate(sizeof(Closure), 0);
530 VAL cl = allocate(sizeof(Closure), 0);
531 SETTY(cl, CT_BITS32);
531 SETTY(cl, CT_BITS32);
532 cl->info.bits32 = (uint32_t) (((int32_t)A) >> ((int32_t)B));
532 cl->info.bits32 = (uint32_t) (((int32_t)A) >> ((int32_t)B));
@@ -534,8 +534,8 @@ VAL idris_b32AShr(VM *vm, VAL a, VAL b) {
534}
534}
535
535
536VAL idris_b64Plus(VM *vm, VAL a, VAL b) {
536VAL idris_b64Plus(VM *vm, VAL a, VAL b) {
537− uint64_t A = a->info.bits64;
537+ uint64_t A = GETBITS64(a);
538− uint64_t B = b->info.bits64;
538+ uint64_t B = GETBITS64(b);
539 VAL cl = allocate(sizeof(Closure), 0);
539 VAL cl = allocate(sizeof(Closure), 0);
540 SETTY(cl, CT_BITS64);
540 SETTY(cl, CT_BITS64);
541 cl->info.bits64 = A + B;
541 cl->info.bits64 = A + B;
@@ -543,8 +543,8 @@ VAL idris_b64Plus(VM *vm, VAL a, VAL b) {
543}
543}
544
544
545VAL idris_b64Minus(VM *vm, VAL a, VAL b) {
545VAL idris_b64Minus(VM *vm, VAL a, VAL b) {
546− uint64_t A = a->info.bits64;
546+ uint64_t A = GETBITS64(a);
547− uint64_t B = b->info.bits64;
547+ uint64_t B = GETBITS64(b);
548 VAL cl = allocate(sizeof(Closure), 0);
548 VAL cl = allocate(sizeof(Closure), 0);
549 SETTY(cl, CT_BITS64);
549 SETTY(cl, CT_BITS64);
550 cl->info.bits64 = A - B;
550 cl->info.bits64 = A - B;
@@ -552,8 +552,8 @@ VAL idris_b64Minus(VM *vm, VAL a, VAL b) {
552}
552}
553
553
554VAL idris_b64Times(VM *vm, VAL a, VAL b) {
554VAL idris_b64Times(VM *vm, VAL a, VAL b) {
555− uint64_t A = a->info.bits64;
555+ uint64_t A = GETBITS64(a);
556− uint64_t B = b->info.bits64;
556+ uint64_t B = GETBITS64(b);
557 VAL cl = allocate(sizeof(Closure), 0);
557 VAL cl = allocate(sizeof(Closure), 0);
558 SETTY(cl, CT_BITS64);
558 SETTY(cl, CT_BITS64);
559 cl->info.bits64 = A * B;
559 cl->info.bits64 = A * B;
@@ -561,8 +561,8 @@ VAL idris_b64Times(VM *vm, VAL a, VAL b) {
561}
561}
562
562
563VAL idris_b64UDiv(VM *vm, VAL a, VAL b) {
563VAL idris_b64UDiv(VM *vm, VAL a, VAL b) {
564− uint64_t A = a->info.bits64;
564+ uint64_t A = GETBITS64(a);
565− uint64_t B = b->info.bits64;
565+ uint64_t B = GETBITS64(b);
566 VAL cl = allocate(sizeof(Closure), 0);
566 VAL cl = allocate(sizeof(Closure), 0);
567 SETTY(cl, CT_BITS64);
567 SETTY(cl, CT_BITS64);
568 cl->info.bits64 = A / B;
568 cl->info.bits64 = A / B;
@@ -570,8 +570,8 @@ VAL idris_b64UDiv(VM *vm, VAL a, VAL b) {
570}
570}
571
571
572VAL idris_b64SDiv(VM *vm, VAL a, VAL b) {
572VAL idris_b64SDiv(VM *vm, VAL a, VAL b) {
573− uint64_t A = a->info.bits64;
573+ uint64_t A = GETBITS64(a);
574− uint64_t B = b->info.bits64;
574+ uint64_t B = GETBITS64(b);
575 VAL cl = allocate(sizeof(Closure), 0);
575 VAL cl = allocate(sizeof(Closure), 0);
576 SETTY(cl, CT_BITS64);
576 SETTY(cl, CT_BITS64);
577 cl->info.bits64 = (uint64_t) (((int64_t) A) / ((int64_t) B));
577 cl->info.bits64 = (uint64_t) (((int64_t) A) / ((int64_t) B));
@@ -579,8 +579,8 @@ VAL idris_b64SDiv(VM *vm, VAL a, VAL b) {
579}
579}
580
580
581VAL idris_b64URem(VM *vm, VAL a, VAL b) {
581VAL idris_b64URem(VM *vm, VAL a, VAL b) {
582− uint64_t A = a->info.bits64;
582+ uint64_t A = GETBITS64(a);
583− uint64_t B = b->info.bits64;
583+ uint64_t B = GETBITS64(b);
584 VAL cl = allocate(sizeof(Closure), 0);
584 VAL cl = allocate(sizeof(Closure), 0);
585 SETTY(cl, CT_BITS64);
585 SETTY(cl, CT_BITS64);
586 cl->info.bits64 = A % B;
586 cl->info.bits64 = A % B;
@@ -588,8 +588,8 @@ VAL idris_b64URem(VM *vm, VAL a, VAL b) {
588}
588}
589
589
590VAL idris_b64SRem(VM *vm, VAL a, VAL b) {
590VAL idris_b64SRem(VM *vm, VAL a, VAL b) {
591− uint64_t A = a->info.bits64;
591+ uint64_t A = GETBITS64(a);
592− uint64_t B = b->info.bits64;
592+ uint64_t B = GETBITS64(b);
593 VAL cl = allocate(sizeof(Closure), 0);
593 VAL cl = allocate(sizeof(Closure), 0);
594 SETTY(cl, CT_BITS64);
594 SETTY(cl, CT_BITS64);
595 cl->info.bits64 = (uint64_t) (((int64_t) A) % ((int64_t) B));
595 cl->info.bits64 = (uint64_t) (((int64_t) A) % ((int64_t) B));
@@ -617,7 +617,7 @@ VAL idris_b64Gte(VM *vm, VAL a, VAL b) {
617}
617}
618
618
619VAL idris_b64Compl(VM *vm, VAL a) {
619VAL idris_b64Compl(VM *vm, VAL a) {
620− uint64_t A = a->info.bits64;
620+ uint64_t A = GETBITS64(a);
621 VAL cl = allocate(sizeof(Closure), 0);
621 VAL cl = allocate(sizeof(Closure), 0);
622 SETTY(cl, CT_BITS64);
622 SETTY(cl, CT_BITS64);
623 cl->info.bits64 = ~ A;
623 cl->info.bits64 = ~ A;
@@ -625,8 +625,8 @@ VAL idris_b64Compl(VM *vm, VAL a) {
625}
625}
626
626
627VAL idris_b64And(VM *vm, VAL a, VAL b) {
627VAL idris_b64And(VM *vm, VAL a, VAL b) {
628− uint64_t A = a->info.bits64;
628+ uint64_t A = GETBITS64(a);
629− uint64_t B = b->info.bits64;
629+ uint64_t B = GETBITS64(b);
630 VAL cl = allocate(sizeof(Closure), 0);
630 VAL cl = allocate(sizeof(Closure), 0);
631 SETTY(cl, CT_BITS64);
631 SETTY(cl, CT_BITS64);
632 cl->info.bits64 = A & B;
632 cl->info.bits64 = A & B;
@@ -634,8 +634,8 @@ VAL idris_b64And(VM *vm, VAL a, VAL b) {
634}
634}
635
635
636VAL idris_b64Or(VM *vm, VAL a, VAL b) {
636VAL idris_b64Or(VM *vm, VAL a, VAL b) {
637− uint64_t A = a->info.bits64;
637+ uint64_t A = GETBITS64(a);
638− uint64_t B = b->info.bits64;
638+ uint64_t B = GETBITS64(b);
639 VAL cl = allocate(sizeof(Closure), 0);
639 VAL cl = allocate(sizeof(Closure), 0);
640 SETTY(cl, CT_BITS64);
640 SETTY(cl, CT_BITS64);
641 cl->info.bits64 = A | B;
641 cl->info.bits64 = A | B;
@@ -643,8 +643,8 @@ VAL idris_b64Or(VM *vm, VAL a, VAL b) {
643}
643}
644
644
645VAL idris_b64Xor(VM *vm, VAL a, VAL b) {
645VAL idris_b64Xor(VM *vm, VAL a, VAL b) {
646− uint64_t A = a->info.bits64;
646+ uint64_t A = GETBITS64(a);
647− uint64_t B = b->info.bits64;
647+ uint64_t B = GETBITS64(b);
648 VAL cl = allocate(sizeof(Closure), 0);
648 VAL cl = allocate(sizeof(Closure), 0);
649 SETTY(cl, CT_BITS64);
649 SETTY(cl, CT_BITS64);
650 cl->info.bits64 = A ^ B;
650 cl->info.bits64 = A ^ B;
@@ -652,8 +652,8 @@ VAL idris_b64Xor(VM *vm, VAL a, VAL b) {
652}
652}
653
653
654VAL idris_b64Shl(VM *vm, VAL a, VAL b) {
654VAL idris_b64Shl(VM *vm, VAL a, VAL b) {
655− uint64_t A = a->info.bits64;
655+ uint64_t A = GETBITS64(a);
656− uint64_t B = b->info.bits64;
656+ uint64_t B = GETBITS64(b);
657 VAL cl = allocate(sizeof(Closure), 0);
657 VAL cl = allocate(sizeof(Closure), 0);
658 SETTY(cl, CT_BITS64);
658 SETTY(cl, CT_BITS64);
659 cl->info.bits64 = A << B;
659 cl->info.bits64 = A << B;
@@ -661,8 +661,8 @@ VAL idris_b64Shl(VM *vm, VAL a, VAL b) {
661}
661}
662
662
663VAL idris_b64LShr(VM *vm, VAL a, VAL b) {
663VAL idris_b64LShr(VM *vm, VAL a, VAL b) {
664− uint64_t A = a->info.bits64;
664+ uint64_t A = GETBITS64(a);
665− uint64_t B = b->info.bits64;
665+ uint64_t B = GETBITS64(b);
666 VAL cl = allocate(sizeof(Closure), 0);
666 VAL cl = allocate(sizeof(Closure), 0);
667 SETTY(cl, CT_BITS64);
667 SETTY(cl, CT_BITS64);
668 cl->info.bits64 = A >> B;
668 cl->info.bits64 = A >> B;
@@ -670,8 +670,8 @@ VAL idris_b64LShr(VM *vm, VAL a, VAL b) {
670}
670}
671
671
672VAL idris_b64AShr(VM *vm, VAL a, VAL b) {
672VAL idris_b64AShr(VM *vm, VAL a, VAL b) {
673− uint64_t A = a->info.bits64;
673+ uint64_t A = GETBITS64(a);
674− uint64_t B = b->info.bits64;
674+ uint64_t B = GETBITS64(b);
675 VAL cl = allocate(sizeof(Closure), 0);
675 VAL cl = allocate(sizeof(Closure), 0);
676 SETTY(cl, CT_BITS64);
676 SETTY(cl, CT_BITS64);
677 cl->info.bits64 = (uint64_t) (((int64_t) A) >> ((int64_t) B));
677 cl->info.bits64 = (uint64_t) (((int64_t) A) >> ((int64_t) B));
@@ -679,7 +679,7 @@ VAL idris_b64AShr(VM *vm, VAL a, VAL b) {
679}
679}
680
680
681VAL idris_b8Z16(VM *vm, VAL a) {
681VAL idris_b8Z16(VM *vm, VAL a) {
682− uint8_t A = a->info.bits8;
682+ uint8_t A = GETBITS8(a);
683 VAL cl = allocate(sizeof(Closure), 0);
683 VAL cl = allocate(sizeof(Closure), 0);
684 SETTY(cl, CT_BITS16);
684 SETTY(cl, CT_BITS16);
685 cl->info.bits16 = (uint16_t) A;
685 cl->info.bits16 = (uint16_t) A;
@@ -687,7 +687,7 @@ VAL idris_b8Z16(VM *vm, VAL a) {
687}
687}
688
688
689VAL idris_b8Z32(VM *vm, VAL a) {
689VAL idris_b8Z32(VM *vm, VAL a) {
690− uint8_t A = a->info.bits8;
690+ uint8_t A = GETBITS8(a);
691 VAL cl = allocate(sizeof(Closure), 0);
691 VAL cl = allocate(sizeof(Closure), 0);
692 SETTY(cl, CT_BITS32);
692 SETTY(cl, CT_BITS32);
693 cl->info.bits32 = (uint32_t) A;
693 cl->info.bits32 = (uint32_t) A;
@@ -695,7 +695,7 @@ VAL idris_b8Z32(VM *vm, VAL a) {
695}
695}
696
696
697VAL idris_b8Z64(VM *vm, VAL a) {
697VAL idris_b8Z64(VM *vm, VAL a) {
698− uint8_t A = a->info.bits8;
698+ uint8_t A = GETBITS8(a);
699 VAL cl = allocate(sizeof(Closure), 0);
699 VAL cl = allocate(sizeof(Closure), 0);
700 SETTY(cl, CT_BITS64);
700 SETTY(cl, CT_BITS64);
701 cl->info.bits64 = (uint64_t) A;
701 cl->info.bits64 = (uint64_t) A;
@@ -703,7 +703,7 @@ VAL idris_b8Z64(VM *vm, VAL a) {
703}
703}
704
704
705VAL idris_b8S16(VM *vm, VAL a) {
705VAL idris_b8S16(VM *vm, VAL a) {
706− uint8_t A = a->info.bits8;
706+ uint8_t A = GETBITS8(a);
707 VAL cl = allocate(sizeof(Closure), 0);
707 VAL cl = allocate(sizeof(Closure), 0);
708 SETTY(cl, CT_BITS16);
708 SETTY(cl, CT_BITS16);
709 cl->info.bits16 = (uint16_t) (int16_t) (int8_t) A;
709 cl->info.bits16 = (uint16_t) (int16_t) (int8_t) A;
@@ -711,7 +711,7 @@ VAL idris_b8S16(VM *vm, VAL a) {
711}
711}
712
712
713VAL idris_b8S32(VM *vm, VAL a) {
713VAL idris_b8S32(VM *vm, VAL a) {
714− uint8_t A = a->info.bits8;
714+ uint8_t A = GETBITS8(a);
715 VAL cl = allocate(sizeof(Closure), 0);
715 VAL cl = allocate(sizeof(Closure), 0);
716 SETTY(cl, CT_BITS32);
716 SETTY(cl, CT_BITS32);
717 cl->info.bits32 = (uint32_t) (int32_t) (int8_t) A;
717 cl->info.bits32 = (uint32_t) (int32_t) (int8_t) A;
@@ -719,7 +719,7 @@ VAL idris_b8S32(VM *vm, VAL a) {
719}
719}
720
720
721VAL idris_b8S64(VM *vm, VAL a) {
721VAL idris_b8S64(VM *vm, VAL a) {
722− uint8_t A = a->info.bits8;
722+ uint8_t A = GETBITS8(a);
723 VAL cl = allocate(sizeof(Closure), 0);
723 VAL cl = allocate(sizeof(Closure), 0);
724 SETTY(cl, CT_BITS64);
724 SETTY(cl, CT_BITS64);
725 cl->info.bits64 = (uint64_t) (int64_t) (int8_t) A;
725 cl->info.bits64 = (uint64_t) (int64_t) (int8_t) A;
@@ -727,7 +727,7 @@ VAL idris_b8S64(VM *vm, VAL a) {
727}
727}
728
728
729VAL idris_b16Z32(VM *vm, VAL a) {
729VAL idris_b16Z32(VM *vm, VAL a) {
730− uint16_t A = a->info.bits16;
730+ uint16_t A = GETBITS16(a);
731 VAL cl = allocate(sizeof(Closure), 0);
731 VAL cl = allocate(sizeof(Closure), 0);
732 SETTY(cl, CT_BITS32);
732 SETTY(cl, CT_BITS32);
733 cl->info.bits32 = (uint32_t) A;
733 cl->info.bits32 = (uint32_t) A;
@@ -735,7 +735,7 @@ VAL idris_b16Z32(VM *vm, VAL a) {
735}
735}
736
736
737VAL idris_b16Z64(VM *vm, VAL a) {
737VAL idris_b16Z64(VM *vm, VAL a) {
738− uint16_t A = a->info.bits16;
738+ uint16_t A = GETBITS16(a);
739 VAL cl = allocate(sizeof(Closure), 0);
739 VAL cl = allocate(sizeof(Closure), 0);
740 SETTY(cl, CT_BITS64);
740 SETTY(cl, CT_BITS64);
741 cl->info.bits64 = (uint64_t) A;
741 cl->info.bits64 = (uint64_t) A;
@@ -743,7 +743,7 @@ VAL idris_b16Z64(VM *vm, VAL a) {
743}
743}
744
744
745VAL idris_b16S32(VM *vm, VAL a) {
745VAL idris_b16S32(VM *vm, VAL a) {
746− uint16_t A = a->info.bits16;
746+ uint16_t A = GETBITS16(a);
747 VAL cl = allocate(sizeof(Closure), 0);
747 VAL cl = allocate(sizeof(Closure), 0);
748 SETTY(cl, CT_BITS32);
748 SETTY(cl, CT_BITS32);
749 cl->info.bits32 = (uint32_t) (int32_t) (int16_t) A;
749 cl->info.bits32 = (uint32_t) (int32_t) (int16_t) A;
@@ -751,7 +751,7 @@ VAL idris_b16S32(VM *vm, VAL a) {
751}
751}
752
752
753VAL idris_b16S64(VM *vm, VAL a) {
753VAL idris_b16S64(VM *vm, VAL a) {
754− uint16_t A = a->info.bits16;
754+ uint16_t A = GETBITS16(a);
755 VAL cl = allocate(sizeof(Closure), 0);
755 VAL cl = allocate(sizeof(Closure), 0);
756 SETTY(cl, CT_BITS64);
756 SETTY(cl, CT_BITS64);
757 cl->info.bits64 = (uint64_t) (int64_t) (int16_t) A;
757 cl->info.bits64 = (uint64_t) (int64_t) (int16_t) A;
@@ -759,7 +759,7 @@ VAL idris_b16S64(VM *vm, VAL a) {
759}
759}
760
760
761VAL idris_b16T8(VM *vm, VAL a) {
761VAL idris_b16T8(VM *vm, VAL a) {
762− uint16_t A = a->info.bits16;
762+ uint16_t A = GETBITS16(a);
763 VAL cl = allocate(sizeof(Closure), 0);
763 VAL cl = allocate(sizeof(Closure), 0);
764 SETTY(cl, CT_BITS8);
764 SETTY(cl, CT_BITS8);
765 cl->info.bits8 = (uint8_t) A;
765 cl->info.bits8 = (uint8_t) A;
@@ -767,7 +767,7 @@ VAL idris_b16T8(VM *vm, VAL a) {
767}
767}
768
768
769VAL idris_b32Z64(VM *vm, VAL a) {
769VAL idris_b32Z64(VM *vm, VAL a) {
770− uint32_t A = a->info.bits32;
770+ uint32_t A = GETBITS32(a);
771 VAL cl = allocate(sizeof(Closure), 0);
771 VAL cl = allocate(sizeof(Closure), 0);
772 SETTY(cl, CT_BITS64);
772 SETTY(cl, CT_BITS64);
773 cl->info.bits64 = (uint64_t) A;
773 cl->info.bits64 = (uint64_t) A;
@@ -775,7 +775,7 @@ VAL idris_b32Z64(VM *vm, VAL a) {
775}
775}
776
776
777VAL idris_b32S64(VM *vm, VAL a) {
777VAL idris_b32S64(VM *vm, VAL a) {
778− uint32_t A = a->info.bits32;
778+ uint32_t A = GETBITS32(a);
779 VAL cl = allocate(sizeof(Closure), 0);
779 VAL cl = allocate(sizeof(Closure), 0);
780 SETTY(cl, CT_BITS64);
780 SETTY(cl, CT_BITS64);
781 cl->info.bits64 = (uint64_t) (int64_t) (int32_t) A;
781 cl->info.bits64 = (uint64_t) (int64_t) (int32_t) A;
@@ -783,7 +783,7 @@ VAL idris_b32S64(VM *vm, VAL a) {
783}
783}
784
784
785VAL idris_b32T8(VM *vm, VAL a) {
785VAL idris_b32T8(VM *vm, VAL a) {
786− uint32_t A = a->info.bits32;
786+ uint32_t A = GETBITS32(a);
787 VAL cl = allocate(sizeof(Closure), 0);
787 VAL cl = allocate(sizeof(Closure), 0);
788 SETTY(cl, CT_BITS8);
788 SETTY(cl, CT_BITS8);
789 cl->info.bits8 = (uint8_t) A;
789 cl->info.bits8 = (uint8_t) A;
@@ -791,7 +791,7 @@ VAL idris_b32T8(VM *vm, VAL a) {
791}
791}
792
792
793VAL idris_b32T16(VM *vm, VAL a) {
793VAL idris_b32T16(VM *vm, VAL a) {
794− uint32_t A = a->info.bits32;
794+ uint32_t A = GETBITS32(a);
795 VAL cl = allocate(sizeof(Closure), 0);
795 VAL cl = allocate(sizeof(Closure), 0);
796 SETTY(cl, CT_BITS16);
796 SETTY(cl, CT_BITS16);
797 cl->info.bits16 = (uint16_t) A;
797 cl->info.bits16 = (uint16_t) A;
@@ -799,7 +799,7 @@ VAL idris_b32T16(VM *vm, VAL a) {
799}
799}
800
800
801VAL idris_b64T8(VM *vm, VAL a) {
801VAL idris_b64T8(VM *vm, VAL a) {
802− uint64_t A = a->info.bits64;
802+ uint64_t A = GETBITS64(a);
803 VAL cl = allocate(sizeof(Closure), 0);
803 VAL cl = allocate(sizeof(Closure), 0);
804 SETTY(cl, CT_BITS8);
804 SETTY(cl, CT_BITS8);
805 cl->info.bits8 = (uint8_t) A;
805 cl->info.bits8 = (uint8_t) A;
@@ -807,7 +807,7 @@ VAL idris_b64T8(VM *vm, VAL a) {
807}
807}
808
808
809VAL idris_b64T16(VM *vm, VAL a) {
809VAL idris_b64T16(VM *vm, VAL a) {
810− uint64_t A = a->info.bits64;
810+ uint64_t A = GETBITS64(a);
811 VAL cl = allocate(sizeof(Closure), 0);
811 VAL cl = allocate(sizeof(Closure), 0);
812 SETTY(cl, CT_BITS16);
812 SETTY(cl, CT_BITS16);
813 cl->info.bits16 = (uint16_t) A;
813 cl->info.bits16 = (uint16_t) A;
@@ -815,7 +815,7 @@ VAL idris_b64T16(VM *vm, VAL a) {
815}
815}
816
816
817VAL idris_b64T32(VM *vm, VAL a) {
817VAL idris_b64T32(VM *vm, VAL a) {
818− uint64_t A = a->info.bits64;
818+ uint64_t A = GETBITS64(a);
819 VAL cl = allocate(sizeof(Closure), 0);
819 VAL cl = allocate(sizeof(Closure), 0);
820 SETTY(cl, CT_BITS32);
820 SETTY(cl, CT_BITS32);
821 cl->info.bits32 = (uint32_t) A;
821 cl->info.bits32 = (uint32_t) A;
rts/idris_buffer.c+5−18
@@ -82,9 +82,9 @@ uint8_t idris_getBufferByte(void* buffer, int loc) {
82int idris_getBufferInt(void* buffer, int loc) {
82int idris_getBufferInt(void* buffer, int loc) {
83 Buffer* b = buffer;
83 Buffer* b = buffer;
84 if (loc >= 0 && loc+3 < b->size) {
84 if (loc >= 0 && loc+3 < b->size) {
85− return b->data[loc] +
85+ return b->data[loc] +
86 (b->data[loc+1] << 8) +
86 (b->data[loc+1] << 8) +
87− (b->data[loc+2] << 16) +
87+ (b->data[loc+2] << 16) +
88 (b->data[loc+3] << 24);
88 (b->data[loc+3] << 24);
89 } else {
89 } else {
90 return 0;
90 return 0;
@@ -111,21 +111,9 @@ double idris_getBufferDouble(void* buffer, int loc) {
111VAL idris_getBufferString(void* buffer, int loc, int len) {
111VAL idris_getBufferString(void* buffer, int loc, int len) {
112 Buffer* b = buffer;
112 Buffer* b = buffer;
113
113
114− Closure* cl = allocate(sizeof(Closure) + // Type) + sizeof(char*) +
114+ char * s = (char*)(b->data + loc);
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) {
115+ size_t sz = loc >= 0 && loc+len <= b->size? len : 0;
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;
116+ return MKSTRlen(NULL, s, sz);
129}
117}
130
118
131int idris_readBuffer(FILE* h, void* buffer, int loc, int max) {
119int 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) {
153 fwrite((b->data)+loc, sizeof(uint8_t), len, h);
141 fwrite((b->data)+loc, sizeof(uint8_t), len, h);
154 }
142 }
155}
143}
156−
rts/idris_gc.c+21−21
@@ -17,31 +17,31 @@ VAL copy(VM* vm, VAL x) {
17 return x;
17 return x;
18 } else {
18 } else {
19 allocCon(cl, vm, CTAG(x), ar, 1);
19 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);
21 }
21 }
22 break;
22 break;
23 case CT_ARRAY:
23 case CT_ARRAY:
24− len = x->info.arr.length;
24+ len = x->sz;
25 allocArray(cl, vm, len, 1);
25 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);
27 break;
27 break;
28 case CT_FLOAT:
28 case CT_FLOAT:
29− cl = MKFLOATc(vm, x->info.f);
29+ cl = MKFLOATc(vm, GETFLOAT(x));
30 break;
30 break;
31 case CT_STRING:
31 case CT_STRING:
32− cl = MKSTRclen(vm, x->info.str.str, x->info.str.len);
32+ cl = MKSTRclen(vm, x->info.str, x->sz);
33 break;
33 break;
34 case CT_STROFFSET:
34 case CT_STROFFSET:
35 cl = MKSTROFFc(vm, x->info.str_offset);
35 cl = MKSTROFFc(vm, x->info.str_offset);
36 break;
36 break;
37 case CT_BIGINT:
37 case CT_BIGINT:
38− cl = MKBIGMc(vm, x->info.ptr);
38+ cl = MKBIGMc(vm, GETPTR(x));
39 break;
39 break;
40 case CT_PTR:
40 case CT_PTR:
41− cl = MKPTRc(vm, x->info.ptr);
41+ cl = MKPTRc(vm, GETPTR(x));
42 break;
42 break;
43 case CT_MANAGEDPTR:
43 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);
45 break;
45 break;
46 case CT_BITS8:
46 case CT_BITS8:
47 cl = idris_b8CopyForGC(vm, x);
47 cl = idris_b8CopyForGC(vm, x);
@@ -56,20 +56,20 @@ VAL copy(VM* vm, VAL x) {
56 cl = idris_b64CopyForGC(vm, x);
56 cl = idris_b64CopyForGC(vm, x);
57 break;
57 break;
58 case CT_REF:
58 case CT_REF:
59− cl = idris_newRefLock((VAL)(x->info.ptr), 1);
59+ cl = idris_newRefLock((VAL)(GETPTR(x)), 1);
60 break;
60 break;
61 case CT_FWD:
61 case CT_FWD:
62− return x->info.ptr;
62+ return GETPTR(x);
63 case CT_RAWDATA:
63 case CT_RAWDATA:
64 {
64 {
65− size_t size = x->info.size + sizeof(Closure);
65+ size_t size = x->sz + sizeof(Closure);
66 cl = allocate(size, 1);
66 cl = allocate(size, 1);
67 memcpy(cl, x, size);
67 memcpy(cl, x, size);
68 }
68 }
69 break;
69 break;
70 case CT_CDATA:
70 case CT_CDATA:
71− cl = MKCDATAc(vm, x->info.c_heap_item);
71+ cl = MKCDATAc(vm, GETCDATA(x));
72− c_heap_mark_item(x->info.c_heap_item);
72+ c_heap_mark_item(GETCDATA(x));
73 break;
73 break;
74 default:
74 default:
75 break;
75 break;
@@ -92,23 +92,23 @@ void cheney(VM *vm) {
92 case CT_CON:
92 case CT_CON:
93 ar = ARITY(heap_item);
93 ar = ARITY(heap_item);
94 for(i = 0; i < ar; ++i) {
94 for(i = 0; i < ar; ++i) {
95− VAL newptr = copy(vm, heap_item->info.c.args[i]);
95+ VAL newptr = copy(vm, heap_item->info.cargs[i]);
96− heap_item->info.c.args[i] = newptr;
96+ heap_item->info.cargs[i] = newptr;
97 }
97 }
98 break;
98 break;
99 case CT_ARRAY:
99 case CT_ARRAY:
100− len = heap_item->info.arr.length;
100+ len = heap_item->sz;
101 for(i = 0; i < len; ++i) {
101 for(i = 0; i < len; ++i) {
102− VAL newptr = copy(vm, heap_item->info.arr.content[i]);
102+ VAL newptr = copy(vm, heap_item->info.array[i]);
103− heap_item->info.arr.content[i] = newptr;
103+ heap_item->info.array[i] = newptr;
104 }
104 }
105 break;
105 break;
106 case CT_REF:
106 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)));
108 break;
108 break;
109 case CT_STROFFSET:
109 case CT_STROFFSET:
110− heap_item->info.str_offset->str
110+ heap_item->info.str_offset
111− = copy(vm, heap_item->info.str_offset->str);
111+ = copy(vm, heap_item->info.str_offset);
112 break;
112 break;
113 default: // Nothing to copy
113 default: // Nothing to copy
114 break;
114 break;
rts/idris_heap.c+2−2
@@ -55,7 +55,7 @@ void c_heap_insert_if_needed(VM * vm, CHeap * heap, CHeapItem * item)
55 heap->first = item;
55 heap->first = item;
56
56
57 // at this point, links are done; let's calculate sizes
57 // at this point, links are done; let's calculate sizes
58−
58+
59 heap->size += item->size;
59 heap->size += item->size;
60 if (heap->size >= heap->gc_trigger_size)
60 if (heap->size >= heap->gc_trigger_size)
61 {
61 {
@@ -195,7 +195,7 @@ void heap_check_pointers(Heap * heap) {
195 int ar = ARITY(heap_item);
195 int ar = ARITY(heap_item);
196 int i = 0;
196 int i = 0;
197 for(i = 0; i < ar; ++i) {
197 for(i = 0; i < ar; ++i) {
198− VAL ptr = heap_item->info.c.args[i];
198+ VAL ptr = heap_item->info.cargs[i];
199
199
200 if (is_valid_ref(ptr)) {
200 if (is_valid_ref(ptr)) {
201 // Check for closure.
201 // Check for closure.
rts/idris_rts.c+95−141
@@ -7,6 +7,11 @@
7#include "idris_bitstring.h"
7#include "idris_bitstring.h"
8#include "getline.h"
8#include "getline.h"
9
9
10+#define STATIC_ASSERT(COND,MSG) typedef char static_assertion_##MSG[(COND)?1:-1]
11+
12+
13+STATIC_ASSERT(sizeof(Closure) == 16, sizeofClosure);
14+
10#ifdef HAS_PTHREAD
15#ifdef HAS_PTHREAD
11static pthread_key_t vm_key;
16static pthread_key_t vm_key;
12#else
17#else
@@ -190,8 +195,8 @@ int space(VM* vm, size_t size) {
190void* idris_alloc(size_t size) {
195void* idris_alloc(size_t size) {
191 Closure* cl = (Closure*) allocate(sizeof(Closure)+size, 0);
196 Closure* cl = (Closure*) allocate(sizeof(Closure)+size, 0);
192 SETTY(cl, CT_RAWDATA);
197 SETTY(cl, CT_RAWDATA);
193− cl->info.size = size;
198+ cl->sz = size;
194− return (void*)((char *)cl+sizeof(Closure));
199+ return (void*)(cl+1);
195}
200}
196
201
197void* idris_realloc(void* old, size_t old_size, size_t size) {
202void* idris_realloc(void* old, size_t old_size, size_t size) {
@@ -255,6 +260,14 @@ void* allocate(size_t size, int outerlock) {
255
260
256}
261}
257
262
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+
258/* Now a macro
271/* Now a macro
259void* allocCon(VM* vm, int arity, int outer) {
272void* allocCon(VM* vm, int arity, int outer) {
260 Closure* cl = allocate(vm, sizeof(Closure) + sizeof(VAL)*arity,
273 Closure* cl = allocate(vm, sizeof(Closure) + sizeof(VAL)*arity,
@@ -275,37 +288,29 @@ VAL MKFLOAT(VM* vm, double val) {
275 return cl;
288 return cl;
276}
289}
277
290
278−VAL MKSTR(VM* vm, const char* str) {
291+VAL MKSTRlen(VM* vm, const char * str, size_t len) {
279− int len;
292+ Closure* cl = allocStr(len, 0);
280− if (str == NULL) {
293+ if (str) {
281− len = 0;
294+ memcpy(cl->info.str, str, len);
282 } else {
295 } else {
283− len = strlen(str)+1;
296+ cl->info.str = NULL;
284 }
297 }
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;
295 return cl;
298 return cl;
296}
299}
297
300
301+VAL MKSTR(VM* vm, const char* str) {
302+ return MKSTRlen(vm, str, str? strlen(str) : ~0);
303+}
304+
298char* GETSTROFF(VAL stroff) {
305char* GETSTROFF(VAL stroff) {
299 // Assume STROFF
306 // Assume STROFF
300− StrOffset* root = stroff->info.str_offset;
307+ return stroff->info.str_offset->info.str + stroff->sz;
301− return (root->str->info.str.str + root->offset);
302}
308}
303
309
304size_t GETSTROFFLEN(VAL stroff) {
310size_t GETSTROFFLEN(VAL stroff) {
305 // Assume STROFF
311 // Assume STROFF
306 // we're working in char* here so no worries about utf8 char length
312 // we're working in char* here so no worries about utf8 char length
307− StrOffset* root = stroff->info.str_offset;
313+ return stroff->info.str_offset->sz - stroff->sz;
308− return (root->str->info.str.len - root->offset);
309}
314}
310
315
311VAL MKCDATA(VM* vm, CHeapItem * item) {
316VAL MKCDATA(VM* vm, CHeapItem * item) {
@@ -332,13 +337,10 @@ VAL MKPTR(VM* vm, void* ptr) {
332}
337}
333
338
334VAL MKMPTR(VM* vm, void* ptr, size_t size) {
339VAL MKMPTR(VM* vm, void* ptr, size_t size) {
335− Closure* cl = allocate(sizeof(Closure) +
340+ Closure* cl = allocate(sizeof(Closure) + size, 0);
336− sizeof(ManagedPtr) + size, 0);
337 SETTY(cl, CT_MANAGEDPTR);
341 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);
342+ memcpy(cl->info.managed_ptr, ptr, size);
341− cl->info.mptr->size = size;
343+ cl->sz = size;
342 return cl;
344 return cl;
343}
345}
344
346
@@ -349,28 +351,14 @@ VAL MKFLOATc(VM* vm, double val) {
349 return cl;
351 return cl;
350}
352}
351
353
352−VAL MKSTRc(VM* vm, char* str) {
354+VAL MKSTRclen(VM* vm, char* str, int len) {
353− int len = strlen(str);
355+ Closure* cl = allocStr(len, 1);
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);
356+ memcpy(cl->info.str, str, len);
361− cl->info.str.len = len;
362 return cl;
357 return cl;
363}
358}
364
359
365−VAL MKSTRclen(VM* vm, char* str, int len) {
360+VAL MKSTRc(VM* vm, char* str) {
366− Closure* cl = allocate(sizeof(Closure) + // Type) + sizeof(char*) +
361+ return MKSTRclen(vm, str, strlen(str));
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;
374}
362}
375
363
376VAL MKPTRc(VM* vm, void* ptr) {
364VAL MKPTRc(VM* vm, void* ptr) {
@@ -381,13 +369,10 @@ VAL MKPTRc(VM* vm, void* ptr) {
381}
369}
382
370
383VAL MKMPTRc(VM* vm, void* ptr, size_t size) {
371VAL MKMPTRc(VM* vm, void* ptr, size_t size) {
384− Closure* cl = allocate(sizeof(Closure) +
372+ Closure* cl = allocate(sizeof(Closure) + size, 1);
385− sizeof(ManagedPtr) + size, 1);
386 SETTY(cl, CT_MANAGEDPTR);
373 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);
374+ memcpy(cl->info.managed_ptr, ptr, size);
390− cl->info.mptr->size = size;
375+ cl->sz = size;
391 return cl;
376 return cl;
392}
377}
393
378
@@ -451,18 +436,18 @@ void dumpVal(VAL v) {
451 }
436 }
452 switch(GETTY(v)) {
437 switch(GETTY(v)) {
453 case CT_CON:
438 case CT_CON:
454− printf("%d[", TAG(v));
439+ printf("%lu[", TAG(v));
455 for(i = 0; i < ARITY(v); ++i) {
440 for(i = 0; i < ARITY(v); ++i) {
456− dumpVal(v->info.c.args[i]);
441+ dumpVal(v->info.cargs[i]);
457 }
442 }
458 printf("] ");
443 printf("] ");
459 break;
444 break;
460 case CT_STRING:
445 case CT_STRING:
461− printf("STR[%s]", v->info.str.str);
446+ printf("STR[%s]", v->info.str);
462 break;
447 break;
463 case CT_STROFFSET:
448 case CT_STROFFSET:
464 printf("OFFSET[");
449 printf("OFFSET[");
465− dumpVal((VAL)(v->info.str_offset->str));
450+ dumpVal((VAL)(v->info.str_offset));
466 printf("]");
451 printf("]");
467 break;
452 break;
468 case CT_FWD:
453 case CT_FWD:
@@ -523,50 +508,40 @@ void idris_memmove(void* dest, void* src, i_int dest_offset, i_int src_offset, i
523
508
524VAL idris_castIntStr(VM* vm, VAL i) {
509VAL idris_castIntStr(VM* vm, VAL i) {
525 int x = (int) GETINT(i);
510 int x = (int) GETINT(i);
526− Closure* cl = allocate(sizeof(Closure) + sizeof(char)*16, 0);
511+ Closure* cl = allocStr(16, 0);
527− SETTY(cl, CT_STRING);
528− cl->info.str.str = (char*)cl + sizeof(Closure);
529− sprintf(cl->info.str.str, "%d", x);
512+ cl->sz = sprintf(cl->info.str, "%d", x);
530− cl->info.str.len = strlen(cl->info.str.str);
531 return cl;
513 return cl;
532}
514}
533
515
534VAL idris_castBitsStr(VM* vm, VAL i) {
516VAL idris_castBitsStr(VM* vm, VAL i) {
535 Closure* cl;
517 Closure* cl;
536− ClosureType ty = i->ty;
518+ ClosureType ty = GETTY(i);
537
519
538 switch (ty) {
520 switch (ty) {
539 case CT_BITS8:
521 case CT_BITS8:
540 // max length 8 bit unsigned int str 3 chars (256)
522 // max length 8 bit unsigned int str 3 chars (256)
541− cl = allocate(sizeof(Closure) + sizeof(char)*4, 0);
523+ cl = allocStr(4, 0);
542− cl->info.str.str = (char*)cl + sizeof(Closure);
543− sprintf(cl->info.str.str, "%" PRIu8, (uint8_t)i->info.bits8);
524+ cl->sz = sprintf(cl->info.str, "%" PRIu8, GETBITS8(i));
544 break;
525 break;
545 case CT_BITS16:
526 case CT_BITS16:
546 // max length 16 bit unsigned int str 5 chars (65,535)
527 // max length 16 bit unsigned int str 5 chars (65,535)
547− cl = allocate(sizeof(Closure) + sizeof(char)*6, 0);
528+ cl = allocStr(6, 0);
548− cl->info.str.str = (char*)cl + sizeof(Closure);
549− sprintf(cl->info.str.str, "%" PRIu16, (uint16_t)i->info.bits16);
529+ cl->sz = sprintf(cl->info.str, "%" PRIu16, GETBITS16(i));
550 break;
530 break;
551 case CT_BITS32:
531 case CT_BITS32:
552 // max length 32 bit unsigned int str 10 chars (4,294,967,295)
532 // max length 32 bit unsigned int str 10 chars (4,294,967,295)
553− cl = allocate(sizeof(Closure) + sizeof(char)*11, 0);
533+ cl = allocStr(11, 0);
554− cl->info.str.str = (char*)cl + sizeof(Closure);
555− sprintf(cl->info.str.str, "%" PRIu32, (uint32_t)i->info.bits32);
534+ cl->sz = sprintf(cl->info.str, "%" PRIu32, GETBITS32(i));
556 break;
535 break;
557 case CT_BITS64:
536 case CT_BITS64:
558 // max length 64 bit unsigned int str 20 chars (18,446,744,073,709,551,615)
537 // 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);
538+ cl = allocStr(21, 0);
560− cl->info.str.str = (char*)cl + sizeof(Closure);
561− sprintf(cl->info.str.str, "%" PRIu64, (uint64_t)i->info.bits64);
539+ cl->sz = sprintf(cl->info.str, "%" PRIu64, GETBITS64(i));
562 break;
540 break;
563 default:
541 default:
564 fprintf(stderr, "Fatal Error: ClosureType %d, not an integer type", ty);
542 fprintf(stderr, "Fatal Error: ClosureType %d, not an integer type", ty);
565 exit(EXIT_FAILURE);
543 exit(EXIT_FAILURE);
566 }
544 }
567−
568− cl->info.str.len = strlen(cl->info.str.str);
569− SETTY(cl, CT_STRING);
570 return cl;
545 return cl;
571}
546}
572
547
@@ -580,12 +555,8 @@ VAL idris_castStrInt(VM* vm, VAL i) {
580}
555}
581
556
582VAL idris_castFloatStr(VM* vm, VAL i) {
557VAL idris_castFloatStr(VM* vm, VAL i) {
583− Closure* cl = allocate(sizeof(Closure) + sizeof(char)*32, 0);
558+ Closure* cl = allocStr(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));
559+ cl->sz = snprintf(cl->info.str, 32, "%.16g", GETFLOAT(i));
587−
588− cl->info.str.len = strlen(cl->info.str.str);
589 return cl;
560 return cl;
590}
561}
591
562
@@ -599,13 +570,9 @@ VAL idris_concat(VM* vm, VAL l, VAL r) {
599 int llen = GETSTRLEN(l);
570 int llen = GETSTRLEN(l);
600 int rlen = GETSTRLEN(r);
571 int rlen = GETSTRLEN(r);
601
572
602− Closure* cl = allocate(sizeof(Closure) + llen + rlen + 1, 0);
573+ Closure* cl = allocStr(llen + rlen, 0);
603− SETTY(cl, CT_STRING);
604− cl->info.str.str = (char*)cl + sizeof(Closure);
605− strcpy(cl->info.str.str, ls);
574+ memcpy(cl->info.str, ls, llen);
606− strcat(cl->info.str.str, rs);
575+ memcpy(cl->info.str + llen, rs, rlen);
607−
608− cl->info.str.len = llen + rlen;
609 return cl;
576 return cl;
610}
577}
611
578
@@ -667,13 +634,11 @@ VAL idris_strHead(VM* vm, VAL str) {
667 return idris_strIndex(vm, str, 0);
634 return idris_strIndex(vm, str, 0);
668}
635}
669
636
670−VAL MKSTROFFc(VM* vm, StrOffset* off) {
637+VAL MKSTROFFc(VM* vm, VAL off) {
671− Closure* cl = allocate(sizeof(Closure) + sizeof(StrOffset), 1);
638+ Closure* cl = allocate(sizeof(Closure), 1);
672 SETTY(cl, CT_STROFFSET);
639 SETTY(cl, CT_STROFFSET);
673− cl->info.str_offset = (StrOffset*)((char*)cl + sizeof(Closure));
674−
675− cl->info.str_offset->str = off->str;
640+ cl->info.str_offset = off->info.str_offset;
676− cl->info.str_offset->offset = off->offset;
641+ cl->sz = off->sz;
677
642
678 return cl;
643 return cl;
679}
644}
@@ -681,22 +646,22 @@ VAL MKSTROFFc(VM* vm, StrOffset* off) {
681VAL idris_strShift(VM* vm, VAL str, int num) {
646VAL idris_strShift(VM* vm, VAL str, int num) {
682 // If there's no room, just copy the string, or we'll have a problem after
647 // If there's no room, just copy the string, or we'll have a problem after
683 // gc moves str
648 // gc moves str
684− if (space(vm, sizeof(Closure) + sizeof(StrOffset))) {
649+ if (space(vm, sizeof(Closure))) {
685− Closure* cl = allocate(sizeof(Closure) + sizeof(StrOffset), 0);
650+ Closure* cl = allocate(sizeof(Closure), 0);
686 SETTY(cl, CT_STROFFSET);
651 SETTY(cl, CT_STROFFSET);
687− cl->info.str_offset = (StrOffset*)((char*)cl + sizeof(Closure));
652+ cl->info.str_offset = cl->info.str_offset;
688
653
689 int offset = 0;
654 int offset = 0;
690 VAL root = str;
655 VAL root = str;
691
656
692 while(root!=NULL && !ISSTR(root)) { // find the root, carry on.
657 while(root!=NULL && !ISSTR(root)) { // find the root, carry on.
693 // In theory, at most one step here!
658 // In theory, at most one step here!
694− offset += root->info.str_offset->offset;
659+ offset += root->sz;
695− root = root->info.str_offset->str;
660+ root = root->info.str_offset;
696 }
661 }
697
662
698− cl->info.str_offset->str = root;
663+ cl->info.str_offset = root;
699− cl->info.str_offset->offset = offset+idris_utf8_findOffset(GETSTR(str), num);
664+ cl->sz = offset+idris_utf8_findOffset(GETSTR(str), num);
700
665
701 return cl;
666 return cl;
702 } else {
667 } else {
@@ -715,23 +680,17 @@ VAL idris_strCons(VM* vm, VAL x, VAL xs) {
715 int xlen = GETSTRLEN(xs);
680 int xlen = GETSTRLEN(xs);
716
681
717 if (xval < 0x80) { // ASCII char
682 if (xval < 0x80) { // ASCII char
718− Closure* cl = allocate(sizeof(Closure) +
683+ Closure* cl = allocStr(xlen + 1, 0);
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));
684+ cl->info.str[0] = (char)(GETINT(x));
723− strcpy(cl->info.str.str+1, xstr);
685+ memcpy(cl->info.str+1, xstr, xlen);
724− cl->info.str.len = xlen + 1;
725 return cl;
686 return cl;
726 } else {
687 } else {
727 char *init = idris_utf8_fromChar(xval);
688 char *init = idris_utf8_fromChar(xval);
689+ size_t ilen = strlen(init);
728− int newlen = strlen(init) + xlen;
690+ int newlen = ilen + xlen;
729− Closure* cl = allocate(sizeof(Closure) + newlen + 1, 0);
691+ Closure* cl = allocStr(newlen, 0);
730− SETTY(cl, CT_STRING);
692+ memcpy(cl->info.str, init, ilen);
731− cl->info.str.str = (char*)cl + sizeof(Closure);
693+ memcpy(cl->info.str + ilen, xstr, xlen);
732− strcpy(cl->info.str.str, init);
733− strcat(cl->info.str.str, xstr);
734− cl->info.str.len = newlen;
735 free(init);
694 free(init);
736 return cl;
695 return cl;
737 }
696 }
@@ -754,12 +713,10 @@ VAL idris_substr(VM* vm, VAL offset, VAL length, VAL str) {
754 else {
713 else {
755 char *start = idris_utf8_advance(str_val, offset_val);
714 char *start = idris_utf8_advance(str_val, offset_val);
756 char *end = idris_utf8_advance(start, length_val);
715 char *end = idris_utf8_advance(start, length_val);
757− Closure* newstr = allocate(sizeof(Closure) + (end - start) +1, 0);
716+ size_t sz = end - start;
758− SETTY(newstr, CT_STRING);
717+ Closure* newstr = allocStr(sz, 0);
759− newstr->info.str.str = (char*)newstr + sizeof(Closure);
760− memcpy(newstr->info.str.str, start, end - start);
718+ memcpy(newstr->info.str, start, sz);
761− *(newstr->info.str.str + (end - start) + 1) = '\0';
719+ newstr->info.str[sz] = '\0';
762− newstr->info.str.len = strlen(newstr->info.str.str);
763 return newstr;
720 return newstr;
764 }
721 }
765}
722}
@@ -768,11 +725,8 @@ VAL idris_strRev(VM* vm, VAL str) {
768 char *xstr = GETSTR(str);
725 char *xstr = GETSTR(str);
769 int xlen = GETSTRLEN(str);
726 int xlen = GETSTRLEN(str);
770
727
771− Closure* cl = allocate(sizeof(Closure) + xlen + 1, 0);
728+ Closure* cl = allocStr(xlen, 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);
729+ idris_utf8_rev(xstr, cl->info.str);
776 return cl;
730 return cl;
777}
731}
778
732
@@ -801,17 +755,17 @@ VAL idris_newArray(VM* vm, int size, VAL def) {
801 int i;
755 int i;
802 allocArray(cl, vm, size, 0);
756 allocArray(cl, vm, size, 0);
803 for(i=0; i<size; ++i) {
757 for(i=0; i<size; ++i) {
804− cl->info.arr.content[i] = def;
758+ cl->info.array[i] = def;
805 }
759 }
806 return cl;
760 return cl;
807}
761}
808
762
809void idris_arraySet(VAL arr, int index, VAL newval) {
763void idris_arraySet(VAL arr, int index, VAL newval) {
810− arr->info.arr.content[index] = newval;
764+ arr->info.array[index] = newval;
811}
765}
812
766
813VAL idris_arrayGet(VAL arr, int index) {
767VAL idris_arrayGet(VAL arr, int index) {
814− return arr->info.arr.content[index];
768+ return arr->info.array[index];
815}
769}
816
770
817VAL idris_systemInfo(VM* vm, VAL index) {
771VAL idris_systemInfo(VM* vm, VAL index) {
@@ -909,20 +863,20 @@ VAL doCopyTo(VM* vm, VAL x) {
909 } else {
863 } else {
910 allocCon(cl, vm, CTAG(x), ar, 1);
864 allocCon(cl, vm, CTAG(x), ar, 1);
911
865
912− argptr = (VAL*)(cl->info.c.args);
866+ argptr = cl->info.cargs;
913 for(i = 0; i < ar; ++i) {
867 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
915 argptr++;
869 argptr++;
916 }
870 }
917 }
871 }
918 break;
872 break;
919 case CT_ARRAY:
873 case CT_ARRAY:
920− len = x->info.arr.length;
874+ len = x->sz;
921 allocArray(cl, vm, len, 1);
875 allocArray(cl, vm, len, 1);
922
876
923− argptr = (VAL*)(cl->info.arr.content);
877+ argptr = cl->info.array;
924 for(i = 0; i < len; ++i) {
878 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
926 argptr++;
880 argptr++;
927 }
881 }
928 break;
882 break;
@@ -930,7 +884,7 @@ VAL doCopyTo(VM* vm, VAL x) {
930 cl = MKFLOATc(vm, x->info.f);
884 cl = MKFLOATc(vm, x->info.f);
931 break;
885 break;
932 case CT_STRING:
886 case CT_STRING:
933− cl = MKSTRc(vm, x->info.str.str);
887+ cl = MKSTRc(vm, x->info.str);
934 break;
888 break;
935 case CT_BIGINT:
889 case CT_BIGINT:
936 cl = MKBIGMc(vm, x->info.ptr);
890 cl = MKBIGMc(vm, x->info.ptr);
@@ -939,7 +893,7 @@ VAL doCopyTo(VM* vm, VAL x) {
939 cl = MKPTRc(vm, x->info.ptr);
893 cl = MKPTRc(vm, x->info.ptr);
940 break;
894 break;
941 case CT_MANAGEDPTR:
895 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);
943 break;
897 break;
944 case CT_CDATA:
898 case CT_CDATA:
945 cl = MKCDATAc(vm, x->info.c_heap_item);
899 cl = MKCDATAc(vm, x->info.c_heap_item);
@@ -958,7 +912,7 @@ VAL doCopyTo(VM* vm, VAL x) {
958 break;
912 break;
959 case CT_RAWDATA:
913 case CT_RAWDATA:
960 {
914 {
961− size_t size = x->info.size + sizeof(Closure);
915+ size_t size = x->sz + sizeof(Closure);
962 cl = allocate(size, 0);
916 cl = allocate(size, 0);
963 memcpy(cl, x, size);
917 memcpy(cl, x, size);
964 }
918 }
@@ -1112,7 +1066,7 @@ Msg* idris_recvMessageFrom(VM* vm, int channel_id, VM* sender) {
1112
1066
1113 struct timespec timeout;
1067 struct timespec timeout;
1114 int status;
1068 int status;
1115−
1069+
1116 if (sender && sender->active == 0) { return NULL; } // No VM to receive from
1070 if (sender && sender->active == 0) { return NULL; } // No VM to receive from
1117
1071
1118 pthread_mutex_lock(&vm->inbox_block);
1072 pthread_mutex_lock(&vm->inbox_block);
@@ -1196,7 +1150,7 @@ void init_nullaries(void) {
1196 for(i = 0; i < 256; ++i) {
1150 for(i = 0; i < 256; ++i) {
1197 cl = malloc(sizeof(Closure));
1151 cl = malloc(sizeof(Closure));
1198 SETTY(cl, CT_CON);
1152 SETTY(cl, CT_CON);
1199− cl->info.c.tag_arity = i << 8;
1153+ cl->sz = i << 8;
1200 nullary_cons[i] = cl;
1154 nullary_cons[i] = cl;
1201 }
1155 }
1202}
1156}
rts/idris_rts.h+45−69
@@ -32,60 +32,30 @@ typedef enum {
32
32
33typedef struct Closure *VAL;
33typedef struct Closure *VAL;
34
34
35+typedef struct Closure {
36+ ClosureType ty:8;
37+ size_t sz:56;
38+ union {
35−// A constructor, consisting of a tag, an arity (16 bits each of the
39+// A constructor, consisting of a tag (encoded in the sz field),
36−// tag_arity field) and arguments
40+// an arity (encoded in 8 bits in the sz field), and arguments
37−typedef struct {
41+ VAL cargs[0];
38− uint32_t tag_arity;
39− VAL args[];
40−} con;
41−
42// An array; similar to a constructor but with a length, and contents
42// An array; similar to a constructor but with a length, and contents
43// initialised to NULL (high level Idris programs are responsible for
43// initialised to NULL (high level Idris programs are responsible for
44// initialising them properly)
44// initialising them properly)
45−typedef struct {
45+ VAL array[0];
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;
76 int i;
46 int i;
77 double f;
47 double f;
78− String str;
79− StrOffset* str_offset;
48+ VAL str_offset;
80− void* ptr;
49+ void * ptr;
50+ char * str;
81 uint8_t bits8;
51 uint8_t bits8;
82 uint16_t bits16;
52 uint16_t bits16;
83 uint32_t bits32;
53 uint32_t bits32;
84 uint64_t bits64;
54 uint64_t bits64;
85− ManagedPtr* mptr;
55+ char managed_ptr[0]; // A foreign pointer, managed by the idris GC
86 CHeapItem* c_heap_item;
56 CHeapItem* c_heap_item;
87− size_t size;
88 } info;
57 } info;
58+ char data[0];
89} Closure;
59} Closure;
90
60
91struct VM;
61struct VM;
@@ -195,10 +165,10 @@ typedef void(*func)(VM*, VAL*);
195#define REG1 (vm->reg1)
165#define REG1 (vm->reg1)
196
166
197// Retrieving values
167// Retrieving values
198−#define GETSTR(x) (ISSTR(x) ? (((VAL)(x))->info.str.str) : GETSTROFF(x))
168+#define GETSTR(x) (ISSTR(x) ? (((VAL)(x))->info.str) : GETSTROFF(x))
199−#define GETSTRLEN(x) (ISSTR(x) ? (((VAL)(x))->info.str.len) : GETSTROFFLEN(x))
169+#define GETSTRLEN(x) (ISSTR(x) ? (((VAL)(x))->sz) : GETSTROFFLEN(x))
200#define GETPTR(x) (((VAL)(x))->info.ptr)
170#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)
202#define GETFLOAT(x) (((VAL)(x))->info.f)
172#define GETFLOAT(x) (((VAL)(x))->info.f)
203#define GETCDATA(x) (((VAL)(x))->info.c_heap_item)
173#define GETCDATA(x) (((VAL)(x))->info.c_heap_item)
204
174
@@ -207,12 +177,12 @@ typedef void(*func)(VM*, VAL*);
207#define GETBITS32(x) (((VAL)(x))->info.bits32)
177#define GETBITS32(x) (((VAL)(x))->info.bits32)
208#define GETBITS64(x) (((VAL)(x))->info.bits64)
178#define GETBITS64(x) (((VAL)(x))->info.bits64)
209
179
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−
213// Already checked it's a CT_CON
180// Already checked it's a CT_CON
214−#define CTAG(x) (((x)->info.c.tag_arity) >> 8)
181+#define CTAG(x) (((x)->sz) >> 8)
215−#define CARITY(x) ((x)->info.c.tag_arity & 0x000000ff)
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)) )
216
186
217
187
218#define GETTY(x) ((x)->ty)
188#define GETTY(x) ((x)->ty)
@@ -241,15 +211,17 @@ typedef intptr_t i_int;
241#ifdef IDRIS_TRACE
211#ifdef IDRIS_TRACE
242#define TRACE idris_trace(vm, __FUNCTION__, __LINE__);
212#define TRACE idris_trace(vm, __FUNCTION__, __LINE__);
243#else
213#else
244−#define TRACE
214+#define TRACE
245#endif
215#endif
246
216
247#define INITFRAME TRACE\
217#define INITFRAME TRACE\
248 __attribute__((unused)) VAL* myoldbase
218 __attribute__((unused)) VAL* myoldbase
249
219
250#define REBASE vm->valstack_base = oldbase
220#define REBASE vm->valstack_base = oldbase
221+#define RESERVE(x) do { \
251−#define RESERVE(x) if (vm->valstack_top+(x) > vm->stack_max) { stackOverflow(); } \
222+ if (vm->valstack_top+(x) > vm->stack_max) { stackOverflow(); } \
252− else { memset(vm->valstack_top, 0, (x)*sizeof(VAL)); }
223+ else { memset(vm->valstack_top, 0, (x)*sizeof(VAL)); } \
224+ } while(0)
253#define ADDTOP(x) vm->valstack_top += (x)
225#define ADDTOP(x) vm->valstack_top += (x)
254#define TOPBASE(x) vm->valstack_top = vm->valstack_base + (x)
226#define TOPBASE(x) vm->valstack_top = vm->valstack_base + (x)
255#define BASETOP(x) vm->valstack_base = vm->valstack_top + (x)
227#define BASETOP(x) vm->valstack_base = vm->valstack_top + (x)
@@ -260,6 +232,7 @@ typedef intptr_t i_int;
260// Creating new values (each value placed at the top of the stack)
232// Creating new values (each value placed at the top of the stack)
261VAL MKFLOAT(VM* vm, double val);
233VAL MKFLOAT(VM* vm, double val);
262VAL MKSTR(VM* vm, const char* str);
234VAL MKSTR(VM* vm, const char* str);
235+VAL MKSTRlen(VM* vm, const char* str, size_t size);
263VAL MKPTR(VM* vm, void* ptr);
236VAL MKPTR(VM* vm, void* ptr);
264VAL MKMPTR(VM* vm, void* ptr, size_t size);
237VAL MKMPTR(VM* vm, void* ptr, size_t size);
265VAL MKB8(VM* vm, uint8_t b);
238VAL MKB8(VM* vm, uint8_t b);
@@ -270,7 +243,7 @@ VAL MKCDATA(VM* vm, CHeapItem * item);
270
243
271// following versions don't take a lock when allocating
244// following versions don't take a lock when allocating
272VAL MKFLOATc(VM* vm, double val);
245VAL MKFLOATc(VM* vm, double val);
273−VAL MKSTROFFc(VM* vm, StrOffset* off);
246+VAL MKSTROFFc(VM* vm, VAL off);
274VAL MKSTRc(VM* vm, char* str);
247VAL MKSTRc(VM* vm, char* str);
275VAL MKSTRclen(VM* vm, char* str, int len);
248VAL MKSTRclen(VM* vm, char* str, int len);
276VAL MKPTRc(VM* vm, void* ptr);
249VAL MKPTRc(VM* vm, void* ptr);
@@ -280,12 +253,11 @@ VAL MKCDATAc(VM* vm, CHeapItem * item);
280char* GETSTROFF(VAL stroff);
253char* GETSTROFF(VAL stroff);
281size_t GETSTROFFLEN(VAL stroff);
254size_t GETSTROFFLEN(VAL stroff);
282
255
283−// #define SETTAG(x, a) (x)->info.c.tag = (a)
284−#define SETARG(x, i, a) ((x)->info.c.args)[i] = ((VAL)(a))
256+#define SETARG(x, i, a) ((x)->info.cargs)[i] = ((VAL)(a))
285−#define GETARG(x, i) ((x)->info.c.args)[i]
257+#define GETARG(x, i) ((x)->info.cargs[i])
286
258
287#define PROJECT(vm,r,loc,num) \
259#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)
289#define SLIDE(vm, args) \
261#define SLIDE(vm, args) \
290 memcpy(&(LOC(0)), &(TOP(0)), sizeof(VAL)*args)
262 memcpy(&(LOC(0)), &(TOP(0)), sizeof(VAL)*args)
291
263
@@ -308,22 +280,26 @@ void* idris_alloc(size_t size);
308void* idris_realloc(void* old, size_t old_size, size_t size);
280void* idris_realloc(void* old, size_t old_size, size_t size);
309void idris_free(void* ptr, size_t size);
281void idris_free(void* ptr, size_t size);
310
282
311−#define allocCon(cl, vm, t, a, o) \
283+#define allocCon(cl, vm, t, a, o) do { \
312− cl = allocate(sizeof(Closure) + sizeof(VAL)*a, o); \
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; \
313− SETTY(cl, CT_CON); \
291+ SETTY(cl, CT_CON); \
314− cl->info.c.tag_arity = ((t) << 8) | (a);
292+ cl->sz = ((t) << 8) | (a); \
293+ } while (0)
315
294
316−#define updateCon(cl, old, t, a) \
317− cl = old; \
318− SETTY(cl, CT_CON); \
319− cl->info.c.tag_arity = ((t) << 8) | (a);
320
295
321#define NULL_CON(x) nullary_cons[x]
296#define NULL_CON(x) nullary_cons[x]
322
297
323−#define allocArray(cl, vm, len, o) \
298+#define allocArray(cl, vm, len, o) do { \
324 cl = allocate(sizeof(Closure) + sizeof(VAL)*len, o); \
299 cl = allocate(sizeof(Closure) + sizeof(VAL)*len, o); \
325 SETTY(cl, CT_ARRAY); \
300 SETTY(cl, CT_ARRAY); \
326− cl->info.arr.length = len;
301+ cl->sz = len; \
302+ } while (0)
327
303
328int idris_errno(void);
304int idris_errno(void);
329char* idris_showerror(int err);
305char* 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
396irts_c (FArith (ATInt ITNative)) x = "GETINT(" ++ x ++ ")"
396irts_c (FArith (ATInt ITNative)) x = "GETINT(" ++ x ++ ")"
397irts_c (FArith (ATInt ITChar)) x = irts_c (FArith (ATInt ITNative)) x
397irts_c (FArith (ATInt ITChar)) x = irts_c (FArith (ATInt ITNative)) x
398irts_c (FArith (ATInt (ITFixed ity))) x
398irts_c (FArith (ATInt (ITFixed ity))) x
399− = "(" ++ x ++ "->info.bits" ++ show (nativeTyWidth ity) ++ ")"
399+ = "GETBITS" ++ show (nativeTyWidth ity) ++ "(" ++ x ++ ")"
400irts_c FString x = "GETSTR(" ++ x ++ ")"
400irts_c FString x = "GETSTR(" ++ x ++ ")"
401irts_c FUnit x = x
401irts_c FUnit x = x
402irts_c FPtr x = "GETPTR(" ++ x ++ ")"
402irts_c FPtr x = "GETPTR(" ++ x ++ ")"
@@ -536,13 +536,13 @@ doOp v (LURem (ITFixed ty)) [x, y] = bitOp v "URem" ty [x, y]
536doOp v (LSRem (ATInt (ITFixed ty))) [x, y] = bitOp v "SRem" ty [x, y]
536doOp v (LSRem (ATInt (ITFixed ty))) [x, y] = bitOp v "SRem" ty [x, y]
537
537
538doOp v (LSExt (ITFixed from) ITBig) [x]
538doOp 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 ++ "))"
540doOp v (LSExt ITNative (ITFixed to)) [x]
540doOp v (LSExt ITNative (ITFixed to)) [x]
541 = v ++ "idris_b" ++ show (nativeTyWidth to) ++ "const(vm, GETINT(" ++ creg x ++ "))"
541 = v ++ "idris_b" ++ show (nativeTyWidth to) ++ "const(vm, GETINT(" ++ creg x ++ "))"
542doOp v (LSExt ITChar (ITFixed to)) [x]
542doOp v (LSExt ITChar (ITFixed to)) [x]
543 = doOp v (LSExt ITNative (ITFixed to)) [x]
543 = doOp v (LSExt ITNative (ITFixed to)) [x]
544doOp v (LSExt (ITFixed from) ITNative) [x]
544doOp 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 ++ ")))"
546doOp v (LSExt (ITFixed from) ITChar) [x]
546doOp v (LSExt (ITFixed from) ITChar) [x]
547 = doOp v (LSExt (ITFixed from) ITNative) [x]
547 = doOp v (LSExt (ITFixed from) ITNative) [x]
548doOp v (LSExt (ITFixed from) (ITFixed to)) [x]
548doOp v (LSExt (ITFixed from) (ITFixed to)) [x]
@@ -552,11 +552,11 @@ doOp v (LZExt ITNative (ITFixed to)) [x]
552doOp v (LZExt ITChar (ITFixed to)) [x]
552doOp v (LZExt ITChar (ITFixed to)) [x]
553 = doOp v (LZExt ITNative (ITFixed to)) [x]
553 = doOp v (LZExt ITNative (ITFixed to)) [x]
554doOp v (LZExt (ITFixed from) ITNative) [x]
554doOp 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 ++ "))"
556doOp v (LZExt (ITFixed from) ITChar) [x]
556doOp v (LZExt (ITFixed from) ITChar) [x]
557 = doOp v (LZExt (ITFixed from) ITNative) [x]
557 = doOp v (LZExt (ITFixed from) ITNative) [x]
558doOp v (LZExt (ITFixed from) ITBig) [x]
558doOp 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 ++ "))"
560doOp v (LZExt ITNative ITBig) [x]
560doOp v (LZExt ITNative ITBig) [x]
561 = v ++ "MKBIGUI(vm, (uintptr_t)GETINT(" ++ creg x ++ "))"
561 = v ++ "MKBIGUI(vm, (uintptr_t)GETINT(" ++ creg x ++ "))"
562doOp v (LZExt (ITFixed from) (ITFixed to)) [x]
562doOp v (LZExt (ITFixed from) (ITFixed to)) [x]
@@ -566,7 +566,7 @@ doOp v (LTrunc ITNative (ITFixed to)) [x]
566doOp v (LTrunc ITChar (ITFixed to)) [x]
566doOp v (LTrunc ITChar (ITFixed to)) [x]
567 = doOp v (LTrunc ITNative (ITFixed to)) [x]
567 = doOp v (LTrunc ITNative (ITFixed to)) [x]
568doOp v (LTrunc (ITFixed from) ITNative) [x]
568doOp 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 ++ "))"
570doOp v (LTrunc (ITFixed from) ITChar) [x]
570doOp v (LTrunc (ITFixed from) ITChar) [x]
571 = doOp v (LTrunc (ITFixed from) ITNative) [x]
571 = doOp v (LTrunc (ITFixed from) ITNative) [x]
572doOp v (LTrunc ITBig (ITFixed IT64)) [x]
572doOp v (LTrunc ITBig (ITFixed IT64)) [x]