[project @ 2002-02-12 11:44:54 by simonmar]
[ghc-hetmet.git] / ghc / lib / std / PrelPtr.lhs
1 -----------------------------------------------------------------------------
2 -- $Id: PrelPtr.lhs,v 1.4 2001/10/17 11:26:04 simonpj Exp $
3 -- 
4 -- (c) 2000
5 -- 
6 -- Module PrelPtr
7
8 \begin{code}
9 {-# OPTIONS -fno-implicit-prelude #-}
10 module PrelPtr{-everything-} where
11         
12 import PrelBase
13
14 ------------------------------------------------------------------------
15 -- Data pointers.
16
17 data Ptr a = Ptr Addr# deriving (Eq, Ord)
18
19 nullPtr :: Ptr a
20 nullPtr = Ptr nullAddr#
21
22 castPtr :: Ptr a -> Ptr b
23 castPtr (Ptr addr) = Ptr addr
24
25 plusPtr :: Ptr a -> Int -> Ptr b
26 plusPtr (Ptr addr) (I# d) = Ptr (plusAddr# addr d)
27
28 alignPtr :: Ptr a -> Int -> Ptr a
29 alignPtr addr@(Ptr a) (I# i)
30   = case remAddr# a i of {
31       0# -> addr;
32       n -> Ptr (plusAddr# a (i -# n)) }
33
34 minusPtr :: Ptr a -> Ptr b -> Int
35 minusPtr (Ptr a1) (Ptr a2) = I# (minusAddr# a1 a2)
36
37 instance CCallable   (Ptr a)
38 instance CReturnable (Ptr a)
39
40 ------------------------------------------------------------------------
41 -- Function pointers for the default calling convention.
42
43 data FunPtr a = FunPtr Addr# deriving (Eq, Ord)
44
45 nullFunPtr :: FunPtr a
46 nullFunPtr = FunPtr nullAddr#
47
48 castFunPtr :: FunPtr a -> FunPtr b
49 castFunPtr (FunPtr addr) = FunPtr addr
50
51 castFunPtrToPtr :: FunPtr a -> Ptr b
52 castFunPtrToPtr (FunPtr addr) = Ptr addr
53
54 castPtrToFunPtr :: Ptr a -> FunPtr b
55 castPtrToFunPtr (Ptr addr) = FunPtr addr
56
57 instance CCallable   (FunPtr a)
58 instance CReturnable (FunPtr a)
59 \end{code}
60