mirror of
https://codeberg.org/ProgramSnail/lang_2023.git
synced 2025-12-06 06:58:45 +00:00
interpreter_tree first iteration
This commit is contained in:
parent
7f4cd5ee9a
commit
1ba132bb06
15 changed files with 1829 additions and 1 deletions
43
include/contexts.hpp
Normal file
43
include/contexts.hpp
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
|
||||
// for clangd
|
||||
#include "symbols_info.hpp"
|
||||
|
||||
namespace info {
|
||||
|
||||
class ContextManager {
|
||||
public:
|
||||
void CallFunction(const std::vector<VariableInfo>&);
|
||||
void EnterContext();
|
||||
void ExitContext();
|
||||
|
||||
void DefineVariable(const VariableInfo& variable);
|
||||
void ChangeVariableValue(const std::string& name, const Value& new_value);
|
||||
const Value& GetVariableValue(const std::string& name);
|
||||
private:
|
||||
class Context {
|
||||
public:
|
||||
Context(bool hide_previous = false) : hide_previous_(hide_previous) {}
|
||||
|
||||
void DefineVariable(const VariableInfo& variable);
|
||||
void ChangeVaraibleValue(const std::string& name, const Value& neew_value);
|
||||
const Value& GetVariableValue(const std::string& name);
|
||||
|
||||
bool IsFirst() { return hide_previous_; }
|
||||
private:
|
||||
bool hide_previous_;
|
||||
std::unordered_map<std::string, VariableInfo> variables_;
|
||||
};
|
||||
|
||||
// TODO handle current namespace (for class names, function names, etc.)
|
||||
// TODO ?? are global variables forbidden ??
|
||||
|
||||
Context global_context_;
|
||||
std::vector<Context> contexts_;
|
||||
};
|
||||
|
||||
} // namespace info
|
||||
Loading…
Add table
Add a link
Reference in a new issue