diff options
Diffstat (limited to 'environment.cpp')
-rw-r--r-- | environment.cpp | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/environment.cpp b/environment.cpp index b38d73b..e375353 100644 --- a/environment.cpp +++ b/environment.cpp @@ -146,6 +146,11 @@ static void singlify(AST &ast){ } bool Environment::resolve(AST &ast){ + unordered_set<Name> avoid; + return resolve(ast,avoid); +} + +bool Environment::resolve(AST &ast,unordered_set<Name> &avoid){ if(ast.quoted){ return false; } @@ -160,23 +165,26 @@ bool Environment::resolve(AST &ast){ break; case AST::Type::name: - try { - ast=get(ast.nameval); - resolve(ast); - ret=true; - } catch(NameError){ - // just leave an unknown name as it is + if(avoid.find(ast.nameval)==avoid.end()){ + try { + avoid.insert(ast.nameval); + ast=get(ast.nameval); + resolve(ast,avoid); + ret=true; + } catch(NameError){ + // just leave an unknown name as it is + } } break; case AST::Type::tuple: for(AST &term : ast.terms){ - ret=resolve(term)||ret; + ret=resolve(term,avoid)||ret; } break; case AST::Type::lambda: - ret=resolve(*ast.lambdaval.body)||ret; + ret=resolve(*ast.lambdaval.body,avoid)||ret; break; } @@ -409,6 +417,7 @@ bool Environment::reduce(AST &ast,i64 depth){ ret=reduce(ast.terms[1],depth+1)||ret; if(!hasFree(ast.terms[1],1)){ ast=ast.terms[0].nativeval(ast.terms[1]); + reduce(ast,depth+1); ret=true; } else { cerr<<indent(depth+1)<<"Argument contained free indices, not calling"<<endl; |