aboutsummaryrefslogtreecommitdiff
path: root/py/runtime0.h
diff options
context:
space:
mode:
authorPaul Sokolovsky <pfalcon@users.sourceforge.net>2017-09-10 17:05:20 +0300
committerPaul Sokolovsky <pfalcon@users.sourceforge.net>2017-09-10 17:05:57 +0300
commiteb84a830df62813f5af7f0144fc77444bf18f3a8 (patch)
treec75036150f3584486bc2064572faa2fe2750ae8c /py/runtime0.h
parentde981040b392685b0d7f2381a63526b71e633b9c (diff)
py/runtime: Implement dispatch for "reverse op" special methods.
If, for class X, X.__add__(Y) doesn't exist (or returns NotImplemented), try Y.__radd__(X) instead. This patch could be simpler, but requires undoing operand swap and operation switch to get non-confusing error message in case __radd__ doesn't exist.
Diffstat (limited to 'py/runtime0.h')
-rw-r--r--py/runtime0.h17
1 files changed, 17 insertions, 0 deletions
diff --git a/py/runtime0.h b/py/runtime0.h
index 3cf5e530d..a3e9d46b9 100644
--- a/py/runtime0.h
+++ b/py/runtime0.h
@@ -101,6 +101,23 @@ typedef enum {
// Operations below this line don't appear in bytecode, they
// just identify special methods.
+ // MP_BINARY_OP_REVERSE_* must follow immediately after MP_BINARY_OP_*
+#if MICROPY_PY_REVERSE_SPECIAL_METHODS
+ MP_BINARY_OP_REVERSE_OR,
+ MP_BINARY_OP_REVERSE_XOR,
+ MP_BINARY_OP_REVERSE_AND,
+ MP_BINARY_OP_REVERSE_LSHIFT,
+ MP_BINARY_OP_REVERSE_RSHIFT,
+ MP_BINARY_OP_REVERSE_ADD,
+
+ MP_BINARY_OP_REVERSE_SUBTRACT,
+ MP_BINARY_OP_REVERSE_MULTIPLY,
+ MP_BINARY_OP_REVERSE_FLOOR_DIVIDE,
+ MP_BINARY_OP_REVERSE_TRUE_DIVIDE,
+ MP_BINARY_OP_REVERSE_MODULO,
+ MP_BINARY_OP_REVERSE_POWER,
+#endif
+
MP_BINARY_OP_DIVMOD, // not emitted by the compiler but supported by the runtime
MP_BINARY_OP_LAST,