[project @ 2000-09-06 10:23:52 by simonmar]
[ghc-hetmet.git] / ghc / compiler / prelude / PrimRep.lhs
index 9dfd5b4..ab6fdc4 100644 (file)
@@ -25,8 +25,7 @@ module PrimRep
 
 #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,6 +46,7 @@ data PrimRep
   | CostCentreRep      -- Pointer to a cost centre
 
   | CharRep            -- Machine characters
+  | Int8Rep             --         8 bit integers
   | IntRep             --         integers (same size as ptr on this arch)
   | WordRep            --         ditto (but *unsigned*)
   | AddrRep            --         addresses ("C pointers")
@@ -54,19 +54,35 @@ data PrimRep
   | DoubleRep          --         doubles
   | Word64Rep          --    guaranteed to be 64 bits (no more, no less.)
   | Int64Rep           --    guaranteed to be 64 bits (no more, no less.)
-
+  
+  -- Perhaps all sized integers and words should be primitive types.
+  
+  -- Int8Rep is currently used to simulate some old CharRep usages
+  -- when Char changed size from 8 to 31 bits. It does not correspond
+  -- to a Haskell unboxed type, in particular it's not used by Int8.
+  
   | 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 +121,11 @@ 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 other          = False
+isFollowableRep other        = False
 
 separateByPtrFollowness :: (a -> PrimRep) -> [a] -> ([a], [a])
 
@@ -162,26 +180,28 @@ getPrimRepSize other        = 1
 
 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!"
+    CharRep        ->    4
+    Int8Rep        ->    1
+    IntRep         ->    wORD_SIZE
+    AddrRep        ->    wORD_SIZE
+    FloatRep       ->    wORD_SIZE
+    DoubleRep      ->    dOUBLE_SIZE * wORD_SIZE
+    Word64Rep      ->    wORD64_SIZE * wORD_SIZE
+    Int64Rep       ->    iNT64_SIZE * wORD_SIZE
+    WeakPtrRep     ->    wORD_SIZE
+    ForeignObjRep  ->    wORD_SIZE
+    StablePtrRep   ->    wORD_SIZE
+    StableNameRep  ->    wORD_SIZE
+    ArrayRep       ->    wORD_SIZE
+    ByteArrayRep   ->    wORD_SIZE
+    _             ->    panic "getPrimRepSize: ouch - this wasn't supposed to happen!"
 
 \end{code}
 
@@ -199,14 +219,12 @@ 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 IntRep        = "I_"       -- short for StgInt
 showPrimRep WordRep       = "W_"       -- short for StgWord
 showPrimRep Int64Rep       = "LI_"       -- short for StgLongInt
@@ -215,14 +233,17 @@ 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 Int8Rep          = "Char" -- To have names like newCharArray#
 primRepString IntRep           = "Int"
 primRepString WordRep          = "Word"
 primRepString Int64Rep         = "Int64"
@@ -233,6 +254,7 @@ primRepString DoubleRep     = "Double"
 primRepString WeakPtrRep       = "Weak"
 primRepString ForeignObjRep    = "ForeignObj"
 primRepString StablePtrRep     = "StablePtr"
+primRepString StableNameRep    = "StableName"
 primRepString other            = pprPanic "primRepString" (ppr other)
 
 showPrimRepToUser pr = primRepString pr