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, integerMinusOneId,
40 fromDomainId, toDomainId,
41 #endif {- Data Parallel Haskell -}
43 -----------------------------------------------------
44 -- the rest of the export list is organised by *type*
45 -----------------------------------------------------
47 -- "type": functions ("arrow" type constructor)
51 boolTyCon, boolTy, falseDataCon, trueDataCon,
53 -- types: Char#, Char, String (= [Char])
54 charPrimTy, charTy, stringTy,
55 charPrimTyCon, charTyCon, charDataCon,
57 -- type: CMP_TAG (used in deriving)
58 cmpTagTy, ltPrimDataCon, eqPrimDataCon, gtPrimDataCon,
60 -- types: Double#, Double
61 doublePrimTy, doubleTy,
62 doublePrimTyCon, doubleTyCon, doubleDataCon,
64 -- types: Float#, Float
66 floatPrimTyCon, floatTyCon, floatDataCon,
68 -- types: Glasgow *primitive* arrays, sequencing and I/O
69 mkPrimIoTy, -- to typecheck "mainIO", "mainPrimIO" & for _ccall_s
70 realWorldStatePrimTy, realWorldStateTy{-boxed-},
71 realWorldTy, realWorldTyCon, realWorldPrimId,
72 stateDataCon, getStatePairingConInfo,
74 -- types: Void# (only used within the compiler)
75 voidPrimTy, voidPrimId,
77 -- types: Addr#, Int#, Word#, Int
78 intPrimTy, intTy, intPrimTyCon, intTyCon, intDataCon,
79 wordPrimTyCon, wordPrimTy, wordTy, wordTyCon, wordDataCon,
80 addrPrimTyCon, addrPrimTy, addrTy, addrTyCon, addrDataCon,
82 -- types: Integer, Rational (= Ratio Integer)
83 integerTy, rationalTy,
84 integerTyCon, integerDataCon,
85 rationalTyCon, ratioDataCon,
88 liftTyCon, liftDataCon, mkLiftTy,
91 listTyCon, mkListTy, nilDataCon, consDataCon,
92 -- NOT USED: buildDataCon,
98 -- packedStringTyCon, packedStringTy, psDataCon, cpsDataCon,
100 -- for compilation of List Comprehensions and foldr
101 foldlId, foldrId, mkFoldl, mkFoldr, mkBuild, buildId,
105 mkPodTy, mkPodNTy, podTyCon, -- user model
106 mkPodizedPodNTy, -- podized model
107 mkInterfacePodNTy, interfacePodTyCon, mKINTERPOD_ID, -- interface model
109 -- Misc used during podization
110 primIfromPodNSelectorId,
111 #endif {- Data Parallel Haskell -}
113 -- and, finally, we must put in some (abstract) data types,
114 -- to make the interface self-sufficient
115 GlobalSwitch, Id, Maybe, Name, PprStyle, PrimKind, HeapOffset,
116 TyCon, UniType, TauType(..), Unique, CoreExpr, PlainCoreExpr(..)
118 IF_ATTACK_PRAGMAS(COMMA tagOf_PrimOp)
119 IF_ATTACK_PRAGMAS(COMMA mkStatePrimTy)
121 #ifndef __GLASGOW_HASKELL__
129 #endif {- Data Parallel Haskell -}
131 import PrelFuns -- help functions, types and things
134 import TysPrim -- TYPES
136 import PrelVals -- VALUES
137 import PrimOps -- PRIMITIVE OPS
139 import AbsUniType ( getTyConDataCons, TyCon
140 IF_ATTACK_PRAGMAS(COMMA cmpTyCon)
142 import CmdLineOpts ( GlobalSwitch(..) )
147 import Unique -- *Key stuff
151 This little devil is too small to merit its own ``TyFun'' module:
157 %************************************************************************
159 \subsection[builtinNameInfo]{Lookup built-in names}
161 %************************************************************************
163 We have two ``builtin name funs,'' one to look up @TyCons@ and
164 @Classes@, the other to look up values.
167 builtinNameInfo :: (GlobalSwitch -> Bool) -- access to global cmd-line flags
168 -> (FAST_STRING -> Maybe Name, -- name lookup fn for values
169 FAST_STRING -> Maybe Name) -- name lookup fn for tycons/classes
171 builtinNameInfo switch_is_on
172 = (init_val_lookup_fn, init_tc_lookup_fn)
175 -- values (including data constructors)
178 = if switch_is_on HideBuiltinNames then
180 else if switch_is_on HideMostBuiltinNames then
181 lookupFM (listToFM min_val_assoc_list)
182 -- OLD: mkStringLookupFn min_val_assoc_list False{-not pre-sorted-}
184 lookupFM (listToFM (concat list_of_val_assoc_lists))
185 -- mkStringLookupFn (concat list_of_val_assoc_lists) False{-not pre-sorted-}
187 min_val_assoc_list -- this is an ad-hoc list; what "happens"
188 = totally_wired_in_Ids -- to be needed (when compiling bits of
189 ++ unboxed_ops -- Prelude).
190 ++ (concat (map pcDataConNameInfo min_nonprim_tycon_list))
192 -- We let a lot of "non-standard" values be visible, so that we
193 -- can make sense of them in interface pragmas. It's cool, though
194 -- -- they all have "non-standard" names, so they won't get past
195 -- the parser in user code.
196 list_of_val_assoc_lists
197 = [ -- each list is empty or all there
199 totally_wired_in_Ids,
201 concat (map pcDataConNameInfo data_tycons),
205 if switch_is_on ForConcurrent then parallel_vals else []
209 -- type constructors and classes
212 = if switch_is_on HideBuiltinNames then
214 else if switch_is_on HideMostBuiltinNames then
215 lookupFM (listToFM min_tc_assoc_list)
216 --OLD: mkStringLookupFn min_tc_assoc_list False{-not pre-sorted-}
219 -- OLD: mkStringLookupFn
220 map pcTyConNameInfo (data_tycons ++ synonym_tycons)
221 ++ std_tycon_list -- TyCons not quite so wired in
224 -- The prim_tys,etc., are OK, because they all
225 -- have "non-standard" names (and we really
226 -- want them for interface pragmas).
227 --OLD: False{-not pre-sorted-}
229 min_tc_assoc_list -- again, pretty ad-hoc
230 = prim_tys ++ (map pcTyConNameInfo min_nonprim_tycon_list)
231 --HA! ++ std_class_list -- no harm in this
233 min_nonprim_tycon_list -- used w/ HideMostBuiltinNames
242 return2GMPsTyCon, -- ADR asked for these last two (WDP 94/11)
243 returnIntAndGMPTyCon ]
245 -- sigh: I (WDP) think these should be local defns
246 -- but you cannot imagine how bad it is for speed (w/ GHC)
247 prim_tys = map pcTyConNameInfo prim_tycons
252 = [(SLIT(":"), WiredInVal consDataCon),
253 (SLIT("error"), WiredInVal eRROR_ID),
254 (SLIT("patError#"), WiredInVal pAT_ERROR_ID), -- occurs in i/faces
255 (SLIT("parError#"), WiredInVal pAR_ERROR_ID), -- ditto
256 (SLIT("_trace"), WiredInVal tRACE_ID),
258 -- now the build / foldr Id, which needs to be built in
259 (SLIT("_build"), WiredInVal buildId),
260 (SLIT("foldl"), WiredInVal foldlId),
261 (SLIT("foldr"), WiredInVal foldrId),
262 (SLIT("_runST"), WiredInVal runSTId),
263 (SLIT("_seq_"), WiredInVal seqId), -- yes, used in sequential-land, too
265 (SLIT("realWorld#"), WiredInVal realWorldPrimId)
269 =[(SLIT("_par_"), WiredInVal parId),
270 (SLIT("_fork_"), WiredInVal forkId)
273 (SLIT("_parLocal_"), WiredInVal parLocalId),
274 (SLIT("_parGlobal_"), WiredInVal parGlobalId)
276 -- (SLIT("_parAt_"), WiredInVal parAtId)
277 -- (SLIT("_parAtForNow_"), WiredInVal parAtForNowId)
278 -- (SLIT("_copyable_"), WiredInVal copyableId)
279 -- (SLIT("_noFollow_"), WiredInVal noFollowId)
284 = (map primOpNameInfo lots_of_primops)
286 -- plus some of the same ones but w/ different names
287 [case (primOpNameInfo IntAddOp) of (_,n) -> (SLIT("+#"), n),
288 case (primOpNameInfo IntSubOp) of (_,n) -> (SLIT("-#"), n),
289 case (primOpNameInfo IntMulOp) of (_,n) -> (SLIT("*#"), n),
290 case (primOpNameInfo IntGtOp) of (_,n) -> (SLIT(">#"), n),
291 case (primOpNameInfo IntGeOp) of (_,n) -> (SLIT(">=#"), n),
292 case (primOpNameInfo IntEqOp) of (_,n) -> (SLIT("==#"), n),
293 case (primOpNameInfo IntNeOp) of (_,n) -> (SLIT("/=#"), n),
294 case (primOpNameInfo IntLtOp) of (_,n) -> (SLIT("<#"), n),
295 case (primOpNameInfo IntLeOp) of (_,n) -> (SLIT("<=#"), n),
296 case (primOpNameInfo DoubleAddOp) of (_,n) -> (SLIT("+##"), n),
297 case (primOpNameInfo DoubleSubOp) of (_,n) -> (SLIT("-##"), n),
298 case (primOpNameInfo DoubleMulOp) of (_,n) -> (SLIT("*##"), n),
299 case (primOpNameInfo DoubleDivOp) of (_,n) -> (SLIT("/##"), n),
300 case (primOpNameInfo DoublePowerOp) of (_,n) -> (SLIT("**##"), n),
301 case (primOpNameInfo DoubleGtOp) of (_,n) -> (SLIT(">##"), n),
302 case (primOpNameInfo DoubleGeOp) of (_,n) -> (SLIT(">=##"), n),
303 case (primOpNameInfo DoubleEqOp) of (_,n) -> (SLIT("==##"), n),
304 case (primOpNameInfo DoubleNeOp) of (_,n) -> (SLIT("/=##"), n),
305 case (primOpNameInfo DoubleLtOp) of (_,n) -> (SLIT("<##"), n),
306 case (primOpNameInfo DoubleLeOp) of (_,n) -> (SLIT("<=##"), n)]
317 mutableArrayPrimTyCon,
318 mutableByteArrayPrimTyCon,
328 swizzle_over (mod, nm, key, arity, is_data)
330 fname = mkPreludeCoreName mod nm
332 (nm, PreludeTyCon key fname arity is_data)
335 [--(pRELUDE_IO, SLIT("Request"), requestTyConKey, 0, True),
336 --OLD: (pRELUDE_IO, SLIT("Response"), responseTyConKey, 0, True),
337 (pRELUDE_IO, SLIT("Dialogue"), dialogueTyConKey, 0, False),
338 (SLIT("PreludeMonadicIO"), SLIT("IO"), iOTyConKey, 1, False)
341 -- Several of these are non-std, but they have non-std
342 -- names, so they won't get past the parser in user code
343 -- (but will be visible for interface-pragma purposes).
357 -- mutableArrayTyCon,
358 -- mutableByteArrayTyCon,
361 returnIntAndGMPTyCon,
363 stateAndAddrPrimTyCon,
364 stateAndArrayPrimTyCon,
365 stateAndByteArrayPrimTyCon,
366 stateAndCharPrimTyCon,
367 stateAndDoublePrimTyCon,
368 stateAndFloatPrimTyCon,
369 stateAndIntPrimTyCon,
370 stateAndMallocPtrPrimTyCon,
371 stateAndMutableArrayPrimTyCon,
372 stateAndMutableByteArrayPrimTyCon,
373 stateAndSynchVarPrimTyCon,
374 stateAndPtrPrimTyCon,
375 stateAndStablePtrPrimTyCon,
376 stateAndWordPrimTyCon,
381 #endif {- Data Parallel Haskell -}
392 swizzle_over (str, key)
393 = (str, PreludeClass key (mkPreludeCoreName pRELUDE_CORE str))
396 [(SLIT("Eq"), eqClassKey),
397 (SLIT("Ord"), ordClassKey),
398 (SLIT("Num"), numClassKey),
399 (SLIT("Real"), realClassKey),
400 (SLIT("Integral"), integralClassKey),
401 (SLIT("Fractional"), fractionalClassKey),
402 (SLIT("Floating"), floatingClassKey),
403 (SLIT("RealFrac"), realFracClassKey),
404 (SLIT("RealFloat"), realFloatClassKey),
405 (SLIT("Ix"), ixClassKey),
406 (SLIT("Enum"), enumClassKey),
407 (SLIT("Text"), textClassKey),
408 (SLIT("_CCallable"), cCallableClassKey),
409 (SLIT("_CReturnable"), cReturnableClassKey),
410 (SLIT("Binary"), binaryClassKey)
412 , (SLIT("Pid"), pidClassKey)
413 , (SLIT("Processor"),processorClassKey)
414 #endif {- Data Parallel Haskell -}
533 NewByteArrayOp CharKind,
534 NewByteArrayOp IntKind,
535 NewByteArrayOp AddrKind,
536 NewByteArrayOp FloatKind,
537 NewByteArrayOp DoubleKind,
539 SameMutableByteArrayOp,
543 ReadByteArrayOp CharKind,
544 ReadByteArrayOp IntKind,
545 ReadByteArrayOp AddrKind,
546 ReadByteArrayOp FloatKind,
547 ReadByteArrayOp DoubleKind,
548 WriteByteArrayOp CharKind,
549 WriteByteArrayOp IntKind,
550 WriteByteArrayOp AddrKind,
551 WriteByteArrayOp FloatKind,
552 WriteByteArrayOp DoubleKind,
553 IndexByteArrayOp CharKind,
554 IndexByteArrayOp IntKind,
555 IndexByteArrayOp AddrKind,
556 IndexByteArrayOp FloatKind,
557 IndexByteArrayOp DoubleKind,
558 IndexOffAddrOp CharKind,
559 IndexOffAddrOp IntKind,
560 IndexOffAddrOp AddrKind,
561 IndexOffAddrOp FloatKind,
562 IndexOffAddrOp DoubleKind,
564 UnsafeFreezeByteArrayOp,
573 ReallyUnsafePtrEqualityOp,
588 readUnfoldingPrimOp :: FAST_STRING -> PrimOp
592 -- "reverse" lookup table
593 tbl = map (\ o -> let { (str,_) = primOpNameInfo o } in (str, o)) lots_of_primops
595 \ str -> case [ op | (s, op) <- tbl, s == str ] of
598 [] -> panic "readUnfoldingPrimOp" -- ++ _UNPK_ str ++"::"++show (map fst tbl))
602 Make table entries for various things:
604 pcTyConNameInfo :: TyCon -> (FAST_STRING, Name)
605 pcTyConNameInfo tycon
606 = (getOccurrenceName tycon, WiredInTyCon tycon)
608 pcDataConNameInfo :: TyCon -> [(FAST_STRING, Name)]
609 pcDataConNameInfo tycon
610 = -- slurp out its data constructors...
611 [(getOccurrenceName con, WiredInVal con) | con <- getTyConDataCons tycon]