Struct brainfuck::Interpreter [] [src]

pub struct Interpreter<'a, T: Tape> {
    // some fields omitted
}

A brainfuck interpreter, with the needed state for execution.

For more information about the brainfuck language in general see the top level documentation for this crate. This implmentation of a brainfuck interpreter allows for optional programs, readers, and writers. Each of which can be set dynamically with the load, read_from, and write_to methods. The interpreter is also in charge of managing the program counter, which is 0 by default.

Each interpreter stores a tape for the execution of the program. The current tape uses a dynamically allocated array of TAPE_LENGTH elements.

Other fields used for instrumentation may also be stored in the interpreter.

Methods

impl<'a, T: Tape + Default> Interpreter<'a, T>

fn new<R: Read, W: Write>(program: Program, reader: &'a mut R, writer: &'a mut W) -> Interpreter<'a, T>

Create a new interpreter with the given program, optional reader, and writer.

fn load(&mut self, program: Program) -> &mut Self

Load a program for the interpreter to run.

fn read_from<R: Read>(&mut self, reader: &'a mut R) -> &mut Self

Use the given reader for the Input instruction.

fn write_to<W: Write>(&mut self, writer: &'a mut W) -> &mut Self

Use the given writer for the Output instruction.

fn run(&mut self) -> Result<(), Error>

Run the interpreter.

fn run_with_callback<F>(&mut self, hook: F) -> Result<(), Error> where F: FnMut(&mut Self, &Instruction)

Run the interpreter with a callback hook.

Trait Implementations

Derived Implementations

impl<'a, T: Default + Tape> Default for Interpreter<'a, T>

fn default() -> Interpreter<'a, T>