diff options
author | David Robillard <d@drobilla.net> | 2010-12-05 00:25:10 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2010-12-05 00:25:10 +0000 |
commit | 931652d4f065c06d9061166c961ff9af6750267e (patch) | |
tree | 6ea7bc4ea6ce0ad08b85f973e52c4e4eabd8f800 /src/parse.cpp | |
parent | 5ca01630edc38087b722e1c22b20edc82d871dd7 (diff) | |
download | resp-931652d4f065c06d9061166c961ff9af6750267e.tar.gz resp-931652d4f065c06d9061166c961ff9af6750267e.tar.bz2 resp-931652d4f065c06d9061166c961ff9af6750267e.zip |
Remove worthless "macro" system.
git-svn-id: http://svn.drobilla.net/resp/resp@299 ad02d1e2-f140-0410-9f75-f8b11f17cedd
Diffstat (limited to 'src/parse.cpp')
-rw-r--r-- | src/parse.cpp | 98 |
1 files changed, 40 insertions, 58 deletions
diff --git a/src/parse.cpp b/src/parse.cpp index 8a7e3e0..e26ef1f 100644 --- a/src/parse.cpp +++ b/src/parse.cpp @@ -40,18 +40,6 @@ PEnv::parse(const AST* exp) 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(); - if (form) { const PEnv::Handler* h = handler(true, form->cppstr); if (h) return h->func(*this, exp, h->arg); // Parse special form @@ -83,48 +71,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<ATuple, const AST> 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<ATuple, const AST> 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<ATuple, const AST> 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<ATuple, const AST> 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<ATuple, const AST> 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<ATuple, const AST> 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)); |