Trait cpr_bf::BrainfuckVM

source ·
pub trait BrainfuckVM {
    // Required methods
    fn run_program(&mut self, program: &Program) -> BfResult;
    fn reset_memory(&mut self);

    // Provided methods
    fn run_string(&mut self, bf_str: &str) -> BfResult { ... }
    fn run_file(&mut self, file: &mut File) -> BfResult { ... }
    fn run_from_path(&mut self, path: &Path) -> BfResult { ... }
}
Expand description

This trait represents an object that is able to run Brainfuck programs, either from a string of Brainfuck source code or by reading a Brainfuck source file

A default implementation can be constructed using VMBuilder

Required Methods§

source

fn run_program(&mut self, program: &Program) -> BfResult

Runs the given Brainfuck program on this VM. After the program has been run, the memory of the VM is not automatically reset back to zero. (see BrainfuckVM::reset_memory)

Note that the VM might not be new, so the VM must take care of resetting the data pointer back to zero before running the program

source

fn reset_memory(&mut self)

Resets all currently allocated memory cells back to their default value, as if no program has been run on the VM before. This does not free any cells that were allocated during the execution of any previous Brainfuck programs.

Provided Methods§

source

fn run_string(&mut self, bf_str: &str) -> BfResult

Compiles and runs the given string of Brainfuck source code. See BrainfuckVM::run_program

source

fn run_file(&mut self, file: &mut File) -> BfResult

Reads the given file into a string, and runs the string on this VM.

See BrainfuckVM::run_string

source

fn run_from_path(&mut self, path: &Path) -> BfResult

Opens the file pointed to by the given path, and attempts to run its contents on this VM.

See BrainfuckVM::run_file

Implementors§