@@ -1528,6 +1528,14 @@ impl Compiler<'_> {
1528
1528
. constants
1529
1529
. insert_full ( ConstantData :: None ) ;
1530
1530
1531
+ // Emit RESUME instruction at function start
1532
+ emit ! (
1533
+ self ,
1534
+ Instruction :: Resume {
1535
+ arg: bytecode:: ResumeType :: AtFuncStart as u32
1536
+ }
1537
+ ) ;
1538
+
1531
1539
self . compile_statements ( body) ?;
1532
1540
1533
1541
// Emit None at end:
@@ -1943,6 +1951,12 @@ impl Compiler<'_> {
1943
1951
emit ! ( self , Instruction :: GetAwaitable ) ;
1944
1952
self . emit_load_const ( ConstantData :: None ) ;
1945
1953
emit ! ( self , Instruction :: YieldFrom ) ;
1954
+ emit ! (
1955
+ self ,
1956
+ Instruction :: Resume {
1957
+ arg: bytecode:: ResumeType :: AfterAwait as u32
1958
+ }
1959
+ ) ;
1946
1960
emit ! ( self , Instruction :: SetupAsyncWith { end: final_block } ) ;
1947
1961
} else {
1948
1962
emit ! ( self , Instruction :: SetupWith { end: final_block } ) ;
@@ -1984,6 +1998,12 @@ impl Compiler<'_> {
1984
1998
emit ! ( self , Instruction :: GetAwaitable ) ;
1985
1999
self . emit_load_const ( ConstantData :: None ) ;
1986
2000
emit ! ( self , Instruction :: YieldFrom ) ;
2001
+ emit ! (
2002
+ self ,
2003
+ Instruction :: Resume {
2004
+ arg: bytecode:: ResumeType :: AfterAwait as u32
2005
+ }
2006
+ ) ;
1987
2007
}
1988
2008
1989
2009
emit ! ( self , Instruction :: WithCleanupFinish ) ;
@@ -2022,6 +2042,12 @@ impl Compiler<'_> {
2022
2042
emit ! ( self , Instruction :: GetANext ) ;
2023
2043
self . emit_load_const ( ConstantData :: None ) ;
2024
2044
emit ! ( self , Instruction :: YieldFrom ) ;
2045
+ emit ! (
2046
+ self ,
2047
+ Instruction :: Resume {
2048
+ arg: bytecode:: ResumeType :: AfterAwait as u32
2049
+ }
2050
+ ) ;
2025
2051
self . compile_store ( target) ?;
2026
2052
emit ! ( self , Instruction :: PopBlock ) ;
2027
2053
} else {
@@ -3493,6 +3519,12 @@ impl Compiler<'_> {
3493
3519
Option :: None => self . emit_load_const ( ConstantData :: None ) ,
3494
3520
} ;
3495
3521
emit ! ( self , Instruction :: YieldValue ) ;
3522
+ emit ! (
3523
+ self ,
3524
+ Instruction :: Resume {
3525
+ arg: bytecode:: ResumeType :: AfterYield as u32
3526
+ }
3527
+ ) ;
3496
3528
}
3497
3529
Expr :: Await ( ExprAwait { value, .. } ) => {
3498
3530
if self . ctx . func != FunctionContext :: AsyncFunction {
@@ -3502,6 +3534,12 @@ impl Compiler<'_> {
3502
3534
emit ! ( self , Instruction :: GetAwaitable ) ;
3503
3535
self . emit_load_const ( ConstantData :: None ) ;
3504
3536
emit ! ( self , Instruction :: YieldFrom ) ;
3537
+ emit ! (
3538
+ self ,
3539
+ Instruction :: Resume {
3540
+ arg: bytecode:: ResumeType :: AfterAwait as u32
3541
+ }
3542
+ ) ;
3505
3543
}
3506
3544
Expr :: YieldFrom ( ExprYieldFrom { value, .. } ) => {
3507
3545
match self . ctx . func {
@@ -3518,6 +3556,12 @@ impl Compiler<'_> {
3518
3556
emit ! ( self , Instruction :: GetIter ) ;
3519
3557
self . emit_load_const ( ConstantData :: None ) ;
3520
3558
emit ! ( self , Instruction :: YieldFrom ) ;
3559
+ emit ! (
3560
+ self ,
3561
+ Instruction :: Resume {
3562
+ arg: bytecode:: ResumeType :: AfterYieldFrom as u32
3563
+ }
3564
+ ) ;
3521
3565
}
3522
3566
Expr :: Name ( ExprName { id, .. } ) => self . load_name ( id. as_str ( ) ) ?,
3523
3567
Expr :: Lambda ( ExprLambda {
@@ -3644,6 +3688,12 @@ impl Compiler<'_> {
3644
3688
compiler. compile_comprehension_element ( elt) ?;
3645
3689
compiler. mark_generator ( ) ;
3646
3690
emit ! ( compiler, Instruction :: YieldValue ) ;
3691
+ emit ! (
3692
+ compiler,
3693
+ Instruction :: Resume {
3694
+ arg: bytecode:: ResumeType :: AfterYield as u32
3695
+ }
3696
+ ) ;
3647
3697
emit ! ( compiler, Instruction :: Pop ) ;
3648
3698
3649
3699
Ok ( ( ) )
@@ -4039,6 +4089,12 @@ impl Compiler<'_> {
4039
4089
emit ! ( self , Instruction :: GetANext ) ;
4040
4090
self . emit_load_const ( ConstantData :: None ) ;
4041
4091
emit ! ( self , Instruction :: YieldFrom ) ;
4092
+ emit ! (
4093
+ self ,
4094
+ Instruction :: Resume {
4095
+ arg: bytecode:: ResumeType :: AfterAwait as u32
4096
+ }
4097
+ ) ;
4042
4098
self . compile_store ( & generator. target ) ?;
4043
4099
emit ! ( self , Instruction :: PopBlock ) ;
4044
4100
} else {
@@ -4117,6 +4173,12 @@ impl Compiler<'_> {
4117
4173
emit ! ( self , Instruction :: GetAwaitable ) ;
4118
4174
self . emit_load_const ( ConstantData :: None ) ;
4119
4175
emit ! ( self , Instruction :: YieldFrom ) ;
4176
+ emit ! (
4177
+ self ,
4178
+ Instruction :: Resume {
4179
+ arg: bytecode:: ResumeType :: AfterAwait as u32
4180
+ }
4181
+ ) ;
4120
4182
}
4121
4183
4122
4184
Ok ( ( ) )
0 commit comments