#define COMPILING_FAST_STRING
#include "HsVersions.h"
+#if __GLASGOW_HASKELL__ < 503
import PrelPack
import PrelIOBase ( IO(..) )
+#else
+import CString
+import GHC.IOBase ( IO(..) )
+#endif
import PrimPacked
import GlaExts
import Addr ( Addr(..) )
import Ptr ( Ptr(..) )
#endif
-#if __GLASGOW_HASKELL__ < 407
-import MutableArray ( MutableArray(..) )
-#else
+#if __GLASGOW_HASKELL__ < 503
import PrelArr ( STArray(..), newSTArray )
import IOExts ( hPutBufFull, hPutBufBAFull )
+#else
+import GHC.Arr ( STArray(..), newSTArray )
+import System.IO ( hPutBuf )
+import IOExts ( hPutBufBA )
+import CString ( unpackNBytesBA# )
#endif
import IOExts ( IORef, newIORef, readIORef, writeIORef )
import Char ( chr, ord )
#define hASH_TBL_SIZE 993
+
+#if __GLASGOW_HASKELL__ < 503
+hPutBuf = hPutBufFull
+hPutBufBA = hPutBufBAFull
+#endif
\end{code}
@FastString@s are packed representations of strings
string_table :: FastStringTableVar
string_table =
unsafePerformIO (
-#if __GLASGOW_HASKELL__ < 405
- stToIO (newArray (0::Int,hASH_TBL_SIZE) [])
- >>= \ (MutableArray _ arr#) ->
-#elif __GLASGOW_HASKELL__ < 407
- stToIO (newArray (0::Int,hASH_TBL_SIZE) [])
- >>= \ (MutableArray _ _ arr#) ->
-#else
stToIO (newSTArray (0::Int,hASH_TBL_SIZE) [])
>>= \ (STArray _ _ arr#) ->
-#endif
newIORef (FastStringTable 0# arr#))
lookupTbl :: FastStringTable -> Int# -> IO [FastString]
-- the string into a ByteArray
-- _trace "empty bucket" $
case copyPrefixStr (A# a#) (I# len#) of
-#if __GLASGOW_HASKELL__ < 405
- (ByteArray _ barr#) ->
-#else
(ByteArray _ _ barr#) ->
-#endif
let f_str = FastString uid# len# barr# in
updTbl string_table ft h [f_str] >>
({- _trace ("new: " ++ show f_str) $ -} return f_str)
case bucket_match ls len# a# of
Nothing ->
case copyPrefixStr (A# a#) (I# len#) of
-#if __GLASGOW_HASKELL__ < 405
- (ByteArray _ barr#) ->
-#else
(ByteArray _ _ barr#) ->
-#endif
let f_str = FastString uid# len# barr# in
updTbl string_table ft h (f_str:ls) >>
( {- _trace ("new: " ++ show f_str) $ -} return f_str)
-- no match, add it to table by copying out the
-- the string into a ByteArray
-- _trace "empty bucket(b)" $
-#if __GLASGOW_HASKELL__ < 405
- case copySubStrBA (ByteArray btm barr#) (I# start#) (I# len#) of
- (ByteArray _ ba#) ->
-#else
case copySubStrBA (ByteArray btm btm barr#) (I# start#) (I# len#) of
(ByteArray _ _ ba#) ->
-#endif
let f_str = FastString uid# len# ba# in
updTbl string_table ft h [f_str] >>
-- _trace ("new(b): " ++ show f_str) $
-- _trace ("non-empty bucket(b)"++show ls) $
case bucket_match ls start# len# barr# of
Nothing ->
-#if __GLASGOW_HASKELL__ < 405
- case copySubStrBA (ByteArray btm barr#) (I# start#) (I# len#) of
- (ByteArray _ ba#) ->
-#else
case copySubStrBA (ByteArray btm btm barr#) (I# start#) (I# len#) of
(ByteArray _ _ ba#) ->
-#endif
let f_str = FastString uid# len# ba# in
updTbl string_table ft h (f_str:ls) >>
-- _trace ("new(b): " ++ show f_str) $
mkFastStringNarrow :: String -> FastString
mkFastStringNarrow str =
case packString str of
-#if __GLASGOW_HASKELL__ < 405
- (ByteArray (_,I# len#) frozen#) ->
-#else
(ByteArray _ (I# len#) frozen#) ->
-#endif
mkFastSubStringBA# frozen# 0# len#
{- 0-indexed array, len# == index to one beyond end of string,
i.e., (0,1) => empty string. -}
EQ
else
unsafePerformIO (
-#if __GLASGOW_HASKELL__ < 405
- _ccall_ strcmp (ByteArray bot b1#) (ByteArray bot b2#) >>= \ (I# res) ->
-#else
_ccall_ strcmp (ByteArray bot bot b1#) (ByteArray bot bot b2#) >>= \ (I# res) ->
-#endif
return (
if res <# 0# then LT
else if res ==# 0# then EQ
else GT
))
where
-#if __GLASGOW_HASKELL__ < 405
- bot :: (Int,Int)
-#else
bot :: Int
-#endif
bot = error "tagCmp"
cmpFS (CharStr bs1 len1) (CharStr bs2 len2)
= unsafePerformIO (
else GT
))
where
-#if __GLASGOW_HASKELL__ < 405
- ba1 = ByteArray ((error "")::(Int,Int)) bs1
-#else
ba1 = ByteArray (error "") ((error "")::Int) bs1
-#endif
ba2 = A# bs2
cmpFS a@(CharStr _ _) b@(FastString _ _ _)
hPutFS :: Handle -> FastString -> IO ()
hPutFS handle (FastString _ l# ba#)
| l# ==# 0# = return ()
-#if __GLASGOW_HASKELL__ < 405
- | otherwise = hPutBufBA handle (ByteArray bot ba#) (I# l#)
-#elif __GLASGOW_HASKELL__ < 407
- | otherwise = hPutBufBA handle (ByteArray bot bot ba#) (I# l#)
-#else
| otherwise = do mba <- stToIO $ unsafeThawByteArray (ByteArray (bot::Int) bot ba#)
- hPutBufBAFull handle mba (I# l#)
+ hPutBufBA handle mba (I# l#)
where
bot = error "hPutFS.ba"
hPutFS handle (CharStr a# l#)
| l# ==# 0# = return ()
-#if __GLASGOW_HASKELL__ < 407
+#if __GLASGOW_HASKELL__ < 411
| otherwise = hPutBuf handle (A# a#) (I# l#)
-#elif __GLASGOW_HASKELL__ < 411
- | otherwise = hPutBufFull handle (A# a#) (I# l#)
#else
- | otherwise = hPutBufFull handle (Ptr a#) (I# l#)
+ | otherwise = hPutBuf handle (Ptr a#) (I# l#)
#endif
-- ONLY here for debugging the NCG (so -ddump-stix works for string
-- literals); no idea if this is really necessary. JRS, 010131
hPutFS handle (UnicodeStr _ is)
= hPutStr handle ("(UnicodeStr " ++ show is ++ ")")
-
-#endif
\end{code}