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