Reorganisation of the source tree
[ghc-hetmet.git] / 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 MkId,
9
10         ghcPrimExports,
11         wiredInThings, basicKnownKeyNames,
12         primOpId,
13         
14         -- Random other things
15         maybeCharLikeCon, maybeIntLikeCon,
16
17         -- Class categories
18         isNumericClass, isStandardClass
19
20     ) where
21
22 #include "HsVersions.h"
23
24 import PrelNames        ( basicKnownKeyNames, 
25                           hasKey, charDataConKey, intDataConKey,
26                           numericClassKeys, standardClassKeys )
27
28 import PrimOp           ( PrimOp, allThePrimOps, primOpOcc, primOpTag, maxPrimOpTag )
29 import DataCon          ( DataCon )
30 import Id               ( Id, idName )
31 import MkId             ( mkPrimOpId, wiredInIds )
32 import MkId             -- All of it, for re-export
33 import Name             ( nameOccName )
34 import TysPrim          ( primTyCons )
35 import TysWiredIn       ( wiredInTyCons )
36 import HscTypes         ( TyThing(..), implicitTyThings, GenAvailInfo(..), RdrAvailInfo )
37 import Class            ( Class, classKey )
38 import Type             ( funTyCon )
39 import TyCon            ( tyConName )
40 import Util             ( isIn )
41
42 import Array            ( Array, array, (!) )
43 \end{code}
44
45 %************************************************************************
46 %*                                                                      *
47 \subsection[builtinNameInfo]{Lookup built-in names}
48 %*                                                                      *
49 %************************************************************************
50
51 We have two ``builtin name funs,'' one to look up @TyCons@ and
52 @Classes@, the other to look up values.
53
54 \begin{code}
55 wiredInThings :: [TyThing]
56 wiredInThings           
57   = concat
58     [           -- Wired in TyCons and their implicit Ids
59           tycon_things
60         , concatMap implicitTyThings tycon_things
61
62                 -- Wired in Ids
63         , map AnId wiredInIds
64
65                 -- PrimOps
66         , map (AnId . mkPrimOpId) allThePrimOps
67     ]
68   where
69     tycon_things = map ATyCon ([funTyCon] ++ primTyCons ++ wiredInTyCons)
70 \end{code}
71
72 We let a lot of "non-standard" values be visible, so that we can make
73 sense of them in interface pragmas. It's cool, though they all have
74 "non-standard" names, so they won't get past the parser in user code.
75
76 %************************************************************************
77 %*                                                                      *
78                 PrimOpIds
79 %*                                                                      *
80 %************************************************************************
81
82 \begin{code}
83 primOpIds :: Array Int Id       -- Indexed by PrimOp tag
84 primOpIds = array (1,maxPrimOpTag) [ (primOpTag op, mkPrimOpId op) 
85                                    | op <- allThePrimOps]
86
87 primOpId :: PrimOp -> Id
88 primOpId op = primOpIds ! primOpTag op
89 \end{code}
90
91
92 %************************************************************************
93 %*                                                                      *
94 \subsection{Export lists for pseudo-modules (GHC.Prim)}
95 %*                                                                      *
96 %************************************************************************
97
98 GHC.Prim "exports" all the primops and primitive types, some 
99 wired-in Ids.
100
101 \begin{code}
102 ghcPrimExports :: [RdrAvailInfo]
103 ghcPrimExports
104  = map (Avail . nameOccName . idName) ghcPrimIds ++
105    map (Avail . primOpOcc) allThePrimOps ++
106    [ AvailTC occ [occ] |
107      n <- funTyCon : primTyCons, let occ = nameOccName (tyConName n) 
108    ]
109 \end{code}
110
111
112 %************************************************************************
113 %*                                                                      *
114 \subsection{Built-in keys}
115 %*                                                                      *
116 %************************************************************************
117
118 ToDo: make it do the ``like'' part properly (as in 0.26 and before).
119
120 \begin{code}
121 maybeCharLikeCon, maybeIntLikeCon :: DataCon -> Bool
122 maybeCharLikeCon con = con `hasKey` charDataConKey
123 maybeIntLikeCon  con = con `hasKey` intDataConKey
124 \end{code}
125
126
127 %************************************************************************
128 %*                                                                      *
129 \subsection{Class predicates}
130 %*                                                                      *
131 %************************************************************************
132
133 \begin{code}
134 isNumericClass, isStandardClass :: Class -> Bool
135
136 isNumericClass     clas = classKey clas `is_elem` numericClassKeys
137 isStandardClass    clas = classKey clas `is_elem` standardClassKeys
138 is_elem = isIn "is_X_Class"
139 \end{code}