Module instruction_executor

Source
Expand description

§Instruction Executor Implementation

Provides concrete implementation of the instruction executor that orchestrates VM execution by managing stack, heap, and variable operations. This is the main execution engine that processes bytecode instructions.

§Architecture

The executor uses a generic design that accepts different implementations for stack, heap, and variable management through traits. This allows for flexible testing and different execution strategies.

§Components

  • Stack Manager: Handles all stack operations (push, pop, etc.)
  • Heap Manager: Manages object allocation and garbage collection
  • Variable Manager: Handles local and global variable storage
  • Frame: Current execution frame with constants and metadata
  • Registers: VM registers including instruction pointer
  • Builtins: Built-in function implementations
  • Context Cache: Execution context for performance optimization

§Execution Model

The executor processes bytecode instructions sequentially, maintaining program state through its managed components. Each instruction may:

  • Modify the stack (push/pop values)
  • Allocate or access heap objects
  • Read/write variables
  • Control execution flow (jumps, calls, returns)

§Usage

use jetcrab::vm::executor::instruction_executor::InstructionExecutorImpl;
use jetcrab::vm::bytecode::Bytecode;
use jetcrab::vm::value::Value;

let mut executor = InstructionExecutorImpl::new(
    stack_manager,
    heap_manager,
    variable_manager,
);

let bytecode = Bytecode::new();
let constants = vec![Value::Number(42.0)];

match executor.execute(&bytecode, &constants) {
    Ok(()) => println!("Execution completed"),
    Err(e) => eprintln!("Execution failed: {:?}", e),
}

Structs§

InstructionExecutorImpl
Concrete implementation of the instruction executor