#include "HsVersions.h"
-import GhciMonad
+import qualified GhciMonad
+import GhciMonad hiding (runStmt)
import GhciTags
import Debugger
-- The GHC interface
-import qualified GHC
+import qualified GHC hiding (resume, runStmt)
import GHC ( Session, LoadHowMuch(..), Target(..), TargetId(..),
Module, ModuleName, TyThing(..), Phase,
BreakIndex, SrcSpan, Resume, SingleStep )
import DynFlags
import Packages
-#ifdef USE_READLINE
+#ifdef USE_EDITLINE
import PackageConfig
import UniqFM
#endif
import SrcLoc
-- Other random utilities
+import ErrUtils
import Digraph
import BasicTypes hiding (isTopLevel)
import Panic hiding (showException)
import qualified System.Win32
#endif
-#ifdef USE_READLINE
+#ifdef USE_EDITLINE
import Control.Concurrent ( yield ) -- Used in readline loop
-import System.Console.Readline as Readline
+import System.Console.Editline.Readline as Readline
#endif
--import SystemExts
import Data.IORef ( IORef, readIORef, writeIORef )
-#ifdef USE_READLINE
+#ifdef USE_EDITLINE
import System.Posix.Internals ( setNonBlockingFD )
#endif
cmdName :: Command -> String
cmdName (n,_,_,_) = n
-macros_ref :: IORef [Command]
GLOBAL_VAR(macros_ref, [], [Command])
builtin_commands :: [Command]
--
-- NOTE: in order for us to override the default correctly, any custom entry
-- must be a SUBSET of word_break_chars.
-#ifdef USE_READLINE
+#ifdef USE_EDITLINE
word_break_chars :: String
word_break_chars = let symbols = "!#$%&*+/<=>?@\\^|-~"
specials = "(),;[]`{}"
" :force <expr> print <expr>, forcing unevaluated parts\n" ++
" :forward go forward in the history (after :back)\n" ++
" :history [<n>] after :trace, show the execution history\n" ++
+ " :list show the source code around current breakpoint\n" ++
+ " :list identifier show the source code for <identifier>\n" ++
+ " :list [<module>] <line> show the source code around line number <line>\n" ++
" :print [<name> ...] prints a value without forcing its computation\n" ++
" :sprint [<name> ...] simplifed version of :print\n" ++
" :step single-step after stopping at a breakpoint\n"++
-- intended for the program, so unbuffer stdin.
hSetBuffering stdin NoBuffering
-#ifdef USE_READLINE
+#ifdef USE_EDITLINE
is_tty <- hIsTerminalDevice stdin
when is_tty $ do
Readline.initialize
default_editor <- findEditor
+ cwd <- getCurrentDirectory
+
startGHCi (runGHCi srcs maybe_exprs)
GHCiState{ progname = "<interactive>",
args = [],
tickarrays = emptyModuleEnv,
last_command = Nothing,
cmdqueue = [],
- remembered_ctx = []
+ remembered_ctx = [],
+ virtual_path = cwd,
+ ghc_e = isJust maybe_exprs
}
-#ifdef USE_READLINE
+#ifdef USE_EDITLINE
Readline.stifleHistory 100
withGhcAppData (\dir -> Readline.writeHistory (dir </> "ghci_history"))
(return True)
-- current progname in the exception text:
-- <progname>: <exception>
io $ withProgName (progname st)
- -- The "fast exit" part just calls exit()
- -- directly instead of doing an orderly
- -- runtime shutdown, otherwise the main
- -- GHCi thread will complain about being
- -- interrupted.
- $ topHandlerFastExit e
+ -- this used to be topHandlerFastExit, see #2228
+ $ topHandler e
runCommands' handle (return Nothing)
-- and finally, exit
-- exception handler above.
-- read commands from stdin
-#ifdef USE_READLINE
+#ifdef USE_EDITLINE
if (is_tty)
then runCommands readlineLoop
else runCommands (fileLoop stdin show_prompt is_tty)
return (showSDoc (f (prompt st)))
-#ifdef USE_READLINE
+#ifdef USE_EDITLINE
readlineLoop :: GHCi (Maybe String)
readlineLoop = do
io yield
| null (filter (not.isSpace) stmt) = return False
| ["import", mod] <- words stmt = keepGoing setContext ('+':mod)
| otherwise
- = do st <- getGHCiState
- session <- getSession
- result <- io $ withProgName (progname st) $ withArgs (args st) $
- GHC.runStmt session stmt step
+ = do result <- GhciMonad.runStmt stmt step
afterRunStmt (const True) result
-
--afterRunStmt :: GHC.RunResult -> GHCi Bool
-- False <=> the statement failed to compile
afterRunStmt :: (SrcSpan -> Bool) -> GHC.RunResult -> GHCi Bool
GHC.RunBreak _ names mb_info
| isNothing mb_info ||
step_here (GHC.resumeSpan $ head resumes) -> do
- printForUser $ ptext SLIT("Stopped at") <+>
+ printForUser $ ptext (sLit "Stopped at") <+>
ppr (GHC.resumeSpan $ head resumes)
-- printTypeOfNames session names
let namesSorted = sortBy compareNames names
st <- getGHCiState
enqueueCommands [stop st]
return ()
- | otherwise -> io(GHC.resume session GHC.SingleStep) >>=
+ | otherwise -> resume GHC.SingleStep >>=
afterRunStmt step_here >> return ()
_ -> return ()
flushInterpBuffers
io installSignalHandlers
b <- isOptionSet RevertCAFs
- io (when b revertCAFs)
+ when b revertCAFs
return (case run_result of GHC.RunOk _ -> True; _ -> False)
addModule :: [FilePath] -> GHCi ()
addModule files = do
- io (revertCAFs) -- always revert CAFs on load/add.
+ revertCAFs -- always revert CAFs on load/add.
files <- mapM expandPath files
targets <- mapM (\m -> io (GHC.guessTarget m Nothing)) files
session <- getSession
afterLoad :: SuccessFlag -> Session -> Bool -> ([Module],[Module]) -> GHCi ()
afterLoad ok session retain_context prev_context = do
- io (revertCAFs) -- always revert CAFs on load.
+ revertCAFs -- always revert CAFs on load.
discardTickArrays
loaded_mod_summaries <- getLoadedModules session
let loaded_mods = map GHC.ms_mod loaded_mod_summaries
vcat (text "other dynamic, non-language, flag settings:"
:map (flagSetting dflags) nonLanguageDynFlags)
))
- where flagSetting dflags (str,f)
+ where flagSetting dflags (str, f, _)
| dopt f dflags = text " " <> text "-f" <> text str
| otherwise = text " " <> text "-fno-" <> text str
- (ghciFlags,others) = partition (\(_,f)->f `elem` flags)
+ (ghciFlags,others) = partition (\(_, f, _) -> f `elem` flags)
DynFlags.fFlags
- nonLanguageDynFlags = filter (\(_,f)->not $ f `elem` map snd xFlags)
- others
+ nonLanguageDynFlags = filterOut (\(_, f, _) -> f `elem` languageOptions)
+ others
flags = [Opt_PrintExplicitForalls
,Opt_PrintBindResult
,Opt_BreakOnException
newDynFlags minus_opts = do
dflags <- getDynFlags
let pkg_flags = packageFlags dflags
- (dflags',leftovers) <- io $ GHC.parseDynamicFlags dflags minus_opts
+ (dflags', leftovers, warns) <- io $ GHC.parseDynamicFlags dflags minus_opts
+ io $ handleFlagWarnings dflags' warns
if (not (null leftovers))
then throwDyn (CmdLineError ("unrecognised flags: " ++
printForUser $ vcat (map pp_resume (reverse resumes))
where
pp_resume resume =
- ptext SLIT("--> ") <> text (GHC.resumeStmt resume)
- $$ nest 2 (ptext SLIT("Stopped at") <+> ppr (GHC.resumeSpan resume))
+ ptext (sLit "--> ") <> text (GHC.resumeStmt resume)
+ $$ nest 2 (ptext (sLit "Stopped at") <+> ppr (GHC.resumeSpan resume))
showPackages :: GHCi ()
showPackages = do
pkg_ids <- fmap (preloadPackages . pkgState) getDynFlags
io $ putStrLn $ showSDoc $ vcat $
text "packages currently loaded:"
- : map (nest 2 . text . packageIdString) pkg_ids
+ : map (nest 2 . text . packageIdString)
+ (sortBy (compare `on` packageIdFS) pkg_ids)
where showFlag (ExposePackage p) = text $ " -package " ++ p
showFlag (HidePackage p) = text $ " -hide-package " ++ p
showFlag (IgnorePackage p) = text $ " -ignore-package " ++ p
dflags <- getDynFlags
io $ putStrLn $ showSDoc $ vcat $
text "active language flags:" :
- [text (" -X" ++ str) | (str,f) <- DynFlags.xFlags, dopt f dflags]
+ [text (" -X" ++ str) | (str, f, _) <- DynFlags.xFlags, dopt f dflags]
-- -----------------------------------------------------------------------------
-- Completion
completeHomeModuleOrFile
:: String -> IO [String]
-#ifdef USE_READLINE
+#ifdef USE_EDITLINE
completeWord :: String -> Int -> Int -> IO (Maybe (String, [String]))
completeWord w start end = do
line <- Readline.getLineBuffer
(s,r') = span isBreak r
in (n,w):words' isBreak (n+length w+length s) r'
-- In a Haskell expression we want to parse 'a-b' as three words
- -- where a compiler flag (ie. -fno-monomorphism-restriction) should
+ -- where a compiler flag (e.g. -ddump-simpl) should
-- only be a single word.
selectWord [] = (0,w)
selectWord ((offset,x):xs)
-- doContinue :: SingleStep -> GHCi ()
doContinue :: (SrcSpan -> Bool) -> SingleStep -> GHCi ()
doContinue pred step = do
- session <- getSession
- runResult <- io $ GHC.resume session step
+ runResult <- resume step
afterRunStmt pred runResult
return ()
backCmd = noArgs $ do
s <- getSession
(names, _, span) <- io $ GHC.back s
- printForUser $ ptext SLIT("Logged breakpoint at") <+> ppr span
+ printForUser $ ptext (sLit "Logged breakpoint at") <+> ppr span
printTypeOfNames s names
-- run the command set with ":set stop <cmd>"
st <- getGHCiState
s <- getSession
(names, ix, span) <- io $ GHC.forward s
printForUser $ (if (ix == 0)
- then ptext SLIT("Stopped at")
- else ptext SLIT("Logged breakpoint at")) <+> ppr span
+ then ptext (sLit "Stopped at")
+ else ptext (sLit "Logged breakpoint at")) <+> ppr span
printTypeOfNames s names
-- run the command set with ":set stop <cmd>"
st <- getGHCiState