This site describes solve-engine as it is on main: 2.43.0, which npm does not have yet. npm installs 2.40.0, so a page may show an answer that version does not give yet.
OpRegistry
Defined in: packages/engine/src/vm/OpRegistry.ts:114
A table of custom opcode handlers the virtual machine never reads.
This once described an extension point: a package allocated an opcode from
the dynamic range (201 to 254), registered a handler for it, and the VM’s
dispatch switch was meant to call that handler from its default arm. The
switch never consulted the registry, and until recently had no default arm
at all, so a registered opcode ran as a no-op and the program failed some
instructions later with a misleading STACK_UNDERFLOW. The dispatch loop now
refuses any opcode it has no arm for, at that instruction, with
MALFORMED_BYTECODE_UNKNOWN_OPCODE, whatever a registry claims about it.
The class, the sharedOpRegistry singleton, the registry field on
VM and the first parameter of createVM() are kept so the calls a
host already makes keep compiling and running; every one of them is
deprecated and goes in the next major. A package that wants the VM to run
its code declares IEnginePackage.pluginFunctions, which CALL_PLUGIN
resolves through the engine’s own context, one table per engine.
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new OpRegistry(): OpRegistry;Returns
Section titled “Returns”OpRegistry
Methods
Section titled “Methods”allocateOpcode()
Section titled “allocateOpcode()”allocateOpcode(): number;Defined in: packages/engine/src/vm/OpRegistry.ts:148
Allocate a unique opcode for a plugin’s custom bytecode handler.
Returns the next available opcode (starting at 201). Each call returns a distinct value. Plugins should call this once during registration and store the result.
Returns
Section titled “Returns”number
A unique opcode number for the calling plugin.
Throws
Section titled “Throws”If the dynamic opcode pool is exhausted.
get(opcode): OpcodeHandler | undefined;Defined in: packages/engine/src/vm/OpRegistry.ts:130
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
opcode | number |
Returns
Section titled “Returns”OpcodeHandler | undefined
has(opcode): boolean;Defined in: packages/engine/src/vm/OpRegistry.ts:134
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
opcode | number |
Returns
Section titled “Returns”boolean
register()
Section titled “register()”register(registration): void;Defined in: packages/engine/src/vm/OpRegistry.ts:118
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
registration | IOpcodeHandlerRegistration |
Returns
Section titled “Returns”void
unregister()
Section titled “unregister()”unregister(opcode): void;Defined in: packages/engine/src/vm/OpRegistry.ts:126
Remove a previously registered opcode handler. Used by package unregistration to reverse shared-registry contributions.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
opcode | number |
Returns
Section titled “Returns”void