doc-src/IsarRef/logics.tex
changeset 20587 f43a46316fa5
parent 19988 05f940b9ef15
child 21077 d6c141871b29
equal deleted inserted replaced
20586:548fd4cd2eb3 20587:f43a46316fa5
   689 \end{descr}
   689 \end{descr}
   690 
   690 
   691 
   691 
   692 \subsection{Executable code}
   692 \subsection{Executable code}
   693 
   693 
   694 Isabelle/Pure provides a generic infrastructure to support code
   694 Isabelle/Pure provides two generic frameworks to support code
   695 generation from executable specifications, both functional and
   695 generation from executable specifications. Isabelle/HOL
   696 relational programs.  Isabelle/HOL instantiates these mechanisms in a
   696 instantiates these mechanisms in a
   697 way that is amenable to end-user applications.  See
   697 way that is amenable to end-user applications
       
   698 
       
   699 One framework generates code from both functional and
       
   700 relational programs to SML.  See
   698 \cite{isabelle-HOL} for further information (this actually covers the
   701 \cite{isabelle-HOL} for further information (this actually covers the
   699 new-style theory format as well).
   702 new-style theory format as well).
   700 
   703 
   701 \indexisarcmd{value}\indexisarcmd{code-module}\indexisarcmd{code-library}
   704 \indexisarcmd{value}\indexisarcmd{code-module}\indexisarcmd{code-library}
   702 \indexisarcmd{consts-code}\indexisarcmd{types-code}
   705 \indexisarcmd{consts-code}\indexisarcmd{types-code}
   743 \begin{descr}
   746 \begin{descr}
   744 \item [$\isarkeyword{value}~t$] reads, evaluates and prints a term
   747 \item [$\isarkeyword{value}~t$] reads, evaluates and prints a term
   745   using the code generator.
   748   using the code generator.
   746 \end{descr}
   749 \end{descr}
   747 
   750 
       
   751 The other framework generates code from functional programs
       
   752 (including overloading using type classes) to SML and Haskell.
       
   753 Conceptually, code generation is split up in three steps: \emph{selection}
       
   754 of code theorems, \emph{extraction} into an abstract executable view
       
   755 and \emph{serialization} to a specific \emph{target language}.
       
   756 
       
   757 \indexisarcmd{code-gen}
       
   758 \indexisarcmd{code-const}\indexisarcmd{code-type}
       
   759 \indexisarcmd{code-class}\indexisarcmd{code-instance}
       
   760 \indexisarcmd{print-codethms}
       
   761 \indexisaratt{code func}
       
   762 \indexisaratt{code nofunc}
       
   763 \indexisaratt{code inline}
       
   764 \indexisaratt{code noinline}
       
   765 
       
   766 \begin{matharray}{rcl}
       
   767   \isarcmd{code_gen}^* & : & \isarkeep{theory~|~proof} \\
       
   768   \isarcmd{code_const} & : & \isartrans{theory}{theory} \\
       
   769   \isarcmd{code_type} & : & \isartrans{theory}{theory} \\
       
   770   \isarcmd{code_class} & : & \isartrans{theory}{theory} \\
       
   771   \isarcmd{code_instance} & : & \isartrans{theory}{theory} \\
       
   772   \isarcmd{print_codethms}^* & : & \isarkeep{theory~|~proof} \\
       
   773   code\ func & : & \isaratt \\
       
   774   code\ nofunc & : & \isaratt \\
       
   775   code\ inline & : & \isaratt \\
       
   776   code\ noinline & : & \isaratt \\
       
   777 \end{matharray}
       
   778 
       
   779 \begin{rail}
       
   780 'code\_gen' ( ( const + ) ( seri + ) | ( const + ) | ( seri + ) );
       
   781 
       
   782 const : term;
       
   783 
       
   784 typeconstructor : nameref;
       
   785 
       
   786 class : nameref;
       
   787 
       
   788 seri : target | 'SML' ( string | '-' | ()) | 'Haskell' (string | ());
       
   789 
       
   790 target : 'SML' | 'Haskell';
       
   791 
       
   792 'code\_const' (const + 'and') \\
       
   793   ( ( '(' target ( syntax + 'and' ) ')' ) + );
       
   794 
       
   795 'code\_type' (typeconstructor + 'and') \\
       
   796   ( ( '(' target ( syntax + 'and' ) ')' ) + );
       
   797 
       
   798 'code\_class' (class + 'and') \\
       
   799   ( ( '(' target \\
       
   800     ( ( string ('where' ( const ( '==' | equiv ) string ) + ) ? ) + 'and' ) ')' ) + );
       
   801 
       
   802 'code\_instance' (( typeconstructor '::' class ) + 'and') \\
       
   803   ( ( '(' target ( '-' + 'and' ) ')' ) + );
       
   804 
       
   805 syntax : ( 'target\_atom' ? string ) | ( 'infix' | 'infixl' | 'infixr' ) nat string;
       
   806 
       
   807 'print\_codethms' ( '(' ( const + ) ? ')' ) ?;
       
   808 
       
   809 ('code\ func' | 'code\ nofunc' | 'code\ inline' | 'code\ noinline');
       
   810 \end{rail}
       
   811 
       
   812 \begin{descr}
       
   813 
       
   814 \item [$\isarcmd{code_gen}$] is the canonical interface for generating and
       
   815   serializing code: for a given list of constants, code is generated for the specified
       
   816   target language(s).  Abstract code is cached incrementally.  If no constant is given,
       
   817   the whole current cache is serialized.  If no serialization instruction
       
   818   is given, only abstract code is cached.
       
   819 
       
   820   The \emph{SML} serializer takes either a filename or an ``-'' as argument.
       
   821   In the first case, code is written to the specified file, in the latter
       
   822   it is compiled internally in the context of the current ML session.
       
   823 
       
   824   For \emph{Haskell}, also a filename is specified; different modules
       
   825   are serialized to different files in the directory of the specified file, or
       
   826   subdirectories.
       
   827 
       
   828 \item [$\isarcmd{code_const}$] associates a list of constants
       
   829   with target-specific serializations.
       
   830 
       
   831 \item [$\isarcmd{code_type}$] associates a list of type constructors
       
   832   with target-specific serializations.
       
   833 
       
   834 \item [$\isarcmd{code_class}$] associates a list of classes
       
   835   with target-specific class names; in addition, constants associated
       
   836   with this class may be given target-specific names used for instance
       
   837   declarations.  Applies only to \emph{Haskell}.
       
   838 
       
   839 \item [$\isarcmd{code_instance}$] declares a list of type constructor / class
       
   840   instance relations as ``already present'' for a given target.
       
   841   Applies only to \emph{Haskell}.
       
   842 
       
   843 \item [$code\ func$ and $code\ nofunc$] select or deselect explicitly
       
   844   a function theorem for code generation.  Usually packages introducing
       
   845   function theorems provide a resonable default setup for selection.
       
   846   If no theorem has been selected for a constant, its definition
       
   847   is used as function theorem if possible.
       
   848 
       
   849 \item [$code\ inline$ and $code\ noinline$] select or deselect
       
   850   inlining theorems which are applied as rewrite rules to any function theorem.
       
   851 
       
   852 \item [$\isarcmd{print_thms}$] gives an overview on selected
       
   853   function theorems, code generator datatypes and inlining theorems.
       
   854   When constants are given, it displays the function theorems
       
   855   for those constants \emph{after} any preprocessing step has been carried out.
       
   856 
       
   857 \end{descr}
   748 
   858 
   749 \section{HOLCF}
   859 \section{HOLCF}
   750 
   860 
   751 \subsection{Mixfix syntax for continuous operations}
   861 \subsection{Mixfix syntax for continuous operations}
   752 
   862