|
27 | 27 | package com.oracle.graal.python.builtins.objects.foreign;
|
28 | 28 |
|
29 | 29 | import static com.oracle.graal.python.builtins.PythonBuiltinClassType.AttributeError;
|
30 |
| -import static com.oracle.graal.python.builtins.PythonBuiltinClassType.StopIteration; |
31 | 30 | import static com.oracle.graal.python.builtins.PythonBuiltinClassType.MemoryError;
|
| 31 | +import static com.oracle.graal.python.builtins.PythonBuiltinClassType.StopIteration; |
32 | 32 | import static com.oracle.graal.python.nodes.SpecialAttributeNames.__BASES__;
|
33 | 33 | import static com.oracle.graal.python.nodes.SpecialMethodNames.__ADD__;
|
| 34 | +import static com.oracle.graal.python.nodes.SpecialMethodNames.__AND__; |
34 | 35 | import static com.oracle.graal.python.nodes.SpecialMethodNames.__BOOL__;
|
35 | 36 | import static com.oracle.graal.python.nodes.SpecialMethodNames.__CALL__;
|
36 | 37 | import static com.oracle.graal.python.nodes.SpecialMethodNames.__DELATTR__;
|
|
53 | 54 | import static com.oracle.graal.python.nodes.SpecialMethodNames.__NEW__;
|
54 | 55 | import static com.oracle.graal.python.nodes.SpecialMethodNames.__NEXT__;
|
55 | 56 | import static com.oracle.graal.python.nodes.SpecialMethodNames.__NE__;
|
| 57 | +import static com.oracle.graal.python.nodes.SpecialMethodNames.__OR__; |
56 | 58 | import static com.oracle.graal.python.nodes.SpecialMethodNames.__RADD__;
|
| 59 | +import static com.oracle.graal.python.nodes.SpecialMethodNames.__RAND__; |
57 | 60 | import static com.oracle.graal.python.nodes.SpecialMethodNames.__RDIVMOD__;
|
58 | 61 | import static com.oracle.graal.python.nodes.SpecialMethodNames.__REPR__;
|
59 | 62 | import static com.oracle.graal.python.nodes.SpecialMethodNames.__RFLOORDIV__;
|
60 | 63 | import static com.oracle.graal.python.nodes.SpecialMethodNames.__RMUL__;
|
| 64 | +import static com.oracle.graal.python.nodes.SpecialMethodNames.__ROR__; |
61 | 65 | import static com.oracle.graal.python.nodes.SpecialMethodNames.__RSUB__;
|
62 | 66 | import static com.oracle.graal.python.nodes.SpecialMethodNames.__RTRUEDIV__;
|
| 67 | +import static com.oracle.graal.python.nodes.SpecialMethodNames.__RXOR__; |
63 | 68 | import static com.oracle.graal.python.nodes.SpecialMethodNames.__SETATTR__;
|
64 | 69 | import static com.oracle.graal.python.nodes.SpecialMethodNames.__SETITEM__;
|
65 | 70 | import static com.oracle.graal.python.nodes.SpecialMethodNames.__STR__;
|
66 | 71 | import static com.oracle.graal.python.nodes.SpecialMethodNames.__SUB__;
|
67 | 72 | import static com.oracle.graal.python.nodes.SpecialMethodNames.__TRUEDIV__;
|
| 73 | +import static com.oracle.graal.python.nodes.SpecialMethodNames.__XOR__; |
68 | 74 |
|
69 | 75 | import java.util.Arrays;
|
70 | 76 | import java.util.List;
|
@@ -940,4 +946,65 @@ Object check(Object self, Object instance,
|
940 | 946 | }
|
941 | 947 | }
|
942 | 948 | }
|
| 949 | + |
| 950 | + @Builtin(name = __RAND__, minNumOfPositionalArgs = 2) |
| 951 | + @Builtin(name = __AND__, minNumOfPositionalArgs = 2) |
| 952 | + @GenerateNodeFactory |
| 953 | + abstract static class AndNode extends PythonBinaryBuiltinNode { |
| 954 | + @Specialization(limit = "3") |
| 955 | + protected static Object op(VirtualFrame frame, Object left, Object right, |
| 956 | + @Cached("create(__AND__, __RAND__)") LookupAndCallBinaryNode callAnd, |
| 957 | + @CachedLibrary("left") InteropLibrary lib) { |
| 958 | + if (lib.isNumber(left) && lib.fitsInLong(left)) { |
| 959 | + try { |
| 960 | + return callAnd.executeObject(frame, lib.asLong(left), right); |
| 961 | + } catch (UnsupportedMessageException e) { |
| 962 | + throw CompilerDirectives.shouldNotReachHere(); |
| 963 | + } |
| 964 | + } else { |
| 965 | + return PNotImplemented.NOT_IMPLEMENTED; |
| 966 | + } |
| 967 | + } |
| 968 | + } |
| 969 | + |
| 970 | + @Builtin(name = __ROR__, minNumOfPositionalArgs = 2) |
| 971 | + @Builtin(name = __OR__, minNumOfPositionalArgs = 2) |
| 972 | + @GenerateNodeFactory |
| 973 | + abstract static class OrNode extends PythonBinaryBuiltinNode { |
| 974 | + @Specialization(limit = "3") |
| 975 | + protected static Object op(VirtualFrame frame, Object left, Object right, |
| 976 | + @Cached("create(__OR__, __ROR__)") LookupAndCallBinaryNode callOr, |
| 977 | + @CachedLibrary("left") InteropLibrary lib) { |
| 978 | + if (lib.isNumber(left) && lib.fitsInLong(left)) { |
| 979 | + try { |
| 980 | + return callOr.executeObject(frame, lib.asLong(left), right); |
| 981 | + } catch (UnsupportedMessageException e) { |
| 982 | + throw CompilerDirectives.shouldNotReachHere(); |
| 983 | + } |
| 984 | + } else { |
| 985 | + return PNotImplemented.NOT_IMPLEMENTED; |
| 986 | + } |
| 987 | + } |
| 988 | + } |
| 989 | + |
| 990 | + @Builtin(name = __RXOR__, minNumOfPositionalArgs = 2) |
| 991 | + @Builtin(name = __XOR__, minNumOfPositionalArgs = 2) |
| 992 | + @GenerateNodeFactory |
| 993 | + abstract static class XorNode extends PythonBinaryBuiltinNode { |
| 994 | + @Specialization(limit = "3") |
| 995 | + protected static Object op(VirtualFrame frame, Object left, Object right, |
| 996 | + @Cached("create(__XOR__, __RXOR__)") LookupAndCallBinaryNode callXor, |
| 997 | + @CachedLibrary("left") InteropLibrary lib) { |
| 998 | + if (lib.isNumber(left) && lib.fitsInLong(left)) { |
| 999 | + try { |
| 1000 | + return callXor.executeObject(frame, lib.asLong(left), right); |
| 1001 | + } catch (UnsupportedMessageException e) { |
| 1002 | + throw CompilerDirectives.shouldNotReachHere(); |
| 1003 | + } |
| 1004 | + } else { |
| 1005 | + return PNotImplemented.NOT_IMPLEMENTED; |
| 1006 | + } |
| 1007 | + } |
| 1008 | + } |
| 1009 | + |
943 | 1010 | }
|
0 commit comments