remove empty dir
[ghc-hetmet.git] / compiler / utils / FastMutInt.lhs
1 {-# OPTIONS -cpp #-}
2 --
3 -- (c) The University of Glasgow 2002
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 #if __GLASGOW_HASKELL__ < 503
21 import GlaExts
22 import PrelIOBase
23 #else
24 import GHC.Base
25 import GHC.IOBase
26 #endif
27
28 #if __GLASGOW_HASKELL__ < 411
29 newByteArray# = newCharArray#
30 #endif
31 \end{code}
32
33 \begin{code}
34 #ifdef __GLASGOW_HASKELL__
35 data FastMutInt = FastMutInt (MutableByteArray# RealWorld)
36
37 newFastMutInt :: IO FastMutInt
38 newFastMutInt = IO $ \s ->
39   case newByteArray# size s of { (# s, arr #) ->
40   (# s, FastMutInt arr #) }
41   where I# size = SIZEOF_HSINT
42
43 readFastMutInt :: FastMutInt -> IO Int
44 readFastMutInt (FastMutInt arr) = IO $ \s ->
45   case readIntArray# arr 0# s of { (# s, i #) ->
46   (# s, I# i #) }
47
48 writeFastMutInt :: FastMutInt -> Int -> IO ()
49 writeFastMutInt (FastMutInt arr) (I# i) = IO $ \s ->
50   case writeIntArray# arr 0# i s of { s ->
51   (# s, () #) }
52 \end{code}
53 #endif
54