author | wenzelm |
Tue, 03 Apr 2007 19:24:16 +0200 | |
changeset 22570 | f166a5416b3f |
parent 22554 | d1499fff65d8 |
child 22705 | 6199df39688d |
permissions | -rw-r--r-- |
20600 | 1 |
(* Title: Pure/Tools/codegen_funcgr.ML |
2 |
ID: $Id$ |
|
3 |
Author: Florian Haftmann, TU Muenchen |
|
4 |
||
22185 | 5 |
Retrieving, normalizing and structuring defining equations |
20855 | 6 |
in graph with explicit dependencies. |
20600 | 7 |
*) |
8 |
||
9 |
signature CODEGEN_FUNCGR = |
|
10 |
sig |
|
22212 | 11 |
type T |
12 |
val timing: bool ref |
|
21120 | 13 |
val funcs: T -> CodegenConsts.const -> thm list |
14 |
val typ: T -> CodegenConsts.const -> typ |
|
15 |
val deps: T -> CodegenConsts.const list -> CodegenConsts.const list list |
|
16 |
val all: T -> CodegenConsts.const list |
|
22212 | 17 |
val pretty: theory -> T -> Pretty.T |
22507 | 18 |
structure Constgraph : GRAPH |
22212 | 19 |
end |
20 |
||
21 |
signature CODEGEN_FUNCGR_RETRIEVAL = |
|
22 |
sig |
|
23 |
type T (* = CODEGEN_FUNCGR.T *) |
|
24 |
val make: theory -> CodegenConsts.const list -> T |
|
25 |
val make_consts: theory -> CodegenConsts.const list -> CodegenConsts.const list * T |
|
26 |
val make_term: theory -> (T -> (thm -> thm) -> cterm -> thm -> 'a) -> cterm -> 'a * T |
|
27 |
val init: theory -> theory |
|
20600 | 28 |
end; |
29 |
||
22212 | 30 |
structure CodegenFuncgr = (*signature is added later*) |
20600 | 31 |
struct |
32 |
||
22212 | 33 |
(** the graph type **) |
20600 | 34 |
|
35 |
structure Constgraph = GraphFun ( |
|
36 |
type key = CodegenConsts.const; |
|
37 |
val ord = CodegenConsts.const_ord; |
|
38 |
); |
|
39 |
||
40 |
type T = (typ * thm list) Constgraph.T; |
|
41 |
||
22185 | 42 |
fun funcs funcgr = |
43 |
these o Option.map snd o try (Constgraph.get_node funcgr); |
|
44 |
||
45 |
fun typ funcgr = |
|
46 |
fst o Constgraph.get_node funcgr; |
|
47 |
||
48 |
fun deps funcgr cs = |
|
49 |
let |
|
50 |
val conn = Constgraph.strong_conn funcgr; |
|
51 |
val order = rev conn; |
|
52 |
in |
|
53 |
(map o filter) (member (op =) (Constgraph.all_succs funcgr cs)) order |
|
54 |
|> filter_out null |
|
55 |
end; |
|
56 |
||
57 |
fun all funcgr = Constgraph.keys funcgr; |
|
58 |
||
22212 | 59 |
fun pretty thy funcgr = |
60 |
AList.make (snd o Constgraph.get_node funcgr) (Constgraph.keys funcgr) |
|
61 |
|> (map o apfst) (CodegenConsts.string_of_const thy) |
|
62 |
|> sort (string_ord o pairself fst) |
|
63 |
|> map (fn (s, thms) => |
|
64 |
(Pretty.block o Pretty.fbreaks) ( |
|
65 |
Pretty.str s |
|
66 |
:: map Display.pretty_thm thms |
|
67 |
)) |
|
68 |
|> Pretty.chunks; |
|
20600 | 69 |
|
70 |
||
22185 | 71 |
(** generic combinators **) |
20600 | 72 |
|
22185 | 73 |
fun fold_consts f thms = |
74 |
thms |
|
75 |
|> maps (op :: o swap o apfst (snd o strip_comb) o Logic.dest_equals o Drule.plain_prop_of) |
|
76 |
|> (fold o fold_aterms) (fn Const c => f c | _ => I); |
|
20600 | 77 |
|
22185 | 78 |
fun consts_of (const, []) = [] |
79 |
| consts_of (const, thms as thm :: _) = |
|
80 |
let |
|
81 |
val thy = Thm.theory_of_thm thm; |
|
82 |
val is_refl = curry CodegenConsts.eq_const const; |
|
22554
d1499fff65d8
simplified constant representation in code generator
haftmann
parents:
22507
diff
changeset
|
83 |
fun the_const c = case try (CodegenConsts.const_of_cexpr thy) c |
22185 | 84 |
of SOME const => if is_refl const then I else insert CodegenConsts.eq_const const |
85 |
| NONE => I |
|
86 |
in fold_consts the_const thms [] end; |
|
20600 | 87 |
|
22185 | 88 |
fun insts_of thy algebra c ty_decl ty = |
20600 | 89 |
let |
22185 | 90 |
val tys_decl = Sign.const_typargs thy (c, ty_decl); |
20600 | 91 |
val tys = Sign.const_typargs thy (c, ty); |
22570
f166a5416b3f
renamed of_sort_derivation record fields (avoid clash with Alice keywords);
wenzelm
parents:
22554
diff
changeset
|
92 |
fun class_relation (x, _) _ = x; |
f166a5416b3f
renamed of_sort_derivation record fields (avoid clash with Alice keywords);
wenzelm
parents:
22554
diff
changeset
|
93 |
fun type_constructor tyco xs class = |
20600 | 94 |
(tyco, class) :: maps (maps fst) xs; |
22570
f166a5416b3f
renamed of_sort_derivation record fields (avoid clash with Alice keywords);
wenzelm
parents:
22554
diff
changeset
|
95 |
fun type_variable (TVar (_, sort)) = map (pair []) sort |
f166a5416b3f
renamed of_sort_derivation record fields (avoid clash with Alice keywords);
wenzelm
parents:
22554
diff
changeset
|
96 |
| type_variable (TFree (_, sort)) = map (pair []) sort; |
20600 | 97 |
fun mk_inst ty (TVar (_, sort)) = cons (ty, sort) |
98 |
| mk_inst ty (TFree (_, sort)) = cons (ty, sort) |
|
22198 | 99 |
| mk_inst (Type (_, tys1)) (Type (_, tys2)) = fold2 mk_inst tys1 tys2; |
21120 | 100 |
fun of_sort_deriv (ty, sort) = |
22185 | 101 |
Sorts.of_sort_derivation (Sign.pp thy) algebra |
22570
f166a5416b3f
renamed of_sort_derivation record fields (avoid clash with Alice keywords);
wenzelm
parents:
22554
diff
changeset
|
102 |
{ class_relation = class_relation, type_constructor = type_constructor, |
f166a5416b3f
renamed of_sort_derivation record fields (avoid clash with Alice keywords);
wenzelm
parents:
22554
diff
changeset
|
103 |
type_variable = type_variable } |
21120 | 104 |
(ty, sort) |
20600 | 105 |
in |
21120 | 106 |
flat (maps of_sort_deriv (fold2 mk_inst tys tys_decl [])) |
20600 | 107 |
end; |
108 |
||
22212 | 109 |
fun drop_classes thy tfrees thm = |
110 |
let |
|
111 |
val (_, thm') = Thm.varifyT' [] thm; |
|
112 |
val tvars = Term.add_tvars (Thm.prop_of thm') []; |
|
113 |
val unconstr = map (Thm.ctyp_of thy o TVar) tvars; |
|
114 |
val instmap = map2 (fn (v_i, _) => fn (v, sort) => pairself (Thm.ctyp_of thy) |
|
115 |
(TVar (v_i, []), TFree (v, sort))) tvars tfrees; |
|
116 |
in |
|
117 |
thm' |
|
118 |
|> fold Thm.unconstrainT unconstr |
|
119 |
|> Thm.instantiate (instmap, []) |
|
120 |
|> Tactic.rule_by_tactic ((REPEAT o CHANGED o ALLGOALS o Tactic.resolve_tac) (AxClass.class_intros thy)) |
|
121 |
end; |
|
122 |
||
22039 | 123 |
|
22185 | 124 |
(** graph algorithm **) |
20600 | 125 |
|
22185 | 126 |
val timing = ref false; |
20600 | 127 |
|
22185 | 128 |
local |
20600 | 129 |
|
22185 | 130 |
exception INVALID of CodegenConsts.const list * string; |
20600 | 131 |
|
22198 | 132 |
fun resort_thms algebra tap_typ [] = [] |
133 |
| resort_thms algebra tap_typ (thms as thm :: _) = |
|
20600 | 134 |
let |
22198 | 135 |
val thy = Thm.theory_of_thm thm; |
136 |
val cs = fold_consts (insert (op =)) thms []; |
|
137 |
fun match_const c (ty, ty_decl) = |
|
20600 | 138 |
let |
22198 | 139 |
val tys = CodegenConsts.typargs thy (c, ty); |
140 |
val sorts = map (snd o dest_TVar) (CodegenConsts.typargs thy (c, ty_decl)); |
|
141 |
in fold2 (curry (CodegenConsts.typ_sort_inst algebra)) tys sorts end; |
|
142 |
fun match (c_ty as (c, ty)) = |
|
143 |
case tap_typ c_ty |
|
144 |
of SOME ty_decl => match_const c (ty, ty_decl) |
|
145 |
| NONE => I; |
|
146 |
val tvars = fold match cs Vartab.empty; |
|
147 |
in map (CodegenFunc.inst_thm tvars) thms end; |
|
20600 | 148 |
|
22198 | 149 |
fun resort_funcss thy algebra funcgr = |
150 |
let |
|
22554
d1499fff65d8
simplified constant representation in code generator
haftmann
parents:
22507
diff
changeset
|
151 |
val typ_funcgr = try (fst o Constgraph.get_node funcgr o CodegenConsts.const_of_cexpr thy); |
22198 | 152 |
fun resort_dep (const, thms) = (const, resort_thms algebra typ_funcgr thms) |
153 |
handle Sorts.CLASS_ERROR e => raise INVALID ([const], Sorts.msg_class_error (Sign.pp thy) e |
|
154 |
^ ",\nfor constant " ^ CodegenConsts.string_of_const thy const |
|
155 |
^ "\nin defining equations\n" |
|
156 |
^ (cat_lines o map string_of_thm) thms) |
|
157 |
fun resort_rec tap_typ (const, []) = (true, (const, [])) |
|
158 |
| resort_rec tap_typ (const, thms as thm :: _) = |
|
159 |
let |
|
160 |
val ty = CodegenFunc.typ_func thm; |
|
161 |
val thms' as thm' :: _ = resort_thms algebra tap_typ thms |
|
162 |
val ty' = CodegenFunc.typ_func thm'; |
|
163 |
in (Sign.typ_equiv thy (ty, ty'), (const, thms')) end; |
|
164 |
fun resort_recs funcss = |
|
165 |
let |
|
22554
d1499fff65d8
simplified constant representation in code generator
haftmann
parents:
22507
diff
changeset
|
166 |
fun tap_typ c_ty = case try (CodegenConsts.const_of_cexpr thy) c_ty |
22198 | 167 |
of SOME const => AList.lookup (CodegenConsts.eq_const) funcss const |
168 |
|> these |
|
169 |
|> try hd |
|
170 |
|> Option.map CodegenFunc.typ_func |
|
171 |
| NONE => NONE; |
|
172 |
val (unchangeds, funcss') = split_list (map (resort_rec tap_typ) funcss); |
|
173 |
val unchanged = fold (fn x => fn y => x andalso y) unchangeds true; |
|
174 |
in (unchanged, funcss') end; |
|
175 |
fun resort_rec_until funcss = |
|
176 |
let |
|
177 |
val (unchanged, funcss') = resort_recs funcss; |
|
178 |
in if unchanged then funcss' else resort_rec_until funcss' end; |
|
179 |
in map resort_dep #> resort_rec_until end; |
|
22039 | 180 |
|
22185 | 181 |
fun instances_of thy algebra insts = |
182 |
let |
|
183 |
val thy_classes = (#classes o Sorts.rep_algebra o Sign.classes_of) thy; |
|
184 |
fun all_classops tyco class = |
|
185 |
try (AxClass.params_of_class thy) class |
|
186 |
|> Option.map snd |
|
187 |
|> these |
|
22554
d1499fff65d8
simplified constant representation in code generator
haftmann
parents:
22507
diff
changeset
|
188 |
|> map (fn (c, _) => (c, SOME tyco)) |
22185 | 189 |
in |
190 |
Symtab.empty |
|
191 |
|> fold (fn (tyco, class) => |
|
192 |
Symtab.map_default (tyco, []) (insert (op =) class)) insts |
|
193 |
|> (fn tab => Symtab.fold (fn (tyco, classes) => append (maps (all_classops tyco) |
|
194 |
(Graph.all_succs thy_classes classes))) tab []) |
|
195 |
end; |
|
196 |
||
197 |
fun instances_of_consts thy algebra funcgr consts = |
|
20600 | 198 |
let |
22554
d1499fff65d8
simplified constant representation in code generator
haftmann
parents:
22507
diff
changeset
|
199 |
fun inst (cexpr as (c, ty)) = insts_of thy algebra c |
d1499fff65d8
simplified constant representation in code generator
haftmann
parents:
22507
diff
changeset
|
200 |
((fst o Constgraph.get_node funcgr o CodegenConsts.const_of_cexpr thy) cexpr) |
d1499fff65d8
simplified constant representation in code generator
haftmann
parents:
22507
diff
changeset
|
201 |
ty handle CLASS_ERROR => []; |
22185 | 202 |
in |
203 |
[] |
|
204 |
|> fold (fold (insert (op =)) o inst) consts |
|
205 |
|> instances_of thy algebra |
|
206 |
end; |
|
207 |
||
22212 | 208 |
fun ensure_const' rewrites thy algebra funcgr const auxgr = |
22185 | 209 |
if can (Constgraph.get_node funcgr) const |
210 |
then (NONE, auxgr) |
|
211 |
else if can (Constgraph.get_node auxgr) const |
|
212 |
then (SOME const, auxgr) |
|
213 |
else if is_some (CodegenData.get_datatype_of_constr thy const) then |
|
214 |
auxgr |
|
215 |
|> Constgraph.new_node (const, []) |
|
216 |
|> pair (SOME const) |
|
217 |
else let |
|
22212 | 218 |
val thms = CodegenData.these_funcs thy const |
219 |
|> map (CodegenFunc.rewrite_func (rewrites thy)) |
|
220 |
|> CodegenFunc.norm_args |
|
221 |
|> CodegenFunc.norm_varnames CodegenNames.purify_tvar CodegenNames.purify_var; |
|
22185 | 222 |
val rhs = consts_of (const, thms); |
223 |
in |
|
224 |
auxgr |
|
225 |
|> Constgraph.new_node (const, thms) |
|
22212 | 226 |
|> fold_map (ensure_const rewrites thy algebra funcgr) rhs |
22185 | 227 |
|-> (fn rhs' => fold (fn SOME const' => Constgraph.add_edge (const, const') |
228 |
| NONE => I) rhs') |
|
229 |
|> pair (SOME const) |
|
230 |
end |
|
22212 | 231 |
and ensure_const rewrites thy algebra funcgr const = |
22185 | 232 |
let |
233 |
val timeap = if !timing |
|
234 |
then Output.timeap_msg ("time for " ^ CodegenConsts.string_of_const thy const) |
|
235 |
else I; |
|
22212 | 236 |
in timeap (ensure_const' rewrites thy algebra funcgr const) end; |
22185 | 237 |
|
22212 | 238 |
fun merge_funcss rewrites thy algebra raw_funcss funcgr = |
22185 | 239 |
let |
22401 | 240 |
val funcss = raw_funcss |
241 |
|> resort_funcss thy algebra funcgr |
|
242 |
|> filter_out (can (Constgraph.get_node funcgr) o fst); |
|
22554
d1499fff65d8
simplified constant representation in code generator
haftmann
parents:
22507
diff
changeset
|
243 |
fun typ_func const [] = CodegenData.default_typ thy const |
d1499fff65d8
simplified constant representation in code generator
haftmann
parents:
22507
diff
changeset
|
244 |
| typ_func (_, NONE) (thm :: _) = CodegenFunc.typ_func thm |
d1499fff65d8
simplified constant representation in code generator
haftmann
parents:
22507
diff
changeset
|
245 |
| typ_func (const as (c, SOME tyco)) (thms as (thm :: _)) = |
d1499fff65d8
simplified constant representation in code generator
haftmann
parents:
22507
diff
changeset
|
246 |
let |
d1499fff65d8
simplified constant representation in code generator
haftmann
parents:
22507
diff
changeset
|
247 |
val ty = CodegenFunc.typ_func thm; |
d1499fff65d8
simplified constant representation in code generator
haftmann
parents:
22507
diff
changeset
|
248 |
val SOME class = AxClass.class_of_param thy c; |
d1499fff65d8
simplified constant representation in code generator
haftmann
parents:
22507
diff
changeset
|
249 |
val sorts_decl = Sorts.mg_domain algebra tyco [class]; |
d1499fff65d8
simplified constant representation in code generator
haftmann
parents:
22507
diff
changeset
|
250 |
val tys = CodegenConsts.typargs thy (c, ty); |
d1499fff65d8
simplified constant representation in code generator
haftmann
parents:
22507
diff
changeset
|
251 |
val sorts = map (snd o dest_TVar) tys; |
d1499fff65d8
simplified constant representation in code generator
haftmann
parents:
22507
diff
changeset
|
252 |
in if sorts = sorts_decl then ty |
d1499fff65d8
simplified constant representation in code generator
haftmann
parents:
22507
diff
changeset
|
253 |
else raise INVALID ([const], "Illegal instantation for class operation " |
d1499fff65d8
simplified constant representation in code generator
haftmann
parents:
22507
diff
changeset
|
254 |
^ CodegenConsts.string_of_const thy const |
d1499fff65d8
simplified constant representation in code generator
haftmann
parents:
22507
diff
changeset
|
255 |
^ "\nin defining equations\n" |
d1499fff65d8
simplified constant representation in code generator
haftmann
parents:
22507
diff
changeset
|
256 |
^ (cat_lines o map string_of_thm) thms) |
d1499fff65d8
simplified constant representation in code generator
haftmann
parents:
22507
diff
changeset
|
257 |
end; |
d1499fff65d8
simplified constant representation in code generator
haftmann
parents:
22507
diff
changeset
|
258 |
fun add_funcs (const, thms) = |
d1499fff65d8
simplified constant representation in code generator
haftmann
parents:
22507
diff
changeset
|
259 |
Constgraph.new_node (const, (typ_func const thms, thms)); |
22185 | 260 |
fun add_deps (funcs as (const, thms)) funcgr = |
261 |
let |
|
262 |
val deps = consts_of funcs; |
|
263 |
val insts = instances_of_consts thy algebra funcgr |
|
264 |
(fold_consts (insert (op =)) thms []); |
|
265 |
in |
|
266 |
funcgr |
|
22212 | 267 |
|> ensure_consts' rewrites thy algebra insts |
22185 | 268 |
|> fold (curry Constgraph.add_edge const) deps |
269 |
|> fold (curry Constgraph.add_edge const) insts |
|
270 |
end; |
|
20600 | 271 |
in |
272 |
funcgr |
|
22185 | 273 |
|> fold add_funcs funcss |
274 |
|> fold add_deps funcss |
|
20600 | 275 |
end |
22212 | 276 |
and ensure_consts' rewrites thy algebra cs funcgr = |
22401 | 277 |
let |
278 |
val auxgr = Constgraph.empty |
|
279 |
|> fold (snd oo ensure_const rewrites thy algebra funcgr) cs; |
|
280 |
in |
|
281 |
funcgr |
|
282 |
|> fold (merge_funcss rewrites thy algebra) |
|
283 |
(map (AList.make (Constgraph.get_node auxgr)) |
|
284 |
(rev (Constgraph.strong_conn auxgr))) |
|
285 |
end handle INVALID (cs', msg) |
|
286 |
=> raise INVALID (fold (insert CodegenConsts.eq_const) cs' cs, msg); |
|
20600 | 287 |
|
22212 | 288 |
fun ensure_consts rewrites thy consts funcgr = |
22185 | 289 |
let |
290 |
val algebra = CodegenData.coregular_algebra thy |
|
22212 | 291 |
in ensure_consts' rewrites thy algebra consts funcgr |
22185 | 292 |
handle INVALID (cs', msg) => error (msg ^ ",\nwhile preprocessing equations for constant(s) " |
293 |
^ commas (map (CodegenConsts.string_of_const thy) cs')) |
|
294 |
end; |
|
295 |
||
20600 | 296 |
in |
297 |
||
22212 | 298 |
(** retrieval interfaces **) |
20600 | 299 |
|
22212 | 300 |
val ensure_consts = ensure_consts; |
21120 | 301 |
|
22212 | 302 |
fun check_consts rewrites thy consts funcgr = |
22185 | 303 |
let |
304 |
val algebra = CodegenData.coregular_algebra thy; |
|
305 |
fun try_const const funcgr = |
|
22212 | 306 |
(SOME const, ensure_consts' rewrites thy algebra [const] funcgr) |
22185 | 307 |
handle INVALID (cs', msg) => (NONE, funcgr); |
22212 | 308 |
val (consts', funcgr') = fold_map try_const consts funcgr; |
309 |
in (map_filter I consts', funcgr') end; |
|
22185 | 310 |
|
22212 | 311 |
fun ensure_consts_term rewrites thy f ct funcgr = |
21120 | 312 |
let |
22554
d1499fff65d8
simplified constant representation in code generator
haftmann
parents:
22507
diff
changeset
|
313 |
fun consts_of thy t = |
d1499fff65d8
simplified constant representation in code generator
haftmann
parents:
22507
diff
changeset
|
314 |
fold_aterms (fn Const c => cons (CodegenConsts.const_of_cexpr thy c) | _ => I) t [] |
22212 | 315 |
fun rhs_conv conv thm = |
316 |
let |
|
317 |
val thm' = (conv o snd o Drule.dest_equals o Thm.cprop_of) thm; |
|
318 |
in Thm.transitive thm thm' end |
|
21120 | 319 |
val _ = Sign.no_vars (Sign.pp thy) (Thm.term_of ct); |
320 |
val _ = Term.fold_types (Type.no_tvars #> K I) (Thm.term_of ct) (); |
|
22212 | 321 |
val thm1 = CodegenData.preprocess_cterm ct |
322 |
|> fold (rhs_conv o MetaSimplifier.rewrite false o single) (rewrites thy); |
|
21120 | 323 |
val ct' = Drule.dest_equals_rhs (Thm.cprop_of thm1); |
22554
d1499fff65d8
simplified constant representation in code generator
haftmann
parents:
22507
diff
changeset
|
324 |
val consts = consts_of thy (Thm.term_of ct'); |
22212 | 325 |
val funcgr' = ensure_consts rewrites thy consts funcgr; |
22198 | 326 |
val algebra = CodegenData.coregular_algebra thy; |
21120 | 327 |
val (_, thm2) = Thm.varifyT' [] thm1; |
328 |
val thm3 = Thm.reflexive (Drule.dest_equals_rhs (Thm.cprop_of thm2)); |
|
22554
d1499fff65d8
simplified constant representation in code generator
haftmann
parents:
22507
diff
changeset
|
329 |
val typ_funcgr = try (fst o Constgraph.get_node funcgr' o CodegenConsts.const_of_cexpr thy); |
22198 | 330 |
val [thm4] = resort_thms algebra typ_funcgr [thm3]; |
21120 | 331 |
val tfrees = Term.add_tfrees (Thm.prop_of thm1) []; |
332 |
fun inst thm = |
|
333 |
let |
|
334 |
val tvars = Term.add_tvars (Thm.prop_of thm) []; |
|
335 |
val instmap = map2 (fn (v_i, sort) => fn (v, _) => pairself (Thm.ctyp_of thy) |
|
336 |
(TVar (v_i, sort), TFree (v, sort))) tvars tfrees; |
|
337 |
in Thm.instantiate (instmap, []) thm end; |
|
338 |
val thm5 = inst thm2; |
|
339 |
val thm6 = inst thm4; |
|
340 |
val ct'' = Drule.dest_equals_rhs (Thm.cprop_of thm6); |
|
341 |
val cs = fold_aterms (fn Const c => cons c | _ => I) (Thm.term_of ct'') []; |
|
342 |
val drop = drop_classes thy tfrees; |
|
22212 | 343 |
val instdefs = instances_of_consts thy algebra funcgr' cs; |
344 |
val funcgr'' = ensure_consts rewrites thy instdefs funcgr'; |
|
345 |
in (f funcgr'' drop ct'' thm5, funcgr'') end; |
|
20600 | 346 |
|
347 |
end; (*local*) |
|
348 |
||
22212 | 349 |
end; (*struct*) |
22185 | 350 |
|
22212 | 351 |
functor CodegenFuncgrRetrieval (val name: string; val rewrites: theory -> thm list) : CODEGEN_FUNCGR_RETRIEVAL = |
352 |
struct |
|
20600 | 353 |
|
22212 | 354 |
(** code data **) |
355 |
||
356 |
type T = CodegenFuncgr.T; |
|
20600 | 357 |
|
22212 | 358 |
structure Funcgr = CodeDataFun |
359 |
(struct |
|
360 |
val name = name; |
|
361 |
type T = T; |
|
362 |
val empty = CodegenFuncgr.Constgraph.empty; |
|
363 |
fun merge _ _ = CodegenFuncgr.Constgraph.empty; |
|
364 |
fun purge _ NONE _ = CodegenFuncgr.Constgraph.empty |
|
365 |
| purge _ (SOME cs) funcgr = |
|
366 |
CodegenFuncgr.Constgraph.del_nodes ((CodegenFuncgr.Constgraph.all_preds funcgr |
|
367 |
o filter (can (CodegenFuncgr.Constgraph.get_node funcgr))) cs) funcgr; |
|
368 |
end); |
|
20600 | 369 |
|
22212 | 370 |
fun make thy = |
371 |
Funcgr.change thy o CodegenFuncgr.ensure_consts rewrites thy; |
|
20600 | 372 |
|
22212 | 373 |
fun make_consts thy = |
374 |
Funcgr.change_yield thy o CodegenFuncgr.check_consts rewrites thy; |
|
375 |
||
376 |
fun make_term thy f = |
|
377 |
Funcgr.change_yield thy o CodegenFuncgr.ensure_consts_term rewrites thy f; |
|
20600 | 378 |
|
22212 | 379 |
val init = Funcgr.init; |
380 |
||
381 |
end; (*functor*) |
|
382 |
||
383 |
structure CodegenFuncgr : CODEGEN_FUNCGR = |
|
384 |
struct |
|
385 |
||
386 |
open CodegenFuncgr; |
|
20600 | 387 |
|
388 |
end; (*struct*) |