aboutsummaryrefslogtreecommitdiffstats
path: root/src/repl.cpp
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2010-12-29 00:35:28 +0000
committerDavid Robillard <d@drobilla.net>2010-12-29 00:35:28 +0000
commit42b51cce2575fa138fddf1cfd4581bf1d1568b24 (patch)
tree03ea8256f19d3418fd4e847391a4b5a84f8b6e0f /src/repl.cpp
parent703f1840af79ca4480c664190cdcf7e6fbd7b90e (diff)
downloadresp-42b51cce2575fa138fddf1cfd4581bf1d1568b24.tar.gz
resp-42b51cce2575fa138fddf1cfd4581bf1d1568b24.tar.bz2
resp-42b51cce2575fa138fddf1cfd4581bf1d1568b24.zip
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
Diffstat (limited to 'src/repl.cpp')
-rw-r--r--src/repl.cpp29
1 files changed, 14 insertions, 15 deletions
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);