1
1
mirror of https://github.com/anoma/juvix.git synced 2024-12-12 14:28:08 +03:00
juvix/test/Core/VampIR/Base.hs
Jan Mas Rovira e0ae356cd7
Use prettyString instead of show . pretty (#2711)
Use `prettyString` instead of relying on `Show` instance for `Doc a` so
that it is more consistent with `prettyText`.
2024-04-12 10:26:54 +02:00

47 lines
1.6 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 (prettyString err)
Right (_, Nothing) -> assertFailure "Empty program"
Right (tabIni, Just node) -> do
coreVampIRAssertion' (setupMainFunction defaultModuleId 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 (moduleFromInfoTable tab) of
Left err -> assertFailure (prettyString (fromJuvixError @GenericError err))
Right m -> do
let tab' = computeCombinedInfoTable m
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)