make GhcProfiled work, and add a "prof" flavour to build.mk
[ghc-hetmet.git] / ghc / InteractiveUI.hs
index d620290..0e9efb6 100644 (file)
@@ -55,6 +55,11 @@ import Maybes                ( orElse, expectJust )
 import FastString
 import Encoding
 
+#if __GLASGOW_HASKELL__ < 611
+import Foreign.C
+import Encoding
+#endif
+
 #ifndef mingw32_HOST_OS
 import System.Posix hiding (getEnv)
 #else
@@ -88,7 +93,14 @@ import Control.Monad as Monad
 import Text.Printf
 import Foreign
 import GHC.Exts                ( unsafeCoerce# )
+
+#if __GLASGOW_HASKELL__ >= 611
+import GHC.IO.Exception        ( IOErrorType(InvalidArgument) )
+import GHC.IO.Handle    ( hFlushAll )
+#else
 import GHC.IOBase      ( IOErrorType(InvalidArgument) )
+#endif
+
 import GHC.TopHandler
 
 import Data.IORef      ( IORef, readIORef, writeIORef )
@@ -501,7 +513,7 @@ fileLoop hdl = do
                 -- this can happen if the user closed stdin, or
                 -- perhaps did getContents which closes stdin at
                 -- EOF.
-        Right l -> fmap Just (Encoding.decode (BS.pack l))
+        Right l -> return (Just l)
 
 mkPrompt :: GHCi String
 mkPrompt = do
@@ -625,7 +637,16 @@ runStmt stmt step
  | null (filter (not.isSpace) stmt) = return False
  | ["import", mod] <- words stmt    = keepGoing' setContext ('+':mod)
  | otherwise
- = do result <- GhciMonad.runStmt stmt step
+ = do
+#if __GLASGOW_HASKELL__ >= 611
+      -- In the new IO library, read handles buffer data even if the Handle
+      -- is set to NoBuffering.  This causes problems for GHCi where there
+      -- are really two stdin Handles.  So we flush any bufferred data in
+      -- GHCi's stdin Handle here (only relevant if stdin is attached to
+      -- a file, otherwise the read buffer can't be flushed).
+      liftIO $ IO.try $ hFlushAll stdin
+#endif
+      result <- GhciMonad.runStmt stmt step
       afterRunStmt (const True) result
 
 --afterRunStmt :: GHC.RunResult -> GHCi Bool