Skip to main content

Vm

Struct Vm 

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

One command-dispatch table used to execute ACTION opcodes.

Implementations§

Source§

impl Vm

Source

pub fn new() -> Self

Creates an empty VM command table.

Source

pub fn define_command<F>(&mut self, command: u16, handler: F)
where F: Fn(&mut VmScript, u16, u8) -> Result<(), VmError> + 'static,

Registers one command handler by its numeric action id.

Source

pub fn define_simple_command<F>(&mut self, command: u16, handler: F)
where F: Fn(&mut VmScript) -> Result<(), VmError> + 'static,

Registers one zero-metadata command handler.

Source

pub fn define_engine_structure<F>(&mut self, index: u8, factory: F)
where F: Fn(u8) -> VmEngineStructureValue + 'static,

Registers one engine-structure default factory by its numeric type index.

Source

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

Registers one fixed default engine-structure value by its numeric type index.

Source

pub fn define_engine_structure_comparer<F>(&mut self, index: u8, comparer: F)

Registers one engine-structure equality hook by its numeric type index.

Source

pub fn define_trace_hook<F>(&mut self, hook: F)
where F: Fn(&VmScript, &VmTraceEvent) + 'static,

Registers one instruction trace hook invoked before each opcode executes.

Source

pub fn clear_trace_hook(&mut self)

Removes the currently registered instruction trace hook.

Source

pub fn run(&self, script: &mut VmScript) -> Result<(), VmError>

Executes one script until it returns from the outermost frame.

§Errors

Returns VmError if execution fails.

Source

pub fn step(&self, script: &mut VmScript) -> Result<VmStepOutcome, VmError>

Executes exactly one instruction.

§Errors

Returns VmError if decoding or execution fails.

Source

pub fn run_until_offset( &self, script: &mut VmScript, offset: usize, options: VmRunOptions, ) -> Result<VmStepOutcome, VmError>

Continues execution until the script is about to execute the instruction at offset.

If the script reaches the requested offset, this returns VmStepOutcome::Running without executing that instruction.

§Errors

Returns VmError if execution fails or exceeds the configured instruction budget.

Source

pub fn step_over( &self, script: &mut VmScript, options: VmRunOptions, ) -> Result<VmStepOutcome, VmError>

Executes the current instruction, stepping over user-function calls.

For non-JSR instructions this behaves like Vm::step. For JSR, it runs until control returns to the caller, preserving a debugger-friendly “step over” behavior.

§Errors

Returns VmError if execution fails or exceeds the configured instruction budget.

Source

pub fn step_out( &self, script: &mut VmScript, options: VmRunOptions, ) -> Result<VmStepOutcome, VmError>

Continues execution until the current function returns to its caller.

If the script is currently at top level, this runs until the script halts or aborts.

§Errors

Returns VmError if execution fails or exceeds the configured instruction budget.

Source

pub fn run_until_line( &self, script: &mut VmScript, file_name: &str, line_number: usize, options: VmRunOptions, ) -> Result<VmStepOutcome, VmError>

Continues execution until the script is about to execute one instruction mapped to file_name:line_number in attached NDB metadata.

If the script reaches the requested line, this returns VmStepOutcome::Running without executing that instruction.

§Errors

Returns VmError if the script has no matching debug mapping, execution fails, or the instruction budget is exceeded.

Source

pub fn run_until_function( &self, script: &mut VmScript, name: &str, options: VmRunOptions, ) -> Result<VmStepOutcome, VmError>

Continues execution until the script is about to execute one instruction inside the named function from attached NDB metadata.

If the script reaches the requested function, this returns VmStepOutcome::Running without executing that instruction.

§Errors

Returns VmError if the script has no matching debug mapping, execution fails, or the instruction budget is exceeded.

Source

pub fn run_with_options( &self, script: &mut VmScript, options: VmRunOptions, ) -> Result<(), VmError>

Executes one script with explicit runtime controls until it returns from the outermost frame.

§Errors

Returns VmError if execution fails or exceeds the configured instruction budget.

Source

pub fn run_situation( &self, situation: &VmSituation, ) -> Result<VmScript, VmError>

Executes one previously captured NWScript action situation.

§Errors

Returns VmError if execution fails.

Source

pub fn run_situation_with_options( &self, situation: &VmSituation, options: VmRunOptions, ) -> Result<VmScript, VmError>

Executes one previously captured NWScript action situation with explicit runtime controls.

§Errors

Returns VmError if execution fails.

Source

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

Decodes one script, runs it, and returns the finished runtime state.

§Errors

Returns VmError if decoding or execution fails.

Source

pub fn run_bytes_with_options( &self, bytes: &[u8], label: impl Into<String>, options: VmRunOptions, ) -> Result<VmScript, VmError>

Decodes one script, runs it with explicit runtime controls, and returns the finished runtime state.

§Errors

Returns VmError if decoding or execution fails.

Source

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

Decodes one script, attaches one NDB table, runs it, and returns the finished runtime state.

This is the recommended path for compiled scripts that contain user-function calls, because the VM uses NDB metadata to recover callee stack shapes.

§Errors

Returns VmError if decoding, metadata attachment, or execution fails.

Source

pub fn run_bytes_with_ndb_and_options( &self, bytes: &[u8], label: impl Into<String>, ndb: &Ndb, options: VmRunOptions, ) -> Result<VmScript, VmError>

Decodes one script, attaches one NDB table, and runs it with explicit runtime controls.

§Errors

Returns VmError if decoding, metadata attachment, or execution fails.

Source

pub fn run_function_bytes( &self, bytes: &[u8], label: impl Into<String>, ndb: &Ndb, name: &str, args: &[VmValue], ) -> Result<VmScript, VmError>

Decodes one script, prepares a named direct function call, and runs it.

This bypasses the compiler-emitted loader and initializes globals automatically for main()-style entry loaders when needed.

§Errors

Returns VmError if decoding fails, the function cannot be invoked directly, or execution fails.

Source

pub fn run_function_bytes_with_options( &self, bytes: &[u8], label: impl Into<String>, ndb: &Ndb, name: &str, args: &[VmValue], options: VmRunOptions, ) -> Result<VmScript, VmError>

Decodes one script, prepares a named direct function call, and runs it with explicit runtime controls.

§Errors

Returns VmError if decoding fails, the function cannot be invoked directly, execution fails, or the instruction budget is exceeded.

Trait Implementations§

Source§

impl Debug for Vm

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for Vm

Source§

fn default() -> Vm

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for Vm

§

impl !RefUnwindSafe for Vm

§

impl !Send for Vm

§

impl !Sync for Vm

§

impl Unpin for Vm

§

impl UnsafeUnpin for Vm

§

impl !UnwindSafe for Vm

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