Struct Machine

Source
pub struct Machine<'a, Constant, Value: Debug> {
    pub code: &'a Code<Constant>,
    pub globals: HashMap<String, Value>,
    /* private fields */
}
Expand description

The entire state of the VM

State contains the code that the VM is executing and a hashmap of all global variables.

Fields§

§code: &'a Code<Constant>§globals: HashMap<String, Value>

Implementations§

Source§

impl<'a, Constant, Value: Debug> Machine<'a, Constant, Value>

Source

pub fn new( code: &'a Code<Constant>, instruction_table: InstructionTable<'a, Constant, Value>, ) -> Machine<'a, Constant, Value>

Source

pub fn start(&mut self) -> bool

Source

pub fn push_operand(&mut self, operand: Value)

Source

pub fn peek_operand(&mut self) -> Result<&Value, EmptyOperandStack>

Source

pub fn pop_operand(&mut self) -> Result<Value, EmptyOperandStack>

Source

pub fn pop_two_operands(&mut self) -> Result<(Value, Value), Exception>

Source

pub fn get_operand(&self, slot: usize) -> Result<&Value, SlotOutOfBounds>

Source

pub fn get_operand_from_top( &self, slot_from_top: usize, ) -> Result<&Value, SlotOutOfBounds>

Source

pub fn set_operand( &mut self, slot: usize, value: Value, ) -> Result<(), SlotOutOfBounds>

Source

pub fn operand_stack_len(&self) -> usize

Source

pub fn peek_frame(&self) -> Result<&CallFrame, EmptyCallStack>

Source

pub fn push_frame(&mut self, chunk_id: usize, name: String, start_slot: usize)

Source

pub fn discard_frame(&mut self) -> Result<CallFrame, EmptyCallStack>

Source

pub fn instruction_pointer( &mut self, ) -> Result<&mut InstructionPointer, EmptyCallStack>

Trait Implementations§

Source§

impl<'a, Constant, Value: Debug> ByteReadable<InstructionPointer> for Machine<'a, Constant, Value>

Source§

fn read(&self, ptr: &mut InstructionPointer) -> Option<u8>

Source§

fn has_next(&self, ptr: &InstructionPointer) -> bool

Source§

fn read_n(&self, ptr: &mut Ptr, n: usize) -> Option<Vec<u8>>

Source§

fn read_u16(&self, ptr: &mut Ptr) -> Option<u16>

Source§

fn read_u32(&self, ptr: &mut Ptr) -> Option<u32>

Source§

fn read_i32(&self, ptr: &mut Ptr) -> Option<i32>

Auto Trait Implementations§

§

impl<'a, Constant, Value> Freeze for Machine<'a, Constant, Value>

§

impl<'a, Constant, Value> RefUnwindSafe for Machine<'a, Constant, Value>
where Value: RefUnwindSafe, Constant: RefUnwindSafe,

§

impl<'a, Constant, Value> Send for Machine<'a, Constant, Value>
where Value: Send, Constant: Sync,

§

impl<'a, Constant, Value> Sync for Machine<'a, Constant, Value>
where Value: Sync, Constant: Sync,

§

impl<'a, Constant, Value> Unpin for Machine<'a, Constant, Value>
where Value: Unpin,

§

impl<'a, Constant, Value> UnwindSafe for Machine<'a, Constant, Value>
where Value: UnwindSafe, Constant: RefUnwindSafe,

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.