pub struct Vm { /* private fields */ }Expand description
A virtual machine that executes compiled Muse Code.
Implementations§
source§impl Vm
impl Vm
sourcepub fn new(guard: &CollectionGuard<'_>) -> Self
pub fn new(guard: &CollectionGuard<'_>) -> Self
Returns a new virtual machine.
Virtual machines are allocated within the [refuse] garbage collector.
Each virtual machine acts as a “root” reference to all of the values
contained within its stack and registers.
sourcepub fn compile_and_execute<'a>(
&self,
source: impl Into<SourceCode<'a>>,
guard: &mut CollectionGuard<'_>,
) -> Result<Value, Error>
pub fn compile_and_execute<'a>( &self, source: impl Into<SourceCode<'a>>, guard: &mut CollectionGuard<'_>, ) -> Result<Value, Error>
sourcepub fn prepare(
&self,
code: &Code,
guard: &mut CollectionGuard<'_>,
) -> Result<(), Fault>
pub fn prepare( &self, code: &Code, guard: &mut CollectionGuard<'_>, ) -> Result<(), Fault>
Prepares to execute code.
This function does not actually execute any code. A call to
resume/resume_async is needed
to begin executing the function call.
sourcepub fn prepare_call(
&self,
function: &Rooted<Function>,
arity: Arity,
guard: &mut CollectionGuard<'_>,
) -> Result<(), Fault>
pub fn prepare_call( &self, function: &Rooted<Function>, arity: Arity, guard: &mut CollectionGuard<'_>, ) -> Result<(), Fault>
Prepares to execute the function body with arity arguments.
This function does not actually execute any code. A call to
resume/resume_async is needed
to begin executing the function call.
sourcepub fn execute(
&self,
code: &Code,
guard: &mut CollectionGuard<'_>,
) -> Result<Value, ExecutionError>
pub fn execute( &self, code: &Code, guard: &mut CollectionGuard<'_>, ) -> Result<Value, ExecutionError>
Executes code and returns the result.
sourcepub fn execute_for(
&self,
code: &Code,
duration: Duration,
guard: &mut CollectionGuard<'_>,
) -> Result<Value, ExecutionError>
pub fn execute_for( &self, code: &Code, duration: Duration, guard: &mut CollectionGuard<'_>, ) -> Result<Value, ExecutionError>
Executes code for at most duration before returning a timout.
sourcepub fn execute_until(
&self,
code: &Code,
instant: Instant,
guard: &mut CollectionGuard<'_>,
) -> Result<Value, ExecutionError>
pub fn execute_until( &self, code: &Code, instant: Instant, guard: &mut CollectionGuard<'_>, ) -> Result<Value, ExecutionError>
Executes code for until instant before returning a timout.
sourcepub fn resume(
&self,
guard: &mut CollectionGuard<'_>,
) -> Result<Value, ExecutionError>
pub fn resume( &self, guard: &mut CollectionGuard<'_>, ) -> Result<Value, ExecutionError>
Resumes executing the current code.
This should only be called if an ExecutionError::Waiting,
ExecutionError::NoBudget, or ExecutionError::Timeout was
returned when executing code.
sourcepub fn resume_until(
&mut self,
instant: Instant,
guard: &mut CollectionGuard<'_>,
) -> Result<Value, ExecutionError>
pub fn resume_until( &mut self, instant: Instant, guard: &mut CollectionGuard<'_>, ) -> Result<Value, ExecutionError>
Resumes executing the currently executing code until instant.
This should only be called if an ExecutionError::Waiting,
ExecutionError::NoBudget, or ExecutionError::Timeout was
returned when executing code.
sourcepub fn resume_for(
&mut self,
duration: Duration,
guard: &mut CollectionGuard<'_>,
) -> Result<Value, ExecutionError>
pub fn resume_for( &mut self, duration: Duration, guard: &mut CollectionGuard<'_>, ) -> Result<Value, ExecutionError>
Resumes executing the currently executing code until duration as
elapsed.
This should only be called if an ExecutionError::Waiting,
ExecutionError::NoBudget, or ExecutionError::Timeout was
returned when executing code.
sourcepub fn execute_async<'context, 'guard>(
&'context self,
code: &Code,
guard: &'context mut CollectionGuard<'guard>,
) -> Result<ExecuteAsync<'static, 'context, 'guard>, Fault>
pub fn execute_async<'context, 'guard>( &'context self, code: &Code, guard: &'context mut CollectionGuard<'guard>, ) -> Result<ExecuteAsync<'static, 'context, 'guard>, Fault>
Returns a future that executes code asynchronously.
sourcepub fn resume_async<'context, 'guard>(
&'context self,
guard: &'context mut CollectionGuard<'guard>,
) -> ExecuteAsync<'static, 'context, 'guard> ⓘ
pub fn resume_async<'context, 'guard>( &'context self, guard: &'context mut CollectionGuard<'guard>, ) -> ExecuteAsync<'static, 'context, 'guard> ⓘ
Resumes executing the current code asynchronously.
This should only be called if an ExecutionError::Waiting,
ExecutionError::NoBudget, or ExecutionError::Timeout was
returned when executing code.
sourcepub fn resume_for_async<'context, 'guard>(
&'context self,
duration: Duration,
guard: &'context mut CollectionGuard<'guard>,
) -> ExecuteAsync<'static, 'context, 'guard> ⓘ
pub fn resume_for_async<'context, 'guard>( &'context self, duration: Duration, guard: &'context mut CollectionGuard<'guard>, ) -> ExecuteAsync<'static, 'context, 'guard> ⓘ
Resumes executing the currently executing code until duration as
elapsed.
This should only be called if an ExecutionError::Waiting,
ExecutionError::NoBudget, or ExecutionError::Timeout was
returned when executing code.
sourcepub fn resume_until_async<'context, 'guard>(
&'context self,
instant: Instant,
guard: &'context mut CollectionGuard<'guard>,
) -> ExecuteAsync<'static, 'context, 'guard> ⓘ
pub fn resume_until_async<'context, 'guard>( &'context self, instant: Instant, guard: &'context mut CollectionGuard<'guard>, ) -> ExecuteAsync<'static, 'context, 'guard> ⓘ
Resumes executing the currently executing code until instant.
This should only be called if an ExecutionError::Waiting,
ExecutionError::NoBudget, or ExecutionError::Timeout was
returned when executing code.
sourcepub fn increase_budget(&self, amount: usize)
pub fn increase_budget(&self, amount: usize)
Increases the current budget by amount.
If the virtual machine currently is unbudgeted, calling this function enables budgeting.
sourcepub fn invoke(
&self,
name: impl Into<SymbolRef>,
params: impl InvokeArgs,
guard: &mut CollectionGuard<'_>,
) -> Result<Value, ExecutionError>
pub fn invoke( &self, name: impl Into<SymbolRef>, params: impl InvokeArgs, guard: &mut CollectionGuard<'_>, ) -> Result<Value, ExecutionError>
Invokes a public function at path name with the given parameters.
sourcepub fn context<'context, 'guard>(
&'context self,
guard: &'context mut CollectionGuard<'guard>,
) -> VmContext<'context, 'guard>
pub fn context<'context, 'guard>( &'context self, guard: &'context mut CollectionGuard<'guard>, ) -> VmContext<'context, 'guard>
Returns an execution context that synchronizes with the garbage collector.
sourcepub fn set_steps_per_charge(&self, steps: u16)
pub fn set_steps_per_charge(&self, steps: u16)
Sets the number of virtual machine steps to take per budget being charged.
This also affects how often the virtual machine checks if it should yield to the garbage collector.
sourcepub fn set_register(&self, register: Register, value: Value) -> Value
pub fn set_register(&self, register: Register, value: Value) -> Value
Replaces the current value in register with value.
sourcepub fn stack(&self, index: Stack) -> Value
pub fn stack(&self, index: Stack) -> Value
Returns the value contained at index on the stack.
§Panics
This function panics if index is out of bounds of the stack.
sourcepub fn set_stack(&self, index: Stack, value: Value) -> Value
pub fn set_stack(&self, index: Stack, value: Value) -> Value
Replaces the current value at index on the stack with value.
§Panics
This function panics if index is out of bounds of the stack.
sourcepub fn declare_variable(
&self,
name: SymbolRef,
mutable: bool,
guard: &mut CollectionGuard<'_>,
) -> Result<Stack, Fault>
pub fn declare_variable( &self, name: SymbolRef, mutable: bool, guard: &mut CollectionGuard<'_>, ) -> Result<Stack, Fault>
Allocates a variable declaration.
Returns a stack index that has been allocated. The Muse virtual machine ensures the stack is Nil-initialized.
sourcepub fn declare(
&self,
name: impl Into<SymbolRef>,
value: Value,
guard: &mut CollectionGuard<'_>,
) -> Result<Option<Value>, Fault>
pub fn declare( &self, name: impl Into<SymbolRef>, value: Value, guard: &mut CollectionGuard<'_>, ) -> Result<Option<Value>, Fault>
Declares an immutable variable with name containing value.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Vm
impl !RefUnwindSafe for Vm
impl Send for Vm
impl Sync for Vm
impl Unpin for Vm
impl !UnwindSafe for Vm
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
§impl<A> Cast for A
impl<A> Cast for A
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit)