From 36bcfe980b04b6f083d2154909d8f1fb41e32e28 Mon Sep 17 00:00:00 2001 From: malcolm Date: Tue, 15 Jun 2004 10:20:05 +0000 Subject: [PATCH] [project @ 2004-06-15 10:20:05 by malcolm] Add missing instances of Data.Bits.Bits for nhc98. --- Foreign/C/Types.hs | 60 +++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 48 insertions(+), 12 deletions(-) diff --git a/Foreign/C/Types.hs b/Foreign/C/Types.hs index ae62af2..0eb64d0 100644 --- a/Foreign/C/Types.hs +++ b/Foreign/C/Types.hs @@ -45,18 +45,7 @@ module Foreign.C.Types , CFile, CFpos, CJmpBuf ) where -#ifdef __NHC__ -import NHC.FFI - ( CChar(..), CSChar(..), CUChar(..) - , CShort(..), CUShort(..), CInt(..), CUInt(..) - , CLong(..), CULong(..), CLLong(..), CULLong(..) - , CPtrdiff(..), CSize(..), CWchar(..), CSigAtomic(..) - , CClock(..), CTime(..) - , CFloat(..), CDouble(..), CLDouble(..) - , CFile, CFpos, CJmpBuf - , Storable(..) - ) -#else +#ifndef __NHC__ import Foreign.Storable import Data.Bits ( Bits(..) ) @@ -165,4 +154,51 @@ data CJmpBuf = CJmpBuf -- C99 types which are still missing include: -- intptr_t, uintptr_t, intmax_t, uintmax_t, wint_t, wctrans_t, wctype_t +#else /* __NHC__ */ + +import NHC.FFI + ( CChar(..), CSChar(..), CUChar(..) + , CShort(..), CUShort(..), CInt(..), CUInt(..) + , CLong(..), CULong(..), CLLong(..), CULLong(..) + , CPtrdiff(..), CSize(..), CWchar(..), CSigAtomic(..) + , CClock(..), CTime(..) + , CFloat(..), CDouble(..), CLDouble(..) + , CFile, CFpos, CJmpBuf + , Storable(..) + ) +import Data.Bits +import NHC.SizedTypes + +#define INSTANCE_BITS(T) \ +instance Bits T where { \ + (T x) .&. (T y) = T (x .&. y) ; \ + (T x) .|. (T y) = T (x .|. y) ; \ + (T x) `xor` (T y) = T (x `xor` y) ; \ + complement (T x) = T (complement x) ; \ + shift (T x) n = T (shift x n) ; \ + rotate (T x) n = T (rotate x n) ; \ + bit n = T (bit n) ; \ + setBit (T x) n = T (setBit x n) ; \ + clearBit (T x) n = T (clearBit x n) ; \ + complementBit (T x) n = T (complementBit x n) ; \ + testBit (T x) n = testBit x n ; \ + bitSize (T x) = bitSize x ; \ + isSigned (T x) = isSigned x } + +INSTANCE_BITS(CChar) +INSTANCE_BITS(CSChar) +INSTANCE_BITS(CUChar) +INSTANCE_BITS(CShort) +INSTANCE_BITS(CUShort) +INSTANCE_BITS(CInt) +INSTANCE_BITS(CUInt) +INSTANCE_BITS(CLong) +INSTANCE_BITS(CULong) +INSTANCE_BITS(CLLong) +INSTANCE_BITS(CULLong) +INSTANCE_BITS(CPtrdiff) +INSTANCE_BITS(CWchar) +INSTANCE_BITS(CSigAtomic) +INSTANCE_BITS(CSize) + #endif -- 1.7.10.4