pub struct Interpreter<'a, T: Tape> { /* private fields */ }Expand description
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.
Implementations§
Source§impl<'a, T: Tape + Default> Interpreter<'a, T>
impl<'a, T: Tape + Default> Interpreter<'a, T>
Sourcepub fn new<R: Read, W: Write>(
program: Program,
reader: &'a mut R,
writer: &'a mut W,
) -> Interpreter<'a, T>
pub 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.
Sourcepub fn load(&mut self, program: Program) -> &mut Self
pub fn load(&mut self, program: Program) -> &mut Self
Load a program for the interpreter to run.
Sourcepub fn read_from<R: Read>(&mut self, reader: &'a mut R) -> &mut Self
pub fn read_from<R: Read>(&mut self, reader: &'a mut R) -> &mut Self
Use the given reader for the Input instruction.
Sourcepub fn write_to<W: Write>(&mut self, writer: &'a mut W) -> &mut Self
pub fn write_to<W: Write>(&mut self, writer: &'a mut W) -> &mut Self
Use the given writer for the Output instruction.
Sourcepub fn run_with_callback<F>(&mut self, hook: F) -> Result<(), Error>where
F: FnMut(&mut Self, &Instruction),
pub fn run_with_callback<F>(&mut self, hook: F) -> Result<(), Error>where
F: FnMut(&mut Self, &Instruction),
Run the interpreter with a callback hook.