@@ -64,6 +64,7 @@ public class PGenerator extends PythonBuiltinObject {
64
64
// running means it is currently on the stack, not just started
65
65
private boolean running ;
66
66
private final boolean isCoroutine ;
67
+ private final boolean isAsyncGen ;
67
68
68
69
// An explicit isIterableCoroutine argument is needed for iterable coroutines (generally created
69
70
// via types.coroutine)
@@ -91,9 +92,10 @@ protected PGenerator(PythonLanguage lang, TruffleString name, TruffleString qual
91
92
this .bytecodeRootNode = rootNode ;
92
93
this .frameInfo = (FrameInfo ) rootNode .getFrameDescriptor ().getInfo ();
93
94
this .isCoroutine = isIterableCoroutine || cls == PythonBuiltinClassType .PCoroutine ;
95
+ this .isAsyncGen = cls == PythonBuiltinClassType .PAsyncGenerator ;
94
96
}
95
97
96
- public void handleResult (PythonLanguage language , GeneratorYieldResult result ) {
98
+ public final void handleResult (PythonLanguage language , GeneratorYieldResult result ) {
97
99
currentCallTarget = result .resumeBci ;
98
100
if (callTargets [currentCallTarget ] == null ) {
99
101
CompilerDirectives .transferToInterpreterAndInvalidate ();
@@ -107,11 +109,11 @@ public void handleResult(PythonLanguage language, GeneratorYieldResult result) {
107
109
* a generator call target returns through a yield, the generator should be updated with the
108
110
* next yield index to use via {@link #handleResult}
109
111
*/
110
- public RootCallTarget getCurrentCallTarget () {
112
+ public final RootCallTarget getCurrentCallTarget () {
111
113
return callTargets [currentCallTarget ];
112
114
}
113
115
114
- public Object getYieldFrom () {
116
+ public final Object getYieldFrom () {
115
117
if (running || finished ) {
116
118
return null ;
117
119
}
@@ -122,11 +124,11 @@ private PBytecodeGeneratorRootNode getCurrentRootNode() {
122
124
return (PBytecodeGeneratorRootNode ) getCurrentCallTarget ().getRootNode ();
123
125
}
124
126
125
- public boolean isStarted () {
127
+ public final boolean isStarted () {
126
128
return currentCallTarget != 0 && !running ;
127
129
}
128
130
129
- public int getBci () {
131
+ public final int getBci () {
130
132
if (!isStarted ()) {
131
133
return -1 ;
132
134
} else if (finished ) {
@@ -136,24 +138,24 @@ public int getBci() {
136
138
}
137
139
}
138
140
139
- public Object [] getArguments () {
141
+ public final Object [] getArguments () {
140
142
return arguments ;
141
143
}
142
144
143
- public boolean isFinished () {
145
+ public final boolean isFinished () {
144
146
return finished ;
145
147
}
146
148
147
- public void markAsFinished () {
149
+ public final void markAsFinished () {
148
150
finished = true ;
149
151
}
150
152
151
153
@ Override
152
- public String toString () {
154
+ public final String toString () {
153
155
return "<generator object " + name + " at " + hashCode () + ">" ;
154
156
}
155
157
156
- public PCode getOrCreateCode (Node inliningTarget , InlinedConditionProfile hasCodeProfile , PythonObjectFactory factory ) {
158
+ public final PCode getOrCreateCode (Node inliningTarget , InlinedConditionProfile hasCodeProfile , PythonObjectFactory factory ) {
157
159
if (hasCodeProfile .profile (inliningTarget , code == null )) {
158
160
RootCallTarget callTarget ;
159
161
callTarget = bytecodeRootNode .getCallTarget ();
@@ -162,32 +164,36 @@ public PCode getOrCreateCode(Node inliningTarget, InlinedConditionProfile hasCod
162
164
return code ;
163
165
}
164
166
165
- public boolean isRunning () {
167
+ public final boolean isRunning () {
166
168
return running ;
167
169
}
168
170
169
- public void setRunning (boolean running ) {
171
+ public final void setRunning (boolean running ) {
170
172
assert !running || !this .running : "Attempted to set an already running generator as running" ;
171
173
this .running = running ;
172
174
}
173
175
174
- public TruffleString getName () {
176
+ public final TruffleString getName () {
175
177
return name ;
176
178
}
177
179
178
- public void setName (TruffleString name ) {
180
+ public final void setName (TruffleString name ) {
179
181
this .name = name ;
180
182
}
181
183
182
- public TruffleString getQualname () {
184
+ public final TruffleString getQualname () {
183
185
return qualname ;
184
186
}
185
187
186
- public void setQualname (TruffleString qualname ) {
188
+ public final void setQualname (TruffleString qualname ) {
187
189
this .qualname = qualname ;
188
190
}
189
191
190
- public boolean isCoroutine () {
192
+ public final boolean isCoroutine () {
191
193
return isCoroutine ;
192
194
}
195
+
196
+ public final boolean isAsyncGen () {
197
+ return isAsyncGen ;
198
+ }
193
199
}
0 commit comments