From b822c704e59121354de8d12867eb5d3b06d63a78 Mon Sep 17 00:00:00 2001 From: "e.gavrin" Date: Thu, 21 Aug 2014 22:52:34 +0400 Subject: [PATCH] Add b_not opcode handler. Fixes in shift opcodes and in test --- src/libcoreint/opcodes.c | 52 +++++++++++++++++++++++++++++++----- tests/jerry/bitwise_logic.js | 13 ++++----- tests/jerry/shift.js | 10 +++---- 3 files changed, 57 insertions(+), 18 deletions(-) diff --git a/src/libcoreint/opcodes.c b/src/libcoreint/opcodes.c index 9486fff51..a04ea14b8 100644 --- a/src/libcoreint/opcodes.c +++ b/src/libcoreint/opcodes.c @@ -291,6 +291,7 @@ typedef enum number_bitwise_shift_left, /**< bitwise LEFT SHIFT calculation */ number_bitwise_shift_right, /**< bitwise RIGHT_SHIFT calculation */ number_bitwise_shift_uright, /**< bitwise UNSIGNED RIGHT SHIFT calculation */ + number_bitwise_not, /**< bitwise NOT calculation */ } number_bitwise_logic_op; /** @@ -430,6 +431,11 @@ do_number_bitwise_logic (struct __int_data *int_data, /**< interpreter context * *res_p = ecma_uint32_to_number (left_uint32 >> (right_uint32 & 0x1F)); break; } + case number_bitwise_not: + { + *res_p = ecma_int32_to_number (~right_int32); + break; + } } ret_value = set_variable_value (int_data, @@ -463,7 +469,6 @@ do_number_bitwise_logic (struct __int_data *int_data, /**< interpreter context * op (logical_not) \ op (logical_and) \ op (logical_or) \ - op (b_not) \ op (instanceof) \ op (in) \ op (meta) \ @@ -1176,9 +1181,9 @@ ecma_completion_value_t opfunc_b_shift_right (OPCODE opdata, /**< operation data */ struct __int_data *int_data) /**< interpreter context */ { - const T_IDX dst_var_idx = opdata.data.b_shift_left.dst; - const T_IDX left_var_idx = opdata.data.b_shift_left.var_left; - const T_IDX right_var_idx = opdata.data.b_shift_left.var_right; + const T_IDX dst_var_idx = opdata.data.b_shift_right.dst; + const T_IDX left_var_idx = opdata.data.b_shift_right.var_left; + const T_IDX right_var_idx = opdata.data.b_shift_right.var_right; int_data->pos++; @@ -1211,9 +1216,9 @@ ecma_completion_value_t opfunc_b_shift_uright (OPCODE opdata, /**< operation data */ struct __int_data *int_data) /**< interpreter context */ { - const T_IDX dst_var_idx = opdata.data.b_shift_left.dst; - const T_IDX left_var_idx = opdata.data.b_shift_left.var_left; - const T_IDX right_var_idx = opdata.data.b_shift_left.var_right; + const T_IDX dst_var_idx = opdata.data.b_shift_uright.dst; + const T_IDX left_var_idx = opdata.data.b_shift_uright.var_left; + const T_IDX right_var_idx = opdata.data.b_shift_uright.var_right; int_data->pos++; @@ -1234,6 +1239,39 @@ opfunc_b_shift_uright (OPCODE opdata, /**< operation data */ return ret_value; } /* opfunc_b_shift_uright */ +/** + * 'Bitwise NOT Operator' opcode handler. + * + * See also: ECMA-262 v5, 10.4 + * + * @return completion value + * Returned value must be freed with ecma_free_completion_value + */ +ecma_completion_value_t +opfunc_b_not (OPCODE opdata, /**< operation data */ + struct __int_data *int_data) /**< interpreter context */ +{ + const T_IDX dst_var_idx = opdata.data.b_not.dst; + const T_IDX right_var_idx = opdata.data.b_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); + + ret_value = do_number_bitwise_logic (int_data, + dst_var_idx, + number_bitwise_not, + right_value.value, + right_value.value); + + ECMA_FINALIZE (right_value); + + return ret_value; +} /* opfunc_b_not */ + + /** * 'Pre increment' opcode handler. * diff --git a/tests/jerry/bitwise_logic.js b/tests/jerry/bitwise_logic.js index d835b7e19..e4f573189 100644 --- a/tests/jerry/bitwise_logic.js +++ b/tests/jerry/bitwise_logic.js @@ -12,9 +12,10 @@ // See the License for the specific language governing permissions and // limitations under the License. -assert((5 & 2) == 0); -assert((2 & 2) == 2); -assert((5 | 2) == 7); -assert((5 | 5) == 5); -assert((5 ^ 2) == 7); -assert((5 ^ 5) == 0); +assert((5 & 2) === 0); +assert((2 & 2) === 2); +assert((5 | 2) === 7); +assert((5 | 5) === 5); +assert((5 ^ 2) === 7); +assert((5 ^ 5) === 0); +assert((~5) == -6); diff --git a/tests/jerry/shift.js b/tests/jerry/shift.js index 3e3c2f0c4..c350aa259 100644 --- a/tests/jerry/shift.js +++ b/tests/jerry/shift.js @@ -12,10 +12,10 @@ // See the License for the specific language governing permissions and // limitations under the License. -assert(9 << 2 === 36); -assert(14 << 2 === 56); +assert((9 << 2) === 36); +assert((14 << 2) === 56); -assert(9 >> 2 === 2); -assert(-14 >> 2 === -4); +assert((9 >> 2) === 2); +assert((-14 >> 2) === -4); -assert(9 >>> 2 === 9 >> 2); +assert((9 >>> 2) === (9 >> 2));