raz / commit 3e3ad9d8

commit
3e3ad9d88088eda2e399a59b6d86b802fd3abf59
author
Luis <42945842+ldiaz94@users.noreply.github.com>
date
parent
3623192c
site: Bytes, slices in code procedures, record constants; the download

More Raz's strings lesson gains Bytes, its asm lesson slices in and out
of code procedures (10.18) and popcnt as the assembler now knows it;
the tour gains record constants (10.16) and Math's pow, log2, round.
The home page's numbers are current; the links to the private GitHub
repo are gone.

The report's tables span the column, with columns as wide as their
text (pandoc no longer splits them equally) and cells set at the top.

make dist makes the release's tarball, for CI and the site alike;
site/build.py builds the latest tag's in a checkout of its own and
serves it from download/, with its SHA-256 and download/latest.

patch · log

51 files changed, +763 -1588

.github/workflows/ci.yml (history) modified +2 -5

@@ -30,9 +30,6 @@
3030 env:
3131 GH_TOKEN: ${{ github.token }}
3232 run: |
33- d=raz-${TAG#v}-linux-x86_64
34- mkdir -p $d/man && cp -r raz lib LICENSE README.md $d
35- cp doc/raz.1 doc/raz.7 doc/raz-tutorial.7 build/raz-lib.3 $d/man
36- tar czf $d.tar.gz $d
37- gh release create "$TAG" $d.tar.gz --verify-tag \
33+ make dist
34+ gh release create "$TAG" build/raz-${TAG#v}-linux-x86_64.tar.gz --verify-tag \
3835 --title "raz ${TAG#v}" --notes "$(./raz --version)"

Makefile (history) modified +21 -2

@@ -119,10 +119,29 @@
119119 rm -rf $(PREFIX)/lib/raz $(PREFIX)/bin/raz $(MAN)/man1/raz.1 $(MAN)/man3/raz-lib.3 \
120120 $(MAN)/man7/raz.7 $(MAN)/man7/raz-tutorial.7
121121
122+# A release's tarball, build/raz-V-linux-x86_64.tar.gz: raz, the lib/
123+# it reads beside itself, and the manual pages, V being what raz
124+# --version says. It is made of the checkout in TREE, this one unless
125+# given: CI packs the tag it checked out, and site/build.py the latest
126+# tag, which it checks out apart.
127+TREE = .
128+
129+dist:
130+ $(MAKE) -C $(TREE) raz man
131+ v=$$($(TREE)/raz --version | sed 's/^raz \([^,]*\),.*/\1/'); \
132+ d=raz-$$v-linux-x86_64; \
133+ rm -rf build/$$d && mkdir -p build/$$d/man && \
134+ cp -r $(TREE)/raz $(TREE)/lib $(TREE)/LICENSE $(TREE)/README.md build/$$d && \
135+ cp $(TREE)/doc/raz.1 $(TREE)/doc/raz.7 $(TREE)/doc/raz-tutorial.7 \
136+ $(TREE)/build/raz-lib.3 build/$$d/man && \
137+ tar czf build/$$d.tar.gz -C build $$d && rm -rf build/$$d && \
138+ echo build/$$d.tar.gz
139+
122140 # The website, plain files in site/public/: its home page, the tour
123141 # "Raz, Set, Go" (whose programs are run here, so the output shown is
124-# real) and the report. site/build.py says how; it needs ./raz and pandoc.
142+# real), the report and the latest release's tarball. site/build.py
143+# says how; it needs ./raz and pandoc.
125144 site: raz
126145 python3 site/build.py
127146
128-.PHONY: units tests check gdb bench kernels stress fmt loc man pdf site clean install uninstall
147+.PHONY: units tests check gdb bench kernels stress fmt loc man pdf dist site clean install uninstall

README.md (history) modified +7 -3

@@ -41,7 +41,7 @@
4141 | `examples/` | Small programs, each with the output it should give |
4242 | `tools/Doc.raz` | Prints what a module exports, with its comments |
4343 | `tools/Pretty.raz` | The formatter: fixes indentation and spacing |
44-| `site/` | The website: home page, the tour "Raz, Set, Go" and the report, as plain files in `site/public/`; `make site` rebuilds them |
44+| `site/` | The website: home page, the tours "Raz, Set, Go" and "More Raz", the report and the latest release's tarball, as plain files in `site/public/`; `make site` rebuilds them |
4545 | `editor/` | Support for vim and emacs |
4646 | `conform/` | The conformance suite: what every implementation must do |
4747 | `test/` | This compiler's own tests, and the scripts that run them |
@@ -71,6 +71,7 @@
7171 make loc # the compiler's lines
7272 make tests # tests of the scanner, encoder and linker on their own
7373 make pdf # build/raz.pdf, the report, by pandoc and Chromium
74+ make dist # build/raz-V-linux-x86_64.tar.gz, the release's tarball
7475 make site # site/public/, the website, by pandoc and python3
7576
7677 ## Using it
@@ -202,8 +203,11 @@
202203 $ git push origin v0.9.1
203204
204205 GitHub then builds and checks the tag, and makes a release of it with
205-a tarball of `raz`, its `lib/` and its manual pages. A tag pushed before the workflow
206-existed is released from the Actions tab: run "ci" with its name.
206+a tarball of `raz`, its `lib/` and its manual pages, made by `make
207+dist`. A tag pushed before the workflow existed is released from the
208+Actions tab: run "ci" with its name. Then `make site` puts the new
209+tag's tarball on the website (it builds it from the tag, apart from
210+the tree at hand); commit `site/public/` and push to publish it.
207211
208212 A version of the report is named by its month and a count; the report's
209213 last section says what each version changed.

site/build.py modified +41 -9

@@ -6,7 +6,8 @@
66 The site is plain files: open public/index.html, or put the folder on
77 any web server. Nothing runs in the reader's browser; the code on the
88 tour's pages is run here, by ./raz, and the output shown is what it
9-printed, so a lesson that stops working fails the build.
9+printed, so a lesson that stops working fails the build. The home page
10+offers the latest release's tarball, made by make dist from the tag.
1011
1112 Lessons are site/content/<tour>/NN-name.txt, one folder to a tour (see
1213 TOURS below):
@@ -31,13 +32,12 @@
3132 session: each line that starts with "$ " is run in the lesson's folder,
3233 with raz on the path, and shown with what it printed.
3334 """
34-import html, os, re, shutil, subprocess, sys, tempfile
35+import hashlib, html, os, re, shutil, subprocess, sys, tempfile
3536
3637 HERE = os.path.dirname(os.path.abspath(__file__))
3738 ROOT = os.path.dirname(HERE)
3839 OUT = os.path.join(HERE, "public")
3940 RAZ = os.path.join(ROOT, "raz")
40-REPO = "https://github.com/ldiaz94/raz"
4141 SITE = "https://raz.lucelad.workers.dev" # where the pages live, for the preview image
4242
4343 # folder in content/, folder in public/, name, the sentence under the name
@@ -237,14 +237,14 @@
237237 <link rel="stylesheet" href="%sstyle.css">
238238 </head>
239239 <body>
240-<header><nav><a class="mark" href="%sindex.html"><img src="%slogo.svg" width="26" height="26" alt="">raz</a>%s<a class="repo" href="%s">GitHub</a></nav></header>
240+<header><nav><a class="mark" href="%sindex.html"><img src="%slogo.svg" width="26" height="26" alt="">raz</a>%s</nav></header>
241241 <main>
242242 %s
243243 </main>
244-<footer>raz is under the ISC license. <a href="%s">Source</a>.</footer>
244+<footer>raz is under the ISC license.</footer>
245245 </body>
246246 </html>
247-""" % (html.escape(title), html.escape(title), SITE, up, up, up, up, up, up, nav, REPO, body, REPO)
247+""" % (html.escape(title), html.escape(title), SITE, up, up, up, up, up, up, nav, body)
248248
249249 def write(path, text):
250250 path = os.path.join(OUT, path)
@@ -307,12 +307,41 @@
307307 p = subprocess.run(
308308 ["pandoc", os.path.join(ROOT, "doc", "raz.md"), "-s", "--template",
309309 os.path.join(HERE, "content", "spec.tmpl"), "--toc", "--toc-depth=1",
310- "--shift-heading-level-by=-1", "--no-highlight", "-t", "html"],
310+ "--shift-heading-level-by=-1", "--no-highlight", "-t", "html",
311+ # wide enough that no row of a table is "long": pandoc would
312+ # otherwise give each column an equal share of the width
313+ "--columns=10000"],
311314 capture_output=True, text=True, check=True)
312315 body = '<div class="spec">%s</div>' % p.stdout
313316 write("spec.html", page("The raz report", body, 0, "spec"))
314317
315-def build_home():
318+def build_download():
319+ """The latest release's tarball, in public/download/ with its SHA-256
320+ and /download/latest leading to it; (version, file name, SHA-256).
321+ It is made of the tag's own checkout, not of the tree at hand, and
322+ kept in build/ to be made once."""
323+ git = lambda *a: subprocess.run(("git", "-C", ROOT) + a, capture_output=True,
324+ text=True, check=True).stdout.strip()
325+ tag = git("describe", "--tags", "--abbrev=0", "--match", "v*")
326+ name = "raz-%s-linux-x86_64.tar.gz" % tag[1:]
327+ made = os.path.join(ROOT, "build", name)
328+ if not os.path.exists(made):
329+ tree = tempfile.mkdtemp()
330+ try:
331+ git("worktree", "add", "--detach", tree, tag)
332+ subprocess.run(["make", "-s", "-C", ROOT, "dist", "TREE=" + tree],
333+ stdout=subprocess.DEVNULL, check=True)
334+ finally:
335+ git("worktree", "remove", "--force", tree)
336+ digest = hashlib.sha256(open(made, "rb").read()).hexdigest()
337+ os.makedirs(os.path.join(OUT, "download"))
338+ shutil.copy(made, os.path.join(OUT, "download"))
339+ write("download/%s.sha256" % name, "%s %s\n" % (digest, name))
340+ # Cloudflare reads _redirects from the root of what it serves
341+ write("_redirects", "/download/latest /download/%s 302\n" % name)
342+ return tag[1:], name, digest
343+
344+def build_home(release):
316345 snippet = open(os.path.join(HERE, "content", "home.raz"), encoding="utf-8").read()
317346 tmp = tempfile.mkdtemp()
318347 try:
@@ -326,6 +355,9 @@
326355 text = open(os.path.join(HERE, "content", "home.html"), encoding="utf-8").read()
327356 text = text.replace("@SNIPPET@", highlight(snippet.rstrip("\n")))
328357 text = text.replace("@OUTPUT@", html.escape(stdout.rstrip("\n")))
358+ version, name, digest = release
359+ text = text.replace("@VERSION@", version).replace("@TARBALL@", name)
360+ text = text.replace("@DIR@", name[:-len(".tar.gz")]).replace("@SHA256@", digest)
329361 write("index.html", page("raz: a small systems language", text, 0, "home"))
330362
331363 def main():
@@ -351,7 +383,7 @@
351383 build_tour(tour, lessons, nxt)
352384 counts.append(len(lessons))
353385 build_spec()
354- build_home()
386+ build_home(build_download())
355387 print("site/public: %s lessons" % " + ".join(map(str, counts)))
356388
357389 main()

site/content/advanced/02-bytes.txt (history) modified +40 -2

@@ -1,8 +1,8 @@
11 title: Strings and bytes
22 part: The library
3-summary: Copying, hashing and ordering strings, and reading and writing binary formats.
3+summary: Copying, hashing and ordering strings, searching bytes many at a time, and reading and writing binary formats.
44 ---
5-A `[]U8` is both a string and a block of bytes. `Str` has what is done with them: comparing, finding, hashing, copying into memory of your own, UTF-8, numbers, and the fixed byte orders of file formats and network protocols.
5+A `[]U8` is both a string and a block of bytes. `Str` has what is done with them: comparing, finding, hashing, copying into memory of your own, UTF-8, numbers, and the fixed byte orders of file formats and network protocols. `Bytes` has the searches, made fast.
66
77 ## Ordering and hashing
88
@@ -75,6 +75,44 @@
7575
7676 end Keep.
7777 ```
78+
79+## Searching
80+
81+`Bytes` finds bytes many at a time: `Bytes.index` and `Bytes.last` give the first and the last place of a byte in a `[]U8`, or -1, `Bytes.count` how many places it has, and `Bytes.find` where one `[]U8` first starts in another (`Str.find` is the same). Each is what a loop over the bytes would give, only faster: the library's own body compares eight bytes at once in a `U64`, and on x86-64 a file of its own, `Bytes.x86_64.raz`, compares sixteen with SSE2, in code procedures.
82+
83+```raz Paths run
84+module Paths;
85+import Out, Fmt, Bytes;
86+
87+(* the last part of a path: what follows its last slash *)
88+proc base(path: []U8): []U8;
89+begin
90+ return path[Bytes.last(path, '/') + 1..LEN(path)];
91+end;
92+
93+proc main*;
94+var text: []U8; at, n, line: INT;
95+begin
96+ Out.str(base("/usr/local/lib/raz/Bytes.raz")); Out.char(' ');
97+ Out.str(base("Out.raz")); Out.ln;
98+
99+ text := "one line\nanother line\nthe line with raz in it\nthe last\n";
100+ Fmt.print("{} lines\n", [Fmt.int(Bytes.count(text, 10))]);
101+ at := Bytes.find(text, "raz");
102+ if at >= 0 then
103+ (* the line it is on: the newlines before it, plus one *)
104+ line := Bytes.count(text[0..at], 10) + 1;
105+ n := Bytes.index(text[at..LEN(text)], 10);
106+ Fmt.print("raz on line {}, at {}, and the line goes on {} more\n",
107+ [Fmt.int(line), Fmt.int(at), Fmt.int(n)]);
108+ end;
109+ Fmt.print("{} {}\n", [Fmt.int(Bytes.find(text, "zzz")), Fmt.int(Bytes.find(text, ""))]);
110+end;
111+
112+end Paths.
113+```
114+
115+When the byte isn't there, `Bytes.last` gives -1, so `base` of a name with no slash is the whole name. A search of a slice gives places in the slice, counted from its own start: add the place the slice starts at to get one in the whole.
78116
79117 ## Binary formats
80118

site/content/advanced/11-asm.txt (history) modified +46 -9

@@ -42,7 +42,8 @@
4242 - Integer and pointer arguments arrive in `rdi`, `rsi`, `rdx`, `rcx`, `r8` and `r9`; `F32` and `F64` ones in `xmm0` to `xmm7`.
4343 - The result goes in `rax` (and `rdx` for a second) or `xmm0`.
4444 - It must keep `rbx`, `rbp`, `rsp` and `r12` to `r15` as it found them. `rax`, `rcx`, `rdx`, `rsi`, `rdi` and `r8` to `r11` are free to change.
45-- Its parameters and results are therefore of the types C can take, at most six integer and eight real parameters and two results.
45+- A slice is two integers, its address and its length, as System V passes a struct of two. As a parameter it takes two registers in a row; as the result its address goes in `rax` and its length in `rdx`.
46+- Its parameters and results are therefore of the types C can take, or slices: at most six integer and eight real parameters, and two results, a slice being the only one.
4647
4748 That is why the next one is so short: the argument is already in `rdi`.
4849
@@ -59,10 +60,10 @@
5960 ret;
6061 end swap64;
6162
62-(* the number of bits set in x: popcnt rax, rdi *)
63+(* the number of bits set in x *)
6364 proc ones(x: U64): INT;
6465 code
65- db 0F3H, 48H, 0FH, 0B8H, 0C7H;
66+ popcnt rax, rdi;
6667 ret;
6768 end ones;
6869
@@ -77,18 +78,18 @@
7778 end Bits.
7879 ```
7980
80-`db` writes any bytes, for an instruction the assembler doesn't know. Which instructions it knows is the implementation's business; `db` keeps you from waiting for it to learn one. (The two instructions above are from the processor manuals: `bswap r64` is `REX.W 0F C8+r`, `popcnt r64, r/m64` is `F3 REX.W 0F B8 /r`.)
81+`db` writes any bytes, for an instruction the assembler doesn't know. Which instructions it knows is the implementation's business: this one knows `popcnt` but not `bswap`, and `db` keeps you from waiting for it to learn one. (`bswap r64` is `REX.W 0F C8+r` in the processor manuals.)
8182
8283 ## Labels and loops
8384
84-A label, `name:`, names the place of the instruction after it, within the procedure. Jumps go to labels, and a constant of the module may stand wherever a number does. This sums an array of `INT`s, which a pointer and a length describe:
85+A label, `name:`, names the place of the instruction after it, within the procedure. Jumps go to labels, and a constant of the module may stand wherever a number does. This sums a slice of `INT`s, whose address arrives in `rdi` and its length in `rsi`:
8586
8687 ```raz Sum run
8788 module Sum;
8889 import Out;
8990
90-(* the sum of the n INTs at p *)
91-proc sum(p: ^INT; n: INT): INT;
91+(* the sum of the INTs of a *)
92+proc sum(a: []INT): INT;
9293 code
9394 xor eax, eax;
9495 test rsi, rsi;
@@ -114,12 +115,48 @@
114115 var a: [6]INT; i: INT;
115116 begin
116117 for i := 0 to 5 do a[i] := (i + 1) * 100; end;
117- Out.int(sum(ADR(a[0]), 6)); Out.char(' ');
118+ Out.int(sum(a)); Out.char(' ');
118119 Out.int(sumRaz(a)); Out.char(' ');
119- Out.int(sum(ADR(a[0]), 0)); Out.ln;
120+ Out.int(sum(a[2..4])); Out.char(' ');
121+ Out.int(sum(a[0..0])); Out.ln;
120122 end;
121123
122124 end Sum.
125+```
126+
127+The procedure trusts the length it is given, as it must: the checks of the language end where its code begins.
128+
129+A slice comes back the same way, its address in `rax` and its length in `rdx`. This one returns what is left of a string past its leading blanks:
130+
131+```raz Trim run
132+module Trim;
133+import Out;
134+
135+(* s past its leading blanks *)
136+proc trim(s: []U8): []U8;
137+code
138+ mov rax, rdi;
139+ mov rdx, rsi;
140+again:
141+ test rdx, rdx;
142+ jz done;
143+ cmp byte [rax], 32;
144+ jne done;
145+ inc rax;
146+ dec rdx;
147+ jmp again;
148+done:
149+ ret;
150+end trim;
151+
152+proc main*;
153+begin
154+ Out.char('['); Out.str(trim(" raz")); Out.str("]\n");
155+ Out.char('['); Out.str(trim("raz")); Out.str("]\n");
156+ Out.char('['); Out.str(trim(" ")); Out.str("]\n");
157+end;
158+
159+end Trim.
123160 ```
124161
125162 A procedure may have up to 64 labels. The check against the raz version is the habit worth keeping: write the procedure in raz first, then in assembly, and compare their results on awkward inputs.

site/content/home.html (history) modified +19 -20

@@ -15,15 +15,15 @@
1515 system calls and call C libraries. It has no garbage collector and no hidden
1616 run time: what the program does is what its text says.</p>
1717
18-<p>The compiler is one Free Pascal program of about 7,800 lines. It makes
18+<p>The compiler is one Free Pascal program of about 9,100 lines. It makes
1919 x86-64 machine code and the ELF file itself, with no assembler or linker, in
20-one pass, at about a million lines a second.</p>
20+one pass, at about 900,000 lines a second.</p>
2121
2222 <div class="facts">
23- <span><b>~7,800</b> lines of compiler</span>
24- <span><b>~1M</b> lines compiled a second</span>
23+ <span><b>~9,100</b> lines of compiler</span>
24+ <span><b>~900K</b> lines compiled a second</span>
2525 <span><b>static</b> executables, no run time to install</span>
26- <span><b>1</b> report, <b>~2,000</b> lines</span>
26+ <span><b>1</b> report, <b>~2,100</b> lines</span>
2727 </div>
2828
2929 <div class="cols">
@@ -45,7 +45,7 @@
4545 <li>Modules with bodies, and generic modules: <code>Map(K, V; hash, eq)</code>.</li>
4646 <li><code>^VOLATILE T</code> and the atomics <code>CAS</code>, <code>XCHG</code>, <code>XADD</code>, <code>FENCE</code>, for devices and lock-free code.</li>
4747 <li><code>extern</code> procedures and variables from C, code procedures in assembly, and <code>SYSCALL</code>.</li>
48- <li>Threads without C, a library of <code>Out</code>, <code>Str</code>, <code>Fmt</code>, <code>Map</code>, <code>Sort</code> and more, and gdb that knows your lines.</li>
48+ <li>Threads without C, a library of <code>Out</code>, <code>Str</code>, <code>Bytes</code>, <code>Fmt</code>, <code>Map</code>, <code>Sort</code> and more, and gdb that knows your lines.</li>
4949 <li>A formatter, a documentation tool, and editor support for vim and emacs.</li>
5050 </ul>
5151 </div>
@@ -60,21 +60,20 @@
6060
6161 <h2>The language, in writing</h2>
6262 <p>The language is defined by <a href="spec.html">the report</a>, which is
63-short on purpose: whatever it doesn&rsquo;t allow, raz doesn&rsquo;t have. There
64-is also a <a href="https://github.com/ldiaz94/raz/blob/main/doc/compiler.md">guide to reading the
65-compiler</a>, file by file.</p>
63+short on purpose: whatever it doesn&rsquo;t allow, raz doesn&rsquo;t have.</p>
6664
6765 <h2 id="download">Download</h2>
68-<p>Each release is a tarball with the compiler, <code>raz</code>, and its
69-library, <code>lib/</code>, which it finds beside itself.</p>
66+<p>raz @VERSION@ is a tarball for x86-64 Linux with the compiler, <code>raz</code>,
67+its library, <code>lib/</code>, which it finds beside itself, and the manual
68+pages. It needs nothing else installed.</p>
7069 <div class="cta">
71- <a class="btn primary" href="https://github.com/ldiaz94/raz/releases/latest">Latest release</a>
72- <a class="btn" href="https://github.com/ldiaz94/raz">Source on GitHub</a>
70+ <a class="btn primary" href="download/@TARBALL@">Download raz @VERSION@</a>
71+ <a class="btn" href="download/@TARBALL@.sha256">SHA-256</a>
7372 </div>
74-<pre class="code"><code>$ tar xzf raz-*.tar.gz
75-$ ./raz run examples/Hello.raz
76-hello, world</code></pre>
77-<p>To build it yourself you need Free Pascal 3.2.2:</p>
78-<pre class="code"><code>$ apt-get install fp-compiler
79-$ git clone https://github.com/ldiaz94/raz
80-$ cd raz &amp;&amp; make &amp;&amp; make install # ~/.local, or PREFIX=/usr/local</code></pre>
73+<pre class="code"><code>$ tar xzf @TARBALL@
74+$ ln -s $PWD/@DIR@/raz ~/.local/bin/raz
75+$ raz run Hello.raz</code></pre>
76+<p>The link works since raz finds <code>lib/</code> beside its real path. The
77+manual pages are in <code>man/</code>: <code>man ./man/raz-tutorial.7</code>.
78+The address <code>download/latest</code> always leads to the newest release.</p>
79+<p class="sha">SHA-256 <code>@SHA256@</code></p>

site/content/tour/04-values.txt (history) modified +2 -0

@@ -90,6 +90,8 @@
9090 Fmt.print("22/7 = {}\n", [Fmt.real(x, 6)]);
9191 Fmt.print("as F32 = {}\n", [Fmt.real(F64(y), 6)]);
9292 Fmt.print("sqrt 2 = {}, pi = {}\n", [Fmt.real(Math.sqrt(2.0), 5), Fmt.real(Math.pi, 5)]);
93+ Fmt.print("2^10 = {}, log2 of that = {}\n", [Fmt.real(Math.pow(2.0, 10.0), 1), Fmt.real(Math.log2(1024.0), 1)]);
94+ Fmt.print("rounded: {} {}\n", [Fmt.real(Math.round(2.5), 1), Fmt.real(Math.round(-2.5), 1)]);
9395 Fmt.print("truncated: {} {}\n", [Fmt.int(I64(2.9)), Fmt.int(I64(-2.9))]);
9496 end;
9597

site/content/tour/07-records.txt (history) modified +31 -0

@@ -41,6 +41,37 @@
4141 end Points.
4242 ```
4343
44+## Tables of constants
45+
46+A constant may be a record, or an array of them: a table the program reads but can't change. Its fields are integers, reals, `BOOL`s, strings, procedures and the like, and arrays and records of these.
47+
48+```raz Planets run
49+module Planets;
50+import Fmt;
51+
52+type Planet = record name: []U8; moons: INT; water: BOOL; end;
53+
54+const Inner: [4]Planet = [
55+ {name: "Mercury"},
56+ {name: "Venus"},
57+ {name: "Earth", moons: 1, water: true},
58+ {name: "Mars", moons: 2}];
59+
60+proc main*;
61+var i, total: INT;
62+begin
63+ for i := 0 to LEN(Inner) - 1 do
64+ total := total + Inner[i].moons;
65+ if Inner[i].moons = 0 then Fmt.print("{} has no moon\n", [Fmt.str(Inner[i].name)]); end;
66+ end;
67+ Fmt.print("{} moons in all\n", [Fmt.int(total)]);
68+end;
69+
70+end Planets.
71+```
72+
73+Fields left out are zero, as in any literal: Mercury's `moons` is 0 and its `water` is `false`.
74+
4475 ## Layout
4576
4677 A record's layout is C's: each field at the next multiple of its own alignment, and the whole padded to a multiple of its largest alignment. `SIZE(T)` says how many bytes. A `packed record` has no padding, which is what a file format or a wire protocol wants.

site/public/_redirects (history) added +1 -0

@@ -0,0 +1 @@
1+/download/latest /download/raz-0.9.0-linux-x86_64.tar.gz 302

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

@@ -16,7 +16,7 @@
1616 <link rel="stylesheet" href="../style.css">
1717 </head>
1818 <body>
19-<header><nav><a class="mark" href="../index.html"><img src="../logo.svg" width="26" height="26" alt="">raz</a><a href="../tour/index.html">Raz, Set, Go</a><a href="../advanced/index.html" aria-current="page">More Raz</a><a href="../spec.html">Report</a><a href="../index.html#download">Download</a><a class="repo" href="https://github.com/ldiaz94/raz">GitHub</a></nav></header>
19+<header><nav><a class="mark" href="../index.html"><img src="../logo.svg" width="26" height="26" alt="">raz</a><a href="../tour/index.html">Raz, Set, Go</a><a href="../advanced/index.html" aria-current="page">More Raz</a><a href="../spec.html">Report</a><a href="../index.html#download">Download</a></nav></header>
2020 <main>
2121 <div class="tour"><aside><h2>More Raz</h2><h3>The library</h3><ol start='1'>
2222 <li><a href="fmt.html">Output and formatting</a></li>
@@ -197,6 +197,6 @@
197197 <h2>What to take from this</h2>
198198 <ul><li>An allocator is a value, so it is passed, wrapped, swapped in a test and replaced by a bump allocator in a program with no heap.</li><li>A library function that needs memory takes the allocator as a parameter, so its caller owns the policy.</li><li>An allocator can use the record-first trick to carry any state it needs, because converting a pointer to a record's first field and back is the same address.</li></ul><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="processes.html">&larr; Time, randomness and other programs</a><a href="index.html">Contents</a><a class="next" href="static.html">A program with no run time &rarr;</a></div></article></div>
199199 </main>
200-<footer>raz is under the ISC license. <a href="https://github.com/ldiaz94/raz">Source</a>.</footer>
200+<footer>raz is under the ISC license.</footer>
201201 </body>
202202 </html>

site/public/advanced/asm.html (history) modified +47 -12

@@ -16,7 +16,7 @@
1616 <link rel="stylesheet" href="../style.css">
1717 </head>
1818 <body>
19-<header><nav><a class="mark" href="../index.html"><img src="../logo.svg" width="26" height="26" alt="">raz</a><a href="../tour/index.html">Raz, Set, Go</a><a href="../advanced/index.html" aria-current="page">More Raz</a><a href="../spec.html">Report</a><a href="../index.html#download">Download</a><a class="repo" href="https://github.com/ldiaz94/raz">GitHub</a></nav></header>
19+<header><nav><a class="mark" href="../index.html"><img src="../logo.svg" width="26" height="26" alt="">raz</a><a href="../tour/index.html">Raz, Set, Go</a><a href="../advanced/index.html" aria-current="page">More Raz</a><a href="../spec.html">Report</a><a href="../index.html#download">Download</a></nav></header>
2020 <main>
2121 <div class="tour"><aside><h2>More Raz</h2><h3>The library</h3><ol start='1'>
2222 <li><a href="fmt.html">Output and formatting</a></li>
@@ -73,7 +73,7 @@
7373 <p>A code procedure is called like any procedure. Everything in it is yours, <code>ret</code> included.</p>
7474 <h2>The convention</h2>
7575 <p>A code procedure follows the System V convention, as every raz procedure does:</p>
76-<ul><li>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>.</li><li>The result goes in <code>rax</code> (and <code>rdx</code> for a second) or <code>xmm0</code>.</li><li>It must keep <code>rbx</code>, <code>rbp</code>, <code>rsp</code> and <code>r12</code> to <code>r15</code> as it found them. <code>rax</code>, <code>rcx</code>, <code>rdx</code>, <code>rsi</code>, <code>rdi</code> and <code>r8</code> to <code>r11</code> are free to change.</li><li>Its parameters and results are therefore of the types C can take, at most six integer and eight real parameters and two results.</li></ul>
76+<ul><li>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>.</li><li>The result goes in <code>rax</code> (and <code>rdx</code> for a second) or <code>xmm0</code>.</li><li>It must keep <code>rbx</code>, <code>rbp</code>, <code>rsp</code> and <code>r12</code> to <code>r15</code> as it found them. <code>rax</code>, <code>rcx</code>, <code>rdx</code>, <code>rsi</code>, <code>rdi</code> and <code>r8</code> to <code>r11</code> are free to change.</li><li>A slice is two integers, its address and its length, as System V passes a struct of two. As a parameter it takes two registers in a row; as the result its address goes in <code>rax</code> and its length in <code>rdx</code>.</li><li>Its parameters and results are therefore of the types C can take, or slices: at most six integer and eight real parameters, and two results, a slice being the only one.</li></ul>
7777 <p>That is why the next one is so short: the argument is already in <code>rdi</code>.</p>
7878 <div class="file"><span>Bits.raz</span></div><pre class="code"><code><span class="kw">module</span> Bits;
7979 <span class="kw">import</span> Out;
@@ -87,10 +87,10 @@
8787 ret;
8888 <span class="kw">end</span> swap64;
8989
90-<span class="comment">(* the number of bits set in x: popcnt rax, rdi *)</span>
90+<span class="comment">(* the number of bits set in x *)</span>
9191 <span class="kw">proc</span> ones(x: <span class="ty">U64</span>): <span class="ty">INT</span>;
9292 <span class="kw">code</span>
93- db <span class="number">0F3H</span>, <span class="number">48H</span>, <span class="number">0FH</span>, <span class="number">0B8H</span>, <span class="number">0C7H</span>;
93+ popcnt rax, rdi;
9494 ret;
9595 <span class="kw">end</span> ones;
9696
@@ -106,14 +106,14 @@
106106 <pre class="output"><code>0x0807060504030201
107107 8 0 64
108108 </code></pre>
109-<p><code>db</code> writes any bytes, for an instruction the assembler doesn't know. Which instructions it knows is the implementation's business; <code>db</code> keeps you from waiting for it to learn one. (The two instructions above are from the processor manuals: <code>bswap r64</code> is <code>REX.W 0F C8+r</code>, <code>popcnt r64, r/m64</code> is <code>F3 REX.W 0F B8 /r</code>.)</p>
109+<p><code>db</code> writes any bytes, for an instruction the assembler doesn't know. Which instructions it knows is the implementation's business: this one knows <code>popcnt</code> but not <code>bswap</code>, and <code>db</code> keeps you from waiting for it to learn one. (<code>bswap r64</code> is <code>REX.W 0F C8+r</code> in the processor manuals.)</p>
110110 <h2>Labels and loops</h2>
111-<p>A label, <code>name:</code>, names the place of the instruction after it, within the procedure. Jumps go to labels, and a constant of the module may stand wherever a number does. This sums an array of <code>INT</code>s, which a pointer and a length describe:</p>
111+<p>A label, <code>name:</code>, names the place of the instruction after it, within the procedure. Jumps go to labels, and a constant of the module may stand wherever a number does. This sums a slice of <code>INT</code>s, whose address arrives in <code>rdi</code> and its length in <code>rsi</code>:</p>
112112 <div class="file"><span>Sum.raz</span></div><pre class="code"><code><span class="kw">module</span> Sum;
113113 <span class="kw">import</span> Out;
114114
115-<span class="comment">(* the sum of the n INTs at p *)</span>
116-<span class="kw">proc</span> sum(p: ^<span class="ty">INT</span>; n: <span class="ty">INT</span>): <span class="ty">INT</span>;
115+<span class="comment">(* the sum of the INTs of a *)</span>
116+<span class="kw">proc</span> sum(a: []<span class="ty">INT</span>): <span class="ty">INT</span>;
117117 <span class="kw">code</span>
118118 <span class="kw">xor</span> eax, eax;
119119 test rsi, rsi;
@@ -139,13 +139,48 @@
139139 <span class="kw">var</span> a: [<span class="number">6</span>]<span class="ty">INT</span>; i: <span class="ty">INT</span>;
140140 <span class="kw">begin</span>
141141 <span class="kw">for</span> i := <span class="number">0</span> <span class="kw">to</span> <span class="number">5</span> <span class="kw">do</span> a[i] := (i + <span class="number">1</span>) * <span class="number">100</span>; <span class="kw">end</span>;
142- Out.int(sum(<span class="ty">ADR</span>(a[<span class="number">0</span>]), <span class="number">6</span>)); Out.char(<span class="string">&#x27; &#x27;</span>);
142+ Out.int(sum(a)); Out.char(<span class="string">&#x27; &#x27;</span>);
143143 Out.int(sumRaz(a)); Out.char(<span class="string">&#x27; &#x27;</span>);
144- Out.int(sum(<span class="ty">ADR</span>(a[<span class="number">0</span>]), <span class="number">0</span>)); Out.ln;
144+ Out.int(sum(a[<span class="number">2</span>..<span class="number">4</span>])); Out.char(<span class="string">&#x27; &#x27;</span>);
145+ Out.int(sum(a[<span class="number">0</span>..<span class="number">0</span>])); Out.ln;
145146 <span class="kw">end</span>;
146147
147148 <span class="kw">end</span> Sum.</code></pre>
148-<pre class="output"><code>2100 2100 0
149+<pre class="output"><code>2100 2100 700 0
150+</code></pre>
151+<p>The procedure trusts the length it is given, as it must: the checks of the language end where its code begins.</p>
152+<p>A slice comes back the same way, its address in <code>rax</code> and its length in <code>rdx</code>. This one returns what is left of a string past its leading blanks:</p>
153+<div class="file"><span>Trim.raz</span></div><pre class="code"><code><span class="kw">module</span> Trim;
154+<span class="kw">import</span> Out;
155+
156+<span class="comment">(* s past its leading blanks *)</span>
157+<span class="kw">proc</span> trim(s: []<span class="ty">U8</span>): []<span class="ty">U8</span>;
158+<span class="kw">code</span>
159+ mov rax, rdi;
160+ mov rdx, rsi;
161+again:
162+ test rdx, rdx;
163+ jz done;
164+ cmp byte [rax], <span class="number">32</span>;
165+ jne done;
166+ inc rax;
167+ dec rdx;
168+ jmp again;
169+done:
170+ ret;
171+<span class="kw">end</span> trim;
172+
173+<span class="kw">proc</span> main*;
174+<span class="kw">begin</span>
175+ Out.char(<span class="string">&#x27;[&#x27;</span>); Out.str(trim(<span class="string">&quot; raz&quot;</span>)); Out.str(<span class="string">&quot;]\n&quot;</span>);
176+ Out.char(<span class="string">&#x27;[&#x27;</span>); Out.str(trim(<span class="string">&quot;raz&quot;</span>)); Out.str(<span class="string">&quot;]\n&quot;</span>);
177+ Out.char(<span class="string">&#x27;[&#x27;</span>); Out.str(trim(<span class="string">&quot; &quot;</span>)); Out.str(<span class="string">&quot;]\n&quot;</span>);
178+<span class="kw">end</span>;
179+
180+<span class="kw">end</span> Trim.</code></pre>
181+<pre class="output"><code>[raz]
182+[raz]
183+[]
149184 </code></pre>
150185 <p>A procedure may have up to 64 labels. The check against the raz version is the habit worth keeping: write the procedure in raz first, then in assembly, and compare their results on awkward inputs.</p>
151186 <h2>Two results, and reals</h2>
@@ -219,6 +254,6 @@
219254 <h2>What goes wrong</h2>
220255 <p>A code procedure that breaks its rules breaks the program, and what follows isn't defined. Writing through a wrong pointer, a changed <code>rbx</code>, a missing <code>ret</code>, a stack left unbalanced: the language can't help, because it doesn't see inside. Keep them short, give each a comment that says what it expects in which register, test each against a raz twin, and use them for what only the machine can do.</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="targets.html">&larr; One module, one file per target</a><a href="index.html">Contents</a><a class="next" href="syscalls.html">System calls &rarr;</a></div></article></div>
221256 </main>
222-<footer>raz is under the ISC license. <a href="https://github.com/ldiaz94/raz">Source</a>.</footer>
257+<footer>raz is under the ISC license.</footer>
223258 </body>
224259 </html>

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

@@ -16,7 +16,7 @@
1616 <link rel="stylesheet" href="../style.css">
1717 </head>
1818 <body>
19-<header><nav><a class="mark" href="../index.html"><img src="../logo.svg" width="26" height="26" alt="">raz</a><a href="../tour/index.html">Raz, Set, Go</a><a href="../advanced/index.html" aria-current="page">More Raz</a><a href="../spec.html">Report</a><a href="../index.html#download">Download</a><a class="repo" href="https://github.com/ldiaz94/raz">GitHub</a></nav></header>
19+<header><nav><a class="mark" href="../index.html"><img src="../logo.svg" width="26" height="26" alt="">raz</a><a href="../tour/index.html">Raz, Set, Go</a><a href="../advanced/index.html" aria-current="page">More Raz</a><a href="../spec.html">Report</a><a href="../index.html#download">Download</a></nav></header>
2020 <main>
2121 <div class="tour"><aside><h2>More Raz</h2><h3>The library</h3><ol start='1'>
2222 <li><a href="fmt.html">Output and formatting</a></li>
@@ -199,6 +199,6 @@
199199 <ul><li>A counter, a ticket, a flag: <code>XADD</code> or <code>XCHG</code>.</li><li>A value computed from the old one: a <code>CAS</code> loop.</li><li>Several variables that must change together: a <code>Lock</code> or a <code>Mutex</code>. Don't try to be clever with several atomics; the one invariant spanning them is the thing that breaks.</li></ul>
200200 <p>All three act on a word. For anything bigger, the thing you swap is a pointer to the bigger thing: the next lessons do exactly that.</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="volatile.html">&larr; Volatile</a><a href="index.html">Contents</a><a class="next" href="ordering.html">Ordering and publication &rarr;</a></div></article></div>
201201 </main>
202-<footer>raz is under the ISC license. <a href="https://github.com/ldiaz94/raz">Source</a>.</footer>
202+<footer>raz is under the ISC license.</footer>
203203 </body>
204204 </html>

site/public/advanced/bytes.html (history) modified +40 -3

@@ -16,7 +16,7 @@
1616 <link rel="stylesheet" href="../style.css">
1717 </head>
1818 <body>
19-<header><nav><a class="mark" href="../index.html"><img src="../logo.svg" width="26" height="26" alt="">raz</a><a href="../tour/index.html">Raz, Set, Go</a><a href="../advanced/index.html" aria-current="page">More Raz</a><a href="../spec.html">Report</a><a href="../index.html#download">Download</a><a class="repo" href="https://github.com/ldiaz94/raz">GitHub</a></nav></header>
19+<header><nav><a class="mark" href="../index.html"><img src="../logo.svg" width="26" height="26" alt="">raz</a><a href="../tour/index.html">Raz, Set, Go</a><a href="../advanced/index.html" aria-current="page">More Raz</a><a href="../spec.html">Report</a><a href="../index.html#download">Download</a></nav></header>
2020 <main>
2121 <div class="tour"><aside><h2>More Raz</h2><h3>The library</h3><ol start='1'>
2222 <li><a href="fmt.html">Output and formatting</a></li>
@@ -44,7 +44,7 @@
4444 <li><a href="lockfree.html">A lock-free stack</a></li>
4545 <li><a href="ring.html">A ring buffer between threads</a></li>
4646 </ol></aside><article><p class="kicker">The library &middot; lesson 2 of 18</p><h1>Strings and bytes</h1>
47-<p>A <code>[]U8</code> is both a string and a block of bytes. <code>Str</code> has what is done with them: comparing, finding, hashing, copying into memory of your own, UTF-8, numbers, and the fixed byte orders of file formats and network protocols.</p>
47+<p>A <code>[]U8</code> is both a string and a block of bytes. <code>Str</code> has what is done with them: comparing, finding, hashing, copying into memory of your own, UTF-8, numbers, and the fixed byte orders of file formats and network protocols. <code>Bytes</code> has the searches, made fast.</p>
4848 <h2>Ordering and hashing</h2>
4949 <p><code>Str.cmp</code> gives -1, 0 or 1, byte by byte, so it orders UTF-8 text by code point. <code>Str.eq</code> is equality. <code>Str.hash</code> is FNV-1a, 64 bits; it is what a <code>Map</code> of strings uses.</p>
5050 <div class="file"><span>Order.raz</span></div><pre class="code"><code><span class="kw">module</span> Order;
@@ -112,6 +112,43 @@
112112 <span class="kw">end</span> Keep.</code></pre>
113113 <pre class="output"><code>name-0 name-1 name-2
114114 </code></pre>
115+<h2>Searching</h2>
116+<p><code>Bytes</code> finds bytes many at a time: <code>Bytes.index</code> and <code>Bytes.last</code> give the first and the last place of a byte in a <code>[]U8</code>, or -1, <code>Bytes.count</code> how many places it has, and <code>Bytes.find</code> where one <code>[]U8</code> first starts in another (<code>Str.find</code> is the same). Each is what a loop over the bytes would give, only faster: the library's own body compares eight bytes at once in a <code>U64</code>, and on x86-64 a file of its own, <code>Bytes.x86_64.raz</code>, compares sixteen with SSE2, in code procedures.</p>
117+<div class="file"><span>Paths.raz</span></div><pre class="code"><code><span class="kw">module</span> Paths;
118+<span class="kw">import</span> Out, Fmt, Bytes;
119+
120+<span class="comment">(* the last part of a path: what follows its last slash *)</span>
121+<span class="kw">proc</span> base(path: []<span class="ty">U8</span>): []<span class="ty">U8</span>;
122+<span class="kw">begin</span>
123+ <span class="kw">return</span> path[Bytes.last(path, <span class="string">&#x27;/&#x27;</span>) + <span class="number">1</span>..<span class="ty">LEN</span>(path)];
124+<span class="kw">end</span>;
125+
126+<span class="kw">proc</span> main*;
127+<span class="kw">var</span> text: []<span class="ty">U8</span>; at, n, line: <span class="ty">INT</span>;
128+<span class="kw">begin</span>
129+ Out.str(base(<span class="string">&quot;/usr/local/lib/raz/Bytes.raz&quot;</span>)); Out.char(<span class="string">&#x27; &#x27;</span>);
130+ Out.str(base(<span class="string">&quot;Out.raz&quot;</span>)); Out.ln;
131+
132+ text := <span class="string">&quot;one line\nanother line\nthe line with raz in it\nthe last\n&quot;</span>;
133+ Fmt.print(<span class="string">&quot;{} lines\n&quot;</span>, [Fmt.int(Bytes.count(text, <span class="number">10</span>))]);
134+ at := Bytes.find(text, <span class="string">&quot;raz&quot;</span>);
135+ <span class="kw">if</span> at &gt;= <span class="number">0</span> <span class="kw">then</span>
136+ <span class="comment">(* the line it is on: the newlines before it, plus one *)</span>
137+ line := Bytes.count(text[<span class="number">0</span>..at], <span class="number">10</span>) + <span class="number">1</span>;
138+ n := Bytes.index(text[at..<span class="ty">LEN</span>(text)], <span class="number">10</span>);
139+ Fmt.print(<span class="string">&quot;raz on line {}, at {}, and the line goes on {} more\n&quot;</span>,
140+ [Fmt.int(line), Fmt.int(at), Fmt.int(n)]);
141+ <span class="kw">end</span>;
142+ Fmt.print(<span class="string">&quot;{} {}\n&quot;</span>, [Fmt.int(Bytes.find(text, <span class="string">&quot;zzz&quot;</span>)), Fmt.int(Bytes.find(text, <span class="string">&quot;&quot;</span>))]);
143+<span class="kw">end</span>;
144+
145+<span class="kw">end</span> Paths.</code></pre>
146+<pre class="output"><code>Bytes.raz Out.raz
147+4 lines
148+raz on line 3, at 36, and the line goes on 9 more
149+-1 0
150+</code></pre>
151+<p>When the byte isn't there, <code>Bytes.last</code> gives -1, so <code>base</code> of a name with no slash is the whole name. A search of a slice gives places in the slice, counted from its own start: add the place the slice starts at to get one in the whole.</p>
115152 <h2>Binary formats</h2>
116153 <p>A file format or a network protocol has a byte order of its own, not the machine's. <code>Str.le</code> and <code>Str.be</code> read an unsigned number of up to 8 bytes in a fixed order (little- or big-endian) and <code>Str.putLE</code> and <code>Str.putBE</code> write one. They work on any slice, so a header is read where it lies, with no struct to overlay and no byte swapping to forget.</p>
117154 <p>Here is a small record format: a 4-byte tag, a 2-byte big-endian length, a 4-byte little-endian checksum, then the data.</p>
@@ -197,6 +234,6 @@
197234 -1
198235 </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="fmt.html">&larr; Output and formatting</a><a href="index.html">Contents</a><a class="next" href="collections.html">Lists, maps and sorting &rarr;</a></div></article></div>
199236 </main>
200-<footer>raz is under the ISC license. <a href="https://github.com/ldiaz94/raz">Source</a>.</footer>
237+<footer>raz is under the ISC license.</footer>
201238 </body>
202239 </html>

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

@@ -16,7 +16,7 @@
1616 <link rel="stylesheet" href="../style.css">
1717 </head>
1818 <body>
19-<header><nav><a class="mark" href="../index.html"><img src="../logo.svg" width="26" height="26" alt="">raz</a><a href="../tour/index.html">Raz, Set, Go</a><a href="../advanced/index.html" aria-current="page">More Raz</a><a href="../spec.html">Report</a><a href="../index.html#download">Download</a><a class="repo" href="https://github.com/ldiaz94/raz">GitHub</a></nav></header>
19+<header><nav><a class="mark" href="../index.html"><img src="../logo.svg" width="26" height="26" alt="">raz</a><a href="../tour/index.html">Raz, Set, Go</a><a href="../advanced/index.html" aria-current="page">More Raz</a><a href="../spec.html">Report</a><a href="../index.html#download">Download</a></nav></header>
2020 <main>
2121 <div class="tour"><aside><h2>More Raz</h2><h3>The library</h3><ol start='1'>
2222 <li><a href="fmt.html">Output and formatting</a></li>
@@ -166,6 +166,6 @@
166166 <h2>Choosing</h2>
167167 <p>Use a <code>List</code> when you push and pop at one end and walk it in order. Use a <code>Map</code> when you look things up by key. Use an array and <code>Sort</code> when you know the size and want an order. When none of them fits, they are each under a hundred lines of raz in <code>lib/</code>, and the advanced tour's allocator lesson shows what is underneath.</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="bytes.html">&larr; Strings and bytes</a><a href="index.html">Contents</a><a class="next" href="files.html">Files and the command line &rarr;</a></div></article></div>
168168 </main>
169-<footer>raz is under the ISC license. <a href="https://github.com/ldiaz94/raz">Source</a>.</footer>
169+<footer>raz is under the ISC license.</footer>
170170 </body>
171171 </html>

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

@@ -16,7 +16,7 @@
1616 <link rel="stylesheet" href="../style.css">
1717 </head>
1818 <body>
19-<header><nav><a class="mark" href="../index.html"><img src="../logo.svg" width="26" height="26" alt="">raz</a><a href="../tour/index.html">Raz, Set, Go</a><a href="../advanced/index.html" aria-current="page">More Raz</a><a href="../spec.html">Report</a><a href="../index.html#download">Download</a><a class="repo" href="https://github.com/ldiaz94/raz">GitHub</a></nav></header>
19+<header><nav><a class="mark" href="../index.html"><img src="../logo.svg" width="26" height="26" alt="">raz</a><a href="../tour/index.html">Raz, Set, Go</a><a href="../advanced/index.html" aria-current="page">More Raz</a><a href="../spec.html">Report</a><a href="../index.html#download">Download</a></nav></header>
2020 <main>
2121 <div class="tour"><aside><h2>More Raz</h2><h3>The library</h3><ol start='1'>
2222 <li><a href="fmt.html">Output and formatting</a></li>
@@ -231,6 +231,6 @@
231231 <p><code>-h</code> and <code>--help</code> are <code>Opt</code>'s: the program never sees them. A mistake on the command line is a sentence on standard error with the program's name first, then the synopsis, and status 2. Nothing in <code>Tool</code> wrote any of that.</p>
232232 <p>A mistake in the table itself, such as an option given twice, is the program's, and <code>init</code> says so and ends with status 1 before it reads a word.</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="collections.html">&larr; Lists, maps and sorting</a><a href="index.html">Contents</a><a class="next" href="processes.html">Time, randomness and other programs &rarr;</a></div></article></div>
233233 </main>
234-<footer>raz is under the ISC license. <a href="https://github.com/ldiaz94/raz">Source</a>.</footer>
234+<footer>raz is under the ISC license.</footer>
235235 </body>
236236 </html>

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

@@ -16,7 +16,7 @@
1616 <link rel="stylesheet" href="../style.css">
1717 </head>
1818 <body>
19-<header><nav><a class="mark" href="../index.html"><img src="../logo.svg" width="26" height="26" alt="">raz</a><a href="../tour/index.html">Raz, Set, Go</a><a href="../advanced/index.html" aria-current="page">More Raz</a><a href="../spec.html">Report</a><a href="../index.html#download">Download</a><a class="repo" href="https://github.com/ldiaz94/raz">GitHub</a></nav></header>
19+<header><nav><a class="mark" href="../index.html"><img src="../logo.svg" width="26" height="26" alt="">raz</a><a href="../tour/index.html">Raz, Set, Go</a><a href="../advanced/index.html" aria-current="page">More Raz</a><a href="../spec.html">Report</a><a href="../index.html#download">Download</a></nav></header>
2020 <main>
2121 <div class="tour"><aside><h2>More Raz</h2><h3>The library</h3><ol start='1'>
2222 <li><a href="fmt.html" aria-current="page">Output and formatting</a></li>
@@ -193,6 +193,6 @@
193193 CE BB
194194 </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="index.html">Contents</a><a class="next" href="bytes.html">Strings and bytes &rarr;</a></div></article></div>
195195 </main>
196-<footer>raz is under the ISC license. <a href="https://github.com/ldiaz94/raz">Source</a>.</footer>
196+<footer>raz is under the ISC license.</footer>
197197 </body>
198198 </html>

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

@@ -16,7 +16,7 @@
1616 <link rel="stylesheet" href="../style.css">
1717 </head>
1818 <body>
19-<header><nav><a class="mark" href="../index.html"><img src="../logo.svg" width="26" height="26" alt="">raz</a><a href="../tour/index.html">Raz, Set, Go</a><a href="../advanced/index.html" aria-current="page">More Raz</a><a href="../spec.html">Report</a><a href="../index.html#download">Download</a><a class="repo" href="https://github.com/ldiaz94/raz">GitHub</a></nav></header>
19+<header><nav><a class="mark" href="../index.html"><img src="../logo.svg" width="26" height="26" alt="">raz</a><a href="../tour/index.html">Raz, Set, Go</a><a href="../advanced/index.html" aria-current="page">More Raz</a><a href="../spec.html">Report</a><a href="../index.html#download">Download</a></nav></header>
2020 <main>
2121 <div class="contents"><h1>More Raz</h1>
2222 <p>The second tour, for the part of raz that sits close to the machine. It
@@ -30,7 +30,7 @@
3030 made, as before.</p>
3131 <h2>The library</h2><ol start='1'>
3232 <li><a href="fmt.html">Output and formatting</a> <span>Out&#x27;s buffer, Fmt&#x27;s arguments, formatting into a Buf, and laying out columns.</span></li>
33-<li><a href="bytes.html">Strings and bytes</a> <span>Copying, hashing and ordering strings, and reading and writing binary formats.</span></li>
33+<li><a href="bytes.html">Strings and bytes</a> <span>Copying, hashing and ordering strings, searching bytes many at a time, and reading and writing binary formats.</span></li>
3434 <li><a href="collections.html">Lists, maps and sorting</a> <span>List(T), Map(K, V) and Sort(T), put together in a word-frequency program.</span></li>
3535 <li><a href="files.html">Files and the command line</a> <span>Whole files with Files, descriptors and directories with Sys, and options with Opt.</span></li>
3636 <li><a href="processes.html">Time, randomness and other programs</a> <span>Clocks, sleeping, random bytes, and running a program with its output piped back.</span></li>
@@ -55,6 +55,6 @@
5555 <li><a href="ring.html">A ring buffer between threads</a> <span>A single-producer, single-consumer queue, put together from what the tour has covered.</span></li>
5656 </ol></div>
5757 </main>
58-<footer>raz is under the ISC license. <a href="https://github.com/ldiaz94/raz">Source</a>.</footer>
58+<footer>raz is under the ISC license.</footer>
5959 </body>
6060 </html>

site/public/advanced/lifecycle.html (history) modified +2 -2

@@ -16,7 +16,7 @@
1616 <link rel="stylesheet" href="../style.css">
1717 </head>
1818 <body>
19-<header><nav><a class="mark" href="../index.html"><img src="../logo.svg" width="26" height="26" alt="">raz</a><a href="../tour/index.html">Raz, Set, Go</a><a href="../advanced/index.html" aria-current="page">More Raz</a><a href="../spec.html">Report</a><a href="../index.html#download">Download</a><a class="repo" href="https://github.com/ldiaz94/raz">GitHub</a></nav></header>
19+<header><nav><a class="mark" href="../index.html"><img src="../logo.svg" width="26" height="26" alt="">raz</a><a href="../tour/index.html">Raz, Set, Go</a><a href="../advanced/index.html" aria-current="page">More Raz</a><a href="../spec.html">Report</a><a href="../index.html#download">Download</a></nav></header>
2020 <main>
2121 <div class="tour"><aside><h2>More Raz</h2><h3>The library</h3><ol start='1'>
2222 <li><a href="fmt.html">Output and formatting</a></li>
@@ -159,6 +159,6 @@
159159 </code></pre>
160160 <p><code>Sys.ready(fd, ms)</code> waits up to <code>ms</code> milliseconds for something to read; with <code>Sys.readyOf</code> it waits on several descriptors, so one loop serves a socket, a terminal and a stop signal together. <code>Sys.ignore(sig, true)</code> makes a signal do nothing, as a shell ignores <code>SIGTTOU</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="linkstatic.html">&larr; Threads without C, and keeping the two apart</a><a href="index.html">Contents</a><a class="next" href="targets.html">One module, one file per target &rarr;</a></div></article></div>
161161 </main>
162-<footer>raz is under the ISC license. <a href="https://github.com/ldiaz94/raz">Source</a>.</footer>
162+<footer>raz is under the ISC license.</footer>
163163 </body>
164164 </html>

site/public/advanced/linkstatic.html (history) modified +2 -2

@@ -16,7 +16,7 @@
1616 <link rel="stylesheet" href="../style.css">
1717 </head>
1818 <body>
19-<header><nav><a class="mark" href="../index.html"><img src="../logo.svg" width="26" height="26" alt="">raz</a><a href="../tour/index.html">Raz, Set, Go</a><a href="../advanced/index.html" aria-current="page">More Raz</a><a href="../spec.html">Report</a><a href="../index.html#download">Download</a><a class="repo" href="https://github.com/ldiaz94/raz">GitHub</a></nav></header>
19+<header><nav><a class="mark" href="../index.html"><img src="../logo.svg" width="26" height="26" alt="">raz</a><a href="../tour/index.html">Raz, Set, Go</a><a href="../advanced/index.html" aria-current="page">More Raz</a><a href="../spec.html">Report</a><a href="../index.html#download">Download</a></nav></header>
2020 <main>
2121 <div class="tour"><aside><h2>More Raz</h2><h3>The library</h3><ol start='1'>
2222 <li><a href="fmt.html">Output and formatting</a></li>
@@ -118,6 +118,6 @@
118118 <h2>The same promise for your own modules</h2>
119119 <p>The rule isn't special to <code>Thread</code>. A module of yours that makes <code>SYSCALL</code>s directly, or relies on being the only owner of signal handlers, or sets up its own stacks, says <code>link static;</code> too, and then the compiler keeps C away from it for you. The module is documenting a fact about itself, and the compiler checks it where the program is assembled.</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="static.html">&larr; A program with no run time</a><a href="index.html">Contents</a><a class="next" href="lifecycle.html">Starting, ending, and signals &rarr;</a></div></article></div>
120120 </main>
121-<footer>raz is under the ISC license. <a href="https://github.com/ldiaz94/raz">Source</a>.</footer>
121+<footer>raz is under the ISC license.</footer>
122122 </body>
123123 </html>

site/public/advanced/listing.html (history) modified +16 -16

@@ -16,7 +16,7 @@
1616 <link rel="stylesheet" href="../style.css">
1717 </head>
1818 <body>
19-<header><nav><a class="mark" href="../index.html"><img src="../logo.svg" width="26" height="26" alt="">raz</a><a href="../tour/index.html">Raz, Set, Go</a><a href="../advanced/index.html" aria-current="page">More Raz</a><a href="../spec.html">Report</a><a href="../index.html#download">Download</a><a class="repo" href="https://github.com/ldiaz94/raz">GitHub</a></nav></header>
19+<header><nav><a class="mark" href="../index.html"><img src="../logo.svg" width="26" height="26" alt="">raz</a><a href="../tour/index.html">Raz, Set, Go</a><a href="../advanced/index.html" aria-current="page">More Raz</a><a href="../spec.html">Report</a><a href="../index.html#download">Download</a></nav></header>
2020 <main>
2121 <div class="tour"><aside><h2>More Raz</h2><h3>The library</h3><ol start='1'>
2222 <li><a href="fmt.html">Output and formatting</a></li>
@@ -126,7 +126,7 @@
126126 7 for i := 0 to LEN(a) - 1 do
127127 32 xor ebx, ebx
128128 34 mov r8, rsi
129- 37 sub r8, 1
129+ 37 lea r8, [r8 - 1]
130130 41 mov [rbp - 56], r8
131131 45 cmp rbx, [rbp - 56]
132132 49 jg 146
@@ -206,7 +206,7 @@
206206 7 for i := 0 to LEN(a) - 1 do
207207 32 xor ebx, ebx
208208 34 mov r8, rsi
209- 37 sub r8, 1
209+ 37 lea r8, [r8 - 1]
210210 41 mov [rbp - 56], r8
211211 45 cmp rbx, [rbp - 56]
212212 49 jg 127
@@ -246,20 +246,20 @@
246246 <ul><li><code>gdb</code> finds procedures by name and lines by number, since the executable carries them: <code>break Dot.dot</code> and <code>list</code> work, and so does stepping a line at a time.</li><li><code>RAZ_PROFILE=1</code> samples the program every millisecond and says which procedures and lines took the time.</li><li><code>objdump -d</code> disassembles what is really in the file, if you want to see the bytes behind a listing.</li></ul>
247247 <pre class="output term"><code><span class="cmd">$ raz -o Dot Dot.raz</span>
248248 <span class="cmd">$ objdump -d -M intel --no-show-raw-insn Dot | sed -n &#x27;/&lt;Dot.dot&gt;:/,/ret/p&#x27; | head -12</span>
249-0000000000403b80 &lt;Dot.dot&gt;:
250- 403b80: push rbp
251- 403b81: mov rbp,rsp
252- 403b84: sub rsp,0x40
253- 403b8b: mov QWORD PTR [rbp-0x30],rbx
254- 403b8f: xor ebx,ebx
255- 403b91: mov QWORD PTR [rbp-0x28],r12
256- 403b95: xor r12d,r12d
257- 403b98: mov QWORD PTR [rbp-0x20],rdx
258- 403b9c: mov QWORD PTR [rbp-0x18],rcx
259- 403ba0: xor ebx,ebx
260- 403ba2: mov r8,rsi</code></pre>
249+0000000000403ac0 &lt;Dot.dot&gt;:
250+ 403ac0: push rbp
251+ 403ac1: mov rbp,rsp
252+ 403ac4: sub rsp,0x40
253+ 403acb: mov QWORD PTR [rbp-0x30],rbx
254+ 403acf: xor ebx,ebx
255+ 403ad1: mov QWORD PTR [rbp-0x28],r12
256+ 403ad5: xor r12d,r12d
257+ 403ad8: mov QWORD PTR [rbp-0x20],rdx
258+ 403adc: mov QWORD PTR [rbp-0x18],rcx
259+ 403ae0: xor ebx,ebx
260+ 403ae2: mov r8,rsi</code></pre>
261261 <p>The listing is what the encoder meant; <code>objdump</code> is what the processor will read. They tell the same story.</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="syscalls.html">&larr; System calls</a><a href="index.html">Contents</a><a class="next" href="volatile.html">Volatile &rarr;</a></div></article></div>
262262 </main>
263-<footer>raz is under the ISC license. <a href="https://github.com/ldiaz94/raz">Source</a>.</footer>
263+<footer>raz is under the ISC license.</footer>
264264 </body>
265265 </html>

site/public/advanced/lockfree.html (history) modified +2 -2

@@ -16,7 +16,7 @@
1616 <link rel="stylesheet" href="../style.css">
1717 </head>
1818 <body>
19-<header><nav><a class="mark" href="../index.html"><img src="../logo.svg" width="26" height="26" alt="">raz</a><a href="../tour/index.html">Raz, Set, Go</a><a href="../advanced/index.html" aria-current="page">More Raz</a><a href="../spec.html">Report</a><a href="../index.html#download">Download</a><a class="repo" href="https://github.com/ldiaz94/raz">GitHub</a></nav></header>
19+<header><nav><a class="mark" href="../index.html"><img src="../logo.svg" width="26" height="26" alt="">raz</a><a href="../tour/index.html">Raz, Set, Go</a><a href="../advanced/index.html" aria-current="page">More Raz</a><a href="../spec.html">Report</a><a href="../index.html#download">Download</a></nav></header>
2020 <main>
2121 <div class="tour"><aside><h2>More Raz</h2><h3>The library</h3><ol start='1'>
2222 <li><a href="fmt.html">Output and formatting</a></li>
@@ -162,6 +162,6 @@
162162 <h2>When to use it</h2>
163163 <p>A lock-free structure is worth it when a lock would be held by a thread that can be descheduled, when the critical section is a single pointer, or when a signal handler or an interrupt must share data with the code it interrupts. Everywhere else a <code>Mutex</code> is shorter, easier to check, and fast enough. The advantage of knowing how to write the other kind is that you understand what the lock is doing for you.</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="ordering.html">&larr; Ordering and publication</a><a href="index.html">Contents</a><a class="next" href="ring.html">A ring buffer between threads &rarr;</a></div></article></div>
164164 </main>
165-<footer>raz is under the ISC license. <a href="https://github.com/ldiaz94/raz">Source</a>.</footer>
165+<footer>raz is under the ISC license.</footer>
166166 </body>
167167 </html>

site/public/advanced/ordering.html (history) modified +2 -2

@@ -16,7 +16,7 @@
1616 <link rel="stylesheet" href="../style.css">
1717 </head>
1818 <body>
19-<header><nav><a class="mark" href="../index.html"><img src="../logo.svg" width="26" height="26" alt="">raz</a><a href="../tour/index.html">Raz, Set, Go</a><a href="../advanced/index.html" aria-current="page">More Raz</a><a href="../spec.html">Report</a><a href="../index.html#download">Download</a><a class="repo" href="https://github.com/ldiaz94/raz">GitHub</a></nav></header>
19+<header><nav><a class="mark" href="../index.html"><img src="../logo.svg" width="26" height="26" alt="">raz</a><a href="../tour/index.html">Raz, Set, Go</a><a href="../advanced/index.html" aria-current="page">More Raz</a><a href="../spec.html">Report</a><a href="../index.html#download">Download</a></nav></header>
2020 <main>
2121 <div class="tour"><aside><h2>More Raz</h2><h3>The library</h3><ol start='1'>
2222 <li><a href="fmt.html">Output and formatting</a></li>
@@ -126,6 +126,6 @@
126126 <h2>The lesson of the three versions</h2>
127127 <ul><li>Shared and written by someone: reach it through an atomic, a volatile pointer or a fence, every time, on both sides.</li><li>To hand over a bundle, publish a single atomic word *after* writing the bundle, and read the bundle only *after* seeing the word.</li><li>Everything under a <code>Lock</code> or a <code>Mutex</code> is ordered by the lock itself, so the data it guards can be ordinary variables. That is the simplest discipline, and the one to prefer until it is measured to be too slow.</li></ul><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="atomics.html">&larr; Atomics</a><a href="index.html">Contents</a><a class="next" href="lockfree.html">A lock-free stack &rarr;</a></div></article></div>
128128 </main>
129-<footer>raz is under the ISC license. <a href="https://github.com/ldiaz94/raz">Source</a>.</footer>
129+<footer>raz is under the ISC license.</footer>
130130 </body>
131131 </html>

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

@@ -16,7 +16,7 @@
1616 <link rel="stylesheet" href="../style.css">
1717 </head>
1818 <body>
19-<header><nav><a class="mark" href="../index.html"><img src="../logo.svg" width="26" height="26" alt="">raz</a><a href="../tour/index.html">Raz, Set, Go</a><a href="../advanced/index.html" aria-current="page">More Raz</a><a href="../spec.html">Report</a><a href="../index.html#download">Download</a><a class="repo" href="https://github.com/ldiaz94/raz">GitHub</a></nav></header>
19+<header><nav><a class="mark" href="../index.html"><img src="../logo.svg" width="26" height="26" alt="">raz</a><a href="../tour/index.html">Raz, Set, Go</a><a href="../advanced/index.html" aria-current="page">More Raz</a><a href="../spec.html">Report</a><a href="../index.html#download">Download</a></nav></header>
2020 <main>
2121 <div class="tour"><aside><h2>More Raz</h2><h3>The library</h3><ol start='1'>
2222 <li><a href="fmt.html">Output and formatting</a></li>
@@ -186,6 +186,6 @@
186186 hello from /tmp
187187 </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="files.html">&larr; Files and the command line</a><a href="index.html">Contents</a><a class="next" href="allocators.html">Writing an allocator &rarr;</a></div></article></div>
188188 </main>
189-<footer>raz is under the ISC license. <a href="https://github.com/ldiaz94/raz">Source</a>.</footer>
189+<footer>raz is under the ISC license.</footer>
190190 </body>
191191 </html>

site/public/advanced/ring.html (history) modified +2 -2

@@ -16,7 +16,7 @@
1616 <link rel="stylesheet" href="../style.css">
1717 </head>
1818 <body>
19-<header><nav><a class="mark" href="../index.html"><img src="../logo.svg" width="26" height="26" alt="">raz</a><a href="../tour/index.html">Raz, Set, Go</a><a href="../advanced/index.html" aria-current="page">More Raz</a><a href="../spec.html">Report</a><a href="../index.html#download">Download</a><a class="repo" href="https://github.com/ldiaz94/raz">GitHub</a></nav></header>
19+<header><nav><a class="mark" href="../index.html"><img src="../logo.svg" width="26" height="26" alt="">raz</a><a href="../tour/index.html">Raz, Set, Go</a><a href="../advanced/index.html" aria-current="page">More Raz</a><a href="../spec.html">Report</a><a href="../index.html#download">Download</a></nav></header>
2020 <main>
2121 <div class="tour"><aside><h2>More Raz</h2><h3>The library</h3><ol start='1'>
2222 <li><a href="fmt.html">Output and formatting</a></li>
@@ -134,6 +134,6 @@
134134 <p>That is the end of the tour. A few places to continue:</p>
135135 <ul><li><strong><a href="../spec.html">The report</a></strong> defines the language, and is short enough to read through.</li><li><strong><code>doc/compiler.md</code></strong> in the sources is a guide to reading the compiler, file by file; it is a model of the style the project is written in.</li><li><strong><code>lib/</code></strong> is the library, in raz. Each module's own <code>main</code> is its test. Reading <code>Heap</code>, <code>Map</code>, <code>Opt</code> and <code>Thread</code> is the best remaining education.</li><li><strong><code>tools/Doc.raz</code></strong> prints what a module exports with its comments: <code>raz -o Doc tools/Doc.raz &amp;&amp; ./Doc lib/Str.raz</code>.</li><li><strong><code>examples/</code></strong> holds small programs with the output each should give, and <code>conform/</code> holds what any implementation must do.</li></ul><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="lockfree.html">&larr; A lock-free stack</a><a href="index.html">Contents</a><a class="next" href="../spec.html">The report &rarr;</a></div></article></div>
136136 </main>
137-<footer>raz is under the ISC license. <a href="https://github.com/ldiaz94/raz">Source</a>.</footer>
137+<footer>raz is under the ISC license.</footer>
138138 </body>
139139 </html>

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

@@ -16,7 +16,7 @@
1616 <link rel="stylesheet" href="../style.css">
1717 </head>
1818 <body>
19-<header><nav><a class="mark" href="../index.html"><img src="../logo.svg" width="26" height="26" alt="">raz</a><a href="../tour/index.html">Raz, Set, Go</a><a href="../advanced/index.html" aria-current="page">More Raz</a><a href="../spec.html">Report</a><a href="../index.html#download">Download</a><a class="repo" href="https://github.com/ldiaz94/raz">GitHub</a></nav></header>
19+<header><nav><a class="mark" href="../index.html"><img src="../logo.svg" width="26" height="26" alt="">raz</a><a href="../tour/index.html">Raz, Set, Go</a><a href="../advanced/index.html" aria-current="page">More Raz</a><a href="../spec.html">Report</a><a href="../index.html#download">Download</a></nav></header>
2020 <main>
2121 <div class="tour"><aside><h2>More Raz</h2><h3>The library</h3><ol start='1'>
2222 <li><a href="fmt.html">Output and formatting</a></li>
@@ -65,7 +65,7 @@
6565 <span class="cmd">$ ldd Bare</span>
6666 not a dynamic executable
6767 <span class="cmd">$ ls -l Bare | awk &#x27;{print $5, &quot;bytes&quot;}&#x27;</span>
68-26272 bytes</code></pre>
68+26176 bytes</code></pre>
6969 <p>It is statically linked: no interpreter, no shared libraries, no <code>libc</code>. <code>ldd</code> says so.</p>
7070 <h2>What it does when it runs</h2>
7171 <p><code>strace</code> lists every system call a program makes. This is the whole of it:</p>
@@ -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; /lib/x86_64-linux-gnu/libc.so.6
101- /lib64/ld-linux-x86-64.so.2</code></pre>
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>
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,19 +134,19 @@
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 28480
138-Lean 28472</code></pre>
137+Heavy 28384
138+Lean 28376</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 28472
145-Lean-stripped 6752
144+Lean 28376
145+Lean-stripped 6720
146146 <span class="cmd">$ ./Lean-stripped</span>
147147 same program</code></pre>
148148 <p><code>raz -S Lean.raz</code> is the other direction: it prints the machine code the compiler made, one source line at a time. The next two parts of the tour use it.</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="allocators.html">&larr; Writing an allocator</a><a href="index.html">Contents</a><a class="next" href="linkstatic.html">Threads without C, and keeping the two apart &rarr;</a></div></article></div>
149149 </main>
150-<footer>raz is under the ISC license. <a href="https://github.com/ldiaz94/raz">Source</a>.</footer>
150+<footer>raz is under the ISC license.</footer>
151151 </body>
152152 </html>

site/public/advanced/syscalls.html (history) modified +2 -2

@@ -16,7 +16,7 @@
1616 <link rel="stylesheet" href="../style.css">
1717 </head>
1818 <body>
19-<header><nav><a class="mark" href="../index.html"><img src="../logo.svg" width="26" height="26" alt="">raz</a><a href="../tour/index.html">Raz, Set, Go</a><a href="../advanced/index.html" aria-current="page">More Raz</a><a href="../spec.html">Report</a><a href="../index.html#download">Download</a><a class="repo" href="https://github.com/ldiaz94/raz">GitHub</a></nav></header>
19+<header><nav><a class="mark" href="../index.html"><img src="../logo.svg" width="26" height="26" alt="">raz</a><a href="../tour/index.html">Raz, Set, Go</a><a href="../advanced/index.html" aria-current="page">More Raz</a><a href="../spec.html">Report</a><a href="../index.html#download">Download</a></nav></header>
2020 <main>
2121 <div class="tour"><aside><h2>More Raz</h2><h3>The library</h3><ol start='1'>
2222 <li><a href="fmt.html">Output and formatting</a></li>
@@ -194,6 +194,6 @@
194194 </code></pre>
195195 <p><code>SYSCALL</code> is the right tool nearly always: the compiler puts the arguments where they belong, and the result is checked in the open. A code procedure is for the rare call you want to make from inside another piece of assembly.</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="asm.html">&larr; Procedures in assembly</a><a href="index.html">Contents</a><a class="next" href="listing.html">What the compiler makes &rarr;</a></div></article></div>
196196 </main>
197-<footer>raz is under the ISC license. <a href="https://github.com/ldiaz94/raz">Source</a>.</footer>
197+<footer>raz is under the ISC license.</footer>
198198 </body>
199199 </html>

site/public/advanced/targets.html (history) modified +2 -2

@@ -16,7 +16,7 @@
1616 <link rel="stylesheet" href="../style.css">
1717 </head>
1818 <body>
19-<header><nav><a class="mark" href="../index.html"><img src="../logo.svg" width="26" height="26" alt="">raz</a><a href="../tour/index.html">Raz, Set, Go</a><a href="../advanced/index.html" aria-current="page">More Raz</a><a href="../spec.html">Report</a><a href="../index.html#download">Download</a><a class="repo" href="https://github.com/ldiaz94/raz">GitHub</a></nav></header>
19+<header><nav><a class="mark" href="../index.html"><img src="../logo.svg" width="26" height="26" alt="">raz</a><a href="../tour/index.html">Raz, Set, Go</a><a href="../advanced/index.html" aria-current="page">More Raz</a><a href="../spec.html">Report</a><a href="../index.html#download">Download</a></nav></header>
2020 <main>
2121 <div class="tour"><aside><h2>More Raz</h2><h3>The library</h3><ol start='1'>
2222 <li><a href="fmt.html">Output and formatting</a></li>
@@ -107,6 +107,6 @@
107107 <h2>What stays the same everywhere</h2>
108108 <p>The core of the library is what every target must have: <code>Rt</code>, <code>Out</code>, <code>Mem</code>, <code>Arena</code>, <code>Lock</code>, <code>Str</code> and <code>Buf</code>, and of <code>Sys</code> what they need. A program that keeps to the core runs on every target. <code>Thread</code>, <code>link</code> and <code>extern</code>, and most of <code>Sys</code>, are what a target may leave out when its system can't give them.</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="lifecycle.html">&larr; Starting, ending, and signals</a><a href="index.html">Contents</a><a class="next" href="asm.html">Procedures in assembly &rarr;</a></div></article></div>
109109 </main>
110-<footer>raz is under the ISC license. <a href="https://github.com/ldiaz94/raz">Source</a>.</footer>
110+<footer>raz is under the ISC license.</footer>
111111 </body>
112112 </html>

site/public/advanced/volatile.html (history) modified +2 -2

@@ -16,7 +16,7 @@
1616 <link rel="stylesheet" href="../style.css">
1717 </head>
1818 <body>
19-<header><nav><a class="mark" href="../index.html"><img src="../logo.svg" width="26" height="26" alt="">raz</a><a href="../tour/index.html">Raz, Set, Go</a><a href="../advanced/index.html" aria-current="page">More Raz</a><a href="../spec.html">Report</a><a href="../index.html#download">Download</a><a class="repo" href="https://github.com/ldiaz94/raz">GitHub</a></nav></header>
19+<header><nav><a class="mark" href="../index.html"><img src="../logo.svg" width="26" height="26" alt="">raz</a><a href="../tour/index.html">Raz, Set, Go</a><a href="../advanced/index.html" aria-current="page">More Raz</a><a href="../spec.html">Report</a><a href="../index.html#download">Download</a></nav></header>
2020 <main>
2121 <div class="tour"><aside><h2>More Raz</h2><h3>The library</h3><ol start='1'>
2222 <li><a href="fmt.html">Output and formatting</a></li>
@@ -149,6 +149,6 @@
149149 | ^^
150150 raz: 2 errors</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="listing.html">&larr; What the compiler makes</a><a href="index.html">Contents</a><a class="next" href="atomics.html">Atomics &rarr;</a></div></article></div>
151151 </main>
152-<footer>raz is under the ISC license. <a href="https://github.com/ldiaz94/raz">Source</a>.</footer>
152+<footer>raz is under the ISC license.</footer>
153153 </body>
154154 </html>

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

Binary file; the patch has it.

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

@@ -0,0 +1 @@
1+c1387747ef3350efb19b35edf2769612fe323ecb08cff34906065b530fc71a09 raz-0.9.0-linux-x86_64.tar.gz

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

@@ -16,7 +16,7 @@
1616 <link rel="stylesheet" href="style.css">
1717 </head>
1818 <body>
19-<header><nav><a class="mark" href="index.html"><img src="logo.svg" width="26" height="26" alt="">raz</a><a href="tour/index.html">Raz, Set, Go</a><a href="advanced/index.html">More Raz</a><a href="spec.html">Report</a><a href="index.html#download">Download</a><a class="repo" href="https://github.com/ldiaz94/raz">GitHub</a></nav></header>
19+<header><nav><a class="mark" href="index.html"><img src="logo.svg" width="26" height="26" alt="">raz</a><a href="tour/index.html">Raz, Set, Go</a><a href="advanced/index.html">More Raz</a><a href="spec.html">Report</a><a href="index.html#download">Download</a></nav></header>
2020 <main>
2121 <section class="hero">
2222 <h1>raz</h1>
@@ -35,15 +35,15 @@
3535 system calls and call C libraries. It has no garbage collector and no hidden
3636 run time: what the program does is what its text says.</p>
3737
38-<p>The compiler is one Free Pascal program of about 7,800 lines. It makes
38+<p>The compiler is one Free Pascal program of about 9,100 lines. It makes
3939 x86-64 machine code and the ELF file itself, with no assembler or linker, in
40-one pass, at about a million lines a second.</p>
40+one pass, at about 900,000 lines a second.</p>
4141
4242 <div class="facts">
43- <span><b>~7,800</b> lines of compiler</span>
44- <span><b>~1M</b> lines compiled a second</span>
43+ <span><b>~9,100</b> lines of compiler</span>
44+ <span><b>~900K</b> lines compiled a second</span>
4545 <span><b>static</b> executables, no run time to install</span>
46- <span><b>1</b> report, <b>~2,000</b> lines</span>
46+ <span><b>1</b> report, <b>~2,100</b> lines</span>
4747 </div>
4848
4949 <div class="cols">
@@ -91,7 +91,7 @@
9191 <li>Modules with bodies, and generic modules: <code>Map(K, V; hash, eq)</code>.</li>
9292 <li><code>^VOLATILE T</code> and the atomics <code>CAS</code>, <code>XCHG</code>, <code>XADD</code>, <code>FENCE</code>, for devices and lock-free code.</li>
9393 <li><code>extern</code> procedures and variables from C, code procedures in assembly, and <code>SYSCALL</code>.</li>
94- <li>Threads without C, a library of <code>Out</code>, <code>Str</code>, <code>Fmt</code>, <code>Map</code>, <code>Sort</code> and more, and gdb that knows your lines.</li>
94+ <li>Threads without C, a library of <code>Out</code>, <code>Str</code>, <code>Bytes</code>, <code>Fmt</code>, <code>Map</code>, <code>Sort</code> and more, and gdb that knows your lines.</li>
9595 <li>A formatter, a documentation tool, and editor support for vim and emacs.</li>
9696 </ul>
9797 </div>
@@ -106,26 +106,25 @@
106106
107107 <h2>The language, in writing</h2>
108108 <p>The language is defined by <a href="spec.html">the report</a>, which is
109-short on purpose: whatever it doesn&rsquo;t allow, raz doesn&rsquo;t have. There
110-is also a <a href="https://github.com/ldiaz94/raz/blob/main/doc/compiler.md">guide to reading the
111-compiler</a>, file by file.</p>
109+short on purpose: whatever it doesn&rsquo;t allow, raz doesn&rsquo;t have.</p>
112110
113111 <h2 id="download">Download</h2>
114-<p>Each release is a tarball with the compiler, <code>raz</code>, and its
115-library, <code>lib/</code>, which it finds beside itself.</p>
112+<p>raz 0.9.0 is a tarball for x86-64 Linux with the compiler, <code>raz</code>,
113+its library, <code>lib/</code>, which it finds beside itself, and the manual
114+pages. It needs nothing else installed.</p>
116115 <div class="cta">
117- <a class="btn primary" href="https://github.com/ldiaz94/raz/releases/latest">Latest release</a>
118- <a class="btn" href="https://github.com/ldiaz94/raz">Source on GitHub</a>
116+ <a class="btn primary" href="download/raz-0.9.0-linux-x86_64.tar.gz">Download raz 0.9.0</a>
117+ <a class="btn" href="download/raz-0.9.0-linux-x86_64.tar.gz.sha256">SHA-256</a>
119118 </div>
120-<pre class="code"><code>$ tar xzf raz-*.tar.gz
121-$ ./raz run examples/Hello.raz
122-hello, world</code></pre>
123-<p>To build it yourself you need Free Pascal 3.2.2:</p>
124-<pre class="code"><code>$ apt-get install fp-compiler
125-$ git clone https://github.com/ldiaz94/raz
126-$ cd raz &amp;&amp; make &amp;&amp; make install # ~/.local, or PREFIX=/usr/local</code></pre>
119+<pre class="code"><code>$ tar xzf raz-0.9.0-linux-x86_64.tar.gz
120+$ ln -s $PWD/raz-0.9.0-linux-x86_64/raz ~/.local/bin/raz
121+$ raz run Hello.raz</code></pre>
122+<p>The link works since raz finds <code>lib/</code> beside its real path. The
123+manual pages are in <code>man/</code>: <code>man ./man/raz-tutorial.7</code>.
124+The address <code>download/latest</code> always leads to the newest release.</p>
125+<p class="sha">SHA-256 <code>c1387747ef3350efb19b35edf2769612fe323ecb08cff34906065b530fc71a09</code></p>
127126
128127 </main>
129-<footer>raz is under the ISC license. <a href="https://github.com/ldiaz94/raz">Source</a>.</footer>
128+<footer>raz is under the ISC license.</footer>
130129 </body>
131130 </html>

site/public/spec.html (history) modified +308 -1404

@@ -16,16 +16,13 @@
1616 <link rel="stylesheet" href="style.css">
1717 </head>
1818 <body>
19-<header><nav><a class="mark" href="index.html"><img src="logo.svg" width="26" height="26" alt="">raz</a><a href="tour/index.html">Raz, Set, Go</a><a href="advanced/index.html">More Raz</a><a href="spec.html" aria-current="page">Report</a><a href="index.html#download">Download</a><a class="repo" href="https://github.com/ldiaz94/raz">GitHub</a></nav></header>
19+<header><nav><a class="mark" href="index.html"><img src="logo.svg" width="26" height="26" alt="">raz</a><a href="tour/index.html">Raz, Set, Go</a><a href="advanced/index.html">More Raz</a><a href="spec.html" aria-current="page">Report</a><a href="index.html#download">Download</a></nav></header>
2020 <main>
2121 <div class="spec"><ul>
22-<li><a href="#a-first-look" id="toc-a-first-look">1. A first
23-look</a></li>
24-<li><a href="#words-and-symbols" id="toc-words-and-symbols">2. Words and
25-symbols</a></li>
22+<li><a href="#a-first-look" id="toc-a-first-look">1. A first look</a></li>
23+<li><a href="#words-and-symbols" id="toc-words-and-symbols">2. Words and symbols</a></li>
2624 <li><a href="#modules" id="toc-modules">3. Modules</a></li>
27-<li><a href="#declarations" id="toc-declarations">4.
28-Declarations</a></li>
25+<li><a href="#declarations" id="toc-declarations">4. Declarations</a></li>
2926 <li><a href="#types" id="toc-types">5. Types</a></li>
3027 <li><a href="#expressions" id="toc-expressions">6. Expressions</a></li>
3128 <li><a href="#statements" id="toc-statements">7. Statements</a></li>
@@ -34,29 +31,13 @@
3431 <li><a href="#programs" id="toc-programs">10. Programs</a></li>
3532 <li><a href="#the-library" id="toc-the-library">11. The library</a></li>
3633 <li><a href="#versions" id="toc-versions">12. Versions</a></li>
37-<li><a href="#appendix-a.-what-an-implementation-chooses"
38-id="toc-appendix-a.-what-an-implementation-chooses">Appendix A. What an
39-implementation chooses</a></li>
40-<li><a href="#appendix-b.-the-grammar"
41-id="toc-appendix-b.-the-grammar">Appendix B. The grammar</a></li>
34+<li><a href="#appendix-a.-what-an-implementation-chooses" id="toc-appendix-a.-what-an-implementation-chooses">Appendix A. What an implementation chooses</a></li>
35+<li><a href="#appendix-b.-the-grammar" id="toc-appendix-b.-the-grammar">Appendix B. The grammar</a></li>
4236 </ul>
43-<p>raz is a small systems language, first made for x86-64 Linux. A raz
44-program can lay a record over a device’s registers, read and write a
45-device’s memory exactly as written, take part in lock-free algorithms,
46-make system calls and call C libraries. It has no garbage collector and
47-no hidden run time: what the program does is what its text says.</p>
48-<p>This report defines the language. It is short on purpose. Whatever it
49-doesn’t allow, raz doesn’t have.</p>
50-<p>This is version 2026-10.17 of the report; section 12 says what each
51-version changed. 2026-10.11 and 2026-10.12 are a thaw the owner chose,
52-for a language anyone can build again. They break programs written for
53-2026-10.10 and before: for 2026-10.9, say, the report of compiler 0.5.0,
54-the last release before them; and 2026-10.12 breaks code procedures
55-written for 2026-10.11.</p>
56-<p>The language is frozen, softly, from this version on: it changes only
57-to mend a defect, and its library grows only by what breaks no program
58-written for it. What anyone wishes it had waits on a list, for a later
59-thaw.</p>
37+<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>
38+<p>This report defines the language. It is short on purpose. Whatever it doesn’t allow, raz doesn’t have.</p>
39+<p>This is version 2026-10.19 of the report; section 12 says what each version changed. 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.</p>
40+<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>
6041 <h1 id="a-first-look">1. A first look</h1>
6142 <pre><code>module Hello;
6243 import Out;
@@ -67,82 +48,27 @@
6748 end;
6849
6950 end Hello.</code></pre>
70-<p>A program is a set of modules. The one named on the command line is
71-the main module, and it exports a procedure <code>main</code>; the
72-program starts there, once every module’s body has run (section 3).
73-Saved as <code>Hello.raz</code>, it is compiled with
74-<code>raz Hello.raz</code>, which writes the executable
75-<code>Hello</code>.</p>
51+<p>A program is a set of modules. The one named on the command line is the main module, and it exports a procedure <code>main</code>; the program starts there, once every module’s body has run (section 3). Saved as <code>Hello.raz</code>, it is compiled with <code>raz Hello.raz</code>, which writes the executable <code>Hello</code>.</p>
7652 <h1 id="words-and-symbols">2. Words and symbols</h1>
77-<p>A program is written in UTF-8. The compiler rejects a file that isn’t
78-valid UTF-8: a malformed or overlong sequence, a surrogate, or a code
79-point beyond 10FFFFH. Everything outside strings, characters and
80-comments is ASCII. Spaces, tabs and line breaks separate symbols and are
81-otherwise ignored.</p>
82-<p><strong>Identifiers</strong> are an ASCII letter or <code>_</code>
83-followed by letters, digits and <code>_</code>, up to 63 characters.
84-Case matters: <code>count</code> and <code>Count</code> are different
85-names. <code>_</code> alone isn’t a name: it is the blank, which stands
86-only to the left of <code>:=</code> (section 7.1).</p>
87-<p><strong>Reserved words</strong> are lowercase, except
88-<code>VOLATILE</code>:</p>
53+<p>A program is written in UTF-8. The compiler rejects a file that isn’t valid UTF-8: a malformed or overlong sequence, a surrogate, or a code point beyond 10FFFFH. Everything outside strings, characters and comments is ASCII. Spaces, tabs and line breaks separate symbols and are otherwise ignored.</p>
54+<p><strong>Identifiers</strong> are an ASCII letter or <code>_</code> followed by letters, digits and <code>_</code>, up to 63 characters. Case matters: <code>count</code> and <code>Count</code> are different names. <code>_</code> alone isn’t a name: it is the blank, which stands only to the left of <code>:=</code> (section 7.1).</p>
55+<p><strong>Reserved words</strong> are lowercase, except <code>VOLATILE</code>:</p>
8956 <pre><code>and begin break by code const defer div do else elsif end extern for
9057 forward if import in link match mod module not of or packed proc record
9158 repeat return set shl shr then to type until var variant VOLATILE while
9259 xor</code></pre>
93-<p><code>static</code>, in <code>link static;</code> (section 3), isn’t
94-one.</p>
95-<p><strong>Predeclared names</strong> are the basic types (section 5.1),
96-<code>ERROR</code>, <code>true</code>, <code>false</code>,
97-<code>nil</code> and the built-in procedures (section 6.8). They belong
98-to a scope around every module, so a module or a procedure may declare
99-the same name for something else, which hides them there.</p>
100-<p><strong>Numbers.</strong> <code>123</code> is decimal.
101-<code>0FFH</code> is hexadecimal: it starts with a digit, its digits are
102-<code>0</code> to <code>9</code> and <code>A</code> to <code>F</code>,
103-and it ends in <code>H</code>, all in capitals. <code>1.5</code> and
104-<code>2.0E-3</code> are reals; a real always has a digit on both sides
105-of its point, and its exponent, if it has one, is <code>E</code>, a sign
106-if wanted, and digits. A decimal number above the largest
107-<code>I64</code>, or a hexadecimal one above the largest
108-<code>U64</code>, is an error.</p>
109-<p>An integer is an untyped constant, which takes the type it is used
110-as, up to the largest <code>I64</code>. A hexadecimal number above that,
111-such as <code>0FFFFFFFFFFFFFFFFH</code>, has type <code>U64</code>: so
112-<code>-1</code> never fits a <code>U64</code>, and the big number goes
113-nowhere else without a conversion. Arithmetic on untyped constants
114-doesn’t wrap: a result beyond the <code>I64</code>s, such as
115-<code>9223372036854775807 + 1</code>, is an error.</p>
116-<p>A real is an untyped constant too, which takes <code>F32</code> or
117-<code>F64</code>, whichever it is used as, rounded to the nearest value
118-of that type; where nothing says which, it is an <code>F64</code>. A
119-real never becomes an integer, nor an integer a real, without a
120-conversion: <code>x := 1;</code> is an error for <code>x: F64</code>,
121-and <code>x := 1.0;</code> is right.</p>
122-<p><strong>Characters.</strong> <code>'a'</code> is the code point of
123-one character, an integer: <code>'a'</code> is 97 and <code>'é'</code>
124-is 233.</p>
125-<p><strong>Strings.</strong> <code>"héllo\n"</code> is a sequence of
126-bytes, the UTF-8 of its text: <code>"é"</code> is the two bytes 0C3H,
127-0A9H. Both characters and strings take the escapes <code>\n</code> (line
128-feed), <code>\t</code> (tab), <code>\r</code> (carriage return),
129-<code>\0</code> (zero), <code>\\</code>, <code>\'</code>,
130-<code>\"</code>, <code>\u{H...}</code> (the code point with hexadecimal
131-value H…, in a string its UTF-8) and, in strings only, <code>\xHH</code>
132-(the byte with hexadecimal value HH, which needn’t make valid UTF-8). In
133-an escape, the hexadecimal digits may be capitals or not. A character or
134-a string ends on the line it starts on.</p>
135-<p>Messages give the line and the column, counted in characters (section
136-10).</p>
137-<p><strong>Comments</strong> are <code>(*</code> … <code>*)</code> and
138-nest. By convention, the comment just before an exported declaration is
139-its documentation, and the one before <code>module</code> is the
140-module’s.</p>
60+<p><code>static</code>, in <code>link static;</code> (section 3), isn’t one.</p>
61+<p><strong>Predeclared names</strong> are the basic types (section 5.1), <code>ERROR</code>, <code>true</code>, <code>false</code>, <code>nil</code> and the built-in procedures (section 6.8). They belong to a scope around every module, so a module or a procedure may declare the same name for something else, which hides them there.</p>
62+<p><strong>Numbers.</strong> <code>123</code> is decimal. <code>0FFH</code> is hexadecimal: it starts with a digit, its digits are <code>0</code> to <code>9</code> and <code>A</code> to <code>F</code>, and it ends in <code>H</code>, all in capitals. <code>1.5</code> and <code>2.0E-3</code> are reals; a real always has a digit on both sides of its point, and its exponent, if it has one, is <code>E</code>, a sign if wanted, and digits. A decimal number above the largest <code>I64</code>, or a hexadecimal one above the largest <code>U64</code>, is an error.</p>
63+<p>An integer is an untyped constant, which takes the type it is used as, up to the largest <code>I64</code>. A hexadecimal number above that, such as <code>0FFFFFFFFFFFFFFFFH</code>, has type <code>U64</code>: so <code>-1</code> never fits a <code>U64</code>, and the big number goes nowhere else without a conversion. Arithmetic on untyped constants doesn’t wrap: a result beyond the <code>I64</code>s, such as <code>9223372036854775807 + 1</code>, is an error.</p>
64+<p>A real is an untyped constant too, which takes <code>F32</code> or <code>F64</code>, whichever it is used as, rounded to the nearest value of that type; where nothing says which, it is an <code>F64</code>. A real never becomes an integer, nor an integer a real, without a conversion: <code>x := 1;</code> is an error for <code>x: F64</code>, and <code>x := 1.0;</code> is right.</p>
65+<p><strong>Characters.</strong> <code>'a'</code> is the code point of one character, an integer: <code>'a'</code> is 97 and <code>'é'</code> is 233.</p>
66+<p><strong>Strings.</strong> <code>"héllo\n"</code> is a sequence of bytes, the UTF-8 of its text: <code>"é"</code> is the two bytes 0C3H, 0A9H. Both characters and strings take the escapes <code>\n</code> (line feed), <code>\t</code> (tab), <code>\r</code> (carriage return), <code>\0</code> (zero), <code>\\</code>, <code>\'</code>, <code>\"</code>, <code>\u{H...}</code> (the code point with hexadecimal value H…, in a string its UTF-8) and, in strings only, <code>\xHH</code> (the byte with hexadecimal value HH, which needn’t make valid UTF-8). In an escape, the hexadecimal digits may be capitals or not. A character or a string ends on the line it starts on.</p>
67+<p>Messages give the line and the column, counted in characters (section 10).</p>
68+<p><strong>Comments</strong> are <code>(*</code> … <code>*)</code> and nest. By convention, the comment just before an exported declaration is its documentation, and the one before <code>module</code> is the module’s.</p>
14169 <p><strong>Operators and delimiters:</strong></p>
14270 <pre><code>+ - * / &amp; | ~ = # &lt; &lt;= &gt; &gt;= := : ; , . .. ... ( ) [ ] { } ^</code></pre>
143-<p><code>|</code> is also what starts an arm of <code>match</code>
144-(section 7.4); an arm comes where a statement could, never after an
145-operand, so the two don’t mix.</p>
71+<p><code>|</code> is also what starts an arm of <code>match</code> (section 7.4); an arm comes where a statement could, never after an operand, so the two don’t mix.</p>
14672 <h1 id="modules">3. Modules</h1>
14773 <pre><code>Module = &quot;module&quot; ident [ &quot;(&quot; ModParams &quot;)&quot; ] &quot;;&quot;
14874 { Import } { Link } [ Check ] { Declaration }
@@ -152,141 +78,40 @@
15278 ImportItem = ident [ &quot;:=&quot; ident [ &quot;(&quot; Type { &quot;,&quot; Type } &quot;)&quot; ] ] .
15379 Link = &quot;link&quot; ( string | &quot;static&quot; ) &quot;;&quot; .
15480 Check = &quot;check&quot; &quot;off&quot; &quot;;&quot; .</code></pre>
155-<p>A module lives in a file of its own name: module <code>Out</code> is
156-<code>Out.raz</code>. The name after <code>end</code> repeats the
157-module’s name.</p>
158-<p><strong>Exports.</strong> A name declared at the top of a module with
159-<code>*</code> after it is exported: other modules can use it as
160-<code>Module.name</code>. Record fields are exported the same way.
161-Everything else is private to the module. An exported variable can be
162-read by the modules that import it, but only its own module changes it.
163-Outside it, the variable is a value, not a variable: nothing that could
164-write it, or let something else write it, may name it or a field or
165-element of it. So it can’t be assigned, passed as a <code>var</code>
166-argument, changed by <code>INC</code>, <code>DEC</code> or
167-<code>NEW</code>, or given to <code>ADR</code>; an array in it can’t be
168-sliced, or used where a slice is expected (the silent conversion of an
169-array, section 5.10), though a slice in it may be sliced, since that
170-makes a new slice and can’t change the variable; in <code>match</code>,
171-its arms’ names stand for the fields of a copy. It can be read, copied
172-and compared, and a copy is the importer’s own. What a pointer or a
173-slice in it points at is another variable, and isn’t held to this: with
174-<code>s: []U8</code> exported, <code>M.s[0] := 0</code> writes what
175-<code>M.s</code> points at, not <code>M</code>. A module that means to
176-share an array exports a pointer to it, or a procedure that returns a
177-slice of it.</p>
178-<p><strong>Imports.</strong> <code>import Out;</code> makes
179-<code>Out</code>’s exports available as <code>Out.x</code>.
180-<code>import O := Out;</code> uses the name <code>O</code> instead. A
181-module can’t import itself, directly or through others.</p>
81+<p>A module lives in a file of its own name: module <code>Out</code> is <code>Out.raz</code>. The name after <code>end</code> repeats the module’s name.</p>
82+<p><strong>Exports.</strong> A name declared at the top of a module with <code>*</code> after it is exported: other modules can use it as <code>Module.name</code>. Record fields are exported the same way. Everything else is private to the module. An exported variable can be read by the modules that import it, but only its own module changes it. Outside it, the variable is a value, not a variable: nothing that could write it, or let something else write it, may name it or a field or element of it. So it can’t be assigned, passed as a <code>var</code> argument, changed by <code>INC</code>, <code>DEC</code> or <code>NEW</code>, or given to <code>ADR</code>; an array in it can’t be sliced, or used where a slice is expected (the silent conversion of an array, section 5.10), though a slice in it may be sliced, since that makes a new slice and can’t change the variable; in <code>match</code>, its arms’ names stand for the fields of a copy. It can be read, copied and compared, and a copy is the importer’s own. What a pointer or a slice in it points at is another variable, and isn’t held to this: with <code>s: []U8</code> exported, <code>M.s[0] := 0</code> writes what <code>M.s</code> points at, not <code>M</code>. A module that means to share an array exports a pointer to it, or a procedure that returns a slice of it.</p>
83+<p><strong>Imports.</strong> <code>import Out;</code> makes <code>Out</code>’s exports available as <code>Out.x</code>. <code>import O := Out;</code> uses the name <code>O</code> instead. A module can’t import itself, directly or through others.</p>
18284 <p><strong>Generic modules</strong> take types as parameters:</p>
18385 <pre><code>module List(T);
18486 type
18587 Node* = record next*: ^Node; val*: T; end;
18688 ...
18789 end List.</code></pre>
188-<p>An import gives the arguments:
189-<code>import Ints := List(I64);</code>. Each distinct list of arguments
190-makes one <em>instance</em>: the module compiled with <code>T</code>
191-standing for <code>I64</code>. Two imports of <code>List(I64)</code>, in
192-any modules, share one instance, its variables and its
193-<code>ERROR</code>s with it: two lists of arguments are the same when
194-their types are the same (section 5.10), an alias as what it stands for,
195-and their procedures are the same procedures. Since every instance is
196-checked on its own, an operation the argument type doesn’t support
197-(adding two records, say) is reported as an error in that instance.</p>
198-<p>An instance is made where its module is first used, not at the
199-import: so the arguments may name types the importing module declares
200-after its imports, as long as they are declared before that first use.
201-The instance is made before the code of the procedure, or the module
202-body, that first uses it, and its arguments are read in the scope
203-there.</p>
90+<p>An import gives the arguments: <code>import Ints := List(I64);</code>. Each distinct list of arguments makes one <em>instance</em>: the module compiled with <code>T</code> standing for <code>I64</code>. Two imports of <code>List(I64)</code>, in any modules, share one instance, its variables and its <code>ERROR</code>s with it: two lists of arguments are the same when their types are the same (section 5.10), an alias as what it stands for, and their procedures are the same procedures. Since every instance is checked on its own, an operation the argument type doesn’t support (adding two records, say) is reported as an error in that instance.</p>
91+<p>An instance is made where its module is first used, not at the import: so the arguments may name types the importing module declares after its imports, as long as they are declared before that first use. The instance is made before the code of the procedure, or the module body, that first uses it, and its arguments are read in the scope there.</p>
20492 <pre><code>import Table := Map([]U8, Colour, Str.hash, Str.eq);
20593
20694 type Colour = (red, green, blue);
20795
20896 var names: Table.Map; (* the instance is made here *)</code></pre>
209-<p>What a generic module needs to do with its types, beyond moving them
210-about, it is given as procedures, after the types:</p>
97+<p>What a generic module needs to do with its types, beyond moving them about, it is given as procedures, after the types:</p>
21198 <pre><code>module Map(K, V; hash: proc(k: K): U64; eq: proc(a, b: K): BOOL);</code></pre>
21299 <pre><code>import Names := Map([]U8, I64, Str.hash, Str.eq);</code></pre>
213-<p>A procedure argument names a procedure, not a variable or an
214-expression, and its signature, with the type arguments put in, must be
215-the parameter’s. Inside the module, <code>hash(k)</code> calls it
216-directly. Two imports make the same instance only if their types and
217-their procedures are the same.</p>
218-<p><strong>Finding modules.</strong> The compiler looks for module
219-<code>Name</code> in the main module’s directory, then in each directory
220-given with <code>-I</code>, then in the <code>lib</code> directory
221-beside the compiler. In each directory it takes the first of
222-<code>Name.OS-ARCH.raz</code>, <code>Name.OS.raz</code>,
223-<code>Name.ARCH.raz</code> and <code>Name.raz</code> that exists, where
224-<code>OS-ARCH</code> is the target, for now only
225-<code>linux-x86_64</code>. So a module whose code depends on the machine
226-or the system comes in one file per target, and the modules that import
227-it don’t change. Machine code (section 8) and system calls belong in
228-such files.</p>
229-<p><strong>One module to a name.</strong> A program has one module of
230-each name, so the compiler reports an error, naming the files, if a
231-module it looks for has files in more than one of these directories,
232-rather than take the first: a <code>Buf.raz</code> beside a program
233-would otherwise stand in for the library’s <code>Buf</code> in every
234-module that imports it, the library’s own among them. A link is the
235-exception: a file that is a symbolic link to one of the module’s files
236-in a later directory chooses that file, so that a directory holding a
237-link to <code>lib/Sys.raz</code> builds a program over the C library’s
238-<code>Sys</code> on Linux too.</p>
239-<p><strong>Names are flat.</strong> The names of a program’s modules are
240-one space, with no packages or paths. So the names of the library’s
241-modules (section 11) are kept for it: a program or another library
242-doesn’t name a module of its own <code>Arena</code>, <code>Buf</code>,
243-<code>C</code>, <code>Files</code>, <code>Fmt</code>, <code>Heap</code>,
244-<code>List</code>, <code>Lock</code>, <code>Map</code>,
245-<code>Math</code>, <code>Mem</code>, <code>Opt</code>, <code>Out</code>,
246-<code>Rt</code>, <code>Sort</code>, <code>Str</code>, <code>Sys</code>
247-or <code>Thread</code>, nor any name the library takes later. The
248-modules of any other library share a prefix of their own, as an X11
249-library’s <code>Xauth</code> and <code>Xkeys</code> do, and a program
250-that wants a shorter name imports one:
251-<code>import Auth := Xauth;</code>.</p>
252-<p>The compiler holds every file of such a module to the same interface.
253-When it takes one of <code>Name.*.raz</code>, it also reads the
254-declarations of the others beside it, and of <code>Name.raz</code> if
255-there is one, and reports an error unless they all export the same
256-names, each the same kind of thing:</p>
100+<p>A procedure argument names a procedure, not a variable or an expression, and its signature, with the type arguments put in, must be the parameter’s. Inside the module, <code>hash(k)</code> calls it directly. Two imports make the same instance only if their types and their procedures are the same.</p>
101+<p><strong>Finding modules.</strong> The compiler looks for module <code>Name</code> in the main module’s directory, then in each directory given with <code>-I</code>, then in the <code>lib</code> directory beside the compiler. In each directory it takes the first of <code>Name.OS-ARCH.raz</code>, <code>Name.OS.raz</code>, <code>Name.ARCH.raz</code> and <code>Name.raz</code> that exists, where <code>OS-ARCH</code> is the target, for now only <code>linux-x86_64</code>. So a module whose code depends on the machine or the system comes in one file per target, and the modules that import it don’t change. Machine code (section 8) and system calls belong in such files.</p>
102+<p><strong>One module to a name.</strong> A program has one module of each name, so the compiler reports an error, naming the files, if a module it looks for has files in more than one of these directories, rather than take the first: a <code>Buf.raz</code> beside a program would otherwise stand in for the library’s <code>Buf</code> in every module that imports it, the library’s own among them. A link is the exception: a file that is a symbolic link to one of the module’s files in a later directory chooses that file, so that a directory holding a link to <code>lib/Sys.raz</code> builds a program over the C library’s <code>Sys</code> on Linux too.</p>
103+<p><strong>Names are flat.</strong> The names of a program’s modules are one space, with no packages or paths. So the names of the library’s modules (section 11) are kept for it: a program or another library doesn’t name a module of its own <code>Arena</code>, <code>Buf</code>, <code>C</code>, <code>Files</code>, <code>Fmt</code>, <code>Heap</code>, <code>List</code>, <code>Lock</code>, <code>Map</code>, <code>Math</code>, <code>Mem</code>, <code>Opt</code>, <code>Out</code>, <code>Rt</code>, <code>Sort</code>, <code>Str</code>, <code>Sys</code> or <code>Thread</code>, nor any name the library takes later. The modules of any other library share a prefix of their own, as an X11 library’s <code>Xauth</code> and <code>Xkeys</code> do, and a program that wants a shorter name imports one: <code>import Auth := Xauth;</code>.</p>
104+<p>The compiler holds every file of such a module to the same interface. When it takes one of <code>Name.*.raz</code>, it also reads the declarations of the others beside it, and of <code>Name.raz</code> if there is one, and reports an error unless they all export the same names, each the same kind of thing:</p>
257105 <ul>
258-<li>a constant of the same type (its value may differ: a system call
259-number, say);</li>
260-<li>a type of the same kind, and for a record or variant the same
261-exported fields and cases, with the same types (unexported fields, and
262-so the size and layout, may differ);</li>
106+<li>a constant of the same type (its value may differ: a system call number, say);</li>
107+<li>a type of the same kind, and for a record or variant the same exported fields and cases, with the same types (unexported fields, and so the size and layout, may differ);</li>
263108 <li>a variable of the same type;</li>
264109 <li>a procedure of the same signature.</li>
265110 </ul>
266-<p>Two types here are the same if they are built alike, a name in one
267-file standing for the same name in another.</p>
268-<p><strong>Module bodies.</strong> A module may end with
269-<code>begin</code> and statements, its body. Every module’s body runs
270-once, before the main module’s <code>main</code>: a module’s body runs
271-after the bodies of the modules it imports, in the order of its
272-<code>import</code>s, and once however many modules import it. Each
273-instance of a generic module has its body run once. Module variables are
274-zero before any body runs. <code>return;</code> ends a body early.</p>
275-<p><strong><code>link "libX11.so.6";</code></strong> names a shared
276-library to load at run time, for the <code>extern</code> declarations of
277-section 9. <strong><code>link static;</code></strong> says the module
278-needs a program without C (section 10): it makes its own system calls,
279-or its own threads, which the C library wouldn’t know about.</p>
280-<p><strong><code>check off;</code></strong>, after the links, leaves out
281-of the module’s own code the checks of indexes and slice bounds of
282-section 6.5, and that a slice of a pointer doesn’t run backwards
283-(section 6.4), for speed where the program is sure of them. An index out
284-of range there reads or writes whatever memory it reaches, and what
285-follows isn’t defined. Every other check stays, and the module’s callers
286-keep theirs. An instance of a generic module follows the generic
287-module’s own <code>check</code> line, not that of the module that made
288-it. <code>check</code> and <code>off</code> aren’t reserved words, as
289-<code>static</code> isn’t.</p>
111+<p>Two types here are the same if they are built alike, a name in one file standing for the same name in another.</p>
112+<p><strong>Module bodies.</strong> A module may end with <code>begin</code> and statements, its body. Every module’s body runs once, before the main module’s <code>main</code>: a module’s body runs after the bodies of the modules it imports, in the order of its <code>import</code>s, and once however many modules import it. Each instance of a generic module has its body run once. Module variables are zero before any body runs. <code>return;</code> ends a body early.</p>
113+<p><strong><code>link "libX11.so.6";</code></strong> names a shared library to load at run time, for the <code>extern</code> declarations of section 9. <strong><code>link static;</code></strong> says the module needs a program without C (section 10): it makes its own system calls, or its own threads, which the C library wouldn’t know about.</p>
114+<p><strong><code>check off;</code></strong>, after the links, leaves out of the module’s own code the checks of indexes and slice bounds of section 6.5, and that a slice of a pointer doesn’t run backwards (section 6.4), for speed where the program is sure of them. An index out of range there reads or writes whatever memory it reaches, and what follows isn’t defined. Every other check stays, and the module’s callers keep theirs. An instance of a generic module follows the generic module’s own <code>check</code> line, not that of the module that made it. <code>check</code> and <code>off</code> aren’t reserved words, as <code>static</code> isn’t.</p>
290115 <h1 id="declarations">4. Declarations</h1>
291116 <pre><code>Declaration = &quot;const&quot; { IdentDef [ &quot;:&quot; Type ] &quot;=&quot; Expr &quot;;&quot; }
292117 | &quot;type&quot; { IdentDef &quot;=&quot; Type &quot;;&quot; }
@@ -295,55 +120,20 @@
295120 | ExternDeclaration &quot;;&quot; .
296121 IdentDef = ident [ &quot;*&quot; ] .
297122 IdentList = IdentDef { &quot;,&quot; IdentDef } .</code></pre>
298-<p>A name must be declared before it is used, with two exceptions: the
299-base type of a pointer may name a type declared later in the same
300-<code>type</code> section (so that two records can point at each other),
301-and a procedure may be declared <code>forward</code> and defined later
302-(section 8).</p>
303-<p><strong>Constants</strong> are evaluated by the compiler. Their
304-expressions use only literals, other constants, operators, conversions,
305-<code>SIZE</code> and the <code>LEN</code> of arrays and strings. A
306-constant is an integer, a real, a <code>BOOL</code>, a name of an
307-enumeration, a set, a string, an array, a record or an
308-<code>ERROR</code>. A constant of an integer type wraps as the program
309-would: <code>U8(250) + 10</code> is 4. Dividing by zero in a constant is
310-an error, and so is dividing the smallest value of a signed type by -1,
311-with <code>div</code> or <code>mod</code>, which stops a program
312-(section 6.1). A string constant can be indexed and sliced as an array
313-of <code>U8</code> is, and its <code>LEN</code> is its length in bytes.
314-<code>+</code> joins two string constants into one:</p>
123+<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>
124+<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>
315125 <pre><code>const Text = &quot;the cat&quot;;
316126 Line = Text + &quot;\n&quot;;
317127 ...
318128 w := Text[4..7]; (* &quot;cat&quot; *)</code></pre>
319-<p>A constant with a type is an <code>ERROR</code> (section 5.8), an
320-array or a record, and the value of an array or record constant is a
321-literal (section 6.5) of constants. Its elements and fields are
322-integers, reals, <code>BOOL</code>s, enumerations, sets,
323-<code>ERROR</code>s, procedures, <code>nil</code>, a string for a
324-<code>[]U8</code>, an array constant for a slice of its element type,
325-and arrays and records of these; no variant and no other pointer:</p>
129+<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 for a slice of its element type, and arrays and records of these; no variant and no other pointer:</p>
326130 <pre><code>const Primes: [5]I64 = [2, 3, 5, 7, 11];
327131 type Rule = record class: []U8; tag: INT; float: BOOL; end;
328132 const Rules: [2]Rule = [{class: &quot;firefox&quot;, tag: 2}, {class: &quot;mpv&quot;, float: true}];
329133 ...
330134 p := Primes[i];</code></pre>
331-<p>It is used as a variable of that type is, but can’t be changed: an
332-array constant can be indexed and sliced and its <code>LEN</code> is
333-<code>n</code>, a record constant’s fields can be read, and either can
334-be assigned, compared as its type allows, and passed. Its parts are
335-constant as a string’s bytes are (section 5.10). A part of it isn’t a
336-constant, even at a constant index.</p>
337-<p><strong>Variables</strong> of a module live as long as the program;
338-variables of a procedure live as long as its call. Both start at zero:
339-every byte of them is zero. So a number starts as <code>0</code>
340-(<code>0.0</code> for <code>F32</code> and <code>F64</code>), a
341-<code>BOOL</code> as <code>false</code>, a pointer, procedure or
342-<code>ERROR</code> as <code>nil</code>, a slice as the empty slice
343-(<code>ptr</code> is <code>nil</code>, <code>len</code> is 0), a variant
344-as its first case with its fields zero, a set as the empty set, and an
345-enumeration as its first name. No variable is ever read before it has a
346-value.</p>
135+<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>
136+<p><strong>Variables</strong> of a module live as long as the program; variables of a procedure live as long as its call. Both start at zero: every byte of them is zero. So a number starts as <code>0</code> (<code>0.0</code> for <code>F32</code> and <code>F64</code>), a <code>BOOL</code> as <code>false</code>, a pointer, procedure or <code>ERROR</code> as <code>nil</code>, a slice as the empty slice (<code>ptr</code> is <code>nil</code>, <code>len</code> is 0), a variant as its first case with its fields zero, a set as the empty set, and an enumeration as its first name. No variable is ever read before it has a value.</p>
347137 <h1 id="types">5. Types</h1>
348138 <pre><code>Type = QualIdent
349139 | &quot;[&quot; Expr &quot;]&quot; Type (* array *)
@@ -359,116 +149,68 @@
359149 QualIdent = [ ident &quot;.&quot; ] ident .</code></pre>
360150 <h2 id="basic-types">5.1 Basic types</h2>
361151 <table>
362-<colgroup>
363-<col style="width: 33%" />
364-<col style="width: 33%" />
365-<col style="width: 33%" />
366-</colgroup>
367152 <thead>
368-<tr class="header">
153+<tr>
369154 <th>Type</th>
370155 <th>Size</th>
371156 <th>Values</th>
372157 </tr>
373158 </thead>
374159 <tbody>
375-<tr class="odd">
376-<td><code>I8</code> <code>I16</code> <code>I32</code>
377-<code>I64</code></td>
160+<tr>
161+<td><code>I8</code> <code>I16</code> <code>I32</code> <code>I64</code></td>
378162 <td>1, 2, 4, 8</td>
379163 <td>signed integers, two’s complement</td>
380164 </tr>
381-<tr class="even">
165+<tr>
382166 <td><code>INT</code></td>
383167 <td>an address’s: 8 on x86-64</td>
384168 <td>signed, as big as an address</td>
385169 </tr>
386-<tr class="odd">
170+<tr>
387171 <td><code>UINT</code></td>
388172 <td>an address’s</td>
389173 <td>unsigned, as big as an address</td>
390174 </tr>
391-<tr class="even">
392-<td><code>U8</code> <code>U16</code> <code>U32</code>
393-<code>U64</code></td>
175+<tr>
176+<td><code>U8</code> <code>U16</code> <code>U32</code> <code>U64</code></td>
394177 <td>1, 2, 4, 8</td>
395178 <td>unsigned integers</td>
396179 </tr>
397-<tr class="odd">
180+<tr>
398181 <td><code>BOOL</code></td>
399182 <td>1</td>
400183 <td><code>false</code> (0), <code>true</code> (1)</td>
401184 </tr>
402-<tr class="even">
185+<tr>
403186 <td><code>F32</code></td>
404187 <td>4</td>
405188 <td>IEEE 754 single precision</td>
406189 </tr>
407-<tr class="odd">
190+<tr>
408191 <td><code>F64</code></td>
409192 <td>8</td>
410193 <td>IEEE 754 double precision</td>
411194 </tr>
412195 </tbody>
413196 </table>
414-<p><code>INT</code> is the everyday integer: lengths, indexes and sizes
415-are <code>INT</code>s. It is as big as an address, so it is the integer
416-a pointer converts to (section 6.7), and a word the atomic built-ins
417-work on (section 6.8). <code>INT</code> and <code>I64</code> are two
418-types, even where they have the same size: an <code>INT</code> goes
419-silently into an <code>I64</code> (section 5.10), but the two don’t mix
420-in an expression (section 6.1), and an <code>I64</code> becomes an
421-<code>INT</code> only by <code>INT(x)</code>, which may drop bits on a
422-smaller target. A type bigger than the largest <code>INT</code> in bytes
423-is an error.</p>
424-<p><code>F32</code> and <code>F64</code> exist only on a target that has
425-reals (appendix A). On one that hasn’t, a real literal, and a use of
426-<code>F32</code>, <code>F64</code> or of a name whose type is made of
427-them, is an error; a declaration that no used code names isn’t, so a
428-module like <code>Fmt</code> keeps one interface on every target.</p>
429-<p>Each is aligned as the target’s C aligns it: to its size on x86-64.
430-So are <code>ERROR</code> (section 5.8), pointers and procedures, each
431-as big as an address; a slice is aligned as an address is.</p>
197+<p><code>INT</code> is the everyday integer: lengths, indexes and sizes are <code>INT</code>s. It is as big as an address, so it is the integer a pointer converts to (section 6.7), and a word the atomic built-ins work on (section 6.8). <code>INT</code> and <code>I64</code> are two types, even where they have the same size: an <code>INT</code> goes silently into an <code>I64</code> (section 5.10), but the two don’t mix in an expression (section 6.1), and an <code>I64</code> becomes an <code>INT</code> only by <code>INT(x)</code>, which may drop bits on a smaller target. A type bigger than the largest <code>INT</code> in bytes is an error.</p>
198+<p><code>F32</code> and <code>F64</code> exist only on a target that has reals (appendix A). On one that hasn’t, a real literal, and a use of <code>F32</code>, <code>F64</code> or of a name whose type is made of them, is an error; a declaration that no used code names isn’t, so a module like <code>Fmt</code> keeps one interface on every target.</p>
199+<p>Each is aligned as the target’s C aligns it: to its size on x86-64. So are <code>ERROR</code> (section 5.8), pointers and procedures, each as big as an address; a slice is aligned as an address is.</p>
432200 <h2 id="arrays">5.2 Arrays</h2>
433-<p><code>[n]T</code> is <code>n</code> elements of type <code>T</code>,
434-one after another. <code>n</code> is a constant greater than zero.
435-Arrays are values: assigning one copies it.</p>
201+<p><code>[n]T</code> is <code>n</code> elements of type <code>T</code>, one after another. <code>n</code> is a constant greater than zero. Arrays are values: assigning one copies it.</p>
436202 <h2 id="slices">5.3 Slices</h2>
437-<p><code>[]T</code> is a view of elements that live elsewhere: a pointer
438-to the first and a count, two addresses’ worth, 16 bytes on x86-64.</p>
203+<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>
439204 <pre><code>Slice = record ptr: ^T; len: INT; end; (* its layout *)</code></pre>
440-<p>A slice is made from an array (<code>a[2..5]</code>, or an array used
441-where a slice is wanted), from another slice, or from a pointer
442-(<code>p[0..n]</code>). It doesn’t own what it points at.</p>
205+<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>
443206 <h2 id="pointers">5.4 Pointers</h2>
444-<p><code>^T</code> is the address of a <code>T</code>, as big as an
445-<code>INT</code>. <code>nil</code> is the pointer to nothing.</p>
446-<p><code>^VOLATILE T</code> is the address of a <code>T</code> that
447-something besides the program may read or change: a device register,
448-memory shared with another process. Section 7.6 says what that
449-promises.</p>
207+<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>
208+<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>
450209 <h2 id="records">5.5 Records</h2>
451210 <pre><code>type Cell = record ch: U8; attr: U8; end;</code></pre>
452-<p>Fields are laid out in order as C lays them out: each at the next
453-multiple of its own alignment, and the whole record padded to a multiple
454-of its largest alignment. A record declared like a C struct has the same
455-layout as that struct. A record may have no fields; its size is then
456-0.</p>
457-<p>A <code>packed record</code> has no padding: each field starts at the
458-byte after the field before it, and the record’s alignment is 1. So a
459-field of a packed record may sit at any address. It is read and written
460-like any other, on every target, even one whose machine can’t reach a
461-misaligned word in one access: the compiled code reaches it in parts
462-there. But a field of a packed record whose type is aligned to more than
463-1 byte, and anything inside it, has no address: <code>ADR</code> of it,
464-a <code>var</code> parameter of it and a slice of it are errors. Nor can
465-it be reached through a <code>^VOLATILE</code> pointer, since a
466-misaligned access can’t be promised as one access (section 7.6). Its
467-value can be copied out and back in.</p>
468-<p>The bytes of a value of more than one byte are in the target’s order
469-(appendix A). A file or a message in an order of its own is read and
470-written a byte at a time, as <code>Str.le</code>, <code>Str.be</code>,
471-<code>Str.putLE</code> and <code>Str.putBE</code> do (section 11).</p>
211+<p>Fields are laid out in order as C lays them out: each at the next multiple of its own alignment, and the whole record padded to a multiple of its largest alignment. A record declared like a C struct has the same layout as that struct. A record may have no fields; its size is then 0.</p>
212+<p>A <code>packed record</code> has no padding: each field starts at the byte after the field before it, and the record’s alignment is 1. So a field of a packed record may sit at any address. It is read and written like any other, on every target, even one whose machine can’t reach a misaligned word in one access: the compiled code reaches it in parts there. But a field of a packed record whose type is aligned to more than 1 byte, and anything inside it, has no address: <code>ADR</code> of it, a <code>var</code> parameter of it and a slice of it are errors. Nor can it be reached through a <code>^VOLATILE</code> pointer, since a misaligned access can’t be promised as one access (section 7.6). Its value can be copied out and back in.</p>
213+<p>The bytes of a value of more than one byte are in the target’s order (appendix A). A file or a message in an order of its own is read and written a byte at a time, as <code>Str.le</code>, <code>Str.be</code>, <code>Str.putLE</code> and <code>Str.putBE</code> do (section 11).</p>
472214 <h2 id="variants">5.6 Variants</h2>
473215 <p>A variant holds one of several cases, each with its own fields:</p>
474216 <pre><code>type
@@ -477,110 +219,40 @@
477219 rect(w, h: F64);
478220 dot;
479221 end;</code></pre>
480-<p>The case names are declared in the scope around the type, so
481-<code>circle</code> can be used directly, and as
482-<code>Shapes.circle</code> from another module if <code>Shape</code> is
483-exported. A case with fields is built by calling it like a procedure,
484-<code>circle(2.0)</code>; a case without fields is just
485-<code>dot</code>. The only way to read the fields is <code>match</code>
486-(section 7.4).</p>
487-<p>Layout: an <code>INT</code> tag (0 for the first case, 1 for the
488-second, and so on), then the space for the fields. Each case’s fields
489-are laid out in that space as a record’s would be, after the tag, and
490-the cases share it, so the variant is as big as its largest case needs,
491-padded to its alignment, the largest of an <code>INT</code>‘s and its
492-fields’. <code>variant a(x: U8); b(y: I64; z: U8); end</code> is 24
493-bytes on x86-64. A variant that starts at zero therefore holds its first
494-case.</p>
222+<p>The case names are declared in the scope around the type, so <code>circle</code> can be used directly, and as <code>Shapes.circle</code> from another module if <code>Shape</code> is exported. A case with fields is built by calling it like a procedure, <code>circle(2.0)</code>; a case without fields is just <code>dot</code>. The only way to read the fields is <code>match</code> (section 7.4).</p>
223+<p>Layout: an <code>INT</code> tag (0 for the first case, 1 for the second, and so on), then the space for the fields. Each case’s fields are laid out in that space as a record’s would be, after the tag, and the cases share it, so the variant is as big as its largest case needs, padded to its alignment, the largest of an <code>INT</code>‘s and its fields’. <code>variant a(x: U8); b(y: I64; z: U8); end</code> is 24 bytes on x86-64. A variant that starts at zero therefore holds its first case.</p>
495224 <h2 id="enumerations-and-sets">5.7 Enumerations and sets</h2>
496225 <pre><code>type
497226 Color* = (red, green, blue);
498227 Colors* = set of Color;</code></pre>
499-<p>An enumeration is a list of names, in order. Like the cases of a
500-variant, the names are declared in the scope around the type. An
501-enumeration has at most 256 names and takes 1 byte; the first name is 0,
502-the next 1, and so on.</p>
503-<p><code>set of E</code>, for an enumeration <code>E</code> of at most
504-64 names, holds any choice of <code>E</code>’s names: bit <code>i</code>
505-stands for the name at position <code>i</code>. It takes the smallest of
506-1, 2, 4 and 8 bytes that has a bit for each name, so a set can stand for
507-a C flags word.</p>
228+<p>An enumeration is a list of names, in order. Like the cases of a variant, the names are declared in the scope around the type. An enumeration has at most 256 names and takes 1 byte; the first name is 0, the next 1, and so on.</p>
229+<p><code>set of E</code>, for an enumeration <code>E</code> of at most 64 names, holds any choice of <code>E</code>’s names: bit <code>i</code> stands for the name at position <code>i</code>. It takes the smallest of 1, 2, 4 and 8 bytes that has a bit for each name, so a set can stand for a C flags word.</p>
508230 <h2 id="errors">5.8 Errors</h2>
509231 <pre><code>const NotFound*: ERROR = &quot;not found&quot;;</code></pre>
510-<p><code>ERROR</code> is a basic type as big as an address. A value of
511-it is made only by a constant declared as above, and each such
512-declaration makes an error different from every other, whatever its
513-message: two modules that both declare <code>"not found"</code> have two
514-different errors. A generic module makes its errors once per instance.
515-<code>nil</code> is no error.</p>
516-<p>Errors compare with <code>=</code> and <code>#</code> only, by which
517-declaration made them, never by their message. <code>MSG(e)</code> is
518-the message, a <code>[]U8</code>; <code>MSG(nil)</code> is
519-<code>""</code>.</p>
232+<p><code>ERROR</code> is a basic type as big as an address. A value of it is made only by a constant declared as above, and each such declaration makes an error different from every other, whatever its message: two modules that both declare <code>"not found"</code> have two different errors. A generic module makes its errors once per instance. <code>nil</code> is no error.</p>
233+<p>Errors compare with <code>=</code> and <code>#</code> only, by which declaration made them, never by their message. <code>MSG(e)</code> is the message, a <code>[]U8</code>; <code>MSG(nil)</code> is <code>""</code>.</p>
520234 <pre><code>proc find*(key: I64): (^Node, ERROR);
521235 ...
522236 n, err := Table.find(7);
523237 if err = Table.NotFound then ... end;</code></pre>
524238 <h2 id="procedure-types">5.9 Procedure types</h2>
525239 <pre><code>type Compare = proc(a, b: I64): BOOL;</code></pre>
526-<p>A value of a procedure type is the address of a procedure with that
527-signature, as big as an address, or <code>nil</code>. Two signatures are
528-alike when their parameters have the same types, each <code>var</code>
529-or not alike, in order, and their results are the same types; the
530-parameters’ names don’t matter.</p>
240+<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>
531241 <h2 id="same-and-assignable">5.10 Same and assignable</h2>
532-<p>Two named types are the same only if they are the same declaration.
533-Two anonymous pointer, array, slice, set or procedure types are the same
534-if they are built alike: <code>^I64</code> is <code>^I64</code> wherever
535-it is written. A record, variant or enumeration, though, is a type of
536-its own wherever it is written, named or not: two
537-<code>record x: I64; end</code> are two types. A named and an anonymous
538-type are the same if the named one is built like the anonymous one, so
539-that <code>p := ADR(n)</code> works for <code>p: NodePtr</code> with
540-<code>type NodePtr = ^Node</code>. Sameness doesn’t pass through the
541-anonymous type: with <code>type P1 = ^Node; P2 = ^Node;</code>, each of
542-<code>P1</code> and <code>P2</code> is the same as <code>^Node</code>,
543-but they are two declarations, so not the same as each other.</p>
544-<p>A type declared with only a name on the right,
545-<code>type Count = I64;</code>, is another name for that type, not a new
546-one.</p>
547-<p>A value of type <code>A</code> can be assigned to a variable of type
548-<code>B</code> (and passed to a parameter of type <code>B</code>, and
549-returned as a <code>B</code>) if they are the same type, or if:</p>
242+<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>
243+<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>
244+<p>A value of type <code>A</code> can be assigned to a variable of type <code>B</code> (and passed to a parameter of type <code>B</code>, and returned as a <code>B</code>) if they are the same type, or if:</p>
550245 <ul>
551-<li><code>A</code> is an integer constant whose value fits in the
552-integer type <code>B</code>;</li>
553-<li><code>A</code> is <code>nil</code> and <code>B</code> is a pointer,
554-procedure or <code>ERROR</code> type;</li>
555-<li><code>A</code> is <code>^T</code> and <code>B</code> is
556-<code>^VOLATILE T</code>;</li>
557-<li><code>A</code> is <code>[n]T</code> and <code>B</code> is
558-<code>[]T</code>;</li>
559-<li><code>A</code> is a string literal and <code>B</code> is
560-<code>[]U8</code>, <code>^U8</code> (a pointer to the bytes followed by
561-a zero byte, as C wants), or <code>[n]U8</code> with <code>n</code> at
562-least the string’s length (the rest is zero);</li>
563-<li><code>A</code> is a procedure and <code>B</code> a procedure type
564-with the same signature;</li>
565-<li><code>A</code> is <code>INT</code> and <code>B</code> is
566-<code>I64</code>, or <code>A</code> is <code>UINT</code> and
567-<code>B</code> is <code>U64</code>, which loses nothing on any
568-target.</li>
246+<li><code>A</code> is an integer constant whose value fits in the integer type <code>B</code>;</li>
247+<li><code>A</code> is <code>nil</code> and <code>B</code> is a pointer, procedure or <code>ERROR</code> type;</li>
248+<li><code>A</code> is <code>^T</code> and <code>B</code> is <code>^VOLATILE T</code>;</li>
249+<li><code>A</code> is <code>[n]T</code> and <code>B</code> is <code>[]T</code>;</li>
250+<li><code>A</code> is a string literal and <code>B</code> is <code>[]U8</code>, <code>^U8</code> (a pointer to the bytes followed by a zero byte, as C wants), or <code>[n]U8</code> with <code>n</code> at least the string’s length (the rest is zero);</li>
251+<li><code>A</code> is a procedure and <code>B</code> a procedure type with the same signature;</li>
252+<li><code>A</code> is <code>INT</code> and <code>B</code> is <code>I64</code>, or <code>A</code> is <code>UINT</code> and <code>B</code> is <code>U64</code>, which loses nothing on any target.</li>
569253 </ul>
570-<p>A string’s bytes are constant. A <code>[]U8</code> or
571-<code>^U8</code> made from a string literal, or a slice of a string
572-constant, points at them, and writing through it isn’t defined: on a
573-target with read-only memory, it may stop the program as a bad address
574-(section 10). A <code>[n]U8</code> made from a string is a copy, the
575-program’s to change.</p>
576-<p>Nothing else converts silently. In particular, there is no other
577-conversion between integer types, between integers and reals, or between
578-<code>F32</code> and <code>F64</code>, without a written conversion
579-(section 6.7). Results passed on whole need the same types exactly: in
580-<code>a, b := f(x)</code> and in <code>return f(x)</code>, an
581-<code>INT</code> result doesn’t pass up as an <code>I64</code>.
582-Elsewhere, <code>return n, n</code> included, an <code>INT</code> widens
583-as above.</p>
254+<p>A string’s bytes are constant. A <code>[]U8</code> or <code>^U8</code> made from a string literal, or a slice of a string constant, points at them, and writing through it isn’t defined: on a target with read-only memory, it may stop the program as a bad address (section 10). A <code>[n]U8</code> made from a string is a copy, the program’s to change.</p>
255+<p>Nothing else converts silently. In particular, there is no other conversion between integer types, between integers and reals, or between <code>F32</code> and <code>F64</code>, without a written conversion (section 6.7). Results passed on whole need the same types exactly: in <code>a, b := f(x)</code> and in <code>return f(x)</code>, an <code>INT</code> result doesn’t pass up as an <code>I64</code>. Elsewhere, <code>return n, n</code> included, an <code>INT</code> widens as above.</p>
584256 <h1 id="expressions">6. Expressions</h1>
585257 <pre><code>Expr = Conjunct { &quot;or&quot; Conjunct } .
586258 Conjunct = Relation { &quot;and&quot; Relation } .
@@ -599,344 +271,189 @@
599271 Designator = QualIdent { Selector } .
600272 Selector = &quot;.&quot; ident | &quot;^&quot; | &quot;[&quot; Expr [ &quot;..&quot; Expr ] &quot;]&quot;
601273 | &quot;(&quot; [ Expr { &quot;,&quot; Expr } ] &quot;)&quot; .</code></pre>
602-<p>The operators bind in the order of the grammar: <code>not</code> and
603-<code>~</code> most tightly, then the multiplying operators, then the
604-adding ones, then the relations, then <code>and</code>, then
605-<code>or</code>. So <code>a + b * c = d</code> is
606-<code>(a + (b * c)) = d</code>, <code>x &amp; 0FH = 0</code> is
607-<code>(x &amp; 0FH) = 0</code>, and
608-<code>i &lt; n and a[i] # 0 or done</code> is
609-<code>((i &lt; n) and (a[i] # 0)) or done</code>. A unary minus applies
610-to the first term: <code>-a * b</code> is <code>-(a * b)</code>.</p>
611-<p><code>and</code>, <code>or</code> and <code>not</code> are for
612-<code>BOOL</code>s only; <code>&amp;</code>, <code>|</code>,
613-<code>xor</code> and <code>~</code> are for integers only.</p>
614-<p>A pointer to a record isn’t the record: its fields are
615-<code>p^.f</code>, never <code>p.f</code>, and the elements of a pointer
616-to an array are <code>p^[i]</code>. A statement starts with a name, so
617-<code>^T(x)^ := v</code> isn’t one.</p>
274+<p>The operators bind in the order of the grammar: <code>not</code> and <code>~</code> most tightly, then the multiplying operators, then the adding ones, then the relations, then <code>and</code>, then <code>or</code>. So <code>a + b * c = d</code> is <code>(a + (b * c)) = d</code>, <code>x &amp; 0FH = 0</code> is <code>(x &amp; 0FH) = 0</code>, and <code>i &lt; n and a[i] # 0 or done</code> is <code>((i &lt; n) and (a[i] # 0)) or done</code>. A unary minus applies to the first term: <code>-a * b</code> is <code>-(a * b)</code>.</p>
275+<p><code>and</code>, <code>or</code> and <code>not</code> are for <code>BOOL</code>s only; <code>&amp;</code>, <code>|</code>, <code>xor</code> and <code>~</code> are for integers only.</p>
276+<p>A pointer to a record isn’t the record: its fields are <code>p^.f</code>, never <code>p.f</code>, and the elements of a pointer to an array are <code>p^[i]</code>. A statement starts with a name, so <code>^T(x)^ := v</code> isn’t one.</p>
618277 <h2 id="integers">6.1 Integers</h2>
619-<p>Both operands of <code>+ - * div mod &amp; | xor</code>, and of a
620-relation, have the same integer type, or one is an untyped constant that
621-takes the other’s type, which it must fit. So do <code>v</code> and
622-<code>k</code> in <code>INC(v, k)</code> and <code>DEC(v, k)</code>. The
623-result has that type and wraps around at its width: in <code>U8</code>,
624-<code>200 + 100</code> is <code>44</code>. A unary minus wraps too: for
625-<code>x</code> of an unsigned type, <code>-x</code> is
626-<code>0 - x</code>. Two integer types are never mixed, whatever their
627-sizes: with <code>i: I64</code>, <code>i &lt; LEN(s)</code> is an error,
628-and <code>i</code> should be an <code>INT</code>.</p>
629-<p>Where the report asks for an integer and names no type, as an index,
630-a slice’s bound, a shift’s count, a pointer’s offset <code>i</code> in
631-<code>p + i</code>, or a conversion’s operand, any integer type will do,
632-and its value is taken. On a target whose <code>INT</code> is narrower,
633-a pointer’s offset is cut to an <code>INT</code>.</p>
634-<p><code>SIZE(T)</code>, and <code>LEN</code> of an array or a string
635-constant, are untyped constants, like a literal.</p>
636-<p><code>div</code> rounds toward zero and <code>mod</code> takes the
637-sign of the dividend, as in C: <code>-7 div 2</code> is <code>-3</code>,
638-<code>-7 mod 2</code> is <code>-1</code>. Dividing by zero, and dividing
639-the smallest value of a signed type by <code>-1</code>, stop the program
640-(<code>SIGFPE</code>), whatever the type and the target.</p>
641-<p><code>&amp;</code> (and), <code>|</code> (or), <code>xor</code> and
642-<code>~</code> (not) work on every bit. <code>x shl n</code> and
643-<code>x shr n</code> shift by <code>n</code> modulo the width of
644-<code>x</code>’s type, in bits: for <code>x: U8</code>,
645-<code>x shl 9</code> is <code>x shl 1</code>. <code>shr</code> brings in
646-copies of the sign bit for signed types and zeros for unsigned ones.
647-<code>n</code> may be of any integer type. The result has
648-<code>x</code>’s type, cut to its width: in <code>U8</code>,
649-<code>0C0H shl 1</code> is <code>80H</code>.</p>
278+<p>Both operands of <code>+ - * div mod &amp; | xor</code>, and of a relation, have the same integer type, or one is an untyped constant that takes the other’s type, which it must fit. So do <code>v</code> and <code>k</code> in <code>INC(v, k)</code> and <code>DEC(v, k)</code>. The result has that type and wraps around at its width: in <code>U8</code>, <code>200 + 100</code> is <code>44</code>. A unary minus wraps too: for <code>x</code> of an unsigned type, <code>-x</code> is <code>0 - x</code>. Two integer types are never mixed, whatever their sizes: with <code>i: I64</code>, <code>i &lt; LEN(s)</code> is an error, and <code>i</code> should be an <code>INT</code>.</p>
279+<p>Where the report asks for an integer and names no type, as an index, a slice’s bound, a shift’s count, a pointer’s offset <code>i</code> in <code>p + i</code>, or a conversion’s operand, any integer type will do, and its value is taken. On a target whose <code>INT</code> is narrower, a pointer’s offset is cut to an <code>INT</code>.</p>
280+<p><code>SIZE(T)</code>, and <code>LEN</code> of an array or a string constant, are untyped constants, like a literal.</p>
281+<p><code>div</code> rounds toward zero and <code>mod</code> takes the sign of the dividend, as in C: <code>-7 div 2</code> is <code>-3</code>, <code>-7 mod 2</code> is <code>-1</code>. Dividing by zero, and dividing the smallest value of a signed type by <code>-1</code>, stop the program (<code>SIGFPE</code>), whatever the type and the target.</p>
282+<p><code>&amp;</code> (and), <code>|</code> (or), <code>xor</code> and <code>~</code> (not) work on every bit. <code>x shl n</code> and <code>x shr n</code> shift by <code>n</code> modulo the width of <code>x</code>’s type, in bits: for <code>x: U8</code>, <code>x shl 9</code> is <code>x shl 1</code>. <code>shr</code> brings in copies of the sign bit for signed types and zeros for unsigned ones. <code>n</code> may be of any integer type. The result has <code>x</code>’s type, cut to its width: in <code>U8</code>, <code>0C0H shl 1</code> is <code>80H</code>.</p>
650283 <p>Relations compare as signed or unsigned according to the type.</p>
651284 <h2 id="booleans">6.2 Booleans</h2>
652-<p><code>and</code> and <code>or</code> evaluate their right operand
653-only when it decides the result. <code>not</code> negates, and
654-<code>=</code> and <code>#</code> compare; <code>#</code> is
655-“different”.</p>
285+<p><code>and</code> and <code>or</code> evaluate their right operand only when it decides the result. <code>not</code> negates, and <code>=</code> and <code>#</code> compare; <code>#</code> is “different”.</p>
656286 <h2 id="reals">6.3 Reals</h2>
657-<p><code>+ - * /</code> and the relations work on <code>F32</code> and
658-on <code>F64</code>. Both operands have the same type, or one is a real
659-constant, which takes the other’s type (section 2). The result has that
660-type: <code>F32</code> arithmetic is done in single precision, rounded
661-at each step as C rounds <code>float</code>. A constant expression of
662-reals is evaluated in double precision, then rounded once to the type it
663-takes.</p>
664-<p>Relations are IEEE 754’s: a NaN is equal to nothing, itself included,
665-so for a NaN <code>x</code>, <code>x # x</code> is true and every other
666-relation with it is false. Dividing by zero gives an infinity or a NaN;
667-arithmetic on reals never stops the program.</p>
287+<p><code>+ - * /</code> and the relations work on <code>F32</code> and on <code>F64</code>. Both operands have the same type, or one is a real constant, which takes the other’s type (section 2). The result has that type: <code>F32</code> arithmetic is done in single precision, rounded at each step as C rounds <code>float</code>. A constant expression of reals is evaluated in double precision, then rounded once to the type it takes.</p>
288+<p>Relations are IEEE 754’s: a NaN is equal to nothing, itself included, so for a NaN <code>x</code>, <code>x # x</code> is true and every other relation with it is false. Dividing by zero gives an infinity or a NaN; arithmetic on reals never stops the program.</p>
668289 <h2 id="pointers-1">6.4 Pointers</h2>
669290 <ul>
670291 <li><code>p^</code> is the variable <code>p</code> points at.</li>
671-<li><code>p + i</code> and <code>p - i</code>, with <code>i</code> an
672-integer, move <code>p</code> by <code>i</code> elements: by
673-<code>i * SIZE(T)</code> bytes for <code>p: ^T</code>.</li>
674-<li><code>p - q</code>, with both of the same pointer type, is the
675-number of elements between them, an <code>INT</code>.</li>
676-<li><code>p[i]</code> is <code>(p + i)^</code>. <code>p[lo..hi]</code>
677-is the slice of the <code>hi - lo</code> elements from
678-<code>p + lo</code>. Neither is checked against a length, which a
679-pointer doesn’t have, but a slice of a pointer that runs backwards,
680-<code>hi &lt; lo</code>, is a failed check (section 6.5). A pointer to
681-an array isn’t indexed this way, since a step would be a whole array:
682-its elements are <code>p^[i]</code>.</li>
683-<li>Pointers compare with <code>= # &lt; &lt;= &gt; &gt;=</code> as
684-unsigned addresses. Procedure values compare with <code>=</code> and
685-<code>#</code> only.</li>
292+<li><code>p + i</code> and <code>p - i</code>, with <code>i</code> an integer, move <code>p</code> by <code>i</code> elements: by <code>i * SIZE(T)</code> bytes for <code>p: ^T</code>.</li>
293+<li><code>p - q</code>, with both of the same pointer type, is the number of elements between them, an <code>INT</code>.</li>
294+<li><code>p[i]</code> is <code>(p + i)^</code>. <code>p[lo..hi]</code> is the slice of the <code>hi - lo</code> elements from <code>p + lo</code>. Neither is checked against a length, which a pointer doesn’t have, but a slice of a pointer that runs backwards, <code>hi &lt; lo</code>, is a failed check (section 6.5). A pointer to an array isn’t indexed this way, since a step would be a whole array: its elements are <code>p^[i]</code>.</li>
295+<li>Pointers compare with <code>= # &lt; &lt;= &gt; &gt;=</code> as unsigned addresses. Procedure values compare with <code>=</code> and <code>#</code> only.</li>
686296 </ul>
687297 <h2 id="arrays-and-slices">6.5 Arrays and slices</h2>
688-<p><code>a[i]</code> is an element of an array or slice, and
689-<code>a[lo..hi]</code> is the slice of the elements from <code>lo</code>
690-up to but not including <code>hi</code>. Both are checked:
691-<code>i</code> must be below the length, and
692-<code>0 &lt;= lo &lt;= hi &lt;= length</code>. A check that fails prints
693-to standard error where it is, as file, line and column, and what
694-failed, with the values involved
695-(<code>index 7 is out of range for a length of 5</code>), and stops the
696-program with status 2. An index or a bound may be of any integer type,
697-and is checked by its value, whatever its type: a negative
698-<code>I8</code>, or a <code>U64</code> past the length, fails like any
699-other. A module that says <code>check off;</code> (section 3) leaves
700-these checks out of its code.</p>
701-<p><strong>Literals.</strong> <code>[e1, e2, ...]</code> builds an
702-array, and <code>{f: e, g: e, ...}</code> a record, where the type it
703-must have is known: assigned to a variable, passed to a parameter,
704-returned, compared with a value of that type, or an element of a bigger
705-literal. The elements must be assignable to the element type, and an
706-array literal for <code>[n]T</code> has exactly <code>n</code> of them.
707-A record literal names its fields, in any order, each at most once; the
708-fields it leaves out are zero, so <code>{}</code> is the record with
709-every field zero. An array literal used as a slice is a hidden variable
710-of the procedure, and lives as long as its call.</p>
298+<p><code>a[i]</code> is an element of an array or slice, and <code>a[lo..hi]</code> is the slice of the elements from <code>lo</code> up to but not including <code>hi</code>. Both are checked: <code>i</code> must be below the length, and <code>0 &lt;= lo &lt;= hi &lt;= length</code>. A check that fails prints to standard error where it is, as file, line and column, and what failed, with the values involved (<code>index 7 is out of range for a length of 5</code>), and stops the program with status 2. An index or a bound may be of any integer type, and is checked by its value, whatever its type: a negative <code>I8</code>, or a <code>U64</code> past the length, fails like any other. A module that says <code>check off;</code> (section 3) leaves these checks out of its code.</p>
299+<p><strong>Literals.</strong> <code>[e1, e2, ...]</code> builds an array, and <code>{f: e, g: e, ...}</code> a record, where the type it must have is known: assigned to a variable, passed to a parameter, returned, compared with a value of that type, or an element of a bigger literal. The elements must be assignable to the element type, and an array literal for <code>[n]T</code> has exactly <code>n</code> of them. A record literal names its fields, in any order, each at most once; the fields it leaves out are zero, so <code>{}</code> is the record with every field zero. An array literal used as a slice is a hidden variable of the procedure, and lives as long as its call.</p>
711300 <pre><code>c := {ch: &#39;A&#39;, attr: 7};
712301 Fmt.print(&quot;{} of {}\n&quot;, [Fmt.int(n), Fmt.int(m)]);</code></pre>
713-<p><strong>Arrays and strings compare.</strong> Two operands that are
714-each a <code>[]T</code> or a <code>[n]T</code>, of the same element type
715-<code>T</code>, are <code>=</code> when they have the same length and
716-the same elements, and <code>#</code> otherwise, where <code>T</code> is
717-an integer type, <code>BOOL</code>, an enumeration, a set or a pointer
718-type. A string literal compares as a <code>[]U8</code>. The comparison
719-is code of its own where it stands, a check of the lengths and then of
720-the bytes, not a call.</p>
721-<p>Arrays of reals don’t compare this way, since <code>-0.0 = 0.0</code>
722-and a NaN is equal to nothing, though their bytes say otherwise; nor do
723-arrays of records, variants or procedures, nor records and variants
724-themselves. Write a loop. Ordering strings is the library’s
725-<code>Str.cmp</code>.</p>
302+<p><strong>Arrays and strings compare.</strong> Two operands that are each a <code>[]T</code> or a <code>[n]T</code>, of the same element type <code>T</code>, are <code>=</code> when they have the same length and the same elements, and <code>#</code> otherwise, where <code>T</code> is an integer type, <code>BOOL</code>, an enumeration, a set or a pointer type. A string literal compares as a <code>[]U8</code>. The comparison is code of its own where it stands, a check of the lengths and then of the bytes, not a call.</p>
303+<p>Arrays of reals don’t compare this way, since <code>-0.0 = 0.0</code> and a NaN is equal to nothing, though their bytes say otherwise; nor do arrays of records, variants or procedures, nor records and variants themselves. Write a loop. Ordering strings is the library’s <code>Str.cmp</code>.</p>
726304 <h2 id="enumerations-and-sets-1">6.6 Enumerations and sets</h2>
727-<p>Enumerations compare with all six relations, by position, and an
728-enumeration can be the variable of a <code>for</code> loop and the
729-expression of a <code>match</code> (section 7.4).</p>
730-<p><code>{red, blue}</code> is a set, of the set type of its names’
731-enumeration; <code>{}</code> is the empty set, where the type it must
732-have is known. On two sets of the same type, <code>+</code> is union,
733-<code>*</code> intersection and <code>-</code> difference;
734-<code>=</code> and <code>#</code> compare, and <code>&lt;=</code> and
735-<code>&gt;=</code> are “is a subset of” and “is a superset of”.
736-<code>x in s</code> is <code>true</code> if <code>x</code>, a value of
737-the enumeration, is in the set <code>s</code>.</p>
305+<p>Enumerations compare with all six relations, by position, and an enumeration can be the variable of a <code>for</code> loop and the expression of a <code>match</code> (section 7.4).</p>
306+<p><code>{red, blue}</code> is a set, of the set type of its names’ enumeration; <code>{}</code> is the empty set, where the type it must have is known. On two sets of the same type, <code>+</code> is union, <code>*</code> intersection and <code>-</code> difference; <code>=</code> and <code>#</code> compare, and <code>&lt;=</code> and <code>&gt;=</code> are “is a subset of” and “is a superset of”. <code>x in s</code> is <code>true</code> if <code>x</code>, a value of the enumeration, is in the set <code>s</code>.</p>
738307 <h2 id="conversions">6.7 Conversions</h2>
739-<p>A type name applied like a procedure converts: <code>I32(x)</code>,
740-<code>F64(n)</code>, <code>^Cell(addr)</code>. A pointer type written
741-out uses the <code>^</code> form of the grammar:
742-<code>^VOLATILE U32(0FEE00000H)</code>.</p>
308+<p>A type name applied like a procedure converts: <code>I32(x)</code>, <code>F64(n)</code>, <code>^Cell(addr)</code>. A pointer type written out uses the <code>^</code> form of the grammar: <code>^VOLATILE U32(0FEE00000H)</code>.</p>
743309 <table>
744-<colgroup>
745-<col style="width: 33%" />
746-<col style="width: 33%" />
747-<col style="width: 33%" />
748-</colgroup>
749310 <thead>
750-<tr class="header">
311+<tr>
751312 <th>From</th>
752313 <th>To</th>
753314 <th>Result</th>
754315 </tr>
755316 </thead>
756317 <tbody>
757-<tr class="odd">
318+<tr>
758319 <td>integer</td>
759320 <td>integer</td>
760-<td>the value cut to the new width, or extended by its sign (signed) or
761-zeros (unsigned)</td>
321+<td>the value cut to the new width, or extended by its sign (signed) or zeros (unsigned)</td>
762322 </tr>
763-<tr class="even">
323+<tr>
764324 <td>integer</td>
765325 <td><code>F32</code>, <code>F64</code></td>
766326 <td>the nearest real</td>
767327 </tr>
768-<tr class="odd">
328+<tr>
769329 <td><code>F32</code>, <code>F64</code></td>
770330 <td>integer</td>
771-<td>rounded toward zero; a NaN, or a real out of the range of
772-<code>I64</code>, gives the smallest <code>I64</code>, then cut</td>
331+<td>rounded toward zero; a NaN, or a real out of the range of <code>I64</code>, gives the smallest <code>I64</code>, then cut</td>
773332 </tr>
774-<tr class="even">
333+<tr>
775334 <td><code>F32</code></td>
776335 <td><code>F64</code></td>
777336 <td>the same value</td>
778337 </tr>
779-<tr class="odd">
338+<tr>
780339 <td><code>F64</code></td>
781340 <td><code>F32</code></td>
782341 <td>the nearest <code>F32</code>; too big a value gives an infinity</td>
783342 </tr>
784-<tr class="even">
343+<tr>
785344 <td>enumeration</td>
786345 <td>integer</td>
787346 <td>its position</td>
788347 </tr>
789-<tr class="odd">
348+<tr>
790349 <td>integer</td>
791350 <td>enumeration</td>
792-<td>the name at that position; a position out of range is a failed check
793-(6.5)</td>
351+<td>the name at that position; a position out of range is a failed check (6.5)</td>
794352 </tr>
795-<tr class="even">
353+<tr>
796354 <td>set</td>
797355 <td>integer</td>
798356 <td>its bits</td>
799357 </tr>
800-<tr class="odd">
358+<tr>
801359 <td>integer</td>
802360 <td>set</td>
803361 <td>the low bits, as many as the set has</td>
804362 </tr>
805-<tr class="even">
363+<tr>
806364 <td><code>INT</code>, <code>UINT</code></td>
807365 <td>pointer, procedure</td>
808366 <td>the address</td>
809367 </tr>
810-<tr class="odd">
368+<tr>
811369 <td>pointer, procedure</td>
812370 <td><code>INT</code>, <code>UINT</code></td>
813371 <td>the address</td>
814372 </tr>
815-<tr class="even">
373+<tr>
816374 <td>pointer, procedure</td>
817375 <td>pointer, procedure</td>
818376 <td>the same address, seen as the new type</td>
819377 </tr>
820378 </tbody>
821379 </table>
822-<p>There are no others: no conversion between <code>BOOL</code> and
823-integers, none between pointers and integers other than <code>INT</code>
824-and <code>UINT</code>, and none to or from records, arrays, slices,
825-variants or <code>ERROR</code>. A conversion of a constant is made by
826-the compiler, by the same rules: <code>U8(300)</code> is 44.</p>
380+<p>There are no others: no conversion between <code>BOOL</code> and integers, none between pointers and integers other than <code>INT</code> and <code>UINT</code>, and none to or from records, arrays, slices, variants or <code>ERROR</code>. A conversion of a constant is made by the compiler, by the same rules: <code>U8(300)</code> is 44.</p>
827381 <h2 id="built-in-procedures">6.8 Built-in procedures</h2>
828382 <table>
829-<colgroup>
830-<col style="width: 50%" />
831-<col style="width: 50%" />
832-</colgroup>
833383 <thead>
834-<tr class="header">
384+<tr>
835385 <th>Call</th>
836386 <th>Result</th>
837387 </tr>
838388 </thead>
839389 <tbody>
840-<tr class="odd">
390+<tr>
841391 <td><code>SIZE(T)</code></td>
842-<td>the size of type <code>T</code> in bytes, an untyped constant;
843-<code>T</code> is a type, not a variable</td>
392+<td>the size of type <code>T</code> in bytes, an untyped constant; <code>T</code> is a type, not a variable</td>
844393 </tr>
845-<tr class="even">
394+<tr>
846395 <td><code>ADR(x)</code></td>
847396 <td>the address of variable <code>x</code>, a <code>^T</code></td>
848397 </tr>
849-<tr class="odd">
398+<tr>
850399 <td><code>LEN(a)</code></td>
851-<td>the number of elements of an array or a string constant (an untyped
852-constant) or of a slice (an <code>INT</code>)</td>
400+<td>the number of elements of an array or a string constant (an untyped constant) or of a slice (an <code>INT</code>)</td>
853401 </tr>
854-<tr class="even">
402+<tr>
855403 <td><code>NEW(p, a)</code></td>
856-<td>sets <code>p: ^T</code> to a fresh, zeroed <code>T</code> from the
857-allocator <code>a: ^Mem.Allocator</code>, or to <code>nil</code> if
858-<code>a</code> has no room</td>
404+<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>
859405 </tr>
860-<tr class="odd">
406+<tr>
861407 <td><code>MSG(e)</code></td>
862408 <td>the message of the error <code>e</code>, a <code>[]U8</code></td>
863409 </tr>
864-<tr class="even">
410+<tr>
865411 <td><code>COPY(d, s)</code></td>
866-<td>copies the elements of <code>s</code> to the start of
867-<code>d</code>, both arrays or slices of one type <code>T</code>;
868-<code>LEN(s)</code> must be at most <code>LEN(d)</code></td>
412+<td>copies the elements of <code>s</code> to the start of <code>d</code>, both arrays or slices of one type <code>T</code>; <code>LEN(s)</code> must be at most <code>LEN(d)</code></td>
869413 </tr>
870-<tr class="odd">
414+<tr>
871415 <td><code>SYSCALL(n, x1, ..., x6)</code></td>
872-<td>Linux system call <code>n</code> with up to six arguments, each a
873-pointer or an integer no wider than <code>INT</code>; the raw result, an
874-<code>INT</code> (a negative number is <code>-errno</code>)</td>
416+<td>Linux system call <code>n</code> with up to six arguments, each a pointer or an integer no wider than <code>INT</code>; the raw result, an <code>INT</code> (a negative number is <code>-errno</code>)</td>
875417 </tr>
876-<tr class="even">
418+<tr>
877419 <td><code>INC(v)</code>, <code>INC(v, k)</code></td>
878-<td>adds 1, or <code>k</code>, to the integer variable <code>v</code>;
879-it wraps, like <code>+</code></td>
420+<td>adds 1, or <code>k</code>, to the integer variable <code>v</code>; it wraps, like <code>+</code></td>
880421 </tr>
881-<tr class="odd">
422+<tr>
882423 <td><code>DEC(v)</code>, <code>DEC(v, k)</code></td>
883424 <td>subtracts 1, or <code>k</code>, from <code>v</code></td>
884425 </tr>
885-<tr class="even">
426+<tr>
886427 <td><code>FENCE</code></td>
887428 <td>a full memory barrier</td>
888429 </tr>
889-<tr class="odd">
430+<tr>
890431 <td><code>CAS(p, old, new)</code></td>
891-<td>if <code>p^ = old</code>, sets <code>p^ := new</code> and returns
892-<code>true</code>; atomically</td>
432+<td>if <code>p^ = old</code>, sets <code>p^ := new</code> and returns <code>true</code>; atomically</td>
893433 </tr>
894-<tr class="even">
434+<tr>
895435 <td><code>XCHG(p, x)</code></td>
896-<td>sets <code>p^ := x</code> and returns the value before,
897-atomically</td>
436+<td>sets <code>p^ := x</code> and returns the value before, atomically</td>
898437 </tr>
899-<tr class="odd">
438+<tr>
900439 <td><code>XADD(p, x)</code></td>
901-<td>adds <code>x</code> to <code>p^</code> and returns the value before,
902-atomically</td>
440+<td>adds <code>x</code> to <code>p^</code> and returns the value before, atomically</td>
903441 </tr>
904-<tr class="even">
442+<tr>
905443 <td><code>ARGC()</code></td>
906444 <td>the number of command line arguments, an <code>INT</code></td>
907445 </tr>
908-<tr class="odd">
446+<tr>
909447 <td><code>ARGV()</code></td>
910448 <td>the arguments, a <code>^^U8</code> (C strings)</td>
911449 </tr>
912450 </tbody>
913451 </table>
914-<p><code>SYSCALL</code> exists only on Linux targets. Other systems have
915-no stable system call interface, and their modules call the C library
916-instead (section 9).</p>
917-<p><code>NEW(p, a)</code> calls <code>a^.alloc(a, SIZE(T), A)</code>,
918-where <code>A</code> is the alignment of <code>T</code>, and zeroes the
919-bytes it gets if they aren’t <code>nil</code>.
920-<code>Mem.Allocator</code> (section 11) is the one type of the library
921-the language names.</p>
922-<p><code>COPY</code> is a statement, as <code>INC</code> is. It copies
923-the bytes of <code>LEN(s)</code> elements as one block, as an assignment
924-of an array does, and is right when <code>d</code> and <code>s</code>
925-overlap, as in <code>COPY(a[1..n], a[0..n - 1])</code>. It is checked as
926-a slice is: past <code>LEN(d)</code>, it stops the program, unless the
927-module says <code>check off;</code>.</p>
928-<p><code>INC</code> and <code>DEC</code> evaluate <code>v</code> once,
929-so <code>INC(a[f(i)])</code> calls <code>f</code> once. They read
930-<code>v</code> and then write it: two accesses, even through a
931-<code>^VOLATILE</code> pointer, and not atomic; <code>XADD</code> is the
932-atomic one.</p>
933-<p>For <code>CAS</code>, <code>XCHG</code> and <code>XADD</code>,
934-<code>p</code> is a <code>^T</code> or <code>^VOLATILE T</code> where
935-<code>T</code> is <code>INT</code>, <code>UINT</code> or a pointer type
936-(<code>INT</code> or <code>UINT</code> for <code>XADD</code>), on every
937-target. They are sequentially consistent, on every target; how a machine
938-without atomic instructions makes them so is the implementation’s choice
939-(appendix A).</p>
452+<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>
453+<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> (section 11) is the one type of the library the language names.</p>
454+<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>
455+<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>
456+<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).</p>
940457 <h1 id="statements">7. Statements</h1>
941458 <pre><code>Statements = { Statement &quot;;&quot; } .
942459 Statement = Designator [ &quot;:=&quot; Expr ]
@@ -955,120 +472,42 @@
955472 | Label { &quot;,&quot; Label } | &quot;else&quot; ) &quot;:&quot; Statements .
956473 Label = Expr [ &quot;..&quot; Expr ] .
957474 Target = Designator | &quot;_&quot; .</code></pre>
958-<p>Every statement ends in <code>;</code>, including the ones that end
959-in <code>end</code> or <code>until</code>.</p>
475+<p>Every statement ends in <code>;</code>, including the ones that end in <code>end</code> or <code>until</code>.</p>
960476 <h2 id="assignment-and-calls">7.1 Assignment and calls</h2>
961-<p><code>x := e</code> evaluates <code>e</code> and stores it in
962-<code>x</code>; arrays, records, slices and variants are copied. A
963-designator on its own is a call, and any result it returns is dropped:
964-<code>Out.ln;</code>, <code>write(fd, buf);</code>.</p>
965-<p><code>a, b := f(x);</code> assigns the results of a procedure that
966-returns several (section 8), in order.</p>
967-<p>The blank, <code>_</code>, drops what would be assigned to it:
968-<code>_ := e;</code> evaluates <code>e</code> and drops it, and
969-<code>n, _ := f(x);</code> keeps the first result and drops the second.
970-What is dropped is still evaluated as any expression is: its calls are
971-made, and a volatile variable in it is read (section 7.6). A result
972-dropped by a call standing on its own is warned of (section 10); one
973-dropped through <code>_</code> isn’t.</p>
477+<p><code>x := e</code> evaluates <code>e</code> and stores it in <code>x</code>; arrays, records, slices and variants are copied. A designator on its own is a call, and any result it returns is dropped: <code>Out.ln;</code>, <code>write(fd, buf);</code>.</p>
478+<p><code>a, b := f(x);</code> assigns the results of a procedure that returns several (section 8), in order.</p>
479+<p>The blank, <code>_</code>, drops what would be assigned to it: <code>_ := e;</code> evaluates <code>e</code> and drops it, and <code>n, _ := f(x);</code> keeps the first result and drops the second. What is dropped is still evaluated as any expression is: its calls are made, and a volatile variable in it is read (section 7.6). A result dropped by a call standing on its own is warned of (section 10); one dropped through <code>_</code> isn’t.</p>
974480 <h2 id="conditions-and-loops">7.2 Conditions and loops</h2>
975-<p><code>if</code>, <code>while</code> and <code>repeat</code> take
976-<code>BOOL</code> expressions. <code>repeat</code> runs its body at
977-least once and stops when the condition is true.</p>
978-<p><code>for i := a to b by s do ... end;</code> sets <code>i</code> to
979-<code>a</code>, <code>a + s</code>, … while <code>i &lt;= b</code> (or
980-<code>i &gt;= b</code> if <code>s</code> is negative). <code>i</code> is
981-a variable of an integer or enumeration type, named by its name alone;
982-<code>a</code> and then <code>b</code> are evaluated once, before the
983-first round; <code>s</code> is a constant other than zero, and 1 if left
984-out. <code>a</code> and <code>b</code> have <code>i</code>’s type, or
985-are untyped constants that take it, as with <code>+</code> (section
986-6.1): so in <code>for i := 0 to LEN(s) - 1</code>, <code>i</code> must
987-be an <code>INT</code>.</p>
988-<p>The loop never steps past <code>b</code>, so <code>i</code> can’t
989-wrap: afterwards <code>i</code> holds the last value it took, or
990-<code>a</code> if the body never ran. The body may assign
991-<code>i</code>. Precisely, for a positive <code>s</code>: at the end of
992-a round, if <code>i &lt;= b</code> and <code>b - i &lt; s</code>, the
993-loop ends with <code>i</code> as it is; otherwise <code>i</code> becomes
994-<code>i + s</code>, wrapping, and the loop goes on while
995-<code>i &lt;= b</code>. A negative <code>s</code> is the same, the other
996-way round.</p>
997-<p><code>break</code> ends the innermost <code>while</code>,
998-<code>repeat</code> or <code>for</code> it stands in, and the program
999-goes on after it. There is no <code>goto</code>.</p>
481+<p><code>if</code>, <code>while</code> and <code>repeat</code> take <code>BOOL</code> expressions. <code>repeat</code> runs its body at least once and stops when the condition is true.</p>
482+<p><code>for i := a to b by s do ... end;</code> sets <code>i</code> to <code>a</code>, <code>a + s</code>, … while <code>i &lt;= b</code> (or <code>i &gt;= b</code> if <code>s</code> is negative). <code>i</code> is a variable of an integer or enumeration type, named by its name alone; <code>a</code> and then <code>b</code> are evaluated once, before the first round; <code>s</code> is a constant other than zero, and 1 if left out. <code>a</code> and <code>b</code> have <code>i</code>’s type, or are untyped constants that take it, as with <code>+</code> (section 6.1): so in <code>for i := 0 to LEN(s) - 1</code>, <code>i</code> must be an <code>INT</code>.</p>
483+<p>The loop never steps past <code>b</code>, so <code>i</code> can’t wrap: afterwards <code>i</code> holds the last value it took, or <code>a</code> if the body never ran. The body may assign <code>i</code>. Precisely, for a positive <code>s</code>: at the end of a round, if <code>i &lt;= b</code> and <code>b - i &lt; s</code>, the loop ends with <code>i</code> as it is; otherwise <code>i</code> becomes <code>i + s</code>, wrapping, and the loop goes on while <code>i &lt;= b</code>. A negative <code>s</code> is the same, the other way round.</p>
484+<p><code>break</code> ends the innermost <code>while</code>, <code>repeat</code> or <code>for</code> it stands in, and the program goes on after it. There is no <code>goto</code>.</p>
1000485 <h2 id="return">7.3 Return</h2>
1001-<p><code>return e;</code> ends the procedure with the result
1002-<code>e</code>; <code>return a, b;</code> with several results;
1003-<code>return f(x);</code> with the several results of <code>f</code>, if
1004-they are the procedure’s own (section 8); <code>return;</code> from a
1005-procedure without results. A procedure with results that runs off its
1006-end returns zeros, each result as a variable of its type starts (section
1007-4).</p>
486+<p><code>return e;</code> ends the procedure with the result <code>e</code>; <code>return a, b;</code> with several results; <code>return f(x);</code> with the several results of <code>f</code>, if they are the procedure’s own (section 8); <code>return;</code> from a procedure without results. A procedure with results that runs off its end returns zeros, each result as a variable of its type starts (section 4).</p>
1008487 <h2 id="match">7.4 Match</h2>
1009488 <pre><code>match s of
1010489 | circle(r): area := 3.14159 * r * r;
1011490 | rect(w, h): area := w * h;
1012491 | dot: area := 0.0;
1013492 end;</code></pre>
1014-<p><code>match</code> runs the arm of the case <code>s</code> holds. An
1015-arm may name the case’s fields, in order, all of them; the names stand
1016-for those fields of <code>s</code> itself, so assigning to one changes
1017-<code>s</code>; if <code>s</code> isn’t a variable, they stand for the
1018-fields of a copy. An arm may also leave the fields unnamed. Every case
1019-must have an arm, and only one, unless there is an <code>| else:</code>
1020-arm, which must come last.</p>
1021-<p><code>match</code> on an enumeration works the same way: each arm
1022-names one of the enumeration’s names.</p>
1023-<p><code>match</code> on an integer runs the arm whose labels hold its
1024-value:</p>
493+<p><code>match</code> 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>
494+<p><code>match</code> on an enumeration works the same way: each arm names one of the enumeration’s names.</p>
495+<p><code>match</code> on an integer runs the arm whose labels hold its value:</p>
1025496 <pre><code>match ch of
1026497 | &#39; &#39;, &#39;\t&#39;: skip := true;
1027498 | &#39;0&#39; .. &#39;9&#39;: digit := true;
1028499 | else:
1029500 end;</code></pre>
1030-<p>A label is a constant, or <code>lo .. hi</code>, the constants from
1031-<code>lo</code> to <code>hi</code>, both included (unlike a slice, which
1032-leaves <code>hi</code> out). Each must fit the integer’s type, and no
1033-value may be in two labels. An integer <code>match</code> must have an
1034-<code>| else:</code> arm, which may be empty. Whether an arm names a
1035-case or gives labels is set by the type matched: <code>| Max:</code> is
1036-a case of a variant or an enumeration, and a constant for an
1037-integer.</p>
501+<p>A label is a constant, or <code>lo .. hi</code>, the constants from <code>lo</code> to <code>hi</code>, both included (unlike a slice, which leaves <code>hi</code> out). Each must fit the integer’s type, and no value may be in two labels. An integer <code>match</code> must have an <code>| else:</code> arm, which may be empty. Whether an arm names a case or gives labels is set by the type matched: <code>| Max:</code> is a case of a variant or an enumeration, and a constant for an integer.</p>
1038502 <h2 id="order-of-evaluation">7.5 Order of evaluation</h2>
1039-<p>Operands, arguments and the designators of an assignment are
1040-evaluated from left to right, and the designators of an assignment
1041-before its right side: <code>a[i()] := g()</code> calls <code>i</code>
1042-and then <code>g</code>.</p>
503+<p>Operands, arguments and the designators of an assignment are evaluated from left to right, and the designators of an assignment before its right side: <code>a[i()] := g()</code> calls <code>i</code> and then <code>g</code>.</p>
1043504 <h2 id="volatile">7.6 Volatile</h2>
1044-<p>A variable reached through a <code>^VOLATILE T</code> is volatile,
1045-and so is any field or element of it. Each read or write of a volatile
1046-variable of a basic, enumeration, set or pointer type is exactly one
1047-memory access, of exactly its size, and volatile accesses happen in the
1048-order the program writes them. Copying a whole record or array through a
1049-volatile pointer is not allowed, since it can’t be one access.</p>
1050-<p>A <code>^VOLATILE T</code> doesn’t convert to <code>^T</code> without
1051-a written conversion.</p>
1052-<p><code>FENCE</code> also orders the program’s ordinary accesses
1053-against those of other processors and devices.</p>
1054-<p><strong>Ordinary variables.</strong> Only volatile accesses,
1055-<code>CAS</code>, <code>XCHG</code>, <code>XADD</code> and
1056-<code>FENCE</code> are exact. Any other access is ordinary: an
1057-implementation may keep a variable in a register, leave out a write that
1058-nothing reads, and change the order of ordinary accesses, as long as
1059-each thread, on its own, does what this report says. A variable that one
1060-thread writes while another reads or writes it, unless both use volatile
1061-accesses or the atomic built-ins, or a <code>FENCE</code> orders them,
1062-holds no particular value then: a read of it gives a value it had or was
1063-given, or a mixture of their bytes. Nothing else of the program becomes
1064-undefined by it.</p>
505+<p>A variable reached through a <code>^VOLATILE T</code> is volatile, and so is any field or element of it. Each read or write of a volatile variable of a basic, enumeration, set or pointer type is exactly one memory access, of exactly its size, and volatile accesses happen in the order the program writes them. Copying a whole record or array through a volatile pointer is not allowed, since it can’t be one access.</p>
506+<p>A <code>^VOLATILE T</code> doesn’t convert to <code>^T</code> without a written conversion.</p>
507+<p><code>FENCE</code> also orders the program’s ordinary accesses against those of other processors and devices.</p>
508+<p><strong>Ordinary variables.</strong> Only volatile accesses, <code>CAS</code>, <code>XCHG</code>, <code>XADD</code> and <code>FENCE</code> are exact. Any other access is ordinary: an implementation may keep a variable in a register, leave out a write that nothing reads, and change the order of ordinary accesses, as long as each thread, on its own, does what this report says. A variable that one thread writes while another reads or writes it, unless both use volatile accesses or the atomic built-ins, or a <code>FENCE</code> orders them, holds no particular value then: a read of it gives a value it had or was given, or a mixture of their bytes. Nothing else of the program becomes undefined by it.</p>
1065509 <h2 id="defer">7.7 Defer</h2>
1066-<p><code>defer s;</code> runs the statement <code>s</code> when the
1067-program leaves the statement list the <code>defer</code> stands in: at
1068-its end, or by a <code>return</code>, or by a <code>break</code> out of
1069-it. Statements deferred in the same list run in the opposite order to
1070-their <code>defer</code>s, and only those whose <code>defer</code> has
1071-been reached run.</p>
510+<p><code>defer s;</code> runs the statement <code>s</code> when the program leaves the statement list the <code>defer</code> stands in: at its end, or by a <code>return</code>, or by a <code>break</code> out of it. Statements deferred in the same list run in the opposite order to their <code>defer</code>s, and only those whose <code>defer</code> has been reached run.</p>
1072511 <pre><code>module Head;
1073512 import Sys, Out;
1074513
@@ -1095,11 +534,7 @@
1095534 end;
1096535
1097536 end Head.</code></pre>
1098-<p><code>return e;</code> evaluates <code>e</code> before the deferred
1099-statements run. A deferred statement can’t contain <code>return</code>,
1100-<code>break</code> or <code>defer</code> that would leave it. A failed
1101-check, <code>Rt.exit</code> and <code>Sys.exit</code> end the program
1102-without running the deferred statements still pending.</p>
537+<p><code>return e;</code> evaluates <code>e</code> before the deferred statements run. A deferred statement can’t contain <code>return</code>, <code>break</code> or <code>defer</code> that would leave it. A failed check, <code>Rt.exit</code> and <code>Sys.exit</code> end the program without running the deferred statements still pending.</p>
1103538 <h1 id="procedures">8. Procedures</h1>
1104539 <pre><code>ProcDeclaration = &quot;proc&quot; IdentDef Signature &quot;;&quot;
1105540 ( &quot;forward&quot; | { LocalDeclaration } &quot;begin&quot; Statements &quot;end&quot; [ ident ]
@@ -1111,20 +546,9 @@
1111546 | [ &quot;:&quot; Results ] .
1112547 Params = [ &quot;var&quot; ] ident { &quot;,&quot; ident } &quot;:&quot; Type .
1113548 Results = Type | &quot;(&quot; Type { &quot;,&quot; Type } &quot;)&quot; .</code></pre>
1114-<p>A procedure without parameters may leave out the parentheses, both
1115-where it is declared (<code>proc main*;</code>) and where it is called
1116-(<code>Out.ln</code>). Used without parentheses in an expression, a
1117-procedure is a procedure value, not a call.</p>
1118-<p><strong>Parameters.</strong> A value parameter is a copy: the
1119-procedure may change it, and the caller’s variable stays as it was. A
1120-<code>var</code> parameter is the caller’s variable itself; its argument
1121-must be a variable of exactly the parameter’s type.</p>
1122-<p><strong>Results.</strong> A procedure returns nothing, one value, or
1123-several. A call that returns several values can only stand on the right
1124-of a multiple assignment, alone as a statement, or alone after
1125-<code>return</code> in a procedure whose results are of the same types,
1126-in the same order, which then returns them as they are:
1127-<code>return divmod(n, 2);</code>.</p>
549+<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>
550+<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>
551+<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>.</p>
1128552 <pre><code>module Divide;
1129553 import Out;
1130554
@@ -1141,17 +565,10 @@
1141565 end;
1142566
1143567 end Divide.</code></pre>
1144-<p><strong>forward.</strong> <code>proc f(x: I64): I64; forward;</code>
1145-declares <code>f</code> so that it can be called before its body
1146-appears; the body comes later with the same signature, though its
1147-parameters may have other names.</p>
1148-<p>A name after a procedure’s <code>end</code>, if written, is the
1149-procedure’s own.</p>
568+<p><strong>forward.</strong> <code>proc f(x: I64): I64; forward;</code> declares <code>f</code> so that it can be called before its body appears; the body comes later with the same signature, though its parameters may have other names.</p>
569+<p>A name after a procedure’s <code>end</code>, if written, is the procedure’s own.</p>
1150570 <p>Procedures don’t nest.</p>
1151-<p><strong>Code procedures.</strong> A procedure whose body is
1152-<code>code</code> is machine code, written by hand in the target’s
1153-assembly language (appendix A): one instruction to each <code>;</code>,
1154-and labels for jumps, up to <code>end</code>:</p>
571+<p><strong>Code procedures.</strong> A procedure whose body is <code>code</code> is machine code, written by hand in the target’s assembly language (appendix A): one instruction to each <code>;</code>, and labels for jumps, up to <code>end</code>:</p>
1155572 <pre><code>proc rdtsc*: U64;
1156573 code
1157574 rdtsc;
@@ -1159,24 +576,8 @@
1159576 or rax, rdx;
1160577 ret;
1161578 end rdtsc;</code></pre>
1162-<p>A label, <code>name:</code>, names the place of the instruction after
1163-it, within the procedure. A constant of the module may stand wherever a
1164-number does. Any bytes may be written with <code>db</code>, as in
1165-<code>db 0FH, 31H;</code>, for an instruction the assembler doesn’t
1166-know.</p>
1167-<p>It is called like any procedure, with the System V convention:
1168-integer and pointer arguments arrive in <code>rdi</code>,
1169-<code>rsi</code>, <code>rdx</code>, <code>rcx</code>, <code>r8</code>
1170-and <code>r9</code>, <code>F32</code> and <code>F64</code> ones in
1171-<code>xmm0</code> to <code>xmm7</code>, and the result goes in
1172-<code>rax</code> (and <code>rdx</code> for a second) or
1173-<code>xmm0</code>. Its parameters and results are therefore of the types
1174-C can take (section 9), at most six integer and eight real parameters,
1175-and at most two results. The instructions are the whole procedure,
1176-<code>ret</code> included; they must keep <code>rbx</code>,
1177-<code>rbp</code>, <code>rsp</code> and <code>r12</code> to
1178-<code>r15</code> as they found them. The compiler doesn’t look past what
1179-they say.</p>
579+<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>
580+<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>
1180581 <h1 id="calling-c">9. Calling C</h1>
1181582 <pre><code>ExternDeclaration = &quot;extern&quot; ( &quot;proc&quot; IdentDef Signature
1182583 | &quot;var&quot; IdentDef &quot;:&quot; Type ) .</code></pre>
@@ -1184,27 +585,10 @@
1184585 extern proc XOpenDisplay(name: ^U8): ^U8;
1185586 extern proc printf(format: ^U8; ...): I32;
1186587 extern var environ: ^^U8;</code></pre>
1187-<p>An <code>extern</code> procedure or variable is found by its name in
1188-the C libraries the program links: the C library always, and each
1189-library named by <code>link</code>.</p>
1190-<p>An <code>extern</code> procedure’s parameters and result are
1191-integers, <code>BOOL</code>, <code>F32</code>, <code>F64</code>,
1192-pointers or procedures; a record goes to C by pointer, never by value.
1193-<code>...</code> accepts any number of further arguments of those types,
1194-and is allowed only in an <code>extern</code>. C takes no
1195-<code>float</code> there, so an <code>F32</code> given to
1196-<code>...</code> is an error: the program writes <code>F64(x)</code>.
1197-Past the parameters, a real constant goes as an <code>F64</code>, an
1198-integer constant as an <code>INT</code>, and a string literal as a
1199-pointer to its bytes followed by a zero byte.</p>
1200-<p>An <code>extern</code> variable is C’s variable itself: reading it
1201-reads C’s, assigning it writes C’s. It can be of any type, declared as C
1202-declares it, a record laid out as C lays it out (section 5.5); the
1203-compiler can’t check that it is. A C variable that is local to each
1204-thread, such as <code>errno</code>, can’t be reached this way; the C
1205-library has a procedure for it (<code>__errno_location</code>).</p>
1206-<p>A C union has no raz type. A program reads one as an array of words,
1207-and the member it wants through a pointer conversion:</p>
588+<p>An <code>extern</code> procedure or variable is found by its name in the C libraries the program links: the C library always, and each library named by <code>link</code>.</p>
589+<p>An <code>extern</code> procedure’s parameters and result are integers, <code>BOOL</code>, <code>F32</code>, <code>F64</code>, pointers or procedures; a record goes to C by pointer, never by value. <code>...</code> accepts any number of further arguments of those types, and is allowed only in an <code>extern</code>. C takes no <code>float</code> there, so an <code>F32</code> given to <code>...</code> is an error: the program writes <code>F64(x)</code>. Past the parameters, a real constant goes as an <code>F64</code>, an integer constant as an <code>INT</code>, and a string literal as a pointer to its bytes followed by a zero byte.</p>
590+<p>An <code>extern</code> variable is C’s variable itself: reading it reads C’s, assigning it writes C’s. It can be of any type, declared as C declares it, a record laid out as C lays it out (section 5.5); the compiler can’t check that it is. A C variable that is local to each thread, such as <code>errno</code>, can’t be reached this way; the C library has a procedure for it (<code>__errno_location</code>).</p>
591+<p>A C union has no raz type. A program reads one as an array of words, and the member it wants through a pointer conversion:</p>
1208592 <pre><code>var ev: [24]I64; (* XEvent: 192 bytes *)
1209593 ...
1210594 XNextEvent(dpy, ADR(ev));
@@ -1212,229 +596,116 @@
1212596 key := ^XKeyEvent(ADR(ev));
1213597 ...
1214598 end;</code></pre>
1215-<p>Every raz procedure uses the System V calling convention, so a raz
1216-procedure whose parameters and result are of those types can be given to
1217-C as a callback.</p>
599+<p>Every raz procedure uses the System V calling convention, so a raz procedure whose parameters and result are of those types can be given to C as a callback.</p>
1218600 <h1 id="programs">10. Programs</h1>
1219-<p>Any module may export a procedure <code>main</code>, declared
1220-<code>proc main*;</code> or <code>proc main*: INT;</code>. The program
1221-runs the bodies of all its modules (section 3), then the main module’s
1222-<code>main</code>, if it has one, and ends with status 0, or with the
1223-status <code>main</code> returns, by calling <code>Rt.exit</code>. The
1224-<code>main</code> of an imported module is an ordinary procedure, which
1225-runs only if something calls it; so a library module can carry a
1226-<code>main</code> that tests it. A program uses C if any of its modules
1227-has an <code>extern</code> declaration or a <code>link</code> of a
1228-library; a module’s other files, read only to check its interface
1229-(section 3), don’t count. A program that doesn’t is a static executable
1230-with no run time besides the code it uses. One that does is linked
1231-dynamically and starts through the C library, so that C’s own set-up and
1232-clean-up run. A program with a module that says
1233-<code>link static;</code> must not use C, and the compiler reports an
1234-error if it does.</p>
1235-<p><strong>Ending.</strong> <code>Rt.exit(status)</code> ends the
1236-program. First it runs the procedures registered with
1237-<code>Rt.atExit</code>, the last registered first, each at most once;
1238-then it ends the program with <code>status</code>, through C’s
1239-<code>exit</code> in a program that uses C, so that C flushes its own
1240-buffers. A failed check (section 6.5) runs them too, after its message,
1241-so that <code>Out</code>’s buffer is written out. <code>Sys.exit</code>
1242-ends the program at once, and a program stopped by a signal runs none of
1243-them.</p>
601+<p>Any module may export a procedure <code>main</code>, declared <code>proc main*;</code> or <code>proc main*: INT;</code>. The program runs the bodies of all its modules (section 3), then the main module’s <code>main</code>, if it has one, and ends with status 0, or with the status <code>main</code> returns, by calling <code>Rt.exit</code>. The <code>main</code> of an imported module is an ordinary procedure, which runs only if something calls it; so a library module can carry a <code>main</code> that tests it. A program uses C if any of its modules has an <code>extern</code> declaration or a <code>link</code> of a library; a module’s other files, read only to check its interface (section 3), don’t count. A program that doesn’t is a static executable with no run time besides the code it uses. One that does is linked dynamically and starts through the C library, so that C’s own set-up and clean-up run. A program with a module that says <code>link static;</code> must not use C, and the compiler reports an error if it does.</p>
602+<p><strong>Ending.</strong> <code>Rt.exit(status)</code> ends the program. First it runs the procedures registered with <code>Rt.atExit</code>, the last registered first, each at most once; then it ends the program with <code>status</code>, through C’s <code>exit</code> in a program that uses C, so that C flushes its own buffers. A failed check (section 6.5) runs them too, after its message, so that <code>Out</code>’s buffer is written out. <code>Sys.exit</code> ends the program at once, and a program stopped by a signal runs none of them.</p>
1244603 <pre><code>proc atExit*(p: proc): ERROR; (* Rt.Full if 32 are registered *)
1245604 proc exit*(status: INT);
1246605 proc trace*; (* the calls under way, on standard error *)</code></pre>
1247-<p><code>Rt.trace</code> says on standard error the calls under way,
1248-from the one that calls it out, each with its variables, as a program
1249-that stops does.</p>
1250-<p>Only what can be reached from <code>main</code> and the module bodies
1251-goes into the executable: unused procedures, variables and strings are
1252-left out. The executable names its procedures and carries line numbers,
1253-so that gdb can stop at a line of the source and show where it is.</p>
1254-<p><strong>Defined behaviour.</strong> Every variable starts at zero,
1255-integers wrap, and indexing arrays and slices is checked, so a program’s
1256-behaviour is defined by this report, with one exception: memory reached
1257-other than through a checked variable. Dereferencing a stale or made-up
1258-pointer, indexing through a pointer, an index out of range in a module
1259-that says <code>check off;</code>, writing a string’s bytes, a code
1260-procedure that breaks its rules, and C code can read or write any
1261-memory, and what follows isn’t defined. Dereferencing <code>nil</code>,
1262-dividing by zero, calling a <code>nil</code> procedure and running out
1263-of stack stop the program, on every target. Before it stops, the program
1264-prints to standard error where it was, as file, line and column, and
1265-why, as far as it can tell: a <code>nil</code> pointer, a
1266-<code>nil</code> procedure, a stack overflow, a bad address or a
1267-division fault; then the calls under way, each with its variables of a
1268-basic, enumeration, set or pointer type. Whether the machine catches
1269-these or the compiled code checks for them is the implementation’s
1270-choice (appendix A); that they stop the program isn’t.</p>
1271-<p><strong>Separate compilation.</strong> An importer depends only on a
1272-module’s interface: what it exports, as an importer sees it, never its
1273-source or its code. So a module can be compiled on its own, and a
1274-program made from modules compiled at different times. Whether an
1275-implementation does so, and into what, is its own choice (appendix A);
1276-one that does makes the same program as if every module were compiled
1277-together, and keeps one copy of each instance.</p>
1278-<p><strong>Messages.</strong> The compiler reports an error with its
1279-file, line and column, the line of source with the offending part
1280-underlined, and, where they help, notes pointing at other places, such
1281-as where a name is declared, and a suggestion, such as a name in reach
1282-spelled almost alike. It goes on after an error to find the others, up
1283-to 20, and writes no executable. After an error it skips the statement
1284-or declaration the error is in and carries on with the next; a name that
1285-isn’t declared is reported once, and nothing that follows from it is
1286-reported. An error in the text itself, such as a string left open, stops
1287-the compile, and so does a module with errors, after it.</p>
1288-<p>The compiler also warns of what is declared and never used: an
1289-import; a constant, type, variable or procedure that isn’t exported; a
1290-parameter of a procedure written in raz. It warns of a variable that is
1291-assigned but never read, too, and of a call standing on its own that
1292-drops a result, as <code>Sys.write(fd, s);</code> does:
1293-<code>_ := Sys.write(fd, s);</code> says it is meant. A name that starts
1294-with <code>_</code> is never warned about. Warnings don’t stop the
1295-compile; <code>raz -Werror</code> makes them errors.</p>
606+<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>
607+<p>Only what can be reached from <code>main</code> and the module bodies goes into the executable: unused procedures, variables and strings are left out. The executable names its procedures and carries line numbers, so that gdb can stop at a line of the source and show where it is.</p>
608+<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, 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. 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>
609+<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. So a module can be compiled on its own, and a program made from modules compiled at different times. Whether an implementation does so, and into what, is its own choice (appendix A); one that does makes the same program as if every module were compiled together, and keeps one copy of each instance.</p>
610+<p><strong>Messages.</strong> The compiler reports an error with its file, line and column, the line of source with the offending part underlined, and, where they help, notes pointing at other places, such as where a name is declared, and a suggestion, such as a name in reach spelled almost alike. It goes on after an error to find the others, up to 20, and writes no executable. After an error it skips the statement or declaration the error is in and carries on with the next; a name that isn’t declared is reported once, and nothing that follows from it is reported. An error in the text itself, such as a string left open, stops the compile, and so does a module with errors, after it.</p>
611+<p>The compiler also warns of what is declared and never used: an import; a constant, type, variable or procedure that isn’t exported; a parameter of a procedure written in raz. It warns of a variable that is assigned but never read, too, and of a call standing on its own that drops a result, as <code>Sys.write(fd, s);</code> does: <code>_ := Sys.write(fd, s);</code> says it is meant. A name that starts with <code>_</code> is never warned about. Warnings don’t stop the compile; <code>raz -Werror</code> makes them errors.</p>
1296612 <h1 id="the-library">11. The library</h1>
1297-<p>Modules written in raz, in the compiler’s <code>lib</code>
1298-directory:</p>
613+<p>Modules written in raz, in the compiler’s <code>lib</code> directory:</p>
1299614 <table>
1300-<colgroup>
1301-<col style="width: 50%" />
1302-<col style="width: 50%" />
1303-</colgroup>
1304615 <thead>
1305-<tr class="header">
616+<tr>
1306617 <th>Module</th>
1307618 <th>What</th>
1308619 </tr>
1309620 </thead>
1310621 <tbody>
1311-<tr class="odd">
622+<tr>
1312623 <td><code>Rt</code></td>
1313-<td>ending the program, <code>exit</code> and <code>atExit</code>;
1314-<code>stop</code>, which ends it with a message; <code>trace</code>, the
1315-calls under way; what the compiler’s checks call when they fail</td>
624+<td>ending the program, <code>exit</code> and <code>atExit</code>; <code>stop</code>, which ends it with a message; <code>trace</code>, the calls under way; what the compiler’s checks call when they fail</td>
1316625 </tr>
1317-<tr class="even">
626+<tr>
1318627 <td><code>Sys</code></td>
1319-<td>system calls: <code>open</code>, <code>openRead</code>,
1320-<code>create</code>, <code>read</code>, <code>write</code>,
1321-<code>seek</code>, <code>close</code>, <code>mmap</code>,
1322-<code>munmap</code>, <code>isTerminal</code>, <code>yield</code>,
1323-<code>exit</code>; files and directories, <code>rename</code>,
1324-<code>remove</code>, <code>removeDir</code>, <code>makeDir</code>,
1325-<code>chmod</code>, <code>symlink</code>, <code>readLink</code>,
1326-<code>info</code>, <code>openDir</code>, <code>nextEntry</code>,
1327-<code>closeDir</code>; the terminal, <code>rawMode</code>,
1328-<code>restoreMode</code>, <code>termSize</code>, <code>ready</code>; the
1329-environment, <code>env</code>, <code>workDir</code>,
1330-<code>setWorkDir</code>; programs, pipes and signals; time,
1331-<code>clock</code>, <code>now</code>, <code>sleep</code>;
1332-<code>random</code>; and sockets. One file per target, and
1333-<code>Sys.raz</code> over the C library for the others</td>
628+<td>system calls: <code>open</code>, <code>openRead</code>, <code>create</code>, <code>read</code>, <code>write</code>, <code>seek</code>, <code>close</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>symlink</code>, <code>readLink</code>, <code>info</code>, <code>openDir</code>, <code>nextEntry</code>, <code>closeDir</code>; the terminal, <code>rawMode</code>, <code>restoreMode</code>, <code>termSize</code>, <code>ready</code>; the environment, <code>env</code>, <code>workDir</code>, <code>setWorkDir</code>; programs, pipes and signals; time, <code>clock</code>, <code>now</code>, <code>sleep</code>; <code>random</code>; and sockets. One file per target, and <code>Sys.raz</code> over the C library for the others</td>
1334629 </tr>
1335-<tr class="odd">
630+<tr>
1336631 <td><code>Out</code></td>
1337-<td>writing text and numbers to standard output, buffered; safe to call
1338-from several threads</td>
632+<td>writing text and numbers to standard output, buffered; safe to call from several threads</td>
1339633 </tr>
1340-<tr class="even">
634+<tr>
1341635 <td><code>C</code></td>
1342-<td>the parts of the C library the others use, and <code>printf</code>,
1343-<code>fflush</code>, <code>stdout</code>, <code>pthread_create</code>; a
1344-program that imports it uses C</td>
636+<td>the parts of the C library the others use, and <code>printf</code>, <code>fflush</code>, <code>stdout</code>, <code>pthread_create</code>; a program that imports it uses C</td>
1345637 </tr>
1346-<tr class="odd">
638+<tr>
1347639 <td><code>Lock</code></td>
1348-<td>a lock for short sections, for C’s threads and <code>Thread</code>’s
1349-alike</td>
640+<td>a lock for short sections, for C’s threads and <code>Thread</code>’s alike</td>
1350641 </tr>
1351-<tr class="even">
642+<tr>
1352643 <td><code>Thread</code></td>
1353-<td>threads for a program without C: <code>spawn</code>,
1354-<code>join</code>, and <code>Mutex</code>; it says
1355-<code>link static</code></td>
644+<td>threads for a program without C: <code>spawn</code>, <code>join</code>, and <code>Mutex</code>; it says <code>link static</code></td>
1356645 </tr>
1357-<tr class="odd">
646+<tr>
1358647 <td><code>Mem</code></td>
1359-<td><code>Allocator</code>, the interface of every allocator, and pages
1360-from the system</td>
648+<td><code>Allocator</code>, the interface of every allocator, and pages from the system</td>
1361649 </tr>
1362-<tr class="even">
650+<tr>
1363651 <td><code>Heap</code></td>
1364-<td>a general allocator, <code>Heap.heap</code>, safe to call from
1365-several threads; freeing a block twice, or one it never gave out, stops
1366-the program</td>
652+<td>a general allocator, <code>Heap.heap</code>, safe to call from several threads; freeing a block twice, or one it never gave out, stops the program</td>
1367653 </tr>
1368-<tr class="odd">
654+<tr>
1369655 <td><code>Arena</code></td>
1370-<td>an allocator that frees everything at once;
1371-<code>ADR(arena.base)</code> is its allocator</td>
656+<td>an allocator that frees everything at once; <code>ADR(arena.base)</code> is its allocator</td>
1372657 </tr>
1373-<tr class="even">
658+<tr>
1374659 <td><code>Str</code></td>
1375-<td>operations on <code>[]U8</code> strings: comparing, hashing,
1376-finding, UTF-8, reading a number</td>
660+<td>operations on <code>[]U8</code> strings: comparing, hashing, finding, UTF-8, reading a number</td>
661+</tr>
662+<tr>
663+<td><code>Bytes</code></td>
664+<td>searches of bytes, many at a time: <code>index</code>, <code>last</code>, <code>count</code> and <code>find</code> in a <code>[]U8</code>; one file per target where the target has instructions for it</td>
1377665 </tr>
1378-<tr class="odd">
666+<tr>
1379667 <td><code>Buf</code></td>
1380668 <td>a growable byte buffer</td>
1381669 </tr>
1382-<tr class="even">
670+<tr>
1383671 <td><code>Fmt</code></td>
1384-<td>formatted output:
1385-<code>Fmt.print("{} of {}\n", [Fmt.int(n), Fmt.real(x, 2)])</code>, or
1386-into a <code>Buf</code> with <code>Fmt.write</code></td>
672+<td>formatted output: <code>Fmt.print("{} of {}\n", [Fmt.int(n), Fmt.real(x, 2)])</code>, or into a <code>Buf</code> with <code>Fmt.write</code></td>
1387673 </tr>
1388-<tr class="odd">
674+<tr>
1389675 <td><code>List</code></td>
1390676 <td>a generic singly linked list, <code>List(T)</code></td>
1391677 </tr>
1392-<tr class="even">
678+<tr>
1393679 <td><code>Map</code></td>
1394680 <td>a generic hash map, <code>Map(K, V; hash, eq)</code></td>
1395681 </tr>
1396-<tr class="odd">
682+<tr>
1397683 <td><code>Sort</code></td>
1398684 <td>sorting a slice in place, <code>Sort(T; less)</code></td>
1399685 </tr>
1400-<tr class="even">
686+<tr>
1401687 <td><code>Math</code></td>
1402-<td>roots, powers, logarithms, rounding and trigonometry, and
1403-<code>pi</code>, for <code>F64</code></td>
688+<td>roots, powers, logarithms, rounding and trigonometry, and <code>pi</code>, for <code>F64</code></td>
1404689 </tr>
1405-<tr class="odd">
690+<tr>
1406691 <td><code>Files</code></td>
1407692 <td>an argument as a string, and a whole file read or written</td>
1408693 </tr>
1409-<tr class="even">
694+<tr>
1410695 <td><code>Opt</code></td>
1411-<td>a command line read through one table, by <code>getopt</code>’s
1412-rules with long options; its help and its mistakes</td>
696+<td>a command line read through one table, by <code>getopt</code>’s rules with long options; its help and its mistakes</td>
1413697 </tr>
1414698 </tbody>
1415699 </table>
1416-<p>Lengths, counts, file descriptors, process ids and statuses are
1417-<code>INT</code>s, and a character is an <code>I32</code>. What may pass
1418-an <code>INT</code> on a small target is an <code>I64</code>: a file’s
1419-size and position, a time in nanoseconds, and a number read from
1420-text.</p>
1421-<p>What follows is each module’s interface, as
1422-<code>tools/Doc.raz</code> prints it from the module’s file;
1423-<code>...</code> stands for fields that are the module’s own. A module’s
1424-<code>main</code>, where it has one, is its test, and is left out
1425-here.</p>
700+<p>Lengths, counts, file descriptors, process ids and statuses are <code>INT</code>s, and a character is an <code>I32</code>. What may pass an <code>INT</code> on a small target is an <code>I64</code>: a file’s size and position, a time in nanoseconds, and a number read from text.</p>
701+<p>What follows is each module’s interface, as <code>tools/Doc.raz</code> prints it from the module’s file; <code>...</code> stands for fields that are the module’s own. A module’s <code>main</code>, where it has one, is its test, and is left out here.</p>
1426702 <pre><code>module Rt;
1427703 const Full*: ERROR = &quot;too many procedures to run at exit&quot;;
1428704 proc atExit*(p: proc): ERROR; (* p run when the program ends by exit *)
1429705 proc exit*(status: INT); (* the atExit procedures, the last first, then the end *)
1430706 proc stop*(msg: []U8); (* msg on standard error, then exit with status 2 *)
1431707 proc trace*; (* the calls under way, and their variables, on standard error *)</code></pre>
1432-<p><code>Rt</code> also holds what the compiler’s checks call when they
1433-fail, and the handlers of the signals that stop a program (section 10).
1434-<code>exit</code> takes each procedure off the list before it runs it,
1435-so it runs once even if it fails or calls <code>exit</code> itself; in a
1436-program that uses C, it ends through C’s <code>exit</code>, so that C
1437-flushes its buffers too.</p>
708+<p><code>Rt</code> also holds what the compiler’s checks call when they fail, and the handlers of the signals that stop a program (section 10). <code>exit</code> takes each procedure off the list before it runs it, so it runs once even if it fails or calls <code>exit</code> itself; in a program that uses C, it ends through C’s <code>exit</code>, so that C flushes its buffers too.</p>
1438709 <pre><code>module Mem;
1439710 type
1440711 Allocator* = record
@@ -1458,11 +729,7 @@
1458729 proc init*(ar: ^Arena; size: INT): BOOL; (* an arena of size bytes; false if the system has none *)
1459730 proc reset*(ar: ^Arena); (* every allocation forgotten; the memory used again *)
1460731 proc done*(ar: ^Arena); (* its memory given back *)</code></pre>
1461-<p><code>NEW(p, a)</code> calls <code>a^.alloc</code>. <code>Heap</code>
1462-keeps blocks of nine sizes, from 16 to 4096 bytes with their header,
1463-each with a list of the free ones; a bigger block gets pages of its own.
1464-An arena hands out memory from one block: its <code>free</code> does
1465-nothing, and <code>reset</code> forgets everything.</p>
732+<p><code>NEW(p, a)</code> calls <code>a^.alloc</code>. <code>Heap</code> keeps blocks of nine sizes, from 16 to 4096 bytes with their header, each with a list of the free ones; a bigger block gets pages of its own. An arena hands out memory from one block: its <code>free</code> does nothing, and <code>reset</code> forgets everything.</p>
1466733 <pre><code>module Lock;
1467734 type Lock* = record ... end;
1468735 proc take*(l: ^Lock);
@@ -1477,13 +744,7 @@
1477744 proc join*(t: ^Thread); (* waits for t to end, then frees its stack *)
1478745 proc lock*(m: ^Mutex);
1479746 proc unlock*(m: ^Mutex);</code></pre>
1480-<p>A <code>Lock</code> is for short sections: a thread that finds it
1481-taken tries again, giving up the processor now and then. A
1482-<code>Mutex</code> sleeps. Each of <code>Thread</code>’s threads runs on
1483-a stack of its own, with a page below it that can’t be touched, so that
1484-running off the stack stops the program. A program that uses C makes its
1485-threads with C’s <code>pthread_create</code>, and so can’t use
1486-<code>Thread</code>.</p>
747+<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. A program that uses C makes its threads with C’s <code>pthread_create</code>, and so can’t use <code>Thread</code>.</p>
1487748 <pre><code>module Out;
1488749 proc str*(s: []U8);
1489750 proc char*(c: U8);
@@ -1491,14 +752,7 @@
1491752 proc int*(n: I64); (* n in decimal *)
1492753 proc hex*(n: U64; digits: INT); (* n in hexadecimal, digits digits at least *)
1493754 proc flush*;</code></pre>
1494-<p><strong>Out and C’s stdio.</strong> <code>Out</code> keeps a buffer
1495-of <code>Sys.outSize</code> bytes, 4 KB on Linux. It writes it out when
1496-it is full, at each line feed when standard output is a terminal, at
1497-<code>Out.flush</code>, and when the program ends by
1498-<code>Rt.exit</code>. A lock keeps what each call writes together when
1499-threads write at once. C’s <code>stdio</code> keeps a buffer of its own
1500-for the same standard output. A program that writes with both flushes
1501-one before writing with the other, or the text comes out of order:</p>
755+<p><strong>Out and C’s stdio.</strong> <code>Out</code> keeps a buffer of <code>Sys.outSize</code> bytes, 4 KB on Linux. It writes it out when it is full, at each line feed when standard output is a terminal, at <code>Out.flush</code>, and when the program ends by <code>Rt.exit</code>. A lock keeps what each call writes together when threads write at once. C’s <code>stdio</code> keeps a buffer of its own for the same standard output. A program that writes with both flushes one before writing with the other, or the text comes out of order:</p>
1502756 <pre><code>module Both;
1503757 import Out, C; (* C: printf, fflush and C&#39;s FILE *stdout *)
1504758
@@ -1512,10 +766,7 @@
1512766 end;
1513767
1514768 end Both.</code></pre>
1515-<p><strong>Sys</strong> gives every target the same procedures, so that
1516-a program that needs only these runs wherever raz does: through system
1517-calls on Linux, through the C library elsewhere. A result that can fail
1518-is a number, minus an errno, as on Linux; 0 is success.</p>
769+<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>
1519770 <pre><code>module Sys;
1520771 const
1521772 stdin* = 0; stdout* = 1; stderr* = 2;
@@ -1616,127 +867,18 @@
1616867 proc listenTcp*(addr: []U8; port: INT): INT;
1617868 proc accept*(fd: INT): INT; (* the next connection, waiting for one *)
1618869 proc send*(fd: INT; s: []U8): INT; (* write, to a socket: -32 (EPIPE), not a signal, if it is closed *)</code></pre>
1619-<p><code>info</code> follows a symbolic link: <code>size</code>,
1620-<code>dir</code> and <code>file</code> are those of what it names, and
1621-<code>symlink</code> says the path was a link, so that a program walking
1622-a tree can choose not to follow one back up it. A link to nothing is
1623-<code>-ENOENT</code>, as a missing file is. <code>file</code> lets a
1624-walk open only what holds data: opening a pipe would wait for a program
1625-to write to it.</p>
1626-<p><code>nextEntry</code> gives every name in the directory except
1627-<code>.</code> and <code>..</code>, in no particular order.
1628-<code>rawMode</code> turns off what the terminal does with keys before
1629-the program reads them: echo, waiting for a whole line, Ctrl-C and
1630-Ctrl-Z as signals, Ctrl-S and Ctrl-Q as flow control, and CR to NL; and
1631-with output, NL to CR NL. A program that turns it on restores it before
1632-it ends: <code>Rt.atExit</code> is the place.</p>
1633-<p><strong>Files.</strong> <code>open</code> gives a file for what
1634-<code>how</code> asks: <code>reading</code>, <code>writing</code> or
1635-both; <code>creating</code> it if it is missing, readable by all and
1636-writable by its owner; with <code>exclusive</code>, failing with -17
1637-(EEXIST) if it is there, as a program does that makes a lock or a file
1638-of its own; <code>truncating</code> it to nothing;
1639-<code>appending</code>, each write going to its end, however other
1640-programs write it too. <code>seek</code> moves to <code>pos</code> from
1641-the start of the file, or from its end if <code>fromEnd</code>, where a
1642-negative <code>pos</code> reads back from the end.
1643-<code>Info.mtime</code> is what a program checks to see whether a file
1644-changed under it; <code>Info.mode</code> holds the nine bits of
1645-<code>rwxrwxrwx</code>, and <code>chmod</code> sets them, 1EDH (755) for
1646-a program, 1A4H (644) for data.</p>
1647-<p><strong>Programs.</strong> <code>openPty</code> makes a
1648-pseudo-terminal, a terminal that a program, a terminal emulator, plays
1649-the screen and the keyboard of: what it writes to the fd is typed, and
1650-what the programs on the terminal write it reads.</p>
1651-<p><code>spawn</code> starts the program at <code>p.path</code>, with
1652-<code>p.args</code> as its arguments, the first being its name. Its
1653-environment is this program’s with each <code>NAME=value</code> of
1654-<code>p.env</code> added or put in place of the old value, or, if
1655-<code>p.onlyEnv</code>, <code>p.env</code> alone. It starts in
1656-<code>p.dir</code>. Its standard input, output and error are
1657-<code>p.fds</code>; a 0 gives it this program’s own, so
1658-<code>{path: "/bin/ls", args: ["ls"]}</code> runs <code>ls</code> as a
1659-shell runs it, with every other field zero. It gets no other open file,
1660-every signal does what it does at first, and none is blocked. If
1661-<code>p.tty</code> is a pseudo-terminal’s fd, the program starts a
1662-session on that terminal: it is its controlling terminal, and its
1663-standard input, output and error, and <code>p.fds</code> and
1664-<code>p.group</code> are not used.</p>
1665-<p><code>p.group</code> puts the program in a process group, the
1666-programs that a shell’s job is made of: -1 makes it the first of a new
1667-group, whose number is its process id, and the other programs of the job
1668-join that number. The terminal gives its keys, and the signals of Ctrl-C
1669-and Ctrl-Z, to one group, the one in its foreground:
1670-<code>p.foreground</code> puts the program’s group there before it
1671-starts, and <code>foreground</code> puts any group there, as a shell
1672-does to take the terminal back. <code>setGroup</code> moves a program to
1673-a group, as the shell does for each program it starts, for whichever of
1674-the two runs first; a shell runs in a group of its own,
1675-<code>setGroup(0, 0)</code>.</p>
1676-<p><code>wait</code> waits for the program <code>pid</code> to change,
1677-or for any of this program’s if <code>pid</code> is -1, and says which
1678-one, and how: <code>exited</code>, with its exit status;
1679-<code>killed</code>, with the number of the signal that ended it; or
1680-<code>stopped</code>, by Ctrl-Z or a signal, with the signal’s number.
1681-Without <code>block</code> it doesn’t wait, and is 0 and
1682-<code>running</code> if no program changed. A program that has nothing
1683-to wait for is -10 (ECHILD). <code>kill</code> sends a program a signal,
1684-<code>sigTerm</code> to end it; to a group, if <code>pid</code> is minus
1685-its number.</p>
1686-<p><strong>Signals.</strong> <code>catch</code> takes the signals
1687-<code>sigs</code> away from what they would do, ending the program most
1688-of them, and gives an fd that is ready to read when one comes, so that a
1689-program waits for signals with <code>ready</code> and
1690-<code>readyOf</code> as it waits for keys or a server.
1691-<code>caught</code> gives each signal that came, in turn. A later
1692-<code>catch</code> adds to the signals caught and gives the same fd.
1693-Catching <code>sigKill</code> or <code>sigStop</code>, or the signals
1694-<code>Rt</code> reports, SIGSEGV and SIGFPE, is -22 (EINVAL).
1695-<code>ignore</code> makes a signal do nothing, as a shell ignores
1696-<code>sigTtou</code> so that it can take its terminal back, and
1697-<code>ignore(sig, false)</code> gives it back what it does at first. A
1698-program that <code>spawn</code> starts begins with neither.</p>
1699-<p><strong>Time.</strong> <code>clock</code> is for measuring how long
1700-something takes: it never goes back, and says nothing of the date.
1701-<code>now</code> is the date and time, which a person or the network may
1702-set back. <code>sleep</code> waits <code>ms</code> milliseconds.</p>
1703-<p><strong>Sockets.</strong> <code>connect</code> is for talking to a
1704-server on the same machine, an X server at
1705-<code>/tmp/.X11-unix/X0</code> say; <code>connectTcp</code> for one
1706-across the network, given its address as numbers,
1707-<code>"127.0.0.1"</code> or <code>"::1"</code>: turning a name into an
1708-address is a library’s work over these. <code>connectUdp</code> gives a
1709-socket of datagrams, each <code>send</code> one message to that address
1710-and each <code>read</code> one message from it, as a program asks a name
1711-server. What a socket receives comes by <code>read</code>, what it sends
1712-goes by <code>send</code>, and <code>close</code> ends it.
1713-<code>send</code> is <code>write</code> for a socket, except when the
1714-other end has closed it: <code>write</code> would stop the program with
1715-the signal SIGPIPE, where <code>send</code> returns -32 (EPIPE), so that
1716-a program learns its server has gone and can end as it wants.
1717-<code>listen</code> and <code>listenTcp</code> are the other side: a
1718-server’s socket, on <code>path</code>, which must not be there yet, or
1719-on <code>port</code> at <code>addr</code>, <code>"0.0.0.0"</code> or
1720-<code>"::"</code> for every address the machine has; <code>accept</code>
1721-gives each connection that comes, as a socket of its own.</p>
1722-<p><code>readyOf</code> waits on several file descriptors at once, as a
1723-program does that listens to a server and a terminal both; a descriptor
1724-at its end, or failed, counts as ready, since a read of it won’t wait.
1725-It looks at the first 64 of <code>fds</code>, and <code>connect</code>
1726-and <code>listen</code> take a path of at most 107 bytes, as
1727-<code>struct sockaddr_un</code> holds; a longer one is -36
1728-(ENAMETOOLONG).</p>
1729-<p>A program that both reads from a descriptor and writes much to it, as
1730-a terminal writes what is pasted to its program while it reads what the
1731-program writes back, must not wait on either: the program may be waiting
1732-for its own writes to be read. <code>setBlocking(fd, false)</code> has a
1733-read or a write on <code>fd</code> that would wait return -11 (EAGAIN)
1734-at once, a write having written what there was room for;
1735-<code>readyFor</code> waits, as <code>readyOf</code> does, for something
1736-to read on any of <code>reads</code> or for room to write on any of
1737-<code>writes</code>. A descriptor in both is given once, when it is
1738-ready for either; the 64 it looks at are <code>reads</code>, then
1739-<code>writes</code>.</p>
870+<p><code>info</code> follows a symbolic link: <code>size</code>, <code>dir</code> and <code>file</code> are those of what it names, and <code>symlink</code> says the path was a link, so that a program walking a tree can choose not to follow one back up it. A link to nothing is <code>-ENOENT</code>, as a missing file is. <code>file</code> lets a walk open only what holds data: opening a pipe would wait for a program to write to it.</p>
871+<p><code>nextEntry</code> gives every name in the directory except <code>.</code> and <code>..</code>, in no particular order. <code>rawMode</code> turns off what the terminal does with keys before the program reads them: echo, waiting for a whole line, Ctrl-C and Ctrl-Z as signals, Ctrl-S and Ctrl-Q as flow control, and CR to NL; and with output, NL to CR NL. A program that turns it on restores it before it ends: <code>Rt.atExit</code> is the place.</p>
872+<p><strong>Files.</strong> <code>open</code> gives a file for what <code>how</code> asks: <code>reading</code>, <code>writing</code> or both; <code>creating</code> it if it is missing, readable by all and writable by its owner; with <code>exclusive</code>, failing with -17 (EEXIST) if it is there, as a program does that makes a lock or a file of its own; <code>truncating</code> it to nothing; <code>appending</code>, each write going to its end, however other programs write it too. <code>seek</code> moves to <code>pos</code> from the start of the file, or from its end if <code>fromEnd</code>, where a negative <code>pos</code> reads back from the end. <code>Info.mtime</code> is what a program checks to see whether a file changed under it; <code>Info.mode</code> holds the nine bits of <code>rwxrwxrwx</code>, and <code>chmod</code> sets them, 1EDH (755) for a program, 1A4H (644) for data.</p>
873+<p><strong>Programs.</strong> <code>openPty</code> makes a pseudo-terminal, a terminal that a program, a terminal emulator, plays the screen and the keyboard of: what it writes to the fd is typed, and what the programs on the terminal write it reads.</p>
874+<p><code>spawn</code> starts the program at <code>p.path</code>, with <code>p.args</code> as its arguments, the first being its name. Its environment is this program’s with each <code>NAME=value</code> of <code>p.env</code> added or put in place of the old value, or, if <code>p.onlyEnv</code>, <code>p.env</code> alone. It starts in <code>p.dir</code>. Its standard input, output and error are <code>p.fds</code>; a 0 gives it this program’s own, so <code>{path: "/bin/ls", args: ["ls"]}</code> runs <code>ls</code> as a shell runs it, with every other field zero. It gets no other open file, every signal does what it does at first, and none is blocked. If <code>p.tty</code> is a pseudo-terminal’s fd, the program starts a session on that terminal: it is its controlling terminal, and its standard input, output and error, and <code>p.fds</code> and <code>p.group</code> are not used.</p>
875+<p><code>p.group</code> puts the program in a process group, the programs that a shell’s job is made of: -1 makes it the first of a new group, whose number is its process id, and the other programs of the job join that number. The terminal gives its keys, and the signals of Ctrl-C and Ctrl-Z, to one group, the one in its foreground: <code>p.foreground</code> puts the program’s group there before it starts, and <code>foreground</code> puts any group there, as a shell does to take the terminal back. <code>setGroup</code> moves a program to a group, as the shell does for each program it starts, for whichever of the two runs first; a shell runs in a group of its own, <code>setGroup(0, 0)</code>.</p>
876+<p><code>wait</code> waits for the program <code>pid</code> to change, or for any of this program’s if <code>pid</code> is -1, and says which one, and how: <code>exited</code>, with its exit status; <code>killed</code>, with the number of the signal that ended it; or <code>stopped</code>, by Ctrl-Z or a signal, with the signal’s number. Without <code>block</code> it doesn’t wait, and is 0 and <code>running</code> if no program changed. A program that has nothing to wait for is -10 (ECHILD). <code>kill</code> sends a program a signal, <code>sigTerm</code> to end it; to a group, if <code>pid</code> is minus its number.</p>
877+<p><strong>Signals.</strong> <code>catch</code> takes the signals <code>sigs</code> away from what they would do, ending the program most of them, and gives an fd that is ready to read when one comes, so that a program waits for signals with <code>ready</code> and <code>readyOf</code> as it waits for keys or a server. <code>caught</code> gives each signal that came, in turn. A later <code>catch</code> adds to the signals caught and gives the same fd. Catching <code>sigKill</code> or <code>sigStop</code>, or the signals <code>Rt</code> reports, SIGSEGV and SIGFPE, is -22 (EINVAL). <code>ignore</code> makes a signal do nothing, as a shell ignores <code>sigTtou</code> so that it can take its terminal back, and <code>ignore(sig, false)</code> gives it back what it does at first. A program that <code>spawn</code> starts begins with neither.</p>
878+<p><strong>Time.</strong> <code>clock</code> is for measuring how long something takes: it never goes back, and says nothing of the date. <code>now</code> is the date and time, which a person or the network may set back. <code>sleep</code> waits <code>ms</code> milliseconds.</p>
879+<p><strong>Sockets.</strong> <code>connect</code> is for talking to a server on the same machine, an X server at <code>/tmp/.X11-unix/X0</code> say; <code>connectTcp</code> for one across the network, given its address as numbers, <code>"127.0.0.1"</code> or <code>"::1"</code>: turning a name into an address is a library’s work over these. <code>connectUdp</code> gives a socket of datagrams, each <code>send</code> one message to that address and each <code>read</code> one message from it, as a program asks a name server. What a socket receives comes by <code>read</code>, what it sends goes by <code>send</code>, and <code>close</code> ends it. <code>send</code> is <code>write</code> for a socket, except when the other end has closed it: <code>write</code> would stop the program with the signal SIGPIPE, where <code>send</code> returns -32 (EPIPE), so that a program learns its server has gone and can end as it wants. <code>listen</code> and <code>listenTcp</code> are the other side: a server’s socket, on <code>path</code>, which must not be there yet, or on <code>port</code> at <code>addr</code>, <code>"0.0.0.0"</code> or <code>"::"</code> for every address the machine has; <code>accept</code> gives each connection that comes, as a socket of its own.</p>
880+<p><code>readyOf</code> waits on several file descriptors at once, as a program does that listens to a server and a terminal both; a descriptor at its end, or failed, counts as ready, since a read of it won’t wait. It looks at the first 64 of <code>fds</code>, and <code>connect</code> and <code>listen</code> take a path of at most 107 bytes, as <code>struct sockaddr_un</code> holds; a longer one is -36 (ENAMETOOLONG).</p>
881+<p>A program that both reads from a descriptor and writes much to it, as a terminal writes what is pasted to its program while it reads what the program writes back, must not wait on either: the program may be waiting for its own writes to be read. <code>setBlocking(fd, false)</code> has a read or a write on <code>fd</code> that would wait return -11 (EAGAIN) at once, a write having written what there was room for; <code>readyFor</code> waits, as <code>readyOf</code> does, for something to read on any of <code>reads</code> or for room to write on any of <code>writes</code>. A descriptor in both is given once, when it is ready for either; the 64 it looks at are <code>reads</code>, then <code>writes</code>.</p>
1740882 <p><strong>Strings, buffers and collections.</strong></p>
1741883 <pre><code>module Str;
1742884 proc cmp*(a, b: []U8): INT; (* -1, 0 or 1 as a sorts before, with or after b, byte by byte *)
@@ -1815,49 +957,19 @@
1815957 proc acos*(x: F64): F64; (* from 0 to pi *)
1816958 proc atan*(x: F64): F64; (* from -pi/2 to pi/2 *)
1817959 proc atan2*(y, x: F64): F64; (* the angle of (x, y) from the x axis, from -pi to pi *)</code></pre>
1818-<p>A <code>Buf</code>, a <code>List</code> and a <code>Map</code> take
1819-their memory from the allocator <code>init</code> gives them.
1820-<code>Fmt</code>’s format takes the next argument at each
1821-<code>{}</code>; <code>{{</code> and <code>}}</code> stand for
1822-<code>{</code> and <code>}</code>. A <code>Map</code> hashes and
1823-compares its keys with the procedures it is given:
1824-<code>import Count := Map([]U8, INT, Str.hash, Str.eq);</code>.</p>
1825-<p><code>Str</code> reads and writes UTF-8. <code>encode</code> writes a
1826-character, of at most 10FFFFH, in one to four bytes; a number that isn’t
1827-one becomes FFFDH, the character that stands for a wrong one.
1828-<code>decode</code> reads the first character of <code>s</code>, and
1829-gives FFFDH and 1 for a byte that doesn’t start one rightly, and 0 and 0
1830-for an empty <code>s</code>. <code>toInt</code> reads a decimal number,
1831-with a <code>-</code> or <code>+</code> before it if any, and nothing
1832-else.</p>
1833-<p><code>le</code> and <code>be</code> read an unsigned number of up to
1834-8 bytes in a fixed order, little-endian or big-endian, whatever the
1835-machine’s own, and <code>putLE</code> and <code>putBE</code> write one;
1836-more than 8 bytes stops the program. They are how a file format or a
1837-network protocol is read and written:</p>
960+<p>A <code>Buf</code>, a <code>List</code> and a <code>Map</code> take their memory from the allocator <code>init</code> gives them. <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>
961+<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>. <code>toInt</code> reads a decimal number, with a <code>-</code> or <code>+</code> before it if any, and nothing else.</p>
962+<p><code>le</code> and <code>be</code> read an unsigned number of up to 8 bytes in a fixed order, little-endian or big-endian, whatever the machine’s own, and <code>putLE</code> and <code>putBE</code> write one; more than 8 bytes stops the program. They are how a file format or a network protocol is read and written:</p>
1838963 <pre><code>len := U32(Str.le(header[4..8]));
1839964 Str.putBE(packet[0..2], U64(port));</code></pre>
1840-<p><code>Map.next</code> walks a map: from 0, it gives the next entry
1841-and the number to pass for the one after it, and -1 when there are no
1842-more. A walk sees each entry once if the map doesn’t change during
1843-it:</p>
965+<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>
1844966 <pre><code>i, k, v := Names.next(ADR(names), 0);
1845967 while i &gt;= 0 do
1846968 Fmt.print(&quot;{} is {}\n&quot;, [Fmt.str(k), Fmt.int(v)]);
1847969 i, k, v := Names.next(ADR(names), i);
1848970 end;</code></pre>
1849-<p><code>Sort.sort</code> puts <code>s</code> in the order
1850-<code>less</code> gives, in place, without memory of its own, in time
1851-<code>n log n</code> at most; two elements equal by <code>less</code>
1852-may change places. <code>Math</code>’s procedures are as C’s
1853-<code>math.h</code> has them, to within the last bit or so.
1854-<code>Fmt.real(x, places)</code> writes <code>x</code> with
1855-<code>places</code> digits after the point, at most 9, rounded to the
1856-nearest; from 1e15 on, with an exponent, as <code>1.50e17</code>; and
1857-<code>nan</code>, <code>inf</code> and <code>-inf</code> as
1858-themselves.</p>
1859-<p><strong>Files and Opt</strong> are what most programs need of their
1860-command line.</p>
971+<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>
972+<p><strong>Files and Opt</strong> are what most programs need of their command line.</p>
1861973 <pre><code>module Files;
1862974 proc arg*(i: INT): []U8; (* argument i; 0 is the program&#39;s name *)
1863975 proc read*(path: []U8; b: ^Buf.Buf): BOOL; (* the whole file added to b *)
@@ -1882,24 +994,8 @@
1882994 proc scope*(p: ^Parser; name: []U8); (* subcommand name&#39;s options, from the word after it *)
1883995 proc number*(p: ^Parser; lo, hi: I64): I64; (* the value just read, a number from lo to hi *)
1884996 proc fail*(p: ^Parser; text: []U8); (* the program&#39;s own mistake *)</code></pre>
1885-<p><code>Opt</code> reads a command line by the rules of the C library’s
1886-<code>getopt</code>, with GNU’s long options, so that a program’s
1887-options behave as every other Unix program’s. The program describes
1888-itself once, in a table of <code>Row</code>s: its synopsis lines, its
1889-subcommands and its options. The help and the messages for mistakes are
1890-made from the table, so they can’t drift from it; the program’s test of
1891-<code>p.letter</code> is the only other place an option appears. The
1892-parser is a record the program owns, and the table a slice it keeps as
1893-long as the parser: a literal written in the call to <code>init</code>
1894-lives as long as the procedure that makes it.</p>
1895-<p>A row’s <code>scope</code> is <code>""</code> for the program itself,
1896-or a subcommand’s name: <code>"start"</code>, or
1897-<code>"remote.add"</code> for a subcommand of <code>remote</code>. An
1898-option has a <code>letter</code>, a <code>long</code> name, or both. One
1899-with a long name only has a key of its own below <code>'!'</code> for a
1900-letter, so that the program can tell it from the others. With a
1901-<code>value</code>, the name the help and the messages give it, the
1902-option takes a value; with <code>""</code> it is a flag.</p>
997+<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>
998+<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.</p>
1903999 <pre><code>const wait = 1; (* the key of --wait, which has no letter *)
19041000 ...
19051001 Opt.init(ADR(p), &quot;keep&quot;, [
@@ -1923,250 +1019,65 @@
19231019 job, ok := Opt.operand(ADR(p));</code></pre>
19241020 <p>The rules are <code>getopt</code>’s:</p>
19251021 <ul>
1926-<li>Flags may share a dash: <code>-lw</code> is <code>-l -w</code>. A
1927-letter’s value is the rest of its word, <code>-bdev</code>, or the whole
1928-next word, <code>-b dev</code>, even one that starts with a dash or is
1929-empty; in a group, the first letter that takes a value takes the rest,
1930-<code>-qn12</code>.</li>
1931-<li>A long option is written in full, with its value after a
1932-<code>=</code> or in the next word: <code>--bar=dev</code>,
1933-<code>--bar dev</code>. An abbreviation is unknown, not guessed, so that
1934-adding an option never breaks a script. A value given to a flag,
1935-<code>--follow=x</code>, is a mistake.</li>
1936-<li><code>--</code> ends the options, and isn’t an operand;
1937-<code>-</code> alone is one. The options end at the first operand, so in
1938-<code>keep start site python -m http.server</code> the <code>-m</code>
1939-is python’s.</li>
1940-<li>Each scope has its own options. An option given twice is read
1941-twice.</li>
1022+<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>
1023+<li>A long option is written in full, with its value after a <code>=</code> or in the next word: <code>--bar=dev</code>, <code>--bar dev</code>. An abbreviation is unknown, not guessed, so that adding an option never breaks a script. A value given to a flag, <code>--follow=x</code>, is a mistake.</li>
1024+<li><code>--</code> ends the options, and isn’t an operand; <code>-</code> alone is one. The options end at the first operand, so in <code>keep start site python -m http.server</code> the <code>-m</code> is python’s.</li>
1025+<li>Each scope has its own options. An option given twice is read twice.</li>
19421026 </ul>
1943-<p><code>number</code> reads the value as <code>Str.toInt</code> does.
1944-<code>operand</code> reads what options are left first, and the program
1945-doesn’t see them.</p>
1946-<p><code>-h</code> or <code>--help</code> among a scope’s options prints
1947-its help on standard output and ends the program with status 0.
1948-<code>init</code> and <code>scope</code> answer it, looking through the
1949-scope’s options before <code>next</code> gives one, so that the program
1950-has done nothing yet: <code>keep -v -h -x</code> prints the help, and
1951-the program never sees <code>-v</code>, nor the mistake. The help is the
1952-scope’s synopsis lines, a blank line, and its subcommands, its options
1953-and the help itself, each with its line of help:</p>
1027+<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.</p>
1028+<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>
19541029 <pre><code>usage: keep start [-b label] name command [argument ...]
19551030
19561031 -b, --bar label show the job in the bar as label
19571032 -h, --help print this and exit</code></pre>
1958-<p>A scope with several synopsis lines has the others indented under the
1959-first; one with none, <code>usage:</code> and its words, as
1960-<code>usage: keep start</code>.</p>
1961-<p>A mistake on the command line is a sentence on standard error, the
1962-program’s name first, then the scope’s synopsis lines, as the help
1963-begins, and status 2:</p>
1033+<p>A scope with several synopsis lines has the others indented under the first; one with none, <code>usage:</code> and its words, as <code>usage: keep start</code>.</p>
1034+<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>
19641035 <pre><code>keep: unknown option -x
19651036 usage: keep start [-b label] name command [argument ...]</code></pre>
1966-<p>The sentences are <code>unknown option -x</code> (or
1967-<code>--name</code>, up to its <code>=</code>),
1968-<code>-b needs a label</code>, <code>--follow takes no value</code> and
1969-<code>--wait wants a number from 1 to 600, not '0'</code>.
1970-<code>fail</code> writes the program’s own mistakes the same way, but
1971-alone, so that the sentence can say where the help is:
1972-<code>keep: no command; see keep -h</code>.</p>
1973-<p>A mistake in the table is the program’s, not its user’s.
1974-<code>init</code> checks the table before it reads a word, and ends the
1975-program with status 1:
1976-<code>keep: option table, row 3: the option is in the scope already</code>.
1977-The others are an option with neither a letter nor a long name, a long
1978-name with <code>=</code> in it, a letter <code>-</code>, and
1979-<code>-h</code> or <code>--help</code> in the table, since they are
1980-<code>Opt</code>’s.</p>
1037+<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>. <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>
1038+<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>, and <code>-h</code> or <code>--help</code> in the table, since they are <code>Opt</code>’s.</p>
19811039 <h1 id="versions">12. Versions</h1>
1982-<p>A version of this report is named by the month it was made in and a
1983-count: <code>2026-10.0</code>, then <code>2026-10.1</code> for the next
1984-change that month. <code>raz --version</code> says which version the
1985-compiler follows.</p>
1040+<p>A version of this report is named by the month it was made in and a count: <code>2026-10.0</code>, then <code>2026-10.1</code> for the next change that month. <code>raz --version</code> says which version the compiler follows.</p>
19861041 <ul>
1987-<li><strong>2026-10.0.</strong> The first numbered version: the language
1988-of compiler 0.3.0.</li>
1989-<li><strong>2026-10.1.</strong> Messages: every error in a run, warnings
1990-of what is never used and <code>-Werror</code> (section 10); failed
1991-checks say what failed, and signals say where (sections 6.5 and
1992-10).</li>
1993-<li><strong>2026-10.2.</strong> <code>Sys</code> gains files and
1994-directories, the terminal, and the environment (section 11).</li>
1995-<li><strong>2026-10.3.</strong> <code>return f(x);</code> passes on the
1996-several results of <code>f</code> (sections 7.3 and 8).
1997-<code>and</code>, <code>or</code> and <code>not</code> are for
1998-<code>BOOL</code>s, and bind below the relations; <code>&amp;</code>,
1999-<code>|</code> and <code>~</code> are the operators on bits, and
2000-<code>xor</code> is for integers only (sections 2 and 6). Arrays and
2001-slices of integers, <code>BOOL</code>s, enumerations, sets and pointers
2002-compare with <code>=</code>, by code where the comparison stands, not by
2003-a call into <code>Rt</code> (section 6.5). A generic module’s instance
2004-is made where it is first used, so its arguments may name types declared
2005-after the imports (section 3).</li>
2006-<li><strong>2026-10.4.</strong> <code>Sys</code> gains a connection to a
2007-Unix socket, waiting on several files at once, pseudo-terminals, and
2008-starting, waiting for and stopping programs (section 11).</li>
2009-<li><strong>2026-10.5.</strong> A module with files in more than one of
2010-the directories searched is an error, unless the first is a link to one
2011-of the others (section 3).</li>
2012-<li><strong>2026-10.6.</strong> <code>Sys.Info</code> says whether the
2013-path is a regular file, and whether it is a symbolic link (section
2014-11).</li>
2015-<li><strong>2026-10.7.</strong> <code>Sys.send</code> writes to a socket
2016-without SIGPIPE (section 11).</li>
2017-<li><strong>2026-10.8.</strong> <code>Sys.workDir</code> returns the
2018-directory, with no <code>var</code> parameter (section 11).</li>
2019-<li><strong>2026-10.9.</strong> The language is frozen (the start of the
2020-report). <code>Sys</code> gains opening a file for any use, seeking,
2021-links, permissions and times; pipes, process groups and the terminal’s
2022-foreground; signals caught on a file descriptor; clocks, sleeping and
2023-random bytes; and network sockets. <code>Sys.spawn</code> takes a
2024-<code>Program</code>, and <code>Sys.wait</code> says which program
2025-changed and how. <code>Str</code> gains UTF-8 and reading a number,
2026-<code>Map</code> removing and walking, <code>Fmt</code> reals;
2027-<code>Sort</code>, <code>Math</code>, <code>Files</code> and
2028-<code>Opt</code> are new (section 11).</li>
2029-<li><strong>2026-10.10.</strong> Said at last: what the compiler did and
2030-the report didn’t say, all through; what an implementation chooses, and
2031-the core every target has (appendix A); the whole grammar (appendix B);
2032-the library’s module names are kept for it (section 3); a record,
2033-variant or enumeration is a type of its own wherever it is written
2034-(section 5.10); a <code>nil</code> pointer, a division by zero and a
2035-stack overflow stop the program on every target (section 10); byte order
2036-is the target’s, and <code>Str</code> reads and writes a fixed one
2037-(sections 5.5 and 11); <code>Out</code>’s buffer is
2038-<code>Sys.outSize</code> bytes (section 11). Changed: a field of a
2039-packed record that may be misaligned has no address and no volatile
2040-access (section 5.5). Mended: arithmetic on untyped constants that
2041-overflows is an error (section 2); a slice of a pointer can’t run
2042-backwards (section 6.4). Ordinary accesses are no longer promised to be
2043-made exactly as written, only volatile and atomic ones (section
2044-7.6).</li>
2045-<li><strong>2026-10.11.</strong> <code>INT</code> and <code>UINT</code>,
2046-as big as an address, are the integers of lengths, slices, pointer
2047-differences, pointer conversions, <code>SYSCALL</code> and
2048-<code>ARGC</code>; <code>SIZE</code> and a constant <code>LEN</code> are
2049-untyped; <code>INT</code> widens silently to <code>I64</code> and
2050-<code>UINT</code> to <code>U64</code>, but neither mixes with them in an
2051-expression or a <code>for</code> (sections 5, 6.1 and 7.2);
2052-<code>Mem.Allocator</code> takes <code>INT</code> sizes. Pointers,
2053-procedures, <code>ERROR</code>s, slices and variants’ tags are sized by
2054-the address, and basic types aligned as the target’s C aligns them
2055-(section 5). Reals are a target’s to have or not (section 5.1). An
2056-exported variable can’t be changed, passed by <code>var</code> or
2057-addressed outside its module, nor an array in it sliced (section 3).
2058-<code>check off;</code> leaves a module’s index and slice checks out
2059-(sections 3, 6.4 and 6.5). An index of any integer type is checked by
2060-its value (6.5). A shift counts modulo its operand’s width, and the
2061-smallest value of every signed type divided by -1 stops the program
2062-(6.1). Writing a string’s bytes isn’t defined (5.10). The atomic
2063-built-ins work on <code>INT</code>, <code>UINT</code> and pointers
2064-(6.8). An integer constant past an extern’s parameters goes as an
2065-<code>INT</code> (9). An importer depends only on a module’s interface,
2066-so a module can be compiled on its own; whether it is, and into what, is
2067-the implementation’s (sections 3 and 10; appendix A). The library takes
2068-and gives <code>INT</code> for lengths, counts, descriptors, process ids
2069-and statuses, <code>main</code>’s and <code>Rt.exit</code>’s among them,
2070-and <code>I32</code> for a character; <code>I64</code> stays for what
2071-may pass an <code>INT</code> on a small target: a file’s size and
2072-position, times, and numbers read from text (section 11). An array
2073-constant has a type and is used as a variable that can’t be changed;
2074-<code>+</code> joins string constants (section 4). <code>match</code>
2075-takes an integer, with constants and ranges as labels (7.4).</li>
2076-<li><strong>2026-10.12.</strong> A code procedure is written in the
2077-target’s assembly language, not as bytes (section 8; appendix A). A
2078-program that stops says the calls under way and their variables, and
2079-<code>Rt.trace</code> says them on demand (sections 10 and 11).</li>
2080-<li><strong>2026-10.13.</strong> <code>Sys</code> gains writing without
2081-waiting, and waiting for room to write (section 11).</li>
2082-<li><strong>2026-10.14.</strong> The blank, <code>_</code>, drops a
2083-value or one of several results (section 7.1); a call that drops a
2084-result is warned of (section 10).</li>
2085-<li><strong>2026-10.15.</strong> <code>Math</code> gains
2086-<code>pow</code>, <code>ceil</code>, <code>round</code>,
2087-<code>log2</code>, <code>log10</code>, <code>tan</code>,
2088-<code>asin</code>, <code>acos</code> and <code>atan</code>;
2089-<code>Sys</code> gains <code>space</code> (section 11).</li>
2090-<li><strong>2026-10.16.</strong> Record constants, and array and record
2091-constants of records, strings, procedures and more (section 4);
2092-<code>Str</code> gains <code>copy</code> (section 11).</li>
2093-<li><strong>2026-10.17.</strong> <code>COPY</code> copies the elements
2094-of one array or slice to another as a block (section 6.8).</li>
1042+<li><strong>2026-10.0.</strong> The first numbered version: the language of compiler 0.3.0.</li>
1043+<li><strong>2026-10.1.</strong> Messages: every error in a run, warnings of what is never used and <code>-Werror</code> (section 10); failed checks say what failed, and signals say where (sections 6.5 and 10).</li>
1044+<li><strong>2026-10.2.</strong> <code>Sys</code> gains files and directories, the terminal, and the environment (section 11).</li>
1045+<li><strong>2026-10.3.</strong> <code>return f(x);</code> passes on the several results of <code>f</code> (sections 7.3 and 8). <code>and</code>, <code>or</code> and <code>not</code> are for <code>BOOL</code>s, and bind below the relations; <code>&amp;</code>, <code>|</code> and <code>~</code> are the operators on bits, and <code>xor</code> is for integers only (sections 2 and 6). Arrays and slices of integers, <code>BOOL</code>s, enumerations, sets and pointers compare with <code>=</code>, by code where the comparison stands, not by a call into <code>Rt</code> (section 6.5). A generic module’s instance is made where it is first used, so its arguments may name types declared after the imports (section 3).</li>
1046+<li><strong>2026-10.4.</strong> <code>Sys</code> gains a connection to a Unix socket, waiting on several files at once, pseudo-terminals, and starting, waiting for and stopping programs (section 11).</li>
1047+<li><strong>2026-10.5.</strong> A module with files in more than one of the directories searched is an error, unless the first is a link to one of the others (section 3).</li>
1048+<li><strong>2026-10.6.</strong> <code>Sys.Info</code> says whether the path is a regular file, and whether it is a symbolic link (section 11).</li>
1049+<li><strong>2026-10.7.</strong> <code>Sys.send</code> writes to a socket without SIGPIPE (section 11).</li>
1050+<li><strong>2026-10.8.</strong> <code>Sys.workDir</code> returns the directory, with no <code>var</code> parameter (section 11).</li>
1051+<li><strong>2026-10.9.</strong> The language is frozen (the start of the report). <code>Sys</code> gains opening a file for any use, seeking, links, permissions and times; pipes, process groups and the terminal’s foreground; signals caught on a file descriptor; clocks, sleeping and random bytes; and network sockets. <code>Sys.spawn</code> takes a <code>Program</code>, and <code>Sys.wait</code> says which program changed and how. <code>Str</code> gains UTF-8 and reading a number, <code>Map</code> removing and walking, <code>Fmt</code> reals; <code>Sort</code>, <code>Math</code>, <code>Files</code> and <code>Opt</code> are new (section 11).</li>
1052+<li><strong>2026-10.10.</strong> Said at last: what the compiler did and the report didn’t say, all through; what an implementation chooses, and the core every target has (appendix A); the whole grammar (appendix B); the library’s module names are kept for it (section 3); a record, variant or enumeration is a type of its own wherever it is written (section 5.10); a <code>nil</code> pointer, a division by zero and a stack overflow stop the program on every target (section 10); byte order is the target’s, and <code>Str</code> reads and writes a fixed one (sections 5.5 and 11); <code>Out</code>’s buffer is <code>Sys.outSize</code> bytes (section 11). Changed: a field of a packed record that may be misaligned has no address and no volatile access (section 5.5). Mended: arithmetic on untyped constants that overflows is an error (section 2); a slice of a pointer can’t run backwards (section 6.4). Ordinary accesses are no longer promised to be made exactly as written, only volatile and atomic ones (section 7.6).</li>
1053+<li><strong>2026-10.11.</strong> <code>INT</code> and <code>UINT</code>, as big as an address, are the integers of lengths, slices, pointer differences, pointer conversions, <code>SYSCALL</code> and <code>ARGC</code>; <code>SIZE</code> and a constant <code>LEN</code> are untyped; <code>INT</code> widens silently to <code>I64</code> and <code>UINT</code> to <code>U64</code>, but neither mixes with them in an expression or a <code>for</code> (sections 5, 6.1 and 7.2); <code>Mem.Allocator</code> takes <code>INT</code> sizes. Pointers, procedures, <code>ERROR</code>s, slices and variants’ tags are sized by the address, and basic types aligned as the target’s C aligns them (section 5). Reals are a target’s to have or not (section 5.1). An exported variable can’t be changed, passed by <code>var</code> or addressed outside its module, nor an array in it sliced (section 3). <code>check off;</code> leaves a module’s index and slice checks out (sections 3, 6.4 and 6.5). An index of any integer type is checked by its value (6.5). A shift counts modulo its operand’s width, and the smallest value of every signed type divided by -1 stops the program (6.1). Writing a string’s bytes isn’t defined (5.10). The atomic built-ins work on <code>INT</code>, <code>UINT</code> and pointers (6.8). An integer constant past an extern’s parameters goes as an <code>INT</code> (9). An importer depends only on a module’s interface, so a module can be compiled on its own; whether it is, and into what, is the implementation’s (sections 3 and 10; appendix A). The library takes and gives <code>INT</code> for lengths, counts, descriptors, process ids and statuses, <code>main</code>’s and <code>Rt.exit</code>’s among them, and <code>I32</code> for a character; <code>I64</code> stays for what may pass an <code>INT</code> on a small target: a file’s size and position, times, and numbers read from text (section 11). An array constant has a type and is used as a variable that can’t be changed; <code>+</code> joins string constants (section 4). <code>match</code> takes an integer, with constants and ranges as labels (7.4).</li>
1054+<li><strong>2026-10.12.</strong> A code procedure is written in the target’s assembly language, not as bytes (section 8; appendix A). A program that stops says the calls under way and their variables, and <code>Rt.trace</code> says them on demand (sections 10 and 11).</li>
1055+<li><strong>2026-10.13.</strong> <code>Sys</code> gains writing without waiting, and waiting for room to write (section 11).</li>
1056+<li><strong>2026-10.14.</strong> The blank, <code>_</code>, drops a value or one of several results (section 7.1); a call that drops a result is warned of (section 10).</li>
1057+<li><strong>2026-10.15.</strong> <code>Math</code> gains <code>pow</code>, <code>ceil</code>, <code>round</code>, <code>log2</code>, <code>log10</code>, <code>tan</code>, <code>asin</code>, <code>acos</code> and <code>atan</code>; <code>Sys</code> gains <code>space</code> (section 11).</li>
1058+<li><strong>2026-10.16.</strong> Record constants, and array and record constants of records, strings, procedures and more (section 4); <code>Str</code> gains <code>copy</code> (section 11).</li>
1059+<li><strong>2026-10.17.</strong> <code>COPY</code> copies the elements of one array or slice to another as a block (section 6.8).</li>
1060+<li><strong>2026-10.18.</strong> A code procedure takes and returns slices (section 8).</li>
1061+<li><strong>2026-10.19.</strong> The library gains <code>Bytes</code> (section 11).</li>
20951062 </ul>
2096-<h1 id="appendix-a.-what-an-implementation-chooses">Appendix A. What an
2097-implementation chooses</h1>
2098-<p>Everything in this report binds every implementation of raz, except
2099-what follows, which each chooses for itself and documents. This
2100-compiler’s choices are in <code>doc/compiler.md</code>, under “This
2101-compiler’s choices”. The programs in <code>conform/</code> are how an
2102-implementation shows that it follows this report: it passes them all,
2103-its reals aside where its target has none; <code>conform/check.sh</code>
2104-runs them.</p>
1063+<h1 id="appendix-a.-what-an-implementation-chooses">Appendix A. What an implementation chooses</h1>
1064+<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>
21051065 <ul>
2106-<li><strong>The target.</strong> Which machines and systems it compiles
2107-for, and the names of their files (<code>linux-x86_64</code>, section
2108-3); for each, the size of an address, and so of <code>INT</code>, and
2109-whether it has reals.</li>
2110-<li><strong>Separate compilation.</strong> Whether modules are compiled
2111-on their own, and if so into what: the object file, its format, the form
2112-of the code in it, when one is out of date, and how an instance is named
2113-so that the program keeps one (section 10). This compiler compiles every
2114-module of a program together, and writes no object files.</li>
2115-<li><strong>Atomics.</strong> How <code>CAS</code>, <code>XCHG</code>
2116-and <code>XADD</code> are made sequentially consistent on a machine
2117-without atomic instructions (section 6.8): on one with a single
2118-processor, by holding off interrupts while they run, for one.</li>
2119-<li><strong>The calling convention.</strong> On x86-64 Linux it is
2120-System V (sections 8 and 9); elsewhere it is the C library’s own, so
2121-that <code>extern</code> procedures and callbacks work. How a procedure
2122-returns several results, and how its frame is laid out, are the
2123-implementation’s.</li>
2124-<li><strong>What is the target’s.</strong> Code procedures (section 8)
2125-hold the target’s machine code, written in its assembly language, and
2126-exist only where the implementation says so; <code>SYSCALL</code> exists
2127-only on Linux targets (section 6.8). A record’s layout is the target’s C
2128-layout (section 5.5), and the order of a value’s bytes is the target’s
2129-(little-endian on x86-64).</li>
2130-<li><strong>The assembly language.</strong> How a code procedure’s
2131-instructions are written (section 8). On x86-64 it is Intel’s syntax, as
2132-NASM writes it: the destination first; registers by name
2133-(<code>rax</code>, <code>eax</code>, <code>al</code>,
2134-<code>xmm0</code>); memory as
2135-<code>[base + index * scale + disp]</code>, with <code>byte</code>,
2136-<code>word</code>, <code>dword</code> or <code>qword</code> before it
2137-where no register says the size; <code>lock</code> before an
2138-instruction. Which instructions it knows is the implementation’s;
2139-<code>db</code> gives any others.</li>
2140-<li><strong>Sizes in the library.</strong> How many bytes
2141-<code>Out</code> keeps before it writes them, <code>Sys.outSize</code>
2142-(section 11): 4 KB on Linux, fewer on a small machine.</li>
2143-<li><strong>The executable.</strong> Its format, and the names and line
2144-numbers it carries for a debugger (section 10).</li>
2145-<li><strong>How a failure is caught.</strong> A <code>nil</code>
2146-pointer, a division by zero or a stack overflow may be caught by the
2147-machine or by checks in the compiled code; either way the program stops
2148-with its message (section 10).</li>
2149-<li><strong>Messages and warnings.</strong> The text of the compiler’s
2150-messages, how many errors it reports before it stops, and which warnings
2151-it gives (section 10). A program that is an error in this report is one
2152-in every implementation; the words that say so are free.</li>
2153-<li><strong>The command line.</strong> How the compiler is run, its
2154-options, and where its library lives (sections 1 and 3).</li>
1066+<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>
1067+<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>
1068+<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>
1069+<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>
1070+<li><strong>What is the target’s.</strong> Code procedures (section 8) hold the target’s machine code, written in its assembly language, and exist only where the implementation says so; <code>SYSCALL</code> exists only on Linux targets (section 6.8). A record’s layout is the target’s C layout (section 5.5), and the order of a value’s bytes is the target’s (little-endian on x86-64).</li>
1071+<li><strong>The assembly language.</strong> How a code procedure’s instructions are written (section 8). On x86-64 it is Intel’s syntax, as NASM writes it: the destination first; registers by name (<code>rax</code>, <code>eax</code>, <code>al</code>, <code>xmm0</code>); memory as <code>[base + index * scale + disp]</code>, with <code>byte</code>, <code>word</code>, <code>dword</code> or <code>qword</code> before it where no register says the size; <code>lock</code> before an instruction. Which instructions it knows is the implementation’s; <code>db</code> gives any others.</li>
1072+<li><strong>Sizes in the library.</strong> How many bytes <code>Out</code> keeps before it writes them, <code>Sys.outSize</code> (section 11): 4 KB on Linux, fewer on a small machine.</li>
1073+<li><strong>The executable.</strong> Its format, and the names and line numbers it carries for a debugger (section 10).</li>
1074+<li><strong>How a failure is caught.</strong> A <code>nil</code> pointer, a division by zero or a stack overflow may be caught by the machine or by checks in the compiled code; either way the program stops with its message (section 10).</li>
1075+<li><strong>Messages and warnings.</strong> The text of the compiler’s messages, how many errors it reports before it stops, and which warnings it gives (section 10). A program that is an error in this report is one in every implementation; the words that say so are free.</li>
1076+<li><strong>The command line.</strong> How the compiler is run, its options, and where its library lives (sections 1 and 3).</li>
21551077 </ul>
2156-<p><strong>The core.</strong> A target may leave out what the system
2157-under it can’t give: <code>Sys</code> past writing, ending the program
2158-and getting memory, <code>Thread</code>, <code>link</code> and
2159-<code>extern</code>. What it must have, besides the whole language,
2160-reals aside, is the core of the library: <code>Rt</code>,
2161-<code>Out</code>, <code>Mem</code>, <code>Arena</code>,
2162-<code>Lock</code>, <code>Str</code> and <code>Buf</code>, and of
2163-<code>Sys</code> what they need. A program that keeps to the core runs
2164-on every target.</p>
1078+<p><strong>The core.</strong> A target may leave out what the system under it can’t give: <code>Sys</code> past writing, ending the program and getting memory, <code>Thread</code>, <code>link</code> and <code>extern</code>. What it must have, besides the whole language, reals aside, is the core of the library: <code>Rt</code>, <code>Out</code>, <code>Mem</code>, <code>Arena</code>, <code>Lock</code>, <code>Str</code> and <code>Buf</code>, and of <code>Sys</code> what they need. A program that keeps to the core runs on every target.</p>
21651079 <h1 id="appendix-b.-the-grammar">Appendix B. The grammar</h1>
2166-<p>The whole syntax of raz, gathered from the sections above, with the
2167-symbols of section 2. <code>{ x }</code> is any number of
2168-<code>x</code>, <code>[ x ]</code> is <code>x</code> or nothing, and
2169-<code>( x | y )</code> is one of them.</p>
1080+<p>The whole syntax of raz, gathered from the sections above, with the symbols of section 2. <code>{ x }</code> is any number of <code>x</code>, <code>[ x ]</code> is <code>x</code> or nothing, and <code>( x | y )</code> is one of them.</p>
21701081 <pre><code>ident = letter { letter | digit } .
21711082 letter = &quot;A&quot; .. &quot;Z&quot; | &quot;a&quot; .. &quot;z&quot; | &quot;_&quot; .
21721083 digit = &quot;0&quot; .. &quot;9&quot; .
@@ -2258,16 +1169,9 @@
22581169 Results = Type | &quot;(&quot; Type { &quot;,&quot; Type } &quot;)&quot; .
22591170 ExternDeclaration = &quot;extern&quot; ( &quot;proc&quot; IdentDef Signature
22601171 | &quot;var&quot; IdentDef &quot;:&quot; Type ) .</code></pre>
2261-<p><code>character</code> is any character but a line break, and in a
2262-string any but <code>"</code> and <code>\</code>, in a character any but
2263-<code>'</code> and <code>\</code>. A procedure argument of a generic
2264-module (section 3) is written as a <code>QualIdent</code>, which is a
2265-<code>Type</code> here. <code>...</code> comes last in a
2266-<code>Signature</code>, and only in an <code>extern</code>. An
2267-<code>Instruction</code> is written in the target’s assembly language
2268-(appendix A).</p>
1172+<p><code>character</code> is any character but a line break, and in a string any but <code>"</code> and <code>\</code>, in a character any but <code>'</code> and <code>\</code>. A procedure argument of a generic module (section 3) is written as a <code>QualIdent</code>, which is a <code>Type</code> here. <code>...</code> comes last in a <code>Signature</code>, and only in an <code>extern</code>. An <code>Instruction</code> is written in the target’s assembly language (appendix A).</p>
22691173 </div>
22701174 </main>
2271-<footer>raz is under the ISC license. <a href="https://github.com/ldiaz94/raz">Source</a>.</footer>
1175+<footer>raz is under the ISC license.</footer>
22721176 </body>
22731177 </html>

site/public/style.css (history) modified +7 -4

@@ -26,7 +26,6 @@
2626 font: 700 20px ui-monospace, monospace; color: var(--accent); }
2727 header nav .mark img { display: block; }
2828 header nav a[aria-current] { border-bottom: 2px solid var(--accent); }
29-header nav .repo { margin-left: auto; color: var(--muted); }
3029 main { padding-top: 28px; padding-bottom: 48px; }
3130 footer { color: var(--muted); font-size: 14px; padding-bottom: 32px; font-family: system-ui, sans-serif; }
3231 h1 { overflow-wrap: anywhere; font-size: 2.1rem; line-height: 1.2; margin: .2em 0 .5em; }
@@ -51,7 +50,7 @@
5150 .hero { padding: 24px 0 8px; }
5251 .hero h1 { font-size: 3.4rem; font-family: ui-monospace, monospace; color: var(--accent); margin: 0; }
5352 .hero .tag { font-size: 1.35rem; margin: .2em 0 1em; }
54-.hero .cta { display: flex; flex-wrap: wrap; gap: 10px; margin: 1em 0; font-family: system-ui, sans-serif; }
53+.cta { display: flex; flex-wrap: wrap; gap: 10px; margin: 1em 0; font-family: system-ui, sans-serif; }
5554 .btn { display: inline-block; padding: 9px 18px; border-radius: 6px; text-decoration: none;
5655 border: 1px solid var(--accent); color: var(--accent); font-weight: 600; font-size: 15px; }
5756 .btn.primary { background: var(--accent); color: var(--bg); }
@@ -85,10 +84,14 @@
8584 /* the report */
8685 .spec { max-width: 46rem; }
8786 .spec pre { background: var(--code-bg); border-left: 2px solid var(--line); white-space: pre-wrap; }
88-.spec table { border-collapse: collapse; display: block; overflow-x: auto; font-size: 15px; }
89-.spec td, .spec th { border-bottom: 1px solid var(--line); padding: 3px 10px; text-align: left; }
87+.spec table { border-collapse: collapse; width: 100%; font-size: 15px; margin: 1em 0; }
88+.spec td, .spec th { border-bottom: 1px solid var(--line); padding: 5px 10px 5px 0;
89+ text-align: left; vertical-align: top; }
90+.spec th { border-bottom-width: 2px; }
91+@media (min-width: 40rem) { .spec td:first-child { white-space: nowrap; } }
9092 .spec nav#TOC ul { list-style: none; padding-left: 1em; }
9193
9294 /* a shell session */
9395 pre.term::before { content: "terminal"; }
9496 pre .cmd { color: #8fd18f; }
97+.sha code { font-size: 13px; word-break: break-all; }

site/public/tour/c.html (history) modified +2 -2

@@ -16,7 +16,7 @@
1616 <link rel="stylesheet" href="../style.css">
1717 </head>
1818 <body>
19-<header><nav><a class="mark" href="../index.html"><img src="../logo.svg" width="26" height="26" alt="">raz</a><a href="../tour/index.html" aria-current="page">Raz, Set, Go</a><a href="../advanced/index.html">More Raz</a><a href="../spec.html">Report</a><a href="../index.html#download">Download</a><a class="repo" href="https://github.com/ldiaz94/raz">GitHub</a></nav></header>
19+<header><nav><a class="mark" href="../index.html"><img src="../logo.svg" width="26" height="26" alt="">raz</a><a href="../tour/index.html" aria-current="page">Raz, Set, Go</a><a href="../advanced/index.html">More Raz</a><a href="../spec.html">Report</a><a href="../index.html#download">Download</a></nav></header>
2020 <main>
2121 <div class="tour"><aside><h2>Raz, Set, Go</h2><h3>Raz</h3><ol start='1'>
2222 <li><a href="hello.html">Hello, world</a></li>
@@ -148,6 +148,6 @@
148148 <pre class="output"><code>3.000 5.000
149149 </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="generics.html">&larr; Generic modules</a><a href="index.html">Contents</a><a class="next" href="threads.html">Threads &rarr;</a></div></article></div>
150150 </main>
151-<footer>raz is under the ISC license. <a href="https://github.com/ldiaz94/raz">Source</a>.</footer>
151+<footer>raz is under the ISC license.</footer>
152152 </body>
153153 </html>

site/public/tour/checks.html (history) modified +2 -2

@@ -16,7 +16,7 @@
1616 <link rel="stylesheet" href="../style.css">
1717 </head>
1818 <body>
19-<header><nav><a class="mark" href="../index.html"><img src="../logo.svg" width="26" height="26" alt="">raz</a><a href="../tour/index.html" aria-current="page">Raz, Set, Go</a><a href="../advanced/index.html">More Raz</a><a href="../spec.html">Report</a><a href="../index.html#download">Download</a><a class="repo" href="https://github.com/ldiaz94/raz">GitHub</a></nav></header>
19+<header><nav><a class="mark" href="../index.html"><img src="../logo.svg" width="26" height="26" alt="">raz</a><a href="../tour/index.html" aria-current="page">Raz, Set, Go</a><a href="../advanced/index.html">More Raz</a><a href="../spec.html">Report</a><a href="../index.html#download">Download</a></nav></header>
2020 <main>
2121 <div class="tour"><aside><h2>Raz, Set, Go</h2><h3>Raz</h3><ol start='1'>
2222 <li><a href="hello.html">Hello, world</a></li>
@@ -181,6 +181,6 @@
181181 <h2>For gdb and the profiler</h2>
182182 <p>The program carries names and line numbers, so <code>gdb</code> can break at <code>Fail.raz:6</code> and show raz source. <code>RAZ_PROFILE=1</code> in the environment makes a program sample itself every millisecond and say at the end where its time went, by procedure and by line.</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="defer.html">&larr; Defer</a><a href="index.html">Contents</a><a class="next" href="generics.html">Generic modules &rarr;</a></div></article></div>
183183 </main>
184-<footer>raz is under the ISC license. <a href="https://github.com/ldiaz94/raz">Source</a>.</footer>
184+<footer>raz is under the ISC license.</footer>
185185 </body>
186186 </html>

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

@@ -16,7 +16,7 @@
1616 <link rel="stylesheet" href="../style.css">
1717 </head>
1818 <body>
19-<header><nav><a class="mark" href="../index.html"><img src="../logo.svg" width="26" height="26" alt="">raz</a><a href="../tour/index.html" aria-current="page">Raz, Set, Go</a><a href="../advanced/index.html">More Raz</a><a href="../spec.html">Report</a><a href="../index.html#download">Download</a><a class="repo" href="https://github.com/ldiaz94/raz">GitHub</a></nav></header>
19+<header><nav><a class="mark" href="../index.html"><img src="../logo.svg" width="26" height="26" alt="">raz</a><a href="../tour/index.html" aria-current="page">Raz, Set, Go</a><a href="../advanced/index.html">More Raz</a><a href="../spec.html">Report</a><a href="../index.html#download">Download</a></nav></header>
2020 <main>
2121 <div class="tour"><aside><h2>Raz, Set, Go</h2><h3>Raz</h3><ol start='1'>
2222 <li><a href="hello.html">Hello, world</a></li>
@@ -182,6 +182,6 @@
182182 <h2>What defer does not do</h2>
183183 <p>A deferred statement can't contain a <code>return</code>, <code>break</code> or <code>defer</code> that would leave it. A failed check, <code>Rt.exit</code> and <code>Sys.exit</code> end the program without running the deferred statements still pending, so deferred cleanup is for the program's resources, not for what must happen at exit; that is what <code>Rt.atExit</code> is for.</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="errors.html">&larr; Errors</a><a href="index.html">Contents</a><a class="next" href="checks.html">When it goes wrong &rarr;</a></div></article></div>
184184 </main>
185-<footer>raz is under the ISC license. <a href="https://github.com/ldiaz94/raz">Source</a>.</footer>
185+<footer>raz is under the ISC license.</footer>
186186 </body>
187187 </html>

site/public/tour/errors.html (history) modified +2 -2

@@ -16,7 +16,7 @@
1616 <link rel="stylesheet" href="../style.css">
1717 </head>
1818 <body>
19-<header><nav><a class="mark" href="../index.html"><img src="../logo.svg" width="26" height="26" alt="">raz</a><a href="../tour/index.html" aria-current="page">Raz, Set, Go</a><a href="../advanced/index.html">More Raz</a><a href="../spec.html">Report</a><a href="../index.html#download">Download</a><a class="repo" href="https://github.com/ldiaz94/raz">GitHub</a></nav></header>
19+<header><nav><a class="mark" href="../index.html"><img src="../logo.svg" width="26" height="26" alt="">raz</a><a href="../tour/index.html" aria-current="page">Raz, Set, Go</a><a href="../advanced/index.html">More Raz</a><a href="../spec.html">Report</a><a href="../index.html#download">Download</a></nav></header>
2020 <main>
2121 <div class="tour"><aside><h2>Raz, Set, Go</h2><h3>Raz</h3><ol start='1'>
2222 <li><a href="hello.html">Hello, world</a></li>
@@ -199,6 +199,6 @@
199199 the table is corrupt
200200 status 2</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="memory.html">&larr; Memory and allocators</a><a href="index.html">Contents</a><a class="next" href="defer.html">Defer &rarr;</a></div></article></div>
201201 </main>
202-<footer>raz is under the ISC license. <a href="https://github.com/ldiaz94/raz">Source</a>.</footer>
202+<footer>raz is under the ISC license.</footer>
203203 </body>
204204 </html>

site/public/tour/generics.html (history) modified +2 -2

@@ -16,7 +16,7 @@
1616 <link rel="stylesheet" href="../style.css">
1717 </head>
1818 <body>
19-<header><nav><a class="mark" href="../index.html"><img src="../logo.svg" width="26" height="26" alt="">raz</a><a href="../tour/index.html" aria-current="page">Raz, Set, Go</a><a href="../advanced/index.html">More Raz</a><a href="../spec.html">Report</a><a href="../index.html#download">Download</a><a class="repo" href="https://github.com/ldiaz94/raz">GitHub</a></nav></header>
19+<header><nav><a class="mark" href="../index.html"><img src="../logo.svg" width="26" height="26" alt="">raz</a><a href="../tour/index.html" aria-current="page">Raz, Set, Go</a><a href="../advanced/index.html">More Raz</a><a href="../spec.html">Report</a><a href="../index.html#download">Download</a></nav></header>
2020 <main>
2121 <div class="tour"><aside><h2>Raz, Set, Go</h2><h3>Raz</h3><ol start='1'>
2222 <li><a href="hello.html">Hello, world</a></li>
@@ -169,6 +169,6 @@
169169 <h2>The library's generics</h2>
170170 <p>The library's <code>List</code>, <code>Map</code> and <code>Sort</code> are generic modules. A <code>Map</code> takes its key hash and equality as procedure arguments: <code>import Count := Map([]U8, INT, Str.hash, Str.eq);</code>. The advanced tour uses each of them in a real program.</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="checks.html">&larr; When it goes wrong</a><a href="index.html">Contents</a><a class="next" href="c.html">Talking to C &rarr;</a></div></article></div>
171171 </main>
172-<footer>raz is under the ISC license. <a href="https://github.com/ldiaz94/raz">Source</a>.</footer>
172+<footer>raz is under the ISC license.</footer>
173173 </body>
174174 </html>

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

@@ -16,7 +16,7 @@
1616 <link rel="stylesheet" href="../style.css">
1717 </head>
1818 <body>
19-<header><nav><a class="mark" href="../index.html"><img src="../logo.svg" width="26" height="26" alt="">raz</a><a href="../tour/index.html" aria-current="page">Raz, Set, Go</a><a href="../advanced/index.html">More Raz</a><a href="../spec.html">Report</a><a href="../index.html#download">Download</a><a class="repo" href="https://github.com/ldiaz94/raz">GitHub</a></nav></header>
19+<header><nav><a class="mark" href="../index.html"><img src="../logo.svg" width="26" height="26" alt="">raz</a><a href="../tour/index.html" aria-current="page">Raz, Set, Go</a><a href="../advanced/index.html">More Raz</a><a href="../spec.html">Report</a><a href="../index.html#download">Download</a></nav></header>
2020 <main>
2121 <div class="tour"><aside><h2>Raz, Set, Go</h2><h3>Raz</h3><ol start='1'>
2222 <li><a href="hello.html" aria-current="page">Hello, world</a></li>
@@ -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-28480 bytes</code></pre>
73+28384 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>.</p>
@@ -140,6 +140,6 @@
140140 two words
141141 status 2</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="index.html">Contents</a><a class="next" href="modules.html">Modules &rarr;</a></div></article></div>
142142 </main>
143-<footer>raz is under the ISC license. <a href="https://github.com/ldiaz94/raz">Source</a>.</footer>
143+<footer>raz is under the ISC license.</footer>
144144 </body>
145145 </html>

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

@@ -16,7 +16,7 @@
1616 <link rel="stylesheet" href="../style.css">
1717 </head>
1818 <body>
19-<header><nav><a class="mark" href="../index.html"><img src="../logo.svg" width="26" height="26" alt="">raz</a><a href="../tour/index.html" aria-current="page">Raz, Set, Go</a><a href="../advanced/index.html">More Raz</a><a href="../spec.html">Report</a><a href="../index.html#download">Download</a><a class="repo" href="https://github.com/ldiaz94/raz">GitHub</a></nav></header>
19+<header><nav><a class="mark" href="../index.html"><img src="../logo.svg" width="26" height="26" alt="">raz</a><a href="../tour/index.html" aria-current="page">Raz, Set, Go</a><a href="../advanced/index.html">More Raz</a><a href="../spec.html">Report</a><a href="../index.html#download">Download</a></nav></header>
2020 <main>
2121 <div class="contents"><h1>Raz, Set, Go</h1>
2222 <p>A tour of raz, in the spirit of <em>A Tour of Go</em>. Each lesson is one
@@ -49,6 +49,6 @@
4949 <li><a href="threads.html">Threads</a> <span>Native threads without C, atomics, a mutex, and why the counter needs both.</span></li>
5050 </ol></div>
5151 </main>
52-<footer>raz is under the ISC license. <a href="https://github.com/ldiaz94/raz">Source</a>.</footer>
52+<footer>raz is under the ISC license.</footer>
5353 </body>
5454 </html>

site/public/tour/integers.html (history) modified +2 -2

@@ -16,7 +16,7 @@
1616 <link rel="stylesheet" href="../style.css">
1717 </head>
1818 <body>
19-<header><nav><a class="mark" href="../index.html"><img src="../logo.svg" width="26" height="26" alt="">raz</a><a href="../tour/index.html" aria-current="page">Raz, Set, Go</a><a href="../advanced/index.html">More Raz</a><a href="../spec.html">Report</a><a href="../index.html#download">Download</a><a class="repo" href="https://github.com/ldiaz94/raz">GitHub</a></nav></header>
19+<header><nav><a class="mark" href="../index.html"><img src="../logo.svg" width="26" height="26" alt="">raz</a><a href="../tour/index.html" aria-current="page">Raz, Set, Go</a><a href="../advanced/index.html">More Raz</a><a href="../spec.html">Report</a><a href="../index.html#download">Download</a></nav></header>
2020 <main>
2121 <div class="tour"><aside><h2>Raz, Set, Go</h2><h3>Raz</h3><ol start='1'>
2222 <li><a href="hello.html">Hello, world</a></li>
@@ -281,6 +281,6 @@
281281 <h2>Which one to use</h2>
282282 <ul><li><strong><code>INT</code></strong> for lengths, indexes, counts, loop variables, and anything you'd write <code>int</code> for in C.</li><li><strong><code>U8</code></strong> for bytes, and for a string's elements (<code>[]U8</code>). <strong><code>I32</code></strong> for a character, a code point.</li><li><strong><code>U32</code>, <code>U64</code></strong> for hashes, bit sets, masks and addresses you do arithmetic on.</li><li><strong><code>I64</code></strong> for what must not shrink on a smaller target: a file's size or position, a time in nanoseconds, a number read from text.</li><li><strong><code>I8</code>, <code>I16</code>, <code>U16</code></strong> when a format or a layout says so, in a record or an array, to save space or match a protocol. Convert at the edge and compute in <code>INT</code>.</li><li><strong><code>UINT</code></strong> rarely: for a count that must use the whole address range, or an address.</li></ul><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="modules.html">&larr; Modules</a><a href="index.html">Contents</a><a class="next" href="values.html">Values and conversions &rarr;</a></div></article></div>
283283 </main>
284-<footer>raz is under the ISC license. <a href="https://github.com/ldiaz94/raz">Source</a>.</footer>
284+<footer>raz is under the ISC license.</footer>
285285 </body>
286286 </html>

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

@@ -16,7 +16,7 @@
1616 <link rel="stylesheet" href="../style.css">
1717 </head>
1818 <body>
19-<header><nav><a class="mark" href="../index.html"><img src="../logo.svg" width="26" height="26" alt="">raz</a><a href="../tour/index.html" aria-current="page">Raz, Set, Go</a><a href="../advanced/index.html">More Raz</a><a href="../spec.html">Report</a><a href="../index.html#download">Download</a><a class="repo" href="https://github.com/ldiaz94/raz">GitHub</a></nav></header>
19+<header><nav><a class="mark" href="../index.html"><img src="../logo.svg" width="26" height="26" alt="">raz</a><a href="../tour/index.html" aria-current="page">Raz, Set, Go</a><a href="../advanced/index.html">More Raz</a><a href="../spec.html">Report</a><a href="../index.html#download">Download</a></nav></header>
2020 <main>
2121 <div class="tour"><aside><h2>Raz, Set, Go</h2><h3>Raz</h3><ol start='1'>
2222 <li><a href="hello.html">Hello, world</a></li>
@@ -182,6 +182,6 @@
182182 <h2>Pages</h2>
183183 <p>Under the allocators are pages from the system: <code>Mem.pages(size)</code> gives zeroed memory in whole pages, or <code>nil</code>, and <code>Mem.unmap</code> gives it back. Most programs never need to call it directly.</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="variants.html">&larr; Enumerations, sets, variants and match</a><a href="index.html">Contents</a><a class="next" href="errors.html">Errors &rarr;</a></div></article></div>
184184 </main>
185-<footer>raz is under the ISC license. <a href="https://github.com/ldiaz94/raz">Source</a>.</footer>
185+<footer>raz is under the ISC license.</footer>
186186 </body>
187187 </html>

site/public/tour/modules.html (history) modified +2 -2

@@ -16,7 +16,7 @@
1616 <link rel="stylesheet" href="../style.css">
1717 </head>
1818 <body>
19-<header><nav><a class="mark" href="../index.html"><img src="../logo.svg" width="26" height="26" alt="">raz</a><a href="../tour/index.html" aria-current="page">Raz, Set, Go</a><a href="../advanced/index.html">More Raz</a><a href="../spec.html">Report</a><a href="../index.html#download">Download</a><a class="repo" href="https://github.com/ldiaz94/raz">GitHub</a></nav></header>
19+<header><nav><a class="mark" href="../index.html"><img src="../logo.svg" width="26" height="26" alt="">raz</a><a href="../tour/index.html" aria-current="page">Raz, Set, Go</a><a href="../advanced/index.html">More Raz</a><a href="../spec.html">Report</a><a href="../index.html#download">Download</a></nav></header>
2020 <main>
2121 <div class="tour"><aside><h2>Raz, Set, Go</h2><h3>Raz</h3><ol start='1'>
2222 <li><a href="hello.html">Hello, world</a></li>
@@ -194,6 +194,6 @@
194194 raz: 2 errors</code></pre>
195195 <p>The compiler goes on to find the others, up to 20, and says what it can: where a name was declared, or a name spelled almost alike. A module with errors writes no executable.</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="hello.html">&larr; Hello, world</a><a href="index.html">Contents</a><a class="next" href="integers.html">Integers &rarr;</a></div></article></div>
196196 </main>
197-<footer>raz is under the ISC license. <a href="https://github.com/ldiaz94/raz">Source</a>.</footer>
197+<footer>raz is under the ISC license.</footer>
198198 </body>
199199 </html>

site/public/tour/procedures.html (history) modified +2 -2

@@ -16,7 +16,7 @@
1616 <link rel="stylesheet" href="../style.css">
1717 </head>
1818 <body>
19-<header><nav><a class="mark" href="../index.html"><img src="../logo.svg" width="26" height="26" alt="">raz</a><a href="../tour/index.html" aria-current="page">Raz, Set, Go</a><a href="../advanced/index.html">More Raz</a><a href="../spec.html">Report</a><a href="../index.html#download">Download</a><a class="repo" href="https://github.com/ldiaz94/raz">GitHub</a></nav></header>
19+<header><nav><a class="mark" href="../index.html"><img src="../logo.svg" width="26" height="26" alt="">raz</a><a href="../tour/index.html" aria-current="page">Raz, Set, Go</a><a href="../advanced/index.html">More Raz</a><a href="../spec.html">Report</a><a href="../index.html#download">Download</a></nav></header>
2020 <main>
2121 <div class="tour"><aside><h2>Raz, Set, Go</h2><h3>Raz</h3><ol start='1'>
2222 <li><a href="hello.html">Hello, world</a></li>
@@ -232,6 +232,6 @@
232232 <h2>Dropped results</h2>
233233 <p>A call that drops a result, as <code>Sys.write(fd, s);</code> does, is warned of; <code>_ := Sys.write(fd, s);</code> says it is meant. The compiler also warns of a variable that is assigned and never read, and of a name declared and never used, unless it starts with <code>_</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="values.html">&larr; Values and conversions</a><a href="index.html">Contents</a><a class="next" href="slices.html">Arrays, slices and strings &rarr;</a></div></article></div>
234234 </main>
235-<footer>raz is under the ISC license. <a href="https://github.com/ldiaz94/raz">Source</a>.</footer>
235+<footer>raz is under the ISC license.</footer>
236236 </body>
237237 </html>

site/public/tour/records.html (history) modified +31 -2

@@ -16,7 +16,7 @@
1616 <link rel="stylesheet" href="../style.css">
1717 </head>
1818 <body>
19-<header><nav><a class="mark" href="../index.html"><img src="../logo.svg" width="26" height="26" alt="">raz</a><a href="../tour/index.html" aria-current="page">Raz, Set, Go</a><a href="../advanced/index.html">More Raz</a><a href="../spec.html">Report</a><a href="../index.html#download">Download</a><a class="repo" href="https://github.com/ldiaz94/raz">GitHub</a></nav></header>
19+<header><nav><a class="mark" href="../index.html"><img src="../logo.svg" width="26" height="26" alt="">raz</a><a href="../tour/index.html" aria-current="page">Raz, Set, Go</a><a href="../advanced/index.html">More Raz</a><a href="../spec.html">Report</a><a href="../index.html#download">Download</a></nav></header>
2020 <main>
2121 <div class="tour"><aside><h2>Raz, Set, Go</h2><h3>Raz</h3><ol start='1'>
2222 <li><a href="hello.html">Hello, world</a></li>
@@ -107,6 +107,35 @@
107107 <pre class="output"><code>(3, 4)(30, 4)(4, 3)
108108 (0, 9)
109109 </code></pre>
110+<h2>Tables of constants</h2>
111+<p>A constant may be a record, or an array of them: a table the program reads but can't change. Its fields are integers, reals, <code>BOOL</code>s, strings, procedures and the like, and arrays and records of these.</p>
112+<div class="file"><span>Planets.raz</span></div><pre class="code"><code><span class="kw">module</span> Planets;
113+<span class="kw">import</span> Fmt;
114+
115+<span class="kw">type</span> Planet = <span class="kw">record</span> name: []<span class="ty">U8</span>; moons: <span class="ty">INT</span>; water: <span class="ty">BOOL</span>; <span class="kw">end</span>;
116+
117+<span class="kw">const</span> Inner: [<span class="number">4</span>]Planet = [
118+ {name: <span class="string">&quot;Mercury&quot;</span>},
119+ {name: <span class="string">&quot;Venus&quot;</span>},
120+ {name: <span class="string">&quot;Earth&quot;</span>, moons: <span class="number">1</span>, water: <span class="ty">true</span>},
121+ {name: <span class="string">&quot;Mars&quot;</span>, moons: <span class="number">2</span>}];
122+
123+<span class="kw">proc</span> main*;
124+<span class="kw">var</span> i, total: <span class="ty">INT</span>;
125+<span class="kw">begin</span>
126+ <span class="kw">for</span> i := <span class="number">0</span> <span class="kw">to</span> <span class="ty">LEN</span>(Inner) - <span class="number">1</span> <span class="kw">do</span>
127+ total := total + Inner[i].moons;
128+ <span class="kw">if</span> Inner[i].moons = <span class="number">0</span> <span class="kw">then</span> Fmt.print(<span class="string">&quot;{} has no moon\n&quot;</span>, [Fmt.str(Inner[i].name)]); <span class="kw">end</span>;
129+ <span class="kw">end</span>;
130+ Fmt.print(<span class="string">&quot;{} moons in all\n&quot;</span>, [Fmt.int(total)]);
131+<span class="kw">end</span>;
132+
133+<span class="kw">end</span> Planets.</code></pre>
134+<pre class="output"><code>Mercury has no moon
135+Venus has no moon
136+3 moons in all
137+</code></pre>
138+<p>Fields left out are zero, as in any literal: Mercury's <code>moons</code> is 0 and its <code>water</code> is <code>false</code>.</p>
110139 <h2>Layout</h2>
111140 <p>A record's layout is C's: each field at the next multiple of its own alignment, and the whole padded to a multiple of its largest alignment. <code>SIZE(T)</code> says how many bytes. A <code>packed record</code> has no padding, which is what a file format or a wire protocol wants.</p>
112141 <div class="file"><span>Layout.raz</span></div><pre class="code"><code><span class="kw">module</span> Layout;
@@ -199,6 +228,6 @@
199228 <pre class="output"><code>40 30 20 10
200229 </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>
201230 </main>
202-<footer>raz is under the ISC license. <a href="https://github.com/ldiaz94/raz">Source</a>.</footer>
231+<footer>raz is under the ISC license.</footer>
203232 </body>
204233 </html>

site/public/tour/slices.html (history) modified +2 -2

@@ -16,7 +16,7 @@
1616 <link rel="stylesheet" href="../style.css">
1717 </head>
1818 <body>
19-<header><nav><a class="mark" href="../index.html"><img src="../logo.svg" width="26" height="26" alt="">raz</a><a href="../tour/index.html" aria-current="page">Raz, Set, Go</a><a href="../advanced/index.html">More Raz</a><a href="../spec.html">Report</a><a href="../index.html#download">Download</a><a class="repo" href="https://github.com/ldiaz94/raz">GitHub</a></nav></header>
19+<header><nav><a class="mark" href="../index.html"><img src="../logo.svg" width="26" height="26" alt="">raz</a><a href="../tour/index.html" aria-current="page">Raz, Set, Go</a><a href="../advanced/index.html">More Raz</a><a href="../spec.html">Report</a><a href="../index.html#download">Download</a></nav></header>
2020 <main>
2121 <div class="tour"><aside><h2>Raz, Set, Go</h2><h3>Raz</h3><ol start='1'>
2222 <li><a href="hello.html">Hello, world</a></li>
@@ -247,6 +247,6 @@
247247 -27
248248 </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="procedures.html">&larr; Procedures and several results</a><a href="index.html">Contents</a><a class="next" href="records.html">Records and pointers &rarr;</a></div></article></div>
249249 </main>
250-<footer>raz is under the ISC license. <a href="https://github.com/ldiaz94/raz">Source</a>.</footer>
250+<footer>raz is under the ISC license.</footer>
251251 </body>
252252 </html>

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

@@ -16,7 +16,7 @@
1616 <link rel="stylesheet" href="../style.css">
1717 </head>
1818 <body>
19-<header><nav><a class="mark" href="../index.html"><img src="../logo.svg" width="26" height="26" alt="">raz</a><a href="../tour/index.html" aria-current="page">Raz, Set, Go</a><a href="../advanced/index.html">More Raz</a><a href="../spec.html">Report</a><a href="../index.html#download">Download</a><a class="repo" href="https://github.com/ldiaz94/raz">GitHub</a></nav></header>
19+<header><nav><a class="mark" href="../index.html"><img src="../logo.svg" width="26" height="26" alt="">raz</a><a href="../tour/index.html" aria-current="page">Raz, Set, Go</a><a href="../advanced/index.html">More Raz</a><a href="../spec.html">Report</a><a href="../index.html#download">Download</a></nav></header>
2020 <main>
2121 <div class="tour"><aside><h2>Raz, Set, Go</h2><h3>Raz</h3><ol start='1'>
2222 <li><a href="hello.html">Hello, world</a></li>
@@ -180,6 +180,6 @@
180180 </code></pre>
181181 <p><code>Thread</code> makes its own threads, without C, so a program that uses it can't use C; one that does makes its threads with C's <code>pthread_create</code> instead. The advanced tour goes further into atomics, memory ordering and lock-free 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="c.html">&larr; Talking to C</a><a href="index.html">Contents</a><a class="next" href="../advanced/index.html">More Raz &rarr;</a></div></article></div>
182182 </main>
183-<footer>raz is under the ISC license. <a href="https://github.com/ldiaz94/raz">Source</a>.</footer>
183+<footer>raz is under the ISC license.</footer>
184184 </body>
185185 </html>

site/public/tour/values.html (history) modified +6 -2

@@ -16,7 +16,7 @@
1616 <link rel="stylesheet" href="../style.css">
1717 </head>
1818 <body>
19-<header><nav><a class="mark" href="../index.html"><img src="../logo.svg" width="26" height="26" alt="">raz</a><a href="../tour/index.html" aria-current="page">Raz, Set, Go</a><a href="../advanced/index.html">More Raz</a><a href="../spec.html">Report</a><a href="../index.html#download">Download</a><a class="repo" href="https://github.com/ldiaz94/raz">GitHub</a></nav></header>
19+<header><nav><a class="mark" href="../index.html"><img src="../logo.svg" width="26" height="26" alt="">raz</a><a href="../tour/index.html" aria-current="page">Raz, Set, Go</a><a href="../advanced/index.html">More Raz</a><a href="../spec.html">Report</a><a href="../index.html#download">Download</a></nav></header>
2020 <main>
2121 <div class="tour"><aside><h2>Raz, Set, Go</h2><h3>Raz</h3><ol start='1'>
2222 <li><a href="hello.html">Hello, world</a></li>
@@ -126,6 +126,8 @@
126126 Fmt.print(<span class="string">&quot;22/7 = {}\n&quot;</span>, [Fmt.real(x, <span class="number">6</span>)]);
127127 Fmt.print(<span class="string">&quot;as F32 = {}\n&quot;</span>, [Fmt.real(<span class="ty">F64</span>(y), <span class="number">6</span>)]);
128128 Fmt.print(<span class="string">&quot;sqrt 2 = {}, pi = {}\n&quot;</span>, [Fmt.real(Math.sqrt(<span class="number">2.0</span>), <span class="number">5</span>), Fmt.real(Math.pi, <span class="number">5</span>)]);
129+ Fmt.print(<span class="string">&quot;2^10 = {}, log2 of that = {}\n&quot;</span>, [Fmt.real(Math.pow(<span class="number">2.0</span>, <span class="number">10.0</span>), <span class="number">1</span>), Fmt.real(Math.log2(<span class="number">1024.0</span>), <span class="number">1</span>)]);
130+ Fmt.print(<span class="string">&quot;rounded: {} {}\n&quot;</span>, [Fmt.real(Math.round(<span class="number">2.5</span>), <span class="number">1</span>), Fmt.real(Math.round(-<span class="number">2.5</span>), <span class="number">1</span>)]);
129131 Fmt.print(<span class="string">&quot;truncated: {} {}\n&quot;</span>, [Fmt.int(<span class="ty">I64</span>(<span class="number">2.9</span>)), Fmt.int(<span class="ty">I64</span>(-<span class="number">2.9</span>))]);
130132 <span class="kw">end</span>;
131133
@@ -133,10 +135,12 @@
133135 <pre class="output"><code>22/7 = 3.142857
134136 as F32 = 3.142857
135137 sqrt 2 = 1.41421, pi = 3.14159
138+2^10 = 1024.0, log2 of that = 10.0
139+rounded: 3.0 -3.0
136140 truncated: 2 -2
137141 </code></pre>
138142 <p>A real converts to an integer by rounding toward zero. Every variable starts at zero, a real's <code>0.0</code> and a <code>BOOL</code>'s <code>false</code> included, so there is no uninitialised value to be surprised by.</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="integers.html">&larr; Integers</a><a href="index.html">Contents</a><a class="next" href="procedures.html">Procedures and several results &rarr;</a></div></article></div>
139143 </main>
140-<footer>raz is under the ISC license. <a href="https://github.com/ldiaz94/raz">Source</a>.</footer>
144+<footer>raz is under the ISC license.</footer>
141145 </body>
142146 </html>

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

@@ -16,7 +16,7 @@
1616 <link rel="stylesheet" href="../style.css">
1717 </head>
1818 <body>
19-<header><nav><a class="mark" href="../index.html"><img src="../logo.svg" width="26" height="26" alt="">raz</a><a href="../tour/index.html" aria-current="page">Raz, Set, Go</a><a href="../advanced/index.html">More Raz</a><a href="../spec.html">Report</a><a href="../index.html#download">Download</a><a class="repo" href="https://github.com/ldiaz94/raz">GitHub</a></nav></header>
19+<header><nav><a class="mark" href="../index.html"><img src="../logo.svg" width="26" height="26" alt="">raz</a><a href="../tour/index.html" aria-current="page">Raz, Set, Go</a><a href="../advanced/index.html">More Raz</a><a href="../spec.html">Report</a><a href="../index.html#download">Download</a></nav></header>
2020 <main>
2121 <div class="tour"><aside><h2>Raz, Set, Go</h2><h3>Raz</h3><ol start='1'>
2222 <li><a href="hello.html">Hello, world</a></li>
@@ -263,6 +263,6 @@
263263 y is letter
264264 </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="records.html">&larr; Records and pointers</a><a href="index.html">Contents</a><a class="next" href="memory.html">Memory and allocators &rarr;</a></div></article></div>
265265 </main>
266-<footer>raz is under the ISC license. <a href="https://github.com/ldiaz94/raz">Source</a>.</footer>
266+<footer>raz is under the ISC license.</footer>
267267 </body>
268268 </html>

site/style.css (history) modified +7 -4

@@ -26,7 +26,6 @@
2626 font: 700 20px ui-monospace, monospace; color: var(--accent); }
2727 header nav .mark img { display: block; }
2828 header nav a[aria-current] { border-bottom: 2px solid var(--accent); }
29-header nav .repo { margin-left: auto; color: var(--muted); }
3029 main { padding-top: 28px; padding-bottom: 48px; }
3130 footer { color: var(--muted); font-size: 14px; padding-bottom: 32px; font-family: system-ui, sans-serif; }
3231 h1 { overflow-wrap: anywhere; font-size: 2.1rem; line-height: 1.2; margin: .2em 0 .5em; }
@@ -51,7 +50,7 @@
5150 .hero { padding: 24px 0 8px; }
5251 .hero h1 { font-size: 3.4rem; font-family: ui-monospace, monospace; color: var(--accent); margin: 0; }
5352 .hero .tag { font-size: 1.35rem; margin: .2em 0 1em; }
54-.hero .cta { display: flex; flex-wrap: wrap; gap: 10px; margin: 1em 0; font-family: system-ui, sans-serif; }
53+.cta { display: flex; flex-wrap: wrap; gap: 10px; margin: 1em 0; font-family: system-ui, sans-serif; }
5554 .btn { display: inline-block; padding: 9px 18px; border-radius: 6px; text-decoration: none;
5655 border: 1px solid var(--accent); color: var(--accent); font-weight: 600; font-size: 15px; }
5756 .btn.primary { background: var(--accent); color: var(--bg); }
@@ -85,10 +84,14 @@
8584 /* the report */
8685 .spec { max-width: 46rem; }
8786 .spec pre { background: var(--code-bg); border-left: 2px solid var(--line); white-space: pre-wrap; }
88-.spec table { border-collapse: collapse; display: block; overflow-x: auto; font-size: 15px; }
89-.spec td, .spec th { border-bottom: 1px solid var(--line); padding: 3px 10px; text-align: left; }
87+.spec table { border-collapse: collapse; width: 100%; font-size: 15px; margin: 1em 0; }
88+.spec td, .spec th { border-bottom: 1px solid var(--line); padding: 5px 10px 5px 0;
89+ text-align: left; vertical-align: top; }
90+.spec th { border-bottom-width: 2px; }
91+@media (min-width: 40rem) { .spec td:first-child { white-space: nowrap; } }
9092 .spec nav#TOC ul { list-style: none; padding-left: 1em; }
9193
9294 /* a shell session */
9395 pre.term::before { content: "terminal"; }
9496 pre .cmd { color: #8fd18f; }
97+.sha code { font-size: 13px; word-break: break-all; }