mirror of
https://github.com/NixOS/nix.git
synced 2025-11-21 01:39:36 +01:00
safer interface for ExprLambda's formals
This commit is contained in:
parent
e43888890f
commit
34f780d747
12 changed files with 105 additions and 82 deletions
|
|
@ -154,13 +154,13 @@ void ExprList::show(const SymbolTable & symbols, std::ostream & str) const
|
|||
void ExprLambda::show(const SymbolTable & symbols, std::ostream & str) const
|
||||
{
|
||||
str << "(";
|
||||
if (hasFormals) {
|
||||
if (auto formals = getFormals()) {
|
||||
str << "{ ";
|
||||
bool first = true;
|
||||
// the natural Symbol ordering is by creation time, which can lead to the
|
||||
// same expression being printed in two different ways depending on its
|
||||
// context. always use lexicographic ordering to avoid this.
|
||||
for (auto & i : getFormalsLexicographic(symbols)) {
|
||||
for (auto & i : formals->lexicographicOrder(symbols)) {
|
||||
if (first)
|
||||
first = false;
|
||||
else
|
||||
|
|
@ -451,20 +451,21 @@ void ExprLambda::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv>
|
|||
if (es.debugRepl)
|
||||
es.exprEnvs.insert(std::make_pair(this, env));
|
||||
|
||||
auto newEnv = std::make_shared<StaticEnv>(nullptr, env, (hasFormals ? getFormals().size() : 0) + (!arg ? 0 : 1));
|
||||
auto newEnv =
|
||||
std::make_shared<StaticEnv>(nullptr, env, (getFormals() ? getFormals()->formals.size() : 0) + (!arg ? 0 : 1));
|
||||
|
||||
Displacement displ = 0;
|
||||
|
||||
if (arg)
|
||||
newEnv->vars.emplace_back(arg, displ++);
|
||||
|
||||
if (hasFormals) {
|
||||
for (auto & i : getFormals())
|
||||
if (auto formals = getFormals()) {
|
||||
for (auto & i : formals->formals)
|
||||
newEnv->vars.emplace_back(i.name, displ++);
|
||||
|
||||
newEnv->sort();
|
||||
|
||||
for (auto & i : getFormals())
|
||||
for (auto & i : formals->formals)
|
||||
if (i.def)
|
||||
i.def->bindVars(es, newEnv);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue