Skip to main content

lua_code/
opcode_names.rs

1//! Opcode name table for debug/disassembly output.
2//!
3//! Order must match the `OpCode` enum (`lopcodes.h` in the reference C
4//! source): the `ORDER OP` invariant.
5
6//
7// Drops the trailing NULL sentinel C uses to mark the end of the array:
8// length is `OP_COUNT`, known at compile time, and a Rust slice with
9// bounds-checking serves the same role.
10
11/// Total number of opcodes. Must equal `OpCode::Count as usize` once the
12/// enum lands.
13pub const OP_COUNT: usize = 86;
14
15/// Opcode names, indexed by `OpCode as usize`. ORDER OP — must match the
16/// `OpCode` enum order in `lopcodes.h` exactly.
17pub const OPNAMES: [&str; OP_COUNT] = [
18    "MOVE",
19    "LOADI",
20    "LOADF",
21    "LOADK",
22    "LOADKX",
23    "LOADFALSE",
24    "LFALSESKIP",
25    "LOADTRUE",
26    "LOADNIL",
27    "GETUPVAL",
28    "SETUPVAL",
29    "GETTABUP",
30    "GETTABLE",
31    "GETI",
32    "GETFIELD",
33    "SETTABUP",
34    "SETTABLE",
35    "SETI",
36    "SETFIELD",
37    "NEWTABLE",
38    "SELF",
39    "ADDI",
40    "ADDK",
41    "SUBK",
42    "MULK",
43    "MODK",
44    "POWK",
45    "DIVK",
46    "IDIVK",
47    "BANDK",
48    "BORK",
49    "BXORK",
50    "SHRI",
51    "SHLI",
52    "ADD",
53    "SUB",
54    "MUL",
55    "MOD",
56    "POW",
57    "DIV",
58    "IDIV",
59    "BAND",
60    "BOR",
61    "BXOR",
62    "SHL",
63    "SHR",
64    "MMBIN",
65    "MMBINI",
66    "MMBINK",
67    "UNM",
68    "BNOT",
69    "NOT",
70    "LEN",
71    "CONCAT",
72    "CLOSE",
73    "TBC",
74    "JMP",
75    "EQ",
76    "LT",
77    "LE",
78    "EQK",
79    "EQI",
80    "LTI",
81    "LEI",
82    "GTI",
83    "GEI",
84    "TEST",
85    "TESTSET",
86    "CALL",
87    "TAILCALL",
88    "RETURN",
89    "RETURN0",
90    "RETURN1",
91    "FORLOOP",
92    "FORPREP",
93    "TFORPREP",
94    "TFORCALL",
95    "TFORLOOP",
96    "SETLIST",
97    "CLOSURE",
98    "VARARG",
99    "VARARGPREP",
100    "EXTRAARG",
101    "ERRNNIL",
102    "VARARGPACK",
103    "GETVARG",
104];
105
106#[cfg(test)]
107mod tests {
108    use super::*;
109
110    #[test]
111    fn op_count_matches_table() {
112        assert_eq!(OPNAMES.len(), OP_COUNT);
113    }
114
115    #[test]
116    fn first_and_last_opcodes() {
117        assert_eq!(OPNAMES[0], "MOVE");
118        assert_eq!(OPNAMES[OP_COUNT - 1], "GETVARG");
119    }
120}