clash-prelude 0.10.7 → 0.10.8
raw patch · 9 files changed
+100/−9 lines, 9 files
Files
- CHANGELOG.md +6/−0
- clash-prelude.cabal +3/−1
- src/CLaSH/Class/BitPack.hs +37/−0
- src/CLaSH/Sized/Fixed.hs +12/−0
- src/CLaSH/Sized/Internal/BitVector.hs +3/−0
- src/CLaSH/Sized/Internal/Index.hs +10/−0
- src/CLaSH/Sized/Internal/Signed.hs +10/−0
- src/CLaSH/Sized/Internal/Unsigned.hs +10/−0
- src/CLaSH/Tutorial.hs +9/−8
CHANGELOG.md view
@@ -1,5 +1,11 @@ # Changelog for [`clash-prelude` package](http://hackage.haskell.org/package/clash-prelude) +## 0.10.8 *June 7th 2016*+* New features:+ * Instances of `Data` for numeric types.+ * Instances of `Read` for {Index, Signed, Unsigned, Fixed}+ * Instances of `BitPack` for 3-8 tuples+ ## 0.10.7 *April 7th 2016* * Support doctest-0.11.0
clash-prelude.cabal view
@@ -1,5 +1,5 @@ Name: clash-prelude-Version: 0.10.7+Version: 0.10.8 Synopsis: CAES Language for Synchronous Hardware - Prelude library Description: CλaSH (pronounced ‘clash’) is a functional hardware description language that@@ -172,6 +172,8 @@ -- See: https://github.com/clash-lang/clash-compiler/commit/721fcfa9198925661cd836668705f817bddaae3c -- as to why we need this. ghc-options: -fcpr-off+ else+ other-extensions: DeriveLift if flag(doclinks) CPP-Options: -DDOCLINKS
src/CLaSH/Class/BitPack.hs view
@@ -10,6 +10,7 @@ {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE TypeOperators #-} {-# LANGUAGE UndecidableInstances #-}+{-# LANGUAGE ViewPatterns #-} {-# LANGUAGE Trustworthy #-} @@ -86,6 +87,42 @@ type BitSize (a,b) = BitSize a + BitSize b pack (a,b) = pack a ++# pack b unpack ab = let (a,b) = split# ab in (unpack a, unpack b)++instance (KnownNat (BitSize c), BitPack (a,b), BitPack c) =>+ BitPack (a,b,c) where+ type BitSize (a,b,c) = BitSize (a,b) + BitSize c+ pack (a,b,c) = pack (a,b) ++# pack c+ unpack (unpack -> ((a,b), c)) = (a,b,c)++instance (KnownNat (BitSize d), BitPack (a,b,c), BitPack d) =>+ BitPack (a,b,c,d) where+ type BitSize (a,b,c,d) = BitSize (a,b,c) + BitSize d+ pack (a,b,c,d) = pack (a,b,c) ++# pack d+ unpack (unpack -> ((a,b,c), d)) = (a,b,c,d)++instance (KnownNat (BitSize e), BitPack (a,b,c,d), BitPack e) =>+ BitPack (a,b,c,d,e) where+ type BitSize (a,b,c,d,e) = BitSize (a,b,c,d) + BitSize e+ pack (a,b,c,d,e) = pack (a,b,c,d) ++# pack e+ unpack (unpack -> ((a,b,c,d), e)) = (a,b,c,d,e)++instance (KnownNat (BitSize f), BitPack (a,b,c,d,e), BitPack f) =>+ BitPack (a,b,c,d,e,f) where+ type BitSize (a,b,c,d,e,f) = BitSize (a,b,c,d,e) + BitSize f+ pack (a,b,c,d,e,f) = pack (a,b,c,d,e) ++# pack f+ unpack (unpack -> ((a,b,c,d,e), f)) = (a,b,c,d,e,f)++instance (KnownNat (BitSize g), BitPack (a,b,c,d,e,f), BitPack g) =>+ BitPack (a,b,c,d,e,f,g) where+ type BitSize (a,b,c,d,e,f,g) = BitSize (a,b,c,d,e,f) + BitSize g+ pack (a,b,c,d,e,f,g) = pack (a,b,c,d,e,f) ++# pack g+ unpack (unpack -> ((a,b,c,d,e,f), g)) = (a,b,c,d,e,f,g)++instance (KnownNat (BitSize h), BitPack (a,b,c,d,e,f,g), BitPack h) =>+ BitPack (a,b,c,d,e,f,g,h) where+ type BitSize (a,b,c,d,e,f,g,h) = BitSize (a,b,c,d,e,f,g) + BitSize h+ pack (a,b,c,d,e,f,g,h) = pack (a,b,c,d,e,f,g) ++# pack h+ unpack (unpack -> ((a,b,c,d,e,f,g), h)) = (a,b,c,d,e,f,g,h) -- | Zero-extend a 'Bool'ean value to a 'BitVector' of the appropriate size. --
src/CLaSH/Sized/Fixed.hs view
@@ -24,6 +24,7 @@ {-# LANGUAGE ConstraintKinds #-} {-# LANGUAGE DataKinds #-}+{-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-} {-# LANGUAGE KindSignatures #-}@@ -68,7 +69,9 @@ import Control.Arrow ((***), second) import Data.Bits (Bits (..), FiniteBits)+import Data.Data (Data) import Data.Default (Default (..))+import Text.Read (Read(..)) import Data.List (find) import Data.Maybe (fromJust) import Data.Proxy (Proxy (..))@@ -112,6 +115,8 @@ newtype Fixed (rep :: Nat -> *) (int :: Nat) (frac :: Nat) = Fixed { unFixed :: rep (int + frac) } +deriving instance (Typeable rep, Typeable int, Typeable frac+ , Data (rep (int + frac))) => Data (Fixed rep int frac) deriving instance Eq (rep (int + frac)) => Eq (Fixed rep int frac) deriving instance Ord (rep (int + frac)) => Ord (Fixed rep int frac) deriving instance Enum (rep (int + frac)) => Enum (Fixed rep int frac)@@ -138,6 +143,8 @@ -- 3.9375 -- >>> minBound :: SFixed 3 4 -- -4.0+-- >>> read (show (maxBound :: SFixed 3 4)) :: SFixed 3 4+-- 3.9375 -- >>> 1 + 2 :: SFixed 3 4 -- 3.0 -- >>> 2 + 3 :: SFixed 3 4@@ -248,6 +255,11 @@ nom = if fRepI < 0 then fRepI_abs .&. ((2 ^ nF) - 1) else fRepI .&. ((2 ^ nF) - 1) denom = 2 ^ nF++-- | None of the 'Read' class' methods are synthesisable.+instance (size ~ (int + frac), KnownNat frac, Bounded (rep size), Integral (rep size))+ => Read (Fixed rep int frac) where+ readPrec = fLitR <$> readPrec {- $constraintsynonyms #constraintsynonyms# Writing polymorphic functions over fixed point numbers can be a potentially
src/CLaSH/Sized/Internal/BitVector.hs view
@@ -5,6 +5,7 @@ -} {-# LANGUAGE DataKinds #-}+{-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE KindSignatures #-} {-# LANGUAGE MagicHash #-}@@ -94,6 +95,7 @@ import Control.Lens (Index, Ixed (..), IxValue) import Data.Bits (Bits (..), FiniteBits (..)) import Data.Char (digitToInt)+import Data.Data (Data) import Data.Default (Default (..)) import Data.Maybe (listToMaybe) import GHC.Integer (smallInteger)@@ -130,6 +132,7 @@ -- | The constructor, 'BV', and the field, 'unsafeToInteger', are not -- synthesisable. BV { unsafeToInteger :: Integer}+ deriving Data -- | 'Bit': a 'BitVector' of length 1 type Bit = BitVector 1
src/CLaSH/Sized/Internal/Index.hs view
@@ -5,6 +5,7 @@ -} {-# LANGUAGE DataKinds #-}+{-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE KindSignatures #-} {-# LANGUAGE MagicHash #-} {-# LANGUAGE MultiParamTypeClasses #-}@@ -57,7 +58,9 @@ ) where +import Data.Data (Data) import Data.Default (Default (..))+import Text.Read (Read (..), ReadPrec) import Language.Haskell.TH (TypeQ, appT, conT, litT, numTyLit, sigE) import Language.Haskell.TH.Syntax (Lift(..)) import GHC.TypeLits (KnownNat, Nat, type (+), type (-), type (*),@@ -80,6 +83,8 @@ -- 7 -- >>> minBound :: Index 8 -- 0+-- >>> read (show (maxBound :: Index 8)) :: Index 8+-- 7 -- >>> 1 + 2 :: Index 8 -- 3 -- >>> 2 + 6 :: Index 8@@ -94,6 +99,7 @@ -- | The constructor, 'I', and the field, 'unsafeToInteger', are not -- synthesisable. I { unsafeToInteger :: Integer }+ deriving Data instance KnownNat n => BitPack (Index n) where type BitSize (Index n) = CLog 2 n@@ -264,6 +270,10 @@ instance Show (Index n) where show (I n) = show n++-- | None of the 'Read' class' methods are synthesisable.+instance KnownNat n => Read (Index n) where+ readPrec = fromIntegral <$> (readPrec :: ReadPrec Word) instance KnownNat n => Default (Index n) where def = fromInteger# 0
src/CLaSH/Sized/Internal/Signed.hs view
@@ -5,6 +5,7 @@ -} {-# LANGUAGE DataKinds #-}+{-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE KindSignatures #-} {-# LANGUAGE MagicHash #-}@@ -80,7 +81,9 @@ import Control.Lens (Index, Ixed (..), IxValue) import Data.Bits (Bits (..), FiniteBits (..))+import Data.Data (Data) import Data.Default (Default (..))+import Text.Read (Read (..), ReadPrec) import GHC.TypeLits (KnownNat, Nat, type (+), natVal) import Language.Haskell.TH (TypeQ, appT, conT, litT, numTyLit, sigE) import Language.Haskell.TH.Syntax (Lift(..))@@ -111,6 +114,8 @@ -- 3 -- >>> minBound :: Signed 3 -- -4+-- >>> read (show (minBound :: Signed 3)) :: Signed 3+-- -4 -- >>> 1 + 2 :: Signed 3 -- 3 -- >>> 2 + 3 :: Signed 3@@ -135,6 +140,7 @@ -- | The constructor, 'S', and the field, 'unsafeToInteger', are not -- synthesisable. S { unsafeToInteger :: Integer}+ deriving Data {-# NOINLINE size# #-} size# :: KnownNat n => Signed n -> Int@@ -142,6 +148,10 @@ instance Show (Signed n) where show (S n) = show n++-- | None of the 'Read' class' methods are synthesisable.+instance KnownNat n => Read (Signed n) where+ readPrec = fromIntegral <$> (readPrec :: ReadPrec Int) instance KnownNat n => BitPack (Signed n) where type BitSize (Signed n) = n
src/CLaSH/Sized/Internal/Unsigned.hs view
@@ -5,6 +5,7 @@ -} {-# LANGUAGE DataKinds #-}+{-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE MagicHash #-} {-# LANGUAGE MultiParamTypeClasses #-}@@ -73,7 +74,9 @@ import Control.Lens (Index, Ixed (..), IxValue) import Data.Bits (Bits (..), FiniteBits (..))+import Data.Data (Data) import Data.Default (Default (..))+import Text.Read (Read (..), ReadPrec) import GHC.TypeLits (KnownNat, Nat, type (+), natVal) import Language.Haskell.TH (TypeQ, appT, conT, litT, numTyLit, sigE) import Language.Haskell.TH.Syntax (Lift(..))@@ -102,6 +105,8 @@ -- 7 -- >>> minBound :: Unsigned 3 -- 0+-- >>> read (show (maxBound :: Unsigned 3)) :: Unsigned 3+-- 7 -- >>> 1 + 2 :: Unsigned 3 -- 3 -- >>> 2 + 6 :: Unsigned 3@@ -124,6 +129,7 @@ -- | The constructor, 'U', and the field, 'unsafeToInteger', are not -- synthesisable. U { unsafeToInteger :: Integer }+ deriving Data {-# NOINLINE size# #-} size# :: KnownNat n => Unsigned n -> Int@@ -131,6 +137,10 @@ instance Show (Unsigned n) where show (U i) = show i++-- | None of the 'Read' class' methods are synthesisable.+instance KnownNat n => Read (Unsigned n) where+ readPrec = fromIntegral <$> (readPrec :: ReadPrec Word) instance BitPack (Unsigned n) where type BitSize (Unsigned n) = n
src/CLaSH/Tutorial.hs view
@@ -188,24 +188,25 @@ {- $installation The CλaSH compiler and Prelude library for circuit design only work with the-<http://haskell.org/ghc GHC> Haskell compiler version 7.10.* and up.+<http://haskell.org/ghc GHC> Haskell compiler version 7.10 (higher or lower+versions of GHC are not supported). - (1) Install __GHC (version 7.10.* or higher)__+ (1) Install __GHC 7.10__ - * Download and install <http://www.haskell.org/ghc/download GHC for your platform>.+ * Download and install <https://www.haskell.org/ghc/download_ghc_7_10_3 GHC for your platform>. Unix user can use @./configure prefix=\<LOCATION\>@ to set the installation location. * Make sure that the @bin@ directory of __GHC__ is in your @PATH@. - The following are alternative options, if you cannot find what you are looking for on <http://www.haskell.org/ghc/download>+ Next follows a list of alternative installation instructions, in case you cannot find what you are looking for on <https://www.haskell.org/ghc/download_ghc_7_10_3> * Ubuntu: * Run: @sudo add-apt-repository -y ppa:hvr/ghc@ * Run: @sudo apt-get update@- * Run: @sudo apt-get install cabal-install-1.22 ghc-7.10.3 libtinfo-dev@- * Update your @PATH@ with: @\/opt\/ghc\/7.10.3\/bin@, @\/opt\/cabal\/1.22/bin@, and @\$HOME\/.cabal\/bin@+ * Run: @sudo apt-get install cabal-install-1.24 ghc-7.10.3 libtinfo-dev@+ * Update your @PATH@ with: @\/opt\/ghc\/7.10.3\/bin@, @\/opt\/cabal\/1.24/bin@, and @\$HOME\/.cabal\/bin@ * Run: @cabal update@ * Skip step 2. @@ -217,11 +218,11 @@ * Windows: - * Follow the instructions on: <https://github.com/fpco/minghc MinGHC>+ * Follow the instructions on: <https://github.com/fpco/minghc#using-the-legacy-installer MinGHC> * Run: @cabal update@ * Skip step 2. - (2) Install __Cabal (version 1.22.* or higher)__+ (2) Install __Cabal (version 1.24 or higher)__ * Binary, when available: