X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=compiler%2Fghci%2FInteractiveUI.hs;h=74310a340df57a03742180a38783cb0766e26fa0;hb=427f3443a432cde66da1e8dde94ef9c5351636da;hp=573aaa01cc49fb4a75746534d2f81e0b7d80133a;hpb=d0a4736028a4834f6ce643a0629c7b5f1f451d34;p=ghc-hetmet.git diff --git a/compiler/ghci/InteractiveUI.hs b/compiler/ghci/InteractiveUI.hs index 573aaa0..74310a3 100644 --- a/compiler/ghci/InteractiveUI.hs +++ b/compiler/ghci/InteractiveUI.hs @@ -6,29 +6,34 @@ -- (c) The GHC Team 2005-2006 -- ----------------------------------------------------------------------------- -module InteractiveUI ( - interactiveUI, - ghciWelcomeMsg - ) where + +module InteractiveUI ( interactiveUI, ghciWelcomeMsg ) where #include "HsVersions.h" import GhciMonad +import GhciTags +import Debugger -- The GHC interface import qualified GHC import GHC ( Session, LoadHowMuch(..), Target(..), TargetId(..), - Type, Module, ModuleName, TyThing(..), Phase ) + Module, ModuleName, TyThing(..), Phase, + BreakIndex, SrcSpan, Resume, SingleStep ) +import PprTyThing import DynFlags + import Packages +#ifdef USE_READLINE import PackageConfig import UniqFM -import PprTyThing -import Outputable +#endif --- for createtags +import HscTypes ( implicitTyThings ) +import qualified RdrName ( getGRE_NameQualifier_maybes ) -- should this come via GHC? +import Outputable hiding (printForUser) +import Module -- for ModuleEnv import Name -import OccName import SrcLoc -- Other random utilities @@ -39,25 +44,12 @@ import Config import StaticFlags import Linker import Util - --- The debugger -import Breakpoints -import Debugger hiding ( addModule ) -import HscTypes -import Id -import Var ( globaliseId ) -import IdInfo -import NameEnv -import RdrName -import Module -import Type -import TcType +import NameSet +import Maybes ( orElse ) +import FastString #ifndef mingw32_HOST_OS -import System.Posix -#if __GLASGOW_HASKELL__ > 504 - hiding (getEnv) -#endif +import System.Posix hiding (getEnv) #else import GHC.ConsoleHandler ( flushConsole ) import System.Win32 ( setConsoleCP, setConsoleOutputCP ) @@ -74,153 +66,183 @@ import System.Console.Readline as Readline import Control.Exception as Exception -- import Control.Concurrent -import Numeric +import qualified Data.ByteString.Char8 as BS import Data.List -import Data.Int ( Int64 ) -import Data.Maybe ( isJust, isNothing, fromMaybe, catMaybes ) +import Data.Maybe import System.Cmd import System.Environment import System.Exit ( exitWith, ExitCode(..) ) import System.Directory import System.IO import System.IO.Error as IO +import System.IO.Unsafe import Data.Char import Data.Dynamic +import Data.Array import Control.Monad as Monad -import Foreign.StablePtr ( newStablePtr ) +import Text.Printf +import Foreign.StablePtr ( newStablePtr ) import GHC.Exts ( unsafeCoerce# ) import GHC.IOBase ( IOErrorType(InvalidArgument) ) -import Data.IORef ( IORef, newIORef, readIORef, writeIORef ) +import Data.IORef ( IORef, readIORef, writeIORef ) +#ifdef USE_READLINE import System.Posix.Internals ( setNonBlockingFD ) +#endif ----------------------------------------------------------------------------- -ghciWelcomeMsg = - " ___ ___ _\n"++ - " / _ \\ /\\ /\\/ __(_)\n"++ - " / /_\\// /_/ / / | | GHC Interactive, version " ++ cProjectVersion ++ ", for Haskell 98.\n"++ - "/ /_\\\\/ __ / /___| | http://www.haskell.org/ghc/\n"++ - "\\____/\\/ /_/\\____/|_| Type :? for help.\n" +ghciWelcomeMsg :: String +ghciWelcomeMsg = "GHCi, version " ++ cProjectVersion ++ + ": http://www.haskell.org/ghc/ :? for help" type Command = (String, String -> GHCi Bool, Bool, String -> IO [String]) + +cmdName :: Command -> String cmdName (n,_,_,_) = n -GLOBAL_VAR(commands, builtin_commands, [Command]) +macros_ref :: IORef [Command] +GLOBAL_VAR(macros_ref, [], [Command]) builtin_commands :: [Command] builtin_commands = [ - ("add", tlC$ keepGoingPaths addModule, False, completeFilename), - ("browse", keepGoing browseCmd, False, completeModule), -#ifdef DEBUGGER - -- I think that :c should mean :continue rather than :cd, makes more sense - -- (pepe 01.11.07) - ("continue", const(bkptOptions "continue"), False, completeNone), -#endif - ("cd", tlC$ keepGoing changeDirectory, False, completeFilename), - ("def", keepGoing defineMacro, False, completeIdentifier), - ("e", keepGoing editFile, False, completeFilename), -- Hugs users are accustomed to :e, so make sure it doesn't overlap + ("?", keepGoing help, False, completeNone), + ("add", keepGoingPaths addModule, False, completeFilename), + ("abandon", keepGoing abandonCmd, False, completeNone), + ("break", keepGoing breakCmd, False, completeIdentifier), + ("back", keepGoing backCmd, False, completeNone), + ("browse", keepGoing (browseCmd False), False, completeModule), + ("browse!", keepGoing (browseCmd True), False, completeModule), + ("cd", keepGoing changeDirectory, False, completeFilename), + ("check", keepGoing checkModule, False, completeHomeModule), + ("continue", keepGoing continueCmd, False, completeNone), + ("cmd", keepGoing cmdCmd, False, completeIdentifier), + ("ctags", keepGoing createCTagsFileCmd, False, completeFilename), + ("def", keepGoing (defineMacro False), False, completeIdentifier), + ("def!", keepGoing (defineMacro True), False, completeIdentifier), + ("delete", keepGoing deleteCmd, False, completeNone), + ("e", keepGoing editFile, False, completeFilename), ("edit", keepGoing editFile, False, completeFilename), + ("etags", keepGoing createETagsFileCmd, False, completeFilename), + ("force", keepGoing forceCmd, False, completeIdentifier), + ("forward", keepGoing forwardCmd, False, completeNone), ("help", keepGoing help, False, completeNone), - ("?", keepGoing help, False, completeNone), + ("history", keepGoing historyCmd, False, completeNone), ("info", keepGoing info, False, completeIdentifier), - ("load", tlC$ keepGoingPaths loadModule_,False, completeHomeModuleOrFile), + ("kind", keepGoing kindOfType, False, completeIdentifier), + ("load", keepGoingPaths loadModule_, False, completeHomeModuleOrFile), + ("list", keepGoing listCmd, False, completeNone), ("module", keepGoing setContext, False, completeModule), - ("main", tlC$ keepGoing runMain, False, completeIdentifier), - ("reload", tlC$ keepGoing reloadModule, False, completeNone), - ("check", keepGoing checkModule, False, completeHomeModule), + ("main", keepGoing runMain, False, completeIdentifier), + ("print", keepGoing printCmd, False, completeIdentifier), + ("quit", quit, False, completeNone), + ("reload", keepGoing reloadModule, False, completeNone), ("set", keepGoing setCmd, True, completeSetOptions), ("show", keepGoing showCmd, False, completeNone), - ("etags", keepGoing createETagsFileCmd, False, completeFilename), - ("ctags", keepGoing createCTagsFileCmd, False, completeFilename), + ("sprint", keepGoing sprintCmd, False, completeIdentifier), + ("step", keepGoing stepCmd, False, completeIdentifier), + ("steplocal", keepGoing stepLocalCmd, False, completeIdentifier), + ("stepmodule",keepGoing stepModuleCmd, False, completeIdentifier), ("type", keepGoing typeOfExpr, False, completeIdentifier), -#if defined(DEBUGGER) - ("print", keepGoing (pprintClosureCommand True False), False, completeIdentifier), - ("sprint", keepGoing (pprintClosureCommand False False),False, completeIdentifier), - ("force", keepGoing (pprintClosureCommand False True), False, completeIdentifier), - ("breakpoint",bkptOptions, False, completeBkpt), -#endif - ("kind", keepGoing kindOfType, False, completeIdentifier), - ("unset", keepGoing unsetOptions, True, completeSetOptions), + ("trace", keepGoing traceCmd, False, completeIdentifier), ("undef", keepGoing undefineMacro, False, completeMacro), - ("quit", quit, False, completeNone) + ("unset", keepGoing unsetOptions, True, completeSetOptions) ] keepGoing :: (String -> GHCi ()) -> (String -> GHCi Bool) keepGoing a str = a str >> return False --- tlC: Top Level Command, not allowed in inferior sessions -tlC :: (String -> GHCi Bool) -> (String -> GHCi Bool) -tlC a str = do - top_level <- isTopLevel - if not top_level - then throwDyn (CmdLineError "Command only allowed at Top Level") - else a str - keepGoingPaths :: ([FilePath] -> GHCi ()) -> (String -> GHCi Bool) keepGoingPaths a str = a (toArgs str) >> return False +shortHelpText :: String shortHelpText = "use :? for help.\n" --- NOTE: spaces at the end of each line to workaround CPP/string gap bug. +helpText :: String helpText = " Commands available from the prompt:\n" ++ "\n" ++ - " evaluate/run \n" ++ + " evaluate/run \n" ++ + " :{\\n ..lines.. \\n:}\\n multiline command\n" ++ " :add ... add module(s) to the current target set\n" ++ - " :breakpoint