1
1
mirror of https://github.com/anoma/juvix.git synced 2025-01-05 22:46:08 +03:00
juvix/app/TreeEvaluator.hs
Łukasz Czajka 0073d04f89
JuvixTree evaluator (#2589)
* Implements JuvixTree evaluator
* Adds JuvixTree evaluation tests
* Adds the `juvix dev tree eval` command
* Depends on #2587 
* Depends on #2583
2024-01-25 19:11:45 +00:00

33 lines
1.0 KiB
Haskell

module TreeEvaluator where
import App
import CommonOptions
import Juvix.Compiler.Tree.Data.InfoTable qualified as Tree
import Juvix.Compiler.Tree.Error qualified as Tree
import Juvix.Compiler.Tree.Evaluator qualified as Tree
import Juvix.Compiler.Tree.Language.Value qualified as Tree
import Juvix.Compiler.Tree.Pretty qualified as Tree
evalTree :: forall r. (Members '[Embed IO, App] r) => Tree.InfoTable -> Sem r ()
evalTree tab =
case tab ^. Tree.infoMainFunction of
Just sym -> do
r <- doEval tab (Tree.lookupFunInfo tab sym)
case r of
Left err ->
exitJuvixError (JuvixError err)
Right Tree.ValVoid ->
return ()
Right val -> do
renderStdOut (Tree.ppOutDefault tab val)
putStrLn ""
Nothing ->
exitMsg (ExitFailure 1) "no 'main' function"
where
doEval ::
Tree.InfoTable ->
Tree.FunctionInfo ->
Sem r (Either Tree.TreeError Tree.Value)
doEval tab' funInfo =
embed $ Tree.catchEvalErrorIO (Tree.hEvalIO stdin stdout tab' funInfo)