mirror of
https://github.com/anoma/juvix.git
synced 2024-12-18 12:21:46 +03:00
75bce8f665
* Closes #2392 Changes checklist ----------------- * [X] Abstract out data types for stored module representation (`ModuleInfo` in `Juvix.Compiler.Store.Language`) * [X] Adapt the parser to operate per-module * [X] Adapt the scoper to operate per-module * [X] Adapt the arity checker to operate per-module * [X] Adapt the type checker to operate per-module * [x] Adapt Core transformations to operate per-module * [X] Adapt the pipeline functions in `Juvix.Compiler.Pipeline` * [X] Add `Juvix.Compiler.Pipeline.Driver` which drives the per-module compilation process * [x] Implement module saving / loading in `Pipeline.Driver` * [x] Detect cyclic module dependencies in `Pipeline.Driver` * [x] Cache visited modules in memory in `Pipeline.Driver` to avoid excessive disk operations and repeated hash re-computations * [x] Recompile a module if one of its dependencies needs recompilation and contains functions that are always inlined. * [x] Fix identifier dependencies for mutual block creation in `Internal.fromConcrete` - Fixed by making textually later definitions depend on earlier ones. - Now instances are used for resolution only after the textual point of their definition. - Similarly, type synonyms will be unfolded only after the textual point of their definition. * [x] Fix CLI * [x] Fix REPL * [x] Fix highlighting * [x] Fix HTML generation * [x] Adapt test suite
57 lines
1.8 KiB
Haskell
57 lines
1.8 KiB
Haskell
module Compilation.Base where
|
|
|
|
import Base
|
|
import Core.Compile.Base
|
|
import Core.Eval.Base
|
|
import Juvix.Compiler.Core qualified as Core
|
|
|
|
data CompileAssertionMode
|
|
= EvalOnly
|
|
| -- | Specify text to be sent to stdin of the process under test
|
|
CompileOnly Text
|
|
| EvalAndCompile
|
|
|
|
compileAssertion ::
|
|
Path Abs Dir ->
|
|
Int ->
|
|
CompileAssertionMode ->
|
|
Path Abs File ->
|
|
Path Abs File ->
|
|
(String -> IO ()) ->
|
|
Assertion
|
|
compileAssertion = compileAssertionEntry id
|
|
|
|
compileAssertionEntry ::
|
|
(EntryPoint -> EntryPoint) ->
|
|
Path Abs Dir ->
|
|
Int ->
|
|
CompileAssertionMode ->
|
|
Path Abs File ->
|
|
Path Abs File ->
|
|
(String -> IO ()) ->
|
|
Assertion
|
|
compileAssertionEntry adjustEntry root' optLevel mode mainFile expectedFile step = do
|
|
step "Translate to JuvixCore"
|
|
entryPoint <- adjustEntry <$> testDefaultEntryPointIO root' mainFile
|
|
PipelineResult {..} <- snd <$> testRunIO entryPoint upToStoredCore
|
|
let tab' = Core.computeCombinedInfoTable (_pipelineResult ^. Core.coreResultModule)
|
|
evalAssertion = coreEvalAssertion' EvalModePlain tab' mainFile expectedFile step
|
|
compileAssertion' stdinText = coreCompileAssertion' optLevel tab' mainFile expectedFile stdinText step
|
|
case mode of
|
|
EvalOnly -> evalAssertion
|
|
CompileOnly stdinText -> compileAssertion' stdinText
|
|
EvalAndCompile -> evalAssertion >> compileAssertion' ""
|
|
|
|
compileErrorAssertion ::
|
|
Path Abs Dir ->
|
|
Path Abs File ->
|
|
(String -> IO ()) ->
|
|
Assertion
|
|
compileErrorAssertion root' mainFile step = do
|
|
step "Translate to JuvixCore"
|
|
entryPoint <- testDefaultEntryPointIO root' mainFile
|
|
PipelineResult {..} <- snd <$> testRunIO entryPoint upToCore
|
|
case run $ runReader Core.defaultCoreOptions $ runError @JuvixError $ Core.toStored' (_pipelineResult ^. Core.coreResultModule) >>= Core.toStripped' of
|
|
Left _ -> assertBool "" True
|
|
Right _ -> assertFailure "no error"
|