diff options
author | Clyne Sullivan <clyne@bitgloo.com> | 2024-06-20 18:01:48 -0400 |
---|---|---|
committer | Clyne Sullivan <clyne@bitgloo.com> | 2024-06-20 18:01:48 -0400 |
commit | 95901f3a5fa0ec18128030c915d1d94bade5de94 (patch) | |
tree | 53c66d5230fa398688c1a5fefcd2e266ba577db6 /var.cpp | |
parent | c546646cd46e9b523c3457fa6e867951ac37daba (diff) |
global env; alloca locals
kinda messy
Diffstat (limited to 'var.cpp')
-rw-r--r-- | var.cpp | 21 |
1 files changed, 11 insertions, 10 deletions
@@ -17,15 +17,11 @@ */ #include "var.hpp" -#include <list> -#include <map> -#include <string> - -static std::list<std::map<std::string, Var>> llvmVars; +std::list<std::map<std::string, Var>> Var::vars; Var Var::lookup(const std::string& name, int skip) { - for (auto sc = llvmVars.rbegin(); sc != llvmVars.rend(); ++sc) { + for (auto sc = vars.rbegin(); sc != vars.rend(); ++sc) { if (skip > 0) { --skip; continue; @@ -37,23 +33,28 @@ Var Var::lookup(const std::string& name, int skip) return {}; } +Var Var::lookupLocal(const std::string& name) +{ + return vars.back().contains(name) ? vars.back()[name] : Var(); +} + void Var::pushScope() { - llvmVars.emplace_back(); + vars.emplace_back(); } void Var::popScope() { - llvmVars.pop_back(); + vars.pop_back(); } Var& Var::addGlobal(const std::string& name, Var var) { - return llvmVars.front().emplace(name, var).first->second; + return vars.front().emplace(name, var).first->second; } Var& Var::addLocal(const std::string& name, Var var) { - return llvmVars.back().emplace(name, var).first->second; + return vars.back().emplace(name, var).first->second; } |