summaryrefslogtreecommitdiff
path: root/libraries/integer-simple
diff options
context:
space:
mode:
authorIan Lynagh <igloo@earth.li>2011-09-17 19:45:44 +0100
committerIan Lynagh <igloo@earth.li>2011-09-17 19:45:44 +0100
commitd02622ad2cdb0af0824fc4226d2b16d9be34bb8a (patch)
tree981a66b0f8dace0a9a43aec7cfa88a226630f370 /libraries/integer-simple
parentcd4d0fbf2e70bb699126848503482790c9570881 (diff)
downloadhaskell-d02622ad2cdb0af0824fc4226d2b16d9be34bb8a.tar.gz
Define mkInteger
Now used by GHC to generate Integer literals.
Diffstat (limited to 'libraries/integer-simple')
-rw-r--r--libraries/integer-simple/GHC/Integer.hs2
-rw-r--r--libraries/integer-simple/GHC/Integer/Type.hs10
2 files changed, 11 insertions, 1 deletions
diff --git a/libraries/integer-simple/GHC/Integer.hs b/libraries/integer-simple/GHC/Integer.hs
index 66e35c965f..c9b50a7cf5 100644
--- a/libraries/integer-simple/GHC/Integer.hs
+++ b/libraries/integer-simple/GHC/Integer.hs
@@ -18,7 +18,7 @@
#include "MachDeps.h"
module GHC.Integer (
- Integer,
+ Integer, mkInteger,
smallInteger, wordToInteger, integerToWord, integerToInt,
#if WORD_SIZE_IN_BITS < 64
integerToWord64, word64ToInteger,
diff --git a/libraries/integer-simple/GHC/Integer/Type.hs b/libraries/integer-simple/GHC/Integer/Type.hs
index 7d1a90edca..02eeef24bd 100644
--- a/libraries/integer-simple/GHC/Integer/Type.hs
+++ b/libraries/integer-simple/GHC/Integer/Type.hs
@@ -51,6 +51,16 @@ type Digit = Word#
-- XXX Could move [] above us
data List a = Nil | Cons a (List a)
+mkInteger :: Bool -- non-negative?
+ -> [Int] -- absolute value in 31 bit chunks, least significant first
+ -- ideally these would be Words rather than Ints, but
+ -- we don't have Word available at the moment.
+ -> Integer
+mkInteger nonNegative is = let abs = f is
+ in if nonNegative then abs else negateInteger abs
+ where f [] = Naught
+ f (I# i : is') = smallInteger i `orInteger` shiftLInteger (f is') 31#
+
errorInteger :: Integer
errorInteger = Positive errorPositive