From c625efd9c53b97be780f9ac709e4653bbe705975 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Thu, 25 Oct 2018 13:47:07 -0400 Subject: [PATCH] Extract the fold over modules to the top level. --- src/Data/Abstract/Evaluatable.hs | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/Data/Abstract/Evaluatable.hs b/src/Data/Abstract/Evaluatable.hs index 30d0fd259..f7eb1e206 100644 --- a/src/Data/Abstract/Evaluatable.hs +++ b/src/Data/Abstract/Evaluatable.hs @@ -145,13 +145,8 @@ evaluate lang analyzeModule analyzeTerm modules = do (_, (preludeBinds, _)) <- runInModule lowerBound moduleInfoFromCallStack . runValue $ do definePrelude lang box unit - foldr (run preludeBinds) ask modules - where run preludeBinds m rest = do - evaluated <- runInModule preludeBinds (moduleInfo m) - (analyzeModule (runValue . evalTerm . moduleBody) - m) - -- FIXME: this should be some sort of Monoidal insert à la the Heap to accommodate multiple Go files being part of the same module. - local (ModuleTable.insert (modulePath (moduleInfo m)) ((evaluated <$ m) :| [])) rest + evaluateModules (run preludeBinds <$> modules) + where run preludeBinds m = (<$ m) <$> runInModule preludeBinds (moduleInfo m) (analyzeModule (runValue . evalTerm . moduleBody) m) evalTerm = fix (analyzeTerm ((. project) . eval)) >=> address @@ -183,6 +178,16 @@ runInModule prelude info . raiseHandler runInterpose . raiseHandler runEavesdrop +evaluateModules :: ( Carrier sig m + , Member (Reader (ModuleTable (NonEmpty (Module (ModuleResult address))))) sig + ) + => [Evaluator term address value m (Module (ModuleResult address))] + -> Evaluator term address value m (ModuleTable (NonEmpty (Module (ModuleResult address)))) +evaluateModules = foldr run ask + where run evaluator rest = do + evaluated <- evaluator + -- FIXME: this should be some sort of Monoidal insert à la the Heap to accommodate multiple Go files being part of the same module. + local (ModuleTable.insert (modulePath (moduleInfo evaluated)) (evaluated :| [])) rest traceResolve :: (Show a, Show b, Member Trace sig, Carrier sig m) => a -> b -> Evaluator term address value m ()