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
diagandscan(quiet,werror,recovery,skipping) have setters. Thesbufarray, which can't be sliced outside, isstrBytes. - 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 gainedtry(report 2026-10.20) for this:Scan.markand the others show the error and returnScan.Failed, which the parser passes up withtryto where it reads on.test/Recover.razis the pattern. NO_COLORset to nothing.Sys.envgives "" 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
[]U8made byDiag.say, which keeps what it makes: messages are made only to be shown. A name fromnameOfstays 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 ofChunk) istext;module(a record's, an import's) ishome; an object'slinkischain. A seed typeTNameisName, and the procedures begin in lower case, asScan's do. - Errors in
Sym.insert(a name declared twice) andopenScope(too many scopes) show the error and returnScan.Failed, asmarkdoes, for the parser to pass up withtry.saveScopesreturns what the seed'svar dgave. - Setters. What other units set in
Chunkhas one each (setLive,setAdr,setReals,setSaves,setCurFile, andrewindTofor gen'sRedoandRewind), andSymhassetCurModule.Scan.grabis 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 anelse, or in a procedure of its own. X64.codeofChunkbeing reserved, its text isChunk.text;Sayand the rest of the encoder keep their names, in lower case.ConstFn, the parser's reader of a constant, returns anERRORtoo, andassemblereturns what it passes up.memmarks 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 byDiag.say, which keeps it, and only when-Sasks for it.LinkandExe. Whatraz.passet there has a setter each:Link.setPlaces,Exe.needLib,noLibs,setMainPath,setStrippedandX64.setListing. The file is written byFiles.writeand made executable bySys.chmod, in place of oneopenwith mode 755 (which the umask would trim).Gen. The seed'sMarkin the middle of a push or a check can't give an error back:newEntry(the stack's 256 places) andcheck(4,096 checks a procedure) show it and go on without doing what they couldn't, and the parser'sresetStackmakes the stack right again;endProcreturns its error ("frame too big") andcodeProcthe assembler's. Avarout of the seed became a result (topConst,operands,deferBegin); the labels, which are chains that a call extends, stayvar.inPlacehas a setter. The seed'sCallrecord isCallInfo(the procedure iscall) andTLinkisLink. Amatchon an enumeration takes one name to an arm, and a set holds at most 64 names, soScan.Sym(over 64) has none: the seed's sets of its names are chains of=.Item. The seed'sMarkended in a jump, so here every routine that can find an error returns anERRORas its last result and the ones that call it pass it up withtry;Itemshows 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'sMismatchof two operands ismismatchOps,demotedandcheckshave setters, andmatchBegin,toSlotanderrorChunkreturn their value and the error.op2has a parameter it never read, now_L. A message is made byDiag.sayfrom strings, with noshortstringto add up. AMarkwith no place is at the scanner's, as in the seed.- No
constparameter. The seed'sconst x: TItemis a value parameter here, so an item of about 130 bytes is copied at each call ofwhat,adrOf,notValueand 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. Aconstparameter (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 theirItemasconst, measured, asdoc/compiler.mdsays.) Parseand the seed's jumps. The seed'sGuard,setjmpandlongjmpareguard, a record of what to put back, and theERRORthat comes up throughtryto 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'sGiveUp, returns the error on to the next one, or ends the compile if there is none (guardscounts them). A routine that can't fail has noERROR(declarations,declaration). The seed's nested procedures (ChooseRegs's three) are procedures of the module with its candidates in variables.deferandmodulebeing words, the seed'sDeferisdeferStatement. A message is made from strings withDiag.say, which has no shortstring to add up to.Scan.skippingis exported to be read, andScan.strWithZerogivesItem.makeStra pointer to a string that may be empty: the seed's@sbufindexed nothing, andADR(Scan.strBytes()[0]), which the port ofItemhad, stopped on"".Raz. The program isproc main*: INT. Where it is, for the library beside it, it reads from/proc/self/exeas FPC'sParamStr(0)does:Files.arg(0)is what the shell was typed, and./razmade the library./lib, so the same program held other paths in its file.raz runwrites the memfd withExe.writeand executes it with the system call,execve, whichSyshas no procedure for. The version is the moduleVersion, whichcheck.shmakes inbuild/src/frombuild/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 inodeSYSCALLstatgives, whichSys.infolacks.- Sets of
Scan.Sym. It has 76 names and a set holds 64, so the operators a rule names are chains of=or the helpersoneOfandisRel. (Amatcharm with several names, which the seed'scasehas, 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 fromScan.grab, which is never freed, in place ofGetMemandFreeMem; 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 comparisona[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; theconstparameter ofItemisn't what stands out. (The seed'smatchon an integer was a chain of compares, each loading the selector from the frame and jumping over ajmp, where FPC makes a jump table; now it makes one too.)