diff options
author | David Robillard <d@drobilla.net> | 2010-12-01 06:06:38 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2010-12-01 06:06:38 +0000 |
commit | 8972c175088b1cd083989ff9c07f59143a59fb69 (patch) | |
tree | 9135a433ddc72b429c420925787bc8c5d39469c7 /src/repl.cpp | |
parent | ea984b91ae477310ac7226fb56338a40531b07cb (diff) | |
download | resp-8972c175088b1cd083989ff9c07f59143a59fb69.tar.gz resp-8972c175088b1cd083989ff9c07f59143a59fb69.tar.bz2 resp-8972c175088b1cd083989ff9c07f59143a59fb69.zip |
Add -T option to type-check and pretty-print with type annotations.
Rename -p to -P (all 'stage' options, i.e. -P -T -S are uppercase for consistency).
Clean up main program.
Decent pretty printing.
git-svn-id: http://svn.drobilla.net/resp/resp@275 ad02d1e2-f140-0410-9f75-f8b11f17cedd
Diffstat (limited to 'src/repl.cpp')
-rw-r--r-- | src/repl.cpp | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/src/repl.cpp b/src/repl.cpp index 0264c18..c2a50f5 100644 --- a/src/repl.cpp +++ b/src/repl.cpp @@ -44,6 +44,8 @@ readParseType(CEnv& cenv, Cursor& cursor, istream& is, AST*& exp, AST*& ast) Constraints c(cenv.tsubst); ast->constrain(cenv.tenv, c); // Constrain types + //cout << "(CONSTRAINTS " << endl << c << ")" << endl; + const Subst subst = unify(c); // Solve type constraints for (Subst::const_iterator i = subst.begin(); i != subst.end(); ++i) { if (!cenv.tsubst.contains(i->first)) { // Substitution's LHS is a new variable @@ -53,8 +55,8 @@ readParseType(CEnv& cenv, Cursor& cursor, istream& is, AST*& exp, AST*& ast) } } - //cout << "**** SUBST\n" << subst << "********" << endl; - //cout << "**** CENV.SUBST\n" << cenv.tsubst << "********" << endl; + //cout << "(SUBST " << endl << subst << ")" << endl; + //cout << "(TSUBST " << endl << cenv.tsubst << ")" << endl; //cenv.tsubst = Subst::compose(cenv.tsubst, subst); Object::pool.addRoot(ast); // Make parsed expression a GC root so it is not deleted @@ -77,18 +79,21 @@ callPrintCollect(CEnv& cenv, CFunc f, AST* result, const AType* resultT, bool ex /// Compile and evaluate code from @a is int -eval(CEnv& cenv, const string& name, istream& is, bool execute) +eval(CEnv& cenv, Cursor& cursor, istream& is, bool execute) { - AST* exp = NULL; - AST* ast = NULL; + AST* exp = NULL; + AST* ast = NULL; list<AST*> parsed; - Cursor cursor(name); try { while (readParseType(cenv, cursor, is, exp, ast)) parsed.push_back(ast); - /*for (list<AST*>::const_iterator i = parsed.begin(); i != parsed.end(); ++i) - pprint(cout, (*i)->cps(cenv.tenv, cenv.penv.sym("halt")));*/ + + if (cenv.args.find("-T") != cenv.args.end()) { + for (list<AST*>::const_iterator i = parsed.begin(); i != parsed.end(); ++i) + pprint(cout, (*i), &cenv, true); + return 0; + } CVal val = NULL; CFunc f = NULL; |