Expand description
Rust on CARDIAC.
A program uses this crate for CARDIAC’s card reader and teletype, inp() and out(), and for a few built-ins
that CARDIAC does its own way. The same program builds two ways:
cargo runbuilds it for your machine.inp()reads numbers from standard input, andout()prints them.cargo cardiac runbuilds it for CARDIAC with the rust-cardiac compiler and runs it on heartburn’sburn.inp()is the instruction INP, andout()is OUT.
use cardiac::*;
fn main() {
let n = inp();
for i in (0..=n).rev() {
out(i);
}
}Given 5, both builds print 5 down to 0.
A CARDIAC cell holds a sign and three digits, so every value is from -999 to 999. A program whose values stay in that range prints the same numbers both ways. With overflow checks on, arithmetic that leaves the range panics on CARDIAC. With them off, a cell keeps the last three digits.
To build for CARDIAC, install the cargo subcommands with cargo install cargo-cardiac, then
cargo cardiac new countdown makes a package like the one above.
The rest is at lab.strangequery.com/rust-cardiac: getting started, what Rust works on CARDIAC, the compiler’s messages, and the tools for running and debugging a program.
Each function’s documentation says what it is on CARDIAC, what it costs there and what it does with cargo run.
Structs§
- Flag
- A
boolfor a flag kept in a cell and tested more than once: the same trues and falses, and on CARDIAC one instruction less per test.
Functions§
- add_
times n * c, ascadded upntimes.nis from 0 to 99, and the product must be from -999 to 999.- assume⚠
- Tells the compiler something about a value that it can’t see for itself, such as a month always being from 1 to 12, so it can leave out checks it would otherwise need.
- digit
- Digit
kof a value 0..=999:k= 0 is the hundreds, 1 the tens, 2 the units. - inp
- Reads the next card.
- load_
resource - An array of
Nvalues from the fileresources/NAME, beside the package’sCargo.toml. - out
- Outputs a value.
- overlay
- Ends a phase of a program too big for CARDIAC’s memory.
- skip_
cards - Reads
ncards and drops them, asfor _ in 0..n { inp(); }does.nis from 0 to 999.