
An Optimising BF Compiler - jsnell
http://www.wilfred.me.uk/blog/2015/08/29/an-optimising-bf-compiler/
======
azeirah
Awesome! Inspired by a flash of lightning, I wrote a genetic algorithm to
generate brainfuck over the past two weeks.

It has gotten so far that it generates brainfuck programs that output any
number you desire. No input processing though ;(

Here are five different (20-char) brainfuck programs that print 1337.. Note my
brainfuck interpreter doesn't output characters, it adds the byte at the
current pointer to the output. I suppose that's not _real_ brainfuck...

    
    
        -.[.>++<+.>]-.><+.[+
        ++->]-.[+.-.-<++]-->
        -[...<[+].++>-.>+]<+
        [+++...+.[-[.->.[]][
        >->-[..<.->-.<<.+.]+
    

Now I want to either rewrite it in c (it's currently in js) for the
performance increase alone. I might attempt writing an interpreter on my
fpga...

~~~
vanderZwan
Have you seen this work?

[http://www.primaryobjects.com/CMS/Article163](http://www.primaryobjects.com/CMS/Article163)

~~~
azeirah
Yep, I have. Pretty cool stuff

------
bdash
Neat! One of the projects that I wrote when learning Rust was a BrainFuck
interpreter and JIT for x86_64[1]. Interestingly, my JIT appears to be run
some programs (e.g., mandelbrot.bf[2]) significantly faster than the versions
compiled by bfc. That's despite including the optimization and code generation
overhead in the timings of my JIT, but excluding them from bfc.

[1]: [https://github.com/bdash/brainrust](https://github.com/bdash/brainrust)
[2]:
[https://github.com/bdash/brainrust/blob/master/examples/mand...](https://github.com/bdash/brainrust/blob/master/examples/mandelbrot.bf)

