Skip to content

Commit 93afa23

Browse files
committed
py, parser: Add commented-out code to discard doc strings.
Doesn't help with RAM reduction because doc strings are interned as soon as they are encountered, which is too soon to do any optimisations on them.
1 parent c53b408 commit 93afa23

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

py/parse.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,20 @@ mp_parse_node_t mp_parse(mp_lexer_t *lex, mp_parse_input_kind_t input_kind, mp_p
511511
}
512512
}
513513

514+
#if 0 && !MICROPY_ENABLE_DOC_STRING
515+
// this code discards lonely statement, such as doc strings
516+
// problem is that doc strings have already been interned, so this doesn't really help reduce RAM usage
517+
if (input_kind != MP_PARSE_SINGLE_INPUT && rule->rule_id == RULE_expr_stmt && peek_result(parser, 0) == MP_PARSE_NODE_NULL) {
518+
mp_parse_node_t p = peek_result(parser, 1);
519+
if (MP_PARSE_NODE_IS_LEAF(p) && !MP_PARSE_NODE_IS_ID(p)) {
520+
pop_result(parser);
521+
pop_result(parser);
522+
push_result_rule(parser, rule_src_line, rules[RULE_pass_stmt], 0);
523+
break;
524+
}
525+
}
526+
#endif
527+
514528
// always emit these rules, even if they have only 1 argument
515529
if (rule->rule_id == RULE_expr_stmt || rule->rule_id == RULE_yield_stmt) {
516530
emit_rule = true;

0 commit comments

Comments
 (0)