[project @ 2003-07-29 16:31:39 by igloo]
[ghc-hetmet.git] / ghc / compiler / ghci / InteractiveUI.hs
index d2d19be..5c014be 100644 (file)
@@ -1,6 +1,6 @@
 {-# OPTIONS -#include "Linker.h" #-}
 -----------------------------------------------------------------------------
--- $Id: InteractiveUI.hs,v 1.153 2003/05/19 15:39:17 simonpj Exp $
+-- $Id: InteractiveUI.hs,v 1.157 2003/07/21 14:33:19 simonmar Exp $
 --
 -- GHC Interactive User Interface
 --
@@ -22,7 +22,7 @@ import HsSyn          ( TyClDecl(..), ConDecl(..), Sig(..) )
 import MkIface         ( ifaceTyThing )
 import DriverFlags
 import DriverState
-import DriverUtil      ( remove_spaces, handle )
+import DriverUtil      ( remove_spaces )
 import Linker          ( showLinkerState, linkPackages )
 import Util
 import IdInfo          ( GlobalIdDetails(..) )
@@ -45,6 +45,7 @@ import Panic          hiding ( showException )
 import Config
 
 #ifndef mingw32_HOST_OS
+import DriverUtil( handle )
 import System.Posix
 #if __GLASGOW_HASKELL__ > 504
        hiding (getEnv)
@@ -157,8 +158,7 @@ helpText = "\
 interactiveUI :: [FilePath] -> IO ()
 interactiveUI srcs = do
    dflags <- getDynFlags
-   saveDynFlags        -- Save the dynamic flags, so that 
-                       -- the later restore will find them
+
    cmstate <- cmInit Interactive;
 
    hFlush stdout
@@ -542,6 +542,14 @@ addModule files = do
 
 changeDirectory :: String -> GHCi ()
 changeDirectory dir = do
+  state    <- getGHCiState
+  when (targets state /= []) $
+       io $ putStr "Warning: changing directory causes all loaded modules to be unloaded, \n\ 
+       \because the search path has changed.\n"
+  dflags   <- io getDynFlags
+  cmstate1 <- io (cmUnload (cmstate state) dflags)
+  setGHCiState state{ cmstate = cmstate1, targets = [] }
+  setContextAfterLoad []
   dir <- expandPath dir
   io (setCurrentDirectory dir)