Archived
1
0
Fork
You've already forked brainhuck
0
My implementation of a brainfuck interpreter in Haskell. Abandoned repo. Moved to https://github.com/0rphee/brainhuck
This repository has been archived on 2024年10月07日. You can view files and clone it, but you cannot make any changes to its state, such as pushing and creating new issues, pull requests or comments.
  • HTML 92.4%
  • Haskell 4.9%
  • Brainfuck 2.7%
2023年04月08日 10:26:36 -06:00
app update types and remove redundant benchmarks 2023年03月01日 20:46:08 -06:00
bench update types and remove redundant benchmarks 2023年03月01日 20:46:08 -06:00
bf add 196 algorithm by Mats Linander 2023年01月25日 22:15:18 -06:00
img update readme according to changes 2023年03月01日 20:46:51 -06:00
src/Brainhuck add optimizations and adapt types to explicitly show what data structure will contain the instructions 2023年03月01日 20:45:06 -06:00
test stack new 2023年01月15日 20:27:49 -06:00
.gitignore Initial commit 2023年01月16日 02:14:51 +00:00
bench.html new benchmarking results 2023年03月01日 20:46:38 -06:00
brainhuck.cabal add deepseq dependency 2023年02月28日 20:08:56 -06:00
CHANGELOG.md remove old Interpreter 2023年01月19日 20:16:05 -06:00
LICENSE stack new 2023年01月15日 20:27:49 -06:00
package.yaml add deepseq dependency 2023年02月28日 20:08:56 -06:00
README.md update readme according to changes 2023年03月01日 20:46:51 -06:00
Setup.hs stack new 2023年01月15日 20:27:49 -06:00
stack.yaml Bump up lts for ghc-9.2.7 2023年04月08日 10:26:36 -06:00
stack.yaml.lock Bump up lts for ghc-9.2.7 2023年04月08日 10:26:36 -06:00

brainhuck

A Haskell implementation of a Brainfuck interpreter.

The interpeter is implemented as an executable (installed with stack install in the directory), which can take the path of Brainfuck source code, or using the --stdin flag, execute code given as an argument to the interpeter.

Usage examples:

brainhuck path/to/program.b
brainhuck --stdin ">>>>+"
brainhuck program.b -s 100 > debug.txt

Flags/Options:

-s --size # memory size (default: 500 cells)
--stdin # execute code given as an argument

I have yet to to document the source code at least to some extent, nevertheless I think it's fairly readable, though maybe not so idiomatic, since I'm still a Haskell beginner-intermediate.

There are two modules for the interpeter in this project. Their only difference is that one uses Boxed Vectors for the memory, and the other uses Unboxed Vectors. Its important to note, that there are two versions of the Unboxed version. One akin to the one with Boxed Vectors, and another that enables optimizations, by means of simplifying the actions (i.e. for "+++++", instead of performing one at a time, every adyacent '+' fuses into a single action). The difference in performance can be seen in the bench.html generated by criterion. Depending on the program, the optimizations will have varying impact on the final performance.

Image of the benchmarking results

It is important to note that the brainhuck executable uses the optimized version.

This interpreter allows for different datatypes to be used as the memory used, only requiring for each datatype a couple of typeclasses, and few more code.