mpri-funcprog-project/src/prettify/PrettyTail.ml

32 lines
1,017 B
OCaml

module S = Tail
open PrettyCommon
let rec fmt_block fmt (S.Lam (self, vars, body)) =
Format.fprintf fmt "λ%a(%a) ·@ %a"
fmt_self self
fmt_vars vars
fmt_term body
and fmt_term fmt (t: S.term) = match t with
| S.Exit ->
Format.fprintf fmt "Exit";
| S.TailCall(fct, args) ->
Format.fprintf fmt "Call %a %a" fmt_val fct fmt_vals args
| S.Print (value, next) ->
Format.fprintf fmt "Print %a;@ %a" fmt_val value fmt_term next
| S.LetVal (var, value, next) ->
Format.fprintf fmt "@[<v 4>let %a = %a@] in@ %a"
fmt_var var fmt_val value fmt_term next
| S.LetBlo (var, block, next) ->
Format.fprintf fmt "@[<v 4>let %a = %a@] in@ %a"
fmt_var var fmt_block block fmt_term next
| S.IfZero (cond, tIf, tElse) ->
Format.fprintf fmt "@[<v 4>ifzero %a then@ %a@]@ @[<v 4>else@ %a@]@ "
fmt_val cond
fmt_term tIf
fmt_term tElse
let show term =
Format.asprintf "@[<v 0>%a@]" fmt_term term