Skip to main content

Vm

Struct Vm 

Source
pub struct Vm {
    pub load_paths: Vec<String>,
    /* private fields */
}
Expand description

VM structure containing hooks and loaded modules

Fields§

§load_paths: Vec<String>

List of directories for module lookup.

Implementations§

Source§

impl Vm

Source

pub fn new() -> Vm

Create a new instance.

Source

pub fn add_load_path(&mut self, path: String)

Add a directory for module lookup.

Source

pub fn call(&mut self, name: &str, args: &[Value]) -> Result<Value, Lovm2Error>

Call a function by name with given arguments.

Source

pub fn context_mut(&mut self) -> &mut Context

Get a mutable reference to the current Context

Source

pub fn add_function<T>( &mut self, key: T, co: Rc<dyn CallProtocol>, ) -> Result<(), Lovm2Error>
where T: Into<Variable>,

Add a new function by name to the virtual machine.

Source

pub fn add_module<T>( &mut self, module: T, namespaced: bool, ) -> Result<(), Lovm2Error>
where T: Into<Module>,

Add the module and all of its slots to scope.

Source

pub fn add_module_by_name( &mut self, name: &str, relative_to: Option<String>, namespaced: bool, ) -> Result<(), Lovm2Error>

Lookup a module name in load_paths and add it to the context. relative_to is expected to be an absolute path to the imported module.

Source

pub fn add_main_module<T>(&mut self, module: T) -> Result<(), Lovm2Error>
where T: Into<Module>,

Add the module and all of its slots to scope.

Source

pub fn run_object(&mut self, co: &dyn CallProtocol) -> Result<Value, Lovm2Error>

A wrapper for run_bytecode that handles pushing and popping stack frames.

Source

pub fn run(&mut self) -> Result<Value, Lovm2Error>

Start the execution at ENTRY_POINT.

Source

pub fn run_bytecode( &mut self, co: &CodeObject, offset: usize, ) -> Result<(), Lovm2Error>

implementation of lovm2 bytecode behavior

Note: This function does not push a stack frame and could therefore mess up local variables if not handled correctly. See Vm::run_object.

Source

pub fn set_import_hook<T>(&mut self, hook: T)
where T: Fn(Option<&str>, &str) -> Result<Option<String>, Lovm2Error> + 'static,

Register a new callback function that is used for patching function names.

Source

pub fn set_load_hook<T>(&mut self, hook: T)
where T: Fn(&LoadRequest) -> Result<Option<Module>, Lovm2Error> + 'static,

Register a new callback function that is used for resolving dependencies at runtime.

Source

pub fn set_interrupt<T>(&mut self, n: u16, func: T) -> Result<(), Lovm2Error>
where T: Fn(&mut Vm) -> Result<(), Lovm2Error> + 'static,

Gegister a new callback function on interrupt n.

Auto Trait Implementations§

§

impl Freeze for Vm

§

impl !RefUnwindSafe for Vm

§

impl !Send for Vm

§

impl !Sync for Vm

§

impl Unpin for Vm

§

impl UnsafeUnpin 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.