Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use absolute path in Core Evaluator to generate source file location #1769

Merged
merged 1 commit into from
Jan 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions app/Evaluator.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ 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 Text.Megaparsec.Pos qualified as M

data EvalOptions = EvalOptions
{ _evalInputFile :: AppPath File,
Expand Down Expand Up @@ -47,7 +46,8 @@ evalAndPrint ::
Core.Node ->
Sem r ()
evalAndPrint opts tab node = do
r <- doEval (project opts ^. evalNoIO) defaultLoc tab node
loc <- defaultLoc
r <- doEval (project opts ^. evalNoIO) loc tab node
case r of
Left err -> exitJuvixError (JuvixError err)
Right node'
Expand All @@ -57,7 +57,7 @@ evalAndPrint opts tab node = do
renderStdOut (Core.ppOut opts node')
embed (putStrLn "")
where
defaultLoc :: Interval
defaultLoc = singletonInterval (mkLoc 0 (M.initialPos (fromSomeFile f)))
defaultLoc :: Sem r Interval
defaultLoc = singletonInterval . mkInitialLoc <$> someBaseToAbs' f
f :: SomeBase File
f = project opts ^. evalInputFile . pathPath
4 changes: 4 additions & 0 deletions src/Juvix/Data/Loc.hs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ mkLoc offset M.SourcePos {..} =
err :: a
err = error ("The path \"" <> pack fp <> "\" is not absolute. Remember to pass an absolute path to Megaparsec when running a parser")

-- | Make a `Loc` that points to the beginning of a file.
mkInitialLoc :: Path Abs File -> Loc
mkInitialLoc = mkLoc 0 . M.initialPos . fromAbsFile

fromPos :: M.Pos -> Pos
fromPos = Pos . fromIntegral . M.unPos

Expand Down
3 changes: 1 addition & 2 deletions test/Core/Eval/Base.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import Juvix.Compiler.Core.Language
import Juvix.Compiler.Core.Pretty
import Juvix.Compiler.Core.Transformation
import Juvix.Compiler.Core.Translation.FromSource
import Text.Megaparsec.Pos qualified as M

coreEvalAssertion ::
Path Abs File ->
Expand Down Expand Up @@ -90,4 +89,4 @@ doEval ::
doEval f hout tab node =
catchEvalErrorIO defaultLoc (hEvalIO stdin hout (tab ^. identContext) [] node)
where
defaultLoc = singletonInterval (mkLoc 0 (M.initialPos (toFilePath f)))
defaultLoc = singletonInterval (mkInitialLoc f)