| 1 | module ArrayConstLen; |
| 2 | import Out, Widths; |
| 3 | |
| 4 | type Rule = record class: []const U8; tag: INT; end; |
| 5 | |
| 6 | const |
| 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 | |
| 12 | var buf: [Count]I64; |
| 13 | |
| 14 | proc sum(a: []const I64): I64; |
| 15 | var s: I64; i: INT; |
| 16 | begin |
| 17 | for i := 0 to LEN(a) - 1 do s := s + a[i]; end; |
| 18 | return s; |
| 19 | end; |
| 20 | |
| 21 | proc wide(c: I32): BOOL; |
| 22 | var i: INT; |
| 23 | begin |
| 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; |
| 28 | end; |
| 29 | |
| 30 | proc main*; |
| 31 | const Local: []const U8 = [1, 2, 3, 4]; |
| 32 | var i: INT; |
| 33 | begin |
| 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; |
| 44 | end; |
| 45 | |
| 46 | end ArrayConstLen. |