author | wenzelm |
Wed, 19 Jan 2011 21:01:37 +0100 | |
changeset 41615 | f70d2cb26acf |
parent 41346 | 6673f6fa94ca |
child 42361 | 23f352990944 |
permissions | -rw-r--r-- |
37744 | 1 |
(* Title: Tools/Code/code_simp.ML |
37442 | 2 |
Author: Florian Haftmann, TU Muenchen |
3 |
||
4 |
Connecting the simplifier and the code generator. |
|
5 |
*) |
|
6 |
||
7 |
signature CODE_SIMP = |
|
8 |
sig |
|
9 |
val map_ss: (simpset -> simpset) -> theory -> theory |
|
41247 | 10 |
val dynamic_conv: theory -> conv |
41188 | 11 |
val dynamic_tac: theory -> int -> tactic |
41184 | 12 |
val dynamic_value: theory -> term -> term |
13 |
val static_conv: theory -> simpset option -> string list -> conv |
|
41188 | 14 |
val static_tac: theory -> simpset option -> string list -> int -> tactic |
37442 | 15 |
val setup: theory -> theory |
16 |
end; |
|
17 |
||
18 |
structure Code_Simp : CODE_SIMP = |
|
19 |
struct |
|
20 |
||
21 |
(* dedicated simpset *) |
|
22 |
||
38759
37a9092de102
simplification/standardization of some theory data;
wenzelm
parents:
38671
diff
changeset
|
23 |
structure Simpset = Theory_Data |
37a9092de102
simplification/standardization of some theory data;
wenzelm
parents:
38671
diff
changeset
|
24 |
( |
37442 | 25 |
type T = simpset; |
26 |
val empty = empty_ss; |
|
41225 | 27 |
fun extend ss = Simplifier.inherit_context empty_ss ss; |
37442 | 28 |
val merge = merge_ss; |
29 |
); |
|
30 |
||
31 |
val map_ss = Simpset.map; |
|
32 |
||
37461 | 33 |
fun simpset_default thy = Simplifier.global_context thy o the_default (Simpset.get thy); |
34 |
||
37442 | 35 |
|
36 |
(* build simpset and conversion from program *) |
|
37 |
||
38 |
fun add_stmt (Code_Thingol.Fun (_, ((_, eqs), some_cong))) ss = |
|
39 |
ss addsimps (map_filter (fst o snd)) eqs addcongs (the_list some_cong) |
|
37449 | 40 |
| add_stmt (Code_Thingol.Classinst (_, (_, (classparam_instances, _)))) ss = |
41 |
ss addsimps (map (fst o snd) classparam_instances) |
|
37442 | 42 |
| add_stmt _ ss = ss; |
43 |
||
37839 | 44 |
val add_program = Graph.fold (add_stmt o fst o snd); |
37442 | 45 |
|
46 |
fun rewrite_modulo thy some_ss program = Simplifier.full_rewrite |
|
37461 | 47 |
(add_program program (simpset_default thy some_ss)); |
48 |
||
49 |
fun conclude_tac thy some_ss = Simplifier.full_simp_tac (simpset_default thy some_ss); |
|
37442 | 50 |
|
51 |
||
39486 | 52 |
(* evaluation with dynamic code context *) |
37442 | 53 |
|
41247 | 54 |
fun dynamic_conv thy = Code_Thingol.dynamic_conv thy |
55 |
(fn naming => fn program => fn t => fn deps => rewrite_modulo thy NONE program); |
|
37442 | 56 |
|
41247 | 57 |
fun dynamic_tac thy = CONVERSION (dynamic_conv thy) THEN' conclude_tac thy NONE; |
37442 | 58 |
|
41247 | 59 |
fun dynamic_value thy = snd o Logic.dest_equals o Thm.prop_of o dynamic_conv thy o Thm.cterm_of thy; |
37444 | 60 |
|
37442 | 61 |
val setup = Method.setup (Binding.name "code_simp") |
41188 | 62 |
(Scan.succeed (SIMPLE_METHOD' o (CHANGED_PROP oo dynamic_tac o ProofContext.theory_of))) |
37442 | 63 |
"simplification with code equations" |
41184 | 64 |
#> Value.add_evaluator ("simp", dynamic_value o ProofContext.theory_of); |
37442 | 65 |
|
66 |
||
39486 | 67 |
(* evaluation with static code context *) |
37442 | 68 |
|
41184 | 69 |
fun static_conv thy some_ss consts = |
70 |
Code_Thingol.static_conv_simple thy consts |
|
41346 | 71 |
(fn program => fn _ => fn _ => rewrite_modulo thy some_ss program); |
37442 | 72 |
|
41188 | 73 |
fun static_tac thy some_ss consts = CONVERSION (static_conv thy some_ss consts) |
37461 | 74 |
THEN' conclude_tac thy some_ss; |
37442 | 75 |
|
76 |
end; |