| | @@ -3,7 +3,7 @@ |
| 3 | 3 | raz (Polish for *one*, as in counting) is a small systems language in Wirth's |
| 4 | 4 | tradition: full control of memory, volatile access, atomics, calls into |
| 5 | 5 | C, generic modules. Its compiler is meant to be read in a long weekend: |
| 6 | | -under 5,000 lines of Free Pascal, one pass, no IR, no optimizer, writing |
| 6 | +under 6,000 lines of Free Pascal, one pass, no IR, no optimizer, writing |
| 7 | 7 | x86-64 machine code and the ELF file itself. |
| 8 | 8 | |
| 9 | 9 | The language is defined by `doc/raz.md`. Where this plan and the report |
| | @@ -14,7 +14,8 @@ |
| 14 | 14 | - The compiler is Free Pascal 3.2.2, `{$mode objfpc}{$H-}`: records, |
| 15 | 15 | pointers, shortstrings. No classes, ansistrings, exceptions, dynamic |
| 16 | 16 | arrays or SysUtils. |
| 17 | | -- The compiler stays near 5,000 lines of code (not counting blank and |
| 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 |
| 18 | 19 | comment lines), within 10%, and compiles at least 400,000 lines of |
| 19 | 20 | raz a second, from reading the sources to writing the executable. |
| 20 | 21 | `make loc` and `make bench` measure them, and a step that breaks |
| | @@ -171,3 +172,104 @@ |
| 171 | 172 | scanner that keeps comments, `tools/Scan.raz`. `make fmt` checks |
| 172 | 173 | that `lib/`, `examples/` and `tools/` come through unchanged, and |
| 173 | 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 | +T.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 | +- [ ] 20. `src/diag.pas`, the one place messages are made: a position |
| 215 | + (file, line, first and last column) and a message built in |
| 216 | + pieces, past shortstring's 255 characters; 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 | +- [ ] 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 | +- [ ] 22. Going on after an error. A poison type that every check |
| 231 | + accepts without a word, so one mistake makes one message; a name |
| 232 | + not declared is declared as poison where it is first used; after |
| 233 | + a syntax error the parser skips to the next `proc` or the end of |
| 234 | + the module; code is still generated, then thrown away; at most |
| 235 | + 20 errors. A module with errors stops the run after it. *main*. |
| 236 | + `tools/Mutate.raz`, which deletes, doubles and swaps symbols in |
| 237 | + the tests that compile; `make check` runs it with fixed seeds |
| 238 | + and fails on a crash or two messages at one place. Writing it |
| 239 | + and sorting what it finds, *agent*; the fixes in `gen.pas`, |
| 240 | + *main*. |
| 241 | +- [ ] 23. Every message reworded to the rules above, each with a test |
| 242 | + in `test/err` that pins its position too. *agent*, one per file |
| 243 | + (`scan.pas`, `parse.pas` in two halves, `gen.pas`, the rest), |
| 244 | + against a list of messages and their tests the main model writes |
| 245 | + first; *main* reviews the wording as a whole. |
| 246 | +- [ ] 24. Notes and help. Objects remember where they are declared: |
| 247 | + "declared here", "the first one is here", "the signature is |
| 248 | + here". Did you mean: the closest name by edit distance in the |
| 249 | + scopes in reach, in a module's exports, among the built-ins |
| 250 | + (`len` for `LEN`). Slips from other languages: `!=`, `==`, `=` |
| 251 | + for `:=`, `&&`, `||`, `!`, `elif`, a missing `then` or `do`, a |
| 252 | + missing import. The machinery, *main*; the catalogue of slips |
| 253 | + and their tests, *agent*. |
| 254 | +- [ ] 25. Warnings: an unused import; an unused constant, type, |
| 255 | + variable or procedure that isn't exported; an unused parameter |
| 256 | + of a procedure written in raz; a variable assigned but never |
| 257 | + read. A name starting with `_` is never warned about. `-Werror` |
| 258 | + makes them errors, and `make check` builds `lib/`, `examples/` |
| 259 | + and `tools/` with it. The machinery, *main*; clearing the |
| 260 | + warnings it finds in `lib/`, `examples/` and `tools/`, *agent*. |
| 261 | +- [ ] 26. Run-time messages. A failed check says which and with what |
| 262 | + values: `index 7 is out of range for a length of 5`, the slice, |
| 263 | + the enumeration position, at file, line and column. A table from |
| 264 | + code addresses to lines goes into the executable, and `Rt` sets |
| 265 | + handlers for SIGSEGV and SIGFPE that print where the program was |
| 266 | + and why (a `nil` pointer, a `nil` procedure, stack overflow, a |
| 267 | + bad address, a division fault) before it dies by that signal. |
| 268 | + Run tests gain an optional `X.stderr`. And the lowest `I64` |
| 269 | + divided by -1 wraps, as the report says, instead of trapping. |
| 270 | + The compiler and `Rt`, |
| 271 | + *main*; the tests, *agent*. |
| 272 | +- [ ] 27. `doc/compiler.md` (its table and routine names), `README.md` |
| 273 | + and `CLAUDE.md` brought up to date; `make loc` within 6,000 and |
| 274 | + 10%, `make bench` at 400,000 lines a second. *agent*, checked by |
| 275 | + *main*. |