diff options
author | Damien George <damien.p.george@gmail.com> | 2015-12-08 12:28:11 +0000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2015-12-10 22:19:48 +0000 |
commit | bdbe8c9ae21559f6dc0b8e1ad84b7bbec2a04726 (patch) | |
tree | 3c603ca42bd10e7d5bbd037d85d6b57735d39393 /py/bc0.h | |
parent | e242b1785f9e25b36f5d225652c679cd7cec6ec0 (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/bc0.h')
-rw-r--r-- | py/bc0.h | 6 |
1 files changed, 2 insertions, 4 deletions
@@ -80,8 +80,6 @@ #define MP_BC_POP_EXCEPT (0x45) #define MP_BC_UNWIND_JUMP (0x46) // rel byte code offset, 16-bit signed, in excess; then a byte -#define MP_BC_NOT (0x47) - #define MP_BC_BUILD_TUPLE (0x50) // uint #define MP_BC_BUILD_LIST (0x51) // uint #define MP_BC_LIST_APPEND (0x52) // uint @@ -115,7 +113,7 @@ #define MP_BC_LOAD_CONST_SMALL_INT_MULTI (0x70) // + N(64) #define MP_BC_LOAD_FAST_MULTI (0xb0) // + N(16) #define MP_BC_STORE_FAST_MULTI (0xc0) // + N(16) -#define MP_BC_UNARY_OP_MULTI (0xd0) // + op(6) -#define MP_BC_BINARY_OP_MULTI (0xd6) // + op(36) +#define MP_BC_UNARY_OP_MULTI (0xd0) // + op(7) +#define MP_BC_BINARY_OP_MULTI (0xd7) // + op(36) #endif // __MICROPY_INCLUDED_PY_BC0_H__ |