mirror of
https://github.com/anoma/juvix.git
synced 2025-01-05 06:14:05 +03:00
9e7a8a98d4
* Remove ParserParams ParserParams is only used to record the root of the project, which is used to prefix source file paths. However source file paths are always absolute so this is not required. * Add GetAbsPath to Files effect The Files effect is not responsible for resolving a relative module path into an absolute path on disk. This will allow us to resolve relative module paths to alternative paths, for example to point to the standard library on disk. * Files effect getAbsPath returns paths within the registered standard library This means that the standard library can exist on disk at a different location to the Juvix project. A command line flag --stdlib-path can be specified to point to a standard library, otherwise the embedded standard library is written to disk at $PROJ_DIR/.juvix-build/stdlib and this is used instead. * Recreate stdlib dir only when juvix version changes * Add UpdateStdlib to the Files effect * Add comment for stdlibOrFile * Remove spurious import
49 lines
1.8 KiB
Haskell
49 lines
1.8 KiB
Haskell
module Commands.Dev.Core.Eval where
|
|
|
|
import Commands.Base
|
|
import Commands.Dev.Core.Eval.Options
|
|
import Juvix.Compiler.Core.Data.InfoTable qualified as Core
|
|
import Juvix.Compiler.Core.Error qualified as Core
|
|
import Juvix.Compiler.Core.Evaluator qualified as Core
|
|
import Juvix.Compiler.Core.Extra.Base qualified as Core
|
|
import Juvix.Compiler.Core.Info qualified as Info
|
|
import Juvix.Compiler.Core.Info.NoDisplayInfo qualified as Info
|
|
import Juvix.Compiler.Core.Language qualified as Core
|
|
import Juvix.Compiler.Core.Pretty qualified as Core
|
|
import Juvix.Compiler.Core.Translation.FromSource qualified as Core
|
|
import Text.Megaparsec.Pos qualified as M
|
|
|
|
doEval ::
|
|
forall r.
|
|
Members '[Embed IO, App] r =>
|
|
Bool ->
|
|
Interval ->
|
|
Core.InfoTable ->
|
|
Core.Node ->
|
|
Sem r (Either Core.CoreError Core.Node)
|
|
doEval noIO loc tab node
|
|
| noIO = embed $ Core.catchEvalError loc (Core.eval (tab ^. Core.identContext) [] node)
|
|
| otherwise = embed $ Core.catchEvalErrorIO loc (Core.evalIO (tab ^. Core.identContext) [] node)
|
|
|
|
runCommand :: forall r. Members '[Embed IO, App] r => CoreEvalOptions -> Sem r ()
|
|
runCommand opts = do
|
|
s <- embed (readFile f)
|
|
case Core.runParser f Core.emptyInfoTable s of
|
|
Left err -> exitJuvixError (JuvixError err)
|
|
Right (tab, Just node) -> do
|
|
r <- doEval (opts ^. coreEvalNoIO) defaultLoc tab node
|
|
case r of
|
|
Left err -> exitJuvixError (JuvixError err)
|
|
Right node'
|
|
| Info.member Info.kNoDisplayInfo (Core.getInfo node') ->
|
|
return ()
|
|
Right node' -> do
|
|
renderStdOut (Core.ppOut opts node')
|
|
embed (putStrLn "")
|
|
Right (_, Nothing) -> return ()
|
|
where
|
|
defaultLoc :: Interval
|
|
defaultLoc = singletonInterval (mkLoc 0 (M.initialPos f))
|
|
f :: FilePath
|
|
f = opts ^. coreEvalInputFile . pathPath
|