2023-01-09 20:21:30 +03:00
|
|
|
module Commands.Dev.Core.Strip where
|
|
|
|
|
|
|
|
import Commands.Base
|
|
|
|
import Commands.Dev.Core.Strip.Options
|
2023-03-27 11:42:27 +03:00
|
|
|
import Juvix.Compiler.Core.Options qualified as Core
|
2023-01-09 20:21:30 +03:00
|
|
|
import Juvix.Compiler.Core.Pipeline qualified as Core
|
|
|
|
import Juvix.Compiler.Core.Pretty qualified as Core
|
|
|
|
import Juvix.Compiler.Core.Translation.FromSource qualified as Core
|
|
|
|
import Juvix.Compiler.Core.Translation.Stripped.FromCore qualified as Stripped
|
|
|
|
|
|
|
|
runCommand :: forall r a. (Members '[Embed IO, App] r, CanonicalProjection a Core.Options, CanonicalProjection a CoreStripOptions) => a -> Sem r ()
|
|
|
|
runCommand opts = do
|
2023-03-27 11:42:27 +03:00
|
|
|
gopts <- askGlobalOptions
|
2023-04-19 17:56:48 +03:00
|
|
|
inputFile :: Path Abs File <- fromAppPathFile sinputFile
|
2023-01-09 20:21:30 +03:00
|
|
|
s' <- embed (readFile $ toFilePath inputFile)
|
2023-03-20 12:13:07 +03:00
|
|
|
(tab, _) <- getRight (mapLeft JuvixError (Core.runParser inputFile Core.emptyInfoTable s'))
|
2023-03-27 11:42:27 +03:00
|
|
|
let r =
|
|
|
|
run $
|
|
|
|
runReader (project gopts) $
|
|
|
|
runError @JuvixError (Core.toStripped' tab :: Sem '[Error JuvixError, Reader Core.CoreOptions] Core.InfoTable)
|
2023-03-20 12:13:07 +03:00
|
|
|
tab' <- getRight $ mapLeft JuvixError $ mapRight Stripped.fromCore r
|
2023-01-09 20:21:30 +03:00
|
|
|
unless (project opts ^. coreStripNoPrint) $ do
|
|
|
|
renderStdOut (Core.ppOut opts tab')
|
|
|
|
where
|
2023-04-19 17:56:48 +03:00
|
|
|
sinputFile :: AppPath File
|
|
|
|
sinputFile = project opts ^. coreStripInputFile
|