aboutsummaryrefslogtreecommitdiffstats
path: root/src/c.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/c.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/c.cpp')
-rw-r--r--src/c.cpp84
1 files changed, 41 insertions, 43 deletions
diff --git a/src/c.cpp b/src/c.cpp
index 65a939d..d139c35 100644
--- a/src/c.cpp
+++ b/src/c.cpp
@@ -41,25 +41,25 @@ struct CEngine : public Engine {
{
}
- CFunc startFn(CEnv& cenv, const string& name, const ATuple* args, const AType* type);
- void pushFnArgs(CEnv& cenv, const ATuple* prot, const AType* type, CFunc f);
+ CFunc startFn(CEnv& cenv, const string& name, const ATuple* args, const ATuple* type);
+ void pushFnArgs(CEnv& cenv, const ATuple* prot, const ATuple* type, CFunc f);
void finishFn(CEnv& cenv, CFunc f, CVal ret);
void eraseFn(CEnv& cenv, CFunc f);
- CVal compileCall(CEnv& cenv, CFunc f, const AType* funcT, const vector<CVal>& args);
- CVal compileCons(CEnv& cenv, const AType* type, CVal rtti, const vector<CVal>& fields);
+ CVal compileCall(CEnv& cenv, CFunc f, const ATuple* funcT, const vector<CVal>& args);
+ CVal compileCons(CEnv& cenv, const ATuple* type, CVal rtti, const vector<CVal>& fields);
CVal compileDot(CEnv& cenv, CVal tup, int32_t index);
- CVal compileGlobalSet(CEnv& cenv, const string& s, CVal v, const AType* t);
+ CVal compileGlobalSet(CEnv& cenv, const string& s, CVal v, const AST* t);
CVal compileGlobalGet(CEnv& cenv, const string& s, CVal v);
CVal compileIf(CEnv& cenv, const AST* cond, const AST* then, const AST* aelse);
- CVal compileIsA(CEnv& cenv, CVal rtti, const ASymbol* tag);
+ CVal compileIsA(CEnv& cenv, CVal rtti, CVal tag);
CVal compileLiteral(CEnv& cenv, const AST* lit);
CVal compilePrimitive(CEnv& cenv, const ATuple* prim);
CVal compileString(CEnv& cenv, const char* str);
void writeModule(CEnv& cenv, std::ostream& os);
- const string call(CEnv& cenv, CFunc f, const AType* retT);
+ const string call(CEnv& cenv, CFunc f, const AST* retT);
private:
typedef string Type;
@@ -73,34 +73,34 @@ private:
inline Value* llVal(CVal v) { return static_cast<Value*>(v); }
inline Function* llFunc(CFunc f) { return static_cast<Function*>(f); }
- const Type* llType(const AType* t);
+ const Type* llType(const AST* t);
std::string out;
};
const CEngine::Type*
-CEngine::llType(const AType* t)
+CEngine::llType(const AST* t)
{
if (t == NULL) {
return NULL;
- } else if (t->kind == AType::NAME) {
- if (t->head()->str() == "Nothing") return new string("void");
- if (t->head()->str() == "Bool") return new string("bool");
- if (t->head()->str() == "Int") return new string("int");
- if (t->head()->str() == "Float") return new string("float");
- if (t->head()->str() == "String") return new string("char*");
- if (t->head()->str() == "Quote") return new string("char*");
- } else if (t->kind == AType::EXPR && t->head()->str() == "Fn") {
- AType::const_iterator i = t->begin();
- const ATuple* protT = (*++i)->to_tuple();
- const AType* retT = (*i)->as_type();
+ } else if (AType::is_name(t)) {
+ const std::string sym(t->as_symbol()->sym());
+ if (sym == "Nothing") return new string("void");
+ if (sym == "Bool") return new string("bool");
+ if (sym == "Int") return new string("int");
+ if (sym == "Float") return new string("float");
+ if (sym == "String") return new string("char*");
+ if (sym == "Quote") return new string("char*");
+ } else if (is_form(t, "Fn")){
+ ATuple::const_iterator i = t->as_tuple()->begin();
+ const ATuple* protT = (*++i)->to_tuple();
+ const AST* retT = *i;
if (!llType(retT))
return NULL;
Type* ret = new Type(*llType(retT) + " (*)(");
FOREACHP(ATuple::const_iterator, i, protT) {
- const AType* at = (*i)->to_type();
- const Type* lt = llType(at);
+ const Type* lt = llType(*i);
if (!lt)
return NULL;
*ret += *lt;
@@ -108,10 +108,10 @@ CEngine::llType(const AType* t)
*ret += ")";
return ret;
- } else if (t->kind == AType::EXPR && t->head()->str() == "Tup") {
+ } else if (AType::is_expr(t) && isupper(t->as_tuple()->head()->str()[0])) {
Type* ret = new Type("struct { void* me; ");
- for (AType::const_iterator i = t->iter_at(1); i != t->end(); ++i) {
- const Type* lt = llType((*i)->to_type());
+ for (ATuple::const_iterator i = t->as_tuple()->iter_at(1); i != t->as_tuple()->end(); ++i) {
+ const Type* lt = llType(*i);
if (!lt)
return NULL;
ret->append("; ");
@@ -125,7 +125,7 @@ CEngine::llType(const AType* t)
}
CVal
-CEngine::compileCall(CEnv& cenv, CFunc func, const AType* funcT, const vector<CVal>& args)
+CEngine::compileCall(CEnv& cenv, CFunc func, const ATuple* funcT, const vector<CVal>& args)
{
Value* varname = new string(cenv.penv.gensymstr("x"));
Function* f = llFunc(func);
@@ -137,7 +137,7 @@ CEngine::compileCall(CEnv& cenv, CFunc func, const AType* funcT, const vector<CV
}
CVal
-CEngine::compileCons(CEnv& cenv, const AType* type, CVal rtti, const vector<CVal>& fields)
+CEngine::compileCons(CEnv& cenv, const ATuple* type, CVal rtti, const vector<CVal>& fields)
{
return NULL;
}
@@ -161,17 +161,16 @@ CEngine::compileString(CEnv& cenv, const char* str)
}
CFunc
-CEngine::startFn(CEnv& cenv, const std::string& name, const ATuple* args, const AType* type)
+CEngine::startFn(CEnv& cenv, const std::string& name, const ATuple* args, const ATuple* type)
{
- const AType* argsT = type->prot()->as_type();
- const AType* retT = type->list_ref(2)->as_type();
+ const ATuple* argsT = type->prot();
+ const AST* retT = type->list_ref(2);
vector<const Type*> cprot;
FOREACHP(ATuple::const_iterator, i, argsT) {
- const AType* at = (*i)->as_type();
- THROW_IF(!llType(at), Cursor(), string("non-concrete parameter :: ")
- + at->str())
- cprot.push_back(llType(at));
+ THROW_IF(!llType(*i), Cursor(), string("non-concrete parameter :: ")
+ + (*i)->str())
+ cprot.push_back(llType(*i));
}
THROW_IF(!llType(retT), Cursor(),
@@ -186,7 +185,7 @@ CEngine::startFn(CEnv& cenv, const std::string& name, const ATuple* args, const
for (; ai != argsT->end(); ++ai, ++ni) {
if (ai != argsT->begin())
f->text += ", ";
- f->text += *llType((*ai)->as_type()) + " " + (*ni)->as_symbol()->sym();
+ f->text += *llType(*ai) + " " + (*ni)->as_symbol()->sym();
}
f->text += ")\n{\n";
@@ -196,21 +195,20 @@ CEngine::startFn(CEnv& cenv, const std::string& name, const ATuple* args, const
}
void
-CEngine::pushFnArgs(CEnv& cenv, const ATuple* prot, const AType* type, CFunc f)
+CEngine::pushFnArgs(CEnv& cenv, const ATuple* prot, const ATuple* type, CFunc f)
{
cenv.push();
- const AType* argsT = type->prot()->as_type();
+ const ATuple* argsT = type->prot();
// Bind argument values in CEnv
vector<Value*> args;
ATuple::const_iterator p = prot->begin();
ATuple::const_iterator pT = argsT->begin();
for (; p != prot->end(); ++p, ++pT) {
- const AType* t = (*pT)->as_type();
- const Type* lt = llType(t);
+ const Type* lt = llType(*pT);
THROW_IF(!lt, (*p)->loc, "untyped parameter\n");
- cenv.def((*p)->as_symbol(), *p, t, new string((*p)->str()));
+ cenv.def((*p)->as_symbol(), *p, (*pT), new string((*p)->str()));
}
}
@@ -267,7 +265,7 @@ CEngine::compileIf(CEnv& cenv, const ATuple* aif)
#endif
CVal
-CEngine::compileIsA(CEnv& cenv, CVal rtti, const ASymbol* tag)
+CEngine::compileIsA(CEnv& cenv, CVal rtti, CVal tag)
{
return NULL;
}
@@ -303,7 +301,7 @@ CEngine::compilePrimitive(CEnv& cenv, const ATuple* prim)
}
CVal
-CEngine::compileGlobalSet(CEnv& cenv, const string& sym, CVal val, const AType* type)
+CEngine::compileGlobalSet(CEnv& cenv, const string& sym, CVal val, const AST* type)
{
return NULL;
}
@@ -321,7 +319,7 @@ CEngine::writeModule(CEnv& cenv, std::ostream& os)
}
const string
-CEngine::call(CEnv& cenv, CFunc f, const AType* retT)
+CEngine::call(CEnv& cenv, CFunc f, const AST* retT)
{
cenv.err << "C backend does not support JIT (call)" << endl;
return "";