@@ -1561,6 +1561,14 @@ impl Compiler<'_> {
15611561 . constants
15621562 . insert_full ( ConstantData :: None ) ;
15631563
1564+ // Emit RESUME instruction at function start
1565+ emit ! (
1566+ self ,
1567+ Instruction :: Resume {
1568+ arg: bytecode:: ResumeType :: AtFuncStart as u32
1569+ }
1570+ ) ;
1571+
15641572 self . compile_statements ( body) ?;
15651573
15661574 // Emit None at end:
@@ -1976,6 +1984,12 @@ impl Compiler<'_> {
19761984 emit ! ( self , Instruction :: GetAwaitable ) ;
19771985 self . emit_load_const ( ConstantData :: None ) ;
19781986 emit ! ( self , Instruction :: YieldFrom ) ;
1987+ emit ! (
1988+ self ,
1989+ Instruction :: Resume {
1990+ arg: bytecode:: ResumeType :: AfterAwait as u32
1991+ }
1992+ ) ;
19791993 emit ! ( self , Instruction :: SetupAsyncWith { end: final_block } ) ;
19801994 } else {
19811995 emit ! ( self , Instruction :: SetupWith { end: final_block } ) ;
@@ -2017,6 +2031,12 @@ impl Compiler<'_> {
20172031 emit ! ( self , Instruction :: GetAwaitable ) ;
20182032 self . emit_load_const ( ConstantData :: None ) ;
20192033 emit ! ( self , Instruction :: YieldFrom ) ;
2034+ emit ! (
2035+ self ,
2036+ Instruction :: Resume {
2037+ arg: bytecode:: ResumeType :: AfterAwait as u32
2038+ }
2039+ ) ;
20202040 }
20212041
20222042 emit ! ( self , Instruction :: WithCleanupFinish ) ;
@@ -2055,6 +2075,12 @@ impl Compiler<'_> {
20552075 emit ! ( self , Instruction :: GetANext ) ;
20562076 self . emit_load_const ( ConstantData :: None ) ;
20572077 emit ! ( self , Instruction :: YieldFrom ) ;
2078+ emit ! (
2079+ self ,
2080+ Instruction :: Resume {
2081+ arg: bytecode:: ResumeType :: AfterAwait as u32
2082+ }
2083+ ) ;
20582084 self . compile_store ( target) ?;
20592085 emit ! ( self , Instruction :: PopBlock ) ;
20602086 } else {
@@ -3526,6 +3552,12 @@ impl Compiler<'_> {
35263552 Option :: None => self . emit_load_const ( ConstantData :: None ) ,
35273553 } ;
35283554 emit ! ( self , Instruction :: YieldValue ) ;
3555+ emit ! (
3556+ self ,
3557+ Instruction :: Resume {
3558+ arg: bytecode:: ResumeType :: AfterYield as u32
3559+ }
3560+ ) ;
35293561 }
35303562 Expr :: Await ( ExprAwait { value, .. } ) => {
35313563 if self . ctx . func != FunctionContext :: AsyncFunction {
@@ -3535,6 +3567,12 @@ impl Compiler<'_> {
35353567 emit ! ( self , Instruction :: GetAwaitable ) ;
35363568 self . emit_load_const ( ConstantData :: None ) ;
35373569 emit ! ( self , Instruction :: YieldFrom ) ;
3570+ emit ! (
3571+ self ,
3572+ Instruction :: Resume {
3573+ arg: bytecode:: ResumeType :: AfterAwait as u32
3574+ }
3575+ ) ;
35383576 }
35393577 Expr :: YieldFrom ( ExprYieldFrom { value, .. } ) => {
35403578 match self . ctx . func {
@@ -3551,6 +3589,12 @@ impl Compiler<'_> {
35513589 emit ! ( self , Instruction :: GetIter ) ;
35523590 self . emit_load_const ( ConstantData :: None ) ;
35533591 emit ! ( self , Instruction :: YieldFrom ) ;
3592+ emit ! (
3593+ self ,
3594+ Instruction :: Resume {
3595+ arg: bytecode:: ResumeType :: AfterYieldFrom as u32
3596+ }
3597+ ) ;
35543598 }
35553599 Expr :: Name ( ExprName { id, .. } ) => self . load_name ( id. as_str ( ) ) ?,
35563600 Expr :: Lambda ( ExprLambda {
@@ -3677,6 +3721,12 @@ impl Compiler<'_> {
36773721 compiler. compile_comprehension_element ( elt) ?;
36783722 compiler. mark_generator ( ) ;
36793723 emit ! ( compiler, Instruction :: YieldValue ) ;
3724+ emit ! (
3725+ compiler,
3726+ Instruction :: Resume {
3727+ arg: bytecode:: ResumeType :: AfterYield as u32
3728+ }
3729+ ) ;
36803730 emit ! ( compiler, Instruction :: Pop ) ;
36813731
36823732 Ok ( ( ) )
@@ -4072,6 +4122,12 @@ impl Compiler<'_> {
40724122 emit ! ( self , Instruction :: GetANext ) ;
40734123 self . emit_load_const ( ConstantData :: None ) ;
40744124 emit ! ( self , Instruction :: YieldFrom ) ;
4125+ emit ! (
4126+ self ,
4127+ Instruction :: Resume {
4128+ arg: bytecode:: ResumeType :: AfterAwait as u32
4129+ }
4130+ ) ;
40754131 self . compile_store ( & generator. target ) ?;
40764132 emit ! ( self , Instruction :: PopBlock ) ;
40774133 } else {
@@ -4150,6 +4206,12 @@ impl Compiler<'_> {
41504206 emit ! ( self , Instruction :: GetAwaitable ) ;
41514207 self . emit_load_const ( ConstantData :: None ) ;
41524208 emit ! ( self , Instruction :: YieldFrom ) ;
4209+ emit ! (
4210+ self ,
4211+ Instruction :: Resume {
4212+ arg: bytecode:: ResumeType :: AfterAwait as u32
4213+ }
4214+ ) ;
41534215 }
41544216
41554217 Ok ( ( ) )
0 commit comments