From 7a2ceae178d182692e57cc4e1d042f10b64037e2 Mon Sep 17 00:00:00 2001 From: yhs0602 Date: Sat, 1 Jun 2024 20:09:21 +0900 Subject: [PATCH 1/3] :sparkles: Function call --- lib/compile.ml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/compile.ml b/lib/compile.ml index e945a7c..4204a97 100644 --- a/lib/compile.ml +++ b/lib/compile.ml @@ -155,4 +155,15 @@ let rec compile (env : Env.t) (pred : Pred.t) (exp : Exp.t) : let g3, det_exp_alt = compile env pred_false e_alt in let g = g1 @+ g2 @+ g3 in (g, Det_exp.If (det_exp_pred, det_exp_con, det_exp_alt)) + | Call (c, params) -> + let f = Env.find_exn env ~name:c in + let g, det_exps = List.fold_map params ~init:Graph.empty ~f:(fun g e -> + let g', de = compile env pred e in + (g @+ g', de)) in + let body = f.body in + let param_det_pairs = List.zip_exn f.params det_exps in + let sub_body = List.fold_left param_det_pairs ~init:body ~f:(fun acc (param_name, det_exp) -> + sub acc param_name det_exp) in + let g_body, det_exp_body = compile env pred sub_body in + ( g @+ g_body, det_exp_body) | _ -> failwith "Not implemented" From f0e8c83d555fd21469b8dd1657aa44cdd3b8278c Mon Sep 17 00:00:00 2001 From: yhs0602 Date: Sat, 1 Jun 2024 20:09:46 +0900 Subject: [PATCH 2/3] :art: Dune fmt --- lib/compile.ml | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/compile.ml b/lib/compile.ml index 4204a97..eaf168f 100644 --- a/lib/compile.ml +++ b/lib/compile.ml @@ -157,13 +157,17 @@ let rec compile (env : Env.t) (pred : Pred.t) (exp : Exp.t) : (g, Det_exp.If (det_exp_pred, det_exp_con, det_exp_alt)) | Call (c, params) -> let f = Env.find_exn env ~name:c in - let g, det_exps = List.fold_map params ~init:Graph.empty ~f:(fun g e -> - let g', de = compile env pred e in - (g @+ g', de)) in + let g, det_exps = + List.fold_map params ~init:Graph.empty ~f:(fun g e -> + let g', de = compile env pred e in + (g @+ g', de)) + in let body = f.body in let param_det_pairs = List.zip_exn f.params det_exps in - let sub_body = List.fold_left param_det_pairs ~init:body ~f:(fun acc (param_name, det_exp) -> - sub acc param_name det_exp) in + let sub_body = + List.fold_left param_det_pairs ~init:body + ~f:(fun acc (param_name, det_exp) -> sub acc param_name det_exp) + in let g_body, det_exp_body = compile env pred sub_body in - ( g @+ g_body, det_exp_body) + (g @+ g_body, det_exp_body) | _ -> failwith "Not implemented" From 19426d94da3c025a230a826bb7a4d33e1fe781e7 Mon Sep 17 00:00:00 2001 From: yhs0602 Date: Sat, 1 Jun 2024 20:18:52 +0900 Subject: [PATCH 3/3] :recycle: Ocaml --- lib/compile.ml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/compile.ml b/lib/compile.ml index eaf168f..658e97c 100644 --- a/lib/compile.ml +++ b/lib/compile.ml @@ -162,10 +162,10 @@ let rec compile (env : Env.t) (pred : Pred.t) (exp : Exp.t) : let g', de = compile env pred e in (g @+ g', de)) in - let body = f.body in - let param_det_pairs = List.zip_exn f.params det_exps in + let { params; body; _ } = f in + let param_det_pairs = List.zip_exn params det_exps in let sub_body = - List.fold_left param_det_pairs ~init:body + List.fold param_det_pairs ~init:body ~f:(fun acc (param_name, det_exp) -> sub acc param_name det_exp) in let g_body, det_exp_body = compile env pred sub_body in