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