Skip to content

Commit 3d52810

Browse files
hsyl20hvr
authored andcommitted
Add support for ghc-bignum package
1 parent a018432 commit 3d52810

File tree

2 files changed

+41
-25
lines changed

2 files changed

+41
-25
lines changed

Data/Text/Lazy/Builder/Int.hs

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,27 +28,35 @@ import Data.Text.Internal.Builder.Int.Digits (digits)
2828
import Data.Text.Array
2929
import Data.Word (Word, Word8, Word16, Word32, Word64)
3030
import GHC.Base (quotInt, remInt)
31-
import GHC.Num (quotRemInteger)
31+
import GHC.Types (Int(..))
3232
import Control.Monad.ST
3333
#if MIN_VERSION_base(4,11,0)
3434
import Prelude hiding ((<>))
3535
#endif
3636

3737
#ifdef __GLASGOW_HASKELL__
38+
39+
#if __GLASGOW_HASKELL__ >= 811
40+
41+
import GHC.Num.Integer
42+
#define HAS_INTEGER_CONSTR 1
43+
#define quotRemInteger integerQuotRem#
44+
45+
#else
46+
47+
import GHC.Num (quotRemInteger)
48+
3849
# if defined(INTEGER_GMP)
3950
import GHC.Integer.GMP.Internals (Integer(S#))
40-
import GHC.Types (Int(I#))
51+
#define IS S#
52+
#define HAS_INTEGER_CONSTR 1
4153
# elif defined(INTEGER_SIMPLE)
4254
import GHC.Integer ()
4355
# else
4456
# error "You need to use either GMP or integer-simple."
4557
# endif
4658
#endif
4759

48-
#if defined(INTEGER_GMP) || defined(INTEGER_SIMPLE)
49-
# define PAIR(a,b) (# a,b #)
50-
#else
51-
# define PAIR(a,b) (a,b)
5260
#endif
5361

5462
decimal :: Integral a => a -> Builder
@@ -199,9 +207,9 @@ hexDigit n
199207
data T = T !Integer !Int
200208

201209
integer :: Int -> Integer -> Builder
202-
#ifdef INTEGER_GMP
203-
integer 10 (S# i#) = decimal (I# i#)
204-
integer 16 (S# i#) = hexadecimal (I# i#)
210+
#ifdef HAS_INTEGER_CONSTR
211+
integer 10 (IS i#) = decimal (I# i#)
212+
integer 16 (IS i#) = hexadecimal (I# i#)
205213
#endif
206214
integer base i
207215
| i < 0 = singleton '-' <> go (-i)
@@ -215,12 +223,12 @@ integer base i
215223
| otherwise = splith p (splitf (p*p) n)
216224

217225
splith p (n:ns) = case n `quotRemInteger` p of
218-
PAIR(q,r) | q > 0 -> q : r : splitb p ns
226+
(# q,r #) | q > 0 -> q : r : splitb p ns
219227
| otherwise -> r : splitb p ns
220228
splith _ _ = error "splith: the impossible happened."
221229

222230
splitb p (n:ns) = case n `quotRemInteger` p of
223-
PAIR(q,r) -> q : r : splitb p ns
231+
(# q,r #) -> q : r : splitb p ns
224232
splitb _ _ = []
225233

226234
T maxInt10 maxDigits10 =
@@ -238,15 +246,15 @@ integer base i
238246
| otherwise = maxDigits16
239247

240248
putH (n:ns) = case n `quotRemInteger` maxInt of
241-
PAIR(x,y)
249+
(# x,y #)
242250
| q > 0 -> int q <> pblock r <> putB ns
243251
| otherwise -> int r <> putB ns
244252
where q = fromInteger x
245253
r = fromInteger y
246254
putH _ = error "putH: the impossible happened"
247255

248256
putB (n:ns) = case n `quotRemInteger` maxInt of
249-
PAIR(x,y) -> pblock q <> pblock r <> putB ns
257+
(# x,y #) -> pblock q <> pblock r <> putB ns
250258
where q = fromInteger x
251259
r = fromInteger y
252260
putB _ = Data.Monoid.mempty

text.cabal

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -175,12 +175,16 @@ library
175175
ghc-options: -Werror
176176
cpp-options: -DASSERTS
177177

178-
if flag(integer-simple)
179-
cpp-options: -DINTEGER_SIMPLE
180-
build-depends: integer-simple >= 0.1 && < 0.5
181-
else
182-
cpp-options: -DINTEGER_GMP
183-
build-depends: integer-gmp >= 0.2 && < 1.1
178+
if impl(ghc >= 8.11)
179+
build-depends: ghc-bignum
180+
181+
if impl(ghc < 8.11)
182+
if flag(integer-simple)
183+
cpp-options: -DINTEGER_SIMPLE
184+
build-depends: integer-simple >= 0.1 && < 0.5
185+
else
186+
cpp-options: -DINTEGER_GMP
187+
build-depends: integer-gmp >= 0.2 && < 1.1
184188

185189
-- compiler specification
186190
default-language: Haskell2010
@@ -310,12 +314,16 @@ test-suite tests
310314
else
311315
build-depends: bytestring >= 0.10.4
312316

313-
if flag(integer-simple)
314-
cpp-options: -DINTEGER_SIMPLE
315-
build-depends: integer-simple >= 0.1 && < 0.5
316-
else
317-
cpp-options: -DINTEGER_GMP
318-
build-depends: integer-gmp >= 0.2
317+
if impl(ghc >= 8.11)
318+
build-depends: ghc-bignum
319+
320+
if impl(ghc < 8.11)
321+
if flag(integer-simple)
322+
cpp-options: -DINTEGER_SIMPLE
323+
build-depends: integer-simple >= 0.1 && < 0.5
324+
else
325+
cpp-options: -DINTEGER_GMP
326+
build-depends: integer-gmp >= 0.2
319327

320328
default-language: Haskell2010
321329
default-extensions: NondecreasingIndentation

0 commit comments

Comments
 (0)