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, 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, wordDataCon,
80 addrPrimTyCon, addrPrimTy, addrTy, addrDataCon,
82 -- types: Integer, Rational (= Ratio Integer)
83 integerTy, rationalTy,
84 integerTyCon, rationalTyCon, ratioDataCon,
87 liftTyCon, liftDataCon, mkLiftTy,
90 listTyCon, mkListTy, nilDataCon, consDataCon,
91 -- NOT USED: buildDataCon,
97 -- packedStringTyCon, packedStringTy, psDataCon, cpsDataCon,
99 -- for compilation of List Comprehensions and foldr
100 foldlId, foldrId, mkFoldl, mkFoldr, mkBuild, buildId,
104 mkPodTy, mkPodNTy, podTyCon, -- user model
105 mkPodizedPodNTy, -- podized model
106 mkInterfacePodNTy, interfacePodTyCon, mKINTERPOD_ID, -- interface model
108 -- Misc used during podization
109 primIfromPodNSelectorId,
110 #endif {- Data Parallel Haskell -}
112 -- and, finally, we must put in some (abstract) data types,
113 -- to make the interface self-sufficient
114 GlobalSwitch, Id, Maybe, Name, PprStyle, PrimKind, HeapOffset,
115 TyCon, UniType, TauType(..), Unique, CoreExpr, PlainCoreExpr(..)
117 IF_ATTACK_PRAGMAS(COMMA tagOf_PrimOp)
118 IF_ATTACK_PRAGMAS(COMMA mkStatePrimTy)
120 #ifndef __GLASGOW_HASKELL__
128 #endif {- Data Parallel Haskell -}
130 import PrelFuns -- help functions, types and things
133 import TysPrim -- TYPES
135 import PrelVals -- VALUES
136 import PrimOps -- PRIMITIVE OPS
138 import AbsUniType ( getTyConDataCons, TyCon
139 IF_ATTACK_PRAGMAS(COMMA cmpTyCon)
141 import CmdLineOpts ( GlobalSwitch(..) )
146 import Unique -- *Key stuff
150 This little devil is too small to merit its own ``TyFun'' module:
156 %************************************************************************
158 \subsection[builtinNameInfo]{Lookup built-in names}
160 %************************************************************************
162 We have two ``builtin name funs,'' one to look up @TyCons@ and
163 @Classes@, the other to look up values.
166 builtinNameInfo :: (GlobalSwitch -> Bool) -- access to global cmd-line flags
167 -> (FAST_STRING -> Maybe Name, -- name lookup fn for values
168 FAST_STRING -> Maybe Name) -- name lookup fn for tycons/classes
170 builtinNameInfo switch_is_on
171 = (init_val_lookup_fn, init_tc_lookup_fn)
174 -- values (including data constructors)
177 = if switch_is_on HideBuiltinNames then
179 else if switch_is_on HideMostBuiltinNames then
180 lookupFM (listToFM min_val_assoc_list)
181 -- OLD: mkStringLookupFn min_val_assoc_list False{-not pre-sorted-}
183 lookupFM (listToFM (concat list_of_val_assoc_lists))
184 -- mkStringLookupFn (concat list_of_val_assoc_lists) False{-not pre-sorted-}
186 min_val_assoc_list -- this is an ad-hoc list; what "happens"
187 = totally_wired_in_Ids -- to be needed (when compiling bits of
188 ++ unboxed_ops -- Prelude).
189 ++ (concat (map pcDataConNameInfo min_nonprim_tycon_list))
191 -- We let a lot of "non-standard" values be visible, so that we
192 -- can make sense of them in interface pragmas. It's cool, though
193 -- -- they all have "non-standard" names, so they won't get past
194 -- the parser in user code.
195 list_of_val_assoc_lists
196 = [ -- each list is empty or all there
198 totally_wired_in_Ids,
200 concat (map pcDataConNameInfo data_tycons),
204 if switch_is_on ForConcurrent then parallel_vals else []
208 -- type constructors and classes
211 = if switch_is_on HideBuiltinNames then
213 else if switch_is_on HideMostBuiltinNames then
214 lookupFM (listToFM min_tc_assoc_list)
215 --OLD: mkStringLookupFn min_tc_assoc_list False{-not pre-sorted-}
218 -- OLD: mkStringLookupFn
219 map pcTyConNameInfo (data_tycons ++ synonym_tycons)
220 ++ std_tycon_list -- TyCons not quite so wired in
223 -- The prim_tys,etc., are OK, because they all
224 -- have "non-standard" names (and we really
225 -- want them for interface pragmas).
226 --OLD: False{-not pre-sorted-}
228 min_tc_assoc_list -- again, pretty ad-hoc
229 = prim_tys ++ (map pcTyConNameInfo min_nonprim_tycon_list)
230 --HA! ++ std_class_list -- no harm in this
232 min_nonprim_tycon_list -- used w/ HideMostBuiltinNames
241 return2GMPsTyCon, -- ADR asked for these last two (WDP 94/11)
242 returnIntAndGMPTyCon ]
244 -- sigh: I (WDP) think these should be local defns
245 -- but you cannot imagine how bad it is for speed (w/ GHC)
246 prim_tys = map pcTyConNameInfo prim_tycons
251 = [(SLIT(":"), WiredInVal consDataCon),
252 (SLIT("error"), WiredInVal eRROR_ID),
253 (SLIT("patError#"), WiredInVal pAT_ERROR_ID), -- occurs in i/faces
254 (SLIT("parError#"), WiredInVal pAR_ERROR_ID), -- ditto
255 (SLIT("_trace"), WiredInVal tRACE_ID),
257 -- now the build / foldr Id, which needs to be built in
258 (SLIT("_build"), WiredInVal buildId),
259 (SLIT("foldl"), WiredInVal foldlId),
260 (SLIT("foldr"), WiredInVal foldrId),
261 (SLIT("_runST"), WiredInVal runSTId),
262 (SLIT("realWorld#"), WiredInVal realWorldPrimId)
266 =[(SLIT("_seq_"), WiredInVal seqId),
267 (SLIT("_par_"), WiredInVal parId),
268 (SLIT("_fork_"), WiredInVal forkId)
271 (SLIT("_parLocal_"), WiredInVal parLocalId),
272 (SLIT("_parGlobal_"), WiredInVal parGlobalId)
274 -- (SLIT("_parAt_"), WiredInVal parAtId)
275 -- (SLIT("_parAtForNow_"), WiredInVal parAtForNowId)
276 -- (SLIT("_copyable_"), WiredInVal copyableId)
277 -- (SLIT("_noFollow_"), WiredInVal noFollowId)
282 = (map primOpNameInfo lots_of_primops)
284 -- plus some of the same ones but w/ different names
285 [case (primOpNameInfo IntAddOp) of (_,n) -> (SLIT("+#"), n),
286 case (primOpNameInfo IntSubOp) of (_,n) -> (SLIT("-#"), n),
287 case (primOpNameInfo IntMulOp) of (_,n) -> (SLIT("*#"), n),
288 case (primOpNameInfo IntGtOp) of (_,n) -> (SLIT(">#"), n),
289 case (primOpNameInfo IntGeOp) of (_,n) -> (SLIT(">=#"), n),
290 case (primOpNameInfo IntEqOp) of (_,n) -> (SLIT("==#"), n),
291 case (primOpNameInfo IntNeOp) of (_,n) -> (SLIT("/=#"), n),
292 case (primOpNameInfo IntLtOp) of (_,n) -> (SLIT("<#"), n),
293 case (primOpNameInfo IntLeOp) of (_,n) -> (SLIT("<=#"), n),
294 case (primOpNameInfo DoubleAddOp) of (_,n) -> (SLIT("+##"), n),
295 case (primOpNameInfo DoubleSubOp) of (_,n) -> (SLIT("-##"), n),
296 case (primOpNameInfo DoubleMulOp) of (_,n) -> (SLIT("*##"), n),
297 case (primOpNameInfo DoubleDivOp) of (_,n) -> (SLIT("/##"), n),
298 case (primOpNameInfo DoublePowerOp) of (_,n) -> (SLIT("**##"), n),
299 case (primOpNameInfo DoubleGtOp) of (_,n) -> (SLIT(">##"), n),
300 case (primOpNameInfo DoubleGeOp) of (_,n) -> (SLIT(">=##"), n),
301 case (primOpNameInfo DoubleEqOp) of (_,n) -> (SLIT("==##"), n),
302 case (primOpNameInfo DoubleNeOp) of (_,n) -> (SLIT("/=##"), n),
303 case (primOpNameInfo DoubleLtOp) of (_,n) -> (SLIT("<##"), n),
304 case (primOpNameInfo DoubleLeOp) of (_,n) -> (SLIT("<=##"), n)]
315 mutableArrayPrimTyCon,
316 mutableByteArrayPrimTyCon,
326 swizzle_over (mod, nm, key, arity, is_data)
328 fname = mkPreludeCoreName mod nm
330 (nm, PreludeTyCon key fname arity is_data)
333 [--(pRELUDE_IO, SLIT("Request"), requestTyConKey, 0, True),
334 --OLD: (pRELUDE_IO, SLIT("Response"), responseTyConKey, 0, True),
335 (pRELUDE_IO, SLIT("Dialogue"), dialogueTyConKey, 0, False),
336 (SLIT("PreludeMonadicIO"), SLIT("IO"), iOTyConKey, 1, False)
339 -- Several of these are non-std, but they have non-std
340 -- names, so they won't get past the parser in user code
341 -- (but will be visible for interface-pragma purposes).
355 -- mutableArrayTyCon,
356 -- mutableByteArrayTyCon,
359 returnIntAndGMPTyCon,
361 stateAndAddrPrimTyCon,
362 stateAndArrayPrimTyCon,
363 stateAndByteArrayPrimTyCon,
364 stateAndCharPrimTyCon,
365 stateAndDoublePrimTyCon,
366 stateAndFloatPrimTyCon,
367 stateAndIntPrimTyCon,
368 stateAndMallocPtrPrimTyCon,
369 stateAndMutableArrayPrimTyCon,
370 stateAndMutableByteArrayPrimTyCon,
371 stateAndSynchVarPrimTyCon,
372 stateAndPtrPrimTyCon,
373 stateAndStablePtrPrimTyCon,
374 stateAndWordPrimTyCon,
379 #endif {- Data Parallel Haskell -}
390 swizzle_over (str, key)
391 = (str, PreludeClass key (mkPreludeCoreName pRELUDE_CORE str))
394 [(SLIT("Eq"), eqClassKey),
395 (SLIT("Ord"), ordClassKey),
396 (SLIT("Num"), numClassKey),
397 (SLIT("Real"), realClassKey),
398 (SLIT("Integral"), integralClassKey),
399 (SLIT("Fractional"), fractionalClassKey),
400 (SLIT("Floating"), floatingClassKey),
401 (SLIT("RealFrac"), realFracClassKey),
402 (SLIT("RealFloat"), realFloatClassKey),
403 (SLIT("Ix"), ixClassKey),
404 (SLIT("Enum"), enumClassKey),
405 (SLIT("Text"), textClassKey),
406 (SLIT("_CCallable"), cCallableClassKey),
407 (SLIT("_CReturnable"), cReturnableClassKey),
408 (SLIT("Binary"), binaryClassKey)
410 , (SLIT("Pid"), pidClassKey)
411 , (SLIT("Processor"),processorClassKey)
412 #endif {- Data Parallel Haskell -}
532 NewByteArrayOp CharKind,
533 NewByteArrayOp IntKind,
534 NewByteArrayOp AddrKind,
535 NewByteArrayOp FloatKind,
536 NewByteArrayOp DoubleKind,
538 SameMutableByteArrayOp,
542 ReadByteArrayOp CharKind,
543 ReadByteArrayOp IntKind,
544 ReadByteArrayOp AddrKind,
545 ReadByteArrayOp FloatKind,
546 ReadByteArrayOp DoubleKind,
547 WriteByteArrayOp CharKind,
548 WriteByteArrayOp IntKind,
549 WriteByteArrayOp AddrKind,
550 WriteByteArrayOp FloatKind,
551 WriteByteArrayOp DoubleKind,
552 IndexByteArrayOp CharKind,
553 IndexByteArrayOp IntKind,
554 IndexByteArrayOp AddrKind,
555 IndexByteArrayOp FloatKind,
556 IndexByteArrayOp DoubleKind,
557 IndexOffAddrOp CharKind,
558 IndexOffAddrOp IntKind,
559 IndexOffAddrOp AddrKind,
560 IndexOffAddrOp FloatKind,
561 IndexOffAddrOp DoubleKind,
563 UnsafeFreezeByteArrayOp,
572 ReallyUnsafePtrEqualityOp,
587 readUnfoldingPrimOp :: FAST_STRING -> PrimOp
591 -- "reverse" lookup table
592 tbl = map (\ o -> let { (str,_) = primOpNameInfo o } in (str, o)) lots_of_primops
594 \ str -> case [ op | (s, op) <- tbl, s == str ] of
597 [] -> panic "readUnfoldingPrimOp" -- ++ _UNPK_ str ++"::"++show (map fst tbl))
601 Make table entries for various things:
603 pcTyConNameInfo :: TyCon -> (FAST_STRING, Name)
604 pcTyConNameInfo tycon
605 = (getOccurrenceName tycon, WiredInTyCon tycon)
607 pcDataConNameInfo :: TyCon -> [(FAST_STRING, Name)]
608 pcDataConNameInfo tycon
609 = -- slurp out its data constructors...
610 [(getOccurrenceName con, WiredInVal con) | con <- getTyConDataCons tycon]