From 563a807be78bfe12e5bfbb9ff0d6da44242696c4 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Thu, 2 Dec 2010 06:16:29 +0000 Subject: Represent code as list structure (i.e. traditional LISP lists built from pairs), rather than tuple structure. Remove unused/crufty depoly stage. Remove cps from AST interface (but keep cps.cpp code around for later). Improved command line interface for compilation stages (options -T -L -S). git-svn-id: http://svn.drobilla.net/resp/resp@277 ad02d1e2-f140-0410-9f75-f8b11f17cedd --- src/repl.cpp | 63 ++++++++++++++++++------------------------------------------ 1 file changed, 19 insertions(+), 44 deletions(-) (limited to 'src/repl.cpp') diff --git a/src/repl.cpp b/src/repl.cpp index c2a50f5..d0a251b 100644 --- a/src/repl.cpp +++ b/src/repl.cpp @@ -35,7 +35,7 @@ readParseType(CEnv& cenv, Cursor& cursor, istream& is, AST*& exp, AST*& ast) is.ignore(std::numeric_limits::max(), '\n'); // Skip REPL junk throw e; } - + if (exp->to() && exp->to()->empty()) return false; @@ -87,39 +87,16 @@ eval(CEnv& cenv, Cursor& cursor, istream& is, bool execute) try { while (readParseType(cenv, cursor, is, exp, ast)) parsed.push_back(ast); - if (cenv.args.find("-T") != cenv.args.end()) { for (list::const_iterator i = parsed.begin(); i != parsed.end(); ++i) - pprint(cout, (*i), &cenv, true); + pprint(cout, *i, &cenv, true); return 0; } CVal val = NULL; CFunc f = NULL; - /* - // De-poly all expressions - Code concrete; - for (list::iterator i = parsed.begin(); i != parsed.end(); ++i) { - AST* c = (*i)->depoly(cenv, concrete); - if (c) - concrete.push_back(c); - } - - if (cenv.args.find("-d") != cenv.args.end()) { - cout << endl << ";;;; CONCRETE {" << endl << endl; - for (Code::iterator i = concrete.begin(); i != concrete.end(); ++i) { - cout << *i << endl; - ADef* def = (*i)->to(); - if (def) - std::cout << " :: " << cenv.type(def->body()) << std::endl; - cout << endl; - } - cout << ";;;; } CONCRETE" << endl << endl; - } - */ - // Lift all expressions Code lifted; for (list::iterator i = parsed.begin(); i != parsed.end(); ++i) { @@ -128,32 +105,29 @@ eval(CEnv& cenv, Cursor& cursor, istream& is, bool execute) lifted.push_back(l); } - if (cenv.args.find("-d") != cenv.args.end()) { - cout << endl << ";;;; LIFTED {" << endl << endl; - for (Code::iterator i = lifted.begin(); i != lifted.end(); ++i) { - cout << *i << endl; - ADef* def = (*i)->to(); - if (def) - std::cout << " :: " << cenv.type(def->body()) << std::endl; - cout << endl; - } - cout << ";;;; } LIFTED" << endl << endl; + if (cenv.args.find("-L") != cenv.args.end()) { + for (Code::const_iterator i = lifted.begin(); i != lifted.end(); ++i) + pprint(cout, *i, &cenv, true); + return 0; } // Compile top-level (lifted) functions Code exprs; - for (Code::iterator i = lifted.begin(); i != lifted.end(); ++i) { - ADef* def = (*i)->to(); - if (def && (*(def->begin() + 2))->to()) { + for (Code::const_iterator i = lifted.begin(); i != lifted.end(); ++i) { + const ADef* def = (*i)->to(); + if (def && def->list_ref(2)->to()) { val = def->compile(cenv); } else { - exprs.push_back(*i); + assert(*i); + ATuple* tup = (*i)->to(); + if (!tup || (tup->tup_len() > 0)) + exprs.push_back(*i); } } const AType* type = cenv.type(exprs.back()); const AType* fnT = tup(cursor, cenv.tenv.Fn, new AType(cursor), type, 0); - + // Create function for top-level of program f = cenv.engine()->startFunction(cenv, "main", new ATuple(cursor), fnT); @@ -164,12 +138,13 @@ eval(CEnv& cenv, Cursor& cursor, istream& is, bool execute) // Finish compilation cenv.engine()->finishFunction(cenv, f, val); - if (cenv.args.find("-d") != cenv.args.end()) + if (cenv.args.find("-S") != cenv.args.end()) { cenv.engine()->writeModule(cenv, cenv.out); + return 0; + } - // Call and print ast - if (cenv.args.find("-S") == cenv.args.end()) - callPrintCollect(cenv, f, ast, type, execute); + // Call and print result + callPrintCollect(cenv, f, ast, type, execute); } catch (Error& e) { cenv.err << e.what() << endl; -- cgit v1.2.1