@@ -2,824 +2,564 @@
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);
5+VAL idris_b8const(VM *vm, uint8_t a) {
6+ Bits8 * cl = iallocate(vm, sizeof(*cl), 0);
87 SETTY(cl, CT_BITS8);
9− cl->info.bits8 = A;
10− return cl;
8+ cl->bits8 = a;
9+ return (VAL)cl;
1110}
1211
13−VAL idris_b16CopyForGC(VM *vm, VAL a) {
14− uint16_t A = a->info.bits16;
15− VAL cl = allocate(sizeof(Closure), 1);
12+VAL idris_b16const(VM *vm, uint16_t a) {
13+ Bits16 * cl = iallocate(vm, sizeof(*cl), 0);
1614 SETTY(cl, CT_BITS16);
17− cl->info.bits16 = A;
18− return cl;
15+ cl->bits16 = a;
16+ return (VAL)cl;
1917}
2018
21−VAL idris_b32CopyForGC(VM *vm, VAL a) {
22− uint32_t A = a->info.bits32;
23− VAL cl = allocate(sizeof(Closure), 1);
19+VAL idris_b32const(VM *vm, uint32_t a) {
20+ Bits32 * cl = iallocate(vm, sizeof(*cl), 0);
2421 SETTY(cl, CT_BITS32);
25− cl->info.bits32 = A;
26− return cl;
22+ cl->bits32 = a;
23+ return (VAL)cl;
2724}
2825
29−VAL idris_b64CopyForGC(VM *vm, VAL a) {
30− uint64_t A = a->info.bits64;
31− VAL cl = allocate(sizeof(Closure), 1);
26+VAL idris_b64const(VM *vm, uint64_t a) {
27+ Bits64 * cl = iallocate(vm, sizeof(*cl), 0);
3228 SETTY(cl, CT_BITS64);
33− cl->info.bits64 = A;
34− return cl;
29+ cl->bits64 = a;
30+ return (VAL)cl;
3531}
3632
3733VAL 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;
34+ return idris_b8const(vm, GETINT(a));
4335}
4436
4537VAL 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;
38+ return idris_b16const(vm, GETINT(a));
5139}
5240
5341VAL 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;
42+ return idris_b32const(vm, GETINT(a));
5943}
6044
6145VAL 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;
46+ return idris_b64const(vm, GETINT(a));
6747}
6848
6949VAL 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;
50+ return MKINT(GETBITS32(a));
9951}
10052
10153VAL 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;
54+ uint8_t A = GETBITS8(a);
55+ uint8_t B = GETBITS8(b);
56+ return idris_b8const(vm, A + B);
10857}
10958
11059VAL 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;
60+ uint8_t A = GETBITS8(a);
61+ uint8_t B = GETBITS8(b);
62+ return idris_b8const(vm, A - B);
11763}
11864
11965VAL 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;
66+ uint8_t A = GETBITS8(a);
67+ uint8_t B = GETBITS8(b);
68+ return idris_b8const(vm, A * B);
12669}
12770
12871VAL 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;
72+ uint8_t A = GETBITS8(a);
73+ uint8_t B = GETBITS8(b);
74+ return idris_b8const(vm, A / B);
13575}
13676
13777VAL 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;
78+ int8_t A = GETBITS8(a);
79+ int8_t B = GETBITS8(b);
80+ return idris_b8const(vm, A / B);
14481}
14582
14683VAL 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;
84+ uint8_t A = GETBITS8(a);
85+ uint8_t B = GETBITS8(b);
86+ return idris_b8const(vm, A % B);
15387}
15488
15589VAL 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;
90+ int8_t A = GETBITS8(a);
91+ int8_t B = GETBITS8(b);
92+ return idris_b8const(vm, A % B);
16293}
16394
16495VAL idris_b8Lt(VM *vm, VAL a, VAL b) {
165− return MKINT((i_int) (a->info.bits8 < b->info.bits8));
96+ return MKINT((i_int) (GETBITS8(a) < GETBITS8(b)));
16697}
16798
16899VAL idris_b8Gt(VM *vm, VAL a, VAL b) {
169− return MKINT((i_int) (a->info.bits8 > b->info.bits8));
100+ return MKINT((i_int) (GETBITS8(a) > GETBITS8(b)));
170101}
171102
172103VAL idris_b8Eq(VM *vm, VAL a, VAL b) {
173− return MKINT((i_int) (a->info.bits8 == b->info.bits8));
104+ return MKINT((i_int) (GETBITS8(a) == GETBITS8(b)));
174105}
175106
176107VAL idris_b8Lte(VM *vm, VAL a, VAL b) {
177− return MKINT((i_int) (a->info.bits8 <= b->info.bits8));
108+ return MKINT((i_int) (GETBITS8(a) <= GETBITS8(b)));
178109}
179110
180111VAL idris_b8Gte(VM *vm, VAL a, VAL b) {
181− return MKINT((i_int) (a->info.bits8 >= b->info.bits8));
112+ return MKINT((i_int) (GETBITS8(a) >= GETBITS8(b)));
182113}
183114
184115VAL 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;
116+ uint8_t A = GETBITS8(a);
117+ return idris_b8const(vm, ~ A);
190118}
191119
192120VAL 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;
121+ uint8_t A = GETBITS8(a);
122+ uint8_t B = GETBITS8(b);
123+ return idris_b8const(vm, A & B);
199124}
200125
201126VAL 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;
127+ uint8_t A = GETBITS8(a);
128+ uint8_t B = GETBITS8(b);
129+ return idris_b8const(vm, A | B);
208130}
209131
210132VAL 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;
133+ uint8_t A = GETBITS8(a);
134+ uint8_t B = GETBITS8(b);
135+ return idris_b8const(vm, A ^ B);
217136}
218137
219138VAL 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;
139+ uint8_t A = GETBITS8(a);
140+ uint8_t B = GETBITS8(b);
141+ return idris_b8const(vm, A << B);
226142}
227143
228144VAL 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;
145+ uint8_t A = GETBITS8(a);
146+ uint8_t B = GETBITS8(b);
147+ return idris_b8const(vm, A >> B);
235148}
236149
237150VAL 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;
151+ int8_t A = GETBITS8(a);
152+ int8_t B = GETBITS8(b);
153+ return idris_b8const(vm, A >> B);
244154}
245155
246156VAL 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;
157+ uint16_t A = GETBITS16(a);
158+ uint16_t B = GETBITS16(b);
159+ return idris_b16const(vm, A + B);
253160}
254161
255162VAL 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;
163+ uint16_t A = GETBITS16(a);
164+ uint16_t B = GETBITS16(b);
165+ return idris_b16const(vm, A - B);
262166}
263167
264168VAL 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;
169+ uint16_t A = GETBITS16(a);
170+ uint16_t B = GETBITS16(b);
171+ return idris_b16const(vm, A * B);
271172}
272173
273174VAL 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;
175+ uint16_t A = GETBITS16(a);
176+ uint16_t B = GETBITS16(b);
177+ return idris_b16const(vm, A / B);
280178}
281179
282180VAL 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;
181+ int16_t A = GETBITS16(a);
182+ int16_t B = GETBITS16(b);
183+ return idris_b16const(vm, A / B);
289184}
290185
291186VAL 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;
187+ uint16_t A = GETBITS16(a);
188+ uint16_t B = GETBITS16(b);
189+ return idris_b16const(vm, A % B);
298190}
299191
300192VAL 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;
193+ int16_t A = GETBITS16(a);
194+ int16_t B = GETBITS16(b);
195+ return idris_b16const(vm, A % B);
307196}
308197
309198VAL idris_b16Lt(VM *vm, VAL a, VAL b) {
310− return MKINT((i_int) (a->info.bits16 < b->info.bits16));
199+ return MKINT((i_int) (GETBITS16(a) < GETBITS16(b)));
311200}
312201
313202VAL idris_b16Gt(VM *vm, VAL a, VAL b) {
314− return MKINT((i_int) (a->info.bits16 > b->info.bits16));
203+ return MKINT((i_int) (GETBITS16(a) > GETBITS16(b)));
315204}
316205
317206VAL idris_b16Eq(VM *vm, VAL a, VAL b) {
318− return MKINT((i_int) (a->info.bits16 == b->info.bits16));
207+ return MKINT((i_int) (GETBITS16(a) == GETBITS16(b)));
319208}
320209
321210VAL idris_b16Lte(VM *vm, VAL a, VAL b) {
322− return MKINT((i_int) (a->info.bits16 <= b->info.bits16));
211+ return MKINT((i_int) (GETBITS16(a) <= GETBITS16(b)));
323212}
324213
325214VAL idris_b16Gte(VM *vm, VAL a, VAL b) {
326− return MKINT((i_int) (a->info.bits16 >= b->info.bits16));
215+ return MKINT((i_int) (GETBITS16(a) >= GETBITS16(b)));
327216}
328217
329218VAL 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;
219+ uint16_t A = GETBITS16(a);
220+ return idris_b16const(vm, ~ A);
335221}
336222
337223VAL 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;
224+ uint16_t A = GETBITS16(a);
225+ uint16_t B = GETBITS16(b);
226+ return idris_b16const(vm, A & B);
344227}
345228
346229VAL 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;
230+ uint16_t A = GETBITS16(a);
231+ uint16_t B = GETBITS16(b);
232+ return idris_b16const(vm, A | B);
353233}
354234
355235VAL 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;
236+ uint16_t A = GETBITS16(a);
237+ uint16_t B = GETBITS16(b);
238+ return idris_b16const(vm, A ^ B);
362239}
363240
364241VAL 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;
242+ uint16_t A = GETBITS16(a);
243+ uint16_t B = GETBITS16(b);
244+ return idris_b16const(vm, A << B);
371245}
372246
373247VAL 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;
248+ uint16_t A = GETBITS16(a);
249+ uint16_t B = GETBITS16(b);
250+ return idris_b16const(vm, A >> B);
380251}
381252
382253VAL 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;
254+ int16_t A = GETBITS16(a);
255+ int16_t B = GETBITS16(b);
256+ return idris_b16const(vm, A >> B);
389257}
390258
391259VAL 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;
260+ uint32_t A = GETBITS32(a);
261+ uint32_t B = GETBITS32(b);
262+ return idris_b32const(vm, A + B);
398263}
399264
400265VAL 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;
266+ uint32_t A = GETBITS32(a);
267+ uint32_t B = GETBITS32(b);
268+ return idris_b32const(vm, A - B);
407269}
408270
409271VAL 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;
272+ uint32_t A = GETBITS32(a);
273+ uint32_t B = GETBITS32(b);
274+ return idris_b32const(vm, A * B);
416275}
417276
418277VAL 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;
278+ uint32_t A = GETBITS32(a);
279+ uint32_t B = GETBITS32(b);
280+ return idris_b32const(vm, A / B);
425281}
426282
427283VAL 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;
284+ int32_t A = GETBITS32(a);
285+ int32_t B = GETBITS32(b);
286+ return idris_b32const(vm, A / B);
434287}
435288
436289VAL 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;
290+ uint32_t A = GETBITS32(a);
291+ uint32_t B = GETBITS32(b);
292+ return idris_b32const(vm, A % B);
443293}
444294
445295VAL 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;
296+ int32_t A = GETBITS32(a);
297+ int32_t B = GETBITS32(b);
298+ return idris_b32const(vm, A % B);
452299}
453300
454301VAL idris_b32Lt(VM *vm, VAL a, VAL b) {
455− return MKINT((i_int) (a->info.bits32 < b->info.bits32));
302+ return MKINT((i_int) (GETBITS32(a) < GETBITS32(b)));
456303}
457304
458305VAL idris_b32Gt(VM *vm, VAL a, VAL b) {
459− return MKINT((i_int) (a->info.bits32 > b->info.bits32));
306+ return MKINT((i_int) (GETBITS32(a) > GETBITS32(b)));
460307}
461308
462309VAL idris_b32Eq(VM *vm, VAL a, VAL b) {
463− return MKINT((i_int) (a->info.bits32 == b->info.bits32));
310+ return MKINT((i_int) (GETBITS32(a) == GETBITS32(b)));
464311}
465312
466313VAL idris_b32Lte(VM *vm, VAL a, VAL b) {
467− return MKINT((i_int) (a->info.bits32 <= b->info.bits32));
314+ return MKINT((i_int) (GETBITS32(a) <= GETBITS32(b)));
468315}
469316
470317VAL idris_b32Gte(VM *vm, VAL a, VAL b) {
471− return MKINT((i_int) (a->info.bits32 >= b->info.bits32));
318+ return MKINT((i_int) (GETBITS32(a) >= GETBITS32(b)));
472319}
473320
474321VAL 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;
322+ uint32_t A = GETBITS32(a);
323+ return idris_b32const(vm, ~ A);
480324}
481325
482326VAL 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;
327+ uint32_t A = GETBITS32(a);
328+ uint32_t B = GETBITS32(b);
329+ return idris_b32const(vm, A & B);
489330}
490331
491332VAL 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;
333+ uint32_t A = GETBITS32(a);
334+ uint32_t B = GETBITS32(b);
335+ return idris_b32const(vm, A | B);
498336}
499337
500338VAL 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;
339+ uint32_t A = GETBITS32(a);
340+ uint32_t B = GETBITS32(b);
341+ return idris_b32const(vm, A ^ B);
507342}
508343
509344VAL 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;
345+ uint32_t A = GETBITS32(a);
346+ uint32_t B = GETBITS32(b);
347+ return idris_b32const(vm, A << B);
516348}
517349
518350VAL 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;
351+ uint32_t A = GETBITS32(a);
352+ uint32_t B = GETBITS32(b);
353+ return idris_b32const(vm, A >> B);
525354}
526355
527356VAL 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;
357+ int32_t A = GETBITS32(a);
358+ int32_t B = GETBITS32(b);
359+ return idris_b32const(vm, A >> B);
534360}
535361
536362VAL 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;
363+ uint64_t A = GETBITS64(a);
364+ uint64_t B = GETBITS64(b);
365+ return idris_b64const(vm, A + B);
543366}
544367
545368VAL 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;
369+ uint64_t A = GETBITS64(a);
370+ uint64_t B = GETBITS64(b);
371+ return idris_b64const(vm, A - B);
552372}
553373
554374VAL 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;
375+ uint64_t A = GETBITS64(a);
376+ uint64_t B = GETBITS64(b);
377+ return idris_b64const(vm, A * B);
561378}
562379
563380VAL 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;
381+ uint64_t A = GETBITS64(a);
382+ uint64_t B = GETBITS64(b);
383+ return idris_b64const(vm, A / B);
570384}
571385
572386VAL 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;
387+ int64_t A = GETBITS64(a);
388+ int64_t B = GETBITS64(b);
389+ return idris_b64const(vm, A / B);
579390}
580391
581392VAL 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;
393+ uint64_t A = GETBITS64(a);
394+ uint64_t B = GETBITS64(b);
395+ return idris_b64const(vm, A % B);
588396}
589397
590398VAL 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;
399+ int64_t A = GETBITS64(a);
400+ int64_t B = GETBITS64(b);
401+ return idris_b64const(vm, A % B);
597402}
598403
599404VAL idris_b64Lt(VM *vm, VAL a, VAL b) {
600− 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));
601408}
602409
603410VAL idris_b64Gt(VM *vm, VAL a, VAL b) {
604− 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));
605414}
606415
607416VAL idris_b64Eq(VM *vm, VAL a, VAL b) {
608− 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));
609420}
610421
611422VAL idris_b64Lte(VM *vm, VAL a, VAL b) {
612− 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));
613426}
614427
615428VAL idris_b64Gte(VM *vm, VAL a, VAL b) {
616− return MKINT((i_int) (a->info.bits64 >= b->info.bits64));
429+ uint64_t A = GETBITS64(a);
430+ uint64_t B = GETBITS64(b);
431+ return MKINT((i_int) (A >= B));
617432}
618433
619434VAL 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;
435+ uint64_t A = GETBITS64(a);
436+ return idris_b64const(vm, ~ A);
625437}
626438
627439VAL 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;
440+ uint64_t A = GETBITS64(a);
441+ uint64_t B = GETBITS64(b);
442+ return idris_b64const(vm, A & B);
634443}
635444
636445VAL 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;
446+ uint64_t A = GETBITS64(a);
447+ uint64_t B = GETBITS64(b);
448+ return idris_b64const(vm, A | B);
643449}
644450
645451VAL 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;
452+ uint64_t A = GETBITS64(a);
453+ uint64_t B = GETBITS64(b);
454+ return idris_b64const(vm, A ^ B);
652455}
653456
654457VAL 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;
458+ uint64_t A = GETBITS64(a);
459+ uint64_t B = GETBITS64(b);
460+ return idris_b64const(vm, A << B);
661461}
662462
663463VAL 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;
464+ uint64_t A = GETBITS64(a);
465+ uint64_t B = GETBITS64(b);
466+ return idris_b64const(vm, A >> B);
670467}
671468
672469VAL 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;
470+ int64_t A = GETBITS64(a);
471+ int64_t B = GETBITS64(b);
472+ return idris_b64const(vm, A >> B);
679473}
680474
681475VAL 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;
476+ uint8_t A = GETBITS8(a);
477+ return idris_b16const(vm, A);
687478}
688479
689480VAL 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;
481+ uint8_t A = GETBITS8(a);
482+ return idris_b32const(vm, A);
695483}
696484
697485VAL 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;
486+ uint8_t A = GETBITS8(a);
487+ return idris_b64const(vm, A);
703488}
704489
705490VAL 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;
491+ int8_t A = GETBITS8(a);
492+ return idris_b16const(vm, (int16_t) A);
711493}
712494
713495VAL 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;
496+ int8_t A = GETBITS8(a);
497+ return idris_b32const(vm, (int32_t) A);
719498}
720499
721500VAL 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;
501+ int8_t A = GETBITS8(a);
502+ return idris_b64const(vm, (int64_t) A);
727503}
728504
729505VAL 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;
506+ uint16_t A = GETBITS16(a);
507+ return idris_b32const(vm, (uint32_t) A);
735508}
736509
737510VAL 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;
511+ uint16_t A = GETBITS16(a);
512+ return idris_b64const(vm, (uint64_t) A);
743513}
744514
745515VAL 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;
516+ int16_t A = GETBITS16(a);
517+ return idris_b32const(vm, (int32_t) A);
751518}
752519
753520VAL 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;
521+ int16_t A = GETBITS16(a);
522+ return idris_b64const(vm, (int64_t) A);
759523}
760524
761525VAL 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;
526+ uint16_t A = GETBITS16(a);
527+ return idris_b8const(vm, (uint8_t) A);
767528}
768529
769530VAL 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;
531+ uint32_t A = GETBITS32(a);
532+ return idris_b64const(vm, (uint64_t) A);
775533}
776534
777535VAL 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;
536+ int32_t A = GETBITS32(a);
537+ return idris_b64const(vm, (int64_t) A);
783538}
784539
785540VAL 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;
541+ uint32_t A = GETBITS32(a);
542+ return idris_b8const(vm, (uint8_t) A);
791543}
792544
793545VAL 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;
546+ uint32_t A = GETBITS32(a);
547+ return idris_b16const(vm, (uint16_t) A);
799548}
800549
801550VAL 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;
551+ uint64_t A = GETBITS64(a);
552+ return idris_b8const(vm, (uint8_t) A);
807553}
808554
809555VAL 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;
556+ uint64_t A = GETBITS64(a);
557+ return idris_b16const(vm, (uint16_t) A);
815558}
816559
817560VAL 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;
561+ uint64_t A = GETBITS64(a);
562+ return idris_b32const(vm, (uint32_t) A);
823563}
824564
825565VAL idris_peekB8(VM* vm, VAL ptr, VAL offset) {