Skip to content

Commit

Permalink
Added TryDomain instances to Clash sized types (#2090) (#2092)
Browse files Browse the repository at this point in the history
(cherry picked from commit c51d0b9)

Co-authored-by: Rowan Goemans <goemansrowan@gmail.com>
  • Loading branch information
mergify[bot] and rowanG077 authored Feb 11, 2022
1 parent f4851d5 commit 63db66d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
1 change: 1 addition & 0 deletions changelog/2022-02-10T18_32_06+01_00_TryDomain_sized_types
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ADDED: Added `Clash.Class.HasDomain.TryDomain` instances to Clash sized types
27 changes: 18 additions & 9 deletions clash-prelude/src/Clash/Class/HasDomain/HasSingleDomain.hs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{-|
Copyright : (C) 2019, Myrtle Software Ltd
2022, QBayLogic B.V.
License : BSD2 (see the file LICENSE)
Maintainer : Christiaan Baaij <christiaan.baaij@gmail.com>
Maintainer : QBayLogic B.V. <devops@qbaylogic.com>
Internals for "Clash.Class.HasDomain"
-}
Expand All @@ -24,12 +25,21 @@ import Clash.Class.HasDomain.CodeGen (mkTryDomainTuples)

import Clash.Sized.Vector (Vec)
import Clash.Sized.RTree (RTree)
import Clash.Sized.Index (Index)
import Clash.Sized.Unsigned (Unsigned)
import Clash.Sized.Signed (Signed)
import Clash.Sized.BitVector (BitVector, Bit)
import Clash.Sized.Fixed (Fixed)

import Clash.Signal.Internal
(Signal, Domain, Clock, Reset, Enable)
import Clash.Signal.Delayed.Internal (DSignal)

import Numeric.Natural (Natural)

import Data.Kind (Type)
import Data.Proxy (Proxy)
import GHC.TypeLits (type (+))
import Type.Errors
(DelayError, TypeError, IfStuck, Pure)

Expand Down Expand Up @@ -144,26 +154,25 @@ type instance TryDomain t (Enable dom) = 'Found dom
type instance TryDomain t (Proxy dom) = 'Found dom
type instance TryDomain t (Vec n a) = TryDomain t a
type instance TryDomain t (RTree d a) = TryDomain t a
type instance TryDomain t (Index n) = 'NotFound
type instance TryDomain t (Unsigned n) = 'NotFound
type instance TryDomain t (Signed n) = 'NotFound
type instance TryDomain t (BitVector n) = 'NotFound
type instance TryDomain t Bit = 'NotFound
type instance TryDomain t (Fixed a n m) = TryDomain t (a (n + m))
type instance TryDomain t (a -> b) = Merge t a b
type instance TryDomain t (a, b) = Merge t a b

type instance TryDomain t () = 'NotFound
type instance TryDomain t Bool = 'NotFound
type instance TryDomain t Integer = 'NotFound
type instance TryDomain t Natural = 'NotFound
type instance TryDomain t Int = 'NotFound
type instance TryDomain t Float = 'NotFound
type instance TryDomain t Double = 'NotFound
type instance TryDomain t (Maybe a) = TryDomain t a
type instance TryDomain t (Either a b) = Merge t a b

-- TODO: Add more instances, including:
--type instance TryDomain t Bit = 'NotFound
--type instance TryDomain t (BitVector n) = 'NotFound
--type instance TryDomain t (Index n) = 'NotFound
--type instance TryDomain t (Fixed rep int frac) = 'NotFound
--type instance TryDomain t (Signed n) = 'NotFound
--type instance TryDomain t (Unsigned n) = 'NotFound

-- | Type family that searches a type and checks whether all subtypes that can
-- contain a domain (for example, Signal) contain the /same/ domain. Its
-- associated type, GetDomain, will yield a type error if that doesn't hold OR
Expand Down

0 comments on commit 63db66d

Please sign in to comment.