xo-expression: + binding_path + assoc w/ each Variable

This commit is contained in:
Roland Conybeare 2024-07-02 16:57:07 -04:00
commit 14796663b1
8 changed files with 105 additions and 3 deletions

View file

@ -7,6 +7,7 @@ set(SELF_SRCS
Lambda.cpp
Variable.cpp
IfExpr.cpp
LocalEnv.cpp
)
xo_add_shared_library4(${SELF_LIB} ${PROJECT_NAME}Targets ${PROJECT_VERSION} 1 ${SELF_SRCS})

View file

@ -0,0 +1,31 @@
/* file LocalEnv.cpp
*
* author: Roland Conybeare
*/
#include "LocalEnv.hpp"
namespace xo {
namespace ast {
binding_path
LocalEnv::lookup_binding(const std::string & vname) const
{
int j_slot = 0;
for (const auto & arg : argv_) {
if (arg->name() == vname)
return { 0 /*i_link*/, j_slot };
++j_slot;
}
auto tmp = parent_env_->lookup_binding(vname);
if (tmp.i_link_ == -1)
return tmp;
else
return { tmp.i_link_ + 1, tmp.j_slot_ };
} /*lookup_binding*/
} /*namespace ast*/
} /*namespace xo*/
/* end LocalEnv.cpp */

View file

@ -1,9 +1,16 @@
/* @file Variable.cpp */
#include "Variable.hpp"
#include "Environment.hpp"
namespace xo {
namespace ast {
void
Variable::attach_envs(ref::brw<Environment> e) {
/** e makes accessible all enclosing lexical scopes **/
this->path_ = e->lookup_binding(this->name_);
} /*attach_envs*/
void
Variable::display(std::ostream & os) const {
os << "<Variable"