raz / commit 3b490ea8

commit
3b490ea830bfb7b36a31615f7aacd7ecafa8916d
author
Luis <42945842+ldiaz94@users.noreply.github.com>
date
parent
0442dd12
AGENTS.md for contributors and their tools; CLAUDE.md local and ignored

- AGENTS.md: what to read, build and check, tests, what a patch keeps
- CLAUDE.md held owner-only process, history and private paths

patch · log

3 files changed, +400 -521

.gitignore (history) modified +2 -0

@@ -10,3 +10,5 @@
1010 !/test/*/mods/
1111 !/test/*/lib/
1212 .claude/worktrees/
13+# the owner's agent notes, local only; AGENTS.md is the shared part
14+/CLAUDE.md

AGENTS.md (history) added +398 -0

@@ -0,0 +1,398 @@
1+# Working on raz
2+
3+This file is for whoever prepares a defect fix or a documentation fix
4+for raz, a person or the AI tool helping them. `CONTRIBUTING.md` says
5+how one is offered: through a GitHub issue, never a pull request, with
6+a `Signed-off-by:` line, and with you answering for every line a tool
7+wrote.
8+
9+## Read first
10+
11+- `doc/raz.md`, the report, volume 1: it defines the language.
12+- `doc/raz-lib.md`, volume 2: the library.
13+- `doc/compiler.md`, the guide to the compiler, file by file, and,
14+ under "This compiler's choices", what the report leaves to an
15+ implementation.
16+- `STANDARDS.md`: how raz is written here.
17+- `doc/report-history.md`, what each version of the report changed;
18+ `PLAN.md`, what is left before 1.0.
19+
20+## Build and check
21+
22+ make raz # the compiler, ./raz, built from src/ by the release BOOT names; its library is lib/
23+ make check # every example and test against its expected output
24+ make fmt # lib/, examples/, tools/, site/, src/ and src/test/ are formatted
25+ make bench # must report at least 400,000 lines a second
26+ make prev-bench # the compiler's speed against BOOT's: more than a tenth slower fails
27+ make fixpoint # BOOT's release builds src, that builds src, that again: the last two agree
28+ make loc # lines of the compiler, by rloc; the last, code, is the budget
29+ make kernels # test/bench's kernels against FPC -O2's twins (needs fp-compiler)
30+ make gdb # gdb stops at a line of a test and names it
31+ make stress # 40,000 native threads; make check runs a small version
32+ make alpine # test/libc in an Alpine container, over musl (docker)
33+ make pdf # the report as PDF
34+ make install # raz on PATH (PREFIX=..., ~/.local by default); make uninstall
35+
36+On a Mac (docker needed):
37+
38+ make docker-check # make check in a linux/amd64 container; under Rosetta it skips 9 tests, each saying why
39+ make mac-check # on Apple Silicon: test/mac and conform/run cross-compiled in the container, run natively, and lldb
40+ make lldb # gdb's test, for lldb, on a program made for darwin-arm64
41+
42+`make check` also runs `tools/Doc.raz` and `tools/Pretty.raz`, the
43+report's whole examples, the tutorial's (`doc/raz-tutorial.7`, each
44+against the output the page shows after it, its status in `test/man`),
45+each library module's own `main` (its test), and the vim and emacs
46+support headless where they are installed (`vim`, `emacs-nox`): each
47+example must indent back exactly as written.
48+
49+`test/libc` runs its programs over `lib/Sys.raz`, the C one, through a
50+link in its `mods`; `make check` runs them again with `-libc musl`
51+where musl's loader is installed (`musl`, `musl-tools`), and compares
52+`tools/cabi.c`'s output, with `cc` and `musl-gcc`, with
53+`lib/CAbi.linux-x86_64.raz`, which is never edited by hand.
54+
55+`fpc` is needed only for `make kernels`; `rloc` only for `make loc`.
56+
57+## Tests
58+
59+The conformance suite, `conform/`, holds what any implementation must
60+do; `test/` holds what is this compiler's alone: its messages, its
61+limits, its target. A test goes in `conform/` when the report alone
62+fixes its output and status, and keeps to the language and the library
63+a target can't leave out. `conform/check.sh` and `test/check.sh` say
64+how each is laid out.
65+
66+- `test/run/X.raz` with `X.expect` (standard output), and optional
67+ `X.status`, `X.stderr` and `X.args`; modules they import in
68+ `test/run/mods`.
69+- `test/err/X.raz` must fail to compile with the text in `X.err` (all
70+ of standard error), given the compiler options in `X.args` if there
71+ is one.
72+- `test/msg` holds this compiler's `X.stderr` and `X.err` for the
73+ programs in `conform/`.
74+- `test/pretty/X.raz` must format to `X.expect`.
75+- `examples/` works the same way. Examples, `test/libc`, the tools and
76+ the library's tests are compiled with `-Werror`: no warnings.
77+- A test or example without `.expect` is only compiled
78+ (`examples/Window.raz` needs a display).
79+
80+## What a patch must keep
81+
82+- **BOOT.** `src/`, the compiler, is raz, built by the release the file
83+ `BOOT` names, by its tag and its tarball's SHA-256. `src/boot.sh`
84+ fetches that tarball into `build/boot/`, checks the sum and puts its
85+ `raz` there with today's `lib/` beside it. So `src/`, and the modules
86+ of `lib/` it imports, use nothing that release doesn't know.
87+ `lib/Sys.raz` and `CAbi` are read for an interface check when BOOT's
88+ release builds `src/`, so they keep to its language too.
89+- **Checks.** `make check` and `make fmt` pass; the fixpoint holds.
90+- **Budget.** At most 18,000 lines of code in `src/` (blank and comment
91+ lines not counted, as `make loc` counts them; the compiler is about
92+ 16,700 now).
93+- **Speed.** At least 400,000 lines of raz a second (`make bench`), and
94+ no more than a tenth slower than BOOT's release (`make prev-bench`).
95+- **The report** stays under 40 pages as `make pdf` renders it.
96+- **Clarity first**, before speed and size: the compiler must be plain
97+ code that a beginner can follow. Each unit opens with what it is,
98+ what it depends on and what it leaves out; comments say why, most of
99+ all where the code is obscure or needs a compiler writer's knowledge.
100+ Every rewrite of the code the compiler makes is explained where it is
101+ done, with the code before and after, and in `doc/compiler.md`.
102+- **Parameters** (`STANDARDS.md`): a value, `var`, `const`, or, only
103+ when it is kept, a pointer; no `ADR` where `var` serves.
104+- **The guide stays true.** The parser reaches the machine only through
105+ `Gen` (`src/Gen.x86_64.raz`; `src/Gen.arm64.raz` for darwin-arm64),
106+ and the executable's format only through `Exe` (`src/Exe.linux.raz`,
107+ `src/Exe.darwin.raz`). When the compiler changes, keep
108+ `doc/compiler.md`'s table of lines and its routine names true. The
109+ arm64 back end is built only into a compiler for darwin-arm64
110+ (`src/cross.sh`); a change must leave x86-64's output as it was
111+ unless it means to change it.
112+- **Documentation** matches the report's plain, short prose.
113+
114+`src/` has one module to a unit of the Pascal compiler it was ported
115+from, with the same names. That compiler, the seed, built `src/` up to
116+v0.19.0 and is in git at that tag (`seed/`); a comment in `src/` that
117+names "the seed" means it. Each release since was built by the one
118+before it.
119+
120+`sbcl/` is an example, not part of the build: a second compiler, in
121+Common Lisp, written from the report alone and kept as a reference
122+(`sbcl/README.md`).
123+
124+## The freeze
125+
126+The language is frozen. It changes only to mend a defect: the compiler
127+or the library doing other than the report says. The library's core
128+(appendix A) changes only to mend a defect or plug a very big gap; the
129+rest of the library grows only conservatively, by what breaks no
130+program. Proposals and new features aren't taken, and a wish isn't
131+recorded.
132+
133+That a word is reserved, however common (`code`, `to`, `packed`,
134+`forward`, `set`, ...), and that module names share one space with the
135+library's (report 3, "Names are flat"), so that a program's module may
136+clash with one of the library's, are settled. Don't raise them, as a
137+defect, a proposal or an awkwardness, in raz or in a program written
138+in it: a name that is taken is renamed.
139+
140+## Readings of the report already taken
141+
142+These are how the compiler behaves, and a fix keeps them. Where one
143+names registers or instructions, it describes the x86-64 back end.
144+
145+- A named and an anonymous type built alike are the same; `type A = B`
146+ is an alias. A hex literal above high(I64) is a `U64`.
147+- `p^.f` and `p^[i]` are explicit; `p[i]` on a pointer to an array is
148+ an error. A statement starts with a name, so `^T(x)^ := v` isn't one.
149+- A `BOOL` converts to every integer type, 0 or 1, in `convert`'s
150+ integer branch with no code of its own, as a `BOOL`'s value is
151+ already 0 or 1; of a constant it folds. No integer to `BOOL`: the
152+ error's help says `x # 0`.
153+- `for`: the step is a constant; the loop never steps past the limit,
154+ so it can't wrap; afterwards the variable holds the last value it
155+ took; the body may assign it.
156+- Two results that are each a single value of a word at most, not a
157+ real, come back in rax and rdx, and so does a slice, as from a code
158+ procedure; other several results, and records, through a hidden
159+ pointer.
160+- `NEW(p, a)` requires `a: ^Mem.Allocator` and calls its `alloc`
161+ field: the one library type the compiler knows by name. `Rt.fail` is
162+ found by name too.
163+- A set literal takes its type from its first name when nothing else
164+ gives it; `{}` needs a known type. String constants can be indexed
165+ and sliced.
166+- A deferred statement's frame slots stay reserved for the rest of its
167+ procedure.
168+- A generic instance first used in a procedure, or in the module's
169+ body, is made before that code begins: `instancesFor` reads ahead
170+ for the import's name, since code can't be compiled inside other
171+ code. Its arguments are read then, in the scope there.
172+- A program uses C if a module it uses (not one read only for an
173+ interface check) has an `extern` or a `link` of a library. `static`
174+ in `link static;` is not a reserved word. It is linked against
175+ glibc, or musl (`/lib/ld-musl-x86_64.so.1`, needing `libc.so`) by
176+ `-libc musl` or on a machine with musl's loader and not glibc's.
177+- `Sys` gives minus Linux's errnos on every target; `Sys.raz` maps the
178+ C library's through `CAbi.errnos`.
179+- C symbols are reached through quadwords the loader fills in
180+ (GLOB_DAT), with no PLT; the executable exports nothing. In a C
181+ program the entry point stores C's `exit` in `Rt.cExit`, found by
182+ name like `Rt.exit`, before any module body runs; and, if the
183+ program has `Thread`, `pthread_create` and `pthread_join` in
184+ `Thread.cCreate` and `Thread.cJoin`, so that `Thread` makes C's
185+ threads there and serves programs with C and without.
186+- Past an extern's parameters, a string goes as a C string and an
187+ integer constant as an `INT`.
188+- A real constant is held as an F64; one typed `F32` holds a value an
189+ F32 can hold (report 2). An `F32` in a register is its low 32 bits;
190+ the upper ones are left as they fall.
191+- `Heap` and `Out` lock with `Lock`, a spinlock that yields, since
192+ they serve C's threads and `Thread`'s alike; `Thread.Mutex` is a
193+ futex.
194+- A failed check says what failed and with what values, at the place
195+ of the offending expression. A signal is told at the place of the
196+ statement it stopped in, or of the procedure for a stack overflow in
197+ its prologue, and the program ends by `Rt.exit(2)`, after its
198+ `atExit` procedures, as a failed check does (a fault inside `Out`'s
199+ or `Heap`'s lock would hang there). The handlers run on a stack of
200+ their own: `Rt`'s for the main thread, and one in each `Thread`
201+ thread's mapping, made by clone or by C. Threads a program makes
202+ with `pthread_create` itself have none, so a stack overflow in one
203+ still ends the program by the signal with no message.
204+- The smallest value of a signed type divided by -1 stops the program
205+ (SIGFPE), as 6.1 says, `mod` as `div`; for a type narrower than 64
206+ bits the code makes the division fault, as the machine wouldn't. In
207+ a constant it is an error, as dividing by zero is.
208+- `INT` widens to `I64` (and `UINT` to `U64`) wherever its value goes
209+ to one: assigned, passed, returned, in `a, b := f(x)` and
210+ `return f(x)`, a `for`'s bounds, `INC`/`DEC`'s step, and where it
211+ meets an `I64` in an operator (5.10 and 6.1). Never to a `U64`, nor
212+ an `I64` back to an `INT`.
213+- `U8`, `I8` and `I16` widen to `INT`, `U8` and `U16` to `UINT`, one
214+ step only (a `U8` into an `I64` is written), and not in
215+ `return f(x)`. An operator's result on them (`made`) doesn't widen;
216+ a conversion's does, `U8(a + b)` too.
217+- A view, `v.(T)`, is `v`'s item with `T` for its type: nothing is
218+ copied. A variable kept in a register goes to memory for it, as for
219+ `ADR`. Another module's variable may be viewed, and not written. A
220+ view that runs past its end fails as kind 7 of `Rt.fail`.
221+- A returned slice of the frame (7.3) is caught by `Item.frame`, which
222+ sees only the expression: a slice held first in a local slice
223+ variable or a record, stored, or come back from a call, isn't, and
224+ is left undefined (10).
225+- An empty slice constant, `const E: []T = [];`, is 16 zero bytes in
226+ read-only data, read as an array constant is; `LEN` of it is no
227+ constant. A constant's slice part takes `[]`, names a constant
228+ whole, of any module, by its type, not its text, and takes an array
229+ literal, an array constant of its own in a chunk with no name,
230+ nested to any depth. An `ERROR` constant given another takes its
231+ chunk: the same error.
232+- An array a call returns, or a record or variant holding one, and a
233+ `const` parameter's temporary holding one, is a slot of the
234+ procedure (8: `Sym.holdsArray`, `allocPerm`): a slice of it may be
235+ kept to the end of the procedure, and returning it is caught only as
236+ 7.3 catches a slice of the frame.
237+- `Buf.add`, `str` and `spare`, and `Vec`'s growing, stop the program
238+ when the allocator has no room; `room` asks first.
239+- `Sys.handle`'s handler only notes the signal, with `XCHG`; it is
240+ installed without `SA_RESTART`, so a call it breaks into is -4,
241+ which `Out` and `Files` try again. Over C, `ready` and `readyFor` try
242+ `poll` again after EINTR only when no signal `handle` took broke in.
243+- An enumeration's name shared in its scope with another
244+ enumeration's is written with its type; shared with anything else,
245+ the name alone is that other declaration. A `match` arm on an
246+ enumeration or a variant (7.4) takes a case alone, found among the
247+ matched type's own whatever the scope holds, or qualified as
248+ anywhere else (`Kind.done`, `Xml.done`, `Xml.Kind.done`), read by
249+ `qualIdent`; a qualified case of another type is an error naming
250+ both.
251+- `Width` follows glibc's `wcwidth` but gives a control 0, and 0 to
252+ the format characters glibc counts as 1 (Egyptian hieroglyph
253+ controls, interlinear annotation), but for the prepended
254+ concatenation marks.
255+- A pointer's base, and a procedure type's parameter or result (4 and
256+ 5.9), may name a type declared later in its `type` section, if the
257+ name is a bare one that nothing in scope declares yet (`[]Later` or
258+ `[2]Later` doesn't wait): a placeholder of form `fNone` stands for
259+ it until the section's end (`laterType`, `resolveLaters`), which
260+ lays several results out again. A procedure type outside a `type`
261+ section, a variable's, waits for nothing.
262+- An `extern` module variable is read-only for an importer, as the
263+ report says of every exported variable (3).
264+- Warnings come only for a module with no errors. A procedure naming
265+ itself doesn't use it; a type named by a pointer, or by a procedure
266+ type's parameter or result, in its own declaration does. An
267+ enumeration's names are never warned of, nor a generic module's
268+ parameters; a generic module is warned of in its first instance
269+ only. Assigning a variable whole (`x :=`, `a, b :=`) doesn't read
270+ it; anything else does.
271+- A `const` parameter is a `var` one never changed: passed by address
272+ always, its `Obj` `isVar` and `isConst`, an item of it `ro`. A slice
273+ of its array may be made, to read; through it the caller's array may
274+ be written, which the report says (8). An argument that isn't a
275+ variable, or is a packed field, a view or volatile, goes in a
276+ temporary of the statement. `match` on a `const` parameter or a
277+ constant gives names that are only read. Procedure types compare
278+ `const` as `var`. It is unused if never read, as a value parameter.
279+- A variant in a constant must be typed; `const D = dot;` is an error
280+ that says to write its type. Its case is read by name (`constCase`).
281+- The library takes a `var` for what it changes and `const` for a
282+ record or array it only reads. `src/` takes an `Item` as `const`
283+ only where profiling shows a gain, on the paths every compile goes
284+ through; the routines that word an error take a value. (A `Map`
285+ passed as a value, four words, made a loop of `get` half again as
286+ slow as `const`.) A trace shows no `var` or `const` parameter.
287+ `Fmt`'s `format` and `put` keep `^Buf.Buf`, since `nil` is standard
288+ output there.
289+- `PTR(s)` is a slice's first word, read with no check; of an array or
290+ a string constant, its address, refused wherever a slice of all of
291+ it is (a packed record's misaligned field, a view, through
292+ `^VOLATILE`, another module's array). `PTR("")` is the string's
293+ place in read-only data, not `nil`; an empty slice cut from another
294+ keeps its place. `PTR([])` is an error, since `[]` has no type
295+ there, and its help says it would be `nil`. A slice where its
296+ element's pointer is wanted, and a pointer where a slice is, are
297+ errors whose help names `PTR(s)` and `LEN(s)`, or `p[0..n]`.
298+- `CAS(v, old, new)`, `XCHG(v, x)` and `XADD(v, x)` take a variable,
299+ whose address is pushed as `ADR`'s is (`atomic`); a local named in
300+ one is kept out of a register, as for `ADR` (`chooseRegs`). A
301+ pointer that isn't a variable, `ADR(x)`, is refused with help, and
302+ so is a pointer variable, `XADD(p, 1)`, whose help says `p^`.
303+- `import SYSTEM` binds to `Sym.system`, no file, whose scope holds
304+ `ADR`, `PTR`, `SYSCALL` and `ARGV`; it is never warned of as unused,
305+ and an alias is refused. What it fences (`Item.needSystem`,
306+ `doc/compiler.md`) is refused elsewhere: `extern`, `link`, code
307+ procedures and `check off;` are said and read on, so one missing
308+ import is one error.
309+- `[]const T` is a slice type with `rdonly` set: not the same as
310+ `[]T`, which goes into it with no code (`coerce`), never back (help
311+ says why). An element read through one has the item's `elemRo`,
312+ which `notReadOnly` refuses, so every write route (`:=`, `INC`, a
313+ `var` argument, `ADR`, a view) is caught in one place; `COPY` and
314+ `FILL` refuse one as their destination (`destSlice`); a slice of
315+ one, or of an array read through one or of another module's array,
316+ is one (`slice`); `BYTES` of one is a `[]const U8`; `match` on an
317+ element gives names only read. A string literal (`tConstBytes` where
318+ indexed), a constant's slice (`ofConst`), `MSG` and a slice of a
319+ `const` parameter's array are `[]const`; a constant's slice part
320+ must be declared `[]const`.
321+- A procedure or a global in a code procedure (8) is found by
322+ `Parse.asmName`, beside `asmConst`, after the procedure's labels,
323+ which `X64.findLabels` enters first: a label wins wherever it is
324+ written. `call p` and `jmp p` are E8 and E9 with a fixup, `[v]`
325+ rip-relative, as ordinary code's; `[v]` stands alone (`[g + 8]` is
326+ an error), a label is only for a jump, and C's names are refused,
327+ their chunk holding C's address. A variable another module exports
328+ may be written through `lea`: its type isn't checked. A code
329+ procedure's body has a scope of its own, so a name not yet declared
330+ is poison there only.
331+- The limits (10): one count, `Parse.nest`, of statements, expressions
332+ and types nested, to 256; 1024 values waiting in one expression
333+ (`Gen.MaxStack`), past which the compile ends; the other limits are
334+ `Parse`'s constants, listed in `doc/compiler.md` under "This
335+ compiler's choices".
336+- `ROL(x, n)` and `ROR(x, n)` are done at `x`'s own width,
337+ `rol al, cl` for a `U8`, with no mask of the count: x86 takes it
338+ modulo 32 or 64, and a byte's or a word's rotation goes round modulo
339+ 8 or 16 itself. A negative count is taken modulo the width as a
340+ shift's is, `n & (w - 1)`: `ROL(x, -1)` is `ROR(x, 1)`. The result
341+ is a built-in's, not an operator's, and widens (`made` is false). Of
342+ two constants they fold, in a constant too.
343+- `ABS(x)` is of `x`'s type and widens (`made` is false). A signed
344+ integer's is `mov rax, r; neg r; cmovs r, rax`, then cut to a narrow
345+ width as `neg` is, so the smallest value gives itself with no check,
346+ as `-x` does; an unsigned one's is no code; a real's is `btr` of its
347+ sign bit in rax, as `neg`'s `btc`. Of a constant it folds, a real's
348+ top bit cleared; of the smallest untyped constant it is `neg`'s
349+ error, "too big for I64". A string is refused as no number.
350+- `MIN(T)` and `MAX(T)` are untyped constants, but `MAX(U64)` and
351+ `MAX(UINT)`, above `high(I64)`, keep their type, as a hex literal
352+ above it is a `U64`. A `T` not an integer type is an error; `MAX(x)`
353+ of a variable is "x isn't a type".
354+- `CLZ(x)`, `CTZ(x)` and `POPCOUNT(x)` give an `INT`, a constant of
355+ one when `x` is. They use only baseline x86-64, no `lzcnt`, `tzcnt`
356+ or `popcnt`: `bsr` or `bsf` on all 64 bits (a narrow value's upper
357+ ones are zero), with `jnz` past setting the count of 0 to the width;
358+ `POPCOUNT` by `Bytes.count`'s sums of two, four and eight bits and a
359+ multiply by `0101...H`, in rax and rdx. A set's `POPCOUNT` counts its
360+ bits the same way.
361+- `SIZE(T.f)` and `OFFSET(T, f)`: the type is read by `parseType`,
362+ where a name before a `.` must be a module's, so `M.T` is read whole
363+ and a `.` past the type is a field's, `SIZE(M.T.f)` too. `T` must be
364+ a record type (a variant is refused, with help); a path `a.b` is
365+ refused, its help naming `a`'s type.
366+- `BYTES(x)`: of a slice, its `PTR` and `LEN * SIZE(T)`, with no check
367+ of what holds the slice (a `const` one, another module's, a field of
368+ a packed record), as for `PTR`; of anything else, a variable's
369+ address and size, refused, as `ADR` refuses, for what is only read,
370+ and, beyond `ADR`, for a volatile variable; a constant of any kind
371+ is no variable. `T` is refused by the view's `notPlain`. The result
372+ keeps `x`'s `frame`, so the bytes of a local are caught by
373+ `notOfFrame` as far as a slice of it is.
374+- `FILL(d, x)` takes `d` as `COPY` does (`destSlice`), then `x` as
375+ `:=` would, with `:=`'s messages, read once before any element is
376+ written. A scalar element of 1, 2, 4 or 8 bytes is stored from
377+ `rax`, a real's bits as an integer's: by a store each into an array
378+ of 16 elements or fewer, else by a loop for fewer than 16 at run
379+ time and `rep stos` of its width from 16 up. A constant zero into an
380+ array is `zeroBytes`, as `NEW`'s zeroing is; into a slice it is
381+ stored as any scalar, which is as fast. Another element is copied
382+ into `d[0]` and forward from there by `rep movsb`. A record literal
383+ of zeros isn't seen as a zero. A const parameter's or another
384+ module's array, as `d`, says why it can't be changed, for `COPY`
385+ too. `seqSlice` copies no slice that is a temporary already (a slice
386+ just cut): nothing `s` or `x` does can change it.
387+- A call of a procedure whose body is only `return e`, with no locals,
388+ a single value its result and no `try` in `e`, is made in place
389+ (`Parse.inlined`): the arguments read and converted as for a call,
390+ each once and in order, into temporaries the parameters are named as
391+ (a `var` or `const` one, a record or an array, by the address the
392+ call would pass), then `e` read again in its own module's scope,
393+ with that module's checks. Another module's procedure and a generic
394+ instance's too; not one already being made in place, nor a call
395+ through a procedure value. The procedure has no frame: it is in
396+ neither the trap report's calls nor gdb's backtrace; a failed check
397+ in `e` is told at `e`'s line, a signal at the caller's statement. A
398+ test that wants its frame calls it through a procedure value.

CLAUDE.md deleted +0 -521

@@ -1,521 +0,0 @@
1-# Working on raz
2-
3-Read `doc/raz.md` (the language report, volume 1) and
4-`doc/compiler.md` (the guide to the compiler) first; `doc/raz-lib.md`
5-is volume 2, the library, `doc/report-history.md` what each version of
6-the report changed, and `PLAN.md` what is left before 1.0. The report
7-defines the language.
8-
9-## Setup and checks
10-
11- make raz # the compiler, ./raz, built from src/ by the release BOOT names; its library is lib/
12- make check # every example and test against its expected output
13- make docker-check # make check in a linux/amd64 container, on a Mac; under Rosetta it skips 9 tests, each saying why
14- make bench # must report at least 400,000 lines a second
15- make prev-bench # the compiler's speed against BOOT's: more than a tenth slower fails
16- make kernels # test/bench's kernels against FPC -O2's twins (apt-get install -y fp-compiler)
17- make loc # lines of the compiler, by rloc; the last, code, is the budget
18- make fixpoint # BOOT's release builds src, that builds src, that again: the last two agree
19- make gdb # gdb stops at a line of a test and names it
20- make lldb # the same for lldb, on a Mac (a program made for darwin-arm64, in the container)
21- make mac-check # on an Apple Silicon Mac: test/mac and conform/run cross-compiled in the container, run natively, and lldb
22- make stress # 40,000 native threads; make check runs a small version
23- make alpine # test/libc in an Alpine container, over musl (docker)
24- make fmt # lib/, examples/ and tools/ are formatted
25- make install # raz on PATH via ~/.local (PREFIX=...); make uninstall
26-
27-`make check` also runs `tools/Doc.raz` and `tools/Pretty.raz`, the
28-report's whole examples, the tutorial's (`doc/raz-tutorial.7`, each
29-against the output the page shows after it, its status in `test/man`), each library module's own `main` (its test),
30-and the vim and emacs support headless where they are installed
31-(`apt-get install -y vim emacs-nox`): each example must indent back
32-exactly as written.
33-
34-`make check` must pass before every commit. The conformance suite,
35-`conform/`, holds what any implementation must do (`conform/check.sh`
36-says how it is laid out); `test/` holds what is this compiler's alone:
37-its messages, its limits, its target. A test goes in `conform/` when
38-the report alone fixes its output and status, and keeps to the
39-language and the library a target can't leave out. Tests:
40-`test/run/X.raz` with `X.expect` (stdout), optional `X.status`,
41-`X.stderr` and `X.args`; modules they import in `test/run/mods`.
42-`test/err/X.raz` must fail to compile with the text in `X.err` (all of
43-standard error), given the compiler options in `X.args` if there is
44-one. `test/msg` holds this compiler's `X.stderr` and `X.err` for the
45-programs in `conform/`.
46-`test/pretty/X.raz` must format to `X.expect`. Examples in `examples/`
47-work the same way, compiled with `-Werror`, as are `test/libc`, the
48-tools and the library's tests: they must have no warnings.
49-
50-## How we work
51-
52-- The compiler, `src/`, is raz, in the language of the report and with
53- the library of `lib/`; it must build with the release `BOOT` names
54- (v0.25.0), so it, and the modules of `lib/` it imports, use nothing
55- that release doesn't know until `BOOT` names a newer one.
56-- Work goes by milestones, each a release, set by the owner. A milestone
57- starts only on the owner's explicit go-ahead; within it, one commit
58- per step, pushed as it is done, then stop for review. Never start a
59- milestone, or change the report's language, without being asked.
60-- Language changes go into `doc/raz.md` first, for the owner to review,
61- before any code.
62-- Commits: author
63- `Luis <42945842+ldiaz94@users.noreply.github.com>`, unsigned
64- (`--no-gpg-sign`), no attribution trailer. Push to `main`. No pull
65- requests unless asked.
66-- Budget: never past 18,000 lines of code (raised from 8,500, then
67- from 11,000 and 14,000, the last for the arm64 macOS port, by the owner's word, who dropped the soft limit; blank and
68- comment lines not counted), with the compiler documented and
69- commented throughout, most of all where it is obscure or needs a
70- compiler writer's knowledge; at least 400,000 lines of raz a second;
71- the report, `doc/raz.md`, under 40 pages as `make pdf` renders it,
72- checked by hand after each milestone (32 at report 2026-10.34).
73-- Clarity comes first, before speed and size: the compiler must be a
74- model of plain code that a beginner can follow. Every rewrite of the
75- code it makes is explained where it is done, with the code before
76- and after, and in `doc/compiler.md`.
77-- Style: clarity over cleverness; each unit opens with what it is, what
78- it depends on and what it leaves out; comments say why. Match the
79- report's plain, short prose in documentation. `STANDARDS.md` says
80- how raz is written here: a parameter is a value, `var`, or, only
81- when it is kept, a pointer; no `ADR` where `var` serves.
82-
83-## Where things stand
84-
85-The website's `/source/` browser and releases are built by ladle,
86-pinned with its checksum under `site/tools/`. `make site` builds the
87-main pages and then the source site, with raz programs, `site/Build.raz`,
88-`Source.raz` and `Verify.raz`, which the Makefile builds with this
89-repository's `./raz` into `build/site/`. Wrangler runs `make site-source`
90-(which builds `raz` first) before uploading, so the generated Git store
91-stays out of this repository. `site/README.md` gives the build, release records and
92-checks. `site/releases` lists website releases whose tags aren't
93-pushed yet (none now); it never makes a tag.
94-
95-v0.25.3, report 2026-10.38 still: `raz -q def` on a module, used or
96-imported, gives its `module` line.
97-v0.25.2, before it: `raz -q def`, where the name at the
98-cursor is declared, for raz-lsp's hover and go to definition.
99-v0.25.1, report 2026-10.38 still, before it, the compiler's and the library's
100-only: `raz -q check` and `raz -q words`, for an editor's language
101-server (`~/r/raz-lsp`; `doc/compiler.md`, "raz -q"), and
102-`Sys.errReadOnly`. `BOOT` still names v0.25.0.
103-v0.25.0, report 2026-10.38, before it, the Moss work (`PLAN.md` 3), the last before
104-the hard freeze: a code procedure names a procedure or a global in
105-`call p`, `jmp p` and `lea r, [v]`; the report's least an implementation
106-accepts, and this compiler's errors past its own limits (a nesting of
107-256, 1024 values waiting); `Host`, the compiler's five asks of the
108-system it runs on, and `Files.argCount`; `-lib DIR`; `Rt`'s places
109-linked only as `Rt` declares them; `push` of a constant, `cld`, `std`
110-and the SHA and shuffle instructions; and in `doc/compiler.md`, a
111-program with its own `Rt`, the machine as the code leaves it, the
112-recipe for an interrupt's entry, and what `src/` asks of `lib/`.
113-Module lookup keeps the root, `/`. The tests need no Python. `BOOT`
114-names v0.25.0 (2026-10-26), so `src/` may use all of 10.38.
115-
116-v0.24.0, report 2026-10.37 still, ends the safety thaw (`PLAN.md` 2): the
117-old forms are errors. What `SYSTEM` fences is refused outside a module
118-that imports it; strings, constants' slices and `MSG` are `[]const`;
119-atomics take only a variable. `lib/`, `src/`, the tools, examples and
120-tests were mended against a temporary `-strict` first. `BOOT` names
121-v0.23.0. The programs in `~/r` move to it one by one (dwa, concha,
122-mosaico, rat and notis first).
123-v0.23.0, report 2026-10.37, before it, the safety thaw's first release, which
124-breaks no program (`PLAN.md` 2): an array a call returns lives to the
125-end of its procedure; `CAS`, `XCHG` and `XADD` take a variable;
126-`[]const T`; `import SYSTEM`, with `SYSTEM.ADR`, `.PTR`, `.SYSCALL` and
127-`.ARGV`; and in the library `Task`, `Guarded` and `Heap`'s debugging
128-mode. Every old form is still taken: a literal into a `[]U8`, the bare
129-built-ins, what `SYSTEM` fences without it, an atomic given `ADR(x)`.
130-`BOOT` names v0.23.0 (2026-10-26), so `src/` and the library it imports
131-may use all of 10.37. CI couldn't run for it either; `make dist` made its tarball here.
132-v0.22.0, report 2026-10.36, before it, is the twelfth thaw, what the proposals
133-collated: `MIN`, `MAX`, `ABS`, `CLZ`, `CTZ`, `POPCOUNT`, `INT(b)`,
134-`OFFSET`, `SIZE(T.f)`, `BYTES` and `FILL`; a qualified case in an arm,
135-slice and `ERROR` constants, a record's procedure field that takes the
136-record, and `ROL` and `ROR` (10.35); library growth (`Fmt`'s widths and
137-`short`, `Str`, `Files`, `Sys`'s `poll`, processes, servers and signals,
138-`Math`, `Opt`, `Heap.sure`, `Vec`, `Arena`); and code made faster
139-(inlining a procedure that only returns, `COPY`, `FILL`, array
140-parameters). `BOOT` named v0.22.0 from 2026-10-23. CI couldn't run for it (GitHub's
141-billing), so its release and tarball were made here by `make dist`, the
142-same bytes CI would make.
143-v0.21.0, report 2026-10.34, before it, the language unchanged, is for a kernel:
144-the assembler knows a kernel's instructions (`cli`, `lgdt`, `mov` to
145-`cr3`, `in`, `out`, ...); `raz -base` sets the load address, in the low
146-or the top 2 GB; `raz -bare` makes a program for the bare machine, which
147-reads no arguments and runs no body of `Rt`; `BOOT` named v0.20.0, and
148-`Sys` takes `PTR` where it had its private `bytes`. `MEM_PROPOSAL.md`
149-proposed a memory-safe raz (the safety thaw took part of it).
150-v0.20.0, report 2026-10.34, before it: v0.19.0 builds `src/` and the
151-Pascal seed is gone; `Buf.bytes`, `Sys.entryKind` and `src/`'s `Item`s
152-only read take `const`; and the tenth thaw, by the owner's word,
153-`PTR(s)`, a slice's pointer, with messages that point to it.
154-v0.19.0, report 2026-10.33, before it: the ninth thaw, a `const`
155-parameter, a variant in a constant, and the library taking `var`,
156-`const` or a value where it took a pointer (`Arena`, `Buf`, `Files`,
157-`Fmt`, `List`, `Lock`, `Map`, `Opt`, `Str`, `Sys`'s directories,
158-`Thread`'s `Mutex`, `Vec`; and `tools/Scan.raz`), which breaks calls
159-written with `ADR`; the compiler's message names the mending.
160-v0.18.1, report 2026-10.32, before it: v0.18.0's thaw (a
161-constant typed `[]T` may be `[]`, the empty slice, as may a constant's
162-slice part), with `Vec.pop` and `Sys.Info.links`, and a constant's
163-slice part naming another module's array constant, a defect mended;
164-and library growth that breaks no program: `Buf.cut`, `Out.lines`,
165-`Thread.signal`, and in `Opt` `spelt` and `refuse`, a `-h` of a
166-scope's own, a value that may be left out (`[name]`) and `number` with
167-no top.
168-v0.17.0's thaw before it: `INT` at least 16 bits, and `U8`, `I8` and
169-`I16` widening to it; an enumeration's name written with its type, and
170-shared; `continue`; `[]` as the empty slice; `Width`. `src/` is the
171-compiler in raz, built by itself (Self, done); the Pascal seed, the
172-release compiler to v0.9.1 and what built `src/` to v0.19.0, is in git
173-at v0.19.0. The compiler takes 1.4 times the Pascal one's time; `make
174-kernels` measures `test/bench` against FPC `-O2`. What
175-each version of the report changed is in `doc/report-history.md`, and
176-what each step did is in git; don't repeat it here.
177-
178-rmacs (emacs's keys) and ravite (vim's), the two editors written in
179-raz, live in repositories of their own, each pinning the raz commit it
180-builds with; they use `tools/Scan.raz` as a tool, not part of the
181-library. rat, rlX11 and rloc are other users of `Sys`.
182-
183-**The freeze.** Since v0.5.0 the language changes only to mend a
184-defect, and the library grows only by what breaks no program written
185-for it. Thaws happen only by the owner's word (v0.6.0, reports
186-2026-10.13 to 10.23, 10.25 for strings, 10.26 for `INT` and views, 10.33
187-for `const` parameters, variants in constants and the library by `var`,
188-10.34 for `PTR`, and 10.35 and 10.36 for what the proposals collated).
189-
190-**The hard freeze** (owner, 2026-10-23). raz takes no more proposals:
191-a wish, the owner's or yours, isn't recorded. `PROPOSALS.md` and
192-`MEM_PROPOSAL.md` are gone (2026-10-26; in git before). What was left
193-open, the safety thaw (done, v0.24.0) and the Moss work (`Host`, a
194-freestanding program stated, the assembler's instructions,
195-implementation limits, in `PLAN.md`'s appendix), is the last. `PLAN.md`
196-gives the order: v0.22.0 for what is done, the safety thaw, the Moss
197-work, the hard freeze, a clean-up, then 1.0 when use shows it. Once it
198-is done the language is in a hard freeze: no more thaws. The
199-language changes only to mend a defect, the compiler or the library doing other than the report says;
200-the library's core (appendix A) only to mend a defect or to plug a very
201-big gap; and the rest of the library grows only conservatively, by what
202-breaks no program, on the owner's word.
203-
204-**The reserved words and the module names are settled.** That a word
205-is reserved, however common (`code`, `to`, `packed`, `forward`, `set`,
206-...), and that the names of modules are one space with the library's
207-(3, "Names are flat"), so that a program's module may clash with one of
208-the library's, now or later, are never brought up: not as a defect, a
209-proposal, an awkwardness or a note, in raz or in any program or library
210-written in it. A name that is taken is renamed, and nothing is said of
211-it.
212-
213-The parser reaches the machine only through `Gen` (`src/Gen.x86_64.raz`),
214-and the executable's format only through `Exe` (`src/Exe.linux.raz`). Keep
215-`doc/compiler.md`'s table of lines and its routine names true when the
216-compiler changes.
217-
218-A release is an annotated tag `vX.Y.Z` on `main`, its message what
219-`raz --version` will print (`raz 0.3.0, report 2026-10.0`); `make
220-check` passes first. The compiler takes its version from `git
221-describe` (`build/version.inc`, made by `make`). Pushing the tag runs
222-`.github/workflows/ci.yml`, which checks it and makes the GitHub
223-release with a tarball of `raz` and `lib/`; it also checks every push
224-to `main`. A release whose tag isn't pushed yet goes to the website
225-by `make site RELEASES="vX.Y.Z=COMMIT"`, its tarball made by `make
226-dist REV=COMMIT VERSION=X.Y.Z`, the same as the tag's will be. `README.md`'s "Versions" gives the commands. v0.3.0 is
227-the first. The tarball has `tools/`, which the website offers from
228-0.7.1 on.
229-
230-`test/libc` runs its programs over `lib/Sys.raz`, the C one, through
231-a link in its `mods`; `make check` runs them again with `-libc musl`
232-where musl's loader is installed (`apt-get install -y musl
233-musl-tools`), and compares `tools/cabi.c`'s output, with `cc` and
234-`musl-gcc`, with `lib/CAbi.linux-x86_64.raz`, which is never edited
235-by hand. A test or example without `.expect` is only
236-compiled (`examples/Window.raz` needs a display).
237-
238-## The compiler and BOOT
239-
240-`src/` is the compiler, in raz: one module to a unit of the Pascal
241-compiler it was ported from, the same names. The release `BOOT` names,
242-by its tag and its tarball's SHA-256, builds it: `src/boot.sh` fetches
243-the tarball into `build/boot/` (curl, or `gh api` for a private
244-repository: CI gives it `GH_TOKEN`), checks the sum and puts its `raz`
245-there with today's `lib/` beside it. Each release is built by the one
246-before it, back to v0.19.0, which the Pascal seed built; the seed is in
247-git at v0.19.0 (`seed/`), and a comment in `src/` that names "the
248-seed" means it. `make check`, the fixpoint and `conform/` are the
249-compiler's tests. Moving `BOOT` to a newer release, once its tag is
250-pushed and CI's tarball has the SHA-256 `make dist` gives here, is a
251-step of its own, by the owner's word; then `src/` may use what that
252-release brought. `fpc` is needed only for `make kernels`' Pascal twins.
253-
254-`sbcl/` is an example, not part of the build: a second compiler, in
255-Common Lisp, written from the report alone and kept as a reference
256-(`sbcl/README.md`).
257-
258-## Readings of the report already taken
259-
260-These are how the compiler behaves; keep them unless the owner says
261-otherwise.
262-
263-- A named and an anonymous type built alike are the same; `type A = B`
264- is an alias. A hex literal above high(I64) is a `U64`.
265-- `p^.f` and `p^[i]` are explicit; `p[i]` on a pointer to an array is
266- an error. A statement starts with a name, so `^T(x)^ := v` isn't one.
267-- A `BOOL` converts to every integer type, 0 or 1 (report 2026-10.36),
268- in `convert`'s integer branch with no code of its own, as a `BOOL`'s
269- value is already 0 or 1; of a constant it folds. No integer to
270- `BOOL`: the error's help says `x # 0`.
271-- `for`: the step is a constant; the loop never steps past the limit, so
272- it can't wrap; afterwards the variable holds the last value it took;
273- the body may assign it. Leave as is.
274-- Two results that are each a single value of a word at most, not a
275- real, come back in rax and rdx, and so does a slice, as from a code
276- procedure (owner's word, v0.7.0); other several results, and records,
277- through a hidden pointer.
278-- `NEW(p, a)` requires `a: ^Mem.Allocator` and calls its `alloc` field:
279- the one library type the compiler knows by name. `Rt.fail` is
280- found by name too.
281-- A set literal takes its type from its first name when nothing else
282- gives it; `{}` needs a known type. String constants can be indexed
283- and sliced.
284-- A deferred statement's frame slots stay reserved for the rest of its
285- procedure.
286-- A generic instance first used in a procedure, or in the module's
287- body, is made before that code begins: `InstancesFor` reads ahead
288- for the import's name, since code can't be compiled inside other
289- code. Its arguments are read then, in the scope there.
290-- A program uses C if a module it uses (not one read only for an
291- interface check) has an `extern` or a `link` of a library. `static`
292- in `link static;` is not a reserved word. It is linked against
293- glibc, or musl (`/lib/ld-musl-x86_64.so.1`, needing `libc.so`) by
294- `-libc musl` or on a machine with musl's loader and not glibc's.
295- `lib/Sys.raz` and `CAbi` are read for the interface check when
296- BOOT's release builds `src/`, so they keep to its language, as the
297- modules `src/` imports do.
298-- `Sys` gives minus Linux's errnos on every target; `Sys.raz` maps the
299- C library's through `CAbi.errnos`.
300-- C symbols are reached through quadwords the loader fills in
301- (GLOB_DAT), with no PLT; the executable exports nothing. In a C
302- program the entry point stores C's `exit` in `Rt.cExit`, found by
303- name like `Rt.exit`, before any module body runs; and, if the
304- program has `Thread`, `pthread_create` and `pthread_join` in
305- `Thread.cCreate` and `Thread.cJoin`, so that `Thread` makes C's
306- threads there and serves programs with C and without.
307-- Past an extern's parameters, a string goes as a C string and an
308- integer constant as an `INT`.
309-- A real constant is held as an F64; one typed `F32` holds a value an
310- F32 can hold (the report says so, 2). An `F32` in a register is its low 32 bits; the upper
311- ones are left as they fall.
312-- `Heap` and `Out` lock with `Lock`, a spinlock that yields, since they
313- serve C's threads and `Thread`'s alike; `Thread.Mutex` is a futex.
314-- A failed check says what failed and with what values, at the place
315- of the offending expression. A signal is told at the place of the
316- statement it stopped in, or of the procedure for a stack overflow in
317- its prologue, and the program ends by `Rt.exit(2)`, after its
318- `atExit` procedures, as a failed check does (report 2026-10.22; a
319- fault inside `Out`'s or `Heap`'s lock would hang there). The handlers run on a stack of their own: `Rt`'s for
320- the main thread, and one in each `Thread` thread's mapping, made
321- by clone or by C. Threads a program makes with `pthread_create`
322- itself have none, so a stack overflow in one still ends the program
323- by the signal with no message.
324-- The smallest value of a signed type divided by -1 stops the program
325- (SIGFPE), as 6.1 says, `mod` as `div`; for a type narrower than 64
326- bits the code makes the division fault, as the machine wouldn't. In
327- a constant it is an error, as dividing by zero is.
328-- `INT` widens to `I64` (and `UINT` to `U64`) wherever its value goes
329- to one: assigned, passed, returned, in `a, b := f(x)` and `return
330- f(x)`, a `for`'s bounds, `INC`/`DEC`'s step, and where it meets an
331- `I64` in an operator (report 2026-10.26, 5.10 and 6.1). Never to a
332- `U64`, nor an `I64` back to an `INT`.
333-- A view, `v.(T)`, is `v`'s item with `T` for its type: nothing is
334- copied. A variable kept in a register goes to memory for it, as for
335- `ADR`. Another module's variable may be viewed, and not written. A
336- view that runs past its end fails as kind 7 of `Rt.fail`. `src/`,
337- and the library it imports (`Str`, `Bytes`, `Sys`, ...), may use
338- views and the widening now that v0.19.0 builds them; they use
339- neither yet.
340-- A returned slice of the frame (report 2026-10.27, 7.3) is caught by
341- `Item.frame`, which sees only the expression: a slice held first in a
342- local slice variable or a record, stored, or come back from a call,
343- isn't, and is left undefined (10). `ret` and `keep`, once
344- proposed, would close it; the owner keeps it open for now.
345-- An empty slice constant, `const E: []T = [];` (report 2026-10.32),
346- is 16 zero bytes in read-only data, read as an array constant is;
347- `LEN` of it is no constant. A constant's slice part takes `[]`, names
348- a constant whole, of any module, by its type, not its text, and takes
349- an array literal (report 2026-10.36), an array constant of its own in
350- a chunk with no name, nested to any depth. An `ERROR` constant given
351- another takes its chunk: the same error.
352-- An array a call returns, or a record or variant holding one, and a
353- `const` parameter's temporary holding one, is a slot of the
354- procedure (report 2026-10.37, 8: `Sym.holdsArray`, `allocPerm`): a
355- slice of it may be kept to the end of the procedure, and returning
356- it is caught only as 7.3 catches a slice of the frame.
357-- `Buf.add`, `str` and `spare`, and `Vec`'s growing, stop the program
358- when the allocator has no room; `room` asks first.
359-- `Sys.handle`'s handler only notes the signal, with `XCHG`; it is
360- installed without `SA_RESTART`, so a call it breaks into is -4, which
361- `Out` and `Files` try again. Over C, `ready` and `readyFor` try `poll`
362- again after EINTR only when no signal `handle` took broke in.
363-- `U8`, `I8` and `I16` widen to `INT`, `U8` and `U16` to `UINT`, one
364- step only (a `U8` into an `I64` is written), and not in `return f(x)`
365- (report 2026-10.31). An operator's result on them (`made`) doesn't
366- widen; a conversion's does, `U8(a + b)` too.
367-- An enumeration's name shared in its scope with another enumeration's
368- is written with its type; shared with anything else, the name alone is
369- that other declaration. A `match` arm on an enumeration or a variant
370- (report 2026-10.36, 7.4) takes a case alone, found among the matched
371- type's own whatever the scope holds, or qualified as anywhere else
372- (`Kind.done`, `Xml.done`, `Xml.Kind.done`), read by `qualIdent`; a
373- qualified case of another type is an error naming both.
374-- `Width` follows glibc's `wcwidth` but gives a control 0, and 0 to the
375- format characters glibc counts as 1 (Egyptian hieroglyph controls,
376- interlinear annotation), but for the prepended concatenation marks.
377-- A pointer's base, and a procedure type's parameter or result (report
378- 2026-10.36, 4 and 5.9), may name a type declared later in its `type`
379- section, if the name is a bare one that nothing in scope declares yet
380- (`[]Later` or `[2]Later` doesn't wait): a placeholder of form `fNone`
381- stands for it until the section's end (`laterType`,
382- `resolveLaters`), which lays several results out again. A procedure
383- type outside a `type` section, a variable's, waits for nothing.
384-- An `extern` module variable is read-only for an importer, as the
385- report says of every exported variable (3).
386-- Warnings come only for a module with no errors. A procedure naming
387- itself doesn't use it; a type named by a pointer, or by a procedure
388- type's parameter or result, in its own declaration does. An enumeration's names are never warned of, nor a
389- generic module's parameters; a generic module is warned of in its
390- first instance only. Assigning a variable whole (`x :=`, `a, b :=`)
391- doesn't read it; anything else does.
392-- A `const` parameter (report 2026-10.33) is a `var` one never changed:
393- passed by address always, its `Obj` `isVar` and `isConst`, an item of
394- it `ro`. A slice of its array may be made, to read; through it the
395- caller's array may be written, which the report says (8). An argument
396- that isn't a variable, or is a packed field, a view or volatile, goes
397- in a temporary of the statement. `match` on a `const` parameter or a
398- constant gives names that are only read. Procedure types compare
399- `const` as `var`. It is unused if never read, as a value parameter.
400-- A variant in a constant must be typed; `const D = dot;` is an error
401- that says to write its type. Its case is read by name (`constCase`).
402-- The library takes a `var` for what it changes and `const` for a record
403- or array it only reads (report 2026-10.33); `Buf.bytes` and
404- `Sys.entryKind` came to it in v0.20.0, with the seed gone. `src/`
405- takes an `Item` as `const` only where callgrind counts a gain, on the
406- paths every compile goes through; the routines that word an error
407- take a value. Measured: a `Map` passed as a value, four
408- words, made a loop of `get` half again as slow as `const`. A trace
409- shows no `var` or `const` parameter. `Fmt`'s `format` and `put` keep
410- `^Buf.Buf`, since `nil` is standard output there.
411-- `PTR(s)` (report 2026-10.34) is a slice's first word, read with no
412- check; of an array or a string constant, its address, refused wherever
413- a slice of all of it is (a packed record's misaligned field, a view,
414- through `^VOLATILE`, another module's array). `PTR("")` is the
415- string's place in read-only data, not `nil`; an empty slice cut from
416- another keeps its place. `PTR([])` is an error, since `[]` has no
417- type there, and its help says it would be `nil`. A slice where its
418- element's pointer is wanted, and a pointer where a slice is, are
419- errors whose help names `PTR(s)` and `LEN(s)`, or `p[0..n]`.
420-- `CAS(v, old, new)`, `XCHG(v, x)` and `XADD(v, x)` (report 2026-10.37)
421- take a variable, whose address is pushed as `ADR`'s is (`atomic`); a
422- local named in one is kept out of a register, as for `ADR`
423- (`chooseRegs`). A pointer that isn't a variable, `ADR(x)`, is refused
424- with help, and so is a pointer variable, `XADD(p, 1)`, whose help says
425- `p^`.
426-- `import SYSTEM` (report 2026-10.37) binds to `Sym.system`, no file,
427- whose scope holds `ADR`, `PTR`, `SYSCALL` and `ARGV`; it is never
428- warned of as unused, and an alias is refused. What it fences
429- (`Item.needSystem`, `doc/compiler.md`) is refused elsewhere: `extern`,
430- `link`, code procedures and `check off;` are said and read on, so one
431- missing import is one error.
432-- `[]const T` (report 2026-10.37) is a slice type with `rdonly` set: not
433- the same as `[]T`, which goes into it with no code (`coerce`), never
434- back (help says why). An element read through one has the item's
435- `elemRo`, which `notReadOnly` refuses, so every write route (`:=`,
436- `INC`, a `var` argument, `ADR`, a view) is caught in one place; `COPY`
437- and `FILL` refuse one as their destination (`destSlice`); a slice of
438- one, or of an array read through one or of another module's array,
439- is one (`slice`); `BYTES` of one is a `[]const U8`; `match` on an
440- element gives names only read. A string literal (`tConstBytes` where
441- indexed), a constant's slice (`ofConst`), `MSG` and a slice of a
442- `const` parameter's array are `[]const`; a constant's slice part must
443- be declared `[]const`.
444-- A procedure or a global in a code procedure (report 2026-10.38, 8)
445- is found by `Parse.asmName`, beside `asmConst`, after the
446- procedure's labels, which `X64.findLabels` enters first: a label
447- wins wherever it is written. `call p` and `jmp p` are E8 and E9 with
448- a fixup, `[v]` rip-relative, as ordinary code's; `[v]` stands alone
449- (`[g + 8]` is an error), a label is only for a jump, and C's names
450- are refused, their chunk holding C's address. A variable another
451- module exports may be written through `lea`: its type isn't
452- checked. A code procedure's body has a scope of its own, so a name
453- not yet declared is poison there only.
454-- The limits (report 2026-10.38, 10): one count, `Parse.nest`, of
455- statements, expressions and types nested, to 256; 1024 values
456- waiting in one expression (`Gen.MaxStack`), past which the compile
457- ends; the other limits are `Parse`'s constants, listed under "This
458- compiler's choices".
459-- `ROL(x, n)` and `ROR(x, n)` (report 2026-10.35) are done at `x`'s
460- own width, `rol al, cl` for a `U8`, with no mask of the count: x86
461- takes it modulo 32 or 64, and a byte's or a word's rotation goes
462- round modulo 8 or 16 itself. A negative count is taken modulo the
463- width as a shift's is, `n & (w - 1)`: `ROL(x, -1)` is `ROR(x, 1)`.
464- The result is a built-in's, not an operator's, and widens (`made`
465- is false). Of two constants they fold, in a constant too.
466-- `ABS(x)` (report 2026-10.36) is of `x`'s type and widens (`made` is
467- false). A signed integer's is `mov rax, r; neg r; cmovs r, rax`, then
468- cut to a narrow width as `neg` is, so the smallest value gives itself
469- with no check, as `-x` does; an unsigned one's is no code; a real's
470- is `btr` of its sign bit in rax, as `neg`'s `btc`. Of a constant it
471- folds, a real's top bit cleared; of the smallest untyped constant it
472- is `neg`'s error, "too big for I64". A string is refused as no number.
473-- `MIN(T)` and `MAX(T)` (report 2026-10.36) are untyped constants, but
474- `MAX(U64)` and `MAX(UINT)`, above `high(I64)`, keep their type, as a
475- hex literal above it is a `U64`. A `T` not an integer type is an
476- error; `MAX(x)` of a variable is "x isn't a type".
477-- `CLZ(x)`, `CTZ(x)` and `POPCOUNT(x)` (report 2026-10.36) give an
478- `INT`, a constant of one when `x` is. They use only baseline x86-64,
479- no `lzcnt`, `tzcnt` or `popcnt`: `bsr` or `bsf` on all 64 bits (a
480- narrow value's upper ones are zero), with `jnz` past setting the
481- count of 0 to the width; `POPCOUNT` by `Bytes.count`'s sums of two,
482- four and eight bits and a multiply by `0101...H`, in rax and rdx. A
483- set's `POPCOUNT` counts its bits the same way.
484-- `SIZE(T.f)` and `OFFSET(T, f)` (report 2026-10.36): the type is read
485- by `parseType`, where a name before a `.` must be a module's, so
486- `M.T` is read whole and a `.` past the type is a field's,
487- `SIZE(M.T.f)` too. `T` must be a record type (a variant is refused,
488- with help); a path `a.b` is refused, its help naming `a`'s type.
489- `BYTES(x)`: of a slice, its `PTR` and `LEN * SIZE(T)`, with no check
490- of what holds the slice (a `const` one, another module's, a field of
491- a packed record), as for `PTR`; of anything else, a variable's
492- address and size, refused, as `ADR` refuses, for what is only read,
493- and, beyond `ADR`, for a volatile variable; a constant of any kind
494- is no variable. `T` is refused by the view's `notPlain`. The result
495- keeps `x`'s `frame`, so the bytes of a local are caught by
496- `notOfFrame` as far as a slice of it is.
497-- `FILL(d, x)` (report 2026-10.36) takes `d` as `COPY` does
498- (`destSlice`), then `x` as `:=` would, with `:=`'s messages, read
499- once before any element is written. A scalar element of 1, 2, 4 or 8
500- bytes is stored from `rax`, a real's bits as an integer's: by a store
501- each into an array of 16 elements or fewer, else by a loop for fewer
502- than 16 at run time and `rep stos` of its width from 16 up. A
503- constant zero into an array is `zeroBytes`, as `NEW`'s zeroing is;
504- into a slice it is stored as any scalar, which is as fast. Another
505- element is copied into `d[0]` and forward from there by `rep movsb`.
506- A record literal of zeros isn't seen as a zero. A const parameter's
507- or another module's array, as `d`, says why it can't be changed, for
508- `COPY` too. `seqSlice` copies no slice that is a temporary already
509- (a slice just cut): nothing `s` or `x` does can change it.
510-- A call of a procedure whose body is only `return e`, with no locals,
511- a single value its result and no `try` in `e`, is made in place
512- (`Parse.inlined`): the arguments read and converted as for a call,
513- each once and in order, into temporaries the parameters are named
514- as (a `var` or `const` one, a record or an array, by the address the
515- call would pass), then `e` read again in its own module's scope,
516- with that module's checks. Another module's procedure and a generic
517- instance's too; not one already being made in place, nor a call
518- through a procedure value. The procedure has no frame: it is in
519- neither the trap report's calls nor gdb's backtrace; a failed check
520- in `e` is told at `e`'s line, a signal at the caller's statement.
521- A test that wants its frame calls it through a procedure value.