1 (* Copyright (C) 1999-2007 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 FlatLattice (S: FLAT_LATTICE_STRUCTS): FLAT_LATTICE =
25 fn Bottom => str "Bottom"
26 | Point p => Point.layout p
30 datatype z = datatype Elt.t
32 datatype t = T of {lessThan: t list ref,
33 upperBound: Point.t option ref,
36 fun layout (T {value, ...}) = Elt.layout (!value)
38 fun new () = T {lessThan = ref [],
39 upperBound = ref NONE,
43 fn (T {value = ref Bottom, ...}) => true
46 fn (T {value = ref (Point _), ...}) => true
49 fn (T {value = ref (Point p), ...}, p') => Point.equals (p, p')
52 fn (T {value = ref (Point p), ...}) => SOME p
55 fn (T {value = ref Top, ...}) => true
58 fun forceTop (T {upperBound, value, ...}): bool =
59 if isSome (!upperBound)
61 else (value := Top; true)
63 fun up (T {lessThan, upperBound, value, ...}, e: Elt.t): bool =
65 fun continue e = List.forall (!lessThan, fn z => up (z, e))
67 not (isSome (!upperBound))
74 | (_, Top) => setTop ()
75 | (Bottom, Point p) =>
77 ; (case !upperBound of
78 NONE => continue (Point p)
80 Point.equals (p, p') andalso continue (Point p)))
81 | (Point p, Point p') => Point.equals (p, p') orelse setTop ()
84 val op <= : t * t -> bool =
85 fn (T {lessThan, value, ...}, e) =>
86 (List.push (lessThan, e)
90 Trace.trace2 ("FlatLattice.<=", layout, layout, Bool.layout)
93 fun lowerBound (e, p): bool = up (e, Point p)
96 Trace.trace2 ("FlatLattice.lowerBound", layout, Point.layout, Bool.layout)
99 fun upperBound (T {upperBound = r, value, ...}, p): bool =
104 | Point p' => Point.equals (p, p')
106 | SOME p' => Point.equals (p, p')
109 Trace.trace2 ("FlatLattice.upperBound", layout, Point.layout, Bool.layout)
112 fun forcePoint (e, p) =
113 lowerBound (e, p) andalso upperBound (e, p)
116 Trace.trace2 ("FlatLattice.forcePoint", layout, Point.layout, Bool.layout)
122 val _ = forcePoint (e, p)
127 val point = Trace.trace ("FlatLattice.point", Point.layout, layout) point