author | haftmann |
Mon, 14 Aug 2006 13:46:21 +0200 | |
changeset 20386 | d1cbe5aa6bf2 |
parent 20353 | d73e49780ef2 |
child 20389 | 8b6ecb22ef35 |
permissions | -rw-r--r-- |
18169
45def66f86cb
added modules for code generator generation two, not operational yet
haftmann
parents:
diff
changeset
|
1 |
(* Title: Pure/Tools/codegen_package.ML |
45def66f86cb
added modules for code generator generation two, not operational yet
haftmann
parents:
diff
changeset
|
2 |
ID: $Id$ |
45def66f86cb
added modules for code generator generation two, not operational yet
haftmann
parents:
diff
changeset
|
3 |
Author: Florian Haftmann, TU Muenchen |
45def66f86cb
added modules for code generator generation two, not operational yet
haftmann
parents:
diff
changeset
|
4 |
|
18217 | 5 |
Code generator from Isabelle theories to |
18169
45def66f86cb
added modules for code generator generation two, not operational yet
haftmann
parents:
diff
changeset
|
6 |
intermediate language ("Thin-gol"). |
45def66f86cb
added modules for code generator generation two, not operational yet
haftmann
parents:
diff
changeset
|
7 |
*) |
45def66f86cb
added modules for code generator generation two, not operational yet
haftmann
parents:
diff
changeset
|
8 |
|
45def66f86cb
added modules for code generator generation two, not operational yet
haftmann
parents:
diff
changeset
|
9 |
signature CODEGEN_PACKAGE = |
45def66f86cb
added modules for code generator generation two, not operational yet
haftmann
parents:
diff
changeset
|
10 |
sig |
20105 | 11 |
val codegen_term: term -> theory -> CodegenThingol.iterm * theory; |
20213 | 12 |
val eval_term: (string (*reference name!*) * 'a ref) * term -> theory -> 'a * theory; |
19884 | 13 |
val is_dtcon: string -> bool; |
14 |
val consts_of_idfs: theory -> string list -> (string * typ) list; |
|
15 |
val idfs_of_consts: theory -> (string * typ) list -> string list; |
|
19967 | 16 |
val get_root_module: theory -> CodegenThingol.module * theory; |
19884 | 17 |
val get_ml_fun_datatype: theory -> (string -> string) |
18 |
-> ((string * CodegenThingol.funn) list -> Pretty.T) |
|
19 |
* ((string * CodegenThingol.datatyp) list -> Pretty.T); |
|
18702 | 20 |
|
18704
2c86ced392a8
substantial improvement in serialization handling
haftmann
parents:
18702
diff
changeset
|
21 |
val add_pretty_list: string -> string -> string * (int * string) |
2c86ced392a8
substantial improvement in serialization handling
haftmann
parents:
18702
diff
changeset
|
22 |
-> theory -> theory; |
20175 | 23 |
val purge_code: theory -> theory; |
18217 | 24 |
|
19884 | 25 |
type appgen; |
20105 | 26 |
val add_appconst: xstring * appgen -> theory -> theory; |
27 |
val add_appconst_i: string * appgen -> theory -> theory; |
|
18702 | 28 |
val appgen_default: appgen; |
20353 | 29 |
val appgen_rep_bin: (theory -> term -> IntInf.int) -> appgen; |
19607
07eeb832f28d
introduced characters for code generator; some improved code lemmas for some list functions
haftmann
parents:
19597
diff
changeset
|
30 |
val appgen_char: (term -> int option) -> appgen; |
20105 | 31 |
val appgen_case: (theory -> term |
32 |
-> ((string * typ) list * ((term * typ) * (term * term) list)) option) |
|
33 |
-> appgen; |
|
34 |
val appgen_let: appgen; |
|
19038 | 35 |
val appgen_wfrec: appgen; |
18217 | 36 |
|
19008 | 37 |
val print_code: theory -> unit; |
18515 | 38 |
|
18231 | 39 |
structure CodegenData: THEORY_DATA; |
19884 | 40 |
type auxtab; |
20353 | 41 |
val mk_tabs: theory -> string list option -> (string * typ) list -> auxtab; |
18169
45def66f86cb
added modules for code generator generation two, not operational yet
haftmann
parents:
diff
changeset
|
42 |
end; |
45def66f86cb
added modules for code generator generation two, not operational yet
haftmann
parents:
diff
changeset
|
43 |
|
18217 | 44 |
structure CodegenPackage : CODEGEN_PACKAGE = |
18169
45def66f86cb
added modules for code generator generation two, not operational yet
haftmann
parents:
diff
changeset
|
45 |
struct |
45def66f86cb
added modules for code generator generation two, not operational yet
haftmann
parents:
diff
changeset
|
46 |
|
18850 | 47 |
open CodegenThingol; |
18217 | 48 |
|
18702 | 49 |
(* shallow name spaces *) |
18217 | 50 |
|
20216 | 51 |
val nsp_module = ""; (*a dummy by convention*) |
18217 | 52 |
val nsp_class = "class"; |
18454 | 53 |
val nsp_tyco = "tyco"; |
18217 | 54 |
val nsp_const = "const"; |
18454 | 55 |
val nsp_dtcon = "dtcon"; |
18217 | 56 |
val nsp_mem = "mem"; |
57 |
val nsp_inst = "inst"; |
|
19213 | 58 |
val nsp_instmem = "instmem"; |
20216 | 59 |
val nsp_eval = "EVAL"; (*only for evaluation*) |
18217 | 60 |
|
19038 | 61 |
fun add_nsp shallow name = |
62 |
name |
|
63 |
|> NameSpace.unpack |
|
64 |
|> split_last |
|
65 |
|> apsnd (single #> cons shallow) |
|
66 |
|> (op @) |
|
67 |
|> NameSpace.pack; |
|
68 |
||
69 |
fun dest_nsp nsp idf = |
|
70 |
let |
|
71 |
val idf' = NameSpace.unpack idf; |
|
72 |
val (idf'', idf_base) = split_last idf'; |
|
73 |
val (modl, shallow) = split_last idf''; |
|
74 |
in |
|
75 |
if nsp = shallow |
|
76 |
then (SOME o NameSpace.pack) (modl @ [idf_base]) |
|
77 |
else NONE |
|
78 |
end; |
|
79 |
||
20386 | 80 |
fun if_nsp nsp f idf = |
81 |
Option.map f (dest_nsp nsp idf); |
|
19956 | 82 |
|
83 |
||
18702 | 84 |
(* code generator basics *) |
18454 | 85 |
|
20386 | 86 |
type auxtab = (bool * string list option) * CodegenTheorems.thmtab; |
18865 | 87 |
type appgen = theory -> auxtab |
20105 | 88 |
-> (string * typ) * term list -> transact -> iterm * transact; |
18217 | 89 |
|
18702 | 90 |
val serializers = ref ( |
91 |
Symtab.empty |
|
92 |
|> Symtab.update ( |
|
93 |
#ml CodegenSerializer.serializers |
|
94 |
|> apsnd (fn seri => seri |
|
20183 | 95 |
nsp_dtcon |
20386 | 96 |
[[nsp_module], [nsp_class, nsp_tyco], [nsp_const, nsp_dtcon, nsp_class, nsp_mem, nsp_inst, nsp_instmem]] |
18702 | 97 |
) |
98 |
) |
|
99 |
|> Symtab.update ( |
|
100 |
#haskell CodegenSerializer.serializers |
|
101 |
|> apsnd (fn seri => seri |
|
19953
2f54a51f1801
class package refinements, slight code generation refinements
haftmann
parents:
19884
diff
changeset
|
102 |
(nsp_dtcon, [nsp_module, nsp_class, nsp_tyco, nsp_dtcon]) |
20386 | 103 |
[[nsp_module], [nsp_class], [nsp_tyco], [nsp_const, nsp_mem], [nsp_dtcon], [nsp_inst], [nsp_instmem]] |
18702 | 104 |
) |
105 |
) |
|
106 |
); |
|
18217 | 107 |
|
108 |
||
18454 | 109 |
(* theory data for code generator *) |
18217 | 110 |
|
18912 | 111 |
fun merge_opt _ (x1, NONE) = x1 |
112 |
| merge_opt _ (NONE, x2) = x2 |
|
113 |
| merge_opt eq (SOME x1, SOME x2) = |
|
114 |
if eq (x1, x2) then SOME x1 else error ("incompatible options during merge"); |
|
115 |
||
20105 | 116 |
type appgens = (int * (appgen * stamp)) Symtab.table |
18217 | 117 |
|
20386 | 118 |
fun merge_appgens (x : appgens * appgens) = |
20105 | 119 |
Symtab.merge (fn ((bounds1, (_, stamp1)), (bounds2, (_, stamp2))) => |
120 |
bounds1 = bounds2 andalso stamp1 = stamp2) x |
|
18217 | 121 |
|
18702 | 122 |
type target_data = { |
18865 | 123 |
syntax_class: string Symtab.table, |
18516 | 124 |
syntax_tyco: (itype CodegenSerializer.pretty_syntax * stamp) Symtab.table, |
20105 | 125 |
syntax_const: (iterm CodegenSerializer.pretty_syntax * stamp) Symtab.table |
18217 | 126 |
}; |
127 |
||
18865 | 128 |
fun map_target_data f { syntax_class, syntax_tyco, syntax_const } = |
18217 | 129 |
let |
18865 | 130 |
val (syntax_class, syntax_tyco, syntax_const) = |
131 |
f (syntax_class, syntax_tyco, syntax_const) |
|
132 |
in { |
|
133 |
syntax_class = syntax_class, |
|
134 |
syntax_tyco = syntax_tyco, |
|
135 |
syntax_const = syntax_const } : target_data |
|
18454 | 136 |
end; |
18217 | 137 |
|
18702 | 138 |
fun merge_target_data |
18865 | 139 |
({ syntax_class = syntax_class1, syntax_tyco = syntax_tyco1, syntax_const = syntax_const1 }, |
140 |
{ syntax_class = syntax_class2, syntax_tyco = syntax_tyco2, syntax_const = syntax_const2 }) = |
|
141 |
{ syntax_class = Symtab.merge (op =) (syntax_class1, syntax_class2), |
|
142 |
syntax_tyco = Symtab.merge (eq_snd (op =)) (syntax_tyco1, syntax_tyco2), |
|
18702 | 143 |
syntax_const = Symtab.merge (eq_snd (op =)) (syntax_const1, syntax_const2) } : target_data; |
18217 | 144 |
|
145 |
structure CodegenData = TheoryDataFun |
|
146 |
(struct |
|
19953
2f54a51f1801
class package refinements, slight code generation refinements
haftmann
parents:
19884
diff
changeset
|
147 |
val name = "Pure/codegen_package"; |
18217 | 148 |
type T = { |
149 |
modl: module, |
|
20105 | 150 |
appgens: appgens, |
18702 | 151 |
target_data: target_data Symtab.table |
18217 | 152 |
}; |
153 |
val empty = { |
|
154 |
modl = empty_module, |
|
20105 | 155 |
appgens = Symtab.empty, |
18702 | 156 |
target_data = |
18217 | 157 |
Symtab.empty |
18702 | 158 |
|> Symtab.fold (fn (target, _) => |
18865 | 159 |
Symtab.update (target, |
160 |
{ syntax_class = Symtab.empty, syntax_tyco = Symtab.empty, syntax_const = Symtab.empty }) |
|
18702 | 161 |
) (! serializers) |
18217 | 162 |
} : T; |
163 |
val copy = I; |
|
164 |
val extend = I; |
|
165 |
fun merge _ ( |
|
20105 | 166 |
{ modl = modl1, appgens = appgens1, |
20386 | 167 |
target_data = target_data1 }, |
20105 | 168 |
{ modl = modl2, appgens = appgens2, |
20386 | 169 |
target_data = target_data2 } |
18217 | 170 |
) = { |
171 |
modl = merge_module (modl1, modl2), |
|
20105 | 172 |
appgens = merge_appgens (appgens1, appgens2), |
19025 | 173 |
target_data = Symtab.join (K merge_target_data) (target_data1, target_data2) |
18217 | 174 |
}; |
19341
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19283
diff
changeset
|
175 |
fun print thy (data : T) = |
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19283
diff
changeset
|
176 |
let |
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19283
diff
changeset
|
177 |
val module = #modl data |
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19283
diff
changeset
|
178 |
in |
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19283
diff
changeset
|
179 |
(Pretty.writeln o Pretty.chunks) [pretty_module module, pretty_deps module] |
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19283
diff
changeset
|
180 |
end; |
18217 | 181 |
end); |
182 |
||
18708 | 183 |
val _ = Context.add_setup CodegenData.init; |
184 |
||
18217 | 185 |
fun map_codegen_data f thy = |
186 |
case CodegenData.get thy |
|
20386 | 187 |
of { modl, appgens, target_data } => |
188 |
let val (modl, appgens, target_data) = |
|
189 |
f (modl, appgens, target_data) |
|
20105 | 190 |
in CodegenData.put { modl = modl, appgens = appgens, |
20386 | 191 |
target_data = target_data } thy end; |
18217 | 192 |
|
19341
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19283
diff
changeset
|
193 |
val print_code = CodegenData.print; |
18217 | 194 |
|
20386 | 195 |
val purge_code = map_codegen_data (fn (_, appgens, target_data) => |
196 |
(empty_module, appgens, target_data)); |
|
18454 | 197 |
|
18865 | 198 |
|
20386 | 199 |
(* name handling *) |
200 |
||
201 |
fun idf_of_class thy class = |
|
202 |
CodegenNames.class thy class |
|
203 |
|> add_nsp nsp_class; |
|
204 |
||
205 |
fun class_of_idf thy = if_nsp nsp_class (CodegenNames.class_rev thy); |
|
206 |
||
207 |
fun idf_of_tyco thy tyco = |
|
208 |
CodegenNames.tyco thy tyco |
|
209 |
|> add_nsp nsp_tyco; |
|
210 |
||
211 |
fun tyco_of_idf thy = if_nsp nsp_tyco (CodegenNames.tyco_rev thy); |
|
212 |
||
213 |
fun idf_of_inst thy inst = |
|
214 |
CodegenNames.instance thy inst |
|
215 |
|> add_nsp nsp_inst; |
|
216 |
||
217 |
fun inst_of_idf thy = if_nsp nsp_inst (CodegenNames.instance_rev thy); |
|
218 |
||
219 |
fun idf_of_const thy thmtab (c_ty as (c, ty)) = |
|
220 |
if is_some (CodegenTheorems.get_dtyp_of_cons thmtab c_ty) then |
|
221 |
CodegenNames.const thy c_ty |
|
222 |
|> add_nsp nsp_dtcon |
|
223 |
else if (is_some o CodegenConsts.class_of_classop thy o CodegenConsts.typinst_of_typ thy) c_ty then |
|
224 |
CodegenNames.const thy c_ty |
|
225 |
|> add_nsp nsp_mem |
|
226 |
else |
|
227 |
CodegenNames.const thy c_ty |
|
228 |
|> add_nsp nsp_const; |
|
229 |
||
230 |
fun const_of_idf thy idf = |
|
231 |
case dest_nsp nsp_const idf |
|
232 |
of SOME c => CodegenNames.const_rev thy c |> SOME |
|
233 |
| _ => (case dest_nsp nsp_dtcon idf |
|
234 |
of SOME c => CodegenNames.const_rev thy c |> SOME |
|
235 |
| _ => (case dest_nsp nsp_mem idf |
|
236 |
of SOME c => CodegenNames.const_rev thy c |> SOME |
|
237 |
| _ => NONE)); |
|
238 |
||
239 |
||
240 |
(* application generators *) |
|
18865 | 241 |
|
20105 | 242 |
fun gen_add_appconst prep_const (raw_c, appgen) thy = |
18454 | 243 |
let |
18865 | 244 |
val c = prep_const thy raw_c; |
20105 | 245 |
val i = (length o fst o strip_type o Sign.the_const_type thy) c |
18865 | 246 |
in map_codegen_data |
20386 | 247 |
(fn (modl, appgens, target_data) => |
18865 | 248 |
(modl, |
20105 | 249 |
appgens |> Symtab.update (c, (i, (appgen, stamp ()))), |
20386 | 250 |
target_data)) thy |
18454 | 251 |
end; |
18217 | 252 |
|
18865 | 253 |
val add_appconst = gen_add_appconst Sign.intern_const; |
254 |
val add_appconst_i = gen_add_appconst (K I); |
|
255 |
||
256 |
||
20386 | 257 |
(* extraction kernel *) |
18865 | 258 |
|
20386 | 259 |
fun check_strict thy f x ((false, _), _) = |
19884 | 260 |
false |
20386 | 261 |
| check_strict thy f x ((_, SOME targets), _) = |
19884 | 262 |
exists ( |
263 |
is_none o (fn tab => Symtab.lookup tab x) o f o the o (Symtab.lookup ((#target_data o CodegenData.get) thy)) |
|
264 |
) targets |
|
20386 | 265 |
| check_strict thy f x ((true, _), _) = |
19884 | 266 |
true; |
267 |
||
20386 | 268 |
fun no_strict ((_, targets), thmtab) = ((false, targets), thmtab); |
269 |
||
270 |
fun sortlookups_const thy thmtab (c, typ_ctxt) = |
|
271 |
let |
|
272 |
val typ_decl = case CodegenTheorems.get_fun_thms thmtab (c, typ_ctxt) |
|
273 |
of thms as thm :: _ => CodegenTheorems.extr_typ thy thm |
|
274 |
| [] => (case AxClass.class_of_param thy c |
|
275 |
of SOME class => (case ClassPackage.the_consts_sign thy class of (v, cs) => |
|
276 |
(Logic.varifyT o map_type_tfree (fn u as (w, _) => |
|
277 |
if w = v then TFree (v, [class]) else TFree u)) |
|
278 |
((the o AList.lookup (op =) cs) c)) |
|
279 |
| NONE => Sign.the_const_type thy c); |
|
280 |
in |
|
281 |
Vartab.empty |
|
282 |
|> Sign.typ_match thy (typ_decl, typ_ctxt) |
|
283 |
|> Vartab.dest |
|
284 |
|> map_filter (fn (_, ([], _)) => NONE |
|
285 |
| (_, (sort, ty)) => SOME (ClassPackage.sortlookup thy (ty, sort))) |
|
286 |
|> filter_out null |
|
287 |
end; |
|
19816
a8c8ed1c85e0
removed 'primitive definitions' added (non)strict generation, minor fixes
haftmann
parents:
19806
diff
changeset
|
288 |
|
18865 | 289 |
fun ensure_def_class thy tabs cls trns = |
18454 | 290 |
let |
20386 | 291 |
fun defgen_class thy (tabs as (_, thmtab)) cls trns = |
292 |
case class_of_idf thy cls |
|
18865 | 293 |
of SOME cls => |
294 |
let |
|
19283 | 295 |
val (v, cs) = (ClassPackage.the_consts_sign thy) cls; |
19953
2f54a51f1801
class package refinements, slight code generation refinements
haftmann
parents:
19884
diff
changeset
|
296 |
val sortctxts = map (ClassPackage.sortcontext_of_typ thy o snd) cs; |
20386 | 297 |
val idfs = map (idf_of_const thy thmtab) cs; |
18865 | 298 |
in |
299 |
trns |
|
19341
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19283
diff
changeset
|
300 |
|> debug_msg (fn _ => "trying defgen class declaration for " ^ quote cls) |
18865 | 301 |
|> fold_map (ensure_def_class thy tabs) (ClassPackage.the_superclasses thy cls) |
19816
a8c8ed1c85e0
removed 'primitive definitions' added (non)strict generation, minor fixes
haftmann
parents:
19806
diff
changeset
|
302 |
||>> (fold_map (exprgen_type thy tabs) o map snd) cs |
18865 | 303 |
||>> (fold_map o fold_map) (exprgen_tyvar_sort thy tabs) sortctxts |
304 |
|-> (fn ((supcls, memtypes), sortctxts) => succeed |
|
19283 | 305 |
(Class (supcls, (unprefix "'" v, idfs ~~ (sortctxts ~~ memtypes))))) |
18865 | 306 |
end |
307 |
| _ => |
|
308 |
trns |
|
309 |
|> fail ("no class definition found for " ^ quote cls); |
|
20386 | 310 |
val cls' = idf_of_class thy cls; |
18454 | 311 |
in |
312 |
trns |
|
19341
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19283
diff
changeset
|
313 |
|> debug_msg (fn _ => "generating class " ^ quote cls) |
19816
a8c8ed1c85e0
removed 'primitive definitions' added (non)strict generation, minor fixes
haftmann
parents:
19806
diff
changeset
|
314 |
|> ensure_def (defgen_class thy tabs) true ("generating class " ^ quote cls) cls' |
18865 | 315 |
|> pair cls' |
316 |
end |
|
20386 | 317 |
and ensure_def_tyco thy (tabs as (_, thmtab)) tyco trns = |
18865 | 318 |
let |
20386 | 319 |
val tyco' = idf_of_tyco thy tyco; |
19816
a8c8ed1c85e0
removed 'primitive definitions' added (non)strict generation, minor fixes
haftmann
parents:
19806
diff
changeset
|
320 |
val strict = check_strict thy #syntax_tyco tyco' tabs; |
20386 | 321 |
fun defgen_datatype thy (tabs as (_, thmtab)) dtco trns = |
322 |
case tyco_of_idf thy dtco |
|
18963 | 323 |
of SOME dtco => |
20353 | 324 |
(case CodegenTheorems.get_dtyp_spec thmtab dtco |
325 |
of SOME (vars, cos) => |
|
19341
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19283
diff
changeset
|
326 |
trns |
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19283
diff
changeset
|
327 |
|> debug_msg (fn _ => "trying defgen datatype for " ^ quote dtco) |
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19283
diff
changeset
|
328 |
|> fold_map (exprgen_tyvar_sort thy tabs) vars |
19816
a8c8ed1c85e0
removed 'primitive definitions' added (non)strict generation, minor fixes
haftmann
parents:
19806
diff
changeset
|
329 |
||>> fold_map (fn (c, tys) => |
a8c8ed1c85e0
removed 'primitive definitions' added (non)strict generation, minor fixes
haftmann
parents:
19806
diff
changeset
|
330 |
fold_map (exprgen_type thy tabs) tys |
20386 | 331 |
#-> (fn tys' => pair (idf_of_const thy thmtab (c, tys ---> Type (dtco, map TFree vars)), tys'))) cos |
19341
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19283
diff
changeset
|
332 |
|-> (fn (vars, cos) => succeed (Datatype |
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19283
diff
changeset
|
333 |
(vars, cos))) |
18963 | 334 |
| NONE => |
335 |
trns |
|
336 |
|> fail ("no datatype found for " ^ quote dtco)) |
|
337 |
| NONE => |
|
338 |
trns |
|
339 |
|> fail ("not a type constructor: " ^ quote dtco) |
|
18865 | 340 |
in |
341 |
trns |
|
19341
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19283
diff
changeset
|
342 |
|> debug_msg (fn _ => "generating type constructor " ^ quote tyco) |
19816
a8c8ed1c85e0
removed 'primitive definitions' added (non)strict generation, minor fixes
haftmann
parents:
19806
diff
changeset
|
343 |
|> ensure_def (defgen_datatype thy tabs) strict ("generating type constructor " ^ quote tyco) tyco' |
18865 | 344 |
|> pair tyco' |
345 |
end |
|
346 |
and exprgen_tyvar_sort thy tabs (v, sort) trns = |
|
18516 | 347 |
trns |
18885 | 348 |
|> fold_map (ensure_def_class thy tabs) (ClassPackage.operational_sort_of thy sort) |
18865 | 349 |
|-> (fn sort => pair (unprefix "'" v, sort)) |
350 |
and exprgen_type thy tabs (TVar _) trns = |
|
18516 | 351 |
error "TVar encountered during code generation" |
18702 | 352 |
| exprgen_type thy tabs (TFree v_s) trns = |
18516 | 353 |
trns |
18702 | 354 |
|> exprgen_tyvar_sort thy tabs v_s |
19167
f237c0cb3882
refined representation of codegen intermediate language
haftmann
parents:
19150
diff
changeset
|
355 |
|-> (fn (v, sort) => pair (ITyVar v)) |
18516 | 356 |
| exprgen_type thy tabs (Type ("fun", [t1, t2])) trns = |
357 |
trns |
|
358 |
|> exprgen_type thy tabs t1 |
|
359 |
||>> exprgen_type thy tabs t2 |
|
360 |
|-> (fn (t1', t2') => pair (t1' `-> t2')) |
|
361 |
| exprgen_type thy tabs (Type (tyco, tys)) trns = |
|
362 |
trns |
|
363 |
|> ensure_def_tyco thy tabs tyco |
|
364 |
||>> fold_map (exprgen_type thy tabs) tys |
|
19816
a8c8ed1c85e0
removed 'primitive definitions' added (non)strict generation, minor fixes
haftmann
parents:
19806
diff
changeset
|
365 |
|-> (fn (tyco, tys) => pair (tyco `%% tys)); |
18516 | 366 |
|
18885 | 367 |
fun exprgen_classlookup thy tabs (ClassPackage.Instance (inst, ls)) trns = |
18517 | 368 |
trns |
18885 | 369 |
|> ensure_def_inst thy tabs inst |
370 |
||>> (fold_map o fold_map) (exprgen_classlookup thy tabs) ls |
|
371 |
|-> (fn (inst, ls) => pair (Instance (inst, ls))) |
|
19253 | 372 |
| exprgen_classlookup thy tabs (ClassPackage.Lookup (clss, (v, (i, j)))) trns = |
18516 | 373 |
trns |
18517 | 374 |
|> fold_map (ensure_def_class thy tabs) clss |
19253 | 375 |
|-> (fn clss => pair (Lookup (clss, (v |> unprefix "'", if j = 1 then ~1 else i)))) |
20386 | 376 |
and mk_fun thy (tabs as (_, thmtab)) (c, ty) trns = |
377 |
case CodegenTheorems.get_fun_thms thmtab (c, ty) |
|
19953
2f54a51f1801
class package refinements, slight code generation refinements
haftmann
parents:
19884
diff
changeset
|
378 |
of eq_thms as eq_thm :: _ => |
18865 | 379 |
let |
19884 | 380 |
val msg = cat_lines ("generating code for theorems " :: map string_of_thm eq_thms); |
20386 | 381 |
val ty = (Logic.unvarifyT o CodegenTheorems.extr_typ thy) eq_thm |
19953
2f54a51f1801
class package refinements, slight code generation refinements
haftmann
parents:
19884
diff
changeset
|
382 |
val sortcontext = ClassPackage.sortcontext_of_typ thy ty; |
18865 | 383 |
fun dest_eqthm eq_thm = |
384 |
let |
|
385 |
val ((t, args), rhs) = |
|
19953
2f54a51f1801
class package refinements, slight code generation refinements
haftmann
parents:
19884
diff
changeset
|
386 |
(apfst strip_comb o Logic.dest_equals o Logic.legacy_unvarify o prop_of) eq_thm; |
18865 | 387 |
in case t |
388 |
of Const (c', _) => if c' = c then (args, rhs) |
|
389 |
else error ("illegal function equation for " ^ quote c |
|
390 |
^ ", actually defining " ^ quote c') |
|
391 |
| _ => error ("illegal function equation for " ^ quote c) |
|
392 |
end; |
|
19816
a8c8ed1c85e0
removed 'primitive definitions' added (non)strict generation, minor fixes
haftmann
parents:
19806
diff
changeset
|
393 |
fun exprgen_eq (args, rhs) trns = |
a8c8ed1c85e0
removed 'primitive definitions' added (non)strict generation, minor fixes
haftmann
parents:
19806
diff
changeset
|
394 |
trns |
a8c8ed1c85e0
removed 'primitive definitions' added (non)strict generation, minor fixes
haftmann
parents:
19806
diff
changeset
|
395 |
|> fold_map (exprgen_term thy tabs) args |
19884 | 396 |
||>> exprgen_term thy tabs rhs; |
20105 | 397 |
fun checkvars (args, rhs) = |
398 |
if CodegenThingol.vars_distinct args then (args, rhs) |
|
399 |
else error ("repeated variables on left hand side of function") |
|
18865 | 400 |
in |
18517 | 401 |
trns |
19884 | 402 |
|> message msg (fn trns => trns |
19816
a8c8ed1c85e0
removed 'primitive definitions' added (non)strict generation, minor fixes
haftmann
parents:
19806
diff
changeset
|
403 |
|> fold_map (exprgen_eq o dest_eqthm) eq_thms |
20105 | 404 |
|-> (fn eqs => pair (map checkvars eqs)) |
19953
2f54a51f1801
class package refinements, slight code generation refinements
haftmann
parents:
19884
diff
changeset
|
405 |
||>> fold_map (exprgen_tyvar_sort thy tabs) sortcontext |
19816
a8c8ed1c85e0
removed 'primitive definitions' added (non)strict generation, minor fixes
haftmann
parents:
19806
diff
changeset
|
406 |
||>> exprgen_type thy tabs ty |
19953
2f54a51f1801
class package refinements, slight code generation refinements
haftmann
parents:
19884
diff
changeset
|
407 |
|-> (fn ((eqs, sortctxt), ty) => (pair o SOME) ((eqs, (sortctxt, ty)), map snd sortcontext))) |
18865 | 408 |
end |
19953
2f54a51f1801
class package refinements, slight code generation refinements
haftmann
parents:
19884
diff
changeset
|
409 |
| [] => (NONE, trns) |
20386 | 410 |
and ensure_def_inst thy tabs (cls, tyco) trns = |
18865 | 411 |
let |
20386 | 412 |
fun defgen_inst thy (tabs as (_, thmtab)) inst trns = |
413 |
case inst_of_idf thy inst |
|
19956 | 414 |
of SOME (class, tyco) => |
18865 | 415 |
let |
18885 | 416 |
val (arity, memdefs) = ClassPackage.the_inst_sign thy (class, tyco); |
20386 | 417 |
val (_, memnames) = ClassPackage.the_consts_sign thy class; |
19953
2f54a51f1801
class package refinements, slight code generation refinements
haftmann
parents:
19884
diff
changeset
|
418 |
val arity_typ = Type (tyco, (map TFree arity)); |
2f54a51f1801
class package refinements, slight code generation refinements
haftmann
parents:
19884
diff
changeset
|
419 |
val operational_arity = map_filter (fn (v, sort) => case ClassPackage.operational_sort_of thy sort |
2f54a51f1801
class package refinements, slight code generation refinements
haftmann
parents:
19884
diff
changeset
|
420 |
of [] => NONE |
2f54a51f1801
class package refinements, slight code generation refinements
haftmann
parents:
19884
diff
changeset
|
421 |
| sort => SOME (v, sort)) arity; |
20386 | 422 |
fun mk_instmemname (m, ty) = |
423 |
NameSpace.append (NameSpace.append ((NameSpace.drop_base o NameSpace.drop_base) |
|
424 |
inst) nsp_instmem) (NameSpace.base (idf_of_const thy thmtab (m, ty))); |
|
18865 | 425 |
fun gen_suparity supclass trns = |
426 |
trns |
|
19136 | 427 |
|> ensure_def_class thy tabs supclass |
19953
2f54a51f1801
class package refinements, slight code generation refinements
haftmann
parents:
19884
diff
changeset
|
428 |
||>> fold_map (exprgen_classlookup thy tabs) |
20386 | 429 |
(ClassPackage.sortlookup thy (arity_typ, [supclass])); |
430 |
fun gen_membr ((m0, ty0), (m, ty)) trns = |
|
18865 | 431 |
trns |
19341
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19283
diff
changeset
|
432 |
|> mk_fun thy tabs (m, ty) |
19280
5091dc43817b
slight improvement in serializer, stub for code generator theorems added
haftmann
parents:
19253
diff
changeset
|
433 |
|-> (fn NONE => error ("could not derive definition for member " |
5091dc43817b
slight improvement in serializer, stub for code generator theorems added
haftmann
parents:
19253
diff
changeset
|
434 |
^ quote m ^ " :: " ^ Sign.string_of_typ thy ty) |
19953
2f54a51f1801
class package refinements, slight code generation refinements
haftmann
parents:
19884
diff
changeset
|
435 |
| SOME (funn, sorts) => fold_map (fn (sort, sort_ctxt) => |
2f54a51f1801
class package refinements, slight code generation refinements
haftmann
parents:
19884
diff
changeset
|
436 |
fold_map (exprgen_classlookup thy tabs) |
20386 | 437 |
(ClassPackage.sortlookup thy (TFree sort_ctxt, sort))) |
20191 | 438 |
(sorts ~~ operational_arity) |
19253 | 439 |
#-> (fn lss => |
20386 | 440 |
pair (idf_of_const thy thmtab (m0, ty0), |
441 |
((mk_instmemname (m0, ty0), funn), lss)))); |
|
18865 | 442 |
in |
443 |
trns |
|
19341
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19283
diff
changeset
|
444 |
|> debug_msg (fn _ => "trying defgen class instance for (" ^ quote cls |
18865 | 445 |
^ ", " ^ quote tyco ^ ")") |
18885 | 446 |
|> ensure_def_class thy tabs class |
18865 | 447 |
||>> ensure_def_tyco thy tabs tyco |
448 |
||>> fold_map (exprgen_tyvar_sort thy tabs) arity |
|
18885 | 449 |
||>> fold_map gen_suparity (ClassPackage.the_superclasses thy class) |
20386 | 450 |
||>> fold_map gen_membr (memnames ~~ memdefs) |
18885 | 451 |
|-> (fn ((((class, tyco), arity), suparities), memdefs) => |
452 |
succeed (Classinst (((class, (tyco, arity)), suparities), memdefs))) |
|
18865 | 453 |
end |
454 |
| _ => |
|
455 |
trns |> fail ("no class instance found for " ^ quote inst); |
|
20386 | 456 |
val inst = idf_of_inst thy (cls, tyco); |
18865 | 457 |
in |
458 |
trns |
|
19341
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19283
diff
changeset
|
459 |
|> debug_msg (fn _ => "generating instance " ^ quote cls ^ " / " ^ quote tyco) |
19816
a8c8ed1c85e0
removed 'primitive definitions' added (non)strict generation, minor fixes
haftmann
parents:
19806
diff
changeset
|
460 |
|> ensure_def (defgen_inst thy tabs) true |
18865 | 461 |
("generating instance " ^ quote cls ^ " / " ^ quote tyco) inst |
462 |
|> pair inst |
|
463 |
end |
|
20386 | 464 |
and ensure_def_const thy (tabs as (_, thmtab)) (c, ty) trns = |
18865 | 465 |
let |
20386 | 466 |
fun defgen_datatypecons thy (tabs as (_, thmtab)) co trns = |
467 |
case CodegenTheorems.get_dtyp_of_cons thmtab ((the o const_of_idf thy) co) |
|
468 |
of SOME tyco => |
|
18865 | 469 |
trns |
19341
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19283
diff
changeset
|
470 |
|> debug_msg (fn _ => "trying defgen datatype constructor for " ^ quote co) |
20386 | 471 |
|> ensure_def_tyco thy tabs tyco |
472 |
|-> (fn _ => succeed Bot) |
|
18865 | 473 |
| _ => |
474 |
trns |
|
475 |
|> fail ("not a datatype constructor: " ^ quote co); |
|
20386 | 476 |
fun defgen_clsmem thy (tabs as (_, thmtab)) m trns = |
477 |
case CodegenConsts.class_of_classop thy |
|
478 |
((CodegenConsts.typinst_of_typ thy o the o const_of_idf thy) m) |
|
479 |
of SOME class => |
|
480 |
trns |
|
481 |
|> debug_msg (fn _ => "trying defgen class member for " ^ quote m) |
|
482 |
|> ensure_def_class thy tabs class |
|
483 |
|-> (fn _ => succeed Bot) |
|
484 |
| _ => |
|
485 |
trns |> fail ("no class found for " ^ quote m) |
|
486 |
fun defgen_funs thy (tabs as (_, thmtab)) c' trns = |
|
487 |
trns |
|
488 |
|> mk_fun thy tabs ((the o const_of_idf thy) c') |
|
489 |
|-> (fn SOME (funn, _) => succeed (Fun funn) |
|
490 |
| NONE => fail ("no defining equations found for " ^ |
|
491 |
(quote (c ^ " :: " ^ Sign.string_of_typ thy ty)))) |
|
19816
a8c8ed1c85e0
removed 'primitive definitions' added (non)strict generation, minor fixes
haftmann
parents:
19806
diff
changeset
|
492 |
fun get_defgen tabs idf strict = |
20386 | 493 |
if (is_some oo dest_nsp) nsp_const idf |
19816
a8c8ed1c85e0
removed 'primitive definitions' added (non)strict generation, minor fixes
haftmann
parents:
19806
diff
changeset
|
494 |
then defgen_funs thy tabs strict |
20386 | 495 |
else if (is_some oo dest_nsp) nsp_mem idf |
19816
a8c8ed1c85e0
removed 'primitive definitions' added (non)strict generation, minor fixes
haftmann
parents:
19806
diff
changeset
|
496 |
then defgen_clsmem thy tabs strict |
20386 | 497 |
else if (is_some oo dest_nsp) nsp_dtcon idf |
19816
a8c8ed1c85e0
removed 'primitive definitions' added (non)strict generation, minor fixes
haftmann
parents:
19806
diff
changeset
|
498 |
then defgen_datatypecons thy tabs strict |
18963 | 499 |
else error ("illegal shallow name space for constant: " ^ quote idf); |
20386 | 500 |
val idf = idf_of_const thy thmtab (c, ty); |
19816
a8c8ed1c85e0
removed 'primitive definitions' added (non)strict generation, minor fixes
haftmann
parents:
19806
diff
changeset
|
501 |
val strict = check_strict thy #syntax_const idf tabs; |
18865 | 502 |
in |
503 |
trns |
|
20353 | 504 |
|> debug_msg (fn _ => "generating constant " ^ (quote (c ^ " :: " ^ Sign.string_of_typ thy ty))) |
19816
a8c8ed1c85e0
removed 'primitive definitions' added (non)strict generation, minor fixes
haftmann
parents:
19806
diff
changeset
|
505 |
|> ensure_def (get_defgen tabs idf) strict ("generating constant " ^ quote c) idf |
18963 | 506 |
|> pair idf |
18865 | 507 |
end |
18517 | 508 |
and exprgen_term thy tabs (Const (f, ty)) trns = |
509 |
trns |
|
510 |
|> appgen thy tabs ((f, ty), []) |
|
18516 | 511 |
|-> (fn e => pair e) |
18912 | 512 |
| exprgen_term thy tabs (Var _) trns = |
513 |
error "Var encountered during code generation" |
|
18516 | 514 |
| exprgen_term thy tabs (Free (v, ty)) trns = |
515 |
trns |
|
18912 | 516 |
|> exprgen_type thy tabs ty |
19167
f237c0cb3882
refined representation of codegen intermediate language
haftmann
parents:
19150
diff
changeset
|
517 |
|-> (fn ty => pair (IVar v)) |
19967 | 518 |
| exprgen_term thy tabs (Abs (raw_v, ty, raw_t)) trns = |
19136 | 519 |
let |
20386 | 520 |
val (v, t) = Syntax.variant_abs (CodegenNames.purify_var raw_v, ty, raw_t); |
19136 | 521 |
in |
522 |
trns |
|
523 |
|> exprgen_type thy tabs ty |
|
524 |
||>> exprgen_term thy tabs t |
|
19167
f237c0cb3882
refined representation of codegen intermediate language
haftmann
parents:
19150
diff
changeset
|
525 |
|-> (fn (ty, e) => pair ((v, ty) `|-> e)) |
19136 | 526 |
end |
18516 | 527 |
| exprgen_term thy tabs (t as t1 $ t2) trns = |
528 |
let |
|
529 |
val (t', ts) = strip_comb t |
|
530 |
in case t' |
|
531 |
of Const (f, ty) => |
|
532 |
trns |
|
18517 | 533 |
|> appgen thy tabs ((f, ty), ts) |
18516 | 534 |
|-> (fn e => pair e) |
535 |
| _ => |
|
536 |
trns |
|
537 |
|> exprgen_term thy tabs t' |
|
538 |
||>> fold_map (exprgen_term thy tabs) ts |
|
539 |
|-> (fn (e, es) => pair (e `$$ es)) |
|
18865 | 540 |
end |
20386 | 541 |
and appgen_default thy (tabs as (_, thmtab)) ((c, ty), ts) trns = |
18865 | 542 |
trns |
543 |
|> ensure_def_const thy tabs (c, ty) |
|
19816
a8c8ed1c85e0
removed 'primitive definitions' added (non)strict generation, minor fixes
haftmann
parents:
19806
diff
changeset
|
544 |
||>> exprgen_type thy tabs ty |
18885 | 545 |
||>> (fold_map o fold_map) (exprgen_classlookup thy tabs) |
20386 | 546 |
(sortlookups_const thy thmtab (c, ty)) |
18912 | 547 |
||>> fold_map (exprgen_term thy tabs) ts |
19816
a8c8ed1c85e0
removed 'primitive definitions' added (non)strict generation, minor fixes
haftmann
parents:
19806
diff
changeset
|
548 |
|-> (fn (((c, ty), ls), es) => |
19202 | 549 |
pair (IConst (c, (ls, ty)) `$$ es)) |
18865 | 550 |
and appgen thy tabs ((f, ty), ts) trns = |
20105 | 551 |
case Symtab.lookup ((#appgens o CodegenData.get) thy) f |
552 |
of SOME (i, (ag, _)) => |
|
553 |
if length ts < i then |
|
18865 | 554 |
let |
20105 | 555 |
val tys = Library.take (i - length ts, ((fst o strip_type) ty)); |
20192
956cd30ef3be
renamed Name.give_names to Name.names and moved Name.alphanum to Symbol.alphanum
haftmann
parents:
20191
diff
changeset
|
556 |
val vs = Name.names (Name.declare f Name.context) "a" tys; |
18865 | 557 |
in |
558 |
trns |
|
18912 | 559 |
|> fold_map (exprgen_type thy tabs) tys |
20105 | 560 |
||>> ag thy tabs ((f, ty), ts @ map Free vs) |
561 |
|-> (fn (tys, e) => pair (map2 (fn (v, _) => pair v) vs tys `|--> e)) |
|
18865 | 562 |
end |
20105 | 563 |
else if length ts > i then |
18865 | 564 |
trns |
20105 | 565 |
|> ag thy tabs ((f, ty), Library.take (i, ts)) |
566 |
||>> fold_map (exprgen_term thy tabs) (Library.drop (i, ts)) |
|
19167
f237c0cb3882
refined representation of codegen intermediate language
haftmann
parents:
19150
diff
changeset
|
567 |
|-> (fn (e, es) => pair (e `$$ es)) |
18865 | 568 |
else |
569 |
trns |
|
570 |
|> ag thy tabs ((f, ty), ts) |
|
571 |
| NONE => |
|
572 |
trns |
|
573 |
|> appgen_default thy tabs ((f, ty), ts); |
|
18516 | 574 |
|
18702 | 575 |
|
18217 | 576 |
(* parametrized generators, for instantiation in HOL *) |
577 |
||
20353 | 578 |
fun appgen_rep_bin int_of_numeral thy tabs (app as (c as (_, ty), [bin])) trns = |
579 |
case try (int_of_numeral thy) bin |
|
580 |
of SOME i => if i < 0 then (*preprocessor eliminates negative numerals*) |
|
581 |
trns |
|
582 |
|> appgen_default thy (no_strict tabs) app |
|
19884 | 583 |
else |
584 |
trns |
|
20353 | 585 |
|> exprgen_term thy (no_strict tabs) (Const c) |
19884 | 586 |
||>> exprgen_term thy (no_strict tabs) bin |
20353 | 587 |
|-> (fn (e1, e2) => pair (CodegenThingol.INum (i, e1 `$ e2))) |
19884 | 588 |
| NONE => |
589 |
trns |
|
590 |
|> appgen_default thy tabs app; |
|
18217 | 591 |
|
19607
07eeb832f28d
introduced characters for code generator; some improved code lemmas for some list functions
haftmann
parents:
19597
diff
changeset
|
592 |
fun appgen_char char_to_index thy tabs (app as ((_, ty), _)) trns = |
07eeb832f28d
introduced characters for code generator; some improved code lemmas for some list functions
haftmann
parents:
19597
diff
changeset
|
593 |
case (char_to_index o list_comb o apfst Const) app |
07eeb832f28d
introduced characters for code generator; some improved code lemmas for some list functions
haftmann
parents:
19597
diff
changeset
|
594 |
of SOME i => |
07eeb832f28d
introduced characters for code generator; some improved code lemmas for some list functions
haftmann
parents:
19597
diff
changeset
|
595 |
trns |
07eeb832f28d
introduced characters for code generator; some improved code lemmas for some list functions
haftmann
parents:
19597
diff
changeset
|
596 |
|> exprgen_type thy tabs ty |
07eeb832f28d
introduced characters for code generator; some improved code lemmas for some list functions
haftmann
parents:
19597
diff
changeset
|
597 |
||>> appgen_default thy tabs app |
07eeb832f28d
introduced characters for code generator; some improved code lemmas for some list functions
haftmann
parents:
19597
diff
changeset
|
598 |
|-> (fn (_, e0) => pair (IChar (chr i, e0))) |
07eeb832f28d
introduced characters for code generator; some improved code lemmas for some list functions
haftmann
parents:
19597
diff
changeset
|
599 |
| NONE => |
07eeb832f28d
introduced characters for code generator; some improved code lemmas for some list functions
haftmann
parents:
19597
diff
changeset
|
600 |
trns |
07eeb832f28d
introduced characters for code generator; some improved code lemmas for some list functions
haftmann
parents:
19597
diff
changeset
|
601 |
|> appgen_default thy tabs app; |
07eeb832f28d
introduced characters for code generator; some improved code lemmas for some list functions
haftmann
parents:
19597
diff
changeset
|
602 |
|
20105 | 603 |
fun appgen_case dest_case_expr thy tabs (app as (c_ty, ts)) trns = |
604 |
let |
|
605 |
val SOME ([], ((st, sty), ds)) = dest_case_expr thy (list_comb (Const c_ty, ts)); |
|
606 |
fun clausegen (dt, bt) trns = |
|
607 |
trns |
|
608 |
|> exprgen_term thy tabs dt |
|
609 |
||>> exprgen_term thy tabs bt; |
|
610 |
in |
|
611 |
trns |
|
612 |
|> exprgen_term thy tabs st |
|
613 |
||>> exprgen_type thy tabs sty |
|
614 |
||>> fold_map clausegen ds |
|
615 |
||>> appgen_default thy tabs app |
|
616 |
|-> (fn (((se, sty), ds), e0) => pair (ICase (((se, sty), ds), e0))) |
|
617 |
end; |
|
618 |
||
619 |
fun appgen_let thy tabs (app as (_, [st, ct])) trns = |
|
620 |
trns |
|
621 |
|> exprgen_term thy tabs ct |
|
622 |
||>> exprgen_term thy tabs st |
|
623 |
||>> appgen_default thy tabs app |
|
624 |
|-> (fn (((v, ty) `|-> be, se), e0) => |
|
625 |
pair (ICase (((se, ty), case be |
|
626 |
of ICase (((IVar w, _), ds), _) => if v = w then ds else [(IVar v, be)] |
|
627 |
| _ => [(IVar v, be)] |
|
628 |
), e0)) |
|
629 |
| (_, e0) => pair e0); |
|
630 |
||
20386 | 631 |
fun appgen_wfrec thy (tabs as (_, thmtab)) ((c, ty), [_, tf, tx]) trns = |
19038 | 632 |
let |
20386 | 633 |
val ty_def = (op ---> o apfst tl o strip_type o Logic.unvarifyT o Sign.the_const_type thy) c; |
19038 | 634 |
val ty' = (op ---> o apfst tl o strip_type) ty; |
20386 | 635 |
val idf = idf_of_const thy thmtab (c, ty); |
19038 | 636 |
in |
637 |
trns |
|
20386 | 638 |
|> ensure_def ((K o fail) "no extraction for wfrec") false ("generating wfrec") idf |
19136 | 639 |
|> exprgen_type thy tabs ty' |
640 |
||>> (fold_map o fold_map) (exprgen_classlookup thy tabs) |
|
20386 | 641 |
(sortlookups_const thy thmtab (c, ty)) |
19816
a8c8ed1c85e0
removed 'primitive definitions' added (non)strict generation, minor fixes
haftmann
parents:
19806
diff
changeset
|
642 |
||>> exprgen_type thy tabs ty_def |
19136 | 643 |
||>> exprgen_term thy tabs tf |
644 |
||>> exprgen_term thy tabs tx |
|
19816
a8c8ed1c85e0
removed 'primitive definitions' added (non)strict generation, minor fixes
haftmann
parents:
19806
diff
changeset
|
645 |
|-> (fn ((((_, ls), ty), tf), tx) => pair (IConst (idf, (ls, ty)) `$ tf `$ tx)) |
19038 | 646 |
end; |
647 |
||
18217 | 648 |
|
18516 | 649 |
|
650 |
(** theory interface **) |
|
18217 | 651 |
|
20353 | 652 |
fun mk_tabs thy targets cs = |
20386 | 653 |
((true, targets), CodegenTheorems.mk_thmtab thy cs); |
18217 | 654 |
|
18756 | 655 |
fun get_serializer target = |
656 |
case Symtab.lookup (!serializers) target |
|
657 |
of SOME seri => seri |
|
19008 | 658 |
| NONE => Scan.fail_with (fn _ => "unknown code target language: " ^ quote target) (); |
18335 | 659 |
|
18516 | 660 |
fun map_module f = |
20386 | 661 |
map_codegen_data (fn (modl, gens, target_data) => |
662 |
(f modl, gens, target_data)); |
|
18516 | 663 |
|
19884 | 664 |
fun purge_defs NONE thy = |
19341
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19283
diff
changeset
|
665 |
map_module (K CodegenThingol.empty_module) thy |
20191 | 666 |
| purge_defs (SOME []) thy = |
667 |
thy |
|
19884 | 668 |
| purge_defs (SOME cs) thy = |
20191 | 669 |
map_module (K CodegenThingol.empty_module) thy; |
670 |
(*let |
|
19816
a8c8ed1c85e0
removed 'primitive definitions' added (non)strict generation, minor fixes
haftmann
parents:
19806
diff
changeset
|
671 |
val tabs = mk_tabs thy NONE; |
19884 | 672 |
val idfs = map (idf_of_const' thy tabs) cs; |
673 |
fun purge idfs modl = |
|
674 |
CodegenThingol.purge_module (filter (can (get_def modl)) idfs) modl |
|
19341
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19283
diff
changeset
|
675 |
in |
19884 | 676 |
map_module (purge idfs) thy |
20191 | 677 |
end;*) |
19341
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19283
diff
changeset
|
678 |
|
20353 | 679 |
fun expand_module targets cs init gen arg thy = |
19597 | 680 |
thy |
681 |
|> CodegenTheorems.notify_dirty |
|
682 |
|> `(#modl o CodegenData.get) |
|
683 |
|> (fn (modl, thy) => |
|
20353 | 684 |
(start_transact init (gen thy (mk_tabs thy targets cs) arg) modl, thy)) |
19597 | 685 |
|-> (fn (x, modl) => map_module (K modl) #> pair x); |
18516 | 686 |
|
20353 | 687 |
fun consts_of t = |
688 |
fold_aterms (fn Const c => cons c | _ => I) t []; |
|
689 |
||
20105 | 690 |
fun codegen_term t thy = |
20353 | 691 |
let |
692 |
val _ = Thm.cterm_of thy t; |
|
693 |
(* val _ = writeln "STARTING GENERATION"; *) |
|
694 |
(* val _ = (writeln o Sign.string_of_term thy) t; *) |
|
695 |
in |
|
696 |
thy |
|
697 |
|> expand_module (SOME [] (*(Symtab.keys (#target_data (CodegenData.get thy)))*)) (consts_of t) NONE exprgen_term t |
|
698 |
end; |
|
19136 | 699 |
|
700 |
val is_dtcon = has_nsp nsp_dtcon; |
|
701 |
||
702 |
fun consts_of_idfs thy = |
|
20386 | 703 |
map (the o const_of_idf thy); |
19150 | 704 |
|
20353 | 705 |
fun idfs_of_consts thy cs = |
20386 | 706 |
map (idf_of_const thy (snd (mk_tabs thy NONE cs))) cs; |
19150 | 707 |
|
19967 | 708 |
fun get_root_module thy = |
709 |
thy |
|
710 |
|> CodegenTheorems.notify_dirty |
|
711 |
|> `(#modl o CodegenData.get); |
|
19042
630b8dd0b31a
exported some interfaces useful for other code generator approaches
haftmann
parents:
19038
diff
changeset
|
712 |
|
20213 | 713 |
fun eval_term (ref_spec, t) thy = |
714 |
let |
|
715 |
val target_data = |
|
716 |
((fn data => (the o Symtab.lookup data) "ml") o #target_data o CodegenData.get) thy; |
|
20386 | 717 |
val eval = CodegenSerializer.eval_term nsp_eval nsp_dtcon [[nsp_module], [nsp_class, nsp_tyco], [nsp_const, nsp_dtcon, nsp_class, nsp_mem, nsp_inst, nsp_instmem], [nsp_eval]] |
20213 | 718 |
((Option.map fst oo Symtab.lookup) (#syntax_tyco target_data), |
719 |
(Option.map fst oo Symtab.lookup) (#syntax_const target_data)) |
|
720 |
(Symtab.keys (#syntax_tyco target_data) @ Symtab.keys (#syntax_const target_data)) |
|
721 |
in |
|
722 |
thy |
|
723 |
|> codegen_term t |
|
724 |
||>> `(#modl o CodegenData.get) |
|
725 |
|-> (fn (t', modl) => `(fn _ => eval (ref_spec, t') modl)) |
|
726 |
end; |
|
727 |
||
19042
630b8dd0b31a
exported some interfaces useful for other code generator approaches
haftmann
parents:
19038
diff
changeset
|
728 |
fun get_ml_fun_datatype thy resolv = |
630b8dd0b31a
exported some interfaces useful for other code generator approaches
haftmann
parents:
19038
diff
changeset
|
729 |
let |
19150 | 730 |
val target_data = |
19042
630b8dd0b31a
exported some interfaces useful for other code generator approaches
haftmann
parents:
19038
diff
changeset
|
731 |
((fn data => (the o Symtab.lookup data) "ml") o #target_data o CodegenData.get) thy; |
630b8dd0b31a
exported some interfaces useful for other code generator approaches
haftmann
parents:
19038
diff
changeset
|
732 |
in |
20183 | 733 |
CodegenSerializer.ml_fun_datatype nsp_dtcon |
19042
630b8dd0b31a
exported some interfaces useful for other code generator approaches
haftmann
parents:
19038
diff
changeset
|
734 |
((Option.map fst oo Symtab.lookup o #syntax_tyco) target_data, |
630b8dd0b31a
exported some interfaces useful for other code generator approaches
haftmann
parents:
19038
diff
changeset
|
735 |
(Option.map fst oo Symtab.lookup o #syntax_const) target_data) |
630b8dd0b31a
exported some interfaces useful for other code generator approaches
haftmann
parents:
19038
diff
changeset
|
736 |
resolv |
630b8dd0b31a
exported some interfaces useful for other code generator approaches
haftmann
parents:
19038
diff
changeset
|
737 |
end; |
18516 | 738 |
|
739 |
||
740 |
(** target languages **) |
|
741 |
||
19816
a8c8ed1c85e0
removed 'primitive definitions' added (non)strict generation, minor fixes
haftmann
parents:
19806
diff
changeset
|
742 |
(* syntax *) |
18516 | 743 |
|
18702 | 744 |
fun read_typ thy = |
745 |
Sign.read_typ (thy, K NONE); |
|
746 |
||
20353 | 747 |
fun read_quote get reader consts_of gen raw thy = |
748 |
let |
|
749 |
val it = reader thy raw; |
|
750 |
val cs = consts_of it; |
|
751 |
in |
|
752 |
thy |
|
753 |
|> expand_module (SOME (Symtab.keys (#target_data (CodegenData.get thy)))) cs ((SOME o get) thy) |
|
754 |
(fn thy => fn tabs => gen thy tabs) [it] |
|
755 |
|-> (fn [x] => pair x) |
|
756 |
end; |
|
18702 | 757 |
|
18865 | 758 |
fun gen_add_syntax_class prep_class class target pretty thy = |
759 |
thy |
|
760 |
|> map_codegen_data |
|
20386 | 761 |
(fn (modl, gens, target_data) => |
18865 | 762 |
(modl, gens, |
763 |
target_data |> Symtab.map_entry target |
|
764 |
(map_target_data |
|
765 |
(fn (syntax_class, syntax_tyco, syntax_const) => |
|
766 |
(syntax_class |
|
20386 | 767 |
|> Symtab.update (prep_class thy class, pretty), syntax_tyco, syntax_const))))); |
18865 | 768 |
|
769 |
val add_syntax_class = gen_add_syntax_class Sign.intern_class; |
|
770 |
||
18963 | 771 |
fun parse_syntax_tyco raw_tyco = |
18217 | 772 |
let |
19042
630b8dd0b31a
exported some interfaces useful for other code generator approaches
haftmann
parents:
19038
diff
changeset
|
773 |
fun prep_tyco thy raw_tyco = |
630b8dd0b31a
exported some interfaces useful for other code generator approaches
haftmann
parents:
19038
diff
changeset
|
774 |
raw_tyco |
18963 | 775 |
|> Sign.intern_type thy |
20386 | 776 |
|> idf_of_tyco thy; |
19042
630b8dd0b31a
exported some interfaces useful for other code generator approaches
haftmann
parents:
19038
diff
changeset
|
777 |
fun no_args_tyco thy raw_tyco = |
630b8dd0b31a
exported some interfaces useful for other code generator approaches
haftmann
parents:
19038
diff
changeset
|
778 |
AList.lookup (op =) ((NameSpace.dest_table o #types o Type.rep_tsig o Sign.tsig_of) thy) |
630b8dd0b31a
exported some interfaces useful for other code generator approaches
haftmann
parents:
19038
diff
changeset
|
779 |
(Sign.intern_type thy raw_tyco) |
630b8dd0b31a
exported some interfaces useful for other code generator approaches
haftmann
parents:
19038
diff
changeset
|
780 |
|> (fn SOME ((Type.LogicalType i), _) => i); |
18963 | 781 |
fun mk reader target thy = |
18702 | 782 |
let |
18756 | 783 |
val _ = get_serializer target; |
18702 | 784 |
val tyco = prep_tyco thy raw_tyco; |
785 |
in |
|
786 |
thy |
|
787 |
|> reader |
|
788 |
|-> (fn pretty => map_codegen_data |
|
20386 | 789 |
(fn (modl, gens, target_data) => |
18702 | 790 |
(modl, gens, |
791 |
target_data |> Symtab.map_entry target |
|
792 |
(map_target_data |
|
18865 | 793 |
(fn (syntax_class, syntax_tyco, syntax_const) => |
794 |
(syntax_class, syntax_tyco |> Symtab.update |
|
18702 | 795 |
(tyco, (pretty, stamp ())), |
20386 | 796 |
syntax_const)))))) |
18702 | 797 |
end; |
18217 | 798 |
in |
19042
630b8dd0b31a
exported some interfaces useful for other code generator approaches
haftmann
parents:
19038
diff
changeset
|
799 |
CodegenSerializer.parse_syntax (fn thy => no_args_tyco thy raw_tyco) |
20353 | 800 |
(read_quote (fn thy => prep_tyco thy raw_tyco) read_typ (K []) |
19816
a8c8ed1c85e0
removed 'primitive definitions' added (non)strict generation, minor fixes
haftmann
parents:
19806
diff
changeset
|
801 |
(fn thy => fn tabs => fold_map (exprgen_type thy tabs))) |
18702 | 802 |
#-> (fn reader => pair (mk reader)) |
18217 | 803 |
end; |
804 |
||
18704
2c86ced392a8
substantial improvement in serialization handling
haftmann
parents:
18702
diff
changeset
|
805 |
fun add_pretty_syntax_const c target pretty = |
2c86ced392a8
substantial improvement in serialization handling
haftmann
parents:
18702
diff
changeset
|
806 |
map_codegen_data |
20386 | 807 |
(fn (modl, gens, target_data) => |
18704
2c86ced392a8
substantial improvement in serialization handling
haftmann
parents:
18702
diff
changeset
|
808 |
(modl, gens, |
2c86ced392a8
substantial improvement in serialization handling
haftmann
parents:
18702
diff
changeset
|
809 |
target_data |> Symtab.map_entry target |
2c86ced392a8
substantial improvement in serialization handling
haftmann
parents:
18702
diff
changeset
|
810 |
(map_target_data |
18865 | 811 |
(fn (syntax_class, syntax_tyco, syntax_const) => |
812 |
(syntax_class, syntax_tyco, |
|
18704
2c86ced392a8
substantial improvement in serialization handling
haftmann
parents:
18702
diff
changeset
|
813 |
syntax_const |
2c86ced392a8
substantial improvement in serialization handling
haftmann
parents:
18702
diff
changeset
|
814 |
|> Symtab.update |
20386 | 815 |
(c, (pretty, stamp ()))))))); |
18704
2c86ced392a8
substantial improvement in serialization handling
haftmann
parents:
18702
diff
changeset
|
816 |
|
18963 | 817 |
fun parse_syntax_const raw_const = |
18217 | 818 |
let |
18963 | 819 |
fun prep_const thy raw_const = |
20353 | 820 |
let |
20386 | 821 |
val c_ty = CodegenConsts.read_const_typ thy raw_const |
822 |
in idf_of_const thy (snd (mk_tabs thy NONE [c_ty])) c_ty end; |
|
19042
630b8dd0b31a
exported some interfaces useful for other code generator approaches
haftmann
parents:
19038
diff
changeset
|
823 |
fun no_args_const thy raw_const = |
20386 | 824 |
(length o fst o strip_type o snd o CodegenConsts.read_const_typ thy) raw_const; |
18963 | 825 |
fun mk reader target thy = |
18702 | 826 |
let |
18756 | 827 |
val _ = get_serializer target; |
18963 | 828 |
val c = prep_const thy raw_const; |
18702 | 829 |
in |
830 |
thy |
|
831 |
|> reader |
|
18704
2c86ced392a8
substantial improvement in serialization handling
haftmann
parents:
18702
diff
changeset
|
832 |
|-> (fn pretty => add_pretty_syntax_const c target pretty) |
18702 | 833 |
end; |
18217 | 834 |
in |
19042
630b8dd0b31a
exported some interfaces useful for other code generator approaches
haftmann
parents:
19038
diff
changeset
|
835 |
CodegenSerializer.parse_syntax (fn thy => no_args_const thy raw_const) |
20353 | 836 |
(read_quote (fn thy => prep_const thy raw_const) Sign.read_term consts_of |
19816
a8c8ed1c85e0
removed 'primitive definitions' added (non)strict generation, minor fixes
haftmann
parents:
19806
diff
changeset
|
837 |
(fn thy => fn tabs => fold_map (exprgen_term thy tabs))) |
18702 | 838 |
#-> (fn reader => pair (mk reader)) |
18217 | 839 |
end; |
840 |
||
18704
2c86ced392a8
substantial improvement in serialization handling
haftmann
parents:
18702
diff
changeset
|
841 |
fun add_pretty_list raw_nil raw_cons (target, seri) thy = |
2c86ced392a8
substantial improvement in serialization handling
haftmann
parents:
18702
diff
changeset
|
842 |
let |
18756 | 843 |
val _ = get_serializer target; |
20353 | 844 |
fun prep_const raw = |
18704
2c86ced392a8
substantial improvement in serialization handling
haftmann
parents:
18702
diff
changeset
|
845 |
let |
20353 | 846 |
val c = Sign.intern_const thy raw |
847 |
in (c, Sign.the_const_type thy c) end; |
|
848 |
val nil' = prep_const raw_nil; |
|
849 |
val cons' = prep_const raw_cons; |
|
850 |
val tabs = mk_tabs thy NONE [nil', cons']; |
|
851 |
fun mk_const c_ty = |
|
20386 | 852 |
idf_of_const thy (snd tabs) c_ty; |
20353 | 853 |
val nil'' = mk_const nil'; |
854 |
val cons'' = mk_const cons'; |
|
855 |
val pr = CodegenSerializer.pretty_list nil'' cons'' seri; |
|
18704
2c86ced392a8
substantial improvement in serialization handling
haftmann
parents:
18702
diff
changeset
|
856 |
in |
2c86ced392a8
substantial improvement in serialization handling
haftmann
parents:
18702
diff
changeset
|
857 |
thy |
20353 | 858 |
|> add_pretty_syntax_const cons'' target pr |
18704
2c86ced392a8
substantial improvement in serialization handling
haftmann
parents:
18702
diff
changeset
|
859 |
end; |
2c86ced392a8
substantial improvement in serialization handling
haftmann
parents:
18702
diff
changeset
|
860 |
|
18217 | 861 |
|
18516 | 862 |
|
19884 | 863 |
(** code basis change notifications **) |
864 |
||
865 |
val _ = Context.add_setup (CodegenTheorems.add_notify purge_defs); |
|
866 |
||
867 |
||
868 |
||
18756 | 869 |
(** toplevel interface **) |
870 |
||
871 |
local |
|
19150 | 872 |
|
19884 | 873 |
fun generate_code targets (SOME raw_consts) thy = |
19816
a8c8ed1c85e0
removed 'primitive definitions' added (non)strict generation, minor fixes
haftmann
parents:
19806
diff
changeset
|
874 |
let |
20386 | 875 |
val consts = map (CodegenConsts.read_const_typ thy) raw_consts; |
19884 | 876 |
val _ = case targets of SOME targets => (map get_serializer targets; ()) | _ => (); |
18756 | 877 |
in |
878 |
thy |
|
20353 | 879 |
|> expand_module targets consts NONE (fold_map oo ensure_def_const) consts |
18756 | 880 |
|-> (fn cs => pair (SOME cs)) |
881 |
end |
|
19816
a8c8ed1c85e0
removed 'primitive definitions' added (non)strict generation, minor fixes
haftmann
parents:
19806
diff
changeset
|
882 |
| generate_code _ NONE thy = |
18756 | 883 |
(NONE, thy); |
884 |
||
885 |
fun serialize_code target seri raw_consts thy = |
|
18217 | 886 |
let |
18756 | 887 |
fun serialize cs thy = |
18702 | 888 |
let |
18756 | 889 |
val module = (#modl o CodegenData.get) thy; |
18702 | 890 |
val target_data = |
891 |
thy |
|
892 |
|> CodegenData.get |
|
893 |
|> #target_data |
|
894 |
|> (fn data => (the oo Symtab.lookup) data target); |
|
20216 | 895 |
val s_class = #syntax_class target_data |
896 |
val s_tyco = #syntax_tyco target_data |
|
897 |
val s_const = #syntax_const target_data |
|
19884 | 898 |
in |
20216 | 899 |
(seri ( |
900 |
Symtab.lookup s_class, |
|
901 |
(Option.map fst oo Symtab.lookup) s_tyco, |
|
902 |
(Option.map fst oo Symtab.lookup) s_const |
|
903 |
) (Symtab.keys s_class @ Symtab.keys s_tyco @ Symtab.keys s_const, cs) module : unit; thy) |
|
19884 | 904 |
end; |
18217 | 905 |
in |
906 |
thy |
|
19884 | 907 |
|> generate_code (SOME [target]) raw_consts |
18756 | 908 |
|-> (fn cs => serialize cs) |
18217 | 909 |
end; |
910 |
||
19341
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19283
diff
changeset
|
911 |
fun purge_consts raw_ts thy = |
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19283
diff
changeset
|
912 |
let |
20386 | 913 |
val cs = map (CodegenConsts.read_const_typ thy) raw_ts; |
19341
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19283
diff
changeset
|
914 |
in fold CodegenTheorems.purge_defs cs thy end; |
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19283
diff
changeset
|
915 |
|
18217 | 916 |
structure P = OuterParse |
917 |
and K = OuterKeyword |
|
918 |
||
919 |
in |
|
920 |
||
18850 | 921 |
val (generateK, serializeK, |
19341
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19283
diff
changeset
|
922 |
syntax_classK, syntax_tycoK, syntax_constK, |
20386 | 923 |
purgeK) = |
18850 | 924 |
("code_generate", "code_serialize", |
19884 | 925 |
"code_classapp", "code_typapp", "code_constapp", |
20386 | 926 |
"code_purge"); |
18335 | 927 |
|
18217 | 928 |
val generateP = |
18282 | 929 |
OuterSyntax.command generateK "generate executable code for constants" K.thy_decl ( |
19884 | 930 |
(Scan.option (P.$$$ "(" |-- P.list1 P.name --| P.$$$ ")") |
931 |
>> (fn SOME ["-"] => SOME [] | ts => ts)) |
|
19816
a8c8ed1c85e0
removed 'primitive definitions' added (non)strict generation, minor fixes
haftmann
parents:
19806
diff
changeset
|
932 |
-- Scan.repeat1 P.term |
19884 | 933 |
>> (fn (targets, raw_consts) => |
934 |
Toplevel.theory (generate_code targets (SOME raw_consts) #> snd)) |
|
18217 | 935 |
); |
936 |
||
937 |
val serializeP = |
|
18282 | 938 |
OuterSyntax.command serializeK "serialize executable code for constants" K.thy_decl ( |
18217 | 939 |
P.name |
19136 | 940 |
-- Scan.option (Scan.repeat1 P.term) |
18756 | 941 |
#-> (fn (target, raw_consts) => |
18850 | 942 |
P.$$$ "(" |
943 |
|-- get_serializer target |
|
944 |
--| P.$$$ ")" |
|
18756 | 945 |
>> (fn seri => |
946 |
Toplevel.theory (serialize_code target seri raw_consts) |
|
947 |
)) |
|
18217 | 948 |
); |
949 |
||
18865 | 950 |
val syntax_classP = |
19884 | 951 |
OuterSyntax.command syntax_classK "define code syntax for class" K.thy_decl ( |
18865 | 952 |
Scan.repeat1 ( |
953 |
P.xname |
|
954 |
-- Scan.repeat1 ( |
|
955 |
P.name -- P.string |
|
956 |
) |
|
957 |
) |
|
958 |
>> (Toplevel.theory oo fold) (fn (raw_class, syns) => |
|
959 |
fold (fn (target, p) => add_syntax_class raw_class target p) syns) |
|
960 |
); |
|
961 |
||
18217 | 962 |
val syntax_tycoP = |
963 |
OuterSyntax.command syntax_tycoK "define code syntax for type constructor" K.thy_decl ( |
|
18702 | 964 |
Scan.repeat1 ( |
965 |
P.xname |
|
18963 | 966 |
#-> (fn raw_tyco => Scan.repeat1 ( |
967 |
P.name -- parse_syntax_tyco raw_tyco |
|
968 |
)) |
|
18702 | 969 |
) |
18963 | 970 |
>> (Toplevel.theory oo fold o fold) |
971 |
(fn (target, modifier) => modifier target) |
|
18217 | 972 |
); |
973 |
||
974 |
val syntax_constP = |
|
975 |
OuterSyntax.command syntax_constK "define code syntax for constant" K.thy_decl ( |
|
18702 | 976 |
Scan.repeat1 ( |
19136 | 977 |
P.term |
18963 | 978 |
#-> (fn raw_const => Scan.repeat1 ( |
979 |
P.name -- parse_syntax_const raw_const |
|
980 |
)) |
|
18702 | 981 |
) |
19008 | 982 |
>> (Toplevel.theory oo fold o fold) |
18963 | 983 |
(fn (target, modifier) => modifier target) |
18217 | 984 |
); |
985 |
||
19341
3414c04fbc39
added definitional code generator module: codegen_theorems.ML
haftmann
parents:
19283
diff
changeset
|
986 |
val purgeP = |
20175 | 987 |
OuterSyntax.command purgeK "purge all incrementally generated code" K.thy_decl |
988 |
(Scan.succeed (Toplevel.theory purge_code)); |
|
18516 | 989 |
|
19884 | 990 |
val _ = OuterSyntax.add_parsers [generateP, serializeP, |
991 |
syntax_classP, syntax_tycoP, syntax_constP, |
|
20386 | 992 |
purgeP]; |
18217 | 993 |
|
994 |
end; (* local *) |
|
995 |
||
996 |
end; (* struct *) |