SBrainVM

Struct SBrainVM 

Source
pub struct SBrainVM<'a> { /* private fields */ }
Expand description

A virtual machine modelling the SBrain Turing machine. This machine implements the specification relatively strictly, providing exactly 2^16 (65536) data and instruction cells. Thus, all pointers are 16 bits and all data is 8 bits. The main deviation from the minimum specification is the jump stack, which is indefinitely expandable.

Implementations§

Source§

impl<'a> SBrainVM<'a>

Source

pub fn new( input: Option<&'a mut dyn Read>, output: Option<&'a mut dyn Write>, program: &[u8], ) -> Result<SBrainVM<'a>, String>

Return a new SBrainVM, with no data in any tapes. If given a None input, all reads read 0. If given a None output, all writes are discarded.

Source

pub fn load_program(&mut self, program: &[u8]) -> Result<(), String>

Load a program tape: copy data from the given slice into the executable tape, starting at address zero. On error, the Err(s) return will contain a message describing the error.

Source

pub fn run(&mut self, cycles: Option<u32>) -> Result<(u32, Option<u8>)>

Run the machine, until completion (cycles = None) or for n cycles (cycles = Some(n)). Return values are number of cycles run and the return code, or None if the code simply ran out of cycles.

Auto Trait Implementations§

§

impl<'a> Freeze for SBrainVM<'a>

§

impl<'a> !RefUnwindSafe for SBrainVM<'a>

§

impl<'a> !Send for SBrainVM<'a>

§

impl<'a> !Sync for SBrainVM<'a>

§

impl<'a> Unpin for SBrainVM<'a>

§

impl<'a> !UnwindSafe for SBrainVM<'a>

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.