aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/compile.cpp5
-rw-r--r--src/repl.cpp21
-rw-r--r--src/tuplr.cpp1
3 files changed, 9 insertions, 18 deletions
diff --git a/src/compile.cpp b/src/compile.cpp
index 605ec40..977ab27 100644
--- a/src/compile.cpp
+++ b/src/compile.cpp
@@ -77,6 +77,11 @@ ADef::compile(CEnv& cenv)
{
cenv.def(sym(), body(), cenv.type(body()), NULL); // define stub first for recursion
CVal val = body()->compile(cenv);
+ if (cenv.vals.size() == 1 && cenv.type(body())->head()->str() != "Fn") {
+ val = cenv.engine()->compileGlobal(
+ cenv, cenv.type(body()), sym()->str(), val);
+ cenv.lock(this);
+ }
cenv.vals.def(sym(), val);
return val;
}
diff --git a/src/repl.cpp b/src/repl.cpp
index 85b2821..a5c6adf 100644
--- a/src/repl.cpp
+++ b/src/repl.cpp
@@ -27,7 +27,7 @@
using namespace std;
static bool
-readParseTypeCompile(CEnv& cenv, Cursor& cursor, istream& is, AST*& exp, AST*& ast, AType*& type)
+readParseTypeLift(CEnv& cenv, Cursor& cursor, istream& is, AST*& exp, AST*& ast, AType*& type)
{
exp = readExpression(cursor, is);
if (exp->to<ATuple*>() && exp->to<ATuple*>()->empty())
@@ -50,10 +50,6 @@ readParseTypeCompile(CEnv& cenv, Cursor& cursor, istream& is, AST*& exp, AST*& a
ast->lift(cenv); // Lift functions
- // Add definitions as GC roots
- if (ast->to<ADef*>())
- cenv.lock(ast);
-
return true;
}
@@ -83,7 +79,7 @@ eval(CEnv& cenv, const string& name, istream& is, bool execute)
list< pair<AST*, AST*> > exprs;
Cursor cursor(name);
try {
- while (readParseTypeCompile(cenv, cursor, is, exp, ast, type))
+ while (readParseTypeLift(cenv, cursor, is, exp, ast, type))
exprs.push_back(make_pair(exp, ast));
//for (list< pair<SExp, AST*> >::const_iterator i = exprs.begin(); i != exprs.end(); ++i)
@@ -127,23 +123,14 @@ repl(CEnv& cenv)
Cursor cursor("(stdin)");
try {
- if (!readParseTypeCompile(cenv, cursor, std::cin, exp, ast, type))
+ if (!readParseTypeLift(cenv, cursor, std::cin, exp, ast, type))
break;
CFunc f = NULL;
try {
// Create function for this repl loop
f = cenv.engine()->startFunction(cenv, replFnName, type, ATuple(cursor));
-
- 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);
+ cenv.engine()->finishFunction(cenv, f, type, ast->compile(cenv));
callPrintCollect(cenv, f, ast, type, true);
} catch (Error& e) {
cenv.out << e.msg << endl;
diff --git a/src/tuplr.cpp b/src/tuplr.cpp
index bc4ac43..5f54480 100644
--- a/src/tuplr.cpp
+++ b/src/tuplr.cpp
@@ -91,7 +91,6 @@ main(int argc, char** argv)
CEnv* cenv = new CEnv(penv, tenv, engine);
cenv->args = args;
- cenv->push();
Object::pool.lock();