language-c99-util 0.1.1 → 0.2.0
raw patch · 4 files changed
+46/−29 lines, 4 filesdep +ieee754dep ~basedep ~language-c99PVP ok
version bump matches the API change (PVP)
Dependencies added: ieee754
Dependency ranges changed: base, language-c99
API changes (from Hackage documentation)
- Language.C99.Util: error_emptylist :: () => [Char] -> a
+ Language.C99.Util: error_emptylist :: [Char] -> a
Files
- ChangeLog.md +5/−0
- language-c99-util.cabal +3/−2
- src/Language/C99/Util/Expr.hs +37/−27
- src/Language/C99/Util/Wrap.hs +1/−0
ChangeLog.md view
@@ -1,5 +1,10 @@ # Revision history for language-c99-util +## 0.2.0 -- 2022-05-21++* Added FlexibleContexts to Wrap to support GHC 9.2.+* Added support for NaN, Infinity and -Infinity.+ ## 0.1.1 -- 2019-04-01 * Fixed version bounds on dependencies.
language-c99-util.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/ name: language-c99-util-version: 0.1.1+version: 0.2.0 synopsis: Utilities for language-c99. description: This library contains a number of utility functions and wrappers for the@@ -29,6 +29,7 @@ Language.C99.Util.Expr -- other-extensions: build-depends: base >=4.9 && <5,- language-c99 >= 0.1 && < 0.2+ language-c99 >= 0.2 && < 0.3,+ ieee754 >= 0.8.0 && < 0.9 hs-source-dirs: src default-language: Haskell2010
src/Language/C99/Util/Expr.hs view
@@ -91,36 +91,46 @@ | i > 0 = UnaryPostfix $ PostfixPrim $ constint i | i < 0 = UnaryOp UOMin (CastUnary $ litint (abs i)) -litdouble :: Double -> UnaryExpr-litdouble = parse . lex where- lex :: Double -> (String, String, String)- lex d | isInfinite d = error "Can't translate an infinite floating point number:"- | otherwise = (nat, dec, exp) where- ds = show d- e = dropWhile (/='e') ds- nat = takeWhile (/='.') ds- dec = takeWhile (/='e') $ tail $ dropWhile (/='.') ds- exp = case length e of- 0 -> ""- _ -> tail e+litfp :: (RealFloat a, Show a) => Maybe FloatSuffix -> a -> UnaryExpr+litfp mbFS n+ | isNaN n = UnaryPostfix $ PostfixPrim $ PrimIdent $ ident "NAN"+ | isInfinite n = case n > 0 of+ True -> UnaryPostfix $ PostfixPrim $ PrimIdent $ ident "INFINITY"+ False -> UnaryOp UOMin (CastUnary $ UnaryPostfix $ PostfixPrim $ PrimIdent $ ident "INFINITY")+ | otherwise = litfpFinite mbFS n+ where+ litfpFinite :: (RealFloat a, Show a) => Maybe FloatSuffix -> a -> UnaryExpr+ litfpFinite mbFS = parse . lex where+ lex :: (RealFloat a, Show a) => a -> (String, String, String)+ lex d = (nat, dec, exp) where+ ds = show d+ e = dropWhile (/='e') ds+ nat = takeWhile (/='.') ds+ dec = takeWhile (/='e') $ tail $ dropWhile (/='.') ds+ exp = case length e of+ 0 -> ""+ _ -> tail e - parse :: (String, String, String) -> UnaryExpr- parse (nat, dec, exp) = op $ PostfixPrim $ PrimConst $ ConstFloat $ FloatDec $ DecFloatFrac (FracZero (Just nat') dec') exp' Nothing where- op = case head nat of- '-' -> UnaryOp UOMin . CastUnary . UnaryPostfix- _ -> UnaryPostfix- nat' = case head nat of- '-' -> digitseq $ digitsc (tail nat)- _ -> digitseq $ digitsc nat- dec' = digitseq $ digitsc dec- exp' = case exp of- "" -> Nothing- (e:es) -> case e of- '-' -> Just $ E (Just SMinus) (digitseq $ digitsc es)- _ -> Just $ E Nothing (digitseq $ digitsc (e:es))+ parse :: (String, String, String) -> UnaryExpr+ parse (nat, dec, exp) = op $ PostfixPrim $ PrimConst $ ConstFloat $ FloatDec $ DecFloatFrac (FracZero (Just nat') dec') exp' mbFS where+ op = case head nat of+ '-' -> UnaryOp UOMin . CastUnary . UnaryPostfix+ _ -> UnaryPostfix+ nat' = case head nat of+ '-' -> digitseq $ digitsc (tail nat)+ _ -> digitseq $ digitsc nat+ dec' = digitseq $ digitsc dec+ exp' = case exp of+ "" -> Nothing+ (e:es) -> case e of+ '-' -> Just $ E (Just SMinus) (digitseq $ digitsc es)+ _ -> Just $ E Nothing (digitseq $ digitsc (e:es)) +litdouble :: Double -> UnaryExpr+litdouble = litfp Nothing+ litfloat :: Float -> UnaryExpr-litfloat = litdouble . realToFrac+litfloat = litfp (Just FF) litstring :: String -> UnaryExpr litstring ss = wrap $ PrimString $ StringLit $ (sl ss) where
src/Language/C99/Util/Wrap.hs view
@@ -2,6 +2,7 @@ {-# LANGUAGE FunctionalDependencies #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE UndecidableInstances #-}+{-# LANGUAGE FlexibleContexts #-} module Language.C99.Util.Wrap ( Wrap