@@ -26,6 +26,13 @@ import Data.Functor.Identity (Identity (..))
26import Data.Proxy (Proxy(..))
26import Data.Proxy (Proxy(..))
27import GHC.Generics (Generic, Rep(..))
27import GHC.Generics (Generic, Rep(..))
28import GHC.Real (Ratio(..))
28import GHC.Real (Ratio(..))
31+XXX Will be added in the future
32+import Streamly.Internal.Data.Unbox.TH
33+import Language.Haskell.TH
29import Streamly.Internal.Data.Unbox
36import Streamly.Internal.Data.Unbox
30 ( PeekRep(..)
37 ( PeekRep(..)
31 , PokeRep(..)
38 , PokeRep(..)
@@ -44,57 +51,83 @@ import Test.Hspec as H
45--------------------------------------------------------------------------------
52--------------------------------------------------------------------------------
57+#define MODULE_NAME "Data.Unbox.Deriving.TH"
58+#define DERIVE_UNBOX(typ) $(makeUnbox ''typ)
60+#define MODULE_NAME "Data.Unbox.Deriving.Generic"
61+#define DERIVE_UNBOX(typ) deriving instance Unbox (typ)
64+--------------------------------------------------------------------------------
66+--------------------------------------------------------------------------------
47-- Unit instance uses a hack, so test all cases
68-- Unit instance uses a hack, so test all cases
48data Unit =
69data Unit =
50− deriving (Unbox, Show, Generic, Eq)
71+ deriving (Show, Generic, Eq)
52data UnarySum
74data UnarySum
55− deriving (Unbox, Show, Generic, Eq)
77+ deriving (Show, Generic, Eq)
78+DERIVE_UNBOX(UnarySum)
57data UnarySum2
81data UnarySum2
58 = UnitSum1 Unit
82 = UnitSum1 Unit
59 | UnitSum2 Unit
83 | UnitSum2 Unit
60− deriving (Generic, Unbox, Eq, Show)
84+ deriving (Generic, Eq, Show)
85+DERIVE_UNBOX(UnarySum2)
62data Unit1 =
87data Unit1 =
63 Unit1 Unit
88 Unit1 Unit
64− deriving (Generic, Unbox, Eq, Show)
89+ deriving (Generic, Eq, Show)
66data Unit2 =
92data Unit2 =
67 Unit2 Unit Unit
93 Unit2 Unit Unit
68− deriving (Generic, Unbox, Eq, Show)
94+ deriving (Generic, Eq, Show)
70data Unit3 =
97data Unit3 =
71 Unit3 Int Unit Int
98 Unit3 Int Unit Int
72− deriving (Generic, Unbox, Eq, Show)
99+ deriving (Generic, Eq, Show)
74data Unit4 =
102data Unit4 =
75 Unit4 Int Unit1 Int
103 Unit4 Int Unit1 Int
76− deriving (Generic, Unbox, Eq, Show)
104+ deriving (Generic, Eq, Show)
78{-# ANN Single "HLint: ignore" #-}
107{-# ANN Single "HLint: ignore" #-}
79data Single =
108data Single =
80 Single Int
109 Single Int
81− deriving (Unbox, Show, Generic, Eq)
110+ deriving (Show, Generic, Eq)
83data Product2 =
113data Product2 =
84 Product2 Int Char
114 Product2 Int Char
85− deriving (Unbox, Show, Generic, Eq)
115+ deriving (Show, Generic, Eq)
116+DERIVE_UNBOX(Product2)
87data SumOfProducts
118data SumOfProducts
89 | SOP1 Int
120 | SOP1 Int
90 | SOP2 Int Char
121 | SOP2 Int Char
91 | SOP3 Int Int Int
122 | SOP3 Int Int Int
92− deriving (Unbox, Show, Generic, Eq)
123+ deriving (Show, Generic, Eq)
124+DERIVE_UNBOX(SumOfProducts)
94data NestedSOP
126data NestedSOP
95 = NSOP0 SumOfProducts
127 = NSOP0 SumOfProducts
96 | NSOP1 SumOfProducts
128 | NSOP1 SumOfProducts
97− deriving (Unbox, Show, Generic, Eq)
129+ deriving (Show, Generic, Eq)
130+DERIVE_UNBOX(NestedSOP)
99--------------------------------------------------------------------------------
132--------------------------------------------------------------------------------
100-- Standalone derivations
133-- Standalone derivations
@@ -213,7 +246,7 @@ testCases = do
213--------------------------------------------------------------------------------
246--------------------------------------------------------------------------------
215moduleName :: String
248moduleName :: String
216−moduleName = "Data.Unboxed"
249+moduleName = MODULE_NAME
218main :: IO ()
251main :: IO ()
219main = hspec $ H.parallel $ describe moduleName testCases
252main = hspec $ H.parallel $ describe moduleName testCases