raz / conform / run / Kinds.raz

95 lines · 2.3 KiB · raw · history · last change 264716cb

1module Kinds;
2import Out;
3
4type
5 Color* = (red, green, blue, black);
6 Colors* = set of Color;
7 Cell = record ch: U8; attr: U8; fg: Color; end;
8 Point = record x, y: I64; name: []const U8; end;
9 Line = record a, b: Point; end;
10
11var log: [8]U8; nlog: I64;
12
13proc note(c: U8);
14begin
15 log[nlog] := c;
16 INC(nlog);
17end;
18
19proc show(s: Colors);
20var c: Color;
21begin
22 for c := red to black do
23 if c in s then Out.int(I64(c)); end;
24 end;
25 Out.str(" ");
26end;
27
28proc name(c: Color): []const U8;
29begin
30 match c of
31 | red: return "red";
32 | green: return "green";
33 | else: return "other";
34 end;
35end;
36
37proc deferred(n: I64): I64;
38var i: I64;
39begin
40 defer note('A');
41 defer note('B');
42 for i := 1 to 3 do
43 defer note('L');
44 if i = 2 then break; end;
45 end;
46 if n > 0 then
47 defer note('C');
48 return n * 10;
49 end;
50 note('D');
51 return -1;
52end;
53
54proc mid(a, b: Point): Point;
55begin
56 return {x: (a.x + b.x) div 2, y: (a.y + b.y) div 2, name: "mid"};
57end;
58
59proc main*;
60var s, t: Colors; c: Color; cell: Cell; p: Point; l: Line; r: I64; one: Colors;
61begin
62 s := {red, blue};
63 t := {blue, black};
64 show(s + t); show(s * t); show(s - t); show({});
65 if red in s then Out.str("in "); end;
66 if not (green in s) then Out.str("out "); end;
67 if s * t <= t then Out.str("sub "); end;
68 if s + t >= s then Out.str("sup "); end;
69 if s # t then Out.str("ne "); end;
70 if s = {blue, red} then Out.str("eq"); end;
71 Out.ln;
72 c := green;
73 one := {c, black};
74 show(one);
75 Out.int(I64(U8(one))); Out.str(" ");
76 Out.int(SIZE(Colors)); Out.str(" ");
77 Out.int(I64(Color(2))); Out.str(" ");
78 if c < blue then Out.str("lt "); end;
79 Out.str(name(c)); Out.str(" "); Out.str(name(black)); Out.ln;
80 cell := {ch: 'x', fg: blue};
81 Out.int(I64(cell.ch)); Out.str(" "); Out.int(I64(cell.attr)); Out.str(" "); Out.int(I64(cell.fg)); Out.ln;
82 p := mid({x: 2, y: 4}, {y: 10, x: 6});
83 Out.int(p.x); Out.int(p.y); Out.str(p.name); Out.ln;
84 l := {a: {x: 1, y: 2}, b: p};
85 Out.int(l.a.y); Out.int(l.b.x); Out.ln;
86 r := deferred(5);
87 Out.int(r); Out.str(" "); Out.str(log[0..nlog]); Out.ln;
88 nlog := 0;
89 r := deferred(0);
90 Out.int(r); Out.str(" "); Out.str(log[0..nlog]); Out.ln;
91 Out.int(I64(Color(I64(c) + 2)));
92 c := Color(nlog);
93end;
94
95end Kinds.