161 |> ProofContext.add_syntax fixes |
161 |> ProofContext.add_syntax fixes |
162 | activate (ctxt, Assumes asms) = |
162 | activate (ctxt, Assumes asms) = |
163 ctxt |> ProofContext.fix_frees (flat (map (map #1 o #2) asms)) |
163 ctxt |> ProofContext.fix_frees (flat (map (map #1 o #2) asms)) |
164 |> ProofContext.assume_i ProofContext.export_assume asms |> #1 |
164 |> ProofContext.assume_i ProofContext.export_assume asms |> #1 |
165 | activate (ctxt, Defines defs) = #1 (ProofContext.assume_i ProofContext.export_def |
165 | activate (ctxt, Defines defs) = #1 (ProofContext.assume_i ProofContext.export_def |
166 (map (fn (a, (t, ps)) => (a, [(ProofContext.cert_def ctxt t, (ps, []))])) defs) ctxt) |
166 (map (fn ((name, atts), (t, ps)) => |
|
167 let val (c, t') = ProofContext.cert_def ctxt t |
|
168 in ((if name = "" then Thm.def_name c else name, atts), [(t', (ps, []))]) end) defs) ctxt) |
167 | activate (ctxt, Notes facts) = #1 (ProofContext.have_thmss facts ctxt) |
169 | activate (ctxt, Notes facts) = #1 (ProofContext.have_thmss facts ctxt) |
168 | activate (ctxt, Uses name) = activate_locale_i name ctxt |
170 | activate (ctxt, Uses name) = activate_locale_i name ctxt |
169 |
171 |
170 and activate_elements_i elems ctxt = foldl activate (ctxt, elems) |
172 and activate_elements_i elems ctxt = foldl activate (ctxt, elems) |
171 |
173 |
231 | prt_elem (Notes facts) = Pretty.big_list "notes" (map prt_fact facts) |
233 | prt_elem (Notes facts) = Pretty.big_list "notes" (map prt_fact facts) |
232 | prt_elem (Uses name) = Pretty.str ("uses " ^ cond_extern sg name); |
234 | prt_elem (Uses name) = Pretty.str ("uses " ^ cond_extern sg name); |
233 |
235 |
234 val prt_header = Pretty.block (Pretty.str ("locale " ^ cond_extern sg name ^ " =") :: |
236 val prt_header = Pretty.block (Pretty.str ("locale " ^ cond_extern sg name ^ " =") :: |
235 (if null imports then [] else |
237 (if null imports then [] else |
236 (flat (separate [Pretty.str "+", Pretty.brk 1] (map (single o Pretty.str) imports)) @ |
238 (Pretty.str " " :: flat (separate [Pretty.str " +", Pretty.brk 1] |
237 [Pretty.str "+"]))); |
239 (map (single o Pretty.str o cond_extern sg) imports)) @ [Pretty.str " +"]))); |
238 in Pretty.block (Pretty.fbreaks (prt_header :: map prt_elem elements)) end; |
240 in Pretty.block (Pretty.fbreaks (prt_header :: map prt_elem elements)) end; |
239 |
241 |
240 val print_locale = Pretty.writeln oo pretty_locale; |
242 val print_locale = Pretty.writeln oo pretty_locale; |
241 |
243 |
242 |
244 |
252 fun closeup ctxt (Assumes asms) = Assumes (asms |> map (fn (a, propps) => |
254 fun closeup ctxt (Assumes asms) = Assumes (asms |> map (fn (a, propps) => |
253 (a, propps |> map (fn (t, (ps1, ps2)) => |
255 (a, propps |> map (fn (t, (ps1, ps2)) => |
254 let val close = close_frees_wrt ctxt t in (close t, (map close ps1, map close ps2)) end)))) |
256 let val close = close_frees_wrt ctxt t in (close t, (map close ps1, map close ps2)) end)))) |
255 | closeup ctxt (Defines defs) = Defines (defs |> map (fn (a, (t, ps)) => |
257 | closeup ctxt (Defines defs) = Defines (defs |> map (fn (a, (t, ps)) => |
256 let |
258 let |
257 val t' = ProofContext.cert_def ctxt t; |
259 val (_, t') = ProofContext.cert_def ctxt t; |
258 val close = close_frees_wrt ctxt t'; |
260 val close = close_frees_wrt ctxt t'; |
259 in (a, (close t', map close ps)) end)) |
261 in (a, (close t', map close ps)) end)) |
260 | closeup ctxt elem = elem; |
262 | closeup ctxt elem = elem; |
261 |
263 |
262 |
264 |
290 (** store results **) |
292 (** store results **) |
291 |
293 |
292 fun store_thm name ((a, th), atts) thy = |
294 fun store_thm name ((a, th), atts) thy = |
293 let |
295 let |
294 val {imports, elements, closed} = the_locale thy name; |
296 val {imports, elements, closed} = the_locale thy name; |
295 val _ = conditional closed |
|
296 (fn () => error ("Cannot store results in closed locale: " ^ quote name)); |
|
297 val note = Notes [((a, atts), [([Thm.name_thm (a, th)], [])])]; |
297 val note = Notes [((a, atts), [([Thm.name_thm (a, th)], [])])]; |
298 in |
298 in |
|
299 conditional closed (fn () => error ("Cannot store results in closed locale: " ^ quote name)); |
299 activate (ProofContext.init thy |> activate_locale_i name, note); (*test attribute*) |
300 activate (ProofContext.init thy |> activate_locale_i name, note); (*test attribute*) |
300 thy |> put_locale name (make_locale imports (elements @ [note]) closed) |
301 thy |> put_locale name (make_locale imports (elements @ [note]) closed) |
301 end; |
302 end; |
302 |
303 |
303 |
304 |