From 5b58575886cc369e2bb76ba21f360e379119ac90 Mon Sep 17 00:00:00 2001 From: Luis <42945842+ldiaz94@users.noreply.github.com> Date: Fri, 16 Oct 2026 11:34:00 +0100 Subject: [PATCH] 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. --- diff --git a/site/content/advanced/12-syscalls.txt b/site/content/advanced/12-syscalls.txt index de55aec..1d11acb 100644 --- a/site/content/advanced/12-syscalls.txt +++ b/site/content/advanced/12-syscalls.txt @@ -102,9 +102,9 @@ (* length 4096; PROT_READ|WRITE = 3; MAP_PRIVATE|ANONYMOUS = 22H; no fd *) p := ^U8(SYSCALL(9, 0, 4096, 3, 22H, -1, 0)); if INT(p) < 0 then Out.str("no memory\n"); return; end; - Out.int(INT(p[0]) + INT(p[4095])); Out.str(" (zero, as promised)\n"); + Out.int(INT(p[0]) + p[4095]); Out.str(" (zero, as promised)\n"); for i := 0 to 4095 do p[i] := U8(i); end; - for i := 0 to 4095 do INC(total, INT(p[i])); end; + for i := 0 to 4095 do INC(total, p[i]); end; Out.int(total); Out.ln; _ := SYSCALL(11, p, 4096); end; diff --git a/site/content/advanced/15-atomics.txt b/site/content/advanced/15-atomics.txt index 1f5da3d..6eed466 100644 --- a/site/content/advanced/15-atomics.txt +++ b/site/content/advanced/15-atomics.txt @@ -60,7 +60,7 @@ if err # nil then Out.str(MSG(err)); Out.ln; return; end; end; for i := 0 to 3 do Thread.join(th[i]); end; - for i := 0 to 3999 do taken := taken + INT(seen[i]); end; + for i := 0 to 3999 do taken := taken + seen[i]; end; Out.int(next); Out.char(' '); Out.int(taken); Out.ln; end; diff --git a/site/content/tour/03-integers.txt b/site/content/tour/03-integers.txt index 2626425..1cf6507 100644 --- a/site/content/tour/03-integers.txt +++ b/site/content/tour/03-integers.txt @@ -39,7 +39,7 @@ 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`. -`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))`. +`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. ## A number written in the program diff --git a/site/content/tour/04-values.txt b/site/content/tour/04-values.txt index e7ddb80..4217e15 100644 --- a/site/content/tour/04-values.txt +++ b/site/content/tour/04-values.txt @@ -9,7 +9,7 @@ ## Conversions are written -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. +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. 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. diff --git a/site/content/tour/06-slices.txt b/site/content/tour/06-slices.txt index 567b38d..f61ab07 100644 --- a/site/content/tour/06-slices.txt +++ b/site/content/tour/06-slices.txt @@ -198,18 +198,19 @@ ## UTF-8 -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. +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. ```raz Runes run module Runes; -import Out, Str; +import Out, Str, Width; proc main*; var s: []U8; c: I32; i, size: INT; bytes: [4]U8; k: INT; begin s := "caf\u{E9} \u{3BB}"; Out.int(LEN(s)); Out.str(" bytes, "); - Out.int(Str.chars(s)); Out.str(" characters\n"); + Out.int(Str.chars(s)); Out.str(" characters, "); + Out.int(Width.columns("\u{4E2D}\u{6587}")); Out.str(" columns for two ideographs\n"); (* each character, as its code point *) c, i := Str.next(s, 0); @@ -233,7 +234,7 @@ ## Loops over lengths -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. +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. ```raz Loops run module Loops; @@ -249,6 +250,11 @@ Out.int(i); Out.ln; repeat DEC(i, 30); until i < 0; Out.int(i); Out.ln; + for i := 1 to 10 do + if i mod 3 = 0 then continue; end; (* 3, 6 and 9 passed over *) + Out.int(i); Out.char(' '); + end; + Out.ln; end; end Loops. diff --git a/site/content/tour/08-variants.txt b/site/content/tour/08-variants.txt index 585b480..8785292 100644 --- a/site/content/tour/08-variants.txt +++ b/site/content/tour/08-variants.txt @@ -7,7 +7,7 @@ ## Enumerations -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. +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. ```raz Days run module Days; diff --git a/site/content/tour/11-defer.txt b/site/content/tour/11-defer.txt index d04aeee..0d33a09 100644 --- a/site/content/tour/11-defer.txt +++ b/site/content/tour/11-defer.txt @@ -5,7 +5,7 @@ ```raz Defers run ``` -`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. +`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. ## The order, and a `return` value @@ -46,7 +46,7 @@ ## In a loop -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`. +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`. ```raz Passes run module Passes; diff --git a/site/public/_redirects b/site/public/_redirects index 931ca50..eb80dfb 100644 --- a/site/public/_redirects +++ b/site/public/_redirects @@ -1 +1 @@ -/download/latest /download/raz-0.16.0-linux-x86_64.tar.gz 302 +/download/latest /download/raz-0.17.0-linux-x86_64.tar.gz 302 diff --git a/site/public/advanced/atomics.html b/site/public/advanced/atomics.html index b22bb46..5514f00 100644 --- a/site/public/advanced/atomics.html +++ b/site/public/advanced/atomics.html @@ -90,7 +90,7 @@ if err # nil then Out.str(MSG(err)); Out.ln; return; end; end; for i := 0 to 3 do Thread.join(th[i]); end; - for i := 0 to 3999 do taken := taken + INT(seen[i]); end; + for i := 0 to 3999 do taken := taken + seen[i]; end; Out.int(next); Out.char(' '); Out.int(taken); Out.ln; end; diff --git a/site/public/advanced/syscalls.html b/site/public/advanced/syscalls.html index d1e9cfc..8990a57 100644 --- a/site/public/advanced/syscalls.html +++ b/site/public/advanced/syscalls.html @@ -126,9 +126,9 @@ (* length 4096; PROT_READ|WRITE = 3; MAP_PRIVATE|ANONYMOUS = 22H; no fd *) p := ^U8(SYSCALL(9, 0, 4096, 3, 22H, -1, 0)); if INT(p) < 0 then Out.str("no memory\n"); return; end; - Out.int(INT(p[0]) + INT(p[4095])); Out.str(" (zero, as promised)\n"); + Out.int(INT(p[0]) + p[4095]); Out.str(" (zero, as promised)\n"); for i := 0 to 4095 do p[i] := U8(i); end; - for i := 0 to 4095 do INC(total, INT(p[i])); end; + for i := 0 to 4095 do INC(total, p[i]); end; Out.int(total); Out.ln; _ := SYSCALL(11, p, 4096); end; diff --git a/site/public/download/raz-0.17.0-linux-x86_64.tar.gz b/site/public/download/raz-0.17.0-linux-x86_64.tar.gz new file mode 100644 index 0000000..8325f76 Binary files /dev/null and b/site/public/download/raz-0.17.0-linux-x86_64.tar.gz differ diff --git a/site/public/download/raz-0.17.0-linux-x86_64.tar.gz.sha256 b/site/public/download/raz-0.17.0-linux-x86_64.tar.gz.sha256 new file mode 100644 index 0000000..db106ec --- /dev/null +++ b/site/public/download/raz-0.17.0-linux-x86_64.tar.gz.sha256 @@ -0,0 +1 @@ +2425d173fb00eb6352a3a1c089469d038e00abae870816fd90d7a6fb707ae370 raz-0.17.0-linux-x86_64.tar.gz diff --git a/site/public/index.html b/site/public/index.html index 2f20c6b..94d4262 100644 --- a/site/public/index.html +++ b/site/public/index.html @@ -42,7 +42,7 @@
The language is defined by the report, which is short on purpose: whatever it doesn’t allow, raz doesn’t have. Its second volume describes the library. Both are on one page, and each is -a PDF: the language (29 pages) and +a PDF: the language (30 pages) and the library.
raz 0.16.0 is a tarball for x86-64 Linux with the compiler, raz,
+
raz 0.17.0 is a tarball for x86-64 Linux with the compiler, raz,
its library, lib/, which it finds beside itself, the formatter
and the documentation tool as sources in tools/, and the manual
pages. It needs nothing else installed.
$ tar xzf raz-0.16.0-linux-x86_64.tar.gz
-$ ln -s $PWD/raz-0.16.0-linux-x86_64/raz ~/.local/bin/raz
+$ tar xzf raz-0.17.0-linux-x86_64.tar.gz
+$ ln -s $PWD/raz-0.17.0-linux-x86_64/raz ~/.local/bin/raz
$ raz run Hello.raz
The link works since raz finds lib/ beside its real path. The
manual pages are in man/: man ./man/raz-tutorial.7.
The address download/latest always leads to the newest release,
-and download/raz-0.16.0-linux-x86_64.tar.gz to this one, for
-good. Earlier releases: 0.15.0, 0.14.0, 0.13.0, 0.12.0, 0.11.1, 0.11.0, 0.10.1, 0.10.0, 0.9.1, 0.9.0, 0.8.0, 0.7.1; each has its SHA-256 beside it, with
+and download/raz-0.17.0-linux-x86_64.tar.gz to this one, for
+good. Earlier releases: 0.16.0, 0.15.0, 0.14.0, 0.13.0, 0.12.0, 0.11.1, 0.11.0, 0.10.1, 0.10.0, 0.9.1, 0.9.0, 0.8.0, 0.7.1; each has its SHA-256 beside it, with
.sha256 added to its name.
-SHA-256 8b612205f434398dd82d72fbe481c3d9aabf408ec82541b0b6317eeddc71b17c
+SHA-256 2425d173fb00eb6352a3a1c089469d038e00abae870816fd90d7a6fb707ae370
diff --git a/site/public/raz-lib.pdf b/site/public/raz-lib.pdf
index 2dbb7b3..4752f89 100644
Binary files a/site/public/raz-lib.pdf and b/site/public/raz-lib.pdf differ
diff --git a/site/public/raz.pdf b/site/public/raz.pdf
index 19b448b..26ef4eb 100644
Binary files a/site/public/raz.pdf and b/site/public/raz.pdf differ
diff --git a/site/public/spec.html b/site/public/spec.html
index 598b5db..3742943 100644
--- a/site/public/spec.html
+++ b/site/public/spec.html
@@ -38,7 +38,7 @@
raz is a small systems language, first made for x86-64 Linux. A raz program can lay a record over a device’s registers, read and write a device’s memory exactly as written, take part in lock-free algorithms, make system calls and call C libraries. It has no garbage collector and no hidden run time: what the program does is what its text says.
This is the first volume of the report: the language, what an implementation chooses, and the grammar. The second, doc/raz-lib.md, is the library, which sections 3 and 10 and appendix A name.
This report defines the language. It is short on purpose. Whatever it doesn’t allow, raz doesn’t have.
-This is version 2026-10.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 try (section 7.8); it breaks a program that has a name try. 2026-10.25 is a fourth, for strings: raw strings, which may run over lines and may be indented with the code around them (section 2), and match on a string (section 7.4); it breaks no program. 2026-10.26 is a fifth: an INT widens to an I64 wherever it goes to one, in an expression too (sections 5.10 and 6.1); and a view, v.(T), reads and writes the bytes of a variable as a T (section 6.9); it breaks no program. 2026-10.27 mends a defect: returning a slice of the procedure’s own frame is an error (section 7.3), which breaks only a program that read memory already gone. 2026-10.28 mends another: an array a call returns lives to the end of its statement, and a slice of it kept past that is undefined (sections 8 and 10). 2026-10.29 is a sixth thaw: an array constant typed []T takes its length from its literal (section 4); it breaks no program.
+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 try (section 7.8); it breaks a program that has a name try. 2026-10.25 is a fourth, for strings: raw strings, which may run over lines and may be indented with the code around them (section 2), and match on a string (section 7.4); it breaks no program. 2026-10.26 is a fifth: an INT widens to an I64 wherever it goes to one, in an expression too (sections 5.10 and 6.1); and a view, v.(T), reads and writes the bytes of a variable as a T (section 6.9); it breaks no program. 2026-10.27 mends a defect: returning a slice of the procedure’s own frame is an error (section 7.3), which breaks only a program that read memory already gone. 2026-10.28 mends another: an array a call returns lives to the end of its statement, and a slice of it kept past that is undefined (sections 8 and 10). 2026-10.29 is a sixth thaw: an array constant typed []T takes its length from its literal (section 4); it breaks no program. 2026-10.30 mends a defect: [] used as a slice is the empty slice, which may be returned (sections 6.5 and 7.3); it breaks no program. 2026-10.31 is a seventh thaw: INT is at least 16 bits, and U8, I8 and I16 widen to it (sections 5.1, 5.10 and 6.1); an enumeration’s name may be written with its type, and must be where another declaration shares it (section 5.7); and continue (section 7.2), which breaks a program that has a name continue.
The language is frozen, softly, from this version on: it changes only to mend a defect, and its library grows only by what breaks no program written for it. What anyone wishes it had waits on a list, for a later thaw.
1. A first look
module Hello;
@@ -55,10 +55,10 @@
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.
Identifiers are an ASCII letter or _ followed by letters, digits and _, up to 63 characters. Case matters: count and Count are different names. _ alone isn’t a name: it is the blank, which stands only to the left of := (section 7.1).
Reserved words are lowercase, except VOLATILE:
-and begin break by code const defer div do else elsif end extern for
-forward if import in link match mod module not of or packed proc record
-repeat return set shl shr then to try type until var variant VOLATILE
-while xor
+and begin break by code const continue defer div do else elsif end
+extern for forward if import in link match mod module not of or packed
+proc record repeat return set shl shr then to try type until var
+variant VOLATILE while xor
static, in link static; (section 3), and check and off, in check off; (section 3), aren’t reserved.
Predeclared names are the basic types (section 5.1), ERROR, true, false, nil 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.
Numbers. 123 is decimal. 0FFH is hexadecimal: it starts with a digit, its digits are 0 to 9 and A to F, and it ends in H, all in capitals. 1.5 and 2.0E-3 are reals; a real always has a digit on both sides of its point, and its exponent, if it has one, is E, a sign if wanted, and digits. A decimal number above the largest I64, or a hexadecimal one above the largest U64, is an error; so is a real above the largest F64. A real below the least F64 is 0.
@@ -210,7 +210,7 @@
-INT is the everyday integer: lengths, indexes and sizes are INTs. 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). INT and I64 are two types, even where they have the same size: an INT goes silently into an I64 wherever it meets one, in an expression too (sections 5.10 and 6.1), and an I64 becomes an INT only by INT(x), which may drop bits on a smaller target. A type bigger than the largest INT in bytes is an error.
+INT is the everyday integer: lengths, indexes and sizes are INTs. It is as big as an address, and at least 16 bits, as UINT 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). INT and I64 are two types, even where they have the same size: an INT goes silently into an I64 wherever it meets one, in an expression too (sections 5.10 and 6.1), and an I64 becomes an INT only by INT(x), which may drop bits on a smaller target. A type bigger than the largest INT in bytes is an error.
F32 and F64 exist only on a target that has reals (appendix A). On one that hasn’t, a real literal, and a use of F32, F64 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 Fmt keeps one interface on every target.
Each is aligned as the target’s C aligns it: to its size on x86-64. So are ERROR (section 5.8), pointers and procedures, each as big as an address; a slice is aligned as an address is.
5.2 Arrays
@@ -242,6 +242,17 @@
Color* = (red, green, blue);
Colors* = set of Color;
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.
+A name of an enumeration may also be written with its type, Color.red, and one imported with the type’s module, M.Color.red. 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, Elem.bold. 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:
+type
+ Style = (bold, italic);
+ Elem = (para, bold, rule);
+proc rule; (* a procedure, beside Elem's rule *)
+...
+s := Style.bold; e := Elem.bold; e := Elem.rule;
+e := para; (* para is Elem's alone *)
+rule; (* the procedure *)
+s := bold; (* an error: write Style.bold or Elem.bold *)
+The type is never taken from where the name stands: s := bold is an error though s is a Style.
set of E, for an enumeration E of at most 64 names, holds any choice of E’s names: bit i stands for the name at position i. 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.
5.8 Errors
const NotFound*: ERROR = "not found";
@@ -266,10 +277,17 @@
A is [n]T and B is []T;
A is a string literal and B is []U8, ^U8 (a pointer to the bytes followed by a zero byte, as C wants), or [n]U8 with n at least the string’s length (the rest is zero);
A is a procedure and B a procedure type with the same signature;
-A is INT and B is I64, or A is UINT and B is U64, which loses nothing on any target.
+A is INT and B is I64, or A is UINT and B is U64, which loses nothing on any target;
+A is U8, I8 or I16 and B is INT, or A is U8 or U16 and B is UINT, which an INT or a UINT of 16 bits holds whole, so on every target; unless the value is what an operator gives (below).
A string’s bytes are constant. A []U8 or ^U8 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 [n]U8 made from a string is a copy, the program’s to change.
Nothing else converts silently. In particular, there is no other conversion between integer types, between integers and reals, or between F32 and F64, without a written conversion (section 6.7). An INT widens to I64, and a UINT to U64, wherever its value goes where an I64 is wanted: in a, b := f(x) and return f(x) as in any other assignment, to the bounds of a for and the step of INC and DEC whose variable is an I64, and in an expression, where it meets an I64 (section 6.1). The types themselves stay two: a ^INT isn’t a ^I64, an INT variable isn’t passed to a var parameter of type I64, and a procedure returning an INT isn’t of a procedure type returning an I64.
+A U8, I8 or I16 widens to INT, and a U8 or U16 to UINT, in the same places, as an INT to I64: assigned, passed, returned, in a, b := f(x), to a for’s bounds and INC and DEC’s step, and in an expression, where it meets an INT or a UINT (section 6.1); not in return f(x), which passes f’s results on as they are. They widen only that far: a U8 meets an I64 only as INT(b) or I64(b). 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 a, b: U8 holding 200 and 100, a + b is 44, so n := a + b, for an INT n, is an error; n := INT(a) + b is 300, and says where the sum is made.
+var s: []U8; n, d: INT;
+n := s[i]; (* an element: widens *)
+n := n * 10 + s[i] - '0'; (* n * 10 + s[i] is an INT, and so the rest *)
+d := s[i] - '0'; (* an error: a U8, which may have wrapped *)
+d := INT(s[i]) - '0'; (* below '0' too, it is negative *)
6. Expressions
Expr = Conjunct { "or" Conjunct } .
Conjunct = Relation { "and" Relation } .
@@ -293,7 +311,7 @@
and, or and not are for BOOLs only; &, |, xor and ~ are for integers only.
A pointer to a record isn’t the record: its fields are p^.f, never p.f, and the elements of a pointer to an array are p^[i]. A statement starts with a name or try, so ^T(x)^ := v isn’t one; a view, mem[a].(I64) := v (section 6.9), says it without a pointer.
6.1 Integers
-Both operands of + - * div mod & | xor, 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 INT and the other an I64 (a UINT and a U64), and the INT widens to I64 (section 5.10). So do v and k in INC(v, k) and DEC(v, k), where only k widens: an I64 k isn’t added to an INT v. The result has that type and wraps around at its width: in U8, 200 + 100 is 44. A unary minus wraps too: for x of an unsigned type, -x is 0 - x. Other integer types are never mixed, whatever their sizes: with i: I32, i < LEN(s) is an error, and i should be an INT. With pos: I64, pos + LEN(s) is an I64.
+Both operands of + - * div mod & | xor, 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 INT and the other an I64 (a UINT and a U64), and the INT widens to I64, or one is an INT and the other a U8, I8 or I16 (a UINT and a U8 or U16) that no operator gave, and it widens to INT (section 5.10). So do v and k in INC(v, k) and DEC(v, k), where only k widens: an I64 k isn’t added to an INT v. The result has that type and wraps around at its width: in U8, 200 + 100 is 44. A unary minus wraps too: for x of an unsigned type, -x is 0 - x. Other integer types are never mixed, whatever their sizes: with i: I32, i < LEN(s) is an error, and i should be an INT; with c: U8, c < LEN(s) is an INT comparison. With pos: I64, pos + LEN(s) is an I64.
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 i in p + i, or a conversion’s operand, any integer type will do, and its value is taken. On a target whose INT is narrower, a pointer’s offset is cut to an INT.
SIZE(T), and LEN of an array or a string constant, are untyped constants, like a literal.
div rounds toward zero and mod takes the sign of the dividend, as in C: -7 div 2 is -3, -7 mod 2 is -1. Dividing by zero, and dividing the smallest value of a signed type by -1, stop the program (section 10), whatever the type and the target.
@@ -314,7 +332,7 @@
6.5 Arrays and slices
a[i] is an element of an array or slice, and a[lo..hi] is the slice of the elements from lo up to but not including hi. Both are checked: i must be below the length, and 0 <= lo <= hi <= length. A check that fails prints to standard error where it is, as file, line and column, and what failed, with the values involved (index 7 is out of range for a length of 5), 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 I8, or a U64 past the length, fails like any other. A module that says check off; (section 3) leaves these checks out of its code.
-Literals. [e1, e2, ...] builds an array, and {f: e, g: e, ...} 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 [n]T has exactly n of them. A record literal names its fields, in any order, each at most once; the fields it leaves out are zero, so {} 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.
+Literals. [e1, e2, ...] builds an array, and {f: e, g: e, ...} 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 [n]T has exactly n of them. A record literal names its fields, in any order, each at most once; the fields it leaves out are zero, so {} 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, [], is the empty slice, as a slice variable starts (section 4), and no variable at all.
c := {ch: 'A', attr: 7};
Fmt.print("{} of {}\n", [Fmt.int(n), Fmt.int(m)]);
Arrays and strings compare. Two operands that are each a []T or a [n]T, of the same element type T, are = when they have the same length and the same elements, and # otherwise, where T is an integer type, BOOL, an enumeration, a set or a pointer type. A string literal compares as a []U8. The comparison is code of its own where it stands, a check of the lengths and then of the bytes, not a call.
@@ -513,6 +531,7 @@
| "match" Expr "of" { "|" Arm } "end"
| "return" [ Expr { "," Expr } ]
| "break"
+ | "continue"
| "defer" Statement
| "try" Designator .
Arm = ( ident [ "(" ident { "," ident } ")" ]
@@ -528,10 +547,17 @@
if, while and repeat take BOOL expressions. repeat runs its body at least once and stops when the condition is true.
for i := a to b by s do ... end; sets i to a, a + s, … while i <= b (or i >= b if s is negative). i is a variable of an integer or enumeration type, named by its name alone; a and then b are evaluated once, before the first round; s is a constant other than zero, and 1 if left out. a and b have i’s type, or are untyped constants that take it, or are INTs that widen to an I64 i, as with + (section 6.1): so in for i := 0 to LEN(s) - 1, i is an INT or an I64.
The loop never steps past b, so i can’t wrap: afterwards i holds the last value it took, or a if the body never ran. The body may assign i. Precisely, for a positive s: at the end of a round, if i <= b and b - i < s, the loop ends with i as it is; otherwise i becomes i + s, wrapping, and the loop goes on while i <= b. A negative s is the same, the other way round.
-break ends the innermost while, repeat or for it stands in, and the program goes on after it. There is no goto.
+break ends the innermost while, repeat or for it stands in, and the program goes on after it. continue ends the round of the innermost one, as reaching the end of its body would: a while tests its condition again, a repeat tests its until, and a for steps its variable, or ends. There is no goto.
+A continue passes over the rest of the body, the step of a while or a repeat included, if it stands there: so the step comes first.
+while i < LEN(t) do
+ ch, n := Str.decode(t[i..LEN(t)]);
+ i := i + n; (* before any continue *)
+ if ch = 0ADH then continue; end; (* a soft hyphen, passed over *)
+ ...
+end;
7.3 Return
return e; ends the procedure with the result e; return a, b; with several results; return f(x); with the several results of f, if they are the procedure’s own (section 8); return; 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).
-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:
+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 [], or an array a call returns, or a slice of one, a field or an element of one included:
proc short(h: Hex): []U8; (* Hex = [64]U8 *)
begin
return h[0..8]; (* an error: h is the procedure's copy *)
@@ -573,7 +599,7 @@
FENCE also orders the program’s ordinary accesses against those of other processors and devices.
Ordinary variables. Only volatile accesses, CAS, XCHG, XADD and FENCE 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 FENCE 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.
7.7 Defer
-defer s; runs the statement s when the program leaves the statement list the defer stands in: at its end, or by a return, or by a break out of it. Statements deferred in the same list run in the opposite order to their defers, and only those whose defer has been reached run.
+defer s; runs the statement s when the program leaves the statement list the defer stands in: at its end, or by a return, or by a break or continue out of it. Statements deferred in the same list run in the opposite order to their defers, and only those whose defer has been reached run.
module Head;
import Sys, Out;
@@ -600,7 +626,7 @@
end;
end Head.
-return e; evaluates e before the deferred statements run. A deferred statement can’t contain defer, nor a return, break or try that would leave it. A failed check, Rt.exit and Sys.exit end the program without running the deferred statements still pending.
+return e; evaluates e before the deferred statements run. A deferred statement can’t contain defer, nor a return, break, continue or try that would leave it. A failed check, Rt.exit and Sys.exit end the program without running the deferred statements still pending.
7.8 Try
A procedure that can fail returns an ERROR as its last result (section 5.8), nil when it didn’t. A caller that can’t deal with the failure passes it on to its own caller, which try does in a word:
proc total(words: [][]U8): (INT, ERROR);
@@ -727,7 +753,7 @@
Messages and warnings. The text of the compiler’s messages, how many errors it reports before it stops, and which warnings it gives, -Werror 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.
The command line. How the compiler is run, its options, and where its library lives (sections 1 and 3).
-The core. A target may leave out what the system under it can’t give: Sys past writing, ending the program and getting memory, Thread, link and extern. What it must have, besides the whole language, reals aside, is the core of the library: Rt, Out, Mem, Arena, Lock, Str and Buf, and of Sys what they need. A program that keeps to the core runs on every target. The rest of the library (Heap, Fmt, List, Map, Vec, Sort, Math, Files, Opt and the rest of Sys) is the standard library: a target may leave a module out, and one that has it gives what doc/raz-lib.md says. conform/ tests the core only.
+The core. A target may leave out what the system under it can’t give: Sys past writing, ending the program and getting memory, Thread, link and extern. What it must have, besides the whole language, reals aside, is the core of the library: Rt, Out, Mem, Arena, Lock, Str and Buf, and of Sys what they need. A program that keeps to the core runs on every target. The rest of the library (Heap, Fmt, List, Map, Vec, Sort, Math, Files, Opt, Width and the rest of Sys) is the standard library: a target may leave a module out, and one that has it gives what doc/raz-lib.md says. conform/ tests the core only.
Appendix B. The grammar
The whole syntax of raz, gathered from the sections above, with the symbols of section 2. { x } is any number of x, [ x ] is x or nothing, and ( x | y ) is one of them.
ident = letter { letter | digit } .
@@ -805,6 +831,7 @@
| "match" Expr "of" { "|" Arm } "end"
| "return" [ Expr { "," Expr } ]
| "break"
+ | "continue"
| "defer" Statement
| "try" Designator .
Arm = ( ident [ "(" ident { "," ident } ")" ]
@@ -916,6 +943,10 @@
Opt
a command line read through one table, by getopt’s rules with long options; its help and its mistakes
+
+Width
+how many columns of a terminal a character, or a string, takes: 0, 1 or 2, as wcwidth says
+
Lengths, counts, file descriptors, process ids and statuses are INTs, and a character is an I32. What may pass an INT on a small target is an I64: a file’s size and position, a time in nanoseconds, and a number read from text.
@@ -1368,6 +1399,11 @@
usage: keep start [-b label] name command [argument ...]
The sentences are unknown option -x (or --name, up to its =), -b needs a label, --follow takes no value and --wait wants a number from 1 to 600, not '0'. fail writes the program’s own mistakes the same way, but alone, so that the sentence can say where the help is: keep: no command; see keep -h.
A mistake in the table is the program’s, not its user’s. init checks the table before it reads a word, and ends the program with status 1: keep: option table, row 3: the option is in the scope already. The others are an option with neither a letter nor a long name, a long name with = in it, a letter -, and -h or --help in the table, since they are Opt’s.
+Width says how many columns of a terminal text takes, for a program with a screen that wraps its lines and cuts them at the window’s edge.
+module Width;
+proc width*(c: I32): INT; (* the columns the character c takes: 0, 1 or 2 *)
+proc columns*(s: []U8): INT; (* the columns the UTF-8 text s takes *)
+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 wcwidth’s answers, but for a control, which is -1 there. Width 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 tools/Widths.raz for a new version of Unicode; a program that imports Width and calls neither procedure carries none of them.
diff --git a/site/public/tour/defer.html b/site/public/tour/defer.html
index a62bf72..98e8dc7 100644
--- a/site/public/tour/defer.html
+++ b/site/public/tour/defer.html
@@ -87,7 +87,7 @@
0
-1
-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.
+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.
The order, and a return value
A return e; evaluates e before the deferred statements run, so the value is what it was at the return.
Order.razmodule Order;
@@ -124,7 +124,7 @@
body: 3 2 1
In a loop
-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.
+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.
Passes.razmodule Passes;
import Out;
diff --git a/site/public/tour/integers.html b/site/public/tour/integers.html
index d7024eb..91e36d1 100644
--- a/site/public/tour/integers.html
+++ b/site/public/tour/integers.html
@@ -70,7 +70,7 @@
INT is the everyday one
Lengths, indexes, counts and sizes are INTs. 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.
-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)).
+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.
A number written in the program
A number in the program text is untyped until it meets a type, and then it must fit. 0FFH is hexadecimal (it starts with a digit and ends in H), a character in quotes is its code point, and '\u{E9}' is a code point written by number. A hexadecimal literal too big for an I64 is a U64.
Literals.razmodule Literals;
diff --git a/site/public/tour/slices.html b/site/public/tour/slices.html
index d314550..649fca7 100644
--- a/site/public/tour/slices.html
+++ b/site/public/tour/slices.html
@@ -277,16 +277,17 @@
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 + and an ordinary string that holds it.
UTF-8
-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.
+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.
Runes.razmodule Runes;
-import Out, Str;
+import Out, Str, Width;
proc main*;
var s: []U8; c: I32; i, size: INT; bytes: [4]U8; k: INT;
begin
s := "caf\u{E9} \u{3BB}";
Out.int(LEN(s)); Out.str(" bytes, ");
- Out.int(Str.chars(s)); Out.str(" characters\n");
+ Out.int(Str.chars(s)); Out.str(" characters, ");
+ Out.int(Width.columns("\u{4E2D}\u{6587}")); Out.str(" columns for two ideographs\n");
(* each character, as its code point *)
c, i := Str.next(s, 0);
@@ -304,7 +305,7 @@
end;
end Runes.
-8 bytes, 6 characters
+8 bytes, 6 characters, 4 columns for two ideographs
99 97 102 233 32 955
955 is last, in 2 bytes
λ
@@ -312,7 +313,7 @@
Str 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.
Loops over lengths
-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.
+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.
Loops.razmodule Loops;
import Out;
@@ -326,12 +327,18 @@
Out.int(i); Out.ln;
repeat DEC(i, 30); until i < 0;
Out.int(i); Out.ln;
+ for i := 1 to 10 do
+ if i mod 3 = 0 then continue; end; (* 3, 6 and 9 passed over *)
+ Out.int(i); Out.char(' ');
+ end;
+ Out.ln;
end;
end Loops.
10 5 0
243
-27
+1 2 4 5 7 8 10
Save a program under its module’s name and run it with raz run Name.raz.
diff --git a/site/public/tour/values.html b/site/public/tour/values.html
index 508c2ee..9c81e35 100644
--- a/site/public/tour/values.html
+++ b/site/public/tour/values.html
@@ -64,7 +64,7 @@
300 4 300 42.857 233 true
Conversions are written
-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 says what each width conversion does.
+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 says what each width conversion does.
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.
Mix.razmodule Mix;
import Out;
diff --git a/site/public/tour/variants.html b/site/public/tour/variants.html
index 5bfaaee..882f973 100644
--- a/site/public/tour/variants.html
+++ b/site/public/tour/variants.html
@@ -105,7 +105,7 @@
01
Enumerations
-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.
+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.
Days.razmodule Days;
import Out;