From 0f9c12b3d2f7732640d8128494248eda587164e9 Mon Sep 17 00:00:00 2001 From: Luis <42945842+ldiaz94@users.noreply.github.com> Date: Sat, 17 Oct 2026 09:56:01 +0000 Subject: [PATCH] site: v0.19.0 and v0.20.0 The website offers both, and /download/latest leads to 0.20.0. Their tags aren't pushed yet: their tarballs were made as the tags will make them (v0.19.0's with its version given by hand, v0.20.0's by make dist VERSION=0.20.0 at 086e55c), and HANDOVER.md gives their SHA-256 for CI's to be checked against. The tour's lessons and the report are built again from today's tree: lesson 7 has "A slice's pointer". make dist lends the BOOT tarball already fetched to its checkout, so a release can be packed with no network. --- diff --git a/HANDOVER.md b/HANDOVER.md index a9f5aeb..5390fa9 100644 --- a/HANDOVER.md +++ b/HANDOVER.md @@ -18,7 +18,7 @@ |---|---|---|---| | `v0.18.1` | `88b18ba` ("Docs for v0.18.1: ...") | `raz 0.18.1, report 2026-10.32` | what `site/public/download/raz-0.18.1-linux-x86_64.tar.gz.sha256` says | | `v0.19.0` | `51a90a6` ("Report 2026-10.33 is followed; ...") | `raz 0.19.0, report 2026-10.33` | `217448cb6521c76a28d71499d70a5dfdebc2dbcbc81d6d41ed9d9590005772ed` | -| `v0.20.0` | the commit "Docs for v0.20.0" (see below) | `raz 0.20.0, report 2026-10.34` | what `site/public/download/raz-0.20.0-linux-x86_64.tar.gz.sha256` says | +| `v0.20.0` | `086e55c` ("Docs for v0.20.0: ...") | `raz 0.20.0, report 2026-10.34` | `bfa954d27d759e4ca7f7f33debb4705f25d5c05a097d86aa28b3260048b5d9cc` | git tag -a v0.18.1 -m 'raz 0.18.1, report 2026-10.32' 88b18ba git push origin v0.18.1 @@ -28,16 +28,15 @@ # gh api repos/ldiaz94/raz/releases/tags/v0.19.0 --jq '.assets[].name' # gh release download v0.19.0 -p '*.tar.gz' && sha256sum raz-0.19.0-*.tar.gz # it must be BOOT's; only then: - git tag -a v0.20.0 -m 'raz 0.20.0, report 2026-10.34' + git tag -a v0.20.0 -m 'raz 0.20.0, report 2026-10.34' 086e55c git push origin v0.20.0 -`` is the commit whose subject is "Docs for v0.20.0", found by -`git log --oneline --grep='^Docs for v0.20.0'`; it is the one before -"site: v0.19.0 and v0.20.0". Check before tagging that `make check` -passes there, and that `src/Raz.raz` there says report 2026-10.34. -The site commit after it changes only -`site/` and this file, so the tag stays on the docs commit, as v0.18.1's -did. +`086e55c` is "Docs for v0.20.0"; the commit after it, "site: v0.19.0 +and v0.20.0", changes only `site/`, `make dist` (which lends a +fetched BOOT tarball to its checkout) and this file, so the tag stays +on the docs commit, as v0.18.1's did. Check before tagging that `make +check` passes there. The sums of v0.19.0 and v0.20.0 are also in +`site/public/download/*.sha256`, which the website serves. Before v0.19.0's release exists, CI on every push to `main` fails at `src/boot.sh` (it can't fetch the tarball `BOOT` names); that is @@ -53,7 +52,9 @@ `build/version.inc` set to `'0.19.0'` (its Makefile predates `VERSION`), which gave BOOT's sum, the same that the session before got with a local tag; v0.20.0's by `make dist REV= -VERSION=0.20.0`, which the Makefile now takes for this. So CI's +VERSION=0.20.0`, which the Makefile now takes for this, twice, with +the same sum; its `raz --version` says `raz 0.20.0, report +2026-10.34`. So CI's tarball for each tag must have the sum in the table; if one differs, the website's copy is wrong and must be replaced by CI's before anyone pins it (the site keeps a tarball once it has it). diff --git a/Makefile b/Makefile index b1dc79c..04de106 100644 --- a/Makefile +++ b/Makefile @@ -155,6 +155,8 @@ dist: rm -rf $(DIST) && git worktree prune && git worktree add -q --detach $(DIST) $(REV) + # the tarball BOOT names, if fetched, lent to the checkout (src/boot.sh checks its sum) + if [ -d build/boot ]; then mkdir -p $(DIST)/build/boot && cp build/boot/*.tar.gz $(DIST)/build/boot/; fi $(MAKE) -C $(DIST) raz man v=$$($(DIST)/raz --version | sed 's/^raz \([^,]*\),.*/\1/'); \ d=raz-$$v-linux-x86_64; \ diff --git a/site/public/_redirects b/site/public/_redirects index 318c1d7..55616d6 100644 --- a/site/public/_redirects +++ b/site/public/_redirects @@ -1 +1 @@ -/download/latest /download/raz-0.18.1-linux-x86_64.tar.gz 302 +/download/latest /download/raz-0.20.0-linux-x86_64.tar.gz 302 diff --git a/site/public/advanced/allocators.html b/site/public/advanced/allocators.html index af001aa..041c53e 100644 --- a/site/public/advanced/allocators.html +++ b/site/public/advanced/allocators.html @@ -172,16 +172,16 @@ var c: Counted.Counted; b: Buf.Buf; l: Names.List; i: INT; p: ^U8; begin Counted.init(ADR(c), Heap.heap); - Buf.init(ADR(b), ADR(c.base)); - for i := 1 to 200 do Buf.str(ADR(b), "0123456789"); end; + Buf.init(b, ADR(c.base)); + for i := 1 to 200 do Buf.str(b, "0123456789"); end; Fmt.print("a buffer of {} bytes took {} allocations\n", [Fmt.int(b.len), Fmt.int(c.allocs)]); - Buf.done(ADR(b)); + Buf.done(b); - Names.init(ADR(l), ADR(c.base)); - for i := 1 to 10 do _ := Names.push(ADR(l), "x"); end; + Names.init(l, ADR(c.base)); + for i := 1 to 10 do _ := Names.push(l, "x"); end; Fmt.print("{} allocations in all, {} frees so far\n", [Fmt.int(c.allocs), Fmt.int(c.frees)]); - Names.clear(ADR(l)); + Names.clear(l); Fmt.print("{} frees after clear\n", [Fmt.int(c.frees)]); p := Mem.alloc(ADR(c.base), 64, 8); diff --git a/site/public/advanced/atomics.html b/site/public/advanced/atomics.html index 5514f00..73c0130 100644 --- a/site/public/advanced/atomics.html +++ b/site/public/advanced/atomics.html @@ -144,20 +144,20 @@ type Lock* = record held: INT; end; (* Takes l, waiting while another thread holds it. *) -proc take*(l: ^Lock); +proc take*(var l: Lock); var tries: INT; begin tries := 0; - while not CAS(ADR(l^.held), 0, 1) do + while not CAS(ADR(l.held), 0, 1) do INC(tries); if tries = 64 then Sys.yield; tries := 0; end; end; end; (* Gives up l, which the caller holds. *) -proc give*(l: ^Lock); +proc give*(var l: Lock); begin - _ := XCHG(ADR(l^.held), 0); + _ := XCHG(ADR(l.held), 0); end;

And here is a use of it: a structure with two fields that must stay in step, which no single atomic can protect.

Account.raz
module Account;
@@ -171,10 +171,10 @@
 var i: INT;
 begin
     for i := 1 to 20000 do
-        Lock.take(ADR(lock));
+        Lock.take(lock);
         INC(deposits);
         INC(balance, 3);
-        Lock.give(ADR(lock));
+        Lock.give(lock);
     end;
 end;
 
diff --git a/site/public/advanced/collections.html b/site/public/advanced/collections.html
index 4021428..5bf9cd0 100644
--- a/site/public/advanced/collections.html
+++ b/site/public/advanced/collections.html
@@ -53,14 +53,14 @@
 proc main*;
 var l: Ints.List; n: ^Ints.Node; v: INT;
 begin
-    Ints.init(ADR(l), Heap.heap);
-    defer Ints.clear(ADR(l));
-    for v := 1 to 5 do _ := Ints.push(ADR(l), v * v); end;
-    Ints.reverse(ADR(l));                    (* oldest first *)
+    Ints.init(l, Heap.heap);
+    defer Ints.clear(l);
+    for v := 1 to 5 do _ := Ints.push(l, v * v); end;
+    Ints.reverse(l);                    (* oldest first *)
     n := l.head;
     while n # nil do Out.int(n^.val); Out.char(' '); n := n^.next; end;
     Out.ln;
-    v, _ := Ints.pop(ADR(l));
+    v, _ := Ints.pop(l);
     Out.int(v); Out.str(" popped, "); Out.int(l.len); Out.str(" left\n");
 end;
 
@@ -76,13 +76,13 @@
 proc main*;
 var v: Ints.Vec; i: INT; s: []INT;
 begin
-    Ints.init(ADR(v), Heap.heap);
-    defer Ints.done(ADR(v));
-    for i := 1 to 1000 do Ints.push(ADR(v), i * i); end;
-    s := Ints.all(ADR(v));
+    Ints.init(v, Heap.heap);
+    defer Ints.done(v);
+    for i := 1 to 1000 do Ints.push(v, i * i); end;
+    s := Ints.all(v);
     Out.int(v.len); Out.str(" squares, the last "); Out.int(s[LEN(s) - 1]); Out.ln;
-    Ints.resize(ADR(v), 3);
-    for i := 0 to v.len - 1 do Out.int(Ints.all(ADR(v))[i]); Out.char(' '); end;
+    Ints.resize(v, 3);
+    for i := 0 to v.len - 1 do Out.int(Ints.all(v)[i]); Out.char(' '); end;
     Out.ln;
 end;
 
@@ -98,22 +98,22 @@
 proc main*;
 var m: Book.Map; age: INT; found, ok: BOOL; i: INT; v: INT;
 begin
-    Book.init(ADR(m), Heap.heap);
-    _ := Book.put(ADR(m), "ada", 36);
-    _ := Book.put(ADR(m), "grace", 45);
-    _ := Book.put(ADR(m), "alan", 41);
-    _ := Book.put(ADR(m), "ada", 37);                (* replaces *)
-    age, found := Book.get(ADR(m), "ada");
+    Book.init(m, Heap.heap);
+    _ := Book.put(m, "ada", 36);
+    _ := Book.put(m, "grace", 45);
+    _ := Book.put(m, "alan", 41);
+    _ := Book.put(m, "ada", 37);                (* replaces *)
+    age, found := Book.get(m, "ada");
     Fmt.print("ada: {} ({})\n", [Fmt.int(age), Fmt.bool(found)]);
-    age, found := Book.get(ADR(m), "linus");
+    age, found := Book.get(m, "linus");
     Fmt.print("linus: {} ({})\n", [Fmt.int(age), Fmt.bool(found)]);
-    ok := Book.remove(ADR(m), "alan");
+    ok := Book.remove(m, "alan");
     Fmt.print("{} entries, removed {}\n", [Fmt.int(m.len), Fmt.bool(ok)]);
     v := 0;
-    i, _, age := Book.next(ADR(m), 0);
+    i, _, age := Book.next(m, 0);
     while i >= 0 do
         INC(v, age);
-        i, _, age := Book.next(ADR(m), i);
+        i, _, age := Book.next(m, i);
     end;
     Out.int(v); Out.str(" years in all\n");
 end;
@@ -151,22 +151,22 @@
     m: Count.Map; entries: Entries.Vec; i, k, found: INT;
     w, rest: []U8; key: []U8; v: INT; all: []Entry;
 begin
-    Count.init(ADR(m), Heap.heap);
-    defer Count.done(ADR(m));
+    Count.init(m, Heap.heap);
+    defer Count.done(m);
     w, rest := Str.field(Text);
     while LEN(w) > 0 do
-        k, _ := Count.get(ADR(m), w);
-        _ := Count.put(ADR(m), w, k + 1);
+        k, _ := Count.get(m, w);
+        _ := Count.put(m, w, k + 1);
         w, rest := Str.field(rest);
     end;
-    Entries.init(ADR(entries), Heap.heap);
-    defer Entries.done(ADR(entries));
-    found, key, v := Count.next(ADR(m), 0);
+    Entries.init(entries, Heap.heap);
+    defer Entries.done(entries);
+    found, key, v := Count.next(m, 0);
     while found >= 0 do
-        Entries.push(ADR(entries), {word: key, n: v});
-        found, key, v := Count.next(ADR(m), found);
+        Entries.push(entries, {word: key, n: v});
+        found, key, v := Count.next(m, found);
     end;
-    all := Entries.all(ADR(entries));
+    all := Entries.all(entries);
     Rank.sort(all);
     for i := 0 to LEN(all) - 1 do
         Fmt.print("{} {}\n", [Fmt.int(all[i].n), Fmt.str(all[i].word)]);
diff --git a/site/public/advanced/files.html b/site/public/advanced/files.html
index 4ca6478..c7fbeeb 100644
--- a/site/public/advanced/files.html
+++ b/site/public/advanced/files.html
@@ -55,15 +55,15 @@
 begin
     ok := Files.write("notes.txt", "first line\nsecond line\n");
     if not ok then Out.str("can't write\n"); return; end;
-    Buf.init(ADR(b), Heap.heap);
-    defer Buf.done(ADR(b));
-    ok := Files.read("notes.txt", ADR(b));
+    Buf.init(b, Heap.heap);
+    defer Buf.done(b);
+    ok := Files.read("notes.txt", b);
     if ok then
-        Out.int(b.len); Out.str(" bytes: "); Out.str(Buf.bytes(ADR(b)));
+        Out.int(b.len); Out.str(" bytes: "); Out.str(Buf.bytes(b));
     end;
-    ok := Files.read("missing.txt", ADR(b));
+    ok := Files.read("missing.txt", b);
     if not ok then Out.str("missing.txt: not there\n"); end;
-    if Files.load("missing.txt", ADR(b)) = -2 then Out.str("missing.txt: ENOENT\n"); end;
+    if Files.load("missing.txt", b) = -2 then Out.str("missing.txt: ENOENT\n"); end;
 end;
 
 end Notes.
@@ -146,22 +146,22 @@ _ := Sys.makeDir("proj/src"); put("proj/b.txt", "bb"); put("proj/a.txt", "a"); - if Sys.openDir(ADR(d), "proj") < 0 then return; end; + if Sys.openDir(d, "proj") < 0 then return; end; n := 0; - name, more := Sys.nextEntry(ADR(d)); + name, more := Sys.nextEntry(d); while more do copy, ok := Str.copy(Heap.heap, name); if ok and (n < 16) then names[n] := copy; INC(n); end; - name, more := Sys.nextEntry(ADR(d)); + name, more := Sys.nextEntry(d); end; - Sys.closeDir(ADR(d)); + Sys.closeDir(d); Order.sort(names[0..n]); - Buf.init(ADR(path), Heap.heap); + Buf.init(path, Heap.heap); for i := 0 to n - 1 do - Buf.reset(ADR(path)); - Buf.str(ADR(path), "proj/"); - Buf.str(ADR(path), names[i]); - info, err := Sys.info(Buf.bytes(ADR(path))); + Buf.reset(path); + Buf.str(path, "proj/"); + Buf.str(path, names[i]); + info, err := Sys.info(Buf.bytes(path)); Out.str(names[i]); if err < 0 then Out.str(" ?"); elsif info.dir then Out.str("/"); @@ -170,7 +170,7 @@ Out.ln; Mem.free(Heap.heap, ^U8(ADR(names[i][0]))); end; - Buf.done(ADR(path)); + Buf.done(path); end; end Tree. @@ -227,23 +227,23 @@ var p: Opt.Parser; verbose: BOOL; n, i: INT; w: []U8; ok: BOOL; begin n := 1; - Opt.init(ADR(p), "tool", [ + Opt.init(p, "tool", [ Opt.usage("", "tool [-v] [--count n] word ..."), Opt.option("", 'v', "verbose", "", "say more"), Opt.option("", count, "count", "n", "repeat each word n times")]); - while Opt.next(ADR(p)) do + while Opt.next(p) do if p.letter = 'v' then verbose := true; - elsif p.letter = count then n := INT(Opt.number(ADR(p), 1, 5)); + elsif p.letter = count then n := INT(Opt.number(p, 1, 5)); end; end; - w, ok := Opt.operand(ADR(p)); - if not ok then Opt.fail(ADR(p), "no words; see tool -h"); end; + w, ok := Opt.operand(p); + if not ok then Opt.fail(p, "no words; see tool -h"); end; while ok do for i := 1 to n do if verbose then Out.str("word: "); end; Fmt.print("{}\n", [Fmt.str(w)]); end; - w, ok := Opt.operand(ADR(p)); + w, ok := Opt.operand(p); end; end; diff --git a/site/public/advanced/fmt.html b/site/public/advanced/fmt.html index 32b116e..ecc677c 100644 --- a/site/public/advanced/fmt.html +++ b/site/public/advanced/fmt.html @@ -96,7 +96,7 @@ import Out, Buf, Fmt, Heap; (* "name (age n)", built in a Buf the caller owns *) -proc describe(b: ^Buf.Buf; name: []U8; age: INT); +proc describe(var b: Buf.Buf; name: []U8; age: INT); begin Fmt.write(b, "{} (age {})", [Fmt.str(name), Fmt.int(age)]); end; @@ -104,12 +104,12 @@ proc main*; var b: Buf.Buf; begin - Buf.init(ADR(b), Heap.heap); - defer Buf.done(ADR(b)); - describe(ADR(b), "Ada", 36); - Buf.str(ADR(b), "; "); - describe(ADR(b), "Grace", 45); - Out.str(Buf.bytes(ADR(b))); Out.ln; + Buf.init(b, Heap.heap); + defer Buf.done(b); + describe(b, "Ada", 36); + Buf.str(b, "; "); + describe(b, "Grace", 45); + Out.str(Buf.bytes(b)); Out.ln; Out.int(b.len); Out.str(" bytes\n"); end; diff --git a/site/public/advanced/processes.html b/site/public/advanced/processes.html index ebd3979..7dcebb7 100644 --- a/site/public/advanced/processes.html +++ b/site/public/advanced/processes.html @@ -139,16 +139,16 @@ p.fds[1] := wr; pid := Sys.spawn(p); Sys.close(wr); (* only the child writes now *) - Buf.init(ADR(b), Heap.heap); - defer Buf.done(ADR(b)); + Buf.init(b, Heap.heap); + defer Buf.done(b); n := Sys.read(rd, chunk); while n > 0 do - Buf.str(ADR(b), chunk[0..n]); + Buf.str(b, chunk[0..n]); n := Sys.read(rd, chunk); end; Sys.close(rd); _, how, status := Sys.wait(pid, true); - Out.str("captured: "); Out.str(Buf.bytes(ADR(b))); + Out.str("captured: "); Out.str(Buf.bytes(b)); Out.str("status "); Out.int(status); Out.ln; if how = Sys.exited then Out.str("(a normal exit)\n"); end; end; diff --git a/site/public/advanced/static.html b/site/public/advanced/static.html index 92b1d11..88d3162 100644 --- a/site/public/advanced/static.html +++ b/site/public/advanced/static.html @@ -97,8 +97,8 @@ Cprint: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, with debug_info, not stripped $ ldd Cprint | sed 's/ (0x[0-9a-f]*)//' linux-vdso.so.1 - libc.so.6 => /usr/lib/libc.so.6 - /lib64/ld-linux-x86-64.so.2 => /usr/lib64/ld-linux-x86-64.so.2 + libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 + /lib64/ld-linux-x86-64.so.2

Both are fine. The point is that you choose, and the language says which you chose: a program uses C exactly when a module of it has an extern or a link of a library.

Only what is reached

The compiler keeps only what can be reached from main and the module bodies. Unused procedures, variables and strings are left out. Here are two programs that differ by one large procedure that nothing calls.

@@ -134,14 +134,14 @@
$ raz Lean.raz
 $ raz Heavy.raz
 $ ls -l Lean Heavy | awk '{print $9, $5}'
-Heavy 28472
-Lean 28464
+Heavy 28440 +Lean 28440

The sizes differ by a few bytes, not by the hundreds of kilobytes that the table and the procedure would take: they are not in the executable at all. You can link in a library module without worrying what else it offers.

Stripping

-s leaves out what is there for finding faults: the symbols and line numbers, the places a failure is told by, and the profiler. It is for the final build of a size-conscious program; the default keeps them so that gdb and failure messages work.

$ raz -s -o Lean-stripped Lean.raz
 $ ls -l Lean Lean-stripped | awk '{print $9, $5}'
-Lean 28464
+Lean 28440
 Lean-stripped 6856
 $ ./Lean-stripped
 same program
diff --git a/site/public/download/raz-0.19.0-linux-x86_64.tar.gz b/site/public/download/raz-0.19.0-linux-x86_64.tar.gz new file mode 100644 index 0000000..9743b27 Binary files /dev/null and b/site/public/download/raz-0.19.0-linux-x86_64.tar.gz differ diff --git a/site/public/download/raz-0.19.0-linux-x86_64.tar.gz.sha256 b/site/public/download/raz-0.19.0-linux-x86_64.tar.gz.sha256 new file mode 100644 index 0000000..0f1e48c --- /dev/null +++ b/site/public/download/raz-0.19.0-linux-x86_64.tar.gz.sha256 @@ -0,0 +1 @@ +217448cb6521c76a28d71499d70a5dfdebc2dbcbc81d6d41ed9d9590005772ed raz-0.19.0-linux-x86_64.tar.gz diff --git a/site/public/download/raz-0.20.0-linux-x86_64.tar.gz b/site/public/download/raz-0.20.0-linux-x86_64.tar.gz new file mode 100644 index 0000000..f0240df Binary files /dev/null and b/site/public/download/raz-0.20.0-linux-x86_64.tar.gz differ diff --git a/site/public/download/raz-0.20.0-linux-x86_64.tar.gz.sha256 b/site/public/download/raz-0.20.0-linux-x86_64.tar.gz.sha256 new file mode 100644 index 0000000..0bf3afc --- /dev/null +++ b/site/public/download/raz-0.20.0-linux-x86_64.tar.gz.sha256 @@ -0,0 +1 @@ +bfa954d27d759e4ca7f7f33debb4705f25d5c05a097d86aa28b3260048b5d9cc raz-0.20.0-linux-x86_64.tar.gz diff --git a/site/public/index.html b/site/public/index.html index 9d9f48e..97f3cbd 100644 --- a/site/public/index.html +++ b/site/public/index.html @@ -42,7 +42,7 @@
~10,700 lines of compiler ~500K lines compiled a second - 1 report, 31 pages + 1 report, 32 pages static executables, no run time to install
@@ -109,28 +109,28 @@

The language is defined by the report, which is short on purpose: whatever it doesn’t allow, raz doesn’t have. Its second volume describes the library. Both are on one page, and each is -a PDF: the language (31 pages) and +a PDF: the language (32 pages) and the library.

Download

-

raz 0.18.1 is a tarball for x86-64 Linux with the compiler, raz, +

raz 0.20.0 is a tarball for x86-64 Linux with the compiler, raz, its library, lib/, which it finds beside itself, the formatter and the documentation tool as sources in tools/, and the manual pages. It needs nothing else installed.

-
$ tar xzf raz-0.18.1-linux-x86_64.tar.gz
-$ ln -s $PWD/raz-0.18.1-linux-x86_64/raz ~/.local/bin/raz
+
$ tar xzf raz-0.20.0-linux-x86_64.tar.gz
+$ ln -s $PWD/raz-0.20.0-linux-x86_64/raz ~/.local/bin/raz
 $ raz run Hello.raz

The link works since raz finds lib/ beside its real path. The manual pages are in man/: man ./man/raz-tutorial.7. The address download/latest always leads to the newest release, -and download/raz-0.18.1-linux-x86_64.tar.gz to this one, for -good. Earlier releases: 0.18.0, 0.17.2, 0.17.1, 0.17.0, 0.16.0, 0.15.0, 0.14.0, 0.13.0, 0.12.0, 0.11.1, 0.11.0, 0.10.1, 0.10.0, 0.9.1, 0.9.0, 0.8.0, 0.7.1; each has its SHA-256 beside it, with +and download/raz-0.20.0-linux-x86_64.tar.gz to this one, for +good. Earlier releases: 0.19.0, 0.18.1, 0.18.0, 0.17.2, 0.17.1, 0.17.0, 0.16.0, 0.15.0, 0.14.0, 0.13.0, 0.12.0, 0.11.1, 0.11.0, 0.10.1, 0.10.0, 0.9.1, 0.9.0, 0.8.0, 0.7.1; each has its SHA-256 beside it, with .sha256 added to its name.

-

SHA-256 95184eacaa25bec1cdcd3e992c6ddc76c0a6fa95c5c5b50e48dc1b402ed65214

+

SHA-256 bfa954d27d759e4ca7f7f33debb4705f25d5c05a097d86aa28b3260048b5d9cc

raz is under the ISC license.
diff --git a/site/public/raz-lib.pdf b/site/public/raz-lib.pdf index 83f3e82..e67a972 100644 Binary files a/site/public/raz-lib.pdf and b/site/public/raz-lib.pdf differ diff --git a/site/public/raz.pdf b/site/public/raz.pdf index 4fbee51..7aea1e1 100644 Binary files a/site/public/raz.pdf and b/site/public/raz.pdf differ diff --git a/site/public/spec.html b/site/public/spec.html index 2d80e1f..cb0cc39 100644 --- a/site/public/spec.html +++ b/site/public/spec.html @@ -38,7 +38,7 @@

raz is a small systems language, first made for x86-64 Linux. A raz program can lay a record over a device’s registers, read and write a device’s memory exactly as written, take part in lock-free algorithms, make system calls and call C libraries. It has no garbage collector and no hidden run time: what the program does is what its text says.

This is the first volume of the report: the language, what an implementation chooses, and the grammar. The second, doc/raz-lib.md, is the library, which sections 3 and 10 and appendix A name.

This report defines the language. It is short on purpose. Whatever it doesn’t allow, raz doesn’t have.

-

This is version 2026-10.32 of the report; section 11 says where each version’s changes are told. 2026-10.11 and 2026-10.12 are a thaw the owner chose, for a language anyone can build again. They break programs written for 2026-10.10 and before: for 2026-10.9, say, the report of compiler 0.5.0, the last release before them; and 2026-10.12 breaks code procedures written for 2026-10.11. 2026-10.20 is a third, for try (section 7.8); it breaks a program that has a name try. 2026-10.25 is a fourth, for strings: raw strings, which may run over lines and may be indented with the code around them (section 2), and match on a string (section 7.4); it breaks no program. 2026-10.26 is a fifth: an INT widens to an I64 wherever it goes to one, in an expression too (sections 5.10 and 6.1); and a view, v.(T), reads and writes the bytes of a variable as a T (section 6.9); it breaks no program. 2026-10.27 mends a defect: returning a slice of the procedure’s own frame is an error (section 7.3), which breaks only a program that read memory already gone. 2026-10.28 mends another: an array a call returns lives to the end of its statement, and a slice of it kept past that is undefined (sections 8 and 10). 2026-10.29 is a sixth thaw: an array constant typed []T takes its length from its literal (section 4); it breaks no program. 2026-10.30 mends a defect: [] used as a slice is the empty slice, which may be returned (sections 6.5 and 7.3); it breaks no program. 2026-10.31 is a seventh thaw: INT is at least 16 bits, and U8, I8 and I16 widen to it (sections 5.1, 5.10 and 6.1); an enumeration’s name may be written with its type, and must be where another declaration shares it (section 5.7); and continue (section 7.2), which breaks a program that has a name continue. 2026-10.32 is an eighth thaw: a constant typed []T may be [], the empty slice (section 4); it breaks no program.

+

This is version 2026-10.34 of the report; section 11 says where each version’s changes are told. 2026-10.11 and 2026-10.12 are a thaw the owner chose, for a language anyone can build again. They break programs written for 2026-10.10 and before: for 2026-10.9, say, the report of compiler 0.5.0, the last release before them; and 2026-10.12 breaks code procedures written for 2026-10.11. 2026-10.20 is a third, for try (section 7.8); it breaks a program that has a name try. 2026-10.25 is a fourth, for strings: raw strings, which may run over lines and may be indented with the code around them (section 2), and match on a string (section 7.4); it breaks no program. 2026-10.26 is a fifth: an INT widens to an I64 wherever it goes to one, in an expression too (sections 5.10 and 6.1); and a view, v.(T), reads and writes the bytes of a variable as a T (section 6.9); it breaks no program. 2026-10.27 mends a defect: returning a slice of the procedure’s own frame is an error (section 7.3), which breaks only a program that read memory already gone. 2026-10.28 mends another: an array a call returns lives to the end of its statement, and a slice of it kept past that is undefined (sections 8 and 10). 2026-10.29 is a sixth thaw: an array constant typed []T takes its length from its literal (section 4); it breaks no program. 2026-10.30 mends a defect: [] used as a slice is the empty slice, which may be returned (sections 6.5 and 7.3); it breaks no program. 2026-10.31 is a seventh thaw: INT is at least 16 bits, and U8, I8 and I16 widen to it (sections 5.1, 5.10 and 6.1); an enumeration’s name may be written with its type, and must be where another declaration shares it (section 5.7); and continue (section 7.2), which breaks a program that has a name continue. 2026-10.32 is an eighth thaw: a constant typed []T may be [], the empty slice (section 4); it breaks no program. 2026-10.33 is a ninth: a const parameter, the caller’s variable read in place (section 8), and a variant in a constant (section 4), which break no program; and the library’s procedures that took a pointer to what they work on take a var parameter, a const one or a value instead (the library volume), which breaks a program that calls them with ADR. 2026-10.34 is a tenth: PTR(s), the address a slice starts at, even an empty one (section 6.8); it breaks no program.

The language is frozen, softly, from this version on: it changes only to mend a defect, and its library grows only by what breaks no program written for it. What anyone wishes it had waits on a list, for a later thaw.

1. A first look

module Hello;
@@ -134,15 +134,16 @@
 IdentDef    = ident [ "*" ] .
 IdentList   = IdentDef { "," IdentDef } .

A name must be declared before it is used, with two exceptions: the base type of a pointer may name a type declared later in the same type section (so that two records can point at each other), and a procedure may be declared forward and defined later (section 8).

-

Constants are evaluated by the compiler. Their expressions use only literals, other constants, operators, conversions, SIZE and the LEN of arrays and strings. A constant is an integer, a real, a BOOL, a name of an enumeration, a set, a string, an array, a record or an ERROR. A constant of an integer type wraps as the program would: U8(250) + 10 is 4. Dividing by zero in a constant is an error, and so is dividing the smallest value of a signed type by -1, with div or mod, which stops a program (section 6.1). A string constant can be indexed and sliced as an array of U8 is, and its LEN is its length in bytes. + joins two string constants into one:

+

Constants are evaluated by the compiler. Their expressions use only literals, other constants, operators, conversions, SIZE, the LEN of arrays and strings, and a variant’s cases. A constant is an integer, a real, a BOOL, a name of an enumeration, a set, a string, an array, a record, a variant or an ERROR. A constant of an integer type wraps as the program would: U8(250) + 10 is 4. Dividing by zero in a constant is an error, and so is dividing the smallest value of a signed type by -1, with div or mod, which stops a program (section 6.1). A string constant can be indexed and sliced as an array of U8 is, and its LEN is its length in bytes. + joins two string constants into one:

const Text = "the cat";
     Line = Text + "\n";
 ...
 w := Text[4..7];    (* "cat" *)
-

A constant with a type is an ERROR (section 5.8), an array or a record, and the value of an array or record constant is a literal (section 6.5) of constants. Its elements and fields are integers, reals, BOOLs, enumerations, sets, ERRORs, procedures, nil, a string for a []U8, an array constant or the empty slice for a slice of its element type, and arrays and records of these; no variant and no other pointer:

+

A constant with a type is an ERROR (section 5.8), an array, a record or a variant, and the value of an array or record constant is a literal (section 6.5) of constants, that of a variant one a case built from constants, as a program builds one (section 5.6). Its elements and fields are integers, reals, BOOLs, enumerations, sets, ERRORs, procedures, nil, a string for a []U8, an array constant or the empty slice for a slice of its element type, and arrays, records and variants of these; no other pointer. A variant constant must have a type: const D = dot; is an error, const D: Shape = dot; isn’t.

const Primes: [5]I64 = [2, 3, 5, 7, 11];
 type Rule = record class: []U8; tag: INT; float: BOOL; end;
 const Rules: [2]Rule = [{class: "firefox", tag: 2}, {class: "mpv", float: true}];
+const Shapes: []Shape = [circle(1.0), rect(2.0, 3.0), dot];   (* Shape of section 5.6 *)
 ...
 p := Primes[i];

It is used as a variable of that type is, but can’t be changed: an array constant can be indexed and sliced and its LEN is n, a record constant’s fields can be read, and either can be assigned, compared as its type allows, and passed. Its parts are constant as a string’s bytes are (section 5.10). A part of it isn’t a constant, even at a constant index.

@@ -219,7 +220,7 @@

5.3 Slices

[]T is a view of elements that live elsewhere: a pointer to the first and a count, two addresses’ worth, 16 bytes on x86-64.

Slice = record ptr: ^T; len: INT; end;    (* its layout *)
-

A slice is made from an array (a[2..5], or an array used where a slice is wanted), from another slice, or from a pointer (p[0..n]). It doesn’t own what it points at.

+

A slice is made from an array (a[2..5], or an array used where a slice is wanted), from another slice, or from a pointer (p[0..n]). It doesn’t own what it points at. LEN(s) is its count, and PTR(s) its pointer (section 6.8).

5.4 Pointers

^T is the address of a T, as big as an INT. nil is the pointer to nothing.

^VOLATILE T is the address of a T that something besides the program may read or change: a device register, memory shared with another process. Section 7.6 says what that promises.

@@ -266,7 +267,7 @@ if err = Table.NotFound then ... end;

5.9 Procedure types

type Compare = proc(a, b: I64): BOOL;
-

A value of a procedure type is the address of a procedure with that signature, as big as an address, or nil. Two signatures are alike when their parameters have the same types, each var or not alike, in order, and their results are the same types; the parameters’ names don’t matter.

+

A value of a procedure type is the address of a procedure with that signature, as big as an address, or nil. Two signatures are alike when their parameters have the same types, each var, const or neither alike, in order, and their results are the same types; the parameters’ names don’t matter.

5.10 Same and assignable

Two named types are the same only if they are the same declaration. Two anonymous pointer, array, slice, set or procedure types are the same if they are built alike: ^I64 is ^I64 wherever it is written. A record, variant or enumeration, though, is a type of its own wherever it is written, named or not: two record x: I64; end are two types. A named and an anonymous type are the same if the named one is built like the anonymous one, so that p := ADR(n) works for p: NodePtr with type NodePtr = ^Node. Sameness doesn’t pass through the anonymous type: with type P1 = ^Node; P2 = ^Node;, each of P1 and P2 is the same as ^Node, but they are two declarations, so not the same as each other.

A type declared with only a name on the right, type Count = I64;, is another name for that type, not a new one.

@@ -437,6 +438,10 @@ the number of elements of an array or a string constant (an untyped constant) or of a slice (an INT) +PTR(s) +the address the slice s starts at, a ^T for s: []T, unchecked; for an array a, that of a[0..LEN(a)] + + NEW(p, a) sets p: ^T to a fresh, zeroed T from the allocator a: ^Mem.Allocator, or to nil if a has no room @@ -488,6 +493,14 @@

SYSCALL exists only on Linux targets. Other systems have no stable system call interface, and their modules call the C library instead (section 9).

NEW(p, a) calls a^.alloc(a, SIZE(T), A), where A is the alignment of T, and zeroes the bytes it gets if they aren’t nil. Mem.Allocator (the library, doc/raz-lib.md) is the one type of the library the language names.

+

PTR(s) is the first of the two words of s (section 5.3), and is not checked. For a slice that isn’t empty it is ADR(s[0]); for an empty one, where s[0] would stop the program, it is what the slice holds: nil for a slice variable as it starts (section 4) and for [], and for one cut empty from another, t[3..3], an address that mustn’t be read through, as the end of an array mustn’t. So a slice becomes a pointer and a length, for a record or for C, with no test for the empty one first:

+
type Value = record n: INT; p: ^U8; end;
+
+proc valueOf(s: []U8): Value;
+begin
+    return {n: LEN(s), p: PTR(s)};      (* "" too *)
+end;
+

and v.p[0..v.n] is the slice again (section 6.4), empty when v.n is 0, whatever v.p is. Reading through the pointer is as unchecked as through any pointer. PTR(a) of an array may be taken wherever the slice a[0..LEN(a)] may be made, and is an error wherever it may not.

COPY is a statement, as INC is. It copies the bytes of LEN(s) elements as one block, as an assignment of an array does, and is right when d and s overlap, as in COPY(a[1..n], a[0..n - 1]). It is checked as a slice is: past LEN(d), it stops the program, unless the module says check off;.

INC and DEC evaluate v once, so INC(a[f(i)]) calls f once. They read v and then write it: two accesses, even through a ^VOLATILE pointer, and not atomic; XADD is the atomic one.

For CAS, XCHG and XADD, p is a ^T or ^VOLATILE T where T is INT, UINT or a pointer type (INT or UINT for XADD), on every target. They are sequentially consistent, on every target; how a machine without atomic instructions makes them so is the implementation’s choice (appendix A). ### 6.9 Views

@@ -570,7 +583,7 @@ | rect(w, h): area := w * h; | dot: area := 0.0; end; -

match takes a variant, an enumeration, an integer type (a U8 included) or a string, a []U8; other types are an error. It runs the arm of the case s holds. An arm may name the case’s fields, in order, all of them; the names stand for those fields of s itself, so assigning to one changes s; if s isn’t a variable, they stand for the fields of a copy. An arm may also leave the fields unnamed. Every case must have an arm, and only one, unless there is an | else: arm, which must come last.

+

match takes a variant, an enumeration, an integer type (a U8 included) or a string, a []U8; other types are an error. It runs the arm of the case s holds. An arm may name the case’s fields, in order, all of them; the names stand for those fields of s itself, so assigning to one changes s; if s is a constant or a const parameter, they can’t be assigned; if s isn’t a variable, they stand for the fields of a copy. An arm may also leave the fields unnamed. Every case must have an arm, and only one, unless there is an | else: arm, which must come last.

match on an enumeration works the same way: each arm names one of the enumeration’s names, or several, separated by commas, for the arm to run when the value is any of them:

match op of
 | sPlus, sMinus: kind := additive;
@@ -670,10 +683,23 @@
                   | "var" { ident { "," ident } ":" Type ";" } .
 Signature         = "(" [ Params { ";" Params } [ ";" "..." ] ] ")" [ ":" Results ]
                   | [ ":" Results ] .
-Params            = [ "var" ] ident { "," ident } ":" Type .
+Params            = [ "var" | "const" ] ident { "," ident } ":" Type .
 Results           = Type | "(" Type { "," Type } ")" .

A procedure without parameters may leave out the parentheses, both where it is declared (proc main*;) and where it is called (Out.ln). Used without parentheses in an expression, a procedure is a procedure value, not a call.

Parameters. A value parameter is a copy: the procedure may change it, and the caller’s variable stays as it was. A var parameter is the caller’s variable itself; its argument must be a variable of exactly the parameter’s type.

+

A const parameter is the caller’s variable too, read in place, whatever its size, with nothing copied; the procedure may only read it. It may not assign it or a part of it (a field, an element of an array in it), give it or a part of it to a var parameter, take the ADR of either, write it through a view (section 6.9), or assign the names a match arm gives its fields. What a slice or a pointer in it points at isn’t part of it: the procedure may write through them, as it may through a value parameter’s; and a slice it makes of an array in it, to read, is a slice like any other, which writes the caller’s array if written through. const keeps the procedure from changing the variable by its name, not every path to its bytes. Its argument is any expression of the parameter’s type: a variable or a constant is passed in place, anything else as a temporary of the statement, as an array a call returns is (below). If the variable changes while the procedure runs, through a var parameter, a pointer or another thread, the procedure sees the change.

+
type Parser = record args: [][]U8; at: INT; (* ... *) end;
+
+proc current(const p: Parser): []U8;     (* reads p, many words, in place *)
+begin
+    return p.args[p.at];
+end;
+
+proc advance(var p: Parser);             (* changes p *)
+begin
+    INC(p.at);
+end;
+

A procedure takes what it reads as a value when it is a single value or a slice, and as const when it is a record or an array; what it changes, as var; and a pointer only for what it keeps past the call, what may be nil, an allocator, or what C or the system takes.

Results. A procedure returns nothing, one value, or several. A call that returns several values can only stand on the right of a multiple assignment, alone as a statement, or alone after return in a procedure whose results are of the same types, in the same order, which then returns them as they are: return divmod(n, 2);. A procedure that can fail has an ERROR as its last result (section 5.8), which try passes on (section 7.8).

An array a call returns lives to the end of the statement the call is in. A slice of it may be used there, indexed, passed or compared; one kept past the statement, in a variable or anywhere else, points at what is gone, and is the exception of section 10:

s := f('a')[0..4];     (* f returns a [8]U8: s is undefined after this *)
@@ -706,7 +732,7 @@
     ret;
 end rdtsc;

A label, name:, names the place of the instruction after it, within the procedure. A constant of the module may stand wherever a number does. Any bytes may be written with db, as in db 0FH, 31H;, for an instruction the assembler doesn’t know.

-

It is called like any procedure, with the System V convention: integer and pointer arguments arrive in rdi, rsi, rdx, rcx, r8 and r9, F32 and F64 ones in xmm0 to xmm7, and the result goes in rax (and rdx for a second) or xmm0. Its parameters and results are therefore of the types C can take (section 9), or slices, at most six integer and eight real parameters, and at most two results. A slice is two integers, as System V passes a struct of them: as a parameter its address arrives in one register and its length in the next, the two counting among the six; as the result its address goes in rax and its length in rdx, and it is the only result. The instructions are the whole procedure, ret included; they must keep rbx, rbp, rsp and r12 to r15 as they found them. The compiler doesn’t look past what they say.

+

It is called like any procedure, with the System V convention: integer and pointer arguments, and the addresses of var and const ones, arrive in rdi, rsi, rdx, rcx, r8 and r9, F32 and F64 ones in xmm0 to xmm7, and the result goes in rax (and rdx for a second) or xmm0. Its parameters and results are therefore of the types C can take (section 9), or slices, at most six integer and eight real parameters, and at most two results. A slice is two integers, as System V passes a struct of them: as a parameter its address arrives in one register and its length in the next, the two counting among the six; as the result its address goes in rax and its length in rdx, and it is the only result. The instructions are the whole procedure, ret included; they must keep rbx, rbp, rsp and r12 to r15 as they found them. The compiler doesn’t look past what they say.

9. Calling C

ExternDeclaration = "extern" ( "proc" IdentDef Signature
                              | "var" IdentDef ":" Type ) .
@@ -733,7 +759,7 @@ proc exit*(status: INT); proc trace*; (* the calls under way, on standard error *)

Rt.trace says on standard error the calls under way, from the one that calls it out, each with its variables, as a program that stops does.

-

Defined behaviour. Every variable starts at zero, integers wrap, and indexing arrays and slices is checked, so a program’s behaviour is defined by this report, with one exception: memory reached other than through a checked variable. Dereferencing a stale or made-up pointer, indexing through a pointer, a slice kept after the call whose frame holds what it points at (section 7.3), a slice of an array a call returned kept past its statement (section 8), an index out of range in a module that says check off;, writing a string’s bytes, a code procedure that breaks its rules, and C code can read or write any memory, and what follows isn’t defined. Dereferencing nil, dividing by zero, calling a nil procedure and running out of stack stop the program, on every target, with status 2, as a failed check does. Before it stops, the program prints to standard error where it was, as file, line and column, and why, as far as it can tell: a nil pointer, a nil procedure, a stack overflow, a bad address or a division fault; then the calls under way, each with its variables of a basic, enumeration, set or pointer type. Whether the machine catches these or the compiled code checks for them is the implementation’s choice (appendix A); that they stop the program isn’t.

+

Defined behaviour. Every variable starts at zero, integers wrap, and indexing arrays and slices is checked, so a program’s behaviour is defined by this report, with one exception: memory reached other than through a checked variable. Dereferencing a stale or made-up pointer, indexing through a pointer, a slice kept after the call whose frame holds what it points at (section 7.3), a slice of an array a call returned, or of a temporary given to a const parameter, kept past its statement (section 8), an index out of range in a module that says check off;, writing a string’s bytes, a code procedure that breaks its rules, and C code can read or write any memory, and what follows isn’t defined. Dereferencing nil, dividing by zero, calling a nil procedure and running out of stack stop the program, on every target, with status 2, as a failed check does. Before it stops, the program prints to standard error where it was, as file, line and column, and why, as far as it can tell: a nil pointer, a nil procedure, a stack overflow, a bad address or a division fault; then the calls under way, each with its variables of a basic, enumeration, set or pointer type. Whether the machine catches these or the compiled code checks for them is the implementation’s choice (appendix A); that they stop the program isn’t.

Separate compilation. An importer depends only on a module’s interface: what it exports, as an importer sees it, never its source or its code. An implementation that compiles modules on its own makes the same program as if every module were compiled together (appendix A).

Errors. A program that breaks a rule of this report that says it is an error isn’t a raz program, and an implementation must reject it: say what is wrong and make no executable. Such a rule is one whose breach would leave the program with no meaning this report can give: a mistake of types, a name that isn’t declared or is declared twice, an assignment to what is read-only, a call with the wrong number of arguments, a type name or a procedure with no result used as a value, type arguments given to a module that isn’t generic, or too many, an import that can’t be found, a procedure declared forward and never defined, a module that imports itself. A fault that is only a lint isn’t an error: a name declared and never used, or a result that a call standing on its own drops (Sys.write(fd, s);, where _ := Sys.write(fd, s); says it is meant). A program with one is valid, and an implementation may warn of it. The text of its messages, how many it reports and which warnings it gives are its own (appendix A).

11. Versions

@@ -742,7 +768,7 @@

Appendix A. What an implementation chooses

Everything in this report binds every implementation of raz, except what follows, which each chooses for itself and documents. This compiler’s choices are in doc/compiler.md, under “This compiler’s choices”. The programs in conform/ are how an implementation shows that it follows this report: it passes them all, its reals aside where its target has none; conform/check.sh runs them.

    -
  • The target. Which machines and systems it compiles for, and the names of their files (linux-x86_64, section 3); for each, the size of an address, and so of INT, and whether it has reals.
  • +
  • The target. Which machines and systems it compiles for, and the names of their files (linux-x86_64, section 3); for each, the size of an address, and so of INT, whether it has reals, and which C library a program that uses C is linked against.
  • Separate compilation. Whether modules are compiled on their own, and if so into what: the object file, its format, the form of the code in it, when one is out of date, and how an instance is named so that the program keeps one (section 10). This compiler compiles every module of a program together, and writes no object files.
  • Atomics. How CAS, XCHG and XADD are made sequentially consistent on a machine without atomic instructions (section 6.8): on one with a single processor, by holding off interrupts while they run, for one.
  • The calling convention. On x86-64 Linux it is System V (sections 8 and 9); elsewhere it is the C library’s own, so that extern procedures and callbacks work. How a procedure returns several results, and how its frame is laid out, are the implementation’s.
  • @@ -848,7 +874,7 @@ | "var" { ident { "," ident } ":" Type ";" } . Signature = "(" [ Params { ";" Params } [ ";" "..." ] ] ")" [ ":" Results ] | [ ":" Results ] . -Params = [ "var" ] ident { "," ident } ":" Type . +Params = [ "var" | "const" ] ident { "," ident } ":" Type . Results = Type | "(" Type { "," Type } ")" . ExternDeclaration = "extern" ( "proc" IdentDef Signature | "var" IdentDef ":" Type ) . @@ -870,7 +896,7 @@ Sys -system calls: open, openMode, openRead, create, read, write, seek, position, truncate, sync, syncAll, lock, close, dup, dupTo, dupAbove, keepOnExec, mmap, munmap, isTerminal, yield, exit; files and directories, rename, remove, removeDir, makeDir, chmod, access, umask, symlink, readLink, info, linkInfo, infoOf, openDir, nextEntry, entryKind, closeDir; the terminal, rawMode, restoreMode, getMode, setMode, termSize, ready; the environment, env, envAt, setEnv, workDir, setWorkDir; programs, spawn, exec and execve, pipes and signals; the user, the machine, time used and limits; time, clock, now, sleep; random; what an errno means, errorText; sockets, among them datagrams served and files passed; and memory shared through a file. One file per target, and Sys.raz over the C library for the others +system calls: open, openMode, openRead, create, read, write, seek, position, truncate, sync, syncAll, lock, close, dup, dupTo, dupAbove, keepOnExec, mmap, munmap, isTerminal, yield, exit; files and directories, rename, remove, removeDir, makeDir, chmod, access, umask, symlink, readLink, info, linkInfo, infoOf, openDir, nextEntry, entryKind, closeDir; the terminal, rawMode, restoreMode, getMode, setMode, termSize, ready; the environment, env, envAt, setEnv, workDir, setWorkDir; programs, spawn, exec and execve, pipes and signals; the user, the machine, time used and limits; time, clock, now, sleep; random; errors, by name, and what one means, errorText; sockets, among them datagrams served and files passed; and memory shared through a file. One file per target, and Sys.raz over the C library for the others, which takes what each C library fixes from CAbi Out @@ -979,14 +1005,14 @@ base*: Mem.Allocator; (* first, so that ^Arena(a) finds the rest *) ... end; -proc init*(ar: ^Arena; size: INT): BOOL; (* an arena of size bytes; false if the system has none *) -proc reset*(ar: ^Arena); (* every allocation forgotten; the memory used again *) -proc done*(ar: ^Arena); (* its memory given back *) +proc init*(var ar: Arena; size: INT): BOOL; (* an arena of size bytes; false if the system has none *) +proc reset*(var ar: Arena); (* every allocation forgotten; the memory used again *) +proc done*(var ar: Arena); (* its memory given back *)

    NEW(p, a) calls a^.alloc. Heap is the general allocator. An arena hands out memory from one block: its free does nothing, and reset forgets everything.

    module Lock;
     type Lock* = record ... end;
    -proc take*(l: ^Lock);
    -proc give*(l: ^Lock);
    +proc take*(var l: Lock);
    +proc give*(var l: Lock);
     
     module Thread;
     const Failed*: ERROR = "can't start a thread";
    @@ -996,8 +1022,8 @@
     proc spawn*(p: proc(arg: ^U8); arg: ^U8): (^Thread, ERROR);   (* p(arg) in a new thread *)
     proc join*(t: ^Thread);         (* waits for t to end, then frees its stack *)
     proc signal*(t: ^Thread; sig: INT): INT;   (* sig sent to t alone: 0, or minus an errno *)
    -proc lock*(m: ^Mutex);
    -proc unlock*(m: ^Mutex);
    +proc lock*(var m: Mutex); +proc unlock*(var m: Mutex);

    A Lock is for short sections: a thread that finds it taken tries again, giving up the processor now and then. A Mutex sleeps. Each of Thread’s threads runs on a stack of its own, with a page below it that can’t be touched, so that running off the stack stops the program with a message, as in the main thread. In a program that uses C, Thread makes its threads with C’s pthread_create, so that C’s library knows of them; in one that doesn’t, with the system’s own calls. The program is the same either way.

    Sys.kill signals a program, and the system gives the signal to any of its threads; signal gives it to t alone, until t is joined, and is -3 (ESRCH) once t has ended. With Sys.handle(sig), a call t waits in, a read or a ready, fails with -4, so that one thread can break into another’s wait, as ^C breaks into the main thread’s. A signal sent before t begins its wait is only noted, so a program sends it again until t says it has stopped.

    module Out;
    @@ -1022,7 +1048,7 @@
     end;
     
     end Both.
    -

    Sys gives every target the same procedures, so that a program that needs only these runs wherever raz does: through system calls on Linux, through the C library elsewhere. A result that can fail is a number, minus an errno, as on Linux; 0 is success.

    +

    Sys gives every target the same procedures, so that a program that needs only these runs wherever raz does: through system calls on Linux, through the C library elsewhere. A result that can fail is a number, minus an errno, as on Linux; 0 is success. The number is Linux’s on every target: Sys over another system’s C library gives the Linux errno of the same name, and a program tests it by the names below; one with no Linux twin keeps its own number. Sys.raz, the Sys over C, keeps to POSIX’s names; what a C library fixes for its target, the layouts of its structs, its numbers and the names that differ, it takes from CAbi, one file per target, which tools/cabi.c, compiled there, writes.

    module Sys;
     const
         stdin* = 0; stdout* = 1; stderr* = 2;
    @@ -1035,6 +1061,16 @@
         (* the limits limit and setLimit take, by their numbers on Linux; each target has its own *)
         limitCpu* = 0; limitFileSize* = 1; limitData* = 2; limitStack* = 3;
         limitCore* = 4; limitProcs* = 6; limitFiles* = 7; limitMemory* = 9;
    +    (* errors, minus Linux's errnos on every target *)
    +    errPerm* = -1; errNoEntry* = -2; errNoProcess* = -3; errIntr* = -4;
    +    errIo* = -5; errBadFd* = -9; errChild* = -10; errAgain* = -11;
    +    errNoMemory* = -12; errDenied* = -13; errExists* = -17;
    +    errNotDir* = -20; errIsDir* = -21; errInvalid* = -22;
    +    errNotTerminal* = -25; errNoSpace* = -28; errPipe* = -32;
    +    errNameTooLong* = -36; errNotEmpty* = -39; errLoop* = -40;
    +    errAddrInUse* = -98; errNetUnreach* = -101; errConnReset* = -104;
    +    errTimedOut* = -110; errRefused* = -111; errHostUnreach* = -113;
    +    errInProgress* = -115;
     
     type
         Access* = (reading, writing, creating, exclusive, truncating, appending, executing);
    @@ -1105,10 +1141,10 @@
     proc infoOf*(fd: INT): (Info, INT);      (* the open file's *)
     proc space*(path: []U8): (I64, I64, INT);   (* the bytes free and in all on path's file system *)
     
    -proc openDir*(d: ^Dir; path: []U8): INT;
    -proc nextEntry*(d: ^Dir): ([]U8, BOOL);  (* a name, good until the next call; false at the end *)
    -proc entryKind*(d: ^Dir): Kind;          (* what the name nextEntry gave last is *)
    -proc closeDir*(d: ^Dir);
    +proc openDir*(var d: Dir; path: []U8): INT;
    +proc nextEntry*(var d: Dir): ([]U8, BOOL);  (* a name, good until the next call; false at the end *)
    +proc entryKind*(const d: Dir): Kind;        (* what the name nextEntry gave last is *)
    +proc closeDir*(var d: Dir);
     
     proc rawMode*(fd: INT): BOOL;      (* the terminal on fd: no echo, no lines, no signals *)
     proc restoreMode*(fd: INT);        (* as rawMode found it *)
    @@ -1220,8 +1256,8 @@
     proc hexVal*(c: U8): INT;             (* c's value as a hexadecimal digit, or -1 *)
     proc lower*(s: []U8);                 (* s's ASCII capitals made small, in place *)
     proc upper*(s: []U8);                 (* s's ASCII small letters made capitals, in place *)
    -proc join*(b: ^Buf.Buf; parts: [][]U8; sep: []U8);   (* the parts added to b, sep between each two *)
    -proc replace*(b: ^Buf.Buf; s, old, new: []U8);       (* s added to b, with new for each old in it *)
    +proc join*(var b: Buf.Buf; parts: [][]U8; sep: []U8);   (* the parts added to b, sep between each two *)
    +proc replace*(var b: Buf.Buf; s, old, new: []U8);       (* s added to b, with new for each old in it *)
     proc encode*(c: I32): ([4]U8, INT);   (* c in UTF-8: its bytes, and how many *)
     proc decode*(s: []U8): (I32, INT);    (* the character s starts with, and its length in bytes *)
     proc decodeLast*(s: []U8): (I32, INT);   (* the character s ends with, and its length in bytes *)
    @@ -1238,15 +1274,15 @@
     
     module Buf;
     type Buf* = record len*: INT; ... end;
    -proc init*(b: ^Buf; a: ^Mem.Allocator);
    -proc room*(b: ^Buf; n: INT): BOOL;    (* room for n more bytes; false if the allocator has none *)
    -proc add*(b: ^Buf; c: U8);
    -proc str*(b: ^Buf; s: []U8);
    -proc spare*(b: ^Buf; n: INT): []U8;   (* room for n more bytes, and those bytes, to fill *)
    -proc bytes*(b: ^Buf): []U8;           (* what it holds, until it next grows *)
    -proc cut*(b: ^Buf; n: INT);           (* only the first n bytes kept, its memory kept *)
    -proc reset*(b: ^Buf);                 (* emptied, its memory kept *)
    -proc done*(b: ^Buf);                  (* its memory given back *)
    +proc init*(var b: Buf; a: ^Mem.Allocator);
    +proc room*(var b: Buf; n: INT): BOOL;    (* room for n more bytes; false if the allocator has none *)
    +proc add*(var b: Buf; c: U8);
    +proc str*(var b: Buf; s: []U8);
    +proc spare*(var b: Buf; n: INT): []U8;   (* room for n more bytes, and those bytes, to fill *)
    +proc bytes*(const b: Buf): []U8;         (* what it holds, until it next grows *)
    +proc cut*(var b: Buf; n: INT);           (* only the first n bytes kept, its memory kept *)
    +proc reset*(var b: Buf);                 (* emptied, its memory kept *)
    +proc done*(var b: Buf);                  (* its memory given back *)
     
     module Fmt;
     type Arg* = variant
    @@ -1260,40 +1296,40 @@
     end;
     proc print*(f: []U8; args: []Arg);              (* to standard output *)
     proc eprint*(f: []U8; args: []Arg);             (* to standard error, once Out is flushed *)
    -proc write*(b: ^Buf.Buf; f: []U8; args: []Arg); (* added to b *)
    +proc write*(var b: Buf.Buf; f: []U8; args: []Arg); (* added to b *)
     
     module List(T);
     type
         Node* = record next*: ^Node; val*: T; end;
         List* = record head*: ^Node; len*: INT; ... end;
    -proc init*(l: ^List; a: ^Mem.Allocator);
    -proc push*(l: ^List; v: T): BOOL;     (* v at the front; false if the allocator has no room *)
    -proc pop*(l: ^List): (T, BOOL);       (* the front value, taken off; false if the list is empty *)
    -proc reverse*(l: ^List);
    -proc clear*(l: ^List);
    +proc init*(var l: List; a: ^Mem.Allocator);
    +proc push*(var l: List; v: T): BOOL;     (* v at the front; false if the allocator has no room *)
    +proc pop*(var l: List): (T, BOOL);       (* the front value, taken off; false if the list is empty *)
    +proc reverse*(var l: List);
    +proc clear*(var l: List);
     
     module Map(K, V; hash: proc(k: K): U64; eq: proc(a, b: K): BOOL);
     type Map* = record len*: INT; ... end;
    -proc init*(m: ^Map; a: ^Mem.Allocator);
    -proc put*(m: ^Map; k: K; v: V): BOOL;         (* k now maps to v; false if there was no room *)
    -proc remove*(m: ^Map; k: K): BOOL;            (* false if k wasn't there *)
    -proc get*(m: ^Map; k: K): (V, BOOL);          (* what k maps to, and whether it maps to anything *)
    -proc next*(m: ^Map; i: INT): (INT, K, V);     (* the entry after i *)
    -proc done*(m: ^Map);                          (* its memory given back, leaving it empty *)
    +proc init*(var m: Map; a: ^Mem.Allocator);
    +proc put*(var m: Map; k: K; v: V): BOOL;         (* k now maps to v; false if there was no room *)
    +proc remove*(var m: Map; k: K): BOOL;            (* false if k wasn't there *)
    +proc get*(const m: Map; k: K): (V, BOOL);        (* what k maps to, and whether it maps to anything *)
    +proc next*(const m: Map; i: INT): (INT, K, V);   (* the entry after i *)
    +proc done*(var m: Map);                          (* its memory given back, leaving it empty *)
     
     module Vec(T);
     type Vec* = record len*: INT; ... end;
    -proc init*(v: ^Vec; a: ^Mem.Allocator);
    -proc room*(v: ^Vec; n: INT): BOOL;    (* room for n more; false if the allocator has none *)
    -proc push*(v: ^Vec; x: T);            (* x added at the end *)
    -proc pop*(v: ^Vec): (T, BOOL);        (* the last element, taken off; false if the array is empty *)
    -proc add*(v: ^Vec): ^T;               (* a new element at the end, zero, to fill in place *)
    -proc tryPush*(v: ^Vec; x: T): BOOL;   (* push; false, and v as it was, if there is no room *)
    -proc tryAdd*(v: ^Vec): (^T, BOOL);    (* add; nil and false, and v as it was, if there is no room *)
    -proc resize*(v: ^Vec; n: INT);        (* n elements: cut short, or the new ones zero *)
    -proc all*(v: ^Vec): []T;              (* the elements, until it next grows *)
    -proc reset*(v: ^Vec);                 (* emptied, its memory kept *)
    -proc done*(v: ^Vec);                  (* its memory given back *)
    +proc init*(var v: Vec; a: ^Mem.Allocator);
    +proc room*(var v: Vec; n: INT): BOOL;    (* room for n more; false if the allocator has none *)
    +proc push*(var v: Vec; x: T);            (* x added at the end *)
    +proc pop*(var v: Vec): (T, BOOL);        (* the last element, taken off; false if the array is empty *)
    +proc add*(var v: Vec): ^T;               (* a new element at the end, zero, to fill in place *)
    +proc tryPush*(var v: Vec; x: T): BOOL;   (* push; false, and v as it was, if there is no room *)
    +proc tryAdd*(var v: Vec): (^T, BOOL);    (* add; nil and false, and v as it was, if there is no room *)
    +proc resize*(var v: Vec; n: INT);        (* n elements: cut short, or the new ones zero *)
    +proc all*(const v: Vec): []T;            (* the elements, until it next grows *)
    +proc reset*(var v: Vec);                 (* emptied, its memory kept *)
    +proc done*(var v: Vec);                  (* its memory given back *)
     
     module Sort(T; less: proc(a, b: T): BOOL);
     proc sort*(s: []T);
    @@ -1320,7 +1356,7 @@
     proc fromBits*(u: U64): F64;          (* the F64 whose bits are u *)
     proc mul*(a, b: U64): (U64, U64);     (* a times b: the low 64 bits of the product, and the high *)
     proc toReal*(s: []U8): (F64, BOOL);   (* s as a real, the F64 nearest it; false if it isn't one *)
    -

    A Buf, a List, a Map and a Vec take their memory from the allocator init gives them. Buf.add, str and spare stop the program, as a failed check does, if the allocator has no room; room asks first. A program reads into a Buf through spare, then adds what it read to len: s := Buf.spare(b, 4096); n := Sys.read(fd, s); if n > 0 then INC(b^.len, n); end;. cut takes back what was added, to a length it had: start := b^.len; ...; Buf.cut(b, start);; a length past len stops the program, as an index past the end does. A Vec is Buf for any T: one block, which doubles when it is full, so push costs the same on average however long it grows. all gives the elements as a slice, indexed and checked as any is, and v.len is their number; the slice, and what add gives, are good until the array next grows. pop takes the last element off, keeping the memory. push, add and resize stop the program, as Buf.add does, if the allocator has no room; room asks first: import Lines := Vec([]U8);. Fmt’s format takes the next argument at each {}; {{ and }} stand for { and }. A Map hashes and compares its keys with the procedures it is given: import Count := Map([]U8, INT, Str.hash, Str.eq);.

    +

    A Buf, a List, a Map and a Vec take their memory from the allocator init gives them. Buf.add, str and spare stop the program, as a failed check does, if the allocator has no room; room asks first. A program reads into a Buf through spare, then adds what it read to len: s := Buf.spare(b, 4096); n := Sys.read(fd, s); if n > 0 then INC(b.len, n); end;. cut takes back what was added, to a length it had: start := b.len; ...; Buf.cut(b, start);; a length past len stops the program, as an index past the end does. A Vec is Buf for any T: one block, which doubles when it is full, so push costs the same on average however long it grows. all gives the elements as a slice, indexed and checked as any is, and v.len is their number; the slice, and what add gives, are good until the array next grows. pop takes the last element off, keeping the memory. push, add and resize stop the program, as Buf.add does, if the allocator has no room; room asks first: import Lines := Vec([]U8);. Fmt’s format takes the next argument at each {}; {{ and }} stand for { and }. A Map hashes and compares its keys with the procedures it is given: import Count := Map([]U8, INT, Str.hash, Str.eq);.

    Str reads and writes UTF-8. encode writes a character, of at most 10FFFFH, in one to four bytes; a number that isn’t one becomes FFFDH, the character that stands for a wrong one. decode reads the first character of s, and gives FFFDH and 1 for a byte that doesn’t start one rightly, and 0 and 0 for an empty s: a continuation, a byte followed by too few continuations, a surrogate, a character beyond 10FFFFH or one spelled in more bytes than it needs. decodeLast reads the last character in the same way, to walk a string backwards. valid says that decode finds no such byte in s, and chars counts the characters, each such byte one. next walks a string a character at a time, as decode reads them: from 0, it gives the character at i and where the one after it starts, and 0 and -1 when i is at the end, or past it:

    c, i := Str.next(s, 0);
     while i >= 0 do
    @@ -1343,17 +1379,17 @@
     Str.putBE(packet[0..2], U64(port));

    Math.toReal reads a real as a constant is written (section 2), with a - or + before it if any, its point and the digits after it, or its exponent, left out if it has none, and e taken as E: 2, -0.5 and 1.5e-3 are reals to it. It gives the F64 nearest the number, and false for anything else, or a number too big for an F64.

    Map.next walks a map: from 0, it gives the next entry and the number to pass for the one after it, and -1 when there are no more. A walk sees each entry once if the map doesn’t change during it:

    -
    i, k, v := Names.next(ADR(names), 0);
    +
    i, k, v := Names.next(names, 0);
     while i >= 0 do
         Fmt.print("{} is {}\n", [Fmt.str(k), Fmt.int(v)]);
    -    i, k, v := Names.next(ADR(names), i);
    +    i, k, v := Names.next(names, i);
     end;

    Sort.sort puts s in the order less gives, in place, without memory of its own, in time n log n at most; two elements equal by less may change places. Math’s procedures are as C’s math.h has them, to within the last bit or so. Fmt.real(x, places) writes x with places digits after the point, at most 9, rounded to the nearest; from 1e15 on, with an exponent, as 1.50e17; and nan, inf and -inf as themselves.

    Files and Opt are what most programs need of their command line.

    module Files;
     proc arg*(i: INT): []U8;                     (* argument i; 0 is the program's name *)
    -proc read*(path: []U8; b: ^Buf.Buf): BOOL;   (* the whole file added to b *)
    -proc load*(path: []U8; b: ^Buf.Buf): INT;    (* as read: 0, or minus the errno that stopped it *)
    +proc read*(path: []U8; var b: Buf.Buf): BOOL;   (* the whole file added to b *)
    +proc load*(path: []U8; var b: Buf.Buf): INT;    (* as read: 0, or minus the errno that stopped it *)
     proc write*(path, data: []U8): BOOL;         (* the file made to hold data *)
     
     module Opt;
    @@ -1370,37 +1406,37 @@
             spelt*: []U8;   (* as it was written, no dashes: "b" or "bar"; to read only *)
             ...
         end;
    -proc init*(p: ^Parser; name: []U8; table: []Row);  (* the arguments from 1 on, by table *)
    -proc next*(p: ^Parser): BOOL;                     (* the next option; false when they end *)
    -proc operand*(p: ^Parser): ([]U8, BOOL);          (* the next operand; false when there are no more *)
    -proc at*(p: ^Parser): INT;                        (* the argument operand would give next *)
    -proc scope*(p: ^Parser; name: []U8);              (* subcommand name's options, from the word after it *)
    -proc number*(p: ^Parser; lo, hi: I64): I64;       (* the value just read, a number from lo to hi *)
    -proc refuse*(p: ^Parser; wants: []U8);            (* the value just read refused, as number refuses one *)
    -proc fail*(p: ^Parser; text: []U8);               (* the program's own mistake *)
    -

    Opt reads a command line by the rules of the C library’s getopt, with GNU’s long options, so that a program’s options behave as every other Unix program’s. The program describes itself once, in a table of Rows: its synopsis lines, its subcommands and its options. The help and the messages for mistakes are made from the table, so they can’t drift from it; the program’s test of p.letter is the only other place an option appears. The parser is a record the program owns, and the table a slice it keeps as long as the parser: a literal written in the call to init lives as long as the procedure that makes it.

    +proc init*(var p: Parser; name: []U8; table: []Row); (* the arguments from 1 on, by table *) +proc next*(var p: Parser): BOOL; (* the next option; false when they end *) +proc operand*(var p: Parser): ([]U8, BOOL); (* the next operand; false when there are no more *) +proc at*(var p: Parser): INT; (* the argument operand would give next *) +proc scope*(var p: Parser; name: []U8); (* subcommand name's options, from the word after it *) +proc number*(const p: Parser; lo, hi: I64): I64; (* the value just read, a number from lo to hi *) +proc refuse*(const p: Parser; wants: []U8); (* the value just read refused, as number refuses one *) +proc fail*(const p: Parser; text: []U8); (* the program's own mistake *)
    +

    Opt reads a command line by the rules of the C library’s getopt, with GNU’s long options, so that a program’s options behave as every other Unix program’s. The program describes itself once, in a table of Rows: its synopsis lines, its subcommands and its options. The help and the messages for mistakes are made from the table, so they can’t drift from it; the program’s test of p.letter is the only other place an option appears. The parser is a record the program owns, and the table a slice it keeps as long as the parser: a literal written in the call to init lives as long as the procedure that makes it, and a constant, const Rows: []Opt.Row = [...], as long as the program.

    A row’s scope is "" for the program itself, or a subcommand’s name: "start", or "remote.add" for a subcommand of remote. An option has a letter, a long name, or both. One with a long name only has a key of its own below '!' for a letter, so that the program can tell it from the others. With a value, the name the help and the messages give it, the option takes a value; with "" it is a flag. A value written in brackets, "[when]", may be left out, and is "" then: it is given only in the option’s own word, --color=always or -calways, never as the next, as getopt’s :: has it, and the help shows it as --color[=when].

    const wait = 1;     (* the key of --wait, which has no letter *)
     ...
    -Opt.init(ADR(p), "keep", [
    +Opt.init(p, "keep", [
         Opt.usage("", "keep [-v] [--wait secs] start ..."),
         Opt.sub("", "start", "start a job"),
         Opt.option("", 'v', "verbose", "", "say more"),
         Opt.option("", wait, "wait", "secs", "give the job secs to start"),
         Opt.usage("start", "keep start [-b label] name command [argument ...]"),
         Opt.option("start", 'b', "bar", "label", "show the job in the bar as label")]);
    -while Opt.next(ADR(p)) do
    +while Opt.next(p) do
         if p.letter = 'v' then verbose := true;
    -    elsif p.letter = wait then secs := Opt.number(ADR(p), 1, 600);
    +    elsif p.letter = wait then secs := Opt.number(p, 1, 600);
         end;
     end;
    -w, ok := Opt.operand(ADR(p));
    -if not ok or (w # "start") then Opt.fail(ADR(p), "no command; see keep -h"); end;
    -Opt.scope(ADR(p), "start");
    -while Opt.next(ADR(p)) do
    +w, ok := Opt.operand(p);
    +if not ok or (w # "start") then Opt.fail(p, "no command; see keep -h"); end;
    +Opt.scope(p, "start");
    +while Opt.next(p) do
         if p.letter = 'b' then bar := p.value; end;
     end;
    -job, ok := Opt.operand(ADR(p));
    +job, ok := Opt.operand(p);

    The rules are getopt’s:

    • Flags may share a dash: -lw is -l -w. A letter’s value is the rest of its word, -bdev, or the whole next word, -b dev, even one that starts with a dash or is empty; in a group, the first letter that takes a value takes the rest, -qn12.
    • @@ -1409,8 +1445,8 @@
    • Each scope has its own options. An option given twice is read twice.

    number reads the value as Str.toInt does. operand reads what options are left first, and the program doesn’t see them. So does at, which says where the operands are: the arguments from operand’s next on are Files.arg(i) for i from at(p) to ARGC() - 1, so that an interpreter hands a script its arguments as they are:

    -
    script, ok := Opt.operand(ADR(p));       (* tery file arg ... *)
    -first := Opt.at(ADR(p));                 (* file's own arguments, from here on *)
    +
    script, ok := Opt.operand(p);       (* tery file arg ... *)
    +first := Opt.at(p);                 (* file's own arguments, from here on *)

    -h or --help among a scope’s options prints its help on standard output and ends the program with status 0. init and scope answer it, looking through the scope’s options before next gives one, so that the program has done nothing yet: keep -v -h -x prints the help, and the program never sees -v, nor the mistake. The help is the scope’s synopsis lines, a blank line, and its subcommands, its options and the help itself, each with its line of help:

    usage: keep start [-b label] name command [argument ...]
     
    @@ -1420,7 +1456,7 @@
     

    A mistake on the command line is a sentence on standard error, the program’s name first, then the scope’s synopsis lines, as the help begins, and status 2:

    keep: unknown option -x
     usage: keep start [-b label] name command [argument ...]
    -

    The sentences are unknown option -x (or --name, up to its =), -b needs a label, --follow takes no value and --wait wants a number from 1 to 600, not '0'; for a number with no top, given the largest I64 for hi, --jobs wants a number from 1 up, not '0'. refuse refuses a value the program reads itself, as number refuses one, naming the option as the user wrote it, -b or --bar: Opt.refuse(ADR(p), "a label with no spaces") writes keep: -b wants a label with no spaces, not 'a b', and the synopsis lines. p.spelt is that spelling, for the program’s own sentences. fail writes the program’s own mistakes the same way, but alone, so that the sentence can say where the help is: keep: no command; see keep -h.

    +

    The sentences are unknown option -x (or --name, up to its =), -b needs a label, --follow takes no value and --wait wants a number from 1 to 600, not '0'; for a number with no top, given the largest I64 for hi, --jobs wants a number from 1 up, not '0'. refuse refuses a value the program reads itself, as number refuses one, naming the option as the user wrote it, -b or --bar: Opt.refuse(p, "a label with no spaces") writes keep: -b wants a label with no spaces, not 'a b', and the synopsis lines. p.spelt is that spelling, for the program’s own sentences. fail writes the program’s own mistakes the same way, but alone, so that the sentence can say where the help is: keep: no command; see keep -h.

    A mistake in the table is the program’s, not its user’s. init checks the table before it reads a word, and ends the program with status 1: keep: option table, row 3: the option is in the scope already. The others are an option with neither a letter nor a long name, a long name with = in it, a letter -, a value with one bracket but not the other, and --help in the table, since it is Opt’s.

    Width says how many columns of a terminal text takes, for a program with a screen that wraps its lines and cuts them at the window’s edge.

    module Width;
    diff --git a/site/public/tour/defer.html b/site/public/tour/defer.html
    index 98e8dc7..88a74a5 100644
    --- a/site/public/tour/defer.html
    +++ b/site/public/tour/defer.html
    @@ -154,16 +154,16 @@
     var b: Buf.Buf;
     begin
         if n < 0 then return false; end;
    -    Buf.init(ADR(b), Heap.heap);
    -    defer Buf.done(ADR(b));            (* freed on every way out below *)
    -    Buf.str(ADR(b), "n is ");
    +    Buf.init(b, Heap.heap);
    +    defer Buf.done(b);            (* freed on every way out below *)
    +    Buf.str(b, "n is ");
         if n > 9 then
    -        Buf.str(ADR(b), "large");
    -        Out.str(Buf.bytes(ADR(b))); Out.ln;
    +        Buf.str(b, "large");
    +        Out.str(Buf.bytes(b)); Out.ln;
             return true;
         end;
    -    Buf.str(ADR(b), "small");
    -    Out.str(Buf.bytes(ADR(b))); Out.ln;
    +    Buf.str(b, "small");
    +    Out.str(Buf.bytes(b)); Out.ln;
         return true;
     end;
     
    diff --git a/site/public/tour/hello.html b/site/public/tour/hello.html
    index f284c9e..868e03d 100644
    --- a/site/public/tour/hello.html
    +++ b/site/public/tour/hello.html
    @@ -70,7 +70,7 @@
     $ raz run Quiet.raz
     hello, again
     $ ls -l Quiet | awk '{print $5, "bytes"}'
    -28472 bytes
    +28440 bytes

    The program is a static executable with no run time besides the code it uses, so it is a few kilobytes, and runs without any library installed.

    What Out can write

    Out is the library's buffered output. It writes strings, single characters, numbers in decimal or hexadecimal, and a line feed. A string is written as it is, with \n for a line feed, \t for a tab, \" and \\; or between backquotes, as a raw string with no escapes at all, which may run over lines (lesson 6).

    diff --git a/site/public/tour/memory.html b/site/public/tour/memory.html index 1725662..9a7af67 100644 --- a/site/public/tour/memory.html +++ b/site/public/tour/memory.html @@ -68,10 +68,10 @@ Mem.free(Heap.heap, ^U8(n)); end; Out.ln; - if not Arena.init(ADR(ar), 100000) then return; end; + if not Arena.init(ar, 100000) then return; end; for i := 1 to 1000 do top := push(top, i, ADR(ar.base)); end; Out.int(top^.val); Out.ln; - Arena.done(ADR(ar)); (* every node at once *) + Arena.done(ar); (* every node at once *) end; end Stack. @@ -112,18 +112,18 @@ proc main*; var ar: Arena.Arena; small: Arena.Arena; list: ^Item; begin - if not Arena.init(ADR(ar), 1000000) then return; end; + if not Arena.init(ar, 1000000) then return; end; list := make(1000, ADR(ar.base)); Out.int(count(list)); Out.str(" items from a big arena\n"); - Arena.reset(ADR(ar)); (* every allocation forgotten *) + Arena.reset(ar); (* every allocation forgotten *) list := make(10, ADR(ar.base)); Out.int(count(list)); Out.str(" after a reset\n"); - Arena.done(ADR(ar)); + Arena.done(ar); - if not Arena.init(ADR(small), 4096) then return; end; + if not Arena.init(small, 4096) then return; end; list := make(1000, ADR(small.base)); if list = nil then Out.str("a small arena ran out, and said so\n"); end; - Arena.done(ADR(small)); + Arena.done(small); end; end Pool. @@ -164,21 +164,21 @@ proc main*; var b: Buf.Buf; i: INT; begin - Buf.init(ADR(b), Heap.heap); - defer Buf.done(ADR(b)); + Buf.init(b, Heap.heap); + defer Buf.done(b); for i := 1 to 5 do - Buf.str(ADR(b), "item "); - Buf.add(ADR(b), U8('0' + i)); - Buf.add(ADR(b), ','); + Buf.str(b, "item "); + Buf.add(b, U8('0' + i)); + Buf.add(b, ','); end; - Out.str(Buf.bytes(ADR(b))); Out.ln; + Out.str(Buf.bytes(b)); Out.ln; Out.int(b.len); Out.str(" bytes\n"); - Buf.reset(ADR(b)); - Str.join(ADR(b), ["red", "green", "blue"], ", "); - Out.str(Buf.bytes(ADR(b))); Out.ln; - Buf.reset(ADR(b)); - Str.replace(ADR(b), "a-b-c", "-", " and "); - Out.str(Buf.bytes(ADR(b))); Out.ln; + Buf.reset(b); + Str.join(b, ["red", "green", "blue"], ", "); + Out.str(Buf.bytes(b)); Out.ln; + Buf.reset(b); + Str.replace(b, "a-b-c", "-", " and "); + Out.str(Buf.bytes(b)); Out.ln; end; end Build. diff --git a/site/public/tour/records.html b/site/public/tour/records.html index d7478dc..c067482 100644 --- a/site/public/tour/records.html +++ b/site/public/tour/records.html @@ -284,7 +284,66 @@ end Chain.
    40 30 20 10 
    -

    Save a program under its module’s name and run it with raz run Name.raz.

    + +

    A slice's pointer

    +

    A slice is a pointer and a length, and a record can keep the two apart: an interpreter keeps a string so, and C takes one so. LEN(s) is the length. The pointer looks like ADR(s[0]), the address of the first element, and that works until the slice is empty: then there is no first element, s[0] is out of range, and the program stops.

    +
    Empty.raz
    module Empty;
    +import Out;
    +
    +type Span = record p: ^U8; n: INT; end;
    +
    +proc spanOf(s: []U8): Span;
    +begin
    +    return {p: ADR(s[0]), n: LEN(s)};
    +end;
    +
    +proc main*;
    +var a, b: Span;
    +begin
    +    a := spanOf("one");
    +    Out.int(a.n); Out.ln;
    +    b := spanOf("");
    +    Out.int(b.n); Out.ln;
    +end;
    +
    +end Empty.
    +
    3
    +Empty.raz:8:22: index 0 is out of range for a length of 0
    +  in Empty.spanOf at Empty.raz:8:22
    +  in Empty.main at Empty.raz:16:5
    +
    +

    PTR(s) is the pointer itself, a ^U8 for a []U8, with no check. For a slice that isn't empty it is ADR(s[0]); for an empty one it is what the slice holds, nil for one never set. So nothing needs testing first, and sp.p[0..sp.n] makes the slice again, empty when sp.n is 0, whatever sp.p is:

    +
    Spans.raz
    module Spans;
    +import Out;
    +
    +type Span = record p: ^U8; n: INT; end;
    +
    +proc spanOf(s: []U8): Span;
    +begin
    +    return {p: PTR(s), n: LEN(s)};
    +end;
    +
    +proc text(sp: Span): []U8;
    +begin
    +    return sp.p[0..sp.n];
    +end;
    +
    +proc main*;
    +var words: [3]Span; i: INT;
    +begin
    +    words := [spanOf("one"), spanOf(""), spanOf("three")];
    +    for i := 0 to 2 do
    +        Out.int(words[i].n); Out.char(' ');
    +        Out.str(text(words[i])); Out.ln;
    +    end;
    +end;
    +
    +end Spans.
    +
    3 one
    +0 
    +5 three
    +
    +

    Of an array, PTR(a) is the address of its first element, a ^T where ADR(a) is a ^[n]T. Reading through the pointer is as unchecked as through any pointer: the length is yours to keep with it. The compiler says so when the two are mixed up: a slice given where a pointer is wanted is an error whose help says to write PTR(s) and LEN(s), and a pointer given where a slice is, p[0..n].

    Save a program under its module’s name and run it with raz run Name.raz.

    raz is under the ISC license.
    diff --git a/site/public/tour/threads.html b/site/public/tour/threads.html index eb14157..9077fb0 100644 --- a/site/public/tour/threads.html +++ b/site/public/tour/threads.html @@ -58,9 +58,9 @@ sum := sum + i; _ := XADD(ADR(hits), 1); end; - Thread.lock(ADR(m)); + Thread.lock(m); total := total + sum; - Thread.unlock(ADR(m)); + Thread.unlock(m); end; proc main*; @@ -124,10 +124,10 @@ var i: INT; begin for i := 1 to 10000 do - Thread.lock(ADR(m)); + Thread.lock(m); balance := balance + 5; INC(deposits); - Thread.unlock(ADR(m)); + Thread.unlock(m); end; end; diff --git a/site/public/tour/variants.html b/site/public/tour/variants.html index 882f973..5b722a3 100644 --- a/site/public/tour/variants.html +++ b/site/public/tour/variants.html @@ -51,7 +51,9 @@ dot; end; -proc area(s: Shape): F64; +const Some: []Shape = [circle(1.0), rect(2.0, 3.5), dot]; + +proc area(const s: Shape): F64; begin match s of | circle(r): return Math.pi * r * r; @@ -80,11 +82,10 @@ end; proc main*; -var shapes: [3]Shape; i: INT; warm: Colours; c: Colour; +var i: INT; warm: Colours; c: Colour; begin - shapes := [circle(1.0), rect(2.0, 3.5), dot]; - for i := 0 to 2 do - Fmt.print("{}\n", [Fmt.real(area(shapes[i]), 2)]); + for i := 0 to LEN(Some) - 1 do + Fmt.print("{}\n", [Fmt.real(area(Some[i]), 2)]); end; Fmt.print("{} {} {}\n", [Fmt.str(kind('7')), Fmt.str(kind('x')), Fmt.str(kind('+'))]);