From bb764edad9982764ea6b812530406a779f32127d Mon Sep 17 00:00:00 2001 From: simonmar Date: Tue, 15 Feb 2005 12:15:25 +0000 Subject: [PATCH] [project @ 2005-02-15 12:15:25 by simonmar] ghc -e 'System.Exit.exitWith (System.Exit.ExitFailure 99)' should just exit 99, rather than printing out the exception. Also while I'm here, make all other exceptions cause 'ghc -e' to exit(1), which is probably what we want. --- ghc/compiler/ghci/InteractiveUI.hs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/ghc/compiler/ghci/InteractiveUI.hs b/ghc/compiler/ghci/InteractiveUI.hs index 89fdfeb..f711bd1 100644 --- a/ghc/compiler/ghci/InteractiveUI.hs +++ b/ghc/compiler/ghci/InteractiveUI.hs @@ -1,6 +1,6 @@ {-# 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 -- @@ -58,6 +58,7 @@ import Data.Int ( Int64 ) 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 @@ -246,7 +247,7 @@ runGHCi paths dflags maybe_expr = do interactiveLoop is_tty show_prompt Just expr -> do -- just evaluate the expression we were given - runCommand expr + runCommandEval expr return () -- and finally, exit @@ -356,6 +357,15 @@ readlineLoop = do 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 @@ -399,7 +409,7 @@ runStmt stmt 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 -- 1.7.10.4