Adjust behaviour of gcd
[ghc-base.git] / NHC / SizedTypes.hs
1 module NHC.SizedTypes
2   -- This module just adds instances of Bits for Int/Word[8,16,32,64]
3   ( Int8,  Int16,  Int32,  Int64
4   , Word8, Word16, Word32, Word64
5   ) where
6
7 {- Note explicit braces and semicolons here - layout is corrupted by cpp. -}
8
9 {
10   import NHC.FFI        (Int8,Int16,Int32,Int64,Word8,Word16,Word32,Word64)
11 ; import Data.Bits
12
13 #define SIZED_TYPE(T,BS,S)      \
14 ; FOREIGNS(T)                   \
15 ; INSTANCE_BITS(T,BS,S)
16
17
18 #define FOREIGNS(T)     \
19 ; foreign import ccall nhc_prim/**/T/**/And         :: T -> T   -> T    \
20 ; foreign import ccall nhc_prim/**/T/**/Or          :: T -> T   -> T    \
21 ; foreign import ccall nhc_prim/**/T/**/Xor         :: T -> T   -> T    \
22 ; foreign import ccall nhc_prim/**/T/**/Lsh         :: T -> Int -> T    \
23 ; foreign import ccall nhc_prim/**/T/**/Rsh         :: T -> Int -> T    \
24 ; foreign import ccall nhc_prim/**/T/**/Compl       :: T        -> T
25
26
27 #define INSTANCE_BITS(T,BS,S)           \
28 ; instance Bits T where                 \
29     { (.&.)      = nhc_prim/**/T/**/And \
30     ; (.|.)      = nhc_prim/**/T/**/Or  \
31     ; xor        = nhc_prim/**/T/**/Xor \
32     ; complement = nhc_prim/**/T/**/Compl       \
33     ; shiftL     = nhc_prim/**/T/**/Lsh \
34     ; shiftR     = nhc_prim/**/T/**/Rsh \
35     ; bitSize  _ = BS                   \
36     ; isSigned _ = S                    \
37     }
38
39 SIZED_TYPE(Int8,8,True)
40 SIZED_TYPE(Int16,16,True)
41 SIZED_TYPE(Int32,32,True)
42 SIZED_TYPE(Int64,64,True)
43
44 SIZED_TYPE(Word8,8,False)
45 SIZED_TYPE(Word16,16,False)
46 SIZED_TYPE(Word32,32,False)
47 SIZED_TYPE(Word64,64,False)
48
49 }