Skip to main content

Module vm

Module vm 

Source
Expand description

High-performance bytecode VM for v2 Jetro expressions.

§Architecture

 String expression
       │  parser::parse()
       ▼
    Expr (AST)
       │  Compiler::compile()
       ▼
    Program              ← flat Arc<[Opcode]>  (cached: compile_cache)
       │  VM::execute()
       ▼
     Val                 ← result              (structural: resolution_cache)

§Optimisations over the tree-walker

  1. Compile cache — parse + compile once per unique expression string.
  2. Val typeArc-wrapped compound nodes; every clone is O(1).
  3. BuiltinMethod enum — O(1) method dispatch (jump-table vs string hash).
  4. Pre-compiled sub-programs — lambda/arg bodies compiled to Arc<Program> once at compile time; never re-compiled per call.
  5. Resolution cache — structural programs ($.a.b[0]) cache their pointer path after the first traversal; subsequent calls skip traversal.
  6. Peephole pass 1 — RootChainPushRoot + GetField+ fused into a single pointer-resolve opcode.
  7. Peephole pass 2 — FilterCountCallMethod(filter) + CallMethod(len/count) fused; counts matches without materialising the intermediate filtered array.
  8. Peephole pass 3 — ConstFold — arithmetic on adjacent integer literals folded at compile time.
  9. Stack machine — iterative exec() loop; no per-opcode stack-frame overhead for simple navigation / arithmetic opcodes.

Structs§

BindObjSpec
Compiled bind-object destructure spec.
CompSpec
Compiled comprehension spec.
CompiledCall
A compiled method call stored inside Opcode::CallMethod.
Compiler
DictCompSpec
FieldChainData
Per-step inline caches for Opcode::FieldChain. One AtomicU64 slot per key in the chain — same encoding as Program.ics (slot_idx + 1, 0 unset). Lives inside the opcode rather than the top-level side-table because the chain length is known only at compile time of that specific opcode.
PassConfig
High-performance v2 virtual machine.
Program
A compiled, immutable v2 program. Cheap to clone (Arc internals).
VM

Enums§

BuiltinMethod
Pre-resolved method identifier — eliminates string comparison at dispatch.
CompiledFSPart
A compiled f-string interpolation part.
CompiledObjEntry
A compiled object field for Opcode::MakeObj.
KvStep
Single step in a pre-resolved KvPath projection.
Opcode

Functions§

fresh_ics
Build a fresh IC side-table with one zeroed AtomicU64 per opcode. Kept public so other modules that fabricate Program values (schema specialisation, analysis passes) can populate the field.