Struct VM

Source
pub struct VM {
    pub operand_stack: Stack<Rc<Value>>,
    /* private fields */
}

Fields§

§operand_stack: Stack<Rc<Value>>

Implementations§

Source§

impl VM

Source

pub fn new(tokens: VecDeque<Token>) -> Result<VM, Error>

Constructs a new VM with the specified tokens. The tokens are usually generated through the lexer. Internally, the tokens are converted to different values by the code object.

§Arguments

tokens - The tokens produced by the lexer.

Source

pub fn repl() -> Result<VM, Error>

Creates a VM in REPL mode.

Source

pub fn load_tokens(&mut self, tokens: VecDeque<Token>) -> Result<(), Error>

Loads the given tokens into the VM. This function does not change the operand stack or the call stack. This function can be used with the REPL mode to help facilitate a proper REPL experience.

§Arguments

tokens - The tokens to load.

Source

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

Runs the VM until the end of the code. This function may return an optionally value, representing the value of the last expression. It may also prematurely return an error. This may be updated to return a vector of errors.

Trait Implementations§

Source§

impl Debug for VM

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for VM

§

impl !RefUnwindSafe for VM

§

impl !Send for VM

§

impl !Sync for VM

§

impl Unpin for VM

§

impl !UnwindSafe for VM

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.