[project @ 2000-10-27 15:40:01 by simonpj]
[ghc-hetmet.git] / ghc / compiler / ghci / CmLink.lhs
index df308e5..3ec42dd 100644 (file)
@@ -13,14 +13,14 @@ module CmLink ( Linkable(..),  Unlinked(..),
 where
 
 import StgInterp       ( linkIModules, ClosureEnv, ItblEnv )
-
+import Linker          ( loadObj, resolveObjs )
 import CmStaticInfo    ( PackageConfigInfo )
 import Module          ( ModuleName, PackageName )
 import InterpSyn       ( UnlinkedIBind, HValue, binder )
 import Module          ( Module )
 import Outputable      ( SDoc )
 import FiniteMap       ( emptyFM )
-import Digraph         ( SCC(..) )
+import Digraph         ( SCC(..), flattenSCC )
 import Outputable
 import Panic           ( panic )
 
@@ -30,8 +30,16 @@ import Panic         ( panic )
 \begin{code}
 data PersistentLinkerState 
    = PersistentLinkerState {
+       -- Current global mapping from RdrNames to closure addresses
         closure_env :: ClosureEnv,
+
+       -- the current global mapping from RdrNames of DataCons to 
+       -- info table addresses.
+       -- When a new Unlinked is linked into the running image, or an existing
+       -- module in the image is replaced, the itbl_env must be updated
+       -- appropriately.
         itbl_env    :: ItblEnv
+
        -- notionally here, but really lives in the C part of the linker:
        --            object_symtab :: FiniteMap String Addr
      }
@@ -44,13 +52,14 @@ data Unlinked
    = DotO FilePath
    | DotA FilePath
    | DotDLL FilePath
-   | Trees [UnlinkedIBind]     -- bunch of interpretable bindings
+   | Trees [UnlinkedIBind] ItblEnv  -- bunch of interpretable bindings, +
+                                   -- a mapping from DataCons to their itbls
 
 instance Outputable Unlinked where
    ppr (DotO path)   = text "DotO" <+> text path
    ppr (DotA path)   = text "DotA" <+> text path
    ppr (DotDLL path) = text "DotDLL" <+> text path
-   ppr (Trees binds) = text "Trees" <+> ppr (map binder binds)
+   ppr (Trees binds _) = text "Trees" <+> ppr (map binder binds)
 
 
 isObject (DotO _) = True
@@ -58,7 +67,7 @@ isObject (DotA _) = True
 isObject (DotDLL _) = True
 isObject _ = False
 
-isInterpretable (Trees _) = True
+isInterpretable (Trees _ _) = True
 isInterpretable _ = False
 
 data Linkable
@@ -89,13 +98,14 @@ link pci groups pls1
         return (LinkOK pls1)
 
 ppLinkableSCC :: SCC Linkable -> SDoc
-ppLinkableSCC (CyclicSCC xs) = ppr xs
-ppLinkableSCC (AcyclicSCC x) = ppr [x]
-
+ppLinkableSCC = ppr . flattenSCC
 
 #else
+
+
 link pci [] pls = return (LinkOK pls)
-link pci (group:groups) pls = do
+link pci (groupSCC:groups) pls = do
+   let group = flattenSCC groupSCC
    -- the group is either all objects or all interpretable, for now
    if all isObject group
        then do mapM loadObj [ file | DotO file <- group ]
@@ -113,6 +123,7 @@ link pci (group:groups) pls = do
        return (LinkErrs pls (ptext SLIT("linker: group must contain all objects or all interpreted modules")))
 #endif
 
+
 modname_of_linkable (LM nm _) = nm
 modname_of_linkable (LP _)    = panic "modname_of_linkable: package"