aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--llvm.cpp20
-rw-r--r--tuplr.cpp4
-rw-r--r--tuplr.hpp12
3 files changed, 18 insertions, 18 deletions
diff --git a/llvm.cpp b/llvm.cpp
index e94a806..8eeab42 100644
--- a/llvm.cpp
+++ b/llvm.cpp
@@ -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;
diff --git a/tuplr.cpp b/tuplr.cpp
index 5837715..a4fd8b8 100644
--- a/tuplr.cpp
+++ b/tuplr.cpp
@@ -28,10 +28,6 @@ using boost::format;
Funcs ASTConsCall::funcs;
-std::ostream& err = std::cerr;
-std::ostream& out = std::cout;
-
-
/***************************************************************************
* Lexer *
***************************************************************************/
diff --git a/tuplr.hpp b/tuplr.hpp
index e7a2329..c86ff68 100644
--- a/tuplr.hpp
+++ b/tuplr.hpp
@@ -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;