aboutsummaryrefslogtreecommitdiffstats
path: root/src/tuplr.cpp
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2009-06-29 00:34:16 +0000
committerDavid Robillard <d@drobilla.net>2009-06-29 00:34:16 +0000
commitf5ea52df50d4b199904c42cadff3917621f336db (patch)
tree67332e0b8bd1ea32542e755289c536949f673494 /src/tuplr.cpp
parent314482b95ff83f1f88e41d45fadd05a7e625bb0c (diff)
downloadresp-f5ea52df50d4b199904c42cadff3917621f336db.tar.gz
resp-f5ea52df50d4b199904c42cadff3917621f336db.tar.bz2
resp-f5ea52df50d4b199904c42cadff3917621f336db.zip
Split code up further.
git-svn-id: http://svn.drobilla.net/resp/tuplr@166 ad02d1e2-f140-0410-9f75-f8b11f17cedd
Diffstat (limited to 'src/tuplr.cpp')
-rw-r--r--src/tuplr.cpp155
1 files changed, 0 insertions, 155 deletions
diff --git a/src/tuplr.cpp b/src/tuplr.cpp
index a0c001d..3bd90f6 100644
--- a/src/tuplr.cpp
+++ b/src/tuplr.cpp
@@ -22,167 +22,12 @@
#include <cerrno>
#include <cstring>
#include <fstream>
-#include <set>
-#include <sstream>
#include "tuplr.hpp"
using namespace std;
-using boost::format;
GC Object::pool;
-template<typename Atom>
-ostream&
-operator<<(ostream& out, const Exp<Atom>& exp)
-{
- switch (exp.type) {
- case Exp<Atom>::ATOM:
- out << exp.atom;
- break;
- case Exp<Atom>::LIST:
- out << "(";
- for (size_t i = 0; i != exp.size(); ++i)
- out << exp.at(i) << ((i != exp.size() - 1) ? " " : "");
- out << ")";
- break;
- }
- return out;
-}
-
-
-/***************************************************************************
- * EVAL/REPL *
- ***************************************************************************/
-
-int
-eval(CEnv& cenv, const string& name, istream& is)
-{
- AST* result = NULL;
- AType* resultType = NULL;
- list< pair<SExp, AST*> > exprs;
- Cursor cursor(name);
- try {
- while (true) {
- SExp exp = readExpression(cursor, is);
- if (exp.type == SExp::LIST && exp.empty())
- break;
-
- result = cenv.penv.parse(exp); // Parse input
- Constraints c;
- result->constrain(cenv.tenv, c); // Constrain types
- cenv.tsubst = Subst::compose(cenv.tsubst, TEnv::unify(c)); // Solve type constraints
- resultType = cenv.type(result);
- result->lift(cenv); // Lift functions
- exprs.push_back(make_pair(exp, result));
-
- // Add definitions as GC roots
- if (result->to<ADef*>())
- cenv.lock(result);
-
- // Add types in type substition as GC roots
- for (Subst::iterator i = cenv.tsubst.begin(); i != cenv.tsubst.end(); ++i) {
- Object::pool.addRoot(i->first);
- Object::pool.addRoot(i->second);
- }
- }
-
- // Print CPS form
- CValue val = NULL;
- /*for (list< pair<SExp, AST*> >::const_iterator i = exprs.begin(); i != exprs.end(); ++i) {
- cout << "; CPS" << endl;
- pprint(cout, i->second->cps(cenv.tenv, cenv.penv.sym("cont")));
- }*/
-
- if (resultType->concrete()) {
- // Create function for top-level of program
- CFunction f = cenv.engine()->startFunction(cenv, "main", resultType, ATuple(cursor));
-
- // Compile all expressions into it
- for (list< pair<SExp, AST*> >::const_iterator i = exprs.begin(); i != exprs.end(); ++i)
- val = cenv.compile(i->second);
-
- // Finish and call it
- cenv.engine()->finishFunction(cenv, f, resultType, val);
- cenv.out << cenv.engine()->call(cenv, f, resultType);
- }
- cenv.out << " : " << resultType << endl;
-
- Object::pool.collect(Object::pool.roots());
-
- if (cenv.args.find("-d") != cenv.args.end())
- cenv.engine()->writeModule(cenv, cenv.out);
-
- } catch (Error& e) {
- cenv.err << e.what() << endl;
- return 1;
- }
- return 0;
-}
-
-int
-repl(CEnv& cenv)
-{
- while (1) {
- cenv.out << "() ";
- cenv.out.flush();
- Cursor cursor("(stdin)");
-
- try {
- SExp exp = readExpression(cursor, std::cin);
- if (exp.type == SExp::LIST && exp.empty())
- break;
-
- AST* body = cenv.penv.parse(exp); // Parse input
- Constraints c;
- body->constrain(cenv.tenv, c); // Constrain types
-
- Subst oldSubst = cenv.tsubst;
- cenv.tsubst = Subst::compose(cenv.tsubst, TEnv::unify(c)); // Solve type constraints
-
- AType* bodyT = cenv.type(body);
- THROW_IF(!bodyT, cursor, "call to untyped body")
-
- body->lift(cenv);
-
- CFunction f = NULL;
- try {
- // Create anonymous function to insert code into
- f = cenv.engine()->startFunction(cenv, cenv.penv.gensymstr("_repl"), bodyT, ATuple(cursor));
- CValue retVal = cenv.compile(body);
- cenv.engine()->finishFunction(cenv, f, bodyT, retVal);
- cenv.out << cenv.engine()->call(cenv, f, bodyT);
- } catch (Error& e) {
- ADef* def = body->to<ADef*>();
- if (def)
- cenv.out << def->sym();
- else
- cenv.out << "?";
- cenv.engine()->eraseFunction(cenv, f);
- }
- cenv.out << " : " << cenv.type(body) << endl;
-
- // Add definitions as GC roots
- if (body->to<ADef*>())
- cenv.lock(body);
-
- Object::pool.collect(Object::pool.roots());
-
- cenv.tsubst = oldSubst;
- if (cenv.args.find("-d") != cenv.args.end())
- cenv.engine()->writeModule(cenv, cenv.out);
-
- } catch (Error& e) {
- cenv.err << e.what() << endl;
- }
- }
- return 0;
-}
-
-
-/***************************************************************************
- * MAIN *
- ***************************************************************************/
-
int
print_usage(char* name, bool error)
{