1425bb815Sopenharmony_ci/* Copyright JS Foundation and other contributors, http://js.foundation
2425bb815Sopenharmony_ci *
3425bb815Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4425bb815Sopenharmony_ci * you may not use this file except in compliance with the License.
5425bb815Sopenharmony_ci * You may obtain a copy of the License at
6425bb815Sopenharmony_ci *
7425bb815Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8425bb815Sopenharmony_ci *
9425bb815Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10425bb815Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS
11425bb815Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12425bb815Sopenharmony_ci * See the License for the specific language governing permissions and
13425bb815Sopenharmony_ci * limitations under the License.
14425bb815Sopenharmony_ci */
15425bb815Sopenharmony_ci
16425bb815Sopenharmony_ci#ifndef BYTE_CODE_H
17425bb815Sopenharmony_ci#define BYTE_CODE_H
18425bb815Sopenharmony_ci
19425bb815Sopenharmony_ci#include "ecma-globals.h"
20425bb815Sopenharmony_ci
21425bb815Sopenharmony_ci/** \addtogroup parser Parser
22425bb815Sopenharmony_ci * @{
23425bb815Sopenharmony_ci *
24425bb815Sopenharmony_ci * \addtogroup jsparser JavaScript
25425bb815Sopenharmony_ci * @{
26425bb815Sopenharmony_ci *
27425bb815Sopenharmony_ci * \addtogroup jsparser_bytecode Bytecode
28425bb815Sopenharmony_ci * @{
29425bb815Sopenharmony_ci */
30425bb815Sopenharmony_ci
31425bb815Sopenharmony_ci/**
32425bb815Sopenharmony_ci * Compact byte code (CBC) is a byte code representation
33425bb815Sopenharmony_ci * of EcmaScript which is designed for low memory
34425bb815Sopenharmony_ci * environments. Most opcodes are only one or sometimes
35425bb815Sopenharmony_ci * two byte long so the CBC provides a small binary size.
36425bb815Sopenharmony_ci *
37425bb815Sopenharmony_ci * The execution engine of CBC is a stack machine, where
38425bb815Sopenharmony_ci * the maximum stack size is known in advance for each
39425bb815Sopenharmony_ci * function.
40425bb815Sopenharmony_ci */
41425bb815Sopenharmony_ci
42425bb815Sopenharmony_ci/**
43425bb815Sopenharmony_ci * Byte code flags. Only the lower 5 bit can be used
44425bb815Sopenharmony_ci * since the stack change is encoded in the upper
45425bb815Sopenharmony_ci * three bits for each instruction between -4 and 3
46425bb815Sopenharmony_ci * (except for call / construct opcodes).
47425bb815Sopenharmony_ci */
48425bb815Sopenharmony_ci#define CBC_STACK_ADJUST_BASE          4
49425bb815Sopenharmony_ci#define CBC_STACK_ADJUST_SHIFT         5
50425bb815Sopenharmony_ci#define CBC_STACK_ADJUST_VALUE(value)  \
51425bb815Sopenharmony_ci  (((value) >> CBC_STACK_ADJUST_SHIFT) - CBC_STACK_ADJUST_BASE)
52425bb815Sopenharmony_ci
53425bb815Sopenharmony_ci#define CBC_NO_FLAG                    0x00u
54425bb815Sopenharmony_ci#define CBC_HAS_LITERAL_ARG            0x01u
55425bb815Sopenharmony_ci#define CBC_HAS_LITERAL_ARG2           0x02u
56425bb815Sopenharmony_ci#define CBC_HAS_BYTE_ARG               0x04u
57425bb815Sopenharmony_ci#define CBC_HAS_BRANCH_ARG             0x08u
58425bb815Sopenharmony_ci
59425bb815Sopenharmony_ci/* These flags are shared */
60425bb815Sopenharmony_ci#define CBC_FORWARD_BRANCH_ARG         0x10u
61425bb815Sopenharmony_ci#define CBC_POP_STACK_BYTE_ARG         0x10u
62425bb815Sopenharmony_ci
63425bb815Sopenharmony_ci#define CBC_ARG_TYPES (CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2 | CBC_HAS_BYTE_ARG | CBC_HAS_BRANCH_ARG)
64425bb815Sopenharmony_ci
65425bb815Sopenharmony_ci#define CBC_HAS_POP_STACK_BYTE_ARG (CBC_HAS_BYTE_ARG | CBC_POP_STACK_BYTE_ARG)
66425bb815Sopenharmony_ci
67425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015)
68425bb815Sopenharmony_ci/**
69425bb815Sopenharmony_ci * CBC_NO_RESULT_OPERATION for ext opcodes
70425bb815Sopenharmony_ci */
71425bb815Sopenharmony_ci#define CBC_EXT_NO_RESULT_OPERATION(opcode) \
72425bb815Sopenharmony_ci  ((opcode) >= PARSER_TO_EXT_OPCODE (CBC_EXT_SUPER_CALL) \
73425bb815Sopenharmony_ci    && (opcode) <= PARSER_TO_EXT_OPCODE (CBC_EXT_SPREAD_CALL_PROP_BLOCK))
74425bb815Sopenharmony_ci#else /* !ENABLED (JERRY_ES2015) */
75425bb815Sopenharmony_ci/**
76425bb815Sopenharmony_ci * CBC_NO_RESULT_OPERATION for ext opcodes
77425bb815Sopenharmony_ci */
78425bb815Sopenharmony_ci#define CBC_EXT_NO_RESULT_OPERATION(opcode) false
79425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */
80425bb815Sopenharmony_ci
81425bb815Sopenharmony_ci/* Debug macro. */
82425bb815Sopenharmony_ci#define CBC_ARGS_EQ(op, types) \
83425bb815Sopenharmony_ci  ((cbc_flags[op] & CBC_ARG_TYPES) == (types))
84425bb815Sopenharmony_ci
85425bb815Sopenharmony_ci/* Debug macro. */
86425bb815Sopenharmony_ci#define CBC_SAME_ARGS(op1, op2) \
87425bb815Sopenharmony_ci  (CBC_EXT_NO_RESULT_OPERATION (op1) ? ((cbc_ext_flags[PARSER_GET_EXT_OPCODE (op1)] & CBC_ARG_TYPES) \
88425bb815Sopenharmony_ci                                         == (cbc_ext_flags[PARSER_GET_EXT_OPCODE (op2)] & CBC_ARG_TYPES)) \
89425bb815Sopenharmony_ci                                     : ((cbc_flags[op1] & CBC_ARG_TYPES) == (cbc_flags[op2] & CBC_ARG_TYPES)))
90425bb815Sopenharmony_ci
91425bb815Sopenharmony_ci#define CBC_UNARY_OPERATION(name, group) \
92425bb815Sopenharmony_ci  CBC_OPCODE (name, CBC_NO_FLAG, 0, \
93425bb815Sopenharmony_ci              (VM_OC_ ## group) | VM_OC_GET_STACK | VM_OC_PUT_STACK) \
94425bb815Sopenharmony_ci  CBC_OPCODE (name ## _LITERAL, CBC_HAS_LITERAL_ARG, 1, \
95425bb815Sopenharmony_ci              (VM_OC_ ## group) | VM_OC_GET_LITERAL | VM_OC_PUT_STACK)
96425bb815Sopenharmony_ci
97425bb815Sopenharmony_ci#define CBC_BINARY_OPERATION(name, group) \
98425bb815Sopenharmony_ci  CBC_OPCODE (name, CBC_NO_FLAG, -1, \
99425bb815Sopenharmony_ci              (VM_OC_ ## group) | VM_OC_GET_STACK_STACK | VM_OC_PUT_STACK) \
100425bb815Sopenharmony_ci  CBC_OPCODE (name ## _RIGHT_LITERAL, CBC_HAS_LITERAL_ARG, 0, \
101425bb815Sopenharmony_ci              (VM_OC_ ## group) | VM_OC_GET_STACK_LITERAL | VM_OC_PUT_STACK) \
102425bb815Sopenharmony_ci  CBC_OPCODE (name ## _TWO_LITERALS, CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, 1, \
103425bb815Sopenharmony_ci              (VM_OC_ ## group) | VM_OC_GET_LITERAL_LITERAL | VM_OC_PUT_STACK)
104425bb815Sopenharmony_ci
105425bb815Sopenharmony_ci#define CBC_UNARY_LVALUE_OPERATION(name, group) \
106425bb815Sopenharmony_ci  CBC_OPCODE (name, CBC_NO_FLAG, -2, \
107425bb815Sopenharmony_ci              (VM_OC_PROP_ ## group) | VM_OC_GET_STACK_STACK | VM_OC_PUT_REFERENCE) \
108425bb815Sopenharmony_ci  CBC_OPCODE (name ## _PUSH_RESULT, CBC_NO_FLAG, -1, \
109425bb815Sopenharmony_ci              (VM_OC_PROP_ ## group) | VM_OC_GET_STACK_STACK | VM_OC_PUT_REFERENCE | VM_OC_PUT_STACK) \
110425bb815Sopenharmony_ci  CBC_OPCODE (name ## _BLOCK, CBC_NO_FLAG, -2, \
111425bb815Sopenharmony_ci              (VM_OC_PROP_ ## group) | VM_OC_GET_STACK_STACK | VM_OC_PUT_REFERENCE | VM_OC_PUT_BLOCK) \
112425bb815Sopenharmony_ci  CBC_OPCODE (name ## _IDENT, CBC_HAS_LITERAL_ARG, 0, \
113425bb815Sopenharmony_ci              (VM_OC_ ## group) | VM_OC_GET_LITERAL | VM_OC_PUT_IDENT) \
114425bb815Sopenharmony_ci  CBC_OPCODE (name ## _IDENT_PUSH_RESULT, CBC_HAS_LITERAL_ARG, 1, \
115425bb815Sopenharmony_ci              (VM_OC_ ## group) | VM_OC_GET_LITERAL | VM_OC_PUT_IDENT | VM_OC_PUT_STACK) \
116425bb815Sopenharmony_ci  CBC_OPCODE (name ## _IDENT_BLOCK, CBC_HAS_LITERAL_ARG, 0, \
117425bb815Sopenharmony_ci              (VM_OC_ ## group) | VM_OC_GET_LITERAL | VM_OC_PUT_IDENT | VM_OC_PUT_BLOCK)
118425bb815Sopenharmony_ci
119425bb815Sopenharmony_ci#define CBC_UNARY_LVALUE_WITH_IDENT 3
120425bb815Sopenharmony_ci
121425bb815Sopenharmony_ci#define CBC_BINARY_WITH_LITERAL 1
122425bb815Sopenharmony_ci#define CBC_BINARY_WITH_TWO_LITERALS 2
123425bb815Sopenharmony_ci
124425bb815Sopenharmony_ci/**
125425bb815Sopenharmony_ci * Several opcodes (mostly call and assignment opcodes) have
126425bb815Sopenharmony_ci * two forms: one which does not push a return value onto
127425bb815Sopenharmony_ci * the stack, and another which does. The reason is that
128425bb815Sopenharmony_ci * the return value of these opcodes are often not used
129425bb815Sopenharmony_ci * and the first form provides smaller byte code.
130425bb815Sopenharmony_ci *
131425bb815Sopenharmony_ci * The following rules must be kept by the code generator:
132425bb815Sopenharmony_ci *  - only the opcode without return value can be emitted
133425bb815Sopenharmony_ci *    by the code generator
134425bb815Sopenharmony_ci *  - the first form can be converted to the second form
135425bb815Sopenharmony_ci *    by adding 1 to the opcode
136425bb815Sopenharmony_ci *  - after the conversion the opcode must be immediately
137425bb815Sopenharmony_ci *    flushed, so no further changes are possible
138425bb815Sopenharmony_ci *
139425bb815Sopenharmony_ci * Hence CBC_NO_RESULT_OPERATION (context_p->last_cbc_opcode)
140425bb815Sopenharmony_ci * cannot be true for an opcode which has a result
141425bb815Sopenharmony_ci */
142425bb815Sopenharmony_ci#define CBC_NO_RESULT_OPERATION(opcode) \
143425bb815Sopenharmony_ci  (((opcode) >= CBC_PRE_INCR && (opcode) < CBC_END) || CBC_EXT_NO_RESULT_OPERATION ((opcode)))
144425bb815Sopenharmony_ci
145425bb815Sopenharmony_ci/**
146425bb815Sopenharmony_ci * Branch instructions are organized in group of 8 opcodes.
147425bb815Sopenharmony_ci *  - 1st opcode: unused, can be used for other purpose
148425bb815Sopenharmony_ci *  - 2nd opcode: forward branch with 1 byte offset
149425bb815Sopenharmony_ci *  - 3rd opcode: forward branch with 2 byte offset
150425bb815Sopenharmony_ci *  - 4th opcode: forward branch with 3 byte offset
151425bb815Sopenharmony_ci *  - 5th opcode: unused, can be used for other purpose
152425bb815Sopenharmony_ci *  - 6th opcode: backward branch with 1 byte offset
153425bb815Sopenharmony_ci *  - 7th opcode: backward branch with 2 byte offset
154425bb815Sopenharmony_ci *  - 8th opcode: backward branch with 3 byte offset
155425bb815Sopenharmony_ci *
156425bb815Sopenharmony_ci * Reasons:
157425bb815Sopenharmony_ci *  The branch_opcode & 0x3 tells the length in bytes of the offset
158425bb815Sopenharmony_ci *  If branch offset & 0x4 == 0, it is a forward branch. Otherwise
159425bb815Sopenharmony_ci *  it is backward.
160425bb815Sopenharmony_ci *
161425bb815Sopenharmony_ci * The offset bytes are encoded in higher to lower order.
162425bb815Sopenharmony_ci */
163425bb815Sopenharmony_ci
164425bb815Sopenharmony_ci#define CBC_FORWARD_BRANCH(name, stack, vm_oc) \
165425bb815Sopenharmony_ci  CBC_OPCODE (name, CBC_HAS_BRANCH_ARG | CBC_FORWARD_BRANCH_ARG, stack, \
166425bb815Sopenharmony_ci              (vm_oc) | VM_OC_GET_BRANCH) \
167425bb815Sopenharmony_ci  CBC_OPCODE (name ## _2, CBC_HAS_BRANCH_ARG | CBC_FORWARD_BRANCH_ARG, stack, \
168425bb815Sopenharmony_ci              (vm_oc) | VM_OC_GET_BRANCH) \
169425bb815Sopenharmony_ci  CBC_OPCODE (name ## _3, CBC_HAS_BRANCH_ARG | CBC_FORWARD_BRANCH_ARG, stack, \
170425bb815Sopenharmony_ci              (vm_oc) | VM_OC_GET_BRANCH)
171425bb815Sopenharmony_ci
172425bb815Sopenharmony_ci#define CBC_BACKWARD_BRANCH(name, stack, vm_oc) \
173425bb815Sopenharmony_ci  CBC_OPCODE (name, CBC_HAS_BRANCH_ARG, stack, \
174425bb815Sopenharmony_ci              (vm_oc) | VM_OC_GET_BRANCH | VM_OC_BACKWARD_BRANCH) \
175425bb815Sopenharmony_ci  CBC_OPCODE (name ## _2, CBC_HAS_BRANCH_ARG, stack, \
176425bb815Sopenharmony_ci              (vm_oc) | VM_OC_GET_BRANCH | VM_OC_BACKWARD_BRANCH) \
177425bb815Sopenharmony_ci  CBC_OPCODE (name ## _3, CBC_HAS_BRANCH_ARG, stack, \
178425bb815Sopenharmony_ci              (vm_oc) | VM_OC_GET_BRANCH | VM_OC_BACKWARD_BRANCH)
179425bb815Sopenharmony_ci
180425bb815Sopenharmony_ci#define CBC_BRANCH_OFFSET_LENGTH(opcode) \
181425bb815Sopenharmony_ci  ((opcode) & 0x3)
182425bb815Sopenharmony_ci
183425bb815Sopenharmony_ci#define CBC_BRANCH_IS_BACKWARD(flags) \
184425bb815Sopenharmony_ci  (!((flags) & CBC_FORWARD_BRANCH_ARG))
185425bb815Sopenharmony_ci
186425bb815Sopenharmony_ci#define CBC_BRANCH_IS_FORWARD(flags) \
187425bb815Sopenharmony_ci  ((flags) & CBC_FORWARD_BRANCH_ARG)
188425bb815Sopenharmony_ci
189425bb815Sopenharmony_ci/* Stack consumption of opcodes with context. */
190425bb815Sopenharmony_ci
191425bb815Sopenharmony_ci/* PARSER_TRY_CONTEXT_STACK_ALLOCATION must be <= 3 */
192425bb815Sopenharmony_ci#define PARSER_TRY_CONTEXT_STACK_ALLOCATION 2
193425bb815Sopenharmony_ci/* PARSER_FOR_IN_CONTEXT_STACK_ALLOCATION must be <= 4 */
194425bb815Sopenharmony_ci#define PARSER_FOR_IN_CONTEXT_STACK_ALLOCATION 4
195425bb815Sopenharmony_ci/* PARSER_FOR_OF_CONTEXT_STACK_ALLOCATION must be <= 3 */
196425bb815Sopenharmony_ci#define PARSER_FOR_OF_CONTEXT_STACK_ALLOCATION 3
197425bb815Sopenharmony_ci/* PARSER_WITH_CONTEXT_STACK_ALLOCATION must be <= 4 */
198425bb815Sopenharmony_ci#define PARSER_WITH_CONTEXT_STACK_ALLOCATION 1
199425bb815Sopenharmony_ci/* PARSER_BLOCK_CONTEXT_STACK_ALLOCATION must be <= 3 */
200425bb815Sopenharmony_ci#define PARSER_BLOCK_CONTEXT_STACK_ALLOCATION 1
201425bb815Sopenharmony_ci
202425bb815Sopenharmony_ci/**
203425bb815Sopenharmony_ci * Opcode definitions.
204425bb815Sopenharmony_ci */
205425bb815Sopenharmony_ci#define CBC_OPCODE_LIST \
206425bb815Sopenharmony_ci  /* Branch opcodes first. Some other opcodes are mixed. */ \
207425bb815Sopenharmony_ci  CBC_OPCODE (CBC_EXT_OPCODE, CBC_NO_FLAG, 0, \
208425bb815Sopenharmony_ci              VM_OC_NONE) \
209425bb815Sopenharmony_ci  CBC_FORWARD_BRANCH (CBC_JUMP_FORWARD, 0, \
210425bb815Sopenharmony_ci                      VM_OC_JUMP) \
211425bb815Sopenharmony_ci  CBC_OPCODE (CBC_POP, CBC_NO_FLAG, -1, \
212425bb815Sopenharmony_ci              VM_OC_POP) \
213425bb815Sopenharmony_ci  CBC_BACKWARD_BRANCH (CBC_JUMP_BACKWARD, 0, \
214425bb815Sopenharmony_ci                       VM_OC_JUMP) \
215425bb815Sopenharmony_ci  CBC_OPCODE (CBC_POP_BLOCK, CBC_NO_FLAG, -1, \
216425bb815Sopenharmony_ci              VM_OC_POP_BLOCK | VM_OC_PUT_BLOCK) \
217425bb815Sopenharmony_ci  CBC_FORWARD_BRANCH (CBC_BRANCH_IF_TRUE_FORWARD, -1, \
218425bb815Sopenharmony_ci                      VM_OC_BRANCH_IF_TRUE) \
219425bb815Sopenharmony_ci  CBC_OPCODE (CBC_THROW, CBC_NO_FLAG, -1, \
220425bb815Sopenharmony_ci              VM_OC_THROW | VM_OC_GET_STACK) \
221425bb815Sopenharmony_ci  CBC_BACKWARD_BRANCH (CBC_BRANCH_IF_TRUE_BACKWARD, -1, \
222425bb815Sopenharmony_ci                       VM_OC_BRANCH_IF_TRUE) \
223425bb815Sopenharmony_ci  CBC_OPCODE (CBC_CONTEXT_END, CBC_NO_FLAG, 0, \
224425bb815Sopenharmony_ci              VM_OC_CONTEXT_END) \
225425bb815Sopenharmony_ci  CBC_FORWARD_BRANCH (CBC_BRANCH_IF_FALSE_FORWARD, -1, \
226425bb815Sopenharmony_ci                      VM_OC_BRANCH_IF_FALSE) \
227425bb815Sopenharmony_ci  CBC_OPCODE (CBC_CREATE_OBJECT, CBC_NO_FLAG, 1, \
228425bb815Sopenharmony_ci              VM_OC_PUSH_OBJECT | VM_OC_PUT_STACK) \
229425bb815Sopenharmony_ci  CBC_BACKWARD_BRANCH (CBC_BRANCH_IF_FALSE_BACKWARD, -1, \
230425bb815Sopenharmony_ci                       VM_OC_BRANCH_IF_FALSE) \
231425bb815Sopenharmony_ci  CBC_OPCODE (CBC_SET_PROPERTY, CBC_HAS_LITERAL_ARG, -1, \
232425bb815Sopenharmony_ci              VM_OC_SET_PROPERTY | VM_OC_NON_STATIC_FLAG | VM_OC_GET_STACK_LITERAL) \
233425bb815Sopenharmony_ci  CBC_FORWARD_BRANCH (CBC_JUMP_FORWARD_EXIT_CONTEXT, 0, \
234425bb815Sopenharmony_ci                      VM_OC_JUMP_AND_EXIT_CONTEXT) \
235425bb815Sopenharmony_ci  CBC_OPCODE (CBC_CREATE_ARRAY, CBC_NO_FLAG, 1, \
236425bb815Sopenharmony_ci              VM_OC_PUSH_ARRAY | VM_OC_PUT_STACK) \
237425bb815Sopenharmony_ci  CBC_FORWARD_BRANCH (CBC_BRANCH_IF_LOGICAL_TRUE, -1, \
238425bb815Sopenharmony_ci                      VM_OC_BRANCH_IF_LOGICAL_TRUE) \
239425bb815Sopenharmony_ci  CBC_OPCODE (CBC_ARRAY_APPEND, CBC_HAS_POP_STACK_BYTE_ARG, 0, \
240425bb815Sopenharmony_ci              VM_OC_APPEND_ARRAY) \
241425bb815Sopenharmony_ci  CBC_FORWARD_BRANCH (CBC_BRANCH_IF_LOGICAL_FALSE, -1, \
242425bb815Sopenharmony_ci                      VM_OC_BRANCH_IF_LOGICAL_FALSE) \
243425bb815Sopenharmony_ci  CBC_OPCODE (CBC_PUSH_ELISION, CBC_NO_FLAG, 1, \
244425bb815Sopenharmony_ci              VM_OC_PUSH_ELISON | VM_OC_PUT_STACK) \
245425bb815Sopenharmony_ci  CBC_FORWARD_BRANCH (CBC_BRANCH_IF_STRICT_EQUAL, -1, \
246425bb815Sopenharmony_ci                      VM_OC_BRANCH_IF_STRICT_EQUAL) \
247425bb815Sopenharmony_ci  CBC_OPCODE (CBC_PUSH_NULL, CBC_NO_FLAG, 1, \
248425bb815Sopenharmony_ci              VM_OC_PUSH_NULL | VM_OC_PUT_STACK) \
249425bb815Sopenharmony_ci  CBC_FORWARD_BRANCH (CBC_BLOCK_CREATE_CONTEXT, \
250425bb815Sopenharmony_ci                      PARSER_BLOCK_CONTEXT_STACK_ALLOCATION, VM_OC_BLOCK_CREATE_CONTEXT) \
251425bb815Sopenharmony_ci  \
252425bb815Sopenharmony_ci  /* Basic opcodes. Note: These 4 opcodes must me in this order */ \
253425bb815Sopenharmony_ci  CBC_OPCODE (CBC_PUSH_LITERAL, CBC_HAS_LITERAL_ARG, 1, \
254425bb815Sopenharmony_ci              VM_OC_PUSH | VM_OC_GET_LITERAL) \
255425bb815Sopenharmony_ci  CBC_OPCODE (CBC_PUSH_TWO_LITERALS, CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, 2, \
256425bb815Sopenharmony_ci              VM_OC_PUSH_TWO | VM_OC_GET_LITERAL_LITERAL) \
257425bb815Sopenharmony_ci  CBC_OPCODE (CBC_PUSH_THIS_LITERAL, CBC_HAS_LITERAL_ARG, 2, \
258425bb815Sopenharmony_ci              VM_OC_PUSH_TWO | VM_OC_GET_THIS_LITERAL) \
259425bb815Sopenharmony_ci  CBC_OPCODE (CBC_PUSH_THREE_LITERALS, CBC_HAS_LITERAL_ARG2, 3, \
260425bb815Sopenharmony_ci              VM_OC_PUSH_THREE | VM_OC_GET_LITERAL_LITERAL) \
261425bb815Sopenharmony_ci  CBC_OPCODE (CBC_PUSH_UNDEFINED, CBC_NO_FLAG, 1, \
262425bb815Sopenharmony_ci              VM_OC_PUSH_UNDEFINED | VM_OC_PUT_STACK) \
263425bb815Sopenharmony_ci  CBC_OPCODE (CBC_PUSH_TRUE, CBC_NO_FLAG, 1, \
264425bb815Sopenharmony_ci              VM_OC_PUSH_TRUE | VM_OC_PUT_STACK) \
265425bb815Sopenharmony_ci  CBC_OPCODE (CBC_PUSH_FALSE, CBC_NO_FLAG, 1, \
266425bb815Sopenharmony_ci              VM_OC_PUSH_FALSE | VM_OC_PUT_STACK) \
267425bb815Sopenharmony_ci  CBC_OPCODE (CBC_PUSH_THIS, CBC_NO_FLAG, 1, \
268425bb815Sopenharmony_ci              VM_OC_PUSH_THIS | VM_OC_PUT_STACK) \
269425bb815Sopenharmony_ci  CBC_OPCODE (CBC_PUSH_NUMBER_0, CBC_NO_FLAG, 1, \
270425bb815Sopenharmony_ci              VM_OC_PUSH_0 | VM_OC_PUT_STACK) \
271425bb815Sopenharmony_ci  CBC_OPCODE (CBC_PUSH_NUMBER_POS_BYTE, CBC_HAS_BYTE_ARG, 1, \
272425bb815Sopenharmony_ci              VM_OC_PUSH_POS_BYTE | VM_OC_PUT_STACK) \
273425bb815Sopenharmony_ci  CBC_OPCODE (CBC_PUSH_NUMBER_NEG_BYTE, CBC_HAS_BYTE_ARG, 1, \
274425bb815Sopenharmony_ci              VM_OC_PUSH_NEG_BYTE | VM_OC_PUT_STACK) \
275425bb815Sopenharmony_ci  /* Note: These 4 opcodes must me in this order */ \
276425bb815Sopenharmony_ci  CBC_OPCODE (CBC_PUSH_PROP, CBC_NO_FLAG, -1, \
277425bb815Sopenharmony_ci              VM_OC_PROP_GET | VM_OC_GET_STACK_STACK | VM_OC_PUT_STACK) \
278425bb815Sopenharmony_ci  CBC_OPCODE (CBC_PUSH_PROP_LITERAL, CBC_HAS_LITERAL_ARG, 0, \
279425bb815Sopenharmony_ci              VM_OC_PROP_GET | VM_OC_GET_STACK_LITERAL | VM_OC_PUT_STACK) \
280425bb815Sopenharmony_ci  CBC_OPCODE (CBC_PUSH_PROP_LITERAL_LITERAL, CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, 1, \
281425bb815Sopenharmony_ci              VM_OC_PROP_GET | VM_OC_GET_LITERAL_LITERAL | VM_OC_PUT_STACK) \
282425bb815Sopenharmony_ci  CBC_OPCODE (CBC_PUSH_PROP_THIS_LITERAL, CBC_HAS_LITERAL_ARG, 1, \
283425bb815Sopenharmony_ci              VM_OC_PROP_GET | VM_OC_GET_THIS_LITERAL | VM_OC_PUT_STACK) \
284425bb815Sopenharmony_ci  CBC_OPCODE (CBC_PUSH_IDENT_REFERENCE, CBC_HAS_LITERAL_ARG, 3, \
285425bb815Sopenharmony_ci              VM_OC_IDENT_REFERENCE | VM_OC_PUT_STACK) \
286425bb815Sopenharmony_ci  /* Note: These 4 opcodes must me in this order */ \
287425bb815Sopenharmony_ci  CBC_OPCODE (CBC_PUSH_PROP_REFERENCE, CBC_NO_FLAG, 1, \
288425bb815Sopenharmony_ci              VM_OC_PROP_REFERENCE | VM_OC_PUT_STACK) \
289425bb815Sopenharmony_ci  CBC_OPCODE (CBC_PUSH_PROP_LITERAL_REFERENCE, CBC_HAS_LITERAL_ARG, 2, \
290425bb815Sopenharmony_ci              VM_OC_PROP_REFERENCE | VM_OC_GET_LITERAL | VM_OC_PUT_STACK) \
291425bb815Sopenharmony_ci  CBC_OPCODE (CBC_PUSH_PROP_LITERAL_LITERAL_REFERENCE, CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, 3, \
292425bb815Sopenharmony_ci              VM_OC_PROP_REFERENCE | VM_OC_GET_LITERAL_LITERAL | VM_OC_PUT_STACK) \
293425bb815Sopenharmony_ci  CBC_OPCODE (CBC_PUSH_PROP_THIS_LITERAL_REFERENCE, CBC_HAS_LITERAL_ARG, 3, \
294425bb815Sopenharmony_ci              VM_OC_PROP_REFERENCE | VM_OC_GET_THIS_LITERAL | VM_OC_PUT_STACK) \
295425bb815Sopenharmony_ci  CBC_OPCODE (CBC_NEW, CBC_HAS_POP_STACK_BYTE_ARG, 0, \
296425bb815Sopenharmony_ci              VM_OC_NEW | VM_OC_PUT_STACK) \
297425bb815Sopenharmony_ci  CBC_OPCODE (CBC_NEW0, CBC_NO_FLAG, 0, \
298425bb815Sopenharmony_ci              VM_OC_NEW | VM_OC_PUT_STACK) \
299425bb815Sopenharmony_ci  CBC_OPCODE (CBC_NEW1, CBC_NO_FLAG, -1, \
300425bb815Sopenharmony_ci              VM_OC_NEW | VM_OC_PUT_STACK) \
301425bb815Sopenharmony_ci  CBC_OPCODE (CBC_EVAL, CBC_NO_FLAG, 0, \
302425bb815Sopenharmony_ci              VM_OC_EVAL) \
303425bb815Sopenharmony_ci  CBC_OPCODE (CBC_CHECK_VAR, CBC_HAS_LITERAL_ARG, 0, \
304425bb815Sopenharmony_ci              VM_OC_CHECK_VAR) \
305425bb815Sopenharmony_ci  CBC_OPCODE (CBC_CHECK_LET, CBC_HAS_LITERAL_ARG, 0, \
306425bb815Sopenharmony_ci              VM_OC_CHECK_LET) \
307425bb815Sopenharmony_ci  CBC_OPCODE (CBC_CREATE_VAR, CBC_HAS_LITERAL_ARG, 0, \
308425bb815Sopenharmony_ci              VM_OC_CREATE_BINDING) \
309425bb815Sopenharmony_ci  CBC_OPCODE (CBC_CREATE_LET, CBC_HAS_LITERAL_ARG, 0, \
310425bb815Sopenharmony_ci              VM_OC_CREATE_BINDING) \
311425bb815Sopenharmony_ci  CBC_OPCODE (CBC_CREATE_CONST, CBC_HAS_LITERAL_ARG, 0, \
312425bb815Sopenharmony_ci              VM_OC_CREATE_BINDING) \
313425bb815Sopenharmony_ci  CBC_OPCODE (CBC_CREATE_LOCAL, CBC_HAS_LITERAL_ARG, 0, \
314425bb815Sopenharmony_ci              VM_OC_CREATE_BINDING) \
315425bb815Sopenharmony_ci  CBC_OPCODE (CBC_INIT_ARG_OR_CATCH, CBC_HAS_LITERAL_ARG, -1, \
316425bb815Sopenharmony_ci              VM_OC_INIT_BINDING) \
317425bb815Sopenharmony_ci  CBC_OPCODE (CBC_INIT_LET, CBC_HAS_LITERAL_ARG, -1, \
318425bb815Sopenharmony_ci              VM_OC_INIT_BINDING) \
319425bb815Sopenharmony_ci  CBC_OPCODE (CBC_INIT_CONST, CBC_HAS_LITERAL_ARG, -1, \
320425bb815Sopenharmony_ci              VM_OC_INIT_BINDING) \
321425bb815Sopenharmony_ci  CBC_OPCODE (CBC_INIT_ARG_OR_FUNC, CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, 0, \
322425bb815Sopenharmony_ci              VM_OC_INIT_ARG_OR_FUNC) \
323425bb815Sopenharmony_ci  CBC_OPCODE (CBC_CREATE_VAR_EVAL, CBC_HAS_LITERAL_ARG, 0, \
324425bb815Sopenharmony_ci              VM_OC_VAR_EVAL) \
325425bb815Sopenharmony_ci  CBC_OPCODE (CBC_CREATE_VAR_FUNC_EVAL, CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, 0, \
326425bb815Sopenharmony_ci              VM_OC_VAR_EVAL) \
327425bb815Sopenharmony_ci  CBC_OPCODE (CBC_SET_VAR_FUNC, CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, 0, \
328425bb815Sopenharmony_ci              VM_OC_ASSIGN | VM_OC_GET_LITERAL | VM_OC_PUT_IDENT) \
329425bb815Sopenharmony_ci  CBC_OPCODE (CBC_SET_BYTECODE_PTR, CBC_NO_FLAG, 0, \
330425bb815Sopenharmony_ci              VM_OC_SET_BYTECODE_PTR) \
331425bb815Sopenharmony_ci  CBC_OPCODE (CBC_RETURN, CBC_NO_FLAG, -1, \
332425bb815Sopenharmony_ci              VM_OC_RETURN | VM_OC_GET_STACK) \
333425bb815Sopenharmony_ci  CBC_OPCODE (CBC_RETURN_WITH_BLOCK, CBC_NO_FLAG, 0, \
334425bb815Sopenharmony_ci              VM_OC_RETURN) \
335425bb815Sopenharmony_ci  CBC_OPCODE (CBC_RETURN_WITH_LITERAL, CBC_HAS_LITERAL_ARG, 0, \
336425bb815Sopenharmony_ci              VM_OC_RETURN | VM_OC_GET_LITERAL) \
337425bb815Sopenharmony_ci  CBC_OPCODE (CBC_SET_LITERAL_PROPERTY, CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, 0, \
338425bb815Sopenharmony_ci              VM_OC_SET_PROPERTY | VM_OC_NON_STATIC_FLAG | VM_OC_GET_LITERAL_LITERAL) \
339425bb815Sopenharmony_ci  CBC_OPCODE (CBC_COPY_TO_GLOBAL, CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, 0, \
340425bb815Sopenharmony_ci              VM_OC_COPY_TO_GLOBAL | VM_OC_GET_LITERAL) \
341425bb815Sopenharmony_ci  CBC_OPCODE (CBC_BREAKPOINT_ENABLED, CBC_NO_FLAG, 0, \
342425bb815Sopenharmony_ci              VM_OC_BREAKPOINT_ENABLED) \
343425bb815Sopenharmony_ci  CBC_OPCODE (CBC_BREAKPOINT_DISABLED, CBC_NO_FLAG, 0, \
344425bb815Sopenharmony_ci              VM_OC_BREAKPOINT_DISABLED) \
345425bb815Sopenharmony_ci  \
346425bb815Sopenharmony_ci  /* Unary opcodes. */ \
347425bb815Sopenharmony_ci  CBC_UNARY_OPERATION (CBC_PLUS, \
348425bb815Sopenharmony_ci                       PLUS) \
349425bb815Sopenharmony_ci  CBC_UNARY_OPERATION (CBC_NEGATE, \
350425bb815Sopenharmony_ci                       MINUS) \
351425bb815Sopenharmony_ci  CBC_UNARY_OPERATION (CBC_LOGICAL_NOT, \
352425bb815Sopenharmony_ci                       NOT) \
353425bb815Sopenharmony_ci  CBC_UNARY_OPERATION (CBC_BIT_NOT, \
354425bb815Sopenharmony_ci                       BIT_NOT) \
355425bb815Sopenharmony_ci  CBC_UNARY_OPERATION (CBC_VOID, \
356425bb815Sopenharmony_ci                       VOID) \
357425bb815Sopenharmony_ci  CBC_OPCODE (CBC_TYPEOF, CBC_NO_FLAG, 0, \
358425bb815Sopenharmony_ci              VM_OC_TYPEOF | VM_OC_GET_STACK | VM_OC_PUT_STACK) \
359425bb815Sopenharmony_ci  CBC_OPCODE (CBC_TYPEOF_IDENT, CBC_HAS_LITERAL_ARG, 1, \
360425bb815Sopenharmony_ci              VM_OC_TYPEOF_IDENT | VM_OC_PUT_STACK) \
361425bb815Sopenharmony_ci  \
362425bb815Sopenharmony_ci  /* Binary opcodes. */ \
363425bb815Sopenharmony_ci  CBC_BINARY_OPERATION (CBC_BIT_OR, \
364425bb815Sopenharmony_ci                        BIT_OR) \
365425bb815Sopenharmony_ci  CBC_BINARY_OPERATION (CBC_BIT_XOR, \
366425bb815Sopenharmony_ci                        BIT_XOR) \
367425bb815Sopenharmony_ci  CBC_BINARY_OPERATION (CBC_BIT_AND, \
368425bb815Sopenharmony_ci                        BIT_AND) \
369425bb815Sopenharmony_ci  CBC_BINARY_OPERATION (CBC_EQUAL, \
370425bb815Sopenharmony_ci                        EQUAL) \
371425bb815Sopenharmony_ci  CBC_BINARY_OPERATION (CBC_NOT_EQUAL, \
372425bb815Sopenharmony_ci                        NOT_EQUAL) \
373425bb815Sopenharmony_ci  CBC_BINARY_OPERATION (CBC_STRICT_EQUAL, \
374425bb815Sopenharmony_ci                        STRICT_EQUAL) \
375425bb815Sopenharmony_ci  CBC_BINARY_OPERATION (CBC_STRICT_NOT_EQUAL, \
376425bb815Sopenharmony_ci                        STRICT_NOT_EQUAL) \
377425bb815Sopenharmony_ci  CBC_BINARY_OPERATION (CBC_LESS, \
378425bb815Sopenharmony_ci                        LESS) \
379425bb815Sopenharmony_ci  CBC_BINARY_OPERATION (CBC_GREATER, \
380425bb815Sopenharmony_ci                        GREATER) \
381425bb815Sopenharmony_ci  CBC_BINARY_OPERATION (CBC_LESS_EQUAL, \
382425bb815Sopenharmony_ci                        LESS_EQUAL) \
383425bb815Sopenharmony_ci  CBC_BINARY_OPERATION (CBC_GREATER_EQUAL, \
384425bb815Sopenharmony_ci                        GREATER_EQUAL) \
385425bb815Sopenharmony_ci  CBC_BINARY_OPERATION (CBC_IN, \
386425bb815Sopenharmony_ci                        IN) \
387425bb815Sopenharmony_ci  CBC_BINARY_OPERATION (CBC_INSTANCEOF, \
388425bb815Sopenharmony_ci                        INSTANCEOF) \
389425bb815Sopenharmony_ci  CBC_BINARY_OPERATION (CBC_LEFT_SHIFT, \
390425bb815Sopenharmony_ci                        LEFT_SHIFT) \
391425bb815Sopenharmony_ci  CBC_BINARY_OPERATION (CBC_RIGHT_SHIFT, \
392425bb815Sopenharmony_ci                        RIGHT_SHIFT) \
393425bb815Sopenharmony_ci  CBC_BINARY_OPERATION (CBC_UNS_RIGHT_SHIFT, \
394425bb815Sopenharmony_ci                        UNS_RIGHT_SHIFT) \
395425bb815Sopenharmony_ci  CBC_BINARY_OPERATION (CBC_ADD, \
396425bb815Sopenharmony_ci                        ADD) \
397425bb815Sopenharmony_ci  CBC_BINARY_OPERATION (CBC_SUBTRACT, \
398425bb815Sopenharmony_ci                        SUB) \
399425bb815Sopenharmony_ci  CBC_BINARY_OPERATION (CBC_MULTIPLY, \
400425bb815Sopenharmony_ci                        MUL) \
401425bb815Sopenharmony_ci  CBC_BINARY_OPERATION (CBC_DIVIDE, \
402425bb815Sopenharmony_ci                        DIV) \
403425bb815Sopenharmony_ci  CBC_BINARY_OPERATION (CBC_MODULO, \
404425bb815Sopenharmony_ci                        MOD) \
405425bb815Sopenharmony_ci  CBC_BINARY_OPERATION (CBC_EXPONENTIATION, \
406425bb815Sopenharmony_ci                        EXP) \
407425bb815Sopenharmony_ci  \
408425bb815Sopenharmony_ci  /* Unary lvalue opcodes. */ \
409425bb815Sopenharmony_ci  CBC_OPCODE (CBC_DELETE_PUSH_RESULT, CBC_NO_FLAG, -1, \
410425bb815Sopenharmony_ci              VM_OC_PROP_DELETE | VM_OC_GET_STACK_STACK | VM_OC_PUT_STACK) \
411425bb815Sopenharmony_ci  CBC_OPCODE (CBC_DELETE_IDENT_PUSH_RESULT, CBC_HAS_LITERAL_ARG, 1, \
412425bb815Sopenharmony_ci              VM_OC_DELETE | VM_OC_PUT_STACK) \
413425bb815Sopenharmony_ci  CBC_UNARY_LVALUE_OPERATION (CBC_PRE_INCR, \
414425bb815Sopenharmony_ci                              PRE_INCR) \
415425bb815Sopenharmony_ci  CBC_UNARY_LVALUE_OPERATION (CBC_PRE_DECR, \
416425bb815Sopenharmony_ci                              PRE_DECR) \
417425bb815Sopenharmony_ci  CBC_UNARY_LVALUE_OPERATION (CBC_POST_INCR, \
418425bb815Sopenharmony_ci                              POST_INCR) \
419425bb815Sopenharmony_ci  CBC_UNARY_LVALUE_OPERATION (CBC_POST_DECR, \
420425bb815Sopenharmony_ci                              POST_DECR) \
421425bb815Sopenharmony_ci  \
422425bb815Sopenharmony_ci  /* Call opcodes. */ \
423425bb815Sopenharmony_ci  CBC_OPCODE (CBC_CALL, CBC_HAS_POP_STACK_BYTE_ARG, -1, \
424425bb815Sopenharmony_ci              VM_OC_CALL) \
425425bb815Sopenharmony_ci  CBC_OPCODE (CBC_CALL_PUSH_RESULT, CBC_HAS_POP_STACK_BYTE_ARG, 0, \
426425bb815Sopenharmony_ci              VM_OC_CALL | VM_OC_PUT_STACK) \
427425bb815Sopenharmony_ci  CBC_OPCODE (CBC_CALL_BLOCK, CBC_HAS_POP_STACK_BYTE_ARG, -1, \
428425bb815Sopenharmony_ci              VM_OC_CALL | VM_OC_PUT_BLOCK) \
429425bb815Sopenharmony_ci  CBC_OPCODE (CBC_CALL_PROP, CBC_HAS_POP_STACK_BYTE_ARG, -3, \
430425bb815Sopenharmony_ci              VM_OC_CALL) \
431425bb815Sopenharmony_ci  CBC_OPCODE (CBC_CALL_PROP_PUSH_RESULT, CBC_HAS_POP_STACK_BYTE_ARG, -2, \
432425bb815Sopenharmony_ci              VM_OC_CALL | VM_OC_PUT_STACK) \
433425bb815Sopenharmony_ci  CBC_OPCODE (CBC_CALL_PROP_BLOCK, CBC_HAS_POP_STACK_BYTE_ARG, -3, \
434425bb815Sopenharmony_ci              VM_OC_CALL | VM_OC_PUT_BLOCK) \
435425bb815Sopenharmony_ci  CBC_OPCODE (CBC_CALL0, CBC_NO_FLAG, -1, \
436425bb815Sopenharmony_ci              VM_OC_CALL) \
437425bb815Sopenharmony_ci  CBC_OPCODE (CBC_CALL0_PUSH_RESULT, CBC_NO_FLAG, 0, \
438425bb815Sopenharmony_ci              VM_OC_CALL | VM_OC_PUT_STACK) \
439425bb815Sopenharmony_ci  CBC_OPCODE (CBC_CALL0_BLOCK, CBC_NO_FLAG, -1, \
440425bb815Sopenharmony_ci              VM_OC_CALL | VM_OC_PUT_BLOCK) \
441425bb815Sopenharmony_ci  CBC_OPCODE (CBC_CALL0_PROP, CBC_NO_FLAG, -3, \
442425bb815Sopenharmony_ci              VM_OC_CALL) \
443425bb815Sopenharmony_ci  CBC_OPCODE (CBC_CALL0_PROP_PUSH_RESULT, CBC_NO_FLAG, -2, \
444425bb815Sopenharmony_ci              VM_OC_CALL | VM_OC_PUT_STACK) \
445425bb815Sopenharmony_ci  CBC_OPCODE (CBC_CALL0_PROP_BLOCK, CBC_NO_FLAG, -3, \
446425bb815Sopenharmony_ci              VM_OC_CALL | VM_OC_PUT_BLOCK) \
447425bb815Sopenharmony_ci  CBC_OPCODE (CBC_CALL1, CBC_NO_FLAG, -2, \
448425bb815Sopenharmony_ci              VM_OC_CALL) \
449425bb815Sopenharmony_ci  CBC_OPCODE (CBC_CALL1_PUSH_RESULT, CBC_NO_FLAG, -1, \
450425bb815Sopenharmony_ci              VM_OC_CALL | VM_OC_PUT_STACK) \
451425bb815Sopenharmony_ci  CBC_OPCODE (CBC_CALL1_BLOCK, CBC_NO_FLAG, -2, \
452425bb815Sopenharmony_ci              VM_OC_CALL | VM_OC_PUT_BLOCK) \
453425bb815Sopenharmony_ci  CBC_OPCODE (CBC_CALL1_PROP, CBC_NO_FLAG, -4, \
454425bb815Sopenharmony_ci              VM_OC_CALL) \
455425bb815Sopenharmony_ci  CBC_OPCODE (CBC_CALL1_PROP_PUSH_RESULT, CBC_NO_FLAG, -3, \
456425bb815Sopenharmony_ci              VM_OC_CALL | VM_OC_PUT_STACK) \
457425bb815Sopenharmony_ci  CBC_OPCODE (CBC_CALL1_PROP_BLOCK, CBC_NO_FLAG, -4, \
458425bb815Sopenharmony_ci              VM_OC_CALL | VM_OC_PUT_BLOCK) \
459425bb815Sopenharmony_ci  CBC_OPCODE (CBC_CALL2, CBC_NO_FLAG, -3, \
460425bb815Sopenharmony_ci              VM_OC_CALL) \
461425bb815Sopenharmony_ci  CBC_OPCODE (CBC_CALL2_PUSH_RESULT, CBC_NO_FLAG, -2, \
462425bb815Sopenharmony_ci              VM_OC_CALL | VM_OC_PUT_STACK) \
463425bb815Sopenharmony_ci  CBC_OPCODE (CBC_CALL2_BLOCK, CBC_NO_FLAG, -3, \
464425bb815Sopenharmony_ci              VM_OC_CALL | VM_OC_PUT_BLOCK) \
465425bb815Sopenharmony_ci  CBC_OPCODE (CBC_CALL2_PROP, CBC_NO_FLAG, -4, \
466425bb815Sopenharmony_ci              VM_OC_CALL) \
467425bb815Sopenharmony_ci  CBC_OPCODE (CBC_CALL2_PROP_PUSH_RESULT, CBC_NO_FLAG, -3, \
468425bb815Sopenharmony_ci              VM_OC_CALL | VM_OC_PUT_STACK) \
469425bb815Sopenharmony_ci  CBC_OPCODE (CBC_CALL2_PROP_BLOCK, CBC_NO_FLAG, -4, \
470425bb815Sopenharmony_ci              VM_OC_CALL | VM_OC_PUT_BLOCK) \
471425bb815Sopenharmony_ci  \
472425bb815Sopenharmony_ci  /* Binary assignment opcodes. */ \
473425bb815Sopenharmony_ci  CBC_OPCODE (CBC_ASSIGN, CBC_NO_FLAG, -3, \
474425bb815Sopenharmony_ci              VM_OC_ASSIGN | VM_OC_GET_STACK | VM_OC_PUT_REFERENCE) \
475425bb815Sopenharmony_ci  CBC_OPCODE (CBC_ASSIGN_PUSH_RESULT, CBC_NO_FLAG, -2, \
476425bb815Sopenharmony_ci              VM_OC_ASSIGN | VM_OC_GET_STACK | VM_OC_PUT_REFERENCE | VM_OC_PUT_STACK) \
477425bb815Sopenharmony_ci  CBC_OPCODE (CBC_ASSIGN_BLOCK, CBC_NO_FLAG, -3, \
478425bb815Sopenharmony_ci              VM_OC_ASSIGN | VM_OC_GET_STACK | VM_OC_PUT_REFERENCE | VM_OC_PUT_BLOCK) \
479425bb815Sopenharmony_ci  CBC_OPCODE (CBC_ASSIGN_SET_IDENT, CBC_HAS_LITERAL_ARG, -1, \
480425bb815Sopenharmony_ci              VM_OC_ASSIGN | VM_OC_GET_STACK | VM_OC_PUT_IDENT) \
481425bb815Sopenharmony_ci  CBC_OPCODE (CBC_ASSIGN_SET_IDENT_PUSH_RESULT, CBC_HAS_LITERAL_ARG, 0, \
482425bb815Sopenharmony_ci              VM_OC_ASSIGN | VM_OC_GET_STACK | VM_OC_PUT_IDENT | VM_OC_PUT_STACK) \
483425bb815Sopenharmony_ci  CBC_OPCODE (CBC_ASSIGN_SET_IDENT_BLOCK, CBC_HAS_LITERAL_ARG, -1, \
484425bb815Sopenharmony_ci              VM_OC_ASSIGN | VM_OC_GET_STACK | VM_OC_PUT_IDENT | VM_OC_PUT_BLOCK) \
485425bb815Sopenharmony_ci  CBC_OPCODE (CBC_ASSIGN_LITERAL_SET_IDENT, CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, 0, \
486425bb815Sopenharmony_ci              VM_OC_ASSIGN | VM_OC_GET_LITERAL | VM_OC_PUT_IDENT) \
487425bb815Sopenharmony_ci  CBC_OPCODE (CBC_ASSIGN_LITERAL_SET_IDENT_PUSH_RESULT, CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, 1, \
488425bb815Sopenharmony_ci              VM_OC_ASSIGN | VM_OC_GET_LITERAL | VM_OC_PUT_IDENT | VM_OC_PUT_STACK) \
489425bb815Sopenharmony_ci  CBC_OPCODE (CBC_ASSIGN_LITERAL_SET_IDENT_BLOCK, CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, 0, \
490425bb815Sopenharmony_ci              VM_OC_ASSIGN | VM_OC_GET_LITERAL | VM_OC_PUT_IDENT | VM_OC_PUT_BLOCK) \
491425bb815Sopenharmony_ci  CBC_OPCODE (CBC_ASSIGN_PROP_LITERAL, CBC_HAS_LITERAL_ARG, -2, \
492425bb815Sopenharmony_ci              VM_OC_ASSIGN_PROP | VM_OC_GET_LITERAL | VM_OC_PUT_REFERENCE) \
493425bb815Sopenharmony_ci  CBC_OPCODE (CBC_ASSIGN_PROP_LITERAL_PUSH_RESULT, CBC_HAS_LITERAL_ARG, -1, \
494425bb815Sopenharmony_ci              VM_OC_ASSIGN_PROP | VM_OC_GET_LITERAL | VM_OC_PUT_REFERENCE | VM_OC_PUT_STACK) \
495425bb815Sopenharmony_ci  CBC_OPCODE (CBC_ASSIGN_PROP_LITERAL_BLOCK, CBC_HAS_LITERAL_ARG, -2, \
496425bb815Sopenharmony_ci              VM_OC_ASSIGN_PROP | VM_OC_GET_LITERAL | VM_OC_PUT_REFERENCE | VM_OC_PUT_BLOCK) \
497425bb815Sopenharmony_ci  CBC_OPCODE (CBC_ASSIGN_PROP_THIS_LITERAL, CBC_HAS_LITERAL_ARG, -1, \
498425bb815Sopenharmony_ci              VM_OC_ASSIGN_PROP_THIS | VM_OC_GET_LITERAL | VM_OC_PUT_REFERENCE) \
499425bb815Sopenharmony_ci  CBC_OPCODE (CBC_ASSIGN_PROP_THIS_LITERAL_PUSH_RESULT, CBC_HAS_LITERAL_ARG, 0, \
500425bb815Sopenharmony_ci              VM_OC_ASSIGN_PROP_THIS | VM_OC_GET_LITERAL | VM_OC_PUT_REFERENCE | VM_OC_PUT_STACK) \
501425bb815Sopenharmony_ci  CBC_OPCODE (CBC_ASSIGN_PROP_THIS_LITERAL_BLOCK, CBC_HAS_LITERAL_ARG, -1, \
502425bb815Sopenharmony_ci              VM_OC_ASSIGN_PROP_THIS | VM_OC_GET_LITERAL | VM_OC_PUT_REFERENCE | VM_OC_PUT_BLOCK) \
503425bb815Sopenharmony_ci  CBC_OPCODE (CBC_MOV_IDENT, CBC_HAS_LITERAL_ARG, -1, \
504425bb815Sopenharmony_ci              VM_OC_MOV_IDENT | VM_OC_GET_STACK | VM_OC_PUT_IDENT) \
505425bb815Sopenharmony_ci  CBC_OPCODE (CBC_ASSIGN_LET_CONST, CBC_HAS_LITERAL_ARG, -1, \
506425bb815Sopenharmony_ci              VM_OC_ASSIGN_LET_CONST | VM_OC_GET_STACK) \
507425bb815Sopenharmony_ci  CBC_OPCODE (CBC_ASSIGN_LET_CONST_LITERAL, CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, 0, \
508425bb815Sopenharmony_ci              VM_OC_ASSIGN_LET_CONST | VM_OC_GET_LITERAL) \
509425bb815Sopenharmony_ci  CBC_OPCODE (CBC_ASSIGN_SUPER, CBC_NO_FLAG, -3, \
510425bb815Sopenharmony_ci              VM_OC_ASSIGN_SUPER) \
511425bb815Sopenharmony_ci  CBC_OPCODE (CBC_ASSIGN_SUPER_PUSH_RESULT, CBC_NO_FLAG, -2, \
512425bb815Sopenharmony_ci              VM_OC_ASSIGN_SUPER | VM_OC_PUT_STACK) \
513425bb815Sopenharmony_ci  CBC_OPCODE (CBC_ASSIGN_SUPER_BLOCK, CBC_NO_FLAG, -3, \
514425bb815Sopenharmony_ci              VM_OC_ASSIGN_SUPER | VM_OC_PUT_BLOCK) \
515425bb815Sopenharmony_ci  \
516425bb815Sopenharmony_ci  /* Last opcode (not a real opcode). */ \
517425bb815Sopenharmony_ci  CBC_OPCODE (CBC_END, CBC_NO_FLAG, 0, \
518425bb815Sopenharmony_ci              VM_OC_NONE)
519425bb815Sopenharmony_ci
520425bb815Sopenharmony_ci/* All EXT branches are statement block end
521425bb815Sopenharmony_ci * marks, so they are always forward branches. */
522425bb815Sopenharmony_ci
523425bb815Sopenharmony_ci#define CBC_EXT_OPCODE_LIST \
524425bb815Sopenharmony_ci  /* Branch opcodes first. Some other opcodes are mixed. */ \
525425bb815Sopenharmony_ci  CBC_OPCODE (CBC_EXT_NOP, CBC_NO_FLAG, 0, \
526425bb815Sopenharmony_ci              VM_OC_NONE) \
527425bb815Sopenharmony_ci  CBC_FORWARD_BRANCH (CBC_EXT_WITH_CREATE_CONTEXT, \
528425bb815Sopenharmony_ci                      -1 + PARSER_WITH_CONTEXT_STACK_ALLOCATION, VM_OC_WITH) \
529425bb815Sopenharmony_ci  CBC_OPCODE (CBC_EXT_FOR_IN_GET_NEXT, CBC_NO_FLAG, 1, \
530425bb815Sopenharmony_ci              VM_OC_FOR_IN_GET_NEXT | VM_OC_PUT_STACK) \
531425bb815Sopenharmony_ci  CBC_FORWARD_BRANCH (CBC_EXT_FOR_IN_CREATE_CONTEXT, \
532425bb815Sopenharmony_ci                      -1 + PARSER_FOR_IN_CONTEXT_STACK_ALLOCATION, VM_OC_FOR_IN_CREATE_CONTEXT) \
533425bb815Sopenharmony_ci  CBC_OPCODE (CBC_EXT_SET_GETTER, CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, 0, \
534425bb815Sopenharmony_ci              VM_OC_SET_GETTER | VM_OC_NON_STATIC_FLAG | VM_OC_GET_LITERAL_LITERAL) \
535425bb815Sopenharmony_ci  CBC_BACKWARD_BRANCH (CBC_EXT_BRANCH_IF_FOR_IN_HAS_NEXT, 0, \
536425bb815Sopenharmony_ci                       VM_OC_FOR_IN_HAS_NEXT) \
537425bb815Sopenharmony_ci  CBC_OPCODE (CBC_EXT_FOR_OF_GET_NEXT, CBC_NO_FLAG, 1, \
538425bb815Sopenharmony_ci              VM_OC_FOR_OF_GET_NEXT | VM_OC_PUT_STACK) \
539425bb815Sopenharmony_ci  CBC_FORWARD_BRANCH (CBC_EXT_FOR_OF_CREATE_CONTEXT, \
540425bb815Sopenharmony_ci                      -1 + PARSER_FOR_OF_CONTEXT_STACK_ALLOCATION, VM_OC_FOR_OF_CREATE_CONTEXT) \
541425bb815Sopenharmony_ci  CBC_OPCODE (CBC_EXT_PUSH_NAMED_FUNC_EXPRESSION, CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, 1, \
542425bb815Sopenharmony_ci              VM_OC_PUSH_NAMED_FUNC_EXPR | VM_OC_GET_LITERAL_LITERAL) \
543425bb815Sopenharmony_ci  CBC_BACKWARD_BRANCH (CBC_EXT_BRANCH_IF_FOR_OF_HAS_NEXT, 0, \
544425bb815Sopenharmony_ci                       VM_OC_FOR_OF_HAS_NEXT) \
545425bb815Sopenharmony_ci  CBC_OPCODE (CBC_EXT_SET_SETTER, CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, 0, \
546425bb815Sopenharmony_ci              VM_OC_SET_SETTER | VM_OC_NON_STATIC_FLAG | VM_OC_GET_LITERAL_LITERAL) \
547425bb815Sopenharmony_ci  CBC_FORWARD_BRANCH (CBC_EXT_TRY_CREATE_CONTEXT, PARSER_TRY_CONTEXT_STACK_ALLOCATION, \
548425bb815Sopenharmony_ci                      VM_OC_TRY) \
549425bb815Sopenharmony_ci  CBC_OPCODE (CBC_EXT_TRY_CREATE_ENV, CBC_NO_FLAG, 0, \
550425bb815Sopenharmony_ci              VM_OC_BLOCK_CREATE_CONTEXT) \
551425bb815Sopenharmony_ci  CBC_FORWARD_BRANCH (CBC_EXT_CATCH, 1, \
552425bb815Sopenharmony_ci                      VM_OC_CATCH) \
553425bb815Sopenharmony_ci  CBC_OPCODE (CBC_EXT_RESOLVE_BASE, CBC_NO_FLAG, 0, \
554425bb815Sopenharmony_ci              VM_OC_RESOLVE_BASE_FOR_CALL) \
555425bb815Sopenharmony_ci  CBC_FORWARD_BRANCH (CBC_EXT_FINALLY, 0, \
556425bb815Sopenharmony_ci                      VM_OC_FINALLY) \
557425bb815Sopenharmony_ci  CBC_OPCODE (CBC_EXT_INITIALIZER_PUSH_PROP, CBC_NO_FLAG, 0, \
558425bb815Sopenharmony_ci              VM_OC_INITIALIZER_PUSH_PROP | VM_OC_GET_STACK) \
559425bb815Sopenharmony_ci  CBC_FORWARD_BRANCH (CBC_EXT_DEFAULT_INITIALIZER, -1, \
560425bb815Sopenharmony_ci                      VM_OC_DEFAULT_INITIALIZER) \
561425bb815Sopenharmony_ci  \
562425bb815Sopenharmony_ci  /* Basic opcodes. */ \
563425bb815Sopenharmony_ci  CBC_OPCODE (CBC_EXT_PUSH_LITERAL_PUSH_NUMBER_0, CBC_HAS_LITERAL_ARG, 2, \
564425bb815Sopenharmony_ci              VM_OC_PUSH_LIT_0 | VM_OC_GET_LITERAL) \
565425bb815Sopenharmony_ci  CBC_OPCODE (CBC_EXT_PUSH_LITERAL_PUSH_NUMBER_POS_BYTE, CBC_HAS_LITERAL_ARG | CBC_HAS_BYTE_ARG, 2, \
566425bb815Sopenharmony_ci              VM_OC_PUSH_LIT_POS_BYTE | VM_OC_GET_LITERAL) \
567425bb815Sopenharmony_ci  CBC_OPCODE (CBC_EXT_PUSH_LITERAL_PUSH_NUMBER_NEG_BYTE, CBC_HAS_LITERAL_ARG | CBC_HAS_BYTE_ARG, 2, \
568425bb815Sopenharmony_ci              VM_OC_PUSH_LIT_NEG_BYTE | VM_OC_GET_LITERAL) \
569425bb815Sopenharmony_ci  CBC_OPCODE (CBC_EXT_CREATE_VAR_EVAL, CBC_HAS_LITERAL_ARG, 0, \
570425bb815Sopenharmony_ci              VM_OC_EXT_VAR_EVAL) \
571425bb815Sopenharmony_ci  CBC_OPCODE (CBC_EXT_CREATE_VAR_FUNC_EVAL, CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, 0, \
572425bb815Sopenharmony_ci              VM_OC_EXT_VAR_EVAL) \
573425bb815Sopenharmony_ci  CBC_OPCODE (CBC_EXT_COPY_FROM_ARG, CBC_HAS_LITERAL_ARG, 0, \
574425bb815Sopenharmony_ci              VM_OC_COPY_FROM_ARG) \
575425bb815Sopenharmony_ci  CBC_OPCODE (CBC_EXT_STRING_CONCAT, CBC_NO_FLAG, -1, \
576425bb815Sopenharmony_ci              VM_OC_STRING_CONCAT | VM_OC_GET_STACK_STACK | VM_OC_PUT_STACK) \
577425bb815Sopenharmony_ci  CBC_OPCODE (CBC_EXT_STRING_CONCAT_RIGHT_LITERAL, CBC_HAS_LITERAL_ARG, 0, \
578425bb815Sopenharmony_ci              VM_OC_STRING_CONCAT | VM_OC_GET_STACK_LITERAL | VM_OC_PUT_STACK) \
579425bb815Sopenharmony_ci  CBC_OPCODE (CBC_EXT_STRING_CONCAT_TWO_LITERALS, CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, 1, \
580425bb815Sopenharmony_ci              VM_OC_STRING_CONCAT | VM_OC_GET_LITERAL_LITERAL | VM_OC_PUT_STACK) \
581425bb815Sopenharmony_ci  CBC_OPCODE (CBC_EXT_GET_TAGGED_TEMPLATE_LITERAL, CBC_HAS_BYTE_ARG, 1, \
582425bb815Sopenharmony_ci              VM_OC_GET_TEMPLATE_OBJECT | VM_OC_PUT_STACK) \
583425bb815Sopenharmony_ci  CBC_OPCODE (CBC_EXT_CLONE_CONTEXT, CBC_NO_FLAG, 0, \
584425bb815Sopenharmony_ci              VM_OC_CLONE_CONTEXT) \
585425bb815Sopenharmony_ci  CBC_OPCODE (CBC_EXT_CLONE_FULL_CONTEXT, CBC_NO_FLAG, 0, \
586425bb815Sopenharmony_ci              VM_OC_CLONE_CONTEXT) \
587425bb815Sopenharmony_ci  CBC_OPCODE (CBC_EXT_RESOURCE_NAME, CBC_NO_FLAG, 0, \
588425bb815Sopenharmony_ci              VM_OC_RESOURCE_NAME) \
589425bb815Sopenharmony_ci  CBC_OPCODE (CBC_EXT_LINE, CBC_NO_FLAG, 0, \
590425bb815Sopenharmony_ci              VM_OC_LINE) \
591425bb815Sopenharmony_ci  CBC_OPCODE (CBC_EXT_ERROR, CBC_NO_FLAG, 0, \
592425bb815Sopenharmony_ci              VM_OC_ERROR) \
593425bb815Sopenharmony_ci  CBC_OPCODE (CBC_EXT_THROW_REFERENCE_ERROR, CBC_NO_FLAG, 1, \
594425bb815Sopenharmony_ci              VM_OC_THROW_REFERENCE_ERROR) \
595425bb815Sopenharmony_ci  CBC_OPCODE (CBC_EXT_THROW_ASSIGN_CONST_ERROR, CBC_NO_FLAG, 0, \
596425bb815Sopenharmony_ci              VM_OC_THROW_CONST_ERROR) \
597425bb815Sopenharmony_ci  CBC_OPCODE (CBC_EXT_REQUIRE_OBJECT_COERCIBLE, CBC_NO_FLAG, 0, \
598425bb815Sopenharmony_ci              VM_OC_REQUIRE_OBJECT_COERCIBLE) \
599425bb815Sopenharmony_ci  \
600425bb815Sopenharmony_ci  /* Computed / class property related opcodes. */ \
601425bb815Sopenharmony_ci  CBC_OPCODE (CBC_EXT_SET_COMPUTED_PROPERTY, CBC_NO_FLAG, -2, \
602425bb815Sopenharmony_ci              VM_OC_SET_COMPUTED_PROPERTY | VM_OC_NON_STATIC_FLAG | VM_OC_GET_STACK_STACK) \
603425bb815Sopenharmony_ci  CBC_OPCODE (CBC_EXT_SET_COMPUTED_PROPERTY_LITERAL, CBC_HAS_LITERAL_ARG, -1, \
604425bb815Sopenharmony_ci              VM_OC_SET_COMPUTED_PROPERTY | VM_OC_NON_STATIC_FLAG | VM_OC_GET_STACK_LITERAL) \
605425bb815Sopenharmony_ci  CBC_OPCODE (CBC_EXT_SET_COMPUTED_GETTER, CBC_HAS_LITERAL_ARG, -1, \
606425bb815Sopenharmony_ci              VM_OC_SET_GETTER | VM_OC_NON_STATIC_FLAG | VM_OC_GET_STACK_LITERAL) \
607425bb815Sopenharmony_ci  CBC_OPCODE (CBC_EXT_SET_COMPUTED_SETTER, CBC_HAS_LITERAL_ARG, -1, \
608425bb815Sopenharmony_ci              VM_OC_SET_SETTER | VM_OC_NON_STATIC_FLAG | VM_OC_GET_STACK_LITERAL) \
609425bb815Sopenharmony_ci  CBC_OPCODE (CBC_EXT_SET_STATIC_PROPERTY_LITERAL, CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, 0, \
610425bb815Sopenharmony_ci              VM_OC_SET_PROPERTY | VM_OC_GET_LITERAL_LITERAL) \
611425bb815Sopenharmony_ci  CBC_OPCODE (CBC_EXT_SET_STATIC_COMPUTED_PROPERTY_LITERAL, CBC_HAS_LITERAL_ARG, -1, \
612425bb815Sopenharmony_ci              VM_OC_SET_COMPUTED_PROPERTY | VM_OC_GET_STACK_LITERAL) \
613425bb815Sopenharmony_ci  CBC_OPCODE (CBC_EXT_SET_STATIC_GETTER, CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, 0, \
614425bb815Sopenharmony_ci              VM_OC_SET_GETTER | VM_OC_GET_LITERAL_LITERAL) \
615425bb815Sopenharmony_ci  CBC_OPCODE (CBC_EXT_SET_STATIC_SETTER, CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, 0, \
616425bb815Sopenharmony_ci              VM_OC_SET_SETTER | VM_OC_GET_LITERAL_LITERAL) \
617425bb815Sopenharmony_ci  CBC_OPCODE (CBC_EXT_SET_STATIC_COMPUTED_GETTER, CBC_HAS_LITERAL_ARG, -1, \
618425bb815Sopenharmony_ci              VM_OC_SET_GETTER | VM_OC_GET_STACK_LITERAL) \
619425bb815Sopenharmony_ci  CBC_OPCODE (CBC_EXT_SET_STATIC_COMPUTED_SETTER, CBC_HAS_LITERAL_ARG, -1, \
620425bb815Sopenharmony_ci              VM_OC_SET_SETTER | VM_OC_GET_STACK_LITERAL) \
621425bb815Sopenharmony_ci  CBC_OPCODE (CBC_EXT_SET__PROTO__, CBC_NO_FLAG, -1, \
622425bb815Sopenharmony_ci              VM_OC_SET__PROTO__ | VM_OC_GET_STACK) \
623425bb815Sopenharmony_ci  \
624425bb815Sopenharmony_ci  /* Class related opcodes. */ \
625425bb815Sopenharmony_ci  CBC_OPCODE (CBC_EXT_PUSH_NAMED_CLASS_ENV, CBC_HAS_LITERAL_ARG, 1, \
626425bb815Sopenharmony_ci              VM_OC_PUSH_CLASS_ENVIRONMENT | VM_OC_GET_LITERAL) \
627425bb815Sopenharmony_ci  CBC_OPCODE (CBC_EXT_PUSH_ANONYMOUS_CLASS_ENV, CBC_NO_FLAG, 1, \
628425bb815Sopenharmony_ci              VM_OC_PUSH_CLASS_ENVIRONMENT) \
629425bb815Sopenharmony_ci  CBC_OPCODE (CBC_EXT_PUSH_IMPLICIT_CONSTRUCTOR, CBC_NO_FLAG, 1, \
630425bb815Sopenharmony_ci              VM_OC_PUSH_IMPLICIT_CTOR | VM_OC_PUT_STACK) \
631425bb815Sopenharmony_ci  CBC_OPCODE (CBC_EXT_PUSH_IMPLICIT_CONSTRUCTOR_HERITAGE, CBC_NO_FLAG, 1, \
632425bb815Sopenharmony_ci              VM_OC_PUSH_IMPLICIT_CTOR | VM_OC_PUT_STACK) \
633425bb815Sopenharmony_ci  CBC_OPCODE (CBC_EXT_INIT_CLASS, CBC_NO_FLAG, 0, \
634425bb815Sopenharmony_ci              VM_OC_INIT_CLASS | VM_OC_PUT_STACK) \
635425bb815Sopenharmony_ci  CBC_OPCODE (CBC_EXT_FINALIZE_NAMED_CLASS, CBC_HAS_LITERAL_ARG, -2, \
636425bb815Sopenharmony_ci              VM_OC_FINALIZE_CLASS | VM_OC_GET_LITERAL) \
637425bb815Sopenharmony_ci  CBC_OPCODE (CBC_EXT_FINALIZE_ANONYMOUS_CLASS, CBC_NO_FLAG, -2, \
638425bb815Sopenharmony_ci              VM_OC_FINALIZE_CLASS) \
639425bb815Sopenharmony_ci  CBC_OPCODE (CBC_EXT_PUSH_SUPER, CBC_NO_FLAG, 1, \
640425bb815Sopenharmony_ci              VM_OC_NONE) \
641425bb815Sopenharmony_ci  CBC_OPCODE (CBC_EXT_PUSH_SUPER_CONSTRUCTOR, CBC_NO_FLAG, 1, \
642425bb815Sopenharmony_ci              VM_OC_PUSH_SUPER_CONSTRUCTOR) \
643425bb815Sopenharmony_ci  CBC_OPCODE (CBC_EXT_PUSH_SUPER_PROP, CBC_NO_FLAG, 0, \
644425bb815Sopenharmony_ci              VM_OC_SUPER_REFERENCE | VM_OC_GET_STACK) \
645425bb815Sopenharmony_ci  CBC_OPCODE (CBC_EXT_SUPER_PROP_REFERENCE, CBC_NO_FLAG, 2, \
646425bb815Sopenharmony_ci              VM_OC_SUPER_REFERENCE | VM_OC_GET_STACK) \
647425bb815Sopenharmony_ci  CBC_OPCODE (CBC_EXT_PUSH_SUPER_PROP_LITERAL, CBC_HAS_LITERAL_ARG, 1, \
648425bb815Sopenharmony_ci              VM_OC_SUPER_REFERENCE | VM_OC_GET_LITERAL) \
649425bb815Sopenharmony_ci  CBC_OPCODE (CBC_EXT_SUPER_PROP_LITERAL_REFERENCE, CBC_HAS_LITERAL_ARG, 3, \
650425bb815Sopenharmony_ci              VM_OC_SUPER_REFERENCE | VM_OC_GET_LITERAL) \
651425bb815Sopenharmony_ci  CBC_OPCODE (CBC_EXT_SUPER_PROP_ASSIGNMENT_REFERENCE, CBC_NO_FLAG, 1, \
652425bb815Sopenharmony_ci              VM_OC_SUPER_REFERENCE | VM_OC_GET_STACK) \
653425bb815Sopenharmony_ci  CBC_OPCODE (CBC_EXT_SUPER_PROP_LITERAL_ASSIGNMENT_REFERENCE, CBC_HAS_LITERAL_ARG, 2, \
654425bb815Sopenharmony_ci              VM_OC_SUPER_REFERENCE | VM_OC_GET_LITERAL) \
655425bb815Sopenharmony_ci  CBC_OPCODE (CBC_EXT_RESOLVE_LEXICAL_THIS, CBC_NO_FLAG, 1, \
656425bb815Sopenharmony_ci              VM_OC_RESOLVE_LEXICAL_THIS | VM_OC_PUT_STACK) \
657425bb815Sopenharmony_ci  CBC_OPCODE (CBC_EXT_LOCAL_EVAL, CBC_HAS_BYTE_ARG, 0, \
658425bb815Sopenharmony_ci              VM_OC_LOCAL_EVAL) \
659425bb815Sopenharmony_ci  CBC_OPCODE (CBC_EXT_SUPER_CALL, CBC_HAS_POP_STACK_BYTE_ARG, -1, \
660425bb815Sopenharmony_ci              VM_OC_SUPER_CALL) \
661425bb815Sopenharmony_ci  CBC_OPCODE (CBC_EXT_SUPER_CALL_PUSH_RESULT, CBC_HAS_POP_STACK_BYTE_ARG, 0, \
662425bb815Sopenharmony_ci              VM_OC_SUPER_CALL | VM_OC_PUT_STACK) \
663425bb815Sopenharmony_ci  CBC_OPCODE (CBC_EXT_SUPER_CALL_BLOCK, CBC_HAS_POP_STACK_BYTE_ARG, -1, \
664425bb815Sopenharmony_ci              VM_OC_SUPER_CALL | VM_OC_PUT_BLOCK) \
665425bb815Sopenharmony_ci  CBC_OPCODE (CBC_EXT_SPREAD_SUPER_CALL, CBC_HAS_POP_STACK_BYTE_ARG, -1, \
666425bb815Sopenharmony_ci              VM_OC_SUPER_CALL) \
667425bb815Sopenharmony_ci  CBC_OPCODE (CBC_EXT_SPREAD_SUPER_CALL_PUSH_RESULT, CBC_HAS_POP_STACK_BYTE_ARG, 0, \
668425bb815Sopenharmony_ci              VM_OC_SUPER_CALL | VM_OC_PUT_STACK) \
669425bb815Sopenharmony_ci  CBC_OPCODE (CBC_EXT_SPREAD_SUPER_CALL_BLOCK, CBC_HAS_POP_STACK_BYTE_ARG, -1, \
670425bb815Sopenharmony_ci              VM_OC_SUPER_CALL | VM_OC_PUT_BLOCK) \
671425bb815Sopenharmony_ci  \
672425bb815Sopenharmony_ci  /* Spread / rest operation related opcodes. */ \
673425bb815Sopenharmony_ci  CBC_OPCODE (CBC_EXT_SPREAD_CALL, CBC_HAS_POP_STACK_BYTE_ARG, -1, \
674425bb815Sopenharmony_ci              VM_OC_SPREAD_ARGUMENTS) \
675425bb815Sopenharmony_ci  CBC_OPCODE (CBC_EXT_SPREAD_CALL_PUSH_RESULT, CBC_HAS_POP_STACK_BYTE_ARG, 0, \
676425bb815Sopenharmony_ci              VM_OC_SPREAD_ARGUMENTS | VM_OC_PUT_STACK) \
677425bb815Sopenharmony_ci  CBC_OPCODE (CBC_EXT_SPREAD_CALL_BLOCK, CBC_HAS_POP_STACK_BYTE_ARG, -1, \
678425bb815Sopenharmony_ci              VM_OC_SPREAD_ARGUMENTS | VM_OC_PUT_BLOCK) \
679425bb815Sopenharmony_ci  CBC_OPCODE (CBC_EXT_SPREAD_CALL_PROP, CBC_HAS_POP_STACK_BYTE_ARG, -3, \
680425bb815Sopenharmony_ci              VM_OC_SPREAD_ARGUMENTS) \
681425bb815Sopenharmony_ci  CBC_OPCODE (CBC_EXT_SPREAD_CALL_PROP_PUSH_RESULT, CBC_HAS_POP_STACK_BYTE_ARG, -2, \
682425bb815Sopenharmony_ci              VM_OC_SPREAD_ARGUMENTS | VM_OC_PUT_STACK) \
683425bb815Sopenharmony_ci  CBC_OPCODE (CBC_EXT_SPREAD_CALL_PROP_BLOCK, CBC_HAS_POP_STACK_BYTE_ARG, -3, \
684425bb815Sopenharmony_ci              VM_OC_SPREAD_ARGUMENTS | VM_OC_PUT_BLOCK) \
685425bb815Sopenharmony_ci  CBC_OPCODE (CBC_EXT_PUSH_SPREAD_ELEMENT, CBC_NO_FLAG, 1, \
686425bb815Sopenharmony_ci              VM_OC_PUSH_SPREAD_ELEMENT) \
687425bb815Sopenharmony_ci  CBC_OPCODE (CBC_EXT_SPREAD_ARRAY_APPEND, CBC_HAS_POP_STACK_BYTE_ARG, 0, \
688425bb815Sopenharmony_ci              VM_OC_APPEND_ARRAY) \
689425bb815Sopenharmony_ci  CBC_OPCODE (CBC_EXT_REST_INITIALIZER, CBC_NO_FLAG, 1, \
690425bb815Sopenharmony_ci              VM_OC_REST_INITIALIZER) \
691425bb815Sopenharmony_ci  CBC_OPCODE (CBC_EXT_REST_INITIALIZER_2, CBC_NO_FLAG, 1, \
692425bb815Sopenharmony_ci              VM_OC_REST_INITIALIZER) \
693425bb815Sopenharmony_ci  CBC_OPCODE (CBC_EXT_REST_INITIALIZER_3, CBC_NO_FLAG, 1, \
694425bb815Sopenharmony_ci              VM_OC_REST_INITIALIZER) \
695425bb815Sopenharmony_ci  CBC_OPCODE (CBC_EXT_INITIALIZER_PUSH_PROP_LITERAL, CBC_HAS_LITERAL_ARG, 1, \
696425bb815Sopenharmony_ci              VM_OC_INITIALIZER_PUSH_PROP | VM_OC_GET_LITERAL) \
697425bb815Sopenharmony_ci  CBC_OPCODE (CBC_EXT_SPREAD_NEW, CBC_HAS_POP_STACK_BYTE_ARG, 0, \
698425bb815Sopenharmony_ci              VM_OC_SPREAD_ARGUMENTS | VM_OC_PUT_STACK) \
699425bb815Sopenharmony_ci  \
700425bb815Sopenharmony_ci  /* Iterator related opcodes. */ \
701425bb815Sopenharmony_ci  CBC_OPCODE (CBC_EXT_GET_ITERATOR, CBC_NO_FLAG, 1, \
702425bb815Sopenharmony_ci              VM_OC_GET_ITERATOR) \
703425bb815Sopenharmony_ci  CBC_OPCODE (CBC_EXT_ITERATOR_STEP, CBC_NO_FLAG, 1, \
704425bb815Sopenharmony_ci              VM_OC_ITERATOR_STEP) \
705425bb815Sopenharmony_ci  CBC_OPCODE (CBC_EXT_ITERATOR_STEP_2, CBC_NO_FLAG, 1, \
706425bb815Sopenharmony_ci              VM_OC_ITERATOR_STEP) \
707425bb815Sopenharmony_ci  CBC_OPCODE (CBC_EXT_ITERATOR_STEP_3, CBC_NO_FLAG, 1, \
708425bb815Sopenharmony_ci              VM_OC_ITERATOR_STEP) \
709425bb815Sopenharmony_ci  CBC_OPCODE (CBC_EXT_ITERATOR_CLOSE, CBC_NO_FLAG, -1, \
710425bb815Sopenharmony_ci              VM_OC_ITERATOR_CLOSE | VM_OC_GET_STACK) \
711425bb815Sopenharmony_ci  \
712425bb815Sopenharmony_ci  /* Executable object related opcodes. */ \
713425bb815Sopenharmony_ci  CBC_OPCODE (CBC_EXT_CREATE_GENERATOR, CBC_NO_FLAG, 1, \
714425bb815Sopenharmony_ci              VM_OC_CREATE_GENERATOR) \
715425bb815Sopenharmony_ci  CBC_OPCODE (CBC_EXT_YIELD, CBC_NO_FLAG, 0, \
716425bb815Sopenharmony_ci              VM_OC_YIELD) \
717425bb815Sopenharmony_ci  CBC_OPCODE (CBC_EXT_YIELD_ITERATOR, CBC_NO_FLAG, 0, \
718425bb815Sopenharmony_ci              VM_OC_YIELD) \
719425bb815Sopenharmony_ci  CBC_OPCODE (CBC_EXT_AWAIT, CBC_NO_FLAG, 0, \
720425bb815Sopenharmony_ci              VM_OC_AWAIT) \
721425bb815Sopenharmony_ci  CBC_OPCODE (CBC_EXT_RETURN, CBC_NO_FLAG, -1, \
722425bb815Sopenharmony_ci              VM_OC_EXT_RETURN | VM_OC_GET_STACK) \
723425bb815Sopenharmony_ci  CBC_OPCODE (CBC_EXT_RETURN_PROMISE, CBC_NO_FLAG, -1, \
724425bb815Sopenharmony_ci              VM_OC_RETURN_PROMISE | VM_OC_GET_STACK) \
725425bb815Sopenharmony_ci  CBC_OPCODE (CBC_EXT_RETURN_PROMISE_UNDEFINED, CBC_NO_FLAG, 0, \
726425bb815Sopenharmony_ci              VM_OC_RETURN_PROMISE) \
727425bb815Sopenharmony_ci  CBC_OPCODE (CBC_EXT_PUSH_NEW_TARGET, CBC_NO_FLAG, 1, \
728425bb815Sopenharmony_ci              VM_OC_PUSH_NEW_TARGET | VM_OC_PUT_STACK) \
729425bb815Sopenharmony_ci  \
730425bb815Sopenharmony_ci  /* Last opcode (not a real opcode). */ \
731425bb815Sopenharmony_ci  CBC_OPCODE (CBC_EXT_END, CBC_NO_FLAG, 0, \
732425bb815Sopenharmony_ci              VM_OC_NONE)
733425bb815Sopenharmony_ci
734425bb815Sopenharmony_ci#define CBC_MAXIMUM_BYTE_VALUE 255
735425bb815Sopenharmony_ci#define CBC_MAXIMUM_SMALL_VALUE 510
736425bb815Sopenharmony_ci#define CBC_MAXIMUM_FULL_VALUE 32767
737425bb815Sopenharmony_ci
738425bb815Sopenharmony_ci#define CBC_PUSH_NUMBER_BYTE_RANGE_END 256
739425bb815Sopenharmony_ci
740425bb815Sopenharmony_ci#define CBC_HIGHEST_BIT_MASK 0x80
741425bb815Sopenharmony_ci#define CBC_LOWER_SEVEN_BIT_MASK 0x7f
742425bb815Sopenharmony_ci
743425bb815Sopenharmony_ci/**
744425bb815Sopenharmony_ci * Literal encoding limit when full literal encoding mode is enabled
745425bb815Sopenharmony_ci */
746425bb815Sopenharmony_ci#define CBC_FULL_LITERAL_ENCODING_LIMIT 128
747425bb815Sopenharmony_ci
748425bb815Sopenharmony_ci/**
749425bb815Sopenharmony_ci * Literal encoding delta when full literal encoding mode is enabled
750425bb815Sopenharmony_ci */
751425bb815Sopenharmony_ci#define CBC_FULL_LITERAL_ENCODING_DELTA 0x8000
752425bb815Sopenharmony_ci
753425bb815Sopenharmony_ci/**
754425bb815Sopenharmony_ci * Literal encoding limit when full literal encoding mode is disabled
755425bb815Sopenharmony_ci */
756425bb815Sopenharmony_ci#define CBC_SMALL_LITERAL_ENCODING_LIMIT 255
757425bb815Sopenharmony_ci
758425bb815Sopenharmony_ci/**
759425bb815Sopenharmony_ci * Literal encoding delta when full literal encoding mode is disabled
760425bb815Sopenharmony_ci */
761425bb815Sopenharmony_ci#define CBC_SMALL_LITERAL_ENCODING_DELTA 0xfe01
762425bb815Sopenharmony_ci
763425bb815Sopenharmony_ci/**
764425bb815Sopenharmony_ci * Literal indicies belong to one of the following groups:
765425bb815Sopenharmony_ci *
766425bb815Sopenharmony_ci * 0 <= index < argument_end                    : arguments
767425bb815Sopenharmony_ci * argument_end <= index < register_end         : registers
768425bb815Sopenharmony_ci * register_end <= index < ident_end            : identifiers
769425bb815Sopenharmony_ci * ident_end <= index < const_literal_end       : constant literals
770425bb815Sopenharmony_ci * const_literal_end <= index < literal_end     : template literals
771425bb815Sopenharmony_ci */
772425bb815Sopenharmony_ci
773425bb815Sopenharmony_ci/**
774425bb815Sopenharmony_ci * Compiled byte code arguments.
775425bb815Sopenharmony_ci */
776425bb815Sopenharmony_citypedef struct
777425bb815Sopenharmony_ci{
778425bb815Sopenharmony_ci  ecma_compiled_code_t header;      /**< compiled code header */
779425bb815Sopenharmony_ci  uint8_t stack_limit;              /**< maximum number of values stored on the stack */
780425bb815Sopenharmony_ci  uint8_t argument_end;             /**< number of arguments expected by the function */
781425bb815Sopenharmony_ci  uint8_t register_end;             /**< end position of the register group */
782425bb815Sopenharmony_ci  uint8_t ident_end;                /**< end position of the identifier group */
783425bb815Sopenharmony_ci  uint8_t const_literal_end;        /**< end position of the const literal group */
784425bb815Sopenharmony_ci  uint8_t literal_end;              /**< end position of the literal group */
785425bb815Sopenharmony_ci} cbc_uint8_arguments_t;
786425bb815Sopenharmony_ci
787425bb815Sopenharmony_ci/**
788425bb815Sopenharmony_ci * Compiled byte code arguments.
789425bb815Sopenharmony_ci */
790425bb815Sopenharmony_citypedef struct
791425bb815Sopenharmony_ci{
792425bb815Sopenharmony_ci  ecma_compiled_code_t header;      /**< compiled code header */
793425bb815Sopenharmony_ci  uint16_t stack_limit;             /**< maximum number of values stored on the stack */
794425bb815Sopenharmony_ci  uint16_t argument_end;            /**< number of arguments expected by the function */
795425bb815Sopenharmony_ci  uint16_t register_end;            /**< end position of the register group */
796425bb815Sopenharmony_ci  uint16_t ident_end;               /**< end position of the identifier group */
797425bb815Sopenharmony_ci  uint16_t const_literal_end;       /**< end position of the const literal group */
798425bb815Sopenharmony_ci  uint16_t literal_end;             /**< end position of the literal group */
799425bb815Sopenharmony_ci  uint16_t padding;                 /**< an unused value */
800425bb815Sopenharmony_ci} cbc_uint16_arguments_t;
801425bb815Sopenharmony_ci
802425bb815Sopenharmony_ci/**
803425bb815Sopenharmony_ci * Compact byte code status flags.
804425bb815Sopenharmony_ci */
805425bb815Sopenharmony_citypedef enum
806425bb815Sopenharmony_ci{
807425bb815Sopenharmony_ci  CBC_CODE_FLAGS_FUNCTION = (1u << 0), /**< compiled code is JavaScript function */
808425bb815Sopenharmony_ci  CBC_CODE_FLAGS_FULL_LITERAL_ENCODING = (1u << 1), /**< full literal encoding mode is enabled */
809425bb815Sopenharmony_ci  CBC_CODE_FLAGS_UINT16_ARGUMENTS = (1u << 2), /**< compiled code data is cbc_uint16_arguments_t */
810425bb815Sopenharmony_ci  CBC_CODE_FLAGS_STRICT_MODE = (1u << 3), /**< strict mode is enabled */
811425bb815Sopenharmony_ci  CBC_CODE_FLAGS_MAPPED_ARGUMENTS_NEEDED = (1u << 4), /**< mapped arguments object must be constructed */
812425bb815Sopenharmony_ci  CBC_CODE_FLAGS_UNMAPPED_ARGUMENTS_NEEDED = (1u << 5), /**< mapped arguments object must be constructed */
813425bb815Sopenharmony_ci  CBC_CODE_FLAGS_LEXICAL_ENV_NOT_NEEDED = (1u << 6), /**< no need to create a lexical environment */
814425bb815Sopenharmony_ci  CBC_CODE_FLAGS_ARROW_FUNCTION = (1u << 7), /**< this function is an arrow function */
815425bb815Sopenharmony_ci  CBC_CODE_FLAGS_STATIC_FUNCTION = (1u << 8), /**< this function is a static snapshot function */
816425bb815Sopenharmony_ci  CBC_CODE_FLAGS_DEBUGGER_IGNORE = (1u << 9), /**< this function should be ignored by debugger */
817425bb815Sopenharmony_ci  CBC_CODE_FLAGS_CLASS_CONSTRUCTOR = (1u << 10), /**< this function is a class constructor */
818425bb815Sopenharmony_ci  CBC_CODE_FLAGS_GENERATOR = (1u << 11), /**< this function is a generator */
819425bb815Sopenharmony_ci  CBC_CODE_FLAGS_REST_PARAMETER = (1u << 12), /**< this function has rest parameter */
820425bb815Sopenharmony_ci  CBC_CODE_FLAG_HAS_TAGGED_LITERALS = (1u << 13), /**< this function has tagged template literal list */
821425bb815Sopenharmony_ci  CBC_CODE_FLAGS_LEXICAL_BLOCK_NEEDED = (1u << 14), /**< compiled code needs a lexical block */
822425bb815Sopenharmony_ci  CBC_CODE_FLAGS_ACCESSOR = (1u << 15) /**< accessor propety 'get' and 'set' functions */
823425bb815Sopenharmony_ci} cbc_code_flags;
824425bb815Sopenharmony_ci
825425bb815Sopenharmony_ci/**
826425bb815Sopenharmony_ci * Any arguments object is needed
827425bb815Sopenharmony_ci */
828425bb815Sopenharmony_ci#define CBC_CODE_FLAGS_IS_ARGUMENTS_NEEDED \
829425bb815Sopenharmony_ci  (CBC_CODE_FLAGS_MAPPED_ARGUMENTS_NEEDED | CBC_CODE_FLAGS_UNMAPPED_ARGUMENTS_NEEDED)
830425bb815Sopenharmony_ci
831425bb815Sopenharmony_ci#define CBC_OPCODE(arg1, arg2, arg3, arg4) arg1,
832425bb815Sopenharmony_ci
833425bb815Sopenharmony_ci/**
834425bb815Sopenharmony_ci * Opcode list.
835425bb815Sopenharmony_ci */
836425bb815Sopenharmony_citypedef enum
837425bb815Sopenharmony_ci{
838425bb815Sopenharmony_ci  CBC_OPCODE_LIST      /**< list of opcodes */
839425bb815Sopenharmony_ci} cbc_opcode_t;
840425bb815Sopenharmony_ci
841425bb815Sopenharmony_ci/**
842425bb815Sopenharmony_ci * Extended opcode list.
843425bb815Sopenharmony_ci */
844425bb815Sopenharmony_citypedef enum
845425bb815Sopenharmony_ci{
846425bb815Sopenharmony_ci  CBC_EXT_OPCODE_LIST  /**< list extended opcodes */
847425bb815Sopenharmony_ci} cbc_ext_opcode_t;
848425bb815Sopenharmony_ci
849425bb815Sopenharmony_ci#undef CBC_OPCODE
850425bb815Sopenharmony_ci
851425bb815Sopenharmony_ci/**
852425bb815Sopenharmony_ci * Opcode flags.
853425bb815Sopenharmony_ci */
854425bb815Sopenharmony_ciextern const uint8_t cbc_flags[];
855425bb815Sopenharmony_ciextern const uint8_t cbc_ext_flags[];
856425bb815Sopenharmony_ci
857425bb815Sopenharmony_ci#if ENABLED (JERRY_PARSER_DUMP_BYTE_CODE)
858425bb815Sopenharmony_ci
859425bb815Sopenharmony_ci/**
860425bb815Sopenharmony_ci * Opcode names for debugging.
861425bb815Sopenharmony_ci */
862425bb815Sopenharmony_ciextern const char * const cbc_names[];
863425bb815Sopenharmony_ciextern const char * const cbc_ext_names[];
864425bb815Sopenharmony_ci
865425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_PARSER_DUMP_BYTE_CODE) */
866425bb815Sopenharmony_ci
867425bb815Sopenharmony_ci/**
868425bb815Sopenharmony_ci * @}
869425bb815Sopenharmony_ci * @}
870425bb815Sopenharmony_ci * @}
871425bb815Sopenharmony_ci */
872425bb815Sopenharmony_ci
873425bb815Sopenharmony_ci#endif /* !BYTE_CODE_H */
874