X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=ghc%2Fcompiler%2Fghci%2FInteractiveUI.hs;h=f8ee7bf1b8d5a4ec7fb65566e983fc37fd4ab2a1;hb=e68a5b608d7ac55f133481d9e428119850668e7a;hp=8cd26ab045dc4247dea120c81906b7c81883f77e;hpb=c9316ee5fdd01cd6105319f47d66b26b8a25a25f;p=ghc-hetmet.git diff --git a/ghc/compiler/ghci/InteractiveUI.hs b/ghc/compiler/ghci/InteractiveUI.hs index 8cd26ab..f8ee7bf 100644 --- a/ghc/compiler/ghci/InteractiveUI.hs +++ b/ghc/compiler/ghci/InteractiveUI.hs @@ -1,212 +1,237 @@ -{-# OPTIONS -#include "Linker.h" -#include "SchedAPI.h" #-} +{-# OPTIONS -#include "Linker.h" #-} ----------------------------------------------------------------------------- --- $Id: InteractiveUI.hs,v 1.129 2002/07/17 13:49:15 simonmar Exp $ -- -- GHC Interactive User Interface -- --- (c) The GHC Team 2000 +-- (c) The GHC Team 2005 -- ----------------------------------------------------------------------------- module InteractiveUI ( - interactiveUI, -- :: CmState -> [FilePath] -> [LibrarySpec] -> IO () - LibrarySpec(..), + interactiveUI, ghciWelcomeMsg ) where -#include "../includes/config.h" #include "HsVersions.h" -import Packages - -import CompManager -import CmTypes ( Linkable, isObjectLinkable, ModSummary(..) ) -import CmLink ( findModuleLinkable_maybe ) - -import HscTypes ( TyThing(..), showModMsg, InteractiveContext(..) ) -import HsSyn ( TyClDecl(..), ConDecl(..), Sig(..) ) -import MkIface ( ifaceTyThing ) -import DriverFlags -import DriverState -import DriverUtil ( handle, remove_spaces ) -import Linker -import Finder ( flushPackageCache ) -import Util -import Id ( isRecordSelector, recordSelectorFieldLabel, - isDataConWrapId, isDataConId, idName ) -import Class ( className ) -import TyCon ( tyConName, tyConClass_maybe, isPrimTyCon, DataConDetails(..) ) -import FieldLabel ( fieldLabelTyCon ) -import SrcLoc ( isGoodSrcLoc ) -import Module ( moduleName ) -import NameEnv ( nameEnvElts ) -import Name ( Name, isHomePackageName, nameSrcLoc, nameOccName, - NamedThing(..) ) -import OccName ( isSymOcc ) -import BasicTypes ( defaultFixity ) +-- The GHC interface +import qualified GHC +import GHC ( Session, verbosity, dopt, DynFlag(..), Target(..), + TargetId(..), DynFlags(..), + pprModule, Type, Module, SuccessFlag(..), + TyThing(..), Name, LoadHowMuch(..), Phase, + GhcException(..), showGhcException, + CheckedModule(..), SrcLoc ) +import DynFlags ( allFlags ) +import Packages ( PackageState(..) ) +import PackageConfig ( InstalledPackageInfo(..) ) +import UniqFM ( eltsUFM ) +import PprTyThing import Outputable -import CmdLineOpts ( DynFlag(..), DynFlags(..), getDynFlags, saveDynFlags, - restoreDynFlags, dopt_unset ) -import Panic ( GhcException(..), showGhcException ) -import Config -#ifndef mingw32_TARGET_OS -import Posix +-- for createtags (should these come via GHC?) +import Module ( moduleString ) +import Name ( nameSrcLoc, nameModule, nameOccName ) +import OccName ( pprOccName ) +import SrcLoc ( isGoodSrcLoc, srcLocFile, srcLocLine, srcLocCol ) + +-- Other random utilities +import Digraph ( flattenSCCs ) +import BasicTypes ( failed, successIf ) +import Panic ( panic, installSignalHandlers ) +import Config +import StaticFlags ( opt_IgnoreDotGhci ) +import Linker ( showLinkerState ) +import Util ( removeSpaces, handle, global, toArgs, + looksLikeModuleName, prefixMatch, sortLe ) + +#ifndef mingw32_HOST_OS +import System.Posix +#if __GLASGOW_HASKELL__ > 504 + hiding (getEnv) +#endif +#else +import GHC.ConsoleHandler ( flushConsole ) #endif -import Exception -import Dynamic -#if HAVE_READLINE_HEADERS && HAVE_READLINE_LIBS -import Readline +#ifdef USE_READLINE +import Control.Concurrent ( yield ) -- Used in readline loop +import System.Console.Readline as Readline #endif -import Concurrent -import IOExts -import SystemExts -import Numeric -import List -import System -import CPUTime -import Directory -import IO -import Char -import Monad +--import SystemExts -import GlaExts ( unsafeCoerce# ) +import Control.Exception as Exception +import Data.Dynamic +-- import Control.Concurrent -import Foreign ( nullPtr ) -import CString ( CString, peekCString, withCString ) +import Numeric +import Data.List +import Data.Int ( Int64 ) +import Data.Maybe ( isJust, fromMaybe, catMaybes ) +import System.Cmd +import System.CPUTime +import System.Environment +import System.Exit ( exitWith, ExitCode(..) ) +import System.Directory +import System.IO +import System.IO.Error as IO +import Data.Char +import Control.Monad as Monad +import Foreign.StablePtr ( newStablePtr ) +import Text.Printf + +import GHC.Exts ( unsafeCoerce# ) +import GHC.IOBase ( IOErrorType(InvalidArgument) ) + +import Data.IORef ( IORef, newIORef, readIORef, writeIORef ) + +import System.Posix.Internals ( setNonBlockingFD ) ----------------------------------------------------------------------------- -ghciWelcomeMsg = "\ -\ ___ ___ _\n\ -\ / _ \\ /\\ /\\/ __(_)\n\ -\ / /_\\// /_/ / / | | GHC Interactive, version " ++ cProjectVersion ++ ", for Haskell 98.\n\ -\/ /_\\\\/ __ / /___| | http://www.haskell.org/ghc/\n\ -\\\____/\\/ /_/\\____/|_| Type :? for help.\n" +ghciWelcomeMsg = + " ___ ___ _\n"++ + " / _ \\ /\\ /\\/ __(_)\n"++ + " / /_\\// /_/ / / | | GHC Interactive, version " ++ cProjectVersion ++ ", for Haskell 98.\n"++ + "/ /_\\\\/ __ / /___| | http://www.haskell.org/ghc/\n"++ + "\\____/\\/ /_/\\____/|_| Type :? for help.\n" + +type Command = (String, String -> GHCi Bool, Bool, String -> IO [String]) +cmdName (n,_,_,_) = n -GLOBAL_VAR(commands, builtin_commands, [(String, String -> GHCi Bool)]) +GLOBAL_VAR(commands, builtin_commands, [Command]) -builtin_commands :: [(String, String -> GHCi Bool)] +builtin_commands :: [Command] builtin_commands = [ - ("add", keepGoing addModule), - ("browse", keepGoing browseCmd), - ("cd", keepGoing changeDirectory), - ("def", keepGoing defineMacro), - ("help", keepGoing help), - ("?", keepGoing help), - ("info", keepGoing info), - ("load", keepGoing loadModule), - ("module", keepGoing setContext), - ("reload", keepGoing reloadModule), - ("set", keepGoing setCmd), - ("show", keepGoing showCmd), - ("type", keepGoing typeOfExpr), - ("unset", keepGoing unsetOptions), - ("undef", keepGoing undefineMacro), - ("quit", quit) + ("add", keepGoingPaths addModule, False, completeFilename), + ("browse", keepGoing browseCmd, False, completeModule), + ("cd", keepGoing changeDirectory, False, completeFilename), + ("def", keepGoing defineMacro, False, completeIdentifier), + ("help", keepGoing help, False, completeNone), + ("?", keepGoing help, False, completeNone), + ("info", keepGoing info, False, completeIdentifier), + ("load", keepGoingPaths loadModule_, False, completeHomeModuleOrFile), + ("module", keepGoing setContext, False, completeModule), + ("main", keepGoing runMain, False, completeIdentifier), + ("reload", keepGoing reloadModule, False, completeNone), + ("check", keepGoing checkModule, False, completeHomeModule), + ("set", keepGoing setCmd, True, completeSetOptions), + ("show", keepGoing showCmd, False, completeNone), + ("etags", keepGoing createETagsFileCmd, False, completeFilename), + ("ctags", keepGoing createCTagsFileCmd, False, completeFilename), + ("type", keepGoing typeOfExpr, False, completeIdentifier), + ("kind", keepGoing kindOfType, False, completeIdentifier), + ("unset", keepGoing unsetOptions, True, completeSetOptions), + ("undef", keepGoing undefineMacro, False, completeMacro), + ("quit", quit, False, completeNone) ] 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. -helpText = "\ -\ Commands available from the prompt:\n\ -\\n\ -\ evaluate/run \n\ -\ :add ... add module(s) to the current target set\n\ -\ :browse [*] display the names defined by \n\ -\ :cd change directory to \n\ -\ :def define a command :\n\ -\ :help, :? display this list of commands\n\ -\ :info [ ...] display information about the given names\n\ -\ :load ... load module(s) and their dependents\n\ -\ :module [+/-] [*] ... set the context for expression evaluation\n\ -\ :reload reload the current module set\n\ -\\n\ -\ :set