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

Fix pipeline setup in the repl #2046

Merged
merged 3 commits into from
May 3, 2023
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
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ jobs:
uses: jaxxstorm/action-install-gh-release@v1.10.0
with:
repo: wasmerio/wasmer
tag: latest
tag: v3.2.1
binaries-location: bin
cache: true

Expand Down Expand Up @@ -178,7 +178,7 @@ jobs:
uses: jaxxstorm/action-install-gh-release@v1.10.0
with:
repo: wasmerio/wasmer
tag: latest
tag: v3.2.1
binaries-location: bin
cache: true

Expand Down
21 changes: 16 additions & 5 deletions app/Commands/Repl.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import Data.String.Interpolate (i, __i)
import Evaluator
import Juvix.Compiler.Concrete.Data.Scope (scopePath)
import Juvix.Compiler.Concrete.Data.ScopedName (absTopModulePath)
import Juvix.Compiler.Concrete.Translation.FromParsed.Analysis.PathResolver (runPathResolver)
import Juvix.Compiler.Core qualified as Core
import Juvix.Compiler.Core.Extra.Value
import Juvix.Compiler.Core.Info qualified as Info
Expand All @@ -21,6 +22,7 @@ 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.Setup (entrySetup)
import Juvix.Data.Error.GenericError qualified as Error
import Juvix.Extra.Paths
import Juvix.Extra.Stdlib
Expand Down Expand Up @@ -123,11 +125,20 @@ runCommand opts = do
entryPoint <- getReplEntryPoint f
loadEntryPoint entryPoint

loadPrelude :: Repl ()
loadPrelude = loadDefaultPrelude

loadDefaultPrelude :: Repl ()
loadDefaultPrelude = whenJustM defaultPreludeEntryPoint loadEntryPoint
loadDefaultPrelude = whenJustM defaultPreludeEntryPoint $ \e -> do
let root = roots ^. rootsRootDir
-- The following is needed to ensure that the default location of the
-- standard library exists
void
. liftIO
. runM
. runFilesIO
. runError @Text
. runReader e
. runPathResolver root
$ entrySetup
loadEntryPoint e

printRoot :: String -> Repl ()
printRoot _ = do
Expand Down Expand Up @@ -267,7 +278,7 @@ runCommand opts = do
welcomeMsg
unless
(opts ^. replNoPrelude || gopts ^. globalNoStdlib)
(maybe loadPrelude (loadFile . (^. pathPath)) (opts ^. replInputFile))
(maybe loadDefaultPrelude (loadFile . (^. pathPath)) (opts ^. replInputFile))

finaliser :: Repl ExitDecision
finaliser = return Exit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module Juvix.Compiler.Concrete.Translation.FromParsed.Analysis.PathResolver
withPath,
withPathFile,
expectedModulePath,
runPathResolver,
runPathResolverPipe,
runPathResolverPipe',
ResolverState,
Expand Down
26 changes: 13 additions & 13 deletions src/Juvix/Extra/Stdlib.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,20 @@ ensureStdlib rootDir buildDir deps =
whenJustM (packageStdlib rootDir buildDir deps) $ \stdlibRoot ->
runReader stdlibRoot updateStdlib

packageStdlib :: Members '[Files] r => Path Abs Dir -> Path Abs Dir -> [Dependency] -> Sem r (Maybe (Path Abs Dir))
packageStdlib rootDir buildDir = firstJustM (isStdLib rootDir buildDir)

isStdLib :: Members '[Files] r => Path Abs Dir -> Path Abs Dir -> Dependency -> Sem r (Maybe (Path Abs Dir))
isStdLib rootDir buildDir (Dependency dep) = do
adir <- canonicalDir rootDir dep
let mstdlib :: Maybe (Path Rel Dir) = stripProperPrefix buildDir adir
return $
if
| mstdlib == Just relStdlibDir -> Just stdLibBuildDir
| otherwise -> Nothing
packageStdlib :: forall r. Members '[Files] r => Path Abs Dir -> Path Abs Dir -> [Dependency] -> Sem r (Maybe (Path Abs Dir))
packageStdlib rootDir buildDir = firstJustM isStdLib
where
stdLibBuildDir :: Path Abs Dir
stdLibBuildDir = juvixStdlibDir buildDir
isStdLib :: Dependency -> Sem r (Maybe (Path Abs Dir))
isStdLib (Dependency dep) = do
adir <- canonicalDir rootDir dep
let mstdlib :: Maybe (Path Rel Dir) = stripProperPrefix buildDir adir
return $
if
| mstdlib == Just relStdlibDir -> Just stdLibBuildDir
| otherwise -> Nothing
where
stdLibBuildDir :: Path Abs Dir
stdLibBuildDir = juvixStdlibDir buildDir

writeStdlib :: forall r. (Members '[Reader StdlibRoot, Files] r) => Sem r ()
writeStdlib = do
Expand Down