#brainfuck #interpreter

bfi

Brainfuck for your machine learning needs

5 releases

0.2.2 Aug 24, 2017
0.2.1 Aug 24, 2017
0.2.0 Aug 24, 2017
0.1.1 Aug 24, 2017
0.1.0 Aug 23, 2017

#64 in Science

Download history 2/week @ 2018-05-04 6/week @ 2018-05-11 2/week @ 2018-05-18 10/week @ 2018-05-25 45/week @ 2018-06-01 1/week @ 2018-06-08 10/week @ 2018-06-15 6/week @ 2018-06-22 63/week @ 2018-06-29 10/week @ 2018-07-06 17/week @ 2018-07-20 10/week @ 2018-07-27

20 downloads per month

rust-bfi

Build Status

Simple and fast Brainfuck interpreter perfectly suited for machine learning needs.

Example

extern crate bfi;

use bfi::{BfMachine, b};

let code = b("+++[->,.<]");  // `b` converts an `&str` to a byte vector: `pub fn b(s: &str) -> Vec<u8>`
let input = b("jackdaws love my big sphinx of quartz");
let mut output = Vec::new();

let mut machine = BfMachine::new();
let res = machine.exec(&code, &input, &mut output);

assert_eq!(output, b("jackdaws"));
assert_eq!(res, Ok(code.len()));

Docs

Here they are.

Implementation details

  • The memory tape is infinitely long to the right.
  • Going to the left of the starting cell causes an Err(BfError::Memory).
  • Cells can hold values from 0 to 255.
  • Addition and subtraction over- and underflow silently.
  • End of input results in an early return.

Why another Brainfuck interpreter?

I like idea of Brainfuck as an environment for reinforcement learning. After searching crates, I haven't found anything decent for interpreting BF in runtime, so I wrote this little thing.

LGPL-3.0 license
  • No runtime deps

Reverse deps