Skip to main content

VmScript

Struct VmScript 

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

One executable NCS script plus its VM runtime state.

Implementations§

Source§

impl VmScript

Source

pub fn from_bytes( bytes: &[u8], label: impl Into<String>, ) -> Result<Self, VmError>

Decodes one NCS V1.0 bytecode stream into a runnable script.

§Errors

Returns VmError if the bytecode is malformed.

Source

pub fn from_instructions( instructions: Vec<NcsInstruction>, label: impl Into<String>, ) -> Self

Builds a runnable script from decoded instructions.

Source

pub fn attach_ndb(&mut self, ndb: &Ndb) -> Result<(), VmError>

Attaches one NDB debug table so the VM can recover user-function frame shapes.

§Errors

Returns VmError if one function record uses unsupported stack metadata.

Source

pub fn from_bytes_with_ndb( bytes: &[u8], label: impl Into<String>, ndb: &Ndb, ) -> Result<Self, VmError>

Decodes one NCS V1.0 bytecode stream and attaches one NDB debug table.

§Errors

Returns VmError if the bytecode or attached debug metadata is malformed.

Source

pub fn run(&mut self, vm: &Vm) -> Result<(), VmError>

Executes this script using the supplied VM command table.

§Errors

Returns VmError if execution fails.

Source

pub fn label(&self) -> &str

Returns the user-facing label associated with this script.

Source

pub fn ip(&self) -> usize

Returns the current instruction pointer in code-section bytes.

Source

pub fn sp(&self) -> usize

Returns the current stack pointer in stack cells.

Source

pub fn bp(&self) -> usize

Returns the current base pointer in stack cells.

Source

pub fn current_instruction(&self) -> Option<&NcsInstruction>

Returns the decoded instruction at the current instruction pointer.

Source

pub fn instruction_at(&self, offset: usize) -> Option<&NcsInstruction>

Returns the decoded instruction at one byte offset, if present.

Source

pub fn current_function(&self) -> Option<VmFunctionInfo>

Returns the attached debug function that contains the current instruction pointer.

Source

pub fn function_at(&self, offset: usize) -> Option<VmFunctionInfo>

Returns the attached debug function that contains one byte offset.

Source

pub fn current_source_location(&self) -> Option<VmSourceLocation>

Returns the attached source location for the current instruction pointer.

Source

pub fn source_location_at(&self, offset: usize) -> Option<VmSourceLocation>

Returns the attached source location for one byte offset.

Source

pub fn save_ip(&self) -> usize

Returns the instruction pointer saved by STOREIP or STORESTATE.

Source

pub fn save_sp(&self) -> usize

Returns the stack pointer saved by STORESTATE.

Source

pub fn save_bp(&self) -> usize

Returns the base pointer saved by STORESTATE.

Source

pub fn stack(&self) -> &[VmValue]

Returns the current stack values.

Source

pub fn stack_string(&self) -> String

Returns a compact debugger-oriented stack rendering with ^ at the base pointer and * at the top stack cell.

Source

pub fn return_depth(&self) -> usize

Returns the current return-frame depth.

Source

pub fn saved_situation(&self) -> Option<&VmSituation>

Returns the last deferred action snapshot captured by STORESTATE.

Source

pub fn take_saved_situation(&mut self) -> Option<VmSituation>

Removes and returns the last deferred action snapshot captured by STORESTATE.

Source

pub fn prepare_function_call( &mut self, ndb: &Ndb, name: &str, args: &[VmValue], ) -> Result<(), VmError>

Configures this script to call one named user function directly.

This bypasses the compiler-emitted loader.

If the script uses globals, the caller must initialize the loader/global frame first before invoking a named function directly.

§Errors

Returns VmError if the function cannot be found or the argument types are unsupported.

Source

pub fn function_return_value( &self, ndb: &Ndb, name: &str, ) -> Result<Option<VmValue>, VmError>

Reads one scalar/object/string/engine-structure return value after a direct function call.

§Errors

Returns VmError if the function cannot be found or uses an unsupported return type.

Source

pub fn abort(&mut self)

Requests that this script abort once control returns to the VM dispatcher.

Source

pub fn aborted(&self) -> bool

Returns whether the last VM run terminated via abort().

Source

pub fn push(&mut self, value: VmValue)

Pushes one raw stack value.

Source

pub fn push_int(&mut self, value: i32)

Pushes one integer value.

Source

pub fn push_float(&mut self, value: f32)

Pushes one floating-point value.

Source

pub fn push_string(&mut self, value: impl Into<String>)

Pushes one string value.

Source

pub fn push_object(&mut self, value: VmObjectId)

Pushes one object id.

Source

pub fn push_engine_structure( &mut self, index: u8, value: VmEngineStructureValue, )

Pushes one engine-structure value.

Source

pub fn push_vector(&mut self, value: [f32; 3])

Pushes one vector value as three stack cells in x, y, z order.

Source

pub fn pop(&mut self) -> Result<VmValue, VmError>

Pops one raw stack value.

§Errors

Returns VmError if the stack is empty.

Source

pub fn pop_int(&mut self) -> Result<i32, VmError>

Pops one integer value.

§Errors

Returns VmError if the stack top is not an integer.

Source

pub fn pop_float(&mut self) -> Result<f32, VmError>

Pops one floating-point value.

§Errors

Returns VmError if the stack top is not a float.

Source

pub fn pop_string(&mut self) -> Result<String, VmError>

Pops one string value.

§Errors

Returns VmError if the stack top is not a string.

Source

pub fn pop_object(&mut self) -> Result<VmObjectId, VmError>

Pops one object id.

§Errors

Returns VmError if the stack top is not an object.

Source

pub fn pop_engine_structure( &mut self, ) -> Result<(u8, VmEngineStructureValue), VmError>

Pops one engine-structure value.

§Errors

Returns VmError if the stack top is not an engine structure.

Source

pub fn pop_engine_structure_index( &mut self, expected_index: u8, ) -> Result<VmEngineStructureValue, VmError>

Pops one engine-structure value and checks its engine-structure index.

§Errors

Returns VmError if the stack top is not the requested engine structure.

Source

pub fn pop_vector(&mut self) -> Result<[f32; 3], VmError>

Pops one vector value from three float stack cells.

§Errors

Returns VmError if the top three cells are not floats.

Trait Implementations§

Source§

impl Clone for VmScript

Source§

fn clone(&self) -> VmScript

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for VmScript

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. 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> 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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more