#include "names.h" #include "utils.h" inline void VariableContainer::CreateFrame() { StackScopes.push(std::unordered_map()); } void VariableContainer::DestroyFrame() { if (StackScopes.empty()) throw FatalError("DestroyFrame: empty stack"); StackScopes.pop(); } std::any VariableContainer::ReadVariable(const std::string &name) { if (StackScopes.size()) { auto &top = StackScopes.top(); if (top.find(name) != top.end()) return top[name]; } if (GlobalScope.find(name) != GlobalScope.end()) return GlobalScope[name]; throw InterpretException(("ReadVariable: " + name + " not found").c_str()); } void VariableContainer::WriteVariable(const std::string &name, const std::any &value) { if (StackScopes.empty()) { GlobalScope[name] = value; return; } auto &top = StackScopes.top(); if (top.find(name) != top.end()) { top[name] = value; return; } if (GlobalScope.find(name) != GlobalScope.end()) { GlobalScope[name] = value; return; } top[name] = value; }