1 (* Copyright (C
) 1999-2006 Henry Cejtin
, Matthew Fluet
, Suresh
2 * Jagannathan
, and Stephen Weeks
.
4 * MLton is released under a BSD
-style license
.
5 * See the file MLton
-LICENSE for details
.
8 structure Pointer
: POINTER
=
11 datatype 'a t
= T
of 'a option ref
15 NONE
=> Error
.bug
"Pointer.!"
18 fun (T r
) := v
= Ref
.:=(r
, SOME v
)
20 fun clear(T r
) = Ref
.:=(r
, NONE
)
22 fun copy(T r
, T r
') = Ref
.:=(r
, Ref
.! r
')
24 fun eq(T r
, T r
') = Ref
.equals(r
, r
')
26 fun follow(T r
) = Ref
.! r
28 fun equals(p
, p
', equals
) =
29 case (follow p
, follow p
') of
31 |
(SOME v
, SOME v
') => equals(v
, v
')
34 fun isNull p
= Option
.isNone(follow p
)
38 fun new v
= make(SOME v
)
40 fun null() = make NONE
42 fun swap(T p
, T p
') = Ref
.swap(p
, p
')