Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
A static c++ brainfuck compiler using c++0x features in 200 nearly readable lines.
C++
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
Makefile
README.md
bf0x.hpp
main.cpp

README.md

bf0x

A static brainfuck compiler in c++0x.

Code is fed to the compiler using a big ugly variadic template.

auto multiply = bf0x::interpreter<bf0x::bstack<bf0x::interpreter>,
     ',','>',',','>','+','+','+','+','+','+','+','+','[','<','-','-',
     '-','-','-','-','<','-','-','-','-','-','-','>','>','-',']','<',
     '<','[','>','[','>','+','>','+','<','<','-',']','>','>','[',
     '<','<','+','>','>','-',']','<','<','<','-',']','>','>','>',
     '+','+','+','+','+','+','[','<','+','+','+','+',
     '+','+','+','+','>','-',']',',','<','.','>','.'>();

bf0x::state st;
multiply.exec(st);

A bunch of variadic templates consume the string char by char, using pattern matching (partial specialization on the first char) and build a big recursive function exec(state& st) which is then inlined and optimized by the c++0x compiler.

Thanks to the c++0x compiler, mix of +, -, < and > are simplified. For example, the code ">++++++++[<------<------>>-]" is assembled into something equivalent to :

data[0] = 8;
while (data[0] != 0) {
    data[1] -= 6;
    data[2] -= 6;
    data[0] --;
}
Something went wrong with that request. Please try again.