[project @ 2000-10-16 13:13:41 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                    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 Auxiliary definitions
103
104 \begin{code}
105 {- I DONT think this should be here -- should be in HscTypes 
106 type DeprecationEnv = NameEnv DeprecTxt         -- Give reason for deprecation
107
108 type GlobalRdrEnv = RdrNameEnv [Name]   -- The list is because there may be name clashes
109                                         -- These only get reported on lookup,
110                                         -- not on construction
111
112 data GenAvailInfo name  = Avail name     -- An ordinary identifier
113                         | AvailTC name   -- The name of the type or class
114                                   [name] -- The available pieces of type/class.
115                                          -- NB: If the type or class is itself
116                                          -- to be in scope, it must be in this list.
117                                          -- Thus, typically: AvailTC Eq [Eq, ==, /=]
118                         deriving( Eq )
119                         -- Equality used when deciding if the interface has changed
120
121 type AvailEnv     = NameEnv AvailInfo   -- Maps a Name to the AvailInfo that contains it
122 type AvailInfo    = GenAvailInfo Name
123 type RdrAvailInfo = GenAvailInfo OccName
124 type Avails       = [AvailInfo]
125 -}
126 \end{code}
127
128
129 %************************************************************************
130 %*                                                                      *
131 \subsection{The persistent compiler state}
132 %*                                                                      *
133 %************************************************************************
134
135 \begin{code}
136 data PersistentCompilerState 
137    = PCS {
138         pcsPST    :: PackageSymbolTable,        -- Domain = non-home-package modules
139         pcsHP     :: RnMonad.HoldingPen,        -- Pre-slurped interface bits and pieces
140         pcsNS     :: NameSupply                 -- Allocate uniques for names
141      }
142
143 type PackageSymbolTable = ModuleEnv ModDetails
144
145 data NameSupply
146  = NS { nsUniqs  :: UniqSupply,
147         nsNames  :: FiniteMap (Module,OccName) Name     -- Ensures that one original name gets one unique
148         nsIParam :: FiniteMap OccName Name              -- Ensures that one implicit parameter name gets one unique
149    }
150 =======
151 >>>>>>> 1.9
152 =======
153
154 -- should be somewhere else?
155 emptyPCS :: IO PersistentCompilerState
156 emptyPCS = return (PersistentCompilerState 
157                       { pcs_modmap = emptyFM,
158                         pcs_pit    = emptyPIT,
159                         pcs_pst    = emptyPST,
160                         pcs_hp     = emptyHoldingPen })
161 >>>>>>> 1.10
162 \end{code}
163