Struct InstructionDispatcher

Source
pub struct InstructionDispatcher;
Expand description

Central instruction dispatcher for the VM

Provides a single entry point for executing all VM instructions by routing them to specialized handlers based on instruction type.

Implementations§

Source§

impl InstructionDispatcher

Source

pub fn execute_instruction<S, H, V>( instruction: &Instruction, stack: &mut S, heap: &mut H, variable_manager: &mut V, frame: &mut Frame, registers: &mut Registers, builtins: &mut Builtins, ) -> Result<Option<usize>, ExecutionError>

Executes a single VM instruction

Routes the instruction to the appropriate handler based on its type. Some instructions may modify the instruction pointer, in which case the new pointer is returned.

§Arguments
  • instruction - The instruction to execute
  • stack - The VM stack for value operations
  • heap - The VM heap for object allocation
  • variable_manager - Manages local and global variables
  • frame - Current execution frame
  • registers - VM registers including instruction pointer
  • builtins - Built-in function implementations
§Returns
  • Ok(None) - Instruction executed normally, continue to next
  • Ok(Some(ip)) - Instruction executed with jump, use new IP
  • Err(ExecutionError) - Execution failed
§Examples
use jetcrab::vm::executor::instruction_dispatcher::InstructionDispatcher;
use jetcrab::vm::instructions::Instruction;

match InstructionDispatcher::execute_instruction(
    &Instruction::Add,
    &mut stack,
    &mut heap,
    &mut variables,
    &mut frame,
    &mut registers,
    &mut builtins,
) {
    Ok(None) => println!("Continue to next instruction"),
    Ok(Some(ip)) => println!("Jump to instruction {}", ip),
    Err(e) => eprintln!("Execution error: {:?}", e),
}

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