2025-10-25 21:28:16 +11:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
|
|
|
|
|
|
#include "../parser/parser.h"
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @class Executor
|
|
|
|
|
* @brief Responsible for executing a sequence of operations defined in an abstract syntax tree (AST).
|
|
|
|
|
*
|
|
|
|
|
* This class provides execution functionality for ASTCodeBlock objects.
|
|
|
|
|
* It maintains a mapping of variables and functions that can be used within the
|
|
|
|
|
* context of execution. The class implements mechanisms for traversing AST nodes
|
|
|
|
|
* and consuming or peeking at individual nodes.
|
|
|
|
|
*/
|
2025-10-26 19:16:35 +11:00
|
|
|
|
|
|
|
|
class Object {
|
|
|
|
|
public:
|
|
|
|
|
std::vector<Object> children;
|
|
|
|
|
};
|
|
|
|
|
|
2025-10-25 21:28:16 +11:00
|
|
|
class Executor {
|
|
|
|
|
private:
|
|
|
|
|
std::map<std::string, ASTFunction> functions;
|
|
|
|
|
std::map<std::string, ASTValue> variables;
|
|
|
|
|
ASTCodeBlock code;
|
|
|
|
|
size_t iterator = 0;
|
|
|
|
|
std::optional<ASTNode> consume();
|
|
|
|
|
std::optional<ASTNode> peek(int ahead = 1);
|
|
|
|
|
public:
|
|
|
|
|
explicit Executor(ASTCodeBlock in, bool isInitCall = false, std::map<std::string, ASTValue> scopeVals = {}, std::map<std::string, ASTFunction> scopeFns = {}, std::vector<ASTValue> args = {});
|
|
|
|
|
};
|
|
|
|
|
|