@@ -1376,9 +1376,8 @@ impl Compiler {
1376
1376
// The thing iterated:
1377
1377
self . compile_expression ( iter) ?;
1378
1378
1379
- if is_async {
1379
+ let check_asynciter_block = if is_async {
1380
1380
let check_asynciter_block = self . new_block ( ) ;
1381
- let body_block = self . new_block ( ) ;
1382
1381
1383
1382
self . emit ( Instruction :: GetAIter ) ;
1384
1383
@@ -1391,21 +1390,8 @@ impl Compiler {
1391
1390
self . emit ( Instruction :: YieldFrom ) ;
1392
1391
self . compile_store ( target) ?;
1393
1392
self . emit ( Instruction :: PopBlock ) ;
1394
- self . emit ( Instruction :: Jump { target : body_block } ) ;
1395
1393
1396
- self . switch_to_block ( check_asynciter_block) ;
1397
- self . emit ( Instruction :: Duplicate ) ;
1398
- let stopasynciter = self . name ( "StopAsyncIteration" ) ;
1399
- self . emit ( Instruction :: LoadGlobal ( stopasynciter) ) ;
1400
- self . emit ( Instruction :: CompareOperation {
1401
- op : bytecode:: ComparisonOperator :: ExceptionMatch ,
1402
- } ) ;
1403
- self . emit ( Instruction :: JumpIfTrue { target : else_block } ) ;
1404
- self . emit ( Instruction :: Raise {
1405
- kind : bytecode:: RaiseKind :: Reraise ,
1406
- } ) ;
1407
-
1408
- self . switch_to_block ( body_block) ;
1394
+ Some ( check_asynciter_block)
1409
1395
} else {
1410
1396
// Retrieve Iterator
1411
1397
self . emit ( Instruction :: GetIter ) ;
@@ -1415,24 +1401,27 @@ impl Compiler {
1415
1401
1416
1402
// Start of loop iteration, set targets:
1417
1403
self . compile_store ( target) ?;
1418
- }
1404
+ None
1405
+ } ;
1419
1406
1420
1407
let was_in_loop = self . ctx . loop_data ;
1421
1408
self . ctx . loop_data = Some ( ( for_block, after_block) ) ;
1422
1409
self . compile_statements ( body) ?;
1423
1410
self . ctx . loop_data = was_in_loop;
1424
1411
self . emit ( Instruction :: Jump { target : for_block } ) ;
1425
1412
1413
+ if let Some ( check_asynciter_block) = check_asynciter_block {
1414
+ self . switch_to_block ( check_asynciter_block) ;
1415
+ self . emit ( Instruction :: EndAsyncFor ) ;
1416
+ }
1417
+
1426
1418
self . switch_to_block ( else_block) ;
1427
1419
self . emit ( Instruction :: PopBlock ) ;
1428
1420
if let Some ( orelse) = orelse {
1429
1421
self . compile_statements ( orelse) ?;
1430
1422
}
1431
1423
1432
1424
self . switch_to_block ( after_block) ;
1433
- if is_async {
1434
- self . emit ( Instruction :: Pop ) ;
1435
- }
1436
1425
1437
1426
Ok ( ( ) )
1438
1427
}
@@ -2169,14 +2158,13 @@ impl Compiler {
2169
2158
) ;
2170
2159
let arg0 = self . varname ( ".0" ) ;
2171
2160
2161
+ // if this is a generator expression, we need to insert a LoadConst(None) before we return;
2162
+ // the other kinds load their collection types below
2172
2163
let is_genexpr = matches ! ( kind, ast:: ComprehensionKind :: GeneratorExpression { .. } ) ;
2173
2164
2174
2165
// Create empty object of proper type:
2175
2166
match kind {
2176
- ast:: ComprehensionKind :: GeneratorExpression { .. } => {
2177
- // pop the None that was passed to kickstart the generator
2178
- self . emit ( Instruction :: Pop ) ;
2179
- }
2167
+ ast:: ComprehensionKind :: GeneratorExpression { .. } => { }
2180
2168
ast:: ComprehensionKind :: List { .. } => {
2181
2169
self . emit ( Instruction :: BuildList {
2182
2170
size : 0 ,
0 commit comments