raz / conform / run / ArrayConstLen.raz

46 lines · 1.3 KiB · raw · history · last change 264716cb

1module ArrayConstLen;
2import Out, Widths;
3
4type Rule = record class: []const U8; tag: INT; end;
5
6const
7 Primes: []const I64 = [2, 3, 5, 7, 11];
8 Rules: []const Rule = [{class: "firefox", tag: 2}, {class: "mpv", tag: 3}];
9 Names: []const []const U8 = ["one", "two", "three"];
10 Count = LEN(Primes); (* a constant *)
11
12var buf: [Count]I64;
13
14proc sum(a: []const I64): I64;
15var s: I64; i: INT;
16begin
17 for i := 0 to LEN(a) - 1 do s := s + a[i]; end;
18 return s;
19end;
20
21proc wide(c: I32): BOOL;
22var i: INT;
23begin
24 for i := 0 to LEN(Widths.Wide) - 1 do
25 if (c >= Widths.Wide[i][0]) and (c <= Widths.Wide[i][1]) then return true; end;
26 end;
27 return false;
28end;
29
30proc main*;
31const Local: []const U8 = [1, 2, 3, 4];
32var i: INT;
33begin
34 Out.int(LEN(Primes)); Out.str(" "); Out.int(sum(Primes)); Out.str(" ");
35 Out.int(LEN(buf)); Out.ln;
36 buf := Primes;
37 if buf = Primes then Out.str("same"); end;
38 Out.ln;
39 for i := 0 to LEN(Rules) - 1 do Out.str(Rules[i].class); Out.str(" "); Out.int(Rules[i].tag); Out.ln; end;
40 Out.str(Names[2]); Out.str(" "); Out.int(LEN(Names)); Out.ln;
41 Out.int(LEN(Local)); Out.str(" "); Out.int(I64(Local[3])); Out.ln;
42 if wide(0AC01H) and not wide(41H) then Out.str("wide"); end;
43 Out.str(" "); Out.int(LEN(Widths.Wide)); Out.ln;
44end;
45
46end ArrayConstLen.