1/* Copyright JS Foundation and other contributors, http://js.foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16#ifndef OPCODES_H
17#define OPCODES_H
18
19#include "ecma-globals.h"
20#include "vm-defines.h"
21
22/** \addtogroup vm Virtual machine
23 * @{
24 *
25 * \addtogroup vm_opcodes Opcodes
26 * @{
27 */
28
29/**
30 * Number arithmetic operations.
31 */
32typedef enum
33{
34  NUMBER_ARITHMETIC_SUBTRACTION, /**< subtraction */
35  NUMBER_ARITHMETIC_MULTIPLICATION, /**< multiplication */
36  NUMBER_ARITHMETIC_DIVISION, /**< division */
37  NUMBER_ARITHMETIC_REMAINDER, /**< remainder calculation */
38#if ENABLED (JERRY_ES2015)
39  NUMBER_ARITHMETIC_EXPONENTIATION, /**< exponentiation */
40#endif /* ENABLED (JERRY_ES2015) */
41} number_arithmetic_op;
42
43/**
44 * Number bitwise logic operations.
45 */
46typedef enum
47{
48  NUMBER_BITWISE_LOGIC_AND, /**< bitwise AND calculation */
49  NUMBER_BITWISE_LOGIC_OR, /**< bitwise OR calculation */
50  NUMBER_BITWISE_LOGIC_XOR, /**< bitwise XOR calculation */
51  NUMBER_BITWISE_SHIFT_LEFT, /**< bitwise LEFT SHIFT calculation */
52  NUMBER_BITWISE_SHIFT_RIGHT, /**< bitwise RIGHT_SHIFT calculation */
53  NUMBER_BITWISE_SHIFT_URIGHT, /**< bitwise UNSIGNED RIGHT SHIFT calculation */
54  NUMBER_BITWISE_NOT, /**< bitwise NOT calculation */
55} number_bitwise_logic_op;
56
57/**
58 * The stack contains spread object during the upcoming APPEND_ARRAY operation
59 */
60#define OPFUNC_HAS_SPREAD_ELEMENT (1 << 8)
61
62ecma_value_t
63vm_var_decl (ecma_object_t *lex_env_p, ecma_string_t *var_name_str_p, bool is_configurable_bindings);
64
65ecma_value_t
66vm_set_var (ecma_object_t *lex_env_p, ecma_string_t *var_name_str_p, bool is_strict, ecma_value_t lit_value);
67
68ecma_value_t
69opfunc_equality (ecma_value_t left_value, ecma_value_t right_value);
70
71ecma_value_t
72do_number_arithmetic (number_arithmetic_op op, ecma_value_t left_value, ecma_value_t right_value);
73
74ecma_value_t
75opfunc_unary_operation (ecma_value_t left_value, bool is_plus);
76
77ecma_value_t
78do_number_bitwise_logic (number_bitwise_logic_op op, ecma_value_t left_value, ecma_value_t right_value);
79
80ecma_value_t
81opfunc_addition (ecma_value_t left_value, ecma_value_t right_value);
82
83ecma_value_t
84opfunc_relation (ecma_value_t left_value, ecma_value_t right_value, bool left_first, bool is_invert);
85
86ecma_value_t
87opfunc_in (ecma_value_t left_value, ecma_value_t right_value);
88
89ecma_value_t
90opfunc_instanceof (ecma_value_t left_value, ecma_value_t right_value);
91
92ecma_value_t
93opfunc_typeof (ecma_value_t left_value);
94
95void
96opfunc_set_accessor (bool is_getter, ecma_value_t object, ecma_string_t *accessor_name_p, ecma_value_t accessor);
97
98ecma_value_t
99vm_op_delete_prop (ecma_value_t object, ecma_value_t property, bool is_strict);
100
101ecma_value_t
102vm_op_delete_var (ecma_value_t name_literal, ecma_object_t *lex_env_p);
103
104ecma_collection_t *
105opfunc_for_in (ecma_value_t left_value, ecma_value_t *result_obj_p);
106
107#if ENABLED (JERRY_ES2015)
108ecma_collection_t *
109opfunc_spread_arguments (ecma_value_t *stack_top_p, uint8_t argument_list_len);
110#endif /* ENABLED (JERRY_ES2015) */
111
112ecma_value_t
113opfunc_append_array (ecma_value_t *stack_top_p, uint16_t values_length);
114
115#if ENABLED (JERRY_ES2015)
116ecma_value_t
117opfunc_create_executable_object (vm_frame_ctx_t *frame_ctx_p);
118
119ecma_value_t
120opfunc_resume_executable_object (vm_executable_object_t *executable_object_p, ecma_value_t value);
121
122ecma_value_t
123opfunc_return_promise (ecma_value_t value);
124
125ecma_value_t
126opfunc_create_implicit_class_constructor (uint8_t opcode);
127
128void
129opfunc_push_class_environment (vm_frame_ctx_t *frame_ctx_p,  ecma_value_t **vm_stack_top, ecma_value_t class_name);
130
131ecma_value_t
132opfunc_init_class (vm_frame_ctx_t *frame_context_p, ecma_value_t *stack_top_p);
133
134void
135opfunc_pop_lexical_environment (vm_frame_ctx_t *frame_ctx_p);
136
137void
138opfunc_finalize_class (vm_frame_ctx_t *frame_ctx_p, ecma_value_t **vm_stack_top_p, ecma_value_t class_name);
139
140ecma_value_t
141opfunc_form_super_reference (ecma_value_t **vm_stack_top_p, vm_frame_ctx_t *frame_ctx_p, ecma_value_t prop_name,
142                             uint8_t opcode);
143
144ecma_value_t
145opfunc_assign_super_reference (ecma_value_t **vm_stack_top_p, vm_frame_ctx_t *frame_ctx_p, uint32_t opcode_data);
146#endif /* ENABLED (JERRY_ES2015) */
147
148/**
149 * @}
150 * @}
151 */
152
153#endif /* !OPCODES_H */
154