aboutsummaryrefslogtreecommitdiffstats
path: root/src/repl.cpp
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2010-12-02 06:16:29 +0000
committerDavid Robillard <d@drobilla.net>2010-12-02 06:16:29 +0000
commit563a807be78bfe12e5bfbb9ff0d6da44242696c4 (patch)
tree13cf7ce3b90d072d6e7106c7d2eb4da33209acb0 /src/repl.cpp
parent32ac40a9ef62d2109563e36fb7cd478426c3489f (diff)
downloadresp-563a807be78bfe12e5bfbb9ff0d6da44242696c4.tar.gz
resp-563a807be78bfe12e5bfbb9ff0d6da44242696c4.tar.bz2
resp-563a807be78bfe12e5bfbb9ff0d6da44242696c4.zip
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
Diffstat (limited to 'src/repl.cpp')
-rw-r--r--src/repl.cpp63
1 files changed, 19 insertions, 44 deletions
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<std::streamsize>::max(), '\n'); // Skip REPL junk
throw e;
}
-
+
if (exp->to<ATuple*>() && exp->to<ATuple*>()->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<AST*>::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<AST*>::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<ADef*>();
- if (def)
- std::cout << " :: " << cenv.type(def->body()) << std::endl;
- cout << endl;
- }
- cout << ";;;; } CONCRETE" << endl << endl;
- }
- */
-
// Lift all expressions
Code lifted;
for (list<AST*>::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<ADef*>();
- 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<ADef*>();
- if (def && (*(def->begin() + 2))->to<AFn*>()) {
+ for (Code::const_iterator i = lifted.begin(); i != lifted.end(); ++i) {
+ const ADef* def = (*i)->to<const ADef*>();
+ if (def && def->list_ref(2)->to<const AFn*>()) {
val = def->compile(cenv);
} else {
- exprs.push_back(*i);
+ assert(*i);
+ ATuple* tup = (*i)->to<ATuple*>();
+ if (!tup || (tup->tup_len() > 0))
+ exprs.push_back(*i);
}
}
const AType* type = cenv.type(exprs.back());
const AType* fnT = tup<const AType>(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;