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