@@ -1262,6 +1262,15 @@ compiler_pop_fblock(struct compiler *c, enum fblocktype t, jump_target_label blo
1262
1262
assert (SAME_LABEL (u -> u_fblock [u -> u_nfblocks ].fb_block , block_label ));
1263
1263
}
1264
1264
1265
+ static struct fblockinfo *
1266
+ compiler_top_fblock (struct compiler * c )
1267
+ {
1268
+ if (c -> u -> u_nfblocks == 0 ) {
1269
+ return NULL ;
1270
+ }
1271
+ return & c -> u -> u_fblock [c -> u -> u_nfblocks - 1 ];
1272
+ }
1273
+
1265
1274
static int
1266
1275
codegen_call_exit_with_nones (struct compiler * c , location loc )
1267
1276
{
@@ -1319,8 +1328,8 @@ codegen_pop_except_and_reraise(struct compiler *c, location loc)
1319
1328
* be popped.
1320
1329
*/
1321
1330
static int
1322
- compiler_unwind_fblock (struct compiler * c , location * ploc ,
1323
- struct fblockinfo * info , int preserve_tos )
1331
+ codegen_unwind_fblock (struct compiler * c , location * ploc ,
1332
+ struct fblockinfo * info , int preserve_tos )
1324
1333
{
1325
1334
switch (info -> fb_type ) {
1326
1335
case WHILE_LOOP :
@@ -1422,13 +1431,13 @@ compiler_unwind_fblock(struct compiler *c, location *ploc,
1422
1431
1423
1432
/** Unwind block stack. If loop is not NULL, then stop when the first loop is encountered. */
1424
1433
static int
1425
- compiler_unwind_fblock_stack (struct compiler * c , location * ploc ,
1426
- int preserve_tos , struct fblockinfo * * loop )
1434
+ codegen_unwind_fblock_stack (struct compiler * c , location * ploc ,
1435
+ int preserve_tos , struct fblockinfo * * loop )
1427
1436
{
1428
- if (c -> u -> u_nfblocks == 0 ) {
1437
+ struct fblockinfo * top = compiler_top_fblock (c );
1438
+ if (top == NULL ) {
1429
1439
return SUCCESS ;
1430
1440
}
1431
- struct fblockinfo * top = & c -> u -> u_fblock [c -> u -> u_nfblocks - 1 ];
1432
1441
if (top -> fb_type == EXCEPTION_GROUP_HANDLER ) {
1433
1442
return compiler_error (
1434
1443
c , * ploc , "'break', 'continue' and 'return' cannot appear in an except* block" );
@@ -1438,11 +1447,11 @@ compiler_unwind_fblock_stack(struct compiler *c, location *ploc,
1438
1447
return SUCCESS ;
1439
1448
}
1440
1449
struct fblockinfo copy = * top ;
1441
- c -> u -> u_nfblocks -- ;
1442
- RETURN_IF_ERROR (compiler_unwind_fblock (c , ploc , & copy , preserve_tos ));
1443
- RETURN_IF_ERROR (compiler_unwind_fblock_stack (c , ploc , preserve_tos , loop ));
1444
- c -> u -> u_fblock [ c -> u -> u_nfblocks ] = copy ;
1445
- c -> u -> u_nfblocks ++ ;
1450
+ compiler_pop_fblock ( c , top -> fb_type , top -> fb_block ) ;
1451
+ RETURN_IF_ERROR (codegen_unwind_fblock (c , ploc , & copy , preserve_tos ));
1452
+ RETURN_IF_ERROR (codegen_unwind_fblock_stack (c , ploc , preserve_tos , loop ));
1453
+ compiler_push_fblock ( c , copy . fb_loc , copy . fb_type , copy . fb_block ,
1454
+ copy . fb_exit , copy . fb_datum ) ;
1446
1455
return SUCCESS ;
1447
1456
}
1448
1457
@@ -3077,7 +3086,7 @@ codegen_return(struct compiler *c, stmt_ty s)
3077
3086
ADDOP (c , loc , NOP );
3078
3087
}
3079
3088
3080
- RETURN_IF_ERROR (compiler_unwind_fblock_stack (c , & loc , preserve_tos , NULL ));
3089
+ RETURN_IF_ERROR (codegen_unwind_fblock_stack (c , & loc , preserve_tos , NULL ));
3081
3090
if (s -> v .Return .value == NULL ) {
3082
3091
ADDOP_LOAD_CONST (c , loc , Py_None );
3083
3092
}
@@ -3096,11 +3105,11 @@ codegen_break(struct compiler *c, location loc)
3096
3105
location origin_loc = loc ;
3097
3106
/* Emit instruction with line number */
3098
3107
ADDOP (c , loc , NOP );
3099
- RETURN_IF_ERROR (compiler_unwind_fblock_stack (c , & loc , 0 , & loop ));
3108
+ RETURN_IF_ERROR (codegen_unwind_fblock_stack (c , & loc , 0 , & loop ));
3100
3109
if (loop == NULL ) {
3101
3110
return compiler_error (c , origin_loc , "'break' outside loop" );
3102
3111
}
3103
- RETURN_IF_ERROR (compiler_unwind_fblock (c , & loc , loop , 0 ));
3112
+ RETURN_IF_ERROR (codegen_unwind_fblock (c , & loc , loop , 0 ));
3104
3113
ADDOP_JUMP (c , loc , JUMP , loop -> fb_exit );
3105
3114
return SUCCESS ;
3106
3115
}
@@ -3112,7 +3121,7 @@ codegen_continue(struct compiler *c, location loc)
3112
3121
location origin_loc = loc ;
3113
3122
/* Emit instruction with line number */
3114
3123
ADDOP (c , loc , NOP );
3115
- RETURN_IF_ERROR (compiler_unwind_fblock_stack (c , & loc , 0 , & loop ));
3124
+ RETURN_IF_ERROR (codegen_unwind_fblock_stack (c , & loc , 0 , & loop ));
3116
3125
if (loop == NULL ) {
3117
3126
return compiler_error (c , origin_loc , "'continue' not properly in loop" );
3118
3127
}
0 commit comments