diff options
Diffstat (limited to 'tests/programs/sized.zc')
| -rw-r--r-- | tests/programs/sized.zc | 67 |
1 files changed, 35 insertions, 32 deletions
diff --git a/tests/programs/sized.zc b/tests/programs/sized.zc index 0a18467..1be0b31 100644 --- a/tests/programs/sized.zc +++ b/tests/programs/sized.zc @@ -1,9 +1,12 @@ +namespace; +include rt, run; + // sized integers: scalars wrap to their size, arrays and pointers of them are packed -struct pix { u8 r, g, b, a; i16 dx; [4]u8 tag; }; +struct pix { u8 r, g, b, a; i16 dx; u8[4] tag; }; u8 gbyte = 300; i8 gneg = 200; u16 gword[5]; -[10]u8 gbuf; +u8[10] run.gbuf; u8 add8(u8 a, u8 b) { return a + b; } @@ -12,13 +15,13 @@ fn scalars() { i8 s = 100; i16 h = 32767; u32 w = 4294967295; - a = a + 10; put_n(a); put_c(' '); // 4 - s = s + 100; put_n(s); put_c(' '); // -56 - h++; put_n(h); put_c(' '); // -32768 - w++; put_n(w); put_c(' '); // 0 - put_n(gbyte); put_c(' '); put_n(gneg); put_c(' '); // 44 -56 - put_n(add8(200, 100)); put_c(' '); // 44 - put_n((i8)200); put_c(' '); put_n(300 as u8); put_c(10); // -56 44 + a = a + 10; rt.put_n(a); rt.put_c(' '); // 4 + s = s + 100; rt.put_n(s); rt.put_c(' '); // -56 + h++; rt.put_n(h); rt.put_c(' '); // -32768 + w++; rt.put_n(w); rt.put_c(' '); // 0 + rt.put_n(gbyte); rt.put_c(' '); rt.put_n(gneg); rt.put_c(' '); // 44 -56 + rt.put_n(add8(200, 100)); rt.put_c(' '); // 44 + rt.put_n((i8)200); rt.put_c(' '); rt.put_n(300 as u8); rt.put_c(10); // -56 44 return 0; } fn arrays() { @@ -29,36 +32,36 @@ fn arrays() { int i = 0, sum = 0; while (i < 20) { buf[i] = i * 20; i++; } // wraps past 255 i = 0; while (i < 20) { sum = sum + buf[i]; i++; } - put_n(sum); put_c(' '); // 1250 - sh[3] = 40000; put_n(sh[3]); put_c(' '); // -25536 - sh[3] += 30000; put_n(sh[3]); put_c(' '); // 4464 - ws[1] = 5000000000; put_n(ws[1]); put_c(' '); // 705032704 - sb[8] = 127; sb[8]++; put_n(sb[8]); put_c(' '); // -128 - sb[0] = 200; put_n(sb[0] < 0); put_c(' '); // 1: -56 is negative - ws[0] = 4000000000; put_n(ws[0] + ws[0]); put_c(' '); // arithmetic is done in int: 8000000000 - put_n(sizeof(buf)); put_c(' '); // 3 words - put_n(sizeof(sh)); put_c(10); // 2 words + rt.put_n(sum); rt.put_c(' '); // 1250 + sh[3] = 40000; rt.put_n(sh[3]); rt.put_c(' '); // -25536 + sh[3] += 30000; rt.put_n(sh[3]); rt.put_c(' '); // 4464 + ws[1] = 5000000000; rt.put_n(ws[1]); rt.put_c(' '); // 705032704 + sb[8] = 127; sb[8]++; rt.put_n(sb[8]); rt.put_c(' '); // -128 + sb[0] = 200; rt.put_n(sb[0] < 0); rt.put_c(' '); // 1: -56 is negative + ws[0] = 4000000000; rt.put_n(ws[0] + ws[0]); rt.put_c(' '); // arithmetic is done in int: 8000000000 + rt.put_n(sizeof(buf)); rt.put_c(' '); // 3 words + rt.put_n(sizeof(sh)); rt.put_c(10); // 2 words return 0; } fn heap() { - u8* p = new(u8, 1000); + u8* p = rt.new(u8, 1000); int i = 0, sum = 0; while (i < 1000) { p[i] = i; i++; } i = 0; while (i < 1000) { sum = sum + p[i]; i++; } - put_n(sum); put_c(' '); // 1000 bytes of 0..255: 3 * 32640 + 28 * ... = 127.. - put_n(osize(p) < 256); put_c(32); // 125 words plus the header, not 1000 - *p = 77; put_n(p[0]); put_c(' '); - free(d*p); - gbuf[9] = 255; gword[4] = 65535; gword[4]++; - put_n(gbuf[9]); put_c(' '); put_n(gword[4]); put_c(10); + rt.put_n(sum); rt.put_c(' '); // 1000 bytes of 0..255: 3 * 32640 + 28 * ... = 127.. + rt.put_n(rt.osize(p) < 256); rt.put_c(32); // 125 words plus the header, not 1000 + *p = 77; rt.put_n(p[0]); rt.put_c(' '); + rt.free(d*p); + run.gbuf[9] = 255; gword[4] = 65535; gword[4]++; + rt.put_n(run.gbuf[9]); rt.put_c(' '); rt.put_n(gword[4]); rt.put_c(10); return 0; } fn fields() { - pix* q = new(pix); + pix* q = rt.new(pix); q.r = 255; q.g = 256; q.dx = 65535; q.tag[2] = 7; q.tag[3] = 300; - put_n(q.r); put_c(' '); put_n(q.g); put_c(' '); put_n(q.dx); put_c(' '); - put_n(q.tag[2]); put_c(' '); put_n(q.tag[3]); put_c(' '); put_n(sizeof(pix)); put_c(10); - free(d*q); + rt.put_n(q.r); rt.put_c(' '); rt.put_n(q.g); rt.put_c(' '); rt.put_n(q.dx); rt.put_c(' '); + rt.put_n(q.tag[2]); rt.put_c(' '); rt.put_n(q.tag[3]); rt.put_c(' '); rt.put_n(sizeof(pix)); rt.put_c(10); + rt.free(d*q); return 0; } o3 fn checksum(u8* p, int n) { @@ -67,11 +70,11 @@ o3 fn checksum(u8* p, int n) { return b * 256 + a; } fn o3run() { - u8* p = new(u8, 5000); + u8* p = rt.new(u8, 5000); int i = 0; while (i < 5000) { p[i] = i * 7; i++; } - put_n(checksum(p, 5000)); put_c(10); - free(d*p); + rt.put_n(checksum(p, 5000)); rt.put_c(10); + rt.free(d*p); return 0; } fn main() { |
