Brainbork is a high-performance interpreter and Just-In-Time (JIT) compiler for a Brainf*ck-compatible derivative. Written in C, it features a clean, modular architecture that generates machine code on-the-fly for x86-64 and aarch64 (ARM64) systems. The entire VM state is encapsulated in a BfVm struct, eliminating global state and ensuring testability.
- Dual Execution Modes: Run code via a fast, portable interpreter
(-i)or the high-performance JIT compiler(-j). - Cross-Platform JIT: Automatically detects x86-64 or aarch64 (ARM64) hosts and generates optimized native code.
- Peephole Optimization: A pre-compilation pass collapses common patterns like
[-]and[+]into a single, efficient op_clear. - Extended Syntax: Lambda Closures: Implements first-class, nestable functions (()) with true closure support (capturing the data pointers).
The project requires only gcc (or clang) and make.
Clone the repository and run make:
git clone https://gripols/Brainbork.git
cd brainbork
make
This detects your host architecture (x86_64 or aarch64), builds the appropriate JIT backend, and creates the brainfork executable.
Execute any Brainf*ck or Brainbork file.
Usage:
./brainbork [options] <filename.bf>
Options:
-i: Interpreter Mode.
-j: JIT Mode (compiles to native assembly).
Example (examples/mandelbrot.bf):
./brainfork -j examples/mandelbrot.bf
./brainfork -i examples/mandelbrot.bf
Brainbork adds three operators for stack-based functions:
(: Define Lambda. Begins a function definition, capturing the current data pointer (p) as a closure.): End Lambda. Marks the end of the function body.!: Call Lambda. Calls the most recently defined lambda. This peeks at the lambda stack (allowing multiple calls), pushes the current state to the call stack, and jumps to the lambda's code with its captured pointer.
Licensed under MIT license.
All contributions are welcome.