author | haftmann |
Tue, 25 Jul 2006 16:43:47 +0200 | |
changeset 20191 | b43fd26e1aaa |
parent 20175 | 0a8ca32f6e64 |
child 20192 | 956cd30ef3be |
permissions | -rw-r--r-- |
19341
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
1 |
(* Title: Pure/Tools/codegen_theorems.ML |
19280
5091dc43817b
slight improvement in serializer, stub for code generator theorems added
haftmann
parents:
diff
changeset
|
2 |
ID: $Id$ |
5091dc43817b
slight improvement in serializer, stub for code generator theorems added
haftmann
parents:
diff
changeset
|
3 |
Author: Florian Haftmann, TU Muenchen |
5091dc43817b
slight improvement in serializer, stub for code generator theorems added
haftmann
parents:
diff
changeset
|
4 |
|
5091dc43817b
slight improvement in serializer, stub for code generator theorems added
haftmann
parents:
diff
changeset
|
5 |
Theorems used for code generation. |
5091dc43817b
slight improvement in serializer, stub for code generator theorems added
haftmann
parents:
diff
changeset
|
6 |
*) |
5091dc43817b
slight improvement in serializer, stub for code generator theorems added
haftmann
parents:
diff
changeset
|
7 |
|
5091dc43817b
slight improvement in serializer, stub for code generator theorems added
haftmann
parents:
diff
changeset
|
8 |
signature CODEGEN_THEOREMS = |
5091dc43817b
slight improvement in serializer, stub for code generator theorems added
haftmann
parents:
diff
changeset
|
9 |
sig |
19884 | 10 |
val add_notify: ((string * typ) list option -> theory -> theory) -> theory -> theory; |
19280
5091dc43817b
slight improvement in serializer, stub for code generator theorems added
haftmann
parents:
diff
changeset
|
11 |
val add_preproc: (theory -> thm list -> thm list) -> theory -> theory; |
19341
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
12 |
val add_fun_extr: (theory -> string * typ -> thm list) -> theory -> theory; |
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
13 |
val add_datatype_extr: (theory -> string |
19597 | 14 |
-> (((string * sort) list * (string * typ list) list) * tactic) option) |
19341
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
15 |
-> theory -> theory; |
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
16 |
val add_fun: thm -> theory -> theory; |
19597 | 17 |
val del_fun: thm -> theory -> theory; |
19280
5091dc43817b
slight improvement in serializer, stub for code generator theorems added
haftmann
parents:
diff
changeset
|
18 |
val add_unfold: thm -> theory -> theory; |
19341
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
19 |
val del_unfold: thm -> theory -> theory; |
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
20 |
val purge_defs: string * typ -> theory -> theory; |
19597 | 21 |
val notify_dirty: theory -> theory; |
19341
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
22 |
|
19953
2f54a51f1801
class package refinements, slight code generation refinements
haftmann
parents:
19897
diff
changeset
|
23 |
val extr_typ: theory -> thm -> typ; |
19341
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
24 |
val common_typ: theory -> (thm -> typ) -> thm list -> thm list; |
19953
2f54a51f1801
class package refinements, slight code generation refinements
haftmann
parents:
19897
diff
changeset
|
25 |
val preprocess: theory -> thm list -> thm list; |
19597 | 26 |
|
19953
2f54a51f1801
class package refinements, slight code generation refinements
haftmann
parents:
19897
diff
changeset
|
27 |
val get_funs: theory -> string * typ -> thm list; |
19341
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
28 |
val get_datatypes: theory -> string |
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
29 |
-> (((string * sort) list * (string * typ list) list) * thm list) option; |
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
30 |
|
19597 | 31 |
type thmtab; |
20191 | 32 |
val mk_thmtab: (string * typ) list -> theory -> thmtab * theory; |
33 |
val norm_typ: theory -> string * typ -> string * typ; |
|
34 |
val get_sortalgebra: thmtab -> Sorts.algebra; |
|
35 |
val get_dtyp_of_cons: thmtab -> string * typ -> string option; |
|
36 |
val get_dtyp_spec: thmtab -> string |
|
37 |
-> ((string * sort) list * (string * typ list) list) option; |
|
38 |
val get_fun_thms: thmtab -> string * typ -> thm list; |
|
39 |
||
19597 | 40 |
val print_thms: theory -> unit; |
41 |
||
42 |
val init_obj: (thm * thm) * (thm * thm) -> theory -> theory; |
|
19341
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
43 |
val debug: bool ref; |
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
44 |
val debug_msg: ('a -> string) -> 'a -> 'a; |
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
45 |
|
19280
5091dc43817b
slight improvement in serializer, stub for code generator theorems added
haftmann
parents:
diff
changeset
|
46 |
end; |
5091dc43817b
slight improvement in serializer, stub for code generator theorems added
haftmann
parents:
diff
changeset
|
47 |
|
5091dc43817b
slight improvement in serializer, stub for code generator theorems added
haftmann
parents:
diff
changeset
|
48 |
structure CodegenTheorems: CODEGEN_THEOREMS = |
5091dc43817b
slight improvement in serializer, stub for code generator theorems added
haftmann
parents:
diff
changeset
|
49 |
struct |
5091dc43817b
slight improvement in serializer, stub for code generator theorems added
haftmann
parents:
diff
changeset
|
50 |
|
19597 | 51 |
(** preliminaries **) |
52 |
||
53 |
(* diagnostics *) |
|
19280
5091dc43817b
slight improvement in serializer, stub for code generator theorems added
haftmann
parents:
diff
changeset
|
54 |
|
19341
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
55 |
val debug = ref false; |
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
56 |
fun debug_msg f x = (if !debug then Output.debug (f x) else (); x); |
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
57 |
|
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
58 |
|
19597 | 59 |
(* auxiliary *) |
19341
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
60 |
|
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
61 |
fun getf_first [] _ = NONE |
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
62 |
| getf_first (f::fs) x = case f x |
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
63 |
of NONE => getf_first fs x |
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
64 |
| y as SOME x => y; |
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
65 |
|
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
66 |
fun getf_first_list [] x = [] |
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
67 |
| getf_first_list (f::fs) x = case f x |
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
68 |
of [] => getf_first_list fs x |
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
69 |
| xs => xs; |
19597 | 70 |
|
71 |
||
72 |
(* object logic setup *) |
|
73 |
||
74 |
structure CodegenTheoremsSetup = TheoryDataFun |
|
75 |
(struct |
|
19953
2f54a51f1801
class package refinements, slight code generation refinements
haftmann
parents:
19897
diff
changeset
|
76 |
val name = "Pure/codegen_theorems_setup"; |
19597 | 77 |
type T = ((string * thm) * ((string * string) * (string * string))) option; |
78 |
val empty = NONE; |
|
79 |
val copy = I; |
|
80 |
val extend = I; |
|
81 |
fun merge pp = merge_opt (eq_pair (eq_pair (op =) eq_thm) |
|
82 |
(eq_pair (eq_pair (op =) (op =)) (eq_pair (op =) (op =)))) : T * T -> T; |
|
83 |
fun print thy data = (); |
|
84 |
end); |
|
85 |
||
86 |
val _ = Context.add_setup CodegenTheoremsSetup.init; |
|
87 |
||
88 |
fun init_obj ((TrueI, FalseE), (conjI, atomize_eq)) thy = |
|
89 |
case CodegenTheoremsSetup.get thy |
|
90 |
of SOME _ => error "code generator already set up for object logic" |
|
20191 | 91 |
| NONE => |
19597 | 92 |
let |
93 |
fun strip_implies t = (Logic.strip_imp_prems t, Logic.strip_imp_concl t); |
|
94 |
fun dest_TrueI thm = |
|
95 |
Drule.plain_prop_of thm |
|
96 |
|> ObjectLogic.drop_judgment thy |
|
97 |
|> Term.dest_Const |
|
98 |
|> apsnd ( |
|
99 |
Term.dest_Type |
|
100 |
#> fst |
|
101 |
); |
|
102 |
fun dest_FalseE thm = |
|
103 |
Drule.plain_prop_of thm |
|
104 |
|> Logic.dest_implies |
|
105 |
|> apsnd ( |
|
106 |
ObjectLogic.drop_judgment thy |
|
107 |
#> Term.dest_Var |
|
108 |
) |
|
109 |
|> fst |
|
110 |
|> ObjectLogic.drop_judgment thy |
|
111 |
|> Term.dest_Const |
|
112 |
|> fst; |
|
113 |
fun dest_conjI thm = |
|
114 |
Drule.plain_prop_of thm |
|
115 |
|> strip_implies |
|
116 |
|> apfst (map (ObjectLogic.drop_judgment thy #> Term.dest_Var)) |
|
117 |
|> apsnd ( |
|
118 |
ObjectLogic.drop_judgment thy |
|
119 |
#> Term.strip_comb |
|
120 |
#> apsnd (map Term.dest_Var) |
|
121 |
#> apfst Term.dest_Const |
|
122 |
) |
|
123 |
|> (fn (v1, ((conj, _), v2)) => if v1 = v2 then conj else error "wrong premise") |
|
20191 | 124 |
fun dest_atomize_eq thm= |
19597 | 125 |
Drule.plain_prop_of thm |
126 |
|> Logic.dest_equals |
|
127 |
|> apfst ( |
|
128 |
ObjectLogic.drop_judgment thy |
|
129 |
#> Term.strip_comb |
|
130 |
#> apsnd (map Term.dest_Var) |
|
131 |
#> apfst Term.dest_Const |
|
132 |
) |
|
133 |
|> apsnd ( |
|
134 |
Logic.dest_equals |
|
135 |
#> apfst Term.dest_Var |
|
136 |
#> apsnd Term.dest_Var |
|
137 |
) |
|
138 |
|> (fn (((eq, _), v2), (v1a as (_, TVar (_, sort)), v1b)) => |
|
139 |
if [v1a, v1b] = v2 andalso sort = Sign.defaultS thy then eq else error "wrong premise") |
|
140 |
in |
|
141 |
((dest_TrueI TrueI, [dest_FalseE FalseE, dest_conjI conjI, dest_atomize_eq atomize_eq]) |
|
142 |
handle _ => error "bad code generator setup") |
|
143 |
|> (fn ((tr, b), [fl, con, eq]) => CodegenTheoremsSetup.put |
|
144 |
(SOME ((b, atomize_eq), ((tr, fl), (con, eq)))) thy) |
|
145 |
end; |
|
146 |
||
147 |
fun get_obj thy = |
|
148 |
case CodegenTheoremsSetup.get thy |
|
149 |
of SOME ((b, atomize), x) => ((Type (b, []), atomize) ,x) |
|
150 |
| NONE => error "no object logic setup for code theorems"; |
|
151 |
||
152 |
fun mk_true thy = |
|
153 |
let |
|
154 |
val ((b, _), ((tr, fl), (con, eq))) = get_obj thy; |
|
155 |
in Const (tr, b) end; |
|
156 |
||
157 |
fun mk_false thy = |
|
158 |
let |
|
159 |
val ((b, _), ((tr, fl), (con, eq))) = get_obj thy; |
|
160 |
in Const (fl, b) end; |
|
161 |
||
162 |
fun mk_obj_conj thy (x, y) = |
|
163 |
let |
|
164 |
val ((b, _), ((tr, fl), (con, eq))) = get_obj thy; |
|
165 |
in Const (con, b --> b --> b) $ x $ y end; |
|
166 |
||
167 |
fun mk_obj_eq thy (x, y) = |
|
168 |
let |
|
169 |
val ((b, _), ((tr, fl), (con, eq))) = get_obj thy; |
|
20105 | 170 |
in Const (eq, fastype_of x --> fastype_of y --> b) $ x $ y end; |
19597 | 171 |
|
172 |
fun is_obj_eq thy c = |
|
173 |
let |
|
174 |
val ((b, _), ((tr, fl), (con, eq))) = get_obj thy; |
|
175 |
in c = eq end; |
|
176 |
||
177 |
fun mk_func thy ((x, y), rhs) = |
|
178 |
Logic.mk_equals ( |
|
179 |
(mk_obj_eq thy (x, y)), |
|
180 |
rhs |
|
181 |
); |
|
182 |
||
183 |
||
184 |
(* theorem purification *) |
|
185 |
||
186 |
fun err_thm msg thm = |
|
187 |
error (msg ^ ": " ^ string_of_thm thm); |
|
188 |
||
189 |
fun abs_norm thy thm = |
|
190 |
let |
|
191 |
fun expvars t = |
|
192 |
let |
|
193 |
val lhs = (fst o Logic.dest_equals) t; |
|
20105 | 194 |
val tys = (fst o strip_type o fastype_of) lhs; |
19597 | 195 |
val used = fold_aterms (fn Var ((v, _), _) => insert (op =) v | _ => I) lhs []; |
20076 | 196 |
val vs = Name.invent_list used "x" (length tys); |
19597 | 197 |
in |
198 |
map2 (fn v => fn ty => Var ((v, 0), ty)) vs tys |
|
199 |
end; |
|
200 |
fun expand ct thm = |
|
201 |
Thm.combination thm (Thm.reflexive ct); |
|
202 |
fun beta_norm thm = |
|
203 |
thm |
|
204 |
|> prop_of |
|
205 |
|> Logic.dest_equals |
|
206 |
|> fst |
|
207 |
|> cterm_of thy |
|
208 |
|> Thm.beta_conversion true |
|
209 |
|> Thm.symmetric |
|
210 |
|> (fn thm' => Thm.transitive thm' thm); |
|
211 |
in |
|
212 |
thm |
|
213 |
|> fold (expand o cterm_of thy) ((expvars o prop_of) thm) |
|
214 |
|> beta_norm |
|
215 |
end; |
|
216 |
||
217 |
fun canonical_tvars thy thm = |
|
218 |
let |
|
219 |
fun mk_inst (v_i as (v, i), (v', sort)) (s as (maxidx, set, acc)) = |
|
220 |
if v = v' orelse member (op =) set v then s |
|
221 |
else let |
|
222 |
val ty = TVar (v_i, sort) |
|
223 |
in |
|
224 |
(maxidx + 1, v :: set, |
|
225 |
(ctyp_of thy ty, ctyp_of thy (TVar ((v', maxidx), sort))) :: acc) |
|
226 |
end; |
|
20175 | 227 |
val lower_name = implode o map (Char.toString o Char.toLower o the o Char.fromString) |
228 |
o explode o Name.alphanum; |
|
19597 | 229 |
fun tvars_of thm = (fold_types o fold_atyps) |
230 |
(fn TVar (v_i as (v, i), sort) => cons (v_i, (lower_name v, sort)) |
|
231 |
| _ => I) (prop_of thm) []; |
|
232 |
val maxidx = Thm.maxidx_of thm + 1; |
|
233 |
val (_, _, inst) = fold mk_inst (tvars_of thm) (maxidx + 1, [], []); |
|
234 |
in Thm.instantiate (inst, []) thm end; |
|
235 |
||
236 |
fun canonical_vars thy thm = |
|
237 |
let |
|
238 |
fun mk_inst (v_i as (v, i), (v', ty)) (s as (maxidx, set, acc)) = |
|
239 |
if v = v' orelse member (op =) set v then s |
|
240 |
else let |
|
241 |
val t = if i = ~1 then Free (v, ty) else Var (v_i, ty) |
|
20191 | 242 |
in |
19597 | 243 |
(maxidx + 1, v :: set, |
244 |
(cterm_of thy t, cterm_of thy (Var ((v', maxidx), ty))) :: acc) |
|
245 |
end; |
|
20175 | 246 |
val lower_name = implode o map (Char.toString o Char.toLower o the o Char.fromString) |
247 |
o explode o Name.alphanum; |
|
19597 | 248 |
fun vars_of thm = fold_aterms |
249 |
(fn Var (v_i as (v, i), ty) => cons (v_i, (lower_name v, ty)) |
|
250 |
| _ => I) (prop_of thm) []; |
|
251 |
val maxidx = Thm.maxidx_of thm + 1; |
|
252 |
val (_, _, inst) = fold mk_inst (vars_of thm) (maxidx + 1, [], []); |
|
253 |
in Thm.instantiate ([], inst) thm end; |
|
254 |
||
19884 | 255 |
fun drop_redundant thy eqs = |
256 |
let |
|
257 |
val matches = curry (Pattern.matches thy o |
|
258 |
pairself (fst o Logic.dest_equals o prop_of)) |
|
259 |
fun drop eqs [] = eqs |
|
260 |
| drop eqs (eq::eqs') = |
|
261 |
drop (eq::eqs) (filter_out (matches eq) eqs') |
|
262 |
in drop [] eqs end; |
|
263 |
||
20191 | 264 |
fun make_eq thy = |
19597 | 265 |
let |
266 |
val ((_, atomize), _) = get_obj thy; |
|
267 |
in rewrite_rule [atomize] end; |
|
268 |
||
269 |
fun dest_eq thy thm = |
|
270 |
case try (make_eq thy #> Drule.plain_prop_of |
|
271 |
#> ObjectLogic.drop_judgment thy #> Logic.dest_equals) thm |
|
272 |
of SOME eq => (eq, thm) |
|
273 |
| NONE => err_thm "not an equation" thm; |
|
274 |
||
275 |
fun dest_fun thy thm = |
|
276 |
let |
|
277 |
fun dest_fun' ((lhs, _), thm) = |
|
278 |
case try (dest_Const o fst o strip_comb) lhs |
|
279 |
of SOME (c, ty) => (c, (ty, thm)) |
|
280 |
| NONE => err_thm "not a function equation" thm; |
|
281 |
in |
|
282 |
thm |
|
283 |
|> dest_eq thy |
|
284 |
|> dest_fun' |
|
285 |
end; |
|
286 |
||
287 |
||
19280
5091dc43817b
slight improvement in serializer, stub for code generator theorems added
haftmann
parents:
diff
changeset
|
288 |
|
5091dc43817b
slight improvement in serializer, stub for code generator theorems added
haftmann
parents:
diff
changeset
|
289 |
(** theory data **) |
5091dc43817b
slight improvement in serializer, stub for code generator theorems added
haftmann
parents:
diff
changeset
|
290 |
|
19597 | 291 |
(* data structures *) |
292 |
||
293 |
fun merge' eq (xys as (xs, ys)) = |
|
294 |
if eq_list eq (xs, ys) then (false, xs) else (true, merge eq xys); |
|
295 |
||
296 |
fun alist_merge' eq_key eq (xys as (xs, ys)) = |
|
297 |
if eq_list (eq_pair eq_key eq) (xs, ys) then (false, xs) else (true, AList.merge eq_key eq xys); |
|
298 |
||
299 |
fun list_symtab_join' eq (xyt as (xt, yt)) = |
|
300 |
let |
|
301 |
val xc = Symtab.keys xt; |
|
302 |
val yc = Symtab.keys yt; |
|
303 |
val zc = filter (member (op =) yc) xc; |
|
304 |
val wc = subtract (op =) zc xc @ subtract (op =) zc yc; |
|
305 |
fun same_thms c = if eq_list eq_thm ((the o Symtab.lookup xt) c, (the o Symtab.lookup yt) c) |
|
306 |
then NONE else SOME c; |
|
307 |
in (wc @ map_filter same_thms zc, Symtab.join (K (merge eq)) xyt) end; |
|
308 |
||
19884 | 309 |
datatype notify = Notify of (serial * ((string * typ) list option -> theory -> theory)) list; |
19597 | 310 |
|
311 |
val mk_notify = Notify; |
|
312 |
fun map_notify f (Notify notify) = mk_notify (f notify); |
|
313 |
fun merge_notify pp (Notify notify1, Notify notify2) = |
|
314 |
mk_notify (AList.merge (op =) (K true) (notify1, notify2)); |
|
315 |
||
316 |
datatype preproc = Preproc of { |
|
19280
5091dc43817b
slight improvement in serializer, stub for code generator theorems added
haftmann
parents:
diff
changeset
|
317 |
preprocs: (serial * (theory -> thm list -> thm list)) list, |
19597 | 318 |
unfolds: thm list |
19280
5091dc43817b
slight improvement in serializer, stub for code generator theorems added
haftmann
parents:
diff
changeset
|
319 |
}; |
5091dc43817b
slight improvement in serializer, stub for code generator theorems added
haftmann
parents:
diff
changeset
|
320 |
|
19597 | 321 |
fun mk_preproc (preprocs, unfolds) = |
322 |
Preproc { preprocs = preprocs, unfolds = unfolds }; |
|
323 |
fun map_preproc f (Preproc { preprocs, unfolds }) = |
|
324 |
mk_preproc (f (preprocs, unfolds)); |
|
325 |
fun merge_preproc _ (Preproc { preprocs = preprocs1, unfolds = unfolds1 }, |
|
326 |
Preproc { preprocs = preprocs2, unfolds = unfolds2 }) = |
|
327 |
let |
|
328 |
val (dirty1, preprocs) = alist_merge' (op =) (K true) (preprocs1, preprocs2); |
|
329 |
val (dirty2, unfolds) = merge' eq_thm (unfolds1, unfolds2); |
|
330 |
in (dirty1 orelse dirty2, mk_preproc (preprocs, unfolds)) end; |
|
19280
5091dc43817b
slight improvement in serializer, stub for code generator theorems added
haftmann
parents:
diff
changeset
|
331 |
|
19341
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
332 |
datatype extrs = Extrs of { |
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
333 |
funs: (serial * (theory -> string * typ -> thm list)) list, |
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
334 |
datatypes: (serial * (theory -> string -> (((string * sort) list * (string * typ list) list) * tactic) option)) list |
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
335 |
}; |
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
336 |
|
19597 | 337 |
fun mk_extrs (funs, datatypes) = |
338 |
Extrs { funs = funs, datatypes = datatypes }; |
|
339 |
fun map_extrs f (Extrs { funs, datatypes }) = |
|
340 |
mk_extrs (f (funs, datatypes)); |
|
19341
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
341 |
fun merge_extrs _ (Extrs { funs = funs1, datatypes = datatypes1 }, |
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
342 |
Extrs { funs = funs2, datatypes = datatypes2 }) = |
19597 | 343 |
let |
344 |
val (dirty1, funs) = alist_merge' (op =) (K true) (funs1, funs2); |
|
345 |
val (dirty2, datatypes) = alist_merge' (op =) (K true) (datatypes1, datatypes2); |
|
346 |
in (dirty1 orelse dirty2, mk_extrs (funs, datatypes)) end; |
|
19341
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
347 |
|
19597 | 348 |
datatype funthms = Funthms of { |
349 |
dirty: string list, |
|
350 |
funs: thm list Symtab.table |
|
19280
5091dc43817b
slight improvement in serializer, stub for code generator theorems added
haftmann
parents:
diff
changeset
|
351 |
}; |
5091dc43817b
slight improvement in serializer, stub for code generator theorems added
haftmann
parents:
diff
changeset
|
352 |
|
19597 | 353 |
fun mk_funthms (dirty, funs) = |
354 |
Funthms { dirty = dirty, funs = funs }; |
|
355 |
fun map_funthms f (Funthms { dirty, funs }) = |
|
356 |
mk_funthms (f (dirty, funs)); |
|
357 |
fun merge_funthms _ (Funthms { dirty = dirty1, funs = funs1 }, |
|
358 |
Funthms { dirty = dirty2, funs = funs2 }) = |
|
359 |
let |
|
360 |
val (dirty3, funs) = list_symtab_join' eq_thm (funs1, funs2); |
|
361 |
in mk_funthms (merge (op =) (merge (op =) (dirty1, dirty2), dirty3), funs) end; |
|
19280
5091dc43817b
slight improvement in serializer, stub for code generator theorems added
haftmann
parents:
diff
changeset
|
362 |
|
19597 | 363 |
datatype T = T of { |
364 |
dirty: bool, |
|
365 |
notify: notify, |
|
366 |
preproc: preproc, |
|
367 |
extrs: extrs, |
|
368 |
funthms: funthms |
|
19341
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
369 |
}; |
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
370 |
|
19597 | 371 |
fun mk_T ((dirty, notify), (preproc, (extrs, funthms))) = |
20191 | 372 |
T { dirty = dirty, notify = notify, preproc= preproc, extrs = extrs, funthms = funthms }; |
19597 | 373 |
fun map_T f (T { dirty, notify, preproc, extrs, funthms }) = |
374 |
mk_T (f ((dirty, notify), (preproc, (extrs, funthms)))); |
|
375 |
fun merge_T pp (T { dirty = dirty1, notify = notify1, preproc = preproc1, extrs = extrs1, funthms = funthms1 }, |
|
376 |
T { dirty = dirty2, notify = notify2, preproc = preproc2, extrs = extrs2, funthms = funthms2 }) = |
|
377 |
let |
|
378 |
val (dirty3, preproc) = merge_preproc pp (preproc1, preproc2); |
|
379 |
val (dirty4, extrs) = merge_extrs pp (extrs1, extrs2); |
|
380 |
in |
|
381 |
mk_T ((dirty1 orelse dirty2 orelse dirty3 orelse dirty4, merge_notify pp (notify1, notify2)), |
|
382 |
(preproc, (extrs, merge_funthms pp (funthms1, funthms2)))) |
|
383 |
end; |
|
19280
5091dc43817b
slight improvement in serializer, stub for code generator theorems added
haftmann
parents:
diff
changeset
|
384 |
|
19597 | 385 |
|
386 |
(* setup *) |
|
19280
5091dc43817b
slight improvement in serializer, stub for code generator theorems added
haftmann
parents:
diff
changeset
|
387 |
|
19597 | 388 |
structure CodegenTheoremsData = TheoryDataFun |
19280
5091dc43817b
slight improvement in serializer, stub for code generator theorems added
haftmann
parents:
diff
changeset
|
389 |
(struct |
19953
2f54a51f1801
class package refinements, slight code generation refinements
haftmann
parents:
19897
diff
changeset
|
390 |
val name = "Pure/codegen_theorems_data"; |
19280
5091dc43817b
slight improvement in serializer, stub for code generator theorems added
haftmann
parents:
diff
changeset
|
391 |
type T = T; |
19597 | 392 |
val empty = mk_T ((false, mk_notify []), (mk_preproc ([], []), |
393 |
(mk_extrs ([], []), mk_funthms ([], Symtab.empty)))); |
|
19280
5091dc43817b
slight improvement in serializer, stub for code generator theorems added
haftmann
parents:
diff
changeset
|
394 |
val copy = I; |
5091dc43817b
slight improvement in serializer, stub for code generator theorems added
haftmann
parents:
diff
changeset
|
395 |
val extend = I; |
5091dc43817b
slight improvement in serializer, stub for code generator theorems added
haftmann
parents:
diff
changeset
|
396 |
val merge = merge_T; |
19341
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
397 |
fun print (thy : theory) (data : T) = |
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
398 |
let |
19436 | 399 |
val pretty_thm = ProofContext.pretty_thm (ProofContext.init thy); |
19597 | 400 |
val funthms = (fn T { funthms, ... } => funthms) data; |
401 |
val funs = (Symtab.dest o (fn Funthms { funs, ... } => funs)) funthms; |
|
402 |
val preproc = (fn T { preproc, ... } => preproc) data; |
|
403 |
val unfolds = (fn Preproc { unfolds, ... } => unfolds) preproc; |
|
19341
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
404 |
in |
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
405 |
(Pretty.writeln o Pretty.block o Pretty.fbreaks) ([ |
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
406 |
Pretty.str "code generation theorems:", |
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
407 |
Pretty.str "function theorems:" ] @ |
19597 | 408 |
(*Pretty.fbreaks ( *) |
20191 | 409 |
map (fn (c, thms) => |
19341
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
410 |
(Pretty.block o Pretty.fbreaks) ( |
19884 | 411 |
Pretty.str c :: map pretty_thm (rev thms) |
19341
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
412 |
) |
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
413 |
) funs |
19597 | 414 |
(*) *) @ [ |
415 |
Pretty.fbrk, |
|
416 |
Pretty.block ( |
|
417 |
Pretty.str "unfolding theorems:" |
|
418 |
:: Pretty.fbrk |
|
419 |
:: (Pretty.fbreaks o map pretty_thm) unfolds |
|
420 |
)]) |
|
19341
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
421 |
end; |
19280
5091dc43817b
slight improvement in serializer, stub for code generator theorems added
haftmann
parents:
diff
changeset
|
422 |
end); |
5091dc43817b
slight improvement in serializer, stub for code generator theorems added
haftmann
parents:
diff
changeset
|
423 |
|
19597 | 424 |
val _ = Context.add_setup CodegenTheoremsData.init; |
425 |
val print_thms = CodegenTheoremsData.print; |
|
426 |
||
427 |
||
428 |
(* accessors *) |
|
19280
5091dc43817b
slight improvement in serializer, stub for code generator theorems added
haftmann
parents:
diff
changeset
|
429 |
|
19341
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
430 |
local |
19597 | 431 |
val the_preproc = (fn T { preproc = Preproc preproc, ... } => preproc) o CodegenTheoremsData.get; |
432 |
val the_extrs = (fn T { extrs = Extrs extrs, ... } => extrs) o CodegenTheoremsData.get; |
|
433 |
val the_funthms = (fn T { funthms = Funthms funthms, ... } => funthms) o CodegenTheoremsData.get; |
|
19341
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
434 |
in |
19597 | 435 |
val is_dirty = (fn T { dirty = dirty, ... } => dirty) o CodegenTheoremsData.get; |
436 |
val the_dirty_consts = (fn { dirty = dirty, ... } => dirty) o the_funthms; |
|
437 |
val the_notify = (fn T { notify = Notify notify, ... } => map snd notify) o CodegenTheoremsData.get; |
|
438 |
val the_preprocs = (fn { preprocs, ... } => map snd preprocs) o the_preproc; |
|
439 |
val the_unfolds = (fn { unfolds, ... } => unfolds) o the_preproc; |
|
19341
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
440 |
val the_funs_extrs = (fn { funs, ... } => map snd funs) o the_extrs; |
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
441 |
val the_datatypes_extrs = (fn { datatypes, ... } => map snd datatypes) o the_extrs; |
19597 | 442 |
val the_funs = (fn { funs, ... } => funs) o the_funthms; |
19341
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
443 |
end (*local*); |
19280
5091dc43817b
slight improvement in serializer, stub for code generator theorems added
haftmann
parents:
diff
changeset
|
444 |
|
19597 | 445 |
val map_data = CodegenTheoremsData.map o map_T; |
446 |
||
447 |
(* notifiers *) |
|
448 |
||
19884 | 449 |
fun all_typs thy c = |
450 |
map (pair c) (Sign.the_const_type thy c :: (map (#lhs) o Theory.definitions_of thy) c); |
|
451 |
||
19280
5091dc43817b
slight improvement in serializer, stub for code generator theorems added
haftmann
parents:
diff
changeset
|
452 |
fun add_notify f = |
19597 | 453 |
map_data (fn ((dirty, notify), x) => |
454 |
((dirty, notify |> map_notify (cons (serial (), f))), x)); |
|
455 |
||
456 |
fun get_reset_dirty thy = |
|
457 |
let |
|
458 |
val dirty = is_dirty thy; |
|
459 |
val dirty_const = if dirty then [] else the_dirty_consts thy; |
|
460 |
in |
|
461 |
thy |
|
462 |
|> map_data (fn ((_, notify), (procs, (extrs, funthms))) => |
|
463 |
((false, notify), (procs, (extrs, funthms |> map_funthms (fn (_, funs) => ([], funs)))))) |
|
464 |
|> pair (dirty, dirty_const) |
|
465 |
end; |
|
19280
5091dc43817b
slight improvement in serializer, stub for code generator theorems added
haftmann
parents:
diff
changeset
|
466 |
|
5091dc43817b
slight improvement in serializer, stub for code generator theorems added
haftmann
parents:
diff
changeset
|
467 |
fun notify_all c thy = |
19597 | 468 |
thy |
469 |
|> get_reset_dirty |
|
470 |
|-> (fn (true, _) => fold (fn f => f NONE) (the_notify thy) |
|
19884 | 471 |
| (false, cs) => let val cs' = case c of NONE => cs | SOME c => insert (op =) c cs |
472 |
in fold (fn f => f (SOME (maps (all_typs thy) cs'))) (the_notify thy) end); |
|
19597 | 473 |
|
474 |
fun notify_dirty thy = |
|
475 |
thy |
|
476 |
|> get_reset_dirty |
|
477 |
|-> (fn (true, _) => fold (fn f => f NONE) (the_notify thy) |
|
19884 | 478 |
| (false, cs) => fold (fn f => f (SOME (maps (all_typs thy) cs))) (the_notify thy)); |
19597 | 479 |
|
480 |
||
481 |
(* modifiers *) |
|
19280
5091dc43817b
slight improvement in serializer, stub for code generator theorems added
haftmann
parents:
diff
changeset
|
482 |
|
5091dc43817b
slight improvement in serializer, stub for code generator theorems added
haftmann
parents:
diff
changeset
|
483 |
fun add_preproc f = |
19597 | 484 |
map_data (fn (x, (preproc, y)) => |
485 |
(x, (preproc |> map_preproc (fn (preprocs, unfolds) => ((serial (), f) :: preprocs, unfolds)), y))) |
|
19280
5091dc43817b
slight improvement in serializer, stub for code generator theorems added
haftmann
parents:
diff
changeset
|
486 |
#> notify_all NONE; |
5091dc43817b
slight improvement in serializer, stub for code generator theorems added
haftmann
parents:
diff
changeset
|
487 |
|
19341
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
488 |
fun add_fun_extr f = |
19597 | 489 |
map_data (fn (x, (preproc, (extrs, funthms))) => |
490 |
(x, (preproc, (extrs |> map_extrs (fn (funs, datatypes) => |
|
491 |
((serial (), f) :: funs, datatypes)), funthms)))) |
|
19341
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
492 |
#> notify_all NONE; |
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
493 |
|
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
494 |
fun add_datatype_extr f = |
19597 | 495 |
map_data (fn (x, (preproc, (extrs, funthms))) => |
496 |
(x, (preproc, (extrs |> map_extrs (fn (funs, datatypes) => |
|
497 |
(funs, (serial (), f) :: datatypes)), funthms)))) |
|
19341
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
498 |
#> notify_all NONE; |
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
499 |
|
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
500 |
fun add_fun thm thy = |
19597 | 501 |
case dest_fun thy thm |
502 |
of (c, _) => |
|
503 |
thy |
|
504 |
|> map_data (fn (x, (preproc, (extrs, funthms))) => |
|
505 |
(x, (preproc, (extrs, funthms |> map_funthms (fn (dirty, funs) => |
|
19884 | 506 |
(dirty, funs |> Symtab.default (c, []) |> Symtab.map_entry c (cons thm))))))) |
19597 | 507 |
|> notify_all (SOME c); |
19341
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
508 |
|
19597 | 509 |
fun del_fun thm thy = |
510 |
case dest_fun thy thm |
|
511 |
of (c, _) => |
|
512 |
thy |
|
513 |
|> map_data (fn (x, (preproc, (extrs, funthms))) => |
|
514 |
(x, (preproc, (extrs, funthms |> map_funthms (fn (dirty, funs) => |
|
515 |
(dirty, funs |> Symtab.map_entry c (remove eq_thm thm))))))) |
|
516 |
|> notify_all (SOME c); |
|
19341
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
517 |
|
19597 | 518 |
fun add_unfold thm thy = |
519 |
thy |
|
520 |
|> tap (fn thy => dest_eq thy thm) |
|
521 |
|> map_data (fn (x, (preproc, y)) => |
|
522 |
(x, (preproc |> map_preproc (fn (preprocs, unfolds) => |
|
523 |
(preprocs, thm :: unfolds)), y))) |
|
524 |
|> notify_all NONE; |
|
19341
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
525 |
|
20191 | 526 |
fun del_unfold thm = |
19597 | 527 |
map_data (fn (x, (preproc, y)) => |
528 |
(x, (preproc |> map_preproc (fn (preprocs, unfolds) => |
|
529 |
(preprocs, remove eq_thm thm unfolds)), y))) |
|
19341
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
530 |
#> notify_all NONE; |
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
531 |
|
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
532 |
fun purge_defs (c, ty) thy = |
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
533 |
thy |
19597 | 534 |
|> map_data (fn (x, (preproc, (extrs, funthms))) => |
535 |
(x, (preproc, (extrs, funthms |> map_funthms (fn (dirty, funs) => |
|
536 |
(dirty, funs |> Symtab.map_entry c |
|
537 |
(filter (fn thm => Sign.typ_instance thy |
|
538 |
((fst o snd o dest_fun thy) thm, ty))))))))) |
|
19341
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
539 |
|> notify_all (SOME c); |
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
540 |
|
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
541 |
|
19597 | 542 |
|
543 |
(** theorem handling **) |
|
544 |
||
545 |
(* preprocessing *) |
|
19341
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
546 |
|
19953
2f54a51f1801
class package refinements, slight code generation refinements
haftmann
parents:
19897
diff
changeset
|
547 |
fun extr_typ thy thm = case dest_fun thy thm |
2f54a51f1801
class package refinements, slight code generation refinements
haftmann
parents:
19897
diff
changeset
|
548 |
of (_, (ty, _)) => ty; |
2f54a51f1801
class package refinements, slight code generation refinements
haftmann
parents:
19897
diff
changeset
|
549 |
|
20191 | 550 |
fun rewrite_rhs conv thm = (case (Drule.strip_comb o cprop_of) thm |
551 |
of (ct', [ct1, ct2]) => (case term_of ct' |
|
552 |
of Const ("==", _) => |
|
553 |
Thm.equal_elim (combination (combination (reflexive ct') (reflexive ct1)) |
|
554 |
(conv ct2)) thm |
|
555 |
| _ => raise ERROR "rewrite_rhs") |
|
556 |
| _ => raise ERROR "rewrite_rhs"); |
|
557 |
||
19341
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
558 |
fun common_typ thy _ [] = [] |
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
559 |
| common_typ thy _ [thm] = [thm] |
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
560 |
| common_typ thy extract_typ thms = |
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
561 |
let |
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
562 |
fun incr_thm thm max = |
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
563 |
let |
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
564 |
val thm' = incr_indexes max thm; |
20105 | 565 |
val max' = (maxidx_of_typ o fastype_of o Drule.plain_prop_of) thm' + 1; |
19341
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
566 |
in (thm', max') end; |
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
567 |
val (thms', maxidx) = fold_map incr_thm thms 0; |
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
568 |
val (ty1::tys) = map extract_typ thms; |
19436 | 569 |
fun unify ty = Sign.typ_unify thy (ty1, ty); |
19341
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
570 |
val (env, _) = fold unify tys (Vartab.empty, maxidx) |
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
571 |
val instT = Vartab.fold (fn (x_i, (sort, ty)) => |
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
572 |
cons (Thm.ctyp_of thy (TVar (x_i, sort)), Thm.ctyp_of thy ty)) env []; |
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
573 |
in map (Thm.instantiate (instT, [])) thms end; |
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
574 |
|
19816
a8c8ed1c85e0
removed 'primitive definitions' added (non)strict generation, minor fixes
haftmann
parents:
19806
diff
changeset
|
575 |
fun preprocess thy thms = |
19341
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
576 |
let |
19597 | 577 |
fun burrow_thms f [] = [] |
20191 | 578 |
| burrow_thms f thms = |
19597 | 579 |
thms |
580 |
|> Conjunction.intr_list |
|
581 |
|> f |
|
582 |
|> Conjunction.elim_list; |
|
19884 | 583 |
fun cmp_thms (thm1, thm2) = |
19953
2f54a51f1801
class package refinements, slight code generation refinements
haftmann
parents:
19897
diff
changeset
|
584 |
not (Sign.typ_instance thy (extr_typ thy thm1, extr_typ thy thm2)); |
19884 | 585 |
fun unvarify thms = |
19897
fe661eb3b0e7
ProofContext: moved variable operations to struct Variable;
wenzelm
parents:
19884
diff
changeset
|
586 |
#1 (Variable.import true thms (ProofContext.init thy)); |
19816
a8c8ed1c85e0
removed 'primitive definitions' added (non)strict generation, minor fixes
haftmann
parents:
19806
diff
changeset
|
587 |
val unfold_thms = Tactic.rewrite true (map (make_eq thy) (the_unfolds thy)); |
19341
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
588 |
in |
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
589 |
thms |
19597 | 590 |
|> map (make_eq thy) |
591 |
|> map (Thm.transfer thy) |
|
592 |
|> fold (fn f => f thy) (the_preprocs thy) |
|
19816
a8c8ed1c85e0
removed 'primitive definitions' added (non)strict generation, minor fixes
haftmann
parents:
19806
diff
changeset
|
593 |
|> map (rewrite_rhs unfold_thms) |
19884 | 594 |
|> debug_msg (fn _ => "[cg_thm] sorting") |
19597 | 595 |
|> debug_msg (commas o map string_of_thm) |
19884 | 596 |
|> sort (make_ord cmp_thms) |
19816
a8c8ed1c85e0
removed 'primitive definitions' added (non)strict generation, minor fixes
haftmann
parents:
19806
diff
changeset
|
597 |
|> debug_msg (fn _ => "[cg_thm] common_typ") |
19597 | 598 |
|> debug_msg (commas o map string_of_thm) |
19953
2f54a51f1801
class package refinements, slight code generation refinements
haftmann
parents:
19897
diff
changeset
|
599 |
|> common_typ thy (extr_typ thy) |
19816
a8c8ed1c85e0
removed 'primitive definitions' added (non)strict generation, minor fixes
haftmann
parents:
19806
diff
changeset
|
600 |
|> debug_msg (fn _ => "[cg_thm] abs_norm") |
19597 | 601 |
|> debug_msg (commas o map string_of_thm) |
19816
a8c8ed1c85e0
removed 'primitive definitions' added (non)strict generation, minor fixes
haftmann
parents:
19806
diff
changeset
|
602 |
|> map (abs_norm thy) |
19597 | 603 |
|> burrow_thms ( |
604 |
debug_msg (fn _ => "[cg_thm] canonical tvars") |
|
605 |
#> debug_msg (string_of_thm) |
|
606 |
#> canonical_tvars thy |
|
607 |
#> debug_msg (fn _ => "[cg_thm] canonical vars") |
|
608 |
#> debug_msg (string_of_thm) |
|
609 |
#> canonical_vars thy |
|
610 |
#> debug_msg (fn _ => "[cg_thm] zero indices") |
|
611 |
#> debug_msg (string_of_thm) |
|
612 |
#> Drule.zero_var_indexes |
|
613 |
) |
|
19884 | 614 |
|> drop_redundant thy |
19280
5091dc43817b
slight improvement in serializer, stub for code generator theorems added
haftmann
parents:
diff
changeset
|
615 |
end; |
5091dc43817b
slight improvement in serializer, stub for code generator theorems added
haftmann
parents:
diff
changeset
|
616 |
|
19341
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
617 |
|
19597 | 618 |
(* retrieval *) |
19341
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
619 |
|
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
620 |
fun get_funs thy (c, ty) = |
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
621 |
let |
19597 | 622 |
val _ = debug_msg (fn _ => "[cg_thm] const (1) " ^ c ^ " :: " ^ Sign.string_of_typ thy ty) () |
623 |
val filter_typ = map_filter (fn (_, (ty', thm)) => |
|
624 |
if Sign.typ_instance thy (ty, ty') |
|
625 |
then SOME thm else debug_msg (fn _ => "[cg_thm] dropping " ^ string_of_thm thm) NONE); |
|
626 |
fun get_funs (c, ty) = |
|
19341
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
627 |
(these o Symtab.lookup (the_funs thy)) c |
19597 | 628 |
|> debug_msg (fn _ => "[cg_thm] trying funs") |
19341
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
629 |
|> map (dest_fun thy) |
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
630 |
|> filter_typ; |
19597 | 631 |
fun get_extr (c, ty) = |
632 |
getf_first_list (map (fn f => f thy) (the_funs_extrs thy)) (c, ty) |
|
633 |
|> debug_msg (fn _ => "[cg_thm] trying extr") |
|
634 |
|> map (dest_fun thy) |
|
635 |
|> filter_typ; |
|
636 |
fun get_spec (c, ty) = |
|
637 |
Theory.definitions_of thy c |
|
638 |
|> debug_msg (fn _ => "[cg_thm] trying spec") |
|
639 |
(* FIXME avoid dynamic name space lookup!? (via Thm.get_axiom_i etc.??) *) |
|
640 |
|> maps (PureThy.get_thms thy o Name o #name) |
|
641 |
|> map_filter (try (dest_fun thy)) |
|
642 |
|> filter_typ; |
|
19341
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
643 |
in |
19597 | 644 |
getf_first_list [get_funs, get_extr, get_spec] (c, ty) |
645 |
|> debug_msg (fn _ => "[cg_thm] const (2) " ^ c ^ " :: " ^ Sign.string_of_typ thy ty) |
|
646 |
|> preprocess thy |
|
19341
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
647 |
end; |
19280
5091dc43817b
slight improvement in serializer, stub for code generator theorems added
haftmann
parents:
diff
changeset
|
648 |
|
19341
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
649 |
fun get_datatypes thy dtco = |
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
650 |
let |
19597 | 651 |
val _ = debug_msg (fn _ => "[cg_thm] datatype " ^ dtco) () |
652 |
val truh = mk_true thy; |
|
653 |
val fals = mk_false thy; |
|
19341
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
654 |
fun mk_lhs vs ((co1, tys1), (co2, tys2)) = |
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
655 |
let |
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
656 |
val dty = Type (dtco, map TFree vs); |
20076 | 657 |
val (xs1, xs2) = chop (length tys1) (Name.invent_list [] "x" (length tys1 + length tys2)); |
19341
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
658 |
val frees1 = map2 (fn x => fn ty => Free (x, ty)) xs1 tys1; |
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
659 |
val frees2 = map2 (fn x => fn ty => Free (x, ty)) xs2 tys2; |
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
660 |
fun zip_co co xs tys = list_comb (Const (co, |
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
661 |
tys ---> dty), map2 (fn x => fn ty => Free (x, ty)) xs tys); |
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
662 |
in |
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
663 |
((frees1, frees2), (zip_co co1 xs1 tys1, zip_co co2 xs2 tys2)) |
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
664 |
end; |
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
665 |
fun mk_rhs [] [] = truh |
19597 | 666 |
| mk_rhs xs ys = foldr1 (mk_obj_conj thy) (map2 (curry (mk_obj_eq thy)) xs ys); |
19341
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
667 |
fun mk_eq vs (args as ((co1, _), (co2, _))) (inj, dist) = |
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
668 |
if co1 = co2 |
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
669 |
then let |
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
670 |
val ((fs1, fs2), lhs) = mk_lhs vs args; |
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
671 |
val rhs = mk_rhs fs1 fs2; |
19597 | 672 |
in (mk_func thy (lhs, rhs) :: inj, dist) end |
19341
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
673 |
else let |
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
674 |
val (_, lhs) = mk_lhs vs args; |
19597 | 675 |
in (inj, mk_func thy (lhs, fals) :: dist) end; |
19341
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
676 |
fun mk_eqs (vs, cos) = |
20191 | 677 |
let val cos' = rev cos |
19341
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
678 |
in (op @) (fold (mk_eq vs) (product cos' cos') ([], [])) end; |
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
679 |
fun mk_eq_thms tac vs_cos = |
20046 | 680 |
map (fn t => Goal.prove_global thy [] [] |
681 |
(ObjectLogic.ensure_propT thy t) (K tac)) (mk_eqs vs_cos); |
|
19341
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
682 |
in |
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
683 |
case getf_first (map (fn f => f thy) (the_datatypes_extrs thy)) dtco |
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
684 |
of NONE => NONE |
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
685 |
| SOME (vs_cos, tac) => SOME (vs_cos, mk_eq_thms tac vs_cos) |
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
686 |
end; |
19280
5091dc43817b
slight improvement in serializer, stub for code generator theorems added
haftmann
parents:
diff
changeset
|
687 |
|
19341
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
688 |
fun get_eq thy (c, ty) = |
19597 | 689 |
if is_obj_eq thy c |
19816
a8c8ed1c85e0
removed 'primitive definitions' added (non)strict generation, minor fixes
haftmann
parents:
19806
diff
changeset
|
690 |
then case strip_type ty |
a8c8ed1c85e0
removed 'primitive definitions' added (non)strict generation, minor fixes
haftmann
parents:
19806
diff
changeset
|
691 |
of (Type (tyco, _) :: _, _) => |
a8c8ed1c85e0
removed 'primitive definitions' added (non)strict generation, minor fixes
haftmann
parents:
19806
diff
changeset
|
692 |
(case get_datatypes thy tyco |
a8c8ed1c85e0
removed 'primitive definitions' added (non)strict generation, minor fixes
haftmann
parents:
19806
diff
changeset
|
693 |
of SOME (_, thms) => thms |
a8c8ed1c85e0
removed 'primitive definitions' added (non)strict generation, minor fixes
haftmann
parents:
19806
diff
changeset
|
694 |
| _ => []) |
19341
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
695 |
| _ => [] |
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
696 |
else []; |
19280
5091dc43817b
slight improvement in serializer, stub for code generator theorems added
haftmann
parents:
diff
changeset
|
697 |
|
20191 | 698 |
structure ConstTab = TableFun(type key = string * typ val ord = prod_ord fast_string_ord Term.typ_ord); |
699 |
structure ConstGraph = GraphFun(type key = string * typ val ord = prod_ord fast_string_ord Term.typ_ord); |
|
700 |
||
701 |
type thmtab = (theory * (thm list ConstGraph.T |
|
702 |
* string ConstTab.table) |
|
703 |
* (Sorts.algebra * ((string * sort) list * (string * typ list) list) Symtab.table)); |
|
704 |
||
705 |
fun thmtab_empty thy = (thy, (ConstGraph.empty, ConstTab.empty), |
|
706 |
(ClassPackage.operational_algebra thy, Symtab.empty)); |
|
707 |
||
708 |
fun norm_typ thy (c, ty) = |
|
709 |
(*more clever: use ty_insts*) |
|
710 |
case get_first (fn ty' => if Sign.typ_instance thy (ty, (*Logic.varifyT*) ty') |
|
711 |
then SOME ty' else NONE) (map #lhs (Theory.definitions_of thy c)) |
|
712 |
of NONE => (c, ty) |
|
713 |
| SOME ty => (c, ty); |
|
714 |
||
715 |
fun get_sortalgebra (_, _, (algebra, _)) = |
|
716 |
algebra; |
|
19597 | 717 |
|
20191 | 718 |
fun get_dtyp_of_cons (thy, (_, dtcotab), _) (c, ty) = |
719 |
let |
|
720 |
val (_, ty') = norm_typ thy (c, ty); |
|
721 |
in ConstTab.lookup dtcotab (c, ty') end; |
|
722 |
||
723 |
fun get_dtyp_spec (_, _, (_, dttab)) tyco = |
|
724 |
Symtab.lookup dttab tyco; |
|
725 |
||
726 |
fun has_fun_thms (thy, (fungr, _), _) (c, ty) = |
|
727 |
let |
|
728 |
val (_, ty') = norm_typ thy (c, ty); |
|
729 |
in can (ConstGraph.get_node fungr) (c, ty') end; |
|
730 |
||
731 |
fun get_fun_thms (thy, (fungr, _), _) (c, ty) = |
|
732 |
let |
|
733 |
val (_, ty') = norm_typ thy (c, ty); |
|
734 |
in these (try (ConstGraph.get_node fungr) (c, ty')) end; |
|
735 |
||
736 |
fun mk_thmtab' thy cs = |
|
19597 | 737 |
let |
20191 | 738 |
fun get_dtco_candidate ty = |
739 |
case strip_type ty |
|
740 |
of (_, Type (tyco, _)) => SOME tyco |
|
741 |
| _ => NONE; |
|
742 |
fun add_tycos (Type (tyco, tys)) = insert (op =) tyco #> fold add_tycos tys |
|
743 |
| add_tycos _ = I; |
|
744 |
val add_consts = fold_aterms |
|
745 |
(fn Const c_ty => insert (op =) (norm_typ thy c_ty) |
|
746 |
| _ => I); |
|
747 |
fun add_dtyps_of_type ty thmtab = |
|
748 |
let |
|
749 |
val tycos = add_tycos ty []; |
|
750 |
val tycos_new = filter (is_some o get_dtyp_spec thmtab) tycos; |
|
751 |
fun add_dtyp_spec dtco (dtyp_spec as (vs, cs)) ((thy, (fungr, dtcotab), (algebra, dttab))) = |
|
752 |
let |
|
753 |
fun mk_co (c, tys) = |
|
754 |
(c, Logic.varifyT (tys ---> Type (dtco, map TFree vs))); |
|
755 |
in |
|
756 |
(thy, (fungr, dtcotab |> fold (fn c_tys => ConstTab.update_new (mk_co c_tys, dtco)) cs), |
|
757 |
(algebra, dttab |> Symtab.update_new (dtco, dtyp_spec))) |
|
758 |
end; |
|
759 |
in |
|
760 |
thmtab |
|
761 |
|> fold (fn tyco => case get_datatypes thy tyco |
|
762 |
of SOME (dtyp_spec, _) => add_dtyp_spec tyco dtyp_spec |
|
763 |
| NONE => I) tycos_new |
|
764 |
end; |
|
765 |
fun known thmtab (c, ty) = |
|
766 |
is_some (get_dtyp_of_cons thmtab (c, ty)) orelse has_fun_thms thmtab (c, ty); |
|
767 |
fun add_funthms (c, ty) (thmtab as (thy, (fungr, dtcotab), algebra_dttab))= |
|
768 |
if known thmtab (norm_typ thy (c, ty)) then thmtab |
|
769 |
else let |
|
770 |
val thms = get_funs thy (c, ty) |
|
771 |
val cs_dep = fold (add_consts o Thm.prop_of) thms []; |
|
772 |
in |
|
773 |
(thy, (fungr |> ConstGraph.new_node ((c, ty), thms) |
|
774 |
, dtcotab), algebra_dttab) |
|
775 |
|> fold add_c cs_dep |
|
776 |
end |
|
777 |
and add_c (c, ty) thmtab = |
|
778 |
let |
|
779 |
val (_, ty') = norm_typ thy (c, ty); |
|
780 |
in |
|
781 |
thmtab |
|
782 |
|> add_dtyps_of_type ty |
|
783 |
|> add_funthms (c, ty) |
|
784 |
end; |
|
785 |
fun narrow_typs fungr = |
|
786 |
let |
|
787 |
(* |
|
788 |
(*!!!remember whether any instantiation had been applied!!!*) |
|
789 |
fun narrow_thms insts thms = |
|
790 |
let |
|
791 |
val (c_def, ty_def) = |
|
792 |
(norm_typ thy o dest_Const o fst o Logic.dest_equals o Thm.prop_of o hd) thms; |
|
793 |
val cs = fold (add_consts o snd o Logic.dest_equals o Thm.prop_of) thms []; |
|
794 |
fun eval_inst c (inst, ty) = |
|
795 |
let |
|
796 |
val inst_ctxt = Sign.const_typargs thy (c, ty); |
|
797 |
val inst_zip = fold (fn (v, ty) => (ty, (the o AList.lookup (op =) inst_ctxt) v)) inst |
|
798 |
fun add_inst (ty_inst, ty_ctxt) = |
|
799 |
if Sign.typ_instance thy (ty_inst, ty_ctxt) |
|
800 |
then I |
|
801 |
else Sign.typ_match thy (ty_ctxt, ty_inst); |
|
802 |
in fold add_inst inst_zip end; |
|
803 |
val inst = |
|
804 |
Vartab.empty |
|
805 |
|> fold (fn c_ty as (c, ty) => |
|
806 |
case ConstTab.lookup insts (norm_typ thy c_ty) |
|
807 |
of NONE => I |
|
808 |
| SOME inst => eval_inst c (inst, ty)) cs |
|
809 |
|> Vartab.dest |
|
810 |
|> map (fn (v, (_, ty)) => (v, ty)); |
|
811 |
val instT = map (fn (v, ty) => |
|
812 |
(Thm.ctyp_of thy (TVar v, Thm.ctyp_of thy ty))) inst; |
|
813 |
val thms' = |
|
814 |
if null inst then NONE thms else |
|
815 |
map Thm.instantiate (instT, []) thms; |
|
816 |
val inst' = if null inst then NONE |
|
817 |
else SOME inst; |
|
818 |
in (inst', thms') end; |
|
819 |
fun narrow_css [c] (insts, fungr) = |
|
820 |
(* HIER GEHTS WEITER *) |
|
821 |
(insts, fungr) |
|
822 |
| narrow_css css (insts, fungr) = |
|
823 |
(insts, fungr) |
|
824 |
*) |
|
825 |
val css = rev (Graph.strong_conn fungr); |
|
826 |
in |
|
827 |
(ConstTab.empty, fungr) |
|
828 |
(*|> fold narrow_css css*) |
|
829 |
|> snd |
|
830 |
end; |
|
831 |
in |
|
832 |
thmtab_empty thy |
|
833 |
|> fold add_c cs |
|
834 |
(* |> (apfst o apfst) narrow_typs *) |
|
835 |
end; |
|
19597 | 836 |
|
20191 | 837 |
fun mk_thmtab cs thy = |
19597 | 838 |
thy |
839 |
|> get_reset_dirty |
|
20191 | 840 |
|> snd |
841 |
|> `(fn thy => mk_thmtab' thy cs); |
|
19597 | 842 |
|
19280
5091dc43817b
slight improvement in serializer, stub for code generator theorems added
haftmann
parents:
diff
changeset
|
843 |
|
19341
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
844 |
(** code attributes and setup **) |
19280
5091dc43817b
slight improvement in serializer, stub for code generator theorems added
haftmann
parents:
diff
changeset
|
845 |
|
19341
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
846 |
local |
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
847 |
fun add_simple_attribute (name, f) = |
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
848 |
(Codegen.add_attribute name o (Scan.succeed o Thm.declaration_attribute)) |
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
849 |
(Context.map_theory o f); |
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
850 |
in |
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
851 |
val _ = map (Context.add_setup o add_simple_attribute) [ |
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
852 |
("fun", add_fun), |
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
853 |
("unfold", (fn thm => Codegen.add_unfold thm #> add_unfold thm)), |
20105 | 854 |
("inline", add_unfold), |
19341
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
855 |
("nofold", del_unfold) |
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
856 |
] |
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
857 |
end; (*local*) |
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
858 |
|
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
859 |
val _ = Context.add_setup (add_fun_extr get_eq); |
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
860 |
|
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19280
diff
changeset
|
861 |
end; (*struct*) |