pub struct Instruction {
pub header: u32,
pub opcode: Opcode,
pub a: u8,
pub b: u8,
pub c: u8,
pub d: i16,
pub e: i32,
pub aux: Option<u32>,
}Expand description
One instruction header and its optional static AUX word.
Plain-old-data on purpose: the dispatch loop fetches instructions by copy,
so the type must never grow a heap allocation. Every aux-bearing Luau
opcode carries exactly one AUX word (Opcode::instruction_len).
§Invariant
opcode, a, b, c, d, and e are pre-decoded views of header;
every constructor (Instruction::from_words, Instruction::abc,
Instruction::abc_with_aux, Instruction::ad) derives them together
so they always agree. The fields stay public (and mutable) for the VM
dispatch loop, so direct mutation of one side can break the invariant —
but never silently: crate::validate_chunk reports the mismatch and
crate::encode_chunk refuses to encode it. To change an instruction,
build a replacement through a constructor instead of mutating fields.
Fields§
§header: u32Header word.
opcode: OpcodeDecoded opcode.
a: u8ABC A operand.
b: u8ABC B operand.
c: u8ABC C operand.
d: i16AD D operand.
e: i32E operand.
aux: Option<u32>The static AUX word following the header, when the opcode has one. Serialized as a 0/1-element array to keep the committed fixture shape.
Implementations§
Source§impl Instruction
impl Instruction
Sourcepub fn from_words(header: u32, aux: Option<u32>) -> Option<Self>
pub fn from_words(header: u32, aux: Option<u32>) -> Option<Self>
Creates an instruction from its raw words.
Sourcepub fn abc_with_aux(
opcode: Opcode,
a: u8,
b: u8,
c: u8,
aux: Option<u32>,
) -> Self
pub fn abc_with_aux( opcode: Opcode, a: u8, b: u8, c: u8, aux: Option<u32>, ) -> Self
Encodes ABC instruction fields followed by an optional static AUX word.
Sourcepub fn jump_offset_words(&self) -> Option<i32>
pub fn jump_offset_words(&self) -> Option<i32>
Returns the encoded jump offset in instruction words, if this opcode jumps.
Luau jump offsets are relative to the word after the instruction header.
For instructions with AUX words, the AUX words are part of the encoded
offset span; for example, comparison jumps use D = 1 for the next
decoded instruction because their AUX word occupies the intervening word.
Sourcepub fn jump_target_word(&self, instruction_word: u32) -> Option<i32>
pub fn jump_target_word(&self, instruction_word: u32) -> Option<i32>
Resolves this instruction’s jump target as an absolute instruction-word offset.
Sourcepub fn capture_type(&self) -> Option<CaptureType>
pub fn capture_type(&self) -> Option<CaptureType>
Returns the CAPTURE operand kind, if this is a valid capture instruction.
Sourcepub fn capture_source(&self) -> Option<u8>
pub fn capture_source(&self) -> Option<u8>
Returns the CAPTURE source register or upvalue index.
Sourcepub fn word_len(&self) -> u32
pub fn word_len(&self) -> u32
Returns the number of instruction words this instruction occupies, counting its header word plus any AUX words.
Sourcepub fn is_header_consistent(&self) -> bool
pub fn is_header_consistent(&self) -> bool
Returns true when the pre-decoded operand fields match a fresh
re-decode of header, i.e. the instruction upholds the type’s
header/field invariant.