mirror of
https://github.com/anoma/juvix.git
synced 2024-09-21 05:28:17 +03:00
65176a333d
- refactor `--target` into subcommands for `dev tree compile`. - prepend `App` to all `CompileTarget` constructors to avoid name clashes with `Target`. - parameterize compile options type with the input kind. The input kind indicates the expected file extension of the input file. If the input file is a .juvix file, then it is optional, otherwise it is mandatory. - Add `AppError MegaparsecError` instance and simplify some related code.
33 lines
1.3 KiB
Haskell
33 lines
1.3 KiB
Haskell
module Commands.Compile.Anoma where
|
|
|
|
import Commands.Base
|
|
import Commands.Compile.Anoma.Options
|
|
import Commands.Extra.NewCompile
|
|
import Juvix.Compiler.Nockma.Pretty qualified as Nockma
|
|
import Juvix.Compiler.Nockma.Translation.FromTree qualified as Nockma
|
|
|
|
runCommand :: (Members '[App, EmbedIO, TaggedLock] r) => AnomaOptions 'InputMain -> Sem r ()
|
|
runCommand opts = do
|
|
let opts' = opts ^. anomaCompileCommonOptions
|
|
inputFile = opts' ^. compileInputFile
|
|
moutputFile = opts' ^. compileOutputFile
|
|
coreRes <- fromCompileCommonOptionsMain opts' >>= compileToCore
|
|
entryPoint <-
|
|
applyOptions opts
|
|
<$> getEntryPoint (opts' ^. compileInputFile)
|
|
nockmaFile :: Path Abs File <- getOutputFile FileExtNockma inputFile moutputFile
|
|
r <-
|
|
runReader entryPoint
|
|
. runError @JuvixError
|
|
. coreToAnoma
|
|
$ coreRes ^. coreResultModule
|
|
res <- getRight r
|
|
outputAnomaResult nockmaFile res
|
|
|
|
outputAnomaResult :: (Members '[EmbedIO, App] r) => Path Abs File -> Nockma.AnomaResult -> Sem r ()
|
|
outputAnomaResult nockmaFile Nockma.AnomaResult {..} = do
|
|
let code = Nockma.ppSerialize _anomaClosure
|
|
prettyNockmaFile = replaceExtensions' [".pretty", ".nockma"] nockmaFile
|
|
writeFileEnsureLn nockmaFile code
|
|
writeFileEnsureLn prettyNockmaFile (Nockma.ppPrint _anomaClosure)
|