Refactoring for OOP

This commit is contained in:
2025-10-26 20:44:47 +11:00
parent 191410d174
commit 81f836bc94
3 changed files with 112 additions and 39 deletions

View File

@@ -1,9 +1,23 @@
#pragma once
#include <map>
#include <optional>
#include <variant>
#include <string>
#include <vector>
#include "../parser/parser.h"
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();
};
/**
* @class Executor
* @brief Responsible for executing a sequence of operations defined in an abstract syntax tree (AST).
@@ -14,20 +28,14 @@
* and consuming or peeking at individual nodes.
*/
class Object {
public:
std::vector<Object> children;
};
class Executor {
private:
std::map<std::string, ASTFunction> functions;
std::map<std::string, ASTValue> variables;
std::map<std::string, Object> 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 = {});
explicit Executor(ASTCodeBlock in, bool isInitCall = false, std::map<std::string, Object> scopeVals = {}, std::vector<Object> args = {});
};