src/HOL/Import/importrecorder.ML
author bulwahn
Thu, 07 Jul 2011 23:33:14 +0200
changeset 43704 47b0be18ccbe
parent 32960 69916a850301
permissions -rw-r--r--
floor and ceiling definitions are not code equations -- this enables trivial evaluation of floor and ceiling
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
19064
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
     1
signature IMPORT_RECORDER =
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
     2
sig
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
     3
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
     4
    datatype deltastate = Consts of (string * typ * mixfix) list
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32740
diff changeset
     5
                        | Specification of (string * string * bool) list * term
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32740
diff changeset
     6
                        | Hol_mapping of string * string * string
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32740
diff changeset
     7
                        | Hol_pending of string * string * term
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32740
diff changeset
     8
                        | Hol_const_mapping of string * string * string
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32740
diff changeset
     9
                        | Hol_move of string * string
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32740
diff changeset
    10
                        | Defs of string * term
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32740
diff changeset
    11
                        | Hol_theorem of string * string * term
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32740
diff changeset
    12
                        | Typedef of string option * (string * string list * mixfix) * term * (string * string) option * term 
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32740
diff changeset
    13
                        | Hol_type_mapping of string * string * string
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32740
diff changeset
    14
                        | Indexed_theorem of int * term
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32740
diff changeset
    15
                        | Protect_varname of string * string
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32740
diff changeset
    16
                        | Dump of string
19064
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
    17
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
    18
    datatype history = History of history_entry list
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32740
diff changeset
    19
         and history_entry = ThmEntry of string*string*bool*history | DeltaEntry of deltastate list
19064
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
    20
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
    21
    val get_history : unit -> history
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
    22
    val set_history : history -> unit
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
    23
    val clear_history : unit -> unit
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32740
diff changeset
    24
                                      
19064
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
    25
    val start_replay_proof : string -> string -> unit
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
    26
    val stop_replay_proof : string -> string -> unit
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
    27
    val abort_replay_proof : string -> string -> unit
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
    28
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
    29
    val add_consts : (string * typ * mixfix) list -> unit
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
    30
    val add_specification : (string * string * bool) list -> thm -> unit
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
    31
    val add_hol_mapping : string -> string -> string -> unit
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
    32
    val add_hol_pending : string -> string -> thm -> unit
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
    33
    val add_hol_const_mapping : string -> string -> string -> unit
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
    34
    val add_hol_move : string -> string -> unit
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
    35
    val add_defs : string -> term -> unit
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
    36
    val add_hol_theorem : string -> string -> thm -> unit
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
    37
    val add_typedef :  string option -> string * string list * mixfix -> term -> (string * string) option -> thm -> unit
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
    38
    val add_hol_type_mapping : string -> string -> string -> unit
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
    39
    val add_indexed_theorem : int -> thm -> unit
19067
c0321d7d6b3d variable counter is now also cached
obua
parents: 19064
diff changeset
    40
    val protect_varname : string -> string -> unit
19068
04b302f2902d cache improvements
obua
parents: 19067
diff changeset
    41
    val add_dump : string -> unit
19064
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
    42
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
    43
    val set_skip_import_dir : string option -> unit
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
    44
    val get_skip_import_dir : unit -> string option
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
    45
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
    46
    val set_skip_import : bool -> unit
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
    47
    val get_skip_import : unit -> bool
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
    48
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
    49
    val save_history : string -> unit
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
    50
    val load_history : string -> unit
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
    51
end
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
    52
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
    53
structure ImportRecorder :> IMPORT_RECORDER  =
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
    54
struct
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
    55
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
    56
datatype deltastate = Consts of (string * typ * mixfix) list
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32740
diff changeset
    57
                    | Specification of (string * string * bool) list * term
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32740
diff changeset
    58
                    | Hol_mapping of string * string * string
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32740
diff changeset
    59
                    | Hol_pending of string * string * term
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32740
diff changeset
    60
                    | Hol_const_mapping of string * string * string
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32740
diff changeset
    61
                    | Hol_move of string * string
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32740
diff changeset
    62
                    | Defs of string * term
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32740
diff changeset
    63
                    | Hol_theorem of string * string * term
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32740
diff changeset
    64
                    | Typedef of string option * (string * string list * mixfix) * term * (string * string) option * term 
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32740
diff changeset
    65
                    | Hol_type_mapping of string * string * string
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32740
diff changeset
    66
                    | Indexed_theorem of int * term
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32740
diff changeset
    67
                    | Protect_varname of string * string
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32740
diff changeset
    68
                    | Dump of string
19064
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
    69
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
    70
datatype history_entry = StartReplay of string*string  
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32740
diff changeset
    71
                       | StopReplay of string*string
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32740
diff changeset
    72
                       | AbortReplay of string*string
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32740
diff changeset
    73
                       | Delta of deltastate list
19064
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
    74
32740
9dd0a2f83429 explicit indication of Unsynchronized.ref;
wenzelm
parents: 21858
diff changeset
    75
val history = Unsynchronized.ref ([]:history_entry list)
9dd0a2f83429 explicit indication of Unsynchronized.ref;
wenzelm
parents: 21858
diff changeset
    76
val history_dir = Unsynchronized.ref (SOME "")
9dd0a2f83429 explicit indication of Unsynchronized.ref;
wenzelm
parents: 21858
diff changeset
    77
val skip_imports = Unsynchronized.ref false
19064
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
    78
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
    79
fun set_skip_import b = skip_imports := b
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
    80
fun get_skip_import () = !skip_imports
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
    81
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
    82
fun clear_history () = history := []
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
    83
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
    84
fun add_delta d = history := (case !history of (Delta ds)::hs => (Delta (d::ds))::hs | hs => (Delta [d])::hs)
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
    85
fun add_replay r = history := (r :: (!history))
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
    86
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
    87
local 
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
    88
    open XMLConvOutput
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
    89
    val consts = list (triple string typ mixfix)
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
    90
    val specification = pair (list (triple string string bool)) term
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
    91
    val hol_mapping = triple string string string
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
    92
    val hol_pending = triple string string term
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
    93
    val hol_const_mapping = triple string string string
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
    94
    val hol_move = pair string string
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
    95
    val defs = pair string term
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
    96
    val hol_theorem = triple string string term
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
    97
    val typedef = quintuple (option string) (triple string (list string) mixfix) term (option (pair string string)) term
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
    98
    val hol_type_mapping = triple string string string
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
    99
    val indexed_theorem = pair int term
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   100
    val entry = pair string string
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   101
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   102
    fun delta (Consts args) = wrap "consts" consts args
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   103
      | delta (Specification args) = wrap "specification" specification args
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   104
      | delta (Hol_mapping args) = wrap "hol_mapping" hol_mapping args
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   105
      | delta (Hol_pending args) = wrap "hol_pending" hol_pending args
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   106
      | delta (Hol_const_mapping args) = wrap "hol_const_mapping" hol_const_mapping args
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   107
      | delta (Hol_move args) = wrap "hol_move" hol_move args
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   108
      | delta (Defs args) = wrap "defs" defs args
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   109
      | delta (Hol_theorem args) = wrap "hol_theorem" hol_theorem args
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   110
      | delta (Typedef args) = wrap "typedef" typedef args
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   111
      | delta (Hol_type_mapping args) = wrap "hol_type_mapping" hol_type_mapping args
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   112
      | delta (Indexed_theorem args) = wrap "indexed_theorem" indexed_theorem args
19067
c0321d7d6b3d variable counter is now also cached
obua
parents: 19064
diff changeset
   113
      | delta (Protect_varname args) = wrap "protect_varname" entry args
19068
04b302f2902d cache improvements
obua
parents: 19067
diff changeset
   114
      | delta (Dump args) = wrap "dump" string args
19064
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   115
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   116
    fun history_entry (StartReplay args) = wrap "startreplay" entry args
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   117
      | history_entry (StopReplay args) = wrap "stopreplay" entry args
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   118
      | history_entry (AbortReplay args) = wrap "abortreplay" entry args
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   119
      | history_entry (Delta args) = wrap "delta" (list delta) args
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   120
in
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   121
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   122
val xml_of_history = list history_entry
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   123
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   124
end
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   125
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   126
local 
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   127
    open XMLConvInput
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   128
    val consts = list (triple string typ mixfix)
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   129
    val specification = pair (list (triple string string bool)) term
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   130
    val hol_mapping = triple string string string
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   131
    val hol_pending = triple string string term
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   132
    val hol_const_mapping = triple string string string
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   133
    val hol_move = pair string string
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   134
    val defs = pair string term
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   135
    val hol_theorem = triple string string term
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   136
    val typedef = quintuple (option string) (triple string (list string) mixfix) term (option (pair string string)) term
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   137
    val hol_type_mapping = triple string string string
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   138
    val indexed_theorem = pair int term
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   139
    val entry = pair string string
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   140
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   141
    fun delta "consts" = unwrap Consts consts
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   142
      | delta "specification" = unwrap Specification specification 
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   143
      | delta "hol_mapping" = unwrap Hol_mapping hol_mapping 
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   144
      | delta "hol_pending" = unwrap Hol_pending hol_pending
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   145
      | delta "hol_const_mapping" = unwrap Hol_const_mapping hol_const_mapping
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   146
      | delta "hol_move" = unwrap Hol_move hol_move
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   147
      | delta "defs" = unwrap Defs defs
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   148
      | delta "hol_theorem" = unwrap Hol_theorem hol_theorem
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   149
      | delta "typedef" = unwrap Typedef typedef
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   150
      | delta "hol_type_mapping" = unwrap Hol_type_mapping hol_type_mapping
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   151
      | delta "indexed_theorem" = unwrap Indexed_theorem indexed_theorem
19067
c0321d7d6b3d variable counter is now also cached
obua
parents: 19064
diff changeset
   152
      | delta "protect_varname" = unwrap Protect_varname entry
19068
04b302f2902d cache improvements
obua
parents: 19067
diff changeset
   153
      | delta "dump" = unwrap Dump string
19064
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   154
      | delta _ = raise ParseException "delta"
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   155
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   156
    val delta = fn e => delta (name_of_wrap e) e
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   157
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   158
    fun history_entry "startreplay" = unwrap StartReplay entry 
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   159
      | history_entry "stopreplay" = unwrap StopReplay entry
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   160
      | history_entry "abortreplay" = unwrap AbortReplay entry
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   161
      | history_entry "delta" = unwrap Delta (list delta)
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   162
      | history_entry _ = raise ParseException "history_entry"
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   163
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   164
    val history_entry = fn e => history_entry (name_of_wrap e) e
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   165
in
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   166
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   167
val history_of_xml = list history_entry
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   168
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   169
end
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   170
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   171
fun start_replay_proof thyname thmname = add_replay (StartReplay (thyname, thmname))
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   172
fun stop_replay_proof thyname thmname = add_replay (StopReplay (thyname, thmname))
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   173
fun abort_replay_proof thyname thmname = add_replay (AbortReplay (thyname, thmname))
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   174
fun add_hol_theorem thyname thmname thm = add_delta (Hol_theorem (thyname, thmname, prop_of thm))
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   175
fun add_hol_mapping thyname thmname isaname = add_delta (Hol_mapping (thyname, thmname, isaname))
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   176
fun add_consts consts = add_delta (Consts consts)
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   177
fun add_typedef thmname_opt typ c absrep_opt th = add_delta (Typedef (thmname_opt, typ, c, absrep_opt, prop_of th))
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   178
fun add_defs thmname eq = add_delta (Defs (thmname, eq)) 
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   179
fun add_hol_const_mapping thyname constname fullcname = add_delta (Hol_const_mapping (thyname, constname, fullcname))
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   180
fun add_hol_move fullname moved_thmname = add_delta (Hol_move (fullname, moved_thmname))
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   181
fun add_hol_type_mapping thyname tycname fulltyname = add_delta (Hol_type_mapping (thyname, tycname, fulltyname))
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   182
fun add_hol_pending thyname thmname th = add_delta (Hol_pending (thyname, thmname, prop_of th))
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   183
fun add_specification names th = add_delta (Specification (names, prop_of th)) 
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   184
fun add_indexed_theorem i th = add_delta (Indexed_theorem (i, prop_of th))
19067
c0321d7d6b3d variable counter is now also cached
obua
parents: 19064
diff changeset
   185
fun protect_varname s t = add_delta (Protect_varname (s,t))
19068
04b302f2902d cache improvements
obua
parents: 19067
diff changeset
   186
fun add_dump s = add_delta (Dump s)
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32740
diff changeset
   187
                            
19064
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   188
fun set_skip_import_dir dir = (history_dir := dir)
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   189
fun get_skip_import_dir () = !history_dir
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   190
21858
05f57309170c avoid conflict with Alice keywords: renamed pack -> implode, unpack -> explode, any -> many, avoided assert;
wenzelm
parents: 19068
diff changeset
   191
fun get_filename thyname = Path.implode (Path.append (Path.explode (the (get_skip_import_dir ()))) (Path.explode (thyname^".history")))
19064
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   192
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   193
fun save_history thyname = 
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   194
    if get_skip_import () then
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32740
diff changeset
   195
        XMLConv.write_to_file xml_of_history (get_filename thyname) (!history)
19064
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   196
    else 
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32740
diff changeset
   197
        ()
19064
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   198
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   199
fun load_history thyname = 
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   200
    if get_skip_import () then
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32740
diff changeset
   201
        let 
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32740
diff changeset
   202
            val filename = get_filename thyname
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32740
diff changeset
   203
            val _ = writeln "load_history / before"
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32740
diff changeset
   204
            val _ = 
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32740
diff changeset
   205
                if File.exists (Path.explode filename) then                                     
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32740
diff changeset
   206
                    (history := XMLConv.read_from_file history_of_xml (get_filename thyname)) 
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32740
diff changeset
   207
                else
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32740
diff changeset
   208
                    clear_history ()
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32740
diff changeset
   209
            val _ = writeln "load_history / after"
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32740
diff changeset
   210
        in
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32740
diff changeset
   211
            ()
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32740
diff changeset
   212
        end
19064
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   213
    else
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32740
diff changeset
   214
        ()
19064
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   215
    
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   216
 
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   217
datatype history = History of history_entry list
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   218
     and history_entry = ThmEntry of string*string*bool*history | DeltaEntry of deltastate list
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   219
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   220
exception CONV 
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   221
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   222
fun conv_histories ((StartReplay (thyname, thmname))::rest) = 
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   223
    let
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32740
diff changeset
   224
        val (hs, rest) = conv_histories rest
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32740
diff changeset
   225
        fun continue thyname' thmname' aborted rest = 
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32740
diff changeset
   226
            if thyname = thyname' andalso thmname = thmname' then
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32740
diff changeset
   227
                let
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32740
diff changeset
   228
                    val (hs', rest) = conv_histories rest
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32740
diff changeset
   229
                in
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32740
diff changeset
   230
                    ((ThmEntry (thyname, thmname, aborted, History hs))::hs', rest)
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32740
diff changeset
   231
                end
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32740
diff changeset
   232
            else
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32740
diff changeset
   233
                raise CONV 
19064
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   234
    in
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32740
diff changeset
   235
        case rest of 
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32740
diff changeset
   236
            (StopReplay (thyname',thmname'))::rest =>
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32740
diff changeset
   237
            continue thyname' thmname' false rest
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32740
diff changeset
   238
          | (AbortReplay (thyname',thmname'))::rest =>
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32740
diff changeset
   239
            continue thyname' thmname' true rest
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32740
diff changeset
   240
          | [] => (hs, [])
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32740
diff changeset
   241
          | _ => raise CONV
19064
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   242
    end
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   243
  | conv_histories ((Delta ds)::rest) = (conv_histories rest) |>> (fn hs => (DeltaEntry (rev ds))::hs)  
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   244
  | conv_histories rest = ([], rest)
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   245
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   246
fun conv es = 
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   247
    let
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32740
diff changeset
   248
        val (h, rest) = conv_histories (rev es)
19064
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   249
    in
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32740
diff changeset
   250
        case rest of
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32740
diff changeset
   251
            [] => h
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 32740
diff changeset
   252
          | _ => raise CONV
19064
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   253
    end 
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   254
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   255
fun get_history () = History (conv (!history))
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   256
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   257
fun reconv (History hs) rs = fold reconv_entry hs rs
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   258
and reconv_entry (ThmEntry (thyname, thmname, aborted, h)) rs =
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   259
    ((if aborted then AbortReplay else StopReplay) (thyname, thmname)) :: (reconv h ((StartReplay (thyname, thmname))::rs))
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   260
  | reconv_entry (DeltaEntry ds) rs = (Delta (rev ds))::rs
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   261
    
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   262
fun set_history h = history := reconv h []
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   263
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   264
bf19cc5a7899 fixed bugs, added caching
obua
parents:
diff changeset
   265
end