Improved codegen

This commit is contained in:
2026-05-22 02:34:01 +02:00
parent c9a3c4693c
commit 960cc40886
5 changed files with 38 additions and 20 deletions
+12 -10
View File
@@ -18,10 +18,11 @@ impl GenRust for Block {
if let Some(soft_return) = &self.1 {
ctx.expr_ensure_semicolon = false;
soft_return.gen_rust(ctx, cg);
cg.addln("");
}
cg.indent -= 1;
cg.add_indentedln("}");
cg.add_indented("}");
}
}
@@ -57,17 +58,14 @@ impl GenRust for Statement {
p.gen_rust(ctx, cg);
}
cg.add(" => {");
cg.indent += 1;
cg.add(" => ");
body.gen_rust(ctx, cg);
cg.indent -= 1;
cg.add_indentedln("}");
cg.ensure_brackets_expr(ctx, body);
}
cg.indent -= 1;
cg.add_indentedln("}");
cg.addln("");
cg.add_indented("}");
}
Statement::If {
@@ -77,16 +75,18 @@ impl GenRust for Statement {
} => {
cg.add("if ");
initial.condition.gen_rust(ctx, cg);
cg.add(" ");
cg.ensure_brackets(ctx, &initial.body);
for else_if_branch in else_if {
cg.add("else if");
else_if_branch.condition.gen_rust(ctx, cg);
cg.add(" ");
cg.ensure_brackets(ctx, &else_if_branch.body);
}
if let Some(else_br) = else_branch {
cg.add("else");
cg.add(" else ");
cg.ensure_brackets(ctx, else_br);
}
}
@@ -116,7 +116,9 @@ impl GenRust for Statement {
cg.indent += 1;
cg.ensure_brackets(ctx, body);
ctx.expr_ensure_semicolon = true;
body.gen_rust(ctx, cg);
update.gen_rust(ctx, cg);