X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=ghc%2Flib%2Fstd%2FPrelMain.lhs;h=d484482242058c44b7561f07729a4af3b1c149ab;hb=ea138284b7343bb1810cfbd0284a608dc57f7d46;hp=05aae478149fe51934b30c34cd5e95e45aaaf967;hpb=6037e956e9b37b1ef2221de04f2dfb72074d1729;p=ghc-hetmet.git diff --git a/ghc/lib/std/PrelMain.lhs b/ghc/lib/std/PrelMain.lhs index 05aae47..d484482 100644 --- a/ghc/lib/std/PrelMain.lhs +++ b/ghc/lib/std/PrelMain.lhs @@ -1,47 +1,22 @@ +% ------------------------------------------------------------------------------ +% $Id: PrelMain.lhs,v 1.9 2001/05/21 14:07:31 simonmar Exp $ % -% (c) The AQUA Project, Glasgow University, 1994-1997 +% (c) The University of Glasgow, 1994-2000 % \section[PrelMain]{Module @PrelMain@} \begin{code} -{-# OPTIONS -#include "cbits/stgio.h" #-} - module PrelMain( mainIO ) where -import Prelude import {-# SOURCE #-} qualified Main -- for type of "Main.main" -import IO ( hFlush, hPutStr, stdout, stderr ) -import PrelAddr ( Addr ) + +import IO import PrelException -import PrelPack ( packString ) -import PrelArr ( ByteArray(..) ) -\end{code} +import PrelTopHandler -\begin{code} mainIO :: IO () -- It must be of type (IO t) because that's what -- the RTS expects. GHC doesn't check this, so -- make sure this type signature stays! -mainIO = catchException Main.main handler - --- make sure we handle errors while reporting the error! --- (e.g. evaluating the string passed to 'error' might generate --- another error, etc.) - -handler :: Exception -> IO () -handler err = catchException (real_handler err) handler - -real_handler :: Exception -> IO () -real_handler ex = - case ex of - ErrorCall s -> reportError s - other -> reportError (showsPrec 0 other "\n") - -reportError :: String -> IO () -reportError str = do - (hFlush stdout) `catchException` (\ _ -> return ()) - let bs@(ByteArray (_,len) _) = packString str - _ccall_ writeErrString__ (``&ErrorHdrHook''::Addr) bs len - _ccall_ stg_exit (1::Int) - +mainIO = catchException Main.main topHandler \end{code}