3 ms·
I while ago I wrote a simple Brainfuck interpreter, JIT and compiler (https://github.com/brianquinlan/brainfuck-jit https://github.com/brianquinlan/brainfuck-ji
by bquinlan 12y ago
I while ago I wrote a simple Brainfuck interpreter, JIT and compiler (https://github.com/brianquinlan/brainfuck-jit https://github.com/brianquinlan/brainfuck-jit).
The compiler implements the "Operation offsets" optimization as described in the article. It is actually pretty straightforward. This function converts a map of offset => delta to x86-64 instructions:
https://github.com/brianquinlan/brainfuck-jit/blob/master/bf_compile_and_go.cpp#L175 https://github.com/brianquinlan/brainfuck-jit/blob/master/bf...
and the function following it generates that table.
- icefox 12y agoA silly Brainfuck interpreter I wrote one evening converts BF to JavaScript and runs eval() on it. The result was that I got for free all of the compiler optimizations and JIT capabilities in the Javascript engines for a trivial amount of effort. I found the resulting execution faster than the various hand rolled C interpreters I found online. The best part was that I spent probably less than an hour implementing and testing my "interpreter".