Skip to content

Instruction Set

Below is the complete set of bytecode instructions supported by the CrossBasic VM, organized by category for visual clarity.


๐Ÿ“ฅ Constants & Stack Manipulation

  • ๐Ÿงฎ OP_CONSTANT Pushes a constant (from the functionโ€™s constant pool) onto the stack.
  • ๐Ÿ—‘๏ธ OP_POP Removes the top value from the stack.
  • ๐Ÿ“‹ OP_DUP Duplicates the top value on the stack.

โž•โž– Arithmetic Operations

  • โž• OP_ADD Pops two values; adds numbers or concatenates strings; pushes the result.
  • โž– OP_SUB Pops two values; subtracts; pushes the result.
  • โœ–๏ธ OP_MUL Pops two values; multiplies; pushes the result.
  • โž— OP_DIV Pops two values; divides; pushes the result.
  • โžฐ OP_NEGATE Pops one numeric value; negates it; pushes the result.
  • ๐Ÿš€ OP_POW Pops two values; computes a^b; pushes the result.
  • ๐Ÿ’  OP_MOD Pops two values; computes modulus (or fmod for floats); pushes the result.

๐Ÿ” Comparisons

  • ๐Ÿ”ฝ OP_LT Pops two values; pushes true if a < b, else false.
  • ๐Ÿ”ฝโœ… OP_LE Pops two values; pushes true if a โ‰ค b, else false.
  • ๐Ÿ”ผ OP_GT Pops two values; pushes true if a > b, else false.
  • ๐Ÿ”ผโœ… OP_GE Pops two values; pushes true if a โ‰ฅ b, else false.
  • ๐Ÿ†š OP_EQ Pops two values; tests equality (numbers, strings, colors, pointers, instances); pushes result.
  • โŒ OP_NE Pops two values; tests inequality; pushes result.

๐Ÿ”„ Logical

  • ๐Ÿ”ง OP_AND Pops two values; logical AND (truthiness); pushes result.
  • ๐Ÿ”จ OP_OR Pops two values; logical OR; pushes result.

๐Ÿ–จ๏ธ I/O

  • ๐Ÿ–จ๏ธ OP_PRINT Pops one value; converts to string; writes to stdout.

๐ŸŒ Globals & Variables

  • ๐ŸŒ OP_DEFINE_GLOBAL Pops a value; defines a new global variable with the given name.
  • ๐ŸŽฏ OP_GET_GLOBAL Pushes the value of a global variable (or built-in like ticks, microseconds).
  • ๐Ÿ“ OP_SET_GLOBAL Pops a value; assigns it to an existing global variable.

๐Ÿ“ž Function & Method Calls

  • ๐Ÿƒ OP_CALL Pops callee and N arguments; invokes functions, methods, array indexing, or built-ins.
  • ๐Ÿค OP_OPTIONAL_CALL Like OP_CALL, but if callee is nil it skips the call (used for optional constructor calls).
  • ๐Ÿ”š OP_RETURN Pops a return value; unwinds the current function frame, returning that value to the caller.

๐Ÿšฆ Control Flow

  • โฌœ OP_NIL Pushes a nil (empty) value onto the stack.
  • ๐Ÿ™ˆ OP_JUMP_IF_FALSE Pops a condition; if false, sets the instruction pointer to the given offset.
  • ๐Ÿšง OP_JUMP Unconditionally jumps to the given offset.

๐Ÿ›๏ธ Classes & Objects

  • ๐Ÿท๏ธ OP_CLASS Creates a new, empty class object and pushes it.
  • ๐Ÿ› ๏ธ OP_METHOD Pops a function and a class; installs the function as a method on that class.
  • ๐Ÿ—๏ธ OP_PROPERTIES Pops a property map and a class; assigns the properties to the class.
  • ๐Ÿ†• OP_NEW Pops a class; allocates and initializes a new instance (handles both scripted and plugin classes).
  • ๐ŸŽฌ OP_CONSTRUCTOR_END After an OP_OPTIONAL_CALL to a constructor, picks either the new instance or the constructorโ€™s return value.

๐Ÿ“ฆ Arrays & Properties

  • ๐Ÿ“ฆ OP_ARRAY Pops N values; creates an array literal from them; pushes the new array instance.
  • ๐Ÿ” OP_GET_PROPERTY Pops an object; retrieves a field, method (as a bound method), or enum member; pushes it.
  • ๐Ÿ–‹๏ธ OP_SET_PROPERTY Pops an object and a value; sets the property or invokes a plugin setter; pushes the object back.

โœจ Thatโ€™s the full CrossBasic VM instruction set