Skip to main content

VM

Struct VM 

Source
pub struct VM {
Show 24 fields pub irep: Rc<IREP>, pub id: usize, pub bytecode: Vec<u8>, pub current_irep: Rc<IREP>, pub pc: Cell<usize>, pub regs: [Option<Rc<RObject>>; 256], pub current_regs_offset: usize, pub current_callinfo: Option<Rc<CALLINFO>>, pub current_breadcrumb: Option<Rc<Breadcrumb>>, pub kargs: RefCell<Option<RHashMap<RSym, Rc<RObject>>>>, pub current_kargs: RefCell<Option<Rc<KArgs>>>, pub target_class: TargetContext, pub exception: Option<Rc<RException>>, pub flag_preemption: Cell<bool>, pub object_class: Rc<RClass>, pub builtin_class_table: RHashMap<&'static str, Rc<RClass>>, pub class_object_table: RHashMap<String, Rc<RObject>>, pub globals: RHashMap<String, Rc<RObject>>, pub consts: RHashMap<String, Rc<RObject>>, pub upper: Option<Rc<ENV>>, pub cur_env: RHashMap<usize, Rc<ENV>>, pub has_env_ref: RHashMap<usize, bool>, pub fn_table: RFnTable, pub fn_block_stack: RFnStack,
}

Fields§

§irep: Rc<IREP>§id: usize§bytecode: Vec<u8>§current_irep: Rc<IREP>§pc: Cell<usize>§regs: [Option<Rc<RObject>>; 256]§current_regs_offset: usize§current_callinfo: Option<Rc<CALLINFO>>§current_breadcrumb: Option<Rc<Breadcrumb>>§kargs: RefCell<Option<RHashMap<RSym, Rc<RObject>>>>§current_kargs: RefCell<Option<Rc<KArgs>>>§target_class: TargetContext§exception: Option<Rc<RException>>§flag_preemption: Cell<bool>§object_class: Rc<RClass>§builtin_class_table: RHashMap<&'static str, Rc<RClass>>§class_object_table: RHashMap<String, Rc<RObject>>§globals: RHashMap<String, Rc<RObject>>§consts: RHashMap<String, Rc<RObject>>§upper: Option<Rc<ENV>>§cur_env: RHashMap<usize, Rc<ENV>>§has_env_ref: RHashMap<usize, bool>§fn_table: RFnTable§fn_block_stack: RFnStack

Implementations§

Source§

impl VM

Source

pub fn open(rite: &mut Rite<'_>) -> VM

Builds a VM from a parsed Rite chunk, consuming the bytecode and preparing the VM so it can be executed via VM::run.

Source

pub fn empty() -> VM

Returns a VM backed by an empty IREP that immediately executes a STOP instruction. Useful for tests or placeholder VMs.

Source

pub fn new_by_raw_irep(irep: IREP) -> VM

Creates a VM directly from a raw IREP tree without going through the Rite loader. This wires up the register file, globals, and builtin tables and runs the prelude to seed standard classes.

Source

pub fn run(&mut self) -> Result<Rc<RObject>, Box<dyn Error>>

Executes the current IREP until completion, returning the value in register 0 or propagating any raised exception as an error. The top-level self is initialized automatically before evaluation.

Source

pub fn run_internal(&mut self) -> Result<Rc<RObject>, Box<dyn Error>>

Internal run method that manages breadcrumb stack for internal calls.

Source

pub fn getself(&mut self) -> Result<Rc<RObject>, Error>

Returns the current self object from register 0, or an error if it has not been initialized yet.

Source

pub fn must_getself(&mut self) -> Rc<RObject>

Retrieves self without error handling, panicking if register 0 is empty. Prefer VM::getself when the value may be absent.

Source

pub fn get_kwargs(&self) -> Option<RHashMap<String, Rc<RObject>>>

Source

pub fn get_class_by_name(&self, name: &str) -> Rc<RClass>

Looks up a previously defined builtin class by name. Panics if the class does not exist, which usually signals a missing prelude setup.

Source

pub fn get_module_by_name(&self, name: &str) -> Rc<RModule>

Source

pub fn get_const_by_name(&self, name: &str) -> Option<Rc<RObject>>

Source

pub fn define_class( &mut self, name: &str, superclass: Option<Rc<RClass>>, parent_module: Option<Rc<RModule>>, ) -> Rc<RClass>

Defines a new class under the optional parent module, inheriting from superclass or Object by default, and registers it in the constant table. The resulting class object is returned for further mutation.

Source

pub fn define_module( &mut self, name: &str, parent_module: Option<Rc<RModule>>, ) -> Rc<RModule>

Defines a new module, optionally nested under another module, and stores it in the VM’s constant table so it becomes accessible to Ruby code.

Source

pub fn debug_dump_to_stdout(&mut self, max_breadcrumb_level: usize)

Source

pub fn get_outermost_env(&self) -> Option<Rc<ENV>>

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.