summaryrefslogtreecommitdiff
path: root/src/AST/Count.hs
diff options
context:
space:
mode:
authorTom Smeding <tom@tomsmeding.com>2024-08-30 17:48:15 +0200
committerTom Smeding <tom@tomsmeding.com>2024-08-30 17:48:15 +0200
commit8b047ff11ebd4715647bfc041a190f72dcf4d5a9 (patch)
treee8440120b7bbd4e45b367acb3f7185d25e7f3766 /src/AST/Count.hs
parentf4b94d7cc2cb05611b462ba278e4f12f7a7a5e5e (diff)
Migrate to accumulators (mostly removing EVM code)
Diffstat (limited to 'src/AST/Count.hs')
-rw-r--r--src/AST/Count.hs18
1 files changed, 10 insertions, 8 deletions
diff --git a/src/AST/Count.hs b/src/AST/Count.hs
index de04b5f..f66b809 100644
--- a/src/AST/Count.hs
+++ b/src/AST/Count.hs
@@ -1,7 +1,12 @@
-{-# LANGUAGE LambdaCase #-}
+{-# LANGUAGE DeriveGeneric #-}
+{-# LANGUAGE DerivingStrategies #-}
+{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE GADTs #-}
+{-# LANGUAGE LambdaCase #-}
module AST.Count where
+import GHC.Generics (Generic, Generically(..))
+
import AST
import Data
@@ -18,9 +23,8 @@ instance Monoid Count where
data Occ = Occ { _occLexical :: Count
, _occRuntime :: Count }
- deriving (Eq)
-instance Semigroup Occ where Occ a b <> Occ c d = Occ (a <> c) (b <> d)
-instance Monoid Occ where mempty = Occ mempty mempty
+ deriving (Eq, Generic)
+ deriving (Semigroup, Monoid) via Generically Occ
-- | One of the two branches is taken
(<||>) :: Occ -> Occ -> Occ
@@ -49,8 +53,6 @@ occCount idx = \case
EIdx1 _ a b -> occCount idx a <> occCount idx b
EIdx _ e es -> occCount idx e <> foldMap (occCount idx) es
EOp _ _ e -> occCount idx e
- EMOne _ _ e -> occCount idx e
- EMScope e -> occCount idx e
- EMReturn _ e -> occCount idx e
- EMBind a b -> occCount idx a <> occCount (IS idx) b
+ EWith a b -> occCount idx a <> occCount (IS idx) b
+ EAccum a b e -> occCount idx a <> occCount idx b <> occCount idx e
EError{} -> mempty