11 text {* |
11 text {* |
12 The Isar \emph{toplevel state} represents the outermost configuration that |
12 The Isar \emph{toplevel state} represents the outermost configuration that |
13 is transformed by a sequence of transitions (commands) within a theory body. |
13 is transformed by a sequence of transitions (commands) within a theory body. |
14 This is a pure value with pure functions acting on it in a timeless and |
14 This is a pure value with pure functions acting on it in a timeless and |
15 stateless manner. Historically, the sequence of transitions was wrapped up |
15 stateless manner. Historically, the sequence of transitions was wrapped up |
16 as sequential command loop, such that commands are applied sequentially |
16 as sequential command loop, such that commands are applied one-by-one. In |
17 one-by-one. In contemporary Isabelle/Isar, processing toplevel commands |
17 contemporary Isabelle/Isar, processing toplevel commands usually works in |
18 usually works in parallel in multi-threaded Isabelle/ML. |
18 parallel in multi-threaded Isabelle/ML \cite{Wenzel:2009,Wenzel:2013:ITP}. |
19 *} |
19 *} |
20 |
20 |
21 |
21 |
22 subsection {* Toplevel state *} |
22 subsection {* Toplevel state *} |
23 |
23 |
26 theory}, or @{text proof}. The initial toplevel is empty; a theory is |
26 theory}, or @{text proof}. The initial toplevel is empty; a theory is |
27 commenced by a @{command theory} header; within a theory we may use theory |
27 commenced by a @{command theory} header; within a theory we may use theory |
28 commands such as @{command definition}, or state a @{command theorem} to be |
28 commands such as @{command definition}, or state a @{command theorem} to be |
29 proven. A proof state accepts a rich collection of Isar proof commands for |
29 proven. A proof state accepts a rich collection of Isar proof commands for |
30 structured proof composition, or unstructured proof scripts. When the proof |
30 structured proof composition, or unstructured proof scripts. When the proof |
31 is concluded we get back to the theory, which is then updated by defining |
31 is concluded we get back to the (local) theory, which is then updated by |
32 the resulting fact. Further theory declarations or theorem statements with |
32 defining the resulting fact. Further theory declarations or theorem |
33 proofs may follow, until we eventually conclude the theory development by |
33 statements with proofs may follow, until we eventually conclude the theory |
34 issuing @{command end} to get back to the empty toplevel. |
34 development by issuing @{command end} to get back to the empty toplevel. |
35 *} |
35 *} |
36 |
36 |
37 text %mlref {* |
37 text %mlref {* |
38 \begin{mldecls} |
38 \begin{mldecls} |
39 @{index_ML_type Toplevel.state} \\ |
39 @{index_ML_type Toplevel.state} \\ |
40 @{index_ML_exception Toplevel.UNDEF} \\ |
40 @{index_ML_exception Toplevel.UNDEF} \\ |
41 @{index_ML Toplevel.is_toplevel: "Toplevel.state -> bool"} \\ |
41 @{index_ML Toplevel.is_toplevel: "Toplevel.state -> bool"} \\ |
42 @{index_ML Toplevel.theory_of: "Toplevel.state -> theory"} \\ |
42 @{index_ML Toplevel.theory_of: "Toplevel.state -> theory"} \\ |
43 @{index_ML Toplevel.proof_of: "Toplevel.state -> Proof.state"} \\ |
43 @{index_ML Toplevel.proof_of: "Toplevel.state -> Proof.state"} \\ |
44 @{index_ML Toplevel.timing: "bool Unsynchronized.ref"} \\ |
|
45 @{index_ML Toplevel.profiling: "int Unsynchronized.ref"} \\ |
|
46 \end{mldecls} |
44 \end{mldecls} |
47 |
45 |
48 \begin{description} |
46 \begin{description} |
49 |
47 |
50 \item Type @{ML_type Toplevel.state} represents Isar toplevel |
48 \item Type @{ML_type Toplevel.state} represents Isar toplevel |
57 |
55 |
58 \item @{ML Toplevel.is_toplevel}~@{text "state"} checks for an empty |
56 \item @{ML Toplevel.is_toplevel}~@{text "state"} checks for an empty |
59 toplevel state. |
57 toplevel state. |
60 |
58 |
61 \item @{ML Toplevel.theory_of}~@{text "state"} selects the |
59 \item @{ML Toplevel.theory_of}~@{text "state"} selects the |
62 background theory of @{text "state"}, raises @{ML Toplevel.UNDEF} |
60 background theory of @{text "state"}, it raises @{ML Toplevel.UNDEF} |
63 for an empty toplevel state. |
61 for an empty toplevel state. |
64 |
62 |
65 \item @{ML Toplevel.proof_of}~@{text "state"} selects the Isar proof |
63 \item @{ML Toplevel.proof_of}~@{text "state"} selects the Isar proof |
66 state if available, otherwise raises @{ML Toplevel.UNDEF}. |
64 state if available, otherwise it raises @{ML Toplevel.UNDEF}. |
67 |
|
68 \item @{ML "Toplevel.timing := true"} makes the toplevel print timing |
|
69 information for each Isar command being executed. |
|
70 |
|
71 \item @{ML Toplevel.profiling}~@{ML_text ":="}~@{text "n"} controls |
|
72 low-level profiling of the underlying ML runtime system. For |
|
73 Poly/ML, @{text "n = 1"} means time and @{text "n = 2"} space |
|
74 profiling. |
|
75 |
65 |
76 \end{description} |
66 \end{description} |
77 *} |
67 *} |
78 |
68 |
79 text %mlantiq {* |
69 text %mlantiq {* |
102 |
92 |
103 The operational part is represented as the sequential union of a |
93 The operational part is represented as the sequential union of a |
104 list of partial functions, which are tried in turn until the first |
94 list of partial functions, which are tried in turn until the first |
105 one succeeds. This acts like an outer case-expression for various |
95 one succeeds. This acts like an outer case-expression for various |
106 alternative state transitions. For example, \isakeyword{qed} works |
96 alternative state transitions. For example, \isakeyword{qed} works |
107 differently for a local proofs vs.\ the global ending of the main |
97 differently for a local proofs vs.\ the global ending of an outermost |
108 proof. |
98 proof. |
109 |
99 |
110 Toplevel transitions are composed via transition transformers. |
100 Transitions are composed via transition transformers. Internally, Isar |
111 Internally, Isar commands are put together from an empty transition |
101 commands are put together from an empty transition extended by name and |
112 extended by name and source position. It is then left to the |
102 source position. It is then left to the individual command parser to turn |
113 individual command parser to turn the given concrete syntax into a |
103 the given concrete syntax into a suitable transition transformer that |
114 suitable transition transformer that adjoins actual operations on a |
104 adjoins actual operations on a theory or proof state. |
115 theory or proof state etc. |
|
116 *} |
105 *} |
117 |
106 |
118 text %mlref {* |
107 text %mlref {* |
119 \begin{mldecls} |
108 \begin{mldecls} |
120 @{index_ML Toplevel.keep: "(Toplevel.state -> unit) -> |
109 @{index_ML Toplevel.keep: "(Toplevel.state -> unit) -> |
152 \item @{ML Toplevel.proofs}~@{text "tr"} adjoins a general proof |
141 \item @{ML Toplevel.proofs}~@{text "tr"} adjoins a general proof |
153 command, with zero or more result states (represented as a lazy |
142 command, with zero or more result states (represented as a lazy |
154 list). |
143 list). |
155 |
144 |
156 \item @{ML Toplevel.end_proof}~@{text "tr"} adjoins a concluding |
145 \item @{ML Toplevel.end_proof}~@{text "tr"} adjoins a concluding |
157 proof command, that returns the resulting theory, after storing the |
146 proof command, that returns the resulting theory, after applying the |
158 resulting facts in the context etc. |
147 resulting facts to the target context. |
159 |
148 |
160 \end{description} |
149 \end{description} |
161 *} |
150 *} |
162 |
151 |
163 |
152 |
173 *} |
162 *} |
174 |
163 |
175 text %mlref {* |
164 text %mlref {* |
176 \begin{mldecls} |
165 \begin{mldecls} |
177 @{index_ML use_thy: "string -> unit"} \\ |
166 @{index_ML use_thy: "string -> unit"} \\ |
178 @{index_ML use_thys: "string list -> unit"} \\ |
167 @{index_ML use_thys: "string list -> unit"} \\[0.5ex] |
179 @{index_ML Thy_Info.get_theory: "string -> theory"} \\ |
168 @{index_ML Thy_Info.get_theory: "string -> theory"} \\ |
180 @{index_ML Thy_Info.remove_thy: "string -> unit"} \\ |
169 @{index_ML Thy_Info.remove_thy: "string -> unit"} \\ |
181 @{index_ML Thy_Info.register_thy: "theory -> unit"} \\ |
170 @{index_ML Thy_Info.register_thy: "theory -> unit"} \\ |
182 \end{mldecls} |
171 \end{mldecls} |
183 |
172 |
184 \begin{description} |
173 \begin{description} |
185 |
174 |
186 \item @{ML use_thy}~@{text A} ensures that theory @{text A} is fully |
175 \item @{ML use_thy}~@{text A} ensures that theory @{text A} is fully |
187 up-to-date wrt.\ the external file store, reloading outdated ancestors as |
176 up-to-date wrt.\ the external file store; outdated ancestors are reloaded on |
188 required. |
177 demand. |
189 |
178 |
190 \item @{ML use_thys} is similar to @{ML use_thy}, but handles several |
179 \item @{ML use_thys} is similar to @{ML use_thy}, but handles several |
191 theories simultaneously. Thus it acts like processing the import header of a |
180 theories simultaneously. Thus it acts like processing the import header of a |
192 theory, without performing the merge of the result. By loading a whole |
181 theory, without performing the merge of the result. By loading a whole |
193 sub-graph of theories, the intrinsic parallelism can be exploited by the |
182 sub-graph of theories, the intrinsic parallelism can be exploited by the |
194 system to speedup loading. |
183 system to speedup loading. |
195 |
184 |
|
185 This variant is used by default in @{tool build} \cite{isabelle-sys}. |
|
186 |
196 \item @{ML Thy_Info.get_theory}~@{text A} retrieves the theory value |
187 \item @{ML Thy_Info.get_theory}~@{text A} retrieves the theory value |
197 presently associated with name @{text A}. Note that the result might be |
188 presently associated with name @{text A}. Note that the result might be |
198 outdated wrt.\ the file-system content. |
189 outdated wrt.\ the file-system content. |
199 |
190 |
200 \item @{ML Thy_Info.remove_thy}~@{text A} deletes theory @{text A} and all |
191 \item @{ML Thy_Info.remove_thy}~@{text A} deletes theory @{text A} and all |
201 descendants from the theory database. |
192 descendants from the theory database. |
202 |
193 |
203 \item @{ML Thy_Info.register_thy}~@{text "text thy"} registers an existing |
194 \item @{ML Thy_Info.register_thy}~@{text "text thy"} registers an existing |
204 theory value with the theory loader database and updates source version |
195 theory value with the theory loader database and updates source version |
205 information according to the current file-system state. |
196 information according to the file store. |
206 |
197 |
207 \end{description} |
198 \end{description} |
208 *} |
199 *} |
209 |
200 |
210 end |
201 end |