Enum OpCode

Source
pub enum OpCode<'s> {
Show 15 variants Call { function: usize, arguments: usize, destination: usize, }, IndexRead { indexee: usize, index: usize, destination: usize, }, IndexWrite { indexee: usize, index: usize, value: usize, }, Create { destination: usize, }, BinaryOperation { left: usize, right: usize, operation: BinaryOperation, destination: usize, }, UnaryOperation { operand: usize, operation: UnaryOperation, destination: usize, }, Jump { operation: u64, if: Option<usize>, }, Return { result: usize, }, ReAssign { actor: usize, destination: usize, }, LoadConst { constant: u16, register: usize, }, LoadGlobal { global: &'s str, register: usize, }, SaveGlobal { register: usize, global: &'s str, }, LoadUpValue { up_value: usize, register: usize, }, SaveUpValue { register: usize, up_value: usize, }, NoOp,
}
Expand description

The operation codes used within the lua virtual machine. All lua code is compiled to blocks of opcodes. Opcodes are the primitive block of “action” (lua code ran from this vm cannot perform any actions more specific than what these opcodes can provide). Each opcode does a different thing, but most opcodes operate with memory directly from the local scope via symbols.

Typically, the lua compiler will use temporary variable names that cannot be accessed from lua directly. All of these temporary variables start with a left parenthesis, because that makes these variables impossible to access or alter accidentally in lua. Theoretically, you can use methods from the debug module to access these temporary variables, but tampering with them won’t do much more than corrupt the state of the currently executing function.

Variants§

§

Call

Calls a function with the name [function], with the arguments array [arguments], and stores the result array in [destination]. [arguments] must be a lua array (a table, typically with numbered keys starting from 1), or else an error will be thrown.

[destination_local] determines if the result will be stored to the local scope or global scope.

Fields

§function: usize

The name of the function, in scope, to be called. Must be a function or else an error will be thrown.

§arguments: usize

The name of the arguments array, in scope. Must be a table or else an error will be thrown.

§destination: usize

The name of where the return values will be stored.

§

IndexRead

Indexes into the object with the name [indexee], with index [index], and stores the result in [destination].

[destination_local] determines if the result will be stored to the local scope or global scope.

Fields

§indexee: usize

The name of the object to be indexed.

§index: usize

The name of the object that serves as the index.

§destination: usize

The name of where the result will be stored.

§

IndexWrite

Indexes into the object with the name [indexee], with index [index], and writes value into [indexee].

Fields

§indexee: usize

The name of the object to be indexed.

§index: usize

The name of the object that serves as the index.

§value: usize

The name of the value to be stored within the indexee.

§

Create

Creates a new empty table at [destination].

[destination_local] determines if the new table will be stored to the local scope or global scope.

Fields

§destination: usize

The name of where the new table will be stored.

§

BinaryOperation

Fields

§left: usize
§right: usize
§destination: usize
§

UnaryOperation

Fields

§operand: usize
§operation: UnaryOperation
§destination: usize
§

Jump

Jumps unconditionally to [operation], or conditionally if the name of a condition is specified in [r#if]. The jump operation is performed in number of opcodes, not bytes.

Fields

§operation: u64

The opcode to jump to.

§if: Option<usize>

An optional condition. If specified, the value at the specified name must be true or false, otherwise an error will be thrown. If true, the jump will occur, otherwise it will not.

§

Return

Fields

§result: usize
§

ReAssign

Fields

§actor: usize
§destination: usize
§

LoadConst

Loads a value from the constant pool at index constant to [destination].

[destination_local] determines if the constant will be stored to the local scope or global scope.

Fields

§constant: u16

The constant to be loaded.

§register: usize

The name of where the constant will be stored.

§

LoadGlobal

Fields

§global: &'s str
§register: usize
§

SaveGlobal

Fields

§register: usize
§global: &'s str
§

LoadUpValue

Fields

§up_value: usize
§register: usize
§

SaveUpValue

Fields

§register: usize
§up_value: usize
§

NoOp

Trait Implementations§

Source§

impl<'s> Clone for OpCode<'s>

Source§

fn clone(&self) -> OpCode<'s>

Returns a duplicate 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<'s> Debug for OpCode<'s>

Source§

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

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

impl<'s> Display for OpCode<'s>

Source§

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

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

impl<'s> Hash for OpCode<'s>

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<'s> PartialEq for OpCode<'s>

Source§

fn eq(&self, other: &OpCode<'s>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'s> Eq for OpCode<'s>

Source§

impl<'s> StructuralPartialEq for OpCode<'s>

Auto Trait Implementations§

§

impl<'s> Freeze for OpCode<'s>

§

impl<'s> RefUnwindSafe for OpCode<'s>

§

impl<'s> Send for OpCode<'s>

§

impl<'s> Sync for OpCode<'s>

§

impl<'s> Unpin for OpCode<'s>

§

impl<'s> UnwindSafe for OpCode<'s>

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> CallHasher for T
where T: Hash + ?Sized,

Source§

default fn get_hash<H, B>(value: &H, build_hasher: &B) -> u64
where H: Hash + ?Sized, B: BuildHasher,

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> 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

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 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.