Using lambda notation to put the address of a string on the data stack is all well and good, but after writing some fairly torturous code to modify the first cell with the length of that string at run time, decided that the assembler should have a syntax for doing that at compile time. The result should be the address of the initial "count" cell on the data stack, with count characters immediately following in consecutive cells. Here's what the assembler and emulator now support:
["Hello, $20, "World! 10, ]" console.outlen @t out, console.write %d+1 out,
That is `["` introduces a counted string, and at run-time jumps past the `]"` marker but leaves the address of the counted string on %d. At compile time, the `]"` back-patches the jump destination address, and the count of number of cells in the string.
I also modified the console device so that when port `outlen` is zero, a value written to `write` or `error` ports is output to console as a character, but if we first write the number of characters to be written to `outlen`, the value written to `write` or `error` ports is treated as an address, and `outlen` characters from that address are written to the console. Much more efficient in time and code than writing. one. character. at. a. t.i.m.e.
I've also found myself forgetting to put a space between $20 or 10 et. al and the following `,` to write those values to memory, which results in weird error messages when saved to the operand stack as an unknown labelref in that case. In the snippet above, you'll notice that I updated the bootstrap assembler to accept any valid number syntax followed by a `,` (sans spacing) to save me from myself.
Work on the bootstrap assembler speeded up considerably once I added a series of tests to ensure all the supported syntax was being assembled correctly.
I'm sure there'll be more improvements to the assembler as I progress, but I'm now concentrating on a somewhat comprehensive ISA Test program to help me flush out bugs in the emulator by checking that each operation behaves as expected at runtime... ramping up from some very basic register and memory manipulations with `mov,` and progress reporting with characterwise`out,` to a little test harness for testing each operation.
$ lua v3asm.lua tests/execute.vas tests/execute.v3 assembled 165 cells, with 26 labels $ ./v3 tests/execute.v3 Ok Ok Ok anonymous string... Ok lambda... Ok cmp,... Ok
More to come!