8000 py: Deoptimise try-finally and subscript parse nodes to match master. · DFRobot/micropython@72912c7 · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 72912c7

Browse files
committed
py: Deoptimise try-finally and subscript parse nodes to match master.
This is a small de-optimisation so that it's easier to merge master into this branch.
1 parent be020eb commit 72912c7

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

py/compile2.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1649,6 +1649,8 @@ STATIC void compile_try_except(compiler_t *comp, const byte *p_body, const byte
16491649
}
16501650

16511651
STATIC void compile_try_finally(compiler_t *comp, const byte *p_body, const byte *p_except, const byte *p_except_top, const byte *p_else, const byte *p_finally) {
1652+
assert(pt_is_rule(p_finally, PN_try_stmt_finally));
1653+
16521654
uint l_finally_block = comp_next_label(comp);
16531655

16541656
EMIT_ARG(setup_finally, l_finally_block);
@@ -1665,7 +1667,7 @@ STATIC void compile_try_finally(compiler_t *comp, const byte *p_body, const byte
16651667
EMIT(pop_block);
16661668
EMIT_ARG(load_const_tok, MP_TOKEN_KW_NONE);
16671669
EMIT_ARG(label_assign, l_finally_block);
1668-
compile_node(comp, p_finally);
1670+
compile_node(comp, pt_rule_first(p_finally));
16691671

16701672
compile_decrease_except_level(comp);
16711673
EMIT(end_finally);
@@ -2412,7 +2414,9 @@ STATIC void compile_subscript_3_helper(compiler_t *comp, const byte *p, const by
24122414
} else if (pt_is_rule(p, PN_subscript_3d)) {
24132415
p = pt_rule_first(p);
24142416
p = compile_node(comp, p);
2415-
if (pt_is_rule(p, PN_sliceop)) {
2417+
assert(pt_is_rule(p, PN_sliceop)); // should always be
2418+
p = pt_rule_first(p);
2419+
if (p == ptop) {
24162420
// [?:x:]
24172421
EMIT_ARG(build_slice, 2);
24182422
} else {

py/grammar.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ DEF_RULE(try_stmt_except_and_more, nc, and(3), rule(try_stmt_except_list), opt_r
180180
DEF_RULE(try_stmt_except, nc, and(4), tok(KW_EXCEPT), opt_rule(try_stmt_as_name), tok(DEL_COLON), rule(suite))
181181
DEF_RULE(try_stmt_as_name, nc, and(2), rule(test), opt_rule(as_name))
182182
DEF_RULE(try_stmt_except_list, nc, one_or_more, rule(try_stmt_except))
183-
DEF_RULE(try_stmt_finally, nc, ident | and(3), tok(KW_FINALLY), tok(DEL_COLON), rule(suite))
183+
DEF_RULE(try_stmt_finally, nc, and(3), tok(KW_FINALLY), tok(DEL_COLON), rule(suite))
184184
DEF_RULE(else_stmt, nc, ident | and(3), tok(KW_ELSE), tok(DEL_COLON), rule(suite))
185185
DEF_RULE(with_stmt, c(with_stmt), and(4), tok(KW_WITH), rule(with_stmt_list), tok(DEL_COLON), rule(suite))
186186
DEF_RULE(with_stmt_list, nc, list, rule(with_item), tok(DEL_COMMA))
@@ -275,7 +275,7 @@ DEF_RULE(subscript_3, c(subscript_3), and(2), tok(DEL_COLON), opt_rule(subscript
275275
DEF_RULE(subscript_3b, nc, or(2), rule(subscript_3c), rule(subscript_3d))
276276
DEF_RULE(subscript_3c, nc, and(2), tok(DEL_COLON), opt_rule(test))
277277
DEF_RULE(subscript_3d, nc, and(2), rule(test), opt_rule(sliceop))
278-
DEF_RULE(sliceop, nc, ident | and(2), tok(DEL_COLON), opt_rule(test))
278+
DEF_RULE(sliceop, nc, and(2), tok(DEL_COLON), opt_rule(test))
279279
#else
280280
DEF_RULE(subscriptlist, c(generic_tuple), list_with_end, rule(test), tok(DEL_COMMA))
281281
#endif

0 commit comments

Comments
 (0)
0