1 (* Copyright (C) 1999-2006 Henry Cejtin, Matthew Fluet, Suresh
2 * Jagannathan, and Stephen Weeks.
3 * Copyright (C) 1997-2000 NEC Research Institute.
5 * MLton is released under a BSD-style license.
6 * See the file MLton-LICENSE for details.
9 functor TwoPointLattice (S: TWO_POINT_LATTICE_STRUCTS): TWO_POINT_LATTICE =
14 structure Set = DisjointSet
15 structure List = AppendList
17 datatype t = T of value Set.t
19 Bottom of (unit -> unit) List.t ref (* If I become Top, then run these. *)
22 fun value (T s) = Set.! s
29 val layout = Layout.str o toString
31 fun new (): t = T (Set.singleton (Bottom (ref List.empty)))
33 fun equals (T s, T s') = Set.equals (s, s')
35 fun addHandler (e, h) =
37 Bottom hs => hs := List.cons (h, !hs)
50 fun runHandlers hs = List.foreach (!hs, fn h => h ())
55 | Bottom hs => (Set.:= (s, Top); runHandlers hs)
61 case (value from, value to) of
63 | (Top, _) => makeTop to
64 | (Bottom hs, _) => hs := List.cons (fn () => makeTop to, !hs)
72 val _ = Set.union (s, s')
76 | (Bottom hs, Top) => (Set.:= (s, e'); runHandlers hs)
77 | (Top, Bottom hs) => (Set.:= (s, e); runHandlers hs)
78 | (Bottom hs, Bottom hs') =>
79 Set.:= (s, Bottom (ref (List.append (!hs, !hs'))))