41
41
package com .oracle .graal .python .builtins .objects .generator ;
42
42
43
43
import static com .oracle .graal .python .builtins .PythonBuiltinClassType .GeneratorExit ;
44
- import static com .oracle .graal .python .builtins .PythonBuiltinClassType .PAsyncGenerator ;
45
- import static com .oracle .graal .python .builtins .PythonBuiltinClassType .PCoroutine ;
46
44
import static com .oracle .graal .python .builtins .PythonBuiltinClassType .StopAsyncIteration ;
47
45
import static com .oracle .graal .python .runtime .exception .PythonErrorType .RuntimeError ;
48
46
import static com .oracle .graal .python .runtime .exception .PythonErrorType .StopIteration ;
@@ -144,9 +142,9 @@ protected List<? extends NodeFactory<? extends PythonBuiltinBaseNode>> getNodeFa
144
142
return CommonGeneratorBuiltinsFactory .getFactories ();
145
143
}
146
144
147
- private static void checkResumable (PythonBuiltinBaseNode node , PGenerator self , boolean isAsyncGen ) {
145
+ private static void checkResumable (PythonBuiltinBaseNode node , PGenerator self ) {
148
146
if (self .isFinished ()) {
149
- if (isAsyncGen ) {
147
+ if (self . isAsyncGen () ) {
150
148
throw node .raise (StopAsyncIteration );
151
149
}
152
150
if (self .isCoroutine ()) {
@@ -183,7 +181,7 @@ Object cached(VirtualFrame frame, PGenerator self, Object sendValue,
183
181
throw handleException (self , inliningTarget , errorProfile , raiseNode , e );
184
182
} catch (GeneratorReturnException e ) {
185
183
returnProfile .enter (inliningTarget );
186
- throw handleReturn (self , inliningTarget , e , raiseNode , profile );
184
+ throw handleReturn (self , e , raiseNode );
187
185
} finally {
188
186
self .setRunning (false );
189
187
}
@@ -216,7 +214,7 @@ Object generic(VirtualFrame frame, PGenerator self, Object sendValue,
216
214
throw handleException (self , inliningTarget , errorProfile , raiseNode , e );
217
215
} catch (GeneratorReturnException e ) {
218
216
returnProfile .enter (inliningTarget );
219
- throw handleReturn (self , inliningTarget , e , raiseNode , profile );
217
+ throw handleReturn (self , e , raiseNode );
220
218
} finally {
221
219
self .setRunning (false );
222
220
}
@@ -225,7 +223,7 @@ Object generic(VirtualFrame frame, PGenerator self, Object sendValue,
225
223
226
224
private PException handleException (PGenerator self , Node inliningTarget , IsBuiltinObjectProfile profile , PRaiseNode raiseNode , PException e ) {
227
225
self .markAsFinished ();
228
- if (profile . profileObject ( inliningTarget , self , PAsyncGenerator )) {
226
+ if (self . isAsyncGen ( )) {
229
227
// Async generators need to wrap StopAsyncIteration in a runtime error
230
228
if (profile .profileException (inliningTarget , e , StopAsyncIteration )) {
231
229
throw raiseNode .raise (RuntimeError , e .getEscapedException (), ErrorMessages .ASYNCGEN_RAISED_ASYNCSTOPITER );
@@ -242,9 +240,9 @@ private Object handleResult(PGenerator self, GeneratorYieldResult result) {
242
240
return result .yieldValue ;
243
241
}
244
242
245
- private static PException handleReturn (PGenerator self , Node inliningTarget , GeneratorReturnException e , PRaiseNode raiseNode , IsBuiltinObjectProfile profile ) {
243
+ private static PException handleReturn (PGenerator self , GeneratorReturnException e , PRaiseNode raiseNode ) {
246
244
self .markAsFinished ();
247
- if (profile . profileObject ( inliningTarget , self , PAsyncGenerator )) {
245
+ if (self . isAsyncGen ( )) {
248
246
throw raiseNode .raise (StopAsyncIteration );
249
247
}
250
248
if (e .value != PNone .NONE ) {
@@ -270,11 +268,10 @@ public abstract static class SendNode extends PythonBinaryBuiltinNode {
270
268
@ Specialization
271
269
Object send (VirtualFrame frame , PGenerator self , Object value ,
272
270
@ Bind ("this" ) Node inliningTarget ,
273
- @ Cached ResumeGeneratorNode resumeGeneratorNode ,
274
- @ Cached IsBuiltinObjectProfile isAsyncGen ) {
271
+ @ Cached ResumeGeneratorNode resumeGeneratorNode ) {
275
272
// even though this isn't a builtin for async generators, SendNode is used on async
276
273
// generators by PAsyncGenSend
277
- checkResumable (this , self , isAsyncGen . profileObject ( inliningTarget , self , PAsyncGenerator ) );
274
+ checkResumable (this , self );
278
275
if (!self .isStarted () && value != PNone .NONE ) {
279
276
throw raise (TypeError , ErrorMessages .SEND_NON_NONE_TO_UNSTARTED_GENERATOR );
280
277
}
@@ -422,7 +419,7 @@ Object sendThrow(VirtualFrame frame, PGenerator self, Object typ, Object val, PT
422
419
423
420
private Object doThrow (VirtualFrame frame , ResumeGeneratorNode resumeGeneratorNode , PGenerator self , PBaseException instance , PythonLanguage language ) {
424
421
instance .setContext (null ); // Will be filled when caught
425
- if (self .isFinished () && self .isCoroutine ()) {
422
+ if (self .isCoroutine () && self .isFinished ()) {
426
423
throw raise (PythonBuiltinClassType .RuntimeError , ErrorMessages .CANNOT_REUSE_CORO );
427
424
}
428
425
if (self .isStarted () && !self .isFinished ()) {
0 commit comments