From 42b51cce2575fa138fddf1cfd4581bf1d1568b24 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Wed, 29 Dec 2010 00:35:28 +0000 Subject: Literal lists (i.e. list quoting). Compile type expressions. Only compile a top-level function if program has code to run (i.e. isn't just definitions). Cast tuples to Object when necessary to avoid LLVM IR type mismatches (for cons stores and return values). Fix memory leaks. git-svn-id: http://svn.drobilla.net/resp/resp@369 ad02d1e2-f140-0410-9f75-f8b11f17cedd --- src/repl.cpp | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) (limited to 'src/repl.cpp') diff --git a/src/repl.cpp b/src/repl.cpp index 81035bb..6c9b3cf 100644 --- a/src/repl.cpp +++ b/src/repl.cpp @@ -136,7 +136,8 @@ eval(CEnv& cenv, Cursor& cursor, istream& is, bool execute) Code exprs; for (Code::const_iterator i = lifted.begin(); i != lifted.end(); ++i) { const ATuple* call = (*i)->to_tuple(); - if (call && is_form(call, "def") && is_form(call->list_ref(2), "fn")) { + if (call && ( (is_form(call, "def-type")) + || (is_form(call, "def") && is_form(call->frrst(), "fn")))) { val = resp_compile(cenv, call); } else { const ATuple* tup = (*i)->to_tuple(); @@ -146,27 +147,25 @@ eval(CEnv& cenv, Cursor& cursor, istream& is, bool execute) } } - const AST* type = cenv.type(exprs.back()); - const ATuple* fnT = tup(cursor, cenv.tenv.Fn, new ATuple(cursor), type, 0); - - // Create function for top-level of program - f = cenv.engine()->startFn(cenv, "main", new ATuple(cursor), fnT); + if (!exprs.empty()) { + const AST* type = cenv.type(exprs.back()); + const ATuple* fnT = tup(cursor, cenv.tenv.Fn, new ATuple(cursor), type, 0); - // Compile expressions (other than function definitions) into it - for (Code::const_iterator i = exprs.begin(); i != exprs.end(); ++i) - val = resp_compile(cenv, *i); + // Create function for program containing all expressions except definitions + f = cenv.engine()->startFn(cenv, "main", new ATuple(cursor), fnT); + for (Code::const_iterator i = exprs.begin(); i != exprs.end(); ++i) + val = resp_compile(cenv, *i); + cenv.engine()->finishFn(cenv, f, val, type); - // Finish compilation - cenv.engine()->finishFn(cenv, f, val); + // Call and print result + callPrintCollect(cenv, f, ast, type, execute); + } if (cenv.args.find("-S") != cenv.args.end()) { cenv.engine()->writeModule(cenv, cenv.out); return 0; } - // Call and print result - callPrintCollect(cenv, f, ast, type, execute); - } catch (Error& e) { cenv.err << e.what() << endl; return 1; @@ -200,7 +199,7 @@ repl(CEnv& cenv) try { // Create function for this repl loop f = cenv.engine()->startFn(cenv, replFnName, new ATuple(cursor), fnT); - cenv.engine()->finishFn(cenv, f, resp_compile(cenv, ast)); + cenv.engine()->finishFn(cenv, f, resp_compile(cenv, ast), type); callPrintCollect(cenv, f, ast, type, true); if (cenv.args.find("-d") != cenv.args.end()) cenv.engine()->writeModule(cenv, cenv.out); -- cgit v1.2.1