summaryrefslogtreecommitdiff
path: root/ghc/lib/std/PrelAddr.lhs
blob: 8a0ba321478739d72f257c522fdf5e093ca7e926 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
%
% (c) The AQUA Project, Glasgow University, 1994-1998
%

\section[PrelAddr]{Module @PrelAddr@}

\begin{code}
{-# OPTIONS -fcompiling-prelude -fno-implicit-prelude #-}

module PrelAddr (
	  Addr(..)
	, nullAddr			-- :: Addr
	, plusAddr			-- :: Addr -> Int -> Addr
	, indexAddrOffAddr	        -- :: Addr -> Int -> Addr

	, Word(..)
	, wordToInt
	, intToWord

	, Word64(..)
	, Int64(..)
   ) where

import PrelGHC
import PrelBase

infixl 5 `plusAddr`
\end{code}

\begin{code}
data Addr = A# Addr# 	deriving (Eq, Ord)
data Word = W# Word# 	deriving (Eq, Ord)

nullAddr :: Addr
nullAddr = A# (int2Addr# 0#)

plusAddr :: Addr -> Int -> Addr
plusAddr (A# addr) (I# off) = A# (int2Addr# (addr2Int# addr +# off))

instance CCallable Addr
instance CReturnable Addr

instance CCallable Word
instance CReturnable Word

wordToInt :: Word -> Int
wordToInt (W# w#) = I# (word2Int# w#)

intToWord :: Int -> Word
intToWord (I# i#) = W# (int2Word# i#)

#if WORD_SIZE_IN_BYTES == 8
data Word64 = W64# Word#
data Int64  = I64# Int#
#else
data Word64 = W64# Word64# --deriving (Eq, Ord) -- Glasgow extension
data Int64  = I64# Int64#  --deriving (Eq, Ord) -- Glasgow extension
#endif

instance CCallable   Word64
instance CReturnable Word64

instance CCallable   Int64
instance CReturnable Int64

indexAddrOffAddr   :: Addr -> Int -> Addr
indexAddrOffAddr (A# addr#) n
  = case n  	    	    	    	of { I# n# ->
    case indexAddrOffAddr# addr# n# 	of { r# ->
    (A# r#)}}

\end{code}