mirror of
https://github.com/micropython/micropython.git
synced 2026-01-07 12:40:15 +01:00
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.
This commit is contained in:
10
py/vm.c
10
py/vm.c
@@ -760,14 +760,6 @@ unwind_jump:;
|
||||
//sp -= 3; // pop 3 exception values
|
||||
DISPATCH();
|
||||
|
||||
ENTRY(MP_BC_NOT):
|
||||
if (TOP() == mp_const_true) {
|
||||
SET_TOP(mp_const_false);
|
||||
} else {
|
||||
SET_TOP(mp_const_true);
|
||||
}
|
||||
DISPATCH();
|
||||
|
||||
ENTRY(MP_BC_BUILD_TUPLE): {
|
||||
MARK_EXC_IP_SELECTIVE();
|
||||
DECODE_UINT;
|
||||
@@ -1230,7 +1222,7 @@ yield:
|
||||
} else if (ip[-1] < MP_BC_STORE_FAST_MULTI + 16) {
|
||||
fastn[MP_BC_STORE_FAST_MULTI - (mp_int_t)ip[-1]] = POP();
|
||||
DISPATCH();
|
||||
} else if (ip[-1] < MP_BC_UNARY_OP_MULTI + 6) {
|
||||
} else if (ip[-1] < MP_BC_UNARY_OP_MULTI + 7) {
|
||||
SET_TOP(mp_unary_op(ip[-1] - MP_BC_UNARY_OP_MULTI, TOP()));
|
||||
DISPATCH();
|
||||
} else if (ip[-1] < MP_BC_BINARY_OP_MULTI + 36) {
|
||||
|
||||
Reference in New Issue
Block a user