28 \isamarkuptrue% |
28 \isamarkuptrue% |
29 % |
29 % |
30 \begin{isamarkuptext}% |
30 \begin{isamarkuptext}% |
31 The Isar toplevel may be considered the centeral hub of the |
31 The Isar toplevel may be considered the centeral hub of the |
32 Isabelle/Isar system, where all key components and sub-systems are |
32 Isabelle/Isar system, where all key components and sub-systems are |
33 integrated into a single read-eval-print loop of Isar commands. |
33 integrated into a single read-eval-print loop of Isar commands. We |
34 Here we even incorporate the existing {\ML} toplevel of the compiler |
34 shall even incorporate the existing {\ML} toplevel of the compiler |
35 and run-time system (cf.\ \secref{sec:ML-toplevel}). |
35 and run-time system (cf.\ \secref{sec:ML-toplevel}). |
36 |
36 |
37 Isabelle/Isar departs from original ``LCF system architecture'' |
37 Isabelle/Isar departs from the original ``LCF system architecture'' |
38 where {\ML} was really The Meta Language for defining theories and |
38 where {\ML} was really The Meta Language for defining theories and |
39 conducting proofs. Instead, {\ML} merely serves as the |
39 conducting proofs. Instead, {\ML} now only serves as the |
40 implementation language for the system (and user extensions), while |
40 implementation language for the system (and user extensions), while |
41 our specific Isar toplevel supports particular notions of |
41 the specific Isar toplevel supports the concepts of theory and proof |
42 incremental theory and proof development more directly. This |
42 development natively. This includes the graph structure of theories |
43 includes the graph structure of theories and the block structure of |
43 and the block structure of proofs, support for unlimited undo, |
44 proofs, support for unlimited undo, facilities for tracing, |
44 facilities for tracing, debugging, timing, profiling etc. |
45 debugging, timing, profiling. |
|
46 |
45 |
47 \medskip The toplevel maintains an implicit state, which is |
46 \medskip The toplevel maintains an implicit state, which is |
48 transformed by a sequence of transitions -- either interactively or |
47 transformed by a sequence of transitions -- either interactively or |
49 in batch-mode. In interactive mode, Isar state transitions are |
48 in batch-mode. In interactive mode, Isar state transitions are |
50 encapsulated as safe transactions, such that both failure and undo |
49 encapsulated as safe transactions, such that both failure and undo |
51 are handled conveniently without destroying the underlying draft |
50 are handled conveniently without destroying the underlying draft |
52 theory (cf.~\secref{sec:context-theory}). In batch mode, |
51 theory (cf.~\secref{sec:context-theory}). In batch mode, |
53 transitions operate in a strictly linear (destructive) fashion, such |
52 transitions operate in a linear (destructive) fashion, such that |
54 that error conditions abort the present attempt to construct a |
53 error conditions abort the present attempt to construct a theory or |
55 theory altogether. |
54 proof altogether. |
56 |
55 |
57 The toplevel state is a disjoint sum of empty \isa{toplevel}, or |
56 The toplevel state is a disjoint sum of empty \isa{toplevel}, or |
58 \isa{theory}, or \isa{proof}. On entering the main Isar loop we |
57 \isa{theory}, or \isa{proof}. On entering the main Isar loop we |
59 start with an empty toplevel. A theory is commenced by giving a |
58 start with an empty toplevel. A theory is commenced by giving a |
60 \isa{{\isasymTHEORY}} header; within a theory we may issue theory |
59 \isa{{\isasymTHEORY}} header; within a theory we may issue theory |
94 \end{mldecls} |
93 \end{mldecls} |
95 |
94 |
96 \begin{description} |
95 \begin{description} |
97 |
96 |
98 \item \verb|Toplevel.state| represents Isar toplevel states, |
97 \item \verb|Toplevel.state| represents Isar toplevel states, |
99 which are normally only manipulated through the toplevel transition |
98 which are normally manipulated through the concept of toplevel |
100 concept (\secref{sec:toplevel-transition}). Also note that a |
99 transitions only (\secref{sec:toplevel-transition}). Also note that |
101 toplevel state is subject to the same linerarity restrictions as a |
100 a raw toplevel state is subject to the same linearity restrictions |
102 theory context (cf.~\secref{sec:context-theory}). |
101 as a theory context (cf.~\secref{sec:context-theory}). |
103 |
102 |
104 \item \verb|Toplevel.UNDEF| is raised for undefined toplevel |
103 \item \verb|Toplevel.UNDEF| is raised for undefined toplevel |
105 operations: \verb|Toplevel.state| is a sum type, many operations |
104 operations. Many operations work only partially for certain cases, |
106 work only partially for certain cases. |
105 since \verb|Toplevel.state| is a sum type. |
107 |
106 |
108 \item \verb|Toplevel.is_toplevel| checks for an empty toplevel state. |
107 \item \verb|Toplevel.is_toplevel|~\isa{state} checks for an empty |
109 |
108 toplevel state. |
110 \item \verb|Toplevel.theory_of| gets the theory of a theory or proof |
109 |
111 (!), otherwise raises \verb|Toplevel.UNDEF|. |
110 \item \verb|Toplevel.theory_of|~\isa{state} selects the theory of |
112 |
111 a theory or proof (!), otherwise raises \verb|Toplevel.UNDEF|. |
113 \item \verb|Toplevel.proof_of| gets the Isar proof state if |
112 |
114 available, otherwise raises \verb|Toplevel.UNDEF|. |
113 \item \verb|Toplevel.proof_of|~\isa{state} selects the Isar proof |
|
114 state if available, otherwise raises \verb|Toplevel.UNDEF|. |
115 |
115 |
116 \item \verb|set Toplevel.debug| makes the toplevel print further |
116 \item \verb|set Toplevel.debug| makes the toplevel print further |
117 details about internal error conditions, exceptions being raised |
117 details about internal error conditions, exceptions being raised |
118 etc. |
118 etc. |
119 |
119 |
120 \item \verb|set Toplevel.timing| makes the toplevel print timing |
120 \item \verb|set Toplevel.timing| makes the toplevel print timing |
121 information for each Isar command being executed. |
121 information for each Isar command being executed. |
122 |
122 |
123 \item \verb|Toplevel.profiling| controls low-level profiling of the |
123 \item \verb|Toplevel.profiling|~\verb|:=|~\isa{n} controls |
124 underlying {\ML} runtime system.\footnote{For Poly/ML, 1 means time |
124 low-level profiling of the underlying {\ML} runtime system. For |
125 and 2 space profiling.} |
125 Poly/ML, \isa{n\ {\isacharequal}\ {\isadigit{1}}} means time and \isa{n\ {\isacharequal}\ {\isadigit{2}}} space |
|
126 profiling. |
126 |
127 |
127 \end{description}% |
128 \end{description}% |
128 \end{isamarkuptext}% |
129 \end{isamarkuptext}% |
129 \isamarkuptrue% |
130 \isamarkuptrue% |
130 % |
131 % |
133 % |
134 % |
134 \isadelimmlref |
135 \isadelimmlref |
135 % |
136 % |
136 \endisadelimmlref |
137 \endisadelimmlref |
137 % |
138 % |
138 \isamarkupsubsection{Toplevel transitions% |
139 \isamarkupsubsection{Toplevel transitions \label{sec:toplevel-transition}% |
139 } |
140 } |
140 \isamarkuptrue% |
141 \isamarkuptrue% |
141 % |
142 % |
142 \begin{isamarkuptext}% |
143 \begin{isamarkuptext}% |
143 An Isar toplevel transition consists of a partial |
144 An Isar toplevel transition consists of a partial function on the |
144 function on the toplevel state, with additional information for |
145 toplevel state, with additional information for diagnostics and |
145 diagnostics and error reporting: there are fields for command name, |
146 error reporting: there are fields for command name, source position, |
146 source position, optional source text, as well as flags for |
147 optional source text, as well as flags for interactive-only commands |
147 interactive-only commands (which issue a warning in batch-mode), |
148 (which issue a warning in batch-mode), printing of result state, |
148 printing of result state, etc. |
149 etc. |
149 |
150 |
150 The operational part is represented as a sequential union of a list |
151 The operational part is represented as the sequential union of a |
151 of partial functions, which are tried in turn until the first one |
152 list of partial functions, which are tried in turn until the first |
152 succeeds (i.e.\ does not raise \verb|Toplevel.UNDEF|). For example, |
153 one succeeds (i.e.\ does not raise \verb|Toplevel.UNDEF|). This acts |
153 a single Isar command like \isacommand{qed} consists of the union of |
154 like an outer case-expression for various alternative state |
154 some function \verb|Proof.state -> Proof.state| for proofs |
155 transitions. For example, \isakeyword{qed} acts differently for a |
155 within proofs, plus \verb|Proof.state -> theory| for proofs at |
156 local proofs vs.\ the global ending of the main proof. |
156 the outer theory level. |
|
157 |
157 |
158 Toplevel transitions are composed via transition transformers. |
158 Toplevel transitions are composed via transition transformers. |
159 Internally, Isar commands are put together from an empty transition |
159 Internally, Isar commands are put together from an empty transition |
160 extended by name and source position (and optional source text). It |
160 extended by name and source position (and optional source text). It |
161 is then left to the individual command parser to turn the given |
161 is then left to the individual command parser to turn the given |
162 syntax body into a suitable transition transformer that adjoin |
162 concrete syntax into a suitable transition transformer that adjoin |
163 actual operations on a theory or proof state etc.% |
163 actual operations on a theory or proof state etc.% |
164 \end{isamarkuptext}% |
164 \end{isamarkuptext}% |
165 \isamarkuptrue% |
165 \isamarkuptrue% |
166 % |
166 % |
167 \isadelimmlref |
167 \isadelimmlref |
188 \verb| Toplevel.transition -> Toplevel.transition| \\ |
188 \verb| Toplevel.transition -> Toplevel.transition| \\ |
189 \end{mldecls} |
189 \end{mldecls} |
190 |
190 |
191 \begin{description} |
191 \begin{description} |
192 |
192 |
193 \item \verb|Toplevel.print| sets the print flag, which causes the |
193 \item \verb|Toplevel.print|~\isa{tr} sets the print flag, which |
194 resulting state of the transition to be echoed in interactive mode. |
194 causes the toplevel loop to echo the result state (in interactive |
195 |
195 mode). |
196 \item \verb|Toplevel.no_timing| indicates that the transition should |
196 |
197 never show timing information, e.g.\ because it is merely a |
197 \item \verb|Toplevel.no_timing|~\isa{tr} indicates that the |
198 diagnostic command. |
198 transition should never show timing information, e.g.\ because it is |
199 |
199 a diagnostic command. |
200 \item \verb|Toplevel.keep| adjoins a diagnostic function. |
200 |
201 |
201 \item \verb|Toplevel.keep|~\isa{tr} adjoins a diagnostic |
202 \item \verb|Toplevel.theory| adjoins a theory transformer. |
202 function. |
203 |
203 |
204 \item \verb|Toplevel.theory_to_proof| adjoins a global goal function, |
204 \item \verb|Toplevel.theory|~\isa{tr} adjoins a theory |
205 which turns a theory into a proof state. The theory may be changed |
205 transformer. |
206 before entering the proof; the generic Isar goal setup includes an |
206 |
207 argument that specifies how to apply the proven result to the |
207 \item \verb|Toplevel.theory_to_proof|~\isa{tr} adjoins a global |
208 theory, when the proof is finished. |
208 goal function, which turns a theory into a proof state. The theory |
209 |
209 may be changed before entering the proof; the generic Isar goal |
210 \item \verb|Toplevel.proof| adjoins a deterministic proof command, |
210 setup includes an argument that specifies how to apply the proven |
211 with a singleton result state. |
211 result to the theory, when the proof is finished. |
212 |
212 |
213 \item \verb|Toplevel.proofs| adjoins a general proof command, with |
213 \item \verb|Toplevel.proof|~\isa{tr} adjoins a deterministic |
214 zero or more result states (represented as a lazy list). |
214 proof command, with a singleton result. |
215 |
215 |
216 \item \verb|Toplevel.proof_to_theory| adjoins a concluding proof |
216 \item \verb|Toplevel.proofs|~\isa{tr} adjoins a general proof |
217 command, that returns the resulting theory, after storing the |
217 command, with zero or more result states (represented as a lazy |
218 resulting facts etc. |
218 list). |
|
219 |
|
220 \item \verb|Toplevel.proof_to_theory|~\isa{tr} adjoins a |
|
221 concluding proof command, that returns the resulting theory, after |
|
222 storing the resulting facts etc. |
219 |
223 |
220 \end{description}% |
224 \end{description}% |
221 \end{isamarkuptext}% |
225 \end{isamarkuptext}% |
222 \isamarkuptrue% |
226 \isamarkuptrue% |
223 % |
227 % |
231 \isamarkupsubsection{Toplevel control% |
235 \isamarkupsubsection{Toplevel control% |
232 } |
236 } |
233 \isamarkuptrue% |
237 \isamarkuptrue% |
234 % |
238 % |
235 \begin{isamarkuptext}% |
239 \begin{isamarkuptext}% |
236 Apart from regular toplevel transactions there are a few |
240 There are a few special control commands that modify the behavior |
237 special control commands that modify the behavior the toplevel |
241 the toplevel itself, and only make sense in interactive mode. Under |
238 itself, and only make sense in interactive mode. Under normal |
242 normal circumstances, the user encounters these only implicitly as |
239 circumstances, the user encounters these only implicitly as part of |
243 part of the protocol between the Isabelle/Isar system and a |
240 the protocol between the Isabelle/Isar system and a user-interface |
244 user-interface such as ProofGeneral. |
241 such as ProofGeneral. |
|
242 |
245 |
243 \begin{description} |
246 \begin{description} |
244 |
247 |
245 \item \isacommand{undo} follows the three-level hierarchy of empty |
248 \item \isacommand{undo} follows the three-level hierarchy of empty |
246 toplevel vs.\ theory vs.\ proof: undo within a proof reverts to the |
249 toplevel vs.\ theory vs.\ proof: undo within a proof reverts to the |
276 operate on the global system state, which consists of the compiler |
279 operate on the global system state, which consists of the compiler |
277 environment plus the values of {\ML} reference variables. There is |
280 environment plus the values of {\ML} reference variables. There is |
278 no clean way to undo {\ML} declarations, except for reverting to a |
281 no clean way to undo {\ML} declarations, except for reverting to a |
279 previously saved state of the whole Isabelle process. {\ML} input |
282 previously saved state of the whole Isabelle process. {\ML} input |
280 is either read interactively from a TTY, or from a string (usually |
283 is either read interactively from a TTY, or from a string (usually |
281 within a theory text), or from a source file (usually associated |
284 within a theory text), or from a source file (usually loaded from a |
282 with a theory). |
285 theory). |
283 |
286 |
284 Whenever the {\ML} toplevel is active, the current Isabelle theory |
287 Whenever the {\ML} toplevel is active, the current Isabelle theory |
285 context is passed as an internal reference variable. Thus {\ML} |
288 context is passed as an internal reference variable. Thus {\ML} |
286 code may access the theory context during compilation, it may even |
289 code may access the theory context during compilation, it may even |
287 change the value of a theory being under construction --- following |
290 change the value of a theory being under construction --- while |
288 the usual linearity restrictions (cf.~\secref{sec:context-theory}).% |
291 observing the usual linearity restrictions |
|
292 (cf.~\secref{sec:context-theory}).% |
289 \end{isamarkuptext}% |
293 \end{isamarkuptext}% |
290 \isamarkuptrue% |
294 \isamarkuptrue% |
291 % |
295 % |
292 \isadelimmlref |
296 \isadelimmlref |
293 % |
297 % |
309 when dropping out of the interactive Isar toplevel into {\ML}, or |
313 when dropping out of the interactive Isar toplevel into {\ML}, or |
310 when Isar invokes {\ML} to process code from a string or a file. |
314 when Isar invokes {\ML} to process code from a string or a file. |
311 |
315 |
312 \item \verb|the_context ()| refers to the theory context of the |
316 \item \verb|the_context ()| refers to the theory context of the |
313 {\ML} toplevel --- at compile time! {\ML} code needs to take care |
317 {\ML} toplevel --- at compile time! {\ML} code needs to take care |
314 to refer to \verb|the_context ()| correctly, recall that evaluation |
318 to refer to \verb|the_context ()| correctly. Recall that |
315 of a function body is delayed until actual runtime. Moreover, |
319 evaluation of a function body is delayed until actual runtime. |
316 persistent {\ML} toplevel bindings to an unfinished theory should be |
320 Moreover, persistent {\ML} toplevel bindings to an unfinished theory |
317 avoided: code should either project out the desired information |
321 should be avoided: code should either project out the desired |
318 immediately, or produce an explicit \verb|theory_ref| (cf.\ |
322 information immediately, or produce an explicit \verb|theory_ref| (cf.\ \secref{sec:context-theory}). |
319 \secref{sec:context-theory}). |
|
320 |
323 |
321 \item \verb|Context.>>|~\isa{f} applies theory transformation |
324 \item \verb|Context.>>|~\isa{f} applies theory transformation |
322 \isa{f} to the current theory of the {\ML} toplevel. In order to |
325 \isa{f} to the current theory of the {\ML} toplevel. In order to |
323 work as expected, the theory should be still under construction, and |
326 work as expected, the theory should be still under construction, and |
324 the Isar language element that invoked the {\ML} compiler in the |
327 the Isar language element that invoked the {\ML} compiler in the |
325 first place shoule be ready to accept the changed theory value |
328 first place should be ready to accept the changed theory value |
326 (e.g.\ \isakeyword{ML-setup}, but not plain \isakeyword{ML}). |
329 (e.g.\ \isakeyword{ML-setup}, but not plain \isakeyword{ML}). |
327 Otherwise the theory may get destroyed! |
330 Otherwise the theory becomes stale! |
328 |
331 |
329 \end{description} |
332 \end{description} |
330 |
333 |
331 It is very important to note that the above functions are really |
334 It is very important to note that the above functions are really |
332 restricted to the compile time, even though the {\ML} compiler is |
335 restricted to the compile time, even though the {\ML} compiler is |
333 invoked at runtime! The majority of {\ML} code uses explicit |
336 invoked at runtime! The majority of {\ML} code uses explicit |
334 functional arguments of a theory or proof context, as required. |
337 functional arguments of a theory or proof context instead. Thus it |
335 Thus it may get run in an arbitrary context later on. |
338 may be invoked for an arbitrary context later on, without having to |
|
339 worry about any operational details. |
336 |
340 |
337 \bigskip |
341 \bigskip |
338 |
342 |
339 \begin{mldecls} |
343 \begin{mldecls} |
340 \indexml{Isar.main}\verb|Isar.main: unit -> unit| \\ |
344 \indexml{Isar.main}\verb|Isar.main: unit -> unit| \\ |
345 \end{mldecls} |
349 \end{mldecls} |
346 |
350 |
347 \begin{description} |
351 \begin{description} |
348 |
352 |
349 \item \verb|Isar.main ()| invokes the Isar toplevel from {\ML}, |
353 \item \verb|Isar.main ()| invokes the Isar toplevel from {\ML}, |
350 initializing the state to empty toplevel state. |
354 initializing an empty toplevel state. |
351 |
355 |
352 \item \verb|Isar.loop ()| continues the Isar toplevel with the |
356 \item \verb|Isar.loop ()| continues the Isar toplevel with the |
353 current state, after dropping out of the Isar toplevel loop. |
357 current state, after having dropped out of the Isar toplevel loop. |
354 |
358 |
355 \item \verb|Isar.state ()| and \verb|Isar.exn ()| get current |
359 \item \verb|Isar.state ()| and \verb|Isar.exn ()| get current |
356 toplevel state and optional error condition, respectively. This |
360 toplevel state and error condition, respectively. This only works |
357 only works after dropping out of the Isar toplevel loop. |
361 after having dropped out of the Isar toplevel loop. |
358 |
362 |
359 \item \verb|Isar.context ()| produces the proof context from \verb|Isar.state ()|. |
363 \item \verb|Isar.context ()| produces the proof context from \verb|Isar.state ()|, analogous to \verb|Context.proof_of| |
|
364 (\secref{sec:generic-context}). |
360 |
365 |
361 \end{description}% |
366 \end{description}% |
362 \end{isamarkuptext}% |
367 \end{isamarkuptext}% |
363 \isamarkuptrue% |
368 \isamarkuptrue% |
364 % |
369 % |
367 % |
372 % |
368 \isadelimmlref |
373 \isadelimmlref |
369 % |
374 % |
370 \endisadelimmlref |
375 \endisadelimmlref |
371 % |
376 % |
372 \isamarkupsection{Theory database% |
377 \isamarkupsection{Theory database \label{sec:theory-database}% |
373 } |
378 } |
374 \isamarkuptrue% |
379 \isamarkuptrue% |
375 % |
380 % |
376 \begin{isamarkuptext}% |
381 \begin{isamarkuptext}% |
377 The theory database maintains a collection of theories, |
382 The theory database maintains a collection of theories, together |
378 together with some administrative information about the original |
383 with some administrative information about their original sources, |
379 sources, which are held in an external store (i.e.\ a collection of |
384 which are held in an external store (i.e.\ some directory within the |
380 directories within the regular file system of the underlying |
385 regular file system). |
381 platform). |
386 |
382 |
387 The theory database is organized as a directed acyclic graph; |
383 The theory database is organized as a directed acyclic graph, with |
388 entries are referenced by theory name. Although some additional |
384 entries referenced by theory name. Although some external |
389 interfaces allow to include a directory specification as well, this |
385 interfaces allow to include a directory specification, this is only |
390 is only a hint to the underlying theory loader. The internal theory |
386 a hint to the underlying theory loader mechanism: the internal |
391 name space is flat! |
387 theory name space is flat. |
|
388 |
392 |
389 Theory \isa{A} is associated with the main theory file \isa{A}\verb,.thy,, which needs to be accessible through the theory |
393 Theory \isa{A} is associated with the main theory file \isa{A}\verb,.thy,, which needs to be accessible through the theory |
390 loader path. A number of optional {\ML} source files may be |
394 loader path. Any number of additional {\ML} source files may be |
391 associated with each theory, by declaring these dependencies in the |
395 associated with each theory, by declaring these dependencies in the |
392 theory header as \isa{{\isasymUSES}}, and loading them consecutively |
396 theory header as \isa{{\isasymUSES}}, and loading them consecutively |
393 within the theory context. The system keeps track of incoming {\ML} |
397 within the theory context. The system keeps track of incoming {\ML} |
394 sources and associates them with the current theory. The special |
398 sources and associates them with the current theory. The file |
395 theory {\ML} file \isa{A}\verb,.ML, is loaded after a theory has |
399 \isa{A}\verb,.ML, is loaded after a theory has been concluded, in |
396 been concluded, in order to support legacy proof {\ML} proof |
400 order to support legacy proof {\ML} proof scripts. |
397 scripts. |
|
398 |
401 |
399 The basic internal actions of the theory database are \isa{update}, \isa{outdate}, and \isa{remove}: |
402 The basic internal actions of the theory database are \isa{update}, \isa{outdate}, and \isa{remove}: |
400 |
403 |
401 \begin{itemize} |
404 \begin{itemize} |
402 |
405 |
403 \item \isa{update\ A} introduces a link of \isa{A} with a |
406 \item \isa{update\ A} introduces a link of \isa{A} with a |
404 \isa{theory} value of the same name; it asserts that the theory |
407 \isa{theory} value of the same name; it asserts that the theory |
405 sources are consistent with that value. |
408 sources are now consistent with that value; |
406 |
409 |
407 \item \isa{outdate\ A} invalidates the link of a theory database |
410 \item \isa{outdate\ A} invalidates the link of a theory database |
408 entry to its sources, but retains the present theory value. |
411 entry to its sources, but retains the present theory value; |
409 |
412 |
410 \item \isa{remove\ A} removes entry \isa{A} from the theory |
413 \item \isa{remove\ A} deletes entry \isa{A} from the theory |
411 database. |
414 database. |
412 |
415 |
413 \end{itemize} |
416 \end{itemize} |
414 |
417 |
415 These actions are propagated to sub- or super-graphs of a theory |
418 These actions are propagated to sub- or super-graphs of a theory |
416 entry in the usual way, in order to preserve global consistency of |
419 entry as expected, in order to preserve global consistency of the |
417 the state of all loaded theories with the sources of the external |
420 state of all loaded theories with the sources of the external store. |
418 store. This implies causal dependencies of certain actions: \isa{update} or \isa{outdate} of an entry will \isa{outdate} |
421 This implies certain causalities between actions: \isa{update} |
419 all descendants; \isa{remove} will \isa{remove} all |
422 or \isa{outdate} of an entry will \isa{outdate} all |
420 descendants. |
423 descendants; \isa{remove} will \isa{remove} all descendants. |
421 |
424 |
422 \medskip There are separate user-level interfaces to operate on the |
425 \medskip There are separate user-level interfaces to operate on the |
423 theory database directly or indirectly. The primitive actions then |
426 theory database directly or indirectly. The primitive actions then |
424 just happen automatically while working with the system. In |
427 just happen automatically while working with the system. In |
425 particular, processing a theory header \isa{{\isasymTHEORY}\ A\ {\isasymIMPORTS}\ B\isactrlsub {\isadigit{1}}\ {\isasymdots}\ B\isactrlsub n\ {\isasymBEGIN}} ensure that the |
428 particular, processing a theory header \isa{{\isasymTHEORY}\ A\ {\isasymIMPORTS}\ B\isactrlsub {\isadigit{1}}\ {\isasymdots}\ B\isactrlsub n\ {\isasymBEGIN}} ensures that the |
426 sub-graph of the collective imports \isa{B\isactrlsub {\isadigit{1}}\ {\isasymdots}\ B\isactrlsub n} |
429 sub-graph of the collective imports \isa{B\isactrlsub {\isadigit{1}}\ {\isasymdots}\ B\isactrlsub n} |
427 is up-to-date. Earlier theories are reloaded as required, with |
430 is up-to-date, too. Earlier theories are reloaded as required, with |
428 \isa{update} actions proceeding in topological order according to |
431 \isa{update} actions proceeding in topological order according to |
429 theory dependencies. There may be also a wave of implied \isa{outdate} actions for derived theory nodes until a stable situation |
432 theory dependencies. There may be also a wave of implied \isa{outdate} actions for derived theory nodes until a stable situation |
430 is achieved eventually.% |
433 is achieved eventually.% |
431 \end{isamarkuptext}% |
434 \end{isamarkuptext}% |
432 \isamarkuptrue% |
435 \isamarkuptrue% |
440 \begin{isamarkuptext}% |
443 \begin{isamarkuptext}% |
441 \begin{mldecls} |
444 \begin{mldecls} |
442 \indexml{theory}\verb|theory: string -> theory| \\ |
445 \indexml{theory}\verb|theory: string -> theory| \\ |
443 \indexml{use-thy}\verb|use_thy: string -> unit| \\ |
446 \indexml{use-thy}\verb|use_thy: string -> unit| \\ |
444 \indexml{update-thy}\verb|update_thy: string -> unit| \\ |
447 \indexml{update-thy}\verb|update_thy: string -> unit| \\ |
445 \indexml{use-thy-only}\verb|use_thy_only: string -> unit| \\ |
|
446 \indexml{update-thy-only}\verb|update_thy_only: string -> unit| \\ |
|
447 \indexml{touch-thy}\verb|touch_thy: string -> unit| \\ |
448 \indexml{touch-thy}\verb|touch_thy: string -> unit| \\ |
448 \indexml{remove-thy}\verb|remove_thy: string -> unit| \\[1ex] |
449 \indexml{remove-thy}\verb|remove_thy: string -> unit| \\[1ex] |
449 \indexml{ThyInfo.begin-theory}\verb|ThyInfo.begin_theory|\verb|: ... -> bool -> theory| \\ |
450 \indexml{ThyInfo.begin-theory}\verb|ThyInfo.begin_theory|\verb|: ... -> bool -> theory| \\ |
450 \indexml{ThyInfo.end-theory}\verb|ThyInfo.end_theory: theory -> theory| \\ |
451 \indexml{ThyInfo.end-theory}\verb|ThyInfo.end_theory: theory -> theory| \\ |
451 \indexml{ThyInfo.register-theory}\verb|ThyInfo.register_theory: theory -> unit| \\[1ex] |
452 \indexml{ThyInfo.register-theory}\verb|ThyInfo.register_theory: theory -> unit| \\[1ex] |
454 \end{mldecls} |
455 \end{mldecls} |
455 |
456 |
456 \begin{description} |
457 \begin{description} |
457 |
458 |
458 \item \verb|theory|~\isa{A} retrieves the theory value presently |
459 \item \verb|theory|~\isa{A} retrieves the theory value presently |
459 associated with \isa{A}. The result is not necessarily |
460 associated with name \isa{A}. Note that the result might be |
460 up-to-date! |
461 outdated. |
461 |
462 |
462 \item \verb|use_thy|~\isa{A} loads theory \isa{A} if it is absent |
463 \item \verb|use_thy|~\isa{A} loads theory \isa{A} if it is absent |
463 or out-of-date. It ensures that all parent theories are available |
464 or out-of-date. It ensures that all parent theories are available |
464 as well, but does not reload them if older versions are already |
465 as well, but does not reload them if older versions are already |
465 present. |
466 present. |
466 |
467 |
467 \item \verb|update_thy| is similar to \verb|use_thy|, but ensures that |
468 \item \verb|update_thy| is similar to \verb|use_thy|, but ensures that |
468 the \isa{A} and all of its ancestors are fully up-to-date. |
469 theory \isa{A} and all ancestors are fully up-to-date. |
469 |
470 |
470 \item \verb|use_thy_only|~\isa{A} is like \verb|use_thy|~\isa{A}, |
471 \item \verb|touch_thy|~\isa{A} performs and \isa{outdate} action |
471 but refrains from loading the attached \isa{A}\verb,.ML, file. |
472 on theory \isa{A} and all descendants. |
472 This is occasionally useful in replaying legacy {\ML} proof scripts |
473 |
473 by hand. |
474 \item \verb|remove_thy|~\isa{A} deletes theory \isa{A} and all |
474 |
|
475 \item \verb|update_thy_only| is analogous to \verb|use_thy_only|, but |
|
476 proceeds like \verb|update_thy| for ancestors. |
|
477 |
|
478 \item \verb|touch_thy|~\isa{A} performs \isa{outdate} action on |
|
479 theory \isa{A} and all of its descendants. |
|
480 |
|
481 \item \verb|remove_thy|~\isa{A} removes \isa{A} and all of its |
|
482 descendants from the theory database. |
475 descendants from the theory database. |
483 |
476 |
484 \item \verb|ThyInfo.begin_theory| is the basic operation behind a |
477 \item \verb|ThyInfo.begin_theory| is the basic operation behind a |
485 \isa{{\isasymTHEORY}} header declaration. The boolean argument |
478 \isa{{\isasymTHEORY}} header declaration. The boolean argument |
486 indicates the strictness of treating ancestors: for \verb|true| (as |
479 indicates the strictness of treating ancestors: for \verb|true| (as |
487 in interactive mode) like \verb|update_thy|, and for \verb|false| (as |
480 in interactive mode) like \verb|update_thy|, and for \verb|false| (as |
488 in batch mode) like \verb|use_thy|. This is {\ML} functions is |
481 in batch mode) like \verb|use_thy|. This is {\ML} functions is |
489 normally not invoked directly. |
482 normally not invoked directly. |
490 |
483 |
491 \item \verb|ThyInfo.end_theory| concludes the loading of a theory |
484 \item \verb|ThyInfo.end_theory| concludes the loading of a theory |
492 proper; an attached theory {\ML} file may be still loaded later on. |
485 proper. An attached theory {\ML} file may be still loaded later on. |
493 This is {\ML} functions is normally not invoked directly. |
486 This is function is normally not invoked directly. |
494 |
487 |
495 \item \verb|ThyInfo.register_theory|~{text thy} registers an existing |
488 \item \verb|ThyInfo.register_theory|~\isa{text\ thy} registers an |
496 theory value with the theory loader database. There is no |
489 existing theory value with the theory loader database. There is no |
497 management of associated sources; this is mainly for bootstrapping. |
490 management of associated sources. |
498 |
491 |
499 \item \verb|ThyInfo.add_hook|~\isa{f} registers function \isa{f} as a hook for theory database actions. The function will be |
492 \item \verb|ThyInfo.add_hook|~\isa{f} registers function \isa{f} as a hook for theory database actions. The function will be |
500 invoked with the action and theory name being involved; thus derived |
493 invoked with the action and theory name being involved; thus derived |
501 actions may be performed in associated system components, e.g.\ |
494 actions may be performed in associated system components, e.g.\ |
502 maintaining the state of an editor for theory sources. |
495 maintaining the state of an editor for the theory sources. |
503 |
496 |
504 The kind and order of actions occurring in practice depends both on |
497 The kind and order of actions occurring in practice depends both on |
505 user interactions and the internal process of resolving theory |
498 user interactions and the internal process of resolving theory |
506 imports. Hooks should not rely on a particular policy here! Any |
499 imports. Hooks should not rely on a particular policy here! Any |
507 exceptions raised by the hook are ignored by the theory database. |
500 exceptions raised by the hook are ignored. |
508 |
501 |
509 \end{description}% |
502 \end{description}% |
510 \end{isamarkuptext}% |
503 \end{isamarkuptext}% |
511 \isamarkuptrue% |
504 \isamarkuptrue% |
512 % |
505 % |