-
-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ast optimizer): adding AST optimization tests and fixing the jso…
…n compiler to accept (if cond then) and not just (if cond then else)
- Loading branch information
Showing
13 changed files
with
151 additions
and
97 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -300,7 +300,6 @@ namespace Ark::internal | |
} | ||
|
||
case NodeType::Unused: | ||
os << "Unused:" << string(); | ||
break; | ||
} | ||
return os; | ||
|
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,33 @@ | ||
#include <boost/ut.hpp> | ||
|
||
#include <CLI/JsonCompiler.hpp> | ||
#include <string> | ||
|
||
#include "TestsHelper.hpp" | ||
|
||
using namespace boost; | ||
|
||
ut::suite<"Optimizer"> optimizer_suite = [] { | ||
using namespace ut; | ||
|
||
"[generate optimized ast]"_test = [] { | ||
iter_test_files( | ||
"OptimizerSuite", | ||
[](TestData&& data) { | ||
JsonCompiler compiler(false, { ARK_TESTS_ROOT "lib/" }, Ark::FeatureASTOptimizer); | ||
|
||
std::string json; | ||
should("parse " + data.stem) = [&] { | ||
expect(nothrow([&] { | ||
mut(compiler).feed(data.path); | ||
json = mut(compiler).compile(); | ||
})); | ||
}; | ||
|
||
should("output the expected AST for " + data.stem) = [&] { | ||
expect(that % json == data.expected); | ||
}; | ||
}, | ||
/* expected_ext= */ "json"); | ||
}; | ||
}; |
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 |
---|---|---|
|
@@ -30,4 +30,4 @@ ut::suite<"AST"> ast_suite = [] { | |
}, | ||
/* expected_ext= */ "json"); | ||
}; | ||
}; | ||
}; |
4 changes: 4 additions & 0 deletions
4
tests/unittests/resources/OptimizerSuite/dead_code_elimination.ark
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,4 @@ | ||
(if false (print "false")) | ||
(if true (print "true")) | ||
(if false () (print "false2")) | ||
(while false (print "false3")) |
1 change: 1 addition & 0 deletions
1
tests/unittests/resources/OptimizerSuite/dead_code_elimination.json
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 @@ | ||
{"type": "Begin", "children": [{"type": "FunctionCall", "name": {"type": "Symbol", "name": "print"}, "args": [{"type": "String", "value": "true"}]}, {"type": "FunctionCall", "name": {"type": "Symbol", "name": "print"}, "args": [{"type": "String", "value": "false2"}]}]} |
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,4 @@ | ||
(let a 1) | ||
(let b 2) | ||
(let c 3) | ||
(print b) |
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 @@ | ||
{"type": "Begin", "children": [{"type": "Let", "name": {"type": "Symbol", "name": "b"}, "value": {"type": "Number", "value": 2}}, {"type": "FunctionCall", "name": {"type": "Symbol", "name": "print"}, "args": [{"type": "Symbol", "name": "b"}]}]} |