-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9e7a8a9
commit b02f2f8
Showing
14 changed files
with
212 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,27 @@ | ||
module Commands.Dev.Core.Read where | ||
|
||
import Commands.Base | ||
import Commands.Dev.Core.Eval qualified as Eval | ||
import Commands.Dev.Core.Read.Options | ||
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. Members '[Embed IO, App] r => CoreReadOptions -> Sem r () | ||
runCommand opts = do | ||
s' <- embed (readFile f) | ||
tab <- getRight (fst <$> mapLeft JuvixError (Core.runParser f Core.emptyInfoTable s')) | ||
(tab, mnode) <- getRight (mapLeft JuvixError (Core.runParser f Core.emptyInfoTable s')) | ||
let tab' = Core.applyTransformations (opts ^. coreReadTransformations) tab | ||
renderStdOut (Core.ppOut opts tab') | ||
embed (Scoper.scopeTrace tab') | ||
unless (opts ^. coreReadNoPrint) (renderStdOut (Core.ppOut opts tab')) | ||
whenJust mnode $ doEval tab' | ||
where | ||
doEval :: Core.InfoTable -> Core.Node -> Sem r () | ||
doEval tab' node = when (opts ^. coreReadEval) $ do | ||
embed (putStrLn "--------------------------------") | ||
embed (putStrLn "| Eval |") | ||
embed (putStrLn "--------------------------------") | ||
Eval.evalAndPrint (project opts) tab' node | ||
f :: FilePath | ||
f = opts ^. coreReadInputFile . pathPath |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
module Juvix.Compiler.Core.Scoper where | ||
|
||
import Juvix.Compiler.Core.Data.InfoTable | ||
import Juvix.Compiler.Core.Extra | ||
import Juvix.Compiler.Core.Language | ||
import Juvix.Compiler.Core.Pretty | ||
import Juvix.Compiler.Core.Transformation.Base | ||
|
||
type ScopeError = Text | ||
|
||
scopeCheck :: InfoTable -> Maybe ScopeError | ||
scopeCheck = either Just (const Nothing) . run . runError . walkT goTopNode | ||
|
||
goTopNode :: Members '[Error ScopeError] r => Symbol -> Node -> Sem r () | ||
goTopNode sym = runReader sym . walkN check | ||
|
||
check :: Members '[Reader Symbol, Error ScopeError] r => Index -> Node -> Sem r () | ||
check k = \case | ||
NVar v | ||
| v ^. varIndex < k -> return () | ||
| otherwise -> scopeErr ("variable " <> ppTrace (NVar v) <> " is out of scope") | ||
_ -> return () | ||
|
||
scopeErr :: Members '[Reader Symbol, Error ScopeError] r => Text -> Sem r a | ||
scopeErr msg = do | ||
sym <- ask @Symbol | ||
throw @ScopeError ("Scope error in the definition of " <> show sym <> "\n" <> msg) | ||
|
||
-- | prints the scope error without exiting | ||
scopeTrace :: InfoTable -> IO () | ||
scopeTrace i = whenJust (scopeCheck i) putStrLn |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.