return ""
#endif
-interactiveUI :: Session -> [(FilePath, Maybe Phase)] -> Maybe String -> IO ()
-interactiveUI session srcs maybe_expr = do
+interactiveUI :: Session -> [(FilePath, Maybe Phase)] -> Maybe [String]
+ -> IO ()
+interactiveUI session srcs maybe_exprs = do
-- HACK! If we happen to get into an infinite loop (eg the user
-- types 'let x=x in x' at the prompt), then the thread will block
-- on a blackhole, and become unreachable during GC. The GC will
-- Initialise buffering for the *interpreted* I/O system
initInterpBuffering session
- when (isNothing maybe_expr) $ do
+ when (isNothing maybe_exprs) $ do
-- Only for GHCi (not runghc and ghc -e):
-- Turn buffering off for the compiled program's stdout/stderr
default_editor <- findEditor
- startGHCi (runGHCi srcs maybe_expr)
+ startGHCi (runGHCi srcs maybe_exprs)
GHCiState{ progname = "<interactive>",
args = [],
prompt = "%s> ",
return ()
-runGHCi :: [(FilePath, Maybe Phase)] -> Maybe String -> GHCi ()
-runGHCi paths maybe_expr = do
+runGHCi :: [(FilePath, Maybe Phase)] -> Maybe [String] -> GHCi ()
+runGHCi paths maybe_exprs = do
let read_dot_files = not opt_IgnoreDotGhci
when (read_dot_files) $ do
when (not (null paths)) $ do
ok <- ghciHandle (\e -> do showException e; return Failed) $
loadModule paths
- when (isJust maybe_expr && failed ok) $
+ when (isJust maybe_exprs && failed ok) $
io (exitWith (ExitFailure 1))
-- if verbosity is greater than 0, or we are connected to a
dflags <- getDynFlags
let show_prompt = verbosity dflags > 0 || is_tty
- case maybe_expr of
+ case maybe_exprs of
Nothing ->
do
#if defined(mingw32_HOST_OS)
#endif
-- enter the interactive loop
interactiveLoop is_tty show_prompt
- Just expr -> do
+ Just exprs -> do
-- just evaluate the expression we were given
- runCommandEval expr
- return ()
+ enqueueCommands exprs
+ let handleEval (ExitException code) = io (exitWith code)
+ handleEval e = handler e
+ runCommands' handleEval (return Nothing)
-- and finally, exit
io $ do when (verbosity dflags > 0) $ putStrLn "Leaving GHCi."
return (Just c)
runCommands :: GHCi (Maybe String) -> GHCi ()
-runCommands getCmd = do
+runCommands = runCommands' handler
+
+runCommands' :: (Exception -> GHCi Bool) -- Exception handler
+ -> GHCi (Maybe String) -> GHCi ()
+runCommands' eh getCmd = do
mb_cmd <- noSpace queryQueue
mb_cmd <- maybe (noSpace getCmd) (return . Just) mb_cmd
case mb_cmd of
Nothing -> return ()
Just c -> do
- b <- ghciHandle handler (doCommand c)
- if b then return () else runCommands getCmd
+ b <- ghciHandle eh (doCommand c)
+ if b then return () else runCommands' eh getCmd
where
noSpace q = q >>= maybe (return Nothing)
(\c->case removeSpaces c of
setGHCiState st{ cmdqueue = cmds ++ cmdqueue st }
--- This version is for the GHC command-line option -e. The only difference
--- from runCommand is that it catches the ExitException exception and
--- exits, rather than printing out the exception.
-runCommandEval :: String -> GHCi Bool
-runCommandEval c = ghciHandle handleEval (doCommand c)
- where
- handleEval (ExitException code) = io (exitWith code)
- handleEval e = do handler e
- io (exitWith (ExitFailure 1))
-
- doCommand (':' : command) = specialCommand command
- doCommand stmt
- = do r <- runStmt stmt GHC.RunToCompletion
- case r of
- False -> io (exitWith (ExitFailure 1))
- -- failure to run the command causes exit(1) for ghc -e.
- _ -> return True
-
runStmt :: String -> SingleStep -> GHCi Bool
runStmt stmt step
| null (filter (not.isSpace) stmt) = return False