raz / commit 4efc5101

commit
4efc5101b539a5e8935ce12e366e034be479cd8b
author
Luis <42945842+ldiaz94@users.noreply.github.com>
date
parent
498caf72
Docs: tidy CLAUDE.md, PLAN.md and README

CLAUDE.md says where things stand in a paragraph, leaving the history
to git and doc/report-history.md, and names sbcl/. PLAN.md cuts Self,
which is done, and shortens the dropped inline wish. The finished
audit, doc/proposal-10.22.md, goes; gen.pas is Gen.raz; the library is
volume 2, not section 11; X64.raz is 1,237 lines.

patch · log

5 files changed, +35 -253

CLAUDE.md modified +22 -44

@@ -78,50 +78,26 @@
7878
7979 ## Where things stand
8080
81-Steps 1-18 are done: the language, the tools (`tools/Doc.raz`, and
82-the formatter, `tools/Pretty.raz`, over the shared `tools/Scan.raz`),
83-`README.md` and the guide to the compiler, `doc/compiler.md`. Stage 5
84-made two editors, which now live in repositories of their own, each
85-pinning the raz commit it builds with: rmacs (emacs's keys) and
86-ravite (vim's). What they needed of the system went into `Sys` (report
87-2026-10.2, approved): the terminal, files, directories and the
88-environment. `tools/Scan.raz` is theirs to use, as a tool, not part of
89-the library. Stage 4, diagnostics (steps 19-27), is done; so are
90-stage 6, the language of report 2026-10.3 (steps 42-47), and stage 8,
91-one module to a name (report 2026-10.5, step 51), and stage 7, `Sys`
92-for rlX11 and rat (reports 2026-10.4 and 10.7, steps 49a-c), with
93-`Info`'s `file` and `symlink` for rloc (2026-10.6, step 49d), and
94-stage 9, several results in place of var parameters (2026-10.8,
95-steps 52-53), and v0.5.0, the library of report 2026-10.9, which the
96-compiler says it follows, and v0.7.0, better code, and v0.7.1, the manual: `raz(1)`,
97-`raz-tutorial(7)`, `raz(7)` and `raz-lib(3)`, made by `tools/Doc.raz`
98-from `lib/`, and v0.8.0, better code again: slices in registers,
99-parameters left in rdi and rsi, operands as the machine has them,
100-`while` tested at the bottom, and one line table, DWARF's, and
101-v0.9.0, better code for reals: reals on the stack and the
102-busiest real variables in xmm registers, and an array's element and a
103-constant offset as operands, measured on two kernels of reals,
104-`Jacobi` and `NBody`. `make kernels` measures `test/bench` against
105-FPC `-O2`. Self (`PLAN.md`) is done: `src/` is the compiler in raz, and
106-the seed in `seed/` is frozen. Next, by `PLAN.md`: what the owner chooses.
81+v0.11.1, report 2026-10.23, is the latest release. `src/` is the
82+compiler in raz, built by itself (Self, done); the seed in `seed/` is
83+frozen, and v0.9.1 was the last release it built. The compiler takes
84+1.4 times the Pascal one's time; `make kernels` measures `test/bench`
85+against FPC `-O2`. Next, by `PLAN.md`: what the owner chooses. What
86+each version of the report changed is in `doc/report-history.md`, and
87+what each step did is in git; don't repeat it here.
10788
89+rmacs (emacs's keys) and ravite (vim's), the two editors written in
90+raz, live in repositories of their own, each pinning the raz commit it
91+builds with; they use `tools/Scan.raz` as a tool, not part of the
92+library. rat, rlX11 and rloc are other users of `Sys`.
93+
10894 **The freeze.** Since v0.5.0 the language changes only to mend a
10995 defect, and the library grows only by what breaks no program written
11096 for it. A wish for more, the owner's or yours, goes on the list in
111-`PLAN.md`, for a later thaw; it isn't built. v0.6.0 was such a thaw,
112-by the owner's word: report 2026-10.12; the compiler follows 2026-10.23, whose `Math` exports `bits`, `fromBits` and `mul` for reading reals exactly, and 2026-10.22, an audit of the report (mends, trims,
113-two volumes, status 2 for every stop), and 2026-10.21, whose `match` on an enumeration takes
114-several names to an arm (10.21), and 2026-10.20, whose `try` returns an error that isn't
115-nil from the procedure it stands in (10.20, the owner's word), and 2026-10.19,
116-whose `Sys` writes without waiting, for rat's pastes (10.13), and
117-whose blank, `_ := f(x)`, drops a result that is otherwise warned of
118-(10.14), and whose `Math` has `pow`, the logarithms to 2 and 10,
119-rounding and the inverse functions, and `Sys` `space` (10.15), and
120-whose constants may be records and tables of them, with `Str.copy`
121-(10.16), and `COPY` (10.17), also by the owner's word, and whose code
122-procedures take and return slices (10.18), and whose library has
123-`Bytes` (10.19). Its parser
124-reaches the machine only through `gen.pas`. Keep
97+`PLAN.md`, for a later thaw; it isn't built. Thaws happen only by the
98+owner's word (v0.6.0, and reports 2026-10.13 to 10.23).
99+
100+The parser reaches the machine only through `Gen.raz`. Keep
125101 `doc/compiler.md`'s table of lines and its routine names true when the
126102 compiler changes.
127103
@@ -132,10 +108,8 @@
132108 `.github/workflows/ci.yml`, which checks it and makes the GitHub
133109 release with a tarball of `raz` and `lib/`; it also checks every push
134110 to `main`. `README.md`'s "Versions" gives the commands. v0.3.0 is
135-the first; v0.11.1, report 2026-10.23, the latest: the compiler in raz,
136-built by itself, and 1.4 times the Pascal one's time (v0.9.1 was the last
137-built by the Pascal seed). The tarball has `tools/`, which the website
138-offers from 0.7.1 on.
111+the first. The tarball has `tools/`, which the website offers from
112+0.7.1 on.
139113
140114 `test/libc` runs its programs over `lib/Sys.raz`, the C one, through
141115 a link in its `mods`. A test or example without `.expect` is only
@@ -149,6 +123,10 @@
149123 `src/` the first time and as the reference its units are tested
150124 against, and to be dropped in time. Never edit the seed; a difference
151125 found goes on the plan, for the owner.
126+
127+`sbcl/` is an example, not part of the build: a second compiler, in
128+Common Lisp, written from the report alone and kept as a reference
129+(`sbcl/README.md`).
152130
153131 ## Readings of the report already taken
154132

PLAN.md (history) modified +11 -88

@@ -5,66 +5,11 @@
55 stopping for the owner's review. A finished milestone is cut from this
66 file: git keeps the history, and the report's history, `doc/report-history.md`, the language's.
77
8-v0.11.1, report 2026-10.23 (`Math` exports `bits`, `fromBits` and `mul`), is the latest release; v0.11.0, report 2026-10.22, was the audit of `doc/proposal-10.22.md`; v0.9.1 was the last built by the seed. All before
9-v0.7.1 is approved by the owner; v0.7.1, v0.8.0, v0.9.0 and v0.9.1 wait
10-for the owner's review. One milestone is under way: Self.
11-
12-## Self: the compiler in raz (under way)
13-
14-For: a compiler written in raz that compiles itself, so that raz needs
15-no Free Pascal. The Pascal compiler in `seed/` is the **seed**: it is
16-never edited for this, and stays the one `make check` builds. The new
17-compiler lives in `src/`, one raz module to a seed unit, the same
18-names, and has its own targets; nothing in `seed/` or `lib/` changes.
19-
20-The language gained `try` (report 2026-10.20) for this: the parser's
21-errors return an `ERROR` (`Scan.Failed`) that `try` passes up to where
22-it reads on, in place of the seed's `longjmp`.
23-
24-Each unit is ported in the seed's order (leaves first) and tested on
25-its own against the seed's, on the same inputs, since no program can
26-link both. The language and the library are frozen: a gap found goes
27-on the wish list, a defect is mended.
28-
29-Steps:
30-
31-1. `diag` and `scan` (done): the trial. Measure `scan`'s speed against the
32- seed's and list what `Sys` and the library lacked. Stop for review:
33- if the cost is too high, mend the code generator first.
34-2. `chunk`, `sym` (2a, done); `link`, `elf`, `x64` (2b, done).
35-3. `gen` (3a, done: `Gen.raz`, tested by `test/GenDump`, a script of
36- calls whose bytes and listing are the same), `item` (3b, done: `Item.raz`, tested by
37- `test/ItemDump`, 60 scripts of operations with mistakes in them).
38-4. `parse`, `raz` (done: `Parse.raz`, `Raz.raz`): the first compiler that
39- builds, tested by compiling 409 programs, the library and the compiler
40- itself with both and comparing the executables, messages and status;
41- 452,000 lines a second, the seed's 815,000.
42-5. Fixpoint (done: `src/fixpoint.sh`, `make fixpoint`): the seed builds `src`, that builds `src`, that builds
43- `src` again, and the last two are byte for byte the same (all
44- three are, 547,000 bytes: the seed and this compiler make the same
45- code from `src/`). `make check` passes on the compiler it made,
46- 661 tests, and `make bench` gives 493,000 to 870,000 lines a second.
47- Then `seed/` is frozen and `self/` is `src/` (the owner's word,
48- 2026-10-13); the seed is dropped in time, its last tag the bootstrap.
8+v0.11.1, report 2026-10.23, is the latest release. All before v0.7.1
9+is approved by the owner; v0.7.1, v0.8.0, v0.9.0 and v0.9.1 wait for
10+the owner's review. No milestone is under way: the last, Self (the
11+compiler in raz, built by itself), is done, and `seed/` is frozen.
4912
50-6. Faster (done, the owner's word, 2026-10-13: the compiler built by
51- itself took 1.8 times as long as the Pascal one, and 1.3 was the aim).
52- `perf` found no hot spot but habits of the code: small blocks cleared
53- and copied by `rep`, a record literal made in a temporary and copied,
54- an element through a pointer worked out, `try` through a slot of the
55- frame, a `var` parameter's address loaded at each use, and a few
56- routines of the scanner. `doc/compiler.md`, "Better code, for the
57- compiler itself", has each, with what it measured and what did not
58- help. The compiler takes 506 ms of 359 for the 348,025-line program,
59- 1.4 times (1.36 by cycles; before 657 of 359, 1.8 times); `make
60- bench`, 678,000 lines a second. The seed's code is no longer what
61- `src/` makes, so `seed-check` no longer compares `Gen`, `Item` or
62- the executables, only messages and statuses, and the fixpoint is of
63- stage 2 and 3.
64-
65-Done when step 5 passes with `make check` and `make bench` on the
66-compiler it made, and the budget of lines kept.
67-
6813 ## Next, when the owner says
6914
7015 - The book, "Compiling Raz": its brief is `doc/book/PLAN.md`.
@@ -73,7 +18,7 @@
7318 would take call overhead off some 15% of the instructions; `chooseRegs`
7419 reads each procedure twice, which is 13% of the time; and `Mem`, `Item`
7520 and `Adr` are records copied at each call that passes them on.
76-- A port to aarch64, to measure one: a new `gen.pas`, an encoder and
21+- A port to aarch64, to measure one: a new `Gen.raz`, an encoder and
7722 assembler for it, and its ELF.
7823
7924 ## Wishes, for a later thaw
@@ -81,35 +26,13 @@
8126 What the language or the library might have, met while writing raz;
8227 none is built while the freeze holds.
8328
84-- **`inline`, a hint.** `proc zeros(v: U64): U64; inline;`, placed as
85- `forward` is: the compiler copies the procedure into each call
86- instead of calling it. A hint an implementation may ignore, so a
87- program means the same everywhere and `conform/` is untouched. This
88- compiler would take it for a procedure whose body is a single
89- `return e`, with value parameters, in the same module, and refuse
90- the mark on any other: the call site's arguments go to temporaries
91- and `e` is read again there (`SaveScan`/`RestoreScan`, as for
92- generic instances), its parameters bound to them. About 100 lines.
93- Measured (2026-10-13): `test/bench/Grep` with its two helpers
94- inlined by hand ran 188 ms against 250, 30% off the kernel's own
95- time, since the loop's values then stay in registers, not the
96- frame; FPC `-O2` with `inline` gains as much. `tools/Pretty` gained
97- nothing: its small procedures cost their work, not their calls.
98- Dropped as a language change (2026-10-13): a hint means nothing a
29+- **`inline`, a hint** (dropped, 2026-10.13): a hint means nothing a
9930 program can see, and this compiler can inline by itself, with no
100- keyword. Debugging would be settled by keeping the callee's lines
101- in the line table as rows that aren't statements (DWARF's
102- `is_stmt`): gdb steps over them, `Rt` still tells a failure at its
103- expression; only `Rt.trace` loses the callee's frame.
104- Measured on rat's 26 MB workload (477 ms): its hot procedures are
105- almost never a single `return e`, and inlining those by hand gained
106- nothing. What did gain, 12%, was hoisting the fast path of two small
107- procedures into their callers by hand: `Width.cells` (`if c < 300H
108- then return 1`) and `Screen.unsplit` (a guard, then rare work),
109- called for every character. An inliner for that, statements and
110- early returns and procedures without results, is several times the
111- size; the same 12% is a few lines in rat. Revisit only if more
112- programs show it.
31+ keyword. Measured: `test/bench/Grep` with its helpers inlined by hand
32+ ran 30% faster; rat's hot procedures gained nothing from it, but 12%
33+ from hoisting two fast paths by hand (`Width.cells`,
34+ `Screen.unsplit`), which is an inliner several times the size. Revisit
35+ only if more programs show it.
11336 - **A `const` parameter.** `proc what(const x: Item): []U8;`: the callee
11437 may not change `x` (nor take its address), so the caller may pass the
11538 address of a record or array without a copy, and the program means the

README.md (history) modified +1 -1

@@ -166,7 +166,7 @@
166166 (buffered output), `C`, `Lock`, `Thread` (threads without C), `Mem`,
167167 `Heap`, `Arena`, `Str`, `Bytes`, `Buf`, `Fmt`, `Math`, `Files`, `Opt` (a command
168168 line read through one table), `List(T)`, `Map(K, V; hash, eq)` and
169-`Sort(T; less)`. Section 11 of the report gives each one's interface,
169+`Sort(T; less)`. Volume 2 of the report, `doc/raz-lib.md`, gives each one's interface,
170170 and `tools/Doc.raz` prints it from the module's file:
171171
172172 $ ./raz -o Doc tools/Doc.raz && ./Doc lib/Str.raz

doc/compiler.md (history) modified +1 -1

@@ -17,7 +17,7 @@
1717 | `src/Scan.raz` | 1,062 | 886 | Symbols, literals, comments, positions |
1818 | `src/Sym.raz` | 684 | 555 | Types, objects, scopes, layout |
1919 | `src/Chunk.raz` | 354 | 272 | The compiled program: chunks, fixups, line notes |
20-| `src/X64.raz` | 1,493 | 1,238 | The instruction encoder, jumps within a procedure, the assembler |
20+| `src/X64.raz` | 1,493 | 1,237 | The instruction encoder, jumps within a procedure, the assembler |
2121 | `src/Gen.raz` | 2,471 | 1,778 | The stack machine, for x86-64: values, operations, checks, calls, frames |
2222 | `src/Item.raz` | 1,763 | 1,458 | Items: types, constants, variables, operators, conversions, calls |
2323 | `src/Parse.raz` | 3,846 | 3,355 | Declarations, statements, expressions, built-ins, recovery, warnings |

doc/proposal-10.22.md deleted +0 -119

@@ -1,119 +0,0 @@
1-# Proposal: report 2026-10.22
2-
3-Made from an audit of `doc/raz.md` against `conform/` and `test/`
4-(about 500 rules: ~260 pinned by `conform/`, ~130 only by `test/`, ~60
5-by no test, ~25 unsettled or in conflict). It mends defects in the
6-report and trims it; it adds no feature. Nothing in `doc/raz.md` or the
7-code changes until the owner approves each part (CLAUDE.md: a thaw).
8-
9-Decided by the owner (2026-10-14):
10-
11-- `INT` and `UINT` stay distinct from `I64` and `U64`. (The first
12- version of this proposal made them aliases; dropped.)
13-- Exported variables stay as they are. (The first version banned them;
14- dropped. Exported constants stay on `PLAN.md`'s wishes list.)
15-- Conformance keeps the error programs, but only for errors that
16- change a program's meaning; warnings and the form of messages leave
17- the report.
18-- Every run-time stop exits with status 2.
19-- The library past the core leaves `conform/`.
20-- The report is split in two volumes, after the fixes.
21-
22-## 1. What is an error, and what is free
23-
24-**Now.** Section 10 tells the compiler what to say (the form of a
25-message, "up to 20" errors, skipping to the next statement, "did you
26-mean", which warnings, `-Werror`), and Appendix A says all of that is
27-the implementation's. The two contradict.
28-
29-**Proposed.**
30-
31-- Section 10's "Messages" and warnings paragraphs move to
32- `doc/compiler.md`, "This compiler's choices". `-Werror` is this
33- compiler's option. Appendix A's line becomes "the text and number of
34- its messages, and which warnings it gives".
35-- The report states the rule once: an implementation must reject a
36- program that is an error because accepting it would give it a
37- meaning the report cannot define: a type error, an undefined or
38- repeated name, an assignment to what is read-only, a missing or
39- wrong `main`, a cycle of modules. A fault that is only a lint (an
40- unused name, a dropped result) is not an error of the language.
41-- `conform/err` is sorted by that rule: what is a language error stays
42- and is judged by status alone; a lint-like test moves to `test/err`.
43-
44-**Costs.** A pass over the 235 error tests. Nothing for a valid program.
45-
46-## 2. Run-time stops exit with status 2
47-
48-**Now.** A failed check exits with status 2 (6.8, `Rt.stop`); a nil
49-pointer, division by zero or stack overflow stops the program "on
50-every target", and this compiler dies by the signal (139, 136), so
51-`conform/` cannot pin it.
52-
53-**Proposed.** Section 10: any stop of a running program (a failed
54-check, a nil pointer, a division by zero, a stack overflow) says why on
55-standard error, whose text is free, and exits with status 2. The
56-compiler's handlers (`Rt`) end the program with status 2 rather than by
57-the signal; `conform/` gets a program for each.
58-
59-**Costs.** `Rt`'s handlers and the tests that expect 139/136 (`test/`);
60-a stack overflow in a C thread still ends by the signal (no handler
61-stack there, CLAUDE.md).
62-
63-## 3. Readings the report doesn't have
64-
65-CLAUDE.md lists readings the compiler took where the report is silent.
66-They go into the report, short, or the compiler changes:
67-
68-- 5.10 and 6.1: where `INT` widens to `I64` (assignment, argument,
69- `return a, b`) and where it does not (`a, b := f(x)`, `return f(x)`,
70- `for`, `INC`/`DEC`); an untyped constant converts to a pointer.
71-- 3: another module's exported variable is read-only: an array or
72- record in it cannot be sliced or `match`ed in place.
73-- 2: the non-reserved words are `static`, `check` and `off` (the
74- report says only `static` in one place).
75-- 7.4: which types `match` takes; `lo .. hi` with `lo > hi` is an
76- error; `defer defer f` is an error ("that would leave it" says less).
77-- 10: `main` takes no parameters.
78-- 6.1: the type of a shift whose left operand is an untyped constant.
79-- 2: a real constant of type `F32` is the nearest `F32` (the compiler
80- rounds twice, through `F64`: it follows the report or the report
81- says so).
82-
83-## 4. The library core, and the second volume
84-
85-Appendix A's core is `Rt`, `Out`, `Mem`, `Arena`, `Lock`, `Str` and
86-`Buf`. `conform/run` imports `Heap`, `Fmt`, `List`, `Map` and `Sort`
87-too. The five leave `conform/` (their tests go to `test/`; each
88-module's own `main` stays its test). The report still defines them.
89-
90-## 5. Trimming
91-
92-To `doc/compiler.md`, or out: the "Separate compilation" paragraph and
93-its twin in Appendix A, the executable and gdb sentences, the NASM
94-bullet (kept short), the library table that repeats the listings,
95-`Heap`'s nine sizes, the 64-descriptor and 107-byte numbers, `Sort`'s
96-complexity claim, `Sys.rawMode`'s key list, and the version history of
97-section 12 (a changelog, not the language). Whether `Opt` stays in
98-the report or only in `raz-lib(3)` is open.
99-
100-## 6. Two volumes
101-
102-After 1-5: volume one is sections 1-10, the core library, the grammar
103-and Appendix A; volume two is the rest of the library. `tools/Doc.raz`,
104-`make check`'s example runs and `README.md` follow the files.
105-
106-## Tests to add (conform/)
107-
108-From the audit's NONE rows that the report fixes: zero initial values
109-per kind, order of evaluation, a variant `match` that runs, generic
110-instances run once, a `defer` not reached doesn't run, a failed check
111-skips pending defers, `Sys.exit` skips `atExit`, `Str`'s byte-order
112-procedures (core), and the run-time stops of 2.
113-
114-## Order, if approved
115-
116-1. Report 1, 2, 3 and 5, in `doc/raz.md` and `doc/compiler.md`: one commit each; stop for review.
117-2. `conform/` and `test/`: the sorting of 1, the moves of 4, the tests above.
118-3. The compiler: `Rt`'s status (2), the readings that change code.
119-4. The split (6).