pub struct VmExecution<T = Vm>{ /* private fields */ }
Expand description
The execution environment for a virtual machine.
When an execution is dropped, the stack of the stack of the head machine will be cleared.
Implementations§
Source§impl<T> VmExecution<T>
impl<T> VmExecution<T>
Sourcepub fn into_generator(self) -> Generator<T>
pub fn into_generator(self) -> Generator<T>
Coerce the current execution into a generator if appropriate.
use rune::Vm;
use std::sync::Arc;
let mut sources = rune::sources! {
entry => {
pub fn main() {
yield 1;
yield 2;
}
}
};
let unit = rune::prepare(&mut sources).build()?;
let mut vm = Vm::without_runtime(Arc::new(unit));
let mut generator = vm.execute(["main"], ())?.into_generator();
let mut n = 1i64;
while let Some(value) = generator.next().into_result()? {
let value: i64 = rune::from_value(value)?;
assert_eq!(value, n);
n += 1;
}
Sourcepub fn into_stream(self) -> Stream<T>
pub fn into_stream(self) -> Stream<T>
Coerce the current execution into a stream if appropriate.
use rune::Vm;
use std::sync::Arc;
let mut sources = rune::sources! {
entry => {
pub async fn main() {
yield 1;
yield 2;
}
}
};
let unit = rune::prepare(&mut sources).build()?;
let mut vm = Vm::without_runtime(Arc::new(unit));
let mut stream = vm.execute(["main"], ())?.into_stream();
let mut n = 1i64;
while let Some(value) = stream.next().await.into_result()? {
let value: i64 = rune::from_value(value)?;
assert_eq!(value, n);
n += 1;
}
Sourcepub async fn async_complete(&mut self) -> VmResult<Value>
pub async fn async_complete(&mut self) -> VmResult<Value>
Complete the current execution without support for async instructions.
This will error if the execution is suspended through yielding.
Sourcepub fn complete(&mut self) -> VmResult<Value>
pub fn complete(&mut self) -> VmResult<Value>
Complete the current execution without support for async instructions.
If any async instructions are encountered, this will error. This will also error if the execution is suspended through yielding.
Sourcepub fn complete_with_diagnostics(
&mut self,
diagnostics: Option<&mut dyn VmDiagnostics>,
) -> VmResult<Value>
pub fn complete_with_diagnostics( &mut self, diagnostics: Option<&mut dyn VmDiagnostics>, ) -> VmResult<Value>
Complete the current execution without support for async instructions.
If any async instructions are encountered, this will error. This will also error if the execution is suspended through yielding.
Sourcepub async fn async_resume_with(
&mut self,
value: Value,
) -> VmResult<GeneratorState>
pub async fn async_resume_with( &mut self, value: Value, ) -> VmResult<GeneratorState>
Resume the current execution with the given value and resume asynchronous execution.
Sourcepub async fn async_resume(&mut self) -> VmResult<GeneratorState>
pub async fn async_resume(&mut self) -> VmResult<GeneratorState>
Resume the current execution with support for async instructions.
If the function being executed is a generator or stream this will resume
it while returning a unit from the current yield
.
Sourcepub async fn async_resume_with_diagnostics(
&mut self,
diagnostics: Option<&mut dyn VmDiagnostics>,
) -> VmResult<GeneratorState>
pub async fn async_resume_with_diagnostics( &mut self, diagnostics: Option<&mut dyn VmDiagnostics>, ) -> VmResult<GeneratorState>
Resume the current execution with support for async instructions.
If the function being executed is a generator or stream this will resume
it while returning a unit from the current yield
.
Sourcepub fn resume_with(&mut self, value: Value) -> VmResult<GeneratorState>
pub fn resume_with(&mut self, value: Value) -> VmResult<GeneratorState>
Resume the current execution with the given value and resume synchronous execution.
Sourcepub fn resume(&mut self) -> VmResult<GeneratorState>
pub fn resume(&mut self) -> VmResult<GeneratorState>
Resume the current execution without support for async instructions.
If the function being executed is a generator or stream this will resume
it while returning a unit from the current yield
.
If any async instructions are encountered, this will error.
Sourcepub fn resume_with_diagnostics(
&mut self,
diagnostics: Option<&mut dyn VmDiagnostics>,
) -> VmResult<GeneratorState>
pub fn resume_with_diagnostics( &mut self, diagnostics: Option<&mut dyn VmDiagnostics>, ) -> VmResult<GeneratorState>
Resume the current execution without support for async instructions.
If the function being executed is a generator or stream this will resume
it while returning a unit from the current yield
.
If any async instructions are encountered, this will error.
Sourcepub fn step(&mut self) -> VmResult<Option<Value>>
pub fn step(&mut self) -> VmResult<Option<Value>>
Step the single execution for one step without support for async instructions.
If any async instructions are encountered, this will error.
Sourcepub async fn async_step(&mut self) -> VmResult<Option<Value>>
pub async fn async_step(&mut self) -> VmResult<Option<Value>>
Step the single execution for one step with support for async instructions.
Source§impl VmExecution<&mut Vm>
impl VmExecution<&mut Vm>
Sourcepub fn into_owned(self) -> VmExecution<Vm>
pub fn into_owned(self) -> VmExecution<Vm>
Convert the current execution into one which owns its virtual machine.