Skip to content

Commit

Permalink
cleanup compile
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcardon committed Aug 17, 2023
1 parent f0f2683 commit 5e70bec
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 40 deletions.
2 changes: 0 additions & 2 deletions pact-core-tests/Pact/Core/Test/ReplTests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ import Pact.Core.Gas
import Pact.Core.Literal
import Pact.Core.Persistence

import Pact.Core.IR.Eval.Runtime

import Pact.Core.Repl.Utils
import Pact.Core.Compile
import Pact.Core.Repl.Compile
Expand Down
48 changes: 10 additions & 38 deletions pact-core/Pact/Core/Repl/Compile.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import Control.Monad
import Control.Monad.Except
import Control.Monad.IO.Class(liftIO)
import Data.Text(Text)
import Data.ByteString(ByteString)
import Data.Proxy
-- import Data.Maybe(mapMaybe)
import qualified Data.Map.Strict as Map
Expand Down Expand Up @@ -46,38 +45,6 @@ import qualified Pact.Core.Syntax.ParseTree as Lisp
import qualified Pact.Core.Syntax.Lexer as Lisp
import qualified Pact.Core.Syntax.Parser as Lisp

-- data InterpretOutput b i
-- = InterpretValue (CEKValue b i (ReplEvalM ReplRawBuiltin SpanInfo)) SpanInfo
-- | InterpretLog Text
-- deriving Show

-- interpretExpr
-- :: ByteString
-- -> ReplM ReplRawBuiltin (ReplEvalResult RawBuiltin SpanInfo)
-- interpretExpr source = do
-- pactdb <- use replPactDb
-- loaded <- use replLoaded
-- lexx <- liftEither (Lisp.lexer source)
-- debugIfFlagSet ReplDebugLexer lexx
-- parsed <- liftEither $ Lisp.parseExpr lexx
-- debugIfFlagSet ReplDebugParser parsed
-- (DesugarOutput desugared loaded' _) <- runDesugarTermLisp Proxy pactdb loaded parsed
-- evalGas <- use replGas
-- evalLog <- use replEvalLog
-- mhashes <- uses (replLoaded . loModules) (fmap (view mdModuleHash))
-- let rEnv = ReplEvalEnv evalGas evalLog
-- cekEnv = EvalEnv
-- { _eeBuiltins = replRawBuiltinRuntime
-- , _eeLoaded = _loAllLoaded loaded'
-- , _eeGasModel = freeGasEnv
-- , _eeMHashes = mhashes
-- , _eeMsgSigs = mempty
-- , _eePactDb = pactdb }
-- rState = ReplEvalState cekEnv (EvalState (CapState [] mempty) [] [] False)
-- value <- liftEither =<< liftIO (runReplCEK rEnv rState desugared)
-- replLoaded .= loaded'
-- pure value

-- Small internal debugging function for playing with file loading within
-- this module
data ReplCompileValue
Expand All @@ -87,13 +54,15 @@ data ReplCompileValue
deriving Show

loadFile :: FilePath -> ReplM ReplRawBuiltin [ReplCompileValue]
loadFile source = liftIO (B.readFile source) >>= interpretReplProgram

loadFile loc = do
source <- SourceCode <$> liftIO (B.readFile loc)
replCurrSource .= source
interpretReplProgram source

interpretReplProgram
:: ByteString
:: SourceCode
-> ReplM ReplRawBuiltin [ReplCompileValue]
interpretReplProgram source = do
interpretReplProgram (SourceCode source) = do
pactdb <- use replPactDb
lexx <- liftEither (Lisp.lexer source)
debugIfFlagSet ReplDebugLexer lexx
Expand All @@ -111,8 +80,11 @@ interpretReplProgram source = do
pure <$> pipe' pactdb rtl
Lisp.RTLReplSpecial rsf -> case rsf of
Lisp.ReplLoad txt b _ -> do
oldLoaded <- use replCurrSource
when b $ replLoaded .= mempty
loadFile (T.unpack txt)
out <- loadFile (T.unpack txt)
replCurrSource .= oldLoaded
pure out
pipe' pactdb tl = do
debugIfLispExpr tl
lastLoaded <- use replLoaded
Expand Down
8 changes: 8 additions & 0 deletions pact-core/Pact/Core/Repl/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ module Pact.Core.Repl.Utils
, unlessReplFlagSet
, debugIfFlagSet
, replCompletion
, replCurrSource
, ReplAction(..)
, parseReplAction
, prettyReplFlag
, ReplSource(..)
, replError
, SourceCode(..)
) where

import Control.Lens
Expand All @@ -43,6 +45,7 @@ import Data.Set(Set)
import Data.Text(Text)
import Data.List(isPrefixOf)
import Data.Maybe(mapMaybe)
import Data.ByteString(ByteString)
import qualified Data.Set as Set
import qualified Data.Map.Strict as Map
import qualified Data.Text as T
Expand All @@ -61,6 +64,10 @@ import qualified Pact.Core.IR.Term as Term

import System.Console.Haskeline.Completion

newtype SourceCode
= SourceCode ByteString
deriving Show

data ReplDebugFlag
= ReplDebugLexer
| ReplDebugParser
Expand Down Expand Up @@ -109,6 +116,7 @@ data ReplState b
, _replPactDb :: PactDb b SpanInfo
, _replGas :: IORef Gas
, _replEvalLog :: IORef (Maybe [(Text, Gas)])
, _replCurrSource :: SourceCode
}


Expand Down

0 comments on commit 5e70bec

Please sign in to comment.