mruby-compiler: optimize NODE_STMTS nesting to reduce AST depth

Modify new_stmts to flatten unnecessary nesting by returning existing
NODE_STMTS directly instead of wrapping them. This reduces memory usage
and AST complexity when multiple parentheses levels are used.

Before: (((expr1; expr2))) creates nested NODE_STMTS
After: (((expr1; expr2))) creates single NODE_STMTS with statements

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Yukihiro "Matz" Matsumoto
2025-07-05 19:34:15 +09:00
parent f6c166cbb0
commit dc0a5f433f
+4
View File
@@ -385,6 +385,10 @@ static node*
new_stmts(parser_state *p, node *body)
{
if (body) {
/* If body is already a NODE_STMTS, just return it directly */
if (typen(body->car) == NODE_STMTS) {
return body;
}
return list2((node*)NODE_STMTS, body);
}
return cons((node*)NODE_STMTS, 0);