examples/term.r8asm was a per-character echo (prompt, echo, backspace erase,
newline, EOF). It is now a small shell: a 4 character line buffer, a backspace
that really removes a character, and Enter -- or EOF, for a half typed line --
commits the line and dispatches on its first character. 'l' prints the length,
'r' prints the buffer backwards, 'q' quits, anything else is ignored.
The header session "lhi" exercises the whole chain: EOF commits the pending
line, so examples_test sees the '3'. Three more sessions are documented in the
header: "rab" gives NUL+'b'+'a'+'r', "lab<BS>" gives '2' (the backspace really
dropped the 'b'), and "lhi<NL>rxy<NL>" prints '3' then the reversed second
line.
Three things ate most of the debugging time; all three are written up in the
file:
* "else" needs a flag cell. biz enters when the low bit is set, so "if not A
then B" cannot be inferred from "the last test missed": set FLAG=1 before the
test, clear it in the matched branch, look at FLAG afterwards. And biz tests
the CURRENT dp cell, so the order has to be "set FLAG, then .tp to the
condition cell, then biz" -- the wrong order made every character look like
a commit key.
* clb_sub_nc eats its operands, so the echo and the append both work from the
copy CE. The first version appended C (already zeroed by the comparison),
which left the line buffer empty: 'l' printed 0 and 'r' printed four NULs.
* the cell layout dominates the tape. copy / clb_sub_nc / clb_nonzero all emit
.tp internally, some of them inside %rep _CELL_SIZE, so a 20 cell gap costs
a couple of thousand characters: putting the constants at 22..28 gave 33067
characters, packing the hot cells into 0..27 gives 21721.
The buffer is left aligned with a length counter -- appending needs a dispatch
on LEN, but backspace is just LEN-- -- and 'r' prints all four cells instead of
dispatching on the length, which costs a NUL for the unused cells and is
documented.
tests/widths.ps1 now also checks term.r8asm at every width (its expected
stream is width independent, which is what makes it a good second program for
the matrix), and TODO/AGENTS/README record the item as done.