summaryrefslogtreecommitdiff
path: root/library/states.ml
blob: 3bb37a4dc5531056bdbc546eb65ec584b96effad (plain)
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
(************************************************************************)
(*  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 6692 2005-02-06 13:03:51Z herbelin $ *)

open System

type state = Lib.frozen * Summary.frozen

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

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

let state_magic_number = 19764

let (extern_state,intern_state) =
  let (raw_extern, raw_intern) = extern_intern state_magic_number ".coq" in
  (fun s -> raw_extern s (get_state())),
  (fun s -> set_state (raw_intern (Library.get_load_paths ()) s))

(* Rollback. *)

let freeze = get_state
let unfreeze = set_state

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