@@ -2,824 +2,558 @@
22
33#include "idris_rts.h"
44
5−VAL idris_b8CopyForGC(VM *vm, VAL a) {
6− uint8_t A = a->info.bits8;
7− VAL cl = allocate(sizeof(Closure), 1);
8− SETTY(cl, CT_BITS8);
9− cl->info.bits8 = A;
10− return cl;
5+VAL idris_b8const(VM *vm, uint8_t a) {
6+ return MKINT(a);
117}
128
13−VAL idris_b16CopyForGC(VM *vm, VAL a) {
14− uint16_t A = a->info.bits16;
15− VAL cl = allocate(sizeof(Closure), 1);
16− SETTY(cl, CT_BITS16);
17− cl->info.bits16 = A;
18− return cl;
9+VAL idris_b16const(VM *vm, uint16_t a) {
10+ return MKINT(a);
1911}
2012
21−VAL idris_b32CopyForGC(VM *vm, VAL a) {
22− uint32_t A = a->info.bits32;
23− VAL cl = allocate(sizeof(Closure), 1);
13+VAL idris_b32const(VM *vm, uint32_t a) {
14+ Bits32 * cl = iallocate(vm, sizeof(*cl), 0);
2415 SETTY(cl, CT_BITS32);
25− cl->info.bits32 = A;
26− return cl;
16+ cl->bits32 = a;
17+ return (VAL)cl;
2718}
2819
29−VAL idris_b64CopyForGC(VM *vm, VAL a) {
30− uint64_t A = a->info.bits64;
31− VAL cl = allocate(sizeof(Closure), 1);
20+VAL idris_b64const(VM *vm, uint64_t a) {
21+ Bits64 * cl = iallocate(vm, sizeof(*cl), 0);
3222 SETTY(cl, CT_BITS64);
33− cl->info.bits64 = A;
34− return cl;
23+ cl->bits64 = a;
24+ return (VAL)cl;
3525}
3626
3727VAL idris_b8(VM *vm, VAL a) {
38− uint8_t A = GETINT(a);
39− VAL cl = allocate(sizeof(Closure), 0);
40− SETTY(cl, CT_BITS8);
41− cl->info.bits8 = (uint8_t) A;
42− return cl;
28+ return idris_b8const(vm, GETINT(a));
4329}
4430
4531VAL idris_b16(VM *vm, VAL a) {
46− uint16_t A = GETINT(a);
47− VAL cl = allocate(sizeof(Closure), 0);
48− SETTY(cl, CT_BITS16);
49− cl->info.bits16 = (uint16_t) A;
50− return cl;
32+ return idris_b16const(vm, GETINT(a));
5133}
5234
5335VAL idris_b32(VM *vm, VAL a) {
54− uint32_t A = GETINT(a);
55− VAL cl = allocate(sizeof(Closure), 0);
56− SETTY(cl, CT_BITS32);
57− cl->info.bits32 = (uint32_t) A;
58− return cl;
36+ return idris_b32const(vm, GETINT(a));
5937}
6038
6139VAL idris_b64(VM *vm, VAL a) {
62− uint64_t A = GETINT(a);
63− VAL cl = allocate(sizeof(Closure), 0);
64− SETTY(cl, CT_BITS64);
65− cl->info.bits64 = (uint64_t) A;
66− return cl;
40+ return idris_b64const(vm, GETINT(a));
6741}
6842
6943VAL idris_castB32Int(VM *vm, VAL a) {
70− return MKINT((i_int)a->info.bits32);
71−}
72−
73−VAL idris_b8const(VM *vm, uint8_t a) {
74− VAL cl = allocate(sizeof(Closure), 0);
75− SETTY(cl, CT_BITS8);
76− cl->info.bits8 = a;
77− return cl;
78−}
79−
80−VAL idris_b16const(VM *vm, uint16_t a) {
81− VAL cl = allocate(sizeof(Closure), 0);
82− SETTY(cl, CT_BITS16);
83− cl->info.bits16 = a;
84− return cl;
85−}
86−
87−VAL idris_b32const(VM *vm, uint32_t a) {
88− VAL cl = allocate(sizeof(Closure), 0);
89− SETTY(cl, CT_BITS32);
90− cl->info.bits32 = a;
91− return cl;
92−}
93−
94−VAL idris_b64const(VM *vm, uint64_t a) {
95− VAL cl = allocate(sizeof(Closure), 0);
96− SETTY(cl, CT_BITS64);
97− cl->info.bits64 = a;
98− return cl;
44+ return MKINT(GETBITS32(a));
9945}
10046
10147VAL idris_b8Plus(VM *vm, VAL a, VAL b) {
102− uint8_t A = a->info.bits8;
103− uint8_t B = b->info.bits8;
104− VAL cl = allocate(sizeof(Closure), 0);
105− SETTY(cl, CT_BITS8);
106− cl->info.bits8 = A + B;
107− return cl;
48+ uint8_t A = GETBITS8(a);
49+ uint8_t B = GETBITS8(b);
50+ return idris_b8const(vm, A + B);
10851}
10952
11053VAL idris_b8Minus(VM *vm, VAL a, VAL b) {
111− uint8_t A = a->info.bits8;
112− uint8_t B = b->info.bits8;
113− VAL cl = allocate(sizeof(Closure), 0);
114− SETTY(cl, CT_BITS8);
115− cl->info.bits8 = A - B;
116− return cl;
54+ uint8_t A = GETBITS8(a);
55+ uint8_t B = GETBITS8(b);
56+ return idris_b8const(vm, A - B);
11757}
11858
11959VAL idris_b8Times(VM *vm, VAL a, VAL b) {
120− uint8_t A = a->info.bits8;
121− uint8_t B = b->info.bits8;
122− VAL cl = allocate(sizeof(Closure), 0);
123− SETTY(cl, CT_BITS8);
124− cl->info.bits8 = A * B;
125− return cl;
60+ uint8_t A = GETBITS8(a);
61+ uint8_t B = GETBITS8(b);
62+ return idris_b8const(vm, A * B);
12663}
12764
12865VAL idris_b8UDiv(VM *vm, VAL a, VAL b) {
129− uint8_t A = a->info.bits8;
130− uint8_t B = b->info.bits8;
131− VAL cl = allocate(sizeof(Closure), 0);
132− SETTY(cl, CT_BITS8);
133− cl->info.bits8 = A / B;
134− return cl;
66+ uint8_t A = GETBITS8(a);
67+ uint8_t B = GETBITS8(b);
68+ return idris_b8const(vm, A / B);
13569}
13670
13771VAL idris_b8SDiv(VM *vm, VAL a, VAL b) {
138− uint8_t A = a->info.bits8;
139− uint8_t B = b->info.bits8;
140− VAL cl = allocate(sizeof(Closure), 0);
141− SETTY(cl, CT_BITS8);
142− cl->info.bits8 = (uint8_t) (((int8_t) A) / ((int8_t) B));
143− return cl;
72+ int8_t A = GETBITS8(a);
73+ int8_t B = GETBITS8(b);
74+ return idris_b8const(vm, A / B);
14475}
14576
14677VAL idris_b8URem(VM *vm, VAL a, VAL b) {
147− uint8_t A = a->info.bits8;
148− uint8_t B = b->info.bits8;
149− VAL cl = allocate(sizeof(Closure), 0);
150− SETTY(cl, CT_BITS8);
151− cl->info.bits8 = A % B;
152− return cl;
78+ uint8_t A = GETBITS8(a);
79+ uint8_t B = GETBITS8(b);
80+ return idris_b8const(vm, A % B);
15381}
15482
15583VAL idris_b8SRem(VM *vm, VAL a, VAL b) {
156− uint8_t A = a->info.bits8;
157− uint8_t B = b->info.bits8;
158− VAL cl = allocate(sizeof(Closure), 0);
159− SETTY(cl, CT_BITS8);
160− cl->info.bits8 = (uint8_t) (((int8_t) A) % ((int8_t) B));
161− return cl;
84+ int8_t A = GETBITS8(a);
85+ int8_t B = GETBITS8(b);
86+ return idris_b8const(vm, A % B);
16287}
16388
16489VAL idris_b8Lt(VM *vm, VAL a, VAL b) {
165− return MKINT((i_int) (a->info.bits8 < b->info.bits8));
90+ return MKINT((i_int) (GETBITS8(a) < GETBITS8(b)));
16691}
16792
16893VAL idris_b8Gt(VM *vm, VAL a, VAL b) {
169− return MKINT((i_int) (a->info.bits8 > b->info.bits8));
94+ return MKINT((i_int) (GETBITS8(a) > GETBITS8(b)));
17095}
17196
17297VAL idris_b8Eq(VM *vm, VAL a, VAL b) {
173− return MKINT((i_int) (a->info.bits8 == b->info.bits8));
98+ return MKINT((i_int) (GETBITS8(a) == GETBITS8(b)));
17499}
175100
176101VAL idris_b8Lte(VM *vm, VAL a, VAL b) {
177− return MKINT((i_int) (a->info.bits8 <= b->info.bits8));
102+ return MKINT((i_int) (GETBITS8(a) <= GETBITS8(b)));
178103}
179104
180105VAL idris_b8Gte(VM *vm, VAL a, VAL b) {
181− return MKINT((i_int) (a->info.bits8 >= b->info.bits8));
106+ return MKINT((i_int) (GETBITS8(a) >= GETBITS8(b)));
182107}
183108
184109VAL idris_b8Compl(VM *vm, VAL a) {
185− uint8_t A = a->info.bits8;
186− VAL cl = allocate(sizeof(Closure), 0);
187− SETTY(cl, CT_BITS8);
188− cl->info.bits8 = ~ A;
189− return cl;
110+ uint8_t A = GETBITS8(a);
111+ return idris_b8const(vm, ~ A);
190112}
191113
192114VAL idris_b8And(VM *vm, VAL a, VAL b) {
193− uint8_t A = a->info.bits8;
194− uint8_t B = b->info.bits8;
195− VAL cl = allocate(sizeof(Closure), 0);
196− SETTY(cl, CT_BITS8);
197− cl->info.bits8 = A & B;
198− return cl;
115+ uint8_t A = GETBITS8(a);
116+ uint8_t B = GETBITS8(b);
117+ return idris_b8const(vm, A & B);
199118}
200119
201120VAL idris_b8Or(VM *vm, VAL a, VAL b) {
202− uint8_t A = a->info.bits8;
203− uint8_t B = b->info.bits8;
204− VAL cl = allocate(sizeof(Closure), 0);
205− SETTY(cl, CT_BITS8);
206− cl->info.bits8 = A | B;
207− return cl;
121+ uint8_t A = GETBITS8(a);
122+ uint8_t B = GETBITS8(b);
123+ return idris_b8const(vm, A | B);
208124}
209125
210126VAL idris_b8Xor(VM *vm, VAL a, VAL b) {
211− uint8_t A = a->info.bits8;
212− uint8_t B = b->info.bits8;
213− VAL cl = allocate(sizeof(Closure), 0);
214− SETTY(cl, CT_BITS8);
215− cl->info.bits8 = A ^ B;
216− return cl;
127+ uint8_t A = GETBITS8(a);
128+ uint8_t B = GETBITS8(b);
129+ return idris_b8const(vm, A ^ B);
217130}
218131
219132VAL idris_b8Shl(VM *vm, VAL a, VAL b) {
220− uint8_t A = a->info.bits8;
221− uint8_t B = b->info.bits8;
222− VAL cl = allocate(sizeof(Closure), 0);
223− SETTY(cl, CT_BITS8);
224− cl->info.bits8 = A << B;
225− return cl;
133+ uint8_t A = GETBITS8(a);
134+ uint8_t B = GETBITS8(b);
135+ return idris_b8const(vm, A << B);
226136}
227137
228138VAL idris_b8LShr(VM *vm, VAL a, VAL b) {
229− uint8_t A = a->info.bits8;
230− uint8_t B = b->info.bits8;
231− VAL cl = allocate(sizeof(Closure), 0);
232− SETTY(cl, CT_BITS8);
233− cl->info.bits8 = A >> B;
234− return cl;
139+ uint8_t A = GETBITS8(a);
140+ uint8_t B = GETBITS8(b);
141+ return idris_b8const(vm, A >> B);
235142}
236143
237144VAL idris_b8AShr(VM *vm, VAL a, VAL b) {
238− uint8_t A = a->info.bits8;
239− uint8_t B = b->info.bits8;
240− VAL cl = allocate(sizeof(Closure), 0);
241− SETTY(cl, CT_BITS8);
242− cl->info.bits8 = (uint8_t) (((int8_t) A) >> ((int8_t) B));
243− return cl;
145+ int8_t A = GETBITS8(a);
146+ int8_t B = GETBITS8(b);
147+ return idris_b8const(vm, A >> B);
244148}
245149
246150VAL idris_b16Plus(VM *vm, VAL a, VAL b) {
247− uint16_t A = a->info.bits16;
248− uint16_t B = b->info.bits16;
249− VAL cl = allocate(sizeof(Closure), 0);
250− SETTY(cl, CT_BITS16);
251− cl->info.bits16 = A + B;
252− return cl;
151+ uint16_t A = GETBITS16(a);
152+ uint16_t B = GETBITS16(b);
153+ return idris_b16const(vm, A + B);
253154}
254155
255156VAL idris_b16Minus(VM *vm, VAL a, VAL b) {
256− uint16_t A = a->info.bits16;
257− uint16_t B = b->info.bits16;
258− VAL cl = allocate(sizeof(Closure), 0);
259− SETTY(cl, CT_BITS16);
260− cl->info.bits16 = A - B;
261− return cl;
157+ uint16_t A = GETBITS16(a);
158+ uint16_t B = GETBITS16(b);
159+ return idris_b16const(vm, A - B);
262160}
263161
264162VAL idris_b16Times(VM *vm, VAL a, VAL b) {
265− uint16_t A = a->info.bits16;
266− uint16_t B = b->info.bits16;
267− VAL cl = allocate(sizeof(Closure), 0);
268− SETTY(cl, CT_BITS16);
269− cl->info.bits16 = A * B;
270− return cl;
163+ uint16_t A = GETBITS16(a);
164+ uint16_t B = GETBITS16(b);
165+ return idris_b16const(vm, A * B);
271166}
272167
273168VAL idris_b16UDiv(VM *vm, VAL a, VAL b) {
274− uint16_t A = a->info.bits16;
275− uint16_t B = b->info.bits16;
276− VAL cl = allocate(sizeof(Closure), 0);
277− SETTY(cl, CT_BITS16);
278− cl->info.bits16 = A / B;
279− return cl;
169+ uint16_t A = GETBITS16(a);
170+ uint16_t B = GETBITS16(b);
171+ return idris_b16const(vm, A / B);
280172}
281173
282174VAL idris_b16SDiv(VM *vm, VAL a, VAL b) {
283− uint16_t A = a->info.bits16;
284− uint16_t B = b->info.bits16;
285− VAL cl = allocate(sizeof(Closure), 0);
286− SETTY(cl, CT_BITS16);
287− cl->info.bits16 = (uint16_t) (((int16_t) A) / ((int16_t) B));
288− return cl;
175+ int16_t A = GETBITS16(a);
176+ int16_t B = GETBITS16(b);
177+ return idris_b16const(vm, A / B);
289178}
290179
291180VAL idris_b16URem(VM *vm, VAL a, VAL b) {
292− uint16_t A = a->info.bits16;
293− uint16_t B = b->info.bits16;
294− VAL cl = allocate(sizeof(Closure), 0);
295− SETTY(cl, CT_BITS16);
296− cl->info.bits16 = A % B;
297− return cl;
181+ uint16_t A = GETBITS16(a);
182+ uint16_t B = GETBITS16(b);
183+ return idris_b16const(vm, A % B);
298184}
299185
300186VAL idris_b16SRem(VM *vm, VAL a, VAL b) {
301− uint16_t A = a->info.bits16;
302− uint16_t B = b->info.bits16;
303− VAL cl = allocate(sizeof(Closure), 0);
304− SETTY(cl, CT_BITS16);
305− cl->info.bits16 = (uint16_t) (((int16_t) A) % ((int16_t) B));
306− return cl;
187+ int16_t A = GETBITS16(a);
188+ int16_t B = GETBITS16(b);
189+ return idris_b16const(vm, A % B);
307190}
308191
309192VAL idris_b16Lt(VM *vm, VAL a, VAL b) {
310− return MKINT((i_int) (a->info.bits16 < b->info.bits16));
193+ return MKINT((i_int) (GETBITS16(a) < GETBITS16(b)));
311194}
312195
313196VAL idris_b16Gt(VM *vm, VAL a, VAL b) {
314− return MKINT((i_int) (a->info.bits16 > b->info.bits16));
197+ return MKINT((i_int) (GETBITS16(a) > GETBITS16(b)));
315198}
316199
317200VAL idris_b16Eq(VM *vm, VAL a, VAL b) {
318− return MKINT((i_int) (a->info.bits16 == b->info.bits16));
201+ return MKINT((i_int) (GETBITS16(a) == GETBITS16(b)));
319202}
320203
321204VAL idris_b16Lte(VM *vm, VAL a, VAL b) {
322− return MKINT((i_int) (a->info.bits16 <= b->info.bits16));
205+ return MKINT((i_int) (GETBITS16(a) <= GETBITS16(b)));
323206}
324207
325208VAL idris_b16Gte(VM *vm, VAL a, VAL b) {
326− return MKINT((i_int) (a->info.bits16 >= b->info.bits16));
209+ return MKINT((i_int) (GETBITS16(a) >= GETBITS16(b)));
327210}
328211
329212VAL idris_b16Compl(VM *vm, VAL a) {
330− uint16_t A = a->info.bits16;
331− VAL cl = allocate(sizeof(Closure), 0);
332− SETTY(cl, CT_BITS16);
333− cl->info.bits16 = ~ A;
334− return cl;
213+ uint16_t A = GETBITS16(a);
214+ return idris_b16const(vm, ~ A);
335215}
336216
337217VAL idris_b16And(VM *vm, VAL a, VAL b) {
338− uint16_t A = a->info.bits16;
339− uint16_t B = b->info.bits16;
340− VAL cl = allocate(sizeof(Closure), 0);
341− SETTY(cl, CT_BITS16);
342− cl->info.bits16 = A & B;
343− return cl;
218+ uint16_t A = GETBITS16(a);
219+ uint16_t B = GETBITS16(b);
220+ return idris_b16const(vm, A & B);
344221}
345222
346223VAL idris_b16Or(VM *vm, VAL a, VAL b) {
347− uint16_t A = a->info.bits16;
348− uint16_t B = b->info.bits16;
349− VAL cl = allocate(sizeof(Closure), 0);
350− SETTY(cl, CT_BITS16);
351− cl->info.bits16 = A | B;
352− return cl;
224+ uint16_t A = GETBITS16(a);
225+ uint16_t B = GETBITS16(b);
226+ return idris_b16const(vm, A | B);
353227}
354228
355229VAL idris_b16Xor(VM *vm, VAL a, VAL b) {
356− uint16_t A = a->info.bits16;
357− uint16_t B = b->info.bits16;
358− VAL cl = allocate(sizeof(Closure), 0);
359− SETTY(cl, CT_BITS16);
360− cl->info.bits16 = A ^ B;
361− return cl;
230+ uint16_t A = GETBITS16(a);
231+ uint16_t B = GETBITS16(b);
232+ return idris_b16const(vm, A ^ B);
362233}
363234
364235VAL idris_b16Shl(VM *vm, VAL a, VAL b) {
365− uint16_t A = a->info.bits16;
366− uint16_t B = b->info.bits16;
367− VAL cl = allocate(sizeof(Closure), 0);
368− SETTY(cl, CT_BITS16);
369− cl->info.bits16 = A << B;
370− return cl;
236+ uint16_t A = GETBITS16(a);
237+ uint16_t B = GETBITS16(b);
238+ return idris_b16const(vm, A << B);
371239}
372240
373241VAL idris_b16LShr(VM *vm, VAL a, VAL b) {
374− uint16_t A = a->info.bits16;
375− uint16_t B = b->info.bits16;
376− VAL cl = allocate(sizeof(Closure), 0);
377− SETTY(cl, CT_BITS16);
378− cl->info.bits16 = A >> B;
379− return cl;
242+ uint16_t A = GETBITS16(a);
243+ uint16_t B = GETBITS16(b);
244+ return idris_b16const(vm, A >> B);
380245}
381246
382247VAL idris_b16AShr(VM *vm, VAL a, VAL b) {
383− uint16_t A = a->info.bits16;
384− uint16_t B = b->info.bits16;
385− VAL cl = allocate(sizeof(Closure), 0);
386− SETTY(cl, CT_BITS16);
387− cl->info.bits16 = (uint16_t) (((int16_t) A) >> ((int16_t) B));
388− return cl;
248+ int16_t A = GETBITS16(a);
249+ int16_t B = GETBITS16(b);
250+ return idris_b16const(vm, A >> B);
389251}
390252
391253VAL idris_b32Plus(VM *vm, VAL a, VAL b) {
392− uint32_t A = a->info.bits32;
393− uint32_t B = b->info.bits32;
394− VAL cl = allocate(sizeof(Closure), 0);
395− SETTY(cl, CT_BITS32);
396− cl->info.bits32 = A + B;
397− return cl;
254+ uint32_t A = GETBITS32(a);
255+ uint32_t B = GETBITS32(b);
256+ return idris_b32const(vm, A + B);
398257}
399258
400259VAL idris_b32Minus(VM *vm, VAL a, VAL b) {
401− uint32_t A = a->info.bits32;
402− uint32_t B = b->info.bits32;
403− VAL cl = allocate(sizeof(Closure), 0);
404− SETTY(cl, CT_BITS32);
405− cl->info.bits32 = A - B;
406− return cl;
260+ uint32_t A = GETBITS32(a);
261+ uint32_t B = GETBITS32(b);
262+ return idris_b32const(vm, A - B);
407263}
408264
409265VAL idris_b32Times(VM *vm, VAL a, VAL b) {
410− uint32_t A = a->info.bits32;
411− uint32_t B = b->info.bits32;
412− VAL cl = allocate(sizeof(Closure), 0);
413− SETTY(cl, CT_BITS32);
414− cl->info.bits32 = A * B;
415− return cl;
266+ uint32_t A = GETBITS32(a);
267+ uint32_t B = GETBITS32(b);
268+ return idris_b32const(vm, A * B);
416269}
417270
418271VAL idris_b32UDiv(VM *vm, VAL a, VAL b) {
419− uint32_t A = a->info.bits32;
420− uint32_t B = b->info.bits32;
421− VAL cl = allocate(sizeof(Closure), 0);
422− SETTY(cl, CT_BITS32);
423− cl->info.bits32 = A / B;
424− return cl;
272+ uint32_t A = GETBITS32(a);
273+ uint32_t B = GETBITS32(b);
274+ return idris_b32const(vm, A / B);
425275}
426276
427277VAL idris_b32SDiv(VM *vm, VAL a, VAL b) {
428− uint32_t A = a->info.bits32;
429− uint32_t B = b->info.bits32;
430− VAL cl = allocate(sizeof(Closure), 0);
431− SETTY(cl, CT_BITS32);
432− cl->info.bits32 = (uint32_t) (((int32_t) A) / ((int32_t) B));
433− return cl;
278+ int32_t A = GETBITS32(a);
279+ int32_t B = GETBITS32(b);
280+ return idris_b32const(vm, A / B);
434281}
435282
436283VAL idris_b32URem(VM *vm, VAL a, VAL b) {
437− uint32_t A = a->info.bits32;
438− uint32_t B = b->info.bits32;
439− VAL cl = allocate(sizeof(Closure), 0);
440− SETTY(cl, CT_BITS32);
441− cl->info.bits32 = A % B;
442− return cl;
284+ uint32_t A = GETBITS32(a);
285+ uint32_t B = GETBITS32(b);
286+ return idris_b32const(vm, A % B);
443287}
444288
445289VAL idris_b32SRem(VM *vm, VAL a, VAL b) {
446− uint32_t A = a->info.bits32;
447− uint32_t B = b->info.bits32;
448− VAL cl = allocate(sizeof(Closure), 0);
449− SETTY(cl, CT_BITS32);
450− cl->info.bits32 = (uint32_t) (((int32_t) A) % ((int32_t) B));
451− return cl;
290+ int32_t A = GETBITS32(a);
291+ int32_t B = GETBITS32(b);
292+ return idris_b32const(vm, A % B);
452293}
453294
454295VAL idris_b32Lt(VM *vm, VAL a, VAL b) {
455− return MKINT((i_int) (a->info.bits32 < b->info.bits32));
296+ return MKINT((i_int) (GETBITS32(a) < GETBITS32(b)));
456297}
457298
458299VAL idris_b32Gt(VM *vm, VAL a, VAL b) {
459− return MKINT((i_int) (a->info.bits32 > b->info.bits32));
300+ return MKINT((i_int) (GETBITS32(a) > GETBITS32(b)));
460301}
461302
462303VAL idris_b32Eq(VM *vm, VAL a, VAL b) {
463− return MKINT((i_int) (a->info.bits32 == b->info.bits32));
304+ return MKINT((i_int) (GETBITS32(a) == GETBITS32(b)));
464305}
465306
466307VAL idris_b32Lte(VM *vm, VAL a, VAL b) {
467− return MKINT((i_int) (a->info.bits32 <= b->info.bits32));
308+ return MKINT((i_int) (GETBITS32(a) <= GETBITS32(b)));
468309}
469310
470311VAL idris_b32Gte(VM *vm, VAL a, VAL b) {
471− return MKINT((i_int) (a->info.bits32 >= b->info.bits32));
312+ return MKINT((i_int) (GETBITS32(a) >= GETBITS32(b)));
472313}
473314
474315VAL idris_b32Compl(VM *vm, VAL a) {
475− uint32_t A = a->info.bits32;
476− VAL cl = allocate(sizeof(Closure), 0);
477− SETTY(cl, CT_BITS32);
478− cl->info.bits32 = ~ A;
479− return cl;
316+ uint32_t A = GETBITS32(a);
317+ return idris_b32const(vm, ~ A);
480318}
481319
482320VAL idris_b32And(VM *vm, VAL a, VAL b) {
483− uint32_t A = a->info.bits32;
484− uint32_t B = b->info.bits32;
485− VAL cl = allocate(sizeof(Closure), 0);
486− SETTY(cl, CT_BITS32);
487− cl->info.bits32 = A & B;
488− return cl;
321+ uint32_t A = GETBITS32(a);
322+ uint32_t B = GETBITS32(b);
323+ return idris_b32const(vm, A & B);
489324}
490325
491326VAL idris_b32Or(VM *vm, VAL a, VAL b) {
492− uint32_t A = a->info.bits32;
493− uint32_t B = b->info.bits32;
494− VAL cl = allocate(sizeof(Closure), 0);
495− SETTY(cl, CT_BITS32);
496− cl->info.bits32 = A | B;
497− return cl;
327+ uint32_t A = GETBITS32(a);
328+ uint32_t B = GETBITS32(b);
329+ return idris_b32const(vm, A | B);
498330}
499331
500332VAL idris_b32Xor(VM *vm, VAL a, VAL b) {
501− uint32_t A = a->info.bits32;
502− uint32_t B = b->info.bits32;
503− VAL cl = allocate(sizeof(Closure), 0);
504− SETTY(cl, CT_BITS32);
505− cl->info.bits32 = A ^ B;
506− return cl;
333+ uint32_t A = GETBITS32(a);
334+ uint32_t B = GETBITS32(b);
335+ return idris_b32const(vm, A ^ B);
507336}
508337
509338VAL idris_b32Shl(VM *vm, VAL a, VAL b) {
510− uint32_t A = a->info.bits32;
511− uint32_t B = b->info.bits32;
512− VAL cl = allocate(sizeof(Closure), 0);
513− SETTY(cl, CT_BITS32);
514− cl->info.bits32 = A << B;
515− return cl;
339+ uint32_t A = GETBITS32(a);
340+ uint32_t B = GETBITS32(b);
341+ return idris_b32const(vm, A << B);
516342}
517343
518344VAL idris_b32LShr(VM *vm, VAL a, VAL b) {
519− uint32_t A = a->info.bits32;
520− uint32_t B = b->info.bits32;
521− VAL cl = allocate(sizeof(Closure), 0);
522− SETTY(cl, CT_BITS32);
523− cl->info.bits32 = A >> B;
524− return cl;
345+ uint32_t A = GETBITS32(a);
346+ uint32_t B = GETBITS32(b);
347+ return idris_b32const(vm, A >> B);
525348}
526349
527350VAL idris_b32AShr(VM *vm, VAL a, VAL b) {
528− uint32_t A = a->info.bits32;
529− uint32_t B = b->info.bits32;
530− VAL cl = allocate(sizeof(Closure), 0);
531− SETTY(cl, CT_BITS32);
532− cl->info.bits32 = (uint32_t) (((int32_t)A) >> ((int32_t)B));
533− return cl;
351+ int32_t A = GETBITS32(a);
352+ int32_t B = GETBITS32(b);
353+ return idris_b32const(vm, A >> B);
534354}
535355
536356VAL idris_b64Plus(VM *vm, VAL a, VAL b) {
537− uint64_t A = a->info.bits64;
538− uint64_t B = b->info.bits64;
539− VAL cl = allocate(sizeof(Closure), 0);
540− SETTY(cl, CT_BITS64);
541− cl->info.bits64 = A + B;
542− return cl;
357+ uint64_t A = GETBITS64(a);
358+ uint64_t B = GETBITS64(b);
359+ return idris_b64const(vm, A + B);
543360}
544361
545362VAL idris_b64Minus(VM *vm, VAL a, VAL b) {
546− uint64_t A = a->info.bits64;
547− uint64_t B = b->info.bits64;
548− VAL cl = allocate(sizeof(Closure), 0);
549− SETTY(cl, CT_BITS64);
550− cl->info.bits64 = A - B;
551− return cl;
363+ uint64_t A = GETBITS64(a);
364+ uint64_t B = GETBITS64(b);
365+ return idris_b64const(vm, A - B);
552366}
553367
554368VAL idris_b64Times(VM *vm, VAL a, VAL b) {
555− uint64_t A = a->info.bits64;
556− uint64_t B = b->info.bits64;
557− VAL cl = allocate(sizeof(Closure), 0);
558− SETTY(cl, CT_BITS64);
559− cl->info.bits64 = A * B;
560− return cl;
369+ uint64_t A = GETBITS64(a);
370+ uint64_t B = GETBITS64(b);
371+ return idris_b64const(vm, A * B);
561372}
562373
563374VAL idris_b64UDiv(VM *vm, VAL a, VAL b) {
564− uint64_t A = a->info.bits64;
565− uint64_t B = b->info.bits64;
566− VAL cl = allocate(sizeof(Closure), 0);
567− SETTY(cl, CT_BITS64);
568− cl->info.bits64 = A / B;
569− return cl;
375+ uint64_t A = GETBITS64(a);
376+ uint64_t B = GETBITS64(b);
377+ return idris_b64const(vm, A / B);
570378}
571379
572380VAL idris_b64SDiv(VM *vm, VAL a, VAL b) {
573− uint64_t A = a->info.bits64;
574− uint64_t B = b->info.bits64;
575− VAL cl = allocate(sizeof(Closure), 0);
576− SETTY(cl, CT_BITS64);
577− cl->info.bits64 = (uint64_t) (((int64_t) A) / ((int64_t) B));
578− return cl;
381+ int64_t A = GETBITS64(a);
382+ int64_t B = GETBITS64(b);
383+ return idris_b64const(vm, A / B);
579384}
580385
581386VAL idris_b64URem(VM *vm, VAL a, VAL b) {
582− uint64_t A = a->info.bits64;
583− uint64_t B = b->info.bits64;
584− VAL cl = allocate(sizeof(Closure), 0);
585− SETTY(cl, CT_BITS64);
586− cl->info.bits64 = A % B;
587− return cl;
387+ uint64_t A = GETBITS64(a);
388+ uint64_t B = GETBITS64(b);
389+ return idris_b64const(vm, A % B);
588390}
589391
590392VAL idris_b64SRem(VM *vm, VAL a, VAL b) {
591− uint64_t A = a->info.bits64;
592− uint64_t B = b->info.bits64;
593− VAL cl = allocate(sizeof(Closure), 0);
594− SETTY(cl, CT_BITS64);
595− cl->info.bits64 = (uint64_t) (((int64_t) A) % ((int64_t) B));
596− return cl;
393+ int64_t A = GETBITS64(a);
394+ int64_t B = GETBITS64(b);
395+ return idris_b64const(vm, A % B);
597396}
598397
599398VAL idris_b64Lt(VM *vm, VAL a, VAL b) {
600− return MKINT((i_int) (a->info.bits64 < b->info.bits64));
399+ uint64_t A = GETBITS64(a);
400+ uint64_t B = GETBITS64(b);
401+ return MKINT((i_int) (A < B));
601402}
602403
603404VAL idris_b64Gt(VM *vm, VAL a, VAL b) {
604− return MKINT((i_int) (a->info.bits64 > b->info.bits64));
405+ uint64_t A = GETBITS64(a);
406+ uint64_t B = GETBITS64(b);
407+ return MKINT((i_int) (A > B));
605408}
606409
607410VAL idris_b64Eq(VM *vm, VAL a, VAL b) {
608− return MKINT((i_int) (a->info.bits64 == b->info.bits64));
411+ uint64_t A = GETBITS64(a);
412+ uint64_t B = GETBITS64(b);
413+ return MKINT((i_int) (A == B));
609414}
610415
611416VAL idris_b64Lte(VM *vm, VAL a, VAL b) {
612− return MKINT((i_int) (a->info.bits64 <= b->info.bits64));
417+ uint64_t A = GETBITS64(a);
418+ uint64_t B = GETBITS64(b);
419+ return MKINT((i_int) (A <= B));
613420}
614421
615422VAL idris_b64Gte(VM *vm, VAL a, VAL b) {
616− return MKINT((i_int) (a->info.bits64 >= b->info.bits64));
423+ uint64_t A = GETBITS64(a);
424+ uint64_t B = GETBITS64(b);
425+ return MKINT((i_int) (A >= B));
617426}
618427
619428VAL idris_b64Compl(VM *vm, VAL a) {
620− uint64_t A = a->info.bits64;
621− VAL cl = allocate(sizeof(Closure), 0);
622− SETTY(cl, CT_BITS64);
623− cl->info.bits64 = ~ A;
624− return cl;
429+ uint64_t A = GETBITS64(a);
430+ return idris_b64const(vm, ~ A);
625431}
626432
627433VAL idris_b64And(VM *vm, VAL a, VAL b) {
628− uint64_t A = a->info.bits64;
629− uint64_t B = b->info.bits64;
630− VAL cl = allocate(sizeof(Closure), 0);
631− SETTY(cl, CT_BITS64);
632− cl->info.bits64 = A & B;
633− return cl;
434+ uint64_t A = GETBITS64(a);
435+ uint64_t B = GETBITS64(b);
436+ return idris_b64const(vm, A & B);
634437}
635438
636439VAL idris_b64Or(VM *vm, VAL a, VAL b) {
637− uint64_t A = a->info.bits64;
638− uint64_t B = b->info.bits64;
639− VAL cl = allocate(sizeof(Closure), 0);
640− SETTY(cl, CT_BITS64);
641− cl->info.bits64 = A | B;
642− return cl;
440+ uint64_t A = GETBITS64(a);
441+ uint64_t B = GETBITS64(b);
442+ return idris_b64const(vm, A | B);
643443}
644444
645445VAL idris_b64Xor(VM *vm, VAL a, VAL b) {
646− uint64_t A = a->info.bits64;
647− uint64_t B = b->info.bits64;
648− VAL cl = allocate(sizeof(Closure), 0);
649− SETTY(cl, CT_BITS64);
650− cl->info.bits64 = A ^ B;
651− return cl;
446+ uint64_t A = GETBITS64(a);
447+ uint64_t B = GETBITS64(b);
448+ return idris_b64const(vm, A ^ B);
652449}
653450
654451VAL idris_b64Shl(VM *vm, VAL a, VAL b) {
655− uint64_t A = a->info.bits64;
656− uint64_t B = b->info.bits64;
657− VAL cl = allocate(sizeof(Closure), 0);
658− SETTY(cl, CT_BITS64);
659− cl->info.bits64 = A << B;
660− return cl;
452+ uint64_t A = GETBITS64(a);
453+ uint64_t B = GETBITS64(b);
454+ return idris_b64const(vm, A << B);
661455}
662456
663457VAL idris_b64LShr(VM *vm, VAL a, VAL b) {
664− uint64_t A = a->info.bits64;
665− uint64_t B = b->info.bits64;
666− VAL cl = allocate(sizeof(Closure), 0);
667− SETTY(cl, CT_BITS64);
668− cl->info.bits64 = A >> B;
669− return cl;
458+ uint64_t A = GETBITS64(a);
459+ uint64_t B = GETBITS64(b);
460+ return idris_b64const(vm, A >> B);
670461}
671462
672463VAL idris_b64AShr(VM *vm, VAL a, VAL b) {
673− uint64_t A = a->info.bits64;
674− uint64_t B = b->info.bits64;
675− VAL cl = allocate(sizeof(Closure), 0);
676− SETTY(cl, CT_BITS64);
677− cl->info.bits64 = (uint64_t) (((int64_t) A) >> ((int64_t) B));
678− return cl;
464+ int64_t A = GETBITS64(a);
465+ int64_t B = GETBITS64(b);
466+ return idris_b64const(vm, A >> B);
679467}
680468
681469VAL idris_b8Z16(VM *vm, VAL a) {
682− uint8_t A = a->info.bits8;
683− VAL cl = allocate(sizeof(Closure), 0);
684− SETTY(cl, CT_BITS16);
685− cl->info.bits16 = (uint16_t) A;
686− return cl;
470+ uint8_t A = GETBITS8(a);
471+ return idris_b16const(vm, A);
687472}
688473
689474VAL idris_b8Z32(VM *vm, VAL a) {
690− uint8_t A = a->info.bits8;
691− VAL cl = allocate(sizeof(Closure), 0);
692− SETTY(cl, CT_BITS32);
693− cl->info.bits32 = (uint32_t) A;
694− return cl;
475+ uint8_t A = GETBITS8(a);
476+ return idris_b32const(vm, A);
695477}
696478
697479VAL idris_b8Z64(VM *vm, VAL a) {
698− uint8_t A = a->info.bits8;
699− VAL cl = allocate(sizeof(Closure), 0);
700− SETTY(cl, CT_BITS64);
701− cl->info.bits64 = (uint64_t) A;
702− return cl;
480+ uint8_t A = GETBITS8(a);
481+ return idris_b64const(vm, A);
703482}
704483
705484VAL idris_b8S16(VM *vm, VAL a) {
706− uint8_t A = a->info.bits8;
707− VAL cl = allocate(sizeof(Closure), 0);
708− SETTY(cl, CT_BITS16);
709− cl->info.bits16 = (uint16_t) (int16_t) (int8_t) A;
710− return cl;
485+ int8_t A = GETBITS8(a);
486+ return idris_b16const(vm, (int16_t) A);
711487}
712488
713489VAL idris_b8S32(VM *vm, VAL a) {
714− uint8_t A = a->info.bits8;
715− VAL cl = allocate(sizeof(Closure), 0);
716− SETTY(cl, CT_BITS32);
717− cl->info.bits32 = (uint32_t) (int32_t) (int8_t) A;
718− return cl;
490+ int8_t A = GETBITS8(a);
491+ return idris_b32const(vm, (int32_t) A);
719492}
720493
721494VAL idris_b8S64(VM *vm, VAL a) {
722− uint8_t A = a->info.bits8;
723− VAL cl = allocate(sizeof(Closure), 0);
724− SETTY(cl, CT_BITS64);
725− cl->info.bits64 = (uint64_t) (int64_t) (int8_t) A;
726− return cl;
495+ int8_t A = GETBITS8(a);
496+ return idris_b64const(vm, (int64_t) A);
727497}
728498
729499VAL idris_b16Z32(VM *vm, VAL a) {
730− uint16_t A = a->info.bits16;
731− VAL cl = allocate(sizeof(Closure), 0);
732− SETTY(cl, CT_BITS32);
733− cl->info.bits32 = (uint32_t) A;
734− return cl;
500+ uint16_t A = GETBITS16(a);
501+ return idris_b32const(vm, (uint32_t) A);
735502}
736503
737504VAL idris_b16Z64(VM *vm, VAL a) {
738− uint16_t A = a->info.bits16;
739− VAL cl = allocate(sizeof(Closure), 0);
740− SETTY(cl, CT_BITS64);
741− cl->info.bits64 = (uint64_t) A;
742− return cl;
505+ uint16_t A = GETBITS16(a);
506+ return idris_b64const(vm, (uint64_t) A);
743507}
744508
745509VAL idris_b16S32(VM *vm, VAL a) {
746− uint16_t A = a->info.bits16;
747− VAL cl = allocate(sizeof(Closure), 0);
748− SETTY(cl, CT_BITS32);
749− cl->info.bits32 = (uint32_t) (int32_t) (int16_t) A;
750− return cl;
510+ int16_t A = GETBITS16(a);
511+ return idris_b32const(vm, (int32_t) A);
751512}
752513
753514VAL idris_b16S64(VM *vm, VAL a) {
754− uint16_t A = a->info.bits16;
755− VAL cl = allocate(sizeof(Closure), 0);
756− SETTY(cl, CT_BITS64);
757− cl->info.bits64 = (uint64_t) (int64_t) (int16_t) A;
758− return cl;
515+ int16_t A = GETBITS16(a);
516+ return idris_b64const(vm, (int64_t) A);
759517}
760518
761519VAL idris_b16T8(VM *vm, VAL a) {
762− uint16_t A = a->info.bits16;
763− VAL cl = allocate(sizeof(Closure), 0);
764− SETTY(cl, CT_BITS8);
765− cl->info.bits8 = (uint8_t) A;
766− return cl;
520+ uint16_t A = GETBITS16(a);
521+ return idris_b8const(vm, (uint8_t) A);
767522}
768523
769524VAL idris_b32Z64(VM *vm, VAL a) {
770− uint32_t A = a->info.bits32;
771− VAL cl = allocate(sizeof(Closure), 0);
772− SETTY(cl, CT_BITS64);
773− cl->info.bits64 = (uint64_t) A;
774− return cl;
525+ uint32_t A = GETBITS32(a);
526+ return idris_b64const(vm, (uint64_t) A);
775527}
776528
777529VAL idris_b32S64(VM *vm, VAL a) {
778− uint32_t A = a->info.bits32;
779− VAL cl = allocate(sizeof(Closure), 0);
780− SETTY(cl, CT_BITS64);
781− cl->info.bits64 = (uint64_t) (int64_t) (int32_t) A;
782− return cl;
530+ int32_t A = GETBITS32(a);
531+ return idris_b64const(vm, (int64_t) A);
783532}
784533
785534VAL idris_b32T8(VM *vm, VAL a) {
786− uint32_t A = a->info.bits32;
787− VAL cl = allocate(sizeof(Closure), 0);
788− SETTY(cl, CT_BITS8);
789− cl->info.bits8 = (uint8_t) A;
790− return cl;
535+ uint32_t A = GETBITS32(a);
536+ return idris_b8const(vm, (uint8_t) A);
791537}
792538
793539VAL idris_b32T16(VM *vm, VAL a) {
794− uint32_t A = a->info.bits32;
795− VAL cl = allocate(sizeof(Closure), 0);
796− SETTY(cl, CT_BITS16);
797− cl->info.bits16 = (uint16_t) A;
798− return cl;
540+ uint32_t A = GETBITS32(a);
541+ return idris_b16const(vm, (uint16_t) A);
799542}
800543
801544VAL idris_b64T8(VM *vm, VAL a) {
802− uint64_t A = a->info.bits64;
803− VAL cl = allocate(sizeof(Closure), 0);
804− SETTY(cl, CT_BITS8);
805− cl->info.bits8 = (uint8_t) A;
806− return cl;
545+ uint64_t A = GETBITS64(a);
546+ return idris_b8const(vm, (uint8_t) A);
807547}
808548
809549VAL idris_b64T16(VM *vm, VAL a) {
810− uint64_t A = a->info.bits64;
811− VAL cl = allocate(sizeof(Closure), 0);
812− SETTY(cl, CT_BITS16);
813− cl->info.bits16 = (uint16_t) A;
814− return cl;
550+ uint64_t A = GETBITS64(a);
551+ return idris_b16const(vm, (uint16_t) A);
815552}
816553
817554VAL idris_b64T32(VM *vm, VAL a) {
818− uint64_t A = a->info.bits64;
819− VAL cl = allocate(sizeof(Closure), 0);
820− SETTY(cl, CT_BITS32);
821− cl->info.bits32 = (uint32_t) A;
822− return cl;
555+ uint64_t A = GETBITS64(a);
556+ return idris_b32const(vm, (uint32_t) A);
823557}
824558
825559VAL idris_peekB8(VM* vm, VAL ptr, VAL offset) {