summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2017-08-13 21:23:02 +1000
committerDamien George <damien.p.george@gmail.com>2017-08-13 21:23:02 +1000
commit72912c753a31301efb7d6b2f35dd1e3e64b98cd4 (patch)
treed6d52e4cbf5d7021e3b92778b66772df25ee6ea6
parentbe020eb2c3c7e8421ee0989a7a09498a91b974fb (diff)
downloadmicropython-72912c753a31301efb7d6b2f35dd1e3e64b98cd4.tar.gz
micropython-72912c753a31301efb7d6b2f35dd1e3e64b98cd4.zip
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.
-rw-r--r--py/compile2.c8
-rw-r--r--py/grammar.h4
2 files changed, 8 insertions, 4 deletions
diff --git a/py/compile2.c b/py/compile2.c
index 5ef00feaa2..ef9e434723 100644
--- a/py/compile2.c
+++ b/py/compile2.c
@@ -1649,6 +1649,8 @@ STATIC void compile_try_except(compiler_t *comp, const byte *p_body, const byte
}
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) {
+ assert(pt_is_rule(p_finally, PN_try_stmt_finally));
+
uint l_finally_block = comp_next_label(comp);
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
EMIT(pop_block);
EMIT_ARG(load_const_tok, MP_TOKEN_KW_NONE);
EMIT_ARG(label_assign, l_finally_block);
- compile_node(comp, p_finally);
+ compile_node(comp, pt_rule_first(p_finally));
compile_decrease_except_level(comp);
EMIT(end_finally);
@@ -2412,7 +2414,9 @@ STATIC void compile_subscript_3_helper(compiler_t *comp, const byte *p, const by
} else if (pt_is_rule(p, PN_subscript_3d)) {
p = pt_rule_first(p);
p = compile_node(comp, p);
- if (pt_is_rule(p, PN_sliceop)) {
+ assert(pt_is_rule(p, PN_sliceop)); // should always be
+ p = pt_rule_first(p);
+ if (p == ptop) {
// [?:x:]
EMIT_ARG(build_slice, 2);
} else {
diff --git a/py/grammar.h b/py/grammar.h
index 004e14826f..89a5a06537 100644
--- a/py/grammar.h
+++ b/py/grammar.h
@@ -180,7 +180,7 @@ DEF_RULE(try_stmt_except_and_more, nc, and(3), rule(try_stmt_except_list), opt_r
DEF_RULE(try_stmt_except, nc, and(4), tok(KW_EXCEPT), opt_rule(try_stmt_as_name), tok(DEL_COLON), rule(suite))
DEF_RULE(try_stmt_as_name, nc, and(2), rule(test), opt_rule(as_name))
DEF_RULE(try_stmt_except_list, nc, one_or_more, rule(try_stmt_except))
-DEF_RULE(try_stmt_finally, nc, ident | and(3), tok(KW_FINALLY), tok(DEL_COLON), rule(suite))
+DEF_RULE(try_stmt_finally, nc, and(3), tok(KW_FINALLY), tok(DEL_COLON), rule(suite))
DEF_RULE(else_stmt, nc, ident | and(3), tok(KW_ELSE), tok(DEL_COLON), rule(suite))
DEF_RULE(with_stmt, c(with_stmt), and(4), tok(KW_WITH), rule(with_stmt_list), tok(DEL_COLON), rule(suite))
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
DEF_RULE(subscript_3b, nc, or(2), rule(subscript_3c), rule(subscript_3d))
DEF_RULE(subscript_3c, nc, and(2), tok(DEL_COLON), opt_rule(test))
DEF_RULE(subscript_3d, nc, and(2), rule(test), opt_rule(sliceop))
-DEF_RULE(sliceop, nc, ident | and(2), tok(DEL_COLON), opt_rule(test))
+DEF_RULE(sliceop, nc, and(2), tok(DEL_COLON), opt_rule(test))
#else
DEF_RULE(subscriptlist, c(generic_tuple), list_with_end, rule(test), tok(DEL_COMMA))
#endif