xo-expression: + LocalEnv::lookup_local_binding()
This commit is contained in:
parent
4b0a2cff2a
commit
8cf89f5eef
2 changed files with 23 additions and 5 deletions
|
|
@ -35,6 +35,11 @@ namespace xo {
|
||||||
int n_arg() const { return argv_.size(); }
|
int n_arg() const { return argv_.size(); }
|
||||||
TypeDescr fn_arg(uint32_t i) const { return argv_[i]->valuetype(); }
|
TypeDescr fn_arg(uint32_t i) const { return argv_[i]->valuetype(); }
|
||||||
|
|
||||||
|
/** report binding path for a formal parameter.
|
||||||
|
* Returns sentinel if @p vname doesn't appear in @ref argv_
|
||||||
|
**/
|
||||||
|
binding_path lookup_local_binding(const std::string & vname) const;
|
||||||
|
|
||||||
/** single-assign this environment's origin **/
|
/** single-assign this environment's origin **/
|
||||||
void assign_origin(Lambda * p) {
|
void assign_origin(Lambda * p) {
|
||||||
assert(origin_ == nullptr);
|
assert(origin_ == nullptr);
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@
|
||||||
namespace xo {
|
namespace xo {
|
||||||
namespace ast {
|
namespace ast {
|
||||||
binding_path
|
binding_path
|
||||||
LocalEnv::lookup_binding(const std::string & vname) const
|
LocalEnv::lookup_local_binding(const std::string & vname) const
|
||||||
{
|
{
|
||||||
int j_slot = 0;
|
int j_slot = 0;
|
||||||
for (const auto & arg : argv_) {
|
for (const auto & arg : argv_) {
|
||||||
|
|
@ -17,12 +17,25 @@ namespace xo {
|
||||||
++j_slot;
|
++j_slot;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto tmp = parent_env_->lookup_binding(vname);
|
return { -2 /*i_link: sentinel*/, 0 };
|
||||||
|
} /*lookup_local_binding*/
|
||||||
|
|
||||||
if (tmp.i_link_ == -1)
|
binding_path
|
||||||
return tmp;
|
LocalEnv::lookup_binding(const std::string & vname) const
|
||||||
|
{
|
||||||
|
{
|
||||||
|
auto local = this->lookup_local_binding(vname);
|
||||||
|
|
||||||
|
if (local.i_link_ == 0)
|
||||||
|
return local;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto free = parent_env_->lookup_binding(vname);
|
||||||
|
|
||||||
|
if (free.i_link_ == -1)
|
||||||
|
return free;
|
||||||
else
|
else
|
||||||
return { tmp.i_link_ + 1, tmp.j_slot_ };
|
return { free.i_link_ + 1, free.j_slot_ };
|
||||||
} /*lookup_binding*/
|
} /*lookup_binding*/
|
||||||
} /*namespace ast*/
|
} /*namespace ast*/
|
||||||
} /*namespace xo*/
|
} /*namespace xo*/
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue