Make this compile again, and update with latest changes from hslibs/lang.
-- Stability : provisional
-- Portability : non-portable (requires universal quantification for runST)
--
--- $Id: Lazy.hs,v 1.3 2001/12/21 15:07:21 simonmar Exp $
+-- $Id: Lazy.hs,v 1.4 2002/01/02 14:40:09 simonmar Exp $
--
-- This module presents an identical interface to Control.Monad.ST,
-- but the underlying implementation of the state thread is lazy.
unsafeInterleaveST,
fixST,
- STRef.STRef,
- newSTRef, readSTRef, writeSTRef,
-
- STArray.STArray,
- newSTArray, readSTArray, writeSTArray, boundsSTArray,
- thawSTArray, freezeSTArray, unsafeFreezeSTArray,
-#ifdef __GLASGOW_HASKELL__
--- no 'good' reason, just doesn't support it right now.
- unsafeThawSTArray,
-#endif
-
ST.unsafeIOToST, ST.stToIO,
strictToLazyST, lazyToStrictST
import Prelude
-import qualified Data.STRef as STRef
-import Data.Array
-
#ifdef __GLASGOW_HASKELL__
import qualified Control.Monad.ST as ST
-import qualified GHC.Arr as STArray
import qualified GHC.ST
import GHC.Base
import Control.Monad
-import Data.Ix
#endif
-#ifdef __HUGS__
-import qualified ST
-import Monad
-import Ix
-import Array
-import PrelPrim ( unST
- , mkST
- , PrimMutableArray
- , PrimArray
- , primNewArray
- , primReadArray
- , primWriteArray
- , primUnsafeFreezeArray
- , primSizeMutableArray
- , primSizeArray
- , primIndexArray
- )
-#endif
-
-
#ifdef __GLASGOW_HASKELL__
newtype ST s a = ST (State s -> (a, State s))
data State s = S# (State# s)
#endif
-#ifdef __HUGS__
-newtype ST s a = ST (s -> (a,s))
-#endif
-
instance Functor (ST s) where
fmap f m = ST $ \ s ->
let
{-# NOINLINE runST #-}
runST :: (forall s. ST s a) -> a
runST st = case st of ST the_st -> let (r,_) = the_st (S# realWorld#) in r
-#endif
-
-#ifdef __HUGS__
-runST :: (__forall s. ST s a) -> a
-runST st = case st of ST the_st -> let (r,_) = the_st realWorld in r
- where realWorld = error "runST: entered the RealWorld"
-#endif
fixST :: (a -> ST s a) -> ST s a
fixST m = ST (\ s ->
(r,s) = m_r s
in
(r,s))
-
--- ---------------------------------------------------------------------------
--- Variables
-
-newSTRef :: a -> ST s (STRef.STRef s a)
-readSTRef :: STRef.STRef s a -> ST s a
-writeSTRef :: STRef.STRef s a -> a -> ST s ()
-
-newSTRef = strictToLazyST . STRef.newSTRef
-readSTRef = strictToLazyST . STRef.readSTRef
-writeSTRef r a = strictToLazyST (STRef.writeSTRef r a)
-
--- --------------------------------------------------------------------------
--- Arrays
-
-newSTArray :: Ix ix => (ix,ix) -> elt -> ST s (STArray.STArray s ix elt)
-readSTArray :: Ix ix => STArray.STArray s ix elt -> ix -> ST s elt
-writeSTArray :: Ix ix => STArray.STArray s ix elt -> ix -> elt -> ST s ()
-boundsSTArray :: Ix ix => STArray.STArray s ix elt -> (ix, ix)
-thawSTArray :: Ix ix => Array ix elt -> ST s (STArray.STArray s ix elt)
-freezeSTArray :: Ix ix => STArray.STArray s ix elt -> ST s (Array ix elt)
-unsafeFreezeSTArray :: Ix ix => STArray.STArray s ix elt -> ST s (Array ix elt)
-
-#ifdef __GLASGOW_HASKELL__
-
-newSTArray ixs init = strictToLazyST (STArray.newSTArray ixs init)
-
-readSTArray arr ix = strictToLazyST (STArray.readSTArray arr ix)
-writeSTArray arr ix v = strictToLazyST (STArray.writeSTArray arr ix v)
-boundsSTArray arr = STArray.boundsSTArray arr
-thawSTArray arr = strictToLazyST (STArray.thawSTArray arr)
-freezeSTArray arr = strictToLazyST (STArray.freezeSTArray arr)
-unsafeFreezeSTArray arr = strictToLazyST (STArray.unsafeFreezeSTArray arr)
-unsafeThawSTArray arr = strictToLazyST (STArray.unsafeThawSTArray arr)
-#endif
-
-
-#ifdef __HUGS__
-newSTArray ixs elt = do
- { arr <- strictToLazyST (primNewArray (rangeSize ixs) elt)
- ; return (STArray ixs arr)
- }
-
-boundsSTArray (STArray ixs arr) = ixs
-readSTArray (STArray ixs arr) ix
- = strictToLazyST (primReadArray arr (index ixs ix))
-writeSTArray (STArray ixs arr) ix elt
- = strictToLazyST (primWriteArray arr (index ixs ix) elt)
-freezeSTArray (STArray ixs arr) = do
- { arr' <- strictToLazyST (primFreezeArray arr)
- ; return (Array ixs arr')
- }
-
-unsafeFreezeSTArray (STArray ixs arr) = do
- { arr' <- strictToLazyST (primUnsafeFreezeArray arr)
- ; return (Array ixs arr')
- }
-
-thawSTArray (Array ixs arr) = do
- { arr' <- strictToLazyST (primThawArray arr)
- ; return (STArray ixs arr')
- }
-
-primFreezeArray :: PrimMutableArray s a -> ST.ST s (PrimArray a)
-primFreezeArray arr = do
- { let n = primSizeMutableArray arr
- ; arr' <- primNewArray n arrEleBottom
- ; mapM_ (copy arr arr') [0..n-1]
- ; primUnsafeFreezeArray arr'
- }
- where
- copy arr arr' i = do { x <- primReadArray arr i; primWriteArray arr' i x }
- arrEleBottom = error "primFreezeArray: panic"
-
-primThawArray :: PrimArray a -> ST.ST s (PrimMutableArray s a)
-primThawArray arr = do
- { let n = primSizeArray arr
- ; arr' <- primNewArray n arrEleBottom
- ; mapM_ (copy arr arr') [0..n-1]
- ; return arr'
- }
- where
- copy arr arr' i = primWriteArray arr' i (primIndexArray arr i)
- arrEleBottom = error "primFreezeArray: panic"
#endif
-- ---------------------------------------------------------------------------
case (m (S# s)) of (a, S# s') -> (# s', a #)
#endif
-#ifdef __HUGS__
-strictToLazyST :: ST.ST s a -> ST s a
-strictToLazyST m = ST $ \s ->
- let
- pr = unST m s
- r = fst pr
- s' = snd pr
- in
- (r, s')
-
-
-lazyToStrictST :: ST s a -> ST.ST s a
-lazyToStrictST (ST m) = mkST $ m
-#endif
-
unsafeInterleaveST :: ST s a -> ST s a
unsafeInterleaveST = strictToLazyST . ST.unsafeInterleaveST . lazyToStrictST
-- Stability : experimental
-- Portability : non-portable
--
--- $Id: Base.hs,v 1.4 2001/07/31 14:36:19 simonmar Exp $
+-- $Id: Base.hs,v 1.5 2002/01/02 14:40:10 simonmar Exp $
--
-- Basis for IArray and MArray. Not intended for external consumption;
-- use IArray or MArray instead.
{-# RULES "cmpUArray/Int" cmpUArray = cmpIntUArray #-}
-showsUArray :: (IArray UArray e, Ix i, Show i, Show e)
- => Int -> UArray i e -> ShowS
-showsUArray p a =
+-----------------------------------------------------------------------------
+-- Showing IArrays
+
+{-# SPECIALISE
+ showsIArray :: (IArray UArray e, Ix i, Show i, Show e) =>
+ Int -> UArray i e -> ShowS
+ #-}
+
+showsIArray :: (IArray a e, Ix i, Show i, Show e) => Int -> a i e -> ShowS
+showsIArray p a =
showParen (p > 9) $
showString "array " .
shows (bounds a) .
{-# INLINE unsafeArray #-}
unsafeArray lu ies = runST (unsafeArrayUArray lu ies)
{-# INLINE unsafeAt #-}
- unsafeAt (UArray _ _ arr#) (I# i#) =
-#if WORD_SIZE_IN_BYTES == 4
- I64# (indexInt64Array# arr# i#)
-#else
- I64# (indexIntArray# arr# i#)
-#endif
+ unsafeAt (UArray _ _ arr#) (I# i#) = I64# (indexInt64Array# arr# i#)
{-# INLINE unsafeReplace #-}
unsafeReplace arr ies = runST (unsafeReplaceUArray arr ies)
{-# INLINE unsafeAccum #-}
{-# INLINE unsafeArray #-}
unsafeArray lu ies = runST (unsafeArrayUArray lu ies)
{-# INLINE unsafeAt #-}
- unsafeAt (UArray _ _ arr#) (I# i#) =
-#if WORD_SIZE_IN_BYTES == 4
- W64# (indexWord64Array# arr# i#)
-#else
- W64# (indexWordArray# arr# i#)
-#endif
+ unsafeAt (UArray _ _ arr#) (I# i#) = W64# (indexWord64Array# arr# i#)
{-# INLINE unsafeReplace #-}
unsafeReplace arr ies = runST (unsafeReplaceUArray arr ies)
{-# INLINE unsafeAccum #-}
compare = cmpUArray
instance (Ix ix, Show ix) => Show (UArray ix Bool) where
- showsPrec = showsUArray
+ showsPrec = showsIArray
instance (Ix ix, Show ix) => Show (UArray ix Char) where
- showsPrec = showsUArray
+ showsPrec = showsIArray
instance (Ix ix, Show ix) => Show (UArray ix Int) where
- showsPrec = showsUArray
+ showsPrec = showsIArray
instance (Ix ix, Show ix) => Show (UArray ix Word) where
- showsPrec = showsUArray
+ showsPrec = showsIArray
instance (Ix ix, Show ix) => Show (UArray ix Float) where
- showsPrec = showsUArray
+ showsPrec = showsIArray
instance (Ix ix, Show ix) => Show (UArray ix Double) where
- showsPrec = showsUArray
+ showsPrec = showsIArray
instance (Ix ix, Show ix) => Show (UArray ix Int8) where
- showsPrec = showsUArray
+ showsPrec = showsIArray
instance (Ix ix, Show ix) => Show (UArray ix Int16) where
- showsPrec = showsUArray
+ showsPrec = showsIArray
instance (Ix ix, Show ix) => Show (UArray ix Int32) where
- showsPrec = showsUArray
+ showsPrec = showsIArray
instance (Ix ix, Show ix) => Show (UArray ix Int64) where
- showsPrec = showsUArray
+ showsPrec = showsIArray
instance (Ix ix, Show ix) => Show (UArray ix Word8) where
- showsPrec = showsUArray
+ showsPrec = showsIArray
instance (Ix ix, Show ix) => Show (UArray ix Word16) where
- showsPrec = showsUArray
+ showsPrec = showsIArray
instance (Ix ix, Show ix) => Show (UArray ix Word32) where
- showsPrec = showsUArray
+ showsPrec = showsIArray
instance (Ix ix, Show ix) => Show (UArray ix Word64) where
- showsPrec = showsUArray
+ showsPrec = showsIArray
-----------------------------------------------------------------------------
-- Mutable arrays
case newByteArray# (n# *# 8#) s1# of { (# s2#, marr# #) ->
(# s2#, STUArray l u marr# #) }}
{-# INLINE unsafeRead #-}
- unsafeRead (STUArray _ _ marr#) (I# i#) = ST $ \s1# ->
-#if WORD_SIZE_IN_BYTES == 4
+ unsafeRead (STUArray _ _ marr#) (I# i#) = ST $ \s1# ->
case readInt64Array# marr# i# s1# of { (# s2#, e# #) ->
-#else
- case readIntArray# marr# i# s1# of { (# s2#, e# #) ->
-#endif
(# s2#, I64# e# #) }
{-# INLINE unsafeWrite #-}
unsafeWrite (STUArray _ _ marr#) (I# i#) (I64# e#) = ST $ \s1# ->
-#if WORD_SIZE_IN_BYTES == 4
case writeInt64Array# marr# i# e# s1# of { s2# ->
-#else
- case writeIntArray# marr# i# e# s1# of { s2# ->
-#endif
(# s2#, () #) }
instance MArray (STUArray s) Word8 (ST s) where
(# s2#, STUArray l u marr# #) }}
{-# INLINE unsafeRead #-}
unsafeRead (STUArray _ _ marr#) (I# i#) = ST $ \s1# ->
-#if WORD_SIZE_IN_BYTES == 4
case readWord64Array# marr# i# s1# of { (# s2#, e# #) ->
-#else
- case readWordArray# marr# i# s1# of { (# s2#, e# #) ->
-#endif
(# s2#, W64# e# #) }
{-# INLINE unsafeWrite #-}
unsafeWrite (STUArray _ _ marr#) (I# i#) (W64# e#) = ST $ \s1# ->
-#if WORD_SIZE_IN_BYTES == 4
case writeWord64Array# marr# i# e# s1# of { s2# ->
-#else
- case writeWordArray# marr# i# e# s1# of { s2# ->
-#endif
(# s2#, () #) }
-----------------------------------------------------------------------------
bOOL_SCALE, bOOL_WORD_SCALE,
wORD_SCALE, dOUBLE_SCALE, fLOAT_SCALE :: Int# -> Int#
-bOOL_SCALE n# = (n# +# last#) `iShiftRA#` 3#
- where I# last# = WORD_SIZE_IN_BYTES * 8 - 1
+bOOL_SCALE n# = (n# +# last#) `uncheckedIShiftRA#` 3#
+ where I# last# = SIZEOF_HSWORD * 8 - 1
bOOL_WORD_SCALE n# = bOOL_INDEX (n# +# last#)
- where I# last# = WORD_SIZE_IN_BYTES * 8 - 1
-wORD_SCALE n# = scale# *# n# where I# scale# = WORD_SIZE_IN_BYTES
-dOUBLE_SCALE n# = scale# *# n# where I# scale# = DOUBLE_SIZE_IN_BYTES
-fLOAT_SCALE n# = scale# *# n# where I# scale# = FLOAT_SIZE_IN_BYTES
+ where I# last# = SIZEOF_HSWORD * 8 - 1
+wORD_SCALE n# = scale# *# n# where I# scale# = SIZEOF_HSWORD
+dOUBLE_SCALE n# = scale# *# n# where I# scale# = SIZEOF_HSDOUBLE
+fLOAT_SCALE n# = scale# *# n# where I# scale# = SIZEOF_HSFLOAT
bOOL_INDEX :: Int# -> Int#
-#if WORD_SIZE_IN_BYTES == 4
-bOOL_INDEX i# = i# `iShiftRA#` 5#
-#elif WORD_SIZE_IN_BYTES == 8
-bOOL_INDEX i# = i# `iShiftRA#` 6#
+#if SIZEOF_HSWORD == 4
+bOOL_INDEX i# = i# `uncheckedIShiftRA#` 5#
+#elif SIZEOF_HSWORD == 8
+bOOL_INDEX i# = i# `uncheckedIShiftRA#` 6#
#endif
bOOL_BIT, bOOL_NOT_BIT :: Int# -> Word#
-bOOL_BIT n# = int2Word# 1# `shiftL#` (word2Int# (int2Word# n# `and#` mask#))
- where W# mask# = WORD_SIZE_IN_BYTES * 8 - 1
+bOOL_BIT n# = int2Word# 1# `uncheckedShiftL#` (word2Int# (int2Word# n# `and#` mask#))
+ where W# mask# = SIZEOF_HSWORD * 8 - 1
bOOL_NOT_BIT n# = bOOL_BIT n# `xor#` mb# where W# mb# = maxBound
-----------------------------------------------------------------------------
-- Stability : experimental
-- Portability : non-portable
--
--- $Id: Diff.hs,v 1.1 2001/07/04 10:48:39 simonmar Exp $
+-- $Id: Diff.hs,v 1.2 2002/01/02 14:40:10 simonmar Exp $
--
-- Functional arrays with constant-time update.
--
-- -fallow-undecidable-instances, so each instance is separate here.
------------------------------------------------------------------------
+-- Showing DiffArrays
+
+instance (Ix ix, Show ix, Show e) => Show (DiffArray ix e) where
+ showsPrec = showsIArray
+
+instance (Ix ix, Show ix) => Show (DiffUArray ix Char) where
+ showsPrec = showsIArray
+
+instance (Ix ix, Show ix) => Show (DiffUArray ix Int) where
+ showsPrec = showsIArray
+
+instance (Ix ix, Show ix) => Show (DiffUArray ix Word) where
+ showsPrec = showsIArray
+
+instance (Ix ix, Show ix) => Show (DiffUArray ix Float) where
+ showsPrec = showsIArray
+
+instance (Ix ix, Show ix) => Show (DiffUArray ix Double) where
+ showsPrec = showsIArray
+
+instance (Ix ix, Show ix) => Show (DiffUArray ix Int8) where
+ showsPrec = showsIArray
+
+instance (Ix ix, Show ix) => Show (DiffUArray ix Int16) where
+ showsPrec = showsIArray
+
+instance (Ix ix, Show ix) => Show (DiffUArray ix Int32) where
+ showsPrec = showsIArray
+
+instance (Ix ix, Show ix) => Show (DiffUArray ix Int64) where
+ showsPrec = showsIArray
+
+instance (Ix ix, Show ix) => Show (DiffUArray ix Word8) where
+ showsPrec = showsIArray
+
+instance (Ix ix, Show ix) => Show (DiffUArray ix Word16) where
+ showsPrec = showsIArray
+
+instance (Ix ix, Show ix) => Show (DiffUArray ix Word32) where
+ showsPrec = showsIArray
+
+instance (Ix ix, Show ix) => Show (DiffUArray ix Word64) where
+ showsPrec = showsIArray
+
+------------------------------------------------------------------------
-- Boring instances.
instance HasBounds a => HasBounds (IOToDiffArray a) where
unsafeAt a i = unsafePerformIO $ a `readDiffArray` i
unsafeReplace a ies = unsafePerformIO $ a `replaceDiffArray` ies
+
+
------------------------------------------------------------------------
-- The important stuff.
+{-# OPTIONS -#include "HsCore.h" #-}
-----------------------------------------------------------------------------
--
-- Module : Data.Array.IO
-- Stability : experimental
-- Portability : non-portable
--
--- $Id: IO.hs,v 1.2 2001/09/14 11:25:23 simonmar Exp $
+-- $Id: IO.hs,v 1.3 2002/01/02 14:40:10 simonmar Exp $
--
-- Mutable boxed/unboxed arrays in the IO monad.
--
= illegalBufferSize handle "hGetArray" count
| otherwise = do
wantReadableHandle "hGetArray" handle $
- \ handle_@Handle__{ haFD=fd, haBuffer=ref } -> do
+ \ handle_@Handle__{ haFD=fd, haBuffer=ref, haIsStream=is_stream } -> do
buf@Buffer{ bufBuf=raw, bufWPtr=w, bufRPtr=r } <- readIORef ref
if bufferEmpty buf
- then readChunkBA fd ptr 0 count
+ then readChunk fd is_stream ptr 0 count
else do
let avail = w - r
copied <- if (count >= avail)
let remaining = count - copied
if remaining > 0
- then do rest <- readChunkBA fd ptr copied remaining
+ then do rest <- readChunk fd is_stream ptr copied remaining
return (rest + count)
else return count
-
-readChunkBA :: FD -> RawBuffer -> Int -> Int -> IO Int
-readChunkBA fd ptr init_off bytes = loop init_off bytes
+
+readChunk :: FD -> Bool -> RawBuffer -> Int -> Int -> IO Int
+readChunk fd is_stream ptr init_off bytes = loop init_off bytes
where
loop :: Int -> Int -> IO Int
loop off bytes | bytes <= 0 = return (off - init_off)
loop off bytes = do
r' <- throwErrnoIfMinus1RetryMayBlock "readChunk"
- (readBA (fromIntegral fd) ptr
+ (read_off (fromIntegral fd) is_stream ptr
(fromIntegral off) (fromIntegral bytes))
(threadWaitRead fd)
let r = fromIntegral r'
then return (off - init_off)
else loop (off + r) (bytes - r)
-foreign import "read_ba_wrap" unsafe
- readBA :: FD -> RawBuffer -> Int -> CInt -> IO CInt
-
- -----------------------------------------------------------------------------
+-- ---------------------------------------------------------------------------
-- hPutArray
hPutArray
= illegalBufferSize handle "hPutArray" count
| otherwise
= do wantWritableHandle "hPutArray" handle $
- \ handle_@Handle__{ haFD=fd, haBuffer=ref } -> do
+ \ handle_@Handle__{ haFD=fd, haBuffer=ref, haIsStream=stream } -> do
old_buf@Buffer{ bufBuf=old_raw, bufRPtr=r, bufWPtr=w, bufSize=size }
<- readIORef ref
return ()
-- else, we have to flush
- else do flushed_buf <- flushWriteBuffer fd old_buf
+ else do flushed_buf <- flushWriteBuffer fd stream old_buf
writeIORef ref flushed_buf
let this_buf =
Buffer{ bufBuf=raw, bufState=WriteBuffer,
bufRPtr=0, bufWPtr=count, bufSize=count }
- flushWriteBuffer fd this_buf
+ flushWriteBuffer fd stream this_buf
return ()
------------------------------------------------------------------------------
+-- ---------------------------------------------------------------------------
-- Internal Utils
-foreign import "memcpy_wrap_dst_off" unsafe
+foreign import "__hscore_memcpy_dst_off" unsafe
memcpy_baoff_ba :: RawBuffer -> Int -> RawBuffer -> CSize -> IO (Ptr ())
-foreign import "memcpy_wrap_src_off" unsafe
+foreign import "__hscore_memcpy_src_off" unsafe
memcpy_ba_baoff :: RawBuffer -> RawBuffer -> Int -> CSize -> IO (Ptr ())
illegalBufferSize :: Handle -> String -> Int -> IO a
-- Stability : experimental
-- Portability : portable
--
--- $Id: IORef.hs,v 1.3 2001/12/21 15:07:21 simonmar Exp $
+-- $Id: IORef.hs,v 1.4 2002/01/02 14:40:09 simonmar Exp $
--
-- Mutable references in the IO monad.
--
#endif
#endif /* __GLASGOW_HASKELL__ */
-#ifdef __HUGS__
-import IOExts ( IORef, newIORef, writeIORef, readIORef )
-import ST ( stToIO, newSTRef, readSTRef, writeSTRef )
-#endif
-
import Data.Dynamic
-#ifndef __PARALLEL_HASKELL__
+#if defined(__GLASGOW_HASKELL__) && !defined(__PARALLEL_HASKELL__)
mkWeakIORef :: IORef a -> IO () -> IO (Weak (IORef a))
mkWeakIORef r@(IORef (STRef r#)) f = IO $ \s ->
case mkWeak# r# r f s of (# s1, w #) -> (# s1, Weak w #)
#endif
+#if defined __HUGS__
+data IORef a -- mutable variables containing values of type a
+
+primitive newIORef "newRef" :: a -> IO (IORef a)
+primitive readIORef "getRef" :: IORef a -> IO a
+primitive writeIORef "setRef" :: IORef a -> a -> IO ()
+primitive eqIORef "eqRef" :: IORef a -> IORef a -> Bool
+
+instance Eq (IORef a) where
+ (==) = eqIORef
+#endif /* __HUGS__ */
+
modifyIORef :: IORef a -> (a -> a) -> IO ()
modifyIORef ref f = writeIORef ref . f =<< readIORef ref
--- /dev/null
+-----------------------------------------------------------------------------
+--
+-- Module : GHC.Exts
+-- Copyright : (c) The University of Glasgow 2001
+-- License : BSD-style (see the file libraries/core/LICENSE)
+--
+-- Maintainer : libraries@haskell.org
+-- Stability : experimental
+-- Portability : non-portable
+--
+-- $Id: Exts.hs,v 1.1 2002/01/02 14:40:10 simonmar Exp $
+--
+-- GHC Extensions: this is the Approved Way to get at GHC-specific stuff.
+--
+-----------------------------------------------------------------------------
+
+module GHC.Exts
+ (
+ -- the representation of some basic types:
+ Int(..),Word(..),Float(..),Double(..),Integer(..),Char(..),
+
+ -- Fusion
+ build, augment,
+
+ -- shifty wrappers from GHC.Base
+ shiftL#, shiftRL#, iShiftL#, iShiftRA#, iShiftRL#,
+
+ -- and finally, all the unboxed primops of GHC!
+ module GHC.Prim
+
+ ) where
+
+import {-# SOURCE #-} GHC.Prim
+import GHC.Base
+import GHC.Word
+import GHC.Num
+import GHC.Float
#undef DEBUG
-- -----------------------------------------------------------------------------
--- $Id: Handle.hs,v 1.1 2001/12/21 15:07:22 simonmar Exp $
+-- $Id: Handle.hs,v 1.2 2002/01/02 14:40:10 simonmar Exp $
--
-- (c) The University of Glasgow, 1994-2001
--
= Buffer{ bufBuf=b, bufRPtr=0, bufWPtr=0, bufSize=size, bufState=state }
allocateBuffer :: Int -> BufferState -> IO Buffer
-allocateBuffer sz@(I## size) state = IO $ \s ->
- case newByteArray## size s of { (## s, b ##) ->
- (## s, newEmptyBuffer b state sz ##) }
+allocateBuffer sz@(I# size) state = IO $ \s ->
+ case newByteArray# size s of { (# s, b #) ->
+ (# s, newEmptyBuffer b state sz #) }
writeCharIntoBuffer :: RawBuffer -> Int -> Char -> IO Int
-writeCharIntoBuffer slab (I## off) (C## c)
- = IO $ \s -> case writeCharArray## slab off c s of
- s -> (## s, I## (off +## 1##) ##)
+writeCharIntoBuffer slab (I# off) (C# c)
+ = IO $ \s -> case writeCharArray# slab off c s of
+ s -> (# s, I# (off +# 1#) #)
readCharFromBuffer :: RawBuffer -> Int -> IO (Char, Int)
-readCharFromBuffer slab (I## off)
- = IO $ \s -> case readCharArray## slab off s of
- (## s, c ##) -> (## s, (C## c, I## (off +## 1##)) ##)
+readCharFromBuffer slab (I# off)
+ = IO $ \s -> case readCharArray# slab off s of
+ (# s, c #) -> (# s, (C# c, I# (off +# 1#)) #)
getBuffer :: FD -> BufferState -> IO (IORef Buffer, BufferMode)
getBuffer fd state = do
puts ("flushReadBuffer: new file offset = " ++ show off ++ "\n")
# endif
throwErrnoIfMinus1Retry "flushReadBuffer"
- (c_lseek (fromIntegral fd) (fromIntegral off) sSEEK_CUR)
+ (c_lseek (fromIntegral fd) (fromIntegral off) sEEK_CUR)
return buf{ bufWPtr=0, bufRPtr=0 }
flushWriteBuffer :: FD -> Bool -> Buffer -> IO Buffer
| otherwise = False
binary_flags
- | binary = PrelHandle.o_BINARY
+ | binary = GHC.Handle.o_BINARY
| otherwise = 0
oflags = oflags1 .|. binary_flags
#undef DEBUG_DUMP
-- -----------------------------------------------------------------------------
--- $Id: IO.hs,v 1.1 2001/12/21 15:07:23 simonmar Exp $
+-- $Id: IO.hs,v 1.2 2002/01/02 14:40:10 simonmar Exp $
--
-- (c) The University of Glasgow, 1992-2001
--
--- Module GHC.IO
-
--- This module defines all basic IO operations.
--- These are needed for the IO operations exported by Prelude,
--- but as it happens they also do everything required by library
--- module IO.
module GHC.IO (
- putChar, putStr, putStrLn, print, getChar, getLine, getContents,
- interact, readFile, writeFile, appendFile, readLn, readIO, hReady,
hWaitForInput, hGetChar, hGetLine, hGetContents, hPutChar, hPutStr,
- hPutStrLn, hPrint,
commitBuffer', -- hack, see below
hGetcBuffered, -- needed by ghc/compiler/utils/StringBuffer.lhs
hGetBuf, hPutBuf, slurpFile
hWaitForInput :: Handle -> Int -> IO Bool
hWaitForInput h msecs = do
- wantReadableHandle "hReady" h $ \ handle_ -> do
+ wantReadableHandle "hWaitForInput" h $ \ handle_ -> do
let ref = haBuffer handle_
buf <- readIORef ref
then return True
else do
- r <- throwErrnoIfMinus1Retry "hReady"
+ r <- throwErrnoIfMinus1Retry "hWaitForInput"
(inputReady (fromIntegral (haFD handle_)) (fromIntegral msecs) (haIsStream handle_))
return (r /= 0)
unpack :: RawBuffer -> Int -> Int -> IO [Char]
unpack buf r 0 = return ""
-unpack buf (I## r) (I## len) = IO $ \s -> unpack [] (len -## 1##) s
+unpack buf (I# r) (I# len) = IO $ \s -> unpack [] (len -# 1#) s
where
unpack acc i s
- | i <## r = (## s, acc ##)
+ | i <# r = (# s, acc #)
| otherwise =
- case readCharArray## buf i s of
- (## s, ch ##) -> unpack (C## ch : acc) (i -## 1##) s
+ case readCharArray# buf i s of
+ (# s, ch #) -> unpack (C# ch : acc) (i -# 1#) s
hGetLineUnBuffered :: Handle -> IO String
unpackAcc :: RawBuffer -> Int -> Int -> [Char] -> IO [Char]
unpackAcc buf r 0 acc = return ""
-unpackAcc buf (I## r) (I## len) acc = IO $ \s -> unpack acc (len -## 1##) s
+unpackAcc buf (I# r) (I# len) acc = IO $ \s -> unpack acc (len -# 1#) s
where
unpack acc i s
- | i <## r = (## s, acc ##)
+ | i <# r = (# s, acc #)
| otherwise =
- case readCharArray## buf i s of
- (## s, ch ##) -> unpack (C## ch : acc) (i -## 1##) s
+ case readCharArray# buf i s of
+ (# s, ch #) -> unpack (C# ch : acc) (i -# 1#) s
-- ---------------------------------------------------------------------------
-- hPutChar
return ()
shoveString n (c:cs) = do
n' <- writeCharIntoBuffer raw n c
- if (c == '\n')
+ if (c == '\n')
then do
new_buf <- commitBuffer hdl raw len n' True{-needs flush-} False
writeLines hdl new_buf cs
-> Bool -- release the buffer?
-> IO Buffer
-commitBuffer hdl raw sz@(I## _) count@(I## _) flush release = do
+commitBuffer hdl raw sz@(I# _) count@(I# _) flush release = do
wantWritableHandle "commitAndReleaseBuffer" hdl $
commitBuffer' hdl raw sz count flush release
--
-- This hack is a fairly big win for hPutStr performance. --SDM 18/9/2001
--
-commitBuffer' hdl raw sz@(I## _) count@(I## _) flush release
+commitBuffer' hdl raw sz@(I# _) count@(I# _) flush release
handle_@Handle__{ haFD=fd, haBuffer=ref, haBuffers=spare_buf_ref } = do
#ifdef DEBUG_DUMP
| count <= 0 = illegalBufferSize handle "hPutBuf" count
| otherwise =
wantWritableHandle "hPutBuf" handle $
- \ handle_@Handle__{ haFD=fd, haBuffer=ref } -> do
+ \ handle_@Handle__{ haFD=fd, haBuffer=ref, haIsStream=is_stream } -> do
old_buf@Buffer{ bufBuf=old_raw, bufRPtr=r, bufWPtr=w, bufSize=size }
<- readIORef ref
return ()
-- else, we have to flush
- else do flushed_buf <- flushWriteBuffer fd old_buf
+ else do flushed_buf <- flushWriteBuffer fd is_stream old_buf
writeIORef ref flushed_buf
-- ToDo: should just memcpy instead of writing if possible
writeChunk fd ptr count
let remaining = count - copied
if remaining > 0
then do rest <- readChunk fd (ptr `plusPtr` copied) remaining
- return (rest + count)
+ return (rest + copied)
else return count
readChunk :: FD -> Ptr a -> Int -> IO Int
{-# OPTIONS -fno-implicit-prelude #-}
-- ---------------------------------------------------------------------------
--- $Id: Posix.hsc,v 1.4 2001/12/21 15:07:25 simonmar Exp $
+-- $Id: Posix.hsc,v 1.5 2002/01/02 14:40:11 simonmar Exp $
--
-- POSIX support layer for the standard libraries
--
-- An error when setting O_NONBLOCK isn't fatal: on some systems
-- there are certain file handles on which this will fail (eg. /dev/null
-- on FreeBSD) so we throw away the return code from fcntl_write.
- fcntl_write (fromIntegral fd)
+ c_fcntl_write (fromIntegral fd)
(#const F_SETFL) (flags .|. #const O_NONBLOCK)
#else
-- Stability : experimental
-- Portability : portable
--
--- $Id: Numeric.hs,v 1.2 2001/08/02 13:30:36 simonmar Exp $
+-- $Id: Numeric.hs,v 1.3 2002/01/02 14:40:09 simonmar Exp $
--
-- Odds and ends, mostly functions for reading and showing
-- RealFloat-like kind of values.
readOct, -- :: (Integral a) => ReadS a
readHex, -- :: (Integral a) => ReadS a
-{- -- left out for now, as we can only export the H98 interface
showHex, -- :: Integral a => a -> ShowS
showOct, -- :: Integral a => a -> ShowS
showBin, -- :: Integral a => a -> ShowS
--}
showEFloat, -- :: (RealFloat a) => Maybe Int -> a -> ShowS
showFFloat, -- :: (RealFloat a) => Maybe Int -> a -> ShowS
floatToDigits, -- :: (RealFloat a) => Integer -> a -> ([Int], Int)
lexDigits, -- :: ReadS String
-{- -- left out for now, as we can only export the H98 interface
-- general purpose number->string converter.
showIntAtBase, -- :: Integral a
-- => a -- base
-- -> (a -> Char) -- digit to char
-- -> a -- number to show.
-- -> ShowS
--}
) where
import Prelude -- For dependencies
-- Stability : provisional
-- Portability : portable
--
--- $Id: Environment.hs,v 1.3 2001/12/21 15:07:26 simonmar Exp $
+-- $Id: Environment.hs,v 1.4 2002/01/02 14:40:11 simonmar Exp $
--
-- Miscellaneous information about the system environment.
--
import Foreign
import Foreign.C
+import Control.Monad
#ifdef __GLASGOW_HASKELL__
import GHC.IOBase
/*
- * (c) The University of Glasgow 2001
+ * (c) The University of Glasgow 2002
*
* static versions of the inline functions in HsCore.h
*/
/*
* (c) The GRASP/AQUA Project, Glasgow University, 1998
*
- * $Id: writeError.c,v 1.3 2001/12/21 15:07:26 simonmar Exp $
+ * $Id: writeError.c,v 1.4 2002/01/02 14:40:11 simonmar Exp $
*
* hPutStr Runtime Support
*/
#include "RtsUtils.h"
#include "HsCore.h"
-#include "PrelIOUtils.h"
-
void
writeErrString__(HsAddr msg_hdr, HsAddr msg, HsInt len)
{
/* -----------------------------------------------------------------------------
- * $Id: HsCore.h,v 1.5 2001/12/21 15:07:26 simonmar Exp $
+ * $Id: HsCore.h,v 1.6 2002/01/02 14:40:11 simonmar Exp $
*
* (c) The University of Glasgow 2001-2002
*
#include "config.h"
#include "HsFFI.h"
+#include <stdio.h>
+
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#include "lockFile.h"
#include "dirUtils.h"
#include "errUtils.h"
-#include "PrelIOUtils.h"
#ifdef _WIN32
#include <io.h>
INLINE int __hscore_s_issock(m) { return S_ISSOCK(m); }
#endif
+#ifndef mingw32_TARGET_OS
INLINE void
__hscore_sigemptyset( sigset_t *set )
{ sigemptyset(set); }
+#endif
INLINE void *
__hscore_memcpy_dst_off( char *dst, int dst_off, char *src, size_t sz )
+++ /dev/null
-/*
- * (c) The University of Glasgow 2001-2002
- *
- * IO / Handle support.
- */
-#ifndef __PRELIOUTILS_H__
-#define __PRELIOUTILS_H__
-
-/* PrelIOUtils.c */
-extern HsBool prel_supportsTextMode();
-extern HsInt prel_bufsiz();
-extern HsInt prel_seek_cur();
-extern HsInt prel_seek_set();
-extern HsInt prel_seek_end();
-
-extern HsInt prel_o_binary();
-
-extern HsInt prel_setmode(HsInt fd, HsBool isBin);
-
-extern HsInt prel_PrelHandle_write(HsInt fd, HsBool isSock, HsAddr ptr, HsInt off, int sz);
-extern HsInt prel_PrelHandle_read(HsInt fd, HsBool isSock, HsAddr ptr, HsInt off, int sz);
-
-extern void* prel_PrelIO_memcpy(char *dst, HsInt dst_off, const char *src, size_t sz);
-
-/* writeError.c */
-extern void writeErrString__(HsAddr msg_hdr, HsAddr msg, HsInt len);
-
-extern int s_isreg_PrelPosix_wrap(int);
-extern int s_isdir_PrelPosix_wrap(int);
-extern int s_isfifo_PrelPosix_wrap(int);
-extern int s_isblk_PrelPosix_wrap(int);
-extern int s_ischr_PrelPosix_wrap(int);
-#ifndef mingw32_TARGET_OS
-extern int s_issock_PrelPosix_wrap(int);
-extern void sigemptyset_PrelPosix_wrap(sigset_t *set);
-#endif
-
-
-#endif /* __PRELIOUTILS_H__ */
-
#ifndef __DIRUTILS_H__
#define __DIRUTILS_H__
-#include <sys/stat.h>
-#include <dirent.h>
+#include "HsCore.h"
+
#include <limits.h>
-#include <errno.h>
-#include <unistd.h>
extern HsInt prel_mkdir(HsAddr pathName, HsInt mode);
extern HsInt prel_lstat(HsAddr fname, HsAddr st);