Skip to content

Commit 68122bd

Browse files
committed
use proper call in GeneratorBuitins.NextNode
1 parent 8917713 commit 68122bd

File tree

1 file changed

+36
-3
lines changed
  • graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/generator

1 file changed

+36
-3
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/generator/GeneratorBuiltins.java

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,15 @@
4747
import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
4848
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
4949
import com.oracle.graal.python.runtime.exception.PException;
50+
import com.oracle.truffle.api.CallTarget;
51+
import com.oracle.truffle.api.RootCallTarget;
52+
import com.oracle.truffle.api.Truffle;
5053
import com.oracle.truffle.api.dsl.Cached;
5154
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
5255
import com.oracle.truffle.api.dsl.NodeFactory;
5356
import com.oracle.truffle.api.dsl.Specialization;
57+
import com.oracle.truffle.api.nodes.DirectCallNode;
58+
import com.oracle.truffle.api.nodes.IndirectCallNode;
5459
import com.oracle.truffle.api.profiles.ConditionProfile;
5560

5661
@CoreFunctions(extendClasses = PGenerator.class)
@@ -85,13 +90,41 @@ public abstract static class NextNode extends PythonUnaryBuiltinNode {
8590

8691
private final ConditionProfile errorProfile = ConditionProfile.createBinaryProfile();
8792

88-
@Specialization
89-
public Object next(PGenerator self) {
93+
protected static DirectCallNode createDirectCall(CallTarget target) {
94+
return Truffle.getRuntime().createDirectCallNode(target);
95+
}
96+
97+
protected static IndirectCallNode createIndirectCall() {
98+
return Truffle.getRuntime().createIndirectCallNode();
99+
}
100+
101+
protected static boolean sameCallTarget(RootCallTarget target1, CallTarget target2) {
102+
return target1 == target2;
103+
}
104+
105+
@Specialization(guards = "sameCallTarget(self.getCallTarget(), call.getCallTarget())", limit = "getCallSiteInlineCacheMaxDepth()")
106+
public Object nextCached(PGenerator self,
107+
@Cached("createDirectCall(self.getCallTarget())") DirectCallNode call) {
108+
if (self.isFinished()) {
109+
throw raise(StopIteration);
110+
}
111+
try {
112+
return call.call(self.getArguments());
113+
} catch (PException e) {
114+
e.expectStopIteration(getCore(), errorProfile);
115+
self.markAsFinished();
116+
throw raise(StopIteration);
117+
}
118+
}
119+
120+
@Specialization(replaces = "nextCached")
121+
public Object next(PGenerator self,
122+
@Cached("createIndirectCall()") IndirectCallNode call) {
90123
if (self.isFinished()) {
91124
throw raise(StopIteration);
92125
}
93126
try {
94-
return self.getCallTarget().call(self.getArguments());
127+
return call.call(self.getCallTarget(), self.getArguments());
95128
} catch (PException e) {
96129
e.expectStopIteration(getCore(), errorProfile);
97130
self.markAsFinished();

0 commit comments

Comments
 (0)