raz / commit 76a05a0c

commit
76a05a0c3d0f359d8c80eb0d7b1cffa60b6326b7
author
Luis <42945842+ldiaz94@users.noreply.github.com>
date
parent
6b556e95
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.

patch · log

2 files changed, +75 -23

PLAN.md (history) modified +7 -3

@@ -66,9 +66,8 @@
6666
6767 ## Proposed, v0.6.0: raz to be rebuilt by anyone
6868
69-Under way: step 3, `doc/ir.md`, is in review; the report's draft
70-2026-10.11 is agreed. The freeze doesn't hold for this
71-work, by the owner's word.
69+Under way: steps 1 to 3 are agreed; step 4 is next. The freeze
70+doesn't hold for this work, by the owner's word.
7271
7372 **For:** a language a person alone can implement again, from the
7473 report, on any machine, in weeks; programs that run on small machines
@@ -136,6 +135,11 @@
136135 - [ ] 9e. A profiler in `Rt`: a program run with `RAZ_PROFILE` set
137136 samples where it is, and at its end says which procedures and
138137 lines took the time.
138+- [ ] 9f. `tools/Obj.raz`: an object file shown for a person to read,
139+ its interface as raz, its code in the text form under each line
140+ of source, its data as bytes and characters; written from
141+ `doc/ir.md` alone, apart from the compiler, as the proof that the
142+ form can be read by another program.
139143 - [ ] 10. `doc/compiler.md`, README, the budget, the report's version
140144 and the compiler's; tag `v0.6.0`.
141145

doc/ir.md modified +68 -20

@@ -303,24 +303,72 @@
303303 form stays small enough to have one: every instruction added must be
304304 easy to interpret, or it doesn't belong.
305305
306-## Open questions
306+## Reading an object file
307307
308-1. **Locals in registers.** The form reaches every variable through
309- `frame k`, so a back end can keep the stack in registers, but not a
310- variable. Keeping variables in registers too (the next step in
311- speed) needs to know which variables never have their address
312- taken. The parser could mark them in the procedure's header at its
313- end, since it has seen every `ADR` by then. Proposed: leave it out
314- of v0.6.0, and keep room in the header for it.
315-2. **Text or binary.** The object file is binary, for speed. A text
316- form, as written above, is what `raz -S` would print, and what the
317- tests of the back end compare. Proposed: both, the text one only
318- for reading.
319-3. **Statements deferred.** The parser compiles a deferred statement
320- once, as a piece of its procedure that ends in `back`, and calls it
321- with `gosub` at each way out of its list, newest first, as today's
322- compiler does with a call inside the procedure. The other way,
323- compiling it again at each way out, needs no `gosub` but makes the
324- code bigger and the parser read the statement more than once.
325- Proposed: keep `gosub`, which costs an interpreter a stack of places
326- to go back to.
308+`tools/Obj.raz` shows what an object file holds, for a person to
309+read: `Obj List.o` prints it, part by part, as the file has them. It
310+reads the binary form by itself, from this document, not through the
311+compiler; so it is also the proof that the form is described well
312+enough to be read by a program written apart.
313+
314+It prints the declarations in raz, the code in the text form above,
315+each statement under its line of source when the source is there,
316+and data as bytes beside their characters. For example:
317+
318+```
319+List.o linux-x86_64, form 1
320+interface 4F1A 09C2 77E0 3B15
321+
322+imports
323+ Mem interface 1D02 88A1 C3F0 0E47 current
324+ Rt interface 6B3E 0412 9D5C A781 changed: compile List again
325+
326+exports
327+ type Node* = record next*: ^Node; val*: I64; end; size 16, align 8
328+ type List* = record head*: ^Node; len*: INT; ... end; size 24, align 8
329+ proc push*(l: ^List; v: I64): BOOL;
330+
331+proc List.push params: w l results: w frame 32 align 16
332+ no address taken: l, v, n
333+
334+ 12 | NEW(n, l^.a);
335+ frame 16
336+ ...
337+ 13 | if n = nil then return false; end;
338+ frame 16
339+ load.w
340+ const.w 0
341+ eq.w
342+ jz 1
343+ const.w 0
344+ ret
345+ label 1
346+ ...
347+
348+data List.Full rodata, 16 bytes, align 1
349+ 0000 6E 6F 20 72 6F 6F 6D 20 66 6F 72 20 69 74 00 00 no room for it..
350+
351+instances none
352+
353+places 14 lines, 3 checks
354+```
355+
356+Each part can be asked for alone (`Obj -code List.o`, `Obj
357+-interface List.o`), and `-S` gives the code alone, as `raz -S` does
358+for a whole program. The text form it prints is the one the back
359+end's tests compare, so that it is kept exact.
360+
361+## Settled
362+
363+These were open questions; the owner chose as proposed.
364+
365+1. **Locals in registers** are left out of v0.6.0. A procedure's
366+ header has room for the variables whose address is never taken,
367+ which the parser knows at the procedure's end, so that a later back
368+ end can keep them in registers without the form changing; the dump
369+ above shows it.
370+2. **Binary and text.** The object file is binary. The text form
371+ is for people and for tests: `raz -S`, and `tools/Obj.raz`, which
372+ prints a whole object file.
373+3. **Deferred statements** are compiled once, end in `back`, and are
374+ run with `gosub` at each way out of their list.