-----------------------------------------------------------------------------
--- $Id: InteractiveUI.hs,v 1.11 2000/11/22 10:56:53 simonmar Exp $
+-- $Id: InteractiveUI.hs,v 1.14 2000/11/22 17:51:16 simonmar Exp $
--
-- GHC Interactive User Interface
--
import Linker
import Module
import Outputable
-import Panic
import Util
import Exception
\ :load <filename> load a module (and it dependents)\n\
\ :module <mod> set the context for expression evaluation to <mod>\n\
\ :reload reload the current module set\n\
-\ :set <opetion> ... set options\n\
+\ :set <option> ... set options\n\
\ :type <expr> show the type of <expr>\n\
\ :quit exit GHCi\n\
\ :!<command> run the shell command <command>\n\
\"
-interactiveUI :: CmState -> IO ()
-interactiveUI st = do
+interactiveUI :: CmState -> [ModuleName] -> IO ()
+interactiveUI st mods = do
hPutStrLn stdout ghciWelcomeMsg
hFlush stdout
hSetBuffering stdout NoBuffering
#ifndef NO_READLINE
Readline.initialize
#endif
- _ <- (unGHCi uiLoop) GHCiState{ modules = [],
- current_module = defaultCurrentModule,
- target = Nothing,
- cmstate = st }
+ let this_mod = case mods of
+ [] -> defaultCurrentModule
+ m:ms -> m
+
+ (unGHCi uiLoop) GHCiState{ modules = mods,
+ current_module = this_mod,
+ target = Nothing,
+ cmstate = st }
return ()
uiLoop :: GHCi ()
specialCommand str = do
let (cmd,rest) = break isSpace str
case [ (s,f) | (s,f) <- commands, prefixMatch cmd s ] of
- [] -> io $ hPutStr stdout ("uknown command `:" ++ cmd ++ "'\n"
+ [] -> io $ hPutStr stdout ("unknown command `:" ++ cmd ++ "'\n"
++ shortHelpText)
[(_,f)] -> f (dropWhile isSpace rest)
cs -> io $ hPutStrLn stdout ("prefix " ++ cmd ++
loadModule :: String -> GHCi ()
loadModule path = do
state <- getGHCiState
- (new_cmstate, ok, mods) <- io (cmLoadModule (cmstate state) path)
+ cmstate1 <- io (cmUnload (cmstate state))
+ (cmstate2, ok, mods) <- io (cmLoadModule cmstate1 path)
let new_state = GHCiState {
- cmstate = new_cmstate,
+ cmstate = cmstate2,
modules = mods,
current_module = case mods of
[] -> defaultCurrentModule
state <- getGHCiState
case target state of
Nothing -> io (putStr "no current target\n")
- Just path -> do (new_cmstate, ok, mod)
- <- io (cmLoadModule (cmstate state) path)
- setGHCiState state{cmstate=new_cmstate}
+ Just path
+ -> do (new_cmstate, ok, mod) <- io (cmLoadModule (cmstate state) path)
+ setGHCiState state{cmstate=new_cmstate}
reloadModule _ = noArgs ":reload"
-- set options in the interpreter. Syntax is exactly the same as the