src/Pure/Tools/iml_package.ML
author haftmann
Sun, 28 Aug 2005 10:05:03 +0200
changeset 17156 e50f95ccde99
permissions -rw-r--r--
(allocating new branch)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
17156
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
     1
signature IML_PACKAGE =
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
     2
sig
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
     3
end;
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
     4
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
     5
structure ImlPackage : IML_PACKAGE =
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
     6
struct
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
     7
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
     8
type nsidf = string
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
     9
type idf = string
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
    10
type qidf = nsidf * idf
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
    11
type iclass = qidf
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
    12
type isort = iclass list
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
    13
type ityco = qidf
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
    14
type iconst = qidf
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
    15
type 'a vidf = string * 'a
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
    16
type tvname = isort vidf
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
    17
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
    18
fun qidf_ord ((a, c), (b, d)) =
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
    19
  (case string_ord (a, b) of EQUAL => string_ord (c, d) | ord => ord);
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
    20
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
    21
structure Idfgraph = GraphFun(type key = qidf val ord = qidf_ord);
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
    22
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
    23
datatype ityp =
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
    24
  IType of ityco * ityp list
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
    25
  | IFree of tvname * isort
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
    26
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
    27
type vname = ityp vidf
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
    28
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
    29
datatype iexpr =
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
    30
  IConst of iconst * ityp
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
    31
  | IVar of vname * ityp
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
    32
  | IAbs of vname * iexpr
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
    33
  | IApp of iexpr * iexpr
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
    34
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
    35
datatype pat =
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
    36
  PConst of iconst
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
    37
  | PVar of vname
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
    38
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
    39
type 'a defn = 'a * (pat list * iexpr) list
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
    40
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
    41
datatype stmt =
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
    42
  Def of ityp defn
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
    43
  | Typdecl of vname list * ityp
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
    44
  | Datadef of (iconst * vname list) list
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
    45
  | Classdecl of string list * (string * ityp) list
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
    46
  | Instdef of iclass * ityco * isort list * (string defn) list
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
    47
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
    48
type module = stmt Idfgraph.T
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
    49
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
    50
type universe = module Graph.T
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
    51
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
    52
fun isort_of_sort nsp sort =
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
    53
  map (pair nsp) sort
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
    54
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
    55
(* fun ityp_of_typ nsp ty =
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
    56
 *   let
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
    57
 *     fun ityp_of_typ' (Type (tycon, tys)) = IType ((nsp, tycon), map ityp_of_typ' tys)
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
    58
 *       | ityp_of_typ' (TFree (varname, sort)) = IFree ((nsp, varname), isort_of_sort nsp sort)
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
    59
 *   in (ityp_of_typ' o unvarifyT) ty end;
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
    60
 *)
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
    61
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
    62
(* fun iexpr_of_term nsp t =
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
    63
 *   let
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
    64
 *     fun iexpr_of_term' (Const (const, ty)) = IConst ((nsp, const), ityp_of_typ nsp ty)
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
    65
 *       | iexpr_of_term' (Free (varname, ty)) = IVar ((nsp, varname), ityp_of_typ nsp ty)
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
    66
 *       | iexpr_of_term' (Free (varname, ty)) = IVar ((nsp, varname), ityp_of_typ nsp ty)
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
    67
 *   in (iexpr_of_term' o map_term_types (unvarifyT)) t
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
    68
 * 
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
    69
 *   datatype term =
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
    70
 *     Const of string * typ |
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
    71
 *     Free of string * typ |
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
    72
 *     Var of indexname * typ |
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
    73
 *     Bound of int |
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
    74
 *     Abs of string * typ * term |
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
    75
 *     op $ of term * term
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
    76
 * 
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
    77
 * 
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
    78
 * fun iexpr_of
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
    79
 *)
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
    80
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
    81
val empty_universe = Graph.empty
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
    82
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
    83
val empty_module = Idfgraph.empty
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
    84
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
    85
datatype deps =
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
    86
  Check
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
    87
  | Nocheck
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
    88
  | Dep of qidf list
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
    89
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
    90
fun add_stmt modname idf deps stmt univ =
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
    91
  let
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
    92
    fun check_deps Nocheck = I
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
    93
      | check_deps (Dep idfs) = Graph.add_deps_acyclic (modname, map #2 idfs)
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
    94
      | check_deps _ = error "'Nocheck' not implemented yet"
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
    95
  in
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
    96
    univ
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
    97
    |> Graph.default_node modname empty_module
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
    98
    |> Graph.map_node modname (Idfgraph.new_node (idf, stmt))
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
    99
    |> fold check_deps deps
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
   100
  end
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
   101
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
   102
(* WICHTIG: resolve_qidf, resolve_midf  *)
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
   103
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
   104
(* IDEAS: Transaktionspuffer, Errormessage-Stack *)
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
   105
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
   106
end;
e50f95ccde99 (allocating new branch)
haftmann
parents:
diff changeset
   107