From 24a0df63c1844c6f2c69f9644a3059d668fd1e6f Mon Sep 17 00:00:00 2001 From: Pierre-Marie Pédrot Date: Sat, 7 Jun 2014 00:28:29 +0200 Subject: Adding a new Control file centralizing the control options of Coq. --- lib/clib.mllib | 1 + lib/control.ml | 40 ++++++++++++++++++++++++++++++++++++++++ lib/control.mli | 26 ++++++++++++++++++++++++++ lib/util.ml | 6 ------ lib/util.mli | 6 ------ 5 files changed, 67 insertions(+), 12 deletions(-) create mode 100644 lib/control.ml create mode 100644 lib/control.mli (limited to 'lib') diff --git a/lib/clib.mllib b/lib/clib.mllib index 1dc540b9aa..cd8964f021 100644 --- a/lib/clib.mllib +++ b/lib/clib.mllib @@ -12,6 +12,7 @@ Option Store Exninfo Backtrace +Control IArray IStream Pp_control diff --git a/lib/control.ml b/lib/control.ml new file mode 100644 index 0000000000..9573614fd7 --- /dev/null +++ b/lib/control.ml @@ -0,0 +1,40 @@ +(************************************************************************) +(* v * The Coq Proof Assistant / The Coq Development Team *) +(* + let e = Backtrace.add_backtrace e in + restore_timeout (); + raise e + +type timeout = { timeout : 'a. int -> (unit -> 'a) -> exn -> 'a } + +let timeout_fun = ref { timeout = unix_timeout } + +let set_timeout f = timeout_fun := f + +let timeout n f e = !timeout_fun.timeout n f e diff --git a/lib/control.mli b/lib/control.mli new file mode 100644 index 0000000000..36c8349152 --- /dev/null +++ b/lib/control.mli @@ -0,0 +1,26 @@ +(************************************************************************) +(* v * The Coq Proof Assistant / The Coq Development Team *) +(* unit +(** Use this function as a potential yield function. If {!interrupt} has been + set, il will raise [Sys.Break]. *) + +val timeout : int -> (unit -> 'a) -> exn -> 'a +(** [timeout n f e] tries to compute [f], and if it fails to do so before [n] + seconds, it raises [e] instead. *) + +type timeout = { timeout : 'a. int -> (unit -> 'a) -> exn -> 'a } + +val set_timeout : timeout -> unit +(** Set a particular timeout function. *) diff --git a/lib/util.ml b/lib/util.ml index 9ade75147b..16b5f4615f 100644 --- a/lib/util.ml +++ b/lib/util.ml @@ -124,9 +124,3 @@ let delayed_force f = f () type ('a, 'b) union = ('a, 'b) CSig.union = Inl of 'a | Inr of 'b type 'a until = 'a CSig.until = Stop of 'a | Cont of 'a - -(*s interruption *) - -let interrupt = ref false -let check_for_interrupt () = - if !interrupt then begin interrupt := false; raise Sys.Break end diff --git a/lib/util.mli b/lib/util.mli index d3e3432a33..fd766a30f9 100644 --- a/lib/util.mli +++ b/lib/util.mli @@ -103,9 +103,3 @@ type ('a, 'b) union = ('a, 'b) CSig.union = Inl of 'a | Inr of 'b type 'a until = 'a CSig.until = Stop of 'a | Cont of 'a (** Used for browsable-until structures. *) -(** {6 ... } *) -(** Coq interruption: set the following boolean reference to interrupt Coq - (it eventually raises [Break], simulating a Ctrl-C) *) - -val interrupt : bool ref -val check_for_interrupt : unit -> unit -- cgit v1.2.3