.endloop expanded to >-+]< : flb clears the LSB and rnz then tests that
very same bit, so it always sees 0 and the body ran exactly once no
matter how many 1s the counter cell held. Measured: a counter of 0b111
came out as 0b110 after a single pass.
Putting a ror after the flb pulls the next bit down before the test,
which is what SPEC describes -- consecutive 1s from the LSB, one per
iteration. Measured:
0b0000_0111 -> 3 passes, counter 0
0b1111_1111 -> 8 passes, counter 0 (a bare ror would spin forever)
Nothing under asm/ uses .loop, so no existing tape changes.
A typo used to end in one of three ways: std::out_of_range aborting the
process (unknown macro, unknown directive), a silent 0 (unknown name used
as an address, which quietly mis-assembles), or a silent empty tape (a
file or %include that could not be opened). All four now go through
ast::fail(), print a line on stderr, set the error flag and make the CLI
exit with 1. Names that are reported repeatedly are only printed once.
While here: import_file set the cell size *after* parsing, so the
%include handler read main_tree.CELL_SIZE before it had ever been set and
handed 0 to included files. It worked by accident because the top-level
call ran again at the end. Moved it before the parse.
r8asm_test.cc came from the working tree (argv instead of a hard-coded
path); it now also checks the arguments and the error flag.
set(CMAKE_CXX_FLAGS ...) replaced the whole flag set. On MSVC that
dropped /EHsc, which this code needs (std::map::at, std::stoi throw), and
it applied -O3 to every configuration -- a Debug build then passes /RTC1
and MSVC refuses to combine that with an optimisation level (D8016).
CMake's Release configuration already passes -O3 / /O2 and defines
NDEBUG, so the block is gone. The only flag worth keeping is
-march=native, and only for a Release build of a non-MSVC compiler.
Also cast the cell-size constants so the size_t -> int32_t narrowing
warnings go away.
The counter is _CELL_MAX ones and one bit is eaten per round, so the loop runs _CELL_SIZE times on any width, and the address layout is built from a named UNIT instead of scattered 2s. Verified against ROT-8: 1 1 2 3 5 8 13 21 34 55.