Module traits

Source
Expand description

§VM Execution Traits

Defines the core traits that provide the interface for VM execution components. These traits define the contract that implementations must fulfill for stack operations, heap management, variable management, and instruction execution.

§Core Traits

  • StackOperations: Defines stack manipulation operations
  • HeapOperations: Defines heap memory management operations
  • VariableManager: Defines variable storage and retrieval operations
  • InstructionExecutor: Defines the main execution interface

§Design Principles

The traits follow these design principles:

  • Generic Implementation: Use trait bounds for flexibility
  • Clear Contracts: Each trait has a well-defined responsibility
  • Error Handling: All operations return Result types
  • Performance: Optimized for common operations

§Usage

use jetcrab::vm::executor::traits::{StackOperations, HeapOperations, VariableManager};

struct MyVM<S, H, V>
where
    S: StackOperations,
    H: HeapOperations,
    V: VariableManager,
{
    stack: S,
    heap: H,
    variables: V,
}

Traits§

HeapOperations
Defines operations for managing the VM’s heap memory
InstructionExecutor
Defines the main interface for VM instruction execution
StackOperations
Defines operations for manipulating the VM’s operand stack
VariableManager
Defines operations for managing VM variables