diff options
author | David Robillard <d@drobilla.net> | 2009-10-16 14:26:42 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2009-10-16 14:26:42 +0000 |
commit | 338da7070dfe47fdf041b35a6d84c00fab6d9678 (patch) | |
tree | 118736b14c7160709cee5e916c3adcb0d5bcd4ab /src/repl.cpp | |
parent | bf0d7b7add98f976592c9766273ecc84f8b0b6b9 (diff) | |
download | resp-338da7070dfe47fdf041b35a6d84c00fab6d9678.tar.gz resp-338da7070dfe47fdf041b35a6d84c00fab6d9678.tar.bz2 resp-338da7070dfe47fdf041b35a6d84c00fab6d9678.zip |
Compile top level definitions to globalas.
git-svn-id: http://svn.drobilla.net/resp/tuplr@239 ad02d1e2-f140-0410-9f75-f8b11f17cedd
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; } |