[project @ 2000-10-11 14:51:02 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 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           -> HomeModMap              -- ModuleName -> Module
44           -> HomeSymbolTable         -- for home module ModDetails          
45           -> PersistentCompilerState -- IN: persistent compiler state
46           -> IO CompResult
47
48 cmCompile finder summary old_iface hst pcs
49    = do putStrLn ("cmCompile: compiling " ++ name_of_summary summary)
50         return (CompOK (error "cmCompile:modDetails")
51                        (Just (error "cmCompile:modIFace", 
52                               --error "cmCompile:Linkable"
53                               --LM (name_of_summary summary) [] 
54                               LM (name_of_summary summary) []
55                               ))
56                        pcs
57                        []
58                )
59
60 data CompResult
61    = CompOK   ModDetails  -- new details (HST additions)
62               (Maybe (ModIFace, Linkable))
63                        -- summary and code; Nothing => compilation not reqd
64                        -- (old summary and code are still valid)
65               PersistentCompilerState -- updated PCS
66               [SDoc]                  -- warnings
67
68    | CompErrs PersistentCompilerState -- updated PCS
69               [SDoc]                  -- errors
70               [SDoc]                  -- warnings
71
72 emptyPCS :: IO PersistentCompilerState
73 emptyPCS = return (PersistentCompilerState 
74                       { pcs_modmap = emptyFM,
75                         pcs_pit    = emptyPIT,
76                         pcs_pst    = emptyPST,
77                         pcs_hp     = emptyHoldingPen })
78
79 -- These two are only here to avoid recursion between CmCompile and
80 -- CompManager.  They really ought to be in the latter.
81 type ModuleEnv a = UniqFM a   -- Domain is Module
82
83 type HomeModMap         = FiniteMap ModuleName Module -- domain: home mods only
84 type HomeSymbolTable    = ModuleEnv ModDetails        -- ditto
85 type HomeInterfaceTable = ModuleEnv ModIFace
86
87 data PersistentCompilerState 
88    = PersistentCompilerState {
89         pcs_modmap :: PackageModMap,         -- domain: package mods only
90         pcs_pit    :: PackageInterfaceTable, -- Package interface table
91         pcs_pst    :: PackageSymbolTable,    -- Package symbol table
92         pcs_hp     :: HoldingPen             -- pre slurped interface bits and pieces
93      }
94
95 type PackageModMap         = FiniteMap ModuleName Module
96 type PackageInterfaceTable = ModuleEnv ModIFace
97 type PackageSymbolTable    = ModuleEnv ModDetails
98
99 emptyPIT :: PackageInterfaceTable
100 emptyPIT = emptyFM
101
102 emptyPST :: PackageSymbolTable
103 emptyPST = emptyFM
104
105 -- ModIFace is nearly the same as RnMonad.ParsedIface.
106 -- Right now it's identical :)
107 data ModIFace 
108    = ModIFace {
109         mi_mod       :: Module,                   -- Complete with package info
110         mi_vers      :: Version,                  -- Module version number
111         mi_orphan    :: WhetherHasOrphans,        -- Whether this module has orphans
112         mi_usages    :: [ImportVersion OccName],  -- Usages
113         mi_exports   :: [ExportItem],             -- Exports
114         mi_insts     :: [RdrNameInstDecl],        -- Local instance declarations
115         mi_decls     :: [(Version, RdrNameHsDecl)],    -- Local definitions
116         mi_fixity    :: (Version, [RdrNameFixitySig]), -- Local fixity declarations, 
117                                                        -- with their version
118         mi_rules     :: (Version, [RdrNameRuleDecl]),  -- Rules, with their version
119         mi_deprecs   :: [RdrNameDeprecation]           -- Deprecations
120      }
121
122 data ModDetails
123    = ModDetails {
124         moduleExports :: Avails,
125         moduleEnv     :: GlobalRdrEnv,           -- == FM RdrName [Name]
126         typeEnv       :: FiniteMap Name TyThing, -- TyThing is in TcEnv.lhs
127         instEnv       :: InstEnv,
128         fixityEnv     :: FiniteMap Name Fixity,
129         ruleEnv       :: FiniteMap Id [CoreRule]
130      }
131
132 -- This should eventually replace RnMonad.Ifaces
133 data HoldingPen
134    = HoldingPen {
135         iDecls :: DeclsMap,     -- A single, global map of Names to decls
136
137         iInsts :: IfaceInsts,
138         -- The as-yet un-slurped instance decls; this bag is depleted when we
139         -- slurp an instance decl so that we don't slurp the same one twice.
140         -- Each is 'gated' by the names that must be available before
141         -- this instance decl is needed.
142
143         iRules :: IfaceRules
144         -- Similar to instance decls, only for rules
145      }
146
147 emptyHoldingPen :: HoldingPen
148 emptyHoldingPen = error "emptyHoldingPen:unimp"
149 \end{code}