[project @ 2001-06-15 15:15:33 by simonmar]
[ghc-hetmet.git] / ghc / compiler / compMan / CmLink.lhs
index 3b3e28b..4b592f5 100644 (file)
@@ -12,25 +12,31 @@ module CmLink ( Linkable(..),  Unlinked(..),
                unload,
                 PersistentLinkerState{-abstractly!-}, emptyPLS,
 #ifdef GHCI
+               delListFromClosureEnv,
+               addListToClosureEnv,
                linkExpr
 #endif
   ) where
 
 
+#ifdef GHCI
+import ByteCodeLink    ( linkIModules, linkIExpr )
+#endif
+
 import Interpreter
 import DriverPipeline
 import CmTypes
-import CmStaticInfo    ( GhciMode(..) )
+import HscTypes                ( GhciMode(..) )
 import Outputable      ( SDoc )
 import Digraph         ( SCC(..), flattenSCC )
+import Name            ( Name )
 import Module          ( ModuleName )
 import FiniteMap
 import Outputable
 import ErrUtils                ( showPass )
 import CmdLineOpts     ( DynFlags(..) )
-import Panic           ( panic, GhcException(..) )
+import Panic           ( panic )
 
-import Exception
 import List
 import Monad
 import IO
@@ -88,6 +94,18 @@ emptyPLS = return (PersistentLinkerState { closure_env = emptyFM,
 emptyPLS = return (PersistentLinkerState {})
 #endif
 
+#ifdef GHCI
+delListFromClosureEnv :: PersistentLinkerState -> [Name]
+       -> IO PersistentLinkerState
+delListFromClosureEnv pls names
+  = return pls{ closure_env = delListFromFM (closure_env pls) names }
+
+addListToClosureEnv :: PersistentLinkerState -> [(Name,HValue)] 
+       -> IO PersistentLinkerState
+addListToClosureEnv pls new_bindings
+  = return pls{ closure_env = addListToFM (closure_env pls) new_bindings }
+#endif
+
 -----------------------------------------------------------------------------
 -- Unloading old objects ready for a new compilation sweep.
 --
@@ -100,6 +118,7 @@ emptyPLS = return (PersistentLinkerState {})
 --
 --     * otherwise, we unload it.
 --
+--      * we also implicitly unload all temporary bindings at this point.
 
 unload :: GhciMode
        -> DynFlags
@@ -199,9 +218,6 @@ link' Interactive dflags batch_attempt_linking linkables pls
         linkObjs (objs ++ bcos) pls
           -- get the objects first
 
-ppLinkableSCC :: SCC Linkable -> SDoc
-ppLinkableSCC = ppr . flattenSCC
-
 filterModuleLinkables :: (ModuleName -> Bool) -> [Linkable] -> [Linkable]
 filterModuleLinkables p [] = []
 filterModuleLinkables p (li:lis)
@@ -216,7 +232,6 @@ filterModuleLinkables p (li:lis)
 
 #ifndef GHCI
 linkObjs      = panic "CmLink.linkObjs: no interpreter"
-lookupClosure = panic "CmLink.lookupClosure: no interpreter"
 #else
 linkObjs [] pls = linkFinish pls []
 linkObjs (l@(LM _ m uls) : ls) pls
@@ -241,8 +256,7 @@ linkInterpretedCode (l@(LM _ m uls) : ls) ul_trees pls
        linkInterpretedCode ls (uls++ul_trees) 
                pls{objects_loaded = l : objects_loaded pls}
    | any isObject uls
-        = throwDyn (OtherError 
-            "can't link object code that depends on interpreted code")
+        = panic "linkInterpretedCode: trying to link object code to interpreted code"
    | otherwise = invalidLinkable
 
 invalidLinkable = panic "CmLink: linkable doesn't contain entirely objects or interpreted code"