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>>§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: RFnStackImplementations§
Source§impl VM
impl VM
Sourcepub fn open(rite: &mut Rite<'_>) -> VM
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.
Sourcepub fn empty() -> VM
pub fn empty() -> VM
Returns a VM backed by an empty IREP that immediately executes a
STOP instruction. Useful for tests or placeholder VMs.
Sourcepub fn new_by_raw_irep(irep: IREP) -> VM
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.
Sourcepub fn run(&mut self) -> Result<Rc<RObject>, Box<dyn Error>>
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.
Sourcepub fn run_internal(&mut self) -> Result<Rc<RObject>, Box<dyn Error>>
pub fn run_internal(&mut self) -> Result<Rc<RObject>, Box<dyn Error>>
Internal run method that manages breadcrumb stack for internal calls.
Sourcepub fn getself(&mut self) -> Result<Rc<RObject>, Error>
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.
Sourcepub fn must_getself(&mut self) -> Rc<RObject>
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.
pub fn get_kwargs(&self) -> Option<RHashMap<String, Rc<RObject>>>
Sourcepub fn get_class_by_name(&self, name: &str) -> Rc<RClass>
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.
pub fn get_module_by_name(&self, name: &str) -> Rc<RModule>
pub fn get_const_by_name(&self, name: &str) -> Option<Rc<RObject>>
Sourcepub fn define_class(
&mut self,
name: &str,
superclass: Option<Rc<RClass>>,
parent_module: Option<Rc<RModule>>,
) -> Rc<RClass>
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.
Sourcepub fn define_module(
&mut self,
name: &str,
parent_module: Option<Rc<RModule>>,
) -> Rc<RModule>
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.