A small typed language, bytecode compiler, and virtual machine written in Rust.
- Typed AST and type checking
- Integer and floating-point arithmetic
if/elseconditionalsforloops with increment and decrement- Function calls and recursive functions
- Variadic formatted printing with
{}placeholders - Bytecode disassembly
- Type-error diagnostics
Run a sample from the repository root:
cargo run -- run crates/crust/samples/compiler/arithmetic.crustDisassemble a sample's bytecode:
cargo run -- disassemble crates/crust/samples/compiler/loop.crustBuild and run the optimized binary:
cargo build --release -p crust
target/release/crust.exe run crates/crust/samples/compiler/recursion.crustAll current samples are in crates/crust/samples/compiler:
| Sample | Demonstrates |
|---|---|
arithmetic.crust |
Arithmetic precedence, locals, formatted output |
conditionals.crust |
if / else and comparisons |
loop.crust |
for loops, local increments, formatted output |
recursion.crust |
Recursive factorial and function calls |
printing.crust |
Multiple formatted print arguments |
type_error.crust |
Intentional type-checking failure |
VHS source tapes are in demo/source. Rendered GIFs are in demo/output:
run.gifdisassemble.gifconditionals.gifloop.gifrecursion.gifprinting.giftype_error.gifbenchmark.gif
Regenerate one demo from the repository root:
vhs demo/source/recursion.tapeRegenerate all demos:
Get-ChildItem demo/source/*.tape | ForEach-Object { vhs $_.FullName }Validate tape syntax without rendering:
vhs validate "demo/source/*.tape"The tapes use bat -P to show source files and repository-root-relative paths, so they should be run from the repository root.