aboutsummaryrefslogtreecommitdiffstats
path: root/tuplr.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tuplr.cpp')
-rw-r--r--tuplr.cpp30
1 files changed, 18 insertions, 12 deletions
diff --git a/tuplr.cpp b/tuplr.cpp
index c49cdf8..dd4681f 100644
--- a/tuplr.cpp
+++ b/tuplr.cpp
@@ -191,9 +191,10 @@ void
initLang(PEnv& penv, TEnv& tenv)
{
// Types
- tenv.def(penv.sym("Bool"), make_pair((AST*)NULL, new AType(penv.sym("Bool"))));
- tenv.def(penv.sym("Int"), make_pair((AST*)NULL, new AType(penv.sym("Int"))));
- tenv.def(penv.sym("Float"), make_pair((AST*)NULL, new AType(penv.sym("Float"))));
+ tenv.def(penv.sym("Nothing"), make_pair((AST*)0, new AType(penv.sym("Nothing"))));
+ tenv.def(penv.sym("Bool"), make_pair((AST*)0, new AType(penv.sym("Bool"))));
+ tenv.def(penv.sym("Int"), make_pair((AST*)0, new AType(penv.sym("Int"))));
+ tenv.def(penv.sym("Float"), make_pair((AST*)0, new AType(penv.sym("Float"))));
// Literals
static bool trueVal = true;
@@ -263,9 +264,6 @@ eval(CEnv& cenv, const string& name, istream& is)
}
}
- // Create function for top-level of program
- CFunction f = cenv.engine()->startFunction(cenv, "main", resultType, ATuple(cursor));
-
// Print CPS form
CValue val = NULL;
/*for (list< pair<SExp, AST*> >::const_iterator i = exprs.begin(); i != exprs.end(); ++i) {
@@ -273,13 +271,21 @@ eval(CEnv& cenv, const string& name, istream& is)
pprint(cout, i->second->cps(cenv.tenv, cenv.penv.sym("cont")));
}*/
- // Compile all expressions into it
- for (list< pair<SExp, AST*> >::const_iterator i = exprs.begin(); i != exprs.end(); ++i)
- val = cenv.compile(i->second);
+ if (resultType->concrete()) {
+ // Create function for top-level of program
+ CFunction f = cenv.engine()->startFunction(cenv, "main", resultType, ATuple(cursor));
- cenv.engine()->finishFunction(cenv, f, val);
+ // Compile all expressions into it
+ for (list< pair<SExp, AST*> >::const_iterator i = exprs.begin(); i != exprs.end(); ++i)
+ val = cenv.compile(i->second);
- cenv.out << cenv.engine()->call(cenv, f, resultType) << " : " << resultType << endl;
+ // Finish and call it
+ cenv.engine()->finishFunction(cenv, f, resultType, val);
+ cenv.out << cenv.engine()->call(cenv, f, resultType) << " : " << resultType << endl;
+ } else {
+ // Non-concrete body type, just report type
+ cenv.out << " : " << resultType << endl;
+ }
Object::pool.collect(Object::pool.roots());
@@ -323,7 +329,7 @@ repl(CEnv& cenv)
// Create anonymous function to insert code into
f = cenv.engine()->startFunction(cenv, cenv.penv.gensymstr("_repl"), bodyT, ATuple(cursor));
CValue retVal = cenv.compile(body);
- cenv.engine()->finishFunction(cenv, f, retVal);
+ cenv.engine()->finishFunction(cenv, f, bodyT, retVal);
cenv.out << cenv.engine()->call(cenv, f, bodyT);
} catch (Error& e) {
ADef* def = body->to<ADef*>();