Permalink
Browse files

Get Bench.Nofib.Spectral.Constraints to build

  • Loading branch information...
1 parent 6e3c577 commit e8488f64ee610f35002ccb8d40e31cfcd6da1048 @nominolo committed Oct 21, 2012
View
@@ -179,7 +179,8 @@ TEST_FILES := tests/Bc/Bc0016.lcbc tests/Bc/Bc0014.lcbc \
tests/Bc/UnpackCString.lcbc tests/Bc/Monoid.lcbc \
tests/Bc/NopPrims.lcbc tests/Bc/NegateInt.lcbc \
tests/Bc/WordCompare.lcbc tests/Bc/TestShow.lcbc \
- tests/Bc/BitOps.lcbc
+ tests/Bc/BitOps.lcbc \
+ tests/Bench/Nofib/Spectral/Constraints.lcbc
lcvm: $(VM_SRCS:.cc=.o) vm/main.o
@echo "LINK $(filter %.o %.a, $^) => $@"
@@ -330,8 +331,10 @@ tests/%.lcbc: tests/%.hs
PRIM_MODULES_ghc-prim = GHC/Bool GHC/Types GHC/Ordering GHC/Tuple GHC/Unit
PRIM_MODULES_integer-gmp = GHC/Integer/Type GHC/Integer
-PRIM_MODULES_base = GHC/Base GHC/Classes GHC/Num GHC/List \
- Control/Exception/Base GHC/Enum Data/Maybe Data/Monoid GHC/Show
+PRIM_MODULES_base = GHC/Base GHC/Classes GHC/Num \
+ Control/Exception/Base GHC/Enum Data/Maybe GHC/List \
+ Data/Monoid GHC/Show GHC/Unicode Data/Char \
+ Data/Tuple Data/List
PRIM_MODULES = \
$(patsubst %,tests/ghc-prim/%.lcbc,$(PRIM_MODULES_ghc-prim)) \
@@ -1,11 +1,26 @@
+{-# LANGUAGE NoImplicitPrelude, CPP #-}
{- Andrew Tolmach and Thomas Nordin's contraint solver
See Proceedings of WAAAPL '99
-}
-import Prelude hiding (Maybe(Just,Nothing))
+
+#ifdef BENCH_GHC
+import Prelude hiding ( Maybe(..) )
import Data.List
import System.Environment
+import GHC.Base ( divInt, remInt )
+#else
+module Bench.Nofib.Spectral.Constraints where
+
+import Data.List
+import Data.Tuple
+--import GHC.Real
+import GHC.Base
+import GHC.List
+import GHC.Num
+import GHC.Show
+#endif
-----------------------------
-- The main program
@@ -15,17 +30,27 @@ run n expected =
let try algorithm = length (search algorithm (queens n)) in
all (==expected) (map try [bt, bm, bjbt, bjbt', fc])
+run1 n =
+ let try algorithm = length (search algorithm (queens n)) in
+ map try [bt, bm, bjbt, bjbt', fc]
+
bench = run 10 724
+test = run 4 2
+
+#ifdef BENCH_GHC
main = print bench
--main = main2
+
main2 = do
[arg] <- getArgs
let
n = read arg :: Int
try algorithm = print (length (search algorithm (queens n)))
sequence_ (map try [bt, bm, bjbt, bjbt', fc])
+#endif
+
-----------------------------
-- Figure 1. CSPs in Haskell.
@@ -66,11 +91,11 @@ inconsistencies CSP{rel=rel} as = [ (level a, level b) | a <- as, b <- reverse
consistent :: CSP -> State -> Bool
consistent csp = null . (inconsistencies csp)
-test :: CSP -> [State] -> [State]
-test csp = filter (consistent csp)
+testCSP :: CSP -> [State] -> [State]
+testCSP csp = filter (consistent csp)
solver :: CSP -> [State]
-solver csp = test csp candidates
+solver csp = testCSP csp candidates
where candidates = generate csp
queens :: Int -> CSP
@@ -185,8 +210,8 @@ btr seed csp = bt csp . hrandom seed
random2 :: Int -> Int
random2 n = if test > 0 then test else test + 2147483647
where test = 16807 * lo - 2836 * hi
- hi = n `div` 127773
- lo = n `rem` 127773
+ hi = n `divInt` 127773
+ lo = n `remInt` 127773
randoms :: Int -> [Int]
randoms = iterate random2
View
@@ -0,0 +1,58 @@
+{-# LANGUAGE NoImplicitPrelude, MagicHash #-}
+module Data.Char
+ (
+ Char
+
+ , String
+
+ -- * Character classification
+ -- | Unicode characters are divided into letters, numbers, marks,
+ -- punctuation, symbols, separators (including spaces) and others
+ -- (including control characters).
+ , isControl, isSpace
+ , isLower, isUpper, isAlpha, isAlphaNum, isPrint
+ , isDigit, isOctDigit, isHexDigit
+-- , isLetter, isMark, isNumber, isPunctuation, isSymbol, isSeparator
+
+ -- ** Subranges
+ , isAscii, isLatin1
+ , isAsciiUpper, isAsciiLower
+
+ -- ** Unicode general categories
+ -- , GeneralCategory(..), generalCategory
+
+ -- * Case conversion
+ , toUpper, toLower -- , toTitle -- :: Char -> Char
+
+ -- * Single digit characters
+ , digitToInt -- :: Char -> Int
+ , intToDigit -- :: Int -> Char
+
+ -- * Numeric representations
+ , ord -- :: Char -> Int
+ , chr -- :: Int -> Char
+
+ -- * String representations
+ -- , showLitChar -- :: Char -> ShowS
+ -- , lexLitChar -- :: ReadS String
+ -- , readLitChar -- :: ReadS Char
+
+ -- Implementation checked wrt. Haskell 98 lib report, 1/99.
+ ) where
+
+import GHC.Base
+import GHC.Show
+import GHC.Unicode
+import GHC.Num
+import GHC.Enum
+
+-- | Convert a single digit 'Char' to the corresponding 'Int'.
+-- This function fails unless its argument satisfies 'isHexDigit',
+-- but recognises both upper and lower-case hexadecimal digits
+-- (i.e. @\'0\'@..@\'9\'@, @\'a\'@..@\'f\'@, @\'A\'@..@\'F\'@).
+digitToInt :: Char -> Int
+digitToInt c
+ | isDigit c = ord c - ord '0'
+ | c >= 'a' && c <= 'f' = ord c - ord 'a' + 10
+ | c >= 'A' && c <= 'F' = ord c - ord 'A' + 10
+ | otherwise = error ("Char.digitToInt: not a digit " ++ show c) -- sigh
Oops, something went wrong.

0 comments on commit e8488f6

Please sign in to comment.