2 % (c) The University of Glasgow, 2000
4 \section[CmCompile]{Compiler for GHCI}
7 module CmCompile ( cmCompile,
8 ModDetails, -- abstract
10 PCS, emptyPCS, -- abstract
11 HST, -- not abstract (CM needs to see it)
17 #include "HsVersions.h"
19 import CmLink ( Linkable(..) )
20 import Outputable ( SDoc )
21 import CmFind ( Finder )
22 import CmSummarise ( ModSummary, name_of_summary )
23 import FiniteMap ( FiniteMap, emptyFM )
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 )
33 import CoreSyn ( CoreRule )
34 import RdrHsSyn ( RdrNameDeprecation, RdrNameRuleDecl, RdrNameFixitySig,
35 RdrNameHsDecl, RdrNameInstDecl )
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
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) []
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
68 | CompErrs PersistentCompilerState -- updated PCS
72 emptyPCS :: IO PersistentCompilerState
73 emptyPCS = return (PersistentCompilerState
74 { pcs_modmap = emptyFM,
77 pcs_hp = emptyHoldingPen })
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
83 type HomeModMap = FiniteMap ModuleName Module -- domain: home mods only
84 type HomeSymbolTable = ModuleEnv ModDetails -- ditto
85 type HomeInterfaceTable = ModuleEnv ModIFace
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
95 type PackageModMap = FiniteMap ModuleName Module
96 type PackageInterfaceTable = ModuleEnv ModIFace
97 type PackageSymbolTable = ModuleEnv ModDetails
99 emptyPIT :: PackageInterfaceTable
102 emptyPST :: PackageSymbolTable
105 -- ModIFace is nearly the same as RnMonad.ParsedIface.
106 -- Right now it's identical :)
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
124 moduleExports :: Avails,
125 moduleEnv :: GlobalRdrEnv, -- == FM RdrName [Name]
126 typeEnv :: FiniteMap Name TyThing, -- TyThing is in TcEnv.lhs
128 fixityEnv :: FiniteMap Name Fixity,
129 ruleEnv :: FiniteMap Id [CoreRule]
132 -- This should eventually replace RnMonad.Ifaces
135 iDecls :: DeclsMap, -- A single, global map of Names to decls
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.
144 -- Similar to instance decls, only for rules
147 emptyHoldingPen :: HoldingPen
148 emptyHoldingPen = error "emptyHoldingPen:unimp"