Skip to main content

VmScope

Struct VmScope 

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

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn symbol(&self) -> ID<()>

Returns the script this scope belongs to.

Source

pub fn position(&self) -> usize

Returns the index of the next operation to run.

Source

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.

Source

pub fn child(&self) -> Option<&VmScope<'a, SE>>

Returns the nested scope that is running right now, if there is one.

Source

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.

Source

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.

Source

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,

Source§

fn clone(&self) -> VmScope<'_, SE>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<SE> ScriptFunctionGenerator<SE> for VmScope<'static, SE>
where SE: ScriptExpression + 'static,

Source§

type Input = Option<Arc<RwLock<dyn VmDebugger<SE> + Send + Sync>>>

Configuration the backend needs, passed through at install time.
Source§

type Output = ID<()>

Anything the backend wants to return alongside the function.
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)>

Builds a body from a script, or returns None when it cannot.
Source§

fn generate_function( function: &ScriptFunction<'static, SE>, registry: &Registry, input: Self::Input, ) -> Option<(Function, Self::Output)>

Builds a whole function, resolving the signature against the registry.

Auto Trait Implementations§

§

impl<'a, SE> Freeze for VmScope<'a, SE>
where Arc<Vec<ScriptOperation<'a, SE>>>: Freeze, Option<Box<VmScope<'a, SE>>>: Freeze, Option<Arc<RwLock<dyn VmDebugger<SE> + Send + Sync>>>: Freeze,

§

impl<'a, SE> RefUnwindSafe for VmScope<'a, SE>

§

impl<'a, SE> Send for VmScope<'a, SE>
where Arc<Vec<ScriptOperation<'a, SE>>>: Send, Option<Box<VmScope<'a, SE>>>: Send, Option<Arc<RwLock<dyn VmDebugger<SE> + Send + Sync>>>: Send,

§

impl<'a, SE> Sync for VmScope<'a, SE>
where Arc<Vec<ScriptOperation<'a, SE>>>: Sync, Option<Box<VmScope<'a, SE>>>: Sync, Option<Arc<RwLock<dyn VmDebugger<SE> + Send + Sync>>>: Sync,

§

impl<'a, SE> Unpin for VmScope<'a, SE>
where Arc<Vec<ScriptOperation<'a, SE>>>: Unpin, Option<Box<VmScope<'a, SE>>>: Unpin, Option<Arc<RwLock<dyn VmDebugger<SE> + Send + Sync>>>: Unpin,

§

impl<'a, SE> UnsafeUnpin for VmScope<'a, SE>

§

impl<'a, SE> UnwindSafe for VmScope<'a, SE>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Finalize for T

Source§

unsafe fn finalize_raw(data: *mut ())

Drops the value stored at data in place. 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> ToOwned for T
where T: Clone,

Source§

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

Source§

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

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.