Nice, but I should note that JITing does not improve performance greatly. Many basic arithmetic operations take O(n) or O(n^2) time, and as you cannot access arbitrary cells in the arbitrary order so most memory access operations also take at least O(n) time. There are handful optimizers that can optimize them provided that the program uses only a fixed amount of cells, but AFAIK there are <i>no</i> such optimizers in general.<p>If you plan to implement an optimization, I recommend a pointer propagation. This is very simple and still lots of optimizers ignore it. For example,<p><pre><code> mem += 3;
while (mem[0]) { mem += 1; mem[0] -= 1; mem += 1; }
mem -= 4;
mem[0] = 0;
</code></pre>
becomes:<p><pre><code> while (mem[3]) { mem[1] -= 1; mem += 2; }
mem[-1] = 0;
mem -= 1; /* you can safely ignore this at the end of file */
</code></pre>
where every relative memory access has been adjusted. Since it only affects the relative memory access, it is safe to apply the optimization to unbalanced loops as long as you keep the stride (a net pointer adjustment) at the end of the loop body.
This reminds me of Awib ( <a href="http://awib.googlecode.com/svn/builds/awib-0.3.b" rel="nofollow">http://awib.googlecode.com/svn/builds/awib-0.3.b</a> ), an optimizing brainfuck compiler written in brainfuck that can produce Linux executables (for i386), Tcl, Ruby, Go or C.
I have did that with AsmJit 4 years ago: <a href="https://github.com/miaout17/justfuck/blob/master/src/JustFuck/main.cpp" rel="nofollow">https://github.com/miaout17/justfuck/blob/master/src/JustFuc...</a><p>Shame on me for using Visual Studio. I turned to pure Linux/Mac development environments in recent years.
Writing a Brainfuck interpreter is a superb optimization exercise. Basic version is trivial to write, and in 2-3 iterations it's possible to get speed ups of 100x or more. If you haven't tried it, I would highly recommended it as a brain stretcher.<p>Then try and see if it's faster than this one - <a href="http://mazonka.com/brainf/bff4.c" rel="nofollow">http://mazonka.com/brainf/bff4.c</a>
The main LLVM codebase includes a BF compiler as an example: <a href="https://llvm.org/svn/llvm-project/llvm/trunk/examples/BrainF/" rel="nofollow">https://llvm.org/svn/llvm-project/llvm/trunk/examples/BrainF...</a><p>See BrainF.cpp in particular.<p>It's a decent first illustration of the great level of abstraction LLVM offers.