32
32
import com .oracle .graal .python .builtins .objects .function .PArguments ;
33
33
import com .oracle .graal .python .builtins .objects .iterator .PRangeIterator ;
34
34
import com .oracle .graal .python .builtins .objects .object .PythonBuiltinObject ;
35
+ import com .oracle .graal .python .nodes .generator .AbstractYieldNode ;
35
36
import com .oracle .graal .python .parser .ExecutionCellSlots ;
36
37
import com .oracle .graal .python .parser .GeneratorInfo ;
37
38
import com .oracle .graal .python .runtime .object .PythonObjectFactory ;
@@ -66,6 +67,7 @@ public final class PGenerator extends PythonBuiltinObject {
66
67
private int currentCallTarget ;
67
68
private final Object iterator ;
68
69
private final boolean isPRangeIterator ;
70
+ private final GeneratorInfo generatorInfo ;
69
71
// running means it is currently on the stack, not just started
70
72
private boolean running ;
71
73
@@ -97,7 +99,7 @@ public static PGenerator create(String name, String qualname, RootCallTarget[] c
97
99
}
98
100
assignCells (generatorFrame , cellVarSlots , cellVarAssumptions );
99
101
PArguments .setGeneratorFrameLocals (generatorFrameArguments , factory .createDictLocals (generatorFrame ));
100
- return new PGenerator (name , qualname , callTargets , frameDescriptor , arguments , closure , iterator );
102
+ return new PGenerator (name , qualname , callTargets , generatorInfo , frameDescriptor , arguments , closure , iterator );
101
103
}
102
104
103
105
@ ExplodeLoop
@@ -116,11 +118,12 @@ private static void assignClosure(PCell[] closure, MaterializedFrame generatorFr
116
118
}
117
119
}
118
120
119
- private PGenerator (String name , String qualname , RootCallTarget [] callTargets , FrameDescriptor frameDescriptor , Object [] arguments , PCell [] closure , Object iterator ) {
121
+ private PGenerator (String name , String qualname , RootCallTarget [] callTargets , GeneratorInfo generatorInfo , FrameDescriptor frameDescriptor , Object [] arguments , PCell [] closure , Object iterator ) {
120
122
super (PythonBuiltinClassType .PGenerator , PythonBuiltinClassType .PGenerator .newInstance ());
121
123
this .name = name ;
122
124
this .qualname = qualname ;
123
125
this .callTargets = callTargets ;
126
+ this .generatorInfo = generatorInfo ;
124
127
this .currentCallTarget = 0 ;
125
128
this .frameDescriptor = frameDescriptor ;
126
129
this .arguments = arguments ;
@@ -147,6 +150,15 @@ public RootCallTarget getCurrentCallTarget() {
147
150
return callTargets [currentCallTarget ];
148
151
}
149
152
153
+ public AbstractYieldNode getCurrentYieldNode () {
154
+ if (currentCallTarget == 0 || running || finished ) {
155
+ // Not stopped on a yield
156
+ return null ;
157
+ }
158
+ // Call target indices are yield indices + 1, see AbstractYieldNode
159
+ return generatorInfo .getYieldNodes ()[currentCallTarget - 1 ];
160
+ }
161
+
150
162
public boolean isStarted () {
151
163
return currentCallTarget != 0 && !running ;
152
164
}
0 commit comments