diff --git a/src/Circuit.hs b/src/Circuit.hs index 0d3024d..7f9de82 100644 --- a/src/Circuit.hs +++ b/src/Circuit.hs @@ -54,10 +54,22 @@ data DF (dom :: Domain) a data DFM2S a = DFM2S Bool a newtype DFS2M = DFS2M Bool -instance Default (DFM2S a) where - def = DFM2S False (error "error default") -instance Default DFS2M where - def = DFS2M True +-- | For /dev/null-like circuits: always acknowledge incoming data +-- while never sending out data. Used for ignoring streams with an underscore prefix. +class DriveVoid a where + driveVoid :: a + +instance DriveVoid () where + driveVoid = () + +instance (DriveVoid a) => DriveVoid (Signal dom a) where + driveVoid = pure driveVoid + +instance DriveVoid (DFM2S a) where + driveVoid = DFM2S False (error "void") + +instance DriveVoid DFS2M where + driveVoid = DFS2M True type instance Fwd (DF dom a) = Signal dom (DFM2S a) type instance Bwd (DF dom a) = Signal dom DFS2M diff --git a/src/CircuitNotation.hs b/src/CircuitNotation.hs index 5e36429..9dc9254 100644 --- a/src/CircuitNotation.hs +++ b/src/CircuitNotation.hs @@ -42,7 +42,6 @@ module CircuitNotation -- base import Control.Exception import qualified Data.Data as Data -import Data.Default import Data.Maybe (fromMaybe) #if __GLASGOW_HASKELL__ >= 900 #else @@ -1173,21 +1172,20 @@ completeUnderscores = do binds <- L.use circuitBinds masters <- L.use circuitMasters slaves <- L.use circuitSlaves - let addDef :: String -> PortDescription PortName -> CircuitM () - addDef suffix = \case + let addVoid :: String -> PortDescription PortName -> CircuitM () + addVoid suffix = \case Ref (PortName loc (unpackFS -> name@('_':_))) -> do - let bind = patBind (varP loc (name <> suffix)) (tagE $ varE loc (thName 'def)) + let bind = patBind (varP loc (name <> suffix)) (tagE $ varE loc (driveVoid ?nms)) circuitLets <>= [L loc bind] _ -> pure () addBind :: Binding exp PortName -> CircuitM () addBind (Binding _ bOut bIn) = do - L.traverseOf_ L.cosmos (addDef "_Fwd") bOut - L.traverseOf_ L.cosmos (addDef "_Bwd") bIn + L.traverseOf_ L.cosmos (addVoid "_Fwd") bOut + L.traverseOf_ L.cosmos (addVoid "_Bwd") bIn mapM_ addBind binds addBind (Binding undefined masters slaves) - -- | Transform declarations in the module by converting circuit blocks. transform :: (?nms :: ExternalNames) @@ -1321,6 +1319,7 @@ data ExternalNames = ExternalNames , fwdBwdCon :: GHC.RdrName , fwdAndBwdTypes :: Direction -> GHC.RdrName , trivialBwd :: GHC.RdrName + , driveVoid :: GHC.RdrName , consPat :: GHC.RdrName } @@ -1335,6 +1334,7 @@ defExternalNames = ExternalNames , fwdAndBwdTypes = \case Fwd -> GHC.Unqual (OccName.mkTcOcc "Fwd") Bwd -> GHC.Unqual (OccName.mkTcOcc "Bwd") + , driveVoid = GHC.Unqual (OccName.mkVarOcc "driveVoid") , trivialBwd = GHC.Unqual (OccName.mkVarOcc "unitBwd") #if __GLASGOW_HASKELL__ > 900 , consPat = GHC.Unqual (OccName.mkDataOcc ":>!")