Skip to main content

Op

Enum Op 

Source
#[non_exhaustive]
pub enum Op {
Show 23 variants Move { dst: Reg, src: Reg, }, LoadConst { dst: Reg, index: Const, }, LoadNil { dst: Reg, }, LoadBool { dst: Reg, val: bool, }, LoadInt { dst: Reg, val: i32, }, Add { dst: Reg, lhs: Reg, rhs: Reg, }, Sub { dst: Reg, lhs: Reg, rhs: Reg, }, Mul { dst: Reg, lhs: Reg, rhs: Reg, }, Div { dst: Reg, lhs: Reg, rhs: Reg, }, Rem { dst: Reg, lhs: Reg, rhs: Reg, }, Neg { dst: Reg, src: Reg, }, Eq { dst: Reg, lhs: Reg, rhs: Reg, }, Ne { dst: Reg, lhs: Reg, rhs: Reg, }, Lt { dst: Reg, lhs: Reg, rhs: Reg, }, Le { dst: Reg, lhs: Reg, rhs: Reg, }, Gt { dst: Reg, lhs: Reg, rhs: Reg, }, Ge { dst: Reg, lhs: Reg, rhs: Reg, }, Not { dst: Reg, src: Reg, }, Jump { target: Addr, }, JumpIfTrue { cond: Reg, target: Addr, }, JumpIfFalse { cond: Reg, target: Addr, }, Return { src: Reg, }, Halt,
}
Expand description

A single decoded instruction.

Instructions divide into data movement (Move, Load*), arithmetic (Add…Neg), comparison (Eq…Ge), the logical Not, control flow (Jump, JumpIfTrue, JumpIfFalse), and termination (Return, Halt).

Arithmetic and comparison operands are numeric: an integer combines with an integer to give an integer (with overflow checked), and any float operand promotes the result to float. Comparisons and Not produce booleans. See the individual variants and the crate root for the exact semantics.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Move

Copy the value in src into dst.

Fields

§dst: Reg

Destination register.

§src: Reg

Source register.

§

LoadConst

Load the constant at pool position index into dst.

Fields

§dst: Reg

Destination register.

§index: Const

Constant-pool index (see Chunk::constant).

§

LoadNil

Load nil into dst.

Fields

§dst: Reg

Destination register.

§

LoadBool

Load the boolean val into dst.

Fields

§dst: Reg

Destination register.

§val: bool

Immediate boolean.

§

LoadInt

Load the 32-bit integer immediate val into dst.

Small integers travel in the instruction itself, avoiding a constant-pool round trip for the common case.

Fields

§dst: Reg

Destination register.

§val: i32

Immediate integer.

§

Add

dst = lhs + rhs (numeric; integer add is overflow-checked).

Fields

§dst: Reg

Destination register.

§lhs: Reg

Left operand register.

§rhs: Reg

Right operand register.

§

Sub

dst = lhs - rhs (numeric; integer subtract is overflow-checked).

Fields

§dst: Reg

Destination register.

§lhs: Reg

Left operand register.

§rhs: Reg

Right operand register.

§

Mul

dst = lhs * rhs (numeric; integer multiply is overflow-checked).

Fields

§dst: Reg

Destination register.

§lhs: Reg

Left operand register.

§rhs: Reg

Right operand register.

§

Div

dst = lhs / rhs (numeric; integer divide-by-zero errors, float follows IEEE-754).

Fields

§dst: Reg

Destination register.

§lhs: Reg

Left operand register.

§rhs: Reg

Right operand register.

§

Rem

dst = lhs % rhs (numeric; integer remainder-by-zero errors).

Fields

§dst: Reg

Destination register.

§lhs: Reg

Left operand register.

§rhs: Reg

Right operand register.

§

Neg

dst = -src (numeric; integer negation is overflow-checked).

Fields

§dst: Reg

Destination register.

§src: Reg

Source register.

§

Eq

dst = (lhs == rhs) as a boolean. Numeric operands compare by value across int/float; other kinds compare structurally. Floats use IEEE-754 equality.

Fields

§dst: Reg

Destination register.

§lhs: Reg

Left operand register.

§rhs: Reg

Right operand register.

§

Ne

dst = (lhs != rhs) — the boolean negation of Op::Eq.

Fields

§dst: Reg

Destination register.

§lhs: Reg

Left operand register.

§rhs: Reg

Right operand register.

§

Lt

dst = (lhs < rhs) (numeric operands only).

Fields

§dst: Reg

Destination register.

§lhs: Reg

Left operand register.

§rhs: Reg

Right operand register.

§

Le

dst = (lhs <= rhs) (numeric operands only).

Fields

§dst: Reg

Destination register.

§lhs: Reg

Left operand register.

§rhs: Reg

Right operand register.

§

Gt

dst = (lhs > rhs) (numeric operands only).

Fields

§dst: Reg

Destination register.

§lhs: Reg

Left operand register.

§rhs: Reg

Right operand register.

§

Ge

dst = (lhs >= rhs) (numeric operands only).

Fields

§dst: Reg

Destination register.

§lhs: Reg

Left operand register.

§rhs: Reg

Right operand register.

§

Not

dst = !src. src must be a boolean.

Fields

§dst: Reg

Destination register.

§src: Reg

Source register.

§

Jump

Unconditionally set the program counter to target.

Fields

§target: Addr

Absolute instruction address to continue from.

§

JumpIfTrue

Branch to target when cond holds a true boolean; otherwise fall through. cond must be a boolean.

Fields

§cond: Reg

Condition register (must be a boolean).

§target: Addr

Absolute instruction address taken when the condition is true.

§

JumpIfFalse

Branch to target when cond holds a false boolean; otherwise fall through. cond must be a boolean.

Fields

§cond: Reg

Condition register (must be a boolean).

§target: Addr

Absolute instruction address taken when the condition is false.

§

Return

Stop execution and yield the value in src as the run’s result.

Fields

§src: Reg

Register holding the value to return.

§

Halt

Stop execution and yield nil.

Trait Implementations§

Source§

impl Clone for Op

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for Op

Source§

impl Debug for Op

Source§

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

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

impl<'de> Deserialize<'de> for Op

Available on crate feature serde only.
Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Eq for Op

Source§

impl PartialEq for Op

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl Serialize for Op

Available on crate feature serde only.
Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Op

Auto Trait Implementations§

§

impl Forget for Op

§

impl Freeze for Op

§

impl Move for Op

§

impl RefUnwindSafe for Op

§

impl Send for Op

§

impl Sync for Op

§

impl Unpin for Op

§

impl UnsafeUnpin for Op

§

impl UnwindSafe for Op

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where 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 T
where T: Clone,

Source§

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 T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

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

Source§

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.