| 1 | (* A parameter passed by its address (var, const) that comes on the |
| 2 | stack, past the six registers, and is kept in a register because a |
| 3 | loop reads it: it holds the address, 8 bytes, whatever its type. It |
| 4 | was loaded as its type's value, a var BOOL as one byte, and the |
| 5 | first read through it stopped the program on a bad pointer. *) |
| 6 | module VarOnStack; |
| 7 | import Out; |
| 8 | |
| 9 | type |
| 10 | Pair = record |
| 11 | a, b: INT; |
| 12 | end; |
| 13 | |
| 14 | (* Six words fill the registers; flag, x, n and p come on the stack. *) |
| 15 | proc f(a, b, c, d, e, g: INT; var flag: BOOL; var x: F64; var n: INT; const p: Pair); |
| 16 | var i: INT; |
| 17 | begin |
| 18 | for i := 1 to 3 do |
| 19 | if not flag then flag := true; end; |
| 20 | x := x + 0.5; |
| 21 | n := n + p.a + p.b + a + b + c + d + e + g; |
| 22 | end; |
| 23 | end; |
| 24 | |
| 25 | proc main*; |
| 26 | var flag: BOOL; x: F64; n: INT; p: Pair; |
| 27 | begin |
| 28 | p := {a: 10, b: 20}; |
| 29 | f(1, 2, 3, 4, 5, 6, flag, x, n, p); |
| 30 | if flag then Out.str("flag set\n"); end; |
| 31 | if x = 1.5 then Out.str("x is 1.5\n"); end; |
| 32 | Out.int(n); |
| 33 | Out.ln; |
| 34 | end; |
| 35 | |
| 36 | end VarOnStack. |