raz / commit c027dc28

commit
c027dc285516a1376079df8821a0c20fbf6345a0
author
Luis <42945842+ldiaz94@users.noreply.github.com>
date
parent
accb6f2b
Plan stage 4, diagnostics; the report says how messages look

Budget to 6,000 lines. Report 2026-10.1: every error in a run,
warnings of what's never used, -Werror; failed checks and signals say
what and where.

patch · log

3 files changed, +134 -7

CLAUDE.md modified +1 -1

@@ -41,7 +41,7 @@
4141 `Luis <42945842+ldiaz94@users.noreply.github.com>`, unsigned
4242 (`--no-gpg-sign`), no attribution trailer. Push to `main`. No pull
4343 requests unless asked.
44-- Budget: about 5,000 lines of code (blank and comment lines not
44+- Budget: about 6,000 lines of code (blank and comment lines not
4545 counted), within 10%; at least 400,000 lines of raz a second.
4646 - Style: clarity over cleverness; each unit opens with what it is, what
4747 it depends on and what it leaves out; comments say why. Match the

PLAN.md (history) modified +104 -2

@@ -3,7 +3,7 @@
33 raz (Polish for *one*, as in counting) is a small systems language in Wirth's
44 tradition: full control of memory, volatile access, atomics, calls into
55 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
77 x86-64 machine code and the ELF file itself.
88
99 The language is defined by `doc/raz.md`. Where this plan and the report
@@ -14,7 +14,8 @@
1414 - The compiler is Free Pascal 3.2.2, `{$mode objfpc}{$H-}`: records,
1515 pointers, shortstrings. No classes, ansistrings, exceptions, dynamic
1616 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
1819 comment lines), within 10%, and compiles at least 400,000 lines of
1920 raz a second, from reading the sources to writing the executable.
2021 `make loc` and `make bench` measure them, and a step that breaks
@@ -171,3 +172,104 @@
171172 scanner that keeps comments, `tools/Scan.raz`. `make fmt` checks
172173 that `lib/`, `examples/` and `tools/` come through unchanged, and
173174 `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*.

doc/raz.md (history) modified +29 -4

@@ -78,7 +78,8 @@
7878 value H..., in a string its UTF-8) and, in strings only, `\xHH` (the
7979 byte with hexadecimal value HH, which needn't make valid UTF-8).
8080
81-Error messages give the line and the column, counted in characters.
81+Messages give the line and the column, counted in characters
82+(section 10).
8283
8384 **Comments** are `(*` ... `*)` and nest. By convention, the comment
8485 just before an exported declaration is its documentation, and the one
@@ -461,8 +462,9 @@
461462 `a[i]` is an element of an array or slice, and `a[lo..hi]` is the slice
462463 of the elements from `lo` up to but not including `hi`. Both are
463464 checked: `i` must be below the length, and `0 <= lo <= hi <= length`.
464-A check that fails prints the file and line to standard error and stops
465-the program with status 2.
465+A check that fails prints to standard error where it is, as file, line
466+and column, and what failed, with the values involved (`index 7 is out
467+of range for a length of 5`), and stops the program with status 2.
466468
467469 **Literals.** `[e1, e2, ...]` builds an array, and `{f: e, g: e, ...}`
468470 a record, where the type it must have is known: assigned to a variable,
@@ -840,8 +842,28 @@
840842 pointer. Dereferencing a stale or made-up pointer, indexing through a
841843 pointer, a code procedure that breaks its rules, and C code can read or
842844 write any memory, and what follows isn't defined. Dereferencing `nil`, dividing
843-by zero and calling a `nil` procedure stop the program with a signal.
845+by zero, calling a `nil` procedure and running out of stack stop the
846+program with a signal. Before it stops, the program prints to standard
847+error where it was, as file, line and column, and why, as far as it can
848+tell: a `nil` pointer, a `nil` procedure, a stack overflow, a bad
849+address or a division fault.
850+
851+**Messages.** The compiler reports an error with its file, line and
852+column, the line of source with the offending part underlined, and,
853+where they help, notes pointing at other places, such as where a name
854+is declared, and a suggestion, such as a name in reach spelled almost
855+alike. It goes on after an error to find the others, up to 20, and
856+writes no executable. After an error of syntax it skips to the next
857+procedure, so that one misplaced symbol brings no false reports after
858+it. A module with errors stops the compile after it.
844859
860+The compiler also warns of what is declared and never used: an import;
861+a constant, type, variable or procedure that isn't exported; a
862+parameter of a procedure written in raz. It warns of a variable that is
863+assigned but never read, too. A name that starts with `_` is never
864+warned about. Warnings don't stop the compile; `raz -Werror` makes them
865+errors.
866+
845867 ## 11. The library
846868
847869 Modules written in raz, in the compiler's `lib` directory:
@@ -905,3 +927,6 @@
905927
906928 - **2026-10.0.** The first numbered version: the language of compiler
907929 0.3.0.
930+- **2026-10.1.** Messages: every error in a run, warnings of what is
931+ never used and `-Werror` (section 10); failed checks say what failed,
932+ and signals say where (sections 6.5 and 10).