[project @ 1997-09-05 16:23:41 by simonpj]
[ghc-hetmet.git] / ghc / compiler / prelude / PrimRep.lhs
index b4fbf55..6317a13 100644 (file)
@@ -15,15 +15,19 @@ module PrimRep (
 
        separateByPtrFollowness, isFollowableRep, isFloatingRep,
        getPrimRepSize, retPrimRepSize,
-       showPrimRep,
-       guessPrimRep
+       showPrimRep,  ppPrimRep,
+       guessPrimRep, decodePrimRep
     ) where
 
-import Ubiq
+IMP_Ubiq()
 
 import Pretty          -- pretty-printing code
 import Util
+#if __GLASGOW_HASKELL__ >= 202
+import Outputable
+#endif
 
+-- Oh dear.
 #include "../../includes/GhcConstants.h"
 \end{code}
 
@@ -50,7 +54,7 @@ data PrimRep
   | FloatRep           --         floats
   | DoubleRep          --         doubles
 
-  | MallocPtrRep       -- This has to be a special kind because ccall
+  | ForeignObjRep      -- This has to be a special kind because ccall
                        -- generates special code when passing/returning
                        -- one of these. [ADR]
 
@@ -65,7 +69,6 @@ data PrimRep
                        -- (Primitive states are mapped onto this)
   deriving (Eq, Ord)
        -- Kinds are used in PrimTyCons, which need both Eq and Ord
-       -- Text is needed for derived-Text on PrimitiveOps
 \end{code}
 
 %************************************************************************
@@ -75,10 +78,12 @@ data PrimRep
 %************************************************************************
 
 Whether or not the thing is a pointer that the garbage-collector
-should follow.
+should follow. Or, to put it another (less confusing) way, whether
+the object in question is a heap object. 
 
-Or, to put it another (less confusing) way, whether the object in
-question is a heap object.
+Depending on the outcome, this predicate determines what stack
+the pointer/object possibly will have to be saved onto, and the
+computation of GC liveness info.
 
 \begin{code}
 isFollowableRep :: PrimRep -> Bool
@@ -86,7 +91,12 @@ isFollowableRep :: PrimRep -> Bool
 isFollowableRep PtrRep        = True
 isFollowableRep ArrayRep      = True
 isFollowableRep ByteArrayRep  = True
-isFollowableRep MallocPtrRep  = True
+-- why is a ForeignObj followable? 4/96 SOF
+--
+-- A: they're followable because these objects
+-- should be lugged around by the storage manager
+-- (==> registers containing them are live) -- 3/97 SOF
+isFollowableRep ForeignObjRep  = True
 
 isFollowableRep StablePtrRep  = False
 -- StablePtrs aren't followable because they are just indices into a
@@ -142,10 +152,35 @@ retPrimRepSize = getPrimRepSize RetRep
 
 \begin{code}
 instance Outputable PrimRep where
-    ppr sty kind = ppStr (showPrimRep kind)
+    ppr sty kind = text (showPrimRep kind)
 
 showPrimRep  :: PrimRep -> String
+-- dumping PrimRep tag for unfoldings
+ppPrimRep  :: PrimRep -> Doc
+
 guessPrimRep :: String -> PrimRep      -- a horrible "inverse" function
+decodePrimRep :: Char  -> PrimRep       -- of equal nature
+
+ppPrimRep k =
+ char 
+  (case k of
+     PtrRep        -> 'P'
+     CodePtrRep    -> 'p'
+     DataPtrRep    -> 'd'
+     CostCentreRep -> 'c'      -- Pointer to a cost centre
+     RetRep        -> 'R'
+     CharRep       -> 'C'
+     IntRep        -> 'I'
+     WordRep       -> 'W'
+     AddrRep       -> 'A'
+     FloatRep      -> 'F'
+     DoubleRep     -> 'D'
+     ArrayRep      -> 'a'
+     ByteArrayRep  -> 'b'
+     StablePtrRep  -> 'S'
+     ForeignObjRep -> 'f'
+     VoidRep       -> 'V'
+     _             -> panic "ppPrimRep")
 
 showPrimRep PtrRep         = "P_"      -- short for StgPtr
 
@@ -166,9 +201,29 @@ showPrimRep DoubleRep        = "StgDouble"
 showPrimRep ArrayRep     = "StgArray" -- see comment below
 showPrimRep ByteArrayRep  = "StgByteArray"
 showPrimRep StablePtrRep  = "StgStablePtr"
-showPrimRep MallocPtrRep  = "StgPtr" -- see comment below
+showPrimRep ForeignObjRep  = "StgPtr" -- see comment below
 showPrimRep VoidRep      = "!!VOID_KIND!!"
 
+decodePrimRep ch =
+ case ch of
+     'P' -> PtrRep        
+     'p' -> CodePtrRep    
+     'd' -> DataPtrRep    
+     'c' -> CostCentreRep 
+     'R' -> RetRep        
+     'C' -> CharRep       
+     'I' -> IntRep        
+     'W' -> WordRep       
+     'A' -> AddrRep       
+     'F' -> FloatRep      
+     'D' -> DoubleRep     
+     'a' -> ArrayRep      
+     'b' -> ByteArrayRep  
+     'S' -> StablePtrRep  
+     'f' -> ForeignObjRep 
+     'V' -> VoidRep
+     _   -> panic "decodePrimRep"
+
 guessPrimRep "D_"           = DataPtrRep
 guessPrimRep "StgRetAddr"   = RetRep
 guessPrimRep "StgChar"      = CharRep
@@ -186,15 +241,17 @@ All local C variables of @ArrayRep@ are declared in C as type
 @StgArray@.  The coercion to a more precise C type is done just before
 indexing (by the relevant C primitive-op macro).
 
-Nota Bene. There are three types associated with Malloc Pointers:
+Nota Bene. There are three types associated with @ForeignObj@ (MallocPtr++): 
 \begin{itemize}
 \item
-@StgMallocClosure@ is the type of the thing the C world gives us.
+@StgForeignObjClosure@ is the type of the thing the prim. op @mkForeignObj@ returns.
+{- old comment for MallocPtr
 (This typename is hardwired into @ppr_casm_results@ in
 @PprAbsC.lhs@.)
+-}
 
 \item
-@StgMallocPtr@ is the type of the thing we give the C world.
+@StgForeignObj@ is the type of the thing we give the C world.
 
 \item
 @StgPtr@ is the type of the (pointer to the) heap object which we