diff options
Diffstat (limited to 'src/repl.cpp')
-rw-r--r-- | src/repl.cpp | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/src/repl.cpp b/src/repl.cpp index d66fe36..85b2821 100644 --- a/src/repl.cpp +++ b/src/repl.cpp @@ -60,7 +60,7 @@ readParseTypeCompile(CEnv& cenv, Cursor& cursor, istream& is, AST*& exp, AST*& a static void callPrintCollect(CEnv& cenv, CFunc f, AST* result, AType* resultT, bool execute) { - if (execute && resultT->concrete()) + if (execute) cenv.out << cenv.engine()->call(cenv, f, resultT); // Print type (if applicable) @@ -127,7 +127,6 @@ repl(CEnv& cenv) Cursor cursor("(stdin)"); try { - Subst oldSubst = cenv.tsubst; if (!readParseTypeCompile(cenv, cursor, std::cin, exp, ast, type)) break; @@ -135,15 +134,22 @@ repl(CEnv& cenv) try { // Create function for this repl loop f = cenv.engine()->startFunction(cenv, replFnName, type, ATuple(cursor)); - cenv.engine()->finishFunction(cenv, f, type, ast->compile(cenv)); + + CVal val = ast->compile(cenv); + + // Set global if expression is a top level define + if (ast->to<ADef*>()) { + ADef* def = ast->to<ADef*>(); + cenv.vals.def(def->sym(), cenv.engine()->compileGlobal( + cenv, cenv.type(def->body()), def->sym()->str(), val)); + } + cenv.engine()->finishFunction(cenv, f, type, val); callPrintCollect(cenv, f, ast, type, true); } catch (Error& e) { cenv.out << e.msg << endl; cenv.engine()->eraseFunction(cenv, f); } - cenv.tsubst = oldSubst; - } catch (Error& e) { cenv.err << e.what() << endl; } |