Closed Sword-Smith closed 11 months ago
PR #230 adds methods for checking growth and shrinkage of the op stack. Additionally, you will be able to write something like:
let sum_op_stack_size_influence = labelled_instructions
.iter()
.map(|instr| instr.op_stack_size_influence())
.sum::<i32>();
Let me know if the added methods grows_op_stack()
, changes_op_stack_size()
, shrinks_op_stack()
, and op_stack_size_influence()
are in your interest, or if there are any lacking or unintuitive ones.
Looks very reasonable to me. This solves my immediate problem and might even give me the ability to build in a really useful set of tests in the compiler, as I can now verify that the compiler's view of the stack matches the size that the instructions dictate.
In the building of the
tasm-lang
compiler it would be nice to have a method onLabelledInstruction
showing if the instruction grows the opstack by one. I guess it can't grow the opstack by 2, so maybe agrows_op_stack(&self) -> bool
function would suffice?Concretely it is for this, admittedly not so pretty, function that I could use this method. This function is trying to determine if a triplet of instructions are writing a memory-spilled value to memory.
instr_1
would in this function have to grow the stack with 1 for that to be the case.