/* file GlobalEnv.hpp * * author: Roland Conybeare, Jun 2024 */ #pragma once #include "Environment.hpp" #include namespace xo { namespace ast { class GlobalEnv : public Environment { public: /** create instance. Probably only need one of these **/ static ref::rp make() { return new GlobalEnv(); } ref::brw require_global(const std::string & vname, ref::brw expr) { global_map_[vname] = expr.get(); return expr; } /*require_global*/ // ----- Environment ----- virtual ref::brw lookup_var(const std::string & vname) const { auto ix = global_map_.find(vname); if (ix == global_map_.end()) { /* not found */ return ref::brw::from_native(nullptr); } return ix->second; } private: GlobalEnv() = default; private: /* for assignable globals, need to allocate memory * addresses for these. */ std::map> global_map_; }; } /*namespace ast*/ } /*namespace xo*/ /* end GlobalEnv.hpp */