function calls

This commit is contained in:
uan
2026-02-04 21:39:14 +01:00
parent ce51292f7c
commit ab5559d206
5 changed files with 35 additions and 10 deletions

View File

@@ -17,7 +17,7 @@ fn (mut g Generator) gen_stmt(stmt Stmt) {
match stmt {
VarDecl {
c_type := g.get_c_type(stmt.type)
g.out.write_string('${c_type} ${stmt.name} = ')
g.out.write_string('${c_type} v${stmt.name}${stmt.scope_depth.str()} = ')
g.gen_expr(stmt.value)
g.out.writeln(';')
}
@@ -57,10 +57,9 @@ fn (mut g Generator) gen_expr(expr Expr) {
g.out.write_string(expr.val.str())
}
Variable {
g.out.write_string(expr.name)
g.out.write_string('v${expr.name}${expr.scope_depth.str()}')
}
UnaryExpr {
// Handle postfix/prefix logic if necessary
g.out.write_string('${expr.ident}${expr.op}')
}
BinaryExpr {
@@ -86,7 +85,15 @@ fn (mut g Generator) gen_expr(expr Expr) {
g.out.write_string('(${c_type})')
g.gen_expr(expr.expr)
}
else {panic('unimplemented ${expr}')}
ParenExpr {
g.out.write_string('(')
g.gen_expr(expr.expr)
g.out.write_string(')')
}
FnCall {
g.out.write_string('${expr.name}()')
}
else {panic("Unimplemented expression")}
}
}