8c5ceb667c906589835f6aef6bf1b3ab7e95dafa
[ghc-hetmet.git] / ghc / compiler / prelude / PrelInfo.lhs
1 %
2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1998
3 %
4 \section[PrelInfo]{The @PrelInfo@ interface to the compiler's prelude knowledge}
5
6 \begin{code}
7 module PrelInfo (
8         module PrelNames,
9         module MkId,
10
11         wiredInThings,  -- Names of wired in things
12         wiredInThingEnv,
13         
14         -- Primop RdrNames
15         eqH_Char_RDR,   ltH_Char_RDR,   eqH_Word_RDR,  ltH_Word_RDR, 
16         eqH_Addr_RDR,   ltH_Addr_RDR,   eqH_Float_RDR, ltH_Float_RDR, 
17         eqH_Double_RDR, ltH_Double_RDR, eqH_Int_RDR,   ltH_Int_RDR,
18         geH_RDR, leH_RDR, minusH_RDR, tagToEnumH_RDR, 
19
20         -- Random other things
21         maybeCharLikeCon, maybeIntLikeCon,
22
23         -- Class categories
24         isCcallishClass, isCreturnableClass, isNoDictClass, 
25         isNumericClass, isStandardClass
26
27     ) where
28
29 #include "HsVersions.h"
30
31 -- friends:
32 import PrelNames        -- Prelude module names
33
34 import PrimOp           ( PrimOp(..), allThePrimOps, primOpRdrName )
35 import DataCon          ( DataCon, dataConId, dataConWrapId )
36 import MkId             ( mkPrimOpId, wiredInIds )
37 import MkId             -- All of it, for re-export
38 import TysPrim          ( primTyCons )
39 import TysWiredIn       ( wiredInTyCons )
40 import HscTypes         ( TyThing(..) )
41
42 -- others:
43 import Name             ( getName, NameEnv, mkNameEnv )
44 import TyCon            ( tyConDataConsIfAvailable, TyCon )
45 import Class            ( Class, classKey )
46 import Type             ( funTyCon )
47 import Util             ( isIn )
48 import Outputable       ( ppr, pprPanic )
49 \end{code}
50
51 %************************************************************************
52 %*                                                                      *
53 \subsection[builtinNameInfo]{Lookup built-in names}
54 %*                                                                      *
55 %************************************************************************
56
57 We have two ``builtin name funs,'' one to look up @TyCons@ and
58 @Classes@, the other to look up values.
59
60 \begin{code}
61 wiredInThings :: [TyThing]
62 wiredInThings
63   = concat
64     [           -- Wired in TyCons
65           concat (map wiredInTyConThings ([funTyCon] ++ primTyCons ++ wiredInTyCons))
66
67                 -- Wired in Ids
68         , map AnId wiredInIds
69
70                 -- PrimOps
71         , map (AnId . mkPrimOpId) allThePrimOps
72     ]
73
74 wiredInTyConThings :: TyCon -> [TyThing]
75 wiredInTyConThings tc
76    = ATyCon tc : [ AnId n | dc <- tyConDataConsIfAvailable tc, 
77                             n  <- [dataConId dc, dataConWrapId dc] ]
78                         -- Synonyms return empty list of constructors
79
80 wiredInThingEnv :: NameEnv TyThing
81 wiredInThingEnv = mkNameEnv [ (getName thing, thing) | thing <- wiredInThings ]
82 \end{code}
83
84 We let a lot of "non-standard" values be visible, so that we can make
85 sense of them in interface pragmas. It's cool, though they all have
86 "non-standard" names, so they won't get past the parser in user code.
87
88
89 %************************************************************************
90 %*                                                                      *
91 \subsection{RdrNames for the primops}
92 %*                                                                      *
93 %************************************************************************
94
95 These can't be in PrelNames, because we get the RdrName from the PrimOp,
96 which is above PrelNames in the module hierarchy.
97
98 \begin{code}
99 eqH_Char_RDR    = primOpRdrName CharEqOp
100 ltH_Char_RDR    = primOpRdrName CharLtOp
101 eqH_Word_RDR    = primOpRdrName WordEqOp
102 ltH_Word_RDR    = primOpRdrName WordLtOp
103 eqH_Addr_RDR    = primOpRdrName AddrEqOp
104 ltH_Addr_RDR    = primOpRdrName AddrLtOp
105 eqH_Float_RDR   = primOpRdrName FloatEqOp
106 ltH_Float_RDR   = primOpRdrName FloatLtOp
107 eqH_Double_RDR  = primOpRdrName DoubleEqOp
108 ltH_Double_RDR  = primOpRdrName DoubleLtOp
109 eqH_Int_RDR     = primOpRdrName IntEqOp
110 ltH_Int_RDR     = primOpRdrName IntLtOp
111 geH_RDR         = primOpRdrName IntGeOp
112 leH_RDR         = primOpRdrName IntLeOp
113 minusH_RDR      = primOpRdrName IntSubOp
114
115 tagToEnumH_RDR  = primOpRdrName TagToEnumOp
116 \end{code}
117
118
119 %************************************************************************
120 %*                                                                      *
121 \subsection{Built-in keys}
122 %*                                                                      *
123 %************************************************************************
124
125 ToDo: make it do the ``like'' part properly (as in 0.26 and before).
126
127 \begin{code}
128 maybeCharLikeCon, maybeIntLikeCon :: DataCon -> Bool
129 maybeCharLikeCon con = con `hasKey` charDataConKey
130 maybeIntLikeCon  con = con `hasKey` intDataConKey
131 \end{code}
132
133
134 %************************************************************************
135 %*                                                                      *
136 \subsection{Class predicates}
137 %*                                                                      *
138 %************************************************************************
139
140 \begin{code}
141 isCcallishClass, isCreturnableClass, isNoDictClass, 
142   isNumericClass, isStandardClass :: Class -> Bool
143
144 isNumericClass     clas = classKey clas `is_elem` numericClassKeys
145 isStandardClass    clas = classKey clas `is_elem` standardClassKeys
146 isCcallishClass    clas = classKey clas `is_elem` cCallishClassKeys
147 isCreturnableClass clas = classKey clas == cReturnableClassKey
148 isNoDictClass      clas = classKey clas `is_elem` noDictClassKeys
149 is_elem = isIn "is_X_Class"
150 \end{code}