%
-% (c) The GRASP/AQUA Project, Glasgow University, 1997
+% (c) The GRASP/AQUA Project, Glasgow University, 1997-1998
%
\section{Fast strings}
tailFS, -- :: FastString -> FastString
concatFS, -- :: [FastString] -> FastString
consFS, -- :: Char -> FastString -> FastString
+ indexFS, -- :: FastString -> Int -> Char
hPutFS -- :: Handle -> FastString -> IO ()
) where
)
#else
import PrelPack
+#if __GLASGOW_HASKELL__ < 400
import PrelST ( StateAndPtr#(..) )
+#endif
+
+#if __GLASGOW_HASKELL__ <= 303
import PrelHandle ( readHandle,
-#if __GLASGOW_HASKELL__ < 303
+# if __GLASGOW_HASKELL__ < 303
filePtr,
-#endif
+# endif
writeHandle
)
+#endif
+
import PrelIOBase ( Handle__(..), IOError(..), IOErrorType(..),
- IOResult(..), IO(..),
+#if __GLASGOW_HASKELL__ < 400
+ IOResult(..),
+#endif
+ IO(..),
#if __GLASGOW_HASKELL__ >= 303
Handle__Type(..),
#endif
import GlaExts
import Addr ( Addr(..) )
import MutableArray ( MutableArray(..) )
+
+-- ForeignObj is now exported abstractly.
+#if __GLASGOW_HASKELL__ >= 303
+import qualified PrelForeign as Foreign ( ForeignObj(..) )
+#else
import Foreign ( ForeignObj(..) )
+#endif
+
import IOExts ( IORef, newIORef, readIORef, writeIORef )
import IO
#define hASH_TBL_SIZE 993
+
+#if __GLASGOW_HASKELL__ >= 400
+#define IOok STret
+#endif
\end{code}
@FastString@s are packed representations of strings
| otherwise = y
compare a b = cmpFS a b
-instance Text FastString where
- showsPrec p ps@(FastString u# _ _) r = showsPrec p (unpackFS ps) r
- showsPrec p ps r = showsPrec p (unpackFS ps) r
-
getByteArray# :: FastString -> ByteArray#
getByteArray# (FastString _ _ ba#) = ba#
headFS f@(CharStr a# l#) =
if l# ># 0# then C# (indexCharOffAddr# a# 0#) else error ("headFS: empty FS: " ++ unpackFS f)
+indexFS :: FastString -> Int -> Char
+indexFS f i@(I# i#) =
+ case f of
+ FastString _ l# ba#
+ | l# ># 0# && l# ># i# -> C# (indexCharArray# ba# i#)
+ | otherwise -> error (msg (I# l#))
+ CharStr a# l#
+ | l# ># 0# && l# ># i# -> C# (indexCharOffAddr# a# i#)
+ | otherwise -> error (msg (I# l#))
+ where
+ msg l = "indexFS: out of range: " ++ show (l,i)
+
tailFS :: FastString -> FastString
tailFS (FastString _ l# ba#) = mkFastSubStringBA# ba# 1# (l# -# 1#)
lookupTbl :: FastStringTable -> Int# -> IO [FastString]
lookupTbl (FastStringTable _ arr#) i# =
IO ( \ s# ->
+#if __GLASGOW_HASKELL__ < 400
case readArray# arr# i# s# of { StateAndPtr# s2# r ->
IOok s2# r })
+#else
+ readArray# arr# i# s#)
+#endif
updTbl :: FastStringTableVar -> FastStringTable -> Int# -> [FastString] -> IO ()
updTbl fs_table_var (FastStringTable uid# arr#) i# ls =
- IO (\ s# -> case writeArray# arr# i# ls s# of { s2# -> IOok s2# () }) >>
+ IO (\ s# -> case writeArray# arr# i# ls s# of { s2# ->
+#if __GLASGOW_HASKELL__ < 400
+ IOok s2# () }) >>
+#else
+ (# s2#, () #) }) >>
+#endif
writeIORef fs_table_var (FastStringTable (uid# +# 1#) arr#)
mkFastString# :: Addr# -> Int# -> FastString
else
constructError "hPutFS" >>= \ err ->
fail err
+
+
#else
hPutFS handle (FastString _ l# ba#)
| l# ==# 0# = return ()
where
bottom = error "hPutFS.ba"
+--ToDo: avoid silly code duplic.
+
hPutFS handle (CharStr a# l#)
| l# ==# 0# = return ()
| otherwise = hPutBuf handle (A# a#) (I# l#)
+
#endif
\end{code}