ArkScript
A small, fast, functional and scripting language for video games
Executor.cpp
Go to the documentation of this file.
2
4
5namespace Ark::internal
6{
7 MacroExecutor::MacroExecutor(MacroProcessor* macroprocessor, unsigned debug) :
8 m_debug(debug),
9 m_macroprocessor(macroprocessor)
10 {}
11
13 {}
14
15 const Node* MacroExecutor::findNearestMacro(const std::string& name) const
16 {
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:62
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
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
const Node * findNearestMacro(const std::string &name) const
Find the nearest macro matching a giving name.
Definition: Executor.cpp:15
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:31
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
const Node * findNearestMacro(const std::string &name) const
Find the nearest macro matching a given name.
Definition: Processor.cpp:503
bool isTruthy(const Node &node)
Check if a node can be evaluated to true.
Definition: Processor.cpp:485
void throwMacroProcessingError(const std::string &message, const Node &node)
Throw a macro processing error.
Definition: Processor.cpp:621
bool isPredefined(const std::string &symbol)
Check if a given symbol is a predefined macro or not.
Definition: Processor.cpp:531
bool applyMacro(Node &node)
Apply a macro on a given node.
Definition: Processor.cpp:213
A node of an Abstract Syntax Tree for ArkScript.
Definition: Node.hpp:29