[project @ 2002-03-14 15:27:15 by simonpj]
[ghc-hetmet.git] / ghc / compiler / prelude / PrelInfo.lhs
index 728cb90..e97d288 100644 (file)
@@ -8,13 +8,10 @@ module PrelInfo (
        module PrelNames,
        module MkId,
 
-       builtinNames,   -- Names of things whose *unique* must be known, but 
-                       -- that is all. If something is in here, you know that
-                       -- if it's used at all then it's Name will be just as
-                       -- it is here, unique and all.  Includes all the 
-
-
-
+       wiredInThings,  -- Names of wired in things
+       wiredInThingEnv,
+       ghcPrimExports,
+       cCallableClassDecl, cReturnableClassDecl, assertDecl,
        
        -- Primop RdrNames
        eqH_Char_RDR,   ltH_Char_RDR,   eqH_Word_RDR,  ltH_Word_RDR, 
@@ -33,23 +30,26 @@ module PrelInfo (
 
 #include "HsVersions.h"
 
--- friends:
-import MkId            -- Ditto
 import PrelNames       -- Prelude module names
 
-import PrimOp          ( PrimOp(..), allThePrimOps, primOpRdrName )
-import DataCon         ( DataCon, dataConId, dataConWrapId )
-import TysPrim         -- TYPES
-import TysWiredIn
-
--- others:
-import RdrName         ( RdrName )
-import Name            ( Name, mkKnownKeyGlobal, getName )
-import TyCon           ( tyConDataConsIfAvailable, TyCon )
+import PrimOp          ( PrimOp(..), allThePrimOps, primOpRdrName, primOpOcc )
+import DataCon         ( DataCon )
+import Id              ( idName )
+import MkId            ( mkPrimOpId, wiredInIds )
+import MkId            -- All of it, for re-export
+import Name            ( nameOccName, nameRdrName )
+import RdrName         ( mkRdrUnqual )
+import HsSyn           ( HsTyVarBndr(..), TyClDecl(..), HsType(..) )
+import OccName         ( mkVarOcc )
+import TysPrim         ( primTyCons )
+import TysWiredIn      ( wiredInTyCons )
+import RdrHsSyn                ( mkClassDecl )
+import HscTypes        ( TyThing(..), implicitTyThingIds, TypeEnv, mkTypeEnv,
+                         GenAvailInfo(..), RdrAvailInfo )
 import Class           ( Class, classKey )
-import Type            ( funTyCon )
-import Bag
-import BasicTypes      ( Boxity(..) )
+import Type            ( funTyCon, openTypeKind, liftedTypeKind )
+import TyCon           ( tyConName )
+import SrcLoc          ( noSrcLoc )
 import Util            ( isIn )
 \end{code}
 
@@ -63,39 +63,81 @@ We have two ``builtin name funs,'' one to look up @TyCons@ and
 @Classes@, the other to look up values.
 
 \begin{code}
-builtinNames :: Bag Name
-builtinNames
-  = unionManyBags
-       [       -- Wired in TyCons
-         unionManyBags (map getTyConNames wired_in_tycons)
+wiredInThings :: [TyThing]
+wiredInThings
+  = concat
+    [          -- Wired in TyCons and their implicit Ids
+         tycon_things
+       , map AnId (implicitTyThingIds tycon_things)
 
                -- Wired in Ids
-       , listToBag (map getName wiredInIds)
+       , map AnId wiredInIds
 
                -- PrimOps
-       , listToBag (map (getName . mkPrimOpId) allThePrimOps)
-
-               -- Other names with magic keys
-       , listToBag (map mkKnownKeyGlobal knownKeyRdrNames)
-       ]
-\end{code}
-
+       , map (AnId . mkPrimOpId) allThePrimOps
+    ]
+  where
+    tycon_things = map ATyCon ([funTyCon] ++ primTyCons ++ wiredInTyCons)
 
-\begin{code}
-getTyConNames :: TyCon -> Bag Name
-getTyConNames tycon
-    = getName tycon `consBag` 
-      unionManyBags (map get_data_con_names (tyConDataConsIfAvailable tycon))
-       -- Synonyms return empty list of constructors
-    where
-      get_data_con_names dc = listToBag [getName (dataConId dc),       -- Worker
-                                        getName (dataConWrapId dc)]    -- Wrapper
+wiredInThingEnv :: TypeEnv
+wiredInThingEnv = mkTypeEnv wiredInThings
 \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{Export lists for pseudo-modules (GHC.Prim)}
+%*                                                                     *
+%************************************************************************
+
+GHC.Prim "exports" all the primops and primitive types, some 
+wired-in Ids, and the CCallable & CReturnable classes.
+
+\begin{code}
+ghcPrimExports :: [RdrAvailInfo]
+ = AvailTC cCallableOcc [ cCallableOcc ] :
+   AvailTC cReturnableOcc [ cReturnableOcc ] :
+   Avail (nameOccName assertName) :    -- doesn't have an Id
+   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
+
+assertDecl
+  = IfaceSig { 
+       tcdName = nameRdrName assertName,
+       tcdType = HsForAllTy (Just [liftedAlpha]) [] (HsTyVar alpha),
+       tcdIdInfo = [],
+       tcdLoc = noSrcLoc
+    }
+
+cCallableClassDecl
+  = mkClassDecl
+    ([], nameRdrName cCallableClassName, [openAlpha])
+    [] -- no fds
+    [] -- no sigs
+    Nothing -- no mbinds
+    noSrcLoc
+
+cReturnableClassDecl
+  = mkClassDecl
+    ([], nameRdrName 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}
 
 %************************************************************************
 %*                                                                     *
@@ -126,60 +168,6 @@ minusH_RDR = primOpRdrName IntSubOp
 tagToEnumH_RDR = primOpRdrName TagToEnumOp
 \end{code}
 
-%************************************************************************
-%*                                                                     *
-\subsection{Wired in TyCons}
-%*                                                                     *
-%************************************************************************
-
-\begin{code}
-wired_in_tycons = [funTyCon] ++
-                 prim_tycons ++
-                 tuple_tycons ++
-                 unboxed_tuple_tycons ++
-                 data_tycons
-
-prim_tycons
-  = [ addrPrimTyCon
-    , arrayPrimTyCon
-    , byteArrayPrimTyCon
-    , charPrimTyCon
-    , doublePrimTyCon
-    , floatPrimTyCon
-    , intPrimTyCon
-    , int64PrimTyCon
-    , foreignObjPrimTyCon
-    , bcoPrimTyCon
-    , weakPrimTyCon
-    , mutableArrayPrimTyCon
-    , mutableByteArrayPrimTyCon
-    , mVarPrimTyCon
-    , mutVarPrimTyCon
-    , realWorldTyCon
-    , stablePtrPrimTyCon
-    , stableNamePrimTyCon
-    , statePrimTyCon
-    , threadIdPrimTyCon
-    , wordPrimTyCon
-    , word64PrimTyCon
-    ]
-
-tuple_tycons = unitTyCon : [tupleTyCon Boxed i | i <- [2..37] ]
-unboxed_tuple_tycons = [tupleTyCon Unboxed i | i <- [1..37] ]
-
-data_tycons
-  = [ addrTyCon
-    , boolTyCon
-    , charTyCon
-    , doubleTyCon
-    , floatTyCon
-    , intTyCon
-    , integerTyCon
-    , listTyCon
-    , wordTyCon
-    ]
-\end{code}
-
 
 %************************************************************************
 %*                                                                     *