Skip to content

Commit 9fd8b13

Browse files
authored
Put safety thunking in auxiliary function (#22)
2 parents 8e17108 + ef509c4 commit 9fd8b13

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/tac2compile.ml

+7-2
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,11 @@ let pp_valexpr_of_bound pp = function
757757
| Valexpr -> pp
758758
| Function {arity} -> pp_mk_closure_val arity pp
759759

760+
(* cf https://github.com/SkySkimmer/coq-ltac2-compiler/issues/17 *)
761+
let add_safety_thunk pp =
762+
str "PV.tclUNIT () >>= fun () ->" ++ spc()
763+
++ pp
764+
760765
(* produce a ocaml term of type valexpr *)
761766
let rec pp_nontac_expr = function
762767
| Atm (AtmInt i) | Ctor (i, []) -> str "(ValInt " ++ (if i >= 0 then int i else surround (int i)) ++ str")"
@@ -768,7 +773,7 @@ let rec pp_nontac_expr = function
768773
pp_mk_closure_val (List.length nas)
769774
(surround
770775
(h (str "fun" ++ pp_binders nas ++ str " ->") ++ spc() ++
771-
str "PV.tclUNIT () >>= fun () ->" ++ spc() ++ pp_expr e))
776+
add_safety_thunk (pp_expr e)))
772777
| Ctor (i, es) -> str "(ValBlk (" ++ int i ++ str ", [|" ++ pp_val_list es ++ str "|]))"
773778
| PrjV (e, i) ->
774779
surround
@@ -943,7 +948,7 @@ let pp_one_constant (kn, knid, na, bnd, e) =
943948
| Fun (nas, e) ->
944949
hv 2
945950
(str "let " ++ h (str na ++ pp_binders nas) ++ str " =" ++ spc() ++
946-
str "PV.tclUNIT () >>= fun () ->" ++ spc() ++ pp_expr e) ++ fnl() ++ fnl()
951+
add_safety_thunk (pp_expr e)) ++ fnl() ++ fnl()
947952
| _ -> hv 2 (str "let " ++ str na ++ str " =" ++ spc() ++ pp_nontac_expr e) ++ fnl() ++ fnl()
948953
in
949954
let pp_set_compiled =

0 commit comments

Comments
 (0)