#[repr(u8)]
pub enum Opcode {
Show 47 variants Nop, PushNil, PushTrue, PushFalse, PushNumber, PushString, CreateClosure, CreateType, CreateStruct, CreateTrait, CreateList, CreateDict, AssignGlobal, SinkGlobal, GetGlobal, AssignLocal, SinkLocal, GetLocal, AssignUpvalue, SinkUpvalue, GetUpvalue, CloseLocal, AssignField, SinkField, GetField, Swap, Discard, JumpForward, JumpForwardIfFalsy, JumpForwardIfTruthy, JumpBackward, EnterBreakableBlock, ExitBreakableBlock, Call, CallMethod, Return, Implement, Negate, Add, Subtract, Multiply, Divide, Not, Equal, Less, LessEqual, Halt,
}
Expand description

A VM opcode.

Variants

Nop

Doesn’t do anything. Used as a default zero value if something goes wrong. Also used for backpatching purposes.

PushNil

Pushes nil onto the stack.

PushTrue

Pushes true onto the stack.

PushFalse

Pushes false onto the stack.

PushNumber

Pushes a number onto the stack. Must be followed by an f64.

PushString

Pushes a string onto the stack. Must be followed by a string.

CreateClosure

Creates a closure from the function with the given ID and pushes it onto the stack.

CreateType

Creates a unique type that can be later implemented. Must be followed by a string indicating the type’s name.

CreateStruct

Creates a struct instance from the type at the top of the stack, with the specified amount of fields.

CreateTrait

Creates an instance of the trait with the given ID and pushes it onto the stack.

CreateList

Creates a list from operand values that are at the top of the stack.

CreateDict

Creates a dict from operand * 2 values that are at the top of the stack. The values have to be arranged in key, value, key, value... order, from bottom to top.

AssignGlobal

Assigns the value at the top of the stack to a global. The value stays on the stack.

SinkGlobal

Sinks the value at the top of the stack to a global. The value is consumed.

GetGlobal

Loads a value from a global.

AssignLocal

Assigns the value at the top of the stack to a local. The value stays on the stack.

SinkLocal

Sinks the value at the top of the stack to a local. The value is consumed.

GetLocal

Loads a value from a local.

AssignUpvalue

Assigns the value at the top of the stack to an upvalue. The value stays on the stack.

SinkUpvalue

Sinks the value at the top of the stack to an upvalue. The value is consumed.

GetUpvalue

Loads a value from an upvalue.

CloseLocal

Closes a local in its upvalue.

AssignField

Assigns to a field in the struct on the top of the stack. The struct is consumed but the value remains on the stack. Assumes the second value from top is a struct and not something else.

SinkField

Sinks to a field in the struct on the top of the stack. Both the struct and the value are consumed.

GetField

Loads a field from the struct on the top of the stack. Assumes the value on top is a struct and not something else.

Swap

Swaps the two values at the top of the stack.

Discard

Removes the value at the top of the stack.

JumpForward

Jumps the program counter forward by an amount of bytes.

JumpForwardIfFalsy

Jumps the program counter forward by an amount of bytes if the value at the top of the stack is falsy.

JumpForwardIfTruthy

Jumps the program counter forward by an amount of bytes if the value at the top of the stack is truthy.

JumpBackward

Jumps the program counter backward by an amount of bytes. Due to how the VM increments the program counter, the actual amount is operand - 4.

EnterBreakableBlock

Enters a breakable block by pushing the break sentinel value onto the stack.

ExitBreakableBlock

Exits the n-th breakable block (counted from innermost) by popping values off the stack until .0 sentinels are removed.

Call

Calls a function with .0 arguments.

CallMethod

Calls the nth method with a arguments, where a is encoded in the lower 8 bits, and n is encoded in the upper 16 bits of .0.

Return

Returns to the calling function.

Implement

Implements a struct according to a prototype identified by the operand.

Negate

Negates a number (prefix -).

Add

Adds two numbers together (infix +).

Subtract

Subtracts a number from another number (infix -).

Multiply

Multiplies two numbers together (infix *).

Divide

Divides a number by another number (infix /).

Not

Flips a boolean-like value (truthy values become false and falsy values become true).

Equal

Compares two values for equality.

Less

Compares two values for less-than relation.

LessEqual

Compares two values for less-than-or-equal relation.

Halt

Halts the interpreter loop.

Implementations

The size of an instruction (1 byte opcode + 3 bytes operand).

Constructs a JumpForward instruction.

Constructs a JumpForwardIfFalsy instruction.

Constructs a JumpForwardIfTruthy instruction.

Constructs a JumpBackward instruction.

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.