jetcrab\vm\executor\instruction_handlers/mod.rs
1//! # Instruction Handlers Module
2//!
3//! This module contains specialized handlers for different types of VM instructions.
4//! Each handler is responsible for executing a specific category of operations.
5//!
6//! ## Handlers
7//!
8//! - **ArithmeticHandler**: Mathematical operations (add, subtract, multiply, etc.)
9//! - **ComparisonHandler**: Comparison and logical operations
10//! - **ControlFlowHandler**: Control flow operations (jumps, calls, returns)
11//! - **StackOpsHandler**: Stack manipulation operations
12//! - **HeapOpsHandler**: Memory allocation and management
13//! - **BuiltinCallsHandler**: Built-in function calls
14//!
15//! ## Design Principles
16//!
17//! Each handler follows these principles:
18//!
19//! - **Single Responsibility**: Each handler handles one category of operations
20//! - **Generic Implementation**: Uses trait bounds for flexibility
21//! - **Error Handling**: Comprehensive error handling with `ExecutionError`
22//! - **Performance**: Optimized for common operations
23//!
24//! ## Usage Example
25//!
26//! ```rust
27//! use jetcrab::vm::executor::instruction_handlers::ArithmeticHandler;
28//! use jetcrab::vm::executor::traits::StackOperations;
29//!
30//! let mut stack = MyStack::new();
31//! ArithmeticHandler::add(&mut stack)?;
32//! ```
33
34pub mod arithmetic;
35pub mod builtin_calls;
36pub mod comparison;
37pub mod control_flow;
38pub mod heap_ops;
39pub mod stack_ops;
40
41pub use arithmetic::ArithmeticHandler;
42pub use builtin_calls::BuiltinCallsHandler;
43pub use comparison::ComparisonHandler;
44pub use control_flow::ControlFlowHandler;
45pub use heap_ops::HeapOpsHandler;
46pub use stack_ops::StackOpsHandler;
47
48/// Unified instruction handler that provides access to all instruction handlers
49pub struct InstructionHandlers;
50
51impl InstructionHandlers {
52 /// Get a reference to the arithmetic handler
53 pub fn arithmetic() -> &'static ArithmeticHandler {
54 &ArithmeticHandler
55 }
56
57 /// Get a reference to the comparison handler
58 pub fn comparison() -> &'static ComparisonHandler {
59 &ComparisonHandler
60 }
61
62 /// Get a reference to the control flow handler
63 pub fn control_flow() -> &'static ControlFlowHandler {
64 &ControlFlowHandler
65 }
66
67 /// Get a reference to the stack operations handler
68 pub fn stack_ops() -> &'static StackOpsHandler {
69 &StackOpsHandler
70 }
71
72 /// Get a reference to the heap operations handler
73 pub fn heap_ops() -> &'static HeapOpsHandler {
74 &HeapOpsHandler
75 }
76
77 /// Get a reference to the builtin calls handler
78 pub fn builtin_calls() -> &'static BuiltinCallsHandler {
79 &BuiltinCallsHandler
80 }
81}