Files
funk/src/runner/runner.h

44 lines
1.2 KiB
C
Raw Normal View History

2025-10-25 21:28:16 +11:00
#pragma once
#include <map>
2025-10-26 20:44:47 +11:00
#include <optional>
#include <variant>
#include <string>
#include <vector>
2025-10-25 21:28:16 +11:00
#include "../parser/parser.h"
2025-10-26 20:44:47 +11:00
class Object {
public:
bool isCustomObject = false;
std::variant<ASTValue, ASTFunction> value;
std::map<std::string, std::variant<Object, ASTFunction, ASTValue>> children;
Object(ASTValue value);
Object(ASTFunction function);
Object();
};
2025-10-25 21:28:16 +11:00
/**
* @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
2025-10-25 21:28:16 +11:00
class Executor {
private:
2025-10-26 20:44:47 +11:00
std::map<std::string, Object> variables;
2025-10-25 21:28:16 +11:00
ASTCodeBlock code;
size_t iterator = 0;
std::optional<ASTNode> consume();
std::optional<ASTNode> peek(int ahead = 1);
2025-10-29 17:59:26 +00:00
void printValue(const ASTValue& arg);
2025-10-25 21:28:16 +11:00
public:
2025-10-26 20:44:47 +11:00
explicit Executor(ASTCodeBlock in, bool isInitCall = false, std::map<std::string, Object> scopeVals = {}, std::vector<Object> args = {});
2025-10-29 11:45:58 +00:00
std::map<std::string, Object> getVariables();
2025-10-25 21:28:16 +11:00
};