src/Pure/Tools/codegen_funcgr.ML
author haftmann
Tue, 30 Jan 2007 08:21:22 +0100
changeset 22212 079de24eee65
parent 22198 226d29db8e0a
child 22223 69d4b98f4c47
permissions -rw-r--r--
added interface for plugging in preprocessors
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
20600
6d75e02ed285 added codegen_data
haftmann
parents:
diff changeset
     1
(*  Title:      Pure/Tools/codegen_funcgr.ML
6d75e02ed285 added codegen_data
haftmann
parents:
diff changeset
     2
    ID:         $Id$
6d75e02ed285 added codegen_data
haftmann
parents:
diff changeset
     3
    Author:     Florian Haftmann, TU Muenchen
6d75e02ed285 added codegen_data
haftmann
parents:
diff changeset
     4
22185
haftmann
parents: 22039
diff changeset
     5
Retrieving, normalizing and structuring defining equations
20855
9f60d493c8fe clarified header comments
haftmann
parents: 20835
diff changeset
     6
in graph with explicit dependencies.
20600
6d75e02ed285 added codegen_data
haftmann
parents:
diff changeset
     7
*)
6d75e02ed285 added codegen_data
haftmann
parents:
diff changeset
     8
6d75e02ed285 added codegen_data
haftmann
parents:
diff changeset
     9
signature CODEGEN_FUNCGR =
6d75e02ed285 added codegen_data
haftmann
parents:
diff changeset
    10
sig
22212
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
    11
  type T
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
    12
  val timing: bool ref
21120
e333c844b057 refined algorithm
haftmann
parents: 20938
diff changeset
    13
  val funcs: T -> CodegenConsts.const -> thm list
e333c844b057 refined algorithm
haftmann
parents: 20938
diff changeset
    14
  val typ: T -> CodegenConsts.const -> typ
e333c844b057 refined algorithm
haftmann
parents: 20938
diff changeset
    15
  val deps: T -> CodegenConsts.const list -> CodegenConsts.const list list
e333c844b057 refined algorithm
haftmann
parents: 20938
diff changeset
    16
  val all: T -> CodegenConsts.const list
22212
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
    17
  val pretty: theory -> T -> Pretty.T
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
    18
end
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
    19
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
    20
signature CODEGEN_FUNCGR_RETRIEVAL =
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
    21
sig
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
    22
  type T (* = CODEGEN_FUNCGR.T *)
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
    23
  val make: theory -> CodegenConsts.const list -> T
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
    24
  val make_consts: theory -> CodegenConsts.const list -> CodegenConsts.const list * T
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
    25
  val make_term: theory -> (T -> (thm -> thm) -> cterm -> thm -> 'a) -> cterm -> 'a * T
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
    26
  val init: theory -> theory
20600
6d75e02ed285 added codegen_data
haftmann
parents:
diff changeset
    27
end;
6d75e02ed285 added codegen_data
haftmann
parents:
diff changeset
    28
22212
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
    29
structure CodegenFuncgr = (*signature is added later*)
20600
6d75e02ed285 added codegen_data
haftmann
parents:
diff changeset
    30
struct
6d75e02ed285 added codegen_data
haftmann
parents:
diff changeset
    31
22212
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
    32
(** the graph type **)
20600
6d75e02ed285 added codegen_data
haftmann
parents:
diff changeset
    33
6d75e02ed285 added codegen_data
haftmann
parents:
diff changeset
    34
structure Constgraph = GraphFun (
6d75e02ed285 added codegen_data
haftmann
parents:
diff changeset
    35
  type key = CodegenConsts.const;
6d75e02ed285 added codegen_data
haftmann
parents:
diff changeset
    36
  val ord = CodegenConsts.const_ord;
6d75e02ed285 added codegen_data
haftmann
parents:
diff changeset
    37
);
6d75e02ed285 added codegen_data
haftmann
parents:
diff changeset
    38
6d75e02ed285 added codegen_data
haftmann
parents:
diff changeset
    39
type T = (typ * thm list) Constgraph.T;
6d75e02ed285 added codegen_data
haftmann
parents:
diff changeset
    40
22185
haftmann
parents: 22039
diff changeset
    41
fun funcs funcgr =
haftmann
parents: 22039
diff changeset
    42
  these o Option.map snd o try (Constgraph.get_node funcgr);
haftmann
parents: 22039
diff changeset
    43
haftmann
parents: 22039
diff changeset
    44
fun typ funcgr =
haftmann
parents: 22039
diff changeset
    45
  fst o Constgraph.get_node funcgr;
haftmann
parents: 22039
diff changeset
    46
haftmann
parents: 22039
diff changeset
    47
fun deps funcgr cs =
haftmann
parents: 22039
diff changeset
    48
  let
haftmann
parents: 22039
diff changeset
    49
    val conn = Constgraph.strong_conn funcgr;
haftmann
parents: 22039
diff changeset
    50
    val order = rev conn;
haftmann
parents: 22039
diff changeset
    51
  in
haftmann
parents: 22039
diff changeset
    52
    (map o filter) (member (op =) (Constgraph.all_succs funcgr cs)) order
haftmann
parents: 22039
diff changeset
    53
    |> filter_out null
haftmann
parents: 22039
diff changeset
    54
  end;
haftmann
parents: 22039
diff changeset
    55
haftmann
parents: 22039
diff changeset
    56
fun all funcgr = Constgraph.keys funcgr;
haftmann
parents: 22039
diff changeset
    57
22212
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
    58
fun pretty thy funcgr =
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
    59
  AList.make (snd o Constgraph.get_node funcgr) (Constgraph.keys funcgr)
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
    60
  |> (map o apfst) (CodegenConsts.string_of_const thy)
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
    61
  |> sort (string_ord o pairself fst)
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
    62
  |> map (fn (s, thms) =>
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
    63
       (Pretty.block o Pretty.fbreaks) (
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
    64
         Pretty.str s
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
    65
         :: map Display.pretty_thm thms
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
    66
       ))
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
    67
  |> Pretty.chunks;
20600
6d75e02ed285 added codegen_data
haftmann
parents:
diff changeset
    68
6d75e02ed285 added codegen_data
haftmann
parents:
diff changeset
    69
22185
haftmann
parents: 22039
diff changeset
    70
(** generic combinators **)
20600
6d75e02ed285 added codegen_data
haftmann
parents:
diff changeset
    71
22185
haftmann
parents: 22039
diff changeset
    72
fun fold_consts f thms =
haftmann
parents: 22039
diff changeset
    73
  thms
haftmann
parents: 22039
diff changeset
    74
  |> maps (op :: o swap o apfst (snd o strip_comb) o Logic.dest_equals o Drule.plain_prop_of)
haftmann
parents: 22039
diff changeset
    75
  |> (fold o fold_aterms) (fn Const c => f c | _ => I);
20600
6d75e02ed285 added codegen_data
haftmann
parents:
diff changeset
    76
22185
haftmann
parents: 22039
diff changeset
    77
fun consts_of (const, []) = []
haftmann
parents: 22039
diff changeset
    78
  | consts_of (const, thms as thm :: _) = 
haftmann
parents: 22039
diff changeset
    79
      let
haftmann
parents: 22039
diff changeset
    80
        val thy = Thm.theory_of_thm thm;
haftmann
parents: 22039
diff changeset
    81
        val is_refl = curry CodegenConsts.eq_const const;
haftmann
parents: 22039
diff changeset
    82
        fun the_const c = case try (CodegenConsts.norm_of_typ thy) c
haftmann
parents: 22039
diff changeset
    83
         of SOME const => if is_refl const then I else insert CodegenConsts.eq_const const
haftmann
parents: 22039
diff changeset
    84
          | NONE => I
haftmann
parents: 22039
diff changeset
    85
      in fold_consts the_const thms [] end;
20600
6d75e02ed285 added codegen_data
haftmann
parents:
diff changeset
    86
22185
haftmann
parents: 22039
diff changeset
    87
fun insts_of thy algebra c ty_decl ty =
20600
6d75e02ed285 added codegen_data
haftmann
parents:
diff changeset
    88
  let
22185
haftmann
parents: 22039
diff changeset
    89
    val tys_decl = Sign.const_typargs thy (c, ty_decl);
20600
6d75e02ed285 added codegen_data
haftmann
parents:
diff changeset
    90
    val tys = Sign.const_typargs thy (c, ty);
22185
haftmann
parents: 22039
diff changeset
    91
    fun classrel (x, _) _ = x;
20600
6d75e02ed285 added codegen_data
haftmann
parents:
diff changeset
    92
    fun constructor tyco xs class =
6d75e02ed285 added codegen_data
haftmann
parents:
diff changeset
    93
      (tyco, class) :: maps (maps fst) xs;
6d75e02ed285 added codegen_data
haftmann
parents:
diff changeset
    94
    fun variable (TVar (_, sort)) = map (pair []) sort
6d75e02ed285 added codegen_data
haftmann
parents:
diff changeset
    95
      | variable (TFree (_, sort)) = map (pair []) sort;
6d75e02ed285 added codegen_data
haftmann
parents:
diff changeset
    96
    fun mk_inst ty (TVar (_, sort)) = cons (ty, sort)
6d75e02ed285 added codegen_data
haftmann
parents:
diff changeset
    97
      | mk_inst ty (TFree (_, sort)) = cons (ty, sort)
22198
226d29db8e0a refined algorithm
haftmann
parents: 22185
diff changeset
    98
      | mk_inst (Type (_, tys1)) (Type (_, tys2)) = fold2 mk_inst tys1 tys2;
21120
e333c844b057 refined algorithm
haftmann
parents: 20938
diff changeset
    99
    fun of_sort_deriv (ty, sort) =
22185
haftmann
parents: 22039
diff changeset
   100
      Sorts.of_sort_derivation (Sign.pp thy) algebra
21120
e333c844b057 refined algorithm
haftmann
parents: 20938
diff changeset
   101
        { classrel = classrel, constructor = constructor, variable = variable }
e333c844b057 refined algorithm
haftmann
parents: 20938
diff changeset
   102
        (ty, sort)
20600
6d75e02ed285 added codegen_data
haftmann
parents:
diff changeset
   103
  in
21120
e333c844b057 refined algorithm
haftmann
parents: 20938
diff changeset
   104
    flat (maps of_sort_deriv (fold2 mk_inst tys tys_decl []))
20600
6d75e02ed285 added codegen_data
haftmann
parents:
diff changeset
   105
  end;
6d75e02ed285 added codegen_data
haftmann
parents:
diff changeset
   106
22212
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
   107
fun drop_classes thy tfrees thm =
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
   108
  let
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
   109
    val (_, thm') = Thm.varifyT' [] thm;
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
   110
    val tvars = Term.add_tvars (Thm.prop_of thm') [];
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
   111
    val unconstr = map (Thm.ctyp_of thy o TVar) tvars;
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
   112
    val instmap = map2 (fn (v_i, _) => fn (v, sort) => pairself (Thm.ctyp_of thy)
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
   113
      (TVar (v_i, []), TFree (v, sort))) tvars tfrees;
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
   114
  in
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
   115
    thm'
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
   116
    |> fold Thm.unconstrainT unconstr
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
   117
    |> Thm.instantiate (instmap, [])
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
   118
    |> Tactic.rule_by_tactic ((REPEAT o CHANGED o ALLGOALS o Tactic.resolve_tac) (AxClass.class_intros thy))
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
   119
  end;
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
   120
22039
9bc8058250a7 slight cleanups
haftmann
parents: 22021
diff changeset
   121
22185
haftmann
parents: 22039
diff changeset
   122
(** graph algorithm **)
20600
6d75e02ed285 added codegen_data
haftmann
parents:
diff changeset
   123
22185
haftmann
parents: 22039
diff changeset
   124
val timing = ref false;
20600
6d75e02ed285 added codegen_data
haftmann
parents:
diff changeset
   125
22185
haftmann
parents: 22039
diff changeset
   126
local
20600
6d75e02ed285 added codegen_data
haftmann
parents:
diff changeset
   127
22185
haftmann
parents: 22039
diff changeset
   128
exception INVALID of CodegenConsts.const list * string;
20600
6d75e02ed285 added codegen_data
haftmann
parents:
diff changeset
   129
22198
226d29db8e0a refined algorithm
haftmann
parents: 22185
diff changeset
   130
fun resort_thms algebra tap_typ [] = []
226d29db8e0a refined algorithm
haftmann
parents: 22185
diff changeset
   131
  | resort_thms algebra tap_typ (thms as thm :: _) =
20600
6d75e02ed285 added codegen_data
haftmann
parents:
diff changeset
   132
      let
22198
226d29db8e0a refined algorithm
haftmann
parents: 22185
diff changeset
   133
        val thy = Thm.theory_of_thm thm;
226d29db8e0a refined algorithm
haftmann
parents: 22185
diff changeset
   134
        val cs = fold_consts (insert (op =)) thms [];
226d29db8e0a refined algorithm
haftmann
parents: 22185
diff changeset
   135
        fun match_const c (ty, ty_decl) =
20600
6d75e02ed285 added codegen_data
haftmann
parents:
diff changeset
   136
          let
22198
226d29db8e0a refined algorithm
haftmann
parents: 22185
diff changeset
   137
            val tys = CodegenConsts.typargs thy (c, ty);
226d29db8e0a refined algorithm
haftmann
parents: 22185
diff changeset
   138
            val sorts = map (snd o dest_TVar) (CodegenConsts.typargs thy (c, ty_decl));
226d29db8e0a refined algorithm
haftmann
parents: 22185
diff changeset
   139
          in fold2 (curry (CodegenConsts.typ_sort_inst algebra)) tys sorts end;
226d29db8e0a refined algorithm
haftmann
parents: 22185
diff changeset
   140
        fun match (c_ty as (c, ty)) =
226d29db8e0a refined algorithm
haftmann
parents: 22185
diff changeset
   141
          case tap_typ c_ty
226d29db8e0a refined algorithm
haftmann
parents: 22185
diff changeset
   142
           of SOME ty_decl => match_const c (ty, ty_decl)
226d29db8e0a refined algorithm
haftmann
parents: 22185
diff changeset
   143
            | NONE => I;
226d29db8e0a refined algorithm
haftmann
parents: 22185
diff changeset
   144
        val tvars = fold match cs Vartab.empty;
226d29db8e0a refined algorithm
haftmann
parents: 22185
diff changeset
   145
      in map (CodegenFunc.inst_thm tvars) thms end;
20600
6d75e02ed285 added codegen_data
haftmann
parents:
diff changeset
   146
22198
226d29db8e0a refined algorithm
haftmann
parents: 22185
diff changeset
   147
fun resort_funcss thy algebra funcgr =
226d29db8e0a refined algorithm
haftmann
parents: 22185
diff changeset
   148
  let
226d29db8e0a refined algorithm
haftmann
parents: 22185
diff changeset
   149
    val typ_funcgr = try (fst o Constgraph.get_node funcgr o CodegenConsts.norm_of_typ thy);
226d29db8e0a refined algorithm
haftmann
parents: 22185
diff changeset
   150
    fun resort_dep (const, thms) = (const, resort_thms algebra typ_funcgr thms)
226d29db8e0a refined algorithm
haftmann
parents: 22185
diff changeset
   151
      handle Sorts.CLASS_ERROR e => raise INVALID ([const], Sorts.msg_class_error (Sign.pp thy) e
226d29db8e0a refined algorithm
haftmann
parents: 22185
diff changeset
   152
                    ^ ",\nfor constant " ^ CodegenConsts.string_of_const thy const
226d29db8e0a refined algorithm
haftmann
parents: 22185
diff changeset
   153
                    ^ "\nin defining equations\n"
226d29db8e0a refined algorithm
haftmann
parents: 22185
diff changeset
   154
                    ^ (cat_lines o map string_of_thm) thms)
226d29db8e0a refined algorithm
haftmann
parents: 22185
diff changeset
   155
    fun resort_rec tap_typ (const, []) = (true, (const, []))
226d29db8e0a refined algorithm
haftmann
parents: 22185
diff changeset
   156
      | resort_rec tap_typ (const, thms as thm :: _) =
226d29db8e0a refined algorithm
haftmann
parents: 22185
diff changeset
   157
          let
226d29db8e0a refined algorithm
haftmann
parents: 22185
diff changeset
   158
            val ty = CodegenFunc.typ_func thm;
226d29db8e0a refined algorithm
haftmann
parents: 22185
diff changeset
   159
            val thms' as thm' :: _ = resort_thms algebra tap_typ thms
226d29db8e0a refined algorithm
haftmann
parents: 22185
diff changeset
   160
            val ty' = CodegenFunc.typ_func thm';
226d29db8e0a refined algorithm
haftmann
parents: 22185
diff changeset
   161
          in (Sign.typ_equiv thy (ty, ty'), (const, thms')) end;
226d29db8e0a refined algorithm
haftmann
parents: 22185
diff changeset
   162
    fun resort_recs funcss =
226d29db8e0a refined algorithm
haftmann
parents: 22185
diff changeset
   163
      let
226d29db8e0a refined algorithm
haftmann
parents: 22185
diff changeset
   164
        fun tap_typ c_ty = case try (CodegenConsts.norm_of_typ thy) c_ty
226d29db8e0a refined algorithm
haftmann
parents: 22185
diff changeset
   165
         of SOME const => AList.lookup (CodegenConsts.eq_const) funcss const
226d29db8e0a refined algorithm
haftmann
parents: 22185
diff changeset
   166
              |> these
226d29db8e0a refined algorithm
haftmann
parents: 22185
diff changeset
   167
              |> try hd
226d29db8e0a refined algorithm
haftmann
parents: 22185
diff changeset
   168
              |> Option.map CodegenFunc.typ_func
226d29db8e0a refined algorithm
haftmann
parents: 22185
diff changeset
   169
          | NONE => NONE;
226d29db8e0a refined algorithm
haftmann
parents: 22185
diff changeset
   170
        val (unchangeds, funcss') = split_list (map (resort_rec tap_typ) funcss);
226d29db8e0a refined algorithm
haftmann
parents: 22185
diff changeset
   171
        val unchanged = fold (fn x => fn y => x andalso y) unchangeds true;
226d29db8e0a refined algorithm
haftmann
parents: 22185
diff changeset
   172
      in (unchanged, funcss') end;
226d29db8e0a refined algorithm
haftmann
parents: 22185
diff changeset
   173
    fun resort_rec_until funcss =
226d29db8e0a refined algorithm
haftmann
parents: 22185
diff changeset
   174
      let
226d29db8e0a refined algorithm
haftmann
parents: 22185
diff changeset
   175
        val (unchanged, funcss') = resort_recs funcss;
226d29db8e0a refined algorithm
haftmann
parents: 22185
diff changeset
   176
      in if unchanged then funcss' else resort_rec_until funcss' end;
226d29db8e0a refined algorithm
haftmann
parents: 22185
diff changeset
   177
  in map resort_dep #> resort_rec_until end;
22039
9bc8058250a7 slight cleanups
haftmann
parents: 22021
diff changeset
   178
22185
haftmann
parents: 22039
diff changeset
   179
fun classop_const thy algebra class classop tyco =
haftmann
parents: 22039
diff changeset
   180
  let
haftmann
parents: 22039
diff changeset
   181
    val sorts = Sorts.mg_domain algebra tyco [class]
haftmann
parents: 22039
diff changeset
   182
    val (var, _) = try (AxClass.params_of_class thy) class |> the_default ("'a", []);
haftmann
parents: 22039
diff changeset
   183
    val vs = Name.names (Name.declare var Name.context) "'a" sorts;
haftmann
parents: 22039
diff changeset
   184
    val arity_typ = Type (tyco, map TFree vs);
haftmann
parents: 22039
diff changeset
   185
  in (classop, [arity_typ]) end;
haftmann
parents: 22039
diff changeset
   186
haftmann
parents: 22039
diff changeset
   187
fun instances_of thy algebra insts =
haftmann
parents: 22039
diff changeset
   188
  let
haftmann
parents: 22039
diff changeset
   189
    val thy_classes = (#classes o Sorts.rep_algebra o Sign.classes_of) thy;
haftmann
parents: 22039
diff changeset
   190
    fun all_classops tyco class =
haftmann
parents: 22039
diff changeset
   191
      try (AxClass.params_of_class thy) class
haftmann
parents: 22039
diff changeset
   192
      |> Option.map snd
haftmann
parents: 22039
diff changeset
   193
      |> these
haftmann
parents: 22039
diff changeset
   194
      |> map (fn (c, _) => classop_const thy algebra class c tyco)
haftmann
parents: 22039
diff changeset
   195
      |> map (CodegenConsts.norm thy)
haftmann
parents: 22039
diff changeset
   196
  in
haftmann
parents: 22039
diff changeset
   197
    Symtab.empty
haftmann
parents: 22039
diff changeset
   198
    |> fold (fn (tyco, class) =>
haftmann
parents: 22039
diff changeset
   199
        Symtab.map_default (tyco, []) (insert (op =) class)) insts
haftmann
parents: 22039
diff changeset
   200
    |> (fn tab => Symtab.fold (fn (tyco, classes) => append (maps (all_classops tyco)
haftmann
parents: 22039
diff changeset
   201
         (Graph.all_succs thy_classes classes))) tab [])
haftmann
parents: 22039
diff changeset
   202
  end;
haftmann
parents: 22039
diff changeset
   203
haftmann
parents: 22039
diff changeset
   204
fun instances_of_consts thy algebra funcgr consts =
20600
6d75e02ed285 added codegen_data
haftmann
parents:
diff changeset
   205
  let
22185
haftmann
parents: 22039
diff changeset
   206
    fun inst (const as (c, ty)) = case try (CodegenConsts.norm_of_typ thy) const
haftmann
parents: 22039
diff changeset
   207
     of SOME const => insts_of thy algebra c (fst (Constgraph.get_node funcgr const)) ty
haftmann
parents: 22039
diff changeset
   208
      | NONE => [];
haftmann
parents: 22039
diff changeset
   209
  in
haftmann
parents: 22039
diff changeset
   210
    []
haftmann
parents: 22039
diff changeset
   211
    |> fold (fold (insert (op =)) o inst) consts
haftmann
parents: 22039
diff changeset
   212
    |> instances_of thy algebra
haftmann
parents: 22039
diff changeset
   213
  end;
haftmann
parents: 22039
diff changeset
   214
22212
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
   215
fun ensure_const' rewrites thy algebra funcgr const auxgr =
22185
haftmann
parents: 22039
diff changeset
   216
  if can (Constgraph.get_node funcgr) const
haftmann
parents: 22039
diff changeset
   217
    then (NONE, auxgr)
haftmann
parents: 22039
diff changeset
   218
  else if can (Constgraph.get_node auxgr) const
haftmann
parents: 22039
diff changeset
   219
    then (SOME const, auxgr)
haftmann
parents: 22039
diff changeset
   220
  else if is_some (CodegenData.get_datatype_of_constr thy const) then
haftmann
parents: 22039
diff changeset
   221
    auxgr
haftmann
parents: 22039
diff changeset
   222
    |> Constgraph.new_node (const, [])
haftmann
parents: 22039
diff changeset
   223
    |> pair (SOME const)
haftmann
parents: 22039
diff changeset
   224
  else let
22212
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
   225
    val thms = CodegenData.these_funcs thy const
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
   226
      |> map (CodegenFunc.rewrite_func (rewrites thy))
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
   227
      |> CodegenFunc.norm_args
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
   228
      |> CodegenFunc.norm_varnames CodegenNames.purify_tvar CodegenNames.purify_var;
22185
haftmann
parents: 22039
diff changeset
   229
    val rhs = consts_of (const, thms);
haftmann
parents: 22039
diff changeset
   230
  in
haftmann
parents: 22039
diff changeset
   231
    auxgr
haftmann
parents: 22039
diff changeset
   232
    |> Constgraph.new_node (const, thms)
22212
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
   233
    |> fold_map (ensure_const rewrites thy algebra funcgr) rhs
22185
haftmann
parents: 22039
diff changeset
   234
    |-> (fn rhs' => fold (fn SOME const' => Constgraph.add_edge (const, const')
haftmann
parents: 22039
diff changeset
   235
                           | NONE => I) rhs')
haftmann
parents: 22039
diff changeset
   236
    |> pair (SOME const)
haftmann
parents: 22039
diff changeset
   237
  end
22212
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
   238
and ensure_const rewrites thy algebra funcgr const =
22185
haftmann
parents: 22039
diff changeset
   239
  let
haftmann
parents: 22039
diff changeset
   240
    val timeap = if !timing
haftmann
parents: 22039
diff changeset
   241
      then Output.timeap_msg ("time for " ^ CodegenConsts.string_of_const thy const)
haftmann
parents: 22039
diff changeset
   242
      else I;
22212
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
   243
  in timeap (ensure_const' rewrites thy algebra funcgr const) end;
22185
haftmann
parents: 22039
diff changeset
   244
22212
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
   245
fun merge_funcss rewrites thy algebra raw_funcss funcgr =
22185
haftmann
parents: 22039
diff changeset
   246
  let
22198
226d29db8e0a refined algorithm
haftmann
parents: 22185
diff changeset
   247
    val funcss = resort_funcss thy algebra funcgr raw_funcss;
226d29db8e0a refined algorithm
haftmann
parents: 22185
diff changeset
   248
    fun classop_typ (c, [typarg]) class =
226d29db8e0a refined algorithm
haftmann
parents: 22185
diff changeset
   249
      let
226d29db8e0a refined algorithm
haftmann
parents: 22185
diff changeset
   250
        val ty = Sign.the_const_type thy c;
226d29db8e0a refined algorithm
haftmann
parents: 22185
diff changeset
   251
        val inst = case typarg
226d29db8e0a refined algorithm
haftmann
parents: 22185
diff changeset
   252
         of Type (tyco, _) => classop_const thy algebra class c tyco
226d29db8e0a refined algorithm
haftmann
parents: 22185
diff changeset
   253
              |> snd
226d29db8e0a refined algorithm
haftmann
parents: 22185
diff changeset
   254
              |> the_single
226d29db8e0a refined algorithm
haftmann
parents: 22185
diff changeset
   255
              |> Logic.varifyT
226d29db8e0a refined algorithm
haftmann
parents: 22185
diff changeset
   256
          | _ => TVar (("'a", 0), [class]);
226d29db8e0a refined algorithm
haftmann
parents: 22185
diff changeset
   257
      in Term.map_type_tvar (K inst) ty end;
22185
haftmann
parents: 22039
diff changeset
   258
    fun default_typ (const as (c, tys)) = case CodegenData.tap_typ thy const
haftmann
parents: 22039
diff changeset
   259
     of SOME ty => ty
22198
226d29db8e0a refined algorithm
haftmann
parents: 22185
diff changeset
   260
      | NONE => (case AxClass.class_of_param thy c
226d29db8e0a refined algorithm
haftmann
parents: 22185
diff changeset
   261
         of SOME class => classop_typ const class
226d29db8e0a refined algorithm
haftmann
parents: 22185
diff changeset
   262
          | NONE => Sign.the_const_type thy c)
226d29db8e0a refined algorithm
haftmann
parents: 22185
diff changeset
   263
    fun typ_func (const as (c, tys)) thm =
226d29db8e0a refined algorithm
haftmann
parents: 22185
diff changeset
   264
      let
226d29db8e0a refined algorithm
haftmann
parents: 22185
diff changeset
   265
        val ty = CodegenFunc.typ_func thm;
226d29db8e0a refined algorithm
haftmann
parents: 22185
diff changeset
   266
      in case AxClass.class_of_param thy c
226d29db8e0a refined algorithm
haftmann
parents: 22185
diff changeset
   267
       of SOME class => (case tys
226d29db8e0a refined algorithm
haftmann
parents: 22185
diff changeset
   268
           of [Type _] => let val ty_decl = classop_typ const class
226d29db8e0a refined algorithm
haftmann
parents: 22185
diff changeset
   269
              in if Sign.typ_equiv thy (ty, ty_decl) then ty
226d29db8e0a refined algorithm
haftmann
parents: 22185
diff changeset
   270
              else raise raise INVALID ([const], "Illegal instantation for class operation "
226d29db8e0a refined algorithm
haftmann
parents: 22185
diff changeset
   271
                    ^ CodegenConsts.string_of_const thy const
226d29db8e0a refined algorithm
haftmann
parents: 22185
diff changeset
   272
                    ^ ":\n" ^ CodegenConsts.string_of_typ thy ty_decl
226d29db8e0a refined algorithm
haftmann
parents: 22185
diff changeset
   273
                    ^ "\nto " ^ CodegenConsts.string_of_typ thy ty)
226d29db8e0a refined algorithm
haftmann
parents: 22185
diff changeset
   274
              end
226d29db8e0a refined algorithm
haftmann
parents: 22185
diff changeset
   275
            | _ => ty)
226d29db8e0a refined algorithm
haftmann
parents: 22185
diff changeset
   276
        | NONE => ty
226d29db8e0a refined algorithm
haftmann
parents: 22185
diff changeset
   277
      end;
22185
haftmann
parents: 22039
diff changeset
   278
    fun add_funcs (const, thms as thm :: _) =
22198
226d29db8e0a refined algorithm
haftmann
parents: 22185
diff changeset
   279
          Constgraph.new_node (const, (typ_func const thm, thms))
22185
haftmann
parents: 22039
diff changeset
   280
      | add_funcs (const, []) =
haftmann
parents: 22039
diff changeset
   281
          Constgraph.new_node (const, (default_typ const, []));
haftmann
parents: 22039
diff changeset
   282
    fun add_deps (funcs as (const, thms)) funcgr =
haftmann
parents: 22039
diff changeset
   283
      let
haftmann
parents: 22039
diff changeset
   284
        val deps = consts_of funcs;
haftmann
parents: 22039
diff changeset
   285
        val insts = instances_of_consts thy algebra funcgr
haftmann
parents: 22039
diff changeset
   286
          (fold_consts (insert (op =)) thms []);
haftmann
parents: 22039
diff changeset
   287
      in
haftmann
parents: 22039
diff changeset
   288
        funcgr
22212
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
   289
        |> ensure_consts' rewrites thy algebra insts
22185
haftmann
parents: 22039
diff changeset
   290
        |> fold (curry Constgraph.add_edge const) deps
haftmann
parents: 22039
diff changeset
   291
        |> fold (curry Constgraph.add_edge const) insts
haftmann
parents: 22039
diff changeset
   292
       end;
20600
6d75e02ed285 added codegen_data
haftmann
parents:
diff changeset
   293
  in
6d75e02ed285 added codegen_data
haftmann
parents:
diff changeset
   294
    funcgr
22185
haftmann
parents: 22039
diff changeset
   295
    |> fold add_funcs funcss
haftmann
parents: 22039
diff changeset
   296
    |> fold add_deps funcss
20600
6d75e02ed285 added codegen_data
haftmann
parents:
diff changeset
   297
  end
22212
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
   298
and ensure_consts' rewrites thy algebra cs funcgr =
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
   299
  fold (snd oo ensure_const rewrites thy algebra funcgr) cs Constgraph.empty
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
   300
  |> (fn auxgr => fold (merge_funcss rewrites thy algebra)
20600
6d75e02ed285 added codegen_data
haftmann
parents:
diff changeset
   301
       (map (AList.make (Constgraph.get_node auxgr))
21387
5d3d340cb783 clarified code for building function equation system; explicit check of type discipline
haftmann
parents: 21196
diff changeset
   302
       (rev (Constgraph.strong_conn auxgr))) funcgr)
22185
haftmann
parents: 22039
diff changeset
   303
  handle INVALID (cs', msg) => raise INVALID (fold (insert CodegenConsts.eq_const) cs' cs, msg);
20600
6d75e02ed285 added codegen_data
haftmann
parents:
diff changeset
   304
22212
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
   305
fun ensure_consts rewrites thy consts funcgr =
22185
haftmann
parents: 22039
diff changeset
   306
  let
haftmann
parents: 22039
diff changeset
   307
    val algebra = CodegenData.coregular_algebra thy
22212
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
   308
  in ensure_consts' rewrites thy algebra consts funcgr
22185
haftmann
parents: 22039
diff changeset
   309
    handle INVALID (cs', msg) => error (msg ^ ",\nwhile preprocessing equations for constant(s) "
haftmann
parents: 22039
diff changeset
   310
    ^ commas (map (CodegenConsts.string_of_const thy) cs'))
haftmann
parents: 22039
diff changeset
   311
  end;
haftmann
parents: 22039
diff changeset
   312
20600
6d75e02ed285 added codegen_data
haftmann
parents:
diff changeset
   313
in
6d75e02ed285 added codegen_data
haftmann
parents:
diff changeset
   314
22212
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
   315
(** retrieval interfaces **)
20600
6d75e02ed285 added codegen_data
haftmann
parents:
diff changeset
   316
22212
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
   317
val ensure_consts = ensure_consts;
21120
e333c844b057 refined algorithm
haftmann
parents: 20938
diff changeset
   318
22212
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
   319
fun check_consts rewrites thy consts funcgr =
22185
haftmann
parents: 22039
diff changeset
   320
  let
haftmann
parents: 22039
diff changeset
   321
    val algebra = CodegenData.coregular_algebra thy;
haftmann
parents: 22039
diff changeset
   322
    fun try_const const funcgr =
22212
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
   323
      (SOME const, ensure_consts' rewrites thy algebra [const] funcgr)
22185
haftmann
parents: 22039
diff changeset
   324
      handle INVALID (cs', msg) => (NONE, funcgr);
22212
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
   325
    val (consts', funcgr') = fold_map try_const consts funcgr;
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
   326
  in (map_filter I consts', funcgr') end;
22185
haftmann
parents: 22039
diff changeset
   327
22212
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
   328
fun ensure_consts_term rewrites thy f ct funcgr =
21120
e333c844b057 refined algorithm
haftmann
parents: 20938
diff changeset
   329
  let
22212
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
   330
    fun rhs_conv conv thm =
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
   331
      let
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
   332
        val thm' = (conv o snd o Drule.dest_equals o Thm.cprop_of) thm;
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
   333
      in Thm.transitive thm thm' end
21120
e333c844b057 refined algorithm
haftmann
parents: 20938
diff changeset
   334
    val _ = Sign.no_vars (Sign.pp thy) (Thm.term_of ct);
e333c844b057 refined algorithm
haftmann
parents: 20938
diff changeset
   335
    val _ = Term.fold_types (Type.no_tvars #> K I) (Thm.term_of ct) ();
22212
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
   336
    val thm1 = CodegenData.preprocess_cterm ct
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
   337
      |> fold (rhs_conv o MetaSimplifier.rewrite false o single) (rewrites thy);
21120
e333c844b057 refined algorithm
haftmann
parents: 20938
diff changeset
   338
    val ct' = Drule.dest_equals_rhs (Thm.cprop_of thm1);
e333c844b057 refined algorithm
haftmann
parents: 20938
diff changeset
   339
    val consts = CodegenConsts.consts_of thy (Thm.term_of ct');
22212
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
   340
    val funcgr' = ensure_consts rewrites thy consts funcgr;
22198
226d29db8e0a refined algorithm
haftmann
parents: 22185
diff changeset
   341
    val algebra = CodegenData.coregular_algebra thy;
21120
e333c844b057 refined algorithm
haftmann
parents: 20938
diff changeset
   342
    val (_, thm2) = Thm.varifyT' [] thm1;
e333c844b057 refined algorithm
haftmann
parents: 20938
diff changeset
   343
    val thm3 = Thm.reflexive (Drule.dest_equals_rhs (Thm.cprop_of thm2));
22212
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
   344
    val typ_funcgr = try (fst o Constgraph.get_node funcgr' o CodegenConsts.norm_of_typ thy);
22198
226d29db8e0a refined algorithm
haftmann
parents: 22185
diff changeset
   345
    val [thm4] = resort_thms algebra typ_funcgr [thm3];
21120
e333c844b057 refined algorithm
haftmann
parents: 20938
diff changeset
   346
    val tfrees = Term.add_tfrees (Thm.prop_of thm1) [];
e333c844b057 refined algorithm
haftmann
parents: 20938
diff changeset
   347
    fun inst thm =
e333c844b057 refined algorithm
haftmann
parents: 20938
diff changeset
   348
      let
e333c844b057 refined algorithm
haftmann
parents: 20938
diff changeset
   349
        val tvars = Term.add_tvars (Thm.prop_of thm) [];
e333c844b057 refined algorithm
haftmann
parents: 20938
diff changeset
   350
        val instmap = map2 (fn (v_i, sort) => fn (v, _) => pairself (Thm.ctyp_of thy)
e333c844b057 refined algorithm
haftmann
parents: 20938
diff changeset
   351
          (TVar (v_i, sort), TFree (v, sort))) tvars tfrees;
e333c844b057 refined algorithm
haftmann
parents: 20938
diff changeset
   352
      in Thm.instantiate (instmap, []) thm end;
e333c844b057 refined algorithm
haftmann
parents: 20938
diff changeset
   353
    val thm5 = inst thm2;
e333c844b057 refined algorithm
haftmann
parents: 20938
diff changeset
   354
    val thm6 = inst thm4;
e333c844b057 refined algorithm
haftmann
parents: 20938
diff changeset
   355
    val ct'' = Drule.dest_equals_rhs (Thm.cprop_of thm6);
e333c844b057 refined algorithm
haftmann
parents: 20938
diff changeset
   356
    val cs = fold_aterms (fn Const c => cons c | _ => I) (Thm.term_of ct'') [];
e333c844b057 refined algorithm
haftmann
parents: 20938
diff changeset
   357
    val drop = drop_classes thy tfrees;
22212
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
   358
    val instdefs = instances_of_consts thy algebra funcgr' cs;
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
   359
    val funcgr'' = ensure_consts rewrites thy instdefs funcgr';
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
   360
  in (f funcgr'' drop ct'' thm5, funcgr'') end;
20600
6d75e02ed285 added codegen_data
haftmann
parents:
diff changeset
   361
6d75e02ed285 added codegen_data
haftmann
parents:
diff changeset
   362
end; (*local*)
6d75e02ed285 added codegen_data
haftmann
parents:
diff changeset
   363
22212
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
   364
end; (*struct*)
22185
haftmann
parents: 22039
diff changeset
   365
22212
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
   366
functor CodegenFuncgrRetrieval (val name: string; val rewrites: theory -> thm list) : CODEGEN_FUNCGR_RETRIEVAL =
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
   367
struct
20600
6d75e02ed285 added codegen_data
haftmann
parents:
diff changeset
   368
22212
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
   369
(** code data **)
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
   370
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
   371
type T = CodegenFuncgr.T;
20600
6d75e02ed285 added codegen_data
haftmann
parents:
diff changeset
   372
22212
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
   373
structure Funcgr = CodeDataFun
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
   374
(struct
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
   375
  val name = name;
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
   376
  type T = T;
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
   377
  val empty = CodegenFuncgr.Constgraph.empty;
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
   378
  fun merge _ _ = CodegenFuncgr.Constgraph.empty;
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
   379
  fun purge _ NONE _ = CodegenFuncgr.Constgraph.empty
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
   380
    | purge _ (SOME cs) funcgr =
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
   381
        CodegenFuncgr.Constgraph.del_nodes ((CodegenFuncgr.Constgraph.all_preds funcgr 
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
   382
          o filter (can (CodegenFuncgr.Constgraph.get_node funcgr))) cs) funcgr;
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
   383
end);
20600
6d75e02ed285 added codegen_data
haftmann
parents:
diff changeset
   384
22212
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
   385
fun make thy =
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
   386
  Funcgr.change thy o CodegenFuncgr.ensure_consts rewrites thy;
20600
6d75e02ed285 added codegen_data
haftmann
parents:
diff changeset
   387
22212
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
   388
fun make_consts thy =
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
   389
  Funcgr.change_yield thy o CodegenFuncgr.check_consts rewrites thy;
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
   390
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
   391
fun make_term thy f =
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
   392
  Funcgr.change_yield thy o CodegenFuncgr.ensure_consts_term rewrites thy f;
20600
6d75e02ed285 added codegen_data
haftmann
parents:
diff changeset
   393
22212
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
   394
val init = Funcgr.init;
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
   395
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
   396
end; (*functor*)
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
   397
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
   398
structure CodegenFuncgr : CODEGEN_FUNCGR =
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
   399
struct
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
   400
079de24eee65 added interface for plugging in preprocessors
haftmann
parents: 22198
diff changeset
   401
open CodegenFuncgr;
20600
6d75e02ed285 added codegen_data
haftmann
parents:
diff changeset
   402
6d75e02ed285 added codegen_data
haftmann
parents:
diff changeset
   403
end; (*struct*)