summaryrefslogtreecommitdiff
path: root/py/runtime.c
diff options
context:
space:
mode:
Diffstat (limited to 'py/runtime.c')
-rw-r--r--py/runtime.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/py/runtime.c b/py/runtime.c
index 21ef42577..c533558da 100644
--- a/py/runtime.c
+++ b/py/runtime.c
@@ -555,7 +555,20 @@ generic_binary_op:
}
}
- // TODO implement dispatch for reverse binary ops
+#if MICROPY_PY_REVERSE_SPECIAL_METHODS
+ if (op >= MP_BINARY_OP_OR && op <= MP_BINARY_OP_REVERSE_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;
+ }
+
+ // Convert __rop__ back to __op__ for error message
+ op -= MP_BINARY_OP_REVERSE_OR - MP_BINARY_OP_OR;
+ }
+#endif
unsupported_op:
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {