Skip to content

Commit 0fe897c

Browse files
Drop Arrows dependency for GHC 8.10
Arrow notation is now picked up as if (-<) was a "normal" operator
1 parent d8f691f commit 0fe897c

File tree

4 files changed

+30
-9
lines changed

4 files changed

+30
-9
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
cabal: ["3.2"]
3030
ghc:
3131
- "8.6.5"
32-
# - "8.10.1"
32+
- "8.10.1"
3333

3434
steps:
3535
- uses: actions/checkout@v2

circuit-notation.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ library
2222
, clash-prelude >= 1.0
2323
, containers
2424
, data-default
25-
, ghc >=8.6 && <8.8
25+
, ghc (>=8.6 && <8.8) || (>=8.10 && < 9.0)
2626
, syb
2727
, lens
2828
, mtl

example/Example.hs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,17 @@
1010
This file contains examples of using the Circuit Notation.
1111
-}
1212

13-
{-# LANGUAGE Arrows #-}
13+
{-# LANGUAGE CPP #-}
1414
{-# LANGUAGE BlockArguments #-}
1515
{-# LANGUAGE DeriveFunctor #-}
1616
{-# LANGUAGE ScopedTypeVariables #-}
1717
{-# LANGUAGE TypeFamilies #-}
1818
{-# LANGUAGE DataKinds #-}
1919

20+
#if __GLASGOW_HASKELL__ < 810
21+
{-# LANGUAGE Arrows #-}
22+
#endif
23+
2024
{-# OPTIONS -fplugin=CircuitNotation #-}
2125
{-# OPTIONS -fplugin-opt=CircuitNotation:debug #-}
2226
{-# OPTIONS -Wall #-}
@@ -37,8 +41,16 @@ import Clash.Prelude (Signal, Vec(..))
3741
idCircuit :: Circuit a a
3842
idCircuit = idC
3943

40-
swapC :: Circuit (a,b) (b,a)
41-
swapC = id $ circuit $ \ ~(a,b) -> ~(b,a)
44+
#if __GLASGOW_HASKELL__ < 810
45+
swapC0 :: Circuit (a,b) (b,a)
46+
swapC0 = id $ circuit $ \ ~(a,b) -> ~(b,a)
47+
#endif
48+
49+
swapC1 :: Circuit (a,b) (b,a)
50+
swapC1 = id $ circuit $ \ ~(a,b) -> (b,a)
51+
52+
swapC2 :: Circuit (a,b) (b,a)
53+
swapC2 = id $ circuit $ \ (a,b) -> (b,a)
4254

4355
circuitA :: Circuit () (DF domain Int)
4456
circuitA = Circuit (\_ -> () :-> pure (DFM2S True 3))

src/CircuitNotation.hs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,12 @@ isDollar = \case
114114
HsVar _ (L _ v) -> v == GHC.mkVarUnqual "$"
115115
_ -> False
116116

117+
-- | Is (-<)?
118+
isFletching :: p ~ GhcPs => HsExpr p -> Bool
119+
isFletching = \case
120+
HsVar _ (L _ v) -> v == GHC.mkVarUnqual "-<"
121+
_ -> False
122+
117123
imap :: (Int -> a -> b) -> [a] -> [b]
118124
imap f = zipWith f [0 ..]
119125

@@ -434,8 +440,10 @@ circuitBody = \case
434440
L _ (HsArrApp _xapp (L _ (HsVar _ (L _ (GHC.Unqual occ)))) arg _ _)
435441
| OccName.occNameString occ == "idC" -> circuitMasters .= bindMaster arg
436442
#else
437-
L _ (HsProc _ _ (L _ (HsCmdTop _ (L _ (HsCmdArrApp _xapp (L _ (HsVar _ (L _ (GHC.Unqual occ)))) arg _ _)))))
438-
| OccName.occNameString occ == "idC" -> circuitMasters .= bindMaster arg
443+
L _ (OpApp _ (L _ (HsVar _ (L _ (GHC.Unqual occ)))) (L _ op) port)
444+
| isFletching op
445+
, OccName.occNameString occ == "idC" -> do
446+
circuitMasters .= bindMaster port
439447
#endif
440448

441449
-- Otherwise create a binding and use that as the master. This is equivalent to changing
@@ -521,6 +529,7 @@ bindMaster (L loc expr) = case expr of
521529
ExprWithTySig ty expr' -> PortType ty (bindMaster expr')
522530
ELazyPat _ expr' -> Lazy loc (bindMaster expr')
523531
#else
532+
-- XXX: Untested?
524533
HsProc _ _ (L _ (HsCmdTop _ (L _ (HsCmdArrApp _xapp (L _ (HsVar _ (L _ (GHC.Unqual occ)))) sig _ _))))
525534
| OccName.occNameString occ == "Signal" -> SignalExpr sig
526535
ExprWithTySig _ expr' ty -> PortType ty (bindMaster expr')
@@ -544,7 +553,7 @@ bodyBinding
544553
-> GenLocated loc (HsExpr p)
545554
-- ^ the statement with an optional @-<@
546555
-> CircuitM ()
547-
bodyBinding mInput lexpr@(L loc expr) =
556+
bodyBinding mInput lexpr@(L loc expr) = do
548557
case expr of
549558
#if __GLASGOW_HASKELL__ < 810
550559
HsArrApp _xhsArrApp circuit port HsFirstOrderApp True ->
@@ -554,7 +563,7 @@ bodyBinding mInput lexpr@(L loc expr) =
554563
, bIn = fromMaybe (Tuple []) mInput
555564
}]
556565
#else
557-
HsProc _ _ (L _ (HsCmdTop _ (L _ (HsCmdArrApp _xhsArrApp circuit port HsFirstOrderApp True)))) ->
566+
OpApp _ circuit (L _ op) port | isFletching op -> do
558567
circuitBinds <>= [Binding
559568
{ bCircuit = circuit
560569
, bOut = bindMaster port

0 commit comments

Comments
 (0)