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 -- lookup functions for built-in names, for the renamer:
19 -- *odd* values that need to be reached out and grabbed:
20 eRROR_ID, pAT_ERROR_ID, aBSENT_ERROR_ID,
22 unpackCStringId, unpackCString2Id,
23 unpackCStringAppendId, unpackCStringFoldrId,
24 integerZeroId, integerPlusOneId,
25 integerPlusTwoId, integerMinusOneId,
27 -----------------------------------------------------
28 -- the rest of the export list is organised by *type*
29 -----------------------------------------------------
32 boolTyCon, boolTy, falseDataCon, trueDataCon,
34 -- types: Char#, Char, String (= [Char])
35 charPrimTy, charTy, stringTy,
36 charPrimTyCon, charTyCon, charDataCon,
38 -- type: Ordering (used in deriving)
39 orderingTy, ltDataCon, eqDataCon, gtDataCon,
41 -- types: Double#, Double
42 doublePrimTy, doubleTy,
43 doublePrimTyCon, doubleTyCon, doubleDataCon,
45 -- types: Float#, Float
47 floatPrimTyCon, floatTyCon, floatDataCon,
49 -- types: Glasgow *primitive* arrays, sequencing and I/O
50 mkPrimIoTy, -- to typecheck "mainPrimIO" & for _ccall_s
51 realWorldStatePrimTy, realWorldStateTy{-boxed-},
52 realWorldTy, realWorldTyCon, realWorldPrimId,
53 statePrimTyCon, stateDataCon, getStatePairingConInfo,
57 -- types: Void# (only used within the compiler)
58 voidPrimTy, voidPrimId,
60 -- types: Addr#, Int#, Word#, Int
61 intPrimTy, intTy, intPrimTyCon, intTyCon, intDataCon,
62 wordPrimTyCon, wordPrimTy, wordTy, wordTyCon, wordDataCon,
63 addrPrimTyCon, addrPrimTy, addrTy, addrTyCon, addrDataCon,
65 -- types: Integer, Rational (= Ratio Integer)
66 integerTy, rationalTy,
67 integerTyCon, integerDataCon,
68 rationalTyCon, ratioDataCon,
71 liftTyCon, liftDataCon, mkLiftTy,
74 listTyCon, mkListTy, nilDataCon, consDataCon,
79 -- for compilation of List Comprehensions and foldr
81 mkBuild, buildId, augmentId, appendId
83 -- and, finally, we must put in some (abstract) data types,
84 -- to make the interface self-sufficient
88 import PrelLoop ( primOpNameInfo )
91 import PrelMods -- Prelude module names
92 import PrelVals -- VALUES
93 import PrimOp ( PrimOp(..), allThePrimOps )
94 import PrimRep ( PrimRep(..) )
95 import TysPrim -- TYPES
101 import Id ( mkTupleCon, GenId{-instances-} )
102 import Name ( Name(..) )
103 import NameTypes ( mkPreludeCoreName, FullName, ShortName )
104 import TyCon ( getTyConDataCons, mkFunTyCon, mkTupleTyCon, TyCon{-instances-} )
106 import Unique -- *Key stuff
107 import Util ( nOfThem, panic )
110 %************************************************************************
112 \subsection[builtinNameInfo]{Lookup built-in names}
114 %************************************************************************
116 We have two ``builtin name funs,'' one to look up @TyCons@ and
117 @Classes@, the other to look up values.
120 builtinNameInfo :: (FAST_STRING -> Maybe Name, -- name lookup fn for values
121 FAST_STRING -> Maybe Name) -- name lookup fn for tycons/classes
124 = (init_val_lookup_fn, init_tc_lookup_fn)
127 -- values (including data constructors)
130 = if opt_HideBuiltinNames then
132 else if opt_HideMostBuiltinNames then
133 lookupFM (listToFM (concat min_val_assoc_lists))
135 lookupFM (listToFM (concat val_assoc_lists))
137 min_val_assoc_lists -- min needed when compiling bits of Prelude
139 concat (map pcDataConNameInfo g_con_tycons),
140 concat (map pcDataConNameInfo min_nonprim_tycon_list),
141 totally_wired_in_Ids,
147 concat (map pcDataConNameInfo g_con_tycons),
148 concat (map pcDataConNameInfo data_tycons),
149 totally_wired_in_Ids,
152 if opt_ForConcurrent then parallel_vals else []
156 -- type constructors and classes
159 = if opt_HideBuiltinNames then
161 else if opt_HideMostBuiltinNames then
162 lookupFM (listToFM (concat min_tc_assoc_lists))
164 lookupFM (listToFM (concat tc_assoc_lists))
166 min_tc_assoc_lists -- again, pretty ad-hoc
168 map pcTyConNameInfo prim_tycons,
169 map pcTyConNameInfo g_tycons,
170 map pcTyConNameInfo min_nonprim_tycon_list
175 map pcTyConNameInfo prim_tycons,
176 map pcTyConNameInfo g_tycons,
177 map pcTyConNameInfo data_tycons,
178 map pcTyConNameInfo synonym_tycons,
183 -- We let a lot of "non-standard" values be visible, so that we
184 -- can make sense of them in interface pragmas. It's cool, though
185 -- they all have "non-standard" names, so they won't get past
186 -- the parser in user code.
198 mutableArrayPrimTyCon,
199 mutableByteArrayPrimTyCon,
208 = mkFunTyCon : g_con_tycons
211 = listTyCon : mkTupleTyCon 0 : [mkTupleTyCon i | i <- [2..32] ]
213 min_nonprim_tycon_list -- used w/ HideMostBuiltinNames
223 return2GMPsTyCon, -- ADR asked for these last two (WDP 94/11)
224 returnIntAndGMPTyCon ]
238 -- mutableArrayTyCon,
239 -- mutableByteArrayTyCon,
242 returnIntAndGMPTyCon,
244 stateAndAddrPrimTyCon,
245 stateAndArrayPrimTyCon,
246 stateAndByteArrayPrimTyCon,
247 stateAndCharPrimTyCon,
248 stateAndDoublePrimTyCon,
249 stateAndFloatPrimTyCon,
250 stateAndIntPrimTyCon,
251 stateAndMallocPtrPrimTyCon,
252 stateAndMutableArrayPrimTyCon,
253 stateAndMutableByteArrayPrimTyCon,
254 stateAndSynchVarPrimTyCon,
255 stateAndPtrPrimTyCon,
256 stateAndStablePtrPrimTyCon,
257 stateAndWordPrimTyCon,
270 = [(SLIT("error"), WiredInVal eRROR_ID),
271 (SLIT("patError#"), WiredInVal pAT_ERROR_ID), -- occurs in i/faces
272 (SLIT("parError#"), WiredInVal pAR_ERROR_ID), -- ditto
273 (SLIT("_trace"), WiredInVal tRACE_ID),
275 -- now the foldr/build Ids, which need to be built in
276 -- because they have magic unfoldings
277 (SLIT("_build"), WiredInVal buildId),
278 (SLIT("_augment"), WiredInVal augmentId),
279 (SLIT("foldl"), WiredInVal foldlId),
280 (SLIT("foldr"), WiredInVal foldrId),
281 (SLIT("unpackAppendPS#"), WiredInVal unpackCStringAppendId),
282 (SLIT("unpackFoldrPS#"), WiredInVal unpackCStringFoldrId),
284 (SLIT("_runST"), WiredInVal runSTId),
285 (SLIT("_seq_"), WiredInVal seqId), -- yes, used in sequential-land, too
287 (SLIT("realWorld#"), WiredInVal realWorldPrimId)
291 =[(SLIT("_par_"), WiredInVal parId),
292 (SLIT("_fork_"), WiredInVal forkId)
295 (SLIT("_parLocal_"), WiredInVal parLocalId),
296 (SLIT("_parGlobal_"), WiredInVal parGlobalId)
298 -- (SLIT("_parAt_"), WiredInVal parAtId)
299 -- (SLIT("_parAtForNow_"), WiredInVal parAtForNowId)
300 -- (SLIT("_copyable_"), WiredInVal copyableId)
301 -- (SLIT("_noFollow_"), WiredInVal noFollowId)
307 swizzle_over (str, key)
308 = (str, ClassOpName key bottom1 str bottom2)
310 bottom1 = panic "PrelInfo.special_class_ops:class"
311 bottom2 = panic "PrelInfo.special_class_ops:tag"
314 [ (SLIT("fromInt"), fromIntClassOpKey),
315 (SLIT("fromInteger"), fromIntegerClassOpKey),
316 (SLIT("fromRational"), fromRationalClassOpKey),
317 (SLIT("enumFrom"), enumFromClassOpKey),
318 (SLIT("enumFromThen"), enumFromThenClassOpKey),
319 (SLIT("enumFromTo"), enumFromToClassOpKey),
320 (SLIT("enumFromThenTo"),enumFromThenToClassOpKey),
321 (SLIT("=="), eqClassOpKey),
322 (SLIT(">="), geClassOpKey),
323 (SLIT("-"), negateClassOpKey)
327 = map primOpNameInfo allThePrimOps
328 -- plus some of the same ones but w/ different names ...
329 ++ map fn funny_name_primops
331 fn (op,s) = case (primOpNameInfo op) of (_,n) -> (s,n)
334 = [(IntAddOp, SLIT("+#")),
335 (IntSubOp, SLIT("-#")),
336 (IntMulOp, SLIT("*#")),
337 (IntGtOp, SLIT(">#")),
338 (IntGeOp, SLIT(">=#")),
339 (IntEqOp, SLIT("==#")),
340 (IntNeOp, SLIT("/=#")),
341 (IntLtOp, SLIT("<#")),
342 (IntLeOp, SLIT("<=#")),
343 (DoubleAddOp, SLIT("+##")),
344 (DoubleSubOp, SLIT("-##")),
345 (DoubleMulOp, SLIT("*##")),
346 (DoubleDivOp, SLIT("/##")),
347 (DoublePowerOp, SLIT("**##")),
348 (DoubleGtOp, SLIT(">##")),
349 (DoubleGeOp, SLIT(">=##")),
350 (DoubleEqOp, SLIT("==##")),
351 (DoubleNeOp, SLIT("/=##")),
352 (DoubleLtOp, SLIT("<##")),
353 (DoubleLeOp, SLIT("<=##"))]
358 swizzle_over (mod, nm, key, arity, is_data)
360 fname = mkPreludeCoreName mod nm
362 (nm, TyConName key fname arity is_data (panic "std_tycon_list:data_cons"))
365 [(SLIT("PreludeMonadicIO"), SLIT("IO"), iOTyConKey, 1, False)
370 swizzle_over (str, key)
371 = (str, ClassName key (mkPreludeCoreName pRELUDE_CORE str) (panic "std_class_list:ops"))
374 [(SLIT("Eq"), eqClassKey),
375 (SLIT("Ord"), ordClassKey),
376 (SLIT("Num"), numClassKey),
377 (SLIT("Real"), realClassKey),
378 (SLIT("Integral"), integralClassKey),
379 (SLIT("Fractional"), fractionalClassKey),
380 (SLIT("Floating"), floatingClassKey),
381 (SLIT("RealFrac"), realFracClassKey),
382 (SLIT("RealFloat"), realFloatClassKey),
383 (SLIT("Ix"), ixClassKey),
384 (SLIT("Enum"), enumClassKey),
385 (SLIT("Show"), showClassKey),
386 (SLIT("Read"), readClassKey),
387 (SLIT("Monad"), monadClassKey),
388 (SLIT("MonadZero"), monadZeroClassKey),
389 (SLIT("Binary"), binaryClassKey),
390 (SLIT("_CCallable"), cCallableClassKey),
391 (SLIT("_CReturnable"), cReturnableClassKey)
396 Make table entries for various things:
398 pcTyConNameInfo :: TyCon -> (FAST_STRING, Name)
399 pcTyConNameInfo tc = (getOccurrenceName tc, WiredInTyCon tc)
401 pcDataConNameInfo :: TyCon -> [(FAST_STRING, Name)]
402 pcDataConNameInfo tycon
403 = -- slurp out its data constructors...
404 [ (getOccurrenceName con, WiredInVal con) | con <- getTyConDataCons tycon ]