mirror of
https://github.com/anoma/juvix.git
synced 2024-10-05 20:47:36 +03:00
parent
802d82f22e
commit
69a12d0c2f
@ -6,17 +6,19 @@ import Juvix.Compiler.Core qualified as Core
|
||||
import Juvix.Compiler.Core.Pretty qualified as Core
|
||||
import Juvix.Compiler.Core.Translation.Stripped.FromCore qualified as Stripped
|
||||
|
||||
runCommand :: forall r a. (Members '[EmbedIO, App] r, CanonicalProjection a Core.Options, CanonicalProjection a CoreStripOptions) => a -> Sem r ()
|
||||
runCommand :: forall r a. (Members '[EmbedIO, TaggedLock, App] r, CanonicalProjection a Core.Options, CanonicalProjection a CoreStripOptions) => a -> Sem r ()
|
||||
runCommand opts = do
|
||||
root <- askRoot
|
||||
gopts <- askGlobalOptions
|
||||
inputFile :: Path Abs File <- fromAppPathFile sinputFile
|
||||
ep <- entryPointFromGlobalOptions root inputFile gopts
|
||||
s' <- readFile inputFile
|
||||
(tab, _) <- getRight (Core.runParser inputFile defaultModuleId mempty s')
|
||||
let r =
|
||||
run
|
||||
. runReader (project' @Core.CoreOptions gopts)
|
||||
. runReader ep
|
||||
. runError @JuvixError
|
||||
$ Core.toStripped' Core.IdentityTrans (Core.moduleFromInfoTable tab)
|
||||
$ Core.toStripped Core.IdentityTrans (Core.moduleFromInfoTable tab)
|
||||
tab' <- getRight $ mapRight (Stripped.fromCore (project gopts ^. Core.optFieldSize) . Core.computeCombinedInfoTable) r
|
||||
unless (project opts ^. coreStripNoPrint) $ do
|
||||
renderStdOut (Core.ppOut opts tab')
|
||||
|
@ -9,12 +9,14 @@ import Juvix.Extra.Strings qualified as Str
|
||||
runCommand :: (Members '[EmbedIO, TaggedLock, App] r) => EvalOptions -> Sem r ()
|
||||
runCommand opts@EvalOptions {..} = do
|
||||
gopts <- askGlobalOptions
|
||||
root <- askRoot
|
||||
entryPoint <- maybe (entryPointFromGlobalOptionsNoFile root gopts) (fromAppPathFile >=> \f -> entryPointFromGlobalOptions root f gopts) _evalInputFile
|
||||
Core.CoreResult {..} <- ignoreProgressLog (runPipelineProgress () _evalInputFile upToCore)
|
||||
let r =
|
||||
run
|
||||
. runReader (project gopts)
|
||||
. runReader entryPoint
|
||||
. runError @JuvixError
|
||||
$ (Core.toStored' _coreResultModule :: Sem '[Error JuvixError, Reader Core.CoreOptions] Core.Module)
|
||||
$ (Core.toStored _coreResultModule :: Sem '[Error JuvixError, Reader EntryPoint] Core.Module)
|
||||
tab <- Core.computeCombinedInfoTable <$> getRight r
|
||||
let mevalNode
|
||||
| isJust _evalSymbolName = getNode tab (selInfo tab)
|
||||
|
@ -14,16 +14,16 @@ import Juvix.Prelude
|
||||
|
||||
-- | Perform transformations on JuvixAsm necessary before the translation to
|
||||
-- JuvixReg
|
||||
toReg' :: (Members '[Error AsmError, Reader Options] r) => InfoTable -> Sem r InfoTable
|
||||
toReg' = validate >=> filterUnreachable >=> computeStackUsage >=> computePrealloc
|
||||
toReg :: (Members '[Error JuvixError, Reader EntryPoint] r) => InfoTable -> Sem r InfoTable
|
||||
toReg = mapReader fromEntryPoint . mapError (JuvixError @AsmError) . toReg'
|
||||
where
|
||||
toReg' :: (Members '[Error AsmError, Reader Options] r) => InfoTable -> Sem r InfoTable
|
||||
toReg' = validate >=> filterUnreachable >=> computeStackUsage >=> computePrealloc
|
||||
|
||||
-- | Perform transformations on JuvixAsm necessary before the translation to
|
||||
-- Nockma
|
||||
toNockma' :: (Members '[Error AsmError, Reader Options] r) => InfoTable -> Sem r InfoTable
|
||||
toNockma' = validate
|
||||
|
||||
toReg :: (Members '[Error JuvixError, Reader EntryPoint] r) => InfoTable -> Sem r InfoTable
|
||||
toReg = mapReader fromEntryPoint . mapError (JuvixError @AsmError) . toReg'
|
||||
|
||||
toNockma :: (Members '[Error JuvixError, Reader EntryPoint] r) => InfoTable -> Sem r InfoTable
|
||||
toNockma = mapReader fromEntryPoint . mapError (JuvixError @AsmError) . toNockma'
|
||||
where
|
||||
toNockma' :: (Members '[Error AsmError, Reader Options] r) => InfoTable -> Sem r InfoTable
|
||||
toNockma' = validate
|
||||
|
@ -24,6 +24,3 @@ fromCore :: (Member (Reader EntryPoint) r) => InfoTable -> Sem r Result
|
||||
fromCore tab = do
|
||||
unsafe <- asks (^. entryPointUnsafe)
|
||||
return $ toResult unsafe $ VampIR.fromCore tab
|
||||
|
||||
fromCore' :: Bool -> InfoTable -> Result
|
||||
fromCore' unsafe = toResult unsafe . VampIR.fromCore
|
||||
|
@ -10,8 +10,8 @@ import Juvix.Compiler.Pipeline.EntryPoint (EntryPoint)
|
||||
|
||||
-- | Perform transformations on CASM necessary before the translation to Cairo
|
||||
-- bytecode
|
||||
toCairo' :: Code -> Sem r Code
|
||||
toCairo' = applyTransformations toCairoTransformations
|
||||
|
||||
toCairo :: (Member (Reader EntryPoint) r) => Code -> Sem r Code
|
||||
toCairo = mapReader fromEntryPoint . toCairo'
|
||||
where
|
||||
toCairo' :: Code -> Sem r Code
|
||||
toCairo' = applyTransformations toCairoTransformations
|
||||
|
@ -9,34 +9,22 @@ import Juvix.Compiler.Core.Options
|
||||
import Juvix.Compiler.Core.Transformation
|
||||
import Juvix.Compiler.Pipeline.EntryPoint (EntryPoint)
|
||||
|
||||
-- | Perform transformations on Core necessary for storage
|
||||
toStored' :: (Members '[Error JuvixError, Reader CoreOptions] r) => Module -> Sem r Module
|
||||
toStored' = applyTransformations toStoredTransformations
|
||||
|
||||
toTypechecked :: (Members '[Error JuvixError, Reader EntryPoint] r) => Module -> Sem r Module
|
||||
toTypechecked = mapReader fromEntryPoint . applyTransformations toTypecheckTransformations
|
||||
|
||||
-- | Perform transformations on Core necessary for storage
|
||||
toStored :: (Members '[Error JuvixError, Reader EntryPoint] r) => Module -> Sem r Module
|
||||
toStored = mapReader fromEntryPoint . applyTransformations toStoredTransformations
|
||||
|
||||
-- | Perform transformations on stored Core necessary before the translation to
|
||||
-- Core.Stripped
|
||||
toStripped' :: (Members '[Error JuvixError, Reader CoreOptions] r) => TransformationId -> Module -> Sem r Module
|
||||
toStripped' checkId = applyTransformations (toStrippedTransformations checkId)
|
||||
|
||||
toStripped :: (Members '[Error JuvixError, Reader EntryPoint] r) => TransformationId -> Module -> Sem r Module
|
||||
toStripped checkId = mapReader fromEntryPoint . applyTransformations (toStrippedTransformations checkId)
|
||||
|
||||
-- | Perform transformations on stored Core necessary before the translation to GEB
|
||||
toGeb' :: (Members '[Error JuvixError, Reader CoreOptions] r) => Module -> Sem r Module
|
||||
toGeb' = applyTransformations toGebTransformations
|
||||
|
||||
toGeb :: (Members '[Error JuvixError, Reader EntryPoint] r) => Module -> Sem r Module
|
||||
toGeb = mapReader fromEntryPoint . applyTransformations toGebTransformations
|
||||
|
||||
-- | Perform transformations on stored Core necessary before the translation to VampIR
|
||||
toVampIR' :: (Members '[Error JuvixError, Reader CoreOptions] r) => Module -> Sem r Module
|
||||
toVampIR' = applyTransformations toVampIRTransformations
|
||||
|
||||
toVampIR :: (Members '[Error JuvixError, Reader EntryPoint] r) => Module -> Sem r Module
|
||||
toVampIR = mapReader fromEntryPoint . applyTransformations toVampIRTransformations
|
||||
|
@ -9,8 +9,6 @@ module Juvix.Compiler.Pipeline
|
||||
where
|
||||
|
||||
import Data.List.Singletons (type (++))
|
||||
import Juvix.Compiler.Asm.Error qualified as Asm
|
||||
import Juvix.Compiler.Asm.Options qualified as Asm
|
||||
import Juvix.Compiler.Asm.Pipeline qualified as Asm
|
||||
import Juvix.Compiler.Asm.Translation.FromTree qualified as Asm
|
||||
import Juvix.Compiler.Backend qualified as Backend
|
||||
@ -261,9 +259,6 @@ storedCoreToGeb spec = Core.toGeb >=> return . uncurry (Geb.toResult spec) . Geb
|
||||
storedCoreToVampIR :: (Members '[Error JuvixError, Reader EntryPoint] r) => Core.Module -> Sem r VampIR.Result
|
||||
storedCoreToVampIR = Core.toVampIR >=> VampIR.fromCore . Core.computeCombinedInfoTable
|
||||
|
||||
storedCoreToVampIR' :: (Members '[Error JuvixError, Reader Core.CoreOptions] r) => Core.Module -> Sem r VampIR.Result
|
||||
storedCoreToVampIR' = Core.toVampIR' >=> return . VampIR.fromCore' False . Core.computeCombinedInfoTable
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
-- Workflows from Core
|
||||
--------------------------------------------------------------------------------
|
||||
@ -301,9 +296,6 @@ coreToGeb spec = Core.toStored >=> storedCoreToGeb spec
|
||||
coreToVampIR :: (Members '[Error JuvixError, Reader EntryPoint] r) => Core.Module -> Sem r VampIR.Result
|
||||
coreToVampIR = Core.toStored >=> storedCoreToVampIR
|
||||
|
||||
coreToVampIR' :: (Members '[Error JuvixError, Reader Core.CoreOptions] r) => Core.Module -> Sem r VampIR.Result
|
||||
coreToVampIR' = Core.toStored' >=> storedCoreToVampIR'
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
-- Other workflows
|
||||
--------------------------------------------------------------------------------
|
||||
@ -362,9 +354,6 @@ regToRiscZeroRust = regToRust' Rust.BackendRiscZero
|
||||
regToCasm :: (Member (Reader EntryPoint) r) => Reg.InfoTable -> Sem r Casm.Result
|
||||
regToCasm = Reg.toCasm >=> return . Casm.fromReg
|
||||
|
||||
regToCasm' :: (Member (Reader Reg.Options) r) => Reg.InfoTable -> Sem r Casm.Result
|
||||
regToCasm' = Reg.toCasm' >=> return . Casm.fromReg
|
||||
|
||||
casmToCairo :: (Member (Reader EntryPoint) r) => Casm.Result -> Sem r Cairo.Result
|
||||
casmToCairo Casm.Result {..} = do
|
||||
code' <- Casm.toCairo _resultCode
|
||||
@ -372,27 +361,5 @@ casmToCairo Casm.Result {..} = do
|
||||
. Cairo.serialize _resultOutputSize (map Casm.builtinName _resultBuiltins)
|
||||
$ Cairo.fromCasm code'
|
||||
|
||||
casmToCairo' :: Casm.Result -> Sem r Cairo.Result
|
||||
casmToCairo' Casm.Result {..} = do
|
||||
code' <- Casm.toCairo' _resultCode
|
||||
return
|
||||
. Cairo.serialize _resultOutputSize (map Casm.builtinName _resultBuiltins)
|
||||
$ Cairo.fromCasm code'
|
||||
|
||||
regToCairo :: (Member (Reader EntryPoint) r) => Reg.InfoTable -> Sem r Cairo.Result
|
||||
regToCairo = regToCasm >=> casmToCairo
|
||||
|
||||
regToCairo' :: (Member (Reader Reg.Options) r) => Reg.InfoTable -> Sem r Cairo.Result
|
||||
regToCairo' = regToCasm' >=> casmToCairo'
|
||||
|
||||
treeToAnoma' :: (Members '[Error JuvixError, Reader NockmaTree.CompilerOptions] r) => Tree.InfoTable -> Sem r NockmaTree.AnomaResult
|
||||
treeToAnoma' = Tree.toNockma >=> NockmaTree.fromTreeTable
|
||||
|
||||
asmToMiniC' :: (Members '[Error JuvixError, Reader Asm.Options] r) => Asm.InfoTable -> Sem r C.MiniCResult
|
||||
asmToMiniC' = mapError (JuvixError @Asm.AsmError) . Asm.toReg' >=> regToMiniC' . Reg.fromAsm
|
||||
|
||||
regToMiniC' :: (Member (Reader Asm.Options) r) => Reg.InfoTable -> Sem r C.MiniCResult
|
||||
regToMiniC' tab = do
|
||||
tab' <- mapReader (^. Asm.optTreeOptions) $ Reg.toC' tab
|
||||
e <- ask
|
||||
return $ C.fromReg (e ^. Asm.optLimits) tab'
|
||||
|
@ -13,25 +13,25 @@ import Juvix.Compiler.Reg.Transformation.Blocks.Liveness qualified as Blocks
|
||||
import Juvix.Compiler.Reg.Translation.Blocks.FromReg qualified as Blocks
|
||||
|
||||
-- | Perform transformations on JuvixReg necessary before the translation to C
|
||||
toC' :: (Member (Reader Options) r) => InfoTable -> Sem r InfoTable
|
||||
toC' = applyTransformations toCTransformations
|
||||
toC :: (Member (Reader EntryPoint) r) => InfoTable -> Sem r InfoTable
|
||||
toC = mapReader fromEntryPoint . toC'
|
||||
where
|
||||
toC' :: (Member (Reader Options) r) => InfoTable -> Sem r InfoTable
|
||||
toC' = applyTransformations toCTransformations
|
||||
|
||||
-- | Perform transformations on JuvixReg necessary before the translation to Rust
|
||||
toRust' :: (Member (Reader Options) r) => InfoTable -> Sem r InfoTable
|
||||
toRust' = applyTransformations toRustTransformations
|
||||
toRust :: (Member (Reader EntryPoint) r) => InfoTable -> Sem r InfoTable
|
||||
toRust = mapReader fromEntryPoint . toRust'
|
||||
where
|
||||
toRust' :: (Member (Reader Options) r) => InfoTable -> Sem r InfoTable
|
||||
toRust' = applyTransformations toRustTransformations
|
||||
|
||||
-- | Perform transformations on JuvixReg necessary before the translation to
|
||||
-- Cairo assembly
|
||||
toCasm' :: (Member (Reader Options) r) => InfoTable -> Sem r Blocks.InfoTable
|
||||
toCasm' =
|
||||
applyTransformations toCasmTransformations
|
||||
>=> return . Blocks.computeLiveness . Blocks.fromReg
|
||||
|
||||
toC :: (Member (Reader EntryPoint) r) => InfoTable -> Sem r InfoTable
|
||||
toC = mapReader fromEntryPoint . toC'
|
||||
|
||||
toRust :: (Member (Reader EntryPoint) r) => InfoTable -> Sem r InfoTable
|
||||
toRust = mapReader fromEntryPoint . toRust'
|
||||
|
||||
toCasm :: (Member (Reader EntryPoint) r) => InfoTable -> Sem r Blocks.InfoTable
|
||||
toCasm = mapReader fromEntryPoint . toCasm'
|
||||
where
|
||||
toCasm' :: (Member (Reader Options) r) => InfoTable -> Sem r Blocks.InfoTable
|
||||
toCasm' =
|
||||
applyTransformations toCasmTransformations
|
||||
>=> return . Blocks.computeLiveness . Blocks.fromReg
|
||||
|
@ -5,15 +5,14 @@ import Juvix.Compiler.Asm.Data.InfoTable
|
||||
import Juvix.Compiler.Asm.Error
|
||||
import Juvix.Compiler.Asm.Options
|
||||
import Juvix.Compiler.Asm.Translation.FromSource
|
||||
import Juvix.Compiler.Backend qualified as Backend
|
||||
import Juvix.Compiler.Backend.C qualified as C
|
||||
import Juvix.Compiler.Pipeline qualified as Pipeline
|
||||
import Runtime.Base qualified as Runtime
|
||||
|
||||
asmCompileAssertion' :: Int -> InfoTable -> Path Abs File -> Path Abs File -> Text -> (String -> IO ()) -> Assertion
|
||||
asmCompileAssertion' optLevel tab mainFile expectedFile stdinText step = do
|
||||
asmCompileAssertion' :: EntryPoint -> Int -> InfoTable -> Path Abs File -> Path Abs File -> Text -> (String -> IO ()) -> Assertion
|
||||
asmCompileAssertion' entryPoint optLevel tab mainFile expectedFile stdinText step = do
|
||||
step "Generate C code"
|
||||
case run $ runReader asmOpts $ runError @JuvixError $ Pipeline.asmToMiniC' tab of
|
||||
case run $ runReader entryPoint' $ runError @JuvixError $ Pipeline.asmToMiniC tab of
|
||||
Left e -> do
|
||||
let err :: AsmError = fromJust (fromJuvixError e)
|
||||
assertFailure ("code generation failed:" <> "\n" <> unpack (err ^. asmErrorMsg))
|
||||
@ -29,13 +28,20 @@ asmCompileAssertion' optLevel tab mainFile expectedFile stdinText step = do
|
||||
-- the actual target, and C code will then need to be re-generated for each
|
||||
-- target separately. Now this works only because those limits that
|
||||
-- Prealloc.hs uses are the same for the Native64 and Wasm32 targets.
|
||||
asmOpts :: Options
|
||||
asmOpts = makeOptions Backend.TargetCNative64 True
|
||||
entryPoint' :: EntryPoint
|
||||
entryPoint' =
|
||||
entryPoint
|
||||
{ _entryPointDebug = True,
|
||||
_entryPointTarget = Just TargetCNative64,
|
||||
_entryPointOptimizationLevel = optLevel
|
||||
}
|
||||
|
||||
asmCompileAssertion :: Path Abs File -> Path Abs File -> Text -> (String -> IO ()) -> Assertion
|
||||
asmCompileAssertion mainFile expectedFile stdinText step = do
|
||||
asmCompileAssertion :: Path Abs Dir -> Path Abs File -> Path Abs File -> Text -> (String -> IO ()) -> Assertion
|
||||
asmCompileAssertion root' mainFile expectedFile stdinText step = do
|
||||
step "Parse"
|
||||
s <- readFile mainFile
|
||||
case runParser mainFile s of
|
||||
Left err -> assertFailure (show err)
|
||||
Right tab -> asmCompileAssertion' 3 tab mainFile expectedFile stdinText step
|
||||
Right tab -> do
|
||||
entryPoint <- testDefaultEntryPointIO root' mainFile
|
||||
asmCompileAssertion' entryPoint 3 tab mainFile expectedFile stdinText step
|
||||
|
@ -12,7 +12,7 @@ testDescr Run.PosTest {..} =
|
||||
in TestDescr
|
||||
{ _testName = _name,
|
||||
_testRoot = tRoot,
|
||||
_testAssertion = Steps $ asmCompileAssertion file' expected' ""
|
||||
_testAssertion = Steps $ asmCompileAssertion tRoot file' expected' ""
|
||||
}
|
||||
|
||||
allTests :: TestTree
|
||||
|
@ -46,7 +46,7 @@ compileAssertionEntry adjustEntry root' bInterp bRunVM optLevel mainFile inputFi
|
||||
step "Pretty print"
|
||||
writeFileEnsureLn tmpFile (toPlainText $ ppProgram _resultCode)
|
||||
)
|
||||
casmRunAssertion' bInterp bRunVM _resultLabelInfo _resultCode _resultBuiltins _resultOutputSize inputFile expectedFile step
|
||||
casmRunAssertion' entryPoint' bInterp bRunVM _resultLabelInfo _resultCode _resultBuiltins _resultOutputSize inputFile expectedFile step
|
||||
|
||||
compileErrorAssertion :: Path Abs Dir -> Path Abs File -> (String -> IO ()) -> Assertion
|
||||
compileErrorAssertion root' mainFile step = do
|
||||
|
@ -7,14 +7,13 @@ import Juvix.Compiler.Casm.Data.Result
|
||||
import Juvix.Compiler.Casm.Error
|
||||
import Juvix.Compiler.Casm.Interpreter
|
||||
import Juvix.Compiler.Reg.Data.InfoTable qualified as Reg
|
||||
import Juvix.Compiler.Reg.Transformation qualified as Reg
|
||||
import Juvix.Data.PPOutput
|
||||
import Reg.Run.Base qualified as Reg
|
||||
|
||||
compileAssertion' :: Maybe (Path Abs File) -> Path Abs Dir -> Path Abs File -> Symbol -> Reg.InfoTable -> (String -> IO ()) -> Assertion
|
||||
compileAssertion' inputFile _ outputFile _ tab step = do
|
||||
compileAssertion' :: EntryPoint -> Maybe (Path Abs File) -> Path Abs Dir -> Path Abs File -> Symbol -> Reg.InfoTable -> (String -> IO ()) -> Assertion
|
||||
compileAssertion' entryPoint inputFile _ outputFile _ tab step = do
|
||||
step "Translate to CASM"
|
||||
case run $ runError @JuvixError $ runReader Reg.defaultOptions $ regToCasm' tab of
|
||||
case run $ runError @JuvixError $ runReader entryPoint $ regToCasm tab of
|
||||
Left err -> assertFailure (prettyString (fromJuvixError @GenericError err))
|
||||
Right Result {..} -> do
|
||||
step "Interpret"
|
||||
@ -28,10 +27,10 @@ compileAssertion' inputFile _ outputFile _ tab step = do
|
||||
hPrint hout v
|
||||
hClose hout
|
||||
|
||||
cairoAssertion' :: Maybe (Path Abs File) -> Path Abs Dir -> Path Abs File -> Symbol -> Reg.InfoTable -> (String -> IO ()) -> Assertion
|
||||
cairoAssertion' inputFile dirPath outputFile _ tab step = do
|
||||
cairoAssertion' :: EntryPoint -> Maybe (Path Abs File) -> Path Abs Dir -> Path Abs File -> Symbol -> Reg.InfoTable -> (String -> IO ()) -> Assertion
|
||||
cairoAssertion' entryPoint inputFile dirPath outputFile _ tab step = do
|
||||
step "Translate to Cairo"
|
||||
case run $ runError @JuvixError $ runReader Reg.defaultOptions $ regToCairo' tab of
|
||||
case run $ runError @JuvixError $ runReader entryPoint $ regToCairo tab of
|
||||
Left err -> assertFailure (prettyString (fromJuvixError @GenericError err))
|
||||
Right res -> do
|
||||
step "Serialize to Cairo bytecode"
|
||||
@ -40,10 +39,12 @@ cairoAssertion' inputFile dirPath outputFile _ tab step = do
|
||||
actualOutput <- Run.casmRunVM' dirPath outputFile inputFile
|
||||
writeFileEnsureLn outputFile actualOutput
|
||||
|
||||
regToCasmAssertion :: Path Abs File -> Maybe (Path Abs File) -> Path Abs File -> (String -> IO ()) -> Assertion
|
||||
regToCasmAssertion mainFile inputFile expectedFile step =
|
||||
Reg.regRunAssertionParam (compileAssertion' inputFile) mainFile expectedFile [] (const (return ())) step
|
||||
regToCasmAssertion :: Path Abs Dir -> Path Abs File -> Maybe (Path Abs File) -> Path Abs File -> (String -> IO ()) -> Assertion
|
||||
regToCasmAssertion root mainFile inputFile expectedFile step = do
|
||||
entryPoint <- testDefaultEntryPointIO root mainFile
|
||||
Reg.regRunAssertionParam (compileAssertion' entryPoint inputFile) mainFile expectedFile [] (const (return ())) step
|
||||
|
||||
regToCairoAssertion :: Path Abs File -> Maybe (Path Abs File) -> Path Abs File -> (String -> IO ()) -> Assertion
|
||||
regToCairoAssertion mainFile inputFile expectedFile step =
|
||||
Reg.regRunAssertionParam (cairoAssertion' inputFile) mainFile expectedFile [] (const (return ())) step
|
||||
regToCairoAssertion :: Path Abs Dir -> Path Abs File -> Maybe (Path Abs File) -> Path Abs File -> (String -> IO ()) -> Assertion
|
||||
regToCairoAssertion root mainFile inputFile expectedFile step = do
|
||||
entryPoint <- testDefaultEntryPointIO root mainFile
|
||||
Reg.regRunAssertionParam (cairoAssertion' entryPoint inputFile) mainFile expectedFile [] (const (return ())) step
|
||||
|
@ -13,7 +13,7 @@ testDescr P.PosTest {..} =
|
||||
in TestDescr
|
||||
{ _testName = _name,
|
||||
_testRoot = tRoot,
|
||||
_testAssertion = Steps $ regToCairoAssertion file' input' expected'
|
||||
_testAssertion = Steps $ regToCairoAssertion tRoot file' input' expected'
|
||||
}
|
||||
|
||||
allTests :: TestTree
|
||||
|
@ -23,7 +23,7 @@ testDescr PosTest {..} =
|
||||
in TestDescr
|
||||
{ _testName = _name,
|
||||
_testRoot = tRoot,
|
||||
_testAssertion = Steps $ regToCasmAssertion file' input' expected'
|
||||
_testAssertion = Steps $ regToCasmAssertion tRoot file' input' expected'
|
||||
}
|
||||
|
||||
filterOutTests :: [String] -> [PosTest] -> [PosTest]
|
||||
|
@ -9,7 +9,6 @@ import Juvix.Compiler.Casm.Extra.InputInfo
|
||||
import Juvix.Compiler.Casm.Interpreter
|
||||
import Juvix.Compiler.Casm.Translation.FromSource
|
||||
import Juvix.Compiler.Casm.Validate
|
||||
import Juvix.Compiler.Tree.Options qualified as Casm
|
||||
import Juvix.Data.Field
|
||||
import Juvix.Data.PPOutput
|
||||
import Juvix.Parser.Error
|
||||
@ -19,8 +18,8 @@ casmRunVM' dirPath outputFile inputFile = do
|
||||
let args = maybe [] (\f -> ["--program_input", toFilePath f]) inputFile
|
||||
readProcessCwd (toFilePath dirPath) "run_cairo_vm.sh" (toFilePath outputFile : args) ""
|
||||
|
||||
casmRunVM :: LabelInfo -> Code -> [Builtin] -> Int -> Maybe (Path Abs File) -> Path Abs File -> (String -> IO ()) -> Assertion
|
||||
casmRunVM labi instrs blts outputSize inputFile expectedFile step = do
|
||||
casmRunVM :: EntryPoint -> LabelInfo -> Code -> [Builtin] -> Int -> Maybe (Path Abs File) -> Path Abs File -> (String -> IO ()) -> Assertion
|
||||
casmRunVM entryPoint labi instrs blts outputSize inputFile expectedFile step = do
|
||||
step "Check run_cairo_vm.sh is on path"
|
||||
assertCmdExists $(mkRelFile "run_cairo_vm.sh")
|
||||
withTempDir'
|
||||
@ -28,8 +27,8 @@ casmRunVM labi instrs blts outputSize inputFile expectedFile step = do
|
||||
step "Serialize to Cairo bytecode"
|
||||
let res =
|
||||
run $
|
||||
runReader Casm.defaultOptions $
|
||||
casmToCairo'
|
||||
runReader entryPoint $
|
||||
casmToCairo
|
||||
( Casm.Result
|
||||
{ _resultLabelInfo = labi,
|
||||
_resultCode = instrs,
|
||||
@ -67,8 +66,8 @@ casmInterpret labi instrs inputFile expectedFile step =
|
||||
assertEqDiffText ("Check: RUN output = " <> toFilePath expectedFile) actualOutput expected
|
||||
)
|
||||
|
||||
casmRunAssertion' :: Bool -> Bool -> LabelInfo -> Code -> [Builtin] -> Int -> Maybe (Path Abs File) -> Path Abs File -> (String -> IO ()) -> Assertion
|
||||
casmRunAssertion' bInterp bRunVM labi instrs blts outputSize inputFile expectedFile step =
|
||||
casmRunAssertion' :: EntryPoint -> Bool -> Bool -> LabelInfo -> Code -> [Builtin] -> Int -> Maybe (Path Abs File) -> Path Abs File -> (String -> IO ()) -> Assertion
|
||||
casmRunAssertion' entryPoint bInterp bRunVM labi instrs blts outputSize inputFile expectedFile step =
|
||||
case validate labi instrs of
|
||||
Left err -> do
|
||||
assertFailure (prettyString err)
|
||||
@ -76,15 +75,17 @@ casmRunAssertion' bInterp bRunVM labi instrs blts outputSize inputFile expectedF
|
||||
when bInterp $
|
||||
casmInterpret labi instrs inputFile expectedFile step
|
||||
when bRunVM $
|
||||
casmRunVM labi instrs blts outputSize inputFile expectedFile step
|
||||
casmRunVM entryPoint labi instrs blts outputSize inputFile expectedFile step
|
||||
|
||||
casmRunAssertion :: Bool -> Bool -> Path Abs File -> Maybe (Path Abs File) -> Path Abs File -> (String -> IO ()) -> Assertion
|
||||
casmRunAssertion bInterp bRunVM mainFile inputFile expectedFile step = do
|
||||
casmRunAssertion :: Bool -> Bool -> Path Abs Dir -> Path Abs File -> Maybe (Path Abs File) -> Path Abs File -> (String -> IO ()) -> Assertion
|
||||
casmRunAssertion bInterp bRunVM root mainFile inputFile expectedFile step = do
|
||||
step "Parse"
|
||||
r <- parseFile mainFile
|
||||
case r of
|
||||
Left err -> assertFailure (prettyString err)
|
||||
Right (labi, instrs) -> casmRunAssertion' bInterp bRunVM labi instrs [] 1 inputFile expectedFile step
|
||||
Right (labi, instrs) -> do
|
||||
entryPoint <- testDefaultEntryPointIO root mainFile
|
||||
casmRunAssertion' entryPoint bInterp bRunVM labi instrs [] 1 inputFile expectedFile step
|
||||
|
||||
casmRunErrorAssertion :: Path Abs File -> (String -> IO ()) -> Assertion
|
||||
casmRunErrorAssertion mainFile step = do
|
||||
|
@ -25,7 +25,7 @@ testDescr PosTest {..} =
|
||||
in TestDescr
|
||||
{ _testName = _name,
|
||||
_testRoot = tRoot,
|
||||
_testAssertion = Steps $ casmRunAssertion _interp _runVM file' input' expected'
|
||||
_testAssertion = Steps $ casmRunAssertion _interp _runVM tRoot file' input' expected'
|
||||
}
|
||||
|
||||
filterTests :: [String] -> [PosTest] -> [PosTest]
|
||||
|
@ -36,7 +36,7 @@ compileAssertionEntry adjustEntry root' optLevel mode mainFile expectedFile step
|
||||
PipelineResult {..} <- snd <$> testRunIO entryPoint upToStoredCore
|
||||
let tab' = Core.computeCombinedInfoTable (_pipelineResult ^. Core.coreResultModule)
|
||||
evalAssertion = coreEvalAssertion' EvalModePlain tab' mainFile expectedFile step
|
||||
compileAssertion' stdinText = coreCompileAssertion' optLevel tab' mainFile expectedFile stdinText step
|
||||
compileAssertion' stdinText = coreCompileAssertion' entryPoint optLevel tab' mainFile expectedFile stdinText step
|
||||
case mode of
|
||||
EvalOnly -> evalAssertion
|
||||
CompileOnly stdinText -> compileAssertion' stdinText
|
||||
@ -58,8 +58,9 @@ compileErrorAssertion root' mainFile step = do
|
||||
let res' =
|
||||
run
|
||||
. runError @JuvixError
|
||||
. runReader Core.defaultCoreOptions
|
||||
$ Core.toStored' (core ^. pipelineResult . Core.coreResultModule) >>= Core.toStripped' Core.CheckExec
|
||||
. runReader entryPoint
|
||||
$ Core.toStored (core ^. pipelineResult . Core.coreResultModule)
|
||||
>>= Core.toStripped Core.CheckExec
|
||||
case res' of
|
||||
Left {} -> return ()
|
||||
Right {} -> noError
|
||||
|
@ -7,7 +7,6 @@ import Core.Eval.Positive qualified as Eval
|
||||
import Juvix.Compiler.Asm.Translation.FromTree qualified as Asm
|
||||
import Juvix.Compiler.Core.Data.Module (computeCombinedInfoTable, moduleFromInfoTable)
|
||||
import Juvix.Compiler.Core.Data.TransformationId
|
||||
import Juvix.Compiler.Core.Options
|
||||
import Juvix.Compiler.Core.Pipeline
|
||||
import Juvix.Compiler.Core.Translation.FromSource
|
||||
import Juvix.Compiler.Core.Translation.Stripped.FromCore qualified as Stripped
|
||||
@ -34,15 +33,16 @@ toTestDescr Test {..} =
|
||||
in TestDescr
|
||||
{ _testName = _name,
|
||||
_testRoot = tRoot,
|
||||
_testAssertion = Steps $ coreAsmAssertion file' expected'
|
||||
_testAssertion = Steps $ coreAsmAssertion tRoot file' expected'
|
||||
}
|
||||
|
||||
coreAsmAssertion ::
|
||||
Path Abs Dir ->
|
||||
Path Abs File ->
|
||||
Path Abs File ->
|
||||
(String -> IO ()) ->
|
||||
Assertion
|
||||
coreAsmAssertion mainFile expectedFile step = do
|
||||
coreAsmAssertion root' mainFile expectedFile step = do
|
||||
step "Parse"
|
||||
r <- parseFile mainFile
|
||||
case r of
|
||||
@ -53,10 +53,11 @@ coreAsmAssertion mainFile expectedFile step = do
|
||||
assertEqDiffText ("Check: EVAL output = " <> toFilePath expectedFile) "" expected
|
||||
Right (tabIni, Just node) -> do
|
||||
step "Translate"
|
||||
entryPoint <- testDefaultEntryPointIO root' mainFile
|
||||
case run
|
||||
. runReader defaultCoreOptions
|
||||
. runReader entryPoint
|
||||
. runError
|
||||
. (toStored' >=> toStripped' IdentityTrans)
|
||||
. (toStored >=> toStripped IdentityTrans)
|
||||
. moduleFromInfoTable
|
||||
$ setupMainFunction defaultModuleId tabIni node of
|
||||
Left err -> assertFailure (prettyString (fromJuvixError @GenericError err))
|
||||
|
@ -10,7 +10,6 @@ import Juvix.Compiler.Asm.Translation.FromTree qualified as Asm
|
||||
import Juvix.Compiler.Core.Data.Module
|
||||
import Juvix.Compiler.Core.Data.TransformationId
|
||||
import Juvix.Compiler.Core.Extra.Utils
|
||||
import Juvix.Compiler.Core.Options
|
||||
import Juvix.Compiler.Core.Pipeline
|
||||
import Juvix.Compiler.Core.Translation.FromSource
|
||||
import Juvix.Compiler.Core.Translation.Stripped.FromCore qualified as Stripped
|
||||
@ -37,10 +36,11 @@ toTestDescr Test {..} =
|
||||
in TestDescr
|
||||
{ _testName = _name,
|
||||
_testRoot = tRoot,
|
||||
_testAssertion = Steps $ coreCompileAssertion file' expected' ""
|
||||
_testAssertion = Steps $ coreCompileAssertion tRoot file' expected' ""
|
||||
}
|
||||
|
||||
coreCompileAssertion' ::
|
||||
EntryPoint ->
|
||||
Int ->
|
||||
InfoTable ->
|
||||
Path Abs File ->
|
||||
@ -48,26 +48,27 @@ coreCompileAssertion' ::
|
||||
Text ->
|
||||
(String -> IO ()) ->
|
||||
Assertion
|
||||
coreCompileAssertion' optLevel tab mainFile expectedFile stdinText step = do
|
||||
coreCompileAssertion' entryPoint optLevel tab mainFile expectedFile stdinText step = do
|
||||
step "Translate to JuvixAsm"
|
||||
case run . runReader opts . runError $ toStored' (moduleFromInfoTable tab) >>= toStripped' CheckExec of
|
||||
case run . runReader entryPoint' . runError $ toStored (moduleFromInfoTable tab) >>= toStripped CheckExec of
|
||||
Left err -> assertFailure (prettyString (fromJuvixError @GenericError err))
|
||||
Right m -> do
|
||||
let tab0 = computeCombinedInfoTable m
|
||||
assertBool "Check info table" (checkInfoTable tab0)
|
||||
let tab' = Asm.fromTree . Tree.fromCore $ Stripped.fromCore (maximum allowedFieldSizes) tab0
|
||||
length (fromText (Asm.ppPrint tab' tab') :: String) `seq`
|
||||
Asm.asmCompileAssertion' optLevel tab' mainFile expectedFile stdinText step
|
||||
Asm.asmCompileAssertion' entryPoint' optLevel tab' mainFile expectedFile stdinText step
|
||||
where
|
||||
opts = defaultCoreOptions {_optOptimizationLevel = optLevel}
|
||||
entryPoint' = entryPoint {_entryPointOptimizationLevel = optLevel}
|
||||
|
||||
coreCompileAssertion ::
|
||||
Path Abs Dir ->
|
||||
Path Abs File ->
|
||||
Path Abs File ->
|
||||
Text ->
|
||||
(String -> IO ()) ->
|
||||
Assertion
|
||||
coreCompileAssertion mainFile expectedFile stdinText step = do
|
||||
coreCompileAssertion root' mainFile expectedFile stdinText step = do
|
||||
step "Parse"
|
||||
r <- parseFile mainFile
|
||||
case r of
|
||||
@ -76,5 +77,6 @@ coreCompileAssertion mainFile expectedFile stdinText step = do
|
||||
step "Empty program: compare expected and actual program output"
|
||||
expected <- readFile expectedFile
|
||||
assertEqDiffText ("Check: EVAL output = " <> toFilePath expectedFile) "" expected
|
||||
Right (tabIni, Just node) ->
|
||||
coreCompileAssertion' 3 (setupMainFunction defaultModuleId tabIni node) mainFile expectedFile stdinText step
|
||||
Right (tabIni, Just node) -> do
|
||||
entryPoint <- testDefaultEntryPointIO root' mainFile
|
||||
coreCompileAssertion' entryPoint 3 (setupMainFunction defaultModuleId tabIni node) mainFile expectedFile stdinText step
|
||||
|
@ -22,7 +22,8 @@ root :: Path Abs Dir
|
||||
root = relToProject $(mkRelDir "tests/VampIR/positive")
|
||||
|
||||
toTestDescr' ::
|
||||
( Path Abs File ->
|
||||
( Path Abs Dir ->
|
||||
Path Abs File ->
|
||||
Path Abs File ->
|
||||
(String -> IO ()) ->
|
||||
Assertion
|
||||
@ -36,11 +37,11 @@ toTestDescr' assertion PosTest {..} =
|
||||
in TestDescr
|
||||
{ _testName = _name,
|
||||
_testRoot = tRoot,
|
||||
_testAssertion = Steps $ assertion file' expected'
|
||||
_testAssertion = Steps $ assertion tRoot file' expected'
|
||||
}
|
||||
|
||||
toTestDescr :: PosTest -> TestDescr
|
||||
toTestDescr = toTestDescr' coreNormalizeAssertion
|
||||
toTestDescr = toTestDescr' (const coreNormalizeAssertion)
|
||||
|
||||
allTests :: TestTree
|
||||
allTests =
|
||||
|
@ -10,7 +10,7 @@ fromTest :: PosTest -> TestTree
|
||||
fromTest = mkTest . toTestDescr
|
||||
|
||||
toTestDescr :: PosTest -> TestDescr
|
||||
toTestDescr = Normalize.toTestDescr' (coreVampIRAssertion [LetHoisting])
|
||||
toTestDescr = Normalize.toTestDescr' (const (coreVampIRAssertion [LetHoisting]))
|
||||
|
||||
allTests :: TestTree
|
||||
allTests =
|
||||
|
@ -10,7 +10,7 @@ fromTest :: PosTest -> TestTree
|
||||
fromTest = mkTest . toTestDescr
|
||||
|
||||
toTestDescr :: PosTest -> TestDescr
|
||||
toTestDescr = Normalize.toTestDescr' (coreVampIRAssertion (toStoredTransformations ++ toVampIRTransformations))
|
||||
toTestDescr = Normalize.toTestDescr' (const (coreVampIRAssertion (toStoredTransformations ++ toVampIRTransformations)))
|
||||
|
||||
allTests :: TestTree
|
||||
allTests =
|
||||
|
@ -4,7 +4,6 @@ import Base
|
||||
import Juvix.Compiler.Nockma.Anoma
|
||||
import Juvix.Compiler.Nockma.EvalCompiled
|
||||
import Juvix.Compiler.Nockma.Evaluator qualified as NockmaEval
|
||||
import Juvix.Compiler.Nockma.Language
|
||||
import Juvix.Compiler.Nockma.Language qualified as Nockma
|
||||
import Juvix.Compiler.Nockma.Pretty qualified as Nockma
|
||||
import Juvix.Compiler.Nockma.Translation.FromTree
|
||||
@ -12,16 +11,18 @@ import Juvix.Compiler.Tree
|
||||
import Tree.Eval.Base
|
||||
import Tree.Eval.Positive qualified as Tree
|
||||
|
||||
runNockmaAssertion :: Handle -> Symbol -> InfoTable -> IO ()
|
||||
runNockmaAssertion hout _main tab = do
|
||||
runNockmaAssertion :: Path Abs Dir -> Handle -> Symbol -> InfoTable -> IO ()
|
||||
runNockmaAssertion root hout _main tab = do
|
||||
entryPoint <- testDefaultEntryPointNoFileIO root
|
||||
let entryPoint' = entryPoint {_entryPointDebug = True}
|
||||
anomaRes :: AnomaResult <-
|
||||
runM
|
||||
. runErrorIO' @JuvixError
|
||||
. runReader opts
|
||||
$ treeToAnoma' tab
|
||||
. runReader entryPoint'
|
||||
$ treeToAnoma tab
|
||||
res <-
|
||||
runM
|
||||
. runOutputSem @(Term Natural)
|
||||
. runOutputSem @(Nockma.Term Natural)
|
||||
(hPutStrLn hout . Nockma.ppTest)
|
||||
. runReader NockmaEval.defaultEvalOptions
|
||||
. NockmaEval.ignoreOpCounts
|
||||
@ -29,16 +30,10 @@ runNockmaAssertion hout _main tab = do
|
||||
let ret = getReturn res
|
||||
whenJust ret (hPutStrLn hout . Nockma.ppTest)
|
||||
where
|
||||
opts :: CompilerOptions
|
||||
opts =
|
||||
CompilerOptions
|
||||
{ _compilerOptionsEnableTrace = True
|
||||
}
|
||||
|
||||
getReturn :: Term Natural -> Maybe (Term Natural)
|
||||
getReturn :: Nockma.Term Natural -> Maybe (Nockma.Term Natural)
|
||||
getReturn = \case
|
||||
TermAtom Nockma.Atom {..}
|
||||
| _atomInfo ^. atomInfoHint == Just AtomHintVoid -> Nothing
|
||||
Nockma.TermAtom Nockma.Atom {..}
|
||||
| _atomInfo ^. Nockma.atomInfoHint == Just Nockma.AtomHintVoid -> Nothing
|
||||
t -> Just t
|
||||
|
||||
testDescr :: Tree.PosTest -> TestDescr
|
||||
@ -49,7 +44,7 @@ testDescr Tree.PosTest {..} =
|
||||
in TestDescr
|
||||
{ _testName = _name,
|
||||
_testRoot = tRoot,
|
||||
_testAssertion = Steps $ treeEvalAssertionParam runNockmaAssertion file' expected' [] (const (return ()))
|
||||
_testAssertion = Steps $ treeEvalAssertionParam (runNockmaAssertion tRoot) file' expected' [] (const (return ()))
|
||||
}
|
||||
|
||||
-- | Tests which require Nockma-specific expected output files
|
||||
|
@ -12,7 +12,7 @@ vampirCompileAssertion root' mainFile dataFile step = do
|
||||
PipelineResult {..} <- snd <$> testRunIO entryPoint upToStoredCore
|
||||
let tab = computeCombinedInfoTable (_pipelineResult ^. coreResultModule)
|
||||
coreVampIRAssertion' tab toVampIRTransformations mainFile dataFile step
|
||||
vampirAssertion' VampirHalo2 tab dataFile step
|
||||
vampirAssertion' entryPoint VampirHalo2 tab dataFile step
|
||||
|
||||
vampirCompileErrorAssertion ::
|
||||
Path Abs Dir ->
|
||||
@ -27,6 +27,6 @@ vampirCompileErrorAssertion root' mainFile step = do
|
||||
Left _ -> return ()
|
||||
Right res ->
|
||||
let m = snd res ^. pipelineResult . coreResultModule
|
||||
in case run $ runReader defaultCoreOptions $ runError @JuvixError $ toVampIR' m of
|
||||
in case run $ runReader entryPoint $ runError @JuvixError $ toVampIR m of
|
||||
Left _ -> return ()
|
||||
Right _ -> assertFailure "no error"
|
||||
|
@ -8,21 +8,23 @@ import System.Process qualified as P
|
||||
|
||||
data VampirBackend = VampirHalo2 | VampirPlonk
|
||||
|
||||
vampirAssertion :: VampirBackend -> Path Abs File -> Path Abs File -> (String -> IO ()) -> Assertion
|
||||
vampirAssertion backend mainFile dataFile step = do
|
||||
vampirAssertion :: VampirBackend -> Path Abs Dir -> Path Abs File -> Path Abs File -> (String -> IO ()) -> Assertion
|
||||
vampirAssertion backend root mainFile dataFile step = do
|
||||
step "Parse"
|
||||
s <- readFile mainFile
|
||||
case runParserMain mainFile defaultModuleId mempty s of
|
||||
Left err -> assertFailure (show err)
|
||||
Right tab -> vampirAssertion' backend tab dataFile step
|
||||
Right tab -> do
|
||||
entryPoint <- testDefaultEntryPointIO root mainFile
|
||||
vampirAssertion' entryPoint backend tab dataFile step
|
||||
|
||||
vampirAssertion' :: VampirBackend -> InfoTable -> Path Abs File -> (String -> IO ()) -> Assertion
|
||||
vampirAssertion' backend tab dataFile step = do
|
||||
vampirAssertion' :: EntryPoint -> VampirBackend -> InfoTable -> Path Abs File -> (String -> IO ()) -> Assertion
|
||||
vampirAssertion' entryPoint backend tab dataFile step = do
|
||||
withTempDir'
|
||||
( \dirPath -> do
|
||||
step "Translate to VampIR"
|
||||
let vampirFile = dirPath <//> $(mkRelFile "program.pir")
|
||||
case run (runReader defaultCoreOptions (runError @JuvixError (coreToVampIR' (moduleFromInfoTable tab)))) of
|
||||
case run (runReader entryPoint (runError @JuvixError (coreToVampIR (moduleFromInfoTable tab)))) of
|
||||
Left err -> assertFailure (prettyString (fromJuvixError @GenericError err))
|
||||
Right VampIR.Result {..} -> do
|
||||
writeFileEnsureLn vampirFile _resultCode
|
||||
|
Loading…
Reference in New Issue
Block a user