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