var.ml 1.6 KB
Newer Older
1
module V = struct
2
3
4
5
6
  type t = { id : Ident.U.t ; fr : int ; kind : int }
  type kind = int
  let function_kind = 1
  let argument_kind = 2

Pietro Abate's avatar
Pietro Abate committed
7
  let dump ppf t = Format.fprintf ppf "{%a(%d)}" Ident.U.print t.id t.fr
8
  let compare x y = Pervasives.compare (x.kind,x.id,x.fr) (y.kind,y.id,y.fr)
9
  let equal x y = (compare x y) = 0
10
  let hash x = Hashtbl.hash (x.id,x.fr,x.kind)
11
  let check _ = ()
12

13
14
  let freshcounter = ref 0

15
  let is_fresh x = x.fr > 0
16

17
  let fresh v = { v with fr = (incr freshcounter;!freshcounter) }
18

19
20
21
22
  let mk id = { id = Ident.U.mk id; fr = 0; kind = 0; }

  let id x = Ident.U.get_str x.id
  let set_kind k v = { v with kind = k }
Pietro Abate's avatar
Pietro Abate committed
23
  let pp ppf x = Format.fprintf ppf "'%a" Ident.U.print x.id
24
25
26
27
end

include V
type var = t
28

Pietro Abate's avatar
Pietro Abate committed
29
module Set = struct
30
31
32
  include SortedList.Make(V)
  let dump ppf s = Utils.pp_list ~sep:";" ~delim:("{","}") V.dump ppf (get s)
  let pp ppf s = Utils.pp_list ~sep:";" ~delim:("{","}") V.pp ppf (get s)
33
  let printf = pp Format.std_formatter
34
35
36
37
  let union = cup
  let inter = cap
  let cardinal = length
  let mem t v = mem v t
38
  let fold = fold
Pietro Abate's avatar
Pietro Abate committed
39
end
40

41
type 'a var_or_atom = [ `Atm of 'a | `Var of t ]
42

43
module Make (X : Custom.T) = struct
44
45
  type t = X.t var_or_atom
  let hash = function `Atm t -> 17 + 17 * X.hash t | `Var x -> 997 + 17 * V.hash x
46

47
  let check = function `Atm t -> X.check t | `Var _ -> ()
48

49
50
  let compare t1 t2 =
    match t1,t2 with
51
    |`Var x, `Var y -> compare x y
52
53
54
55
    |`Atm x, `Atm y -> X.compare x y
    |`Var _, `Atm _ -> -1
    |`Atm _, `Var _ -> 1

56
  let equal t1 t2 = (compare t1 t2) == 0
57

58
59
  let dump ppf = function
    |`Atm x -> X.dump ppf x
60
    |`Var x -> V.dump ppf x
61
end