# src: the compiler in raz The port of the Pascal compiler, the **seed**, to raz. The seed built `src/` from the port to v0.19.0, and went in v0.20.0; git has it, in `seed/` at the tag v0.19.0. Since then the release `../BOOT` names builds `src/` (`boot.sh` fetches it), and a comment here that names the seed means the Pascal compiler. One module to a seed unit, with the seed's name, written to the same rules: plain code, each module opening with what it is, what it depends on and what it leaves out. make prev-bench # the compiler's speed against BOOT's: a tenth slower fails make fixpoint # BOOT's builds src, that builds src, that builds it again While it was ported, each unit was tested against the seed's: a pair of dumpers, one over each side's units, read the same files or ran the same pseudo-random script of calls, and had to print the same, with the same messages and status; the compiler built whole had to give every program the messages and status the seed gave. That test was dropped after v0.17.0: the two had grown apart, the compiler making better code since v0.10.1 and following newer reports since, and `make check`, `conform/` and the fixpoint test the compiler as it is. `test/Recover.raz`, the pattern of going on after an error, is run by `make check`. `make fixpoint` (`fixpoint.sh`) is the proof that the compiler is whole: BOOT's release builds `Raz.raz` (stage 1), stage 1 builds it (stage 2), and stage 2 builds it again (stage 3). Stages 2 and 3 must be the same file; they are (stage 1 is not, when BOOT's compiler makes other code than this one; until v0.19.0 the seed was stage 0). Stage 3 then stands in for `./raz`, and `make check` and `make bench` run on it. Each stage is built by the same command in the same place, since a program holds the paths it was made from. ## What the port found What the port found in the seed, which the seed kept; a record now. - **Names.** An exported variable is read-only outside its module, so what the parser sets in the seed's `diag` and `scan` (`quiet`, `werror`, `recovery`, `skipping`) have setters. The `sbuf` array, which can't be sliced outside, is `strBytes`. - **Going on after an error.** raz has no `setjmp`, and the seed's parser ends its errors in a jump back to the statement or declaration being read, which is how it reports up to 20 errors in a run. The language gained `try` (report 2026-10.20) for this: `Scan.mark` and the others show the error and return `Scan.Failed`, which the parser passes up with `try` to where it reads on. `test/Recover.raz` is the pattern. - **`NO_COLOR` set to nothing.** `Sys.env` gives "" for a variable that is unset and for one that is empty, so the port reads the second as the first. no-color.org says a variable that is empty doesn't turn colour off, so the port is the one that follows it and the seed differs; no test depends on either. - **Strings are slices.** A message is a `[]U8` made by `Diag.say`, which keeps what it makes: messages are made only to be shown. A name from `nameOf` stays valid, since names are kept in chunks that are never moved; the seed's was a copy. - **Reserved words as names.** The seed's `code` (the text buffer of `Chunk`) is `text`; `module` (a record's, an import's) is `home`; an object's `link` is `chain`. A seed type `TName` is `Name`, and the procedures begin in lower case, as `Scan`'s do. - **Errors in `Sym`.** `insert` (a name declared twice) and `openScope` (too many scopes) show the error and return `Scan.Failed`, as `mark` does, for the parser to pass up with `try`. `saveScopes` returns what the seed's `var d` gave. - **Setters.** What other units set in `Chunk` has one each (`setLive`, `setAdr`, `setReals`, `setSaves`, `setCurFile`, and `rewindTo` for gen's `Redo` and `Rewind`), and `Sym` has `setCurModule`. `Scan.grab` is exported for the memory they all take. - **No `continue`.** The seed's loops that skip to the next round (`MarkLive`, the line program, the assembler's statements) have the rest of the body in an `else`, or in a procedure of its own. - **`X64`.** `code` of `Chunk` being reserved, its text is `Chunk.text`; `Say` and the rest of the encoder keep their names, in lower case. `ConstFn`, the parser's reader of a constant, returns an `ERROR` too, and `assemble` returns what it passes up. `mem` marks an offset beyond 32 bits and goes on, since an operand has nowhere to return an error to; the compile ends with the message shown. The listing's text is made by `Diag.say`, which keeps it, and only when `-S` asks for it. - **`Link` and `Exe`.** What `raz.pas` set there has a setter each: `Link.setPlaces`, `Exe.needLib`, `noLibs`, `setMainPath`, `setStripped` and `X64.setListing`. The file is written by `Files.write` and made executable by `Sys.chmod`, in place of one `open` with mode 755 (which the umask would trim). - **`Gen`.** The seed's `Mark` in the middle of a push or a check can't give an error back: `newEntry` (the stack's 256 places) and `check` (4,096 checks a procedure) show it and go on without doing what they couldn't, and the parser's `resetStack` makes the stack right again; `endProc` returns its error ("frame too big") and `codeProc` the assembler's. A `var` out of the seed became a result (`topConst`, `operands`, `deferBegin`); the labels, which are chains that a call extends, stay `var`. `inPlace` has a setter. The seed's `Call` record is `CallInfo` (the procedure is `call`) and `TLink` is `Link`. A `match` on an enumeration takes one name to an arm, and a set holds at most 64 names, so `Scan.Sym` (over 64) has none: the seed's sets of its names are chains of `=`. - **`Item`.** The seed's `Mark` ended in a jump, so here every routine that can find an error returns an `ERROR` as its last result and the ones that call it pass it up with `try`; `Item` shows the message and returns what the seed jumped out of, so a script that goes on after an error sees the same state. The seed's `Mismatch` of two operands is `mismatchOps`, `demoted` and `checks` have setters, and `matchBegin`, `toSlot` and `errorChunk` return their value and the error. `op2` has a parameter it never read, now `_L`. A message is made by `Diag.say` from strings, with no `shortstring` to add up. A `Mark` with no place is at the scanner's, as in the seed. - **No `const` parameter.** The seed's `const x: TItem` is a value parameter here, so an item of about 130 bytes is copied at each call of `what`, `adrOf`, `notValue` and the others. The result is the same; whether the compiler built from this is slower for it is for the speed test of step 4 to say. A `const` parameter (a hint that the callee won't change it, so that the caller may pass its address) would be a language change. (It came in report 2026-10.33; since v0.20.0, built by v0.19.0, which has it, the routines that every program's compile goes through take their `Item` as `const`, measured, as `doc/compiler.md` says.) - **`Parse` and the seed's jumps.** The seed's `Guard`, `setjmp` and `longjmp` are `guard`, a record of what to put back, and the `ERROR` that comes up through `try` to the statement or declaration that is the recovery point (`statement`, `declaration`), which looks at it, puts the state back (`restore`) and skips ahead, as the seed does. `giveUp`, the seed's `GiveUp`, returns the error on to the next one, or ends the compile if there is none (`guards` counts them). A routine that can't fail has no `ERROR` (`declarations`, `declaration`). The seed's nested procedures (`ChooseRegs`'s three) are procedures of the module with its candidates in variables. `defer` and `module` being words, the seed's `Defer` is `deferStatement`. A message is made from strings with `Diag.say`, which has no shortstring to add up to. `Scan.skipping` is exported to be read, and `Scan.strWithZero` gives `Item.makeStr` a pointer to a string that may be empty: the seed's `@sbuf` indexed nothing, and `ADR(Scan.strBytes()[0])`, which the port of `Item` had, stopped on `""`. - **`Raz`.** The program is `proc main*: INT`. Where it is, for the library beside it, it reads from `/proc/self/exe` as FPC's `ParamStr(0)` does: `Files.arg(0)` is what the shell was typed, and `./raz` made the library `./lib`, so the same program held other paths in its file. `raz run` writes the memfd with `Exe.write` and executes it with the system call, `execve`, which `Sys` has no procedure for. The version is the module `Version`, which `check.sh` makes in `build/src/` from `build/version.inc`, as the seed's `{$I}` is. Two names of a file, for a module found in two places, are told by the device and inode `SYSCALL` `stat` gives, which `Sys.info` lacks. - **Sets of `Scan.Sym`.** It has 76 names and a set holds 64, so the operators a rule names are chains of `=` or the helpers `oneOf` and `isRel`. (A `match` arm with several names, which the seed's `case` has, was added to the report for this: 2026-10.21.) - **Strings made by the compiler.** A joined string (`"a" + "b"`) and an error's text are built in memory from `Scan.grab`, which is never freed, in place of `GetMem` and `FreeMem`; the compiler runs once. - **No bit cast.** A real's bits and back go through a pointer. - **Speed.** On the 348,025 lines of `test/genbench.sh`, 7.6 MB, the seed's scanner takes 75 ms and this one 74. It took 121 at first. What closed the gap, in the source: a byte loop in place of the slice comparison `a[0..n] = b[0..n]` (97 ms), a 256-entry table for the bytes of a name (84), and one for the symbols that are a byte each (75). What is left for the code generator, which would help every module: the slice comparison is slower than the loop it stands for. On the whole compiler, the same 348,025 lines take 427 ms with the seed's and 770 with this one (452,000 lines a second, over the 400,000 the budget wants): `Scan.tokPos`, a record of three words returned through a pointer, is 9% of it, and the rest is spread thin; the `const` parameter of `Item` isn't what stands out. (The seed's `match` on an integer was a chain of compares, each loading the selector from the frame and jumping over a `jmp`, where FPC makes a jump table; now it makes one too.)