151 Before selected function theorems are turned into abstract |
151 Before selected function theorems are turned into abstract |
152 code, a chain of definitional transformation steps is carried |
152 code, a chain of definitional transformation steps is carried |
153 out: \emph{preprocessing}. In essence, the preprocessor |
153 out: \emph{preprocessing}. In essence, the preprocessor |
154 consists of two components: a \emph{simpset} and \emph{function transformers}. |
154 consists of two components: a \emph{simpset} and \emph{function transformers}. |
155 |
155 |
156 The \emph{simpset} allows to employ the full generality of the Isabelle |
156 The \emph{simpset} allows to employ the full generality of the |
157 simplifier. Due to the interpretation of theorems |
157 Isabelle simplifier. Due to the interpretation of theorems as code |
158 as code equations, rewrites are applied to the right |
158 equations, rewrites are applied to the right hand side and the |
159 hand side and the arguments of the left hand side of an |
159 arguments of the left hand side of an equation, but never to the |
160 equation, but never to the constant heading the left hand side. |
160 constant heading the left hand side. An important special case are |
161 An important special case are \emph{inline theorems} which may be |
161 \emph{unfold theorems} which may be declared and undeclared using |
162 declared and undeclared using the |
162 the @{attribute code_unfold} or \emph{@{attribute code_unfold} del} |
163 \emph{code inline} or \emph{code inline del} attribute respectively. |
163 attribute respectively. |
164 |
164 |
165 Some common applications: |
165 Some common applications: |
166 *} |
166 *} |
167 |
167 |
168 text_raw {* |
168 text_raw {* |
171 |
171 |
172 text {* |
172 text {* |
173 \item replacing non-executable constructs by executable ones: |
173 \item replacing non-executable constructs by executable ones: |
174 *} |
174 *} |
175 |
175 |
176 lemma %quote [code inline]: |
176 lemma %quote [code_inline]: |
177 "x \<in> set xs \<longleftrightarrow> x mem xs" by (induct xs) simp_all |
177 "x \<in> set xs \<longleftrightarrow> x mem xs" by (induct xs) simp_all |
178 |
178 |
179 text {* |
179 text {* |
180 \item eliminating superfluous constants: |
180 \item eliminating superfluous constants: |
181 *} |
181 *} |
182 |
182 |
183 lemma %quote [code inline]: |
183 lemma %quote [code_inline]: |
184 "1 = Suc 0" by simp |
184 "1 = Suc 0" by simp |
185 |
185 |
186 text {* |
186 text {* |
187 \item replacing executable but inconvenient constructs: |
187 \item replacing executable but inconvenient constructs: |
188 *} |
188 *} |
189 |
189 |
190 lemma %quote [code inline]: |
190 lemma %quote [code_inline]: |
191 "xs = [] \<longleftrightarrow> List.null xs" by (induct xs) simp_all |
191 "xs = [] \<longleftrightarrow> List.null xs" by (induct xs) simp_all |
192 |
192 |
193 text_raw {* |
193 text_raw {* |
194 \end{itemize} |
194 \end{itemize} |
195 *} |
195 *} |
208 @{command code_thms} provides a convenient |
208 @{command code_thms} provides a convenient |
209 mechanism to inspect the impact of a preprocessor setup |
209 mechanism to inspect the impact of a preprocessor setup |
210 on code equations. |
210 on code equations. |
211 |
211 |
212 \begin{warn} |
212 \begin{warn} |
213 The attribute \emph{code unfold} |
213 |
214 associated with the @{text "SML code generator"} also applies to |
214 Attribute @{attribute code_unfold} also applies to the |
215 the @{text "generic code generator"}: |
215 preprocessor of the ancient @{text "SML code generator"}; in case |
216 \emph{code unfold} implies \emph{code inline}. |
216 this is not what you intend, use @{attribute code_inline} instead. |
217 \end{warn} |
217 \end{warn} |
218 *} |
218 *} |
219 |
219 |
220 subsection {* Datatypes \label{sec:datatypes} *} |
220 subsection {* Datatypes \label{sec:datatypes} *} |
221 |
221 |