AxelUlmestig / brainfuck

2 stars 1 forks source link
brainfuck brainfuck-compiler compiler haskell interpreter

Brainfuck

Introduction

Brainfuck is a very small and confusing programming language. This Wikipedia article gives a pretty good summary of it.

This repository contains a Brainfuck compiler written in a very large and confusing programming language called Haskell.

Setup

In order to run it you must first install the Stack build tool.

Run the following command to build and install the brainfuck interpreter on your computer.

$ stack install

This will install a CLI tool called brainfuck.

Running brainfuck code

Now we can run a Hello World example of Brainfuck. First copy the program found here and save it in a file called hello.bf. Then run the interpreter with the file.

$ brainfuck run hello.bf

Which should result in the following output:

$ brainfuck run hello.bf
Hello World!

Compiling brainfuck code

The current version only supports compiling to Linux distributions with x86-64 architecture.

$ brainfuck compile hello.bf

will produce an executable called hello

$ ./hello
Hello World!

Optimizations

The brainfuck code goes through the following optimzation steps before it gets run/compiled.

Debugging

If you want to debug the executables (and you're a masochist) you can compile with the --debug flag and then use gdb to step through the assembly code in the executable.

$ brainfuck compile hello.bf --debug
$ gdb hello