mirror of
https://github.com/anoma/juvix.git
synced 2024-12-14 17:32:00 +03:00
c9b8cdd5e9
This implements a basic version of the algorithm from: Luc Maranget, [Compiling pattern matching to good decision trees](http://moscova.inria.fr/~maranget/papers/ml05e-maranget.pdf). No heuristics are used - the first column is always chosen. * Closes #1798 * Closes #1225 * Closes #1926 * Adds a global `--no-coverage` option which turns off coverage checking in favour of generating runtime failures * Changes the representation of Match patterns in JuvixCore to achieve a more streamlined implementation * Adds options to the Core pipeline
53 lines
2.1 KiB
Haskell
53 lines
2.1 KiB
Haskell
module Commands.Dev.Asm.Compile where
|
|
|
|
import Commands.Base
|
|
import Commands.Dev.Asm.Compile.Options
|
|
import Commands.Extra.Compile qualified as Compile
|
|
import Data.Text.IO qualified as TIO
|
|
import Juvix.Compiler.Asm.Translation.FromSource qualified as Asm
|
|
import Juvix.Compiler.Backend qualified as Backend
|
|
import Juvix.Compiler.Backend.C qualified as C
|
|
|
|
runCommand :: forall r. (Members '[Embed IO, App] r) => AsmCompileOptions -> Sem r ()
|
|
runCommand opts = do
|
|
file <- getFile
|
|
ep <- getEntryPoint (AppPath (Abs file) True)
|
|
tgt <- getTarget (opts ^. compileTarget)
|
|
let entryPoint :: EntryPoint
|
|
entryPoint =
|
|
ep
|
|
{ _entryPointTarget = tgt,
|
|
_entryPointDebug = opts ^. compileDebug
|
|
}
|
|
s <- embed (readFile (toFilePath file))
|
|
case Asm.runParser (toFilePath file) s of
|
|
Left err -> exitJuvixError (JuvixError err)
|
|
Right tab -> do
|
|
case run $ runReader entryPoint $ runError $ asmToMiniC tab of
|
|
Left err -> exitJuvixError err
|
|
Right C.MiniCResult {..} -> do
|
|
buildDir <- askBuildDir
|
|
ensureDir buildDir
|
|
cFile <- inputCFile file
|
|
embed $ TIO.writeFile (toFilePath cFile) _resultCCode
|
|
Compile.runCommand opts {_compileInputFile = AppPath (Abs cFile) False}
|
|
where
|
|
getFile :: Sem r (Path Abs File)
|
|
getFile = someBaseToAbs' (opts ^. compileInputFile . pathPath)
|
|
|
|
getTarget :: CompileTarget -> Sem r Backend.Target
|
|
getTarget = \case
|
|
TargetWasm32Wasi -> return Backend.TargetCWasm32Wasi
|
|
TargetNative64 -> return Backend.TargetCNative64
|
|
TargetGeb -> exitMsg (ExitFailure 1) "error: GEB target not supported for JuvixAsm"
|
|
TargetCore -> exitMsg (ExitFailure 1) "error: JuvixCore target not supported for JuvixAsm"
|
|
TargetAsm -> exitMsg (ExitFailure 1) "error: JuvixAsm target not supported for JuvixAsm"
|
|
|
|
inputCFile :: (Members '[App] r) => Path Abs File -> Sem r (Path Abs File)
|
|
inputCFile inputFileCompile = do
|
|
buildDir <- askBuildDir
|
|
return (buildDir <//> outputMiniCFile)
|
|
where
|
|
outputMiniCFile :: Path Rel File
|
|
outputMiniCFile = replaceExtension' ".c" (filename inputFileCompile)
|