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 = 86;
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",
22 "LOADI",
23 "LOADF",
24 "LOADK",
25 "LOADKX",
26 "LOADFALSE",
27 "LFALSESKIP",
28 "LOADTRUE",
29 "LOADNIL",
30 "GETUPVAL",
31 "SETUPVAL",
32 "GETTABUP",
33 "GETTABLE",
34 "GETI",
35 "GETFIELD",
36 "SETTABUP",
37 "SETTABLE",
38 "SETI",
39 "SETFIELD",
40 "NEWTABLE",
41 "SELF",
42 "ADDI",
43 "ADDK",
44 "SUBK",
45 "MULK",
46 "MODK",
47 "POWK",
48 "DIVK",
49 "IDIVK",
50 "BANDK",
51 "BORK",
52 "BXORK",
53 "SHRI",
54 "SHLI",
55 "ADD",
56 "SUB",
57 "MUL",
58 "MOD",
59 "POW",
60 "DIV",
61 "IDIV",
62 "BAND",
63 "BOR",
64 "BXOR",
65 "SHL",
66 "SHR",
67 "MMBIN",
68 "MMBINI",
69 "MMBINK",
70 "UNM",
71 "BNOT",
72 "NOT",
73 "LEN",
74 "CONCAT",
75 "CLOSE",
76 "TBC",
77 "JMP",
78 "EQ",
79 "LT",
80 "LE",
81 "EQK",
82 "EQI",
83 "LTI",
84 "LEI",
85 "GTI",
86 "GEI",
87 "TEST",
88 "TESTSET",
89 "CALL",
90 "TAILCALL",
91 "RETURN",
92 "RETURN0",
93 "RETURN1",
94 "FORLOOP",
95 "FORPREP",
96 "TFORPREP",
97 "TFORCALL",
98 "TFORLOOP",
99 "SETLIST",
100 "CLOSURE",
101 "VARARG",
102 "VARARGPREP",
103 "EXTRAARG",
104 "ERRNNIL",
105 "VARARGPACK",
106 "GETVARG",
107];
108
109#[cfg(test)]
110mod tests {
111 use super::*;
112
113 #[test]
114 fn op_count_matches_table() {
115 assert_eq!(OPNAMES.len(), OP_COUNT);
116 }
117
118 #[test]
119 fn first_and_last_opcodes() {
120 assert_eq!(OPNAMES[0], "MOVE");
121 assert_eq!(OPNAMES[OP_COUNT - 1], "GETVARG");
122 }
123}
124
125// ──────────────────────────────────────────────────────────────────────────
126// PORT STATUS
127// source: src/lopnames.h (103 lines, 1 static array)
128// target_crate: lua-code
129// confidence: high
130// todos: 0
131// port_notes: 1 (dropped NULL sentinel — Rust length is exact)
132// unsafe_blocks: 0
133// notes: opcode name table only; OpCode enum lands separately
134// ──────────────────────────────────────────────────────────────────────────