pub struct InstructionExecutorImpl<S, H, V>{ /* private fields */ }Expand description
Concrete implementation of the instruction executor
Orchestrates VM execution by coordinating between stack, heap, and variable management systems. Provides the main execution loop that processes bytecode instructions sequentially.
§Type Parameters
S- Stack operations implementationH- Heap operations implementationV- Variable management implementation
§Examples
use jetcrab::vm::executor::instruction_executor::InstructionExecutorImpl;
let executor = InstructionExecutorImpl::new(
my_stack_manager,
my_heap_manager,
my_variable_manager,
);Implementations§
Source§impl<S, H, V> InstructionExecutorImpl<S, H, V>
impl<S, H, V> InstructionExecutorImpl<S, H, V>
Sourcepub fn new(stack_manager: S, heap_manager: H, variable_manager: V) -> Self
pub fn new(stack_manager: S, heap_manager: H, variable_manager: V) -> Self
Creates a new instruction executor with the provided managers
Initializes the executor with concrete implementations for stack, heap, and variable management, along with default instances of frame, registers, builtins, and context cache.
§Arguments
stack_manager- Implementation for stack operationsheap_manager- Implementation for heap operationsvariable_manager- Implementation for variable management
§Returns
A new instruction executor ready for bytecode execution
§Examples
let executor = InstructionExecutorImpl::new(
StackManager::new(),
HeapManager::new(),
VariableManagerImpl::new(),
);Sourcepub fn stack_manager(&self) -> &S
pub fn stack_manager(&self) -> &S
Gets a reference to the stack manager
Provides read-only access to the stack manager for inspection of stack state without modification.
Sourcepub fn stack_manager_mut(&mut self) -> &mut S
pub fn stack_manager_mut(&mut self) -> &mut S
Gets a mutable reference to the stack manager
Provides write access to the stack manager for stack operations like push, pop, and other manipulations.
Sourcepub fn heap_manager(&self) -> &H
pub fn heap_manager(&self) -> &H
Gets a reference to the heap manager
Provides read-only access to the heap manager for inspection of heap state and object access.
Sourcepub fn heap_manager_mut(&mut self) -> &mut H
pub fn heap_manager_mut(&mut self) -> &mut H
Gets a mutable reference to the heap manager
Provides write access to the heap manager for object allocation, deallocation, and garbage collection operations.
Sourcepub fn variable_manager(&self) -> &V
pub fn variable_manager(&self) -> &V
Gets a reference to the variable manager
Provides read-only access to the variable manager for variable lookups and scope inspection.
Sourcepub fn variable_manager_mut(&mut self) -> &mut V
pub fn variable_manager_mut(&mut self) -> &mut V
Gets a mutable reference to the variable manager
Provides write access to the variable manager for variable assignment, scope management, and variable operations.
Trait Implementations§
Source§impl<S, H, V> InstructionExecutor for InstructionExecutorImpl<S, H, V>
impl<S, H, V> InstructionExecutor for InstructionExecutorImpl<S, H, V>
Source§fn execute(
&mut self,
bytecode: &Bytecode,
constants: &[Value],
) -> Result<(), ExecutionError>
fn execute( &mut self, bytecode: &Bytecode, constants: &[Value], ) -> Result<(), ExecutionError>
Executes bytecode instructions sequentially
Processes bytecode instructions one by one, maintaining VM state through the managed components. Handles control flow changes, stack operations, heap management, and variable operations.
§Arguments
bytecode- The bytecode containing instructions to executeconstants- Array of constant values referenced by instructions
§Returns
Ok(())- Execution completed successfullyErr(ExecutionError)- Execution failed with specific error
§Examples
let bytecode = Bytecode::new();
let constants = vec![Value::Number(42.0)];
match executor.execute(&bytecode, &constants) {
Ok(()) => println!("Execution completed"),
Err(e) => eprintln!("Error: {:?}", e),
}