mirror of
https://github.com/anoma/juvix.git
synced 2024-12-14 08:27:03 +03:00
98b1daec7d
Print JuvixCore InfoTable in such a way that it can be parsed back by the JuvixCore parser. * Depends on PR #1832 * Depends on PR #1862 * Closes #1841 * Adds "JuvixCore print" tests which read the files from Core/positive/*.jvc, print them, read them back and check if the evaluation results are preserved. --------- Co-authored-by: Jan Mas Rovira <janmasrovira@gmail.com>
35 lines
1.4 KiB
Haskell
35 lines
1.4 KiB
Haskell
module Commands.Compile where
|
|
|
|
import Commands.Base
|
|
import Commands.Compile.Options
|
|
import Commands.Dev.Core.Compile.Base qualified as Compile
|
|
import Commands.Extra.Compile qualified as Compile
|
|
import Data.Text.IO qualified as TIO
|
|
import Juvix.Compiler.Core qualified as Core
|
|
import Juvix.Compiler.Core.Pipeline qualified as Core
|
|
import Juvix.Compiler.Core.Pretty qualified as Core
|
|
import Juvix.Compiler.Core.Transformation.DisambiguateNames qualified as Core
|
|
|
|
runCommand :: (Members '[Embed IO, App] r) => CompileOptions -> Sem r ()
|
|
runCommand opts@CompileOptions {..} = do
|
|
inputFile <- someBaseToAbs' (_compileInputFile ^. pathPath)
|
|
Core.CoreResult {..} <- runPipeline _compileInputFile upToCore
|
|
let arg =
|
|
Compile.PipelineArg
|
|
{ _pipelineArgFile = inputFile,
|
|
_pipelineArgOptions = opts,
|
|
_pipelineArgInfoTable = _coreResultTable
|
|
}
|
|
case _compileTarget of
|
|
TargetNative64 -> Compile.runCPipeline arg
|
|
TargetWasm32Wasi -> Compile.runCPipeline arg
|
|
TargetGeb -> Compile.runGebPipeline arg
|
|
TargetCore -> writeCoreFile arg
|
|
TargetAsm -> Compile.runAsmPipeline arg
|
|
|
|
writeCoreFile :: (Members '[Embed IO, App] r) => Compile.PipelineArg -> Sem r ()
|
|
writeCoreFile Compile.PipelineArg {..} = do
|
|
coreFile <- Compile.outputFile _pipelineArgOptions _pipelineArgFile
|
|
let tab = Core.toEval _pipelineArgInfoTable
|
|
embed $ TIO.writeFile (toFilePath coreFile) (show $ Core.ppOutDefault (Core.disambiguateNames tab))
|