PrelInfo.lhs 4.39 KB
Newer Older
1
%
2
% (c) The GRASP/AQUA Project, Glasgow University, 1992-1998
3
4
5
6
7
%
\section[PrelInfo]{The @PrelInfo@ interface to the compiler's prelude knowledge}

\begin{code}
module PrelInfo (
8
9
	module MkId,

10
	ghcPrimExports,
11
12
	wiredInThings, basicKnownKeyNames,
	primOpId,
13
14
	
	-- Random other things
15
	maybeCharLikeCon, maybeIntLikeCon,
16
17

	-- Class categories
18
	isNumericClass, isStandardClass
19

20
21
    ) where

22
#include "HsVersions.h"
sof's avatar
sof committed
23

24
25
import PrelNames	( basicKnownKeyNames, 
			  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
32
import MkId		( mkPrimOpId, wiredInIds )
import MkId		-- All of it, for re-export
33
import Name		( nameOccName )
34
35
import TysPrim		( primTyCons )
import TysWiredIn	( wiredInTyCons )
36
37
38
import HscTypes 	( TyThing(..), implicitTyThings, GenAvailInfo(..), RdrAvailInfo )
import Class	 	( Class, classKey )
import Type		( funTyCon )
39
import TyCon		( tyConName )
40
import Util		( isIn )
41
42

import Array		( Array, array, (!) )
43
44
45
46
47
48
49
50
\end{code}

%************************************************************************
%*									*
\subsection[builtinNameInfo]{Lookup built-in names}
%*									*
%************************************************************************

51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
Notes about wired in things
~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Wired-in things are Ids/TyCons that are completely known to the compiler.
  They are global values in GHC, (e.g.  listTyCon :: TyCon).

* A wired in Name contains the thing itself inside the Name: 
	see Name.wiredInNameTyThing_maybe
  (E.g. listTyConName contains listTyCon. 

* The name cache is initialised with (the names of) all wired-in things

* The type checker sees if the Name is wired in before looking up 
  the name in the type environment.  So the type envt itself contains
  no wired in things.

* MkIface prunes out wired-in things before putting them in an interface file.
  So interface files never contain wired-in things.

69
70

\begin{code}
71
wiredInThings :: [TyThing]
72
wiredInThings		
73
  = concat
74
75
    [		-- Wired in TyCons and their implicit Ids
	  tycon_things
76
	, concatMap implicitTyThings tycon_things
77
78

		-- Wired in Ids
79
	, map AnId wiredInIds
80

81
		-- PrimOps
82
	, map (AnId . mkPrimOpId) allThePrimOps
83
    ]
84
85
  where
    tycon_things = map ATyCon ([funTyCon] ++ primTyCons ++ wiredInTyCons)
86
87
88
89
90
\end{code}

We let a lot of "non-standard" values be visible, so that we can make
sense of them in interface pragmas. It's cool, though they all have
"non-standard" names, so they won't get past the parser in user code.
91

92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
%************************************************************************
%*									*
		PrimOpIds
%*									*
%************************************************************************

\begin{code}
primOpIds :: Array Int Id	-- Indexed by PrimOp tag
primOpIds = array (1,maxPrimOpTag) [ (primOpTag op, mkPrimOpId op) 
				   | op <- allThePrimOps]

primOpId :: PrimOp -> Id
primOpId op = primOpIds ! primOpTag op
\end{code}


108
109
110
111
112
113
114
%************************************************************************
%*									*
\subsection{Export lists for pseudo-modules (GHC.Prim)}
%*									*
%************************************************************************

GHC.Prim "exports" all the primops and primitive types, some 
115
wired-in Ids.
116
117
118

\begin{code}
ghcPrimExports :: [RdrAvailInfo]
119
ghcPrimExports
120
 = map (Avail . nameOccName . idName) ghcPrimIds ++
121
122
123
124
125
   map (Avail . primOpOcc) allThePrimOps ++
   [ AvailTC occ [occ] |
     n <- funTyCon : primTyCons, let occ = nameOccName (tyConName n) 
   ]
\end{code}
126
127


128
129
130
131
132
%************************************************************************
%*									*
\subsection{Built-in keys}
%*									*
%************************************************************************
133

134
ToDo: make it do the ``like'' part properly (as in 0.26 and before).
135

136
\begin{code}
137
maybeCharLikeCon, maybeIntLikeCon :: DataCon -> Bool
138
139
maybeCharLikeCon con = con `hasKey` charDataConKey
maybeIntLikeCon  con = con `hasKey` intDataConKey
140
\end{code}
141

142

143
144
%************************************************************************
%*									*
145
\subsection{Class predicates}
146
147
148
149
%*									*
%************************************************************************

\begin{code}
150
isNumericClass, isStandardClass :: Class -> Bool
sof's avatar
sof committed
151
152
153

isNumericClass     clas = classKey clas `is_elem` numericClassKeys
isStandardClass    clas = classKey clas `is_elem` standardClassKeys
154
is_elem = isIn "is_X_Class"
155
\end{code}