on master help sign in
Add more TH helpers to TH.Bottom
commit88a43713fb5bfd57e5adc0a6f2da80d7d6602091 authorAdithya Kumar <adithya@composewell.com> dateTue 12 Sep 2023, 21:56 (3 years ago) parent64940c6
1 file changed+40−1
core/src/Streamly/Internal/Data/Serialize/TH/Bottom.hs+40−1
core/src/Streamly/Internal/Data/Serialize/TH/Bottom.hs+40−1
@@ -19,14 +19,18 @@ module Streamly.Internal.Data.Serialize.TH.Bottom
1919 , mkFieldName
2020 , isUnitType
2121 , c2w
22+ , wListToString
2223 , xorCmp
2324 , serializeW8List
2425 , litIntegral
26+ , litProxy
2527 , matchConstructor
2628 , openConstructor
2729 , makeI
30+ , makeN
2831 , makeA
2932 , int_w8
33+ , int_w32
3034 , w32_int
3135 , _acc
3236 , _arr
@@ -35,13 +39,17 @@ module Streamly.Internal.Data.Serialize.TH.Bottom
3539 , _x
3640 , _tag
3741 , _val
42+ , errorUnsupported
43+ , errorUnimplemented
3844 ) where
3945
40−import Data.Char (ord)
46+import Data.Char (chr, ord)
4147import Data.List (foldl')
4248import Data.Word (Word16, Word32, Word64, Word8)
4349import Data.Bits (Bits, (.|.), shiftL, zeroBits, xor)
4450import Streamly.Internal.System.IO (unsafeInlineIO)
51+import Streamly.Internal.Data.Unbox (Unbox)
52+import Data.Proxy (Proxy)
4553
4654import Language.Haskell.TH
4755import Streamly.Internal.Data.Serialize.Type
@@ -211,6 +219,9 @@ isUnitType _ = False
211219int_w8 :: Int -> Word8
212220int_w8 = fromIntegral
213221
222+int_w32 :: Int -> Word32
223+int_w32 = fromIntegral
224+
214225w8_w16 :: Word8 -> Word16
215226w8_w16 = fromIntegral
216227
@@ -226,6 +237,9 @@ w32_int = fromIntegral
226237c2w :: Char -> Word8
227238c2w = fromIntegral . ord
228239
240+wListToString :: [Word8] -> String
241+wListToString = fmap (chr . fromIntegral)
242+
229243--------------------------------------------------------------------------------
230244-- Bit manipulation
231245--------------------------------------------------------------------------------
@@ -349,3 +363,28 @@ serializeW8List off arr w8List = do
349363
350364litIntegral :: Integral a => a -> Q Exp
351365litIntegral = 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+ ]