Skip to main content

Module vm

Module vm 

Source
Expand description

Lua virtual machine — port of src/lvm.c (1899 lines, 32 functions).

This module implements:

  • Number coercion helpers (tonumber_, flttointeger, tointegerns, tointeger)
  • Numeric for-loop preparation and stepping (forlimit, forprep, floatforloop)
  • Table get/set with metamethod chaining (finishget, finishset)
  • String comparison respecting embedded NULs (l_strcmp)
  • Relational operators: lessthan, lessequal, equalobj (with metamethods)
  • String concatenation (concat)
  • Object length operator (objlen)
  • Integer arithmetic: idiv, mod, modf, shiftl
  • Closure creation (pushclosure)
  • Yield-resume bridge (finishOp)
  • Main interpreter loop (execute) — the Lua bytecode dispatch engine.

§Control flow note

The C source uses goto startfunc / goto returning / goto ret across labelled points in luaV_execute. These are modelled with Rust’s labelled loops ('startfunc, 'returning, 'dispatch) and continue/break on those labels. See inline PORT NOTE comments.

Enums§

OpCode
TODO(multiversion, Step 0 deferred): this OpCode is a DUPLICATE of the canonical one in lua-code/src/opcodes.rs:87. The Step-0 plan wanted them consolidated to one owner (lua-code) with lua-vm depending on it, but that creates a DEPENDENCY CYCLE: lua-code/Cargo.toml already depends on lua-vm, so lua-vm cannot depend back on lua-code. Consolidating therefore requires moving the canonical OpCode/OP_MODES/Instruction definitions DOWN into lua-types (which lua-types/src/opcode.rs already reserves) and pointing both lua-vm and lua-code at it — plus reconciling variant-name skew between the two copies (lua-vm uses BXOrK/BXOr, lua-code uses BXorK/BXor; lua-vm also has LoadKx/GetUpval aliases) and the InstructionExt decode trait that lives here. That is a larger refactor than the Step-0 scaffold; deferred to keep 5.4 green. Duplicate sites: lua-vm/src/vm.rs:45 (this enum) vs lua-code/src/opcodes.rs:87 (canonical).

Traits§

InstructionExt
TODO(phase-b): Instruction accessor extension trait. The real per-mode decode helpers live in lua-types::opcode once translated. Stubbed locally so call sites resolve; bodies are inferred from lopcodes.h macro shapes.