![]() |
ArkScript
A small, fast, functional and scripting language for video games
|
The ArkScript AST optimizer. More...
#include <Optimizer.hpp>
Public Member Functions | |
Optimizer (unsigned debug) noexcept | |
Construct a new Optimizer. | |
void | process (const Node &ast) override |
Send the AST to the optimizer, then run the different optimization strategies on it. | |
const Node & | ast () const noexcept override |
Returns the modified AST. | |
![]() | |
Pass (std::string name, unsigned debug_level) | |
Construct a new Pass object. | |
virtual | ~Pass ()=default |
Private Member Functions | |
void | countAndPruneDeadCode (Node &node) |
Count the occurrences of each symbol in the AST, recursively, and prune if false/true, while false/true. | |
void | pruneUnusedGlobalVariables (Node &node) |
Remove unused global variables from the AST. | |
Private Attributes | |
Node | m_ast |
std::unordered_map< std::string, unsigned > | m_sym_appearances |
Additional Inherited Members | |
![]() | |
Logger | m_logger |
The ArkScript AST optimizer.
Definition at line 28 of file Optimizer.hpp.
|
explicitnoexcept |
Construct a new Optimizer.
debug | level of debug |
Definition at line 5 of file Optimizer.cpp.
|
nodiscardoverridevirtualnoexcept |
Returns the modified AST.
Implements Ark::internal::Pass.
Definition at line 28 of file Optimizer.cpp.
References m_ast.
Referenced by Ark::Welder::computeAST(), and process().
|
private |
Count the occurrences of each symbol in the AST, recursively, and prune if false/true, while false/true.
node |
Definition at line 33 of file Optimizer.cpp.
References Ark::internal::Node::arkNamespace(), Ark::internal::Namespace::ast, Ark::internal::Capture, Ark::internal::Node::constList(), countAndPruneDeadCode(), Ark::internal::Field, Ark::internal::If, Ark::internal::Node::isListLike(), Ark::internal::Keyword, Ark::internal::List, Ark::internal::Node::list(), m_sym_appearances, Ark::internal::Namespace, Ark::internal::Node::nodeType(), Ark::internal::Node::string(), Ark::internal::Symbol, Ark::internal::Unused, and Ark::internal::While.
Referenced by countAndPruneDeadCode(), and process().
|
overridevirtual |
Send the AST to the optimizer, then run the different optimization strategies on it.
ast |
Implements Ark::internal::Pass.
Definition at line 9 of file Optimizer.cpp.
References ast(), countAndPruneDeadCode(), Ark::internal::Node::debugPrint(), Ark::internal::List, m_ast, Ark::internal::Pass::m_logger, Ark::internal::Node::nodeType(), pruneUnusedGlobalVariables(), Ark::internal::Logger::shouldTrace(), Ark::internal::Logger::trace(), Ark::internal::Logger::traceEnd(), and Ark::internal::Logger::traceStart().
Referenced by Ark::Welder::computeAST().
|
private |
Remove unused global variables from the AST.
node |
Definition at line 85 of file Optimizer.cpp.
References Ark::internal::Begin, Ark::internal::Logger::debug(), Ark::internal::Keyword, Ark::internal::Let, Ark::internal::List, Ark::internal::Node::list(), Ark::internal::Pass::m_logger, m_sym_appearances, Ark::internal::Mut, Ark::internal::Namespace, pruneUnusedGlobalVariables(), and Ark::internal::Unused.
Referenced by process(), and pruneUnusedGlobalVariables().
|
private |
Definition at line 53 of file Optimizer.hpp.
|
private |
Definition at line 54 of file Optimizer.hpp.
Referenced by countAndPruneDeadCode(), and pruneUnusedGlobalVariables().