Struct koto_runtime::KotoVm

source ·
pub struct KotoVm { /* private fields */ }
Expand description

The Koto runtime’s virtual machine

Implementations§

source§

impl KotoVm

source

pub fn with_settings(settings: KotoVmSettings) -> Self

Initializes a Koto VM with the provided settings

source

pub fn spawn_shared_vm(&self) -> Self

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
source

pub fn loader(&self) -> &KCell<Loader>

The loader, responsible for loading and compiling Koto scripts and modules

source

pub fn prelude(&self) -> &KMap

The prelude, containing items that can be imported within all modules

source

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.

source

pub fn exports_mut(&mut self) -> &mut KMap

Returns a mutable reference to the active module’s exports map

source

pub fn stdin(&self) -> &Ptr<dyn KotoFile>

The stdin wrapper used by the VM

source

pub fn stdout(&self) -> &Ptr<dyn KotoFile>

The stdout wrapper used by the VM

source

pub fn stderr(&self) -> &Ptr<dyn KotoFile>

The stderr wrapper used by the VM

source

pub fn run(&mut self, chunk: Ptr<Chunk>) -> Result<KValue>

Runs the provided Chunk, returning the resulting KValue

source

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.

source

pub fn call_function<'a>( &mut self, function: KValue, args: impl Into<CallArgs<'a>> ) -> Result<KValue>

Calls a function with some given arguments

source

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

source

pub fn value_to_string(&mut self, value: &KValue) -> Result<String>

Returns a displayable string for the given value

source

pub fn run_unary_op(&mut self, op: UnaryOp, value: KValue) -> Result<KValue>

Provides the result of running a unary operation on a KValue

source

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

source

pub fn make_iterator(&mut self, value: KValue) -> Result<KIterator>

Makes a KIterator that iterates over the provided value’s contents

source

pub fn run_tests(&mut self, tests: KMap) -> Result<KValue>

Runs any tests that are contained in the map’s @tests meta entry

Any test failure will be returned as an error.

source

pub fn chunk(&self) -> Ptr<Chunk>

The bytecode chunk currently active in the VM

Trait Implementations§

source§

impl Clone for KotoVm

source§

fn clone(&self) -> KotoVm

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for KotoVm

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for KotoVm

source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> 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> Downcast for T
where T: Any,

source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

Convert 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)

Convert &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)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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.