From 49de5d3357be3b42fc935d2b5bc936f53086e10b Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Mon, 28 May 2018 09:51:58 -0400 Subject: [PATCH] Generalize runGoto. --- src/Control/Abstract/Goto.hs | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/Control/Abstract/Goto.hs b/src/Control/Abstract/Goto.hs index 21d37aa4d..7e8b3bc2b 100644 --- a/src/Control/Abstract/Goto.hs +++ b/src/Control/Abstract/Goto.hs @@ -9,7 +9,7 @@ module Control.Abstract.Goto ) where import Control.Abstract.Evaluator -import Control.Monad.Effect (Eff) +import Control.Monad.Effect.Internal import qualified Data.IntMap as IntMap import Prelude hiding (fail) import Prologue @@ -54,24 +54,26 @@ data Goto effects value return where -- @ -- -- Callers can then evaluate the high-level 'Goto' effect by passing @Gotos@ and @getGotos@ to 'runGoto'. -runGoto :: Members '[ Fail - , Fresh - , State table - ] effects +runGoto :: ( Effectful (m location value) + , Members '[ Fail + , Fresh + , State table + ] effects + ) => (GotoTable effects value -> table) -> (table -> GotoTable effects value) - -> Evaluator location value (Goto effects value ': effects) a - -> Evaluator location value effects a -runGoto from to = interpret (\ goto -> do + -> m location value (Goto effects value ': effects) a + -> m location value effects a +runGoto from to = raiseHandler (interpret (\ goto -> do table <- to <$> getTable case goto of Label action -> do supremum <- fresh supremum <$ putTable (from (IntMap.insert supremum action table)) - Goto label -> maybeM (raiseEff (fail ("unknown label: " <> show label))) (IntMap.lookup label table)) + Goto label -> maybeM (raiseEff (fail ("unknown label: " <> show label))) (IntMap.lookup label table))) -getTable :: Member (State table) effects => Evaluator location value effects table +getTable :: (Effectful m, Member (State table) effects) => m effects table getTable = get -putTable :: Member (State table) effects => table -> Evaluator location value effects () +putTable :: (Effectful m, Member (State table) effects) => table -> m effects () putTable = put