on master help sign in
Add more TH helpers to TH.Bottom
88a4371Adithya Kumar
core/src/Streamly/Internal/Data/Serialize/TH/Bottom.hs+40−1
@@ -19,14 +19,18 @@ module Streamly.Internal.Data.Serialize.TH.Bottom
19 , mkFieldName
19 , mkFieldName
20 , isUnitType
20 , isUnitType
21 , c2w
21 , c2w
22+ , wListToString
22 , xorCmp
23 , xorCmp
23 , serializeW8List
24 , serializeW8List
24 , litIntegral
25 , litIntegral
26+ , litProxy
25 , matchConstructor
27 , matchConstructor
26 , openConstructor
28 , openConstructor
27 , makeI
29 , makeI
30+ , makeN
28 , makeA
31 , makeA
29 , int_w8
32 , int_w8
33+ , int_w32
30 , w32_int
34 , w32_int
31 , _acc
35 , _acc
32 , _arr
36 , _arr
@@ -35,13 +39,17 @@ module Streamly.Internal.Data.Serialize.TH.Bottom
35 , _x
39 , _x
36 , _tag
40 , _tag
37 , _val
41 , _val
42+ , errorUnsupported
43+ , errorUnimplemented
38 ) where
44 ) where
39
45
40−import Data.Char (ord)
46+import Data.Char (chr, ord)
41import Data.List (foldl')
47import Data.List (foldl')
42import Data.Word (Word16, Word32, Word64, Word8)
48import Data.Word (Word16, Word32, Word64, Word8)
43import Data.Bits (Bits, (.|.), shiftL, zeroBits, xor)
49import Data.Bits (Bits, (.|.), shiftL, zeroBits, xor)
44import Streamly.Internal.System.IO (unsafeInlineIO)
50import Streamly.Internal.System.IO (unsafeInlineIO)
51+import Streamly.Internal.Data.Unbox (Unbox)
52+import Data.Proxy (Proxy)
45
53
46import Language.Haskell.TH
54import Language.Haskell.TH
47import Streamly.Internal.Data.Serialize.Type
55import Streamly.Internal.Data.Serialize.Type
@@ -211,6 +219,9 @@ isUnitType _ = False
211int_w8 :: Int -> Word8
219int_w8 :: Int -> Word8
212int_w8 = fromIntegral
220int_w8 = fromIntegral
213
221
222+int_w32 :: Int -> Word32
223+int_w32 = fromIntegral
224+
214w8_w16 :: Word8 -> Word16
225w8_w16 :: Word8 -> Word16
215w8_w16 = fromIntegral
226w8_w16 = fromIntegral
216
227
@@ -226,6 +237,9 @@ w32_int = fromIntegral
226c2w :: Char -> Word8
237c2w :: Char -> Word8
227c2w = fromIntegral . ord
238c2w = fromIntegral . ord
228
239
240+wListToString :: [Word8] -> String
241+wListToString = fmap (chr . fromIntegral)
242+
229--------------------------------------------------------------------------------
243--------------------------------------------------------------------------------
230-- Bit manipulation
244-- Bit manipulation
231--------------------------------------------------------------------------------
245--------------------------------------------------------------------------------
@@ -349,3 +363,28 @@ serializeW8List off arr w8List = do
349
363
350litIntegral :: Integral a => a -> Q Exp
364litIntegral :: Integral a => a -> Q Exp
351litIntegral = litE . IntegerL . fromIntegral
365litIntegral = litE . IntegerL . fromIntegral
366+
367+litProxy :: Unbox a => Proxy a -> Q Exp
368+litProxy = litE . IntegerL . fromIntegral . Unbox.sizeOf
369+
370+--------------------------------------------------------------------------------
371+-- Error codes
372+--------------------------------------------------------------------------------
373+
374+errorUnsupported :: a
375+errorUnsupported =
376+ error
377+ $ unlines
378+ [ "Unsupported."
379+ , "There is improper use of the library."
380+ , "This case is unsupported."
381+ , "Please contact the developer if this case is of interest."
382+ ]
383+
384+errorUnimplemented :: a
385+errorUnimplemented =
386+ error
387+ $ unlines
388+ [ "Unimplemented."
389+ , "Please contact the developer if this case is of interest."
390+ ]