From: simonmar Date: Wed, 23 Jan 2002 16:50:52 +0000 (+0000) Subject: [project @ 2002-01-23 16:50:46 by simonmar] X-Git-Tag: Approximately_9120_patches~269 X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=92cdc09e48d3410182581f5bd687d1ee7cbe476b;p=ghc-hetmet.git [project @ 2002-01-23 16:50:46 by simonmar] - Implement an alternative :module syntax so we can play around with it. - Implement ':show bindings' and ':show modules' - Fix a bug whereby doing :info on a local binding would cause a panic (this needs to be merged to STABLE - the change is part of the patch to HscMain). - Some cleanups in InteractiveUI.hs --- diff --git a/ghc/compiler/compMan/CompManager.lhs b/ghc/compiler/compMan/CompManager.lhs index 7eb2c91..b78d51a 100644 --- a/ghc/compiler/compMan/CompManager.lhs +++ b/ghc/compiler/compMan/CompManager.lhs @@ -25,7 +25,8 @@ module CompManager ( cmSetContext, -- :: CmState -> DynFlags -> [String] -> [String] -> IO CmState cmGetContext, -- :: CmState -> IO ([String],[String]) - cmInfoThing, -- :: CmState -> DynFlags -> String -> IO (Maybe TyThing) + cmInfoThing, -- :: CmState -> DynFlags -> String + -- -> IO (CmState, [(TyThing,Fixity)]) CmRunResult(..), cmRunStmt, -- :: CmState -> DynFlags -> String @@ -39,12 +40,24 @@ module CompManager ( HValue, cmCompileExpr, -- :: CmState -> DynFlags -> String -- -> IO (CmState, Maybe HValue) + + cmGetModuleGraph, -- :: CmState -> ModuleGraph + cmGetLinkables, -- :: CmState -> [Linkable] + + cmGetBindings, -- :: CmState -> [TyThing] + cmGetPrintUnqual, -- :: CmState -> PrintUnqualified #endif + + -- utils + showModMsg, -- ) where #include "HsVersions.h" +import MkIface --tmp +import HsSyn -- tmp + import CmLink import CmTypes import DriverPipeline @@ -59,7 +72,7 @@ import HscMain ( initPersistentCompilerState ) #endif import HscTypes import Name ( Name, NamedThing(..), nameRdrName, nameModule, - isHomePackageName ) + isHomePackageName, isGlobalName ) import Rename ( mkGlobalContext ) import RdrName ( emptyRdrEnv ) import Module @@ -156,6 +169,15 @@ cmInit :: GhciMode -> IO CmState cmInit mode = emptyCmState mode ----------------------------------------------------------------------------- +-- Grab information from the CmState + +cmGetModuleGraph = mg +cmGetLinkables = ui + +cmGetBindings cmstate = nameEnvElts (ic_type_env (ic cmstate)) +cmGetPrintUnqual cmstate = ic_print_unqual (ic cmstate) + +----------------------------------------------------------------------------- -- Setting the context doesn't throw away any bindings; the bindings -- we've built up in the InteractiveContext simply move to the new -- module. They always shadow anything in scope in the current context. @@ -219,19 +241,18 @@ cmModuleIsInterpreted cmstate str -- and type constructor), so we return a list of all the possible TyThings. #ifdef GHCI -cmInfoThing :: CmState -> DynFlags -> String - -> IO (CmState, PrintUnqualified, [(TyThing,Fixity)]) +cmInfoThing :: CmState -> DynFlags -> String -> IO (CmState, [(TyThing,Fixity)]) cmInfoThing cmstate dflags id = do (new_pcs, things) <- hscThing dflags hst hit pcs icontext id let pairs = map (\x -> (x, getFixity new_pcs (getName x))) things - return (cmstate{ pcs=new_pcs }, unqual, pairs) - where + return (cmstate{ pcs=new_pcs }, pairs) + where CmState{ hst=hst, hit=hit, pcs=pcs, pls=pls, ic=icontext } = cmstate - unqual = ic_print_unqual icontext getFixity :: PersistentCompilerState -> Name -> Fixity getFixity pcs name - | Just iface <- lookupModuleEnv iface_table (nameModule name), + | isGlobalName name, + Just iface <- lookupModuleEnv iface_table (nameModule name), Just fixity <- lookupNameEnv (mi_fixities iface) name = fixity | otherwise diff --git a/ghc/compiler/ghci/InteractiveUI.hs b/ghc/compiler/ghci/InteractiveUI.hs index fb0732b..11d41c7 100644 --- a/ghc/compiler/ghci/InteractiveUI.hs +++ b/ghc/compiler/ghci/InteractiveUI.hs @@ -1,6 +1,6 @@ {-# OPTIONS -#include "Linker.h" -#include "SchedAPI.h" #-} ----------------------------------------------------------------------------- --- $Id: InteractiveUI.hs,v 1.108 2002/01/22 16:50:29 simonmar Exp $ +-- $Id: InteractiveUI.hs,v 1.109 2002/01/23 16:50:49 simonmar Exp $ -- -- GHC Interactive User Interface -- @@ -13,8 +13,12 @@ module InteractiveUI ( interactiveUI, ghciWelcomeMsg ) where #include "HsVersions.h" import Packages + import CompManager -import HscTypes ( TyThing(..) ) +import CmTypes ( Linkable, isObjectLinkable, ModSummary(..) ) +import CmLink ( findModuleLinkable_maybe ) + +import HscTypes ( TyThing(..), showModMsg, InteractiveContext(..) ) import MkIface ( ifaceTyThing ) import DriverFlags import DriverState @@ -28,13 +32,15 @@ import Class ( className ) import TyCon ( tyConName, tyConClass_maybe, isPrimTyCon ) 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 ) import Outputable -import CmdLineOpts ( DynFlag(..), getDynFlags, saveDynFlags, restoreDynFlags, - dopt_unset ) +import CmdLineOpts ( DynFlag(..), getDynFlags, saveDynFlags, + restoreDynFlags, dopt_unset ) import Panic ( GhcException(..), showGhcException ) import Config @@ -58,7 +64,7 @@ import CPUTime import Directory import IO import Char -import Monad ( when, join ) +import Monad import PrelGHC ( unsafeCoerce# ) import Foreign ( nullPtr ) @@ -83,11 +89,11 @@ builtin_commands = [ ("help", keepGoing help), ("?", keepGoing help), ("info", keepGoing info), - ("import", keepGoing importModules), ("load", keepGoing loadModule), ("module", keepGoing setContext), ("reload", keepGoing reloadModule), ("set", keepGoing setCmd), + ("show", keepGoing showCmd), ("type", keepGoing typeOfExpr), ("unset", keepGoing unsetOptions), ("undef", keepGoing undefineMacro), @@ -111,11 +117,16 @@ helpText = "\ \ :load ... load module(s) and their dependents\n\ \ :module set the context for expression evaluation to \n\ \ :reload reload the current module set\n\ +\\n\ \ :set