Minor refactoring in RtClosureInspect
[ghc-hetmet.git] / compiler / ghci / GhciMonad.hs
index 9202ddf..f7c5c01 100644 (file)
@@ -1,3 +1,6 @@
+{-# OPTIONS -fno-cse #-}
+-- -fno-cse is needed for GLOBAL_VAR's to behave properly
+
 -----------------------------------------------------------------------------
 --
 -- Monadery code used in InteractiveUI
@@ -20,17 +23,16 @@ import HscTypes
 import SrcLoc
 import Module
 import ObjLink
+import Linker
 import StaticFlags
 
 import Data.Maybe
 import Numeric
-import Control.Exception as Exception
 import Data.Array
 import Data.Char
 import Data.Int         ( Int64 )
 import Data.IORef
 import Data.List
-import Data.Typeable
 import System.CPUTime
 import System.Directory
 import System.Environment
@@ -66,7 +68,7 @@ data GHCiState = GHCiState
         remembered_ctx :: [(CtxtCmd, [String], [String])],
              -- we remember the :module commands between :loads, so that
              -- on a :reload we can replay them.  See bugs #2049,
-             -- #1873, #1360. Previously we tried to remember modules that
+             -- \#1873, #1360. Previously we tried to remember modules that
              -- were supposed to be in the context but currently had errors,
              -- but this was complicated.  Just replaying the :module commands
              -- seems to be the right thing.
@@ -136,9 +138,9 @@ instance Monad GHCi where
 instance Functor GHCi where
     fmap f m = m >>= return . f
 
-ghciHandleDyn :: Typeable t => (t -> GHCi a) -> GHCi a -> GHCi a
-ghciHandleDyn h (GHCi m) = GHCi $ \s -> 
-   Exception.catchDyn (m s) (\e -> unGHCi (h e) s)
+ghciHandleGhcException :: (GhcException -> GHCi a) -> GHCi a -> GHCi a
+ghciHandleGhcException h (GHCi m) = GHCi $ \s -> 
+   handleGhcException (\e -> unGHCi (h e) s) (m s)
 
 getGHCiState :: GHCi GHCiState
 getGHCiState   = GHCi $ \r -> readIORef r
@@ -190,7 +192,7 @@ unsetOption opt
       setGHCiState (st{ options = filter (/= opt) (options st) })
 
 io :: IO a -> GHCi a
-io m = GHCi { unGHCi = \_ -> m >>= return }
+io m = GHCi (\_ -> m)
 
 printForUser :: SDoc -> GHCi ()
 printForUser doc = do
@@ -295,11 +297,8 @@ GLOBAL_VAR(stderr_ptr, error "no stderr_ptr", Ptr ())
 initInterpBuffering :: GHC.Session -> IO ()
 initInterpBuffering session
  = do -- make sure these are linked
-      mb_hval1 <- GHC.compileExpr session "System.IO.stdout"
-      mb_hval2 <- GHC.compileExpr session "System.IO.stderr"
-      mb_hval3 <- GHC.compileExpr session "System.IO.stdin"
-      when (any isNothing [mb_hval1,mb_hval2,mb_hval3]) $
-        panic "interactiveUI:setBuffering"
+      dflags <- GHC.getSessionDynFlags session
+      initDynLinker dflags
 
         -- ToDo: we should really look up these names properly, but
         -- it's a fiddle and not all the bits are exposed via the GHC