author | wenzelm |
Wed, 28 Feb 2007 22:05:46 +0100 | |
changeset 22380 | 7635e59e3125 |
parent 22353 | c818c6b836f5 |
child 22424 | 8a5412121687 |
permissions | -rw-r--r-- |
20894 | 1 |
(* Title: Pure/Isar/theory_target.ML |
2 |
ID: $Id$ |
|
3 |
Author: Makarius |
|
4 |
||
21594
2859c94d67d4
reworked notes: towards proper import/export of proof terms;
wenzelm
parents:
21585
diff
changeset
|
5 |
Common theory/locale targets. |
20894 | 6 |
*) |
7 |
||
8 |
signature THEORY_TARGET = |
|
9 |
sig |
|
21006 | 10 |
val peek: local_theory -> string option |
22353 | 11 |
val begin: bstring -> Proof.context -> local_theory |
20894 | 12 |
val init: xstring option -> theory -> local_theory |
13 |
val init_i: string option -> theory -> local_theory |
|
14 |
end; |
|
15 |
||
16 |
structure TheoryTarget: THEORY_TARGET = |
|
17 |
struct |
|
18 |
||
19 |
(** locale targets **) |
|
20 |
||
21006 | 21 |
(* context data *) |
22 |
||
23 |
structure Data = ProofDataFun |
|
24 |
( |
|
25 |
val name = "Isar/theory_target"; |
|
26 |
type T = string option; |
|
27 |
fun init _ = NONE; |
|
28 |
fun print _ _ = (); |
|
29 |
); |
|
30 |
||
31 |
val _ = Context.add_setup Data.init; |
|
32 |
val peek = Data.get; |
|
33 |
||
34 |
||
20894 | 35 |
(* pretty *) |
36 |
||
37 |
fun pretty loc ctxt = |
|
38 |
let |
|
39 |
val thy = ProofContext.theory_of ctxt; |
|
40 |
val fixes = map (fn (x, T) => (x, SOME T, NoSyn)) (#1 (ProofContext.inferred_fixes ctxt)); |
|
21585 | 41 |
val assumes = map (fn A => (("", []), [(A, [])])) (map Thm.term_of (Assumption.assms_of ctxt)); |
20894 | 42 |
val elems = |
43 |
(if null fixes then [] else [Element.Fixes fixes]) @ |
|
44 |
(if null assumes then [] else [Element.Assumes assumes]); |
|
45 |
in |
|
20984 | 46 |
if loc = "" then |
47 |
[Pretty.block |
|
48 |
[Pretty.str "theory", Pretty.brk 1, Pretty.str (Context.theory_name thy), |
|
49 |
Pretty.str " =", Pretty.brk 1, ThyInfo.pretty_theory thy]] |
|
50 |
else if null elems then [Pretty.str ("locale " ^ Locale.extern thy loc)] |
|
51 |
else |
|
52 |
[Pretty.big_list ("locale " ^ Locale.extern thy loc ^ " =") |
|
53 |
(map (Pretty.chunks o Element.pretty_ctxt ctxt) elems)] |
|
20894 | 54 |
end; |
55 |
||
56 |
||
21804 | 57 |
(* consts *) |
58 |
||
21825 | 59 |
fun internal_abbrev prmode ((c, mx), t) = |
22380 | 60 |
(* FIXME really permissive *) |
61 |
LocalTheory.term_syntax (perhaps o try o ProofContext.target_abbrev prmode ((c, mx), t)) #> |
|
21825 | 62 |
ProofContext.add_abbrev Syntax.internalM (c, t) #> snd; |
21804 | 63 |
|
22353 | 64 |
fun consts is_loc some_class depends decls lthy = |
21804 | 65 |
let |
66 |
val xs = filter depends (#1 (ProofContext.inferred_fixes (LocalTheory.target_of lthy))); |
|
21747 | 67 |
|
21804 | 68 |
fun const ((c, T), mx) thy = |
69 |
let |
|
70 |
val U = map #2 xs ---> T; |
|
71 |
val t = Term.list_comb (Const (Sign.full_name thy c, U), map Free xs); |
|
22353 | 72 |
val (mx1, mx2) = ClassPackage.fork_mixfix is_loc some_class mx; |
21804 | 73 |
val thy' = Sign.add_consts_authentic [(c, U, mx1)] thy; |
74 |
in (((c, mx2), t), thy') end; |
|
75 |
||
76 |
val (abbrs, lthy') = lthy |> LocalTheory.theory_result (fold_map const decls); |
|
77 |
val defs = map (apsnd (pair ("", []))) abbrs; |
|
78 |
in |
|
79 |
lthy' |
|
21825 | 80 |
|> is_loc ? fold (internal_abbrev Syntax.default_mode) abbrs |
21804 | 81 |
|> LocalDefs.add_defs defs |>> map (apsnd snd) |
82 |
end; |
|
83 |
||
84 |
||
85 |
(* abbrev *) |
|
21747 | 86 |
|
87 |
fun occ_params ctxt ts = |
|
88 |
#1 (ProofContext.inferred_fixes ctxt) |
|
89 |
|> filter (member (op =) (fold (Variable.add_fixed ctxt) ts [])); |
|
90 |
||
22353 | 91 |
fun abbrev is_loc some_class prmode ((raw_c, mx), raw_t) lthy = |
21747 | 92 |
let |
93 |
val thy_ctxt = ProofContext.init (ProofContext.theory_of lthy); |
|
94 |
val target = LocalTheory.target_of lthy; |
|
95 |
val target_morphism = LocalTheory.target_morphism lthy; |
|
96 |
||
97 |
val c = Morphism.name target_morphism raw_c; |
|
98 |
val t = Morphism.term target_morphism raw_t; |
|
99 |
val xs = map Free (occ_params target [t]); |
|
100 |
val u = fold_rev Term.lambda xs t; |
|
21804 | 101 |
val U = Term.fastype_of u; |
21747 | 102 |
val u' = singleton (Variable.export_terms (Variable.declare_term u target) thy_ctxt) u; |
103 |
||
21804 | 104 |
val ((lhs as Const (full_c, _), rhs), lthy1) = lthy |
21747 | 105 |
|> LocalTheory.theory_result (Sign.add_abbrev (#1 prmode) (c, u')); |
22353 | 106 |
val (mx1, mx2) = ClassPackage.fork_mixfix is_loc some_class mx; |
21747 | 107 |
in |
108 |
lthy1 |
|
21804 | 109 |
|> LocalTheory.theory (Sign.add_notation prmode [(lhs, mx1)]) |
21825 | 110 |
|> is_loc ? internal_abbrev prmode ((c, mx2), Term.list_comb (Const (full_c, U), xs)) |
21804 | 111 |
|> ProofContext.local_abbrev (c, rhs) |
21747 | 112 |
end; |
113 |
||
114 |
||
20894 | 115 |
(* defs *) |
116 |
||
21845 | 117 |
local |
21570 | 118 |
|
21594
2859c94d67d4
reworked notes: towards proper import/export of proof terms;
wenzelm
parents:
21585
diff
changeset
|
119 |
fun expand_term ctxt t = |
21570 | 120 |
let |
121 |
val thy = ProofContext.theory_of ctxt; |
|
122 |
val thy_ctxt = ProofContext.init thy; |
|
123 |
val ct = Thm.cterm_of thy t; |
|
21594
2859c94d67d4
reworked notes: towards proper import/export of proof terms;
wenzelm
parents:
21585
diff
changeset
|
124 |
val (defs, ct') = LocalDefs.export ctxt thy_ctxt (Drule.mk_term ct) ||> Drule.dest_term; |
21708 | 125 |
in (Thm.term_of ct', MetaSimplifier.rewrite true defs ct) end; |
21570 | 126 |
|
20894 | 127 |
fun add_def (name, prop) = |
128 |
Theory.add_defs_i false false [(name, prop)] #> |
|
129 |
(fn thy => (Drule.unvarify (Thm.get_axiom_i thy (Sign.full_name thy name)), thy)); |
|
130 |
||
131 |
in |
|
132 |
||
22353 | 133 |
fun defs loc some_class kind args lthy0 = |
20894 | 134 |
let |
21533
bada5ac1216a
simplified consts: no auxiliary params, sane mixfix syntax;
wenzelm
parents:
21498
diff
changeset
|
135 |
fun def ((c, mx), ((name, atts), rhs)) lthy1 = |
20894 | 136 |
let |
21594
2859c94d67d4
reworked notes: towards proper import/export of proof terms;
wenzelm
parents:
21585
diff
changeset
|
137 |
val (rhs', rhs_conv) = expand_term lthy0 rhs; |
21570 | 138 |
val xs = Variable.add_fixed (LocalTheory.target_of lthy0) rhs' []; |
20894 | 139 |
|
21570 | 140 |
val ([(lhs, lhs_def)], lthy2) = lthy1 |
141 |
|> LocalTheory.consts (member (op =) xs) [((c, Term.fastype_of rhs), mx)]; |
|
142 |
val lhs' = #2 (Logic.dest_equals (Thm.prop_of lhs_def)); |
|
21533
bada5ac1216a
simplified consts: no auxiliary params, sane mixfix syntax;
wenzelm
parents:
21498
diff
changeset
|
143 |
|
21570 | 144 |
val name' = Thm.def_name_optional c name; |
145 |
val (def, lthy3) = lthy2 |
|
20894 | 146 |
|> LocalTheory.theory_result (add_def (name', Logic.mk_equals (lhs', rhs'))); |
21845 | 147 |
val eq = LocalDefs.trans_terms lthy3 |
148 |
[(*c == loc.c xs*) lhs_def, |
|
149 |
(*lhs' == rhs'*) def, |
|
150 |
(*rhs' == rhs*) Thm.symmetric rhs_conv]; |
|
22353 | 151 |
val lthy4 = case some_class |
152 |
of SOME class => |
|
153 |
LocalTheory.raw_theory |
|
154 |
(ClassPackage.add_def_in_class lthy3 class |
|
155 |
((c, mx), ((name, atts), (rhs, eq)))) lthy3 |
|
156 |
| _ => lthy3; |
|
22301 | 157 |
in ((lhs, ((name', atts), [([eq], [])])), lthy4) end; |
20894 | 158 |
|
21570 | 159 |
val ((lhss, facts), lthy') = lthy0 |> fold_map def args |>> split_list; |
21433 | 160 |
val (res, lthy'') = lthy' |> LocalTheory.notes kind facts; |
20894 | 161 |
in (lhss ~~ map (apsnd the_single) res, lthy'') end; |
162 |
||
163 |
end; |
|
164 |
||
165 |
||
21611
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
166 |
(* axioms *) |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
167 |
|
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
168 |
local |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
169 |
|
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
170 |
fun add_axiom hyps (name, prop) thy = |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
171 |
let |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
172 |
val name' = if name = "" then "axiom_" ^ serial_string () else name; |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
173 |
val prop' = Logic.list_implies (hyps, prop); |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
174 |
val thy' = thy |> Theory.add_axioms_i [(name', prop')]; |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
175 |
val axm = Drule.unvarify (Thm.get_axiom_i thy' (Sign.full_name thy' name')); |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
176 |
val prems = map (Thm.assume o Thm.cterm_of thy') hyps; |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
177 |
in (Drule.implies_elim_list axm prems, thy') end; |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
178 |
|
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
179 |
in |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
180 |
|
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
181 |
fun axioms kind specs lthy = |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
182 |
let |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
183 |
val hyps = map Thm.term_of (Assumption.assms_of lthy); |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
184 |
fun axiom ((name, atts), props) thy = thy |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
185 |
|> fold_map (add_axiom hyps) (PureThy.name_multi name props) |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
186 |
|-> (fn ths => pair ((name, atts), [(ths, [])])); |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
187 |
in |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
188 |
lthy |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
189 |
|> fold (fold Variable.declare_term o snd) specs |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
190 |
|> LocalTheory.theory_result (fold_map axiom specs) |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
191 |
|-> LocalTheory.notes kind |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
192 |
end; |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
193 |
|
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
194 |
end; |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
195 |
|
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
196 |
|
20894 | 197 |
(* notes *) |
198 |
||
21611
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
199 |
fun import_export_proof ctxt (name, raw_th) = |
21594
2859c94d67d4
reworked notes: towards proper import/export of proof terms;
wenzelm
parents:
21585
diff
changeset
|
200 |
let |
21611
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
201 |
val thy = ProofContext.theory_of ctxt; |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
202 |
val thy_ctxt = ProofContext.init thy; |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
203 |
val certT = Thm.ctyp_of thy; |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
204 |
val cert = Thm.cterm_of thy; |
21594
2859c94d67d4
reworked notes: towards proper import/export of proof terms;
wenzelm
parents:
21585
diff
changeset
|
205 |
|
21611
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
206 |
(*export assumes/defines*) |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
207 |
val th = Goal.norm_result raw_th; |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
208 |
val (defs, th') = LocalDefs.export ctxt thy_ctxt th; |
21708 | 209 |
val concl_conv = MetaSimplifier.rewrite true defs (Thm.cprop_of th); |
210 |
val assms = map (MetaSimplifier.rewrite_rule defs o Thm.assume) (Assumption.assms_of ctxt); |
|
21611
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
211 |
val nprems = Thm.nprems_of th' - Thm.nprems_of th; |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
212 |
|
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
213 |
(*export fixes*) |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
214 |
val tfrees = map TFree (Drule.fold_terms Term.add_tfrees th' []); |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
215 |
val frees = map Free (Drule.fold_terms Term.add_frees th' []); |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
216 |
val (th'' :: vs) = (th' :: map (Drule.mk_term o cert) (map Logic.mk_type tfrees @ frees)) |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
217 |
|> Variable.export ctxt thy_ctxt |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
218 |
|> Drule.zero_var_indexes_list; |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
219 |
|
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
220 |
(*thm definition*) |
21644 | 221 |
val result = th'' |
222 |
|> PureThy.name_thm true true "" |
|
223 |
|> Goal.close_result |
|
224 |
|> PureThy.name_thm true true name; |
|
21611
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
225 |
|
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
226 |
(*import fixes*) |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
227 |
val (tvars, vars) = |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
228 |
chop (length tfrees) (map (Thm.term_of o Drule.dest_term) vs) |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
229 |
|>> map Logic.dest_type; |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
230 |
|
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
231 |
val instT = map_filter (fn (TVar v, T) => SOME (v, T) | _ => NONE) (tvars ~~ tfrees); |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
232 |
val inst = filter (is_Var o fst) (vars ~~ frees); |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
233 |
val cinstT = map (pairself certT o apfst TVar) instT; |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
234 |
val cinst = map (pairself (cert o Term.map_types (TermSubst.instantiateT instT))) inst; |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
235 |
val result' = Thm.instantiate (cinstT, cinst) result; |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
236 |
|
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
237 |
(*import assumes/defines*) |
21594
2859c94d67d4
reworked notes: towards proper import/export of proof terms;
wenzelm
parents:
21585
diff
changeset
|
238 |
val assm_tac = FIRST' (map (fn assm => Tactic.compose_tac (false, assm, 0)) assms); |
21611
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
239 |
val result'' = |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
240 |
(case SINGLE (Seq.INTERVAL assm_tac 1 nprems) result' of |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
241 |
NONE => raise THM ("Failed to re-import result", 0, [result']) |
21845 | 242 |
| SOME res => LocalDefs.trans_props ctxt [res, Thm.symmetric concl_conv]) |
21644 | 243 |
|> Goal.norm_result |
244 |
|> PureThy.name_thm false false name; |
|
21611
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
245 |
|
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
246 |
in (result'', result) end; |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
247 |
|
21594
2859c94d67d4
reworked notes: towards proper import/export of proof terms;
wenzelm
parents:
21585
diff
changeset
|
248 |
fun notes loc kind facts lthy = |
21585 | 249 |
let |
21594
2859c94d67d4
reworked notes: towards proper import/export of proof terms;
wenzelm
parents:
21585
diff
changeset
|
250 |
val is_loc = loc <> ""; |
2859c94d67d4
reworked notes: towards proper import/export of proof terms;
wenzelm
parents:
21585
diff
changeset
|
251 |
val thy = ProofContext.theory_of lthy; |
21615
1bd558879c44
notes: proper naming of thm proof, activated import_export_proof;
wenzelm
parents:
21613
diff
changeset
|
252 |
val full = LocalTheory.full_name lthy; |
21585 | 253 |
|
21594
2859c94d67d4
reworked notes: towards proper import/export of proof terms;
wenzelm
parents:
21585
diff
changeset
|
254 |
val facts' = facts |
21615
1bd558879c44
notes: proper naming of thm proof, activated import_export_proof;
wenzelm
parents:
21613
diff
changeset
|
255 |
|> map (fn (a, bs) => (a, PureThy.burrow_fact (PureThy.name_multi (full (fst a))) bs)) |
1bd558879c44
notes: proper naming of thm proof, activated import_export_proof;
wenzelm
parents:
21613
diff
changeset
|
256 |
|> PureThy.map_facts (import_export_proof lthy); |
21611
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
257 |
val local_facts = PureThy.map_facts #1 facts' |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
258 |
|> Attrib.map_facts (Attrib.attribute_i thy); |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
259 |
val target_facts = PureThy.map_facts #1 facts' |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
260 |
|> is_loc ? Element.facts_map (Element.morph_ctxt (LocalTheory.target_morphism lthy)); |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
261 |
val global_facts = PureThy.map_facts #2 facts' |
21594
2859c94d67d4
reworked notes: towards proper import/export of proof terms;
wenzelm
parents:
21585
diff
changeset
|
262 |
|> Attrib.map_facts (if is_loc then K I else Attrib.attribute_i thy); |
2859c94d67d4
reworked notes: towards proper import/export of proof terms;
wenzelm
parents:
21585
diff
changeset
|
263 |
in |
21611
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
264 |
lthy |> LocalTheory.theory |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
265 |
(Sign.qualified_names |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
266 |
#> PureThy.note_thmss_i kind global_facts #> snd |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
267 |
#> Sign.restore_naming thy) |
21585 | 268 |
|
21611
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
269 |
|> is_loc ? LocalTheory.target (Locale.add_thmss loc kind target_facts) |
21594
2859c94d67d4
reworked notes: towards proper import/export of proof terms;
wenzelm
parents:
21585
diff
changeset
|
270 |
|
21433 | 271 |
|> ProofContext.set_stmt true |
20894 | 272 |
|> ProofContext.qualified_names |
21611
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
273 |
|> ProofContext.note_thmss_i kind local_facts |
20894 | 274 |
||> ProofContext.restore_naming lthy |
21433 | 275 |
||> ProofContext.restore_stmt lthy |
20894 | 276 |
end; |
277 |
||
278 |
||
21533
bada5ac1216a
simplified consts: no auxiliary params, sane mixfix syntax;
wenzelm
parents:
21498
diff
changeset
|
279 |
(* target declarations *) |
20894 | 280 |
|
21611
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
281 |
fun target_decl _ "" f = |
21533
bada5ac1216a
simplified consts: no auxiliary params, sane mixfix syntax;
wenzelm
parents:
21498
diff
changeset
|
282 |
LocalTheory.theory (Context.theory_map (f Morphism.identity)) #> |
bada5ac1216a
simplified consts: no auxiliary params, sane mixfix syntax;
wenzelm
parents:
21498
diff
changeset
|
283 |
LocalTheory.target (Context.proof_map (f Morphism.identity)) |
21668 | 284 |
| target_decl add loc f = LocalTheory.target (add loc f); |
20894 | 285 |
|
21611
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
286 |
val type_syntax = target_decl Locale.add_type_syntax; |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
287 |
val term_syntax = target_decl Locale.add_term_syntax; |
fc95ff1fe738
notes: proper import/export of proofs (still inactive);
wenzelm
parents:
21594
diff
changeset
|
288 |
val declaration = target_decl Locale.add_declaration; |
20894 | 289 |
|
21533
bada5ac1216a
simplified consts: no auxiliary params, sane mixfix syntax;
wenzelm
parents:
21498
diff
changeset
|
290 |
fun target_morphism loc lthy = |
21594
2859c94d67d4
reworked notes: towards proper import/export of proof terms;
wenzelm
parents:
21585
diff
changeset
|
291 |
ProofContext.export_morphism lthy (LocalTheory.target_of lthy) $> |
21613
ae3bb930b50f
notes: more careful treatment of Goal.close_result;
wenzelm
parents:
21611
diff
changeset
|
292 |
Morphism.thm_morphism Goal.norm_result; |
21533
bada5ac1216a
simplified consts: no auxiliary params, sane mixfix syntax;
wenzelm
parents:
21498
diff
changeset
|
293 |
|
22203 | 294 |
fun target_naming loc lthy = |
21668 | 295 |
(if loc = "" then Sign.naming_of (ProofContext.theory_of lthy) |
296 |
else ProofContext.naming_of (LocalTheory.target_of lthy)) |
|
22203 | 297 |
|> NameSpace.qualified_names; |
21533
bada5ac1216a
simplified consts: no auxiliary params, sane mixfix syntax;
wenzelm
parents:
21498
diff
changeset
|
298 |
|
20894 | 299 |
|
300 |
(* init and exit *) |
|
301 |
||
22353 | 302 |
fun begin loc ctxt = |
303 |
let |
|
304 |
val thy = ProofContext.theory_of ctxt; |
|
305 |
val is_loc = loc <> ""; |
|
306 |
val some_class = ClassPackage.class_of_locale thy loc; |
|
307 |
in |
|
308 |
ctxt |
|
309 |
|> Data.put (if is_loc then SOME loc else NONE) |
|
310 |
|> LocalTheory.init (NameSpace.base loc) |
|
21747 | 311 |
{pretty = pretty loc, |
22353 | 312 |
consts = consts is_loc some_class, |
21747 | 313 |
axioms = axioms, |
22353 | 314 |
abbrev = abbrev is_loc some_class, |
315 |
defs = defs loc some_class, |
|
21747 | 316 |
notes = notes loc, |
317 |
type_syntax = type_syntax loc, |
|
318 |
term_syntax = term_syntax loc, |
|
319 |
declaration = declaration loc, |
|
320 |
target_morphism = target_morphism loc, |
|
22203 | 321 |
target_naming = target_naming loc, |
21804 | 322 |
reinit = fn _ => |
22353 | 323 |
begin loc o (if is_loc then Locale.init loc else ProofContext.init), |
21747 | 324 |
exit = LocalTheory.target_of} |
325 |
end; |
|
20894 | 326 |
|
22353 | 327 |
fun init_i NONE thy = begin "" (ProofContext.init thy) |
328 |
| init_i (SOME loc) thy = begin loc (Locale.init loc thy); |
|
20894 | 329 |
|
21276 | 330 |
fun init (SOME "-") thy = init_i NONE thy |
331 |
| init loc thy = init_i (Option.map (Locale.intern thy) loc) thy; |
|
20894 | 332 |
|
333 |
end; |