mirror of
https://github.com/anoma/juvix.git
synced 2024-12-22 06:11:36 +03:00
f2298bd674
An implementation of the translation from JuvixCore to JuvixAsm. After merging this PR, the only remaining step to complete the basic compilation pipeline (#1556) is the compilation of complex pattern matching (#1531). * Fixes several bugs in lambda-lifting. * Fixes several bugs in the RemoveTypeArgs transformation. * Fixes several bugs in the TopEtaExpand transformation. * Adds the ConvertBuiltinTypes transformation which converts the builtin bool inductive type to Core primitive bool. * Adds the `juvix dev core strip` command. * Adds the `juvix dev core asm` command. * Adds the `juvix dev core compile` command. * Adds two groups of tests: - JuvixCore to JuvixAsm translation: translate JuvixCore tests to JuvixAsm and run the results with the JuvixAsm interpreter, - JuvixCore compilation: compile JuvixCore tests to native code and WASM and execute the results. * Closes #1520 * Closes #1549
33 lines
1.6 KiB
Haskell
33 lines
1.6 KiB
Haskell
module Commands.Dev.Core.Read where
|
|
|
|
import Commands.Base
|
|
import Commands.Dev.Core.Read.Options
|
|
import Evaluator qualified as Eval
|
|
import Juvix.Compiler.Core.Pretty qualified as Core
|
|
import Juvix.Compiler.Core.Scoper qualified as Scoper
|
|
import Juvix.Compiler.Core.Transformation qualified as Core
|
|
import Juvix.Compiler.Core.Translation.FromSource qualified as Core
|
|
|
|
runCommand :: forall r a. (Members '[Embed IO, App] r, CanonicalProjection a Eval.EvalOptions, CanonicalProjection a Core.Options, CanonicalProjection a CoreReadOptions) => a -> Sem r ()
|
|
runCommand opts = do
|
|
inputFile :: Path Abs File <- someBaseToAbs' sinputFile
|
|
s' <- embed . readFile . toFilePath $ inputFile
|
|
tab <- getRight (mapLeft JuvixError (Core.runParserMain (toFilePath inputFile) Core.emptyInfoTable s'))
|
|
let tab' = Core.applyTransformations (project opts ^. coreReadTransformations) tab
|
|
embed (Scoper.scopeTrace tab')
|
|
unless (project opts ^. coreReadNoPrint) $ do
|
|
renderStdOut (Core.ppOut opts tab')
|
|
whenJust (tab' ^. Core.infoMain) $ \sym -> doEval tab' (fromJust $ tab' ^. Core.identContext . at sym)
|
|
where
|
|
doEval :: Core.InfoTable -> Core.Node -> Sem r ()
|
|
doEval tab' node =
|
|
if
|
|
| project opts ^. coreReadEval -> do
|
|
embed (putStrLn "--------------------------------")
|
|
embed (putStrLn "| Eval |")
|
|
embed (putStrLn "--------------------------------")
|
|
Eval.evalAndPrint opts tab' node
|
|
| otherwise -> return ()
|
|
sinputFile :: SomeBase File
|
|
sinputFile = project opts ^. coreReadInputFile . pathPath
|