{-# OPTIONS -fno-warn-incomplete-patterns -optc-DNON_POSIX_SOURCE #-}
-----------------------------------------------------------------------------
--- $Id: Main.hs,v 1.128 2003/06/27 18:28:33 sof Exp $
+-- $Id: Main.hs,v 1.132 2003/09/04 11:08:47 simonmar Exp $
--
-- GHC Driver program
--
hFlush stdout
case exception of
-- an IO exception probably isn't our fault, so don't panic
- IOException _ -> hPutStr stderr (show exception)
+ IOException _ -> hPutStrLn stderr (show exception)
AsyncException StackOverflow ->
hPutStrLn stderr "stack overflow: use +RTS -K<size> \
\to increase it"
-- -O and --interactive are not a good combination
-- ditto with any kind of way selection
orig_opt_level <- readIORef v_OptLevel
- when (orig_opt_level > 0 && mode == DoInteractive) $
+ when (orig_opt_level > 0 && isInteractive mode) $
do putStr "warning: -O conflicts with --interactive; -O turned off.\n"
writeIORef v_OptLevel 0
orig_ways <- readIORef v_Ways
- when (notNull orig_ways && mode == DoInteractive) $
+ when (notNull orig_ways && isInteractive mode) $
do throwDyn (UsageError
"--interactive can't be used with -prof, -ticky, -unreg or -smp.")
build_tag <- readIORef v_Build_tag
let lang = case mode of
DoInteractive -> HscInterpreted
+ DoEval _ -> HscInterpreted
_other | build_tag /= "" -> HscC
| otherwise -> hscLang dyn_flags
-- for ways other that the normal way, we must
hscLang = lang,
-- leave out hscOutName for now
hscOutName = panic "Main.main:hscOutName not set",
- verbosity = 1
+ verbosity = case mode of
+ DoEval _ -> 0
+ _other -> 1
})
-- The rest of the arguments are "dynamic"
(staticLink o_files def_hs_pkgs) }
#ifndef GHCI
- DoInteractive -> throwDyn (CmdLineError "not built for interactive use")
+ DoInteractive -> noInteractiveError
+ DoEval _ -> noInteractiveError
+ where
+ noInteractiveError = throwDyn (CmdLineError "not built for interactive use")
#else
- DoInteractive -> interactiveUI srcs
+ DoInteractive -> interactiveUI srcs Nothing
+ DoEval expr -> interactiveUI srcs (Just expr)
#endif
-- -----------------------------------------------------------------------------
checkOptions :: GhcMode -> [String] -> [String] -> IO ()
-- Final sanity checking before kicking off a compilation (pipeline).
checkOptions mode srcs objs = do
+ -- Complain about any unknown flags
+ let unknown_opts = [ f | f@('-':_) <- srcs ]
+ when (notNull unknown_opts) (unknownFlagsErr unknown_opts)
+
-- -ohi sanity check
ohi <- readIORef v_Output_hi
if (isJust ohi &&
- (mode == DoMake || mode == DoInteractive || srcs `lengthExceeds` 1))
+ (mode == DoMake || isInteractive mode || srcs `lengthExceeds` 1))
then throwDyn (UsageError "-ohi can only be used when compiling a single source file")
else do
-- Check that there are some input files (except in the interactive
-- case)
- if null srcs && null objs && mode /= DoInteractive
+ if null srcs && null objs && not (isInteractive mode)
then throwDyn (UsageError "no input files")
else do
- -- Complain about any unknown flags
- let unknown_opts = [ f | f@('-':_) <- srcs ]
- when (notNull unknown_opts) (unknownFlagsErr unknown_opts)
-
-- Verify that output files point somewhere sensible.
verifyOutputFiles
+isInteractive DoInteractive = True
+isInteractive (DoEval _) = True
+isInteractive _ = False
-- -----------------------------------------------------------------------------
-- Compile files in one-shot mode.
| mode==DoLink || mode==DoMkDLL = Nothing
| otherwise = o_file
- runPipeline mode stop_flag True maybe_o_file src
+ runPipeline mode stop_flag True maybe_o_file src Nothing{-no ModLocation-}
-- ----------------------------------------------------------------------------