Skip to main content

ruau_bytecode/
opcodes.rs

1//! Stable Luau bytecode numeric tags.
2
3use serde::{Deserialize, Serialize};
4
5/// Luau bytecode opcode stored in the low byte of each instruction word.
6#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)]
7#[repr(u8)]
8pub enum Opcode {
9    /// No operation.
10    Nop = 0,
11    /// Debugger break.
12    Break = 1,
13    /// Load nil.
14    LoadNil = 2,
15    /// Load boolean.
16    LoadB = 3,
17    /// Load small number.
18    LoadN = 4,
19    /// Load constant.
20    LoadK = 5,
21    /// Move register.
22    Move = 6,
23    /// Get global.
24    GetGlobal = 7,
25    /// Set global.
26    SetGlobal = 8,
27    /// Get upvalue.
28    GetUpval = 9,
29    /// Set upvalue.
30    SetUpval = 10,
31    /// Close upvalues.
32    CloseUpvals = 11,
33    /// Get import.
34    GetImport = 12,
35    /// Get table by register key.
36    GetTable = 13,
37    /// Set table by register key.
38    SetTable = 14,
39    /// Get table by string key.
40    GetTableKs = 15,
41    /// Set table by string key.
42    SetTableKs = 16,
43    /// Get table by small integer key.
44    GetTableN = 17,
45    /// Set table by small integer key.
46    SetTableN = 18,
47    /// New closure.
48    NewClosure = 19,
49    /// Method-call preparation.
50    NameCall = 20,
51    /// Function call.
52    Call = 21,
53    /// Return from function.
54    Return = 22,
55    /// Relative jump.
56    Jump = 23,
57    /// Backedge jump.
58    JumpBack = 24,
59    /// Conditional truthy jump.
60    JumpIf = 25,
61    /// Conditional falsey jump.
62    JumpIfNot = 26,
63    /// Equality jump.
64    JumpIfEq = 27,
65    /// Less-or-equal jump.
66    JumpIfLe = 28,
67    /// Less-than jump.
68    JumpIfLt = 29,
69    /// Inequality jump.
70    JumpIfNotEq = 30,
71    /// Not less-or-equal jump.
72    JumpIfNotLe = 31,
73    /// Not less-than jump.
74    JumpIfNotLt = 32,
75    /// Addition.
76    Add = 33,
77    /// Subtraction.
78    Sub = 34,
79    /// Multiplication.
80    Mul = 35,
81    /// Division.
82    Div = 36,
83    /// Modulo.
84    Mod = 37,
85    /// Power.
86    Pow = 38,
87    /// Addition with constant.
88    AddK = 39,
89    /// Subtraction with constant.
90    SubK = 40,
91    /// Multiplication with constant.
92    MulK = 41,
93    /// Division with constant.
94    DivK = 42,
95    /// Modulo with constant.
96    ModK = 43,
97    /// Power with constant.
98    PowK = 44,
99    /// Logical and.
100    And = 45,
101    /// Logical or.
102    Or = 46,
103    /// Logical and with constant.
104    AndK = 47,
105    /// Logical or with constant.
106    OrK = 48,
107    /// Concatenation.
108    Concat = 49,
109    /// Logical not.
110    Not = 50,
111    /// Numeric negation.
112    Minus = 51,
113    /// Length.
114    Length = 52,
115    /// Create table.
116    NewTable = 53,
117    /// Duplicate table template.
118    DupTable = 54,
119    /// Set list.
120    SetList = 55,
121    /// Numeric-for preparation.
122    ForNPrep = 56,
123    /// Numeric-for loop.
124    ForNLoop = 57,
125    /// Generic-for loop.
126    ForGLoop = 58,
127    /// Generic-for preparation for inext.
128    ForGPrepInext = 59,
129    /// Fastcall with three register arguments.
130    FastCall3 = 60,
131    /// Generic-for preparation for next.
132    ForGPrepNext = 61,
133    /// Runtime native call pseudo-instruction.
134    NativeCall = 62,
135    /// Get varargs.
136    GetVarargs = 63,
137    /// Duplicate closure.
138    DupClosure = 64,
139    /// Prepare varargs.
140    PrepVarargs = 65,
141    /// Load extended constant.
142    LoadKx = 66,
143    /// Long relative jump.
144    JumpX = 67,
145    /// Fastcall.
146    FastCall = 68,
147    /// Coverage counter.
148    Coverage = 69,
149    /// Upvalue capture.
150    Capture = 70,
151    /// Constant-minus-register subtraction.
152    SubRk = 71,
153    /// Constant-divided-by-register division.
154    DivRk = 72,
155    /// Fastcall with one register argument.
156    FastCall1 = 73,
157    /// Fastcall with two register arguments.
158    FastCall2 = 74,
159    /// Fastcall with one register and one constant argument.
160    FastCall2K = 75,
161    /// Generic-for preparation.
162    ForGPrep = 76,
163    /// Nil equality jump.
164    JumpXEqKNil = 77,
165    /// Boolean equality jump.
166    JumpXEqKB = 78,
167    /// Number equality jump.
168    JumpXEqKN = 79,
169    /// String equality jump.
170    JumpXEqKS = 80,
171    /// Floor division.
172    IDiv = 81,
173    /// Floor division with constant.
174    IDivK = 82,
175    /// Userdata field get.
176    GetUdataKs = 83,
177    /// Userdata field set.
178    SetUdataKs = 84,
179    /// Userdata method-call preparation.
180    NameCallUdata = 85,
181    /// Register class member.
182    NewClassMember = 86,
183    /// Call with feedback slot.
184    CallFb = 87,
185    /// Compare closure proto.
186    CmpProto = 88,
187    /// Reify a class object.
188    NewClass = 89,
189}
190
191impl Opcode {
192    /// Sentinel one past the largest valid opcode.
193    pub const COUNT: u8 = 90;
194
195    /// Converts the serialized opcode byte into a typed opcode.
196    #[must_use]
197    pub const fn from_byte(value: u8) -> Option<Self> {
198        Some(match value {
199            0 => Self::Nop,
200            1 => Self::Break,
201            2 => Self::LoadNil,
202            3 => Self::LoadB,
203            4 => Self::LoadN,
204            5 => Self::LoadK,
205            6 => Self::Move,
206            7 => Self::GetGlobal,
207            8 => Self::SetGlobal,
208            9 => Self::GetUpval,
209            10 => Self::SetUpval,
210            11 => Self::CloseUpvals,
211            12 => Self::GetImport,
212            13 => Self::GetTable,
213            14 => Self::SetTable,
214            15 => Self::GetTableKs,
215            16 => Self::SetTableKs,
216            17 => Self::GetTableN,
217            18 => Self::SetTableN,
218            19 => Self::NewClosure,
219            20 => Self::NameCall,
220            21 => Self::Call,
221            22 => Self::Return,
222            23 => Self::Jump,
223            24 => Self::JumpBack,
224            25 => Self::JumpIf,
225            26 => Self::JumpIfNot,
226            27 => Self::JumpIfEq,
227            28 => Self::JumpIfLe,
228            29 => Self::JumpIfLt,
229            30 => Self::JumpIfNotEq,
230            31 => Self::JumpIfNotLe,
231            32 => Self::JumpIfNotLt,
232            33 => Self::Add,
233            34 => Self::Sub,
234            35 => Self::Mul,
235            36 => Self::Div,
236            37 => Self::Mod,
237            38 => Self::Pow,
238            39 => Self::AddK,
239            40 => Self::SubK,
240            41 => Self::MulK,
241            42 => Self::DivK,
242            43 => Self::ModK,
243            44 => Self::PowK,
244            45 => Self::And,
245            46 => Self::Or,
246            47 => Self::AndK,
247            48 => Self::OrK,
248            49 => Self::Concat,
249            50 => Self::Not,
250            51 => Self::Minus,
251            52 => Self::Length,
252            53 => Self::NewTable,
253            54 => Self::DupTable,
254            55 => Self::SetList,
255            56 => Self::ForNPrep,
256            57 => Self::ForNLoop,
257            58 => Self::ForGLoop,
258            59 => Self::ForGPrepInext,
259            60 => Self::FastCall3,
260            61 => Self::ForGPrepNext,
261            62 => Self::NativeCall,
262            63 => Self::GetVarargs,
263            64 => Self::DupClosure,
264            65 => Self::PrepVarargs,
265            66 => Self::LoadKx,
266            67 => Self::JumpX,
267            68 => Self::FastCall,
268            69 => Self::Coverage,
269            70 => Self::Capture,
270            71 => Self::SubRk,
271            72 => Self::DivRk,
272            73 => Self::FastCall1,
273            74 => Self::FastCall2,
274            75 => Self::FastCall2K,
275            76 => Self::ForGPrep,
276            77 => Self::JumpXEqKNil,
277            78 => Self::JumpXEqKB,
278            79 => Self::JumpXEqKN,
279            80 => Self::JumpXEqKS,
280            81 => Self::IDiv,
281            82 => Self::IDivK,
282            83 => Self::GetUdataKs,
283            84 => Self::SetUdataKs,
284            85 => Self::NameCallUdata,
285            86 => Self::NewClassMember,
286            87 => Self::CallFb,
287            88 => Self::CmpProto,
288            89 => Self::NewClass,
289            _ => return None,
290        })
291    }
292
293    /// Serialized numeric value.
294    #[must_use]
295    pub const fn byte(self) -> u8 {
296        self as u8
297    }
298
299    /// Number of 32-bit words occupied by the instruction.
300    #[must_use]
301    pub const fn instruction_len(self) -> usize {
302        match self {
303            Self::GetGlobal
304            | Self::SetGlobal
305            | Self::GetImport
306            | Self::GetTableKs
307            | Self::SetTableKs
308            | Self::NameCall
309            | Self::JumpIfEq
310            | Self::JumpIfLe
311            | Self::JumpIfLt
312            | Self::JumpIfNotEq
313            | Self::JumpIfNotLe
314            | Self::JumpIfNotLt
315            | Self::NewTable
316            | Self::SetList
317            | Self::ForGLoop
318            | Self::LoadKx
319            | Self::FastCall2
320            | Self::FastCall2K
321            | Self::FastCall3
322            | Self::JumpXEqKNil
323            | Self::JumpXEqKB
324            | Self::JumpXEqKN
325            | Self::JumpXEqKS
326            | Self::GetUdataKs
327            | Self::SetUdataKs
328            | Self::NameCallUdata
329            | Self::NewClassMember
330            | Self::CallFb
331            | Self::CmpProto
332            | Self::NewClass => 2,
333            _ => 1,
334        }
335    }
336}
337
338/// Constant table tag.
339#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)]
340#[repr(u8)]
341pub enum ConstantTag {
342    /// Nil constant.
343    Nil = 0,
344    /// Boolean constant.
345    Boolean = 1,
346    /// Number constant.
347    Number = 2,
348    /// String constant.
349    String = 3,
350    /// Import constant.
351    Import = 4,
352    /// Table-shape constant.
353    Table = 5,
354    /// Closure constant.
355    Closure = 6,
356    /// Vector constant.
357    Vector = 7,
358    /// Table-shape constant with pre-filled constants.
359    TableWithConstants = 8,
360    /// 64-bit integer constant.
361    Integer = 9,
362    /// Class-shape constant.
363    ClassShape = 10,
364    /// Double-precision vector constant.
365    VectorDouble = 11,
366}
367
368impl ConstantTag {
369    /// Converts a serialized constant tag.
370    #[must_use]
371    pub const fn from_byte(value: u8) -> Option<Self> {
372        Some(match value {
373            0 => Self::Nil,
374            1 => Self::Boolean,
375            2 => Self::Number,
376            3 => Self::String,
377            4 => Self::Import,
378            5 => Self::Table,
379            6 => Self::Closure,
380            7 => Self::Vector,
381            8 => Self::TableWithConstants,
382            9 => Self::Integer,
383            10 => Self::ClassShape,
384            11 => Self::VectorDouble,
385            _ => return None,
386        })
387    }
388}
389
390/// Bytecode type-info tag.
391#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)]
392#[repr(u16)]
393pub enum TypeTag {
394    /// Nil type.
395    Nil = 0,
396    /// Boolean type.
397    Boolean = 1,
398    /// Number type.
399    Number = 2,
400    /// String type.
401    String = 3,
402    /// Table type.
403    Table = 4,
404    /// Function type.
405    Function = 5,
406    /// Thread type.
407    Thread = 6,
408    /// Userdata type.
409    Userdata = 7,
410    /// Vector type.
411    Vector = 8,
412    /// Buffer type.
413    Buffer = 9,
414    /// Integer type.
415    Integer = 10,
416    /// Any type.
417    Any = 15,
418    /// First tagged userdata type.
419    TaggedUserdataBase = 64,
420    /// End of tagged userdata range.
421    TaggedUserdataEnd = 96,
422    /// Optional-bit mask.
423    OptionalBit = 128,
424    /// Invalid sentinel.
425    Invalid = 256,
426}
427
428/// Builtin function ids used by fastcall instructions.
429pub struct BuiltinFunction;
430
431#[allow(missing_docs)]
432impl BuiltinFunction {
433    /// No builtin.
434    pub const NONE: u8 = 0;
435    /// `assert`.
436    pub const ASSERT: u8 = 1;
437    pub const MATH_ABS: u8 = 2;
438    pub const MATH_ACOS: u8 = 3;
439    pub const MATH_ASIN: u8 = 4;
440    pub const MATH_ATAN2: u8 = 5;
441    pub const MATH_ATAN: u8 = 6;
442    pub const MATH_CEIL: u8 = 7;
443    pub const MATH_COSH: u8 = 8;
444    pub const MATH_COS: u8 = 9;
445    pub const MATH_DEG: u8 = 10;
446    pub const MATH_EXP: u8 = 11;
447    pub const MATH_FLOOR: u8 = 12;
448    pub const MATH_FMOD: u8 = 13;
449    pub const MATH_FREXP: u8 = 14;
450    pub const MATH_LDEXP: u8 = 15;
451    pub const MATH_LOG10: u8 = 16;
452    pub const MATH_LOG: u8 = 17;
453    pub const MATH_MAX: u8 = 18;
454    pub const MATH_MIN: u8 = 19;
455    pub const MATH_MODF: u8 = 20;
456    pub const MATH_POW: u8 = 21;
457    pub const MATH_RAD: u8 = 22;
458    pub const MATH_SINH: u8 = 23;
459    pub const MATH_SIN: u8 = 24;
460    pub const MATH_SQRT: u8 = 25;
461    pub const MATH_TANH: u8 = 26;
462    pub const MATH_TAN: u8 = 27;
463    pub const BIT32_ARSHIFT: u8 = 28;
464    pub const BIT32_BAND: u8 = 29;
465    pub const BIT32_BNOT: u8 = 30;
466    pub const BIT32_BOR: u8 = 31;
467    pub const BIT32_BXOR: u8 = 32;
468    pub const BIT32_BTEST: u8 = 33;
469    pub const BIT32_EXTRACT: u8 = 34;
470    pub const BIT32_LROTATE: u8 = 35;
471    pub const BIT32_LSHIFT: u8 = 36;
472    pub const BIT32_REPLACE: u8 = 37;
473    pub const BIT32_RROTATE: u8 = 38;
474    pub const BIT32_RSHIFT: u8 = 39;
475    pub const TYPE: u8 = 40;
476    pub const STRING_BYTE: u8 = 41;
477    pub const STRING_CHAR: u8 = 42;
478    pub const STRING_LEN: u8 = 43;
479    pub const TYPEOF: u8 = 44;
480    pub const STRING_SUB: u8 = 45;
481    pub const MATH_CLAMP: u8 = 46;
482    pub const MATH_SIGN: u8 = 47;
483    pub const MATH_ROUND: u8 = 48;
484    pub const RAWSET: u8 = 49;
485    pub const RAWGET: u8 = 50;
486    pub const RAWEQUAL: u8 = 51;
487    pub const TABLE_INSERT: u8 = 52;
488    pub const TABLE_UNPACK: u8 = 53;
489    pub const VECTOR: u8 = 54;
490    pub const BIT32_COUNTLZ: u8 = 55;
491    pub const BIT32_COUNTRZ: u8 = 56;
492    pub const SELECT_VARARG: u8 = 57;
493    pub const RAWLEN: u8 = 58;
494    pub const BIT32_EXTRACTK: u8 = 59;
495    pub const GETMETATABLE: u8 = 60;
496    pub const SETMETATABLE: u8 = 61;
497    pub const TONUMBER: u8 = 62;
498    pub const TOSTRING: u8 = 63;
499    pub const BIT32_BYTESWAP: u8 = 64;
500    pub const BUFFER_READI8: u8 = 65;
501    pub const BUFFER_READU8: u8 = 66;
502    pub const BUFFER_WRITEU8: u8 = 67;
503    pub const BUFFER_READI16: u8 = 68;
504    pub const BUFFER_READU16: u8 = 69;
505    pub const BUFFER_WRITEU16: u8 = 70;
506    pub const BUFFER_READI32: u8 = 71;
507    pub const BUFFER_READU32: u8 = 72;
508    pub const BUFFER_WRITEU32: u8 = 73;
509    pub const BUFFER_READF32: u8 = 74;
510    pub const BUFFER_WRITEF32: u8 = 75;
511    pub const BUFFER_READF64: u8 = 76;
512    pub const BUFFER_WRITEF64: u8 = 77;
513    pub const VECTOR_MAGNITUDE: u8 = 78;
514    pub const VECTOR_NORMALIZE: u8 = 79;
515    pub const VECTOR_CROSS: u8 = 80;
516    pub const VECTOR_DOT: u8 = 81;
517    pub const VECTOR_FLOOR: u8 = 82;
518    pub const VECTOR_CEIL: u8 = 83;
519    pub const VECTOR_ABS: u8 = 84;
520    pub const VECTOR_SIGN: u8 = 85;
521    pub const VECTOR_CLAMP: u8 = 86;
522    pub const VECTOR_MIN: u8 = 87;
523    pub const VECTOR_MAX: u8 = 88;
524    pub const MATH_LERP: u8 = 89;
525    pub const VECTOR_LERP: u8 = 90;
526    pub const MATH_ISNAN: u8 = 91;
527    pub const MATH_ISINF: u8 = 92;
528    pub const MATH_ISFINITE: u8 = 93;
529    pub const INTEGER_CREATE: u8 = 94;
530    pub const INTEGER_TONUMBER: u8 = 95;
531    pub const INTEGER_NEG: u8 = 96;
532    pub const INTEGER_ADD: u8 = 97;
533    pub const INTEGER_SUB: u8 = 98;
534    pub const INTEGER_MUL: u8 = 99;
535    pub const INTEGER_DIV: u8 = 100;
536    pub const INTEGER_MIN: u8 = 101;
537    pub const INTEGER_MAX: u8 = 102;
538    pub const INTEGER_REM: u8 = 103;
539    pub const INTEGER_IDIV: u8 = 104;
540    pub const INTEGER_UDIV: u8 = 105;
541    pub const INTEGER_UREM: u8 = 106;
542    pub const INTEGER_MOD: u8 = 107;
543    pub const INTEGER_CLAMP: u8 = 108;
544    pub const INTEGER_BAND: u8 = 109;
545    pub const INTEGER_BOR: u8 = 110;
546    pub const INTEGER_BNOT: u8 = 111;
547    pub const INTEGER_BXOR: u8 = 112;
548    pub const INTEGER_LT: u8 = 113;
549    pub const INTEGER_LE: u8 = 114;
550    pub const INTEGER_ULT: u8 = 115;
551    pub const INTEGER_ULE: u8 = 116;
552    pub const INTEGER_GT: u8 = 117;
553    pub const INTEGER_GE: u8 = 118;
554    pub const INTEGER_UGT: u8 = 119;
555    pub const INTEGER_UGE: u8 = 120;
556    pub const INTEGER_LSHIFT: u8 = 121;
557    pub const INTEGER_RSHIFT: u8 = 122;
558    pub const INTEGER_ARSHIFT: u8 = 123;
559    pub const INTEGER_LROTATE: u8 = 124;
560    pub const INTEGER_RROTATE: u8 = 125;
561    pub const INTEGER_EXTRACT: u8 = 126;
562    pub const INTEGER_BTEST: u8 = 127;
563    pub const INTEGER_COUNTRZ: u8 = 128;
564    pub const INTEGER_COUNTLZ: u8 = 129;
565    pub const INTEGER_BSWAP: u8 = 130;
566    pub const BUFFER_READINTEGER: u8 = 131;
567    pub const BUFFER_WRITEINTEGER: u8 = 132;
568
569    /// Sentinel one past the largest builtin function id — the size of the
570    /// fastcall id space, mirroring [`Opcode::COUNT`].
571    pub const COUNT: u8 = 133;
572}
573
574/// Capture type used by `CAPTURE`.
575#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)]
576#[repr(u8)]
577pub enum CaptureType {
578    /// Capture value.
579    Val = 0,
580    /// Capture by reference.
581    Ref = 1,
582    /// Capture upvalue.
583    Upval = 2,
584}
585
586impl CaptureType {
587    /// Converts a serialized capture tag.
588    #[must_use]
589    pub const fn from_byte(value: u8) -> Option<Self> {
590        match value {
591            0 => Some(Self::Val),
592            1 => Some(Self::Ref),
593            2 => Some(Self::Upval),
594            _ => None,
595        }
596    }
597}
598
599/// `JumpXEqK*` AUX word: bit 31 negates the comparison.
600pub const JUMPX_K_NOT_BIT: u32 = 1 << 31;
601/// `JumpXEqK*` AUX word: the low 24 bits carry the constant index.
602pub const JUMPX_K_INDEX_MASK: u32 = (1 << 24) - 1;
603
604/// `FORGLOOP` AUX word: bit 31 marks an `ipairs`-style inext fast path
605/// (set when the loop was prepared by `ForGPrepInext`).
606pub const FORGLOOP_INEXT_BIT: u32 = 1 << 31;
607/// `FORGLOOP` AUX word: the low byte carries the iteration variable count.
608pub const FORGLOOP_VARS_MASK: u32 = 0xff;
609
610/// Import id: bits 30-31 carry the path-component count (1-3).
611pub const IMPORT_PATH_COUNT_SHIFT: u32 = 30;
612/// Import id: each path component is a 10-bit string-constant index,
613/// packed high-to-low starting at bit 20.
614pub const IMPORT_PATH_COMPONENT_BITS: u32 = 10;
615/// Mask for one packed import path component.
616pub const IMPORT_PATH_COMPONENT_MASK: u32 = (1 << IMPORT_PATH_COMPONENT_BITS) - 1;
617
618/// Bit shift of the `index`-th (0-based) packed import path component.
619#[must_use]
620pub const fn import_component_shift(index: u32) -> u32 {
621    IMPORT_PATH_COUNT_SHIFT - IMPORT_PATH_COMPONENT_BITS * (index + 1)
622}
623
624/// Proto flag bitmask values.
625pub struct ProtoFlag;
626
627impl ProtoFlag {
628    /// Function can be inlined. (Bits 0-2 are upstream's native-codegen
629    /// flags — `NATIVE_MODULE`/`NATIVE_COLD`/`NATIVE_FUNCTION` — which this
630    /// compiler never sets; the encoded flag byte carries them verbatim.)
631    pub const INLINABLE: u8 = 1 << 3;
632    /// Top-level proto returns a table populated by export statements.
633    pub const USES_EXPORT: u8 = 1 << 4;
634}
635
636/// Feedback-slot type tags.
637#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)]
638#[repr(u8)]
639pub enum FeedbackType {
640    /// Call-target feedback.
641    CallTarget = 0,
642}
643
644impl FeedbackType {
645    /// Converts a serialized feedback tag.
646    #[must_use]
647    pub const fn from_byte(value: u8) -> Option<Self> {
648        match value {
649            0 => Some(Self::CallTarget),
650            _ => None,
651        }
652    }
653}
654
655#[cfg(test)]
656mod tests {
657    use super::{
658        BuiltinFunction, CaptureType, ConstantTag, FeedbackType, Opcode, ProtoFlag, TypeTag,
659    };
660
661    macro_rules! upstream_case {
662        ($case:literal) => {};
663    }
664
665    #[test]
666    fn opcode_numbers_match_upstream() {
667        upstream_case!("Compiler.test.cpp::Compiler::BytecodeIsStable");
668        assert_eq!(Opcode::Nop.byte(), 0);
669        assert_eq!(Opcode::Return.byte(), 22);
670        assert_eq!(Opcode::FastCall3.byte(), 60);
671        assert_eq!(Opcode::CmpProto.byte(), 88);
672        assert_eq!(Opcode::NewClass.byte(), 89);
673        assert_eq!(Opcode::COUNT, 90);
674    }
675
676    #[test]
677    fn other_bytecode_tags_match_upstream() {
678        assert_eq!(ConstantTag::Nil as u8, 0);
679        assert_eq!(ConstantTag::Integer as u8, 9);
680        assert_eq!(ConstantTag::ClassShape as u8, 10);
681        assert_eq!(ConstantTag::VectorDouble as u8, 11);
682        assert_eq!(TypeTag::Any as u16, 15);
683        assert_eq!(TypeTag::OptionalBit as u16, 128);
684        assert_eq!(TypeTag::Invalid as u16, 256);
685        assert_eq!(CaptureType::Upval as u8, 2);
686        assert_eq!(ProtoFlag::INLINABLE, 8);
687        assert_eq!(ProtoFlag::USES_EXPORT, 16);
688        assert_eq!(FeedbackType::CallTarget as u8, 0);
689        assert_eq!(BuiltinFunction::BUFFER_WRITEINTEGER, 132);
690        assert_eq!(BuiltinFunction::COUNT, 133);
691    }
692}