Skip to main content

js_compile/
opcode.rs

1//! The instruction set, transcribed from the reference `quickjs-opcode.h`.
2//!
3//! That header is the single source of truth for three things: the opcode
4//! numbering, the instruction length, and how many values each instruction pops
5//! and pushes. Those are exactly the facts the compiler, the verifier and the
6//! disassembler need, so the table below is a transcription rather than a
7//! re-derivation: a typo there would be a typo in three places at once.
8//!
9//! Two numbering spaces exist in the reference implementation:
10//!
11//! * [`Opcode`] — instructions that appear in finished bytecode, numbered
12//!   `0 .. OP_COUNT`.
13//! * [`TempOpcode`] — instructions the compiler emits while building a function
14//!   and removes before the bytecode is finished (scope bookkeeping, labels,
15//!   line numbers). Their numbers overlap the short-form opcodes, so they can
16//!   never be confused with a finished instruction.
17//!
18//! The numbering matches the C implementation even though the serialised format
19//! is our own (see [`crate::serialize`]): it makes disassembly diffs against
20//! `qjsc` readable, and costs nothing.
21
22/// Operand encoding of an instruction.
23#[derive(Debug, Clone, Copy, PartialEq, Eq)]
24pub enum OpFormat {
25    /// `none`
26    None,
27    /// `none_int`
28    NoneInt,
29    /// `none_loc`
30    NoneLoc,
31    /// `none_arg`
32    NoneArg,
33    /// `none_var_ref`
34    NoneVarRef,
35    /// `u8`
36    U8,
37    /// `i8`
38    I8,
39    /// `loc8`
40    Loc8,
41    /// `const8`
42    Const8,
43    /// `label8`
44    Label8,
45    /// `u16`
46    U16,
47    /// `i16`
48    I16,
49    /// `label16`
50    Label16,
51    /// `npop`
52    Npop,
53    /// `npopx`
54    Npopx,
55    /// `npop_u16`
56    NpopU16,
57    /// `loc`
58    Loc,
59    /// `arg`
60    Arg,
61    /// `var_ref`
62    VarRef,
63    /// `u32`
64    U32,
65    /// `i32`
66    I32,
67    /// `const`
68    Const,
69    /// `label`
70    Label,
71    /// `atom`
72    Atom,
73    /// `atom_u8`
74    AtomU8,
75    /// `atom_u16`
76    AtomU16,
77    /// `atom_label_u8`
78    AtomLabelU8,
79    /// `atom_label_u16`
80    AtomLabelU16,
81    /// `label_u16`
82    LabelU16,
83}
84
85impl OpFormat {
86    /// The encoding name as written in the reference implementation.
87    pub fn as_str(self) -> &'static str {
88        match self {
89            OpFormat::None => "none",
90            OpFormat::NoneInt => "none_int",
91            OpFormat::NoneLoc => "none_loc",
92            OpFormat::NoneArg => "none_arg",
93            OpFormat::NoneVarRef => "none_var_ref",
94            OpFormat::U8 => "u8",
95            OpFormat::I8 => "i8",
96            OpFormat::Loc8 => "loc8",
97            OpFormat::Const8 => "const8",
98            OpFormat::Label8 => "label8",
99            OpFormat::U16 => "u16",
100            OpFormat::I16 => "i16",
101            OpFormat::Label16 => "label16",
102            OpFormat::Npop => "npop",
103            OpFormat::Npopx => "npopx",
104            OpFormat::NpopU16 => "npop_u16",
105            OpFormat::Loc => "loc",
106            OpFormat::Arg => "arg",
107            OpFormat::VarRef => "var_ref",
108            OpFormat::U32 => "u32",
109            OpFormat::I32 => "i32",
110            OpFormat::Const => "const",
111            OpFormat::Label => "label",
112            OpFormat::Atom => "atom",
113            OpFormat::AtomU8 => "atom_u8",
114            OpFormat::AtomU16 => "atom_u16",
115            OpFormat::AtomLabelU8 => "atom_label_u8",
116            OpFormat::AtomLabelU16 => "atom_label_u16",
117            OpFormat::LabelU16 => "label_u16",
118        }
119    }
120
121    /// Whether the encoding carries a jump target.
122    pub fn is_label(self) -> bool {
123        matches!(
124            self,
125            OpFormat::Label
126                | OpFormat::Label8
127                | OpFormat::Label16
128                | OpFormat::AtomLabelU8
129                | OpFormat::AtomLabelU16
130                | OpFormat::LabelU16
131        )
132    }
133}
134
135/// Static description of one instruction.
136#[derive(Debug, Clone, Copy)]
137pub struct OpInfo {
138    /// Mnemonic, as printed by the reference disassembler.
139    pub name: &'static str,
140    /// Instruction length in bytes, including the opcode byte.
141    pub size: u8,
142    /// Number of operands popped from the value stack.
143    pub n_pop: u8,
144    /// Number of results pushed onto the value stack.
145    pub n_push: u8,
146    /// Operand encoding.
147    pub format: OpFormat,
148}
149
150/// An instruction of finished bytecode.
151///
152/// Discriminants are the opcode numbers: the byte stored in the instruction
153/// stream is exactly `self as u8`, which keeps [`Opcode::from_u8`] a table
154/// lookup and lets a disassembly diff against `qjsc` point at a byte offset.
155#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
156#[repr(u8)]
157pub enum Opcode {
158    /// `invalid` — 1 byte(s), pops 0, pushes 0
159    Invalid = 0,
160    /// `push_i32` — 5 byte(s), pops 0, pushes 1
161    PushI32 = 1,
162    /// `push_const` — 5 byte(s), pops 0, pushes 1
163    PushConst = 2,
164    /// `fclosure` — 5 byte(s), pops 0, pushes 1
165    Fclosure = 3,
166    /// `push_atom_value` — 5 byte(s), pops 0, pushes 1
167    PushAtomValue = 4,
168    /// `private_symbol` — 5 byte(s), pops 0, pushes 1
169    PrivateSymbol = 5,
170    /// `undefined` — 1 byte(s), pops 0, pushes 1
171    Undefined = 6,
172    /// `null` — 1 byte(s), pops 0, pushes 1
173    Null = 7,
174    /// `push_this` — 1 byte(s), pops 0, pushes 1
175    PushThis = 8,
176    /// `push_false` — 1 byte(s), pops 0, pushes 1
177    PushFalse = 9,
178    /// `push_true` — 1 byte(s), pops 0, pushes 1
179    PushTrue = 10,
180    /// `object` — 1 byte(s), pops 0, pushes 1
181    Object = 11,
182    /// `special_object` — 2 byte(s), pops 0, pushes 1
183    SpecialObject = 12,
184    /// `rest` — 3 byte(s), pops 0, pushes 1
185    Rest = 13,
186    /// `drop` — 1 byte(s), pops 1, pushes 0
187    Drop = 14,
188    /// `nip` — 1 byte(s), pops 2, pushes 1
189    Nip = 15,
190    /// `nip1` — 1 byte(s), pops 3, pushes 2
191    Nip1 = 16,
192    /// `dup` — 1 byte(s), pops 1, pushes 2
193    Dup = 17,
194    /// `dup1` — 1 byte(s), pops 2, pushes 3
195    Dup1 = 18,
196    /// `dup2` — 1 byte(s), pops 2, pushes 4
197    Dup2 = 19,
198    /// `dup3` — 1 byte(s), pops 3, pushes 6
199    Dup3 = 20,
200    /// `insert2` — 1 byte(s), pops 2, pushes 3
201    Insert2 = 21,
202    /// `insert3` — 1 byte(s), pops 3, pushes 4
203    Insert3 = 22,
204    /// `insert4` — 1 byte(s), pops 4, pushes 5
205    Insert4 = 23,
206    /// `perm3` — 1 byte(s), pops 3, pushes 3
207    Perm3 = 24,
208    /// `perm4` — 1 byte(s), pops 4, pushes 4
209    Perm4 = 25,
210    /// `perm5` — 1 byte(s), pops 5, pushes 5
211    Perm5 = 26,
212    /// `swap` — 1 byte(s), pops 2, pushes 2
213    Swap = 27,
214    /// `swap2` — 1 byte(s), pops 4, pushes 4
215    Swap2 = 28,
216    /// `rot3l` — 1 byte(s), pops 3, pushes 3
217    Rot3l = 29,
218    /// `rot3r` — 1 byte(s), pops 3, pushes 3
219    Rot3r = 30,
220    /// `rot4l` — 1 byte(s), pops 4, pushes 4
221    Rot4l = 31,
222    /// `rot5l` — 1 byte(s), pops 5, pushes 5
223    Rot5l = 32,
224    /// `call_constructor` — 3 byte(s), pops 2, pushes 1
225    CallConstructor = 33,
226    /// `call` — 3 byte(s), pops 1, pushes 1
227    Call = 34,
228    /// `tail_call` — 3 byte(s), pops 1, pushes 0
229    TailCall = 35,
230    /// `call_method` — 3 byte(s), pops 2, pushes 1
231    CallMethod = 36,
232    /// `tail_call_method` — 3 byte(s), pops 2, pushes 0
233    TailCallMethod = 37,
234    /// `array_from` — 3 byte(s), pops 0, pushes 1
235    ArrayFrom = 38,
236    /// `apply` — 3 byte(s), pops 3, pushes 1
237    Apply = 39,
238    /// `return` — 1 byte(s), pops 1, pushes 0
239    Return = 40,
240    /// `return_undef` — 1 byte(s), pops 0, pushes 0
241    ReturnUndef = 41,
242    /// `check_ctor_return` — 1 byte(s), pops 1, pushes 2
243    CheckCtorReturn = 42,
244    /// `check_ctor` — 1 byte(s), pops 0, pushes 0
245    CheckCtor = 43,
246    /// `init_ctor` — 1 byte(s), pops 0, pushes 1
247    InitCtor = 44,
248    /// `check_brand` — 1 byte(s), pops 2, pushes 2
249    CheckBrand = 45,
250    /// `add_brand` — 1 byte(s), pops 2, pushes 0
251    AddBrand = 46,
252    /// `return_async` — 1 byte(s), pops 1, pushes 0
253    ReturnAsync = 47,
254    /// `throw` — 1 byte(s), pops 1, pushes 0
255    Throw = 48,
256    /// `throw_error` — 6 byte(s), pops 0, pushes 0
257    ThrowError = 49,
258    /// `eval` — 5 byte(s), pops 1, pushes 1
259    Eval = 50,
260    /// `apply_eval` — 3 byte(s), pops 2, pushes 1
261    ApplyEval = 51,
262    /// `regexp` — 1 byte(s), pops 2, pushes 1
263    Regexp = 52,
264    /// `get_super` — 1 byte(s), pops 1, pushes 1
265    GetSuper = 53,
266    /// `import` — 1 byte(s), pops 2, pushes 1
267    Import = 54,
268    /// `get_var_undef` — 3 byte(s), pops 0, pushes 1
269    GetVarUndef = 55,
270    /// `get_var` — 3 byte(s), pops 0, pushes 1
271    GetVar = 56,
272    /// `put_var` — 3 byte(s), pops 1, pushes 0
273    PutVar = 57,
274    /// `put_var_init` — 3 byte(s), pops 1, pushes 0
275    PutVarInit = 58,
276    /// `get_ref_value` — 1 byte(s), pops 2, pushes 3
277    GetRefValue = 59,
278    /// `put_ref_value` — 1 byte(s), pops 3, pushes 0
279    PutRefValue = 60,
280    /// `get_field` — 5 byte(s), pops 1, pushes 1
281    GetField = 61,
282    /// `get_field2` — 5 byte(s), pops 1, pushes 2
283    GetField2 = 62,
284    /// `put_field` — 5 byte(s), pops 2, pushes 0
285    PutField = 63,
286    /// `get_private_field` — 1 byte(s), pops 2, pushes 1
287    GetPrivateField = 64,
288    /// `put_private_field` — 1 byte(s), pops 3, pushes 0
289    PutPrivateField = 65,
290    /// `define_private_field` — 1 byte(s), pops 3, pushes 1
291    DefinePrivateField = 66,
292    /// `get_array_el` — 1 byte(s), pops 2, pushes 1
293    GetArrayEl = 67,
294    /// `get_array_el2` — 1 byte(s), pops 2, pushes 2
295    GetArrayEl2 = 68,
296    /// `get_array_el3` — 1 byte(s), pops 2, pushes 3
297    GetArrayEl3 = 69,
298    /// `put_array_el` — 1 byte(s), pops 3, pushes 0
299    PutArrayEl = 70,
300    /// `get_super_value` — 1 byte(s), pops 3, pushes 1
301    GetSuperValue = 71,
302    /// `put_super_value` — 1 byte(s), pops 4, pushes 0
303    PutSuperValue = 72,
304    /// `define_field` — 5 byte(s), pops 2, pushes 1
305    DefineField = 73,
306    /// `set_name` — 5 byte(s), pops 1, pushes 1
307    SetName = 74,
308    /// `set_name_computed` — 1 byte(s), pops 2, pushes 2
309    SetNameComputed = 75,
310    /// `set_proto` — 1 byte(s), pops 2, pushes 1
311    SetProto = 76,
312    /// `set_home_object` — 1 byte(s), pops 2, pushes 2
313    SetHomeObject = 77,
314    /// `define_array_el` — 1 byte(s), pops 3, pushes 2
315    DefineArrayEl = 78,
316    /// `append` — 1 byte(s), pops 3, pushes 2
317    Append = 79,
318    /// `copy_data_properties` — 2 byte(s), pops 3, pushes 3
319    CopyDataProperties = 80,
320    /// `define_method` — 6 byte(s), pops 2, pushes 1
321    DefineMethod = 81,
322    /// `define_method_computed` — 2 byte(s), pops 3, pushes 1
323    DefineMethodComputed = 82,
324    /// `define_class` — 6 byte(s), pops 2, pushes 2
325    DefineClass = 83,
326    /// `define_class_computed` — 6 byte(s), pops 3, pushes 3
327    DefineClassComputed = 84,
328    /// `get_loc` — 3 byte(s), pops 0, pushes 1
329    GetLoc = 85,
330    /// `put_loc` — 3 byte(s), pops 1, pushes 0
331    PutLoc = 86,
332    /// `set_loc` — 3 byte(s), pops 1, pushes 1
333    SetLoc = 87,
334    /// `get_arg` — 3 byte(s), pops 0, pushes 1
335    GetArg = 88,
336    /// `put_arg` — 3 byte(s), pops 1, pushes 0
337    PutArg = 89,
338    /// `set_arg` — 3 byte(s), pops 1, pushes 1
339    SetArg = 90,
340    /// `get_var_ref` — 3 byte(s), pops 0, pushes 1
341    GetVarRef = 91,
342    /// `put_var_ref` — 3 byte(s), pops 1, pushes 0
343    PutVarRef = 92,
344    /// `set_var_ref` — 3 byte(s), pops 1, pushes 1
345    SetVarRef = 93,
346    /// `set_loc_uninitialized` — 3 byte(s), pops 0, pushes 0
347    SetLocUninitialized = 94,
348    /// `get_loc_check` — 3 byte(s), pops 0, pushes 1
349    GetLocCheck = 95,
350    /// `put_loc_check` — 3 byte(s), pops 1, pushes 0
351    PutLocCheck = 96,
352    /// `set_loc_check` — 3 byte(s), pops 1, pushes 1
353    SetLocCheck = 97,
354    /// `put_loc_check_init` — 3 byte(s), pops 1, pushes 0
355    PutLocCheckInit = 98,
356    /// `get_loc_checkthis` — 3 byte(s), pops 0, pushes 1
357    GetLocCheckthis = 99,
358    /// `get_var_ref_check` — 3 byte(s), pops 0, pushes 1
359    GetVarRefCheck = 100,
360    /// `put_var_ref_check` — 3 byte(s), pops 1, pushes 0
361    PutVarRefCheck = 101,
362    /// `put_var_ref_check_init` — 3 byte(s), pops 1, pushes 0
363    PutVarRefCheckInit = 102,
364    /// `close_loc` — 3 byte(s), pops 0, pushes 0
365    CloseLoc = 103,
366    /// `if_false` — 5 byte(s), pops 1, pushes 0
367    IfFalse = 104,
368    /// `if_true` — 5 byte(s), pops 1, pushes 0
369    IfTrue = 105,
370    /// `goto` — 5 byte(s), pops 0, pushes 0
371    Goto = 106,
372    /// `catch` — 5 byte(s), pops 0, pushes 1
373    Catch = 107,
374    /// `gosub` — 5 byte(s), pops 0, pushes 0
375    Gosub = 108,
376    /// `ret` — 1 byte(s), pops 1, pushes 0
377    Ret = 109,
378    /// `nip_catch` — 1 byte(s), pops 2, pushes 1
379    NipCatch = 110,
380    /// `to_object` — 1 byte(s), pops 1, pushes 1
381    ToObject = 111,
382    /// `to_propkey` — 1 byte(s), pops 1, pushes 1
383    ToPropkey = 112,
384    /// `with_get_var` — 10 byte(s), pops 1, pushes 0
385    WithGetVar = 113,
386    /// `with_put_var` — 10 byte(s), pops 2, pushes 1
387    WithPutVar = 114,
388    /// `with_delete_var` — 10 byte(s), pops 1, pushes 0
389    WithDeleteVar = 115,
390    /// `with_make_ref` — 10 byte(s), pops 1, pushes 0
391    WithMakeRef = 116,
392    /// `with_get_ref` — 10 byte(s), pops 1, pushes 0
393    WithGetRef = 117,
394    /// `make_loc_ref` — 7 byte(s), pops 0, pushes 2
395    MakeLocRef = 118,
396    /// `make_arg_ref` — 7 byte(s), pops 0, pushes 2
397    MakeArgRef = 119,
398    /// `make_var_ref_ref` — 7 byte(s), pops 0, pushes 2
399    MakeVarRefRef = 120,
400    /// `make_var_ref` — 5 byte(s), pops 0, pushes 2
401    MakeVarRef = 121,
402    /// `for_in_start` — 1 byte(s), pops 1, pushes 1
403    ForInStart = 122,
404    /// `for_of_start` — 1 byte(s), pops 1, pushes 3
405    ForOfStart = 123,
406    /// `for_await_of_start` — 1 byte(s), pops 1, pushes 3
407    ForAwaitOfStart = 124,
408    /// `for_in_next` — 1 byte(s), pops 1, pushes 3
409    ForInNext = 125,
410    /// `for_of_next` — 2 byte(s), pops 3, pushes 5
411    ForOfNext = 126,
412    /// `for_await_of_next` — 1 byte(s), pops 3, pushes 4
413    ForAwaitOfNext = 127,
414    /// `iterator_check_object` — 1 byte(s), pops 1, pushes 1
415    IteratorCheckObject = 128,
416    /// `iterator_get_value_done` — 1 byte(s), pops 2, pushes 3
417    IteratorGetValueDone = 129,
418    /// `iterator_close` — 1 byte(s), pops 3, pushes 0
419    IteratorClose = 130,
420    /// `iterator_next` — 1 byte(s), pops 4, pushes 4
421    IteratorNext = 131,
422    /// `iterator_call` — 2 byte(s), pops 4, pushes 5
423    IteratorCall = 132,
424    /// `initial_yield` — 1 byte(s), pops 0, pushes 0
425    InitialYield = 133,
426    /// `yield` — 1 byte(s), pops 1, pushes 2
427    Yield = 134,
428    /// `yield_star` — 1 byte(s), pops 1, pushes 2
429    YieldStar = 135,
430    /// `async_yield_star` — 1 byte(s), pops 1, pushes 2
431    AsyncYieldStar = 136,
432    /// `await` — 1 byte(s), pops 1, pushes 1
433    Await = 137,
434    /// `neg` — 1 byte(s), pops 1, pushes 1
435    Neg = 138,
436    /// `plus` — 1 byte(s), pops 1, pushes 1
437    Plus = 139,
438    /// `dec` — 1 byte(s), pops 1, pushes 1
439    Dec = 140,
440    /// `inc` — 1 byte(s), pops 1, pushes 1
441    Inc = 141,
442    /// `post_dec` — 1 byte(s), pops 1, pushes 2
443    PostDec = 142,
444    /// `post_inc` — 1 byte(s), pops 1, pushes 2
445    PostInc = 143,
446    /// `dec_loc` — 2 byte(s), pops 0, pushes 0
447    DecLoc = 144,
448    /// `inc_loc` — 2 byte(s), pops 0, pushes 0
449    IncLoc = 145,
450    /// `add_loc` — 2 byte(s), pops 1, pushes 0
451    AddLoc = 146,
452    /// `not` — 1 byte(s), pops 1, pushes 1
453    Not = 147,
454    /// `lnot` — 1 byte(s), pops 1, pushes 1
455    Lnot = 148,
456    /// `typeof` — 1 byte(s), pops 1, pushes 1
457    Typeof = 149,
458    /// `delete` — 1 byte(s), pops 2, pushes 1
459    Delete = 150,
460    /// `delete_var` — 5 byte(s), pops 0, pushes 1
461    DeleteVar = 151,
462    /// `mul` — 1 byte(s), pops 2, pushes 1
463    Mul = 152,
464    /// `div` — 1 byte(s), pops 2, pushes 1
465    Div = 153,
466    /// `mod` — 1 byte(s), pops 2, pushes 1
467    Mod = 154,
468    /// `add` — 1 byte(s), pops 2, pushes 1
469    Add = 155,
470    /// `sub` — 1 byte(s), pops 2, pushes 1
471    Sub = 156,
472    /// `pow` — 1 byte(s), pops 2, pushes 1
473    Pow = 157,
474    /// `shl` — 1 byte(s), pops 2, pushes 1
475    Shl = 158,
476    /// `sar` — 1 byte(s), pops 2, pushes 1
477    Sar = 159,
478    /// `shr` — 1 byte(s), pops 2, pushes 1
479    Shr = 160,
480    /// `lt` — 1 byte(s), pops 2, pushes 1
481    Lt = 161,
482    /// `lte` — 1 byte(s), pops 2, pushes 1
483    Lte = 162,
484    /// `gt` — 1 byte(s), pops 2, pushes 1
485    Gt = 163,
486    /// `gte` — 1 byte(s), pops 2, pushes 1
487    Gte = 164,
488    /// `instanceof` — 1 byte(s), pops 2, pushes 1
489    Instanceof = 165,
490    /// `in` — 1 byte(s), pops 2, pushes 1
491    In = 166,
492    /// `eq` — 1 byte(s), pops 2, pushes 1
493    Eq = 167,
494    /// `neq` — 1 byte(s), pops 2, pushes 1
495    Neq = 168,
496    /// `strict_eq` — 1 byte(s), pops 2, pushes 1
497    StrictEq = 169,
498    /// `strict_neq` — 1 byte(s), pops 2, pushes 1
499    StrictNeq = 170,
500    /// `and` — 1 byte(s), pops 2, pushes 1
501    And = 171,
502    /// `xor` — 1 byte(s), pops 2, pushes 1
503    Xor = 172,
504    /// `or` — 1 byte(s), pops 2, pushes 1
505    Or = 173,
506    /// `is_undefined_or_null` — 1 byte(s), pops 1, pushes 1
507    IsUndefinedOrNull = 174,
508    /// `private_in` — 1 byte(s), pops 2, pushes 1
509    PrivateIn = 175,
510    /// `push_bigint_i32` — 5 byte(s), pops 0, pushes 1
511    PushBigintI32 = 176,
512    /// `using_dispose_init` — 1 byte(s), pops 0, pushes 1
513    UsingDisposeInit = 177,
514    /// `using_dispose` — 3 byte(s), pops 1, pushes 1
515    UsingDispose = 178,
516    /// `using_dispose_async` — 3 byte(s), pops 0, pushes 1
517    UsingDisposeAsync = 179,
518    /// `using_dispose_merge` — 1 byte(s), pops 2, pushes 1
519    UsingDisposeMerge = 180,
520    /// `using_dispose_end` — 1 byte(s), pops 1, pushes 0
521    UsingDisposeEnd = 181,
522    /// `using_check` — 2 byte(s), pops 1, pushes 2
523    UsingCheck = 182,
524    /// `nop` — 1 byte(s), pops 0, pushes 0
525    Nop = 183,
526    /// `push_minus1` — 1 byte(s), pops 0, pushes 1
527    PushMinus1 = 184,
528    /// `push_0` — 1 byte(s), pops 0, pushes 1
529    Push0 = 185,
530    /// `push_1` — 1 byte(s), pops 0, pushes 1
531    Push1 = 186,
532    /// `push_2` — 1 byte(s), pops 0, pushes 1
533    Push2 = 187,
534    /// `push_3` — 1 byte(s), pops 0, pushes 1
535    Push3 = 188,
536    /// `push_4` — 1 byte(s), pops 0, pushes 1
537    Push4 = 189,
538    /// `push_5` — 1 byte(s), pops 0, pushes 1
539    Push5 = 190,
540    /// `push_6` — 1 byte(s), pops 0, pushes 1
541    Push6 = 191,
542    /// `push_7` — 1 byte(s), pops 0, pushes 1
543    Push7 = 192,
544    /// `push_i8` — 2 byte(s), pops 0, pushes 1
545    PushI8 = 193,
546    /// `push_i16` — 3 byte(s), pops 0, pushes 1
547    PushI16 = 194,
548    /// `push_const8` — 2 byte(s), pops 0, pushes 1
549    PushConst8 = 195,
550    /// `fclosure8` — 2 byte(s), pops 0, pushes 1
551    Fclosure8 = 196,
552    /// `push_empty_string` — 1 byte(s), pops 0, pushes 1
553    PushEmptyString = 197,
554    /// `get_loc8` — 2 byte(s), pops 0, pushes 1
555    GetLoc8 = 198,
556    /// `put_loc8` — 2 byte(s), pops 1, pushes 0
557    PutLoc8 = 199,
558    /// `set_loc8` — 2 byte(s), pops 1, pushes 1
559    SetLoc8 = 200,
560    /// `get_loc0` — 1 byte(s), pops 0, pushes 1
561    GetLoc0 = 201,
562    /// `get_loc1` — 1 byte(s), pops 0, pushes 1
563    GetLoc1 = 202,
564    /// `get_loc2` — 1 byte(s), pops 0, pushes 1
565    GetLoc2 = 203,
566    /// `get_loc3` — 1 byte(s), pops 0, pushes 1
567    GetLoc3 = 204,
568    /// `put_loc0` — 1 byte(s), pops 1, pushes 0
569    PutLoc0 = 205,
570    /// `put_loc1` — 1 byte(s), pops 1, pushes 0
571    PutLoc1 = 206,
572    /// `put_loc2` — 1 byte(s), pops 1, pushes 0
573    PutLoc2 = 207,
574    /// `put_loc3` — 1 byte(s), pops 1, pushes 0
575    PutLoc3 = 208,
576    /// `set_loc0` — 1 byte(s), pops 1, pushes 1
577    SetLoc0 = 209,
578    /// `set_loc1` — 1 byte(s), pops 1, pushes 1
579    SetLoc1 = 210,
580    /// `set_loc2` — 1 byte(s), pops 1, pushes 1
581    SetLoc2 = 211,
582    /// `set_loc3` — 1 byte(s), pops 1, pushes 1
583    SetLoc3 = 212,
584    /// `get_arg0` — 1 byte(s), pops 0, pushes 1
585    GetArg0 = 213,
586    /// `get_arg1` — 1 byte(s), pops 0, pushes 1
587    GetArg1 = 214,
588    /// `get_arg2` — 1 byte(s), pops 0, pushes 1
589    GetArg2 = 215,
590    /// `get_arg3` — 1 byte(s), pops 0, pushes 1
591    GetArg3 = 216,
592    /// `put_arg0` — 1 byte(s), pops 1, pushes 0
593    PutArg0 = 217,
594    /// `put_arg1` — 1 byte(s), pops 1, pushes 0
595    PutArg1 = 218,
596    /// `put_arg2` — 1 byte(s), pops 1, pushes 0
597    PutArg2 = 219,
598    /// `put_arg3` — 1 byte(s), pops 1, pushes 0
599    PutArg3 = 220,
600    /// `set_arg0` — 1 byte(s), pops 1, pushes 1
601    SetArg0 = 221,
602    /// `set_arg1` — 1 byte(s), pops 1, pushes 1
603    SetArg1 = 222,
604    /// `set_arg2` — 1 byte(s), pops 1, pushes 1
605    SetArg2 = 223,
606    /// `set_arg3` — 1 byte(s), pops 1, pushes 1
607    SetArg3 = 224,
608    /// `get_var_ref0` — 1 byte(s), pops 0, pushes 1
609    GetVarRef0 = 225,
610    /// `get_var_ref1` — 1 byte(s), pops 0, pushes 1
611    GetVarRef1 = 226,
612    /// `get_var_ref2` — 1 byte(s), pops 0, pushes 1
613    GetVarRef2 = 227,
614    /// `get_var_ref3` — 1 byte(s), pops 0, pushes 1
615    GetVarRef3 = 228,
616    /// `put_var_ref0` — 1 byte(s), pops 1, pushes 0
617    PutVarRef0 = 229,
618    /// `put_var_ref1` — 1 byte(s), pops 1, pushes 0
619    PutVarRef1 = 230,
620    /// `put_var_ref2` — 1 byte(s), pops 1, pushes 0
621    PutVarRef2 = 231,
622    /// `put_var_ref3` — 1 byte(s), pops 1, pushes 0
623    PutVarRef3 = 232,
624    /// `set_var_ref0` — 1 byte(s), pops 1, pushes 1
625    SetVarRef0 = 233,
626    /// `set_var_ref1` — 1 byte(s), pops 1, pushes 1
627    SetVarRef1 = 234,
628    /// `set_var_ref2` — 1 byte(s), pops 1, pushes 1
629    SetVarRef2 = 235,
630    /// `set_var_ref3` — 1 byte(s), pops 1, pushes 1
631    SetVarRef3 = 236,
632    /// `get_length` — 1 byte(s), pops 1, pushes 1
633    GetLength = 237,
634    /// `if_false8` — 2 byte(s), pops 1, pushes 0
635    IfFalse8 = 238,
636    /// `if_true8` — 2 byte(s), pops 1, pushes 0
637    IfTrue8 = 239,
638    /// `goto8` — 2 byte(s), pops 0, pushes 0
639    Goto8 = 240,
640    /// `goto16` — 3 byte(s), pops 0, pushes 0
641    Goto16 = 241,
642    /// `call0` — 1 byte(s), pops 1, pushes 1
643    Call0 = 242,
644    /// `call1` — 1 byte(s), pops 1, pushes 1
645    Call1 = 243,
646    /// `call2` — 1 byte(s), pops 1, pushes 1
647    Call2 = 244,
648    /// `call3` — 1 byte(s), pops 1, pushes 1
649    Call3 = 245,
650    /// `is_undefined` — 1 byte(s), pops 1, pushes 1
651    IsUndefined = 246,
652    /// `is_null` — 1 byte(s), pops 1, pushes 1
653    IsNull = 247,
654    /// `typeof_is_undefined` — 1 byte(s), pops 1, pushes 1
655    TypeofIsUndefined = 248,
656    /// `typeof_is_function` — 1 byte(s), pops 1, pushes 1
657    TypeofIsFunction = 249,
658}
659
660/// Number of finished instructions (the reference `OP_COUNT`).
661pub const OP_COUNT: u8 = 250;
662
663/// An instruction that only exists while a function is being compiled.
664///
665/// The numbers overlap the short-form opcodes, exactly as in the reference
666/// implementation, because these can never appear in finished bytecode.
667#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
668#[repr(u8)]
669pub enum TempOpcode {
670    /// `enter_scope` — 3 byte(s), pops 0, pushes 0
671    EnterScope = 1,
672    /// `leave_scope` — 3 byte(s), pops 0, pushes 0
673    LeaveScope = 2,
674    /// `label` — 5 byte(s), pops 0, pushes 0
675    Label = 3,
676    /// `scope_get_var_undef` — 7 byte(s), pops 0, pushes 1
677    ScopeGetVarUndef = 4,
678    /// `scope_get_var` — 7 byte(s), pops 0, pushes 1
679    ScopeGetVar = 5,
680    /// `scope_put_var` — 7 byte(s), pops 1, pushes 0
681    ScopePutVar = 6,
682    /// `scope_delete_var` — 7 byte(s), pops 0, pushes 1
683    ScopeDeleteVar = 7,
684    /// `scope_make_ref` — 11 byte(s), pops 0, pushes 2
685    ScopeMakeRef = 8,
686    /// `scope_get_ref` — 7 byte(s), pops 0, pushes 2
687    ScopeGetRef = 9,
688    /// `scope_put_var_init` — 7 byte(s), pops 0, pushes 2
689    ScopePutVarInit = 10,
690    /// `scope_get_var_checkthis` — 7 byte(s), pops 0, pushes 1
691    ScopeGetVarCheckthis = 11,
692    /// `scope_get_private_field` — 7 byte(s), pops 1, pushes 1
693    ScopeGetPrivateField = 12,
694    /// `scope_get_private_field2` — 7 byte(s), pops 1, pushes 2
695    ScopeGetPrivateField2 = 13,
696    /// `scope_put_private_field` — 7 byte(s), pops 2, pushes 0
697    ScopePutPrivateField = 14,
698    /// `scope_in_private_field` — 7 byte(s), pops 1, pushes 1
699    ScopeInPrivateField = 15,
700    /// `get_field_opt_chain` — 5 byte(s), pops 1, pushes 1
701    GetFieldOptChain = 16,
702    /// `get_array_el_opt_chain` — 1 byte(s), pops 2, pushes 1
703    GetArrayElOptChain = 17,
704    /// `set_class_name` — 5 byte(s), pops 1, pushes 1
705    SetClassName = 18,
706    /// `line_num` — 5 byte(s), pops 0, pushes 0
707    LineNum = 19,
708}
709
710impl Opcode {
711    /// The static description of this instruction.
712    pub fn info(self) -> OpInfo {
713        OP_INFO[self as usize]
714    }
715
716    /// The mnemonic.
717    pub fn name(self) -> &'static str {
718        self.info().name
719    }
720
721    /// Instruction length in bytes.
722    pub fn size(self) -> u8 {
723        self.info().size
724    }
725
726    /// Decode an opcode byte. `None` for a value that is not an instruction.
727    pub fn from_u8(byte: u8) -> Option<Opcode> {
728        OP_BY_BYTE.get(byte as usize).copied().flatten()
729    }
730
731    /// Look up by mnemonic.
732    pub fn by_name(name: &str) -> Option<Opcode> {
733        OP_INFO
734            .iter()
735            .position(|info| info.name == name)
736            .map(|index| OP_ALL[index])
737    }
738}
739
740impl TempOpcode {
741    /// The static description of this instruction.
742    pub fn info(self) -> OpInfo {
743        TEMP_INFO[self as usize - TEMP_START]
744    }
745
746    /// The mnemonic.
747    pub fn name(self) -> &'static str {
748        self.info().name
749    }
750}
751
752const TEMP_START: usize = 1;
753
754impl Opcode {
755    /// The operand index that a short-form opcode encodes in its own number.
756    ///
757    /// `get_loc0` … `get_loc3` carry their slot index in the opcode byte, so the
758    /// disassembler and the interpreter recover it by subtraction. Returns
759    /// `None` for instructions with an explicit operand.
760    pub fn specialised_index(self) -> Option<i32> {
761        use Opcode::*;
762        let byte = self as u32;
763        let base = |op: Opcode| op as u32;
764        // `push_minus1` sits immediately before `push_0`, so the family is a
765        // contiguous range that starts one opcode earlier.
766        if (base(PushMinus1)..=base(Push7)).contains(&byte) {
767            // `push_minus1` yields -1, exactly as the reference computes it.
768            return Some(byte as i32 - base(Push0) as i32);
769        }
770        if (base(GetLoc0)..=base(SetLoc3)).contains(&byte) {
771            return Some(((byte - base(GetLoc0)) % 4) as i32);
772        }
773        if (base(GetArg0)..=base(SetArg3)).contains(&byte) {
774            return Some(((byte - base(GetArg0)) % 4) as i32);
775        }
776        if (base(GetVarRef0)..=base(SetVarRef3)).contains(&byte) {
777            return Some(((byte - base(GetVarRef0)) % 4) as i32);
778        }
779        if (base(Call0)..=base(Call3)).contains(&byte) {
780            return Some((byte - base(Call0)) as i32);
781        }
782        None
783    }
784
785    /// The short form of `self` for a given operand index, when one exists.
786    ///
787    /// The compiler uses this once slot indices are known: `get_loc 7` becomes
788    /// `get_loc3`, which is one byte instead of three.
789    pub fn short_form(self, index: u32) -> Option<Opcode> {
790        use Opcode::*;
791        let base = match self {
792            PushI32 => Push0,
793            GetLoc => GetLoc0,
794            PutLoc => PutLoc0,
795            SetLoc => SetLoc0,
796            GetArg => GetArg0,
797            PutArg => PutArg0,
798            SetArg => SetArg0,
799            GetVarRef => GetVarRef0,
800            PutVarRef => PutVarRef0,
801            SetVarRef => SetVarRef0,
802            Call => Call0,
803            _ => return None,
804        };
805        if self == PushI32 {
806            // `push_i32` folds into `push_minus1` (index -1, encoded as u32::MAX)
807            // or `push_N` for 0..=7.
808            if index == u32::MAX {
809                return Some(PushMinus1);
810            }
811            return if index <= 7 {
812                Opcode::from_u8(u8::try_from(Push0 as u32 + index).ok()?)
813            } else {
814                None
815            };
816        }
817        if index > 3 {
818            return None;
819        }
820        u8::try_from(base as u32 + index)
821            .ok()
822            .and_then(Opcode::from_u8)
823    }
824}
825
826/// Every finished opcode, indexed by discriminant.
827static OP_ALL: [Opcode; 250] = [
828    Opcode::Invalid,
829    Opcode::PushI32,
830    Opcode::PushConst,
831    Opcode::Fclosure,
832    Opcode::PushAtomValue,
833    Opcode::PrivateSymbol,
834    Opcode::Undefined,
835    Opcode::Null,
836    Opcode::PushThis,
837    Opcode::PushFalse,
838    Opcode::PushTrue,
839    Opcode::Object,
840    Opcode::SpecialObject,
841    Opcode::Rest,
842    Opcode::Drop,
843    Opcode::Nip,
844    Opcode::Nip1,
845    Opcode::Dup,
846    Opcode::Dup1,
847    Opcode::Dup2,
848    Opcode::Dup3,
849    Opcode::Insert2,
850    Opcode::Insert3,
851    Opcode::Insert4,
852    Opcode::Perm3,
853    Opcode::Perm4,
854    Opcode::Perm5,
855    Opcode::Swap,
856    Opcode::Swap2,
857    Opcode::Rot3l,
858    Opcode::Rot3r,
859    Opcode::Rot4l,
860    Opcode::Rot5l,
861    Opcode::CallConstructor,
862    Opcode::Call,
863    Opcode::TailCall,
864    Opcode::CallMethod,
865    Opcode::TailCallMethod,
866    Opcode::ArrayFrom,
867    Opcode::Apply,
868    Opcode::Return,
869    Opcode::ReturnUndef,
870    Opcode::CheckCtorReturn,
871    Opcode::CheckCtor,
872    Opcode::InitCtor,
873    Opcode::CheckBrand,
874    Opcode::AddBrand,
875    Opcode::ReturnAsync,
876    Opcode::Throw,
877    Opcode::ThrowError,
878    Opcode::Eval,
879    Opcode::ApplyEval,
880    Opcode::Regexp,
881    Opcode::GetSuper,
882    Opcode::Import,
883    Opcode::GetVarUndef,
884    Opcode::GetVar,
885    Opcode::PutVar,
886    Opcode::PutVarInit,
887    Opcode::GetRefValue,
888    Opcode::PutRefValue,
889    Opcode::GetField,
890    Opcode::GetField2,
891    Opcode::PutField,
892    Opcode::GetPrivateField,
893    Opcode::PutPrivateField,
894    Opcode::DefinePrivateField,
895    Opcode::GetArrayEl,
896    Opcode::GetArrayEl2,
897    Opcode::GetArrayEl3,
898    Opcode::PutArrayEl,
899    Opcode::GetSuperValue,
900    Opcode::PutSuperValue,
901    Opcode::DefineField,
902    Opcode::SetName,
903    Opcode::SetNameComputed,
904    Opcode::SetProto,
905    Opcode::SetHomeObject,
906    Opcode::DefineArrayEl,
907    Opcode::Append,
908    Opcode::CopyDataProperties,
909    Opcode::DefineMethod,
910    Opcode::DefineMethodComputed,
911    Opcode::DefineClass,
912    Opcode::DefineClassComputed,
913    Opcode::GetLoc,
914    Opcode::PutLoc,
915    Opcode::SetLoc,
916    Opcode::GetArg,
917    Opcode::PutArg,
918    Opcode::SetArg,
919    Opcode::GetVarRef,
920    Opcode::PutVarRef,
921    Opcode::SetVarRef,
922    Opcode::SetLocUninitialized,
923    Opcode::GetLocCheck,
924    Opcode::PutLocCheck,
925    Opcode::SetLocCheck,
926    Opcode::PutLocCheckInit,
927    Opcode::GetLocCheckthis,
928    Opcode::GetVarRefCheck,
929    Opcode::PutVarRefCheck,
930    Opcode::PutVarRefCheckInit,
931    Opcode::CloseLoc,
932    Opcode::IfFalse,
933    Opcode::IfTrue,
934    Opcode::Goto,
935    Opcode::Catch,
936    Opcode::Gosub,
937    Opcode::Ret,
938    Opcode::NipCatch,
939    Opcode::ToObject,
940    Opcode::ToPropkey,
941    Opcode::WithGetVar,
942    Opcode::WithPutVar,
943    Opcode::WithDeleteVar,
944    Opcode::WithMakeRef,
945    Opcode::WithGetRef,
946    Opcode::MakeLocRef,
947    Opcode::MakeArgRef,
948    Opcode::MakeVarRefRef,
949    Opcode::MakeVarRef,
950    Opcode::ForInStart,
951    Opcode::ForOfStart,
952    Opcode::ForAwaitOfStart,
953    Opcode::ForInNext,
954    Opcode::ForOfNext,
955    Opcode::ForAwaitOfNext,
956    Opcode::IteratorCheckObject,
957    Opcode::IteratorGetValueDone,
958    Opcode::IteratorClose,
959    Opcode::IteratorNext,
960    Opcode::IteratorCall,
961    Opcode::InitialYield,
962    Opcode::Yield,
963    Opcode::YieldStar,
964    Opcode::AsyncYieldStar,
965    Opcode::Await,
966    Opcode::Neg,
967    Opcode::Plus,
968    Opcode::Dec,
969    Opcode::Inc,
970    Opcode::PostDec,
971    Opcode::PostInc,
972    Opcode::DecLoc,
973    Opcode::IncLoc,
974    Opcode::AddLoc,
975    Opcode::Not,
976    Opcode::Lnot,
977    Opcode::Typeof,
978    Opcode::Delete,
979    Opcode::DeleteVar,
980    Opcode::Mul,
981    Opcode::Div,
982    Opcode::Mod,
983    Opcode::Add,
984    Opcode::Sub,
985    Opcode::Pow,
986    Opcode::Shl,
987    Opcode::Sar,
988    Opcode::Shr,
989    Opcode::Lt,
990    Opcode::Lte,
991    Opcode::Gt,
992    Opcode::Gte,
993    Opcode::Instanceof,
994    Opcode::In,
995    Opcode::Eq,
996    Opcode::Neq,
997    Opcode::StrictEq,
998    Opcode::StrictNeq,
999    Opcode::And,
1000    Opcode::Xor,
1001    Opcode::Or,
1002    Opcode::IsUndefinedOrNull,
1003    Opcode::PrivateIn,
1004    Opcode::PushBigintI32,
1005    Opcode::UsingDisposeInit,
1006    Opcode::UsingDispose,
1007    Opcode::UsingDisposeAsync,
1008    Opcode::UsingDisposeMerge,
1009    Opcode::UsingDisposeEnd,
1010    Opcode::UsingCheck,
1011    Opcode::Nop,
1012    Opcode::PushMinus1,
1013    Opcode::Push0,
1014    Opcode::Push1,
1015    Opcode::Push2,
1016    Opcode::Push3,
1017    Opcode::Push4,
1018    Opcode::Push5,
1019    Opcode::Push6,
1020    Opcode::Push7,
1021    Opcode::PushI8,
1022    Opcode::PushI16,
1023    Opcode::PushConst8,
1024    Opcode::Fclosure8,
1025    Opcode::PushEmptyString,
1026    Opcode::GetLoc8,
1027    Opcode::PutLoc8,
1028    Opcode::SetLoc8,
1029    Opcode::GetLoc0,
1030    Opcode::GetLoc1,
1031    Opcode::GetLoc2,
1032    Opcode::GetLoc3,
1033    Opcode::PutLoc0,
1034    Opcode::PutLoc1,
1035    Opcode::PutLoc2,
1036    Opcode::PutLoc3,
1037    Opcode::SetLoc0,
1038    Opcode::SetLoc1,
1039    Opcode::SetLoc2,
1040    Opcode::SetLoc3,
1041    Opcode::GetArg0,
1042    Opcode::GetArg1,
1043    Opcode::GetArg2,
1044    Opcode::GetArg3,
1045    Opcode::PutArg0,
1046    Opcode::PutArg1,
1047    Opcode::PutArg2,
1048    Opcode::PutArg3,
1049    Opcode::SetArg0,
1050    Opcode::SetArg1,
1051    Opcode::SetArg2,
1052    Opcode::SetArg3,
1053    Opcode::GetVarRef0,
1054    Opcode::GetVarRef1,
1055    Opcode::GetVarRef2,
1056    Opcode::GetVarRef3,
1057    Opcode::PutVarRef0,
1058    Opcode::PutVarRef1,
1059    Opcode::PutVarRef2,
1060    Opcode::PutVarRef3,
1061    Opcode::SetVarRef0,
1062    Opcode::SetVarRef1,
1063    Opcode::SetVarRef2,
1064    Opcode::SetVarRef3,
1065    Opcode::GetLength,
1066    Opcode::IfFalse8,
1067    Opcode::IfTrue8,
1068    Opcode::Goto8,
1069    Opcode::Goto16,
1070    Opcode::Call0,
1071    Opcode::Call1,
1072    Opcode::Call2,
1073    Opcode::Call3,
1074    Opcode::IsUndefined,
1075    Opcode::IsNull,
1076    Opcode::TypeofIsUndefined,
1077    Opcode::TypeofIsFunction,
1078];
1079
1080/// Static descriptions, indexed by discriminant.
1081static OP_INFO: [OpInfo; 250] = [
1082    OpInfo {
1083        name: "invalid",
1084        size: 1,
1085        n_pop: 0,
1086        n_push: 0,
1087        format: OpFormat::None,
1088    },
1089    OpInfo {
1090        name: "push_i32",
1091        size: 5,
1092        n_pop: 0,
1093        n_push: 1,
1094        format: OpFormat::I32,
1095    },
1096    OpInfo {
1097        name: "push_const",
1098        size: 5,
1099        n_pop: 0,
1100        n_push: 1,
1101        format: OpFormat::Const,
1102    },
1103    OpInfo {
1104        name: "fclosure",
1105        size: 5,
1106        n_pop: 0,
1107        n_push: 1,
1108        format: OpFormat::Const,
1109    },
1110    OpInfo {
1111        name: "push_atom_value",
1112        size: 5,
1113        n_pop: 0,
1114        n_push: 1,
1115        format: OpFormat::Atom,
1116    },
1117    OpInfo {
1118        name: "private_symbol",
1119        size: 5,
1120        n_pop: 0,
1121        n_push: 1,
1122        format: OpFormat::Atom,
1123    },
1124    OpInfo {
1125        name: "undefined",
1126        size: 1,
1127        n_pop: 0,
1128        n_push: 1,
1129        format: OpFormat::None,
1130    },
1131    OpInfo {
1132        name: "null",
1133        size: 1,
1134        n_pop: 0,
1135        n_push: 1,
1136        format: OpFormat::None,
1137    },
1138    OpInfo {
1139        name: "push_this",
1140        size: 1,
1141        n_pop: 0,
1142        n_push: 1,
1143        format: OpFormat::None,
1144    },
1145    OpInfo {
1146        name: "push_false",
1147        size: 1,
1148        n_pop: 0,
1149        n_push: 1,
1150        format: OpFormat::None,
1151    },
1152    OpInfo {
1153        name: "push_true",
1154        size: 1,
1155        n_pop: 0,
1156        n_push: 1,
1157        format: OpFormat::None,
1158    },
1159    OpInfo {
1160        name: "object",
1161        size: 1,
1162        n_pop: 0,
1163        n_push: 1,
1164        format: OpFormat::None,
1165    },
1166    OpInfo {
1167        name: "special_object",
1168        size: 2,
1169        n_pop: 0,
1170        n_push: 1,
1171        format: OpFormat::U8,
1172    },
1173    OpInfo {
1174        name: "rest",
1175        size: 3,
1176        n_pop: 0,
1177        n_push: 1,
1178        format: OpFormat::U16,
1179    },
1180    OpInfo {
1181        name: "drop",
1182        size: 1,
1183        n_pop: 1,
1184        n_push: 0,
1185        format: OpFormat::None,
1186    },
1187    OpInfo {
1188        name: "nip",
1189        size: 1,
1190        n_pop: 2,
1191        n_push: 1,
1192        format: OpFormat::None,
1193    },
1194    OpInfo {
1195        name: "nip1",
1196        size: 1,
1197        n_pop: 3,
1198        n_push: 2,
1199        format: OpFormat::None,
1200    },
1201    OpInfo {
1202        name: "dup",
1203        size: 1,
1204        n_pop: 1,
1205        n_push: 2,
1206        format: OpFormat::None,
1207    },
1208    OpInfo {
1209        name: "dup1",
1210        size: 1,
1211        n_pop: 2,
1212        n_push: 3,
1213        format: OpFormat::None,
1214    },
1215    OpInfo {
1216        name: "dup2",
1217        size: 1,
1218        n_pop: 2,
1219        n_push: 4,
1220        format: OpFormat::None,
1221    },
1222    OpInfo {
1223        name: "dup3",
1224        size: 1,
1225        n_pop: 3,
1226        n_push: 6,
1227        format: OpFormat::None,
1228    },
1229    OpInfo {
1230        name: "insert2",
1231        size: 1,
1232        n_pop: 2,
1233        n_push: 3,
1234        format: OpFormat::None,
1235    },
1236    OpInfo {
1237        name: "insert3",
1238        size: 1,
1239        n_pop: 3,
1240        n_push: 4,
1241        format: OpFormat::None,
1242    },
1243    OpInfo {
1244        name: "insert4",
1245        size: 1,
1246        n_pop: 4,
1247        n_push: 5,
1248        format: OpFormat::None,
1249    },
1250    OpInfo {
1251        name: "perm3",
1252        size: 1,
1253        n_pop: 3,
1254        n_push: 3,
1255        format: OpFormat::None,
1256    },
1257    OpInfo {
1258        name: "perm4",
1259        size: 1,
1260        n_pop: 4,
1261        n_push: 4,
1262        format: OpFormat::None,
1263    },
1264    OpInfo {
1265        name: "perm5",
1266        size: 1,
1267        n_pop: 5,
1268        n_push: 5,
1269        format: OpFormat::None,
1270    },
1271    OpInfo {
1272        name: "swap",
1273        size: 1,
1274        n_pop: 2,
1275        n_push: 2,
1276        format: OpFormat::None,
1277    },
1278    OpInfo {
1279        name: "swap2",
1280        size: 1,
1281        n_pop: 4,
1282        n_push: 4,
1283        format: OpFormat::None,
1284    },
1285    OpInfo {
1286        name: "rot3l",
1287        size: 1,
1288        n_pop: 3,
1289        n_push: 3,
1290        format: OpFormat::None,
1291    },
1292    OpInfo {
1293        name: "rot3r",
1294        size: 1,
1295        n_pop: 3,
1296        n_push: 3,
1297        format: OpFormat::None,
1298    },
1299    OpInfo {
1300        name: "rot4l",
1301        size: 1,
1302        n_pop: 4,
1303        n_push: 4,
1304        format: OpFormat::None,
1305    },
1306    OpInfo {
1307        name: "rot5l",
1308        size: 1,
1309        n_pop: 5,
1310        n_push: 5,
1311        format: OpFormat::None,
1312    },
1313    OpInfo {
1314        name: "call_constructor",
1315        size: 3,
1316        n_pop: 2,
1317        n_push: 1,
1318        format: OpFormat::Npop,
1319    },
1320    OpInfo {
1321        name: "call",
1322        size: 3,
1323        n_pop: 1,
1324        n_push: 1,
1325        format: OpFormat::Npop,
1326    },
1327    OpInfo {
1328        name: "tail_call",
1329        size: 3,
1330        n_pop: 1,
1331        n_push: 0,
1332        format: OpFormat::Npop,
1333    },
1334    OpInfo {
1335        name: "call_method",
1336        size: 3,
1337        n_pop: 2,
1338        n_push: 1,
1339        format: OpFormat::Npop,
1340    },
1341    OpInfo {
1342        name: "tail_call_method",
1343        size: 3,
1344        n_pop: 2,
1345        n_push: 0,
1346        format: OpFormat::Npop,
1347    },
1348    OpInfo {
1349        name: "array_from",
1350        size: 3,
1351        n_pop: 0,
1352        n_push: 1,
1353        format: OpFormat::Npop,
1354    },
1355    OpInfo {
1356        name: "apply",
1357        size: 3,
1358        n_pop: 3,
1359        n_push: 1,
1360        format: OpFormat::U16,
1361    },
1362    OpInfo {
1363        name: "return",
1364        size: 1,
1365        n_pop: 1,
1366        n_push: 0,
1367        format: OpFormat::None,
1368    },
1369    OpInfo {
1370        name: "return_undef",
1371        size: 1,
1372        n_pop: 0,
1373        n_push: 0,
1374        format: OpFormat::None,
1375    },
1376    OpInfo {
1377        name: "check_ctor_return",
1378        size: 1,
1379        n_pop: 1,
1380        n_push: 2,
1381        format: OpFormat::None,
1382    },
1383    OpInfo {
1384        name: "check_ctor",
1385        size: 1,
1386        n_pop: 0,
1387        n_push: 0,
1388        format: OpFormat::None,
1389    },
1390    OpInfo {
1391        name: "init_ctor",
1392        size: 1,
1393        n_pop: 0,
1394        n_push: 1,
1395        format: OpFormat::None,
1396    },
1397    OpInfo {
1398        name: "check_brand",
1399        size: 1,
1400        n_pop: 2,
1401        n_push: 2,
1402        format: OpFormat::None,
1403    },
1404    OpInfo {
1405        name: "add_brand",
1406        size: 1,
1407        n_pop: 2,
1408        n_push: 0,
1409        format: OpFormat::None,
1410    },
1411    OpInfo {
1412        name: "return_async",
1413        size: 1,
1414        n_pop: 1,
1415        n_push: 0,
1416        format: OpFormat::None,
1417    },
1418    OpInfo {
1419        name: "throw",
1420        size: 1,
1421        n_pop: 1,
1422        n_push: 0,
1423        format: OpFormat::None,
1424    },
1425    OpInfo {
1426        name: "throw_error",
1427        size: 6,
1428        n_pop: 0,
1429        n_push: 0,
1430        format: OpFormat::AtomU8,
1431    },
1432    OpInfo {
1433        name: "eval",
1434        size: 5,
1435        n_pop: 1,
1436        n_push: 1,
1437        format: OpFormat::NpopU16,
1438    },
1439    OpInfo {
1440        name: "apply_eval",
1441        size: 3,
1442        n_pop: 2,
1443        n_push: 1,
1444        format: OpFormat::U16,
1445    },
1446    OpInfo {
1447        name: "regexp",
1448        size: 1,
1449        n_pop: 2,
1450        n_push: 1,
1451        format: OpFormat::None,
1452    },
1453    OpInfo {
1454        name: "get_super",
1455        size: 1,
1456        n_pop: 1,
1457        n_push: 1,
1458        format: OpFormat::None,
1459    },
1460    OpInfo {
1461        name: "import",
1462        size: 1,
1463        n_pop: 2,
1464        n_push: 1,
1465        format: OpFormat::None,
1466    },
1467    OpInfo {
1468        name: "get_var_undef",
1469        size: 3,
1470        n_pop: 0,
1471        n_push: 1,
1472        format: OpFormat::VarRef,
1473    },
1474    OpInfo {
1475        name: "get_var",
1476        size: 3,
1477        n_pop: 0,
1478        n_push: 1,
1479        format: OpFormat::VarRef,
1480    },
1481    OpInfo {
1482        name: "put_var",
1483        size: 3,
1484        n_pop: 1,
1485        n_push: 0,
1486        format: OpFormat::VarRef,
1487    },
1488    OpInfo {
1489        name: "put_var_init",
1490        size: 3,
1491        n_pop: 1,
1492        n_push: 0,
1493        format: OpFormat::VarRef,
1494    },
1495    OpInfo {
1496        name: "get_ref_value",
1497        size: 1,
1498        n_pop: 2,
1499        n_push: 3,
1500        format: OpFormat::None,
1501    },
1502    OpInfo {
1503        name: "put_ref_value",
1504        size: 1,
1505        n_pop: 3,
1506        n_push: 0,
1507        format: OpFormat::None,
1508    },
1509    OpInfo {
1510        name: "get_field",
1511        size: 5,
1512        n_pop: 1,
1513        n_push: 1,
1514        format: OpFormat::Atom,
1515    },
1516    OpInfo {
1517        name: "get_field2",
1518        size: 5,
1519        n_pop: 1,
1520        n_push: 2,
1521        format: OpFormat::Atom,
1522    },
1523    OpInfo {
1524        name: "put_field",
1525        size: 5,
1526        n_pop: 2,
1527        n_push: 0,
1528        format: OpFormat::Atom,
1529    },
1530    OpInfo {
1531        name: "get_private_field",
1532        size: 1,
1533        n_pop: 2,
1534        n_push: 1,
1535        format: OpFormat::None,
1536    },
1537    OpInfo {
1538        name: "put_private_field",
1539        size: 1,
1540        n_pop: 3,
1541        n_push: 0,
1542        format: OpFormat::None,
1543    },
1544    OpInfo {
1545        name: "define_private_field",
1546        size: 1,
1547        n_pop: 3,
1548        n_push: 1,
1549        format: OpFormat::None,
1550    },
1551    OpInfo {
1552        name: "get_array_el",
1553        size: 1,
1554        n_pop: 2,
1555        n_push: 1,
1556        format: OpFormat::None,
1557    },
1558    OpInfo {
1559        name: "get_array_el2",
1560        size: 1,
1561        n_pop: 2,
1562        n_push: 2,
1563        format: OpFormat::None,
1564    },
1565    OpInfo {
1566        name: "get_array_el3",
1567        size: 1,
1568        n_pop: 2,
1569        n_push: 3,
1570        format: OpFormat::None,
1571    },
1572    OpInfo {
1573        name: "put_array_el",
1574        size: 1,
1575        n_pop: 3,
1576        n_push: 0,
1577        format: OpFormat::None,
1578    },
1579    OpInfo {
1580        name: "get_super_value",
1581        size: 1,
1582        n_pop: 3,
1583        n_push: 1,
1584        format: OpFormat::None,
1585    },
1586    OpInfo {
1587        name: "put_super_value",
1588        size: 1,
1589        n_pop: 4,
1590        n_push: 0,
1591        format: OpFormat::None,
1592    },
1593    OpInfo {
1594        name: "define_field",
1595        size: 5,
1596        n_pop: 2,
1597        n_push: 1,
1598        format: OpFormat::Atom,
1599    },
1600    OpInfo {
1601        name: "set_name",
1602        size: 5,
1603        n_pop: 1,
1604        n_push: 1,
1605        format: OpFormat::Atom,
1606    },
1607    OpInfo {
1608        name: "set_name_computed",
1609        size: 1,
1610        n_pop: 2,
1611        n_push: 2,
1612        format: OpFormat::None,
1613    },
1614    OpInfo {
1615        name: "set_proto",
1616        size: 1,
1617        n_pop: 2,
1618        n_push: 1,
1619        format: OpFormat::None,
1620    },
1621    OpInfo {
1622        name: "set_home_object",
1623        size: 1,
1624        n_pop: 2,
1625        n_push: 2,
1626        format: OpFormat::None,
1627    },
1628    OpInfo {
1629        name: "define_array_el",
1630        size: 1,
1631        n_pop: 3,
1632        n_push: 2,
1633        format: OpFormat::None,
1634    },
1635    OpInfo {
1636        name: "append",
1637        size: 1,
1638        n_pop: 3,
1639        n_push: 2,
1640        format: OpFormat::None,
1641    },
1642    OpInfo {
1643        name: "copy_data_properties",
1644        size: 2,
1645        n_pop: 3,
1646        n_push: 3,
1647        format: OpFormat::U8,
1648    },
1649    OpInfo {
1650        name: "define_method",
1651        size: 6,
1652        n_pop: 2,
1653        n_push: 1,
1654        format: OpFormat::AtomU8,
1655    },
1656    OpInfo {
1657        name: "define_method_computed",
1658        size: 2,
1659        n_pop: 3,
1660        n_push: 1,
1661        format: OpFormat::U8,
1662    },
1663    OpInfo {
1664        name: "define_class",
1665        size: 6,
1666        n_pop: 2,
1667        n_push: 2,
1668        format: OpFormat::AtomU8,
1669    },
1670    OpInfo {
1671        name: "define_class_computed",
1672        size: 6,
1673        n_pop: 3,
1674        n_push: 3,
1675        format: OpFormat::AtomU8,
1676    },
1677    OpInfo {
1678        name: "get_loc",
1679        size: 3,
1680        n_pop: 0,
1681        n_push: 1,
1682        format: OpFormat::Loc,
1683    },
1684    OpInfo {
1685        name: "put_loc",
1686        size: 3,
1687        n_pop: 1,
1688        n_push: 0,
1689        format: OpFormat::Loc,
1690    },
1691    OpInfo {
1692        name: "set_loc",
1693        size: 3,
1694        n_pop: 1,
1695        n_push: 1,
1696        format: OpFormat::Loc,
1697    },
1698    OpInfo {
1699        name: "get_arg",
1700        size: 3,
1701        n_pop: 0,
1702        n_push: 1,
1703        format: OpFormat::Arg,
1704    },
1705    OpInfo {
1706        name: "put_arg",
1707        size: 3,
1708        n_pop: 1,
1709        n_push: 0,
1710        format: OpFormat::Arg,
1711    },
1712    OpInfo {
1713        name: "set_arg",
1714        size: 3,
1715        n_pop: 1,
1716        n_push: 1,
1717        format: OpFormat::Arg,
1718    },
1719    OpInfo {
1720        name: "get_var_ref",
1721        size: 3,
1722        n_pop: 0,
1723        n_push: 1,
1724        format: OpFormat::VarRef,
1725    },
1726    OpInfo {
1727        name: "put_var_ref",
1728        size: 3,
1729        n_pop: 1,
1730        n_push: 0,
1731        format: OpFormat::VarRef,
1732    },
1733    OpInfo {
1734        name: "set_var_ref",
1735        size: 3,
1736        n_pop: 1,
1737        n_push: 1,
1738        format: OpFormat::VarRef,
1739    },
1740    OpInfo {
1741        name: "set_loc_uninitialized",
1742        size: 3,
1743        n_pop: 0,
1744        n_push: 0,
1745        format: OpFormat::Loc,
1746    },
1747    OpInfo {
1748        name: "get_loc_check",
1749        size: 3,
1750        n_pop: 0,
1751        n_push: 1,
1752        format: OpFormat::Loc,
1753    },
1754    OpInfo {
1755        name: "put_loc_check",
1756        size: 3,
1757        n_pop: 1,
1758        n_push: 0,
1759        format: OpFormat::Loc,
1760    },
1761    OpInfo {
1762        name: "set_loc_check",
1763        size: 3,
1764        n_pop: 1,
1765        n_push: 1,
1766        format: OpFormat::Loc,
1767    },
1768    OpInfo {
1769        name: "put_loc_check_init",
1770        size: 3,
1771        n_pop: 1,
1772        n_push: 0,
1773        format: OpFormat::Loc,
1774    },
1775    OpInfo {
1776        name: "get_loc_checkthis",
1777        size: 3,
1778        n_pop: 0,
1779        n_push: 1,
1780        format: OpFormat::Loc,
1781    },
1782    OpInfo {
1783        name: "get_var_ref_check",
1784        size: 3,
1785        n_pop: 0,
1786        n_push: 1,
1787        format: OpFormat::VarRef,
1788    },
1789    OpInfo {
1790        name: "put_var_ref_check",
1791        size: 3,
1792        n_pop: 1,
1793        n_push: 0,
1794        format: OpFormat::VarRef,
1795    },
1796    OpInfo {
1797        name: "put_var_ref_check_init",
1798        size: 3,
1799        n_pop: 1,
1800        n_push: 0,
1801        format: OpFormat::VarRef,
1802    },
1803    OpInfo {
1804        name: "close_loc",
1805        size: 3,
1806        n_pop: 0,
1807        n_push: 0,
1808        format: OpFormat::Loc,
1809    },
1810    OpInfo {
1811        name: "if_false",
1812        size: 5,
1813        n_pop: 1,
1814        n_push: 0,
1815        format: OpFormat::Label,
1816    },
1817    OpInfo {
1818        name: "if_true",
1819        size: 5,
1820        n_pop: 1,
1821        n_push: 0,
1822        format: OpFormat::Label,
1823    },
1824    OpInfo {
1825        name: "goto",
1826        size: 5,
1827        n_pop: 0,
1828        n_push: 0,
1829        format: OpFormat::Label,
1830    },
1831    OpInfo {
1832        name: "catch",
1833        size: 5,
1834        n_pop: 0,
1835        n_push: 1,
1836        format: OpFormat::Label,
1837    },
1838    OpInfo {
1839        name: "gosub",
1840        size: 5,
1841        n_pop: 0,
1842        n_push: 0,
1843        format: OpFormat::Label,
1844    },
1845    OpInfo {
1846        name: "ret",
1847        size: 1,
1848        n_pop: 1,
1849        n_push: 0,
1850        format: OpFormat::None,
1851    },
1852    OpInfo {
1853        name: "nip_catch",
1854        size: 1,
1855        n_pop: 2,
1856        n_push: 1,
1857        format: OpFormat::None,
1858    },
1859    OpInfo {
1860        name: "to_object",
1861        size: 1,
1862        n_pop: 1,
1863        n_push: 1,
1864        format: OpFormat::None,
1865    },
1866    OpInfo {
1867        name: "to_propkey",
1868        size: 1,
1869        n_pop: 1,
1870        n_push: 1,
1871        format: OpFormat::None,
1872    },
1873    OpInfo {
1874        name: "with_get_var",
1875        size: 10,
1876        n_pop: 1,
1877        n_push: 0,
1878        format: OpFormat::AtomLabelU8,
1879    },
1880    OpInfo {
1881        name: "with_put_var",
1882        size: 10,
1883        n_pop: 2,
1884        n_push: 1,
1885        format: OpFormat::AtomLabelU8,
1886    },
1887    OpInfo {
1888        name: "with_delete_var",
1889        size: 10,
1890        n_pop: 1,
1891        n_push: 0,
1892        format: OpFormat::AtomLabelU8,
1893    },
1894    OpInfo {
1895        name: "with_make_ref",
1896        size: 10,
1897        n_pop: 1,
1898        n_push: 0,
1899        format: OpFormat::AtomLabelU8,
1900    },
1901    OpInfo {
1902        name: "with_get_ref",
1903        size: 10,
1904        n_pop: 1,
1905        n_push: 0,
1906        format: OpFormat::AtomLabelU8,
1907    },
1908    OpInfo {
1909        name: "make_loc_ref",
1910        size: 7,
1911        n_pop: 0,
1912        n_push: 2,
1913        format: OpFormat::AtomU16,
1914    },
1915    OpInfo {
1916        name: "make_arg_ref",
1917        size: 7,
1918        n_pop: 0,
1919        n_push: 2,
1920        format: OpFormat::AtomU16,
1921    },
1922    OpInfo {
1923        name: "make_var_ref_ref",
1924        size: 7,
1925        n_pop: 0,
1926        n_push: 2,
1927        format: OpFormat::AtomU16,
1928    },
1929    OpInfo {
1930        name: "make_var_ref",
1931        size: 5,
1932        n_pop: 0,
1933        n_push: 2,
1934        format: OpFormat::Atom,
1935    },
1936    OpInfo {
1937        name: "for_in_start",
1938        size: 1,
1939        n_pop: 1,
1940        n_push: 1,
1941        format: OpFormat::None,
1942    },
1943    OpInfo {
1944        name: "for_of_start",
1945        size: 1,
1946        n_pop: 1,
1947        n_push: 3,
1948        format: OpFormat::None,
1949    },
1950    OpInfo {
1951        name: "for_await_of_start",
1952        size: 1,
1953        n_pop: 1,
1954        n_push: 3,
1955        format: OpFormat::None,
1956    },
1957    OpInfo {
1958        name: "for_in_next",
1959        size: 1,
1960        n_pop: 1,
1961        n_push: 3,
1962        format: OpFormat::None,
1963    },
1964    OpInfo {
1965        name: "for_of_next",
1966        size: 2,
1967        n_pop: 3,
1968        n_push: 5,
1969        format: OpFormat::U8,
1970    },
1971    OpInfo {
1972        name: "for_await_of_next",
1973        size: 1,
1974        n_pop: 3,
1975        n_push: 4,
1976        format: OpFormat::None,
1977    },
1978    OpInfo {
1979        name: "iterator_check_object",
1980        size: 1,
1981        n_pop: 1,
1982        n_push: 1,
1983        format: OpFormat::None,
1984    },
1985    OpInfo {
1986        name: "iterator_get_value_done",
1987        size: 1,
1988        n_pop: 2,
1989        n_push: 3,
1990        format: OpFormat::None,
1991    },
1992    OpInfo {
1993        name: "iterator_close",
1994        size: 1,
1995        n_pop: 3,
1996        n_push: 0,
1997        format: OpFormat::None,
1998    },
1999    OpInfo {
2000        name: "iterator_next",
2001        size: 1,
2002        n_pop: 4,
2003        n_push: 4,
2004        format: OpFormat::None,
2005    },
2006    OpInfo {
2007        name: "iterator_call",
2008        size: 2,
2009        n_pop: 4,
2010        n_push: 5,
2011        format: OpFormat::U8,
2012    },
2013    OpInfo {
2014        name: "initial_yield",
2015        size: 1,
2016        n_pop: 0,
2017        n_push: 0,
2018        format: OpFormat::None,
2019    },
2020    OpInfo {
2021        name: "yield",
2022        size: 1,
2023        n_pop: 1,
2024        n_push: 2,
2025        format: OpFormat::None,
2026    },
2027    OpInfo {
2028        name: "yield_star",
2029        size: 1,
2030        n_pop: 1,
2031        n_push: 2,
2032        format: OpFormat::None,
2033    },
2034    OpInfo {
2035        name: "async_yield_star",
2036        size: 1,
2037        n_pop: 1,
2038        n_push: 2,
2039        format: OpFormat::None,
2040    },
2041    OpInfo {
2042        name: "await",
2043        size: 1,
2044        n_pop: 1,
2045        n_push: 1,
2046        format: OpFormat::None,
2047    },
2048    OpInfo {
2049        name: "neg",
2050        size: 1,
2051        n_pop: 1,
2052        n_push: 1,
2053        format: OpFormat::None,
2054    },
2055    OpInfo {
2056        name: "plus",
2057        size: 1,
2058        n_pop: 1,
2059        n_push: 1,
2060        format: OpFormat::None,
2061    },
2062    OpInfo {
2063        name: "dec",
2064        size: 1,
2065        n_pop: 1,
2066        n_push: 1,
2067        format: OpFormat::None,
2068    },
2069    OpInfo {
2070        name: "inc",
2071        size: 1,
2072        n_pop: 1,
2073        n_push: 1,
2074        format: OpFormat::None,
2075    },
2076    OpInfo {
2077        name: "post_dec",
2078        size: 1,
2079        n_pop: 1,
2080        n_push: 2,
2081        format: OpFormat::None,
2082    },
2083    OpInfo {
2084        name: "post_inc",
2085        size: 1,
2086        n_pop: 1,
2087        n_push: 2,
2088        format: OpFormat::None,
2089    },
2090    OpInfo {
2091        name: "dec_loc",
2092        size: 2,
2093        n_pop: 0,
2094        n_push: 0,
2095        format: OpFormat::Loc8,
2096    },
2097    OpInfo {
2098        name: "inc_loc",
2099        size: 2,
2100        n_pop: 0,
2101        n_push: 0,
2102        format: OpFormat::Loc8,
2103    },
2104    OpInfo {
2105        name: "add_loc",
2106        size: 2,
2107        n_pop: 1,
2108        n_push: 0,
2109        format: OpFormat::Loc8,
2110    },
2111    OpInfo {
2112        name: "not",
2113        size: 1,
2114        n_pop: 1,
2115        n_push: 1,
2116        format: OpFormat::None,
2117    },
2118    OpInfo {
2119        name: "lnot",
2120        size: 1,
2121        n_pop: 1,
2122        n_push: 1,
2123        format: OpFormat::None,
2124    },
2125    OpInfo {
2126        name: "typeof",
2127        size: 1,
2128        n_pop: 1,
2129        n_push: 1,
2130        format: OpFormat::None,
2131    },
2132    OpInfo {
2133        name: "delete",
2134        size: 1,
2135        n_pop: 2,
2136        n_push: 1,
2137        format: OpFormat::None,
2138    },
2139    OpInfo {
2140        name: "delete_var",
2141        size: 5,
2142        n_pop: 0,
2143        n_push: 1,
2144        format: OpFormat::Atom,
2145    },
2146    OpInfo {
2147        name: "mul",
2148        size: 1,
2149        n_pop: 2,
2150        n_push: 1,
2151        format: OpFormat::None,
2152    },
2153    OpInfo {
2154        name: "div",
2155        size: 1,
2156        n_pop: 2,
2157        n_push: 1,
2158        format: OpFormat::None,
2159    },
2160    OpInfo {
2161        name: "mod",
2162        size: 1,
2163        n_pop: 2,
2164        n_push: 1,
2165        format: OpFormat::None,
2166    },
2167    OpInfo {
2168        name: "add",
2169        size: 1,
2170        n_pop: 2,
2171        n_push: 1,
2172        format: OpFormat::None,
2173    },
2174    OpInfo {
2175        name: "sub",
2176        size: 1,
2177        n_pop: 2,
2178        n_push: 1,
2179        format: OpFormat::None,
2180    },
2181    OpInfo {
2182        name: "pow",
2183        size: 1,
2184        n_pop: 2,
2185        n_push: 1,
2186        format: OpFormat::None,
2187    },
2188    OpInfo {
2189        name: "shl",
2190        size: 1,
2191        n_pop: 2,
2192        n_push: 1,
2193        format: OpFormat::None,
2194    },
2195    OpInfo {
2196        name: "sar",
2197        size: 1,
2198        n_pop: 2,
2199        n_push: 1,
2200        format: OpFormat::None,
2201    },
2202    OpInfo {
2203        name: "shr",
2204        size: 1,
2205        n_pop: 2,
2206        n_push: 1,
2207        format: OpFormat::None,
2208    },
2209    OpInfo {
2210        name: "lt",
2211        size: 1,
2212        n_pop: 2,
2213        n_push: 1,
2214        format: OpFormat::None,
2215    },
2216    OpInfo {
2217        name: "lte",
2218        size: 1,
2219        n_pop: 2,
2220        n_push: 1,
2221        format: OpFormat::None,
2222    },
2223    OpInfo {
2224        name: "gt",
2225        size: 1,
2226        n_pop: 2,
2227        n_push: 1,
2228        format: OpFormat::None,
2229    },
2230    OpInfo {
2231        name: "gte",
2232        size: 1,
2233        n_pop: 2,
2234        n_push: 1,
2235        format: OpFormat::None,
2236    },
2237    OpInfo {
2238        name: "instanceof",
2239        size: 1,
2240        n_pop: 2,
2241        n_push: 1,
2242        format: OpFormat::None,
2243    },
2244    OpInfo {
2245        name: "in",
2246        size: 1,
2247        n_pop: 2,
2248        n_push: 1,
2249        format: OpFormat::None,
2250    },
2251    OpInfo {
2252        name: "eq",
2253        size: 1,
2254        n_pop: 2,
2255        n_push: 1,
2256        format: OpFormat::None,
2257    },
2258    OpInfo {
2259        name: "neq",
2260        size: 1,
2261        n_pop: 2,
2262        n_push: 1,
2263        format: OpFormat::None,
2264    },
2265    OpInfo {
2266        name: "strict_eq",
2267        size: 1,
2268        n_pop: 2,
2269        n_push: 1,
2270        format: OpFormat::None,
2271    },
2272    OpInfo {
2273        name: "strict_neq",
2274        size: 1,
2275        n_pop: 2,
2276        n_push: 1,
2277        format: OpFormat::None,
2278    },
2279    OpInfo {
2280        name: "and",
2281        size: 1,
2282        n_pop: 2,
2283        n_push: 1,
2284        format: OpFormat::None,
2285    },
2286    OpInfo {
2287        name: "xor",
2288        size: 1,
2289        n_pop: 2,
2290        n_push: 1,
2291        format: OpFormat::None,
2292    },
2293    OpInfo {
2294        name: "or",
2295        size: 1,
2296        n_pop: 2,
2297        n_push: 1,
2298        format: OpFormat::None,
2299    },
2300    OpInfo {
2301        name: "is_undefined_or_null",
2302        size: 1,
2303        n_pop: 1,
2304        n_push: 1,
2305        format: OpFormat::None,
2306    },
2307    OpInfo {
2308        name: "private_in",
2309        size: 1,
2310        n_pop: 2,
2311        n_push: 1,
2312        format: OpFormat::None,
2313    },
2314    OpInfo {
2315        name: "push_bigint_i32",
2316        size: 5,
2317        n_pop: 0,
2318        n_push: 1,
2319        format: OpFormat::I32,
2320    },
2321    OpInfo {
2322        name: "using_dispose_init",
2323        size: 1,
2324        n_pop: 0,
2325        n_push: 1,
2326        format: OpFormat::None,
2327    },
2328    OpInfo {
2329        name: "using_dispose",
2330        size: 3,
2331        n_pop: 1,
2332        n_push: 1,
2333        format: OpFormat::Loc,
2334    },
2335    OpInfo {
2336        name: "using_dispose_async",
2337        size: 3,
2338        n_pop: 0,
2339        n_push: 1,
2340        format: OpFormat::Loc,
2341    },
2342    OpInfo {
2343        name: "using_dispose_merge",
2344        size: 1,
2345        n_pop: 2,
2346        n_push: 1,
2347        format: OpFormat::None,
2348    },
2349    OpInfo {
2350        name: "using_dispose_end",
2351        size: 1,
2352        n_pop: 1,
2353        n_push: 0,
2354        format: OpFormat::None,
2355    },
2356    OpInfo {
2357        name: "using_check",
2358        size: 2,
2359        n_pop: 1,
2360        n_push: 2,
2361        format: OpFormat::U8,
2362    },
2363    OpInfo {
2364        name: "nop",
2365        size: 1,
2366        n_pop: 0,
2367        n_push: 0,
2368        format: OpFormat::None,
2369    },
2370    OpInfo {
2371        name: "push_minus1",
2372        size: 1,
2373        n_pop: 0,
2374        n_push: 1,
2375        format: OpFormat::NoneInt,
2376    },
2377    OpInfo {
2378        name: "push_0",
2379        size: 1,
2380        n_pop: 0,
2381        n_push: 1,
2382        format: OpFormat::NoneInt,
2383    },
2384    OpInfo {
2385        name: "push_1",
2386        size: 1,
2387        n_pop: 0,
2388        n_push: 1,
2389        format: OpFormat::NoneInt,
2390    },
2391    OpInfo {
2392        name: "push_2",
2393        size: 1,
2394        n_pop: 0,
2395        n_push: 1,
2396        format: OpFormat::NoneInt,
2397    },
2398    OpInfo {
2399        name: "push_3",
2400        size: 1,
2401        n_pop: 0,
2402        n_push: 1,
2403        format: OpFormat::NoneInt,
2404    },
2405    OpInfo {
2406        name: "push_4",
2407        size: 1,
2408        n_pop: 0,
2409        n_push: 1,
2410        format: OpFormat::NoneInt,
2411    },
2412    OpInfo {
2413        name: "push_5",
2414        size: 1,
2415        n_pop: 0,
2416        n_push: 1,
2417        format: OpFormat::NoneInt,
2418    },
2419    OpInfo {
2420        name: "push_6",
2421        size: 1,
2422        n_pop: 0,
2423        n_push: 1,
2424        format: OpFormat::NoneInt,
2425    },
2426    OpInfo {
2427        name: "push_7",
2428        size: 1,
2429        n_pop: 0,
2430        n_push: 1,
2431        format: OpFormat::NoneInt,
2432    },
2433    OpInfo {
2434        name: "push_i8",
2435        size: 2,
2436        n_pop: 0,
2437        n_push: 1,
2438        format: OpFormat::I8,
2439    },
2440    OpInfo {
2441        name: "push_i16",
2442        size: 3,
2443        n_pop: 0,
2444        n_push: 1,
2445        format: OpFormat::I16,
2446    },
2447    OpInfo {
2448        name: "push_const8",
2449        size: 2,
2450        n_pop: 0,
2451        n_push: 1,
2452        format: OpFormat::Const8,
2453    },
2454    OpInfo {
2455        name: "fclosure8",
2456        size: 2,
2457        n_pop: 0,
2458        n_push: 1,
2459        format: OpFormat::Const8,
2460    },
2461    OpInfo {
2462        name: "push_empty_string",
2463        size: 1,
2464        n_pop: 0,
2465        n_push: 1,
2466        format: OpFormat::None,
2467    },
2468    OpInfo {
2469        name: "get_loc8",
2470        size: 2,
2471        n_pop: 0,
2472        n_push: 1,
2473        format: OpFormat::Loc8,
2474    },
2475    OpInfo {
2476        name: "put_loc8",
2477        size: 2,
2478        n_pop: 1,
2479        n_push: 0,
2480        format: OpFormat::Loc8,
2481    },
2482    OpInfo {
2483        name: "set_loc8",
2484        size: 2,
2485        n_pop: 1,
2486        n_push: 1,
2487        format: OpFormat::Loc8,
2488    },
2489    OpInfo {
2490        name: "get_loc0",
2491        size: 1,
2492        n_pop: 0,
2493        n_push: 1,
2494        format: OpFormat::NoneLoc,
2495    },
2496    OpInfo {
2497        name: "get_loc1",
2498        size: 1,
2499        n_pop: 0,
2500        n_push: 1,
2501        format: OpFormat::NoneLoc,
2502    },
2503    OpInfo {
2504        name: "get_loc2",
2505        size: 1,
2506        n_pop: 0,
2507        n_push: 1,
2508        format: OpFormat::NoneLoc,
2509    },
2510    OpInfo {
2511        name: "get_loc3",
2512        size: 1,
2513        n_pop: 0,
2514        n_push: 1,
2515        format: OpFormat::NoneLoc,
2516    },
2517    OpInfo {
2518        name: "put_loc0",
2519        size: 1,
2520        n_pop: 1,
2521        n_push: 0,
2522        format: OpFormat::NoneLoc,
2523    },
2524    OpInfo {
2525        name: "put_loc1",
2526        size: 1,
2527        n_pop: 1,
2528        n_push: 0,
2529        format: OpFormat::NoneLoc,
2530    },
2531    OpInfo {
2532        name: "put_loc2",
2533        size: 1,
2534        n_pop: 1,
2535        n_push: 0,
2536        format: OpFormat::NoneLoc,
2537    },
2538    OpInfo {
2539        name: "put_loc3",
2540        size: 1,
2541        n_pop: 1,
2542        n_push: 0,
2543        format: OpFormat::NoneLoc,
2544    },
2545    OpInfo {
2546        name: "set_loc0",
2547        size: 1,
2548        n_pop: 1,
2549        n_push: 1,
2550        format: OpFormat::NoneLoc,
2551    },
2552    OpInfo {
2553        name: "set_loc1",
2554        size: 1,
2555        n_pop: 1,
2556        n_push: 1,
2557        format: OpFormat::NoneLoc,
2558    },
2559    OpInfo {
2560        name: "set_loc2",
2561        size: 1,
2562        n_pop: 1,
2563        n_push: 1,
2564        format: OpFormat::NoneLoc,
2565    },
2566    OpInfo {
2567        name: "set_loc3",
2568        size: 1,
2569        n_pop: 1,
2570        n_push: 1,
2571        format: OpFormat::NoneLoc,
2572    },
2573    OpInfo {
2574        name: "get_arg0",
2575        size: 1,
2576        n_pop: 0,
2577        n_push: 1,
2578        format: OpFormat::NoneArg,
2579    },
2580    OpInfo {
2581        name: "get_arg1",
2582        size: 1,
2583        n_pop: 0,
2584        n_push: 1,
2585        format: OpFormat::NoneArg,
2586    },
2587    OpInfo {
2588        name: "get_arg2",
2589        size: 1,
2590        n_pop: 0,
2591        n_push: 1,
2592        format: OpFormat::NoneArg,
2593    },
2594    OpInfo {
2595        name: "get_arg3",
2596        size: 1,
2597        n_pop: 0,
2598        n_push: 1,
2599        format: OpFormat::NoneArg,
2600    },
2601    OpInfo {
2602        name: "put_arg0",
2603        size: 1,
2604        n_pop: 1,
2605        n_push: 0,
2606        format: OpFormat::NoneArg,
2607    },
2608    OpInfo {
2609        name: "put_arg1",
2610        size: 1,
2611        n_pop: 1,
2612        n_push: 0,
2613        format: OpFormat::NoneArg,
2614    },
2615    OpInfo {
2616        name: "put_arg2",
2617        size: 1,
2618        n_pop: 1,
2619        n_push: 0,
2620        format: OpFormat::NoneArg,
2621    },
2622    OpInfo {
2623        name: "put_arg3",
2624        size: 1,
2625        n_pop: 1,
2626        n_push: 0,
2627        format: OpFormat::NoneArg,
2628    },
2629    OpInfo {
2630        name: "set_arg0",
2631        size: 1,
2632        n_pop: 1,
2633        n_push: 1,
2634        format: OpFormat::NoneArg,
2635    },
2636    OpInfo {
2637        name: "set_arg1",
2638        size: 1,
2639        n_pop: 1,
2640        n_push: 1,
2641        format: OpFormat::NoneArg,
2642    },
2643    OpInfo {
2644        name: "set_arg2",
2645        size: 1,
2646        n_pop: 1,
2647        n_push: 1,
2648        format: OpFormat::NoneArg,
2649    },
2650    OpInfo {
2651        name: "set_arg3",
2652        size: 1,
2653        n_pop: 1,
2654        n_push: 1,
2655        format: OpFormat::NoneArg,
2656    },
2657    OpInfo {
2658        name: "get_var_ref0",
2659        size: 1,
2660        n_pop: 0,
2661        n_push: 1,
2662        format: OpFormat::NoneVarRef,
2663    },
2664    OpInfo {
2665        name: "get_var_ref1",
2666        size: 1,
2667        n_pop: 0,
2668        n_push: 1,
2669        format: OpFormat::NoneVarRef,
2670    },
2671    OpInfo {
2672        name: "get_var_ref2",
2673        size: 1,
2674        n_pop: 0,
2675        n_push: 1,
2676        format: OpFormat::NoneVarRef,
2677    },
2678    OpInfo {
2679        name: "get_var_ref3",
2680        size: 1,
2681        n_pop: 0,
2682        n_push: 1,
2683        format: OpFormat::NoneVarRef,
2684    },
2685    OpInfo {
2686        name: "put_var_ref0",
2687        size: 1,
2688        n_pop: 1,
2689        n_push: 0,
2690        format: OpFormat::NoneVarRef,
2691    },
2692    OpInfo {
2693        name: "put_var_ref1",
2694        size: 1,
2695        n_pop: 1,
2696        n_push: 0,
2697        format: OpFormat::NoneVarRef,
2698    },
2699    OpInfo {
2700        name: "put_var_ref2",
2701        size: 1,
2702        n_pop: 1,
2703        n_push: 0,
2704        format: OpFormat::NoneVarRef,
2705    },
2706    OpInfo {
2707        name: "put_var_ref3",
2708        size: 1,
2709        n_pop: 1,
2710        n_push: 0,
2711        format: OpFormat::NoneVarRef,
2712    },
2713    OpInfo {
2714        name: "set_var_ref0",
2715        size: 1,
2716        n_pop: 1,
2717        n_push: 1,
2718        format: OpFormat::NoneVarRef,
2719    },
2720    OpInfo {
2721        name: "set_var_ref1",
2722        size: 1,
2723        n_pop: 1,
2724        n_push: 1,
2725        format: OpFormat::NoneVarRef,
2726    },
2727    OpInfo {
2728        name: "set_var_ref2",
2729        size: 1,
2730        n_pop: 1,
2731        n_push: 1,
2732        format: OpFormat::NoneVarRef,
2733    },
2734    OpInfo {
2735        name: "set_var_ref3",
2736        size: 1,
2737        n_pop: 1,
2738        n_push: 1,
2739        format: OpFormat::NoneVarRef,
2740    },
2741    OpInfo {
2742        name: "get_length",
2743        size: 1,
2744        n_pop: 1,
2745        n_push: 1,
2746        format: OpFormat::None,
2747    },
2748    OpInfo {
2749        name: "if_false8",
2750        size: 2,
2751        n_pop: 1,
2752        n_push: 0,
2753        format: OpFormat::Label8,
2754    },
2755    OpInfo {
2756        name: "if_true8",
2757        size: 2,
2758        n_pop: 1,
2759        n_push: 0,
2760        format: OpFormat::Label8,
2761    },
2762    OpInfo {
2763        name: "goto8",
2764        size: 2,
2765        n_pop: 0,
2766        n_push: 0,
2767        format: OpFormat::Label8,
2768    },
2769    OpInfo {
2770        name: "goto16",
2771        size: 3,
2772        n_pop: 0,
2773        n_push: 0,
2774        format: OpFormat::Label16,
2775    },
2776    OpInfo {
2777        name: "call0",
2778        size: 1,
2779        n_pop: 1,
2780        n_push: 1,
2781        format: OpFormat::Npopx,
2782    },
2783    OpInfo {
2784        name: "call1",
2785        size: 1,
2786        n_pop: 1,
2787        n_push: 1,
2788        format: OpFormat::Npopx,
2789    },
2790    OpInfo {
2791        name: "call2",
2792        size: 1,
2793        n_pop: 1,
2794        n_push: 1,
2795        format: OpFormat::Npopx,
2796    },
2797    OpInfo {
2798        name: "call3",
2799        size: 1,
2800        n_pop: 1,
2801        n_push: 1,
2802        format: OpFormat::Npopx,
2803    },
2804    OpInfo {
2805        name: "is_undefined",
2806        size: 1,
2807        n_pop: 1,
2808        n_push: 1,
2809        format: OpFormat::None,
2810    },
2811    OpInfo {
2812        name: "is_null",
2813        size: 1,
2814        n_pop: 1,
2815        n_push: 1,
2816        format: OpFormat::None,
2817    },
2818    OpInfo {
2819        name: "typeof_is_undefined",
2820        size: 1,
2821        n_pop: 1,
2822        n_push: 1,
2823        format: OpFormat::None,
2824    },
2825    OpInfo {
2826        name: "typeof_is_function",
2827        size: 1,
2828        n_pop: 1,
2829        n_push: 1,
2830        format: OpFormat::None,
2831    },
2832];
2833
2834/// Descriptions of the temporary opcodes.
2835static TEMP_INFO: [OpInfo; 19] = [
2836    OpInfo {
2837        name: "enter_scope",
2838        size: 3,
2839        n_pop: 0,
2840        n_push: 0,
2841        format: OpFormat::U16,
2842    },
2843    OpInfo {
2844        name: "leave_scope",
2845        size: 3,
2846        n_pop: 0,
2847        n_push: 0,
2848        format: OpFormat::U16,
2849    },
2850    OpInfo {
2851        name: "label",
2852        size: 5,
2853        n_pop: 0,
2854        n_push: 0,
2855        format: OpFormat::Label,
2856    },
2857    OpInfo {
2858        name: "scope_get_var_undef",
2859        size: 7,
2860        n_pop: 0,
2861        n_push: 1,
2862        format: OpFormat::AtomU16,
2863    },
2864    OpInfo {
2865        name: "scope_get_var",
2866        size: 7,
2867        n_pop: 0,
2868        n_push: 1,
2869        format: OpFormat::AtomU16,
2870    },
2871    OpInfo {
2872        name: "scope_put_var",
2873        size: 7,
2874        n_pop: 1,
2875        n_push: 0,
2876        format: OpFormat::AtomU16,
2877    },
2878    OpInfo {
2879        name: "scope_delete_var",
2880        size: 7,
2881        n_pop: 0,
2882        n_push: 1,
2883        format: OpFormat::AtomU16,
2884    },
2885    OpInfo {
2886        name: "scope_make_ref",
2887        size: 11,
2888        n_pop: 0,
2889        n_push: 2,
2890        format: OpFormat::AtomLabelU16,
2891    },
2892    OpInfo {
2893        name: "scope_get_ref",
2894        size: 7,
2895        n_pop: 0,
2896        n_push: 2,
2897        format: OpFormat::AtomU16,
2898    },
2899    OpInfo {
2900        name: "scope_put_var_init",
2901        size: 7,
2902        n_pop: 0,
2903        n_push: 2,
2904        format: OpFormat::AtomU16,
2905    },
2906    OpInfo {
2907        name: "scope_get_var_checkthis",
2908        size: 7,
2909        n_pop: 0,
2910        n_push: 1,
2911        format: OpFormat::AtomU16,
2912    },
2913    OpInfo {
2914        name: "scope_get_private_field",
2915        size: 7,
2916        n_pop: 1,
2917        n_push: 1,
2918        format: OpFormat::AtomU16,
2919    },
2920    OpInfo {
2921        name: "scope_get_private_field2",
2922        size: 7,
2923        n_pop: 1,
2924        n_push: 2,
2925        format: OpFormat::AtomU16,
2926    },
2927    OpInfo {
2928        name: "scope_put_private_field",
2929        size: 7,
2930        n_pop: 2,
2931        n_push: 0,
2932        format: OpFormat::AtomU16,
2933    },
2934    OpInfo {
2935        name: "scope_in_private_field",
2936        size: 7,
2937        n_pop: 1,
2938        n_push: 1,
2939        format: OpFormat::AtomU16,
2940    },
2941    OpInfo {
2942        name: "get_field_opt_chain",
2943        size: 5,
2944        n_pop: 1,
2945        n_push: 1,
2946        format: OpFormat::Atom,
2947    },
2948    OpInfo {
2949        name: "get_array_el_opt_chain",
2950        size: 1,
2951        n_pop: 2,
2952        n_push: 1,
2953        format: OpFormat::None,
2954    },
2955    OpInfo {
2956        name: "set_class_name",
2957        size: 5,
2958        n_pop: 1,
2959        n_push: 1,
2960        format: OpFormat::U32,
2961    },
2962    OpInfo {
2963        name: "line_num",
2964        size: 5,
2965        n_pop: 0,
2966        n_push: 0,
2967        format: OpFormat::U32,
2968    },
2969];
2970
2971/// Decode table indexed by opcode byte.
2972const OP_BY_BYTE: [Option<Opcode>; 256] = [
2973    Some(Opcode::Invalid),
2974    Some(Opcode::PushI32),
2975    Some(Opcode::PushConst),
2976    Some(Opcode::Fclosure),
2977    Some(Opcode::PushAtomValue),
2978    Some(Opcode::PrivateSymbol),
2979    Some(Opcode::Undefined),
2980    Some(Opcode::Null),
2981    Some(Opcode::PushThis),
2982    Some(Opcode::PushFalse),
2983    Some(Opcode::PushTrue),
2984    Some(Opcode::Object),
2985    Some(Opcode::SpecialObject),
2986    Some(Opcode::Rest),
2987    Some(Opcode::Drop),
2988    Some(Opcode::Nip),
2989    Some(Opcode::Nip1),
2990    Some(Opcode::Dup),
2991    Some(Opcode::Dup1),
2992    Some(Opcode::Dup2),
2993    Some(Opcode::Dup3),
2994    Some(Opcode::Insert2),
2995    Some(Opcode::Insert3),
2996    Some(Opcode::Insert4),
2997    Some(Opcode::Perm3),
2998    Some(Opcode::Perm4),
2999    Some(Opcode::Perm5),
3000    Some(Opcode::Swap),
3001    Some(Opcode::Swap2),
3002    Some(Opcode::Rot3l),
3003    Some(Opcode::Rot3r),
3004    Some(Opcode::Rot4l),
3005    Some(Opcode::Rot5l),
3006    Some(Opcode::CallConstructor),
3007    Some(Opcode::Call),
3008    Some(Opcode::TailCall),
3009    Some(Opcode::CallMethod),
3010    Some(Opcode::TailCallMethod),
3011    Some(Opcode::ArrayFrom),
3012    Some(Opcode::Apply),
3013    Some(Opcode::Return),
3014    Some(Opcode::ReturnUndef),
3015    Some(Opcode::CheckCtorReturn),
3016    Some(Opcode::CheckCtor),
3017    Some(Opcode::InitCtor),
3018    Some(Opcode::CheckBrand),
3019    Some(Opcode::AddBrand),
3020    Some(Opcode::ReturnAsync),
3021    Some(Opcode::Throw),
3022    Some(Opcode::ThrowError),
3023    Some(Opcode::Eval),
3024    Some(Opcode::ApplyEval),
3025    Some(Opcode::Regexp),
3026    Some(Opcode::GetSuper),
3027    Some(Opcode::Import),
3028    Some(Opcode::GetVarUndef),
3029    Some(Opcode::GetVar),
3030    Some(Opcode::PutVar),
3031    Some(Opcode::PutVarInit),
3032    Some(Opcode::GetRefValue),
3033    Some(Opcode::PutRefValue),
3034    Some(Opcode::GetField),
3035    Some(Opcode::GetField2),
3036    Some(Opcode::PutField),
3037    Some(Opcode::GetPrivateField),
3038    Some(Opcode::PutPrivateField),
3039    Some(Opcode::DefinePrivateField),
3040    Some(Opcode::GetArrayEl),
3041    Some(Opcode::GetArrayEl2),
3042    Some(Opcode::GetArrayEl3),
3043    Some(Opcode::PutArrayEl),
3044    Some(Opcode::GetSuperValue),
3045    Some(Opcode::PutSuperValue),
3046    Some(Opcode::DefineField),
3047    Some(Opcode::SetName),
3048    Some(Opcode::SetNameComputed),
3049    Some(Opcode::SetProto),
3050    Some(Opcode::SetHomeObject),
3051    Some(Opcode::DefineArrayEl),
3052    Some(Opcode::Append),
3053    Some(Opcode::CopyDataProperties),
3054    Some(Opcode::DefineMethod),
3055    Some(Opcode::DefineMethodComputed),
3056    Some(Opcode::DefineClass),
3057    Some(Opcode::DefineClassComputed),
3058    Some(Opcode::GetLoc),
3059    Some(Opcode::PutLoc),
3060    Some(Opcode::SetLoc),
3061    Some(Opcode::GetArg),
3062    Some(Opcode::PutArg),
3063    Some(Opcode::SetArg),
3064    Some(Opcode::GetVarRef),
3065    Some(Opcode::PutVarRef),
3066    Some(Opcode::SetVarRef),
3067    Some(Opcode::SetLocUninitialized),
3068    Some(Opcode::GetLocCheck),
3069    Some(Opcode::PutLocCheck),
3070    Some(Opcode::SetLocCheck),
3071    Some(Opcode::PutLocCheckInit),
3072    Some(Opcode::GetLocCheckthis),
3073    Some(Opcode::GetVarRefCheck),
3074    Some(Opcode::PutVarRefCheck),
3075    Some(Opcode::PutVarRefCheckInit),
3076    Some(Opcode::CloseLoc),
3077    Some(Opcode::IfFalse),
3078    Some(Opcode::IfTrue),
3079    Some(Opcode::Goto),
3080    Some(Opcode::Catch),
3081    Some(Opcode::Gosub),
3082    Some(Opcode::Ret),
3083    Some(Opcode::NipCatch),
3084    Some(Opcode::ToObject),
3085    Some(Opcode::ToPropkey),
3086    Some(Opcode::WithGetVar),
3087    Some(Opcode::WithPutVar),
3088    Some(Opcode::WithDeleteVar),
3089    Some(Opcode::WithMakeRef),
3090    Some(Opcode::WithGetRef),
3091    Some(Opcode::MakeLocRef),
3092    Some(Opcode::MakeArgRef),
3093    Some(Opcode::MakeVarRefRef),
3094    Some(Opcode::MakeVarRef),
3095    Some(Opcode::ForInStart),
3096    Some(Opcode::ForOfStart),
3097    Some(Opcode::ForAwaitOfStart),
3098    Some(Opcode::ForInNext),
3099    Some(Opcode::ForOfNext),
3100    Some(Opcode::ForAwaitOfNext),
3101    Some(Opcode::IteratorCheckObject),
3102    Some(Opcode::IteratorGetValueDone),
3103    Some(Opcode::IteratorClose),
3104    Some(Opcode::IteratorNext),
3105    Some(Opcode::IteratorCall),
3106    Some(Opcode::InitialYield),
3107    Some(Opcode::Yield),
3108    Some(Opcode::YieldStar),
3109    Some(Opcode::AsyncYieldStar),
3110    Some(Opcode::Await),
3111    Some(Opcode::Neg),
3112    Some(Opcode::Plus),
3113    Some(Opcode::Dec),
3114    Some(Opcode::Inc),
3115    Some(Opcode::PostDec),
3116    Some(Opcode::PostInc),
3117    Some(Opcode::DecLoc),
3118    Some(Opcode::IncLoc),
3119    Some(Opcode::AddLoc),
3120    Some(Opcode::Not),
3121    Some(Opcode::Lnot),
3122    Some(Opcode::Typeof),
3123    Some(Opcode::Delete),
3124    Some(Opcode::DeleteVar),
3125    Some(Opcode::Mul),
3126    Some(Opcode::Div),
3127    Some(Opcode::Mod),
3128    Some(Opcode::Add),
3129    Some(Opcode::Sub),
3130    Some(Opcode::Pow),
3131    Some(Opcode::Shl),
3132    Some(Opcode::Sar),
3133    Some(Opcode::Shr),
3134    Some(Opcode::Lt),
3135    Some(Opcode::Lte),
3136    Some(Opcode::Gt),
3137    Some(Opcode::Gte),
3138    Some(Opcode::Instanceof),
3139    Some(Opcode::In),
3140    Some(Opcode::Eq),
3141    Some(Opcode::Neq),
3142    Some(Opcode::StrictEq),
3143    Some(Opcode::StrictNeq),
3144    Some(Opcode::And),
3145    Some(Opcode::Xor),
3146    Some(Opcode::Or),
3147    Some(Opcode::IsUndefinedOrNull),
3148    Some(Opcode::PrivateIn),
3149    Some(Opcode::PushBigintI32),
3150    Some(Opcode::UsingDisposeInit),
3151    Some(Opcode::UsingDispose),
3152    Some(Opcode::UsingDisposeAsync),
3153    Some(Opcode::UsingDisposeMerge),
3154    Some(Opcode::UsingDisposeEnd),
3155    Some(Opcode::UsingCheck),
3156    Some(Opcode::Nop),
3157    Some(Opcode::PushMinus1),
3158    Some(Opcode::Push0),
3159    Some(Opcode::Push1),
3160    Some(Opcode::Push2),
3161    Some(Opcode::Push3),
3162    Some(Opcode::Push4),
3163    Some(Opcode::Push5),
3164    Some(Opcode::Push6),
3165    Some(Opcode::Push7),
3166    Some(Opcode::PushI8),
3167    Some(Opcode::PushI16),
3168    Some(Opcode::PushConst8),
3169    Some(Opcode::Fclosure8),
3170    Some(Opcode::PushEmptyString),
3171    Some(Opcode::GetLoc8),
3172    Some(Opcode::PutLoc8),
3173    Some(Opcode::SetLoc8),
3174    Some(Opcode::GetLoc0),
3175    Some(Opcode::GetLoc1),
3176    Some(Opcode::GetLoc2),
3177    Some(Opcode::GetLoc3),
3178    Some(Opcode::PutLoc0),
3179    Some(Opcode::PutLoc1),
3180    Some(Opcode::PutLoc2),
3181    Some(Opcode::PutLoc3),
3182    Some(Opcode::SetLoc0),
3183    Some(Opcode::SetLoc1),
3184    Some(Opcode::SetLoc2),
3185    Some(Opcode::SetLoc3),
3186    Some(Opcode::GetArg0),
3187    Some(Opcode::GetArg1),
3188    Some(Opcode::GetArg2),
3189    Some(Opcode::GetArg3),
3190    Some(Opcode::PutArg0),
3191    Some(Opcode::PutArg1),
3192    Some(Opcode::PutArg2),
3193    Some(Opcode::PutArg3),
3194    Some(Opcode::SetArg0),
3195    Some(Opcode::SetArg1),
3196    Some(Opcode::SetArg2),
3197    Some(Opcode::SetArg3),
3198    Some(Opcode::GetVarRef0),
3199    Some(Opcode::GetVarRef1),
3200    Some(Opcode::GetVarRef2),
3201    Some(Opcode::GetVarRef3),
3202    Some(Opcode::PutVarRef0),
3203    Some(Opcode::PutVarRef1),
3204    Some(Opcode::PutVarRef2),
3205    Some(Opcode::PutVarRef3),
3206    Some(Opcode::SetVarRef0),
3207    Some(Opcode::SetVarRef1),
3208    Some(Opcode::SetVarRef2),
3209    Some(Opcode::SetVarRef3),
3210    Some(Opcode::GetLength),
3211    Some(Opcode::IfFalse8),
3212    Some(Opcode::IfTrue8),
3213    Some(Opcode::Goto8),
3214    Some(Opcode::Goto16),
3215    Some(Opcode::Call0),
3216    Some(Opcode::Call1),
3217    Some(Opcode::Call2),
3218    Some(Opcode::Call3),
3219    Some(Opcode::IsUndefined),
3220    Some(Opcode::IsNull),
3221    Some(Opcode::TypeofIsUndefined),
3222    Some(Opcode::TypeofIsFunction),
3223    None,
3224    None,
3225    None,
3226    None,
3227    None,
3228    None,
3229];
3230
3231#[cfg(test)]
3232mod tests {
3233    use super::*;
3234
3235    #[test]
3236    fn every_discriminant_matches_its_index() {
3237        for (index, opcode) in OP_ALL.iter().enumerate() {
3238            assert_eq!(
3239                *opcode as usize, index,
3240                "OP_ALL must be ordered by discriminant"
3241            );
3242            assert!(!opcode.name().is_empty());
3243            assert!(opcode.size() >= 1, "{} has a zero size", opcode.name());
3244        }
3245        assert_eq!(OP_ALL.len(), OP_COUNT as usize);
3246        assert_eq!(OP_INFO.len(), OP_ALL.len());
3247        assert_eq!(TEMP_INFO.len(), 20 - TEMP_START);
3248    }
3249
3250    #[test]
3251    fn opcode_bytes_round_trip() {
3252        for opcode in OP_ALL {
3253            assert_eq!(
3254                Opcode::from_u8(opcode as u8),
3255                Some(opcode),
3256                "{}",
3257                opcode.name()
3258            );
3259        }
3260        assert_eq!(Opcode::from_u8(OP_COUNT), None);
3261        assert_eq!(Opcode::from_u8(255), None);
3262    }
3263
3264    #[test]
3265    fn names_round_trip() {
3266        for opcode in OP_ALL {
3267            assert_eq!(
3268                Opcode::by_name(opcode.name()),
3269                Some(opcode),
3270                "{}",
3271                opcode.name()
3272            );
3273        }
3274    }
3275
3276    #[test]
3277    fn temporary_opcodes_overlap_real_opcodes() {
3278        // The reference implementation reuses these numbers for the short-form
3279        // opcodes, so a temporary opcode can never survive into finished
3280        // bytecode: its byte decodes as some other, real instruction.
3281        assert_eq!(TempOpcode::EnterScope as u8, Opcode::PushI32 as u8);
3282        assert_eq!(TempOpcode::LineNum as u8, 19);
3283        assert!(Opcode::from_u8(TempOpcode::EnterScope as u8).is_some());
3284        assert!(Opcode::from_u8(TempOpcode::LineNum as u8).is_some());
3285    }
3286}