ref: 2c113e30f0892e015ae61ab8f453c9b3a073c73b
parent: 94fe38f0e0291527680dff7ebf7539929317621c
author: Ori Bernstein <ori@eigenstate.org>
date: Sat Jan 23 21:13:51 EST 2016
Fix prefix encoding for integers. Now we don't break with large types.
--- a/6/gengas.c
+++ b/6/gengas.c
@@ -288,7 +288,7 @@
break;
shift = 8 - i;
b = ~0ull << (shift + 1);
- b |= val & ((1 << (8 - shift)) - 1);
+ b |= val & ~(~0ull << shift);
fprintf(fd, "\t.byte %u\n", b);
val >>= shift;
while (val != 0) {
--- a/lib/std/introspect.myr
+++ b/lib/std/introspect.myr
@@ -368,11 +368,12 @@
}
const getipacked : (p : byte[:] -> (size, size)) = {p : byte[:]
- var mask, val, len, i
+ var mask, val, len, shift, i
mask = 0x80
val = 0
len = 1
+ shift = 8 - len
while p[0] & mask != mask << 1
len++
mask >>= 1
@@ -379,9 +380,10 @@
mask |= 0x80
;;
- val = (p[0] castto(size)) & ~(1 << (8 - len))
+ shift = 8 - len
+ val = (p[0] castto(std.size)) & ~(~0 << shift)
for i = 1; i < len; i++
- val |= (p[i] castto(size)) << (i*8 - len)
+ val |= (p[i] castto(std.size)) << (i*8 - len)
;;
-> (val, len)
}