Skip to content

Commit eacbd7a

Browse files
committed
py: Fix constant folding and inline-asm to work with new async grammar.
1 parent 81ebba7 commit eacbd7a

2 files changed

Lines changed: 6 additions & 11 deletions

File tree

py/compile.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1402,8 +1402,7 @@ STATIC void compile_for_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) {
14021402
mp_parse_node_struct_t *pns_it = (mp_parse_node_struct_t*)pns->nodes[1];
14031403
if (MP_PARSE_NODE_IS_ID(pns_it->nodes[0])
14041404
&& MP_PARSE_NODE_LEAF_ARG(pns_it->nodes[0]) == MP_QSTR_range
1405-
&& MP_PARSE_NODE_IS_STRUCT_KIND(pns_it->nodes[1], PN_trailer_paren)
1406-
&& MP_PARSE_NODE_IS_NULL(pns_it->nodes[2])) {
1405+
&& MP_PARSE_NODE_IS_STRUCT_KIND(pns_it->nodes[1], PN_trailer_paren)) {
14071406
mp_parse_node_t pn_range_args = ((mp_parse_node_struct_t*)pns_it->nodes[1])->nodes[0];
14081407
mp_parse_node_t *args;
14091408
int n_args = mp_parse_node_extract_list(&pn_range_args, PN_arglist, &args);
@@ -3186,7 +3185,6 @@ STATIC void compile_scope_inline_asm(compiler_t *comp, scope_t *scope, pass_kind
31863185
if (!MP_PARSE_NODE_IS_STRUCT_KIND(pns2->nodes[1], PN_trailer_paren)) {
31873186
goto not_an_instruction;
31883187
}
3189-
assert(MP_PARSE_NODE_IS_NULL(pns2->nodes[2]));
31903188

31913189
// parse node looks like an instruction
31923190
// get instruction name and args

py/parse.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -563,11 +563,10 @@ STATIC bool fold_constants(parser_t *parser, const rule_t *rule, size_t num_args
563563
// this node is of the form <x> = <y>
564564
mp_parse_node_t pn0 = peek_result(parser, 1);
565565
if (MP_PARSE_NODE_IS_ID(pn0)
566-
&& MP_PARSE_NODE_IS_STRUCT_KIND(pn1, RULE_power)
566+
&& MP_PARSE_NODE_IS_STRUCT_KIND(pn1, RULE_atom_expr_normal)
567567
&& MP_PARSE_NODE_IS_ID(((mp_parse_node_struct_t*)pn1)->nodes[0])
568568
&& MP_PARSE_NODE_LEAF_ARG(((mp_parse_node_struct_t*)pn1)->nodes[0]) == MP_QSTR_const
569569
&& MP_PARSE_NODE_IS_STRUCT_KIND(((mp_parse_node_struct_t*)pn1)->nodes[1], RULE_trailer_paren)
570-
&& MP_PARSE_NODE_IS_NULL(((mp_parse_node_struct_t*)pn1)->nodes[2])
571570
) {
572571
// code to assign dynamic constants: id = const(value)
573572

@@ -599,13 +598,11 @@ STATIC bool fold_constants(parser_t *parser, const rule_t *rule, size_t num_args
599598
#endif
600599

601600
#if MICROPY_COMP_MODULE_CONST
602-
} else if (rule->rule_id == RULE_power) {
603-
mp_parse_node_t pn0 = peek_result(parser, 2);
604-
mp_parse_node_t pn1 = peek_result(parser, 1);
605-
mp_parse_node_t pn2 = peek_result(parser, 0);
601+
} else if (rule->rule_id == RULE_atom_expr_normal) {
602+
mp_parse_node_t pn0 = peek_result(parser, 1);
603+
mp_parse_node_t pn1 = peek_result(parser, 0);
606604
if (!(MP_PARSE_NODE_IS_ID(pn0)
607-
&& MP_PARSE_NODE_IS_STRUCT_KIND(pn1, RULE_trailer_period)
608-
&& MP_PARSE_NODE_IS_NULL(pn2))) {
605+
&& MP_PARSE_NODE_IS_STRUCT_KIND(pn1, RULE_trailer_period))) {
609606
return false;
610607
}
611608
// id1.id2

0 commit comments

Comments
 (0)