raz / commit 72af0e47

commit
72af0e475a5929ea8e0e2af1c16f8a0ace6f9969
author
Luis <42945842+ldiaz94@users.noreply.github.com>
date
parent
596c810a
make raz builds src/ with the seed; the guide describes src/

make raz: fpc builds the seed into build/seed/ and the seed compiles src/
(with a generated Version module) into ./raz. make seed-check and seed-bench
(were self, self-bench) test src/ against the seed, build/self is build/src,
make loc counts src/*.raz (10,491 lines of code: past the soft 10,000, under
11,000). doc/compiler.md is rewritten for src/*.raz: its table, its routine
names, recovery by try; CLAUDE.md and README say the compiler is raz.

patch · log

9 files changed, +616 -547

CLAUDE.md modified +11 -5

@@ -8,12 +8,14 @@
88 ## Setup and checks
99
1010 apt-get install -y fp-compiler # Free Pascal 3.2.2, if fpc is missing
11- make raz # the compiler, ./raz; its library is lib/
11+ make raz # the compiler, ./raz, built from src/ by the seed; its library is lib/
1212 make check # every example and test against its expected output
1313 make bench # must report at least 400,000 lines a second
1414 make kernels # test/bench's kernels against FPC -O2's twins
1515 make loc # lines of the compiler, by rloc; the last, code, is the budget
1616 make tests # the small Pascal tests of scan, x64, link and elf
17+ make seed-check # src/ against the seed: each unit, then every program
18+ make fixpoint # the seed builds src, that builds src, that again: the last two agree
1719 make gdb # gdb stops at a line of a test and names it
1820 make stress # 40,000 native threads; make check runs a small version
1921 make fmt # lib/, examples/ and tools/ are formatted
@@ -44,9 +46,12 @@
4446
4547 ## How we work
4648
47-- The compiler is Free Pascal 3.2.2, `{$mode objfpc}{$H-}`: records,
48- pointers, shortstrings. No classes, ansistrings, exceptions, dynamic
49- arrays or SysUtils.
49+- The compiler, `src/`, is raz, in the language of the report and with
50+ the library of `lib/`; it must build with the seed (`seed/`, Free
51+ Pascal 3.2.2, `{$mode objfpc}{$H-}`: records, pointers, shortstrings;
52+ no classes, ansistrings, exceptions, dynamic arrays or SysUtils), so
53+ it uses nothing the seed doesn't know until a release makes a new
54+ seed.
5055 - Plans go by milestones, each a release (`PLAN.md`). A milestone
5156 starts only on the owner's explicit go-ahead; within it, one commit
5257 per step, pushed as it is done, then stop for review. Never start a
@@ -96,7 +101,8 @@
96101 busiest real variables in xmm registers, and an array's element and a
97102 constant offset as operands, measured on two kernels of reals,
98103 `Jacobi` and `NBody`. `make kernels` measures `test/bench` against
99-FPC `-O2`. Next, by `PLAN.md`: what the owner chooses.
104+FPC `-O2`. Self (`PLAN.md`) is done: `src/` is the compiler in raz, and
105+the seed in `seed/` is frozen. Next, by `PLAN.md`: what the owner chooses.
100106
101107 **The freeze.** Since v0.5.0 the language changes only to mend a
102108 defect, and the library grows only by what breaks no program written

Makefile (history) modified +22 -10

@@ -1,12 +1,24 @@
1-# Builds the compiler, raz, from seed/ into the repository's root; the
2-# library it needs is lib/, beside it.
1+# Builds the compiler, raz, from src/ into the repository's root; the
2+# library it needs is lib/, beside it. The seed, the Pascal compiler in
3+# seed/, builds it: fpc makes the seed in build/seed/ (with lib/ beside
4+# it, as every raz has), and the seed compiles src/. The one module
5+# the build makes, Version, holds what git says the version is.
36
47 FPC = fpc
58 FPCFLAGS = -O2 -Mobjfpc -Sh- -vew -FUbuild
69
7-raz: seed/*.pas build/version.inc | build
8- $(FPC) $(FPCFLAGS) -Fibuild -FE. -oraz seed/raz.pas
10+raz: build/seed/raz src/*.raz build/src/Version.raz
11+ build/seed/raz -Werror -I src -I build/src -o raz src/Raz.raz
12+
13+build/seed/raz: seed/*.pas build/version.inc | build
14+ mkdir -p build/seed
15+ $(FPC) $(FPCFLAGS) -Fibuild -FEbuild/seed -obuild/seed/raz seed/raz.pas
16+ ln -sfn ../../lib build/seed/lib
917
18+build/src/Version.raz: build/version.inc | build
19+ mkdir -p build/src
20+ printf 'module Version;\nconst Text* = "%s";\nend Version.\n' "$$(tr -d "'" < build/version.inc)" >$@
21+
1022 # The version is git's name for the commit; the file changes only when
1123 # that does, so raz isn't rebuilt for nothing.
1224 build/version.inc: FORCE | build
@@ -35,11 +47,11 @@
3547 check: raz build/raz-lib.3
3648 test/check.sh
3749
38-# the raz compiler in raz, src/, tested against the seed's units
39-self: raz | build
50+# the compiler's units, and the whole compiler, tested against the seed's
51+seed-check: raz | build
4052 src/check.sh
4153
42-self-bench: raz | build
54+seed-bench: raz | build
4355 src/bench.sh
4456
4557 # the seed builds src/, that builds src/, that builds it again: the
@@ -88,8 +100,8 @@
88100 # lines of the compiler, by rloc: each file's blank, comment and code,
89101 # then the lines of code in all
90102 loc:
91- @rloc -f seed/*.pas
92- @rloc -c seed/*.pas
103+ @rloc -f src/*.raz
104+ @rloc -c src/*.raz
93105
94106 # raz-lib(3), the library's manual page, made by tools/Doc.raz from
95107 # its sources, in the order of the report's section 11
@@ -161,4 +173,4 @@
161173 site: raz
162174 python3 site/build.py
163175
164-.PHONY: units tests self self-bench fixpoint check gdb bench kernels stress fmt loc man pdf dist site clean install uninstall
176+.PHONY: units tests seed-check seed-bench fixpoint check gdb bench kernels stress fmt loc man pdf dist site clean install uninstall

README.md (history) modified +5 -4

@@ -24,10 +24,10 @@
2424 $ examples/Hello
2525 hello, world
2626
27-The compiler is about 7,800 lines of Free Pascal: one pass, no
27+The compiler is about 10,000 lines of raz, written in itself: one pass, no
2828 intermediate form, no optimizer. It writes x86-64 machine code and the
2929 ELF executable itself, with no assembler or linker, and compiles about
30-a million lines a second.
30+over 400,000 lines a second.
3131
3232 ## What's here
3333
@@ -50,8 +50,9 @@
5050
5151 ## Building
5252
53-The compiler needs Free Pascal 3.2.2 (`apt-get install fp-compiler`)
54-and builds into the repository's root:
53+The first build needs Free Pascal 3.2.2 (`apt-get install fp-compiler`):
54+it builds the seed, the Pascal compiler in `seed/`, which builds the
55+compiler, `src/`, in the repository's root:
5556
5657 make # ./raz
5758 make install # ~/.local/bin/raz, its library and tools in

doc/compiler.md (history) modified +534 -484

@@ -1,7 +1,9 @@
11 # Reading the raz compiler
22
3-The compiler is eleven files of Free Pascal, under 10,000 lines of code.
4-This guide walks through them in the order they are best read: from the
3+The compiler is eleven files of raz, about 10,500 lines of code (the
4+budget is a soft 10,000, never past 11,000). It is its own compiler: the
5+frozen Pascal compiler in `seed/` builds `src/` the first time, and
6+after that `src/` builds itself. This guide walks through the files in the order they are best read: from the
57 characters of a source file to the bytes of an executable. It assumes
68 you know the language from `doc/raz.md`, and enough x86-64 to read a
79 disassembly. The manual pages say the rest: `raz(1)` the command,
@@ -10,17 +12,17 @@
1012
1113 | File | Lines | Code | What |
1214 |---|---|---|---|
13-| `seed/diag.pas` | 316 | 233 | Messages: positions, source excerpts, colour, counts |
14-| `seed/scan.pas` | 886 | 747 | Symbols, literals, comments, positions |
15-| `seed/sym.pas` | 646 | 528 | Types, objects, scopes, layout |
16-| `seed/chunk.pas` | 318 | 246 | The compiled program: chunks, fixups, line notes |
17-| `seed/x64.pas` | 1,208 | 998 | The instruction encoder, jumps within a procedure, the assembler |
18-| `seed/gen.pas` | 2,322 | 1,670 | The stack machine, for x86-64: values, operations, checks, calls, frames |
19-| `seed/item.pas` | 1,575 | 1,299 | Items: types, constants, variables, operators, conversions, calls |
20-| `seed/parse.pas` | 3,280 | 2,851 | Declarations, statements, expressions, built-ins, recovery, warnings |
21-| `seed/link.pas` | 334 | 258 | Tree shaking, layout, patching, the places |
22-| `seed/elf.pas` | 373 | 294 | Static and dynamic ELF, symbol table, line numbers |
23-| `seed/raz.pas` | 245 | 188 | The command line |
15+| `src/Diag.raz` | 410 | 315 | Messages: positions, source excerpts, colour, counts |
16+| `src/Scan.raz` | 1,002 | 842 | Symbols, literals, comments, positions |
17+| `src/Sym.raz` | 684 | 555 | Types, objects, scopes, layout |
18+| `src/Chunk.raz` | 354 | 272 | The compiled program: chunks, fixups, line notes |
19+| `src/X64.raz` | 1,472 | 1,222 | The instruction encoder, jumps within a procedure, the assembler |
20+| `src/Gen.raz` | 2,350 | 1,693 | The stack machine, for x86-64: values, operations, checks, calls, frames |
21+| `src/Item.raz` | 1,729 | 1,438 | Items: types, constants, variables, operators, conversions, calls |
22+| `src/Parse.raz` | 3,775 | 3,298 | Declarations, statements, expressions, built-ins, recovery, warnings |
23+| `src/Link.raz` | 380 | 298 | Tree shaking, layout, patching, the places |
24+| `src/Elf.raz` | 431 | 344 | Static and dynamic ELF, symbol table, line numbers |
25+| `src/Raz.raz` | 273 | 214 | The command line |
2426
2527 Every file opens with a comment that says what it is, what it depends
2628 on and what it leaves out. Read those first; they are the map.
@@ -30,18 +32,21 @@
3032 There is one pass and no tree. The parser reads a construct and, in
3133 the same breath, has the code generator emit its machine code. Nothing
3234 is kept to be looked at again, except the declarations, which live in
33-the symbol table for as long as the compiler runs.
35+the symbol table for as long as the compiler runs. An error is shown
36+at once and returned as an `ERROR` (`Scan.Failed`), which each routine
37+passes up with `try` to where the parser reads on, at the next
38+statement or declaration.
3439
35-Three layers do it. `parse.pas` knows the language's syntax. `item.pas`
40+Three layers do it. `Parse.raz` knows the language's syntax. `Item.raz`
3641 knows what the program means: each operand is an *item*, as in Wirth's
3742 compilers, and the routines there check the items' types, fold
3843 constants and work out where variables are. Neither knows the machine:
39-they drive a stack machine, `gen.pas`, by its calls (push a value,
44+they drive a stack machine, `Gen.raz`, by its calls (push a value,
4045 add the two on top, store the top in a variable, jump if it is false),
4146 each with the kind of the value (a word, a 64-bit integer, an `F32`,
42-an `F64`). `gen.pas` is the only one that knows x86-64; a port to
43-another machine is a new `gen.pas`, with an encoder of its own in place
44-of `x64.pas`.
47+an `F64`). `Gen.raz` is the only one that knows x86-64; a port to
48+another machine is a new `Gen.raz`, with an encoder of its own in place
49+of `X64.raz`.
4550
4651 On x86-64 the stack lives in registers, as in Wirth's compilers
4752 (Niklaus Wirth's Pascal and Oberon compilers): the value at depth `d`,
@@ -79,23 +84,23 @@
7984
8085 `raz Hello.raz` does this:
8186
82-1. `raz.pas` reads the command line and calls `CompileMain`
83- (`parse.pas`).
84-2. `CompileMain` imports `Rt` first, since every program needs it, and
85- then compiles `Hello.raz` with `CompileFile`.
86-3. `CompileFile` opens the file in the scanner and parses the module.
87- At `import Out;` it calls `ImportModule`, which finds `Out.raz` and
88- compiles it there and then, saving and restoring the scanner and the
87+1. `Raz.raz` reads the command line and calls `compileMain`
88+ (`Parse.raz`).
89+2. `compileMain` imports `Rt` first, since every program needs it, and
90+ then compiles `Hello.raz` with `compileFile`.
91+3. `compileFile` opens the file in the scanner and parses the module.
92+ At `import Out;` it calls `importModule`, which finds `Out.raz` and
93+ compiles it there and then, saving and restoring the scanner (`Scan.saveScan`, `Scan.restoreScan`) and the
8994 scopes around it. So modules are finished in an order where each
9095 comes after those it imports; that is the order their bodies run.
9196 4. Each procedure becomes a chunk of code; `Out.str("hello, world\n")`
9297 becomes a string chunk, a call, and a fixup to `Out.str`'s chunk.
93-5. Back in `raz.pas`, `Use` marks the modules the program uses; the
94- entry point, `_start`, is written by `gen.pas`'s `EntryPoint` as one
98+5. Back in `Raz.raz`, `use` marks the modules the program uses; the
99+ entry point, `_start`, is written by `Gen.raz`'s `entryPoint` as one
95100 more chunk: save `argc` and `argv` and the address of the places
96101 (below), call every used module's body, call `main`, call `Rt.exit`.
97-6. `MarkLive` (`link.pas`) marks what `_start` reaches; then
98- `WriteElf` (`elf.pas`) has `link.pas` place it and patch it, and
102+6. `markLive` (`Link.raz`) marks what `_start` reaches; then
103+ `writeElf` (`Elf.raz`) has `Link.linkAll` place it and patch it, and
99104 writes headers, code, data, symbols and line numbers.
100105
101106 ## A procedure, compiled
@@ -111,9 +116,9 @@
111116 under each line of source, named by the compiler as it made them):
112117
113118 ```
114-push rbp ; EnterBody: the frame
119+push rbp ; enterBody: the frame
115120 mov rbp,rsp
116-sub rsp,0x10 ; its size, patched in by EndProc
121+sub rsp,0x10 ; its size, patched in by endProc
117122 mov r9,rsi ; b, at depth 1; a, at depth 0, and
118123 shl r9,0x1 ; the 2 are only noted; times 2
119124 mov r8,rdi ; is a shift; a is loaded for +
@@ -124,13 +129,12 @@
124129 ```
125130
126131 `scale` calls nothing, so its parameters stay in `rdi` and `rsi`,
127-where they arrive (`KeepArrived`): they are register variables that
132+where they arrive (`keepArrived`): they are register variables that
128133 cost nothing to keep. Every line of it can be traced to a routine in
129-`gen.pas`: the moves are `Loaded`'s, the shift and the add `Op`'s, the
130-result `ReturnJump`'s, and the frame is `EnterBody`'s and `EndProc`'s.
134+`Gen.raz`: the moves are `loaded`'s, the shift and the add `op`'s, the
135+result `returnJump`'s, and the frame is `enterBody`'s and `endProc`'s.
131136 It is not the fastest code. It is code whose every instruction you
132137 can account for, which is the point.
133-
134138 ## Better code, in one procedure
135139
136140 `Str.decode` reads one UTF-8 character from a slice of bytes, and for
@@ -246,18 +250,18 @@
246250 slots of the four variables, all of them in registers, and the slots
247251 the registers are saved in, which are written before they are read.
248252 Now a variable in a register has no slot, and only the locals in
249- memory are zeroed (`PlaceLocals`, `UseRegs`, `EnterBody`).
253+ memory are zeroed (`placeLocals`, `useRegs`, `enterBody`).
250254 2. **The hidden pointer**: the two results went through `rcx` to the
251255 caller's memory. Two words come back in `rax` and `rdx` now
252- (`InTwoRegs`), so `return 0, 0` is two instructions; and the caller
253- pops them straight into its variables (`mWords`, `MultiAssign`).
256+ (`inTwoRegs`), so `return 0, 0` is two instructions; and the caller
257+ pops them straight into its variables (`pushWords`, `multiAssign`).
254258 3. **`cmp r8, 0`** is `test r8, r8`, the same flags in fewer bytes
255- (`CmpI`).
259+ (`cmpI`).
256260 4. **Copies through `rax`**: `s[0]`'s address is worked out in the
257- register it is used from (`IndexSlice`), and a result is put in `rax`
258- from where it is (`PopTo`).
261+ register it is used from (`indexSlice`), and a result is put in `rax`
262+ from where it is (`popTo`).
259263 5. **The `jmp 421` after `return`**, which nothing could reach: a branch
260- of an `if` that ends gets no jump past the others (`IfStatement`).
264+ of an `if` that ends gets no jump past the others (`ifStatement`).
261265
262266 What is left is worth knowing too. The slice's two words still go to
263267 the frame, since only single values live in registers; `movzx` then
@@ -300,13 +304,13 @@
300304 add r9, r12
301305 ```
302306
303- Its item is at `bReg`, and its `TAdr` names both registers (`hi`
304- for the length's): `PushVar` reads either word (`RegAt`),
305- `IndexSlice` and `Slice` compare with the length's and add the
307+ Its item is at `bReg`, and its `Adr` names both registers (`hi`
308+ for the length's): `pushVar` reads either word (`regAt`),
309+ `indexSlice` and `slice` compare with the length's and add the
306310 pointer's, a failed check takes the length from its register
307- (`InRegister`), and `CopyTo` loads both. What wants a slice's
311+ (`inRegister`), and `copyTo` loads both. What wants a slice's
308312 memory, a comparison or `COPY`, has its words stored in a
309- temporary first (`CopyToTemp`). rat 5% faster, the heap sort 5%,
313+ temporary first (`copyToTemp`). rat 5% faster, the heap sort 5%,
310314 the search 4%.
311315
312316 2. **Parameters left where they arrive.** `find(s, sub: []U8)` stored
@@ -321,12 +325,12 @@
321325 ```
322326
323327 In a procedure that names no procedure, a procedure variable, `NEW`,
324- `SYSCALL` or `COPY`, as `ChooseRegs` sees reading ahead, the
328+ `SYSCALL` or `COPY`, as `chooseRegs` sees reading ahead, the
325329 parameters that arrive in `rdi` and `rsi` stay there, which only a
326330 call or a copy needs: nothing is saved or moved, and `s[i]` is read
327- through `rdi` itself (`KeepArrived`). Where gen needs them after
331+ through `rdi` itself (`keepArrived`). Where Gen needs them after
328332 all, to copy a record or compare two slices, it sets `lost`, and
329- `Body` compiles the procedure again with the parameters in memory,
333+ `body` compiles the procedure again with the parameters in memory,
330334 as for a variable demoted. The trap report shows a parameter kept
331335 so: `Rt.fail` is given `rdi` and `rsi` as the failing code had
332336 them, and the signal handler takes them from the context the
@@ -347,11 +351,11 @@
347351 ```
348352
349353 Now an element of a slice in registers is only noted, as the
350- operand `[rdi + r12 * 8]` (`lIdx`, made by `IndexSlice`), and a
354+ operand `[rdi + r12 * 8]` (`lIdx`, made by `indexSlice`), and a
351355 variable in memory, or at an address noted, as the operand that
352- reads it (`lMem`, made by `PushVar`): each is read where it is
353- used, and `Op`, `Compare` and `JumpCmp` take an 8-byte one as their
354- right operand as it is (`TopInMem`):
356+ reads it (`lMem`, made by `pushVar`): each is read where it is
357+ used, and `op`, `compare` and `jumpCmp` take an 8-byte one as their
358+ right operand as it is (`topInMem`):
355359
356360 ```
357361 mov r8, rbx
@@ -359,8 +363,8 @@
359363 ```
360364
361365 A value noted in memory must be read before anything can change
362- it: before a call (`SpillBelow`) and an atomic built-in (`Atomic`),
363- both through `ReadMems`. The heap sort 14% faster, the search 5%;
366+ it: before a call (`spillBelow`) and an atomic built-in (`atomic`),
367+ both through `readMems`. The heap sort 14% faster, the search 5%;
364368 rat within noise, its text 3.9% smaller. Loop tops aligned to 16
365369 bytes were tried with it, and taken out: the search lost 3%, and
366370 rat gained nothing.
@@ -376,9 +380,9 @@
376380
377381 and `i`'s step as well. An assignment whose expression starts with
378382 its variable, in a register, and changes it by `+`, `-`, `|` or
379- `xor`, naming it nowhere else (`ChangesItself`, read ahead in the
380- statement), has gen work the value out in the variable's own
381- register (`inPlace`, `lInto`), and `ForStep` steps one so too:
383+ `xor`, naming it nowhere else (`changesItself`, read ahead in the
384+ statement), has Gen work the value out in the variable's own
385+ register (`inPlace`, `lInto`), and `Item.forStep` steps one so too:
382386
383387 ```
384388 add r12, 1
@@ -389,7 +393,7 @@
389393 slow as before, for it crossed a 64-byte line that the processor
390394 fetches decoded instructions in. The top of a `for` loop, which
391395 the code jumps to rather than runs into, now starts at a multiple
392- of 32 bytes (`AlignLoop`, `Align` in x64), the no-ops before it
396+ of 32 bytes (`alignLoop`, `align` in X64), the no-ops before it
393397 never run. The sum 41% faster, the search 6%; rat within noise.
394398
395399 4. **`while` tested at the bottom.** A `while` loop tested its
@@ -414,10 +418,10 @@
414418 jl top
415419 ```
416420
417- One pass reads the condition before the body, so `WhileStatement`
421+ One pass reads the condition before the body, so `whileStatement`
418422 compiles it where it is written, for its messages, takes its code
419- back (`Rewind`), and reads it again after the body (`SaveScan`,
420- `RestoreScan`). A constant condition, as in `while true`, is no
423+ back (`rewind`), and reads it again after the body (`saveScan`,
424+ `restoreScan`, in Scan). A constant condition, as in `while true`, is no
421425 test. The heap sort 3% faster, rat 2%; the search lost 7%, all of
422426 it to where its loops fell: without the top aligned it lost
423427 nothing, and rat gained nothing either.
@@ -466,12 +470,12 @@
466470 ```
467471
468472 Now a real at depth `d` is held in `xmm8` to `xmm11`, in
469- `XRegs[d mod 4]` (`RegIn`): it is loaded and stored with `movsd`
470- (`movss` for an `F32`; `XValueTo`, `PopVar`), a constant is read
471- from 8 bytes of read-only data (`RealConst`), and an operation takes
472- its right operand from memory as it is, as `Op` does for an integer
473- (`RealOp`). A constant on the left of `+` or `*` is left on top by
474- `Op2`, in `item.pas`, as their order doesn't matter, rather than
473+ `XRegs[d mod 4]` (`regIn`): it is loaded and stored with `movsd`
474+ (`movss` for an `F32`; `xValueTo`, `popVar`), a constant is read
475+ from 8 bytes of read-only data (`realConst`), and an operation takes
476+ its right operand from memory as it is, as `op` does for an integer
477+ (`realOp`). A constant on the left of `+` or `*` is left on top by
478+ `Item.op2`, as their order doesn't matter, rather than
475479 swapped under the other operand and back:
476480
477481 ```
@@ -483,7 +487,7 @@
483487 movsd [rdi + r8 * 8], xmm9
484488 ```
485489
486- `Call` moves a real argument straight to its `xmm0` to `xmm7`, and
490+ `call` moves a real argument straight to its `xmm0` to `xmm7`, and
487491 takes a real result from `xmm0`; a comparison is `ucomisd` of the
488492 two registers; a conversion is done in the value's own registers.
489493 The registers from `xmm8` up carry no arguments, so that moving one
@@ -509,7 +513,7 @@
509513 its index in a variable's register, is noted as the operand that
510514 reads it, its base the array's address, made in the value's own
511515 register; one in the frame has `rbp` as its base, whatever its
512- index (`IndexArray`, as `IndexSlice` does for a slice in
516+ index (`indexArray`, as `indexSlice` does for a slice in
513517 registers):
514518
515519 ```
@@ -518,8 +522,8 @@
518522 ```
519523
520524 A computed index in a chunk's array is added up as before, as it
521- would need a third register. `CheckIndex` compares a variable's
522- register as it is (`Peek`), not a copy. NBody 225 ms to 147; rat
525+ would need a third register. `checkIndex` compares a variable's
526+ register as it is (`peek`), not a copy. NBody 225 ms to 147; rat
523527 within noise.
524528
525529 3. **An offset as the machine has it.** The sweep's four neighbours,
@@ -540,12 +544,12 @@
540544 ```
541545
542546 Now a word in a register may carry an offset not yet added (`off`,
543- in `TEntry`): `Op` notes `x + c` and `x - c` there, carries it
547+ in `Entry`): `op` notes `x + c` and `x - c` there, carries it
544548 through `+` and `-`, and through `*` by a constant, as `(x + a) * k`
545549 is `x * k + a * k`. An element's operand takes it as its
546- displacement (`IndexOff`, for `IndexSlice` and `IndexArray`), and so
547- does a field's through a pointer (`Place`); anything else adds it
548- where the value is read (`Loaded`, `Peek`, `ValueTo`, with a `lea`,
550+ displacement (`indexOff`, for `indexSlice` and `indexArray`), and so
551+ does a field's through a pointer (`place`); anything else adds it
552+ where the value is read (`loaded`, `peek`, `valueTo`, with a `lea`,
549553 which leaves the flags alone). A value changed in place, `lInto`,
550554 carries none, and an index that is checked has it added first:
551555
@@ -574,12 +578,12 @@
574578 mulsd xmm8, [rbp - 8]
575579 ```
576580
577- Now `ChooseRegs` gives the busiest reals of a procedure `xmm12` to
581+ Now `chooseRegs` gives the busiest reals of a procedure `xmm12` to
578582 `xmm15` (`XVarRegs`), as it gives the busiest integers `rbx` and
579583 `r12` to `r15`, and gen reads and writes them where they are: a
580584 real in a variable's register is `lHeld` or `lInto`, as an
581- integer's is (`XValueTo`, `PopVar`, `Peek` for `RealOp` and
582- `Compare`):
585+ integer's is (`xValueTo`, `popVar`, `peek` for `realOp` and
586+ `compare`):
583587
584588 ```
585589 subsd xmm8, [r9 + r12 * 8]
@@ -589,15 +593,15 @@
589593 mulsd xmm8, xmm13
590594 ```
591595
592- Each such variable has its slot too, which `PopVar` writes as it
596+ Each such variable has its slot too, which `popVar` writes as it
593597 writes the register (`movsd [rbp - 8], xmm13` after the `movaps`),
594598 off the chain the round waits on: the trap report finds the value
595599 there, as it finds any variable's, whether a check failed or a
596- signal stopped the program, and `Call` loads the register from it
597- after each call (`XHome`, `HomeOf`), as System V keeps no xmm
600+ signal stopped the program, and `call` loads the register from it
601+ after each call (`xHome`, `homeOf`), as System V keeps no xmm
598602 register through one. A register number from `XmmVar`, 16, up is
599603 an xmm register's, so that `xmm12` isn't taken for `r12` where the
600- parser counts its registers (`RegsOf`, `RegAt`). NBody 147 ms to
604+ parser counts its registers (`regsOf`, `regAt`). NBody 147 ms to
601605 116, and a copy of it without the call to `sqrt` 114 to 81; rat
602606 within noise. Storing the slot only before a call, and so showing
603607 nothing in the trap report, bought 3% more on that copy and nothing
@@ -615,69 +619,70 @@
615619 which there is no register. A comparison of reals still makes a
616620 `BOOL` before it jumps, as `not (a < b)` isn't `a >= b` for a NaN;
617621 neither kernel has one.
622+## Diag.raz: messages
618623
619-## diag.pas: messages
624+Every message the compiler prints is made here. A position, `Pos`, is a
625+file and a stretch of bytes in it; `error`, `warning` and `note` show it
626+as `file:line:column`, then the line of source with the stretch
627+underlined, and `help` adds a line of advice. Notes and help are shown
628+only with an error that was: not one at the place of the last, and not
629+one under `quiet`, which the parser sets (`setQuiet`) when an error
630+follows from another (see Parse.raz). The line and column are worked out
631+only when a message is printed (`locate`, `chars`), so positions cost
632+nothing while compiling. `addFile` keeps every source file the scanner
633+opens, so a note can show a line of any of them. `finish` prints the
634+count of errors and warnings and stops if there were errors; `fatal` is
635+for errors with no place in the source. A message is made by `say` from
636+a format and its arguments, and kept for good, since a message is made
637+only where it is about to be shown.
620638
621-Every message the compiler prints is made here. A position, `TPos`, is
622-a file and a stretch of bytes in it; `Error`, `Warning` and `Note` show
623-it as `file:line:column`, then the line of source with the stretch
624-underlined, and `Help` adds a line of advice. Notes and help are shown
625-only with an error that was: not one at the place of the last, and
626-not one under `quiet`, which the parser sets when an error follows
627-from another (see parse.pas). The line and column are
628-worked out only when a message is printed (`Locate`, `Chars`), so
629-positions cost nothing while compiling. `AddFile` keeps every source
630-file the scanner opens, so a note can show a line of any of them.
631-`Finish` prints the count of errors and warnings and stops if there
632-were errors; `Fatal` is for errors with no place in the source.
639+## Scan.raz: the scanner
633640
634-## scan.pas: the scanner
635-
636-The scanner turns bytes into symbols (`TSym`). The current symbol is in
641+The scanner turns bytes into symbols (`Sym`). The current symbol is in
637642 `tok`, with its value in `ival` (integers and characters), `rval`
638-(reals), `id` (identifiers) or `sbuf` and `slen` (strings, already
639-decoded).
643+(reals), `id` (identifiers) or `strBytes`, the `slen` bytes of a string,
644+already decoded.
640645
641-Read `Next` first: it skips white space and comments (`Comment`, which
642-counts nesting), then dispatches on the first character. `Number`
643-handles decimal, `0FFH`-style hexadecimal and reals; `LitChar` handles
644-one character of a literal, escapes included. `ReadReal` turns a real's
645-digits into the nearest `F64` exactly, as a fraction of two big
646-integers (`TBig`), since Free Pascal's `Val` can be one bit off.
646+Read `next` first: it skips white space and comments (`comment`, which
647+counts nesting), then dispatches on the first character. `number`
648+handles decimal, `0FFH`-style hexadecimal and reals; `litChar` handles
649+one character of a literal, escapes included. `readReal` turns a real's
650+digits into the nearest `F64` exactly, as a fraction of two big integers
651+(`Big`), since a library's reader can be one bit off.
647652
648-Identifiers are *interned*: `Intern` puts each distinct name once in a
653+Identifiers are *interned*: `intern` puts each distinct name once in a
649654 pool and hands back a small integer, so every later comparison of names
650655 is a comparison of integers. The reserved words are interned first, in
651-the order of `TSym`, so a name's number tells at once whether it is a
656+the order of `Sym`, so a name's number tells at once whether it is a
652657 reserved word.
653658
654-Source is UTF-8, checked by `Utf8` wherever a byte above 127 appears:
659+Source is UTF-8, checked by `utf8` wherever a byte above 127 appears:
655660 in strings, characters and comments. Anywhere else it is an error.
656661
657-`TokPos` is the position of the current symbol, `SpanFrom` the stretch
662+`tokPos` is the position of the current symbol, `spanFrom` the stretch
658663 from a saved position to the end of the symbol before the current one,
659-and `MissingPos` the place to say a symbol is missing: just after the
660-symbol before, when the current one starts a new line. Errors go
661-through `Mark`, at the current symbol, `MarkAt`, at a position, or
662-`MarkHelp`, which adds a line of help; each reports the error
663-(`diag.Error`) and jumps to `recovery`, the parser's place to go on
664-from (see parse.pas), through `Fail`. An error with notes is reported
665-with `Error` and `Note`, then `Fail`. A message names what it found: `Found` describes
666-the current symbol and `SymText` spells an operator or reserved word,
667-so that the parser's `Expect` and `Expected` say `expected ";", found
668-"end"`. Errors in the text itself stop the
669-compiler (`MarkBytes`, `LexError`): past a string left open, the
670-symbols can't be trusted. A slip from another language, such as `!=`
671-for `#`, is reported by `Slip`, which reads on as if the right symbol
672-were written; not while the parser is `skipping` what it read once
673-before an error. `SaveScan` and `RestoreScan` keep
674-the scanner's state while an imported module is compiled.
664+and `missingPos` the place to say a symbol is missing: just after the
665+symbol before, when the current one starts a new line. Errors go through
666+`mark`, at the current symbol, `markAt`, at a position, or `markHelp`,
667+which adds a line of help; each reports the error (`Diag.error`) and
668+returns `Failed`, an `ERROR` the parser passes up with `try` to where it
669+goes on from (see Parse.raz). An error with notes is reported with
670+`Diag.error` and `Diag.note`, then returns `Failed` itself. A message
671+names what it found: `found` describes the current symbol and `symText`
672+spells an operator or reserved word, so that the parser's `expect` and
673+`expected` say `expected ";", found "end"`. Errors in the text itself
674+stop the compiler (`markBytes`, `lexError`): past a string left open,
675+the symbols can't be trusted. A slip from another language, such as `!=`
676+for `#`, is reported by `slip`, which reads on as if the right symbol
677+were written; not while the parser is `skipping` (`setSkipping`) what it
678+read once before an error. `saveScan` and `restoreScan` keep the
679+scanner's state while an imported module is compiled.
675680
676-## sym.pas: types, objects and scopes
681+## Sym.raz: types, objects and scopes
677682
678683 Two records hold everything the compiler knows about a program.
679684
680-`TType` is a type. Its `form` says what kind (`fInt`, `fPtr`, `fArray`,
685+`Type` is a type. Its `form` says what kind (`fInt`, `fPtr`, `fArray`,
681686 `fRecord`, `fVariant`, `fProc`, and so on), and the other fields mean
682687 what that form needs: `base` is what a pointer points at, an array or
683688 slice holds, or a procedure returns; `fields` lists a record's fields,
@@ -685,365 +690,390 @@
685690 elements. `size` and `align` are worked out when the type is built, by
686691 the C rules. `obj` is the declaration that named the type, if any.
687692
688-`TObj` is anything a name can stand for: a constant, type, variable,
693+`Obj` is anything a name can stand for: a constant, type, variable,
689694 procedure, module, field, variant case or built-in (`cls`), and `pos`
690695 is where its name is declared, for notes. Where it
691696 lives is decided here too: a module variable's chunk, a local's frame
692697 offset in `val`, a procedure's chunk.
693698
694699 Scopes are numbers. The universe is 0; each module, procedure, record
695-and match arm gets a new one from `NewScope`. All objects of all scopes
696-sit in one open-addressed hash table, keyed by scope and name: `Find`
697-looks in one scope, `Lookup` in each open scope from the innermost out.
698-A lookup costs the same however big a program grows, which matters at
699-a million lines a second. After an error, `Closest` looks through the
700+and match arm gets a new one from `newScope`. All objects of all scopes
701+sit in one open-addressed hash table, keyed by scope and name: `find`
702+looks in one scope, `lookup` in each open scope from the innermost out.
703+A lookup costs the same however big a program grows, which matters at a
704+million lines a second. After an error, `closest` looks through the
700705 whole table for the name in reach spelled most like one not found
701-(`Distance`), for "did you mean".
706+(`distance`), for "did you mean".
702707
703-`Same` and `Alike` decide whether two types are the same: one
704-declaration for named types, built alike otherwise. `Fingerprint`
705-hashes what a declaration exports, for the check that a module's files
706-for different targets agree. The universe, the basic types and built-in
707-procedures, is set up in the unit's `initialization`.
708+`same` and `alike` decide whether two types are the same: one
709+declaration for named types, built alike otherwise. `fingerprint` hashes
710+what a declaration exports, for the check that a module's files for
711+different targets agree. The universe, the basic types and built-in
712+procedures, is set up in the module's body.
708713
709-## chunk.pas: the compiled program
714+Two routines can find an error: `insert`, for a name declared twice, and
715+`openScope`, for too many scopes. Each shows it and returns
716+`Scan.Failed`, for the parser to pass up with `try`. A record's module
717+and an object's link, which the seed called `module` and `link`, are
718+`home` and `chain`, since those are reserved words here; `setCurModule`
719+is how the parser says which module it is in, as an exported variable
720+can't be set from outside.
710721
711-Code is written into one growing buffer, `code`, with `pc` its length;
712-strings and other constants go to `rodata`. A chunk (`TChunk`) records
722+## Chunk.raz: the compiled program
723+
724+Code is written into one growing buffer, `text`, with `pc` its length;
725+strings and other constants go to `rodata`. A chunk (`Chunk`) records
713726 its section, where its bytes start, how many, and the fixups it makes.
714-`BeginChunk` and `EndChunk` bracket a procedure; `SetData` and `SetBss`
727+`beginChunk` and `endChunk` bracket a procedure; `setData` and `setBss`
715728 make data chunks.
716729
717-A *fixup* (`TFixup`) is a 32-bit field in the code that will hold the
730+A *fixup* (`Fixup`) is a 32-bit field in the code that will hold the
718731 distance to another chunk: a call's target, or a rip-relative address.
719-`AddFixup` records one; `link.pas` fills them in. A constant's
720-addresses are *data fixups*, `AddDataFixup`'s: 64-bit fields in
721-rodata that will hold a chunk's address itself, since the executable is
722-loaded where the linker placed it. `NoteLine` records
723-which line and column of the source the code from `pc` on belongs to,
724-for gdb and for the places. `ExternChunk` makes, once per C symbol,
725-the quadword the dynamic loader will fill with that symbol's address.
726-None of this depends on the machine.
732+`addFixup` records one; `Link.raz` fills them in. A constant's addresses
733+are *data fixups*, `addDataFixup`'s: 64-bit fields in rodata that will
734+hold a chunk's address itself, since the executable is loaded where the
735+linker placed it. `noteLine` records which line and column of the source
736+the code from `pc` on belongs to, for gdb and for the places.
737+`externChunk` makes, once per C symbol, the quadword the dynamic loader
738+will fill with that symbol's address. `takeBack` and `rewindTo` undo the
739+end of what was made, for a body compiled a second time. What other
740+modules set in a chunk, such as `live` or `adr`, has a setter each
741+(`setLive`, `setAdr`), since an exported variable can't be set from
742+outside. None of this depends on the machine.
727743
728-## x64.pas: machine code
744+## X64.raz: machine code
729745
730-The encoder is `OpM` and `OpR`: a prefix, the REX byte, the opcode, the
746+The encoder is `opM` and `opR`: a prefix, the REX byte, the opcode, the
731747 ModRM and SIB bytes and the displacement, for a register and a memory
732-operand (`TMem`) or two registers. Everything else (`MovRR`, `Load`,
733-`Store`, `Alu`, `Sse`, ...) is a line or two that calls them with the
748+operand (`Mem`) or two registers. Everything else (`movRR`, `load`,
749+`store`, `alu`, `sse`, ...) is a line or two that calls them with the
734750 right opcode. Only the instructions the code generator uses are here.
735-`test/enctest.pas` emits one of each for `objdump` to check. `Here` is
751+`test/enctest.pas` emits one of each, with the seed's encoder, for `objdump` to check. `here` is
736752 the address of the code being written, as an operand.
737753
738-The assembler, `Assemble`, reads a code procedure's instructions with
754+The assembler, `assemble`, reads a code procedure's instructions with
739755 the scanner, Intel's syntax as NASM writes it, and encodes them with
740-`OpM` and `OpR`: `Operand` reads a register, a memory operand or a
741-constant (by the parser's `AsmConst`, handed in: a whole expression,
742-or for a scale a single factor, so that `[rdi + rsi * 4 + 16]` doesn't
743-read `4 + 16` as the scale), and a few tables
744-give the operations of a kind their opcodes (`Alus`, `Unaries`,
745-`Shifts`, `SseOps`, `Plain`; `PackedOps` the SSE2 integer operations
746-on 16 bytes at a time, with `movdqu`, `movdqa` and `pmovmskb` beside
747-them, and `BitOps` the bit scans and counts: `bsf`, `bsr`, `tzcnt`,
748-`lzcnt`, `popcnt`). Labels are chains of jumps, as below.
749-`db` gives bytes it doesn't know. `RegNames` and `CondNames` are the
750-names of the registers and conditions.
756+`opM` and `opR`: `operand` reads a register, a memory operand or a
757+constant (by the parser's `asmConst`, handed in as a `ConstFn`: a whole
758+expression, or for a scale a single factor, so that `[rdi + rsi * 4 +
759+16]` doesn't read `4 + 16` as the scale), and a few tables give the
760+operations of a kind their opcodes (`Alus`, `Unaries`, `Shifts`,
761+`SseOps`, `Plain`; `PackedOps` the SSE2 integer operations on 16 bytes
762+at a time, with `movdqu`, `movdqa` and `pmovmskb` beside them, and
763+`BitOps` the bit scans and counts: `bsf`, `bsr`, `tzcnt`, `lzcnt`,
764+`popcnt`). Labels are chains of jumps, as below. `db` gives bytes it
765+doesn't know. An error in an instruction is returned as an `ERROR`,
766+which `assemble` passes up. An offset that doesn't fit in 32 bits
767+(`mem`) can't be returned, since an operand has nowhere to give it: it
768+is shown, and the compile goes on to its end. `RegNames` and `CondNames`
769+are the names of the registers and conditions.
751770
752-The listing, `raz -S`: with `listing` set, each routine of the encoder
753-says, with `Say`, the instruction it is about to write, as the
754-assembler would read it; `List` prints the main module's live
755-procedures with each line of source (`LineText` in `diag.pas`) and the
756-instructions under it. Nothing is disassembled: the listing is what
757-the encoder meant.
771+The listing, `raz -S`: with `listing` set (`setListing`), each routine
772+of the encoder says, with `say`, the instruction it is about to write,
773+as the assembler would read it; `list` prints the main module's live
774+procedures with each line of source (`lineText` in `Diag.raz`) and the
775+instructions under it. Nothing is disassembled: the listing is what the
776+encoder meant.
758777
759778 Jumps within a procedure don't wait for the linker. A label not yet
760779 placed is a chain of the jumps to it, each jump's 32-bit field holding
761-the position of the one before (`Jmp`, `Jcc`); `FixLink` walks the
780+the position of the one before (`jmp`, `jcc`); `fixLink` walks the
762781 chain and patches each once the label's position is known. This is the
763782 trick from Wirth's compilers, and it means a label is one integer.
764-`DropJumpTo` takes back a `jmp` just made to a label about to be
783+`dropJumpTo` takes back a `jmp` just made to a label about to be
765784 placed after it, so a `return` that ends a procedure doesn't jump to
766785 the next instruction; the line notes made after it move back with it
767-(`TakeBack`, in `chunk.pas`).
786+(`takeBack`, in `Chunk.raz`).
768787
769-## gen.pas: the stack machine
788+## Gen.raz: the stack machine
770789
771790 This is the only unit that knows the machine. The calls it answers:
772791
773-- values: `PushConst`, `PushAdr` (the address of a variable),
774- `PushVar` (its value), `PushProc`, and `PopVar`, which stores the
775- value on top; `Drop` and `Swap`;
776-- operations on the values on top: `Op`, `Compare`, `Neg`,
777- `Complement`, `NotBool`, `Narrow` (to a narrow integer's width),
778- the conversions between integers and reals, `CompareSeq` (of two
779- slices), and copying: `CopyBlock`, `CopyTo`, `ZeroVar`, and
780- `CopySlice` for `COPY`, a `rep movsb` that goes down when the
781- destination is above the source;
782-- jumps: `Jump`, `JumpIf` (on a `BOOL`), `JumpCmp` (on two integers),
783- `JumpOut` (`JumpCmp` from within an expression) and `CondValue` for
784- `and` and `or`, `Fix` where the label is, and `JoinJumps`;
785-- checks: `CheckIndex`, `CheckEnum`, and `IndexSlice`, `Slice` and
786- `SlicePtr`, which check as they make their address or slice; and
787- `IndexArray`, an element's address in an array in the frame or a
792+- values: `pushConst`, `pushAdr` (the address of a variable), `pushVar`
793+ (its value), `pushProc`, and `popVar`, which stores the value on top;
794+ `drop` and `swap`;
795+- operations on the values on top: `op`, `compare`, `neg`, `complement`,
796+ `notBool`, `narrow` (to a narrow integer's width), the conversions
797+ between integers and reals, `compareSeq` (of two slices), and copying:
798+ `copyBlock`, `copyTo`, `zeroVar`, and `copySlice` for `COPY`, a `rep
799+ movsb` that goes down when the destination is above the source;
800+- jumps: `jump`, `jumpIf` (on a `BOOL`), `jumpCmp` (on two integers),
801+ `jumpOut` (`jumpCmp` from within an expression) and `condValue` for
802+ `and` and `or`, `fix` where the label is, and `joinJumps`;
803+- checks: `checkIndex`, `checkEnum`, and `indexSlice`, `slice` and
804+ `slicePtr`, which check as they make their address or slice; and
805+ `indexArray`, an element's address in an array in the frame or a
788806 chunk, the index checked before;
789-- calls (`Call`), frames (`BeginProc`, `EnterBody`, `ReturnJump`,
790- `EndProc`, the temporaries of `AllocTemp`), deferred statements
791- (`DeferBegin`, `DeferEnd`, `RunDefer`), the built-ins that are
792- instructions (`Atomic`, `SysCall`, `Fence`), and the program's entry
793- point (`EntryPoint`).
807+- calls (`call`), frames (`beginProc`, `enterBody`, `returnJump`,
808+ `endProc`, the temporaries of `allocTemp`), deferred statements
809+ (`deferBegin`, `deferEnd`, `runDefer`), the built-ins that are
810+ instructions (`atomic`, `sysCall`, `fence`), and the program's entry
811+ point (`entryPoint`).
794812
795-A variable's place is a `TAdr`: relative to the frame (`bFrame`), to a
813+A variable's place is an `Adr`: relative to the frame (`bFrame`), to a
796814 chunk (`bGlobal`), to an address on the stack (`bStack`), or to one
797815 held in a frame slot (`bSlot`, as a `var` parameter's is); plus `off`.
798-`Place` turns it into an x64 memory operand, popping or loading the
816+`place` turns it into an x64 memory operand, popping or loading the
799817 address first, so that a variable is read or written with one
800818 instruction.
801819
802820 The stack: `stack` notes where each value is, a constant (`lConst`), an
803-address not yet computed (`lAdr`, `AdrMem`'s operand), an element's
804-address not yet computed (`lIdx`, an operand `[base + index * size]`),
805-a variable's value not yet read (`lMem`, at an operand), a register
821+address not yet computed (`lAdr`, `adrMem`'s operand), an element's
822+address not yet computed (`lIdx`, an operand `[base + index * size]`), a
823+variable's value not yet read (`lMem`, at an operand), a register
806824 variable's own register, read in place (`lHeld`), the value's own
807-register (`lReg`) or a frame slot (`lFrame`); `owner` says which
808-value each register holds, `lIdx` and `lMem` holding theirs when it
809-is their index. A word in a register may have an offset not yet
810-added (`off`), which an operand takes as its displacement. The value at depth `d` belongs in
811-`Regs[d mod 4]`, `r8` to `r11`: `rax`, `rdx` and `rcx`, which division
812-and shifts need, and `rsi` and `rdi`, which copying needs, aren't among
813-them. A real belongs in `XRegs[d mod 4]`, `xmm8` to `xmm11`, which
814-carry no arguments; each depth has the two registers, and `owner`
815-doesn't tell them apart (`RegIn`, `RegOf`). `Claim` gives a value its register, and `Spill`s the lower one
816-that holds it, when an expression is deeper than the registers;
817-`Loaded` brings a value into its register, from its constant, address
818-or slot; `Place` uses a noted address as the operand itself, so that
819-`PopVar`, storing a constant, and `IncDec` are one instruction on
820-memory: `DEC(n)` is `sub qword [rbp - 8], 1`. `Top` is `Loaded` for the
821-value on top, and `Target` the register a new one is computed in.
822-`Drop` emits no code, and the dropped value's register still holds it
823-until the next push, which several routines rely on. Before a call every
824-value in a register is spilled (`SpillBelow`), since the call may change
825-them, and so are the values under a comparison that jumps out of an
826-expression (`JumpOut`), which both ways to its label must find in the
827-same place. `pushed` counts the quadwords on the machine's stack. A
828-call needs `rsp` a multiple of 16, so `Call` pads by one quadword when
829-`pushed` plus its stack arguments is odd; in a deferred statement
830-`pushed` starts at 1, for the return address. `Op` takes a
831-constant on the right as it is, after moving one on the left of `+`,
832-`*`, `&`, `|` or `xor` there, and a power of two on the right of `*`,
833-`div` or `mod` becomes shifts (`DivPow2`), since `idiv` is slow; an
834-element's size multiplies an index by a shift too (`MulI`), as a shift
835-takes one cycle and `imul` three.
836-Narrow integers are brought back to their width after each operation,
837-which is how `U8` arithmetic wraps; since they are computed in 64 bits,
838-a shift's count is cut to their width first, and `DivTrap` makes the
839-smallest value of one divided by -1 fault as an `I64`'s does.
825+register (`lReg`) or a frame slot (`lFrame`); `owner` says which value
826+each register holds, `lIdx` and `lMem` holding theirs when it is their
827+index. A word in a register may have an offset not yet added (`off`),
828+which an operand takes as its displacement. The value at depth `d`
829+belongs in `Regs[d mod 4]`, `r8` to `r11`: `rax`, `rdx` and `rcx`, which
830+division and shifts need, and `rsi` and `rdi`, which copying needs,
831+aren't among them. A real belongs in `XRegs[d mod 4]`, `xmm8` to
832+`xmm11`, which carry no arguments; each depth has the two registers, and
833+`owner` doesn't tell them apart (`regIn`, `regOf`). `claim` gives a
834+value its register, and `spill`s the lower one that holds it, when an
835+expression is deeper than the registers; `loaded` brings a value into
836+its register, from its constant, address or slot; `place` uses a noted
837+address as the operand itself, so that `popVar`, storing a constant, and
838+`incDec` are one instruction on memory: `DEC(n)` is `sub qword [rbp -
839+8], 1`. `top` is `loaded` for the value on top, and `target` the
840+register a new one is computed in. `drop` emits no code, and the dropped
841+value's register still holds it until the next push, which several
842+routines rely on. Before a call every value in a register is spilled
843+(`spillBelow`), since the call may change them, and so are the values
844+under a comparison that jumps out of an expression (`jumpOut`), which
845+both ways to its label must find in the same place. `pushed` counts the
846+quadwords on the machine's stack. A call needs `rsp` a multiple of 16,
847+so `call` pads by one quadword when `pushed` plus its stack arguments is
848+odd; in a deferred statement `pushed` starts at 1, for the return
849+address. `op` takes a constant on the right as it is, after moving one
850+on the left of `+`, `*`, `&`, `|` or `xor` there, and a power of two on
851+the right of `*`, `div` or `mod` becomes shifts (`divPow2`), since
852+`idiv` is slow; an element's size multiplies an index by a shift too
853+(`mulI`), as a shift takes one cycle and `imul` three. Narrow integers
854+are brought back to their width after each operation, which is how `U8`
855+arithmetic wraps; since they are computed in 64 bits, a shift's count is
856+cut to their width first, and `divTrap` makes the smallest value of one
857+divided by -1 fault as an `I64`'s does.
840858
841-Checks: `Check` jumps, when the check fails, to code at the end of the
842-procedure (`EndFails`), so that a check that holds is a jump not taken.
843-That code puts the values involved where `Rt.fail` wants them and
844-calls a stub for its kind of failure (`failStubs`, made by
845-`EntryPoint`), which says the kind and passes the address it was
846-called from, by which `Rt` finds the place: the failing code has the
847-place of the offending expression (`LineCol` in `scan.pas`). It leaves
848-`rdi` and `rsi` as they were, so that the stub can pass them on, for
849-the trap report to show a parameter kept in them. A check
850-costs a compare and a jump where it stands, and a dozen bytes out of
851-the way. Code is aligned to 32 bytes, the windows x86 fetches it in,
852-so that where a procedure's loops fall doesn't depend on what comes
853-before it.
859+Checks: `check` jumps, when the check fails, to code at the end of the
860+procedure (`endFails`), so that a check that holds is a jump not taken.
861+That code puts the values involved where `Rt.fail` wants them and calls
862+a stub for its kind of failure (`failStubs`, made by `entryPoint`),
863+which says the kind and passes the address it was called from, by which
864+`Rt` finds the place: the failing code has the place of the offending
865+expression (`lineCol` in `Scan.raz`). It leaves `rdi` and `rsi` as they
866+were, so that the stub can pass them on, for the trap report to show a
867+parameter kept in them. A check costs a compare and a jump where it
868+stands, and a dozen bytes out of the way. Code is aligned to 32 bytes,
869+the windows x86 fetches it in, so that where a procedure's loops fall
870+doesn't depend on what comes before it.
854871
855-What the machine catches, the code doesn't test for (report section
856-10, appendix A): on x86-64 Linux a division by zero raises SIGFPE, a
857-stack overflow meets the guard page under the stack, a call to `nil`
858-jumps to an address never mapped, and so does a load or store within
859-`NilPage` bytes of address 0. `Rt`'s handlers say where and why. What
860-is left is a field of a `nil` pointer past that page: an item reached
861-through `^` is `deref` until `NilTest` (`item.pas`) has it used, and
862-gen's `CheckNil` tests the pointer only if the use reaches past
863-`NilPage`. A port whose machine catches less tests for more, in its
864-own `gen.pas`: `Rt.fail` stops for a nil pointer, a division by zero
865-and a stack overflow as the signals would.
872+The stack has 256 places and a procedure may have 4,096 checks. Past
873+either, `newEntry` or `check` shows the error and goes on, since a push
874+or a check has nowhere to return it; the parser's `resetStack` makes the
875+stack right again. `endProc` returns its error (a frame too big) and
876+`codeProc` the assembler's.
866877
878+What the machine catches, the code doesn't test for (report section 10,
879+appendix A): on x86-64 Linux a division by zero raises SIGFPE, a stack
880+overflow meets the guard page under the stack, a call to `nil` jumps to
881+an address never mapped, and so does a load or store within `NilPage`
882+bytes of address 0. `Rt`'s handlers say where and why. What is left is a
883+field of a `nil` pointer past that page: an item reached through `^` is
884+`deref` until `nilTest` (`Item.raz`) has it used, and Gen's `checkNil`
885+tests the pointer only if the use reaches past `NilPage`. A port whose
886+machine catches less tests for more, in its own `Gen.raz`: `Rt.fail`
887+stops for a nil pointer, a division by zero and a stack overflow as the
888+signals would.
889+
867890 Calls: the arguments are computed left to right onto the stack, where
868-they wait for `Call`, as any values do: a constant, an address or a
869-variable in a register only noted, the rest in registers, or spilled
870-by a call in a later argument, so that it can't disturb them. `Call`
871-spills what is under them, moves each into the register System V
872-wants (`ValueTo`), `r8` and `r9` last since they may hold others, and
873-aligns the stack. A slice goes as its two words, in two registers or
874-both on the stack, as System V passes a struct of two integers, and
875-the procedure keeps them in its frame. A record
876-passed by value goes as the address of a copy. A result of two words,
877-a slice or two single values that aren't reals (`InTwoRegs`, in
878-`sym.pas`), comes back in rax and rdx, as System V returns a struct of
879-two integers: `return` leaves both on the stack for `ReturnJump`.
880-`Call` leaves two results on the stack, and stores a slice in a
881-temporary of the caller's. Any other record, or
891+they wait for `call`, as any values do: a constant, an address or a
892+variable in a register only noted, the rest in registers, or spilled by
893+a call in a later argument, so that it can't disturb them. `call` spills
894+what is under them, moves each into the register System V wants
895+(`valueTo`), `r8` and `r9` last since they may hold others, and aligns
896+the stack. A slice goes as its two words, in two registers or both on
897+the stack, as System V passes a struct of two integers, and the
898+procedure keeps them in its frame. A record passed by value goes as the
899+address of a copy. A result of two words, a slice or two single values
900+that aren't reals (`inTwoRegs`, in `Sym.raz`), comes back in rax and
901+rdx, as System V returns a struct of two integers: `return` leaves both
902+on the stack for `returnJump`. `call` leaves two results on the stack,
903+and stores a slice in a temporary of the caller's. Any other record, or
882904 several results, come back in memory the caller provides, through a
883-hidden pointer in `rdi` (`BehindPointer`, `ResultTo`, `CopyResult`). C
905+hidden pointer in `rdi` (`behindPointer`, `resultTo`, `copyResult`). C
884906 returns a struct of up to 16 bytes in `rax` and `rdx`; raz sends every
885907 record through memory, and only a slice or two single values in
886908 registers.
887909
888-Frames: `BeginProc` gives the parameters their slots; `EnterBody`
889-writes the prologue, which zeroes the locals in memory (with a few
890-stores, or a loop for more; there are none to zero in `scale`) but not
891-the temporaries, since each is written before it is read; `EndProc` writes
910+Frames: `beginProc` gives the parameters their slots; `enterBody` writes
911+the prologue, which zeroes the locals in memory (with a few stores, or a
912+loop for more; there are none to zero in `scale`) but not the
913+temporaries, since each is written before it is read; `endProc` writes
892914 the epilogue and patches the frame's size in. Within a statement,
893-scratch space comes from `AllocTemp` and is given back by
894-`ReleaseTemps`; `AllocPerm` reserves space for the whole procedure.
915+scratch space comes from `allocTemp` and is given back by
916+`releaseTemps`; `allocPerm` reserves space for the whole procedure.
895917
896-Register variables: the parser chooses them (`ChooseRegs`, below),
897-then gives the locals left in memory their slots (`PlaceLocals`), and
898-tells gen (`UseRegs`) the registers, as bits of `VarRegs`. A variable
899-in a register has no slot of its own. Gen saves the registers in slots
900-a quadword each, after the locals and not zeroed, as each is written
901-first. The
902-prologue saves them, zeroes them, and moves a parameter into its
903-register from the register or stack slot it arrived in; the epilogue
904-restores them. A slice may have two, its pointer's and its length's
905-(see "Better code again" above). A variable in one is an
906-item at `bReg`: `PushVar` notes it (`lHeld`) rather than copying it,
907-`Peek` reads it in place where the value is only read, so `i < n` is
908-`cmp rbx, r12`, and `PopVar` and `IncDecReg` write it. Rt finds the
909-values for the trap report from the saves: each procedure's record in
910-the places says which it saved, and where (`saveMask`, `saveAt`).
911-A real takes one of `xmm12` to `xmm15` (`XVarRegs`, numbered from
912-`XmmVar` up, so that `xmm12` isn't taken for `r12`), which the prologue
913-zeroes and saves nothing for, and a slot as well, which `PopVar`
914-writes as it writes the register (`XHome`): the trap report finds it
915-there, and `Call` loads the register from it after each call, as
916-System V has no callee-saved xmm register.
918+Register variables: the parser chooses them (`chooseRegs`, in
919+Parse.raz), then gives the locals left in memory their slots
920+(`placeLocals`), and tells Gen (`useRegs`) the registers, as bits of
921+`VarRegs`. A variable in a register has no slot of its own. Gen saves
922+the registers in slots a quadword each, after the locals and not zeroed,
923+as each is written first. The prologue saves them, zeroes them, and
924+moves a parameter into its register from the register or stack slot it
925+arrived in; the epilogue restores them. A slice may have two, its
926+pointer's and its length's (see "Better code again" above). A variable
927+in one is an item at `bReg`: `pushVar` notes it (`lHeld`) rather than
928+copying it, `peek` reads it in place where the value is only read, so `i
929+< n` is `cmp rbx, r12`, and `popVar` and `incDecReg` write it. Rt finds
930+the values for the trap report from the saves: each procedure's record
931+in the places says which it saved, and where (`saveMask`, `saveAt`). A
932+real takes one of `xmm12` to `xmm15` (`XVarRegs`, numbered from `XmmVar`
933+up, so that `xmm12` isn't taken for `r12`), which the prologue zeroes
934+and saves nothing for, and a slot as well, which `popVar` writes as it
935+writes the register (`xHome`): the trap report finds it there, and
936+`call` loads the register from it after each call, as System V has no
937+callee-saved xmm register.
917938
918-## item.pas: items
939+## Item.raz: items
919940
920-An operand is an *item* (`TItem`), as in Wirth's compilers. Its `mode`
941+An operand is an *item* (`Item`), as in Wirth's compilers. Its `mode`
921942 says what it is now:
922943
923944 - `mConst`: a value known to the compiler, in `val`;
924-- `mVar`: a variable, at `base`, `chunk` and `off`, which `AdrOf`
925- makes a `TAdr` for gen;
926-- `mStack`: a value on gen's stack;
945+- `mVar`: a variable, at `base`, `chunk` and `off`, which `adrOf` makes
946+ an `Adr` for Gen;
947+- `mStack`: a value on Gen's stack;
927948 - `mWords`: the two results of a call, as rax and rdx brought them, on
928- gen's stack, the first under the second. `a, b := f(x)` brings the
929- first to the top (`Swap`) and pops each into its variable, so that
949+ Gen's stack, the first under the second. `a, b := f(x)` brings the
950+ first to the top (`swap`) and pops each into its variable, so that
930951 nothing goes through memory; `return f(x)` leaves them for
931- `ReturnJump`; anything else makes them a temporary (`CopyToTemp`);
952+ `returnJump`; anything else makes them a temporary (`copyToTemp`);
932953 - `mCond`: a condition, as Wirth's compilers keep one: two integers on
933- gen's stack, compared by `rel` once something wants the result, and
934- the jumps of `and` and `or` that land where it is false (`fj`) or
935- true (`tj`); `CondJump` makes it a jump, `Value` a `BOOL`;
954+ Gen's stack, compared by `rel` once something wants the result, and
955+ the jumps of `and` and `or` that land where it is false (`fj`) or true
956+ (`tj`); `condJump` makes it a jump, `value` a `BOOL`;
936957 - `mProc`, `mType`, `mStr`, and a few more the parser needs.
937958
938959 An item also carries `pos`, the stretch of source it came from, which
939960 the parser sets as it reads an expression; an error about an item is
940-reported there (`MarkAt(x.pos, ...)`), and one about two operands
941-across both (`Join(x.pos, y.pos)`). `What` names an item for a
961+reported there (`Scan.markAt(x.pos, ...)`), and one about two operands
962+across both (`Diag.join(x.pos, y.pos)`). `what` names an item for a
942963 message: a constant without a type of its own as it is written
943964 (`found 1.5`), anything else by its type.
944965
945-Two routines move items towards the machine: `Value` pushes an item's
946-value, and `Address` a variable's address. Both leave the item saying
947-it is on the stack. An item nothing more is done with is given back to
948-`Discard`.
966+An error is shown where it is found, by `Scan.markAt` and the others,
967+which return `Scan.Failed`. Every routine here that can find one returns
968+an `ERROR` as its last result, and the ones that call it pass it up with
969+`try`, to where the parser reads on.
949970
950-Expressions: `Op1` is called when the parser has seen an operator and
951-its left operand, `Op2` when it has the right one. `Op1` pushes the
952-left operand, unless it is a constant; for `and` and `or` it makes the
953-left one a condition (`MakeCond`) and jumps past the right one, which
954-`Op2` joins to it: `(a < b) and (c < d)` in an `if` is two compares
955-and two jumps, as `not` of a condition is the other comparison. `Op2` checks the types, folds constants
956-(`FoldInt`, `FoldReal`), and otherwise pushes the right operand and has
957-gen do the operation; a constant on the left goes on after the right,
958-and the two `Swap`. A set's operations are operations on its bits
959-(`SetOp`). `=` and `#` on arrays, slices and strings make a slice of
960-each side (`SeqSlice`) and have gen compare them right where the
961-comparison stands: no call. `+` on two string constants is `JoinStr`,
962-which makes one string of them, in a chunk of its own.
971+Two routines move items towards the machine: `value` pushes an item's
972+value, and `address` a variable's address. Both leave the item saying it
973+is on the stack. An item nothing more is done with is given back to
974+`discard`.
963975
964-Variables: `Deref`, `Field`, `Index` and `Slice` turn an item for a
965-variable into an item for part of it, mostly by adding to `off`. An
966-item for another module's exported variable, or part of it, is `ro`:
967-it isn't a variable (`isVar`), and `NotReadOnly` says why where one is
968-wanted; what it points at is. An array or record constant is a
969-variable too, in read-only data: `AggregateConst` (`parse.pas`) reads
970-its literal, part by part in `ConstPart`, into the bytes of a chunk,
971-as a string constant's are; an address in it, of a string, an array
972-constant, a procedure or an `ERROR`, becomes a data fixup. `MakeItem` makes it
973-an `mVar` there that isn't `isVar`, so it is read, indexed, sliced and
974-passed, never changed. `Index` and `Slice` have gen make the bounds
975-checks, unless the module says `check off;` (`checks`, which
976-`CompileFile` sets for each module), and `Convert` the check of an
977-enumeration's position.
976+Expressions: `op1` is called when the parser has seen an operator and
977+its left operand, `op2` when it has the right one. `op1` pushes the left
978+operand, unless it is a constant; for `and` and `or` it makes the left
979+one a condition (`makeCond`) and jumps past the right one, which `op2`
980+joins to it: `(a < b) and (c < d)` in an `if` is two compares and two
981+jumps, as `not` of a condition is the other comparison. `op2` checks the
982+types, folds constants (`foldInt`, `foldReal`), and otherwise pushes the
983+right operand and has Gen do the operation; a constant on the left goes
984+on after the right, and the two `swap`. A set's operations are
985+operations on its bits (`setOp`). `=` and `#` on arrays, slices and
986+strings make a slice of each side (`seqSlice`) and have Gen compare them
987+right where the comparison stands: no call. `+` on two string constants
988+is `joinStr`, which makes one string of them, in a chunk of its own.
989+
990+Variables: `deref`, `field`, `index` and `slice` turn an item for a
991+variable into an item for part of it, mostly by adding to `off`. An item
992+for another module's exported variable, or part of it, is `ro`: it isn't
993+a variable (`isVar`), and `notReadOnly` says why where one is wanted;
994+what it points at is. An array or record constant is a variable too, in
995+read-only data: `aggregateConst` (`Parse.raz`) reads its literal, part
996+by part in `constPart`, into the bytes of a chunk, as a string
997+constant's are; an address in it, of a string, an array constant, a
998+procedure or an `ERROR`, becomes a data fixup. `makeItem` makes it an
999+`mVar` there that isn't `isVar`, so it is read, indexed, sliced and
1000+passed, never changed. `index` and `slice` have Gen make the bounds
1001+checks, unless the module says `check off;` (`checks`, set by
1002+`setChecks`, which `compileFile` sets for each module), and `convert`
1003+the check of an enumeration's position.
9781004
979-Assignment and conversion: `Coerce` makes a value fit the type it's
1005+Assignment and conversion: `coerce` makes a value fit the type it's
9801006 going to, or reports that it can't; it's where a string literal becomes
981-a slice, an array a slice, an untyped constant a typed one, and an
982-`INT` an `I64` (`Widens`). `CoerceExact` is for where the types must
983-be the same, as in a `for` loop, `INC` and several results. `Assign`
984-stores, or copies records and arrays. `Convert` is the written
985-conversion, `T(x)`.
1007+a slice, an array a slice, an untyped constant a typed one, and an `INT`
1008+an `I64` (`widens`). `coerceExact` is for where the types must be the
1009+same, as in a `for` loop, `INC` and several results. `assign` stores, or
1010+copies records and arrays. `convert` is the written conversion, `T(x)`.
9861011
987-Calls: `BeginCall`, then `PassArg` for each argument, then `EndCall`,
988-which has gen's `Call` make the call. Each argument is left on gen's
989-stack, a slice as its two words (`PushWords`). `return f(x);` passing
990-on f's several results, with `ReturnAll`, pushes them from the call's
1012+Calls: `beginCall`, then `passArg` for each argument, then `endCall`,
1013+which has Gen's `call` make the call. Each argument is left on Gen's
1014+stack, a slice as its two words (`pushWords`). `return f(x);` passing on
1015+f's several results, with `returnAll`, pushes them from the call's
9911016 temporary if they are two words, or else copies them to the place its
9921017 own hidden pointer names.
9931018
994-## parse.pas: the parser
1019+## Parse.raz: the parser
9951020
9961021 A recursive descent parser, one routine for each rule of the grammar in
997-the report, calling `item.pas`, and for jumps `gen.pas`, as it goes.
1022+the report, calling `Item.raz`, and for jumps `Gen.raz`, as it goes.
1023+Like the other modules it is written in raz: the Free Pascal seed built
1024+it the first time, and it builds itself now. Its routines begin in
1025+lower case, and each one that can find an error ends in an `ERROR`
1026+result, passed up with `try` (see Recovery below).
9981027
999-Start with expressions, bottom up: `Factor`, `Term`, `SimpleExpr`,
1000-`Relation`, `Conjunct` (the `and`s), `Expression` (the `or`s). Then `Designator`, which reads a name and what follows
1028+Start with expressions, bottom up: `factor`, `term`, `simpleExpr`,
1029+`relation`, `conjunct` (the `and`s), `expression` (the `or`s). Then `designator`, which reads a name and what follows
10011030 it: `.field`, `^`, `[i]`, `[lo..hi]`, a call, a conversion. Each step
1002-calls the matching routine in `item.pas` on the item it has. The
1031+calls the matching routine in `Item.raz` on the item it has. The
10031032 `want` parameter carries the type an expression must have, where it is
1004-known, so that `[1, 2, 3]`, `{x: 1}` and `{red}` know what to build.
1033+known, so that `[1, 2, 3]`, `{x: 1}` and `{red}` know what to build
1034+(`arrayLiteral`, `recordLiteral`, `setLiteral`).
10051035
1006-Then statements: `Statement` makes each one a recovery point (below)
1007-and `OneStatement` dispatches; `IfStatement`,
1008-`WhileStatement`, `ForStatement` and `MatchStatement` emit their jumps
1036+Then statements: `statement` makes each one a recovery point (below)
1037+and `oneStatement` dispatches; `ifStatement`,
1038+`whileStatement`, `forStatement` and `matchStatement` emit their jumps
10091039 with gen's labels. A branch of an `if` that ends, in `return` or
10101040 `break` (`ends`), gets no jump past the others; and `if c then break;
1011-end` is one jump out of the loop where `c` holds (`ThenPart`,
1012-`LoneBreak`, `CondJumpTrue`), not a jump past a jump. A `for` loop
1041+end` is one jump out of the loop where `c` holds (`thenPart`,
1042+`loneBreak`, and `Item.condJumpTrue`), not a jump past a jump. A `for` loop
10131043 steps its variable at the top and tests at the bottom, so that a round
10141044 by 1 is one compare and one jump; its rare case, a body that moves the
1015-variable past the limit, has code of its own after (`ForNext`, whose
1045+variable past the limit, has code of its own after (`Item.forNext`, whose
10161046 comment walks through the report's rule). The blank is a symbol of its own, `sBlank`, so
10171047 no declaration or expression takes it: `_ := e` loads a single value
1018-and drops it, and `MultiAssign` skips the results it stands for. A
1048+and drops it, and `multiAssign` skips the results it stands for. A
10191049 `match` on an integer reads each arm's
1020-labels in `IntArm`, which refuses a value in two of them. The arms
1050+labels in `intArm`, which refuses a value in two of them. The arms
10211051 come first and the test after them: the match starts with a jump to
1022-`Dispatch`, placed after the last arm, since a jump table can only be
1052+`dispatch`, placed after the last arm, since a jump table can only be
10231053 made once every arm's place is known (an enumeration's arms are
10241054 picked the same way; a variant's, by its tag, arm by arm).
1025-`Dispatch` makes a jump table (gen's `JumpTable`, whose comment shows
1055+`dispatch` makes a jump table (gen's `jumpTable`, whose comment shows
10261056 the code) for four labels or more that lie close together, else
1027-compares and branches one label after another with `MatchRange`, each
1028-jumping back to its arm. `Defer` is worth reading: a deferred statement
1057+compares and branches one label after another with `Item.matchRange`, each
1058+jumping back to its arm. `deferStatement` is worth reading: a deferred statement
10291059 is compiled where it stands, as a little subroutine of the procedure
1030-that the code jumps over (gen's `DeferBegin` and `DeferEnd`), and
1031-`RunDefers` emits a call to it at every way out of its statement list:
1060+that the code jumps over (gen's `deferBegin` and `deferEnd`), and
1061+`runDefers` emits a call to it at every way out of its statement list:
10321062 the end, `return` and `break`. A `return`'s result waits in the frame
10331063 meanwhile, so that gen's stack is empty when they run.
10341064
1035-`try` (report 7.8) is `TryCall`, for the statement, an operand
1036-(`Factor`) and the right of a multiple assignment (`MultiAssign`). It
1037-reads the call as `Designator` does, takes the error, the last of its
1065+`try` (report 7.8) is `tryCall`, for the statement, an operand
1066+(`factor`) and the right of a multiple assignment (`multiAssign`). It
1067+reads the call as `designator` does, takes the error, the last of its
10381068 results, out of the way into a slot of the frame, and leaves in `x`
10391069 the results that are left: none, one value, or a tuple of the others,
1040-`WithoutLast`. Then, in the code before and after, this:
1070+`withoutLast`. Then, in the code before and after, this:
10411071
10421072 ```
1043- load [slot]; jz ok ; JumpIf(ok, false)
1044- and rsp, -16 ; TryAlign, if a deferred statement is in force
1045- call deferred... ; RunDefers(0), as for a return
1046- mov rax/rdx or the results ; TryReturn(slot): zeros, and the error last
1073+ load [slot]; jz ok ; Gen.jumpIf(ok, false)
1074+ and rsp, -16 ; Gen.tryAlign, if a deferred statement is in force
1075+ call deferred... ; runDefers(0), as for a return
1076+ mov rax/rdx or the results ; Gen.tryReturn(slot): zeros, and the error last
10471077 jmp exit
10481078 ok: ...
10491079 ```
@@ -1051,117 +1081,130 @@
10511081 Unlike `return`, which is a statement and finds gen's stack empty,
10521082 `try` can stand in the middle of an expression, with values waiting
10531083 on gen's stack and quadwords pushed for another call's arguments. The
1054-out-of-line code therefore makes no entry on the stack: `TryReturn`
1055-loads registers and jumps, and `TryAlign` makes the machine's stack
1084+out-of-line code therefore makes no entry on the stack: `tryReturn`
1085+loads registers and jumps, and `tryAlign` makes the machine's stack
10561086 even for the deferred statements, which expect it so. The code that
10571087 follows is the code for an error that is nil, with the stack as it
10581088 was, so no model needs resetting.
10591089
1060-Then declarations: `Declarations` reads `const`, `type`, `var`, `proc`
1061-and `extern`, each one through `Declaration`, a recovery point, which
1062-calls `ConstDecl`, `TypeDecl`, `VarDecl`, `ProcDecl` or `ExternDecl`. `ProcDecl` handles forward declarations, code procedures
1063-(`CodeBody`, which checks the signature, a slice parameter counting as
1090+Then declarations: `declarations` reads `const`, `type`, `var`, `proc`
1091+and `extern`, each one through `declaration`, a recovery point, which
1092+calls `constDecl`, `typeDecl`, `varDecl`, `procDecl` or `externDecl`
1093+(by `declarationOf`). `procDecl` handles forward declarations, code procedures
1094+(`codeBody`, which checks the signature, a slice parameter counting as
10641095 two of the six integer registers and a slice result going in rax and
1065-rdx, and has gen's `CodeProc` run
1066-the target's assembler) and bodies (`Body`).
1067-`ParseType` and its helpers (`RecordType`, `VariantType`, `Signature`,
1068-`EnumType`) build `TType`s.
1096+rdx, and has gen's `codeProc` run
1097+the target's assembler) and bodies (`body`).
1098+`parseType` and its helpers (`recordType`, `variantType`, `signature`,
1099+`enumType`) build `Sym.Type`s.
10691100
1070-Last, modules, at the end of the file. `CompileFile` reads one module.
1071-`ImportModule` finds a module's file, trying the target's names first,
1072-and compiles it if it isn't yet. `CheckOneModule` first makes sure no
1101+Last, modules, at the end of the file. `compileFile` reads one module.
1102+`importModule` finds a module's file, trying the target's names first,
1103+and compiles it if it isn't yet. `checkOneModule` first makes sure no
10731104 later directory has the module too, unless the file is a link to one
1074-of its files there; `CheckSiblings` then reads the files for other
1075-targets beside it, declarations only, and `CompareIface` holds them
1105+of its files there; `checkSiblings` then reads the files for other
1106+targets beside it, declarations only, and `compareIface` holds them
10761107 to the same exports by their fingerprints. A generic module is
10771108 compiled once per distinct list of arguments, where it is first used.
1078-The import only notes where its arguments are (`SkipArgs`, `deferred`);
1079-`FirstUse`, from `QualIdent`, has `MakeInstance` go back there, where
1080-`ParseArgs` reads them, then compile the instance. `Params` binds them
1081-to the module's parameters, and `IsModule` decides whether an instance
1109+The import only notes where its arguments are (`skipArgs`, `deferred`);
1110+`firstUse`, from `qualIdent`, has `makeInstance` go back there, where
1111+`parseArgs` reads them, then compile the instance. `moduleParams` binds them
1112+to the module's parameters, and `isModule` decides whether an instance
10821113 already exists. An instance can't be compiled in the middle of another
10831114 procedure's code, since the code buffer is one run of bytes, so
1084-`InstancesFor` reads ahead through a procedure, or the module's body,
1115+`instancesFor` reads ahead through a procedure, or the module's body,
10851116 before its code begins, and makes the instances it names.
10861117
10871118 **Recovery.** After an error the parser carries on, so that one run
1088-reports them all. `Guard` notes, at the start of a statement or
1089-declaration, the scanner's state and the parser's; `setjmp` marks the
1090-place, and `MarkAt` jumps back to it after reporting. `Restore` puts
1119+reports them all. The Pascal seed did it with `setjmp` and `longjmp`;
1120+raz has neither, so here an error is a value. `Scan.mark` and the
1121+routines like it show the message and return the `ERROR` `Scan.Failed`;
1122+each routine that calls one passes it up with `try`, until it reaches a
1123+recovery point, `statement` or `declaration`, which looks at what came
1124+back. At the start of its construct it called `guard`, which notes in a
1125+`Recover` the scanner's state and the parser's (the scopes, gen's stack,
1126+the loop, the deferred statements, `quiet`). On an error `restore` puts
10911127 the state back, the construct's first symbol current again, and
1092-`SkipConstruct` reads past it, counting the words that open and close
1128+`skipConstruct` reads past it, counting the words that open and close
10931129 blocks. A symbol at the start of a line ends the skip: by the usual
10941130 layout it starts the next declaration, so the statement gives up its
1095-procedure (`GiveUp`), and `SkipProc` reads to the procedure's
1096-`end Name;`. A name not declared is reported by `NotDeclared`, with
1097-what it may have meant: a module to import (`ModuleFile`) or a name
1098-spelled alike. It is then declared where it is used, with the type
1099-`tPoison` (`Poison`), as are the names of a declaration that had an
1100-error; a construct that uses poison sets `quiet`, and its errors
1101-aren't reported, since they follow from one that was. Nothing breaks
1102-for the half-made code: once there is an error, no executable is
1103-written.
1131+procedure (`giveUp`), which passes the error on up to the next
1132+recovery point, the declaration of the procedure, and `skipProc`
1133+reads to the procedure's `end Name;`. A declaration that is not a
1134+procedure is skipped by `skipDeclaration`. `guards` counts the recovery
1135+points open: `giveUp` with none left ends the compile. A routine that
1136+can't fail has no `ERROR` result (`declarations`, `declaration`). A name not declared is reported by
1137+`notDeclared`, with what it may have meant: a module to import
1138+(`moduleFile`) or a name spelled alike (`didYouMean`). It is then
1139+declared where it is used, with the type `tPoison` (`poison`), as are
1140+the names of a declaration that had an error; a construct that uses
1141+poison sets `Diag.quiet` (by `Diag.setQuiet`, since a variable
1142+exported by another module is read-only), and its errors aren't
1143+reported, since they follow from one that was. Nothing breaks for the
1144+half-made code: once there is an error, no executable is written.
11041145
11051146 **Hints.** Some messages guess at the mistake from the layout. A
1106-block statement passes `CloseEnd` its start and how far its line is
1147+block statement passes `closeEnd` its start and how far its line is
11071148 indented; an `end` further left was most likely meant for a block
1108-around it, so the first such statement is kept, and `EndMissing`
1149+around it, so the first such statement is kept, and `endMissing`
11091150 notes it when a procedure's own `end` turns out to be missing. A type
1110-error in an argument goes through `Mismatch`, which notes the
1111-parameter it goes to (`passing`, set by `PassArg`).
1151+error in an argument goes through `Item.mismatch`, which notes the
1152+parameter it goes to (`Item.passing`, set by `Item.passArg`).
11121153
1113-**Warnings.** `Declare` keeps each module's declarations in order in
1114-two lists, through `link`: its own and its procedures', parameters
1115-and a match's names for fields among them. `Named` marks an object
1154+**Warnings.** `declare` keeps each module's declarations in order in
1155+two lists, through `chain`: its own (`first`) and its procedures'
1156+(`locals`), parameters
1157+and a match's names for fields among them. `named` marks an object
11161158 `used` and `read` wherever a name finds it, except a procedure naming
1117-itself; `LeftSide` puts `read` back as it was for a variable named
1159+itself; `leftSide` puts `read` back as it was for a variable named
11181160 whole before `:=`, which is written, not read. At the end of a module
1119-with no errors, `Warnings` merges the two lists by position and `Warn`
1161+with no errors, `warnings` merges the two lists by position and `warn`
11201162 reports what isn't exported, doesn't start with `_`, and was never
11211163 used, or, for a variable, only assigned, and a procedure with results
11221164 that may reach its end (`openEnd`, from `ends`, which each statement
11231165 sets). The calls that drop results are a third list, `drops`, in
1124-order: `CompileFile` notes where the module's own begin, since the
1125-instances it makes along the way add theirs and take them back. A
1166+order: `compileFile` notes where the module's own begin (`numDrops`),
1167+since the instances it makes along the way add theirs and take them
1168+back. A
11261169 generic module's instances
11271170 share its text, so only the first is warned of.
11281171
1129-The built-in procedures are in `Builtin` (and `New_`, `Atomic`): each
1172+The built-in procedures are in `builtin` (and `new_`, `atomic`): each
11301173 parses its own arguments, since `SIZE` takes a type and `INC` a
11311174 variable.
11321175
11331176 **Register variables.** One pass can't know whether a variable's
1134-address will be taken before its code is made, so `ChooseRegs` reads
1135-the body ahead, as `InstancesFor` does, and counts each variable's
1177+address will be taken before its code is made, so `chooseRegs` reads
1178+the body ahead, as `instancesFor` does, and counts each variable's
11361179 uses: 1 for each, 4 in a loop, 16 in two, at most 64 (loops nested three
11371180 deep or more); one `ADR` takes is out. The
11381181 busiest used at least three times get the five registers (`o^.reg`),
11391182 a slice two (`o^.reg2` too), its count halved for each, and the
1140-busiest reals the four of `XVarRegs`, each with a slot as well
1141-(`PlaceLocals`, `XHome`). An
1183+busiest reals the four of `Gen.XVarRegs`, each with a slot as well
1184+(`placeLocals`, `Gen.xHome`). An
11421185 address wanted after all, by a `var` parameter, say, comes to
1143-`Address` (`item.pas`), which puts the variable back in memory and
1144-sets `demoted`: `Body` then throws the procedure's code away
1145-(`MarkCode`, `Redo`), places the locals again, and compiles its
1186+`Item.address`, which puts the variable back in memory and
1187+sets `Item.demoted`: `body` then throws the procedure's code away
1188+(`Gen.markCode`, `Gen.redo`), places the locals again, and compiles its
11461189 statements again. Its notes for
1147-the trap report are made after, by `VarKind`, which marks a variable
1190+the trap report are made after, by `varKind`, which marks a variable
11481191 in a register with the register's number.
11491192
1150-## link.pas: tree shaking and layout
1193+## Link.raz: tree shaking and layout
11511194
1152-`MarkLive` starts from the entry chunk and follows fixups, marking each
1195+`markLive` starts from the entry chunk and follows fixups, marking each
11531196 chunk it reaches, through the data fixups of constants too; nothing
1154-else goes into the executable. `LinkAll`
1155-places the live chunks section by section (`Place`), each at its
1197+else goes into the executable. `linkAll`
1198+places the live chunks section by section (`place`), each at its
11561199 alignment, then copies their bytes into the images of text and rodata,
11571200 patching every fixup with the distance from the end of its field to its
11581201 target, and every data fixup with its target's address.
11591202
1160-Between placing text and placing rodata, `MakePlaces` writes the
1203+Between placing text and placing rodata, `makePlaces` writes the
11611204 places, a rodata chunk: for the trap report, each live procedure's
1162-address range and name, and its variables, which `Body` (`parse.pas`)
1163-notes with `NoteVar`: each one's name, its place in the frame and how
1164-`Rt` shows it (`VarKind`); then the line table (`MakeLines`), DWARF
1205+address range and name, and its variables, which `Parse.body`
1206+notes with `Chunk.noteVar`: each one's name, its place in the frame and how
1207+`Rt` shows it (`varKind`); then the line table (`makeLines`), DWARF
11651208 4's line program, which gdb reads as `.debug_line`: one sequence of
11661209 rows for each procedure, a row for each line note in live code, its
11671210 address, file, line and column. A row that moves the address and the
@@ -1184,12 +1227,12 @@
11841227 own code, and `exit` has `profile` say which procedures and places
11851228 those fell in, by the same tables: each procedure's samples in its own
11861229 code, and its total, counting once each sample it was on the chain of.
1187-The entry point gives Rt what the program has (`TLink`): the places,
1230+The entry point gives Rt what the program has (`Gen.Link`): the places,
11881231 `calls`, which tells the calls under way, `place`, which says where an
11891232 address is, and the profiler's start. What it isn't given, nothing
11901233 reaches, so the linker leaves it out: `raz -noprofile` gives no
11911234 profiler, and `raz -s` none of them, whose failures say only their
1192-address (and `elf.pas` writes no symbols or line numbers). Hello is 28
1235+address (and `Elf.raz` writes no symbols or line numbers). Hello is 28
11931236 KB, 21 KB without the profiler, and 7 KB stripped.
11941237
11951238 The layout is chosen so the file can be mapped as it lies, with no
@@ -1199,9 +1242,9 @@
11991242 segments, with their different permissions, share a page. bss follows
12001243 the loader's table, or begins a page of its own.
12011244
1202-## elf.pas: the executable
1245+## Elf.raz: the executable
12031246
1204-`WriteElf` writes the ELF header, the program headers, the text and
1247+`writeElf` writes the ELF header, the program headers, the text and
12051248 rodata images, and then what isn't loaded: section headers, a symbol
12061249 table with every live procedure and variable by `Module.name`, and
12071250 the compile unit that names the line table. The line table is in the
@@ -1211,34 +1254,36 @@
12111254 loader accepts: an interpreter header naming the loader; a dynamic
12121255 section naming the libraries; and, for each C symbol the program uses,
12131256 a symbol and a `GLOB_DAT` relocation that has the loader write the
1214-symbol's address into the quadword `ExternChunk` made. Code calls C
1257+symbol's address into the quadword `Chunk.externChunk` made. Code calls C
12151258 through that quadword. There is no PLT and no lazy binding.
1216-`SizeTables` and `PutTables` lay these out in the room `link.pas` left
1259+`sizeTables` and `putTables` lay these out in the room `Link.raz` left
12171260 at the end of rodata.
12181261
1219-Line numbers are DWARF 4: the line table `MakeLines` made from the
1220-notes `NoteLine` made, and the single compile unit gdb needs to find
1221-it, which `PutDebug` writes. There are no types or variables in it;
1262+Line numbers are DWARF 4: the line table `makeLines` made from the
1263+notes `Chunk.noteLine` made, and the single compile unit gdb needs to find
1264+it, which `putDebug` writes. There are no types or variables in it;
12221265 gdb can stop at a line and show where it is, not print a variable.
12231266
1224-## raz.pas: the command line
1267+## Raz.raz: the command line
12251268
1226-`raz.pas` parses the arguments, calls `CompileMain`, and works out what
1227-the program uses: `Use` marks the modules imported from the main module
1228-and `Rt`; `UsesC` decides whether the program is dynamic, refusing one
1269+`Raz.raz` parses the arguments, calls `Parse.compileMain`, and works out what
1270+the program uses: `use` marks the modules imported from the main module
1271+and `Rt`; `usesC` decides whether the program is dynamic, refusing one
12291272 that both uses C and has a module saying `link static`. Then it has
1230-gen's `EntryPoint` write the entry point, and `MarkLive` mark what it
1231-reaches. On a target
1232-without reals (`HasReals`, beside `Target` in `parse.pas`; x86-64 has
1273+gen's `entryPoint` write the entry point, and `Link.markLive` mark what it
1274+reaches. The program is `proc main*: INT`; where raz is, for the library
1275+beside it, it reads from `/proc/self/exe`, and the version it prints is
1276+the module `Version`, which the build makes from `git describe`. On a target
1277+without reals (`HasReals`, a constant of `Parse`; x86-64 has
12331278 them), a live chunk that computes with one is an error at the first
1234-place it does: `UsesReals` in `item.pas` notes it, from `Value` and a
1279+place it does: `Item.usesReals` notes it, from `Item.value` and a
12351280 real literal, on the chunk of the procedure being compiled. A real
12361281 moved whole, as a record's bytes are, isn't noted. A static program starts at `_start` itself. A dynamic
12371282 one starts at a `_start` that calls `__libc_start_main` the way C's own
12381283 start-up does, which sets C up and calls back a `main` that runs the
12391284 module bodies and the program's `main`.
12401285
1241-`raz -S` lists the code (`List`, in `x64.pas`) instead of writing
1286+`raz -S` lists the code (`X64.list`) instead of writing
12421287 it. `raz run` writes the executable to a memfd, a file only in memory, and
12431288 executes it through `/proc/self/fd` in raz's own place, handing it the
12441289 rest of raz's `argv`. Nothing is left on disk, and the program's
@@ -1259,23 +1304,23 @@
12591304 a link to it (`make install` puts `raz` and `lib/` together in
12601305 `PREFIX/lib/raz`). In each directory it tries `X.linux-x86_64.raz`,
12611306 `X.linux.raz`, `X.x86_64.raz` and `X.raz`, in that order, and takes
1262- the first found (`ModuleFile`, `parse.pas`).
1307+ the first found (`moduleFile`, `Parse.raz`).
12631308 - **Errors.** Every error in a run is reported, up to 20 (`MaxErrors`,
1264- `diag.pas`); then the compiler stops. Two errors at the same place
1309+ `Diag.raz`); then the compiler stops. Two errors at the same place
12651310 are told as one. Any error is status 1.
12661311 - **Warnings.** Of a declaration never used, or a variable only
1267- assigned (`Warn`, `parse.pas`): not of what is exported, a name that
1312+ assigned (`warn`, `Parse.raz`): not of what is exported, a name that
12681313 starts with `_`, an enumeration's names or a generic module's
12691314 parameters. A procedure naming itself doesn't use it; a type named by
12701315 a pointer in its own declaration does. Assigning a variable whole
12711316 (`x :=`, `a, b :=`) doesn't read it; anything else does. Warnings
12721317 come only for a module with no errors, and a generic module's only
12731318 for its first instance. A procedure with results is warned of if
1274- it may reach its end without `return` (`ends`, `parse.pas`): each
1319+ it may reach its end without `return` (`ends`, `Parse.raz`): each
12751320 way through its statements must end in a `return`, an `if` with an
12761321 `else`, a `match`, a `while true` or a `repeat ... until false`
12771322 with no `break`. So is a call standing on its own that drops a
1278- result (`drops`, kept by `OneStatement` and told by `Dropped`);
1323+ result (`drops`, kept by `noteDrop` and told by `dropped`);
12791324 `_ := f(x)` drops one on purpose. `-Werror` makes each an error.
12801325 - **Registers for variables.** Up to five of a procedure's single
12811326 values, not reals, whose address is never taken, live in `rbx` and
@@ -1317,24 +1362,29 @@
13171362 module body runs.
13181363 - **Frames.** A deferred statement's slots stay reserved for the rest
13191364 of its procedure. A generic instance first used in a procedure, or in
1320- a module's body, is made before that code begins (`InstancesFor`).
1365+ a module's body, is made before that code begins (`instancesFor`).
13211366 - **The executable** carries DWARF line numbers and the names of
13221367 procedures for gdb, and the places (`Rt.places`), which hold the
13231368 line table, DWARF's, that gdb reads and `Rt` runs.
13241369
13251370 ## Where to start changing it
13261371
1327-- **A built-in procedure:** an entry in `sym.pas`'s universe, a case in
1328- `Builtin` in `parse.pas`, and the code, in `gen.pas` if it is an
1372+- **A built-in procedure:** an entry in `Sym.raz`'s universe (`enter`),
1373+ a case in `builtin` in `Parse.raz`, and the code, in `Gen.raz` if it is an
13291374 instruction, or of calls to gen right there.
1330-- **An instruction:** a routine in `x64.pas` built on `OpM` or `OpR`,
1331- and a line in `test/enctest.pas` to check its encoding.
1332-- **A machine:** a new `gen.pas`, answering the same calls, and an
1333- encoder and assembler for it in place of `x64.pas`.
1334-- **A statement:** a reserved word in `scan.pas` (in `TSym` and `Words`,
1335- in the same order), a case in `OneStatement`, and a routine beside the
1375+- **An instruction:** a routine in `X64.raz` built on `opM` or `opR`,
1376+ and a line in `test/enctest.pas` to check its encoding (the seed's
1377+ test; `test/X64Dump` is the port's).
1378+- **A machine:** a new `Gen.raz`, answering the same calls, and an
1379+ encoder and assembler for it in place of `X64.raz`.
1380+- **A statement:** a reserved word in `Scan.raz` (in `Sym` and `words`,
1381+ in the same order), a case in `oneStatement`, and a routine beside the
13361382 others.
1337-- **A check that fails:** `Check` in `gen.pas`, and the message in
1383+- **A check that fails:** `check` in `Gen.raz`, and the message in
13381384 `lib/Rt.raz`'s `fail`; a reason a signal gives, `onSignal` there.
13391385
1340-After any change: `make check`, `make bench`, `make loc`.
1386+The compiler is in raz, and `make raz` builds it with the seed, the
1387+frozen Pascal compiler in `seed/`, which is never edited to suit it;
1388+`make fixpoint` has it build itself twice more and checks that the last
1389+two are the same file. After any change: `make check`, `make bench`,
1390+`make loc`.

src/README.md (history) modified +6 -6

@@ -7,9 +7,9 @@
77 rules: plain code, each module opening with what it is, what it
88 depends on and what it leaves out. The seed is never edited from here.
99
10- make self # each unit against the seed's, on the same files
11- make self-bench # the scanner's speed against the seed's
12- make fixpoint # the seed builds self, that builds self, that builds it again
10+ make seed-check # each unit against the seed's, on the same files
11+ make seed-bench # the scanner's speed against the seed's
12+ make fixpoint # the seed builds src, that builds src, that builds it again
1313
1414 `Chunk` and `Sym` have no input files to read, so each has a dumper
1515 pair, `test/ChunkDump` and `test/SymDump`, that runs one fixed
@@ -41,14 +41,14 @@
4141 point into is `test/ItemDump.txt`.
4242
4343 `Parse` and `Raz`, the last two units, are tested whole: the seed builds
44-`src/Raz.raz` into `build/self/raz.self`, and each compiler, run as
44+`src/Raz.raz` into `build/src/raz.src`, and each compiler, run as
4545 `build/cmp/raz` (a program holds the paths it was made from, and the
4646 library is found beside the compiler), compiles the library, the
4747 examples, the tools, `src/` itself, every test of `test/` and
4848 `conform/`, and the 348,025-line program of `test/genbench.py`, with the
4949 options each test has. The executable, the messages, and the status
5050 must be the same for every file: 409 of them, 289 of which are errors.
51-`make self-bench` gives the speed of both.
51+`make seed-bench` gives the speed of both.
5252
5353 `make fixpoint` (`fixpoint.sh`) is the proof that the port is whole:
5454 the seed builds `Raz.raz` (stage 1), stage 1 builds it (stage 2), and
@@ -167,7 +167,7 @@
167167 `raz run` writes the memfd with `Elf.writeElf` and executes it with
168168 the system call, `execve`, which `Sys` has no procedure for. The
169169 version is the module `Version`, which `check.sh` makes in
170- `build/self/` from `build/version.inc`, as the seed's `{$I}` is.
170+ `build/src/` from `build/version.inc`, as the seed's `{$I}` is.
171171 Two names of a file, for a module found in two places, are told by
172172 the device and inode `SYSCALL` `stat` gives, which `Sys.info` lacks.
173173 - **Sets of `Scan.Sym`.** It has 76 names and a set holds 64, so the

src/Raz.raz (history) modified +1 -1

@@ -21,7 +21,7 @@
2121 Rt.exit then ends the program with.
2222
2323 Depends on: everything else, and Version, a module the build makes
24- (build/self/Version.raz) from what git describe says, as the seed's
24+ (build/src/Version.raz) from what git describe says, as the seed's
2525 build/version.inc is.
2626 Leaves out: the work itself; the other units compile, link and
2727 write, and this only reads the command line and runs them in order. *)

src/bench.sh (history) modified +5 -5

@@ -3,12 +3,12 @@
33 # benchmark program: the best of seven runs of each. Run from the
44 # repository root, after src/check.sh has built the tests.
55 set -e
6-b=build/self
6+b=build/src
77 python3 test/genbench.py 12000 >$b/Bench.raz
88 fpc -O2 -Mobjfpc -Sh- -vew -FUbuild -Fuseed -o$b/scanbench.seed src/test/ScanBench.pas >/dev/null
9-./raz -Werror -I src -o $b/scanbench.self src/test/ScanBench.raz
9+./raz -Werror -I src -o $b/scanbench.src src/test/ScanBench.raz
1010 echo "$(wc -l <$b/Bench.raz) lines"
11-for t in seed self; do
11+for t in seed src; do
1212 best=0
1313 for i in 1 2 3 4 5 6 7; do
1414 s=$(date +%s%N); $b/scanbench.$t $b/Bench.raz >/dev/null; e=$(date +%s%N)
@@ -23,8 +23,8 @@
2323 mkdir -p build/cmp/bench
2424 ln -sfn ../../lib build/cmp/lib
2525 cp $b/Bench.raz build/cmp/bench/Bench.raz
26-for t in seed self; do
27- if [ $t = seed ]; then cp raz build/cmp/raz; else cp $b/raz.self build/cmp/raz; fi
26+for t in seed src; do
27+ if [ $t = seed ]; then cp build/seed/raz build/cmp/raz; else cp $b/raz.src build/cmp/raz; fi
2828 best=0
2929 for i in 1 2 3 4 5; do
3030 s=$(date +%s%N); build/cmp/raz -o build/cmp/bench/Bench.$t build/cmp/bench/Bench.raz; e=$(date +%s%N)

src/check.sh modified +31 -31

@@ -4,10 +4,10 @@
44 # status. Run from the repository root, after `make raz`; the seed's
55 # side is built by fpc from seed/.
66 set -e
7-b=build/self
7+b=build/src
88 mkdir -p $b
99 fpc -O2 -Mobjfpc -Sh- -vew -FUbuild -Fuseed -o$b/scandump.seed src/test/ScanDump.pas >/dev/null
10-./raz -Werror -I src -o $b/scandump.self src/test/ScanDump.raz
10+./raz -Werror -I src -o $b/scandump.src src/test/ScanDump.raz
1111 python3 src/test/genreals.py > $b/reals.raz
1212 # one small file for each message the scanner makes, and the places
1313 # diag shows them in: a tab, a long line, characters before the place
@@ -19,9 +19,9 @@
1919 [ -f "$f" ] || continue
2020 s1=0; s2=0
2121 $b/scandump.seed $f >$b/seed.out 2>$b/seed.err || s1=$?
22- $b/scandump.self $f >$b/self.out 2>$b/self.err || s2=$?
22+ $b/scandump.src $f >$b/src.out 2>$b/src.err || s2=$?
2323 n=$((n + 1))
24- if [ $s1 != $s2 ] || ! cmp -s $b/seed.out $b/self.out || ! cmp -s $b/seed.err $b/self.err; then
24+ if [ $s1 != $s2 ] || ! cmp -s $b/seed.out $b/src.out || ! cmp -s $b/seed.err $b/src.err; then
2525 echo "differs: $f (status $s1 and $s2)"; bad=$((bad + 1))
2626 fi
2727 done
@@ -40,18 +40,18 @@
4040 for u in Chunk Sym; do
4141 l=$(echo $u | tr A-Z a-z)
4242 fpc -O2 -Mobjfpc -Sh- -vew -FUbuild -Fuseed -o$b/${l}dump.seed src/test/${u}Dump.pas >/dev/null
43- ./raz -Werror -I src -o $b/${l}dump.self src/test/${u}Dump.raz
43+ ./raz -Werror -I src -o $b/${l}dump.src src/test/${u}Dump.raz
4444 done
4545 for a in "" dup deep; do
46- for s in seed self; do
46+ for s in seed src; do
4747 t=0; $b/chunkdump.$s >$b/chunk.$s 2>/dev/null || t=$?
4848 t2=0; $b/symdump.$s $a >$b/sym.$s.out 2>$b/sym.$s.err || t2=$?
4949 echo "$t $t2" >$b/status.$s
5050 done
51- cmp $b/status.seed $b/status.self
52- cmp $b/chunk.seed $b/chunk.self
53- cmp $b/sym.seed.out $b/sym.self.out
54- cmp $b/sym.seed.err $b/sym.self.err
51+ cmp $b/status.seed $b/status.src
52+ cmp $b/chunk.seed $b/chunk.src
53+ cmp $b/sym.seed.out $b/sym.src.out
54+ cmp $b/sym.seed.err $b/sym.src.err
5555 done
5656 echo "chunk and sym ok"
5757
@@ -59,11 +59,11 @@
5959 # as a static, a dynamic and a stripped executable, which must be the
6060 # same file from both sides
6161 fpc -O2 -Mobjfpc -Sh- -vew -FUbuild -Fuseed -o$b/linkdump.seed src/test/LinkDump.pas >/dev/null
62-./raz -Werror -I src -o $b/linkdump.self src/test/LinkDump.raz
62+./raz -Werror -I src -o $b/linkdump.src src/test/LinkDump.raz
6363 for m in 0 1 2; do
6464 $b/linkdump.seed $m $b/link.seed
65- $b/linkdump.self $m $b/link.self
66- cmp $b/link.seed $b/link.self
65+ $b/linkdump.src $m $b/link.src
66+ cmp $b/link.seed $b/link.src
6767 done
6868 echo "link and elf ok"
6969
@@ -71,21 +71,21 @@
7171 # of every kind and a file for each error it makes; the bytes and the
7272 # listing, or the message and status, must be the same
7373 fpc -O2 -Mobjfpc -Sh- -vew -FUbuild -Fuseed -o$b/x64dump.seed src/test/X64Dump.pas >/dev/null
74-./raz -Werror -I src -o $b/x64dump.self src/test/X64Dump.raz
74+./raz -Werror -I src -o $b/x64dump.src src/test/X64Dump.raz
7575 $b/x64dump.seed >$b/x64.seed
76-$b/x64dump.self >$b/x64.self
77-cmp $b/x64.seed $b/x64.self
76+$b/x64dump.src >$b/x64.src
77+cmp $b/x64.seed $b/x64.src
7878 fpc -O2 -Mobjfpc -Sh- -vew -FUbuild -Fuseed -o$b/asmdump.seed src/test/AsmDump.pas >/dev/null
79-./raz -Werror -I src -o $b/asmdump.self src/test/AsmDump.raz
79+./raz -Werror -I src -o $b/asmdump.src src/test/AsmDump.raz
8080 mkdir -p $b/asm
8181 python3 src/test/genasm.py $b/asm
8282 n=0; bad=0
8383 for f in $b/asm/*.raz; do
8484 s1=0; s2=0
8585 $b/asmdump.seed $f >$b/seed.out 2>$b/seed.err || s1=$?
86- $b/asmdump.self $f >$b/self.out 2>$b/self.err || s2=$?
86+ $b/asmdump.src $f >$b/src.out 2>$b/src.err || s2=$?
8787 n=$((n + 1))
88- if [ $s1 != $s2 ] || ! cmp -s $b/seed.out $b/self.out || ! cmp -s $b/seed.err $b/self.err; then
88+ if [ $s1 != $s2 ] || ! cmp -s $b/seed.out $b/src.out || ! cmp -s $b/seed.err $b/src.err; then
8989 echo "differs: $f (status $s1 and $s2)"; bad=$((bad + 1))
9090 fi
9191 done
@@ -97,11 +97,11 @@
9797 # line notes and listing must be the same; once with the static entry
9898 # point and once with the dynamic one
9999 fpc -O2 -Mobjfpc -Sh- -vew -FUbuild -Fuseed -o$b/gendump.seed src/test/GenDump.pas >/dev/null
100-./raz -Werror -I src -o $b/gendump.self src/test/GenDump.raz
100+./raz -Werror -I src -o $b/gendump.src src/test/GenDump.raz
101101 for a in "" dyn; do
102102 $b/gendump.seed $a >$b/gen.seed
103- $b/gendump.self $a >$b/gen.self
104- cmp $b/gen.seed $b/gen.self
103+ $b/gendump.src $a >$b/gen.src
104+ cmp $b/gen.seed $b/gen.src
105105 done
106106 echo "gen ok"
107107
@@ -110,14 +110,14 @@
110110 # made and the messages must be the same. A run ends at the 20th error,
111111 # as a compile does, so the script changes with each argument.
112112 fpc -O2 -Mobjfpc -Sh- -vew -FUbuild -Fuseed -o$b/itemdump.seed src/test/ItemDump.pas >/dev/null
113-./raz -Werror -I src -o $b/itemdump.self src/test/ItemDump.raz
113+./raz -Werror -I src -o $b/itemdump.src src/test/ItemDump.raz
114114 n=0; bad=0
115115 for a in $(seq 0 59); do
116116 s1=0; s2=0
117117 $b/itemdump.seed $a >$b/seed.out 2>$b/seed.err || s1=$?
118- $b/itemdump.self $a >$b/self.out 2>$b/self.err || s2=$?
118+ $b/itemdump.src $a >$b/src.out 2>$b/src.err || s2=$?
119119 n=$((n + 1))
120- if [ $s1 != $s2 ] || ! cmp -s $b/seed.out $b/self.out || ! cmp -s $b/seed.err $b/self.err; then
120+ if [ $s1 != $s2 ] || ! cmp -s $b/seed.out $b/src.out || ! cmp -s $b/seed.err $b/src.err; then
121121 echo "differs: item script $a (status $s1 and $s2)"; bad=$((bad + 1))
122122 fi
123123 done
@@ -131,7 +131,7 @@
131131 # holds the paths it was made from and the library is found beside the
132132 # compiler.
133133 printf 'module Version;\nconst Text* = "%s";\nend Version.\n' "$(tr -d "'" < build/version.inc)" >$b/Version.raz
134-./raz -Werror -I src -I $b -o $b/raz.self src/Raz.raz
134+./raz -Werror -I src -I $b -o $b/raz.src src/Raz.raz
135135 c=build/cmp
136136 mkdir -p $c
137137 ln -sfn ../../lib $c/lib
@@ -143,10 +143,10 @@
143143 conform/run/*.raz test/err/*.raz conform/err/*.raz; do
144144 files="$files $f"
145145 done
146-for side in seed self; do
146+for side in seed src; do
147147 rm -rf $c/$side
148148 mkdir -p $c/$side
149- if [ $side = seed ]; then cp raz $c/raz; else cp $b/raz.self $c/raz; fi
149+ if [ $side = seed ]; then cp build/seed/raz $c/raz; else cp $b/raz.src $c/raz; fi
150150 for f in $files; do
151151 dir=$(dirname $f); name=$(basename $f .raz); x=$(echo $dir | tr / _).$name
152152 flags=
@@ -156,7 +156,7 @@
156156 [ -f $dir/$name.args ] && [ $dir = test/err ] && flags="$flags $(cat $dir/$name.args)"
157157 case $dir in
158158 lib) opts= ;;
159- src|tools) opts="-I src -I build/self" ;;
159+ src|tools) opts="-I src -I build/src" ;;
160160 test/err) opts="-I test/err/mods -I test/run/mods" ;;
161161 *) opts="-I $dir/mods" ;;
162162 esac
@@ -170,8 +170,8 @@
170170 x=$(dirname $f | tr / _).$(basename $f .raz)
171171 n=$((n + 1))
172172 for e in "" .out .err .status; do
173- [ -f $c/seed/$x$e ] || [ -f $c/self/$x$e ] || continue
174- if ! cmp -s $c/seed/$x$e $c/self/$x$e; then
173+ [ -f $c/seed/$x$e ] || [ -f $c/src/$x$e ] || continue
174+ if ! cmp -s $c/seed/$x$e $c/src/$x$e; then
175175 echo "differs: $f ($x$e)"; bad=$((bad + 1)); break
176176 fi
177177 done

src/fixpoint.sh (history) modified +1 -1

@@ -13,7 +13,7 @@
1313 mkdir -p $d/v
1414 ln -s ../../lib $d/lib
1515 printf 'module Version;\nconst Text* = "%s";\nend Version.\n' "$(tr -d "'" < build/version.inc)" >$d/v/Version.raz
16-cp raz $d/stage0
16+cp build/seed/raz $d/stage0
1717 for n in 1 2 3; do
1818 cp $d/stage$((n - 1)) $d/raz
1919 $d/raz -Werror -I src -I $d/v -o $d/stage$n src/Raz.raz