raz / conform / run / IntWiden.raz

68 lines · 1.5 KiB · raw · history · last change 264716cb

1(* An INT widens to an I64, and a UINT to a U64, wherever its value
2 goes to one: in an expression, a relation, a for loop's bounds, the
3 step of INC and DEC, and several results passed on (report sections
4 5.10, 6.1 and 7.2). *)
5module IntWiden;
6import Out;
7
8proc two: (INT, INT);
9begin
10 return 3, 4;
11end;
12
13proc three: (INT, INT, INT);
14begin
15 return 5, 6, 7;
16end;
17
18(* passed on whole: two results come back in registers, three through
19 memory *)
20proc twoWide: (I64, I64);
21begin
22 return two();
23end;
24
25proc threeWide: (I64, I64, I64);
26begin
27 return three();
28end;
29
30proc show(label: []const U8; v: I64);
31begin
32 Out.str(label); Out.str(" "); Out.int(v); Out.str("\n");
33end;
34
35proc main*;
36var
37 a, b, c, i: I64; n: INT; s: []const U8; u: U64; w: UINT;
38begin
39 s := "hello";
40 n := -2;
41 a := 10;
42 show("a + n", a + n);
43 show("n * a", n * a);
44 show("5 + (a - n)", 5 + (a - n));
45 show("a + LEN(s)", a + LEN(s));
46 show("n * n + a", n * n + a);
47 if n < a then Out.str("n < a\n"); end;
48 if LEN(s) = a - 5 then Out.str("LEN(s) = a - 5\n"); end;
49 c := 0;
50 for i := 0 to LEN(s) - 1 do c := c + i; end;
51 show("sum of 0 to LEN(s) - 1", c);
52 INC(a, LEN(s));
53 DEC(a, n);
54 show("a after INC and DEC", a);
55 a, b := two();
56 show("a, b := two()", a * 10 + b);
57 a, b := twoWide();
58 show("twoWide", a * 10 + b);
59 a, b, c := threeWide();
60 show("threeWide", a * 100 + b * 10 + c);
61 w := 7;
62 u := 0FFFFFFFFFFFFFFFFH;
63 u := u + w; (* wraps around, as U64 does *)
64 Out.hex(u, 16); Out.str("\n");
65 if w > u then Out.str("w > u\n"); end;
66end;
67
68end IntWiden.