CmCompile.lhs 5.71 KB
Newer Older
1
%
2
% (c) The University of Glasgow, 2000
3
4
5
6
7
%
\section[CmCompile]{Compiler for GHCI}

\begin{code}
module CmCompile ( cmCompile,
8
9
10
11
12
                   ModDetails,       -- abstract
                   ModIFace,         -- abstract
                   PCS, emptyPCS,    -- abstract
                   HST,              -- not abstract (CM needs to see it)
                   HIT,              -- ditto
13
14
15
16
17
18
                   CompResult(..)
                 )
where

#include "HsVersions.h"

19
import CmLink		( Linkable(..) )
20
21
import Outputable	( SDoc )
import CmFind		( Finder )
22
import CmSummarise	( ModSummary, name_of_summary )
23
import FiniteMap	( FiniteMap, emptyFM )
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39

import Module		( Module )
import RnMonad		( Avails, GlobalRdrEnv, DeclsMap, 
                          WhetherHasOrphans, ImportVersion,
                          IfaceInsts, IfaceRules, ExportItem )
import TcEnv		( TyThing, InstEnv )
import Name		( Name, OccName )
import BasicTypes	( Fixity, Version )
import Id		( Id )
import CoreSyn		( CoreRule )
import RdrHsSyn		( RdrNameDeprecation, RdrNameRuleDecl, RdrNameFixitySig,
                          RdrNameHsDecl, RdrNameInstDecl )


\end{code}
\begin{code}
40
41
42
43
44
45
cmCompile :: Finder                  -- to find modules
          -> ModSummary              -- summary, including source
          -> Maybe ModIFace          -- old interface, if available
          -> HomeModMap              -- ModuleName -> Module
          -> HomeSymbolTable         -- for home module ModDetails          
          -> PersistentCompilerState -- IN: persistent compiler state
46
47
          -> IO CompResult

48
49
50
51
52
53
54
55
56
57
58
cmCompile finder summary old_iface hst pcs
   = do putStrLn ("cmCompile: compiling " ++ name_of_summary summary)
        return (CompOK (error "cmCompile:modDetails")
                       (Just (error "cmCompile:modIFace", 
                              --error "cmCompile:Linkable"
                              --LM (name_of_summary summary) [] 
                              LM (name_of_summary summary) []
                              ))
                       pcs
                       []
               )
59
60
61
62
63
64

data CompResult
   = CompOK   ModDetails  -- new details (HST additions)
              (Maybe (ModIFace, Linkable))
                       -- summary and code; Nothing => compilation not reqd
                       -- (old summary and code are still valid)
65
66
              PersistentCompilerState -- updated PCS
              [SDoc]                  -- warnings
67

68
69
70
   | CompErrs PersistentCompilerState -- updated PCS
              [SDoc]                  -- errors
              [SDoc]                  -- warnings
71

72
73
74
75
76
77
emptyPCS :: IO PersistentCompilerState
emptyPCS = return (PersistentCompilerState 
                      { pcs_modmap = emptyFM,
                        pcs_pit    = emptyPIT,
                        pcs_pst    = emptyPST,
                        pcs_hp     = emptyHoldingPen })
78
79
80

-- These two are only here to avoid recursion between CmCompile and
-- CompManager.  They really ought to be in the latter.
81
type ModuleEnv a = UniqFM a   -- Domain is Module
82

83
84
85
type HomeModMap         = FiniteMap ModuleName Module -- domain: home mods only
type HomeSymbolTable    = ModuleEnv ModDetails        -- ditto
type HomeInterfaceTable = ModuleEnv ModIFace
86

87
88
89
90
91
92
93
data PersistentCompilerState 
   = PersistentCompilerState {
        pcs_modmap :: PackageModMap,         -- domain: package mods only
        pcs_pit    :: PackageInterfaceTable, -- Package interface table
        pcs_pst    :: PackageSymbolTable,    -- Package symbol table
        pcs_hp     :: HoldingPen             -- pre slurped interface bits and pieces
     }
94

95
96
97
type PackageModMap         = FiniteMap ModuleName Module
type PackageInterfaceTable = ModuleEnv ModIFace
type PackageSymbolTable    = ModuleEnv ModDetails
98

99
emptyPIT :: PackageInterfaceTable
100
101
emptyPIT = emptyFM

102
emptyPST :: PackageSymbolTable
103
104
emptyPST = emptyFM

105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
-- ModIFace is nearly the same as RnMonad.ParsedIface.
-- Right now it's identical :)
data ModIFace 
   = ModIFace {
        mi_mod       :: Module,                   -- Complete with package info
        mi_vers      :: Version,                  -- Module version number
        mi_orphan    :: WhetherHasOrphans,        -- Whether this module has orphans
        mi_usages    :: [ImportVersion OccName],  -- Usages
        mi_exports   :: [ExportItem],             -- Exports
        mi_insts     :: [RdrNameInstDecl],        -- Local instance declarations
        mi_decls     :: [(Version, RdrNameHsDecl)],    -- Local definitions
        mi_fixity    :: (Version, [RdrNameFixitySig]), -- Local fixity declarations, 
                                                       -- with their version
        mi_rules     :: (Version, [RdrNameRuleDecl]),  -- Rules, with their version
        mi_deprecs   :: [RdrNameDeprecation]           -- Deprecations
     }

data ModDetails
   = ModDetails {
        moduleExports :: Avails,
        moduleEnv     :: GlobalRdrEnv,           -- == FM RdrName [Name]
        typeEnv       :: FiniteMap Name TyThing, -- TyThing is in TcEnv.lhs
        instEnv       :: InstEnv,
        fixityEnv     :: FiniteMap Name Fixity,
        ruleEnv       :: FiniteMap Id [CoreRule]
     }

-- This should eventually replace RnMonad.Ifaces
data HoldingPen
   = HoldingPen {
        iDecls :: DeclsMap,     -- A single, global map of Names to decls

        iInsts :: IfaceInsts,
        -- The as-yet un-slurped instance decls; this bag is depleted when we
        -- slurp an instance decl so that we don't slurp the same one twice.
        -- Each is 'gated' by the names that must be available before
        -- this instance decl is needed.

        iRules :: IfaceRules
        -- Similar to instance decls, only for rules
     }
146
147
148

emptyHoldingPen :: HoldingPen
emptyHoldingPen = error "emptyHoldingPen:unimp"
149
\end{code}