author | haftmann |
Tue, 22 Apr 2008 08:33:16 +0200 | |
changeset 26732 | 6ea9de67e576 |
parent 26513 | 6f306c8c2c54 |
child 26975 | 103dca19ef2e |
permissions | -rw-r--r-- |
24589 | 1 |
(* Title: HOL/Tools/datatype_codegen.ML |
12445 | 2 |
ID: $Id$ |
20105 | 3 |
Author: Stefan Berghofer & Florian Haftmann, TU Muenchen |
12445 | 4 |
|
25534
d0b74fdd6067
simplified infrastructure for code generator operational equality
haftmann
parents:
25505
diff
changeset
|
5 |
Code generator facilities for inductive datatypes. |
12445 | 6 |
*) |
7 |
||
8 |
signature DATATYPE_CODEGEN = |
|
9 |
sig |
|
20426 | 10 |
val get_eq: theory -> string -> thm list |
23811 | 11 |
val get_case_cert: theory -> string -> thm |
18708 | 12 |
val setup: theory -> theory |
12445 | 13 |
end; |
14 |
||
15 |
structure DatatypeCodegen : DATATYPE_CODEGEN = |
|
16 |
struct |
|
17 |
||
25534
d0b74fdd6067
simplified infrastructure for code generator operational equality
haftmann
parents:
25505
diff
changeset
|
18 |
(** SML code generator **) |
d0b74fdd6067
simplified infrastructure for code generator operational equality
haftmann
parents:
25505
diff
changeset
|
19 |
|
12445 | 20 |
open Codegen; |
21 |
||
22 |
(**** datatype definition ****) |
|
23 |
||
14104 | 24 |
(* find shortest path to constructor with no recursive arguments *) |
25 |
||
26 |
fun find_nonempty (descr: DatatypeAux.descr) is i = |
|
27 |
let |
|
17521 | 28 |
val (_, _, constrs) = valOf (AList.lookup (op =) descr i); |
15531 | 29 |
fun arg_nonempty (_, DatatypeAux.DtRec i) = if i mem is then NONE |
15570 | 30 |
else Option.map (curry op + 1 o snd) (find_nonempty descr (i::is) i) |
15531 | 31 |
| arg_nonempty _ = SOME 0; |
15570 | 32 |
fun max xs = Library.foldl |
15531 | 33 |
(fn (NONE, _) => NONE |
34 |
| (SOME i, SOME j) => SOME (Int.max (i, j)) |
|
35 |
| (_, NONE) => NONE) (SOME 0, xs); |
|
14104 | 36 |
val xs = sort (int_ord o pairself snd) |
15570 | 37 |
(List.mapPartial (fn (s, dts) => Option.map (pair s) |
14104 | 38 |
(max (map (arg_nonempty o DatatypeAux.strip_dtyp) dts))) constrs) |
15531 | 39 |
in case xs of [] => NONE | x :: _ => SOME x end; |
14104 | 40 |
|
25889
c93803252748
Test data generation and conversion to terms is now more closely
berghofe
parents:
25864
diff
changeset
|
41 |
fun add_dt_defs thy defs dep module gr (descr: DatatypeAux.descr) sorts = |
12445 | 42 |
let |
15570 | 43 |
val descr' = List.filter (can (map DatatypeAux.dest_DtTFree o #2 o snd)) descr; |
44 |
val rtnames = map (#1 o snd) (List.filter (fn (_, (_, _, cs)) => |
|
14104 | 45 |
exists (exists DatatypeAux.is_rec_type o snd) cs) descr'); |
12445 | 46 |
|
17144 | 47 |
val (_, (tname, _, _)) :: _ = descr'; |
48 |
val node_id = tname ^ " (type)"; |
|
49 |
val module' = if_library (thyname_of_type tname thy) module; |
|
12445 | 50 |
|
51 |
fun mk_dtdef gr prfx [] = (gr, []) |
|
52 |
| mk_dtdef gr prfx ((_, (tname, dts, cs))::xs) = |
|
53 |
let |
|
54 |
val tvs = map DatatypeAux.dest_DtTFree dts; |
|
55 |
val cs' = map (apsnd (map (DatatypeAux.typ_of_dtyp descr sorts))) cs; |
|
17144 | 56 |
val (gr', (_, type_id)) = mk_type_id module' tname gr; |
57 |
val (gr'', ps) = |
|
58 |
foldl_map (fn (gr, (cname, cargs)) => |
|
59 |
foldl_map (invoke_tycodegen thy defs node_id module' false) |
|
60 |
(gr, cargs) |>>> |
|
61 |
mk_const_id module' cname) (gr', cs'); |
|
62 |
val (gr''', rest) = mk_dtdef gr'' "and " xs |
|
12445 | 63 |
in |
17144 | 64 |
(gr''', |
12445 | 65 |
Pretty.block (Pretty.str prfx :: |
66 |
(if null tvs then [] else |
|
67 |
[mk_tuple (map Pretty.str tvs), Pretty.str " "]) @ |
|
17144 | 68 |
[Pretty.str (type_id ^ " ="), Pretty.brk 1] @ |
15570 | 69 |
List.concat (separate [Pretty.brk 1, Pretty.str "| "] |
17144 | 70 |
(map (fn (ps', (_, cname)) => [Pretty.block |
71 |
(Pretty.str cname :: |
|
12445 | 72 |
(if null ps' then [] else |
15570 | 73 |
List.concat ([Pretty.str " of", Pretty.brk 1] :: |
12445 | 74 |
separate [Pretty.str " *", Pretty.brk 1] |
75 |
(map single ps'))))]) ps))) :: rest) |
|
13754
021cf00435a9
Code generator for datatypes now also generates suitable term_of functions (when
berghofe
parents:
12890
diff
changeset
|
76 |
end; |
021cf00435a9
Code generator for datatypes now also generates suitable term_of functions (when
berghofe
parents:
12890
diff
changeset
|
77 |
|
25889
c93803252748
Test data generation and conversion to terms is now more closely
berghofe
parents:
25864
diff
changeset
|
78 |
fun mk_constr_term cname Ts T ps = |
c93803252748
Test data generation and conversion to terms is now more closely
berghofe
parents:
25864
diff
changeset
|
79 |
List.concat (separate [Pretty.str " $", Pretty.brk 1] |
c93803252748
Test data generation and conversion to terms is now more closely
berghofe
parents:
25864
diff
changeset
|
80 |
([Pretty.str ("Const (\"" ^ cname ^ "\","), Pretty.brk 1, |
c93803252748
Test data generation and conversion to terms is now more closely
berghofe
parents:
25864
diff
changeset
|
81 |
mk_type false (Ts ---> T), Pretty.str ")"] :: ps)); |
c93803252748
Test data generation and conversion to terms is now more closely
berghofe
parents:
25864
diff
changeset
|
82 |
|
17144 | 83 |
fun mk_term_of_def gr prfx [] = [] |
84 |
| mk_term_of_def gr prfx ((_, (tname, dts, cs)) :: xs) = |
|
13754
021cf00435a9
Code generator for datatypes now also generates suitable term_of functions (when
berghofe
parents:
12890
diff
changeset
|
85 |
let |
021cf00435a9
Code generator for datatypes now also generates suitable term_of functions (when
berghofe
parents:
12890
diff
changeset
|
86 |
val cs' = map (apsnd (map (DatatypeAux.typ_of_dtyp descr sorts))) cs; |
021cf00435a9
Code generator for datatypes now also generates suitable term_of functions (when
berghofe
parents:
12890
diff
changeset
|
87 |
val dts' = map (DatatypeAux.typ_of_dtyp descr sorts) dts; |
021cf00435a9
Code generator for datatypes now also generates suitable term_of functions (when
berghofe
parents:
12890
diff
changeset
|
88 |
val T = Type (tname, dts'); |
17144 | 89 |
val rest = mk_term_of_def gr "and " xs; |
13754
021cf00435a9
Code generator for datatypes now also generates suitable term_of functions (when
berghofe
parents:
12890
diff
changeset
|
90 |
val (_, eqs) = foldl_map (fn (prfx, (cname, Ts)) => |
021cf00435a9
Code generator for datatypes now also generates suitable term_of functions (when
berghofe
parents:
12890
diff
changeset
|
91 |
let val args = map (fn i => |
021cf00435a9
Code generator for datatypes now also generates suitable term_of functions (when
berghofe
parents:
12890
diff
changeset
|
92 |
Pretty.str ("x" ^ string_of_int i)) (1 upto length Ts) |
021cf00435a9
Code generator for datatypes now also generates suitable term_of functions (when
berghofe
parents:
12890
diff
changeset
|
93 |
in (" | ", Pretty.blk (4, |
17144 | 94 |
[Pretty.str prfx, mk_term_of gr module' false T, Pretty.brk 1, |
95 |
if null Ts then Pretty.str (snd (get_const_id cname gr)) |
|
16645 | 96 |
else parens (Pretty.block |
17144 | 97 |
[Pretty.str (snd (get_const_id cname gr)), |
13754
021cf00435a9
Code generator for datatypes now also generates suitable term_of functions (when
berghofe
parents:
12890
diff
changeset
|
98 |
Pretty.brk 1, mk_tuple args]), |
021cf00435a9
Code generator for datatypes now also generates suitable term_of functions (when
berghofe
parents:
12890
diff
changeset
|
99 |
Pretty.str " =", Pretty.brk 1] @ |
25889
c93803252748
Test data generation and conversion to terms is now more closely
berghofe
parents:
25864
diff
changeset
|
100 |
mk_constr_term cname Ts T |
c93803252748
Test data generation and conversion to terms is now more closely
berghofe
parents:
25864
diff
changeset
|
101 |
(map (fn (x, U) => [Pretty.block [mk_term_of gr module' false U, |
c93803252748
Test data generation and conversion to terms is now more closely
berghofe
parents:
25864
diff
changeset
|
102 |
Pretty.brk 1, x]]) (args ~~ Ts)))) |
13754
021cf00435a9
Code generator for datatypes now also generates suitable term_of functions (when
berghofe
parents:
12890
diff
changeset
|
103 |
end) (prfx, cs') |
14104 | 104 |
in eqs @ rest end; |
105 |
||
17144 | 106 |
fun mk_gen_of_def gr prfx [] = [] |
107 |
| mk_gen_of_def gr prfx ((i, (tname, dts, cs)) :: xs) = |
|
14104 | 108 |
let |
109 |
val tvs = map DatatypeAux.dest_DtTFree dts; |
|
25889
c93803252748
Test data generation and conversion to terms is now more closely
berghofe
parents:
25864
diff
changeset
|
110 |
val Us = map (DatatypeAux.typ_of_dtyp descr sorts) dts; |
c93803252748
Test data generation and conversion to terms is now more closely
berghofe
parents:
25864
diff
changeset
|
111 |
val T = Type (tname, Us); |
14104 | 112 |
val (cs1, cs2) = |
15570 | 113 |
List.partition (exists DatatypeAux.is_rec_type o snd) cs; |
15531 | 114 |
val SOME (cname, _) = find_nonempty descr [i] i; |
14104 | 115 |
|
116 |
fun mk_delay p = Pretty.block |
|
117 |
[Pretty.str "fn () =>", Pretty.brk 1, p]; |
|
118 |
||
25889
c93803252748
Test data generation and conversion to terms is now more closely
berghofe
parents:
25864
diff
changeset
|
119 |
fun mk_force p = Pretty.block [p, Pretty.brk 1, Pretty.str "()"]; |
c93803252748
Test data generation and conversion to terms is now more closely
berghofe
parents:
25864
diff
changeset
|
120 |
|
15397
5260ac75e07c
Fixed bug in mk_gen_of_def that could cause non-termination of the generator
berghofe
parents:
14981
diff
changeset
|
121 |
fun mk_constr s b (cname, dts) = |
14104 | 122 |
let |
17144 | 123 |
val gs = map (fn dt => mk_app false (mk_gen gr module' false rtnames s |
15397
5260ac75e07c
Fixed bug in mk_gen_of_def that could cause non-termination of the generator
berghofe
parents:
14981
diff
changeset
|
124 |
(DatatypeAux.typ_of_dtyp descr sorts dt)) |
5260ac75e07c
Fixed bug in mk_gen_of_def that could cause non-termination of the generator
berghofe
parents:
14981
diff
changeset
|
125 |
[Pretty.str (if b andalso DatatypeAux.is_rec_type dt then "0" |
5260ac75e07c
Fixed bug in mk_gen_of_def that could cause non-termination of the generator
berghofe
parents:
14981
diff
changeset
|
126 |
else "j")]) dts; |
25889
c93803252748
Test data generation and conversion to terms is now more closely
berghofe
parents:
25864
diff
changeset
|
127 |
val Ts = map (DatatypeAux.typ_of_dtyp descr sorts) dts; |
c93803252748
Test data generation and conversion to terms is now more closely
berghofe
parents:
25864
diff
changeset
|
128 |
val xs = map Pretty.str |
c93803252748
Test data generation and conversion to terms is now more closely
berghofe
parents:
25864
diff
changeset
|
129 |
(DatatypeProp.indexify_names (replicate (length dts) "x")); |
c93803252748
Test data generation and conversion to terms is now more closely
berghofe
parents:
25864
diff
changeset
|
130 |
val ts = map Pretty.str |
c93803252748
Test data generation and conversion to terms is now more closely
berghofe
parents:
25864
diff
changeset
|
131 |
(DatatypeProp.indexify_names (replicate (length dts) "t")); |
17144 | 132 |
val (_, id) = get_const_id cname gr |
25889
c93803252748
Test data generation and conversion to terms is now more closely
berghofe
parents:
25864
diff
changeset
|
133 |
in |
c93803252748
Test data generation and conversion to terms is now more closely
berghofe
parents:
25864
diff
changeset
|
134 |
mk_let |
c93803252748
Test data generation and conversion to terms is now more closely
berghofe
parents:
25864
diff
changeset
|
135 |
(map2 (fn p => fn q => mk_tuple [p, q]) xs ts ~~ gs) |
c93803252748
Test data generation and conversion to terms is now more closely
berghofe
parents:
25864
diff
changeset
|
136 |
(mk_tuple |
c93803252748
Test data generation and conversion to terms is now more closely
berghofe
parents:
25864
diff
changeset
|
137 |
[case xs of |
c93803252748
Test data generation and conversion to terms is now more closely
berghofe
parents:
25864
diff
changeset
|
138 |
_ :: _ :: _ => Pretty.block |
c93803252748
Test data generation and conversion to terms is now more closely
berghofe
parents:
25864
diff
changeset
|
139 |
[Pretty.str id, Pretty.brk 1, mk_tuple xs] |
c93803252748
Test data generation and conversion to terms is now more closely
berghofe
parents:
25864
diff
changeset
|
140 |
| _ => mk_app false (Pretty.str id) xs, |
c93803252748
Test data generation and conversion to terms is now more closely
berghofe
parents:
25864
diff
changeset
|
141 |
mk_delay (Pretty.block (mk_constr_term cname Ts T |
c93803252748
Test data generation and conversion to terms is now more closely
berghofe
parents:
25864
diff
changeset
|
142 |
(map (single o mk_force) ts)))]) |
14104 | 143 |
end; |
144 |
||
15397
5260ac75e07c
Fixed bug in mk_gen_of_def that could cause non-termination of the generator
berghofe
parents:
14981
diff
changeset
|
145 |
fun mk_choice [c] = mk_constr "(i-1)" false c |
14104 | 146 |
| mk_choice cs = Pretty.block [Pretty.str "one_of", |
147 |
Pretty.brk 1, Pretty.blk (1, Pretty.str "[" :: |
|
15570 | 148 |
List.concat (separate [Pretty.str ",", Pretty.fbrk] |
15397
5260ac75e07c
Fixed bug in mk_gen_of_def that could cause non-termination of the generator
berghofe
parents:
14981
diff
changeset
|
149 |
(map (single o mk_delay o mk_constr "(i-1)" false) cs)) @ |
14104 | 150 |
[Pretty.str "]"]), Pretty.brk 1, Pretty.str "()"]; |
151 |
||
25889
c93803252748
Test data generation and conversion to terms is now more closely
berghofe
parents:
25864
diff
changeset
|
152 |
val gs = maps (fn s => |
c93803252748
Test data generation and conversion to terms is now more closely
berghofe
parents:
25864
diff
changeset
|
153 |
let val s' = strip_tname s |
c93803252748
Test data generation and conversion to terms is now more closely
berghofe
parents:
25864
diff
changeset
|
154 |
in [Pretty.str (s' ^ "G"), Pretty.str (s' ^ "T")] end) tvs; |
17144 | 155 |
val gen_name = "gen_" ^ snd (get_type_id tname gr) |
14104 | 156 |
|
157 |
in |
|
158 |
Pretty.blk (4, separate (Pretty.brk 1) |
|
159 |
(Pretty.str (prfx ^ gen_name ^ |
|
160 |
(if null cs1 then "" else "'")) :: gs @ |
|
161 |
(if null cs1 then [] else [Pretty.str "i"]) @ |
|
162 |
[Pretty.str "j"]) @ |
|
163 |
[Pretty.str " =", Pretty.brk 1] @ |
|
164 |
(if not (null cs1) andalso not (null cs2) |
|
165 |
then [Pretty.str "frequency", Pretty.brk 1, |
|
166 |
Pretty.blk (1, [Pretty.str "[", |
|
167 |
mk_tuple [Pretty.str "i", mk_delay (mk_choice cs1)], |
|
168 |
Pretty.str ",", Pretty.fbrk, |
|
169 |
mk_tuple [Pretty.str "1", mk_delay (mk_choice cs2)], |
|
170 |
Pretty.str "]"]), Pretty.brk 1, Pretty.str "()"] |
|
171 |
else if null cs2 then |
|
172 |
[Pretty.block [Pretty.str "(case", Pretty.brk 1, |
|
173 |
Pretty.str "i", Pretty.brk 1, Pretty.str "of", |
|
174 |
Pretty.brk 1, Pretty.str "0 =>", Pretty.brk 1, |
|
17521 | 175 |
mk_constr "0" true (cname, valOf (AList.lookup (op =) cs cname)), |
14104 | 176 |
Pretty.brk 1, Pretty.str "| _ =>", Pretty.brk 1, |
177 |
mk_choice cs1, Pretty.str ")"]] |
|
178 |
else [mk_choice cs2])) :: |
|
179 |
(if null cs1 then [] |
|
180 |
else [Pretty.blk (4, separate (Pretty.brk 1) |
|
181 |
(Pretty.str ("and " ^ gen_name) :: gs @ [Pretty.str "i"]) @ |
|
182 |
[Pretty.str " =", Pretty.brk 1] @ |
|
183 |
separate (Pretty.brk 1) (Pretty.str (gen_name ^ "'") :: gs @ |
|
184 |
[Pretty.str "i", Pretty.str "i"]))]) @ |
|
17144 | 185 |
mk_gen_of_def gr "and " xs |
14104 | 186 |
end |
13754
021cf00435a9
Code generator for datatypes now also generates suitable term_of functions (when
berghofe
parents:
12890
diff
changeset
|
187 |
|
12445 | 188 |
in |
20681
0e4df994ad34
Fixed bug concerning the generation of identifiers for
berghofe
parents:
20608
diff
changeset
|
189 |
((add_edge_acyclic (node_id, dep) gr |
12445 | 190 |
handle Graph.CYCLES _ => gr) handle Graph.UNDEF _ => |
191 |
let |
|
17144 | 192 |
val gr1 = add_edge (node_id, dep) |
193 |
(new_node (node_id, (NONE, "", "")) gr); |
|
12445 | 194 |
val (gr2, dtdef) = mk_dtdef gr1 "datatype " descr'; |
195 |
in |
|
17144 | 196 |
map_node node_id (K (NONE, module', |
12445 | 197 |
Pretty.string_of (Pretty.blk (0, separate Pretty.fbrk dtdef @ |
13754
021cf00435a9
Code generator for datatypes now also generates suitable term_of functions (when
berghofe
parents:
12890
diff
changeset
|
198 |
[Pretty.str ";"])) ^ "\n\n" ^ |
021cf00435a9
Code generator for datatypes now also generates suitable term_of functions (when
berghofe
parents:
12890
diff
changeset
|
199 |
(if "term_of" mem !mode then |
021cf00435a9
Code generator for datatypes now also generates suitable term_of functions (when
berghofe
parents:
12890
diff
changeset
|
200 |
Pretty.string_of (Pretty.blk (0, separate Pretty.fbrk |
17144 | 201 |
(mk_term_of_def gr2 "fun " descr') @ [Pretty.str ";"])) ^ "\n\n" |
14104 | 202 |
else "") ^ |
203 |
(if "test" mem !mode then |
|
204 |
Pretty.string_of (Pretty.blk (0, separate Pretty.fbrk |
|
17144 | 205 |
(mk_gen_of_def gr2 "fun " descr') @ [Pretty.str ";"])) ^ "\n\n" |
13754
021cf00435a9
Code generator for datatypes now also generates suitable term_of functions (when
berghofe
parents:
12890
diff
changeset
|
206 |
else ""))) gr2 |
20681
0e4df994ad34
Fixed bug concerning the generation of identifiers for
berghofe
parents:
20608
diff
changeset
|
207 |
end, |
0e4df994ad34
Fixed bug concerning the generation of identifiers for
berghofe
parents:
20608
diff
changeset
|
208 |
module') |
12445 | 209 |
end; |
210 |
||
211 |
||
212 |
(**** case expressions ****) |
|
213 |
||
17144 | 214 |
fun pretty_case thy defs gr dep module brack constrs (c as Const (_, T)) ts = |
12445 | 215 |
let val i = length constrs |
216 |
in if length ts <= i then |
|
17144 | 217 |
invoke_codegen thy defs dep module brack (gr, eta_expand c ts (i+1)) |
12445 | 218 |
else |
219 |
let |
|
15570 | 220 |
val ts1 = Library.take (i, ts); |
221 |
val t :: ts2 = Library.drop (i, ts); |
|
15574
b1d1b5bfc464
Removed practically all references to Library.foldr.
skalberg
parents:
15570
diff
changeset
|
222 |
val names = foldr add_term_names |
b1d1b5bfc464
Removed practically all references to Library.foldr.
skalberg
parents:
15570
diff
changeset
|
223 |
(map (fst o fst o dest_Var) (foldr add_term_vars [] ts1)) ts1; |
15570 | 224 |
val (Ts, dT) = split_last (Library.take (i+1, fst (strip_type T))); |
12445 | 225 |
|
226 |
fun pcase gr [] [] [] = ([], gr) |
|
227 |
| pcase gr ((cname, cargs)::cs) (t::ts) (U::Us) = |
|
228 |
let |
|
229 |
val j = length cargs; |
|
20071
8f3e1ddb50e6
replaced Term.variant(list) by Name.variant(_list);
wenzelm
parents:
19886
diff
changeset
|
230 |
val xs = Name.variant_list names (replicate j "x"); |
15570 | 231 |
val Us' = Library.take (j, fst (strip_type U)); |
12445 | 232 |
val frees = map Free (xs ~~ Us'); |
17144 | 233 |
val (gr0, cp) = invoke_codegen thy defs dep module false |
12445 | 234 |
(gr, list_comb (Const (cname, Us' ---> dT), frees)); |
235 |
val t' = Envir.beta_norm (list_comb (t, frees)); |
|
17144 | 236 |
val (gr1, p) = invoke_codegen thy defs dep module false (gr0, t'); |
12445 | 237 |
val (ps, gr2) = pcase gr1 cs ts Us; |
238 |
in |
|
239 |
([Pretty.block [cp, Pretty.str " =>", Pretty.brk 1, p]] :: ps, gr2) |
|
240 |
end; |
|
241 |
||
242 |
val (ps1, gr1) = pcase gr constrs ts1 Ts; |
|
15570 | 243 |
val ps = List.concat (separate [Pretty.brk 1, Pretty.str "| "] ps1); |
17144 | 244 |
val (gr2, p) = invoke_codegen thy defs dep module false (gr1, t); |
245 |
val (gr3, ps2) = foldl_map (invoke_codegen thy defs dep module true) (gr2, ts2) |
|
12445 | 246 |
in (gr3, (if not (null ts2) andalso brack then parens else I) |
247 |
(Pretty.block (separate (Pretty.brk 1) |
|
248 |
(Pretty.block ([Pretty.str "(case ", p, Pretty.str " of", |
|
249 |
Pretty.brk 1] @ ps @ [Pretty.str ")"]) :: ps2)))) |
|
250 |
end |
|
251 |
end; |
|
252 |
||
253 |
||
254 |
(**** constructors ****) |
|
255 |
||
17144 | 256 |
fun pretty_constr thy defs gr dep module brack args (c as Const (s, T)) ts = |
12445 | 257 |
let val i = length args |
258 |
in if i > 1 andalso length ts < i then |
|
17144 | 259 |
invoke_codegen thy defs dep module brack (gr, eta_expand c ts i) |
12445 | 260 |
else |
261 |
let |
|
17144 | 262 |
val id = mk_qual_id module (get_const_id s gr); |
16645 | 263 |
val (gr', ps) = foldl_map |
17144 | 264 |
(invoke_codegen thy defs dep module (i = 1)) (gr, ts); |
12445 | 265 |
in (case args of |
266 |
_ :: _ :: _ => (gr', (if brack then parens else I) |
|
267 |
(Pretty.block [Pretty.str id, Pretty.brk 1, mk_tuple ps])) |
|
268 |
| _ => (gr', mk_app brack (Pretty.str id) ps)) |
|
269 |
end |
|
270 |
end; |
|
271 |
||
272 |
||
273 |
(**** code generators for terms and types ****) |
|
274 |
||
17144 | 275 |
fun datatype_codegen thy defs gr dep module brack t = (case strip_comb t of |
12445 | 276 |
(c as Const (s, T), ts) => |
22778
a5b87573f427
Streamlined datatype_codegen function using new datatype_of_case
berghofe
parents:
22746
diff
changeset
|
277 |
(case DatatypePackage.datatype_of_case thy s of |
a5b87573f427
Streamlined datatype_codegen function using new datatype_of_case
berghofe
parents:
22746
diff
changeset
|
278 |
SOME {index, descr, ...} => |
22921
475ff421a6a3
consts in consts_code Isar commands are now referred to by usual term syntax
haftmann
parents:
22778
diff
changeset
|
279 |
if is_some (get_assoc_code thy (s, T)) then NONE else |
22778
a5b87573f427
Streamlined datatype_codegen function using new datatype_of_case
berghofe
parents:
22746
diff
changeset
|
280 |
SOME (pretty_case thy defs gr dep module brack |
a5b87573f427
Streamlined datatype_codegen function using new datatype_of_case
berghofe
parents:
22746
diff
changeset
|
281 |
(#3 (the (AList.lookup op = descr index))) c ts) |
a5b87573f427
Streamlined datatype_codegen function using new datatype_of_case
berghofe
parents:
22746
diff
changeset
|
282 |
| NONE => case (DatatypePackage.datatype_of_constr thy s, strip_type T) of |
a5b87573f427
Streamlined datatype_codegen function using new datatype_of_case
berghofe
parents:
22746
diff
changeset
|
283 |
(SOME {index, descr, ...}, (_, U as Type _)) => |
22921
475ff421a6a3
consts in consts_code Isar commands are now referred to by usual term syntax
haftmann
parents:
22778
diff
changeset
|
284 |
if is_some (get_assoc_code thy (s, T)) then NONE else |
22778
a5b87573f427
Streamlined datatype_codegen function using new datatype_of_case
berghofe
parents:
22746
diff
changeset
|
285 |
let val SOME args = AList.lookup op = |
a5b87573f427
Streamlined datatype_codegen function using new datatype_of_case
berghofe
parents:
22746
diff
changeset
|
286 |
(#3 (the (AList.lookup op = descr index))) s |
a5b87573f427
Streamlined datatype_codegen function using new datatype_of_case
berghofe
parents:
22746
diff
changeset
|
287 |
in |
a5b87573f427
Streamlined datatype_codegen function using new datatype_of_case
berghofe
parents:
22746
diff
changeset
|
288 |
SOME (pretty_constr thy defs |
a5b87573f427
Streamlined datatype_codegen function using new datatype_of_case
berghofe
parents:
22746
diff
changeset
|
289 |
(fst (invoke_tycodegen thy defs dep module false (gr, U))) |
a5b87573f427
Streamlined datatype_codegen function using new datatype_of_case
berghofe
parents:
22746
diff
changeset
|
290 |
dep module brack args c ts) |
a5b87573f427
Streamlined datatype_codegen function using new datatype_of_case
berghofe
parents:
22746
diff
changeset
|
291 |
end |
a5b87573f427
Streamlined datatype_codegen function using new datatype_of_case
berghofe
parents:
22746
diff
changeset
|
292 |
| _ => NONE) |
a5b87573f427
Streamlined datatype_codegen function using new datatype_of_case
berghofe
parents:
22746
diff
changeset
|
293 |
| _ => NONE); |
12445 | 294 |
|
17144 | 295 |
fun datatype_tycodegen thy defs gr dep module brack (Type (s, Ts)) = |
22778
a5b87573f427
Streamlined datatype_codegen function using new datatype_of_case
berghofe
parents:
22746
diff
changeset
|
296 |
(case DatatypePackage.get_datatype thy s of |
15531 | 297 |
NONE => NONE |
25889
c93803252748
Test data generation and conversion to terms is now more closely
berghofe
parents:
25864
diff
changeset
|
298 |
| SOME {descr, sorts, ...} => |
22921
475ff421a6a3
consts in consts_code Isar commands are now referred to by usual term syntax
haftmann
parents:
22778
diff
changeset
|
299 |
if is_some (get_assoc_type thy s) then NONE else |
16645 | 300 |
let |
301 |
val (gr', ps) = foldl_map |
|
17144 | 302 |
(invoke_tycodegen thy defs dep module false) (gr, Ts); |
25889
c93803252748
Test data generation and conversion to terms is now more closely
berghofe
parents:
25864
diff
changeset
|
303 |
val (gr'', module') = add_dt_defs thy defs dep module gr' descr sorts; |
20681
0e4df994ad34
Fixed bug concerning the generation of identifiers for
berghofe
parents:
20608
diff
changeset
|
304 |
val (gr''', tyid) = mk_type_id module' s gr'' |
0e4df994ad34
Fixed bug concerning the generation of identifiers for
berghofe
parents:
20608
diff
changeset
|
305 |
in SOME (gr''', |
12445 | 306 |
Pretty.block ((if null Ts then [] else |
307 |
[mk_tuple ps, Pretty.str " "]) @ |
|
20681
0e4df994ad34
Fixed bug concerning the generation of identifiers for
berghofe
parents:
20608
diff
changeset
|
308 |
[Pretty.str (mk_qual_id module tyid)])) |
12445 | 309 |
end) |
16645 | 310 |
| datatype_tycodegen _ _ _ _ _ _ _ = NONE; |
12445 | 311 |
|
18247
b17724cae935
code generator: case expressions, improved name resolving
haftmann
parents:
18220
diff
changeset
|
312 |
|
25534
d0b74fdd6067
simplified infrastructure for code generator operational equality
haftmann
parents:
25505
diff
changeset
|
313 |
(** generic code generator **) |
20105 | 314 |
|
25534
d0b74fdd6067
simplified infrastructure for code generator operational equality
haftmann
parents:
25505
diff
changeset
|
315 |
(* specification *) |
20426 | 316 |
|
25534
d0b74fdd6067
simplified infrastructure for code generator operational equality
haftmann
parents:
25505
diff
changeset
|
317 |
fun add_datatype_spec vs dtco cos thy = |
20835 | 318 |
let |
25534
d0b74fdd6067
simplified infrastructure for code generator operational equality
haftmann
parents:
25505
diff
changeset
|
319 |
val cs = map (fn (c, tys) => (c, tys ---> Type (dtco, map TFree vs))) cos; |
d0b74fdd6067
simplified infrastructure for code generator operational equality
haftmann
parents:
25505
diff
changeset
|
320 |
in |
d0b74fdd6067
simplified infrastructure for code generator operational equality
haftmann
parents:
25505
diff
changeset
|
321 |
thy |
d0b74fdd6067
simplified infrastructure for code generator operational equality
haftmann
parents:
25505
diff
changeset
|
322 |
|> try (Code.add_datatype cs) |
d0b74fdd6067
simplified infrastructure for code generator operational equality
haftmann
parents:
25505
diff
changeset
|
323 |
|> the_default thy |
d0b74fdd6067
simplified infrastructure for code generator operational equality
haftmann
parents:
25505
diff
changeset
|
324 |
end; |
21516 | 325 |
|
25534
d0b74fdd6067
simplified infrastructure for code generator operational equality
haftmann
parents:
25505
diff
changeset
|
326 |
|
d0b74fdd6067
simplified infrastructure for code generator operational equality
haftmann
parents:
25505
diff
changeset
|
327 |
(* case certificates *) |
19346 | 328 |
|
23811 | 329 |
fun get_case_cert thy tyco = |
330 |
let |
|
331 |
val raw_thms = |
|
332 |
(#case_rewrites o DatatypePackage.the_datatype thy) tyco; |
|
333 |
val thms as hd_thm :: _ = raw_thms |
|
334 |
|> Conjunction.intr_balanced |
|
24976
821628d16552
moved Drule.unvarify to Thm.unvarify (cf. more_thm.ML);
wenzelm
parents:
24845
diff
changeset
|
335 |
|> Thm.unvarify |
23811 | 336 |
|> Conjunction.elim_balanced (length raw_thms) |
337 |
|> map Simpdata.mk_meta_eq |
|
338 |
|> map Drule.zero_var_indexes |
|
339 |
val params = fold_aterms (fn (Free (v, _)) => insert (op =) v |
|
340 |
| _ => I) (Thm.prop_of hd_thm) []; |
|
341 |
val rhs = hd_thm |
|
342 |
|> Thm.prop_of |
|
343 |
|> Logic.dest_equals |
|
344 |
|> fst |
|
345 |
|> Term.strip_comb |
|
346 |
|> apsnd (fst o split_last) |
|
347 |
|> list_comb; |
|
348 |
val lhs = Free (Name.variant params "case", Term.fastype_of rhs); |
|
349 |
val asm = (Thm.cterm_of thy o Logic.mk_equals) (lhs, rhs); |
|
350 |
in |
|
351 |
thms |
|
352 |
|> Conjunction.intr_balanced |
|
353 |
|> MetaSimplifier.rewrite_rule [(Thm.symmetric o Thm.assume) asm] |
|
354 |
|> Thm.implies_intr asm |
|
355 |
|> Thm.generalize ([], params) 0 |
|
25597
34860182b250
moved instance parameter management from class.ML to axclass.ML
haftmann
parents:
25569
diff
changeset
|
356 |
|> AxClass.unoverload thy |
23811 | 357 |
|> Thm.varifyT |
358 |
end; |
|
359 |
||
25534
d0b74fdd6067
simplified infrastructure for code generator operational equality
haftmann
parents:
25505
diff
changeset
|
360 |
fun add_datatype_cases dtco thy = |
25505 | 361 |
let |
25534
d0b74fdd6067
simplified infrastructure for code generator operational equality
haftmann
parents:
25505
diff
changeset
|
362 |
val {case_rewrites, ...} = DatatypePackage.the_datatype thy dtco; |
d0b74fdd6067
simplified infrastructure for code generator operational equality
haftmann
parents:
25505
diff
changeset
|
363 |
val certs = get_case_cert thy dtco; |
20426 | 364 |
in |
365 |
thy |
|
25534
d0b74fdd6067
simplified infrastructure for code generator operational equality
haftmann
parents:
25505
diff
changeset
|
366 |
|> Code.add_case certs |
d0b74fdd6067
simplified infrastructure for code generator operational equality
haftmann
parents:
25505
diff
changeset
|
367 |
|> fold_rev Code.add_default_func case_rewrites |
20426 | 368 |
end; |
369 |
||
25534
d0b74fdd6067
simplified infrastructure for code generator operational equality
haftmann
parents:
25505
diff
changeset
|
370 |
|
d0b74fdd6067
simplified infrastructure for code generator operational equality
haftmann
parents:
25505
diff
changeset
|
371 |
(* equality *) |
d0b74fdd6067
simplified infrastructure for code generator operational equality
haftmann
parents:
25505
diff
changeset
|
372 |
|
d0b74fdd6067
simplified infrastructure for code generator operational equality
haftmann
parents:
25505
diff
changeset
|
373 |
local |
20426 | 374 |
|
25534
d0b74fdd6067
simplified infrastructure for code generator operational equality
haftmann
parents:
25505
diff
changeset
|
375 |
val not_sym = thm "HOL.not_sym"; |
d0b74fdd6067
simplified infrastructure for code generator operational equality
haftmann
parents:
25505
diff
changeset
|
376 |
val not_false_true = iffD2 OF [nth (thms "HOL.simp_thms") 7, TrueI]; |
d0b74fdd6067
simplified infrastructure for code generator operational equality
haftmann
parents:
25505
diff
changeset
|
377 |
val refl = thm "refl"; |
d0b74fdd6067
simplified infrastructure for code generator operational equality
haftmann
parents:
25505
diff
changeset
|
378 |
val eqTrueI = thm "eqTrueI"; |
20835 | 379 |
|
25534
d0b74fdd6067
simplified infrastructure for code generator operational equality
haftmann
parents:
25505
diff
changeset
|
380 |
fun mk_distinct cos = |
22423 | 381 |
let |
25534
d0b74fdd6067
simplified infrastructure for code generator operational equality
haftmann
parents:
25505
diff
changeset
|
382 |
fun sym_product [] = [] |
d0b74fdd6067
simplified infrastructure for code generator operational equality
haftmann
parents:
25505
diff
changeset
|
383 |
| sym_product (x::xs) = map (pair x) xs @ sym_product xs; |
d0b74fdd6067
simplified infrastructure for code generator operational equality
haftmann
parents:
25505
diff
changeset
|
384 |
fun mk_co_args (co, tys) ctxt = |
d0b74fdd6067
simplified infrastructure for code generator operational equality
haftmann
parents:
25505
diff
changeset
|
385 |
let |
d0b74fdd6067
simplified infrastructure for code generator operational equality
haftmann
parents:
25505
diff
changeset
|
386 |
val names = Name.invents ctxt "a" (length tys); |
d0b74fdd6067
simplified infrastructure for code generator operational equality
haftmann
parents:
25505
diff
changeset
|
387 |
val ctxt' = fold Name.declare names ctxt; |
d0b74fdd6067
simplified infrastructure for code generator operational equality
haftmann
parents:
25505
diff
changeset
|
388 |
val vs = map2 (curry Free) names tys; |
d0b74fdd6067
simplified infrastructure for code generator operational equality
haftmann
parents:
25505
diff
changeset
|
389 |
in (vs, ctxt') end; |
d0b74fdd6067
simplified infrastructure for code generator operational equality
haftmann
parents:
25505
diff
changeset
|
390 |
fun mk_dist ((co1, tys1), (co2, tys2)) = |
22423 | 391 |
let |
25534
d0b74fdd6067
simplified infrastructure for code generator operational equality
haftmann
parents:
25505
diff
changeset
|
392 |
val ((xs1, xs2), _) = Name.context |
d0b74fdd6067
simplified infrastructure for code generator operational equality
haftmann
parents:
25505
diff
changeset
|
393 |
|> mk_co_args (co1, tys1) |
d0b74fdd6067
simplified infrastructure for code generator operational equality
haftmann
parents:
25505
diff
changeset
|
394 |
||>> mk_co_args (co2, tys2); |
d0b74fdd6067
simplified infrastructure for code generator operational equality
haftmann
parents:
25505
diff
changeset
|
395 |
val prem = HOLogic.mk_eq |
d0b74fdd6067
simplified infrastructure for code generator operational equality
haftmann
parents:
25505
diff
changeset
|
396 |
(list_comb (co1, xs1), list_comb (co2, xs2)); |
d0b74fdd6067
simplified infrastructure for code generator operational equality
haftmann
parents:
25505
diff
changeset
|
397 |
val t = HOLogic.mk_not prem; |
d0b74fdd6067
simplified infrastructure for code generator operational equality
haftmann
parents:
25505
diff
changeset
|
398 |
in HOLogic.mk_Trueprop t end; |
d0b74fdd6067
simplified infrastructure for code generator operational equality
haftmann
parents:
25505
diff
changeset
|
399 |
in map mk_dist (sym_product cos) end; |
d0b74fdd6067
simplified infrastructure for code generator operational equality
haftmann
parents:
25505
diff
changeset
|
400 |
|
d0b74fdd6067
simplified infrastructure for code generator operational equality
haftmann
parents:
25505
diff
changeset
|
401 |
in |
20426 | 402 |
|
25534
d0b74fdd6067
simplified infrastructure for code generator operational equality
haftmann
parents:
25505
diff
changeset
|
403 |
fun get_eq thy dtco = |
d0b74fdd6067
simplified infrastructure for code generator operational equality
haftmann
parents:
25505
diff
changeset
|
404 |
let |
d0b74fdd6067
simplified infrastructure for code generator operational equality
haftmann
parents:
25505
diff
changeset
|
405 |
val (vs, cs) = DatatypePackage.the_datatype_spec thy dtco; |
d0b74fdd6067
simplified infrastructure for code generator operational equality
haftmann
parents:
25505
diff
changeset
|
406 |
fun mk_triv_inject co = |
d0b74fdd6067
simplified infrastructure for code generator operational equality
haftmann
parents:
25505
diff
changeset
|
407 |
let |
d0b74fdd6067
simplified infrastructure for code generator operational equality
haftmann
parents:
25505
diff
changeset
|
408 |
val ct' = Thm.cterm_of thy |
d0b74fdd6067
simplified infrastructure for code generator operational equality
haftmann
parents:
25505
diff
changeset
|
409 |
(Const (co, Type (dtco, map (fn (v, sort) => TVar ((v, 0), sort)) vs))) |
d0b74fdd6067
simplified infrastructure for code generator operational equality
haftmann
parents:
25505
diff
changeset
|
410 |
val cty' = Thm.ctyp_of_term ct'; |
d0b74fdd6067
simplified infrastructure for code generator operational equality
haftmann
parents:
25505
diff
changeset
|
411 |
val SOME (ct, cty) = fold_aterms (fn Var (v, ty) => |
d0b74fdd6067
simplified infrastructure for code generator operational equality
haftmann
parents:
25505
diff
changeset
|
412 |
(K o SOME) (Thm.cterm_of thy (Var (v, Thm.typ_of cty')), Thm.ctyp_of thy ty) | _ => I) |
d0b74fdd6067
simplified infrastructure for code generator operational equality
haftmann
parents:
25505
diff
changeset
|
413 |
(Thm.prop_of refl) NONE; |
d0b74fdd6067
simplified infrastructure for code generator operational equality
haftmann
parents:
25505
diff
changeset
|
414 |
in eqTrueI OF [Thm.instantiate ([(cty, cty')], [(ct, ct')]) refl] end; |
d0b74fdd6067
simplified infrastructure for code generator operational equality
haftmann
parents:
25505
diff
changeset
|
415 |
val inject1 = map_filter (fn (co, []) => SOME (mk_triv_inject co) | _ => NONE) cs |
d0b74fdd6067
simplified infrastructure for code generator operational equality
haftmann
parents:
25505
diff
changeset
|
416 |
val inject2 = (#inject o DatatypePackage.the_datatype thy) dtco; |
d0b74fdd6067
simplified infrastructure for code generator operational equality
haftmann
parents:
25505
diff
changeset
|
417 |
val ctxt = ProofContext.init thy; |
d0b74fdd6067
simplified infrastructure for code generator operational equality
haftmann
parents:
25505
diff
changeset
|
418 |
val simpset = Simplifier.context ctxt |
d0b74fdd6067
simplified infrastructure for code generator operational equality
haftmann
parents:
25505
diff
changeset
|
419 |
(MetaSimplifier.empty_ss addsimprocs [distinct_simproc]); |
d0b74fdd6067
simplified infrastructure for code generator operational equality
haftmann
parents:
25505
diff
changeset
|
420 |
val cos = map (fn (co, tys) => |
d0b74fdd6067
simplified infrastructure for code generator operational equality
haftmann
parents:
25505
diff
changeset
|
421 |
(Const (co, tys ---> Type (dtco, map TFree vs)), tys)) cs; |
d0b74fdd6067
simplified infrastructure for code generator operational equality
haftmann
parents:
25505
diff
changeset
|
422 |
val tac = ALLGOALS (simp_tac simpset) |
d0b74fdd6067
simplified infrastructure for code generator operational equality
haftmann
parents:
25505
diff
changeset
|
423 |
THEN ALLGOALS (ProofContext.fact_tac [not_false_true, TrueI]); |
d0b74fdd6067
simplified infrastructure for code generator operational equality
haftmann
parents:
25505
diff
changeset
|
424 |
val distinct = |
d0b74fdd6067
simplified infrastructure for code generator operational equality
haftmann
parents:
25505
diff
changeset
|
425 |
mk_distinct cos |
d0b74fdd6067
simplified infrastructure for code generator operational equality
haftmann
parents:
25505
diff
changeset
|
426 |
|> map (fn t => Goal.prove_global thy [] [] t (K tac)) |
d0b74fdd6067
simplified infrastructure for code generator operational equality
haftmann
parents:
25505
diff
changeset
|
427 |
|> (fn thms => thms @ map (fn thm => not_sym OF [thm]) thms) |
d0b74fdd6067
simplified infrastructure for code generator operational equality
haftmann
parents:
25505
diff
changeset
|
428 |
in inject1 @ inject2 @ distinct end; |
20426 | 429 |
|
25534
d0b74fdd6067
simplified infrastructure for code generator operational equality
haftmann
parents:
25505
diff
changeset
|
430 |
end; |
20835 | 431 |
|
25534
d0b74fdd6067
simplified infrastructure for code generator operational equality
haftmann
parents:
25505
diff
changeset
|
432 |
fun add_datatypes_equality vs dtcos thy = |
20597 | 433 |
let |
26513 | 434 |
val vs' = (map o apsnd) |
435 |
(curry (Sorts.inter_sort (Sign.classes_of thy)) [HOLogic.class_eq]) vs; |
|
436 |
fun add_def tyco lthy = |
|
437 |
let |
|
438 |
val ty = Type (tyco, map TFree vs'); |
|
439 |
fun mk_side const_name = Const (const_name, ty --> ty --> HOLogic.boolT) |
|
440 |
$ Free ("x", ty) $ Free ("y", ty); |
|
441 |
val def = HOLogic.mk_Trueprop (HOLogic.mk_eq |
|
26732 | 442 |
(mk_side @{const_name eq_class.eq}, mk_side @{const_name "op ="})); |
26513 | 443 |
val def' = Syntax.check_term lthy def; |
444 |
val ((_, (_, thm)), lthy') = Specification.definition |
|
445 |
(NONE, (("", []), def')) lthy; |
|
446 |
val ctxt_thy = ProofContext.init (ProofContext.theory_of lthy); |
|
447 |
val thm' = singleton (ProofContext.export lthy' ctxt_thy) thm; |
|
448 |
in (thm', lthy') end; |
|
449 |
fun tac thms = Class.intro_classes_tac [] |
|
450 |
THEN ALLGOALS (ProofContext.fact_tac thms); |
|
25534
d0b74fdd6067
simplified infrastructure for code generator operational equality
haftmann
parents:
25505
diff
changeset
|
451 |
fun get_eq' thy dtco = get_eq thy dtco |
d0b74fdd6067
simplified infrastructure for code generator operational equality
haftmann
parents:
25505
diff
changeset
|
452 |
|> map (CodeUnit.constrain_thm [HOLogic.class_eq]) |
26513 | 453 |
|> map Simpdata.mk_eq |
454 |
|> map (MetaSimplifier.rewrite_rule [Thm.transfer thy @{thm equals_eq}]); |
|
25534
d0b74fdd6067
simplified infrastructure for code generator operational equality
haftmann
parents:
25505
diff
changeset
|
455 |
fun add_eq_thms dtco thy = |
20597 | 456 |
let |
24137
8d7896398147
replaced Theory.self_ref by Theory.check_thy, which now produces a checked ref;
wenzelm
parents:
23811
diff
changeset
|
457 |
val thy_ref = Theory.check_thy thy; |
26732 | 458 |
val const = AxClass.param_of_inst thy (@{const_name eq_class.eq}, dtco); |
25534
d0b74fdd6067
simplified infrastructure for code generator operational equality
haftmann
parents:
25505
diff
changeset
|
459 |
val get_thms = (fn () => get_eq' (Theory.deref thy_ref) dtco |> rev); |
20597 | 460 |
in |
24219 | 461 |
Code.add_funcl (const, Susp.delay get_thms) thy |
20597 | 462 |
end; |
463 |
in |
|
25534
d0b74fdd6067
simplified infrastructure for code generator operational equality
haftmann
parents:
25505
diff
changeset
|
464 |
thy |
25864 | 465 |
|> TheoryTarget.instantiation (dtcos, vs', [HOLogic.class_eq]) |
26513 | 466 |
|> fold_map add_def dtcos |
467 |
|-> (fn thms => Class.prove_instantiation_instance (K (tac thms)) |
|
468 |
#> LocalTheory.exit |
|
469 |
#> ProofContext.theory_of |
|
470 |
#> fold Code.del_func thms |
|
471 |
#> fold add_eq_thms dtcos) |
|
20597 | 472 |
end; |
473 |
||
20426 | 474 |
|
475 |
(** theory setup **) |
|
476 |
||
25534
d0b74fdd6067
simplified infrastructure for code generator operational equality
haftmann
parents:
25505
diff
changeset
|
477 |
fun add_datatype_code dtcos thy = |
23513 | 478 |
let |
25534
d0b74fdd6067
simplified infrastructure for code generator operational equality
haftmann
parents:
25505
diff
changeset
|
479 |
val (vs :: _, coss) = (split_list o map (DatatypePackage.the_datatype_spec thy)) dtcos; |
25489 | 480 |
in |
25505 | 481 |
thy |
25534
d0b74fdd6067
simplified infrastructure for code generator operational equality
haftmann
parents:
25505
diff
changeset
|
482 |
|> fold2 (add_datatype_spec vs) dtcos coss |
d0b74fdd6067
simplified infrastructure for code generator operational equality
haftmann
parents:
25505
diff
changeset
|
483 |
|> fold add_datatype_cases dtcos |
d0b74fdd6067
simplified infrastructure for code generator operational equality
haftmann
parents:
25505
diff
changeset
|
484 |
|> add_datatypes_equality vs dtcos |
25489 | 485 |
end; |
486 |
||
19008 | 487 |
val setup = |
20597 | 488 |
add_codegen "datatype" datatype_codegen |
24626
85eceef2edc7
introduced generic concepts for theory interpretators
haftmann
parents:
24624
diff
changeset
|
489 |
#> add_tycodegen "datatype" datatype_tycodegen |
25534
d0b74fdd6067
simplified infrastructure for code generator operational equality
haftmann
parents:
25505
diff
changeset
|
490 |
#> DatatypePackage.interpretation add_datatype_code |
20597 | 491 |
|
12445 | 492 |
end; |