src/HOL/Tools/inductive_codegen.ML
author berghofe
Wed, 13 Nov 2002 15:28:41 +0100
changeset 13708 a3a410782c95
parent 13105 3d1e7a199bdc
child 14162 f05f299512e9
permissions -rw-r--r--
prove_goal' -> Goal.simple_prove_goal_cterm
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12453
806502073957 - Changed type of invoke_codegen
berghofe
parents: 11539
diff changeset
     1
(*  Title:      HOL/inductive_codegen.ML
11537
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
     2
    ID:         $Id$
11539
0f17da240450 tuned headers;
wenzelm
parents: 11537
diff changeset
     3
    Author:     Stefan Berghofer, TU Muenchen
0f17da240450 tuned headers;
wenzelm
parents: 11537
diff changeset
     4
    License:    GPL (GNU GENERAL PUBLIC LICENSE)
11537
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
     5
11539
0f17da240450 tuned headers;
wenzelm
parents: 11537
diff changeset
     6
Code generator for inductive predicates.
11537
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
     7
*)
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
     8
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
     9
signature INDUCTIVE_CODEGEN =
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
    10
sig
12557
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
    11
  val add : theory attribute
11537
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
    12
  val setup : (theory -> theory) list
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
    13
end;
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
    14
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
    15
structure InductiveCodegen : INDUCTIVE_CODEGEN =
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
    16
struct
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
    17
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
    18
open Codegen;
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
    19
12557
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
    20
(**** theory data ****)
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
    21
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
    22
structure CodegenArgs =
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
    23
struct
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
    24
  val name = "HOL/inductive_codegen";
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
    25
  type T = thm list Symtab.table;
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
    26
  val empty = Symtab.empty;
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
    27
  val copy = I;
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
    28
  val prep_ext = I;
13105
3d1e7a199bdc use eq_thm_prop instead of slightly inadequate eq_thm;
wenzelm
parents: 13038
diff changeset
    29
  val merge = Symtab.merge_multi Drule.eq_thm_prop;
12557
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
    30
  fun print _ _ = ();
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
    31
end;
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
    32
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
    33
structure CodegenData = TheoryDataFun(CodegenArgs);
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
    34
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
    35
fun warn thm = warning ("InductiveCodegen: Not a proper clause:\n" ^
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
    36
  string_of_thm thm);
11537
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
    37
12557
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
    38
fun add (p as (thy, thm)) =
12562
323ce5a89695 Fixed bug in function add.
berghofe
parents: 12557
diff changeset
    39
  let val tab = CodegenData.get thy;
12557
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
    40
  in (case concl_of thm of
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
    41
      _ $ (Const ("op :", _) $ _ $ t) => (case head_of t of
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
    42
        Const (s, _) => (CodegenData.put (Symtab.update ((s,
12562
323ce5a89695 Fixed bug in function add.
berghofe
parents: 12557
diff changeset
    43
          if_none (Symtab.lookup (tab, s)) [] @ [thm]), tab)) thy, thm)
12557
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
    44
      | _ => (warn thm; p))
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
    45
    | _ => (warn thm; p))
12562
323ce5a89695 Fixed bug in function add.
berghofe
parents: 12557
diff changeset
    46
  end;
12557
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
    47
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
    48
fun get_clauses thy s =
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
    49
  (case Symtab.lookup (CodegenData.get thy, s) of
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
    50
     None => (case InductivePackage.get_inductive thy s of
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
    51
       None => None
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
    52
     | Some ({names, ...}, {intrs, ...}) => Some (names, intrs))
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
    53
   | Some thms => Some ([s], thms));
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
    54
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
    55
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
    56
(**** improper tuples ****)
11537
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
    57
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
    58
fun prod_factors p (Const ("Pair", _) $ t $ u) =
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
    59
      p :: prod_factors (1::p) t @ prod_factors (2::p) u
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
    60
  | prod_factors p _ = [];
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
    61
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
    62
fun split_prod p ps t = if p mem ps then (case t of
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
    63
       Const ("Pair", _) $ t $ u =>
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
    64
         split_prod (1::p) ps t @ split_prod (2::p) ps u
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
    65
     | _ => error "Inconsistent use of products") else [t];
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
    66
12557
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
    67
datatype factors = FVar of int list list | FFix of int list list;
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
    68
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
    69
exception Factors;
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
    70
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
    71
fun mg_factor (FVar f) (FVar f') = FVar (f inter f')
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
    72
  | mg_factor (FVar f) (FFix f') =
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
    73
      if f' subset f then FFix f' else raise Factors
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
    74
  | mg_factor (FFix f) (FVar f') =
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
    75
      if f subset f' then FFix f else raise Factors
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
    76
  | mg_factor (FFix f) (FFix f') =
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
    77
      if f subset f' andalso f' subset f then FFix f else raise Factors;
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
    78
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
    79
fun dest_factors (FVar f) = f
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
    80
  | dest_factors (FFix f) = f;
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
    81
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
    82
fun infer_factors sg extra_fs (fs, (optf, t)) =
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
    83
  let fun err s = error (s ^ "\n" ^ Sign.string_of_term sg t)
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
    84
  in (case (optf, strip_comb t) of
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
    85
      (Some f, (Const (name, _), args)) =>
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
    86
        (case assoc (extra_fs, name) of
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
    87
           None => overwrite (fs, (name, if_none
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
    88
             (apsome (mg_factor f) (assoc (fs, name))) f))
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
    89
         | Some (fs', f') => (mg_factor f (FFix f');
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
    90
             foldl (infer_factors sg extra_fs)
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
    91
               (fs, map (apsome FFix) fs' ~~ args)))
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
    92
    | (Some f, (Var ((name, _), _), [])) =>
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
    93
        overwrite (fs, (name, if_none
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
    94
          (apsome (mg_factor f) (assoc (fs, name))) f))
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
    95
    | (None, _) => fs
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
    96
    | _ => err "Illegal term")
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
    97
      handle Factors => err "Product factor mismatch in"
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
    98
  end;
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
    99
11537
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   100
fun string_of_factors p ps = if p mem ps then
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   101
    "(" ^ string_of_factors (1::p) ps ^ ", " ^ string_of_factors (2::p) ps ^ ")"
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   102
  else "_";
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   103
12557
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   104
11537
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   105
(**** check if a term contains only constructor functions ****)
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   106
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   107
fun is_constrt thy =
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   108
  let
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   109
    val cnstrs = flat (flat (map
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   110
      (map (fn (_, (_, _, cs)) => map (apsnd length) cs) o #descr o snd)
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   111
      (Symtab.dest (DatatypePackage.get_datatypes thy))));
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   112
    fun check t = (case strip_comb t of
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   113
        (Var _, []) => true
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   114
      | (Const (s, _), ts) => (case assoc (cnstrs, s) of
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   115
            None => false
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   116
          | Some i => length ts = i andalso forall check ts)
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   117
      | _ => false)
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   118
  in check end;
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   119
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   120
(**** check if a type is an equality type (i.e. doesn't contain fun) ****)
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   121
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   122
fun is_eqT (Type (s, Ts)) = s <> "fun" andalso forall is_eqT Ts
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   123
  | is_eqT _ = true;
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   124
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   125
(**** mode inference ****)
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   126
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   127
val term_vs = map (fst o fst o dest_Var) o term_vars;
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   128
val terms_vs = distinct o flat o (map term_vs);
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   129
13038
e968745986f1 - made modes_of more robust
berghofe
parents: 12565
diff changeset
   130
fun assoc' s tab key = (case assoc (tab, key) of
e968745986f1 - made modes_of more robust
berghofe
parents: 12565
diff changeset
   131
      None => error ("Unable to determine " ^ s ^ " of " ^ quote key)
e968745986f1 - made modes_of more robust
berghofe
parents: 12565
diff changeset
   132
    | Some x => x);
e968745986f1 - made modes_of more robust
berghofe
parents: 12565
diff changeset
   133
11537
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   134
(** collect all Vars in a term (with duplicates!) **)
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   135
fun term_vTs t = map (apfst fst o dest_Var)
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   136
  (filter is_Var (foldl_aterms (op :: o Library.swap) ([], t)));
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   137
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   138
fun known_args _ _ [] = []
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   139
  | known_args vs i (t::ts) = if term_vs t subset vs then i::known_args vs (i+1) ts
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   140
      else known_args vs (i+1) ts;
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   141
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   142
fun get_args _ _ [] = ([], [])
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   143
  | get_args is i (x::xs) = (if i mem is then apfst else apsnd) (cons x)
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   144
      (get_args is (i+1) xs);
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   145
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   146
fun merge xs [] = xs
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   147
  | merge [] ys = ys
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   148
  | merge (x::xs) (y::ys) = if length x >= length y then x::merge xs (y::ys)
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   149
      else y::merge (x::xs) ys;
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   150
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   151
fun subsets i j = if i <= j then
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   152
       let val is = subsets (i+1) j
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   153
       in merge (map (fn ks => i::ks) is) is end
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   154
     else [[]];
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   155
12557
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   156
fun cprod ([], ys) = []
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   157
  | cprod (x :: xs, ys) = map (pair x) ys @ cprod (xs, ys);
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   158
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   159
fun cprods xss = foldr (map op :: o cprod) (xss, [[]]);
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   160
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   161
datatype mode = Mode of (int list option list * int list) * mode option list;
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   162
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   163
fun modes_of modes t =
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   164
  let
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   165
    fun mk_modes name args = flat
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   166
      (map (fn (m as (iss, is)) => map (Mode o pair m) (cprods (map
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   167
        (fn (None, _) => [None]
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   168
          | (Some js, arg) => map Some
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   169
              (filter (fn Mode ((_, js'), _) => js=js') (modes_of modes arg)))
13038
e968745986f1 - made modes_of more robust
berghofe
parents: 12565
diff changeset
   170
                (iss ~~ args)))) (assoc' "modes" modes name))
12557
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   171
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   172
  in (case strip_comb t of
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   173
      (Const (name, _), args) => mk_modes name args
13038
e968745986f1 - made modes_of more robust
berghofe
parents: 12565
diff changeset
   174
    | (Var ((name, _), _), args) => mk_modes name args
e968745986f1 - made modes_of more robust
berghofe
parents: 12565
diff changeset
   175
    | (Free (name, _), args) => mk_modes name args)
12557
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   176
  end;
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   177
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   178
datatype indprem = Prem of term list * term | Sidecond of term;
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   179
11537
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   180
fun select_mode_prem thy modes vs ps =
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   181
  find_first (is_some o snd) (ps ~~ map
12557
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   182
    (fn Prem (us, t) => find_first (fn Mode ((_, is), _) =>
11537
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   183
          let
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   184
            val (_, out_ts) = get_args is 1 us;
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   185
            val vTs = flat (map term_vTs out_ts);
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   186
            val dupTs = map snd (duplicates vTs) @
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   187
              mapfilter (curry assoc vTs) vs;
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   188
          in
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   189
            is subset known_args vs 1 us andalso
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   190
            forall (is_constrt thy) (snd (get_args is 1 us)) andalso
12557
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   191
            term_vs t subset vs andalso
11537
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   192
            forall is_eqT dupTs
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   193
          end)
12557
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   194
            (modes_of modes t)
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   195
      | Sidecond t => if term_vs t subset vs then Some (Mode (([], []), []))
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   196
          else None) ps);
11537
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   197
12557
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   198
fun check_mode_clause thy arg_vs modes (iss, is) (ts, ps) =
11537
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   199
  let
12557
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   200
    val modes' = modes @ mapfilter
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   201
      (fn (_, None) => None | (v, Some js) => Some (v, [([], js)]))
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   202
        (arg_vs ~~ iss);
11537
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   203
    fun check_mode_prems vs [] = Some vs
12557
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   204
      | check_mode_prems vs ps = (case select_mode_prem thy modes' vs ps of
11537
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   205
          None => None
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   206
        | Some (x, _) => check_mode_prems
12557
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   207
            (case x of Prem (us, _) => vs union terms_vs us | _ => vs)
11537
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   208
            (filter_out (equal x) ps));
12557
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   209
    val (in_ts', _) = get_args is 1 ts;
11537
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   210
    val in_ts = filter (is_constrt thy) in_ts';
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   211
    val in_vs = terms_vs in_ts;
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   212
    val concl_vs = terms_vs ts
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   213
  in
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   214
    forall is_eqT (map snd (duplicates (flat (map term_vTs in_ts')))) andalso
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   215
    (case check_mode_prems (arg_vs union in_vs) ps of
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   216
       None => false
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   217
     | Some vs => concl_vs subset vs)
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   218
  end;
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   219
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   220
fun check_modes_pred thy arg_vs preds modes (p, ms) =
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   221
  let val Some rs = assoc (preds, p)
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   222
  in (p, filter (fn m => forall (check_mode_clause thy arg_vs modes m) rs) ms) end
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   223
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   224
fun fixp f x =
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   225
  let val y = f x
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   226
  in if x = y then x else fixp f y end;
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   227
12557
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   228
fun infer_modes thy extra_modes factors arg_vs preds = fixp (fn modes =>
11537
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   229
  map (check_modes_pred thy arg_vs preds (modes @ extra_modes)) modes)
12557
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   230
    (map (fn (s, (fs, f)) => (s, cprod (cprods (map
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   231
      (fn None => [None]
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   232
        | Some f' => map Some (subsets 1 (length f' + 1))) fs),
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   233
      subsets 1 (length f + 1)))) factors);
11537
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   234
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   235
(**** code generation ****)
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   236
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   237
fun mk_eq (x::xs) =
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   238
  let fun mk_eqs _ [] = []
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   239
        | mk_eqs a (b::cs) = Pretty.str (a ^ " = " ^ b) :: mk_eqs b cs
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   240
  in mk_eqs x xs end;
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   241
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   242
fun mk_tuple xs = Pretty.block (Pretty.str "(" ::
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   243
  flat (separate [Pretty.str ",", Pretty.brk 1] (map single xs)) @
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   244
  [Pretty.str ")"]);
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   245
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   246
fun mk_v ((names, vs), s) = (case assoc (vs, s) of
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   247
      None => ((names, (s, [s])::vs), s)
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   248
    | Some xs => let val s' = variant names s in
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   249
        ((s'::names, overwrite (vs, (s, s'::xs))), s') end);
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   250
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   251
fun distinct_v (nvs, Var ((s, 0), T)) =
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   252
      apsnd (Var o rpair T o rpair 0) (mk_v (nvs, s))
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   253
  | distinct_v (nvs, t $ u) =
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   254
      let
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   255
        val (nvs', t') = distinct_v (nvs, t);
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   256
        val (nvs'', u') = distinct_v (nvs', u);
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   257
      in (nvs'', t' $ u') end
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   258
  | distinct_v x = x;
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   259
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   260
fun compile_match nvs eq_ps out_ps success_p fail_p =
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   261
  let val eqs = flat (separate [Pretty.str " andalso", Pretty.brk 1]
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   262
    (map single (flat (map (mk_eq o snd) nvs) @ eq_ps)));
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   263
  in
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   264
    Pretty.block
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   265
     ([Pretty.str "(fn ", mk_tuple out_ps, Pretty.str " =>", Pretty.brk 1] @
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   266
      (Pretty.block ((if eqs=[] then [] else Pretty.str "if " ::
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   267
         [Pretty.block eqs, Pretty.brk 1, Pretty.str "then "]) @
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   268
         (success_p ::
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   269
          (if eqs=[] then [] else [Pretty.brk 1, Pretty.str "else ", fail_p]))) ::
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   270
       [Pretty.brk 1, Pretty.str "| _ => ", fail_p, Pretty.str ")"]))
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   271
  end;
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   272
12557
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   273
fun modename thy s (iss, is) = space_implode "__"
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   274
  (mk_const_id (sign_of thy) s ::
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   275
    map (space_implode "_" o map string_of_int) (mapfilter I iss @ [is]));
11537
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   276
12557
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   277
fun compile_expr thy dep brack (gr, (None, t)) =
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   278
      apsnd single (invoke_codegen thy dep brack (gr, t))
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   279
  | compile_expr _ _ _ (gr, (Some _, Var ((name, _), _))) =
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   280
      (gr, [Pretty.str name])
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   281
  | compile_expr thy dep brack (gr, (Some (Mode (mode, ms)), t)) =
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   282
      let
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   283
        val (Const (name, _), args) = strip_comb t;
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   284
        val (gr', ps) = foldl_map
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   285
          (compile_expr thy dep true) (gr, ms ~~ args);
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   286
      in (gr', (if brack andalso not (null ps) then
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   287
        single o parens o Pretty.block else I)
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   288
          (flat (separate [Pretty.brk 1]
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   289
            ([Pretty.str (modename thy name mode)] :: ps))))
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   290
      end;
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   291
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   292
fun compile_clause thy gr dep all_vs arg_vs modes (iss, is) (ts, ps) =
11537
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   293
  let
12557
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   294
    val modes' = modes @ mapfilter
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   295
      (fn (_, None) => None | (v, Some js) => Some (v, [([], js)]))
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   296
        (arg_vs ~~ iss);
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   297
11537
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   298
    fun check_constrt ((names, eqs), t) =
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   299
      if is_constrt thy t then ((names, eqs), t) else
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   300
        let val s = variant names "x";
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   301
        in ((s::names, (s, t)::eqs), Var ((s, 0), fastype_of t)) end;
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   302
12557
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   303
    val (in_ts, out_ts) = get_args is 1 ts;
11537
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   304
    val ((all_vs', eqs), in_ts') =
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   305
      foldl_map check_constrt ((all_vs, []), in_ts);
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   306
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   307
    fun compile_prems out_ts' vs names gr [] =
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   308
          let
12453
806502073957 - Changed type of invoke_codegen
berghofe
parents: 11539
diff changeset
   309
            val (gr2, out_ps) = foldl_map
806502073957 - Changed type of invoke_codegen
berghofe
parents: 11539
diff changeset
   310
              (invoke_codegen thy dep false) (gr, out_ts);
11537
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   311
            val (gr3, eq_ps) = foldl_map (fn (gr, (s, t)) =>
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   312
              apsnd (Pretty.block o cons (Pretty.str (s ^ " = ")) o single)
12453
806502073957 - Changed type of invoke_codegen
berghofe
parents: 11539
diff changeset
   313
                (invoke_codegen thy dep false (gr, t))) (gr2, eqs);
11537
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   314
            val (nvs, out_ts'') = foldl_map distinct_v
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   315
              ((names, map (fn x => (x, [x])) vs), out_ts');
12453
806502073957 - Changed type of invoke_codegen
berghofe
parents: 11539
diff changeset
   316
            val (gr4, out_ps') = foldl_map
806502073957 - Changed type of invoke_codegen
berghofe
parents: 11539
diff changeset
   317
              (invoke_codegen thy dep false) (gr3, out_ts'');
11537
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   318
          in
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   319
            (gr4, compile_match (snd nvs) eq_ps out_ps'
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   320
              (Pretty.block [Pretty.str "Seq.single", Pretty.brk 1, mk_tuple out_ps])
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   321
              (Pretty.str "Seq.empty"))
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   322
          end
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   323
      | compile_prems out_ts vs names gr ps =
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   324
          let
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   325
            val vs' = distinct (flat (vs :: map term_vs out_ts));
12557
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   326
            val Some (p, mode as Some (Mode ((_, js), _))) =
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   327
              select_mode_prem thy modes' (arg_vs union vs') ps;
11537
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   328
            val ps' = filter_out (equal p) ps;
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   329
          in
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   330
            (case p of
12557
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   331
               Prem (us, t) =>
11537
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   332
                 let
12557
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   333
                   val (in_ts, out_ts') = get_args js 1 us;
12453
806502073957 - Changed type of invoke_codegen
berghofe
parents: 11539
diff changeset
   334
                   val (gr1, in_ps) = foldl_map
806502073957 - Changed type of invoke_codegen
berghofe
parents: 11539
diff changeset
   335
                     (invoke_codegen thy dep false) (gr, in_ts);
11537
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   336
                   val (nvs, out_ts'') = foldl_map distinct_v
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   337
                     ((names, map (fn x => (x, [x])) vs), out_ts);
12557
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   338
                   val (gr2, out_ps) = foldl_map
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   339
                     (invoke_codegen thy dep false) (gr1, out_ts'');
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   340
                   val (gr3, ps) = compile_expr thy dep false (gr2, (mode, t));
11537
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   341
                   val (gr4, rest) = compile_prems out_ts' vs' (fst nvs) gr3 ps';
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   342
                 in
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   343
                   (gr4, compile_match (snd nvs) [] out_ps
12557
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   344
                      (Pretty.block (ps @
11537
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   345
                         [Pretty.brk 1, mk_tuple in_ps,
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   346
                          Pretty.str " :->", Pretty.brk 1, rest]))
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   347
                      (Pretty.str "Seq.empty"))
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   348
                 end
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   349
             | Sidecond t =>
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   350
                 let
12453
806502073957 - Changed type of invoke_codegen
berghofe
parents: 11539
diff changeset
   351
                   val (gr1, side_p) = invoke_codegen thy dep true (gr, t);
11537
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   352
                   val (nvs, out_ts') = foldl_map distinct_v
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   353
                     ((names, map (fn x => (x, [x])) vs), out_ts);
12453
806502073957 - Changed type of invoke_codegen
berghofe
parents: 11539
diff changeset
   354
                   val (gr2, out_ps) = foldl_map
806502073957 - Changed type of invoke_codegen
berghofe
parents: 11539
diff changeset
   355
                     (invoke_codegen thy dep false) (gr1, out_ts')
11537
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   356
                   val (gr3, rest) = compile_prems [] vs' (fst nvs) gr2 ps';
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   357
                 in
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   358
                   (gr3, compile_match (snd nvs) [] out_ps
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   359
                      (Pretty.block [Pretty.str "?? ", side_p,
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   360
                        Pretty.str " :->", Pretty.brk 1, rest])
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   361
                      (Pretty.str "Seq.empty"))
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   362
                 end)
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   363
          end;
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   364
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   365
    val (gr', prem_p) = compile_prems in_ts' [] all_vs' gr ps;
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   366
  in
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   367
    (gr', Pretty.block [Pretty.str "Seq.single inp :->", Pretty.brk 1, prem_p])
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   368
  end;
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   369
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   370
fun compile_pred thy gr dep prfx all_vs arg_vs modes s cls mode =
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   371
  let val (gr', cl_ps) = foldl_map (fn (gr, cl) =>
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   372
    compile_clause thy gr dep all_vs arg_vs modes mode cl) (gr, cls)
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   373
  in
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   374
    ((gr', "and "), Pretty.block
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   375
      ([Pretty.block (separate (Pretty.brk 1)
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   376
         (Pretty.str (prfx ^ modename thy s mode) :: map Pretty.str arg_vs) @
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   377
         [Pretty.str " inp ="]),
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   378
        Pretty.brk 1] @
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   379
       flat (separate [Pretty.str " ++", Pretty.brk 1] (map single cl_ps))))
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   380
  end;
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   381
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   382
fun compile_preds thy gr dep all_vs arg_vs modes preds =
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   383
  let val ((gr', _), prs) = foldl_map (fn ((gr, prfx), (s, cls)) =>
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   384
    foldl_map (fn ((gr', prfx'), mode) =>
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   385
      compile_pred thy gr' dep prfx' all_vs arg_vs modes s cls mode)
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   386
        ((gr, prfx), the (assoc (modes, s)))) ((gr, "fun "), preds)
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   387
  in
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   388
    (gr', space_implode "\n\n" (map Pretty.string_of (flat prs)) ^ ";\n\n")
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   389
  end;
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   390
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   391
(**** processing of introduction rules ****)
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   392
12557
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   393
exception Modes of
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   394
  (string * (int list option list * int list) list) list *
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   395
  (string * (int list list option list * int list list)) list;
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   396
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   397
fun lookup_modes gr dep = apfst flat (apsnd flat (ListPair.unzip
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   398
  (map ((fn (Some (Modes x), _) => x | _ => ([], [])) o Graph.get_node gr)
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   399
    (Graph.all_preds gr [dep]))));
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   400
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   401
fun string_of_mode (iss, is) = space_implode " -> " (map
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   402
  (fn None => "X"
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   403
    | Some js => enclose "[" "]" (commas (map string_of_int js)))
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   404
       (iss @ [Some is]));
11537
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   405
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   406
fun print_modes modes = message ("Inferred modes:\n" ^
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   407
  space_implode "\n" (map (fn (s, ms) => s ^ ": " ^ commas (map
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   408
    string_of_mode ms)) modes));
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   409
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   410
fun print_factors factors = message ("Factors:\n" ^
12557
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   411
  space_implode "\n" (map (fn (s, (fs, f)) => s ^ ": " ^
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   412
    space_implode " -> " (map
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   413
      (fn None => "X" | Some f' => string_of_factors [] f')
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   414
        (fs @ [Some f]))) factors));
11537
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   415
12557
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   416
fun mk_extra_defs thy gr dep names ts =
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   417
  foldl (fn (gr, name) =>
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   418
    if name mem names then gr
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   419
    else (case get_clauses thy name of
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   420
        None => gr
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   421
      | Some (names, intrs) =>
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   422
          mk_ind_def thy gr dep names intrs))
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   423
            (gr, foldr add_term_consts (ts, []))
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   424
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   425
and mk_ind_def thy gr dep names intrs =
11537
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   426
  let val ids = map (mk_const_id (sign_of thy)) names
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   427
  in Graph.add_edge (hd ids, dep) gr handle Graph.UNDEF _ =>
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   428
    let
12557
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   429
      fun dest_prem factors (_ $ (Const ("op :", _) $ t $ u)) =
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   430
            (case head_of u of
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   431
               Const (name, _) => Prem (split_prod []
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   432
                 (the (assoc (factors, name))) t, u)
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   433
             | Var ((name, _), _) => Prem (split_prod []
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   434
                 (the (assoc (factors, name))) t, u))
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   435
        | dest_prem factors (_ $ ((eq as Const ("op =", _)) $ t $ u)) =
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   436
            Prem ([t, u], eq)
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   437
        | dest_prem factors (_ $ t) = Sidecond t;
11537
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   438
12557
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   439
      fun add_clause factors (clauses, intr) =
11537
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   440
        let
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   441
          val _ $ (_ $ t $ u) = Logic.strip_imp_concl intr;
12557
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   442
          val Const (name, _) = head_of u;
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   443
          val prems = map (dest_prem factors) (Logic.strip_imp_prems intr);
11537
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   444
        in
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   445
          (overwrite (clauses, (name, if_none (assoc (clauses, name)) [] @
12557
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   446
             [(split_prod [] (the (assoc (factors, name))) t, prems)])))
11537
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   447
        end;
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   448
12557
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   449
      fun add_prod_factors extra_fs (fs, _ $ (Const ("op :", _) $ t $ u)) =
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   450
            infer_factors (sign_of thy) extra_fs
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   451
              (fs, (Some (FVar (prod_factors [] t)), u))
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   452
        | add_prod_factors _ (fs, _) = fs;
11537
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   453
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   454
      val intrs' = map (rename_term o #prop o rep_thm o standard) intrs;
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   455
      val _ $ (_ $ _ $ u) = Logic.strip_imp_concl (hd intrs');
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   456
      val (_, args) = strip_comb u;
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   457
      val arg_vs = flat (map term_vs args);
12557
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   458
      val gr' = mk_extra_defs thy
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   459
        (Graph.add_edge (hd ids, dep)
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   460
          (Graph.new_node (hd ids, (None, "")) gr)) (hd ids) names intrs';
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   461
      val (extra_modes', extra_factors) = lookup_modes gr' (hd ids);
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   462
      val extra_modes =
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   463
        ("op =", [([], [1]), ([], [2]), ([], [1, 2])]) :: extra_modes';
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   464
      val fs = map (apsnd dest_factors)
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   465
        (foldl (add_prod_factors extra_factors) ([], flat (map (fn t =>
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   466
          Logic.strip_imp_concl t :: Logic.strip_imp_prems t) intrs')));
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   467
      val _ = (case map fst fs \\ names \\ arg_vs of
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   468
          [] => ()
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   469
        | xs => error ("Non-inductive sets: " ^ commas_quote xs));
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   470
      val factors = mapfilter (fn (name, f) =>
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   471
        if name mem arg_vs then None
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   472
        else Some (name, (map (curry assoc fs) arg_vs, f))) fs;
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   473
      val clauses =
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   474
        foldl (add_clause (fs @ map (apsnd snd) extra_factors)) ([], intrs');
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   475
      val modes = infer_modes thy extra_modes factors arg_vs clauses;
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   476
      val _ = print_factors factors;
11537
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   477
      val _ = print_modes modes;
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   478
      val (gr'', s) = compile_preds thy gr' (hd ids) (terms_vs intrs') arg_vs
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   479
        (modes @ extra_modes) clauses;
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   480
    in
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   481
      (Graph.map_node (hd ids) (K (Some (Modes (modes, factors)), s)) gr'')
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   482
    end      
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   483
  end;
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   484
12557
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   485
fun mk_ind_call thy gr dep t u is_query = (case head_of u of
13038
e968745986f1 - made modes_of more robust
berghofe
parents: 12565
diff changeset
   486
  Const (s, T) => (case (get_clauses thy s, get_assoc_code thy s T) of
e968745986f1 - made modes_of more robust
berghofe
parents: 12565
diff changeset
   487
       (None, _) => None
e968745986f1 - made modes_of more robust
berghofe
parents: 12565
diff changeset
   488
     | (Some (names, intrs), None) =>
11537
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   489
         let
12565
9df4b3934487 Eliminated "query" syntax.
berghofe
parents: 12562
diff changeset
   490
          fun mk_mode (((ts, mode), i), Const ("dummy_pattern", _)) =
9df4b3934487 Eliminated "query" syntax.
berghofe
parents: 12562
diff changeset
   491
                ((ts, mode), i+1)
11537
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   492
            | mk_mode (((ts, mode), i), t) = ((ts @ [t], mode @ [i]), i+1);
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   493
12557
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   494
           val gr1 = mk_extra_defs thy
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   495
             (mk_ind_def thy gr dep names intrs) dep names [u];
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   496
           val (modes, factors) = lookup_modes gr1 dep;
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   497
           val ts = split_prod [] (snd (the (assoc (factors, s)))) t;
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   498
           val (ts', is) = if is_query then
11537
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   499
               fst (foldl mk_mode ((([], []), 1), ts))
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   500
             else (ts, 1 upto length ts);
12557
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   501
           val mode = (case find_first (fn Mode ((_, js), _) => is=js)
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   502
                  (modes_of modes u) of
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   503
                None => error ("No such mode for " ^ s ^ ": " ^
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   504
                  string_of_mode ([], is))
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   505
              | mode => mode);
12453
806502073957 - Changed type of invoke_codegen
berghofe
parents: 11539
diff changeset
   506
           val (gr2, in_ps) = foldl_map
806502073957 - Changed type of invoke_codegen
berghofe
parents: 11539
diff changeset
   507
             (invoke_codegen thy dep false) (gr1, ts');
12557
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   508
           val (gr3, ps) = compile_expr thy dep false (gr2, (mode, u))
11537
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   509
         in
12557
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   510
           Some (gr3, Pretty.block
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   511
             (ps @ [Pretty.brk 1, mk_tuple in_ps]))
13038
e968745986f1 - made modes_of more robust
berghofe
parents: 12565
diff changeset
   512
         end
e968745986f1 - made modes_of more robust
berghofe
parents: 12565
diff changeset
   513
     | _ => None)
11537
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   514
  | _ => None);
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   515
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   516
fun inductive_codegen thy gr dep brack (Const ("op :", _) $ t $ u) =
12565
9df4b3934487 Eliminated "query" syntax.
berghofe
parents: 12562
diff changeset
   517
      ((case mk_ind_call thy gr dep (Term.no_dummy_patterns t) u false of
11537
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   518
         None => None
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   519
       | Some (gr', call_p) => Some (gr', (if brack then parens else I)
12453
806502073957 - Changed type of invoke_codegen
berghofe
parents: 11539
diff changeset
   520
           (Pretty.block [Pretty.str "?! (", call_p, Pretty.str ")"])))
12565
9df4b3934487 Eliminated "query" syntax.
berghofe
parents: 12562
diff changeset
   521
        handle TERM _ => mk_ind_call thy gr dep t u true)
11537
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   522
  | inductive_codegen thy gr dep brack _ = None;
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   523
12557
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   524
val setup =
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   525
  [add_codegen "inductive" inductive_codegen,
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   526
   CodegenData.init,
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   527
   add_attribute "ind" add];
11537
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   528
e007d35359c3 New code generators for HOL.
berghofe
parents:
diff changeset
   529
end;
12453
806502073957 - Changed type of invoke_codegen
berghofe
parents: 11539
diff changeset
   530
806502073957 - Changed type of invoke_codegen
berghofe
parents: 11539
diff changeset
   531
806502073957 - Changed type of invoke_codegen
berghofe
parents: 11539
diff changeset
   532
(**** combinators for code generated from inductive predicates ****)
806502073957 - Changed type of invoke_codegen
berghofe
parents: 11539
diff changeset
   533
806502073957 - Changed type of invoke_codegen
berghofe
parents: 11539
diff changeset
   534
infix 5 :->;
806502073957 - Changed type of invoke_codegen
berghofe
parents: 11539
diff changeset
   535
infix 3 ++;
806502073957 - Changed type of invoke_codegen
berghofe
parents: 11539
diff changeset
   536
806502073957 - Changed type of invoke_codegen
berghofe
parents: 11539
diff changeset
   537
fun s :-> f = Seq.flat (Seq.map f s);
806502073957 - Changed type of invoke_codegen
berghofe
parents: 11539
diff changeset
   538
806502073957 - Changed type of invoke_codegen
berghofe
parents: 11539
diff changeset
   539
fun s1 ++ s2 = Seq.append (s1, s2);
806502073957 - Changed type of invoke_codegen
berghofe
parents: 11539
diff changeset
   540
806502073957 - Changed type of invoke_codegen
berghofe
parents: 11539
diff changeset
   541
fun ?? b = if b then Seq.single () else Seq.empty;
806502073957 - Changed type of invoke_codegen
berghofe
parents: 11539
diff changeset
   542
806502073957 - Changed type of invoke_codegen
berghofe
parents: 11539
diff changeset
   543
fun ?! s = is_some (Seq.pull s);    
806502073957 - Changed type of invoke_codegen
berghofe
parents: 11539
diff changeset
   544
12557
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   545
fun op__61__1 x = Seq.single x;
12453
806502073957 - Changed type of invoke_codegen
berghofe
parents: 11539
diff changeset
   546
12557
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   547
val op__61__2 = op__61__1;
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   548
bb2e4689347e Implemented higher order modes.
berghofe
parents: 12453
diff changeset
   549
fun op__61__1_2 (x, y) = ?? (x = y);