aboutsummaryrefslogtreecommitdiff
path: root/py/runtime.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2019-10-29 12:08:07 +1100
committerDamien George <damien.p.george@gmail.com>2019-10-29 23:13:51 +1100
commit323d47887f0e407b6560a5957ea934049e70d2aa (patch)
treeb2b9be3ababe644123d964731ea7f653822fa86f /py/runtime.c
parent25946d1ef4c20439368b37ec27acf2184b25be28 (diff)
py/runtime: Reorder some binary ops so they don't require conditionals.
runtime0.h is part of the MicroPython ABI so it's simpler if it's independent of config options, like MICROPY_PY_REVERSE_SPECIAL_METHODS. What's effectively done here is to move MP_BINARY_OP_DIVMOD and MP_BINARY_OP_CONTAINS up in the enum, then remove the #if MICROPY_PY_REVERSE_SPECIAL_METHODS conditional. Without this change .mpy files would need to have a feature flag for MICROPY_PY_REVERSE_SPECIAL_METHODS (when embedding native code that uses this enum). This commit has no effect when MICROPY_PY_REVERSE_SPECIAL_METHODS is disabled. With this option enabled this commit reduces code size by about 60 bytes.
Diffstat (limited to 'py/runtime.c')
-rw-r--r--py/runtime.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/py/runtime.c b/py/runtime.c
index 6b7a9ce3c..deb82e935 100644
--- a/py/runtime.c
+++ b/py/runtime.c
@@ -570,16 +570,17 @@ generic_binary_op:
}
#if MICROPY_PY_REVERSE_SPECIAL_METHODS
- if (op >= MP_BINARY_OP_OR && op <= MP_BINARY_OP_REVERSE_POWER) {
+ if (op >= MP_BINARY_OP_OR && op <= MP_BINARY_OP_POWER) {
mp_obj_t t = rhs;
rhs = lhs;
lhs = t;
- if (op <= MP_BINARY_OP_POWER) {
- op += MP_BINARY_OP_REVERSE_OR - MP_BINARY_OP_OR;
- goto generic_binary_op;
- }
-
+ op += MP_BINARY_OP_REVERSE_OR - MP_BINARY_OP_OR;
+ goto generic_binary_op;
+ } else if (op >= MP_BINARY_OP_REVERSE_OR) {
// Convert __rop__ back to __op__ for error message
+ mp_obj_t t = rhs;
+ rhs = lhs;
+ lhs = t;
op -= MP_BINARY_OP_REVERSE_OR - MP_BINARY_OP_OR;
}
#endif