diff options
author | David Robillard <d@drobilla.net> | 2009-06-27 01:12:25 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2009-06-27 01:12:25 +0000 |
commit | f81807ae192fa9b54320da69b59c063e505e94e1 (patch) | |
tree | eb12822d7f4687c6d26b513b43d334320ce4f805 /tuplr.cpp | |
parent | 9ba1ca23fb217c747117c5bbff3fcaac98f5f261 (diff) | |
download | resp-f81807ae192fa9b54320da69b59c063e505e94e1.tar.gz resp-f81807ae192fa9b54320da69b59c063e505e94e1.tar.bz2 resp-f81807ae192fa9b54320da69b59c063e505e94e1.zip |
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
Diffstat (limited to 'tuplr.cpp')
-rw-r--r-- | tuplr.cpp | 30 |
1 files changed, 18 insertions, 12 deletions
@@ -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*>(); |