author | wenzelm |
Sun, 08 Mar 2009 17:26:14 +0100 | |
changeset 30364 | 577edc39b501 |
parent 29585 | c23295521af5 |
child 30528 | 7173bf123335 |
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 |
||
22846 | 15 |
structure HOL4DefThy = TheoryDataFun |
16 |
( |
|
17 |
type T = ImportStatus |
|
18 |
val empty = NoImport |
|
19 |
val copy = I |
|
20 |
val extend = I |
|
21 |
fun merge _ (NoImport,NoImport) = NoImport |
|
22 |
| merge _ _ = (warning "Import status set during merge"; NoImport) |
|
23 |
) |
|
14516 | 24 |
|
22846 | 25 |
structure ImportSegment = TheoryDataFun |
26 |
( |
|
27 |
type T = string |
|
28 |
val empty = "" |
|
29 |
val copy = I |
|
30 |
val extend = I |
|
31 |
fun merge _ ("",arg) = arg |
|
32 |
| merge _ (arg,"") = arg |
|
33 |
| merge _ (s1,s2) = |
|
34 |
if s1 = s2 |
|
35 |
then s1 |
|
36 |
else error "Trying to merge two different import segments" |
|
37 |
) |
|
14516 | 38 |
|
39 |
val get_import_segment = ImportSegment.get |
|
40 |
val set_import_segment = ImportSegment.put |
|
41 |
||
22846 | 42 |
structure HOL4UNames = TheoryDataFun |
43 |
( |
|
44 |
type T = string list |
|
45 |
val empty = [] |
|
46 |
val copy = I |
|
47 |
val extend = I |
|
48 |
fun merge _ ([],[]) = [] |
|
49 |
| merge _ _ = error "Used names not empty during merge" |
|
50 |
) |
|
14516 | 51 |
|
22846 | 52 |
structure HOL4Dump = TheoryDataFun |
53 |
( |
|
54 |
type T = string * string * string list |
|
55 |
val empty = ("","",[]) |
|
56 |
val copy = I |
|
57 |
val extend = I |
|
58 |
fun merge _ (("","",[]),("","",[])) = ("","",[]) |
|
59 |
| merge _ _ = error "Dump data not empty during merge" |
|
60 |
) |
|
14516 | 61 |
|
22846 | 62 |
structure HOL4Moves = TheoryDataFun |
63 |
( |
|
64 |
type T = string Symtab.table |
|
65 |
val empty = Symtab.empty |
|
66 |
val copy = I |
|
67 |
val extend = I |
|
68 |
fun merge _ : T * T -> T = Symtab.merge (K true) |
|
69 |
) |
|
14516 | 70 |
|
22846 | 71 |
structure HOL4Imports = TheoryDataFun |
72 |
( |
|
73 |
type T = string Symtab.table |
|
74 |
val empty = Symtab.empty |
|
75 |
val copy = I |
|
76 |
val extend = I |
|
77 |
fun merge _ : T * T -> T = Symtab.merge (K true) |
|
78 |
) |
|
14516 | 79 |
|
80 |
fun get_segment2 thyname thy = |
|
17412 | 81 |
Symtab.lookup (HOL4Imports.get thy) thyname |
14516 | 82 |
|
83 |
fun set_segment thyname segname thy = |
|
84 |
let |
|
85 |
val imps = HOL4Imports.get thy |
|
17412 | 86 |
val imps' = Symtab.update_new (thyname,segname) imps |
14516 | 87 |
in |
88 |
HOL4Imports.put imps' thy |
|
89 |
end |
|
90 |
||
22846 | 91 |
structure HOL4CMoves = TheoryDataFun |
92 |
( |
|
93 |
type T = string Symtab.table |
|
94 |
val empty = Symtab.empty |
|
95 |
val copy = I |
|
96 |
val extend = I |
|
97 |
fun merge _ : T * T -> T = Symtab.merge (K true) |
|
98 |
) |
|
14516 | 99 |
|
22846 | 100 |
structure HOL4Maps = TheoryDataFun |
101 |
( |
|
102 |
type T = (string option) StringPair.table |
|
103 |
val empty = StringPair.empty |
|
104 |
val copy = I |
|
105 |
val extend = I |
|
106 |
fun merge _ : T * T -> T = StringPair.merge (K true) |
|
107 |
) |
|
14516 | 108 |
|
22846 | 109 |
structure HOL4Thms = TheoryDataFun |
110 |
( |
|
111 |
type T = holthm StringPair.table |
|
112 |
val empty = StringPair.empty |
|
113 |
val copy = I |
|
114 |
val extend = I |
|
115 |
fun merge _ : T * T -> T = StringPair.merge (K true) |
|
116 |
) |
|
14516 | 117 |
|
22846 | 118 |
structure HOL4ConstMaps = TheoryDataFun |
119 |
( |
|
120 |
type T = (bool * string * typ option) StringPair.table |
|
121 |
val empty = StringPair.empty |
|
122 |
val copy = I |
|
123 |
val extend = I |
|
124 |
fun merge _ : T * T -> T = StringPair.merge (K true) |
|
125 |
) |
|
14516 | 126 |
|
22846 | 127 |
structure HOL4Rename = TheoryDataFun |
128 |
( |
|
129 |
type T = string StringPair.table |
|
130 |
val empty = StringPair.empty |
|
131 |
val copy = I |
|
132 |
val extend = I |
|
133 |
fun merge _ : T * T -> T = StringPair.merge (K true) |
|
134 |
) |
|
14516 | 135 |
|
22846 | 136 |
structure HOL4DefMaps = TheoryDataFun |
137 |
( |
|
138 |
type T = string StringPair.table |
|
139 |
val empty = StringPair.empty |
|
140 |
val copy = I |
|
141 |
val extend = I |
|
142 |
fun merge _ : T * T -> T = StringPair.merge (K true) |
|
143 |
) |
|
14516 | 144 |
|
22846 | 145 |
structure HOL4TypeMaps = TheoryDataFun |
146 |
( |
|
147 |
type T = (bool * string) StringPair.table |
|
148 |
val empty = StringPair.empty |
|
149 |
val copy = I |
|
150 |
val extend = I |
|
151 |
fun merge _ : T * T -> T = StringPair.merge (K true) |
|
152 |
) |
|
14516 | 153 |
|
22846 | 154 |
structure HOL4Pending = TheoryDataFun |
155 |
( |
|
156 |
type T = ((term * term) list * thm) StringPair.table |
|
157 |
val empty = StringPair.empty |
|
158 |
val copy = I |
|
159 |
val extend = I |
|
160 |
fun merge _ : T * T -> T = StringPair.merge (K true) |
|
161 |
) |
|
14516 | 162 |
|
22846 | 163 |
structure HOL4Rewrites = TheoryDataFun |
164 |
( |
|
165 |
type T = thm list |
|
166 |
val empty = [] |
|
167 |
val copy = I |
|
168 |
val extend = I |
|
169 |
fun merge _ = Library.gen_union Thm.eq_thm |
|
170 |
) |
|
14516 | 171 |
|
172 |
val hol4_debug = ref false |
|
173 |
fun message s = if !hol4_debug then writeln s else () |
|
174 |
||
21546 | 175 |
local |
176 |
val eq_reflection = thm "eq_reflection" |
|
177 |
in |
|
20897 | 178 |
fun add_hol4_rewrite (Context.Theory thy, th) = |
14516 | 179 |
let |
180 |
val _ = message "Adding HOL4 rewrite" |
|
21546 | 181 |
val th1 = th RS eq_reflection |
14516 | 182 |
val current_rews = HOL4Rewrites.get thy |
18921 | 183 |
val new_rews = insert Thm.eq_thm th1 current_rews |
14516 | 184 |
val updated_thy = HOL4Rewrites.put new_rews thy |
185 |
in |
|
18728 | 186 |
(Context.Theory updated_thy,th1) |
20897 | 187 |
end |
21546 | 188 |
| add_hol4_rewrite (context, th) = (context, th RS eq_reflection); |
189 |
end |
|
14516 | 190 |
|
191 |
fun ignore_hol4 bthy bthm thy = |
|
192 |
let |
|
193 |
val _ = message ("Ignoring " ^ bthy ^ "." ^ bthm) |
|
194 |
val curmaps = HOL4Maps.get thy |
|
17412 | 195 |
val newmaps = StringPair.update_new ((bthy,bthm),NONE) curmaps |
14516 | 196 |
val upd_thy = HOL4Maps.put newmaps thy |
197 |
in |
|
198 |
upd_thy |
|
199 |
end |
|
200 |
||
201 |
val opt_get_output_thy = #2 o HOL4Dump.get |
|
202 |
||
203 |
fun get_output_thy thy = |
|
204 |
case #2 (HOL4Dump.get thy) of |
|
205 |
"" => error "No theory file being output" |
|
206 |
| thyname => thyname |
|
207 |
||
208 |
val get_output_dir = #1 o HOL4Dump.get |
|
209 |
||
210 |
fun add_hol4_move bef aft thy = |
|
211 |
let |
|
212 |
val curmoves = HOL4Moves.get thy |
|
17412 | 213 |
val newmoves = Symtab.update_new (bef, aft) curmoves |
14516 | 214 |
in |
215 |
HOL4Moves.put newmoves thy |
|
216 |
end |
|
217 |
||
218 |
fun get_hol4_move bef thy = |
|
17412 | 219 |
Symtab.lookup (HOL4Moves.get thy) bef |
14516 | 220 |
|
221 |
fun follow_name thmname thy = |
|
222 |
let |
|
223 |
val moves = HOL4Moves.get thy |
|
224 |
fun F thmname = |
|
17412 | 225 |
case Symtab.lookup moves thmname of |
15531 | 226 |
SOME name => F name |
227 |
| NONE => thmname |
|
14516 | 228 |
in |
229 |
F thmname |
|
230 |
end |
|
231 |
||
232 |
fun add_hol4_cmove bef aft thy = |
|
233 |
let |
|
234 |
val curmoves = HOL4CMoves.get thy |
|
17412 | 235 |
val newmoves = Symtab.update_new (bef, aft) curmoves |
14516 | 236 |
in |
237 |
HOL4CMoves.put newmoves thy |
|
238 |
end |
|
239 |
||
240 |
fun get_hol4_cmove bef thy = |
|
17412 | 241 |
Symtab.lookup (HOL4CMoves.get thy) bef |
14516 | 242 |
|
243 |
fun follow_cname thmname thy = |
|
244 |
let |
|
245 |
val moves = HOL4CMoves.get thy |
|
246 |
fun F thmname = |
|
17412 | 247 |
case Symtab.lookup moves thmname of |
15531 | 248 |
SOME name => F name |
249 |
| NONE => thmname |
|
14516 | 250 |
in |
251 |
F thmname |
|
252 |
end |
|
253 |
||
254 |
fun add_hol4_mapping bthy bthm isathm thy = |
|
17644 | 255 |
let |
256 |
(* val _ = writeln ("Before follow_name: "^isathm) *) |
|
257 |
val isathm = follow_name isathm thy |
|
258 |
(* val _ = writeln ("Adding theorem map: " ^ bthy ^ "." ^ bthm ^ " --> " ^ isathm)*) |
|
14516 | 259 |
val curmaps = HOL4Maps.get thy |
17412 | 260 |
val newmaps = StringPair.update_new ((bthy,bthm),SOME isathm) curmaps |
14516 | 261 |
val upd_thy = HOL4Maps.put newmaps thy |
262 |
in |
|
263 |
upd_thy |
|
264 |
end; |
|
265 |
||
266 |
fun get_hol4_type_mapping bthy tycon thy = |
|
267 |
let |
|
268 |
val maps = HOL4TypeMaps.get thy |
|
269 |
in |
|
17412 | 270 |
StringPair.lookup maps (bthy,tycon) |
14516 | 271 |
end |
272 |
||
273 |
fun get_hol4_mapping bthy bthm thy = |
|
274 |
let |
|
275 |
val curmaps = HOL4Maps.get thy |
|
276 |
in |
|
17412 | 277 |
StringPair.lookup curmaps (bthy,bthm) |
14516 | 278 |
end; |
279 |
||
280 |
fun add_hol4_const_mapping bthy bconst internal isaconst thy = |
|
281 |
let |
|
282 |
val thy = case opt_get_output_thy thy of |
|
283 |
"" => thy |
|
284 |
| output_thy => if internal |
|
28965 | 285 |
then add_hol4_cmove (Sign.full_bname thy bconst) (output_thy ^ "." ^ bthy ^ "." ^ bconst) thy |
14516 | 286 |
else thy |
287 |
val _ = message ("Adding cmap " ^ bthy ^ "." ^ bconst ^ " -> " ^ isaconst ^ (if internal then " (*)" else "")) |
|
288 |
val curmaps = HOL4ConstMaps.get thy |
|
17412 | 289 |
val newmaps = StringPair.update_new ((bthy,bconst),(internal,isaconst,NONE)) curmaps |
14516 | 290 |
val upd_thy = HOL4ConstMaps.put newmaps thy |
291 |
in |
|
292 |
upd_thy |
|
293 |
end; |
|
294 |
||
295 |
fun add_hol4_const_renaming bthy bconst newname thy = |
|
296 |
let |
|
297 |
val currens = HOL4Rename.get thy |
|
298 |
val _ = message ("Adding renaming " ^ bthy ^ "." ^ bconst ^ " -> " ^ newname) |
|
17412 | 299 |
val newrens = StringPair.update_new ((bthy,bconst),newname) currens |
14516 | 300 |
val upd_thy = HOL4Rename.put newrens thy |
301 |
in |
|
302 |
upd_thy |
|
303 |
end; |
|
304 |
||
305 |
fun get_hol4_const_renaming bthy bconst thy = |
|
306 |
let |
|
307 |
val currens = HOL4Rename.get thy |
|
308 |
in |
|
17412 | 309 |
StringPair.lookup currens (bthy,bconst) |
14516 | 310 |
end; |
311 |
||
312 |
fun get_hol4_const_mapping bthy bconst thy = |
|
313 |
let |
|
314 |
val bconst = case get_hol4_const_renaming bthy bconst thy of |
|
15531 | 315 |
SOME name => name |
316 |
| NONE => bconst |
|
14516 | 317 |
val maps = HOL4ConstMaps.get thy |
318 |
in |
|
17412 | 319 |
StringPair.lookup maps (bthy,bconst) |
14516 | 320 |
end |
321 |
||
322 |
fun add_hol4_const_wt_mapping bthy bconst internal isaconst typ thy = |
|
323 |
let |
|
324 |
val thy = case opt_get_output_thy thy of |
|
325 |
"" => thy |
|
326 |
| output_thy => if internal |
|
28965 | 327 |
then add_hol4_cmove (Sign.full_bname thy bconst) (output_thy ^ "." ^ bthy ^ "." ^ bconst) thy |
14516 | 328 |
else thy |
329 |
val _ = message ("Adding cmap " ^ bthy ^ "." ^ bconst ^ " -> " ^ isaconst ^ (if internal then " (*)" else "")) |
|
330 |
val curmaps = HOL4ConstMaps.get thy |
|
17412 | 331 |
val newmaps = StringPair.update_new ((bthy,bconst),(internal,isaconst,SOME typ)) curmaps |
14516 | 332 |
val upd_thy = HOL4ConstMaps.put newmaps thy |
333 |
in |
|
334 |
upd_thy |
|
335 |
end; |
|
336 |
||
337 |
fun add_hol4_type_mapping bthy bconst internal isaconst thy = |
|
338 |
let |
|
339 |
val curmaps = HOL4TypeMaps.get thy |
|
17322 | 340 |
val _ = writeln ("Adding tmap " ^ bthy ^ "." ^ bconst ^ " -> " ^ isaconst ^ (if internal then " (*)" else "")) |
17412 | 341 |
val newmaps = StringPair.update_new ((bthy,bconst),(internal,isaconst)) curmaps |
342 |
handle x => let val (internal, isaconst') = the (StringPair.lookup curmaps (bthy, bconst)) in |
|
17322 | 343 |
warning ("couldn't map type "^bthy^"."^bconst^" to "^isaconst^": already mapped to "^isaconst'); raise x end |
344 |
val upd_thy = HOL4TypeMaps.put newmaps thy |
|
14516 | 345 |
in |
346 |
upd_thy |
|
347 |
end; |
|
348 |
||
349 |
fun add_hol4_pending bthy bthm hth thy = |
|
350 |
let |
|
28965 | 351 |
val thmname = Sign.full_bname thy bthm |
14516 | 352 |
val _ = message ("Add pending " ^ bthy ^ "." ^ bthm) |
353 |
val curpend = HOL4Pending.get thy |
|
17412 | 354 |
val newpend = StringPair.update_new ((bthy,bthm),hth) curpend |
14516 | 355 |
val upd_thy = HOL4Pending.put newpend thy |
356 |
val thy' = case opt_get_output_thy upd_thy of |
|
357 |
"" => add_hol4_mapping bthy bthm thmname upd_thy |
|
358 |
| output_thy => |
|
359 |
let |
|
360 |
val new_thmname = output_thy ^ "." ^ bthy ^ "." ^ bthm |
|
361 |
in |
|
362 |
upd_thy |> add_hol4_move thmname new_thmname |
|
363 |
|> add_hol4_mapping bthy bthm new_thmname |
|
364 |
end |
|
365 |
in |
|
366 |
thy' |
|
367 |
end; |
|
368 |
||
369 |
fun get_hol4_theorem thyname thmname thy = |
|
21056 | 370 |
let |
371 |
val isathms = HOL4Thms.get thy |
|
372 |
in |
|
373 |
StringPair.lookup isathms (thyname,thmname) |
|
374 |
end; |
|
14516 | 375 |
|
21056 | 376 |
fun add_hol4_theorem thyname thmname hth = |
377 |
let |
|
378 |
val _ = message ("Adding HOL4 theorem " ^ thyname ^ "." ^ thmname) |
|
379 |
in |
|
380 |
HOL4Thms.map (StringPair.update_new ((thyname, thmname), hth)) |
|
381 |
end; |
|
14516 | 382 |
|
383 |
fun export_hol4_pending thy = |
|
21056 | 384 |
let |
385 |
val rews = HOL4Rewrites.get thy; |
|
386 |
val pending = HOL4Pending.get thy; |
|
387 |
fun process ((bthy,bthm), hth as (_,thm)) thy = |
|
388 |
let |
|
389 |
val thm1 = rewrite_rule (map (Thm.transfer thy) rews) (Thm.transfer thy thm); |
|
390 |
val thm2 = standard thm1; |
|
391 |
in |
|
392 |
thy |
|
29585 | 393 |
|> PureThy.store_thm (Binding.name bthm, thm2) |
21056 | 394 |
|> snd |
395 |
|> add_hol4_theorem bthy bthm hth |
|
396 |
end; |
|
397 |
in |
|
398 |
thy |
|
399 |
|> StringPair.fold process pending |
|
400 |
|> HOL4Pending.put StringPair.empty |
|
401 |
end; |
|
14516 | 402 |
|
403 |
fun setup_dump (dir,thyname) thy = |
|
15647 | 404 |
HOL4Dump.put (dir,thyname,["(* AUTOMATICALLY GENERATED, DO NOT EDIT! *)"]) thy |
14516 | 405 |
|
406 |
fun add_dump str thy = |
|
407 |
let |
|
408 |
val (dir,thyname,curdump) = HOL4Dump.get thy |
|
409 |
in |
|
410 |
HOL4Dump.put (dir,thyname,str::curdump) thy |
|
411 |
end |
|
412 |
||
413 |
fun flush_dump thy = |
|
414 |
let |
|
415 |
val (dir,thyname,dumpdata) = HOL4Dump.get thy |
|
416 |
val os = TextIO.openOut (OS.Path.joinDirFile {dir=dir, |
|
417 |
file=thyname ^ ".thy"}) |
|
418 |
val _ = app (fn s => TextIO.output(os,s ^ "\n\n")) (rev dumpdata) |
|
419 |
val _ = TextIO.closeOut os |
|
420 |
in |
|
421 |
HOL4Dump.put ("","",[]) thy |
|
422 |
end |
|
423 |
||
424 |
fun set_generating_thy thyname thy = |
|
425 |
case HOL4DefThy.get thy of |
|
426 |
NoImport => HOL4DefThy.put (Generating thyname) thy |
|
427 |
| _ => error "Import already in progess" |
|
428 |
||
429 |
fun set_replaying_thy thyname thy = |
|
430 |
case HOL4DefThy.get thy of |
|
431 |
NoImport => HOL4DefThy.put (Replaying thyname) thy |
|
432 |
| _ => error "Import already in progess" |
|
433 |
||
434 |
fun clear_import_thy thy = |
|
435 |
case HOL4DefThy.get thy of |
|
436 |
NoImport => error "No import in progress" |
|
437 |
| _ => HOL4DefThy.put NoImport thy |
|
438 |
||
439 |
fun get_generating_thy thy = |
|
440 |
case HOL4DefThy.get thy of |
|
441 |
Generating thyname => thyname |
|
442 |
| _ => error "No theory being generated" |
|
443 |
||
444 |
fun get_replaying_thy thy = |
|
445 |
case HOL4DefThy.get thy of |
|
446 |
Replaying thyname => thyname |
|
447 |
| _ => error "No theory being replayed" |
|
448 |
||
449 |
fun get_import_thy thy = |
|
450 |
case HOL4DefThy.get thy of |
|
451 |
Replaying thyname => thyname |
|
452 |
| Generating thyname => thyname |
|
453 |
| _ => error "No theory being imported" |
|
454 |
||
455 |
fun should_ignore thyname thy thmname = |
|
456 |
case get_hol4_mapping thyname thmname thy of |
|
15531 | 457 |
SOME NONE => true |
14516 | 458 |
| _ => false |
459 |
||
460 |
val trans_string = |
|
461 |
let |
|
462 |
fun quote s = "\"" ^ s ^ "\"" |
|
463 |
fun F [] = [] |
|
464 |
| F (#"\\" :: cs) = patch #"\\" cs |
|
465 |
| F (#"\"" :: cs) = patch #"\"" cs |
|
466 |
| F (c :: cs) = c :: F cs |
|
467 |
and patch c rest = #"\\" :: c :: F rest |
|
468 |
in |
|
469 |
quote o String.implode o F o String.explode |
|
470 |
end |
|
471 |
||
472 |
fun dump_import_thy thyname thy = |
|
473 |
let |
|
474 |
val output_dir = get_output_dir thy |
|
475 |
val output_thy = get_output_thy thy |
|
17607
7725da65f8e0
1) fixed bug in type_introduction: first stage uses different namespace than second stage
obua
parents:
17412
diff
changeset
|
476 |
val input_thy = Context.theory_name thy |
14516 | 477 |
val import_segment = get_import_segment thy |
478 |
val os = TextIO.openOut (OS.Path.joinDirFile {dir=output_dir, |
|
479 |
file=thyname ^ ".imp"}) |
|
480 |
fun out s = TextIO.output(os,s) |
|
21056 | 481 |
val (ignored, mapped) = StringPair.fold |
482 |
(fn ((bthy, bthm), v) => fn (ign, map) => |
|
483 |
if bthy = thyname |
|
484 |
then case v |
|
485 |
of NONE => (bthm :: ign, map) |
|
486 |
| SOME w => (ign, (bthm, w) :: map) |
|
487 |
else (ign, map)) (HOL4Maps.get thy) ([],[]); |
|
488 |
fun mk init = StringPair.fold |
|
489 |
(fn ((bthy, bthm), v) => if bthy = thyname then cons (bthm, v) else I) init []; |
|
490 |
val constmaps = mk (HOL4ConstMaps.get thy); |
|
491 |
val constrenames = mk (HOL4Rename.get thy); |
|
492 |
val typemaps = mk (HOL4TypeMaps.get thy); |
|
493 |
val defmaps = mk (HOL4DefMaps.get thy); |
|
14516 | 494 |
fun new_name internal isa = |
495 |
if internal |
|
496 |
then |
|
497 |
let |
|
30364
577edc39b501
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
29585
diff
changeset
|
498 |
val paths = Long_Name.explode isa |
15570 | 499 |
val i = Library.drop(length paths - 2,paths) |
14516 | 500 |
in |
501 |
case i of |
|
502 |
[seg,con] => output_thy ^ "." ^ seg ^ "." ^ con |
|
503 |
| _ => error "hol4rews.dump internal error" |
|
504 |
end |
|
505 |
else |
|
506 |
isa |
|
507 |
||
508 |
val _ = out "import\n\n" |
|
509 |
||
510 |
val _ = out ("import_segment " ^ trans_string import_segment ^ "\n\n") |
|
511 |
val _ = if null defmaps |
|
512 |
then () |
|
513 |
else out "def_maps" |
|
514 |
val _ = app (fn (hol,isa) => |
|
515 |
out ("\n " ^ (trans_string hol) ^ " > " ^ (trans_string isa))) defmaps |
|
516 |
val _ = if null defmaps |
|
517 |
then () |
|
518 |
else out "\n\n" |
|
519 |
||
520 |
val _ = if null typemaps |
|
521 |
then () |
|
522 |
else out "type_maps" |
|
523 |
val _ = app (fn (hol,(internal,isa)) => |
|
524 |
out ("\n " ^ (trans_string hol) ^ " > " ^ (trans_string (new_name internal isa)))) typemaps |
|
525 |
val _ = if null typemaps |
|
526 |
then () |
|
527 |
else out "\n\n" |
|
528 |
||
529 |
val _ = if null constmaps |
|
530 |
then () |
|
531 |
else out "const_maps" |
|
532 |
val _ = app (fn (hol,(internal,isa,opt_ty)) => |
|
533 |
(out ("\n " ^ (trans_string hol) ^ " > " ^ (trans_string (follow_cname isa thy))); |
|
534 |
case opt_ty of |
|
26928 | 535 |
SOME ty => out (" :: \"" ^ (Display.string_of_ctyp (ctyp_of thy ty)) ^ "\"") |
15531 | 536 |
| NONE => ())) constmaps |
14516 | 537 |
val _ = if null constmaps |
538 |
then () |
|
539 |
else out "\n\n" |
|
540 |
||
541 |
val _ = if null constrenames |
|
542 |
then () |
|
543 |
else out "const_renames" |
|
544 |
val _ = app (fn (old,new) => |
|
545 |
out ("\n " ^ (trans_string old) ^ " > " ^ (trans_string new))) constrenames |
|
546 |
val _ = if null constrenames |
|
547 |
then () |
|
548 |
else out "\n\n" |
|
549 |
||
17607
7725da65f8e0
1) fixed bug in type_introduction: first stage uses different namespace than second stage
obua
parents:
17412
diff
changeset
|
550 |
fun gen2replay in_thy out_thy s = |
7725da65f8e0
1) fixed bug in type_introduction: first stage uses different namespace than second stage
obua
parents:
17412
diff
changeset
|
551 |
let |
30364
577edc39b501
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
29585
diff
changeset
|
552 |
val ss = Long_Name.explode s |
17607
7725da65f8e0
1) fixed bug in type_introduction: first stage uses different namespace than second stage
obua
parents:
17412
diff
changeset
|
553 |
in |
7725da65f8e0
1) fixed bug in type_introduction: first stage uses different namespace than second stage
obua
parents:
17412
diff
changeset
|
554 |
if (hd ss = in_thy) then |
30364
577edc39b501
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
29585
diff
changeset
|
555 |
Long_Name.implode (out_thy::(tl ss)) |
17607
7725da65f8e0
1) fixed bug in type_introduction: first stage uses different namespace than second stage
obua
parents:
17412
diff
changeset
|
556 |
else |
7725da65f8e0
1) fixed bug in type_introduction: first stage uses different namespace than second stage
obua
parents:
17412
diff
changeset
|
557 |
s |
7725da65f8e0
1) fixed bug in type_introduction: first stage uses different namespace than second stage
obua
parents:
17412
diff
changeset
|
558 |
end |
7725da65f8e0
1) fixed bug in type_introduction: first stage uses different namespace than second stage
obua
parents:
17412
diff
changeset
|
559 |
|
14516 | 560 |
val _ = if null mapped |
561 |
then () |
|
562 |
else out "thm_maps" |
|
17607
7725da65f8e0
1) fixed bug in type_introduction: first stage uses different namespace than second stage
obua
parents:
17412
diff
changeset
|
563 |
val _ = app (fn (hol,isa) => out ("\n " ^ (trans_string hol) ^ " > " ^ (trans_string (gen2replay input_thy output_thy isa)))) mapped |
14516 | 564 |
val _ = if null mapped |
565 |
then () |
|
566 |
else out "\n\n" |
|
567 |
||
568 |
val _ = if null ignored |
|
569 |
then () |
|
570 |
else out "ignore_thms" |
|
571 |
val _ = app (fn ign => out ("\n " ^ (trans_string ign))) ignored |
|
572 |
val _ = if null ignored |
|
573 |
then () |
|
574 |
else out "\n\n" |
|
575 |
||
576 |
val _ = out "end\n" |
|
577 |
val _ = TextIO.closeOut os |
|
578 |
in |
|
579 |
thy |
|
580 |
end |
|
581 |
||
582 |
fun set_used_names names thy = |
|
583 |
let |
|
584 |
val unames = HOL4UNames.get thy |
|
585 |
in |
|
586 |
case unames of |
|
587 |
[] => HOL4UNames.put names thy |
|
588 |
| _ => error "hol4rews.set_used_names called on initialized data!" |
|
589 |
end |
|
590 |
||
22846 | 591 |
val clear_used_names = HOL4UNames.put []; |
14516 | 592 |
|
593 |
fun get_defmap thyname const thy = |
|
594 |
let |
|
595 |
val maps = HOL4DefMaps.get thy |
|
596 |
in |
|
17412 | 597 |
StringPair.lookup maps (thyname,const) |
14516 | 598 |
end |
599 |
||
600 |
fun add_defmap thyname const defname thy = |
|
601 |
let |
|
602 |
val _ = message ("Adding defmap " ^ thyname ^ "." ^ const ^ " --> " ^ defname) |
|
603 |
val maps = HOL4DefMaps.get thy |
|
17412 | 604 |
val maps' = StringPair.update_new ((thyname,const),defname) maps |
14516 | 605 |
val thy' = HOL4DefMaps.put maps' thy |
606 |
in |
|
607 |
thy' |
|
608 |
end |
|
609 |
||
610 |
fun get_defname thyname name thy = |
|
611 |
let |
|
612 |
val maps = HOL4DefMaps.get thy |
|
613 |
fun F dname = (dname,add_defmap thyname name dname thy) |
|
614 |
in |
|
17412 | 615 |
case StringPair.lookup maps (thyname,name) of |
15531 | 616 |
SOME thmname => (thmname,thy) |
617 |
| NONE => |
|
14516 | 618 |
let |
619 |
val used = HOL4UNames.get thy |
|
28677 | 620 |
val defname = Thm.def_name name |
14516 | 621 |
val pdefname = name ^ "_primdef" |
622 |
in |
|
623 |
if not (defname mem used) |
|
624 |
then F defname (* name_def *) |
|
625 |
else if not (pdefname mem used) |
|
626 |
then F pdefname (* name_primdef *) |
|
20071
8f3e1ddb50e6
replaced Term.variant(list) by Name.variant(_list);
wenzelm
parents:
18921
diff
changeset
|
627 |
else F (Name.variant used pdefname) (* last resort *) |
14516 | 628 |
end |
629 |
end |
|
630 |
||
631 |
local |
|
632 |
fun handle_meta [x as Appl[Appl[Constant "_constrain", Constant "==", _],_,_]] = x |
|
633 |
| handle_meta [x as Appl[Appl[Constant "_constrain", Constant "all", _],_]] = x |
|
634 |
| handle_meta [x as Appl[Appl[Constant "_constrain", Constant "==>", _],_,_]] = x |
|
635 |
| 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
|
636 |
| handle_meta _ = error "hol4rews error: Trueprop not applied to single argument" |
14516 | 637 |
in |
638 |
val smarter_trueprop_parsing = [("Trueprop",handle_meta)] |
|
639 |
end |
|
640 |
||
641 |
local |
|
642 |
fun initial_maps thy = |
|
643 |
thy |> add_hol4_type_mapping "min" "bool" false "bool" |
|
644 |
|> add_hol4_type_mapping "min" "fun" false "fun" |
|
645 |
|> add_hol4_type_mapping "min" "ind" false "Nat.ind" |
|
646 |
|> add_hol4_const_mapping "min" "=" false "op =" |
|
647 |
|> add_hol4_const_mapping "min" "==>" false "op -->" |
|
648 |
|> add_hol4_const_mapping "min" "@" false "Hilbert_Choice.Eps" |
|
649 |
in |
|
650 |
val hol4_setup = |
|
18708 | 651 |
initial_maps #> |
652 |
Attrib.add_attributes |
|
18728 | 653 |
[("hol4rew", Attrib.no_args add_hol4_rewrite, "HOL4 rewrite rule")] |
14516 | 654 |
end |