py/compile: Combine subscript_2 and subscript_3 into one function.

crypto-aes
Damien George 5 years ago
parent c149197928
commit d23bec3fc8

@ -2546,7 +2546,16 @@ STATIC void compile_trailer_period(compiler_t *comp, mp_parse_node_struct_t *pns
}
#if MICROPY_PY_BUILTINS_SLICE
STATIC void compile_subscript_3_helper(compiler_t *comp, mp_parse_node_struct_t *pns) {
STATIC void compile_subscript(compiler_t *comp, mp_parse_node_struct_t *pns) {
if (MP_PARSE_NODE_STRUCT_KIND(pns) == PN_subscript_2) {
compile_node(comp, pns->nodes[0]); // start of slice
assert(MP_PARSE_NODE_IS_STRUCT(pns->nodes[1])); // should always be
pns = (mp_parse_node_struct_t*)pns->nodes[1];
} else {
// pns is a PN_subscript_3, load None for start of slice
EMIT_ARG(load_const_tok, MP_TOKEN_KW_NONE);
}
assert(MP_PARSE_NODE_STRUCT_KIND(pns) == PN_subscript_3); // should always be
mp_parse_node_t pn = pns->nodes[0];
if (MP_PARSE_NODE_IS_NULL(pn)) {
@ -2590,17 +2599,6 @@ STATIC void compile_subscript_3_helper(compiler_t *comp, mp_parse_node_struct_t
EMIT_ARG(build, 2, MP_EMIT_BUILD_SLICE);
}
}
STATIC void compile_subscript_2(compiler_t *comp, mp_parse_node_struct_t *pns) {
compile_node(comp, pns->nodes[0]); // start of slice
assert(MP_PARSE_NODE_IS_STRUCT(pns->nodes[1])); // should always be
compile_subscript_3_helper(comp, (mp_parse_node_struct_t*)pns->nodes[1]);
}
STATIC void compile_subscript_3(compiler_t *comp, mp_parse_node_struct_t *pns) {
EMIT_ARG(load_const_tok, MP_TOKEN_KW_NONE);
compile_subscript_3_helper(comp, pns);
}
#endif // MICROPY_PY_BUILTINS_SLICE
STATIC void compile_dictorsetmaker_item(compiler_t *comp, mp_parse_node_struct_t *pns) {

@ -290,8 +290,8 @@ DEF_RULE(trailer_period, c(trailer_period), and(2), tok(DEL_PERIOD), tok(NAME))
#if MICROPY_PY_BUILTINS_SLICE
DEF_RULE(subscriptlist, c(generic_tuple), list_with_end, rule(subscript), tok(DEL_COMMA))
DEF_RULE_NC(subscript, or(2), rule(subscript_3), rule(subscript_2))
DEF_RULE(subscript_2, c(subscript_2), and_ident(2), rule(test), opt_rule(subscript_3))
DEF_RULE(subscript_3, c(subscript_3), and(2), tok(DEL_COLON), opt_rule(subscript_3b))
DEF_RULE(subscript_2, c(subscript), and_ident(2), rule(test), opt_rule(subscript_3))
DEF_RULE(subscript_3, c(subscript), and(2), tok(DEL_COLON), opt_rule(subscript_3b))
DEF_RULE_NC(subscript_3b, or(2), rule(subscript_3c), rule(subscript_3d))
DEF_RULE_NC(subscript_3c, and(2), tok(DEL_COLON), opt_rule(test))
DEF_RULE_NC(subscript_3d, and_ident(2), rule(test), opt_rule(sliceop))

Loading…
Cancel
Save