|
| 1 | +import collections |
1 | 2 | import operator
|
2 | 3 | import os
|
3 | 4 | import sys
|
|
21 | 22 | import termcolor
|
22 | 23 |
|
23 | 24 |
|
| 25 | +# Many opcodes end up delegating to special functions in the object protocol -- |
| 26 | +# this maps bytecode operation names to the corresponding special function |
| 27 | +# name. |
24 | 28 | OPNAME_TO_SPECIAL = {
|
25 |
| - 'BINARY_SUBTRACT': '__sub__', |
26 | 29 | 'BINARY_ADD': '__add__',
|
27 |
| - 'BINARY_SUBSCR': '__getitem__', |
28 | 30 | 'BINARY_AND': '__and__',
|
29 | 31 | 'BINARY_MULTIPLY': '__mul__',
|
30 | 32 | 'BINARY_OR': '__or__',
|
31 | 33 | 'BINARY_POWER': '__pow__',
|
| 34 | + 'BINARY_SUBSCR': '__getitem__', |
| 35 | + 'BINARY_SUBTRACT': '__sub__', |
32 | 36 | }
|
| 37 | +# These are the "right hand side" variants of the above for the symmetrical |
| 38 | +# binops. |
33 | 39 | OPNAME_TO_SPECIAL_RHS = {
|
34 | 40 | 'BINARY_ADD': '__radd__',
|
35 |
| - 'BINARY_SUBTRACT': '__rsub__', |
36 |
| - 'BINARY_MULTIPLY': '__rmul__', |
37 | 41 | 'BINARY_AND': '__rand__',
|
| 42 | + 'BINARY_MULTIPLY': '__rmul__', |
38 | 43 | 'BINARY_OR': '__ror__',
|
39 | 44 | 'BINARY_POWER': '__rpow__',
|
| 45 | + 'BINARY_SUBTRACT': '__rsub__', |
40 | 46 | }
|
| 47 | + |
41 | 48 | COMPARE_TO_SPECIAL = {
|
42 | 49 | '==': '__eq__',
|
43 | 50 | '!=': '__ne__',
|
@@ -139,6 +146,7 @@ def run_binop(opname: Text, lhs: Any, rhs: Any, ictx: ICtx) -> Result[Any]:
|
139 | 146 | builtin_value_types = {
|
140 | 147 | ebool, ebytes, estr, eint, elist, edict, ebytearray, eset, etuple,
|
141 | 148 | float, complex, slice, range, ebytearray, type(sys.version_info),
|
| 149 | + collections.OrderedDict, |
142 | 150 | }
|
143 | 151 |
|
144 | 152 | if (opname in ('BINARY_TRUE_DIVIDE', 'BINARY_MODULO') and rhs_type is eint
|
|
0 commit comments