@@ -1528,6 +1528,14 @@ impl Compiler<'_> {
15281528 . constants
15291529 . insert_full ( ConstantData :: None ) ;
15301530
1531+ // Emit RESUME instruction at function start
1532+ emit ! (
1533+ self ,
1534+ Instruction :: Resume {
1535+ arg: bytecode:: ResumeType :: AtFuncStart as u32
1536+ }
1537+ ) ;
1538+
15311539 self . compile_statements ( body) ?;
15321540
15331541 // Emit None at end:
@@ -1943,6 +1951,12 @@ impl Compiler<'_> {
19431951 emit ! ( self , Instruction :: GetAwaitable ) ;
19441952 self . emit_load_const ( ConstantData :: None ) ;
19451953 emit ! ( self , Instruction :: YieldFrom ) ;
1954+ emit ! (
1955+ self ,
1956+ Instruction :: Resume {
1957+ arg: bytecode:: ResumeType :: AfterAwait as u32
1958+ }
1959+ ) ;
19461960 emit ! ( self , Instruction :: SetupAsyncWith { end: final_block } ) ;
19471961 } else {
19481962 emit ! ( self , Instruction :: SetupWith { end: final_block } ) ;
@@ -1984,6 +1998,12 @@ impl Compiler<'_> {
19841998 emit ! ( self , Instruction :: GetAwaitable ) ;
19851999 self . emit_load_const ( ConstantData :: None ) ;
19862000 emit ! ( self , Instruction :: YieldFrom ) ;
2001+ emit ! (
2002+ self ,
2003+ Instruction :: Resume {
2004+ arg: bytecode:: ResumeType :: AfterAwait as u32
2005+ }
2006+ ) ;
19872007 }
19882008
19892009 emit ! ( self , Instruction :: WithCleanupFinish ) ;
@@ -2022,6 +2042,12 @@ impl Compiler<'_> {
20222042 emit ! ( self , Instruction :: GetANext ) ;
20232043 self . emit_load_const ( ConstantData :: None ) ;
20242044 emit ! ( self , Instruction :: YieldFrom ) ;
2045+ emit ! (
2046+ self ,
2047+ Instruction :: Resume {
2048+ arg: bytecode:: ResumeType :: AfterAwait as u32
2049+ }
2050+ ) ;
20252051 self . compile_store ( target) ?;
20262052 emit ! ( self , Instruction :: PopBlock ) ;
20272053 } else {
@@ -3493,6 +3519,12 @@ impl Compiler<'_> {
34933519 Option :: None => self . emit_load_const ( ConstantData :: None ) ,
34943520 } ;
34953521 emit ! ( self , Instruction :: YieldValue ) ;
3522+ emit ! (
3523+ self ,
3524+ Instruction :: Resume {
3525+ arg: bytecode:: ResumeType :: AfterYield as u32
3526+ }
3527+ ) ;
34963528 }
34973529 Expr :: Await ( ExprAwait { value, .. } ) => {
34983530 if self . ctx . func != FunctionContext :: AsyncFunction {
@@ -3502,6 +3534,12 @@ impl Compiler<'_> {
35023534 emit ! ( self , Instruction :: GetAwaitable ) ;
35033535 self . emit_load_const ( ConstantData :: None ) ;
35043536 emit ! ( self , Instruction :: YieldFrom ) ;
3537+ emit ! (
3538+ self ,
3539+ Instruction :: Resume {
3540+ arg: bytecode:: ResumeType :: AfterAwait as u32
3541+ }
3542+ ) ;
35053543 }
35063544 Expr :: YieldFrom ( ExprYieldFrom { value, .. } ) => {
35073545 match self . ctx . func {
@@ -3518,6 +3556,12 @@ impl Compiler<'_> {
35183556 emit ! ( self , Instruction :: GetIter ) ;
35193557 self . emit_load_const ( ConstantData :: None ) ;
35203558 emit ! ( self , Instruction :: YieldFrom ) ;
3559+ emit ! (
3560+ self ,
3561+ Instruction :: Resume {
3562+ arg: bytecode:: ResumeType :: AfterYieldFrom as u32
3563+ }
3564+ ) ;
35213565 }
35223566 Expr :: Name ( ExprName { id, .. } ) => self . load_name ( id. as_str ( ) ) ?,
35233567 Expr :: Lambda ( ExprLambda {
@@ -3644,6 +3688,12 @@ impl Compiler<'_> {
36443688 compiler. compile_comprehension_element ( elt) ?;
36453689 compiler. mark_generator ( ) ;
36463690 emit ! ( compiler, Instruction :: YieldValue ) ;
3691+ emit ! (
3692+ compiler,
3693+ Instruction :: Resume {
3694+ arg: bytecode:: ResumeType :: AfterYield as u32
3695+ }
3696+ ) ;
36473697 emit ! ( compiler, Instruction :: Pop ) ;
36483698
36493699 Ok ( ( ) )
@@ -4039,6 +4089,12 @@ impl Compiler<'_> {
40394089 emit ! ( self , Instruction :: GetANext ) ;
40404090 self . emit_load_const ( ConstantData :: None ) ;
40414091 emit ! ( self , Instruction :: YieldFrom ) ;
4092+ emit ! (
4093+ self ,
4094+ Instruction :: Resume {
4095+ arg: bytecode:: ResumeType :: AfterAwait as u32
4096+ }
4097+ ) ;
40424098 self . compile_store ( & generator. target ) ?;
40434099 emit ! ( self , Instruction :: PopBlock ) ;
40444100 } else {
@@ -4117,6 +4173,12 @@ impl Compiler<'_> {
41174173 emit ! ( self , Instruction :: GetAwaitable ) ;
41184174 self . emit_load_const ( ConstantData :: None ) ;
41194175 emit ! ( self , Instruction :: YieldFrom ) ;
4176+ emit ! (
4177+ self ,
4178+ Instruction :: Resume {
4179+ arg: bytecode:: ResumeType :: AfterAwait as u32
4180+ }
4181+ ) ;
41204182 }
41214183
41224184 Ok ( ( ) )
0 commit comments