| 1 | module EmptySliceConst; |
| 2 | import 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 | |
| 7 | type Prop = record name: []const U8; runs: []const [2]I32; end; |
| 8 | |
| 9 | const |
| 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 | |
| 16 | proc sum(a: []const I64): I64; |
| 17 | var s: I64; i: INT; |
| 18 | begin |
| 19 | for i := 0 to LEN(a) - 1 do s := s + a[i]; end; |
| 20 | return s; |
| 21 | end; |
| 22 | |
| 23 | proc main*; |
| 24 | var s: []const I64; i: INT; |
| 25 | begin |
| 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; |
| 37 | end; |
| 38 | |
| 39 | end EmptySliceConst. |