Skip to content

Commit 3acaa28

Browse files
committed
py: Don't allocate an extra parse node for power exponent.
Previous to this patch, the "**b" in "a**b" had its own parse node with just one item (the "b"). Now, the "b" is just the last element of the power parse-node. This saves (a tiny bit of) RAM when compiling.
1 parent 52e062e commit 3acaa28

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

py/compile.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1970,6 +1970,10 @@ STATIC void compile_power(compiler_t *comp, mp_parse_node_struct_t *pns) {
19701970
comp->func_arg_is_super = MP_PARSE_NODE_IS_ID(pns->nodes[0]) && MP_PARSE_NODE_LEAF_ARG(pns->nodes[0]) == MP_QSTR_super;
19711971

19721972
compile_generic_all_nodes(comp, pns);
1973+
1974+
if (!MP_PARSE_NODE_IS_NULL(pns->nodes[2])) {
1975+
EMIT_ARG(binary_op, MP_BINARY_OP_POWER);
1976+
}
19731977
}
19741978

19751979
STATIC void compile_trailer_paren_helper(compiler_t *comp, mp_parse_node_t pn_arglist, bool is_method_call, int n_positional_extra) {
@@ -2087,11 +2091,6 @@ STATIC void compile_power_trailers(compiler_t *comp, mp_parse_node_struct_t *pns
20872091
}
20882092
}
20892093

2090-
STATIC void compile_power_dbl_star(compiler_t *comp, mp_parse_node_struct_t *pns) {
2091-
compile_node(comp, pns->nodes[0]);
2092-
EMIT_ARG(binary_op, MP_BINARY_OP_POWER);
2093-
}
2094-
20952094
STATIC void compile_atom_string(compiler_t *comp, mp_parse_node_struct_t *pns) {
20962095
// a list of strings
20972096

py/grammar.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ DEF_RULE(factor_2, c(factor_2), and(2), rule(factor_op), rule(factor))
241241
DEF_RULE(factor_op, nc, or(3), tok(OP_PLUS), tok(OP_MINUS), tok(OP_TILDE))
242242
DEF_RULE(power, c(power), and(3), rule(atom), opt_rule(power_trailers), opt_rule(power_dbl_star))
243243
DEF_RULE(power_trailers, c(power_trailers), one_or_more, rule(trailer))
244-
DEF_RULE(power_dbl_star, c(power_dbl_star), and(2), tok(OP_DBL_STAR), rule(factor))
244+
DEF_RULE(power_dbl_star, nc, ident | and(2), tok(OP_DBL_STAR), rule(factor))
245245

246246
// atom: '(' [yield_expr|testlist_comp] ')' | '[' [testlist_comp] ']' | '{' [dictorsetmaker] '}' | NAME | NUMBER | STRING+ | '...' | 'None' | 'True' | 'False'
247247
// testlist_comp: (test|star_expr) ( comp_for | (',' (test|star_expr))* [','] )

0 commit comments

Comments
 (0)