src/Tools/code/code_package.ML
changeset 24621 97d403d9ab54
parent 24585 c359896d0f48
child 24662 f79f6061525c
equal deleted inserted replaced
24620:40811901b998 24621:97d403d9ab54
     5 Code generator translation kernel.  Code generator Isar setup.
     5 Code generator translation kernel.  Code generator Isar setup.
     6 *)
     6 *)
     7 
     7 
     8 signature CODE_PACKAGE =
     8 signature CODE_PACKAGE =
     9 sig
     9 sig
    10   (*interfaces*)
       
    11   val eval_conv: theory
    10   val eval_conv: theory
    12     -> (CodeThingol.code -> CodeThingol.typscheme * CodeThingol.iterm
    11     -> (CodeThingol.code -> CodeThingol.typscheme * CodeThingol.iterm
    13        -> string list -> cterm -> thm)
    12        -> string list -> cterm -> thm)
    14     -> cterm -> thm;
    13     -> cterm -> thm;
    15   val eval_term: theory
    14   val eval_term: theory
    16     -> (CodeThingol.code -> CodeThingol.typscheme * CodeThingol.iterm
    15     -> (CodeThingol.code -> CodeThingol.typscheme * CodeThingol.iterm
    17        -> string list -> cterm -> 'a)
    16        -> string list -> cterm -> 'a)
    18     -> cterm -> 'a;
    17     -> cterm -> 'a;
    19   val satisfies_ref: (unit -> bool) option ref;
    18   val satisfies_ref: (unit -> bool) option ref;
    20   val satisfies: theory -> cterm -> string list -> bool;
    19   val satisfies: theory -> cterm -> string list -> bool;
       
    20   val eval_invoke: theory -> (string * (unit -> 'a) option ref) -> CodeThingol.code
       
    21     -> CodeThingol.iterm * CodeThingol.itype -> string list -> 'a;
    21   val codegen_command: theory -> string -> unit;
    22   val codegen_command: theory -> string -> unit;
    22 
    23 
    23   (*axiomatic interfaces*)
       
    24   type appgen;
    24   type appgen;
    25   val add_appconst: string * appgen -> theory -> theory;
    25   val add_appconst: string * appgen -> theory -> theory;
    26   val appgen_let: appgen;
    26   val appgen_let: appgen;
    27   val appgen_if: appgen;
    27   val appgen_if: appgen;
    28   val appgen_case: (theory -> term
    28   val appgen_case: (theory -> term
   423 fun code thy permissive cs seris =
   423 fun code thy permissive cs seris =
   424   let
   424   let
   425     val code = Program.get thy;
   425     val code = Program.get thy;
   426     val seris' = map (fn (((target, module), file), args) =>
   426     val seris' = map (fn (((target, module), file), args) =>
   427       CodeTarget.get_serializer thy target permissive module file args
   427       CodeTarget.get_serializer thy target permissive module file args
   428         CodeName.labelled_name cs) seris;
   428         CodeName.labelled_name (K false) cs) seris;
   429   in (map (fn f => f code) seris' : unit list; ()) end;
   429   in (map (fn f => f code) seris' : unit list; ()) end;
   430 
   430 
   431 fun raw_eval f thy g =
   431 fun raw_eval f thy g =
   432   let
   432   let
   433     val value_name = "Isabelle_Eval.EVAL.EVAL";
   433     val value_name = "Isabelle_Eval.EVAL.EVAL";
   459   in f thy h end;
   459   in f thy h end;
   460 
   460 
   461 fun eval_conv thy = raw_eval CodeFuncgr.eval_conv thy;
   461 fun eval_conv thy = raw_eval CodeFuncgr.eval_conv thy;
   462 fun eval_term thy = raw_eval CodeFuncgr.eval_term thy;
   462 fun eval_term thy = raw_eval CodeFuncgr.eval_term thy;
   463 
   463 
       
   464 fun eval_invoke thy = CodeTarget.eval_invoke thy CodeName.labelled_name (K false);
       
   465 
   464 val satisfies_ref : (unit -> bool) option ref = ref NONE;
   466 val satisfies_ref : (unit -> bool) option ref = ref NONE;
   465 
   467 
   466 fun satisfies thy ct witnesses =
   468 fun satisfies thy ct witnesses =
   467   let
   469   let
   468     fun evl code ((vs, ty), t) deps ct =
   470     fun evl code ((vs, ty), t) deps ct =
   470         val t0 = Thm.term_of ct
   472         val t0 = Thm.term_of ct
   471         val _ = (Term.map_types o Term.map_atyps) (fn _ =>
   473         val _ = (Term.map_types o Term.map_atyps) (fn _ =>
   472           error ("Term " ^ Sign.string_of_term thy t0 ^ " contains polymorphic type"))
   474           error ("Term " ^ Sign.string_of_term thy t0 ^ " contains polymorphic type"))
   473           t0;
   475           t0;
   474       in
   476       in
   475         CodeTarget.eval_term thy ("CodePackage.satisfies_ref", satisfies_ref)
   477         eval_invoke thy ("CodePackage.satisfies_ref", satisfies_ref)
   476           code (t, ty) witnesses
   478           code (t, ty) witnesses
   477       end;
   479       end;
   478   in eval_term thy evl ct end;
   480   in eval_term thy evl ct end;
   479 
   481 
   480 fun filter_generatable thy consts =
   482 fun filter_generatable thy consts =
   550   in
   552   in
   551     thy
   553     thy
   552     |> Sign.sticky_prefix "codeprop"
   554     |> Sign.sticky_prefix "codeprop"
   553     |> lift_name_yield (fold_map add codeprops)
   555     |> lift_name_yield (fold_map add codeprops)
   554     ||> Sign.restore_naming thy
   556     ||> Sign.restore_naming thy
   555     |-> (fn c_thms => fold (Code.add_func true o snd) c_thms #> pair c_thms)
   557     |-> (fn c_thms => fold (Code.add_func o snd) c_thms #> pair c_thms)
   556   end;
   558   end;
   557 
   559 
   558 
   560 
   559 
   561 
   560 (** toplevel interface and setup **)
   562 (** toplevel interface and setup **)