From fa02016680d1ff9f229b5ff5ae86d97ea20298d6 Mon Sep 17 00:00:00 2001 From: Luis <42945842+ldiaz94@users.noreply.github.com> Date: Fri, 16 Oct 2026 11:05:45 +0100 Subject: [PATCH] [] 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. --- diff --git a/conform/run/EmptySlice.expect b/conform/run/EmptySlice.expect new file mode 100644 index 0000000..fc1a6c5 --- /dev/null +++ b/conform/run/EmptySlice.expect @@ -0,0 +1,4 @@ +2 20 +not found, 0 +empty, as a variable starts +0 diff --git a/conform/run/EmptySlice.raz b/conform/run/EmptySlice.raz new file mode 100644 index 0000000..0b611e5 --- /dev/null +++ b/conform/run/EmptySlice.raz @@ -0,0 +1,43 @@ +(* [] used as a slice is the empty slice, as a slice variable starts, + and no variable of the procedure: it may be returned beside an error + (report 2026-10.30, sections 6.5 and 7.3). *) +module EmptySlice; +import Out; + +type Pair = record a, b: INT; end; + +const NotFound: ERROR = "not found"; + +var pairs: [3]Pair; + +(* The pairs from the first whose a is key on, or none and NotFound. *) +proc from(key: INT): ([]Pair, ERROR); +var i: INT; +begin + for i := 0 to LEN(pairs) - 1 do + if pairs[i].a = key then return pairs[i..LEN(pairs)], nil; end; + end; + return [], NotFound; +end; + +proc none: []INT; +begin + return []; +end; + +proc main*; +var s: []Pair; e: ERROR; t, u: []INT; w: [2]INT; +begin + pairs := [{a: 1, b: 10}, {a: 2, b: 20}, {a: 3, b: 30}]; + s, e := from(2); + Out.int(LEN(s)); Out.str(" "); Out.int(s[0].b); Out.ln; + s, e := from(9); + if e = NotFound then Out.str("not found, "); Out.int(LEN(s)); Out.ln; end; + t := none(); + w := t.([2]INT); (* ptr and len (5.3) *) + if (w[0] = 0) and (w[1] = 0) then Out.str("empty, as a variable starts\n"); end; + u := []; + Out.int(LEN(u)); Out.ln; +end; + +end EmptySlice. diff --git a/src/Raz.raz b/src/Raz.raz index 0961567..14040d9 100644 --- a/src/Raz.raz +++ b/src/Raz.raz @@ -29,7 +29,7 @@ import Sys, Out, Version, Files, Fmt, Diag, Scan, Sym, Chunk, X64, Gen, Parse, Link, Elf; const - Report = "2026-10.29"; (* the version of doc/raz.md it follows *) + Report = "2026-10.31"; (* the version of doc/raz.md it follows *) MemfdCreate = 319; (* the system call *) MfdCloexec = 1; (* an ELF still executes: the kernel opens it first *) Execve = 59; diff --git a/src/check.sh b/src/check.sh index 7a32a61..8fce9ad 100755 --- a/src/check.sh +++ b/src/check.sh @@ -13,8 +13,9 @@ # converts the narrower of two integers; and views, v.(T), # whose tests are conform/*/View*.raz, and which Math, examples/Elf.raz # and, through Math, test/bench/NBody.raz use; and returning a slice of -# the frame as an error (report 2026-10.27); and an array constant -# typed []T (report 2026-10.29). +# the frame as an error (report 2026-10.27); an array constant typed +# []T (report 2026-10.29); and [] as the empty slice, seen through a +# view (report 2026-10.30). newer="conform/run/RawStrings.raz conform/err/ScanRawOpen.raz conform/err/ScanRawIndent.raz conform/run/MatchStr.raz conform/err/MatchStrTwice.raz conform/err/MatchStrNoElse.raz conform/err/MatchStrVar.raz conform/err/MatchReal.raz conform/err/AtMatch.raz @@ -23,7 +24,8 @@ conform/err/IntResultsNarrow.raz conform/err/GenIntTypes.raz lib/Math.raz examples/Elf.raz test/bench/NBody.raz conform/err/FrameSlice.raz - conform/run/ArrayConstLen.raz conform/err/ArrayConstLenEmpty.raz conform/err/ArrayConstLenLiteral.raz" + conform/run/ArrayConstLen.raz conform/err/ArrayConstLenEmpty.raz conform/err/ArrayConstLenLiteral.raz + conform/run/EmptySlice.raz" newer() { case $1 in conform/*/View*.raz) return 0 ;; esac for g in $newer; do [ $g = $1 ] && return 0; done