Refactoring function call operations to return 'normal' completion values instead of 'return' completion values. Removing ECMA_FUNCTION_CALL macro.

This commit is contained in:
Ruben Ayrapetyan
2014-09-24 14:21:03 +04:00
parent 3a31bf6eb1
commit 25ec2bea17
9 changed files with 58 additions and 89 deletions
+5
View File
@@ -493,6 +493,11 @@ run_int_from_pos (opcode_counter_t start_pos,
completion = run_int_loop (&int_data); completion = run_int_loop (&int_data);
JERRY_ASSERT (ecma_is_completion_value_normal (completion)
|| ecma_is_completion_value_throw (completion)
|| ecma_is_completion_value_return (completion)
|| ecma_is_completion_value_exit (completion));
for (uint32_t reg_index = 0; for (uint32_t reg_index = 0;
reg_index < regs_num; reg_index < regs_num;
reg_index++) reg_index++)
+9 -9
View File
@@ -89,9 +89,9 @@ opfunc_call_1 (opcode_t opdata __unused, int_data_t *int_data)
ecma_object_t *func_obj_p = ECMA_GET_POINTER (func_value.u.value.value); ecma_object_t *func_obj_p = ECMA_GET_POINTER (func_value.u.value.value);
ECMA_TRY_CATCH (this_value, ecma_op_implicit_this_value (int_data->lex_env_p), ret_value); ECMA_TRY_CATCH (this_value, ecma_op_implicit_this_value (int_data->lex_env_p), ret_value);
ECMA_FUNCTION_CALL (call_completion, ECMA_TRY_CATCH (call_completion,
ecma_op_function_call (func_obj_p, this_value.u.value, &arg_value.u.value, 1), ecma_op_function_call (func_obj_p, this_value.u.value, &arg_value.u.value, 1),
ret_value); ret_value);
ret_value = set_variable_value (int_data, lhs_var_idx, call_completion.u.value); ret_value = set_variable_value (int_data, lhs_var_idx, call_completion.u.value);
@@ -697,9 +697,9 @@ opfunc_call_0 (opcode_t opdata, /**< operation data */
ecma_object_t *func_obj_p = ECMA_GET_POINTER (func_value.u.value.value); ecma_object_t *func_obj_p = ECMA_GET_POINTER (func_value.u.value.value);
ECMA_TRY_CATCH (this_value, ecma_op_implicit_this_value (int_data->lex_env_p), ret_value); ECMA_TRY_CATCH (this_value, ecma_op_implicit_this_value (int_data->lex_env_p), ret_value);
ECMA_FUNCTION_CALL (call_completion, ECMA_TRY_CATCH (call_completion,
ecma_op_function_call (func_obj_p, this_value.u.value, NULL, 0), ecma_op_function_call (func_obj_p, this_value.u.value, NULL, 0),
ret_value); ret_value);
ret_value = set_variable_value (int_data, lhs_var_idx, call_completion.u.value); ret_value = set_variable_value (int_data, lhs_var_idx, call_completion.u.value);
@@ -771,9 +771,9 @@ opfunc_call_n (opcode_t opdata, /**< operation data */
{ {
ecma_object_t *func_obj_p = ECMA_GET_POINTER (func_value.u.value.value); ecma_object_t *func_obj_p = ECMA_GET_POINTER (func_value.u.value.value);
ECMA_FUNCTION_CALL (call_completion, ECMA_TRY_CATCH (call_completion,
ecma_op_function_call (func_obj_p, this_value.u.value, arg_values, args_number), ecma_op_function_call (func_obj_p, this_value.u.value, arg_values, args_number),
ret_value); ret_value);
ret_value = set_variable_value (int_data, lhs_var_idx, call_completion.u.value); ret_value = set_variable_value (int_data, lhs_var_idx, call_completion.u.value);
@@ -144,8 +144,8 @@ ecma_builtin_global_object_is_nan (ecma_value_t arg) /**< routine's first argume
bool is_nan = ecma_number_is_nan (*num_p); bool is_nan = ecma_number_is_nan (*num_p);
ret_value = ecma_make_return_completion_value (ecma_make_simple_value (is_nan ? ECMA_SIMPLE_VALUE_TRUE ret_value = ecma_make_simple_completion_value (is_nan ? ECMA_SIMPLE_VALUE_TRUE
: ECMA_SIMPLE_VALUE_FALSE)); : ECMA_SIMPLE_VALUE_FALSE);
ECMA_FINALIZE (num_value); ECMA_FINALIZE (num_value);
@@ -173,8 +173,8 @@ ecma_builtin_global_object_is_finite (ecma_value_t arg) /**< routine's first arg
bool is_finite = !(ecma_number_is_nan (*num_p) bool is_finite = !(ecma_number_is_nan (*num_p)
|| ecma_number_is_infinity (*num_p)); || ecma_number_is_infinity (*num_p));
ret_value = ecma_make_return_completion_value (ecma_make_simple_value (is_finite ? ECMA_SIMPLE_VALUE_TRUE ret_value = ecma_make_simple_completion_value (is_finite ? ECMA_SIMPLE_VALUE_TRUE
: ECMA_SIMPLE_VALUE_FALSE)); : ECMA_SIMPLE_VALUE_FALSE);
ECMA_FINALIZE (num_value); ECMA_FINALIZE (num_value);
@@ -190,7 +190,7 @@ ecma_builtin_math_object_abs (ecma_value_t arg) /**< routine's argument */
*num_p = ecma_number_negate (arg_num); *num_p = ecma_number_negate (arg_num);
} }
ret_value = ecma_make_return_completion_value (ecma_make_number_value (num_p)); ret_value = ecma_make_normal_completion_value (ecma_make_number_value (num_p));
ECMA_FINALIZE (arg_num_value); ECMA_FINALIZE (arg_num_value);
@@ -420,7 +420,7 @@ ecma_builtin_math_object_max (ecma_value_t args[], /**< arguments list */
ecma_number_t *num_p = ecma_alloc_number (); ecma_number_t *num_p = ecma_alloc_number ();
*num_p = ret_num; *num_p = ret_num;
return ecma_make_return_completion_value (ecma_make_number_value (num_p)); return ecma_make_normal_completion_value (ecma_make_number_value (num_p));
} /* ecma_builtin_math_object_max */ } /* ecma_builtin_math_object_max */
/** /**
@@ -510,7 +510,7 @@ ecma_builtin_math_object_min (ecma_value_t args[], /**< arguments list */
ecma_number_t *num_p = ecma_alloc_number (); ecma_number_t *num_p = ecma_alloc_number ();
*num_p = ret_num; *num_p = ret_num;
return ecma_make_return_completion_value (ecma_make_number_value (num_p)); return ecma_make_normal_completion_value (ecma_make_number_value (num_p));
} /* ecma_builtin_math_object_min */ } /* ecma_builtin_math_object_min */
/** /**
@@ -567,7 +567,7 @@ ecma_builtin_math_object_random (void)
ecma_number_t *rand_p = ecma_alloc_number (); ecma_number_t *rand_p = ecma_alloc_number ();
*rand_p = rand; *rand_p = rand;
return ecma_make_return_completion_value (ecma_make_number_value (rand_p)); return ecma_make_normal_completion_value (ecma_make_number_value (rand_p));
} /* ecma_builtin_math_object_random */ } /* ecma_builtin_math_object_random */
/** /**
@@ -620,7 +620,7 @@ ecma_builtin_math_object_round (ecma_value_t arg) /**< routine's argument */
} }
} }
ret_value = ecma_make_return_completion_value (ecma_make_number_value (num_p)); ret_value = ecma_make_normal_completion_value (ecma_make_number_value (num_p));
ECMA_FINALIZE (arg_num_value); ECMA_FINALIZE (arg_num_value);
@@ -707,7 +707,7 @@ ecma_builtin_math_object_sqrt (ecma_value_t arg) /**< routine's argument */
ecma_number_t *num_p = ecma_alloc_number (); ecma_number_t *num_p = ecma_alloc_number ();
*num_p = ret_num; *num_p = ret_num;
ret_value = ecma_make_return_completion_value (ecma_make_number_value (num_p)); ret_value = ecma_make_normal_completion_value (ecma_make_number_value (num_p));
ECMA_FINALIZE (arg_num_value); ECMA_FINALIZE (arg_num_value);
@@ -121,25 +121,20 @@ ecma_builtin_object_dispatch_call (ecma_value_t *arguments_list_p, /**< argument
{ {
JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL); JERRY_ASSERT (arguments_list_len == 0 || arguments_list_p != NULL);
ecma_completion_value_t ret_value;
if (arguments_list_len == 0 if (arguments_list_len == 0
|| ecma_is_value_undefined (arguments_list_p[0]) || ecma_is_value_undefined (arguments_list_p[0])
|| ecma_is_value_null (arguments_list_p [0])) || ecma_is_value_null (arguments_list_p [0]))
{ {
return ecma_builtin_object_dispatch_construct (arguments_list_p, arguments_list_len); ret_value = ecma_builtin_object_dispatch_construct (arguments_list_p, arguments_list_len);
} }
else else
{ {
ecma_completion_value_t new_obj_value = ecma_op_to_object (arguments_list_p [0]); ret_value = ecma_op_to_object (arguments_list_p [0]);
if (!ecma_is_completion_value_normal (new_obj_value))
{
return new_obj_value;
}
else
{
return ecma_make_return_completion_value (new_obj_value.u.value);
}
} }
return ret_value;
} /* ecma_builtin_object_dispatch_call */ } /* ecma_builtin_object_dispatch_call */
/** /**
@@ -157,7 +152,7 @@ ecma_builtin_object_dispatch_construct (ecma_value_t *arguments_list_p, /**< arg
{ {
ecma_object_t *obj_p = ecma_op_create_object_object_noarg (); ecma_object_t *obj_p = ecma_op_create_object_object_noarg ();
return ecma_make_return_completion_value (ecma_make_object_value (obj_p)); return ecma_make_normal_completion_value (ecma_make_object_value (obj_p));
} }
else else
{ {
@@ -169,7 +164,7 @@ ecma_builtin_object_dispatch_construct (ecma_value_t *arguments_list_p, /**< arg
} }
else else
{ {
return ecma_make_return_completion_value (new_obj_value.u.value); return ecma_make_normal_completion_value (new_obj_value.u.value);
} }
} }
} /* ecma_builtin_object_dispatch_construct */ } /* ecma_builtin_object_dispatch_construct */
+8 -10
View File
@@ -532,11 +532,9 @@ ecma_op_function_call (ecma_object_t *func_obj_p, /**< Function object */
local_env_p, local_env_p,
is_strict, is_strict,
false); false);
if (ecma_is_completion_value_normal (completion)) if (ecma_is_completion_value_return (completion))
{ {
JERRY_ASSERT(ecma_is_completion_value_empty (completion)); ret_value = ecma_make_normal_completion_value (completion.u.value);
ret_value = ecma_make_return_completion_value (ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED));
} }
else else
{ {
@@ -622,12 +620,12 @@ ecma_op_function_construct (ecma_object_t *func_obj_p, /**< Function object */
ecma_deref_object (prototype_p); ecma_deref_object (prototype_p);
// 8. // 8.
ECMA_FUNCTION_CALL (call_completion, ECMA_TRY_CATCH (call_completion,
ecma_op_function_call (func_obj_p, ecma_op_function_call (func_obj_p,
ecma_make_object_value (obj_p), ecma_make_object_value (obj_p),
arguments_list_p, arguments_list_p,
arguments_list_len), arguments_list_len),
ret_value); ret_value);
ecma_value_t obj_value; ecma_value_t obj_value;
+3 -3
View File
@@ -240,9 +240,9 @@ ecma_op_put_value (ecma_reference_t ref, /**< ECMA-reference */
ecma_object_t *setter_p = ECMA_GET_POINTER(prop_p->u.named_accessor_property.set_p); ecma_object_t *setter_p = ECMA_GET_POINTER(prop_p->u.named_accessor_property.set_p);
JERRY_ASSERT (setter_p != NULL); JERRY_ASSERT (setter_p != NULL);
ECMA_FUNCTION_CALL (call_completion, ECMA_TRY_CATCH (call_completion,
ecma_op_function_call (setter_p, base, &value, 1), ecma_op_function_call (setter_p, base, &value, 1),
ret_value); ret_value);
ret_value = ecma_make_empty_completion_value (); ret_value = ecma_make_empty_completion_value ();
+12 -12
View File
@@ -159,12 +159,12 @@ ecma_op_general_object_get (ecma_object_t *obj_p, /**< the object */
{ {
ecma_completion_value_t ret_value; ecma_completion_value_t ret_value;
ECMA_FUNCTION_CALL (call_completion, ECMA_TRY_CATCH (call_completion,
ecma_op_function_call (getter_p, ecma_op_function_call (getter_p,
ecma_make_object_value (obj_p), ecma_make_object_value (obj_p),
NULL, NULL,
0), 0),
ret_value); ret_value);
ret_value = ecma_make_normal_completion_value (ecma_copy_value (call_completion.u.value, true)); ret_value = ecma_make_normal_completion_value (ecma_copy_value (call_completion.u.value, true));
@@ -308,12 +308,12 @@ ecma_op_general_object_put (ecma_object_t *obj_p, /**< the object */
ecma_completion_value_t ret_value; ecma_completion_value_t ret_value;
ECMA_FUNCTION_CALL (call_completion, ECMA_TRY_CATCH (call_completion,
ecma_op_function_call (setter_p, ecma_op_function_call (setter_p,
ecma_make_object_value (obj_p), ecma_make_object_value (obj_p),
&value, &value,
1), 1),
ret_value); ret_value);
ret_value = ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_TRUE); ret_value = ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_TRUE);
+3 -32
View File
@@ -39,42 +39,13 @@
{ \ { \
JERRY_ASSERT(ecma_is_completion_value_normal (var)) JERRY_ASSERT(ecma_is_completion_value_normal (var))
/**
* The macro defines function call block that executes function call 'op',
* assigns call's completion value to 'var', and checks for exceptions
* that might be thrown during initialization.
*
* If no return values is not return completion value,
* then code after the function call block is executed.
* Otherwise, completion value is just copied to return_value.
*
* Note:
* Each ECMA_FUNCTION_CALL should have it's own corresponding ECMA_FINALIZE
* statement with same argument as corresponding ECMA_FUNCTION_CALL's first argument.
*/
#define ECMA_FUNCTION_CALL(var, op, return_value) \
ecma_completion_value_t var = op; \
if (unlikely (!ecma_is_completion_value_return (var))) \
{ \
return_value = ecma_copy_completion_value (var); \
} \
else \
{ \
JERRY_ASSERT(!ecma_is_completion_value_normal (var))
/**
* The define is not used. It is just for vera++ style checker that wants to find closing pair for all opening braces
*/
#define ECMA_FUNCTION_CALL_CLOSING_BRACKET_FOR_VERA_STYLE_CHECKER }
/** /**
* The macro marks end of code block that is defined by corresponding * The macro marks end of code block that is defined by corresponding
* ECMA_TRY_CATCH / ECMA_FUNCTION_CALL and frees variable, initialized * ECMA_TRY_CATCH and frees variable, initialized by the ECMA_TRY_CATCH.
* by the ECMA_TRY_CATCH / ECMA_FUNCTION_CALL.
* *
* Note: * Note:
* Each ECMA_TRY_CATCH / ECMA_FUNCTION_CALL should be followed by ECMA_FINALIZE with same argument * Each ECMA_TRY_CATCH should be followed by ECMA_FINALIZE with same argument
* as corresponding ECMA_TRY_CATCH's / ECMA_FUNCTION_CALL's first argument. * as corresponding ECMA_TRY_CATCH's first argument.
*/ */
#define ECMA_FINALIZE(var) } \ #define ECMA_FINALIZE(var) } \
ecma_free_completion_value (var) ecma_free_completion_value (var)