1
0
Fork 0

Add function calls to IR Generator

This commit is contained in:
Vili Sinervä 2025-02-05 23:28:00 +02:00
parent 2cf26ec39d
commit b3a8188dfe
No known key found for this signature in database
GPG key ID: DF8FEAF54EFAC996
3 changed files with 30 additions and 3 deletions

View file

@ -220,7 +220,31 @@ fn visit_ast_node<'source>(
symbols.get("unit").clone()
}
FunCall(_, _) => todo!(),
FunCall(name, expressions) => {
let fn_var = symbols.get(name).clone();
let Type::Func(_, result_type) = types.get(&fn_var).unwrap().clone() else {
panic!("Function call does not have entry in types table!");
};
let mut args = Vec::new();
for expression in expressions {
args.push(visit_ast_node(
expression,
types,
symbols,
instructions,
labels,
));
}
let result_var = add_var(&result_type, types);
instructions.push(IrInstruction::new(
ast.loc,
Call(fn_var, args, result_var.clone()),
));
result_var
}
Block(expressions) => {
let mut result_var = symbols.get("unit").clone();
for expression in expressions {