raz / commit fa020166

commit
fa02016680d1ff9f229b5ff5ae86d97ea20298d6
author
Luis <42945842+ldiaz94@users.noreply.github.com>
date
parent
906f50f4
[] as the empty slice, tested (report 2026-10.30); the compiler follows 2026-10.31

The compiler already made [] a nil pointer and a length of 0, and let
it be returned: conform/run/EmptySlice pins it, through a view, which
the seed doesn't know. raz --version says report 2026-10.31, whose
thaw the next steps build.

patch · log

4 files changed, +53 -4

conform/run/EmptySlice.expect (history) added +4 -0

@@ -0,0 +1,4 @@
1+2 20
2+not found, 0
3+empty, as a variable starts
4+0

conform/run/EmptySlice.raz (history) added +43 -0

@@ -0,0 +1,43 @@
1+(* [] used as a slice is the empty slice, as a slice variable starts,
2+ and no variable of the procedure: it may be returned beside an error
3+ (report 2026-10.30, sections 6.5 and 7.3). *)
4+module EmptySlice;
5+import Out;
6+
7+type Pair = record a, b: INT; end;
8+
9+const NotFound: ERROR = "not found";
10+
11+var pairs: [3]Pair;
12+
13+(* The pairs from the first whose a is key on, or none and NotFound. *)
14+proc from(key: INT): ([]Pair, ERROR);
15+var i: INT;
16+begin
17+ for i := 0 to LEN(pairs) - 1 do
18+ if pairs[i].a = key then return pairs[i..LEN(pairs)], nil; end;
19+ end;
20+ return [], NotFound;
21+end;
22+
23+proc none: []INT;
24+begin
25+ return [];
26+end;
27+
28+proc main*;
29+var s: []Pair; e: ERROR; t, u: []INT; w: [2]INT;
30+begin
31+ pairs := [{a: 1, b: 10}, {a: 2, b: 20}, {a: 3, b: 30}];
32+ s, e := from(2);
33+ Out.int(LEN(s)); Out.str(" "); Out.int(s[0].b); Out.ln;
34+ s, e := from(9);
35+ if e = NotFound then Out.str("not found, "); Out.int(LEN(s)); Out.ln; end;
36+ t := none();
37+ w := t.([2]INT); (* ptr and len (5.3) *)
38+ if (w[0] = 0) and (w[1] = 0) then Out.str("empty, as a variable starts\n"); end;
39+ u := [];
40+ Out.int(LEN(u)); Out.ln;
41+end;
42+
43+end EmptySlice.

src/Raz.raz (history) modified +1 -1

@@ -29,7 +29,7 @@
2929 import Sys, Out, Version, Files, Fmt, Diag, Scan, Sym, Chunk, X64, Gen, Parse, Link, Elf;
3030
3131 const
32- Report = "2026-10.29"; (* the version of doc/raz.md it follows *)
32+ Report = "2026-10.31"; (* the version of doc/raz.md it follows *)
3333 MemfdCreate = 319; (* the system call *)
3434 MfdCloexec = 1; (* an ELF still executes: the kernel opens it first *)
3535 Execve = 59;

src/check.sh modified +5 -3

@@ -13,8 +13,9 @@
1313 # converts the narrower of two integers; and views, v.(T),
1414 # whose tests are conform/*/View*.raz, and which Math, examples/Elf.raz
1515 # and, through Math, test/bench/NBody.raz use; and returning a slice of
16-# the frame as an error (report 2026-10.27); and an array constant
17-# typed []T (report 2026-10.29).
16+# the frame as an error (report 2026-10.27); an array constant typed
17+# []T (report 2026-10.29); and [] as the empty slice, seen through a
18+# view (report 2026-10.30).
1819 newer="conform/run/RawStrings.raz conform/err/ScanRawOpen.raz conform/err/ScanRawIndent.raz
1920 conform/run/MatchStr.raz conform/err/MatchStrTwice.raz conform/err/MatchStrNoElse.raz
2021 conform/err/MatchStrVar.raz conform/err/MatchReal.raz conform/err/AtMatch.raz
@@ -23,7 +24,8 @@
2324 conform/err/IntResultsNarrow.raz conform/err/GenIntTypes.raz
2425 lib/Math.raz examples/Elf.raz test/bench/NBody.raz
2526 conform/err/FrameSlice.raz
26- conform/run/ArrayConstLen.raz conform/err/ArrayConstLenEmpty.raz conform/err/ArrayConstLenLiteral.raz"
27+ conform/run/ArrayConstLen.raz conform/err/ArrayConstLenEmpty.raz conform/err/ArrayConstLenLiteral.raz
28+ conform/run/EmptySlice.raz"
2729 newer() {
2830 case $1 in conform/*/View*.raz) return 0 ;; esac
2931 for g in $newer; do [ $g = $1 ] && return 0; done