Skip to main content

Runtime

Struct Runtime 

Source
pub struct Runtime { /* private fields */ }
Expand description

Persistent state used to execute compiled MiraScript programs.

A Runtime owns all dynamically allocated values. Values containing handles therefore remain usable until this Runtime is dropped.

Implementations§

Source§

impl Runtime

Source

pub fn call( &mut self, function: MiraValue, args: &[MiraValue], ) -> Result<MiraValue>

Call a function value owned by this Runtime.

Source§

impl Runtime

Source

pub fn insert_global( &mut self, name: impl Into<String>, value: impl Into<MiraManageable>, ) -> Result<Option<MiraValue>>

Insert or replace a global after converting it into a Runtime value.

Source

pub fn insert_fn( &mut self, name: impl Into<String>, function: impl Into<MiraNativeFn>, ) -> Result<Option<MiraValue>>

Insert a named native function into the global namespace.

Source

pub fn get_global(&self, name: &str) -> Option<MiraValue>

Clone a global value by name.

Source

pub fn contains_global(&self, name: &str) -> bool

Return whether a global name is defined.

Source

pub fn remove_global(&mut self, name: &str) -> Option<MiraValue>

Remove a global value by name, returning the previous value if it existed. You shall call take_* to remove the value from the Runtime’s arena if you want to reclaim its memory.

Source

pub fn global_names(&self) -> impl Iterator<Item = &str>

Iterate over global names in insertion order.

Source§

impl Runtime

Source

pub fn new() -> Self

Create a Runtime using default limits and install the standard library.

Source

pub fn with_options(options: RunOptions) -> Self

Create a Runtime using explicit execution limits and providers.

Source

pub fn eval(&mut self, script: &str) -> Result<MiraValue>

Compile and execute a MiraScript program in this Runtime.

Source

pub fn eval_unchecked(&mut self, script: &str) -> MiraValue

Compile and execute a MiraScript program in this Runtime, returning the result or panicking on error.

Source

pub fn run(&mut self, script: &MiraScript) -> Result<MiraValue>

Execute a compiled script in this Runtime.

Source

pub fn options(&self) -> &RunOptions

Return the Runtime’s execution configuration.

Source

pub fn values_equal( &mut self, left: MiraValue, right: MiraValue, ) -> Result<bool>

Compare values using MiraScript’s structural equality semantics.

Source§

impl Runtime

Source

pub fn insert(&mut self, value: impl Into<MiraManageable>) -> Result<MiraValue>

Insert an owned value into this Runtime when necessary.

Source§

impl Runtime

Functions for working with string handles.

Source

pub fn insert_string( &mut self, value: impl Into<String>, ) -> Result<MiraHandle<String>>

Insert an owned string and return its typed handle.

Source

pub fn get_string(&self, handle: MiraHandle<String>) -> Result<&str>

Read a string handle owned by this Runtime.

Source

pub fn get_string_mut( &mut self, handle: MiraHandle<String>, ) -> Result<&mut String>

Mutably read a string handle owned by this Runtime.

Source

pub fn take_string(&mut self, handle: MiraHandle<String>) -> Result<String>

Take a string handle owned by this Runtime, consuming the handle.

Source§

impl Runtime

Functions for working with function handles.

Source

pub fn insert_function<T: MiraFunction>( &mut self, value: T, ) -> Result<MiraHandle<T>>

Insert a function and return a concrete typed handle.

Source

pub fn get_function<T: MiraFunction>(&self, handle: MiraHandle<T>) -> Result<&T>

Read the concrete function stored behind a typed handle.

Source

pub fn take_function<T: MiraFunction>( &mut self, handle: MiraHandle<T>, ) -> Result<Rc<T>>

Take the concrete function stored behind a typed handle, consuming the handle.

Source§

impl Runtime

Functions for working with array handles.

Source

pub fn insert_array<T: MiraArray>(&mut self, value: T) -> Result<MiraHandle<T>>

Insert a array and return a concrete typed handle.

Source

pub fn get_array<T: MiraArray>(&self, handle: MiraHandle<T>) -> Result<&T>

Read the concrete target represented by a typed array handle.

Source

pub fn get_array_mut<T: MiraArray>( &mut self, handle: MiraHandle<T>, ) -> Result<&mut T>

Mutably read the concrete object stored directly behind a array handle.

Source

pub fn take_array<T: MiraArray>(&mut self, handle: MiraHandle<T>) -> Result<T>

Take the concrete object stored directly behind a array handle, consuming the handle.

Source§

impl Runtime

Functions for working with record handles.

Source

pub fn insert_record<T: MiraRecord>( &mut self, value: T, ) -> Result<MiraHandle<T>>

Insert a record and return a concrete typed handle.

Source

pub fn get_record<T: MiraRecord>(&self, handle: MiraHandle<T>) -> Result<&T>

Read the concrete target represented by a typed record handle.

Source

pub fn get_record_mut<T: MiraRecord>( &mut self, handle: MiraHandle<T>, ) -> Result<&mut T>

Mutably read the concrete object stored directly behind a record handle.

Source

pub fn take_record<T: MiraRecord>(&mut self, handle: MiraHandle<T>) -> Result<T>

Take the concrete object stored directly behind a record handle, consuming the handle.

Source§

impl Runtime

Functions for working with module handles.

Source

pub fn insert_module<T: MiraModule>( &mut self, value: T, ) -> Result<MiraHandle<T>>

Insert a module and return a concrete typed handle.

Source

pub fn get_module<T: MiraModule>(&self, handle: MiraHandle<T>) -> Result<&T>

Read the concrete target represented by a typed module handle.

Source

pub fn get_module_mut<T: MiraModule>( &mut self, handle: MiraHandle<T>, ) -> Result<&mut T>

Mutably read the concrete object stored directly behind a module handle.

Source

pub fn take_module<T: MiraModule>(&mut self, handle: MiraHandle<T>) -> Result<T>

Take the concrete object stored directly behind a module handle, consuming the handle.

Trait Implementations§

Source§

impl Default for Runtime

Source§

fn default() -> Self

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

Auto Trait Implementations§

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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.