raz / commit 5b585758

commit
5b58575886cc369e2bb76ba21f360e379119ac90
author
Luis <42945842+ldiaz94@users.noreply.github.com>
date
parent
375c41de
site: v0.17.0, and the tours for report 2026-10.31

Integers and values: the small types widening to INT. Slices: continue
in the loops, Width's columns beside Str's characters. Variants: an
enumeration's name with its type. Defer: continue. Two advanced
examples drop conversions they no longer need.

patch · log

21 files changed, +100 -50

site/content/advanced/12-syscalls.txt (history) modified +2 -2

@@ -102,9 +102,9 @@
102102 (* length 4096; PROT_READ|WRITE = 3; MAP_PRIVATE|ANONYMOUS = 22H; no fd *)
103103 p := ^U8(SYSCALL(9, 0, 4096, 3, 22H, -1, 0));
104104 if INT(p) < 0 then Out.str("no memory\n"); return; end;
105- Out.int(INT(p[0]) + INT(p[4095])); Out.str(" (zero, as promised)\n");
105+ Out.int(INT(p[0]) + p[4095]); Out.str(" (zero, as promised)\n");
106106 for i := 0 to 4095 do p[i] := U8(i); end;
107- for i := 0 to 4095 do INC(total, INT(p[i])); end;
107+ for i := 0 to 4095 do INC(total, p[i]); end;
108108 Out.int(total); Out.ln;
109109 _ := SYSCALL(11, p, 4096);
110110 end;

site/content/advanced/15-atomics.txt (history) modified +1 -1

@@ -60,7 +60,7 @@
6060 if err # nil then Out.str(MSG(err)); Out.ln; return; end;
6161 end;
6262 for i := 0 to 3 do Thread.join(th[i]); end;
63- for i := 0 to 3999 do taken := taken + INT(seen[i]); end;
63+ for i := 0 to 3999 do taken := taken + seen[i]; end;
6464 Out.int(next); Out.char(' '); Out.int(taken); Out.ln;
6565 end;
6666

site/content/tour/03-integers.txt (history) modified +1 -1

@@ -39,7 +39,7 @@
3939
4040 Lengths, indexes, counts and sizes are `INT`s. `LEN(s)` of a slice is an `INT`, and so is the loop variable that walks it. It is as big as an address, so it is the integer a pointer converts to, and the word the atomics work on. Reach for `INT` unless you have a reason: a byte is a `U8`, a character an `I32`, a file's size an `I64`, a hash a `U64`.
4141
42-`INT` and `I64` are two types even where they have the same size. An `INT` goes silently into an `I64` (and a `UINT` into a `U64`) wherever it meets one, in `pos + LEN(s)` as in a call, which is why `Out.int(n)` and `Fmt.int(n)` take an `I64` and accept any `INT`. The other way is written, `INT(pos)`, since an `INT` may be smaller on another machine. Nothing else converts unasked: any other integer is converted where it is written, as `Out.int(I64(b))`.
42+`INT` and `I64` are two types even where they have the same size. An `INT` goes silently into an `I64` (and a `UINT` into a `U64`) wherever it meets one, in `pos + LEN(s)` as in a call, which is why `Out.int(n)` and `Fmt.int(n)` take an `I64` and accept any `INT`. The other way is written, `INT(pos)`, since an `INT` may be smaller on another machine. An `INT` holds every `U8`, `I8` and `I16` on any machine, so those go silently into an `INT` too (and a `U8` or `U16` into a `UINT`): `n := s[i]`, and `n * 10 + s[i] - '0'` for a digit. Not what an operator made of them, which was computed in the small type and may have wrapped there: with `a, b: U8`, `n := a + b` is an error, and `INT(a) + b` the sum. And only one step: a `U8` goes into an `INT`, not on into an `I64`, so `Out.int(I64(b))` still says it. Nothing else converts unasked.
4343
4444 ## A number written in the program
4545

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

@@ -9,7 +9,7 @@
99
1010 ## Conversions are written
1111
12-Two types never mix but for one: an `INT` goes into an `I64` wherever it meets one, which loses nothing, so with `pos: I64`, `pos + LEN(s)` is an `I64`. With `i: I32` and a slice `s`, `i < LEN(s)` is an error. A type's name converts: `F64(n)`, `I64(b)`, `U8(x)`; an `I64` becomes an `INT` only so, `INT(pos)`, since an `INT` may be smaller on another machine. The [lesson on integers](integers.html) says what each width conversion does.
12+Two types never mix but where nothing can be lost: an `INT` goes into an `I64` wherever it meets one, so with `pos: I64`, `pos + LEN(s)` is an `I64`; and a `U8`, `I8` or `I16` into an `INT`, unless an operator made it, so `n := s[i]` needs no conversion. With `i: I32` and a slice `s`, `i < LEN(s)` is an error. A type's name converts: `F64(n)`, `I64(b)`, `U8(x)`; an `I64` becomes an `INT` only so, `INT(pos)`, since an `INT` may be smaller on another machine. The [lesson on integers](integers.html) says what each width conversion does.
1313
1414 A number written in the program is untyped until it meets a type, and `1.5` is a real, which an integer never becomes without a conversion.
1515

site/content/tour/06-slices.txt (history) modified +10 -4

@@ -198,18 +198,19 @@
198198
199199 ## UTF-8
200200
201-A character is an `I32`, its code point. A string stays bytes; UTF-8 is how `Str` reads them. `Str.next` walks a string a character at a time, giving each one and where the next starts, -1 at the end. `Str.decode` reads the first character of a string and says how many bytes it took, `Str.decodeLast` the last, and `Str.encode` goes the other way. `Str.chars` counts characters and `Str.valid` says whether a string is UTF-8 at all; a byte that doesn't start a character rightly reads as FFFDH, the character that stands for a wrong one. Byte length and character count are different things, and the program is the one that says which it wants.
201+A character is an `I32`, its code point. A string stays bytes; UTF-8 is how `Str` reads them. `Str.next` walks a string a character at a time, giving each one and where the next starts, -1 at the end. `Str.decode` reads the first character of a string and says how many bytes it took, `Str.decodeLast` the last, and `Str.encode` goes the other way. `Str.chars` counts characters and `Str.valid` says whether a string is UTF-8 at all; a byte that doesn't start a character rightly reads as FFFDH, the character that stands for a wrong one. Byte length and character count are different things, and the program is the one that says which it wants. On a terminal there is a third: a character takes 0, 1 or 2 columns, a combining accent none and an ideograph two, and `Width.columns` counts those.
202202
203203 ```raz Runes run
204204 module Runes;
205-import Out, Str;
205+import Out, Str, Width;
206206
207207 proc main*;
208208 var s: []U8; c: I32; i, size: INT; bytes: [4]U8; k: INT;
209209 begin
210210 s := "caf\u{E9} \u{3BB}";
211211 Out.int(LEN(s)); Out.str(" bytes, ");
212- Out.int(Str.chars(s)); Out.str(" characters\n");
212+ Out.int(Str.chars(s)); Out.str(" characters, ");
213+ Out.int(Width.columns("\u{4E2D}\u{6587}")); Out.str(" columns for two ideographs\n");
213214
214215 (* each character, as its code point *)
215216 c, i := Str.next(s, 0);
@@ -233,7 +234,7 @@
233234
234235 ## Loops over lengths
235236
236-A `for` loop takes its bounds once, and never steps past the last: with an empty slice, `0 to LEN(s) - 1` doesn't run at all, and the variable can't wrap. `for` takes a constant step with `by`, and `while` and `repeat ... until` do the rest.
237+A `for` loop takes its bounds once, and never steps past the last: with an empty slice, `0 to LEN(s) - 1` doesn't run at all, and the variable can't wrap. `for` takes a constant step with `by`, and `while` and `repeat ... until` do the rest. `break` leaves a loop, and `continue` ends its round: a `for` steps, a `while` or a `repeat` tests again. So a `while` moves on before any `continue`, or it never moves at all.
237238
238239 ```raz Loops run
239240 module Loops;
@@ -249,6 +250,11 @@
249250 Out.int(i); Out.ln;
250251 repeat DEC(i, 30); until i < 0;
251252 Out.int(i); Out.ln;
253+ for i := 1 to 10 do
254+ if i mod 3 = 0 then continue; end; (* 3, 6 and 9 passed over *)
255+ Out.int(i); Out.char(' ');
256+ end;
257+ Out.ln;
252258 end;
253259
254260 end Loops.

site/content/tour/08-variants.txt (history) modified +1 -1

@@ -7,7 +7,7 @@
77
88 ## Enumerations
99
10-An enumeration is a list of names, in order. They convert to their position and back, and a `for` loop can run over them. An integer that has no name at its position is a failed check, never a silent wrong value.
10+An enumeration is a list of names, in order. They convert to their position and back, and a `for` loop can run over them. A name may be written with its type, `Day.mon`, and two enumerations of a module may share a name, `Style.bold` and `Elem.bold`, which is then always written so. An integer that has no name at its position is a failed check, never a silent wrong value.
1111
1212 ```raz Days run
1313 module Days;

site/content/tour/11-defer.txt (history) modified +2 -2

@@ -5,7 +5,7 @@
55 ```raz Defers run
66 ```
77
8-`defer s;` runs `s` when the program leaves the statements the `defer` stands in: at their end, or by a `return` or a `break`. Deferred statements run the last first, and only those whose `defer` was reached. So a file is closed beside the line that opens it, however the procedure ends.
8+`defer s;` runs `s` when the program leaves the statements the `defer` stands in: at their end, or by a `return`, a `break` or a `continue`. Deferred statements run the last first, and only those whose `defer` was reached. So a file is closed beside the line that opens it, however the procedure ends.
99
1010 ## The order, and a `return` value
1111
@@ -46,7 +46,7 @@
4646
4747 ## In a loop
4848
49-A `defer` stands in the statement list that holds it, so in a loop body it runs at the end of each pass, and on a `break`.
49+A `defer` stands in the statement list that holds it, so in a loop body it runs at the end of each pass, and on a `break` or a `continue`.
5050
5151 ```raz Passes run
5252 module Passes;

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

@@ -1 +1 @@
1-/download/latest /download/raz-0.16.0-linux-x86_64.tar.gz 302
1+/download/latest /download/raz-0.17.0-linux-x86_64.tar.gz 302

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

@@ -90,7 +90,7 @@
9090 <span class="kw">if</span> err # <span class="ty">nil</span> <span class="kw">then</span> Out.str(<span class="ty">MSG</span>(err)); Out.ln; <span class="kw">return</span>; <span class="kw">end</span>;
9191 <span class="kw">end</span>;
9292 <span class="kw">for</span> i := <span class="number">0</span> <span class="kw">to</span> <span class="number">3</span> <span class="kw">do</span> Thread.join(th[i]); <span class="kw">end</span>;
93- <span class="kw">for</span> i := <span class="number">0</span> <span class="kw">to</span> <span class="number">3999</span> <span class="kw">do</span> taken := taken + <span class="ty">INT</span>(seen[i]); <span class="kw">end</span>;
93+ <span class="kw">for</span> i := <span class="number">0</span> <span class="kw">to</span> <span class="number">3999</span> <span class="kw">do</span> taken := taken + seen[i]; <span class="kw">end</span>;
9494 Out.int(next); Out.char(<span class="string">&#x27; &#x27;</span>); Out.int(taken); Out.ln;
9595 <span class="kw">end</span>;
9696

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

@@ -126,9 +126,9 @@
126126 <span class="comment">(* length 4096; PROT_READ|WRITE = 3; MAP_PRIVATE|ANONYMOUS = 22H; no fd *)</span>
127127 p := ^<span class="ty">U8</span>(SYSCALL(<span class="number">9</span>, <span class="number">0</span>, <span class="number">4096</span>, <span class="number">3</span>, <span class="number">22H</span>, -<span class="number">1</span>, <span class="number">0</span>));
128128 <span class="kw">if</span> <span class="ty">INT</span>(p) &lt; <span class="number">0</span> <span class="kw">then</span> Out.str(<span class="string">&quot;no memory\n&quot;</span>); <span class="kw">return</span>; <span class="kw">end</span>;
129- Out.int(<span class="ty">INT</span>(p[<span class="number">0</span>]) + <span class="ty">INT</span>(p[<span class="number">4095</span>])); Out.str(<span class="string">&quot; (zero, as promised)\n&quot;</span>);
129+ Out.int(<span class="ty">INT</span>(p[<span class="number">0</span>]) + p[<span class="number">4095</span>]); Out.str(<span class="string">&quot; (zero, as promised)\n&quot;</span>);
130130 <span class="kw">for</span> i := <span class="number">0</span> <span class="kw">to</span> <span class="number">4095</span> <span class="kw">do</span> p[i] := <span class="ty">U8</span>(i); <span class="kw">end</span>;
131- <span class="kw">for</span> i := <span class="number">0</span> <span class="kw">to</span> <span class="number">4095</span> <span class="kw">do</span> <span class="ty">INC</span>(total, <span class="ty">INT</span>(p[i])); <span class="kw">end</span>;
131+ <span class="kw">for</span> i := <span class="number">0</span> <span class="kw">to</span> <span class="number">4095</span> <span class="kw">do</span> <span class="ty">INC</span>(total, p[i]); <span class="kw">end</span>;
132132 Out.int(total); Out.ln;
133133 _ := SYSCALL(<span class="number">11</span>, p, <span class="number">4096</span>);
134134 <span class="kw">end</span>;

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

Binary file; the patch has it.

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

@@ -0,0 +1 @@
1+2425d173fb00eb6352a3a1c089469d038e00abae870816fd90d7a6fb707ae370 raz-0.17.0-linux-x86_64.tar.gz

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

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

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

Binary file; the patch has it.

site/public/raz.pdf (history) modified

Binary file; the patch has it.

site/public/spec.html (history) modified +50 -14

@@ -38,7 +38,7 @@
3838 <p>raz is a small systems language, first made for x86-64 Linux. A raz program can lay a record over a device’s registers, read and write a device’s memory exactly as written, take part in lock-free algorithms, make system calls and call C libraries. It has no garbage collector and no hidden run time: what the program does is what its text says.</p>
3939 <p>This is the first volume of the report: the language, what an implementation chooses, and the grammar. The second, <code>doc/raz-lib.md</code>, is the library, which sections 3 and 10 and appendix A name.</p>
4040 <p>This report defines the language. It is short on purpose. Whatever it doesn’t allow, raz doesn’t have.</p>
41-<p>This is version 2026-10.29 of the report; section 11 says where each version’s changes are told. 2026-10.11 and 2026-10.12 are a thaw the owner chose, for a language anyone can build again. They break programs written for 2026-10.10 and before: for 2026-10.9, say, the report of compiler 0.5.0, the last release before them; and 2026-10.12 breaks code procedures written for 2026-10.11. 2026-10.20 is a third, for <code>try</code> (section 7.8); it breaks a program that has a name <code>try</code>. 2026-10.25 is a fourth, for strings: raw strings, which may run over lines and may be indented with the code around them (section 2), and <code>match</code> on a string (section 7.4); it breaks no program. 2026-10.26 is a fifth: an <code>INT</code> widens to an <code>I64</code> wherever it goes to one, in an expression too (sections 5.10 and 6.1); and a view, <code>v.(T)</code>, reads and writes the bytes of a variable as a <code>T</code> (section 6.9); it breaks no program. 2026-10.27 mends a defect: returning a slice of the procedure’s own frame is an error (section 7.3), which breaks only a program that read memory already gone. 2026-10.28 mends another: an array a call returns lives to the end of its statement, and a slice of it kept past that is undefined (sections 8 and 10). 2026-10.29 is a sixth thaw: an array constant typed <code>[]T</code> takes its length from its literal (section 4); it breaks no program.</p>
41+<p>This is version 2026-10.31 of the report; section 11 says where each version’s changes are told. 2026-10.11 and 2026-10.12 are a thaw the owner chose, for a language anyone can build again. They break programs written for 2026-10.10 and before: for 2026-10.9, say, the report of compiler 0.5.0, the last release before them; and 2026-10.12 breaks code procedures written for 2026-10.11. 2026-10.20 is a third, for <code>try</code> (section 7.8); it breaks a program that has a name <code>try</code>. 2026-10.25 is a fourth, for strings: raw strings, which may run over lines and may be indented with the code around them (section 2), and <code>match</code> on a string (section 7.4); it breaks no program. 2026-10.26 is a fifth: an <code>INT</code> widens to an <code>I64</code> wherever it goes to one, in an expression too (sections 5.10 and 6.1); and a view, <code>v.(T)</code>, reads and writes the bytes of a variable as a <code>T</code> (section 6.9); it breaks no program. 2026-10.27 mends a defect: returning a slice of the procedure’s own frame is an error (section 7.3), which breaks only a program that read memory already gone. 2026-10.28 mends another: an array a call returns lives to the end of its statement, and a slice of it kept past that is undefined (sections 8 and 10). 2026-10.29 is a sixth thaw: an array constant typed <code>[]T</code> takes its length from its literal (section 4); it breaks no program. 2026-10.30 mends a defect: <code>[]</code> used as a slice is the empty slice, which may be returned (sections 6.5 and 7.3); it breaks no program. 2026-10.31 is a seventh thaw: <code>INT</code> is at least 16 bits, and <code>U8</code>, <code>I8</code> and <code>I16</code> widen to it (sections 5.1, 5.10 and 6.1); an enumeration’s name may be written with its type, and must be where another declaration shares it (section 5.7); and <code>continue</code> (section 7.2), which breaks a program that has a name <code>continue</code>.</p>
4242 <p>The language is frozen, softly, from this version on: it changes only to mend a defect, and its library grows only by what breaks no program written for it. What anyone wishes it had waits on a list, for a later thaw.</p>
4343 <h1 id="a-first-look">1. A first look</h1>
4444 <pre><code>module Hello;
@@ -55,10 +55,10 @@
5555 <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, and a file with a NUL byte. Everything outside strings, characters and comments is ASCII. Spaces, tabs and line breaks separate symbols and are otherwise ignored.</p>
5656 <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>
5757 <p><strong>Reserved words</strong> are lowercase, except <code>VOLATILE</code>:</p>
58-<pre><code>and begin break by code const defer div do else elsif end extern for
59-forward if import in link match mod module not of or packed proc record
60-repeat return set shl shr then to try type until var variant VOLATILE
61-while xor</code></pre>
58+<pre><code>and begin break by code const continue defer div do else elsif end
59+extern for forward if import in link match mod module not of or packed
60+proc record repeat return set shl shr then to try type until var
61+variant VOLATILE while xor</code></pre>
6262 <p><code>static</code>, in <code>link static;</code> (section 3), and <code>check</code> and <code>off</code>, in <code>check off;</code> (section 3), aren’t reserved.</p>
6363 <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>
6464 <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; so is a real above the largest <code>F64</code>. A real below the least <code>F64</code> is 0.</p>
@@ -210,7 +210,7 @@
210210 </tr>
211211 </tbody>
212212 </table>
213-<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> wherever it meets one, in an expression too (sections 5.10 and 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>
213+<p><code>INT</code> is the everyday integer: lengths, indexes and sizes are <code>INT</code>s. It is as big as an address, and at least 16 bits, as <code>UINT</code> is, on every target; 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> wherever it meets one, in an expression too (sections 5.10 and 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>
214214 <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>
215215 <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>
216216 <h2 id="arrays">5.2 Arrays</h2>
@@ -242,6 +242,17 @@
242242 Color* = (red, green, blue);
243243 Colors* = set of Color;</code></pre>
244244 <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>
245+<p>A name of an enumeration may also be written with its type, <code>Color.red</code>, and one imported with the type’s module, <code>M.Color.red</code>. Two enumerations of a scope may share a name, and an enumeration may have a name that something else of its scope has, a constant, a variable or a procedure: such a name is written with its type, <code>Elem.bold</code>. Written alone, it names the one declaration of it that isn’t an enumeration’s, if there is one, and is an error if there isn’t:</p>
246+<pre><code>type
247+ Style = (bold, italic);
248+ Elem = (para, bold, rule);
249+proc rule; (* a procedure, beside Elem&#39;s rule *)
250+...
251+s := Style.bold; e := Elem.bold; e := Elem.rule;
252+e := para; (* para is Elem&#39;s alone *)
253+rule; (* the procedure *)
254+s := bold; (* an error: write Style.bold or Elem.bold *)</code></pre>
255+<p>The type is never taken from where the name stands: <code>s := bold</code> is an error though <code>s</code> is a <code>Style</code>.</p>
245256 <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>
246257 <h2 id="errors">5.8 Errors</h2>
247258 <pre><code>const NotFound*: ERROR = &quot;not found&quot;;</code></pre>
@@ -266,10 +277,17 @@
266277 <li><code>A</code> is <code>[n]T</code> and <code>B</code> is <code>[]T</code>;</li>
267278 <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>
268279 <li><code>A</code> is a procedure and <code>B</code> a procedure type with the same signature;</li>
269-<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>
280+<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>
281+<li><code>A</code> is <code>U8</code>, <code>I8</code> or <code>I16</code> and <code>B</code> is <code>INT</code>, or <code>A</code> is <code>U8</code> or <code>U16</code> and <code>B</code> is <code>UINT</code>, which an <code>INT</code> or a <code>UINT</code> of 16 bits holds whole, so on every target; unless the value is what an operator gives (below).</li>
270282 </ul>
271283 <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>
272284 <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). An <code>INT</code> widens to <code>I64</code>, and a <code>UINT</code> to <code>U64</code>, wherever its value goes where an <code>I64</code> is wanted: in <code>a, b := f(x)</code> and <code>return f(x)</code> as in any other assignment, to the bounds of a <code>for</code> and the step of <code>INC</code> and <code>DEC</code> whose variable is an <code>I64</code>, and in an expression, where it meets an <code>I64</code> (section 6.1). The types themselves stay two: a <code>^INT</code> isn’t a <code>^I64</code>, an <code>INT</code> variable isn’t passed to a <code>var</code> parameter of type <code>I64</code>, and a procedure returning an <code>INT</code> isn’t of a procedure type returning an <code>I64</code>.</p>
285+<p>A <code>U8</code>, <code>I8</code> or <code>I16</code> widens to <code>INT</code>, and a <code>U8</code> or <code>U16</code> to <code>UINT</code>, in the same places, as an <code>INT</code> to <code>I64</code>: assigned, passed, returned, in <code>a, b := f(x)</code>, to a <code>for</code>’s bounds and <code>INC</code> and <code>DEC</code>’s step, and in an expression, where it meets an <code>INT</code> or a <code>UINT</code> (section 6.1); not in <code>return f(x)</code>, which passes <code>f</code>’s results on as they are. They widen only that far: a <code>U8</code> meets an <code>I64</code> only as <code>INT(b)</code> or <code>I64(b)</code>. And they widen only as values that are moved: a variable, an element, a field, a call’s result or a conversion’s. What an operator gives on them doesn’t: it was computed in their type, and has wrapped there. With <code>a, b: U8</code> holding 200 and 100, <code>a + b</code> is 44, so <code>n := a + b</code>, for an <code>INT</code> <code>n</code>, is an error; <code>n := INT(a) + b</code> is 300, and says where the sum is made.</p>
286+<pre><code>var s: []U8; n, d: INT;
287+n := s[i]; (* an element: widens *)
288+n := n * 10 + s[i] - &#39;0&#39;; (* n * 10 + s[i] is an INT, and so the rest *)
289+d := s[i] - &#39;0&#39;; (* an error: a U8, which may have wrapped *)
290+d := INT(s[i]) - &#39;0&#39;; (* below &#39;0&#39; too, it is negative *)</code></pre>
273291 <h1 id="expressions">6. Expressions</h1>
274292 <pre><code>Expr = Conjunct { &quot;or&quot; Conjunct } .
275293 Conjunct = Relation { &quot;and&quot; Relation } .
@@ -293,7 +311,7 @@
293311 <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>
294312 <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 or <code>try</code>, so <code>^T(x)^ := v</code> isn’t one; a view, <code>mem[a].(I64) := v</code> (section 6.9), says it without a pointer.</p>
295313 <h2 id="integers">6.1 Integers</h2>
296-<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, or one is an <code>INT</code> and the other an <code>I64</code> (a <code>UINT</code> and a <code>U64</code>), and the <code>INT</code> widens to <code>I64</code> (section 5.10). So do <code>v</code> and <code>k</code> in <code>INC(v, k)</code> and <code>DEC(v, k)</code>, where only <code>k</code> widens: an <code>I64</code> <code>k</code> isn’t added to an <code>INT</code> <code>v</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>. Other integer types are never mixed, whatever their sizes: with <code>i: I32</code>, <code>i &lt; LEN(s)</code> is an error, and <code>i</code> should be an <code>INT</code>. With <code>pos: I64</code>, <code>pos + LEN(s)</code> is an <code>I64</code>.</p>
314+<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, or one is an <code>INT</code> and the other an <code>I64</code> (a <code>UINT</code> and a <code>U64</code>), and the <code>INT</code> widens to <code>I64</code>, or one is an <code>INT</code> and the other a <code>U8</code>, <code>I8</code> or <code>I16</code> (a <code>UINT</code> and a <code>U8</code> or <code>U16</code>) that no operator gave, and it widens to <code>INT</code> (section 5.10). So do <code>v</code> and <code>k</code> in <code>INC(v, k)</code> and <code>DEC(v, k)</code>, where only <code>k</code> widens: an <code>I64</code> <code>k</code> isn’t added to an <code>INT</code> <code>v</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>. Other integer types are never mixed, whatever their sizes: with <code>i: I32</code>, <code>i &lt; LEN(s)</code> is an error, and <code>i</code> should be an <code>INT</code>; with <code>c: U8</code>, <code>c &lt; LEN(s)</code> is an <code>INT</code> comparison. With <code>pos: I64</code>, <code>pos + LEN(s)</code> is an <code>I64</code>.</p>
297315 <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>
298316 <p><code>SIZE(T)</code>, and <code>LEN</code> of an array or a string constant, are untyped constants, like a literal.</p>
299317 <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 (section 10), whatever the type and the target.</p>
@@ -314,7 +332,7 @@
314332 </ul>
315333 <h2 id="arrays-and-slices">6.5 Arrays and slices</h2>
316334 <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>
317-<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>
335+<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; the empty one, <code>[]</code>, is the empty slice, as a slice variable starts (section 4), and no variable at all.</p>
318336 <pre><code>c := {ch: &#39;A&#39;, attr: 7};
319337 Fmt.print(&quot;{} of {}\n&quot;, [Fmt.int(n), Fmt.int(m)]);</code></pre>
320338 <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>
@@ -513,6 +531,7 @@
513531 | &quot;match&quot; Expr &quot;of&quot; { &quot;|&quot; Arm } &quot;end&quot;
514532 | &quot;return&quot; [ Expr { &quot;,&quot; Expr } ]
515533 | &quot;break&quot;
534+ | &quot;continue&quot;
516535 | &quot;defer&quot; Statement
517536 | &quot;try&quot; Designator .
518537 Arm = ( ident [ &quot;(&quot; ident { &quot;,&quot; ident } &quot;)&quot; ]
@@ -528,10 +547,17 @@
528547 <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>
529548 <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, or are <code>INT</code>s that widen to an <code>I64</code> <code>i</code>, as with <code>+</code> (section 6.1): so in <code>for i := 0 to LEN(s) - 1</code>, <code>i</code> is an <code>INT</code> or an <code>I64</code>.</p>
530549 <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>
531-<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>
550+<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. <code>continue</code> ends the round of the innermost one, as reaching the end of its body would: a <code>while</code> tests its condition again, a <code>repeat</code> tests its <code>until</code>, and a <code>for</code> steps its variable, or ends. There is no <code>goto</code>.</p>
551+<p>A <code>continue</code> passes over the rest of the body, the step of a <code>while</code> or a <code>repeat</code> included, if it stands there: so the step comes first.</p>
552+<pre><code>while i &lt; LEN(t) do
553+ ch, n := Str.decode(t[i..LEN(t)]);
554+ i := i + n; (* before any continue *)
555+ if ch = 0ADH then continue; end; (* a soft hyphen, passed over *)
556+ ...
557+end;</code></pre>
532558 <h2 id="return">7.3 Return</h2>
533559 <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>
534-<p>A slice returned must not point into the procedure’s own frame, which is gone once it returns. It is an error to return, as a slice, a local array, a value parameter that is an array, an array literal, or an array a call returns, or a slice of one, a field or an element of one included:</p>
560+<p>A slice returned must not point into the procedure’s own frame, which is gone once it returns. It is an error to return, as a slice, a local array, a value parameter that is an array, an array literal other than <code>[]</code>, or an array a call returns, or a slice of one, a field or an element of one included:</p>
535561 <pre><code>proc short(h: Hex): []U8; (* Hex = [64]U8 *)
536562 begin
537563 return h[0..8]; (* an error: h is the procedure&#39;s copy *)
@@ -573,7 +599,7 @@
573599 <p><code>FENCE</code> also orders the program’s ordinary accesses against those of other processors and devices.</p>
574600 <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>
575601 <h2 id="defer">7.7 Defer</h2>
576-<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>
602+<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> or <code>continue</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>
577603 <pre><code>module Head;
578604 import Sys, Out;
579605
@@ -600,7 +626,7 @@
600626 end;
601627
602628 end Head.</code></pre>
603-<p><code>return e;</code> evaluates <code>e</code> before the deferred statements run. A deferred statement can’t contain <code>defer</code>, nor a <code>return</code>, <code>break</code> or <code>try</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>
629+<p><code>return e;</code> evaluates <code>e</code> before the deferred statements run. A deferred statement can’t contain <code>defer</code>, nor a <code>return</code>, <code>break</code>, <code>continue</code> or <code>try</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>
604630 <h2 id="try">7.8 Try</h2>
605631 <p>A procedure that can fail returns an <code>ERROR</code> as its last result (section 5.8), <code>nil</code> when it didn’t. A caller that can’t deal with the failure passes it on to its own caller, which <code>try</code> does in a word:</p>
606632 <pre><code>proc total(words: [][]U8): (INT, ERROR);
@@ -727,7 +753,7 @@
727753 <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, <code>-Werror</code> included (section 10). That a program that is an error in this report is rejected isn’t free; the words that say so are. So is what a program that fails says on standard error: conformance is judged by a program’s standard output and exit status, never by its standard error.</li>
728754 <li><strong>The command line.</strong> How the compiler is run, its options, and where its library lives (sections 1 and 3).</li>
729755 </ul>
730-<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. The rest of the library (<code>Heap</code>, <code>Fmt</code>, <code>List</code>, <code>Map</code>, <code>Vec</code>, <code>Sort</code>, <code>Math</code>, <code>Files</code>, <code>Opt</code> and the rest of <code>Sys</code>) is the standard library: a target may leave a module out, and one that has it gives what <code>doc/raz-lib.md</code> says. <code>conform/</code> tests the core only.</p>
756+<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. The rest of the library (<code>Heap</code>, <code>Fmt</code>, <code>List</code>, <code>Map</code>, <code>Vec</code>, <code>Sort</code>, <code>Math</code>, <code>Files</code>, <code>Opt</code>, <code>Width</code> and the rest of <code>Sys</code>) is the standard library: a target may leave a module out, and one that has it gives what <code>doc/raz-lib.md</code> says. <code>conform/</code> tests the core only.</p>
731757 <h1 id="appendix-b.-the-grammar">Appendix B. The grammar</h1>
732758 <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>
733759 <pre><code>ident = letter { letter | digit } .
@@ -805,6 +831,7 @@
805831 | &quot;match&quot; Expr &quot;of&quot; { &quot;|&quot; Arm } &quot;end&quot;
806832 | &quot;return&quot; [ Expr { &quot;,&quot; Expr } ]
807833 | &quot;break&quot;
834+ | &quot;continue&quot;
808835 | &quot;defer&quot; Statement
809836 | &quot;try&quot; Designator .
810837 Arm = ( ident [ &quot;(&quot; ident { &quot;,&quot; ident } &quot;)&quot; ]
@@ -916,6 +943,10 @@
916943 <td><code>Opt</code></td>
917944 <td>a command line read through one table, by <code>getopt</code>’s rules with long options; its help and its mistakes</td>
918945 </tr>
946+<tr>
947+<td><code>Width</code></td>
948+<td>how many columns of a terminal a character, or a string, takes: 0, 1 or 2, as <code>wcwidth</code> says</td>
949+</tr>
919950 </tbody>
920951 </table>
921952 <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>
@@ -1368,6 +1399,11 @@
13681399 usage: keep start [-b label] name command [argument ...]</code></pre>
13691400 <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>
13701401 <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>
1402+<p><strong>Width</strong> says how many columns of a terminal text takes, for a program with a screen that wraps its lines and cuts them at the window’s edge.</p>
1403+<pre><code>module Width;
1404+proc width*(c: I32): INT; (* the columns the character c takes: 0, 1 or 2 *)
1405+proc columns*(s: []U8): INT; (* the columns the UTF-8 text s takes *)</code></pre>
1406+<p>A combining mark, a format character, a control and Hangul’s medial and final jamo take 0 columns; an ideograph, a kana, most emoji and the rest that Unicode calls East Asian Wide or Fullwidth take 2; every other character takes 1, the ambiguous ones among them, as most terminals draw them. These are the C library’s <code>wcwidth</code>’s answers, but for a control, which is -1 there. <code>Width</code> knows characters, not clusters: an emoji joined to another by a zero width joiner, or a flag, counts as its parts. Its tables, about 4 KB, come from Unicode’s data, made again by <code>tools/Widths.raz</code> for a new version of Unicode; a program that imports <code>Width</code> and calls neither procedure carries none of them.</p>
13711407 </div>
13721408 </main>
13731409 <footer>raz is under the ISC license.</footer>

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

@@ -87,7 +87,7 @@
8787 0
8888 -1
8989 </code></pre>
90-<p><code>defer s;</code> runs <code>s</code> when the program leaves the statements the <code>defer</code> stands in: at their end, or by a <code>return</code> or a <code>break</code>. Deferred statements run the last first, and only those whose <code>defer</code> was reached. So a file is closed beside the line that opens it, however the procedure ends.</p>
90+<p><code>defer s;</code> runs <code>s</code> when the program leaves the statements the <code>defer</code> stands in: at their end, or by a <code>return</code>, a <code>break</code> or a <code>continue</code>. Deferred statements run the last first, and only those whose <code>defer</code> was reached. So a file is closed beside the line that opens it, however the procedure ends.</p>
9191 <h2>The order, and a <code>return</code> value</h2>
9292 <p>A <code>return e;</code> evaluates <code>e</code> before the deferred statements run, so the value is what it was at the return.</p>
9393 <div class="file"><span>Order.raz</span></div><pre class="code"><code><span class="kw">module</span> Order;
@@ -124,7 +124,7 @@
124124 body: 3 2 1
125125 </code></pre>
126126 <h2>In a loop</h2>
127-<p>A <code>defer</code> stands in the statement list that holds it, so in a loop body it runs at the end of each pass, and on a <code>break</code>.</p>
127+<p>A <code>defer</code> stands in the statement list that holds it, so in a loop body it runs at the end of each pass, and on a <code>break</code> or a <code>continue</code>.</p>
128128 <div class="file"><span>Passes.raz</span></div><pre class="code"><code><span class="kw">module</span> Passes;
129129 <span class="kw">import</span> Out;
130130

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

@@ -70,7 +70,7 @@
7070 </code></pre>
7171 <h2>INT is the everyday one</h2>
7272 <p>Lengths, indexes, counts and sizes are <code>INT</code>s. <code>LEN(s)</code> of a slice is an <code>INT</code>, and so is the loop variable that walks it. It is as big as an address, so it is the integer a pointer converts to, and the word the atomics work on. Reach for <code>INT</code> unless you have a reason: a byte is a <code>U8</code>, a character an <code>I32</code>, a file's size an <code>I64</code>, a hash a <code>U64</code>.</p>
73-<p><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> (and a <code>UINT</code> into a <code>U64</code>) wherever it meets one, in <code>pos + LEN(s)</code> as in a call, which is why <code>Out.int(n)</code> and <code>Fmt.int(n)</code> take an <code>I64</code> and accept any <code>INT</code>. The other way is written, <code>INT(pos)</code>, since an <code>INT</code> may be smaller on another machine. Nothing else converts unasked: any other integer is converted where it is written, as <code>Out.int(I64(b))</code>.</p>
73+<p><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> (and a <code>UINT</code> into a <code>U64</code>) wherever it meets one, in <code>pos + LEN(s)</code> as in a call, which is why <code>Out.int(n)</code> and <code>Fmt.int(n)</code> take an <code>I64</code> and accept any <code>INT</code>. The other way is written, <code>INT(pos)</code>, since an <code>INT</code> may be smaller on another machine. An <code>INT</code> holds every <code>U8</code>, <code>I8</code> and <code>I16</code> on any machine, so those go silently into an <code>INT</code> too (and a <code>U8</code> or <code>U16</code> into a <code>UINT</code>): <code>n := s[i]</code>, and <code>n * 10 + s[i] - '0'</code> for a digit. Not what an operator made of them, which was computed in the small type and may have wrapped there: with <code>a, b: U8</code>, <code>n := a + b</code> is an error, and <code>INT(a) + b</code> the sum. And only one step: a <code>U8</code> goes into an <code>INT</code>, not on into an <code>I64</code>, so <code>Out.int(I64(b))</code> still says it. Nothing else converts unasked.</p>
7474 <h2>A number written in the program</h2>
7575 <p>A number in the program text is untyped until it meets a type, and then it must fit. <code>0FFH</code> is hexadecimal (it starts with a digit and ends in <code>H</code>), a character in quotes is its code point, and <code>'\u{E9}'</code> is a code point written by number. A hexadecimal literal too big for an <code>I64</code> is a <code>U64</code>.</p>
7676 <div class="file"><span>Literals.raz</span></div><pre class="code"><code><span class="kw">module</span> Literals;

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

@@ -277,16 +277,17 @@
277277 </code></pre>
278278 <p>A line of an indented raw string that doesn't start with the closing line's blanks is an error, so a slip in the indent is caught where it is made, not printed. A raw string can't hold a backquote; join one in with <code>+</code> and an ordinary string that holds it.</p>
279279 <h2>UTF-8</h2>
280-<p>A character is an <code>I32</code>, its code point. A string stays bytes; UTF-8 is how <code>Str</code> reads them. <code>Str.next</code> walks a string a character at a time, giving each one and where the next starts, -1 at the end. <code>Str.decode</code> reads the first character of a string and says how many bytes it took, <code>Str.decodeLast</code> the last, and <code>Str.encode</code> goes the other way. <code>Str.chars</code> counts characters and <code>Str.valid</code> says whether a string is UTF-8 at all; a byte that doesn't start a character rightly reads as FFFDH, the character that stands for a wrong one. Byte length and character count are different things, and the program is the one that says which it wants.</p>
280+<p>A character is an <code>I32</code>, its code point. A string stays bytes; UTF-8 is how <code>Str</code> reads them. <code>Str.next</code> walks a string a character at a time, giving each one and where the next starts, -1 at the end. <code>Str.decode</code> reads the first character of a string and says how many bytes it took, <code>Str.decodeLast</code> the last, and <code>Str.encode</code> goes the other way. <code>Str.chars</code> counts characters and <code>Str.valid</code> says whether a string is UTF-8 at all; a byte that doesn't start a character rightly reads as FFFDH, the character that stands for a wrong one. Byte length and character count are different things, and the program is the one that says which it wants. On a terminal there is a third: a character takes 0, 1 or 2 columns, a combining accent none and an ideograph two, and <code>Width.columns</code> counts those.</p>
281281 <div class="file"><span>Runes.raz</span></div><pre class="code"><code><span class="kw">module</span> Runes;
282-<span class="kw">import</span> Out, Str;
282+<span class="kw">import</span> Out, Str, Width;
283283
284284 <span class="kw">proc</span> main*;
285285 <span class="kw">var</span> s: []<span class="ty">U8</span>; c: <span class="ty">I32</span>; i, size: <span class="ty">INT</span>; bytes: [<span class="number">4</span>]<span class="ty">U8</span>; k: <span class="ty">INT</span>;
286286 <span class="kw">begin</span>
287287 s := <span class="string">&quot;caf\u{E9} \u{3BB}&quot;</span>;
288288 Out.int(<span class="ty">LEN</span>(s)); Out.str(<span class="string">&quot; bytes, &quot;</span>);
289- Out.int(Str.chars(s)); Out.str(<span class="string">&quot; characters\n&quot;</span>);
289+ Out.int(Str.chars(s)); Out.str(<span class="string">&quot; characters, &quot;</span>);
290+ Out.int(Width.columns(<span class="string">&quot;\u{4E2D}\u{6587}&quot;</span>)); Out.str(<span class="string">&quot; columns for two ideographs\n&quot;</span>);
290291
291292 <span class="comment">(* each character, as its code point *)</span>
292293 c, i := Str.next(s, <span class="number">0</span>);
@@ -304,7 +305,7 @@
304305 <span class="kw">end</span>;
305306
306307 <span class="kw">end</span> Runes.</code></pre>
307-<pre class="output"><code>8 bytes, 6 characters
308+<pre class="output"><code>8 bytes, 6 characters, 4 columns for two ideographs
308309 99 97 102 233 32 955
309310 955 is last, in 2 bytes
310311 λ
@@ -312,7 +313,7 @@
312313 </code></pre>
313314 <p><code>Str</code> knows UTF-8 and no more of Unicode: its case is ASCII's, and it doesn't say how wide a character is on a terminal or which spellings of a text are the same. Those need tables bigger than the rest of the library.</p>
314315 <h2>Loops over lengths</h2>
315-<p>A <code>for</code> loop takes its bounds once, and never steps past the last: with an empty slice, <code>0 to LEN(s) - 1</code> doesn't run at all, and the variable can't wrap. <code>for</code> takes a constant step with <code>by</code>, and <code>while</code> and <code>repeat ... until</code> do the rest.</p>
316+<p>A <code>for</code> loop takes its bounds once, and never steps past the last: with an empty slice, <code>0 to LEN(s) - 1</code> doesn't run at all, and the variable can't wrap. <code>for</code> takes a constant step with <code>by</code>, and <code>while</code> and <code>repeat ... until</code> do the rest. <code>break</code> leaves a loop, and <code>continue</code> ends its round: a <code>for</code> steps, a <code>while</code> or a <code>repeat</code> tests again. So a <code>while</code> moves on before any <code>continue</code>, or it never moves at all.</p>
316317 <div class="file"><span>Loops.raz</span></div><pre class="code"><code><span class="kw">module</span> Loops;
317318 <span class="kw">import</span> Out;
318319
@@ -326,12 +327,18 @@
326327 Out.int(i); Out.ln;
327328 <span class="kw">repeat</span> <span class="ty">DEC</span>(i, <span class="number">30</span>); <span class="kw">until</span> i &lt; <span class="number">0</span>;
328329 Out.int(i); Out.ln;
330+ <span class="kw">for</span> i := <span class="number">1</span> <span class="kw">to</span> <span class="number">10</span> <span class="kw">do</span>
331+ <span class="kw">if</span> i <span class="kw">mod</span> <span class="number">3</span> = <span class="number">0</span> <span class="kw">then</span> continue; <span class="kw">end</span>; <span class="comment">(* 3, 6 and 9 passed over *)</span>
332+ Out.int(i); Out.char(<span class="string">&#x27; &#x27;</span>);
333+ <span class="kw">end</span>;
334+ Out.ln;
329335 <span class="kw">end</span>;
330336
331337 <span class="kw">end</span> Loops.</code></pre>
332338 <pre class="output"><code>10 5 0
333339 243
334340 -27
341+1 2 4 5 7 8 10
335342 </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>
336343 </main>
337344 <footer>raz is under the ISC license.</footer>

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

@@ -64,7 +64,7 @@
6464 <pre class="output"><code>300 4 300 42.857 233 true
6565 </code></pre>
6666 <h2>Conversions are written</h2>
67-<p>Two types never mix but for one: an <code>INT</code> goes into an <code>I64</code> wherever it meets one, which loses nothing, so with <code>pos: I64</code>, <code>pos + LEN(s)</code> is an <code>I64</code>. With <code>i: I32</code> and a slice <code>s</code>, <code>i &lt; LEN(s)</code> is an error. A type's name converts: <code>F64(n)</code>, <code>I64(b)</code>, <code>U8(x)</code>; an <code>I64</code> becomes an <code>INT</code> only so, <code>INT(pos)</code>, since an <code>INT</code> may be smaller on another machine. The <a href="integers.html">lesson on integers</a> says what each width conversion does.</p>
67+<p>Two types never mix but where nothing can be lost: an <code>INT</code> goes into an <code>I64</code> wherever it meets one, so with <code>pos: I64</code>, <code>pos + LEN(s)</code> is an <code>I64</code>; and a <code>U8</code>, <code>I8</code> or <code>I16</code> into an <code>INT</code>, unless an operator made it, so <code>n := s[i]</code> needs no conversion. With <code>i: I32</code> and a slice <code>s</code>, <code>i &lt; LEN(s)</code> is an error. A type's name converts: <code>F64(n)</code>, <code>I64(b)</code>, <code>U8(x)</code>; an <code>I64</code> becomes an <code>INT</code> only so, <code>INT(pos)</code>, since an <code>INT</code> may be smaller on another machine. The <a href="integers.html">lesson on integers</a> says what each width conversion does.</p>
6868 <p>A number written in the program is untyped until it meets a type, and <code>1.5</code> is a real, which an integer never becomes without a conversion.</p>
6969 <div class="file"><span>Mix.raz</span></div><pre class="code"><code><span class="kw">module</span> Mix;
7070 <span class="kw">import</span> Out;

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

@@ -105,7 +105,7 @@
105105 01
106106 </code></pre>
107107 <h2>Enumerations</h2>
108-<p>An enumeration is a list of names, in order. They convert to their position and back, and a <code>for</code> loop can run over them. An integer that has no name at its position is a failed check, never a silent wrong value.</p>
108+<p>An enumeration is a list of names, in order. They convert to their position and back, and a <code>for</code> loop can run over them. A name may be written with its type, <code>Day.mon</code>, and two enumerations of a module may share a name, <code>Style.bold</code> and <code>Elem.bold</code>, which is then always written so. An integer that has no name at its position is a failed check, never a silent wrong value.</p>
109109 <div class="file"><span>Days.raz</span></div><pre class="code"><code><span class="kw">module</span> Days;
110110 <span class="kw">import</span> Out;
111111