Crate bf[][src]

bf-rs is a optimizing Brainfuck interpreter and JIT compiler inspired by Eli Bendersky’s series on JIT compilation. It includes a library crate bf that exports most of the functionality, and an executable bfi that provides a command-line interface for executing Brainfuck programs.

This crate supports Rust version 1.20 and later. However, by default, installing bf does not enable the JIT compiler because that requires nightly Rust. To build and install from crates.io with the native x86-64 JIT enabled:

$ cargo +nightly install bf --features=jit

This library implements a number of compilation passes:

Interpreters are provided for the intermediate forms as well. In particular, all representations of Brainfuck programs implement the Interpretable trait.

Modules

ast

Parsing and interpretation for unoptimized Brainfuck abstract syntax trees.

bytecode

Brainfuck bytecode instead of an abstract syntax tree.

common

Definitions common to multiple passes.

jit

Just-in-time compiles Brainfuck AST to x64 machine code (--features jit, nightly only)

llvm

JIT compiler for Brainfuck based on LLVM.

peephole

The peephole optimizer, which replaces common loop forms with single (non-Brainfuck) instructions.

rle

Run-length encodes Brainfuck commands.

rts

Minimal run-time system, which does I/O.

state

The Brainfuck machine state.

test_helpers

Helper definitions for testing both inside and outside (e.g., benches) the crate.

traits

Contains the Interpretable trait, which provides a common interface for running a Brainfuck program.