-{-# OPTIONS -#include "Linker.h" -#include "SchedAPI.h" #-}
+{-# OPTIONS -#include "Linker.h" #-}
-----------------------------------------------------------------------------
--- $Id: InteractiveUI.hs,v 1.138 2002/12/05 12:36:54 simonmar Exp $
+-- $Id: InteractiveUI.hs,v 1.150 2003/04/12 16:27:24 panne Exp $
--
-- GHC Interactive User Interface
--
import DriverFlags
import DriverState
import DriverUtil ( remove_spaces, handle )
-import Linker ( initLinker, showLinkerState, linkLibraries )
-import Finder ( flushFinderCache )
+import Linker ( initLinker, showLinkerState, linkLibraries,
+ linkPackages )
import Util
-import Id ( isRecordSelector, recordSelectorFieldLabel,
- isDataConWrapId, isDataConId, idName )
+import IdInfo ( GlobalIdDetails(..) )
+import Id ( isImplicitId, idName, globalIdDetails )
import Class ( className )
import TyCon ( tyConName, tyConClass_maybe, isPrimTyCon, DataConDetails(..) )
+import DataCon ( dataConName )
import FieldLabel ( fieldLabelTyCon )
import SrcLoc ( isGoodSrcLoc )
import Module ( showModMsg, lookupModuleEnv )
import Outputable
import CmdLineOpts ( DynFlag(..), DynFlags(..), getDynFlags, saveDynFlags,
restoreDynFlags, dopt_unset )
-import Panic ( GhcException(..), showGhcException )
+import Panic hiding ( showException )
import Config
-#ifndef mingw32_TARGET_OS
+#ifndef mingw32_HOST_OS
import System.Posix
+#if __GLASGOW_HASKELL__ > 504
+ hiding (getEnv)
+#endif
#endif
#if HAVE_READLINE_HEADERS && HAVE_READLINE_LIBS
import GHC.Exts ( unsafeCoerce# )
-import Foreign ( nullPtr )
-import Foreign.C.String ( CString, peekCString, withCString )
import Data.IORef ( IORef, newIORef, readIORef, writeIORef )
-import GHC.Posix ( setNonBlockingFD )
+import System.Posix.Internals ( setNonBlockingFD )
-----------------------------------------------------------------------------
builtin_commands :: [(String, String -> GHCi Bool)]
builtin_commands = [
- ("add", keepGoing addModule),
+ ("add", keepGoingPaths addModule),
("browse", keepGoing browseCmd),
("cd", keepGoing changeDirectory),
("def", keepGoing defineMacro),
("help", keepGoing help),
("?", keepGoing help),
("info", keepGoing info),
- ("load", keepGoing loadModule),
+ ("load", keepGoingPaths loadModule),
("module", keepGoing setContext),
("reload", keepGoing reloadModule),
("set", keepGoing setCmd),
keepGoing :: (String -> GHCi ()) -> (String -> GHCi Bool)
keepGoing a str = a str >> return False
+keepGoingPaths :: ([FilePath] -> GHCi ()) -> (String -> GHCi Bool)
+keepGoingPaths a str = a (toArgs str) >> return False
+
shortHelpText = "use :? for help.\n"
-- NOTE: spaces at the end of each line to workaround CPP/string gap bug.
dflags <- getDynFlags
- -- packages are loaded "on-demand" now
initLinker
+
+ -- link packages requested explicitly on the command-line
+ expl <- readIORef v_ExplicitPackages
+ linkPackages dflags expl
+
+ -- link libraries from the command-line
linkLibraries dflags cmdline_objs
-- Initialise buffering for the *interpreted* I/O system
-- perform a :load for files given on the GHCi command line
when (not (null paths)) $
ghciHandle showException $
- loadModule (unwords paths)
+ loadModule paths
-- enter the interactive loop
-#if defined(mingw32_TARGET_OS)
+#if defined(mingw32_HOST_OS)
-- always show prompt, since hIsTerminalDevice returns True for Consoles
-- only, which we may or may not be running under (cf. Emacs sub-shells.)
interactiveLoop True
checkPerms :: String -> IO Bool
checkPerms name =
-#ifdef mingw32_TARGET_OS
+#ifdef mingw32_HOST_OS
return True
#else
DriverUtil.handle (\_ -> return False) $ do
l <- io (IO.try (hGetLine hdl))
case l of
Left e | isEOFError e -> return ()
- | otherwise -> throw e
+ | otherwise -> io (ioError e)
Right l ->
case remove_spaces l of
"" -> fileLoop hdl prompt
handler :: Exception -> GHCi Bool
handler exception = do
flushInterpBuffers
+ io installSignalHandlers
ghciHandle handler (showException exception >> return False)
showException (DynException dyn) =
when b (mapM_ (showTypeOfName cmstate) names)
flushInterpBuffers
+ io installSignalHandlers
b <- isOptionSet RevertCAFs
io (when b revertCAFs)
return True
showTyThing (AClass cl)
= hcat [ppr cl, text " is a class", showSrcLoc (className cl)]
+ showTyThing (ADataCon dc)
+ = hcat [ppr dc, text " is a data constructor", showSrcLoc (dataConName dc)]
showTyThing (ATyCon ty)
| isPrimTyCon ty
= hcat [ppr ty, text " is a primitive type constructor"]
= hcat [ppr id, text " is a ", idDescr id, showSrcLoc (idName id)]
idDescr id
- | isRecordSelector id =
- case tyConClass_maybe (fieldLabelTyCon (
- recordSelectorFieldLabel id)) of
- Nothing -> text "record selector"
- Just c -> text "method in class " <> ppr c
- | isDataConWrapId id = text "data constructor"
- | otherwise = text "variable"
+ = case globalIdDetails id of
+ RecordSelId lbl -> text "record selector for type" <+> ppr (fieldLabelTyCon lbl)
+ ClassOpId cls -> text "method in class" <+> ppr cls
+ otherwise -> text "variable"
-- also print out the source location for home things
showSrcLoc name
setCmState cms
return ()
-addModule :: String -> GHCi ()
-addModule str = do
- let files = words str
+addModule :: [FilePath] -> GHCi ()
+addModule files = do
state <- getGHCiState
dflags <- io (getDynFlags)
io (revertCAFs) -- always revert CAFs on load/add.
io (writeIORef commands (filter ((/= macro_name) . fst) cmds))
-loadModule :: String -> GHCi ()
-loadModule str = timeIt (loadModule' str)
+loadModule :: [FilePath] -> GHCi ()
+loadModule fs = timeIt (loadModule' fs)
-loadModule' str = do
- let files = words str
+loadModule' :: [FilePath] -> GHCi ()
+loadModule' files = do
state <- getGHCiState
dflags <- io getDynFlags
things' = filter wantToSee things
- wantToSee (AnId id) = not (isDataConId id || isDataConWrapId id)
- wantToSee _ = True
+ wantToSee (AnId id) = not (isImplicitId id)
+ wantToSee (ADataCon _) = False -- They'll come via their TyCon
+ wantToSee _ = True
thing_names = map getName things
mapM_ setOpt plus_opts
-- now, the GHC flags
- pkgs_before <- io (readIORef v_Packages)
+ pkgs_before <- io (readIORef v_ExplicitPackages)
leftovers <- io (processArgs static_flags minus_opts [])
- pkgs_after <- io (readIORef v_Packages)
+ pkgs_after <- io (readIORef v_ExplicitPackages)
-- update things if the users wants more packages
let new_packages = pkgs_after \\ pkgs_before
dflags <- io getDynFlags
cmstate1 <- io (cmUnload (cmstate state) dflags)
setGHCiState state{ cmstate = cmstate1, targets = [] }
+ io (linkPackages dflags new_pkgs)
setContextAfterLoad []
------------------------------------------------------------------------------
+-- ---------------------------------------------------------------------------
-- code for `:show'
showCmd str =