diff options
author | David Robillard <d@drobilla.net> | 2009-03-06 08:23:38 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2009-03-06 08:23:38 +0000 |
commit | c49d6fabbd295c3d0b2a29c4e68eb7a358e4f3a9 (patch) | |
tree | e24963f09d40dd58fff9ed83df143425efabe98a | |
parent | cb66805e44aaf15f4c1877ac71a1a92cbcd747cc (diff) | |
download | resp-c49d6fabbd295c3d0b2a29c4e68eb7a358e4f3a9.tar.gz resp-c49d6fabbd295c3d0b2a29c4e68eb7a358e4f3a9.tar.bz2 resp-c49d6fabbd295c3d0b2a29c4e68eb7a358e4f3a9.zip |
Tidy.
git-svn-id: http://svn.drobilla.net/resp/tuplr@58 ad02d1e2-f140-0410-9f75-f8b11f17cedd
-rw-r--r-- | tuplr.cpp | 2 | ||||
-rw-r--r-- | tuplr_llvm.cpp | 44 |
2 files changed, 20 insertions, 26 deletions
@@ -23,8 +23,6 @@ #include <stack> #include "tuplr.hpp" -#define FOREACH(IT, i, c) for (IT i = (c).begin(); i != (c).end(); ++i) - using namespace std; using boost::format; diff --git a/tuplr_llvm.cpp b/tuplr_llvm.cpp index b236bbd..b5fb862 100644 --- a/tuplr_llvm.cpp +++ b/tuplr_llvm.cpp @@ -31,15 +31,19 @@ #include "llvm/Transforms/Scalar.h" #include "tuplr.hpp" -llvm::Value* LLVal(CValue v) { return static_cast<llvm::Value*>(v); } -const llvm::Type* LLType(CType t) { return static_cast<const llvm::Type*>(t); } -llvm::Function* LLFunc(CFunction f) { return static_cast<llvm::Function*>(f); } +using namespace llvm; +using namespace std; +using boost::format; + +inline Value* LLVal(CValue v) { return static_cast<Value*>(v); } +inline const Type* LLType(CType t) { return static_cast<const Type*>(t); } +inline Function* LLFunc(CFunction f) { return static_cast<Function*>(f); } struct CEngine { CEngine(); - llvm::Module* module; - llvm::ExecutionEngine* engine; - llvm::IRBuilder<> builder; + Module* module; + ExecutionEngine* engine; + IRBuilder<> builder; }; struct CArg { @@ -48,9 +52,6 @@ struct CArg { int arg; }; -using namespace llvm; -using namespace std; -using boost::format; /*************************************************************************** @@ -499,7 +500,7 @@ ASTCdrCall::compile(CEnv& cenv) * EVAL/REPL/MAIN * ***************************************************************************/ -std::string +const string call(AType* retT, void* fp) { std::stringstream ss; @@ -541,7 +542,7 @@ eval(CEnv& cenv, const string& name, istream& is) if (!ctype) throw Error("body has no system type", cursor); // Create function for top-level of program - Function* f = compileFunction(cenv, cenv.gensym("input"), ctype, ASTTuple()); + Function* f = compileFunction(cenv, "main", ctype, ASTTuple()); // Compile all expressions into it Value* val = NULL; @@ -552,14 +553,12 @@ eval(CEnv& cenv, const string& name, istream& is) cenv.engine.builder.CreateRet(val); cenv.optimise(f); - string resultStr = call(resultType, cenv.engine.engine->getPointerToFunction(f)); - out << resultStr << " : " << resultType->str() << endl; - + out << call(resultType, cenv.engine.engine->getPointerToFunction(f)) + << " : " << resultType->str() << endl; } catch (Error& e) { err << e.what() << endl; return 1; } - return 0; } @@ -570,11 +569,11 @@ repl(CEnv& cenv) out << "() "; out.flush(); Cursor cursor("(stdin)"); - SExp exp = readExpression(cursor, std::cin); - if (exp.type == SExp::LIST && exp.list.empty()) - break; - try { + SExp exp = readExpression(cursor, std::cin); + if (exp.type == SExp::LIST && exp.list.empty()) + break; + AST* body = parseExpression(cenv.penv, exp); // Parse input body->constrain(cenv.tenv); // Constrain types cenv.tenv.solve(); // Solve and apply type constraints @@ -583,7 +582,7 @@ repl(CEnv& cenv) if (!bodyT) throw Error("call to untyped body", cursor); body->lift(cenv); - + if (bodyT->type()) { // Create anonymous function to insert code into Function* f = compileFunction(cenv, cenv.gensym("_repl"), bodyT->type(), ASTTuple()); @@ -597,16 +596,13 @@ repl(CEnv& cenv) } out << call(bodyT, cenv.engine.engine->getPointerToFunction(f)); } else { - CValue val = cenv.compile(body); - out << "; " << val; + out << "; " << cenv.compile(body); } out << " : " << cenv.tenv.type(body)->str() << endl; - } catch (Error& e) { err << e.what() << endl; } } - return 0; } |