diff --git a/src/libcoreint/interpreter.c b/src/libcoreint/interpreter.c index 63a52768e..c109e706a 100644 --- a/src/libcoreint/interpreter.c +++ b/src/libcoreint/interpreter.c @@ -46,7 +46,7 @@ run_int (void) { JERRY_ASSERT( __program != NULL ); - const interp_bytecode_idx start_pos = 0; + const opcode_counter_t start_pos = 0; ecma_value_t this_binding_value = ecma_make_simple_value( ECMA_SIMPLE_VALUE_UNDEFINED); ecma_object_t *lex_env_p = ecma_create_lexical_environment (NULL, ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE); @@ -88,7 +88,7 @@ run_int (void) } ecma_completion_value_t -run_int_from_pos (interp_bytecode_idx start_pos, +run_int_from_pos (opcode_counter_t start_pos, ecma_value_t this_binding_value, ecma_object_t *lex_env_p, bool is_strict) @@ -111,7 +111,7 @@ run_int_from_pos (interp_bytecode_idx start_pos, JERRY_ASSERT( ecma_is_value_empty( regs[0]) ); struct __int_data int_data; - int_data.pos = (interp_bytecode_idx) (start_pos + 1); + int_data.pos = (opcode_counter_t) (start_pos + 1); int_data.this_binding = this_binding_value; int_data.lex_env_p = lex_env_p; int_data.is_strict = is_strict; diff --git a/src/libcoreint/interpreter.h b/src/libcoreint/interpreter.h index 0c524e4b2..c1d22f544 100644 --- a/src/libcoreint/interpreter.h +++ b/src/libcoreint/interpreter.h @@ -20,11 +20,11 @@ #include "globals.h" #include "opcodes.h" -typedef uint16_t interp_bytecode_idx; +typedef uint16_t opcode_counter_t; struct __int_data { - interp_bytecode_idx pos; /**< current opcode to execute */ + opcode_counter_t pos; /**< current opcode to execute */ ecma_value_t this_binding; /**< this binding for current context */ ecma_object_t *lex_env_p; /**< current lexical environment */ bool is_strict; /**< is current code execution mode strict? */ @@ -35,7 +35,7 @@ struct __int_data void init_int (const OPCODE* program_p); bool run_int (void); -ecma_completion_value_t run_int_from_pos (interp_bytecode_idx start_pos, +ecma_completion_value_t run_int_from_pos (opcode_counter_t start_pos, ecma_value_t this_binding_value, ecma_object_t *lex_env_p, bool is_strict); diff --git a/src/libcoreint/opcodes.c b/src/libcoreint/opcodes.c index e9e468fea..f831d88da 100644 --- a/src/libcoreint/opcodes.c +++ b/src/libcoreint/opcodes.c @@ -565,7 +565,7 @@ opfunc_jmp_down (OPCODE opdata, /**< operation data */ { JERRY_ASSERT( int_data->pos <= int_data->pos + opdata.data.jmp_up.opcode_count ); - int_data->pos = (interp_bytecode_idx) ( 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(); } /* opfunc_jmp_down */ @@ -582,7 +582,7 @@ opfunc_jmp_up (OPCODE opdata, /**< operation data */ { JERRY_ASSERT( int_data->pos >= opdata.data.jmp_up.opcode_count ); - int_data->pos = (interp_bytecode_idx) ( 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(); } /* opfunc_jmp_up */ @@ -1309,16 +1309,16 @@ opfunc_func_decl_0(OPCODE opdata, /**< operation data */ const bool is_strict = int_data->is_strict; - const interp_bytecode_idx varg_first_opcode_idx = (interp_bytecode_idx) (int_data->pos + 1); + 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 ); - const interp_bytecode_idx jmp_down_opcode_idx = (interp_bytecode_idx) (int_data->pos); + const opcode_counter_t jmp_down_opcode_idx = (opcode_counter_t) (int_data->pos); TODO( ASSERT( Current opcode is jmp_down ) ); - const interp_bytecode_idx function_code_opcode_idx = (interp_bytecode_idx) (jmp_down_opcode_idx + 1); + const opcode_counter_t function_code_opcode_idx = (opcode_counter_t) (jmp_down_opcode_idx + 1); // a. const ecma_char_t *fn = function_name.str_p; @@ -1360,10 +1360,7 @@ opfunc_func_decl_0(OPCODE opdata, /**< operation data */ /** * 'Function call with no arguments' opcode handler. * - * See also: ECMA-262 v5, 13.2.1 - * - * TODO: Move the call mechanic to ecma_op_function_call - * Rewrite from scratch. + * See also: ECMA-262 v5, 11.2.3 * * @return completion value * Returned value must be freed with ecma_free_completion_value. @@ -1373,6 +1370,7 @@ 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; int_data->pos++; @@ -1380,37 +1378,28 @@ opfunc_call_0( OPCODE opdata, /**< operation data */ ECMA_TRY_CATCH( func_value, get_variable_value( int_data, func_name_lit_idx, false), ret_value); - if ( func_value.value.value_type != ECMA_TYPE_OBJECT ) + 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_property_t* code_prop_p = ecma_find_internal_property( func_obj_p, ECMA_INTERNAL_PROPERTY_CODE); - ecma_property_t* scope_prop_p = ecma_find_internal_property( func_obj_p, ECMA_INTERNAL_PROPERTY_SCOPE); - interp_bytecode_idx code_idx = (interp_bytecode_idx) code_prop_p->u.internal_property.value; - ecma_object_t *scope_p = ecma_get_pointer( scope_prop_p->u.internal_property.value); + ECMA_TRY_CATCH( this_value, ecma_op_implicit_this_value( int_data->lex_env_p), ret_value); - ecma_object_t *new_lex_env_p = ecma_create_lexical_environment( scope_p, - ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE); - - ret_value = run_int_from_pos( code_idx, - ecma_make_simple_value( ECMA_SIMPLE_VALUE_UNDEFINED), - new_lex_env_p, - false); + 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; - ecma_free_value( returned_value); + ret_value = set_variable_value( int_data, lhs_var_idx, returned_value); - ret_value = ecma_make_empty_completion_value(); + ecma_free_value( returned_value); } - ecma_deref_object( new_lex_env_p); + ECMA_FINALIZE( this_value); } ECMA_FINALIZE( func_value); diff --git a/src/libecmaoperations/ecma-function-object.c b/src/libecmaoperations/ecma-function-object.c index 737d34c38..ba0cc4d73 100644 --- a/src/libecmaoperations/ecma-function-object.c +++ b/src/libecmaoperations/ecma-function-object.c @@ -37,7 +37,7 @@ */ static uint32_t ecma_pack_code_internal_property_value( bool is_strict, /**< is code strict? */ - interp_bytecode_idx opcode_idx) /**< index of first opcode */ + opcode_counter_t opcode_idx) /**< index of first opcode */ { uint32_t value = opcode_idx; const uint32_t is_strict_bit_offset = sizeof(value) * JERRY_BITSINBYTE - 1; @@ -58,7 +58,7 @@ ecma_pack_code_internal_property_value( bool is_strict, /**< is code strict? */ * * @return opcode index */ -static interp_bytecode_idx +static opcode_counter_t ecma_unpack_code_internal_property_value( uint32_t value, /**< packed value */ bool* out_is_strict_p) /**< out: is code strict? */ { @@ -69,7 +69,7 @@ ecma_unpack_code_internal_property_value( uint32_t value, /**< packed value */ bool is_strict = ( ( value & ( 1u << is_strict_bit_offset ) ) != 0 ); *out_is_strict_p = is_strict; - interp_bytecode_idx opcode_idx = (interp_bytecode_idx) ( value & ~( 1u << is_strict_bit_offset ) ); + opcode_counter_t opcode_idx = (opcode_counter_t) ( value & ~( 1u << is_strict_bit_offset ) ); return opcode_idx; } /* ecma_unpack_code_internal_property_value */ @@ -111,7 +111,7 @@ ecma_op_create_function_object( const ecma_char_t* formal_parameter_list_p[], /* size_t formal_parameters_number, /**< formal parameters list's length */ ecma_object_t *scope_p, /**< function's scope */ bool is_strict, /**< 'strict' flag */ - interp_bytecode_idx first_opcode_idx) /**< index of first opcode of function's body */ + opcode_counter_t first_opcode_idx) /**< index of first opcode of function's body */ { // 1., 4., 13. FIXME( Setup prototype of Function object to built-in Function prototype object (15.3.3.1) ); @@ -262,7 +262,7 @@ ecma_op_function_call( ecma_object_t *func_obj_p, /**< Function object */ bool is_strict; // 8. - interp_bytecode_idx code_first_opcode_idx = ecma_unpack_code_internal_property_value( code_prop_value, &is_strict); + opcode_counter_t code_first_opcode_idx = ecma_unpack_code_internal_property_value( code_prop_value, &is_strict); ecma_value_t this_binding; // 1. diff --git a/src/libecmaoperations/ecma-function-object.h b/src/libecmaoperations/ecma-function-object.h index 7df749008..53e527c0a 100644 --- a/src/libecmaoperations/ecma-function-object.h +++ b/src/libecmaoperations/ecma-function-object.h @@ -33,7 +33,7 @@ ecma_op_create_function_object( const ecma_char_t* formal_parameter_list_p[], size_t formal_parameters_number, ecma_object_t *scope_p, bool is_strict, - interp_bytecode_idx first_opcode_idx); + opcode_counter_t first_opcode_idx); extern ecma_object_t* ecma_op_get_throw_type_error( void);