raz / commit 0f9c12b3

commit
0f9c12b3d2f7732640d8128494248eda587164e9
author
Luis <42945842+ldiaz94@users.noreply.github.com>
date
parent
086e55c4
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.

patch · log

24 files changed, +323 -222

HANDOVER.md modified +11 -10

@@ -18,7 +18,7 @@
1818 |---|---|---|---|
1919 | `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 |
2020 | `v0.19.0` | `51a90a6` ("Report 2026-10.33 is followed; ...") | `raz 0.19.0, report 2026-10.33` | `217448cb6521c76a28d71499d70a5dfdebc2dbcbc81d6d41ed9d9590005772ed` |
21-| `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 |
21+| `v0.20.0` | `086e55c` ("Docs for v0.20.0: ...") | `raz 0.20.0, report 2026-10.34` | `bfa954d27d759e4ca7f7f33debb4705f25d5c05a097d86aa28b3260048b5d9cc` |
2222
2323 git tag -a v0.18.1 -m 'raz 0.18.1, report 2026-10.32' 88b18ba
2424 git push origin v0.18.1
@@ -28,16 +28,15 @@
2828 # gh api repos/ldiaz94/raz/releases/tags/v0.19.0 --jq '.assets[].name'
2929 # gh release download v0.19.0 -p '*.tar.gz' && sha256sum raz-0.19.0-*.tar.gz
3030 # it must be BOOT's; only then:
31- git tag -a v0.20.0 -m 'raz 0.20.0, report 2026-10.34' <commit>
31+ git tag -a v0.20.0 -m 'raz 0.20.0, report 2026-10.34' 086e55c
3232 git push origin v0.20.0
3333
34-`<commit>` is the commit whose subject is "Docs for v0.20.0", found by
35-`git log --oneline --grep='^Docs for v0.20.0'`; it is the one before
36-"site: v0.19.0 and v0.20.0". Check before tagging that `make check`
37-passes there, and that `src/Raz.raz` there says report 2026-10.34.
38-The site commit after it changes only
39-`site/` and this file, so the tag stays on the docs commit, as v0.18.1's
40-did.
34+`086e55c` is "Docs for v0.20.0"; the commit after it, "site: v0.19.0
35+and v0.20.0", changes only `site/`, `make dist` (which lends a
36+fetched BOOT tarball to its checkout) and this file, so the tag stays
37+on the docs commit, as v0.18.1's did. Check before tagging that `make
38+check` passes there. The sums of v0.19.0 and v0.20.0 are also in
39+`site/public/download/*.sha256`, which the website serves.
4140
4241 Before v0.19.0's release exists, CI on every push to `main` fails at
4342 `src/boot.sh` (it can't fetch the tarball `BOOT` names); that is
@@ -53,7 +52,9 @@
5352 `build/version.inc` set to `'0.19.0'` (its Makefile predates
5453 `VERSION`), which gave BOOT's sum, the same that the session before
5554 got with a local tag; v0.20.0's by `make dist REV=<commit>
56-VERSION=0.20.0`, which the Makefile now takes for this. So CI's
55+VERSION=0.20.0`, which the Makefile now takes for this, twice, with
56+the same sum; its `raz --version` says `raz 0.20.0, report
57+2026-10.34`. So CI's
5758 tarball for each tag must have the sum in the table; if one differs,
5859 the website's copy is wrong and must be replaced by CI's before
5960 anyone pins it (the site keeps a tarball once it has it).

Makefile (history) modified +2 -0

@@ -155,6 +155,8 @@
155155
156156 dist:
157157 rm -rf $(DIST) && git worktree prune && git worktree add -q --detach $(DIST) $(REV)
158+ # the tarball BOOT names, if fetched, lent to the checkout (src/boot.sh checks its sum)
159+ if [ -d build/boot ]; then mkdir -p $(DIST)/build/boot && cp build/boot/*.tar.gz $(DIST)/build/boot/; fi
158160 $(MAKE) -C $(DIST) raz man
159161 v=$$($(DIST)/raz --version | sed 's/^raz \([^,]*\),.*/\1/'); \
160162 d=raz-$$v-linux-x86_64; \

site/public/_redirects (history) modified +1 -1

@@ -1 +1 @@
1-/download/latest /download/raz-0.18.1-linux-x86_64.tar.gz 302
1+/download/latest /download/raz-0.20.0-linux-x86_64.tar.gz 302

site/public/advanced/allocators.html (history) modified +6 -6

@@ -172,16 +172,16 @@
172172 <span class="kw">var</span> c: Counted.Counted; b: Buf.Buf; l: Names.List; i: <span class="ty">INT</span>; p: ^<span class="ty">U8</span>;
173173 <span class="kw">begin</span>
174174 Counted.init(<span class="ty">ADR</span>(c), Heap.heap);
175- Buf.init(<span class="ty">ADR</span>(b), <span class="ty">ADR</span>(c.base));
176- <span class="kw">for</span> i := <span class="number">1</span> <span class="kw">to</span> <span class="number">200</span> <span class="kw">do</span> Buf.str(<span class="ty">ADR</span>(b), <span class="string">&quot;0123456789&quot;</span>); <span class="kw">end</span>;
175+ Buf.init(b, <span class="ty">ADR</span>(c.base));
176+ <span class="kw">for</span> i := <span class="number">1</span> <span class="kw">to</span> <span class="number">200</span> <span class="kw">do</span> Buf.str(b, <span class="string">&quot;0123456789&quot;</span>); <span class="kw">end</span>;
177177 Fmt.print(<span class="string">&quot;a buffer of {} bytes took {} allocations\n&quot;</span>,
178178 [Fmt.int(b.len), Fmt.int(c.allocs)]);
179- Buf.done(<span class="ty">ADR</span>(b));
179+ Buf.done(b);
180180
181- Names.init(<span class="ty">ADR</span>(l), <span class="ty">ADR</span>(c.base));
182- <span class="kw">for</span> i := <span class="number">1</span> <span class="kw">to</span> <span class="number">10</span> <span class="kw">do</span> _ := Names.push(<span class="ty">ADR</span>(l), <span class="string">&quot;x&quot;</span>); <span class="kw">end</span>;
181+ Names.init(l, <span class="ty">ADR</span>(c.base));
182+ <span class="kw">for</span> i := <span class="number">1</span> <span class="kw">to</span> <span class="number">10</span> <span class="kw">do</span> _ := Names.push(l, <span class="string">&quot;x&quot;</span>); <span class="kw">end</span>;
183183 Fmt.print(<span class="string">&quot;{} allocations in all, {} frees so far\n&quot;</span>, [Fmt.int(c.allocs), Fmt.int(c.frees)]);
184- Names.clear(<span class="ty">ADR</span>(l));
184+ Names.clear(l);
185185 Fmt.print(<span class="string">&quot;{} frees after clear\n&quot;</span>, [Fmt.int(c.frees)]);
186186
187187 p := Mem.alloc(<span class="ty">ADR</span>(c.base), <span class="number">64</span>, <span class="number">8</span>);

site/public/advanced/atomics.html (history) modified +6 -6

@@ -144,20 +144,20 @@
144144 type Lock* = record held: INT; end;
145145
146146 (* Takes l, waiting while another thread holds it. *)
147-proc take*(l: ^Lock);
147+proc take*(var l: Lock);
148148 var tries: INT;
149149 begin
150150 tries := 0;
151- while not CAS(ADR(l^.held), 0, 1) do
151+ while not CAS(ADR(l.held), 0, 1) do
152152 INC(tries);
153153 if tries = 64 then Sys.yield; tries := 0; end;
154154 end;
155155 end;
156156
157157 (* Gives up l, which the caller holds. *)
158-proc give*(l: ^Lock);
158+proc give*(var l: Lock);
159159 begin
160- _ := XCHG(ADR(l^.held), 0);
160+ _ := XCHG(ADR(l.held), 0);
161161 end;</code></pre>
162162 <p>And here is a use of it: a structure with two fields that must stay in step, which no single atomic can protect.</p>
163163 <div class="file"><span>Account.raz</span></div><pre class="code"><code><span class="kw">module</span> Account;
@@ -171,10 +171,10 @@
171171 <span class="kw">var</span> i: <span class="ty">INT</span>;
172172 <span class="kw">begin</span>
173173 <span class="kw">for</span> i := <span class="number">1</span> <span class="kw">to</span> <span class="number">20000</span> <span class="kw">do</span>
174- Lock.take(<span class="ty">ADR</span>(lock));
174+ Lock.take(lock);
175175 <span class="ty">INC</span>(deposits);
176176 <span class="ty">INC</span>(balance, <span class="number">3</span>);
177- Lock.give(<span class="ty">ADR</span>(lock));
177+ Lock.give(lock);
178178 <span class="kw">end</span>;
179179 <span class="kw">end</span>;
180180

site/public/advanced/collections.html (history) modified +31 -31

@@ -53,14 +53,14 @@
5353 <span class="kw">proc</span> main*;
5454 <span class="kw">var</span> l: Ints.List; n: ^Ints.Node; v: <span class="ty">INT</span>;
5555 <span class="kw">begin</span>
56- Ints.init(<span class="ty">ADR</span>(l), Heap.heap);
57- <span class="kw">defer</span> Ints.clear(<span class="ty">ADR</span>(l));
58- <span class="kw">for</span> v := <span class="number">1</span> <span class="kw">to</span> <span class="number">5</span> <span class="kw">do</span> _ := Ints.push(<span class="ty">ADR</span>(l), v * v); <span class="kw">end</span>;
59- Ints.reverse(<span class="ty">ADR</span>(l)); <span class="comment">(* oldest first *)</span>
56+ Ints.init(l, Heap.heap);
57+ <span class="kw">defer</span> Ints.clear(l);
58+ <span class="kw">for</span> v := <span class="number">1</span> <span class="kw">to</span> <span class="number">5</span> <span class="kw">do</span> _ := Ints.push(l, v * v); <span class="kw">end</span>;
59+ Ints.reverse(l); <span class="comment">(* oldest first *)</span>
6060 n := l.head;
6161 <span class="kw">while</span> n # <span class="ty">nil</span> <span class="kw">do</span> Out.int(n^.val); Out.char(<span class="string">&#x27; &#x27;</span>); n := n^.next; <span class="kw">end</span>;
6262 Out.ln;
63- v, _ := Ints.pop(<span class="ty">ADR</span>(l));
63+ v, _ := Ints.pop(l);
6464 Out.int(v); Out.str(<span class="string">&quot; popped, &quot;</span>); Out.int(l.len); Out.str(<span class="string">&quot; left\n&quot;</span>);
6565 <span class="kw">end</span>;
6666
@@ -76,13 +76,13 @@
7676 <span class="kw">proc</span> main*;
7777 <span class="kw">var</span> v: Ints.Vec; i: <span class="ty">INT</span>; s: []<span class="ty">INT</span>;
7878 <span class="kw">begin</span>
79- Ints.init(<span class="ty">ADR</span>(v), Heap.heap);
80- <span class="kw">defer</span> Ints.done(<span class="ty">ADR</span>(v));
81- <span class="kw">for</span> i := <span class="number">1</span> <span class="kw">to</span> <span class="number">1000</span> <span class="kw">do</span> Ints.push(<span class="ty">ADR</span>(v), i * i); <span class="kw">end</span>;
82- s := Ints.all(<span class="ty">ADR</span>(v));
79+ Ints.init(v, Heap.heap);
80+ <span class="kw">defer</span> Ints.done(v);
81+ <span class="kw">for</span> i := <span class="number">1</span> <span class="kw">to</span> <span class="number">1000</span> <span class="kw">do</span> Ints.push(v, i * i); <span class="kw">end</span>;
82+ s := Ints.all(v);
8383 Out.int(v.len); Out.str(<span class="string">&quot; squares, the last &quot;</span>); Out.int(s[<span class="ty">LEN</span>(s) - <span class="number">1</span>]); Out.ln;
84- Ints.resize(<span class="ty">ADR</span>(v), <span class="number">3</span>);
85- <span class="kw">for</span> i := <span class="number">0</span> <span class="kw">to</span> v.len - <span class="number">1</span> <span class="kw">do</span> Out.int(Ints.all(<span class="ty">ADR</span>(v))[i]); Out.char(<span class="string">&#x27; &#x27;</span>); <span class="kw">end</span>;
84+ Ints.resize(v, <span class="number">3</span>);
85+ <span class="kw">for</span> i := <span class="number">0</span> <span class="kw">to</span> v.len - <span class="number">1</span> <span class="kw">do</span> Out.int(Ints.all(v)[i]); Out.char(<span class="string">&#x27; &#x27;</span>); <span class="kw">end</span>;
8686 Out.ln;
8787 <span class="kw">end</span>;
8888
@@ -98,22 +98,22 @@
9898 <span class="kw">proc</span> main*;
9999 <span class="kw">var</span> m: Book.Map; age: <span class="ty">INT</span>; found, ok: <span class="ty">BOOL</span>; i: <span class="ty">INT</span>; v: <span class="ty">INT</span>;
100100 <span class="kw">begin</span>
101- Book.init(<span class="ty">ADR</span>(m), Heap.heap);
102- _ := Book.put(<span class="ty">ADR</span>(m), <span class="string">&quot;ada&quot;</span>, <span class="number">36</span>);
103- _ := Book.put(<span class="ty">ADR</span>(m), <span class="string">&quot;grace&quot;</span>, <span class="number">45</span>);
104- _ := Book.put(<span class="ty">ADR</span>(m), <span class="string">&quot;alan&quot;</span>, <span class="number">41</span>);
105- _ := Book.put(<span class="ty">ADR</span>(m), <span class="string">&quot;ada&quot;</span>, <span class="number">37</span>); <span class="comment">(* replaces *)</span>
106- age, found := Book.get(<span class="ty">ADR</span>(m), <span class="string">&quot;ada&quot;</span>);
101+ Book.init(m, Heap.heap);
102+ _ := Book.put(m, <span class="string">&quot;ada&quot;</span>, <span class="number">36</span>);
103+ _ := Book.put(m, <span class="string">&quot;grace&quot;</span>, <span class="number">45</span>);
104+ _ := Book.put(m, <span class="string">&quot;alan&quot;</span>, <span class="number">41</span>);
105+ _ := Book.put(m, <span class="string">&quot;ada&quot;</span>, <span class="number">37</span>); <span class="comment">(* replaces *)</span>
106+ age, found := Book.get(m, <span class="string">&quot;ada&quot;</span>);
107107 Fmt.print(<span class="string">&quot;ada: {} ({})\n&quot;</span>, [Fmt.int(age), Fmt.bool(found)]);
108- age, found := Book.get(<span class="ty">ADR</span>(m), <span class="string">&quot;linus&quot;</span>);
108+ age, found := Book.get(m, <span class="string">&quot;linus&quot;</span>);
109109 Fmt.print(<span class="string">&quot;linus: {} ({})\n&quot;</span>, [Fmt.int(age), Fmt.bool(found)]);
110- ok := Book.remove(<span class="ty">ADR</span>(m), <span class="string">&quot;alan&quot;</span>);
110+ ok := Book.remove(m, <span class="string">&quot;alan&quot;</span>);
111111 Fmt.print(<span class="string">&quot;{} entries, removed {}\n&quot;</span>, [Fmt.int(m.len), Fmt.bool(ok)]);
112112 v := <span class="number">0</span>;
113- i, _, age := Book.next(<span class="ty">ADR</span>(m), <span class="number">0</span>);
113+ i, _, age := Book.next(m, <span class="number">0</span>);
114114 <span class="kw">while</span> i &gt;= <span class="number">0</span> <span class="kw">do</span>
115115 <span class="ty">INC</span>(v, age);
116- i, _, age := Book.next(<span class="ty">ADR</span>(m), i);
116+ i, _, age := Book.next(m, i);
117117 <span class="kw">end</span>;
118118 Out.int(v); Out.str(<span class="string">&quot; years in all\n&quot;</span>);
119119 <span class="kw">end</span>;
@@ -151,22 +151,22 @@
151151 m: Count.Map; entries: Entries.Vec; i, k, found: <span class="ty">INT</span>;
152152 w, rest: []<span class="ty">U8</span>; key: []<span class="ty">U8</span>; v: <span class="ty">INT</span>; all: []Entry;
153153 <span class="kw">begin</span>
154- Count.init(<span class="ty">ADR</span>(m), Heap.heap);
155- <span class="kw">defer</span> Count.done(<span class="ty">ADR</span>(m));
154+ Count.init(m, Heap.heap);
155+ <span class="kw">defer</span> Count.done(m);
156156 w, rest := Str.field(Text);
157157 <span class="kw">while</span> <span class="ty">LEN</span>(w) &gt; <span class="number">0</span> <span class="kw">do</span>
158- k, _ := Count.get(<span class="ty">ADR</span>(m), w);
159- _ := Count.put(<span class="ty">ADR</span>(m), w, k + <span class="number">1</span>);
158+ k, _ := Count.get(m, w);
159+ _ := Count.put(m, w, k + <span class="number">1</span>);
160160 w, rest := Str.field(rest);
161161 <span class="kw">end</span>;
162- Entries.init(<span class="ty">ADR</span>(entries), Heap.heap);
163- <span class="kw">defer</span> Entries.done(<span class="ty">ADR</span>(entries));
164- found, key, v := Count.next(<span class="ty">ADR</span>(m), <span class="number">0</span>);
162+ Entries.init(entries, Heap.heap);
163+ <span class="kw">defer</span> Entries.done(entries);
164+ found, key, v := Count.next(m, <span class="number">0</span>);
165165 <span class="kw">while</span> found &gt;= <span class="number">0</span> <span class="kw">do</span>
166- Entries.push(<span class="ty">ADR</span>(entries), {word: key, n: v});
167- found, key, v := Count.next(<span class="ty">ADR</span>(m), found);
166+ Entries.push(entries, {word: key, n: v});
167+ found, key, v := Count.next(m, found);
168168 <span class="kw">end</span>;
169- all := Entries.all(<span class="ty">ADR</span>(entries));
169+ all := Entries.all(entries);
170170 Rank.sort(all);
171171 <span class="kw">for</span> i := <span class="number">0</span> <span class="kw">to</span> <span class="ty">LEN</span>(all) - <span class="number">1</span> <span class="kw">do</span>
172172 Fmt.print(<span class="string">&quot;{} {}\n&quot;</span>, [Fmt.int(all[i].n), Fmt.str(all[i].word)]);

site/public/advanced/files.html (history) modified +22 -22

@@ -55,15 +55,15 @@
5555 <span class="kw">begin</span>
5656 ok := Files.write(<span class="string">&quot;notes.txt&quot;</span>, <span class="string">&quot;first line\nsecond line\n&quot;</span>);
5757 <span class="kw">if</span> <span class="kw">not</span> ok <span class="kw">then</span> Out.str(<span class="string">&quot;can&#x27;t write\n&quot;</span>); <span class="kw">return</span>; <span class="kw">end</span>;
58- Buf.init(<span class="ty">ADR</span>(b), Heap.heap);
59- <span class="kw">defer</span> Buf.done(<span class="ty">ADR</span>(b));
60- ok := Files.read(<span class="string">&quot;notes.txt&quot;</span>, <span class="ty">ADR</span>(b));
58+ Buf.init(b, Heap.heap);
59+ <span class="kw">defer</span> Buf.done(b);
60+ ok := Files.read(<span class="string">&quot;notes.txt&quot;</span>, b);
6161 <span class="kw">if</span> ok <span class="kw">then</span>
62- Out.int(b.len); Out.str(<span class="string">&quot; bytes: &quot;</span>); Out.str(Buf.bytes(<span class="ty">ADR</span>(b)));
62+ Out.int(b.len); Out.str(<span class="string">&quot; bytes: &quot;</span>); Out.str(Buf.bytes(b));
6363 <span class="kw">end</span>;
64- ok := Files.read(<span class="string">&quot;missing.txt&quot;</span>, <span class="ty">ADR</span>(b));
64+ ok := Files.read(<span class="string">&quot;missing.txt&quot;</span>, b);
6565 <span class="kw">if</span> <span class="kw">not</span> ok <span class="kw">then</span> Out.str(<span class="string">&quot;missing.txt: not there\n&quot;</span>); <span class="kw">end</span>;
66- <span class="kw">if</span> Files.load(<span class="string">&quot;missing.txt&quot;</span>, <span class="ty">ADR</span>(b)) = -<span class="number">2</span> <span class="kw">then</span> Out.str(<span class="string">&quot;missing.txt: ENOENT\n&quot;</span>); <span class="kw">end</span>;
66+ <span class="kw">if</span> Files.load(<span class="string">&quot;missing.txt&quot;</span>, b) = -<span class="number">2</span> <span class="kw">then</span> Out.str(<span class="string">&quot;missing.txt: ENOENT\n&quot;</span>); <span class="kw">end</span>;
6767 <span class="kw">end</span>;
6868
6969 <span class="kw">end</span> Notes.</code></pre>
@@ -146,22 +146,22 @@
146146 _ := Sys.makeDir(<span class="string">&quot;proj/src&quot;</span>);
147147 put(<span class="string">&quot;proj/b.txt&quot;</span>, <span class="string">&quot;bb&quot;</span>);
148148 put(<span class="string">&quot;proj/a.txt&quot;</span>, <span class="string">&quot;a&quot;</span>);
149- <span class="kw">if</span> Sys.openDir(<span class="ty">ADR</span>(d), <span class="string">&quot;proj&quot;</span>) &lt; <span class="number">0</span> <span class="kw">then</span> <span class="kw">return</span>; <span class="kw">end</span>;
149+ <span class="kw">if</span> Sys.openDir(d, <span class="string">&quot;proj&quot;</span>) &lt; <span class="number">0</span> <span class="kw">then</span> <span class="kw">return</span>; <span class="kw">end</span>;
150150 n := <span class="number">0</span>;
151- name, more := Sys.nextEntry(<span class="ty">ADR</span>(d));
151+ name, more := Sys.nextEntry(d);
152152 <span class="kw">while</span> more <span class="kw">do</span>
153153 copy, ok := Str.copy(Heap.heap, name);
154154 <span class="kw">if</span> ok <span class="kw">and</span> (n &lt; <span class="number">16</span>) <span class="kw">then</span> names[n] := copy; <span class="ty">INC</span>(n); <span class="kw">end</span>;
155- name, more := Sys.nextEntry(<span class="ty">ADR</span>(d));
155+ name, more := Sys.nextEntry(d);
156156 <span class="kw">end</span>;
157- Sys.closeDir(<span class="ty">ADR</span>(d));
157+ Sys.closeDir(d);
158158 Order.sort(names[<span class="number">0</span>..n]);
159- Buf.init(<span class="ty">ADR</span>(path), Heap.heap);
159+ Buf.init(path, Heap.heap);
160160 <span class="kw">for</span> i := <span class="number">0</span> <span class="kw">to</span> n - <span class="number">1</span> <span class="kw">do</span>
161- Buf.reset(<span class="ty">ADR</span>(path));
162- Buf.str(<span class="ty">ADR</span>(path), <span class="string">&quot;proj/&quot;</span>);
163- Buf.str(<span class="ty">ADR</span>(path), names[i]);
164- info, err := Sys.info(Buf.bytes(<span class="ty">ADR</span>(path)));
161+ Buf.reset(path);
162+ Buf.str(path, <span class="string">&quot;proj/&quot;</span>);
163+ Buf.str(path, names[i]);
164+ info, err := Sys.info(Buf.bytes(path));
165165 Out.str(names[i]);
166166 <span class="kw">if</span> err &lt; <span class="number">0</span> <span class="kw">then</span> Out.str(<span class="string">&quot; ?&quot;</span>);
167167 <span class="kw">elsif</span> info.dir <span class="kw">then</span> Out.str(<span class="string">&quot;/&quot;</span>);
@@ -170,7 +170,7 @@
170170 Out.ln;
171171 Mem.free(Heap.heap, ^<span class="ty">U8</span>(<span class="ty">ADR</span>(names[i][<span class="number">0</span>])));
172172 <span class="kw">end</span>;
173- Buf.done(<span class="ty">ADR</span>(path));
173+ Buf.done(path);
174174 <span class="kw">end</span>;
175175
176176 <span class="kw">end</span> Tree.</code></pre>
@@ -227,23 +227,23 @@
227227 <span class="kw">var</span> p: Opt.Parser; verbose: <span class="ty">BOOL</span>; n, i: <span class="ty">INT</span>; w: []<span class="ty">U8</span>; ok: <span class="ty">BOOL</span>;
228228 <span class="kw">begin</span>
229229 n := <span class="number">1</span>;
230- Opt.init(<span class="ty">ADR</span>(p), <span class="string">&quot;tool&quot;</span>, [
230+ Opt.init(p, <span class="string">&quot;tool&quot;</span>, [
231231 Opt.usage(<span class="string">&quot;&quot;</span>, <span class="string">&quot;tool [-v] [--count n] word ...&quot;</span>),
232232 Opt.option(<span class="string">&quot;&quot;</span>, <span class="string">&#x27;v&#x27;</span>, <span class="string">&quot;verbose&quot;</span>, <span class="string">&quot;&quot;</span>, <span class="string">&quot;say more&quot;</span>),
233233 Opt.option(<span class="string">&quot;&quot;</span>, count, <span class="string">&quot;count&quot;</span>, <span class="string">&quot;n&quot;</span>, <span class="string">&quot;repeat each word n times&quot;</span>)]);
234- <span class="kw">while</span> Opt.next(<span class="ty">ADR</span>(p)) <span class="kw">do</span>
234+ <span class="kw">while</span> Opt.next(p) <span class="kw">do</span>
235235 <span class="kw">if</span> p.letter = <span class="string">&#x27;v&#x27;</span> <span class="kw">then</span> verbose := <span class="ty">true</span>;
236- <span class="kw">elsif</span> p.letter = count <span class="kw">then</span> n := <span class="ty">INT</span>(Opt.number(<span class="ty">ADR</span>(p), <span class="number">1</span>, <span class="number">5</span>));
236+ <span class="kw">elsif</span> p.letter = count <span class="kw">then</span> n := <span class="ty">INT</span>(Opt.number(p, <span class="number">1</span>, <span class="number">5</span>));
237237 <span class="kw">end</span>;
238238 <span class="kw">end</span>;
239- w, ok := Opt.operand(<span class="ty">ADR</span>(p));
240- <span class="kw">if</span> <span class="kw">not</span> ok <span class="kw">then</span> Opt.fail(<span class="ty">ADR</span>(p), <span class="string">&quot;no words; see tool -h&quot;</span>); <span class="kw">end</span>;
239+ w, ok := Opt.operand(p);
240+ <span class="kw">if</span> <span class="kw">not</span> ok <span class="kw">then</span> Opt.fail(p, <span class="string">&quot;no words; see tool -h&quot;</span>); <span class="kw">end</span>;
241241 <span class="kw">while</span> ok <span class="kw">do</span>
242242 <span class="kw">for</span> i := <span class="number">1</span> <span class="kw">to</span> n <span class="kw">do</span>
243243 <span class="kw">if</span> verbose <span class="kw">then</span> Out.str(<span class="string">&quot;word: &quot;</span>); <span class="kw">end</span>;
244244 Fmt.print(<span class="string">&quot;{}\n&quot;</span>, [Fmt.str(w)]);
245245 <span class="kw">end</span>;
246- w, ok := Opt.operand(<span class="ty">ADR</span>(p));
246+ w, ok := Opt.operand(p);
247247 <span class="kw">end</span>;
248248 <span class="kw">end</span>;
249249

site/public/advanced/fmt.html (history) modified +7 -7

@@ -96,7 +96,7 @@
9696 <span class="kw">import</span> Out, Buf, Fmt, Heap;
9797
9898 <span class="comment">(* &quot;name (age n)&quot;, built in a Buf the caller owns *)</span>
99-<span class="kw">proc</span> describe(b: ^Buf.Buf; name: []<span class="ty">U8</span>; age: <span class="ty">INT</span>);
99+<span class="kw">proc</span> describe(<span class="kw">var</span> b: Buf.Buf; name: []<span class="ty">U8</span>; age: <span class="ty">INT</span>);
100100 <span class="kw">begin</span>
101101 Fmt.write(b, <span class="string">&quot;{} (age {})&quot;</span>, [Fmt.str(name), Fmt.int(age)]);
102102 <span class="kw">end</span>;
@@ -104,12 +104,12 @@
104104 <span class="kw">proc</span> main*;
105105 <span class="kw">var</span> b: Buf.Buf;
106106 <span class="kw">begin</span>
107- Buf.init(<span class="ty">ADR</span>(b), Heap.heap);
108- <span class="kw">defer</span> Buf.done(<span class="ty">ADR</span>(b));
109- describe(<span class="ty">ADR</span>(b), <span class="string">&quot;Ada&quot;</span>, <span class="number">36</span>);
110- Buf.str(<span class="ty">ADR</span>(b), <span class="string">&quot;; &quot;</span>);
111- describe(<span class="ty">ADR</span>(b), <span class="string">&quot;Grace&quot;</span>, <span class="number">45</span>);
112- Out.str(Buf.bytes(<span class="ty">ADR</span>(b))); Out.ln;
107+ Buf.init(b, Heap.heap);
108+ <span class="kw">defer</span> Buf.done(b);
109+ describe(b, <span class="string">&quot;Ada&quot;</span>, <span class="number">36</span>);
110+ Buf.str(b, <span class="string">&quot;; &quot;</span>);
111+ describe(b, <span class="string">&quot;Grace&quot;</span>, <span class="number">45</span>);
112+ Out.str(Buf.bytes(b)); Out.ln;
113113 Out.int(b.len); Out.str(<span class="string">&quot; bytes\n&quot;</span>);
114114 <span class="kw">end</span>;
115115

site/public/advanced/processes.html (history) modified +4 -4

@@ -139,16 +139,16 @@
139139 p.fds[<span class="number">1</span>] := wr;
140140 pid := Sys.spawn(p);
141141 Sys.close(wr); <span class="comment">(* only the child writes now *)</span>
142- Buf.init(<span class="ty">ADR</span>(b), Heap.heap);
143- <span class="kw">defer</span> Buf.done(<span class="ty">ADR</span>(b));
142+ Buf.init(b, Heap.heap);
143+ <span class="kw">defer</span> Buf.done(b);
144144 n := Sys.read(rd, chunk);
145145 <span class="kw">while</span> n &gt; <span class="number">0</span> <span class="kw">do</span>
146- Buf.str(<span class="ty">ADR</span>(b), chunk[<span class="number">0</span>..n]);
146+ Buf.str(b, chunk[<span class="number">0</span>..n]);
147147 n := Sys.read(rd, chunk);
148148 <span class="kw">end</span>;
149149 Sys.close(rd);
150150 _, how, status := Sys.wait(pid, <span class="ty">true</span>);
151- Out.str(<span class="string">&quot;captured: &quot;</span>); Out.str(Buf.bytes(<span class="ty">ADR</span>(b)));
151+ Out.str(<span class="string">&quot;captured: &quot;</span>); Out.str(Buf.bytes(b));
152152 Out.str(<span class="string">&quot;status &quot;</span>); Out.int(status); Out.ln;
153153 <span class="kw">if</span> how = Sys.exited <span class="kw">then</span> Out.str(<span class="string">&quot;(a normal exit)\n&quot;</span>); <span class="kw">end</span>;
154154 <span class="kw">end</span>;

site/public/advanced/static.html (history) modified +5 -5

@@ -97,8 +97,8 @@
9797 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
9898 <span class="cmd">$ ldd Cprint | sed &#x27;s/ (0x[0-9a-f]*)//&#x27;</span>
9999 linux-vdso.so.1
100- libc.so.6 =&gt; /usr/lib/libc.so.6
101- /lib64/ld-linux-x86-64.so.2 =&gt; /usr/lib64/ld-linux-x86-64.so.2</code></pre>
100+ libc.so.6 =&gt; /lib/x86_64-linux-gnu/libc.so.6
101+ /lib64/ld-linux-x86-64.so.2</code></pre>
102102 <p>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 <code>extern</code> or a <code>link</code> of a library.</p>
103103 <h2>Only what is reached</h2>
104104 <p>The compiler keeps only what can be reached from <code>main</code> 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.</p>
@@ -134,14 +134,14 @@
134134 <pre class="output term"><code><span class="cmd">$ raz Lean.raz</span>
135135 <span class="cmd">$ raz Heavy.raz</span>
136136 <span class="cmd">$ ls -l Lean Heavy | awk &#x27;{print $9, $5}&#x27;</span>
137-Heavy 28472
138-Lean 28464</code></pre>
137+Heavy 28440
138+Lean 28440</code></pre>
139139 <p>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.</p>
140140 <h2>Stripping</h2>
141141 <p><code>-s</code> 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.</p>
142142 <pre class="output term"><code><span class="cmd">$ raz -s -o Lean-stripped Lean.raz</span>
143143 <span class="cmd">$ ls -l Lean Lean-stripped | awk &#x27;{print $9, $5}&#x27;</span>
144-Lean 28464
144+Lean 28440
145145 Lean-stripped 6856
146146 <span class="cmd">$ ./Lean-stripped</span>
147147 same program</code></pre>

site/public/download/raz-0.19.0-linux-x86_64.tar.gz (history) added

Binary file; the patch has it.

site/public/download/raz-0.19.0-linux-x86_64.tar.gz.sha256 (history) added +1 -0

@@ -0,0 +1 @@
1+217448cb6521c76a28d71499d70a5dfdebc2dbcbc81d6d41ed9d9590005772ed raz-0.19.0-linux-x86_64.tar.gz

site/public/download/raz-0.20.0-linux-x86_64.tar.gz (history) added

Binary file; the patch has it.

site/public/download/raz-0.20.0-linux-x86_64.tar.gz.sha256 (history) added +1 -0

@@ -0,0 +1 @@
1+bfa954d27d759e4ca7f7f33debb4705f25d5c05a097d86aa28b3260048b5d9cc raz-0.20.0-linux-x86_64.tar.gz

site/public/index.html (history) modified +10 -10

@@ -42,7 +42,7 @@
4242 <div class="facts">
4343 <span><b>~10,700</b> lines of compiler</span>
4444 <span><b>~500K</b> lines compiled a second</span>
45- <span><b>1</b> report, <b>31</b> pages</span>
45+ <span><b>1</b> report, <b>32</b> pages</span>
4646 <span><b>static</b> executables, no run time to install</span>
4747 </div>
4848
@@ -109,28 +109,28 @@
109109 <p>The language is defined by <a href="spec.html">the report</a>, which is
110110 short on purpose: whatever it doesn&rsquo;t allow, raz doesn&rsquo;t have.
111111 Its second volume describes the library. Both are on one page, and each is
112-a PDF: <a href="raz.pdf">the language</a> (31 pages) and
112+a PDF: <a href="raz.pdf">the language</a> (32 pages) and
113113 <a href="raz-lib.pdf">the library</a>.</p>
114114
115115 <h2 id="download">Download</h2>
116-<p>raz 0.18.1 is a tarball for x86-64 Linux with the compiler, <code>raz</code>,
116+<p>raz 0.20.0 is a tarball for x86-64 Linux with the compiler, <code>raz</code>,
117117 its library, <code>lib/</code>, which it finds beside itself, the formatter
118118 and the documentation tool as sources in <code>tools/</code>, and the manual
119119 pages. It needs nothing else installed.</p>
120120 <div class="cta">
121- <a class="btn primary" href="download/raz-0.18.1-linux-x86_64.tar.gz">Download raz 0.18.1</a>
122- <a class="btn" href="download/raz-0.18.1-linux-x86_64.tar.gz.sha256">SHA-256</a>
121+ <a class="btn primary" href="download/raz-0.20.0-linux-x86_64.tar.gz">Download raz 0.20.0</a>
122+ <a class="btn" href="download/raz-0.20.0-linux-x86_64.tar.gz.sha256">SHA-256</a>
123123 </div>
124-<pre class="code"><code>$ tar xzf raz-0.18.1-linux-x86_64.tar.gz
125-$ ln -s $PWD/raz-0.18.1-linux-x86_64/raz ~/.local/bin/raz
124+<pre class="code"><code>$ tar xzf raz-0.20.0-linux-x86_64.tar.gz
125+$ ln -s $PWD/raz-0.20.0-linux-x86_64/raz ~/.local/bin/raz
126126 $ raz run Hello.raz</code></pre>
127127 <p>The link works since raz finds <code>lib/</code> beside its real path. The
128128 manual pages are in <code>man/</code>: <code>man ./man/raz-tutorial.7</code>.
129129 The address <code>download/latest</code> always leads to the newest release,
130-and <code>download/raz-0.18.1-linux-x86_64.tar.gz</code> to this one, for
131-good. Earlier releases: <a href="download/raz-0.18.0-linux-x86_64.tar.gz">0.18.0</a>, <a href="download/raz-0.17.2-linux-x86_64.tar.gz">0.17.2</a>, <a href="download/raz-0.17.1-linux-x86_64.tar.gz">0.17.1</a>, <a href="download/raz-0.17.0-linux-x86_64.tar.gz">0.17.0</a>, <a href="download/raz-0.16.0-linux-x86_64.tar.gz">0.16.0</a>, <a href="download/raz-0.15.0-linux-x86_64.tar.gz">0.15.0</a>, <a href="download/raz-0.14.0-linux-x86_64.tar.gz">0.14.0</a>, <a href="download/raz-0.13.0-linux-x86_64.tar.gz">0.13.0</a>, <a href="download/raz-0.12.0-linux-x86_64.tar.gz">0.12.0</a>, <a href="download/raz-0.11.1-linux-x86_64.tar.gz">0.11.1</a>, <a href="download/raz-0.11.0-linux-x86_64.tar.gz">0.11.0</a>, <a href="download/raz-0.10.1-linux-x86_64.tar.gz">0.10.1</a>, <a href="download/raz-0.10.0-linux-x86_64.tar.gz">0.10.0</a>, <a href="download/raz-0.9.1-linux-x86_64.tar.gz">0.9.1</a>, <a href="download/raz-0.9.0-linux-x86_64.tar.gz">0.9.0</a>, <a href="download/raz-0.8.0-linux-x86_64.tar.gz">0.8.0</a>, <a href="download/raz-0.7.1-linux-x86_64.tar.gz">0.7.1</a>; each has its SHA-256 beside it, with
130+and <code>download/raz-0.20.0-linux-x86_64.tar.gz</code> to this one, for
131+good. Earlier releases: <a href="download/raz-0.19.0-linux-x86_64.tar.gz">0.19.0</a>, <a href="download/raz-0.18.1-linux-x86_64.tar.gz">0.18.1</a>, <a href="download/raz-0.18.0-linux-x86_64.tar.gz">0.18.0</a>, <a href="download/raz-0.17.2-linux-x86_64.tar.gz">0.17.2</a>, <a href="download/raz-0.17.1-linux-x86_64.tar.gz">0.17.1</a>, <a href="download/raz-0.17.0-linux-x86_64.tar.gz">0.17.0</a>, <a href="download/raz-0.16.0-linux-x86_64.tar.gz">0.16.0</a>, <a href="download/raz-0.15.0-linux-x86_64.tar.gz">0.15.0</a>, <a href="download/raz-0.14.0-linux-x86_64.tar.gz">0.14.0</a>, <a href="download/raz-0.13.0-linux-x86_64.tar.gz">0.13.0</a>, <a href="download/raz-0.12.0-linux-x86_64.tar.gz">0.12.0</a>, <a href="download/raz-0.11.1-linux-x86_64.tar.gz">0.11.1</a>, <a href="download/raz-0.11.0-linux-x86_64.tar.gz">0.11.0</a>, <a href="download/raz-0.10.1-linux-x86_64.tar.gz">0.10.1</a>, <a href="download/raz-0.10.0-linux-x86_64.tar.gz">0.10.0</a>, <a href="download/raz-0.9.1-linux-x86_64.tar.gz">0.9.1</a>, <a href="download/raz-0.9.0-linux-x86_64.tar.gz">0.9.0</a>, <a href="download/raz-0.8.0-linux-x86_64.tar.gz">0.8.0</a>, <a href="download/raz-0.7.1-linux-x86_64.tar.gz">0.7.1</a>; each has its SHA-256 beside it, with
132132 <code>.sha256</code> added to its name.</p>
133-<p class="sha">SHA-256 <code>95184eacaa25bec1cdcd3e992c6ddc76c0a6fa95c5c5b50e48dc1b402ed65214</code></p>
133+<p class="sha">SHA-256 <code>bfa954d27d759e4ca7f7f33debb4705f25d5c05a097d86aa28b3260048b5d9cc</code></p>
134134
135135 </main>
136136 <footer>raz is under the ISC license.</footer>

site/public/raz-lib.pdf (history) modified

Binary file; the patch has it.

site/public/raz.pdf (history) modified

Binary file; the patch has it.

site/public/spec.html (history) modified +119 -83

@@ -38,7 +38,7 @@
3838 <p>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.</p>
3939 <p>This is the first volume of the report: the language, what an implementation chooses, and the grammar. The second, <code>doc/raz-lib.md</code>, is the library, which sections 3 and 10 and appendix A name.</p>
4040 <p>This report defines the language. It is short on purpose. Whatever it doesn’t allow, raz doesn’t have.</p>
41-<p>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 <code>try</code> (section 7.8); it breaks a program that has a name <code>try</code>. 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 <code>match</code> on a string (section 7.4); it breaks no program. 2026-10.26 is a fifth: an <code>INT</code> widens to an <code>I64</code> wherever it goes to one, in an expression too (sections 5.10 and 6.1); and a view, <code>v.(T)</code>, reads and writes the bytes of a variable as a <code>T</code> (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 <code>[]T</code> takes its length from its literal (section 4); it breaks no program. 2026-10.30 mends a defect: <code>[]</code> 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: <code>INT</code> is at least 16 bits, and <code>U8</code>, <code>I8</code> and <code>I16</code> 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 <code>continue</code> (section 7.2), which breaks a program that has a name <code>continue</code>. 2026-10.32 is an eighth thaw: a constant typed <code>[]T</code> may be <code>[]</code>, the empty slice (section 4); it breaks no program.</p>
41+<p>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 <code>try</code> (section 7.8); it breaks a program that has a name <code>try</code>. 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 <code>match</code> on a string (section 7.4); it breaks no program. 2026-10.26 is a fifth: an <code>INT</code> widens to an <code>I64</code> wherever it goes to one, in an expression too (sections 5.10 and 6.1); and a view, <code>v.(T)</code>, reads and writes the bytes of a variable as a <code>T</code> (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 <code>[]T</code> takes its length from its literal (section 4); it breaks no program. 2026-10.30 mends a defect: <code>[]</code> 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: <code>INT</code> is at least 16 bits, and <code>U8</code>, <code>I8</code> and <code>I16</code> 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 <code>continue</code> (section 7.2), which breaks a program that has a name <code>continue</code>. 2026-10.32 is an eighth thaw: a constant typed <code>[]T</code> may be <code>[]</code>, the empty slice (section 4); it breaks no program. 2026-10.33 is a ninth: a <code>const</code> 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 <code>var</code> parameter, a <code>const</code> one or a value instead (the library volume), which breaks a program that calls them with <code>ADR</code>. 2026-10.34 is a tenth: <code>PTR(s)</code>, the address a slice starts at, even an empty one (section 6.8); it breaks no program.</p>
4242 <p>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.</p>
4343 <h1 id="a-first-look">1. A first look</h1>
4444 <pre><code>module Hello;
@@ -134,15 +134,16 @@
134134 IdentDef = ident [ &quot;*&quot; ] .
135135 IdentList = IdentDef { &quot;,&quot; IdentDef } .</code></pre>
136136 <p>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 <code>type</code> section (so that two records can point at each other), and a procedure may be declared <code>forward</code> and defined later (section 8).</p>
137-<p><strong>Constants</strong> are evaluated by the compiler. Their expressions use only literals, other constants, operators, conversions, <code>SIZE</code> and the <code>LEN</code> of arrays and strings. A constant is an integer, a real, a <code>BOOL</code>, a name of an enumeration, a set, a string, an array, a record or an <code>ERROR</code>. A constant of an integer type wraps as the program would: <code>U8(250) + 10</code> 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 <code>div</code> or <code>mod</code>, which stops a program (section 6.1). A string constant can be indexed and sliced as an array of <code>U8</code> is, and its <code>LEN</code> is its length in bytes. <code>+</code> joins two string constants into one:</p>
137+<p><strong>Constants</strong> are evaluated by the compiler. Their expressions use only literals, other constants, operators, conversions, <code>SIZE</code>, the <code>LEN</code> of arrays and strings, and a variant’s cases. A constant is an integer, a real, a <code>BOOL</code>, a name of an enumeration, a set, a string, an array, a record, a variant or an <code>ERROR</code>. A constant of an integer type wraps as the program would: <code>U8(250) + 10</code> 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 <code>div</code> or <code>mod</code>, which stops a program (section 6.1). A string constant can be indexed and sliced as an array of <code>U8</code> is, and its <code>LEN</code> is its length in bytes. <code>+</code> joins two string constants into one:</p>
138138 <pre><code>const Text = &quot;the cat&quot;;
139139 Line = Text + &quot;\n&quot;;
140140 ...
141141 w := Text[4..7]; (* &quot;cat&quot; *)</code></pre>
142-<p>A constant with a type is an <code>ERROR</code> (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, <code>BOOL</code>s, enumerations, sets, <code>ERROR</code>s, procedures, <code>nil</code>, a string for a <code>[]U8</code>, 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:</p>
142+<p>A constant with a type is an <code>ERROR</code> (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, <code>BOOL</code>s, enumerations, sets, <code>ERROR</code>s, procedures, <code>nil</code>, a string for a <code>[]U8</code>, 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: <code>const D = dot;</code> is an error, <code>const D: Shape = dot;</code> isn’t.</p>
143143 <pre><code>const Primes: [5]I64 = [2, 3, 5, 7, 11];
144144 type Rule = record class: []U8; tag: INT; float: BOOL; end;
145145 const Rules: [2]Rule = [{class: &quot;firefox&quot;, tag: 2}, {class: &quot;mpv&quot;, float: true}];
146+const Shapes: []Shape = [circle(1.0), rect(2.0, 3.0), dot]; (* Shape of section 5.6 *)
146147 ...
147148 p := Primes[i];</code></pre>
148149 <p>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 <code>LEN</code> is <code>n</code>, 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.</p>
@@ -219,7 +220,7 @@
219220 <h2 id="slices">5.3 Slices</h2>
220221 <p><code>[]T</code> is a view of elements that live elsewhere: a pointer to the first and a count, two addresses’ worth, 16 bytes on x86-64.</p>
221222 <pre><code>Slice = record ptr: ^T; len: INT; end; (* its layout *)</code></pre>
222-<p>A slice is made from an array (<code>a[2..5]</code>, or an array used where a slice is wanted), from another slice, or from a pointer (<code>p[0..n]</code>). It doesn’t own what it points at.</p>
223+<p>A slice is made from an array (<code>a[2..5]</code>, or an array used where a slice is wanted), from another slice, or from a pointer (<code>p[0..n]</code>). It doesn’t own what it points at. <code>LEN(s)</code> is its count, and <code>PTR(s)</code> its pointer (section 6.8).</p>
223224 <h2 id="pointers">5.4 Pointers</h2>
224225 <p><code>^T</code> is the address of a <code>T</code>, as big as an <code>INT</code>. <code>nil</code> is the pointer to nothing.</p>
225226 <p><code>^VOLATILE T</code> is the address of a <code>T</code> that something besides the program may read or change: a device register, memory shared with another process. Section 7.6 says what that promises.</p>
@@ -266,7 +267,7 @@
266267 if err = Table.NotFound then ... end;</code></pre>
267268 <h2 id="procedure-types">5.9 Procedure types</h2>
268269 <pre><code>type Compare = proc(a, b: I64): BOOL;</code></pre>
269-<p>A value of a procedure type is the address of a procedure with that signature, as big as an address, or <code>nil</code>. Two signatures are alike when their parameters have the same types, each <code>var</code> or not alike, in order, and their results are the same types; the parameters’ names don’t matter.</p>
270+<p>A value of a procedure type is the address of a procedure with that signature, as big as an address, or <code>nil</code>. Two signatures are alike when their parameters have the same types, each <code>var</code>, <code>const</code> or neither alike, in order, and their results are the same types; the parameters’ names don’t matter.</p>
270271 <h2 id="same-and-assignable">5.10 Same and assignable</h2>
271272 <p>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: <code>^I64</code> is <code>^I64</code> wherever it is written. A record, variant or enumeration, though, is a type of its own wherever it is written, named or not: two <code>record x: I64; end</code> are two types. A named and an anonymous type are the same if the named one is built like the anonymous one, so that <code>p := ADR(n)</code> works for <code>p: NodePtr</code> with <code>type NodePtr = ^Node</code>. Sameness doesn’t pass through the anonymous type: with <code>type P1 = ^Node; P2 = ^Node;</code>, each of <code>P1</code> and <code>P2</code> is the same as <code>^Node</code>, but they are two declarations, so not the same as each other.</p>
272273 <p>A type declared with only a name on the right, <code>type Count = I64;</code>, is another name for that type, not a new one.</p>
@@ -437,6 +438,10 @@
437438 <td>the number of elements of an array or a string constant (an untyped constant) or of a slice (an <code>INT</code>)</td>
438439 </tr>
439440 <tr>
441+<td><code>PTR(s)</code></td>
442+<td>the address the slice <code>s</code> starts at, a <code>^T</code> for <code>s: []T</code>, unchecked; for an array <code>a</code>, that of <code>a[0..LEN(a)]</code></td>
443+</tr>
444+<tr>
440445 <td><code>NEW(p, a)</code></td>
441446 <td>sets <code>p: ^T</code> to a fresh, zeroed <code>T</code> from the allocator <code>a: ^Mem.Allocator</code>, or to <code>nil</code> if <code>a</code> has no room</td>
442447 </tr>
@@ -488,6 +493,14 @@
488493 </table>
489494 <p><code>SYSCALL</code> exists only on Linux targets. Other systems have no stable system call interface, and their modules call the C library instead (section 9).</p>
490495 <p><code>NEW(p, a)</code> calls <code>a^.alloc(a, SIZE(T), A)</code>, where <code>A</code> is the alignment of <code>T</code>, and zeroes the bytes it gets if they aren’t <code>nil</code>. <code>Mem.Allocator</code> (the library, <code>doc/raz-lib.md</code>) is the one type of the library the language names.</p>
496+<p><code>PTR(s)</code> is the first of the two words of <code>s</code> (section 5.3), and is not checked. For a slice that isn’t empty it is <code>ADR(s[0])</code>; for an empty one, where <code>s[0]</code> would stop the program, it is what the slice holds: <code>nil</code> for a slice variable as it starts (section 4) and for <code>[]</code>, and for one cut empty from another, <code>t[3..3]</code>, 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:</p>
497+<pre><code>type Value = record n: INT; p: ^U8; end;
498+
499+proc valueOf(s: []U8): Value;
500+begin
501+ return {n: LEN(s), p: PTR(s)}; (* &quot;&quot; too *)
502+end;</code></pre>
503+<p>and <code>v.p[0..v.n]</code> is the slice again (section 6.4), empty when <code>v.n</code> is 0, whatever <code>v.p</code> is. Reading through the pointer is as unchecked as through any pointer. <code>PTR(a)</code> of an array may be taken wherever the slice <code>a[0..LEN(a)]</code> may be made, and is an error wherever it may not.</p>
491504 <p><code>COPY</code> is a statement, as <code>INC</code> is. It copies the bytes of <code>LEN(s)</code> elements as one block, as an assignment of an array does, and is right when <code>d</code> and <code>s</code> overlap, as in <code>COPY(a[1..n], a[0..n - 1])</code>. It is checked as a slice is: past <code>LEN(d)</code>, it stops the program, unless the module says <code>check off;</code>.</p>
492505 <p><code>INC</code> and <code>DEC</code> evaluate <code>v</code> once, so <code>INC(a[f(i)])</code> calls <code>f</code> once. They read <code>v</code> and then write it: two accesses, even through a <code>^VOLATILE</code> pointer, and not atomic; <code>XADD</code> is the atomic one.</p>
493506 <p>For <code>CAS</code>, <code>XCHG</code> and <code>XADD</code>, <code>p</code> is a <code>^T</code> or <code>^VOLATILE T</code> where <code>T</code> is <code>INT</code>, <code>UINT</code> or a pointer type (<code>INT</code> or <code>UINT</code> for <code>XADD</code>), 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</p>
@@ -570,7 +583,7 @@
570583 | rect(w, h): area := w * h;
571584 | dot: area := 0.0;
572585 end;</code></pre>
573-<p><code>match</code> takes a variant, an enumeration, an integer type (a <code>U8</code> included) or a string, a <code>[]U8</code>; other types are an error. It runs the arm of the case <code>s</code> holds. An arm may name the case’s fields, in order, all of them; the names stand for those fields of <code>s</code> itself, so assigning to one changes <code>s</code>; if <code>s</code> 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 <code>| else:</code> arm, which must come last.</p>
586+<p><code>match</code> takes a variant, an enumeration, an integer type (a <code>U8</code> included) or a string, a <code>[]U8</code>; other types are an error. It runs the arm of the case <code>s</code> holds. An arm may name the case’s fields, in order, all of them; the names stand for those fields of <code>s</code> itself, so assigning to one changes <code>s</code>; if <code>s</code> is a constant or a <code>const</code> parameter, they can’t be assigned; if <code>s</code> 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 <code>| else:</code> arm, which must come last.</p>
574587 <p><code>match</code> 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:</p>
575588 <pre><code>match op of
576589 | sPlus, sMinus: kind := additive;
@@ -670,10 +683,23 @@
670683 | &quot;var&quot; { ident { &quot;,&quot; ident } &quot;:&quot; Type &quot;;&quot; } .
671684 Signature = &quot;(&quot; [ Params { &quot;;&quot; Params } [ &quot;;&quot; &quot;...&quot; ] ] &quot;)&quot; [ &quot;:&quot; Results ]
672685 | [ &quot;:&quot; Results ] .
673-Params = [ &quot;var&quot; ] ident { &quot;,&quot; ident } &quot;:&quot; Type .
686+Params = [ &quot;var&quot; | &quot;const&quot; ] ident { &quot;,&quot; ident } &quot;:&quot; Type .
674687 Results = Type | &quot;(&quot; Type { &quot;,&quot; Type } &quot;)&quot; .</code></pre>
675688 <p>A procedure without parameters may leave out the parentheses, both where it is declared (<code>proc main*;</code>) and where it is called (<code>Out.ln</code>). Used without parentheses in an expression, a procedure is a procedure value, not a call.</p>
676689 <p><strong>Parameters.</strong> A value parameter is a copy: the procedure may change it, and the caller’s variable stays as it was. A <code>var</code> parameter is the caller’s variable itself; its argument must be a variable of exactly the parameter’s type.</p>
690+<p>A <code>const</code> 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 <code>var</code> parameter, take the <code>ADR</code> of either, write it through a view (section 6.9), or assign the names a <code>match</code> 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. <code>const</code> 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 <code>var</code> parameter, a pointer or another thread, the procedure sees the change.</p>
691+<pre><code>type Parser = record args: [][]U8; at: INT; (* ... *) end;
692+
693+proc current(const p: Parser): []U8; (* reads p, many words, in place *)
694+begin
695+ return p.args[p.at];
696+end;
697+
698+proc advance(var p: Parser); (* changes p *)
699+begin
700+ INC(p.at);
701+end;</code></pre>
702+<p>A procedure takes what it reads as a value when it is a single value or a slice, and as <code>const</code> when it is a record or an array; what it changes, as <code>var</code>; and a pointer only for what it keeps past the call, what may be <code>nil</code>, an allocator, or what C or the system takes.</p>
677703 <p><strong>Results.</strong> 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 <code>return</code> in a procedure whose results are of the same types, in the same order, which then returns them as they are: <code>return divmod(n, 2);</code>. A procedure that can fail has an <code>ERROR</code> as its last result (section 5.8), which <code>try</code> passes on (section 7.8).</p>
678704 <p>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:</p>
679705 <pre><code>s := f(&#39;a&#39;)[0..4]; (* f returns a [8]U8: s is undefined after this *)
@@ -706,7 +732,7 @@
706732 ret;
707733 end rdtsc;</code></pre>
708734 <p>A label, <code>name:</code>, 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 <code>db</code>, as in <code>db 0FH, 31H;</code>, for an instruction the assembler doesn’t know.</p>
709-<p>It is called like any procedure, with the System V convention: integer and pointer arguments arrive in <code>rdi</code>, <code>rsi</code>, <code>rdx</code>, <code>rcx</code>, <code>r8</code> and <code>r9</code>, <code>F32</code> and <code>F64</code> ones in <code>xmm0</code> to <code>xmm7</code>, and the result goes in <code>rax</code> (and <code>rdx</code> for a second) or <code>xmm0</code>. 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 <code>rax</code> and its length in <code>rdx</code>, and it is the only result. The instructions are the whole procedure, <code>ret</code> included; they must keep <code>rbx</code>, <code>rbp</code>, <code>rsp</code> and <code>r12</code> to <code>r15</code> as they found them. The compiler doesn’t look past what they say.</p>
735+<p>It is called like any procedure, with the System V convention: integer and pointer arguments, and the addresses of <code>var</code> and <code>const</code> ones, arrive in <code>rdi</code>, <code>rsi</code>, <code>rdx</code>, <code>rcx</code>, <code>r8</code> and <code>r9</code>, <code>F32</code> and <code>F64</code> ones in <code>xmm0</code> to <code>xmm7</code>, and the result goes in <code>rax</code> (and <code>rdx</code> for a second) or <code>xmm0</code>. 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 <code>rax</code> and its length in <code>rdx</code>, and it is the only result. The instructions are the whole procedure, <code>ret</code> included; they must keep <code>rbx</code>, <code>rbp</code>, <code>rsp</code> and <code>r12</code> to <code>r15</code> as they found them. The compiler doesn’t look past what they say.</p>
710736 <h1 id="calling-c">9. Calling C</h1>
711737 <pre><code>ExternDeclaration = &quot;extern&quot; ( &quot;proc&quot; IdentDef Signature
712738 | &quot;var&quot; IdentDef &quot;:&quot; Type ) .</code></pre>
@@ -733,7 +759,7 @@
733759 proc exit*(status: INT);
734760 proc trace*; (* the calls under way, on standard error *)</code></pre>
735761 <p><code>Rt.trace</code> 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.</p>
736-<p><strong>Defined behaviour.</strong> 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 <code>check off;</code>, 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 <code>nil</code>, dividing by zero, calling a <code>nil</code> 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 <code>nil</code> pointer, a <code>nil</code> 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.</p>
762+<p><strong>Defined behaviour.</strong> 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 <code>const</code> parameter, kept past its statement (section 8), an index out of range in a module that says <code>check off;</code>, 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 <code>nil</code>, dividing by zero, calling a <code>nil</code> 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 <code>nil</code> pointer, a <code>nil</code> 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.</p>
737763 <p><strong>Separate compilation.</strong> 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).</p>
738764 <p><strong>Errors.</strong> 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 <code>forward</code> 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 (<code>Sys.write(fd, s);</code>, where <code>_ := Sys.write(fd, s);</code> 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).</p>
739765 <h1 id="versions">11. Versions</h1>
@@ -742,7 +768,7 @@
742768 <h1 id="appendix-a.-what-an-implementation-chooses">Appendix A. What an implementation chooses</h1>
743769 <p>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 <code>doc/compiler.md</code>, under “This compiler’s choices”. The programs in <code>conform/</code> are how an implementation shows that it follows this report: it passes them all, its reals aside where its target has none; <code>conform/check.sh</code> runs them.</p>
744770 <ul>
745-<li><strong>The target.</strong> Which machines and systems it compiles for, and the names of their files (<code>linux-x86_64</code>, section 3); for each, the size of an address, and so of <code>INT</code>, and whether it has reals.</li>
771+<li><strong>The target.</strong> Which machines and systems it compiles for, and the names of their files (<code>linux-x86_64</code>, section 3); for each, the size of an address, and so of <code>INT</code>, whether it has reals, and which C library a program that uses C is linked against.</li>
746772 <li><strong>Separate compilation.</strong> 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.</li>
747773 <li><strong>Atomics.</strong> How <code>CAS</code>, <code>XCHG</code> and <code>XADD</code> 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.</li>
748774 <li><strong>The calling convention.</strong> On x86-64 Linux it is System V (sections 8 and 9); elsewhere it is the C library’s own, so that <code>extern</code> procedures and callbacks work. How a procedure returns several results, and how its frame is laid out, are the implementation’s.</li>
@@ -848,7 +874,7 @@
848874 | &quot;var&quot; { ident { &quot;,&quot; ident } &quot;:&quot; Type &quot;;&quot; } .
849875 Signature = &quot;(&quot; [ Params { &quot;;&quot; Params } [ &quot;;&quot; &quot;...&quot; ] ] &quot;)&quot; [ &quot;:&quot; Results ]
850876 | [ &quot;:&quot; Results ] .
851-Params = [ &quot;var&quot; ] ident { &quot;,&quot; ident } &quot;:&quot; Type .
877+Params = [ &quot;var&quot; | &quot;const&quot; ] ident { &quot;,&quot; ident } &quot;:&quot; Type .
852878 Results = Type | &quot;(&quot; Type { &quot;,&quot; Type } &quot;)&quot; .
853879 ExternDeclaration = &quot;extern&quot; ( &quot;proc&quot; IdentDef Signature
854880 | &quot;var&quot; IdentDef &quot;:&quot; Type ) .</code></pre>
@@ -870,7 +896,7 @@
870896 </tr>
871897 <tr>
872898 <td><code>Sys</code></td>
873-<td>system calls: <code>open</code>, <code>openMode</code>, <code>openRead</code>, <code>create</code>, <code>read</code>, <code>write</code>, <code>seek</code>, <code>position</code>, <code>truncate</code>, <code>sync</code>, <code>syncAll</code>, <code>lock</code>, <code>close</code>, <code>dup</code>, <code>dupTo</code>, <code>dupAbove</code>, <code>keepOnExec</code>, <code>mmap</code>, <code>munmap</code>, <code>isTerminal</code>, <code>yield</code>, <code>exit</code>; files and directories, <code>rename</code>, <code>remove</code>, <code>removeDir</code>, <code>makeDir</code>, <code>chmod</code>, <code>access</code>, <code>umask</code>, <code>symlink</code>, <code>readLink</code>, <code>info</code>, <code>linkInfo</code>, <code>infoOf</code>, <code>openDir</code>, <code>nextEntry</code>, <code>entryKind</code>, <code>closeDir</code>; the terminal, <code>rawMode</code>, <code>restoreMode</code>, <code>getMode</code>, <code>setMode</code>, <code>termSize</code>, <code>ready</code>; the environment, <code>env</code>, <code>envAt</code>, <code>setEnv</code>, <code>workDir</code>, <code>setWorkDir</code>; programs, <code>spawn</code>, <code>exec</code> and <code>execve</code>, pipes and signals; the user, the machine, time used and limits; time, <code>clock</code>, <code>now</code>, <code>sleep</code>; <code>random</code>; what an errno means, <code>errorText</code>; sockets, among them datagrams served and files passed; and memory shared through a file. One file per target, and <code>Sys.raz</code> over the C library for the others</td>
899+<td>system calls: <code>open</code>, <code>openMode</code>, <code>openRead</code>, <code>create</code>, <code>read</code>, <code>write</code>, <code>seek</code>, <code>position</code>, <code>truncate</code>, <code>sync</code>, <code>syncAll</code>, <code>lock</code>, <code>close</code>, <code>dup</code>, <code>dupTo</code>, <code>dupAbove</code>, <code>keepOnExec</code>, <code>mmap</code>, <code>munmap</code>, <code>isTerminal</code>, <code>yield</code>, <code>exit</code>; files and directories, <code>rename</code>, <code>remove</code>, <code>removeDir</code>, <code>makeDir</code>, <code>chmod</code>, <code>access</code>, <code>umask</code>, <code>symlink</code>, <code>readLink</code>, <code>info</code>, <code>linkInfo</code>, <code>infoOf</code>, <code>openDir</code>, <code>nextEntry</code>, <code>entryKind</code>, <code>closeDir</code>; the terminal, <code>rawMode</code>, <code>restoreMode</code>, <code>getMode</code>, <code>setMode</code>, <code>termSize</code>, <code>ready</code>; the environment, <code>env</code>, <code>envAt</code>, <code>setEnv</code>, <code>workDir</code>, <code>setWorkDir</code>; programs, <code>spawn</code>, <code>exec</code> and <code>execve</code>, pipes and signals; the user, the machine, time used and limits; time, <code>clock</code>, <code>now</code>, <code>sleep</code>; <code>random</code>; errors, by name, and what one means, <code>errorText</code>; sockets, among them datagrams served and files passed; and memory shared through a file. One file per target, and <code>Sys.raz</code> over the C library for the others, which takes what each C library fixes from <code>CAbi</code></td>
874900 </tr>
875901 <tr>
876902 <td><code>Out</code></td>
@@ -979,14 +1005,14 @@
9791005 base*: Mem.Allocator; (* first, so that ^Arena(a) finds the rest *)
9801006 ...
9811007 end;
982-proc init*(ar: ^Arena; size: INT): BOOL; (* an arena of size bytes; false if the system has none *)
983-proc reset*(ar: ^Arena); (* every allocation forgotten; the memory used again *)
984-proc done*(ar: ^Arena); (* its memory given back *)</code></pre>
1008+proc init*(var ar: Arena; size: INT): BOOL; (* an arena of size bytes; false if the system has none *)
1009+proc reset*(var ar: Arena); (* every allocation forgotten; the memory used again *)
1010+proc done*(var ar: Arena); (* its memory given back *)</code></pre>
9851011 <p><code>NEW(p, a)</code> calls <code>a^.alloc</code>. <code>Heap</code> is the general allocator. An arena hands out memory from one block: its <code>free</code> does nothing, and <code>reset</code> forgets everything.</p>
9861012 <pre><code>module Lock;
9871013 type Lock* = record ... end;
988-proc take*(l: ^Lock);
989-proc give*(l: ^Lock);
1014+proc take*(var l: Lock);
1015+proc give*(var l: Lock);
9901016
9911017 module Thread;
9921018 const Failed*: ERROR = &quot;can&#39;t start a thread&quot;;
@@ -996,8 +1022,8 @@
9961022 proc spawn*(p: proc(arg: ^U8); arg: ^U8): (^Thread, ERROR); (* p(arg) in a new thread *)
9971023 proc join*(t: ^Thread); (* waits for t to end, then frees its stack *)
9981024 proc signal*(t: ^Thread; sig: INT): INT; (* sig sent to t alone: 0, or minus an errno *)
999-proc lock*(m: ^Mutex);
1000-proc unlock*(m: ^Mutex);</code></pre>
1025+proc lock*(var m: Mutex);
1026+proc unlock*(var m: Mutex);</code></pre>
10011027 <p>A <code>Lock</code> is for short sections: a thread that finds it taken tries again, giving up the processor now and then. A <code>Mutex</code> sleeps. Each of <code>Thread</code>’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, <code>Thread</code> makes its threads with C’s <code>pthread_create</code>, 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.</p>
10021028 <p><code>Sys.kill</code> signals a program, and the system gives the signal to any of its threads; <code>signal</code> gives it to <code>t</code> alone, until <code>t</code> is joined, and is -3 (ESRCH) once <code>t</code> has ended. With <code>Sys.handle(sig)</code>, a call <code>t</code> waits in, a <code>read</code> or a <code>ready</code>, fails with -4, so that one thread can break into another’s wait, as <code>^C</code> breaks into the main thread’s. A signal sent before <code>t</code> begins its wait is only noted, so a program sends it again until <code>t</code> says it has stopped.</p>
10031029 <pre><code>module Out;
@@ -1022,7 +1048,7 @@
10221048 end;
10231049
10241050 end Both.</code></pre>
1025-<p><strong>Sys</strong> 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.</p>
1051+<p><strong>Sys</strong> 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: <code>Sys</code> 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. <code>Sys.raz</code>, the <code>Sys</code> 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 <code>CAbi</code>, one file per target, which <code>tools/cabi.c</code>, compiled there, writes.</p>
10261052 <pre><code>module Sys;
10271053 const
10281054 stdin* = 0; stdout* = 1; stderr* = 2;
@@ -1035,6 +1061,16 @@
10351061 (* the limits limit and setLimit take, by their numbers on Linux; each target has its own *)
10361062 limitCpu* = 0; limitFileSize* = 1; limitData* = 2; limitStack* = 3;
10371063 limitCore* = 4; limitProcs* = 6; limitFiles* = 7; limitMemory* = 9;
1064+ (* errors, minus Linux&#39;s errnos on every target *)
1065+ errPerm* = -1; errNoEntry* = -2; errNoProcess* = -3; errIntr* = -4;
1066+ errIo* = -5; errBadFd* = -9; errChild* = -10; errAgain* = -11;
1067+ errNoMemory* = -12; errDenied* = -13; errExists* = -17;
1068+ errNotDir* = -20; errIsDir* = -21; errInvalid* = -22;
1069+ errNotTerminal* = -25; errNoSpace* = -28; errPipe* = -32;
1070+ errNameTooLong* = -36; errNotEmpty* = -39; errLoop* = -40;
1071+ errAddrInUse* = -98; errNetUnreach* = -101; errConnReset* = -104;
1072+ errTimedOut* = -110; errRefused* = -111; errHostUnreach* = -113;
1073+ errInProgress* = -115;
10381074
10391075 type
10401076 Access* = (reading, writing, creating, exclusive, truncating, appending, executing);
@@ -1105,10 +1141,10 @@
11051141 proc infoOf*(fd: INT): (Info, INT); (* the open file&#39;s *)
11061142 proc space*(path: []U8): (I64, I64, INT); (* the bytes free and in all on path&#39;s file system *)
11071143
1108-proc openDir*(d: ^Dir; path: []U8): INT;
1109-proc nextEntry*(d: ^Dir): ([]U8, BOOL); (* a name, good until the next call; false at the end *)
1110-proc entryKind*(d: ^Dir): Kind; (* what the name nextEntry gave last is *)
1111-proc closeDir*(d: ^Dir);
1144+proc openDir*(var d: Dir; path: []U8): INT;
1145+proc nextEntry*(var d: Dir): ([]U8, BOOL); (* a name, good until the next call; false at the end *)
1146+proc entryKind*(const d: Dir): Kind; (* what the name nextEntry gave last is *)
1147+proc closeDir*(var d: Dir);
11121148
11131149 proc rawMode*(fd: INT): BOOL; (* the terminal on fd: no echo, no lines, no signals *)
11141150 proc restoreMode*(fd: INT); (* as rawMode found it *)
@@ -1220,8 +1256,8 @@
12201256 proc hexVal*(c: U8): INT; (* c&#39;s value as a hexadecimal digit, or -1 *)
12211257 proc lower*(s: []U8); (* s&#39;s ASCII capitals made small, in place *)
12221258 proc upper*(s: []U8); (* s&#39;s ASCII small letters made capitals, in place *)
1223-proc join*(b: ^Buf.Buf; parts: [][]U8; sep: []U8); (* the parts added to b, sep between each two *)
1224-proc replace*(b: ^Buf.Buf; s, old, new: []U8); (* s added to b, with new for each old in it *)
1259+proc join*(var b: Buf.Buf; parts: [][]U8; sep: []U8); (* the parts added to b, sep between each two *)
1260+proc replace*(var b: Buf.Buf; s, old, new: []U8); (* s added to b, with new for each old in it *)
12251261 proc encode*(c: I32): ([4]U8, INT); (* c in UTF-8: its bytes, and how many *)
12261262 proc decode*(s: []U8): (I32, INT); (* the character s starts with, and its length in bytes *)
12271263 proc decodeLast*(s: []U8): (I32, INT); (* the character s ends with, and its length in bytes *)
@@ -1238,15 +1274,15 @@
12381274
12391275 module Buf;
12401276 type Buf* = record len*: INT; ... end;
1241-proc init*(b: ^Buf; a: ^Mem.Allocator);
1242-proc room*(b: ^Buf; n: INT): BOOL; (* room for n more bytes; false if the allocator has none *)
1243-proc add*(b: ^Buf; c: U8);
1244-proc str*(b: ^Buf; s: []U8);
1245-proc spare*(b: ^Buf; n: INT): []U8; (* room for n more bytes, and those bytes, to fill *)
1246-proc bytes*(b: ^Buf): []U8; (* what it holds, until it next grows *)
1247-proc cut*(b: ^Buf; n: INT); (* only the first n bytes kept, its memory kept *)
1248-proc reset*(b: ^Buf); (* emptied, its memory kept *)
1249-proc done*(b: ^Buf); (* its memory given back *)
1277+proc init*(var b: Buf; a: ^Mem.Allocator);
1278+proc room*(var b: Buf; n: INT): BOOL; (* room for n more bytes; false if the allocator has none *)
1279+proc add*(var b: Buf; c: U8);
1280+proc str*(var b: Buf; s: []U8);
1281+proc spare*(var b: Buf; n: INT): []U8; (* room for n more bytes, and those bytes, to fill *)
1282+proc bytes*(const b: Buf): []U8; (* what it holds, until it next grows *)
1283+proc cut*(var b: Buf; n: INT); (* only the first n bytes kept, its memory kept *)
1284+proc reset*(var b: Buf); (* emptied, its memory kept *)
1285+proc done*(var b: Buf); (* its memory given back *)
12501286
12511287 module Fmt;
12521288 type Arg* = variant
@@ -1260,40 +1296,40 @@
12601296 end;
12611297 proc print*(f: []U8; args: []Arg); (* to standard output *)
12621298 proc eprint*(f: []U8; args: []Arg); (* to standard error, once Out is flushed *)
1263-proc write*(b: ^Buf.Buf; f: []U8; args: []Arg); (* added to b *)
1299+proc write*(var b: Buf.Buf; f: []U8; args: []Arg); (* added to b *)
12641300
12651301 module List(T);
12661302 type
12671303 Node* = record next*: ^Node; val*: T; end;
12681304 List* = record head*: ^Node; len*: INT; ... end;
1269-proc init*(l: ^List; a: ^Mem.Allocator);
1270-proc push*(l: ^List; v: T): BOOL; (* v at the front; false if the allocator has no room *)
1271-proc pop*(l: ^List): (T, BOOL); (* the front value, taken off; false if the list is empty *)
1272-proc reverse*(l: ^List);
1273-proc clear*(l: ^List);
1305+proc init*(var l: List; a: ^Mem.Allocator);
1306+proc push*(var l: List; v: T): BOOL; (* v at the front; false if the allocator has no room *)
1307+proc pop*(var l: List): (T, BOOL); (* the front value, taken off; false if the list is empty *)
1308+proc reverse*(var l: List);
1309+proc clear*(var l: List);
12741310
12751311 module Map(K, V; hash: proc(k: K): U64; eq: proc(a, b: K): BOOL);
12761312 type Map* = record len*: INT; ... end;
1277-proc init*(m: ^Map; a: ^Mem.Allocator);
1278-proc put*(m: ^Map; k: K; v: V): BOOL; (* k now maps to v; false if there was no room *)
1279-proc remove*(m: ^Map; k: K): BOOL; (* false if k wasn&#39;t there *)
1280-proc get*(m: ^Map; k: K): (V, BOOL); (* what k maps to, and whether it maps to anything *)
1281-proc next*(m: ^Map; i: INT): (INT, K, V); (* the entry after i *)
1282-proc done*(m: ^Map); (* its memory given back, leaving it empty *)
1313+proc init*(var m: Map; a: ^Mem.Allocator);
1314+proc put*(var m: Map; k: K; v: V): BOOL; (* k now maps to v; false if there was no room *)
1315+proc remove*(var m: Map; k: K): BOOL; (* false if k wasn&#39;t there *)
1316+proc get*(const m: Map; k: K): (V, BOOL); (* what k maps to, and whether it maps to anything *)
1317+proc next*(const m: Map; i: INT): (INT, K, V); (* the entry after i *)
1318+proc done*(var m: Map); (* its memory given back, leaving it empty *)
12831319
12841320 module Vec(T);
12851321 type Vec* = record len*: INT; ... end;
1286-proc init*(v: ^Vec; a: ^Mem.Allocator);
1287-proc room*(v: ^Vec; n: INT): BOOL; (* room for n more; false if the allocator has none *)
1288-proc push*(v: ^Vec; x: T); (* x added at the end *)
1289-proc pop*(v: ^Vec): (T, BOOL); (* the last element, taken off; false if the array is empty *)
1290-proc add*(v: ^Vec): ^T; (* a new element at the end, zero, to fill in place *)
1291-proc tryPush*(v: ^Vec; x: T): BOOL; (* push; false, and v as it was, if there is no room *)
1292-proc tryAdd*(v: ^Vec): (^T, BOOL); (* add; nil and false, and v as it was, if there is no room *)
1293-proc resize*(v: ^Vec; n: INT); (* n elements: cut short, or the new ones zero *)
1294-proc all*(v: ^Vec): []T; (* the elements, until it next grows *)
1295-proc reset*(v: ^Vec); (* emptied, its memory kept *)
1296-proc done*(v: ^Vec); (* its memory given back *)
1322+proc init*(var v: Vec; a: ^Mem.Allocator);
1323+proc room*(var v: Vec; n: INT): BOOL; (* room for n more; false if the allocator has none *)
1324+proc push*(var v: Vec; x: T); (* x added at the end *)
1325+proc pop*(var v: Vec): (T, BOOL); (* the last element, taken off; false if the array is empty *)
1326+proc add*(var v: Vec): ^T; (* a new element at the end, zero, to fill in place *)
1327+proc tryPush*(var v: Vec; x: T): BOOL; (* push; false, and v as it was, if there is no room *)
1328+proc tryAdd*(var v: Vec): (^T, BOOL); (* add; nil and false, and v as it was, if there is no room *)
1329+proc resize*(var v: Vec; n: INT); (* n elements: cut short, or the new ones zero *)
1330+proc all*(const v: Vec): []T; (* the elements, until it next grows *)
1331+proc reset*(var v: Vec); (* emptied, its memory kept *)
1332+proc done*(var v: Vec); (* its memory given back *)
12971333
12981334 module Sort(T; less: proc(a, b: T): BOOL);
12991335 proc sort*(s: []T);
@@ -1320,7 +1356,7 @@
13201356 proc fromBits*(u: U64): F64; (* the F64 whose bits are u *)
13211357 proc mul*(a, b: U64): (U64, U64); (* a times b: the low 64 bits of the product, and the high *)
13221358 proc toReal*(s: []U8): (F64, BOOL); (* s as a real, the F64 nearest it; false if it isn&#39;t one *)</code></pre>
1323-<p>A <code>Buf</code>, a <code>List</code>, a <code>Map</code> and a <code>Vec</code> take their memory from the allocator <code>init</code> gives them. <code>Buf.add</code>, <code>str</code> and <code>spare</code> stop the program, as a failed check does, if the allocator has no room; <code>room</code> asks first. A program reads into a <code>Buf</code> through <code>spare</code>, then adds what it read to <code>len</code>: <code>s := Buf.spare(b, 4096); n := Sys.read(fd, s); if n &gt; 0 then INC(b^.len, n); end;</code>. <code>cut</code> takes back what was added, to a length it had: <code>start := b^.len; ...; Buf.cut(b, start);</code>; a length past <code>len</code> stops the program, as an index past the end does. A <code>Vec</code> is <code>Buf</code> for any <code>T</code>: one block, which doubles when it is full, so <code>push</code> costs the same on average however long it grows. <code>all</code> gives the elements as a slice, indexed and checked as any is, and <code>v.len</code> is their number; the slice, and what <code>add</code> gives, are good until the array next grows. <code>pop</code> takes the last element off, keeping the memory. <code>push</code>, <code>add</code> and <code>resize</code> stop the program, as <code>Buf.add</code> does, if the allocator has no room; <code>room</code> asks first: <code>import Lines := Vec([]U8);</code>. <code>Fmt</code>’s format takes the next argument at each <code>{}</code>; <code>{{</code> and <code>}}</code> stand for <code>{</code> and <code>}</code>. A <code>Map</code> hashes and compares its keys with the procedures it is given: <code>import Count := Map([]U8, INT, Str.hash, Str.eq);</code>.</p>
1359+<p>A <code>Buf</code>, a <code>List</code>, a <code>Map</code> and a <code>Vec</code> take their memory from the allocator <code>init</code> gives them. <code>Buf.add</code>, <code>str</code> and <code>spare</code> stop the program, as a failed check does, if the allocator has no room; <code>room</code> asks first. A program reads into a <code>Buf</code> through <code>spare</code>, then adds what it read to <code>len</code>: <code>s := Buf.spare(b, 4096); n := Sys.read(fd, s); if n &gt; 0 then INC(b.len, n); end;</code>. <code>cut</code> takes back what was added, to a length it had: <code>start := b.len; ...; Buf.cut(b, start);</code>; a length past <code>len</code> stops the program, as an index past the end does. A <code>Vec</code> is <code>Buf</code> for any <code>T</code>: one block, which doubles when it is full, so <code>push</code> costs the same on average however long it grows. <code>all</code> gives the elements as a slice, indexed and checked as any is, and <code>v.len</code> is their number; the slice, and what <code>add</code> gives, are good until the array next grows. <code>pop</code> takes the last element off, keeping the memory. <code>push</code>, <code>add</code> and <code>resize</code> stop the program, as <code>Buf.add</code> does, if the allocator has no room; <code>room</code> asks first: <code>import Lines := Vec([]U8);</code>. <code>Fmt</code>’s format takes the next argument at each <code>{}</code>; <code>{{</code> and <code>}}</code> stand for <code>{</code> and <code>}</code>. A <code>Map</code> hashes and compares its keys with the procedures it is given: <code>import Count := Map([]U8, INT, Str.hash, Str.eq);</code>.</p>
13241360 <p><code>Str</code> reads and writes UTF-8. <code>encode</code> 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. <code>decode</code> reads the first character of <code>s</code>, and gives FFFDH and 1 for a byte that doesn’t start one rightly, and 0 and 0 for an empty <code>s</code>: a continuation, a byte followed by too few continuations, a surrogate, a character beyond 10FFFFH or one spelled in more bytes than it needs. <code>decodeLast</code> reads the last character in the same way, to walk a string backwards. <code>valid</code> says that <code>decode</code> finds no such byte in <code>s</code>, and <code>chars</code> counts the characters, each such byte one. <code>next</code> walks a string a character at a time, as <code>decode</code> reads them: from 0, it gives the character at <code>i</code> and where the one after it starts, and 0 and -1 when <code>i</code> is at the end, or past it:</p>
13251361 <pre><code>c, i := Str.next(s, 0);
13261362 while i &gt;= 0 do
@@ -1343,17 +1379,17 @@
13431379 Str.putBE(packet[0..2], U64(port));</code></pre>
13441380 <p><code>Math.toReal</code> reads a real as a constant is written (section 2), with a <code>-</code> or <code>+</code> before it if any, its point and the digits after it, or its exponent, left out if it has none, and <code>e</code> taken as <code>E</code>: <code>2</code>, <code>-0.5</code> and <code>1.5e-3</code> are reals to it. It gives the <code>F64</code> nearest the number, and <code>false</code> for anything else, or a number too big for an <code>F64</code>.</p>
13451381 <p><code>Map.next</code> 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:</p>
1346-<pre><code>i, k, v := Names.next(ADR(names), 0);
1382+<pre><code>i, k, v := Names.next(names, 0);
13471383 while i &gt;= 0 do
13481384 Fmt.print(&quot;{} is {}\n&quot;, [Fmt.str(k), Fmt.int(v)]);
1349- i, k, v := Names.next(ADR(names), i);
1385+ i, k, v := Names.next(names, i);
13501386 end;</code></pre>
13511387 <p><code>Sort.sort</code> puts <code>s</code> in the order <code>less</code> gives, in place, without memory of its own, in time <code>n log n</code> at most; two elements equal by <code>less</code> may change places. <code>Math</code>’s procedures are as C’s <code>math.h</code> has them, to within the last bit or so. <code>Fmt.real(x, places)</code> writes <code>x</code> with <code>places</code> digits after the point, at most 9, rounded to the nearest; from 1e15 on, with an exponent, as <code>1.50e17</code>; and <code>nan</code>, <code>inf</code> and <code>-inf</code> as themselves.</p>
13521388 <p><strong>Files and Opt</strong> are what most programs need of their command line.</p>
13531389 <pre><code>module Files;
13541390 proc arg*(i: INT): []U8; (* argument i; 0 is the program&#39;s name *)
1355-proc read*(path: []U8; b: ^Buf.Buf): BOOL; (* the whole file added to b *)
1356-proc load*(path: []U8; b: ^Buf.Buf): INT; (* as read: 0, or minus the errno that stopped it *)
1391+proc read*(path: []U8; var b: Buf.Buf): BOOL; (* the whole file added to b *)
1392+proc load*(path: []U8; var b: Buf.Buf): INT; (* as read: 0, or minus the errno that stopped it *)
13571393 proc write*(path, data: []U8): BOOL; (* the file made to hold data *)
13581394
13591395 module Opt;
@@ -1370,37 +1406,37 @@
13701406 spelt*: []U8; (* as it was written, no dashes: &quot;b&quot; or &quot;bar&quot;; to read only *)
13711407 ...
13721408 end;
1373-proc init*(p: ^Parser; name: []U8; table: []Row); (* the arguments from 1 on, by table *)
1374-proc next*(p: ^Parser): BOOL; (* the next option; false when they end *)
1375-proc operand*(p: ^Parser): ([]U8, BOOL); (* the next operand; false when there are no more *)
1376-proc at*(p: ^Parser): INT; (* the argument operand would give next *)
1377-proc scope*(p: ^Parser; name: []U8); (* subcommand name&#39;s options, from the word after it *)
1378-proc number*(p: ^Parser; lo, hi: I64): I64; (* the value just read, a number from lo to hi *)
1379-proc refuse*(p: ^Parser; wants: []U8); (* the value just read refused, as number refuses one *)
1380-proc fail*(p: ^Parser; text: []U8); (* the program&#39;s own mistake *)</code></pre>
1381-<p><code>Opt</code> reads a command line by the rules of the C library’s <code>getopt</code>, 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 <code>Row</code>s: 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 <code>p.letter</code> 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 <code>init</code> lives as long as the procedure that makes it.</p>
1409+proc init*(var p: Parser; name: []U8; table: []Row); (* the arguments from 1 on, by table *)
1410+proc next*(var p: Parser): BOOL; (* the next option; false when they end *)
1411+proc operand*(var p: Parser): ([]U8, BOOL); (* the next operand; false when there are no more *)
1412+proc at*(var p: Parser): INT; (* the argument operand would give next *)
1413+proc scope*(var p: Parser; name: []U8); (* subcommand name&#39;s options, from the word after it *)
1414+proc number*(const p: Parser; lo, hi: I64): I64; (* the value just read, a number from lo to hi *)
1415+proc refuse*(const p: Parser; wants: []U8); (* the value just read refused, as number refuses one *)
1416+proc fail*(const p: Parser; text: []U8); (* the program&#39;s own mistake *)</code></pre>
1417+<p><code>Opt</code> reads a command line by the rules of the C library’s <code>getopt</code>, 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 <code>Row</code>s: 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 <code>p.letter</code> 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 <code>init</code> lives as long as the procedure that makes it, and a constant, <code>const Rows: []Opt.Row = [...]</code>, as long as the program.</p>
13821418 <p>A row’s <code>scope</code> is <code>""</code> for the program itself, or a subcommand’s name: <code>"start"</code>, or <code>"remote.add"</code> for a subcommand of <code>remote</code>. An option has a <code>letter</code>, a <code>long</code> name, or both. One with a long name only has a key of its own below <code>'!'</code> for a letter, so that the program can tell it from the others. With a <code>value</code>, the name the help and the messages give it, the option takes a value; with <code>""</code> it is a flag. A value written in brackets, <code>"[when]"</code>, may be left out, and is <code>""</code> then: it is given only in the option’s own word, <code>--color=always</code> or <code>-calways</code>, never as the next, as <code>getopt</code>’s <code>::</code> has it, and the help shows it as <code>--color[=when]</code>.</p>
13831419 <pre><code>const wait = 1; (* the key of --wait, which has no letter *)
13841420 ...
1385-Opt.init(ADR(p), &quot;keep&quot;, [
1421+Opt.init(p, &quot;keep&quot;, [
13861422 Opt.usage(&quot;&quot;, &quot;keep [-v] [--wait secs] start ...&quot;),
13871423 Opt.sub(&quot;&quot;, &quot;start&quot;, &quot;start a job&quot;),
13881424 Opt.option(&quot;&quot;, &#39;v&#39;, &quot;verbose&quot;, &quot;&quot;, &quot;say more&quot;),
13891425 Opt.option(&quot;&quot;, wait, &quot;wait&quot;, &quot;secs&quot;, &quot;give the job secs to start&quot;),
13901426 Opt.usage(&quot;start&quot;, &quot;keep start [-b label] name command [argument ...]&quot;),
13911427 Opt.option(&quot;start&quot;, &#39;b&#39;, &quot;bar&quot;, &quot;label&quot;, &quot;show the job in the bar as label&quot;)]);
1392-while Opt.next(ADR(p)) do
1428+while Opt.next(p) do
13931429 if p.letter = &#39;v&#39; then verbose := true;
1394- elsif p.letter = wait then secs := Opt.number(ADR(p), 1, 600);
1430+ elsif p.letter = wait then secs := Opt.number(p, 1, 600);
13951431 end;
13961432 end;
1397-w, ok := Opt.operand(ADR(p));
1398-if not ok or (w # &quot;start&quot;) then Opt.fail(ADR(p), &quot;no command; see keep -h&quot;); end;
1399-Opt.scope(ADR(p), &quot;start&quot;);
1400-while Opt.next(ADR(p)) do
1433+w, ok := Opt.operand(p);
1434+if not ok or (w # &quot;start&quot;) then Opt.fail(p, &quot;no command; see keep -h&quot;); end;
1435+Opt.scope(p, &quot;start&quot;);
1436+while Opt.next(p) do
14011437 if p.letter = &#39;b&#39; then bar := p.value; end;
14021438 end;
1403-job, ok := Opt.operand(ADR(p));</code></pre>
1439+job, ok := Opt.operand(p);</code></pre>
14041440 <p>The rules are <code>getopt</code>’s:</p>
14051441 <ul>
14061442 <li>Flags may share a dash: <code>-lw</code> is <code>-l -w</code>. A letter’s value is the rest of its word, <code>-bdev</code>, or the whole next word, <code>-b dev</code>, even one that starts with a dash or is empty; in a group, the first letter that takes a value takes the rest, <code>-qn12</code>.</li>
@@ -1409,8 +1445,8 @@
14091445 <li>Each scope has its own options. An option given twice is read twice.</li>
14101446 </ul>
14111447 <p><code>number</code> reads the value as <code>Str.toInt</code> does. <code>operand</code> reads what options are left first, and the program doesn’t see them. So does <code>at</code>, which says where the operands are: the arguments from <code>operand</code>’s next on are <code>Files.arg(i)</code> for <code>i</code> from <code>at(p)</code> to <code>ARGC() - 1</code>, so that an interpreter hands a script its arguments as they are:</p>
1412-<pre><code>script, ok := Opt.operand(ADR(p)); (* tery file arg ... *)
1413-first := Opt.at(ADR(p)); (* file&#39;s own arguments, from here on *)</code></pre>
1448+<pre><code>script, ok := Opt.operand(p); (* tery file arg ... *)
1449+first := Opt.at(p); (* file&#39;s own arguments, from here on *)</code></pre>
14141450 <p><code>-h</code> or <code>--help</code> among a scope’s options prints its help on standard output and ends the program with status 0. <code>init</code> and <code>scope</code> answer it, looking through the scope’s options before <code>next</code> gives one, so that the program has done nothing yet: <code>keep -v -h -x</code> prints the help, and the program never sees <code>-v</code>, 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:</p>
14151451 <pre><code>usage: keep start [-b label] name command [argument ...]
14161452
@@ -1420,7 +1456,7 @@
14201456 <p>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:</p>
14211457 <pre><code>keep: unknown option -x
14221458 usage: keep start [-b label] name command [argument ...]</code></pre>
1423-<p>The sentences are <code>unknown option -x</code> (or <code>--name</code>, up to its <code>=</code>), <code>-b needs a label</code>, <code>--follow takes no value</code> and <code>--wait wants a number from 1 to 600, not '0'</code>; for a number with no top, given the largest <code>I64</code> for <code>hi</code>, <code>--jobs wants a number from 1 up, not '0'</code>. <code>refuse</code> refuses a value the program reads itself, as <code>number</code> refuses one, naming the option as the user wrote it, <code>-b</code> or <code>--bar</code>: <code>Opt.refuse(ADR(p), "a label with no spaces")</code> writes <code>keep: -b wants a label with no spaces, not 'a b'</code>, and the synopsis lines. <code>p.spelt</code> is that spelling, for the program’s own sentences. <code>fail</code> writes the program’s own mistakes the same way, but alone, so that the sentence can say where the help is: <code>keep: no command; see keep -h</code>.</p>
1459+<p>The sentences are <code>unknown option -x</code> (or <code>--name</code>, up to its <code>=</code>), <code>-b needs a label</code>, <code>--follow takes no value</code> and <code>--wait wants a number from 1 to 600, not '0'</code>; for a number with no top, given the largest <code>I64</code> for <code>hi</code>, <code>--jobs wants a number from 1 up, not '0'</code>. <code>refuse</code> refuses a value the program reads itself, as <code>number</code> refuses one, naming the option as the user wrote it, <code>-b</code> or <code>--bar</code>: <code>Opt.refuse(p, "a label with no spaces")</code> writes <code>keep: -b wants a label with no spaces, not 'a b'</code>, and the synopsis lines. <code>p.spelt</code> is that spelling, for the program’s own sentences. <code>fail</code> writes the program’s own mistakes the same way, but alone, so that the sentence can say where the help is: <code>keep: no command; see keep -h</code>.</p>
14241460 <p>A mistake in the table is the program’s, not its user’s. <code>init</code> checks the table before it reads a word, and ends the program with status 1: <code>keep: option table, row 3: the option is in the scope already</code>. The others are an option with neither a letter nor a long name, a long name with <code>=</code> in it, a letter <code>-</code>, a value with one bracket but not the other, and <code>--help</code> in the table, since it is <code>Opt</code>’s.</p>
14251461 <p><strong>Width</strong> 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.</p>
14261462 <pre><code>module Width;

site/public/tour/defer.html (history) modified +7 -7

@@ -154,16 +154,16 @@
154154 <span class="kw">var</span> b: Buf.Buf;
155155 <span class="kw">begin</span>
156156 <span class="kw">if</span> n &lt; <span class="number">0</span> <span class="kw">then</span> <span class="kw">return</span> <span class="ty">false</span>; <span class="kw">end</span>;
157- Buf.init(<span class="ty">ADR</span>(b), Heap.heap);
158- <span class="kw">defer</span> Buf.done(<span class="ty">ADR</span>(b)); <span class="comment">(* freed on every way out below *)</span>
159- Buf.str(<span class="ty">ADR</span>(b), <span class="string">&quot;n is &quot;</span>);
157+ Buf.init(b, Heap.heap);
158+ <span class="kw">defer</span> Buf.done(b); <span class="comment">(* freed on every way out below *)</span>
159+ Buf.str(b, <span class="string">&quot;n is &quot;</span>);
160160 <span class="kw">if</span> n &gt; <span class="number">9</span> <span class="kw">then</span>
161- Buf.str(<span class="ty">ADR</span>(b), <span class="string">&quot;large&quot;</span>);
162- Out.str(Buf.bytes(<span class="ty">ADR</span>(b))); Out.ln;
161+ Buf.str(b, <span class="string">&quot;large&quot;</span>);
162+ Out.str(Buf.bytes(b)); Out.ln;
163163 <span class="kw">return</span> <span class="ty">true</span>;
164164 <span class="kw">end</span>;
165- Buf.str(<span class="ty">ADR</span>(b), <span class="string">&quot;small&quot;</span>);
166- Out.str(Buf.bytes(<span class="ty">ADR</span>(b))); Out.ln;
165+ Buf.str(b, <span class="string">&quot;small&quot;</span>);
166+ Out.str(Buf.bytes(b)); Out.ln;
167167 <span class="kw">return</span> <span class="ty">true</span>;
168168 <span class="kw">end</span>;
169169

site/public/tour/hello.html (history) modified +1 -1

@@ -70,7 +70,7 @@
7070 <span class="cmd">$ raz run Quiet.raz</span>
7171 hello, again
7272 <span class="cmd">$ ls -l Quiet | awk &#x27;{print $5, &quot;bytes&quot;}&#x27;</span>
73-28472 bytes</code></pre>
73+28440 bytes</code></pre>
7474 <p>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.</p>
7575 <h2>What <code>Out</code> can write</h2>
7676 <p><code>Out</code> 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 <code>\n</code> for a line feed, <code>\t</code> for a tab, <code>\"</code> and <code>\\</code>; or between backquotes, as a raw string with no escapes at all, which may run over lines (lesson 6).</p>

site/public/tour/memory.html (history) modified +19 -19

@@ -68,10 +68,10 @@
6868 Mem.free(Heap.heap, ^<span class="ty">U8</span>(n));
6969 <span class="kw">end</span>;
7070 Out.ln;
71- <span class="kw">if</span> <span class="kw">not</span> Arena.init(<span class="ty">ADR</span>(ar), <span class="number">100000</span>) <span class="kw">then</span> <span class="kw">return</span>; <span class="kw">end</span>;
71+ <span class="kw">if</span> <span class="kw">not</span> Arena.init(ar, <span class="number">100000</span>) <span class="kw">then</span> <span class="kw">return</span>; <span class="kw">end</span>;
7272 <span class="kw">for</span> i := <span class="number">1</span> <span class="kw">to</span> <span class="number">1000</span> <span class="kw">do</span> top := push(top, i, <span class="ty">ADR</span>(ar.base)); <span class="kw">end</span>;
7373 Out.int(top^.val); Out.ln;
74- Arena.done(<span class="ty">ADR</span>(ar)); <span class="comment">(* every node at once *)</span>
74+ Arena.done(ar); <span class="comment">(* every node at once *)</span>
7575 <span class="kw">end</span>;
7676
7777 <span class="kw">end</span> Stack.</code></pre>
@@ -112,18 +112,18 @@
112112 <span class="kw">proc</span> main*;
113113 <span class="kw">var</span> ar: Arena.Arena; small: Arena.Arena; list: ^Item;
114114 <span class="kw">begin</span>
115- <span class="kw">if</span> <span class="kw">not</span> Arena.init(<span class="ty">ADR</span>(ar), <span class="number">1000000</span>) <span class="kw">then</span> <span class="kw">return</span>; <span class="kw">end</span>;
115+ <span class="kw">if</span> <span class="kw">not</span> Arena.init(ar, <span class="number">1000000</span>) <span class="kw">then</span> <span class="kw">return</span>; <span class="kw">end</span>;
116116 list := make(<span class="number">1000</span>, <span class="ty">ADR</span>(ar.base));
117117 Out.int(count(list)); Out.str(<span class="string">&quot; items from a big arena\n&quot;</span>);
118- Arena.reset(<span class="ty">ADR</span>(ar)); <span class="comment">(* every allocation forgotten *)</span>
118+ Arena.reset(ar); <span class="comment">(* every allocation forgotten *)</span>
119119 list := make(<span class="number">10</span>, <span class="ty">ADR</span>(ar.base));
120120 Out.int(count(list)); Out.str(<span class="string">&quot; after a reset\n&quot;</span>);
121- Arena.done(<span class="ty">ADR</span>(ar));
121+ Arena.done(ar);
122122
123- <span class="kw">if</span> <span class="kw">not</span> Arena.init(<span class="ty">ADR</span>(small), <span class="number">4096</span>) <span class="kw">then</span> <span class="kw">return</span>; <span class="kw">end</span>;
123+ <span class="kw">if</span> <span class="kw">not</span> Arena.init(small, <span class="number">4096</span>) <span class="kw">then</span> <span class="kw">return</span>; <span class="kw">end</span>;
124124 list := make(<span class="number">1000</span>, <span class="ty">ADR</span>(small.base));
125125 <span class="kw">if</span> list = <span class="ty">nil</span> <span class="kw">then</span> Out.str(<span class="string">&quot;a small arena ran out, and said so\n&quot;</span>); <span class="kw">end</span>;
126- Arena.done(<span class="ty">ADR</span>(small));
126+ Arena.done(small);
127127 <span class="kw">end</span>;
128128
129129 <span class="kw">end</span> Pool.</code></pre>
@@ -164,21 +164,21 @@
164164 <span class="kw">proc</span> main*;
165165 <span class="kw">var</span> b: Buf.Buf; i: <span class="ty">INT</span>;
166166 <span class="kw">begin</span>
167- Buf.init(<span class="ty">ADR</span>(b), Heap.heap);
168- <span class="kw">defer</span> Buf.done(<span class="ty">ADR</span>(b));
167+ Buf.init(b, Heap.heap);
168+ <span class="kw">defer</span> Buf.done(b);
169169 <span class="kw">for</span> i := <span class="number">1</span> <span class="kw">to</span> <span class="number">5</span> <span class="kw">do</span>
170- Buf.str(<span class="ty">ADR</span>(b), <span class="string">&quot;item &quot;</span>);
171- Buf.add(<span class="ty">ADR</span>(b), <span class="ty">U8</span>(<span class="string">&#x27;0&#x27;</span> + i));
172- Buf.add(<span class="ty">ADR</span>(b), <span class="string">&#x27;,&#x27;</span>);
170+ Buf.str(b, <span class="string">&quot;item &quot;</span>);
171+ Buf.add(b, <span class="ty">U8</span>(<span class="string">&#x27;0&#x27;</span> + i));
172+ Buf.add(b, <span class="string">&#x27;,&#x27;</span>);
173173 <span class="kw">end</span>;
174- Out.str(Buf.bytes(<span class="ty">ADR</span>(b))); Out.ln;
174+ Out.str(Buf.bytes(b)); Out.ln;
175175 Out.int(b.len); Out.str(<span class="string">&quot; bytes\n&quot;</span>);
176- Buf.reset(<span class="ty">ADR</span>(b));
177- Str.join(<span class="ty">ADR</span>(b), [<span class="string">&quot;red&quot;</span>, <span class="string">&quot;green&quot;</span>, <span class="string">&quot;blue&quot;</span>], <span class="string">&quot;, &quot;</span>);
178- Out.str(Buf.bytes(<span class="ty">ADR</span>(b))); Out.ln;
179- Buf.reset(<span class="ty">ADR</span>(b));
180- Str.replace(<span class="ty">ADR</span>(b), <span class="string">&quot;a-b-c&quot;</span>, <span class="string">&quot;-&quot;</span>, <span class="string">&quot; and &quot;</span>);
181- Out.str(Buf.bytes(<span class="ty">ADR</span>(b))); Out.ln;
176+ Buf.reset(b);
177+ Str.join(b, [<span class="string">&quot;red&quot;</span>, <span class="string">&quot;green&quot;</span>, <span class="string">&quot;blue&quot;</span>], <span class="string">&quot;, &quot;</span>);
178+ Out.str(Buf.bytes(b)); Out.ln;
179+ Buf.reset(b);
180+ Str.replace(b, <span class="string">&quot;a-b-c&quot;</span>, <span class="string">&quot;-&quot;</span>, <span class="string">&quot; and &quot;</span>);
181+ Out.str(Buf.bytes(b)); Out.ln;
182182 <span class="kw">end</span>;
183183
184184 <span class="kw">end</span> Build.</code></pre>

site/public/tour/records.html (history) modified +60 -1

@@ -284,7 +284,66 @@
284284
285285 <span class="kw">end</span> Chain.</code></pre>
286286 <pre class="output"><code>40 30 20 10
287-</code></pre><p class="tryit">Save a program under its module&rsquo;s name and run it with <code>raz run Name.raz</code>.</p><div class="pager"><a href="slices.html">&larr; Arrays, slices and strings</a><a href="index.html">Contents</a><a class="next" href="variants.html">Enumerations, sets, variants and match &rarr;</a></div></article></div>
287+</code></pre>
288+<h2>A slice's pointer</h2>
289+<p>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. <code>LEN(s)</code> is the length. The pointer looks like <code>ADR(s[0])</code>, the address of the first element, and that works until the slice is empty: then there is no first element, <code>s[0]</code> is out of range, and the program stops.</p>
290+<div class="file"><span>Empty.raz</span></div><pre class="code"><code><span class="kw">module</span> Empty;
291+<span class="kw">import</span> Out;
292+
293+<span class="kw">type</span> Span = <span class="kw">record</span> p: ^<span class="ty">U8</span>; n: <span class="ty">INT</span>; <span class="kw">end</span>;
294+
295+<span class="kw">proc</span> spanOf(s: []<span class="ty">U8</span>): Span;
296+<span class="kw">begin</span>
297+ <span class="kw">return</span> {p: <span class="ty">ADR</span>(s[<span class="number">0</span>]), n: <span class="ty">LEN</span>(s)};
298+<span class="kw">end</span>;
299+
300+<span class="kw">proc</span> main*;
301+<span class="kw">var</span> a, b: Span;
302+<span class="kw">begin</span>
303+ a := spanOf(<span class="string">&quot;one&quot;</span>);
304+ Out.int(a.n); Out.ln;
305+ b := spanOf(<span class="string">&quot;&quot;</span>);
306+ Out.int(b.n); Out.ln;
307+<span class="kw">end</span>;
308+
309+<span class="kw">end</span> Empty.</code></pre>
310+<pre class="output"><code>3
311+<span class="err">Empty.raz:8:22: index 0 is out of range for a length of 0
312+ in Empty.spanOf at Empty.raz:8:22
313+ in Empty.main at Empty.raz:16:5
314+</span></code></pre>
315+<p><code>PTR(s)</code> is the pointer itself, a <code>^U8</code> for a <code>[]U8</code>, with no check. For a slice that isn't empty it is <code>ADR(s[0])</code>; for an empty one it is what the slice holds, <code>nil</code> for one never set. So nothing needs testing first, and <code>sp.p[0..sp.n]</code> makes the slice again, empty when <code>sp.n</code> is 0, whatever <code>sp.p</code> is:</p>
316+<div class="file"><span>Spans.raz</span></div><pre class="code"><code><span class="kw">module</span> Spans;
317+<span class="kw">import</span> Out;
318+
319+<span class="kw">type</span> Span = <span class="kw">record</span> p: ^<span class="ty">U8</span>; n: <span class="ty">INT</span>; <span class="kw">end</span>;
320+
321+<span class="kw">proc</span> spanOf(s: []<span class="ty">U8</span>): Span;
322+<span class="kw">begin</span>
323+ <span class="kw">return</span> {p: PTR(s), n: <span class="ty">LEN</span>(s)};
324+<span class="kw">end</span>;
325+
326+<span class="kw">proc</span> text(sp: Span): []<span class="ty">U8</span>;
327+<span class="kw">begin</span>
328+ <span class="kw">return</span> sp.p[<span class="number">0</span>..sp.n];
329+<span class="kw">end</span>;
330+
331+<span class="kw">proc</span> main*;
332+<span class="kw">var</span> words: [<span class="number">3</span>]Span; i: <span class="ty">INT</span>;
333+<span class="kw">begin</span>
334+ words := [spanOf(<span class="string">&quot;one&quot;</span>), spanOf(<span class="string">&quot;&quot;</span>), spanOf(<span class="string">&quot;three&quot;</span>)];
335+ <span class="kw">for</span> i := <span class="number">0</span> <span class="kw">to</span> <span class="number">2</span> <span class="kw">do</span>
336+ Out.int(words[i].n); Out.char(<span class="string">&#x27; &#x27;</span>);
337+ Out.str(text(words[i])); Out.ln;
338+ <span class="kw">end</span>;
339+<span class="kw">end</span>;
340+
341+<span class="kw">end</span> Spans.</code></pre>
342+<pre class="output"><code>3 one
343+0
344+5 three
345+</code></pre>
346+<p>Of an array, <code>PTR(a)</code> is the address of its first element, a <code>^T</code> where <code>ADR(a)</code> is a <code>^[n]T</code>. 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 <code>PTR(s)</code> and <code>LEN(s)</code>, and a pointer given where a slice is, <code>p[0..n]</code>.</p><p class="tryit">Save a program under its module&rsquo;s name and run it with <code>raz run Name.raz</code>.</p><div class="pager"><a href="slices.html">&larr; Arrays, slices and strings</a><a href="index.html">Contents</a><a class="next" href="variants.html">Enumerations, sets, variants and match &rarr;</a></div></article></div>
288347 </main>
289348 <footer>raz is under the ISC license.</footer>
290349 </body>

site/public/tour/threads.html (history) modified +4 -4

@@ -58,9 +58,9 @@
5858 sum := sum + i;
5959 _ := <span class="ty">XADD</span>(<span class="ty">ADR</span>(hits), <span class="number">1</span>);
6060 <span class="kw">end</span>;
61- Thread.lock(<span class="ty">ADR</span>(m));
61+ Thread.lock(m);
6262 total := total + sum;
63- Thread.unlock(<span class="ty">ADR</span>(m));
63+ Thread.unlock(m);
6464 <span class="kw">end</span>;
6565
6666 <span class="kw">proc</span> main*;
@@ -124,10 +124,10 @@
124124 <span class="kw">var</span> i: <span class="ty">INT</span>;
125125 <span class="kw">begin</span>
126126 <span class="kw">for</span> i := <span class="number">1</span> <span class="kw">to</span> <span class="number">10000</span> <span class="kw">do</span>
127- Thread.lock(<span class="ty">ADR</span>(m));
127+ Thread.lock(m);
128128 balance := balance + <span class="number">5</span>;
129129 <span class="ty">INC</span>(deposits);
130- Thread.unlock(<span class="ty">ADR</span>(m));
130+ Thread.unlock(m);
131131 <span class="kw">end</span>;
132132 <span class="kw">end</span>;
133133

site/public/tour/variants.html (history) modified +6 -5

@@ -51,7 +51,9 @@
5151 dot;
5252 <span class="kw">end</span>;
5353
54-<span class="kw">proc</span> area(s: Shape): <span class="ty">F64</span>;
54+<span class="kw">const</span> Some: []Shape = [circle(<span class="number">1.0</span>), rect(<span class="number">2.0</span>, <span class="number">3.5</span>), dot];
55+
56+<span class="kw">proc</span> area(<span class="kw">const</span> s: Shape): <span class="ty">F64</span>;
5557 <span class="kw">begin</span>
5658 <span class="kw">match</span> s <span class="kw">of</span>
5759 | circle(r): <span class="kw">return</span> Math.pi * r * r;
@@ -80,11 +82,10 @@
8082 <span class="kw">end</span>;
8183
8284 <span class="kw">proc</span> main*;
83-<span class="kw">var</span> shapes: [<span class="number">3</span>]Shape; i: <span class="ty">INT</span>; warm: Colours; c: Colour;
85+<span class="kw">var</span> i: <span class="ty">INT</span>; warm: Colours; c: Colour;
8486 <span class="kw">begin</span>
85- shapes := [circle(<span class="number">1.0</span>), rect(<span class="number">2.0</span>, <span class="number">3.5</span>), dot];
86- <span class="kw">for</span> i := <span class="number">0</span> <span class="kw">to</span> <span class="number">2</span> <span class="kw">do</span>
87- Fmt.print(<span class="string">&quot;{}\n&quot;</span>, [Fmt.real(area(shapes[i]), <span class="number">2</span>)]);
87+ <span class="kw">for</span> i := <span class="number">0</span> <span class="kw">to</span> <span class="ty">LEN</span>(Some) - <span class="number">1</span> <span class="kw">do</span>
88+ Fmt.print(<span class="string">&quot;{}\n&quot;</span>, [Fmt.real(area(Some[i]), <span class="number">2</span>)]);
8889 <span class="kw">end</span>;
8990 Fmt.print(<span class="string">&quot;{} {} {}\n&quot;</span>, [Fmt.str(kind(<span class="string">&#x27;7&#x27;</span>)), Fmt.str(kind(<span class="string">&#x27;x&#x27;</span>)),
9091 Fmt.str(kind(<span class="string">&#x27;+&#x27;</span>))]);