1 (* Title: Tools/code/code_package.ML
3 Author: Florian Haftmann, TU Muenchen
5 Code generator translation kernel. Code generator Isar setup.
8 signature CODE_PACKAGE =
11 -> (CodeThingol.code -> CodeThingol.typscheme * CodeThingol.iterm
12 -> string list -> cterm -> thm)
15 -> (CodeThingol.code -> CodeThingol.typscheme * CodeThingol.iterm
16 -> string list -> term -> 'a)
18 val satisfies_ref: (unit -> bool) option ref;
19 val satisfies: theory -> term -> string list -> bool;
20 val eval_invoke: theory -> (string * (unit -> 'a) option ref) -> CodeThingol.code
21 -> CodeThingol.iterm * CodeThingol.itype -> string list -> 'a;
22 val codegen_command: theory -> string -> unit;
25 structure CodePackage : CODE_PACKAGE =
28 open BasicCodeThingol;
32 fun code_depgr thy [] = CodeFuncgr.make thy []
33 | code_depgr thy consts =
35 val gr = CodeFuncgr.make thy consts;
36 val select = Graph.all_succs gr consts;
39 |> Graph.subgraph (member (op =) select)
40 |> Graph.map_nodes ((apsnd o map) (Conv.fconv_rule (Class.overload thy)))
44 Pretty.writeln o CodeFuncgr.pretty thy o code_depgr thy;
46 fun code_deps thy consts =
48 val gr = code_depgr thy consts;
49 fun mk_entry (const, (_, (_, parents))) =
51 val name = CodeUnit.string_of_const thy const;
52 val nameparents = map (CodeUnit.string_of_const thy) parents;
53 in { name = name, ID = name, dir = "", unfold = true,
54 path = "", parents = nameparents }
56 val prgr = Graph.fold ((fn x => fn xs => xs @ [x]) o mk_entry) gr [];
57 in Present.display_graph prgr end;
60 (** code translation **)
62 structure Program = CodeDataFun
64 type T = CodeThingol.code;
65 val empty = CodeThingol.empty_code;
66 fun merge _ = CodeThingol.merge_code;
67 fun purge _ NONE _ = CodeThingol.empty_code
68 | purge NONE _ _ = CodeThingol.empty_code
69 | purge (SOME thy) (SOME cs) code =
72 map_filter (CodeName.const_rev thy) (Graph.keys code);
73 val dels = (Graph.all_preds code
74 o map (CodeName.const thy)
75 o filter (member (op =) cs_exisiting)
77 in Graph.del_nodes dels code end;
81 (* translation kernel *)
83 val value_name = "Isabelle_Eval.EVAL.EVAL";
85 fun ensure_def thy = CodeThingol.ensure_def
86 (fn s => if s = value_name then "<term>" else CodeName.labelled_name thy s);
88 exception CONSTRAIN of (string * typ) * typ;
90 fun ensure_def_class thy (algbr as ((_, algebra), _)) funcgr class =
92 val superclasses = (Sorts.certify_sort algebra o Sorts.super_classes algebra) class;
93 val (v, cs) = AxClass.params_of_class thy class;
94 val class' = CodeName.class thy class;
96 fold_map (fn superclass => ensure_def_class thy algbr funcgr superclass
97 ##>> ensure_def_classrel thy algbr funcgr (class, superclass)) superclasses
98 ##>> fold_map (fn (c, ty) => ensure_def_const thy algbr funcgr c
99 ##>> exprgen_typ thy algbr funcgr ty) cs
100 #>> (fn info => CodeThingol.Class (unprefix "'" v, info))
102 ensure_def thy defgen_class class'
105 and ensure_def_classrel thy algbr funcgr (subclass, superclass) =
107 val classrel' = CodeName.classrel thy (subclass, superclass);
108 val defgen_classrel =
109 ensure_def_class thy algbr funcgr subclass
110 ##>> ensure_def_class thy algbr funcgr superclass
111 #>> CodeThingol.Classrel;
113 ensure_def thy defgen_classrel classrel'
116 and ensure_def_tyco thy algbr funcgr "fun" =
118 | ensure_def_tyco thy algbr funcgr tyco =
120 val defgen_datatype =
122 val (vs, cos) = Code.get_datatype thy tyco;
124 fold_map (exprgen_tyvar_sort thy algbr funcgr) vs
125 ##>> fold_map (fn (c, tys) =>
126 ensure_def_const thy algbr funcgr c
127 ##>> fold_map (exprgen_typ thy algbr funcgr) tys) cos
128 #>> CodeThingol.Datatype
130 val tyco' = CodeName.tyco thy tyco;
132 ensure_def thy defgen_datatype tyco'
135 and exprgen_tyvar_sort thy (algbr as ((proj_sort, _), _)) funcgr (v, sort) =
136 fold_map (ensure_def_class thy algbr funcgr) (proj_sort sort)
137 #>> (fn sort => (unprefix "'" v, sort))
138 and exprgen_typ thy algbr funcgr (TFree vs) =
139 exprgen_tyvar_sort thy algbr funcgr vs
140 #>> (fn (v, sort) => ITyVar v)
141 | exprgen_typ thy algbr funcgr (Type (tyco, tys)) =
142 ensure_def_tyco thy algbr funcgr tyco
143 ##>> fold_map (exprgen_typ thy algbr funcgr) tys
144 #>> (fn (tyco, tys) => tyco `%% tys)
145 and exprgen_dicts thy (algbr as ((proj_sort, algebra), consts)) funcgr (ty_ctxt, sort_decl) =
147 val pp = Sign.pp thy;
149 Global of (class * string) * typarg list list
150 | Local of (class * class) list * (string * (int * sort));
151 fun class_relation (Global ((_, tyco), yss), _) class =
152 Global ((class, tyco), yss)
153 | class_relation (Local (classrels, v), subclass) superclass =
154 Local ((subclass, superclass) :: classrels, v);
155 fun type_constructor tyco yss class =
156 Global ((class, tyco), (map o map) fst yss);
157 fun type_variable (TFree (v, sort)) =
159 val sort' = proj_sort sort;
160 in map_index (fn (n, class) => (Local ([], (v, (n, sort'))), class)) sort' end;
161 val typargs = Sorts.of_sort_derivation pp algebra
162 {class_relation = class_relation, type_constructor = type_constructor,
163 type_variable = type_variable}
164 (ty_ctxt, proj_sort sort_decl);
165 fun mk_dict (Global (inst, yss)) =
166 ensure_def_inst thy algbr funcgr inst
167 ##>> (fold_map o fold_map) mk_dict yss
168 #>> (fn (inst, dss) => DictConst (inst, dss))
169 | mk_dict (Local (classrels, (v, (k, sort)))) =
170 fold_map (ensure_def_classrel thy algbr funcgr) classrels
171 #>> (fn classrels => DictVar (classrels, (unprefix "'" v, (k, length sort))))
173 fold_map mk_dict typargs
175 and exprgen_dict_parms thy (algbr as (_, consts)) funcgr (c, ty_ctxt) =
177 val ty_decl = Consts.the_declaration consts c;
178 val (tys, tys_decl) = pairself (curry (Consts.typargs consts) c) (ty_ctxt, ty_decl);
179 val sorts = map (snd o dest_TVar) tys_decl;
181 fold_map (exprgen_dicts thy algbr funcgr) (tys ~~ sorts)
183 and exprgen_eq thy algbr funcgr thm =
185 val (args, rhs) = (apfst (snd o strip_comb) o Logic.dest_equals
186 o Logic.unvarify o prop_of) thm;
188 fold_map (exprgen_term thy algbr funcgr) args
189 ##>> exprgen_term thy algbr funcgr rhs
192 and ensure_def_inst thy (algbr as ((_, algebra), _)) funcgr (class, tyco) =
194 val superclasses = (Sorts.certify_sort algebra o Sorts.super_classes algebra) class;
195 val (var, classparams) = try (AxClass.params_of_class thy) class |> the_default ("'a", [])
196 val vs = Name.names Name.context "'a" (Sorts.mg_domain algebra tyco [class]);
197 val sorts' = Sorts.mg_domain (Sign.classes_of thy) tyco [class];
198 val vs' = map2 (fn (v, sort1) => fn sort2 => (v,
199 Sorts.inter_sort (Sign.classes_of thy) (sort1, sort2))) vs sorts';
200 val arity_typ = Type (tyco, map TFree vs);
201 val arity_typ' = Type (tyco, map (fn (v, sort) => TVar ((v, 0), sort)) vs');
202 fun exprgen_superarity superclass =
203 ensure_def_class thy algbr funcgr superclass
204 ##>> ensure_def_classrel thy algbr funcgr (class, superclass)
205 ##>> exprgen_dicts thy algbr funcgr (arity_typ, [superclass])
206 #>> (fn ((superclass, classrel), [DictConst (inst, dss)]) =>
207 (superclass, (classrel, (inst, dss))));
208 fun exprgen_classparam_inst (c, ty) =
210 val c_inst = Const (c, map_type_tfree (K arity_typ') ty);
211 val thm = Class.unoverload thy (Thm.cterm_of thy c_inst);
212 val c_ty = (apsnd Logic.unvarifyT o dest_Const o snd
213 o Logic.dest_equals o Thm.prop_of) thm;
215 ensure_def_const thy algbr funcgr c
216 ##>> exprgen_const thy algbr funcgr c_ty
217 #>> (fn (c, IConst c_inst) => ((c, c_inst), thm))
220 ensure_def_class thy algbr funcgr class
221 ##>> ensure_def_tyco thy algbr funcgr tyco
222 ##>> fold_map (exprgen_tyvar_sort thy algbr funcgr) vs
223 ##>> fold_map exprgen_superarity superclasses
224 ##>> fold_map exprgen_classparam_inst classparams
225 #>> (fn ((((class, tyco), arity), superarities), classparams) =>
226 CodeThingol.Classinst ((class, (tyco, arity)), (superarities, classparams)));
227 val inst = CodeName.instance thy (class, tyco);
229 ensure_def thy defgen_inst inst
232 and ensure_def_const thy (algbr as (_, consts)) funcgr c =
234 val c' = CodeName.const thy c;
235 fun defgen_datatypecons tyco =
236 ensure_def_tyco thy algbr funcgr tyco
237 #>> K (CodeThingol.Datatypecons c');
238 fun defgen_classparam class =
239 ensure_def_class thy algbr funcgr class
240 #>> K (CodeThingol.Classparam c');
241 fun defgen_fun trns =
243 val raw_thms = CodeFuncgr.funcs funcgr c;
244 val ty = (Logic.unvarifyT o CodeFuncgr.typ funcgr) c;
245 val vs = (map dest_TFree o Consts.typargs consts) (c, ty);
246 val thms = if (null o Term.typ_tfrees) ty orelse (null o fst o strip_type) ty
248 else map (CodeUnit.expand_eta 1) raw_thms;
251 |> fold_map (exprgen_tyvar_sort thy algbr funcgr) vs
252 ||>> exprgen_typ thy algbr funcgr ty
253 ||>> fold_map (exprgen_eq thy algbr funcgr) thms
254 |>> (fn ((vs, ty), eqs) => CodeThingol.Fun ((vs, ty), eqs))
256 val defgen = case Code.get_datatype_of_constr thy c
257 of SOME tyco => defgen_datatypecons tyco
258 | NONE => (case AxClass.class_of_param thy c
259 of SOME class => defgen_classparam class
260 | NONE => defgen_fun)
262 ensure_def thy defgen c'
265 and exprgen_term thy algbr funcgr (Const (c, ty)) =
266 exprgen_app thy algbr funcgr ((c, ty), [])
267 | exprgen_term thy algbr funcgr (Free (v, _)) =
269 | exprgen_term thy algbr funcgr (Abs (abs as (_, ty, _))) =
271 val (v, t) = Syntax.variant_abs abs;
273 exprgen_typ thy algbr funcgr ty
274 ##>> exprgen_term thy algbr funcgr t
275 #>> (fn (ty, t) => (v, ty) `|-> t)
277 | exprgen_term thy algbr funcgr (t as _ $ _) =
279 of (Const (c, ty), ts) =>
280 exprgen_app thy algbr funcgr ((c, ty), ts)
282 exprgen_term thy algbr funcgr t'
283 ##>> fold_map (exprgen_term thy algbr funcgr) ts
284 #>> (fn (t, ts) => t `$$ ts)
285 and exprgen_const thy algbr funcgr (c, ty) =
286 ensure_def_const thy algbr funcgr c
287 ##>> exprgen_dict_parms thy algbr funcgr (c, ty)
288 ##>> fold_map (exprgen_typ thy algbr funcgr) ((fst o Term.strip_type) ty)
289 (*##>> exprgen_typ thy algbr funcgr ((snd o Term.strip_type) ty)*)
290 #>> (fn ((c, iss), tys) => IConst (c, (iss, tys)))
291 and exprgen_app_default thy algbr funcgr (c_ty, ts) =
292 exprgen_const thy algbr funcgr c_ty
293 ##>> fold_map (exprgen_term thy algbr funcgr) ts
294 #>> (fn (t, ts) => t `$$ ts)
295 and exprgen_case thy algbr funcgr n cases (app as ((c, ty), ts)) =
297 (*FIXME rework this code*)
298 val (all_tys, _) = strip_type ty;
299 val (tys, _) = chop (1 + (if null cases then 1 else length cases)) all_tys;
302 fun is_undefined (Const (c, _)) = Code.is_undefined thy c
303 | is_undefined _ = false;
304 fun mk_case (co, n) t =
306 val (vs, body) = Term.strip_abs_eta n t;
307 val selector = list_comb (Const (co, map snd vs ---> sty), map Free vs);
308 in if is_undefined body then NONE else SOME (selector, body) end;
310 of [] => let val ([v_ty], body) = Term.strip_abs_eta 1 (the_single (nth_drop n ts))
311 in [(Free v_ty, body)] end
312 | cases => map_filter (uncurry mk_case) (AList.make (CodeUnit.no_args thy) cases
315 exprgen_term thy algbr funcgr st
316 ##>> exprgen_typ thy algbr funcgr sty
317 ##>> fold_map (fn (pat, body) => exprgen_term thy algbr funcgr pat
318 ##>> exprgen_term thy algbr funcgr body) ds
319 ##>> exprgen_app_default thy algbr funcgr app
320 #>> (fn (((st, sty), ds), t0) => ICase (((st, sty), ds), t0))
322 and exprgen_app thy algbr funcgr ((c, ty), ts) = case Code.get_case_data thy c
323 of SOME (n, cases) => let val i = 1 + (if null cases then 1 else length cases) in
324 if length ts < i then
327 val tys = (curry Library.take (i - k) o curry Library.drop k o fst o strip_type) ty;
328 val ctxt = (fold o fold_aterms)
329 (fn Free (v, _) => Name.declare v | _ => I) ts Name.context;
330 val vs = Name.names ctxt "a" tys;
332 fold_map (exprgen_typ thy algbr funcgr) tys
333 ##>> exprgen_case thy algbr funcgr n cases ((c, ty), ts @ map Free vs)
334 #>> (fn (tys, t) => map2 (fn (v, _) => pair v) vs tys `|--> t)
336 else if length ts > i then
337 exprgen_case thy algbr funcgr n cases ((c, ty), Library.take (i, ts))
338 ##>> fold_map (exprgen_term thy algbr funcgr) (Library.drop (i, ts))
339 #>> (fn (t, ts) => t `$$ ts)
341 exprgen_case thy algbr funcgr n cases ((c, ty), ts)
343 | NONE => exprgen_app_default thy algbr funcgr ((c, ty), ts);
346 (* entrance points into translation kernel *)
348 fun ensure_def_const' thy algbr funcgr c trns =
349 ensure_def_const thy algbr funcgr c trns
350 handle CONSTRAIN ((c, ty), ty_decl) => error (
351 "Constant " ^ c ^ " with most general type\n"
352 ^ CodeUnit.string_of_typ thy ty
353 ^ "\noccurs with type\n"
354 ^ CodeUnit.string_of_typ thy ty_decl);
356 fun perhaps_def_const thy algbr funcgr c trns =
357 case try (ensure_def_const thy algbr funcgr c) trns
358 of SOME (c, trns) => (SOME c, trns)
359 | NONE => (NONE, trns);
361 fun exprgen_term' thy algbr funcgr t trns =
362 exprgen_term thy algbr funcgr t trns
363 handle CONSTRAIN ((c, ty), ty_decl) => error ("In term " ^ (quote o Sign.string_of_term thy) t
364 ^ ",\nconstant " ^ c ^ " with most general type\n"
365 ^ CodeUnit.string_of_typ thy ty
366 ^ "\noccurs with type\n"
367 ^ CodeUnit.string_of_typ thy ty_decl);
370 (** code generation interfaces **)
372 (* generic generation combinators *)
374 fun generate thy funcgr gen it =
376 val naming = NameSpace.qualified_names NameSpace.default_naming;
377 val consttab = Consts.empty
378 |> fold (fn c => Consts.declare true naming [] (c, CodeFuncgr.typ funcgr c))
379 (CodeFuncgr.all funcgr);
380 val algbr = (Code.operational_algebra thy, consttab);
382 Program.change_yield thy
383 (CodeThingol.start_transact (gen thy algbr funcgr it))
387 fun code thy permissive cs seris =
389 val code = Program.get thy;
390 val seris' = map (fn (((target, module), file), args) =>
391 CodeTarget.get_serializer thy target permissive module file args
392 CodeName.labelled_name cs) seris;
393 in (map (fn f => f code) seris' : unit list; ()) end;
395 fun raw_eval evaluate term_of thy g =
397 val value_name = "Isabelle_Eval.EVAL.EVAL";
398 fun ensure_eval thy algbr funcgr t =
400 val ty = fastype_of t;
401 val vs = fold_term_types (K (fold_atyps (insert (eq_fst op =)
402 o dest_TFree))) t [];
404 fold_map (exprgen_tyvar_sort thy algbr funcgr) vs
405 ##>> exprgen_typ thy algbr funcgr ty
406 ##>> exprgen_term' thy algbr funcgr t
407 #>> (fn ((vs, ty), t) => CodeThingol.Fun ((vs, ty), [(([], t), Drule.dummy_thm)]));
408 fun result (dep, code) =
410 val CodeThingol.Fun ((vs, ty), [(([], t), _)]) = Graph.get_node code value_name;
411 val deps = Graph.imm_succs code value_name;
412 val code' = Graph.del_nodes [value_name] code;
413 val code'' = CodeThingol.project_code false [] (SOME deps) code';
414 in ((code'', ((vs, ty), t), deps), (dep, code')) end;
416 ensure_def thy defgen_eval value_name
421 val (code, vs_ty_t, deps) = generate thy funcgr ensure_eval (term_of ct);
422 in g code vs_ty_t deps ct end;
423 in evaluate thy h end;
425 fun eval_conv thy = raw_eval CodeFuncgr.eval_conv Thm.term_of thy;
426 fun eval_term thy = raw_eval CodeFuncgr.eval_term I thy;
428 fun eval_invoke thy = CodeTarget.eval_invoke thy CodeName.labelled_name;
430 val satisfies_ref : (unit -> bool) option ref = ref NONE;
432 fun satisfies thy t witnesses =
434 fun evl code ((vs, ty), t) deps ct =
435 eval_invoke thy ("CodePackage.satisfies_ref", satisfies_ref)
436 code (t, ty) witnesses;
437 in eval_term thy evl t end;
439 fun filter_generatable thy consts =
441 val (consts', funcgr) = CodeFuncgr.make_consts thy consts;
442 val consts'' = generate thy funcgr (fold_map ooo perhaps_def_const) consts';
443 val consts''' = map_filter (fn (const, SOME _) => SOME const | (_, NONE) => NONE)
444 (consts' ~~ consts'');
447 fun generate_const_exprs thy raw_cs =
449 val (perm1, cs) = CodeUnit.read_const_exprs thy
450 (filter_generatable thy) raw_cs;
451 val (perm2, cs') = case generate thy (CodeFuncgr.make thy cs)
452 (fold_map ooo ensure_def_const') cs
453 of [] => (true, NONE)
454 | cs => (false, SOME cs);
455 in (perm1 orelse perm2, cs') end;
458 (** code properties **)
460 fun mk_codeprops thy all_cs sel_cs =
462 fun select (thmref, thm) = case try (Drule.unvarify o Drule.zero_var_indexes) thm
465 val t = (ObjectLogic.drop_judgment thy o Thm.prop_of) thm;
466 val cs = fold_aterms (fn Const (c, ty) =>
467 cons (Class.unoverload_const thy (c, ty)) | _ => I) t [];
468 in if exists (member (op =) sel_cs) cs
469 andalso forall (member (op =) all_cs) cs
470 then SOME (thmref, thm) else NONE end;
471 fun mk_codeprop (thmref, thm) =
473 val t = ObjectLogic.drop_judgment thy (Thm.prop_of thm);
474 val ty_judg = fastype_of t;
475 val tfrees1 = fold_aterms (fn Const (c, ty) =>
476 Term.add_tfreesT ty | _ => I) t [];
477 val vars = Term.add_frees t [];
478 val tfrees2 = fold (Term.add_tfreesT o snd) vars [];
479 val tfrees' = subtract (op =) tfrees2 tfrees1 |> map TFree;
480 val ty = map Term.itselfT tfrees' @ map snd vars ---> ty_judg;
481 val tfree_vars = map Logic.mk_type tfrees';
482 val c = PureThy.string_of_thmref thmref
484 |> (fn [x] => [x] | (x::xs) => xs)
486 val propdef = (((c, ty), tfree_vars @ map Free vars), t);
487 in if c = "" then NONE else SOME (thmref, propdef) end;
489 PureThy.thms_containing thy ([], [])
490 |> maps PureThy.selections
492 |> map_filter mk_codeprop
495 fun add_codeprops all_cs sel_cs thy =
497 val codeprops = mk_codeprops thy all_cs sel_cs;
498 fun lift_name_yield f x = (Name.context, x) |> f ||> snd;
499 fun add (thmref, (((raw_c, ty), ts), t)) (names, thy) =
501 val _ = warning ("Adding theorem " ^ quote (PureThy.string_of_thmref thmref)
502 ^ " as code property " ^ quote raw_c);
503 val ([raw_c'], names') = Name.variants [raw_c] names;
506 |> PureThy.simple_def ("", []) (((raw_c', ty, Syntax.NoSyn), ts), t)
511 |> Sign.sticky_prefix "codeprop"
512 |> lift_name_yield (fold_map add codeprops)
513 ||> Sign.restore_naming thy
514 |-> (fn c_thms => fold (Code.add_func o snd) c_thms #> pair c_thms)
519 (** toplevel interface and setup **)
523 structure P = OuterParse
526 fun code_cmd raw_cs seris thy =
528 val (permissive, cs) = generate_const_exprs thy raw_cs;
529 val _ = code thy permissive cs seris;
532 fun code_thms_cmd thy =
533 code_thms thy o snd o CodeUnit.read_const_exprs thy (fst o CodeFuncgr.make_consts thy);
535 fun code_deps_cmd thy =
536 code_deps thy o snd o CodeUnit.read_const_exprs thy (fst o CodeFuncgr.make_consts thy);
538 fun code_props_cmd raw_cs seris thy =
540 val (_, all_cs) = generate_const_exprs thy ["*"];
541 val (permissive, cs) = generate_const_exprs thy raw_cs;
542 val (c_thms, thy') = add_codeprops (map (the o CodeName.const_rev thy) (these all_cs))
543 (map (the o CodeName.const_rev thy) (these cs)) thy;
544 val prop_cs = (filter_generatable thy' o map fst) c_thms;
545 val _ = if null seris then [] else generate thy' (CodeFuncgr.make thy' prop_cs)
546 (fold_map ooo ensure_def_const') prop_cs;
547 val _ = if null seris then () else code thy' permissive
548 (SOME (map (CodeName.const thy') prop_cs)) seris;
551 val (inK, module_nameK, fileK) = ("in", "module_name", "file");
555 -- Scan.repeat (P.$$$ inK |-- P.name
556 -- Scan.option (P.$$$ module_nameK |-- P.name)
557 -- Scan.option (P.$$$ fileK |-- P.name)
558 -- Scan.optional (P.$$$ "(" |-- P.arguments --| P.$$$ ")") []
559 ) >> (fn (raw_cs, seris) => cmd raw_cs seris));
561 val _ = OuterSyntax.keywords [inK, module_nameK, fileK];
563 val (codeK, code_thmsK, code_depsK, code_propsK) =
564 ("export_code", "code_thms", "code_deps", "code_props");
569 OuterSyntax.improper_command codeK "generate executable code for constants"
570 K.diag (P.!!! (code_exprP code_cmd) >> (fn f => Toplevel.keep (f o Toplevel.theory_of)));
572 fun codegen_command thy cmd =
573 case Scan.read OuterLex.stopper (P.!!! (code_exprP code_cmd)) ((filter OuterLex.is_proper o OuterSyntax.scan) cmd)
574 of SOME f => (writeln "Now generating code..."; f thy)
575 | NONE => error ("Bad directive " ^ quote cmd);
578 OuterSyntax.improper_command code_thmsK "print system of defining equations for code" OuterKeyword.diag
580 >> (fn cs => Toplevel.no_timing o Toplevel.unknown_theory
581 o Toplevel.keep ((fn thy => code_thms_cmd thy cs) o Toplevel.theory_of)));
584 OuterSyntax.improper_command code_depsK "visualize dependencies of defining equations for code" OuterKeyword.diag
586 >> (fn cs => Toplevel.no_timing o Toplevel.unknown_theory
587 o Toplevel.keep ((fn thy => code_deps_cmd thy cs) o Toplevel.theory_of)));
590 OuterSyntax.command code_propsK "generate characteristic properties for executable constants"
591 K.thy_decl (P.!!! (code_exprP code_props_cmd) >> Toplevel.theory);