From b3b1ba020681834de62c6eede89278e9b3384a59 Mon Sep 17 00:00:00 2001 From: "e.gavrin" Date: Tue, 12 Aug 2014 01:13:32 +0400 Subject: [PATCH] Formatting fixes in libcoreint --- src/libcoreint/opcode-structures.h | 66 +- src/libcoreint/opcodes.c | 1084 ++++++++++++++-------------- src/libcoreint/opcodes.h | 38 +- 3 files changed, 603 insertions(+), 585 deletions(-) diff --git a/src/libcoreint/opcode-structures.h b/src/libcoreint/opcode-structures.h index c73d18a53..b94bc3fae 100644 --- a/src/libcoreint/opcode-structures.h +++ b/src/libcoreint/opcode-structures.h @@ -14,41 +14,42 @@ */ #ifndef OPCODE_STRUCTURES_H -#define OPCODE_STRUCTURES_H +#define OPCODE_STRUCTURES_H -// Jerry bytecode ver:07/04/2014 -#define OP_DEF(name, list) struct __op_##name { list ; } ; +#define OP_DEF(name, list) struct __op_##name { list ; } ; #define OP_CODE_DECL_VOID(name) \ struct __op_##name { T_IDX __do_not_use; }; \ - OPCODE getop_##name ( void ); + OPCODE getop_##name (void); -#define OP_CODE_DECL(name, type, ... ) \ - OP_DEF (name, type##_DECL( __VA_ARGS__ ) ) \ - OPCODE getop_##name ( type ); +#define OP_CODE_DECL(name, type, ...) \ + OP_DEF (name, type##_DECL(__VA_ARGS__)) \ + OPCODE getop_##name (type); #define T_IDX_IDX T_IDX, T_IDX #define T_IDX_IDX_IDX T_IDX, T_IDX, T_IDX #define T_IDX_DECL(name) T_IDX name #define T_IDX_IDX_DECL(name1, name2) \ - T_IDX_DECL( name1 ) ; \ - T_IDX_DECL( name2 ) + T_IDX_DECL (name1) ; \ + T_IDX_DECL (name2) #define T_IDX_IDX_IDX_DECL(name1, name2, name3) \ - T_IDX_DECL( name1 ) ; \ - T_IDX_DECL( name2 ); \ - T_IDX_DECL( name3 ) + T_IDX_DECL (name1) ; \ + T_IDX_DECL (name2); \ + T_IDX_DECL (name3) #define GETOP_IMPL_0(name) \ - OPCODE getop_##name () { \ + OPCODE getop_##name () \ + { \ OPCODE opdata; \ opdata.op_idx = __op__idx_##name; \ return opdata; \ } #define GETOP_IMPL_1(name, field1) \ - OPCODE getop_##name (T_IDX arg1) { \ + OPCODE getop_##name (T_IDX arg1) \ + { \ OPCODE opdata; \ opdata.op_idx = __op__idx_##name; \ opdata.data.name.field1 = arg1; \ @@ -56,7 +57,8 @@ } #define GETOP_IMPL_2(name, field1, field2) \ - OPCODE getop_##name (T_IDX arg1, T_IDX arg2) { \ + OPCODE getop_##name (T_IDX arg1, T_IDX arg2) \ + { \ OPCODE opdata; \ opdata.op_idx = __op__idx_##name; \ opdata.data.name.field1 = arg1; \ @@ -65,7 +67,8 @@ } #define GETOP_IMPL_3(name, field1, field2, field3) \ - OPCODE getop_##name (T_IDX arg1, T_IDX arg2, T_IDX arg3) { \ + OPCODE getop_##name (T_IDX arg1, T_IDX arg2, T_IDX arg3) \ + { \ OPCODE opdata; \ opdata.op_idx = __op__idx_##name; \ opdata.data.name.field1 = arg1; \ @@ -287,73 +290,73 @@ OP_CODE_DECL (assignment, T_IDX_IDX_IDX, // Functions calls, declarations and argument handling -/** a = name(); */ +/** a = name (); */ OP_CODE_DECL (call_0, T_IDX_IDX, lhs, name_lit_idx) -/** a = name(arg1); */ +/** a = name (arg1); */ OP_CODE_DECL (call_1, T_IDX_IDX_IDX, lhs, name_lit_idx, arg1_lit_idx) -/** a = name(arg1, ... */ +/** a = name (arg1, ... */ OP_CODE_DECL (call_n, T_IDX_IDX_IDX, lhs, name_lit_idx, arg1_lit_idx) -/** a = new name(); */ +/** a = new name (); */ OP_CODE_DECL (construct_0, T_IDX_IDX, lhs, name_lit_idx) -/** a = new name(arg1); */ +/** a = new name (arg1); */ OP_CODE_DECL (construct_1, T_IDX_IDX_IDX, lhs, name_lit_idx, arg1_lit_idx) -/** a = new name(arg1, ... */ +/** a = new name (arg1, ... */ OP_CODE_DECL (construct_n, T_IDX_IDX_IDX, lhs, name_lit_idx, arg1_lit_idx) -/** name(); */ +/** name (); */ OP_CODE_DECL (func_decl_0, T_IDX, name_lit_idx) -/** name(arg1); */ +/** name (arg1); */ OP_CODE_DECL (func_decl_1, T_IDX_IDX, name_lit_idx, arg1_lit_idx) -/** name(arg1, arg2); */ +/** name (arg1, arg2); */ OP_CODE_DECL (func_decl_2, T_IDX_IDX_IDX, name_lit_idx, arg1_lit_idx, arg2_lit_idx) -/** name(arg1, arg2, ... */ +/** name (arg1, arg2, ... */ OP_CODE_DECL (func_decl_n, T_IDX_IDX_IDX, name_lit_idx, arg1_lit_idx, arg2_lit_idx) -/** a = name(); */ +/** a = name (); */ OP_CODE_DECL (func_expr_0, T_IDX_IDX, lhs, name_lit_idx) -/** a = name(arg1); */ +/** a = name (arg1); */ OP_CODE_DECL (func_expr_1, T_IDX_IDX_IDX, lhs, name_lit_idx, arg1_lit_idx) -/** a = name(arg1, ... */ +/** a = name (arg1, ... */ OP_CODE_DECL (func_expr_n, T_IDX_IDX_IDX, lhs, name_lit_idx, @@ -484,7 +487,6 @@ OP_CODE_DECL (var_decl, T_IDX, OP_CODE_DECL (reg_var_decl, T_IDX_IDX, min, max) - -#endif /* OPCODE_STRUCTURES_H */ - + +#endif /* OPCODE_STRUCTURES_H */ diff --git a/src/libcoreint/opcodes.c b/src/libcoreint/opcodes.c index 01405590b..0755b4463 100644 --- a/src/libcoreint/opcodes.c +++ b/src/libcoreint/opcodes.c @@ -72,52 +72,52 @@ typedef struct * Initialize string literal copy. */ static void __unused -init_string_literal_copy(T_IDX idx, /**< literal identifier */ - string_literal_copy *str_lit_descr_p) /**< pointer to string literal copy descriptor */ +init_string_literal_copy (T_IDX idx, /**< literal identifier */ + string_literal_copy *str_lit_descr_p) /**< pointer to string literal copy descriptor */ { - JERRY_ASSERT( str_lit_descr_p != NULL ); + JERRY_ASSERT (str_lit_descr_p != NULL); - ssize_t sz = try_get_string_by_idx( idx, + ssize_t sz = try_get_string_by_idx (idx, str_lit_descr_p->literal_copy, - sizeof(str_lit_descr_p->literal_copy)); - if ( sz > 0 ) - { - str_lit_descr_p->str_p = str_lit_descr_p->literal_copy; - } + sizeof (str_lit_descr_p->literal_copy)); + if (sz > 0) + { + str_lit_descr_p->str_p = str_lit_descr_p->literal_copy; + } else - { - JERRY_ASSERT( sz < 0 ); + { + JERRY_ASSERT (sz < 0); - ssize_t req_sz = -sz; + ssize_t req_sz = -sz; - str_lit_descr_p->str_p = mem_heap_alloc_block( (size_t)req_sz, - MEM_HEAP_ALLOC_SHORT_TERM); + str_lit_descr_p->str_p = mem_heap_alloc_block ((size_t) req_sz, + MEM_HEAP_ALLOC_SHORT_TERM); - sz = try_get_string_by_idx( idx, - str_lit_descr_p->str_p, - req_sz); + sz = try_get_string_by_idx (idx, + str_lit_descr_p->str_p, + req_sz); - JERRY_ASSERT( sz > 0 ); - } + JERRY_ASSERT (sz > 0); + } } /* init_string_literal */ /** * Free string literal copy. */ static void __unused -free_string_literal_copy(string_literal_copy *str_lit_descr_p) /**< string literal copy descriptor */ +free_string_literal_copy (string_literal_copy *str_lit_descr_p) /**< string literal copy descriptor */ { - JERRY_ASSERT( str_lit_descr_p != NULL ); - JERRY_ASSERT( str_lit_descr_p->str_p != NULL ); + JERRY_ASSERT (str_lit_descr_p != NULL); + JERRY_ASSERT (str_lit_descr_p->str_p != NULL); - if ( str_lit_descr_p->str_p == str_lit_descr_p->literal_copy ) - { - /* copy is inside descriptor */ - } + if (str_lit_descr_p->str_p == str_lit_descr_p->literal_copy) + { + /* copy is inside descriptor */ + } else - { - mem_heap_free_block( str_lit_descr_p->str_p); - } + { + mem_heap_free_block (str_lit_descr_p->str_p); + } str_lit_descr_p->str_p = NULL; @@ -135,15 +135,17 @@ free_string_literal_copy(string_literal_copy *str_lit_descr_p) /**< string liter * false - otherwise. */ static bool -do_strict_eval_arguments_check( ecma_reference_t ref) /**< ECMA-reference */ +do_strict_eval_arguments_check (ecma_reference_t ref) /**< ECMA-reference */ { - FIXME( Replace strcmp with ecma_char_t[] comparator ); - return ( ref.is_strict - && ( __strcmp( (char*)ref.referenced_name_p, (char*)ecma_get_magic_string( ECMA_MAGIC_STRING_EVAL)) == 0 - || __strcmp( (char*)ref.referenced_name_p, (char*)ecma_get_magic_string( ECMA_MAGIC_STRING_ARGUMENTS)) == 0 ) - && ( ref.base.value_type == ECMA_TYPE_OBJECT ) - && ( ECMA_GET_POINTER( ref.base.value) != NULL ) - && ( ( (ecma_object_t*) ECMA_GET_POINTER( ref.base.value) )->is_lexical_environment ) ); + FIXME (Replace strcmp with ecma_char_t[] comparator); + return (ref.is_strict + && (__strcmp ((char*) ref.referenced_name_p, + (char*) ecma_get_magic_string (ECMA_MAGIC_STRING_EVAL)) == 0 + || __strcmp ((char*) ref.referenced_name_p, + (char*) ecma_get_magic_string (ECMA_MAGIC_STRING_ARGUMENTS)) == 0) + && (ref.base.value_type == ECMA_TYPE_OBJECT) + && (ECMA_GET_POINTER (ref.base.value) != NULL) + && (((ecma_object_t*) ECMA_GET_POINTER (ref.base.value))->is_lexical_environment)); } /* do_strict_eval_arguments_check */ /** @@ -153,22 +155,22 @@ do_strict_eval_arguments_check( ecma_reference_t ref) /**< ECMA-reference */ * Returned value must be freed with ecma_free_completion_value */ static ecma_completion_value_t -get_variable_value(struct __int_data *int_data, /**< interpreter context */ - T_IDX var_idx, /**< variable identifier */ - bool do_eval_or_arguments_check) /** run 'strict eval or arguments reference' check +get_variable_value (struct __int_data *int_data, /**< interpreter context */ + T_IDX var_idx, /**< variable identifier */ + bool do_eval_or_arguments_check) /** run 'strict eval or arguments reference' check See also: do_strict_eval_arguments_check */ { ecma_completion_value_t ret_value; - if ( var_idx >= int_data->min_reg_num - && var_idx <= int_data->max_reg_num ) + if (var_idx >= int_data->min_reg_num + && var_idx <= int_data->max_reg_num) { ecma_value_t reg_value = int_data->regs_p[ var_idx - int_data->min_reg_num ]; - JERRY_ASSERT( !ecma_is_value_empty( reg_value) ); + JERRY_ASSERT (!ecma_is_value_empty (reg_value)); ret_value = ecma_make_completion_value (ECMA_COMPLETION_TYPE_NORMAL, - ecma_copy_value( reg_value, true), + ecma_copy_value (reg_value, true), ECMA_TARGET_ID_RESERVED); } else @@ -176,23 +178,23 @@ get_variable_value(struct __int_data *int_data, /**< interpreter context */ string_literal_copy var_name; ecma_reference_t ref; - init_string_literal_copy( var_idx, &var_name); - ref = ecma_op_get_identifier_reference( int_data->lex_env_p, - var_name.str_p, - int_data->is_strict); + init_string_literal_copy (var_idx, &var_name); + ref = ecma_op_get_identifier_reference (int_data->lex_env_p, + var_name.str_p, + int_data->is_strict); - if ( unlikely( do_eval_or_arguments_check - && do_strict_eval_arguments_check( ref) ) ) + if (unlikely (do_eval_or_arguments_check + && do_strict_eval_arguments_check (ref))) { - ret_value = ecma_make_throw_value( ecma_new_standard_error( ECMA_ERROR_SYNTAX)); + ret_value = ecma_make_throw_value (ecma_new_standard_error (ECMA_ERROR_SYNTAX)); } else { - ret_value = ecma_op_get_value( ref); + ret_value = ecma_op_get_value (ref); } - ecma_free_reference( ref); - free_string_literal_copy( &var_name); + ecma_free_reference (ref); + free_string_literal_copy (&var_name); } return ret_value; @@ -205,47 +207,47 @@ get_variable_value(struct __int_data *int_data, /**< interpreter context */ * Returned value must be freed with ecma_free_completion_value */ static ecma_completion_value_t -set_variable_value(struct __int_data *int_data, /**< interpreter context */ - T_IDX var_idx, /**< variable identifier */ - ecma_value_t value) /**< value to set */ +set_variable_value (struct __int_data *int_data, /**< interpreter context */ + T_IDX var_idx, /**< variable identifier */ + ecma_value_t value) /**< value to set */ { ecma_completion_value_t ret_value; - if ( var_idx >= int_data->min_reg_num - && var_idx <= int_data->max_reg_num ) + if (var_idx >= int_data->min_reg_num + && var_idx <= int_data->max_reg_num) { ecma_value_t reg_value = int_data->regs_p[ var_idx - int_data->min_reg_num ]; - if ( !ecma_is_value_empty( reg_value) ) + if (!ecma_is_value_empty (reg_value)) { - ecma_free_value( reg_value, true); + ecma_free_value (reg_value, true); } - int_data->regs_p[ var_idx - int_data->min_reg_num ] = ecma_copy_value( value, true); + int_data->regs_p[ var_idx - int_data->min_reg_num ] = ecma_copy_value (value, true); - ret_value = ecma_make_empty_completion_value(); + ret_value = ecma_make_empty_completion_value (); } else { string_literal_copy var_name; ecma_reference_t ref; - init_string_literal_copy( var_idx, &var_name); - ref = ecma_op_get_identifier_reference( int_data->lex_env_p, - var_name.str_p, - int_data->is_strict); + init_string_literal_copy (var_idx, &var_name); + ref = ecma_op_get_identifier_reference (int_data->lex_env_p, + var_name.str_p, + int_data->is_strict); - if ( unlikely( do_strict_eval_arguments_check( ref) ) ) + if (unlikely (do_strict_eval_arguments_check (ref))) { - ret_value = ecma_make_throw_value( ecma_new_standard_error( ECMA_ERROR_SYNTAX)); + ret_value = ecma_make_throw_value (ecma_new_standard_error (ECMA_ERROR_SYNTAX)); } else { - ret_value = ecma_op_put_value( ref, value); + ret_value = ecma_op_put_value (ref, value); } - ecma_free_reference( ref); - free_string_literal_copy( &var_name); + ecma_free_reference (ref); + free_string_literal_copy (&var_name); } return ret_value; @@ -267,118 +269,130 @@ typedef enum * Perform ECMA number arithmetic operation. * * The algorithm of the operation is following: - * leftNum = ToNumber( leftValue); - * rightNum = ToNumber( rightValue); + * leftNum = ToNumber (leftValue); + * rightNum = ToNumber (rightValue); * result = leftNum ArithmeticOp rightNum; * * @return completion value * Returned value must be freed with ecma_free_completion_value */ static ecma_completion_value_t -do_number_arithmetic(struct __int_data *int_data, /**< interpreter context */ - T_IDX dst_var_idx, /**< destination variable identifier */ - number_arithmetic_op op, /**< number arithmetic operation */ - ecma_value_t left_value, /**< left value */ - ecma_value_t right_value) /** right value */ +do_number_arithmetic (struct __int_data *int_data, /**< interpreter context */ + T_IDX dst_var_idx, /**< destination variable identifier */ + number_arithmetic_op op, /**< number arithmetic operation */ + ecma_value_t left_value, /**< left value */ + ecma_value_t right_value) /** right value */ { ecma_completion_value_t ret_value; - ECMA_TRY_CATCH(num_left_value, ecma_op_to_number( left_value), ret_value); - ECMA_TRY_CATCH(num_right_value, ecma_op_to_number( right_value), ret_value); + ECMA_TRY_CATCH (num_left_value, ecma_op_to_number (left_value), ret_value); + ECMA_TRY_CATCH (num_right_value, ecma_op_to_number (right_value), ret_value); ecma_number_t *left_p, *right_p, *res_p; - left_p = (ecma_number_t*)ECMA_GET_POINTER( num_left_value.value.value); - right_p = (ecma_number_t*)ECMA_GET_POINTER( num_right_value.value.value); + left_p = (ecma_number_t*) ECMA_GET_POINTER (num_left_value.value.value); + right_p = (ecma_number_t*) ECMA_GET_POINTER (num_right_value.value.value); - res_p = ecma_alloc_number(); + res_p = ecma_alloc_number (); - switch ( op ) - { + switch (op) + { case number_arithmetic_addition: - *res_p = ecma_op_number_add( *left_p, *right_p); - break; - case number_arithmetic_substraction: - *res_p = ecma_op_number_substract( *left_p, *right_p); - break; - case number_arithmetic_multiplication: - *res_p = ecma_op_number_multiply( *left_p, *right_p); - break; - case number_arithmetic_division: - *res_p = ecma_op_number_divide( *left_p, *right_p); - break; - case number_arithmetic_remainder: - *res_p = ecma_op_number_remainder( *left_p, *right_p); + { + *res_p = ecma_op_number_add (*left_p, *right_p); break; } + case number_arithmetic_substraction: + { + *res_p = ecma_op_number_substract (*left_p, *right_p); + break; + } + case number_arithmetic_multiplication: + { + *res_p = ecma_op_number_multiply (*left_p, *right_p); + break; + } + case number_arithmetic_division: + { + *res_p = ecma_op_number_divide (*left_p, *right_p); + break; + } + case number_arithmetic_remainder: + { + *res_p = ecma_op_number_remainder (*left_p, *right_p); + break; + } + } - ret_value = set_variable_value(int_data, - dst_var_idx, - ecma_make_number_value( res_p)); + ret_value = set_variable_value (int_data, + dst_var_idx, + ecma_make_number_value (res_p)); - ecma_dealloc_number( res_p); + ecma_dealloc_number (res_p); - ECMA_FINALIZE( num_right_value); - ECMA_FINALIZE( num_left_value); + ECMA_FINALIZE (num_right_value); + ECMA_FINALIZE (num_left_value); return ret_value; } /* do_number_arithmetic */ #define OP_UNIMPLEMENTED_LIST(op) \ - op(call_n) \ - op(func_decl_1) \ - op(func_decl_2) \ - op(func_decl_n) \ - op(varg_1_end) \ - op(varg_2_end) \ - op(varg_3) \ - op(varg_3_end) \ - op(retval) \ - op(b_shift_left) \ - op(b_shift_right) \ - op(b_shift_uright) \ - op(b_and) \ - op(b_or) \ - op(b_xor) \ - op(logical_and) \ - op(logical_or) \ - op(equal_value_type) \ - op(not_equal_value_type) \ - op(less_or_equal_than) \ - op(greater_or_equal_than) \ - op(construct_0) \ - op(construct_1) \ - op(construct_n) \ - op(func_expr_0) \ - op(func_expr_1) \ - op(func_expr_n) \ - op(array_0) \ - op(array_1) \ - op(array_2) \ - op(array_n) \ - op(prop) \ - op(prop_access) \ - op(prop_get_decl) \ - op(prop_set_decl) \ - op(obj_0) \ - op(obj_1) \ - op(obj_2) \ - op(obj_n) \ - op(this) \ - op(delete) \ - op(typeof) \ - op(with) \ - op(end_with) \ - op(logical_not) \ - op(b_not) \ - op(instanceof) \ - op(in) \ + op (call_n) \ + op (func_decl_1) \ + op (func_decl_2) \ + op (func_decl_n) \ + op (varg_1_end) \ + op (varg_2_end) \ + op (varg_3) \ + op (varg_3_end) \ + op (retval) \ + op (b_shift_left) \ + op (b_shift_right) \ + op (b_shift_uright) \ + op (b_and) \ + op (b_or) \ + op (b_xor) \ + op (logical_and) \ + op (logical_or) \ + op (equal_value_type) \ + op (not_equal_value_type) \ + op (less_or_equal_than) \ + op (greater_or_equal_than) \ + op (construct_0) \ + op (construct_1) \ + op (construct_n) \ + op (func_expr_0) \ + op (func_expr_1) \ + op (func_expr_n) \ + op (array_0) \ + op (array_1) \ + op (array_2) \ + op (array_n) \ + op (prop) \ + op (prop_access) \ + op (prop_get_decl) \ + op (prop_set_decl) \ + op (obj_0) \ + op (obj_1) \ + op (obj_2) \ + op (obj_n) \ + op (this) \ + op (delete) \ + op (typeof) \ + op (with) \ + op (end_with) \ + op (logical_not) \ + op (b_not) \ + op (instanceof) \ + op (in) \ static char __unused unimplemented_list_end #define DEFINE_UNIMPLEMENTED_OP(op) \ - ecma_completion_value_t opfunc_ ## op(OPCODE opdata, struct __int_data *int_data) { \ - JERRY_UNIMPLEMENTED_REF_UNUSED_VARS( opdata, int_data); \ + ecma_completion_value_t opfunc_ ## op (OPCODE opdata, struct __int_data *int_data) \ + { \ + JERRY_UNIMPLEMENTED_REF_UNUSED_VARS (opdata, int_data); \ } -OP_UNIMPLEMENTED_LIST(DEFINE_UNIMPLEMENTED_OP); + +OP_UNIMPLEMENTED_LIST (DEFINE_UNIMPLEMENTED_OP); #undef DEFINE_UNIMPLEMENTED_OP /** @@ -390,95 +404,95 @@ opfunc_nop (OPCODE opdata __unused, /**< operation data */ { int_data->pos++; - return ecma_make_empty_completion_value(); + return ecma_make_empty_completion_value (); } /* opfunc_nop */ ecma_completion_value_t opfunc_call_1 (OPCODE opdata __unused, struct __int_data *int_data) -{ +{ ecma_completion_value_t ret_value; ret_value = ecma_make_empty_completion_value (); #ifdef __TARGET_HOST_x64 __printf ("%d::op_call_1:idx:%d:%d\t", - int_data->pos, - opdata.data.call_1.name_lit_idx, - opdata.data.call_1.arg1_lit_idx); + int_data->pos, + opdata.data.call_1.name_lit_idx, + opdata.data.call_1.arg1_lit_idx); #endif int_data->pos++; string_literal_copy str_value; - init_string_literal_copy( opdata.data.call_1.name_lit_idx, &str_value); + init_string_literal_copy (opdata.data.call_1.name_lit_idx, &str_value); #ifdef __TARGET_HOST_x64 - __printf("%s\n", str_value.str_p); + __printf ("%s\n", str_value.str_p); #endif - - if (!__strcmp ((const char*)str_value.str_p, "LEDToggle")) + + if (!__strcmp ((const char*) str_value.str_p, "LEDToggle")) { ECMA_TRY_CATCH (cond_value, get_variable_value (int_data, opdata.data.call_1.arg1_lit_idx, false), ret_value); - JERRY_ASSERT(cond_value.value.value_type == ECMA_TYPE_NUMBER ); - ecma_number_t * num_p = (ecma_number_t*)ECMA_GET_POINTER(cond_value.value.value); - uint32_t int_num = (uint32_t)*num_p; + JERRY_ASSERT (cond_value.value.value_type == ECMA_TYPE_NUMBER); + ecma_number_t * num_p = (ecma_number_t*) ECMA_GET_POINTER (cond_value.value.value); + uint32_t int_num = (uint32_t) * num_p; led_toggle (int_num); ret_value = ecma_make_empty_completion_value (); ECMA_FINALIZE (cond_value); } - - if (!__strcmp ((const char*)str_value.str_p, "LEDOn")) + + if (!__strcmp ((const char*) str_value.str_p, "LEDOn")) { ECMA_TRY_CATCH (cond_value, get_variable_value (int_data, opdata.data.call_1.arg1_lit_idx, false), ret_value); - JERRY_ASSERT(cond_value.value.value_type == ECMA_TYPE_NUMBER ); - ecma_number_t * num_p = (ecma_number_t*)ECMA_GET_POINTER(cond_value.value.value); - uint32_t int_num = (uint32_t)*num_p; + JERRY_ASSERT (cond_value.value.value_type == ECMA_TYPE_NUMBER); + ecma_number_t * num_p = (ecma_number_t*) ECMA_GET_POINTER (cond_value.value.value); + uint32_t int_num = (uint32_t) * num_p; led_on (int_num); ret_value = ecma_make_empty_completion_value (); ECMA_FINALIZE (cond_value); } - - if (!__strcmp ((const char*)str_value.str_p, "LEDOff")) + + if (!__strcmp ((const char*) str_value.str_p, "LEDOff")) { ECMA_TRY_CATCH (cond_value, get_variable_value (int_data, opdata.data.call_1.arg1_lit_idx, false), ret_value); - JERRY_ASSERT(cond_value.value.value_type == ECMA_TYPE_NUMBER ); - ecma_number_t * num_p = (ecma_number_t*)ECMA_GET_POINTER(cond_value.value.value); - uint32_t int_num = (uint32_t)*num_p; + JERRY_ASSERT (cond_value.value.value_type == ECMA_TYPE_NUMBER); + ecma_number_t * num_p = (ecma_number_t*) ECMA_GET_POINTER (cond_value.value.value); + uint32_t int_num = (uint32_t) * num_p; led_off (int_num); ret_value = ecma_make_empty_completion_value (); ECMA_FINALIZE (cond_value); } - - if (!__strcmp ((const char*)str_value.str_p, "LEDOnce")) + + if (!__strcmp ((const char*) str_value.str_p, "LEDOnce")) { ECMA_TRY_CATCH (cond_value, get_variable_value (int_data, opdata.data.call_1.arg1_lit_idx, false), ret_value); - JERRY_ASSERT(cond_value.value.value_type == ECMA_TYPE_NUMBER ); - ecma_number_t * num_p = (ecma_number_t*)ECMA_GET_POINTER(cond_value.value.value); - uint32_t int_num = (uint32_t)*num_p; + JERRY_ASSERT (cond_value.value.value_type == ECMA_TYPE_NUMBER); + ecma_number_t * num_p = (ecma_number_t*) ECMA_GET_POINTER (cond_value.value.value); + uint32_t int_num = (uint32_t) * num_p; led_blink_once (int_num); ret_value = ecma_make_empty_completion_value (); ECMA_FINALIZE (cond_value); } - - if (!__strcmp ((const char*)str_value.str_p, "wait")) + + if (!__strcmp ((const char*) str_value.str_p, "wait")) { ECMA_TRY_CATCH (cond_value, get_variable_value (int_data, opdata.data.call_1.arg1_lit_idx, false), ret_value); - JERRY_ASSERT(cond_value.value.value_type == ECMA_TYPE_NUMBER ); - ecma_number_t * num_p = (ecma_number_t*)ECMA_GET_POINTER(cond_value.value.value); - uint32_t int_num = (uint32_t)*num_p; + JERRY_ASSERT (cond_value.value.value_type == ECMA_TYPE_NUMBER); + ecma_number_t * num_p = (ecma_number_t*) ECMA_GET_POINTER (cond_value.value.value); + uint32_t int_num = (uint32_t) * num_p; wait_ms (int_num); ret_value = ecma_make_empty_completion_value (); ECMA_FINALIZE (cond_value); } if (!__strcmp ((const char *) str_value.str_p, "exit")) - { - ECMA_TRY_CATCH (cond_value, get_variable_value (int_data, opdata.data.call_1.arg1_lit_idx, false), ret_value); - JERRY_ASSERT(cond_value.value.value_type == ECMA_TYPE_NUMBER ); - ecma_number_t * num_p = (ecma_number_t*)ECMA_GET_POINTER(cond_value.value.value); - opfunc_exitval (getop_exitval ((T_IDX)*num_p), int_data); - ret_value = ecma_make_empty_completion_value (); - ECMA_FINALIZE (cond_value); - } + { + ECMA_TRY_CATCH (cond_value, get_variable_value (int_data, opdata.data.call_1.arg1_lit_idx, false), ret_value); + JERRY_ASSERT (cond_value.value.value_type == ECMA_TYPE_NUMBER); + ecma_number_t * num_p = (ecma_number_t*) ECMA_GET_POINTER (cond_value.value.value); + opfunc_exitval (getop_exitval ((T_IDX) * num_p), int_data); + ret_value = ecma_make_empty_completion_value (); + ECMA_FINALIZE (cond_value); + } free_string_literal_copy (&str_value); @@ -501,23 +515,23 @@ opfunc_is_true_jmp (OPCODE opdata, /**< operation data */ ecma_completion_value_t ret_value; - ECMA_TRY_CATCH(cond_value, get_variable_value( int_data, cond_var_idx, false), ret_value); + ECMA_TRY_CATCH (cond_value, get_variable_value (int_data, cond_var_idx, false), ret_value); - ecma_completion_value_t to_bool_completion = ecma_op_to_boolean( cond_value.value); - JERRY_ASSERT( ecma_is_completion_value_normal( to_bool_completion) ); + ecma_completion_value_t to_bool_completion = ecma_op_to_boolean (cond_value.value); + JERRY_ASSERT (ecma_is_completion_value_normal (to_bool_completion)); - if ( ecma_is_value_true( to_bool_completion.value) ) - { - int_data->pos = dst_opcode_idx; - } + if (ecma_is_value_true (to_bool_completion.value)) + { + int_data->pos = dst_opcode_idx; + } else - { - int_data->pos++; - } + { + int_data->pos++; + } - ret_value = ecma_make_empty_completion_value(); + ret_value = ecma_make_empty_completion_value (); - ECMA_FINALIZE(cond_value); + ECMA_FINALIZE (cond_value); return ret_value; } /* opfunc_is_true_jmp */ @@ -538,23 +552,23 @@ opfunc_is_false_jmp (OPCODE opdata, /**< operation data */ ecma_completion_value_t ret_value; - ECMA_TRY_CATCH(cond_value, get_variable_value( int_data, cond_var_idx, false), ret_value); + ECMA_TRY_CATCH (cond_value, get_variable_value (int_data, cond_var_idx, false), ret_value); - ecma_completion_value_t to_bool_completion = ecma_op_to_boolean( cond_value.value); - JERRY_ASSERT( ecma_is_completion_value_normal( to_bool_completion) ); + ecma_completion_value_t to_bool_completion = ecma_op_to_boolean (cond_value.value); + JERRY_ASSERT (ecma_is_completion_value_normal (to_bool_completion)); - if ( !ecma_is_value_true( to_bool_completion.value) ) - { - int_data->pos = dst_opcode_idx; - } + if (!ecma_is_value_true (to_bool_completion.value)) + { + int_data->pos = dst_opcode_idx; + } else - { - int_data->pos++; - } + { + int_data->pos++; + } - ret_value = ecma_make_empty_completion_value(); + ret_value = ecma_make_empty_completion_value (); - ECMA_FINALIZE(cond_value); + ECMA_FINALIZE (cond_value); return ret_value; } /* opfunc_is_false_jmp */ @@ -571,7 +585,7 @@ opfunc_jmp (OPCODE opdata, /**< operation data */ { int_data->pos = opdata.data.jmp.opcode_idx; - return ecma_make_empty_completion_value(); + return ecma_make_empty_completion_value (); } /* opfunc_jmp */ /** @@ -584,11 +598,11 @@ ecma_completion_value_t opfunc_jmp_down (OPCODE opdata, /**< operation data */ struct __int_data *int_data) /**< interpreter context */ { - JERRY_ASSERT( int_data->pos <= int_data->pos + opdata.data.jmp_up.opcode_count ); + JERRY_ASSERT (int_data->pos <= int_data->pos + opdata.data.jmp_up.opcode_count); - int_data->pos = (opcode_counter_t) ( int_data->pos + opdata.data.jmp_down.opcode_count ); + int_data->pos = (opcode_counter_t) (int_data->pos + opdata.data.jmp_down.opcode_count); - return ecma_make_empty_completion_value(); + return ecma_make_empty_completion_value (); } /* opfunc_jmp_down */ /** @@ -601,11 +615,11 @@ ecma_completion_value_t opfunc_jmp_up (OPCODE opdata, /**< operation data */ struct __int_data *int_data) /**< interpreter context */ { - JERRY_ASSERT( int_data->pos >= opdata.data.jmp_up.opcode_count ); + JERRY_ASSERT (int_data->pos >= opdata.data.jmp_up.opcode_count); - int_data->pos = (opcode_counter_t) ( int_data->pos - opdata.data.jmp_down.opcode_count ); + int_data->pos = (opcode_counter_t) (int_data->pos - opdata.data.jmp_down.opcode_count); - return ecma_make_empty_completion_value(); + return ecma_make_empty_completion_value (); } /* opfunc_jmp_up */ /** @@ -635,76 +649,77 @@ opfunc_assignment (OPCODE opdata, /**< operation data */ ecma_completion_value_t get_value_completion; - switch ( type_value_right ) + switch (type_value_right) { case OPCODE_ARG_TYPE_SIMPLE: - { - get_value_completion = ecma_make_completion_value( ECMA_COMPLETION_TYPE_NORMAL, - ecma_make_simple_value( src_val_descr), + { + get_value_completion = ecma_make_completion_value (ECMA_COMPLETION_TYPE_NORMAL, + ecma_make_simple_value (src_val_descr), ECMA_TARGET_ID_RESERVED); - break; - } + break; + } case OPCODE_ARG_TYPE_STRING: - { - string_literal_copy str_value; - ecma_array_first_chunk_t *ecma_string_p; + { + string_literal_copy str_value; + ecma_array_first_chunk_t *ecma_string_p; - init_string_literal_copy( src_val_descr, &str_value); - ecma_string_p = ecma_new_ecma_string( str_value.str_p); - free_string_literal_copy( &str_value); + init_string_literal_copy (src_val_descr, &str_value); + ecma_string_p = ecma_new_ecma_string (str_value.str_p); + free_string_literal_copy (&str_value); - get_value_completion = ecma_make_completion_value(ECMA_COMPLETION_TYPE_NORMAL, - ecma_make_string_value( ecma_string_p), - ECMA_TARGET_ID_RESERVED); - break; - } + get_value_completion = ecma_make_completion_value (ECMA_COMPLETION_TYPE_NORMAL, + ecma_make_string_value (ecma_string_p), + ECMA_TARGET_ID_RESERVED); + break; + } case OPCODE_ARG_TYPE_VARIABLE: - { - get_value_completion = get_variable_value(int_data, - src_val_descr, - false); + { + get_value_completion = get_variable_value (int_data, + src_val_descr, + false); - break; - } + break; + } case OPCODE_ARG_TYPE_NUMBER: - { - ecma_number_t *num_p = ecma_alloc_number(); - *num_p = get_number_by_idx( src_val_descr); + { + ecma_number_t *num_p = ecma_alloc_number (); + *num_p = get_number_by_idx (src_val_descr); - get_value_completion = ecma_make_completion_value(ECMA_COMPLETION_TYPE_NORMAL, - ecma_make_number_value( num_p), - ECMA_TARGET_ID_RESERVED); - break; - } + get_value_completion = ecma_make_completion_value (ECMA_COMPLETION_TYPE_NORMAL, + ecma_make_number_value (num_p), + ECMA_TARGET_ID_RESERVED); + break; + } case OPCODE_ARG_TYPE_SMALLINT: - { - ecma_number_t *num_p = ecma_alloc_number(); - *num_p = src_val_descr; + { + ecma_number_t *num_p = ecma_alloc_number (); + *num_p = src_val_descr; - get_value_completion = ecma_make_completion_value(ECMA_COMPLETION_TYPE_NORMAL, - ecma_make_number_value( num_p), - ECMA_TARGET_ID_RESERVED); - break; - } - JERRY_UNIMPLEMENTED(); + get_value_completion = ecma_make_completion_value (ECMA_COMPLETION_TYPE_NORMAL, + ecma_make_number_value (num_p), + ECMA_TARGET_ID_RESERVED); + break; + } + + JERRY_UNIMPLEMENTED (); } - if ( unlikely( ecma_is_completion_value_throw( get_value_completion) ) ) - { - return get_value_completion; - } + if (unlikely (ecma_is_completion_value_throw (get_value_completion))) + { + return get_value_completion; + } else - { - JERRY_ASSERT( ecma_is_completion_value_normal( get_value_completion) ); - - ecma_completion_value_t assignment_completion_value = set_variable_value(int_data, + { + JERRY_ASSERT (ecma_is_completion_value_normal (get_value_completion)); + + ecma_completion_value_t assignment_completion_value = set_variable_value (int_data, dst_var_idx, get_value_completion.value); - - ecma_free_completion_value( get_value_completion); - return assignment_completion_value; - } + ecma_free_completion_value (get_value_completion); + + return assignment_completion_value; + } } /* opfunc_assignment */ /** @@ -716,8 +731,8 @@ opfunc_assignment (OPCODE opdata, /**< operation data */ * Returned value must be freed with ecma_free_completion_value */ ecma_completion_value_t -opfunc_addition(OPCODE opdata, /**< operation data */ - struct __int_data *int_data) /**< interpreter context */ +opfunc_addition (OPCODE opdata, /**< operation data */ + struct __int_data *int_data) /**< interpreter context */ { const T_IDX dst_var_idx = opdata.data.addition.dst; const T_IDX left_var_idx = opdata.data.addition.var_left; @@ -727,29 +742,29 @@ opfunc_addition(OPCODE opdata, /**< operation data */ ecma_completion_value_t ret_value; - ECMA_TRY_CATCH(left_value, get_variable_value( int_data, left_var_idx, false), ret_value); - ECMA_TRY_CATCH(right_value, get_variable_value( int_data, right_var_idx, false), ret_value); - ECMA_TRY_CATCH(prim_left_value, ecma_op_to_primitive( left_value.value, ECMA_PREFERRED_TYPE_NO), ret_value); - ECMA_TRY_CATCH(prim_right_value, ecma_op_to_primitive( right_value.value, ECMA_PREFERRED_TYPE_NO), ret_value); + ECMA_TRY_CATCH (left_value, get_variable_value (int_data, left_var_idx, false), ret_value); + ECMA_TRY_CATCH (right_value, get_variable_value (int_data, right_var_idx, false), ret_value); + ECMA_TRY_CATCH (prim_left_value, ecma_op_to_primitive (left_value.value, ECMA_PREFERRED_TYPE_NO), ret_value); + ECMA_TRY_CATCH (prim_right_value, ecma_op_to_primitive (right_value.value, ECMA_PREFERRED_TYPE_NO), ret_value); - if ( prim_left_value.value.value_type == ECMA_TYPE_STRING - || prim_right_value.value.value_type == ECMA_TYPE_STRING ) - { - JERRY_UNIMPLEMENTED(); - } + if (prim_left_value.value.value_type == ECMA_TYPE_STRING + || prim_right_value.value.value_type == ECMA_TYPE_STRING) + { + JERRY_UNIMPLEMENTED (); + } else - { - ret_value = do_number_arithmetic(int_data, - dst_var_idx, - number_arithmetic_addition, - prim_left_value.value, - prim_right_value.value); - } + { + ret_value = do_number_arithmetic (int_data, + dst_var_idx, + number_arithmetic_addition, + prim_left_value.value, + prim_right_value.value); + } - ECMA_FINALIZE(prim_right_value); - ECMA_FINALIZE(prim_left_value); - ECMA_FINALIZE(right_value); - ECMA_FINALIZE(left_value); + ECMA_FINALIZE (prim_right_value); + ECMA_FINALIZE (prim_left_value); + ECMA_FINALIZE (right_value); + ECMA_FINALIZE (left_value); return ret_value; } /* opfunc_addition */ @@ -763,8 +778,8 @@ opfunc_addition(OPCODE opdata, /**< operation data */ * Returned value must be freed with ecma_free_completion_value */ ecma_completion_value_t -opfunc_substraction(OPCODE opdata, /**< operation data */ - struct __int_data *int_data) /**< interpreter context */ +opfunc_substraction (OPCODE opdata, /**< operation data */ + struct __int_data *int_data) /**< interpreter context */ { const T_IDX dst_var_idx = opdata.data.substraction.dst; const T_IDX left_var_idx = opdata.data.substraction.var_left; @@ -774,17 +789,17 @@ opfunc_substraction(OPCODE opdata, /**< operation data */ ecma_completion_value_t ret_value; - ECMA_TRY_CATCH(left_value, get_variable_value( int_data, left_var_idx, false), ret_value); - ECMA_TRY_CATCH(right_value, get_variable_value( int_data, right_var_idx, false), ret_value); + ECMA_TRY_CATCH (left_value, get_variable_value (int_data, left_var_idx, false), ret_value); + ECMA_TRY_CATCH (right_value, get_variable_value (int_data, right_var_idx, false), ret_value); - ret_value = do_number_arithmetic(int_data, - dst_var_idx, - number_arithmetic_substraction, - left_value.value, - right_value.value); + ret_value = do_number_arithmetic (int_data, + dst_var_idx, + number_arithmetic_substraction, + left_value.value, + right_value.value); - ECMA_FINALIZE(right_value); - ECMA_FINALIZE(left_value); + ECMA_FINALIZE (right_value); + ECMA_FINALIZE (left_value); return ret_value; } /* opfunc_substraction */ @@ -798,8 +813,8 @@ opfunc_substraction(OPCODE opdata, /**< operation data */ * Returned value must be freed with ecma_free_completion_value */ ecma_completion_value_t -opfunc_multiplication(OPCODE opdata, /**< operation data */ - struct __int_data *int_data) /**< interpreter context */ +opfunc_multiplication (OPCODE opdata, /**< operation data */ + struct __int_data *int_data) /**< interpreter context */ { const T_IDX dst_var_idx = opdata.data.multiplication.dst; const T_IDX left_var_idx = opdata.data.multiplication.var_left; @@ -809,17 +824,17 @@ opfunc_multiplication(OPCODE opdata, /**< operation data */ ecma_completion_value_t ret_value; - ECMA_TRY_CATCH(left_value, get_variable_value( int_data, left_var_idx, false), ret_value); - ECMA_TRY_CATCH(right_value, get_variable_value( int_data, right_var_idx, false), ret_value); + ECMA_TRY_CATCH (left_value, get_variable_value (int_data, left_var_idx, false), ret_value); + ECMA_TRY_CATCH (right_value, get_variable_value (int_data, right_var_idx, false), ret_value); - ret_value = do_number_arithmetic(int_data, - dst_var_idx, - number_arithmetic_multiplication, - left_value.value, - right_value.value); + ret_value = do_number_arithmetic (int_data, + dst_var_idx, + number_arithmetic_multiplication, + left_value.value, + right_value.value); - ECMA_FINALIZE(right_value); - ECMA_FINALIZE(left_value); + ECMA_FINALIZE (right_value); + ECMA_FINALIZE (left_value); return ret_value; } /* opfunc_multiplication */ @@ -833,8 +848,8 @@ opfunc_multiplication(OPCODE opdata, /**< operation data */ * Returned value must be freed with ecma_free_completion_value */ ecma_completion_value_t -opfunc_division(OPCODE opdata, /**< operation data */ - struct __int_data *int_data) /**< interpreter context */ +opfunc_division (OPCODE opdata, /**< operation data */ + struct __int_data *int_data) /**< interpreter context */ { const T_IDX dst_var_idx = opdata.data.division.dst; const T_IDX left_var_idx = opdata.data.division.var_left; @@ -844,17 +859,17 @@ opfunc_division(OPCODE opdata, /**< operation data */ ecma_completion_value_t ret_value; - ECMA_TRY_CATCH(left_value, get_variable_value( int_data, left_var_idx, false), ret_value); - ECMA_TRY_CATCH(right_value, get_variable_value( int_data, right_var_idx, false), ret_value); + ECMA_TRY_CATCH (left_value, get_variable_value (int_data, left_var_idx, false), ret_value); + ECMA_TRY_CATCH (right_value, get_variable_value (int_data, right_var_idx, false), ret_value); - ret_value = do_number_arithmetic(int_data, - dst_var_idx, - number_arithmetic_division, - left_value.value, - right_value.value); + ret_value = do_number_arithmetic (int_data, + dst_var_idx, + number_arithmetic_division, + left_value.value, + right_value.value); - ECMA_FINALIZE(right_value); - ECMA_FINALIZE(left_value); + ECMA_FINALIZE (right_value); + ECMA_FINALIZE (left_value); return ret_value; } /* opfunc_division */ @@ -868,8 +883,8 @@ opfunc_division(OPCODE opdata, /**< operation data */ * Returned value must be freed with ecma_free_completion_value */ ecma_completion_value_t -opfunc_remainder(OPCODE opdata, /**< operation data */ - struct __int_data *int_data) /**< interpreter context */ +opfunc_remainder (OPCODE opdata, /**< operation data */ + struct __int_data *int_data) /**< interpreter context */ { const T_IDX dst_var_idx = opdata.data.remainder.dst; const T_IDX left_var_idx = opdata.data.remainder.var_left; @@ -879,17 +894,17 @@ opfunc_remainder(OPCODE opdata, /**< operation data */ ecma_completion_value_t ret_value; - ECMA_TRY_CATCH(left_value, get_variable_value( int_data, left_var_idx, false), ret_value); - ECMA_TRY_CATCH(right_value, get_variable_value( int_data, right_var_idx, false), ret_value); + ECMA_TRY_CATCH (left_value, get_variable_value (int_data, left_var_idx, false), ret_value); + ECMA_TRY_CATCH (right_value, get_variable_value (int_data, right_var_idx, false), ret_value); - ret_value = do_number_arithmetic(int_data, - dst_var_idx, - number_arithmetic_remainder, - left_value.value, - right_value.value); + ret_value = do_number_arithmetic (int_data, + dst_var_idx, + number_arithmetic_remainder, + left_value.value, + right_value.value); - ECMA_FINALIZE(right_value); - ECMA_FINALIZE(left_value); + ECMA_FINALIZE (right_value); + ECMA_FINALIZE (left_value); return ret_value; } /* opfunc_remainder */ @@ -903,8 +918,8 @@ opfunc_remainder(OPCODE opdata, /**< operation data */ * Returned value must be freed with ecma_free_completion_value */ ecma_completion_value_t -opfunc_pre_incr(OPCODE opdata, /**< operation data */ - struct __int_data *int_data) /**< interpreter context */ +opfunc_pre_incr (OPCODE opdata, /**< operation data */ + struct __int_data *int_data) /**< interpreter context */ { const T_IDX dst_var_idx = opdata.data.pre_incr.dst; const T_IDX incr_var_idx = opdata.data.pre_incr.var_right; @@ -914,16 +929,16 @@ opfunc_pre_incr(OPCODE opdata, /**< operation data */ ecma_completion_value_t ret_value; // 1., 2., 3. - ECMA_TRY_CATCH(old_value, get_variable_value( int_data, incr_var_idx, true), ret_value); - ECMA_TRY_CATCH(old_num_value, ecma_op_to_number( old_value.value), ret_value); + ECMA_TRY_CATCH (old_value, get_variable_value (int_data, incr_var_idx, true), ret_value); + ECMA_TRY_CATCH (old_num_value, ecma_op_to_number (old_value.value), ret_value); // 4. - ecma_number_t* new_num_p = ecma_alloc_number(); - - ecma_number_t* old_num_p = (ecma_number_t*)ECMA_GET_POINTER( old_num_value.value.value); - *new_num_p= ecma_op_number_add (*old_num_p, ECMA_NUMBER_ONE); + ecma_number_t* new_num_p = ecma_alloc_number (); - ecma_value_t new_num_value = ecma_make_number_value( new_num_p); + ecma_number_t* old_num_p = (ecma_number_t*) ECMA_GET_POINTER (old_num_value.value.value); + *new_num_p = ecma_op_number_add (*old_num_p, ECMA_NUMBER_ONE); + + ecma_value_t new_num_value = ecma_make_number_value (new_num_p); // 5. ret_value = set_variable_value (int_data, @@ -934,12 +949,12 @@ opfunc_pre_incr(OPCODE opdata, /**< operation data */ ecma_completion_value_t reg_assignment_res = set_variable_value (int_data, dst_var_idx, new_num_value); - JERRY_ASSERT( ecma_is_empty_completion_value( reg_assignment_res) ); + JERRY_ASSERT (ecma_is_empty_completion_value (reg_assignment_res)); - ecma_dealloc_number( new_num_p); + ecma_dealloc_number (new_num_p); - ECMA_FINALIZE(old_num_value); - ECMA_FINALIZE(old_value); + ECMA_FINALIZE (old_num_value); + ECMA_FINALIZE (old_value); return ret_value; } /* opfunc_pre_incr */ @@ -953,8 +968,8 @@ opfunc_pre_incr(OPCODE opdata, /**< operation data */ * Returned value must be freed with ecma_free_completion_value */ ecma_completion_value_t -opfunc_pre_decr(OPCODE opdata, /**< operation data */ - struct __int_data *int_data) /**< interpreter context */ +opfunc_pre_decr (OPCODE opdata, /**< operation data */ + struct __int_data *int_data) /**< interpreter context */ { const T_IDX dst_var_idx = opdata.data.pre_decr.dst; const T_IDX decr_var_idx = opdata.data.pre_decr.var_right; @@ -964,16 +979,16 @@ opfunc_pre_decr(OPCODE opdata, /**< operation data */ ecma_completion_value_t ret_value; // 1., 2., 3. - ECMA_TRY_CATCH(old_value, get_variable_value( int_data, decr_var_idx, true), ret_value); - ECMA_TRY_CATCH(old_num_value, ecma_op_to_number( old_value.value), ret_value); + ECMA_TRY_CATCH (old_value, get_variable_value (int_data, decr_var_idx, true), ret_value); + ECMA_TRY_CATCH (old_num_value, ecma_op_to_number (old_value.value), ret_value); // 4. - ecma_number_t* new_num_p = ecma_alloc_number(); - - ecma_number_t* old_num_p = (ecma_number_t*)ECMA_GET_POINTER( old_num_value.value.value); - *new_num_p= ecma_op_number_substract (*old_num_p, ECMA_NUMBER_ONE); + ecma_number_t* new_num_p = ecma_alloc_number (); - ecma_value_t new_num_value = ecma_make_number_value( new_num_p); + ecma_number_t* old_num_p = (ecma_number_t*) ECMA_GET_POINTER (old_num_value.value.value); + *new_num_p = ecma_op_number_substract (*old_num_p, ECMA_NUMBER_ONE); + + ecma_value_t new_num_value = ecma_make_number_value (new_num_p); // 5. ret_value = set_variable_value (int_data, @@ -984,12 +999,12 @@ opfunc_pre_decr(OPCODE opdata, /**< operation data */ ecma_completion_value_t reg_assignment_res = set_variable_value (int_data, dst_var_idx, new_num_value); - JERRY_ASSERT( ecma_is_empty_completion_value (reg_assignment_res) ); + JERRY_ASSERT (ecma_is_empty_completion_value (reg_assignment_res)); - ecma_dealloc_number( new_num_p); + ecma_dealloc_number (new_num_p); - ECMA_FINALIZE(old_num_value); - ECMA_FINALIZE(old_value); + ECMA_FINALIZE (old_num_value); + ECMA_FINALIZE (old_value); return ret_value; } /* opfunc_pre_decr */ @@ -1003,8 +1018,8 @@ opfunc_pre_decr(OPCODE opdata, /**< operation data */ * Returned value must be freed with ecma_free_completion_value */ ecma_completion_value_t -opfunc_post_incr(OPCODE opdata, /**< operation data */ - struct __int_data *int_data) /**< interpreter context */ +opfunc_post_incr (OPCODE opdata, /**< operation data */ + struct __int_data *int_data) /**< interpreter context */ { const T_IDX dst_var_idx = opdata.data.post_incr.dst; const T_IDX incr_var_idx = opdata.data.post_incr.var_right; @@ -1014,30 +1029,30 @@ opfunc_post_incr(OPCODE opdata, /**< operation data */ ecma_completion_value_t ret_value; // 1., 2., 3. - ECMA_TRY_CATCH(old_value, get_variable_value( int_data, incr_var_idx, true), ret_value); - ECMA_TRY_CATCH(old_num_value, ecma_op_to_number( old_value.value), ret_value); + ECMA_TRY_CATCH (old_value, get_variable_value (int_data, incr_var_idx, true), ret_value); + ECMA_TRY_CATCH (old_num_value, ecma_op_to_number (old_value.value), ret_value); // 4. - ecma_number_t* new_num_p = ecma_alloc_number(); - - ecma_number_t* old_num_p = (ecma_number_t*)ECMA_GET_POINTER( old_num_value.value.value); - *new_num_p= ecma_op_number_add (*old_num_p, ECMA_NUMBER_ONE); + ecma_number_t* new_num_p = ecma_alloc_number (); + + ecma_number_t* old_num_p = (ecma_number_t*) ECMA_GET_POINTER (old_num_value.value.value); + *new_num_p = ecma_op_number_add (*old_num_p, ECMA_NUMBER_ONE); // 5. ret_value = set_variable_value (int_data, incr_var_idx, - ecma_make_number_value( new_num_p)); + ecma_make_number_value (new_num_p)); - ecma_dealloc_number( new_num_p); + ecma_dealloc_number (new_num_p); // assignment of operator result to register variable ecma_completion_value_t reg_assignment_res = set_variable_value (int_data, dst_var_idx, old_value.value); - JERRY_ASSERT( ecma_is_empty_completion_value( reg_assignment_res) ); + JERRY_ASSERT (ecma_is_empty_completion_value (reg_assignment_res)); - ECMA_FINALIZE(old_num_value); - ECMA_FINALIZE(old_value); + ECMA_FINALIZE (old_num_value); + ECMA_FINALIZE (old_value); return ret_value; } /* opfunc_post_incr */ @@ -1051,8 +1066,8 @@ opfunc_post_incr(OPCODE opdata, /**< operation data */ * Returned value must be freed with ecma_free_completion_value */ ecma_completion_value_t -opfunc_post_decr(OPCODE opdata, /**< operation data */ - struct __int_data *int_data) /**< interpreter context */ +opfunc_post_decr (OPCODE opdata, /**< operation data */ + struct __int_data *int_data) /**< interpreter context */ { const T_IDX dst_var_idx = opdata.data.post_decr.dst; const T_IDX decr_var_idx = opdata.data.post_decr.var_right; @@ -1062,30 +1077,30 @@ opfunc_post_decr(OPCODE opdata, /**< operation data */ ecma_completion_value_t ret_value; // 1., 2., 3. - ECMA_TRY_CATCH(old_value, get_variable_value( int_data, decr_var_idx, true), ret_value); - ECMA_TRY_CATCH(old_num_value, ecma_op_to_number( old_value.value), ret_value); + ECMA_TRY_CATCH (old_value, get_variable_value (int_data, decr_var_idx, true), ret_value); + ECMA_TRY_CATCH (old_num_value, ecma_op_to_number (old_value.value), ret_value); // 4. - ecma_number_t* new_num_p = ecma_alloc_number(); - - ecma_number_t* old_num_p = (ecma_number_t*)ECMA_GET_POINTER( old_num_value.value.value); - *new_num_p= ecma_op_number_substract (*old_num_p, ECMA_NUMBER_ONE); + ecma_number_t* new_num_p = ecma_alloc_number (); + + ecma_number_t* old_num_p = (ecma_number_t*) ECMA_GET_POINTER (old_num_value.value.value); + *new_num_p = ecma_op_number_substract (*old_num_p, ECMA_NUMBER_ONE); // 5. ret_value = set_variable_value (int_data, decr_var_idx, - ecma_make_number_value( new_num_p)); + ecma_make_number_value (new_num_p)); - ecma_dealloc_number( new_num_p); + ecma_dealloc_number (new_num_p); // assignment of operator result to register variable ecma_completion_value_t reg_assignment_res = set_variable_value (int_data, dst_var_idx, old_value.value); - JERRY_ASSERT( ecma_is_empty_completion_value (reg_assignment_res) ); + JERRY_ASSERT (ecma_is_empty_completion_value (reg_assignment_res)); - ECMA_FINALIZE(old_num_value); - ECMA_FINALIZE(old_value); + ECMA_FINALIZE (old_num_value); + ECMA_FINALIZE (old_value); return ret_value; } /* opfunc_post_decr */ @@ -1099,8 +1114,8 @@ opfunc_post_decr(OPCODE opdata, /**< operation data */ * Returned value must be freed with ecma_free_completion_value */ ecma_completion_value_t -opfunc_equal_value(OPCODE opdata, /**< operation data */ - struct __int_data *int_data) /**< interpreter context */ +opfunc_equal_value (OPCODE opdata, /**< operation data */ + struct __int_data *int_data) /**< interpreter context */ { const T_IDX dst_var_idx = opdata.data.equal_value.dst; const T_IDX left_var_idx = opdata.data.equal_value.var_left; @@ -1110,16 +1125,16 @@ opfunc_equal_value(OPCODE opdata, /**< operation data */ ecma_completion_value_t ret_value; - ECMA_TRY_CATCH(left_value, get_variable_value( int_data, left_var_idx, false), ret_value); - ECMA_TRY_CATCH(right_value, get_variable_value( int_data, right_var_idx, false), ret_value); + ECMA_TRY_CATCH (left_value, get_variable_value (int_data, left_var_idx, false), ret_value); + ECMA_TRY_CATCH (right_value, get_variable_value (int_data, right_var_idx, false), ret_value); - bool is_equal = ecma_op_abstract_equality_compare( left_value.value, right_value.value); + bool is_equal = ecma_op_abstract_equality_compare (left_value.value, right_value.value); - ret_value = set_variable_value( int_data, dst_var_idx, ecma_make_simple_value (is_equal ? ECMA_SIMPLE_VALUE_TRUE - : ECMA_SIMPLE_VALUE_FALSE)); + ret_value = set_variable_value (int_data, dst_var_idx, ecma_make_simple_value (is_equal ? ECMA_SIMPLE_VALUE_TRUE + : ECMA_SIMPLE_VALUE_FALSE)); - ECMA_FINALIZE(right_value); - ECMA_FINALIZE(left_value); + ECMA_FINALIZE (right_value); + ECMA_FINALIZE (left_value); return ret_value; } /* opfunc_equal_value */ @@ -1133,8 +1148,8 @@ opfunc_equal_value(OPCODE opdata, /**< operation data */ * Returned value must be freed with ecma_free_completion_value */ ecma_completion_value_t -opfunc_not_equal_value(OPCODE opdata, /**< operation data */ - struct __int_data *int_data) /**< interpreter context */ +opfunc_not_equal_value (OPCODE opdata, /**< operation data */ + struct __int_data *int_data) /**< interpreter context */ { const T_IDX dst_var_idx = opdata.data.not_equal_value.dst; const T_IDX left_var_idx = opdata.data.not_equal_value.var_left; @@ -1144,17 +1159,17 @@ opfunc_not_equal_value(OPCODE opdata, /**< operation data */ ecma_completion_value_t ret_value; - ECMA_TRY_CATCH(left_value, get_variable_value( int_data, left_var_idx, false), ret_value); - ECMA_TRY_CATCH(right_value, get_variable_value( int_data, right_var_idx, false), ret_value); + ECMA_TRY_CATCH (left_value, get_variable_value (int_data, left_var_idx, false), ret_value); + ECMA_TRY_CATCH (right_value, get_variable_value (int_data, right_var_idx, false), ret_value); - bool is_equal = ecma_op_abstract_equality_compare( left_value.value, right_value.value); + bool is_equal = ecma_op_abstract_equality_compare (left_value.value, right_value.value); - ret_value = set_variable_value( int_data, dst_var_idx, ecma_make_simple_value (is_equal ? ECMA_SIMPLE_VALUE_FALSE - : ECMA_SIMPLE_VALUE_TRUE)); + ret_value = set_variable_value (int_data, dst_var_idx, ecma_make_simple_value (is_equal ? ECMA_SIMPLE_VALUE_FALSE + : ECMA_SIMPLE_VALUE_TRUE)); - ECMA_FINALIZE(right_value); - ECMA_FINALIZE(left_value); + ECMA_FINALIZE (right_value); + ECMA_FINALIZE (left_value); return ret_value; } /* opfunc_not_equal_value */ @@ -1168,8 +1183,8 @@ opfunc_not_equal_value(OPCODE opdata, /**< operation data */ * Returned value must be freed with ecma_free_completion_value */ ecma_completion_value_t -opfunc_less_than(OPCODE opdata, /**< operation data */ - struct __int_data *int_data) /**< interpreter context */ +opfunc_less_than (OPCODE opdata, /**< operation data */ + struct __int_data *int_data) /**< interpreter context */ { const T_IDX dst_var_idx = opdata.data.less_than.dst; const T_IDX left_var_idx = opdata.data.less_than.var_left; @@ -1179,32 +1194,32 @@ opfunc_less_than(OPCODE opdata, /**< operation data */ ecma_completion_value_t ret_value; - ECMA_TRY_CATCH(left_value, get_variable_value( int_data, left_var_idx, false), ret_value); - ECMA_TRY_CATCH(right_value, get_variable_value( int_data, right_var_idx, false), ret_value); - ECMA_TRY_CATCH(compare_result, - ecma_op_abstract_relational_compare (left_value.value, - right_value.value, - true), - ret_value); + ECMA_TRY_CATCH (left_value, get_variable_value (int_data, left_var_idx, false), ret_value); + ECMA_TRY_CATCH (right_value, get_variable_value (int_data, right_var_idx, false), ret_value); + ECMA_TRY_CATCH (compare_result, + ecma_op_abstract_relational_compare (left_value.value, + right_value.value, + true), + ret_value); ecma_simple_value_t res; - if ( ecma_is_value_undefined( compare_result.value) ) - { - res = ECMA_SIMPLE_VALUE_FALSE; - } + if (ecma_is_value_undefined (compare_result.value)) + { + res = ECMA_SIMPLE_VALUE_FALSE; + } else - { - JERRY_ASSERT( ecma_is_value_boolean( compare_result.value) ); + { + JERRY_ASSERT (ecma_is_value_boolean (compare_result.value)); - res = compare_result.value.value; - } + res = compare_result.value.value; + } - ret_value = set_variable_value( int_data, dst_var_idx, ecma_make_simple_value( res)); + ret_value = set_variable_value (int_data, dst_var_idx, ecma_make_simple_value (res)); - ECMA_FINALIZE(compare_result); - ECMA_FINALIZE(right_value); - ECMA_FINALIZE(left_value); + ECMA_FINALIZE (compare_result); + ECMA_FINALIZE (right_value); + ECMA_FINALIZE (left_value); return ret_value; } /* opfunc_less_than */ @@ -1218,8 +1233,8 @@ opfunc_less_than(OPCODE opdata, /**< operation data */ * Returned value must be freed with ecma_free_completion_value */ ecma_completion_value_t -opfunc_greater_than(OPCODE opdata, /**< operation data */ - struct __int_data *int_data) /**< interpreter context */ +opfunc_greater_than (OPCODE opdata, /**< operation data */ + struct __int_data *int_data) /**< interpreter context */ { const T_IDX dst_var_idx = opdata.data.greater_than.dst; const T_IDX left_var_idx = opdata.data.greater_than.var_left; @@ -1229,32 +1244,32 @@ opfunc_greater_than(OPCODE opdata, /**< operation data */ ecma_completion_value_t ret_value; - ECMA_TRY_CATCH(left_value, get_variable_value( int_data, left_var_idx, false), ret_value); - ECMA_TRY_CATCH(right_value, get_variable_value( int_data, right_var_idx, false), ret_value); - ECMA_TRY_CATCH(compare_result, - ecma_op_abstract_relational_compare (right_value.value, - left_value.value, - false), - ret_value); + ECMA_TRY_CATCH (left_value, get_variable_value (int_data, left_var_idx, false), ret_value); + ECMA_TRY_CATCH (right_value, get_variable_value (int_data, right_var_idx, false), ret_value); + ECMA_TRY_CATCH (compare_result, + ecma_op_abstract_relational_compare (right_value.value, + left_value.value, + false), + ret_value); ecma_simple_value_t res; - if ( ecma_is_value_undefined( compare_result.value) ) - { - res = ECMA_SIMPLE_VALUE_FALSE; - } + if (ecma_is_value_undefined (compare_result.value)) + { + res = ECMA_SIMPLE_VALUE_FALSE; + } else - { - JERRY_ASSERT( ecma_is_value_boolean( compare_result.value) ); + { + JERRY_ASSERT (ecma_is_value_boolean (compare_result.value)); - res = compare_result.value.value; - } + res = compare_result.value.value; + } - ret_value = set_variable_value( int_data, dst_var_idx, ecma_make_simple_value( res)); + ret_value = set_variable_value (int_data, dst_var_idx, ecma_make_simple_value (res)); - ECMA_FINALIZE(compare_result); - ECMA_FINALIZE(right_value); - ECMA_FINALIZE(left_value); + ECMA_FINALIZE (compare_result); + ECMA_FINALIZE (right_value); + ECMA_FINALIZE (left_value); return ret_value; } /* opfunc_greater_than */ @@ -1265,10 +1280,10 @@ opfunc_greater_than(OPCODE opdata, /**< operation data */ * The opcode is meta-opcode that is not supposed to be executed. */ ecma_completion_value_t -opfunc_reg_var_decl(OPCODE opdata __unused, /**< operation data */ - struct __int_data *int_data __unused) /**< interpreter context */ +opfunc_reg_var_decl (OPCODE opdata __unused, /**< operation data */ + struct __int_data *int_data __unused) /**< interpreter context */ { - JERRY_UNREACHABLE(); + JERRY_UNREACHABLE (); } /* opfunc_reg_var_decl */ /** @@ -1281,39 +1296,40 @@ opfunc_reg_var_decl(OPCODE opdata __unused, /**< operation data */ * However, ecma_free_completion_value may be called for it, but it is a no-op. */ ecma_completion_value_t -opfunc_var_decl(OPCODE opdata, /**< operation data */ - struct __int_data *int_data) /**< interpreter context */ +opfunc_var_decl (OPCODE opdata, /**< operation data */ + struct __int_data *int_data) /**< interpreter context */ { string_literal_copy variable_name; - init_string_literal_copy( opdata.data.var_decl.variable_name, &variable_name); + init_string_literal_copy (opdata.data.var_decl.variable_name, &variable_name); - if ( ecma_is_completion_value_normal_false( ecma_op_has_binding (int_data->lex_env_p, - variable_name.str_p)) ) + if (ecma_is_completion_value_normal_false (ecma_op_has_binding (int_data->lex_env_p, + variable_name.str_p))) { - FIXME( Pass configurableBindings that is true if and only if current code is eval code ); + FIXME ("Pass configurableBindings that is true if and only if current code is eval code"); + ecma_completion_value_t completion = ecma_op_create_mutable_binding (int_data->lex_env_p, variable_name.str_p, false); - JERRY_ASSERT( ecma_is_empty_completion_value( completion) ); + JERRY_ASSERT (ecma_is_empty_completion_value (completion)); /* Skipping SetMutableBinding as we have already checked that there were not - * any binding with specified name in current lexical environment + * any binding with specified name in current lexical environment * and CreateMutableBinding sets the created binding's value to undefined */ - JERRY_ASSERT( ecma_is_completion_value_normal_simple_value( ecma_op_get_binding_value (int_data->lex_env_p, + JERRY_ASSERT (ecma_is_completion_value_normal_simple_value (ecma_op_get_binding_value (int_data->lex_env_p, variable_name.str_p, true), - ECMA_SIMPLE_VALUE_UNDEFINED) ); + ECMA_SIMPLE_VALUE_UNDEFINED)); } - free_string_literal_copy( &variable_name); + free_string_literal_copy (&variable_name); int_data->pos++; - return ecma_make_empty_completion_value(); + return ecma_make_empty_completion_value (); } /* opfunc_var_decl */ - /** +/** * 'Function declaration with no parameters' opcode handler. * * See also: ECMA-262 v5, 10.5 - Declaration binding instantiation (block 5). @@ -1322,25 +1338,25 @@ opfunc_var_decl(OPCODE opdata, /**< operation data */ * returned value must be freed with ecma_free_completion_value. */ ecma_completion_value_t -opfunc_func_decl_0(OPCODE opdata, /**< operation data */ - struct __int_data *int_data) /**< interpreter context */ +opfunc_func_decl_0 (OPCODE opdata, /**< operation data */ + struct __int_data *int_data) /**< interpreter context */ { string_literal_copy function_name; - init_string_literal_copy( opdata.data.func_decl_0.name_lit_idx, &function_name); + init_string_literal_copy (opdata.data.func_decl_0.name_lit_idx, &function_name); - TODO( Check if code of function itself is strict ); + TODO ("Check if code of function itself is strict"); const bool is_strict = int_data->is_strict; const opcode_counter_t varg_first_opcode_idx = (opcode_counter_t) (int_data->pos + 1); int_data->pos = varg_first_opcode_idx; - TODO( Iterate vargs ); + TODO (Iterate vargs); const opcode_counter_t jmp_down_opcode_idx = (opcode_counter_t) (int_data->pos); - OPCODE jmp_down_opcode = read_opcode( jmp_down_opcode_idx ); - JERRY_ASSERT( jmp_down_opcode.op_idx == __op__idx_jmp_down ); - int_data->pos = (opcode_counter_t) ( jmp_down_opcode_idx + jmp_down_opcode.data.jmp_down.opcode_count ); + OPCODE jmp_down_opcode = read_opcode (jmp_down_opcode_idx); + JERRY_ASSERT (jmp_down_opcode.op_idx == __op__idx_jmp_down); + int_data->pos = (opcode_counter_t) (jmp_down_opcode_idx + jmp_down_opcode.data.jmp_down.opcode_count); const opcode_counter_t function_code_opcode_idx = (opcode_counter_t) (jmp_down_opcode_idx + 1); @@ -1348,43 +1364,44 @@ opfunc_func_decl_0(OPCODE opdata, /**< operation data */ const ecma_char_t *fn = function_name.str_p; // b. - TODO( Pass formal parameter list ); - ecma_object_t *fo = ecma_op_create_function_object( NULL, + TODO (Pass formal parameter list); + ecma_object_t *fo = ecma_op_create_function_object (NULL, 0, int_data->lex_env_p, is_strict, function_code_opcode_idx); - ecma_value_t fo_value = ecma_make_object_value( fo); - + ecma_value_t fo_value = ecma_make_object_value (fo); + // c. - bool func_already_declared = ecma_is_completion_value_normal_true( ecma_op_has_binding (int_data->lex_env_p, fn)); + bool func_already_declared = ecma_is_completion_value_normal_true (ecma_op_has_binding (int_data->lex_env_p, fn)); // d. - if ( !func_already_declared ) - { - FIXME( Pass configurableBindings that is true if and only if current code is eval code ); - ecma_completion_value_t completion = ecma_op_create_mutable_binding( int_data->lex_env_p, - fn, - false); + if (!func_already_declared) + { + FIXME ("Pass configurableBindings that is true if and only if current code is eval code"); - JERRY_ASSERT( ecma_is_empty_completion_value( completion) ); - } + ecma_completion_value_t completion = ecma_op_create_mutable_binding (int_data->lex_env_p, + fn, + false); + + JERRY_ASSERT (ecma_is_empty_completion_value (completion)); + } // e. - TODO( Check if current lexical environment is global environment and implement the case ); + TODO ("Check if current lexical environment is global environment and implement the case"); // f. - ecma_completion_value_t ret_value = ecma_op_set_mutable_binding( int_data->lex_env_p, fn, fo_value, is_strict); + ecma_completion_value_t ret_value = ecma_op_set_mutable_binding (int_data->lex_env_p, fn, fo_value, is_strict); - ecma_free_value( fo_value, true); + ecma_free_value (fo_value, true); - free_string_literal_copy( &function_name); + free_string_literal_copy (&function_name); return ret_value; } /* opfunc_func_decl_0 */ /** - * 'Function call with no arguments' opcode handler. + * Function call with no arguments' opcode handler. * * See also: ECMA-262 v5, 11.2.3 * @@ -1392,9 +1409,9 @@ opfunc_func_decl_0(OPCODE opdata, /**< operation data */ * Returned value must be freed with ecma_free_completion_value. */ ecma_completion_value_t -opfunc_call_0( OPCODE opdata, /**< operation data */ +opfunc_call_0 (OPCODE opdata, /**< operation data */ struct __int_data *int_data) /**< interpreter context */ -{ +{ const T_IDX func_name_lit_idx = opdata.data.call_0.name_lit_idx; const T_IDX lhs_var_idx = opdata.data.call_0.lhs; @@ -1402,33 +1419,33 @@ opfunc_call_0( OPCODE opdata, /**< operation data */ ecma_completion_value_t ret_value; - ECMA_TRY_CATCH( func_value, get_variable_value( int_data, func_name_lit_idx, false), ret_value); + ECMA_TRY_CATCH (func_value, get_variable_value (int_data, func_name_lit_idx, false), ret_value); - if ( !ecma_op_is_callable( func_value.value) ) - { - ret_value = ecma_make_throw_value( ecma_new_standard_error( ECMA_ERROR_TYPE)); - } + if (!ecma_op_is_callable (func_value.value)) + { + ret_value = ecma_make_throw_value (ecma_new_standard_error (ECMA_ERROR_TYPE)); + } else + { + ecma_object_t *func_obj_p = ECMA_GET_POINTER (func_value.value.value); + + ECMA_TRY_CATCH (this_value, ecma_op_implicit_this_value (int_data->lex_env_p), ret_value); + + ret_value = ecma_op_function_call (func_obj_p, this_value.value, NULL, 0); + + if (ret_value.type == ECMA_COMPLETION_TYPE_RETURN) { - ecma_object_t *func_obj_p = ECMA_GET_POINTER( func_value.value.value); + ecma_value_t returned_value = ret_value.value; - ECMA_TRY_CATCH( this_value, ecma_op_implicit_this_value( int_data->lex_env_p), ret_value); + ret_value = set_variable_value (int_data, lhs_var_idx, returned_value); - ret_value = ecma_op_function_call( func_obj_p, this_value.value, NULL, 0); - - if ( ret_value.type == ECMA_COMPLETION_TYPE_RETURN ) - { - ecma_value_t returned_value = ret_value.value; - - ret_value = set_variable_value( int_data, lhs_var_idx, returned_value); - - ecma_free_value( returned_value, true); - } - - ECMA_FINALIZE( this_value); + ecma_free_value (returned_value, true); } - ECMA_FINALIZE( func_value); + ECMA_FINALIZE (this_value); + } + + ECMA_FINALIZE (func_value); return ret_value; } /* opfunc_call_0 */ @@ -1443,11 +1460,11 @@ opfunc_call_0( OPCODE opdata, /**< operation data */ * However, ecma_free_completion_value may be called for it, but it is a no-op. */ ecma_completion_value_t -opfunc_ret( OPCODE opdata __unused, /**< operation data */ +opfunc_ret (OPCODE opdata __unused, /**< operation data */ struct __int_data *int_data __unused) /**< interpreter context */ { - return ecma_make_completion_value( ECMA_COMPLETION_TYPE_RETURN, - ecma_make_simple_value( ECMA_SIMPLE_VALUE_UNDEFINED), + return ecma_make_completion_value (ECMA_COMPLETION_TYPE_RETURN, + ecma_make_simple_value (ECMA_SIMPLE_VALUE_UNDEFINED), ECMA_TARGET_ID_RESERVED); } /* opfunc_ret */ @@ -1465,17 +1482,17 @@ opfunc_ret( OPCODE opdata __unused, /**< operation data */ * However, ecma_free_completion_value may be called for it, but it is a no-op. */ ecma_completion_value_t -opfunc_exitval(OPCODE opdata, /**< operation data */ - struct __int_data *int_data __unused) /**< interpreter context */ +opfunc_exitval (OPCODE opdata, /**< operation data */ + struct __int_data *int_data __unused) /**< interpreter context */ { - JERRY_ASSERT( opdata.data.exitval.status_code == 0 - || opdata.data.exitval.status_code == 1 ); + JERRY_ASSERT (opdata.data.exitval.status_code == 0 + || opdata.data.exitval.status_code == 1); - ecma_value_t exit_status = ecma_make_simple_value( opdata.data.exitval.status_code == 0 ? ECMA_SIMPLE_VALUE_TRUE - : ECMA_SIMPLE_VALUE_FALSE); - return ecma_make_completion_value( ECMA_COMPLETION_TYPE_EXIT, - exit_status, - ECMA_TARGET_ID_RESERVED); + ecma_value_t exit_status = ecma_make_simple_value (opdata.data.exitval.status_code == 0 ? ECMA_SIMPLE_VALUE_TRUE + : ECMA_SIMPLE_VALUE_FALSE); + return ecma_make_completion_value (ECMA_COMPLETION_TYPE_EXIT, + exit_status, + ECMA_TARGET_ID_RESERVED); } /* opfunc_exitval */ @@ -1555,4 +1572,3 @@ GETOP_IMPL_2 (typeof, lhs, obj) GETOP_IMPL_1 (with, expr) GETOP_IMPL_0 (end_with) GETOP_IMPL_2 (reg_var_decl, min, max) - diff --git a/src/libcoreint/opcodes.h b/src/libcoreint/opcodes.h index 8a7f328dc..7e86a9c63 100644 --- a/src/libcoreint/opcodes.h +++ b/src/libcoreint/opcodes.h @@ -14,7 +14,7 @@ */ #ifndef OPCODES_H -#define OPCODES_H +#define OPCODES_H #include "ecma-globals.h" #include "globals.h" @@ -24,7 +24,7 @@ struct __int_data; #define OP_STRUCT_FIELD(name) struct __op_##name name; #define OP_ENUM_FIELD(name) __op__idx_##name , -#define OP_FUNC_DECL(name) ecma_completion_value_t opfunc_##name (OPCODE, struct __int_data *); +#define OP_FUNC_DECL(name) ecma_completion_value_t opfunc_##name (OPCODE, struct __int_data *); /** A single bytecode instruction is 32bit wide and has an 8bit opcode field and several operand of 8 of 16 bit.*/ @@ -33,9 +33,10 @@ struct __int_data; #define T_IDX uint8_t /** index values */ OPCODE; -typedef ecma_completion_value_t (*opfunc)(OPCODE, struct __int_data *); +typedef +ecma_completion_value_t (*opfunc) (OPCODE, struct __int_data *); -#define OP_CALLS_AND_ARGS(op) \ +#define OP_CALLS_AND_ARGS(op) \ op (call_0) \ op (call_1) \ op (call_n) \ @@ -57,7 +58,7 @@ typedef ecma_completion_value_t (*opfunc)(OPCODE, struct __int_data *); op (retval) \ op (ret) -#define OP_INITS(op) \ +#define OP_INITS(op) \ op (array_0) \ op (array_1) \ op (array_2) \ @@ -74,34 +75,34 @@ typedef ecma_completion_value_t (*opfunc)(OPCODE, struct __int_data *); op (delete) \ op (typeof) \ op (with) \ - op (end_with) + op (end_with) -#define OP_ASSIGNMENTS(op) \ +#define OP_ASSIGNMENTS(op) \ op (assignment) -#define OP_B_SHIFTS(op) \ +#define OP_B_SHIFTS(op) \ op (b_shift_left) \ op (b_shift_right) \ op (b_shift_uright) -#define OP_B_BITWISE(op) \ +#define OP_B_BITWISE(op) \ op (b_and) \ op (b_or) \ op (b_xor) \ op (b_not) -#define OP_B_LOGICAL(op) \ +#define OP_B_LOGICAL(op) \ op (logical_and) \ op (logical_or) \ op (logical_not) -#define OP_EQUALITY(op) \ +#define OP_EQUALITY(op) \ op (equal_value) \ op (not_equal_value) \ op (equal_value_type) \ - op (not_equal_value_type) + op (not_equal_value_type) -#define OP_RELATIONAL(op) \ +#define OP_RELATIONAL(op) \ op (less_than) \ op (greater_than) \ op (less_or_equal_than) \ @@ -109,7 +110,7 @@ typedef ecma_completion_value_t (*opfunc)(OPCODE, struct __int_data *); op (instanceof) \ op (in) -#define OP_ARITHMETIC(op) \ +#define OP_ARITHMETIC(op) \ op (post_incr) \ op (post_decr) \ op (pre_incr) \ @@ -120,17 +121,17 @@ typedef ecma_completion_value_t (*opfunc)(OPCODE, struct __int_data *); op (multiplication) \ op (remainder) -#define OP_UNCONDITIONAL_JUMPS(op) \ +#define OP_UNCONDITIONAL_JUMPS(op) \ op (jmp) \ op (jmp_up) \ op (jmp_down) \ op (nop) -#define OP_UNARY_OPS(op) \ +#define OP_UNARY_OPS(op) \ op (is_true_jmp) \ op (is_false_jmp) -#define OP_LIST(op) \ +#define OP_LIST(op) \ OP_CALLS_AND_ARGS (op) \ OP_INITS (op) \ OP_ASSIGNMENTS (op) \ @@ -180,5 +181,4 @@ typedef enum OPCODE_ARG_TYPE_VARIABLE /**< index of variable name */ } opcode_arg_type_operand; -#endif /* OPCODES_H */ - +#endif /* OPCODES_H */