2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1995
4 \section[AbsPrel]{The @AbsPrel@ interface to the compiler's prelude knowledge}
7 #include "HsVersions.h"
11 -- unlike most export lists, this one is actually interesting :-)
13 -- re-export some PrimOp stuff:
14 PrimOp(..), typeOfPrimOp, primOpNameInfo,
15 HeapRequirement(..), primOpHeapReq, primOpCanTriggerGC,
16 primOpNeedsWrapper, primOpOkForSpeculation, primOpIsCheap,
18 PrimOpResultInfo(..), getPrimOpResultInfo,
19 pprPrimOp, showPrimOp, isCompareOp,
20 readUnfoldingPrimOp, -- actually, defined herein
22 pRELUDE, pRELUDE_BUILTIN, pRELUDE_CORE, pRELUDE_RATIO,
23 pRELUDE_LIST, pRELUDE_TEXT, --OLD: pRELUDE_ARRAY, pRELUDE_COMPLEX,
24 pRELUDE_PRIMIO, pRELUDE_IO, pRELUDE_PS,
25 gLASGOW_ST, {-gLASGOW_IO,-} gLASGOW_MISC,
27 -- lookup functions for built-in names, for the renamer:
30 -- *odd* values that need to be reached out and grabbed:
31 eRROR_ID, pAT_ERROR_ID, aBSENT_ERROR_ID,
32 unpackCStringId, unpackCString2Id, packStringForCId, unpackCStringAppendId,
33 integerZeroId, integerPlusOneId,
34 integerPlusTwoId, integerMinusOneId,
41 fromDomainId, toDomainId,
42 #endif {- Data Parallel Haskell -}
44 -----------------------------------------------------
45 -- the rest of the export list is organised by *type*
46 -----------------------------------------------------
48 -- "type": functions ("arrow" type constructor)
52 boolTyCon, boolTy, falseDataCon, trueDataCon,
54 -- types: Char#, Char, String (= [Char])
55 charPrimTy, charTy, stringTy,
56 charPrimTyCon, charTyCon, charDataCon,
58 -- type: CMP_TAG (used in deriving)
59 cmpTagTy, ltPrimDataCon, eqPrimDataCon, gtPrimDataCon,
61 -- types: Double#, Double
62 doublePrimTy, doubleTy,
63 doublePrimTyCon, doubleTyCon, doubleDataCon,
65 -- types: Float#, Float
67 floatPrimTyCon, floatTyCon, floatDataCon,
69 -- types: Glasgow *primitive* arrays, sequencing and I/O
70 mkPrimIoTy, -- to typecheck "mainIO", "mainPrimIO" & for _ccall_s
71 realWorldStatePrimTy, realWorldStateTy{-boxed-},
72 realWorldTy, realWorldTyCon, realWorldPrimId,
73 stateDataCon, getStatePairingConInfo,
75 -- types: Void# (only used within the compiler)
76 voidPrimTy, voidPrimId,
78 -- types: Addr#, Int#, Word#, Int
79 intPrimTy, intTy, intPrimTyCon, intTyCon, intDataCon,
80 wordPrimTyCon, wordPrimTy, wordTy, wordTyCon, wordDataCon,
81 addrPrimTyCon, addrPrimTy, addrTy, addrTyCon, addrDataCon,
83 -- types: Integer, Rational (= Ratio Integer)
84 integerTy, rationalTy,
85 integerTyCon, integerDataCon,
86 rationalTyCon, ratioDataCon,
89 liftTyCon, liftDataCon, mkLiftTy,
92 listTyCon, mkListTy, nilDataCon, consDataCon,
93 -- NOT USED: buildDataCon,
99 -- packedStringTyCon, packedStringTy, psDataCon, cpsDataCon,
101 -- for compilation of List Comprehensions and foldr
102 foldlId, foldrId, mkFoldl, mkFoldr, mkBuild, buildId,
106 mkPodTy, mkPodNTy, podTyCon, -- user model
107 mkPodizedPodNTy, -- podized model
108 mkInterfacePodNTy, interfacePodTyCon, mKINTERPOD_ID, -- interface model
110 -- Misc used during podization
111 primIfromPodNSelectorId,
112 #endif {- Data Parallel Haskell -}
114 -- and, finally, we must put in some (abstract) data types,
115 -- to make the interface self-sufficient
116 GlobalSwitch, Id, Maybe, Name, PprStyle, PrimKind, HeapOffset,
117 TyCon, UniType, TauType(..), Unique, CoreExpr, PlainCoreExpr(..)
119 IF_ATTACK_PRAGMAS(COMMA tagOf_PrimOp)
120 IF_ATTACK_PRAGMAS(COMMA mkStatePrimTy)
122 #ifndef __GLASGOW_HASKELL__
130 #endif {- Data Parallel Haskell -}
132 import PrelFuns -- help functions, types and things
135 import TysPrim -- TYPES
137 import PrelVals -- VALUES
138 import PrimOps -- PRIMITIVE OPS
140 import AbsUniType ( getTyConDataCons, TyCon
141 IF_ATTACK_PRAGMAS(COMMA cmpTyCon)
143 import CmdLineOpts ( GlobalSwitch(..) )
148 import Unique -- *Key stuff
152 This little devil is too small to merit its own ``TyFun'' module:
158 %************************************************************************
160 \subsection[builtinNameInfo]{Lookup built-in names}
162 %************************************************************************
164 We have two ``builtin name funs,'' one to look up @TyCons@ and
165 @Classes@, the other to look up values.
168 builtinNameInfo :: (GlobalSwitch -> Bool) -- access to global cmd-line flags
169 -> (FAST_STRING -> Maybe Name, -- name lookup fn for values
170 FAST_STRING -> Maybe Name) -- name lookup fn for tycons/classes
172 builtinNameInfo switch_is_on
173 = (init_val_lookup_fn, init_tc_lookup_fn)
176 -- values (including data constructors)
179 = if switch_is_on HideBuiltinNames then
181 else if switch_is_on HideMostBuiltinNames then
182 lookupFM (listToFM min_val_assoc_list)
183 -- OLD: mkStringLookupFn min_val_assoc_list False{-not pre-sorted-}
185 lookupFM (listToFM (concat list_of_val_assoc_lists))
186 -- mkStringLookupFn (concat list_of_val_assoc_lists) False{-not pre-sorted-}
188 min_val_assoc_list -- this is an ad-hoc list; what "happens"
189 = totally_wired_in_Ids -- to be needed (when compiling bits of
190 ++ unboxed_ops -- Prelude).
191 ++ (concat (map pcDataConNameInfo min_nonprim_tycon_list))
193 -- We let a lot of "non-standard" values be visible, so that we
194 -- can make sense of them in interface pragmas. It's cool, though
195 -- -- they all have "non-standard" names, so they won't get past
196 -- the parser in user code.
197 list_of_val_assoc_lists
198 = [ -- each list is empty or all there
200 totally_wired_in_Ids,
202 concat (map pcDataConNameInfo data_tycons),
206 if switch_is_on ForConcurrent then parallel_vals else []
210 -- type constructors and classes
213 = if switch_is_on HideBuiltinNames then
215 else if switch_is_on HideMostBuiltinNames then
216 lookupFM (listToFM min_tc_assoc_list)
217 --OLD: mkStringLookupFn min_tc_assoc_list False{-not pre-sorted-}
220 -- OLD: mkStringLookupFn
221 map pcTyConNameInfo (data_tycons ++ synonym_tycons)
222 ++ std_tycon_list -- TyCons not quite so wired in
225 -- The prim_tys,etc., are OK, because they all
226 -- have "non-standard" names (and we really
227 -- want them for interface pragmas).
228 --OLD: False{-not pre-sorted-}
230 min_tc_assoc_list -- again, pretty ad-hoc
231 = prim_tys ++ (map pcTyConNameInfo min_nonprim_tycon_list)
232 --HA! ++ std_class_list -- no harm in this
234 min_nonprim_tycon_list -- used w/ HideMostBuiltinNames
244 return2GMPsTyCon, -- ADR asked for these last two (WDP 94/11)
245 returnIntAndGMPTyCon ]
247 -- sigh: I (WDP) think these should be local defns
248 -- but you cannot imagine how bad it is for speed (w/ GHC)
249 prim_tys = map pcTyConNameInfo prim_tycons
254 = [(SLIT(":"), WiredInVal consDataCon),
255 (SLIT("error"), WiredInVal eRROR_ID),
256 (SLIT("patError#"), WiredInVal pAT_ERROR_ID), -- occurs in i/faces
257 (SLIT("parError#"), WiredInVal pAR_ERROR_ID), -- ditto
258 (SLIT("_trace"), WiredInVal tRACE_ID),
260 -- now the build / foldr Id, which needs to be built in
261 (SLIT("_build"), WiredInVal buildId),
262 (SLIT("foldl"), WiredInVal foldlId),
263 (SLIT("foldr"), WiredInVal foldrId),
264 (SLIT("_runST"), WiredInVal runSTId),
265 (SLIT("_seq_"), WiredInVal seqId), -- yes, used in sequential-land, too
267 (SLIT("realWorld#"), WiredInVal realWorldPrimId)
271 =[(SLIT("_par_"), WiredInVal parId),
272 (SLIT("_fork_"), WiredInVal forkId)
275 (SLIT("_parLocal_"), WiredInVal parLocalId),
276 (SLIT("_parGlobal_"), WiredInVal parGlobalId)
278 -- (SLIT("_parAt_"), WiredInVal parAtId)
279 -- (SLIT("_parAtForNow_"), WiredInVal parAtForNowId)
280 -- (SLIT("_copyable_"), WiredInVal copyableId)
281 -- (SLIT("_noFollow_"), WiredInVal noFollowId)
286 = (map primOpNameInfo lots_of_primops)
288 -- plus some of the same ones but w/ different names
289 [case (primOpNameInfo IntAddOp) of (_,n) -> (SLIT("+#"), n),
290 case (primOpNameInfo IntSubOp) of (_,n) -> (SLIT("-#"), n),
291 case (primOpNameInfo IntMulOp) of (_,n) -> (SLIT("*#"), n),
292 case (primOpNameInfo IntGtOp) of (_,n) -> (SLIT(">#"), n),
293 case (primOpNameInfo IntGeOp) of (_,n) -> (SLIT(">=#"), n),
294 case (primOpNameInfo IntEqOp) of (_,n) -> (SLIT("==#"), n),
295 case (primOpNameInfo IntNeOp) of (_,n) -> (SLIT("/=#"), n),
296 case (primOpNameInfo IntLtOp) of (_,n) -> (SLIT("<#"), n),
297 case (primOpNameInfo IntLeOp) of (_,n) -> (SLIT("<=#"), n),
298 case (primOpNameInfo DoubleAddOp) of (_,n) -> (SLIT("+##"), n),
299 case (primOpNameInfo DoubleSubOp) of (_,n) -> (SLIT("-##"), n),
300 case (primOpNameInfo DoubleMulOp) of (_,n) -> (SLIT("*##"), n),
301 case (primOpNameInfo DoubleDivOp) of (_,n) -> (SLIT("/##"), n),
302 case (primOpNameInfo DoublePowerOp) of (_,n) -> (SLIT("**##"), n),
303 case (primOpNameInfo DoubleGtOp) of (_,n) -> (SLIT(">##"), n),
304 case (primOpNameInfo DoubleGeOp) of (_,n) -> (SLIT(">=##"), n),
305 case (primOpNameInfo DoubleEqOp) of (_,n) -> (SLIT("==##"), n),
306 case (primOpNameInfo DoubleNeOp) of (_,n) -> (SLIT("/=##"), n),
307 case (primOpNameInfo DoubleLtOp) of (_,n) -> (SLIT("<##"), n),
308 case (primOpNameInfo DoubleLeOp) of (_,n) -> (SLIT("<=##"), n)]
319 mutableArrayPrimTyCon,
320 mutableByteArrayPrimTyCon,
330 swizzle_over (mod, nm, key, arity, is_data)
332 fname = mkPreludeCoreName mod nm
334 (nm, PreludeTyCon key fname arity is_data)
337 [--(pRELUDE_IO, SLIT("Request"), requestTyConKey, 0, True),
338 --OLD: (pRELUDE_IO, SLIT("Response"), responseTyConKey, 0, True),
339 (pRELUDE_IO, SLIT("Dialogue"), dialogueTyConKey, 0, False),
340 (SLIT("PreludeMonadicIO"), SLIT("IO"), iOTyConKey, 1, False)
343 -- Several of these are non-std, but they have non-std
344 -- names, so they won't get past the parser in user code
345 -- (but will be visible for interface-pragma purposes).
359 -- mutableArrayTyCon,
360 -- mutableByteArrayTyCon,
363 returnIntAndGMPTyCon,
365 stateAndAddrPrimTyCon,
366 stateAndArrayPrimTyCon,
367 stateAndByteArrayPrimTyCon,
368 stateAndCharPrimTyCon,
369 stateAndDoublePrimTyCon,
370 stateAndFloatPrimTyCon,
371 stateAndIntPrimTyCon,
372 stateAndMallocPtrPrimTyCon,
373 stateAndMutableArrayPrimTyCon,
374 stateAndMutableByteArrayPrimTyCon,
375 stateAndSynchVarPrimTyCon,
376 stateAndPtrPrimTyCon,
377 stateAndStablePtrPrimTyCon,
378 stateAndWordPrimTyCon,
383 #endif {- Data Parallel Haskell -}
394 swizzle_over (str, key)
395 = (str, PreludeClass key (mkPreludeCoreName pRELUDE_CORE str))
398 [(SLIT("Eq"), eqClassKey),
399 (SLIT("Ord"), ordClassKey),
400 (SLIT("Num"), numClassKey),
401 (SLIT("Real"), realClassKey),
402 (SLIT("Integral"), integralClassKey),
403 (SLIT("Fractional"), fractionalClassKey),
404 (SLIT("Floating"), floatingClassKey),
405 (SLIT("RealFrac"), realFracClassKey),
406 (SLIT("RealFloat"), realFloatClassKey),
407 (SLIT("Ix"), ixClassKey),
408 (SLIT("Enum"), enumClassKey),
409 (SLIT("Text"), textClassKey),
410 (SLIT("_CCallable"), cCallableClassKey),
411 (SLIT("_CReturnable"), cReturnableClassKey),
412 (SLIT("Binary"), binaryClassKey)
414 , (SLIT("Pid"), pidClassKey)
415 , (SLIT("Processor"),processorClassKey)
416 #endif {- Data Parallel Haskell -}
535 NewByteArrayOp CharKind,
536 NewByteArrayOp IntKind,
537 NewByteArrayOp AddrKind,
538 NewByteArrayOp FloatKind,
539 NewByteArrayOp DoubleKind,
541 SameMutableByteArrayOp,
545 ReadByteArrayOp CharKind,
546 ReadByteArrayOp IntKind,
547 ReadByteArrayOp AddrKind,
548 ReadByteArrayOp FloatKind,
549 ReadByteArrayOp DoubleKind,
550 WriteByteArrayOp CharKind,
551 WriteByteArrayOp IntKind,
552 WriteByteArrayOp AddrKind,
553 WriteByteArrayOp FloatKind,
554 WriteByteArrayOp DoubleKind,
555 IndexByteArrayOp CharKind,
556 IndexByteArrayOp IntKind,
557 IndexByteArrayOp AddrKind,
558 IndexByteArrayOp FloatKind,
559 IndexByteArrayOp DoubleKind,
560 IndexOffAddrOp CharKind,
561 IndexOffAddrOp IntKind,
562 IndexOffAddrOp AddrKind,
563 IndexOffAddrOp FloatKind,
564 IndexOffAddrOp DoubleKind,
566 UnsafeFreezeByteArrayOp,
575 ReallyUnsafePtrEqualityOp,
590 readUnfoldingPrimOp :: FAST_STRING -> PrimOp
594 -- "reverse" lookup table
595 tbl = map (\ o -> let { (str,_) = primOpNameInfo o } in (str, o)) lots_of_primops
597 \ str -> case [ op | (s, op) <- tbl, s == str ] of
600 [] -> panic "readUnfoldingPrimOp" -- ++ _UNPK_ str ++"::"++show (map fst tbl))
604 Make table entries for various things:
606 pcTyConNameInfo :: TyCon -> (FAST_STRING, Name)
607 pcTyConNameInfo tycon
608 = (getOccurrenceName tycon, WiredInTyCon tycon)
610 pcDataConNameInfo :: TyCon -> [(FAST_STRING, Name)]
611 pcDataConNameInfo tycon
612 = -- slurp out its data constructors...
613 [(getOccurrenceName con, WiredInVal con) | con <- getTyConDataCons tycon]