From 76a05a0c3d0f359d8c80eb0d7b1cffa60b6326b7 Mon Sep 17 00:00:00 2001 From: Luis <42945842+ldiaz94@users.noreply.github.com> Date: Sun, 11 Oct 2026 21:22:03 +0000 Subject: [PATCH] doc/ir.md settled; tools/Obj.raz shows an object file The three questions go as proposed: room in a procedure's header for the variables whose address is never taken, binary object files with a text form for people and tests, gosub for deferred statements. tools/Obj.raz prints an object file for a person to read, written from doc/ir.md alone; it is step 9f. --- diff --git a/PLAN.md b/PLAN.md index 1988f67..bb3d274 100644 --- a/PLAN.md +++ b/PLAN.md @@ -66,9 +66,8 @@ ## Proposed, v0.6.0: raz to be rebuilt by anyone -Under way: step 3, `doc/ir.md`, is in review; the report's draft -2026-10.11 is agreed. The freeze doesn't hold for this -work, by the owner's word. +Under way: steps 1 to 3 are agreed; step 4 is next. The freeze +doesn't hold for this work, by the owner's word. **For:** a language a person alone can implement again, from the report, on any machine, in weeks; programs that run on small machines @@ -136,6 +135,11 @@ - [ ] 9e. A profiler in `Rt`: a program run with `RAZ_PROFILE` set samples where it is, and at its end says which procedures and lines took the time. +- [ ] 9f. `tools/Obj.raz`: an object file shown for a person to read, + its interface as raz, its code in the text form under each line + of source, its data as bytes and characters; written from + `doc/ir.md` alone, apart from the compiler, as the proof that the + form can be read by another program. - [ ] 10. `doc/compiler.md`, README, the budget, the report's version and the compiler's; tag `v0.6.0`. diff --git a/doc/ir.md b/doc/ir.md index e539c37..a21cb05 100644 --- a/doc/ir.md +++ b/doc/ir.md @@ -303,24 +303,72 @@ form stays small enough to have one: every instruction added must be easy to interpret, or it doesn't belong. -## Open questions +## Reading an object file -1. **Locals in registers.** The form reaches every variable through - `frame k`, so a back end can keep the stack in registers, but not a - variable. Keeping variables in registers too (the next step in - speed) needs to know which variables never have their address - taken. The parser could mark them in the procedure's header at its - end, since it has seen every `ADR` by then. Proposed: leave it out - of v0.6.0, and keep room in the header for it. -2. **Text or binary.** The object file is binary, for speed. A text - form, as written above, is what `raz -S` would print, and what the - tests of the back end compare. Proposed: both, the text one only - for reading. -3. **Statements deferred.** The parser compiles a deferred statement - once, as a piece of its procedure that ends in `back`, and calls it - with `gosub` at each way out of its list, newest first, as today's - compiler does with a call inside the procedure. The other way, - compiling it again at each way out, needs no `gosub` but makes the - code bigger and the parser read the statement more than once. - Proposed: keep `gosub`, which costs an interpreter a stack of places - to go back to. +`tools/Obj.raz` shows what an object file holds, for a person to +read: `Obj List.o` prints it, part by part, as the file has them. It +reads the binary form by itself, from this document, not through the +compiler; so it is also the proof that the form is described well +enough to be read by a program written apart. + +It prints the declarations in raz, the code in the text form above, +each statement under its line of source when the source is there, +and data as bytes beside their characters. For example: + +``` +List.o linux-x86_64, form 1 +interface 4F1A 09C2 77E0 3B15 + +imports + Mem interface 1D02 88A1 C3F0 0E47 current + Rt interface 6B3E 0412 9D5C A781 changed: compile List again + +exports + type Node* = record next*: ^Node; val*: I64; end; size 16, align 8 + type List* = record head*: ^Node; len*: INT; ... end; size 24, align 8 + proc push*(l: ^List; v: I64): BOOL; + +proc List.push params: w l results: w frame 32 align 16 + no address taken: l, v, n + + 12 | NEW(n, l^.a); + frame 16 + ... + 13 | if n = nil then return false; end; + frame 16 + load.w + const.w 0 + eq.w + jz 1 + const.w 0 + ret + label 1 + ... + +data List.Full rodata, 16 bytes, align 1 + 0000 6E 6F 20 72 6F 6F 6D 20 66 6F 72 20 69 74 00 00 no room for it.. + +instances none + +places 14 lines, 3 checks +``` + +Each part can be asked for alone (`Obj -code List.o`, `Obj +-interface List.o`), and `-S` gives the code alone, as `raz -S` does +for a whole program. The text form it prints is the one the back +end's tests compare, so that it is kept exact. + +## Settled + +These were open questions; the owner chose as proposed. + +1. **Locals in registers** are left out of v0.6.0. A procedure's + header has room for the variables whose address is never taken, + which the parser knows at the procedure's end, so that a later back + end can keep them in registers without the form changing; the dump + above shows it. +2. **Binary and text.** The object file is binary. The text form + is for people and for tests: `raz -S`, and `tools/Obj.raz`, which + prints a whole object file. +3. **Deferred statements** are compiled once, end in `back`, and are + run with `gosub` at each way out of their list.