Module header tidyup #2
[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
23 #if __GLASGOW_HASKELL__ < 411
24 newByteArray# = newCharArray#
25 #endif
26 \end{code}
27
28 \begin{code}
29 #ifdef __GLASGOW_HASKELL__
30 data FastMutInt = FastMutInt (MutableByteArray# RealWorld)
31
32 newFastMutInt :: IO FastMutInt
33 newFastMutInt = IO $ \s ->
34   case newByteArray# size s of { (# s, arr #) ->
35   (# s, FastMutInt arr #) }
36   where I# size = SIZEOF_HSINT
37
38 readFastMutInt :: FastMutInt -> IO Int
39 readFastMutInt (FastMutInt arr) = IO $ \s ->
40   case readIntArray# arr 0# s of { (# s, i #) ->
41   (# s, I# i #) }
42
43 writeFastMutInt :: FastMutInt -> Int -> IO ()
44 writeFastMutInt (FastMutInt arr) (I# i) = IO $ \s ->
45   case writeIntArray# arr 0# i s of { s ->
46   (# s, () #) }
47 \end{code}
48 #endif
49