8000 compiler_try_star_finally, compiler_try_star_except return SUCCESS/ERROR · python/cpython@2680b56 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2680b56

Browse files
committed
compiler_try_star_finally, compiler_try_star_except return SUCCESS/ERROR
1 parent 0902cf1 commit 2680b56

File tree

1 file changed

+72
-73
lines changed

1 file changed

+72
-73
lines changed

Python/compile.c

Lines changed: 72 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -3562,46 +3562,45 @@ compiler_try_star_finally(struct compiler *c, stmt_ty s)
35623562
NEW_JUMP_TARGET_LABEL(c, exit);
35633563
NEW_JUMP_TARGET_LABEL(c, cleanup);
35643564
/* `try` block */
3565-
_ADDOP_JUMP(c, loc, SETUP_FINALLY, end);
3565+
ADDOP_JUMP(c, loc, SETUP_FINALLY, end);
35663566

35673567
USE_LABEL(c, body);
3568-
if (compiler_push_fblock(c, loc, FINALLY_TRY, body, end, s->v.TryStar.finalbody) < 0) {
3569-
return 0;
3570-
}
3568+
RETURN_IF_ERROR(
3569+
compiler_push_fblock(c, loc, FINALLY_TRY, body, end,
3570+
s->v.TryStar.finalbody));
3571+
35713572
if (s->v.TryStar.handlers && asdl_seq_LEN(s->v.TryStar.handlers)) {
3572-
if (!compiler_try_star_except(c, s)) {
3573-
return 0;
3574-
}
3573+
RETURN_IF_ERROR(compiler_try_star_except(c, s));
35753574
}
35763575
else {
3577-
_VISIT_SEQ(c, stmt, s->v.TryStar.body);
3576+
VISIT_SEQ(c, stmt, s->v.TryStar.body);
35783577
}
3579-
_ADDOP(c, NO_LOCATION, POP_BLOCK);
3578+
ADDOP(c, NO_LOCATION, POP_BLOCK);
35803579
compiler_pop_fblock(c, FINALLY_TRY, body);
3581-
_VISIT_SEQ(c, stmt, s->v.TryStar.finalbody);
3580+
VISIT_SEQ(c, stmt, s->v.TryStar.finalbody);
35823581

3583-
_ADDOP_JUMP(c, NO_LOCATION, JUMP, exit);
3582+
ADDOP_JUMP(c, NO_LOCATION, JUMP, exit);
35843583

35853584
/* `finally` block */
35863585
USE_LABEL(c, end);
35873586

35883587
loc = NO_LOCATION;
3589-
_ADDOP_JUMP(c, loc, SETUP_CLEANUP, cleanup);
3590-
_ADDOP(c, loc, PUSH_EXC_INFO);
3591-
if (compiler_push_fblock(c, loc, FINALLY_END, end, NO_LABEL, NULL) < 0) {
3592-
return 0;
3593-
}
3594-
_VISIT_SEQ(c, stmt, s->v.TryStar.finalbody);
3588 8000 +
ADDOP_JUMP(c, loc, SETUP_CLEANUP, cleanup);
3589+
ADDOP(c, loc, PUSH_EXC_INFO);
3590+
RETURN_IF_ERROR(
3591+
compiler_push_fblock(c, loc, FINALLY_END, end, NO_LABEL, NULL));
3592+
3593+
VISIT_SEQ(c, stmt, s->v.TryStar.finalbody);
35953594
loc = location_of_last_executing_statement(s->v.Try.finalbody);
35963595

35973596
compiler_pop_fblock(c, FINALLY_END, end);
3598-
_ADDOP_I(c, loc, RERAISE, 0);
3597+
ADDOP_I(c, loc, RERAISE, 0);
35993598

36003599
USE_LABEL(c, cleanup);
3601-
_POP_EXCEPT_AND_RERAISE(c, loc);
3600+
POP_EXCEPT_AND_RERAISE(c, loc);
36023601

36033602
USE_LABEL(c, exit);
3604-
return 1;
3603+
return SUCCESS;
36053604
}
36063605

36073606

@@ -3820,27 +3819,27 @@ compiler_try_star_except(struct compiler *c, stmt_ty s)
38203819
NEW_JUMP_TARGET_LABEL(c, cleanup);
38213820
NEW_JUMP_TARGET_LABEL(c, reraise_star);
38223821

3823-
_ADDOP_JUMP(c, loc, SETUP_FINALLY, except);
3822+
ADDOP_JUMP(c, loc, SETUP_FINALLY, except);
38243823

38253824
USE_LABEL(c, body);
3826-
if (compiler_push_fblock(c, loc, TRY_EXCEPT, body, NO_LABEL, NULL) < 0) {
3827-
return 0;
3828-
}
3829-
_VISIT_SEQ(c, stmt, s->v.TryStar.body);
3825+
RETURN_IF_ERROR(
3826+
compiler_push_fblock(c, loc, TRY_EXCEPT, body, NO_LABEL, NULL));
3827+
VISIT_SEQ(c, stmt, s->v.TryStar.body);
38303828
compiler_pop_fblock(c, TRY_EXCEPT, body);
3831-
_ADDOP(c, NO_LOCATION, POP_BLOCK);
3832-
_ADDOP_JUMP(c, NO_LOCATION, JUMP, orelse);
3829+
ADDOP(c, NO_LOCATION, POP_BLOCK);
3830+
ADDOP_JUMP(c, NO_LOCATION, JUMP, orelse);
38333831
Py_ssize_t n = asdl_seq_LEN(s->v.TryStar.handlers);
38343832

38353833
USE_LABEL(c, except);
38363834

3837-
_ADDOP_JUMP(c, NO_LOCATION, SETUP_CLEANUP, cleanup);
3838-
_ADDOP(c, NO_LOCATION, PUSH_EXC_INFO);
3835+
ADDOP_JUMP(c, NO_LOCATION, SETUP_CLEANUP, cleanup);
3836+
ADDOP(c, NO_LOCATION, PUSH_EXC_INFO);
3837+
38393838
/* Runtime will push a block here, so we need to account for that */
3840-
if (compiler_push_fblock(c, loc, EXCEPTION_GROUP_HANDLER,
3841-
NO_LABEL, NO_LABEL, "except handler") < 0) {
3842-
return 0;
3843-
}
3839+
RETURN_IF_ERROR(
3840+
compiler_push_fblock(c, loc, EXCEPTION_GROUP_HANDLER,
3841+
NO_LABEL, NO_LABEL, "except handler"));
3842+
38443843
for (Py_ssize_t i = 0; i < n; i++) {
38453844
excepthandler_ty handler = (excepthandler_ty)asdl_seq_GET(
38463845
s->v.TryStar.handlers, i);
@@ -3854,24 +3853,24 @@ compiler_try_star_except(struct compiler *c, stmt_ty s)
38543853
[exc] COPY 1
38553854
[orig, exc]
38563855
*/
3857-
_ADDOP_I(c, loc, COPY, 1);
3856+
ADDOP_I(c, loc, COPY, 1);
38583857

38593858
/* create empty list for exceptions raised/reraise in the except* blocks */
38603859
/*
38613860
[orig, exc] BUILD_LIST
38623861
[orig, exc, []] SWAP 2
38633862
[orig, [], exc]
38643863
*/
3865-
_ADDOP_I(c, loc, BUILD_LIST, 0);
3866-
_ADDOP_I(c, loc, SWAP, 2);
3864+
ADDOP_I(c, loc, BUILD_LIST, 0);
3865+
ADDOP_I(c, loc, SWAP, 2);
38673866
}
38683867
if (handler->v.ExceptHandler.type) {
3869-
_VISIT(c, expr, handler->v.ExceptHandler.type);
3870-
_ADDOP(c, loc, CHECK_EG_MATCH);
3871-
_ADDOP_I(c, loc, COPY, 1);
3872-
_ADDOP_JUMP(c, loc, POP_JUMP_IF_NOT_NONE, handle_match);
3873-
_ADDOP(c, loc, POP_TOP); // match
3874-
_ADDOP_JUMP(c, loc, JUMP, except);
3868+
VISIT(c, expr, handler->v.ExceptHandler.type);
3869+
ADDOP(c, loc, CHECK_EG_MATCH);
3870+
ADDOP_I(c, loc, COPY, 1);
3871+
ADDOP_JUMP(c, loc, POP_JUMP_IF_NOT_NONE, handle_match);
3872+
ADDOP(c, loc, POP_TOP); // match
3873+
ADDOP_JUMP(c, loc, JUMP, except);
38753874
}
38763875

38773876
USE_LABEL(c, handle_match);
@@ -3883,7 +3882,7 @@ compiler_try_star_except(struct compiler *c, stmt_ty s)
38833882
compiler_nameop(c, loc, handler->v.ExceptHandler.name, Store);
38843883
}
38853884
else {
3886-
_ADDOP(c, loc, POP_TOP); // match
3885+
ADDOP(c, loc, POP_TOP); // match
38873886
}
38883887

38893888
/*
@@ -3897,77 +3896,77 @@ compiler_try_star_except(struct compiler *c, stmt_ty s)
38973896
del name
38983897
*/
38993898
/* second try: */
3900-
_ADDOP_JUMP(c, loc, SETUP_CLEANUP, cleanup_end);
3899+
ADDOP_JUMP(c, loc, SETUP_CLEANUP, cleanup_end);
39013900

39023901
USE_LABEL(c, cleanup_body);
3903-
if (compiler_push_fblock(c, loc, HANDLER_CLEANUP, cleanup_body, NO_LABEL, handler->v.ExceptHandler.name) < 0) {
3904-
return 0;
3905-
}
3902+
RETURN_IF_ERROR(
3903+
compiler_push_fblock(c, loc, HANDLER_CLEANUP, cleanup_body,
3904+
NO_LABEL, handler->v.ExceptHandler.name));
39063905

39073906
/* second # body */
3908-
_VISIT_SEQ(c, stmt, handler->v.ExceptHandler.body);
3907+
VISIT_SEQ(c, stmt, handler->v.ExceptHandler.body);
39093908
compiler_pop_fblock(c, HANDLER_CLEANUP, cleanup_body);
39103909
/* name = None; del name; # artificial */
3911-
_ADDOP(c, NO_LOCATION, POP_BLOCK);
3910+
ADDOP(c, NO_LOCATION, POP_BLOCK);
39123911
if (handler->v.ExceptHandler.name) {
3913-
_ADDOP_LOAD_CONST(c, NO_LOCATION, Py_None);
3912+
ADDOP_LOAD_CONST(c, NO_LOCATION, Py_None);
39143913
compiler_nameop(c, NO_LOCATION, handler->v.ExceptHandler.name, Store);
39153914
compiler_nameop(c, NO_LOCATION, handler->v.ExceptHandler.name, Del);
39163915
}
3917-
_ADDOP_JUMP(c, NO_LOCATION, JUMP, except);
3916+
ADDOP_JUMP(c, NO_LOCATION, JUMP, except);
39183917

39193918
/* except: */
39203919
USE_LABEL(c, cleanup_end);
39213920

39223921
/* name = None; del name; # artificial */
39233922
if (handler->v.ExceptHandler.name) {
3924-
_ADDOP_LOAD_CONST(c, NO_LOCATION, Py_None);
3923+
ADDOP_LOAD_CONST(c, NO_LOCATION, Py_None);
39253924
compiler_nameop(c, NO_LOCATION, handler->v.ExceptHandler.name, Store);
39263925
compiler_nameop(c, NO_LOCATION, handler->v.ExceptHandler.name, Del);
39273926
}
39283927

39293928
/* add exception raised to the res list */
3930-
_ADDOP_I(c, NO_LOCATION, LIST_APPEND, 3); // exc
3931-
_ADDOP(c, NO_LOCATION, POP_TOP); // lasti
3932-
_ADDOP_JUMP(c, NO_LOCATION, JUMP, except);
3929+
ADDOP_I(c, NO_LOCATION, LIST_APPEND, 3); // exc
3930+
ADDOP(c, NO_LOCATION, POP_TOP); // lasti
3931+
ADDOP_JUMP(c, NO_LOCATION, JUMP, except);
39333932

39343933
USE_LABEL(c, except);
39353934

39363935
if (i == n - 1) {
39373936
/* Add exc to the list (if not None it's the unhandled part of the EG) */
3938-
_ADDOP_I(c, NO_LOCATION, LIST_APPEND, 1);
3939-
_ADDOP_JUMP(c, NO_LOCATION, JUMP, reraise_star);
3937+
ADDOP_I(c, NO_LOCATION, LIST_APPEND, 1);
3938+
ADDOP_JUMP(c, NO_LOCATION, JUMP, reraise_star);
39403939
}
39413940
}
39423941
/* artificial */
39433942
compiler_pop_fblock(c, EXCEPTION_GROUP_HANDLER, NO_LABEL);
39443943
NEW_JUMP_TARGET_LABEL(c, reraise);
39453944

39463945
USE_LABEL(c, reraise_star);
3947-
_ADDOP(c, NO_LOCATION, PREP_RERAISE_STAR);
3948-
_ADDOP_I(c, NO_LOCATION, COPY, 1);
3949-
_ADDOP_JUMP(c, NO_LOCATION, POP_JUMP_IF_NOT_NONE, reraise);
3946+
ADDOP(c, NO_LOCATION, PREP_RERAISE_STAR);
3947+
ADDOP_I(c, NO_LOCATION, COPY, 1);
3948+
ADDOP_JUMP(c, NO_LOCATION, POP_JUMP_IF_NOT_NONE, reraise);
39503949

39513950
/* Nothing to reraise */
3952-
_ADDOP(c, NO_LOCATION, POP_TOP);
3953-
_ADDOP(c, NO_LOCATION, POP_BLOCK);
3954-
_ADDOP(c, NO_LOCATION, POP_EXCEPT);
3955-
_ADDOP_JUMP(c, NO_LOCATION, JUMP, end);
3951+
ADDOP(c, NO_LOCATION, POP_TOP);
3952+
ADDOP(c, NO_LOCATION, POP_BLOCK);
3953+
ADDOP(c, NO_LOCATION, POP_EXCEPT);
3954+
ADDOP_JUMP(c, NO_LOCATION, JUMP, end);
39563955

39573956
USE_LABEL(c, reraise);
3958-
_ADDOP(c, NO_LOCATION, POP_BLOCK);
3959-
_ADDOP_I(c, NO_LOCATION, SWAP, 2);
3960-
_ADDOP(c, NO_LOCATION, POP_EXCEPT);
3961-
_ADDOP_I(c, NO_LOCATION, RERAISE, 0);
3957+
ADDOP(c, NO_LOCATION, POP_BLOCK);
3958+
ADDOP_I(c, NO_LOCATION, SWAP, 2);
3959+
ADDOP(c, NO_LOCATION, POP_EXCEPT);
3960+
ADDOP_I(c, NO_LOCATION, RERAISE, 0);
39623961

39633962
USE_LABEL(c, cleanup);
3964-
_POP_EXCEPT_AND_RERAISE(c, NO_LOCATION);
3963+
POP_EXCEPT_AND_RERAISE(c, NO_LOCATION);
39653964

39663965
USE_LABEL(c, orelse);
3967-
_VISIT_SEQ(c, stmt, s->v.TryStar.orelse);
3966+
VISIT_SEQ(c, stmt, s->v.TryStar.orelse);
39683967

39693968
USE_LABEL(c, end);
3970-
return 1;
3969+
return SUCCESS;
39713970
}
39723971

39733972
static int
@@ -3982,10 +3981,10 @@ static int
39823981
compiler_try_star(struct compiler *c, stmt_ty s)
39833982
{
39843983
if (s->v.TryStar.finalbody && asdl_seq_LEN(s->v.TryStar.finalbody)) {
3985-
return compiler_try_star_finally(c, s);
3984+
return compiler_try_star_finally(c, s) == SUCCESS ? 1 : 0;
39863985
}
39873986
else {
3988-
return compiler_try_star_except(c, s);
3987+
return compiler_try_star_except(c, s) == SUCCESS ? 1 : 0;
39893988
}
39903989
}
39913990

0 commit comments

Comments
 (0)
0