1
1
mirror of https://github.com/anoma/juvix.git synced 2024-12-22 06:11:36 +03:00
juvix/app/Commands/Dev/Core/Read.hs
2022-11-07 14:47:56 +01:00

28 lines
1.3 KiB
Haskell

module Commands.Dev.Core.Read where
import Commands.Base
import Commands.Dev.Core.Read.Options
import Evaluator qualified as Eval
import Juvix.Compiler.Core.Pretty qualified as Core
import Juvix.Compiler.Core.Scoper qualified as Scoper
import Juvix.Compiler.Core.Transformation qualified as Core
import Juvix.Compiler.Core.Translation.FromSource qualified as Core
runCommand :: forall r a. (Members '[Embed IO, App] r, CanonicalProjection a Eval.EvalOptions, CanonicalProjection a Core.Options, CanonicalProjection a CoreReadOptions) => a -> Sem r ()
runCommand opts = do
s' <- embed (readFile f)
(tab, mnode) <- getRight (mapLeft JuvixError (Core.runParser f Core.emptyInfoTable s'))
let tab' = Core.applyTransformations (project opts ^. coreReadTransformations) tab
embed (Scoper.scopeTrace tab')
unless (project opts ^. coreReadNoPrint) (renderStdOut (Core.ppOut opts tab'))
whenJust mnode $ doEval tab'
where
doEval :: Core.InfoTable -> Core.Node -> Sem r ()
doEval tab' node = when (project opts ^. coreReadEval) $ do
embed (putStrLn "--------------------------------")
embed (putStrLn "| Eval |")
embed (putStrLn "--------------------------------")
Eval.evalAndPrint opts tab' node
f :: FilePath
f = project opts ^. coreReadInputFile . pathPath