2022-09-14 17:16:15 +03:00
|
|
|
module Commands.Dev.Core.Read where
|
|
|
|
|
|
|
|
import Commands.Base
|
|
|
|
import Commands.Dev.Core.Read.Options
|
2022-11-07 16:47:56 +03:00
|
|
|
import Evaluator qualified as Eval
|
2023-03-27 11:42:27 +03:00
|
|
|
import Juvix.Compiler.Core.Options qualified as Core
|
|
|
|
import Juvix.Compiler.Core.Pretty qualified as Pretty
|
2022-10-21 20:13:06 +03:00
|
|
|
import Juvix.Compiler.Core.Scoper qualified as Scoper
|
2022-09-14 17:16:15 +03:00
|
|
|
import Juvix.Compiler.Core.Transformation qualified as Core
|
2023-03-15 18:41:39 +03:00
|
|
|
import Juvix.Compiler.Core.Transformation.DisambiguateNames qualified as Core
|
2022-09-14 17:16:15 +03:00
|
|
|
import Juvix.Compiler.Core.Translation.FromSource qualified as Core
|
|
|
|
|
2023-02-22 17:27:40 +03:00
|
|
|
runCommand ::
|
|
|
|
forall r a.
|
|
|
|
( Members '[Embed IO, App] r,
|
|
|
|
CanonicalProjection a Eval.EvalOptions,
|
2023-03-27 11:42:27 +03:00
|
|
|
CanonicalProjection a Pretty.Options,
|
2023-02-22 17:27:40 +03:00
|
|
|
CanonicalProjection a CoreReadOptions
|
|
|
|
) =>
|
|
|
|
a ->
|
|
|
|
Sem r ()
|
2022-09-14 17:16:15 +03:00
|
|
|
runCommand opts = do
|
2023-03-27 11:42:27 +03:00
|
|
|
gopts <- askGlobalOptions
|
2023-04-19 17:56:48 +03:00
|
|
|
inputFile :: Path Abs File <- fromAppPathFile sinputFile
|
2022-12-20 15:05:40 +03:00
|
|
|
s' <- embed . readFile . toFilePath $ inputFile
|
2023-01-26 14:55:06 +03:00
|
|
|
tab <- getRight (mapLeft JuvixError (Core.runParserMain inputFile Core.emptyInfoTable s'))
|
2023-03-27 11:42:27 +03:00
|
|
|
let r = run $ runReader (project @GlobalOptions @Core.CoreOptions gopts) $ runError @JuvixError $ Core.applyTransformations (project opts ^. coreReadTransformations) tab
|
2023-03-20 12:13:07 +03:00
|
|
|
tab0 <- getRight $ mapLeft JuvixError r
|
|
|
|
let tab' = if project opts ^. coreReadNoDisambiguate then tab0 else Core.disambiguateNames tab0
|
2022-10-21 20:13:06 +03:00
|
|
|
embed (Scoper.scopeTrace tab')
|
2022-12-12 16:58:25 +03:00
|
|
|
unless (project opts ^. coreReadNoPrint) $ do
|
2023-03-27 11:42:27 +03:00
|
|
|
renderStdOut (Pretty.ppOut opts tab')
|
2023-01-09 20:21:30 +03:00
|
|
|
whenJust (tab' ^. Core.infoMain) $ \sym -> doEval tab' (fromJust $ tab' ^. Core.identContext . at sym)
|
2022-09-14 17:16:15 +03:00
|
|
|
where
|
2022-10-21 20:13:06 +03:00
|
|
|
doEval :: Core.InfoTable -> Core.Node -> Sem r ()
|
2022-12-12 16:58:25 +03:00
|
|
|
doEval tab' node =
|
|
|
|
if
|
|
|
|
| project opts ^. coreReadEval -> do
|
|
|
|
embed (putStrLn "--------------------------------")
|
|
|
|
embed (putStrLn "| Eval |")
|
|
|
|
embed (putStrLn "--------------------------------")
|
|
|
|
Eval.evalAndPrint opts tab' node
|
2023-05-15 19:01:40 +03:00
|
|
|
| project opts ^. coreReadNormalize -> do
|
|
|
|
embed (putStrLn "--------------------------------")
|
|
|
|
embed (putStrLn "| Normalize |")
|
|
|
|
embed (putStrLn "--------------------------------")
|
|
|
|
Eval.normalizeAndPrint opts tab' node
|
2023-01-09 20:21:30 +03:00
|
|
|
| otherwise -> return ()
|
2023-04-19 17:56:48 +03:00
|
|
|
sinputFile :: AppPath File
|
|
|
|
sinputFile = project opts ^. coreReadInputFile
|