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_STACK_H 17425bb815Sopenharmony_ci#define VM_STACK_H 18425bb815Sopenharmony_ci 19425bb815Sopenharmony_ci#include "ecma-globals.h" 20425bb815Sopenharmony_ci 21425bb815Sopenharmony_ci/** \addtogroup vm Virtual machine 22425bb815Sopenharmony_ci * @{ 23425bb815Sopenharmony_ci * 24425bb815Sopenharmony_ci * \addtogroup stack VM stack 25425bb815Sopenharmony_ci * @{ 26425bb815Sopenharmony_ci */ 27425bb815Sopenharmony_ci 28425bb815Sopenharmony_ci/** 29425bb815Sopenharmony_ci * Create context on the vm stack. 30425bb815Sopenharmony_ci */ 31425bb815Sopenharmony_ci#define VM_CREATE_CONTEXT(type, end_offset) ((ecma_value_t) ((type) | ((end_offset) << 7))) 32425bb815Sopenharmony_ci 33425bb815Sopenharmony_ci/** 34425bb815Sopenharmony_ci * Create context on the vm stack with environment. 35425bb815Sopenharmony_ci */ 36425bb815Sopenharmony_ci#define VM_CREATE_CONTEXT_WITH_ENV(type, end_offset) \ 37425bb815Sopenharmony_ci (VM_CREATE_CONTEXT ((type),(end_offset)) | VM_CONTEXT_HAS_LEX_ENV) 38425bb815Sopenharmony_ci 39425bb815Sopenharmony_ci/** 40425bb815Sopenharmony_ci * Get type of a vm context. 41425bb815Sopenharmony_ci */ 42425bb815Sopenharmony_ci#define VM_GET_CONTEXT_TYPE(value) ((vm_stack_context_type_t) ((value) & 0x1f)) 43425bb815Sopenharmony_ci 44425bb815Sopenharmony_ci/** 45425bb815Sopenharmony_ci * Get the end position of a vm context. 46425bb815Sopenharmony_ci */ 47425bb815Sopenharmony_ci#define VM_GET_CONTEXT_END(value) ((value) >> 7) 48425bb815Sopenharmony_ci 49425bb815Sopenharmony_ci/** 50425bb815Sopenharmony_ci * This flag is set if the context has a lexical environment. 51425bb815Sopenharmony_ci */ 52425bb815Sopenharmony_ci#define VM_CONTEXT_HAS_LEX_ENV 0x20 53425bb815Sopenharmony_ci 54425bb815Sopenharmony_ci/** 55425bb815Sopenharmony_ci * This flag is set if the iterator close operation should be invoked during a for-of context break. 56425bb815Sopenharmony_ci */ 57425bb815Sopenharmony_ci#define VM_CONTEXT_CLOSE_ITERATOR 0x40 58425bb815Sopenharmony_ci 59425bb815Sopenharmony_ci/** 60425bb815Sopenharmony_ci * Context types for the vm stack. 61425bb815Sopenharmony_ci */ 62425bb815Sopenharmony_citypedef enum 63425bb815Sopenharmony_ci{ 64425bb815Sopenharmony_ci /* Update VM_CONTEXT_IS_FINALLY macro if the following three values are changed. */ 65425bb815Sopenharmony_ci VM_CONTEXT_FINALLY_JUMP, /**< finally context with a jump */ 66425bb815Sopenharmony_ci VM_CONTEXT_FINALLY_THROW, /**< finally context with a throw */ 67425bb815Sopenharmony_ci VM_CONTEXT_FINALLY_RETURN, /**< finally context with a return */ 68425bb815Sopenharmony_ci VM_CONTEXT_TRY, /**< try context */ 69425bb815Sopenharmony_ci VM_CONTEXT_CATCH, /**< catch context */ 70425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015) 71425bb815Sopenharmony_ci VM_CONTEXT_BLOCK, /**< block context */ 72425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */ 73425bb815Sopenharmony_ci VM_CONTEXT_WITH, /**< with context */ 74425bb815Sopenharmony_ci VM_CONTEXT_FOR_IN, /**< for-in context */ 75425bb815Sopenharmony_ci#if ENABLED (JERRY_ES2015) 76425bb815Sopenharmony_ci VM_CONTEXT_FOR_OF, /**< for-of context */ 77425bb815Sopenharmony_ci#endif /* ENABLED (JERRY_ES2015) */ 78425bb815Sopenharmony_ci} vm_stack_context_type_t; 79425bb815Sopenharmony_ci 80425bb815Sopenharmony_ci/** 81425bb815Sopenharmony_ci * Checks whether the context type is a finally type. 82425bb815Sopenharmony_ci */ 83425bb815Sopenharmony_ci#define VM_CONTEXT_IS_FINALLY(context_type) \ 84425bb815Sopenharmony_ci ((context_type) <= VM_CONTEXT_FINALLY_RETURN) 85425bb815Sopenharmony_ci 86425bb815Sopenharmony_ci/** 87425bb815Sopenharmony_ci * Shift needs to be applied to get the next item of the offset array. 88425bb815Sopenharmony_ci */ 89425bb815Sopenharmony_ci#define VM_CONTEXT_OFFSET_SHIFT 4 90425bb815Sopenharmony_ci 91425bb815Sopenharmony_ci/** 92425bb815Sopenharmony_ci * Checks whether an offset is available. 93425bb815Sopenharmony_ci */ 94425bb815Sopenharmony_ci#define VM_CONTEXT_HAS_NEXT_OFFSET(offsets) ((offsets) >= (1 << VM_CONTEXT_OFFSET_SHIFT)) 95425bb815Sopenharmony_ci 96425bb815Sopenharmony_ci/** 97425bb815Sopenharmony_ci * Gets the next offset from the offset array. 98425bb815Sopenharmony_ci */ 99425bb815Sopenharmony_ci#define VM_CONTEXT_GET_NEXT_OFFSET(offsets) (-((int32_t) ((offsets) & ((1 << VM_CONTEXT_OFFSET_SHIFT) - 1)))) 100425bb815Sopenharmony_ci 101425bb815Sopenharmony_ciecma_value_t *vm_stack_context_abort (vm_frame_ctx_t *frame_ctx_p, ecma_value_t *vm_stack_top_p); 102425bb815Sopenharmony_cibool vm_stack_find_finally (vm_frame_ctx_t *frame_ctx_p, ecma_value_t **vm_stack_top_ref_p, 103425bb815Sopenharmony_ci vm_stack_context_type_t finally_type, uint32_t search_limit); 104425bb815Sopenharmony_ciuint32_t vm_get_context_value_offsets (ecma_value_t *context_item_p); 105425bb815Sopenharmony_civoid vm_ref_lex_env_chain (ecma_object_t *lex_env_p, uint16_t context_depth, 106425bb815Sopenharmony_ci ecma_value_t *context_end_p, bool do_ref); 107425bb815Sopenharmony_ci 108425bb815Sopenharmony_ci/** 109425bb815Sopenharmony_ci * @} 110425bb815Sopenharmony_ci * @} 111425bb815Sopenharmony_ci */ 112425bb815Sopenharmony_ci 113425bb815Sopenharmony_ci#endif /* !VM_STACK_H */ 114