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#ifndef VM_DEFINES_H
16425bb815Sopenharmony_ci#define VM_DEFINES_H
17425bb815Sopenharmony_ci
18425bb815Sopenharmony_ci#include "byte-code.h"
19425bb815Sopenharmony_ci#include "ecma-globals.h"
20425bb815Sopenharmony_ci
21425bb815Sopenharmony_ci/** \addtogroup vm Virtual machine
22425bb815Sopenharmony_ci * @{
23425bb815Sopenharmony_ci *
24425bb815Sopenharmony_ci * \addtogroup vm_executor Executor
25425bb815Sopenharmony_ci * @{
26425bb815Sopenharmony_ci */
27425bb815Sopenharmony_ci
28425bb815Sopenharmony_ci/**
29425bb815Sopenharmony_ci * Helper for += on uint16_t values.
30425bb815Sopenharmony_ci */
31425bb815Sopenharmony_ci#define VM_PLUS_EQUAL_U16(base, value) (base) = (uint16_t) ((base) + (value))
32425bb815Sopenharmony_ci
33425bb815Sopenharmony_ci/**
34425bb815Sopenharmony_ci * Helper for -= on uint16_t values.
35425bb815Sopenharmony_ci */
36425bb815Sopenharmony_ci#define VM_MINUS_EQUAL_U16(base, value) (base) = (uint16_t) ((base) - (value))
37425bb815Sopenharmony_ci
38425bb815Sopenharmony_ci/**
39425bb815Sopenharmony_ci * Context of interpreter, related to a JS stack frame
40425bb815Sopenharmony_ci */
41425bb815Sopenharmony_citypedef struct vm_frame_ctx_t
42425bb815Sopenharmony_ci{
43425bb815Sopenharmony_ci  const ecma_compiled_code_t *bytecode_header_p;      /**< currently executed byte-code data */
44425bb815Sopenharmony_ci  const uint8_t *byte_code_p;                         /**< current byte code pointer */
45425bb815Sopenharmony_ci  const uint8_t *byte_code_start_p;                   /**< byte code start pointer */
46425bb815Sopenharmony_ci  ecma_value_t *stack_top_p;                          /**< stack top pointer */
47425bb815Sopenharmony_ci  ecma_value_t *literal_start_p;                      /**< literal list start pointer */
48425bb815Sopenharmony_ci  ecma_object_t *lex_env_p;                           /**< current lexical environment */
49425bb815Sopenharmony_ci  struct vm_frame_ctx_t *prev_context_p;              /**< previous context */
50425bb815Sopenharmony_ci  ecma_value_t this_binding;                          /**< this binding */
51425bb815Sopenharmony_ci  ecma_value_t block_result;                          /**< block result */
52425bb815Sopenharmony_ci#if defined(JERRY_FUNCTION_BACKTRACE) && !defined(__APPLE__)
53425bb815Sopenharmony_ci  ecma_value_t callee_value;
54425bb815Sopenharmony_ci#endif
55425bb815Sopenharmony_ci#if ENABLED (JERRY_LINE_INFO) || ENABLED (JERRY_ES2015_MODULE_SYSTEM)
56425bb815Sopenharmony_ci  ecma_value_t resource_name;                         /**< current resource name (usually a file name) */
57425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_LINE_INFO) || ENABLED (JERRY_ES2015_MODULE_SYSTEM) */
58425bb815Sopenharmony_ci#if ENABLED (JERRY_LINE_INFO)
59425bb815Sopenharmony_ci  uint32_t current_line;                              /**< currently executed line */
60425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_LINE_INFO) */
61425bb815Sopenharmony_ci  uint16_t context_depth;                             /**< current context depth */
62425bb815Sopenharmony_ci  uint8_t is_eval_code;                               /**< eval mode flag */
63425bb815Sopenharmony_ci  uint8_t call_operation;                             /**< perform a call or construct operation */
64425bb815Sopenharmony_ci  /* Registers start immediately after the frame context. */
65425bb815Sopenharmony_ci} vm_frame_ctx_t;
66425bb815Sopenharmony_ci
67425bb815Sopenharmony_ci/**
68425bb815Sopenharmony_ci * Get register list corresponding to the frame context.
69425bb815Sopenharmony_ci */
70425bb815Sopenharmony_ci#define VM_GET_REGISTERS(frame_ctx_p) ((ecma_value_t *) ((frame_ctx_p) + 1))
71425bb815Sopenharmony_ci
72425bb815Sopenharmony_ci/**
73425bb815Sopenharmony_ci * Read or write a specific register.
74425bb815Sopenharmony_ci */
75425bb815Sopenharmony_ci#define VM_GET_REGISTER(frame_ctx_p, i) (((ecma_value_t *) ((frame_ctx_p) + 1))[i])
76425bb815Sopenharmony_ci
77425bb815Sopenharmony_ci/**
78425bb815Sopenharmony_ci * Generator frame context.
79425bb815Sopenharmony_ci */
80425bb815Sopenharmony_citypedef struct
81425bb815Sopenharmony_ci{
82425bb815Sopenharmony_ci  ecma_extended_object_t extended_object; /**< extended object part */
83425bb815Sopenharmony_ci  vm_frame_ctx_t frame_ctx; /**< frame context part */
84425bb815Sopenharmony_ci} vm_executable_object_t;
85425bb815Sopenharmony_ci
86425bb815Sopenharmony_ci/**
87425bb815Sopenharmony_ci * @}
88425bb815Sopenharmony_ci * @}
89425bb815Sopenharmony_ci */
90425bb815Sopenharmony_ci
91425bb815Sopenharmony_ci#endif /* !VM_DEFINES_H */
92