[project @ 2000-11-06 08:15:20 by simonpj]
[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(..), TypeEnv, mkTypeEnv )
41
42 -- others:
43 import TyCon            ( tyConDataConsIfAvailable, tyConGenIds, TyCon )
44 import Class            ( Class, classKey )
45 import Type             ( funTyCon )
46 import Util             ( isIn )
47 \end{code}
48
49 %************************************************************************
50 %*                                                                      *
51 \subsection[builtinNameInfo]{Lookup built-in names}
52 %*                                                                      *
53 %************************************************************************
54
55 We have two ``builtin name funs,'' one to look up @TyCons@ and
56 @Classes@, the other to look up values.
57
58 \begin{code}
59 wiredInThings :: [TyThing]
60 wiredInThings
61   = concat
62     [           -- Wired in TyCons
63           concat (map wiredInTyConThings ([funTyCon] ++ primTyCons ++ wiredInTyCons))
64
65                 -- Wired in Ids
66         , map AnId wiredInIds
67
68                 -- PrimOps
69         , map (AnId . mkPrimOpId) allThePrimOps
70     ]
71
72 wiredInTyConThings :: TyCon -> [TyThing]
73 -- This is a bit of a cheat (c.f. TcTyDecls.mkImplicitDataBinds
74 -- It assumes that wired in tycons have no record selectors
75 wiredInTyConThings tc
76    = [ATyCon tc] 
77    ++ [ AnId i | i <- tyConGenIds tc ]
78    ++ [ AnId n | dc <- tyConDataConsIfAvailable tc, 
79                  n  <- [dataConId dc, dataConWrapId dc] ] 
80                         -- Synonyms return empty list of constructors
81
82 wiredInThingEnv :: TypeEnv
83 wiredInThingEnv = mkTypeEnv wiredInThings
84 \end{code}
85
86 We let a lot of "non-standard" values be visible, so that we can make
87 sense of them in interface pragmas. It's cool, though they all have
88 "non-standard" names, so they won't get past the parser in user code.
89
90
91 %************************************************************************
92 %*                                                                      *
93 \subsection{RdrNames for the primops}
94 %*                                                                      *
95 %************************************************************************
96
97 These can't be in PrelNames, because we get the RdrName from the PrimOp,
98 which is above PrelNames in the module hierarchy.
99
100 \begin{code}
101 eqH_Char_RDR    = primOpRdrName CharEqOp
102 ltH_Char_RDR    = primOpRdrName CharLtOp
103 eqH_Word_RDR    = primOpRdrName WordEqOp
104 ltH_Word_RDR    = primOpRdrName WordLtOp
105 eqH_Addr_RDR    = primOpRdrName AddrEqOp
106 ltH_Addr_RDR    = primOpRdrName AddrLtOp
107 eqH_Float_RDR   = primOpRdrName FloatEqOp
108 ltH_Float_RDR   = primOpRdrName FloatLtOp
109 eqH_Double_RDR  = primOpRdrName DoubleEqOp
110 ltH_Double_RDR  = primOpRdrName DoubleLtOp
111 eqH_Int_RDR     = primOpRdrName IntEqOp
112 ltH_Int_RDR     = primOpRdrName IntLtOp
113 geH_RDR         = primOpRdrName IntGeOp
114 leH_RDR         = primOpRdrName IntLeOp
115 minusH_RDR      = primOpRdrName IntSubOp
116
117 tagToEnumH_RDR  = primOpRdrName TagToEnumOp
118 \end{code}
119
120
121 %************************************************************************
122 %*                                                                      *
123 \subsection{Built-in keys}
124 %*                                                                      *
125 %************************************************************************
126
127 ToDo: make it do the ``like'' part properly (as in 0.26 and before).
128
129 \begin{code}
130 maybeCharLikeCon, maybeIntLikeCon :: DataCon -> Bool
131 maybeCharLikeCon con = con `hasKey` charDataConKey
132 maybeIntLikeCon  con = con `hasKey` intDataConKey
133 \end{code}
134
135
136 %************************************************************************
137 %*                                                                      *
138 \subsection{Class predicates}
139 %*                                                                      *
140 %************************************************************************
141
142 \begin{code}
143 isCcallishClass, isCreturnableClass, isNoDictClass, 
144   isNumericClass, isStandardClass :: Class -> Bool
145
146 isNumericClass     clas = classKey clas `is_elem` numericClassKeys
147 isStandardClass    clas = classKey clas `is_elem` standardClassKeys
148 isCcallishClass    clas = classKey clas `is_elem` cCallishClassKeys
149 isCreturnableClass clas = classKey clas == cReturnableClassKey
150 isNoDictClass      clas = classKey clas `is_elem` noDictClassKeys
151 is_elem = isIn "is_X_Class"
152 \end{code}