[project @ 2003-09-11 00:58:02 by sof]
[ghc-hetmet.git] / ghc / compiler / main / Main.hs
index 1fed643..5c66a92 100644 (file)
@@ -1,7 +1,7 @@
 {-# 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
 --
@@ -97,7 +97,7 @@ main =
           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"
@@ -142,11 +142,11 @@ main =
        -- -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.")
 
@@ -177,6 +177,7 @@ main =
    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 
@@ -187,7 +188,9 @@ main =
                           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"
@@ -255,9 +258,13 @@ main =
                                    (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
 
 -- -----------------------------------------------------------------------------
@@ -266,10 +273,14 @@ main =
 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
 
@@ -281,17 +292,16 @@ checkOptions mode srcs objs = 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.
@@ -318,7 +328,7 @@ compileFile mode stop_flag src = do
          | 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-}
 
 
 -- ----------------------------------------------------------------------------