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 )
25 import PrelMods -- Prelude module names
26 import PrelVals -- VALUES
27 import PrimOp ( PrimOp(..), allThePrimOps )
28 import PrimRep ( PrimRep(..) )
29 import TysPrim -- TYPES
33 import FiniteMap ( FiniteMap, emptyFM, listToFM )
34 import Id ( mkTupleCon, GenId, SYN_IE(Id) )
35 import Maybes ( catMaybes )
36 import Name ( origName, OrigName(..), Name )
37 import RnHsSyn ( RnName(..) )
38 import TyCon ( tyConDataCons, mkFunTyCon, mkTupleTyCon, TyCon )
40 import UniqFM ( UniqFM, emptyUFM, listToUFM )
41 import Unique -- *Key stuff
42 import Util ( nOfThem, panic )
45 %************************************************************************
47 \subsection[builtinNameInfo]{Lookup built-in names}
49 %************************************************************************
51 We have two ``builtin name funs,'' one to look up @TyCons@ and
52 @Classes@, the other to look up values.
55 builtinNameInfo :: ( BuiltinNames, BuiltinKeys, BuiltinIdInfos )
57 type BuiltinNames = (FiniteMap OrigName RnName, -- WiredIn Ids
58 FiniteMap OrigName RnName) -- WiredIn TyCons
59 -- Two maps because "[]" is in both...
61 type BuiltinKeys = FiniteMap OrigName (Unique, Name -> RnName)
62 -- Names with known uniques
64 type BuiltinIdInfos = UniqFM IdInfo -- Info for known unique Ids
66 builtinNameMaps = case builtinNameInfo of { (x,_,_) -> x }
67 builtinKeysMap = case builtinNameInfo of { (_,x,_) -> x }
68 builtinValNamesMap = fst builtinNameMaps
69 builtinTcNamesMap = snd builtinNameMaps
72 = ( (listToFM assoc_val_wired, listToFM assoc_tc_wired)
74 , listToUFM assoc_id_infos
80 concat (map pcDataConWiredInInfo g_con_tycons),
81 concat (map pcDataConWiredInInfo data_tycons),
84 map pcIdWiredInInfo wired_in_ids,
90 map pcTyConWiredInInfo prim_tycons,
91 map pcTyConWiredInInfo g_tycons,
92 map pcTyConWiredInInfo data_tycons
104 id_keys = map id_key id_keys_infos
105 id_key (str_mod, uniq, info) = (str_mod, (uniq, RnImplicit))
107 assoc_id_infos = catMaybes (map assoc_info id_keys_infos)
108 assoc_info (str_mod, uniq, Just info) = Just (uniq, info)
109 assoc_info (str_mod, uniq, Nothing) = Nothing
113 We let a lot of "non-standard" values be visible, so that we can make
114 sense of them in interface pragmas. It's cool, though they all have
115 "non-standard" names, so they won't get past the parser in user code.
117 The WiredIn TyCons and DataCons ...
128 , foreignObjPrimTyCon
129 , mutableArrayPrimTyCon
130 , mutableByteArrayPrimTyCon
139 = mkFunTyCon : g_con_tycons
142 = listTyCon : mkTupleTyCon 0 : [mkTupleTyCon i | i <- [2..37] ]
144 min_nonprim_tycon_list -- used w/ HideMostBuiltinNames
152 , return2GMPsTyCon -- ADR asked for these last two (WDP 94/11)
153 , returnIntAndGMPTyCon
169 , returnIntAndGMPTyCon
172 , stateAndAddrPrimTyCon
173 , stateAndArrayPrimTyCon
174 , stateAndByteArrayPrimTyCon
175 , stateAndCharPrimTyCon
176 , stateAndDoublePrimTyCon
177 , stateAndFloatPrimTyCon
178 , stateAndForeignObjPrimTyCon
179 , stateAndIntPrimTyCon
180 , stateAndMutableArrayPrimTyCon
181 , stateAndMutableByteArrayPrimTyCon
182 , stateAndPtrPrimTyCon
183 , stateAndStablePtrPrimTyCon
184 , stateAndSynchVarPrimTyCon
185 , stateAndWordPrimTyCon
193 ToDo: Some of these should be moved to id_keys_infos!
204 , iRREFUT_PAT_ERROR_ID
209 , nON_EXHAUSTIVE_GUARDS_ERROR_ID
210 , nO_DEFAULT_METHOD_ERROR_ID
211 , nO_EXPLICIT_METHOD_ERROR_ID
230 , unpackCStringAppendId
231 , unpackCStringFoldrId
236 pcTyConWiredInInfo :: TyCon -> (OrigName, RnName)
237 pcTyConWiredInInfo tc = (origName "pcTyConWiredInInfo" tc, WiredInTyCon tc)
239 pcDataConWiredInInfo :: TyCon -> [(OrigName, RnName)]
240 pcDataConWiredInInfo tycon
241 = [ (origName "pcDataConWiredInInfo" con, WiredInId con) | con <- tyConDataCons tycon ]
243 pcIdWiredInInfo :: Id -> (OrigName, RnName)
244 pcIdWiredInInfo id = (origName "pcIdWiredInInfo" id, WiredInId id)
247 WiredIn primitive numeric operations ...
250 = map prim_fn allThePrimOps ++ map funny_fn funny_name_primops
252 prim_fn op = case (primOpNameInfo op) of (s,n) -> ((OrigName gHC_BUILTINS s),n)
253 funny_fn (op,s) = case (primOpNameInfo op) of (_,n) -> ((OrigName gHC_BUILTINS s),n)
256 = [ (IntAddOp, SLIT("+#"))
257 , (IntSubOp, SLIT("-#"))
258 , (IntMulOp, SLIT("*#"))
259 , (IntGtOp, SLIT(">#"))
260 , (IntGeOp, SLIT(">=#"))
261 , (IntEqOp, SLIT("==#"))
262 , (IntNeOp, SLIT("/=#"))
263 , (IntLtOp, SLIT("<#"))
264 , (IntLeOp, SLIT("<=#"))
265 , (DoubleAddOp, SLIT("+##"))
266 , (DoubleSubOp, SLIT("-##"))
267 , (DoubleMulOp, SLIT("*##"))
268 , (DoubleDivOp, SLIT("/##"))
269 , (DoublePowerOp, SLIT("**##"))
270 , (DoubleGtOp, SLIT(">##"))
271 , (DoubleGeOp, SLIT(">=##"))
272 , (DoubleEqOp, SLIT("==##"))
273 , (DoubleNeOp, SLIT("/=##"))
274 , (DoubleLtOp, SLIT("<##"))
275 , (DoubleLeOp, SLIT("<=##"))
280 Ids, Synonyms, Classes and ClassOps with builtin keys.
281 For the Ids we may also have some builtin IdInfo.
283 id_keys_infos :: [(OrigName, Unique, Maybe IdInfo)]
285 = [ -- here because we use them in derived instances
286 (OrigName pRELUDE SLIT("&&"), andandIdKey, Nothing)
287 , (OrigName pRELUDE SLIT("."), composeIdKey, Nothing)
288 , (OrigName gHC__ SLIT("lex"), lexIdKey, Nothing)
289 , (OrigName pRELUDE SLIT("not"), notIdKey, Nothing)
290 , (OrigName pRELUDE SLIT("readParen"), readParenIdKey, Nothing)
291 , (OrigName pRELUDE SLIT("showParen"), showParenIdKey, Nothing)
292 , (OrigName pRELUDE SLIT("showString"), showStringIdKey,Nothing)
293 , (OrigName gHC__ SLIT("readList__"), ureadListIdKey, Nothing)
294 , (OrigName gHC__ SLIT("showList__"), ushowListIdKey, Nothing)
295 , (OrigName gHC__ SLIT("showSpace"), showSpaceIdKey, Nothing)
299 = [ (OrigName gHC__ SLIT("IO"), (iOTyConKey, RnImplicitTyCon))
300 , (OrigName pRELUDE SLIT("Ordering"), (orderingTyConKey, RnImplicitTyCon))
301 , (OrigName rATIO SLIT("Rational"), (rationalTyConKey, RnImplicitTyCon))
302 , (OrigName rATIO SLIT("Ratio"), (ratioTyConKey, RnImplicitTyCon))
305 -- this "class_keys" list *must* include:
306 -- classes that are grabbed by key (e.g., eqClassKey)
307 -- classes in "Class.standardClassKeys" (quite a few)
310 = [ (str_mod, (k, RnImplicitClass)) | (str_mod,k) <-
311 [ (OrigName pRELUDE SLIT("Eq"), eqClassKey) -- mentioned, derivable
312 , (OrigName pRELUDE SLIT("Eval"), evalClassKey) -- mentioned
313 , (OrigName pRELUDE SLIT("Ord"), ordClassKey) -- derivable
314 , (OrigName pRELUDE SLIT("Num"), numClassKey) -- mentioned, numeric
315 , (OrigName pRELUDE SLIT("Real"), realClassKey) -- numeric
316 , (OrigName pRELUDE SLIT("Integral"), integralClassKey) -- numeric
317 , (OrigName pRELUDE SLIT("Fractional"), fractionalClassKey) -- numeric
318 , (OrigName pRELUDE SLIT("Floating"), floatingClassKey) -- numeric
319 , (OrigName pRELUDE SLIT("RealFrac"), realFracClassKey) -- numeric
320 , (OrigName pRELUDE SLIT("RealFloat"), realFloatClassKey) -- numeric
321 , (OrigName iX SLIT("Ix"), ixClassKey) -- derivable (but it isn't Prelude.Ix; hmmm)
322 , (OrigName pRELUDE SLIT("Bounded"), boundedClassKey) -- derivable
323 , (OrigName pRELUDE SLIT("Enum"), enumClassKey) -- derivable
324 , (OrigName pRELUDE SLIT("Show"), showClassKey) -- derivable
325 , (OrigName pRELUDE SLIT("Read"), readClassKey) -- derivable
326 , (OrigName pRELUDE SLIT("Monad"), monadClassKey)
327 , (OrigName pRELUDE SLIT("MonadZero"), monadZeroClassKey)
328 , (OrigName pRELUDE SLIT("MonadPlus"), monadPlusClassKey)
329 , (OrigName pRELUDE SLIT("Functor"), functorClassKey)
330 , (OrigName gHC__ SLIT("CCallable"), cCallableClassKey) -- mentioned, ccallish
331 , (OrigName gHC__ SLIT("CReturnable"), cReturnableClassKey) -- mentioned, ccallish
335 = [ (str_mod, (k, RnImplicit)) | (str_mod,k) <-
336 [ (OrigName pRELUDE SLIT("fromInt"), fromIntClassOpKey)
337 , (OrigName pRELUDE SLIT("fromInteger"), fromIntegerClassOpKey)
338 , (OrigName pRELUDE SLIT("fromRational"), fromRationalClassOpKey)
339 , (OrigName pRELUDE SLIT("enumFrom"), enumFromClassOpKey)
340 , (OrigName pRELUDE SLIT("enumFromThen"), enumFromThenClassOpKey)
341 , (OrigName pRELUDE SLIT("enumFromTo"), enumFromToClassOpKey)
342 , (OrigName pRELUDE SLIT("enumFromThenTo"),enumFromThenToClassOpKey)
343 , (OrigName pRELUDE SLIT("=="), eqClassOpKey)
344 , (OrigName pRELUDE SLIT(">>="), thenMClassOpKey)
345 , (OrigName pRELUDE SLIT("zero"), zeroClassOpKey)
349 ToDo: make it do the ``like'' part properly (as in 0.26 and before).
351 maybeCharLikeTyCon tc = if (uniqueOf tc == charDataConKey) then Just charDataCon else Nothing
352 maybeIntLikeTyCon tc = if (uniqueOf tc == intDataConKey) then Just intDataCon else Nothing