From 29056ce0ad48d58e260d57b4af095b8320e878cd Mon Sep 17 00:00:00 2001 From: bQUARKz Date: Wed, 18 Feb 2026 12:57:12 +0000 Subject: [PATCH] pr1.2 --- crates/console/prometeu-bytecode/src/abi.rs | 18 +++++----- crates/console/prometeu-bytecode/src/lib.rs | 5 ++- .../prometeu-vm/src/virtual_machine.rs | 10 +++--- docs/bytecode/RESET_LEGACY_MAP.md | 17 +++++----- docs/specs/pbs/Prometeu Runtime Traps.md | 14 ++++---- files/TODOs.md | 34 ------------------- 6 files changed, 31 insertions(+), 67 deletions(-) diff --git a/crates/console/prometeu-bytecode/src/abi.rs b/crates/console/prometeu-bytecode/src/abi.rs index 942dbe9b..9349f5a6 100644 --- a/crates/console/prometeu-bytecode/src/abi.rs +++ b/crates/console/prometeu-bytecode/src/abi.rs @@ -1,19 +1,17 @@ //! 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. -// --- HIP Trap Codes --- +// --- Runtime Trap Codes (post-HIP reset) --- -/// Attempted to access a gate that does not exist or has been recycled incorrectly. -pub const TRAP_INVALID_GATE: u32 = 0x01; -/// Attempted to access a gate that has been explicitly released (RC=0). -pub const TRAP_DEAD_GATE: u32 = 0x02; -/// Attempted to access a field or index beyond the allocated slots for a gate. -pub const TRAP_OOB: u32 = 0x03; -/// Attempted a typed operation on a gate whose storage type does not match. -pub const TRAP_TYPE: u32 = 0x04; +/// Attempted to execute an unknown or invalid opcode. +pub const TRAP_ILLEGAL_INSTRUCTION: u32 = 0x0000_0001; +/// 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 arguments on the stack for the requested syscall. +/// 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; diff --git a/crates/console/prometeu-bytecode/src/lib.rs b/crates/console/prometeu-bytecode/src/lib.rs index ba82e094..73ad3a16 100644 --- a/crates/console/prometeu-bytecode/src/lib.rs +++ b/crates/console/prometeu-bytecode/src/lib.rs @@ -8,9 +8,8 @@ mod program_image; mod value; pub use abi::{ - TrapInfo, TRAP_BAD_RET_SLOTS, TRAP_DEAD_GATE, TRAP_DIV_ZERO, TRAP_INVALID_FUNC, - TRAP_INVALID_GATE, TRAP_INVALID_LOCAL, TRAP_INVALID_SYSCALL, TRAP_OOB, TRAP_STACK_UNDERFLOW, - TRAP_TYPE, + TrapInfo, TRAP_BAD_RET_SLOTS, TRAP_DIV_ZERO, TRAP_ILLEGAL_INSTRUCTION, TRAP_INVALID_FUNC, + TRAP_INVALID_LOCAL, TRAP_INVALID_SYSCALL, TRAP_OOB, TRAP_STACK_UNDERFLOW, TRAP_TYPE, }; pub use decoder::{decode_next, DecodeError}; pub use layout::{compute_function_layouts, FunctionLayout}; diff --git a/crates/console/prometeu-vm/src/virtual_machine.rs b/crates/console/prometeu-vm/src/virtual_machine.rs index e6d0e419..2b94744e 100644 --- a/crates/console/prometeu-vm/src/virtual_machine.rs +++ b/crates/console/prometeu-vm/src/virtual_machine.rs @@ -7,8 +7,8 @@ use prometeu_bytecode::OpCode; use prometeu_bytecode::ProgramImage; use prometeu_bytecode::Value; use prometeu_bytecode::{ - TRAP_BAD_RET_SLOTS, TRAP_DEAD_GATE, TRAP_DIV_ZERO, TRAP_INVALID_FUNC, TRAP_INVALID_GATE, - TRAP_INVALID_SYSCALL, TRAP_OOB, TRAP_STACK_UNDERFLOW, TRAP_TYPE, TrapInfo, + TRAP_BAD_RET_SLOTS, TRAP_DIV_ZERO, TRAP_INVALID_FUNC, TRAP_INVALID_SYSCALL, TRAP_OOB, + TRAP_STACK_UNDERFLOW, TRAP_TYPE, TrapInfo, }; use prometeu_hal::vm_fault::VmFault; @@ -1156,11 +1156,11 @@ impl VirtualMachine { ) -> Result<&GateEntry, LogicalFrameEndingReason> { let idx = gate_id as usize; let entry = self.gate_pool.get(idx).ok_or_else(|| { - self.trap(TRAP_INVALID_GATE, opcode, format!("Invalid gate id: {}", gate_id), pc) + self.trap(TRAP_OOB, opcode, format!("Invalid gate id: {}", gate_id), pc) })?; if !entry.alive { return Err(self.trap( - TRAP_DEAD_GATE, + TRAP_OOB, opcode, format!("Dead gate id: {}", gate_id), pc, @@ -2034,7 +2034,7 @@ mod tests { let report = vm.run_budget(100, &mut native, &mut ctx).unwrap(); match report.reason { LogicalFrameEndingReason::Trap(trap) => { - assert_eq!(trap.code, TRAP_INVALID_GATE); + assert_eq!(trap.code, TRAP_OOB); assert_eq!(trap.opcode, OpCode::GateLoad as u16); } _ => panic!("Expected Trap, got {:?}", report.reason), diff --git a/docs/bytecode/RESET_LEGACY_MAP.md b/docs/bytecode/RESET_LEGACY_MAP.md index e14eedc3..3ce52b0f 100644 --- a/docs/bytecode/RESET_LEGACY_MAP.md +++ b/docs/bytecode/RESET_LEGACY_MAP.md @@ -25,10 +25,10 @@ grep -RIn --exclude-dir target \ # Scope-related (inventory only; not necessarily to delete) grep -RIn --exclude-dir target -e 'PushScope' -e 'PopScope' crates/console -# Trap codes with HIP/RC semantics +# Trap codes inventory (post-reset, check for any lingering gate-specific traps) grep -RIn --exclude-dir target \ - -e 'TRAP_INVALID_GATE' -e 'TRAP_DEAD_GATE' -e 'TRAP_TYPE' \ - crates/console/prometeu-bytecode crates/console/prometeu-vm + -e '\bTRAP_\w\+' \ + crates/console/prometeu-bytecode crates/console/prometeu-vm | grep -Ei 'gate|heap|hip' -n || true # Value::Gate usages grep -RIn --exclude-dir target -e 'Value::Gate' crates/console @@ -88,11 +88,9 @@ Remove — OpCode variants (definitions and all references) 2) Trap codes (RC/HIP) -Remove — HIP-specific traps (delete constants and all usages) +Remove — gate-specific traps (delete constants and all usages) - crates/console/prometeu-bytecode/src/abi.rs - - TRAP_INVALID_GATE (0x01) - - TRAP_DEAD_GATE (0x02) - - TRAP_TYPE (0x04) — typed storage/gate mismatch (legacy) + - Remove identifiers tied to HIP/gate semantics Keep — still meaningful under GC model (names may be revised later, but remain functionally) - crates/console/prometeu-bytecode/src/abi.rs @@ -103,10 +101,11 @@ Keep — still meaningful under GC model (names may be revised later, but remain - TRAP_DIV_ZERO (0x0000_000A) - TRAP_INVALID_FUNC (0x0000_000B) - TRAP_BAD_RET_SLOTS (0x0000_000C) + - TRAP_TYPE — retained; semantics generalized to non-HIP type mismatches Usages to edit alongside removal - crates/console/prometeu-vm/src/virtual_machine.rs - - Imports: TRAP_INVALID_GATE, TRAP_DEAD_GATE, TRAP_TYPE + - Imports: remove any gate-specific trap imports - resolve_gate() and gate handlers construct TrapInfo with those codes - Tests asserting these trap codes @@ -144,7 +143,7 @@ Will be removed outright (symbols or blocks) - prometeu-bytecode - opcode.rs: all Gate* variants and Alloc variant; TryFrom/encoding IDs and cycles for those - opcode_spec.rs: corresponding spec arms (GATE_*, ALLOC) - - abi.rs: TRAP_INVALID_GATE, TRAP_DEAD_GATE, TRAP_TYPE constants + - abi.rs: gate-specific trap constants - prometeu-vm - virtual_machine.rs: handlers for Alloc and all Gate* opcodes; GateEntry/GateId data structures; resolve_gate(); HIP-focused unit tests listed above diff --git a/docs/specs/pbs/Prometeu Runtime Traps.md b/docs/specs/pbs/Prometeu Runtime Traps.md index f3000ae1..5db0c2b5 100644 --- a/docs/specs/pbs/Prometeu Runtime Traps.md +++ b/docs/specs/pbs/Prometeu Runtime Traps.md @@ -81,13 +81,15 @@ TrapInfo { | `TRAP_OOB` | Out of bounds | Access beyond allowed bounds | | `TRAP_INVALID_LOCAL` | Invalid local | Local slot index out of bounds | -### 5.2 Heap / Gate +### 5.2 Execution & Types -| Code | Name | Meaning | -| ------------------- | -------------- | -------------------------- | -| `TRAP_INVALID_GATE` | Invalid gate | Non-existent gate handle | -| `TRAP_DEAD_GATE` | Dead gate | Gate with refcount = 0 | -| `TRAP_TYPE` | Type violation | Heap or gate type mismatch | +| Code | Name | Meaning | +| ------------------------- | -------------------- | ------------------------------------------------------ | +| `TRAP_ILLEGAL_INSTRUCTION`| Illegal instruction | Unknown/invalid opcode encountered | +| `TRAP_TYPE` | Type violation | Type mismatch for operation or syscall argument types | +| `TRAP_DIV_ZERO` | Divide by zero | Division/modulo by zero | +| `TRAP_INVALID_FUNC` | Invalid function | Function index not present in function table | +| `TRAP_BAD_RET_SLOTS` | Bad return slots | Stack height mismatch at return | ### 5.3 System diff --git a/files/TODOs.md b/files/TODOs.md index fa83c4e9..72676374 100644 --- a/files/TODOs.md +++ b/files/TODOs.md @@ -1,37 +1,3 @@ -# PR-1.2 — Remove HIP/RC Trap Codes From ABI - -### Briefing - -The new architecture removes HIP/RC completely. Any ABI surface describing HIP traps or gate-related traps must be deleted. - -### Target - -* Delete HIP/RC trap codes from bytecode ABI. -* Replace with a minimal, architecture-aligned trap/error taxonomy. - -### Work items - -* Remove HIP trap constants/enums (e.g., anything like `TRAP_INVALID_GATE`, `TRAP_DEAD_GATE`, and related HIP trap identifiers). -* If there is a shared trap enum used by VM/tooling: - - * Keep only traps that remain meaningful in the GC stack+heap model (e.g., OOB, illegal instruction, stack underflow), as specified. - * Rename/restructure as needed to reflect the reset. -* Update any match arms / formatting / disasm text that referenced HIP traps. -* Update tests and fixtures accordingly. - -### Acceptance checklist - -* [ ] No HIP/gate trap identifiers remain in the codebase. -* [ ] Bytecode crates compile. -* [ ] Disassembler / printers compile and produce readable output for remaining traps. -* [ ] `cargo test` passes. - -### Tests - -* Update/adjust any trap-related unit tests. - ---- - # PR-1.3 — Remove RC/HIP Opcodes From `opcode` and Decode/Encode Paths ### Briefing