diff --git a/pact-lsp/Pact/Core/LanguageServer.hs b/pact-lsp/Pact/Core/LanguageServer.hs index 93f77ad1..748e332f 100644 --- a/pact-lsp/Pact/Core/LanguageServer.hs +++ b/pact-lsp/Pact/Core/LanguageServer.hs @@ -254,7 +254,7 @@ setupAndProcessFile nuri content = do , _replTestResults = [] } stateRef <- newIORef rstate - res <- runReplT stateRef (processFile Repl.interpretEvalBigStep nuri content) + res <- evalReplM stateRef (processFile Repl.interpretEvalBigStep nuri content) st <- readIORef stateRef pure $ (st,) <$> res where diff --git a/pact-repl/Main.hs b/pact-repl/Main.hs index 5c531431..708cfad5 100644 --- a/pact-repl/Main.hs +++ b/pact-repl/Main.hs @@ -139,7 +139,7 @@ main = O.execParser argParser >>= \case exitEither _ Left {} = die "Load failed" exitEither m (Right t) = m t >> exitSuccess exitLoad = exitEither (\_ -> hPutStrLn stderr "Load successful" >> hFlush stderr) - runScript f dolog = execScript dolog f >>= exitLoad + runScript f dolog = execScript dolog f >>= exitLoad . fst printVersion = putStrLn ("pact version " <> showVersion PI.version) printBuiltins = traverse_ (\bi -> T.putStrLn $ "\"" <> bi <> "\"") replCoreBuiltinNames diff --git a/pact-repl/Pact/Core/Repl.hs b/pact-repl/Pact/Core/Repl.hs index f77e6039..3f2d7fa0 100644 --- a/pact-repl/Pact/Core/Repl.hs +++ b/pact-repl/Pact/Core/Repl.hs @@ -37,12 +37,14 @@ import Pact.Core.Serialise import Pact.Core.Info import Pact.Core.Errors -execScript :: Bool -> FilePath -> IO (Either (PactError SpanInfo) [ReplCompileValue]) +execScript :: Bool -> FilePath -> IO (Either (PactError SpanInfo) [ReplCompileValue], ReplState ReplCoreBuiltin) execScript dolog f = do pdb <- mockPactDb serialisePact_repl_spaninfo ee <- defaultEvalEnv pdb replBuiltinMap ref <- newIORef (mkReplState ee logger) - runReplT ref $ loadFile f interpretEvalDirect + v <- evalReplM ref $ loadFile f interpretEvalDirect + state <- readIORef ref + pure (v, state) where logger :: Text -> EvalM e b i () logger @@ -55,7 +57,7 @@ runRepl = do ee <- defaultEvalEnv pdb replBuiltinMap let display' rcv = runInputT replSettings (displayOutput rcv) ref <- newIORef (mkReplState ee display') - runReplT ref (runInputT replSettings loop) >>= \case + evalReplM ref (runInputT replSettings loop) >>= \case Left err -> do putStrLn "Exited repl session with error:" putStrLn $ T.unpack $ replError (SourceCode "(interactive)" "") err diff --git a/pact-repl/Pact/Core/Repl/Utils.hs b/pact-repl/Pact/Core/Repl/Utils.hs index 52f24768..9f4eeffa 100644 --- a/pact-repl/Pact/Core/Repl/Utils.hs +++ b/pact-repl/Pact/Core/Repl/Utils.hs @@ -16,7 +16,7 @@ module Pact.Core.Repl.Utils ( ReplDebugFlag(..) , printDebug , replFlagSet - , runReplT + , evalReplM , ReplState(..) , replFlags , replEvalEnv @@ -204,9 +204,8 @@ replCompletion natives = dns = defNames ems in fmap ((renderModuleName mn <> ".") <>) dns -runReplT :: IORef (ReplState b) -> ReplM b a -> IO (Either (PactError SpanInfo) a) -runReplT env st = runEvalMResult (ReplEnv env) def st - +evalReplM :: IORef (ReplState b) -> ReplM b a -> IO (Either (PactError SpanInfo) a) +evalReplM env st = runEvalMResult (ReplEnv env) def st replError :: SourceCode diff --git a/pact-tests/Pact/Core/Test/GasGolden.hs b/pact-tests/Pact/Core/Test/GasGolden.hs index 2036e180..2108e092 100644 --- a/pact-tests/Pact/Core/Test/GasGolden.hs +++ b/pact-tests/Pact/Core/Test/GasGolden.hs @@ -114,6 +114,6 @@ runGasTest file interpret = do let source = SourceCode file src let rstate = mkReplState ee' (const (pure ())) & replCurrSource .~ source stateRef <- newIORef rstate - runReplT stateRef (interpret source) >>= \case + evalReplM stateRef (interpret source) >>= \case Left _ -> pure Nothing Right _ -> Just <$> readIORef gasRef diff --git a/pact-tests/Pact/Core/Test/ReplTests.hs b/pact-tests/Pact/Core/Test/ReplTests.hs index b90fd85f..9a0bda43 100644 --- a/pact-tests/Pact/Core/Test/ReplTests.hs +++ b/pact-tests/Pact/Core/Test/ReplTests.hs @@ -84,7 +84,7 @@ runReplTest (ReplSourceDir path) pdb file src interp = do let source = SourceCode (path file) src let rstate = mkReplState ee (const (pure ())) & replCurrSource .~ source stateRef <- newIORef rstate - runReplT stateRef (interp source) >>= \case + evalReplM stateRef (interp source) >>= \case Left e -> let rendered = replError (SourceCode file src) e in assertFailure (T.unpack rendered) diff --git a/pact-tests/Pact/Core/Test/StaticErrorTests.hs b/pact-tests/Pact/Core/Test/StaticErrorTests.hs index c02fc735..8a556d6f 100644 --- a/pact-tests/Pact/Core/Test/StaticErrorTests.hs +++ b/pact-tests/Pact/Core/Test/StaticErrorTests.hs @@ -41,7 +41,7 @@ runStaticTest label src interp predicate = do & replCurrSource .~ source & replNativesEnabled .~ True stateRef <- newIORef rstate - v <- runReplT stateRef (interpretReplProgram interp source) + v <- evalReplM stateRef (interpretReplProgram interp source) case v of Left err -> assertBool ("Expected Error to match predicate, but got " <> show err <> " instead") (predicate err)