on master help sign in
Allow us to build Array Int
cc59efeBryan O'Sullivan
Data/Text/Array.hs+38−2
@@ -51,8 +51,9 @@ if (_k_) < 0 || (_k_) >= (_len_) then error ("Data.Text.Array." ++ (_func_) ++ "
51#if defined(__GLASGOW_HASKELL__)
51#if defined(__GLASGOW_HASKELL__)
52#include "MachDeps.h"
52#include "MachDeps.h"
53
53
54−import GHC.Base (ByteArray#, MutableByteArray#, Int(..), indexWord16Array#,
54+import GHC.Base (ByteArray#, MutableByteArray#, Int(..), indexIntArray#,
55+ indexWord16Array#, newByteArray#, readIntArray#,
55− newByteArray#, readWord16Array#, unsafeCoerce#,
56+ readWord16Array#, unsafeCoerce#, writeIntArray#,
56 writeWord16Array#, (+#), (*#))
57 writeWord16Array#, (+#), (*#))
57import GHC.Prim (Int#)
58import GHC.Prim (Int#)
58import GHC.ST (ST(..), runST)
59import GHC.ST (ST(..), runST)
@@ -160,6 +161,9 @@ unsafeFreeze :: MArray s e -> ST s (Array e)
160
161
161#if defined(__GLASGOW_HASKELL__)
162#if defined(__GLASGOW_HASKELL__)
162
163
164+iNT_SCALE :: Int# -> Int#
165+iNT_SCALE n# = scale# *# n# where I# scale# = SIZEOF_INT
166+
163wORD16_SCALE :: Int# -> Int#
167wORD16_SCALE :: Int# -> Int#
164wORD16_SCALE n# = scale# *# n# where I# scale# = SIZEOF_WORD16
168wORD16_SCALE n# = scale# *# n# where I# scale# = SIZEOF_WORD16
165
169
@@ -219,6 +223,38 @@ new len initVal = do
219 sequence_ [unsafeWrite marr i initVal | i <- [0..len-1]]
223 sequence_ [unsafeWrite marr i initVal | i <- [0..len-1]]
220 return marr
224 return marr
221
225
226+instance Elt Int where
227+#if defined(__GLASGOW_HASKELL__)
228+
229+ bytesInArray (I# i#) _ = I# (iNT_SCALE i#)
230+ {-# INLINE bytesInArray #-}
231+
232+ unsafeIndex (Array len ba#) i@(I# i#) =
233+ CHECK_BOUNDS("unsafeIndex",len,i)
234+ case indexIntArray# ba# i# of r# -> (I# r#)
235+ {-# INLINE unsafeIndex #-}
236+
237+ unsafeRead (MArray len mba#) i@(I# i#) = ST $ \s# ->
238+ CHECK_BOUNDS("unsafeRead",len,i)
239+ case readIntArray# mba# i# s# of
240+ (# s2#, r# #) -> (# s2#, I# r# #)
241+ {-# INLINE unsafeRead #-}
242+
243+ unsafeWrite (MArray len marr#) i@(I# i#) (I# e#) = ST $ \s1# ->
244+ CHECK_BOUNDS("unsafeWrite",len,i)
245+ case writeIntArray# marr# i# e# s1# of
246+ s2# -> (# s2#, () #)
247+ {-# INLINE unsafeWrite #-}
248+
249+#elif defined(__HUGS__)
250+
251+ bytesInArray n w = sizeOf w * n
252+ unsafeIndex = unsafeIndexArray
253+ unsafeRead = unsafeReadMArray
254+ unsafeWrite = unsafeWriteMArray
255+
256+#endif
257+
222instance Elt Word16 where
258instance Elt Word16 where
223#if defined(__GLASGOW_HASKELL__)
259#if defined(__GLASGOW_HASKELL__)
224
260