raz / test / run / Results.raz

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

1module Results;
2import Out;
3import SYSTEM;
4
5const
6 NotFound*: ERROR = "not found";
7 Empty: ERROR = "empty";
8 Other: ERROR = "not found";
9
10type Pair = record a, b: I64; end;
11
12var table: [4]I64; g: Pair;
13
14proc divmod(a, b: I64): (I64, I64);
15begin
16 return a div b, a mod b;
17end;
18
19proc find(key: I64): (I64, ERROR);
20var i: I64;
21begin
22 for i := 0 to 3 do
23 if table[i] = key then return i, nil; end;
24 end;
25 return -1, NotFound;
26end;
27
28proc mixed(x: F64): (F64, []const U8, Pair, BOOL);
29var p: Pair;
30begin
31 p.a := 1; p.b := 2;
32 return x * 2.0, "two", p, true;
33end;
34
35proc minmax(a, b: I64): (I64, I64);
36code
37 mov rax, rdi;
38 mov rdx, rsi;
39 cmp rdi, rsi;
40 jle done;
41 mov rax, rsi;
42 mov rdx, rdi;
43 done:
44 ret;
45end minmax;
46
47proc nothing: (I64, ERROR);
48begin
49end;
50
51proc main*;
52var q, r, i: I64; e: ERROR; x: F64; s: []const U8; p: Pair; ok: BOOL; a: [3]I64; u: U8;
53begin
54 q, r := divmod(17, 5);
55 Out.int(q); Out.str(" "); Out.int(r); Out.ln;
56 table := [10, 20, 30, 40];
57 i, e := find(30);
58 Out.int(i); if e = nil then Out.str(" nil"); end; Out.ln;
59 i, e := find(7);
60 Out.int(i); Out.str(" "); Out.str(MSG(e));
61 if e = NotFound then Out.str(" is NotFound"); end;
62 if e # Other then Out.str(", not Other"); end;
63 if e # Empty then Out.str(", not Empty"); end;
64 Out.ln;
65 Out.str("["); Out.str(MSG(nil)); Out.str("]"); Out.ln;
66 x, s, p, ok := mixed(1.5);
67 Out.int(I64(x * 10.0)); Out.str(" "); Out.str(s); Out.str(" "); Out.int(p.b);
68 if ok then Out.str(" ok"); end; Out.ln;
69 a[1], g.b := divmod(9, 4);
70 Out.int(a[1]); Out.str(" "); Out.int(g.b); Out.ln;
71 q, r := minmax(9, 3);
72 Out.int(q); Out.int(r); Out.ln;
73 _, _ := divmod(1, 1);
74 i, e := nothing();
75 Out.int(i); if e = nil then Out.str(" zero"); end; Out.ln;
76 i := 5;
77 INC(i); INC(i, 10); DEC(i, 2);
78 a[2] := 7; DEC(a[2]);
79 u := 255; INC(u);
80 Out.int(i); Out.str(" "); Out.int(a[2]); Out.str(" "); Out.int(I64(u)); Out.ln;
81end;
82
83end Results.