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/showbc.c | |
parent | e242b1785f9e25b36f5d225652c679cd7cec6ec0 (diff) | |
download | micropython-bdbe8c9ae21559f6dc0b8e1ad84b7bbec2a04726.tar.gz micropython-bdbe8c9ae21559f6dc0b8e1ad84b7bbec2a04726.zip |
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/showbc.c')
-rw-r--r-- | py/showbc.c | 6 |
1 files changed, 1 insertions, 5 deletions
diff --git a/py/showbc.c b/py/showbc.c index 9b08fa6d63..dd5959f4a9 100644 --- a/py/showbc.c +++ b/py/showbc.c @@ -399,10 +399,6 @@ const byte *mp_bytecode_print_str(const byte *ip) { printf("POP_EXCEPT"); break; - case MP_BC_NOT: - printf("NOT"); - break; - case MP_BC_BUILD_TUPLE: DECODE_UINT; printf("BUILD_TUPLE " UINT_FMT, unum); @@ -541,7 +537,7 @@ const byte *mp_bytecode_print_str(const byte *ip) { printf("LOAD_FAST " UINT_FMT, (mp_uint_t)ip[-1] - MP_BC_LOAD_FAST_MULTI); } else if (ip[-1] < MP_BC_STORE_FAST_MULTI + 16) { printf("STORE_FAST " UINT_FMT, (mp_uint_t)ip[-1] - MP_BC_STORE_FAST_MULTI); - } else if (ip[-1] < MP_BC_UNARY_OP_MULTI + 6) { + } else if (ip[-1] < MP_BC_UNARY_OP_MULTI + 7) { printf("UNARY_OP " UINT_FMT, (mp_uint_t)ip[-1] - MP_BC_UNARY_OP_MULTI); } else if (ip[-1] < MP_BC_BINARY_OP_MULTI + 36) { mp_uint_t op = ip[-1] - MP_BC_BINARY_OP_MULTI; |