src/Pure/Isar/code.ML
author haftmann
Mon, 29 Sep 2008 12:32:00 +0200
changeset 28403 da9ae7774513
parent 28368 8437fb395294
child 28423 9fc3befd8191
permissions -rw-r--r--
more precise redundancy check
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
     1
(*  Title:      Pure/Isar/code.ML
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
     2
    ID:         $Id$
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
     3
    Author:     Florian Haftmann, TU Muenchen
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
     4
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
     5
Abstract executable content of theory.  Management of data dependent on
25485
33840a854e63 tuned interfaces of class module
haftmann
parents: 25462
diff changeset
     6
executable content.  Cache assumes non-concurrent processing of a single theory.
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
     7
*)
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
     8
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
     9
signature CODE =
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
    10
sig
28368
8437fb395294 clarified function transformator interface
haftmann
parents: 28359
diff changeset
    11
  val add_eqn: thm -> theory -> theory
8437fb395294 clarified function transformator interface
haftmann
parents: 28359
diff changeset
    12
  val add_nonlinear_eqn: thm -> theory -> theory
8437fb395294 clarified function transformator interface
haftmann
parents: 28359
diff changeset
    13
  val add_liberal_eqn: thm -> theory -> theory
8437fb395294 clarified function transformator interface
haftmann
parents: 28359
diff changeset
    14
  val add_default_eqn: thm -> theory -> theory
8437fb395294 clarified function transformator interface
haftmann
parents: 28359
diff changeset
    15
  val add_default_eqn_attr: Attrib.src
8437fb395294 clarified function transformator interface
haftmann
parents: 28359
diff changeset
    16
  val del_eqn: thm -> theory -> theory
8437fb395294 clarified function transformator interface
haftmann
parents: 28359
diff changeset
    17
  val del_eqns: string -> theory -> theory
8437fb395294 clarified function transformator interface
haftmann
parents: 28359
diff changeset
    18
  val add_eqnl: string * (thm * bool) list Susp.T -> theory -> theory
27557
151731493264 simpsets as pre/postprocessors; generic preprocessor now named function transformators
haftmann
parents: 26970
diff changeset
    19
  val map_pre: (MetaSimplifier.simpset -> MetaSimplifier.simpset) -> theory -> theory
151731493264 simpsets as pre/postprocessors; generic preprocessor now named function transformators
haftmann
parents: 26970
diff changeset
    20
  val map_post: (MetaSimplifier.simpset -> MetaSimplifier.simpset) -> theory -> theory
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
    21
  val add_inline: thm -> theory -> theory
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
    22
  val del_inline: thm -> theory -> theory
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
    23
  val add_post: thm -> theory -> theory
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
    24
  val del_post: thm -> theory -> theory
27609
b23c9ad0fe7d tuned code theorem bookkeeping
haftmann
parents: 27582
diff changeset
    25
  val add_functrans: string * (theory -> thm list -> thm list option) -> theory -> theory
27557
151731493264 simpsets as pre/postprocessors; generic preprocessor now named function transformators
haftmann
parents: 26970
diff changeset
    26
  val del_functrans: string -> theory -> theory
24423
ae9cd0e92423 overloaded definitions accompanied by explicit constants
haftmann
parents: 24283
diff changeset
    27
  val add_datatype: (string * typ) list -> theory -> theory
ae9cd0e92423 overloaded definitions accompanied by explicit constants
haftmann
parents: 24283
diff changeset
    28
  val add_datatype_cmd: string list -> theory -> theory
25485
33840a854e63 tuned interfaces of class module
haftmann
parents: 25462
diff changeset
    29
  val type_interpretation:
33840a854e63 tuned interfaces of class module
haftmann
parents: 25462
diff changeset
    30
    (string * ((string * sort) list * (string * typ list) list)
33840a854e63 tuned interfaces of class module
haftmann
parents: 25462
diff changeset
    31
      -> theory -> theory) -> theory -> theory
24844
98c006a30218 certificates for code generator case expressions
haftmann
parents: 24837
diff changeset
    32
  val add_case: thm -> theory -> theory
98c006a30218 certificates for code generator case expressions
haftmann
parents: 24837
diff changeset
    33
  val add_undefined: string -> theory -> theory
27675
cb0021d56e11 added explicit purge_data
haftmann
parents: 27609
diff changeset
    34
  val purge_data: theory -> theory
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
    35
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
    36
  val coregular_algebra: theory -> Sorts.algebra
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
    37
  val operational_algebra: theory -> (sort -> sort) * Sorts.algebra
28368
8437fb395294 clarified function transformator interface
haftmann
parents: 28359
diff changeset
    38
  val these_eqns: theory -> string -> (thm * bool) list
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
    39
  val get_datatype: theory -> string -> ((string * sort) list * (string * typ list) list)
24423
ae9cd0e92423 overloaded definitions accompanied by explicit constants
haftmann
parents: 24283
diff changeset
    40
  val get_datatype_of_constr: theory -> string -> string option
24844
98c006a30218 certificates for code generator case expressions
haftmann
parents: 24837
diff changeset
    41
  val get_case_data: theory -> string -> (int * string list) option
98c006a30218 certificates for code generator case expressions
haftmann
parents: 24837
diff changeset
    42
  val is_undefined: theory -> string -> bool
26970
bc28e7bcb765 explicit type schemes for functions
haftmann
parents: 26947
diff changeset
    43
  val default_typ: theory -> string -> (string * sort) list * typ
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
    44
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
    45
  val preprocess_conv: cterm -> thm
24837
cacc5744be75 clarified terminology
haftmann
parents: 24731
diff changeset
    46
  val preprocess_term: theory -> term -> term
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
    47
  val postprocess_conv: cterm -> thm
24837
cacc5744be75 clarified terminology
haftmann
parents: 24731
diff changeset
    48
  val postprocess_term: theory -> term -> term
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
    49
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
    50
  val add_attribute: string * (Args.T list -> attribute * Args.T list) -> theory -> theory
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
    51
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
    52
  val print_codesetup: theory -> unit
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
    53
end;
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
    54
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
    55
signature CODE_DATA_ARGS =
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
    56
sig
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
    57
  type T
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
    58
  val empty: T
27609
b23c9ad0fe7d tuned code theorem bookkeeping
haftmann
parents: 27582
diff changeset
    59
  val purge: theory -> string list -> T -> T
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
    60
end;
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
    61
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
    62
signature CODE_DATA =
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
    63
sig
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
    64
  type T
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
    65
  val get: theory -> T
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
    66
  val change: theory -> (T -> T) -> T
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
    67
  val change_yield: theory -> (T -> 'a * T) -> 'a * T
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
    68
end;
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
    69
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
    70
signature PRIVATE_CODE =
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
    71
sig
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
    72
  include CODE
27609
b23c9ad0fe7d tuned code theorem bookkeeping
haftmann
parents: 27582
diff changeset
    73
  val declare_data: Object.T -> (theory -> string list -> Object.T -> Object.T)
b23c9ad0fe7d tuned code theorem bookkeeping
haftmann
parents: 27582
diff changeset
    74
    -> serial
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
    75
  val get_data: serial * ('a -> Object.T) * (Object.T -> 'a)
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
    76
    -> theory -> 'a
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
    77
  val change_data: serial * ('a -> Object.T) * (Object.T -> 'a)
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
    78
    -> theory -> ('a -> 'a) -> 'a
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
    79
  val change_yield_data: serial * ('a -> Object.T) * (Object.T -> 'a)
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
    80
    -> theory -> ('a -> 'b * 'a) -> 'b * 'a
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
    81
end;
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
    82
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
    83
structure Code : PRIVATE_CODE =
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
    84
struct
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
    85
25312
eb9067371342 clarified merge
haftmann
parents: 24969
diff changeset
    86
(** code attributes **)
eb9067371342 clarified merge
haftmann
parents: 24969
diff changeset
    87
eb9067371342 clarified merge
haftmann
parents: 24969
diff changeset
    88
structure CodeAttr = TheoryDataFun (
eb9067371342 clarified merge
haftmann
parents: 24969
diff changeset
    89
  type T = (string * (Args.T list -> attribute * Args.T list)) list;
eb9067371342 clarified merge
haftmann
parents: 24969
diff changeset
    90
  val empty = [];
eb9067371342 clarified merge
haftmann
parents: 24969
diff changeset
    91
  val copy = I;
eb9067371342 clarified merge
haftmann
parents: 24969
diff changeset
    92
  val extend = I;
26970
bc28e7bcb765 explicit type schemes for functions
haftmann
parents: 26947
diff changeset
    93
  fun merge _ = AList.merge (op = : string * string -> bool) (K true);
25312
eb9067371342 clarified merge
haftmann
parents: 24969
diff changeset
    94
);
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
    95
25312
eb9067371342 clarified merge
haftmann
parents: 24969
diff changeset
    96
fun add_attribute (attr as (name, _)) =
eb9067371342 clarified merge
haftmann
parents: 24969
diff changeset
    97
  let
eb9067371342 clarified merge
haftmann
parents: 24969
diff changeset
    98
    fun add_parser ("", parser) attrs = attrs @ [("", parser)]
eb9067371342 clarified merge
haftmann
parents: 24969
diff changeset
    99
      | add_parser (name, parser) attrs = (name, Args.$$$ name |-- parser) :: attrs;
eb9067371342 clarified merge
haftmann
parents: 24969
diff changeset
   100
    fun error "" = error ("Code attribute already declared")
eb9067371342 clarified merge
haftmann
parents: 24969
diff changeset
   101
      | error name = error ("Code attribute " ^ name ^ " already declared")
eb9067371342 clarified merge
haftmann
parents: 24969
diff changeset
   102
  in CodeAttr.map (fn attrs => if AList.defined (op =) attrs name
eb9067371342 clarified merge
haftmann
parents: 24969
diff changeset
   103
    then error name else add_parser attr attrs)
eb9067371342 clarified merge
haftmann
parents: 24969
diff changeset
   104
  end;
eb9067371342 clarified merge
haftmann
parents: 24969
diff changeset
   105
eb9067371342 clarified merge
haftmann
parents: 24969
diff changeset
   106
val _ =
eb9067371342 clarified merge
haftmann
parents: 24969
diff changeset
   107
  let
eb9067371342 clarified merge
haftmann
parents: 24969
diff changeset
   108
    val code_attr = Attrib.syntax (Scan.peek (fn context =>
eb9067371342 clarified merge
haftmann
parents: 24969
diff changeset
   109
      List.foldr op || Scan.fail (map snd (CodeAttr.get (Context.theory_of context)))));
eb9067371342 clarified merge
haftmann
parents: 24969
diff changeset
   110
  in
26463
9283b4185fdf Context.>> : operate on Context.generic;
wenzelm
parents: 26435
diff changeset
   111
    Context.>> (Context.map_theory
9283b4185fdf Context.>> : operate on Context.generic;
wenzelm
parents: 26435
diff changeset
   112
      (Attrib.add_attributes
9283b4185fdf Context.>> : operate on Context.generic;
wenzelm
parents: 26435
diff changeset
   113
        [("code", code_attr, "declare theorems for code generation")]))
25312
eb9067371342 clarified merge
haftmann
parents: 24969
diff changeset
   114
  end;
eb9067371342 clarified merge
haftmann
parents: 24969
diff changeset
   115
eb9067371342 clarified merge
haftmann
parents: 24969
diff changeset
   116
28143
e5c6c4aac52c different bookkeeping for code equations
haftmann
parents: 28054
diff changeset
   117
(** logical and syntactical specification of executable code **)
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   118
28350
715163ec93c0 non left-linear equations for nbe
haftmann
parents: 28143
diff changeset
   119
(* defining equations with linear flag, default flag and lazy theorems *)
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   120
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   121
fun pretty_lthms ctxt r = case Susp.peek r
28350
715163ec93c0 non left-linear equations for nbe
haftmann
parents: 28143
diff changeset
   122
 of SOME thms => map (ProofContext.pretty_thm ctxt o fst) thms
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   123
  | NONE => [Pretty.str "[...]"];
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   124
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   125
fun certificate thy f r =
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   126
  case Susp.peek r
28350
715163ec93c0 non left-linear equations for nbe
haftmann
parents: 28143
diff changeset
   127
   of SOME thms => (Susp.value o burrow_fst (f thy)) thms
24844
98c006a30218 certificates for code generator case expressions
haftmann
parents: 24837
diff changeset
   128
    | NONE => let
98c006a30218 certificates for code generator case expressions
haftmann
parents: 24837
diff changeset
   129
        val thy_ref = Theory.check_thy thy;
28350
715163ec93c0 non left-linear equations for nbe
haftmann
parents: 28143
diff changeset
   130
      in Susp.delay (fn () => (burrow_fst (f (Theory.deref thy_ref)) o Susp.force) r) end;
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   131
28350
715163ec93c0 non left-linear equations for nbe
haftmann
parents: 28143
diff changeset
   132
fun add_drop_redundant (thm, linear) thms =
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   133
  let
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   134
    val thy = Thm.theory_of_thm thm;
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   135
    val args_of = snd o strip_comb o fst o Logic.dest_equals o Thm.plain_prop_of;
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   136
    val args = args_of thm;
28403
da9ae7774513 more precise redundancy check
haftmann
parents: 28368
diff changeset
   137
    val incr_idx = Logic.incr_indexes ([], Thm.maxidx_of thm + 1);
28350
715163ec93c0 non left-linear equations for nbe
haftmann
parents: 28143
diff changeset
   138
    fun matches_args args' = length args <= length args' andalso
28403
da9ae7774513 more precise redundancy check
haftmann
parents: 28368
diff changeset
   139
      Pattern.matchess thy (args, (map incr_idx o curry Library.take (length args)) args');
28359
bd4750bcb4e6 clarifed redundancy policy
haftmann
parents: 28353
diff changeset
   140
    fun drop (thm', linear') = if (linear orelse not linear')
bd4750bcb4e6 clarifed redundancy policy
haftmann
parents: 28353
diff changeset
   141
      andalso matches_args (args_of thm') then 
bd4750bcb4e6 clarifed redundancy policy
haftmann
parents: 28353
diff changeset
   142
        (warning ("Code generator: dropping redundant defining equation\n" ^ Display.string_of_thm thm'); true)
28350
715163ec93c0 non left-linear equations for nbe
haftmann
parents: 28143
diff changeset
   143
      else false;
715163ec93c0 non left-linear equations for nbe
haftmann
parents: 28143
diff changeset
   144
  in (thm, linear) :: filter_out drop thms end;
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   145
28350
715163ec93c0 non left-linear equations for nbe
haftmann
parents: 28143
diff changeset
   146
fun add_thm _ thm (false, thms) = (false, Susp.map_force (add_drop_redundant thm) thms)
715163ec93c0 non left-linear equations for nbe
haftmann
parents: 28143
diff changeset
   147
  | add_thm true thm (true, thms) = (true, Susp.map_force (fn thms => thms @ [thm]) thms)
28143
e5c6c4aac52c different bookkeeping for code equations
haftmann
parents: 28054
diff changeset
   148
  | add_thm false thm (true, thms) = (false, Susp.value [thm]);
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   149
28143
e5c6c4aac52c different bookkeeping for code equations
haftmann
parents: 28054
diff changeset
   150
fun add_lthms lthms _ = (false, lthms);
25312
eb9067371342 clarified merge
haftmann
parents: 24969
diff changeset
   151
28350
715163ec93c0 non left-linear equations for nbe
haftmann
parents: 28143
diff changeset
   152
fun del_thm thm = (apsnd o Susp.map_force) (remove (eq_fst Thm.eq_thm_prop) (thm, true));
25312
eb9067371342 clarified merge
haftmann
parents: 24969
diff changeset
   153
28143
e5c6c4aac52c different bookkeeping for code equations
haftmann
parents: 28054
diff changeset
   154
fun merge_defthms ((true, _), defthms2) = defthms2
e5c6c4aac52c different bookkeeping for code equations
haftmann
parents: 28054
diff changeset
   155
  | merge_defthms (defthms1 as (false, _), (true, _)) = defthms1
e5c6c4aac52c different bookkeeping for code equations
haftmann
parents: 28054
diff changeset
   156
  | merge_defthms ((false, _), defthms2 as (false, _)) = defthms2;
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   157
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   158
28143
e5c6c4aac52c different bookkeeping for code equations
haftmann
parents: 28054
diff changeset
   159
(* syntactic datatypes *)
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   160
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   161
val eq_string = op = : string * string -> bool;
28143
e5c6c4aac52c different bookkeeping for code equations
haftmann
parents: 28054
diff changeset
   162
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   163
fun eq_dtyp ((vs1, cs1), (vs2, cs2)) = 
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   164
  gen_eq_set (eq_pair eq_string (gen_eq_set eq_string)) (vs1, vs2)
24423
ae9cd0e92423 overloaded definitions accompanied by explicit constants
haftmann
parents: 24283
diff changeset
   165
    andalso gen_eq_set (eq_fst eq_string) (cs1, cs2);
28143
e5c6c4aac52c different bookkeeping for code equations
haftmann
parents: 28054
diff changeset
   166
27582
367aff8d7ffd dropped junk
haftmann
parents: 27557
diff changeset
   167
fun merge_dtyps (tabs as (tab1, tab2)) =
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   168
  let
27582
367aff8d7ffd dropped junk
haftmann
parents: 27557
diff changeset
   169
    fun join _ (cos as (_, cos2)) = if eq_dtyp cos then raise Symtab.SAME else cos2;
367aff8d7ffd dropped junk
haftmann
parents: 27557
diff changeset
   170
  in Symtab.join join tabs end;
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   171
28143
e5c6c4aac52c different bookkeeping for code equations
haftmann
parents: 28054
diff changeset
   172
e5c6c4aac52c different bookkeeping for code equations
haftmann
parents: 28054
diff changeset
   173
(* specification data *)
e5c6c4aac52c different bookkeeping for code equations
haftmann
parents: 28054
diff changeset
   174
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   175
datatype spec = Spec of {
28368
8437fb395294 clarified function transformator interface
haftmann
parents: 28359
diff changeset
   176
  eqns: (bool * (thm * bool) list Susp.T) Symtab.table,
24844
98c006a30218 certificates for code generator case expressions
haftmann
parents: 24837
diff changeset
   177
  dtyps: ((string * sort) list * (string * typ list) list) Symtab.table,
98c006a30218 certificates for code generator case expressions
haftmann
parents: 24837
diff changeset
   178
  cases: (int * string list) Symtab.table * unit Symtab.table
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   179
};
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   180
28368
8437fb395294 clarified function transformator interface
haftmann
parents: 28359
diff changeset
   181
fun mk_spec (eqns, (dtyps, cases)) =
8437fb395294 clarified function transformator interface
haftmann
parents: 28359
diff changeset
   182
  Spec { eqns = eqns, dtyps = dtyps, cases = cases };
8437fb395294 clarified function transformator interface
haftmann
parents: 28359
diff changeset
   183
fun map_spec f (Spec { eqns = eqns, dtyps = dtyps, cases = cases }) =
8437fb395294 clarified function transformator interface
haftmann
parents: 28359
diff changeset
   184
  mk_spec (f (eqns, (dtyps, cases)));
8437fb395294 clarified function transformator interface
haftmann
parents: 28359
diff changeset
   185
fun merge_spec (Spec { eqns = eqns1, dtyps = dtyps1, cases = (cases1, undefs1) },
8437fb395294 clarified function transformator interface
haftmann
parents: 28359
diff changeset
   186
  Spec { eqns = eqns2, dtyps = dtyps2, cases = (cases2, undefs2) }) =
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   187
  let
28368
8437fb395294 clarified function transformator interface
haftmann
parents: 28359
diff changeset
   188
    val eqns = Symtab.join (K merge_defthms) (eqns1, eqns2);
27582
367aff8d7ffd dropped junk
haftmann
parents: 27557
diff changeset
   189
    val dtyps = merge_dtyps (dtyps1, dtyps2);
27609
b23c9ad0fe7d tuned code theorem bookkeeping
haftmann
parents: 27582
diff changeset
   190
    val cases = (Symtab.merge (K true) (cases1, cases2),
b23c9ad0fe7d tuned code theorem bookkeeping
haftmann
parents: 27582
diff changeset
   191
      Symtab.merge (K true) (undefs1, undefs2));
28368
8437fb395294 clarified function transformator interface
haftmann
parents: 28359
diff changeset
   192
  in mk_spec (eqns, (dtyps, cases)) end;
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   193
25312
eb9067371342 clarified merge
haftmann
parents: 24969
diff changeset
   194
eb9067371342 clarified merge
haftmann
parents: 24969
diff changeset
   195
(* pre- and postprocessor *)
eb9067371342 clarified merge
haftmann
parents: 24969
diff changeset
   196
eb9067371342 clarified merge
haftmann
parents: 24969
diff changeset
   197
datatype thmproc = Thmproc of {
27557
151731493264 simpsets as pre/postprocessors; generic preprocessor now named function transformators
haftmann
parents: 26970
diff changeset
   198
  pre: MetaSimplifier.simpset,
151731493264 simpsets as pre/postprocessors; generic preprocessor now named function transformators
haftmann
parents: 26970
diff changeset
   199
  post: MetaSimplifier.simpset,
27609
b23c9ad0fe7d tuned code theorem bookkeeping
haftmann
parents: 27582
diff changeset
   200
  functrans: (string * (serial * (theory -> thm list -> thm list option))) list
25312
eb9067371342 clarified merge
haftmann
parents: 24969
diff changeset
   201
};
eb9067371342 clarified merge
haftmann
parents: 24969
diff changeset
   202
27557
151731493264 simpsets as pre/postprocessors; generic preprocessor now named function transformators
haftmann
parents: 26970
diff changeset
   203
fun mk_thmproc ((pre, post), functrans) =
151731493264 simpsets as pre/postprocessors; generic preprocessor now named function transformators
haftmann
parents: 26970
diff changeset
   204
  Thmproc { pre = pre, post = post, functrans = functrans };
151731493264 simpsets as pre/postprocessors; generic preprocessor now named function transformators
haftmann
parents: 26970
diff changeset
   205
fun map_thmproc f (Thmproc { pre, post, functrans }) =
151731493264 simpsets as pre/postprocessors; generic preprocessor now named function transformators
haftmann
parents: 26970
diff changeset
   206
  mk_thmproc (f ((pre, post), functrans));
151731493264 simpsets as pre/postprocessors; generic preprocessor now named function transformators
haftmann
parents: 26970
diff changeset
   207
fun merge_thmproc (Thmproc { pre = pre1, post = post1, functrans = functrans1 },
151731493264 simpsets as pre/postprocessors; generic preprocessor now named function transformators
haftmann
parents: 26970
diff changeset
   208
  Thmproc { pre = pre2, post = post2, functrans = functrans2 }) =
25312
eb9067371342 clarified merge
haftmann
parents: 24969
diff changeset
   209
    let
27557
151731493264 simpsets as pre/postprocessors; generic preprocessor now named function transformators
haftmann
parents: 26970
diff changeset
   210
      val pre = MetaSimplifier.merge_ss (pre1, pre2);
151731493264 simpsets as pre/postprocessors; generic preprocessor now named function transformators
haftmann
parents: 26970
diff changeset
   211
      val post = MetaSimplifier.merge_ss (post1, post2);
151731493264 simpsets as pre/postprocessors; generic preprocessor now named function transformators
haftmann
parents: 26970
diff changeset
   212
      val functrans = AList.merge (op =) (eq_fst (op =)) (functrans1, functrans2);
151731493264 simpsets as pre/postprocessors; generic preprocessor now named function transformators
haftmann
parents: 26970
diff changeset
   213
    in mk_thmproc ((pre, post), functrans) end;
25312
eb9067371342 clarified merge
haftmann
parents: 24969
diff changeset
   214
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   215
datatype exec = Exec of {
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   216
  thmproc: thmproc,
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   217
  spec: spec
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   218
};
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   219
28143
e5c6c4aac52c different bookkeeping for code equations
haftmann
parents: 28054
diff changeset
   220
e5c6c4aac52c different bookkeeping for code equations
haftmann
parents: 28054
diff changeset
   221
(* code setup data *)
e5c6c4aac52c different bookkeeping for code equations
haftmann
parents: 28054
diff changeset
   222
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   223
fun mk_exec (thmproc, spec) =
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   224
  Exec { thmproc = thmproc, spec = spec };
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   225
fun map_exec f (Exec { thmproc = thmproc, spec = spec }) =
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   226
  mk_exec (f (thmproc, spec));
27557
151731493264 simpsets as pre/postprocessors; generic preprocessor now named function transformators
haftmann
parents: 26970
diff changeset
   227
fun merge_exec (Exec { thmproc = thmproc1, spec = spec1 },
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   228
  Exec { thmproc = thmproc2, spec = spec2 }) =
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   229
  let
27557
151731493264 simpsets as pre/postprocessors; generic preprocessor now named function transformators
haftmann
parents: 26970
diff changeset
   230
    val thmproc = merge_thmproc (thmproc1, thmproc2);
151731493264 simpsets as pre/postprocessors; generic preprocessor now named function transformators
haftmann
parents: 26970
diff changeset
   231
    val spec = merge_spec (spec1, spec2);
151731493264 simpsets as pre/postprocessors; generic preprocessor now named function transformators
haftmann
parents: 26970
diff changeset
   232
  in mk_exec (thmproc, spec) end;
151731493264 simpsets as pre/postprocessors; generic preprocessor now named function transformators
haftmann
parents: 26970
diff changeset
   233
val empty_exec = mk_exec (mk_thmproc ((MetaSimplifier.empty_ss, MetaSimplifier.empty_ss), []),
24844
98c006a30218 certificates for code generator case expressions
haftmann
parents: 24837
diff changeset
   234
  mk_spec (Symtab.empty, (Symtab.empty, (Symtab.empty, Symtab.empty))));
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   235
25312
eb9067371342 clarified merge
haftmann
parents: 24969
diff changeset
   236
fun the_thmproc (Exec { thmproc = Thmproc x, ...}) = x;
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   237
fun the_spec (Exec { spec = Spec x, ...}) = x;
28368
8437fb395294 clarified function transformator interface
haftmann
parents: 28359
diff changeset
   238
val the_eqns = #eqns o the_spec;
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   239
val the_dtyps = #dtyps o the_spec;
24844
98c006a30218 certificates for code generator case expressions
haftmann
parents: 24837
diff changeset
   240
val the_cases = #cases o the_spec;
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   241
val map_thmproc = map_exec o apfst o map_thmproc;
28368
8437fb395294 clarified function transformator interface
haftmann
parents: 28359
diff changeset
   242
val map_eqns = map_exec o apsnd o map_spec o apfst;
24844
98c006a30218 certificates for code generator case expressions
haftmann
parents: 24837
diff changeset
   243
val map_dtyps = map_exec o apsnd o map_spec o apsnd o apfst;
98c006a30218 certificates for code generator case expressions
haftmann
parents: 24837
diff changeset
   244
val map_cases = map_exec o apsnd o map_spec o apsnd o apsnd;
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   245
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   246
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   247
(* data slots dependent on executable content *)
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   248
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   249
(*private copy avoids potential conflict of table exceptions*)
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   250
structure Datatab = TableFun(type key = int val ord = int_ord);
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   251
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   252
local
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   253
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   254
type kind = {
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   255
  empty: Object.T,
27609
b23c9ad0fe7d tuned code theorem bookkeeping
haftmann
parents: 27582
diff changeset
   256
  purge: theory -> string list -> Object.T -> Object.T
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   257
};
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   258
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   259
val kinds = ref (Datatab.empty: kind Datatab.table);
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   260
val kind_keys = ref ([]: serial list);
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   261
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   262
fun invoke f k = case Datatab.lookup (! kinds) k
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   263
 of SOME kind => f kind
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   264
  | NONE => sys_error "Invalid code data identifier";
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   265
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   266
in
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   267
27609
b23c9ad0fe7d tuned code theorem bookkeeping
haftmann
parents: 27582
diff changeset
   268
fun declare_data empty purge =
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   269
  let
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   270
    val k = serial ();
27609
b23c9ad0fe7d tuned code theorem bookkeeping
haftmann
parents: 27582
diff changeset
   271
    val kind = {empty = empty, purge = purge};
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   272
    val _ = change kinds (Datatab.update (k, kind));
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   273
    val _ = change kind_keys (cons k);
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   274
  in k end;
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   275
27609
b23c9ad0fe7d tuned code theorem bookkeeping
haftmann
parents: 27582
diff changeset
   276
fun invoke_init k = invoke (fn kind => #empty kind) k;
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   277
27609
b23c9ad0fe7d tuned code theorem bookkeeping
haftmann
parents: 27582
diff changeset
   278
fun invoke_purge_all thy cs =
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   279
  fold (fn k => Datatab.map_entry k
27609
b23c9ad0fe7d tuned code theorem bookkeeping
haftmann
parents: 27582
diff changeset
   280
    (invoke (fn kind => #purge kind thy cs) k)) (! kind_keys);
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   281
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   282
end; (*local*)
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   283
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   284
25312
eb9067371342 clarified merge
haftmann
parents: 24969
diff changeset
   285
(** theory store **)
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   286
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   287
local
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   288
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   289
type data = Object.T Datatab.table;
27609
b23c9ad0fe7d tuned code theorem bookkeeping
haftmann
parents: 27582
diff changeset
   290
val empty_data = Datatab.empty : data;
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   291
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   292
structure CodeData = TheoryDataFun
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   293
(
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   294
  type T = exec * data ref;
27609
b23c9ad0fe7d tuned code theorem bookkeeping
haftmann
parents: 27582
diff changeset
   295
  val empty = (empty_exec, ref empty_data);
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   296
  fun copy (exec, data) = (exec, ref (! data));
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   297
  val extend = copy;
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   298
  fun merge pp ((exec1, data1), (exec2, data2)) =
27609
b23c9ad0fe7d tuned code theorem bookkeeping
haftmann
parents: 27582
diff changeset
   299
    (merge_exec (exec1, exec2), ref empty_data);
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   300
);
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   301
26463
9283b4185fdf Context.>> : operate on Context.generic;
wenzelm
parents: 26435
diff changeset
   302
val _ = Context.>> (Context.map_theory CodeData.init);
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   303
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   304
fun thy_data f thy = f ((snd o CodeData.get) thy);
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   305
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   306
fun get_ensure_init kind data_ref =
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   307
  case Datatab.lookup (! data_ref) kind
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   308
   of SOME x => x
27609
b23c9ad0fe7d tuned code theorem bookkeeping
haftmann
parents: 27582
diff changeset
   309
    | NONE => let val y = invoke_init kind
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   310
        in (change data_ref (Datatab.update (kind, y)); y) end;
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   311
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   312
in
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   313
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   314
(* access to executable content *)
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   315
24844
98c006a30218 certificates for code generator case expressions
haftmann
parents: 24837
diff changeset
   316
val the_exec = fst o CodeData.get;
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   317
27983
00e005cdceb0 corrected cache handling for class operations
haftmann
parents: 27675
diff changeset
   318
fun complete_class_params thy cs =
00e005cdceb0 corrected cache handling for class operations
haftmann
parents: 27675
diff changeset
   319
  fold (fn c => case AxClass.inst_of_param thy c
00e005cdceb0 corrected cache handling for class operations
haftmann
parents: 27675
diff changeset
   320
   of NONE => insert (op =) c
00e005cdceb0 corrected cache handling for class operations
haftmann
parents: 27675
diff changeset
   321
    | SOME (c', _) => insert (op =) c' #> insert (op =) c) cs [];
00e005cdceb0 corrected cache handling for class operations
haftmann
parents: 27675
diff changeset
   322
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   323
fun map_exec_purge touched f thy =
27609
b23c9ad0fe7d tuned code theorem bookkeeping
haftmann
parents: 27582
diff changeset
   324
  CodeData.map (fn (exec, data) => (f exec, ref (case touched
27983
00e005cdceb0 corrected cache handling for class operations
haftmann
parents: 27675
diff changeset
   325
   of SOME cs => invoke_purge_all thy (complete_class_params thy cs) (! data)
27609
b23c9ad0fe7d tuned code theorem bookkeeping
haftmann
parents: 27582
diff changeset
   326
    | NONE => empty_data))) thy;
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   327
27675
cb0021d56e11 added explicit purge_data
haftmann
parents: 27609
diff changeset
   328
val purge_data = (CodeData.map o apsnd) (K (ref empty_data));
cb0021d56e11 added explicit purge_data
haftmann
parents: 27609
diff changeset
   329
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   330
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   331
(* access to data dependent on abstract executable content *)
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   332
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   333
fun get_data (kind, _, dest) = thy_data (get_ensure_init kind #> dest);
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   334
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   335
fun change_data (kind, mk, dest) =
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   336
  let
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   337
    fun chnge data_ref f =
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   338
      let
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   339
        val data = get_ensure_init kind data_ref;
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   340
        val data' = f (dest data);
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   341
      in (change data_ref (Datatab.update (kind, mk data')); data') end;
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   342
  in thy_data chnge end;
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   343
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   344
fun change_yield_data (kind, mk, dest) =
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   345
  let
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   346
    fun chnge data_ref f =
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   347
      let
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   348
        val data = get_ensure_init kind data_ref;
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   349
        val (x, data') = f (dest data);
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   350
      in (x, (change data_ref (Datatab.update (kind, mk data')); data')) end;
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   351
  in thy_data chnge end;
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   352
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   353
end; (*local*)
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   354
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   355
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   356
(* print executable content *)
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   357
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   358
fun print_codesetup thy =
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   359
  let
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   360
    val ctxt = ProofContext.init thy;
24844
98c006a30218 certificates for code generator case expressions
haftmann
parents: 24837
diff changeset
   361
    val exec = the_exec thy;
28368
8437fb395294 clarified function transformator interface
haftmann
parents: 28359
diff changeset
   362
    fun pretty_eqn (s, (_, lthms)) =
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   363
      (Pretty.block o Pretty.fbreaks) (
28143
e5c6c4aac52c different bookkeeping for code equations
haftmann
parents: 28054
diff changeset
   364
        Pretty.str s :: pretty_lthms ctxt lthms
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   365
      );
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   366
    fun pretty_dtyp (s, []) =
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   367
          Pretty.str s
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   368
      | pretty_dtyp (s, cos) =
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   369
          (Pretty.block o Pretty.breaks) (
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   370
            Pretty.str s
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   371
            :: Pretty.str "="
28403
da9ae7774513 more precise redundancy check
haftmann
parents: 28368
diff changeset
   372
            :: separate (Pretty.str "|") (map (fn (c, []) => Pretty.str (Code_Unit.string_of_const thy c)
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   373
                 | (c, tys) =>
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   374
                     (Pretty.block o Pretty.breaks)
28054
2b84d34c5d02 restructured and split code serializer module
haftmann
parents: 27983
diff changeset
   375
                        (Pretty.str (Code_Unit.string_of_const thy c)
26947
133905a0c493 moved global pretty/string_of functions from Sign to Syntax;
wenzelm
parents: 26928
diff changeset
   376
                          :: Pretty.str "of"
133905a0c493 moved global pretty/string_of functions from Sign to Syntax;
wenzelm
parents: 26928
diff changeset
   377
                          :: map (Pretty.quote o Syntax.pretty_typ_global thy) tys)) cos)
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   378
          );
27557
151731493264 simpsets as pre/postprocessors; generic preprocessor now named function transformators
haftmann
parents: 26970
diff changeset
   379
    val pre = (#pre o the_thmproc) exec;
151731493264 simpsets as pre/postprocessors; generic preprocessor now named function transformators
haftmann
parents: 26970
diff changeset
   380
    val post = (#post o the_thmproc) exec;
151731493264 simpsets as pre/postprocessors; generic preprocessor now named function transformators
haftmann
parents: 26970
diff changeset
   381
    val functrans = (map fst o #functrans o the_thmproc) exec;
28368
8437fb395294 clarified function transformator interface
haftmann
parents: 28359
diff changeset
   382
    val eqns = the_eqns exec
24423
ae9cd0e92423 overloaded definitions accompanied by explicit constants
haftmann
parents: 24283
diff changeset
   383
      |> Symtab.dest
28054
2b84d34c5d02 restructured and split code serializer module
haftmann
parents: 27983
diff changeset
   384
      |> (map o apfst) (Code_Unit.string_of_const thy)
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   385
      |> sort (string_ord o pairself fst);
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   386
    val dtyps = the_dtyps exec
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   387
      |> Symtab.dest
26947
133905a0c493 moved global pretty/string_of functions from Sign to Syntax;
wenzelm
parents: 26928
diff changeset
   388
      |> map (fn (dtco, (vs, cos)) =>
133905a0c493 moved global pretty/string_of functions from Sign to Syntax;
wenzelm
parents: 26928
diff changeset
   389
          (Syntax.string_of_typ_global thy (Type (dtco, map TFree vs)), cos))
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   390
      |> sort (string_ord o pairself fst)
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   391
  in
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   392
    (Pretty.writeln o Pretty.chunks) [
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   393
      Pretty.block (
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   394
        Pretty.str "defining equations:"
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   395
        :: Pretty.fbrk
28368
8437fb395294 clarified function transformator interface
haftmann
parents: 28359
diff changeset
   396
        :: (Pretty.fbreaks o map pretty_eqn) eqns
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   397
      ),
27557
151731493264 simpsets as pre/postprocessors; generic preprocessor now named function transformators
haftmann
parents: 26970
diff changeset
   398
      Pretty.block [
151731493264 simpsets as pre/postprocessors; generic preprocessor now named function transformators
haftmann
parents: 26970
diff changeset
   399
        Pretty.str "preprocessing simpset:",
151731493264 simpsets as pre/postprocessors; generic preprocessor now named function transformators
haftmann
parents: 26970
diff changeset
   400
        Pretty.fbrk,
151731493264 simpsets as pre/postprocessors; generic preprocessor now named function transformators
haftmann
parents: 26970
diff changeset
   401
        MetaSimplifier.pretty_ss pre
151731493264 simpsets as pre/postprocessors; generic preprocessor now named function transformators
haftmann
parents: 26970
diff changeset
   402
      ],
151731493264 simpsets as pre/postprocessors; generic preprocessor now named function transformators
haftmann
parents: 26970
diff changeset
   403
      Pretty.block [
151731493264 simpsets as pre/postprocessors; generic preprocessor now named function transformators
haftmann
parents: 26970
diff changeset
   404
        Pretty.str "postprocessing simpset:",
151731493264 simpsets as pre/postprocessors; generic preprocessor now named function transformators
haftmann
parents: 26970
diff changeset
   405
        Pretty.fbrk,
151731493264 simpsets as pre/postprocessors; generic preprocessor now named function transformators
haftmann
parents: 26970
diff changeset
   406
        MetaSimplifier.pretty_ss post
151731493264 simpsets as pre/postprocessors; generic preprocessor now named function transformators
haftmann
parents: 26970
diff changeset
   407
      ],
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   408
      Pretty.block (
27609
b23c9ad0fe7d tuned code theorem bookkeeping
haftmann
parents: 27582
diff changeset
   409
        Pretty.str "function transformers:"
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   410
        :: Pretty.fbrk
27557
151731493264 simpsets as pre/postprocessors; generic preprocessor now named function transformators
haftmann
parents: 26970
diff changeset
   411
        :: (Pretty.fbreaks o map Pretty.str) functrans
25968
66cfe1d00be0 print postprocessor equations
haftmann
parents: 25597
diff changeset
   412
      ),
66cfe1d00be0 print postprocessor equations
haftmann
parents: 25597
diff changeset
   413
      Pretty.block (
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   414
        Pretty.str "datatypes:"
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   415
        :: Pretty.fbrk
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   416
        :: (Pretty.fbreaks o map pretty_dtyp) dtyps
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   417
      )
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   418
    ]
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   419
  end;
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   420
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   421
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   422
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   423
(** theorem transformation and certification **)
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   424
28368
8437fb395294 clarified function transformator interface
haftmann
parents: 28359
diff changeset
   425
fun const_of thy = dest_Const o fst o strip_comb o fst o Logic.dest_equals o Thm.plain_prop_of;
8437fb395294 clarified function transformator interface
haftmann
parents: 28359
diff changeset
   426
8437fb395294 clarified function transformator interface
haftmann
parents: 28359
diff changeset
   427
fun const_of_eqn thy = AxClass.unoverload_const thy o const_of thy;
26970
bc28e7bcb765 explicit type schemes for functions
haftmann
parents: 26947
diff changeset
   428
28368
8437fb395294 clarified function transformator interface
haftmann
parents: 28359
diff changeset
   429
fun common_typ_eqns [] = []
8437fb395294 clarified function transformator interface
haftmann
parents: 28359
diff changeset
   430
  | common_typ_eqns [thm] = [thm]
8437fb395294 clarified function transformator interface
haftmann
parents: 28359
diff changeset
   431
  | common_typ_eqns (thms as thm :: _) = (*FIXME is too general*)
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   432
      let
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   433
        val thy = Thm.theory_of_thm thm;
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   434
        fun incr_thm thm max =
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   435
          let
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   436
            val thm' = incr_indexes max thm;
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   437
            val max' = Thm.maxidx_of thm' + 1;
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   438
          in (thm', max') end;
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   439
        val (thms', maxidx) = fold_map incr_thm thms 0;
26970
bc28e7bcb765 explicit type schemes for functions
haftmann
parents: 26947
diff changeset
   440
        val ty1 :: tys = map (snd o const_of thy) thms';
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   441
        fun unify ty env = Sign.typ_unify thy (ty1, ty) env
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   442
          handle Type.TUNIFY =>
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   443
            error ("Type unificaton failed, while unifying defining equations\n"
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   444
            ^ (cat_lines o map Display.string_of_thm) thms
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   445
            ^ "\nwith types\n"
28054
2b84d34c5d02 restructured and split code serializer module
haftmann
parents: 27983
diff changeset
   446
            ^ (cat_lines o map (Code_Unit.string_of_typ thy)) (ty1 :: tys));
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   447
        val (env, _) = fold unify tys (Vartab.empty, maxidx)
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   448
        val instT = Vartab.fold (fn (x_i, (sort, ty)) =>
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   449
          cons (Thm.ctyp_of thy (TVar (x_i, sort)), Thm.ctyp_of thy ty)) env [];
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   450
      in map (Thm.instantiate (instT, [])) thms' end;
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   451
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   452
fun certify_const thy const thms =
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   453
  let
28368
8437fb395294 clarified function transformator interface
haftmann
parents: 28359
diff changeset
   454
    fun cert thm = if const = const_of_eqn thy thm
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   455
      then thm else error ("Wrong head of defining equation,\nexpected constant "
28054
2b84d34c5d02 restructured and split code serializer module
haftmann
parents: 27983
diff changeset
   456
        ^ Code_Unit.string_of_const thy const ^ "\n" ^ Display.string_of_thm thm)
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   457
  in map cert thms end;
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   458
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   459
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   460
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   461
(** operational sort algebra and class discipline **)
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   462
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   463
local
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   464
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   465
fun aggr_neutr f y [] = y
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   466
  | aggr_neutr f y (x::xs) = aggr_neutr f (f y x) xs;
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   467
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   468
fun aggregate f [] = NONE
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   469
  | aggregate f (x::xs) = SOME (aggr_neutr f x xs);
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   470
25462
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25312
diff changeset
   471
fun inter_sorts algebra =
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25312
diff changeset
   472
  aggregate (map2 (curry (Sorts.inter_sort algebra)));
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   473
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   474
fun specific_constraints thy (class, tyco) =
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   475
  let
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   476
    val vs = Name.invents Name.context "" (Sign.arity_number thy tyco);
24969
b38527eefb3b removed obsolete AxClass.params_of_class;
wenzelm
parents: 24928
diff changeset
   477
    val classparams = (map fst o these o try (#params o AxClass.get_info thy)) class;
28368
8437fb395294 clarified function transformator interface
haftmann
parents: 28359
diff changeset
   478
    val eqns = classparams
25597
34860182b250 moved instance parameter management from class.ML to axclass.ML
haftmann
parents: 25501
diff changeset
   479
      |> map_filter (fn c => try (AxClass.param_of_inst thy) (c, tyco))
28368
8437fb395294 clarified function transformator interface
haftmann
parents: 28359
diff changeset
   480
      |> map (Symtab.lookup ((the_eqns o the_exec) thy))
28350
715163ec93c0 non left-linear equations for nbe
haftmann
parents: 28143
diff changeset
   481
      |> (map o Option.map) (map fst o Susp.force o snd)
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   482
      |> maps these
28143
e5c6c4aac52c different bookkeeping for code equations
haftmann
parents: 28054
diff changeset
   483
      |> map (Thm.transfer thy);
24423
ae9cd0e92423 overloaded definitions accompanied by explicit constants
haftmann
parents: 24283
diff changeset
   484
    fun sorts_of [Type (_, tys)] = map (snd o dest_TVar) tys
ae9cd0e92423 overloaded definitions accompanied by explicit constants
haftmann
parents: 24283
diff changeset
   485
      | sorts_of tys = map (snd o dest_TVar) tys;
28368
8437fb395294 clarified function transformator interface
haftmann
parents: 28359
diff changeset
   486
    val sorts = map (sorts_of o Sign.const_typargs thy o const_of thy) eqns;
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   487
  in sorts end;
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   488
25462
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25312
diff changeset
   489
fun weakest_constraints thy algebra (class, tyco) =
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   490
  let
25462
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25312
diff changeset
   491
    val all_superclasses = Sorts.complete_sort algebra [class];
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25312
diff changeset
   492
  in case inter_sorts algebra (maps (fn class => specific_constraints thy (class, tyco)) all_superclasses)
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   493
   of SOME sorts => sorts
25462
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25312
diff changeset
   494
    | NONE => Sorts.mg_domain algebra tyco [class]
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   495
  end;
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   496
25462
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25312
diff changeset
   497
fun strongest_constraints thy algebra (class, tyco) =
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   498
  let
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   499
    val all_subclasses = class :: Graph.all_preds ((#classes o Sorts.rep_algebra) algebra) [class];
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   500
    val inst_subclasses = filter (can (Sorts.mg_domain algebra tyco) o single) all_subclasses;
25462
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25312
diff changeset
   501
  in case inter_sorts algebra (maps (fn class => specific_constraints thy (class, tyco)) inst_subclasses)
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   502
   of SOME sorts => sorts
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   503
    | NONE => replicate
25462
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25312
diff changeset
   504
        (Sign.arity_number thy tyco) (Sorts.minimize_sort algebra (Sorts.all_classes algebra))
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25312
diff changeset
   505
  end;
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25312
diff changeset
   506
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25312
diff changeset
   507
fun get_algebra thy (class, tyco) =
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25312
diff changeset
   508
  let
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25312
diff changeset
   509
    val base_algebra = Sign.classes_of thy;
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25312
diff changeset
   510
  in if can (Sorts.mg_domain base_algebra tyco) [class]
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25312
diff changeset
   511
    then base_algebra
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25312
diff changeset
   512
    else let
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25312
diff changeset
   513
      val superclasses = Sorts.super_classes base_algebra class;
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25312
diff changeset
   514
      val sorts = inter_sorts base_algebra
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25312
diff changeset
   515
          (map_filter (fn class => try (Sorts.mg_domain base_algebra tyco) [class]) superclasses)
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25312
diff changeset
   516
        |> the_default (replicate (Sign.arity_number thy tyco) [])
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25312
diff changeset
   517
    in
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25312
diff changeset
   518
      base_algebra
26947
133905a0c493 moved global pretty/string_of functions from Sign to Syntax;
wenzelm
parents: 26928
diff changeset
   519
      |> Sorts.add_arities (Syntax.pp_global thy) (tyco, [(class, sorts)])
25462
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25312
diff changeset
   520
    end
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   521
  end;
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   522
24837
cacc5744be75 clarified terminology
haftmann
parents: 24731
diff changeset
   523
fun gen_classparam_typ constr thy class (c, tyco) = 
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   524
  let
25462
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25312
diff changeset
   525
    val algebra = get_algebra thy (class, tyco);
24969
b38527eefb3b removed obsolete AxClass.params_of_class;
wenzelm
parents: 24928
diff changeset
   526
    val cs = these (try (#params o AxClass.get_info thy) class);
25462
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25312
diff changeset
   527
    val SOME ty = AList.lookup (op =) cs c;
24969
b38527eefb3b removed obsolete AxClass.params_of_class;
wenzelm
parents: 24928
diff changeset
   528
    val sort_args = Name.names (Name.declare Name.aT Name.context) Name.aT
25462
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25312
diff changeset
   529
      (constr thy algebra (class, tyco));
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   530
    val ty_inst = Type (tyco, map TFree sort_args);
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   531
  in Logic.varifyT (map_type_tfree (K ty_inst) ty) end;
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   532
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   533
fun retrieve_algebra thy operational =
26947
133905a0c493 moved global pretty/string_of functions from Sign to Syntax;
wenzelm
parents: 26928
diff changeset
   534
  Sorts.subalgebra (Syntax.pp_global thy) operational
25462
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25312
diff changeset
   535
    (weakest_constraints thy (Sign.classes_of thy))
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   536
    (Sign.classes_of thy);
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   537
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   538
in
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   539
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   540
fun coregular_algebra thy = retrieve_algebra thy (K true) |> snd;
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   541
fun operational_algebra thy =
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   542
  let
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   543
    fun add_iff_operational class =
24928
3419943838f5 renamed AxClass.get_definition to AxClass.get_info (again);
wenzelm
parents: 24848
diff changeset
   544
      can (AxClass.get_info thy) class ? cons class;
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   545
    val operational_classes = fold add_iff_operational (Sign.all_classes thy) []
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   546
  in retrieve_algebra thy (member (op =) operational_classes) end;
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   547
24837
cacc5744be75 clarified terminology
haftmann
parents: 24731
diff changeset
   548
val classparam_weakest_typ = gen_classparam_typ weakest_constraints;
cacc5744be75 clarified terminology
haftmann
parents: 24731
diff changeset
   549
val classparam_strongest_typ = gen_classparam_typ strongest_constraints;
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   550
28368
8437fb395294 clarified function transformator interface
haftmann
parents: 28359
diff changeset
   551
fun assert_eqn_linear (eqn as (thm, linear)) =
8437fb395294 clarified function transformator interface
haftmann
parents: 28359
diff changeset
   552
  if linear then eqn else Code_Unit.bad_thm
8437fb395294 clarified function transformator interface
haftmann
parents: 28359
diff changeset
   553
    ("Duplicate variables on left hand side of defining equation:\n"
8437fb395294 clarified function transformator interface
haftmann
parents: 28359
diff changeset
   554
      ^ Display.string_of_thm thm);
8437fb395294 clarified function transformator interface
haftmann
parents: 28359
diff changeset
   555
8437fb395294 clarified function transformator interface
haftmann
parents: 28359
diff changeset
   556
fun assert_eqn_typ (thm, linear) =
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   557
  let
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   558
    val thy = Thm.theory_of_thm thm;
24837
cacc5744be75 clarified terminology
haftmann
parents: 24731
diff changeset
   559
    fun check_typ_classparam tyco (c, thm) =
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   560
          let
24423
ae9cd0e92423 overloaded definitions accompanied by explicit constants
haftmann
parents: 24283
diff changeset
   561
            val SOME class = AxClass.class_of_param thy c;
26970
bc28e7bcb765 explicit type schemes for functions
haftmann
parents: 26947
diff changeset
   562
            val (_, ty) = const_of thy thm;
24837
cacc5744be75 clarified terminology
haftmann
parents: 24731
diff changeset
   563
            val ty_decl = classparam_weakest_typ thy class (c, tyco);
cacc5744be75 clarified terminology
haftmann
parents: 24731
diff changeset
   564
            val ty_strongest = classparam_strongest_typ thy class (c, tyco);
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   565
            fun constrain thm = 
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   566
              let
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   567
                val max = Thm.maxidx_of thm + 1;
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   568
                val ty_decl' = Logic.incr_tvar max ty_decl;
26970
bc28e7bcb765 explicit type schemes for functions
haftmann
parents: 26947
diff changeset
   569
                val (_, ty') = const_of thy thm;
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   570
                val (env, _) = Sign.typ_unify thy (ty_decl', ty') (Vartab.empty, max);
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   571
                val instT = Vartab.fold (fn (x_i, (sort, ty)) =>
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   572
                  cons (Thm.ctyp_of thy (TVar (x_i, sort)), Thm.ctyp_of thy ty)) env [];
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   573
              in Thm.instantiate (instT, []) thm end;
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   574
          in if Sign.typ_instance thy (ty_strongest, ty)
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   575
            then if Sign.typ_instance thy (ty, ty_decl)
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   576
            then thm
28054
2b84d34c5d02 restructured and split code serializer module
haftmann
parents: 27983
diff changeset
   577
            else (warning ("Constraining type\n" ^ Code_Unit.string_of_typ thy ty
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   578
              ^ "\nof defining equation\n"
26928
ca87aff1ad2d structure Display: less pervasive operations;
wenzelm
parents: 26463
diff changeset
   579
              ^ Display.string_of_thm thm
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   580
              ^ "\nto permitted most general type\n"
28054
2b84d34c5d02 restructured and split code serializer module
haftmann
parents: 27983
diff changeset
   581
              ^ Code_Unit.string_of_typ thy ty_decl);
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   582
              constrain thm)
28054
2b84d34c5d02 restructured and split code serializer module
haftmann
parents: 27983
diff changeset
   583
            else Code_Unit.bad_thm ("Type\n" ^ Code_Unit.string_of_typ thy ty
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   584
              ^ "\nof defining equation\n"
26928
ca87aff1ad2d structure Display: less pervasive operations;
wenzelm
parents: 26463
diff changeset
   585
              ^ Display.string_of_thm thm
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   586
              ^ "\nis incompatible with permitted least general type\n"
28054
2b84d34c5d02 restructured and split code serializer module
haftmann
parents: 27983
diff changeset
   587
              ^ Code_Unit.string_of_typ thy ty_strongest)
24423
ae9cd0e92423 overloaded definitions accompanied by explicit constants
haftmann
parents: 24283
diff changeset
   588
          end;
ae9cd0e92423 overloaded definitions accompanied by explicit constants
haftmann
parents: 24283
diff changeset
   589
    fun check_typ_fun (c, thm) =
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   590
      let
26970
bc28e7bcb765 explicit type schemes for functions
haftmann
parents: 26947
diff changeset
   591
        val (_, ty) = const_of thy thm;
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   592
        val ty_decl = Sign.the_const_type thy c;
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   593
      in if Sign.typ_equiv thy (Type.strip_sorts ty_decl, Type.strip_sorts ty)
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   594
        then thm
28054
2b84d34c5d02 restructured and split code serializer module
haftmann
parents: 27983
diff changeset
   595
        else Code_Unit.bad_thm ("Type\n" ^ Code_Unit.string_of_typ thy ty
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   596
           ^ "\nof defining equation\n"
26928
ca87aff1ad2d structure Display: less pervasive operations;
wenzelm
parents: 26463
diff changeset
   597
           ^ Display.string_of_thm thm
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   598
           ^ "\nis incompatible with declared function type\n"
28054
2b84d34c5d02 restructured and split code serializer module
haftmann
parents: 27983
diff changeset
   599
           ^ Code_Unit.string_of_typ thy ty_decl)
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   600
      end;
24423
ae9cd0e92423 overloaded definitions accompanied by explicit constants
haftmann
parents: 24283
diff changeset
   601
    fun check_typ (c, thm) =
25597
34860182b250 moved instance parameter management from class.ML to axclass.ML
haftmann
parents: 25501
diff changeset
   602
      case AxClass.inst_of_param thy c
24837
cacc5744be75 clarified terminology
haftmann
parents: 24731
diff changeset
   603
       of SOME (c, tyco) => check_typ_classparam tyco (c, thm)
24423
ae9cd0e92423 overloaded definitions accompanied by explicit constants
haftmann
parents: 24283
diff changeset
   604
        | NONE => check_typ_fun (c, thm);
28368
8437fb395294 clarified function transformator interface
haftmann
parents: 28359
diff changeset
   605
    val c = const_of_eqn thy thm;
8437fb395294 clarified function transformator interface
haftmann
parents: 28359
diff changeset
   606
    val thm' = check_typ (c, thm);
8437fb395294 clarified function transformator interface
haftmann
parents: 28359
diff changeset
   607
  in (thm', linear) end;
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   608
28368
8437fb395294 clarified function transformator interface
haftmann
parents: 28359
diff changeset
   609
fun mk_eqn linear = Code_Unit.error_thm
8437fb395294 clarified function transformator interface
haftmann
parents: 28359
diff changeset
   610
  (assert_eqn_typ o (if linear then assert_eqn_linear else I) o Code_Unit.mk_eqn);
8437fb395294 clarified function transformator interface
haftmann
parents: 28359
diff changeset
   611
val mk_liberal_eqn = Code_Unit.warning_thm
8437fb395294 clarified function transformator interface
haftmann
parents: 28359
diff changeset
   612
  (assert_eqn_typ o assert_eqn_linear o Code_Unit.mk_eqn);
8437fb395294 clarified function transformator interface
haftmann
parents: 28359
diff changeset
   613
val mk_syntactic_eqn = Code_Unit.warning_thm
8437fb395294 clarified function transformator interface
haftmann
parents: 28359
diff changeset
   614
  (assert_eqn_typ o Code_Unit.mk_eqn);
8437fb395294 clarified function transformator interface
haftmann
parents: 28359
diff changeset
   615
val mk_default_eqn = Code_Unit.try_thm
8437fb395294 clarified function transformator interface
haftmann
parents: 28359
diff changeset
   616
  (assert_eqn_typ o assert_eqn_linear o Code_Unit.mk_eqn);
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   617
28143
e5c6c4aac52c different bookkeeping for code equations
haftmann
parents: 28054
diff changeset
   618
end; (*local*)
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   619
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   620
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   621
(** interfaces and attributes **)
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   622
24624
b8383b1bbae3 distinction between regular and default code theorems
haftmann
parents: 24585
diff changeset
   623
fun delete_force msg key xs =
b8383b1bbae3 distinction between regular and default code theorems
haftmann
parents: 24585
diff changeset
   624
  if AList.defined (op =) xs key then AList.delete (op =) key xs
b8383b1bbae3 distinction between regular and default code theorems
haftmann
parents: 24585
diff changeset
   625
  else error ("No such " ^ msg ^ ": " ^ quote key);
b8383b1bbae3 distinction between regular and default code theorems
haftmann
parents: 24585
diff changeset
   626
24423
ae9cd0e92423 overloaded definitions accompanied by explicit constants
haftmann
parents: 24283
diff changeset
   627
fun get_datatype thy tyco =
24844
98c006a30218 certificates for code generator case expressions
haftmann
parents: 24837
diff changeset
   628
  case Symtab.lookup ((the_dtyps o the_exec) thy) tyco
24423
ae9cd0e92423 overloaded definitions accompanied by explicit constants
haftmann
parents: 24283
diff changeset
   629
   of SOME spec => spec
ae9cd0e92423 overloaded definitions accompanied by explicit constants
haftmann
parents: 24283
diff changeset
   630
    | NONE => Sign.arity_number thy tyco
24848
5dbbd33c3236 replaced literal 'a by Name.aT;
wenzelm
parents: 24844
diff changeset
   631
        |> Name.invents Name.context Name.aT
24423
ae9cd0e92423 overloaded definitions accompanied by explicit constants
haftmann
parents: 24283
diff changeset
   632
        |> map (rpair [])
ae9cd0e92423 overloaded definitions accompanied by explicit constants
haftmann
parents: 24283
diff changeset
   633
        |> rpair [];
ae9cd0e92423 overloaded definitions accompanied by explicit constants
haftmann
parents: 24283
diff changeset
   634
ae9cd0e92423 overloaded definitions accompanied by explicit constants
haftmann
parents: 24283
diff changeset
   635
fun get_datatype_of_constr thy c =
ae9cd0e92423 overloaded definitions accompanied by explicit constants
haftmann
parents: 24283
diff changeset
   636
  case (snd o strip_type o Sign.the_const_type thy) c
ae9cd0e92423 overloaded definitions accompanied by explicit constants
haftmann
parents: 24283
diff changeset
   637
   of Type (tyco, _) => if member (op =)
24844
98c006a30218 certificates for code generator case expressions
haftmann
parents: 24837
diff changeset
   638
       ((the_default [] o Option.map (map fst o snd) o Symtab.lookup ((the_dtyps o the_exec) thy)) tyco) c
24423
ae9cd0e92423 overloaded definitions accompanied by explicit constants
haftmann
parents: 24283
diff changeset
   639
       then SOME tyco else NONE
ae9cd0e92423 overloaded definitions accompanied by explicit constants
haftmann
parents: 24283
diff changeset
   640
    | _ => NONE;
ae9cd0e92423 overloaded definitions accompanied by explicit constants
haftmann
parents: 24283
diff changeset
   641
ae9cd0e92423 overloaded definitions accompanied by explicit constants
haftmann
parents: 24283
diff changeset
   642
fun get_constr_typ thy c =
ae9cd0e92423 overloaded definitions accompanied by explicit constants
haftmann
parents: 24283
diff changeset
   643
  case get_datatype_of_constr thy c
ae9cd0e92423 overloaded definitions accompanied by explicit constants
haftmann
parents: 24283
diff changeset
   644
   of SOME tyco => let
ae9cd0e92423 overloaded definitions accompanied by explicit constants
haftmann
parents: 24283
diff changeset
   645
          val (vs, cos) = get_datatype thy tyco;
ae9cd0e92423 overloaded definitions accompanied by explicit constants
haftmann
parents: 24283
diff changeset
   646
          val SOME tys = AList.lookup (op =) cos c;
ae9cd0e92423 overloaded definitions accompanied by explicit constants
haftmann
parents: 24283
diff changeset
   647
          val ty = tys ---> Type (tyco, map TFree vs);
ae9cd0e92423 overloaded definitions accompanied by explicit constants
haftmann
parents: 24283
diff changeset
   648
        in SOME (Logic.varifyT ty) end
ae9cd0e92423 overloaded definitions accompanied by explicit constants
haftmann
parents: 24283
diff changeset
   649
    | NONE => NONE;
ae9cd0e92423 overloaded definitions accompanied by explicit constants
haftmann
parents: 24283
diff changeset
   650
24844
98c006a30218 certificates for code generator case expressions
haftmann
parents: 24837
diff changeset
   651
val get_case_data = Symtab.lookup o fst o the_cases o the_exec;
98c006a30218 certificates for code generator case expressions
haftmann
parents: 24837
diff changeset
   652
98c006a30218 certificates for code generator case expressions
haftmann
parents: 24837
diff changeset
   653
val is_undefined = Symtab.defined o snd o the_cases o the_exec;
98c006a30218 certificates for code generator case expressions
haftmann
parents: 24837
diff changeset
   654
28368
8437fb395294 clarified function transformator interface
haftmann
parents: 28359
diff changeset
   655
fun gen_add_eqn linear strict default thm thy =
8437fb395294 clarified function transformator interface
haftmann
parents: 28359
diff changeset
   656
  case (if strict then SOME o mk_eqn linear else mk_liberal_eqn) thm
8437fb395294 clarified function transformator interface
haftmann
parents: 28359
diff changeset
   657
   of SOME (thm, _) =>
28143
e5c6c4aac52c different bookkeeping for code equations
haftmann
parents: 28054
diff changeset
   658
        let
28368
8437fb395294 clarified function transformator interface
haftmann
parents: 28359
diff changeset
   659
          val c = const_of_eqn thy thm;
28143
e5c6c4aac52c different bookkeeping for code equations
haftmann
parents: 28054
diff changeset
   660
          val _ = if strict andalso (is_some o AxClass.class_of_param thy) c
e5c6c4aac52c different bookkeeping for code equations
haftmann
parents: 28054
diff changeset
   661
            then error ("Rejected polymorphic equation for overloaded constant:\n"
e5c6c4aac52c different bookkeeping for code equations
haftmann
parents: 28054
diff changeset
   662
              ^ Display.string_of_thm thm)
e5c6c4aac52c different bookkeeping for code equations
haftmann
parents: 28054
diff changeset
   663
            else ();
e5c6c4aac52c different bookkeeping for code equations
haftmann
parents: 28054
diff changeset
   664
          val _ = if strict andalso (is_some o get_datatype_of_constr thy) c
e5c6c4aac52c different bookkeeping for code equations
haftmann
parents: 28054
diff changeset
   665
            then error ("Rejected equation for datatype constructor:\n"
28368
8437fb395294 clarified function transformator interface
haftmann
parents: 28359
diff changeset
   666
              ^ Display.string_of_thm thm)
28143
e5c6c4aac52c different bookkeeping for code equations
haftmann
parents: 28054
diff changeset
   667
            else ();
e5c6c4aac52c different bookkeeping for code equations
haftmann
parents: 28054
diff changeset
   668
        in
28368
8437fb395294 clarified function transformator interface
haftmann
parents: 28359
diff changeset
   669
          (map_exec_purge (SOME [c]) o map_eqns) (Symtab.map_default
8437fb395294 clarified function transformator interface
haftmann
parents: 28359
diff changeset
   670
            (c, (true, Susp.value [])) (add_thm default (thm, linear))) thy
24624
b8383b1bbae3 distinction between regular and default code theorems
haftmann
parents: 24585
diff changeset
   671
        end
b8383b1bbae3 distinction between regular and default code theorems
haftmann
parents: 24585
diff changeset
   672
    | NONE => thy;
b8383b1bbae3 distinction between regular and default code theorems
haftmann
parents: 24585
diff changeset
   673
28368
8437fb395294 clarified function transformator interface
haftmann
parents: 28359
diff changeset
   674
val add_eqn = gen_add_eqn true true false;
8437fb395294 clarified function transformator interface
haftmann
parents: 28359
diff changeset
   675
val add_liberal_eqn = gen_add_eqn true false false;
8437fb395294 clarified function transformator interface
haftmann
parents: 28359
diff changeset
   676
val add_default_eqn = gen_add_eqn true false true;
8437fb395294 clarified function transformator interface
haftmann
parents: 28359
diff changeset
   677
val add_nonlinear_eqn = gen_add_eqn false true false;
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   678
28368
8437fb395294 clarified function transformator interface
haftmann
parents: 28359
diff changeset
   679
fun del_eqn thm thy = case mk_syntactic_eqn thm
8437fb395294 clarified function transformator interface
haftmann
parents: 28359
diff changeset
   680
 of SOME (thm, _) => let
8437fb395294 clarified function transformator interface
haftmann
parents: 28359
diff changeset
   681
        val c = const_of_eqn thy thm;
8437fb395294 clarified function transformator interface
haftmann
parents: 28359
diff changeset
   682
      in map_exec_purge (SOME [c]) (map_eqns
8437fb395294 clarified function transformator interface
haftmann
parents: 28359
diff changeset
   683
        (Symtab.map_entry c (del_thm thm))) thy
28143
e5c6c4aac52c different bookkeeping for code equations
haftmann
parents: 28054
diff changeset
   684
      end
e5c6c4aac52c different bookkeeping for code equations
haftmann
parents: 28054
diff changeset
   685
  | NONE => thy;
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   686
28368
8437fb395294 clarified function transformator interface
haftmann
parents: 28359
diff changeset
   687
fun del_eqns c = map_exec_purge (SOME [c])
8437fb395294 clarified function transformator interface
haftmann
parents: 28359
diff changeset
   688
  (map_eqns (Symtab.map_entry c (K (false, Susp.value []))));
26021
25d06476727e explicit del_funcs
haftmann
parents: 25968
diff changeset
   689
28368
8437fb395294 clarified function transformator interface
haftmann
parents: 28359
diff changeset
   690
fun add_eqnl (c, lthms) thy =
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   691
  let
28143
e5c6c4aac52c different bookkeeping for code equations
haftmann
parents: 28054
diff changeset
   692
    val lthms' = certificate thy (fn thy => certify_const thy c) lthms;
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   693
      (*FIXME must check compatibility with sort algebra;
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   694
        alas, naive checking results in non-termination!*)
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   695
  in
28143
e5c6c4aac52c different bookkeeping for code equations
haftmann
parents: 28054
diff changeset
   696
    map_exec_purge (SOME [c])
28368
8437fb395294 clarified function transformator interface
haftmann
parents: 28359
diff changeset
   697
      (map_eqns (Symtab.map_default (c, (true, Susp.value []))
28143
e5c6c4aac52c different bookkeeping for code equations
haftmann
parents: 28054
diff changeset
   698
        (add_lthms lthms'))) thy
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   699
  end;
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   700
28368
8437fb395294 clarified function transformator interface
haftmann
parents: 28359
diff changeset
   701
val add_default_eqn_attr = Attrib.internal (fn _ => Thm.declaration_attribute
8437fb395294 clarified function transformator interface
haftmann
parents: 28359
diff changeset
   702
  (fn thm => Context.mapping (add_default_eqn thm) I));
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   703
25485
33840a854e63 tuned interfaces of class module
haftmann
parents: 25462
diff changeset
   704
structure TypeInterpretation = InterpretationFun(type T = string * serial val eq = eq_snd (op =) : T * T -> bool);
25462
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25312
diff changeset
   705
24423
ae9cd0e92423 overloaded definitions accompanied by explicit constants
haftmann
parents: 24283
diff changeset
   706
fun add_datatype raw_cs thy =
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   707
  let
25597
34860182b250 moved instance parameter management from class.ML to axclass.ML
haftmann
parents: 25501
diff changeset
   708
    val cs = map (fn c_ty as (_, ty) => (AxClass.unoverload_const thy c_ty, ty)) raw_cs;
28054
2b84d34c5d02 restructured and split code serializer module
haftmann
parents: 27983
diff changeset
   709
    val (tyco, vs_cos) = Code_Unit.constrset_of_consts thy cs;
25462
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25312
diff changeset
   710
    val cs' = map fst (snd vs_cos);
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25312
diff changeset
   711
    val purge_cs = case Symtab.lookup ((the_dtyps o the_exec) thy) tyco
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25312
diff changeset
   712
     of SOME (vs, cos) => if null cos then NONE else SOME (cs' @ map fst cos)
24423
ae9cd0e92423 overloaded definitions accompanied by explicit constants
haftmann
parents: 24283
diff changeset
   713
      | NONE => NONE;
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   714
  in
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   715
    thy
25462
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25312
diff changeset
   716
    |> map_exec_purge purge_cs (map_dtyps (Symtab.update (tyco, vs_cos))
28368
8437fb395294 clarified function transformator interface
haftmann
parents: 28359
diff changeset
   717
        #> map_eqns (fold (Symtab.delete_safe o fst) cs))
25485
33840a854e63 tuned interfaces of class module
haftmann
parents: 25462
diff changeset
   718
    |> TypeInterpretation.data (tyco, serial ())
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   719
  end;
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   720
25485
33840a854e63 tuned interfaces of class module
haftmann
parents: 25462
diff changeset
   721
fun type_interpretation f =  TypeInterpretation.interpretation
33840a854e63 tuned interfaces of class module
haftmann
parents: 25462
diff changeset
   722
  (fn (tyco, _) => fn thy => f (tyco, get_datatype thy tyco) thy);
33840a854e63 tuned interfaces of class module
haftmann
parents: 25462
diff changeset
   723
24423
ae9cd0e92423 overloaded definitions accompanied by explicit constants
haftmann
parents: 24283
diff changeset
   724
fun add_datatype_cmd raw_cs thy =
ae9cd0e92423 overloaded definitions accompanied by explicit constants
haftmann
parents: 24283
diff changeset
   725
  let
28054
2b84d34c5d02 restructured and split code serializer module
haftmann
parents: 27983
diff changeset
   726
    val cs = map (Code_Unit.read_bare_const thy) raw_cs;
24423
ae9cd0e92423 overloaded definitions accompanied by explicit constants
haftmann
parents: 24283
diff changeset
   727
  in add_datatype cs thy end;
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   728
24844
98c006a30218 certificates for code generator case expressions
haftmann
parents: 24837
diff changeset
   729
fun add_case thm thy =
98c006a30218 certificates for code generator case expressions
haftmann
parents: 24837
diff changeset
   730
  let
28054
2b84d34c5d02 restructured and split code serializer module
haftmann
parents: 27983
diff changeset
   731
    val entry as (c, _) = Code_Unit.case_cert thm;
24844
98c006a30218 certificates for code generator case expressions
haftmann
parents: 24837
diff changeset
   732
  in
98c006a30218 certificates for code generator case expressions
haftmann
parents: 24837
diff changeset
   733
    (map_exec_purge (SOME [c]) o map_cases o apfst) (Symtab.update entry) thy
98c006a30218 certificates for code generator case expressions
haftmann
parents: 24837
diff changeset
   734
  end;
98c006a30218 certificates for code generator case expressions
haftmann
parents: 24837
diff changeset
   735
98c006a30218 certificates for code generator case expressions
haftmann
parents: 24837
diff changeset
   736
fun add_undefined c thy =
98c006a30218 certificates for code generator case expressions
haftmann
parents: 24837
diff changeset
   737
  (map_exec_purge (SOME [c]) o map_cases o apsnd) (Symtab.update (c, ())) thy;
98c006a30218 certificates for code generator case expressions
haftmann
parents: 24837
diff changeset
   738
27557
151731493264 simpsets as pre/postprocessors; generic preprocessor now named function transformators
haftmann
parents: 26970
diff changeset
   739
val map_pre = map_exec_purge NONE o map_thmproc o apfst o apfst;
151731493264 simpsets as pre/postprocessors; generic preprocessor now named function transformators
haftmann
parents: 26970
diff changeset
   740
val map_post = map_exec_purge NONE o map_thmproc o apfst o apsnd;
151731493264 simpsets as pre/postprocessors; generic preprocessor now named function transformators
haftmann
parents: 26970
diff changeset
   741
151731493264 simpsets as pre/postprocessors; generic preprocessor now named function transformators
haftmann
parents: 26970
diff changeset
   742
fun add_inline thm thy = (map_pre o MetaSimplifier.add_simp)
28054
2b84d34c5d02 restructured and split code serializer module
haftmann
parents: 27983
diff changeset
   743
  (Code_Unit.error_thm Code_Unit.mk_rew thm) thy;
27557
151731493264 simpsets as pre/postprocessors; generic preprocessor now named function transformators
haftmann
parents: 26970
diff changeset
   744
    (*fully applied in order to get right context for mk_rew!*)
151731493264 simpsets as pre/postprocessors; generic preprocessor now named function transformators
haftmann
parents: 26970
diff changeset
   745
151731493264 simpsets as pre/postprocessors; generic preprocessor now named function transformators
haftmann
parents: 26970
diff changeset
   746
fun del_inline thm thy = (map_pre o MetaSimplifier.del_simp)
28054
2b84d34c5d02 restructured and split code serializer module
haftmann
parents: 27983
diff changeset
   747
  (Code_Unit.error_thm Code_Unit.mk_rew thm) thy;
27557
151731493264 simpsets as pre/postprocessors; generic preprocessor now named function transformators
haftmann
parents: 26970
diff changeset
   748
    (*fully applied in order to get right context for mk_rew!*)
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   749
27557
151731493264 simpsets as pre/postprocessors; generic preprocessor now named function transformators
haftmann
parents: 26970
diff changeset
   750
fun add_post thm thy = (map_post o MetaSimplifier.add_simp)
28054
2b84d34c5d02 restructured and split code serializer module
haftmann
parents: 27983
diff changeset
   751
  (Code_Unit.error_thm Code_Unit.mk_rew thm) thy;
27557
151731493264 simpsets as pre/postprocessors; generic preprocessor now named function transformators
haftmann
parents: 26970
diff changeset
   752
    (*fully applied in order to get right context for mk_rew!*)
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   753
27557
151731493264 simpsets as pre/postprocessors; generic preprocessor now named function transformators
haftmann
parents: 26970
diff changeset
   754
fun del_post thm thy = (map_post o MetaSimplifier.del_simp)
28054
2b84d34c5d02 restructured and split code serializer module
haftmann
parents: 27983
diff changeset
   755
  (Code_Unit.error_thm Code_Unit.mk_rew thm) thy;
27557
151731493264 simpsets as pre/postprocessors; generic preprocessor now named function transformators
haftmann
parents: 26970
diff changeset
   756
    (*fully applied in order to get right context for mk_rew!*)
151731493264 simpsets as pre/postprocessors; generic preprocessor now named function transformators
haftmann
parents: 26970
diff changeset
   757
  
151731493264 simpsets as pre/postprocessors; generic preprocessor now named function transformators
haftmann
parents: 26970
diff changeset
   758
fun add_functrans (name, f) =
151731493264 simpsets as pre/postprocessors; generic preprocessor now named function transformators
haftmann
parents: 26970
diff changeset
   759
  (map_exec_purge NONE o map_thmproc o apsnd)
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   760
    (AList.update (op =) (name, (serial (), f)));
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   761
27557
151731493264 simpsets as pre/postprocessors; generic preprocessor now named function transformators
haftmann
parents: 26970
diff changeset
   762
fun del_functrans name =
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   763
  (map_exec_purge NONE o map_thmproc o apsnd)
27609
b23c9ad0fe7d tuned code theorem bookkeeping
haftmann
parents: 27582
diff changeset
   764
    (delete_force "function transformer" name);
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   765
26463
9283b4185fdf Context.>> : operate on Context.generic;
wenzelm
parents: 26435
diff changeset
   766
val _ = Context.>> (Context.map_theory
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   767
  (let
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   768
    fun mk_attribute f = Thm.declaration_attribute (fn thm => Context.mapping (f thm) I);
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   769
    fun add_simple_attribute (name, f) =
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   770
      add_attribute (name, Scan.succeed (mk_attribute f));
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   771
    fun add_del_attribute (name, (add, del)) =
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   772
      add_attribute (name, Args.del |-- Scan.succeed (mk_attribute del)
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   773
        || Scan.succeed (mk_attribute add))
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   774
  in
25462
dad0291cb76a rudimentary instantiation target
haftmann
parents: 25312
diff changeset
   775
    TypeInterpretation.init
28368
8437fb395294 clarified function transformator interface
haftmann
parents: 28359
diff changeset
   776
    #> add_del_attribute ("func", (add_eqn, del_eqn))
8437fb395294 clarified function transformator interface
haftmann
parents: 28359
diff changeset
   777
    #> add_simple_attribute ("nbe", add_nonlinear_eqn)
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   778
    #> add_del_attribute ("inline", (add_inline, del_inline))
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   779
    #> add_del_attribute ("post", (add_post, del_post))
26463
9283b4185fdf Context.>> : operate on Context.generic;
wenzelm
parents: 26435
diff changeset
   780
  end));
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   781
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   782
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   783
(** post- and preprocessing **)
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   784
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   785
local
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   786
27609
b23c9ad0fe7d tuned code theorem bookkeeping
haftmann
parents: 27582
diff changeset
   787
fun apply_functrans thy [] = []
28353
40306cc4d16a (temporary workaround)
haftmann
parents: 28350
diff changeset
   788
  | apply_functrans thy (thms as (thm, _) :: _) =
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   789
      let
28368
8437fb395294 clarified function transformator interface
haftmann
parents: 28359
diff changeset
   790
        val const = const_of_eqn thy thm;
27609
b23c9ad0fe7d tuned code theorem bookkeeping
haftmann
parents: 27582
diff changeset
   791
        val functrans = (map (fn (_, (_, f)) => f thy) o #functrans
b23c9ad0fe7d tuned code theorem bookkeeping
haftmann
parents: 27582
diff changeset
   792
          o the_thmproc o the_exec) thy;
28353
40306cc4d16a (temporary workaround)
haftmann
parents: 28350
diff changeset
   793
        val thms' = perhaps (perhaps_loop (perhaps_apply functrans)) (map fst thms);
40306cc4d16a (temporary workaround)
haftmann
parents: 28350
diff changeset
   794
        val thms'' = certify_const thy const thms';
28368
8437fb395294 clarified function transformator interface
haftmann
parents: 28359
diff changeset
   795
      in map Code_Unit.add_linear thms'' end;
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   796
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   797
fun rhs_conv conv thm =
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   798
  let
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   799
    val thm' = (conv o Thm.rhs_of) thm;
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   800
  in Thm.transitive thm thm' end
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   801
24837
cacc5744be75 clarified terminology
haftmann
parents: 24731
diff changeset
   802
fun term_of_conv thy f =
cacc5744be75 clarified terminology
haftmann
parents: 24731
diff changeset
   803
  Thm.cterm_of thy
cacc5744be75 clarified terminology
haftmann
parents: 24731
diff changeset
   804
  #> f
cacc5744be75 clarified terminology
haftmann
parents: 24731
diff changeset
   805
  #> Thm.prop_of
cacc5744be75 clarified terminology
haftmann
parents: 24731
diff changeset
   806
  #> Logic.dest_equals
cacc5744be75 clarified terminology
haftmann
parents: 24731
diff changeset
   807
  #> snd;
cacc5744be75 clarified terminology
haftmann
parents: 24731
diff changeset
   808
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   809
in
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   810
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   811
fun preprocess thy thms =
27582
367aff8d7ffd dropped junk
haftmann
parents: 27557
diff changeset
   812
  let
367aff8d7ffd dropped junk
haftmann
parents: 27557
diff changeset
   813
    val pre = (Simplifier.theory_context thy o #pre o the_thmproc o the_exec) thy;
367aff8d7ffd dropped junk
haftmann
parents: 27557
diff changeset
   814
  in
367aff8d7ffd dropped junk
haftmann
parents: 27557
diff changeset
   815
    thms
27609
b23c9ad0fe7d tuned code theorem bookkeeping
haftmann
parents: 27582
diff changeset
   816
    |> apply_functrans thy
28368
8437fb395294 clarified function transformator interface
haftmann
parents: 28359
diff changeset
   817
    |> (map o apfst) (Code_Unit.rewrite_eqn pre)
28350
715163ec93c0 non left-linear equations for nbe
haftmann
parents: 28143
diff changeset
   818
    (*FIXME - must check here: rewrite rule, defining equation, proper constant *)
28353
40306cc4d16a (temporary workaround)
haftmann
parents: 28350
diff changeset
   819
    |> (map o apfst) (AxClass.unoverload thy)
28368
8437fb395294 clarified function transformator interface
haftmann
parents: 28359
diff changeset
   820
    |> burrow_fst common_typ_eqns
27582
367aff8d7ffd dropped junk
haftmann
parents: 27557
diff changeset
   821
  end;
26970
bc28e7bcb765 explicit type schemes for functions
haftmann
parents: 26947
diff changeset
   822
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   823
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   824
fun preprocess_conv ct =
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   825
  let
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   826
    val thy = Thm.theory_of_cterm ct;
27582
367aff8d7ffd dropped junk
haftmann
parents: 27557
diff changeset
   827
    val pre = (Simplifier.theory_context thy o #pre o the_thmproc o the_exec) thy;
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   828
  in
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   829
    ct
27582
367aff8d7ffd dropped junk
haftmann
parents: 27557
diff changeset
   830
    |> Simplifier.rewrite pre
25597
34860182b250 moved instance parameter management from class.ML to axclass.ML
haftmann
parents: 25501
diff changeset
   831
    |> rhs_conv (AxClass.unoverload_conv thy)
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   832
  end;
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   833
24837
cacc5744be75 clarified terminology
haftmann
parents: 24731
diff changeset
   834
fun preprocess_term thy = term_of_conv thy preprocess_conv;
cacc5744be75 clarified terminology
haftmann
parents: 24731
diff changeset
   835
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   836
fun postprocess_conv ct =
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   837
  let
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   838
    val thy = Thm.theory_of_cterm ct;
27582
367aff8d7ffd dropped junk
haftmann
parents: 27557
diff changeset
   839
    val post = (Simplifier.theory_context thy o #post o the_thmproc o the_exec) thy;
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   840
  in
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   841
    ct
25597
34860182b250 moved instance parameter management from class.ML to axclass.ML
haftmann
parents: 25501
diff changeset
   842
    |> AxClass.overload_conv thy
27582
367aff8d7ffd dropped junk
haftmann
parents: 27557
diff changeset
   843
    |> rhs_conv (Simplifier.rewrite post)
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   844
  end;
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   845
24837
cacc5744be75 clarified terminology
haftmann
parents: 24731
diff changeset
   846
fun postprocess_term thy = term_of_conv thy postprocess_conv;
cacc5744be75 clarified terminology
haftmann
parents: 24731
diff changeset
   847
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   848
end; (*local*)
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   849
25597
34860182b250 moved instance parameter management from class.ML to axclass.ML
haftmann
parents: 25501
diff changeset
   850
fun default_typ_proto thy c = case AxClass.inst_of_param thy c
24837
cacc5744be75 clarified terminology
haftmann
parents: 24731
diff changeset
   851
 of SOME (c, tyco) => classparam_weakest_typ thy ((the o AxClass.class_of_param thy) c)
24423
ae9cd0e92423 overloaded definitions accompanied by explicit constants
haftmann
parents: 24283
diff changeset
   852
      (c, tyco) |> SOME
ae9cd0e92423 overloaded definitions accompanied by explicit constants
haftmann
parents: 24283
diff changeset
   853
  | NONE => (case AxClass.class_of_param thy c
ae9cd0e92423 overloaded definitions accompanied by explicit constants
haftmann
parents: 24283
diff changeset
   854
     of SOME class => SOME (Term.map_type_tvar
24848
5dbbd33c3236 replaced literal 'a by Name.aT;
wenzelm
parents: 24844
diff changeset
   855
          (K (TVar ((Name.aT, 0), [class]))) (Sign.the_const_type thy c))
24423
ae9cd0e92423 overloaded definitions accompanied by explicit constants
haftmann
parents: 24283
diff changeset
   856
      | NONE => get_constr_typ thy c);
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   857
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   858
local
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   859
28368
8437fb395294 clarified function transformator interface
haftmann
parents: 28359
diff changeset
   860
fun get_eqns thy const =
8437fb395294 clarified function transformator interface
haftmann
parents: 28359
diff changeset
   861
  Symtab.lookup ((the_eqns o the_exec) thy) const
28143
e5c6c4aac52c different bookkeeping for code equations
haftmann
parents: 28054
diff changeset
   862
  |> Option.map (Susp.force o snd)
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   863
  |> these
28350
715163ec93c0 non left-linear equations for nbe
haftmann
parents: 28143
diff changeset
   864
  |> (map o apfst) (Thm.transfer thy);
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   865
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   866
in
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   867
28368
8437fb395294 clarified function transformator interface
haftmann
parents: 28359
diff changeset
   868
fun these_eqns thy const =
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   869
  let
28368
8437fb395294 clarified function transformator interface
haftmann
parents: 28359
diff changeset
   870
    val drop_refl = filter_out
8437fb395294 clarified function transformator interface
haftmann
parents: 28359
diff changeset
   871
      (is_equal o Term.fast_term_ord o Logic.dest_equals o Thm.plain_prop_of o fst);
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   872
  in
28368
8437fb395294 clarified function transformator interface
haftmann
parents: 28359
diff changeset
   873
    get_eqns thy const
28353
40306cc4d16a (temporary workaround)
haftmann
parents: 28350
diff changeset
   874
    |> preprocess thy
28368
8437fb395294 clarified function transformator interface
haftmann
parents: 28359
diff changeset
   875
    |> drop_refl
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   876
  end;
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   877
24423
ae9cd0e92423 overloaded definitions accompanied by explicit constants
haftmann
parents: 24283
diff changeset
   878
fun default_typ thy c = case default_typ_proto thy c
28054
2b84d34c5d02 restructured and split code serializer module
haftmann
parents: 27983
diff changeset
   879
 of SOME ty => Code_Unit.typscheme thy (c, ty)
28368
8437fb395294 clarified function transformator interface
haftmann
parents: 28359
diff changeset
   880
  | NONE => (case get_eqns thy c
8437fb395294 clarified function transformator interface
haftmann
parents: 28359
diff changeset
   881
     of (thm, _) :: _ => snd (Code_Unit.head_eqn (AxClass.unoverload thy thm))
28054
2b84d34c5d02 restructured and split code serializer module
haftmann
parents: 27983
diff changeset
   882
      | [] => Code_Unit.typscheme thy (c, Sign.the_const_type thy c));
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   883
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   884
end; (*local*)
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   885
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   886
end; (*struct*)
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   887
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   888
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   889
(** type-safe interfaces for data depedent on executable content **)
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   890
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   891
functor CodeDataFun(Data: CODE_DATA_ARGS): CODE_DATA =
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   892
struct
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   893
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   894
type T = Data.T;
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   895
exception Data of T;
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   896
fun dest (Data x) = x
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   897
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   898
val kind = Code.declare_data (Data Data.empty)
27609
b23c9ad0fe7d tuned code theorem bookkeeping
haftmann
parents: 27582
diff changeset
   899
  (fn thy => fn cs => fn Data x => Data (Data.purge thy cs x));
24219
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   900
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   901
val data_op = (kind, Data, dest);
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   902
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   903
val get = Code.get_data data_op;
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   904
val change = Code.change_data data_op;
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   905
fun change_yield thy = Code.change_yield_data data_op thy;
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   906
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   907
end;
e558fe311376 new structure for code generator modules
haftmann
parents:
diff changeset
   908
28143
e5c6c4aac52c different bookkeeping for code equations
haftmann
parents: 28054
diff changeset
   909
structure Code : CODE = struct open Code; end;