Skip to content

Commit

Permalink
support for pretty printing of alias
Browse files Browse the repository at this point in the history
  • Loading branch information
artoy committed Aug 4, 2023
1 parent 06eb5da commit 1010212
Showing 1 changed file with 37 additions and 12 deletions.
49 changes: 37 additions & 12 deletions src/convMoCHi.ml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ module Mochi = struct
(** Direction of assignment generated by alias statements *)
type adist = Left | Right | None [@@deriving sexp]

(* TODO: Is it needed? *)
(** The value actually assigned by alias statements *)
type arhs =
| AVar of string
Expand Down Expand Up @@ -127,6 +128,38 @@ module Mochi = struct
| Ref (ot, _) -> pp_nondet_ot ot
| _ -> assert false

let rec pp_aexp = function
| AVarExp xs -> ps @@ String.concat " :: " xs
| ATupleLhsExp (xs, x, xi', ae, xs') ->
pl [
ps "let (";
ps @@ String.concat ", " xs;
pf ") = %s in" x;
nl;
pf "let %s = " xi';
pp_aexp ae;
ps " in";
ps "(";
ps @@ String.concat ", " xs';
ps ")";
]
| ATupleRhsExp (xs, x, ae) ->
pl [
ps "let (";
ps @@ String.concat ", " xs;
pf ") = %s in" x;
pp_aexp ae;
]
| AListExp (x, h, t, ae) ->
pl [
pf "match %s with" x;
nl;
pf "%s :: %s ->" h t;
nl;
pp_aexp ae;
ps " | _ -> assert false";
]

let rec pp_exp = function
| Unit -> ps "()"
| Fail -> ps "Fail"
Expand Down Expand Up @@ -161,19 +194,11 @@ module Mochi = struct
| Call (callee, arg_names) ->
let pp_callee = fn_to_mochi callee in
pf "(%s %s)" pp_callee @@ String.concat " " arg_names
| Alias (xd, xs, p1, p2, p3, e) ->
| Alias (x, ae) ->
pl
[
pf "let %s = %a in" xd (ul pl)
[
pf "let %a = %s in" (ul AstPrinter.pp_patt) p1 xd;
nl;
pf "let %a = %s in" (ul AstPrinter.pp_patt) p2 xs;
nl;
AstPrinter.pp_patt p3;
];
nl;
pp_exp e;
pf "let %s = " x;
pp_aexp ae;
]
| Cond (x, e1, e2) ->
pblock ~nl:false ~op:(pf "if %s = 0 then (" x) ~body:(pp_exp e1)
Expand All @@ -194,7 +219,7 @@ module Mochi = struct
pf " :: ";
pp_exp t;
]
(* It is not right. We have to use monad to use variables that is defined or updated in branch *)
(* TODO: It is not right. We have to use monad to use variables that is defined or updated in branch *)
| Match (x, e1, h, r, e2) ->
pl [
pf "match %s with " x;
Expand Down

0 comments on commit 1010212

Please sign in to comment.