Struct koto_runtime::prelude::KotoVm
source · pub struct KotoVm { /* private fields */ }
Expand description
The Koto runtime’s virtual machine
Implementations§
source§impl KotoVm
impl KotoVm
sourcepub fn with_settings(settings: KotoVmSettings) -> Self
pub fn with_settings(settings: KotoVmSettings) -> Self
Initializes a Koto VM with the provided settings
Spawn a VM that shares the same execution context
e.g.
- An iterator spawns a shared VM that can be used to execute functors
- A generator function spawns a shared VM to yield incremental results
- Thrown errors spawn a shared VM to display an error from a custom error type
sourcepub fn loader(&self) -> &KCell<Loader>
pub fn loader(&self) -> &KCell<Loader>
The loader, responsible for loading and compiling Koto scripts and modules
sourcepub fn prelude(&self) -> &KMap
pub fn prelude(&self) -> &KMap
The prelude, containing items that can be imported within all modules
sourcepub fn exports(&self) -> &KMap
pub fn exports(&self) -> &KMap
The active module’s exports map
Note that this is the exports map of the active module, so during execution the returned map will be of the module that’s currently being executed.
sourcepub fn exports_mut(&mut self) -> &mut KMap
pub fn exports_mut(&mut self) -> &mut KMap
Returns a mutable reference to the active module’s exports map
sourcepub fn continue_running(&mut self) -> Result<ReturnOrYield>
pub fn continue_running(&mut self) -> Result<ReturnOrYield>
Continues execution in a suspended VM
This is currently used to support generators, which yield incremental results and then leave the VM in a suspended state.
sourcepub fn call_function<'a>(
&mut self,
function: KValue,
args: impl Into<CallArgs<'a>>,
) -> Result<KValue>
pub fn call_function<'a>( &mut self, function: KValue, args: impl Into<CallArgs<'a>>, ) -> Result<KValue>
Calls a function with some given arguments
sourcepub fn call_instance_function<'a>(
&mut self,
instance: KValue,
function: KValue,
args: impl Into<CallArgs<'a>>,
) -> Result<KValue>
pub fn call_instance_function<'a>( &mut self, instance: KValue, function: KValue, args: impl Into<CallArgs<'a>>, ) -> Result<KValue>
Runs an instance function with some given arguments
sourcepub fn value_to_string(&mut self, value: &KValue) -> Result<String>
pub fn value_to_string(&mut self, value: &KValue) -> Result<String>
Returns a displayable string for the given value
sourcepub fn run_unary_op(&mut self, op: UnaryOp, value: KValue) -> Result<KValue>
pub fn run_unary_op(&mut self, op: UnaryOp, value: KValue) -> Result<KValue>
Provides the result of running a unary operation on a KValue
sourcepub fn run_binary_op(
&mut self,
op: BinaryOp,
lhs: KValue,
rhs: KValue,
) -> Result<KValue>
pub fn run_binary_op( &mut self, op: BinaryOp, lhs: KValue, rhs: KValue, ) -> Result<KValue>
Provides the result of running a binary operation on a pair of Values
sourcepub fn make_iterator(&mut self, value: KValue) -> Result<KIterator>
pub fn make_iterator(&mut self, value: KValue) -> Result<KIterator>
Makes a KIterator that iterates over the provided value’s contents
Trait Implementations§
Auto Trait Implementations§
impl Freeze for KotoVm
impl !RefUnwindSafe for KotoVm
impl Send for KotoVm
impl Sync for KotoVm
impl Unpin for KotoVm
impl !UnwindSafe for KotoVm
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.