{-# LANGUAGE TemplateHaskell, ScopedTypeVariables, RelaxedPolyRec,
PatternGuards #-}
module ForSyDe.Deep.Process.SynchProc (
constSY, mapSY, zipWithSY, zipWith3SY,
zipWith4SY, zipWith5SY, zipWith6SY, zipWithxSY,
delaySY, delaynSY,
scanlSY, scanl2SY, scanl3SY, scanl4SY,
scanldSY, scanld2SY, scanld3SY, scanld4SY,
mooreSY, moore2SY, moore3SY, moore4SY,
mealySY, mealy2SY, mealy3SY, mealy4SY,
sourceSY, filterSY, fillSY, holdSY,
whenSY, zipSY, zip3SY, zip4SY, zip5SY, zip6SY,
unzipSY, unzip3SY, unzip4SY, unzip5SY, unzip6SY,
zipxSY, unzipxSY, mapxSY,
fstSY, sndSY, groupSY) where
import ForSyDe.Deep.Ids
import ForSyDe.Deep.Process.ProcType
import ForSyDe.Deep.Process.ProcType.Instances()
import ForSyDe.Deep.Process.ProcFun
import ForSyDe.Deep.Process.ProcVal
import ForSyDe.Deep.OSharing
import ForSyDe.Deep.Netlist
import ForSyDe.Deep.AbsentExt
import qualified Data.Param.FSVec as V
import Data.Param.FSVec hiding ((++), map)
import Data.TypeLevel (Nat, toInt)
import Data.Typeable.FSDTypeRepLib
import Data.Set (union)
import Data.Maybe
import Data.Dynamic
constSY :: ProcType a =>
ProcId
-> a
-> Signal a
constSY id v = Signal (newNodeOutSig nodeRef ConstOut)
where nodeRef = newURef $ Proc id $ Const (mkProcVal v)
mapSY :: forall a b . (ProcType a, ProcType b) =>
ProcId
-> ProcFun (a -> b)
-> Signal a
-> Signal b
mapSY id f s = Signal (newNodeOutSig nodeRef ZipWithNSYOut)
where nodeRef = newURef $ Proc id $ ZipWithNSY dynPF [unSignal s]
dynPF = procFun2Dyn (getEnums (undefined ::a) `union`
getEnums (undefined ::b))
f
zipWithSY :: forall a b c . (ProcType a, ProcType b, ProcType c) =>
ProcId
-> ProcFun (a -> b -> c)
-> Signal a
-> Signal b
-> Signal c
zipWithSY id f s1 s2 = Signal (newNodeOutSig nodeRef ZipWithNSYOut)
where nodeRef = newURef $ Proc id $
ZipWithNSY dynPF [unSignal s1,unSignal s2]
dynPF = procFun2Dyn (getEnums (undefined ::a) `union`
getEnums (undefined ::b) `union`
getEnums (undefined ::c) )
f
zipWith3SY :: forall a b c d.
(ProcType a, ProcType b, ProcType c, ProcType d) =>
ProcId
-> ProcFun (a -> b -> c -> d)
-> Signal a
-> Signal b
-> Signal c
-> Signal d
zipWith3SY id f s1 s2 s3 = Signal (newNodeOutSig nodeRef ZipWithNSYOut)
where nodeRef = newURef $ Proc id $
ZipWithNSY dynPF
[unSignal s1,
unSignal s2,
unSignal s3]
dynPF = procFun2Dyn (getEnums (undefined ::a) `union`
getEnums (undefined ::b) `union`
getEnums (undefined ::c) `union`
getEnums (undefined ::d))
f
zipWith4SY ::forall a b c d e.
(ProcType a, ProcType b, ProcType c, ProcType d, ProcType e) =>
ProcId
-> ProcFun (a -> b -> c -> d -> e)
-> Signal a
-> Signal b
-> Signal c
-> Signal d
-> Signal e
zipWith4SY id f s1 s2 s3 s4 = Signal (newNodeOutSig nodeRef ZipWithNSYOut)
where nodeRef = newURef $ Proc id $
ZipWithNSY dynPF
[unSignal s1,
unSignal s2,
unSignal s3,
unSignal s4]
dynPF = procFun2Dyn (getEnums (undefined ::a) `union`
getEnums (undefined ::b) `union`
getEnums (undefined ::c) `union`
getEnums (undefined ::d) `union`
getEnums (undefined ::e) )
f
zipWith5SY :: forall a b c d e f.
(ProcType a, ProcType b, ProcType c, ProcType d, ProcType e,
ProcType f) =>
ProcId
-> ProcFun (a -> b -> c -> d -> e -> f)
-> Signal a
-> Signal b
-> Signal c
-> Signal d
-> Signal e
-> Signal f
zipWith5SY id f s1 s2 s3 s4 s5 = Signal (newNodeOutSig nodeRef ZipWithNSYOut)
where nodeRef = newURef $ Proc id $
ZipWithNSY dynPF
[unSignal s1,
unSignal s2,
unSignal s3,
unSignal s4,
unSignal s5]
dynPF = procFun2Dyn (getEnums (undefined ::a) `union`
getEnums (undefined ::b) `union`
getEnums (undefined ::c) `union`
getEnums (undefined ::d) `union`
getEnums (undefined ::e) `union`
getEnums (undefined ::f) )
f
zipWith6SY :: forall a b c d e f g.
(ProcType a, ProcType b, ProcType c, ProcType d, ProcType e,
ProcType f, ProcType g) =>
ProcId
-> ProcFun (a -> b -> c -> d -> e -> f -> g)
-> Signal a
-> Signal b
-> Signal c
-> Signal d
-> Signal e
-> Signal f
-> Signal g
zipWith6SY id f s1 s2 s3 s4 s5 s6 = Signal (newNodeOutSig nodeRef ZipWithNSYOut)
where nodeRef = newURef $ Proc id $
ZipWithNSY dynPF
[unSignal s1,
unSignal s2,
unSignal s3,
unSignal s4,
unSignal s5,
unSignal s6]
dynPF = procFun2Dyn (getEnums (undefined ::a) `union`
getEnums (undefined ::b) `union`
getEnums (undefined ::c) `union`
getEnums (undefined ::d) `union`
getEnums (undefined ::e) `union`
getEnums (undefined ::f) `union`
getEnums (undefined ::g) )
f
mapxSY :: (Nat s, ProcType a, ProcType b) =>
ProcId
-> ProcFun (a -> b)
-> FSVec s (Signal a)
-> FSVec s (Signal b)
mapxSY id f = V.zipWith (\n s -> mapSY (id ++ show n) f s)
(V.reallyUnsafeVector [(1::Int)..])
zipWithxSY :: forall s a b .
(Nat s, Typeable s, ProcType a, ProcType b) =>
ProcId
-> ProcFun (FSVec s a -> b)
-> FSVec s (Signal a)
-> Signal b
zipWithxSY id f sv = Signal (newNodeOutSig nodeRef ZipWithxSYOut)
where nodeRef = newURef $ Proc id $
ZipWithxSY (vecProcFun2List dynPF)
(map unSignal (V.fromVector sv))
vecProcFun2List :: TypedProcFun (FSVec s' a' -> b') ->
TypedProcFun ([a'] -> b')
vecProcFun2List f = f{tval = \x -> (tval f) (reallyUnsafeVector x)}
dynPF = contProcFun2Dyn (getEnums (undefined ::a) `union`
getEnums (undefined ::b) )
f
delaySY :: ProcType a =>
ProcId
-> a
-> Signal a
-> Signal a
delaySY id v s = Signal (newNodeOutSig nodeRef DelaySYOut)
where procVal = mkProcVal v
nodeRef = newURef $ Proc id $ DelaySY procVal (unSignal s)
delaynSY :: ProcType a =>
ProcId
-> a
-> Int
-> Signal a
-> Signal a
delaynSY id e n s = (\(a,_,_) -> a) $ delaynSYacum (s, 1, n)
where
delaynSYacum acum@(lastSig, curr, max)
| curr > max = acum
| otherwise =
delaynSYacum (delaySY (id ++ "_" ++ show curr) e lastSig, curr+1, max)
scanlSY :: (ProcType a, ProcType b) =>
ProcId
-> ProcFun (a -> b -> a)
-> a
-> Signal b
-> Signal a
scanlSY id f mem s = s'
where s' = zipWithSY (id ++ "_NxtSt") f
(delaySY (id ++ "_Delay") mem s') s
scanl2SY :: (ProcType a, ProcType b, ProcType c) =>
ProcId
-> ProcFun (a -> b -> c -> a)
-> a
-> Signal b
-> Signal c
-> Signal a
scanl2SY id f mem s1 s2 = s'
where s' = zipWith3SY (id ++ "_NxtSt") f
(delaySY (id ++ "_Delay") mem s') s1 s2
scanl3SY :: (ProcType a, ProcType b, ProcType c, ProcType d) =>
ProcId
-> ProcFun (a -> b -> c -> d -> a)
-> a
-> Signal b
-> Signal c
-> Signal d
-> Signal a
scanl3SY id f mem s1 s2 s3 = s'
where s' = zipWith4SY (id ++ "_NxtSt") f
(delaySY (id ++ "_Delay") mem s') s1 s2 s3
scanl4SY :: (ProcType a, ProcType b, ProcType c, ProcType d, ProcType e) =>
ProcId
-> ProcFun (a -> b -> c -> d -> e -> a)
-> a
-> Signal b
-> Signal c
-> Signal d
-> Signal e
-> Signal a
scanl4SY id f mem s1 s2 s3 s4 = s'
where s' = zipWith5SY (id ++ "_NxtSt") f
(delaySY (id ++ "_Delay") mem s') s1 s2 s3 s4
scanldSY :: (ProcType a, ProcType b) =>
ProcId
-> ProcFun (a -> b -> a)
-> a
-> Signal b
-> Signal a
scanldSY id f mem s = s'
where s' = delaySY (id ++ "_Delay") mem $
zipWithSY (id ++ "_NxtSt") f s' s
scanld2SY :: (ProcType a, ProcType b, ProcType c) =>
ProcId
-> ProcFun (a -> b -> c -> a)
-> a
-> Signal b
-> Signal c
-> Signal a
scanld2SY id f mem s1 s2 = s'
where s' = delaySY (id ++ "_Delay") mem $
zipWith3SY (id ++ "_NxtSt") f s' s1 s2
scanld3SY :: (ProcType a, ProcType b, ProcType c, ProcType d) =>
ProcId
-> ProcFun (a -> b -> c -> d -> a)
-> a
-> Signal b
-> Signal c
-> Signal d
-> Signal a
scanld3SY id f mem s1 s2 s3 = s'
where s' = delaySY (id ++ "_Delay") mem $
zipWith4SY (id ++ "_NxtSt") f s' s1 s2 s3
scanld4SY :: (ProcType a, ProcType b, ProcType c, ProcType d, ProcType e) =>
ProcId
-> ProcFun (a -> b -> c -> d -> e -> a)
-> a
-> Signal b
-> Signal c
-> Signal d
-> Signal e
-> Signal a
scanld4SY id f mem s1 s2 s3 s4 = s'
where s' = delaySY (id ++ "_Delay") mem $
zipWith5SY (id ++ "_NxtSt") f s' s1 s2 s3 s4
mooreSY :: (ProcType a, ProcType b, ProcType c) =>
ProcId
-> ProcFun (a -> b -> a)
-> ProcFun (a -> c)
-> a
-> Signal b
-> Signal c
mooreSY id nextState output initial =
mapSY (id ++ "_OutDec") output .scanldSY id nextState initial
moore2SY :: (ProcType a, ProcType b, ProcType c, ProcType d) =>
ProcId
-> ProcFun (a -> b -> c -> a)
-> ProcFun (a -> d)
-> a
-> Signal b
-> Signal c
-> Signal d
moore2SY id nextState output initial i1 i2 =
mapSY (id ++ "_OutDec") output $ scanld2SY id nextState initial i1 i2
moore3SY :: (ProcType a, ProcType b, ProcType c, ProcType d, ProcType e) =>
ProcId
-> ProcFun (a -> b -> c -> d -> a)
-> ProcFun (a -> e)
-> a
-> Signal b
-> Signal c
-> Signal d
-> Signal e
moore3SY id nextState output initial i1 i2 i3 =
mapSY (id ++ "_OutDec") output $ scanld3SY id nextState initial i1 i2 i3
moore4SY :: (ProcType a, ProcType b, ProcType c, ProcType d, ProcType e, ProcType f) =>
ProcId
-> ProcFun (a -> b -> c -> d -> e -> a)
-> ProcFun (a -> f)
-> a
-> Signal b
-> Signal c
-> Signal d
-> Signal e
-> Signal f
moore4SY id nextState output initial i1 i2 i3 i4 =
mapSY (id ++ "_OutDec") output $ scanld4SY id nextState initial i1 i2 i3 i4
mealySY :: (ProcType a, ProcType b, ProcType c) =>
ProcId
-> ProcFun (a -> b -> a)
-> ProcFun (a -> b -> c)
-> a
-> Signal b
-> Signal c
mealySY id nextState output initial i =
zipWithSY (id ++ "_OutDec") output state i
where state = scanldSY id nextState initial i
mealy2SY :: (ProcType a, ProcType b, ProcType c, ProcType d) =>
ProcId
-> ProcFun (a -> b -> c -> a)
-> ProcFun (a -> b -> c -> d)
-> a
-> Signal b
-> Signal c
-> Signal d
mealy2SY id nextState output initial i1 i2 =
zipWith3SY (id ++ "_OutDec") output state i1 i2
where state = scanld2SY id nextState initial i1 i2
mealy3SY :: (ProcType a, ProcType b, ProcType c, ProcType d,
ProcType e) =>
ProcId
-> ProcFun (a -> b -> c -> d -> a)
-> ProcFun (a -> b -> c -> d -> e)
-> a
-> Signal b
-> Signal c
-> Signal d
-> Signal e
mealy3SY id nextState output initial i1 i2 i3 =
zipWith4SY (id ++ "_OutDec") output state i1 i2 i3
where state = scanld3SY id nextState initial i1 i2 i3
mealy4SY :: (ProcType a, ProcType b, ProcType c, ProcType d,
ProcType e, ProcType f) =>
ProcId
-> ProcFun (a -> b -> c -> d -> e -> a)
-> ProcFun (a -> b -> c -> d -> e -> f)
-> a
-> Signal b
-> Signal c
-> Signal d
-> Signal e
-> Signal f
mealy4SY id nextState output initial i1 i2 i3 i4 =
zipWith5SY (id ++ "_OutDec") output state i1 i2 i3 i4
where state = scanld4SY id nextState initial i1 i2 i3 i4
filterSY :: ProcType a =>
ProcId
-> ProcFun (a -> Bool)
-> Signal a
-> Signal (AbstExt a)
filterSY id pred = mapSY id (filterer `defArgPF` pred)
where filterer =
$(newProcFun [d| filterer :: (a -> Bool) -> a -> AbstExt a
filterer pred val =
if pred val then Prst val
else Abst |])
sourceSY :: ProcType a =>
ProcId
-> ProcFun (a -> a)
-> a
-> Signal a
sourceSY id f s0 = o
where o = delaySY (id ++ "_Delay") s0 s
s = mapSY (id ++ "_Nxt") f o
fillSY :: ProcType a =>
ProcId
-> a
-> Signal (AbstExt a)
-> Signal a
fillSY id v s = mapSY id (replaceAbst `defArgVal` v) s
where replaceAbst :: ProcFun (a -> AbstExt a -> a)
replaceAbst = $(newProcFun
[d| replaceAbst :: a -> AbstExt a -> a
replaceAbst x y = fromAbstExt x y |])
holdSY :: ProcType a =>
ProcId
-> a
-> Signal (AbstExt a)
-> Signal a
holdSY id a s = scanlSY id hold a s
where hold = $(newProcFun [d| hold :: a -> AbstExt a -> a
hold a abs = fromAbstExt a abs |])
whenSY :: (ProcType a, ProcType b) =>
ProcId
-> Signal (AbstExt a) -> Signal (AbstExt b) -> Signal (AbstExt a)
whenSY id = zipWithSY id whenF
where whenF = $(newProcFun [d| whenF :: AbstExt a -> AbstExt b -> AbstExt a
whenF v1 v2 = if isAbsent v2
then Abst
else v1 |])
zipSY :: (ProcType a, ProcType b) =>
ProcId
-> Signal a
-> Signal b
-> Signal (a,b)
zipSY id = zipWithSY id tup2
where tup2 :: ProcFun (a -> b -> (a,b))
tup2 = $(newProcFun [d| tup2 :: a -> b -> (a,b)
tup2 a b = (a,b) |])
zip3SY :: (ProcType a, ProcType b, ProcType c) =>
ProcId ->
Signal a ->
Signal b ->
Signal c ->
Signal (a,b,c)
zip3SY id = zipWith3SY id tup3
where tup3 :: ProcFun (a -> b -> c -> (a,b,c))
tup3 = $(newProcFun [d| tup3 :: a -> b -> c -> (a,b,c)
tup3 a b c = (a,b,c) |])
zip4SY :: (ProcType a, ProcType b, ProcType c, ProcType d) =>
ProcId ->
Signal a ->
Signal b ->
Signal c ->
Signal d ->
Signal (a,b,c,d)
zip4SY id = zipWith4SY id tup4
where tup4 :: ProcFun (a -> b -> c -> d -> (a,b,c,d))
tup4 = $(newProcFun [d| tup4 :: a -> b -> c -> d -> (a,b,c,d)
tup4 a b c d = (a,b,c,d) |])
zip5SY :: (ProcType a, ProcType b, ProcType c, ProcType d, ProcType e) =>
ProcId ->
Signal a ->
Signal b ->
Signal c ->
Signal d ->
Signal e ->
Signal (a,b,c,d,e)
zip5SY id = zipWith5SY id tup5
where tup5 :: ProcFun (a -> b -> c -> d -> e -> (a,b,c,d,e))
tup5 = $(newProcFun [d| tup5 :: a -> b -> c -> d -> e -> (a,b,c,d,e)
tup5 a b c d e = (a,b,c,d,e) |])
zip6SY :: (ProcType a, ProcType b, ProcType c, ProcType d, ProcType e,
ProcType f) =>
ProcId ->
Signal a ->
Signal b ->
Signal c ->
Signal d ->
Signal e ->
Signal f ->
Signal (a,b,c,d,e,f)
zip6SY id = zipWith6SY id tup6
where tup6 :: ProcFun (a -> b -> c -> d -> e -> f -> (a,b,c,d,e,f))
tup6 = $(newProcFun [d| tup6 :: a -> b -> c -> d -> e -> f ->
(a,b,c,d,e,f)
tup6 a b c d e f = (a,b,c,d,e,f) |])
unzipSY :: forall a b . (ProcType a, ProcType b) =>
ProcId
-> Signal (a,b)
-> (Signal a,Signal b)
unzipSY id s = (Signal (newNodeOutSig nodeRef (UnzipNSYOut 1)),
Signal (newNodeOutSig nodeRef (UnzipNSYOut 2)))
where ts = [fsdTypeOf (undefined :: a), fsdTypeOf (undefined :: b)]
nodeRef = newURef $ Proc id $
UnzipNSY ts untup (unSignal s)
untup :: Dynamic -> [Dynamic]
untup i = let (t1,t2) = ((fromJust.fromDynamic) i) :: (a,b)
in [toDyn t1, toDyn t2]
unzip3SY :: forall a b c . (ProcType a, ProcType b, ProcType c) =>
ProcId
-> Signal (a,b,c)
-> (Signal a, Signal b, Signal c)
unzip3SY id s = (Signal (newNodeOutSig nodeRef (UnzipNSYOut 1)),
Signal (newNodeOutSig nodeRef (UnzipNSYOut 2)),
Signal (newNodeOutSig nodeRef (UnzipNSYOut 3)))
where ts = [fsdTypeOf (undefined :: a), fsdTypeOf (undefined :: b),
fsdTypeOf (undefined :: c)]
nodeRef = newURef $ Proc id $
UnzipNSY ts untup3 (unSignal s)
untup3 :: Dynamic -> [Dynamic]
untup3 i = let (t1,t2,t3) = ((fromJust.fromDynamic) i) :: (a,b,c)
in [toDyn t1, toDyn t2, toDyn t3]
unzip4SY :: forall a b c d . (ProcType a, ProcType b, ProcType c,
ProcType d) =>
ProcId
-> Signal (a,b,c,d)
-> (Signal a, Signal b, Signal c, Signal d)
unzip4SY id s = (Signal (newNodeOutSig nodeRef (UnzipNSYOut 1)),
Signal (newNodeOutSig nodeRef (UnzipNSYOut 2)),
Signal (newNodeOutSig nodeRef (UnzipNSYOut 3)),
Signal (newNodeOutSig nodeRef (UnzipNSYOut 4)))
where ts = [fsdTypeOf (undefined :: a), fsdTypeOf (undefined :: b),
fsdTypeOf (undefined :: c), fsdTypeOf (undefined :: d)]
nodeRef = newURef $ Proc id $
UnzipNSY ts untup4 (unSignal s)
untup4 :: Dynamic -> [Dynamic]
untup4 i = let (t1,t2,t3,t4) = ((fromJust.fromDynamic) i) :: (a,b,c,d)
in [toDyn t1, toDyn t2, toDyn t3, toDyn t4]
unzip5SY :: forall a b c d e . (ProcType a, ProcType b, ProcType c,
ProcType d, ProcType e) =>
ProcId
-> Signal (a,b,c,d,e)
-> (Signal a, Signal b, Signal c, Signal d, Signal e)
unzip5SY id s = (Signal (newNodeOutSig nodeRef (UnzipNSYOut 1)),
Signal (newNodeOutSig nodeRef (UnzipNSYOut 2)),
Signal (newNodeOutSig nodeRef (UnzipNSYOut 3)),
Signal (newNodeOutSig nodeRef (UnzipNSYOut 4)),
Signal (newNodeOutSig nodeRef (UnzipNSYOut 5)))
where ts = [fsdTypeOf (undefined :: a), fsdTypeOf (undefined :: b),
fsdTypeOf (undefined :: c), fsdTypeOf (undefined :: d),
fsdTypeOf (undefined :: e)]
nodeRef = newURef $ Proc id $
UnzipNSY ts untup5 (unSignal s)
untup5 :: Dynamic -> [Dynamic]
untup5 i = let (t1,t2,t3,t4,t5)
= ((fromJust.fromDynamic) i) :: (a,b,c,d,e)
in [toDyn t1, toDyn t2, toDyn t3, toDyn t4, toDyn t5]
unzip6SY :: forall a b c d e f . (ProcType a, ProcType b, ProcType c,
ProcType d, ProcType e, ProcType f) =>
ProcId
-> Signal (a,b,c,d,e,f)
-> (Signal a, Signal b, Signal c, Signal d, Signal e, Signal f)
unzip6SY id s = (Signal (newNodeOutSig nodeRef (UnzipNSYOut 1)),
Signal (newNodeOutSig nodeRef (UnzipNSYOut 2)),
Signal (newNodeOutSig nodeRef (UnzipNSYOut 3)),
Signal (newNodeOutSig nodeRef (UnzipNSYOut 4)),
Signal (newNodeOutSig nodeRef (UnzipNSYOut 5)),
Signal (newNodeOutSig nodeRef (UnzipNSYOut 6)))
where ts = [fsdTypeOf (undefined :: a), fsdTypeOf (undefined :: b),
fsdTypeOf (undefined :: c), fsdTypeOf (undefined :: d),
fsdTypeOf (undefined :: e), fsdTypeOf (undefined :: f)]
nodeRef = newURef $ Proc id $
UnzipNSY ts untup6 (unSignal s)
untup6 :: Dynamic -> [Dynamic]
untup6 i = let (t1,t2,t3,t4,t5,t6)
= ((fromJust.fromDynamic) i) :: (a,b,c,d,e,f)
in [toDyn t1, toDyn t2, toDyn t3, toDyn t4, toDyn t5,
toDyn t6]
zipxSY :: (Nat s, Typeable s, ProcType a) =>
ProcId
-> FSVec s (Signal a)
-> Signal (FSVec s a)
zipxSY id = zipWithxSY id vectId
where vectId = $(newProcFun [d| vectId :: FSVec s a -> FSVec s a
vectId v = v |])
unzipxSY :: forall s a . (Typeable s, Nat s, ProcType a) =>
ProcId
-> Signal (FSVec s a)
-> FSVec s (Signal a)
unzipxSY id vs = V.map (\tag -> Signal (newNodeOutSig nodeRef tag) )
(reallyUnsafeVector [UnzipxSYOut i | i <- [1..n]])
where n = toInt (undefined :: s)
t = fsdTypeOf (undefined :: a)
nodeRef = newURef $ Proc id $
UnzipxSY t n unvector (unSignal vs)
unvector :: Dynamic -> [Dynamic]
unvector i = let v = ((fromJust.fromDynamic) i) :: FSVec s a
in map toDyn (V.fromVector v)
fstSY :: (ProcType a, ProcType b) => ProcId -> Signal (a,b) -> Signal a
fstSY id = mapSY id first
where first = $(newProcFun [d| first :: (a,b) -> a
first (a,_) = a |])
sndSY :: (ProcType a, ProcType b) => ProcId -> Signal (a,b) -> Signal b
sndSY id = mapSY id second
where second = $(newProcFun [d| second :: (a,b) -> b
second (_,b) = b |])
groupSY :: forall k a . (Nat k, Typeable k, ProcType a) =>
ProcId -> k -> Signal a -> Signal (AbstExt (FSVec k a))
groupSY id k = mooreSY id (f `defArgVal` kV) (g `defArgVal` kV) s0
where
kV = toInt k
s0 = (0, V.copy k (undefined :: a))
f = $(newProcFun [d| f :: Nat k' => Int -> (Int, FSVec k' a') -> a' ->
(Int, FSVec k' a')
f k (count,v) a =
(count+1 `mod` k, unsafeReplace v count a) |])
g = $(newProcFun [d| g :: Nat k' => Int -> (Int, FSVec k' a') -> AbstExt (FSVec k' a')
g k (count,v) = if k-1 == count then Prst v else Abst |])
unsafeReplace :: Nat s => FSVec s a' -> Int -> a' ->FSVec s a'
unsafeReplace v i a =
reallyUnsafeVector $ unsafeReplace' (fromVector v) i a
where unsafeReplace' [] _ _ = []
unsafeReplace' (_:xs) 0 y = (y:xs)
unsafeReplace' (x:xs) n y = x : (unsafeReplace' xs (n - 1) y)