raz / commit 4c0f8e56

commit
4c0f8e5619938935300d784ec81808d81e2447de
author
Luis <42945842+ldiaz94@users.noreply.github.com>
date
parent
aef7ca04
Drop PLAN.md: its steps are done and its rules live elsewhere

The Pascal dialect rule moves to CLAUDE.md; the rest was already in
the report, doc/compiler.md, README.md and CLAUDE.md. The history is
in git.

patch · log

1 file changed, +0 -532

PLAN.md (history) deleted +0 -532

@@ -1,532 +0,0 @@
1-# raz: the plan
2-
3-raz (Polish for *one*, as in counting) is a small systems language in Wirth's
4-tradition: full control of memory, volatile access, atomics, calls into
5-C, generic modules. Its compiler is meant to be read in a long weekend:
6-under 6,000 lines of Free Pascal, one pass, no IR, no optimizer, writing
7-x86-64 machine code and the ELF file itself.
8-
9-The language is defined by `doc/raz.md`. Where this plan and the report
10-disagree, the report wins and this plan is fixed.
11-
12-## Ground rules
13-
14-- The compiler is Free Pascal 3.2.2, `{$mode objfpc}{$H-}`: records,
15- pointers, shortstrings. No classes, ansistrings, exceptions, dynamic
16- arrays or SysUtils.
17-- The compiler stays near 6,000 lines of code (5,000 until stage 4,
18- which bought its diagnostics with the rest) (not counting blank and
19- comment lines), within 10%, and compiles at least 400,000 lines of
20- raz a second, from reading the sources to writing the executable.
21- `make loc` and `make bench` measure them, and a step that breaks
22- either limit isn't done.
23-- Clarity over cleverness. Every unit opens with a header comment: what
24- it is, what it depends on, what it leaves out. Comments say why, and
25- what wherever a layout or encoding isn't obvious.
26-- One commit per step, as
27- `Luis <42945842+ldiaz94@users.noreply.github.com>`, unsigned,
28- with no attribution trailer.
29-- Work stops after every stage for review. A stage starts only on an
30- explicit go-ahead; within it, each step is committed and pushed as it
31- is done.
32-- Not in scope for now: man pages, QEMU or bare metal tests, aarch64,
33- macOS and Windows (Mach-O, PE), an optimizer.
34-
35-## Decisions
36-
37-1. Source files end in `.raz`, one module per file, named after it.
38-2. "Not equal" is `#`.
39-3. Every statement ends in `;`, including `end;` and `until x;`. Every
40- match arm starts with `|`, the `else` arm too.
41-4. Code generation is a stack machine through `rax`: no register
42- allocation, and every access the program writes is one instruction
43- in source order. Volatile is therefore a type rule; the code
44- generator honours it by doing nothing clever.
45-5. Every procedure uses the System V calling convention, so any
46- procedure with scalar parameters can be handed to C as a callback.
47-6. Records are laid out as C lays them out.
48-7. Modules are compiled together, from source, in one run: no symbol
49- files, no separate compilation. A generic module is compiled once
50- per distinct list of arguments, its types and its procedures.
51-8. Tree shaking: the linker keeps only the procedures, variables and
52- literals reachable from the entry point.
53-9. Variadic arguments exist only to call C. raz code gets the same
54- effect from a slice of a variant (`Fmt.print`).
55-10. Strings are `[]U8`. The language compares them with `=`; the rest
56- is a library.
57-
58-## The compiler, in reading order
59-
60-Lines after stage 3, all of them and those of code (neither blank nor
61-only comment), as `make loc` counts them:
62-
63-| File | Lines | Code | What |
64-|---|---|---|---|
65-| `src/scan.pas` | 548 | 471 | Symbols, literals, comments, error messages |
66-| `src/sym.pas` | 508 | 422 | Types, objects, scopes, layout |
67-| `src/x64.pas` | 680 | 546 | Code buffer, chunks, fixups, line notes, instruction encoder |
68-| `src/gen.pas` | 1,414 | 1,240 | Items: loading, storing, copying, frames, calls |
69-| `src/parse.pas` | 1,816 | 1,685 | Declarations, statements, expressions, built-ins |
70-| `src/link.pas` | 131 | 95 | Tree shaking, layout, patching |
71-| `src/elf.pas` | 424 | 350 | Static and dynamic ELF, symbol table, line numbers |
72-| `src/raz.pas` | 183 | 145 | The command line, the entry points |
73-| total | 5,704 | 4,954 | |
74-
75-## Steps
76-
77-Stage 1: the core
78-
79-- [x] 1. Language report, `doc/raz.md`. Reviewed and approved before
80- any more code.
81-- [x] 2. Scanner and symbol table, `scan.pas` and `sym.pas`, written
82- against the report; they compile.
83-- [x] 3. Machine code, `x64.pas`.
84-- [x] 4. Linking and output, `link.pas` and `elf.pas`: tree shaking,
85- static ELF, symbol table. A hand built chunk runs.
86-- [x] 5. Parser and code generator, `gen.pas` and `parse.pas`:
87- everything in the report except multiple results, errors,
88- enumerations and sets, record literals, `defer`, `NEW`, generic
89- modules and `extern`. Module bodies, per-target modules and their
90- interface check, and code procedures are in.
91-- [x] 6. `lib/Rt.raz`, `lib/Sys.linux-x86_64.raz`, `lib/Out.raz`;
92- examples (hello, args, variants and slices, volatile, a code
93- procedure); `make check` runs them against expected output;
94- `make bench` times the compiler on generated raz.
95-
96-Stage 2: the rest of the language
97-
98-- [x] 7. Multiple results and errors; `INC` and `DEC`.
99-- [x] 8. Enumerations and sets, record literals, `defer`; examples.
100-- [x] 9. `NEW`; `lib/Mem.raz`, `lib/Arena.raz`, `lib/Heap.raz`.
101-- [x] 10. Generic modules, with type and procedure arguments;
102- `lib/Str.raz`, `lib/Buf.raz`, `lib/Fmt.raz`; examples.
103-
104-Stage 3: calling C, and what comes with it
105-
106-- [x] 11. `extern proc`, `extern var` and `link`; dynamic ELF, start
107- through `__libc_start_main`. A plain `lib/Sys.raz` over the C
108- library, the default for targets with no file of their own.
109- Examples with `printf` to `stdout`, and an X11 window, reading
110- `XEvent` as an array of words through pointer conversions.
111- Ending a program: the entry point calls `Rt.exit(status)`, which
112- runs the procedures registered with `Rt.atExit`, then ends it;
113- `Rt.fail` runs them too. A buffered `lib/Out.raz`: 4 KB, flushed
114- at each newline when standard output is a terminal, when full,
115- by `Out.flush`, and at exit. The report says how to mix `Out`
116- with C's `stdio`: flush one before using the other.
117-- [x] 12. `F32`: arithmetic, conversions, calls; real literals become
118- untyped constants that take `F32` or `F64`.
119-- [x] 13. A thread-safe `lib/Heap.raz`: its bad sizes refused, and a
120- marker in each block's header so that freeing a block twice, or
121- one it never gave out, stops the program; `Out` locks its buffer.
122- An example with threads from `pthread_create`.
123- Native threads for programs without C, in
124- `lib/Thread.linux-x86_64.raz`: `spawn` on an `mmap`ed stack with
125- a guard page, through `clone` and a small code procedure; `join`
126- and a `Mutex` through `futex`. `link static;` marks a module that
127- needs a program without C; the compiler refuses a program that
128- uses both.
129-- [x] 14. Line numbers for gdb: `.debug_line`, with the least of
130- `.debug_info` and `.debug_abbrev` that gdb needs.
131-
132-Tools
133-
134-- [x] 15. Versions first: the report says its version, by date
135- (`2026-10.0`, then `.1` for the next change that month), and
136- ends with what each version changed; `raz --version` prints its
137- own and the report's, `raz 0.3.0, report 2026-10.0`. Each
138- finished stage is tagged, `v0.3.0` for stage 3. Then
139- `tools/Doc.raz`, a raz program: prints a module's own
140- comment, the one before `module`, then its exported
141- declarations, each with the comment just before it; and pulls
142- out the examples of `doc/raz.md` that are whole modules.
143- `make check` also compiles those examples, running the ones with
144- a `main`, and runs each library module's `main` as its test.
145- The test runner stays in the Makefile: it must work when the
146- compiler doesn't. (Tagging is left for later, at the owner's
147- word.)
148-
149-- [x] 16. Editor support: `editor/vim` (`syntax/raz.vim`, `indent/raz.vim`
150- by `shiftwidth()`, and `ftdetect/raz.vim`, which sets 4 spaces)
151- and `editor/emacs/raz-mode.el` (indenting by `raz-indent-offset`,
152- 4 unless set). Both colour reserved words, basic types, built-in
153- procedures, numbers, characters, strings and nested comments.
154- `make check` loads each, headless, on the examples. And a stress
155- test of native threads, `make stress`: 40,000 threads spawned and
156- joined, about 200 alive at once and waiting on one `Mutex`, so a
157- stack `join` failed to free would run the process out of mappings;
158- `spawn` under a low thread limit fails with `Thread.Failed`. A small
159- version of it runs in `make check`.
160-
161-Wrap up
162-
163-- [x] 17. `README.md` and `doc/compiler.md`, a guide to reading the
164- compiler file by file.
165-
166-Later
167-
168-- [x] 18. `tools/Pretty.raz`, a formatter that keeps every line break
169- and comment where it is: it fixes indentation (4 spaces a level)
170- and the spaces around operators and after `,` and `;`, and
171- leaves formatted code as it is. It shares with `Doc.raz` a
172- scanner that keeps comments, `tools/Scan.raz`. `make fmt` checks
173- that `lib/`, `examples/` and `tools/` come through unchanged, and
174- `make check` does too, with the cases in `test/pretty`.
175-
176-Stage 4: diagnostics
177-
178-Messages second to none: each error exact and alone, with the source
179-under it, notes and suggestions; every error in a run, not just the
180-first; warnings for what is never used; and run-time failures that say
181-what failed and where. The budget grows to 6,000 lines for it.
182-
183-A message looks like this, with colour when standard error is a
184-terminal and `NO_COLOR` is unset:
185-
186-```
187-T.raz:5:10: error: y isn't declared
188- 5 | x := y + 1;
189- | ^
190-help: did you mean x?
191-T.raz:3:5: note: x is declared here
192- 3 | var x: I64;
193- | ^
194-raz: 1 error
195-```
196-
197-How messages are worded, for every step that writes one: lowercase,
198-no full stop, the report's plain words; name the things involved
199-(`a`, an `I64`) rather than describe them; say what was expected and
200-what was found; one fact per line, the rest in notes and help.
201-Symbols are quoted with `"`, names and types are not.
202-
203-The work splits between the main model, which designs the machinery
204-and writes the tricky code (marked *main*), and subagents on weaker
205-models, which do the wide, mechanical parts against an interface the
206-main model has fixed first (marked *agent*). Agents work one per
207-file, so that they can run side by side without touching each
208-other's lines; each runs `make check` before handing back, and the
209-main model reads every diff before it is committed.
210-
211-- [x] 19. The report first, for review before any code: messages,
212- warnings and `-Werror` in section 10, run-time messages in
213- sections 6.5 and 10, report version `2026-10.1`. *main*
214-- [x] 20. `src/diag.pas`, the one place messages are made: a position
215- (a file and a stretch of bytes, its line and columns worked out
216- only for a message); the source excerpt
217- and its underline, colour, notes and help; counting errors and
218- warnings, the summary, `-Werror`, the exit status. `Mark` and
219- `Fatal` move there. `test/err` and `test/pretty` keep working:
220- `X.err` becomes the whole message, without colour, and the
221- Makefile compares all of it. *main*; regenerating and checking
222- the 57 `.err` files, *agent*.
223-- [x] 21. Exact positions. An item and a statement remember where
224- they start, so an error points at the whole offending
225- expression, not the symbol after it; a missing `;`, `then` or
226- `end` points just after the symbol before it. The scanner keeps
227- the previous symbol's end. The machinery, *main*; moving each
228- of the 200 `Mark` calls onto the right position, *agent*, one
229- per file.
230-- [x] 22. Going on after an error. Each statement and declaration is
231- a recovery point (`setjmp`): an error jumps back to it, the
232- scanner rereads it from its start and skips to its end, and the
233- parser carries on with the next; no error site goes on past its
234- error, so none needs reviewing. A name not declared is declared
235- with a poison type where it is first used, as are the names of a
236- declaration with an error, and errors in a construct that uses
237- poison aren't reported. A symbol at the start of a line ends a
238- skip: it starts the next declaration, and its procedure is given
239- up. Code is still generated, then thrown away; at most 20 errors;
240- an error in the text, or a module with errors, stops the run.
241- *main*.
242- `tools/Mutate.raz`, which deletes, doubles and swaps symbols in
243- the tests that compile; `make check` runs it with fixed seeds
244- and fails on a crash or two messages at one place. Writing it
245- and sorting what it finds, *agent*; the fixes in `gen.pas`,
246- *main*.
247-- [x] 23. Every message reworded to the rules above, each with a test
248- in `test/err` that pins its position too. *agent*, one per file
249- (`scan.pas`, `parse.pas` in two halves, `gen.pas`, the rest),
250- against a list of messages and their tests the main model writes
251- first; *main* reviews the wording as a whole.
252-- [x] 24. Notes and help. Objects remember where they are declared:
253- "declared here", "the first one is here", "the signature is
254- here". The checks on `main` in `raz.pas` point at
255- it, so that every error has a place (the fuzzer finds them). Did you mean: the closest name by edit distance in the
256- scopes in reach, in a module's exports, among the built-ins
257- (`len` for `LEN`). Slips from other languages: `!=`, `==`, `=`
258- for `:=`, `&&`, `||`, `!`, `elif`, a missing `then` or `do`, a
259- missing import. The machinery, *main*; the catalogue of slips
260- and their tests, *agent*.
261-- [x] 25. Warnings: an unused import; an unused constant, type,
262- variable or procedure that isn't exported; an unused parameter
263- of a procedure written in raz; a variable assigned but never
264- read. A name starting with `_` is never warned about. `-Werror`
265- makes them errors, and `make check` builds `lib/`, `examples/`
266- and `tools/` with it. The machinery, *main*; clearing the
267- warnings it finds in `lib/`, `examples/` and `tools/`, *agent*.
268-- [x] 26. Run-time messages. A failed check says which and with what
269- values: `index 7 is out of range for a length of 5`, the slice,
270- the enumeration position, at file, line and column. A table from
271- code addresses to lines goes into the executable, and `Rt` sets
272- handlers for SIGSEGV and SIGFPE that print where the program was
273- and why (a `nil` pointer, a `nil` procedure, stack overflow, a
274- bad address, a division fault) before it dies by that signal.
275- Run tests gain an optional `X.stderr`. And the lowest `I64`
276- divided by -1 stops the program with SIGFPE, as the report says
277- (6.1), and is told as a division fault.
278- The compiler and `Rt`,
279- *main*; the tests, *agent*.
280-- [x] 27. `doc/compiler.md` (its table and routine names), `README.md`
281- and `CLAUDE.md` brought up to date; `make loc` within 6,000 and
282- 10%, `make bench` at 400,000 lines a second. *agent*, checked by
283- *main*.
284-
285-Stage 5: ravite, an editor
286-
287-(The editors have since moved to repositories of their own, rmacs with
288-emacs's keys and ravite with vim's, each pinning the raz it builds
289-with; what follows is how they were made here.)
290-
291-ravite (raz visual text editor) is a terminal editor written in raz,
292-good enough to write raz in every day, with emacs's keys. It lives in
293-`ravite/`. Its first version had vim's keys (steps 28 to 33); the
294-owner chose emacs's instead, with more of emacs: buffers, the
295-minibuffer, ido, a small dired, M-x, and settings. Steps 28, 29 and 31
296-stand as they are; the rest is redone from step 35.
297-
298-Ground rules, besides the plan's:
299-
300-- No line budget: code that is easy to read and follow, and well
301- commented, comes before its length (the owner's word, after step
302- 40). `make loc` counts it, as a measure.
303-- On Linux a program without C, a static executable; what it needs of
304- the system is `Sys`'s (steps 34 and 41), so that over the C `Sys`
305- it runs through the C library.
306-- Every session test, `test/ravite/X.keys`, does what emacs (`emacs -Q
307- -nw`) does with the same keys, checked when it is written, except
308- where ravite says it differs (`doc/ravite.md`).
309-- `make ravite` builds `build/ravite`; `make install` puts it on PATH;
310- `make check` runs its tests; `make fmt` covers `ravite/`.
311-
312-What it does, with emacs's keys and names:
313-
314-- **Editing.** C-f C-b C-n C-p and the arrows, C-a C-e, M-f M-b, M-<
315- M->, C-v M-v, C-l, M-g g, M-{ M-}; typing, RET with the line's
316- indent, TAB to the next multiple of 4, DEL C-d, M-DEL M-d, C-k, C-o,
317- C-t, M-u M-l M-c. The mark and the region, shown: C-SPC, C-x C-x,
318- C-x h, C-w, M-w; the kill ring: C-y, M-y, kills in a row add up.
319- C-/ C-_ C-x u undo; M-x undo-redo. C-u and M-digits for a count.
320- C-g gets out of anything.
321-- **Search.** C-s and C-r search incrementally, for text; M-% replaces,
322- asking y n ! q at each.
323-- **Buffers.** Any number. C-x C-f finds a file, C-x C-s saves, C-x
324- C-w writes to another name, C-x s saves those that need it, C-x b
325- switches, C-x k kills, C-x C-b lists them in a buffer of their own,
326- C-x C-c quits, asking about unsaved buffers. `*scratch*` is there
327- from the start, a buffer that is no file.
328-- **The minibuffer.** One line at the bottom, edited with the same keys
329- as any buffer. ido completes in it, for buffers, files and M-x:
330- the candidates that hold what is typed show after it, C-s and C-r
331- turn them round, TAB completes, RET takes the first, C-j takes what
332- is typed; for files, / goes into a directory and DEL out of one.
333-- **Dired.** C-x d, or finding a directory, lists it: RET or f opens
334- what is on the line, ^ goes up, n and p move, g reads it again, +
335- makes a directory, R renames, D deletes a file after a yes, q leaves.
336-- **M-x and settings.** Every command has a name and runs by M-x. Keys
337- are bound to names in keymaps, with C-x and M-g as prefixes. At
338- start ravite reads `~/.ravite`, lines of `bind KEYS COMMAND` and
339- `set VARIABLE VALUE`, keys written as emacs writes them (`C-x C-s`,
340- `M-%`). M-x global-set-key and set-variable do the same while it
341- runs; C-h k and C-h b say what keys do. The variables: indent,
342- tab-width, colour, ido.
343-- **The screen.** The buffer, a mode line (`-UU-:**- name L12 Top`)
344- and the echo area, which the minibuffer shares. Long lines scroll
345- sideways. A `.raz` buffer is coloured as before; `NO_COLOR` or `set
346- colour off` turns it off.
347-
348-What it leaves out: several windows, the mouse, the system clipboard,
349-undo in a tree (undo and redo are a line), patterns (search is for
350-text), major modes and their indenting, Lisp, the minibuffer's history,
351-and dired's marks. FreeBSD comes once `Sys` has what ravite needs.
352-
353-The modules:
354-
355-| Module | Lines | What |
356-|---|---|---|
357-| `Tty.linux-x86_64.raz` | 120 (155) | the terminal, directories and files, until `Sys` has them |
358-| `Keys.raz` | 220 (271) | a key from the bytes a terminal sends, Meta too; keys written as emacs writes them |
359-| `Text.raz` | 330 (337) | the text, a gap buffer, with undo and redo |
360-| `Colour.raz` | 110 (109) | the colour of each byte on the screen |
361-| `View.raz` | 170 (121) | the screen: the buffer, the mode line, the echo area |
362-| `Core.raz` | 300 (375) | buffers, the current one, the echo area, reading keys and running them, through procedures the main module sets |
363-| `Edit.raz` | 450 (558) | moving, typing, deleting, the mark, the kill ring, undo |
364-| `Mini.raz` | 350 (269) | the minibuffer, ido, yes or no |
365-| `Search.raz` | 200 (241) | incremental search, query-replace |
366-| `Dired.raz` | 250 (336) | directories, and the list of buffers |
367-| `Commands.raz` | 400 (799) | the commands' names, keymaps, M-x, settings, help, files and buffers |
368-| `Ravite.raz` | 250 (271) | the arguments, the screen, the keys from the terminal or a script, the loop |
369-| total | 3,150 (3,842) | |
370-
371-In brackets, what each came to by step 40: 3,842 lines, past the
372-3,300 then planned. The owner set the budget aside for readability;
373-step 41 took `Tty`'s 155 lines out to `Sys`.
374-
375-Testing. `ravite -script W H file...` reads keys as emacs writes them
376-from standard input, on a screen W by H, and at their end, or at C-x
377-C-c, prints the screen as plain text, then the current buffer. Each
378-`test/ravite/X.keys` has its `X.expect`, and may have an `X.txt` to
379-start from, or `X.args` for other arguments. Each module's `main` is
380-its test.
381-
382-Steps 28 to 33 (vim's keys):
383-
384-- [x] 28. `Tty` and `Keys`, with `Keys`'s test; raw mode, the size
385- and the keys tried through a pseudo-terminal.
386-- [x] 29. `Text`: the gap buffer and undo, with its test.
387-- [x] 30. `View` and `Ravite` with vim's keys; `-script` and
388- `test/ravite`; `make ravite`, `make loc` and `make fmt`.
389-- [x] 31. `Colour`.
390-- [x] 32. Visual mode, search, `%`, `f t`, and `file:line`.
391-- [x] 33. `doc/ravite.md`.
392-
393-Steps 34 on (emacs's keys):
394-
395-- [x] 34. The report: what `Sys` gains for ravite, for review before
396- any code (report version `2026-10.2`).
397-- [x] 35. `Keys` with Meta and emacs's notation; `Core`, `View` with a
398- mode line and the echo area, `Edit`, `Commands` with keymaps and
399- C-u, `Mini` without ido, and `Ravite`: editing with emacs's keys,
400- finding, saving and writing files, M-x by full name, quitting; the
401- session tests, checked against emacs.
402-- [x] 36. ido in the minibuffer, for M-x, files and buffers; buffers,
403- `*scratch*`, C-x b, C-x k, C-x C-b, C-x s, C-x C-c.
404-- [x] 37. `Search`: C-s, C-r, M-%.
405-- [x] 38. `Dired`.
406-- [x] 39. Settings: `~/.ravite`, M-x global-set-key and set-variable,
407- C-h k, C-h b.
408-- [x] 40. `doc/ravite.md` again, `README.md`, `CLAUDE.md`; `test/emacs.py`,
409- which checks a session against emacs.
410-- [x] 41. Once the owner approves step 34: `Sys` gains it, on Linux
411- and over C, with tests; ravite's `Tty` goes. `make check` runs
412- ravite's sessions over both.
413-
414-Stage 6: the language of report 2026-10.3
415-
416-The owner's choices after stage 5, written into the report first:
417-results passed on by `return`; `and`, `or` and `not` for `BOOL`s only,
418-binding below the relations, and `&`, `|`, `~` for bits, as in Go; `=`
419-on arrays and slices of plain elements, compiled where it stands
420-rather than called in `Rt`, so that no syntax runs hidden library
421-code; and generic instances made where they are first used, so that
422-their arguments may name types declared after the imports. Not
423-started: each step waits for the owner's word, and stage 4's open
424-steps come first unless the owner says otherwise.
425-
426-- [x] 42. The report, version 2026-10.3: sections 2, 3, 6, 6.5, 7.3, 8
427- and 11, and the list of versions. Approved before any code.
428-- [x] 43. `return f(x);`: the call's results are copied behind the
429- procedure's own hidden pointer, the one its caller gave it. The
430- results must be the procedure's, type for type; `test/err` for
431- a mismatch, `test/run` for one, two and three results, through
432- two levels of calls.
433-- [x] 44. `=` and `#` inline: the lengths compared, then, if equal,
434- the bytes, `LEN * SIZE(T)` of them, with `repe cmpsb`; for
435- strings and for arrays and slices of integers, `BOOL`s,
436- enumerations, sets and pointers, any mix of `[n]T` and `[]T`.
437- `Rt.eq` goes, and CLAUDE.md's note that the compiler finds it by
438- name. Tests: equal, of different lengths, empty, a string
439- literal against an array, and in `test/err` arrays of `F64`, of
440- records, and of two element types.
441-- [x] 45. Operators: `&` and `~` in the scanner, `|` an operator where
442- an operand came before it; the parser's levels, `or` over `and`
443- over the relations; `and`, `or`, `not` refused on integers and
444- `&`, `|`, `xor`, `~` on `BOOL`s, each with a message that names
445- the other. Every raz source moves to the new operators: `lib/`,
446- `tools/` (Pretty spaces `&` and `|` as it spaces `+`, and
447- leaves a match arm's `|` where it is), `examples/`, `test/`, the
448- report's examples, and `test/genbench.py`; each `and` or `or`
449- between relations is checked by hand, since its meaning may
450- change without an error. `make bench` must still pass.
451-- [x] 46. Generic instances on first use: the import keeps its
452- arguments unresolved, and the instance is made, and its body
453- queued to run before the importer's, the first time the import's
454- name is used; an argument not declared by then is an error at
455- the import. Tests: a type declared after the import, two imports
456- sharing one instance, an import never used (no instance), and
457- the error.
458-- [ ] 47. `doc/compiler.md` (its table and routine names),
459- `README.md`, CLAUDE.md's readings, the report's first line and
460- the compiler's to 2026-10.3; `make loc` within 6,000 and 10%,
461- `make bench` at 400,000 lines a second. Then the editors, rmacs
462- and ravite, move their pin to this raz, in their own
463- repositories, with their sources moved to the new operators.
464-
465-Stage 7: Sys for rlX11 and rat, report 2026-10.4
466-
467-rlX11, an X11 client library written in raz, and rat, a terminal
468-emulator over it, are to need no C: they talk to the X server over a
469-socket, and rat runs its programs on a pseudo-terminal. Sys gains what
470-that takes. Approved; under way, each step on the owner's word.
471-
472-- [x] 48. The report, version 2026-10.4: `connect`, `readyOf`,
473- `openPty`, `setTermSize`, `spawn`, `wait`, `kill` (section 11),
474- for review before any code.
475-- [x] 49a. The owner approves 2026-10.4. `connect` and `readyOf`, what
476- rlX11 needs first: on Linux `socket` (close-on-exec) and
477- `connect` for a Unix socket, `poll` over several fds; over C
478- by POSIX's names, `struct sockaddr_un` named glibc's. Both
479- files' tests: `connect` refused where nothing listens, and taken
480- by a listener the test makes, which `readyOf` then finds ready;
481- a byte across, and the end of the connection.
482-- [x] 49c. `send` (report 2026-10.7), at the owner's word: `write` to
483- a socket with `MSG_NOSIGNAL`, -32 (EPIPE) where `write` would
484- bring SIGPIPE. Both tests send to a connection closed.
485-- [x] 49b. The rest, for rat: `/dev/ptmx` with `TIOCSPTLCK` and
486- `TIOCGPTN` for the pseudo-terminal, `TIOCSWINSZ` for its size;
487- `fork`, then in the child `setsid`, the terminal opened as its
488- controlling one with `TIOCSCTTY`, `dup2` to 0, 1 and 2,
489- `close_range` for the rest, and `execve` with the environment
490- made from this one's; `wait4`, `kill`. Over C by POSIX's names
491- (`posix_openpt`, `grantpt`, `unlockpt`, `ptsname`, `fork`,
492- `execve`, `waitpid`, `kill`), what is glibc's named in the
493- file, as before. Both files' tests: a program spawned on a
494- pseudo-terminal that prints its size and its arguments and ends
495- with a status read back by `wait`; a program stopped by `kill`.
496-- [x] 49d. `Info`'s `file` and `symlink` (report 2026-10.6, for rloc,
497- which walks a tree and must not open a pipe): on Linux `lstat`,
498- then `stat`; over C the same by POSIX's names, `struct stat`
499- glibc's. The report's `link` becomes `symlink`, since `link` is a
500- reserved word. Both tests: a file, a directory, `/dev/null`, and
501- a link to a directory.
502-
503-Stage 8: one module to a name, report 2026-10.5
504-
505-A module found in two directories was taken from the first, silently,
506-by every module that imports it: a program's `C.raz` stood in for the
507-library's `C` inside `Rt`, and the compiler said only "Rt imports
508-itself". Done.
509-
510-- [x] 50. The report, version 2026-10.5: one module to a name, the
511- link that chooses a file, libraries' prefixes (section 3), for
512- review before any code.
513-- [x] 51. `ModuleFile` goes on through the later directories once it
514- has found a module's file, and an error names the files of each
515- other directory that has the module, unless the file found is a
516- symbolic link to one of them (compared by device and inode). A
517- test in `test/err` with a `C.raz` of its own; `test/libc`, and
518- ravite's `ravite-c`, still build through their link to
519- `lib/Sys.raz`. `Report` in `src/raz.pas` goes to 2026-10.5
520- with it, or with step 49, whichever comes last.
521-
522-Stage 9: several results in place of var parameters, report 2026-10.8
523-
524-At the owner's word: a procedure gives back what it makes as its
525-results, not through a `var` parameter. Done.
526-
527-- [x] 52. The report, version 2026-10.8: `Sys.workDir` returns the
528- directory, good until the next call, and an errno.
529-- [x] 53. Both Sys files: `workDir` from a buffer of the module's;
530- `cstr`, which fills its caller's storage rather than making a
531- result, takes a slice, as `read` does. What is left of `var` is
532- the tests of the feature itself.