raz / conform / run / ZeroStart.raz

69 lines · 1.9 KiB · raw · history · last change 264716cb

1(* Every variable starts at zero: a module's, and a procedure's even
2 where the stack held other values before. *)
3module ZeroStart;
4import Out;
5
6type
7 Colour = (red, green, blue);
8 Flags = set of Colour;
9 Rec = record n: I64; ok: BOOL; p: ^Rec; end;
10 Shape = variant first(x: I64); second(y: I64); end;
11
12var
13 n: I64; u: U8; ok: BOOL; p: ^Rec; f: proc; e: ERROR; s: []const U8;
14 c: Colour; fl: Flags; r: Rec; a: [3]I64; v: Shape;
15
16proc line(name: []const U8; zero: BOOL);
17begin
18 Out.str(name);
19 if zero then Out.str(" zero"); else Out.str(" NOT ZERO"); end;
20 Out.ln;
21end;
22
23proc which(name: []const U8; v: Shape);
24begin
25 Out.str(name);
26 match v of
27 | first(x): Out.str(" first "); Out.int(x);
28 | second(y): Out.str(" second "); Out.int(y);
29 end;
30 Out.ln;
31end;
32
33(* leaves its frame full of other values *)
34proc dirty;
35var pad: [64]I64; i: INT;
36begin
37 for i := 0 to 63 do pad[i] := 7; end;
38end;
39
40proc locals;
41var
42 n: I64; u: U8; ok: BOOL; p: ^Rec; f: proc; e: ERROR; s: []const U8;
43 c: Colour; fl: Flags; r: Rec; a: [3]I64; v: Shape;
44begin
45 line("local number", (n = 0) and (u = 0));
46 line("local bool", not ok);
47 line("local pointers", (p = nil) and (f = nil) and (e = nil));
48 line("local slice", LEN(s) = 0);
49 line("local enumeration and set", (c = red) and not (red in fl) and not (blue in fl));
50 line("local record", (r.n = 0) and not r.ok and (r.p = nil));
51 line("local array", (a[0] = 0) and (a[1] = 0) and (a[2] = 0));
52 which("local variant", v);
53end;
54
55proc main*;
56begin
57 line("number", (n = 0) and (u = 0));
58 line("bool", not ok);
59 line("pointers", (p = nil) and (f = nil) and (e = nil));
60 line("slice", LEN(s) = 0);
61 line("enumeration and set", (c = red) and not (red in fl) and not (blue in fl));
62 line("record", (r.n = 0) and not r.ok and (r.p = nil));
63 line("array", (a[0] = 0) and (a[1] = 0) and (a[2] = 0));
64 which("variant", v);
65 dirty;
66 locals;
67end;
68
69end ZeroStart.