From f81807ae192fa9b54320da69b59c063e505e94e1 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 27 Jun 2009 01:12:25 +0000 Subject: Add nothing type. Only actually compile down to LLVM if main program is typed. git-svn-id: http://svn.drobilla.net/resp/tuplr@152 ad02d1e2-f140-0410-9f75-f8b11f17cedd --- tuplr.cpp | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) (limited to 'tuplr.cpp') 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 >::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 >::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 >::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(); -- cgit v1.2.1