copilot-language 0.2 → 0.3
raw patch · 8 files changed
+53/−76 lines, 8 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Copilot.Language.Operators.Integral: (^) :: (Typed a, Typed b, Num a, Bits a, Integral b) => Stream a -> Stream b -> Stream a
Files
- copilot-language.cabal +1/−1
- src/Copilot/Language.hs +1/−1
- src/Copilot/Language/Operators/BitWise.hs +12/−14
- src/Copilot/Language/Operators/Boolean.hs +2/−2
- src/Copilot/Language/Operators/Integral.hs +14/−0
- src/Copilot/Language/Operators/Mux.hs +1/−1
- src/Copilot/Language/Prelude.hs +1/−0
- src/Copilot/Language/Stream.hs +21/−57
copilot-language.cabal view
@@ -1,6 +1,6 @@ cabal-version: >=1.10 name: copilot-language-version: 0.2+version: 0.3 synopsis: A Haskell-embedded DSL for monitoring hard real-time distributed systems. description: Blah blah blah...
src/Copilot/Language.hs view
@@ -2,7 +2,7 @@ -- Copyright © 2011 National Institute of Aerospace / Galois, Inc. -------------------------------------------------------------------------------- --- |+-- | Main Copilot language export file. module Copilot.Language ( module Data.Int
src/Copilot/Language/Operators/BitWise.hs view
@@ -5,36 +5,34 @@ {-# OPTIONS_GHC -fno-warn-orphans #-} module Copilot.Language.Operators.BitWise- ( Bits ( (.&.), complement, (.|.) )+ ( Bits ((.&.), complement, (.|.)) , (.^.) , (.<<.) , (.>>.) ) where -import Copilot.Core ( Typed, typeOf )+import Copilot.Core (Typed, typeOf) import qualified Copilot.Core as Core import Copilot.Language.Stream import qualified Prelude as P import Data.Bits -instance ( Typed a, Bits a ) => Bits ( Stream a ) where- (.&.) = Op2 ( Core.BwAnd typeOf )- complement = Op1 ( Core.BwNot typeOf )- (.|.) = Op2 ( Core.BwOr typeOf )- xor = Op2 ( Core.BwXor typeOf )+instance (Typed a, Bits a) => Bits (Stream a) where+ (.&.) = Op2 (Core.BwAnd typeOf)+ complement = Op1 (Core.BwNot typeOf)+ (.|.) = Op2 (Core.BwOr typeOf)+ xor = Op2 (Core.BwXor typeOf) shiftL = P.error "shiftL undefined, for left-shifting use .<<." shiftR = P.error "shiftR undefined, for right-shifting use .>>." rotate = P.error "tbd: rotate" bitSize = P.error "tbd: bitSize" isSigned = P.error "tbd: issigned" - -- Avoid redefinition of the Operators.Boolean xor-(.^.) :: ( Bits a ) => a -> a -> a+(.^.) :: Bits a => a -> a -> a (.^.) = xor --(.<<.), (.>>.) :: ( Bits a, Typed a, Typed b, P.Integral b ) =>- Stream a -> Stream b -> Stream a-(.<<.) = Op2 ( Core.BwShiftL typeOf typeOf )-(.>>.) = Op2 ( Core.BwShiftR typeOf typeOf )+(.<<.), (.>>.) :: (Bits a, Typed a, Typed b, P.Integral b) + => Stream a -> Stream b -> Stream a+(.<<.) = Op2 (Core.BwShiftL typeOf typeOf)+(.>>.) = Op2 (Core.BwShiftR typeOf typeOf)
src/Copilot/Language/Operators/Boolean.hs view
@@ -28,7 +28,7 @@ false :: Stream Bool false = constant False -infix 4 &&+infixr 4 && (&&) :: Stream Bool -> Stream Bool -> Stream Bool (Const False) && _ = false@@ -37,7 +37,7 @@ x && (Const True) = x x && y = Op2 Core.And x y -infix 4 ||+infixr 4 || (||) :: Stream Bool -> Stream Bool -> Stream Bool (Const True) || _ = true
src/Copilot/Language/Operators/Integral.hs view
@@ -7,12 +7,17 @@ module Copilot.Language.Operators.Integral ( div , mod+ , (^) ) where import Copilot.Core (Typed, typeOf) import qualified Copilot.Core as Core+import Copilot.Language.Operators.BitWise ((.<<.)) import Copilot.Language.Stream++import qualified Data.Bits as B import qualified Prelude as P+import Data.List (foldl', replicate) -------------------------------------------------------------------------------- @@ -27,5 +32,14 @@ (Const 0) `mod` _ = (Const 0) (Const x) `mod` (Const y) = Const (x `P.mod` y) x `mod` y = Op2 (Core.Mod typeOf) x y++(^) :: (Typed a, Typed b, P.Num a, B.Bits a, P.Integral b) + => Stream a -> Stream b -> Stream a+(Const 0) ^ _ = Const 0+(Const 1) ^ _ = Const 1+(Const x) ^ (Const y) = Const (x P.^ y)+(Const 2) ^ y = (Const 2) .<<. y+x ^ (Const y) = foldl' ((P.*)) (Const 1) (replicate (P.fromIntegral y) x)+_ ^ _ = Core.badUsage "in ^: in x ^ y, either x must be the constant 2, or y must be a constant. (Do not confuse ^ with bitwise XOR (.^.) or with ** for exponentation of floats/doubles.)" --------------------------------------------------------------------------------
src/Copilot/Language/Operators/Mux.hs view
@@ -2,7 +2,7 @@ -- Copyright © 2011 National Institute of Aerospace / Galois, Inc. -------------------------------------------------------------------------------- --- |+-- | if-then-else. module Copilot.Language.Operators.Mux ( mux
src/Copilot/Language/Prelude.hs view
@@ -15,6 +15,7 @@ , div, mod , (<=), (>=), (<), (>) , (&&)+ , (^) , (||) , const , drop
src/Copilot/Language/Stream.hs view
@@ -22,63 +22,27 @@ -------------------------------------------------------------------------------- data Stream :: * -> * where- Append- :: Typed a- => [a]- -> Maybe (Stream Bool)- -> Stream a- -> Stream a- Const- :: Typed a- => a- -> Stream a- Drop- :: Typed a- => Int- -> Stream a- -> Stream a- Extern- :: Typed a- => String- -> Maybe [a]- -> Stream a- ExternFun- :: Typed a- => String- -> [FunArg]- -> Maybe (Stream a)- -> Stream a- ExternArray- :: (Typed a, Typed b, Integral a)- => String- -> Stream a- -> Int- -> Maybe [[b]]- -> Stream b- Local- :: (Typed a, Typed b)- => Stream a- -> (Stream a -> Stream b)- -> Stream b- Var- :: Typed a- => String- -> Stream a- Op1- :: (Typed a, Typed b)- => Core.Op1 a b- -> Stream a -> Stream b- Op2- :: (Typed a, Typed b, Typed c)- => Core.Op2 a b c- -> Stream a -> Stream b -> Stream c- Op3- :: (Typed a, Typed b, Typed c, Typed d)- => Core.Op3 a b c d- -> Stream a- -> Stream b- -> Stream c- -> Stream d+ Append :: Typed a + => [a] -> Maybe (Stream Bool) -> Stream a -> Stream a+ Const :: Typed a => a -> Stream a+ Drop :: Typed a+ => Int -> Stream a -> Stream a+ Extern :: Typed a+ => String -> Maybe [a] -> Stream a+ ExternFun :: Typed a + => String -> [FunArg] -> Maybe (Stream a) -> Stream a+ ExternArray :: (Typed a, Typed b, Integral a)+ => String -> Stream a -> Int -> Maybe [[b]] -> Stream b+ Local :: (Typed a, Typed b) + => Stream a -> (Stream a -> Stream b) -> Stream b+ Var :: Typed a + => String -> Stream a+ Op1 :: (Typed a, Typed b)+ => Core.Op1 a b -> Stream a -> Stream b+ Op2 :: (Typed a, Typed b, Typed c)+ => Core.Op2 a b c -> Stream a -> Stream b -> Stream c+ Op3 :: (Typed a, Typed b, Typed c, Typed d)+ => Core.Op3 a b c d -> Stream a -> Stream b -> Stream c -> Stream d --------------------------------------------------------------------------------