author | wenzelm |
Mon, 05 Sep 2005 17:38:18 +0200 | |
changeset 17261 | 193b84a70ca4 |
parent 16424 | 18a07ad8fea8 |
child 17322 | 781abf7011e6 |
permissions | -rw-r--r-- |
14620
1be590fd2422
Minor cleanup of headers and some speedup of the HOL4 import.
skalberg
parents:
14518
diff
changeset
|
1 |
(* Title: HOL/Import/hol4rews.ML |
1be590fd2422
Minor cleanup of headers and some speedup of the HOL4 import.
skalberg
parents:
14518
diff
changeset
|
2 |
ID: $Id$ |
1be590fd2422
Minor cleanup of headers and some speedup of the HOL4 import.
skalberg
parents:
14518
diff
changeset
|
3 |
Author: Sebastian Skalberg (TU Muenchen) |
1be590fd2422
Minor cleanup of headers and some speedup of the HOL4 import.
skalberg
parents:
14518
diff
changeset
|
4 |
*) |
1be590fd2422
Minor cleanup of headers and some speedup of the HOL4 import.
skalberg
parents:
14518
diff
changeset
|
5 |
|
14516 | 6 |
structure StringPair = TableFun(type key = string * string val ord = prod_ord string_ord string_ord); |
7 |
||
8 |
type holthm = (term * term) list * thm |
|
9 |
||
10 |
datatype ImportStatus = |
|
11 |
NoImport |
|
12 |
| Generating of string |
|
13 |
| Replaying of string |
|
14 |
||
15 |
structure HOL4DefThyArgs: THEORY_DATA_ARGS = |
|
16 |
struct |
|
17 |
val name = "HOL4/import_status" |
|
18 |
type T = ImportStatus |
|
19 |
val empty = NoImport |
|
20 |
val copy = I |
|
16424 | 21 |
val extend = I |
22 |
fun merge _ (NoImport,NoImport) = NoImport |
|
23 |
| merge _ _ = (warning "Import status set during merge"; NoImport) |
|
14516 | 24 |
fun print sg import_status = |
25 |
Pretty.writeln (Pretty.str (case import_status of NoImport => "No current import" | Generating thyname => ("Generating " ^ thyname) | Replaying thyname => ("Replaying " ^ thyname))) |
|
26 |
end; |
|
27 |
||
28 |
structure HOL4DefThy = TheoryDataFun(HOL4DefThyArgs); |
|
29 |
||
30 |
structure ImportSegmentArgs: THEORY_DATA_ARGS = |
|
31 |
struct |
|
14620
1be590fd2422
Minor cleanup of headers and some speedup of the HOL4 import.
skalberg
parents:
14518
diff
changeset
|
32 |
val name = "HOL4/import_segment" |
14516 | 33 |
type T = string |
34 |
val empty = "" |
|
35 |
val copy = I |
|
16424 | 36 |
val extend = I |
37 |
fun merge _ ("",arg) = arg |
|
38 |
| merge _ (arg,"") = arg |
|
39 |
| merge _ (s1,s2) = |
|
14516 | 40 |
if s1 = s2 |
41 |
then s1 |
|
42 |
else error "Trying to merge two different import segments" |
|
43 |
fun print sg import_segment = |
|
44 |
Pretty.writeln (Pretty.str ("Import segment: " ^ import_segment)) |
|
45 |
end; |
|
46 |
||
47 |
structure ImportSegment = TheoryDataFun(ImportSegmentArgs); |
|
48 |
||
49 |
val get_import_segment = ImportSegment.get |
|
50 |
val set_import_segment = ImportSegment.put |
|
51 |
||
52 |
structure HOL4UNamesArgs: THEORY_DATA_ARGS = |
|
53 |
struct |
|
54 |
val name = "HOL4/used_names" |
|
55 |
type T = string list |
|
56 |
val empty = [] |
|
57 |
val copy = I |
|
16424 | 58 |
val extend = I |
59 |
fun merge _ ([],[]) = [] |
|
60 |
| merge _ _ = error "Used names not empty during merge" |
|
14516 | 61 |
fun print sg used_names = |
62 |
Pretty.writeln (Pretty.str "Printing of HOL4/used_names Not implemented") |
|
63 |
end; |
|
64 |
||
65 |
structure HOL4UNames = TheoryDataFun(HOL4UNamesArgs); |
|
66 |
||
67 |
structure HOL4DumpArgs: THEORY_DATA_ARGS = |
|
68 |
struct |
|
69 |
val name = "HOL4/dump_data" |
|
70 |
type T = string * string * string list |
|
71 |
val empty = ("","",[]) |
|
72 |
val copy = I |
|
16424 | 73 |
val extend = I |
74 |
fun merge _ (("","",[]),("","",[])) = ("","",[]) |
|
75 |
| merge _ _ = error "Dump data not empty during merge" |
|
14516 | 76 |
fun print sg dump_data = |
77 |
Pretty.writeln (Pretty.str "Printing of HOL4/dump_data Not implemented") |
|
78 |
end; |
|
79 |
||
80 |
structure HOL4Dump = TheoryDataFun(HOL4DumpArgs); |
|
81 |
||
82 |
structure HOL4MovesArgs: THEORY_DATA_ARGS = |
|
83 |
struct |
|
84 |
val name = "HOL4/moves" |
|
85 |
type T = string Symtab.table |
|
86 |
val empty = Symtab.empty |
|
87 |
val copy = I |
|
16424 | 88 |
val extend = I |
89 |
fun merge _ : T * T -> T = Symtab.merge (K true) |
|
14516 | 90 |
fun print sg tab = |
91 |
Pretty.writeln (Pretty.big_list "HOL4 moves:" |
|
92 |
(Symtab.foldl (fn (xl,(bef,aft)) => (Pretty.str (bef ^ " --> " ^ aft)::xl)) ([],tab))) |
|
93 |
end; |
|
94 |
||
95 |
structure HOL4Moves = TheoryDataFun(HOL4MovesArgs); |
|
96 |
||
97 |
structure HOL4ImportsArgs: THEORY_DATA_ARGS = |
|
98 |
struct |
|
99 |
val name = "HOL4/imports" |
|
100 |
type T = string Symtab.table |
|
101 |
val empty = Symtab.empty |
|
102 |
val copy = I |
|
16424 | 103 |
val extend = I |
104 |
fun merge _ : T * T -> T = Symtab.merge (K true) |
|
14516 | 105 |
fun print sg tab = |
106 |
Pretty.writeln (Pretty.big_list "HOL4 imports:" |
|
107 |
(Symtab.foldl (fn (xl,(thyname,segname)) => (Pretty.str (thyname ^ " imported from segment " ^ segname)::xl)) ([],tab))) |
|
108 |
end; |
|
109 |
||
110 |
structure HOL4Imports = TheoryDataFun(HOL4ImportsArgs); |
|
111 |
||
112 |
fun get_segment2 thyname thy = |
|
17261 | 113 |
Symtab.curried_lookup (HOL4Imports.get thy) thyname |
14516 | 114 |
|
115 |
fun set_segment thyname segname thy = |
|
116 |
let |
|
117 |
val imps = HOL4Imports.get thy |
|
17261 | 118 |
val imps' = Symtab.curried_update_new (thyname,segname) imps |
14516 | 119 |
in |
120 |
HOL4Imports.put imps' thy |
|
121 |
end |
|
122 |
||
123 |
structure HOL4CMovesArgs: THEORY_DATA_ARGS = |
|
124 |
struct |
|
125 |
val name = "HOL4/constant_moves" |
|
126 |
type T = string Symtab.table |
|
127 |
val empty = Symtab.empty |
|
128 |
val copy = I |
|
16424 | 129 |
val extend = I |
130 |
fun merge _ : T * T -> T = Symtab.merge (K true) |
|
14516 | 131 |
fun print sg tab = |
132 |
Pretty.writeln (Pretty.big_list "HOL4 constant moves:" |
|
133 |
(Symtab.foldl (fn (xl,(bef,aft)) => (Pretty.str (bef ^ " --> " ^ aft)::xl)) ([],tab))) |
|
134 |
end; |
|
135 |
||
136 |
structure HOL4CMoves = TheoryDataFun(HOL4CMovesArgs); |
|
137 |
||
138 |
structure HOL4MapsArgs: THEORY_DATA_ARGS = |
|
139 |
struct |
|
140 |
val name = "HOL4/mappings" |
|
141 |
type T = (string option) StringPair.table |
|
142 |
val empty = StringPair.empty |
|
143 |
val copy = I |
|
16424 | 144 |
val extend = I |
145 |
fun merge _ : T * T -> T = StringPair.merge (K true) |
|
14516 | 146 |
fun print sg tab = |
147 |
Pretty.writeln (Pretty.big_list "HOL4 mappings:" |
|
15531 | 148 |
(StringPair.foldl (fn (xl,((bthy,bthm),isathm)) => (Pretty.str (bthy ^ "." ^ bthm ^ (case isathm of SOME th => " --> " ^ th | NONE => "IGNORED"))::xl)) ([],tab))) |
14516 | 149 |
end; |
150 |
||
151 |
structure HOL4Maps = TheoryDataFun(HOL4MapsArgs); |
|
152 |
||
153 |
structure HOL4ThmsArgs: THEORY_DATA_ARGS = |
|
154 |
struct |
|
155 |
val name = "HOL4/theorems" |
|
156 |
type T = holthm StringPair.table |
|
157 |
val empty = StringPair.empty |
|
158 |
val copy = I |
|
16424 | 159 |
val extend = I |
160 |
fun merge _ : T * T -> T = StringPair.merge (K true) |
|
14516 | 161 |
fun print sg tab = |
162 |
Pretty.writeln (Pretty.big_list "HOL4 mappings:" |
|
163 |
(StringPair.foldl (fn (xl,((bthy,bthm),(_,thm))) => (Pretty.str (bthy ^ "." ^ bthm ^ ":")::(Display.pretty_thm thm)::xl)) ([],tab))) |
|
164 |
end; |
|
165 |
||
166 |
structure HOL4Thms = TheoryDataFun(HOL4ThmsArgs); |
|
167 |
||
168 |
structure HOL4ConstMapsArgs: THEORY_DATA_ARGS = |
|
169 |
struct |
|
170 |
val name = "HOL4/constmappings" |
|
171 |
type T = (bool * string * typ option) StringPair.table |
|
172 |
val empty = StringPair.empty |
|
173 |
val copy = I |
|
16424 | 174 |
val extend = I |
175 |
fun merge _ : T * T -> T = StringPair.merge (K true) |
|
14516 | 176 |
fun print sg tab = |
177 |
Pretty.writeln (Pretty.big_list "HOL4 constant mappings:" |
|
178 |
(StringPair.foldl (fn (xl,((bthy,bconst),(internal,isaconst,_))) => (Pretty.str (bthy ^ "." ^ bconst ^ " --> " ^ isaconst ^ (if internal then " (*)" else ""))::xl)) ([],tab))) |
|
179 |
end; |
|
180 |
||
181 |
structure HOL4ConstMaps = TheoryDataFun(HOL4ConstMapsArgs); |
|
182 |
||
183 |
structure HOL4RenameArgs: THEORY_DATA_ARGS = |
|
184 |
struct |
|
185 |
val name = "HOL4/renamings" |
|
186 |
type T = string StringPair.table |
|
187 |
val empty = StringPair.empty |
|
188 |
val copy = I |
|
16424 | 189 |
val extend = I |
190 |
fun merge _ : T * T -> T = StringPair.merge (K true) |
|
14516 | 191 |
fun print sg tab = |
192 |
Pretty.writeln (Pretty.big_list "HOL4 constant renamings:" |
|
193 |
(StringPair.foldl (fn (xl,((bthy,bconst),newname)) => (Pretty.str (bthy ^ "." ^ bconst ^ " --> " ^ newname)::xl)) ([],tab))) |
|
194 |
end; |
|
195 |
||
196 |
structure HOL4Rename = TheoryDataFun(HOL4RenameArgs); |
|
197 |
||
198 |
structure HOL4DefMapsArgs: THEORY_DATA_ARGS = |
|
199 |
struct |
|
200 |
val name = "HOL4/def_maps" |
|
201 |
type T = string StringPair.table |
|
202 |
val empty = StringPair.empty |
|
203 |
val copy = I |
|
16424 | 204 |
val extend = I |
205 |
fun merge _ : T * T -> T = StringPair.merge (K true) |
|
14516 | 206 |
fun print sg tab = |
207 |
Pretty.writeln (Pretty.big_list "HOL4 constant definitions:" |
|
208 |
(StringPair.foldl (fn (xl,((bthy,bconst),newname)) => (Pretty.str (bthy ^ "." ^ bconst ^ ": " ^ newname)::xl)) ([],tab))) |
|
209 |
end; |
|
210 |
||
211 |
structure HOL4DefMaps = TheoryDataFun(HOL4DefMapsArgs); |
|
212 |
||
213 |
structure HOL4TypeMapsArgs: THEORY_DATA_ARGS = |
|
214 |
struct |
|
215 |
val name = "HOL4/typemappings" |
|
216 |
type T = (bool * string) StringPair.table |
|
217 |
val empty = StringPair.empty |
|
218 |
val copy = I |
|
16424 | 219 |
val extend = I |
220 |
fun merge _ : T * T -> T = StringPair.merge (K true) |
|
14516 | 221 |
fun print sg tab = |
222 |
Pretty.writeln (Pretty.big_list "HOL4 type mappings:" |
|
223 |
(StringPair.foldl (fn (xl,((bthy,bconst),(internal,isaconst))) => (Pretty.str (bthy ^ "." ^ bconst ^ " --> " ^ isaconst ^ (if internal then " (*)" else ""))::xl)) ([],tab))) |
|
224 |
end; |
|
225 |
||
226 |
structure HOL4TypeMaps = TheoryDataFun(HOL4TypeMapsArgs); |
|
227 |
||
228 |
structure HOL4PendingArgs: THEORY_DATA_ARGS = |
|
229 |
struct |
|
230 |
val name = "HOL4/pending" |
|
231 |
type T = ((term * term) list * thm) StringPair.table |
|
232 |
val empty = StringPair.empty |
|
233 |
val copy = I |
|
16424 | 234 |
val extend = I |
235 |
fun merge _ : T * T -> T = StringPair.merge (K true) |
|
14516 | 236 |
fun print sg tab = |
237 |
Pretty.writeln (Pretty.big_list "HOL4 pending theorems:" |
|
238 |
(StringPair.foldl (fn (xl,((bthy,bthm),(_,th))) => (Pretty.chunks [Pretty.str (bthy ^ "." ^ bthm ^ ":"),Display.pretty_thm th]::xl)) ([],tab))) |
|
239 |
end; |
|
240 |
||
241 |
structure HOL4Pending = TheoryDataFun(HOL4PendingArgs); |
|
242 |
||
243 |
structure HOL4RewritesArgs: THEORY_DATA_ARGS = |
|
244 |
struct |
|
245 |
val name = "HOL4/rewrites" |
|
246 |
type T = thm list |
|
247 |
val empty = [] |
|
248 |
val copy = I |
|
16424 | 249 |
val extend = I |
250 |
fun merge _ = Library.gen_union Thm.eq_thm |
|
14516 | 251 |
fun print sg thms = |
252 |
Pretty.writeln (Pretty.big_list "HOL4 rewrite rules:" |
|
253 |
(map Display.pretty_thm thms)) |
|
254 |
end; |
|
255 |
||
256 |
structure HOL4Rewrites = TheoryDataFun(HOL4RewritesArgs); |
|
257 |
||
258 |
val hol4_debug = ref false |
|
259 |
fun message s = if !hol4_debug then writeln s else () |
|
260 |
||
261 |
fun add_hol4_rewrite (thy,th) = |
|
262 |
let |
|
263 |
val _ = message "Adding HOL4 rewrite" |
|
264 |
val th1 = th RS eq_reflection |
|
265 |
val current_rews = HOL4Rewrites.get thy |
|
266 |
val new_rews = gen_ins Thm.eq_thm (th1,current_rews) |
|
267 |
val updated_thy = HOL4Rewrites.put new_rews thy |
|
268 |
in |
|
269 |
(updated_thy,th1) |
|
270 |
end; |
|
271 |
||
272 |
fun ignore_hol4 bthy bthm thy = |
|
273 |
let |
|
274 |
val _ = message ("Ignoring " ^ bthy ^ "." ^ bthm) |
|
275 |
val curmaps = HOL4Maps.get thy |
|
15531 | 276 |
val newmaps = StringPair.update_new(((bthy,bthm),NONE),curmaps) |
14516 | 277 |
val upd_thy = HOL4Maps.put newmaps thy |
278 |
in |
|
279 |
upd_thy |
|
280 |
end |
|
281 |
||
282 |
val opt_get_output_thy = #2 o HOL4Dump.get |
|
283 |
||
284 |
fun get_output_thy thy = |
|
285 |
case #2 (HOL4Dump.get thy) of |
|
286 |
"" => error "No theory file being output" |
|
287 |
| thyname => thyname |
|
288 |
||
289 |
val get_output_dir = #1 o HOL4Dump.get |
|
290 |
||
291 |
fun add_hol4_move bef aft thy = |
|
292 |
let |
|
293 |
val curmoves = HOL4Moves.get thy |
|
17261 | 294 |
val newmoves = Symtab.curried_update_new (bef, aft) curmoves |
14516 | 295 |
in |
296 |
HOL4Moves.put newmoves thy |
|
297 |
end |
|
298 |
||
299 |
fun get_hol4_move bef thy = |
|
17261 | 300 |
Symtab.curried_lookup (HOL4Moves.get thy) bef |
14516 | 301 |
|
302 |
fun follow_name thmname thy = |
|
303 |
let |
|
304 |
val moves = HOL4Moves.get thy |
|
305 |
fun F thmname = |
|
17261 | 306 |
case Symtab.curried_lookup moves thmname of |
15531 | 307 |
SOME name => F name |
308 |
| NONE => thmname |
|
14516 | 309 |
in |
310 |
F thmname |
|
311 |
end |
|
312 |
||
313 |
fun add_hol4_cmove bef aft thy = |
|
314 |
let |
|
315 |
val curmoves = HOL4CMoves.get thy |
|
17261 | 316 |
val newmoves = Symtab.curried_update_new (bef, aft) curmoves |
14516 | 317 |
in |
318 |
HOL4CMoves.put newmoves thy |
|
319 |
end |
|
320 |
||
321 |
fun get_hol4_cmove bef thy = |
|
17261 | 322 |
Symtab.curried_lookup (HOL4CMoves.get thy) bef |
14516 | 323 |
|
324 |
fun follow_cname thmname thy = |
|
325 |
let |
|
326 |
val moves = HOL4CMoves.get thy |
|
327 |
fun F thmname = |
|
17261 | 328 |
case Symtab.curried_lookup moves thmname of |
15531 | 329 |
SOME name => F name |
330 |
| NONE => thmname |
|
14516 | 331 |
in |
332 |
F thmname |
|
333 |
end |
|
334 |
||
335 |
fun add_hol4_mapping bthy bthm isathm thy = |
|
336 |
let |
|
337 |
val isathm = follow_name isathm thy |
|
338 |
val _ = message ("Adding theorem map: " ^ bthy ^ "." ^ bthm ^ " --> " ^ isathm) |
|
339 |
val curmaps = HOL4Maps.get thy |
|
15531 | 340 |
val newmaps = StringPair.update_new(((bthy,bthm),SOME isathm),curmaps) |
14516 | 341 |
val upd_thy = HOL4Maps.put newmaps thy |
342 |
in |
|
343 |
upd_thy |
|
344 |
end; |
|
345 |
||
346 |
fun get_hol4_type_mapping bthy tycon thy = |
|
347 |
let |
|
348 |
val maps = HOL4TypeMaps.get thy |
|
349 |
in |
|
350 |
StringPair.lookup(maps,(bthy,tycon)) |
|
351 |
end |
|
352 |
||
353 |
fun get_hol4_mapping bthy bthm thy = |
|
354 |
let |
|
355 |
val curmaps = HOL4Maps.get thy |
|
356 |
in |
|
357 |
StringPair.lookup(curmaps,(bthy,bthm)) |
|
358 |
end; |
|
359 |
||
360 |
fun add_hol4_const_mapping bthy bconst internal isaconst thy = |
|
361 |
let |
|
362 |
val thy = case opt_get_output_thy thy of |
|
363 |
"" => thy |
|
364 |
| output_thy => if internal |
|
365 |
then add_hol4_cmove (Sign.full_name (sign_of thy) bconst) (output_thy ^ "." ^ bthy ^ "." ^ bconst) thy |
|
366 |
else thy |
|
367 |
val _ = message ("Adding cmap " ^ bthy ^ "." ^ bconst ^ " -> " ^ isaconst ^ (if internal then " (*)" else "")) |
|
368 |
val curmaps = HOL4ConstMaps.get thy |
|
15531 | 369 |
val newmaps = StringPair.update_new(((bthy,bconst),(internal,isaconst,NONE)),curmaps) |
14516 | 370 |
val upd_thy = HOL4ConstMaps.put newmaps thy |
371 |
in |
|
372 |
upd_thy |
|
373 |
end; |
|
374 |
||
375 |
fun add_hol4_const_renaming bthy bconst newname thy = |
|
376 |
let |
|
377 |
val currens = HOL4Rename.get thy |
|
378 |
val _ = message ("Adding renaming " ^ bthy ^ "." ^ bconst ^ " -> " ^ newname) |
|
379 |
val newrens = StringPair.update_new(((bthy,bconst),newname),currens) |
|
380 |
val upd_thy = HOL4Rename.put newrens thy |
|
381 |
in |
|
382 |
upd_thy |
|
383 |
end; |
|
384 |
||
385 |
fun get_hol4_const_renaming bthy bconst thy = |
|
386 |
let |
|
387 |
val currens = HOL4Rename.get thy |
|
388 |
in |
|
389 |
StringPair.lookup(currens,(bthy,bconst)) |
|
390 |
end; |
|
391 |
||
392 |
fun get_hol4_const_mapping bthy bconst thy = |
|
393 |
let |
|
394 |
val bconst = case get_hol4_const_renaming bthy bconst thy of |
|
15531 | 395 |
SOME name => name |
396 |
| NONE => bconst |
|
14516 | 397 |
val maps = HOL4ConstMaps.get thy |
398 |
in |
|
399 |
StringPair.lookup(maps,(bthy,bconst)) |
|
400 |
end |
|
401 |
||
402 |
fun add_hol4_const_wt_mapping bthy bconst internal isaconst typ thy = |
|
403 |
let |
|
404 |
val thy = case opt_get_output_thy thy of |
|
405 |
"" => thy |
|
406 |
| output_thy => if internal |
|
407 |
then add_hol4_cmove (Sign.full_name (sign_of thy) bconst) (output_thy ^ "." ^ bthy ^ "." ^ bconst) thy |
|
408 |
else thy |
|
409 |
val _ = message ("Adding cmap " ^ bthy ^ "." ^ bconst ^ " -> " ^ isaconst ^ (if internal then " (*)" else "")) |
|
410 |
val curmaps = HOL4ConstMaps.get thy |
|
15531 | 411 |
val newmaps = StringPair.update_new(((bthy,bconst),(internal,isaconst,SOME typ)),curmaps) |
14516 | 412 |
val upd_thy = HOL4ConstMaps.put newmaps thy |
413 |
in |
|
414 |
upd_thy |
|
415 |
end; |
|
416 |
||
417 |
fun add_hol4_type_mapping bthy bconst internal isaconst thy = |
|
418 |
let |
|
419 |
val curmaps = HOL4TypeMaps.get thy |
|
420 |
val _ = message ("Adding tmap " ^ bthy ^ "." ^ bconst ^ " -> " ^ isaconst ^ (if internal then " (*)" else "")) |
|
421 |
val newmaps = StringPair.update_new(((bthy,bconst),(internal,isaconst)),curmaps) |
|
422 |
val upd_thy = HOL4TypeMaps.put newmaps thy |
|
423 |
in |
|
424 |
upd_thy |
|
425 |
end; |
|
426 |
||
427 |
fun add_hol4_pending bthy bthm hth thy = |
|
428 |
let |
|
429 |
val thmname = Sign.full_name (sign_of thy) bthm |
|
430 |
val _ = message ("Add pending " ^ bthy ^ "." ^ bthm) |
|
431 |
val curpend = HOL4Pending.get thy |
|
432 |
val newpend = StringPair.update_new(((bthy,bthm),hth),curpend) |
|
433 |
val upd_thy = HOL4Pending.put newpend thy |
|
434 |
val thy' = case opt_get_output_thy upd_thy of |
|
435 |
"" => add_hol4_mapping bthy bthm thmname upd_thy |
|
436 |
| output_thy => |
|
437 |
let |
|
438 |
val new_thmname = output_thy ^ "." ^ bthy ^ "." ^ bthm |
|
439 |
in |
|
440 |
upd_thy |> add_hol4_move thmname new_thmname |
|
441 |
|> add_hol4_mapping bthy bthm new_thmname |
|
442 |
end |
|
443 |
in |
|
444 |
thy' |
|
445 |
end; |
|
446 |
||
447 |
fun get_hol4_theorem thyname thmname thy = |
|
448 |
let |
|
449 |
val isathms = HOL4Thms.get thy |
|
450 |
in |
|
451 |
StringPair.lookup (isathms,(thyname,thmname)) |
|
452 |
end |
|
453 |
||
454 |
fun add_hol4_theorem thyname thmname hth thy = |
|
455 |
let |
|
456 |
val _ = message ("Adding HOL4 theorem " ^ thyname ^ "." ^ thmname) |
|
457 |
val isathms = HOL4Thms.get thy |
|
458 |
val isathms' = StringPair.update_new (((thyname,thmname),hth),isathms) |
|
459 |
val thy' = HOL4Thms.put isathms' thy |
|
460 |
in |
|
461 |
thy' |
|
462 |
end |
|
463 |
||
464 |
fun export_hol4_pending thy = |
|
465 |
let |
|
466 |
val rews = HOL4Rewrites.get thy |
|
467 |
val outthy = get_output_thy thy |
|
468 |
fun process (thy,((bthy,bthm),hth as (_,thm))) = |
|
469 |
let |
|
470 |
val sg = sign_of thy |
|
16424 | 471 |
val thm1 = rewrite_rule (map (Thm.transfer sg) rews) (Thm.transfer sg thm) |
14516 | 472 |
val thm2 = standard thm1 |
473 |
val (thy2,_) = PureThy.store_thm((bthm,thm2),[]) thy |
|
474 |
val thy5 = add_hol4_theorem bthy bthm hth thy2 |
|
475 |
in |
|
476 |
thy5 |
|
477 |
end |
|
478 |
||
479 |
val pending = HOL4Pending.get thy |
|
480 |
val thy1 = StringPair.foldl process (thy,pending) |
|
481 |
val thy2 = HOL4Pending.put (StringPair.empty) thy1 |
|
482 |
in |
|
483 |
thy2 |
|
484 |
end; |
|
485 |
||
486 |
fun setup_dump (dir,thyname) thy = |
|
15647 | 487 |
HOL4Dump.put (dir,thyname,["(* AUTOMATICALLY GENERATED, DO NOT EDIT! *)"]) thy |
14516 | 488 |
|
489 |
fun add_dump str thy = |
|
490 |
let |
|
491 |
val (dir,thyname,curdump) = HOL4Dump.get thy |
|
492 |
in |
|
493 |
HOL4Dump.put (dir,thyname,str::curdump) thy |
|
494 |
end |
|
495 |
||
496 |
fun flush_dump thy = |
|
497 |
let |
|
498 |
val (dir,thyname,dumpdata) = HOL4Dump.get thy |
|
499 |
val os = TextIO.openOut (OS.Path.joinDirFile {dir=dir, |
|
500 |
file=thyname ^ ".thy"}) |
|
501 |
val _ = app (fn s => TextIO.output(os,s ^ "\n\n")) (rev dumpdata) |
|
502 |
val _ = TextIO.closeOut os |
|
503 |
in |
|
504 |
HOL4Dump.put ("","",[]) thy |
|
505 |
end |
|
506 |
||
507 |
fun set_generating_thy thyname thy = |
|
508 |
case HOL4DefThy.get thy of |
|
509 |
NoImport => HOL4DefThy.put (Generating thyname) thy |
|
510 |
| _ => error "Import already in progess" |
|
511 |
||
512 |
fun set_replaying_thy thyname thy = |
|
513 |
case HOL4DefThy.get thy of |
|
514 |
NoImport => HOL4DefThy.put (Replaying thyname) thy |
|
515 |
| _ => error "Import already in progess" |
|
516 |
||
517 |
fun clear_import_thy thy = |
|
518 |
case HOL4DefThy.get thy of |
|
519 |
NoImport => error "No import in progress" |
|
520 |
| _ => HOL4DefThy.put NoImport thy |
|
521 |
||
522 |
fun get_generating_thy thy = |
|
523 |
case HOL4DefThy.get thy of |
|
524 |
Generating thyname => thyname |
|
525 |
| _ => error "No theory being generated" |
|
526 |
||
527 |
fun get_replaying_thy thy = |
|
528 |
case HOL4DefThy.get thy of |
|
529 |
Replaying thyname => thyname |
|
530 |
| _ => error "No theory being replayed" |
|
531 |
||
532 |
fun get_import_thy thy = |
|
533 |
case HOL4DefThy.get thy of |
|
534 |
Replaying thyname => thyname |
|
535 |
| Generating thyname => thyname |
|
536 |
| _ => error "No theory being imported" |
|
537 |
||
538 |
fun should_ignore thyname thy thmname = |
|
539 |
case get_hol4_mapping thyname thmname thy of |
|
15531 | 540 |
SOME NONE => true |
14516 | 541 |
| _ => false |
542 |
||
543 |
val trans_string = |
|
544 |
let |
|
545 |
fun quote s = "\"" ^ s ^ "\"" |
|
546 |
fun F [] = [] |
|
547 |
| F (#"\\" :: cs) = patch #"\\" cs |
|
548 |
| F (#"\"" :: cs) = patch #"\"" cs |
|
549 |
| F (c :: cs) = c :: F cs |
|
550 |
and patch c rest = #"\\" :: c :: F rest |
|
551 |
in |
|
552 |
quote o String.implode o F o String.explode |
|
553 |
end |
|
554 |
||
555 |
fun dump_import_thy thyname thy = |
|
556 |
let |
|
557 |
val output_dir = get_output_dir thy |
|
558 |
val output_thy = get_output_thy thy |
|
559 |
val import_segment = get_import_segment thy |
|
560 |
val sg = sign_of thy |
|
561 |
val os = TextIO.openOut (OS.Path.joinDirFile {dir=output_dir, |
|
562 |
file=thyname ^ ".imp"}) |
|
563 |
fun out s = TextIO.output(os,s) |
|
564 |
val (ignored,mapped) = |
|
565 |
StringPair.foldl (fn ((ign,map),((bthy,bthm),v)) => |
|
566 |
if bthy = thyname |
|
567 |
then (case v of |
|
15531 | 568 |
NONE => (bthm::ign,map) |
569 |
| SOME w => (ign,(bthm,w)::map)) |
|
14516 | 570 |
else (ign,map)) |
571 |
(([],[]),HOL4Maps.get thy) |
|
572 |
val constmaps = |
|
573 |
StringPair.foldl (fn (map,((bthy,bthm),v)) => |
|
574 |
if bthy = thyname |
|
575 |
then (bthm,v)::map |
|
576 |
else map) |
|
577 |
([],HOL4ConstMaps.get thy) |
|
578 |
||
579 |
val constrenames = |
|
580 |
StringPair.foldl (fn (map,((bthy,bthm),v)) => |
|
581 |
if bthy = thyname |
|
582 |
then (bthm,v)::map |
|
583 |
else map) |
|
584 |
([],HOL4Rename.get thy) |
|
585 |
||
586 |
val typemaps = |
|
587 |
StringPair.foldl (fn (map,((bthy,bthm),v)) => |
|
588 |
if bthy = thyname |
|
589 |
then (bthm,v)::map |
|
590 |
else map) |
|
591 |
([],HOL4TypeMaps.get thy) |
|
592 |
||
593 |
val defmaps = |
|
594 |
StringPair.foldl (fn (map,((bthy,bthm),v)) => |
|
595 |
if bthy = thyname |
|
596 |
then (bthm,v)::map |
|
597 |
else map) |
|
598 |
([],HOL4DefMaps.get thy) |
|
599 |
||
600 |
fun new_name internal isa = |
|
601 |
if internal |
|
602 |
then |
|
603 |
let |
|
604 |
val paths = NameSpace.unpack isa |
|
15570 | 605 |
val i = Library.drop(length paths - 2,paths) |
14516 | 606 |
in |
607 |
case i of |
|
608 |
[seg,con] => output_thy ^ "." ^ seg ^ "." ^ con |
|
609 |
| _ => error "hol4rews.dump internal error" |
|
610 |
end |
|
611 |
else |
|
612 |
isa |
|
613 |
||
614 |
val _ = out "import\n\n" |
|
615 |
||
616 |
val _ = out ("import_segment " ^ trans_string import_segment ^ "\n\n") |
|
617 |
val _ = if null defmaps |
|
618 |
then () |
|
619 |
else out "def_maps" |
|
620 |
val _ = app (fn (hol,isa) => |
|
621 |
out ("\n " ^ (trans_string hol) ^ " > " ^ (trans_string isa))) defmaps |
|
622 |
val _ = if null defmaps |
|
623 |
then () |
|
624 |
else out "\n\n" |
|
625 |
||
626 |
val _ = if null typemaps |
|
627 |
then () |
|
628 |
else out "type_maps" |
|
629 |
val _ = app (fn (hol,(internal,isa)) => |
|
630 |
out ("\n " ^ (trans_string hol) ^ " > " ^ (trans_string (new_name internal isa)))) typemaps |
|
631 |
val _ = if null typemaps |
|
632 |
then () |
|
633 |
else out "\n\n" |
|
634 |
||
635 |
val _ = if null constmaps |
|
636 |
then () |
|
637 |
else out "const_maps" |
|
638 |
val _ = app (fn (hol,(internal,isa,opt_ty)) => |
|
639 |
(out ("\n " ^ (trans_string hol) ^ " > " ^ (trans_string (follow_cname isa thy))); |
|
640 |
case opt_ty of |
|
15531 | 641 |
SOME ty => out (" :: \"" ^ (string_of_ctyp (ctyp_of sg ty)) ^ "\"") |
642 |
| NONE => ())) constmaps |
|
14516 | 643 |
val _ = if null constmaps |
644 |
then () |
|
645 |
else out "\n\n" |
|
646 |
||
647 |
val _ = if null constrenames |
|
648 |
then () |
|
649 |
else out "const_renames" |
|
650 |
val _ = app (fn (old,new) => |
|
651 |
out ("\n " ^ (trans_string old) ^ " > " ^ (trans_string new))) constrenames |
|
652 |
val _ = if null constrenames |
|
653 |
then () |
|
654 |
else out "\n\n" |
|
655 |
||
656 |
val _ = if null mapped |
|
657 |
then () |
|
658 |
else out "thm_maps" |
|
659 |
val _ = app (fn (hol,isa) => out ("\n " ^ (trans_string hol) ^ " > " ^ (trans_string isa))) mapped |
|
660 |
val _ = if null mapped |
|
661 |
then () |
|
662 |
else out "\n\n" |
|
663 |
||
664 |
val _ = if null ignored |
|
665 |
then () |
|
666 |
else out "ignore_thms" |
|
667 |
val _ = app (fn ign => out ("\n " ^ (trans_string ign))) ignored |
|
668 |
val _ = if null ignored |
|
669 |
then () |
|
670 |
else out "\n\n" |
|
671 |
||
672 |
val _ = out "end\n" |
|
673 |
val _ = TextIO.closeOut os |
|
674 |
in |
|
675 |
thy |
|
676 |
end |
|
677 |
||
678 |
fun set_used_names names thy = |
|
679 |
let |
|
680 |
val unames = HOL4UNames.get thy |
|
681 |
in |
|
682 |
case unames of |
|
683 |
[] => HOL4UNames.put names thy |
|
684 |
| _ => error "hol4rews.set_used_names called on initialized data!" |
|
685 |
end |
|
686 |
||
687 |
val clear_used_names = HOL4UNames.put HOL4UNamesArgs.empty |
|
688 |
||
689 |
fun get_defmap thyname const thy = |
|
690 |
let |
|
691 |
val maps = HOL4DefMaps.get thy |
|
692 |
in |
|
693 |
StringPair.lookup(maps,(thyname,const)) |
|
694 |
end |
|
695 |
||
696 |
fun add_defmap thyname const defname thy = |
|
697 |
let |
|
698 |
val _ = message ("Adding defmap " ^ thyname ^ "." ^ const ^ " --> " ^ defname) |
|
699 |
val maps = HOL4DefMaps.get thy |
|
700 |
val maps' = StringPair.update_new(((thyname,const),defname),maps) |
|
701 |
val thy' = HOL4DefMaps.put maps' thy |
|
702 |
in |
|
703 |
thy' |
|
704 |
end |
|
705 |
||
706 |
fun get_defname thyname name thy = |
|
707 |
let |
|
708 |
val maps = HOL4DefMaps.get thy |
|
709 |
fun F dname = (dname,add_defmap thyname name dname thy) |
|
710 |
in |
|
711 |
case StringPair.lookup(maps,(thyname,name)) of |
|
15531 | 712 |
SOME thmname => (thmname,thy) |
713 |
| NONE => |
|
14516 | 714 |
let |
715 |
val used = HOL4UNames.get thy |
|
716 |
val defname = def_name name |
|
717 |
val pdefname = name ^ "_primdef" |
|
718 |
in |
|
719 |
if not (defname mem used) |
|
720 |
then F defname (* name_def *) |
|
721 |
else if not (pdefname mem used) |
|
722 |
then F pdefname (* name_primdef *) |
|
723 |
else F (variant used pdefname) (* last resort *) |
|
724 |
end |
|
725 |
end |
|
726 |
||
727 |
local |
|
728 |
fun handle_meta [x as Appl[Appl[Constant "_constrain", Constant "==", _],_,_]] = x |
|
729 |
| handle_meta [x as Appl[Appl[Constant "_constrain", Constant "all", _],_]] = x |
|
730 |
| handle_meta [x as Appl[Appl[Constant "_constrain", Constant "==>", _],_,_]] = x |
|
731 |
| handle_meta [x] = Appl[Constant "Trueprop",x] |
|
14518
c3019a66180f
Added a number of explicit type casts and delayed evaluations (all seemingly
skalberg
parents:
14516
diff
changeset
|
732 |
| handle_meta _ = error "hol4rews error: Trueprop not applied to single argument" |
14516 | 733 |
in |
734 |
val smarter_trueprop_parsing = [("Trueprop",handle_meta)] |
|
735 |
end |
|
736 |
||
737 |
local |
|
738 |
fun initial_maps thy = |
|
739 |
thy |> add_hol4_type_mapping "min" "bool" false "bool" |
|
740 |
|> add_hol4_type_mapping "min" "fun" false "fun" |
|
741 |
|> add_hol4_type_mapping "min" "ind" false "Nat.ind" |
|
742 |
|> add_hol4_const_mapping "min" "=" false "op =" |
|
743 |
|> add_hol4_const_mapping "min" "==>" false "op -->" |
|
744 |
|> add_hol4_const_mapping "min" "@" false "Hilbert_Choice.Eps" |
|
745 |
in |
|
746 |
val hol4_setup = |
|
747 |
[HOL4Rewrites.init, |
|
748 |
HOL4Maps.init, |
|
749 |
HOL4UNames.init, |
|
750 |
HOL4DefMaps.init, |
|
751 |
HOL4Moves.init, |
|
752 |
HOL4CMoves.init, |
|
753 |
HOL4ConstMaps.init, |
|
754 |
HOL4Rename.init, |
|
755 |
HOL4TypeMaps.init, |
|
756 |
HOL4Pending.init, |
|
757 |
HOL4Thms.init, |
|
758 |
HOL4Dump.init, |
|
759 |
HOL4DefThy.init, |
|
760 |
HOL4Imports.init, |
|
761 |
ImportSegment.init, |
|
762 |
initial_maps, |
|
763 |
Attrib.add_attributes [("hol4rew", |
|
764 |
(Attrib.no_args add_hol4_rewrite, |
|
765 |
Attrib.no_args Attrib.undef_local_attribute), |
|
766 |
"HOL4 rewrite rule")]] |
|
767 |
end |