From 931652d4f065c06d9061166c961ff9af6750267e Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sun, 5 Dec 2010 00:25:10 +0000 Subject: Remove worthless "macro" system. git-svn-id: http://svn.drobilla.net/resp/resp@299 ad02d1e2-f140-0410-9f75-f8b11f17cedd --- src/parse.cpp | 98 ++++++++++++++++++++++++----------------------------------- src/resp.hpp | 9 ------ 2 files changed, 40 insertions(+), 67 deletions(-) (limited to 'src') diff --git a/src/parse.cpp b/src/parse.cpp index 8a7e3e0..e26ef1f 100644 --- a/src/parse.cpp +++ b/src/parse.cpp @@ -36,18 +36,6 @@ const AST* PEnv::parse(const AST* exp) { const ATuple* tup = exp->to_tuple(); - if (tup) { - THROW_IF(tup->empty(), exp->loc, "Call to empty list"); - const ALexeme* form = tup->head()->to_lexeme(); - if (form) { - MF mf = mac(*form); - if (mf) { - exp = mf(*this, exp)->as_tuple(); // Apply macro - tup = exp->to_tuple(); - } - } - } - if (tup) { THROW_IF(tup->empty(), exp->loc, "Call to empty list"); const ALexeme* form = tup->head()->to_lexeme(); @@ -82,48 +70,6 @@ PEnv::parse(const AST* exp) } -/*************************************************************************** - * Macro Functions * - ***************************************************************************/ - -inline const AST* -macDef(PEnv& penv, const AST* exp) -{ - const ATuple* tup = exp->to_tuple(); - ATuple::const_iterator i = tup->begin(); - THROW_IF(i == tup->end(), tup->loc, "Unexpected end of `def' macro call"); - const AST* arg1 = *(++i); - THROW_IF(i == tup->end(), arg1->loc, "Unexpected end of `def' macro call"); - if (arg1->to_lexeme()) { - return exp; - } else { - // (def (f x) y) => (def f (fn (x) y)) - const ATuple* pat = arg1->to_tuple(); - - List argsExp; - ATuple::const_iterator j = pat->begin(); - for (++j; j != pat->end(); ++j) - argsExp.push_back(*j); - argsExp.head->loc = exp->loc; - const AST* body = *(++i); - - List fnExp; - fnExp.push_back(new ALexeme(exp->loc, "fn")); - fnExp.push_back(argsExp.head); - for (; i != tup->end(); ++i) - fnExp.push_back(*i); - fnExp.head->loc = body->loc; - - List ret; - ret.push_back(tup->head()); - ret.push_back(pat->head()); - ret.push_back(fnExp.head); - ret.head->loc = exp->loc; - return ret.head; - } -} - - /*************************************************************************** * Parser Functions * ***************************************************************************/ @@ -166,6 +112,45 @@ parseQuote(PEnv& penv, const AST* exp, void* arg) return ret; } +inline const AST* +parseDef(PEnv& penv, const AST* exp, void* arg) +{ + const ATuple* tup = exp->as_tuple(); + + ATuple::const_iterator i = tup->begin(); + THROW_IF(i == tup->end(), tup->loc, "Unexpected end of `def' form"); + const AST* arg1 = *(++i); + THROW_IF(i == tup->end(), arg1->loc, "Unexpected end of `def' form"); + if (arg1->to_lexeme()) { + return parseCall(penv, exp, arg); + } else { + // (def (f x) y) => (def f (fn (x) y)) + const ATuple* pat = arg1->to_tuple(); + + List argsExp; + ATuple::const_iterator j = pat->begin(); + for (++j; j != pat->end(); ++j) + argsExp.push_back(*j); + argsExp.head->loc = exp->loc; + const AST* body = *(++i); + + List fnExp; + fnExp.push_back(new ALexeme(exp->loc, "fn")); + fnExp.push_back(argsExp.head); + for (; i != tup->end(); ++i) + fnExp.push_back(*i); + fnExp.head->loc = body->loc; + + List ret; + ret.push_back(tup->head()); + ret.push_back(pat->head()); + ret.push_back(fnExp.head); + ret.head->loc = exp->loc; + + return parseCall(penv, ret.head, arg); + } +} + /*************************************************************************** * Language Definition * @@ -189,15 +174,12 @@ initLang(PEnv& penv, TEnv& tenv) penv.reg(false, "#t", PEnv::Handler(parseBool, &trueVal)); penv.reg(false, "#f", PEnv::Handler(parseBool, &falseVal)); - // Macros - penv.defmac("def", macDef); - // Special forms penv.reg(true, "fn", PEnv::Handler(parseFn)); penv.reg(true, "quote", PEnv::Handler(parseQuote)); penv.reg(true, "if", PEnv::Handler(parseCall)); penv.reg(true, ".", PEnv::Handler(parseCall)); - penv.reg(true, "def", PEnv::Handler(parseCall)); + penv.reg(true, "def", PEnv::Handler(parseDef)); penv.reg(true, "def-type", PEnv::Handler(parseCall)); penv.reg(true, "match", PEnv::Handler(parseCall)); diff --git a/src/resp.hpp b/src/resp.hpp index 35edf31..d524aae 100644 --- a/src/resp.hpp +++ b/src/resp.hpp @@ -572,11 +572,9 @@ AST::operator==(const AST& rhs) const struct PEnv : private map { PEnv() : symID(0) {} typedef const AST* (*PF)(PEnv&, const AST*, void*); ///< Parse Function - typedef const AST* (*MF)(PEnv&, const AST*); ///< Macro Function struct Handler { Handler(PF f, void* a=0) : func(f), arg(a) {} PF func; void* arg; }; map aHandlers; ///< Atom parse functions map lHandlers; ///< List parse functions - map macros; ///< Macro functions void reg(bool list, const string& s, const Handler& h) { (list ? lHandlers : aHandlers).insert(make_pair(sym(s)->str(), h)); } @@ -585,13 +583,6 @@ struct PEnv : private map { map::const_iterator i = handlers.find(s); return (i != handlers.end()) ? &i->second : NULL; } - void defmac(const string& s, const MF f) { - macros.insert(make_pair(s, f)); - } - MF mac(const ALexeme& s) const { - map::const_iterator i = macros.find(s.cppstr); - return (i != macros.end()) ? i->second : NULL; - } string gensymstr(const char* s="_") { return (format("%s_%d") % s % symID++).str(); } ASymbol* gensym(const char* s="_") { return sym(gensymstr(s)); } ASymbol* sym(const string& s, Cursor c=Cursor()) { -- cgit v1.2.1