~arcade/fucc

an optimizing brainfuck compiler in ocaml

refs

main
browse  log 

clone

read-only
https://git.sr.ht/~arcade/fucc
read/write
git@git.sr.ht:~arcade/fucc

You can also use your local clone with git send-email.

#fucc - an optimizing brainfuck parser

#Overview

I wanted to actually write a compiler, but I keep biting off more than I can chew, and this was a first step! It works in a pretty "traditional way":

  1. Tokenize into an IR
    • Notably, here I encode long runs of +, -, >, or < as just the operation plus the length
  2. Apply optimization transformations
    • Convert clears ([-]) to a dedicated operation
    • Convert left and right scans to dedicated operations
  3. C codegen
    • Simply run through the list of tokens, and add a pre- and post-amble

#Usage

  • Compile and install with dune install
  • Run with fucc <input.bf> <output.c>
  • Compile C code cc <output.c>
  • Run executable! ./a.out

NOTE:
All brainfuck code must be terminated with a bang (!)