| | @@ -303,24 +303,72 @@ |
| 303 | 303 | form stays small enough to have one: every instruction added must be |
| 304 | 304 | easy to interpret, or it doesn't belong. |
| 305 | 305 | |
| 306 | | -## Open questions |
| 306 | +## Reading an object file |
| 307 | 307 | |
| 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. |