From bdbe8c9ae21559f6dc0b8e1ad84b7bbec2a04726 Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 8 Dec 2015 12:28:11 +0000 Subject: 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. --- py/runtime0.h | 2 -- 1 file changed, 2 deletions(-) (limited to 'py/runtime0.h') diff --git a/py/runtime0.h b/py/runtime0.h index d00949f92..6417cfd03 100644 --- a/py/runtime0.h +++ b/py/runtime0.h @@ -45,8 +45,6 @@ typedef enum { MP_UNARY_OP_POSITIVE, MP_UNARY_OP_NEGATIVE, MP_UNARY_OP_INVERT, - // The NOT op is only implemented by bool. The emitter must synthesise NOT - // for other types by calling BOOL then inverting (eg by then calling NOT). MP_UNARY_OP_NOT, } mp_unary_op_t; -- cgit v1.2.3