Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exec script returns repl state #301

Merged
merged 1 commit into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pact-lsp/Pact/Core/LanguageServer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pact-repl/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 5 additions & 3 deletions pact-repl/Pact/Core/Repl.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
7 changes: 3 additions & 4 deletions pact-repl/Pact/Core/Repl/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module Pact.Core.Repl.Utils
( ReplDebugFlag(..)
, printDebug
, replFlagSet
, runReplT
, evalReplM
, ReplState(..)
, replFlags
, replEvalEnv
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pact-tests/Pact/Core/Test/GasGolden.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion pact-tests/Pact/Core/Test/ReplTests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pact-tests/Pact/Core/Test/StaticErrorTests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading