Rename the two different 'CELL_SIZE's so they stop being confused

There were two unrelated things under one name:

  r8asm::ast::CELL_BITS   the machine word width in bits, a run time number
                          (import_file(path, 8)), used by %rep and the .xor
                          argument masking
  r8veritas<PARAMS>       how many parameter cells a synth block has, a
                          compile time template argument selected by 'params N'

The first is now CELL_BITS, the second PARAMS.  What a .r8asm program sees does
not change: _CELL_SIZE / _CELL_MAX / _ROL_STEP keep their names, because
lib.r8asm uses them.

Answering the actual question along the way: the machine word width is a run
time parameter (import_file's second argument, hardcoded to 8 by the CLI), not a
template argument -- the comment in r8asm.hh even apologises for that.  The
synth block's 'params N' is the other one, and only that goes through the
template switch (1..8).

The first attempt at the rename also rewrote the _CELL_SIZE string used by %rep
into _CELL_BITS, so the lookup threw and the assembler died with a fastfail on
any file containing .xor or %rep.  Caught by regressing test.r8asm (exit
0xC0000409, no tape); the string is restored and asm/test.r8asm is back to 1666
characters with all seven blocks cached.
This commit is contained in:
dsh committed 2026-11-06 20:14:49 +08:00
1 parent e18827580f
commit 7d259b1c6c
5 files changed
+63 -48

No files matched your search

+13 -11
View File
@@ -64,11 +64,13 @@ std::string peel(std::string &str) { // Peel the first word from string.
#undef EMPTY_CHARS
#undef OPERATORS
void r8asm::ast::set_cell_size(size_t cell_size) {
CELL_SIZE = cell_size;
scopes = {{{"_CELL_SIZE", static_cast<general_data>(cell_size)},
{"_CELL_MAX", static_cast<general_data>((1 << cell_size) - 1)},
{"_ROL_STEP", static_cast<general_data>(cell_size - 1)}}};
void r8asm::ast::set_cell_bits(size_t cell_bits) {
CELL_BITS = cell_bits;
// the names a .r8asm program sees stay as they were: _CELL_SIZE is the
// machine word width in bits (CELL_BITS on the C++ side)
scopes = {{{"_CELL_SIZE", static_cast<general_data>(cell_bits)},
{"_CELL_MAX", static_cast<general_data>((1 << cell_bits) - 1)},
{"_ROL_STEP", static_cast<general_data>(cell_bits - 1)}}};
}
r8asm::general_data r8asm::ast::expand_node_to_data(const ast_node &node) {
@@ -257,10 +259,10 @@ r8asm::ast_node r8asm::ast::expand_node_to_ins(const ast_node &node) {
/*
XOR
children[0]: argument
WARNING: argument bigger than ((1<<CELL_SIZE)-1) will be cut off
WARNING: argument bigger than ((1<<CELL_BITS)-1) will be cut off
e.g.
children[0] -> 5(0b101)
when define CELL_SIZE 2, only the last 2 bit will be noticed,
when define CELL_BITS 2, only the last 2 bit will be noticed,
and 5 means 0b01(1) here.
then the node will be expanded like this:
@@ -436,7 +438,7 @@ r8asm::ast_node r8asm::parse(const token_stream &stream) {
filename += tp->value;
// now tp points at RQUOTE
import_file(filename, main_tree.CELL_SIZE);
import_file(filename, main_tree.CELL_BITS);
// import_file has already said why if it failed; the error flag is
// set, so this file will not be reported as assembled.
} break;
@@ -550,7 +552,7 @@ r8asm::ast_node r8asm::parse(const token_stream &stream) {
}
file << "%endmacro\n";
file.close();
import_file(path, main_tree.CELL_SIZE);
import_file(path, main_tree.CELL_BITS);
std::remove(path.c_str());
}
} break;
@@ -855,10 +857,10 @@ bool r8asm::import_file(const std::string &filename, size_t cell_size) {
return (false);
}
// Before parsing: %include asks main_tree.CELL_SIZE for the width to hand
// Before parsing: %include asks main_tree.CELL_BITS for the width to hand
// to the included file, and that used to answer 0 because the size was
// only set at the end of this function.
main_tree.set_cell_size(cell_size);
main_tree.set_cell_bits(cell_size);
for (const auto &token_it : parse(stream).children) {
main_tree.root.children.push_back(token_it);