| Crates.io | brainstem |
| lib.rs | brainstem |
| version | 0.1.0 |
| created_at | 2025-06-17 19:57:54.304538+00 |
| updated_at | 2025-06-17 19:57:54.304538+00 |
| description | A Brainfuck compiler and interpreter library, with a BrainStem frontend language. |
| homepage | https://github.com/hmeyer/brainstem |
| repository | https://github.com/hmeyer/brainstem |
| max_upload_size | |
| id | 1716193 |
| size | 118,531 |
A compiler and interpreter for Brainfuck, written in Rust.
BrainStem is a compilation system:
BrainStem (low-level language) → Brainfuck → (optional Brainfuck runtime)
BrainStem is a low level language and compiler. It supports variables, arithmetic and boolean expressions, conditionals, loops, stackframe handling and linear memory access. BrainStem gets compiled to Brainfuck.
var x = 42; // Declare a variable
var arr[] = [1,2,3]; // Declare an array
var str[] = "abc"; // String arrays
var sum = a + b;
var product = x * y;
var quotient = n / m;
var remainder = n % m;
if x > 0 then {
putc("+");
} else {
putc("-");
}
while condition {
// body
}
// Push a stack frame with modified variables
PushStackFrame(x=x+1);
// Do something in the new context
PopStackFrame();
var x = 5;
putc("0" + x); # Will print 5
cargo build --release
cargo run -- --input program.bs --run
cargo run -- --input program.bs --output program.bf
cargo run -- --input program.bs --run --int-type i32
# Run the hello world example
cargo run -- --input examples/hello_world.bs --run
# Run factorial example with larger integer type
cargo run -- --input examples/factorial.bs --run --int-type i32
In the examples directory you'll find several BrainStem programs that demonstrate the language features:
These examples also serve as end-to-end tests for the compiler and runtime.
This project is licensed under the MIT License - see the LICENSE file for details.