94 be trusted, including code generator configurations by the user. |
94 be trusted, including code generator configurations by the user. |
95 |
95 |
96 Evaluation is carried out in a target language \emph{Eval} which |
96 Evaluation is carried out in a target language \emph{Eval} which |
97 inherits from \emph{SML} but for convenience uses parts of the |
97 inherits from \emph{SML} but for convenience uses parts of the |
98 Isabelle runtime environment. The soundness of computation carried |
98 Isabelle runtime environment. The soundness of computation carried |
99 out there crucially on the correctness of the code generator; this |
99 out there depends crucially on the correctness of the code |
100 is one of the reasons why you should not use adaptation (see |
100 generator; this is one of the reasons why you should not use |
101 \secref{sec:adaptation}) frivolously.% |
101 adaptation (see \secref{sec:adaptation}) frivolously.% |
102 \end{isamarkuptext}% |
102 \end{isamarkuptext}% |
103 \isamarkuptrue% |
103 \isamarkuptrue% |
104 % |
104 % |
105 \isamarkupsubsection{Aspects of evaluation% |
105 \isamarkupsubsection{Aspects of evaluation% |
106 } |
106 } |
240 \isamarkupsubsection{Intimate connection between logic and system runtime% |
240 \isamarkupsubsection{Intimate connection between logic and system runtime% |
241 } |
241 } |
242 \isamarkuptrue% |
242 \isamarkuptrue% |
243 % |
243 % |
244 \begin{isamarkuptext}% |
244 \begin{isamarkuptext}% |
245 FIXME% |
245 The toolbox of static evaluation conversions forms a reasonable base |
246 \end{isamarkuptext}% |
246 to interweave generated code and system tools. However in some |
247 \isamarkuptrue% |
247 situations more direct interaction is desirable.% |
248 % |
248 \end{isamarkuptext}% |
249 \isamarkupsubsubsection{Static embedding of generated code into system runtime -- the code antiquotation% |
249 \isamarkuptrue% |
250 } |
250 % |
251 \isamarkuptrue% |
251 \isamarkupsubsubsection{Static embedding of generated code into system runtime -- the \isa{code} antiquotation% |
252 % |
252 } |
253 \begin{isamarkuptext}% |
253 \isamarkuptrue% |
254 FIXME |
254 % |
255 |
255 \begin{isamarkuptext}% |
256 In scenarios involving techniques like reflection it is quite common |
256 The \isa{code} antiquotation allows to include constants from |
257 that code generated from a theory forms the basis for implementing a |
257 generated code directly into ML system code, as in the following toy |
258 proof procedure in \isa{SML}. To facilitate interfacing of |
258 example:% |
259 generated code with system code, the code generator provides a |
|
260 \isa{code} antiquotation:% |
|
261 \end{isamarkuptext}% |
259 \end{isamarkuptext}% |
262 \isamarkuptrue% |
260 \isamarkuptrue% |
263 % |
261 % |
264 \isadelimquote |
262 \isadelimquote |
265 % |
263 % |
311 \isadelimquotett |
309 \isadelimquotett |
312 % |
310 % |
313 \endisadelimquotett |
311 \endisadelimquotett |
314 % |
312 % |
315 \begin{isamarkuptext}% |
313 \begin{isamarkuptext}% |
316 \noindent \isa{code} takes as argument the name of a constant; after the |
314 \noindent \isa{code} takes as argument the name of a constant; |
317 whole \isa{SML} is read, the necessary code is generated transparently |
315 after the whole ML is read, the necessary code is generated |
318 and the corresponding constant names are inserted. This technique also |
316 transparently and the corresponding constant names are inserted. |
319 allows to use pattern matching on constructors stemming from compiled |
317 This technique also allows to use pattern matching on constructors |
320 \isa{datatypes}. |
318 stemming from compiled \isa{datatypes}. Note that it is not |
321 |
319 possible to refer to constants which carry adaptations by means of |
322 For a less simplistic example, theory \isa{Ferrack} is |
320 \isa{code}; here you have to refer to the adapted code directly. |
323 a good reference.% |
321 |
|
322 For a less simplistic example, theory \isa{Approximation} in |
|
323 the \isa{Decision{\isacharunderscore}Procs} session is a good reference.% |
324 \end{isamarkuptext}% |
324 \end{isamarkuptext}% |
325 \isamarkuptrue% |
325 \isamarkuptrue% |
326 % |
326 % |
327 \isamarkupsubsubsection{Static embedding of generated code into system runtime -- \isa{code{\isacharunderscore}reflect}% |
327 \isamarkupsubsubsection{Static embedding of generated code into system runtime -- \isa{code{\isacharunderscore}reflect}% |
328 } |
328 } |
329 \isamarkuptrue% |
329 \isamarkuptrue% |
330 % |
330 % |
331 \begin{isamarkuptext}% |
331 \begin{isamarkuptext}% |
332 FIXME \indexdef{}{command}{code\_reflect}\hypertarget{command.code-reflect}{\hyperlink{command.code-reflect}{\mbox{\isa{\isacommand{code{\isacharunderscore}reflect}}}}}% |
332 The \isa{code} antiquoation is lightweight, but the generated code |
|
333 is only accessible while the ML section is processed. Sometimes this |
|
334 is not appropriate, especially if the generated code contains datatype |
|
335 declarations which are shared with other parts of the system. In these |
|
336 cases, \indexdef{}{command}{code\_reflect}\hypertarget{command.code-reflect}{\hyperlink{command.code-reflect}{\mbox{\isa{\isacommand{code{\isacharunderscore}reflect}}}}} can be used:% |
|
337 \end{isamarkuptext}% |
|
338 \isamarkuptrue% |
|
339 % |
|
340 \isadelimquote |
|
341 % |
|
342 \endisadelimquote |
|
343 % |
|
344 \isatagquote |
|
345 \isacommand{code{\isacharunderscore}reflect}\isamarkupfalse% |
|
346 \ Sum{\isacharunderscore}Type\isanewline |
|
347 \ \ \isakeyword{datatypes}\ sum\ {\isacharequal}\ Inl\ {\isacharbar}\ Inr\isanewline |
|
348 \ \ \isakeyword{functions}\ {\isachardoublequoteopen}Sum{\isacharunderscore}Type{\isachardot}Projl{\isachardoublequoteclose}\ {\isachardoublequoteopen}Sum{\isacharunderscore}Type{\isachardot}Projr{\isachardoublequoteclose}% |
|
349 \endisatagquote |
|
350 {\isafoldquote}% |
|
351 % |
|
352 \isadelimquote |
|
353 % |
|
354 \endisadelimquote |
|
355 % |
|
356 \begin{isamarkuptext}% |
|
357 \noindent \indexdef{}{command}{code\_reflect}\hypertarget{command.code-reflect}{\hyperlink{command.code-reflect}{\mbox{\isa{\isacommand{code{\isacharunderscore}reflect}}}}} takes a structure name and |
|
358 references to datatypes and functions; for these code is compiled |
|
359 into the named ML structure and the \emph{Eval} target is modified |
|
360 in a way that future code generation will reference these |
|
361 precompiled versions of the given datatypes and functions. This |
|
362 also allows to refer to the referenced datatypes and functions from |
|
363 arbitrary ML code as well. |
|
364 |
|
365 A typical example for \hyperlink{command.code-reflect}{\mbox{\isa{\isacommand{code{\isacharunderscore}reflect}}}} can be found in the |
|
366 \hyperlink{theory.Predicate}{\mbox{\isa{Predicate}}} theory.% |
333 \end{isamarkuptext}% |
367 \end{isamarkuptext}% |
334 \isamarkuptrue% |
368 \isamarkuptrue% |
335 % |
369 % |
336 \isamarkupsubsubsection{Separate compilation -- \isa{code{\isacharunderscore}reflect}% |
370 \isamarkupsubsubsection{Separate compilation -- \isa{code{\isacharunderscore}reflect}% |
337 } |
371 } |
338 \isamarkuptrue% |
372 \isamarkuptrue% |
339 % |
373 % |
340 \begin{isamarkuptext}% |
374 \begin{isamarkuptext}% |
341 FIXME% |
375 For technical reasons it is sometimes necessary to separate |
|
376 generation and compilation of code which is supposed to be used in |
|
377 the system runtime. For this \hyperlink{command.code-reflect}{\mbox{\isa{\isacommand{code{\isacharunderscore}reflect}}}} with an |
|
378 optional \isa{file} argument can be used:% |
|
379 \end{isamarkuptext}% |
|
380 \isamarkuptrue% |
|
381 % |
|
382 \isadelimquote |
|
383 % |
|
384 \endisadelimquote |
|
385 % |
|
386 \isatagquote |
|
387 \isacommand{code{\isacharunderscore}reflect}\isamarkupfalse% |
|
388 \ Rat\isanewline |
|
389 \ \ \isakeyword{datatypes}\ rat\ {\isacharequal}\ Frct\isanewline |
|
390 \ \ \isakeyword{functions}\ Fract\isanewline |
|
391 \ \ \ \ {\isachardoublequoteopen}{\isacharparenleft}plus\ {\isacharcolon}{\isacharcolon}\ rat\ {\isasymRightarrow}\ rat\ {\isasymRightarrow}\ rat{\isacharparenright}{\isachardoublequoteclose}\ {\isachardoublequoteopen}{\isacharparenleft}minus\ {\isacharcolon}{\isacharcolon}\ rat\ {\isasymRightarrow}\ rat\ {\isasymRightarrow}\ rat{\isacharparenright}{\isachardoublequoteclose}\isanewline |
|
392 \ \ \ \ {\isachardoublequoteopen}{\isacharparenleft}times\ {\isacharcolon}{\isacharcolon}\ rat\ {\isasymRightarrow}\ rat\ {\isasymRightarrow}\ rat{\isacharparenright}{\isachardoublequoteclose}\ {\isachardoublequoteopen}{\isacharparenleft}divide\ {\isacharcolon}{\isacharcolon}\ rat\ {\isasymRightarrow}\ rat\ {\isasymRightarrow}\ rat{\isacharparenright}{\isachardoublequoteclose}\isanewline |
|
393 \ \ \isakeyword{file}\ {\isachardoublequoteopen}examples{\isacharslash}rat{\isachardot}ML{\isachardoublequoteclose}% |
|
394 \endisatagquote |
|
395 {\isafoldquote}% |
|
396 % |
|
397 \isadelimquote |
|
398 % |
|
399 \endisadelimquote |
|
400 % |
|
401 \begin{isamarkuptext}% |
|
402 \noindent This just generates the references code to the specified |
|
403 file which can be included into the system runtime later on.% |
342 \end{isamarkuptext}% |
404 \end{isamarkuptext}% |
343 \isamarkuptrue% |
405 \isamarkuptrue% |
344 % |
406 % |
345 \isadelimtheory |
407 \isadelimtheory |
346 % |
408 % |