Skip to main content

lua_code/
opcodes.rs

1//! Opcode definitions and instruction encoding/decoding for the Lua 5.4 VM.
2//!
3//! Ports `src/lopcodes.c` (the `luaP_opmodes` table) and `src/lopcodes.h`
4//! (the `OpCode`/`OpMode` enums, field-size constants, and instruction
5//! accessor macros). Per PORTING.md §1, headers merge into their consuming
6//! `.rs`.
7//!
8//! C source preserved inline as `
9
10
11// ─── Instruction format diagram ──────────────────────────────────────────────
12//
13
14// ─── OpMode ──────────────────────────────────────────────────────────────────
15
16/// Instruction addressing mode.
17///
18#[derive(Debug, Clone, Copy, PartialEq, Eq)]
19#[repr(u8)]
20pub enum OpMode {
21    Abc = 0,
22    ABx = 1,
23    AsBx = 2,
24    Ax = 3,
25    SJ = 4,
26}
27
28// ─── Field size constants ─────────────────────────────────────────────────────
29//
30
31pub const SIZE_C: u32 = 8;
32pub const SIZE_B: u32 = 8;
33pub const SIZE_BX: u32 = SIZE_C + SIZE_B + 1;
34pub const SIZE_A: u32 = 8;
35pub const SIZE_AX: u32 = SIZE_BX + SIZE_A;
36pub const SIZE_S_J: u32 = SIZE_BX + SIZE_A;
37pub const SIZE_OP: u32 = 7;
38
39// ─── Field position constants ─────────────────────────────────────────────────
40//
41
42pub const POS_OP: u32 = 0;
43pub const POS_A: u32 = POS_OP + SIZE_OP;
44pub const POS_K: u32 = POS_A + SIZE_A;
45pub const POS_B: u32 = POS_K + 1;
46pub const POS_C: u32 = POS_B + SIZE_B;
47pub const POS_BX: u32 = POS_K;
48pub const POS_AX: u32 = POS_A;
49pub const POS_S_J: u32 = POS_A;
50
51// ─── Argument limit constants ─────────────────────────────────────────────────
52//
53
54pub const MAXARG_BX: u32 = (1u32 << SIZE_BX) - 1;
55pub const OFFSET_S_BX: i32 = (MAXARG_BX >> 1) as i32;
56pub const MAXARG_AX: u32 = (1u32 << SIZE_AX) - 1;
57pub const MAXARG_S_J: u32 = (1u32 << SIZE_S_J) - 1;
58pub const OFFSET_S_J: i32 = (MAXARG_S_J >> 1) as i32;
59pub const MAXARG_A: u32 = (1u32 << SIZE_A) - 1;
60pub const MAXARG_B: u32 = (1u32 << SIZE_B) - 1;
61pub const MAXARG_C: u32 = (1u32 << SIZE_C) - 1;
62pub const OFFSET_S_C: i32 = (MAXARG_C >> 1) as i32;
63
64/// Sentinel "no register" value that fits in 8 bits.
65///
66pub const NO_REG: u32 = MAXARG_A;
67
68/// Maximum RK index (for debugging only).
69///
70pub const MAXINDEXRK: u32 = MAXARG_B;
71
72/// Number of list items to accumulate before a SETLIST instruction.
73///
74pub const LFIELDS_PER_FLUSH: u32 = 50;
75
76// ─── OpCode enum ─────────────────────────────────────────────────────────────
77//
78//
79// ORDER OP — variant discriminants must match `lopcodes.h` exactly.
80// The VM casts the raw opcode field directly to this enum.
81
82/// The opcode enum is owned by `lua-vm` (the VM hot path decodes against
83/// it directly); `lua-code` re-exports it so codegen and the VM share one
84/// definition. `OpCode::from_u32` is the canonical decoder.
85pub use lua_vm::vm::OpCode;
86
87/// Total number of opcodes.
88///
89pub const NUM_OPCODES: usize = OpCode::ExtraArg as usize + 1;
90
91
92// ─── opmode_byte helper ───────────────────────────────────────────────────────
93//
94//        (((mm)<<7) | ((ot)<<6) | ((it)<<5) | ((t)<<4) | ((a)<<3) | (m))
95//
96// Bit layout for each entry in OP_MODES:
97//   bits 0-2: OpMode value (Abc=0 ABx=1 AsBx=2 Ax=3 SJ=4)
98//   bit 3:    instruction sets register A
99//   bit 4:    is a test (next instruction must be a jump)
100//   bit 5:    instruction uses L->top from previous (IT mode)
101//   bit 6:    instruction sets L->top for next (OT mode)
102//   bit 7:    is a metamethod instruction (MM)
103
104const fn opmode_byte(mm: u8, ot: u8, it: u8, t: u8, a: u8, m: u8) -> u8 {
105    (mm << 7) | (ot << 6) | (it << 5) | (t << 4) | (a << 3) | m
106}
107
108// Shorthand mode constants for the OP_MODES table below.
109const M_ABC: u8 = OpMode::Abc as u8;
110const M_ABX: u8 = OpMode::ABx as u8;
111const M_ASBX: u8 = OpMode::AsBx as u8;
112const M_AX: u8 = OpMode::Ax as u8;
113const M_SJ: u8 = OpMode::SJ as u8;
114
115// ─── OP_MODES table ───────────────────────────────────────────────────────────
116//
117//
118// Per macros.tsv: LUAI_DDEF → drop (definition site, no modifier needed in Rust).
119// Per macros.tsv: LUAI_DDEC → `pub(crate) static` at the declaration site.
120
121/// Opcode properties table, indexed by `OpCode as usize`.
122///
123///
124/// Use `get_op_mode`, `test_a_mode`, etc. to query individual properties
125/// rather than indexing this array directly.
126pub(crate) const OP_MODES: [u8; NUM_OPCODES] = [
127    opmode_byte(0, 0, 0, 0, 1, M_ABC),
128    opmode_byte(0, 0, 0, 0, 1, M_ASBX),
129    opmode_byte(0, 0, 0, 0, 1, M_ASBX),
130    opmode_byte(0, 0, 0, 0, 1, M_ABX),
131    opmode_byte(0, 0, 0, 0, 1, M_ABX),
132    opmode_byte(0, 0, 0, 0, 1, M_ABC),
133    opmode_byte(0, 0, 0, 0, 1, M_ABC),
134    opmode_byte(0, 0, 0, 0, 1, M_ABC),
135    opmode_byte(0, 0, 0, 0, 1, M_ABC),
136    opmode_byte(0, 0, 0, 0, 1, M_ABC),
137    opmode_byte(0, 0, 0, 0, 0, M_ABC),
138    opmode_byte(0, 0, 0, 0, 1, M_ABC),
139    opmode_byte(0, 0, 0, 0, 1, M_ABC),
140    opmode_byte(0, 0, 0, 0, 1, M_ABC),
141    opmode_byte(0, 0, 0, 0, 1, M_ABC),
142    opmode_byte(0, 0, 0, 0, 0, M_ABC),
143    opmode_byte(0, 0, 0, 0, 0, M_ABC),
144    opmode_byte(0, 0, 0, 0, 0, M_ABC),
145    opmode_byte(0, 0, 0, 0, 0, M_ABC),
146    opmode_byte(0, 0, 0, 0, 1, M_ABC),
147    opmode_byte(0, 0, 0, 0, 1, M_ABC),
148    opmode_byte(0, 0, 0, 0, 1, M_ABC),
149    opmode_byte(0, 0, 0, 0, 1, M_ABC),
150    opmode_byte(0, 0, 0, 0, 1, M_ABC),
151    opmode_byte(0, 0, 0, 0, 1, M_ABC),
152    opmode_byte(0, 0, 0, 0, 1, M_ABC),
153    opmode_byte(0, 0, 0, 0, 1, M_ABC),
154    opmode_byte(0, 0, 0, 0, 1, M_ABC),
155    opmode_byte(0, 0, 0, 0, 1, M_ABC),
156    opmode_byte(0, 0, 0, 0, 1, M_ABC),
157    opmode_byte(0, 0, 0, 0, 1, M_ABC),
158    opmode_byte(0, 0, 0, 0, 1, M_ABC),
159    opmode_byte(0, 0, 0, 0, 1, M_ABC),
160    opmode_byte(0, 0, 0, 0, 1, M_ABC),
161    opmode_byte(0, 0, 0, 0, 1, M_ABC),
162    opmode_byte(0, 0, 0, 0, 1, M_ABC),
163    opmode_byte(0, 0, 0, 0, 1, M_ABC),
164    opmode_byte(0, 0, 0, 0, 1, M_ABC),
165    opmode_byte(0, 0, 0, 0, 1, M_ABC),
166    opmode_byte(0, 0, 0, 0, 1, M_ABC),
167    opmode_byte(0, 0, 0, 0, 1, M_ABC),
168    opmode_byte(0, 0, 0, 0, 1, M_ABC),
169    opmode_byte(0, 0, 0, 0, 1, M_ABC),
170    opmode_byte(0, 0, 0, 0, 1, M_ABC),
171    opmode_byte(0, 0, 0, 0, 1, M_ABC),
172    opmode_byte(0, 0, 0, 0, 1, M_ABC),
173    opmode_byte(1, 0, 0, 0, 0, M_ABC),
174    opmode_byte(1, 0, 0, 0, 0, M_ABC),
175    opmode_byte(1, 0, 0, 0, 0, M_ABC),
176    opmode_byte(0, 0, 0, 0, 1, M_ABC),
177    opmode_byte(0, 0, 0, 0, 1, M_ABC),
178    opmode_byte(0, 0, 0, 0, 1, M_ABC),
179    opmode_byte(0, 0, 0, 0, 1, M_ABC),
180    opmode_byte(0, 0, 0, 0, 1, M_ABC),
181    opmode_byte(0, 0, 0, 0, 0, M_ABC),
182    opmode_byte(0, 0, 0, 0, 0, M_ABC),
183    opmode_byte(0, 0, 0, 0, 0, M_SJ),
184    opmode_byte(0, 0, 0, 1, 0, M_ABC),
185    opmode_byte(0, 0, 0, 1, 0, M_ABC),
186    opmode_byte(0, 0, 0, 1, 0, M_ABC),
187    opmode_byte(0, 0, 0, 1, 0, M_ABC),
188    opmode_byte(0, 0, 0, 1, 0, M_ABC),
189    opmode_byte(0, 0, 0, 1, 0, M_ABC),
190    opmode_byte(0, 0, 0, 1, 0, M_ABC),
191    opmode_byte(0, 0, 0, 1, 0, M_ABC),
192    opmode_byte(0, 0, 0, 1, 0, M_ABC),
193    opmode_byte(0, 0, 0, 1, 0, M_ABC),
194    opmode_byte(0, 0, 0, 1, 1, M_ABC),
195    opmode_byte(0, 1, 1, 0, 1, M_ABC),
196    opmode_byte(0, 1, 1, 0, 1, M_ABC),
197    opmode_byte(0, 0, 1, 0, 0, M_ABC),
198    opmode_byte(0, 0, 0, 0, 0, M_ABC),
199    opmode_byte(0, 0, 0, 0, 0, M_ABC),
200    opmode_byte(0, 0, 0, 0, 1, M_ABX),
201    opmode_byte(0, 0, 0, 0, 1, M_ABX),
202    opmode_byte(0, 0, 0, 0, 0, M_ABX),
203    opmode_byte(0, 0, 0, 0, 0, M_ABC),
204    opmode_byte(0, 0, 0, 0, 1, M_ABX),
205    opmode_byte(0, 0, 1, 0, 0, M_ABC),
206    opmode_byte(0, 0, 0, 0, 1, M_ABX),
207    opmode_byte(0, 1, 0, 0, 1, M_ABC),
208    opmode_byte(0, 0, 1, 0, 1, M_ABC),
209    opmode_byte(0, 0, 0, 0, 0, M_AX),
210];
211
212// ─── OP_MODES accessors ───────────────────────────────────────────────────────
213//
214
215/// Extract the `OpMode` for an opcode.
216///
217pub fn get_op_mode(op: OpCode) -> OpMode {
218    match OP_MODES[op as usize] & 7 {
219        0 => OpMode::Abc,
220        1 => OpMode::ABx,
221        2 => OpMode::AsBx,
222        3 => OpMode::Ax,
223        4 => OpMode::SJ,
224        // PERF(port): unreachable branch — values 5-7 are unused; profile in Phase B
225        _ => OpMode::Abc,
226    }
227}
228
229/// True if this opcode writes to register A.
230///
231#[inline]
232pub fn test_a_mode(op: OpCode) -> bool {
233    (OP_MODES[op as usize] & (1 << 3)) != 0
234}
235
236/// True if this opcode is a test (the next instruction must be a jump).
237///
238#[inline]
239pub fn test_t_mode(op: OpCode) -> bool {
240    (OP_MODES[op as usize] & (1 << 4)) != 0
241}
242
243/// True if this opcode uses `L->top` as set by the previous instruction (B == 0 case).
244///
245#[inline]
246pub fn test_it_mode(op: OpCode) -> bool {
247    (OP_MODES[op as usize] & (1 << 5)) != 0
248}
249
250/// True if this opcode sets `L->top` for the next instruction (C == 0 case).
251///
252#[inline]
253pub fn test_ot_mode(op: OpCode) -> bool {
254    (OP_MODES[op as usize] & (1 << 6)) != 0
255}
256
257/// True if this opcode is a metamethod call.
258///
259#[inline]
260pub fn test_mm_mode(op: OpCode) -> bool {
261    (OP_MODES[op as usize] & (1 << 7)) != 0
262}
263
264// ─── Instruction newtype ──────────────────────────────────────────────────────
265//
266// Per types.tsv: `Instruction` is a `u32` newtype; bytecode word.
267// All accessor/builder macros from lopcodes.h become methods here.
268
269/// A single Lua bytecode instruction (unsigned 32-bit word).
270///
271#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
272#[repr(transparent)]
273pub struct Instruction(pub u32);
274
275impl Instruction {
276    // ── Low-level field accessors ─────────────────────────────────────────
277
278    /// Extract a bit-field of `size` bits at position `pos`.
279    ///
280    #[inline]
281    pub const fn get_arg(self, pos: u32, size: u32) -> u32 {
282        (self.0 >> pos) & ((1u32 << size) - 1)
283    }
284
285    /// Set a bit-field of `size` bits at position `pos` to `v`.
286    ///
287    #[inline]
288    pub fn set_arg(&mut self, v: u32, pos: u32, size: u32) {
289        let mask = ((1u32 << size) - 1) << pos;
290        self.0 = (self.0 & !mask) | ((v << pos) & mask);
291    }
292
293    // ── Opcode field ──────────────────────────────────────────────────────
294
295    /// Extract the opcode.
296    ///
297    #[inline]
298    pub fn opcode(self) -> Option<OpCode> {
299        OpCode::from_u32(self.get_arg(POS_OP, SIZE_OP))
300    }
301
302    /// Replace the opcode field.
303    ///
304    #[inline]
305    pub fn set_opcode(&mut self, op: OpCode) {
306        self.set_arg(op as u32, POS_OP, SIZE_OP);
307    }
308
309    // ── A field ───────────────────────────────────────────────────────────
310
311    #[inline]
312    pub const fn arg_a(self) -> u32 {
313        self.get_arg(POS_A, SIZE_A)
314    }
315
316    #[inline]
317    pub fn set_arg_a(&mut self, v: u32) {
318        self.set_arg(v, POS_A, SIZE_A);
319    }
320
321    // ── k bit ─────────────────────────────────────────────────────────────
322
323    #[inline]
324    pub const fn arg_k(self) -> u32 {
325        self.get_arg(POS_K, 1)
326    }
327
328    #[inline]
329    pub const fn test_k(self) -> bool {
330        self.arg_k() != 0
331    }
332
333    #[inline]
334    pub fn set_arg_k(&mut self, v: u32) {
335        self.set_arg(v, POS_K, 1);
336    }
337
338    // ── B field (iABC only) ───────────────────────────────────────────────
339
340    #[inline]
341    pub const fn arg_b(self) -> u32 {
342        self.get_arg(POS_B, SIZE_B)
343    }
344
345    #[inline]
346    pub const fn arg_s_b(self) -> i32 {
347        self.arg_b() as i32 - OFFSET_S_C
348    }
349
350    #[inline]
351    pub fn set_arg_b(&mut self, v: u32) {
352        self.set_arg(v, POS_B, SIZE_B);
353    }
354
355    // ── C field (iABC only) ───────────────────────────────────────────────
356
357    #[inline]
358    pub const fn arg_c(self) -> u32 {
359        self.get_arg(POS_C, SIZE_C)
360    }
361
362    #[inline]
363    pub const fn arg_s_c(self) -> i32 {
364        self.arg_c() as i32 - OFFSET_S_C
365    }
366
367    #[inline]
368    pub fn set_arg_c(&mut self, v: u32) {
369        self.set_arg(v, POS_C, SIZE_C);
370    }
371
372    // ── Bx field (iABx / iAsBx) ──────────────────────────────────────────
373
374    #[inline]
375    pub const fn arg_bx(self) -> u32 {
376        self.get_arg(POS_BX, SIZE_BX)
377    }
378
379    #[inline]
380    pub fn set_arg_bx(&mut self, v: u32) {
381        self.set_arg(v, POS_BX, SIZE_BX);
382    }
383
384    #[inline]
385    pub const fn arg_s_bx(self) -> i32 {
386        self.arg_bx() as i32 - OFFSET_S_BX
387    }
388
389    #[inline]
390    pub fn set_arg_s_bx(&mut self, b: i32) {
391        self.set_arg_bx((b + OFFSET_S_BX) as u32);
392    }
393
394    // ── Ax field (iAx) ────────────────────────────────────────────────────
395
396    #[inline]
397    pub const fn arg_ax(self) -> u32 {
398        self.get_arg(POS_AX, SIZE_AX)
399    }
400
401    #[inline]
402    pub fn set_arg_ax(&mut self, v: u32) {
403        self.set_arg(v, POS_AX, SIZE_AX);
404    }
405
406    // ── sJ field (isJ) ────────────────────────────────────────────────────
407
408    #[inline]
409    pub const fn arg_s_j(self) -> i32 {
410        self.get_arg(POS_S_J, SIZE_S_J) as i32 - OFFSET_S_J
411    }
412
413    #[inline]
414    pub fn set_arg_s_j(&mut self, j: i32) {
415        self.set_arg((j + OFFSET_S_J) as u32, POS_S_J, SIZE_S_J);
416    }
417
418    // ── Instruction builders ──────────────────────────────────────────────
419
420    /// Build an `iABC` instruction.
421    ///
422    #[inline]
423    pub fn abck(op: OpCode, a: u32, b: u32, c: u32, k: u32) -> Self {
424        Self(
425            ((op as u32) << POS_OP)
426                | (a << POS_A)
427                | (b << POS_B)
428                | (c << POS_C)
429                | (k << POS_K),
430        )
431    }
432
433    /// Build an `iABx` instruction.
434    ///
435    #[inline]
436    pub fn abx(op: OpCode, a: u32, bc: u32) -> Self {
437        Self(((op as u32) << POS_OP) | (a << POS_A) | (bc << POS_BX))
438    }
439
440    /// Build an `iAx` instruction.
441    ///
442    #[inline]
443    pub fn ax(op: OpCode, a: u32) -> Self {
444        Self(((op as u32) << POS_OP) | (a << POS_AX))
445    }
446
447    /// Build an `isJ` instruction.
448    ///
449    #[inline]
450    pub fn sj(op: OpCode, j: u32, k: u32) -> Self {
451        Self(((op as u32) << POS_OP) | (j << POS_S_J) | (k << POS_K))
452    }
453
454    // ── Mode query helpers (isOT / isIT) ──────────────────────────────────
455
456    /// True if this instruction sets `L->top` for the next instruction.
457    ///
458    /// `(testOTMode(GET_OPCODE(i)) && GETARG_C(i) == 0) || GET_OPCODE(i) == OP_TAILCALL`
459    pub fn is_out_top(self) -> bool {
460        match self.opcode() {
461            Some(op) => (test_ot_mode(op) && self.arg_c() == 0) || op == OpCode::TailCall,
462            None => false,
463        }
464    }
465
466    /// True if this instruction uses `L->top` from the previous instruction.
467    ///
468    pub fn is_in_top(self) -> bool {
469        match self.opcode() {
470            Some(op) => test_it_mode(op) && self.arg_b() == 0,
471            None => false,
472        }
473    }
474
475    /// Return the `OpMode` for this instruction.
476    ///
477    pub fn op_mode(self) -> Option<OpMode> {
478        self.opcode().map(get_op_mode)
479    }
480}
481
482// ─── Signed-argument encode/decode helpers ────────────────────────────────────
483//
484//
485// These are inline helpers used at call sites; the Instruction methods above
486// incorporate them, but standalone functions are provided for codegen use.
487
488/// Encode a signed integer into an unsigned C-field value.
489///
490#[inline]
491pub const fn int_to_s_c(i: i32) -> u32 {
492    (i + OFFSET_S_C) as u32
493}
494
495/// Decode a C-field unsigned value to a signed integer.
496///
497#[inline]
498pub const fn s_c_to_int(i: u32) -> i32 {
499    i as i32 - OFFSET_S_C
500}
501
502// ─── Tests ────────────────────────────────────────────────────────────────────
503
504#[cfg(test)]
505mod tests {
506    use super::*;
507
508    #[test]
509    fn num_opcodes_matches_enum() {
510        assert_eq!(NUM_OPCODES, 83);
511        assert_eq!(OpCode::ExtraArg as usize, 82);
512    }
513
514    #[test]
515    fn op_modes_table_length() {
516        assert_eq!(OP_MODES.len(), NUM_OPCODES);
517    }
518
519    #[test]
520    fn opmode_byte_values() {
521        assert_eq!(OP_MODES[OpCode::Move as usize], 0b00001000); // a=1, mode=iABC=0 → 8
522        assert_eq!(OP_MODES[OpCode::LoadI as usize], 0b00001010); // a=1, mode=iAsBx=2 → 10
523        assert_eq!(OP_MODES[OpCode::Jmp as usize], 0b00000100); // a=0, mode=isJ=4 → 4
524        assert_eq!(OP_MODES[OpCode::MmBin as usize], 0b10000000); // mm=1, a=0, mode=iABC=0 → 128
525        assert_eq!(OP_MODES[OpCode::Call as usize], 0b01101000); // ot=1,it=1,a=1,mode=0 → 104
526        assert_eq!(OP_MODES[OpCode::ExtraArg as usize], 0b00000011); // mode=iAx=3 → 3
527    }
528
529    #[test]
530    fn from_u32_round_trip() {
531        for i in 0..NUM_OPCODES {
532            let op = OpCode::from_u32(i as u32).expect("valid opcode");
533            assert_eq!(op as usize, i);
534        }
535        assert!(OpCode::from_u32(83).is_none());
536    }
537
538    #[test]
539    fn instruction_arg_a() {
540        let i = Instruction::abck(OpCode::Move, 5, 3, 0, 0);
541        assert_eq!(i.arg_a(), 5);
542        assert_eq!(i.arg_b(), 3);
543    }
544
545    #[test]
546    fn instruction_s_bx_round_trip() {
547        let mut i = Instruction::abx(OpCode::LoadK, 0, 0);
548        i.set_arg_s_bx(-10);
549        assert_eq!(i.arg_s_bx(), -10);
550        i.set_arg_s_bx(0);
551        assert_eq!(i.arg_s_bx(), 0);
552        i.set_arg_s_bx(100);
553        assert_eq!(i.arg_s_bx(), 100);
554    }
555
556    #[test]
557    fn instruction_s_j_round_trip() {
558        let mut i = Instruction::sj(OpCode::Jmp, (OFFSET_S_J) as u32, 0);
559        assert_eq!(i.arg_s_j(), 0);
560        i.set_arg_s_j(42);
561        assert_eq!(i.arg_s_j(), 42);
562        i.set_arg_s_j(-1);
563        assert_eq!(i.arg_s_j(), -1);
564    }
565
566    #[test]
567    fn get_op_mode_smoke() {
568        assert_eq!(get_op_mode(OpCode::Move), OpMode::Abc);
569        assert_eq!(get_op_mode(OpCode::LoadI), OpMode::AsBx);
570        assert_eq!(get_op_mode(OpCode::LoadK), OpMode::ABx);
571        assert_eq!(get_op_mode(OpCode::Jmp), OpMode::SJ);
572        assert_eq!(get_op_mode(OpCode::ExtraArg), OpMode::Ax);
573    }
574
575    #[test]
576    fn int_to_s_c_round_trip() {
577        assert_eq!(s_c_to_int(int_to_s_c(0)), 0);
578        assert_eq!(s_c_to_int(int_to_s_c(100)), 100);
579        assert_eq!(s_c_to_int(int_to_s_c(-50)), -50);
580    }
581}
582
583// ──────────────────────────────────────────────────────────────────────────
584// PORT STATUS
585//   source:        src/lopcodes.c  (104 lines, 0 functions — data only)
586//                  src/lopcodes.h  (406 lines, merged per PORTING.md §1)
587//   target_crate:  lua-code
588//   confidence:    high
589//   todos:         1
590//   port_notes:    1
591//   unsafe_blocks: 0
592//   notes:         Pure data/encoding translation; OpCode::from_u32 needs
593//                  Phase B review for transmute vs. num_enum. Self_ rename
594//                  is permanent (Rust keyword conflict).
595// ──────────────────────────────────────────────────────────────────────────