diff options
Diffstat (limited to 'src/repl.cpp')
-rw-r--r-- | src/repl.cpp | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/src/repl.cpp b/src/repl.cpp index 472d1a5..977976b 100644 --- a/src/repl.cpp +++ b/src/repl.cpp @@ -29,7 +29,13 @@ using namespace std; static bool readParseType(CEnv& cenv, Cursor& cursor, istream& is, AST*& exp, AST*& ast) { - exp = readExpression(cursor, is); + try { + exp = readExpression(cursor, is); + } catch (Error e) { + is.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); // Skip REPL junk + throw e; + } + if (exp->to<ATuple*>() && exp->to<ATuple*>()->empty()) return false; @@ -40,9 +46,10 @@ readParseType(CEnv& cenv, Cursor& cursor, istream& is, AST*& exp, AST*& ast) 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)) { - //cout << "New variable " << i->first << " = " << i->second << endl; - cenv.tsubst.push_back(*i); + if (!cenv.tsubst.contains(i->first)) { // Substitution's LHS is a new variable + cenv.tsubst.push_back(*i); // Add substitution to global type substitution + Object::pool.addRoot(i->first); + Object::pool.addRoot(i->second); } } @@ -50,12 +57,8 @@ readParseType(CEnv& cenv, Cursor& cursor, istream& is, AST*& exp, AST*& ast) //cout << "**** CENV.SUBST\n" << cenv.tsubst << "********" << endl; //cenv.tsubst = Subst::compose(cenv.tsubst, subst); - // 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); - } - + Object::pool.addRoot(ast); // Make parsed expression a GC root so it is not deleted + return true; } |