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 VM_H 17425bb815Sopenharmony_ci#define VM_H 18425bb815Sopenharmony_ci 19425bb815Sopenharmony_ci#include "ecma-globals.h" 20425bb815Sopenharmony_ci#include "jrt.h" 21425bb815Sopenharmony_ci#include "vm-defines.h" 22425bb815Sopenharmony_ci 23425bb815Sopenharmony_ci/** \addtogroup vm Virtual machine 24425bb815Sopenharmony_ci * @{ 25425bb815Sopenharmony_ci * 26425bb815Sopenharmony_ci * \addtogroup vm_executor Executor 27425bb815Sopenharmony_ci * @{ 28425bb815Sopenharmony_ci */ 29425bb815Sopenharmony_ci 30425bb815Sopenharmony_ci/** 31425bb815Sopenharmony_ci * Each CBC opcode is transformed to three vm opcodes: 32425bb815Sopenharmony_ci * 33425bb815Sopenharmony_ci * - first opcode is a "get arguments" opcode which specifies 34425bb815Sopenharmony_ci * the type (register, literal, stack, etc.) and number 35425bb815Sopenharmony_ci * (from 0 to 2) of input arguments 36425bb815Sopenharmony_ci * - second opcode is a "group" opcode which specifies 37425bb815Sopenharmony_ci * the actual operation (add, increment, call, etc.) 38425bb815Sopenharmony_ci * - third opcode is a "put result" opcode which specifies 39425bb815Sopenharmony_ci * the destination where the result is stored (register, 40425bb815Sopenharmony_ci * stack, etc.) 41425bb815Sopenharmony_ci */ 42425bb815Sopenharmony_ci 43425bb815Sopenharmony_ci/** 44425bb815Sopenharmony_ci * If VM_OC_GET_ARGS_INDEX(opcode) == VM_OC_GET_BRANCH, 45425bb815Sopenharmony_ci * this flag signals that the branch is a backward branch. 46425bb815Sopenharmony_ci */ 47425bb815Sopenharmony_ci#define VM_OC_BACKWARD_BRANCH (1 << 15) 48425bb815Sopenharmony_ci 49425bb815Sopenharmony_ci/** 50425bb815Sopenharmony_ci * Position of "get arguments" opcode. 51425bb815Sopenharmony_ci */ 52425bb815Sopenharmony_ci#define VM_OC_GET_ARGS_SHIFT 8 53425bb815Sopenharmony_ci 54425bb815Sopenharmony_ci/** 55425bb815Sopenharmony_ci * Mask of "get arguments" opcode. 56425bb815Sopenharmony_ci */ 57425bb815Sopenharmony_ci#define VM_OC_GET_ARGS_MASK 0x7 58425bb815Sopenharmony_ci 59425bb815Sopenharmony_ci/** 60425bb815Sopenharmony_ci * Generate the binary representation of a "get arguments" opcode. 61425bb815Sopenharmony_ci */ 62425bb815Sopenharmony_ci#define VM_OC_GET_ARGS_CREATE_INDEX(V) (((V) & VM_OC_GET_ARGS_MASK) << VM_OC_GET_ARGS_SHIFT) 63425bb815Sopenharmony_ci 64425bb815Sopenharmony_ci/** 65425bb815Sopenharmony_ci * Extract the "get arguments" opcode. 66425bb815Sopenharmony_ci */ 67425bb815Sopenharmony_ci#define VM_OC_GET_ARGS_INDEX(O) ((O) & (VM_OC_GET_ARGS_MASK << VM_OC_GET_ARGS_SHIFT)) 68425bb815Sopenharmony_ci 69425bb815Sopenharmony_ci/** 70425bb815Sopenharmony_ci * Checks whether the result is stored somewhere. 71425bb815Sopenharmony_ci */ 72425bb815Sopenharmony_ci#define VM_OC_HAS_GET_ARGS(V) ((V) & (VM_OC_GET_ARGS_MASK << VM_OC_GET_ARGS_SHIFT)) 73425bb815Sopenharmony_ci 74425bb815Sopenharmony_ci/** 75425bb815Sopenharmony_ci * Argument getters that are part of the opcodes. 76425bb815Sopenharmony_ci */ 77425bb815Sopenharmony_citypedef enum 78425bb815Sopenharmony_ci{ 79425bb815Sopenharmony_ci VM_OC_GET_NONE = VM_OC_GET_ARGS_CREATE_INDEX (0), /**< do nothing */ 80425bb815Sopenharmony_ci VM_OC_GET_BRANCH = VM_OC_GET_ARGS_CREATE_INDEX (1), /**< branch argument */ 81425bb815Sopenharmony_ci VM_OC_GET_STACK = VM_OC_GET_ARGS_CREATE_INDEX (2), /**< pop one element from the stack */ 82425bb815Sopenharmony_ci VM_OC_GET_STACK_STACK = VM_OC_GET_ARGS_CREATE_INDEX (3), /**< pop two elements from the stack */ 83425bb815Sopenharmony_ci 84425bb815Sopenharmony_ci VM_OC_GET_LITERAL = VM_OC_GET_ARGS_CREATE_INDEX (4), /**< resolve literal */ 85425bb815Sopenharmony_ci VM_OC_GET_LITERAL_LITERAL = VM_OC_GET_ARGS_CREATE_INDEX (5), /**< resolve two literals */ 86425bb815Sopenharmony_ci VM_OC_GET_STACK_LITERAL = VM_OC_GET_ARGS_CREATE_INDEX (6), /**< pop one element from the stack 87425bb815Sopenharmony_ci * and resolve a literal */ 88425bb815Sopenharmony_ci VM_OC_GET_THIS_LITERAL = VM_OC_GET_ARGS_CREATE_INDEX (7), /**< get this and resolve a literal */ 89425bb815Sopenharmony_ci} vm_oc_get_types; 90425bb815Sopenharmony_ci 91425bb815Sopenharmony_ci/** 92425bb815Sopenharmony_ci * Mask of "group" opcode. 93425bb815Sopenharmony_ci */ 94425bb815Sopenharmony_ci#define VM_OC_GROUP_MASK 0xff 95425bb815Sopenharmony_ci 96425bb815Sopenharmony_ci/** 97425bb815Sopenharmony_ci * Extract the "group" opcode. 98425bb815Sopenharmony_ci */ 99425bb815Sopenharmony_ci#define VM_OC_GROUP_GET_INDEX(O) ((O) & VM_OC_GROUP_MASK) 100425bb815Sopenharmony_ci 101425bb815Sopenharmony_ci/** 102425bb815Sopenharmony_ci * Opcodes. 103425bb815Sopenharmony_ci */ 104425bb815Sopenharmony_citypedef enum 105425bb815Sopenharmony_ci{ 106425bb815Sopenharmony_ci VM_OC_POP, /**< pop from stack */ 107425bb815Sopenharmony_ci VM_OC_POP_BLOCK, /**< pop block */ 108425bb815Sopenharmony_ci VM_OC_PUSH, /**< push one literal */ 109425bb815Sopenharmony_ci VM_OC_PUSH_TWO, /**< push two literals */ 110425bb815Sopenharmony_ci VM_OC_PUSH_THREE, /**< push three literals */ 111425bb815Sopenharmony_ci VM_OC_PUSH_UNDEFINED, /**< push undefined value */ 112425bb815Sopenharmony_ci VM_OC_PUSH_TRUE, /**< push true value */ 113425bb815Sopenharmony_ci VM_OC_PUSH_FALSE, /**< push false value */ 114425bb815Sopenharmony_ci VM_OC_PUSH_NULL, /**< push null value */ 115425bb815Sopenharmony_ci VM_OC_PUSH_THIS, /**< push this */ 116425bb815Sopenharmony_ci VM_OC_PUSH_0, /**< push number zero */ 117425bb815Sopenharmony_ci VM_OC_PUSH_POS_BYTE, /**< push number between 1 and 256 */ 118425bb815Sopenharmony_ci VM_OC_PUSH_NEG_BYTE, /**< push number between -1 and -256 */ 119425bb815Sopenharmony_ci VM_OC_PUSH_LIT_0, /**< push literal and number zero */ 120425bb815Sopenharmony_ci VM_OC_PUSH_LIT_POS_BYTE, /**< push literal and number between 1 and 256 */ 121425bb815Sopenharmony_ci VM_OC_PUSH_LIT_NEG_BYTE, /**< push literal and number between -1 and -256 */ 122425bb815Sopenharmony_ci VM_OC_PUSH_OBJECT, /**< push object */ 123425bb815Sopenharmony_ci VM_OC_PUSH_NAMED_FUNC_EXPR, /**< push named function expression */ 124425bb815Sopenharmony_ci VM_OC_SET_PROPERTY, /**< set property */ 125425bb815Sopenharmony_ci 126425bb815Sopenharmony_ci VM_OC_SET_GETTER, /**< set getter */ 127425bb815Sopenharmony_ci VM_OC_SET_SETTER, /**< set setter */ 128425bb815Sopenharmony_ci VM_OC_PUSH_ARRAY, /**< push array */ 129425bb815Sopenharmony_ci VM_OC_PUSH_ELISON, /**< push elison */ 130425bb815Sopenharmony_ci VM_OC_APPEND_ARRAY, /**< append array */ 131425bb815Sopenharmony_ci VM_OC_IDENT_REFERENCE, /**< ident reference */ 132425bb815Sopenharmony_ci VM_OC_PROP_REFERENCE, /**< prop reference */ 133425bb815Sopenharmony_ci VM_OC_PROP_GET, /**< prop get */ 134425bb815Sopenharmony_ci 135425bb815Sopenharmony_ci /* These eight opcodes must be in this order. */ 136425bb815Sopenharmony_ci VM_OC_PROP_PRE_INCR, /**< prefix increment of a property */ 137425bb815Sopenharmony_ci VM_OC_PROP_PRE_DECR, /**< prop prefix decrement of a property */ 138425bb815Sopenharmony_ci VM_OC_PROP_POST_INCR, /**< prop postfix increment of a property */ 139425bb815Sopenharmony_ci VM_OC_PROP_POST_DECR, /**< prop postfix decrement of a property */ 140425bb815Sopenharmony_ci VM_OC_PRE_INCR, /**< prefix increment */ 141425bb815Sopenharmony_ci VM_OC_PRE_DECR, /**< prefix decrement */ 142425bb815Sopenharmony_ci VM_OC_POST_INCR, /**< postfix increment */ 143425bb815Sopenharmony_ci VM_OC_POST_DECR, /**< postfix decrement */ 144425bb815Sopenharmony_ci 145425bb815Sopenharmony_ci VM_OC_PROP_DELETE, /**< delete property */ 146425bb815Sopenharmony_ci VM_OC_DELETE, /**< delete */ 147425bb815Sopenharmony_ci 148425bb815Sopenharmony_ci VM_OC_MOV_IDENT, /**< move identifier register reference */ 149425bb815Sopenharmony_ci VM_OC_ASSIGN, /**< assign */ 150425bb815Sopenharmony_ci VM_OC_ASSIGN_PROP, /**< assign property */ 151425bb815Sopenharmony_ci VM_OC_ASSIGN_PROP_THIS, /**< assign prop this */ 152425bb815Sopenharmony_ci 153425bb815Sopenharmony_ci VM_OC_RETURN, /**< return */ 154425bb815Sopenharmony_ci VM_OC_THROW, /**< throw */ 155425bb815Sopenharmony_ci VM_OC_THROW_REFERENCE_ERROR, /**< throw reference error */ 156425bb815Sopenharmony_ci 157425bb815Sopenharmony_ci VM_OC_EVAL, /**< eval */ 158425bb815Sopenharmony_ci VM_OC_CALL, /**< call */ 159425bb815Sopenharmony_ci VM_OC_NEW, /**< new */ 160425bb815Sopenharmony_ci VM_OC_RESOLVE_BASE_FOR_CALL, /**< resolve base value before call */ 161425bb815Sopenharmony_ci VM_OC_ERROR, /**< error while the vm_loop is suspended */ 162425bb815Sopenharmony_ci 163425bb815Sopenharmony_ci VM_OC_JUMP, /**< jump */ 164425bb815Sopenharmony_ci VM_OC_BRANCH_IF_STRICT_EQUAL, /**< branch if strict equal */ 165425bb815Sopenharmony_ci 166425bb815Sopenharmony_ci /* These four opcodes must be in this order. */ 167425bb815Sopenharmony_ci VM_OC_BRANCH_IF_TRUE, /**< branch if true */ 168425bb815Sopenharmony_ci VM_OC_BRANCH_IF_FALSE, /**< branch if false */ 169425bb815Sopenharmony_ci VM_OC_BRANCH_IF_LOGICAL_TRUE, /**< branch if logical true */ 170425bb815Sopenharmony_ci VM_OC_BRANCH_IF_LOGICAL_FALSE, /**< branch if logical false */ 171425bb815Sopenharmony_ci 172425bb815Sopenharmony_ci VM_OC_PLUS, /**< unary plus */ 173425bb815Sopenharmony_ci VM_OC_MINUS, /**< unary minus */ 174425bb815Sopenharmony_ci VM_OC_NOT, /**< not */ 175425bb815Sopenharmony_ci VM_OC_BIT_NOT, /**< bitwise not */ 176425bb815Sopenharmony_ci VM_OC_VOID, /**< void */ 177425bb815Sopenharmony_ci VM_OC_TYPEOF_IDENT, /**< typeof identifier */ 178425bb815Sopenharmony_ci VM_OC_TYPEOF, /**< typeof */ 179425bb815Sopenharmony_ci 180425bb815Sopenharmony_ci VM_OC_ADD, /**< binary add */ 181425bb815Sopenharmony_ci VM_OC_SUB, /**< binary sub */ 182425bb815Sopenharmony_ci VM_OC_MUL, /**< mul */ 183425bb815Sopenharmony_ci VM_OC_DIV, /**< div */ 184425bb815Sopenharmony_ci VM_OC_MOD, /**< mod */ 185425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015) 186425bb815Sopenharmony_ci VM_OC_EXP, /**< exponentiation */ 187425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */ 188425bb815Sopenharmony_ci 189425bb815Sopenharmony_ci VM_OC_EQUAL, /**< equal */ 190425bb815Sopenharmony_ci VM_OC_NOT_EQUAL, /**< not equal */ 191425bb815Sopenharmony_ci VM_OC_STRICT_EQUAL, /**< strict equal */ 192425bb815Sopenharmony_ci VM_OC_STRICT_NOT_EQUAL, /**< strict not equal */ 193425bb815Sopenharmony_ci VM_OC_LESS, /**< less */ 194425bb815Sopenharmony_ci VM_OC_GREATER, /**< greater */ 195425bb815Sopenharmony_ci VM_OC_LESS_EQUAL, /**< less equal */ 196425bb815Sopenharmony_ci VM_OC_GREATER_EQUAL, /**< greater equal */ 197425bb815Sopenharmony_ci VM_OC_IN, /**< in */ 198425bb815Sopenharmony_ci VM_OC_INSTANCEOF, /**< instanceof */ 199425bb815Sopenharmony_ci 200425bb815Sopenharmony_ci VM_OC_BIT_OR, /**< bitwise or */ 201425bb815Sopenharmony_ci VM_OC_BIT_XOR, /**< bitwise xor */ 202425bb815Sopenharmony_ci VM_OC_BIT_AND, /**< bitwise and */ 203425bb815Sopenharmony_ci VM_OC_LEFT_SHIFT, /**< left shift */ 204425bb815Sopenharmony_ci VM_OC_RIGHT_SHIFT, /**< right shift */ 205425bb815Sopenharmony_ci VM_OC_UNS_RIGHT_SHIFT, /**< unsigned right shift */ 206425bb815Sopenharmony_ci 207425bb815Sopenharmony_ci VM_OC_BLOCK_CREATE_CONTEXT, /**< create lexical environment for blocks enclosed in braces */ 208425bb815Sopenharmony_ci VM_OC_WITH, /**< with */ 209425bb815Sopenharmony_ci VM_OC_FOR_IN_CREATE_CONTEXT, /**< for in create context */ 210425bb815Sopenharmony_ci VM_OC_FOR_IN_GET_NEXT, /**< get next */ 211425bb815Sopenharmony_ci VM_OC_FOR_IN_HAS_NEXT, /**< has next */ 212425bb815Sopenharmony_ci 213425bb815Sopenharmony_ci VM_OC_TRY, /**< try */ 214425bb815Sopenharmony_ci VM_OC_CATCH, /**< catch */ 215425bb815Sopenharmony_ci VM_OC_FINALLY, /**< finally */ 216425bb815Sopenharmony_ci VM_OC_CONTEXT_END, /**< context end */ 217425bb815Sopenharmony_ci VM_OC_JUMP_AND_EXIT_CONTEXT, /**< jump and exit context */ 218425bb815Sopenharmony_ci 219425bb815Sopenharmony_ci VM_OC_CREATE_BINDING, /**< create variables */ 220425bb815Sopenharmony_ci VM_OC_SET_BYTECODE_PTR, /**< setting bytecode pointer */ 221425bb815Sopenharmony_ci VM_OC_VAR_EVAL, /**< variable and function evaluation */ 222425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015) 223425bb815Sopenharmony_ci VM_OC_EXT_VAR_EVAL, /**< variable and function evaluation for 224425bb815Sopenharmony_ci * functions with separate argument context */ 225425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */ 226425bb815Sopenharmony_ci VM_OC_INIT_ARG_OR_FUNC, /**< create and init a function or argument binding */ 227425bb815Sopenharmony_ci 228425bb815Sopenharmony_ci#if ENABLED (JERRY_DEBUGGER) 229425bb815Sopenharmony_ci VM_OC_BREAKPOINT_ENABLED, /**< enabled breakpoint for debugger */ 230425bb815Sopenharmony_ci VM_OC_BREAKPOINT_DISABLED, /**< disabled breakpoint for debugger */ 231425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_DEBUGGER) */ 232425bb815Sopenharmony_ci#if ENABLED (JERRY_LINE_INFO) || ENABLED (JERRY_ES2015_MODULE_SYSTEM) 233425bb815Sopenharmony_ci VM_OC_RESOURCE_NAME, /**< resource name of the current function */ 234425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_LINE_INFO) || ENABLED (JERRY_ES2015_MODULE_SYSTEM) */ 235425bb815Sopenharmony_ci#if ENABLED (JERRY_LINE_INFO) 236425bb815Sopenharmony_ci VM_OC_LINE, /**< line number of the next statement */ 237425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_LINE_INFO) */ 238425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015) 239425bb815Sopenharmony_ci VM_OC_CHECK_VAR, /**< check redeclared vars in the global scope */ 240425bb815Sopenharmony_ci VM_OC_CHECK_LET, /**< check redeclared lets in the global scope */ 241425bb815Sopenharmony_ci VM_OC_ASSIGN_LET_CONST, /**< assign values to let/const declarations */ 242425bb815Sopenharmony_ci VM_OC_INIT_BINDING, /**< create and intialize a binding */ 243425bb815Sopenharmony_ci VM_OC_THROW_CONST_ERROR, /**< throw invalid assignment to const variable error */ 244425bb815Sopenharmony_ci VM_OC_COPY_TO_GLOBAL, /**< copy value to global lex env */ 245425bb815Sopenharmony_ci VM_OC_COPY_FROM_ARG, /**< copy value from arg lex env */ 246425bb815Sopenharmony_ci VM_OC_CLONE_CONTEXT, /**< clone lexical environment with let/const declarations */ 247425bb815Sopenharmony_ci VM_OC_SET_COMPUTED_PROPERTY, /**< set computed property */ 248425bb815Sopenharmony_ci 249425bb815Sopenharmony_ci VM_OC_FOR_OF_CREATE_CONTEXT, /**< for of create context */ 250425bb815Sopenharmony_ci VM_OC_FOR_OF_GET_NEXT, /**< get next */ 251425bb815Sopenharmony_ci VM_OC_FOR_OF_HAS_NEXT, /**< has next */ 252425bb815Sopenharmony_ci 253425bb815Sopenharmony_ci VM_OC_LOCAL_EVAL, /**< eval in local context */ 254425bb815Sopenharmony_ci VM_OC_SUPER_CALL, /**< call the 'super' constructor */ 255425bb815Sopenharmony_ci VM_OC_PUSH_CLASS_ENVIRONMENT, /**< push class environment */ 256425bb815Sopenharmony_ci VM_OC_PUSH_IMPLICIT_CTOR, /**< create implicit class constructor */ 257425bb815Sopenharmony_ci VM_OC_INIT_CLASS, /**< initialize class */ 258425bb815Sopenharmony_ci VM_OC_FINALIZE_CLASS, /**< finalize class */ 259425bb815Sopenharmony_ci VM_OC_PUSH_SUPER_CONSTRUCTOR, /**< getSuperConstructor operation */ 260425bb815Sopenharmony_ci VM_OC_RESOLVE_LEXICAL_THIS, /**< resolve this_binding from from the lexical environment */ 261425bb815Sopenharmony_ci VM_OC_SUPER_REFERENCE, /**< push super reference */ 262425bb815Sopenharmony_ci 263425bb815Sopenharmony_ci VM_OC_PUSH_SPREAD_ELEMENT, /**< push spread element */ 264425bb815Sopenharmony_ci VM_OC_GET_ITERATOR, /**< GetIterator abstract operation */ 265425bb815Sopenharmony_ci VM_OC_ITERATOR_STEP, /**< IteratorStep abstract operation */ 266425bb815Sopenharmony_ci VM_OC_ITERATOR_CLOSE, /**< IteratorClose abstract operation */ 267425bb815Sopenharmony_ci VM_OC_DEFAULT_INITIALIZER, /**< default initializer inside a pattern */ 268425bb815Sopenharmony_ci VM_OC_REST_INITIALIZER, /**< create rest object inside an array pattern */ 269425bb815Sopenharmony_ci VM_OC_INITIALIZER_PUSH_PROP, /**< push property for object initializer */ 270425bb815Sopenharmony_ci VM_OC_SPREAD_ARGUMENTS, /**< perform function call/construct with spreaded arguments */ 271425bb815Sopenharmony_ci VM_OC_CREATE_GENERATOR, /**< create a generator object */ 272425bb815Sopenharmony_ci VM_OC_YIELD, /**< yield operation */ 273425bb815Sopenharmony_ci VM_OC_AWAIT, /**< await operation */ 274425bb815Sopenharmony_ci VM_OC_EXT_RETURN, /**< return which also clears the stack */ 275425bb815Sopenharmony_ci VM_OC_RETURN_PROMISE, /**< return from an async function */ 276425bb815Sopenharmony_ci VM_OC_STRING_CONCAT, /**< string concatenation */ 277425bb815Sopenharmony_ci VM_OC_GET_TEMPLATE_OBJECT, /**< GetTemplateObject operation */ 278425bb815Sopenharmony_ci VM_OC_PUSH_NEW_TARGET, /**< push new.target onto the stack */ 279425bb815Sopenharmony_ci VM_OC_REQUIRE_OBJECT_COERCIBLE,/**< RequireObjectCoercible opretaion */ 280425bb815Sopenharmony_ci VM_OC_ASSIGN_SUPER, /**< assign super reference */ 281425bb815Sopenharmony_ci VM_OC_SET__PROTO__, /**< set prototpe when __proto__: form is used */ 282425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */ 283425bb815Sopenharmony_ci VM_OC_NONE, /**< a special opcode for unsupported byte codes */ 284425bb815Sopenharmony_ci} vm_oc_types; 285425bb815Sopenharmony_ci 286425bb815Sopenharmony_ci/** 287425bb815Sopenharmony_ci * Unused opcodes, but required by byte-code types. 288425bb815Sopenharmony_ci */ 289425bb815Sopenharmony_citypedef enum 290425bb815Sopenharmony_ci{ 291425bb815Sopenharmony_ci#if !ENABLED (JERRY_ES2015) 292425bb815Sopenharmony_ci VM_OC_EXP = VM_OC_NONE, /**< exponentiation */ 293425bb815Sopenharmony_ci#endif /* !ENABLED (JERRY_ES2015) */ 294425bb815Sopenharmony_ci#if !ENABLED (JERRY_DEBUGGER) 295425bb815Sopenharmony_ci VM_OC_BREAKPOINT_ENABLED = VM_OC_NONE, /**< enabled breakpoint for debugger is unused */ 296425bb815Sopenharmony_ci VM_OC_BREAKPOINT_DISABLED = VM_OC_NONE, /**< disabled breakpoint for debugger is unused */ 297425bb815Sopenharmony_ci#endif /* !ENABLED (JERRY_DEBUGGER) */ 298425bb815Sopenharmony_ci#if !ENABLED (JERRY_LINE_INFO) && !ENABLED (JERRY_ES2015_MODULE_SYSTEM) 299425bb815Sopenharmony_ci VM_OC_RESOURCE_NAME = VM_OC_NONE, /**< resource name of the current function is unused */ 300425bb815Sopenharmony_ci#endif /* !ENABLED (JERRY_LINE_INFO) && !ENABLED (JERRY_ES2015_MODULE_SYSTEM) */ 301425bb815Sopenharmony_ci#if !ENABLED (JERRY_LINE_INFO) 302425bb815Sopenharmony_ci VM_OC_LINE = VM_OC_NONE, /**< line number of the next statement is unused */ 303425bb815Sopenharmony_ci#endif /* !ENABLED (JERRY_LINE_INFO) */ 304425bb815Sopenharmony_ci#if !ENABLED (JERRY_ES2015) 305425bb815Sopenharmony_ci VM_OC_EXT_VAR_EVAL = VM_OC_NONE, /**< variable and function evaluation for 306425bb815Sopenharmony_ci * functions with separate argument context */ 307425bb815Sopenharmony_ci VM_OC_CHECK_VAR = VM_OC_NONE, /**< check redeclared vars in the global scope */ 308425bb815Sopenharmony_ci VM_OC_CHECK_LET = VM_OC_NONE, /**< check redeclared lets in the global scope */ 309425bb815Sopenharmony_ci VM_OC_ASSIGN_LET_CONST = VM_OC_NONE, /**< assign values to let/const declarations */ 310425bb815Sopenharmony_ci VM_OC_INIT_BINDING = VM_OC_NONE, /**< create and intialize a binding */ 311425bb815Sopenharmony_ci VM_OC_THROW_CONST_ERROR = VM_OC_NONE, /**< throw invalid assignment to const variable error */ 312425bb815Sopenharmony_ci VM_OC_COPY_TO_GLOBAL = VM_OC_NONE, /**< copy value to global lex env */ 313425bb815Sopenharmony_ci VM_OC_COPY_FROM_ARG = VM_OC_NONE, /**< copy value from arg lex env */ 314425bb815Sopenharmony_ci VM_OC_CLONE_CONTEXT = VM_OC_NONE, /**< clone lexical environment with let/const declarations */ 315425bb815Sopenharmony_ci VM_OC_SET_COMPUTED_PROPERTY = VM_OC_NONE, /**< set computed property is unused */ 316425bb815Sopenharmony_ci 317425bb815Sopenharmony_ci VM_OC_FOR_OF_CREATE_CONTEXT = VM_OC_NONE, /**< for of create context */ 318425bb815Sopenharmony_ci VM_OC_FOR_OF_GET_NEXT = VM_OC_NONE, /**< get next */ 319425bb815Sopenharmony_ci VM_OC_FOR_OF_HAS_NEXT = VM_OC_NONE, /**< has next */ 320425bb815Sopenharmony_ci 321425bb815Sopenharmony_ci VM_OC_LOCAL_EVAL = VM_OC_NONE, /**< eval in local context */ 322425bb815Sopenharmony_ci VM_OC_SUPER_CALL = VM_OC_NONE, /**< call the 'super' constructor */ 323425bb815Sopenharmony_ci VM_OC_PUSH_CLASS_ENVIRONMENT = VM_OC_NONE, /**< push class environment */ 324425bb815Sopenharmony_ci VM_OC_PUSH_IMPLICIT_CTOR = VM_OC_NONE, /**< create implicit class constructor */ 325425bb815Sopenharmony_ci VM_OC_INIT_CLASS = VM_OC_NONE, /**< initialize class */ 326425bb815Sopenharmony_ci VM_OC_FINALIZE_CLASS = VM_OC_NONE, /**< finalize class */ 327425bb815Sopenharmony_ci VM_OC_PUSH_SUPER_CONSTRUCTOR = VM_OC_NONE, /**< getSuperConstructor operation */ 328425bb815Sopenharmony_ci VM_OC_RESOLVE_LEXICAL_THIS = VM_OC_NONE, /**< resolve this_binding from from the lexical environment */ 329425bb815Sopenharmony_ci VM_OC_SUPER_REFERENCE = VM_OC_NONE, /**< push super reference */ 330425bb815Sopenharmony_ci 331425bb815Sopenharmony_ci VM_OC_PUSH_SPREAD_ELEMENT = VM_OC_NONE, /**< push spread element */ 332425bb815Sopenharmony_ci VM_OC_GET_ITERATOR = VM_OC_NONE, /**< GetIterator abstract operation */ 333425bb815Sopenharmony_ci VM_OC_ITERATOR_STEP = VM_OC_NONE, /**< IteratorStep abstract operation */ 334425bb815Sopenharmony_ci VM_OC_ITERATOR_CLOSE = VM_OC_NONE, /**< IteratorClose abstract operation */ 335425bb815Sopenharmony_ci VM_OC_DEFAULT_INITIALIZER = VM_OC_NONE, /**< default initializer inside a pattern */ 336425bb815Sopenharmony_ci VM_OC_REST_INITIALIZER = VM_OC_NONE, /**< create rest object inside an array pattern */ 337425bb815Sopenharmony_ci VM_OC_INITIALIZER_PUSH_PROP = VM_OC_NONE, /**< push property for object initializer */ 338425bb815Sopenharmony_ci VM_OC_SPREAD_ARGUMENTS = VM_OC_NONE, /**< perform function call/construct with spreaded arguments */ 339425bb815Sopenharmony_ci VM_OC_CREATE_GENERATOR = VM_OC_NONE, /**< create a generator object */ 340425bb815Sopenharmony_ci VM_OC_YIELD = VM_OC_NONE, /**< yield operation */ 341425bb815Sopenharmony_ci VM_OC_AWAIT = VM_OC_NONE, /**< await operation */ 342425bb815Sopenharmony_ci VM_OC_EXT_RETURN = VM_OC_NONE, /**< return which also clears the stack */ 343425bb815Sopenharmony_ci VM_OC_RETURN_PROMISE = VM_OC_NONE, /**< return from an async function */ 344425bb815Sopenharmony_ci VM_OC_STRING_CONCAT = VM_OC_NONE, /**< string concatenation */ 345425bb815Sopenharmony_ci VM_OC_GET_TEMPLATE_OBJECT = VM_OC_NONE, /**< GetTemplateObject operation */ 346425bb815Sopenharmony_ci VM_OC_PUSH_NEW_TARGET = VM_OC_NONE, /**< push new.target onto the stack */ 347425bb815Sopenharmony_ci VM_OC_REQUIRE_OBJECT_COERCIBLE = VM_OC_NONE,/**< RequireObjectCoercible opretaion */ 348425bb815Sopenharmony_ci VM_OC_ASSIGN_SUPER = VM_OC_NONE, /**< assign super reference */ 349425bb815Sopenharmony_ci VM_OC_SET__PROTO__ = VM_OC_NONE, /**< set prototpe when __proto__: form is used */ 350425bb815Sopenharmony_ci#endif /* !ENABLED (JERRY_ES2015) */ 351425bb815Sopenharmony_ci 352425bb815Sopenharmony_ci VM_OC_UNUSED = VM_OC_NONE /**< placeholder if the list is empty */ 353425bb815Sopenharmony_ci} vm_oc_unused_types; 354425bb815Sopenharmony_ci 355425bb815Sopenharmony_ci/** 356425bb815Sopenharmony_ci * Decrement operator. 357425bb815Sopenharmony_ci */ 358425bb815Sopenharmony_ci#define VM_OC_DECREMENT_OPERATOR_FLAG 0x1 359425bb815Sopenharmony_ci 360425bb815Sopenharmony_ci/** 361425bb815Sopenharmony_ci * Postfix increment/decrement operator. 362425bb815Sopenharmony_ci */ 363425bb815Sopenharmony_ci#define VM_OC_POST_INCR_DECR_OPERATOR_FLAG 0x2 364425bb815Sopenharmony_ci 365425bb815Sopenharmony_ci/** 366425bb815Sopenharmony_ci * An named variable is updated by the increment/decrement operator. 367425bb815Sopenharmony_ci */ 368425bb815Sopenharmony_ci#define VM_OC_IDENT_INCR_DECR_OPERATOR_FLAG 0x4 369425bb815Sopenharmony_ci 370425bb815Sopenharmony_ci/** 371425bb815Sopenharmony_ci * Jump to target offset if input value is logical false. 372425bb815Sopenharmony_ci */ 373425bb815Sopenharmony_ci#define VM_OC_BRANCH_IF_FALSE_FLAG 0x1 374425bb815Sopenharmony_ci 375425bb815Sopenharmony_ci/** 376425bb815Sopenharmony_ci * Branch optimized for logical and/or opcodes. 377425bb815Sopenharmony_ci */ 378425bb815Sopenharmony_ci#define VM_OC_LOGICAL_BRANCH_FLAG 0x2 379425bb815Sopenharmony_ci 380425bb815Sopenharmony_ci/** 381425bb815Sopenharmony_ci * Bit index shift for non-static property initializers. 382425bb815Sopenharmony_ci */ 383425bb815Sopenharmony_ci#define VM_OC_NON_STATIC_SHIFT 15 384425bb815Sopenharmony_ci 385425bb815Sopenharmony_ci/** 386425bb815Sopenharmony_ci * This flag is set for static property initializers. 387425bb815Sopenharmony_ci */ 388425bb815Sopenharmony_ci#define VM_OC_NON_STATIC_FLAG (0x1 << VM_OC_NON_STATIC_SHIFT) 389425bb815Sopenharmony_ci 390425bb815Sopenharmony_ci/** 391425bb815Sopenharmony_ci * Position of "put result" opcode. 392425bb815Sopenharmony_ci */ 393425bb815Sopenharmony_ci#define VM_OC_PUT_RESULT_SHIFT 11 394425bb815Sopenharmony_ci 395425bb815Sopenharmony_ci/** 396425bb815Sopenharmony_ci * Mask of "put result" opcode. 397425bb815Sopenharmony_ci */ 398425bb815Sopenharmony_ci#define VM_OC_PUT_RESULT_MASK 0xf 399425bb815Sopenharmony_ci 400425bb815Sopenharmony_ci/** 401425bb815Sopenharmony_ci * Generate a "put result" opcode flag bit. 402425bb815Sopenharmony_ci */ 403425bb815Sopenharmony_ci#define VM_OC_PUT_RESULT_CREATE_FLAG(V) (((V) & VM_OC_PUT_RESULT_MASK) << VM_OC_PUT_RESULT_SHIFT) 404425bb815Sopenharmony_ci 405425bb815Sopenharmony_ci/** 406425bb815Sopenharmony_ci * Checks whether the result is stored somewhere. 407425bb815Sopenharmony_ci */ 408425bb815Sopenharmony_ci#define VM_OC_HAS_PUT_RESULT(V) ((V) & (VM_OC_PUT_RESULT_MASK << VM_OC_PUT_RESULT_SHIFT)) 409425bb815Sopenharmony_ci 410425bb815Sopenharmony_ci/** 411425bb815Sopenharmony_ci * Specify where the result is stored 412425bb815Sopenharmony_ci */ 413425bb815Sopenharmony_citypedef enum 414425bb815Sopenharmony_ci{ 415425bb815Sopenharmony_ci VM_OC_PUT_IDENT = VM_OC_PUT_RESULT_CREATE_FLAG (0x1), 416425bb815Sopenharmony_ci VM_OC_PUT_REFERENCE = VM_OC_PUT_RESULT_CREATE_FLAG (0x2), 417425bb815Sopenharmony_ci VM_OC_PUT_STACK = VM_OC_PUT_RESULT_CREATE_FLAG (0x4), 418425bb815Sopenharmony_ci VM_OC_PUT_BLOCK = VM_OC_PUT_RESULT_CREATE_FLAG (0x8), 419425bb815Sopenharmony_ci} vm_oc_put_types; 420425bb815Sopenharmony_ci 421425bb815Sopenharmony_ci/** 422425bb815Sopenharmony_ci * Non-recursive vm_loop: the vm_loop can be suspended 423425bb815Sopenharmony_ci * to execute a call /construct operation. These return 424425bb815Sopenharmony_ci * types of the vm_loop tells whether a call operation 425425bb815Sopenharmony_ci * is in progress or the vm_loop is finished. 426425bb815Sopenharmony_ci */ 427425bb815Sopenharmony_citypedef enum 428425bb815Sopenharmony_ci{ 429425bb815Sopenharmony_ci VM_NO_EXEC_OP, /**< do nothing */ 430425bb815Sopenharmony_ci VM_EXEC_CALL, /**< invoke a function */ 431425bb815Sopenharmony_ci VM_EXEC_SUPER_CALL, /**< invoke a function through 'super' keyword */ 432425bb815Sopenharmony_ci VM_EXEC_SPREAD_OP, /**< call/construct operation with spreaded argument list */ 433425bb815Sopenharmony_ci VM_EXEC_RETURN, /**< return with the completion value without freeing registers */ 434425bb815Sopenharmony_ci VM_EXEC_CONSTRUCT, /**< construct a new object */ 435425bb815Sopenharmony_ci} vm_call_operation; 436425bb815Sopenharmony_ci 437425bb815Sopenharmony_ciecma_value_t vm_run_global (const ecma_compiled_code_t *bytecode_p); 438425bb815Sopenharmony_ciecma_value_t vm_run_eval (ecma_compiled_code_t *bytecode_data_p, uint32_t parse_opts); 439425bb815Sopenharmony_ci 440425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015_MODULE_SYSTEM) 441425bb815Sopenharmony_ciecma_value_t vm_run_module (const ecma_compiled_code_t *bytecode_p, ecma_object_t *lex_env_p); 442425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015_MODULE_SYSTEM) */ 443425bb815Sopenharmony_ci 444425bb815Sopenharmony_ciecma_value_t vm_run (const ecma_compiled_code_t *bytecode_header_p, ecma_value_t this_binding_value, 445425bb815Sopenharmony_ci ecma_object_t *lex_env_p, const ecma_value_t *arg_list_p, ecma_length_t arg_list_len); 446425bb815Sopenharmony_ciecma_value_t vm_execute (vm_frame_ctx_t *frame_ctx_p); 447425bb815Sopenharmony_ci 448425bb815Sopenharmony_cibool vm_is_strict_mode (void); 449425bb815Sopenharmony_cibool vm_is_direct_eval_form_call (void); 450425bb815Sopenharmony_ci 451425bb815Sopenharmony_ciecma_value_t vm_get_backtrace (uint32_t max_depth); 452425bb815Sopenharmony_ci 453425bb815Sopenharmony_ci/** 454425bb815Sopenharmony_ci * @} 455425bb815Sopenharmony_ci * @} 456425bb815Sopenharmony_ci */ 457425bb815Sopenharmony_ci 458425bb815Sopenharmony_ci#endif /* !VM_H */ 459