xo-reader: feat: + var lookup in envframestack, psm

This commit is contained in:
Roland Conybeare 2024-08-19 18:11:28 -04:00
commit eed5cdf691
4 changed files with 51 additions and 0 deletions

View file

@ -6,6 +6,8 @@
#include "envframestack.hpp"
namespace xo {
using xo::ast::Variable;
namespace scm {
envframe &
envframestack::top_envframe() {
@ -50,6 +52,20 @@ namespace xo {
}
}
rp<Variable>
envframestack::lookup(const std::string & x) const {
for (std::size_t i = 0, z = this->size(); i < z; ++i) {
const auto & frame = (*this)[i];
auto retval = frame.lookup(x);
if (retval)
return retval;
}
return nullptr;
}
void
envframestack::print(std::ostream & os) const {
os << "<envframestack"

View file

@ -7,7 +7,14 @@
#include "exprstatestack.hpp"
namespace xo {
using xo::ast::Variable;
namespace scm {
rp<Variable>
parserstatemachine::lookup_var(const std::string & x) const {
return p_env_stack_->lookup(x);
}
std::unique_ptr<exprstate>
parserstatemachine::pop_exprstate() {
return p_stack_->pop_exprstate();
@ -22,6 +29,16 @@ namespace xo {
parserstatemachine::push_exprstate(std::unique_ptr<exprstate> x) {
p_stack_->push_exprstate(std::move(x));
}
void
parserstatemachine::push_envframe(envframe x) {
p_env_stack_->push_envframe(std::move(x));
}
void
parserstatemachine::pop_envframe() {
p_env_stack_->pop_envframe();
}
} /*namespace scm*/
} /*namespace xo*/