From ba5c979bafd4be26ceeea41d09ca0c5c6025bdd5 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Tue, 13 Oct 2009 22:10:48 +0000 Subject: Remove unnecessary lexical addressing stuff. git-svn-id: http://svn.drobilla.net/resp/tuplr@211 ad02d1e2-f140-0410-9f75-f8b11f17cedd --- src/constrain.cpp | 7 +++---- src/tuplr.hpp | 34 ++++++---------------------------- 2 files changed, 9 insertions(+), 32 deletions(-) diff --git a/src/constrain.cpp b/src/constrain.cpp index 6f68b4c..e751895 100644 --- a/src/constrain.cpp +++ b/src/constrain.cpp @@ -75,10 +75,9 @@ AString::constrain(TEnv& tenv, Constraints& c) const void ASymbol::constrain(TEnv& tenv, Constraints& c) const { - addr = tenv.lookup(this); - if (!addr) - throw Error(loc, (format("undefined symbol `%1%'") % cppstr).str()); - c.push_back(Constraint(tenv.var(this), tenv.deref(addr).second, loc)); + pair* ref = tenv.ref(this); + THROW_IF(!ref, loc, (format("undefined symbol `%1%'") % cppstr).str()); + c.push_back(Constraint(tenv.var(this), ref->second, loc)); } void diff --git a/src/tuplr.hpp b/src/tuplr.hpp index 313286a..b7f4adf 100644 --- a/src/tuplr.hpp +++ b/src/tuplr.hpp @@ -62,13 +62,6 @@ struct Error { string msg; }; -/// Lexical Address -struct LAddr { - LAddr(unsigned u=0, unsigned o=0) : up(u), over(o) {} - operator bool() const { return !(up == 0 && over == 0); } - unsigned up, over; -}; - /// Generic Lexical Environment template struct Env : public list< vector< pair > > { @@ -90,21 +83,6 @@ struct Env : public list< vector< pair > > { return &b->second; return NULL; } - LAddr lookup(const K& key) const { - unsigned up = 0; - for (typename Env::const_iterator f = this->begin(); f != this->end(); ++f, ++up) - for (unsigned over = 0; over < f->size(); ++over) - if ((*f)[over].first == key) - return LAddr(up + 1, over + 1); - return LAddr(); - } - V& deref(LAddr addr) { - assert(addr); - typename Env::iterator f = this->begin(); - for (unsigned u = 1; u < addr.up; ++u, ++f) { assert(f != this->end()); } - assert(f->size() > addr.over - 1); - return (*f)[addr.over - 1].second; - } }; @@ -244,8 +222,7 @@ struct ASymbol : public AST { bool operator==(const AST& rhs) const { return this == &rhs; } void constrain(TEnv& tenv, Constraints& c) const; CVal compile(CEnv& cenv); - mutable LAddr addr; - const string cppstr; + const string cppstr; private: friend class PEnv; ASymbol(const string& s, Cursor c) : AST(c), cppstr(s) {} @@ -594,12 +571,13 @@ struct TEnv : public Env< const ASymbol*, pair > { return ref(penv.sym(name))->second; } AST* resolve(AST* ast) { - const ASymbol* sym = ast->to(); - return (sym && sym->addr) ? ref(sym)->first : ast; + const ASymbol* sym = ast->to(); + const pair* rec = ref(sym); + return rec ? rec->first : ast; } const AST* resolve(const AST* ast) { const ASymbol* sym = ast->to(); - return (sym && sym->addr) ? ref(sym)->first : ast; + return sym ? ref(sym)->first : ast; } static Subst buildSubst(AType* fnT, const AType& argsT); @@ -664,7 +642,7 @@ struct CEnv { AType* type(AST* ast, const Subst& subst = Subst()) const { ASymbol* sym = ast->to(); if (sym) - return sym->addr ? tenv.deref(sym->addr).second : NULL; + return tenv.ref(sym)->second; return tsubst.apply(subst.apply(tenv.vars[ast]))->to(); } void def(const ASymbol* sym, AST* c, AType* t, CVal v) { -- cgit v1.2.1