Rework ecma collection. (#2153)

Greatly simplify the iterator part and make it compatible with 32 bit cpointers.

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
This commit is contained in:
Zoltan Herczeg
2018-01-10 15:55:56 +01:00
committed by Dániel Bátyai
parent f833da2c13
commit b9560b7c70
23 changed files with 511 additions and 521 deletions
+10 -11
View File
@@ -285,15 +285,14 @@ vm_op_delete_var (jmem_cpointer_t name_literal, /**< name literal */
* See also:
* ECMA-262 v5, 12.6.4
*
* @return completion value
* Returned value must be freed with ecma_free_value
* @return chain list of property names
*/
ecma_collection_header_t *
ecma_collection_chunk_t *
opfunc_for_in (ecma_value_t left_value, /**< left value */
ecma_value_t *result_obj_p) /**< expression object */
{
ecma_value_t compl_val = ECMA_VALUE_EMPTY;
ecma_collection_header_t *prop_names_p = NULL;
ecma_collection_chunk_t *prop_names_p = NULL;
/* 3. */
if (!ecma_is_value_undefined (left_value)
@@ -305,18 +304,18 @@ opfunc_for_in (ecma_value_t left_value, /**< left value */
compl_val);
ecma_object_t *obj_p = ecma_get_object_from_value (obj_expr_value);
prop_names_p = ecma_op_object_get_property_names (obj_p, false, true, true);
ecma_collection_header_t *prop_names_coll_p = ecma_op_object_get_property_names (obj_p, false, true, true);
if (prop_names_p->unit_number != 0)
if (prop_names_coll_p->item_count != 0)
{
prop_names_p = ECMA_GET_POINTER (ecma_collection_chunk_t,
prop_names_coll_p->first_chunk_cp);
ecma_ref_object (obj_p);
*result_obj_p = ecma_make_object_value (obj_p);
}
else
{
ecma_dealloc_collection_header (prop_names_p);
prop_names_p = NULL;
}
jmem_heap_free_block (prop_names_coll_p, sizeof (ecma_collection_header_t));
ECMA_FINALIZE (obj_expr_value);
}
+1 -1
View File
@@ -93,7 +93,7 @@ vm_op_delete_prop (ecma_value_t object, ecma_value_t property, bool is_strict);
ecma_value_t
vm_op_delete_var (jmem_cpointer_t name_literal, ecma_object_t *lex_env_p);
ecma_collection_header_t *
ecma_collection_chunk_t *
opfunc_for_in (ecma_value_t left_value, ecma_value_t *result_obj_p);
/**
+18 -9
View File
@@ -67,21 +67,30 @@ vm_stack_context_abort (vm_frame_ctx_t *frame_ctx_p, /**< frame context */
}
case VM_CONTEXT_FOR_IN:
{
jmem_cpointer_t current = (jmem_cpointer_t) vm_stack_top_p[-2];
ecma_collection_chunk_t *chunk_p;
chunk_p = ECMA_GET_INTERNAL_VALUE_ANY_POINTER (ecma_collection_chunk_t, vm_stack_top_p[-2]);
uint32_t index = vm_stack_top_p[-3];
while (current != JMEM_CP_NULL)
while (chunk_p != NULL)
{
ecma_collection_chunk_t *chunk_p = JMEM_CP_GET_NON_NULL_POINTER (ecma_collection_chunk_t,
current);
ecma_value_t value = chunk_p->items[index];
lit_utf8_byte_t *data_ptr = chunk_p->data;
ecma_free_value (*(ecma_value_t *) data_ptr);
if (unlikely (ecma_is_value_collection_chunk (value)))
{
ecma_collection_chunk_t *next_chunk_p = ecma_get_collection_chunk_from_value (value);
jmem_heap_free_block (chunk_p, sizeof (ecma_collection_chunk_t));
current = chunk_p->next_chunk_cp;
ecma_dealloc_collection_chunk (chunk_p);
chunk_p = next_chunk_p;
index = 0;
}
else
{
ecma_free_value (value);
index++;
}
}
ecma_free_value (vm_stack_top_p[-3]);
ecma_free_value (vm_stack_top_p[-4]);
VM_MINUS_EQUAL_U16 (frame_ctx_p->context_depth, PARSER_FOR_IN_CONTEXT_STACK_ALLOCATION);
vm_stack_top_p -= PARSER_FOR_IN_CONTEXT_STACK_ALLOCATION;
+56 -26
View File
@@ -2274,10 +2274,10 @@ vm_loop (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
JERRY_ASSERT (frame_ctx_p->registers_p + register_end + frame_ctx_p->context_depth == stack_top_p);
ecma_value_t expr_obj_value = ECMA_VALUE_UNDEFINED;
ecma_collection_header_t *header_p = opfunc_for_in (value, &expr_obj_value);
ecma_collection_chunk_t *prop_names_p = opfunc_for_in (value, &expr_obj_value);
ecma_free_value (value);
if (header_p == NULL)
if (prop_names_p == NULL)
{
byte_code_p = byte_code_start_p + branch_offset;
continue;
@@ -2288,62 +2288,92 @@ vm_loop (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
VM_PLUS_EQUAL_U16 (frame_ctx_p->context_depth, PARSER_FOR_IN_CONTEXT_STACK_ALLOCATION);
stack_top_p += PARSER_FOR_IN_CONTEXT_STACK_ALLOCATION;
stack_top_p[-1] = (ecma_value_t) VM_CREATE_CONTEXT (VM_CONTEXT_FOR_IN, branch_offset);
stack_top_p[-2] = header_p->first_chunk_cp;
stack_top_p[-3] = expr_obj_value;
ECMA_SET_INTERNAL_VALUE_ANY_POINTER (stack_top_p[-2], prop_names_p);
stack_top_p[-3] = 0;
stack_top_p[-4] = expr_obj_value;
ecma_dealloc_collection_header (header_p);
continue;
}
case VM_OC_FOR_IN_GET_NEXT:
{
ecma_value_t *context_top_p = frame_ctx_p->registers_p + register_end + frame_ctx_p->context_depth;
ecma_collection_chunk_t *chunk_p = JMEM_CP_GET_NON_NULL_POINTER (ecma_collection_chunk_t, context_top_p[-2]);
ecma_collection_chunk_t *chunk_p;
chunk_p = ECMA_GET_INTERNAL_VALUE_ANY_POINTER (ecma_collection_chunk_t, context_top_p[-2]);
JERRY_ASSERT (VM_GET_CONTEXT_TYPE (context_top_p[-1]) == VM_CONTEXT_FOR_IN);
lit_utf8_byte_t *data_ptr = chunk_p->data;
result = *(ecma_value_t *) data_ptr;
context_top_p[-2] = chunk_p->next_chunk_cp;
uint32_t index = context_top_p[-3];
ecma_dealloc_collection_chunk (chunk_p);
JERRY_ASSERT (!ecma_is_value_collection_chunk (chunk_p->items[index]));
*stack_top_p++ = result;
*stack_top_p++ = chunk_p->items[index];
index++;
if (likely (!ecma_is_value_collection_chunk (chunk_p->items[index])))
{
context_top_p[-3] = index;
continue;
}
context_top_p[-3] = 0;
ecma_collection_chunk_t *next_chunk_p = ecma_get_collection_chunk_from_value (chunk_p->items[index]);
ECMA_SET_INTERNAL_VALUE_ANY_POINTER (context_top_p[-2], next_chunk_p);
jmem_heap_free_block (chunk_p, sizeof (ecma_collection_chunk_t));
continue;
}
case VM_OC_FOR_IN_HAS_NEXT:
{
JERRY_ASSERT (frame_ctx_p->registers_p + register_end + frame_ctx_p->context_depth == stack_top_p);
ecma_collection_chunk_t *chunk_p;
chunk_p = ECMA_GET_INTERNAL_VALUE_ANY_POINTER (ecma_collection_chunk_t, stack_top_p[-2]);
uint32_t index = stack_top_p[-3];
ecma_object_t *object_p = ecma_get_object_from_value (stack_top_p[-4]);
while (true)
{
if (stack_top_p[-2] == JMEM_CP_NULL)
if (chunk_p == NULL)
{
ecma_free_value (stack_top_p[-3]);
ecma_deref_object (object_p);
VM_MINUS_EQUAL_U16 (frame_ctx_p->context_depth, PARSER_FOR_IN_CONTEXT_STACK_ALLOCATION);
stack_top_p -= PARSER_FOR_IN_CONTEXT_STACK_ALLOCATION;
break;
}
ecma_collection_chunk_t *chunk_p = JMEM_CP_GET_NON_NULL_POINTER (ecma_collection_chunk_t, stack_top_p[-2]);
ecma_string_t *prop_name_p = ecma_get_string_from_value (chunk_p->items[index]);
lit_utf8_byte_t *data_ptr = chunk_p->data;
ecma_string_t *prop_name_p = ecma_get_string_from_value (*(ecma_value_t *) data_ptr);
if (!ecma_op_object_has_property (ecma_get_object_from_value (stack_top_p[-3]),
prop_name_p))
{
stack_top_p[-2] = chunk_p->next_chunk_cp;
ecma_deref_ecma_string (prop_name_p);
ecma_dealloc_collection_chunk (chunk_p);
}
else
if (likely (ecma_op_object_has_property (object_p, prop_name_p)))
{
byte_code_p = byte_code_start_p + branch_offset;
break;
}
}
index++;
ecma_value_t value = chunk_p->items[index];
if (likely (!ecma_is_value_collection_chunk (value)))
{
stack_top_p[-3] = index;
}
else
{
index = 0;
stack_top_p[-3] = 0;
ecma_collection_chunk_t *next_chunk_p = ecma_get_collection_chunk_from_value (value);
ECMA_SET_INTERNAL_VALUE_ANY_POINTER (stack_top_p[-2], next_chunk_p);
jmem_heap_free_block (chunk_p, sizeof (ecma_collection_chunk_t));
chunk_p = next_chunk_p;
}
ecma_deref_ecma_string (prop_name_p);
}
continue;
}
case VM_OC_TRY: