diff options
Diffstat (limited to 'src/parse.cpp')
-rw-r--r-- | src/parse.cpp | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/src/parse.cpp b/src/parse.cpp index 7f107aa..8a7e3e0 100644 --- a/src/parse.cpp +++ b/src/parse.cpp @@ -23,16 +23,16 @@ using namespace std; -ATuple* +const ATuple* parseTuple(PEnv& penv, const ATuple* e) { - List<ATuple, AST> ret; + List<ATuple, const AST> ret; FOREACHP(ATuple::const_iterator, i, e) ret.push_back(penv.parse(*i)); return ret.head; } -AST* +const AST* PEnv::parse(const AST* exp) { const ATuple* tup = exp->to_tuple(); @@ -86,7 +86,7 @@ PEnv::parse(const AST* exp) * Macro Functions * ***************************************************************************/ -inline AST* +inline const AST* macDef(PEnv& penv, const AST* exp) { const ATuple* tup = exp->to_tuple(); @@ -95,28 +95,28 @@ macDef(PEnv& penv, const AST* exp) const AST* arg1 = *(++i); THROW_IF(i == tup->end(), arg1->loc, "Unexpected end of `def' macro call"); if (arg1->to_lexeme()) { - return const_cast<AST*>(exp); + return exp; } else { // (def (f x) y) => (def f (fn (x) y)) const ATuple* pat = arg1->to_tuple(); - List<ATuple, AST> argsExp; + List<ATuple, const AST> argsExp; ATuple::const_iterator j = pat->begin(); for (++j; j != pat->end(); ++j) - argsExp.push_back(const_cast<AST*>(*j)); + argsExp.push_back(*j); argsExp.head->loc = exp->loc; const AST* body = *(++i); - List<ATuple, AST> fnExp; + 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(const_cast<AST*>(*i)); + fnExp.push_back(*i); fnExp.head->loc = body->loc; - List<ATuple, AST> ret; - ret.push_back(const_cast<AST*>(tup->head())); - ret.push_back(const_cast<AST*>(pat->head())); + 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; @@ -128,26 +128,26 @@ macDef(PEnv& penv, const AST* exp) * Parser Functions * ***************************************************************************/ -inline AST* +inline const AST* parseCall(PEnv& penv, const AST* exp, void* arg) { return parseTuple(penv, exp->to_tuple()); } -inline AST* +inline const AST* parseBool(PEnv& penv, const AST* exp, void* arg) { return new ALiteral<bool>(T_BOOL, *reinterpret_cast<bool*>(arg), exp->loc); } -inline AST* +inline const AST* parseFn(PEnv& penv, const AST* exp, void* arg) { const ATuple* texp = exp->to_tuple(); ATuple::const_iterator a = texp->begin(); THROW_IF(++a == texp->end(), exp->loc, "Unexpected end of `fn' form"); - ATuple* prot = parseTuple(penv, (*a++)->to_tuple()); - List<ATuple, AST> ret(new ATuple(penv.sym("fn"), NULL, Cursor())); + const ATuple* prot = parseTuple(penv, (*a++)->to_tuple()); + List<ATuple, const AST> ret(new ATuple(penv.sym("fn"), NULL, Cursor())); ret.push_back(prot); while (a != texp->end()) ret.push_back(penv.parse(*a++)); @@ -155,7 +155,7 @@ parseFn(PEnv& penv, const AST* exp, void* arg) return new ATuple(*ret.head); } -inline AST* +inline const AST* parseQuote(PEnv& penv, const AST* exp, void* arg) { const ATuple* texp = exp->to_tuple(); @@ -190,7 +190,7 @@ initLang(PEnv& penv, TEnv& tenv) penv.reg(false, "#f", PEnv::Handler(parseBool, &falseVal)); // Macros - penv.defmac("def", macDef); + penv.defmac("def", macDef); // Special forms penv.reg(true, "fn", PEnv::Handler(parseFn)); |