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