[commit: ghc] master: Make the StgWord/StgHalfWord types more similar (20670cc)

Ian Lynagh <[email protected]>
Newsgroups gmane.comp.lang.haskell.cvs.ghc
Message-ID <[email protected]>
Repository : ssh://darcs.haskell.org//srv/darcs/ghc

On branch  : master

http://hackage.haskell.org/trac/ghc/changeset/20670cc63395397cf2b9d80d9da27c77c1ebb8da

>---------------------------------------------------------------

commit 20670cc63395397cf2b9d80d9da27c77c1ebb8da
Author: Ian Lynagh <[email protected]>
Date:   Wed Sep 19 14:49:27 2012 +0100

    Make the StgWord/StgHalfWord types more similar
    
    Also added a couple of comments.

>---------------------------------------------------------------

 compiler/cmm/SMRep.lhs |   13 ++++++++-----
 1 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/compiler/cmm/SMRep.lhs b/compiler/cmm/SMRep.lhs
index 53110cf..d964448 100644
--- a/compiler/cmm/SMRep.lhs
+++ b/compiler/cmm/SMRep.lhs
@@ -76,6 +76,7 @@ roundUpToWords dflags n = (n + (wORD_SIZE dflags - 1)) .&. (complement (wORD_SIZ
 StgWord is a type representing an StgWord on the target platform.
 
 \begin{code}
+-- A Word64 is large enough to hold a Word for either a 32bit or 64bit platform
 newtype StgWord = StgWord Word64
     deriving (Eq,
 #if __GLASGOW_HASKELL__ < 706
@@ -100,23 +101,25 @@ instance Outputable StgWord where
 
 --
 
-newtype StgHalfWord = StgHalfWord Integer
+-- A Word32 is large enough to hold half a Word for either a 32bit or
+-- 64bit platform
+newtype StgHalfWord = StgHalfWord Word32
     deriving Eq
 
 fromStgHalfWord :: StgHalfWord -> Integer
-fromStgHalfWord (StgHalfWord i) = i
+fromStgHalfWord (StgHalfWord w) = toInteger w
 
 toStgHalfWord :: DynFlags -> Integer -> StgHalfWord
 toStgHalfWord dflags i
     = case platformWordSize (targetPlatform dflags) of
       -- These conversions mean that things like toStgHalfWord (-1)
       -- do the right thing
-      4 -> StgHalfWord (toInteger (fromInteger i :: Word16))
-      8 -> StgHalfWord (toInteger (fromInteger i :: Word32))
+      4 -> StgHalfWord (fromIntegral (fromInteger i :: Word16))
+      8 -> StgHalfWord (fromInteger i :: Word32)
       w -> panic ("toStgHalfWord: Unknown platformWordSize: " ++ show w)
 
 instance Outputable StgHalfWord where
-    ppr (StgHalfWord i) = integer i
+    ppr (StgHalfWord w) = integer (toInteger w)
 
 hALF_WORD_SIZE :: DynFlags -> ByteOff
 hALF_WORD_SIZE dflags = platformWordSize (targetPlatform dflags) `shiftR` 1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.