author | haftmann |
Mon, 27 Sep 2010 16:27:31 +0200 | |
changeset 39745 | 3aa2bc9c5478 |
parent 39683 | f75a01ee6c41 |
child 40352 | 8fd36f8a5cb7 |
permissions | -rw-r--r-- |
28447 | 1 |
% |
2 |
\begin{isabellebody}% |
|
3 |
\def\isabellecontext{Further}% |
|
4 |
% |
|
5 |
\isadelimtheory |
|
6 |
% |
|
7 |
\endisadelimtheory |
|
8 |
% |
|
9 |
\isatagtheory |
|
10 |
\isacommand{theory}\isamarkupfalse% |
|
11 |
\ Further\isanewline |
|
12 |
\isakeyword{imports}\ Setup\isanewline |
|
13 |
\isakeyword{begin}% |
|
14 |
\endisatagtheory |
|
15 |
{\isafoldtheory}% |
|
16 |
% |
|
17 |
\isadelimtheory |
|
18 |
% |
|
19 |
\endisadelimtheory |
|
20 |
% |
|
21 |
\isamarkupsection{Further issues \label{sec:further}% |
|
22 |
} |
|
23 |
\isamarkuptrue% |
|
24 |
% |
|
38437 | 25 |
\isamarkupsubsection{Modules namespace% |
28447 | 26 |
} |
27 |
\isamarkuptrue% |
|
28 |
% |
|
29 |
\begin{isamarkuptext}% |
|
38437 | 30 |
When invoking the \hyperlink{command.export-code}{\mbox{\isa{\isacommand{export{\isacharunderscore}code}}}} command it is possible to leave |
31 |
out the \hyperlink{keyword.module-name}{\mbox{\isa{\isakeyword{module{\isacharunderscore}name}}}} part; then code is distributed over |
|
32 |
different modules, where the module name space roughly is induced |
|
33 |
by the Isabelle theory name space. |
|
34 |
||
35 |
Then sometimes the awkward situation occurs that dependencies between |
|
36 |
definitions introduce cyclic dependencies between modules, which in the |
|
37 |
\isa{Haskell} world leaves you to the mercy of the \isa{Haskell} implementation |
|
38 |
you are using, while for \isa{SML}/\isa{OCaml} code generation is not possible. |
|
39 |
||
40 |
A solution is to declare module names explicitly. |
|
41 |
Let use assume the three cyclically dependent |
|
42 |
modules are named \emph{A}, \emph{B} and \emph{C}. |
|
43 |
Then, by stating% |
|
44 |
\end{isamarkuptext}% |
|
45 |
\isamarkuptrue% |
|
46 |
% |
|
47 |
\isadelimquote |
|
48 |
% |
|
49 |
\endisadelimquote |
|
50 |
% |
|
51 |
\isatagquote |
|
52 |
\isacommand{code{\isacharunderscore}modulename}\isamarkupfalse% |
|
53 |
\ SML\isanewline |
|
54 |
\ \ A\ ABC\isanewline |
|
55 |
\ \ B\ ABC\isanewline |
|
56 |
\ \ C\ ABC% |
|
57 |
\endisatagquote |
|
58 |
{\isafoldquote}% |
|
59 |
% |
|
60 |
\isadelimquote |
|
61 |
% |
|
62 |
\endisadelimquote |
|
63 |
% |
|
64 |
\begin{isamarkuptext}% |
|
65 |
\noindent |
|
66 |
we explicitly map all those modules on \emph{ABC}, |
|
67 |
resulting in an ad-hoc merge of this three modules |
|
68 |
at serialisation time.% |
|
28447 | 69 |
\end{isamarkuptext}% |
70 |
\isamarkuptrue% |
|
71 |
% |
|
37426 | 72 |
\isamarkupsubsection{Locales and interpretation% |
73 |
} |
|
74 |
\isamarkuptrue% |
|
75 |
% |
|
76 |
\begin{isamarkuptext}% |
|
77 |
A technical issue comes to surface when generating code from |
|
78 |
specifications stemming from locale interpretation. |
|
79 |
||
80 |
Let us assume a locale specifying a power operation |
|
81 |
on arbitrary types:% |
|
82 |
\end{isamarkuptext}% |
|
83 |
\isamarkuptrue% |
|
84 |
% |
|
85 |
\isadelimquote |
|
86 |
% |
|
87 |
\endisadelimquote |
|
88 |
% |
|
89 |
\isatagquote |
|
90 |
\isacommand{locale}\isamarkupfalse% |
|
91 |
\ power\ {\isacharequal}\isanewline |
|
92 |
\ \ \isakeyword{fixes}\ power\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isacharprime}a\ {\isasymRightarrow}\ {\isacharprime}b\ {\isasymRightarrow}\ {\isacharprime}b{\isachardoublequoteclose}\isanewline |
|
93 |
\ \ \isakeyword{assumes}\ power{\isacharunderscore}commute{\isacharcolon}\ {\isachardoublequoteopen}power\ x\ {\isasymcirc}\ power\ y\ {\isacharequal}\ power\ y\ {\isasymcirc}\ power\ x{\isachardoublequoteclose}\isanewline |
|
94 |
\isakeyword{begin}% |
|
95 |
\endisatagquote |
|
96 |
{\isafoldquote}% |
|
97 |
% |
|
98 |
\isadelimquote |
|
99 |
% |
|
100 |
\endisadelimquote |
|
101 |
% |
|
102 |
\begin{isamarkuptext}% |
|
103 |
\noindent Inside that locale we can lift \isa{power} to exponent lists |
|
104 |
by means of specification relative to that locale:% |
|
105 |
\end{isamarkuptext}% |
|
106 |
\isamarkuptrue% |
|
107 |
% |
|
108 |
\isadelimquote |
|
109 |
% |
|
110 |
\endisadelimquote |
|
111 |
% |
|
112 |
\isatagquote |
|
113 |
\isacommand{primrec}\isamarkupfalse% |
|
114 |
\ powers\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}{\isacharprime}a\ list\ {\isasymRightarrow}\ {\isacharprime}b\ {\isasymRightarrow}\ {\isacharprime}b{\isachardoublequoteclose}\ \isakeyword{where}\isanewline |
|
115 |
\ \ {\isachardoublequoteopen}powers\ {\isacharbrackleft}{\isacharbrackright}\ {\isacharequal}\ id{\isachardoublequoteclose}\isanewline |
|
116 |
{\isacharbar}\ {\isachardoublequoteopen}powers\ {\isacharparenleft}x\ {\isacharhash}\ xs{\isacharparenright}\ {\isacharequal}\ power\ x\ {\isasymcirc}\ powers\ xs{\isachardoublequoteclose}\isanewline |
|
117 |
\isanewline |
|
118 |
\isacommand{lemma}\isamarkupfalse% |
|
119 |
\ powers{\isacharunderscore}append{\isacharcolon}\isanewline |
|
120 |
\ \ {\isachardoublequoteopen}powers\ {\isacharparenleft}xs\ {\isacharat}\ ys{\isacharparenright}\ {\isacharequal}\ powers\ xs\ {\isasymcirc}\ powers\ ys{\isachardoublequoteclose}\isanewline |
|
121 |
\ \ \isacommand{by}\isamarkupfalse% |
|
122 |
\ {\isacharparenleft}induct\ xs{\isacharparenright}\ simp{\isacharunderscore}all\isanewline |
|
123 |
\isanewline |
|
124 |
\isacommand{lemma}\isamarkupfalse% |
|
125 |
\ powers{\isacharunderscore}power{\isacharcolon}\isanewline |
|
126 |
\ \ {\isachardoublequoteopen}powers\ xs\ {\isasymcirc}\ power\ x\ {\isacharequal}\ power\ x\ {\isasymcirc}\ powers\ xs{\isachardoublequoteclose}\isanewline |
|
127 |
\ \ \isacommand{by}\isamarkupfalse% |
|
128 |
\ {\isacharparenleft}induct\ xs{\isacharparenright}\isanewline |
|
129 |
\ \ \ \ {\isacharparenleft}simp{\isacharunderscore}all\ del{\isacharcolon}\ o{\isacharunderscore}apply\ id{\isacharunderscore}apply\ add{\isacharcolon}\ o{\isacharunderscore}assoc\ {\isacharbrackleft}symmetric{\isacharbrackright}{\isacharcomma}\isanewline |
|
130 |
\ \ \ \ \ \ simp\ del{\isacharcolon}\ o{\isacharunderscore}apply\ add{\isacharcolon}\ o{\isacharunderscore}assoc\ power{\isacharunderscore}commute{\isacharparenright}\isanewline |
|
131 |
\isanewline |
|
132 |
\isacommand{lemma}\isamarkupfalse% |
|
133 |
\ powers{\isacharunderscore}rev{\isacharcolon}\isanewline |
|
134 |
\ \ {\isachardoublequoteopen}powers\ {\isacharparenleft}rev\ xs{\isacharparenright}\ {\isacharequal}\ powers\ xs{\isachardoublequoteclose}\isanewline |
|
135 |
\ \ \ \ \isacommand{by}\isamarkupfalse% |
|
136 |
\ {\isacharparenleft}induct\ xs{\isacharparenright}\ {\isacharparenleft}simp{\isacharunderscore}all\ add{\isacharcolon}\ powers{\isacharunderscore}append\ powers{\isacharunderscore}power{\isacharparenright}\isanewline |
|
137 |
\isanewline |
|
138 |
\isacommand{end}\isamarkupfalse% |
|
139 |
% |
|
140 |
\endisatagquote |
|
141 |
{\isafoldquote}% |
|
142 |
% |
|
143 |
\isadelimquote |
|
144 |
% |
|
145 |
\endisadelimquote |
|
146 |
% |
|
147 |
\begin{isamarkuptext}% |
|
38505 | 148 |
After an interpretation of this locale (say, \indexdef{}{command}{interpretation}\hypertarget{command.interpretation}{\hyperlink{command.interpretation}{\mbox{\isa{\isacommand{interpretation}}}}} \isa{fun{\isacharunderscore}power{\isacharcolon}} \isa{{\isachardoublequote}power\ {\isacharparenleft}{\isasymlambda}n\ {\isacharparenleft}f\ {\isacharcolon}{\isacharcolon}\ {\isacharprime}a\ {\isasymRightarrow}\ {\isacharprime}a{\isacharparenright}{\isachardot}\ f\ {\isacharcircum}{\isacharcircum}\ n{\isacharparenright}{\isachardoublequote}}), one would expect to have a constant \isa{fun{\isacharunderscore}power{\isachardot}powers\ {\isacharcolon}{\isacharcolon}\ nat\ list\ {\isasymRightarrow}\ {\isacharparenleft}{\isacharprime}a\ {\isasymRightarrow}\ {\isacharprime}a{\isacharparenright}\ {\isasymRightarrow}\ {\isacharprime}a\ {\isasymRightarrow}\ {\isacharprime}a} for which code |
37426 | 149 |
can be generated. But this not the case: internally, the term |
150 |
\isa{fun{\isacharunderscore}power{\isachardot}powers} is an abbreviation for the foundational |
|
151 |
term \isa{{\isachardoublequote}power{\isachardot}powers\ {\isacharparenleft}{\isasymlambda}n\ {\isacharparenleft}f\ {\isacharcolon}{\isacharcolon}\ {\isacharprime}a\ {\isasymRightarrow}\ {\isacharprime}a{\isacharparenright}{\isachardot}\ f\ {\isacharcircum}{\isacharcircum}\ n{\isacharparenright}{\isachardoublequote}} |
|
152 |
(see \cite{isabelle-locale} for the details behind). |
|
153 |
||
37836 | 154 |
Fortunately, with minor effort the desired behaviour can be achieved. |
37426 | 155 |
First, a dedicated definition of the constant on which the local \isa{powers} |
156 |
after interpretation is supposed to be mapped on:% |
|
157 |
\end{isamarkuptext}% |
|
158 |
\isamarkuptrue% |
|
159 |
% |
|
160 |
\isadelimquote |
|
161 |
% |
|
162 |
\endisadelimquote |
|
163 |
% |
|
164 |
\isatagquote |
|
165 |
\isacommand{definition}\isamarkupfalse% |
|
166 |
\ funpows\ {\isacharcolon}{\isacharcolon}\ {\isachardoublequoteopen}nat\ list\ {\isasymRightarrow}\ {\isacharparenleft}{\isacharprime}a\ {\isasymRightarrow}\ {\isacharprime}a{\isacharparenright}\ {\isasymRightarrow}\ {\isacharprime}a\ {\isasymRightarrow}\ {\isacharprime}a{\isachardoublequoteclose}\ \isakeyword{where}\isanewline |
|
167 |
\ \ {\isacharbrackleft}code\ del{\isacharbrackright}{\isacharcolon}\ {\isachardoublequoteopen}funpows\ {\isacharequal}\ power{\isachardot}powers\ {\isacharparenleft}{\isasymlambda}n\ f{\isachardot}\ f\ {\isacharcircum}{\isacharcircum}\ n{\isacharparenright}{\isachardoublequoteclose}% |
|
168 |
\endisatagquote |
|
169 |
{\isafoldquote}% |
|
170 |
% |
|
171 |
\isadelimquote |
|
172 |
% |
|
173 |
\endisadelimquote |
|
174 |
% |
|
175 |
\begin{isamarkuptext}% |
|
176 |
\noindent In general, the pattern is \isa{c\ {\isacharequal}\ t} where \isa{c} is |
|
177 |
the name of the future constant and \isa{t} the foundational term |
|
178 |
corresponding to the local constant after interpretation. |
|
179 |
||
180 |
The interpretation itself is enriched with an equation \isa{t\ {\isacharequal}\ c}:% |
|
181 |
\end{isamarkuptext}% |
|
182 |
\isamarkuptrue% |
|
183 |
% |
|
184 |
\isadelimquote |
|
185 |
% |
|
186 |
\endisadelimquote |
|
187 |
% |
|
188 |
\isatagquote |
|
189 |
\isacommand{interpretation}\isamarkupfalse% |
|
190 |
\ fun{\isacharunderscore}power{\isacharcolon}\ power\ {\isachardoublequoteopen}{\isasymlambda}n\ {\isacharparenleft}f\ {\isacharcolon}{\isacharcolon}\ {\isacharprime}a\ {\isasymRightarrow}\ {\isacharprime}a{\isacharparenright}{\isachardot}\ f\ {\isacharcircum}{\isacharcircum}\ n{\isachardoublequoteclose}\ \isakeyword{where}\isanewline |
|
191 |
\ \ {\isachardoublequoteopen}power{\isachardot}powers\ {\isacharparenleft}{\isasymlambda}n\ f{\isachardot}\ f\ {\isacharcircum}{\isacharcircum}\ n{\isacharparenright}\ {\isacharequal}\ funpows{\isachardoublequoteclose}\isanewline |
|
192 |
\ \ \isacommand{by}\isamarkupfalse% |
|
193 |
\ unfold{\isacharunderscore}locales\isanewline |
|
39559 | 194 |
\ \ \ \ {\isacharparenleft}simp{\isacharunderscore}all\ add{\isacharcolon}\ fun{\isacharunderscore}eq{\isacharunderscore}iff\ funpow{\isacharunderscore}mult\ mult{\isacharunderscore}commute\ funpows{\isacharunderscore}def{\isacharparenright}% |
37426 | 195 |
\endisatagquote |
196 |
{\isafoldquote}% |
|
197 |
% |
|
198 |
\isadelimquote |
|
199 |
% |
|
200 |
\endisadelimquote |
|
201 |
% |
|
202 |
\begin{isamarkuptext}% |
|
203 |
\noindent This additional equation is trivially proved by the definition |
|
204 |
itself. |
|
205 |
||
206 |
After this setup procedure, code generation can continue as usual:% |
|
207 |
\end{isamarkuptext}% |
|
208 |
\isamarkuptrue% |
|
209 |
% |
|
39745 | 210 |
\isadelimquotetypewriter |
37426 | 211 |
% |
39745 | 212 |
\endisadelimquotetypewriter |
37426 | 213 |
% |
39745 | 214 |
\isatagquotetypewriter |
37426 | 215 |
% |
216 |
\begin{isamarkuptext}% |
|
39683 | 217 |
funpow\ {\isacharcolon}{\isacharcolon}\ forall\ a{\isachardot}\ Nat\ {\isacharminus}{\isachargreater}\ {\isacharparenleft}a\ {\isacharminus}{\isachargreater}\ a{\isacharparenright}\ {\isacharminus}{\isachargreater}\ a\ {\isacharminus}{\isachargreater}\ a{\isacharsemicolon}\isanewline |
39664
0afaf89ab591
more canonical type setting of type writer code examples
haftmann
parents:
39559
diff
changeset
|
218 |
funpow\ Zero{\isacharunderscore}nat\ f\ {\isacharequal}\ id{\isacharsemicolon}\isanewline |
0afaf89ab591
more canonical type setting of type writer code examples
haftmann
parents:
39559
diff
changeset
|
219 |
funpow\ {\isacharparenleft}Suc\ n{\isacharparenright}\ f\ {\isacharequal}\ f\ {\isachardot}\ funpow\ n\ f{\isacharsemicolon}\isanewline |
0afaf89ab591
more canonical type setting of type writer code examples
haftmann
parents:
39559
diff
changeset
|
220 |
\isanewline |
0afaf89ab591
more canonical type setting of type writer code examples
haftmann
parents:
39559
diff
changeset
|
221 |
funpows\ {\isacharcolon}{\isacharcolon}\ forall\ a{\isachardot}\ {\isacharbrackleft}Nat{\isacharbrackright}\ {\isacharminus}{\isachargreater}\ {\isacharparenleft}a\ {\isacharminus}{\isachargreater}\ a{\isacharparenright}\ {\isacharminus}{\isachargreater}\ a\ {\isacharminus}{\isachargreater}\ a{\isacharsemicolon}\isanewline |
0afaf89ab591
more canonical type setting of type writer code examples
haftmann
parents:
39559
diff
changeset
|
222 |
funpows\ {\isacharbrackleft}{\isacharbrackright}\ {\isacharequal}\ id{\isacharsemicolon}\isanewline |
39683 | 223 |
funpows\ {\isacharparenleft}x\ {\isacharcolon}\ xs{\isacharparenright}\ {\isacharequal}\ funpow\ x\ {\isachardot}\ funpows\ xs{\isacharsemicolon}\isanewline% |
37426 | 224 |
\end{isamarkuptext}% |
225 |
\isamarkuptrue% |
|
226 |
% |
|
39745 | 227 |
\endisatagquotetypewriter |
228 |
{\isafoldquotetypewriter}% |
|
37426 | 229 |
% |
39745 | 230 |
\isadelimquotetypewriter |
37426 | 231 |
% |
39745 | 232 |
\endisadelimquotetypewriter |
37426 | 233 |
% |
38437 | 234 |
\isamarkupsubsection{Imperative data structures% |
28447 | 235 |
} |
236 |
\isamarkuptrue% |
|
237 |
% |
|
238 |
\begin{isamarkuptext}% |
|
38437 | 239 |
If you consider imperative data structures as inevitable for a |
240 |
specific application, you should consider \emph{Imperative |
|
241 |
Functional Programming with Isabelle/HOL} |
|
242 |
\cite{bulwahn-et-al:2008:imperative}; the framework described there |
|
39070 | 243 |
is available in session \isa{Imperative{\isacharunderscore}HOL}.% |
28447 | 244 |
\end{isamarkuptext}% |
245 |
\isamarkuptrue% |
|
246 |
% |
|
38405 | 247 |
\isamarkupsubsection{ML system interfaces \label{sec:ml}% |
248 |
} |
|
249 |
\isamarkuptrue% |
|
250 |
% |
|
251 |
\begin{isamarkuptext}% |
|
38510 | 252 |
Since the code generator framework not only aims to provide a nice |
253 |
Isar interface but also to form a base for code-generation-based |
|
254 |
applications, here a short description of the most fundamental ML |
|
255 |
interfaces.% |
|
38405 | 256 |
\end{isamarkuptext}% |
257 |
\isamarkuptrue% |
|
258 |
% |
|
259 |
\isamarkupsubsubsection{Managing executable content% |
|
260 |
} |
|
261 |
\isamarkuptrue% |
|
262 |
% |
|
263 |
\isadelimmlref |
|
264 |
% |
|
265 |
\endisadelimmlref |
|
266 |
% |
|
267 |
\isatagmlref |
|
268 |
% |
|
269 |
\begin{isamarkuptext}% |
|
270 |
\begin{mldecls} |
|
38510 | 271 |
\indexdef{}{ML}{Code.read\_const}\verb|Code.read_const: theory -> string -> string| \\ |
38405 | 272 |
\indexdef{}{ML}{Code.add\_eqn}\verb|Code.add_eqn: thm -> theory -> theory| \\ |
273 |
\indexdef{}{ML}{Code.del\_eqn}\verb|Code.del_eqn: thm -> theory -> theory| \\ |
|
274 |
\indexdef{}{ML}{Code\_Preproc.map\_pre}\verb|Code_Preproc.map_pre: (simpset -> simpset) -> theory -> theory| \\ |
|
275 |
\indexdef{}{ML}{Code\_Preproc.map\_post}\verb|Code_Preproc.map_post: (simpset -> simpset) -> theory -> theory| \\ |
|
38509 | 276 |
\indexdef{}{ML}{Code\_Preproc.add\_functrans}\verb|Code_Preproc.add_functrans: |\isasep\isanewline% |
277 |
\verb| string * (theory -> (thm * bool) list -> (thm * bool) list option)|\isasep\isanewline% |
|
278 |
\verb| -> theory -> theory| \\ |
|
38405 | 279 |
\indexdef{}{ML}{Code\_Preproc.del\_functrans}\verb|Code_Preproc.del_functrans: string -> theory -> theory| \\ |
280 |
\indexdef{}{ML}{Code.add\_datatype}\verb|Code.add_datatype: (string * typ) list -> theory -> theory| \\ |
|
281 |
\indexdef{}{ML}{Code.get\_type}\verb|Code.get_type: theory -> string|\isasep\isanewline% |
|
282 |
\verb| -> (string * sort) list * ((string * string list) * typ list) list| \\ |
|
283 |
\indexdef{}{ML}{Code.get\_type\_of\_constr\_or\_abstr}\verb|Code.get_type_of_constr_or_abstr: theory -> string -> (string * bool) option| |
|
284 |
\end{mldecls} |
|
285 |
||
286 |
\begin{description} |
|
287 |
||
38510 | 288 |
\item \verb|Code.read_const|~\isa{thy}~\isa{s} |
289 |
reads a constant as a concrete term expression \isa{s}. |
|
290 |
||
38405 | 291 |
\item \verb|Code.add_eqn|~\isa{thm}~\isa{thy} adds function |
292 |
theorem \isa{thm} to executable content. |
|
293 |
||
294 |
\item \verb|Code.del_eqn|~\isa{thm}~\isa{thy} removes function |
|
295 |
theorem \isa{thm} from executable content, if present. |
|
296 |
||
297 |
\item \verb|Code_Preproc.map_pre|~\isa{f}~\isa{thy} changes |
|
298 |
the preprocessor simpset. |
|
299 |
||
300 |
\item \verb|Code_Preproc.add_functrans|~\isa{{\isacharparenleft}name{\isacharcomma}\ f{\isacharparenright}}~\isa{thy} adds |
|
301 |
function transformer \isa{f} (named \isa{name}) to executable content; |
|
302 |
\isa{f} is a transformer of the code equations belonging |
|
303 |
to a certain function definition, depending on the |
|
304 |
current theory context. Returning \isa{NONE} indicates that no |
|
305 |
transformation took place; otherwise, the whole process will be iterated |
|
306 |
with the new code equations. |
|
307 |
||
308 |
\item \verb|Code_Preproc.del_functrans|~\isa{name}~\isa{thy} removes |
|
309 |
function transformer named \isa{name} from executable content. |
|
310 |
||
311 |
\item \verb|Code.add_datatype|~\isa{cs}~\isa{thy} adds |
|
312 |
a datatype to executable content, with generation |
|
313 |
set \isa{cs}. |
|
314 |
||
315 |
\item \verb|Code.get_type_of_constr_or_abstr|~\isa{thy}~\isa{const} |
|
316 |
returns type constructor corresponding to |
|
317 |
constructor \isa{const}; returns \isa{NONE} |
|
318 |
if \isa{const} is no constructor. |
|
319 |
||
320 |
\end{description}% |
|
321 |
\end{isamarkuptext}% |
|
322 |
\isamarkuptrue% |
|
323 |
% |
|
324 |
\endisatagmlref |
|
325 |
{\isafoldmlref}% |
|
326 |
% |
|
327 |
\isadelimmlref |
|
328 |
% |
|
329 |
\endisadelimmlref |
|
330 |
% |
|
331 |
\isamarkupsubsubsection{Data depending on the theory's executable content% |
|
332 |
} |
|
333 |
\isamarkuptrue% |
|
334 |
% |
|
335 |
\begin{isamarkuptext}% |
|
336 |
Implementing code generator applications on top |
|
337 |
of the framework set out so far usually not only |
|
338 |
involves using those primitive interfaces |
|
339 |
but also storing code-dependent data and various |
|
340 |
other things. |
|
341 |
||
342 |
Due to incrementality of code generation, changes in the |
|
343 |
theory's executable content have to be propagated in a |
|
344 |
certain fashion. Additionally, such changes may occur |
|
345 |
not only during theory extension but also during theory |
|
346 |
merge, which is a little bit nasty from an implementation |
|
347 |
point of view. The framework provides a solution |
|
348 |
to this technical challenge by providing a functorial |
|
349 |
data slot \verb|Code_Data|; on instantiation |
|
350 |
of this functor, the following types and operations |
|
351 |
are required: |
|
352 |
||
353 |
\medskip |
|
354 |
\begin{tabular}{l} |
|
355 |
\isa{type\ T} \\ |
|
356 |
\isa{val\ empty{\isacharcolon}\ T} \\ |
|
357 |
\end{tabular} |
|
358 |
||
359 |
\begin{description} |
|
360 |
||
361 |
\item \isa{T} the type of data to store. |
|
362 |
||
363 |
\item \isa{empty} initial (empty) data. |
|
364 |
||
365 |
\end{description} |
|
366 |
||
367 |
\noindent An instance of \verb|Code_Data| provides the following |
|
368 |
interface: |
|
369 |
||
370 |
\medskip |
|
371 |
\begin{tabular}{l} |
|
372 |
\isa{change{\isacharcolon}\ theory\ {\isasymrightarrow}\ {\isacharparenleft}T\ {\isasymrightarrow}\ T{\isacharparenright}\ {\isasymrightarrow}\ T} \\ |
|
373 |
\isa{change{\isacharunderscore}yield{\isacharcolon}\ theory\ {\isasymrightarrow}\ {\isacharparenleft}T\ {\isasymrightarrow}\ {\isacharprime}a\ {\isacharasterisk}\ T{\isacharparenright}\ {\isasymrightarrow}\ {\isacharprime}a\ {\isacharasterisk}\ T} |
|
374 |
\end{tabular} |
|
375 |
||
376 |
\begin{description} |
|
377 |
||
378 |
\item \isa{change} update of current data (cached!) |
|
379 |
by giving a continuation. |
|
380 |
||
381 |
\item \isa{change{\isacharunderscore}yield} update with side result. |
|
382 |
||
383 |
\end{description}% |
|
384 |
\end{isamarkuptext}% |
|
385 |
\isamarkuptrue% |
|
386 |
% |
|
28447 | 387 |
\isadelimtheory |
388 |
% |
|
389 |
\endisadelimtheory |
|
390 |
% |
|
391 |
\isatagtheory |
|
392 |
\isacommand{end}\isamarkupfalse% |
|
393 |
% |
|
394 |
\endisatagtheory |
|
395 |
{\isafoldtheory}% |
|
396 |
% |
|
397 |
\isadelimtheory |
|
398 |
% |
|
399 |
\endisadelimtheory |
|
400 |
\isanewline |
|
401 |
\end{isabellebody}% |
|
402 |
%%% Local Variables: |
|
403 |
%%% mode: latex |
|
404 |
%%% TeX-master: "root" |
|
405 |
%%% End: |