Skip to content

Commit

Permalink
refactor: removing the MacroExecutorPipeline and integrating it direc…
Browse files Browse the repository at this point in the history
…tly inside the MacroProcessor

It was in fact just a class to hold a vector and a single public method
to run a loop and call methods on the objects inside the vector.
  • Loading branch information
SuperFola committed Jul 28, 2024
1 parent 3b5d80b commit 592a68a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 83 deletions.
55 changes: 0 additions & 55 deletions include/Ark/Compiler/Macros/Pipeline.hpp

This file was deleted.

6 changes: 4 additions & 2 deletions include/Ark/Compiler/Macros/Processor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@

#include <Ark/Compiler/AST/Node.hpp>
#include <Ark/Compiler/Macros/MacroScope.hpp>
#include <Ark/Compiler/Macros/Pipeline.hpp>

#include <unordered_map>
#include <memory>
#include <string>

namespace Ark::internal
{
class MacroExecutor;

/**
* @brief The class handling the macros definitions and calls, given an AST
*
Expand Down Expand Up @@ -55,7 +57,7 @@ namespace Ark::internal
unsigned m_debug; ///< The debug level
Node m_ast; ///< The modified AST
std::vector<MacroScope> m_macros; ///< Handling macros in a scope fashion
MacroExecutorPipeline m_executor_pipeline;
std::vector<std::shared_ptr<MacroExecutor>> m_executors;
std::vector<std::string> m_predefined_macros; ///< Already existing macros, non-keywords, non-builtins
std::unordered_map<std::string, Node> m_defined_functions;

Expand Down
21 changes: 0 additions & 21 deletions src/arkreactor/Compiler/Macros/Pipeline.cpp

This file was deleted.

18 changes: 13 additions & 5 deletions src/arkreactor/Compiler/Macros/Processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <Ark/Constants.hpp>
#include <Ark/Exceptions.hpp>
#include <Ark/Builtins/Builtins.hpp>
#include <Ark/Compiler/Macros/Executor.hpp>
#include <Ark/Compiler/Macros/Executors/Symbol.hpp>
#include <Ark/Compiler/Macros/Executors/Function.hpp>
#include <Ark/Compiler/Macros/Executors/Conditional.hpp>
Expand All @@ -19,10 +20,9 @@ namespace Ark::internal
m_debug(debug)
{
// create executors pipeline
m_executor_pipeline = MacroExecutorPipeline(
{ std::make_shared<SymbolExecutor>(this),
std::make_shared<ConditionalExecutor>(this),
std::make_shared<FunctionExecutor>(this) });
m_executors = { { std::make_shared<SymbolExecutor>(this),
std::make_shared<ConditionalExecutor>(this),
std::make_shared<FunctionExecutor>(this) } };

m_predefined_macros = {
"symcat",
Expand Down Expand Up @@ -205,7 +205,15 @@ namespace Ark::internal
MaxMacroProcessingDepth),
node);

return m_executor_pipeline.applyMacro(node, depth);
for (const auto& executor : m_executors)
{
if (executor->canHandle(node))
{
if (executor->applyMacro(node, depth))
return true;
}
}
return false;
}

void MacroProcessor::unify(const std::unordered_map<std::string, Node>& map, Node& target, Node* parent, const std::size_t index, const std::size_t unify_depth)
Expand Down

0 comments on commit 592a68a

Please sign in to comment.