|
47 | 47 | import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
|
48 | 48 | import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
|
49 | 49 | 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; |
50 | 53 | import com.oracle.truffle.api.dsl.Cached;
|
51 | 54 | import com.oracle.truffle.api.dsl.GenerateNodeFactory;
|
52 | 55 | import com.oracle.truffle.api.dsl.NodeFactory;
|
53 | 56 | import com.oracle.truffle.api.dsl.Specialization;
|
| 57 | +import com.oracle.truffle.api.nodes.DirectCallNode; |
| 58 | +import com.oracle.truffle.api.nodes.IndirectCallNode; |
54 | 59 | import com.oracle.truffle.api.profiles.ConditionProfile;
|
55 | 60 |
|
56 | 61 | @CoreFunctions(extendClasses = PGenerator.class)
|
@@ -85,13 +90,41 @@ public abstract static class NextNode extends PythonUnaryBuiltinNode {
|
85 | 90 |
|
86 | 91 | private final ConditionProfile errorProfile = ConditionProfile.createBinaryProfile();
|
87 | 92 |
|
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) { |
90 | 123 | if (self.isFinished()) {
|
91 | 124 | throw raise(StopIteration);
|
92 | 125 | }
|
93 | 126 | try {
|
94 |
| - return self.getCallTarget().call(self.getArguments()); |
| 127 | + return call.call(self.getCallTarget(), self.getArguments()); |
95 | 128 | } catch (PException e) {
|
96 | 129 | e.expectStopIteration(getCore(), errorProfile);
|
97 | 130 | self.markAsFinished();
|
|
0 commit comments