[project @ 2000-10-30 17:18:26 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, 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 wiredInTyConThings tc
74    = ATyCon tc : [ AnId n | dc <- tyConDataConsIfAvailable tc, 
75                             n  <- [dataConId dc, dataConWrapId dc] ]
76                         -- Synonyms return empty list of constructors
77
78 wiredInThingEnv :: TypeEnv
79 wiredInThingEnv = mkTypeEnv wiredInThings
80 \end{code}
81
82 We let a lot of "non-standard" values be visible, so that we can make
83 sense of them in interface pragmas. It's cool, though they all have
84 "non-standard" names, so they won't get past the parser in user code.
85
86
87 %************************************************************************
88 %*                                                                      *
89 \subsection{RdrNames for the primops}
90 %*                                                                      *
91 %************************************************************************
92
93 These can't be in PrelNames, because we get the RdrName from the PrimOp,
94 which is above PrelNames in the module hierarchy.
95
96 \begin{code}
97 eqH_Char_RDR    = primOpRdrName CharEqOp
98 ltH_Char_RDR    = primOpRdrName CharLtOp
99 eqH_Word_RDR    = primOpRdrName WordEqOp
100 ltH_Word_RDR    = primOpRdrName WordLtOp
101 eqH_Addr_RDR    = primOpRdrName AddrEqOp
102 ltH_Addr_RDR    = primOpRdrName AddrLtOp
103 eqH_Float_RDR   = primOpRdrName FloatEqOp
104 ltH_Float_RDR   = primOpRdrName FloatLtOp
105 eqH_Double_RDR  = primOpRdrName DoubleEqOp
106 ltH_Double_RDR  = primOpRdrName DoubleLtOp
107 eqH_Int_RDR     = primOpRdrName IntEqOp
108 ltH_Int_RDR     = primOpRdrName IntLtOp
109 geH_RDR         = primOpRdrName IntGeOp
110 leH_RDR         = primOpRdrName IntLeOp
111 minusH_RDR      = primOpRdrName IntSubOp
112
113 tagToEnumH_RDR  = primOpRdrName TagToEnumOp
114 \end{code}
115
116
117 %************************************************************************
118 %*                                                                      *
119 \subsection{Built-in keys}
120 %*                                                                      *
121 %************************************************************************
122
123 ToDo: make it do the ``like'' part properly (as in 0.26 and before).
124
125 \begin{code}
126 maybeCharLikeCon, maybeIntLikeCon :: DataCon -> Bool
127 maybeCharLikeCon con = con `hasKey` charDataConKey
128 maybeIntLikeCon  con = con `hasKey` intDataConKey
129 \end{code}
130
131
132 %************************************************************************
133 %*                                                                      *
134 \subsection{Class predicates}
135 %*                                                                      *
136 %************************************************************************
137
138 \begin{code}
139 isCcallishClass, isCreturnableClass, isNoDictClass, 
140   isNumericClass, isStandardClass :: Class -> Bool
141
142 isNumericClass     clas = classKey clas `is_elem` numericClassKeys
143 isStandardClass    clas = classKey clas `is_elem` standardClassKeys
144 isCcallishClass    clas = classKey clas `is_elem` cCallishClassKeys
145 isCreturnableClass clas = classKey clas == cReturnableClassKey
146 isNoDictClass      clas = classKey clas `is_elem` noDictClassKeys
147 is_elem = isIn "is_X_Class"
148 \end{code}