compile basic function calls

This commit is contained in:
tali 2023-12-02 16:06:36 -05:00
parent 62cf27b0c7
commit ffbe99061f
1 changed files with 13 additions and 0 deletions

View File

@ -33,6 +33,19 @@ let compile modl =
emit (SLT (sp + 1, sp, ele));
emit (GET (sp + 1, sp));
Reg sp
| Ast.Call (Var name, args) -> (
match Env.find name env with
| exception Not_found -> Fmt.failwith "unbound: %S" name
| { self; elem } ->
List.iteri
(fun i arg ->
let sp = sp + i + 1 in
emit_mov sp (compile_exp env sp arg))
args;
let idx = Code.cst (Value.of_elem elem) in
emit_mov sp idx;
emit (CLL (self, sp, List.length args));
Reg sp)
| Ast.Binop (op, lhs, rhs) ->
let lhs = compile_exp env sp lhs in
emit_mov sp lhs;