Memory Opcodes
This section documents the memory operations instructions available in CandleVM.
For operand encodings, see the executable format reference.
Values, modules, globals and resources
| Opcode byte | Opcode | Operand bytes | Behavior |
|---|---|---|---|
| 9 | LoadConst | destination: register, value: tagged value | Loads an immediate Value using the encoding rules and stores it. |
| 10 | Mov | destination: register, source: register | Copies a runtime value from one register to another. |
| 11 | LoadModule | destination: register, name: string | Looks up the exact module name and stores a ModuleRef; unknown names raise ModuleName. |
| 12 | LoadFunction | destination: register, module: register, name: string | Requires a ModuleRef; another value type raises ValueTypeMismatch. It looks up the exact function name and stores a FunctionRef. An invalid module ID raises InvalidModuleRef, and a missing function raises FunctionName. |
| 13 | LoadGlobal | destination: register, name: string | Loads the named global. A missing global reads as Null. |
| 14 | StoreGlobal | name: string, source: register | Stores a global. Storing Null removes it. A write to an existing read-only global raises ReadOnlyGlobal. |
| 15 | LoadResource | destination: register, id: string | Looks up an embedded resource by exact ID, allocates a new buffer containing a copy, and stores its ObjectRef. Missing IDs raise ResourceNotFound. |
| 16 | Type | destination: register, source: register | Stores the source value's type discriminator as a byte. |
| 17 | ObjectType | destination: register, object: register | Requires a valid ObjectRef and stores its object type discriminator as a byte. |
At VM startup, read-only globals include API_VERSION, VM_VERSION, DEBUG, TYPE_NULL, TYPE_BYTE, TYPE_NUMBER, TYPE_BOOL, TYPE_CHAR, TYPE_MODULE_REF, TYPE_FUNCTION_REF, TYPE_OBJECT_REF, and OBJECT_TYPE_ARRAY, OBJECT_TYPE_MAP, OBJECT_TYPE_STRING, OBJECT_TYPE_ERROR, OBJECT_TYPE_BUFFER, OBJECT_TYPE_NATIVE.