pub struct BrainfuckReader { /* private fields */ }Expand description
A simple Brainfuck interpreter.
The interpreter maintains:
- the program codes as a
String, - a customizable capacity memory tape initialized to zeros (30,000 cells by default),
- a data pointer indexing into that tape.
Implementations§
Source§impl BrainfuckReader
impl BrainfuckReader
Sourcepub fn new(code: String) -> Self
pub fn new(code: String) -> Self
Create a new interpreter from Brainfuck code.
The memory tape is initialized to 30,000 zeroed cells.
Sourcepub fn new_with_memory(code: String, memory_size: usize) -> Self
pub fn new_with_memory(code: String, memory_size: usize) -> Self
Create a new interpreter from Brainfuck code but with a custom memory size.
Sourcepub fn set_output_sink<F>(&mut self, sink: F)
pub fn set_output_sink<F>(&mut self, sink: F)
Provide an output sink. When set, ‘.’ sends bytes to this sink instead of stdout. The sink receives a slice of bytes; for Brainfuck, it will be a single-byte slice per ‘.’.
Sourcepub fn set_input_provider<F>(&mut self, provider: F)
pub fn set_input_provider<F>(&mut self, provider: F)
Provide an input provider. When set, ‘,’ reads from this provider instead of stdin. Returning None indicates EOF (cell is set to 0).
Sourcepub fn set_tape_observer<F>(&mut self, window_size: usize, observer: F)
pub fn set_tape_observer<F>(&mut self, window_size: usize, observer: F)
Provide a tape observer and desired window size.
Sourcepub fn run(&mut self) -> Result<(), BrainfuckReaderError>
pub fn run(&mut self) -> Result<(), BrainfuckReaderError>
Execute the Brainfuck program until completion.
Returns Ok(()) on success or a BrainfuckReaderError on failure.
Sourcepub fn run_debug(&mut self) -> Result<(), BrainfuckReaderError>
pub fn run_debug(&mut self) -> Result<(), BrainfuckReaderError>
Debug-run the Brainfuck program, printing a step-by-step table of operations instead of producing I/O side effects. The interpreter state (pointer, memory) advances exactly as it would during a real run, but:
- ‘.’ does not print the character; we log the action instead
- ‘,’ does not read from stdin; we simulate EOF and set the cell to 0 and log
Sourcepub fn run_with_control(
&mut self,
step_control: StepControl,
) -> Result<(), BrainfuckReaderError>
pub fn run_with_control( &mut self, step_control: StepControl, ) -> Result<(), BrainfuckReaderError>
Execute with cooperative cancellation and optional step limit.
Sourcepub fn run_debug_with_control(
&mut self,
step_control: StepControl,
) -> Result<(), BrainfuckReaderError>
pub fn run_debug_with_control( &mut self, step_control: StepControl, ) -> Result<(), BrainfuckReaderError>
Debug-run with cooperative cancellation and optional step limit.
Auto Trait Implementations§
impl Freeze for BrainfuckReader
impl !RefUnwindSafe for BrainfuckReader
impl Send for BrainfuckReader
impl Sync for BrainfuckReader
impl Unpin for BrainfuckReader
impl !UnwindSafe for BrainfuckReader
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more