From 38c95972f062322d2922068987ec9d1bca23dbc5 Mon Sep 17 00:00:00 2001 From: Luis <42945842+ldiaz94@users.noreply.github.com> Date: Wed, 14 Oct 2026 12:13:28 +0100 Subject: [PATCH] site: v0.11.0; tables as HTML, cards on phones; stops exit 2; two volumes Co-Authored-By: Claude Sonnet 5.5 --- diff --git a/site/build.py b/site/build.py index 2d41af6..ea2a4d4 100644 --- a/site/build.py +++ b/site/build.py @@ -17,7 +17,7 @@ summary: a line for the contents page --- Paragraphs, separated by blank lines. `code`, **bold**, - [links](url) and "- " lists are understood, and nothing else. + [links](url), "- " lists and pipe tables are understood, and nothing else. ```raz Name run ``` @@ -147,12 +147,26 @@ s = re.sub(r"\[([^\]]+)\]\(([^)]+)\)", r'\1', s) return s +def table(lines): + """A pipe table (header, a |---| rule, rows) as HTML. Each cell + carries its column's name, which the style sheet shows when the + screen is too narrow for columns.""" + cells = lambda l: [c.strip() for c in l.strip().strip("|").split("|")] + head = cells(lines[0]) + rows = "".join("%s" % "".join( + '%s' % (html.escape(h), inline(c)) + for h, c in zip(head, cells(l))) for l in lines[2:]) + return "%s%s
" % ( + "".join("%s" % inline(h) for h in head), rows) + def prose(text): out = [] for para in re.split(r"\n\s*\n", text.strip()): lines = para.split("\n") if para.startswith("## "): out.append("

%s

" % inline(para[3:])) + elif all(l.startswith("|") for l in lines): + out.append(table(lines)) elif all(l.startswith("- ") for l in lines): out.append("" % "".join( "
  • %s
  • " % inline(l[2:]) for l in lines)) diff --git a/site/content/advanced/09-lifecycle.txt b/site/content/advanced/09-lifecycle.txt index c928198..c6fbe03 100644 --- a/site/content/advanced/09-lifecycle.txt +++ b/site/content/advanced/09-lifecycle.txt @@ -108,7 +108,7 @@ ## Signals -A program is stopped by a signal it doesn't catch, with a message that names the place for `SIGSEGV` and `SIGFPE`, and without one for the others. A program that wants to handle one, say `SIGTERM` for a clean shutdown, doesn't write a handler that runs at an arbitrary moment. It asks for the signals to arrive as data: `Sys.catch` takes a list of signals and gives a descriptor that is ready to read when one comes, and `Sys.caught` says which. So the program waits for signals the way it waits for input. +A program is stopped by a signal it doesn't catch, with a message that names the place for `SIGSEGV` and `SIGFPE`, and without one for the others, and ends with status 2. A program that wants to handle one, say `SIGTERM` for a clean shutdown, doesn't write a handler that runs at an arbitrary moment. It asks for the signals to arrive as data: `Sys.catch` takes a list of signals and gives a descriptor that is ready to read when one comes, and `Sys.caught` says which. So the program waits for signals the way it waits for input. ```raz Terms run module Terms; diff --git a/site/content/home.html b/site/content/home.html index 15561d2..bbfcc05 100644 --- a/site/content/home.html +++ b/site/content/home.html @@ -23,7 +23,7 @@ ~10,700 lines of compiler ~650K lines compiled a second static executables, no run time to install - 1 report, about 30 pages + 2 volumes: the language and the library
    @@ -59,7 +59,7 @@ volatile accesses, atomics and lock-free code, in 18 more.

    The language, in writing

    -

    The language is defined by the report, which is +

    The language is defined by the report, in two volumes (the language, then the library), which is short on purpose: whatever it doesn’t allow, raz doesn’t have.

    Download

    diff --git a/site/content/tour/12-checks.txt b/site/content/tour/12-checks.txt index e3e0aa0..9ebb5ca 100644 --- a/site/content/tour/12-checks.txt +++ b/site/content/tour/12-checks.txt @@ -13,7 +13,7 @@ ## Other failures -The same shape of message tells of a `nil` pointer, a division by zero, a bad slice and a stack overflow. Each of them stops the program with status 2, or by the signal if the machine caught it, and never runs on with a wrong value. +The same shape of message tells of a `nil` pointer, a division by zero, a bad slice and a stack overflow. Each of them stops the program with status 2, and never runs on with a wrong value. ```raz Nilp fail module Nilp; diff --git a/site/public/_redirects b/site/public/_redirects index e6129a0..9ecc9fa 100644 --- a/site/public/_redirects +++ b/site/public/_redirects @@ -1 +1 @@ -/download/latest /download/raz-0.10.1-linux-x86_64.tar.gz 302 +/download/latest /download/raz-0.11.0-linux-x86_64.tar.gz 302 diff --git a/site/public/advanced/atomics.html b/site/public/advanced/atomics.html index 78ad1fa..179ccf6 100644 --- a/site/public/advanced/atomics.html +++ b/site/public/advanced/atomics.html @@ -45,7 +45,7 @@
  • A ring buffer between threads
  • Shared memory · lesson 15 of 18

    Atomics

    A volatile access is one access. An atomic is one *indivisible* step: nothing can happen between its read and its write, so two threads using it can't lose each other's work. There are three, built into the language as procedures, and they are sequentially consistent on every target:

    -

    | Call | Does | |---|---| | XADD(p, x) | adds x to p^ and returns the value before | | XCHG(p, x) | sets p^ := x and returns the value before | | CAS(p, old, new) | if p^ = old, sets p^ := new and returns true; otherwise false |

    +
    CallDoes
    XADD(p, x)adds x to p^ and returns the value before
    XCHG(p, x)sets p^ := x and returns the value before
    CAS(p, old, new)if p^ = old, sets p^ := new and returns true; otherwise false

    p is a ^T or ^VOLATILE T where T is INT, UINT or a pointer type (INT or UINT for XADD). They compile to single x86-64 instructions: lock xadd, xchg (which is always locked when it touches memory) and lock cmpxchg:

    Ops.raz
    module Ops;
     
    diff --git a/site/public/advanced/lifecycle.html b/site/public/advanced/lifecycle.html
    index f761694..f92a4d4 100644
    --- a/site/public/advanced/lifecycle.html
    +++ b/site/public/advanced/lifecycle.html
    @@ -134,7 +134,7 @@
     status 3

    Neither the deferred statement nor bye ran. That's the rule, and the reason to keep cleanup that matters (a terminal, a lock file) in atExit and use Rt.exit for ending.

    Signals

    -

    A program is stopped by a signal it doesn't catch, with a message that names the place for SIGSEGV and SIGFPE, and without one for the others. A program that wants to handle one, say SIGTERM for a clean shutdown, doesn't write a handler that runs at an arbitrary moment. It asks for the signals to arrive as data: Sys.catch takes a list of signals and gives a descriptor that is ready to read when one comes, and Sys.caught says which. So the program waits for signals the way it waits for input.

    +

    A program is stopped by a signal it doesn't catch, with a message that names the place for SIGSEGV and SIGFPE, and without one for the others, and ends with status 2. A program that wants to handle one, say SIGTERM for a clean shutdown, doesn't write a handler that runs at an arbitrary moment. It asks for the signals to arrive as data: Sys.catch takes a list of signals and gives a descriptor that is ready to read when one comes, and Sys.caught says which. So the program waits for signals the way it waits for input.

    Terms.raz
    module Terms;
     import Out, Sys;
     
    diff --git a/site/public/advanced/listing.html b/site/public/advanced/listing.html
    index ca7f6da..f58c4fc 100644
    --- a/site/public/advanced/listing.html
    +++ b/site/public/advanced/listing.html
    @@ -246,18 +246,18 @@
     
    • gdb finds procedures by name and lines by number, since the executable carries them: break Dot.dot and list work, and so does stepping a line at a time.
    • RAZ_PROFILE=1 samples the program every millisecond and says which procedures and lines took the time.
    • objdump -d disassembles what is really in the file, if you want to see the bytes behind a listing.
    $ raz -o Dot Dot.raz
     $ objdump -d -M intel --no-show-raw-insn Dot | sed -n '/<Dot.dot>:/,/ret/p' | head -12
    -0000000000403b40 <Dot.dot>:
    -  403b40:	push   rbp
    -  403b41:	mov    rbp,rsp
    -  403b44:	sub    rsp,0x40
    -  403b4b:	mov    QWORD PTR [rbp-0x30],rbx
    -  403b4f:	xor    ebx,ebx
    -  403b51:	mov    QWORD PTR [rbp-0x28],r12
    -  403b55:	xor    r12d,r12d
    -  403b58:	mov    QWORD PTR [rbp-0x20],rdx
    -  403b5c:	mov    QWORD PTR [rbp-0x18],rcx
    -  403b60:	xor    ebx,ebx
    -  403b62:	mov    r8,rsi
    +0000000000403aa0 <Dot.dot>: + 403aa0: push rbp + 403aa1: mov rbp,rsp + 403aa4: sub rsp,0x40 + 403aab: mov QWORD PTR [rbp-0x30],rbx + 403aaf: xor ebx,ebx + 403ab1: mov QWORD PTR [rbp-0x28],r12 + 403ab5: xor r12d,r12d + 403ab8: mov QWORD PTR [rbp-0x20],rdx + 403abc: mov QWORD PTR [rbp-0x18],rcx + 403ac0: xor ebx,ebx + 403ac2: mov r8,rsi

    The listing is what the encoder meant; objdump is what the processor will read. They tell the same story.

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

    diff --git a/site/public/advanced/static.html b/site/public/advanced/static.html index 1998974..17e52db 100644 --- a/site/public/advanced/static.html +++ b/site/public/advanced/static.html @@ -65,7 +65,7 @@ $ ldd Bare not a dynamic executable $ ls -l Bare | awk '{print $5, "bytes"}' -26288 bytes +26096 bytes

    It is statically linked: no interpreter, no shared libraries, no libc. ldd says so.

    What it does when it runs

    strace lists every system call a program makes. This is the whole of it:

    @@ -134,15 +134,15 @@
    $ raz Lean.raz
     $ raz Heavy.raz
     $ ls -l Lean Heavy | awk '{print $9, $5}'
    -Heavy 28496
    -Lean 28488
    +Heavy 28304 +Lean 28296

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

    Stripping

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

    $ raz -s -o Lean-stripped Lean.raz
     $ ls -l Lean Lean-stripped | awk '{print $9, $5}'
    -Lean 28488
    -Lean-stripped 6880
    +Lean 28296
    +Lean-stripped 6720
     $ ./Lean-stripped
     same program

    raz -S Lean.raz is the other direction: it prints the machine code the compiler made, one source line at a time. The next two parts of the tour use it.

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

    ← Writing an allocatorContents
    diff --git a/site/public/download/raz-0.11.0-linux-x86_64.tar.gz b/site/public/download/raz-0.11.0-linux-x86_64.tar.gz new file mode 100644 index 0000000..654721c Binary files /dev/null and b/site/public/download/raz-0.11.0-linux-x86_64.tar.gz differ diff --git a/site/public/download/raz-0.11.0-linux-x86_64.tar.gz.sha256 b/site/public/download/raz-0.11.0-linux-x86_64.tar.gz.sha256 new file mode 100644 index 0000000..bdd3e0d --- /dev/null +++ b/site/public/download/raz-0.11.0-linux-x86_64.tar.gz.sha256 @@ -0,0 +1 @@ +21efde9a00f589ff456a44dafb9f49a124e87d22f557965050480ce300c09c97 raz-0.11.0-linux-x86_64.tar.gz diff --git a/site/public/index.html b/site/public/index.html index c9c62ea..3140675 100644 --- a/site/public/index.html +++ b/site/public/index.html @@ -43,7 +43,7 @@ ~10,700 lines of compiler ~650K lines compiled a second static executables, no run time to install - 1 report, about 30 pages + 2 volumes: the language and the library
    @@ -105,28 +105,28 @@ volatile accesses, atomics and lock-free code, in 18 more.

    The language, in writing

    -

    The language is defined by the report, which is +

    The language is defined by the report, in two volumes (the language, then the library), which is short on purpose: whatever it doesn’t allow, raz doesn’t have.

    Download

    -

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

    raz 0.11.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.10.1-linux-x86_64.tar.gz
    -$ ln -s $PWD/raz-0.10.1-linux-x86_64/raz ~/.local/bin/raz
    +
    $ tar xzf raz-0.11.0-linux-x86_64.tar.gz
    +$ ln -s $PWD/raz-0.11.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.10.1-linux-x86_64.tar.gz to this one, for -good. Earlier releases: 0.9.1, 0.9.0, 0.8.0, 0.7.1; each has its SHA-256 beside it, with +and download/raz-0.11.0-linux-x86_64.tar.gz to this one, for +good. Earlier releases: 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 d844589a05ba97f25413cbf5befe8f60f33857ecdbc12e049c18fe703ab23097

    +

    SHA-256 21efde9a00f589ff456a44dafb9f49a124e87d22f557965050480ce300c09c97

    raz is under the ISC license.
    diff --git a/site/public/spec.html b/site/public/spec.html index 357d946..49028f7 100644 --- a/site/public/spec.html +++ b/site/public/spec.html @@ -29,14 +29,15 @@
  • 8. Procedures
  • 9. Calling C
  • 10. Programs
  • -
  • 11. The library
  • -
  • 12. Versions
  • +
  • 11. Versions
  • Appendix A. What an implementation chooses
  • Appendix B. The grammar
  • +
  • The library, volume 2
  • 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.21 of the report; section 12 says what each version changed. 2026-10.11 and 2026-10.12 are a thaw the owner chose, for a language anyone can build again. They break programs written for 2026-10.10 and before: for 2026-10.9, say, the report of compiler 0.5.0, the last release before them; and 2026-10.12 breaks code procedures written for 2026-10.11. 2026-10.20 is a third, for try (section 7.8); it breaks a program that has a name try.

    +

    This is version 2026-10.22 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.

    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;
    @@ -50,20 +51,20 @@
     end Hello.

    A program is a set of modules. The one named on the command line is the main module, and it exports a procedure main; the program starts there, once every module’s body has run (section 3). Saved as Hello.raz, it is compiled with raz Hello.raz, which writes the executable Hello.

    2. Words and symbols

    -

    A program is written in UTF-8. The compiler rejects a file that isn’t valid UTF-8: a malformed or overlong sequence, a surrogate, or a code point beyond 10FFFFH. Everything outside strings, characters and comments is ASCII. Spaces, tabs and line breaks separate symbols and are otherwise ignored.

    +

    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
    -

    static, in link static; (section 3), isn’t one.

    +

    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.

    +

    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.

    An integer is an untyped constant, which takes the type it is used as, up to the largest I64. A hexadecimal number above that, such as 0FFFFFFFFFFFFFFFFH, has type U64: so -1 never fits a U64, and the big number goes nowhere else without a conversion. Arithmetic on untyped constants doesn’t wrap: a result beyond the I64s, such as 9223372036854775807 + 1, is an error.

    -

    A real is an untyped constant too, which takes F32 or F64, whichever it is used as, rounded to the nearest value of that type; where nothing says which, it is an F64. A real never becomes an integer, nor an integer a real, without a conversion: x := 1; is an error for x: F64, and x := 1.0; is right.

    +

    A real is an untyped constant too. It is read as the nearest F64 (a tie goes to the even one), and takes F32 or F64, whichever it is used as: an F32 is the nearest to that F64. Where nothing says which, it is an F64. A real never becomes an integer, nor an integer a real, without a conversion: x := 1; is an error for x: F64, and x := 1.0; is right.

    Characters. 'a' is the code point of one character, an integer: 'a' is 97 and 'é' is 233.

    -

    Strings. "héllo\n" is a sequence of bytes, the UTF-8 of its text: "é" is the two bytes 0C3H, 0A9H. Both characters and strings take the escapes \n (line feed), \t (tab), \r (carriage return), \0 (zero), \\, \', \", \u{H...} (the code point with hexadecimal value H…, in a string its UTF-8) and, in strings only, \xHH (the byte with hexadecimal value HH, which needn’t make valid UTF-8). In an escape, the hexadecimal digits may be capitals or not. A character or a string ends on the line it starts on.

    +

    Strings. "héllo\n" is a sequence of bytes, the UTF-8 of its text: "é" is the two bytes 0C3H, 0A9H. Both characters and strings take the escapes \n (line feed), \t (tab), \r (carriage return), \0 (zero), \\, \', \", \u{H...} (the code point with hexadecimal value H…, up to 10FFFFH, in a string its UTF-8) and, in strings only, \xHH (the byte with hexadecimal value HH, which needn’t make valid UTF-8). In an escape, the hexadecimal digits may be capitals or not. A character or a string ends on the line it starts on.

    Messages give the line and the column, counted in characters (section 10).

    Comments are (* … *) and nest. By convention, the comment just before an exported declaration is its documentation, and the one before module is the module’s.

    Operators and delimiters:

    @@ -100,7 +101,7 @@

    A procedure argument names a procedure, not a variable or an expression, and its signature, with the type arguments put in, must be the parameter’s. Inside the module, hash(k) calls it directly. Two imports make the same instance only if their types and their procedures are the same.

    Finding modules. The compiler looks for module Name in the main module’s directory, then in each directory given with -I, then in the lib directory beside the compiler. In each directory it takes the first of Name.OS-ARCH.raz, Name.OS.raz, Name.ARCH.raz and Name.raz that exists, where OS-ARCH is the target, for now only linux-x86_64. So a module whose code depends on the machine or the system comes in one file per target, and the modules that import it don’t change. Machine code (section 8) and system calls belong in such files.

    One module to a name. A program has one module of each name, so the compiler reports an error, naming the files, if a module it looks for has files in more than one of these directories, rather than take the first: a Buf.raz beside a program would otherwise stand in for the library’s Buf in every module that imports it, the library’s own among them. A link is the exception: a file that is a symbolic link to one of the module’s files in a later directory chooses that file, so that a directory holding a link to lib/Sys.raz builds a program over the C library’s Sys on Linux too.

    -

    Names are flat. The names of a program’s modules are one space, with no packages or paths. So the names of the library’s modules (section 11) are kept for it: a program or another library doesn’t name a module of its own Arena, Buf, C, Files, Fmt, Heap, List, Lock, Map, Math, Mem, Opt, Out, Rt, Sort, Str, Sys or Thread, nor any name the library takes later. The modules of any other library share a prefix of their own, as an X11 library’s Xauth and Xkeys do, and a program that wants a shorter name imports one: import Auth := Xauth;.

    +

    Names are flat. The names of a program’s modules are one space, with no packages or paths. So the names of the library’s modules (the library, doc/raz-lib.md) are kept for it: a program or another library doesn’t name a module of its own Arena, Buf, C, Files, Fmt, Heap, List, Lock, Map, Math, Mem, Opt, Out, Rt, Sort, Str, Sys or Thread, nor any name the library takes later. The modules of any other library share a prefix of their own, as an X11 library’s Xauth and Xkeys do, and a program that wants a shorter name imports one: import Auth := Xauth;.

    The compiler holds every file of such a module to the same interface. When it takes one of Name.*.raz, it also reads the declarations of the others beside it, and of Name.raz if there is one, and reports an error unless they all export the same names, each the same kind of thing:

    • a constant of the same type (its value may differ: a system call number, say);
    • @@ -111,7 +112,7 @@

      Two types here are the same if they are built alike, a name in one file standing for the same name in another.

      Module bodies. A module may end with begin and statements, its body. Every module’s body runs once, before the main module’s main: a module’s body runs after the bodies of the modules it imports, in the order of its imports, and once however many modules import it. Each instance of a generic module has its body run once. Module variables are zero before any body runs. return; ends a body early.

      link "libX11.so.6"; names a shared library to load at run time, for the extern declarations of section 9. link static; says the module needs a program without C (section 10): it makes its own system calls, or its own threads, which the C library wouldn’t know about.

      -

      check off;, after the links, leaves out of the module’s own code the checks of indexes and slice bounds of section 6.5, and that a slice of a pointer doesn’t run backwards (section 6.4), for speed where the program is sure of them. An index out of range there reads or writes whatever memory it reaches, and what follows isn’t defined. Every other check stays, and the module’s callers keep theirs. An instance of a generic module follows the generic module’s own check line, not that of the module that made it. check and off aren’t reserved words, as static isn’t.

      +

      check off;, after the links, leaves out of the module’s own code the checks of indexes and slice bounds of section 6.5, and that a slice of a pointer doesn’t run backwards (section 6.4), for speed where the program is sure of them. An index out of range there reads or writes whatever memory it reaches, and what follows isn’t defined. Every other check stays, and the module’s callers keep theirs. An instance of a generic module follows the generic module’s own check line, not that of the module that made it.

      4. Declarations

      Declaration = "const" { IdentDef [ ":" Type ] "=" Expr ";" }
                   | "type" { IdentDef "=" Type ";" }
      @@ -210,7 +211,7 @@
       
      type Cell = record ch: U8; attr: U8; end;

      Fields are laid out in order as C lays them out: each at the next multiple of its own alignment, and the whole record padded to a multiple of its largest alignment. A record declared like a C struct has the same layout as that struct. A record may have no fields; its size is then 0.

      A packed record has no padding: each field starts at the byte after the field before it, and the record’s alignment is 1. So a field of a packed record may sit at any address. It is read and written like any other, on every target, even one whose machine can’t reach a misaligned word in one access: the compiled code reaches it in parts there. But a field of a packed record whose type is aligned to more than 1 byte, and anything inside it, has no address: ADR of it, a var parameter of it and a slice of it are errors. Nor can it be reached through a ^VOLATILE pointer, since a misaligned access can’t be promised as one access (section 7.6). Its value can be copied out and back in.

      -

      The bytes of a value of more than one byte are in the target’s order (appendix A). A file or a message in an order of its own is read and written a byte at a time, as Str.le, Str.be, Str.putLE and Str.putBE do (section 11).

      +

      The bytes of a value of more than one byte are in the target’s order (appendix A). A file or a message in an order of its own is read and written a byte at a time, as Str.le, Str.be, Str.putLE and Str.putBE do (the library, doc/raz-lib.md).

      5.6 Variants

      A variant holds one of several cases, each with its own fields:

      type
      @@ -253,7 +254,7 @@
       
    • A is INT and B is I64, or A is UINT and B is U64, which loses nothing on any target.

    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). Results passed on whole need the same types exactly: in a, b := f(x) and in return f(x), an INT result doesn’t pass up as an I64. Elsewhere, return n, n included, an INT widens as above.

    +

    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). Results passed on whole need the same types exactly: in a, b := f(x) and in return f(x), an INT result doesn’t pass up as an I64. Elsewhere, return n, n included, an INT widens as above; the bounds of a for and the step of INC and DEC take the type of the variable they work on, and an INT is not widened to it.

    6. Expressions

    Expr       = Conjunct { "or" Conjunct } .
     Conjunct   = Relation { "and" Relation } .
    @@ -280,8 +281,8 @@
     

    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. So do v and k in INC(v, k) and DEC(v, k). 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. Two integer types are never mixed, whatever their sizes: with i: I64, i < LEN(s) is an error, and i should be an INT.

    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 (SIGFPE), whatever the type and the target.

    -

    & (and), | (or), xor and ~ (not) work on every bit. x shl n and x shr n shift by n modulo the width of x’s type, in bits: for x: U8, x shl 9 is x shl 1. shr brings in copies of the sign bit for signed types and zeros for unsigned ones. n may be of any integer type. The result has x’s type, cut to its width: in U8, 0C0H shl 1 is 80H.

    +

    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.

    +

    & (and), | (or), xor and ~ (not) work on every bit. x shl n and x shr n shift by n modulo the width of x’s type, in bits: for x: U8, x shl 9 is x shl 1. shr brings in copies of the sign bit for signed types and zeros for unsigned ones. n may be of any integer type. The result has x’s type, cut to its width: in U8, 0C0H shl 1 is 80H. If x is an untyped constant, so is the result, and it doesn’t wrap: 1 shl 9 is 512, which doesn’t fit a U8.

    Relations compare as signed or unsigned according to the type.

    6.2 Booleans

    and and or evaluate their right operand only when it decides the result. not negates, and = and # compare; # is “different”.

    @@ -350,7 +351,7 @@ integer enumeration -the name at that position; a position out of range is a failed check (6.5) +the name at that position; a position out of range is a failed check (6.5), and in a constant an error set @@ -379,7 +380,7 @@ -

    There are no others: no conversion between BOOL and integers, none between pointers and integers other than INT and UINT, and none to or from records, arrays, slices, variants or ERROR. A conversion of a constant is made by the compiler, by the same rules: U8(300) is 44.

    +

    There are no others: no conversion between BOOL and integers, none between pointers and integers other than INT and UINT, and none to or from records, arrays, slices, variants or ERROR. An untyped integer constant converts to a pointer as an INT does, as in ^VOLATILE U32(0FEE00000H); it isn’t assigned to a pointer without the conversion. A conversion of a constant is made by the compiler, by the same rules: U8(300) is 44.

    6.8 Built-in procedures

    @@ -452,7 +453,7 @@

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

    -

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

    +

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

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

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

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

    @@ -479,7 +480,7 @@

    7.1 Assignment and calls

    x := e evaluates e and stores it in x; arrays, records, slices and variants are copied. A designator on its own is a call, and any result it returns is dropped: Out.ln;, write(fd, buf);.

    a, b := f(x); assigns the results of a procedure that returns several (section 8), in order.

    -

    The blank, _, drops what would be assigned to it: _ := e; evaluates e and drops it, and n, _ := f(x); keeps the first result and drops the second. What is dropped is still evaluated as any expression is: its calls are made, and a volatile variable in it is read (section 7.6). A result dropped by a call standing on its own is warned of (section 10); one dropped through _ isn’t.

    +

    The blank, _, drops what would be assigned to it: _ := e; evaluates e and drops it, and n, _ := f(x); keeps the first result and drops the second. What is dropped is still evaluated as any expression is: its calls are made, and a volatile variable in it is read (section 7.6). A result dropped by a call standing on its own is a lint an implementation may warn of (section 10); one dropped through _ says it is meant.

    7.2 Conditions and loops

    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, as with + (section 6.1): so in for i := 0 to LEN(s) - 1, i must be an INT.

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

    match runs the arm of the case s holds. An arm may name the case’s fields, in order, all of them; the names stand for those fields of s itself, so assigning to one changes s; if s isn’t a variable, they stand for the fields of a copy. An arm may also leave the fields unnamed. Every case must have an arm, and only one, unless there is an | else: arm, which must come last.

    +

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

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

    match op of
     | sPlus, sMinus: kind := additive;
    @@ -507,12 +508,12 @@
     | '0' .. '9':     digit := true;
     | else:
     end;
    -

    A label is a constant, or lo .. hi, the constants from lo to hi, both included (unlike a slice, which leaves hi out). Each must fit the integer’s type, and no value may be in two labels. An integer match must have an | else: arm, which may be empty. Whether an arm names a case or gives labels is set by the type matched: | Max: is a case of a variant or an enumeration, and a constant for an integer.

    +

    A label is a constant, or lo .. hi, the constants from lo to hi, both included (unlike a slice, which leaves hi out; lo may not be above hi). Each must fit the integer’s type, and no value may be in two labels. An integer match must have an | else: arm, which may be empty. Whether an arm names a case or gives labels is set by the type matched: | Max: is a case of a variant or an enumeration, and a constant for an integer.

    7.5 Order of evaluation

    Operands, arguments and the designators of an assignment are evaluated from left to right, and the designators of an assignment before its right side: a[i()] := g() calls i and then g.

    7.6 Volatile

    A variable reached through a ^VOLATILE T is volatile, and so is any field or element of it. Each read or write of a volatile variable of a basic, enumeration, set or pointer type is exactly one memory access, of exactly its size, and volatile accesses happen in the order the program writes them. Copying a whole record or array through a volatile pointer is not allowed, since it can’t be one access.

    -

    A ^VOLATILE T doesn’t convert to ^T without a written conversion.

    +

    A ^VOLATILE T doesn’t convert to ^T without a written conversion, and a volatile variable isn’t passed as a var argument, which would lose its volatility.

    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

    @@ -543,7 +544,7 @@ end; end Head.
    -

    return e; evaluates e before the deferred statements run. A deferred statement can’t contain return, break, defer 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 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);
    @@ -567,7 +568,7 @@
     
  • With one, it is a value of that type, an operand wherever c would be: n := try number(s);, sum + try number(s), if try ready(fd) then. Like not, it applies to the factor after it: try f(x) + 1 is (try f(x)) + 1.
  • With several, it stands only on the right of a multiple assignment, as c itself would, with a target for each: a, b := try f(x);.
  • -

    As a statement, try c; drops the values of c that it has, and a dropped value is warned of as a call that drops a result is (section 10); _ := try c; and a, _ := try c; say it is meant (section 7.1). The error is never dropped: try is the way of passing it on.

    +

    As a statement, try c; drops the values of c that it has, and a dropped value is a lint, as a call that drops a result is (section 10); _ := try c; and a, _ := try c; say it is meant (section 7.1). The error is never dropped: try is the way of passing it on.

    Where try may stand. Every use of try is an error unless:

    • the procedure it stands in has an ERROR as its last result. A module’s body, and a procedure with no results, such as proc main*;, have none: there an error is dealt with where it is found, by a test;
    • @@ -607,7 +608,7 @@ end; end Divide.
    -

    forward. proc f(x: I64): I64; forward; declares f so that it can be called before its body appears; the body comes later with the same signature, though its parameters may have other names.

    +

    forward. proc f(x: I64): I64; forward; declares f so that it can be called before its body appears; the body comes later in the module, with the same signature, though its parameters may have other names; a forward with no body is an error.

    A name after a procedure’s end, if written, is the procedure’s own.

    Procedures don’t nest.

    Code procedures. A procedure whose body is code is machine code, written by hand in the target’s assembly language (appendix A): one instruction to each ;, and labels for jumps, up to end:

    @@ -641,17 +642,131 @@

    Every raz procedure uses the System V calling convention, so a raz procedure whose parameters and result are of those types can be given to C as a callback.

    10. Programs

    Any module may export a procedure main, declared proc main*; or proc main*: INT;. The program runs the bodies of all its modules (section 3), then the main module’s main, if it has one, and ends with status 0, or with the status main returns, by calling Rt.exit. The main of an imported module is an ordinary procedure, which runs only if something calls it; so a library module can carry a main that tests it. A program uses C if any of its modules has an extern declaration or a link of a library; a module’s other files, read only to check its interface (section 3), don’t count. A program that doesn’t is a static executable with no run time besides the code it uses. One that does is linked dynamically and starts through the C library, so that C’s own set-up and clean-up run. A program with a module that says link static; must not use C, and the compiler reports an error if it does.

    -

    Ending. Rt.exit(status) ends the program. First it runs the procedures registered with Rt.atExit, the last registered first, each at most once; then it ends the program with status, through C’s exit in a program that uses C, so that C flushes its own buffers. A failed check (section 6.5) runs them too, after its message, so that Out’s buffer is written out. Sys.exit ends the program at once, and a program stopped by a signal runs none of them.

    +

    Ending. Rt.exit(status) ends the program. First it runs the procedures registered with Rt.atExit, the last registered first, each at most once; then it ends the program with status, through C’s exit in a program that uses C, so that C flushes its own buffers. A program that stops (below), a failed check (section 6.5) included, runs them too, after its message, so that Out’s buffer is written out, and ends with status 2. Sys.exit ends the program at once, and a program killed by a signal from outside runs none of them.

    proc atExit*(p: proc): ERROR;   (* Rt.Full if 32 are registered *)
     proc exit*(status: INT);
     proc trace*;                    (* the calls under way, on standard error *)

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

    -

    Only what can be reached from main and the module bodies goes into the executable: unused procedures, variables and strings are left out. The executable names its procedures and carries line numbers, so that gdb can stop at a line of the source and show where it is.

    -

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

    -

    Separate compilation. An importer depends only on a module’s interface: what it exports, as an importer sees it, never its source or its code. So a module can be compiled on its own, and a program made from modules compiled at different times. Whether an implementation does so, and into what, is its own choice (appendix A); one that does makes the same program as if every module were compiled together, and keeps one copy of each instance.

    -

    Messages. The compiler reports an error with its file, line and column, the line of source with the offending part underlined, and, where they help, notes pointing at other places, such as where a name is declared, and a suggestion, such as a name in reach spelled almost alike. It goes on after an error to find the others, up to 20, and writes no executable. After an error it skips the statement or declaration the error is in and carries on with the next; a name that isn’t declared is reported once, and nothing that follows from it is reported. An error in the text itself, such as a string left open, stops the compile, and so does a module with errors, after it.

    -

    The compiler also warns of what is declared and never used: an import; a constant, type, variable or procedure that isn’t exported; a parameter of a procedure written in raz. It warns of a variable that is assigned but never read, too, and of a call standing on its own that drops a result, as Sys.write(fd, s); does: _ := Sys.write(fd, s); says it is meant. A name that starts with _ is never warned about. Warnings don’t stop the compile; raz -Werror makes them errors.

    -

    11. The library

    +

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

    +

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

    +

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

    +

    11. Versions

    +

    A version of this report is named by the month it was made in and a count: 2026-10.0, then 2026-10.1 for the next change that month. raz --version says which version the compiler follows.

    +

    The history of the versions, what each changed, is in doc/report-history.md.

    +

    Appendix A. What an implementation chooses

    +

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

    + +

    The 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, 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.

    +

    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 } .
    +letter     = "A" .. "Z" | "a" .. "z" | "_" .
    +digit      = "0" .. "9" .
    +hexDigit   = digit | "A" .. "F" .
    +number     = digit { digit }
    +           | digit { hexDigit } "H"
    +           | digit { digit } "." digit { digit } [ "E" [ "+" | "-" ] digit { digit } ] .
    +char       = "'" ( character | escape ) "'" .
    +string     = '"' { character | escape | "\x" anyHex anyHex } '"' .
    +escape     = "\n" | "\t" | "\r" | "\0" | "\\" | "\'" | '\"'
    +           | "\u{" anyHex { anyHex } "}" .
    +anyHex     = hexDigit | "a" .. "f" .
    +
    +Module     = "module" ident [ "(" ModParams ")" ] ";"
    +             { Import } { Link } [ Check ] { Declaration }
    +             [ "begin" Statements ] "end" ident "." .
    +ModParams  = ident { "," ident } { ";" ident ":" "proc" Signature } .
    +Import     = "import" ImportItem { "," ImportItem } ";" .
    +ImportItem = ident [ ":=" ident [ "(" Type { "," Type } ")" ] ] .
    +Link       = "link" ( string | "static" ) ";" .
    +Check      = "check" "off" ";" .
    +
    +Declaration = "const" { IdentDef [ ":" Type ] "=" Expr ";" }
    +            | "type" { IdentDef "=" Type ";" }
    +            | "var" { IdentList ":" Type ";" }
    +            | ProcDeclaration ";"
    +            | ExternDeclaration ";" .
    +IdentDef    = ident [ "*" ] .
    +IdentList   = IdentDef { "," IdentDef } .
    +
    +Type      = QualIdent
    +          | "[" Expr "]" Type
    +          | "[" "]" Type
    +          | "^" [ "VOLATILE" ] Type
    +          | [ "packed" ] "record" { IdentList ":" Type ";" } "end"
    +          | "variant" { Case ";" } "end"
    +          | "(" ident { "," ident } ")"
    +          | "set" "of" QualIdent
    +          | "proc" Signature .
    +Case      = ident [ "(" FieldList { ";" FieldList } ")" ] .
    +FieldList = ident { "," ident } ":" Type .
    +QualIdent = [ ident "." ] ident .
    +
    +Expr       = Conjunct { "or" Conjunct } .
    +Conjunct   = Relation { "and" Relation } .
    +Relation   = SimpleExpr [ RelOp SimpleExpr ] .
    +RelOp      = "=" | "#" | "<" | "<=" | ">" | ">=" | "in" .
    +SimpleExpr = [ "-" ] Term { AddOp Term } .
    +AddOp      = "+" | "-" | "|" | "xor" .
    +Term       = Factor { MulOp Factor } .
    +MulOp      = "*" | "/" | "div" | "mod" | "&" | "shl" | "shr" .
    +Factor     = number | char | string | Designator | "(" Expr ")"
    +           | "not" Factor | "~" Factor
    +           | "[" [ Expr { "," Expr } ] "]"
    +           | "{" [ Element { "," Element } ] "}"
    +           | "^" [ "VOLATILE" ] Type "(" Expr ")"
    +           | "try" Designator .
    +Element    = Expr | ident ":" Expr .
    +Designator = QualIdent { Selector } .
    +Selector   = "." ident | "^" | "[" Expr [ ".." Expr ] "]"
    +           | "(" [ Expr { "," Expr } ] ")" .
    +
    +Statements = { Statement ";" } .
    +Statement  = Designator [ ":=" Expr ]
    +           | "_" ":=" Expr
    +           | Target "," Target { "," Target } ":=" Expr
    +           | "if" Expr "then" Statements
    +             { "elsif" Expr "then" Statements } [ "else" Statements ] "end"
    +           | "while" Expr "do" Statements "end"
    +           | "repeat" Statements "until" Expr
    +           | "for" ident ":=" Expr "to" Expr [ "by" Expr ] "do" Statements "end"
    +           | "match" Expr "of" { "|" Arm } "end"
    +           | "return" [ Expr { "," Expr } ]
    +           | "break"
    +           | "defer" Statement
    +           | "try" Designator .
    +Arm        = ( ident [ "(" ident { "," ident } ")" ]
    +             | Label { "," Label } | "else" ) ":" Statements .
    +Label      = Expr [ ".." Expr ] .
    +Target     = Designator | "_" .
    +
    +ProcDeclaration   = "proc" IdentDef Signature ";"
    +                    ( "forward" | { LocalDeclaration } "begin" Statements "end" [ ident ]
    +                    | "code" { [ ident ":" ] [ Instruction ] ";" } "end" [ ident ] ) .
    +LocalDeclaration  = "const" { ident [ ":" Type ] "=" Expr ";" }
    +                  | "type" { ident "=" Type ";" }
    +                  | "var" { ident { "," ident } ":" Type ";" } .
    +Signature         = "(" [ Params { ";" Params } [ ";" "..." ] ] ")" [ ":" Results ]
    +                  | [ ":" Results ] .
    +Params            = [ "var" ] ident { "," ident } ":" Type .
    +Results           = Type | "(" Type { "," Type } ")" .
    +ExternDeclaration = "extern" ( "proc" IdentDef Signature
    +                             | "var" IdentDef ":" Type ) .
    +

    character is any character but a line break, and in a string any but " and \, in a character any but ' and \. A procedure argument of a generic module (section 3) is written as a QualIdent, which is a Type here. ... comes last in a Signature, and only in an extern. An Instruction is written in the target’s assembly language (appendix A).

    +

    The library, volume 2

    +

    The second volume of the report on raz. The first, doc/raz.md, defines the language; this one defines the modules that come with it, and refers to the first’s sections by number, as “section 6.8”. Only the core binds every implementation (appendix A of the first volume); the rest is the standard library.

    Modules written in raz, in the compiler’s lib directory:

    @@ -771,7 +886,7 @@ proc init*(ar: ^Arena; size: INT): BOOL; (* an arena of size bytes; false if the system has none *) proc reset*(ar: ^Arena); (* every allocation forgotten; the memory used again *) proc done*(ar: ^Arena); (* its memory given back *) -

    NEW(p, a) calls a^.alloc. Heap keeps blocks of nine sizes, from 16 to 4096 bytes with their header, each with a list of the free ones; a bigger block gets pages of its own. An arena hands out memory from one block: its free does nothing, and reset forgets everything.

    +

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

    module Lock;
     type Lock* = record ... end;
     proc take*(l: ^Lock);
    @@ -910,7 +1025,7 @@
     proc accept*(fd: INT): INT;        (* the next connection, waiting for one *)
     proc send*(fd: INT; s: []U8): INT; (* write, to a socket: -32 (EPIPE), not a signal, if it is closed *)

    info follows a symbolic link: size, dir and file are those of what it names, and symlink says the path was a link, so that a program walking a tree can choose not to follow one back up it. A link to nothing is -ENOENT, as a missing file is. file lets a walk open only what holds data: opening a pipe would wait for a program to write to it.

    -

    nextEntry gives every name in the directory except . and .., in no particular order. rawMode turns off what the terminal does with keys before the program reads them: echo, waiting for a whole line, Ctrl-C and Ctrl-Z as signals, Ctrl-S and Ctrl-Q as flow control, and CR to NL; and with output, NL to CR NL. A program that turns it on restores it before it ends: Rt.atExit is the place.

    +

    nextEntry gives every name in the directory except . and .., in no particular order. rawMode turns off what the terminal does with keys before the program reads them (echo, line editing, signals, flow control), and NL to CR NL on output. A program that turns it on restores it before it ends: Rt.atExit is the place.

    Files. open gives a file for what how asks: reading, writing or both; creating it if it is missing, readable by all and writable by its owner; with exclusive, failing with -17 (EEXIST) if it is there, as a program does that makes a lock or a file of its own; truncating it to nothing; appending, each write going to its end, however other programs write it too. seek moves to pos from the start of the file, or from its end if fromEnd, where a negative pos reads back from the end. Info.mtime is what a program checks to see whether a file changed under it; Info.mode holds the nine bits of rwxrwxrwx, and chmod sets them, 1EDH (755) for a program, 1A4H (644) for data.

    Programs. openPty makes a pseudo-terminal, a terminal that a program, a terminal emulator, plays the screen and the keyboard of: what it writes to the fd is typed, and what the programs on the terminal write it reads.

    spawn starts the program at p.path, with p.args as its arguments, the first being its name. Its environment is this program’s with each NAME=value of p.env added or put in place of the old value, or, if p.onlyEnv, p.env alone. It starts in p.dir. Its standard input, output and error are p.fds; a 0 gives it this program’s own, so {path: "/bin/ls", args: ["ls"]} runs ls as a shell runs it, with every other field zero. It gets no other open file, every signal does what it does at first, and none is blocked. If p.tty is a pseudo-terminal’s fd, the program starts a session on that terminal: it is its controlling terminal, and its standard input, output and error, and p.fds and p.group are not used.

    @@ -1078,144 +1193,6 @@ 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.

    -

    12. Versions

    -

    A version of this report is named by the month it was made in and a count: 2026-10.0, then 2026-10.1 for the next change that month. raz --version says which version the compiler follows.

    - -

    Appendix A. What an implementation chooses

    -

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

    - -

    The 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.

    -

    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 } .
    -letter     = "A" .. "Z" | "a" .. "z" | "_" .
    -digit      = "0" .. "9" .
    -hexDigit   = digit | "A" .. "F" .
    -number     = digit { digit }
    -           | digit { hexDigit } "H"
    -           | digit { digit } "." digit { digit } [ "E" [ "+" | "-" ] digit { digit } ] .
    -char       = "'" ( character | escape ) "'" .
    -string     = '"' { character | escape | "\x" anyHex anyHex } '"' .
    -escape     = "\n" | "\t" | "\r" | "\0" | "\\" | "\'" | '\"'
    -           | "\u{" anyHex { anyHex } "}" .
    -anyHex     = hexDigit | "a" .. "f" .
    -
    -Module     = "module" ident [ "(" ModParams ")" ] ";"
    -             { Import } { Link } [ Check ] { Declaration }
    -             [ "begin" Statements ] "end" ident "." .
    -ModParams  = ident { "," ident } { ";" ident ":" "proc" Signature } .
    -Import     = "import" ImportItem { "," ImportItem } ";" .
    -ImportItem = ident [ ":=" ident [ "(" Type { "," Type } ")" ] ] .
    -Link       = "link" ( string | "static" ) ";" .
    -Check      = "check" "off" ";" .
    -
    -Declaration = "const" { IdentDef [ ":" Type ] "=" Expr ";" }
    -            | "type" { IdentDef "=" Type ";" }
    -            | "var" { IdentList ":" Type ";" }
    -            | ProcDeclaration ";"
    -            | ExternDeclaration ";" .
    -IdentDef    = ident [ "*" ] .
    -IdentList   = IdentDef { "," IdentDef } .
    -
    -Type      = QualIdent
    -          | "[" Expr "]" Type
    -          | "[" "]" Type
    -          | "^" [ "VOLATILE" ] Type
    -          | [ "packed" ] "record" { IdentList ":" Type ";" } "end"
    -          | "variant" { Case ";" } "end"
    -          | "(" ident { "," ident } ")"
    -          | "set" "of" QualIdent
    -          | "proc" Signature .
    -Case      = ident [ "(" FieldList { ";" FieldList } ")" ] .
    -FieldList = ident { "," ident } ":" Type .
    -QualIdent = [ ident "." ] ident .
    -
    -Expr       = Conjunct { "or" Conjunct } .
    -Conjunct   = Relation { "and" Relation } .
    -Relation   = SimpleExpr [ RelOp SimpleExpr ] .
    -RelOp      = "=" | "#" | "<" | "<=" | ">" | ">=" | "in" .
    -SimpleExpr = [ "-" ] Term { AddOp Term } .
    -AddOp      = "+" | "-" | "|" | "xor" .
    -Term       = Factor { MulOp Factor } .
    -MulOp      = "*" | "/" | "div" | "mod" | "&" | "shl" | "shr" .
    -Factor     = number | char | string | Designator | "(" Expr ")"
    -           | "not" Factor | "~" Factor
    -           | "[" [ Expr { "," Expr } ] "]"
    -           | "{" [ Element { "," Element } ] "}"
    -           | "^" [ "VOLATILE" ] Type "(" Expr ")"
    -           | "try" Designator .
    -Element    = Expr | ident ":" Expr .
    -Designator = QualIdent { Selector } .
    -Selector   = "." ident | "^" | "[" Expr [ ".." Expr ] "]"
    -           | "(" [ Expr { "," Expr } ] ")" .
    -
    -Statements = { Statement ";" } .
    -Statement  = Designator [ ":=" Expr ]
    -           | "_" ":=" Expr
    -           | Target "," Target { "," Target } ":=" Expr
    -           | "if" Expr "then" Statements
    -             { "elsif" Expr "then" Statements } [ "else" Statements ] "end"
    -           | "while" Expr "do" Statements "end"
    -           | "repeat" Statements "until" Expr
    -           | "for" ident ":=" Expr "to" Expr [ "by" Expr ] "do" Statements "end"
    -           | "match" Expr "of" { "|" Arm } "end"
    -           | "return" [ Expr { "," Expr } ]
    -           | "break"
    -           | "defer" Statement
    -           | "try" Designator .
    -Arm        = ( ident [ "(" ident { "," ident } ")" ]
    -             | Label { "," Label } | "else" ) ":" Statements .
    -Label      = Expr [ ".." Expr ] .
    -Target     = Designator | "_" .
    -
    -ProcDeclaration   = "proc" IdentDef Signature ";"
    -                    ( "forward" | { LocalDeclaration } "begin" Statements "end" [ ident ]
    -                    | "code" { [ ident ":" ] [ Instruction ] ";" } "end" [ ident ] ) .
    -LocalDeclaration  = "const" { ident [ ":" Type ] "=" Expr ";" }
    -                  | "type" { ident "=" Type ";" }
    -                  | "var" { ident { "," ident } ":" Type ";" } .
    -Signature         = "(" [ Params { ";" Params } [ ";" "..." ] ] ")" [ ":" Results ]
    -                  | [ ":" Results ] .
    -Params            = [ "var" ] ident { "," ident } ":" Type .
    -Results           = Type | "(" Type { "," Type } ")" .
    -ExternDeclaration = "extern" ( "proc" IdentDef Signature
    -                             | "var" IdentDef ":" Type ) .
    -

    character is any character but a line break, and in a string any but " and \, in a character any but ' and \. A procedure argument of a generic module (section 3) is written as a QualIdent, which is a Type here. ... comes last in a Signature, and only in an extern. An Instruction is written in the target’s assembly language (appendix A).

    raz is under the ISC license.
    diff --git a/site/public/style.css b/site/public/style.css index 2b1abd2..c39d221 100644 --- a/site/public/style.css +++ b/site/public/style.css @@ -84,10 +84,20 @@ /* the report */ .spec { max-width: 46rem; } .spec pre { background: var(--code-bg); border-left: 2px solid var(--line); white-space: pre-wrap; } -.spec table { border-collapse: collapse; width: 100%; font-size: 15px; margin: 1em 0; } -.spec td, .spec th { border-bottom: 1px solid var(--line); padding: 5px 10px 5px 0; +.tour article table, .spec table { border-collapse: collapse; width: 100%; font-size: 15px; margin: 1em 0; } +.tour article td, .tour article th, .spec td, .tour article th, .spec th { border-bottom: 1px solid var(--line); padding: 5px 10px 5px 0; text-align: left; vertical-align: top; } -.spec th { border-bottom-width: 2px; } +.tour article th, .spec th { border-bottom-width: 2px; } +/* narrow screens: each row becomes a card, its cells labelled by column */ +@media (max-width: 39.99rem) { + .tour article table thead { display: none; } + .tour article table, .tour article tbody, .tour article tr, .tour article td { display: block; } + .tour article tr { border: 1px solid var(--line); border-radius: 6px; padding: 6px 12px; margin: 0 0 10px; } + .tour article td { border: 0; padding: 3px 0; } + .spec table { display: block; overflow-x: auto; } + .tour article td::before { content: attr(data-label); display: block; font: 11px system-ui, sans-serif; + text-transform: uppercase; letter-spacing: .08em; color: var(--muted); } +} @media (min-width: 40rem) { .spec td:first-child { white-space: nowrap; } } .spec nav#TOC ul { list-style: none; padding-left: 1em; } diff --git a/site/public/tour/checks.html b/site/public/tour/checks.html index ce0624f..7fe208e 100644 --- a/site/public/tour/checks.html +++ b/site/public/tour/checks.html @@ -68,7 +68,7 @@

    Reading the message

    The first line is the place of the offending expression: file, line and column, then what failed and the numbers involved. Each in line after it is a call still under way, innermost first, with the basic-typed variables it held. That is usually enough to see the bug without a debugger.

    Other failures

    -

    The same shape of message tells of a nil pointer, a division by zero, a bad slice and a stack overflow. Each of them stops the program with status 2, or by the signal if the machine caught it, and never runs on with a wrong value.

    +

    The same shape of message tells of a nil pointer, a division by zero, a bad slice and a stack overflow. Each of them stops the program with status 2, and never runs on with a wrong value.

    Nilp.raz
    module Nilp;
     import Out;
     
    @@ -90,7 +90,8 @@
     end;
     
     end Nilp.
    -
    Nilp.raz:8:11: stopped by a nil pointer
    +
    2
    +Nilp.raz:8:11: stopped by a nil pointer
       in Nilp.last at Nilp.raz:8:11: n = nil
       in Nilp.main at Nilp.raz:18:5
     
    @@ -110,7 +111,8 @@ end; end Zero.
    -
    Zero.raz:6:5: stopped by a division fault
    +
    3
    +Zero.raz:6:5: stopped by a division fault
       in Zero.ratio at Zero.raz:6:5: a = 10, b = 0
       in Zero.main at Zero.raz:13:5: n = 0
     
    diff --git a/site/public/tour/hello.html b/site/public/tour/hello.html index b991229..992f33a 100644 --- a/site/public/tour/hello.html +++ b/site/public/tour/hello.html @@ -70,7 +70,7 @@ $ raz run Quiet.raz hello, again $ ls -l Quiet | awk '{print $5, "bytes"}' -28496 bytes
    +28304 bytes

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

    What Out can write

    Out is the library's buffered output. It writes strings, single characters, numbers in decimal or hexadecimal, and a line feed. A string is written as it is, with \n for a line feed, \t for a tab, \" and \\.

    diff --git a/site/public/tour/integers.html b/site/public/tour/integers.html index e9cc550..4da0fc7 100644 --- a/site/public/tour/integers.html +++ b/site/public/tour/integers.html @@ -40,7 +40,7 @@
  • Threads
  • Raz · lesson 3 of 15

    Integers

    raz has ten integer types, and a program that works with bytes, addresses, hashes and file offsets uses most of them. Each is a different type, so each has rules, and the rules are the same everywhere: that is the point of having them.

    -

    | Type | Size | Values | |---|---|---| | I8 I16 I32 I64 | 1, 2, 4, 8 bytes | signed, two's complement | | U8 U16 U32 U64 | 1, 2, 4, 8 bytes | unsigned | | INT | an address's: 8 on x86-64 | signed, as big as an address | | UINT | an address's | unsigned, as big as an address |

    +
    TypeSizeValues
    I8 I16 I32 I641, 2, 4, 8 bytessigned, two's complement
    U8 U16 U32 U641, 2, 4, 8 bytesunsigned
    INTan address's: 8 on x86-64signed, as big as an address
    UINTan address'sunsigned, as big as an address

    SIZE(T) says how many bytes a type takes, and an unsigned type's largest value is what you get by taking one from zero. This program asks each type.

    Family.raz
    module Family;
     import Out;
    diff --git a/site/public/tour/values.html b/site/public/tour/values.html
    index e05ba13..9e8705f 100644
    --- a/site/public/tour/values.html
    +++ b/site/public/tour/values.html
    @@ -87,7 +87,7 @@
     

    The fix is the conversion, written where it happens: if i < I64(LEN(s)). It costs nothing at run time and says what is meant.

    What converts to what

    Everything else that converts does so with the type's name, and the rules are short:

    -

    | From | To | Result | |---|---|---| | integer | integer | cut to the new width, or extended by the sign (signed) or zeros (unsigned) | | integer | F32, F64 | the nearest real | | F32, F64 | integer | rounded toward zero | | F32 | F64 | the same value; the other way, the nearest F32 | | enumeration | integer | its position; and back, if there is a name at that position | | set | integer | its bits; and back | | INT, UINT | pointer | the address; and back |

    +
    FromToResult
    integerintegercut to the new width, or extended by the sign (signed) or zeros (unsigned)
    integerF32, F64the nearest real
    F32, F64integerrounded toward zero
    F32F64the same value; the other way, the nearest F32
    enumerationintegerits position; and back, if there is a name at that position
    setintegerits bits; and back
    INT, UINTpointerthe address; and back

    There is no conversion between BOOL and an integer: say what you mean with if. A BOOL is true or false, and and, or and not are for BOOLs: they bind below the relations, so i < n and a[i] # 0 needs no parentheses, and and and or evaluate their right operand only when it decides the result. #, not <>, is "different".

    Truth.raz
    module Truth;
     import Out;
    diff --git a/site/style.css b/site/style.css
    index 2b1abd2..c39d221 100644
    --- a/site/style.css
    +++ b/site/style.css
    @@ -84,10 +84,20 @@
     /* the report */
     .spec { max-width: 46rem; }
     .spec pre { background: var(--code-bg); border-left: 2px solid var(--line); white-space: pre-wrap; }
    -.spec table { border-collapse: collapse; width: 100%; font-size: 15px; margin: 1em 0; }
    -.spec td, .spec th { border-bottom: 1px solid var(--line); padding: 5px 10px 5px 0;
    +.tour article table, .spec table { border-collapse: collapse; width: 100%; font-size: 15px; margin: 1em 0; }
    +.tour article td, .tour article th, .spec td, .tour article th, .spec th { border-bottom: 1px solid var(--line); padding: 5px 10px 5px 0;
       text-align: left; vertical-align: top; }
    -.spec th { border-bottom-width: 2px; }
    +.tour article th, .spec th { border-bottom-width: 2px; }
    +/* narrow screens: each row becomes a card, its cells labelled by column */
    +@media (max-width: 39.99rem) {
    +  .tour article table thead { display: none; }
    +  .tour article table, .tour article tbody, .tour article tr, .tour article td { display: block; }
    +  .tour article tr { border: 1px solid var(--line); border-radius: 6px; padding: 6px 12px; margin: 0 0 10px; }
    +  .tour article td { border: 0; padding: 3px 0; }
    +  .spec table { display: block; overflow-x: auto; }
    +  .tour article td::before { content: attr(data-label); display: block; font: 11px system-ui, sans-serif;
    +    text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
    +}
     @media (min-width: 40rem) { .spec td:first-child { white-space: nowrap; } }
     .spec nav#TOC ul { list-style: none; padding-left: 1em; }