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 NPointLattice (S: N_POINT_LATTICE_STRUCTS): N_POINT_LATTICE =
14 val N = List.length names - 1
16 structure Set = DisjointSet
18 type value = int * (unit -> unit) AppendList.t ref List.t
19 datatype t = T of value Set.t
21 fun value (T s) = Set.! s
25 (n, _) => List.nth (names, n)
27 val layout = Layout.str o toString
30 T (Set.singleton (0, List.duplicate (N, fn () => ref AppendList.empty)))
32 fun equals (T s, T s') = Set.equals (s, s')
34 fun whenN (s, n', h') =
36 (n, hss) => if n' < 0 orelse n' > N
37 then Error.bug "NPointLattice.whenN"
41 val hs = List.nth (hss, n' - n - 1)
43 hs := AppendList.cons (h', !hs)
48 (n, _) => if n' < 0 orelse n' > N
49 then Error.bug "NPointLattice.isN"
56 else (Set.:= (s, (n + 1, tl hss)) ;
57 AppendList.foreach (!(hd hss), fn h => h ()))
61 (n, _) => if n' < 0 orelse n' > N
62 then Error.bug "NPointLattice.makeN"
65 else (up s ; makeN (s, n'))
71 case (value from, value to) of
77 then hs := AppendList.cons (fn () => makeN (to, n + i + 1), !hs)
87 val _ = Set.union (s, s')
90 ((n,hss), (n',hss')) =>
92 val n'' = Int.max (n, n')
97 = fn (hss, 0: Int.t) => hss
100 (!hs, fn h => h ()) ;
102 | ([], _) => Error.bug "NPointLattice.=="
106 val hss = doit (n, hss)
107 val hss' = doit (n', hss')
110 (hss, hss', fn (hs, hs') =>
111 ref (AppendList.append (!hs, !hs')))
113 Set.:= (s, (n'', hss''))