5 in a graph with explicit dependencies. |
5 in a graph with explicit dependencies. |
6 *) |
6 *) |
7 |
7 |
8 signature CODE_PREPROC = |
8 signature CODE_PREPROC = |
9 sig |
9 sig |
10 val map_pre: (simpset -> simpset) -> theory -> theory |
10 val map_pre: (Proof.context -> Proof.context) -> theory -> theory |
11 val map_post: (simpset -> simpset) -> theory -> theory |
11 val map_post: (Proof.context -> Proof.context) -> theory -> theory |
12 val add_unfold: thm -> theory -> theory |
12 val add_unfold: thm -> theory -> theory |
13 val add_functrans: string * (theory -> (thm * bool) list -> (thm * bool) list option) -> theory -> theory |
13 val add_functrans: string * (theory -> (thm * bool) list -> (thm * bool) list option) -> theory -> theory |
14 val del_functrans: string -> theory -> theory |
14 val del_functrans: string -> theory -> theory |
15 val simple_functrans: (theory -> thm list -> thm list option) |
15 val simple_functrans: (theory -> thm list -> thm list option) |
16 -> theory -> (thm * bool) list -> (thm * bool) list option |
16 -> theory -> (thm * bool) list -> (thm * bool) list option |
77 else error ("No such " ^ msg ^ ": " ^ quote key); |
77 else error ("No such " ^ msg ^ ": " ^ quote key); |
78 |
78 |
79 val map_data = Code_Preproc_Data.map o map_thmproc; |
79 val map_data = Code_Preproc_Data.map o map_thmproc; |
80 |
80 |
81 val map_pre_post = map_data o apfst; |
81 val map_pre_post = map_data o apfst; |
82 val map_pre = map_pre_post o apfst; |
82 |
83 val map_post = map_pre_post o apsnd; |
83 fun map_simpset which f thy = |
|
84 map_pre_post (which (simpset_map (Proof_Context.init_global thy) f)) thy; |
|
85 val map_pre = map_simpset apfst; |
|
86 val map_post = map_simpset apsnd; |
84 |
87 |
85 val add_unfold = map_pre o Simplifier.add_simp; |
88 val add_unfold = map_pre o Simplifier.add_simp; |
86 val del_unfold = map_pre o Simplifier.del_simp; |
89 val del_unfold = map_pre o Simplifier.del_simp; |
87 val add_post = map_post o Simplifier.add_simp; |
90 val add_post = map_post o Simplifier.add_simp; |
88 val del_post = map_post o Simplifier.del_simp; |
91 val del_post = map_post o Simplifier.del_simp; |
89 |
92 |
90 fun add_code_abbrev raw_thm thy = |
93 fun add_code_abbrev raw_thm thy = |
91 let |
94 let |
92 val thm = Local_Defs.meta_rewrite_rule (Proof_Context.init_global thy) raw_thm; |
95 val ctxt = Proof_Context.init_global thy; |
|
96 val thm = Local_Defs.meta_rewrite_rule ctxt raw_thm; |
93 val thm_sym = Thm.symmetric thm; |
97 val thm_sym = Thm.symmetric thm; |
94 in |
98 in |
95 thy |> map_pre_post (fn (pre, post) => |
99 thy |> map_pre_post (fn (pre, post) => |
96 (pre |> Simplifier.add_simp thm_sym, post |> Simplifier.add_simp thm)) |
100 (pre |> simpset_map ctxt (Simplifier.add_simp thm_sym), |
|
101 post |> simpset_map ctxt (Simplifier.add_simp thm))) |
97 end; |
102 end; |
98 |
103 |
99 fun add_functrans (name, f) = (map_data o apsnd) |
104 fun add_functrans (name, f) = (map_data o apsnd) |
100 (AList.update (op =) (name, (serial (), f))); |
105 (AList.update (op =) (name, (serial (), f))); |
101 |
106 |
167 in |
172 in |
168 (Pretty.writeln o Pretty.chunks) [ |
173 (Pretty.writeln o Pretty.chunks) [ |
169 Pretty.block [ |
174 Pretty.block [ |
170 Pretty.str "preprocessing simpset:", |
175 Pretty.str "preprocessing simpset:", |
171 Pretty.fbrk, |
176 Pretty.fbrk, |
172 Simplifier.pretty_ss ctxt pre |
177 Simplifier.pretty_simpset (put_simpset pre ctxt) |
173 ], |
178 ], |
174 Pretty.block [ |
179 Pretty.block [ |
175 Pretty.str "postprocessing simpset:", |
180 Pretty.str "postprocessing simpset:", |
176 Pretty.fbrk, |
181 Pretty.fbrk, |
177 Simplifier.pretty_ss ctxt post |
182 Simplifier.pretty_simpset (put_simpset post ctxt) |
178 ], |
183 ], |
179 Pretty.block ( |
184 Pretty.block ( |
180 Pretty.str "function transformers:" |
185 Pretty.str "function transformers:" |
181 :: Pretty.fbrk |
186 :: Pretty.fbrk |
182 :: (Pretty.fbreaks o map Pretty.str) functrans |
187 :: (Pretty.fbreaks o map Pretty.str) functrans |
259 case try (Graph.get_node eqngr) c |
264 case try (Graph.get_node eqngr) c |
260 of SOME (lhs, cert) => ((lhs, []), cert) |
265 of SOME (lhs, cert) => ((lhs, []), cert) |
261 | NONE => let |
266 | NONE => let |
262 val functrans = (map (fn (_, (_, f)) => f thy) |
267 val functrans = (map (fn (_, (_, f)) => f thy) |
263 o #functrans o the_thmproc) thy; |
268 o #functrans o the_thmproc) thy; |
264 val pre = (Simplifier.global_context thy o #pre o the_thmproc) thy; |
269 val {pre, ...} = the_thmproc thy; |
265 val cert = Code.get_cert thy { functrans = functrans, ss = pre } c; |
270 val cert = Code.get_cert thy { functrans = functrans, ss = pre } c; |
266 val (lhs, rhss) = Code.typargs_deps_of_cert thy cert; |
271 val (lhs, rhss) = Code.typargs_deps_of_cert thy cert; |
267 in ((lhs, rhss), cert) end; |
272 in ((lhs, rhss), cert) end; |
268 |
273 |
269 fun obtain_instance thy arities (inst as (class, tyco)) = |
274 fun obtain_instance thy arities (inst as (class, tyco)) = |