mirror of
https://github.com/anoma/juvix.git
synced 2024-12-19 04:41:36 +03:00
75bce8f665
* Closes #2392 Changes checklist ----------------- * [X] Abstract out data types for stored module representation (`ModuleInfo` in `Juvix.Compiler.Store.Language`) * [X] Adapt the parser to operate per-module * [X] Adapt the scoper to operate per-module * [X] Adapt the arity checker to operate per-module * [X] Adapt the type checker to operate per-module * [x] Adapt Core transformations to operate per-module * [X] Adapt the pipeline functions in `Juvix.Compiler.Pipeline` * [X] Add `Juvix.Compiler.Pipeline.Driver` which drives the per-module compilation process * [x] Implement module saving / loading in `Pipeline.Driver` * [x] Detect cyclic module dependencies in `Pipeline.Driver` * [x] Cache visited modules in memory in `Pipeline.Driver` to avoid excessive disk operations and repeated hash re-computations * [x] Recompile a module if one of its dependencies needs recompilation and contains functions that are always inlined. * [x] Fix identifier dependencies for mutual block creation in `Internal.fromConcrete` - Fixed by making textually later definitions depend on earlier ones. - Now instances are used for resolution only after the textual point of their definition. - Similarly, type synonyms will be unfolded only after the textual point of their definition. * [x] Fix CLI * [x] Fix REPL * [x] Fix highlighting * [x] Fix HTML generation * [x] Adapt test suite
76 lines
2.4 KiB
Haskell
76 lines
2.4 KiB
Haskell
module Evaluator where
|
|
|
|
import App
|
|
import CommonOptions
|
|
import Juvix.Compiler.Core qualified as Core
|
|
import Juvix.Compiler.Core.Extra.Value qualified as Core
|
|
import Juvix.Compiler.Core.Info qualified as Info
|
|
import Juvix.Compiler.Core.Info.NoDisplayInfo qualified as Info
|
|
import Juvix.Compiler.Core.Normalizer
|
|
import Juvix.Compiler.Core.Pretty qualified as Core
|
|
import Juvix.Compiler.Core.Transformation.DisambiguateNames qualified as Core
|
|
|
|
data EvalOptions = EvalOptions
|
|
{ _evalInputFile :: AppPath File,
|
|
_evalNoIO :: Bool,
|
|
_evalNoDisambiguate :: Bool,
|
|
_evalPrintValues :: Bool
|
|
}
|
|
|
|
makeLenses ''EvalOptions
|
|
|
|
doEvalIO ::
|
|
Bool ->
|
|
Interval ->
|
|
Core.InfoTable ->
|
|
Core.Node ->
|
|
IO (Either Core.CoreError Core.Node)
|
|
doEvalIO noIO i tab node = runM (Core.doEval noIO i tab node)
|
|
|
|
evalAndPrint ::
|
|
forall r a.
|
|
(Members '[Embed IO, App] r, CanonicalProjection a EvalOptions, CanonicalProjection a Core.Options) =>
|
|
a ->
|
|
Core.InfoTable ->
|
|
Core.Node ->
|
|
Sem r ()
|
|
evalAndPrint opts tab node = do
|
|
loc <- defaultLoc
|
|
r <- Core.doEval (project opts ^. evalNoIO) loc tab node
|
|
case r of
|
|
Left err -> exitJuvixError (JuvixError err)
|
|
Right node'
|
|
| Info.member Info.kNoDisplayInfo (Core.getInfo node') ->
|
|
return ()
|
|
Right node'
|
|
| project opts ^. evalPrintValues -> do
|
|
renderStdOut (Core.ppOut opts (Core.toValue tab node'))
|
|
newline
|
|
| otherwise -> do
|
|
renderStdOut (Core.ppOut opts node'')
|
|
newline
|
|
where
|
|
node'' = if project opts ^. evalNoDisambiguate then node' else Core.disambiguateNodeNames (Core.moduleFromInfoTable tab) node'
|
|
where
|
|
defaultLoc :: Sem r Interval
|
|
defaultLoc = singletonInterval . mkInitialLoc <$> fromAppPathFile f
|
|
f :: AppPath File
|
|
f = project opts ^. evalInputFile
|
|
|
|
normalizeAndPrint ::
|
|
forall r a.
|
|
(Members '[Embed IO, App] r, CanonicalProjection a EvalOptions, CanonicalProjection a Core.Options) =>
|
|
a ->
|
|
Core.InfoTable ->
|
|
Core.Node ->
|
|
Sem r ()
|
|
normalizeAndPrint opts tab node =
|
|
let node' = normalize (Core.moduleFromInfoTable tab) node
|
|
in if
|
|
| Info.member Info.kNoDisplayInfo (Core.getInfo node') ->
|
|
return ()
|
|
| otherwise -> do
|
|
let node'' = if project opts ^. evalNoDisambiguate then node' else Core.disambiguateNodeNames (Core.moduleFromInfoTable tab) node'
|
|
renderStdOut (Core.ppOut opts node'')
|
|
embed (putStrLn "")
|