79 Ultimately, the code generator which this tutorial deals with |
79 Ultimately, the code generator which this tutorial deals with |
80 is supposed to replace the already established code generator |
80 is supposed to replace the already established code generator |
81 by Stefan Berghofer \cite{Berghofer-Nipkow:2002}. |
81 by Stefan Berghofer \cite{Berghofer-Nipkow:2002}. |
82 So, for the moment, there are two distinct code generators |
82 So, for the moment, there are two distinct code generators |
83 in Isabelle. |
83 in Isabelle. |
84 Also note that while the framework itself is largely |
84 Also note that while the framework itself is |
85 object-logic independent, only @{text HOL} provides a reasonable |
85 object-logic independent, only @{text HOL} provides a reasonable |
86 framework setup. |
86 framework setup. |
87 \end{warn} |
87 \end{warn} |
88 *} |
88 *} |
89 |
89 |
90 |
90 |
91 section {* An example: a simple theory of search trees \label{sec:example} *} |
91 section {* An example: a simple theory of search trees \label{sec:example} *} |
92 |
92 |
93 text {* |
93 text {* |
94 When writing executable specifications, it is convenient to use |
94 When writing executable specifications using @{text HOL}, |
|
95 it is convenient to use |
95 three existing packages: the datatype package for defining |
96 three existing packages: the datatype package for defining |
96 datatypes, the function package for (recursive) functions, |
97 datatypes, the function package for (recursive) functions, |
97 and the class package for overloaded definitions. |
98 and the class package for overloaded definitions. |
98 |
99 |
99 We develope a small theory of search trees; trees are represented |
100 We develope a small theory of search trees; trees are represented |
206 section {* Basics \label{sec:basics} *} |
207 section {* Basics \label{sec:basics} *} |
207 |
208 |
208 subsection {* Invoking the code generator *} |
209 subsection {* Invoking the code generator *} |
209 |
210 |
210 text {* |
211 text {* |
211 Thanks to a reasonable setup of the HOL theories, in |
212 Thanks to a reasonable setup of the @{text HOL} theories, in |
212 most cases code generation proceeds without further ado: |
213 most cases code generation proceeds without further ado: |
213 *} |
214 *} |
214 |
215 |
215 fun |
216 fun |
216 fac :: "nat \<Rightarrow> nat" where |
217 fac :: "nat \<Rightarrow> nat" where |
275 text {* |
276 text {* |
276 \noindent which displays a table of constant with corresponding |
277 \noindent which displays a table of constant with corresponding |
277 defining equations (the additional stuff displayed |
278 defining equations (the additional stuff displayed |
278 shall not bother us for the moment). |
279 shall not bother us for the moment). |
279 |
280 |
280 The typical HOL tools are already set up in a way that |
281 The typical @{text HOL} tools are already set up in a way that |
281 function definitions introduced by @{text "\<DEFINITION>"}, |
282 function definitions introduced by @{text "\<DEFINITION>"}, |
282 @{text "\<FUN>"}, |
283 @{text "\<FUN>"}, |
283 @{text "\<FUNCTION>"}, @{text "\<PRIMREC>"}, |
284 @{text "\<FUNCTION>"}, @{text "\<PRIMREC>"}, |
284 @{text "\<RECDEF>"} are implicitly propagated |
285 @{text "\<RECDEF>"} are implicitly propagated |
285 to this defining equation table. Specific theorems may be |
286 to this defining equation table. Specific theorems may be |
448 *} |
449 *} |
449 |
450 |
450 subsection {* Library theories \label{sec:library} *} |
451 subsection {* Library theories \label{sec:library} *} |
451 |
452 |
452 text {* |
453 text {* |
453 The HOL \emph{Main} theory already provides a code generator setup |
454 The @{text HOL} @{text Main} theory already provides a code |
|
455 generator setup |
454 which should be suitable for most applications. Common extensions |
456 which should be suitable for most applications. Common extensions |
455 and modifications are available by certain theories of the HOL |
457 and modifications are available by certain theories of the @{text HOL} |
456 library; beside being useful in applications, they may serve |
458 library; beside being useful in applications, they may serve |
457 as a tutorial for customizing the code generator setup. |
459 as a tutorial for customizing the code generator setup. |
458 |
460 |
459 \begin{description} |
461 \begin{description} |
460 |
462 |
461 \item[@{text "Pretty_Int"}] represents HOL integers by big |
463 \item[@{text "Pretty_Int"}] represents @{text HOL} integers by big |
462 integer literals in target languages. |
464 integer literals in target languages. |
463 \item[@{text "Pretty_Char"}] represents HOL characters by |
465 \item[@{text "Pretty_Char"}] represents @{text HOL} characters by |
464 character literals in target languages. |
466 character literals in target languages. |
465 \item[@{text "Pretty_Char_chr"}] like @{text "Pretty_Char_chr"}, |
467 \item[@{text "Pretty_Char_chr"}] like @{text "Pretty_Char_chr"}, |
466 but also offers treatment of character codes; includes |
468 but also offers treatment of character codes; includes |
467 @{text "Pretty_Int"}. |
469 @{text "Pretty_Int"}. |
468 \item[@{text "ExecutableSet"}] allows to generate code |
470 \item[@{text "ExecutableSet"}] allows to generate code |
472 \item[@{text "EfficientNat"}] \label{eff_nat} implements natural numbers by integers, |
474 \item[@{text "EfficientNat"}] \label{eff_nat} implements natural numbers by integers, |
473 which in general will result in higher efficency; pattern |
475 which in general will result in higher efficency; pattern |
474 matching with @{const "0\<Colon>nat"} / @{const "Suc"} |
476 matching with @{const "0\<Colon>nat"} / @{const "Suc"} |
475 is eliminated; includes @{text "Pretty_Int"}. |
477 is eliminated; includes @{text "Pretty_Int"}. |
476 \item[@{text "MLString"}] provides an additional datatype @{text "mlstring"}; |
478 \item[@{text "MLString"}] provides an additional datatype @{text "mlstring"}; |
477 in the HOL default setup, strings in HOL are mapped to list |
479 in the @{text HOL} default setup, strings in HOL are mapped to list |
478 of HOL characters in SML; values of type @{text "mlstring"} are |
480 of @{text HOL} characters in SML; values of type @{text "mlstring"} are |
479 mapped to strings in SML. |
481 mapped to strings in SML. |
480 |
482 |
481 \end{description} |
483 \end{description} |
|
484 |
|
485 \begin{warn} |
|
486 When importing any of these theories, they should form the last |
|
487 items in an import list. Since these theories adapt the |
|
488 code generator setup in a non-conservative fashion, |
|
489 strange effects may occur otherwise. |
|
490 \end{warn} |
482 *} |
491 *} |
483 |
492 |
484 subsection {* Preprocessing *} |
493 subsection {* Preprocessing *} |
485 |
494 |
486 text {* |
495 text {* |