Add opcode handlers for logical_[not, or, and]]

This commit is contained in:
e.gavrin
2014-08-22 01:27:37 +04:00
parent 8e4ff93436
commit 7bda6e9d01
2 changed files with 150 additions and 3 deletions
+125 -3
View File
@@ -467,9 +467,6 @@ do_number_bitwise_logic (struct __int_data *int_data, /**< interpreter context *
op (typeof) \
op (with) \
op (end_with) \
op (logical_not) \
op (logical_and) \
op (logical_or) \
op (meta) \
static char __unused unimplemented_list_end
@@ -2282,6 +2279,131 @@ opfunc_in (OPCODE opdata __unused, /**< operation data */
return ret_value;
} /* opfunc_in */
/**
* 'Logical NOT Operator' opcode handler.
*
* See also: ECMA-262 v5, 11.4.9
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value
*/
ecma_completion_value_t
opfunc_logical_not (OPCODE opdata, /**< operation data */
struct __int_data *int_data) /**< interpreter context */
{
const T_IDX dst_var_idx = opdata.data.logical_not.dst;
const T_IDX right_var_idx = opdata.data.logical_not.var_right;
int_data->pos++;
ecma_completion_value_t ret_value;
ECMA_TRY_CATCH (right_value, get_variable_value (int_data, right_var_idx, false), ret_value);
ecma_simple_value_t old_value = ECMA_SIMPLE_VALUE_TRUE;
ecma_completion_value_t to_bool_value = ecma_op_to_boolean (right_value.value);
if (ecma_is_value_true (to_bool_value.value))
{
old_value = ECMA_SIMPLE_VALUE_FALSE;
}
ret_value = set_variable_value (int_data,
dst_var_idx,
ecma_make_simple_value (old_value));
ECMA_FINALIZE (right_value);
return ret_value;
} /* opfunc_logical_not */
/**
* 'Logical OR Operator' opcode handler.
*
* See also: ECMA-262 v5, 11.11
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value
*/
ecma_completion_value_t
opfunc_logical_or (OPCODE opdata, /**< operation data */
struct __int_data *int_data) /**< interpreter context */
{
const T_IDX dst_var_idx = opdata.data.logical_or.dst;
const T_IDX left_var_idx = opdata.data.logical_or.var_left;
const T_IDX right_var_idx = opdata.data.logical_or.var_right;
int_data->pos++;
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_completion_value_t to_bool_value = ecma_op_to_boolean (left_value.value);
if (ecma_is_value_true (to_bool_value.value))
{
ret_value = set_variable_value (int_data,
dst_var_idx,
left_value.value);
}
else
{
ret_value = set_variable_value (int_data,
dst_var_idx,
right_value.value);
}
ECMA_FINALIZE (right_value);
ECMA_FINALIZE (left_value);
return ret_value;
} /* opfunc_logical_or */
/**
* 'Logical AND Operator' opcode handler.
*
* See also: ECMA-262 v5, 11.11
*
* @return completion value
* Returned value must be freed with ecma_free_completion_value
*/
ecma_completion_value_t
opfunc_logical_and (OPCODE opdata, /**< operation data */
struct __int_data *int_data) /**< interpreter context */
{
const T_IDX dst_var_idx = opdata.data.logical_and.dst;
const T_IDX left_var_idx = opdata.data.logical_and.var_left;
const T_IDX right_var_idx = opdata.data.logical_and.var_right;
int_data->pos++;
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_completion_value_t to_bool_value = ecma_op_to_boolean (left_value.value);
if (ecma_is_value_true (to_bool_value.value) == false)
{
ret_value = set_variable_value (int_data,
dst_var_idx,
left_value.value);
}
else
{
ret_value = set_variable_value (int_data,
dst_var_idx,
right_value.value);
}
ECMA_FINALIZE (right_value);
ECMA_FINALIZE (left_value);
return ret_value;
} /* opfunc_logical_and */
/** Opcode generators. */
GETOP_IMPL_2 (is_true_jmp, value, opcode)
+25
View File
@@ -0,0 +1,25 @@
// Copyright 2014 Samsung Electronics Co., Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
assert((!false) === true);
assert((true || true) === true);
assert((false || true) === true);
assert((false || false) === false);
assert((true || false) === true);
assert((true && true) === true);
assert((true && false) === false);
assert((false && true) === false);
assert((false && false) === false);