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 pRELUDE, pRELUDE_BUILTIN, pRELUDE_CORE, pRELUDE_RATIO,
12 pRELUDE_LIST, pRELUDE_TEXT,
13 pRELUDE_PRIMIO, pRELUDE_IO, pRELUDE_PS,
14 gLASGOW_ST, gLASGOW_MISC,
16 -- finite maps for built-in things (for the renamer and typechecker):
17 builtinNameInfo, BuiltinNames(..),
18 BuiltinKeys(..), BuiltinIdInfos(..),
20 -- *odd* values that need to be reached out and grabbed:
21 eRROR_ID, pAT_ERROR_ID, aBSENT_ERROR_ID,
23 unpackCStringId, unpackCString2Id,
24 unpackCStringAppendId, unpackCStringFoldrId,
25 integerZeroId, integerPlusOneId,
26 integerPlusTwoId, integerMinusOneId,
28 -----------------------------------------------------
29 -- the rest of the export list is organised by *type*
30 -----------------------------------------------------
33 boolTyCon, boolTy, falseDataCon, trueDataCon,
35 -- types: Char#, Char, String (= [Char])
36 charPrimTy, charTy, stringTy,
37 charPrimTyCon, charTyCon, charDataCon,
39 -- type: Ordering (used in deriving)
40 orderingTy, ltDataCon, eqDataCon, gtDataCon,
42 -- types: Double#, Double
43 doublePrimTy, doubleTy,
44 doublePrimTyCon, doubleTyCon, doubleDataCon,
46 -- types: Float#, Float
48 floatPrimTyCon, floatTyCon, floatDataCon,
50 -- types: Glasgow *primitive* arrays, sequencing and I/O
51 mkPrimIoTy, -- to typecheck "mainPrimIO" & for _ccall_s
52 realWorldStatePrimTy, realWorldStateTy{-boxed-},
53 realWorldTy, realWorldTyCon, realWorldPrimId,
54 statePrimTyCon, stateDataCon, getStatePairingConInfo,
58 -- types: Void# (only used within the compiler)
59 voidPrimTy, voidPrimId,
61 -- types: Addr#, Int#, Word#, Int
62 intPrimTy, intTy, intPrimTyCon, intTyCon, intDataCon,
63 wordPrimTyCon, wordPrimTy, wordTy, wordTyCon, wordDataCon,
64 addrPrimTyCon, addrPrimTy, addrTy, addrTyCon, addrDataCon,
66 -- types: Integer, Rational (= Ratio Integer)
67 integerTy, rationalTy,
68 integerTyCon, integerDataCon,
69 rationalTyCon, ratioDataCon,
72 liftTyCon, liftDataCon, mkLiftTy,
75 listTyCon, mkListTy, nilDataCon, consDataCon,
80 -- for compilation of List Comprehensions and foldr
82 mkBuild, buildId, augmentId, appendId
84 -- and, finally, we must put in some (abstract) data types,
85 -- to make the interface self-sufficient
89 import PrelLoop ( primOpNameInfo )
92 import PrelMods -- Prelude module names
93 import PrelVals -- VALUES
94 import PrimOp ( PrimOp(..), allThePrimOps )
95 import PrimRep ( PrimRep(..) )
96 import TysPrim -- TYPES
100 import CmdLineOpts ( opt_HideBuiltinNames,
101 opt_HideMostBuiltinNames,
104 import FiniteMap ( FiniteMap, emptyFM, listToFM )
105 import Id ( mkTupleCon, GenId, Id(..) )
106 import Maybes ( catMaybes )
107 import Name ( mkBuiltinName )
108 import Outputable ( getOrigName )
109 import RnHsSyn ( RnName(..) )
110 import TyCon ( tyConDataCons, mkFunTyCon, mkTupleTyCon, TyCon )
112 import UniqFM ( UniqFM, emptyUFM, listToUFM )
113 import Unique -- *Key stuff
114 import Util ( nOfThem, panic )
117 %************************************************************************
119 \subsection[builtinNameInfo]{Lookup built-in names}
121 %************************************************************************
123 We have two ``builtin name funs,'' one to look up @TyCons@ and
124 @Classes@, the other to look up values.
127 builtinNameInfo :: ( BuiltinNames, BuiltinKeys, BuiltinIdInfos )
129 type BuiltinNames = FiniteMap FAST_STRING RnName -- WiredIn Ids/TyCons
130 type BuiltinKeys = FiniteMap FAST_STRING Unique -- Names with known uniques
131 type BuiltinIdInfos = UniqFM IdInfo -- Info for known unique Ids
134 = if opt_HideBuiltinNames then
140 else if opt_HideMostBuiltinNames then
142 listToFM min_assoc_wired,
148 listToFM assoc_wired,
150 listToUFM assoc_id_infos
154 min_assoc_wired -- min needed when compiling bits of Prelude
158 map pcTyConWiredInInfo prim_tycons,
159 map pcTyConWiredInInfo g_tycons,
160 map pcTyConWiredInInfo min_nonprim_tycon_list,
163 concat (map pcDataConWiredInInfo g_con_tycons),
164 concat (map pcDataConWiredInInfo min_nonprim_tycon_list),
167 map pcIdWiredInInfo wired_in_ids,
175 map pcTyConWiredInInfo prim_tycons,
176 map pcTyConWiredInInfo g_tycons,
177 map pcTyConWiredInInfo data_tycons,
178 map pcTyConWiredInInfo synonym_tycons,
181 concat (map pcDataConWiredInInfo g_con_tycons),
182 concat (map pcDataConWiredInInfo data_tycons),
185 map pcIdWiredInInfo wired_in_ids,
186 map pcIdWiredInInfo parallel_ids,
199 id_keys = map id_key id_keys_infos
200 id_key (str, uniq, info) = (str, uniq)
202 assoc_id_infos = catMaybes (map assoc_info id_keys_infos)
203 assoc_info (str, uniq, Just info) = Just (uniq, info)
204 assoc_info (str, uniq, Nothing) = Nothing
208 We let a lot of "non-standard" values be visible, so that we can make
209 sense of them in interface pragmas. It's cool, though they all have
210 "non-standard" names, so they won't get past the parser in user code.
212 The WiredIn TyCons and DataCons ...
224 mutableArrayPrimTyCon,
225 mutableByteArrayPrimTyCon,
234 = mkFunTyCon : g_con_tycons
237 = listTyCon : mkTupleTyCon 0 : [mkTupleTyCon i | i <- [2..32] ]
239 min_nonprim_tycon_list -- used w/ HideMostBuiltinNames
249 return2GMPsTyCon, -- ADR asked for these last two (WDP 94/11)
268 returnIntAndGMPTyCon,
270 stateAndAddrPrimTyCon,
271 stateAndArrayPrimTyCon,
272 stateAndByteArrayPrimTyCon,
273 stateAndCharPrimTyCon,
274 stateAndDoublePrimTyCon,
275 stateAndFloatPrimTyCon,
276 stateAndIntPrimTyCon,
277 stateAndMallocPtrPrimTyCon,
278 stateAndMutableArrayPrimTyCon,
279 stateAndMutableByteArrayPrimTyCon,
280 stateAndSynchVarPrimTyCon,
281 stateAndPtrPrimTyCon,
282 stateAndStablePtrPrimTyCon,
283 stateAndWordPrimTyCon,
296 pcTyConWiredInInfo :: TyCon -> (FAST_STRING, RnName)
297 pcTyConWiredInInfo tc = (snd (getOrigName tc), WiredInTyCon tc)
299 pcDataConWiredInInfo :: TyCon -> [(FAST_STRING, RnName)]
300 pcDataConWiredInInfo tycon
301 = [ (snd (getOrigName con), WiredInId con) | con <- tyConDataCons tycon ]
305 ToDo: Some of these should be moved to id_keys_infos!
309 pAT_ERROR_ID, -- occurs in i/faces
310 pAR_ERROR_ID, -- ditto
317 -- foldr/build Ids have magic unfoldings
322 unpackCStringAppendId,
327 = if not opt_ForConcurrent then
343 pcIdWiredInInfo :: Id -> (FAST_STRING, RnName)
344 pcIdWiredInInfo id = (snd (getOrigName id), WiredInId id)
347 WiredIn primitive numeric operations ...
350 = map primOpNameInfo allThePrimOps ++ map fn funny_name_primops
352 fn (op,s) = case (primOpNameInfo op) of (_,n) -> (s,n)
356 (IntAddOp, SLIT("+#")),
357 (IntSubOp, SLIT("-#")),
358 (IntMulOp, SLIT("*#")),
359 (IntGtOp, SLIT(">#")),
360 (IntGeOp, SLIT(">=#")),
361 (IntEqOp, SLIT("==#")),
362 (IntNeOp, SLIT("/=#")),
363 (IntLtOp, SLIT("<#")),
364 (IntLeOp, SLIT("<=#")),
365 (DoubleAddOp, SLIT("+##")),
366 (DoubleSubOp, SLIT("-##")),
367 (DoubleMulOp, SLIT("*##")),
368 (DoubleDivOp, SLIT("/##")),
369 (DoublePowerOp, SLIT("**##")),
370 (DoubleGtOp, SLIT(">##")),
371 (DoubleGeOp, SLIT(">=##")),
372 (DoubleEqOp, SLIT("==##")),
373 (DoubleNeOp, SLIT("/=##")),
374 (DoubleLtOp, SLIT("<##")),
375 (DoubleLeOp, SLIT("<=##"))
380 Ids, Synonyms, Classes and ClassOps with builtin keys.
381 For the Ids we may also have some builtin IdInfo.
383 id_keys_infos :: [(FAST_STRING, Unique, Maybe IdInfo)]
390 (SLIT("IO"), iOTyConKey) -- SLIT("PreludeMonadicIO")
395 (SLIT("Eq"), eqClassKey),
396 (SLIT("Ord"), ordClassKey),
397 (SLIT("Num"), numClassKey),
398 (SLIT("Real"), realClassKey),
399 (SLIT("Integral"), integralClassKey),
400 (SLIT("Fractional"), fractionalClassKey),
401 (SLIT("Floating"), floatingClassKey),
402 (SLIT("RealFrac"), realFracClassKey),
403 (SLIT("RealFloat"), realFloatClassKey),
404 (SLIT("Ix"), ixClassKey),
405 (SLIT("Enum"), enumClassKey),
406 (SLIT("Show"), showClassKey),
407 (SLIT("Read"), readClassKey),
408 (SLIT("Monad"), monadClassKey),
409 (SLIT("MonadZero"), monadZeroClassKey),
410 (SLIT("Binary"), binaryClassKey),
411 (SLIT("_CCallable"), cCallableClassKey),
412 (SLIT("_CReturnable"), cReturnableClassKey)
417 (SLIT("fromInt"), fromIntClassOpKey),
418 (SLIT("fromInteger"), fromIntegerClassOpKey),
419 (SLIT("fromRational"), fromRationalClassOpKey),
420 (SLIT("enumFrom"), enumFromClassOpKey),
421 (SLIT("enumFromThen"), enumFromThenClassOpKey),
422 (SLIT("enumFromTo"), enumFromToClassOpKey),
423 (SLIT("enumFromThenTo"), enumFromThenToClassOpKey),
424 (SLIT("=="), eqClassOpKey),
425 (SLIT(">="), geClassOpKey)