var.ml 1.57 KB
Newer Older
Pietro Abate's avatar
Pietro Abate committed
1

2
module V = struct
3
4
5
6
7
  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
8
  let dump ppf t = Format.fprintf ppf "{%a(%d)}" Ident.U.print t.id t.fr
9
  let compare x y = Pervasives.compare (x.kind,x.id,x.fr) (y.kind,y.id,y.fr)
10
  let equal x y = (compare x y) = 0
11
  let hash x = Hashtbl.hash (x.id,x.fr,x.kind)
12
  let check _ = ()
13

14
15
  let freshcounter = ref 0

16
  let is_fresh x = x.fr > 0
17

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

20
21
22
23
  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
24
  let pp ppf x = Format.fprintf ppf "'%a" Ident.U.print x.id
25
26
27
28
end

include V
type var = t
29

Pietro Abate's avatar
Pietro Abate committed
30
module Set = struct
31
32
33
  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)
34
  let printf = pp Format.std_formatter
35
36
37
38
  let union = cup
  let inter = cap
  let cardinal = length
  let mem t v = mem v t
39
  let fold = fold
Pietro Abate's avatar
Pietro Abate committed
40
end
41

42
type 'a pairvar = [ `Atm of 'a | `Var of t ]
43

44
45
module Make (X : Custom.T) = struct
  type t = X.t pairvar
46
  let hash = function `Atm t -> X.hash t | `Var x -> V.hash x
47

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

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

  let equal t1 t2 = (compare t1 t2) = 0
58

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