35 val const_of = dest_Const o head_of o fst o dest_eqn; |
35 val const_of = dest_Const o head_of o fst o dest_eqn; |
36 |
36 |
37 fun warn thm = warning ("RecfunCodegen: Not a proper equation:\n" ^ |
37 fun warn thm = warning ("RecfunCodegen: Not a proper equation:\n" ^ |
38 string_of_thm thm); |
38 string_of_thm thm); |
39 |
39 |
40 fun add optmod = Thm.declaration_attribute (fn thm => Context.map_theory (fn thy => |
40 fun add optmod = Thm.declaration_attribute (fn thm => Context.map_theory |
41 let |
41 let |
42 val tab = CodegenData.get thy; |
42 fun add thm = |
43 val (s, _) = const_of (prop_of thm); |
43 if Pattern.pattern (lhs_of thm) then |
|
44 CodegenData.map |
|
45 (Symtab.update_list ((fst o const_of o prop_of) thm, (thm, optmod))) |
|
46 else tap (fn _ => warn thm) |
|
47 handle TERM _ => tap (fn _ => warn thm); |
44 in |
48 in |
45 if Pattern.pattern (lhs_of thm) then |
49 add thm |
46 CodegenData.put (Symtab.update_list (s, (thm, optmod)) tab) thy |
50 #> CodegenTheorems.add_fun thm |
47 else (warn thm; thy) |
51 end); |
48 end handle TERM _ => (warn thm; thy))); |
|
49 |
52 |
50 val del = Thm.declaration_attribute (fn thm => Context.map_theory (fn thy => |
53 fun del_thm thm thy = |
51 let |
54 let |
52 val tab = CodegenData.get thy; |
55 val tab = CodegenData.get thy; |
53 val (s, _) = const_of (prop_of thm); |
56 val (s, _) = const_of (prop_of thm); |
54 in case Symtab.lookup tab s of |
57 in case Symtab.lookup tab s of |
55 NONE => thy |
58 NONE => thy |
56 | SOME thms => |
59 | SOME thms => |
57 CodegenData.put (Symtab.update (s, gen_rem (eq_thm o apfst fst) (thms, thm)) tab) thy |
60 CodegenData.put (Symtab.update (s, gen_rem (eq_thm o apfst fst) (thms, thm)) tab) thy |
58 end handle TERM _ => (warn thm; thy))); |
61 end handle TERM _ => (warn thm; thy); |
|
62 |
|
63 val del = Thm.declaration_attribute |
|
64 (fn thm => Context.map_theory (del_thm thm #> CodegenTheorems.del_def thm)) |
59 |
65 |
60 fun del_redundant thy eqs [] = eqs |
66 fun del_redundant thy eqs [] = eqs |
61 | del_redundant thy eqs (eq :: eqs') = |
67 | del_redundant thy eqs (eq :: eqs') = |
62 let |
68 let |
63 val matches = curry |
69 val matches = curry |