control flow

This commit is contained in:
uan
2026-02-06 17:03:35 +01:00
parent db1b4b88c0
commit a09a642bb7
5 changed files with 80 additions and 22 deletions

View File

@@ -112,7 +112,6 @@ fn (mut g Generator) gen_stmt(stmt Stmt) {
g.out.writeln('}')
}
FuncDecl {
dump(stmt.ret_type)
c_type := g.mangle_if_class(g.get_c_type(stmt.ret_type))
g.out.write_string('${c_type} ${mangle_func(stmt.name)}(')
for param in stmt.params {
@@ -121,7 +120,7 @@ fn (mut g Generator) gen_stmt(stmt Stmt) {
g.out.write_string(', ')
}
}
g.out.write_string(')')
g.out.write_string(') ')
g.gen_stmt(stmt.block)
}
Param {
@@ -138,6 +137,22 @@ fn (mut g Generator) gen_stmt(stmt Stmt) {
g.gen_class_print_func(stmt)
}
IfStmt {
g.out.write_string('if (')
g.gen_expr(stmt.condition)
g.out.write_string(') ')
g.gen_stmt(stmt.block)
}
ElseStmt {
g.out.write_string('else ')
g.gen_stmt(stmt.block)
}
ElifStmt {
g.out.write_string('else if (')
g.gen_expr(stmt.condition)
g.out.write_string(') ')
g.gen_stmt(stmt.block)
}
}
}
@@ -173,7 +188,6 @@ fn (mut g Generator) gen_expr(expr Expr) {
for i < expr.exprs.len {
inner_expr := expr.exprs[i];
expr_type := expr.types[i];
label := g.get_print_label(inner_expr);
if g.symbols.lookup_class(expr_type) != none {
class_name := mangle_struct(expr_type)
g.out.write_string('print_${class_name}(')
@@ -181,7 +195,6 @@ fn (mut g Generator) gen_expr(expr Expr) {
g.out.write_string(', 0);')
} else {
g.out.write_string('printf(\"')
dump(label);
format := get_type_format(expr_type)
g.out.write_string('%${format}')
g.out.write_string('\", ')
@@ -193,7 +206,7 @@ fn (mut g Generator) gen_expr(expr Expr) {
g.out.write_string('printf(\" \");')
}
}
g.out.write_string('printf(\"\\n\");\n')
g.out.write_string('printf(\"\\n\")')
}
TypeCast {
c_type := g.mangle_if_class(g.get_c_type(expr.type))