Instruction format and execution

Updated: April 19, 2023

Each virtual machine instruction consists of an opcode and up to three operands, which we name P1, P2, and P3. P1 can be an arbitrary integer. P2 must be a non-negative integer. In any operation that might cause a jump, P2 is always the jump destination. P3 may point to a function, data structure, or string, or it may be NULL. Some operators use from one to three operands but some use none.

The virtual machine begins execution on instruction number 0. Execution continues until:

  1. A Halt instruction is seen.
  2. The program counter becomes one greater than the address of the last instruction.
  3. An execution error occurs.

When the virtual machine halts, all memory that it allocated is released, and all database cursors it may have open are closed. If the execution stopped due to an error, any pending transactions are terminated and any database changes made are rolled back.