src/Tools/code/code_funcgr.ML
changeset 28924 5c8781b7d6a4
parent 28724 4656aacba2bc
child 29962 bd4dc7fa742d
child 30240 5b25fee0362c
equal deleted inserted replaced
28923:0a981c596372 28924:5c8781b7d6a4
    11   type T
    11   type T
    12   val eqns: T -> string -> (thm * bool) list
    12   val eqns: T -> string -> (thm * bool) list
    13   val typ: T -> string -> (string * sort) list * typ
    13   val typ: T -> string -> (string * sort) list * typ
    14   val all: T -> string list
    14   val all: T -> string list
    15   val pretty: theory -> T -> Pretty.T
    15   val pretty: theory -> T -> Pretty.T
    16   val make: theory -> string list -> T
    16   val make: theory -> string list
    17   val eval_conv: theory -> (term -> term * (T -> thm)) -> cterm -> thm
    17     -> ((sort -> sort) * Sorts.algebra) * T
    18   val eval_term: theory -> (term -> term * (T -> 'a)) -> term -> 'a
    18   val eval_conv: theory
       
    19     -> (term -> term * (((sort -> sort) * Sorts.algebra) -> T -> thm)) -> cterm -> thm
       
    20   val eval_term: theory
       
    21     -> (term -> term * (((sort -> sort) * Sorts.algebra) -> T -> 'a)) -> term -> 'a
    19   val timing: bool ref
    22   val timing: bool ref
    20 end
    23 end
    21 
    24 
    22 structure Code_Funcgr : CODE_FUNCGR =
    25 structure Code_Funcgr : CODE_FUNCGR =
    23 struct
    26 struct
   233     val funcgr' = ensure_consts thy algebra consts funcgr;
   236     val funcgr' = ensure_consts thy algebra consts funcgr;
   234     val (t'', evaluator_funcgr) = evaluator t';
   237     val (t'', evaluator_funcgr) = evaluator t';
   235     val consts' = consts_of t'';
   238     val consts' = consts_of t'';
   236     val dicts = instances_of_consts thy algebra funcgr' consts';
   239     val dicts = instances_of_consts thy algebra funcgr' consts';
   237     val funcgr'' = ensure_consts thy algebra dicts funcgr';
   240     val funcgr'' = ensure_consts thy algebra dicts funcgr';
   238   in (evaluator_lift evaluator_funcgr thm funcgr'', funcgr'') end;
   241   in (evaluator_lift (evaluator_funcgr (Code.operational_algebra thy)) thm funcgr'', funcgr'') end;
   239 
   242 
   240 fun proto_eval_conv thy =
   243 fun proto_eval_conv thy =
   241   let
   244   let
   242     fun evaluator_lift evaluator thm1 funcgr =
   245     fun evaluator_lift evaluator thm1 funcgr =
   243       let
   246       let
   265     Graph.del_nodes ((Graph.all_preds funcgr 
   268     Graph.del_nodes ((Graph.all_preds funcgr 
   266       o filter (can (Graph.get_node funcgr))) cs) funcgr;
   269       o filter (can (Graph.get_node funcgr))) cs) funcgr;
   267 );
   270 );
   268 
   271 
   269 fun make thy =
   272 fun make thy =
   270   Funcgr.change thy o ensure_consts thy (Code.coregular_algebra thy);
   273   pair (Code.operational_algebra thy)
       
   274   o Funcgr.change thy o ensure_consts thy (Code.coregular_algebra thy);
   271 
   275 
   272 fun eval_conv thy f =
   276 fun eval_conv thy f =
   273   fst o Funcgr.change_yield thy o proto_eval_conv thy f;
   277   fst o Funcgr.change_yield thy o proto_eval_conv thy f;
   274 
   278 
   275 fun eval_term thy f =
   279 fun eval_term thy f =
   278 
   282 
   279 (** diagnostic commands **)
   283 (** diagnostic commands **)
   280 
   284 
   281 fun code_depgr thy consts =
   285 fun code_depgr thy consts =
   282   let
   286   let
   283     val gr = make thy consts;
   287     val (_, gr) = make thy consts;
   284     val select = Graph.all_succs gr consts;
   288     val select = Graph.all_succs gr consts;
   285   in
   289   in
   286     gr
   290     gr
   287     |> not (null consts) ? Graph.subgraph (member (op =) select) 
   291     |> not (null consts) ? Graph.subgraph (member (op =) select) 
   288     |> Graph.map_nodes ((apsnd o map o apfst) (AxClass.overload thy))
   292     |> Graph.map_nodes ((apsnd o map o apfst) (AxClass.overload thy))