diff options
-rw-r--r-- | llvm.cpp | 20 | ||||
-rw-r--r-- | tuplr.cpp | 4 | ||||
-rw-r--r-- | tuplr.hpp | 12 |
3 files changed, 18 insertions, 18 deletions
@@ -92,8 +92,8 @@ struct CEnvPimpl { Function* alloc; }; -CEnv::CEnv(PEnv& p, TEnv& t, CEngine& eng) - : engine(eng), penv(p), tenv(t), symID(0), _pimpl(new CEnvPimpl(eng)) +CEnv::CEnv(PEnv& p, TEnv& t, CEngine& e, ostream& os, ostream& es) + : engine(e), penv(p), tenv(t), symID(0), alloc(0), log(os, es), _pimpl(new CEnvPimpl(e)) { } @@ -539,10 +539,10 @@ eval(CEnv& cenv, const string& name, istream& is) cenv.engine.builder.CreateRet(val); cenv.optimise(f); - out << call(resultType, cenv.engine.engine->getPointerToFunction(f)) + cenv.log.out << call(resultType, cenv.engine.engine->getPointerToFunction(f)) << " : " << resultType->str() << endl; } catch (Error& e) { - err << e.what() << endl; + cenv.log.err << e.what() << endl; return 1; } return 0; @@ -552,8 +552,8 @@ int repl(CEnv& cenv) { while (1) { - out << "() "; - out.flush(); + cenv.log.out << "() "; + cenv.log.out.flush(); Cursor cursor("(stdin)"); try { SExp exp = readExpression(cursor, std::cin); @@ -580,13 +580,13 @@ repl(CEnv& cenv) f->eraseFromParent(); // Error reading body, remove function throw e; } - out << call(bodyT, cenv.engine.engine->getPointerToFunction(f)); + cenv.log.out << call(bodyT, cenv.engine.engine->getPointerToFunction(f)); } else { - out << "; " << cenv.compile(body); + cenv.log.out << "; " << cenv.compile(body); } - out << " : " << cenv.tenv.type(body)->str() << endl; + cenv.log.out << " : " << cenv.tenv.type(body)->str() << endl; } catch (Error& e) { - err << e.what() << endl; + cenv.log.err << e.what() << endl; } } return 0; @@ -28,10 +28,6 @@ using boost::format; Funcs ASTConsCall::funcs; -std::ostream& err = std::cerr; -std::ostream& out = std::cout; - - /*************************************************************************** * Lexer * ***************************************************************************/ @@ -36,9 +36,6 @@ using boost::format; * Basic Utility Classes * ***************************************************************************/ -extern std::ostream& err; -extern std::ostream& out; - struct Cursor { Cursor(const string& n="", unsigned l=1, unsigned c=0) : name(n), line(l), col(c) {} operator bool() const { return !(line == 1 && col == 0); } @@ -55,6 +52,12 @@ struct Error { Cursor loc; }; +struct Log { + Log(ostream& o, ostream& e) : out(o), err(e) {} + ostream& out; + ostream& err; +}; + template<typename Atom> struct Exp { Exp(Cursor c) : type(LIST), loc(c) {} @@ -465,7 +468,7 @@ struct CEnvPimpl; /// Compile-Time Environment struct CEnv { - CEnv(PEnv& p, TEnv& t, CEngine& engine); + CEnv(PEnv& p, TEnv& t, CEngine& e, ostream& os=std::cout, ostream& es=std::cerr); ~CEnv(); typedef Env<const ASTSymbol*, AST*> Code; @@ -486,6 +489,7 @@ struct CEnv { Vals vals; unsigned symID; CFunction alloc; + Log log; private: CEnvPimpl* _pimpl; |