• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef VM_DEFINES_H
16 #define VM_DEFINES_H
17 
18 #include "byte-code.h"
19 #include "ecma-globals.h"
20 
21 /** \addtogroup vm Virtual machine
22  * @{
23  *
24  * \addtogroup vm_executor Executor
25  * @{
26  */
27 
28 /**
29  * Helper for += on uint16_t values.
30  */
31 #define VM_PLUS_EQUAL_U16(base, value) (base) = (uint16_t) ((base) + (value))
32 
33 /**
34  * Helper for -= on uint16_t values.
35  */
36 #define VM_MINUS_EQUAL_U16(base, value) (base) = (uint16_t) ((base) - (value))
37 
38 /**
39  * Context of interpreter, related to a JS stack frame
40  */
41 typedef struct vm_frame_ctx_t
42 {
43   const ecma_compiled_code_t *bytecode_header_p;      /**< currently executed byte-code data */
44   const uint8_t *byte_code_p;                         /**< current byte code pointer */
45   const uint8_t *byte_code_start_p;                   /**< byte code start pointer */
46   ecma_value_t *stack_top_p;                          /**< stack top pointer */
47   ecma_value_t *literal_start_p;                      /**< literal list start pointer */
48   ecma_object_t *lex_env_p;                           /**< current lexical environment */
49   struct vm_frame_ctx_t *prev_context_p;              /**< previous context */
50   ecma_value_t this_binding;                          /**< this binding */
51   ecma_value_t block_result;                          /**< block result */
52 #if defined(JERRY_FUNCTION_BACKTRACE) && !defined(__APPLE__)
53   ecma_value_t callee_value;
54 #endif
55 #if ENABLED (JERRY_LINE_INFO) || ENABLED (JERRY_ES2015_MODULE_SYSTEM)
56   ecma_value_t resource_name;                         /**< current resource name (usually a file name) */
57 #endif /* ENABLED (JERRY_LINE_INFO) || ENABLED (JERRY_ES2015_MODULE_SYSTEM) */
58 #if ENABLED (JERRY_LINE_INFO)
59   uint32_t current_line;                              /**< currently executed line */
60 #endif /* ENABLED (JERRY_LINE_INFO) */
61   uint16_t context_depth;                             /**< current context depth */
62   uint8_t is_eval_code;                               /**< eval mode flag */
63   uint8_t call_operation;                             /**< perform a call or construct operation */
64   /* Registers start immediately after the frame context. */
65 } vm_frame_ctx_t;
66 
67 /**
68  * Get register list corresponding to the frame context.
69  */
70 #define VM_GET_REGISTERS(frame_ctx_p) ((ecma_value_t *) ((frame_ctx_p) + 1))
71 
72 /**
73  * Read or write a specific register.
74  */
75 #define VM_GET_REGISTER(frame_ctx_p, i) (((ecma_value_t *) ((frame_ctx_p) + 1))[i])
76 
77 /**
78  * Generator frame context.
79  */
80 typedef struct
81 {
82   ecma_extended_object_t extended_object; /**< extended object part */
83   vm_frame_ctx_t frame_ctx; /**< frame context part */
84 } vm_executable_object_t;
85 
86 /**
87  * @}
88  * @}
89  */
90 
91 #endif /* !VM_DEFINES_H */
92