Commit 0a8cd35e authored by Pietro Abate's avatar Pietro Abate

Add delta to Types.Tallying.{norm,merge}

- delta is not yet used to do anything meaningful
- remove optional argument ?fresh from Var.mk (legacy not used)
- print -> pp,printf refactoring
parent 727e0b21
......@@ -222,7 +222,7 @@ let test_norm =
(Printf.sprintf " %s \\ %s" s t) >:: (fun _ ->
let s = parse_typ s in
let t = parse_typ t in
let result = Tallying.norm (diff s t) in
let result = Tallying.norm Var.Set.empty (diff s t) in
let elem s = MSet.of_list (Tallying.CS.S.elements s) in
MSet.assert_equal (elem expected) (elem result)
)
......@@ -264,7 +264,7 @@ let test_merge =
let result =
try
Tallying.CS.S.fold (fun c acc ->
Tallying.CS.union (Tallying.merge c) acc
Tallying.CS.union (Tallying.merge Var.Set.empty c) acc
) s Tallying.CS.S.empty
with Tallying.UnSatConstr _ -> Tallying.CS.unsat
in
......
This diff is collapsed.
......@@ -419,8 +419,8 @@ module Tallying : sig
val prod : s -> s -> s
end
val norm : t -> CS.s
val merge : CS.m -> CS.s
val norm : Var.Set.t -> t -> CS.s
val merge : Var.Set.t -> CS.m -> CS.s
val solve : CS.s -> CS.es
val unify : CS.sigma -> CS.sigma
......
module V = struct
type t = { fresh : bool; id : string; repr : string }
type t = { id : string; repr : string }
let dump ppf t =
let r = if t.repr = t.id then "" else Format.sprintf ";repr=%s" t.repr in
Format.fprintf ppf "{id=%s;fresh=%b%s}" t.id t.fresh r
Format.fprintf ppf "{id=%s;%s}" t.id r
let compare x y = Pervasives.compare x.id y.id
let equal x y = Pervasives.compare x.id y.id = 0
let hash x = Hashtbl.hash x.id
let check _ = ()
let make_id ?(fresh=false) ?repr id =
let make_id ?repr id =
match repr with
|None -> { id = id ; fresh = fresh ; repr = id }
|Some r -> { id = id ; fresh = fresh ; repr = r }
|None -> { id = id ; repr = id }
|Some r -> { id = id ; repr = r }
end
type var = [ `Var of V.t ]
type t = var
let id (`Var x) = x.V.id
let dump ppf (`Var x) = Format.fprintf ppf "%a" V.dump x
let pp ppf (`Var x) = Format.fprintf ppf "'%s" x.V.repr
let compare (`Var x) (`Var y) = V.compare x y
......@@ -24,31 +26,21 @@ let equal v1 v2 = (compare v1 v2) = 0
let hash (`Var x) = V.hash x
let check _ = ()
let mk ?fresh ?repr id = `Var (V.make_id ?fresh ?repr id)
let mk ?repr id = `Var (V.make_id ?repr id)
let fresh : ?pre: string -> unit -> [> var ] =
let counter = ref 0 in
fun ?(pre="_fresh_") -> fun _ ->
let id = (Printf.sprintf "%s%d" pre !counter) in
let v = mk ~fresh:true id in
let v = mk id in
incr counter;
v
;;
let id (`Var x) = x.V.id
let is_fresh (`Var x) = x.V.fresh
module Set = struct
include Set.Make(struct type t = var let compare = compare end)
let aux_print sep printer ppf s =
let rec aux ppf = function
|[] -> ()
|[h] -> printer ppf h
|h::l -> Format.fprintf ppf "%a %s %a" printer h sep aux l
in
aux ppf (elements s)
let dump ppf s = aux_print ";" dump ppf s
let pp ppf s = aux_print ";" pp ppf s
let dump ppf s = Utils.pp_list ~sep:";" ~delim:("{","}") dump ppf (elements s)
let pp ppf s = Utils.pp_list ~sep:";" ~delim:("{","}") pp ppf (elements s)
let printf = pp Format.std_formatter
let is_empty s = equal s empty
let from_list l = List.fold_left (fun acc x -> add x acc) empty l
end
......
module V : sig
include Custom.T
val make_id : ?fresh:bool -> ?repr:string -> string -> t
val make_id : ?repr:string -> string -> t
end
type var = [ `Var of V.t ]
......@@ -8,15 +8,15 @@ type var = [ `Var of V.t ]
include Custom.T with type t = var
val pp : Format.formatter -> var -> unit
val mk : ?fresh:bool -> ?repr:string -> string -> var
val mk : ?repr:string -> string -> var
val fresh : ?pre:string -> unit -> var
val id : var -> string
val is_fresh : var -> bool
module Set : sig
include Set.S with type elt = var
val dump : Format.formatter -> t -> unit
val pp : Format.formatter -> t -> unit
val printf : t -> unit
val is_empty : t -> bool
val from_list : elt list -> t
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment