src/Pure/Tools/codegen_package.ML
changeset 23955 f1ba12c117ec
parent 23812 f935b85fbb4c
child 24166 7b28dc69bdbb
equal deleted inserted replaced
23954:bc85c552e82f 23955:f1ba12c117ec
     5 Code generator translation kernel.  Code generator Isar setup.
     5 Code generator translation kernel.  Code generator Isar setup.
     6 *)
     6 *)
     7 
     7 
     8 signature CODEGEN_PACKAGE =
     8 signature CODEGEN_PACKAGE =
     9 sig
     9 sig
       
    10   val compile_term: theory -> term -> CodegenThingol.code * CodegenThingol.iterm;
    10   val eval_term: theory -> (string (*reference name!*) * 'a option ref) * term -> 'a;
    11   val eval_term: theory -> (string (*reference name!*) * 'a option ref) * term -> 'a;
    11   val satisfies_ref: bool option ref;
    12   val satisfies_ref: bool option ref;
    12   val satisfies: theory -> term -> string list -> bool;
    13   val satisfies: theory -> term -> string list -> bool;
    13   val codegen_command: theory -> string -> unit;
    14   val codegen_command: theory -> string -> unit;
    14 
    15 
   530     val ct = Thm.cterm_of thy t;
   531     val ct = Thm.cterm_of thy t;
   531     val (ct', funcgr) = Funcgr.make_term thy (K (K K)) ct;
   532     val (ct', funcgr) = Funcgr.make_term thy (K (K K)) ct;
   532     val t' = Thm.term_of ct';
   533     val t' = Thm.term_of ct';
   533   in generate thy funcgr exprgen_term' t' end;
   534   in generate thy funcgr exprgen_term' t' end;
   534 
   535 
       
   536 fun compile_term thy t =
       
   537   let
       
   538     val ct = Thm.cterm_of thy t;
       
   539     val (ct', funcgr) = Funcgr.make_term thy (K (K K)) ct;
       
   540     val t' = Thm.term_of ct';
       
   541     val t'' = generate thy funcgr exprgen_term' t';
       
   542     val consts = CodegenThingol.fold_constnames (insert (op =)) t'' [];
       
   543     val code = Code.get thy
       
   544       |> CodegenThingol.project_code true [] (SOME consts)
       
   545   in (code, t'') end;
       
   546 
   535 fun raw_eval_term thy (ref_spec, t) args =
   547 fun raw_eval_term thy (ref_spec, t) args =
   536   let
   548   let
   537     val _ = (Term.map_types o Term.map_atyps) (fn _ =>
   549     val _ = (Term.map_types o Term.map_atyps) (fn _ =>
   538       error ("Term " ^ Sign.string_of_term thy t ^ " contains polymorphic type"))
   550       error ("Term " ^ Sign.string_of_term thy t ^ " contains polymorphic type"))
   539       t;
   551       t;