pub struct VmScope<'a, SE>where
SE: ScriptExpression,{ /* private fields */ }Expand description
A list of script operations and the position reached in them.
This is the whole interpreter. Build one with VmScope::new and drive it
with VmScope::run, VmScope::run_until_suspended or
VmScope::step. It is also the ScriptFunctionGenerator of this backend,
so installing a script package produces one scope per function call.
Cloning copies the position and the child scope as well, so a clone carries on where the original stood.
Implementations§
Source§impl<'a, SE> VmScope<'a, SE>where
SE: ScriptExpression,
impl<'a, SE> VmScope<'a, SE>where
SE: ScriptExpression,
Sourcepub fn new(
handle: Arc<Vec<ScriptOperation<'a, SE>>>,
symbol: ID<()>,
) -> VmScope<'a, SE>
pub fn new( handle: Arc<Vec<ScriptOperation<'a, SE>>>, symbol: ID<()>, ) -> VmScope<'a, SE>
Starts a scope at the first operation of handle.
symbol names the script this scope belongs to, for debugging.
Sourcepub unsafe fn restore(
self,
position: usize,
child: Option<VmScope<'a, SE>>,
) -> VmScope<'a, SE>
pub unsafe fn restore( self, position: usize, child: Option<VmScope<'a, SE>>, ) -> VmScope<'a, SE>
Puts the scope back at position, with child as the nested scope that
was running there.
This is how a scope taken apart with VmScope::into_inner is put back
together, for example after being stored somewhere.
§Safety
position and child must come from a scope over the same script. The
operations that follow expect the stack and the registers to look the
way the skipped operations left them. Any other position runs them
against a state they were never written for.
Sourcepub fn with_debugger(
self,
debugger: Option<Arc<RwLock<dyn VmDebugger<SE> + Send + Sync>>>,
) -> VmScope<'a, SE>
pub fn with_debugger( self, debugger: Option<Arc<RwLock<dyn VmDebugger<SE> + Send + Sync>>>, ) -> VmScope<'a, SE>
Attaches a debugger, builder style. Child scopes inherit it.
Sourcepub fn into_inner(
self,
) -> (Arc<Vec<ScriptOperation<'a, SE>>>, ID<()>, usize, Option<Box<VmScope<'a, SE>>>, Option<Arc<RwLock<dyn VmDebugger<SE> + Send + Sync>>>)
pub fn into_inner( self, ) -> (Arc<Vec<ScriptOperation<'a, SE>>>, ID<()>, usize, Option<Box<VmScope<'a, SE>>>, Option<Arc<RwLock<dyn VmDebugger<SE> + Send + Sync>>>)
Splits the scope into its parts: script, symbol, position, child scope and debugger.
VmScope::restore puts them back together.
Sourcepub fn has_completed(&self) -> bool
pub fn has_completed(&self) -> bool
Returns true once every operation of this scope has run.
Says nothing about a child scope that may still be running.
Sourcepub fn child(&self) -> Option<&VmScope<'a, SE>>
pub fn child(&self) -> Option<&VmScope<'a, SE>>
Returns the nested scope that is running right now, if there is one.
Sourcepub fn run(&mut self, context: &mut Context, registry: &Registry)
pub fn run(&mut self, context: &mut Context, registry: &Registry)
Steps until the scope is done.
A Suspend operation does not stop this, so use
VmScope::run_until_suspended when the script is meant to yield.
§Panics
Panics on the same terms as VmScope::step.
Sourcepub fn run_until_suspended(
&mut self,
context: &mut Context,
registry: &Registry,
) -> VmScopeResult
pub fn run_until_suspended( &mut self, context: &mut Context, registry: &Registry, ) -> VmScopeResult
Steps until the scope is done or hits a Suspend operation.
Call it again to carry on from where it stopped. Never returns
VmScopeResult::Continue.
§Panics
Panics on the same terms as VmScope::step.
Sourcepub fn step(
&mut self,
context: &mut Context,
registry: &Registry,
) -> VmScopeResult
pub fn step( &mut self, context: &mut Context, registry: &Registry, ) -> VmScopeResult
Runs one operation, or one operation of the deepest child scope.
A scope past its last operation reports
VmScopeResult::Completed and does nothing.
§Panics
The operations trust what the frontend produced, so a broken script
panics rather than failing. It panics when a register or a function
query matches nothing, when a register index does not exist, when a
value does not fit on the stack, and when a branch or loop operation
finds no bool on top of the stack.
Trait Implementations§
Source§impl<SE> Clone for VmScope<'_, SE>where
SE: ScriptExpression,
impl<SE> Clone for VmScope<'_, SE>where
SE: ScriptExpression,
Source§impl<SE> ScriptFunctionGenerator<SE> for VmScope<'static, SE>where
SE: ScriptExpression + 'static,
impl<SE> ScriptFunctionGenerator<SE> for VmScope<'static, SE>where
SE: ScriptExpression + 'static,
Source§type Input = Option<Arc<RwLock<dyn VmDebugger<SE> + Send + Sync>>>
type Input = Option<Arc<RwLock<dyn VmDebugger<SE> + Send + Sync>>>
Source§fn generate_function_body(
script: Arc<Vec<ScriptOperation<'static, SE>>>,
debugger: <VmScope<'static, SE> as ScriptFunctionGenerator<SE>>::Input,
) -> Option<(FunctionBody, <VmScope<'static, SE> as ScriptFunctionGenerator<SE>>::Output)>
fn generate_function_body( script: Arc<Vec<ScriptOperation<'static, SE>>>, debugger: <VmScope<'static, SE> as ScriptFunctionGenerator<SE>>::Input, ) -> Option<(FunctionBody, <VmScope<'static, SE> as ScriptFunctionGenerator<SE>>::Output)>
None when it cannot.