bf2fj — Brainfuck to FlipJump¶
A direct Brainfuck-to-FlipJump compiler with four optimisation passes. Smaller and faster than running Brainfuck on top of an interpreter implemented in FlipJump.
Install¶
pip install bf2fj
Run¶
bf2fj hello_world.bf # generate hello_world.fj
bf2fj hello_world.bf -r # generate AND immediately run
-r (run) shells out to the local fj interpreter — make sure the main FlipJump toolchain is installed too.
Optimisations¶
The compiler applies four passes to the Brainfuck source before code generation:
Consolidate consecutive data ops —
+++++becomes a single “add 5” macro call instead of five separate+operations.Consolidate pointer movements —
>>>>becomes “shift right by 4” instead of four separate>s.Replace zeroing loops — the
[-]idiom (loop subtracting 1 until zero) is detected and replaced with a direct “set to 0” operation.Combine zero+modify —
[-]+++(zero, then add 3) becomes a single “set to 3” operation.
The cumulative effect is large. On the BF test corpus shipped with the repo, total operation counts drop ~88% — one program went from 2,900,990 ops (naïve translation) to 337,484 ops (with all four passes).
Useful flags¶
Flag |
Purpose |
|---|---|
|
Reserve |
|
Compile then immediately run via the local |
Caveats¶
Output is a single
.fjfile matching the input’s base name.The compiler doesn’t currently expose hooks for custom cell sizes or signed-cell semantics beyond the BF spec defaults.
See also¶
The FlipJump IDE — paste the generated
.fjand step through it.Standard Library —
bit/memory.fj— the tape-cell representation bf2fj uses under the hood.