From: malcolm Date: Thu, 24 Apr 2003 12:25:28 +0000 (+0000) Subject: [project @ 2003-04-24 12:25:26 by malcolm] X-Git-Tag: nhc98-1-18-release~670 X-Git-Url: http://git.megacz.com/?p=ghc-base.git;a=commitdiff_plain;h=17c3536d93b3d35082ac025bb35176168c359165 [project @ 2003-04-24 12:25:26 by malcolm] Add instances of Data.Bits.Bits for Int/Word[8,16,32,64] in a different way. The module Data.Bits is only available from the base package, which is normally added to the link line *before* the standard libraries, hence if the instances are in the latter, you get link errors. So move the instances into the base package where they belong, in NHC.SizedTypes. --- diff --git a/Data/Int.hs b/Data/Int.hs index 8e0e8bd..8d3b202 100644 --- a/Data/Int.hs +++ b/Data/Int.hs @@ -37,6 +37,7 @@ import Hugs.Int ( Int8, Int16, Int32, Int64 ) import Prelude import Prelude (Int) import NHC.FFI (Int8, Int16, Int32, Int64) +import NHC.SizedTypes (Int8, Int16, Int32, Int64) -- instances of Bits #endif {- $notes diff --git a/Data/Word.hs b/Data/Word.hs index 23a1b57..3a0a795 100644 --- a/Data/Word.hs +++ b/Data/Word.hs @@ -35,6 +35,7 @@ import Hugs.Word #ifdef __NHC__ import NHC.FFI (Word8, Word16, Word32, Word64) +import NHC.SizedTypes (Word8, Word16, Word32, Word64) -- instances of Bits type Word = Word32 #endif diff --git a/Makefile.nhc98 b/Makefile.nhc98 index 086efce..2d287d1 100644 --- a/Makefile.nhc98 +++ b/Makefile.nhc98 @@ -11,6 +11,7 @@ SRCS = \ Data/HashTable.hs Data/Dynamic.hs Data/Monoid.hs Data/Tree.hs \ Control/Monad.hs Control/Monad/Fix.hs Control/Monad/Trans.hs \ Control/Arrow.hs Debug/Trace.hs \ + NHC/SizedTypes.hs \ System/IO.hs System/IO/Error.hs System/IO/Unsafe.hs \ System/Environment.hs System/Exit.hs System/Locale.hs \ System/Directory.hs System/Mem.hs System/Cmd.hs System/Info.hs \ @@ -49,6 +50,9 @@ SRCS = \ # Here are the main rules. include ../Makefile.common +# some extra rules +NHC/SizedTypes.hs: NHC/SizedTypes.hs.cpp + $(CC) -E $< >$@ # Here are the dependencies. $(OBJDIR)/Data/FiniteMap.$O: $(OBJDIR)/Data/Maybe.$O @@ -56,6 +60,9 @@ $(OBJDIR)/Data/Set.$O: $(OBJDIR)/Data/Maybe.$O $(OBJDIR)/Data/FiniteMap.$O $(OBJDIR)/Data/Array.$O: $(OBJDIR)/Data/Ix.$O $(OBJDIR)/Data/Dynamic.$O: $(OBJDIR)/Foreign/Ptr.$O \ $(OBJDIR)/Foreign/StablePtr.$O $(OBJDIR)/Data/HashTable.$O +$(OBJDIR)/Data/Int.$O: $(OBJDIR)/NHC/SizedTypes.$O +$(OBJDIR)/Data/Word.$O: $(OBJDIR)/NHC/SizedTypes.$O +$(OBJDIR)/NHC/SizedTypes.$O: $(OBJDIR)/Data/Bits.$O $(OBJDIR)/System/IO.$O: $(OBJDIR)/System/IO/Error.$O $(OBJDIR)/System/Random.$O: $(OBJDIR)/Data/Char.$O $(OBJDIR)/Data/IORef.$O \ $(OBJDIR)/System/IO/Unsafe.$O @@ -101,6 +108,9 @@ Data/FiniteMap.$C: Data/Maybe.$C Data/Set.$C: Data/Maybe.$C Data/FiniteMap.$C Data/Array.$C: Data/Ix.$C Data/Dynamic.$C: Foreign/Ptr.$C Data/HashTable.$C +Data/Int.$C: NHC/SizedTypes.$C +Data/Word.$C: NHC/SizedTypes.$C +NHC/SizedTypes.$C: Data/Bits.$C System/IO.$C: System/IO/Error.$C System/Random.$C: Data/Char.$C Data/IORef.$C System/IO/Unsafe.$C Debug/Trace.$C: System/IO.$C System/IO/Unsafe.$C diff --git a/NHC/SizedTypes.hs.cpp b/NHC/SizedTypes.hs.cpp new file mode 100644 index 0000000..50c3686 --- /dev/null +++ b/NHC/SizedTypes.hs.cpp @@ -0,0 +1,48 @@ +module NHC.SizedTypes + -- This module just adds instances of Bits for Int/Word[8,16,32,64] + ( Int8, Int16, Int32, Int64 + , Word8, Word16, Word32, Word64 + ) where + +{- Note explicit braces and semicolons here - layout is corrupted by cpp. -} + +{import NHC.FFI (Int8,Int16,Int32,Int64,Word8,Word16,Word32,Word64) +;import Data.Bits + +#define SIZED_TYPE(T,BS,S) \ +; FOREIGNS(T) \ +; INSTANCE_BITS(T,BS,S) + + +#define FOREIGNS(T) \ +; foreign import ccall nhc_prim##T##And :: T -> T -> T \ +; foreign import ccall nhc_prim##T##Or :: T -> T -> T \ +; foreign import ccall nhc_prim##T##Xor :: T -> T -> T \ +; foreign import ccall nhc_prim##T##Lsh :: T -> Int -> T \ +; foreign import ccall nhc_prim##T##Rsh :: T -> Int -> T \ +; foreign import ccall nhc_prim##T##Compl :: T -> T + + +#define INSTANCE_BITS(T,BS,S) \ +; instance Bits T where \ + { (.&.) = nhc_prim##T##And \ + ; (.|.) = nhc_prim##T##Or \ + ; xor = nhc_prim##T##Xor \ + ; complement = nhc_prim##T##Compl \ + ; shiftL = nhc_prim##T##Lsh \ + ; shiftR = nhc_prim##T##Rsh \ + ; bitSize _ = BS \ + ; isSigned _ = S \ + } + +SIZED_TYPE(Int8,8,True) +SIZED_TYPE(Int16,16,True) +SIZED_TYPE(Int32,32,True) +SIZED_TYPE(Int64,64,True) + +SIZED_TYPE(Word8,8,False) +SIZED_TYPE(Word16,16,False) +SIZED_TYPE(Word32,32,False) +SIZED_TYPE(Word64,64,False) + +}