codegen method arguments

This commit is contained in:
tali 2023-12-13 17:16:57 -05:00
parent c61c1d4e25
commit be83ca2177
3 changed files with 11 additions and 12 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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