pub struct Vm { /* private fields */ }Expand description
Virtual machine for EndBASIC program execution.
Implementations§
Source§impl Vm
impl Vm
Sourcepub fn new(upcalls_by_name: HashMap<SymbolKey, Rc<dyn Callable>>) -> Self
pub fn new(upcalls_by_name: HashMap<SymbolKey, Rc<dyn Callable>>) -> Self
Creates a new VM with the given upcalls_by_name as the available built-in callables.
Sourcepub fn new_with_limits(
upcalls_by_name: HashMap<SymbolKey, Rc<dyn Callable>>,
limits: Limits,
) -> Self
pub fn new_with_limits( upcalls_by_name: HashMap<SymbolKey, Rc<dyn Callable>>, limits: Limits, ) -> Self
Creates a new VM with the given upcalls_by_name and resource limits.
Sourcepub fn reset(&mut self)
pub fn reset(&mut self)
Resets any existing execution state, including upcall caches and the program counter.
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Resets runtime state (registers, heap, last error, call stack, program counter) but preserves upcall caches so the same image can continue to be executed.
Note: because the program counter is also reset, callers need to either re-set it to a specific location or replace the image with one that resumes from the start.
Sourcepub fn clear_error_handler(&mut self)
pub fn clear_error_handler(&mut self)
Clears the current error handler without affecting execution state or captured errors.
Sourcepub fn get_global(
&self,
image: &Image,
key: &SymbolKey,
) -> GetGlobalResult<Option<ConstantDatum>>
pub fn get_global( &self, image: &Image, key: &SymbolKey, ) -> GetGlobalResult<Option<ConstantDatum>>
Returns the value of the global scalar variable key as a ConstantDatum.
Returns Ok(None) if the variable is not defined (no image is loaded or the
variable was not declared). Returns Err if the variable exists but is an
array; in that case, use get_global_array instead.
Sourcepub fn get_global_array(
&self,
image: &Image,
key: &SymbolKey,
subscripts: &[i32],
) -> GetGlobalResult<Option<ConstantDatum>>
pub fn get_global_array( &self, image: &Image, key: &SymbolKey, subscripts: &[i32], ) -> GetGlobalResult<Option<ConstantDatum>>
Returns the value of an element in the global array variable key at the given
subscripts as a ConstantDatum.
Returns Ok(None) if the variable is not defined (no image is loaded or the
variable was not declared). Returns Err if the variable exists but is a scalar
(use get_global instead), or if the subscripts are out of bounds.
Sourcepub fn get_program(
&self,
image: &Image,
key: &SymbolKey,
) -> GetGlobalResult<Option<ConstantDatum>>
pub fn get_program( &self, image: &Image, key: &SymbolKey, ) -> GetGlobalResult<Option<ConstantDatum>>
Returns the value of the program-scope scalar variable key as a ConstantDatum.
Returns Ok(None) if the variable is not defined (no image is loaded or the
variable was not declared). Returns Err if the variable exists but is an
array; in that case, use get_program_array instead.
Sourcepub fn get_program_array(
&self,
image: &Image,
key: &SymbolKey,
subscripts: &[i32],
) -> GetGlobalResult<Option<ConstantDatum>>
pub fn get_program_array( &self, image: &Image, key: &SymbolKey, subscripts: &[i32], ) -> GetGlobalResult<Option<ConstantDatum>>
Returns the value of an element in the program-scope array variable key at the
given subscripts as a ConstantDatum.
Returns Ok(None) if the variable is not defined (no image is loaded or the
variable was not declared). Returns Err if the variable exists but is a scalar
(use get_program instead), or if the subscripts are out of bounds.
Sourcepub fn exec<'a>(&'a mut self, image: &'a Image) -> StopReason<'a>
pub fn exec<'a>(&'a mut self, image: &'a Image) -> StopReason<'a>
Starts or resumes execution of image.
Returns a StopReason indicating why execution stopped, which may be due to program
termination, an exception, or a pending upcall that requires caller handling.