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
|
2022-09-14 17:16:15 +03:00
|
|
|
import Juvix.Compiler.Core.Pretty qualified as Core
|
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
|
|
|
|
import Juvix.Compiler.Core.Translation.FromSource qualified as Core
|
|
|
|
|
2022-11-07 16:47:56 +03:00
|
|
|
runCommand :: forall r a. (Members '[Embed IO, App] r, CanonicalProjection a Eval.EvalOptions, CanonicalProjection a Core.Options, CanonicalProjection a CoreReadOptions) => a -> Sem r ()
|
2022-09-14 17:16:15 +03:00
|
|
|
runCommand opts = do
|
|
|
|
s' <- embed (readFile f)
|
2022-10-21 20:13:06 +03:00
|
|
|
(tab, mnode) <- getRight (mapLeft JuvixError (Core.runParser f Core.emptyInfoTable s'))
|
2022-11-07 16:47:56 +03:00
|
|
|
let tab' = Core.applyTransformations (project opts ^. coreReadTransformations) tab
|
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
|
|
|
|
renderStdOut (Core.ppOut opts tab')
|
2022-10-21 20:13:06 +03:00
|
|
|
whenJust mnode $ doEval tab'
|
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
|
|
|
|
| otherwise -> do
|
|
|
|
embed (putStrLn "-- Node")
|
|
|
|
renderStdOut (Core.ppOut opts node)
|
|
|
|
embed (putStrLn "")
|
2022-09-14 17:16:15 +03:00
|
|
|
f :: FilePath
|
2022-11-07 16:47:56 +03:00
|
|
|
f = project opts ^. coreReadInputFile . pathPath
|