Vm

Struct Vm 

Source
pub struct Vm<'vm> { /* private fields */ }
Expand description

Stack-based virtual machine for executing bytecode programs.

The VM evaluates programs by executing bytecode instructions on a stack, performing arithmetic operations and function calls.

§Error Handling

Behavior varies based on the numeric backend:

  • f64 mode: Relaxed error handling. Only catches errors that would cause panics. Allows Inf and NaN results from operations like 1/0 or sqrt(-1).

  • Decimal mode: Strict error handling. All arithmetic operations are checked for overflow/underflow. Returns errors for domain violations.

Implementations§

Source§

impl<'vm> Vm<'vm>

Source

pub fn run( bytecode: &'vm [Instr], symtable: &'vm mut SymTable, ) -> Result<Number, VmError>

Executes bytecode and returns the result.

§Errors

Returns VmError if execution fails due to:

  • Stack underflow
  • Division by zero
  • Invalid operations (e.g., factorial of non-integer)
  • Function errors
  • Invalid symbol indices
  • Invalid jumps

Trait Implementations§

Source§

impl<'vm> Debug for Vm<'vm>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'vm> Freeze for Vm<'vm>

§

impl<'vm> RefUnwindSafe for Vm<'vm>

§

impl<'vm> Send for Vm<'vm>

§

impl<'vm> Sync for Vm<'vm>

§

impl<'vm> Unpin for Vm<'vm>

§

impl<'vm> !UnwindSafe for Vm<'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.