CARDIAC › rust-cardiac › Message codes › RCI0001
RCI0001note
Bools that would be smaller as Flags.
note[RCI0001]: {which} tested {n} times; as cardiac::Flag (`false.into()`, `.get()`) each test is an instruction less: about {saved} cells or more
The program keeps bools in cells and tests them often enough that cardiac::Flag would make it smaller.
CARDIAC has one test, TAC: jump if the accumulator is negative. A bool is 0 or 1, as Rust promises, so testing one kept in a cell is three instructions: load it, take away 1, TAC. A cardiac::Flag holds -1 for false and 0 for true, so testing it is two. That is a cell and a step less a test, for one cell holding -1, which many programs have already.
A condition tested where it is worked out (if a < b) is never kept in a cell, and needs no Flag.
use cardiac::*;
let mut seen_zero: Flag = false.into();
loop {
let v = inp();
if v == 0 {
seen_zero = true.into();
}
if seen_zero.get() {
out(v);
}
}
In a terminal: cargo cardiac help RCI0001.