Merge branch 'master' of git-server:jerry

This commit is contained in:
Ilmir Usmanov
2014-07-23 22:56:06 +04:00
6 changed files with 176 additions and 23 deletions
+84 -12
View File
@@ -316,8 +316,6 @@ do_number_arithmetic(struct __int_data *int_data, /**< interpreter context */
} /* do_number_arithmetic */
#define OP_UNIMPLEMENTED_LIST(op) \
op(is_true_jmp) \
op(is_false_jmp) \
op(call_0) \
op(call_n) \
op(func_decl_1) \
@@ -399,7 +397,81 @@ opfunc_call_1 (OPCODE opdata __unused, struct __int_data *int_data)
}
/**
* Jump opcode handler.
* 'Jump if true' opcode handler.
*
* Note:
* the opcode changes current opcode position to specified opcode index
* if argument evaluates to true.
*/
ecma_completion_value_t
opfunc_is_true_jmp (OPCODE opdata, /**< operation data */
struct __int_data *int_data) /**< interpreter context */
{
const T_IDX cond_var_idx = opdata.data.is_true_jmp.value;
const T_IDX dst_opcode_idx = opdata.data.is_true_jmp.opcode;
ecma_completion_value_t ret_value;
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) );
if ( ecma_is_value_true( to_bool_completion.value) )
{
int_data->pos = dst_opcode_idx;
}
else
{
int_data->pos++;
}
ret_value = ecma_make_empty_completion_value();
FINALIZE(cond_value);
return ret_value;
} /* opfunc_is_true_jmp */
/**
* 'Jump if false' opcode handler.
*
* Note:
* the opcode changes current opcode position to specified opcode index
* if argument evaluates to false.
*/
ecma_completion_value_t
opfunc_is_false_jmp (OPCODE opdata, /**< operation data */
struct __int_data *int_data) /**< interpreter context */
{
const T_IDX cond_var_idx = opdata.data.is_false_jmp.value;
const T_IDX dst_opcode_idx = opdata.data.is_false_jmp.opcode;
ecma_completion_value_t ret_value;
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) );
if ( !ecma_is_value_true( to_bool_completion.value) )
{
int_data->pos = dst_opcode_idx;
}
else
{
int_data->pos++;
}
ret_value = ecma_make_empty_completion_value();
FINALIZE(cond_value);
return ret_value;
} /* opfunc_is_false_jmp */
/**
* 'Jump' opcode handler.
*
* Note:
* the opcode changes current opcode position to specified opcode index
@@ -414,7 +486,7 @@ opfunc_jmp (OPCODE opdata, /**< operation data */
} /* opfunc_jmp */
/**
* Jump down opcode handler.
* 'Jump down' opcode handler.
*
* Note:
* the opcode changes adds specified value to current opcode position
@@ -429,7 +501,7 @@ opfunc_jmp_down (OPCODE opdata, /**< operation data */
} /* opfunc_jmp_down */
/**
* Jump up opcode handler.
* 'Jump up' opcode handler.
*
* Note:
* the opcode changes substracts specified value from current opcode position
@@ -446,7 +518,7 @@ opfunc_jmp_up (OPCODE opdata, /**< operation data */
} /* opfunc_jmp_up */
/**
* Assignment opcode handler.
* 'Assignment' opcode handler.
*
* Note:
* This handler implements case of assignment of a literal's or a variable's
@@ -545,7 +617,7 @@ opfunc_assignment (OPCODE opdata, /**< operation data */
} /* opfunc_assignment */
/**
* Addition opcode handler.
* 'Addition' opcode handler.
*
* See also: ECMA-262 v5, 11.6.1
*
@@ -592,7 +664,7 @@ opfunc_addition(OPCODE opdata, /**< operation data */
} /* opfunc_addition */
/**
* Substraction opcode handler.
* 'Substraction' opcode handler.
*
* See also: ECMA-262 v5, 11.6.2
*
@@ -627,7 +699,7 @@ opfunc_substraction(OPCODE opdata, /**< operation data */
} /* opfunc_substraction */
/**
* Multiplication opcode handler.
* 'Multiplication' opcode handler.
*
* See also: ECMA-262 v5, 11.5, 11.5.1
*
@@ -662,7 +734,7 @@ opfunc_multiplication(OPCODE opdata, /**< operation data */
} /* opfunc_multiplication */
/**
* Division opcode handler.
* 'Division' opcode handler.
*
* See also: ECMA-262 v5, 11.5, 11.5.2
*
@@ -697,7 +769,7 @@ opfunc_division(OPCODE opdata, /**< operation data */
} /* opfunc_division */
/**
* Remainder calculation opcode handler.
* 'Remainder calculation' opcode handler.
*
* See also: ECMA-262 v5, 11.5, 11.5.3
*
@@ -732,7 +804,7 @@ opfunc_remainder(OPCODE opdata, /**< operation data */
} /* opfunc_remainder */
/**
* Variable declaration opcode handler.
* 'Variable declaration' opcode handler.
*
* See also: ECMA-262 v5, 10.5 - Declaration binding instantiation (block 8).
*
+72
View File
@@ -116,6 +116,78 @@ ecma_op_to_primitive( ecma_value_t value) /**< ecma-value */
JERRY_UNREACHABLE();
} /* ecma_op_to_primitive */
/**
* ToBoolean operation.
*
* See also:
* ECMA-262 v5, 9.2
*
* @return completion value
* Returned value is simple and so need not be freed.
* However, ecma_free_completion_value may be called for it, but it is a no-op.
*/
ecma_completion_value_t
ecma_op_to_boolean( ecma_value_t value) /**< ecma-value */
{
ecma_simple_value_t res = ECMA_SIMPLE_VALUE_EMPTY;
switch ( (ecma_type_t)value.value_type )
{
case ECMA_TYPE_NUMBER:
{
ecma_number_t *num_p = ecma_get_pointer( value.value);
TODO( Implement according to ECMA );
res = ( *num_p == 0 ) ? ECMA_SIMPLE_VALUE_FALSE:
ECMA_SIMPLE_VALUE_TRUE;
break;
}
case ECMA_TYPE_SIMPLE:
{
if ( ecma_is_value_boolean (value ) )
{
res = value.value;
} else if ( ecma_is_value_undefined (value)
|| ecma_is_value_null( value) )
{
res = ECMA_SIMPLE_VALUE_FALSE;
} else
{
JERRY_UNREACHABLE();
}
break;
}
case ECMA_TYPE_STRING:
{
ecma_array_first_chunk_t *str_p = ecma_get_pointer( value.value);
res = ( str_p->header.unit_number == 0 ) ? ECMA_SIMPLE_VALUE_FALSE:
ECMA_SIMPLE_VALUE_TRUE;
break;
}
case ECMA_TYPE_OBJECT:
{
res = ECMA_SIMPLE_VALUE_TRUE;
break;
}
case ECMA_TYPE__COUNT:
{
JERRY_UNREACHABLE();
}
}
JERRY_ASSERT( res == ECMA_SIMPLE_VALUE_FALSE
|| res == ECMA_SIMPLE_VALUE_TRUE );
return ecma_make_completion_value (ECMA_COMPLETION_TYPE_NORMAL,
ecma_make_simple_value( res),
ECMA_TARGET_ID_RESERVED);
} /* ecma_op_to_boolean */
/**
* ToNumber operation.
*
+1
View File
@@ -28,6 +28,7 @@
extern ecma_completion_value_t ecma_op_check_object_coercible( ecma_value_t value);
extern ecma_completion_value_t ecma_op_to_primitive( ecma_value_t value);
extern ecma_completion_value_t ecma_op_to_boolean( ecma_value_t value);
extern ecma_completion_value_t ecma_op_to_number( ecma_value_t value);
extern ecma_completion_value_t ecma_op_to_object( ecma_value_t value);
+5 -3
View File
@@ -86,9 +86,11 @@ ecma_make_reference(ecma_value_t base, /**< base value */
ecma_char_t *name_p, /**< referenced name */
bool is_strict) /**< strict reference flag */
{
return (ecma_reference_t) { .base = ecma_copy_value( base),
.referenced_name_p = name_p,
.is_strict = is_strict };
ecma_reference_t ref = (ecma_reference_t) { .base = ecma_copy_value( base),
.referenced_name_p = name_p,
.is_strict = is_strict };
return ref;
} /* ecma_make_reference */
/**
+11 -7
View File
@@ -26,13 +26,17 @@ main( int __unused argc,
char __unused **argv)
{
const OPCODE test_program[] = {
getop_var_decl( 0),
getop_var_decl( 1),
getop_assignment( 0, OPCODE_ARG_TYPE_STRING, 1),
getop_assignment( 1, OPCODE_ARG_TYPE_VARIABLE, 0),
getop_assignment( 0, OPCODE_ARG_TYPE_SMALLINT, 253),
getop_assignment( 1, OPCODE_ARG_TYPE_NUMBER, 2),
getop_exitval( 0)
/* 0: */ getop_var_decl( 0),
/* 1: */ getop_var_decl( 1),
/* 2: */ getop_assignment( 0, OPCODE_ARG_TYPE_STRING, 1),
/* 3: */ getop_assignment( 1, OPCODE_ARG_TYPE_VARIABLE, 0),
/* 4: */ getop_is_true_jmp( 1, 6),
/* 5: */ getop_jmp_down( 5),
/* 6: */ getop_assignment( 0, OPCODE_ARG_TYPE_SMALLINT, 253),
/* 7: */ getop_assignment( 1, OPCODE_ARG_TYPE_NUMBER, 2),
/* 8: */ getop_is_false_jmp( 1, 10),
/* 9: */ getop_exitval( 0),
/* 10: */ getop_exitval( 1)
};
mem_init();
@@ -27,7 +27,9 @@ main( int __unused argc,
{
const OPCODE test_program[] = {
getop_var_decl( 0),
getop_exitval( 0)
getop_is_true_jmp( 0, 3),
getop_exitval( 0),
getop_exitval( 1)
};
mem_init();