FastMutInt - make #endif be inside \{code} to match #ifdef
[ghc-hetmet.git] / compiler / utils / FastMutInt.lhs
1 {-# OPTIONS -cpp #-}
2 --
3 -- (c) The University of Glasgow 2002-2006
4 --
5 -- Unboxed mutable Ints
6
7 \begin{code}
8 module FastMutInt(
9         FastMutInt, newFastMutInt,
10         readFastMutInt, writeFastMutInt
11   ) where
12
13 #include "MachDeps.h"
14
15 #ifndef SIZEOF_HSINT
16 #define SIZEOF_HSINT  INT_SIZE_IN_BYTES
17 #endif
18
19
20 import GHC.Base
21 import GHC.IOBase
22 \end{code}
23
24 \begin{code}
25 #ifdef __GLASGOW_HASKELL__
26 data FastMutInt = FastMutInt (MutableByteArray# RealWorld)
27
28 newFastMutInt :: IO FastMutInt
29 newFastMutInt = IO $ \s ->
30   case newByteArray# size s of { (# s, arr #) ->
31   (# s, FastMutInt arr #) }
32   where I# size = SIZEOF_HSINT
33
34 readFastMutInt :: FastMutInt -> IO Int
35 readFastMutInt (FastMutInt arr) = IO $ \s ->
36   case readIntArray# arr 0# s of { (# s, i #) ->
37   (# s, I# i #) }
38
39 writeFastMutInt :: FastMutInt -> Int -> IO ()
40 writeFastMutInt (FastMutInt arr) (I# i) = IO $ \s ->
41   case writeIntArray# arr 0# i s of { s ->
42   (# s, () #) }
43 #endif
44 \end{code}
45