2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1996
4 \section[PrelInfo]{The @PrelInfo@ interface to the compiler's prelude knowledge}
7 #include "HsVersions.h"
11 -- finite maps for built-in things (for the renamer and typechecker):
12 builtinNameInfo, builtinNameMaps,
13 builtinValNamesMap, builtinTcNamesMap,
16 SYN_IE(BuiltinKeys), SYN_IE(BuiltinIdInfos),
18 maybeCharLikeTyCon, maybeIntLikeTyCon
22 IMPORT_DELOOPER(PrelLoop) ( primOpNameInfo )
23 IMPORT_DELOOPER(IdLoop) ( SpecEnv )
26 import PrelMods -- Prelude module names
27 import PrelVals -- VALUES
28 import PrimOp ( PrimOp(..), allThePrimOps )
29 import PrimRep ( PrimRep(..) )
30 import TysPrim -- TYPES
34 import FiniteMap ( FiniteMap, emptyFM, listToFM )
35 import Id ( mkTupleCon, GenId, SYN_IE(Id) )
36 import Maybes ( catMaybes )
37 import Name ( origName, OrigName(..), Name )
38 import RnHsSyn ( RnName(..) )
39 import TyCon ( tyConDataCons, mkFunTyCon, mkTupleTyCon, TyCon )
41 import UniqFM ( UniqFM, emptyUFM, listToUFM )
42 import Unique -- *Key stuff
43 import Util ( nOfThem, panic )
46 %************************************************************************
48 \subsection[builtinNameInfo]{Lookup built-in names}
50 %************************************************************************
52 We have two ``builtin name funs,'' one to look up @TyCons@ and
53 @Classes@, the other to look up values.
56 builtinNameInfo :: ( BuiltinNames, BuiltinKeys, BuiltinIdInfos )
58 type BuiltinNames = (FiniteMap OrigName RnName, -- WiredIn Ids
59 FiniteMap OrigName RnName) -- WiredIn TyCons
60 -- Two maps because "[]" is in both...
62 type BuiltinKeys = FiniteMap OrigName (Unique, Name -> RnName)
63 -- Names with known uniques
65 type BuiltinIdInfos = UniqFM IdInfo -- Info for known unique Ids
67 builtinNameMaps = case builtinNameInfo of { (x,_,_) -> x }
68 builtinKeysMap = case builtinNameInfo of { (_,x,_) -> x }
69 builtinValNamesMap = fst builtinNameMaps
70 builtinTcNamesMap = snd builtinNameMaps
73 = ( (listToFM assoc_val_wired, listToFM assoc_tc_wired)
75 , listToUFM assoc_id_infos
81 concat (map pcDataConWiredInInfo g_con_tycons),
82 concat (map pcDataConWiredInInfo data_tycons),
85 map pcIdWiredInInfo wired_in_ids,
91 map pcTyConWiredInInfo prim_tycons,
92 map pcTyConWiredInInfo g_tycons,
93 map pcTyConWiredInInfo data_tycons
105 id_keys = map id_key id_keys_infos
106 id_key (str_mod, uniq, info) = (str_mod, (uniq, RnImplicit))
108 assoc_id_infos = catMaybes (map assoc_info id_keys_infos)
109 assoc_info (str_mod, uniq, Just info) = Just (uniq, info)
110 assoc_info (str_mod, uniq, Nothing) = Nothing
114 We let a lot of "non-standard" values be visible, so that we can make
115 sense of them in interface pragmas. It's cool, though they all have
116 "non-standard" names, so they won't get past the parser in user code.
118 The WiredIn TyCons and DataCons ...
129 , foreignObjPrimTyCon
130 , mutableArrayPrimTyCon
131 , mutableByteArrayPrimTyCon
140 = mkFunTyCon : g_con_tycons
143 = listTyCon : mkTupleTyCon 0 : [mkTupleTyCon i | i <- [2..37] ]
145 min_nonprim_tycon_list -- used w/ HideMostBuiltinNames
153 , return2GMPsTyCon -- ADR asked for these last two (WDP 94/11)
154 , returnIntAndGMPTyCon
170 , returnIntAndGMPTyCon
173 , stateAndAddrPrimTyCon
174 , stateAndArrayPrimTyCon
175 , stateAndByteArrayPrimTyCon
176 , stateAndCharPrimTyCon
177 , stateAndDoublePrimTyCon
178 , stateAndFloatPrimTyCon
179 , stateAndForeignObjPrimTyCon
180 , stateAndIntPrimTyCon
181 , stateAndMutableArrayPrimTyCon
182 , stateAndMutableByteArrayPrimTyCon
183 , stateAndPtrPrimTyCon
184 , stateAndStablePtrPrimTyCon
185 , stateAndSynchVarPrimTyCon
186 , stateAndWordPrimTyCon
194 ToDo: Some of these should be moved to id_keys_infos!
205 , iRREFUT_PAT_ERROR_ID
210 , nON_EXHAUSTIVE_GUARDS_ERROR_ID
211 , nO_DEFAULT_METHOD_ERROR_ID
212 , nO_EXPLICIT_METHOD_ERROR_ID
231 , unpackCStringAppendId
232 , unpackCStringFoldrId
237 pcTyConWiredInInfo :: TyCon -> (OrigName, RnName)
238 pcTyConWiredInInfo tc = (origName "pcTyConWiredInInfo" tc, WiredInTyCon tc)
240 pcDataConWiredInInfo :: TyCon -> [(OrigName, RnName)]
241 pcDataConWiredInInfo tycon
242 = [ (origName "pcDataConWiredInInfo" con, WiredInId con) | con <- tyConDataCons tycon ]
244 pcIdWiredInInfo :: Id -> (OrigName, RnName)
245 pcIdWiredInInfo id = (origName "pcIdWiredInInfo" id, WiredInId id)
248 WiredIn primitive numeric operations ...
251 = map prim_fn allThePrimOps ++ map funny_fn funny_name_primops
253 prim_fn op = case (primOpNameInfo op) of (s,n) -> ((OrigName gHC_BUILTINS s),n)
254 funny_fn (op,s) = case (primOpNameInfo op) of (_,n) -> ((OrigName gHC_BUILTINS s),n)
257 = [ (IntAddOp, SLIT("+#"))
258 , (IntSubOp, SLIT("-#"))
259 , (IntMulOp, SLIT("*#"))
260 , (IntGtOp, SLIT(">#"))
261 , (IntGeOp, SLIT(">=#"))
262 , (IntEqOp, SLIT("==#"))
263 , (IntNeOp, SLIT("/=#"))
264 , (IntLtOp, SLIT("<#"))
265 , (IntLeOp, SLIT("<=#"))
266 , (DoubleAddOp, SLIT("+##"))
267 , (DoubleSubOp, SLIT("-##"))
268 , (DoubleMulOp, SLIT("*##"))
269 , (DoubleDivOp, SLIT("/##"))
270 , (DoublePowerOp, SLIT("**##"))
271 , (DoubleGtOp, SLIT(">##"))
272 , (DoubleGeOp, SLIT(">=##"))
273 , (DoubleEqOp, SLIT("==##"))
274 , (DoubleNeOp, SLIT("/=##"))
275 , (DoubleLtOp, SLIT("<##"))
276 , (DoubleLeOp, SLIT("<=##"))
281 Ids, Synonyms, Classes and ClassOps with builtin keys.
282 For the Ids we may also have some builtin IdInfo.
284 id_keys_infos :: [(OrigName, Unique, Maybe IdInfo)]
286 = [ -- here because we use them in derived instances
287 (OrigName pRELUDE SLIT("&&"), andandIdKey, Nothing)
288 , (OrigName pRELUDE SLIT("."), composeIdKey, Nothing)
289 , (OrigName gHC__ SLIT("lex"), lexIdKey, Nothing)
290 , (OrigName pRELUDE SLIT("not"), notIdKey, Nothing)
291 , (OrigName pRELUDE SLIT("readParen"), readParenIdKey, Nothing)
292 , (OrigName pRELUDE SLIT("showParen"), showParenIdKey, Nothing)
293 , (OrigName pRELUDE SLIT("showString"), showStringIdKey,Nothing)
294 , (OrigName gHC__ SLIT("readList__"), ureadListIdKey, Nothing)
295 , (OrigName gHC__ SLIT("showList__"), ushowListIdKey, Nothing)
296 , (OrigName gHC__ SLIT("showSpace"), showSpaceIdKey, Nothing)
300 = [ (OrigName gHC__ SLIT("IO"), (iOTyConKey, RnImplicitTyCon))
301 , (OrigName pRELUDE SLIT("Ordering"), (orderingTyConKey, RnImplicitTyCon))
302 , (OrigName rATIO SLIT("Rational"), (rationalTyConKey, RnImplicitTyCon))
303 , (OrigName rATIO SLIT("Ratio"), (ratioTyConKey, RnImplicitTyCon))
306 -- this "class_keys" list *must* include:
307 -- classes that are grabbed by key (e.g., eqClassKey)
308 -- classes in "Class.standardClassKeys" (quite a few)
311 = [ (str_mod, (k, RnImplicitClass)) | (str_mod,k) <-
312 [ (OrigName pRELUDE SLIT("Eq"), eqClassKey) -- mentioned, derivable
313 , (OrigName pRELUDE SLIT("Eval"), evalClassKey) -- mentioned
314 , (OrigName pRELUDE SLIT("Ord"), ordClassKey) -- derivable
315 , (OrigName pRELUDE SLIT("Num"), numClassKey) -- mentioned, numeric
316 , (OrigName pRELUDE SLIT("Real"), realClassKey) -- numeric
317 , (OrigName pRELUDE SLIT("Integral"), integralClassKey) -- numeric
318 , (OrigName pRELUDE SLIT("Fractional"), fractionalClassKey) -- numeric
319 , (OrigName pRELUDE SLIT("Floating"), floatingClassKey) -- numeric
320 , (OrigName pRELUDE SLIT("RealFrac"), realFracClassKey) -- numeric
321 , (OrigName pRELUDE SLIT("RealFloat"), realFloatClassKey) -- numeric
322 , (OrigName iX SLIT("Ix"), ixClassKey) -- derivable (but it isn't Prelude.Ix; hmmm)
323 , (OrigName pRELUDE SLIT("Bounded"), boundedClassKey) -- derivable
324 , (OrigName pRELUDE SLIT("Enum"), enumClassKey) -- derivable
325 , (OrigName pRELUDE SLIT("Show"), showClassKey) -- derivable
326 , (OrigName pRELUDE SLIT("Read"), readClassKey) -- derivable
327 , (OrigName pRELUDE SLIT("Monad"), monadClassKey)
328 , (OrigName pRELUDE SLIT("MonadZero"), monadZeroClassKey)
329 , (OrigName pRELUDE SLIT("MonadPlus"), monadPlusClassKey)
330 , (OrigName pRELUDE SLIT("Functor"), functorClassKey)
331 , (OrigName gHC__ SLIT("CCallable"), cCallableClassKey) -- mentioned, ccallish
332 , (OrigName gHC__ SLIT("CReturnable"), cReturnableClassKey) -- mentioned, ccallish
336 = [ (str_mod, (k, RnImplicit)) | (str_mod,k) <-
337 [ (OrigName pRELUDE SLIT("fromInt"), fromIntClassOpKey)
338 , (OrigName pRELUDE SLIT("fromInteger"), fromIntegerClassOpKey)
339 , (OrigName pRELUDE SLIT("fromRational"), fromRationalClassOpKey)
340 , (OrigName pRELUDE SLIT("enumFrom"), enumFromClassOpKey)
341 , (OrigName pRELUDE SLIT("enumFromThen"), enumFromThenClassOpKey)
342 , (OrigName pRELUDE SLIT("enumFromTo"), enumFromToClassOpKey)
343 , (OrigName pRELUDE SLIT("enumFromThenTo"),enumFromThenToClassOpKey)
344 , (OrigName pRELUDE SLIT("=="), eqClassOpKey)
345 , (OrigName pRELUDE SLIT(">>="), thenMClassOpKey)
346 , (OrigName pRELUDE SLIT("zero"), zeroClassOpKey)
350 ToDo: make it do the ``like'' part properly (as in 0.26 and before).
352 maybeCharLikeTyCon tc = if (uniqueOf tc == charDataConKey) then Just charDataCon else Nothing
353 maybeIntLikeTyCon tc = if (uniqueOf tc == intDataConKey) then Just intDataCon else Nothing