|
49 | 49 | import com.oracle.graal.python.builtins.objects.bytes.PBytes;
|
50 | 50 | import com.oracle.graal.python.builtins.objects.type.PythonClass;
|
51 | 51 | import com.oracle.graal.python.nodes.SpecialMethodNames;
|
| 52 | +import com.oracle.graal.python.nodes.call.special.LookupAndCallBinaryNode; |
| 53 | +import com.oracle.graal.python.nodes.call.special.LookupAndCallTernaryNode; |
52 | 54 | import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
|
53 | 55 | import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
|
54 | 56 | import com.oracle.graal.python.nodes.function.builtins.PythonBinaryBuiltinNode;
|
|
60 | 62 | import com.oracle.graal.python.runtime.exception.PythonErrorType;
|
61 | 63 | import com.oracle.truffle.api.CompilerDirectives;
|
62 | 64 | import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
|
| 65 | +import com.oracle.truffle.api.dsl.Cached; |
63 | 66 | import com.oracle.truffle.api.dsl.Fallback;
|
64 | 67 | import com.oracle.truffle.api.dsl.GenerateNodeFactory;
|
65 | 68 | import com.oracle.truffle.api.dsl.NodeFactory;
|
@@ -607,6 +610,10 @@ abstract static class RMulNode extends MulNode {
|
607 | 610 | @TypeSystemReference(PythonArithmeticTypes.class)
|
608 | 611 | abstract static class PowNode extends PythonTernaryBuiltinNode {
|
609 | 612 |
|
| 613 | + protected static PowNode create() { |
| 614 | + return null; |
| 615 | + } |
| 616 | + |
610 | 617 | @Specialization(guards = "right >= 0", rewriteOn = ArithmeticException.class)
|
611 | 618 | int doIntegerFast(int left, int right, @SuppressWarnings("unused") PNone none) {
|
612 | 619 | int result = 1;
|
@@ -688,6 +695,28 @@ PInt doPInt(PInt left, PInt right, @SuppressWarnings("unused") PNone none) {
|
688 | 695 | return factory().createInt((long) value);
|
689 | 696 | }
|
690 | 697 |
|
| 698 | + @Specialization |
| 699 | + Object modulo(Object x, Object y, long z, |
| 700 | + @Cached("create(__POW__)") LookupAndCallTernaryNode powNode, |
| 701 | + @Cached("create(__MOD__)") LookupAndCallBinaryNode modNode) { |
| 702 | + Object result = powNode.execute(x, y, PNone.NO_VALUE); |
| 703 | + if (result == PNotImplemented.NOT_IMPLEMENTED) { |
| 704 | + return result; |
| 705 | + } |
| 706 | + return modNode.executeObject(result, z); |
| 707 | + } |
| 708 | + |
| 709 | + @Specialization |
| 710 | + Object modulo(Object x, Object y, PInt z, |
| 711 | + @Cached("create(__POW__)") LookupAndCallTernaryNode powNode, |
| 712 | + @Cached("create(__MOD__)") LookupAndCallBinaryNode modNode) { |
| 713 | + Object result = powNode.execute(x, y, PNone.NO_VALUE); |
| 714 | + if (result == PNotImplemented.NOT_IMPLEMENTED) { |
| 715 | + return result; |
| 716 | + } |
| 717 | + return modNode.executeObject(result, z); |
| 718 | + } |
| 719 | + |
691 | 720 | @Fallback
|
692 | 721 | @SuppressWarnings("unused")
|
693 | 722 | Object doFallback(Object x, Object y, Object z) {
|
|
0 commit comments