ArkScript
A small, fast, functional and scripting language for video games
Executor.cpp
Go to the documentation of this file.
2 
4 
5 namespace Ark::internal
6 {
7  MacroExecutor::MacroExecutor(MacroProcessor* macroprocessor, unsigned debug) :
8  m_debug(debug),
9  m_macroprocessor(macroprocessor)
10  {}
11 
13  {}
14 
15  Node* MacroExecutor::findNearestMacro(const std::string& name)
16  {
17  return m_macroprocessor->findNearestMacro(name);
18  }
19 
21  {
23  }
24 
25  bool MacroExecutor::isTruthy(const Node& node)
26  {
27  return m_macroprocessor->isTruthy(node);
28  }
29 
30  Node MacroExecutor::evaluate(Node& node, bool is_not_body)
31  {
32  return m_macroprocessor->evaluate(node, is_not_body);
33  }
34 
35  void MacroExecutor::unify(const std::unordered_map<std::string, Node>& map, Node& target, Node* parent)
36  {
37  m_macroprocessor->unify(map, target, parent);
38  }
39 
40  void MacroExecutor::throwMacroProcessingError(const std::string& message, const Node& node)
41  {
43  }
44 
46  {
47  return m_macroprocessor->applyMacro(node);
48  }
49 
50  bool MacroExecutor::isPredefined(const std::string& symbol)
51  {
52  return m_macroprocessor->isPredefined(symbol);
53  }
54 }
The base class for all MacroExecutors.
Handles the macros and their expansion in ArkScript source code.
Node evaluate(Node &node, bool is_not_body)
Evaluate only the macros.
Definition: Executor.cpp:30
MacroExecutor(MacroProcessor *macroprocessor, unsigned debug=0)
Construct a new Macro Executor object.
Definition: Executor.cpp:7
MacroProcessor * m_macroprocessor
Definition: Executor.hpp:63
bool isTruthy(const Node &node)
Check if a node can be evaluated to true.
Definition: Executor.cpp:25
void throwMacroProcessingError(const std::string &message, const Node &node)
Throw a macro processing error.
Definition: Executor.cpp:40
virtual ~MacroExecutor()
Need a virtual destructor to correctly destory object.
Definition: Executor.cpp:12
void registerMacro(Node &node)
Registers macros based on their type.
Definition: Executor.cpp:20
Node * findNearestMacro(const std::string &name)
Find the nearest macro matching a giving name.
Definition: Executor.cpp:15
void unify(const std::unordered_map< std::string, Node > &, Node &, Node *)
Applies the spread operator.
Definition: Executor.cpp:35
bool isPredefined(const std::string &symbol)
Check if a given symbol is a predefined macro.
Definition: Executor.cpp:50
bool applyMacroProxy(Node &node)
Execute a node, trying to emplace macros calls.
Definition: Executor.cpp:45
The class handling the macros definitions and calls, given an AST.
Definition: Processor.hpp:30
void unify(const std::unordered_map< std::string, Node > &map, Node &target, Node *parent, std::size_t index=0)
Unify a target node with a given map symbol => replacement node, recursively.
Definition: Processor.cpp:218
void registerMacro(Node &node)
Registers macros based on their type.
Definition: Processor.cpp:51
Node evaluate(Node &node, bool is_not_body=false)
Evaluate only the macros.
Definition: Processor.cpp:245
bool isTruthy(const Node &node)
Check if a node can be evaluated to true.
Definition: Processor.cpp:481
void throwMacroProcessingError(const std::string &message, const Node &node)
Throw a macro processing error.
Definition: Processor.cpp:624
bool isPredefined(const std::string &symbol)
Check if a given symbol is a predefined macro or not.
Definition: Processor.cpp:534
bool applyMacro(Node &node)
Apply a macro on a given node.
Definition: Processor.cpp:213
Node * findNearestMacro(const std::string &name)
Find the nearest macro matching a given name.
Definition: Processor.cpp:499
A node of an Abstract Syntax Tree for ArkScript.
Definition: Node.hpp:29