Truffle BF

October 19, 2016 · View on GitHub

A Brainfuck (short BF) implementation using Truffle for the GraalVM.

BF is a famous esoteric language invented by the Swiss Urban Müller in 1993, in an attempt to make a language for which he could write the smallest possible compiler for the Amiga OS, version 2.0. Instead of beeing as small as possible, this implementations aims to be as fast as possible by leveraging dynamic speculation with Truffle and Graal.

This repository is licensed under the permissive UPL licence. Feel free to fork an extend it.

BF Short Reference

Brainfuck operates on an array of memory cells, also referred to as the tape, each initially set to zero. There is a pointer, initially pointing to the first memory cell. The commands are:

CommandDescription
>Move the pointer to the right
<Move the pointer to the left
+Increment the memory cell under the pointer
-Decrement the memory cell under the pointer
.Output the character signified by the cell at the pointer
,Input a character and store it in the cell at the pointer
[Jump past the matching ] if the cell under the pointer is 0
]Jump back to the matching [ if the cell under the pointer is nonzero

All characters other than ><+-.,[] should be considered comments and ignored.

For more information see the reference on Esolangs.

Prerequisites

  • JDK 8
  • maven3

Installation

IDE Setup

Netbeans

  • Tested with Netbeans 8.2
  • Open Netbeans
  • File -> Open Project -> Select bf folder -> Open Project

Eclipse

  • Tested with Eclipse Mars SR2
  • Open Eclipse with a new workspace
  • Install m2e and m2e-apt plugins from the Eclipse marketplace (Help -> Eclipse Marketplace...)
  • File -> Import... -> Existing Maven Projects -> Select bf folder -> Finish

IntelliJ IDEA

  • Tested with IntelliJ 2016.1.3 Community Edition
  • Open IntelliJ IDEA
  • File -> New -> Project from existing Sources -> Select bf folder -> Click next and keep everything default on several screens -> Finish

Running

  • Execute ./bf hello.bf to run a simple language source file.

IGV

Debugging

  • Execute ./bf -debug tests/HelloWorld.sl.
  • Attach a Java remote debugger (like Eclipse) on port 8000.

Tested Compatibility

Truffle BF is compatible to:

  • Truffle-Version: 0.18
  • GraalVM-Version: 0.17

Further information

License

The Truffle framework is licensed under the GPL 2 with Classpath exception. Truffle BF is licensed under the Universal Permissive License (UPL).