Skip to content

createVM

function createVM(
registry,
maxStackDepth?,
maxInstructions?,
maxFunctionRecursionDepth?,
maxCollectionSize?,
maxAllocatedElements?,
maxFunctionCalls?,
maxDateOffsetYears?,
minDateOffsetYears?,
context?): VM;

Defined in: packages/engine/src/vm/VM.ts:58

Create a new VM instance with the given opcode registry and configurable limits.

The VM is a stack machine that executes compiled bytecode. It manages:

  • A value stack (bounded by maxStackDepth)
  • A variable store (Map of name → Value)
  • An instruction counter (bounded by maxInstructions)
  • An AbortSignal for async cancellation
ParameterTypeDefault valueDescription
registryOpRegistryundefinedOpcode handler registry for plugin-extensible opcodes
maxStackDepthnumber200Maximum stack slots (default 200)
maxInstructionsnumber50000Maximum opcodes per expression (default 50000)
maxFunctionRecursionDepthnumber50Maximum nested user-defined-function calls (default 50). See the VM interface’s pushCallFrame doc for why this exists as its own dedicated guard, separate from maxInstructions.
maxCollectionSizenumber100000Maximum elements a Range or Matrix may be expanded to by map/reduce (default 100000). Neither of the two counters above can see that expansion, since it happens inside one opcode and never touches the value stack.
maxAllocatedElementsnumber2000000Maximum elements one evaluation may materialise in TOTAL (default 2000000). The parameter above bounds one collection; per-site bounds do not compose, and an operation whose result is the product of two legal operands (a matrix multiply) is bounded by neither. See vm/AllocationBudget.ts.
maxFunctionCallsnumber10000Maximum user-defined-function calls one evaluation may make in total (default 10000). maxFunctionRecursionDepth above bounds how deep they nest and cannot see how many there are: a doubling chain reaches two million calls at a depth of twenty-two.
maxDateOffsetYearsnumber100How far forward <date> + N workdays may reach, in years (default 100). The one date offset that walks rather than computing, so the one that needs a ceiling. See addBusinessDays().
minDateOffsetYearsnumber-100The same bound backwards, negative (default -100).
contextEngineContextdefaultEngineContextRegistries belonging to the engine that created this VM.

VM