Skip to content

Commit 7aa1b16

Browse files
Change fill_varg_list to append arguments values to ecma-values collection, instead of array; rename it to vm_fill_varg_list.
JerryScript-DCO-1.0-Signed-off-by: Ruben Ayrapetyan [email protected]
1 parent b08e8a3 commit 7aa1b16

File tree

3 files changed

+89
-82
lines changed

3 files changed

+89
-82
lines changed

jerry-core/vm/opcodes-ecma-support.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,9 @@
3737
bool is_reg_variable (vm_frame_ctx_t *frame_ctx_p, idx_t var_idx);
3838
ecma_completion_value_t get_variable_value (vm_frame_ctx_t *, idx_t, bool);
3939
ecma_completion_value_t set_variable_value (vm_frame_ctx_t *, vm_instr_counter_t, idx_t, ecma_value_t);
40-
ecma_completion_value_t fill_varg_list (vm_frame_ctx_t *frame_ctx_p,
41-
ecma_length_t args_number,
42-
ecma_value_t args_values[],
43-
ecma_length_t *out_arg_number_p);
40+
ecma_completion_value_t vm_fill_varg_list (vm_frame_ctx_t *frame_ctx_p,
41+
ecma_length_t args_number,
42+
ecma_collection_header_t *args_values_p);
4443
void fill_params_list (vm_frame_ctx_t *frame_ctx_p,
4544
ecma_length_t params_number,
4645
ecma_string_t* params_names[]);

jerry-core/vm/opcodes-varg.cpp

Lines changed: 21 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -27,56 +27,44 @@
2727
* of last expression evaluated
2828
*/
2929
ecma_completion_value_t
30-
fill_varg_list (vm_frame_ctx_t *frame_ctx_p, /**< interpreter context */
31-
ecma_length_t args_number, /**< number of arguments */
32-
ecma_value_t arg_values[], /**< out: arguments' values */
33-
ecma_length_t *out_arg_number_p) /**< out: number of arguments
34-
successfully read */
30+
vm_fill_varg_list (vm_frame_ctx_t *frame_ctx_p, /**< interpreter context */
31+
ecma_length_t args_number, /**< number of arguments */
32+
ecma_collection_header_t *arg_collection_p) /** collection to fill with argument values */
3533
{
3634
ecma_completion_value_t ret_value = ecma_make_empty_completion_value ();
3735

3836
ecma_length_t arg_index;
3937
for (arg_index = 0;
4038
arg_index < args_number && ecma_is_completion_value_empty (ret_value);
41-
)
39+
arg_index++)
4240
{
43-
ecma_completion_value_t evaluate_arg_completion = vm_loop (frame_ctx_p, NULL);
41+
ECMA_TRY_CATCH (evaluate_arg,
42+
vm_loop (frame_ctx_p, NULL),
43+
ret_value);
4444

45-
if (ecma_is_completion_value_empty (evaluate_arg_completion))
46-
{
47-
vm_instr_t next_instr = vm_get_instr (frame_ctx_p->instrs_p, frame_ctx_p->pos);
48-
JERRY_ASSERT (next_instr.op_idx == VM_OP_META);
49-
JERRY_ASSERT (next_instr.data.meta.type == OPCODE_META_TYPE_VARG);
50-
51-
const idx_t varg_var_idx = next_instr.data.meta.data_1;
45+
vm_instr_t next_instr = vm_get_instr (frame_ctx_p->instrs_p, frame_ctx_p->pos);
46+
JERRY_ASSERT (next_instr.op_idx == VM_OP_META);
47+
JERRY_ASSERT (next_instr.data.meta.type == OPCODE_META_TYPE_VARG);
5248

53-
ecma_completion_value_t get_arg_completion = get_variable_value (frame_ctx_p, varg_var_idx, false);
49+
const idx_t varg_var_idx = next_instr.data.meta.data_1;
5450

55-
if (ecma_is_completion_value_normal (get_arg_completion))
56-
{
57-
arg_values[arg_index++] = ecma_get_completion_value_value (get_arg_completion);
58-
}
59-
else
60-
{
61-
JERRY_ASSERT (ecma_is_completion_value_throw (get_arg_completion));
51+
ECMA_TRY_CATCH (get_arg,
52+
get_variable_value (frame_ctx_p, varg_var_idx, false),
53+
ret_value);
6254

63-
ret_value = get_arg_completion;
64-
}
65-
}
66-
else
67-
{
68-
JERRY_ASSERT (ecma_is_completion_value_throw (evaluate_arg_completion));
55+
ecma_append_to_values_collection (arg_collection_p,
56+
ecma_get_completion_value_value (get_arg_completion),
57+
true);
6958

70-
ret_value = evaluate_arg_completion;
71-
}
59+
ECMA_FINALIZE (get_arg);
7260

7361
frame_ctx_p->pos++;
74-
}
7562

76-
*out_arg_number_p = arg_index;
63+
ECMA_FINALIZE (evaluate_arg);
64+
}
7765

7866
return ret_value;
79-
} /* fill_varg_list */
67+
} /* vm_fill_varg_list */
8068

8169
/**
8270
* Fill parameters' list

jerry-core/vm/opcodes.cpp

Lines changed: 65 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -814,13 +814,12 @@ opfunc_call_n (vm_instr_t instr, /**< instruction */
814814
function_var_idx,
815815
&call_flags);
816816

817-
MEM_DEFINE_LOCAL_ARRAY (arg_values, args_number_idx, ecma_value_t);
817+
ecma_collection_header_t *arg_collection_p = ecma_new_values_collection (NULL, 0, true);
818818

819-
ecma_length_t args_read;
820-
ecma_completion_value_t get_arg_completion = fill_varg_list (frame_ctx_p,
821-
args_number_idx,
822-
arg_values,
823-
&args_read);
819+
ecma_completion_value_t get_arg_completion = vm_fill_varg_list (frame_ctx_p,
820+
args_number_idx,
821+
arg_collection_p);
822+
ecma_length_t args_read = arg_collection_p->unit_number;
824823

825824
if (ecma_is_completion_value_empty (get_arg_completion))
826825
{
@@ -839,11 +838,24 @@ opfunc_call_n (vm_instr_t instr, /**< instruction */
839838

840839
ecma_object_t *func_obj_p = ecma_get_object_from_value (func_value);
841840

841+
MEM_DEFINE_LOCAL_ARRAY (arg_values, args_read, ecma_value_t);
842+
843+
ecma_collection_iterator_t arg_collection_iter;
844+
ecma_collection_iterator_init (&arg_collection_iter,
845+
arg_collection_p);
846+
847+
for (ecma_length_t arg_index = 0;
848+
ecma_collection_iterator_next (&arg_collection_iter);
849+
arg_index++)
850+
{
851+
arg_values[arg_index] = *arg_collection_iter.current_value_p;
852+
}
853+
842854
ECMA_TRY_CATCH (call_ret_value,
843855
ecma_op_function_call (func_obj_p,
844856
this_value,
845857
arg_values,
846-
args_number_idx),
858+
args_read),
847859
ret_value);
848860

849861
ret_value = set_variable_value (frame_ctx_p, lit_oc,
@@ -852,6 +864,8 @@ opfunc_call_n (vm_instr_t instr, /**< instruction */
852864

853865
ECMA_FINALIZE (call_ret_value);
854866

867+
MEM_FINALIZE_LOCAL_ARRAY (arg_values);
868+
855869
if (call_flags & OPCODE_CALL_FLAGS_DIRECT_CALL_TO_EVAL_FORM)
856870
{
857871
JERRY_ASSERT (frame_ctx_p->is_call_in_direct_eval_form);
@@ -870,15 +884,7 @@ opfunc_call_n (vm_instr_t instr, /**< instruction */
870884
ret_value = get_arg_completion;
871885
}
872886

873-
for (ecma_length_t arg_index = 0;
874-
arg_index < args_read;
875-
arg_index++)
876-
{
877-
ecma_free_value (arg_values[arg_index], true);
878-
}
879-
880-
MEM_FINALIZE_LOCAL_ARRAY (arg_values);
881-
887+
ecma_free_values_collection (arg_collection_p, true);
882888
ecma_free_value (this_value, true);
883889

884890
ECMA_FINALIZE (func_value);
@@ -908,15 +914,14 @@ opfunc_construct_n (vm_instr_t instr, /**< instruction */
908914
get_variable_value (frame_ctx_p, constructor_name_lit_idx, false),
909915
ret_value);
910916

911-
MEM_DEFINE_LOCAL_ARRAY (arg_values, args_number, ecma_value_t);
912-
913917
frame_ctx_p->pos++;
914918

915-
ecma_length_t args_read;
916-
ecma_completion_value_t get_arg_completion = fill_varg_list (frame_ctx_p,
917-
args_number,
918-
arg_values,
919-
&args_read);
919+
ecma_collection_header_t *arg_collection_p = ecma_new_values_collection (NULL, 0, true);
920+
921+
ecma_completion_value_t get_arg_completion = vm_fill_varg_list (frame_ctx_p,
922+
args_number,
923+
arg_collection_p);
924+
ecma_length_t args_read = arg_collection_p->unit_number;
920925

921926
if (ecma_is_completion_value_empty (get_arg_completion))
922927
{
@@ -930,6 +935,19 @@ opfunc_construct_n (vm_instr_t instr, /**< instruction */
930935
{
931936
ecma_object_t *constructor_obj_p = ecma_get_object_from_value (constructor_value);
932937

938+
MEM_DEFINE_LOCAL_ARRAY (arg_values, args_read, ecma_value_t);
939+
940+
ecma_collection_iterator_t arg_collection_iter;
941+
ecma_collection_iterator_init (&arg_collection_iter,
942+
arg_collection_p);
943+
944+
for (ecma_length_t arg_index = 0;
945+
ecma_collection_iterator_next (&arg_collection_iter);
946+
arg_index++)
947+
{
948+
arg_values[arg_index] = *arg_collection_iter.current_value_p;
949+
}
950+
933951
ECMA_TRY_CATCH (construction_ret_value,
934952
ecma_op_function_construct (constructor_obj_p,
935953
arg_values,
@@ -940,6 +958,8 @@ opfunc_construct_n (vm_instr_t instr, /**< instruction */
940958
construction_ret_value);
941959

942960
ECMA_FINALIZE (construction_ret_value);
961+
962+
MEM_FINALIZE_LOCAL_ARRAY (arg_values);
943963
}
944964
}
945965
else
@@ -949,14 +969,7 @@ opfunc_construct_n (vm_instr_t instr, /**< instruction */
949969
ret_value = get_arg_completion;
950970
}
951971

952-
for (ecma_length_t arg_index = 0;
953-
arg_index < args_read;
954-
arg_index++)
955-
{
956-
ecma_free_value (arg_values[arg_index], true);
957-
}
958-
959-
MEM_FINALIZE_LOCAL_ARRAY (arg_values);
972+
ecma_free_values_collection (arg_collection_p, true);
960973

961974
ECMA_FINALIZE (constructor_value);
962975

@@ -987,18 +1000,30 @@ opfunc_array_decl (vm_instr_t instr, /**< instruction */
9871000

9881001
ecma_completion_value_t ret_value = ecma_make_empty_completion_value ();
9891002

990-
MEM_DEFINE_LOCAL_ARRAY (arg_values, args_number, ecma_value_t);
1003+
ecma_collection_header_t *arg_collection_p = ecma_new_values_collection (NULL, 0, true);
9911004

992-
ecma_length_t args_read;
993-
ecma_completion_value_t get_arg_completion = fill_varg_list (frame_ctx_p,
994-
args_number,
995-
arg_values,
996-
&args_read);
1005+
ecma_completion_value_t get_arg_completion = vm_fill_varg_list (frame_ctx_p,
1006+
args_number,
1007+
arg_collection_p);
1008+
ecma_length_t args_read = arg_collection_p->unit_number;
9971009

9981010
if (ecma_is_completion_value_empty (get_arg_completion))
9991011
{
10001012
JERRY_ASSERT (args_read == args_number);
10011013

1014+
MEM_DEFINE_LOCAL_ARRAY (arg_values, args_read, ecma_value_t);
1015+
1016+
ecma_collection_iterator_t arg_collection_iter;
1017+
ecma_collection_iterator_init (&arg_collection_iter,
1018+
arg_collection_p);
1019+
1020+
for (ecma_length_t arg_index = 0;
1021+
ecma_collection_iterator_next (&arg_collection_iter);
1022+
arg_index++)
1023+
{
1024+
arg_values[arg_index] = *arg_collection_iter.current_value_p;
1025+
}
1026+
10021027
ECMA_TRY_CATCH (array_obj_value,
10031028
ecma_op_create_array_object (arg_values,
10041029
args_number,
@@ -1010,6 +1035,8 @@ opfunc_array_decl (vm_instr_t instr, /**< instruction */
10101035
array_obj_value);
10111036

10121037
ECMA_FINALIZE (array_obj_value);
1038+
1039+
MEM_FINALIZE_LOCAL_ARRAY (arg_values);
10131040
}
10141041
else
10151042
{
@@ -1018,14 +1045,7 @@ opfunc_array_decl (vm_instr_t instr, /**< instruction */
10181045
ret_value = get_arg_completion;
10191046
}
10201047

1021-
for (ecma_length_t arg_index = 0;
1022-
arg_index < args_read;
1023-
arg_index++)
1024-
{
1025-
ecma_free_value (arg_values[arg_index], true);
1026-
}
1027-
1028-
MEM_FINALIZE_LOCAL_ARRAY (arg_values);
1048+
ecma_free_values_collection (arg_collection_p, true);
10291049

10301050
return ret_value;
10311051
} /* opfunc_array_decl */

0 commit comments

Comments
 (0)