[project @ 2000-09-29 15:59:28 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,            -- 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 )
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 newPCS :: IO PCS
65 newPCS = return (error "newPCS:unimp")
66
67 -- These two are only here to avoid recursion between CmCompile and
68 -- CompManager.  They really ought to be in the latter.
69 type HST = FiniteMap Module ModDetails
70 type HIT = FiniteMap Module ModIFace
71
72
73 data PCS = MkPCS PIT         -- Package interface table
74                  PST         -- Package symbol table
75                  HoldingPen  -- pre slurped interface bits and pieces
76
77 type PIT = FiniteMap Module ModIFace
78 type PST = FiniteMap Module ModDetails
79
80 -- ModIFace is nearly the same as RnMonad.ParsedIface.
81 -- Right now it's identical :)
82 data ModIFace 
83    = ModIFace {
84         mi_mod       :: Module,                   -- Complete with package info
85         mi_vers      :: Version,                  -- Module version number
86         mi_orphan    :: WhetherHasOrphans,        -- Whether this module has orphans
87         mi_usages    :: [ImportVersion OccName],  -- Usages
88         mi_exports   :: [ExportItem],             -- Exports
89         mi_insts     :: [RdrNameInstDecl],        -- Local instance declarations
90         mi_decls     :: [(Version, RdrNameHsDecl)],    -- Local definitions
91         mi_fixity    :: (Version, [RdrNameFixitySig]), -- Local fixity declarations, 
92                                                        -- with their version
93         mi_rules     :: (Version, [RdrNameRuleDecl]),  -- Rules, with their version
94         mi_deprecs   :: [RdrNameDeprecation]           -- Deprecations
95      }
96
97 data ModDetails
98    = ModDetails {
99         moduleExports :: Avails,
100         moduleEnv     :: GlobalRdrEnv,           -- == FM RdrName [Name]
101         typeEnv       :: FiniteMap Name TyThing, -- TyThing is in TcEnv.lhs
102         instEnv       :: InstEnv,
103         fixityEnv     :: FiniteMap Name Fixity,
104         ruleEnv       :: FiniteMap Id [CoreRule]
105      }
106
107 -- This should eventually replace RnMonad.Ifaces
108 data HoldingPen
109    = HoldingPen {
110         iDecls :: DeclsMap,     -- A single, global map of Names to decls
111
112         iInsts :: IfaceInsts,
113         -- The as-yet un-slurped instance decls; this bag is depleted when we
114         -- slurp an instance decl so that we don't slurp the same one twice.
115         -- Each is 'gated' by the names that must be available before
116         -- this instance decl is needed.
117
118         iRules :: IfaceRules
119         -- Similar to instance decls, only for rules
120      }
121 \end{code}