Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

bfc

A closure-based Brainfuck interpreter in C and C++.

About

Instead of the typical switch-statement interpreter loop, this compiles Brainfuck programs into a sequence of closures (function pointers) that can be executed directly.

Inspired by this PlanetScale post on interpreter performance and skx/closure-based-brainfuck-vm.

Why closures?

Most Brainfuck interpreters read each character and dispatch via a switch.

Building

make
# or directly:
gcc -O2 -o bf bf.c
g++ -O2 -o bf++ bf.cpp

Usage

./bf program.bf

Files

  • bf.c — C implementation
  • bf.cpp — C++ implementation
  • Makefile — Build script

Brainfuck reference

Command Description
> Move pointer right
< Move pointer left
+ Increment current cell
- Decrement current cell
. Output current cell as ASCII
, Read one byte of input
[ Jump past matching ] if cell is zero
] Jump back to matching [ if cell is non-zero

About

A closure-based BrainFuck intepreter

Resources

Stars

0 stars

Watchers

0 watching

Forks

Contributors

Languages