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
impl InstructionDispatcher
Sourcepub 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>
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 executestack- The VM stack for value operationsheap- The VM heap for object allocationvariable_manager- Manages local and global variablesframe- Current execution frameregisters- VM registers including instruction pointerbuiltins- Built-in function implementations
§Returns
Ok(None)- Instruction executed normally, continue to nextOk(Some(ip))- Instruction executed with jump, use new IPErr(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§
impl Freeze for InstructionDispatcher
impl RefUnwindSafe for InstructionDispatcher
impl Send for InstructionDispatcher
impl Sync for InstructionDispatcher
impl Unpin for InstructionDispatcher
impl UnwindSafe for InstructionDispatcher
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more