From bca79754d69afec61a18d77f6924410af7e371f6 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Mon, 26 Jan 2009 18:12:17 +0000 Subject: Shrink. git-svn-id: http://svn.drobilla.net/resp/llvm-lisp@22 ad02d1e2-f140-0410-9f75-f8b11f17cedd --- ll.cpp | 44 +++++++++++++++++++------------------------- 1 file changed, 19 insertions(+), 25 deletions(-) diff --git a/ll.cpp b/ll.cpp index 1804f80..13b16af 100644 --- a/ll.cpp +++ b/ll.cpp @@ -304,23 +304,29 @@ struct PEnv : private map { }; /// 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(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(true)); - cenv.code.def(penv.sym("false"), new ASTLiteral(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(true)); + cenv.code.def(penv.sym("false"), new ASTLiteral(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 -- cgit v1.2.1