diff options
author | Clyne Sullivan <clyne@bitgloo.com> | 2024-06-15 08:04:15 -0400 |
---|---|---|
committer | Clyne Sullivan <clyne@bitgloo.com> | 2024-06-15 08:04:15 -0400 |
commit | 0ad40ced64ba5b2b83f7c9274efea1aa3677a534 (patch) | |
tree | d019d32a7919f52e4aa6897bfa279ed57ef7038f /var.cpp | |
parent | 47d7c964d075f92b9ce657f1b946f5bd6895439b (diff) |
break code into separate files
Diffstat (limited to 'var.cpp')
-rw-r--r-- | var.cpp | 42 |
1 files changed, 42 insertions, 0 deletions
@@ -0,0 +1,42 @@ +#include "var.hpp" + +#include <list> +#include <map> +#include <string> + +static std::list<std::map<std::string, Var>> llvmVars; + +Var Var::lookup(const std::string& name, int skip) +{ + for (auto sc = llvmVars.rbegin(); sc != llvmVars.rend(); ++sc) { + if (skip > 0) { + --skip; + continue; + } + if (sc->contains(name)) + return (*sc)[name]; + } + + return {}; +} + +void Var::pushScope() +{ + llvmVars.emplace_back(); +} + +void Var::popScope() +{ + llvmVars.pop_back(); +} + +Var& Var::addGlobal(const std::string& name, Var var) +{ + return llvmVars.front().emplace(name, var).first->second; +} + +Var& Var::addLocal(const std::string& name, Var var) +{ + return llvmVars.back().emplace(name, var).first->second; +} + |