1
1
mirror of https://github.com/anoma/juvix.git synced 2024-12-14 17:32:00 +03:00
juvix/test/Core/VampIR/Base.hs
Łukasz Czajka d576111241
VampIR integration (#2103)
* Closes #2035 
* Depends on #2086 
* Depends on #2096 
* Adds end-to-end tests for the Juvix-to-VampIR compilation pipeline.

---------

Co-authored-by: Jonathan Cubides <jonathan.cubides@uib.no>
2023-05-22 20:18:18 +02:00

46 lines
1.5 KiB
Haskell

module Core.VampIR.Base where
import Base
import Core.Eval.Base
import Juvix.Compiler.Core.Options
import Juvix.Compiler.Core.Pretty
import Juvix.Compiler.Core.Transformation
import Juvix.Compiler.Core.Transformation.LetHoisting (isLetHoisted)
import Juvix.Compiler.Core.Translation.FromSource
coreVampIRAssertion ::
[TransformationId] ->
Path Abs File ->
Path Abs File ->
(String -> IO ()) ->
Assertion
coreVampIRAssertion transforms mainFile expectedFile step = do
step "Parse"
r <- parseFile mainFile
case r of
Left err -> assertFailure (show (pretty err))
Right (_, Nothing) -> assertFailure "Empty program"
Right (tabIni, Just node) -> do
coreVampIRAssertion' (setupMainFunction tabIni node) transforms mainFile expectedFile step
coreVampIRAssertion' ::
InfoTable ->
[TransformationId] ->
Path Abs File ->
Path Abs File ->
(String -> IO ()) ->
Assertion
coreVampIRAssertion' tab transforms mainFile expectedFile step = do
step "Transform and normalize"
case run . runReader defaultCoreOptions . runError @JuvixError $
applyTransformations transforms tab of
Left err -> assertFailure (show (pretty (fromJuvixError @GenericError err)))
Right tab' -> do
step "Check let-hoisted"
walkT checkHoisted tab'
coreEvalAssertion' EvalModeJSON tab' mainFile expectedFile step
where
checkHoisted :: Symbol -> Node -> IO ()
checkHoisted s n =
unless (isLetHoisted n) (assertFailure $ "node not hoisted: " <> show s)