2022-11-07 16:47:56 +03:00
|
|
|
module Evaluator where
|
|
|
|
|
|
|
|
import App
|
|
|
|
import CommonOptions
|
|
|
|
import Juvix.Compiler.Core.Data.InfoTable qualified as Core
|
|
|
|
import Juvix.Compiler.Core.Error qualified as Core
|
|
|
|
import Juvix.Compiler.Core.Evaluator qualified as Core
|
|
|
|
import Juvix.Compiler.Core.Extra.Base qualified as Core
|
2023-06-06 13:35:01 +03:00
|
|
|
import Juvix.Compiler.Core.Extra.Value qualified as Core
|
2022-11-07 16:47:56 +03:00
|
|
|
import Juvix.Compiler.Core.Info qualified as Info
|
|
|
|
import Juvix.Compiler.Core.Info.NoDisplayInfo qualified as Info
|
|
|
|
import Juvix.Compiler.Core.Language qualified as Core
|
2023-05-15 19:01:40 +03:00
|
|
|
import Juvix.Compiler.Core.Normalizer
|
2022-11-07 16:47:56 +03:00
|
|
|
import Juvix.Compiler.Core.Pretty qualified as Core
|
2023-03-15 18:41:39 +03:00
|
|
|
import Juvix.Compiler.Core.Transformation.DisambiguateNames qualified as Core
|
2022-11-07 16:47:56 +03:00
|
|
|
|
|
|
|
data EvalOptions = EvalOptions
|
2022-12-20 15:05:40 +03:00
|
|
|
{ _evalInputFile :: AppPath File,
|
2023-03-15 18:41:39 +03:00
|
|
|
_evalNoIO :: Bool,
|
2023-06-06 13:35:01 +03:00
|
|
|
_evalNoDisambiguate :: Bool,
|
|
|
|
_evalPrintValues :: Bool
|
2022-11-07 16:47:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
makeLenses ''EvalOptions
|
|
|
|
|
|
|
|
doEval ::
|
|
|
|
forall r.
|
Update CI to install Smoke, Github actions, and Makefile fixes (#1735)
This PR adds some maintenance at different levels to the CI config, the
Make file, and formatting.
- Most of the actions used by the CI related to haskell, ormolu, hlint
and pre-commit have been updated because Github requires NodeJS 16. This
change removes all the old warnings related to nodeJs.
In the case of ormolu, the new version makes us format some files that
were not formatted before, similarly with hlint.
- The CI has been updated to use the latest version of the Smoke testing
framework, which introduced installation of the dependencies for Linux
(libicu66) and macOS (icu4c) in the CI. In the case of macOS, the CI
uses a binary for smoke. For Linux, we use stack to build smoke from the
source. The source here is in a fork of [the official Smoke
repo](https://github.com/SamirTalwar/smoke). Such includes some
features/changes that are not yet in the official repo.
- The Makefile runs the ormolu and hlint targets using as a path for the
binaries the environment variables ORMOLU and HLINT. Thus, export those
variables in your environment before running `make check,` `make format`
or `make hlint`. Otherwise, the Makefile will use the binaries provided
by `stack`.
Co-authored-by: Paul Cadman <git@paulcadman.dev>
2023-01-24 13:50:23 +03:00
|
|
|
(Members '[Embed IO] r) =>
|
2022-11-07 16:47:56 +03:00
|
|
|
Bool ->
|
|
|
|
Interval ->
|
|
|
|
Core.InfoTable ->
|
|
|
|
Core.Node ->
|
|
|
|
Sem r (Either Core.CoreError Core.Node)
|
|
|
|
doEval noIO loc tab node
|
2023-03-20 15:01:35 +03:00
|
|
|
| noIO = embed $ Core.catchEvalError loc (Core.eval stderr (tab ^. Core.identContext) [] node)
|
2022-11-07 16:47:56 +03:00
|
|
|
| otherwise = embed $ Core.catchEvalErrorIO loc (Core.evalIO (tab ^. Core.identContext) [] node)
|
|
|
|
|
|
|
|
doEvalIO ::
|
|
|
|
Bool ->
|
|
|
|
Interval ->
|
|
|
|
Core.InfoTable ->
|
|
|
|
Core.Node ->
|
|
|
|
IO (Either Core.CoreError Core.Node)
|
|
|
|
doEvalIO noIO i tab node = runM (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
|
2023-01-26 12:14:06 +03:00
|
|
|
loc <- defaultLoc
|
|
|
|
r <- doEval (project opts ^. evalNoIO) loc tab node
|
2022-11-07 16:47:56 +03:00
|
|
|
case r of
|
|
|
|
Left err -> exitJuvixError (JuvixError err)
|
|
|
|
Right node'
|
|
|
|
| Info.member Info.kNoDisplayInfo (Core.getInfo node') ->
|
|
|
|
return ()
|
2023-06-06 13:35:01 +03:00
|
|
|
Right node'
|
|
|
|
| project opts ^. evalPrintValues -> do
|
|
|
|
renderStdOut (Core.ppOut opts (Core.toValue tab node'))
|
|
|
|
newline
|
|
|
|
| otherwise -> do
|
|
|
|
renderStdOut (Core.ppOut opts node'')
|
|
|
|
newline
|
2023-03-15 18:41:39 +03:00
|
|
|
where
|
|
|
|
node'' = if project opts ^. evalNoDisambiguate then node' else Core.disambiguateNodeNames tab node'
|
2022-11-07 16:47:56 +03:00
|
|
|
where
|
2023-01-26 12:14:06 +03:00
|
|
|
defaultLoc :: Sem r Interval
|
2023-04-19 17:56:48 +03:00
|
|
|
defaultLoc = singletonInterval . mkInitialLoc <$> fromAppPathFile f
|
|
|
|
f :: AppPath File
|
|
|
|
f = project opts ^. evalInputFile
|
2023-05-15 19:01:40 +03:00
|
|
|
|
|
|
|
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 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 tab node'
|
|
|
|
renderStdOut (Core.ppOut opts node'')
|
|
|
|
embed (putStrLn "")
|