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.

Implementations§

source§

impl Opcode

source

pub fn num_operands(&self) -> usize

Returns the number of operands that this instruction type should have.

Trait Implementations§

source§

impl Clone for Opcode

source§

fn clone(&self) -> Opcode

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Opcode

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl From<&str> for Opcode

source§

fn from(s: &str) -> Self

Converts to this type from the input type.
source§

impl From<Opcode> for &str

source§

fn from(opcode: Opcode) -> Self

Converts to this type from the input type.
source§

impl From<Opcode> for u8

source§

fn from(opcode: Opcode) -> Self

Converts to this type from the input type.
source§

impl From<u8> for Opcode

source§

fn from(byte: u8) -> Self

Converts to this type from the input type.
source§

impl FromBytes for Opcode

§

type Error = OpcodeParseError

The error type returned when the conversion fails
source§

fn from_bytes(source: &mut BufferIterator<'_>) -> Result<Self, Self::Error>

Parses a value from the buffer iterator.
source§

impl Hash for Opcode

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl PartialEq<Opcode> for Opcode

source§

fn eq(&self, other: &Opcode) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl ToBytes for Opcode

source§

fn to_bytes(&self, buf: &mut impl WritableBuffer)

Converts a type into bytes and appends it to the buffer.
source§

impl Copy for Opcode

source§

impl Eq for Opcode

source§

impl StructuralEq for Opcode

source§

impl StructuralPartialEq for Opcode

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.