-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a Tree transform to check that anoma-get is not used
Apply this transformation to the Tree->Asm translation.
- Loading branch information
1 parent
ab8f681
commit 2edc12d
Showing
11 changed files
with
117 additions
and
4 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
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,23 @@ | ||
module Juvix.Compiler.Tree.Transformation.CheckNoAnoma where | ||
|
||
import Juvix.Compiler.Tree.Data.InfoTable | ||
import Juvix.Compiler.Tree.Error | ||
import Juvix.Compiler.Tree.Extra.Recursors | ||
import Juvix.Compiler.Tree.Transformation.Base | ||
|
||
checkNoAnoma :: forall r. (Member (Error TreeError) r) => InfoTable -> Sem r () | ||
checkNoAnoma = walkT checkNode | ||
where | ||
checkNode :: Symbol -> Node -> Sem r () | ||
checkNode _ = \case | ||
Unop NodeUnop {..} -> case _nodeUnopOpcode of | ||
OpAnomaGet -> | ||
throw | ||
TreeError | ||
{ _treeErrorMsg = "OpAnomaGet is unsupported", | ||
_treeErrorLoc = _nodeUnopInfo ^. nodeInfoLocation | ||
} | ||
OpFail -> return () | ||
OpTrace -> return () | ||
PrimUnop {} -> return () | ||
_ -> return () |
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,67 @@ | ||
module Tree.Transformation.CheckNoAnoma where | ||
|
||
import Base | ||
import Juvix.Compiler.Tree.Error | ||
import Juvix.Compiler.Tree.Transformation as Tree | ||
import Juvix.Compiler.Tree.Translation.FromSource | ||
import Juvix.Data.PPOutput | ||
import Tree.Eval.Negative qualified as Eval | ||
|
||
data CheckNoAnomaTest = CheckNoAnomaTest | ||
{ _testEval :: Eval.NegTest | ||
} | ||
|
||
fromTest :: CheckNoAnomaTest -> TestTree | ||
fromTest = mkTest . toTestDescr | ||
|
||
root :: Path Abs Dir | ||
root = relToProject $(mkRelDir "tests/Tree/negative/") | ||
|
||
treeEvalTransformationErrorAssertion :: | ||
Path Abs File -> | ||
[TransformationId] -> | ||
(JuvixError -> IO ()) -> | ||
(String -> IO ()) -> | ||
Assertion | ||
treeEvalTransformationErrorAssertion mainFile trans checkError step = do | ||
step "Parse" | ||
s <- readFile mainFile | ||
case runParser mainFile s of | ||
Left err -> assertFailure (show (pretty err)) | ||
Right tab0 -> do | ||
step "Validate" | ||
case run $ runError @JuvixError $ applyTransformations [Validate] tab0 of | ||
Left err -> assertFailure (show (pretty (fromJuvixError @GenericError err))) | ||
Right tab1 -> do | ||
unless (null trans) $ | ||
step "Transform" | ||
case run $ runError @JuvixError $ applyTransformations trans tab1 of | ||
Left e -> checkError e | ||
Right {} -> assertFailure "Expected error" | ||
|
||
toTestDescr :: CheckNoAnomaTest -> TestDescr | ||
toTestDescr CheckNoAnomaTest {..} = | ||
let Eval.NegTest {..} = _testEval | ||
tRoot = root <//> _relDir | ||
file' = tRoot <//> _file | ||
checkError :: JuvixError -> IO () | ||
checkError e = | ||
unless | ||
(isJust (fromJuvixError @TreeError e)) | ||
(assertFailure (unpack ("Expected TreeError. got: " <> renderTextDefault e))) | ||
in TestDescr | ||
{ _testName = _name, | ||
_testRoot = tRoot, | ||
_testAssertion = Steps $ treeEvalTransformationErrorAssertion file' [CheckNoAnoma] checkError | ||
} | ||
|
||
allTests :: TestTree | ||
allTests = testGroup "CheckNoAnoma" (map (fromTest . CheckNoAnomaTest) tests) | ||
|
||
tests :: [Eval.NegTest] | ||
tests = | ||
[ Eval.NegTest | ||
"anomaGet" | ||
$(mkRelDir ".") | ||
$(mkRelFile "test009.jvt") | ||
] |
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,5 @@ | ||
-- calling unsupported anoma-get | ||
|
||
function main() : * { | ||
anoma-get(1) | ||
} |