From ab4cb90d1918fc6b77a6dd20d67cffb257c54a67 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Thu, 5 Mar 2009 18:41:17 +0000 Subject: Cleanup. git-svn-id: http://svn.drobilla.net/resp/tuplr@45 ad02d1e2-f140-0410-9f75-f8b11f17cedd --- tuplr.cpp | 57 ++++++++++++++++++++++++++++++--------------------------- 1 file changed, 30 insertions(+), 27 deletions(-) (limited to 'tuplr.cpp') diff --git a/tuplr.cpp b/tuplr.cpp index 94bd2a5..f5db2ce 100644 --- a/tuplr.cpp +++ b/tuplr.cpp @@ -42,6 +42,9 @@ using namespace llvm; using namespace std; using boost::format; +std::ostream& err = std::cerr; +std::ostream& out = std::cout; + struct Cursor { Cursor(const string& n="", unsigned l=1, unsigned c=0) : name(n), line(l), col(c) {} string str() const { return (format("%1%:%2%:%3%") % name % line % col).str(); } @@ -818,7 +821,7 @@ ASTClosure::lift(CEnv& cenv) { AType* type = cenv.tenv.type(this); if (!type->concrete()) { - std::cerr << "closure is untyped, not lifting" << endl; + err << "closure is untyped, not lifting" << endl; return; } @@ -1137,7 +1140,7 @@ eval(CEnv& cenv, ExecutionEngine* engine, const string& name, istream& is) if (!resultType || resultType->var) throw Error("body is undefined/untyped", cursor); } catch (Error& e) { - std::cerr << e.what() << endl; + err << e.what() << endl; return 1; } @@ -1145,7 +1148,7 @@ eval(CEnv& cenv, ExecutionEngine* engine, const string& name, istream& is) ASTTuple prot; const Type* ctype = resultType->type(); if (!ctype) { - std::cerr << "program body has non-compilable type" << endl; + err << "program body has non-compilable type" << endl; return 2; } assert(ctype); @@ -1163,7 +1166,7 @@ eval(CEnv& cenv, ExecutionEngine* engine, const string& name, istream& is) cenv.optimise(*f); string resultStr = call(resultType, engine->getPointerToFunction(f)); - std::cout << resultStr << " : " << resultType->str() << endl; + out << resultStr << " : " << resultType->str() << endl; return 0; } @@ -1172,8 +1175,8 @@ int repl(CEnv& cenv, ExecutionEngine* engine) { while (1) { - std::cout << "() "; - std::cout.flush(); + out << "() "; + out.flush(); Cursor cursor("(stdin)"); SExp exp = readExpression(cursor, std::cin); if (exp.type == SExp::LIST && exp.list.empty()) @@ -1204,15 +1207,15 @@ repl(CEnv& cenv, ExecutionEngine* engine) f->eraseFromParent(); // Error reading body, remove function throw e; } - std::cout << call(bodyT, engine->getPointerToFunction(f)); + out << call(bodyT, engine->getPointerToFunction(f)); } else { Value* val = cenv.compile(body); - std::cout << "; " << val; + out << "; " << val; } - std::cout << " : " << cenv.tenv.type(body)->str() << endl; + out << " : " << cenv.tenv.type(body)->str() << endl; } catch (Error& e) { - std::cerr << e.what() << endl; + err << e.what() << endl; } } @@ -1228,22 +1231,22 @@ main(int argc, char** argv) penv.reg("if", PEnv::Parser(parseIf, Op())); penv.reg("def", PEnv::Parser(parseDef, Op())); penv.reg("cons", PEnv::Parser(parseCons, Op())); - penv.reg("car", PEnv::Parser(parseCar, Op())); - penv.reg("cdr", PEnv::Parser(parseCdr, Op())); - penv.reg("+", PRIM(Add, 0)); - penv.reg("-", PRIM(Sub, 0)); - penv.reg("*", PRIM(Mul, 0)); - penv.reg("/", PRIM(FDiv, 0)); - penv.reg("%", PRIM(FRem, 0)); - penv.reg("&", PRIM(And, 0)); - penv.reg("|", PRIM(Or, 0)); - penv.reg("^", PRIM(Xor, 0)); - penv.reg("=", PRIM(ICmp, CmpInst::ICMP_EQ)); - penv.reg("!=", PRIM(ICmp, CmpInst::ICMP_NE)); - penv.reg(">", PRIM(ICmp, CmpInst::ICMP_SGT)); - penv.reg(">=", PRIM(ICmp, CmpInst::ICMP_SGE)); - penv.reg("<", PRIM(ICmp, CmpInst::ICMP_SLT)); - penv.reg("<=", PRIM(ICmp, CmpInst::ICMP_SLE)); + penv.reg("car", PEnv::Parser(parseCar, Op())); + penv.reg("cdr", PEnv::Parser(parseCdr, Op())); + penv.reg("+", PRIM(Add, 0)); + penv.reg("-", PRIM(Sub, 0)); + penv.reg("*", PRIM(Mul, 0)); + penv.reg("/", PRIM(FDiv, 0)); + penv.reg("%", PRIM(FRem, 0)); + penv.reg("&", PRIM(And, 0)); + penv.reg("|", PRIM(Or, 0)); + penv.reg("^", PRIM(Xor, 0)); + penv.reg("=", PRIM(ICmp, CmpInst::ICMP_EQ)); + penv.reg("!=", PRIM(ICmp, CmpInst::ICMP_NE)); + penv.reg(">", PRIM(ICmp, CmpInst::ICMP_SGT)); + penv.reg(">=", PRIM(ICmp, CmpInst::ICMP_SGE)); + penv.reg("<", PRIM(ICmp, CmpInst::ICMP_SLT)); + penv.reg("<=", PRIM(ICmp, CmpInst::ICMP_SLE)); Module* module = new Module("interactive"); ExecutionEngine* engine = ExecutionEngine::create(module); @@ -1272,7 +1275,7 @@ main(int argc, char** argv) ret = repl(cenv, engine); } - //std::cout << endl << "*** Generated Code ***" << endl; + //out << endl << "*** Generated Code ***" << endl; //cenv.module->dump(); return ret; -- cgit v1.2.1