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