[project @ 2002-10-18 13:35:46 by simonpj]
[ghc-hetmet.git] / ghc / compiler / prelude / PrelInfo.lhs
index f1a64ed..3e0cf4a 100644 (file)
@@ -10,13 +10,10 @@ module PrelInfo (
 
        wiredInThings,  -- Names of wired in things
        wiredInThingEnv,
+       ghcPrimExports,
+       cCallableClassDecl, cReturnableClassDecl,
+       knownKeyNames,
        
-       -- Primop RdrNames
-       eqH_Char_RDR,   ltH_Char_RDR,   eqH_Word_RDR,  ltH_Word_RDR, 
-       eqH_Addr_RDR,   ltH_Addr_RDR,   eqH_Float_RDR, ltH_Float_RDR, 
-       eqH_Double_RDR, ltH_Double_RDR, eqH_Int_RDR,   ltH_Int_RDR,
-       geH_RDR, leH_RDR, minusH_RDR, tagToEnumH_RDR, 
-
        -- Random other things
        maybeCharLikeCon, maybeIntLikeCon,
 
@@ -28,21 +25,34 @@ module PrelInfo (
 
 #include "HsVersions.h"
 
--- friends:
-import PrelNames       -- Prelude module names
-
-import PrimOp          ( PrimOp(..), allThePrimOps, primOpRdrName )
-import DataCon         ( DataCon, dataConId, dataConWrapId )
+import PrelNames       ( basicKnownKeyNames, 
+                         cCallableClassName, cReturnableClassName,
+                         hasKey, charDataConKey, intDataConKey,
+                         numericClassKeys, standardClassKeys, cCallishClassKeys,
+                         noDictClassKeys )
+#ifdef GHCI
+import DsMeta          ( templateHaskellNames )
+import NameSet         ( nameSetToList )
+#endif
+
+import PrimOp          ( allThePrimOps, primOpOcc )
+import DataCon         ( DataCon )
+import Id              ( idName )
 import MkId            ( mkPrimOpId, wiredInIds )
 import MkId            -- All of it, for re-export
+import Name            ( Name, nameOccName )
+import RdrName         ( mkRdrUnqual, getRdrName )
+import HsSyn           ( HsTyVarBndr(..) )
+import OccName         ( mkVarOcc )
 import TysPrim         ( primTyCons )
 import TysWiredIn      ( wiredInTyCons )
-import HscTypes        ( TyThing(..), TypeEnv, mkTypeEnv )
-
--- others:
-import TyCon           ( tyConDataConsIfAvailable, tyConGenIds, TyCon )
-import Class           ( Class, classKey )
-import Type            ( funTyCon )
+import RdrHsSyn                ( mkClassDecl )
+import HscTypes        ( TyThing(..), implicitTyThingIds, TypeEnv, mkTypeEnv,
+                         GenAvailInfo(..), RdrAvailInfo )
+import Class           ( Class, classKey, className )
+import Type            ( funTyCon, openTypeKind, liftedTypeKind )
+import TyCon           ( tyConName )
+import SrcLoc          ( noSrcLoc )
 import Util            ( isIn )
 \end{code}
 
@@ -59,8 +69,9 @@ We have two ``builtin name funs,'' one to look up @TyCons@ and
 wiredInThings :: [TyThing]
 wiredInThings
   = concat
-    [          -- Wired in TyCons
-         concat (map wiredInTyConThings ([funTyCon] ++ primTyCons ++ wiredInTyCons))
+    [          -- Wired in TyCons and their implicit Ids
+         tycon_things
+       , map AnId (implicitTyThingIds tycon_things)
 
                -- Wired in Ids
        , map AnId wiredInIds
@@ -68,53 +79,65 @@ wiredInThings
                -- PrimOps
        , map (AnId . mkPrimOpId) allThePrimOps
     ]
-
-wiredInTyConThings :: TyCon -> [TyThing]
--- This is a bit of a cheat (c.f. TcTyDecls.mkImplicitDataBinds
--- It assumes that wired in tycons have no record selectors
-wiredInTyConThings tc
-   = [ATyCon tc] 
-   ++ [ AnId i | i <- tyConGenIds tc ]
-   ++ [ AnId n | dc <- tyConDataConsIfAvailable tc, 
-                 n  <- [dataConId dc, dataConWrapId dc] ] 
-                       -- Synonyms return empty list of constructors
+  where
+    tycon_things = map ATyCon ([funTyCon] ++ primTyCons ++ wiredInTyCons)
 
 wiredInThingEnv :: TypeEnv
 wiredInThingEnv = mkTypeEnv wiredInThings
+
+knownKeyNames :: [Name]
+knownKeyNames 
+  = basicKnownKeyNames
+#ifdef GHCI
+    ++ nameSetToList templateHaskellNames
+#endif
 \end{code}
 
 We let a lot of "non-standard" values be visible, so that we can make
 sense of them in interface pragmas. It's cool, though they all have
 "non-standard" names, so they won't get past the parser in user code.
 
-
 %************************************************************************
 %*                                                                     *
-\subsection{RdrNames for the primops}
+\subsection{Export lists for pseudo-modules (GHC.Prim)}
 %*                                                                     *
 %************************************************************************
 
-These can't be in PrelNames, because we get the RdrName from the PrimOp,
-which is above PrelNames in the module hierarchy.
+GHC.Prim "exports" all the primops and primitive types, some 
+wired-in Ids, and the CCallable & CReturnable classes.
 
 \begin{code}
-eqH_Char_RDR   = primOpRdrName CharEqOp
-ltH_Char_RDR   = primOpRdrName CharLtOp
-eqH_Word_RDR   = primOpRdrName WordEqOp
-ltH_Word_RDR   = primOpRdrName WordLtOp
-eqH_Addr_RDR   = primOpRdrName AddrEqOp
-ltH_Addr_RDR   = primOpRdrName AddrLtOp
-eqH_Float_RDR  = primOpRdrName FloatEqOp
-ltH_Float_RDR  = primOpRdrName FloatLtOp
-eqH_Double_RDR = primOpRdrName DoubleEqOp
-ltH_Double_RDR = primOpRdrName DoubleLtOp
-eqH_Int_RDR    = primOpRdrName IntEqOp
-ltH_Int_RDR    = primOpRdrName IntLtOp
-geH_RDR                = primOpRdrName IntGeOp
-leH_RDR                = primOpRdrName IntLeOp
-minusH_RDR     = primOpRdrName IntSubOp
-
-tagToEnumH_RDR = primOpRdrName TagToEnumOp
+ghcPrimExports :: [RdrAvailInfo]
+ = AvailTC cCallableOcc [ cCallableOcc ] :
+   AvailTC cReturnableOcc [ cReturnableOcc ] :
+   map (Avail . nameOccName . idName) ghcPrimIds ++
+   map (Avail . primOpOcc) allThePrimOps ++
+   [ AvailTC occ [occ] |
+     n <- funTyCon : primTyCons, let occ = nameOccName (tyConName n) 
+   ]
+ where
+   cCallableOcc = nameOccName cCallableClassName
+   cReturnableOcc = nameOccName cReturnableClassName
+
+cCallableClassDecl
+  = mkClassDecl
+    ([], getRdrName cCallableClassName, [openAlpha])
+    [] -- no fds
+    [] -- no sigs
+    Nothing -- no mbinds
+    noSrcLoc
+
+cReturnableClassDecl
+  = mkClassDecl
+    ([], getRdrName cReturnableClassName, [openAlpha])
+    [] -- no fds
+    [] -- no sigs
+    Nothing -- no mbinds
+    noSrcLoc
+
+alpha = mkRdrUnqual (mkVarOcc FSLIT("a"))
+openAlpha = IfaceTyVar alpha openTypeKind
+liftedAlpha = IfaceTyVar alpha liftedTypeKind
 \end{code}
 
 
@@ -146,7 +169,7 @@ isCcallishClass, isCreturnableClass, isNoDictClass,
 isNumericClass     clas = classKey clas `is_elem` numericClassKeys
 isStandardClass    clas = classKey clas `is_elem` standardClassKeys
 isCcallishClass           clas = classKey clas `is_elem` cCallishClassKeys
-isCreturnableClass clas = classKey clas == cReturnableClassKey
+isCreturnableClass clas = className clas == cReturnableClassName
 isNoDictClass      clas = classKey clas `is_elem` noDictClassKeys
 is_elem = isIn "is_X_Class"
 \end{code}