atom 1.0.5 → 1.0.6
raw patch · 5 files changed
+161/−11 lines, 5 filesdep +sybdep +uniplatePVP ok
version bump matches the API change (PVP)
Dependencies added: syb, uniplate
API changes (from Hackage documentation)
+ Language.Atom.Expressions: Acos :: E a -> E a
+ Language.Atom.Expressions: Acosh :: E a -> E a
+ Language.Atom.Expressions: Asin :: E a -> E a
+ Language.Atom.Expressions: Asinh :: E a -> E a
+ Language.Atom.Expressions: Atan :: E a -> E a
+ Language.Atom.Expressions: Atanh :: E a -> E a
+ Language.Atom.Expressions: Cos :: E a -> E a
+ Language.Atom.Expressions: Cosh :: E a -> E a
+ Language.Atom.Expressions: Exp :: E a -> E a
+ Language.Atom.Expressions: Log :: E a -> E a
+ Language.Atom.Expressions: Pi :: E a
+ Language.Atom.Expressions: Pow :: E a -> E a -> E a
+ Language.Atom.Expressions: Sin :: E a -> E a
+ Language.Atom.Expressions: Sinh :: E a -> E a
+ Language.Atom.Expressions: Sqrt :: E a -> E a
+ Language.Atom.Expressions: UAcos :: UE -> UE
+ Language.Atom.Expressions: UAcosh :: UE -> UE
+ Language.Atom.Expressions: UAsin :: UE -> UE
+ Language.Atom.Expressions: UAsinh :: UE -> UE
+ Language.Atom.Expressions: UAtan :: UE -> UE
+ Language.Atom.Expressions: UAtanh :: UE -> UE
+ Language.Atom.Expressions: UCos :: UE -> UE
+ Language.Atom.Expressions: UCosh :: UE -> UE
+ Language.Atom.Expressions: UExp :: UE -> UE
+ Language.Atom.Expressions: ULog :: UE -> UE
+ Language.Atom.Expressions: UPi :: UE
+ Language.Atom.Expressions: UPow :: UE -> UE -> UE
+ Language.Atom.Expressions: USin :: UE -> UE
+ Language.Atom.Expressions: USinh :: UE -> UE
+ Language.Atom.Expressions: USqrt :: UE -> UE
+ Language.Atom.Expressions: instance (Num a, Fractional a, Floating a, FloatingE a) => Floating (E a)
+ Language.Atom.Expressions: instance Data Const
+ Language.Atom.Expressions: instance Data Type
+ Language.Atom.Expressions: instance Data UA
+ Language.Atom.Expressions: instance Data UE
+ Language.Atom.Expressions: instance Data UV
+ Language.Atom.Expressions: instance Typeable Const
+ Language.Atom.Expressions: instance Typeable Type
+ Language.Atom.Expressions: instance Typeable UA
+ Language.Atom.Expressions: instance Typeable UE
+ Language.Atom.Expressions: instance Typeable UV
Files
- Language/Atom/Code.hs +44/−0
- Language/Atom/Elaboration.hs +11/−0
- Language/Atom/Expressions.hs +92/−7
- RELEASE-NOTES +8/−0
- atom.cabal +6/−4
Language/Atom/Code.hs view
@@ -11,6 +11,8 @@ import Data.Maybe import Text.Printf +import Data.Generics.Uniplate.Data+ import Language.Atom.Analysis import Language.Atom.Elaboration import Language.Atom.Expressions@@ -100,14 +102,55 @@ UD2B _ -> ["*((", ct Word64, " *) &(", a, "))"] UB2F _ -> ["*((", ct Float , " *) &(", a, "))"] UB2D _ -> ["*((", ct Double, " *) &(", a, "))"]+-- math.h:+ UPi -> [ "M_PI" ]+ UExp _ -> [ "exp", f, " ( ", a, " )"]+ ULog _ -> [ "log", f, " ( ", a, " )"]+ USqrt _ -> [ "sqrt", f, " ( ", a, " )"]+ UPow _ _ -> [ "pow", f, " ( ", a, ", ", b, " )"]+ USin _ -> [ "sin", f, " ( ", a, " )"]+ UAsin _ -> [ "asin", f, " ( ", a, " )"]+ UCos _ -> [ "cos", f, " ( ", a, " )"]+ UAcos _ -> [ "acos", f, " ( ", a, " )"]+ USinh _ -> [ "sinh", f, " ( ", a, " )"]+ UCosh _ -> [ "cosh", f, " ( ", a, " )"]+ UAsinh _ -> [ "asinh", f, " ( ", a, " )"]+ UAcosh _ -> [ "acosh", f, " ( ", a, " )"]+ UAtan _ -> [ "atan", f, " ( ", a, " )"]+ UAtanh _ -> [ "atanh", f, " ( ", a, " )"] where ct = cType a = head operands b = operands !! 1 c = operands !! 2+ f = case ( typeOf ue ) of+ Float -> "f"+ Double -> ""+ _ -> error "unhandled float type" + type RuleCoverage = [(Name, Int, Int)] +containMathHFunctions rules = any isMathHCall ues+ where ues = rules >>= allUEs >>= universe+ isMathHCall fc = case fc of+ UPi -> True+ UExp _ -> True+ ULog _ -> True+ USqrt _ -> True+ UPow _ _ -> True+ USin _ -> True+ UAsin _ -> True+ UCos _ -> True+ UAcos _ -> True+ USinh _ -> True+ UCosh _ -> True+ UAsinh _ -> True+ UAcosh _ -> True+ UAtan _ -> True+ UAtanh _ -> True+ _ -> False+ writeC :: Name -> Config -> StateHierarchy -> [Rule] -> Schedule -> [Name] -> [Name] -> [(Name, Type)] -> IO RuleCoverage writeC name config state rules schedule assertionNames coverageNames probeNames = do writeFile (name ++ ".c") c@@ -118,6 +161,7 @@ c = unlines [ "#include <stdbool.h>" , "#include <stdint.h>"+ , codeIf ( containMathHFunctions rules ) "#include <math.h>" , "" , preCode , ""
Language/Atom/Elaboration.hs view
@@ -27,6 +27,7 @@ import Control.Monad.Trans import Data.Function (on) import Data.List+import Data.Char import Language.Atom.Expressions type UID = Int@@ -273,11 +274,21 @@ addName :: Name -> Atom Name addName name = do (g, atom) <- get+ checkName name if elem name (atomNames atom) then error $ "ERROR: Name \"" ++ name ++ "\" not unique in " ++ show atom ++ "." else do put (g, atom { atomNames = name : atomNames atom }) return $ atomName atom ++ "." ++ name++-- still accepts some misformed names+checkName :: Name -> Atom ()+checkName name =+ if (\ x -> isAlpha x || x == '_') (head name) && + and (map (\ x -> isAlphaNum x || x `elem` "._-[]") (tail name)) && + and (map isAscii name)+ then return ()+ else error $ "ERROR: Name \"" ++ name ++ "\" is not a valid identifier." {- ruleGraph :: Name -> [Rule] -> [UV] -> IO ()
Language/Atom/Expressions.hs view
@@ -1,3 +1,5 @@+{-# LANGUAGE GADTs, DeriveDataTypeable #-}+ module Language.Atom.Expressions ( -- * Types@@ -77,6 +79,8 @@ import Data.Ratio import Data.Word +import Data.Generics hiding ( typeOf )+ --infixl 7 /., %. --infixl 6 +., -. --infixr 5 ++.@@ -99,7 +103,7 @@ | Word64 | Float | Double- deriving (Show, Read, Eq, Ord, Enum)+ deriving (Show, Read, Eq, Ord, Enum, Data, Typeable) data Const = CBool Bool@@ -113,7 +117,7 @@ | CWord64 Word64 | CFloat Float | CDouble Double- deriving (Eq, Ord)+ deriving (Eq, Ord, Data, Typeable) instance Show Const where show c = case c of@@ -165,7 +169,7 @@ = UV Int String Const | UVArray UA UE | UVExtern String Type- deriving (Show, Eq, Ord)+ deriving (Show, Eq, Ord, Data, Typeable) -- | A typed array. data A a = A UA deriving Eq@@ -174,7 +178,7 @@ data UA = UA Int String [Const] | UAExtern String Type- deriving (Show, Eq, Ord)+ deriving (Show, Eq, Ord, Data, Typeable) -- | A typed expression. data E a where@@ -200,6 +204,22 @@ B2F :: E Word32 -> E Float B2D :: E Word64 -> E Double Retype :: UE -> E a+-- math.h:+ Pi :: FloatingE a => E a+ Exp :: FloatingE a => E a -> E a+ Log :: FloatingE a => E a -> E a+ Sqrt :: FloatingE a => E a -> E a+ Pow :: FloatingE a => E a -> E a -> E a+ Sin :: FloatingE a => E a -> E a+ Asin :: FloatingE a => E a -> E a+ Cos :: FloatingE a => E a -> E a+ Acos :: FloatingE a => E a -> E a+ Sinh :: FloatingE a => E a -> E a+ Cosh :: FloatingE a => E a -> E a+ Asinh :: FloatingE a => E a -> E a+ Acosh :: FloatingE a => E a -> E a+ Atan :: FloatingE a => E a -> E a+ Atanh :: FloatingE a => E a -> E a instance Show (E a) where show _ = error "Show (E a) not implemented"@@ -230,7 +250,23 @@ | UD2B UE | UB2F UE | UB2D UE- deriving (Show, Eq, Ord)+-- math.h:+ | UPi+ | UExp UE+ | ULog UE+ | USqrt UE+ | UPow UE UE+ | USin UE+ | UAsin UE+ | UCos UE+ | UAcos UE+ | USinh UE+ | UCosh UE+ | UAsinh UE+ | UAcosh UE+ | UAtan UE+ | UAtanh UE+ deriving (Show, Eq, Ord, Data, Typeable) class Width a where width :: a -> Int@@ -314,6 +350,22 @@ UD2B _ -> Word64 UB2F _ -> Float UB2D _ -> Double+-- math.h:+ UPi -> Double+ UExp a -> typeOf a+ ULog a -> typeOf a+ USqrt a -> typeOf a+ UPow a _ -> typeOf a+ USin a -> typeOf a+ UAsin a -> typeOf a+ UCos a -> typeOf a+ UAcos a -> typeOf a+ USinh a -> typeOf a+ UCosh a -> typeOf a+ UAsinh a -> typeOf a+ UAcosh a -> typeOf a+ UAtan a -> typeOf a+ UAtanh a -> typeOf a instance Expr a => TypeOf (E a) where typeOf = eType@@ -473,7 +525,8 @@ recip a = 1 / a fromRational r = Const $ fromInteger (numerator r) / fromInteger (denominator r) -{-+-- make typed Atom expressions an instance of Floating+-- to generate calls to functions in math.h instance (Num a, Fractional a, Floating a, FloatingE a) => Floating (E a) where pi = Const pi exp (Const a) = Const $ exp a@@ -496,7 +549,6 @@ asinh a = log (a + sqrt (a ** 2 + 1)) acosh a = log (a + sqrt (a ** 2 - 1)) atanh a = 0.5 * log ((1 + a) / (1 - a))--} instance (Expr a, OrdE a, EqE a, IntegralE a, Bits a) => Bits (E a) where (Const a) .&. (Const b) = Const $ a .&. b@@ -684,6 +736,22 @@ UD2B a -> [a] UB2F a -> [a] UB2D a -> [a]+-- math.h:+ UPi -> []+ UExp a -> [a]+ ULog a -> [a]+ USqrt a -> [a]+ UPow a b -> [a, b]+ USin a -> [a]+ UAsin a -> [a]+ UCos a -> [a]+ UAcos a -> [a]+ USinh a -> [a]+ UCosh a -> [a]+ UAsinh a -> [a]+ UAcosh a -> [a]+ UAtan a -> [a]+ UAtanh a -> [a] -- | The list of all UVs that directly control the value of an expression. nearestUVs :: UE -> [UV]@@ -727,6 +795,23 @@ B2F a -> UB2F (ue a) B2D a -> UB2D (ue a) Retype a -> a+-- math.h:+ Pi -> UPi+ Exp a -> UExp (ue a)+ Log a -> ULog (ue a)+ Sqrt a -> USqrt (ue a)+ Pow a b -> UPow (ue a) (ue b)+ Sin a -> USin (ue a)+ Asin a -> UAsin (ue a)+ Cos a -> UCos (ue a)+ Acos a -> UAcos (ue a)+ Sinh a -> USinh (ue a)+ Cosh a -> UCosh (ue a)+ Asinh a -> UAsinh (ue a)+ Acosh a -> UAcosh (ue a)+ Atan a -> UAtan (ue a)+ Atanh a -> UAtanh (ue a)+ where tt = eType t
RELEASE-NOTES view
@@ -1,3 +1,11 @@+atom 1.0.6 09/20/2010++- Support for math.h expressions++atom 1.0.5 09/20/2010++- Deriving Enum for Type+ atom 1.0.4 05/23/2010 - Added 'exactPhase'. (Lee Pike)
atom.cabal view
@@ -1,5 +1,5 @@ name: atom-version: 1.0.5+version: 1.0.6 category: Language @@ -18,7 +18,7 @@ the need and overhead of RTOSs for many embedded applications. author: Tom Hawkins <tomahawkins@gmail.com>-maintainer: Tom Hawkins <tomahawkins@gmail.com>+maintainer: Tom Hawkins <tomahawkins@gmail.com>, Lee Pike <leepike@gmail.com> license: BSD3 license-file: LICENSE@@ -35,7 +35,9 @@ build-depends: base >= 4.0 && < 5, mtl >= 1.1.0.1 && < 1.2,- process >= 1.0.1.1 && < 1.2+ process >= 1.0.1.1 && < 1.2,+ syb >= 0.1.0.0 && < 0.2.0.0,+ uniplate >= 1.5.0 && < 2.0 exposed-modules: Language.Atom@@ -50,7 +52,7 @@ Language.Atom.Scheduling Language.Atom.Unit - extensions: GADTs+ extensions: GADTs, DeriveDataTypeable if impl(ghc > 6.8) ghc-options: -fwarn-tabs