SilverSight/formal/SilverSight/AVMIsa/Instr.lean
allaun cb50581eef feat(avm): implement static type-checking and math primitives in AVMIsa
Added Q16_16 multiplication, division, and comparison operators to Prim
and Step semantics. Implemented static type checking (checkInstr,
checkProgram) in TypeCheck.lean and proved the step_preservation safety
theorem in TypeSafety.lean. Verified with new arithmetic execution
canaries in Run.lean.

Build: 3307 jobs, 0 errors (lake build)
2026-06-27 23:48:17 -05:00

46 lines
1 KiB
Text

-- AVM ISA v1 (Lean-only): Instructions
-- Closed-world opcodes. No CALL/IMPORT. No string dispatch.
import SilverSight.AVMIsa.Value
namespace SilverSight.AVMIsa
/-- Finite primitive set (closed-world).
If extensibility is needed, add a constructor here and define its semantics in Lean.
Backends must implement the same semantics.
-/
inductive Prim : Type where
| addSatQ0
| subSatQ0
| addSatQ16
| subSatQ16
| mulSatQ16
| divSatQ16
| ltQ16
| eqQ16
| and
| or
| not
deriving DecidableEq, BEq, Inhabited, Repr
/-- Core instruction set.
`load`/`store` use `Nat` indices in this v1 skeleton.
Strict implementations SHOULD replace them with `Fin n` once the local-frame
size is part of `Program`.
-/
inductive Instr : Type where
| push : AnyVal → Instr
| pop : Instr
| dup : Instr
| swap : Instr
| load : Nat → Instr
| store : Nat → Instr
| jump : Nat → Instr
| jumpIf : Nat → Instr
| prim : Prim → Instr
| halt : Instr
deriving Inhabited, Repr
end SilverSight.AVMIsa