From 3e3ad9d88088eda2e399a59b6d86b802fd3abf59 Mon Sep 17 00:00:00 2001 From: Luis <42945842+ldiaz94@users.noreply.github.com> Date: Tue, 13 Oct 2026 12:55:25 +0100 Subject: [PATCH] site: Bytes, slices in code procedures, record constants; the download More Raz's strings lesson gains Bytes, its asm lesson slices in and out of code procedures (10.18) and popcnt as the assembler now knows it; the tour gains record constants (10.16) and Math's pow, log2, round. The home page's numbers are current; the links to the private GitHub repo are gone. The report's tables span the column, with columns as wide as their text (pandoc no longer splits them equally) and cells set at the top. make dist makes the release's tarball, for CI and the site alike; site/build.py builds the latest tag's in a checkout of its own and serves it from download/, with its SHA-256 and download/latest. --- diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f65ba80..1b8b0f9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -30,9 +30,6 @@ env: GH_TOKEN: ${{ github.token }} run: | - d=raz-${TAG#v}-linux-x86_64 - mkdir -p $d/man && cp -r raz lib LICENSE README.md $d - cp doc/raz.1 doc/raz.7 doc/raz-tutorial.7 build/raz-lib.3 $d/man - tar czf $d.tar.gz $d - gh release create "$TAG" $d.tar.gz --verify-tag \ + make dist + gh release create "$TAG" build/raz-${TAG#v}-linux-x86_64.tar.gz --verify-tag \ --title "raz ${TAG#v}" --notes "$(./raz --version)" diff --git a/Makefile b/Makefile index de82658..bb2480b 100644 --- a/Makefile +++ b/Makefile @@ -119,10 +119,29 @@ rm -rf $(PREFIX)/lib/raz $(PREFIX)/bin/raz $(MAN)/man1/raz.1 $(MAN)/man3/raz-lib.3 \ $(MAN)/man7/raz.7 $(MAN)/man7/raz-tutorial.7 +# A release's tarball, build/raz-V-linux-x86_64.tar.gz: raz, the lib/ +# it reads beside itself, and the manual pages, V being what raz +# --version says. It is made of the checkout in TREE, this one unless +# given: CI packs the tag it checked out, and site/build.py the latest +# tag, which it checks out apart. +TREE = . + +dist: + $(MAKE) -C $(TREE) raz man + v=$$($(TREE)/raz --version | sed 's/^raz \([^,]*\),.*/\1/'); \ + d=raz-$$v-linux-x86_64; \ + rm -rf build/$$d && mkdir -p build/$$d/man && \ + cp -r $(TREE)/raz $(TREE)/lib $(TREE)/LICENSE $(TREE)/README.md build/$$d && \ + cp $(TREE)/doc/raz.1 $(TREE)/doc/raz.7 $(TREE)/doc/raz-tutorial.7 \ + $(TREE)/build/raz-lib.3 build/$$d/man && \ + tar czf build/$$d.tar.gz -C build $$d && rm -rf build/$$d && \ + echo build/$$d.tar.gz + # The website, plain files in site/public/: its home page, the tour # "Raz, Set, Go" (whose programs are run here, so the output shown is -# real) and the report. site/build.py says how; it needs ./raz and pandoc. +# real), the report and the latest release's tarball. site/build.py +# says how; it needs ./raz and pandoc. site: raz python3 site/build.py -.PHONY: units tests check gdb bench kernels stress fmt loc man pdf site clean install uninstall +.PHONY: units tests check gdb bench kernels stress fmt loc man pdf dist site clean install uninstall diff --git a/README.md b/README.md index 55f2cca..ababa8d 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ | `examples/` | Small programs, each with the output it should give | | `tools/Doc.raz` | Prints what a module exports, with its comments | | `tools/Pretty.raz` | The formatter: fixes indentation and spacing | -| `site/` | The website: home page, the tour "Raz, Set, Go" and the report, as plain files in `site/public/`; `make site` rebuilds them | +| `site/` | The website: home page, the tours "Raz, Set, Go" and "More Raz", the report and the latest release's tarball, as plain files in `site/public/`; `make site` rebuilds them | | `editor/` | Support for vim and emacs | | `conform/` | The conformance suite: what every implementation must do | | `test/` | This compiler's own tests, and the scripts that run them | @@ -71,6 +71,7 @@ make loc # the compiler's lines make tests # tests of the scanner, encoder and linker on their own make pdf # build/raz.pdf, the report, by pandoc and Chromium + make dist # build/raz-V-linux-x86_64.tar.gz, the release's tarball make site # site/public/, the website, by pandoc and python3 ## Using it @@ -202,8 +203,11 @@ $ git push origin v0.9.1 GitHub then builds and checks the tag, and makes a release of it with -a tarball of `raz`, its `lib/` and its manual pages. A tag pushed before the workflow -existed is released from the Actions tab: run "ci" with its name. +a tarball of `raz`, its `lib/` and its manual pages, made by `make +dist`. A tag pushed before the workflow existed is released from the +Actions tab: run "ci" with its name. Then `make site` puts the new +tag's tarball on the website (it builds it from the tag, apart from +the tree at hand); commit `site/public/` and push to publish it. A version of the report is named by its month and a count; the report's last section says what each version changed. diff --git a/site/build.py b/site/build.py index ae47855..b08e679 100644 --- a/site/build.py +++ b/site/build.py @@ -6,7 +6,8 @@ The site is plain files: open public/index.html, or put the folder on any web server. Nothing runs in the reader's browser; the code on the tour's pages is run here, by ./raz, and the output shown is what it -printed, so a lesson that stops working fails the build. +printed, so a lesson that stops working fails the build. The home page +offers the latest release's tarball, made by make dist from the tag. Lessons are site/content//NN-name.txt, one folder to a tour (see TOURS below): @@ -31,13 +32,12 @@ session: each line that starts with "$ " is run in the lesson's folder, with raz on the path, and shown with what it printed. """ -import html, os, re, shutil, subprocess, sys, tempfile +import hashlib, html, os, re, shutil, subprocess, sys, tempfile HERE = os.path.dirname(os.path.abspath(__file__)) ROOT = os.path.dirname(HERE) OUT = os.path.join(HERE, "public") RAZ = os.path.join(ROOT, "raz") -REPO = "https://github.com/ldiaz94/raz" SITE = "https://raz.lucelad.workers.dev" # where the pages live, for the preview image # folder in content/, folder in public/, name, the sentence under the name @@ -237,14 +237,14 @@ -
+
%s
- + -""" % (html.escape(title), html.escape(title), SITE, up, up, up, up, up, up, nav, REPO, body, REPO) +""" % (html.escape(title), html.escape(title), SITE, up, up, up, up, up, up, nav, body) def write(path, text): path = os.path.join(OUT, path) @@ -307,12 +307,41 @@ p = subprocess.run( ["pandoc", os.path.join(ROOT, "doc", "raz.md"), "-s", "--template", os.path.join(HERE, "content", "spec.tmpl"), "--toc", "--toc-depth=1", - "--shift-heading-level-by=-1", "--no-highlight", "-t", "html"], + "--shift-heading-level-by=-1", "--no-highlight", "-t", "html", + # wide enough that no row of a table is "long": pandoc would + # otherwise give each column an equal share of the width + "--columns=10000"], capture_output=True, text=True, check=True) body = '
%s
' % p.stdout write("spec.html", page("The raz report", body, 0, "spec")) -def build_home(): +def build_download(): + """The latest release's tarball, in public/download/ with its SHA-256 + and /download/latest leading to it; (version, file name, SHA-256). + It is made of the tag's own checkout, not of the tree at hand, and + kept in build/ to be made once.""" + git = lambda *a: subprocess.run(("git", "-C", ROOT) + a, capture_output=True, + text=True, check=True).stdout.strip() + tag = git("describe", "--tags", "--abbrev=0", "--match", "v*") + name = "raz-%s-linux-x86_64.tar.gz" % tag[1:] + made = os.path.join(ROOT, "build", name) + if not os.path.exists(made): + tree = tempfile.mkdtemp() + try: + git("worktree", "add", "--detach", tree, tag) + subprocess.run(["make", "-s", "-C", ROOT, "dist", "TREE=" + tree], + stdout=subprocess.DEVNULL, check=True) + finally: + git("worktree", "remove", "--force", tree) + digest = hashlib.sha256(open(made, "rb").read()).hexdigest() + os.makedirs(os.path.join(OUT, "download")) + shutil.copy(made, os.path.join(OUT, "download")) + write("download/%s.sha256" % name, "%s %s\n" % (digest, name)) + # Cloudflare reads _redirects from the root of what it serves + write("_redirects", "/download/latest /download/%s 302\n" % name) + return tag[1:], name, digest + +def build_home(release): snippet = open(os.path.join(HERE, "content", "home.raz"), encoding="utf-8").read() tmp = tempfile.mkdtemp() try: @@ -326,6 +355,9 @@ text = open(os.path.join(HERE, "content", "home.html"), encoding="utf-8").read() text = text.replace("@SNIPPET@", highlight(snippet.rstrip("\n"))) text = text.replace("@OUTPUT@", html.escape(stdout.rstrip("\n"))) + version, name, digest = release + text = text.replace("@VERSION@", version).replace("@TARBALL@", name) + text = text.replace("@DIR@", name[:-len(".tar.gz")]).replace("@SHA256@", digest) write("index.html", page("raz: a small systems language", text, 0, "home")) def main(): @@ -351,7 +383,7 @@ build_tour(tour, lessons, nxt) counts.append(len(lessons)) build_spec() - build_home() + build_home(build_download()) print("site/public: %s lessons" % " + ".join(map(str, counts))) main() diff --git a/site/content/advanced/02-bytes.txt b/site/content/advanced/02-bytes.txt index 186f834..65906ad 100644 --- a/site/content/advanced/02-bytes.txt +++ b/site/content/advanced/02-bytes.txt @@ -1,8 +1,8 @@ title: Strings and bytes part: The library -summary: Copying, hashing and ordering strings, and reading and writing binary formats. +summary: Copying, hashing and ordering strings, searching bytes many at a time, and reading and writing binary formats. --- -A `[]U8` is both a string and a block of bytes. `Str` has what is done with them: comparing, finding, hashing, copying into memory of your own, UTF-8, numbers, and the fixed byte orders of file formats and network protocols. +A `[]U8` is both a string and a block of bytes. `Str` has what is done with them: comparing, finding, hashing, copying into memory of your own, UTF-8, numbers, and the fixed byte orders of file formats and network protocols. `Bytes` has the searches, made fast. ## Ordering and hashing @@ -75,6 +75,44 @@ end Keep. ``` + +## Searching + +`Bytes` finds bytes many at a time: `Bytes.index` and `Bytes.last` give the first and the last place of a byte in a `[]U8`, or -1, `Bytes.count` how many places it has, and `Bytes.find` where one `[]U8` first starts in another (`Str.find` is the same). Each is what a loop over the bytes would give, only faster: the library's own body compares eight bytes at once in a `U64`, and on x86-64 a file of its own, `Bytes.x86_64.raz`, compares sixteen with SSE2, in code procedures. + +```raz Paths run +module Paths; +import Out, Fmt, Bytes; + +(* the last part of a path: what follows its last slash *) +proc base(path: []U8): []U8; +begin + return path[Bytes.last(path, '/') + 1..LEN(path)]; +end; + +proc main*; +var text: []U8; at, n, line: INT; +begin + Out.str(base("/usr/local/lib/raz/Bytes.raz")); Out.char(' '); + Out.str(base("Out.raz")); Out.ln; + + text := "one line\nanother line\nthe line with raz in it\nthe last\n"; + Fmt.print("{} lines\n", [Fmt.int(Bytes.count(text, 10))]); + at := Bytes.find(text, "raz"); + if at >= 0 then + (* the line it is on: the newlines before it, plus one *) + line := Bytes.count(text[0..at], 10) + 1; + n := Bytes.index(text[at..LEN(text)], 10); + Fmt.print("raz on line {}, at {}, and the line goes on {} more\n", + [Fmt.int(line), Fmt.int(at), Fmt.int(n)]); + end; + Fmt.print("{} {}\n", [Fmt.int(Bytes.find(text, "zzz")), Fmt.int(Bytes.find(text, ""))]); +end; + +end Paths. +``` + +When the byte isn't there, `Bytes.last` gives -1, so `base` of a name with no slash is the whole name. A search of a slice gives places in the slice, counted from its own start: add the place the slice starts at to get one in the whole. ## Binary formats diff --git a/site/content/advanced/11-asm.txt b/site/content/advanced/11-asm.txt index c10c572..e4e55eb 100644 --- a/site/content/advanced/11-asm.txt +++ b/site/content/advanced/11-asm.txt @@ -42,7 +42,8 @@ - Integer and pointer arguments arrive in `rdi`, `rsi`, `rdx`, `rcx`, `r8` and `r9`; `F32` and `F64` ones in `xmm0` to `xmm7`. - The result goes in `rax` (and `rdx` for a second) or `xmm0`. - It must keep `rbx`, `rbp`, `rsp` and `r12` to `r15` as it found them. `rax`, `rcx`, `rdx`, `rsi`, `rdi` and `r8` to `r11` are free to change. -- Its parameters and results are therefore of the types C can take, at most six integer and eight real parameters and two results. +- A slice is two integers, its address and its length, as System V passes a struct of two. As a parameter it takes two registers in a row; as the result its address goes in `rax` and its length in `rdx`. +- Its parameters and results are therefore of the types C can take, or slices: at most six integer and eight real parameters, and two results, a slice being the only one. That is why the next one is so short: the argument is already in `rdi`. @@ -59,10 +60,10 @@ ret; end swap64; -(* the number of bits set in x: popcnt rax, rdi *) +(* the number of bits set in x *) proc ones(x: U64): INT; code - db 0F3H, 48H, 0FH, 0B8H, 0C7H; + popcnt rax, rdi; ret; end ones; @@ -77,18 +78,18 @@ end Bits. ``` -`db` writes any bytes, for an instruction the assembler doesn't know. Which instructions it knows is the implementation's business; `db` keeps you from waiting for it to learn one. (The two instructions above are from the processor manuals: `bswap r64` is `REX.W 0F C8+r`, `popcnt r64, r/m64` is `F3 REX.W 0F B8 /r`.) +`db` writes any bytes, for an instruction the assembler doesn't know. Which instructions it knows is the implementation's business: this one knows `popcnt` but not `bswap`, and `db` keeps you from waiting for it to learn one. (`bswap r64` is `REX.W 0F C8+r` in the processor manuals.) ## Labels and loops -A label, `name:`, names the place of the instruction after it, within the procedure. Jumps go to labels, and a constant of the module may stand wherever a number does. This sums an array of `INT`s, which a pointer and a length describe: +A label, `name:`, names the place of the instruction after it, within the procedure. Jumps go to labels, and a constant of the module may stand wherever a number does. This sums a slice of `INT`s, whose address arrives in `rdi` and its length in `rsi`: ```raz Sum run module Sum; import Out; -(* the sum of the n INTs at p *) -proc sum(p: ^INT; n: INT): INT; +(* the sum of the INTs of a *) +proc sum(a: []INT): INT; code xor eax, eax; test rsi, rsi; @@ -114,12 +115,48 @@ var a: [6]INT; i: INT; begin for i := 0 to 5 do a[i] := (i + 1) * 100; end; - Out.int(sum(ADR(a[0]), 6)); Out.char(' '); + Out.int(sum(a)); Out.char(' '); Out.int(sumRaz(a)); Out.char(' '); - Out.int(sum(ADR(a[0]), 0)); Out.ln; + Out.int(sum(a[2..4])); Out.char(' '); + Out.int(sum(a[0..0])); Out.ln; end; end Sum. +``` + +The procedure trusts the length it is given, as it must: the checks of the language end where its code begins. + +A slice comes back the same way, its address in `rax` and its length in `rdx`. This one returns what is left of a string past its leading blanks: + +```raz Trim run +module Trim; +import Out; + +(* s past its leading blanks *) +proc trim(s: []U8): []U8; +code + mov rax, rdi; + mov rdx, rsi; +again: + test rdx, rdx; + jz done; + cmp byte [rax], 32; + jne done; + inc rax; + dec rdx; + jmp again; +done: + ret; +end trim; + +proc main*; +begin + Out.char('['); Out.str(trim(" raz")); Out.str("]\n"); + Out.char('['); Out.str(trim("raz")); Out.str("]\n"); + Out.char('['); Out.str(trim(" ")); Out.str("]\n"); +end; + +end Trim. ``` A procedure may have up to 64 labels. The check against the raz version is the habit worth keeping: write the procedure in raz first, then in assembly, and compare their results on awkward inputs. diff --git a/site/content/home.html b/site/content/home.html index c919546..61492eb 100644 --- a/site/content/home.html +++ b/site/content/home.html @@ -15,15 +15,15 @@ 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.

-

The compiler is one Free Pascal program of about 7,800 lines. It makes +

The compiler is one Free Pascal program of about 9,100 lines. It makes x86-64 machine code and the ELF file itself, with no assembler or linker, in -one pass, at about a million lines a second.

+one pass, at about 900,000 lines a second.

- ~7,800 lines of compiler - ~1M lines compiled a second + ~9,100 lines of compiler + ~900K lines compiled a second static executables, no run time to install - 1 report, ~2,000 lines + 1 report, ~2,100 lines
@@ -45,7 +45,7 @@
  • Modules with bodies, and generic modules: Map(K, V; hash, eq).
  • ^VOLATILE T and the atomics CAS, XCHG, XADD, FENCE, for devices and lock-free code.
  • extern procedures and variables from C, code procedures in assembly, and SYSCALL.
  • -
  • Threads without C, a library of Out, Str, Fmt, Map, Sort and more, and gdb that knows your lines.
  • +
  • Threads without C, a library of Out, Str, Bytes, Fmt, Map, Sort and more, and gdb that knows your lines.
  • A formatter, a documentation tool, and editor support for vim and emacs.
  • @@ -60,21 +60,20 @@

    The language, in writing

    The language is defined by the report, which is -short on purpose: whatever it doesn’t allow, raz doesn’t have. There -is also a guide to reading the -compiler, file by file.

    +short on purpose: whatever it doesn’t allow, raz doesn’t have.

    Download

    -

    Each release is a tarball with the compiler, raz, and its -library, lib/, which it finds beside itself.

    +

    raz @VERSION@ is a tarball for x86-64 Linux with the compiler, raz, +its library, lib/, which it finds beside itself, and the manual +pages. It needs nothing else installed.

    - Latest release - Source on GitHub + Download raz @VERSION@ + SHA-256
    -
    $ tar xzf raz-*.tar.gz
    -$ ./raz run examples/Hello.raz
    -hello, world
    -

    To build it yourself you need Free Pascal 3.2.2:

    -
    $ apt-get install fp-compiler
    -$ git clone https://github.com/ldiaz94/raz
    -$ cd raz && make && make install    # ~/.local, or PREFIX=/usr/local
    +
    $ tar xzf @TARBALL@
    +$ ln -s $PWD/@DIR@/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.

    +

    SHA-256 @SHA256@

    diff --git a/site/content/tour/04-values.txt b/site/content/tour/04-values.txt index 5dcc4e1..e996be2 100644 --- a/site/content/tour/04-values.txt +++ b/site/content/tour/04-values.txt @@ -90,6 +90,8 @@ Fmt.print("22/7 = {}\n", [Fmt.real(x, 6)]); Fmt.print("as F32 = {}\n", [Fmt.real(F64(y), 6)]); Fmt.print("sqrt 2 = {}, pi = {}\n", [Fmt.real(Math.sqrt(2.0), 5), Fmt.real(Math.pi, 5)]); + Fmt.print("2^10 = {}, log2 of that = {}\n", [Fmt.real(Math.pow(2.0, 10.0), 1), Fmt.real(Math.log2(1024.0), 1)]); + Fmt.print("rounded: {} {}\n", [Fmt.real(Math.round(2.5), 1), Fmt.real(Math.round(-2.5), 1)]); Fmt.print("truncated: {} {}\n", [Fmt.int(I64(2.9)), Fmt.int(I64(-2.9))]); end; diff --git a/site/content/tour/07-records.txt b/site/content/tour/07-records.txt index 97ea279..bd0fd3a 100644 --- a/site/content/tour/07-records.txt +++ b/site/content/tour/07-records.txt @@ -41,6 +41,37 @@ end Points. ``` +## Tables of constants + +A constant may be a record, or an array of them: a table the program reads but can't change. Its fields are integers, reals, `BOOL`s, strings, procedures and the like, and arrays and records of these. + +```raz Planets run +module Planets; +import Fmt; + +type Planet = record name: []U8; moons: INT; water: BOOL; end; + +const Inner: [4]Planet = [ + {name: "Mercury"}, + {name: "Venus"}, + {name: "Earth", moons: 1, water: true}, + {name: "Mars", moons: 2}]; + +proc main*; +var i, total: INT; +begin + for i := 0 to LEN(Inner) - 1 do + total := total + Inner[i].moons; + if Inner[i].moons = 0 then Fmt.print("{} has no moon\n", [Fmt.str(Inner[i].name)]); end; + end; + Fmt.print("{} moons in all\n", [Fmt.int(total)]); +end; + +end Planets. +``` + +Fields left out are zero, as in any literal: Mercury's `moons` is 0 and its `water` is `false`. + ## Layout A record's layout is C's: each field at the next multiple of its own alignment, and the whole padded to a multiple of its largest alignment. `SIZE(T)` says how many bytes. A `packed record` has no padding, which is what a file format or a wire protocol wants. diff --git a/site/public/_redirects b/site/public/_redirects new file mode 100644 index 0000000..df7b391 --- /dev/null +++ b/site/public/_redirects @@ -0,0 +1 @@ +/download/latest /download/raz-0.9.0-linux-x86_64.tar.gz 302 diff --git a/site/public/advanced/allocators.html b/site/public/advanced/allocators.html index fbe981b..e3b46a7 100644 --- a/site/public/advanced/allocators.html +++ b/site/public/advanced/allocators.html @@ -16,7 +16,7 @@ -
    +
    - + diff --git a/site/public/advanced/asm.html b/site/public/advanced/asm.html index eb702c5..0e3ea56 100644 --- a/site/public/advanced/asm.html +++ b/site/public/advanced/asm.html @@ -16,7 +16,7 @@ -
    +
    -
    raz is under the ISC license. Source.
    +
    raz is under the ISC license.
    diff --git a/site/public/advanced/atomics.html b/site/public/advanced/atomics.html index 52b2654..78ad1fa 100644 --- a/site/public/advanced/atomics.html +++ b/site/public/advanced/atomics.html @@ -16,7 +16,7 @@ -
    +
    -
    raz is under the ISC license. Source.
    +
    raz is under the ISC license.
    diff --git a/site/public/advanced/bytes.html b/site/public/advanced/bytes.html index ecfbf3f..75963ee 100644 --- a/site/public/advanced/bytes.html +++ b/site/public/advanced/bytes.html @@ -16,7 +16,7 @@ -
    +

    The library · lesson 2 of 18

    Strings and bytes

    -

    A []U8 is both a string and a block of bytes. Str has what is done with them: comparing, finding, hashing, copying into memory of your own, UTF-8, numbers, and the fixed byte orders of file formats and network protocols.

    +

    A []U8 is both a string and a block of bytes. Str has what is done with them: comparing, finding, hashing, copying into memory of your own, UTF-8, numbers, and the fixed byte orders of file formats and network protocols. Bytes has the searches, made fast.

    Ordering and hashing

    Str.cmp gives -1, 0 or 1, byte by byte, so it orders UTF-8 text by code point. Str.eq is equality. Str.hash is FNV-1a, 64 bits; it is what a Map of strings uses.

    Order.raz
    module Order;
    @@ -112,6 +112,43 @@
     end Keep.
    name-0 name-1 name-2 
     
    +

    Searching

    +

    Bytes finds bytes many at a time: Bytes.index and Bytes.last give the first and the last place of a byte in a []U8, or -1, Bytes.count how many places it has, and Bytes.find where one []U8 first starts in another (Str.find is the same). Each is what a loop over the bytes would give, only faster: the library's own body compares eight bytes at once in a U64, and on x86-64 a file of its own, Bytes.x86_64.raz, compares sixteen with SSE2, in code procedures.

    +
    Paths.raz
    module Paths;
    +import Out, Fmt, Bytes;
    +
    +(* the last part of a path: what follows its last slash *)
    +proc base(path: []U8): []U8;
    +begin
    +    return path[Bytes.last(path, '/') + 1..LEN(path)];
    +end;
    +
    +proc main*;
    +var text: []U8; at, n, line: INT;
    +begin
    +    Out.str(base("/usr/local/lib/raz/Bytes.raz")); Out.char(' ');
    +    Out.str(base("Out.raz")); Out.ln;
    +
    +    text := "one line\nanother line\nthe line with raz in it\nthe last\n";
    +    Fmt.print("{} lines\n", [Fmt.int(Bytes.count(text, 10))]);
    +    at := Bytes.find(text, "raz");
    +    if at >= 0 then
    +        (* the line it is on: the newlines before it, plus one *)
    +        line := Bytes.count(text[0..at], 10) + 1;
    +        n := Bytes.index(text[at..LEN(text)], 10);
    +        Fmt.print("raz on line {}, at {}, and the line goes on {} more\n",
    +            [Fmt.int(line), Fmt.int(at), Fmt.int(n)]);
    +    end;
    +    Fmt.print("{} {}\n", [Fmt.int(Bytes.find(text, "zzz")), Fmt.int(Bytes.find(text, ""))]);
    +end;
    +
    +end Paths.
    +
    Bytes.raz Out.raz
    +4 lines
    +raz on line 3, at 36, and the line goes on 9 more
    +-1 0
    +
    +

    When the byte isn't there, Bytes.last gives -1, so base of a name with no slash is the whole name. A search of a slice gives places in the slice, counted from its own start: add the place the slice starts at to get one in the whole.

    Binary formats

    A file format or a network protocol has a byte order of its own, not the machine's. Str.le and Str.be read an unsigned number of up to 8 bytes in a fixed order (little- or big-endian) and Str.putLE and Str.putBE write one. They work on any slice, so a header is read where it lies, with no struct to overlay and no byte swapping to forget.

    Here is a small record format: a 4-byte tag, a 2-byte big-endian length, a 4-byte little-endian checksum, then the data.

    @@ -197,6 +234,6 @@ -1

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

    -
    raz is under the ISC license. Source.
    +
    raz is under the ISC license.
    diff --git a/site/public/advanced/collections.html b/site/public/advanced/collections.html index f61e67b..4ff5bf5 100644 --- a/site/public/advanced/collections.html +++ b/site/public/advanced/collections.html @@ -16,7 +16,7 @@ -
    +
    -
    raz is under the ISC license. Source.
    +
    raz is under the ISC license.
    diff --git a/site/public/advanced/files.html b/site/public/advanced/files.html index e9f6a85..9ef66e2 100644 --- a/site/public/advanced/files.html +++ b/site/public/advanced/files.html @@ -16,7 +16,7 @@ -
    +
    -
    raz is under the ISC license. Source.
    +
    raz is under the ISC license.
    diff --git a/site/public/advanced/fmt.html b/site/public/advanced/fmt.html index a70da6e..d16efea 100644 --- a/site/public/advanced/fmt.html +++ b/site/public/advanced/fmt.html @@ -16,7 +16,7 @@ -
    +
    - + diff --git a/site/public/advanced/index.html b/site/public/advanced/index.html index 4211550..702d919 100644 --- a/site/public/advanced/index.html +++ b/site/public/advanced/index.html @@ -16,7 +16,7 @@ -
    +

    More Raz

    The second tour, for the part of raz that sits close to the machine. It @@ -30,7 +30,7 @@ made, as before.

    The library

    1. Output and formatting Out's buffer, Fmt's arguments, formatting into a Buf, and laying out columns.
    2. -
    3. Strings and bytes Copying, hashing and ordering strings, and reading and writing binary formats.
    4. +
    5. Strings and bytes Copying, hashing and ordering strings, searching bytes many at a time, and reading and writing binary formats.
    6. Lists, maps and sorting List(T), Map(K, V) and Sort(T), put together in a word-frequency program.
    7. Files and the command line Whole files with Files, descriptors and directories with Sys, and options with Opt.
    8. Time, randomness and other programs Clocks, sleeping, random bytes, and running a program with its output piped back.
    9. @@ -55,6 +55,6 @@
    10. A ring buffer between threads A single-producer, single-consumer queue, put together from what the tour has covered.
    - + diff --git a/site/public/advanced/lifecycle.html b/site/public/advanced/lifecycle.html index be0b90e..f761694 100644 --- a/site/public/advanced/lifecycle.html +++ b/site/public/advanced/lifecycle.html @@ -16,7 +16,7 @@ -
    +
    - + diff --git a/site/public/advanced/linkstatic.html b/site/public/advanced/linkstatic.html index 605c3e7..80626b3 100644 --- a/site/public/advanced/linkstatic.html +++ b/site/public/advanced/linkstatic.html @@ -16,7 +16,7 @@ -
    +
    - + diff --git a/site/public/advanced/listing.html b/site/public/advanced/listing.html index e42980c..57a3bae 100644 --- a/site/public/advanced/listing.html +++ b/site/public/advanced/listing.html @@ -16,7 +16,7 @@ -
    +
    - + diff --git a/site/public/advanced/lockfree.html b/site/public/advanced/lockfree.html index 3542693..7ff02df 100644 --- a/site/public/advanced/lockfree.html +++ b/site/public/advanced/lockfree.html @@ -16,7 +16,7 @@ -
    +
    - + diff --git a/site/public/advanced/ordering.html b/site/public/advanced/ordering.html index 02cd621..d28a0b5 100644 --- a/site/public/advanced/ordering.html +++ b/site/public/advanced/ordering.html @@ -16,7 +16,7 @@ -
    +
    - + diff --git a/site/public/advanced/processes.html b/site/public/advanced/processes.html index 1e2a1de..9a45bf5 100644 --- a/site/public/advanced/processes.html +++ b/site/public/advanced/processes.html @@ -16,7 +16,7 @@ -
    +
    - + diff --git a/site/public/advanced/ring.html b/site/public/advanced/ring.html index 5c09300..55d77ac 100644 --- a/site/public/advanced/ring.html +++ b/site/public/advanced/ring.html @@ -16,7 +16,7 @@ -
    +
    - + diff --git a/site/public/advanced/static.html b/site/public/advanced/static.html index 0f5df18..c568cb9 100644 --- a/site/public/advanced/static.html +++ b/site/public/advanced/static.html @@ -16,7 +16,7 @@ -
    +
    - + diff --git a/site/public/advanced/syscalls.html b/site/public/advanced/syscalls.html index 41b619a..83733e1 100644 --- a/site/public/advanced/syscalls.html +++ b/site/public/advanced/syscalls.html @@ -16,7 +16,7 @@ -
    +
    - + diff --git a/site/public/advanced/targets.html b/site/public/advanced/targets.html index 4d79d6c..0d31585 100644 --- a/site/public/advanced/targets.html +++ b/site/public/advanced/targets.html @@ -16,7 +16,7 @@ -
    +
    - + diff --git a/site/public/advanced/volatile.html b/site/public/advanced/volatile.html index a508b26..2177371 100644 --- a/site/public/advanced/volatile.html +++ b/site/public/advanced/volatile.html @@ -16,7 +16,7 @@ -
    +
    - + diff --git a/site/public/download/raz-0.9.0-linux-x86_64.tar.gz b/site/public/download/raz-0.9.0-linux-x86_64.tar.gz new file mode 100644 index 0000000..457b96e Binary files /dev/null and b/site/public/download/raz-0.9.0-linux-x86_64.tar.gz differ diff --git a/site/public/download/raz-0.9.0-linux-x86_64.tar.gz.sha256 b/site/public/download/raz-0.9.0-linux-x86_64.tar.gz.sha256 new file mode 100644 index 0000000..eb385a9 --- /dev/null +++ b/site/public/download/raz-0.9.0-linux-x86_64.tar.gz.sha256 @@ -0,0 +1 @@ +c1387747ef3350efb19b35edf2769612fe323ecb08cff34906065b530fc71a09 raz-0.9.0-linux-x86_64.tar.gz diff --git a/site/public/index.html b/site/public/index.html index abc9d30..3efaeac 100644 --- a/site/public/index.html +++ b/site/public/index.html @@ -16,7 +16,7 @@ -
    +

    raz

    @@ -35,15 +35,15 @@ 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.

    -

    The compiler is one Free Pascal program of about 7,800 lines. It makes +

    The compiler is one Free Pascal program of about 9,100 lines. It makes x86-64 machine code and the ELF file itself, with no assembler or linker, in -one pass, at about a million lines a second.

    +one pass, at about 900,000 lines a second.

    - ~7,800 lines of compiler - ~1M lines compiled a second + ~9,100 lines of compiler + ~900K lines compiled a second static executables, no run time to install - 1 report, ~2,000 lines + 1 report, ~2,100 lines
    @@ -91,7 +91,7 @@
  • Modules with bodies, and generic modules: Map(K, V; hash, eq).
  • ^VOLATILE T and the atomics CAS, XCHG, XADD, FENCE, for devices and lock-free code.
  • extern procedures and variables from C, code procedures in assembly, and SYSCALL.
  • -
  • Threads without C, a library of Out, Str, Fmt, Map, Sort and more, and gdb that knows your lines.
  • +
  • Threads without C, a library of Out, Str, Bytes, Fmt, Map, Sort and more, and gdb that knows your lines.
  • A formatter, a documentation tool, and editor support for vim and emacs.
  • @@ -106,26 +106,25 @@

    The language, in writing

    The language is defined by the report, which is -short on purpose: whatever it doesn’t allow, raz doesn’t have. There -is also a guide to reading the -compiler, file by file.

    +short on purpose: whatever it doesn’t allow, raz doesn’t have.

    Download

    -

    Each release is a tarball with the compiler, raz, and its -library, lib/, which it finds beside itself.

    +

    raz 0.9.0 is a tarball for x86-64 Linux with the compiler, raz, +its library, lib/, which it finds beside itself, and the manual +pages. It needs nothing else installed.

    -
    $ tar xzf raz-*.tar.gz
    -$ ./raz run examples/Hello.raz
    -hello, world
    -

    To build it yourself you need Free Pascal 3.2.2:

    -
    $ apt-get install fp-compiler
    -$ git clone https://github.com/ldiaz94/raz
    -$ cd raz && make && make install    # ~/.local, or PREFIX=/usr/local
    +
    $ tar xzf raz-0.9.0-linux-x86_64.tar.gz
    +$ ln -s $PWD/raz-0.9.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.

    +

    SHA-256 c1387747ef3350efb19b35edf2769612fe323ecb08cff34906065b530fc71a09

    - + diff --git a/site/public/spec.html b/site/public/spec.html index 587bb7f..eb5d4f2 100644 --- a/site/public/spec.html +++ b/site/public/spec.html @@ -16,16 +16,13 @@ -
    +
    -

    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 report defines the language. It is short on purpose. Whatever it -doesn’t allow, raz doesn’t have.

    -

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

    -

    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.

    +

    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 report defines the language. It is short on purpose. Whatever it doesn’t allow, raz doesn’t have.

    +

    This is version 2026-10.19 of the report; section 12 says what each version changed. 2026-10.11 and 2026-10.12 are a thaw the owner chose, for a language anyone can build again. They break programs written for 2026-10.10 and before: for 2026-10.9, say, the report of compiler 0.5.0, the last release before them; and 2026-10.12 breaks code procedures written for 2026-10.11.

    +

    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;
     import Out;
    @@ -67,82 +48,27 @@
     end;
     
     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.

    +

    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.

    -

    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:

    +

    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.

    +

    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 type until var variant VOLATILE while
     xor
    -

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

    -

    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.

    -

    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.

    -

    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.

    -

    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.

    +

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

    +

    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.

    +

    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.

    +

    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.

    +

    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:

    +  -  *  /  &  |  ~  =  #  <  <=  >  >=  :=  :  ;  ,  .  ..  ...  (  )  [  ]  {  }  ^
    -

    | is also what starts an arm of match -(section 7.4); an arm comes where a statement could, never after an -operand, so the two don’t mix.

    +

    | is also what starts an arm of match (section 7.4); an arm comes where a statement could, never after an operand, so the two don’t mix.

    3. Modules

    Module     = "module" ident [ "(" ModParams ")" ] ";"
                  { Import } { Link } [ Check ] { Declaration }
    @@ -152,141 +78,40 @@
     ImportItem = ident [ ":=" ident [ "(" Type { "," Type } ")" ] ] .
     Link       = "link" ( string | "static" ) ";" .
     Check      = "check" "off" ";" .
    -

    A module lives in a file of its own name: module Out is -Out.raz. The name after end repeats the -module’s name.

    -

    Exports. A name declared at the top of a module with -* after it is exported: other modules can use it as -Module.name. Record fields are exported the same way. -Everything else is private to the module. An exported variable can be -read by the modules that import it, but only its own module changes it. -Outside it, the variable is a value, not a variable: nothing that could -write it, or let something else write it, may name it or a field or -element of it. So it can’t be assigned, passed as a var -argument, changed by INC, DEC or -NEW, or given to ADR; an array in it can’t be -sliced, or used where a slice is expected (the silent conversion of an -array, section 5.10), though a slice in it may be sliced, since that -makes a new slice and can’t change the variable; in match, -its arms’ names stand for the fields of a copy. It can be read, copied -and compared, and a copy is the importer’s own. What a pointer or a -slice in it points at is another variable, and isn’t held to this: with -s: []U8 exported, M.s[0] := 0 writes what -M.s points at, not M. A module that means to -share an array exports a pointer to it, or a procedure that returns a -slice of it.

    -

    Imports. import Out; makes -Out’s exports available as Out.x. -import O := Out; uses the name O instead. A -module can’t import itself, directly or through others.

    +

    A module lives in a file of its own name: module Out is Out.raz. The name after end repeats the module’s name.

    +

    Exports. A name declared at the top of a module with * after it is exported: other modules can use it as Module.name. Record fields are exported the same way. Everything else is private to the module. An exported variable can be read by the modules that import it, but only its own module changes it. Outside it, the variable is a value, not a variable: nothing that could write it, or let something else write it, may name it or a field or element of it. So it can’t be assigned, passed as a var argument, changed by INC, DEC or NEW, or given to ADR; an array in it can’t be sliced, or used where a slice is expected (the silent conversion of an array, section 5.10), though a slice in it may be sliced, since that makes a new slice and can’t change the variable; in match, its arms’ names stand for the fields of a copy. It can be read, copied and compared, and a copy is the importer’s own. What a pointer or a slice in it points at is another variable, and isn’t held to this: with s: []U8 exported, M.s[0] := 0 writes what M.s points at, not M. A module that means to share an array exports a pointer to it, or a procedure that returns a slice of it.

    +

    Imports. import Out; makes Out’s exports available as Out.x. import O := Out; uses the name O instead. A module can’t import itself, directly or through others.

    Generic modules take types as parameters:

    module List(T);
     type
         Node* = record next*: ^Node; val*: T; end;
     ...
     end List.
    -

    An import gives the arguments: -import Ints := List(I64);. Each distinct list of arguments -makes one instance: the module compiled with T -standing for I64. Two imports of List(I64), in -any modules, share one instance, its variables and its -ERRORs with it: two lists of arguments are the same when -their types are the same (section 5.10), an alias as what it stands for, -and their procedures are the same procedures. Since every instance is -checked on its own, an operation the argument type doesn’t support -(adding two records, say) is reported as an error in that instance.

    -

    An instance is made where its module is first used, not at the -import: so the arguments may name types the importing module declares -after its imports, as long as they are declared before that first use. -The instance is made before the code of the procedure, or the module -body, that first uses it, and its arguments are read in the scope -there.

    +

    An import gives the arguments: import Ints := List(I64);. Each distinct list of arguments makes one instance: the module compiled with T standing for I64. Two imports of List(I64), in any modules, share one instance, its variables and its ERRORs with it: two lists of arguments are the same when their types are the same (section 5.10), an alias as what it stands for, and their procedures are the same procedures. Since every instance is checked on its own, an operation the argument type doesn’t support (adding two records, say) is reported as an error in that instance.

    +

    An instance is made where its module is first used, not at the import: so the arguments may name types the importing module declares after its imports, as long as they are declared before that first use. The instance is made before the code of the procedure, or the module body, that first uses it, and its arguments are read in the scope there.

    import Table := Map([]U8, Colour, Str.hash, Str.eq);
     
     type Colour = (red, green, blue);
     
     var names: Table.Map;   (* the instance is made here *)
    -

    What a generic module needs to do with its types, beyond moving them -about, it is given as procedures, after the types:

    +

    What a generic module needs to do with its types, beyond moving them about, it is given as procedures, after the types:

    module Map(K, V; hash: proc(k: K): U64; eq: proc(a, b: K): BOOL);
    import Names := Map([]U8, I64, Str.hash, Str.eq);
    -

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

    -

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

    +

    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);
    • -
    • a type of the same kind, and for a record or variant the same -exported fields and cases, with the same types (unexported fields, and -so the size and layout, may differ);
    • +
    • a constant of the same type (its value may differ: a system call number, say);
    • +
    • a type of the same kind, and for a record or variant the same exported fields and cases, with the same types (unexported fields, and so the size and layout, may differ);
    • a variable of the same type;
    • a procedure of the same signature.
    -

    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.

    +

    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.

    4. Declarations

    Declaration = "const" { IdentDef [ ":" Type ] "=" Expr ";" }
                 | "type" { IdentDef "=" Type ";" }
    @@ -295,55 +120,20 @@
                 | ExternDeclaration ";" .
     IdentDef    = ident [ "*" ] .
     IdentList   = IdentDef { "," IdentDef } .
    -

    A name must be declared before it is used, with two exceptions: the -base type of a pointer may name a type declared later in the same -type section (so that two records can point at each other), -and a procedure may be declared forward and defined later -(section 8).

    -

    Constants are evaluated by the compiler. Their -expressions use only literals, other constants, operators, conversions, -SIZE and the LEN of arrays and strings. A -constant is an integer, a real, a BOOL, a name of an -enumeration, a set, a string, an array, a record or an -ERROR. A constant of an integer type wraps as the program -would: U8(250) + 10 is 4. Dividing by zero in a constant is -an error, and so is dividing the smallest value of a signed type by -1, -with div or mod, which stops a program -(section 6.1). A string constant can be indexed and sliced as an array -of U8 is, and its LEN is its length in bytes. -+ joins two string constants into one:

    +

    A name must be declared before it is used, with two exceptions: the base type of a pointer may name a type declared later in the same type section (so that two records can point at each other), and a procedure may be declared forward and defined later (section 8).

    +

    Constants are evaluated by the compiler. Their expressions use only literals, other constants, operators, conversions, SIZE and the LEN of arrays and strings. A constant is an integer, a real, a BOOL, a name of an enumeration, a set, a string, an array, a record or an ERROR. A constant of an integer type wraps as the program would: U8(250) + 10 is 4. Dividing by zero in a constant is an error, and so is dividing the smallest value of a signed type by -1, with div or mod, which stops a program (section 6.1). A string constant can be indexed and sliced as an array of U8 is, and its LEN is its length in bytes. + joins two string constants into one:

    const Text = "the cat";
         Line = Text + "\n";
     ...
     w := Text[4..7];    (* "cat" *)
    -

    A constant with a type is an ERROR (section 5.8), an -array or a record, and the value of an array or record constant is a -literal (section 6.5) of constants. Its elements and fields are -integers, reals, BOOLs, enumerations, sets, -ERRORs, procedures, nil, a string for a -[]U8, an array constant for a slice of its element type, -and arrays and records of these; no variant and no other pointer:

    +

    A constant with a type is an ERROR (section 5.8), an array or a record, and the value of an array or record constant is a literal (section 6.5) of constants. Its elements and fields are integers, reals, BOOLs, enumerations, sets, ERRORs, procedures, nil, a string for a []U8, an array constant for a slice of its element type, and arrays and records of these; no variant and no other pointer:

    const Primes: [5]I64 = [2, 3, 5, 7, 11];
     type Rule = record class: []U8; tag: INT; float: BOOL; end;
     const Rules: [2]Rule = [{class: "firefox", tag: 2}, {class: "mpv", float: true}];
     ...
     p := Primes[i];
    -

    It is used as a variable of that type is, but can’t be changed: an -array constant can be indexed and sliced and its LEN is -n, a record constant’s fields can be read, and either can -be assigned, compared as its type allows, and passed. Its parts are -constant as a string’s bytes are (section 5.10). A part of it isn’t a -constant, even at a constant index.

    -

    Variables of a module live as long as the program; -variables of a procedure live as long as its call. Both start at zero: -every byte of them is zero. So a number starts as 0 -(0.0 for F32 and F64), a -BOOL as false, a pointer, procedure or -ERROR as nil, a slice as the empty slice -(ptr is nil, len is 0), a variant -as its first case with its fields zero, a set as the empty set, and an -enumeration as its first name. No variable is ever read before it has a -value.

    +

    It is used as a variable of that type is, but can’t be changed: an array constant can be indexed and sliced and its LEN is n, a record constant’s fields can be read, and either can be assigned, compared as its type allows, and passed. Its parts are constant as a string’s bytes are (section 5.10). A part of it isn’t a constant, even at a constant index.

    +

    Variables of a module live as long as the program; variables of a procedure live as long as its call. Both start at zero: every byte of them is zero. So a number starts as 0 (0.0 for F32 and F64), a BOOL as false, a pointer, procedure or ERROR as nil, a slice as the empty slice (ptr is nil, len is 0), a variant as its first case with its fields zero, a set as the empty set, and an enumeration as its first name. No variable is ever read before it has a value.

    5. Types

    Type      = QualIdent
               | "[" Expr "]" Type                 (* array *)
    @@ -359,116 +149,68 @@
     QualIdent = [ ident "." ] ident .

    5.1 Basic types

    ----- - + - - + + - + - + - - + + - + - + - +
    Type Size Values
    I8 I16 I32 -I64
    I8 I16 I32 I64 1, 2, 4, 8 signed integers, two’s complement
    INT an address’s: 8 on x86-64 signed, as big as an address
    UINT an address’s unsigned, as big as an address
    U8 U16 U32 -U64
    U8 U16 U32 U64 1, 2, 4, 8 unsigned integers
    BOOL 1 false (0), true (1)
    F32 4 IEEE 754 single precision
    F64 8 IEEE 754 double precision
    -

    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 (section 5.10), but the two don’t mix -in an expression (section 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.

    +

    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 (section 5.10), but the two don’t mix in an expression (section 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

    -

    [n]T is n elements of type T, -one after another. n is a constant greater than zero. -Arrays are values: assigning one copies it.

    +

    [n]T is n elements of type T, one after another. n is a constant greater than zero. Arrays are values: assigning one copies it.

    5.3 Slices

    -

    []T is a view of elements that live elsewhere: a pointer -to the first and a count, two addresses’ worth, 16 bytes on x86-64.

    +

    []T is a view of elements that live elsewhere: a pointer to the first and a count, two addresses’ worth, 16 bytes on x86-64.

    Slice = record ptr: ^T; len: INT; end;    (* its layout *)
    -

    A slice is made from an array (a[2..5], or an array used -where a slice is wanted), from another slice, or from a pointer -(p[0..n]). It doesn’t own what it points at.

    +

    A slice is made from an array (a[2..5], or an array used where a slice is wanted), from another slice, or from a pointer (p[0..n]). It doesn’t own what it points at.

    5.4 Pointers

    -

    ^T is the address of a T, as big as an -INT. nil is the pointer to nothing.

    -

    ^VOLATILE T is the address of a T that -something besides the program may read or change: a device register, -memory shared with another process. Section 7.6 says what that -promises.

    +

    ^T is the address of a T, as big as an INT. nil is the pointer to nothing.

    +

    ^VOLATILE T is the address of a T that something besides the program may read or change: a device register, memory shared with another process. Section 7.6 says what that promises.

    5.5 Records

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

    +

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

    5.6 Variants

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

    type
    @@ -477,110 +219,40 @@
             rect(w, h: F64);
             dot;
         end;
    -

    The case names are declared in the scope around the type, so -circle can be used directly, and as -Shapes.circle from another module if Shape is -exported. A case with fields is built by calling it like a procedure, -circle(2.0); a case without fields is just -dot. The only way to read the fields is match -(section 7.4).

    -

    Layout: an INT tag (0 for the first case, 1 for the -second, and so on), then the space for the fields. Each case’s fields -are laid out in that space as a record’s would be, after the tag, and -the cases share it, so the variant is as big as its largest case needs, -padded to its alignment, the largest of an INT‘s and its -fields’. variant a(x: U8); b(y: I64; z: U8); end is 24 -bytes on x86-64. A variant that starts at zero therefore holds its first -case.

    +

    The case names are declared in the scope around the type, so circle can be used directly, and as Shapes.circle from another module if Shape is exported. A case with fields is built by calling it like a procedure, circle(2.0); a case without fields is just dot. The only way to read the fields is match (section 7.4).

    +

    Layout: an INT tag (0 for the first case, 1 for the second, and so on), then the space for the fields. Each case’s fields are laid out in that space as a record’s would be, after the tag, and the cases share it, so the variant is as big as its largest case needs, padded to its alignment, the largest of an INT‘s and its fields’. variant a(x: U8); b(y: I64; z: U8); end is 24 bytes on x86-64. A variant that starts at zero therefore holds its first case.

    5.7 Enumerations and sets

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

    -

    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.

    +

    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.

    +

    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";
    -

    ERROR is a basic type as big as an address. A value of -it is made only by a constant declared as above, and each such -declaration makes an error different from every other, whatever its -message: two modules that both declare "not found" have two -different errors. A generic module makes its errors once per instance. -nil is no error.

    -

    Errors compare with = and # only, by which -declaration made them, never by their message. MSG(e) is -the message, a []U8; MSG(nil) is -"".

    +

    ERROR is a basic type as big as an address. A value of it is made only by a constant declared as above, and each such declaration makes an error different from every other, whatever its message: two modules that both declare "not found" have two different errors. A generic module makes its errors once per instance. nil is no error.

    +

    Errors compare with = and # only, by which declaration made them, never by their message. MSG(e) is the message, a []U8; MSG(nil) is "".

    proc find*(key: I64): (^Node, ERROR);
     ...
     n, err := Table.find(7);
     if err = Table.NotFound then ... end;

    5.9 Procedure types

    type Compare = proc(a, b: I64): BOOL;
    -

    A value of a procedure type is the address of a procedure with that -signature, as big as an address, or nil. Two signatures are -alike when their parameters have the same types, each var -or not alike, in order, and their results are the same types; the -parameters’ names don’t matter.

    +

    A value of a procedure type is the address of a procedure with that signature, as big as an address, or nil. Two signatures are alike when their parameters have the same types, each var or not alike, in order, and their results are the same types; the parameters’ names don’t matter.

    5.10 Same and assignable

    -

    Two named types are the same only if they are the same declaration. -Two anonymous pointer, array, slice, set or procedure types are the same -if they are built alike: ^I64 is ^I64 wherever -it is written. A record, variant or enumeration, though, is a type of -its own wherever it is written, named or not: two -record x: I64; end are two types. A named and an anonymous -type are the same if the named one is built like the anonymous one, so -that p := ADR(n) works for p: NodePtr with -type NodePtr = ^Node. Sameness doesn’t pass through the -anonymous type: with type P1 = ^Node; P2 = ^Node;, each of -P1 and P2 is the same as ^Node, -but they are two declarations, so not the same as each other.

    -

    A type declared with only a name on the right, -type Count = I64;, is another name for that type, not a new -one.

    -

    A value of type A can be assigned to a variable of type -B (and passed to a parameter of type B, and -returned as a B) if they are the same type, or if:

    +

    Two named types are the same only if they are the same declaration. Two anonymous pointer, array, slice, set or procedure types are the same if they are built alike: ^I64 is ^I64 wherever it is written. A record, variant or enumeration, though, is a type of its own wherever it is written, named or not: two record x: I64; end are two types. A named and an anonymous type are the same if the named one is built like the anonymous one, so that p := ADR(n) works for p: NodePtr with type NodePtr = ^Node. Sameness doesn’t pass through the anonymous type: with type P1 = ^Node; P2 = ^Node;, each of P1 and P2 is the same as ^Node, but they are two declarations, so not the same as each other.

    +

    A type declared with only a name on the right, type Count = I64;, is another name for that type, not a new one.

    +

    A value of type A can be assigned to a variable of type B (and passed to a parameter of type B, and returned as a B) if they are the same type, or if:

      -
    • A is an integer constant whose value fits in the -integer type B;
    • -
    • A is nil and B is a pointer, -procedure or ERROR type;
    • -
    • A is ^T and B is -^VOLATILE T;
    • -
    • 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 an integer constant whose value fits in the integer type B;
    • +
    • A is nil and B is a pointer, procedure or ERROR type;
    • +
    • A is ^T and B is ^VOLATILE T;
    • +
    • 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 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.

    +

    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.

    6. Expressions

    Expr       = Conjunct { "or" Conjunct } .
     Conjunct   = Relation { "and" Relation } .
    @@ -599,344 +271,189 @@
     Designator = QualIdent { Selector } .
     Selector   = "." ident | "^" | "[" Expr [ ".." Expr ] "]"
                | "(" [ Expr { "," Expr } ] ")" .
    -

    The operators bind in the order of the grammar: not and -~ most tightly, then the multiplying operators, then the -adding ones, then the relations, then and, then -or. So a + b * c = d is -(a + (b * c)) = d, x & 0FH = 0 is -(x & 0FH) = 0, and -i < n and a[i] # 0 or done is -((i < n) and (a[i] # 0)) or done. A unary minus applies -to the first term: -a * b is -(a * b).

    -

    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, so -^T(x)^ := v isn’t one.

    +

    The operators bind in the order of the grammar: not and ~ most tightly, then the multiplying operators, then the adding ones, then the relations, then and, then or. So a + b * c = d is (a + (b * c)) = d, x & 0FH = 0 is (x & 0FH) = 0, and i < n and a[i] # 0 or done is ((i < n) and (a[i] # 0)) or done. A unary minus applies to the first term: -a * b is -(a * b).

    +

    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, so ^T(x)^ := v isn’t one.

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

    +

    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.

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

    +

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

    6.3 Reals

    -

    + - * / and the relations work on F32 and -on F64. Both operands have the same type, or one is a real -constant, which takes the other’s type (section 2). The result has that -type: F32 arithmetic is done in single precision, rounded -at each step as C rounds float. A constant expression of -reals is evaluated in double precision, then rounded once to the type it -takes.

    -

    Relations are IEEE 754’s: a NaN is equal to nothing, itself included, -so for a NaN x, x # x is true and every other -relation with it is false. Dividing by zero gives an infinity or a NaN; -arithmetic on reals never stops the program.

    +

    + - * / and the relations work on F32 and on F64. Both operands have the same type, or one is a real constant, which takes the other’s type (section 2). The result has that type: F32 arithmetic is done in single precision, rounded at each step as C rounds float. A constant expression of reals is evaluated in double precision, then rounded once to the type it takes.

    +

    Relations are IEEE 754’s: a NaN is equal to nothing, itself included, so for a NaN x, x # x is true and every other relation with it is false. Dividing by zero gives an infinity or a NaN; arithmetic on reals never stops the program.

    6.4 Pointers

    • p^ is the variable p points at.
    • -
    • p + i and p - i, with i an -integer, move p by i elements: by -i * SIZE(T) bytes for p: ^T.
    • -
    • p - q, with both of the same pointer type, is the -number of elements between them, an INT.
    • -
    • p[i] is (p + i)^. p[lo..hi] -is the slice of the hi - lo elements from -p + lo. Neither is checked against a length, which a -pointer doesn’t have, but a slice of a pointer that runs backwards, -hi < lo, is a failed check (section 6.5). A pointer to -an array isn’t indexed this way, since a step would be a whole array: -its elements are p^[i].
    • -
    • Pointers compare with = # < <= > >= as -unsigned addresses. Procedure values compare with = and -# only.
    • +
    • p + i and p - i, with i an integer, move p by i elements: by i * SIZE(T) bytes for p: ^T.
    • +
    • p - q, with both of the same pointer type, is the number of elements between them, an INT.
    • +
    • p[i] is (p + i)^. p[lo..hi] is the slice of the hi - lo elements from p + lo. Neither is checked against a length, which a pointer doesn’t have, but a slice of a pointer that runs backwards, hi < lo, is a failed check (section 6.5). A pointer to an array isn’t indexed this way, since a step would be a whole array: its elements are p^[i].
    • +
    • Pointers compare with = # < <= > >= as unsigned addresses. Procedure values compare with = and # only.

    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.

    +

    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.

    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.

    -

    Arrays of reals don’t compare this way, since -0.0 = 0.0 -and a NaN is equal to nothing, though their bytes say otherwise; nor do -arrays of records, variants or procedures, nor records and variants -themselves. Write a loop. Ordering strings is the library’s -Str.cmp.

    +

    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.

    +

    Arrays of reals don’t compare this way, since -0.0 = 0.0 and a NaN is equal to nothing, though their bytes say otherwise; nor do arrays of records, variants or procedures, nor records and variants themselves. Write a loop. Ordering strings is the library’s Str.cmp.

    6.6 Enumerations and sets

    -

    Enumerations compare with all six relations, by position, and an -enumeration can be the variable of a for loop and the -expression of a match (section 7.4).

    -

    {red, blue} is a set, of the set type of its names’ -enumeration; {} is the empty set, where the type it must -have is known. On two sets of the same type, + is union, -* intersection and - difference; -= and # compare, and <= and ->= are “is a subset of” and “is a superset of”. -x in s is true if x, a value of -the enumeration, is in the set s.

    +

    Enumerations compare with all six relations, by position, and an enumeration can be the variable of a for loop and the expression of a match (section 7.4).

    +

    {red, blue} is a set, of the set type of its names’ enumeration; {} is the empty set, where the type it must have is known. On two sets of the same type, + is union, * intersection and - difference; = and # compare, and <= and >= are “is a subset of” and “is a superset of”. x in s is true if x, a value of the enumeration, is in the set s.

    6.7 Conversions

    -

    A type name applied like a procedure converts: I32(x), -F64(n), ^Cell(addr). A pointer type written -out uses the ^ form of the grammar: -^VOLATILE U32(0FEE00000H).

    +

    A type name applied like a procedure converts: I32(x), F64(n), ^Cell(addr). A pointer type written out uses the ^ form of the grammar: ^VOLATILE U32(0FEE00000H).

    ----- - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - +
    From To Result
    integer integerthe value cut to the new width, or extended by its sign (signed) or -zeros (unsigned)the value cut to the new width, or extended by its sign (signed) or zeros (unsigned)
    integer F32, F64 the nearest real
    F32, F64 integerrounded toward zero; a NaN, or a real out of the range of -I64, gives the smallest I64, then cutrounded toward zero; a NaN, or a real out of the range of I64, gives the smallest I64, then cut
    F32 F64 the same value
    F64 F32 the nearest F32; too big a value gives an infinity
    enumeration integer its position
    integer enumerationthe 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)
    set integer its bits
    integer set the low bits, as many as the set has
    INT, UINT pointer, procedure the address
    pointer, procedure INT, UINT the address
    pointer, procedure pointer, procedure the same address, seen as the new type
    -

    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. A conversion of a constant is made by the compiler, by the same rules: U8(300) is 44.

    6.8 Built-in procedures

    ---- - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - +
    Call Result
    SIZE(T)the size of type T in bytes, an untyped constant; -T is a type, not a variablethe size of type T in bytes, an untyped constant; T is a type, not a variable
    ADR(x) the address of variable x, a ^T
    LEN(a)the number of elements of an array or a string constant (an untyped -constant) or of a slice (an INT)the number of elements of an array or a string constant (an untyped constant) or of a slice (an INT)
    NEW(p, a)sets p: ^T to a fresh, zeroed T from the -allocator a: ^Mem.Allocator, or to nil if -a has no roomsets p: ^T to a fresh, zeroed T from the allocator a: ^Mem.Allocator, or to nil if a has no room
    MSG(e) the message of the error e, a []U8
    COPY(d, s)copies the elements of s to the start of -d, both arrays or slices of one type T; -LEN(s) must be at most LEN(d)copies the elements of s to the start of d, both arrays or slices of one type T; LEN(s) must be at most LEN(d)
    SYSCALL(n, x1, ..., x6)Linux system call n with up to six arguments, each a -pointer or an integer no wider than INT; the raw result, an -INT (a negative number is -errno)Linux system call n with up to six arguments, each a pointer or an integer no wider than INT; the raw result, an INT (a negative number is -errno)
    INC(v), INC(v, k)adds 1, or k, to the integer variable v; -it wraps, like +adds 1, or k, to the integer variable v; it wraps, like +
    DEC(v), DEC(v, k) subtracts 1, or k, from v
    FENCE a full memory barrier
    CAS(p, old, new)if p^ = old, sets p^ := new and returns -true; atomicallyif p^ = old, sets p^ := new and returns true; atomically
    XCHG(p, x)sets p^ := x and returns the value before, -atomicallysets p^ := x and returns the value before, atomically
    XADD(p, x)adds x to p^ and returns the value before, -atomicallyadds x to p^ and returns the value before, atomically
    ARGC() the number of command line arguments, an INT
    ARGV() the arguments, a ^^U8 (C strings)
    -

    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.

    -

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

    +

    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.

    +

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

    7. Statements

    Statements = { Statement ";" } .
     Statement  = Designator [ ":=" Expr ]
    @@ -955,120 +472,42 @@
                  | Label { "," Label } | "else" ) ":" Statements .
     Label      = Expr [ ".." Expr ] .
     Target     = Designator | "_" .
    -

    Every statement ends in ;, including the ones that end -in end or until.

    +

    Every statement ends in ;, including the ones that end in end or until.

    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.

    +

    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.

    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.

    -

    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.

    +

    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.

    +

    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.

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

    +

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

    7.4 Match

    match s of
     | circle(r):  area := 3.14159 * r * r;
     | 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 on an enumeration works the same way: each arm -names one of the enumeration’s names.

    -

    match on an integer runs the arm whose labels hold its -value:

    +

    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 on an enumeration works the same way: each arm names one of the enumeration’s names.

    +

    match on an integer runs the arm whose labels hold its value:

    match ch of
     | ' ', '\t':      skip := true;
     | '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). 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.

    +

    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.

    -

    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.

    +

    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.

    +

    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 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;
     
    @@ -1095,11 +534,7 @@
     end;
     
     end Head.
    -

    return e; evaluates e before the deferred -statements run. A deferred statement can’t contain return, -break or defer 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 return, break or defer that would leave it. A failed check, Rt.exit and Sys.exit end the program without running the deferred statements still pending.

    8. Procedures

    ProcDeclaration   = "proc" IdentDef Signature ";"
                         ( "forward" | { LocalDeclaration } "begin" Statements "end" [ ident ]
    @@ -1111,20 +546,9 @@
                       | [ ":" Results ] .
     Params            = [ "var" ] ident { "," ident } ":" Type .
     Results           = Type | "(" Type { "," Type } ")" .
    -

    A procedure without parameters may leave out the parentheses, both -where it is declared (proc main*;) and where it is called -(Out.ln). Used without parentheses in an expression, a -procedure is a procedure value, not a call.

    -

    Parameters. A value parameter is a copy: the -procedure may change it, and the caller’s variable stays as it was. A -var parameter is the caller’s variable itself; its argument -must be a variable of exactly the parameter’s type.

    -

    Results. A procedure returns nothing, one value, or -several. A call that returns several values can only stand on the right -of a multiple assignment, alone as a statement, or alone after -return in a procedure whose results are of the same types, -in the same order, which then returns them as they are: -return divmod(n, 2);.

    +

    A procedure without parameters may leave out the parentheses, both where it is declared (proc main*;) and where it is called (Out.ln). Used without parentheses in an expression, a procedure is a procedure value, not a call.

    +

    Parameters. A value parameter is a copy: the procedure may change it, and the caller’s variable stays as it was. A var parameter is the caller’s variable itself; its argument must be a variable of exactly the parameter’s type.

    +

    Results. A procedure returns nothing, one value, or several. A call that returns several values can only stand on the right of a multiple assignment, alone as a statement, or alone after return in a procedure whose results are of the same types, in the same order, which then returns them as they are: return divmod(n, 2);.

    module Divide;
     import Out;
     
    @@ -1141,17 +565,10 @@
     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.

    -

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

    +

    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.

    +

    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:

    +

    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:

    proc rdtsc*: U64;
     code
         rdtsc;
    @@ -1159,24 +576,8 @@
         or rax, rdx;
         ret;
     end rdtsc;
    -

    A label, name:, names the place of the instruction after -it, within the procedure. A constant of the module may stand wherever a -number does. Any bytes may be written with db, as in -db 0FH, 31H;, for an instruction the assembler doesn’t -know.

    -

    It is called like any procedure, with the System V convention: -integer and pointer arguments arrive in rdi, -rsi, rdx, rcx, r8 -and r9, F32 and F64 ones in -xmm0 to xmm7, and the result goes in -rax (and rdx for a second) or -xmm0. Its parameters and results are therefore of the types -C can take (section 9), at most six integer and eight real parameters, -and at most two results. The instructions are the whole procedure, -ret included; they must keep rbx, -rbp, rsp and r12 to -r15 as they found them. The compiler doesn’t look past what -they say.

    +

    A label, name:, names the place of the instruction after it, within the procedure. A constant of the module may stand wherever a number does. Any bytes may be written with db, as in db 0FH, 31H;, for an instruction the assembler doesn’t know.

    +

    It is called like any procedure, with the System V convention: integer and pointer arguments arrive in rdi, rsi, rdx, rcx, r8 and r9, F32 and F64 ones in xmm0 to xmm7, and the result goes in rax (and rdx for a second) or xmm0. Its parameters and results are therefore of the types C can take (section 9), or slices, at most six integer and eight real parameters, and at most two results. A slice is two integers, as System V passes a struct of them: as a parameter its address arrives in one register and its length in the next, the two counting among the six; as the result its address goes in rax and its length in rdx, and it is the only result. The instructions are the whole procedure, ret included; they must keep rbx, rbp, rsp and r12 to r15 as they found them. The compiler doesn’t look past what they say.

    9. Calling C

    ExternDeclaration = "extern" ( "proc" IdentDef Signature
                                  | "var" IdentDef ":" Type ) .
    @@ -1184,27 +585,10 @@ extern proc XOpenDisplay(name: ^U8): ^U8; extern proc printf(format: ^U8; ...): I32; extern var environ: ^^U8; -

    An extern procedure or variable is found by its name in -the C libraries the program links: the C library always, and each -library named by link.

    -

    An extern procedure’s parameters and result are -integers, BOOL, F32, F64, -pointers or procedures; a record goes to C by pointer, never by value. -... accepts any number of further arguments of those types, -and is allowed only in an extern. C takes no -float there, so an F32 given to -... is an error: the program writes F64(x). -Past the parameters, a real constant goes as an F64, an -integer constant as an INT, and a string literal as a -pointer to its bytes followed by a zero byte.

    -

    An extern variable is C’s variable itself: reading it -reads C’s, assigning it writes C’s. It can be of any type, declared as C -declares it, a record laid out as C lays it out (section 5.5); the -compiler can’t check that it is. A C variable that is local to each -thread, such as errno, can’t be reached this way; the C -library has a procedure for it (__errno_location).

    -

    A C union has no raz type. A program reads one as an array of words, -and the member it wants through a pointer conversion:

    +

    An extern procedure or variable is found by its name in the C libraries the program links: the C library always, and each library named by link.

    +

    An extern procedure’s parameters and result are integers, BOOL, F32, F64, pointers or procedures; a record goes to C by pointer, never by value. ... accepts any number of further arguments of those types, and is allowed only in an extern. C takes no float there, so an F32 given to ... is an error: the program writes F64(x). Past the parameters, a real constant goes as an F64, an integer constant as an INT, and a string literal as a pointer to its bytes followed by a zero byte.

    +

    An extern variable is C’s variable itself: reading it reads C’s, assigning it writes C’s. It can be of any type, declared as C declares it, a record laid out as C lays it out (section 5.5); the compiler can’t check that it is. A C variable that is local to each thread, such as errno, can’t be reached this way; the C library has a procedure for it (__errno_location).

    +

    A C union has no raz type. A program reads one as an array of words, and the member it wants through a pointer conversion:

    var ev: [24]I64;                       (* XEvent: 192 bytes *)
     ...
     XNextEvent(dpy, ADR(ev));
    @@ -1212,229 +596,116 @@
         key := ^XKeyEvent(ADR(ev));
         ...
     end;
    -

    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.

    +

    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.

    +

    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.

    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.

    +

    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

    -

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

    +

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

    ---- - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + + + + + - + - + - + - + - + - + - + - + - + - + - +
    Module What
    Rtending the program, exit and atExit; -stop, which ends it with a message; trace, the -calls under way; what the compiler’s checks call when they failending the program, exit and atExit; stop, which ends it with a message; trace, the calls under way; what the compiler’s checks call when they fail
    Syssystem calls: open, openRead, -create, read, write, -seek, close, mmap, -munmap, isTerminal, yield, -exit; files and directories, rename, -remove, removeDir, makeDir, -chmod, symlink, readLink, -info, openDir, nextEntry, -closeDir; the terminal, rawMode, -restoreMode, termSize, ready; the -environment, env, workDir, -setWorkDir; programs, pipes and signals; time, -clock, now, sleep; -random; and sockets. One file per target, and -Sys.raz over the C library for the otherssystem calls: open, openRead, create, read, write, seek, close, mmap, munmap, isTerminal, yield, exit; files and directories, rename, remove, removeDir, makeDir, chmod, symlink, readLink, info, openDir, nextEntry, closeDir; the terminal, rawMode, restoreMode, termSize, ready; the environment, env, workDir, setWorkDir; programs, pipes and signals; time, clock, now, sleep; random; and sockets. One file per target, and Sys.raz over the C library for the others
    Outwriting text and numbers to standard output, buffered; safe to call -from several threadswriting text and numbers to standard output, buffered; safe to call from several threads
    Cthe parts of the C library the others use, and printf, -fflush, stdout, pthread_create; a -program that imports it uses Cthe parts of the C library the others use, and printf, fflush, stdout, pthread_create; a program that imports it uses C
    Locka lock for short sections, for C’s threads and Thread’s -alikea lock for short sections, for C’s threads and Thread’s alike
    Threadthreads for a program without C: spawn, -join, and Mutex; it says -link staticthreads for a program without C: spawn, join, and Mutex; it says link static
    MemAllocator, the interface of every allocator, and pages -from the systemAllocator, the interface of every allocator, and pages from the system
    Heapa general allocator, Heap.heap, safe to call from -several threads; freeing a block twice, or one it never gave out, stops -the programa general allocator, Heap.heap, safe to call from several threads; freeing a block twice, or one it never gave out, stops the program
    Arenaan allocator that frees everything at once; -ADR(arena.base) is its allocatoran allocator that frees everything at once; ADR(arena.base) is its allocator
    Stroperations on []U8 strings: comparing, hashing, -finding, UTF-8, reading a numberoperations on []U8 strings: comparing, hashing, finding, UTF-8, reading a number
    Bytessearches of bytes, many at a time: index, last, count and find in a []U8; one file per target where the target has instructions for it
    Buf a growable byte buffer
    Fmtformatted output: -Fmt.print("{} of {}\n", [Fmt.int(n), Fmt.real(x, 2)]), or -into a Buf with Fmt.writeformatted output: Fmt.print("{} of {}\n", [Fmt.int(n), Fmt.real(x, 2)]), or into a Buf with Fmt.write
    List a generic singly linked list, List(T)
    Map a generic hash map, Map(K, V; hash, eq)
    Sort sorting a slice in place, Sort(T; less)
    Mathroots, powers, logarithms, rounding and trigonometry, and -pi, for F64roots, powers, logarithms, rounding and trigonometry, and pi, for F64
    Files an argument as a string, and a whole file read or written
    Opta command line read through one table, by getopt’s -rules with long options; its help and its mistakesa command line read through one table, by getopt’s rules with long options; its help and its mistakes
    -

    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.

    -

    What follows is each module’s interface, as -tools/Doc.raz prints it from the module’s file; -... stands for fields that are the module’s own. A module’s -main, where it has one, is its test, and is left out -here.

    +

    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.

    +

    What follows is each module’s interface, as tools/Doc.raz prints it from the module’s file; ... stands for fields that are the module’s own. A module’s main, where it has one, is its test, and is left out here.

    module Rt;
     const Full*: ERROR = "too many procedures to run at exit";
     proc atExit*(p: proc): ERROR;   (* p run when the program ends by exit *)
     proc exit*(status: INT);        (* the atExit procedures, the last first, then the end *)
     proc stop*(msg: []U8);          (* msg on standard error, then exit with status 2 *)
     proc trace*;                    (* the calls under way, and their variables, on standard error *)
    -

    Rt also holds what the compiler’s checks call when they -fail, and the handlers of the signals that stop a program (section 10). -exit takes each procedure off the list before it runs it, -so it runs once even if it fails or calls exit itself; in a -program that uses C, it ends through C’s exit, so that C -flushes its buffers too.

    +

    Rt also holds what the compiler’s checks call when they fail, and the handlers of the signals that stop a program (section 10). exit takes each procedure off the list before it runs it, so it runs once even if it fails or calls exit itself; in a program that uses C, it ends through C’s exit, so that C flushes its buffers too.

    module Mem;
     type
         Allocator* = record
    @@ -1458,11 +729,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 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.

    module Lock;
     type Lock* = record ... end;
     proc take*(l: ^Lock);
    @@ -1477,13 +744,7 @@
     proc join*(t: ^Thread);         (* waits for t to end, then frees its stack *)
     proc lock*(m: ^Mutex);
     proc unlock*(m: ^Mutex);
    -

    A Lock is for short sections: a thread that finds it -taken tries again, giving up the processor now and then. A -Mutex sleeps. Each of Thread’s threads runs on -a stack of its own, with a page below it that can’t be touched, so that -running off the stack stops the program. A program that uses C makes its -threads with C’s pthread_create, and so can’t use -Thread.

    +

    A Lock is for short sections: a thread that finds it taken tries again, giving up the processor now and then. A Mutex sleeps. Each of Thread’s threads runs on a stack of its own, with a page below it that can’t be touched, so that running off the stack stops the program. A program that uses C makes its threads with C’s pthread_create, and so can’t use Thread.

    module Out;
     proc str*(s: []U8);
     proc char*(c: U8);
    @@ -1491,14 +752,7 @@
     proc int*(n: I64);               (* n in decimal *)
     proc hex*(n: U64; digits: INT);  (* n in hexadecimal, digits digits at least *)
     proc flush*;
    -

    Out and C’s stdio. Out keeps a buffer -of Sys.outSize bytes, 4 KB on Linux. It writes it out when -it is full, at each line feed when standard output is a terminal, at -Out.flush, and when the program ends by -Rt.exit. A lock keeps what each call writes together when -threads write at once. C’s stdio keeps a buffer of its own -for the same standard output. A program that writes with both flushes -one before writing with the other, or the text comes out of order:

    +

    Out and C’s stdio. Out keeps a buffer of Sys.outSize bytes, 4 KB on Linux. It writes it out when it is full, at each line feed when standard output is a terminal, at Out.flush, and when the program ends by Rt.exit. A lock keeps what each call writes together when threads write at once. C’s stdio keeps a buffer of its own for the same standard output. A program that writes with both flushes one before writing with the other, or the text comes out of order:

    module Both;
     import Out, C;      (* C: printf, fflush and C's FILE *stdout *)
     
    @@ -1512,10 +766,7 @@
     end;
     
     end Both.
    -

    Sys gives every target the same procedures, so that -a program that needs only these runs wherever raz does: through system -calls on Linux, through the C library elsewhere. A result that can fail -is a number, minus an errno, as on Linux; 0 is success.

    +

    Sys gives every target the same procedures, so that a program that needs only these runs wherever raz does: through system calls on Linux, through the C library elsewhere. A result that can fail is a number, minus an errno, as on Linux; 0 is success.

    module Sys;
     const
         stdin* = 0; stdout* = 1; stderr* = 2;
    @@ -1616,127 +867,18 @@
     proc listenTcp*(addr: []U8; port: INT): INT;
     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.

    -

    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.

    -

    p.group puts the program in a process group, the -programs that a shell’s job is made of: -1 makes it the first of a new -group, whose number is its process id, and the other programs of the job -join that number. The terminal gives its keys, and the signals of Ctrl-C -and Ctrl-Z, to one group, the one in its foreground: -p.foreground puts the program’s group there before it -starts, and foreground puts any group there, as a shell -does to take the terminal back. setGroup moves a program to -a group, as the shell does for each program it starts, for whichever of -the two runs first; a shell runs in a group of its own, -setGroup(0, 0).

    -

    wait waits for the program pid to change, -or for any of this program’s if pid is -1, and says which -one, and how: exited, with its exit status; -killed, with the number of the signal that ended it; or -stopped, by Ctrl-Z or a signal, with the signal’s number. -Without block it doesn’t wait, and is 0 and -running if no program changed. A program that has nothing -to wait for is -10 (ECHILD). kill sends a program a signal, -sigTerm to end it; to a group, if pid is minus -its number.

    -

    Signals. catch takes the signals -sigs away from what they would do, ending the program most -of them, and gives an fd that is ready to read when one comes, so that a -program waits for signals with ready and -readyOf as it waits for keys or a server. -caught gives each signal that came, in turn. A later -catch adds to the signals caught and gives the same fd. -Catching sigKill or sigStop, or the signals -Rt reports, SIGSEGV and SIGFPE, is -22 (EINVAL). -ignore makes a signal do nothing, as a shell ignores -sigTtou so that it can take its terminal back, and -ignore(sig, false) gives it back what it does at first. A -program that spawn starts begins with neither.

    -

    Time. clock is for measuring how long -something takes: it never goes back, and says nothing of the date. -now is the date and time, which a person or the network may -set back. sleep waits ms milliseconds.

    -

    Sockets. connect is for talking to a -server on the same machine, an X server at -/tmp/.X11-unix/X0 say; connectTcp for one -across the network, given its address as numbers, -"127.0.0.1" or "::1": turning a name into an -address is a library’s work over these. connectUdp gives a -socket of datagrams, each send one message to that address -and each read one message from it, as a program asks a name -server. What a socket receives comes by read, what it sends -goes by send, and close ends it. -send is write for a socket, except when the -other end has closed it: write would stop the program with -the signal SIGPIPE, where send returns -32 (EPIPE), so that -a program learns its server has gone and can end as it wants. -listen and listenTcp are the other side: a -server’s socket, on path, which must not be there yet, or -on port at addr, "0.0.0.0" or -"::" for every address the machine has; accept -gives each connection that comes, as a socket of its own.

    -

    readyOf waits on several file descriptors at once, as a -program does that listens to a server and a terminal both; a descriptor -at its end, or failed, counts as ready, since a read of it won’t wait. -It looks at the first 64 of fds, and connect -and listen take a path of at most 107 bytes, as -struct sockaddr_un holds; a longer one is -36 -(ENAMETOOLONG).

    -

    A program that both reads from a descriptor and writes much to it, as -a terminal writes what is pasted to its program while it reads what the -program writes back, must not wait on either: the program may be waiting -for its own writes to be read. setBlocking(fd, false) has a -read or a write on fd that would wait return -11 (EAGAIN) -at once, a write having written what there was room for; -readyFor waits, as readyOf does, for something -to read on any of reads or for room to write on any of -writes. A descriptor in both is given once, when it is -ready for either; the 64 it looks at are reads, then -writes.

    +

    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.

    +

    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.

    +

    p.group puts the program in a process group, the programs that a shell’s job is made of: -1 makes it the first of a new group, whose number is its process id, and the other programs of the job join that number. The terminal gives its keys, and the signals of Ctrl-C and Ctrl-Z, to one group, the one in its foreground: p.foreground puts the program’s group there before it starts, and foreground puts any group there, as a shell does to take the terminal back. setGroup moves a program to a group, as the shell does for each program it starts, for whichever of the two runs first; a shell runs in a group of its own, setGroup(0, 0).

    +

    wait waits for the program pid to change, or for any of this program’s if pid is -1, and says which one, and how: exited, with its exit status; killed, with the number of the signal that ended it; or stopped, by Ctrl-Z or a signal, with the signal’s number. Without block it doesn’t wait, and is 0 and running if no program changed. A program that has nothing to wait for is -10 (ECHILD). kill sends a program a signal, sigTerm to end it; to a group, if pid is minus its number.

    +

    Signals. catch takes the signals sigs away from what they would do, ending the program most of them, and gives an fd that is ready to read when one comes, so that a program waits for signals with ready and readyOf as it waits for keys or a server. caught gives each signal that came, in turn. A later catch adds to the signals caught and gives the same fd. Catching sigKill or sigStop, or the signals Rt reports, SIGSEGV and SIGFPE, is -22 (EINVAL). ignore makes a signal do nothing, as a shell ignores sigTtou so that it can take its terminal back, and ignore(sig, false) gives it back what it does at first. A program that spawn starts begins with neither.

    +

    Time. clock is for measuring how long something takes: it never goes back, and says nothing of the date. now is the date and time, which a person or the network may set back. sleep waits ms milliseconds.

    +

    Sockets. connect is for talking to a server on the same machine, an X server at /tmp/.X11-unix/X0 say; connectTcp for one across the network, given its address as numbers, "127.0.0.1" or "::1": turning a name into an address is a library’s work over these. connectUdp gives a socket of datagrams, each send one message to that address and each read one message from it, as a program asks a name server. What a socket receives comes by read, what it sends goes by send, and close ends it. send is write for a socket, except when the other end has closed it: write would stop the program with the signal SIGPIPE, where send returns -32 (EPIPE), so that a program learns its server has gone and can end as it wants. listen and listenTcp are the other side: a server’s socket, on path, which must not be there yet, or on port at addr, "0.0.0.0" or "::" for every address the machine has; accept gives each connection that comes, as a socket of its own.

    +

    readyOf waits on several file descriptors at once, as a program does that listens to a server and a terminal both; a descriptor at its end, or failed, counts as ready, since a read of it won’t wait. It looks at the first 64 of fds, and connect and listen take a path of at most 107 bytes, as struct sockaddr_un holds; a longer one is -36 (ENAMETOOLONG).

    +

    A program that both reads from a descriptor and writes much to it, as a terminal writes what is pasted to its program while it reads what the program writes back, must not wait on either: the program may be waiting for its own writes to be read. setBlocking(fd, false) has a read or a write on fd that would wait return -11 (EAGAIN) at once, a write having written what there was room for; readyFor waits, as readyOf does, for something to read on any of reads or for room to write on any of writes. A descriptor in both is given once, when it is ready for either; the 64 it looks at are reads, then writes.

    Strings, buffers and collections.

    module Str;
     proc cmp*(a, b: []U8): INT;           (* -1, 0 or 1 as a sorts before, with or after b, byte by byte *)
    @@ -1815,49 +957,19 @@
     proc acos*(x: F64): F64;              (* from 0 to pi *)
     proc atan*(x: F64): F64;              (* from -pi/2 to pi/2 *)
     proc atan2*(y, x: F64): F64;          (* the angle of (x, y) from the x axis, from -pi to pi *)
    -

    A Buf, a List and a Map take -their memory from the allocator init gives them. -Fmt’s format takes the next argument at each -{}; {{ and }} stand for -{ and }. A Map hashes and -compares its keys with the procedures it is given: -import Count := Map([]U8, INT, Str.hash, Str.eq);.

    -

    Str reads and writes UTF-8. encode writes a -character, of at most 10FFFFH, in one to four bytes; a number that isn’t -one becomes FFFDH, the character that stands for a wrong one. -decode reads the first character of s, and -gives FFFDH and 1 for a byte that doesn’t start one rightly, and 0 and 0 -for an empty s. toInt reads a decimal number, -with a - or + before it if any, and nothing -else.

    -

    le and be read an unsigned number of up to -8 bytes in a fixed order, little-endian or big-endian, whatever the -machine’s own, and putLE and putBE write one; -more than 8 bytes stops the program. They are how a file format or a -network protocol is read and written:

    +

    A Buf, a List and a Map take their memory from the allocator init gives them. Fmt’s format takes the next argument at each {}; {{ and }} stand for { and }. A Map hashes and compares its keys with the procedures it is given: import Count := Map([]U8, INT, Str.hash, Str.eq);.

    +

    Str reads and writes UTF-8. encode writes a character, of at most 10FFFFH, in one to four bytes; a number that isn’t one becomes FFFDH, the character that stands for a wrong one. decode reads the first character of s, and gives FFFDH and 1 for a byte that doesn’t start one rightly, and 0 and 0 for an empty s. toInt reads a decimal number, with a - or + before it if any, and nothing else.

    +

    le and be read an unsigned number of up to 8 bytes in a fixed order, little-endian or big-endian, whatever the machine’s own, and putLE and putBE write one; more than 8 bytes stops the program. They are how a file format or a network protocol is read and written:

    len := U32(Str.le(header[4..8]));
     Str.putBE(packet[0..2], U64(port));
    -

    Map.next walks a map: from 0, it gives the next entry -and the number to pass for the one after it, and -1 when there are no -more. A walk sees each entry once if the map doesn’t change during -it:

    +

    Map.next walks a map: from 0, it gives the next entry and the number to pass for the one after it, and -1 when there are no more. A walk sees each entry once if the map doesn’t change during it:

    i, k, v := Names.next(ADR(names), 0);
     while i >= 0 do
         Fmt.print("{} is {}\n", [Fmt.str(k), Fmt.int(v)]);
         i, k, v := Names.next(ADR(names), i);
     end;
    -

    Sort.sort puts s in the order -less gives, in place, without memory of its own, in time -n log n at most; two elements equal by less -may change places. Math’s procedures are as C’s -math.h has them, to within the last bit or so. -Fmt.real(x, places) writes x with -places digits after the point, at most 9, rounded to the -nearest; from 1e15 on, with an exponent, as 1.50e17; and -nan, inf and -inf as -themselves.

    -

    Files and Opt are what most programs need of their -command line.

    +

    Sort.sort puts s in the order less gives, in place, without memory of its own, in time n log n at most; two elements equal by less may change places. Math’s procedures are as C’s math.h has them, to within the last bit or so. Fmt.real(x, places) writes x with places digits after the point, at most 9, rounded to the nearest; from 1e15 on, with an exponent, as 1.50e17; and nan, inf and -inf as themselves.

    +

    Files and Opt are what most programs need of their command line.

    module Files;
     proc arg*(i: INT): []U8;                     (* argument i; 0 is the program's name *)
     proc read*(path: []U8; b: ^Buf.Buf): BOOL;   (* the whole file added to b *)
    @@ -1882,24 +994,8 @@
     proc scope*(p: ^Parser; name: []U8);              (* subcommand name's options, from the word after it *)
     proc number*(p: ^Parser; lo, hi: I64): I64;       (* the value just read, a number from lo to hi *)
     proc fail*(p: ^Parser; text: []U8);               (* the program's own mistake *)
    -

    Opt reads a command line by the rules of the C library’s -getopt, with GNU’s long options, so that a program’s -options behave as every other Unix program’s. The program describes -itself once, in a table of Rows: its synopsis lines, its -subcommands and its options. The help and the messages for mistakes are -made from the table, so they can’t drift from it; the program’s test of -p.letter is the only other place an option appears. The -parser is a record the program owns, and the table a slice it keeps as -long as the parser: a literal written in the call to init -lives as long as the procedure that makes it.

    -

    A row’s scope is "" for the program itself, -or a subcommand’s name: "start", or -"remote.add" for a subcommand of remote. An -option has a letter, a long name, or both. One -with a long name only has a key of its own below '!' for a -letter, so that the program can tell it from the others. With a -value, the name the help and the messages give it, the -option takes a value; with "" it is a flag.

    +

    Opt reads a command line by the rules of the C library’s getopt, with GNU’s long options, so that a program’s options behave as every other Unix program’s. The program describes itself once, in a table of Rows: its synopsis lines, its subcommands and its options. The help and the messages for mistakes are made from the table, so they can’t drift from it; the program’s test of p.letter is the only other place an option appears. The parser is a record the program owns, and the table a slice it keeps as long as the parser: a literal written in the call to init lives as long as the procedure that makes it.

    +

    A row’s scope is "" for the program itself, or a subcommand’s name: "start", or "remote.add" for a subcommand of remote. An option has a letter, a long name, or both. One with a long name only has a key of its own below '!' for a letter, so that the program can tell it from the others. With a value, the name the help and the messages give it, the option takes a value; with "" it is a flag.

    const wait = 1;     (* the key of --wait, which has no letter *)
     ...
     Opt.init(ADR(p), "keep", [
    @@ -1923,250 +1019,65 @@
     job, ok := Opt.operand(ADR(p));

    The rules are getopt’s:

      -
    • Flags may share a dash: -lw is -l -w. A -letter’s value is the rest of its word, -bdev, or the whole -next word, -b dev, even one that starts with a dash or is -empty; in a group, the first letter that takes a value takes the rest, --qn12.
    • -
    • A long option is written in full, with its value after a -= or in the next word: --bar=dev, ---bar dev. An abbreviation is unknown, not guessed, so that -adding an option never breaks a script. A value given to a flag, ---follow=x, is a mistake.
    • -
    • -- ends the options, and isn’t an operand; -- alone is one. The options end at the first operand, so in -keep start site python -m http.server the -m -is python’s.
    • -
    • Each scope has its own options. An option given twice is read -twice.
    • +
    • Flags may share a dash: -lw is -l -w. A letter’s value is the rest of its word, -bdev, or the whole next word, -b dev, even one that starts with a dash or is empty; in a group, the first letter that takes a value takes the rest, -qn12.
    • +
    • A long option is written in full, with its value after a = or in the next word: --bar=dev, --bar dev. An abbreviation is unknown, not guessed, so that adding an option never breaks a script. A value given to a flag, --follow=x, is a mistake.
    • +
    • -- ends the options, and isn’t an operand; - alone is one. The options end at the first operand, so in keep start site python -m http.server the -m is python’s.
    • +
    • Each scope has its own options. An option given twice is read twice.
    -

    number reads the value as Str.toInt does. -operand reads what options are left first, and the program -doesn’t see them.

    -

    -h or --help among a scope’s options prints -its help on standard output and ends the program with status 0. -init and scope answer it, looking through the -scope’s options before next gives one, so that the program -has done nothing yet: keep -v -h -x prints the help, and -the program never sees -v, nor the mistake. The help is the -scope’s synopsis lines, a blank line, and its subcommands, its options -and the help itself, each with its line of help:

    +

    number reads the value as Str.toInt does. operand reads what options are left first, and the program doesn’t see them.

    +

    -h or --help among a scope’s options prints its help on standard output and ends the program with status 0. init and scope answer it, looking through the scope’s options before next gives one, so that the program has done nothing yet: keep -v -h -x prints the help, and the program never sees -v, nor the mistake. The help is the scope’s synopsis lines, a blank line, and its subcommands, its options and the help itself, each with its line of help:

    usage: keep start [-b label] name command [argument ...]
     
       -b, --bar label   show the job in the bar as label
       -h, --help        print this and exit
    -

    A scope with several synopsis lines has the others indented under the -first; one with none, usage: and its words, as -usage: keep start.

    -

    A mistake on the command line is a sentence on standard error, the -program’s name first, then the scope’s synopsis lines, as the help -begins, and status 2:

    +

    A scope with several synopsis lines has the others indented under the first; one with none, usage: and its words, as usage: keep start.

    +

    A mistake on the command line is a sentence on standard error, the program’s name first, then the scope’s synopsis lines, as the help begins, and status 2:

    keep: unknown option -x
     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.

    +

    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.

    +

    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.

      -
    • 2026-10.0. The first numbered version: the language -of compiler 0.3.0.
    • -
    • 2026-10.1. Messages: every error in a run, warnings -of what is never used and -Werror (section 10); failed -checks say what failed, and signals say where (sections 6.5 and -10).
    • -
    • 2026-10.2. Sys gains files and -directories, the terminal, and the environment (section 11).
    • -
    • 2026-10.3. return f(x); passes on the -several results of f (sections 7.3 and 8). -and, or and not are for -BOOLs, and bind below the relations; &, -| and ~ are the operators on bits, and -xor is for integers only (sections 2 and 6). Arrays and -slices of integers, BOOLs, enumerations, sets and pointers -compare with =, by code where the comparison stands, not by -a call into Rt (section 6.5). A generic module’s instance -is made where it is first used, so its arguments may name types declared -after the imports (section 3).
    • -
    • 2026-10.4. Sys gains a connection to a -Unix socket, waiting on several files at once, pseudo-terminals, and -starting, waiting for and stopping programs (section 11).
    • -
    • 2026-10.5. A module with files in more than one of -the directories searched is an error, unless the first is a link to one -of the others (section 3).
    • -
    • 2026-10.6. Sys.Info says whether the -path is a regular file, and whether it is a symbolic link (section -11).
    • -
    • 2026-10.7. Sys.send writes to a socket -without SIGPIPE (section 11).
    • -
    • 2026-10.8. Sys.workDir returns the -directory, with no var parameter (section 11).
    • -
    • 2026-10.9. The language is frozen (the start of the -report). Sys gains opening a file for any use, seeking, -links, permissions and times; pipes, process groups and the terminal’s -foreground; signals caught on a file descriptor; clocks, sleeping and -random bytes; and network sockets. Sys.spawn takes a -Program, and Sys.wait says which program -changed and how. Str gains UTF-8 and reading a number, -Map removing and walking, Fmt reals; -Sort, Math, Files and -Opt are new (section 11).
    • -
    • 2026-10.10. Said at last: what the compiler did and -the report didn’t say, all through; what an implementation chooses, and -the core every target has (appendix A); the whole grammar (appendix B); -the library’s module names are kept for it (section 3); a record, -variant or enumeration is a type of its own wherever it is written -(section 5.10); a nil pointer, a division by zero and a -stack overflow stop the program on every target (section 10); byte order -is the target’s, and Str reads and writes a fixed one -(sections 5.5 and 11); Out’s buffer is -Sys.outSize bytes (section 11). Changed: a field of a -packed record that may be misaligned has no address and no volatile -access (section 5.5). Mended: arithmetic on untyped constants that -overflows is an error (section 2); a slice of a pointer can’t run -backwards (section 6.4). Ordinary accesses are no longer promised to be -made exactly as written, only volatile and atomic ones (section -7.6).
    • -
    • 2026-10.11. INT and UINT, -as big as an address, are the integers of lengths, slices, pointer -differences, pointer conversions, SYSCALL and -ARGC; SIZE and a constant LEN are -untyped; INT widens silently to I64 and -UINT to U64, but neither mixes with them in an -expression or a for (sections 5, 6.1 and 7.2); -Mem.Allocator takes INT sizes. Pointers, -procedures, ERRORs, slices and variants’ tags are sized by -the address, and basic types aligned as the target’s C aligns them -(section 5). Reals are a target’s to have or not (section 5.1). An -exported variable can’t be changed, passed by var or -addressed outside its module, nor an array in it sliced (section 3). -check off; leaves a module’s index and slice checks out -(sections 3, 6.4 and 6.5). An index of any integer type is checked by -its value (6.5). A shift counts modulo its operand’s width, and the -smallest value of every signed type divided by -1 stops the program -(6.1). Writing a string’s bytes isn’t defined (5.10). The atomic -built-ins work on INT, UINT and pointers -(6.8). An integer constant past an extern’s parameters goes as an -INT (9). An importer depends only on a module’s interface, -so a module can be compiled on its own; whether it is, and into what, is -the implementation’s (sections 3 and 10; appendix A). The library takes -and gives INT for lengths, counts, descriptors, process ids -and statuses, main’s and Rt.exit’s among them, -and I32 for a character; I64 stays for what -may pass an INT on a small target: a file’s size and -position, times, and numbers read from text (section 11). An array -constant has a type and is used as a variable that can’t be changed; -+ joins string constants (section 4). match -takes an integer, with constants and ranges as labels (7.4).
    • -
    • 2026-10.12. A code procedure is written in the -target’s assembly language, not as bytes (section 8; appendix A). A -program that stops says the calls under way and their variables, and -Rt.trace says them on demand (sections 10 and 11).
    • -
    • 2026-10.13. Sys gains writing without -waiting, and waiting for room to write (section 11).
    • -
    • 2026-10.14. The blank, _, drops a -value or one of several results (section 7.1); a call that drops a -result is warned of (section 10).
    • -
    • 2026-10.15. Math gains -pow, ceil, round, -log2, log10, tan, -asin, acos and atan; -Sys gains space (section 11).
    • -
    • 2026-10.16. Record constants, and array and record -constants of records, strings, procedures and more (section 4); -Str gains copy (section 11).
    • -
    • 2026-10.17. COPY copies the elements -of one array or slice to another as a block (section 6.8).
    • +
    • 2026-10.0. The first numbered version: the language of compiler 0.3.0.
    • +
    • 2026-10.1. Messages: every error in a run, warnings of what is never used and -Werror (section 10); failed checks say what failed, and signals say where (sections 6.5 and 10).
    • +
    • 2026-10.2. Sys gains files and directories, the terminal, and the environment (section 11).
    • +
    • 2026-10.3. return f(x); passes on the several results of f (sections 7.3 and 8). and, or and not are for BOOLs, and bind below the relations; &, | and ~ are the operators on bits, and xor is for integers only (sections 2 and 6). Arrays and slices of integers, BOOLs, enumerations, sets and pointers compare with =, by code where the comparison stands, not by a call into Rt (section 6.5). A generic module’s instance is made where it is first used, so its arguments may name types declared after the imports (section 3).
    • +
    • 2026-10.4. Sys gains a connection to a Unix socket, waiting on several files at once, pseudo-terminals, and starting, waiting for and stopping programs (section 11).
    • +
    • 2026-10.5. A module with files in more than one of the directories searched is an error, unless the first is a link to one of the others (section 3).
    • +
    • 2026-10.6. Sys.Info says whether the path is a regular file, and whether it is a symbolic link (section 11).
    • +
    • 2026-10.7. Sys.send writes to a socket without SIGPIPE (section 11).
    • +
    • 2026-10.8. Sys.workDir returns the directory, with no var parameter (section 11).
    • +
    • 2026-10.9. The language is frozen (the start of the report). Sys gains opening a file for any use, seeking, links, permissions and times; pipes, process groups and the terminal’s foreground; signals caught on a file descriptor; clocks, sleeping and random bytes; and network sockets. Sys.spawn takes a Program, and Sys.wait says which program changed and how. Str gains UTF-8 and reading a number, Map removing and walking, Fmt reals; Sort, Math, Files and Opt are new (section 11).
    • +
    • 2026-10.10. Said at last: what the compiler did and the report didn’t say, all through; what an implementation chooses, and the core every target has (appendix A); the whole grammar (appendix B); the library’s module names are kept for it (section 3); a record, variant or enumeration is a type of its own wherever it is written (section 5.10); a nil pointer, a division by zero and a stack overflow stop the program on every target (section 10); byte order is the target’s, and Str reads and writes a fixed one (sections 5.5 and 11); Out’s buffer is Sys.outSize bytes (section 11). Changed: a field of a packed record that may be misaligned has no address and no volatile access (section 5.5). Mended: arithmetic on untyped constants that overflows is an error (section 2); a slice of a pointer can’t run backwards (section 6.4). Ordinary accesses are no longer promised to be made exactly as written, only volatile and atomic ones (section 7.6).
    • +
    • 2026-10.11. INT and UINT, as big as an address, are the integers of lengths, slices, pointer differences, pointer conversions, SYSCALL and ARGC; SIZE and a constant LEN are untyped; INT widens silently to I64 and UINT to U64, but neither mixes with them in an expression or a for (sections 5, 6.1 and 7.2); Mem.Allocator takes INT sizes. Pointers, procedures, ERRORs, slices and variants’ tags are sized by the address, and basic types aligned as the target’s C aligns them (section 5). Reals are a target’s to have or not (section 5.1). An exported variable can’t be changed, passed by var or addressed outside its module, nor an array in it sliced (section 3). check off; leaves a module’s index and slice checks out (sections 3, 6.4 and 6.5). An index of any integer type is checked by its value (6.5). A shift counts modulo its operand’s width, and the smallest value of every signed type divided by -1 stops the program (6.1). Writing a string’s bytes isn’t defined (5.10). The atomic built-ins work on INT, UINT and pointers (6.8). An integer constant past an extern’s parameters goes as an INT (9). An importer depends only on a module’s interface, so a module can be compiled on its own; whether it is, and into what, is the implementation’s (sections 3 and 10; appendix A). The library takes and gives INT for lengths, counts, descriptors, process ids and statuses, main’s and Rt.exit’s among them, and I32 for a character; I64 stays for what may pass an INT on a small target: a file’s size and position, times, and numbers read from text (section 11). An array constant has a type and is used as a variable that can’t be changed; + joins string constants (section 4). match takes an integer, with constants and ranges as labels (7.4).
    • +
    • 2026-10.12. A code procedure is written in the target’s assembly language, not as bytes (section 8; appendix A). A program that stops says the calls under way and their variables, and Rt.trace says them on demand (sections 10 and 11).
    • +
    • 2026-10.13. Sys gains writing without waiting, and waiting for room to write (section 11).
    • +
    • 2026-10.14. The blank, _, drops a value or one of several results (section 7.1); a call that drops a result is warned of (section 10).
    • +
    • 2026-10.15. Math gains pow, ceil, round, log2, log10, tan, asin, acos and atan; Sys gains space (section 11).
    • +
    • 2026-10.16. Record constants, and array and record constants of records, strings, procedures and more (section 4); Str gains copy (section 11).
    • +
    • 2026-10.17. COPY copies the elements of one array or slice to another as a block (section 6.8).
    • +
    • 2026-10.18. A code procedure takes and returns slices (section 8).
    • +
    • 2026-10.19. The library gains Bytes (section 11).
    -

    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.

    +

    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 target. Which machines and systems it compiles -for, and the names of their files (linux-x86_64, section -3); for each, the size of an address, and so of INT, and -whether it has reals.
    • -
    • Separate compilation. Whether modules are compiled -on their own, and if so into what: the object file, its format, the form -of the code in it, when one is out of date, and how an instance is named -so that the program keeps one (section 10). This compiler compiles every -module of a program together, and writes no object files.
    • -
    • Atomics. How CAS, XCHG -and XADD are made sequentially consistent on a machine -without atomic instructions (section 6.8): on one with a single -processor, by holding off interrupts while they run, for one.
    • -
    • The calling convention. On x86-64 Linux it is -System V (sections 8 and 9); elsewhere it is the C library’s own, so -that extern procedures and callbacks work. How a procedure -returns several results, and how its frame is laid out, are the -implementation’s.
    • -
    • What is the target’s. Code procedures (section 8) -hold the target’s machine code, written in its assembly language, and -exist only where the implementation says so; SYSCALL exists -only on Linux targets (section 6.8). A record’s layout is the target’s C -layout (section 5.5), and the order of a value’s bytes is the target’s -(little-endian on x86-64).
    • -
    • The assembly language. How a code procedure’s -instructions are written (section 8). On x86-64 it is Intel’s syntax, as -NASM writes it: the destination first; registers by name -(rax, eax, al, -xmm0); memory as -[base + index * scale + disp], with byte, -word, dword or qword before it -where no register says the size; lock before an -instruction. Which instructions it knows is the implementation’s; -db gives any others.
    • -
    • Sizes in the library. How many bytes -Out keeps before it writes them, Sys.outSize -(section 11): 4 KB on Linux, fewer on a small machine.
    • -
    • The executable. Its format, and the names and line -numbers it carries for a debugger (section 10).
    • -
    • How a failure is caught. A nil -pointer, a division by zero or a stack overflow may be caught by the -machine or by checks in the compiled code; either way the program stops -with its message (section 10).
    • -
    • Messages and warnings. The text of the compiler’s -messages, how many errors it reports before it stops, and which warnings -it gives (section 10). A program that is an error in this report is one -in every implementation; the words that say so are free.
    • -
    • The command line. How the compiler is run, its -options, and where its library lives (sections 1 and 3).
    • +
    • The target. Which machines and systems it compiles for, and the names of their files (linux-x86_64, section 3); for each, the size of an address, and so of INT, and whether it has reals.
    • +
    • Separate compilation. Whether modules are compiled on their own, and if so into what: the object file, its format, the form of the code in it, when one is out of date, and how an instance is named so that the program keeps one (section 10). This compiler compiles every module of a program together, and writes no object files.
    • +
    • Atomics. How CAS, XCHG and XADD are made sequentially consistent on a machine without atomic instructions (section 6.8): on one with a single processor, by holding off interrupts while they run, for one.
    • +
    • The calling convention. On x86-64 Linux it is System V (sections 8 and 9); elsewhere it is the C library’s own, so that extern procedures and callbacks work. How a procedure returns several results, and how its frame is laid out, are the implementation’s.
    • +
    • What is the target’s. Code procedures (section 8) hold the target’s machine code, written in its assembly language, and exist only where the implementation says so; SYSCALL exists only on Linux targets (section 6.8). A record’s layout is the target’s C layout (section 5.5), and the order of a value’s bytes is the target’s (little-endian on x86-64).
    • +
    • The assembly language. How a code procedure’s instructions are written (section 8). On x86-64 it is Intel’s syntax, as NASM writes it: the destination first; registers by name (rax, eax, al, xmm0); memory as [base + index * scale + disp], with byte, word, dword or qword before it where no register says the size; lock before an instruction. Which instructions it knows is the implementation’s; db gives any others.
    • +
    • Sizes in the library. How many bytes Out keeps before it writes them, Sys.outSize (section 11): 4 KB on Linux, fewer on a small machine.
    • +
    • The executable. Its format, and the names and line numbers it carries for a debugger (section 10).
    • +
    • How a failure is caught. A nil pointer, a division by zero or a stack overflow may be caught by the machine or by checks in the compiled code; either way the program stops with its message (section 10).
    • +
    • Messages and warnings. The text of the compiler’s messages, how many errors it reports before it stops, and which warnings it gives (section 10). A program that is an error in this report is one in every implementation; the words that say so are free.
    • +
    • 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 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.

    +

    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" .
    @@ -2258,16 +1169,9 @@
     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).

    +

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

    - + diff --git a/site/public/style.css b/site/public/style.css index 0f4832c..2b1abd2 100644 --- a/site/public/style.css +++ b/site/public/style.css @@ -26,7 +26,6 @@ font: 700 20px ui-monospace, monospace; color: var(--accent); } header nav .mark img { display: block; } header nav a[aria-current] { border-bottom: 2px solid var(--accent); } -header nav .repo { margin-left: auto; color: var(--muted); } main { padding-top: 28px; padding-bottom: 48px; } footer { color: var(--muted); font-size: 14px; padding-bottom: 32px; font-family: system-ui, sans-serif; } h1 { overflow-wrap: anywhere; font-size: 2.1rem; line-height: 1.2; margin: .2em 0 .5em; } @@ -51,7 +50,7 @@ .hero { padding: 24px 0 8px; } .hero h1 { font-size: 3.4rem; font-family: ui-monospace, monospace; color: var(--accent); margin: 0; } .hero .tag { font-size: 1.35rem; margin: .2em 0 1em; } -.hero .cta { display: flex; flex-wrap: wrap; gap: 10px; margin: 1em 0; font-family: system-ui, sans-serif; } +.cta { display: flex; flex-wrap: wrap; gap: 10px; margin: 1em 0; font-family: system-ui, sans-serif; } .btn { display: inline-block; padding: 9px 18px; border-radius: 6px; text-decoration: none; border: 1px solid var(--accent); color: var(--accent); font-weight: 600; font-size: 15px; } .btn.primary { background: var(--accent); color: var(--bg); } @@ -85,10 +84,14 @@ /* 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; display: block; overflow-x: auto; font-size: 15px; } -.spec td, .spec th { border-bottom: 1px solid var(--line); padding: 3px 10px; text-align: left; } +.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; + text-align: left; vertical-align: top; } +.spec th { border-bottom-width: 2px; } +@media (min-width: 40rem) { .spec td:first-child { white-space: nowrap; } } .spec nav#TOC ul { list-style: none; padding-left: 1em; } /* a shell session */ pre.term::before { content: "terminal"; } pre .cmd { color: #8fd18f; } +.sha code { font-size: 13px; word-break: break-all; } diff --git a/site/public/tour/c.html b/site/public/tour/c.html index 2e7c644..ee3d498 100644 --- a/site/public/tour/c.html +++ b/site/public/tour/c.html @@ -16,7 +16,7 @@ -
    +
    - + diff --git a/site/public/tour/checks.html b/site/public/tour/checks.html index cfffc4d..ce0624f 100644 --- a/site/public/tour/checks.html +++ b/site/public/tour/checks.html @@ -16,7 +16,7 @@ -
    +
    - + diff --git a/site/public/tour/defer.html b/site/public/tour/defer.html index e35a693..a62bf72 100644 --- a/site/public/tour/defer.html +++ b/site/public/tour/defer.html @@ -16,7 +16,7 @@ -
    +
    - + diff --git a/site/public/tour/errors.html b/site/public/tour/errors.html index 33c96d5..98a30ba 100644 --- a/site/public/tour/errors.html +++ b/site/public/tour/errors.html @@ -16,7 +16,7 @@ -
    +
    - + diff --git a/site/public/tour/generics.html b/site/public/tour/generics.html index 768b135..26e8d83 100644 --- a/site/public/tour/generics.html +++ b/site/public/tour/generics.html @@ -16,7 +16,7 @@ -
    +
    - + diff --git a/site/public/tour/hello.html b/site/public/tour/hello.html index c5084b9..1870137 100644 --- a/site/public/tour/hello.html +++ b/site/public/tour/hello.html @@ -16,7 +16,7 @@ -
    +
    - + diff --git a/site/public/tour/index.html b/site/public/tour/index.html index 661ad69..1b2dc0b 100644 --- a/site/public/tour/index.html +++ b/site/public/tour/index.html @@ -16,7 +16,7 @@ -
    +

    Raz, Set, Go

    A tour of raz, in the spirit of A Tour of Go. Each lesson is one @@ -49,6 +49,6 @@

  • Threads Native threads without C, atomics, a mutex, and why the counter needs both.
  • - + diff --git a/site/public/tour/integers.html b/site/public/tour/integers.html index 17d75e4..e9cc550 100644 --- a/site/public/tour/integers.html +++ b/site/public/tour/integers.html @@ -16,7 +16,7 @@ -
    +
    - + diff --git a/site/public/tour/memory.html b/site/public/tour/memory.html index ca0c62b..8954289 100644 --- a/site/public/tour/memory.html +++ b/site/public/tour/memory.html @@ -16,7 +16,7 @@ -
    +
    - + diff --git a/site/public/tour/modules.html b/site/public/tour/modules.html index 26d313e..fc91246 100644 --- a/site/public/tour/modules.html +++ b/site/public/tour/modules.html @@ -16,7 +16,7 @@ -
    +
    - + diff --git a/site/public/tour/procedures.html b/site/public/tour/procedures.html index d1ec52a..aaa707f 100644 --- a/site/public/tour/procedures.html +++ b/site/public/tour/procedures.html @@ -16,7 +16,7 @@ -
    +
    - + diff --git a/site/public/tour/records.html b/site/public/tour/records.html index 8784513..b770b35 100644 --- a/site/public/tour/records.html +++ b/site/public/tour/records.html @@ -16,7 +16,7 @@ -
    +
    -
    raz is under the ISC license. Source.
    +
    raz is under the ISC license.
    diff --git a/site/public/tour/slices.html b/site/public/tour/slices.html index 3223df2..60ebe3b 100644 --- a/site/public/tour/slices.html +++ b/site/public/tour/slices.html @@ -16,7 +16,7 @@ -
    +
    - + diff --git a/site/public/tour/threads.html b/site/public/tour/threads.html index b87a0b1..eb14157 100644 --- a/site/public/tour/threads.html +++ b/site/public/tour/threads.html @@ -16,7 +16,7 @@ -
    +
    - + diff --git a/site/public/tour/values.html b/site/public/tour/values.html index 7c12fff..e05ba13 100644 --- a/site/public/tour/values.html +++ b/site/public/tour/values.html @@ -16,7 +16,7 @@ -
    +
    - + diff --git a/site/public/tour/variants.html b/site/public/tour/variants.html index 31e7126..f6bd0ce 100644 --- a/site/public/tour/variants.html +++ b/site/public/tour/variants.html @@ -16,7 +16,7 @@ -
    +
    - + diff --git a/site/style.css b/site/style.css index 0f4832c..2b1abd2 100644 --- a/site/style.css +++ b/site/style.css @@ -26,7 +26,6 @@ font: 700 20px ui-monospace, monospace; color: var(--accent); } header nav .mark img { display: block; } header nav a[aria-current] { border-bottom: 2px solid var(--accent); } -header nav .repo { margin-left: auto; color: var(--muted); } main { padding-top: 28px; padding-bottom: 48px; } footer { color: var(--muted); font-size: 14px; padding-bottom: 32px; font-family: system-ui, sans-serif; } h1 { overflow-wrap: anywhere; font-size: 2.1rem; line-height: 1.2; margin: .2em 0 .5em; } @@ -51,7 +50,7 @@ .hero { padding: 24px 0 8px; } .hero h1 { font-size: 3.4rem; font-family: ui-monospace, monospace; color: var(--accent); margin: 0; } .hero .tag { font-size: 1.35rem; margin: .2em 0 1em; } -.hero .cta { display: flex; flex-wrap: wrap; gap: 10px; margin: 1em 0; font-family: system-ui, sans-serif; } +.cta { display: flex; flex-wrap: wrap; gap: 10px; margin: 1em 0; font-family: system-ui, sans-serif; } .btn { display: inline-block; padding: 9px 18px; border-radius: 6px; text-decoration: none; border: 1px solid var(--accent); color: var(--accent); font-weight: 600; font-size: 15px; } .btn.primary { background: var(--accent); color: var(--bg); } @@ -85,10 +84,14 @@ /* 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; display: block; overflow-x: auto; font-size: 15px; } -.spec td, .spec th { border-bottom: 1px solid var(--line); padding: 3px 10px; text-align: left; } +.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; + text-align: left; vertical-align: top; } +.spec th { border-bottom-width: 2px; } +@media (min-width: 40rem) { .spec td:first-child { white-space: nowrap; } } .spec nav#TOC ul { list-style: none; padding-left: 1em; } /* a shell session */ pre.term::before { content: "terminal"; } pre .cmd { color: #8fd18f; } +.sha code { font-size: 13px; word-break: break-all; }