Skip to main content

Module vm

Module vm 

Source
Expand description

The fusevm execution engine — stack-based bytecode dispatch loop.

This is the hot path. Every cycle counts. The dispatch loop uses a flat match on Op variants — Rust compiles this to a jump table.

Frontends register extension handlers via ExtensionHandler for language-specific opcodes (Op::Extended, Op::ExtendedWide).

§Optimizations

  • Type-specialized integer fast paths: Add, Sub, Mul, Mod, comparisons check for Int×Int first and skip to_float() coercion entirely.
  • Zero-clone dispatch: ops are borrowed from the chunk, not cloned per cycle. LoadConst copies scalars (Int/Float/Bool) without touching Arc refcounts.
  • In-place container mutation: array/hash ops (Push, Pop, Shift, Set, HashSet, HashDelete) mutate globals directly — no clone-modify-writeback.
  • Cow<str> string coercion: as_str_cow() borrows Str variants without allocation. Used in string comparisons, Concat, Print, hash key lookup.
  • Inline builtin cache: CallBuiltin dispatches through a pre-registered function pointer table — no name lookup at runtime.
  • Fused superinstructions: hot loop patterns run as single ops (AccumSumLoop, SlotIncLtIntJumpBack, etc.)
  • Pre-allocated collections: Range, MakeHash, HashKeys/Values use exact or estimated capacity. ConcatConstLoop pre-sizes the string buffer.

Structs§

Frame
Call frame on the frame stack.
VM
The virtual machine.
VMPool
Pool of reusable VM instances.

Enums§

VMResult
Result of VM execution

Type Aliases§

BuiltinHandler
Builtin function handler: (vm, argc) → Value
ExtensionHandler
Extension handler for language-specific opcodes. Frontends register this at VM init.
ExtensionWideHandler
Wide extension handler (usize payload).