1
1
mirror of https://github.com/anoma/juvix.git synced 2024-09-21 05:28:17 +03:00
juvix/app/Commands/Compile/Cairo.hs
Jan Mas Rovira 65176a333d
refactor --target into subcommands for dev tree compile and other improvements (#2713)
- 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.
2024-04-16 17:32:44 +02:00

25 lines
846 B
Haskell

module Commands.Compile.Cairo where
import Commands.Base
import Commands.Compile.Cairo.Options
import Commands.Extra.NewCompile
import Data.Aeson qualified as JSON
runCommand :: (Members '[App, TaggedLock, EmbedIO] r) => CairoOptions 'InputMain -> Sem r ()
runCommand opts = do
let opts' = opts ^. cairoCompileCommonOptions
inputFile = opts' ^. compileInputFile
moutputFile = opts' ^. compileOutputFile
coreRes <- fromCompileCommonOptionsMain opts' >>= compileToCore
entryPoint <-
applyOptions opts
<$> getEntryPoint (opts' ^. compileInputFile)
cairoFile :: Path Abs File <- getOutputFile FileExtJson inputFile moutputFile
r <-
runReader entryPoint
. runError @JuvixError
. coreToCairo
$ coreRes ^. coreResultModule
res <- getRight r
liftIO (JSON.encodeFile (toFilePath cairoFile) res)