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