Bryan O'Sullivan avatar Bryan O'Sullivan committed 4ca33aa

Allow us to build Array Int

Comments (0)

Files changed (1)

Data/Text/Array.hs

 #if defined(__GLASGOW_HASKELL__)
 #include "MachDeps.h"
 
-import GHC.Base (ByteArray#, MutableByteArray#, Int(..), indexWord16Array#,
-                 newByteArray#, readWord16Array#, unsafeCoerce#,
+import GHC.Base (ByteArray#, MutableByteArray#, Int(..), indexIntArray#,
+                 indexWord16Array#, newByteArray#, readIntArray#,
+                 readWord16Array#, unsafeCoerce#, writeIntArray#,
                  writeWord16Array#, (+#), (*#))
 import GHC.Prim (Int#)
 import GHC.ST (ST(..), runST)
 
 #if defined(__GLASGOW_HASKELL__)
 
+iNT_SCALE :: Int# -> Int#
+iNT_SCALE n# = scale# *# n# where I# scale# = SIZEOF_INT
+
 wORD16_SCALE :: Int# -> Int#
 wORD16_SCALE n# = scale# *# n# where I# scale# = SIZEOF_WORD16
 
   sequence_ [unsafeWrite marr i initVal | i <- [0..len-1]]
   return marr
 
+instance Elt Int where
+#if defined(__GLASGOW_HASKELL__)
+
+    bytesInArray (I# i#) _ = I# (iNT_SCALE i#)
+    {-# INLINE bytesInArray #-}
+
+    unsafeIndex (Array len ba#) i@(I# i#) =
+      CHECK_BOUNDS("unsafeIndex",len,i)
+        case indexIntArray# ba# i# of r# -> (I# r#)
+    {-# INLINE unsafeIndex #-}
+
+    unsafeRead (MArray len mba#) i@(I# i#) = ST $ \s# ->
+      CHECK_BOUNDS("unsafeRead",len,i)
+      case readIntArray# mba# i# s# of
+        (# s2#, r# #) -> (# s2#, I# r# #)
+    {-# INLINE unsafeRead #-}
+
+    unsafeWrite (MArray len marr#) i@(I# i#) (I# e#) = ST $ \s1# ->
+      CHECK_BOUNDS("unsafeWrite",len,i)
+      case writeIntArray# marr# i# e# s1# of
+        s2# -> (# s2#, () #)
+    {-# INLINE unsafeWrite #-}
+
+#elif defined(__HUGS__)
+
+    bytesInArray n w = sizeOf w * n
+    unsafeIndex = unsafeIndexArray
+    unsafeRead = unsafeReadMArray
+    unsafeWrite = unsafeWriteMArray
+
+#endif
+
 instance Elt Word16 where
 #if defined(__GLASGOW_HASKELL__)
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.