[project @ 2001-12-05 17:35:12 by sewardj]
[ghc-hetmet.git] / ghc / compiler / prelude / PrimRep.lhs
index 9dfd5b4..8054366 100644 (file)
@@ -17,16 +17,13 @@ module PrimRep
       , is64BitRep
       , getPrimRepSize
       , getPrimRepSizeInBytes
+      , getPrimRepArrayElemSize
       , retPrimRepSize
-      , showPrimRep
-      , primRepString
-      , showPrimRepToUser
       ) where
 
 #include "HsVersions.h"
 
-import Constants ( dOUBLE_SIZE, iNT64_SIZE, wORD64_SIZE )
-import Util
+import Constants ( dOUBLE_SIZE, iNT64_SIZE, wORD64_SIZE, wORD_SIZE )
 import Outputable
 \end{code}
 
@@ -47,26 +44,43 @@ data PrimRep
   | CostCentreRep      -- Pointer to a cost centre
 
   | CharRep            -- Machine characters
-  | IntRep             --         integers (same size as ptr on this arch)
-  | WordRep            --         ditto (but *unsigned*)
-  | AddrRep            --         addresses ("C pointers")
+  | IntRep             --         signed   integers (same size as ptr on this arch)
+  | WordRep            --         unsigned integers (same size as ptr on this arch)
+  | AddrRep            --         addresses (C pointers)
   | FloatRep           --         floats
   | DoubleRep          --         doubles
-  | Word64Rep          --    guaranteed to be 64 bits (no more, no less.)
-  | Int64Rep           --    guaranteed to be 64 bits (no more, no less.)
+
+  | Int8Rep             --          8 bit signed   integers
+  | Int16Rep            --         16 bit signed   integers
+  | Int32Rep            --         32 bit signed   integers
+  | Int64Rep           --         64 bit signed   integers
+  | Word8Rep            --          8 bit unsigned integers
+  | Word16Rep           --         16 bit unsigned integers
+  | Word32Rep           --         32 bit unsigned integers
+  | Word64Rep          --         64 bit unsigned integers
 
   | WeakPtrRep
   | ForeignObjRep      
+  | BCORep
+
+  | StablePtrRep       -- guaranteed to be represented by a pointer
 
-  | StablePtrRep       -- We could replace this with IntRep but maybe
-                       -- there's some documentation gain from having
-                       -- it special? [ADR]
+  | StableNameRep      -- A stable name is a real heap object, unpointed,
+                       -- with one field containing an index into the
+                       -- stable pointer table.  It has to be a heap
+                       -- object so the garbage collector can track these
+                       -- objects and reclaim stable pointer entries.
 
   | ThreadIdRep                -- Really a pointer to a TSO
 
   | ArrayRep           -- Primitive array of Haskell pointers
   | ByteArrayRep       -- Primitive array of bytes (no Haskell pointers)
 
+  | PrimPtrRep         -- Used for MutVars and MVars; 
+                       -- a pointer to a primitive object
+                       -- ToDo: subsumes WeakPtrRep, ThreadIdRep, 
+                       -- StableNameRep, ForeignObjRep, and BCORep ?
+
   | VoidRep            -- Occupies no space at all!
                        -- (Primitive states are mapped onto this)
   deriving (Eq, Ord)
@@ -105,9 +119,12 @@ isFollowableRep ArrayRep      = True       -- all heap objects:
 isFollowableRep ByteArrayRep  = True   --      ''
 isFollowableRep WeakPtrRep    = True   --      ''
 isFollowableRep ForeignObjRep = True   --      ''
+isFollowableRep StableNameRep = True    --      ''
+isFollowableRep PrimPtrRep    = True    --      ''
 isFollowableRep ThreadIdRep   = True   -- pointer to a TSO
+isFollowableRep BCORep        = True
 
-isFollowableRep other          = False
+isFollowableRep other        = False
 
 separateByPtrFollowness :: (a -> PrimRep) -> [a] -> ([a], [a])
 
@@ -129,59 +146,80 @@ See codeGen/CgCon:cgTopRhsCon.
 
 \begin{code}
 isFloatingRep :: PrimRep -> Bool
-
 isFloatingRep DoubleRep = True
 isFloatingRep FloatRep  = True
-isFloatingRep other     = False
-
+isFloatingRep _         = False
 \end{code}
 
 \begin{code}
 is64BitRep :: PrimRep -> Bool
-
 is64BitRep Int64Rep  = True
 is64BitRep Word64Rep = True
-is64BitRep other     = False
-
+is64BitRep _         = False
 \end{code}
 
-
-
 \begin{code}
 getPrimRepSize :: PrimRep -> Int
+getPrimRepSize DoubleRep = dOUBLE_SIZE -- "words", of course
+getPrimRepSize Word64Rep = wORD64_SIZE
+getPrimRepSize Int64Rep  = iNT64_SIZE
+getPrimRepSize VoidRep   = 0
+getPrimRepSize _         = 1
 
-getPrimRepSize DoubleRep  = dOUBLE_SIZE        -- "words", of course
-getPrimRepSize Word64Rep  = wORD64_SIZE
-getPrimRepSize Int64Rep   = iNT64_SIZE
---getPrimRepSize FloatRep = 1
---getPrimRepSize CharRep  = 1  -- ToDo: count in bytes?
---getPrimRepSize ArrayRep = 1  -- Listed specifically for *documentation*
---getPrimRepSize ByteArrayRep = 1
-getPrimRepSize VoidRep   = 0
-getPrimRepSize other     = 1
-
+retPrimRepSize :: Int
 retPrimRepSize = getPrimRepSize RetRep
 
--- size in bytes, ToDo: cpp in the right vals.
+-- sizes in bytes.
 -- (used in some settings to figure out how many bytes
 -- we have to push onto the stack when calling external
--- entry points (e.g., stdcalling on win32))
+-- entry points (e.g., stdcalling on win32)
 getPrimRepSizeInBytes :: PrimRep -> Int
-getPrimRepSizeInBytes pr =
- case pr of
-    CharRep        ->    1
-    IntRep         ->    4
-    AddrRep        ->    4
-    FloatRep       ->    4
-    DoubleRep      ->    8
-    Word64Rep      ->    8
-    Int64Rep       ->    8
-    WeakPtrRep     ->    4
-    ForeignObjRep  ->    4
-    StablePtrRep   ->    4
-    ArrayRep       ->    4
-    ByteArrayRep   ->    4
-    _             ->   panic "getPrimRepSize: ouch - this wasn't supposed to happen!"
+getPrimRepSizeInBytes CharRep       = 4
+getPrimRepSizeInBytes IntRep        = wORD_SIZE
+getPrimRepSizeInBytes WordRep       = wORD_SIZE
+getPrimRepSizeInBytes AddrRep       = wORD_SIZE
+getPrimRepSizeInBytes FloatRep      = wORD_SIZE
+getPrimRepSizeInBytes DoubleRep     = dOUBLE_SIZE * wORD_SIZE
+getPrimRepSizeInBytes Int8Rep       = 1
+getPrimRepSizeInBytes Int16Rep      = 2
+getPrimRepSizeInBytes Int32Rep      = 4
+getPrimRepSizeInBytes Int64Rep      = 8
+getPrimRepSizeInBytes Word8Rep      = 1
+getPrimRepSizeInBytes Word16Rep     = 2
+getPrimRepSizeInBytes Word32Rep     = 4
+getPrimRepSizeInBytes Word64Rep     = 8
+getPrimRepSizeInBytes WeakPtrRep    = wORD_SIZE
+getPrimRepSizeInBytes ForeignObjRep = wORD_SIZE
+getPrimRepSizeInBytes StablePtrRep  = wORD_SIZE
+getPrimRepSizeInBytes StableNameRep = wORD_SIZE
+getPrimRepSizeInBytes ArrayRep      = wORD_SIZE
+getPrimRepSizeInBytes ByteArrayRep  = wORD_SIZE
+getPrimRepSizeInBytes other         = pprPanic "getPrimRepSizeInBytes" (ppr other)
+
+
+-- Sizes in bytes of things when they are array elements,
+-- so that we can generate the correct indexing code
+-- inside the compiler.  This is not the same as the above
+-- getPrimRepSizeInBytes, the rationale behind which is
+-- unclear to me.
+getPrimRepArrayElemSize :: PrimRep -> Int
+getPrimRepArrayElemSize PtrRep        = wORD_SIZE
+getPrimRepArrayElemSize IntRep        = wORD_SIZE
+getPrimRepArrayElemSize WordRep       = wORD_SIZE
+getPrimRepArrayElemSize AddrRep       = wORD_SIZE
+getPrimRepArrayElemSize StablePtrRep  = wORD_SIZE
+getPrimRepArrayElemSize ForeignObjRep = wORD_SIZE
+getPrimRepArrayElemSize Word8Rep      = 1
+getPrimRepArrayElemSize Word16Rep     = 2
+getPrimRepArrayElemSize Word32Rep     = 4
+getPrimRepArrayElemSize Word64Rep     = 8
+getPrimRepArrayElemSize Int8Rep       = 1
+getPrimRepArrayElemSize Int16Rep      = 2
+getPrimRepArrayElemSize Int32Rep      = 4
+getPrimRepArrayElemSize Int64Rep      = 8
+getPrimRepArrayElemSize FloatRep      = 4
+getPrimRepArrayElemSize DoubleRep     = 8
+getPrimRepArrayElemSize other         = pprPanic "getPrimRepSizeArrayElemSize" (ppr other)
 
 \end{code}
 
@@ -196,17 +234,18 @@ instance Outputable PrimRep where
     ppr kind = text (showPrimRep kind)
 
 showPrimRep  :: PrimRep -> String
-showPrimRepToUser :: PrimRep -> String
-
 showPrimRep PtrRep        = "P_"       -- short for StgPtr
-
-showPrimRep CodePtrRep     = "P_"      -- DEATH to StgFunPtr! (94/02/22 WDP)
-showPrimRep PtrRep         = "P_"      -- short for StgPtr
 showPrimRep CodePtrRep     = "P_"      -- DEATH to StgFunPtr! (94/02/22 WDP)
 showPrimRep DataPtrRep     = "D_"
 showPrimRep RetRep         = "P_"
 showPrimRep CostCentreRep  = "CostCentre"
 showPrimRep CharRep       = "C_"
+showPrimRep Int8Rep       = "StgInt8"
+showPrimRep Int16Rep      = "StgInt16"
+showPrimRep Int32Rep      = "StgInt32"
+showPrimRep Word8Rep      = "StgWord8"
+showPrimRep Word16Rep     = "StgWord16"
+showPrimRep Word32Rep     = "StgWord32"
 showPrimRep IntRep        = "I_"       -- short for StgInt
 showPrimRep WordRep       = "W_"       -- short for StgWord
 showPrimRep Int64Rep       = "LI_"       -- short for StgLongInt
@@ -215,27 +254,15 @@ showPrimRep AddrRep          = "StgAddr"
 showPrimRep FloatRep      = "StgFloat"
 showPrimRep DoubleRep     = "StgDouble"
 showPrimRep ArrayRep      = "P_" -- see comment below
+showPrimRep PrimPtrRep    = "P_"
 showPrimRep ByteArrayRep   = "StgByteArray"
 showPrimRep StablePtrRep   = "StgStablePtr"
+showPrimRep StableNameRep  = "P_"
 showPrimRep ThreadIdRep           = "StgTSO*"
 showPrimRep WeakPtrRep     = "P_"
 showPrimRep ForeignObjRep  = "StgAddr"
 showPrimRep VoidRep       = "!!VOID_KIND!!"
-
-primRepString CharRep          = "Char"
-primRepString IntRep           = "Int"
-primRepString WordRep          = "Word"
-primRepString Int64Rep         = "Int64"
-primRepString Word64Rep        = "Word64"
-primRepString AddrRep          = "Addr"
-primRepString FloatRep         = "Float"
-primRepString DoubleRep        = "Double"
-primRepString WeakPtrRep       = "Weak"
-primRepString ForeignObjRep    = "ForeignObj"
-primRepString StablePtrRep     = "StablePtr"
-primRepString other            = pprPanic "primRepString" (ppr other)
-
-showPrimRepToUser pr = primRepString pr
+showPrimRep BCORep         = "P_"      -- not sure -- JRS 000708
 \end{code}
 
 Foreign Objects and Arrays are treated specially by the code for