raz / conform / run / EmptySliceConst.raz

39 lines · 1.2 KiB · raw · history · last change 264716cb

1module EmptySliceConst;
2import Out, Widths;
3
4(* A constant typed []T whose literal is [] is the empty slice, used as
5 a slice is: as a table with nothing in it, or a part of a constant *)
6
7type Prop = record name: []const U8; runs: []const [2]I32; end;
8
9const
10 None: []const I64 = [];
11 Wide: []const [2]I32 = [[1100H, 115FH]];
12 Narrow: []const [2]I32 = [];
13 Props: []const Prop = [{name: "wide", runs: Wide}, {name: "narrow", runs: Narrow}, {name: "none", runs: []},
14 {name: "Widths.Wide", runs: Widths.Wide}, {name: "Widths.Narrow", runs: Widths.Narrow}];
15
16proc sum(a: []const I64): I64;
17var s: I64; i: INT;
18begin
19 for i := 0 to LEN(a) - 1 do s := s + a[i]; end;
20 return s;
21end;
22
23proc main*;
24var s: []const I64; i: INT;
25begin
26 s := None;
27 Out.int(LEN(None)); Out.str(" "); Out.int(sum(None)); Out.str(" "); Out.int(LEN(s)); Out.str(" ");
28 Out.int(LEN(None[0..0])); Out.str(" "); Out.int(LEN(Widths.Narrow)); Out.ln;
29 if s = None then Out.str("same"); end;
30 Out.ln;
31 for i := 0 to LEN(Props) - 1 do
32 Out.str(Props[i].name); Out.str(" "); Out.int(LEN(Props[i].runs)); Out.ln;
33 end;
34 i := 0;
35 Out.int(None[i]); (* none to index: a failed check *)
36 Out.ln;
37end;
38
39end EmptySliceConst.