doc-src/IsarAdvanced/Codegen/Thy/document/Codegen.tex
changeset 22550 c5039bee2602
parent 22479 de15ea8fb348
child 22751 1bfd75c1f232
equal deleted inserted replaced
22549:ab23925c64d6 22550:c5039bee2602
    47   application of theorem proving systems in the area of
    47   application of theorem proving systems in the area of
    48   software development and verification, its relevance manifests
    48   software development and verification, its relevance manifests
    49   for running test cases and rapid prototyping.  In logical
    49   for running test cases and rapid prototyping.  In logical
    50   calculi like constructive type theory,
    50   calculi like constructive type theory,
    51   a notion of executability is implicit due to the nature
    51   a notion of executability is implicit due to the nature
    52   of the calculus.  In contrast, specifications in Isabelle/HOL
    52   of the calculus.  In contrast, specifications in Isabelle
    53   can be highly non-executable.  In order to bridge
    53   can be highly non-executable.  In order to bridge
    54   the gap between logic and executable specifications,
    54   the gap between logic and executable specifications,
    55   an explicit non-trivial transformation has to be applied:
    55   an explicit non-trivial transformation has to be applied:
    56   code generation.
    56   code generation.
    57 
    57 
    59   Isabelle system \cite{isa-tutorial}.
    59   Isabelle system \cite{isa-tutorial}.
    60   Generic in the sense that the
    60   Generic in the sense that the
    61   \qn{target language} for which code shall ultimately be
    61   \qn{target language} for which code shall ultimately be
    62   generated is not fixed but may be an arbitrary state-of-the-art
    62   generated is not fixed but may be an arbitrary state-of-the-art
    63   functional programming language (currently, the implementation
    63   functional programming language (currently, the implementation
    64   supports SML \cite{SML}, OCaml \cite{OCaml} and Haskell \cite{haskell-revised-report}).
    64   supports SML \cite{SML}, OCaml \cite{OCaml} and Haskell
       
    65   \cite{haskell-revised-report}).
    65   We aim to provide a
    66   We aim to provide a
    66   versatile environment
    67   versatile environment
    67   suitable for software development and verification,
    68   suitable for software development and verification,
    68   structuring the process
    69   structuring the process
    69   of code generation into a small set of orthogonal principles
    70   of code generation into a small set of orthogonal principles
    70   while achieving a big coverage of application areas
    71   while achieving a big coverage of application areas
    71   with maximum flexibility.
    72   with maximum flexibility.
    72 
    73 
    73   For readers, some familiarity and experience
    74   Conceptually the code generator framework is part
    74   with the ingredients
    75   of Isabelle's \isa{Pure} meta logic; the object logic
    75   of the HOL \emph{Main} theory is assumed.%
    76   \isa{HOL} which is an extension of \isa{Pure}
       
    77   already comes with a reasonable framework setup and thus provides
       
    78   a good working horse for raising code-generation-driven
       
    79   applications.  So, we assume some familiarity and experience
       
    80   with the ingredients of the \isa{HOL} \emph{Main} theory
       
    81   (see also \cite{isa-tutorial}).%
    76 \end{isamarkuptext}%
    82 \end{isamarkuptext}%
    77 \isamarkuptrue%
    83 \isamarkuptrue%
    78 %
    84 %
    79 \isamarkupsubsection{Overview%
    85 \isamarkupsubsection{Overview%
    80 }
    86 }
    81 \isamarkuptrue%
    87 \isamarkuptrue%
    82 %
    88 %
    83 \begin{isamarkuptext}%
    89 \begin{isamarkuptext}%
    84 The code generator aims to be usable with no further ado
    90 The code generator aims to be usable with no further ado
    85   in most cases while allowing for detailed customization.
    91   in most cases while allowing for detailed customization.
    86   This manifests in the structure of this tutorial: this introduction
    92   This manifests in the structure of this tutorial:
    87   continues with a short introduction of concepts.  Section
    93   we start with a generic example \secref{sec:example}
       
    94   and introduce code generation concepts \secref{sec:concept}.
       
    95   Section
    88   \secref{sec:basics} explains how to use the framework naively,
    96   \secref{sec:basics} explains how to use the framework naively,
    89   presuming a reasonable default setup.  Then, section
    97   presuming a reasonable default setup.  Then, section
    90   \secref{sec:advanced} deals with advanced topics,
    98   \secref{sec:advanced} deals with advanced topics,
    91   introducing further aspects of the code generator framework
    99   introducing further aspects of the code generator framework
    92   in a motivation-driven manner.  Last, section \secref{sec:ml}
   100   in a motivation-driven manner.  Last, section \secref{sec:ml}
    97     is supposed to replace the already established code generator
   105     is supposed to replace the already established code generator
    98     by Stefan Berghofer \cite{Berghofer-Nipkow:2002}.
   106     by Stefan Berghofer \cite{Berghofer-Nipkow:2002}.
    99     So, for the moment, there are two distinct code generators
   107     So, for the moment, there are two distinct code generators
   100     in Isabelle.
   108     in Isabelle.
   101     Also note that while the framework itself is largely
   109     Also note that while the framework itself is largely
   102     object-logic independent, only HOL provides a reasonable
   110     object-logic independent, only \isa{HOL} provides a reasonable
   103     framework setup.    
   111     framework setup.    
   104   \end{warn}%
   112   \end{warn}%
   105 \end{isamarkuptext}%
   113 \end{isamarkuptext}%
   106 \isamarkuptrue%
   114 \isamarkuptrue%
   107 %
   115 %
   108 \isamarkupsubsection{An exmaple: a simple theory of search trees%
   116 \isamarkupsection{An example: a simple theory of search trees \label{sec:example}%
   109 }
   117 }
       
   118 \isamarkuptrue%
       
   119 %
       
   120 \begin{isamarkuptext}%
       
   121 When writing executable specifications, it is convenient to use
       
   122   three existing packages: the datatype package for defining
       
   123   datatypes, the function package for (recursive) functions,
       
   124   and the class package for overloaded definitions.
       
   125 
       
   126   We develope a small theory of search trees; trees are represented
       
   127   as a datatype with key type \isa{{\isacharprime}a} and value type \isa{{\isacharprime}b}:%
       
   128 \end{isamarkuptext}%
   110 \isamarkuptrue%
   129 \isamarkuptrue%
   111 \isacommand{datatype}\isamarkupfalse%
   130 \isacommand{datatype}\isamarkupfalse%
   112 \ {\isacharparenleft}{\isacharprime}a{\isacharcomma}\ {\isacharprime}b{\isacharparenright}\ searchtree\ {\isacharequal}\ Leaf\ {\isachardoublequoteopen}{\isacharprime}a{\isasymColon}linorder{\isachardoublequoteclose}\ {\isacharprime}b\isanewline
   131 \ {\isacharparenleft}{\isacharprime}a{\isacharcomma}\ {\isacharprime}b{\isacharparenright}\ searchtree\ {\isacharequal}\ Leaf\ {\isachardoublequoteopen}{\isacharprime}a{\isasymColon}linorder{\isachardoublequoteclose}\ {\isacharprime}b\isanewline
   113 \ \ {\isacharbar}\ Branch\ {\isachardoublequoteopen}{\isacharparenleft}{\isacharprime}a{\isacharcomma}\ {\isacharprime}b{\isacharparenright}\ searchtree{\isachardoublequoteclose}\ {\isachardoublequoteopen}{\isacharprime}a{\isachardoublequoteclose}\ {\isachardoublequoteopen}{\isacharparenleft}{\isacharprime}a{\isacharcomma}\ {\isacharprime}b{\isacharparenright}\ searchtree{\isachardoublequoteclose}\isanewline
   132 \ \ {\isacharbar}\ Branch\ {\isachardoublequoteopen}{\isacharparenleft}{\isacharprime}a{\isacharcomma}\ {\isacharprime}b{\isacharparenright}\ searchtree{\isachardoublequoteclose}\ {\isachardoublequoteopen}{\isacharprime}a{\isachardoublequoteclose}\ {\isachardoublequoteopen}{\isacharparenleft}{\isacharprime}a{\isacharcomma}\ {\isacharprime}b{\isacharparenright}\ searchtree{\isachardoublequoteclose}%
   114 \isanewline
   133 \begin{isamarkuptext}%
       
   134 \noindent Note that we have constrained the type of keys
       
   135   to the class of total orders, \isa{linorder}.
       
   136 
       
   137   We define \isa{find} and \isa{update} functions:%
       
   138 \end{isamarkuptext}%
       
   139 \isamarkuptrue%
   115 \isacommand{fun}\isamarkupfalse%
   140 \isacommand{fun}\isamarkupfalse%
   116 \isanewline
   141 \isanewline
   117 \ \ find\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isacharparenleft}{\isacharprime}a{\isasymColon}linorder{\isacharcomma}\ {\isacharprime}b{\isacharparenright}\ searchtree\ {\isasymRightarrow}\ {\isacharprime}a\ {\isasymRightarrow}\ {\isacharprime}b\ option{\isachardoublequoteclose}\ \isakeyword{where}\isanewline
   142 \ \ find\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isacharparenleft}{\isacharprime}a{\isasymColon}linorder{\isacharcomma}\ {\isacharprime}b{\isacharparenright}\ searchtree\ {\isasymRightarrow}\ {\isacharprime}a\ {\isasymRightarrow}\ {\isacharprime}b\ option{\isachardoublequoteclose}\ \isakeyword{where}\isanewline
   118 \ \ {\isachardoublequoteopen}find\ {\isacharparenleft}Leaf\ key\ val{\isacharparenright}\ it\ {\isacharequal}\ {\isacharparenleft}if\ it\ {\isacharequal}\ key\ then\ Some\ val\ else\ None{\isacharparenright}{\isachardoublequoteclose}\isanewline
   143 \ \ {\isachardoublequoteopen}find\ {\isacharparenleft}Leaf\ key\ val{\isacharparenright}\ it\ {\isacharequal}\ {\isacharparenleft}if\ it\ {\isacharequal}\ key\ then\ Some\ val\ else\ None{\isacharparenright}{\isachardoublequoteclose}\isanewline
   119 \ \ {\isacharbar}\ {\isachardoublequoteopen}find\ {\isacharparenleft}Branch\ t{\isadigit{1}}\ key\ t{\isadigit{2}}{\isacharparenright}\ it\ {\isacharequal}\ {\isacharparenleft}if\ it\ {\isasymle}\ key\ then\ find\ t{\isadigit{1}}\ it\ else\ find\ t{\isadigit{2}}\ it{\isacharparenright}{\isachardoublequoteclose}\isanewline
   144 \ \ {\isacharbar}\ {\isachardoublequoteopen}find\ {\isacharparenleft}Branch\ t{\isadigit{1}}\ key\ t{\isadigit{2}}{\isacharparenright}\ it\ {\isacharequal}\ {\isacharparenleft}if\ it\ {\isasymle}\ key\ then\ find\ t{\isadigit{1}}\ it\ else\ find\ t{\isadigit{2}}\ it{\isacharparenright}{\isachardoublequoteclose}\isanewline
   129 \ \ \ {\isacharparenright}{\isachardoublequoteclose}\isanewline
   154 \ \ \ {\isacharparenright}{\isachardoublequoteclose}\isanewline
   130 \ \ {\isacharbar}\ {\isachardoublequoteopen}update\ {\isacharparenleft}it{\isacharcomma}\ entry{\isacharparenright}\ {\isacharparenleft}Branch\ t{\isadigit{1}}\ key\ t{\isadigit{2}}{\isacharparenright}\ {\isacharequal}\ {\isacharparenleft}\isanewline
   155 \ \ {\isacharbar}\ {\isachardoublequoteopen}update\ {\isacharparenleft}it{\isacharcomma}\ entry{\isacharparenright}\ {\isacharparenleft}Branch\ t{\isadigit{1}}\ key\ t{\isadigit{2}}{\isacharparenright}\ {\isacharequal}\ {\isacharparenleft}\isanewline
   131 \ \ \ \ if\ it\ {\isasymle}\ key\isanewline
   156 \ \ \ \ if\ it\ {\isasymle}\ key\isanewline
   132 \ \ \ \ \ \ then\ {\isacharparenleft}Branch\ {\isacharparenleft}update\ {\isacharparenleft}it{\isacharcomma}\ entry{\isacharparenright}\ t{\isadigit{1}}{\isacharparenright}\ key\ t{\isadigit{2}}{\isacharparenright}\isanewline
   157 \ \ \ \ \ \ then\ {\isacharparenleft}Branch\ {\isacharparenleft}update\ {\isacharparenleft}it{\isacharcomma}\ entry{\isacharparenright}\ t{\isadigit{1}}{\isacharparenright}\ key\ t{\isadigit{2}}{\isacharparenright}\isanewline
   133 \ \ \ \ \ \ else\ {\isacharparenleft}Branch\ t{\isadigit{1}}\ key\ {\isacharparenleft}update\ {\isacharparenleft}it{\isacharcomma}\ entry{\isacharparenright}\ t{\isadigit{2}}{\isacharparenright}{\isacharparenright}\isanewline
   158 \ \ \ \ \ \ else\ {\isacharparenleft}Branch\ t{\isadigit{1}}\ key\ {\isacharparenleft}update\ {\isacharparenleft}it{\isacharcomma}\ entry{\isacharparenright}\ t{\isadigit{2}}{\isacharparenright}{\isacharparenright}\isanewline
   134 \ \ \ {\isacharparenright}{\isachardoublequoteclose}\isanewline
   159 \ \ \ {\isacharparenright}{\isachardoublequoteclose}%
   135 \isanewline
   160 \begin{isamarkuptext}%
       
   161 \noindent For testing purpose, we define a small example
       
   162   using natural numbers \isa{nat} (which are a \isa{linorder})
       
   163   as keys and strings values:%
       
   164 \end{isamarkuptext}%
       
   165 \isamarkuptrue%
   136 \isacommand{fun}\isamarkupfalse%
   166 \isacommand{fun}\isamarkupfalse%
   137 \isanewline
   167 \isanewline
   138 \ \ example\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}nat\ {\isasymRightarrow}\ {\isacharparenleft}nat{\isacharcomma}\ string{\isacharparenright}\ searchtree{\isachardoublequoteclose}\ \isakeyword{where}\isanewline
   168 \ \ example\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}nat\ {\isasymRightarrow}\ {\isacharparenleft}nat{\isacharcomma}\ string{\isacharparenright}\ searchtree{\isachardoublequoteclose}\ \isakeyword{where}\isanewline
   139 \ \ {\isachardoublequoteopen}example\ n\ {\isacharequal}\ update\ {\isacharparenleft}n{\isacharcomma}\ {\isacharprime}{\isacharprime}bar{\isacharprime}{\isacharprime}{\isacharparenright}\ {\isacharparenleft}Leaf\ {\isadigit{0}}\ {\isacharprime}{\isacharprime}foo{\isacharprime}{\isacharprime}{\isacharparenright}{\isachardoublequoteclose}\isanewline
   169 \ \ {\isachardoublequoteopen}example\ n\ {\isacharequal}\ update\ {\isacharparenleft}n{\isacharcomma}\ {\isacharprime}{\isacharprime}bar{\isacharprime}{\isacharprime}{\isacharparenright}\ {\isacharparenleft}Leaf\ {\isadigit{0}}\ {\isacharprime}{\isacharprime}foo{\isacharprime}{\isacharprime}{\isacharparenright}{\isachardoublequoteclose}%
   140 \isanewline
   170 \begin{isamarkuptext}%
       
   171 \noindent Then we generate code%
       
   172 \end{isamarkuptext}%
       
   173 \isamarkuptrue%
   141 \isacommand{code{\isacharunderscore}gen}\isamarkupfalse%
   174 \isacommand{code{\isacharunderscore}gen}\isamarkupfalse%
   142 \ example\ {\isacharparenleft}SML\ {\isachardoublequoteopen}examples{\isacharslash}tree{\isachardot}ML{\isachardoublequoteclose}{\isacharparenright}%
   175 \ example\ {\isacharparenleft}SML\ {\isachardoublequoteopen}examples{\isacharslash}tree{\isachardot}ML{\isachardoublequoteclose}{\isacharparenright}%
   143 \begin{isamarkuptext}%
   176 \begin{isamarkuptext}%
   144 \lstsml{Thy/examples/tree.ML}%
   177 \noindent which looks like:
   145 \end{isamarkuptext}%
   178   \lstsml{Thy/examples/tree.ML}%
   146 \isamarkuptrue%
   179 \end{isamarkuptext}%
   147 %
   180 \isamarkuptrue%
   148 \isamarkupsubsection{Code generation process%
   181 %
       
   182 \isamarkupsection{Code generation concepts and process \label{sec:concept}%
   149 }
   183 }
   150 \isamarkuptrue%
   184 \isamarkuptrue%
   151 %
   185 %
   152 \begin{isamarkuptext}%
   186 \begin{isamarkuptext}%
   153 \begin{figure}[h]
   187 \begin{figure}[h]
   215 \isanewline
   249 \isanewline
   216 \ \ fac\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}nat\ {\isasymRightarrow}\ nat{\isachardoublequoteclose}\ \isakeyword{where}\isanewline
   250 \ \ fac\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}nat\ {\isasymRightarrow}\ nat{\isachardoublequoteclose}\ \isakeyword{where}\isanewline
   217 \ \ \ \ {\isachardoublequoteopen}fac\ {\isadigit{0}}\ {\isacharequal}\ {\isadigit{1}}{\isachardoublequoteclose}\isanewline
   251 \ \ \ \ {\isachardoublequoteopen}fac\ {\isadigit{0}}\ {\isacharequal}\ {\isadigit{1}}{\isachardoublequoteclose}\isanewline
   218 \ \ {\isacharbar}\ {\isachardoublequoteopen}fac\ {\isacharparenleft}Suc\ n{\isacharparenright}\ {\isacharequal}\ Suc\ n\ {\isacharasterisk}\ fac\ n{\isachardoublequoteclose}%
   252 \ \ {\isacharbar}\ {\isachardoublequoteopen}fac\ {\isacharparenleft}Suc\ n{\isacharparenright}\ {\isacharequal}\ Suc\ n\ {\isacharasterisk}\ fac\ n{\isachardoublequoteclose}%
   219 \begin{isamarkuptext}%
   253 \begin{isamarkuptext}%
   220 This executable specification is now turned to SML code:%
   254 \noindent This executable specification is now turned to SML code:%
   221 \end{isamarkuptext}%
   255 \end{isamarkuptext}%
   222 \isamarkuptrue%
   256 \isamarkuptrue%
   223 \isacommand{code{\isacharunderscore}gen}\isamarkupfalse%
   257 \isacommand{code{\isacharunderscore}gen}\isamarkupfalse%
   224 \ fac\ {\isacharparenleft}SML\ {\isachardoublequoteopen}examples{\isacharslash}fac{\isachardot}ML{\isachardoublequoteclose}{\isacharparenright}%
   258 \ fac\ {\isacharparenleft}SML\ {\isachardoublequoteopen}examples{\isacharslash}fac{\isachardot}ML{\isachardoublequoteclose}{\isacharparenright}%
   225 \begin{isamarkuptext}%
   259 \begin{isamarkuptext}%
   226 The \isa{{\isasymCODEGEN}} command takes a space-separated list of
   260 \noindent  The \isa{{\isasymCODEGEN}} command takes a space-separated list of
   227   constants together with \qn{serialization directives}
   261   constants together with \qn{serialization directives}
   228   in parentheses. These start with a \qn{target language}
   262   in parentheses. These start with a \qn{target language}
   229   identifier, followed by arguments, their semantics
   263   identifier, followed by arguments, their semantics
   230   depending on the target. In the SML case, a filename
   264   depending on the target. In the SML case, a filename
   231   is given where to write the generated code to.
   265   is given where to write the generated code to.
   236   code:
   270   code:
   237 
   271 
   238   \lstsml{Thy/examples/fac.ML}
   272   \lstsml{Thy/examples/fac.ML}
   239 
   273 
   240   The code generator will complain when a required
   274   The code generator will complain when a required
   241   ingredient does not provide a executable counterpart.
   275   ingredient does not provide a executable counterpart,
   242   This is the case if an involved type is not a datatype:%
   276   e.g.~generating code
       
   277   for constants not yielding
       
   278   a defining equation (e.g.~the Hilbert choice
       
   279   operation \isa{SOME}):%
   243 \end{isamarkuptext}%
   280 \end{isamarkuptext}%
   244 \isamarkuptrue%
   281 \isamarkuptrue%
   245 %
   282 %
   246 \isadelimML
   283 \isadelimML
   247 %
   284 %
   254 %
   291 %
   255 \isadelimML
   292 \isadelimML
   256 \isanewline
   293 \isanewline
   257 %
   294 %
   258 \endisadelimML
   295 \endisadelimML
   259 \isacommand{typedecl}\isamarkupfalse%
       
   260 \ {\isacharprime}a\ foo\isanewline
       
   261 \isanewline
       
   262 \isacommand{definition}\isamarkupfalse%
   296 \isacommand{definition}\isamarkupfalse%
   263 \isanewline
   297 \isanewline
   264 \ \ bar\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isacharprime}a\ foo\ {\isasymRightarrow}\ {\isacharprime}a\ {\isasymRightarrow}\ {\isacharprime}a{\isachardoublequoteclose}\ \isakeyword{where}\isanewline
   298 \ \ pick{\isacharunderscore}some\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isacharprime}a\ list\ {\isasymRightarrow}\ {\isacharprime}a{\isachardoublequoteclose}\ \isakeyword{where}\isanewline
   265 \ \ {\isachardoublequoteopen}bar\ x\ y\ {\isacharequal}\ y{\isachardoublequoteclose}\isanewline
   299 \ \ {\isachardoublequoteopen}pick{\isacharunderscore}some\ xs\ {\isacharequal}\ {\isacharparenleft}SOME\ x{\isachardot}\ x\ {\isasymin}\ set\ xs{\isacharparenright}{\isachardoublequoteclose}\isanewline
   266 %
   300 %
   267 \isadelimML
   301 \isadelimML
   268 %
   302 %
   269 \endisadelimML
   303 \endisadelimML
   270 %
   304 %
   276 \isadelimML
   310 \isadelimML
   277 %
   311 %
   278 \endisadelimML
   312 \endisadelimML
   279 \isanewline
   313 \isanewline
   280 \isacommand{code{\isacharunderscore}gen}\isamarkupfalse%
   314 \isacommand{code{\isacharunderscore}gen}\isamarkupfalse%
   281 \ bar\ {\isacharparenleft}SML\ {\isachardoublequoteopen}examples{\isacharslash}fail{\isacharunderscore}type{\isachardot}ML{\isachardoublequoteclose}{\isacharparenright}%
       
   282 \begin{isamarkuptext}%
       
   283 \noindent will result in an error. Likewise, generating code
       
   284   for constants not yielding
       
   285   a defining equation will fail, e.g.~the Hilbert choice
       
   286   operation \isa{SOME}:%
       
   287 \end{isamarkuptext}%
       
   288 \isamarkuptrue%
       
   289 %
       
   290 \isadelimML
       
   291 %
       
   292 \endisadelimML
       
   293 %
       
   294 \isatagML
       
   295 %
       
   296 \endisatagML
       
   297 {\isafoldML}%
       
   298 %
       
   299 \isadelimML
       
   300 \isanewline
       
   301 %
       
   302 \endisadelimML
       
   303 \isacommand{definition}\isamarkupfalse%
       
   304 \isanewline
       
   305 \ \ pick{\isacharunderscore}some\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isacharprime}a\ list\ {\isasymRightarrow}\ {\isacharprime}a{\isachardoublequoteclose}\ \isakeyword{where}\isanewline
       
   306 \ \ {\isachardoublequoteopen}pick{\isacharunderscore}some\ xs\ {\isacharequal}\ {\isacharparenleft}SOME\ x{\isachardot}\ x\ {\isasymin}\ set\ xs{\isacharparenright}{\isachardoublequoteclose}\isanewline
       
   307 %
       
   308 \isadelimML
       
   309 %
       
   310 \endisadelimML
       
   311 %
       
   312 \isatagML
       
   313 %
       
   314 \endisatagML
       
   315 {\isafoldML}%
       
   316 %
       
   317 \isadelimML
       
   318 %
       
   319 \endisadelimML
       
   320 \isanewline
       
   321 \isacommand{code{\isacharunderscore}gen}\isamarkupfalse%
       
   322 \ pick{\isacharunderscore}some\ {\isacharparenleft}SML\ {\isachardoublequoteopen}examples{\isacharslash}fail{\isacharunderscore}const{\isachardot}ML{\isachardoublequoteclose}{\isacharparenright}%
   315 \ pick{\isacharunderscore}some\ {\isacharparenleft}SML\ {\isachardoublequoteopen}examples{\isacharslash}fail{\isacharunderscore}const{\isachardot}ML{\isachardoublequoteclose}{\isacharparenright}%
       
   316 \begin{isamarkuptext}%
       
   317 \noindent will fail.%
       
   318 \end{isamarkuptext}%
       
   319 \isamarkuptrue%
       
   320 %
   323 \isamarkupsubsection{Theorem selection%
   321 \isamarkupsubsection{Theorem selection%
   324 }
   322 }
   325 \isamarkuptrue%
   323 \isamarkuptrue%
   326 %
   324 %
   327 \begin{isamarkuptext}%
   325 \begin{isamarkuptext}%
   333 %
   331 %
   334 \begin{isamarkuptext}%
   332 \begin{isamarkuptext}%
   335 \noindent which displays a table of constant with corresponding
   333 \noindent which displays a table of constant with corresponding
   336   defining equations (the additional stuff displayed
   334   defining equations (the additional stuff displayed
   337   shall not bother us for the moment). If this table does
   335   shall not bother us for the moment). If this table does
   338   not provide at least one function
   336   not provide at least one defining
   339   equation, the table of primitive definitions is searched
   337   equation for a particular constant, the table of primitive
       
   338   definitions is searched
   340   whether it provides one.
   339   whether it provides one.
   341 
   340 
   342   The typical HOL tools are already set up in a way that
   341   The typical HOL tools are already set up in a way that
   343   function definitions introduced by \isa{{\isasymFUN}},
   342   function definitions introduced by \isa{{\isasymFUN}},
   344   \isa{{\isasymFUNCTION}}, \isa{{\isasymPRIMREC}}
   343   \isa{{\isasymFUNCTION}}, \isa{{\isasymPRIMREC}}
   576 %
   575 %
   577 \begin{isamarkuptext}%
   576 \begin{isamarkuptext}%
   578 \noindent print all cached defining equations (i.e.~\emph{after}
   577 \noindent print all cached defining equations (i.e.~\emph{after}
   579   any applied transformation).  A
   578   any applied transformation).  A
   580   list of constants may be given; their function
   579   list of constants may be given; their function
   581   equations are added to the cache if not already present.%
   580   equations are added to the cache if not already present.
       
   581 
       
   582   Similarly, the \isa{{\isasymCODEDEPS}} command shows a graph
       
   583   visualizing dependencies between defining equations.%
   582 \end{isamarkuptext}%
   584 \end{isamarkuptext}%
   583 \isamarkuptrue%
   585 \isamarkuptrue%
   584 %
   586 %
   585 \isamarkupsection{Recipes and advanced topics \label{sec:advanced}%
   587 \isamarkupsection{Recipes and advanced topics \label{sec:advanced}%
   586 }
   588 }
  1489 would mean nothing else than to introduce the evil
  1491 would mean nothing else than to introduce the evil
  1490   sort constraint by hand.%
  1492   sort constraint by hand.%
  1491 \end{isamarkuptext}%
  1493 \end{isamarkuptext}%
  1492 \isamarkuptrue%
  1494 \isamarkuptrue%
  1493 %
  1495 %
       
  1496 \isamarkupsubsection{Constructor sets for datatypes%
       
  1497 }
       
  1498 \isamarkuptrue%
       
  1499 %
       
  1500 \begin{isamarkuptext}%
       
  1501 \fixme%
       
  1502 \end{isamarkuptext}%
       
  1503 \isamarkuptrue%
       
  1504 %
  1494 \isamarkupsubsection{Cyclic module dependencies%
  1505 \isamarkupsubsection{Cyclic module dependencies%
  1495 }
  1506 }
  1496 \isamarkuptrue%
  1507 \isamarkuptrue%
  1497 %
  1508 %
  1498 \begin{isamarkuptext}%
  1509 \begin{isamarkuptext}%
  1634 %
  1645 %
  1635 \isatagmlref
  1646 \isatagmlref
  1636 %
  1647 %
  1637 \begin{isamarkuptext}%
  1648 \begin{isamarkuptext}%
  1638 \begin{mldecls}
  1649 \begin{mldecls}
  1639   \indexmltype{CodegenConsts.const}\verb|type CodegenConsts.const = string * typ list| \\
  1650   \indexmltype{CodegenConsts.const}\verb|type CodegenConsts.const = string * string option| \\
  1640   \indexml{CodegenConsts.norm-of-typ}\verb|CodegenConsts.norm_of_typ: theory -> string * typ -> CodegenConsts.const| \\
  1651   \indexml{CodegenConsts.const-of-cexpr}\verb|CodegenConsts.const_of_cexpr: theory -> string * typ -> CodegenConsts.const| \\
  1641   \indexml{CodegenConsts.typ-of-inst}\verb|CodegenConsts.typ_of_inst: theory -> CodegenConsts.const -> string * typ| \\
       
  1642  \end{mldecls}
  1652  \end{mldecls}
  1643 
  1653 
  1644   \begin{description}
  1654   \begin{description}
  1645 
  1655 
  1646   \item \verb|CodegenConsts.const| is the identifier type:
  1656   \item \verb|CodegenConsts.const| is the identifier type:
  1647      the product of a \emph{string} with a list of \emph{typs}.
  1657      the product of a \emph{string} with a list of \emph{typs}.
  1648      The \emph{string} is the constant name as represented inside Isabelle;
  1658      The \emph{string} is the constant name as represented inside Isabelle;
  1649      the \emph{typs} are a type instantiation in the sense of System F,
  1659      for overloaded constants, the attached \emph{string option}
  1650      with canonical names for type variables.
  1660      is either \isa{SOME} type constructor denoting an instance,
  1651 
  1661      or \isa{NONE} for the polymorphic constant.
  1652   \item \verb|CodegenConsts.norm_of_typ|~\isa{thy}~\isa{{\isacharparenleft}constname{\isacharcomma}\ typ{\isacharparenright}}
  1662 
  1653      maps a constant expression \isa{{\isacharparenleft}constname{\isacharcomma}\ typ{\isacharparenright}} to its canonical identifier.
  1663   \item \verb|CodegenConsts.const_of_cexpr|~\isa{thy}~\isa{{\isacharparenleft}constname{\isacharcomma}\ typ{\isacharparenright}}
  1654 
  1664      maps a constant expression \isa{{\isacharparenleft}constname{\isacharcomma}\ typ{\isacharparenright}}
  1655   \item \verb|CodegenConsts.typ_of_inst|~\isa{thy}~\isa{const}
  1665      to its canonical identifier.
  1656      maps a canonical identifier \isa{const} to a constant
       
  1657      expression with appropriate type.
       
  1658 
  1666 
  1659   \end{description}%
  1667   \end{description}%
  1660 \end{isamarkuptext}%
  1668 \end{isamarkuptext}%
  1661 \isamarkuptrue%
  1669 \isamarkuptrue%
  1662 %
  1670 %
  1718 %
  1726 %
  1719 \isatagmlref
  1727 \isatagmlref
  1720 %
  1728 %
  1721 \begin{isamarkuptext}%
  1729 \begin{isamarkuptext}%
  1722 \begin{mldecls}
  1730 \begin{mldecls}
  1723   \indexml{CodegenData.add-func}\verb|CodegenData.add_func: thm -> theory -> theory| \\
  1731   \indexml{CodegenData.add-func}\verb|CodegenData.add_func: bool -> thm -> theory -> theory| \\
  1724   \indexml{CodegenData.del-func}\verb|CodegenData.del_func: thm -> theory -> theory| \\
  1732   \indexml{CodegenData.del-func}\verb|CodegenData.del_func: thm -> theory -> theory| \\
  1725   \indexml{CodegenData.add-funcl}\verb|CodegenData.add_funcl: CodegenConsts.const * thm list Susp.T -> theory -> theory| \\
  1733   \indexml{CodegenData.add-funcl}\verb|CodegenData.add_funcl: CodegenConsts.const * thm list Susp.T -> theory -> theory| \\
  1726   \indexml{CodegenData.add-inline}\verb|CodegenData.add_inline: thm -> theory -> theory| \\
  1734   \indexml{CodegenData.add-inline}\verb|CodegenData.add_inline: thm -> theory -> theory| \\
  1727   \indexml{CodegenData.del-inline}\verb|CodegenData.del_inline: thm -> theory -> theory| \\
  1735   \indexml{CodegenData.del-inline}\verb|CodegenData.del_inline: thm -> theory -> theory| \\
  1728   \indexml{CodegenData.add-inline-proc}\verb|CodegenData.add_inline_proc: string * (theory -> cterm list -> thm list)|\isasep\isanewline%
  1736   \indexml{CodegenData.add-inline-proc}\verb|CodegenData.add_inline_proc: string * (theory -> cterm list -> thm list)|\isasep\isanewline%
  1810 %
  1818 %
  1811 \begin{isamarkuptext}%
  1819 \begin{isamarkuptext}%
  1812 \begin{mldecls}
  1820 \begin{mldecls}
  1813   \indexml{CodegenConsts.const-ord}\verb|CodegenConsts.const_ord: CodegenConsts.const * CodegenConsts.const -> order| \\
  1821   \indexml{CodegenConsts.const-ord}\verb|CodegenConsts.const_ord: CodegenConsts.const * CodegenConsts.const -> order| \\
  1814   \indexml{CodegenConsts.eq-const}\verb|CodegenConsts.eq_const: CodegenConsts.const * CodegenConsts.const -> bool| \\
  1822   \indexml{CodegenConsts.eq-const}\verb|CodegenConsts.eq_const: CodegenConsts.const * CodegenConsts.const -> bool| \\
  1815   \indexml{CodegenConsts.consts-of}\verb|CodegenConsts.consts_of: theory -> term -> CodegenConsts.const list| \\
       
  1816   \indexml{CodegenConsts.read-const}\verb|CodegenConsts.read_const: theory -> string -> CodegenConsts.const| \\
  1823   \indexml{CodegenConsts.read-const}\verb|CodegenConsts.read_const: theory -> string -> CodegenConsts.const| \\
  1817   \indexmlstructure{CodegenConsts.Consttab}\verb|structure CodegenConsts.Consttab| \\
  1824   \indexmlstructure{CodegenConsts.Consttab}\verb|structure CodegenConsts.Consttab| \\
  1818   \indexml{CodegenFunc.typ-func}\verb|CodegenFunc.typ_func: thm -> typ| \\
  1825   \indexml{CodegenFunc.typ-func}\verb|CodegenFunc.typ_func: thm -> typ| \\
  1819   \indexml{CodegenFunc.rewrite-func}\verb|CodegenFunc.rewrite_func: thm list -> thm -> thm| \\
  1826   \indexml{CodegenFunc.rewrite-func}\verb|CodegenFunc.rewrite_func: thm list -> thm -> thm| \\
  1820   \end{mldecls}
  1827   \end{mldecls}
  1824   \item \verb|CodegenConsts.const_ord|,~\verb|CodegenConsts.eq_const|
  1831   \item \verb|CodegenConsts.const_ord|,~\verb|CodegenConsts.eq_const|
  1825      provide order and equality on constant identifiers.
  1832      provide order and equality on constant identifiers.
  1826 
  1833 
  1827   \item \verb|CodegenConsts.Consttab|
  1834   \item \verb|CodegenConsts.Consttab|
  1828      provides table structures with constant identifiers as keys.
  1835      provides table structures with constant identifiers as keys.
  1829 
       
  1830   \item \verb|CodegenConsts.consts_of|~\isa{thy}~\isa{t}
       
  1831      returns all constant identifiers mentioned in a term \isa{t}.
       
  1832 
  1836 
  1833   \item \verb|CodegenConsts.read_const|~\isa{thy}~\isa{s}
  1837   \item \verb|CodegenConsts.read_const|~\isa{thy}~\isa{s}
  1834      reads a constant as a concrete term expression \isa{s}.
  1838      reads a constant as a concrete term expression \isa{s}.
  1835 
  1839 
  1836   \item \verb|CodegenFunc.typ_func|~\isa{thm}
  1840   \item \verb|CodegenFunc.typ_func|~\isa{thm}