src/Tools/Code/code_thingol.ML
changeset 34173 458ced35abb8
parent 34084 05cb31ca48ae
child 34244 03f8dcab55f3
equal deleted inserted replaced
34172:4301e9ea1c54 34173:458ced35abb8
    88 
    88 
    89   val expand_eta: theory -> int -> thm -> thm
    89   val expand_eta: theory -> int -> thm -> thm
    90   val canonize_thms: theory -> thm list -> thm list
    90   val canonize_thms: theory -> thm list -> thm list
    91   val read_const_exprs: theory -> string list -> string list * string list
    91   val read_const_exprs: theory -> string list -> string list * string list
    92   val consts_program: theory -> string list -> string list * (naming * program)
    92   val consts_program: theory -> string list -> string list * (naming * program)
    93   val cached_program: theory -> naming * program
       
    94   val eval_conv: theory
    93   val eval_conv: theory
    95     -> (naming -> program -> ((string * sort) list * typscheme) * iterm -> string list -> cterm -> thm)
    94     -> (naming -> program -> ((string * sort) list * typscheme) * iterm -> string list -> cterm -> thm)
    96     -> cterm -> thm
    95     -> cterm -> thm
    97   val eval: theory -> ((term -> term) -> 'a -> 'a)
    96   val eval: theory -> ((term -> term) -> 'a -> 'a)
    98     -> (naming -> program -> ((string * sort) list * typscheme) * iterm -> string list -> 'a)
    97     -> (naming -> program -> ((string * sort) list * typscheme) * iterm -> string list -> 'a)
   841   in fold_map mk_dict typargs end;
   840   in fold_map mk_dict typargs end;
   842 
   841 
   843 
   842 
   844 (* store *)
   843 (* store *)
   845 
   844 
   846 structure Program = Code_Data_Fun
   845 structure Program = Code_Data
   847 (
   846 (
   848   type T = naming * program;
   847   type T = naming * program;
   849   val empty = (empty_naming, Graph.empty);
   848   val empty = (empty_naming, Graph.empty);
   850   fun purge thy cs (naming, program) =
       
   851     let
       
   852       val names_delete = cs
       
   853         |> map_filter (lookup_const naming)
       
   854         |> filter (can (Graph.get_node program))
       
   855         |> Graph.all_preds program;
       
   856       val program' = Graph.del_nodes names_delete program;
       
   857     in (naming, program') end;
       
   858 );
   849 );
   859 
       
   860 val cached_program = Program.get;
       
   861 
   850 
   862 fun invoke_generation thy (algebra, eqngr) f name =
   851 fun invoke_generation thy (algebra, eqngr) f name =
   863   Program.change_yield thy (fn naming_program => (NONE, naming_program)
   852   Program.change_yield thy (fn naming_program => (NONE, naming_program)
   864     |> f thy algebra eqngr name
   853     |> f thy algebra eqngr name
   865     |-> (fn name => fn (_, naming_program) => (name, naming_program)));
   854     |-> (fn name => fn (_, naming_program) => (name, naming_program)));
   941   in pairself flat o split_list o map read_const_expr end;
   930   in pairself flat o split_list o map read_const_expr end;
   942 
   931 
   943 fun code_depgr thy consts =
   932 fun code_depgr thy consts =
   944   let
   933   let
   945     val (_, eqngr) = Code_Preproc.obtain thy consts [];
   934     val (_, eqngr) = Code_Preproc.obtain thy consts [];
   946     val select = Graph.all_succs eqngr consts;
   935     val all_consts = Graph.all_succs eqngr consts;
   947   in
   936   in
   948     eqngr
   937     eqngr
   949     |> not (null consts) ? Graph.subgraph (member (op =) select) 
   938     |> Graph.subgraph (member (op =) all_consts) 
   950     |> Graph.map_nodes ((apsnd o map o apfst) (AxClass.overload thy))
   939     |> Graph.map_nodes ((apsnd o map o apfst) (AxClass.overload thy))
   951   end;
   940   end;
   952 
   941 
   953 fun code_thms thy = Pretty.writeln o Code_Preproc.pretty thy o code_depgr thy;
   942 fun code_thms thy = Pretty.writeln o Code_Preproc.pretty thy o code_depgr thy;
   954 
   943 
   981 
   970 
   982 in
   971 in
   983 
   972 
   984 val _ =
   973 val _ =
   985   OuterSyntax.improper_command "code_thms" "print system of code equations for code" OuterKeyword.diag
   974   OuterSyntax.improper_command "code_thms" "print system of code equations for code" OuterKeyword.diag
   986     (Scan.repeat P.term_group
   975     (Scan.repeat1 P.term_group
   987       >> (fn cs => Toplevel.no_timing o Toplevel.unknown_theory
   976       >> (fn cs => Toplevel.no_timing o Toplevel.unknown_theory
   988         o Toplevel.keep ((fn thy => code_thms_cmd thy cs) o Toplevel.theory_of)));
   977         o Toplevel.keep ((fn thy => code_thms_cmd thy cs) o Toplevel.theory_of)));
   989 
   978 
   990 val _ =
   979 val _ =
   991   OuterSyntax.improper_command "code_deps" "visualize dependencies of code equations for code" OuterKeyword.diag
   980   OuterSyntax.improper_command "code_deps" "visualize dependencies of code equations for code" OuterKeyword.diag
   992     (Scan.repeat P.term_group
   981     (Scan.repeat1 P.term_group
   993       >> (fn cs => Toplevel.no_timing o Toplevel.unknown_theory
   982       >> (fn cs => Toplevel.no_timing o Toplevel.unknown_theory
   994         o Toplevel.keep ((fn thy => code_deps_cmd thy cs) o Toplevel.theory_of)));
   983         o Toplevel.keep ((fn thy => code_deps_cmd thy cs) o Toplevel.theory_of)));
   995 
   984 
   996 end;
   985 end;
   997 
   986