aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2009-01-26 18:12:17 +0000
committerDavid Robillard <d@drobilla.net>2009-01-26 18:12:17 +0000
commitbca79754d69afec61a18d77f6924410af7e371f6 (patch)
treefe82ec669c6f4dc6343229665852ddeaab50aeab
parent885e68d83196a9de16ba0e6e707f55d271fc41bb (diff)
downloadresp-bca79754d69afec61a18d77f6924410af7e371f6.tar.gz
resp-bca79754d69afec61a18d77f6924410af7e371f6.tar.bz2
resp-bca79754d69afec61a18d77f6924410af7e371f6.zip
Shrink.
git-svn-id: http://svn.drobilla.net/resp/llvm-lisp@22 ad02d1e2-f140-0410-9f75-f8b11f17cedd
-rw-r--r--ll.cpp44
1 files 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<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