Skip to main content

Module interp

Module interp 

Source
Expand description

Byte-PVM interpreter.

Predecodes a PvmProgram via crate::decode::predecode and dispatches over the resulting DecodedInst array.

Cherry-picked from v2 javm/src/interpreter/mod.rs::run (~787 LOC). The opcode-dispatch arms are verbatim modulo two adaptations:

  1. State as parameters. v2’s Interpreter owns gas/regs/mem/ code/etc. v3’s Interpreter::run is a free function that takes &PvmProgram + &mut Regs + &mut Mem + &mut GasCounter + &mut dyn EcallHandler. The predecoded state is computed on entry (matching v2’s Interpreter::new flow, but inline rather than stored).

  2. Ecall routing. v2 returns ExitReason::Ecall / HostCall directly to the kernel. v3 routes both through the EcallHandler trait: on Continue the loop resumes at inst.next_idx; on Exit(reason) the run returns. The diagnostic regs.gpr[7] “unsupported opcode” recording from the MVP is dropped (full coverage means it can’t fire).

Preserved optimizations (vs v2):

  • Predecoded DecodedInst flat layout (40 bytes; no Args enum matching in the hot loop).
  • pc_to_idx hot-loop indexing for dynamic jumps.
  • Gas-block charging via inst.bb_gas_cost (JAR v0.8.0).
  • do_load! / do_store! macros (zero overhead).
  • Fast-path mem.read_* / write_* helpers (single MOV on x86).

Structs§

Interpreter
Namespace for byte-PVM execution.