| 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). *) |
| 5 | module IntWiden; |
| 6 | import Out; |
| 7 | |
| 8 | proc two: (INT, INT); |
| 9 | begin |
| 10 | return 3, 4; |
| 11 | end; |
| 12 | |
| 13 | proc three: (INT, INT, INT); |
| 14 | begin |
| 15 | return 5, 6, 7; |
| 16 | end; |
| 17 | |
| 18 | (* passed on whole: two results come back in registers, three through |
| 19 | memory *) |
| 20 | proc twoWide: (I64, I64); |
| 21 | begin |
| 22 | return two(); |
| 23 | end; |
| 24 | |
| 25 | proc threeWide: (I64, I64, I64); |
| 26 | begin |
| 27 | return three(); |
| 28 | end; |
| 29 | |
| 30 | proc show(label: []const U8; v: I64); |
| 31 | begin |
| 32 | Out.str(label); Out.str(" "); Out.int(v); Out.str("\n"); |
| 33 | end; |
| 34 | |
| 35 | proc main*; |
| 36 | var |
| 37 | a, b, c, i: I64; n: INT; s: []const U8; u: U64; w: UINT; |
| 38 | begin |
| 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; |
| 66 | end; |
| 67 | |
| 68 | end IntWiden. |