Skip to main content

lua_code/
opcode_names.rs

1//! Opcode name table for debug/disassembly output.
2//!
3//! Direct port of `src/lopnames.h` from Lua 5.4.7. Order must match the
4//! `OpCode` enum (`src/lopcodes.h`); `ORDER OP` invariant.
5//!
6//! The C source is preserved inline as `
7//! review.
8
9//
10// PORT NOTE: dropped the trailing NULL sentinel. Length is `OP_COUNT` known
11// at compile time; Rust slice + bounds-check serves the role of the
12// sentinel.
13
14/// Total number of opcodes. Must equal `OpCode::Count as usize` once the
15/// enum lands; trailer-required hook checks this constant exists.
16pub const OP_COUNT: usize = 83;
17
18/// Opcode names, indexed by `OpCode as usize`. ORDER OP — must match the
19/// `OpCode` enum order in `lopcodes.h` exactly.
20pub const OPNAMES: [&str; OP_COUNT] = [
21    "MOVE", "LOADI", "LOADF", "LOADK", "LOADKX", "LOADFALSE", "LFALSESKIP",
22    "LOADTRUE", "LOADNIL", "GETUPVAL", "SETUPVAL", "GETTABUP", "GETTABLE",
23    "GETI", "GETFIELD", "SETTABUP", "SETTABLE", "SETI", "SETFIELD",
24    "NEWTABLE", "SELF", "ADDI", "ADDK", "SUBK", "MULK", "MODK", "POWK",
25    "DIVK", "IDIVK", "BANDK", "BORK", "BXORK", "SHRI", "SHLI", "ADD",
26    "SUB", "MUL", "MOD", "POW", "DIV", "IDIV", "BAND", "BOR", "BXOR",
27    "SHL", "SHR", "MMBIN", "MMBINI", "MMBINK", "UNM", "BNOT", "NOT",
28    "LEN", "CONCAT", "CLOSE", "TBC", "JMP", "EQ", "LT", "LE", "EQK",
29    "EQI", "LTI", "LEI", "GTI", "GEI", "TEST", "TESTSET", "CALL",
30    "TAILCALL", "RETURN", "RETURN0", "RETURN1", "FORLOOP", "FORPREP",
31    "TFORPREP", "TFORCALL", "TFORLOOP", "SETLIST", "CLOSURE", "VARARG",
32    "VARARGPREP", "EXTRAARG",
33];
34
35#[cfg(test)]
36mod tests {
37    use super::*;
38
39    #[test]
40    fn op_count_matches_table() {
41        assert_eq!(OPNAMES.len(), OP_COUNT);
42    }
43
44    #[test]
45    fn first_and_last_opcodes() {
46        assert_eq!(OPNAMES[0], "MOVE");
47        assert_eq!(OPNAMES[OP_COUNT - 1], "EXTRAARG");
48    }
49}
50
51// ──────────────────────────────────────────────────────────────────────────
52// PORT STATUS
53//   source:        src/lopnames.h (103 lines, 1 static array)
54//   target_crate:  lua-code
55//   confidence:    high
56//   todos:         0
57//   port_notes:    1   (dropped NULL sentinel — Rust length is exact)
58//   unsafe_blocks: 0
59//   notes:         opcode name table only; OpCode enum lands separately
60// ──────────────────────────────────────────────────────────────────────────