{-# OPTIONS -#include "Linker.h" #-}
-----------------------------------------------------------------------------
--- $Id: InteractiveUI.hs,v 1.187 2005/02/04 13:32:28 simonmar Exp $
+-- $Id: InteractiveUI.hs,v 1.188 2005/02/15 12:15:25 simonmar Exp $
--
-- GHC Interactive User Interface
--
import System.Cmd
import System.CPUTime
import System.Environment
+import System.Exit ( exitWith, ExitCode(..) )
import System.Directory
import System.IO
import System.IO.Error as IO
interactiveLoop is_tty show_prompt
Just expr -> do
-- just evaluate the expression we were given
- runCommand expr
+ runCommandEval expr
return ()
-- and finally, exit
runCommand :: String -> GHCi Bool
runCommand c = ghciHandle handler (doCommand c)
+-- 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 c = ghciHandle handleEval (doCommand c)
+ where
+ handleEval (ExitException code) = io (exitWith code)
+ handleEval e = do showException e
+ io (exitWith (ExitFailure 1))
+
-- This is the exception handler for exceptions generated by the
-- user's code; it normally just prints out the exception. The
-- handler must be recursive, in case showing the exception causes
setGHCiState st{cmstate = new_cmstate}
case result of
CmRunFailed -> return []
- CmRunException e -> showException e >> return []
+ CmRunException e -> throw e -- this is caught by runCommand(Eval)
CmRunOk names -> return names
-- possibly print the type and revert CAFs after evaluating an expression