Skip to content

Commit

Permalink
Merge pull request #6 from shapespeare/feat/misc
Browse files Browse the repository at this point in the history
Implement call
  • Loading branch information
yhs0602 authored Jun 1, 2024
2 parents 365eceb + 19426d9 commit 15e1926
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lib/compile.ml
Original file line number Diff line number Diff line change
Expand Up @@ -187,4 +187,19 @@ 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 { params; body; _ } = f in
let param_det_pairs = List.zip_exn params det_exps in
let sub_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
(g @+ g_body, det_exp_body)
| _ -> failwith "Not implemented"

0 comments on commit 15e1926

Please sign in to comment.