raz / conform / run / Arith.raz

74 lines · 1.6 KiB · raw · history · last change 264716cb

1module Arith;
2import Out;
3
4const
5 K = 10;
6 M = K * 3 + 2;
7 Big = 0FFFFFFFFFFFFFFFFH;
8
9var g: I64;
10
11proc show(s: []const U8; n: I64);
12begin
13 Out.str(s); Out.str(" "); Out.int(n); Out.ln;
14end;
15
16proc showb(s: []const U8; t: BOOL);
17begin
18 if t then show(s, 1); else show(s, 0); end;
19end;
20
21proc main*;
22var a, b: I64; u: U8; i8: I8; w: U32; x: U64; r: F64; t: BOOL;
23begin
24 show("M", M);
25 a := 17; b := 5;
26 show("add", a + b);
27 show("sub", a - b);
28 show("mul", a * b);
29 show("div", -7 div 2);
30 show("mod", -7 mod 2);
31 show("divv", (0 - a) div b);
32 show("modv", (0 - a) mod b);
33 show("prec", 2 + 3 * 4);
34 show("neg", -a * b);
35 u := 200;
36 u := u + 100;
37 show("u8wrap", I64(u));
38 i8 := 127;
39 i8 := i8 + 1;
40 show("i8wrap", I64(i8));
41 w := 0FFFFFFFFH;
42 w := w + 2;
43 show("u32wrap", I64(w));
44 x := Big;
45 showb("u64>i", x > 5);
46 showb("i64<", -1 < 5);
47 show("shl", 1 shl 10);
48 show("shr", -16 shr 2);
49 show("ushr", I64(U64(-16) shr 60));
50 show("and", 12 & 10);
51 show("or", 12 | 3);
52 show("xor", 12 xor 10);
53 show("not", ~0);
54 r := F64(a) / 2.0;
55 show("real", I64(r * 10.0));
56 r := -2.75;
57 show("trunc", I64(r));
58 showb("nan", 0.0 / 0.0 = 0.0 / 0.0);
59 showb("rlt", 1.5 < 2.5);
60 show("u64real", I64(F64(x) / 1.0E18));
61 t := (a > 3) and (b < 3);
62 if not t then show("bool", 1); end;
63 t := (a > 3) or (g div 0 = 1);
64 if t then show("shortcut", 1); end;
65 g := 42;
66 show("global", g);
67 show("char", 'A');
68 show("utf8", 'é');
69 show("hexconst", 0FFH);
70 show("cut", I64(U8(300)));
71 show("sext", I64(I8(U8(255))));
72end;
73
74end Arith.