compile basic function calls
This commit is contained in:
parent
62cf27b0c7
commit
ffbe99061f
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue