summaryrefslogtreecommitdiff
path: root/py/emitnative.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2015-12-08 12:28:11 +0000
committerDamien George <damien.p.george@gmail.com>2015-12-10 22:19:48 +0000
commitbdbe8c9ae21559f6dc0b8e1ad84b7bbec2a04726 (patch)
tree3c603ca42bd10e7d5bbd037d85d6b57735d39393 /py/emitnative.c
parente242b1785f9e25b36f5d225652c679cd7cec6ec0 (diff)
py: Make UNARY_OP_NOT a first-class op, to agree with Py not semantics.
Fixes #1684 and makes "not" match Python semantics. The code is also simplified (the separate MP_BC_NOT opcode is removed) and the patch saves 68 bytes for bare-arm/ and 52 bytes for minimal/. Previously "not x" was implemented as !mp_unary_op(x, MP_UNARY_OP_BOOL), so any given object only needs to implement MP_UNARY_OP_BOOL (and the VM had a special opcode to do the ! bit). With this patch "not x" is implemented as mp_unary_op(x, MP_UNARY_OP_NOT), but this operation is caught at the start of mp_unary_op and dispatched as !mp_obj_is_true(x). mp_obj_is_true has special logic to test for truthness, and is the correct way to handle the not operation.
Diffstat (limited to 'py/emitnative.c')
-rw-r--r--py/emitnative.c5
1 files changed, 0 insertions, 5 deletions
diff --git a/py/emitnative.c b/py/emitnative.c
index 34e0b928b..65908070f 100644
--- a/py/emitnative.c
+++ b/py/emitnative.c
@@ -2061,11 +2061,6 @@ STATIC void emit_native_unary_op(emit_t *emit, mp_unary_op_t op) {
vtype_kind_t vtype;
emit_pre_pop_reg(emit, &vtype, REG_ARG_2);
if (vtype == VTYPE_PYOBJ) {
- if (op == MP_UNARY_OP_NOT) {
- // we need to synthesise this operation by converting to bool first
- emit_call_with_imm_arg(emit, MP_F_UNARY_OP, MP_UNARY_OP_BOOL, REG_ARG_1);
- ASM_MOV_REG_REG(emit->as, REG_ARG_2, REG_RET);
- }
emit_call_with_imm_arg(emit, MP_F_UNARY_OP, op, REG_ARG_1);
emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET);
} else {