author | wenzelm |
Mon, 30 Jul 2012 17:03:24 +0200 | |
changeset 48609 | 0090fab725e3 |
parent 46563 | 0ad69b30b39c |
permissions | -rw-r--r-- |
38560 | 1 |
% |
2 |
\begin{isabellebody}% |
|
3 |
\def\isabellecontext{Evaluation}% |
|
4 |
% |
|
5 |
\isadelimtheory |
|
6 |
% |
|
7 |
\endisadelimtheory |
|
8 |
% |
|
9 |
\isatagtheory |
|
10 |
\isacommand{theory}\isamarkupfalse% |
|
11 |
\ Evaluation\isanewline |
|
12 |
\isakeyword{imports}\ Setup\isanewline |
|
13 |
\isakeyword{begin}% |
|
14 |
\endisatagtheory |
|
15 |
{\isafoldtheory}% |
|
16 |
% |
|
17 |
\isadelimtheory |
|
18 |
% |
|
19 |
\endisadelimtheory |
|
20 |
% |
|
40755 | 21 |
\isamarkupsection{Evaluation \label{sec:evaluation}% |
38560 | 22 |
} |
23 |
\isamarkuptrue% |
|
24 |
% |
|
25 |
\begin{isamarkuptext}% |
|
39599 | 26 |
Recalling \secref{sec:principle}, code generation turns a system of |
27 |
equations into a program with the \emph{same} equational semantics. |
|
28 |
As a consequence, this program can be used as a \emph{rewrite |
|
29 |
engine} for terms: rewriting a term \isa{t} using a program to a |
|
40406 | 30 |
term \isa{t{\isaliteral{27}{\isacharprime}}} yields the theorems \isa{t\ {\isaliteral{5C3C65717569763E}{\isasymequiv}}\ t{\isaliteral{27}{\isacharprime}}}. This |
39599 | 31 |
application of code generation in the following is referred to as |
32 |
\emph{evaluation}.% |
|
38560 | 33 |
\end{isamarkuptext}% |
34 |
\isamarkuptrue% |
|
35 |
% |
|
36 |
\isamarkupsubsection{Evaluation techniques% |
|
37 |
} |
|
38 |
\isamarkuptrue% |
|
39 |
% |
|
40 |
\begin{isamarkuptext}% |
|
40350 | 41 |
The existing infrastructure provides a rich palette of evaluation |
39599 | 42 |
techniques, each comprising different aspects: |
43 |
||
44 |
\begin{description} |
|
45 |
||
46 |
\item[Expressiveness.] Depending on how good symbolic computation |
|
47 |
is supported, the class of terms which can be evaluated may be |
|
48 |
bigger or smaller. |
|
49 |
||
50 |
\item[Efficiency.] The more machine-near the technique, the |
|
51 |
faster it is. |
|
52 |
||
53 |
\item[Trustability.] Techniques which a huge (and also probably |
|
54 |
more configurable infrastructure) are more fragile and less |
|
55 |
trustable. |
|
56 |
||
57 |
\end{description}% |
|
38560 | 58 |
\end{isamarkuptext}% |
59 |
\isamarkuptrue% |
|
60 |
% |
|
39599 | 61 |
\isamarkupsubsubsection{The simplifier (\isa{simp})% |
38560 | 62 |
} |
63 |
\isamarkuptrue% |
|
64 |
% |
|
65 |
\begin{isamarkuptext}% |
|
39599 | 66 |
The simplest way for evaluation is just using the simplifier with |
67 |
the original code equations of the underlying program. This gives |
|
68 |
fully symbolic evaluation and highest trustablity, with the usual |
|
69 |
performance of the simplifier. Note that for operations on abstract |
|
70 |
datatypes (cf.~\secref{sec:invariant}), the original theorems as |
|
71 |
given by the users are used, not the modified ones.% |
|
38560 | 72 |
\end{isamarkuptext}% |
73 |
\isamarkuptrue% |
|
74 |
% |
|
39599 | 75 |
\isamarkupsubsubsection{Normalization by evaluation (\isa{nbe})% |
38560 | 76 |
} |
77 |
\isamarkuptrue% |
|
78 |
% |
|
79 |
\begin{isamarkuptext}% |
|
39599 | 80 |
Normalization by evaluation \cite{Aehlig-Haftmann-Nipkow:2008:nbe} |
81 |
provides a comparably fast partially symbolic evaluation which |
|
82 |
permits also normalization of functions and uninterpreted symbols; |
|
83 |
the stack of code to be trusted is considerable.% |
|
38560 | 84 |
\end{isamarkuptext}% |
85 |
\isamarkuptrue% |
|
86 |
% |
|
39599 | 87 |
\isamarkupsubsubsection{Evaluation in ML (\isa{code})% |
38560 | 88 |
} |
89 |
\isamarkuptrue% |
|
90 |
% |
|
91 |
\begin{isamarkuptext}% |
|
39599 | 92 |
Highest performance can be achieved by evaluation in ML, at the cost |
93 |
of being restricted to ground results and a layered stack of code to |
|
94 |
be trusted, including code generator configurations by the user. |
|
95 |
||
96 |
Evaluation is carried out in a target language \emph{Eval} which |
|
97 |
inherits from \emph{SML} but for convenience uses parts of the |
|
98 |
Isabelle runtime environment. The soundness of computation carried |
|
39609 | 99 |
out there depends crucially on the correctness of the code |
39643 | 100 |
generator setup; this is one of the reasons why you should not use |
39609 | 101 |
adaptation (see \secref{sec:adaptation}) frivolously.% |
39599 | 102 |
\end{isamarkuptext}% |
103 |
\isamarkuptrue% |
|
104 |
% |
|
105 |
\isamarkupsubsection{Aspects of evaluation% |
|
106 |
} |
|
107 |
\isamarkuptrue% |
|
108 |
% |
|
109 |
\begin{isamarkuptext}% |
|
110 |
Each of the techniques can be combined with different aspects. The |
|
111 |
most important distinction is between dynamic and static evaluation. |
|
112 |
Dynamic evaluation takes the code generator configuration \qt{as it |
|
113 |
is} at the point where evaluation is issued. Best example is the |
|
114 |
\indexdef{}{command}{value}\hypertarget{command.value}{\hyperlink{command.value}{\mbox{\isa{\isacommand{value}}}}} command which allows ad-hoc evaluation of |
|
115 |
terms:% |
|
38560 | 116 |
\end{isamarkuptext}% |
117 |
\isamarkuptrue% |
|
118 |
% |
|
119 |
\isadelimquote |
|
120 |
% |
|
121 |
\endisadelimquote |
|
122 |
% |
|
123 |
\isatagquote |
|
124 |
\isacommand{value}\isamarkupfalse% |
|
40406 | 125 |
\ {\isaliteral{22}{\isachardoublequoteopen}}{\isadigit{4}}{\isadigit{2}}\ {\isaliteral{2F}{\isacharslash}}\ {\isaliteral{28}{\isacharparenleft}}{\isadigit{1}}{\isadigit{2}}\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ rat{\isaliteral{29}{\isacharparenright}}{\isaliteral{22}{\isachardoublequoteclose}}% |
38560 | 126 |
\endisatagquote |
127 |
{\isafoldquote}% |
|
128 |
% |
|
129 |
\isadelimquote |
|
130 |
% |
|
131 |
\endisadelimquote |
|
132 |
% |
|
133 |
\begin{isamarkuptext}% |
|
39599 | 134 |
\noindent By default \hyperlink{command.value}{\mbox{\isa{\isacommand{value}}}} tries all available evaluation |
135 |
techniques and prints the result of the first succeeding one. A particular |
|
136 |
technique may be specified in square brackets, e.g.% |
|
38560 | 137 |
\end{isamarkuptext}% |
138 |
\isamarkuptrue% |
|
139 |
% |
|
140 |
\isadelimquote |
|
141 |
% |
|
142 |
\endisadelimquote |
|
143 |
% |
|
144 |
\isatagquote |
|
39599 | 145 |
\isacommand{value}\isamarkupfalse% |
40406 | 146 |
\ {\isaliteral{5B}{\isacharbrackleft}}nbe{\isaliteral{5D}{\isacharbrackright}}\ {\isaliteral{22}{\isachardoublequoteopen}}{\isadigit{4}}{\isadigit{2}}\ {\isaliteral{2F}{\isacharslash}}\ {\isaliteral{28}{\isacharparenleft}}{\isadigit{1}}{\isadigit{2}}\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ rat{\isaliteral{29}{\isacharparenright}}{\isaliteral{22}{\isachardoublequoteclose}}% |
38560 | 147 |
\endisatagquote |
148 |
{\isafoldquote}% |
|
149 |
% |
|
150 |
\isadelimquote |
|
151 |
% |
|
152 |
\endisadelimquote |
|
153 |
% |
|
154 |
\begin{isamarkuptext}% |
|
43656
9ece73262746
adding documentation of the value antiquotation to the code generation manual
bulwahn
parents:
41185
diff
changeset
|
155 |
To employ dynamic evaluation in the document generation, there is also |
9ece73262746
adding documentation of the value antiquotation to the code generation manual
bulwahn
parents:
41185
diff
changeset
|
156 |
a \isa{value} antiquotation. By default, it also tries all available evaluation |
9ece73262746
adding documentation of the value antiquotation to the code generation manual
bulwahn
parents:
41185
diff
changeset
|
157 |
techniques and prints the result of the first succeeding one, unless a particular |
9ece73262746
adding documentation of the value antiquotation to the code generation manual
bulwahn
parents:
41185
diff
changeset
|
158 |
technique is specified in square brackets. |
9ece73262746
adding documentation of the value antiquotation to the code generation manual
bulwahn
parents:
41185
diff
changeset
|
159 |
|
9ece73262746
adding documentation of the value antiquotation to the code generation manual
bulwahn
parents:
41185
diff
changeset
|
160 |
Static evaluation freezes the code generator configuration at a |
39599 | 161 |
certain point and uses this context whenever evaluation is issued |
162 |
later on. This is particularly appropriate for proof procedures |
|
163 |
which use evaluation, since then the behaviour of evaluation is not |
|
164 |
changed or even compromised later on by actions of the user. |
|
165 |
||
166 |
As a technical complication, terms after evaluation in ML must be |
|
167 |
turned into Isabelle's internal term representation again. Since |
|
168 |
this is also configurable, it is never fully trusted. For this |
|
169 |
reason, evaluation in ML comes with further aspects: |
|
170 |
||
171 |
\begin{description} |
|
172 |
||
173 |
\item[Plain evaluation.] A term is normalized using the provided |
|
174 |
term reconstruction from ML to Isabelle; for applications which |
|
175 |
do not need to be fully trusted. |
|
176 |
||
177 |
\item[Property conversion.] Evaluates propositions; since these |
|
178 |
are monomorphic, the term reconstruction is fixed once and for all |
|
179 |
and therefore trustable. |
|
180 |
||
181 |
\item[Conversion.] Evaluates an arbitrary term \isa{t} first |
|
40406 | 182 |
by plain evaluation and certifies the result \isa{t{\isaliteral{27}{\isacharprime}}} by |
183 |
checking the equation \isa{t\ {\isaliteral{5C3C65717569763E}{\isasymequiv}}\ t{\isaliteral{27}{\isacharprime}}} using property |
|
39599 | 184 |
conversion. |
185 |
||
186 |
\end{description} |
|
187 |
||
188 |
\noindent The picture is further complicated by the roles of |
|
189 |
exceptions. Here three cases have to be distinguished: |
|
190 |
||
191 |
\begin{itemize} |
|
192 |
||
40406 | 193 |
\item Evaluation of \isa{t} terminates with a result \isa{t{\isaliteral{27}{\isacharprime}}}. |
39599 | 194 |
|
195 |
\item Evaluation of \isa{t} terminates which en exception |
|
40350 | 196 |
indicating a pattern match failure or a non-implemented |
39599 | 197 |
function. As sketched in \secref{sec:partiality}, this can be |
198 |
interpreted as partiality. |
|
199 |
||
39643 | 200 |
\item Evaluation raises any other kind of exception. |
39599 | 201 |
|
202 |
\end{itemize} |
|
203 |
||
40406 | 204 |
\noindent For conversions, the first case yields the equation \isa{t\ {\isaliteral{3D}{\isacharequal}}\ t{\isaliteral{27}{\isacharprime}}}, the second defaults to reflexivity \isa{t\ {\isaliteral{3D}{\isacharequal}}\ t}. |
39643 | 205 |
Exceptions of the third kind are propagated to the user. |
39599 | 206 |
|
207 |
By default return values of plain evaluation are optional, yielding |
|
40406 | 208 |
\isa{SOME\ t{\isaliteral{27}{\isacharprime}}} in the first case, \isa{NONE} in the |
40350 | 209 |
second, and propagating the exception in the third case. A strict |
40406 | 210 |
variant of plain evaluation either yields \isa{t{\isaliteral{27}{\isacharprime}}} or propagates |
39599 | 211 |
any exception, a liberal variant caputures any exception in a result |
40406 | 212 |
of type \isa{Exn{\isaliteral{2E}{\isachardot}}result}. |
39599 | 213 |
|
214 |
For property conversion (which coincides with conversion except for |
|
215 |
evaluation in ML), methods are provided which solve a given goal by |
|
216 |
evaluation.% |
|
38560 | 217 |
\end{isamarkuptext}% |
218 |
\isamarkuptrue% |
|
219 |
% |
|
39599 | 220 |
\isamarkupsubsection{Schematic overview% |
38560 | 221 |
} |
222 |
\isamarkuptrue% |
|
223 |
% |
|
224 |
\begin{isamarkuptext}% |
|
39693 | 225 |
\newcommand{\ttsize}{\fontsize{5.8pt}{8pt}\selectfont} |
226 |
\fontsize{9pt}{12pt}\selectfont |
|
227 |
\begin{tabular}{ll||c|c|c} |
|
39599 | 228 |
& & \isa{simp} & \isa{nbe} & \isa{code} \tabularnewline \hline \hline |
39693 | 229 |
\multirow{5}{1ex}{\rotatebox{90}{dynamic}} |
230 |
& interactive evaluation |
|
40406 | 231 |
& \hyperlink{command.value}{\mbox{\isa{\isacommand{value}}}} \isa{{\isaliteral{5B}{\isacharbrackleft}}simp{\isaliteral{5D}{\isacharbrackright}}} & \hyperlink{command.value}{\mbox{\isa{\isacommand{value}}}} \isa{{\isaliteral{5B}{\isacharbrackleft}}nbe{\isaliteral{5D}{\isacharbrackright}}} & \hyperlink{command.value}{\mbox{\isa{\isacommand{value}}}} \isa{{\isaliteral{5B}{\isacharbrackleft}}code{\isaliteral{5D}{\isacharbrackright}}} |
39599 | 232 |
\tabularnewline |
39693 | 233 |
& plain evaluation & & & \ttsize\verb|Code_Evaluation.dynamic_value| \tabularnewline \cline{2-5} |
40406 | 234 |
& evaluation method & \hyperlink{method.code-simp}{\mbox{\isa{code{\isaliteral{5F}{\isacharunderscore}}simp}}} & \hyperlink{method.normalization}{\mbox{\isa{normalization}}} & \hyperlink{method.eval}{\mbox{\isa{eval}}} \tabularnewline |
39693 | 235 |
& property conversion & & & \ttsize\verb|Code_Runtime.dynamic_holds_conv| \tabularnewline \cline{2-5} |
41184 | 236 |
& conversion & \ttsize\verb|Code_Simp.dynamic_conv| & \ttsize\verb|Nbe.dynamic_conv| |
237 |
& \ttsize\verb|Code_Evaluation.dynamic_conv| \tabularnewline \hline \hline |
|
39693 | 238 |
\multirow{3}{1ex}{\rotatebox{90}{static}} |
41185 | 239 |
& plain evaluation & & & \ttsize\verb|Code_Evaluation.static_value| \tabularnewline \cline{2-5} |
39599 | 240 |
& property conversion & & |
39693 | 241 |
& \ttsize\verb|Code_Runtime.static_holds_conv| \tabularnewline \cline{2-5} |
41184 | 242 |
& conversion & \ttsize\verb|Code_Simp.static_conv| |
243 |
& \ttsize\verb|Nbe.static_conv| |
|
244 |
& \ttsize\verb|Code_Evaluation.static_conv| |
|
39599 | 245 |
\end{tabular}% |
246 |
\end{isamarkuptext}% |
|
247 |
\isamarkuptrue% |
|
248 |
% |
|
249 |
\isamarkupsubsection{Intimate connection between logic and system runtime% |
|
250 |
} |
|
251 |
\isamarkuptrue% |
|
252 |
% |
|
253 |
\begin{isamarkuptext}% |
|
39609 | 254 |
The toolbox of static evaluation conversions forms a reasonable base |
255 |
to interweave generated code and system tools. However in some |
|
256 |
situations more direct interaction is desirable.% |
|
39599 | 257 |
\end{isamarkuptext}% |
258 |
\isamarkuptrue% |
|
259 |
% |
|
39609 | 260 |
\isamarkupsubsubsection{Static embedding of generated code into system runtime -- the \isa{code} antiquotation% |
39599 | 261 |
} |
262 |
\isamarkuptrue% |
|
263 |
% |
|
264 |
\begin{isamarkuptext}% |
|
39609 | 265 |
The \isa{code} antiquotation allows to include constants from |
266 |
generated code directly into ML system code, as in the following toy |
|
267 |
example:% |
|
38560 | 268 |
\end{isamarkuptext}% |
269 |
\isamarkuptrue% |
|
270 |
% |
|
271 |
\isadelimquote |
|
272 |
% |
|
273 |
\endisadelimquote |
|
274 |
% |
|
275 |
\isatagquote |
|
276 |
\isacommand{datatype}\isamarkupfalse% |
|
40406 | 277 |
\ form\ {\isaliteral{3D}{\isacharequal}}\ T\ {\isaliteral{7C}{\isacharbar}}\ F\ {\isaliteral{7C}{\isacharbar}}\ And\ form\ form\ {\isaliteral{7C}{\isacharbar}}\ Or\ form\ form\ % |
39745 | 278 |
\endisatagquote |
279 |
{\isafoldquote}% |
|
280 |
% |
|
281 |
\isadelimquote |
|
282 |
% |
|
283 |
\endisadelimquote |
|
284 |
% |
|
285 |
\isadelimquotett |
|
286 |
\ % |
|
287 |
\endisadelimquotett |
|
288 |
% |
|
289 |
\isatagquotett |
|
290 |
\isacommand{ML}\isamarkupfalse% |
|
40406 | 291 |
\ {\isaliteral{7B2A}{\isacharverbatimopen}}\isanewline |
292 |
\ \ fun\ eval{\isaliteral{5F}{\isacharunderscore}}form\ % |
|
38560 | 293 |
\isaantiq |
40406 | 294 |
code\ T{}% |
38560 | 295 |
\endisaantiq |
40406 | 296 |
\ {\isaliteral{3D}{\isacharequal}}\ true\isanewline |
297 |
\ \ \ \ {\isaliteral{7C}{\isacharbar}}\ eval{\isaliteral{5F}{\isacharunderscore}}form\ % |
|
38560 | 298 |
\isaantiq |
40406 | 299 |
code\ F{}% |
38560 | 300 |
\endisaantiq |
40406 | 301 |
\ {\isaliteral{3D}{\isacharequal}}\ false\isanewline |
302 |
\ \ \ \ {\isaliteral{7C}{\isacharbar}}\ eval{\isaliteral{5F}{\isacharunderscore}}form\ {\isaliteral{28}{\isacharparenleft}}% |
|
38560 | 303 |
\isaantiq |
40406 | 304 |
code\ And{}% |
38560 | 305 |
\endisaantiq |
40406 | 306 |
\ {\isaliteral{28}{\isacharparenleft}}p{\isaliteral{2C}{\isacharcomma}}\ q{\isaliteral{29}{\isacharparenright}}{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{3D}{\isacharequal}}\isanewline |
307 |
\ \ \ \ \ \ \ \ eval{\isaliteral{5F}{\isacharunderscore}}form\ p\ andalso\ eval{\isaliteral{5F}{\isacharunderscore}}form\ q\isanewline |
|
308 |
\ \ \ \ {\isaliteral{7C}{\isacharbar}}\ eval{\isaliteral{5F}{\isacharunderscore}}form\ {\isaliteral{28}{\isacharparenleft}}% |
|
38560 | 309 |
\isaantiq |
40406 | 310 |
code\ Or{}% |
38560 | 311 |
\endisaantiq |
40406 | 312 |
\ {\isaliteral{28}{\isacharparenleft}}p{\isaliteral{2C}{\isacharcomma}}\ q{\isaliteral{29}{\isacharparenright}}{\isaliteral{29}{\isacharparenright}}\ {\isaliteral{3D}{\isacharequal}}\isanewline |
313 |
\ \ \ \ \ \ \ \ eval{\isaliteral{5F}{\isacharunderscore}}form\ p\ orelse\ eval{\isaliteral{5F}{\isacharunderscore}}form\ q{\isaliteral{3B}{\isacharsemicolon}}\isanewline |
|
314 |
{\isaliteral{2A7D}{\isacharverbatimclose}}% |
|
39745 | 315 |
\endisatagquotett |
316 |
{\isafoldquotett}% |
|
38560 | 317 |
% |
39745 | 318 |
\isadelimquotett |
38560 | 319 |
% |
39745 | 320 |
\endisadelimquotett |
38560 | 321 |
% |
322 |
\begin{isamarkuptext}% |
|
39609 | 323 |
\noindent \isa{code} takes as argument the name of a constant; |
324 |
after the whole ML is read, the necessary code is generated |
|
325 |
transparently and the corresponding constant names are inserted. |
|
326 |
This technique also allows to use pattern matching on constructors |
|
39643 | 327 |
stemming from compiled datatypes. Note that the \isa{code} |
328 |
antiquotation may not refer to constants which carry adaptations; |
|
329 |
here you have to refer to the corresponding adapted code directly. |
|
38560 | 330 |
|
39609 | 331 |
For a less simplistic example, theory \isa{Approximation} in |
40406 | 332 |
the \isa{Decision{\isaliteral{5F}{\isacharunderscore}}Procs} session is a good reference.% |
38560 | 333 |
\end{isamarkuptext}% |
334 |
\isamarkuptrue% |
|
335 |
% |
|
40406 | 336 |
\isamarkupsubsubsection{Static embedding of generated code into system runtime -- \isa{code{\isaliteral{5F}{\isacharunderscore}}reflect}% |
39599 | 337 |
} |
338 |
\isamarkuptrue% |
|
339 |
% |
|
340 |
\begin{isamarkuptext}% |
|
39609 | 341 |
The \isa{code} antiquoation is lightweight, but the generated code |
342 |
is only accessible while the ML section is processed. Sometimes this |
|
343 |
is not appropriate, especially if the generated code contains datatype |
|
344 |
declarations which are shared with other parts of the system. In these |
|
40406 | 345 |
cases, \indexdef{}{command}{code\_reflect}\hypertarget{command.code-reflect}{\hyperlink{command.code-reflect}{\mbox{\isa{\isacommand{code{\isaliteral{5F}{\isacharunderscore}}reflect}}}}} can be used:% |
39609 | 346 |
\end{isamarkuptext}% |
347 |
\isamarkuptrue% |
|
348 |
% |
|
349 |
\isadelimquote |
|
350 |
% |
|
351 |
\endisadelimquote |
|
352 |
% |
|
353 |
\isatagquote |
|
40406 | 354 |
\isacommand{code{\isaliteral{5F}{\isacharunderscore}}reflect}\isamarkupfalse% |
355 |
\ Sum{\isaliteral{5F}{\isacharunderscore}}Type\isanewline |
|
356 |
\ \ \isakeyword{datatypes}\ sum\ {\isaliteral{3D}{\isacharequal}}\ Inl\ {\isaliteral{7C}{\isacharbar}}\ Inr\isanewline |
|
357 |
\ \ \isakeyword{functions}\ {\isaliteral{22}{\isachardoublequoteopen}}Sum{\isaliteral{5F}{\isacharunderscore}}Type{\isaliteral{2E}{\isachardot}}Projl{\isaliteral{22}{\isachardoublequoteclose}}\ {\isaliteral{22}{\isachardoublequoteopen}}Sum{\isaliteral{5F}{\isacharunderscore}}Type{\isaliteral{2E}{\isachardot}}Projr{\isaliteral{22}{\isachardoublequoteclose}}% |
|
39609 | 358 |
\endisatagquote |
359 |
{\isafoldquote}% |
|
360 |
% |
|
361 |
\isadelimquote |
|
362 |
% |
|
363 |
\endisadelimquote |
|
364 |
% |
|
365 |
\begin{isamarkuptext}% |
|
40406 | 366 |
\noindent \indexdef{}{command}{code\_reflect}\hypertarget{command.code-reflect}{\hyperlink{command.code-reflect}{\mbox{\isa{\isacommand{code{\isaliteral{5F}{\isacharunderscore}}reflect}}}}} takes a structure name and |
39609 | 367 |
references to datatypes and functions; for these code is compiled |
368 |
into the named ML structure and the \emph{Eval} target is modified |
|
369 |
in a way that future code generation will reference these |
|
370 |
precompiled versions of the given datatypes and functions. This |
|
371 |
also allows to refer to the referenced datatypes and functions from |
|
372 |
arbitrary ML code as well. |
|
373 |
||
40406 | 374 |
A typical example for \hyperlink{command.code-reflect}{\mbox{\isa{\isacommand{code{\isaliteral{5F}{\isacharunderscore}}reflect}}}} can be found in the |
46563 | 375 |
\isa{Predicate} theory.% |
39599 | 376 |
\end{isamarkuptext}% |
377 |
\isamarkuptrue% |
|
378 |
% |
|
40406 | 379 |
\isamarkupsubsubsection{Separate compilation -- \isa{code{\isaliteral{5F}{\isacharunderscore}}reflect}% |
39599 | 380 |
} |
381 |
\isamarkuptrue% |
|
382 |
% |
|
383 |
\begin{isamarkuptext}% |
|
39609 | 384 |
For technical reasons it is sometimes necessary to separate |
385 |
generation and compilation of code which is supposed to be used in |
|
40406 | 386 |
the system runtime. For this \hyperlink{command.code-reflect}{\mbox{\isa{\isacommand{code{\isaliteral{5F}{\isacharunderscore}}reflect}}}} with an |
39609 | 387 |
optional \isa{file} argument can be used:% |
388 |
\end{isamarkuptext}% |
|
389 |
\isamarkuptrue% |
|
390 |
% |
|
391 |
\isadelimquote |
|
392 |
% |
|
393 |
\endisadelimquote |
|
394 |
% |
|
395 |
\isatagquote |
|
40406 | 396 |
\isacommand{code{\isaliteral{5F}{\isacharunderscore}}reflect}\isamarkupfalse% |
39609 | 397 |
\ Rat\isanewline |
40406 | 398 |
\ \ \isakeyword{datatypes}\ rat\ {\isaliteral{3D}{\isacharequal}}\ Frct\isanewline |
39609 | 399 |
\ \ \isakeyword{functions}\ Fract\isanewline |
40406 | 400 |
\ \ \ \ {\isaliteral{22}{\isachardoublequoteopen}}{\isaliteral{28}{\isacharparenleft}}plus\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ rat\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ rat\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ rat{\isaliteral{29}{\isacharparenright}}{\isaliteral{22}{\isachardoublequoteclose}}\ {\isaliteral{22}{\isachardoublequoteopen}}{\isaliteral{28}{\isacharparenleft}}minus\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ rat\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ rat\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ rat{\isaliteral{29}{\isacharparenright}}{\isaliteral{22}{\isachardoublequoteclose}}\isanewline |
401 |
\ \ \ \ {\isaliteral{22}{\isachardoublequoteopen}}{\isaliteral{28}{\isacharparenleft}}times\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ rat\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ rat\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ rat{\isaliteral{29}{\isacharparenright}}{\isaliteral{22}{\isachardoublequoteclose}}\ {\isaliteral{22}{\isachardoublequoteopen}}{\isaliteral{28}{\isacharparenleft}}divide\ {\isaliteral{3A}{\isacharcolon}}{\isaliteral{3A}{\isacharcolon}}\ rat\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ rat\ {\isaliteral{5C3C52696768746172726F773E}{\isasymRightarrow}}\ rat{\isaliteral{29}{\isacharparenright}}{\isaliteral{22}{\isachardoublequoteclose}}\isanewline |
|
402 |
\ \ \isakeyword{file}\ {\isaliteral{22}{\isachardoublequoteopen}}examples{\isaliteral{2F}{\isacharslash}}rat{\isaliteral{2E}{\isachardot}}ML{\isaliteral{22}{\isachardoublequoteclose}}% |
|
39609 | 403 |
\endisatagquote |
404 |
{\isafoldquote}% |
|
405 |
% |
|
406 |
\isadelimquote |
|
407 |
% |
|
408 |
\endisadelimquote |
|
409 |
% |
|
410 |
\begin{isamarkuptext}% |
|
39643 | 411 |
\noindent This merely generates the referenced code to the given |
39609 | 412 |
file which can be included into the system runtime later on.% |
39599 | 413 |
\end{isamarkuptext}% |
414 |
\isamarkuptrue% |
|
415 |
% |
|
38560 | 416 |
\isadelimtheory |
417 |
% |
|
418 |
\endisadelimtheory |
|
419 |
% |
|
420 |
\isatagtheory |
|
421 |
\isacommand{end}\isamarkupfalse% |
|
422 |
% |
|
423 |
\endisatagtheory |
|
424 |
{\isafoldtheory}% |
|
425 |
% |
|
426 |
\isadelimtheory |
|
427 |
% |
|
428 |
\endisadelimtheory |
|
429 |
\isanewline |
|
46523 | 430 |
\isanewline |
38560 | 431 |
\end{isabellebody}% |
432 |
%%% Local Variables: |
|
433 |
%%% mode: latex |
|
434 |
%%% TeX-master: "root" |
|
435 |
%%% End: |