Skip to content

Commit

Permalink
insert "int list" to argument automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
artoy committed Sep 4, 2023
1 parent 4c163cd commit 73dd5b0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
15 changes: 12 additions & 3 deletions src/convMoCHi.ml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ module Mochi = struct
| Match of string * exp * string * string * exp
[@@deriving sexp]

type fn = { name : string; args : string list; body : exp } [@@deriving sexp]
type fn = { name : string; args : (string * OwnershipInference.otype) list; body : exp } [@@deriving sexp]
type prog = fn list * exp [@@deriving sexp]

let builtin =
Expand Down Expand Up @@ -237,13 +237,17 @@ module Mochi = struct
ps " ) ) ";
]

let pp_arg = function
| (arg, OwnershipInference.IntList _) -> Printf.sprintf "(%s: int list)" arg
| (arg, _) -> arg

let pp_fn ff { name; args; body } ~first =
pl
[
pblock ~nl:true
~op:
(pf "%s %s %s =" (if first then "let rec" else "and") name
@@ String.concat " " args)
@@ String.concat " " @@ List.map pp_arg args)
~body:(pp_exp body) ~close:null;
]
ff
Expand Down Expand Up @@ -494,7 +498,12 @@ let rec exp_to_mochi (ri : OwnershipInference.Result.t)

let fn_to_mochi (ri : OwnershipInference.Result.t) (ro : (int * float) list)
{ name; args; body } =
Mochi.{ name; args; body = exp_to_mochi ri ro args body }
let rec zip_list l1 l2 acc =
match l1, l2 with
h1 :: t1, h2 :: t2 -> zip_list t1 t2 ((h1, h2) :: acc)
| _ -> acc
in
Mochi.{ name; args = zip_list args (StringMap.find name ri.theta).arg_types []; body = exp_to_mochi ri ro args body }

let prog_to_mochi (ri : OwnershipInference.Result.t) (ro : (int * float) list)
(fns, exp) =
Expand Down
2 changes: 1 addition & 1 deletion src/test/list/length.imp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ len(l) {
match l with
Nil -> return 0
| Cons h t -> {
let t_der = *t in
let t_deref = *t in
let n = 1 + len(t_deref) in {
alias(t_deref = *t);
alias(l.Cons.2 = t);
Expand Down

0 comments on commit 73dd5b0

Please sign in to comment.