diff options
-rw-r--r-- | ll.cpp | 44 |
1 files changed, 19 insertions, 25 deletions
@@ -304,23 +304,29 @@ struct PEnv : private map<const string, ASTSymbol*> { }; /// The fundamental parser method +static AST* parseExpression(PEnv& penv, const SExp& exp); + +static TupV +pmap(PEnv& penv, const SExp::List& l) +{ + TupV ret(l.size()); + size_t n = 0; + FOREACH(SExp::List::const_iterator, i, l) + ret[n++] = parseExpression(penv, *i); + return ret; +} + static AST* parseExpression(PEnv& penv, const SExp& exp) { if (exp.type == SExp::LIST) { if (exp.list.empty()) throw SyntaxError("Call to empty list"); - // Dispatch to parse function if possible if (exp.list.front().type == SExp::ATOM) { const PEnv::Parser* handler = penv.parser(exp.list.front().atom); - if (handler) + if (handler) // Dispatch to parse function return handler->pf(penv, exp.list, handler->ud); } - // Otherwise parse as a regular call - size_t n = 0; - TupV code(exp.list.size()); - FOREACH(SExp::List::const_iterator, e, exp.list) - code[n++] = parseExpression(penv, *e); - return new ASTCall(code); + return new ASTCall(pmap(penv, exp.list)); // Parse as regular call } else if (isdigit(exp.atom[0])) { if (exp.atom.find('.') == string::npos) return new ASTLiteral<int32_t>(strtol(exp.atom.c_str(), NULL, 10)); @@ -332,16 +338,6 @@ parseExpression(PEnv& penv, const SExp& exp) // Special forms -static TupV -pmap(PEnv& penv, const SExp::List& l) -{ - TupV code(l.size()); - size_t n = 0; - for (SExp::List::const_iterator i = l.begin(); i != l.end(); ++i) - code[n++] = parseExpression(penv, *i); - return code; -} - static AST* parseIf(PEnv& penv, const SExp::List& c, UD) { return new ASTIf(pmap(penv, c)); } @@ -824,8 +820,7 @@ ASTClosure::lift(CEnv& cenv) Value* ASTClosure::compile(CEnv& cenv) { - // Function was already compiled in the lifting pass - return func; + return func; // Function was already compiled in the lifting pass } Value* @@ -896,12 +891,11 @@ main() ExecutionEngine* engine = ExecutionEngine::create(module); CEnv cenv(penv, module, engine->getTargetData()); - cenv.code.def(penv.sym("true"), new ASTLiteral<bool>(true)); - cenv.code.def(penv.sym("false"), new ASTLiteral<bool>(false)); - cenv.tenv.name("Bool", Type::Int1Ty); cenv.tenv.name("Int", Type::Int32Ty); cenv.tenv.name("Float", Type::FloatTy); + cenv.code.def(penv.sym("true"), new ASTLiteral<bool>(true)); + cenv.code.def(penv.sym("false"), new ASTLiteral<bool>(false)); while (1) { std::cout << "(= "; @@ -938,9 +932,9 @@ main() void* fp = engine->getPointerToFunction(f); if (bodyT->ctype == Type::Int32Ty) - std::cout << " " <<((int32_t (*)())fp)(); + std::cout << " " << ((int32_t (*)())fp)(); else if (bodyT->ctype == Type::FloatTy) - std::cout << " " <<((float (*)())fp)(); + std::cout << " " << ((float (*)())fp)(); else if (bodyT->ctype == Type::Int1Ty) std::cout << " " << ((bool (*)())fp)(); else |