on master help sign in
Allow us to build Array Int

--HG-- extra : convert_revision : 26d550140a5fbe5ee125d440ceb47ad04cdf91bd

commitcc59efe4f9a568632f1cb708ee0ea302d41962b4 authorBryan O'Sullivan <bos@serpentine.com> dateThu 12 Feb 2009, 08:08 (18 years ago) parentc7c71f7
1 file changed+38−2
Data/Text/Array.hs+38−2
Data/Text/Array.hs+38−2
@@ -51,8 +51,9 @@ if (_k_) < 0 || (_k_) >= (_len_) then error ("Data.Text.Array." ++ (_func_) ++ "
5151#if defined(__GLASGOW_HASKELL__)
5252#include "MachDeps.h"
5353
54−import GHC.Base (ByteArray#, MutableByteArray#, Int(..), indexWord16Array#,
55− newByteArray#, readWord16Array#, unsafeCoerce#,
54+import GHC.Base (ByteArray#, MutableByteArray#, Int(..), indexIntArray#,
55+ indexWord16Array#, newByteArray#, readIntArray#,
56+ readWord16Array#, unsafeCoerce#, writeIntArray#,
5657 writeWord16Array#, (+#), (*#))
5758import GHC.Prim (Int#)
5859import GHC.ST (ST(..), runST)
@@ -160,6 +161,9 @@ unsafeFreeze :: MArray s e -> ST s (Array e)
160161
161162#if defined(__GLASGOW_HASKELL__)
162163
164+iNT_SCALE :: Int# -> Int#
165+iNT_SCALE n# = scale# *# n# where I# scale# = SIZEOF_INT
166+
163167wORD16_SCALE :: Int# -> Int#
164168wORD16_SCALE n# = scale# *# n# where I# scale# = SIZEOF_WORD16
165169
@@ -219,6 +223,38 @@ new len initVal = do
219223 sequence_ [unsafeWrite marr i initVal | i <- [0..len-1]]
220224 return marr
221225
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+
222258instance Elt Word16 where
223259#if defined(__GLASGOW_HASKELL__)
224260