[project @ 1999-12-20 10:34:27 by simonpj]
[ghc-hetmet.git] / ghc / lib / std / PrelStable.lhs
1 % -----------------------------------------------------------------------------
2 % $Id: PrelStable.lhs,v 1.3 1999/12/20 10:34:35 simonpj Exp $
3 %
4 % (c) The GHC Team, 1992-1999
5 %
6
7 \begin{code}
8 {-# OPTIONS -fno-implicit-prelude #-}
9
10 module PrelStable 
11         ( StablePtr(..)
12         , makeStablePtr   -- :: a -> IO (StablePtr a)    
13         , deRefStablePtr  -- :: StablePtr a -> a
14         , freeStablePtr   -- :: StablePtr a -> IO ()
15    ) where
16
17 import PrelBase
18 import PrelIOBase
19
20 -----------------------------------------------------------------------------
21 -- Stable Pointers
22
23 data StablePtr  a = StablePtr  (StablePtr#  a)
24
25 instance CCallable   (StablePtr a)
26 instance CReturnable (StablePtr a)
27
28 makeStablePtr  :: a -> IO (StablePtr a)
29 deRefStablePtr :: StablePtr a -> IO a
30 foreign import "freeStablePtr" freeStablePtr :: StablePtr a -> IO ()
31
32 makeStablePtr a = IO $ \ s ->
33     case makeStablePtr# a s of (# s', sp #) -> (# s', StablePtr sp #)
34
35 deRefStablePtr (StablePtr sp) = IO $ \s -> deRefStablePtr# sp s
36
37
38 instance Eq (StablePtr a) where 
39     (StablePtr sp1) == (StablePtr sp2) =
40         case eqStablePtr# sp1 sp2 of
41            0# -> False
42            _  -> True
43 \end{code}