summaryrefslogtreecommitdiff
path: root/testsuite
diff options
context:
space:
mode:
Diffstat (limited to 'testsuite')
-rw-r--r--testsuite/tests/ghci/should_run/SizedLiterals.hs117
-rw-r--r--testsuite/tests/ghci/should_run/SizedLiterals.stdout10
-rw-r--r--testsuite/tests/ghci/should_run/SizedLiteralsA.hs139
-rw-r--r--testsuite/tests/ghci/should_run/all.T2
4 files changed, 268 insertions, 0 deletions
diff --git a/testsuite/tests/ghci/should_run/SizedLiterals.hs b/testsuite/tests/ghci/should_run/SizedLiterals.hs
new file mode 100644
index 0000000000..e02683d27c
--- /dev/null
+++ b/testsuite/tests/ghci/should_run/SizedLiterals.hs
@@ -0,0 +1,117 @@
+{-# LANGUAGE TemplateHaskell #-}
+
+import SizedLiteralsA
+import Language.Haskell.TH
+
+{-
+
+ This file is compiled with the GHC flags:
+
+ -O -fbyte-code-and-object-code -fprefer-byte-code
+
+ This makes sure that the Template Haskell runs in the bytecode
+ interpreter with optimized bytecode, allowing us to test the
+ sized unboxed literals.
+
+ Running the test in GHCi directly would disable optimization.
+
+ -}
+
+main :: IO ()
+main = do
+ print $(pure $ ListE [ ie (fibw8 5)
+ , ie (fibw16 5)
+ , ie (fibw32 5)
+ , ie (fibw64 5)
+ ])
+
+ print $(pure $ ListE [ ie (fibi8 5)
+ , ie (fibi16 5)
+ , ie (fibi32 5)
+ , ie (fibi64 5)
+ ])
+
+ print $(pure $ ListE [ ie (branchi8 0)
+ , ie (branchi8 1)
+ , ie (branchi8 (-1))
+ , ie (branchi8 126)
+ , ie (branchi8 127)
+ , ie (branchi8 (-127))
+ , ie (branchi8 (-128))
+ , ie (branchi8 2)
+ ])
+
+ print $(pure $ ListE [ ie (branchi16 0)
+ , ie (branchi16 1)
+ , ie (branchi16 (-1))
+ , ie (branchi16 32767)
+ , ie (branchi16 32766)
+ , ie (branchi16 (-32768))
+ , ie (branchi16 (-32767))
+ , ie (branchi16 2)
+ ])
+
+ print $(pure $ ListE [ ie (branchi32 0)
+ , ie (branchi32 1)
+ , ie (branchi32 (-1))
+ , ie (branchi32 2147483646)
+ , ie (branchi32 2147483647)
+ , ie (branchi32 (-2147483648))
+ , ie (branchi32 (-2147483647))
+ , ie (branchi32 2)
+ ])
+
+ print $(pure $ ListE [ ie (branchi64 0)
+ , ie (branchi64 1)
+ , ie (branchi64 (-1))
+ , ie (branchi64 2147483647)
+ , ie (branchi64 2147483648)
+ , ie (branchi64 4294967297)
+ , ie (branchi64 (-2147483648))
+ , ie (branchi64 (-2147483649))
+ , ie (branchi64 (-4294967295))
+ , ie (branchi64 9223372036854775807)
+ , ie (branchi64 9223372036854775806)
+ , ie (branchi64 (-9223372036854775808))
+ , ie (branchi64 (-9223372036854775807))
+ , ie (branchi64 2)
+ ])
+
+ print $(pure $ ListE [ ie (branchw8 0)
+ , ie (branchw8 1)
+ , ie (branchw8 254)
+ , ie (branchw8 255)
+ , ie (branchw8 2)
+ ])
+
+ print $(pure $ ListE [ ie (branchw16 0)
+ , ie (branchw16 1)
+ , ie (branchw16 255)
+ , ie (branchw16 256)
+ , ie (branchw16 65534)
+ , ie (branchw16 65535)
+ , ie (branchw16 2)
+ ])
+
+ print $(pure $ ListE [ ie (branchw32 0)
+ , ie (branchw32 1)
+ , ie (branchw32 65534)
+ , ie (branchw32 65535)
+ , ie (branchw32 65536)
+ , ie (branchw32 4294967295)
+ , ie (branchw32 4294967294)
+ , ie (branchw32 4294967293)
+ , ie (branchw32 2)
+ ])
+
+ print $(pure $ ListE [ ie (branchw64 0)
+ , ie (branchw64 1)
+ , ie (branchw64 65536)
+ , ie (branchw64 4294967295)
+ , ie (branchw64 4294967296)
+ , ie (branchw64 4294967297)
+ , ie (branchw64 18446744073709551615)
+ , ie (branchw64 18446744073709551614)
+ , ie (branchw64 18446744073709551613)
+ , ie (branchw64 2)
+ ]) \ No newline at end of file
diff --git a/testsuite/tests/ghci/should_run/SizedLiterals.stdout b/testsuite/tests/ghci/should_run/SizedLiterals.stdout
new file mode 100644
index 0000000000..a9013b05ff
--- /dev/null
+++ b/testsuite/tests/ghci/should_run/SizedLiterals.stdout
@@ -0,0 +1,10 @@
+[5,5,5,5]
+[5,5,5,5]
+[1,2,3,4,5,6,7,0]
+[1,2,3,255,256,65534,65535,0]
+[1,2,3,65535,65536,4294967294,4294967295,0]
+[18446744073709551615,2147483648,4294967296,4294967297,9,1,18446744073709551614,3,4,5,6,7,8,0]
+[1,-1,2,-2,0]
+[256,-256,32767,-32768,-1,1,0]
+[2147483647,-2147483648,65535,65536,-1,-65536,-65537,1,0]
+[9223372036854775807,2147483648,4294967296,4294967297,-1,9223372036854775806,-9223372036854775808,-9223372036854775807,1,0]
diff --git a/testsuite/tests/ghci/should_run/SizedLiteralsA.hs b/testsuite/tests/ghci/should_run/SizedLiteralsA.hs
new file mode 100644
index 0000000000..3cfec65071
--- /dev/null
+++ b/testsuite/tests/ghci/should_run/SizedLiteralsA.hs
@@ -0,0 +1,139 @@
+module SizedLiteralsA where
+
+import GHC.Word
+import GHC.Int
+import Language.Haskell.TH.Syntax
+
+fibw8 :: Word8 -> Word8
+fibw8 0 = 0
+fibw8 1 = 1
+fibw8 n = fibw8 (n-1) + fibw8 (n-2)
+
+fibw16 :: Word16 -> Word16
+fibw16 0 = 0
+fibw16 1 = 1
+fibw16 n = fibw16 (n-1) + fibw16 (n-2)
+
+fibw32 :: Word32 -> Word32
+fibw32 0 = 0
+fibw32 1 = 1
+fibw32 n = fibw32 (n-1) + fibw32 (n-2)
+
+fibw64 :: Word64 -> Word64
+fibw64 0 = 0
+fibw64 1 = 1
+fibw64 n = fibw64 (n-1) + fibw64 (n-2)
+
+--
+
+fibi8 :: Int8 -> Int8
+fibi8 0 = 0
+fibi8 1 = 1
+fibi8 n = fibi8 (n-1) + fibi8 (n-2)
+
+fibi16 :: Int16 -> Int16
+fibi16 0 = 0
+fibi16 1 = 1
+fibi16 n = fibi16 (n-1) + fibi16 (n-2)
+
+fibi32 :: Int32 -> Int32
+fibi32 0 = 0
+fibi32 1 = 1
+fibi32 n = fibi32 (n-1) + fibi32 (n-2)
+
+fibi64 :: Int64 -> Int64
+fibi64 0 = 0
+fibi64 1 = 1
+fibi64 n = fibi64 (n-1) + fibi64 (n-2)
+
+--
+
+branchi8 :: Int8 -> Word8
+branchi8 0 = 1
+branchi8 1 = 2
+branchi8 (-1) = 3
+branchi8 126 = 4
+branchi8 127 = 5
+branchi8 (-127) = 6
+branchi8 (-128) = 7
+branchi8 _ = 0
+
+branchi16 :: Int16 -> Word16
+branchi16 0 = 1
+branchi16 1 = 2
+branchi16 (-1) = 3
+branchi16 32767 = 255
+branchi16 32766 = 256
+branchi16 (-32768) = 65534
+branchi16 (-32767) = 65535
+branchi16 _ = 0
+
+branchi32 :: Int32 -> Word32
+branchi32 0 = 1
+branchi32 1 = 2
+branchi32 (-1) = 3
+branchi32 2147483646 = 65535
+branchi32 2147483647 = 65536
+branchi32 (-2147483648) = 4294967294
+branchi32 (-2147483647) = 4294967295
+branchi32 _ = 0
+
+branchi64 :: Int64 -> Word64
+branchi64 0 = 18446744073709551615
+branchi64 1 = 2147483648
+branchi64 (-1) = 4294967296
+branchi64 2147483647 = 4294967297
+branchi64 2147483648 = 9
+branchi64 4294967297 = 1
+branchi64 (-2147483648) = 18446744073709551614
+branchi64 (-2147483649) = 3
+branchi64 (-4294967295) = 4
+branchi64 9223372036854775807 = 5
+branchi64 9223372036854775806 = 6
+branchi64 (-9223372036854775808) = 7
+branchi64 (-9223372036854775807) = 8
+branchi64 _ = 0
+
+branchw8 :: Word8 -> Int8
+branchw8 0 = 1
+branchw8 1 = (-1)
+branchw8 254 = 2
+branchw8 255 = (-2)
+branchw8 _ = 0
+
+branchw16 :: Word16 -> Int16
+branchw16 0 = 256
+branchw16 1 = (-256)
+branchw16 255 = 32767
+branchw16 256 = (-32768)
+branchw16 65534 = (-1)
+branchw16 65535 = 1
+branchw16 _ = 0
+
+branchw32 :: Word32 -> Int32
+branchw32 0 = 2147483647
+branchw32 1 = (-2147483648)
+branchw32 65534 = 65535
+branchw32 65535 = 65536
+branchw32 65536 = (-1)
+branchw32 4294967295 = (-65536)
+branchw32 4294967294 = (-65537)
+branchw32 4294967293 = 1
+branchw32 _ = 0
+
+branchw64 :: Word64 -> Int64
+branchw64 0 = 9223372036854775807
+branchw64 1 = 2147483648
+branchw64 65536 = 4294967296
+branchw64 4294967295 = 4294967297
+branchw64 4294967296 = (-1)
+branchw64 4294967297 = 9223372036854775806
+branchw64 18446744073709551615 = (-9223372036854775808)
+branchw64 18446744073709551614 = (-9223372036854775807)
+branchw64 18446744073709551613 = 1
+branchw64 _ = 0
+
+--
+
+ie :: Integral a => a -> Exp
+ie x = LitE (IntegerL (toInteger x))
diff --git a/testsuite/tests/ghci/should_run/all.T b/testsuite/tests/ghci/should_run/all.T
index 935cbecd7d..331ffdb726 100644
--- a/testsuite/tests/ghci/should_run/all.T
+++ b/testsuite/tests/ghci/should_run/all.T
@@ -85,3 +85,5 @@ test('T19628', [extra_files(['T19628a.hs']), only_ways(['ghci']) ], compile_and_
test('T21052', just_ghci, ghci_script, ['T21052.script'])
test('T21300', just_ghci, ghci_script, ['T21300.script'])
test('UnliftedDataType2', just_ghci, compile_and_run, [''])
+test('SizedLiterals', [req_interp, extra_files(["SizedLiteralsA.hs"]),extra_hc_opts("-O -fbyte-code-and-object-code -fprefer-byte-code")], compile_and_run, [''])
+