Skip to content

Commit

Permalink
fix repl loading
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszcz committed Dec 20, 2023
1 parent e91cbe0 commit cc34c77
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 45 deletions.
4 changes: 0 additions & 4 deletions app/App.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ data App m a where
GetMainFile :: Maybe (AppPath File) -> App m (Path Abs File)
FromAppPathDir :: AppPath Dir -> App m (Path Abs Dir)
RenderStdOut :: (HasAnsiBackend a, HasTextBackend a) => a -> App m ()
RunCorePipelineEither :: AppPath File -> App m (Either JuvixError Artifacts)
Say :: Text -> App m ()
SayRaw :: ByteString -> App m ()

Expand Down Expand Up @@ -76,9 +75,6 @@ reAppIO args@RunAppIOArgs {..} =
AskInvokeDir -> return invDir
AskPkgDir -> return (_runAppIOArgsRoot ^. rootRootDir)
AskBuildDir -> return (resolveAbsBuildDir (_runAppIOArgsRoot ^. rootRootDir) (_runAppIOArgsRoot ^. rootBuildDir))
RunCorePipelineEither input -> do
entry <- getEntryPoint' args input
embed (corePipelineIOEither entry)
Say t
| g ^. globalOnlyErrors -> return ()
| otherwise -> embed (putStrLn t)
Expand Down
37 changes: 5 additions & 32 deletions app/Commands/Repl.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,9 @@ import Juvix.Compiler.Core.Transformation qualified as Core
import Juvix.Compiler.Core.Transformation.DisambiguateNames (disambiguateNames)
import Juvix.Compiler.Internal.Language qualified as Internal
import Juvix.Compiler.Internal.Pretty qualified as Internal
import Juvix.Compiler.Pipeline.Loader.PathResolver (runPathResolver)
import Juvix.Compiler.Pipeline.Loader.PathResolver.DependenciesConfig
import Juvix.Compiler.Pipeline.Loader.PathResolver.Error
import Juvix.Compiler.Pipeline.Package.Loader.Error
import Juvix.Compiler.Pipeline.Package.Loader.EvalEff.IO
import Juvix.Compiler.Pipeline.Repl
import Juvix.Compiler.Pipeline.Run
import Juvix.Compiler.Pipeline.Setup (entrySetup)
import Juvix.Data.CodeAnn (Ann)
import Juvix.Data.Effect.Git
import Juvix.Data.Effect.Process
import Juvix.Data.Error.GenericError qualified as Error
import Juvix.Data.NameKind
import Juvix.Extra.Paths qualified as P
Expand Down Expand Up @@ -119,7 +111,7 @@ quit _ = liftIO (throwIO Interrupt)

loadEntryPoint :: EntryPoint -> Repl ()
loadEntryPoint ep = do
artif <- liftIO (corePipelineIO' ep)
artif <- liftIO (runReplPipelineIO ep)
let newCtx =
ReplContext
{ _replContextArtifacts = artif,
Expand All @@ -141,29 +133,10 @@ loadFile f = do
loadEntryPoint entryPoint

loadDefaultPrelude :: Repl ()
loadDefaultPrelude = whenJustM defaultPreludeEntryPoint $ \e -> do
root <- Reader.asks (^. replRoot . rootRootDir)
let hasInternet = not (e ^. entryPointOffline)
-- The following is needed to ensure that the default location of the
-- standard library exists
void
. liftIO
. runM
. evalInternet hasInternet
. runFilesIO
. runError @JuvixError
. runReader e
. runTaggedLockPermissive
. runLogIO
. runProcessIO
. runError @GitProcessError
. runGitProcess
. runError @DependencyError
. runError @PackageLoaderError
. runEvalFileEffIO
. runPathResolver root
$ entrySetup defaultDependenciesConfig
loadEntryPoint e
loadDefaultPrelude =
whenJustM
defaultPreludeEntryPoint
loadEntryPoint

getReplEntryPoint :: (Root -> a -> GlobalOptions -> IO EntryPoint) -> a -> Repl EntryPoint
getReplEntryPoint f inputFile = do
Expand Down
18 changes: 9 additions & 9 deletions src/Juvix/Compiler/Pipeline/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -98,27 +98,27 @@ runIO opts entry = runIOEither entry >=> mayThrow
Left err -> runReader opts $ printErrorAnsiSafe err >> embed exitFailure
Right r -> return r

corePipelineIO' :: EntryPoint -> IO Artifacts
corePipelineIO' = corePipelineIO defaultGenericOptions
runReplPipelineIO :: EntryPoint -> IO Artifacts
runReplPipelineIO = runReplPipelineIO' defaultGenericOptions

corePipelineIO :: GenericOptions -> EntryPoint -> IO Artifacts
corePipelineIO opts entry = corePipelineIOEither entry >>= mayThrow
runReplPipelineIO' :: GenericOptions -> EntryPoint -> IO Artifacts
runReplPipelineIO' opts entry = runReplPipelineIOEither entry >>= mayThrow
where
mayThrow :: Either JuvixError r -> IO r
mayThrow = \case
Left err -> runM . runReader opts $ printErrorAnsiSafe err >> embed exitFailure
Right r -> return r

corePipelineIOEither ::
runReplPipelineIOEither ::
EntryPoint ->
IO (Either JuvixError Artifacts)
corePipelineIOEither = corePipelineIOEither' LockModePermissive
runReplPipelineIOEither = runReplPipelineIOEither' LockModePermissive

corePipelineIOEither' ::
runReplPipelineIOEither' ::
LockMode ->
EntryPoint ->
IO (Either JuvixError Artifacts)
corePipelineIOEither' lockMode entry = do
runReplPipelineIOEither' lockMode entry = do
let hasInternet = not (entry ^. entryPointOffline)
runPathResolver'
| mainIsPackageFile entry = runPackagePathResolverArtifacts (entry ^. entryPointResolverRoot)
Expand All @@ -144,7 +144,7 @@ corePipelineIOEither' lockMode entry = do
. mapError (JuvixError @PackageLoaderError)
. runEvalFileEffIO
. runPathResolver'
$ processFileToStoredCore entry
$ entrySetup defaultDependenciesConfig >> processFileToStoredCore entry
return $ case eith of
Left err -> Left err
Right (art, PipelineResult {..}) ->
Expand Down

0 comments on commit cc34c77

Please sign in to comment.