raz / test / run / VarOnStack.raz

36 lines · 1.0 KiB · raw · history · last change c9a30772

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. *)
6module VarOnStack;
7import Out;
8
9type
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. *)
15proc f(a, b, c, d, e, g: INT; var flag: BOOL; var x: F64; var n: INT; const p: Pair);
16var i: INT;
17begin
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;
23end;
24
25proc main*;
26var flag: BOOL; x: F64; n: INT; p: Pair;
27begin
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;
34end;
35
36end VarOnStack.