[project @ 2000-10-06 13:07:32 by sewardj]
[ghc-hetmet.git] / ghc / compiler / ghci / CmCompile.lhs
1 %
2 % (c) The AQUA Project, Glasgow University, 1993-2000
3 %
4 \section[CmCompile]{Compiler for GHCI}
5
6 \begin{code}
7 module CmCompile ( cmCompile,
8                    ModDetails,       -- abstract
9                    ModIFace,         -- abstract
10                    PCS, emptyPCS,    -- abstract
11                    HST,              -- not abstract (CM needs to see it)
12                    HIT,              -- ditto
13                    CompResult(..)
14                  )
15 where
16
17 #include "HsVersions.h"
18
19 import CmLink           ( Linkable )
20 import Outputable       ( SDoc )
21 import CmFind           ( Finder )
22 import CmSummarise      ( ModSummary )
23 import CmStaticInfo     ( SI )
24 import FiniteMap        ( FiniteMap, emptyFM )
25
26 import Module           ( Module )
27 import RnMonad          ( Avails, GlobalRdrEnv, DeclsMap, 
28                           WhetherHasOrphans, ImportVersion,
29                           IfaceInsts, IfaceRules, ExportItem )
30 import TcEnv            ( TyThing, InstEnv )
31 import Name             ( Name, OccName )
32 import BasicTypes       ( Fixity, Version )
33 import Id               ( Id )
34 import CoreSyn          ( CoreRule )
35 import RdrHsSyn         ( RdrNameDeprecation, RdrNameRuleDecl, RdrNameFixitySig,
36                           RdrNameHsDecl, RdrNameInstDecl )
37
38
39 \end{code}
40 \begin{code}
41 cmCompile :: SI               -- obvious
42           -> Finder           -- to find modules
43           -> ModSummary       -- summary, including source
44           -> Maybe ModIFace   -- old interface, if available
45           -> HST              -- for home module ModDetails
46           -> PCS              -- IN: persistent compiler state
47           -> IO CompResult
48
49 cmCompile flags finder summary old_iface hst pcs
50    = return (error "cmCompile:unimp")
51
52
53 data CompResult
54    = CompOK   ModDetails  -- new details (HST additions)
55               (Maybe (ModIFace, Linkable))
56                        -- summary and code; Nothing => compilation not reqd
57                        -- (old summary and code are still valid)
58               PCS      -- updated PCS
59               [SDoc]   -- warnings
60
61    | CompErrs PCS      -- updated PCS
62               [SDoc]   -- warnings and errors
63
64 emptyPCS :: IO PCS
65 emptyPCS = return (MkPCS emptyPIT emptyPST emptyHoldingPen)
66
67
68 -- These two are only here to avoid recursion between CmCompile and
69 -- CompManager.  They really ought to be in the latter.
70 type HST = FiniteMap {-really:Module-} String{- == ModName-} ModDetails
71 type HIT = FiniteMap {-really:Module-} String{- == ModName-} ModIFace
72
73
74 data PCS = MkPCS PIT         -- Package interface table
75                  PST         -- Package symbol table
76                  HoldingPen  -- pre slurped interface bits and pieces
77
78 type PIT = FiniteMap Module ModIFace
79 type PST = FiniteMap Module ModDetails
80
81 emptyPIT :: PIT
82 emptyPIT = emptyFM
83
84 emptyPST :: PST
85 emptyPST = emptyFM
86
87 -- ModIFace is nearly the same as RnMonad.ParsedIface.
88 -- Right now it's identical :)
89 data ModIFace 
90    = ModIFace {
91         mi_mod       :: Module,                   -- Complete with package info
92         mi_vers      :: Version,                  -- Module version number
93         mi_orphan    :: WhetherHasOrphans,        -- Whether this module has orphans
94         mi_usages    :: [ImportVersion OccName],  -- Usages
95         mi_exports   :: [ExportItem],             -- Exports
96         mi_insts     :: [RdrNameInstDecl],        -- Local instance declarations
97         mi_decls     :: [(Version, RdrNameHsDecl)],    -- Local definitions
98         mi_fixity    :: (Version, [RdrNameFixitySig]), -- Local fixity declarations, 
99                                                        -- with their version
100         mi_rules     :: (Version, [RdrNameRuleDecl]),  -- Rules, with their version
101         mi_deprecs   :: [RdrNameDeprecation]           -- Deprecations
102      }
103
104 data ModDetails
105    = ModDetails {
106         moduleExports :: Avails,
107         moduleEnv     :: GlobalRdrEnv,           -- == FM RdrName [Name]
108         typeEnv       :: FiniteMap Name TyThing, -- TyThing is in TcEnv.lhs
109         instEnv       :: InstEnv,
110         fixityEnv     :: FiniteMap Name Fixity,
111         ruleEnv       :: FiniteMap Id [CoreRule]
112      }
113
114 -- This should eventually replace RnMonad.Ifaces
115 data HoldingPen
116    = HoldingPen {
117         iDecls :: DeclsMap,     -- A single, global map of Names to decls
118
119         iInsts :: IfaceInsts,
120         -- The as-yet un-slurped instance decls; this bag is depleted when we
121         -- slurp an instance decl so that we don't slurp the same one twice.
122         -- Each is 'gated' by the names that must be available before
123         -- this instance decl is needed.
124
125         iRules :: IfaceRules
126         -- Similar to instance decls, only for rules
127      }
128
129 emptyHoldingPen :: HoldingPen
130 emptyHoldingPen = error "emptyHoldingPen:unimp"
131 \end{code}