Skip to content

Commit 5c838b2

Browse files
committed
support int.__pow__ with 3 arguments
1 parent 093c598 commit 5c838b2

File tree

1 file changed

+29
-0
lines changed
  • graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ints

1 file changed

+29
-0
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ints/IntBuiltins.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@
4949
import com.oracle.graal.python.builtins.objects.bytes.PBytes;
5050
import com.oracle.graal.python.builtins.objects.type.PythonClass;
5151
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;
5254
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
5355
import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
5456
import com.oracle.graal.python.nodes.function.builtins.PythonBinaryBuiltinNode;
@@ -60,6 +62,7 @@
6062
import com.oracle.graal.python.runtime.exception.PythonErrorType;
6163
import com.oracle.truffle.api.CompilerDirectives;
6264
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
65+
import com.oracle.truffle.api.dsl.Cached;
6366
import com.oracle.truffle.api.dsl.Fallback;
6467
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
6568
import com.oracle.truffle.api.dsl.NodeFactory;
@@ -607,6 +610,10 @@ abstract static class RMulNode extends MulNode {
607610
@TypeSystemReference(PythonArithmeticTypes.class)
608611
abstract static class PowNode extends PythonTernaryBuiltinNode {
609612

613+
protected static PowNode create() {
614+
return null;
615+
}
616+
610617
@Specialization(guards = "right >= 0", rewriteOn = ArithmeticException.class)
611618
int doIntegerFast(int left, int right, @SuppressWarnings("unused") PNone none) {
612619
int result = 1;
@@ -688,6 +695,28 @@ PInt doPInt(PInt left, PInt right, @SuppressWarnings("unused") PNone none) {
688695
return factory().createInt((long) value);
689696
}
690697

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+
691720
@Fallback
692721
@SuppressWarnings("unused")
693722
Object doFallback(Object x, Object y, Object z) {

0 commit comments

Comments
 (0)