raz / conform / run / SystemInt.raz

75 lines · 2.0 KiB · raw · history · last change 264716cb

1module SystemInt;
2(* INT and UINT: what gives them, where they widen, shifts modulo the
3 width, and another module's variables read but not changed *)
4import Out, Shared;
5import SYSTEM;
6
7var cells: [10]I32;
8
9proc wide(x: I64): I64;
10begin
11 return x + 1;
12end;
13
14(* an INT returned as an I64 *)
15proc len(s: []const U8): I64;
16begin
17 return LEN(s);
18end;
19
20proc main*;
21var
22 n: INT; i: I64; u: UINT; w: U64; b: U8; h: I32; k: INT;
23 p, q: ^I32; copy: [3]INT;
24begin
25 n := LEN("four"); (* untyped, so it fits any integer *)
26 b := SIZE(I64);
27 i := n; (* INT into I64 *)
28 i := wide(n);
29 u := 7;
30 w := u; (* UINT into U64 *)
31 Out.int(i); Out.str(" "); Out.int(I64(b)); Out.str(" "); Out.int(len("abc"));
32 Out.str(" "); Out.int(I64(w)); Out.ln;
33
34 p := SYSTEM.ADR(cells[2]);
35 q := SYSTEM.ADR(cells[9]);
36 n := q - p; (* an INT *)
37 u := UINT(q) - UINT(p);
38 Out.int(n); Out.str(" "); Out.int(I64(u)); Out.str(" ");
39 Out.int(INT(^I32(INT(p) + 4) - p)); Out.ln;
40
41 (* a shift counts modulo the width of its operand's type *)
42 b := 3;
43 k := 9;
44 Out.int(I64(b shl k)); Out.str(" ");
45 h := -64;
46 k := 33;
47 Out.int(I64(h shr k)); Out.str(" ");
48 Out.int(I64(U8(3) shl 9)); Out.str(" ");
49 n := 1;
50 k := 65;
51 Out.int(n shl k); Out.ln;
52
53 (* an index of any integer type, by its value *)
54 cells[U8(3)] := 30;
55 cells[I8(4)] := 40;
56 Out.int(I64(cells[UINT(3)] + cells[U64(4)])); Out.ln;
57
58 Shared.bump;
59 Shared.bump;
60 copy := Shared.words;
61 copy[0] := 9; (* the importer's own copy *)
62 Shared.bytes[0] := 'x'; (* what the slice points at *)
63 match Shared.shape of
64 | circle(r): r := r + 1; Out.int(r); Out.str(" ");
65 | dot:
66 end;
67 match Shared.shape of
68 | circle(r): Out.int(r); Out.str(" ");
69 | dot:
70 end;
71 Out.int(Shared.count); Out.str(" "); Out.int(copy[0] + copy[1]); Out.str(" ");
72 Out.int(I64(Shared.bytes[0])); Out.ln;
73end;
74
75end SystemInt.