File: states.ml

package info (click to toggle)
coq-doc 8.2pl1-1
  • links: PTS, VCS
  • area: non-free
  • in suites: squeeze
  • size: 19,240 kB
  • ctags: 22,737
  • sloc: ml: 132,933; ansic: 1,960; sh: 1,366; lisp: 456; makefile: 327
file content (44 lines) | stat: -rw-r--r-- 1,340 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
(************************************************************************)
(*  v      *   The Coq Proof Assistant  /  The Coq Development Team     *)
(* <O___,, * CNRS-Ecole Polytechnique-INRIA Futurs-Universite Paris Sud *)
(*   \VV/  **************************************************************)
(*    //   *      This file is distributed under the terms of the       *)
(*         *       GNU Lesser General Public License Version 2.1        *)
(************************************************************************)

(* $Id: states.ml 12080 2009-04-11 16:56:20Z herbelin $ *)

open System

type state = Lib.frozen * Summary.frozen

let freeze () =
  (Lib.freeze(), Summary.freeze_summaries())

let unfreeze (fl,fs) =
  Lib.unfreeze fl;
  Summary.unfreeze_summaries fs

let (extern_state,intern_state) =
  let (raw_extern, raw_intern) =
    extern_intern Coq_config.state_magic_number ".coq" in
  (fun s -> raw_extern s (freeze())),
  (fun s ->
    unfreeze (raw_intern (Library.get_load_paths ()) s);
    Library.overwrite_library_filenames s)

(* Rollback. *)

let with_heavy_rollback f x =
  let st = freeze () in
  try 
    f x
  with reraise ->
    (unfreeze st; raise reraise)

let with_state_protection f x =
  let st = freeze () in
  try 
    let a = f x in unfreeze st; a
  with reraise ->
    (unfreeze st; raise reraise)