on master help sign in
Use idris_alloc for GMP allocation
f7b72a6Edwin Brady
rts/idris_bitstring.c+86−86
@@ -2,7 +2,7 @@
2
2
3VAL idris_b8CopyForGC(VM *vm, VAL a) {
3VAL idris_b8CopyForGC(VM *vm, VAL a) {
4 uint8_t A = a->info.bits8;
4 uint8_t A = a->info.bits8;
5− VAL cl = allocate(vm, sizeof(Closure), 1);
5+ VAL cl = allocate(sizeof(Closure), 1);
6 SETTY(cl, BITS8);
6 SETTY(cl, BITS8);
7 cl->info.bits8 = A;
7 cl->info.bits8 = A;
8 return cl;
8 return cl;
@@ -10,7 +10,7 @@ VAL idris_b8CopyForGC(VM *vm, VAL a) {
10
10
11VAL idris_b16CopyForGC(VM *vm, VAL a) {
11VAL idris_b16CopyForGC(VM *vm, VAL a) {
12 uint16_t A = a->info.bits16;
12 uint16_t A = a->info.bits16;
13− VAL cl = allocate(vm, sizeof(Closure), 1);
13+ VAL cl = allocate(sizeof(Closure), 1);
14 SETTY(cl, BITS16);
14 SETTY(cl, BITS16);
15 cl->info.bits16 = A;
15 cl->info.bits16 = A;
16 return cl;
16 return cl;
@@ -18,7 +18,7 @@ VAL idris_b16CopyForGC(VM *vm, VAL a) {
18
18
19VAL idris_b32CopyForGC(VM *vm, VAL a) {
19VAL idris_b32CopyForGC(VM *vm, VAL a) {
20 uint32_t A = a->info.bits32;
20 uint32_t A = a->info.bits32;
21− VAL cl = allocate(vm, sizeof(Closure), 1);
21+ VAL cl = allocate(sizeof(Closure), 1);
22 SETTY(cl, BITS32);
22 SETTY(cl, BITS32);
23 cl->info.bits32 = A;
23 cl->info.bits32 = A;
24 return cl;
24 return cl;
@@ -26,7 +26,7 @@ VAL idris_b32CopyForGC(VM *vm, VAL a) {
26
26
27VAL idris_b64CopyForGC(VM *vm, VAL a) {
27VAL idris_b64CopyForGC(VM *vm, VAL a) {
28 uint64_t A = a->info.bits64;
28 uint64_t A = a->info.bits64;
29− VAL cl = allocate(vm, sizeof(Closure), 1);
29+ VAL cl = allocate(sizeof(Closure), 1);
30 SETTY(cl, BITS64);
30 SETTY(cl, BITS64);
31 cl->info.bits64 = A;
31 cl->info.bits64 = A;
32 return cl;
32 return cl;
@@ -34,7 +34,7 @@ VAL idris_b64CopyForGC(VM *vm, VAL a) {
34
34
35VAL idris_b8(VM *vm, VAL a) {
35VAL idris_b8(VM *vm, VAL a) {
36 uint8_t A = GETINT(a);
36 uint8_t A = GETINT(a);
37− VAL cl = allocate(vm, sizeof(Closure), 0);
37+ VAL cl = allocate(sizeof(Closure), 0);
38 SETTY(cl, BITS8);
38 SETTY(cl, BITS8);
39 cl->info.bits8 = (uint8_t) A;
39 cl->info.bits8 = (uint8_t) A;
40 return cl;
40 return cl;
@@ -42,7 +42,7 @@ VAL idris_b8(VM *vm, VAL a) {
42
42
43VAL idris_b16(VM *vm, VAL a) {
43VAL idris_b16(VM *vm, VAL a) {
44 uint16_t A = GETINT(a);
44 uint16_t A = GETINT(a);
45− VAL cl = allocate(vm, sizeof(Closure), 0);
45+ VAL cl = allocate(sizeof(Closure), 0);
46 SETTY(cl, BITS16);
46 SETTY(cl, BITS16);
47 cl->info.bits16 = (uint16_t) A;
47 cl->info.bits16 = (uint16_t) A;
48 return cl;
48 return cl;
@@ -50,7 +50,7 @@ VAL idris_b16(VM *vm, VAL a) {
50
50
51VAL idris_b32(VM *vm, VAL a) {
51VAL idris_b32(VM *vm, VAL a) {
52 uint32_t A = GETINT(a);
52 uint32_t A = GETINT(a);
53− VAL cl = allocate(vm, sizeof(Closure), 0);
53+ VAL cl = allocate(sizeof(Closure), 0);
54 SETTY(cl, BITS32);
54 SETTY(cl, BITS32);
55 cl->info.bits32 = (uint32_t) A;
55 cl->info.bits32 = (uint32_t) A;
56 return cl;
56 return cl;
@@ -58,7 +58,7 @@ VAL idris_b32(VM *vm, VAL a) {
58
58
59VAL idris_b64(VM *vm, VAL a) {
59VAL idris_b64(VM *vm, VAL a) {
60 uint64_t A = GETINT(a);
60 uint64_t A = GETINT(a);
61− VAL cl = allocate(vm, sizeof(Closure), 0);
61+ VAL cl = allocate(sizeof(Closure), 0);
62 SETTY(cl, BITS64);
62 SETTY(cl, BITS64);
63 cl->info.bits64 = (uint64_t) A;
63 cl->info.bits64 = (uint64_t) A;
64 return cl;
64 return cl;
@@ -69,28 +69,28 @@ VAL idris_castB32Int(VM *vm, VAL a) {
69}
69}
70
70
71VAL idris_b8const(VM *vm, uint8_t a) {
71VAL idris_b8const(VM *vm, uint8_t a) {
72− VAL cl = allocate(vm, sizeof(Closure), 0);
72+ VAL cl = allocate(sizeof(Closure), 0);
73 SETTY(cl, BITS8);
73 SETTY(cl, BITS8);
74 cl->info.bits8 = a;
74 cl->info.bits8 = a;
75 return cl;
75 return cl;
76}
76}
77
77
78VAL idris_b16const(VM *vm, uint16_t a) {
78VAL idris_b16const(VM *vm, uint16_t a) {
79− VAL cl = allocate(vm, sizeof(Closure), 0);
79+ VAL cl = allocate(sizeof(Closure), 0);
80 SETTY(cl, BITS16);
80 SETTY(cl, BITS16);
81 cl->info.bits16 = a;
81 cl->info.bits16 = a;
82 return cl;
82 return cl;
83}
83}
84
84
85VAL idris_b32const(VM *vm, uint32_t a) {
85VAL idris_b32const(VM *vm, uint32_t a) {
86− VAL cl = allocate(vm, sizeof(Closure), 0);
86+ VAL cl = allocate(sizeof(Closure), 0);
87 SETTY(cl, BITS32);
87 SETTY(cl, BITS32);
88 cl->info.bits32 = a;
88 cl->info.bits32 = a;
89 return cl;
89 return cl;
90}
90}
91
91
92VAL idris_b64const(VM *vm, uint64_t a) {
92VAL idris_b64const(VM *vm, uint64_t a) {
93− VAL cl = allocate(vm, sizeof(Closure), 0);
93+ VAL cl = allocate(sizeof(Closure), 0);
94 SETTY(cl, BITS64);
94 SETTY(cl, BITS64);
95 cl->info.bits64 = a;
95 cl->info.bits64 = a;
96 return cl;
96 return cl;
@@ -99,7 +99,7 @@ VAL idris_b64const(VM *vm, uint64_t a) {
99VAL idris_b8Plus(VM *vm, VAL a, VAL b) {
99VAL idris_b8Plus(VM *vm, VAL a, VAL b) {
100 uint8_t A = a->info.bits8;
100 uint8_t A = a->info.bits8;
101 uint8_t B = b->info.bits8;
101 uint8_t B = b->info.bits8;
102− VAL cl = allocate(vm, sizeof(Closure), 0);
102+ VAL cl = allocate(sizeof(Closure), 0);
103 SETTY(cl, BITS8);
103 SETTY(cl, BITS8);
104 cl->info.bits8 = A + B;
104 cl->info.bits8 = A + B;
105 return cl;
105 return cl;
@@ -108,7 +108,7 @@ VAL idris_b8Plus(VM *vm, VAL a, VAL b) {
108VAL idris_b8Minus(VM *vm, VAL a, VAL b) {
108VAL idris_b8Minus(VM *vm, VAL a, VAL b) {
109 uint8_t A = a->info.bits8;
109 uint8_t A = a->info.bits8;
110 uint8_t B = b->info.bits8;
110 uint8_t B = b->info.bits8;
111− VAL cl = allocate(vm, sizeof(Closure), 0);
111+ VAL cl = allocate(sizeof(Closure), 0);
112 SETTY(cl, BITS8);
112 SETTY(cl, BITS8);
113 cl->info.bits8 = A - B;
113 cl->info.bits8 = A - B;
114 return cl;
114 return cl;
@@ -117,7 +117,7 @@ VAL idris_b8Minus(VM *vm, VAL a, VAL b) {
117VAL idris_b8Times(VM *vm, VAL a, VAL b) {
117VAL idris_b8Times(VM *vm, VAL a, VAL b) {
118 uint8_t A = a->info.bits8;
118 uint8_t A = a->info.bits8;
119 uint8_t B = b->info.bits8;
119 uint8_t B = b->info.bits8;
120− VAL cl = allocate(vm, sizeof(Closure), 0);
120+ VAL cl = allocate(sizeof(Closure), 0);
121 SETTY(cl, BITS8);
121 SETTY(cl, BITS8);
122 cl->info.bits8 = A * B;
122 cl->info.bits8 = A * B;
123 return cl;
123 return cl;
@@ -126,7 +126,7 @@ VAL idris_b8Times(VM *vm, VAL a, VAL b) {
126VAL idris_b8UDiv(VM *vm, VAL a, VAL b) {
126VAL idris_b8UDiv(VM *vm, VAL a, VAL b) {
127 uint8_t A = a->info.bits8;
127 uint8_t A = a->info.bits8;
128 uint8_t B = b->info.bits8;
128 uint8_t B = b->info.bits8;
129− VAL cl = allocate(vm, sizeof(Closure), 0);
129+ VAL cl = allocate(sizeof(Closure), 0);
130 SETTY(cl, BITS8);
130 SETTY(cl, BITS8);
131 cl->info.bits8 = A / B;
131 cl->info.bits8 = A / B;
132 return cl;
132 return cl;
@@ -135,7 +135,7 @@ VAL idris_b8UDiv(VM *vm, VAL a, VAL b) {
135VAL idris_b8SDiv(VM *vm, VAL a, VAL b) {
135VAL idris_b8SDiv(VM *vm, VAL a, VAL b) {
136 uint8_t A = a->info.bits8;
136 uint8_t A = a->info.bits8;
137 uint8_t B = b->info.bits8;
137 uint8_t B = b->info.bits8;
138− VAL cl = allocate(vm, sizeof(Closure), 0);
138+ VAL cl = allocate(sizeof(Closure), 0);
139 SETTY(cl, BITS8);
139 SETTY(cl, BITS8);
140 cl->info.bits8 = (uint8_t) (((int8_t) A) / ((int8_t) B));
140 cl->info.bits8 = (uint8_t) (((int8_t) A) / ((int8_t) B));
141 return cl;
141 return cl;
@@ -144,7 +144,7 @@ VAL idris_b8SDiv(VM *vm, VAL a, VAL b) {
144VAL idris_b8URem(VM *vm, VAL a, VAL b) {
144VAL idris_b8URem(VM *vm, VAL a, VAL b) {
145 uint8_t A = a->info.bits8;
145 uint8_t A = a->info.bits8;
146 uint8_t B = b->info.bits8;
146 uint8_t B = b->info.bits8;
147− VAL cl = allocate(vm, sizeof(Closure), 0);
147+ VAL cl = allocate(sizeof(Closure), 0);
148 SETTY(cl, BITS8);
148 SETTY(cl, BITS8);
149 cl->info.bits8 = A % B;
149 cl->info.bits8 = A % B;
150 return cl;
150 return cl;
@@ -153,7 +153,7 @@ VAL idris_b8URem(VM *vm, VAL a, VAL b) {
153VAL idris_b8SRem(VM *vm, VAL a, VAL b) {
153VAL idris_b8SRem(VM *vm, VAL a, VAL b) {
154 uint8_t A = a->info.bits8;
154 uint8_t A = a->info.bits8;
155 uint8_t B = b->info.bits8;
155 uint8_t B = b->info.bits8;
156− VAL cl = allocate(vm, sizeof(Closure), 0);
156+ VAL cl = allocate(sizeof(Closure), 0);
157 SETTY(cl, BITS8);
157 SETTY(cl, BITS8);
158 cl->info.bits8 = (uint8_t) (((int8_t) A) % ((int8_t) B));
158 cl->info.bits8 = (uint8_t) (((int8_t) A) % ((int8_t) B));
159 return cl;
159 return cl;
@@ -181,7 +181,7 @@ VAL idris_b8Gte(VM *vm, VAL a, VAL b) {
181
181
182VAL idris_b8Compl(VM *vm, VAL a) {
182VAL idris_b8Compl(VM *vm, VAL a) {
183 uint8_t A = a->info.bits8;
183 uint8_t A = a->info.bits8;
184− VAL cl = allocate(vm, sizeof(Closure), 0);
184+ VAL cl = allocate(sizeof(Closure), 0);
185 SETTY(cl, BITS8);
185 SETTY(cl, BITS8);
186 cl->info.bits8 = ~ A;
186 cl->info.bits8 = ~ A;
187 return cl;
187 return cl;
@@ -190,7 +190,7 @@ VAL idris_b8Compl(VM *vm, VAL a) {
190VAL idris_b8And(VM *vm, VAL a, VAL b) {
190VAL idris_b8And(VM *vm, VAL a, VAL b) {
191 uint8_t A = a->info.bits8;
191 uint8_t A = a->info.bits8;
192 uint8_t B = b->info.bits8;
192 uint8_t B = b->info.bits8;
193− VAL cl = allocate(vm, sizeof(Closure), 0);
193+ VAL cl = allocate(sizeof(Closure), 0);
194 SETTY(cl, BITS8);
194 SETTY(cl, BITS8);
195 cl->info.bits8 = A & B;
195 cl->info.bits8 = A & B;
196 return cl;
196 return cl;
@@ -199,7 +199,7 @@ VAL idris_b8And(VM *vm, VAL a, VAL b) {
199VAL idris_b8Or(VM *vm, VAL a, VAL b) {
199VAL idris_b8Or(VM *vm, VAL a, VAL b) {
200 uint8_t A = a->info.bits8;
200 uint8_t A = a->info.bits8;
201 uint8_t B = b->info.bits8;
201 uint8_t B = b->info.bits8;
202− VAL cl = allocate(vm, sizeof(Closure), 0);
202+ VAL cl = allocate(sizeof(Closure), 0);
203 SETTY(cl, BITS8);
203 SETTY(cl, BITS8);
204 cl->info.bits8 = A | B;
204 cl->info.bits8 = A | B;
205 return cl;
205 return cl;
@@ -208,7 +208,7 @@ VAL idris_b8Or(VM *vm, VAL a, VAL b) {
208VAL idris_b8Xor(VM *vm, VAL a, VAL b) {
208VAL idris_b8Xor(VM *vm, VAL a, VAL b) {
209 uint8_t A = a->info.bits8;
209 uint8_t A = a->info.bits8;
210 uint8_t B = b->info.bits8;
210 uint8_t B = b->info.bits8;
211− VAL cl = allocate(vm, sizeof(Closure), 0);
211+ VAL cl = allocate(sizeof(Closure), 0);
212 SETTY(cl, BITS8);
212 SETTY(cl, BITS8);
213 cl->info.bits8 = A ^ B;
213 cl->info.bits8 = A ^ B;
214 return cl;
214 return cl;
@@ -217,7 +217,7 @@ VAL idris_b8Xor(VM *vm, VAL a, VAL b) {
217VAL idris_b8Shl(VM *vm, VAL a, VAL b) {
217VAL idris_b8Shl(VM *vm, VAL a, VAL b) {
218 uint8_t A = a->info.bits8;
218 uint8_t A = a->info.bits8;
219 uint8_t B = b->info.bits8;
219 uint8_t B = b->info.bits8;
220− VAL cl = allocate(vm, sizeof(Closure), 0);
220+ VAL cl = allocate(sizeof(Closure), 0);
221 SETTY(cl, BITS8);
221 SETTY(cl, BITS8);
222 cl->info.bits8 = A << B;
222 cl->info.bits8 = A << B;
223 return cl;
223 return cl;
@@ -226,7 +226,7 @@ VAL idris_b8Shl(VM *vm, VAL a, VAL b) {
226VAL idris_b8LShr(VM *vm, VAL a, VAL b) {
226VAL idris_b8LShr(VM *vm, VAL a, VAL b) {
227 uint8_t A = a->info.bits8;
227 uint8_t A = a->info.bits8;
228 uint8_t B = b->info.bits8;
228 uint8_t B = b->info.bits8;
229− VAL cl = allocate(vm, sizeof(Closure), 0);
229+ VAL cl = allocate(sizeof(Closure), 0);
230 SETTY(cl, BITS8);
230 SETTY(cl, BITS8);
231 cl->info.bits8 = A >> B;
231 cl->info.bits8 = A >> B;
232 return cl;
232 return cl;
@@ -235,7 +235,7 @@ VAL idris_b8LShr(VM *vm, VAL a, VAL b) {
235VAL idris_b8AShr(VM *vm, VAL a, VAL b) {
235VAL idris_b8AShr(VM *vm, VAL a, VAL b) {
236 uint8_t A = a->info.bits8;
236 uint8_t A = a->info.bits8;
237 uint8_t B = b->info.bits8;
237 uint8_t B = b->info.bits8;
238− VAL cl = allocate(vm, sizeof(Closure), 0);
238+ VAL cl = allocate(sizeof(Closure), 0);
239 SETTY(cl, BITS8);
239 SETTY(cl, BITS8);
240 cl->info.bits8 = (uint8_t) (((int8_t) A) >> ((int8_t) B));
240 cl->info.bits8 = (uint8_t) (((int8_t) A) >> ((int8_t) B));
241 return cl;
241 return cl;
@@ -244,7 +244,7 @@ VAL idris_b8AShr(VM *vm, VAL a, VAL b) {
244VAL idris_b16Plus(VM *vm, VAL a, VAL b) {
244VAL idris_b16Plus(VM *vm, VAL a, VAL b) {
245 uint16_t A = a->info.bits16;
245 uint16_t A = a->info.bits16;
246 uint16_t B = b->info.bits16;
246 uint16_t B = b->info.bits16;
247− VAL cl = allocate(vm, sizeof(Closure), 0);
247+ VAL cl = allocate(sizeof(Closure), 0);
248 SETTY(cl, BITS16);
248 SETTY(cl, BITS16);
249 cl->info.bits16 = A + B;
249 cl->info.bits16 = A + B;
250 return cl;
250 return cl;
@@ -253,7 +253,7 @@ VAL idris_b16Plus(VM *vm, VAL a, VAL b) {
253VAL idris_b16Minus(VM *vm, VAL a, VAL b) {
253VAL idris_b16Minus(VM *vm, VAL a, VAL b) {
254 uint16_t A = a->info.bits16;
254 uint16_t A = a->info.bits16;
255 uint16_t B = b->info.bits16;
255 uint16_t B = b->info.bits16;
256− VAL cl = allocate(vm, sizeof(Closure), 0);
256+ VAL cl = allocate(sizeof(Closure), 0);
257 SETTY(cl, BITS16);
257 SETTY(cl, BITS16);
258 cl->info.bits16 = A - B;
258 cl->info.bits16 = A - B;
259 return cl;
259 return cl;
@@ -262,7 +262,7 @@ VAL idris_b16Minus(VM *vm, VAL a, VAL b) {
262VAL idris_b16Times(VM *vm, VAL a, VAL b) {
262VAL idris_b16Times(VM *vm, VAL a, VAL b) {
263 uint16_t A = a->info.bits16;
263 uint16_t A = a->info.bits16;
264 uint16_t B = b->info.bits16;
264 uint16_t B = b->info.bits16;
265− VAL cl = allocate(vm, sizeof(Closure), 0);
265+ VAL cl = allocate(sizeof(Closure), 0);
266 SETTY(cl, BITS16);
266 SETTY(cl, BITS16);
267 cl->info.bits16 = A * B;
267 cl->info.bits16 = A * B;
268 return cl;
268 return cl;
@@ -271,7 +271,7 @@ VAL idris_b16Times(VM *vm, VAL a, VAL b) {
271VAL idris_b16UDiv(VM *vm, VAL a, VAL b) {
271VAL idris_b16UDiv(VM *vm, VAL a, VAL b) {
272 uint16_t A = a->info.bits16;
272 uint16_t A = a->info.bits16;
273 uint16_t B = b->info.bits16;
273 uint16_t B = b->info.bits16;
274− VAL cl = allocate(vm, sizeof(Closure), 0);
274+ VAL cl = allocate(sizeof(Closure), 0);
275 SETTY(cl, BITS16);
275 SETTY(cl, BITS16);
276 cl->info.bits16 = A / B;
276 cl->info.bits16 = A / B;
277 return cl;
277 return cl;
@@ -280,7 +280,7 @@ VAL idris_b16UDiv(VM *vm, VAL a, VAL b) {
280VAL idris_b16SDiv(VM *vm, VAL a, VAL b) {
280VAL idris_b16SDiv(VM *vm, VAL a, VAL b) {
281 uint16_t A = a->info.bits16;
281 uint16_t A = a->info.bits16;
282 uint16_t B = b->info.bits16;
282 uint16_t B = b->info.bits16;
283− VAL cl = allocate(vm, sizeof(Closure), 0);
283+ VAL cl = allocate(sizeof(Closure), 0);
284 SETTY(cl, BITS16);
284 SETTY(cl, BITS16);
285 cl->info.bits16 = (uint16_t) (((int16_t) A) / ((int16_t) B));
285 cl->info.bits16 = (uint16_t) (((int16_t) A) / ((int16_t) B));
286 return cl;
286 return cl;
@@ -289,7 +289,7 @@ VAL idris_b16SDiv(VM *vm, VAL a, VAL b) {
289VAL idris_b16URem(VM *vm, VAL a, VAL b) {
289VAL idris_b16URem(VM *vm, VAL a, VAL b) {
290 uint16_t A = a->info.bits16;
290 uint16_t A = a->info.bits16;
291 uint16_t B = b->info.bits16;
291 uint16_t B = b->info.bits16;
292− VAL cl = allocate(vm, sizeof(Closure), 0);
292+ VAL cl = allocate(sizeof(Closure), 0);
293 SETTY(cl, BITS16);
293 SETTY(cl, BITS16);
294 cl->info.bits16 = A % B;
294 cl->info.bits16 = A % B;
295 return cl;
295 return cl;
@@ -298,7 +298,7 @@ VAL idris_b16URem(VM *vm, VAL a, VAL b) {
298VAL idris_b16SRem(VM *vm, VAL a, VAL b) {
298VAL idris_b16SRem(VM *vm, VAL a, VAL b) {
299 uint16_t A = a->info.bits16;
299 uint16_t A = a->info.bits16;
300 uint16_t B = b->info.bits16;
300 uint16_t B = b->info.bits16;
301− VAL cl = allocate(vm, sizeof(Closure), 0);
301+ VAL cl = allocate(sizeof(Closure), 0);
302 SETTY(cl, BITS16);
302 SETTY(cl, BITS16);
303 cl->info.bits16 = (uint16_t) (((int16_t) A) % ((int16_t) B));
303 cl->info.bits16 = (uint16_t) (((int16_t) A) % ((int16_t) B));
304 return cl;
304 return cl;
@@ -326,7 +326,7 @@ VAL idris_b16Gte(VM *vm, VAL a, VAL b) {
326
326
327VAL idris_b16Compl(VM *vm, VAL a) {
327VAL idris_b16Compl(VM *vm, VAL a) {
328 uint16_t A = a->info.bits16;
328 uint16_t A = a->info.bits16;
329− VAL cl = allocate(vm, sizeof(Closure), 0);
329+ VAL cl = allocate(sizeof(Closure), 0);
330 SETTY(cl, BITS16);
330 SETTY(cl, BITS16);
331 cl->info.bits16 = ~ A;
331 cl->info.bits16 = ~ A;
332 return cl;
332 return cl;
@@ -335,7 +335,7 @@ VAL idris_b16Compl(VM *vm, VAL a) {
335VAL idris_b16And(VM *vm, VAL a, VAL b) {
335VAL idris_b16And(VM *vm, VAL a, VAL b) {
336 uint16_t A = a->info.bits16;
336 uint16_t A = a->info.bits16;
337 uint16_t B = b->info.bits16;
337 uint16_t B = b->info.bits16;
338− VAL cl = allocate(vm, sizeof(Closure), 0);
338+ VAL cl = allocate(sizeof(Closure), 0);
339 SETTY(cl, BITS16);
339 SETTY(cl, BITS16);
340 cl->info.bits16 = A & B;
340 cl->info.bits16 = A & B;
341 return cl;
341 return cl;
@@ -344,7 +344,7 @@ VAL idris_b16And(VM *vm, VAL a, VAL b) {
344VAL idris_b16Or(VM *vm, VAL a, VAL b) {
344VAL idris_b16Or(VM *vm, VAL a, VAL b) {
345 uint16_t A = a->info.bits16;
345 uint16_t A = a->info.bits16;
346 uint16_t B = b->info.bits16;
346 uint16_t B = b->info.bits16;
347− VAL cl = allocate(vm, sizeof(Closure), 0);
347+ VAL cl = allocate(sizeof(Closure), 0);
348 SETTY(cl, BITS16);
348 SETTY(cl, BITS16);
349 cl->info.bits16 = A | B;
349 cl->info.bits16 = A | B;
350 return cl;
350 return cl;
@@ -353,7 +353,7 @@ VAL idris_b16Or(VM *vm, VAL a, VAL b) {
353VAL idris_b16Xor(VM *vm, VAL a, VAL b) {
353VAL idris_b16Xor(VM *vm, VAL a, VAL b) {
354 uint16_t A = a->info.bits16;
354 uint16_t A = a->info.bits16;
355 uint16_t B = b->info.bits16;
355 uint16_t B = b->info.bits16;
356− VAL cl = allocate(vm, sizeof(Closure), 0);
356+ VAL cl = allocate(sizeof(Closure), 0);
357 SETTY(cl, BITS16);
357 SETTY(cl, BITS16);
358 cl->info.bits16 = A ^ B;
358 cl->info.bits16 = A ^ B;
359 return cl;
359 return cl;
@@ -362,7 +362,7 @@ VAL idris_b16Xor(VM *vm, VAL a, VAL b) {
362VAL idris_b16Shl(VM *vm, VAL a, VAL b) {
362VAL idris_b16Shl(VM *vm, VAL a, VAL b) {
363 uint16_t A = a->info.bits16;
363 uint16_t A = a->info.bits16;
364 uint16_t B = b->info.bits16;
364 uint16_t B = b->info.bits16;
365− VAL cl = allocate(vm, sizeof(Closure), 0);
365+ VAL cl = allocate(sizeof(Closure), 0);
366 SETTY(cl, BITS16);
366 SETTY(cl, BITS16);
367 cl->info.bits16 = A << B;
367 cl->info.bits16 = A << B;
368 return cl;
368 return cl;
@@ -371,7 +371,7 @@ VAL idris_b16Shl(VM *vm, VAL a, VAL b) {
371VAL idris_b16LShr(VM *vm, VAL a, VAL b) {
371VAL idris_b16LShr(VM *vm, VAL a, VAL b) {
372 uint16_t A = a->info.bits16;
372 uint16_t A = a->info.bits16;
373 uint16_t B = b->info.bits16;
373 uint16_t B = b->info.bits16;
374− VAL cl = allocate(vm, sizeof(Closure), 0);
374+ VAL cl = allocate(sizeof(Closure), 0);
375 SETTY(cl, BITS16);
375 SETTY(cl, BITS16);
376 cl->info.bits16 = A >> B;
376 cl->info.bits16 = A >> B;
377 return cl;
377 return cl;
@@ -380,7 +380,7 @@ VAL idris_b16LShr(VM *vm, VAL a, VAL b) {
380VAL idris_b16AShr(VM *vm, VAL a, VAL b) {
380VAL idris_b16AShr(VM *vm, VAL a, VAL b) {
381 uint16_t A = a->info.bits16;
381 uint16_t A = a->info.bits16;
382 uint16_t B = b->info.bits16;
382 uint16_t B = b->info.bits16;
383− VAL cl = allocate(vm, sizeof(Closure), 0);
383+ VAL cl = allocate(sizeof(Closure), 0);
384 SETTY(cl, BITS16);
384 SETTY(cl, BITS16);
385 cl->info.bits16 = (uint16_t) (((int16_t) A) >> ((int16_t) B));
385 cl->info.bits16 = (uint16_t) (((int16_t) A) >> ((int16_t) B));
386 return cl;
386 return cl;
@@ -389,7 +389,7 @@ VAL idris_b16AShr(VM *vm, VAL a, VAL b) {
389VAL idris_b32Plus(VM *vm, VAL a, VAL b) {
389VAL idris_b32Plus(VM *vm, VAL a, VAL b) {
390 uint32_t A = a->info.bits32;
390 uint32_t A = a->info.bits32;
391 uint32_t B = b->info.bits32;
391 uint32_t B = b->info.bits32;
392− VAL cl = allocate(vm, sizeof(Closure), 0);
392+ VAL cl = allocate(sizeof(Closure), 0);
393 SETTY(cl, BITS32);
393 SETTY(cl, BITS32);
394 cl->info.bits32 = A + B;
394 cl->info.bits32 = A + B;
395 return cl;
395 return cl;
@@ -398,7 +398,7 @@ VAL idris_b32Plus(VM *vm, VAL a, VAL b) {
398VAL idris_b32Minus(VM *vm, VAL a, VAL b) {
398VAL idris_b32Minus(VM *vm, VAL a, VAL b) {
399 uint32_t A = a->info.bits32;
399 uint32_t A = a->info.bits32;
400 uint32_t B = b->info.bits32;
400 uint32_t B = b->info.bits32;
401− VAL cl = allocate(vm, sizeof(Closure), 0);
401+ VAL cl = allocate(sizeof(Closure), 0);
402 SETTY(cl, BITS32);
402 SETTY(cl, BITS32);
403 cl->info.bits32 = A - B;
403 cl->info.bits32 = A - B;
404 return cl;
404 return cl;
@@ -407,7 +407,7 @@ VAL idris_b32Minus(VM *vm, VAL a, VAL b) {
407VAL idris_b32Times(VM *vm, VAL a, VAL b) {
407VAL idris_b32Times(VM *vm, VAL a, VAL b) {
408 uint32_t A = a->info.bits32;
408 uint32_t A = a->info.bits32;
409 uint32_t B = b->info.bits32;
409 uint32_t B = b->info.bits32;
410− VAL cl = allocate(vm, sizeof(Closure), 0);
410+ VAL cl = allocate(sizeof(Closure), 0);
411 SETTY(cl, BITS32);
411 SETTY(cl, BITS32);
412 cl->info.bits32 = A * B;
412 cl->info.bits32 = A * B;
413 return cl;
413 return cl;
@@ -416,7 +416,7 @@ VAL idris_b32Times(VM *vm, VAL a, VAL b) {
416VAL idris_b32UDiv(VM *vm, VAL a, VAL b) {
416VAL idris_b32UDiv(VM *vm, VAL a, VAL b) {
417 uint32_t A = a->info.bits32;
417 uint32_t A = a->info.bits32;
418 uint32_t B = b->info.bits32;
418 uint32_t B = b->info.bits32;
419− VAL cl = allocate(vm, sizeof(Closure), 0);
419+ VAL cl = allocate(sizeof(Closure), 0);
420 SETTY(cl, BITS32);
420 SETTY(cl, BITS32);
421 cl->info.bits32 = A / B;
421 cl->info.bits32 = A / B;
422 return cl;
422 return cl;
@@ -425,7 +425,7 @@ VAL idris_b32UDiv(VM *vm, VAL a, VAL b) {
425VAL idris_b32SDiv(VM *vm, VAL a, VAL b) {
425VAL idris_b32SDiv(VM *vm, VAL a, VAL b) {
426 uint32_t A = a->info.bits32;
426 uint32_t A = a->info.bits32;
427 uint32_t B = b->info.bits32;
427 uint32_t B = b->info.bits32;
428− VAL cl = allocate(vm, sizeof(Closure), 0);
428+ VAL cl = allocate(sizeof(Closure), 0);
429 SETTY(cl, BITS32);
429 SETTY(cl, BITS32);
430 cl->info.bits32 = (uint32_t) (((int32_t) A) / ((int32_t) B));
430 cl->info.bits32 = (uint32_t) (((int32_t) A) / ((int32_t) B));
431 return cl;
431 return cl;
@@ -434,7 +434,7 @@ VAL idris_b32SDiv(VM *vm, VAL a, VAL b) {
434VAL idris_b32URem(VM *vm, VAL a, VAL b) {
434VAL idris_b32URem(VM *vm, VAL a, VAL b) {
435 uint32_t A = a->info.bits32;
435 uint32_t A = a->info.bits32;
436 uint32_t B = b->info.bits32;
436 uint32_t B = b->info.bits32;
437− VAL cl = allocate(vm, sizeof(Closure), 0);
437+ VAL cl = allocate(sizeof(Closure), 0);
438 SETTY(cl, BITS32);
438 SETTY(cl, BITS32);
439 cl->info.bits32 = A % B;
439 cl->info.bits32 = A % B;
440 return cl;
440 return cl;
@@ -443,7 +443,7 @@ VAL idris_b32URem(VM *vm, VAL a, VAL b) {
443VAL idris_b32SRem(VM *vm, VAL a, VAL b) {
443VAL idris_b32SRem(VM *vm, VAL a, VAL b) {
444 uint32_t A = a->info.bits32;
444 uint32_t A = a->info.bits32;
445 uint32_t B = b->info.bits32;
445 uint32_t B = b->info.bits32;
446− VAL cl = allocate(vm, sizeof(Closure), 0);
446+ VAL cl = allocate(sizeof(Closure), 0);
447 SETTY(cl, BITS32);
447 SETTY(cl, BITS32);
448 cl->info.bits32 = (uint32_t) (((int32_t) A) % ((int32_t) B));
448 cl->info.bits32 = (uint32_t) (((int32_t) A) % ((int32_t) B));
449 return cl;
449 return cl;
@@ -471,7 +471,7 @@ VAL idris_b32Gte(VM *vm, VAL a, VAL b) {
471
471
472VAL idris_b32Compl(VM *vm, VAL a) {
472VAL idris_b32Compl(VM *vm, VAL a) {
473 uint32_t A = a->info.bits32;
473 uint32_t A = a->info.bits32;
474− VAL cl = allocate(vm, sizeof(Closure), 0);
474+ VAL cl = allocate(sizeof(Closure), 0);
475 SETTY(cl, BITS32);
475 SETTY(cl, BITS32);
476 cl->info.bits32 = ~ A;
476 cl->info.bits32 = ~ A;
477 return cl;
477 return cl;
@@ -480,7 +480,7 @@ VAL idris_b32Compl(VM *vm, VAL a) {
480VAL idris_b32And(VM *vm, VAL a, VAL b) {
480VAL idris_b32And(VM *vm, VAL a, VAL b) {
481 uint32_t A = a->info.bits32;
481 uint32_t A = a->info.bits32;
482 uint32_t B = b->info.bits32;
482 uint32_t B = b->info.bits32;
483− VAL cl = allocate(vm, sizeof(Closure), 0);
483+ VAL cl = allocate(sizeof(Closure), 0);
484 SETTY(cl, BITS32);
484 SETTY(cl, BITS32);
485 cl->info.bits32 = A & B;
485 cl->info.bits32 = A & B;
486 return cl;
486 return cl;
@@ -489,7 +489,7 @@ VAL idris_b32And(VM *vm, VAL a, VAL b) {
489VAL idris_b32Or(VM *vm, VAL a, VAL b) {
489VAL idris_b32Or(VM *vm, VAL a, VAL b) {
490 uint32_t A = a->info.bits32;
490 uint32_t A = a->info.bits32;
491 uint32_t B = b->info.bits32;
491 uint32_t B = b->info.bits32;
492− VAL cl = allocate(vm, sizeof(Closure), 0);
492+ VAL cl = allocate(sizeof(Closure), 0);
493 SETTY(cl, BITS32);
493 SETTY(cl, BITS32);
494 cl->info.bits32 = A | B;
494 cl->info.bits32 = A | B;
495 return cl;
495 return cl;
@@ -498,7 +498,7 @@ VAL idris_b32Or(VM *vm, VAL a, VAL b) {
498VAL idris_b32Xor(VM *vm, VAL a, VAL b) {
498VAL idris_b32Xor(VM *vm, VAL a, VAL b) {
499 uint32_t A = a->info.bits32;
499 uint32_t A = a->info.bits32;
500 uint32_t B = b->info.bits32;
500 uint32_t B = b->info.bits32;
501− VAL cl = allocate(vm, sizeof(Closure), 0);
501+ VAL cl = allocate(sizeof(Closure), 0);
502 SETTY(cl, BITS32);
502 SETTY(cl, BITS32);
503 cl->info.bits32 = A ^ B;
503 cl->info.bits32 = A ^ B;
504 return cl;
504 return cl;
@@ -507,7 +507,7 @@ VAL idris_b32Xor(VM *vm, VAL a, VAL b) {
507VAL idris_b32Shl(VM *vm, VAL a, VAL b) {
507VAL idris_b32Shl(VM *vm, VAL a, VAL b) {
508 uint32_t A = a->info.bits32;
508 uint32_t A = a->info.bits32;
509 uint32_t B = b->info.bits32;
509 uint32_t B = b->info.bits32;
510− VAL cl = allocate(vm, sizeof(Closure), 0);
510+ VAL cl = allocate(sizeof(Closure), 0);
511 SETTY(cl, BITS32);
511 SETTY(cl, BITS32);
512 cl->info.bits32 = A << B;
512 cl->info.bits32 = A << B;
513 return cl;
513 return cl;
@@ -516,7 +516,7 @@ VAL idris_b32Shl(VM *vm, VAL a, VAL b) {
516VAL idris_b32LShr(VM *vm, VAL a, VAL b) {
516VAL idris_b32LShr(VM *vm, VAL a, VAL b) {
517 uint32_t A = a->info.bits32;
517 uint32_t A = a->info.bits32;
518 uint32_t B = b->info.bits32;
518 uint32_t B = b->info.bits32;
519− VAL cl = allocate(vm, sizeof(Closure), 0);
519+ VAL cl = allocate(sizeof(Closure), 0);
520 SETTY(cl, BITS32);
520 SETTY(cl, BITS32);
521 cl->info.bits32 = A >> B;
521 cl->info.bits32 = A >> B;
522 return cl;
522 return cl;
@@ -525,7 +525,7 @@ VAL idris_b32LShr(VM *vm, VAL a, VAL b) {
525VAL idris_b32AShr(VM *vm, VAL a, VAL b) {
525VAL idris_b32AShr(VM *vm, VAL a, VAL b) {
526 uint32_t A = a->info.bits32;
526 uint32_t A = a->info.bits32;
527 uint32_t B = b->info.bits32;
527 uint32_t B = b->info.bits32;
528− VAL cl = allocate(vm, sizeof(Closure), 0);
528+ VAL cl = allocate(sizeof(Closure), 0);
529 SETTY(cl, BITS32);
529 SETTY(cl, BITS32);
530 cl->info.bits32 = (uint32_t) (((int32_t)A) >> ((int32_t)B));
530 cl->info.bits32 = (uint32_t) (((int32_t)A) >> ((int32_t)B));
531 return cl;
531 return cl;
@@ -534,7 +534,7 @@ VAL idris_b32AShr(VM *vm, VAL a, VAL b) {
534VAL idris_b64Plus(VM *vm, VAL a, VAL b) {
534VAL idris_b64Plus(VM *vm, VAL a, VAL b) {
535 uint64_t A = a->info.bits64;
535 uint64_t A = a->info.bits64;
536 uint64_t B = b->info.bits64;
536 uint64_t B = b->info.bits64;
537− VAL cl = allocate(vm, sizeof(Closure), 0);
537+ VAL cl = allocate(sizeof(Closure), 0);
538 SETTY(cl, BITS64);
538 SETTY(cl, BITS64);
539 cl->info.bits64 = A + B;
539 cl->info.bits64 = A + B;
540 return cl;
540 return cl;
@@ -543,7 +543,7 @@ VAL idris_b64Plus(VM *vm, VAL a, VAL b) {
543VAL idris_b64Minus(VM *vm, VAL a, VAL b) {
543VAL idris_b64Minus(VM *vm, VAL a, VAL b) {
544 uint64_t A = a->info.bits64;
544 uint64_t A = a->info.bits64;
545 uint64_t B = b->info.bits64;
545 uint64_t B = b->info.bits64;
546− VAL cl = allocate(vm, sizeof(Closure), 0);
546+ VAL cl = allocate(sizeof(Closure), 0);
547 SETTY(cl, BITS64);
547 SETTY(cl, BITS64);
548 cl->info.bits64 = A - B;
548 cl->info.bits64 = A - B;
549 return cl;
549 return cl;
@@ -552,7 +552,7 @@ VAL idris_b64Minus(VM *vm, VAL a, VAL b) {
552VAL idris_b64Times(VM *vm, VAL a, VAL b) {
552VAL idris_b64Times(VM *vm, VAL a, VAL b) {
553 uint64_t A = a->info.bits64;
553 uint64_t A = a->info.bits64;
554 uint64_t B = b->info.bits64;
554 uint64_t B = b->info.bits64;
555− VAL cl = allocate(vm, sizeof(Closure), 0);
555+ VAL cl = allocate(sizeof(Closure), 0);
556 SETTY(cl, BITS64);
556 SETTY(cl, BITS64);
557 cl->info.bits64 = A * B;
557 cl->info.bits64 = A * B;
558 return cl;
558 return cl;
@@ -561,7 +561,7 @@ VAL idris_b64Times(VM *vm, VAL a, VAL b) {
561VAL idris_b64UDiv(VM *vm, VAL a, VAL b) {
561VAL idris_b64UDiv(VM *vm, VAL a, VAL b) {
562 uint64_t A = a->info.bits64;
562 uint64_t A = a->info.bits64;
563 uint64_t B = b->info.bits64;
563 uint64_t B = b->info.bits64;
564− VAL cl = allocate(vm, sizeof(Closure), 0);
564+ VAL cl = allocate(sizeof(Closure), 0);
565 SETTY(cl, BITS64);
565 SETTY(cl, BITS64);
566 cl->info.bits64 = A / B;
566 cl->info.bits64 = A / B;
567 return cl;
567 return cl;
@@ -570,7 +570,7 @@ VAL idris_b64UDiv(VM *vm, VAL a, VAL b) {
570VAL idris_b64SDiv(VM *vm, VAL a, VAL b) {
570VAL idris_b64SDiv(VM *vm, VAL a, VAL b) {
571 uint64_t A = a->info.bits64;
571 uint64_t A = a->info.bits64;
572 uint64_t B = b->info.bits64;
572 uint64_t B = b->info.bits64;
573− VAL cl = allocate(vm, sizeof(Closure), 0);
573+ VAL cl = allocate(sizeof(Closure), 0);
574 SETTY(cl, BITS64);
574 SETTY(cl, BITS64);
575 cl->info.bits64 = (uint64_t) (((int64_t) A) / ((int64_t) B));
575 cl->info.bits64 = (uint64_t) (((int64_t) A) / ((int64_t) B));
576 return cl;
576 return cl;
@@ -579,7 +579,7 @@ VAL idris_b64SDiv(VM *vm, VAL a, VAL b) {
579VAL idris_b64URem(VM *vm, VAL a, VAL b) {
579VAL idris_b64URem(VM *vm, VAL a, VAL b) {
580 uint64_t A = a->info.bits64;
580 uint64_t A = a->info.bits64;
581 uint64_t B = b->info.bits64;
581 uint64_t B = b->info.bits64;
582− VAL cl = allocate(vm, sizeof(Closure), 0);
582+ VAL cl = allocate(sizeof(Closure), 0);
583 SETTY(cl, BITS64);
583 SETTY(cl, BITS64);
584 cl->info.bits64 = A % B;
584 cl->info.bits64 = A % B;
585 return cl;
585 return cl;
@@ -588,7 +588,7 @@ VAL idris_b64URem(VM *vm, VAL a, VAL b) {
588VAL idris_b64SRem(VM *vm, VAL a, VAL b) {
588VAL idris_b64SRem(VM *vm, VAL a, VAL b) {
589 uint64_t A = a->info.bits64;
589 uint64_t A = a->info.bits64;
590 uint64_t B = b->info.bits64;
590 uint64_t B = b->info.bits64;
591− VAL cl = allocate(vm, sizeof(Closure), 0);
591+ VAL cl = allocate(sizeof(Closure), 0);
592 SETTY(cl, BITS64);
592 SETTY(cl, BITS64);
593 cl->info.bits64 = (uint64_t) (((int64_t) A) % ((int64_t) B));
593 cl->info.bits64 = (uint64_t) (((int64_t) A) % ((int64_t) B));
594 return cl;
594 return cl;
@@ -616,7 +616,7 @@ VAL idris_b64Gte(VM *vm, VAL a, VAL b) {
616
616
617VAL idris_b64Compl(VM *vm, VAL a) {
617VAL idris_b64Compl(VM *vm, VAL a) {
618 uint64_t A = a->info.bits64;
618 uint64_t A = a->info.bits64;
619− VAL cl = allocate(vm, sizeof(Closure), 0);
619+ VAL cl = allocate(sizeof(Closure), 0);
620 SETTY(cl, BITS64);
620 SETTY(cl, BITS64);
621 cl->info.bits64 = ~ A;
621 cl->info.bits64 = ~ A;
622 return cl;
622 return cl;
@@ -625,7 +625,7 @@ VAL idris_b64Compl(VM *vm, VAL a) {
625VAL idris_b64And(VM *vm, VAL a, VAL b) {
625VAL idris_b64And(VM *vm, VAL a, VAL b) {
626 uint64_t A = a->info.bits64;
626 uint64_t A = a->info.bits64;
627 uint64_t B = b->info.bits64;
627 uint64_t B = b->info.bits64;
628− VAL cl = allocate(vm, sizeof(Closure), 0);
628+ VAL cl = allocate(sizeof(Closure), 0);
629 SETTY(cl, BITS64);
629 SETTY(cl, BITS64);
630 cl->info.bits64 = A & B;
630 cl->info.bits64 = A & B;
631 return cl;
631 return cl;
@@ -634,7 +634,7 @@ VAL idris_b64And(VM *vm, VAL a, VAL b) {
634VAL idris_b64Or(VM *vm, VAL a, VAL b) {
634VAL idris_b64Or(VM *vm, VAL a, VAL b) {
635 uint64_t A = a->info.bits64;
635 uint64_t A = a->info.bits64;
636 uint64_t B = b->info.bits64;
636 uint64_t B = b->info.bits64;
637− VAL cl = allocate(vm, sizeof(Closure), 0);
637+ VAL cl = allocate(sizeof(Closure), 0);
638 SETTY(cl, BITS64);
638 SETTY(cl, BITS64);
639 cl->info.bits64 = A | B;
639 cl->info.bits64 = A | B;
640 return cl;
640 return cl;
@@ -643,7 +643,7 @@ VAL idris_b64Or(VM *vm, VAL a, VAL b) {
643VAL idris_b64Xor(VM *vm, VAL a, VAL b) {
643VAL idris_b64Xor(VM *vm, VAL a, VAL b) {
644 uint64_t A = a->info.bits64;
644 uint64_t A = a->info.bits64;
645 uint64_t B = b->info.bits64;
645 uint64_t B = b->info.bits64;
646− VAL cl = allocate(vm, sizeof(Closure), 0);
646+ VAL cl = allocate(sizeof(Closure), 0);
647 SETTY(cl, BITS64);
647 SETTY(cl, BITS64);
648 cl->info.bits64 = A ^ B;
648 cl->info.bits64 = A ^ B;
649 return cl;
649 return cl;
@@ -652,7 +652,7 @@ VAL idris_b64Xor(VM *vm, VAL a, VAL b) {
652VAL idris_b64Shl(VM *vm, VAL a, VAL b) {
652VAL idris_b64Shl(VM *vm, VAL a, VAL b) {
653 uint64_t A = a->info.bits64;
653 uint64_t A = a->info.bits64;
654 uint64_t B = b->info.bits64;
654 uint64_t B = b->info.bits64;
655− VAL cl = allocate(vm, sizeof(Closure), 0);
655+ VAL cl = allocate(sizeof(Closure), 0);
656 SETTY(cl, BITS64);
656 SETTY(cl, BITS64);
657 cl->info.bits64 = A << B;
657 cl->info.bits64 = A << B;
658 return cl;
658 return cl;
@@ -661,7 +661,7 @@ VAL idris_b64Shl(VM *vm, VAL a, VAL b) {
661VAL idris_b64LShr(VM *vm, VAL a, VAL b) {
661VAL idris_b64LShr(VM *vm, VAL a, VAL b) {
662 uint64_t A = a->info.bits64;
662 uint64_t A = a->info.bits64;
663 uint64_t B = b->info.bits64;
663 uint64_t B = b->info.bits64;
664− VAL cl = allocate(vm, sizeof(Closure), 0);
664+ VAL cl = allocate(sizeof(Closure), 0);
665 SETTY(cl, BITS64);
665 SETTY(cl, BITS64);
666 cl->info.bits64 = A >> B;
666 cl->info.bits64 = A >> B;
667 return cl;
667 return cl;
@@ -670,7 +670,7 @@ VAL idris_b64LShr(VM *vm, VAL a, VAL b) {
670VAL idris_b64AShr(VM *vm, VAL a, VAL b) {
670VAL idris_b64AShr(VM *vm, VAL a, VAL b) {
671 uint64_t A = a->info.bits64;
671 uint64_t A = a->info.bits64;
672 uint64_t B = b->info.bits64;
672 uint64_t B = b->info.bits64;
673− VAL cl = allocate(vm, sizeof(Closure), 0);
673+ VAL cl = allocate(sizeof(Closure), 0);
674 SETTY(cl, BITS64);
674 SETTY(cl, BITS64);
675 cl->info.bits64 = (uint64_t) (((int64_t) A) >> ((int64_t) B));
675 cl->info.bits64 = (uint64_t) (((int64_t) A) >> ((int64_t) B));
676 return cl;
676 return cl;
@@ -678,7 +678,7 @@ VAL idris_b64AShr(VM *vm, VAL a, VAL b) {
678
678
679VAL idris_b8Z16(VM *vm, VAL a) {
679VAL idris_b8Z16(VM *vm, VAL a) {
680 uint8_t A = a->info.bits8;
680 uint8_t A = a->info.bits8;
681− VAL cl = allocate(vm, sizeof(Closure), 0);
681+ VAL cl = allocate(sizeof(Closure), 0);
682 SETTY(cl, BITS16);
682 SETTY(cl, BITS16);
683 cl->info.bits16 = (uint16_t) A;
683 cl->info.bits16 = (uint16_t) A;
684 return cl;
684 return cl;
@@ -686,7 +686,7 @@ VAL idris_b8Z16(VM *vm, VAL a) {
686
686
687VAL idris_b8Z32(VM *vm, VAL a) {
687VAL idris_b8Z32(VM *vm, VAL a) {
688 uint8_t A = a->info.bits8;
688 uint8_t A = a->info.bits8;
689− VAL cl = allocate(vm, sizeof(Closure), 0);
689+ VAL cl = allocate(sizeof(Closure), 0);
690 SETTY(cl, BITS32);
690 SETTY(cl, BITS32);
691 cl->info.bits32 = (uint32_t) A;
691 cl->info.bits32 = (uint32_t) A;
692 return cl;
692 return cl;
@@ -694,7 +694,7 @@ VAL idris_b8Z32(VM *vm, VAL a) {
694
694
695VAL idris_b8Z64(VM *vm, VAL a) {
695VAL idris_b8Z64(VM *vm, VAL a) {
696 uint8_t A = a->info.bits8;
696 uint8_t A = a->info.bits8;
697− VAL cl = allocate(vm, sizeof(Closure), 0);
697+ VAL cl = allocate(sizeof(Closure), 0);
698 SETTY(cl, BITS64);
698 SETTY(cl, BITS64);
699 cl->info.bits64 = (uint64_t) A;
699 cl->info.bits64 = (uint64_t) A;
700 return cl;
700 return cl;
@@ -702,7 +702,7 @@ VAL idris_b8Z64(VM *vm, VAL a) {
702
702
703VAL idris_b8S16(VM *vm, VAL a) {
703VAL idris_b8S16(VM *vm, VAL a) {
704 uint8_t A = a->info.bits8;
704 uint8_t A = a->info.bits8;
705− VAL cl = allocate(vm, sizeof(Closure), 0);
705+ VAL cl = allocate(sizeof(Closure), 0);
706 SETTY(cl, BITS16);
706 SETTY(cl, BITS16);
707 cl->info.bits16 = (uint16_t) (int16_t) (int8_t) A;
707 cl->info.bits16 = (uint16_t) (int16_t) (int8_t) A;
708 return cl;
708 return cl;
@@ -710,7 +710,7 @@ VAL idris_b8S16(VM *vm, VAL a) {
710
710
711VAL idris_b8S32(VM *vm, VAL a) {
711VAL idris_b8S32(VM *vm, VAL a) {
712 uint8_t A = a->info.bits8;
712 uint8_t A = a->info.bits8;
713− VAL cl = allocate(vm, sizeof(Closure), 0);
713+ VAL cl = allocate(sizeof(Closure), 0);
714 SETTY(cl, BITS32);
714 SETTY(cl, BITS32);
715 cl->info.bits32 = (uint32_t) (int32_t) (int8_t) A;
715 cl->info.bits32 = (uint32_t) (int32_t) (int8_t) A;
716 return cl;
716 return cl;
@@ -718,7 +718,7 @@ VAL idris_b8S32(VM *vm, VAL a) {
718
718
719VAL idris_b8S64(VM *vm, VAL a) {
719VAL idris_b8S64(VM *vm, VAL a) {
720 uint8_t A = a->info.bits8;
720 uint8_t A = a->info.bits8;
721− VAL cl = allocate(vm, sizeof(Closure), 0);
721+ VAL cl = allocate(sizeof(Closure), 0);
722 SETTY(cl, BITS64);
722 SETTY(cl, BITS64);
723 cl->info.bits64 = (uint64_t) (int64_t) (int8_t) A;
723 cl->info.bits64 = (uint64_t) (int64_t) (int8_t) A;
724 return cl;
724 return cl;
@@ -726,7 +726,7 @@ VAL idris_b8S64(VM *vm, VAL a) {
726
726
727VAL idris_b16Z32(VM *vm, VAL a) {
727VAL idris_b16Z32(VM *vm, VAL a) {
728 uint16_t A = a->info.bits16;
728 uint16_t A = a->info.bits16;
729− VAL cl = allocate(vm, sizeof(Closure), 0);
729+ VAL cl = allocate(sizeof(Closure), 0);
730 SETTY(cl, BITS32);
730 SETTY(cl, BITS32);
731 cl->info.bits32 = (uint32_t) A;
731 cl->info.bits32 = (uint32_t) A;
732 return cl;
732 return cl;
@@ -734,7 +734,7 @@ VAL idris_b16Z32(VM *vm, VAL a) {
734
734
735VAL idris_b16Z64(VM *vm, VAL a) {
735VAL idris_b16Z64(VM *vm, VAL a) {
736 uint16_t A = a->info.bits16;
736 uint16_t A = a->info.bits16;
737− VAL cl = allocate(vm, sizeof(Closure), 0);
737+ VAL cl = allocate(sizeof(Closure), 0);
738 SETTY(cl, BITS64);
738 SETTY(cl, BITS64);
739 cl->info.bits64 = (uint64_t) A;
739 cl->info.bits64 = (uint64_t) A;
740 return cl;
740 return cl;
@@ -742,7 +742,7 @@ VAL idris_b16Z64(VM *vm, VAL a) {
742
742
743VAL idris_b16S32(VM *vm, VAL a) {
743VAL idris_b16S32(VM *vm, VAL a) {
744 uint16_t A = a->info.bits16;
744 uint16_t A = a->info.bits16;
745− VAL cl = allocate(vm, sizeof(Closure), 0);
745+ VAL cl = allocate(sizeof(Closure), 0);
746 SETTY(cl, BITS32);
746 SETTY(cl, BITS32);
747 cl->info.bits32 = (uint32_t) (int32_t) (int16_t) A;
747 cl->info.bits32 = (uint32_t) (int32_t) (int16_t) A;
748 return cl;
748 return cl;
@@ -750,7 +750,7 @@ VAL idris_b16S32(VM *vm, VAL a) {
750
750
751VAL idris_b16S64(VM *vm, VAL a) {
751VAL idris_b16S64(VM *vm, VAL a) {
752 uint16_t A = a->info.bits16;
752 uint16_t A = a->info.bits16;
753− VAL cl = allocate(vm, sizeof(Closure), 0);
753+ VAL cl = allocate(sizeof(Closure), 0);
754 SETTY(cl, BITS64);
754 SETTY(cl, BITS64);
755 cl->info.bits64 = (uint64_t) (int64_t) (int16_t) A;
755 cl->info.bits64 = (uint64_t) (int64_t) (int16_t) A;
756 return cl;
756 return cl;
@@ -758,7 +758,7 @@ VAL idris_b16S64(VM *vm, VAL a) {
758
758
759VAL idris_b16T8(VM *vm, VAL a) {
759VAL idris_b16T8(VM *vm, VAL a) {
760 uint16_t A = a->info.bits16;
760 uint16_t A = a->info.bits16;
761− VAL cl = allocate(vm, sizeof(Closure), 0);
761+ VAL cl = allocate(sizeof(Closure), 0);
762 SETTY(cl, BITS8);
762 SETTY(cl, BITS8);
763 cl->info.bits8 = (uint8_t) A;
763 cl->info.bits8 = (uint8_t) A;
764 return cl;
764 return cl;
@@ -766,7 +766,7 @@ VAL idris_b16T8(VM *vm, VAL a) {
766
766
767VAL idris_b32Z64(VM *vm, VAL a) {
767VAL idris_b32Z64(VM *vm, VAL a) {
768 uint32_t A = a->info.bits32;
768 uint32_t A = a->info.bits32;
769− VAL cl = allocate(vm, sizeof(Closure), 0);
769+ VAL cl = allocate(sizeof(Closure), 0);
770 SETTY(cl, BITS64);
770 SETTY(cl, BITS64);
771 cl->info.bits64 = (uint64_t) A;
771 cl->info.bits64 = (uint64_t) A;
772 return cl;
772 return cl;
@@ -774,7 +774,7 @@ VAL idris_b32Z64(VM *vm, VAL a) {
774
774
775VAL idris_b32S64(VM *vm, VAL a) {
775VAL idris_b32S64(VM *vm, VAL a) {
776 uint32_t A = a->info.bits32;
776 uint32_t A = a->info.bits32;
777− VAL cl = allocate(vm, sizeof(Closure), 0);
777+ VAL cl = allocate(sizeof(Closure), 0);
778 SETTY(cl, BITS64);
778 SETTY(cl, BITS64);
779 cl->info.bits64 = (uint64_t) (int64_t) (int32_t) A;
779 cl->info.bits64 = (uint64_t) (int64_t) (int32_t) A;
780 return cl;
780 return cl;
@@ -782,7 +782,7 @@ VAL idris_b32S64(VM *vm, VAL a) {
782
782
783VAL idris_b32T8(VM *vm, VAL a) {
783VAL idris_b32T8(VM *vm, VAL a) {
784 uint32_t A = a->info.bits32;
784 uint32_t A = a->info.bits32;
785− VAL cl = allocate(vm, sizeof(Closure), 0);
785+ VAL cl = allocate(sizeof(Closure), 0);
786 SETTY(cl, BITS8);
786 SETTY(cl, BITS8);
787 cl->info.bits8 = (uint8_t) A;
787 cl->info.bits8 = (uint8_t) A;
788 return cl;
788 return cl;
@@ -790,7 +790,7 @@ VAL idris_b32T8(VM *vm, VAL a) {
790
790
791VAL idris_b32T16(VM *vm, VAL a) {
791VAL idris_b32T16(VM *vm, VAL a) {
792 uint32_t A = a->info.bits32;
792 uint32_t A = a->info.bits32;
793− VAL cl = allocate(vm, sizeof(Closure), 0);
793+ VAL cl = allocate(sizeof(Closure), 0);
794 SETTY(cl, BITS16);
794 SETTY(cl, BITS16);
795 cl->info.bits16 = (uint16_t) A;
795 cl->info.bits16 = (uint16_t) A;
796 return cl;
796 return cl;
@@ -798,7 +798,7 @@ VAL idris_b32T16(VM *vm, VAL a) {
798
798
799VAL idris_b64T8(VM *vm, VAL a) {
799VAL idris_b64T8(VM *vm, VAL a) {
800 uint64_t A = a->info.bits64;
800 uint64_t A = a->info.bits64;
801− VAL cl = allocate(vm, sizeof(Closure), 0);
801+ VAL cl = allocate(sizeof(Closure), 0);
802 SETTY(cl, BITS8);
802 SETTY(cl, BITS8);
803 cl->info.bits8 = (uint8_t) A;
803 cl->info.bits8 = (uint8_t) A;
804 return cl;
804 return cl;
@@ -806,7 +806,7 @@ VAL idris_b64T8(VM *vm, VAL a) {
806
806
807VAL idris_b64T16(VM *vm, VAL a) {
807VAL idris_b64T16(VM *vm, VAL a) {
808 uint64_t A = a->info.bits64;
808 uint64_t A = a->info.bits64;
809− VAL cl = allocate(vm, sizeof(Closure), 0);
809+ VAL cl = allocate(sizeof(Closure), 0);
810 SETTY(cl, BITS16);
810 SETTY(cl, BITS16);
811 cl->info.bits16 = (uint16_t) A;
811 cl->info.bits16 = (uint16_t) A;
812 return cl;
812 return cl;
@@ -814,7 +814,7 @@ VAL idris_b64T16(VM *vm, VAL a) {
814
814
815VAL idris_b64T32(VM *vm, VAL a) {
815VAL idris_b64T32(VM *vm, VAL a) {
816 uint64_t A = a->info.bits64;
816 uint64_t A = a->info.bits64;
817− VAL cl = allocate(vm, sizeof(Closure), 0);
817+ VAL cl = allocate(sizeof(Closure), 0);
818 SETTY(cl, BITS32);
818 SETTY(cl, BITS32);
819 cl->info.bits32 = (uint32_t) A;
819 cl->info.bits32 = (uint32_t) A;
820 return cl;
820 return cl;
rts/idris_gc.c+3−2
@@ -101,11 +101,12 @@ void idris_gc(VM* vm) {
101 STATS_ENTER_GC(vm->stats, vm->heap.size)
101 STATS_ENTER_GC(vm->stats, vm->heap.size)
102 // printf("Collecting\n");
102 // printf("Collecting\n");
103
103
104− char* newheap = malloc(vm->heap.size);
105− char* oldheap = vm->heap.heap;
106 if (vm->heap.old != NULL)
104 if (vm->heap.old != NULL)
107 free(vm->heap.old);
105 free(vm->heap.old);
108
106
107+ char* newheap = malloc(vm->heap.size);
108+ char* oldheap = vm->heap.heap;
109+
109 vm->heap.heap = newheap;
110 vm->heap.heap = newheap;
110#ifdef FORCE_ALIGNMENT
111#ifdef FORCE_ALIGNMENT
111 if (((i_int)(vm->heap.heap)&1) == 1) {
112 if (((i_int)(vm->heap.heap)&1) == 1) {
rts/idris_gmp.c+46−15
@@ -7,15 +7,26 @@
7#include <stdlib.h>
7#include <stdlib.h>
8#include <string.h>
8#include <string.h>
9
9
10+// TMP HACK! Require this much space in the heap before a GMP operation
11+// so it doesn't garbage collect in the middle.
12+// This is highly dodgy and needs to be done better because who knows if
13+// GMP will need to allocate more than 64k... better to work out how
14+// much space is needed (or find another way of preventing copying)
15+#define IDRIS_MAXGMP 65536
16+
17+void init_gmpalloc() {
18+ mp_set_memory_functions(idris_alloc, idris_realloc, idris_free);
19+}
20+
10VAL MKBIGI(int val) {
21VAL MKBIGI(int val) {
11 return MKINT((i_int)val);
22 return MKINT((i_int)val);
12}
23}
13
24
14VAL MKBIGC(VM* vm, char* val) {
25VAL MKBIGC(VM* vm, char* val) {
26+ idris_requireAlloc(IDRIS_MAXGMP);
15 mpz_t* bigint;
27 mpz_t* bigint;
16
28
17− VAL cl = allocate(vm, sizeof(Closure) +
29+ VAL cl = allocate(sizeof(Closure) + sizeof(mpz_t), 0);
18− sizeof(mpz_t), 0);
19 bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
30 bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
20
31
21 mpz_init(*bigint);
32 mpz_init(*bigint);
@@ -28,9 +39,10 @@ VAL MKBIGC(VM* vm, char* val) {
28}
39}
29
40
30VAL MKBIGM(VM* vm, void* big) {
41VAL MKBIGM(VM* vm, void* big) {
42+ idris_requireAlloc(IDRIS_MAXGMP);
43+
31 mpz_t* bigint;
44 mpz_t* bigint;
32− VAL cl = allocate(vm, sizeof(Closure) +
45+ VAL cl = allocate(sizeof(Closure) + sizeof(mpz_t), 0);
33− sizeof(mpz_t), 0);
34 bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
46 bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
35
47
36 mpz_init(*bigint);
48 mpz_init(*bigint);
@@ -43,9 +55,10 @@ VAL MKBIGM(VM* vm, void* big) {
43}
55}
44
56
45VAL MKBIGMc(VM* vm, void* big) {
57VAL MKBIGMc(VM* vm, void* big) {
58+ idris_requireAlloc(IDRIS_MAXGMP);
59+
46 mpz_t* bigint;
60 mpz_t* bigint;
47− VAL cl = allocate(vm, sizeof(Closure) +
61+ VAL cl = allocate(sizeof(Closure) + sizeof(mpz_t), 0);
48− sizeof(mpz_t), 0);
49 bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
62 bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
50
63
51 mpz_init_set(*bigint, *((mpz_t*)big));
64 mpz_init_set(*bigint, *((mpz_t*)big));
@@ -57,8 +70,10 @@ VAL MKBIGMc(VM* vm, void* big) {
57}
70}
58
71
59VAL MKBIGUI(VM* vm, unsigned long val) {
72VAL MKBIGUI(VM* vm, unsigned long val) {
73+ idris_requireAlloc(IDRIS_MAXGMP);
74+
60 mpz_t* bigint;
75 mpz_t* bigint;
61− VAL cl = allocate(vm, sizeof(Closure) + sizeof(mpz_t), 0);
76+ VAL cl = allocate(sizeof(Closure) + sizeof(mpz_t), 0);
62 bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
77 bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
63
78
64 mpz_init_set_ui(*bigint, val);
79 mpz_init_set_ui(*bigint, val);
@@ -70,8 +85,10 @@ VAL MKBIGUI(VM* vm, unsigned long val) {
70}
85}
71
86
72VAL MKBIGSI(VM* vm, signed long val) {
87VAL MKBIGSI(VM* vm, signed long val) {
88+ idris_requireAlloc(IDRIS_MAXGMP);
89+
73 mpz_t* bigint;
90 mpz_t* bigint;
74− VAL cl = allocate(vm, sizeof(Closure) + sizeof(mpz_t), 0);
91+ VAL cl = allocate(sizeof(Closure) + sizeof(mpz_t), 0);
75 bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
92 bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
76
93
77 mpz_init_set_si(*bigint, val);
94 mpz_init_set_si(*bigint, val);
@@ -83,9 +100,11 @@ VAL MKBIGSI(VM* vm, signed long val) {
83}
100}
84
101
85VAL GETBIG(VM * vm, VAL x) {
102VAL GETBIG(VM * vm, VAL x) {
103+ idris_requireAlloc(IDRIS_MAXGMP);
104+
86 if (ISINT(x)) {
105 if (ISINT(x)) {
87 mpz_t* bigint;
106 mpz_t* bigint;
88− VAL cl = allocate(vm, sizeof(Closure) + sizeof(mpz_t), 0);
107+ VAL cl = allocate(sizeof(Closure) + sizeof(mpz_t), 0);
89 bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
108 bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
90
109
91 mpz_init(*bigint);
110 mpz_init(*bigint);
@@ -106,8 +125,10 @@ VAL GETBIG(VM * vm, VAL x) {
106}
125}
107
126
108VAL bigAdd(VM* vm, VAL x, VAL y) {
127VAL bigAdd(VM* vm, VAL x, VAL y) {
128+ idris_requireAlloc(IDRIS_MAXGMP);
129+
109 mpz_t* bigint;
130 mpz_t* bigint;
110− VAL cl = allocate(vm, sizeof(Closure) + sizeof(mpz_t), 0);
131+ VAL cl = allocate(sizeof(Closure) + sizeof(mpz_t), 0);
111 bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
132 bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
112 mpz_add(*bigint, GETMPZ(GETBIG(vm,x)), GETMPZ(GETBIG(vm,y)));
133 mpz_add(*bigint, GETMPZ(GETBIG(vm,x)), GETMPZ(GETBIG(vm,y)));
113 SETTY(cl, BIGINT);
134 SETTY(cl, BIGINT);
@@ -116,8 +137,10 @@ VAL bigAdd(VM* vm, VAL x, VAL y) {
116}
137}
117
138
118VAL bigSub(VM* vm, VAL x, VAL y) {
139VAL bigSub(VM* vm, VAL x, VAL y) {
140+ idris_requireAlloc(IDRIS_MAXGMP);
141+
119 mpz_t* bigint;
142 mpz_t* bigint;
120− VAL cl = allocate(vm, sizeof(Closure) + sizeof(mpz_t), 0);
143+ VAL cl = allocate(sizeof(Closure) + sizeof(mpz_t), 0);
121 bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
144 bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
122 mpz_sub(*bigint, GETMPZ(GETBIG(vm,x)), GETMPZ(GETBIG(vm,y)));
145 mpz_sub(*bigint, GETMPZ(GETBIG(vm,x)), GETMPZ(GETBIG(vm,y)));
123 SETTY(cl, BIGINT);
146 SETTY(cl, BIGINT);
@@ -126,8 +149,10 @@ VAL bigSub(VM* vm, VAL x, VAL y) {
126}
149}
127
150
128VAL bigMul(VM* vm, VAL x, VAL y) {
151VAL bigMul(VM* vm, VAL x, VAL y) {
152+ idris_requireAlloc(IDRIS_MAXGMP);
153+
129 mpz_t* bigint;
154 mpz_t* bigint;
130− VAL cl = allocate(vm, sizeof(Closure) + sizeof(mpz_t), 0);
155+ VAL cl = allocate(sizeof(Closure) + sizeof(mpz_t), 0);
131 bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
156 bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
132 mpz_mul(*bigint, GETMPZ(GETBIG(vm,x)), GETMPZ(GETBIG(vm,y)));
157 mpz_mul(*bigint, GETMPZ(GETBIG(vm,x)), GETMPZ(GETBIG(vm,y)));
133 SETTY(cl, BIGINT);
158 SETTY(cl, BIGINT);
@@ -136,8 +161,10 @@ VAL bigMul(VM* vm, VAL x, VAL y) {
136}
161}
137
162
138VAL bigDiv(VM* vm, VAL x, VAL y) {
163VAL bigDiv(VM* vm, VAL x, VAL y) {
164+ idris_requireAlloc(IDRIS_MAXGMP);
165+
139 mpz_t* bigint;
166 mpz_t* bigint;
140− VAL cl = allocate(vm, sizeof(Closure) + sizeof(mpz_t), 0);
167+ VAL cl = allocate(sizeof(Closure) + sizeof(mpz_t), 0);
141 bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
168 bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
142 mpz_tdiv_q(*bigint, GETMPZ(GETBIG(vm,x)), GETMPZ(GETBIG(vm,y)));
169 mpz_tdiv_q(*bigint, GETMPZ(GETBIG(vm,x)), GETMPZ(GETBIG(vm,y)));
143 SETTY(cl, BIGINT);
170 SETTY(cl, BIGINT);
@@ -146,8 +173,10 @@ VAL bigDiv(VM* vm, VAL x, VAL y) {
146}
173}
147
174
148VAL bigMod(VM* vm, VAL x, VAL y) {
175VAL bigMod(VM* vm, VAL x, VAL y) {
176+ idris_requireAlloc(IDRIS_MAXGMP);
177+
149 mpz_t* bigint;
178 mpz_t* bigint;
150− VAL cl = allocate(vm, sizeof(Closure) + sizeof(mpz_t), 0);
179+ VAL cl = allocate(sizeof(Closure) + sizeof(mpz_t), 0);
151 bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
180 bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
152 mpz_mod(*bigint, GETMPZ(GETBIG(vm,x)), GETMPZ(GETBIG(vm,y)));
181 mpz_mod(*bigint, GETMPZ(GETBIG(vm,x)), GETMPZ(GETBIG(vm,y)));
153 SETTY(cl, BIGINT);
182 SETTY(cl, BIGINT);
@@ -229,6 +258,8 @@ VAL idris_bigMod(VM* vm, VAL x, VAL y) {
229}
258}
230
259
231int bigEqConst(VAL x, int c) {
260int bigEqConst(VAL x, int c) {
261+ idris_requireAlloc(IDRIS_MAXGMP);
262+
232 if (ISINT(x)) { return (GETINT(x) == c); }
263 if (ISINT(x)) { return (GETINT(x) == c); }
233 else {
264 else {
234 int rv = mpz_cmp_si(GETMPZ(x), c);
265 int rv = mpz_cmp_si(GETMPZ(x), c);
@@ -321,7 +352,7 @@ VAL idris_castFloatBig(VM* vm, VAL f) {
321 double val = GETFLOAT(f);
352 double val = GETFLOAT(f);
322
353
323 mpz_t* bigint;
354 mpz_t* bigint;
324− VAL cl = allocate(vm, sizeof(Closure) + sizeof(mpz_t), 0);
355+ VAL cl = allocate(sizeof(Closure) + sizeof(mpz_t), 0);
325 bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
356 bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
326
357
327 mpz_init_set_d(*bigint, val);
358 mpz_init_set_d(*bigint, val);
rts/idris_gmp.h+3
@@ -7,6 +7,9 @@
7#include "mini-gmp.h"
7#include "mini-gmp.h"
8#endif
8#endif
9
9
10+// Set memory allocation functions
11+void init_gmpalloc();
12+
10VAL MKBIGI(int val);
13VAL MKBIGI(int val);
11VAL MKBIGC(VM* vm, char* bigint);
14VAL MKBIGC(VM* vm, char* bigint);
12VAL MKBIGM(VM* vm, void* bigint);
15VAL MKBIGM(VM* vm, void* bigint);
rts/idris_main.c+7−2
@@ -1,6 +1,7 @@
1#include "idris_opts.h"
1#include "idris_opts.h"
2#include "idris_stats.h"
2#include "idris_stats.h"
3#include "idris_rts.h"
3#include "idris_rts.h"
4+#include "idris_gmp.h"
4// The default options should give satisfactory results under many circumstances.
5// The default options should give satisfactory results under many circumstances.
5RTSOpts opts = {
6RTSOpts opts = {
6 .init_heap_size = 4096000,
7 .init_heap_size = 4096000,
@@ -15,7 +16,11 @@ int main(int argc, char* argv[]) {
15 __idris_argv = argv;
16 __idris_argv = argv;
16
17
17 VM* vm = init_vm(opts.max_stack_size, opts.init_heap_size, 1);
18 VM* vm = init_vm(opts.max_stack_size, opts.init_heap_size, 1);
18− initNullaries();
19+ init_threadkeys();
20+ init_threaddata(vm);
21+ init_gmpalloc();
22+
23+ init_nullaries();
19
24
20 _idris__123_runMain0_125_(vm, NULL);
25 _idris__123_runMain0_125_(vm, NULL);
21
26
@@ -31,6 +36,6 @@ int main(int argc, char* argv[]) {
31 print_stats(&stats);
36 print_stats(&stats);
32 }
37 }
33
38
34− freeNullaries();
39+ free_nullaries();
35 return EXIT_SUCCESS;
40 return EXIT_SUCCESS;
36}
41}
rts/idris_rts.c+82−35
@@ -11,6 +11,15 @@
11#include "idris_gc.h"
11#include "idris_gc.h"
12#include "idris_bitstring.h"
12#include "idris_bitstring.h"
13
13
14+#ifdef HAS_PTHREAD
15+static pthread_key_t vm_key;
16+#else
17+static VM* global_vm;
18+#endif
19+
20+void free_key(VM *vm) {
21+ // nothing to free, we just used the VM pointer which is freed elsewhere
22+}
14
23
15VM* init_vm(int stack_size, size_t heap_size,
24VM* init_vm(int stack_size, size_t heap_size,
16 int max_threads // not implemented yet
25 int max_threads // not implemented yet
@@ -54,11 +63,24 @@ VM* init_vm(int stack_size, size_t heap_size,
54
63
55 vm->max_threads = max_threads;
64 vm->max_threads = max_threads;
56 vm->processes = 0;
65 vm->processes = 0;
66+
67+#else
68+ global_vm = vm;
57#endif
69#endif
58 STATS_LEAVE_INIT(vm->stats)
70 STATS_LEAVE_INIT(vm->stats)
59 return vm;
71 return vm;
60}
72}
61
73
74+void init_threadkeys() {
75+ pthread_key_create(&vm_key, (void*)free_key);
76+}
77+
78+void init_threaddata(VM *vm) {
79+#ifdef HAS_PTHREAD
80+ pthread_setspecific(vm_key, vm);
81+#endif
82+}
83+
62Stats terminate(VM* vm) {
84Stats terminate(VM* vm) {
63 Stats stats = vm->stats;
85 Stats stats = vm->stats;
64 STATS_ENTER_EXIT(stats)
86 STATS_ENTER_EXIT(stats)
@@ -78,7 +100,13 @@ Stats terminate(VM* vm) {
78 return stats;
100 return stats;
79}
101}
80
102
81−void idris_requireAlloc(VM* vm, size_t size) {
103+void idris_requireAlloc(size_t size) {
104+#ifdef HAS_PTHREAD
105+ VM* vm = pthread_getspecific(vm_key);
106+#else
107+ VM* vm = global_vm;
108+#endif
109+
82 if (!(vm->heap.next + size < vm->heap.end)) {
110 if (!(vm->heap.next + size < vm->heap.end)) {
83 idris_gc(vm);
111 idris_gc(vm);
84 }
112 }
@@ -90,8 +118,9 @@ void idris_requireAlloc(VM* vm, size_t size) {
90#endif
118#endif
91}
119}
92
120
93−void idris_doneAlloc(VM* vm) {
121+void idris_doneAlloc() {
94#ifdef HAS_PTHREAD
122#ifdef HAS_PTHREAD
123+ VM* vm = pthread_getspecific(vm_key);
95 int lock = vm->processes > 0;
124 int lock = vm->processes > 0;
96 if (lock) { // We only need to lock if we're in concurrent mode
125 if (lock) { // We only need to lock if we're in concurrent mode
97 pthread_mutex_unlock(&vm->alloc_lock);
126 pthread_mutex_unlock(&vm->alloc_lock);
@@ -103,14 +132,31 @@ int space(VM* vm, size_t size) {
103 return (vm->heap.next + size + sizeof(size_t) < vm->heap.end);
132 return (vm->heap.next + size + sizeof(size_t) < vm->heap.end);
104}
133}
105
134
106−void* allocate(VM* vm, size_t size, int outerlock) {
135+void* idris_alloc(size_t size) {
136+ return allocate(size, 0);
137+}
138+
139+void* idris_realloc(void* old, size_t old_size, size_t size) {
140+ void* ptr = idris_alloc(size);
141+ memcpy(ptr, old, old_size);
142+ return ptr;
143+}
144+
145+void idris_free(void* ptr, size_t size) {
146+}
147+
148+void* allocate(size_t size, int outerlock) {
107// return malloc(size);
149// return malloc(size);
150+
108#ifdef HAS_PTHREAD
151#ifdef HAS_PTHREAD
152+ VM* vm = pthread_getspecific(vm_key);
109 int lock = vm->processes > 0 && !outerlock;
153 int lock = vm->processes > 0 && !outerlock;
110
154
111 if (lock) { // not message passing
155 if (lock) { // not message passing
112 pthread_mutex_lock(&vm->alloc_lock);
156 pthread_mutex_lock(&vm->alloc_lock);
113 }
157 }
158+#else
159+ VM* vm = global_vm;
114#endif
160#endif
115
161
116 if ((size & 7)!=0) {
162 if ((size & 7)!=0) {
@@ -141,7 +187,7 @@ void* allocate(VM* vm, size_t size, int outerlock) {
141 pthread_mutex_unlock(&vm->alloc_lock);
187 pthread_mutex_unlock(&vm->alloc_lock);
142 }
188 }
143#endif
189#endif
144− return allocate(vm, size, 0);
190+ return allocate(size, 0);
145 }
191 }
146
192
147}
193}
@@ -160,7 +206,7 @@ void* allocCon(VM* vm, int arity, int outer) {
160*/
206*/
161
207
162VAL MKFLOAT(VM* vm, double val) {
208VAL MKFLOAT(VM* vm, double val) {
163− Closure* cl = allocate(vm, sizeof(Closure), 0);
209+ Closure* cl = allocate(sizeof(Closure), 0);
164 SETTY(cl, FLOAT);
210 SETTY(cl, FLOAT);
165 cl -> info.f = val;
211 cl -> info.f = val;
166 return cl;
212 return cl;
@@ -173,8 +219,8 @@ VAL MKSTR(VM* vm, const char* str) {
173 } else {
219 } else {
174 len = strlen(str)+1;
220 len = strlen(str)+1;
175 }
221 }
176− Closure* cl = allocate(vm, sizeof(Closure) + // Type) + sizeof(char*) +
222+ Closure* cl = allocate(sizeof(Closure) + // Type) + sizeof(char*) +
177− sizeof(char)*len, 0);
223+ sizeof(char)*len, 0);
178 SETTY(cl, STRING);
224 SETTY(cl, STRING);
179 cl -> info.str = (char*)cl + sizeof(Closure);
225 cl -> info.str = (char*)cl + sizeof(Closure);
180 if (str == NULL) {
226 if (str == NULL) {
@@ -192,15 +238,15 @@ char* GETSTROFF(VAL stroff) {
192}
238}
193
239
194VAL MKPTR(VM* vm, void* ptr) {
240VAL MKPTR(VM* vm, void* ptr) {
195− Closure* cl = allocate(vm, sizeof(Closure), 0);
241+ Closure* cl = allocate(sizeof(Closure), 0);
196 SETTY(cl, PTR);
242 SETTY(cl, PTR);
197 cl -> info.ptr = ptr;
243 cl -> info.ptr = ptr;
198 return cl;
244 return cl;
199}
245}
200
246
201VAL MKMPTR(VM* vm, void* ptr, size_t size) {
247VAL MKMPTR(VM* vm, void* ptr, size_t size) {
202− Closure* cl = allocate(vm, sizeof(Closure) +
248+ Closure* cl = allocate(sizeof(Closure) +
203− sizeof(ManagedPtr) + size, 0);
249+ sizeof(ManagedPtr) + size, 0);
204 SETTY(cl, MANAGEDPTR);
250 SETTY(cl, MANAGEDPTR);
205 cl->info.mptr = (ManagedPtr*)((char*)cl + sizeof(Closure));
251 cl->info.mptr = (ManagedPtr*)((char*)cl + sizeof(Closure));
206 cl->info.mptr->data = (char*)cl + sizeof(Closure) + sizeof(ManagedPtr);
252 cl->info.mptr->data = (char*)cl + sizeof(Closure) + sizeof(ManagedPtr);
@@ -210,15 +256,15 @@ VAL MKMPTR(VM* vm, void* ptr, size_t size) {
210}
256}
211
257
212VAL MKFLOATc(VM* vm, double val) {
258VAL MKFLOATc(VM* vm, double val) {
213− Closure* cl = allocate(vm, sizeof(Closure), 1);
259+ Closure* cl = allocate(sizeof(Closure), 1);
214 SETTY(cl, FLOAT);
260 SETTY(cl, FLOAT);
215 cl -> info.f = val;
261 cl -> info.f = val;
216 return cl;
262 return cl;
217}
263}
218
264
219VAL MKSTRc(VM* vm, char* str) {
265VAL MKSTRc(VM* vm, char* str) {
220− Closure* cl = allocate(vm, sizeof(Closure) + // Type) + sizeof(char*) +
266+ Closure* cl = allocate(sizeof(Closure) + // Type) + sizeof(char*) +
221− sizeof(char)*strlen(str)+1, 1);
267+ sizeof(char)*strlen(str)+1, 1);
222 SETTY(cl, STRING);
268 SETTY(cl, STRING);
223 cl -> info.str = (char*)cl + sizeof(Closure);
269 cl -> info.str = (char*)cl + sizeof(Closure);
224
270
@@ -227,15 +273,15 @@ VAL MKSTRc(VM* vm, char* str) {
227}
273}
228
274
229VAL MKPTRc(VM* vm, void* ptr) {
275VAL MKPTRc(VM* vm, void* ptr) {
230− Closure* cl = allocate(vm, sizeof(Closure), 1);
276+ Closure* cl = allocate(sizeof(Closure), 1);
231 SETTY(cl, PTR);
277 SETTY(cl, PTR);
232 cl -> info.ptr = ptr;
278 cl -> info.ptr = ptr;
233 return cl;
279 return cl;
234}
280}
235
281
236VAL MKMPTRc(VM* vm, void* ptr, size_t size) {
282VAL MKMPTRc(VM* vm, void* ptr, size_t size) {
237− Closure* cl = allocate(vm, sizeof(Closure) +
283+ Closure* cl = allocate(sizeof(Closure) +
238− sizeof(ManagedPtr) + size, 1);
284+ sizeof(ManagedPtr) + size, 1);
239 SETTY(cl, MANAGEDPTR);
285 SETTY(cl, MANAGEDPTR);
240 cl->info.mptr = (ManagedPtr*)((char*)cl + sizeof(Closure));
286 cl->info.mptr = (ManagedPtr*)((char*)cl + sizeof(Closure));
241 cl->info.mptr->data = (char*)cl + sizeof(Closure) + sizeof(ManagedPtr);
287 cl->info.mptr->data = (char*)cl + sizeof(Closure) + sizeof(ManagedPtr);
@@ -245,28 +291,28 @@ VAL MKMPTRc(VM* vm, void* ptr, size_t size) {
245}
291}
246
292
247VAL MKB8(VM* vm, uint8_t bits8) {
293VAL MKB8(VM* vm, uint8_t bits8) {
248− Closure* cl = allocate(vm, sizeof(Closure), 1);
294+ Closure* cl = allocate(sizeof(Closure), 1);
249 SETTY(cl, BITS8);
295 SETTY(cl, BITS8);
250 cl -> info.bits8 = bits8;
296 cl -> info.bits8 = bits8;
251 return cl;
297 return cl;
252}
298}
253
299
254VAL MKB16(VM* vm, uint16_t bits16) {
300VAL MKB16(VM* vm, uint16_t bits16) {
255− Closure* cl = allocate(vm, sizeof(Closure), 1);
301+ Closure* cl = allocate(sizeof(Closure), 1);
256 SETTY(cl, BITS16);
302 SETTY(cl, BITS16);
257 cl -> info.bits16 = bits16;
303 cl -> info.bits16 = bits16;
258 return cl;
304 return cl;
259}
305}
260
306
261VAL MKB32(VM* vm, uint32_t bits32) {
307VAL MKB32(VM* vm, uint32_t bits32) {
262− Closure* cl = allocate(vm, sizeof(Closure), 1);
308+ Closure* cl = allocate(sizeof(Closure), 1);
263 SETTY(cl, BITS32);
309 SETTY(cl, BITS32);
264 cl -> info.bits32 = bits32;
310 cl -> info.bits32 = bits32;
265 return cl;
311 return cl;
266}
312}
267
313
268VAL MKB64(VM* vm, uint64_t bits64) {
314VAL MKB64(VM* vm, uint64_t bits64) {
269− Closure* cl = allocate(vm, sizeof(Closure), 1);
315+ Closure* cl = allocate(sizeof(Closure), 1);
270 SETTY(cl, BITS64);
316 SETTY(cl, BITS64);
271 cl -> info.bits64 = bits64;
317 cl -> info.bits64 = bits64;
272 return cl;
318 return cl;
@@ -347,7 +393,7 @@ void idris_memmove(void* dest, void* src, i_int dest_offset, i_int src_offset, i
347
393
348VAL idris_castIntStr(VM* vm, VAL i) {
394VAL idris_castIntStr(VM* vm, VAL i) {
349 int x = (int) GETINT(i);
395 int x = (int) GETINT(i);
350− Closure* cl = allocate(vm, sizeof(Closure) + sizeof(char)*16, 0);
396+ Closure* cl = allocate(sizeof(Closure) + sizeof(char)*16, 0);
351 SETTY(cl, STRING);
397 SETTY(cl, STRING);
352 cl -> info.str = (char*)cl + sizeof(Closure);
398 cl -> info.str = (char*)cl + sizeof(Closure);
353 sprintf(cl -> info.str, "%d", x);
399 sprintf(cl -> info.str, "%d", x);
@@ -364,7 +410,7 @@ VAL idris_castStrInt(VM* vm, VAL i) {
364}
410}
365
411
366VAL idris_castFloatStr(VM* vm, VAL i) {
412VAL idris_castFloatStr(VM* vm, VAL i) {
367− Closure* cl = allocate(vm, sizeof(Closure) + sizeof(char)*32, 0);
413+ Closure* cl = allocate(sizeof(Closure) + sizeof(char)*32, 0);
368 SETTY(cl, STRING);
414 SETTY(cl, STRING);
369 cl -> info.str = (char*)cl + sizeof(Closure);
415 cl -> info.str = (char*)cl + sizeof(Closure);
370 sprintf(cl -> info.str, "%g", GETFLOAT(i));
416 sprintf(cl -> info.str, "%g", GETFLOAT(i));
@@ -380,8 +426,7 @@ VAL idris_concat(VM* vm, VAL l, VAL r) {
380 char *ls = GETSTR(l);
426 char *ls = GETSTR(l);
381 // dumpVal(l);
427 // dumpVal(l);
382 // printf("\n");
428 // printf("\n");
383− Closure* cl = allocate(vm, sizeof(Closure) + strlen(ls) + strlen(rs) + 1,
429+ Closure* cl = allocate(sizeof(Closure) + strlen(ls) + strlen(rs) + 1, 0);
384− 0);
385 SETTY(cl, STRING);
430 SETTY(cl, STRING);
386 cl -> info.str = (char*)cl + sizeof(Closure);
431 cl -> info.str = (char*)cl + sizeof(Closure);
387 strcpy(cl -> info.str, ls);
432 strcpy(cl -> info.str, ls);
@@ -451,7 +496,7 @@ VAL idris_strHead(VM* vm, VAL str) {
451}
496}
452
497
453VAL MKSTROFFc(VM* vm, StrOffset* off) {
498VAL MKSTROFFc(VM* vm, StrOffset* off) {
454− Closure* cl = allocate(vm, sizeof(Closure) + sizeof(StrOffset), 1);
499+ Closure* cl = allocate(sizeof(Closure) + sizeof(StrOffset), 1);
455 SETTY(cl, STROFFSET);
500 SETTY(cl, STROFFSET);
456 cl->info.str_offset = (StrOffset*)((char*)cl + sizeof(Closure));
501 cl->info.str_offset = (StrOffset*)((char*)cl + sizeof(Closure));
457
502
@@ -465,7 +510,7 @@ VAL idris_strTail(VM* vm, VAL str) {
465 // If there's no room, just copy the string, or we'll have a problem after
510 // If there's no room, just copy the string, or we'll have a problem after
466 // gc moves str
511 // gc moves str
467 if (space(vm, sizeof(Closure) + sizeof(StrOffset))) {
512 if (space(vm, sizeof(Closure) + sizeof(StrOffset))) {
468− Closure* cl = allocate(vm, sizeof(Closure) + sizeof(StrOffset), 0);
513+ Closure* cl = allocate(sizeof(Closure) + sizeof(StrOffset), 0);
469 SETTY(cl, STROFFSET);
514 SETTY(cl, STROFFSET);
470 cl->info.str_offset = (StrOffset*)((char*)cl + sizeof(Closure));
515 cl->info.str_offset = (StrOffset*)((char*)cl + sizeof(Closure));
471
516
@@ -489,8 +534,8 @@ VAL idris_strTail(VM* vm, VAL str) {
489
534
490VAL idris_strCons(VM* vm, VAL x, VAL xs) {
535VAL idris_strCons(VM* vm, VAL x, VAL xs) {
491 char *xstr = GETSTR(xs);
536 char *xstr = GETSTR(xs);
492− Closure* cl = allocate(vm, sizeof(Closure) +
537+ Closure* cl = allocate(sizeof(Closure) +
493− strlen(xstr) + 2, 0);
538+ strlen(xstr) + 2, 0);
494 SETTY(cl, STRING);
539 SETTY(cl, STRING);
495 cl -> info.str = (char*)cl + sizeof(Closure);
540 cl -> info.str = (char*)cl + sizeof(Closure);
496 cl -> info.str[0] = (char)(GETINT(x));
541 cl -> info.str[0] = (char)(GETINT(x));
@@ -504,8 +549,8 @@ VAL idris_strIndex(VM* vm, VAL str, VAL i) {
504
549
505VAL idris_strRev(VM* vm, VAL str) {
550VAL idris_strRev(VM* vm, VAL str) {
506 char *xstr = GETSTR(str);
551 char *xstr = GETSTR(str);
507− Closure* cl = allocate(vm, sizeof(Closure) +
552+ Closure* cl = allocate(sizeof(Closure) +
508− strlen(xstr) + 1, 0);
553+ strlen(xstr) + 1, 0);
509 SETTY(cl, STRING);
554 SETTY(cl, STRING);
510 cl -> info.str = (char*)cl + sizeof(Closure);
555 cl -> info.str = (char*)cl + sizeof(Closure);
511 int y = 0;
556 int y = 0;
@@ -532,7 +577,7 @@ VAL idris_systemInfo(VM* vm, VAL index) {
532}
577}
533
578
534VAL MKBUFFERc(VM* vm, Buffer* buf) {
579VAL MKBUFFERc(VM* vm, Buffer* buf) {
535− Closure* cl = allocate(vm, sizeof(Closure) + sizeof *buf + buf->cap, 1);
580+ Closure* cl = allocate(sizeof(Closure) + sizeof *buf + buf->cap, 1);
536 SETTY(cl, BUFFER);
581 SETTY(cl, BUFFER);
537 cl->info.buf = (Buffer*)((void*)cl + sizeof(Closure));
582 cl->info.buf = (Buffer*)((void*)cl + sizeof(Closure));
538 memmove(cl->info.buf, buf, sizeof *buf + buf->fill);
583 memmove(cl->info.buf, buf, sizeof *buf + buf->fill);
@@ -549,7 +594,7 @@ static VAL internal_allocate(VM *vm, size_t hint) {
549 size |= size >> (1 << i);
594 size |= size >> (1 << i);
550 ++size;
595 ++size;
551
596
552− Closure* cl = allocate(vm, size, 0);
597+ Closure* cl = allocate(size, 0);
553 SETTY(cl, BUFFER);
598 SETTY(cl, BUFFER);
554 cl->info.buf = (Buffer*)((void*)cl + sizeof(Closure));
599 cl->info.buf = (Buffer*)((void*)cl + sizeof(Closure));
555 cl->info.buf->cap = size - (sizeof(Closure) + sizeof(Buffer));
600 cl->info.buf->cap = size - (sizeof(Closure) + sizeof(Buffer));
@@ -557,7 +602,7 @@ static VAL internal_allocate(VM *vm, size_t hint) {
557}
602}
558
603
559// Following functions cast uint64_t to size_t, which may narrow!
604// Following functions cast uint64_t to size_t, which may narrow!
560−VAL idris_allocate(VM* vm, VAL hint) {
605+VAL idris_buffer_allocate(VM* vm, VAL hint) {
561 Closure* cl = internal_allocate(vm, hint->info.bits64);
606 Closure* cl = internal_allocate(vm, hint->info.bits64);
562 cl->info.buf->fill = 0;
607 cl->info.buf->fill = 0;
563 return cl;
608 return cl;
@@ -778,6 +823,8 @@ void* runThread(void* arg) {
778 VM* vm = td->vm;
823 VM* vm = td->vm;
779 VM* callvm = td->callvm;
824 VM* callvm = td->callvm;
780
825
826+ init_threaddata(vm);
827+
781 TOP(0) = td->arg;
828 TOP(0) = td->arg;
782 BASETOP(0);
829 BASETOP(0);
783 ADDTOP(1);
830 ADDTOP(1);
@@ -970,7 +1017,7 @@ VAL idris_recvMessage(VM* vm) {
970
1017
971VAL* nullary_cons;
1018VAL* nullary_cons;
972
1019
973−void initNullaries() {
1020+void init_nullaries() {
974 int i;
1021 int i;
975 VAL cl;
1022 VAL cl;
976 nullary_cons = malloc(256 * sizeof(VAL));
1023 nullary_cons = malloc(256 * sizeof(VAL));
@@ -982,7 +1029,7 @@ void initNullaries() {
982 }
1029 }
983}
1030}
984
1031
985−void freeNullaries() {
1032+void free_nullaries() {
986 int i;
1033 int i;
987 for(i = 0; i < 256; ++i) {
1034 for(i = 0; i < 256; ++i) {
988 free(nullary_cons[i]);
1035 free(nullary_cons[i]);
rts/idris_rts.h+19−19
@@ -108,9 +108,14 @@ typedef struct {
108// Create a new VM
108// Create a new VM
109VM* init_vm(int stack_size, size_t heap_size,
109VM* init_vm(int stack_size, size_t heap_size,
110 int max_threads);
110 int max_threads);
111+// Initialise thread-local data for this VM
112+void init_threaddata(VM *vm);
111// Clean up a VM once it's no longer needed
113// Clean up a VM once it's no longer needed
112Stats terminate(VM* vm);
114Stats terminate(VM* vm);
113
115
116+// Set up key for thread-local data - called once from idris_main
117+void init_threadkeys();
118+
114// Functions all take a pointer to their VM, and previous stack base,
119// Functions all take a pointer to their VM, and previous stack base,
115// and return nothing.
120// and return nothing.
116typedef void(*func)(VM*, VAL*);
121typedef void(*func)(VM*, VAL*);
@@ -201,7 +206,7 @@ char* GETSTROFF(VAL stroff);
201void PROJECT(VM* vm, VAL r, int loc, int arity);
206void PROJECT(VM* vm, VAL r, int loc, int arity);
202void SLIDE(VM* vm, int args);
207void SLIDE(VM* vm, int args);
203
208
204−void* allocate(VM* vm, size_t size, int outerlock);
209+void* allocate(size_t size, int outerlock);
205// void* allocCon(VM* vm, int arity, int outerlock);
210// void* allocCon(VM* vm, int arity, int outerlock);
206
211
207// When allocating from C, call 'idris_requireAlloc' with a size to
212// When allocating from C, call 'idris_requireAlloc' with a size to
@@ -210,11 +215,18 @@ void* allocate(VM* vm, size_t size, int outerlock);
210// idris_doneAlloc *must* be called when allocation from C is done (as it
215// idris_doneAlloc *must* be called when allocation from C is done (as it
211// may take a lock if other threads are running).
216// may take a lock if other threads are running).
212
217
213−void idris_requireAlloc(VM* vm, size_t size);
218+void idris_requireAlloc(size_t size);
214−void idris_doneAlloc(VM* vm);
219+void idris_doneAlloc();
220+
221+// public interface to allocation (note that this may move other pointers
222+// if allocating beyond the limits given by idris_requireAlloc!)
223+// 'realloc' just calls alloc and copies; 'free' does nothing
224+void* idris_alloc(size_t size);
225+void* idris_realloc(void* old, size_t old_size, size_t size);
226+void idris_free(void* ptr, size_t size);
215
227
216#define allocCon(cl, vm, t, a, o) \
228#define allocCon(cl, vm, t, a, o) \
217− cl = allocate(vm, sizeof(Closure) + sizeof(VAL)*a, o); \
229+ cl = allocate(sizeof(Closure) + sizeof(VAL)*a, o); \
218 SETTY(cl, CON); \
230 SETTY(cl, CON); \
219 cl->info.c.tag_arity = ((t) << 8) | (a);
231 cl->info.c.tag_arity = ((t) << 8) | (a);
220
232
@@ -226,8 +238,8 @@ void idris_doneAlloc(VM* vm);
226#define NULL_CON(x) nullary_cons[x]
238#define NULL_CON(x) nullary_cons[x]
227
239
228extern VAL* nullary_cons;
240extern VAL* nullary_cons;
229−void initNullaries();
241+void init_nullaries();
230−void freeNullaries();
242+void free_nullaries();
231
243
232void* vmThread(VM* callvm, func f, VAL arg);
244void* vmThread(VM* callvm, func f, VAL arg);
233
245
@@ -275,7 +287,7 @@ VAL idris_strIndex(VM* vm, VAL str, VAL i);
275VAL idris_strRev(VM* vm, VAL str);
287VAL idris_strRev(VM* vm, VAL str);
276
288
277// Buffer primitives
289// Buffer primitives
278−VAL idris_allocate(VM* vm, VAL hint);
290+VAL idris_buffer_allocate(VM* vm, VAL hint);
279VAL idris_appendBuffer(VM* vm, VAL fst, VAL fstLen, VAL cnt, VAL sndLen, VAL sndOff, VAL snd);
291VAL idris_appendBuffer(VM* vm, VAL fst, VAL fstLen, VAL cnt, VAL sndLen, VAL sndOff, VAL snd);
280VAL idris_appendB8Native(VM* vm, VAL buf, VAL len, VAL cnt, VAL val);
292VAL idris_appendB8Native(VM* vm, VAL buf, VAL len, VAL cnt, VAL val);
281VAL idris_appendB16Native(VM* vm, VAL buf, VAL len, VAL cnt, VAL val);
293VAL idris_appendB16Native(VM* vm, VAL buf, VAL len, VAL cnt, VAL val);
@@ -317,18 +329,6 @@ const char *idris_getArg(int i);
317
329
318void stackOverflow();
330void stackOverflow();
319
331
320−// Some FFI help (functions and macros below are all which C code should
321−// use)
322−
323−// When allocating from C, call 'idris_requireAlloc' with a size to
324−// guarantee that no garbage collection will happen (and hence nothing
325−// will move) until at least size bytes have been allocated.
326−// idris_doneAlloc *must* be called when allocation from C is done (as it
327−// may take a lock if other threads are running).
328−
329−void idris_requireAlloc(VM* vm, size_t size);
330−void idris_doneAlloc(VM* vm);
331−
332// I think these names are nicer for an API...
332// I think these names are nicer for an API...
333
333
334#define idris_constructor allocCon
334#define idris_constructor allocCon
src/IRTS/CodegenC.hs+1−1
@@ -480,7 +480,7 @@ doOp v LStrCons [x, y] = v ++ "idris_strCons(vm, " ++ creg x ++ "," ++ creg y ++
480doOp v LStrIndex [x, y] = v ++ "idris_strIndex(vm, " ++ creg x ++ "," ++ creg y ++ ")"
480doOp v LStrIndex [x, y] = v ++ "idris_strIndex(vm, " ++ creg x ++ "," ++ creg y ++ ")"
481doOp v LStrRev [x] = v ++ "idris_strRev(vm, " ++ creg x ++ ")"
481doOp v LStrRev [x] = v ++ "idris_strRev(vm, " ++ creg x ++ ")"
482
482
483−doOp v LAllocate [x] = v ++ "idris_allocate(vm, " ++ creg x ++ ")"
483+doOp v LAllocate [x] = v ++ "idris_buffer_allocate(vm, " ++ creg x ++ ")"
484doOp v LAppendBuffer [a, b, c, d, e, f] = v ++ "idris_appendBuffer(vm, " ++ creg a ++ "," ++ creg b ++ "," ++ creg c ++ "," ++ creg d ++ "," ++ creg e ++ "," ++ creg f ++ ")"
484doOp v LAppendBuffer [a, b, c, d, e, f] = v ++ "idris_appendBuffer(vm, " ++ creg a ++ "," ++ creg b ++ "," ++ creg c ++ "," ++ creg d ++ "," ++ creg e ++ "," ++ creg f ++ ")"
485doOp v (LAppend ity en) [a, b, c, d] = v ++ "idris_append" ++ intTyName ity ++ show en ++ "(vm, " ++ creg a ++ "," ++ creg b ++ "," ++ creg c ++ "," ++ creg d ++ ")"
485doOp v (LAppend ity en) [a, b, c, d] = v ++ "idris_append" ++ intTyName ity ++ show en ++ "(vm, " ++ creg a ++ "," ++ creg b ++ "," ++ creg c ++ "," ++ creg d ++ ")"
486doOp v (LPeek ity en) [x, y] = v ++ "idris_peek" ++ intTyName ity ++ show en ++ "(vm, " ++ creg x ++ "," ++ creg y ++ ")"
486doOp v (LPeek ity en) [x, y] = v ++ "idris_peek" ++ intTyName ity ++ show en ++ "(vm, " ++ creg x ++ "," ++ creg y ++ ")"