@@ -108,8 +108,8 @@ It's called a frame block to distinguish it from a basic block in the
108
108
compiler IR.
109
109
*/
110
110
111
- enum fblocktype { WHILE_LOOP , FOR_LOOP , EXCEPT , FINALLY_TRY , FINALLY_END ,
112
- WITH , ASYNC_WITH , HANDLER_CLEANUP , POP_VALUE };
111
+ enum fblocktype { WHILE_LOOP , FOR_LOOP , TRY_EXCEPT , FINALLY_TRY , FINALLY_END ,
112
+ WITH , ASYNC_WITH , HANDLER_CLEANUP , POP_VALUE , EXCEPTION_HANDLER };
113
113
114
114
struct fblockinfo {
115
115
enum fblocktype fb_type ;
@@ -1623,9 +1623,7 @@ compiler_push_fblock(struct compiler *c, enum fblocktype t, basicblock *b,
1623
1623
{
1624
1624
struct fblockinfo * f ;
1625
1625
if (c -> u -> u_nfblocks >= CO_MAXBLOCKS ) {
1626
- PyErr_SetString (PyExc_SyntaxError ,
1627
- "too many statically nested blocks" );
1628
- return 0 ;
1626
+ return compiler_error (c , "too many statically nested blocks" );
1629
1627
}
1630
1628
f = & c -> u -> u_fblock [c -> u -> u_nfblocks ++ ];
1631
1629
f -> fb_type = t ;
@@ -1665,6 +1663,7 @@ compiler_unwind_fblock(struct compiler *c, struct fblockinfo *info,
1665
1663
{
1666
1664
switch (info -> fb_type ) {
1667
1665
case WHILE_LOOP :
1666
+ case EXCEPTION_HANDLER :
1668
1667
return 1 ;
1669
1668
1670
1669
case FOR_LOOP :
@@ -1675,7 +1674,7 @@ compiler_unwind_fblock(struct compiler *c, struct fblockinfo *info,
1675
1674
ADDOP (c , POP_TOP );
1676
1675
return 1 ;
1677
1676
1678
- case EXCEPT :
1677
+ case TRY_EXCEPT :
1679
1678
ADDOP (c , POP_BLOCK );
1680
1679
return 1 ;
1681
1680
@@ -3060,14 +3059,17 @@ compiler_try_except(struct compiler *c, stmt_ty s)
3060
3059
return 0 ;
3061
3060
ADDOP_JUMP (c , SETUP_FINALLY , except );
3062
3061
compiler_use_next_block (c , body );
3063
- if (!compiler_push_fblock (c , EXCEPT , body , NULL , NULL ))
3062
+ if (!compiler_push_fblock (c , TRY_EXCEPT , body , NULL , NULL ))
3064
3063
return 0 ;
3065
3064
VISIT_SEQ (c , stmt , s -> v .Try .body );
3066
3065
ADDOP (c , POP_BLOCK );
3067
- compiler_pop_fblock (c , EXCEPT , body );
3066
+ compiler_pop_fblock (c , TRY_EXCEPT , body );
3068
3067
ADDOP_JUMP (c , JUMP_FORWARD , orelse );
3069
3068
n = asdl_seq_LEN (s -> v .Try .handlers );
3070
3069
compiler_use_next_block (c , except );
3070
+ /* Runtime will push a block here, so we need to account for that */
3071
+ if (!compiler_push_fblock (c , EXCEPTION_HANDLER , NULL , NULL , NULL ))
3072
+ return 0 ;
3071
3073
for (i = 0 ; i < n ; i ++ ) {
3072
3074
excepthandler_ty handler = (excepthandler_ty )asdl_seq_GET (
3073
3075
s -> v .Try .handlers , i );
@@ -3152,6 +3154,7 @@ compiler_try_except(struct compiler *c, stmt_ty s)
3152
3154
}
3153
3155
compiler_use_next_block (c , except );
3154
3156
}
3157
+ compiler_pop_fblock (c , EXCEPTION_HANDLER , NULL );
3155
3158
ADDOP (c , RERAISE );
3156
3159
compiler_use_next_block (c , orelse );
3157
3160
VISIT_SEQ (c , stmt , s -> v .Try .orelse );
0 commit comments