aboutsummaryrefslogtreecommitdiffstats
path: root/src/repl.cpp
diff options
context:
space:
mode:
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);