... If you're here and you're wondering what this is, it's a simple F# program that compiles brainfuck to .NET IL.
Some simple optimizations are also applied in the process, some of which are the same as in my old brainfuck interpreter in C, but this time the optimizations actually compose much better... and the optimization pass code is a lot easier to read because it's not written in C.
- Uses a 65536 * 4 cell space by default.
- Uses (unsigned) byte cells, wrapping on overflow.
Includes a special '#' instruction to dump the contents of all 65536 cells in a 16 column format, with a newline between each cell printed (as a number, not as a character).(TODO)- Can directly execute your program, or optionally builds it to a .NET assembly and writes it to file.
- Reads your program from an input string (the --input flag) or from file (with the --file flag).
- Accepts an unbounded input program size.
- Compiles the executed brainfuck to .NET IL, executing by invoking a method generated in the dynamic assembly.
- Optimizes a few common brainfuck patterns to more specific instructions before compiling to .NET IL, such as:
- >>>, ++++, etc.. optimizes continuous sequences of ptr mov/arithmetic into single operations
- [-] (which is equal to set current cell to zero) to a direct set to zero
- cleans up obviously no-op operations
See attached LICENSE file.