Struct Interpreter

Source
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>

Source

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.

Source

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

Load a program for the interpreter to run.

Source

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

Use the given reader for the Input instruction.

Source

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

Use the given writer for the Output instruction.

Source

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

Run the interpreter.

Source

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.

Trait Implementations§

Source§

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

Source§

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

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<'a, T> Freeze for Interpreter<'a, T>

§

impl<'a, T> !RefUnwindSafe for Interpreter<'a, T>

§

impl<'a, T> !Send for Interpreter<'a, T>

§

impl<'a, T> !Sync for Interpreter<'a, T>

§

impl<'a, T> Unpin for Interpreter<'a, T>

§

impl<'a, T> !UnwindSafe for Interpreter<'a, T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.