[project @ 2002-09-09 12:50:26 by simonpj]
[ghc-hetmet.git] / ghc / compiler / compMan / CmTypes.lhs
index d2dfb1c..fd3cbfc 100644 (file)
@@ -6,14 +6,13 @@
 \begin{code}
 module CmTypes ( 
    Unlinked(..),  isObject, nameOfObject, isInterpretable,
-   Linkable(..), linkableTime,
-   ModSummary(..), name_of_summary, pprSummaryTime
+   Linkable(..), isObjectLinkable, partitionLinkable,
+   ModSummary(..), ms_allimps, pprSummaryTime, modSummaryName,
   ) where
 
 import Interpreter
 import HscTypes
 import Module
-import CmStaticInfo
 import Outputable
 
 import Time            ( ClockTime )
@@ -23,14 +22,14 @@ data Unlinked
    = DotO FilePath
    | DotA FilePath
    | DotDLL FilePath
-   | Trees [UnlinkedIBind] ItblEnv  -- bunch of interpretable bindings, +
-                                   -- a mapping from DataCons to their itbls
+   | BCOs [UnlinkedBCO] 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 binds
+   ppr (BCOs bcos _) = text "BCOs" <+> ppr bcos
 
 isObject (DotO _) = True
 isObject (DotA _) = True
@@ -41,23 +40,34 @@ nameOfObject (DotO fn)   = fn
 nameOfObject (DotA fn)   = fn
 nameOfObject (DotDLL fn) = fn
 
-isInterpretable (Trees _ _) = True
-isInterpretable _ = False
-
-data Linkable
-   = LM ClockTime ModuleName [Unlinked]
-   | LP PackageName
+isInterpretable = not . isObject
+
+data Linkable = LM {
+  linkableTime     :: ClockTime,
+  linkableModName  :: ModuleName,      -- should be Module, but see below
+  linkableUnlinked :: [Unlinked]
+ }
+
+isObjectLinkable :: Linkable -> Bool
+isObjectLinkable l = all isObject (linkableUnlinked l)
+
+-- HACK to support f-x-dynamic in the interpreter; no other purpose
+partitionLinkable :: Linkable -> [Linkable]
+partitionLinkable li
+   = let li_uls = linkableUnlinked li
+         li_uls_obj = filter isObject li_uls
+         li_uls_bco = filter isInterpretable li_uls
+     in 
+         case (li_uls_obj, li_uls_bco) of
+            (objs@(_:_), bcos@(_:_)) 
+               -> [li{linkableUnlinked=li_uls_obj}, li{linkableUnlinked=li_uls_bco}]
+            other
+               -> [li]
 
 instance Outputable Linkable where
-   ppr (LM when_made mod_nm unlinkeds)
-      = text "LinkableM" <+> parens (text (show when_made)) <+> ppr mod_nm 
-                         <+> ppr unlinkeds
-   ppr (LP package_nm)
-      = text "LinkableP" <+> ptext package_nm
-
-linkableTime (LM when_made mod_nm unlinkeds) = when_made
-linkableTime (LP package_nm)                 = panic "linkableTime"
-
+   ppr (LM when_made mod unlinkeds)
+      = (text "LinkableM" <+> parens (text (show when_made)) <+> ppr mod)
+        $$ nest 3 (ppr unlinkeds)
 
 -- The ModuleLocation contains both the original source filename and the
 -- filename of the cleaned-up source file after all preprocessing has been
@@ -67,12 +77,11 @@ linkableTime (LP package_nm)                 = panic "linkableTime"
 -- and let @compile@ read from that file on the way back up.
 data ModSummary
    = ModSummary {
-        ms_mod      :: Module,               -- name, package
-        ms_location :: ModuleLocation,       -- location
-        ms_srcimps  :: [ModuleName],         -- source imports
-        ms_imps     :: [ModuleName],         -- non-source imports
-        ms_hs_date  :: Maybe ClockTime       -- timestamp of summarised
-                                             -- file, if home && source
+        ms_mod      :: Module,                 -- name, package
+        ms_location :: ModuleLocation,         -- location
+        ms_srcimps  :: [ModuleName],           -- source imports
+        ms_imps     :: [ModuleName],           -- non-source imports
+        ms_hs_date  :: ClockTime               -- timestamp of summarised file
      }
 
 instance Outputable ModSummary where
@@ -88,6 +97,9 @@ instance Outputable ModSummary where
 pprSummaryTime ms
    = text "ms_hs_date = " <> parens (text (show (ms_hs_date ms)))
 
-name_of_summary :: ModSummary -> ModuleName
-name_of_summary = moduleName . ms_mod
+ms_allimps ms 
+   = ms_srcimps ms ++ ms_imps ms
+
+modSummaryName :: ModSummary -> ModuleName
+modSummaryName = moduleName . ms_mod
 \end{code}