{-# OPTIONS -#include "Linker.h" -#include "SchedAPI.h" #-}
-----------------------------------------------------------------------------
--- $Id: InteractiveUI.hs,v 1.112 2002/01/28 13:34:10 simonmar Exp $
+-- $Id: InteractiveUI.hs,v 1.121 2002/04/24 09:42:18 simonmar Exp $
--
-- GHC Interactive User Interface
--
import Id ( isRecordSelector, recordSelectorFieldLabel,
isDataConWrapId, isDataConId, idName )
import Class ( className )
-import TyCon ( tyConName, tyConClass_maybe, isPrimTyCon )
+import TyCon ( tyConName, tyConClass_maybe, isPrimTyCon, DataConDetails(..) )
import FieldLabel ( fieldLabelTyCon )
import SrcLoc ( isGoodSrcLoc )
import Module ( moduleName )
import Char
import Monad
-import PrelGHC ( unsafeCoerce# )
+import GlaExts ( unsafeCoerce# )
+
import Foreign ( nullPtr )
import CString ( peekCString )
shortHelpText = "use :? for help.\n"
+-- NOTE: spaces at the end of each line to workaround CPP/string gap bug.
helpText = "\
\ Commands available from the prompt:\n\
-\\
-\ <stmt> evaluate/run <stmt>\n\
-\ :add <filename> ... add module(s) to the current target set\n\
-\ :browse [*]<module> display the names defined by <module>\n\
-\ :cd <dir> change directory to <dir>\n\
-\ :def <cmd> <expr> define a command :<cmd>\n\
-\ :help, :? display this list of commands\n\
-\ :info [<name> ...] display information about the given names\n\
-\ :load <filename> ... load module(s) and their dependents\n\
-\ :module <mod> set the context for expression evaluation to <mod>\n\
-\ :reload reload the current module set\n\
\\n\
-\ :set <option> ... set options\n\
-\ :set args <arg> ... set the arguments returned by System.getArgs\n\
-\ :set prog <progname> set the value returned by System.getProgName\n\
+\ <stmt> evaluate/run <stmt>\n\
+\ :add <filename> ... add module(s) to the current target set\n\
+\ :browse [*]<module> display the names defined by <module>\n\
+\ :cd <dir> change directory to <dir>\n\
+\ :def <cmd> <expr> define a command :<cmd>\n\
+\ :help, :? display this list of commands\n\
+\ :info [<name> ...] display information about the given names\n\
+\ :load <filename> ... load module(s) and their dependents\n\
+\ :module [+/-] [*]<mod> ... set the context for expression evaluation\n\
+\ :reload reload the current module set\n\
+\\n\
+\ :set <option> ... set options\n\
+\ :set args <arg> ... set the arguments returned by System.getArgs\n\
+\ :set prog <progname> set the value returned by System.getProgName\n\
+\\n\
+\ :show modules show the currently loaded modules\n\
+\ :show bindings show the current bindings made at the prompt\n\
\\n\
-\ :show modules show the currently loaded modules\n\
-\ :show bindings show the current bindings made at the prompt\n\
+\ :type <expr> show the type of <expr>\n\
+\ :undef <cmd> undefine user-defined command :<cmd>\n\
+\ :unset <option> ... unset options\n\
+\ :quit exit GHCi\n\
+\ :!<command> run the shell command <command>\n\
\\n\
-\ :type <expr> show the type of <expr>\n\
-\ :undef <cmd> undefine user-defined command :<cmd>\n\
-\ :unset <option> ... unset options\n\
-\ :quit exit GHCi\n\
-\ :!<command> run the shell command <command>\n\
-\\
\ Options for `:set' and `:unset':\n\
-\\
+\\n\
\ +r revert top-level expressions after each evaluation\n\
\ +s print timing/memory stats after each evaluation\n\
\ +t print type after evaluation\n\
_ -> panic "interactiveUI:buffering"
(cmstate, maybe_hval)
- <- cmCompileExpr cmstate dflags "IO.hFlush PrelHandle.stderr"
+ <- cmCompileExpr cmstate dflags "IO.hFlush IO.stderr"
case maybe_hval of
Just hval -> writeIORef flush_stderr (unsafeCoerce# hval :: IO ())
_ -> panic "interactiveUI:stderr"
(cmstate, maybe_hval)
- <- cmCompileExpr cmstate dflags "IO.hFlush PrelHandle.stdout"
+ <- cmCompileExpr cmstate dflags "IO.hFlush IO.stdout"
case maybe_hval of
Just hval -> writeIORef flush_stdout (unsafeCoerce# hval :: IO ())
_ -> panic "interactiveUI:stdout"
checkPerms :: String -> IO Bool
checkPerms name =
- handle (\_ -> return False) $ do
#ifdef mingw32_TARGET_OS
- doesFileExist name
+ return True
#else
+ DriverUtil.handle (\_ -> return False) $ do
st <- getFileStatus name
me <- getRealUserID
if fileOwner st /= me then do
if quit then return () else stringLoop ss
mkPrompt toplevs exports
- = concat (intersperse " " (toplevs ++ map ('*':) exports)) ++ "> "
+ = concat (intersperse " " (map ('*':) toplevs ++ exports)) ++ "> "
#if HAVE_READLINE_HEADERS && HAVE_READLINE_LIBS
readlineLoop :: GHCi ()
setContextAfterLoad (m:_) = do
cmstate <- getCmState
b <- io (cmModuleIsInterpreted cmstate m)
- if b then setContext m else setContext ('*':m)
+ if b then setContext ('*':m) else setContext m
modulesLoadedMsg ok mods dflags =
when (verbosity dflags > 0) $ do
| otherwise = hsep (
punctuate comma (map text mods)) <> text "."
case ok of
- False ->
+ False ->
io (putStrLn (showSDoc (text "Failed, modules loaded: " <> mod_commas)))
- True ->
+ True ->
io (putStrLn (showSDoc (text "Ok, modules loaded: " <> mod_commas)))
browseCmd :: String -> GHCi ()
browseCmd m =
case words m of
- ['*':m] | looksLikeModuleName m -> browseModule m True
- [m] | looksLikeModuleName m -> browseModule m False
+ ['*':m] | looksLikeModuleName m -> browseModule m False
+ [m] | looksLikeModuleName m -> browseModule m True
_ -> throwDyn (CmdLineError "syntax: :browse <module>")
browseModule m exports_only = do
thingDecl thing@(ATyCon t) =
let rn_decl = ifaceTyThing thing in
case rn_decl of
- TyData { tcdCons = cons } ->
- rn_decl{ tcdCons = filter conIsVisible cons }
+ TyData { tcdCons = DataCons cons } ->
+ rn_decl{ tcdCons = DataCons (filter conIsVisible cons) }
other -> other
where
conIsVisible (ConDecl n _ _ _ _ _) = n `elem` thing_names
setCmState cms'
separate cmstate [] as bs = return (as,bs)
-separate cmstate (('*':m):ms) as bs = separate cmstate ms as (m:bs)
-separate cmstate (m:ms) as bs = do
+separate cmstate (('*':m):ms) as bs = do
b <- io (cmModuleIsInterpreted cmstate m)
if b then separate cmstate ms (m:as) bs
else throwDyn (CmdLineError ("module `" ++ m ++ "' is not interpreted"))
-
+separate cmstate (m:ms) as bs = separate cmstate ms as (m:bs)
+
prel = "Prelude"
-- Packages that don't need loading, because the compiler shares them with
-- the interpreted program.
-dont_load_these = [ "gmp", "rts" ]
+dont_load_these = [ "rts" ]
-- Packages that are already linked into GHCi. For mingw32, we only
-- skip gmp and rts, since std and after need to load the msvcrt.dll
looksLikeModuleName [] = False
looksLikeModuleName (c:cs) = isUpper c && all isAlphaNumEx cs
-isAlphaNumEx c = isAlphaNum c || c == '_'
+isAlphaNumEx c = isAlphaNum c || c == '_' || c == '.'
maybePutStr dflags s | verbosity dflags > 0 = putStr s
| otherwise = return ()