Control Flow
These mnemonics define execution flow and function calls. Registers may also be written as self or void where a register is expected. For runtime execution details, see CandleVM control flow opcodes.
| CASM mnemonic | CandleVM opcode | Operands | CandleC behavior |
|---|---|---|---|
nop | Nop | — | Emits an instruction with no operands. |
exit | Exit | code | Encodes one register operand. CandleVM converts its value to the process exit code. |
call | Call | return, function [, parameter ...] | Takes a return register and function register, followed by up to 8 parameter registers. CandleC infers and encodes the parameter count. |
pcall | Pcall | return, error, function [, parameter ...] | Takes return and error registers, a function register, then up to 8 parameter registers. CandleC infers and encodes the count. |
ret | Ret | value | Returns the value in the given register. Use void to return Null. |
throw | Throw | error | Passes the register containing an Error to CandleVM to raise. |
jmp | Jump | instruction-delta | Uses a signed integer target delta relative to the current instruction index in the function. |
jmp_if | JumpIf | instruction-delta, condition | Branches by the delta when the condition register is true. |
jmp_if_not | JumpIfNot | instruction-delta, condition | Branches by the delta when the condition register is false. |
call and pcall do not take an explicit count operand in CASM. CandleC calculates it from the number of parameter registers and emits it in the bytecode. The runtime supplies Null for missing parameters and consumes but ignores extra arguments beyond the function's declared parameter count.
Jump deltas count instructions in the current function, with the current instruction at index zero. CandleC converts the target index into a relative byte offset for CandleVM and currently accepts encoded offsets from -128 through 127. CASM has no symbolic labels. A target may point immediately after the instruction sequence, including an automatically appended ret void.