Enum kerbalobjects::Opcode
source · pub enum Opcode {
Show 54 variants
Bogus,
Eof,
Eop,
Nop,
Sto,
Uns,
Gmb,
Smb,
Gidx,
Sidx,
Bfa,
Jmp,
Add,
Sub,
Mul,
Div,
Pow,
Cgt,
Clt,
Cge,
Cle,
Ceq,
Cne,
Neg,
Bool,
Not,
And,
Or,
Call,
Ret,
Push,
Pop,
Dup,
Swap,
Eval,
Addt,
Rmvt,
Wait,
Gmet,
Stol,
Stog,
Bscp,
Escp,
Stoe,
Phdl,
Btr,
Exst,
Argb,
Targ,
Tcan,
Prl,
Pdrl,
Lbrt,
Pushv,
}
Expand description
The opcode of a kOS machine code instruction.
Each instruction is made up of an opcode, and a series of zero or more operands. This enum contains all currently supported kOS opcodes, and 2 additional ones.
Opcode::Bogus is the Opcode variant used to express that it is an unrecognized opcode. This is inspired by the actual kOS C# code.
Opcode::Pushv is an internal value that is can be used by tools working with kOS machine code, and it represents a normal Opcode::Push instruction, however specifying that the operand should be stored as a KOSValue “Value” type (ScalarDouble, StringValue). This is mostly just useful for the KASM assembler implementation.
See the instruction docs for more detailed documentation.
Variants§
Bogus
Specified also in the kOS C# code, represents an unrecognized Opcode
Eof
Stop executing for this cycle.
Eop
Aborts the current program and returns to the interpreter.
Nop
No operation: does nothing.
Sto
Consumes the top value of the stack and stores it in the variable named by the operand.
Uns
Consumes the top value of the stack and unsets the variable that it names.
Gmb
Gets the suffix of a variable on the stack.
Smb
Sets the suffix of a variable on the stack.
Gidx
Gets the value of an index into a variable on the stack.
Sidx
Sets the value of an index into a variable on the stack.
Bfa
Branches to the provided location if the value on the stack is false.
Jmp
Unconditionally branches to the provided location.
Add
Adds two variables on the stack. Also used to concatenate strings.
Sub
Subtracts two variables on the stack.
Mul
Multiplies two variables on the stack.
Div
Divides two variables on the stack.
Pow
Raises a value on the stack to another value on the stack.
Cgt
Compares two values on the stack. Pushes true if one is greater, false otherwise.
See instruction docs for the order of values in the comparison.
Clt
Compares two values on the stack. Pushes true if one is less, false otherwise.
See instruction docs for the order of values in the comparison.
Cge
Compares two values on the stack. Pushes true if one is greater or equal, false otherwise.
See instruction docs for the order of values in the comparison.
Cle
Compares two values on the stack. Pushes true if one is less or equal, false otherwise.
See instruction docs for the order of values in the comparison.
Ceq
Compares two values on the stack. Pushes true if both are equal, false otherwise.
Cne
Compares two values on the stack. Pushes true if both are not equal, false otherwise.
Neg
Consumes a value on the stack, and pushes back the negative.
Bool
Converts a value on the stack into a boolean.
See instruction docs for how the conversion is performed.
Not
Converts a value on the stack into a boolean, and pushes the negated value.
See instruction docs for how the conversion is performed.
And
Performs the logical AND operation between boolean values.
Or
Performs the logical OR operation between boolean values.
Call
Calls a function.
See instruction docs for call instruction format.
Ret
Returns from a function call.
Push
Pushes a value to the stack.
Pop
Pops a value off of the stack and discards it.
Dup
Duplicates the value on the top of the stack.
Swap
Swaps the top value of the stack with the value just below.
Eval
“Evaluates” the top value of the stack. Usually this replaces a variable name with the variable’s value.
Addt
Adds a new kOS trigger.
Rmvt
Removes a kOS trigger.
Wait
Waits for a specified amount of time.
Gmet
Gets the suffixed method of a variable on the stack.
Stol
Consumes the top value of the stack and stores it in the variable named by the operand. If the variable of the provided name does not exist, a new local variable is created.
Stog
Consumes the top value of the stack and stores it in the variable named by the operand. If the variable of the provided name does not exist, a new global variable is created.
Bscp
Begins a new variable scope
Escp
Ends a scope named by the provided id.
Stoe
Consumes the top value of the stack and stores it in the variable named by the operand. If the variable of the provided name does not exist, an error occurs.
Phdl
Pushes a function delegate to the stack.
Btr
Branches to the provided location if the value on the stack is true.
Exst
Checks if the provided variable name exists.
Argb
Asserts that the top of the stack is a KOSValue::ArgMarker
Targ
Pushes true if the top of the stack is a KOSValue::ArgMarker, false if not.
Tcan
Tests if the current trigger is requested to be cancelled. Pushes true if it is, false if not.
Prl
Pushes a value that is replaced with the correct value after the file is loaded.
Pdrl
Pushes a function delegate that is replaced with the correct value after the file is loaded.
Lbrt
Resets the current internal kOS label value.
Pushv
An internal value created for use by the Kerbal Assembler. This is not an opcode recognized by kOS, and should always be replaced with a regular Opcode::Push. This exists to be a special instruction that pushes the “Value” version of an argument.