1
1
mirror of https://github.com/anoma/juvix.git synced 2024-12-15 18:13:56 +03:00
juvix/app/Commands/Extra/Compile/Options.hs
Łukasz Czajka 2d798ec31c
New compilation pipeline (#1832)
* Depends on PR #1824 
* Closes #1556 
* Closes #1825 
* Closes #1843
* Closes #1729 
* Closes #1596 
* Closes #1343 
* Closes #1382 
* Closes #1867 
* Closes #1876 
* Changes the `juvix compile` command to use the new pipeline.
* Removes the `juvix dev minic` command and the `BackendC` tests.
* Adds the `juvix eval` command.
* Fixes bugs in the Nat-to-integer conversion.
* Fixes bugs in the Internal-to-Core and Core-to-Core.Stripped
translations.
* Fixes bugs in the RemoveTypeArgs transformation.
* Fixes bugs in lambda-lifting (incorrect de Bruijn indices in the types
of added binders).
* Fixes several other bugs in the compilation pipeline.
* Adds a separate EtaExpandApps transformation to avoid quadratic
runtime in the Internal-to-Core translation due to repeated calls to
etaExpandApps.
* Changes Internal-to-Core to avoid generating matches on values which
don't have an inductive type.

---------

Co-authored-by: Paul Cadman <git@paulcadman.dev>
Co-authored-by: janmasrovira <janmasrovira@gmail.com>
2023-03-14 16:24:07 +01:00

92 lines
2.5 KiB
Haskell

module Commands.Extra.Compile.Options where
import CommonOptions hiding (show)
import Prelude (Show (show))
data CompileTarget
= TargetWasm32Wasi
| TargetNative64
| TargetGeb
| TargetCore
| TargetAsm
deriving stock (Data, Bounded, Enum)
instance Show CompileTarget where
show = \case
TargetWasm32Wasi -> "wasm32-wasi"
TargetNative64 -> "native"
TargetGeb -> "geb"
TargetCore -> "core"
TargetAsm -> "asm"
data CompileOptions = CompileOptions
{ _compileDebug :: Bool,
_compileCOutput :: Bool,
_compilePreprocess :: Bool,
_compileAssembly :: Bool,
_compileTerm :: Bool,
_compileOutputFile :: Maybe (AppPath File),
_compileTarget :: CompileTarget,
_compileInputFile :: AppPath File
}
deriving stock (Data)
makeLenses ''CompileOptions
parseCompileOptions :: Parser (AppPath File) -> Parser CompileOptions
parseCompileOptions parseInputFile = do
_compileDebug <-
switch
( short 'g'
<> long "debug"
<> help "Generate debug information and runtime assertions"
)
_compileCOutput <-
switch
( short 'C'
<> long "only-c"
<> help "Produce C output only (for targets: wasm32-wasi, native)"
)
_compilePreprocess <-
switch
( short 'E'
<> long "only-preprocess"
<> help "Run the C preprocessor only (for targets: wasm32-wasi, native)"
)
_compileAssembly <-
switch
( short 'S'
<> long "only-assemble"
<> help "Produce assembly output only (for targets: wasm32-wasi, native)"
)
_compileTerm <-
switch
( short 'G'
<> long "only-term"
<> help "Produce term output only (for targets: geb)"
)
_compileTarget <- optCompileTarget
_compileOutputFile <- optional parseGenericOutputFile
_compileInputFile <- parseInputFile
pure CompileOptions {..}
optCompileTarget :: Parser CompileTarget
optCompileTarget =
option
(eitherReader parseTarget)
( long "target"
<> short 't'
<> metavar "TARGET"
<> value TargetNative64
<> showDefault
<> help ("select a target: " <> show allTargets)
<> completeWith (map show allTargets)
)
where
allTargets :: [CompileTarget]
allTargets = allElements
parseTarget :: String -> Either String CompileTarget
parseTarget txt = maybe err return (lookup (map toLower txt) [(Prelude.show t, t) | t <- allElements])
where
err = Left $ "unrecognised target: " <> txt