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

Per-module compilation #2468

Merged
merged 85 commits into from
Dec 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
85 commits
Select commit Hold shift + click to select a range
bf52baf
serialization instances
lukaszcz Oct 24, 2023
095f7e5
wip
lukaszcz Oct 27, 2023
0e686e0
wip
lukaszcz Nov 6, 2023
78e69b7
wip
lukaszcz Nov 7, 2023
bb73b56
wip internal
lukaszcz Nov 8, 2023
4d4c633
wip compilation
lukaszcz Nov 8, 2023
80e42c8
fix compilation
lukaszcz Nov 9, 2023
cde98a2
new name id
lukaszcz Nov 9, 2023
a4c65d8
wip
lukaszcz Nov 9, 2023
2017716
wip
lukaszcz Nov 10, 2023
1646d66
wip
lukaszcz Nov 13, 2023
079525e
wip
lukaszcz Nov 14, 2023
a45392c
fix pipeline wip
lukaszcz Nov 15, 2023
86f0e6e
serialize concrete
lukaszcz Nov 16, 2023
e23e2e4
simplify
lukaszcz Nov 17, 2023
88884e8
simplify import
lukaszcz Nov 17, 2023
67d1826
stored name signatures
lukaszcz Nov 17, 2023
a12a004
add file
lukaszcz Nov 17, 2023
39c5c42
signature info
lukaszcz Nov 17, 2023
b8c9fa4
SignatureInfoBuilder
lukaszcz Nov 20, 2023
8fb470d
InternalModule
lukaszcz Nov 20, 2023
19c9d5c
Store.Scoped.Data.InfoTable
lukaszcz Nov 20, 2023
33d3b61
fix scoper
lukaszcz Nov 21, 2023
c6798d7
fix Internal.FromConcrete
lukaszcz Nov 21, 2023
46b2753
Core.fromInternal
lukaszcz Nov 21, 2023
e3f0d4e
FunctionsTable & TypesTable
lukaszcz Nov 21, 2023
812503b
adjust Core (wip)
lukaszcz Nov 21, 2023
14c1cce
Core <-> Store.Core conversions
lukaszcz Nov 22, 2023
97c6771
Repl.hs & Run.hs
lukaszcz Nov 22, 2023
bf2a84c
fix compilation
lukaszcz Nov 23, 2023
d77b93a
add module id to core Symbol
lukaszcz Nov 23, 2023
ab94301
add module id to core tags
lukaszcz Nov 23, 2023
a29df67
per-module compilation in Core
lukaszcz Nov 24, 2023
10b5641
combine info table
lukaszcz Nov 27, 2023
283efdb
import cycle detection
lukaszcz Nov 27, 2023
9573931
Merge branch 'main' into per-module-compilation
lukaszcz Nov 27, 2023
145976c
Merge branch 'main' into per-module-compilation
lukaszcz Nov 27, 2023
ed4a419
merge fixes
lukaszcz Nov 27, 2023
1420873
bugfixes
lukaszcz Nov 27, 2023
4f73fd4
bugfixes
lukaszcz Nov 27, 2023
53db8be
scoped local modules
lukaszcz Nov 28, 2023
9707059
fix duplicate dependencies
lukaszcz Nov 28, 2023
e197eb7
Merge branch 'main' into per-module-compilation
lukaszcz Nov 28, 2023
f2468d8
Merge branch 'main' into per-module-compilation
lukaszcz Nov 29, 2023
a3792c3
Merge branch 'main' into per-module-compilation
lukaszcz Dec 1, 2023
63f8861
Merge branch 'main' into per-module-compilation
lukaszcz Dec 1, 2023
578c2b3
module saving/loading
lukaszcz Dec 1, 2023
0ae4460
Merge branch 'main' into per-module-compilation
lukaszcz Dec 14, 2023
7cd72fb
Fix after merge
lukaszcz Dec 14, 2023
b048ad4
bugfixes
lukaszcz Dec 14, 2023
efd76fc
refactor
lukaszcz Dec 14, 2023
085d0ab
cache visited modules in memory
lukaszcz Dec 15, 2023
f99426a
tests compile
lukaszcz Dec 15, 2023
cf07146
Merge branch 'main' into per-module-compilation
lukaszcz Dec 15, 2023
b871ffb
fix after merge
lukaszcz Dec 15, 2023
836576f
fix path resolver errors
lukaszcz Dec 18, 2023
96c5340
fix path resolver errors
lukaszcz Dec 18, 2023
e9b4dd6
fix scoping local modules
lukaszcz Dec 18, 2023
dfa86e8
fix scoper tests
lukaszcz Dec 18, 2023
dd91517
fix alias bug
lukaszcz Dec 18, 2023
13ee253
fix combined scoped info table
lukaszcz Dec 18, 2023
1fbc8bd
fix format
lukaszcz Dec 18, 2023
06c7f57
fix markdown test
lukaszcz Dec 18, 2023
916a986
fix geb tests
lukaszcz Dec 18, 2023
858d1e1
fix info table pruning
lukaszcz Dec 19, 2023
21f0e9d
fix internal to core tests
lukaszcz Dec 19, 2023
c7e6613
fix dependency builder
lukaszcz Dec 20, 2023
1c923a5
comment
lukaszcz Dec 20, 2023
f7057b0
fix pipeline tests
lukaszcz Dec 20, 2023
e91cbe0
fix judoc scoping
lukaszcz Dec 20, 2023
cc34c77
fix repl loading
lukaszcz Dec 20, 2023
2ec39b9
fix repl scoping & evaluation
lukaszcz Dec 20, 2023
768e2fb
fix smoke tests
lukaszcz Dec 21, 2023
3993587
fix repl imports
lukaszcz Dec 21, 2023
d7f0afe
fix repl
lukaszcz Dec 21, 2023
43baaf0
fix double stdin read
lukaszcz Dec 21, 2023
9cc0f78
fix imports on stdin
lukaszcz Dec 21, 2023
511f9e2
fix synonyms test
lukaszcz Dec 21, 2023
a9db3e4
lock build dir for parallel tests
lukaszcz Dec 21, 2023
ea76263
fix highlighting
lukaszcz Dec 21, 2023
d68d1d2
fine-grained locking
lukaszcz Dec 22, 2023
18a21e7
fix recursive html generation
lukaszcz Dec 22, 2023
ab74823
fix smoke tests
lukaszcz Dec 22, 2023
6f050e8
remove dead code
lukaszcz Dec 22, 2023
f8559b9
fragile recompilation
lukaszcz Dec 22, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
62 changes: 43 additions & 19 deletions app/App.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ module App where
import CommonOptions
import Data.ByteString qualified as ByteString
import GlobalOptions
import Juvix.Compiler.Concrete.Translation.FromParsed.Analysis.PathResolver
import Juvix.Compiler.Internal.Translation (InternalTypedResult)
import Juvix.Compiler.Internal.Translation.FromInternal.Analysis.Termination.Checker
import Juvix.Compiler.Pipeline.Package
import Juvix.Compiler.Pipeline.Loader.PathResolver
import Juvix.Compiler.Pipeline.Root
import Juvix.Compiler.Pipeline.Run
import Juvix.Data.Error qualified as Error
import Juvix.Extra.Paths.Base hiding (rootBuildDir)
Expand All @@ -30,7 +31,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 +76,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 Expand Up @@ -129,17 +126,17 @@ getEntryPoint' RunAppIOArgs {..} inputFile = do
| otherwise -> return Nothing
set entryPointStdin estdin <$> entryPointFromGlobalOptionsPre root (inputFile ^. pathPath) opts

runPipelineNoFileEither :: (Members '[Embed IO, TaggedLock, App] r) => Sem (PipelineEff r) a -> Sem r (Either JuvixError (ResolverState, a))
runPipelineNoFileEither p = do
args <- askArgs
entry <- getEntryPointStdin' args
snd <$> runIOEither entry p

runPipelineEither :: (Members '[Embed IO, TaggedLock, App] r) => AppPath File -> Sem (PipelineEff r) a -> Sem r (Either JuvixError (ResolverState, a))
runPipelineEither :: (Members '[Embed IO, TaggedLock, App] r) => AppPath File -> Sem (PipelineEff r) a -> Sem r (Either JuvixError (ResolverState, PipelineResult a))
runPipelineEither input p = do
args <- askArgs
entry <- getEntryPoint' args input
snd <$> runIOEither entry p
runIOEither entry p

runPipelineSetupEither :: (Members '[Embed IO, TaggedLock, App] r) => Sem (PipelineEff' r) a -> Sem r (Either JuvixError (ResolverState, a))
runPipelineSetupEither p = do
args <- askArgs
entry <- getEntryPointStdin' args
runIOEitherPipeline entry p

getEntryPointStdin' :: (Members '[Embed IO, TaggedLock] r) => RunAppIOArgs -> Sem r EntryPoint
getEntryPointStdin' RunAppIOArgs {..} = do
Expand Down Expand Up @@ -170,7 +167,13 @@ getEntryPoint inputFile = do
_runAppIOArgsRoot <- askRoot
getEntryPoint' (RunAppIOArgs {..}) inputFile

runPipelineTermination :: (Members '[App, Embed IO, TaggedLock] r) => AppPath File -> Sem (Termination ': PipelineEff r) a -> Sem r a
getEntryPointStdin :: (Members '[Embed IO, App, TaggedLock] r) => Sem r EntryPoint
getEntryPointStdin = do
_runAppIOArgsGlobalOptions <- askGlobalOptions
_runAppIOArgsRoot <- askRoot
getEntryPointStdin' (RunAppIOArgs {..})

runPipelineTermination :: (Members '[Embed IO, App, TaggedLock] r) => AppPath File -> Sem (Termination ': PipelineEff r) a -> Sem r (PipelineResult a)
runPipelineTermination input p = do
r <- runPipelineEither input (evalTermination iniTerminationState p)
case r of
Expand All @@ -182,11 +185,32 @@ runPipeline input p = do
r <- runPipelineEither input p
case r of
Left err -> exitJuvixError err
Right res -> return (snd res)
Right res -> return (snd res ^. pipelineResult)

runPipelineHtml :: (Members '[App, Embed IO, TaggedLock] r) => Bool -> AppPath File -> Sem r (InternalTypedResult, [InternalTypedResult])
runPipelineHtml bNonRecursive input =
if
| bNonRecursive -> do
r <- runPipeline input upToInternalTyped
return (r, [])
| otherwise -> do
args <- askArgs
entry <- getEntryPoint' args input
r <- runPipelineHtmlEither entry
case r of
Left err -> exitJuvixError err
Right res -> return res

runPipelineEntry :: (Members '[App, Embed IO, TaggedLock] r) => EntryPoint -> Sem (PipelineEff r) a -> Sem r a
runPipelineEntry entry p = do
r <- runIOEither entry p
case r of
Left err -> exitJuvixError err
Right res -> return (snd res ^. pipelineResult)

runPipelineNoFile :: (Members '[App, Embed IO, TaggedLock] r) => Sem (PipelineEff r) a -> Sem r a
runPipelineNoFile p = do
r <- runPipelineNoFileEither p
runPipelineSetup :: (Members '[App, Embed IO, TaggedLock] r) => Sem (PipelineEff' r) a -> Sem r a
runPipelineSetup p = do
r <- runPipelineSetupEither p
case r of
Left err -> exitJuvixError err
Right res -> return (snd res)
Expand Down
8 changes: 4 additions & 4 deletions app/Commands/Compile.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ runCommand opts@CompileOptions {..} = do
Compile.PipelineArg
{ _pipelineArgFile = inputFile,
_pipelineArgOptions = opts,
_pipelineArgInfoTable = _coreResultTable
_pipelineArgModule = _coreResultModule
}
case _compileTarget of
TargetNative64 -> Compile.runCPipeline arg
Expand All @@ -31,8 +31,8 @@ writeCoreFile :: (Members '[Embed IO, App, TaggedLock] r) => Compile.PipelineArg
writeCoreFile pa@Compile.PipelineArg {..} = do
entryPoint <- Compile.getEntry pa
coreFile <- Compile.outputFile _pipelineArgOptions _pipelineArgFile
r <- runReader entryPoint $ runError @JuvixError $ Core.toEval _pipelineArgInfoTable
r <- runReader entryPoint $ runError @JuvixError $ Core.toStored _pipelineArgModule
case r of
Left e -> exitJuvixError e
Right tab ->
embed $ TIO.writeFile (toFilePath coreFile) (show $ Core.ppOutDefault (Core.disambiguateNames tab))
Right md ->
embed $ TIO.writeFile (toFilePath coreFile) (show $ Core.ppOutDefault (Core.disambiguateNames md ^. Core.moduleInfoTable))
4 changes: 3 additions & 1 deletion app/Commands/Dependencies/Update.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module Commands.Dependencies.Update where

import Commands.Base
import Juvix.Compiler.Pipeline.Loader.PathResolver
import Juvix.Compiler.Pipeline.Setup

runCommand :: (Members '[Embed IO, TaggedLock, App] r) => Sem r ()
runCommand = runPipelineNoFile (upToSetup (set dependenciesConfigForceUpdateLockfile True defaultDependenciesConfig))
runCommand = runPipelineSetup (entrySetup (set dependenciesConfigForceUpdateLockfile True defaultDependenciesConfig))
6 changes: 3 additions & 3 deletions app/Commands/Dev/Core/Asm.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ runCommand opts = do
gopts <- askGlobalOptions
inputFile :: Path Abs File <- fromAppPathFile sinputFile
s' <- readFile $ toFilePath inputFile
tab <- getRight (mapLeft JuvixError (Core.runParserMain inputFile Core.emptyInfoTable s'))
r <- runReader (project @GlobalOptions @Core.CoreOptions gopts) $ runError @JuvixError $ Core.toStripped' tab
tab' <- Asm.fromCore . Stripped.fromCore <$> getRight r
tab <- getRight (mapLeft JuvixError (Core.runParserMain inputFile defaultModuleId mempty s'))
r <- runReader (project @GlobalOptions @Core.CoreOptions gopts) $ runError @JuvixError $ Core.toStripped' (Core.moduleFromInfoTable tab)
tab' <- Asm.fromCore . Stripped.fromCore . Core.computeCombinedInfoTable <$> getRight r
if
| project opts ^. coreAsmPrint ->
renderStdOut (Asm.ppOutDefault tab' tab')
Expand Down
6 changes: 3 additions & 3 deletions app/Commands/Dev/Core/Compile.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ module Commands.Dev.Core.Compile where
import Commands.Base
import Commands.Dev.Core.Compile.Base
import Commands.Dev.Core.Compile.Options
import Juvix.Compiler.Core.Data.InfoTable qualified as Core
import Juvix.Compiler.Core.Data.Module qualified as Core
import Juvix.Compiler.Core.Translation.FromSource qualified as Core

runCommand :: forall r. (Members '[Embed IO, App, TaggedLock] r) => CompileOptions -> Sem r ()
runCommand opts = do
file <- getFile
s <- readFile (toFilePath file)
tab <- getRight (mapLeft JuvixError (Core.runParserMain file Core.emptyInfoTable s))
let arg = PipelineArg opts file tab
tab <- getRight (mapLeft JuvixError (Core.runParserMain file defaultModuleId mempty s))
let arg = PipelineArg opts file (Core.moduleFromInfoTable tab)
case opts ^. compileTarget of
TargetWasm32Wasi -> runCPipeline arg
TargetNative64 -> runCPipeline arg
Expand Down
12 changes: 6 additions & 6 deletions app/Commands/Dev/Core/Compile/Base.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import Juvix.Compiler.Backend qualified as Backend
import Juvix.Compiler.Backend.C qualified as C
import Juvix.Compiler.Backend.Geb qualified as Geb
import Juvix.Compiler.Backend.VampIR.Translation qualified as VampIR
import Juvix.Compiler.Core.Data.InfoTable qualified as Core
import Juvix.Compiler.Core.Data.Module qualified as Core
import System.FilePath (takeBaseName)

data PipelineArg = PipelineArg
{ _pipelineArgOptions :: CompileOptions,
_pipelineArgFile :: Path Abs File,
_pipelineArgInfoTable :: Core.InfoTable
_pipelineArgModule :: Core.Module
}

getEntry :: (Members '[Embed IO, App, TaggedLock] r) => PipelineArg -> Sem r EntryPoint
Expand Down Expand Up @@ -51,7 +51,7 @@ runCPipeline ::
Sem r ()
runCPipeline pa@PipelineArg {..} = do
entryPoint <- getEntry pa
C.MiniCResult {..} <- getRight (run (runReader entryPoint (runError (coreToMiniC _pipelineArgInfoTable :: Sem '[Error JuvixError, Reader EntryPoint] C.MiniCResult))))
C.MiniCResult {..} <- getRight (run (runReader entryPoint (runError (coreToMiniC _pipelineArgModule :: Sem '[Error JuvixError, Reader EntryPoint] C.MiniCResult))))
cFile <- inputCFile _pipelineArgFile
embed $ TIO.writeFile (toFilePath cFile) _resultCCode
outfile <- Compile.outputFile _pipelineArgOptions _pipelineArgFile
Expand Down Expand Up @@ -84,7 +84,7 @@ runGebPipeline pa@PipelineArg {..} = do
{ _lispPackageName = fromString $ takeBaseName $ toFilePath gebFile,
_lispPackageEntry = "*entry*"
}
Geb.Result {..} <- getRight (run (runReader entryPoint (runError (coreToGeb spec _pipelineArgInfoTable :: Sem '[Error JuvixError, Reader EntryPoint] Geb.Result))))
Geb.Result {..} <- getRight (run (runReader entryPoint (runError (coreToGeb spec _pipelineArgModule :: Sem '[Error JuvixError, Reader EntryPoint] Geb.Result))))
embed $ TIO.writeFile (toFilePath gebFile) _resultCode

runVampIRPipeline ::
Expand All @@ -95,14 +95,14 @@ runVampIRPipeline ::
runVampIRPipeline pa@PipelineArg {..} = do
entryPoint <- getEntry pa
vampirFile <- Compile.outputFile _pipelineArgOptions _pipelineArgFile
VampIR.Result {..} <- getRight (run (runReader entryPoint (runError (coreToVampIR _pipelineArgInfoTable :: Sem '[Error JuvixError, Reader EntryPoint] VampIR.Result))))
VampIR.Result {..} <- getRight (run (runReader entryPoint (runError (coreToVampIR _pipelineArgModule :: Sem '[Error JuvixError, Reader EntryPoint] VampIR.Result))))
embed $ TIO.writeFile (toFilePath vampirFile) _resultCode

runAsmPipeline :: (Members '[Embed IO, App, TaggedLock] r) => PipelineArg -> Sem r ()
runAsmPipeline pa@PipelineArg {..} = do
entryPoint <- getEntry pa
asmFile <- Compile.outputFile _pipelineArgOptions _pipelineArgFile
r <- runReader entryPoint $ runError @JuvixError (coreToAsm _pipelineArgInfoTable)
r <- runReader entryPoint $ runError @JuvixError (coreToAsm _pipelineArgModule)
tab' <- getRight r
let code = Asm.ppPrint tab' tab'
embed $ TIO.writeFile (toFilePath asmFile) code
3 changes: 1 addition & 2 deletions app/Commands/Dev/Core/Eval.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ module Commands.Dev.Core.Eval where
import Commands.Base
import Commands.Dev.Core.Eval.Options
import Evaluator
import Juvix.Compiler.Core.Data.InfoTable qualified as Core
import Juvix.Compiler.Core.Translation.FromSource qualified as Core

runCommand :: forall r. (Members '[Embed IO, App] r) => CoreEvalOptions -> Sem r ()
runCommand opts = do
f :: Path Abs File <- fromAppPathFile b
s <- readFile (toFilePath f)
case Core.runParser f Core.emptyInfoTable s of
case Core.runParser f defaultModuleId mempty s of
Left err -> exitJuvixError (JuvixError err)
Right (tab, Just node) -> do evalAndPrint opts tab node
Right (_, Nothing) -> return ()
Expand Down
17 changes: 7 additions & 10 deletions app/Commands/Dev/Core/FromConcrete.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,21 @@ import Commands.Base
import Commands.Dev.Core.FromConcrete.Options
import Evaluator
import Juvix.Compiler.Core.Data.InfoTable
import Juvix.Compiler.Core.Data.Module qualified as Core
import Juvix.Compiler.Core.Options qualified as Core
import Juvix.Compiler.Core.Pretty qualified as Core
import Juvix.Compiler.Core.Transformation qualified as Core
import Juvix.Compiler.Core.Transformation.DisambiguateNames (disambiguateNames)
import Juvix.Compiler.Core.Transformation.DisambiguateNames (disambiguateNames')
import Juvix.Compiler.Core.Translation

runCommand :: forall r. (Members '[Embed IO, TaggedLock, App] r) => CoreFromConcreteOptions -> Sem r ()
runCommand localOpts = do
gopts <- askGlobalOptions
tab <- (^. coreResultTable) <$> runPipeline (localOpts ^. coreFromConcreteInputFile) upToCore
md <- (^. coreResultModule) <$> runPipeline (localOpts ^. coreFromConcreteInputFile) upToCore
path :: Path Abs File <- fromAppPathFile (localOpts ^. coreFromConcreteInputFile)
let r = run $ runReader (project @GlobalOptions @Core.CoreOptions gopts) $ runError @JuvixError $ Core.applyTransformations (project localOpts ^. coreFromConcreteTransformations) tab
tab0 :: InfoTable <- getRight r
let tab' :: InfoTable = if localOpts ^. coreFromConcreteNoDisambiguate then tab0 else disambiguateNames tab0
let r = run $ runReader (project @GlobalOptions @Core.CoreOptions gopts) $ runError @JuvixError $ Core.applyTransformations (project localOpts ^. coreFromConcreteTransformations) md
tab0 :: InfoTable <- Core.computeCombinedInfoTable <$> getRight r
let tab' :: InfoTable = if localOpts ^. coreFromConcreteNoDisambiguate then tab0 else disambiguateNames' tab0
inInputModule :: IdentifierInfo -> Bool
inInputModule _ | not (localOpts ^. coreFromConcreteFilter) = True
inInputModule x = (== Just path) . (^? identifierLocation . _Just . intervalFile) $ x
Expand All @@ -40,12 +41,8 @@ runCommand localOpts = do
goPrint :: Sem r ()
goPrint = case localOpts ^. coreFromConcreteSymbolName of
Just {} -> printNode (fromMaybe err (getDef selInfo))
Nothing -> renderStdOut (Core.ppOut localOpts printTab)
Nothing -> renderStdOut (Core.ppOut localOpts tab')
where
printTab :: InfoTable
printTab
| localOpts ^. coreFromConcreteFilter = filterByFile path tab'
| otherwise = tab'
printNode :: (Text, Core.Node) -> Sem r ()
printNode (name, node) = do
renderStdOut (name <> " = ")
Expand Down
3 changes: 1 addition & 2 deletions app/Commands/Dev/Core/Normalize.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ module Commands.Dev.Core.Normalize where
import Commands.Base
import Commands.Dev.Core.Normalize.Options
import Evaluator
import Juvix.Compiler.Core.Data.InfoTable qualified as Core
import Juvix.Compiler.Core.Translation.FromSource qualified as Core

runCommand :: forall r. (Members '[Embed IO, App] r) => CoreNormalizeOptions -> Sem r ()
runCommand opts = do
f :: Path Abs File <- fromAppPathFile b
s <- readFile (toFilePath f)
case Core.runParser f Core.emptyInfoTable s of
case Core.runParser f defaultModuleId mempty s of
Left err -> exitJuvixError (JuvixError err)
Right (tab, Just node) -> do normalizeAndPrint opts tab node
Right (_, Nothing) -> return ()
Expand Down
6 changes: 3 additions & 3 deletions app/Commands/Dev/Core/Read.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ runCommand opts = do
gopts <- askGlobalOptions
inputFile :: Path Abs File <- fromAppPathFile sinputFile
s' <- readFile . toFilePath $ inputFile
tab <- getRight (mapLeft JuvixError (Core.runParserMain inputFile Core.emptyInfoTable s'))
let r = run $ runReader (project @GlobalOptions @Core.CoreOptions gopts) $ runError @JuvixError $ Core.applyTransformations (project opts ^. coreReadTransformations) tab
tab <- getRight (mapLeft JuvixError (Core.runParserMain inputFile defaultModuleId mempty s'))
let r = run $ runReader (project @GlobalOptions @Core.CoreOptions gopts) $ runError @JuvixError $ Core.applyTransformations (project opts ^. coreReadTransformations) (Core.moduleFromInfoTable tab)
tab0 <- getRight $ mapLeft JuvixError r
let tab' = if project opts ^. coreReadNoDisambiguate then tab0 else Core.disambiguateNames tab0
let tab' = Core.computeCombinedInfoTable $ if project opts ^. coreReadNoDisambiguate then tab0 else Core.disambiguateNames tab0
embed (Scoper.scopeTrace tab')
unless (project opts ^. coreReadNoPrint) $ do
renderStdOut (Pretty.ppOut opts tab')
Expand Down
19 changes: 11 additions & 8 deletions app/Commands/Dev/Core/Repl.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module Commands.Dev.Core.Repl where
import Commands.Base
import Commands.Dev.Core.Repl.Options
import Juvix.Compiler.Core.Data.InfoTable qualified as Core
import Juvix.Compiler.Core.Data.Module qualified as Core
import Juvix.Compiler.Core.Evaluator qualified as Core
import Juvix.Compiler.Core.Extra.Base qualified as Core
import Juvix.Compiler.Core.Info qualified as Info
Expand All @@ -18,10 +19,10 @@ import Juvix.Extra.Paths
runCommand :: forall r. (Members '[Embed IO, App] r) => CoreReplOptions -> Sem r ()
runCommand opts = do
showReplWelcome
runRepl opts Core.emptyInfoTable
runRepl opts mempty

parseText :: Core.InfoTable -> Text -> Either Core.MegaparsecError (Core.InfoTable, Maybe Core.Node)
parseText = Core.runParser replPath
parseText = Core.runParser replPath defaultModuleId

runRepl :: forall r. (Members '[Embed IO, App] r) => CoreReplOptions -> Core.InfoTable -> Sem r ()
runRepl opts tab = do
Expand Down Expand Up @@ -76,15 +77,15 @@ runRepl opts tab = do
':' : 'l' : ' ' : f -> do
s' <- readFile f
sf <- someBaseToAbs' (someFile f)
case Core.runParser sf Core.emptyInfoTable s' of
case Core.runParser sf defaultModuleId mempty s' of
Left err -> do
printJuvixError (JuvixError err)
runRepl opts tab
Right (tab', mnode) -> case mnode of
Nothing -> runRepl opts tab'
Just node -> replEval False tab' node
":r" ->
runRepl opts Core.emptyInfoTable
runRepl opts mempty
_ ->
case parseText tab s of
Left err -> do
Expand All @@ -105,26 +106,28 @@ runRepl opts tab = do
Right node'
| Info.member Info.kNoDisplayInfo (Core.getInfo node') -> runRepl opts tab'
| otherwise -> do
renderStdOut (Core.ppOut opts (Core.disambiguateNodeNames tab' node'))
renderStdOut (Core.ppOut opts (Core.disambiguateNodeNames (Core.moduleFromInfoTable tab') node'))
embed (putStrLn "")
runRepl opts tab'
where
defaultLoc = singletonInterval (mkInitialLoc replPath)

replNormalize :: Core.InfoTable -> Core.Node -> Sem r ()
replNormalize tab' node =
let node' = normalize tab' node
let md' = Core.moduleFromInfoTable tab'
node' = normalize md' node
in if
| Info.member Info.kNoDisplayInfo (Core.getInfo node') ->
runRepl opts tab'
| otherwise -> do
renderStdOut (Core.ppOut opts (Core.disambiguateNodeNames tab' node'))
renderStdOut (Core.ppOut opts (Core.disambiguateNodeNames md' node'))
embed (putStrLn "")
runRepl opts tab'

replType :: Core.InfoTable -> Core.Node -> Sem r ()
replType tab' node = do
let ty = Core.disambiguateNodeNames tab' (Core.computeNodeType tab' node)
let md' = Core.moduleFromInfoTable tab'
ty = Core.disambiguateNodeNames md' (Core.computeNodeType md' node)
renderStdOut (Core.ppOut opts ty)
embed (putStrLn "")
runRepl opts tab'
Expand Down