bfcore

Struct Interpreter

Source
pub struct Interpreter<'a, I, O>
where I: Input, O: Output,
{ /* private fields */ }
Expand description

The struct containing the data for interpretting brainfuck code

Implementations§

Source§

impl<'a, I, O> Interpreter<'a, I, O>
where I: Input, O: Output,

Source

pub fn new(program: &str, input: &'a mut I, output: &'a mut O) -> Self

Create a new interpreter from a program, an input object, and an output object

Examples found in repository?
examples/minimal.rs (lines 11-15)
10
11
12
13
14
15
16
fn main() {
    Interpreter::new(
        "+[----->+++<]>+.---.+++++++..+++.[--->+<]>-----.--[->++++<]>-.--------.+++.------.--------.-[--->+<]>.",
        &mut In::default(),
        &mut Out::default()
    ).run();
}
More examples
Hide additional examples
examples/print.rs (lines 25-29)
24
25
26
27
28
29
30
fn main() {
    Interpreter::new(
        "+[------->++<]>++.++.---------.+++++.++++++.[---->+<]>+++.+[->+++<]>++.[--->+<]>+.--[->+++<]>-.++++++++++++.+++.----.-------.--[--->+<]>...",
        &mut In::default(),
        &mut Out::default()
    ).run();
}
examples/hello_world.rs (lines 43-47)
40
41
42
43
44
45
46
47
48
fn main() {
    // Create an interpreter with a program that prints hello world
    // Give it instances of our input and output structs
    Interpreter::new(
        r#"+[----->+++<]>+.---.+++++++..+++.[--->+<]>-----.--[->++++<]>-.--------.+++.------.--------.-[--->+<]>."#,
        &mut MyInput::default(),
        &mut MyOutput::default()
    ).run(); // Run the interpreter
}
Source

pub fn run(&mut self)

Execute the program. This can be done over and over again, the interpreter is reset each time. HOWEVER: State kept within your input and output objects CANNOT be reset!!! This only resets the interpreter’s internal state before execution!!!!

Examples found in repository?
examples/minimal.rs (line 15)
10
11
12
13
14
15
16
fn main() {
    Interpreter::new(
        "+[----->+++<]>+.---.+++++++..+++.[--->+<]>-----.--[->++++<]>-.--------.+++.------.--------.-[--->+<]>.",
        &mut In::default(),
        &mut Out::default()
    ).run();
}
More examples
Hide additional examples
examples/print.rs (line 29)
24
25
26
27
28
29
30
fn main() {
    Interpreter::new(
        "+[------->++<]>++.++.---------.+++++.++++++.[---->+<]>+++.+[->+++<]>++.[--->+<]>+.--[->+++<]>-.++++++++++++.+++.----.-------.--[--->+<]>...",
        &mut In::default(),
        &mut Out::default()
    ).run();
}
examples/hello_world.rs (line 47)
40
41
42
43
44
45
46
47
48
fn main() {
    // Create an interpreter with a program that prints hello world
    // Give it instances of our input and output structs
    Interpreter::new(
        r#"+[----->+++<]>+.---.+++++++..+++.[--->+<]>-----.--[->++++<]>-.--------.+++.------.--------.-[--->+<]>."#,
        &mut MyInput::default(),
        &mut MyOutput::default()
    ).run(); // Run the interpreter
}

Auto Trait Implementations§

§

impl<'a, I, O> Freeze for Interpreter<'a, I, O>

§

impl<'a, I, O> RefUnwindSafe for Interpreter<'a, I, O>

§

impl<'a, I, O> Send for Interpreter<'a, I, O>
where I: Send, O: Send,

§

impl<'a, I, O> Sync for Interpreter<'a, I, O>
where I: Sync, O: Sync,

§

impl<'a, I, O> Unpin for Interpreter<'a, I, O>

§

impl<'a, I, O> !UnwindSafe for Interpreter<'a, I, O>

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.