src/HOL/Tools/recfun_codegen.ML
changeset 15257 19dcdea98649
parent 14981 e73f8140af78
child 15321 694f9d3ce90d
equal deleted inserted replaced
15256:9237f388fbb1 15257:19dcdea98649
    60   end handle TERM _ => (warn thm; p);
    60   end handle TERM _ => (warn thm; p);
    61 
    61 
    62 fun get_equations thy (s, T) =
    62 fun get_equations thy (s, T) =
    63   (case Symtab.lookup (CodegenData.get thy, s) of
    63   (case Symtab.lookup (CodegenData.get thy, s) of
    64      None => []
    64      None => []
    65    | Some thms => filter (fn thm => is_instance thy T
    65    | Some thms => preprocess thy (filter (fn thm => is_instance thy T
    66        (snd (const_of (prop_of thm)))) thms);
    66        (snd (const_of (prop_of thm)))) thms));
    67 
    67 
    68 fun mk_poly_id thy (s, T) = mk_const_id (sign_of thy) s ^
    68 fun mk_poly_id thy (s, T) = mk_const_id (sign_of thy) s ^
    69   (case get_defn thy s T of
    69   (case get_defn thy s T of
    70      Some (_, Some i) => "_def" ^ string_of_int i
    70      Some (_, Some i) => "_def" ^ string_of_int i
    71    | _ => "");
    71    | _ => "");
   131            if dname = dep then gr else Graph.add_edge (dname, dep) gr
   131            if dname = dep then gr else Graph.add_edge (dname, dep) gr
   132          else if s = dep then gr else Graph.add_edge (s, dep) gr)
   132          else if s = dep then gr else Graph.add_edge (s, dep) gr)
   133   end;
   133   end;
   134 
   134 
   135 fun recfun_codegen thy gr dep brack t = (case strip_comb t of
   135 fun recfun_codegen thy gr dep brack t = (case strip_comb t of
   136     (Const p, ts) => (case get_equations thy p of
   136     (Const (p as (s, T)), ts) => (case (get_equations thy p, get_assoc_code thy s T) of
   137        [] => None
   137        ([], _) => None
   138      | eqns =>
   138      | (_, Some _) => None
       
   139      | (eqns, None) =>
   139         let val (gr', ps) = foldl_map (invoke_codegen thy dep true) (gr, ts)
   140         let val (gr', ps) = foldl_map (invoke_codegen thy dep true) (gr, ts)
   140         in
   141         in
   141           Some (add_rec_funs thy gr' dep (map prop_of eqns),
   142           Some (add_rec_funs thy gr' dep (map prop_of eqns),
   142             mk_app brack (Pretty.str (mk_poly_id thy p)) ps)
   143             mk_app brack (Pretty.str (mk_poly_id thy p)) ps)
   143         end)
   144         end)