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