1
1
mirror of https://github.com/anoma/juvix.git synced 2024-12-15 18:13:56 +03:00
juvix/app/Commands/Eval.hs
Jonathan Cubides 9f22eaa1cf
Test core to geb translation (#1865)
This PR adds testing for the core-to-geb translation.
It works as follows:

  1. Parse the Juvix Core file.
  2. Prepare the Juvix Core node for translation to Geb.
  3. Translate the Juvix Core node to Geb.
5. Perform type checking on the translated Geb node to ensure that the
types
from the core node make sense in the Geb context and avoid any Geb
runtime
     errors.
6. Evaluate the Juvix Core node to see if it produces the expected
result.
7. Translate the result of the evaluated Juvix Core node to Geb for
comparison
     with the expected output later.
8. Compare the result of the evaluation of the Geb term produced in step
3
with the result of the evaluation of the Geb term produced in step 6 to
     ensure consistency.
9. If step 8 succeeds, then compare the output of step 6 (the evaluation
of the core
     node) with the expected output (given in Geb format) to ensure that
     the program is functioning as intended.

This PR goes after:

- https://github.com/anoma/juvix/pull/1863
and
https://github.com/anoma/juvix/pull/1832
2023-03-27 15:32:03 +02:00

42 lines
1.4 KiB
Haskell

module Commands.Eval where
import Commands.Base
import Commands.Eval.Options
import Evaluator qualified as Eval
import Juvix.Compiler.Core qualified as Core
runCommand :: (Members '[Embed IO, App] r) => EvalOptions -> Sem r ()
runCommand opts@EvalOptions {..} = do
gopts <- askGlobalOptions
Core.CoreResult {..} <- runPipeline _evalInputFile upToCore
let r =
run $
runReader (project gopts) $
runError @JuvixError $
(Core.toEval' _coreResultTable :: Sem '[Error JuvixError, Reader Core.CoreOptions] Core.InfoTable)
tab <- getRight r
let evalNode =
if
| isJust (_evalSymbolName) -> getNode' tab (selInfo tab)
| otherwise -> getNode' tab (mainInfo tab)
Eval.evalAndPrint opts tab evalNode
where
mainInfo :: Core.InfoTable -> Maybe Core.IdentifierInfo
mainInfo tab = do
s <- tab ^. Core.infoMain
tab ^. Core.infoIdentifiers . at s
selInfo :: Core.InfoTable -> Maybe Core.IdentifierInfo
selInfo tab = do
s <- _evalSymbolName
find (^. Core.identifierName . to (== s)) (tab ^. Core.infoIdentifiers)
getNode' :: Core.InfoTable -> Maybe Core.IdentifierInfo -> Core.Node
getNode' tab m = fromMaybe err (getNode tab m)
getNode :: Core.InfoTable -> Maybe Core.IdentifierInfo -> Maybe Core.Node
getNode tab m = m >>= \i -> tab ^. Core.identContext . at (i ^. Core.identifierSymbol)
err :: a
err = error "function not found"