raz / test / run / Data.raz

73 lines · 2.0 KiB · raw · history · last change 264716cb

1module Data;
2import Out;
3import SYSTEM;
4
5type
6 Cell = record ch: U8; attr: U8; end;
7 Mixed = record a: U8; b: I64; c: U16; end;
8 Packed = packed record a: U8; b: I64; c: U16; end;
9 Node = record next: ^Node; val: I64; end;
10 Grid = [3][4]I32;
11 Pair = record x, y: I64; end;
12
13var
14 nodes: [5]Node;
15 grid: Grid;
16 gp: Pair;
17
18proc sum(p: ^Node): I64;
19var s: I64;
20begin
21 s := 0;
22 while p # nil do
23 s := s + p^.val;
24 p := p^.next;
25 end;
26 return s;
27end;
28
29proc main*;
30var
31 c: Cell; cells: [4]Cell; m: Mixed; i, j: I64; p, q: ^I64; arr: [8]I64;
32 s: []I64; pp: Pair; bp: ^U8;
33begin
34 Out.int(SIZE(Cell)); Out.str(" ");
35 Out.int(SIZE(Mixed)); Out.str(" ");
36 Out.int(SIZE(Packed)); Out.str(" ");
37 Out.int(SIZE(Grid)); Out.str(" ");
38 Out.int(SIZE([]U8)); Out.ln;
39 c.ch := 'x'; c.attr := 7;
40 cells[2] := c;
41 Out.int(I64(cells[2].ch)); Out.str(" "); Out.int(I64(cells[2].attr)); Out.ln;
42 for i := 0 to 4 do
43 nodes[i].val := i * i;
44 if i < 4 then nodes[i].next := SYSTEM.ADR(nodes[i + 1]); end;
45 end;
46 Out.int(sum(SYSTEM.ADR(nodes[0]))); Out.ln;
47 for i := 0 to 2 do
48 for j := 0 to 3 do grid[i][j] := I32(i * 10 + j); end;
49 end;
50 Out.int(I64(grid[2][3])); Out.str(" "); Out.int(I64(grid[1][0])); Out.ln;
51 for i := 0 to 7 do arr[i] := i * 100; end;
52 p := SYSTEM.ADR(arr[0]);
53 q := p + 5;
54 Out.int(q^); Out.str(" "); Out.int(q - p); Out.str(" "); Out.int(p[3]); Out.ln;
55 s := arr[2..6];
56 Out.int(LEN(s)); Out.str(" "); Out.int(s[0]); Out.str(" "); Out.int(s[3]); Out.ln;
57 s := s[1..3];
58 Out.int(LEN(s)); Out.str(" "); Out.int(s[0]); Out.ln;
59 s := p[1..3];
60 Out.int(s[1]); Out.ln;
61 s := arr;
62 Out.int(LEN(s)); Out.ln;
63 pp.x := 3; pp.y := 4;
64 gp := pp;
65 pp.x := 99;
66 Out.int(gp.x); Out.str(" "); Out.int(gp.y); Out.ln;
67 m.a := 1; m.b := -2; m.c := 65535;
68 Out.int(m.b); Out.str(" "); Out.int(I64(m.c)); Out.ln;
69 bp := ^U8(SYSTEM.ADR(m));
70 Out.int(INT(SYSTEM.ADR(m.c)) - INT(bp)); Out.ln;
71end;
72
73end Data.