aboutsummaryrefslogtreecommitdiffstats
path: root/src/compile.cpp
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2010-12-27 17:51:29 +0000
committerDavid Robillard <d@drobilla.net>2010-12-27 17:51:29 +0000
commit0b014dee824646461b7d402bf9bbcf954ff0eba3 (patch)
tree6e9da06aad29bc641bbc04e181a32e272cc66af8 /src/compile.cpp
parent28e3727290335ee85793795f7ec6d48e050db922 (diff)
downloadresp-0b014dee824646461b7d402bf9bbcf954ff0eba3.tar.gz
resp-0b014dee824646461b7d402bf9bbcf954ff0eba3.tar.bz2
resp-0b014dee824646461b7d402bf9bbcf954ff0eba3.zip
Kill AType.
git-svn-id: http://svn.drobilla.net/resp/resp@359 ad02d1e2-f140-0410-9f75-f8b11f17cedd
Diffstat (limited to 'src/compile.cpp')
-rw-r--r--src/compile.cpp57
1 files changed, 29 insertions, 28 deletions
diff --git a/src/compile.cpp b/src/compile.cpp
index 3c16fbf..4fed182 100644
--- a/src/compile.cpp
+++ b/src/compile.cpp
@@ -29,7 +29,7 @@ using namespace std;
static CVal
compile_symbol(CEnv& cenv, const ASymbol* sym) throw()
{
- if (cenv.repl && cenv.vals.topLevel(sym) && cenv.type(sym)->head()->str() != "Fn") {
+ if (cenv.repl && cenv.vals.topLevel(sym) && !is_form(cenv.type(sym), "Fn")) {
return cenv.engine()->compileGlobalGet(cenv, sym->sym(), *cenv.vals.ref(sym));
} else {
return *cenv.vals.ref(sym);
@@ -37,16 +37,31 @@ compile_symbol(CEnv& cenv, const ASymbol* sym) throw()
}
static CVal
+compile_type(CEnv& cenv, const AST* type) throw()
+{
+ const ASymbol* sym = type->as_tuple()->head()->as_symbol();
+ CVal* existing = cenv.vals.ref(sym);
+ if (existing) {
+ return *existing;
+ } else {
+ CVal compiled = cenv.engine()->compileString(
+ cenv, (string("__T_") + type->as_tuple()->head()->str()).c_str());
+ cenv.vals.def(sym, compiled);
+ return compiled;
+ }
+}
+
+static CVal
compile_cons(CEnv& cenv, const ATuple* cons) throw()
{
- AType* type = new AType(cons->head()->as_symbol(), NULL, Cursor());
- TList tlist(type);
+ ATuple* type = new ATuple(cons->head()->as_symbol(), NULL, Cursor());
+ List tlist(type);
vector<CVal> fields;
for (ATuple::const_iterator i = cons->iter_at(1); i != cons->end(); ++i) {
tlist.push_back(cenv.type(*i));
fields.push_back(resp_compile(cenv, *i));
}
- return cenv.engine()->compileCons(cenv, type, resp_compile(cenv, type), fields);
+ return cenv.engine()->compileCons(cenv, type, compile_type(cenv, type), fields);
}
static CVal
@@ -67,7 +82,7 @@ compile_def(CEnv& cenv, const ATuple* def) throw()
const AST* const body = def->list_ref(2);
cenv.def(sym, body, cenv.type(body), NULL); // define stub first for recursion
CVal val = resp_compile(cenv, body);
- if (cenv.repl && cenv.vals.size() == 1 && cenv.type(body)->head()->str() != "Fn") {
+ if (cenv.repl && cenv.vals.size() == 1 && !is_form(cenv.type(body), "Fn")) {
val = cenv.engine()->compileGlobalSet(
cenv, sym->str(), val, cenv.type(body));
cenv.lock(def);
@@ -91,14 +106,14 @@ compile_fn(CEnv& cenv, const ATuple* fn) throw()
{
assert(!cenv.currentFn);
- const AType* type = cenv.type(fn);
+ const AST* type = cenv.type(fn);
CFunc f = cenv.findImpl(fn, type);
if (f)
return f;
// Write function declaration and push stack frame
- f = cenv.engine()->startFn(cenv, cenv.name(fn), fn->prot(), type);
- cenv.engine()->pushFnArgs(cenv, fn->prot(), type, f);
+ f = cenv.engine()->startFn(cenv, cenv.name(fn), fn->prot(), type->as_tuple());
+ cenv.engine()->pushFnArgs(cenv, fn->prot(), type->as_tuple(), f);
cenv.currentFn = f;
// Write function body
@@ -129,24 +144,11 @@ compile_if(CEnv& cenv, const ATuple* aif) throw()
static CVal
compile_tag_is(CEnv& cenv, const ATuple* call) throw()
{
- const AST* lhs = call->list_ref(1);
- const ASymbol* rhs = call->list_ref(2)->as_symbol();
- return cenv.engine()->compileIsA(cenv, resp_compile(cenv, lhs), rhs);
-}
+ const AST* lhs = call->list_ref(1);
+ const ASymbol* tag = call->list_ref(2)->as_symbol();
+ const ATuple* patT = new ATuple(tag, 0, Cursor());
-static CVal
-compile_type(CEnv& cenv, const AType* type) throw()
-{
- const ASymbol* sym = type->head()->as_symbol();
- CVal* existing = cenv.vals.ref(sym);
- if (existing) {
- return *existing;
- } else {
- CVal compiled = cenv.engine()->compileString(
- cenv, (string("__T_") + type->head()->str()).c_str());
- cenv.vals.def(sym, compiled);
- return compiled;
- }
+ return cenv.engine()->compileIsA(cenv, resp_compile(cenv, lhs), compile_type(cenv, patT));
}
static CVal
@@ -161,7 +163,7 @@ compile_call(CEnv& cenv, const ATuple* call) throw()
for (ATuple::const_iterator e = call->iter_at(1); e != call->end(); ++e)
args.push_back(resp_compile(cenv, *e));
- return cenv.engine()->compileCall(cenv, f, cenv.type(call->head()), args);
+ return cenv.engine()->compileCall(cenv, f, cenv.type(call->head())->as_tuple(), args);
}
CVal
@@ -170,11 +172,10 @@ resp_compile(CEnv& cenv, const AST* ast) throw()
switch (ast->tag()) {
case T_UNKNOWN:
return NULL;
- case T_TYPE:
- return compile_type(cenv, ast->as_type());
case T_BOOL:
case T_FLOAT:
case T_INT32:
+ case T_TVAR:
return cenv.engine()->compileLiteral(cenv, ast);
case T_STRING:
return cenv.engine()->compileString(cenv, ((AString*)ast)->cppstr.c_str());