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_CONSTANTPushes a constant (from the functionโs constant pool) onto the stack. - ๐๏ธ
OP_POPRemoves the top value from the stack. - ๐
OP_DUPDuplicates the top value on the stack.
โโ Arithmetic Operations¶
- โ
OP_ADDPops two values; adds numbers or concatenates strings; pushes the result. - โ
OP_SUBPops two values; subtracts; pushes the result. - โ๏ธ
OP_MULPops two values; multiplies; pushes the result. - โ
OP_DIVPops two values; divides; pushes the result. - โฐ
OP_NEGATEPops one numeric value; negates it; pushes the result. - ๐
OP_POWPops two values; computes a^b; pushes the result. - ๐
OP_MODPops two values; computes modulus (or fmod for floats); pushes the result.
๐ Comparisons¶
- ๐ฝ
OP_LTPops two values; pushestrueif a < b, elsefalse. - ๐ฝโ
OP_LEPops two values; pushestrueif a โค b, elsefalse. - ๐ผ
OP_GTPops two values; pushestrueif a > b, elsefalse. - ๐ผโ
OP_GEPops two values; pushestrueif a โฅ b, elsefalse. - ๐
OP_EQPops two values; tests equality (numbers, strings, colors, pointers, instances); pushes result. - โ
OP_NEPops two values; tests inequality; pushes result.
๐ Logical¶
- ๐ง
OP_ANDPops two values; logical AND (truthiness); pushes result. - ๐จ
OP_ORPops two values; logical OR; pushes result.
๐จ๏ธ I/O¶
- ๐จ๏ธ
OP_PRINTPops one value; converts to string; writes to stdout.
๐ Globals & Variables¶
- ๐
OP_DEFINE_GLOBALPops a value; defines a new global variable with the given name. - ๐ฏ
OP_GET_GLOBALPushes the value of a global variable (or built-in liketicks,microseconds). - ๐
OP_SET_GLOBALPops a value; assigns it to an existing global variable.
๐ Function & Method Calls¶
- ๐
OP_CALLPops callee and N arguments; invokes functions, methods, array indexing, or built-ins. - ๐ค
OP_OPTIONAL_CALLLikeOP_CALL, but if callee isnilit skips the call (used for optional constructor calls). - ๐
OP_RETURNPops a return value; unwinds the current function frame, returning that value to the caller.
๐ฆ Control Flow¶
- โฌ
OP_NILPushes anil(empty) value onto the stack. - ๐
OP_JUMP_IF_FALSEPops a condition; if false, sets the instruction pointer to the given offset. - ๐ง
OP_JUMPUnconditionally jumps to the given offset.
๐๏ธ Classes & Objects¶
- ๐ท๏ธ
OP_CLASSCreates a new, empty class object and pushes it. - ๐ ๏ธ
OP_METHODPops a function and a class; installs the function as a method on that class. - ๐๏ธ
OP_PROPERTIESPops a property map and a class; assigns the properties to the class. - ๐
OP_NEWPops a class; allocates and initializes a new instance (handles both scripted and plugin classes). - ๐ฌ
OP_CONSTRUCTOR_ENDAfter anOP_OPTIONAL_CALLto a constructor, picks either the new instance or the constructorโs return value.
๐ฆ Arrays & Properties¶
- ๐ฆ
OP_ARRAYPops N values; creates an array literal from them; pushes the new array instance. - ๐
OP_GET_PROPERTYPops an object; retrieves a field, method (as a bound method), or enum member; pushes it. - ๐๏ธ
OP_SET_PROPERTYPops 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