Remove block result (#4799)
JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik robert.fancsik@h-lab.eu
This commit is contained in:
@@ -639,6 +639,7 @@ opfunc_create_executable_object (vm_frame_ctx_t *frame_ctx_p, /**< frame context
|
||||
executable_object_p->extended_object.u.cls.type = class_type;
|
||||
executable_object_p->extended_object.u.cls.u2.executable_obj_flags = 0;
|
||||
ECMA_SET_INTERNAL_VALUE_ANY_POINTER (executable_object_p->extended_object.u.cls.u3.head, NULL);
|
||||
executable_object_p->iterator = ECMA_VALUE_UNDEFINED;
|
||||
|
||||
JERRY_ASSERT (!(frame_ctx_p->status_flags & VM_FRAME_CTX_DIRECT_EVAL));
|
||||
|
||||
@@ -646,6 +647,7 @@ opfunc_create_executable_object (vm_frame_ctx_t *frame_ctx_p, /**< frame context
|
||||
vm_frame_ctx_shared_t *new_shared_p = &(executable_object_p->shared);
|
||||
*new_shared_p = *(frame_ctx_p->shared_p);
|
||||
new_shared_p->status_flags &= (uint32_t) ~VM_FRAME_CTX_SHARED_HAS_ARG_LIST;
|
||||
new_shared_p->status_flags |= VM_FRAME_CTX_SHARED_EXECUTABLE;
|
||||
|
||||
vm_frame_ctx_t *new_frame_ctx_p = &(executable_object_p->frame_ctx);
|
||||
*new_frame_ctx_p = *frame_ctx_p;
|
||||
@@ -690,7 +692,7 @@ opfunc_create_executable_object (vm_frame_ctx_t *frame_ctx_p, /**< frame context
|
||||
ecma_deref_if_object (*new_registers_p++);
|
||||
}
|
||||
|
||||
JERRY_ASSERT (new_frame_ctx_p->block_result == ECMA_VALUE_UNDEFINED);
|
||||
JERRY_ASSERT (*VM_GET_EXECUTABLE_ITERATOR (new_frame_ctx_p) == ECMA_VALUE_UNDEFINED);
|
||||
|
||||
new_frame_ctx_p->this_binding = ecma_copy_value_if_not_object (new_frame_ctx_p->this_binding);
|
||||
|
||||
@@ -767,7 +769,7 @@ opfunc_resume_executable_object (vm_executable_object_t *executable_object_p, /*
|
||||
ecma_ref_if_object (*register_p++);
|
||||
}
|
||||
|
||||
ecma_ref_if_object (executable_object_p->frame_ctx.block_result);
|
||||
ecma_ref_if_object (executable_object_p->iterator);
|
||||
|
||||
JERRY_ASSERT (ECMA_EXECUTABLE_OBJECT_IS_SUSPENDED (executable_object_p));
|
||||
|
||||
@@ -828,7 +830,7 @@ opfunc_resume_executable_object (vm_executable_object_t *executable_object_p, /*
|
||||
ecma_deref_if_object (*register_p++);
|
||||
}
|
||||
|
||||
ecma_deref_if_object (executable_object_p->frame_ctx.block_result);
|
||||
ecma_deref_if_object (executable_object_p->iterator);
|
||||
|
||||
return result;
|
||||
} /* opfunc_resume_executable_object */
|
||||
@@ -876,7 +878,6 @@ opfunc_async_create_and_await (vm_frame_ctx_t *frame_ctx_p, /**< frame context *
|
||||
ecma_value_t value, /**< awaited value (takes reference) */
|
||||
uint16_t extra_flags) /**< extra flags */
|
||||
{
|
||||
JERRY_ASSERT (frame_ctx_p->block_result == ECMA_VALUE_UNDEFINED);
|
||||
JERRY_ASSERT (CBC_FUNCTION_GET_TYPE (frame_ctx_p->shared_p->bytecode_header_p->status_flags) == CBC_FUNCTION_ASYNC
|
||||
|| (CBC_FUNCTION_GET_TYPE (frame_ctx_p->shared_p->bytecode_header_p->status_flags)
|
||||
== CBC_FUNCTION_ASYNC_ARROW));
|
||||
@@ -902,7 +903,7 @@ opfunc_async_create_and_await (vm_frame_ctx_t *frame_ctx_p, /**< frame context *
|
||||
result = ecma_op_create_promise_object (ECMA_VALUE_EMPTY, ECMA_VALUE_UNDEFINED, promise_p);
|
||||
|
||||
JERRY_ASSERT (ecma_is_value_object (result));
|
||||
executable_object_p->frame_ctx.block_result = result;
|
||||
executable_object_p->iterator = result;
|
||||
|
||||
return result;
|
||||
} /* opfunc_async_create_and_await */
|
||||
@@ -1523,8 +1524,8 @@ opfunc_assign_super_reference (ecma_value_t **vm_stack_top_p, /**< vm stack top
|
||||
}
|
||||
else if (opcode_data & VM_OC_PUT_BLOCK)
|
||||
{
|
||||
ecma_fast_free_value (frame_ctx_p->block_result);
|
||||
frame_ctx_p->block_result = result;
|
||||
ecma_fast_free_value (VM_GET_REGISTER (frame_ctx_p, 0));
|
||||
VM_GET_REGISTERS (frame_ctx_p)[0] = result;
|
||||
}
|
||||
|
||||
*vm_stack_top_p = stack_top_p;
|
||||
|
||||
@@ -48,6 +48,8 @@ typedef enum
|
||||
VM_FRAME_CTX_SHARED_NON_ARROW_FUNC = (1 << 4), /**< non-arrow function */
|
||||
VM_FRAME_CTX_SHARED_HERITAGE_PRESENT = (1 << 5), /**< class heritage present */
|
||||
VM_FRAME_CTX_SHARED_HAS_CLASS_FIELDS = (1 << 6), /**< has class fields */
|
||||
VM_FRAME_CTX_SHARED_EXECUTABLE = (1 << 7), /**< frame is an executable object constructed
|
||||
* with opfunc_create_executable_object */
|
||||
#endif /* JERRY_ESNEXT */
|
||||
} vm_frame_ctx_shared_flags_t;
|
||||
|
||||
@@ -112,7 +114,6 @@ typedef struct vm_frame_ctx_t
|
||||
ecma_object_t *lex_env_p; /**< current lexical environment */
|
||||
struct vm_frame_ctx_t *prev_context_p; /**< previous context */
|
||||
ecma_value_t this_binding; /**< this binding */
|
||||
ecma_value_t block_result; /**< block result */
|
||||
uint16_t context_depth; /**< current context depth */
|
||||
uint8_t status_flags; /**< combination of vm_frame_ctx_flags_t bits */
|
||||
uint8_t call_operation; /**< perform a call or construct operation */
|
||||
@@ -130,11 +131,19 @@ typedef struct vm_frame_ctx_t
|
||||
#define VM_GET_REGISTER(frame_ctx_p, i) (((ecma_value_t *) ((frame_ctx_p) + 1))[i])
|
||||
|
||||
/**
|
||||
* Get the executable object.
|
||||
* Calculate the executable object from a vm_executable_object frame context.
|
||||
*/
|
||||
#define VM_GET_EXECUTABLE_OBJECT(frame_ctx_p) \
|
||||
((ecma_extended_object_t *) ((uintptr_t) (frame_ctx_p) - (uintptr_t) offsetof (vm_executable_object_t, frame_ctx)))
|
||||
|
||||
/**
|
||||
* Calculate the shared_part from a vm_executable_object frame context.
|
||||
*/
|
||||
#define VM_GET_EXECUTABLE_ITERATOR(frame_ctx_p) \
|
||||
((ecma_value_t *) ((uintptr_t) (frame_ctx_p) \
|
||||
- (uintptr_t) offsetof (vm_executable_object_t, frame_ctx) \
|
||||
+ (uintptr_t) offsetof (vm_executable_object_t, iterator)))
|
||||
|
||||
/**
|
||||
* Generator frame context.
|
||||
*/
|
||||
@@ -142,6 +151,7 @@ typedef struct
|
||||
{
|
||||
ecma_extended_object_t extended_object; /**< extended object part */
|
||||
vm_frame_ctx_shared_t shared; /**< shared part */
|
||||
ecma_value_t iterator; /**< executable object's iterator */
|
||||
vm_frame_ctx_t frame_ctx; /**< frame context part */
|
||||
} vm_executable_object_t;
|
||||
|
||||
|
||||
+40
-35
@@ -46,6 +46,9 @@
|
||||
* @{
|
||||
*/
|
||||
|
||||
JERRY_STATIC_ASSERT ((sizeof (vm_frame_ctx_t) % sizeof (ecma_value_t)) == 0,
|
||||
sizeof_vm_frame_ctx_must_be_sizeof_ecma_value_t_aligned);
|
||||
|
||||
/**
|
||||
* Get the value of object[property].
|
||||
*
|
||||
@@ -657,8 +660,8 @@ vm_super_call (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
|
||||
}
|
||||
else
|
||||
{
|
||||
ecma_fast_free_value (frame_ctx_p->block_result);
|
||||
frame_ctx_p->block_result = completion_value;
|
||||
ecma_fast_free_value (VM_GET_REGISTER (frame_ctx_p, 0));
|
||||
VM_GET_REGISTERS (frame_ctx_p)[0] = completion_value;
|
||||
}
|
||||
}
|
||||
} /* vm_super_call */
|
||||
@@ -749,8 +752,8 @@ vm_spread_operation (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
|
||||
}
|
||||
else
|
||||
{
|
||||
ecma_fast_free_value (frame_ctx_p->block_result);
|
||||
frame_ctx_p->block_result = completion_value;
|
||||
ecma_fast_free_value (VM_GET_REGISTER (frame_ctx_p, 0));
|
||||
VM_GET_REGISTERS (frame_ctx_p)[0] = completion_value;
|
||||
}
|
||||
|
||||
/* EXT_OPCODE, SPREAD_OPCODE, BYTE_ARG */
|
||||
@@ -839,8 +842,8 @@ opfunc_call (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
|
||||
}
|
||||
else
|
||||
{
|
||||
ecma_fast_free_value (frame_ctx_p->block_result);
|
||||
frame_ctx_p->block_result = completion_value;
|
||||
ecma_fast_free_value (VM_GET_REGISTER (frame_ctx_p, 0));
|
||||
VM_GET_REGISTERS (frame_ctx_p)[0] = completion_value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1003,8 +1006,8 @@ opfunc_construct (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
|
||||
else \
|
||||
{ \
|
||||
JERRY_ASSERT (opcode_data & VM_OC_PUT_BLOCK); \
|
||||
ecma_free_value (frame_ctx_p->block_result); \
|
||||
frame_ctx_p->block_result = (value); \
|
||||
ecma_free_value (VM_GET_REGISTER (frame_ctx_p, 0)); \
|
||||
VM_GET_REGISTERS (frame_ctx_p)[0] = (value); \
|
||||
opcode_data &= (uint32_t) ~VM_OC_PUT_BLOCK; \
|
||||
}
|
||||
|
||||
@@ -1207,8 +1210,8 @@ vm_loop (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
|
||||
}
|
||||
case VM_OC_POP_BLOCK:
|
||||
{
|
||||
ecma_fast_free_value (frame_ctx_p->block_result);
|
||||
frame_ctx_p->block_result = *(--stack_top_p);
|
||||
ecma_fast_free_value (VM_GET_REGISTER (frame_ctx_p, 0));
|
||||
VM_GET_REGISTERS (frame_ctx_p)[0] = *(--stack_top_p);
|
||||
continue;
|
||||
}
|
||||
case VM_OC_PUSH:
|
||||
@@ -2663,7 +2666,7 @@ vm_loop (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
|
||||
}
|
||||
|
||||
async_generator_object_p->u.cls.u2.executable_obj_flags |= ECMA_EXECUTABLE_OBJECT_DO_AWAIT_OR_YIELD;
|
||||
frame_ctx_p->block_result = left_value;
|
||||
*VM_GET_EXECUTABLE_ITERATOR (frame_ctx_p) = left_value;
|
||||
|
||||
frame_ctx_p->call_operation = VM_EXEC_RETURN;
|
||||
frame_ctx_p->byte_code_p = byte_code_p;
|
||||
@@ -2672,7 +2675,7 @@ vm_loop (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
|
||||
}
|
||||
case VM_OC_AWAIT:
|
||||
{
|
||||
if (JERRY_UNLIKELY (frame_ctx_p->block_result == ECMA_VALUE_UNDEFINED))
|
||||
if (JERRY_UNLIKELY (!(frame_ctx_p->shared_p->status_flags & VM_FRAME_CTX_SHARED_EXECUTABLE)))
|
||||
{
|
||||
frame_ctx_p->call_operation = VM_EXEC_RETURN;
|
||||
frame_ctx_p->byte_code_p = byte_code_p;
|
||||
@@ -2722,13 +2725,15 @@ vm_loop (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
|
||||
{
|
||||
JERRY_ASSERT (VM_GET_REGISTERS (frame_ctx_p) + register_end + frame_ctx_p->context_depth == stack_top_p);
|
||||
|
||||
result = frame_ctx_p->block_result;
|
||||
frame_ctx_p->block_result = ECMA_VALUE_UNDEFINED;
|
||||
|
||||
if (result == ECMA_VALUE_UNDEFINED)
|
||||
if (!(frame_ctx_p->shared_p->status_flags & VM_FRAME_CTX_SHARED_EXECUTABLE))
|
||||
{
|
||||
result = ecma_op_create_promise_object (ECMA_VALUE_EMPTY, ECMA_VALUE_UNDEFINED, NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = *VM_GET_EXECUTABLE_ITERATOR (frame_ctx_p);
|
||||
*VM_GET_EXECUTABLE_ITERATOR (frame_ctx_p) = ECMA_VALUE_UNDEFINED;
|
||||
}
|
||||
|
||||
vm_stack_context_type_t context_type = VM_GET_CONTEXT_TYPE (stack_top_p[-1]);
|
||||
|
||||
@@ -3113,18 +3118,25 @@ vm_loop (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
|
||||
left_value = ECMA_VALUE_UNDEFINED;
|
||||
break;
|
||||
}
|
||||
case VM_OC_RETURN_FUNCTION_END:
|
||||
{
|
||||
if (CBC_FUNCTION_GET_TYPE (bytecode_header_p->status_flags) == CBC_FUNCTION_SCRIPT)
|
||||
{
|
||||
result = VM_GET_REGISTER (frame_ctx_p, 0);
|
||||
VM_GET_REGISTERS (frame_ctx_p)[0] = ECMA_VALUE_UNDEFINED;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = ECMA_VALUE_UNDEFINED;
|
||||
}
|
||||
|
||||
goto error;
|
||||
}
|
||||
case VM_OC_RETURN:
|
||||
{
|
||||
JERRY_ASSERT (opcode == CBC_RETURN
|
||||
|| opcode == CBC_RETURN_WITH_BLOCK
|
||||
|| opcode == CBC_RETURN_WITH_LITERAL);
|
||||
|
||||
if (opcode == CBC_RETURN_WITH_BLOCK)
|
||||
{
|
||||
left_value = frame_ctx_p->block_result;
|
||||
frame_ctx_p->block_result = ECMA_VALUE_UNDEFINED;
|
||||
}
|
||||
|
||||
result = left_value;
|
||||
left_value = ECMA_VALUE_UNDEFINED;
|
||||
goto error;
|
||||
@@ -4319,7 +4331,7 @@ vm_loop (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
|
||||
| (ECMA_AWAIT_FOR_NEXT << ECMA_AWAIT_STATE_SHIFT));
|
||||
|
||||
if (CBC_FUNCTION_GET_TYPE (bytecode_header_p->status_flags) == CBC_FUNCTION_ASYNC_GENERATOR
|
||||
|| frame_ctx_p->block_result != ECMA_VALUE_UNDEFINED)
|
||||
|| (frame_ctx_p->shared_p->status_flags & VM_FRAME_CTX_SHARED_EXECUTABLE))
|
||||
{
|
||||
ecma_extended_object_t *executable_object_p = VM_GET_EXECUTABLE_OBJECT (frame_ctx_p);
|
||||
result = ecma_promise_async_await (executable_object_p, result);
|
||||
@@ -4794,8 +4806,8 @@ vm_loop (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
|
||||
}
|
||||
else if (opcode_data & VM_OC_PUT_BLOCK)
|
||||
{
|
||||
ecma_fast_free_value (frame_ctx_p->block_result);
|
||||
frame_ctx_p->block_result = result;
|
||||
ecma_fast_free_value (VM_GET_REGISTER (frame_ctx_p, 0));
|
||||
VM_GET_REGISTERS (frame_ctx_p)[0] = result;
|
||||
}
|
||||
|
||||
free_both_values:
|
||||
@@ -4878,7 +4890,6 @@ error:
|
||||
if (frame_ctx_p->context_depth == 0)
|
||||
{
|
||||
/* In most cases there is no context. */
|
||||
ecma_fast_free_value (frame_ctx_p->block_result);
|
||||
frame_ctx_p->call_operation = VM_NO_EXEC_OP;
|
||||
return result;
|
||||
}
|
||||
@@ -4985,7 +4996,6 @@ error:
|
||||
}
|
||||
|
||||
finish:
|
||||
ecma_free_value (frame_ctx_p->block_result);
|
||||
frame_ctx_p->call_operation = VM_NO_EXEC_OP;
|
||||
return result;
|
||||
}
|
||||
@@ -5148,7 +5158,7 @@ vm_init_module_scope (ecma_module_t *module_p) /**< module without scope */
|
||||
}
|
||||
default:
|
||||
{
|
||||
JERRY_ASSERT (opcode == CBC_RETURN_WITH_BLOCK);
|
||||
JERRY_ASSERT (opcode == CBC_RETURN_FUNCTION_END);
|
||||
return ECMA_VALUE_EMPTY;
|
||||
}
|
||||
}
|
||||
@@ -5179,7 +5189,6 @@ vm_init_exec (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
|
||||
const ecma_compiled_code_t *bytecode_header_p = shared_p->bytecode_header_p;
|
||||
|
||||
frame_ctx_p->prev_context_p = JERRY_CONTEXT (vm_top_context_p);
|
||||
frame_ctx_p->block_result = ECMA_VALUE_UNDEFINED;
|
||||
frame_ctx_p->context_depth = 0;
|
||||
frame_ctx_p->status_flags = (uint8_t) ((shared_p->status_flags & VM_FRAME_CTX_DIRECT_EVAL)
|
||||
| (bytecode_header_p->status_flags & VM_FRAME_CTX_IS_STRICT));
|
||||
@@ -5356,11 +5365,7 @@ vm_run (vm_frame_ctx_shared_t *shared_p, /**< shared data */
|
||||
frame_size = (size_t) (args_p->register_end + args_p->stack_limit);
|
||||
}
|
||||
|
||||
frame_size = frame_size * sizeof (ecma_value_t) + sizeof (vm_frame_ctx_t);
|
||||
frame_size = (frame_size + sizeof (uintptr_t) - 1) / sizeof (uintptr_t);
|
||||
|
||||
/* Use JERRY_MAX() to avoid array declaration with size 0. */
|
||||
JERRY_VLA (uintptr_t, stack, frame_size);
|
||||
JERRY_VLA (ecma_value_t, stack, frame_size + (sizeof (vm_frame_ctx_t) / sizeof (ecma_value_t)));
|
||||
|
||||
frame_ctx_p = (vm_frame_ctx_t *) stack;
|
||||
|
||||
|
||||
@@ -152,6 +152,7 @@ typedef enum
|
||||
VM_OC_ASSIGN_PROP_THIS, /**< assign prop this */
|
||||
|
||||
VM_OC_RETURN, /**< return */
|
||||
VM_OC_RETURN_FUNCTION_END, /**< return at the end of a function/script */
|
||||
VM_OC_THROW, /**< throw */
|
||||
VM_OC_THROW_REFERENCE_ERROR, /**< throw reference error */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user