codegen method arguments
This commit is contained in:
parent
c61c1d4e25
commit
be83ca2177
|
@ -5,7 +5,7 @@ let () =
|
|||
Logs.set_level (Some Logs.Debug);
|
||||
|
||||
try
|
||||
let ast = parse "fun f() 3 val x = f() + 1" in
|
||||
let ast = parse "fun twice(x) x*2 val r = twice(5)" in
|
||||
Logs.debug (fun m -> m "[AST] %a" Ast.pp_modl ast);
|
||||
let prog = compile ast in
|
||||
Logs.debug (fun m -> Code.dump (m "[BC] %s") prog.main);
|
||||
|
|
|
@ -134,12 +134,12 @@ let rec compile_lambda (lam : Ir.lambda) =
|
|||
in
|
||||
|
||||
set_reg lam.self (Code.R 0);
|
||||
if lam.args <> [] then
|
||||
failwith "Bcc.compile: TODO(lambda.args)";
|
||||
(* if lam.clos <> [] then *)
|
||||
(* failwith "Bcc.compile: TODO(lambda.clos)"; *)
|
||||
|
||||
let sp = Code.R 1 in
|
||||
let sp =
|
||||
List.fold_left
|
||||
(fun sp arg -> set_reg arg sp; suc sp)
|
||||
(Code.R 1)
|
||||
lam.args
|
||||
in
|
||||
let rv = emit_exp sp lam.body in
|
||||
emit (RET rv);
|
||||
|
||||
|
|
|
@ -218,12 +218,11 @@ let lower ~lib (modl : Ast.modl) =
|
|||
|
||||
and compile_lambda env args body =
|
||||
let self = new_id () in
|
||||
if args <> [] then
|
||||
failwith "Ir.compile_lambda: TODO(args non-empty)";
|
||||
(* FIXME: capture environment *)
|
||||
let env = ignore env; Env.Empty in
|
||||
let args = [] in
|
||||
let args = List.map (fun a -> a, new_id ()) args in
|
||||
(* FIXME: environment *)
|
||||
let env = ignore env; Env.Args args in
|
||||
let body = lower_exp env body in
|
||||
let args = List.map snd args in
|
||||
{ self; args; body }
|
||||
in
|
||||
|
||||
|
|
Loading…
Reference in New Issue