//! This module defines the Application Binary Interface (ABI) of the Prometeu Virtual Machine. //! It specifies how instructions are encoded in bytes and how they interact with memory. /// Attempted to execute an unknown or invalid opcode. pub const TRAP_ILLEGAL_INSTRUCTION: u32 = 0x0000_0001; /// Program explicitly requested termination via the TRAP opcode. pub const TRAP_EXPLICIT: u32 = 0x0000_0002; /// Out-of-bounds access (e.g., stack/heap/local index out of range). pub const TRAP_OOB: u32 = 0x0000_0003; /// Type mismatch for the attempted operation (e.g., wrong operand type or syscall argument type). pub const TRAP_TYPE: u32 = 0x0000_0004; /// The syscall ID provided is not recognized by the system. pub const TRAP_INVALID_SYSCALL: u32 = 0x0000_0007; /// Not enough values on the operand stack for the requested operation/syscall. pub const TRAP_STACK_UNDERFLOW: u32 = 0x0000_0008; /// Attempted to access a local slot that is out of bounds for the current frame. pub const TRAP_INVALID_LOCAL: u32 = 0x0000_0009; /// Division or modulo by zero. pub const TRAP_DIV_ZERO: u32 = 0x0000_000A; /// Attempted to call a function that does not exist in the function table. pub const TRAP_INVALID_FUNC: u32 = 0x0000_000B; /// Executed RET with an incorrect stack height (mismatch with function metadata). pub const TRAP_BAD_RET_SLOTS: u32 = 0x0000_000C; /// The intrinsic ID provided is not recognized by the runtime, or its metadata is invalid. pub const TRAP_INVALID_INTRINSIC: u32 = 0x0000_000D; use serde::{Deserialize, Serialize}; /// Detailed information about a source code span. #[derive(Debug, Clone, PartialEq, Eq, Default, Serialize, Deserialize)] pub struct SourceSpan { pub file_id: u32, pub start: u32, pub end: u32, } /// Detailed information about a runtime trap. #[derive(Debug, Clone, PartialEq, Eq)] pub struct TrapInfo { /// The specific trap code (e.g., TRAP_OOB). pub code: u32, /// The numeric value of the opcode that triggered the trap. pub opcode: u16, /// A human-readable message explaining the trap. pub message: String, /// The absolute Program Counter (PC) address where the trap occurred. pub pc: u32, /// Optional source span information if debug symbols are available. pub span: Option, }