[project @ 2000-10-16 08:24:18 by simonpj]
[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                    PersistentCompilerState, emptyPCS,    -- abstract
11                    HomeSymbolTable,    -- not abstract (CM needs to see it)
12                    HomeInterfaceTable, -- ditto
13                    CompResult(..)
14                  )
15 where
16
17 #include "HsVersions.h"
18
19 -- many of these need to be moved to HscTypes
20 --import CmLink         ( Linkable(..) )
21 --import Outputable     ( SDoc )
22 --import CmFind         ( Finder )
23 --import CmSummarise    ( ModSummary, name_of_summary )
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 import HscTypes         ( )
39
40 \end{code}
41
42
43 %************************************************************************
44 %*                                                                      *
45 \subsection{The main compiler interface}
46 %*                                                                      *
47 %************************************************************************
48
49
50 \begin{code}
51 cmCompile :: Finder                  -- to find modules
52           -> ModSummary              -- summary, including source
53           -> Maybe ModIFace          -- old interface, if available
54           -> HomeModMap              -- ModuleName -> Module
55           -> HomeSymbolTable         -- for home module ModDetails          
56           -> PersistentCompilerState -- IN: persistent compiler state
57           -> IO CompResult
58
59 cmCompile finder summary old_iface hst pcs
60    = do putStrLn ("cmCompile: compiling " ++ name_of_summary summary)
61         return (CompOK (error "cmCompile:modDetails")
62                        (Just (error "cmCompile:modIFace", 
63                               --error "cmCompile:Linkable"
64                               --LM (name_of_summary summary) [] 
65                               LM (name_of_summary summary) []
66                               ))
67                        pcs
68                        []
69                )
70
71 data CompResult
72    = CompOK   ModDetails  -- new details (HST additions)
73               (Maybe (ModIFace, Linkable))
74                        -- summary and code; Nothing => compilation not reqd
75                        -- (old summary and code are still valid)
76               PersistentCompilerState -- updated PCS
77               [SDoc]                  -- warnings
78
79    | CompErrs PersistentCompilerState -- updated PCS
80               [SDoc]                  -- errors
81               [SDoc]                  -- warnings
82
83
84 -- These two are only here to avoid recursion between CmCompile and
85 -- CompManager.  They really ought to be in the latter.
86 type ModuleEnv a = UniqFM a   -- Domain is Module
87
88 type HomeModMap         = FiniteMap ModuleName Module -- domain: home mods only
89 type HomeSymbolTable    = ModuleEnv ModDetails        -- ditto
90 type HomeInterfaceTable = ModuleEnv ModIFace
91 \end{code}
92
93
94 %************************************************************************
95 %*                                                                      *
96 \subsection{Module details}
97 %*                                                                      *
98 %************************************************************************
99
100 A @ModDetails@ summarises everything we know about a compiled module
101
102 \begin{code}
103 data ModDetails
104    = ModDetails {
105         moduleExports :: Avails,                -- What it exports
106         moduleEnv     :: GlobalRdrEnv,          -- Its top level environment
107
108         fixityEnv     :: NameEnv Fixity,
109         deprecEnv     :: NameEnv DeprecTxt,
110         typeEnv       :: NameEnv TcEnv.TyThing,
111
112         instEnv       :: InstEnv,
113         ruleEnv       :: IdEnv [CoreRule]       -- Domain includes Ids from other modules
114      }
115 \end{code}
116
117 Auxiliary definitions
118
119 \begin{code}
120 type DeprecationEnv = NameEnv DeprecTxt         -- Give reason for deprecation
121
122 type GlobalRdrEnv = RdrNameEnv [Name]   -- The list is because there may be name clashes
123                                         -- These only get reported on lookup,
124                                         -- not on construction
125
126 data GenAvailInfo name  = Avail name     -- An ordinary identifier
127                         | AvailTC name   -- The name of the type or class
128                                   [name] -- The available pieces of type/class.
129                                          -- NB: If the type or class is itself
130                                          -- to be in scope, it must be in this list.
131                                          -- Thus, typically: AvailTC Eq [Eq, ==, /=]
132                         deriving( Eq )
133                         -- Equality used when deciding if the interface has changed
134
135 type AvailEnv     = NameEnv AvailInfo   -- Maps a Name to the AvailInfo that contains it
136 type AvailInfo    = GenAvailInfo Name
137 type RdrAvailInfo = GenAvailInfo OccName
138 type Avails       = [AvailInfo]
139 \end{code}
140
141
142 %************************************************************************
143 %*                                                                      *
144 \subsection{The persistent compiler state}
145 %*                                                                      *
146 %************************************************************************
147
148 \begin{code}
149 data PersistentCompilerState 
150    = PCS {
151         pcsPST    :: PackageSymbolTable,        -- Domain = non-home-package modules
152         pcsHP     :: RnMonad.HoldingPen,        -- Pre-slurped interface bits and pieces
153         pcsNS     :: NameSupply                 -- Allocate uniques for names
154      }
155
156 type PackageSymbolTable = ModuleEnv ModDetails
157
158 data NameSupply
159  = NS { nsUniqs  :: UniqSupply,
160         nsNames  :: FiniteMap (Module,OccName) Name     -- Ensures that one original name gets one unique
161         nsIParam :: FiniteMap OccName Name              -- Ensures that one implicit parameter name gets one unique
162    }
163 =======
164 >>>>>>> 1.9
165 =======
166
167 -- should be somewhere else?
168 emptyPCS :: IO PersistentCompilerState
169 emptyPCS = return (PersistentCompilerState 
170                       { pcs_modmap = emptyFM,
171                         pcs_pit    = emptyPIT,
172                         pcs_pst    = emptyPST,
173                         pcs_hp     = emptyHoldingPen })
174 >>>>>>> 1.10
175 \end{code}
176