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
Parameters
Section titled “Parameters”| Parameter | Type | Default value | Description |
|---|---|---|---|
registry | OpRegistry | undefined | Opcode handler registry for plugin-extensible opcodes |
maxStackDepth | number | 200 | Maximum stack slots (default 200) |
maxInstructions | number | 50000 | Maximum opcodes per expression (default 50000) |
maxFunctionRecursionDepth | number | 50 | Maximum 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. |
maxCollectionSize | number | 100000 | Maximum 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. |
maxAllocatedElements | number | 2000000 | Maximum 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. |
maxFunctionCalls | number | 10000 | Maximum 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. |
maxDateOffsetYears | number | 100 | How 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(). |
minDateOffsetYears | number | -100 | The same bound backwards, negative (default -100). |
context | EngineContext | defaultEngineContext | Registries belonging to the engine that created this VM. |