aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2010-12-02 18:36:49 +0000
committerDavid Robillard <d@drobilla.net>2010-12-02 18:36:49 +0000
commit1b61928f542f1c54ac67791f382b20b39927eac5 (patch)
treea1b516f08b965fa962514b75882d2d9c00ec7781
parenta2021fceed6810a5c9f2f14632fc40a5c122cf0e (diff)
downloadresp-1b61928f542f1c54ac67791f382b20b39927eac5.tar.gz
resp-1b61928f542f1c54ac67791f382b20b39927eac5.tar.bz2
resp-1b61928f542f1c54ac67791f382b20b39927eac5.zip
Remove use of ACall class hierarchy from compile phase.
git-svn-id: http://svn.drobilla.net/resp/resp@281 ad02d1e2-f140-0410-9f75-f8b11f17cedd
-rw-r--r--src/c.cpp8
-rw-r--r--src/compile.cpp88
-rw-r--r--src/llvm.cpp8
-rw-r--r--src/resp.hpp4
4 files changed, 49 insertions, 59 deletions
diff --git a/src/c.cpp b/src/c.cpp
index 4d53436..7cd72da 100644
--- a/src/c.cpp
+++ b/src/c.cpp
@@ -159,8 +159,8 @@ struct CEngine : public Engine {
CVal compileLiteral(CEnv& cenv, const AST* lit);
CVal compileString(CEnv& cenv, const char* str);
CVal compilePrimitive(CEnv& cenv, const APrimitive* prim);
- CVal compileIf(CEnv& cenv, const AIf* aif);
- CVal compileMatch(CEnv& cenv, const AMatch* match);
+ CVal compileIf(CEnv& cenv, const ACall* aif);
+ CVal compileMatch(CEnv& cenv, const ACall* match);
CVal compileGlobal(CEnv& cenv, const AType* type, const string& sym, CVal val);
CVal getGlobal(CEnv& cenv, const string& sym, CVal val);
@@ -230,7 +230,7 @@ CEngine::pushFunctionArgs(CEnv& cenv, const AFn* fn, const AType* type, CFunc f)
}
CVal
-CEngine::compileIf(CEnv& cenv, const AIf* aif)
+CEngine::compileIf(CEnv& cenv, const ACall* aif)
{
Value* varname = new string(cenv.penv.gensymstr("if"));
out += (format("%s %s;\n") % *llType(cenv.type(aif)) % *varname).str();
@@ -262,7 +262,7 @@ CEngine::compileIf(CEnv& cenv, const AIf* aif)
}
CVal
-CEngine::compileMatch(CEnv& cenv, const AMatch* match)
+CEngine::compileMatch(CEnv& cenv, const ACall* match)
{
return NULL;
}
diff --git a/src/compile.cpp b/src/compile.cpp
index 8518051..9f9168a 100644
--- a/src/compile.cpp
+++ b/src/compile.cpp
@@ -67,6 +67,21 @@ compile_fn(CEnv& cenv, const AFn* fn) throw()
}
static CVal
+compile_type(CEnv& cenv, const AType* type) throw()
+{
+ const ASymbol* sym = type->head()->as<const ASymbol*>();
+ 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;
+ }
+}
+
+static CVal
compile_call(CEnv& cenv, const ACall* call) throw()
{
CFunc f = resp_compile(cenv, *call->begin());
@@ -82,7 +97,7 @@ compile_call(CEnv& cenv, const ACall* call) throw()
}
static CVal
-compile_def(CEnv& cenv, const ADef* def) throw()
+compile_def(CEnv& cenv, const ACall* def) throw()
{
const ASymbol* const sym = def->list_ref(1)->as<const ASymbol*>();
const AST* const body = def->list_ref(2);
@@ -98,7 +113,7 @@ compile_def(CEnv& cenv, const ADef* def) throw()
}
static CVal
-compile_cons(CEnv& cenv, const ACons* cons) throw()
+compile_cons(CEnv& cenv, const ACall* cons) throw()
{
AType* type = new AType(const_cast<ASymbol*>(cons->head()->as<const ASymbol*>()), NULL, Cursor());
TList tlist(type);
@@ -111,22 +126,7 @@ compile_cons(CEnv& cenv, const ACons* cons) throw()
}
static CVal
-compile_type(CEnv& cenv, const AType* type) throw()
-{
- const ASymbol* sym = type->head()->as<const ASymbol*>();
- 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;
- }
-}
-
-static CVal
-compile_dot(CEnv& cenv, const ADot* dot) throw()
+compile_dot(CEnv& cenv, const ACall* dot) throw()
{
ATuple::const_iterator i = dot->begin();
const AST* tup = *++i;
@@ -147,10 +147,6 @@ resp_compile(CEnv& cenv, const AST* ast) throw()
if (str)
return cenv.engine()->compileString(cenv, str->c_str());
- const AQuote* quote = ast->to<const AQuote*>();
- if (quote)
- return resp_compile(cenv, quote->list_ref(1));
-
const ALexeme* lexeme = ast->to<const ALexeme*>();
if (lexeme)
return cenv.engine()->compileString(cenv, lexeme->c_str());
@@ -162,42 +158,36 @@ resp_compile(CEnv& cenv, const AST* ast) throw()
const AFn* fn = ast->to<const AFn*>();
if (fn)
return compile_fn(cenv, fn);
-
- const ADef* def = ast->to<const ADef*>();
- if (def)
- return compile_def(cenv, def);
-
- const AIf* aif = ast->to<const AIf*>();
- if (aif)
- return cenv.engine()->compileIf(cenv, aif);
-
- const ACons* cons = ast->to<const ACons*>();
- if (cons)
- return compile_cons(cenv, cons);
const APrimitive* prim = ast->to<const APrimitive*>();
if (prim)
return cenv.engine()->compilePrimitive(cenv, prim);
- const AMatch* match = ast->to<const AMatch*>();
- if (match)
- return cenv.engine()->compileMatch(cenv, match);
-
const AType* type = ast->to<const AType*>();
if (type)
return compile_type(cenv, type);
- const ADot* dot = ast->to<const ADot*>();
- if (dot)
- return compile_dot(cenv, dot);
-
- const ADefType* deftype = ast->to<const ADefType*>();
- if (deftype)
- return NULL;
-
- const ACall* call = ast->to<const ACall*>();
- if (call)
- return compile_call(cenv, call);
+ const ACall* const call = ast->to<const ACall*>();
+ if (call) {
+ const ASymbol* const sym = call->head()->to<const ASymbol*>();
+ const std::string form = sym ? sym->cppstr : "";
+ if (form == "def")
+ return compile_def(cenv, call);
+ else if (form == "if")
+ return cenv.engine()->compileIf(cenv, call);
+ else if (form == "cons" || isupper(form[0]))
+ return compile_cons(cenv, call);
+ else if (form == ".")
+ return compile_dot(cenv, call);
+ else if (form == "quote")
+ return resp_compile(cenv, call->list_ref(1));
+ else if (form == "match")
+ return cenv.engine()->compileMatch(cenv, call);
+ else if (form == "def-type")
+ return NULL;
+ else
+ return compile_call(cenv, call);
+ }
cenv.err << "Attempt to compile unknown type" << endl;
assert(false);
diff --git a/src/llvm.cpp b/src/llvm.cpp
index 3aaf21b..29c09ee 100644
--- a/src/llvm.cpp
+++ b/src/llvm.cpp
@@ -197,8 +197,8 @@ struct LLVMEngine : public Engine {
CVal compileLiteral(CEnv& cenv, const AST* lit);
CVal compileString(CEnv& cenv, const char* str);
CVal compilePrimitive(CEnv& cenv, const APrimitive* prim);
- CVal compileIf(CEnv& cenv, const AIf* aif);
- CVal compileMatch(CEnv& cenv, const AMatch* match);
+ CVal compileIf(CEnv& cenv, const ACall* aif);
+ CVal compileMatch(CEnv& cenv, const ACall* match);
CVal compileGlobal(CEnv& cenv, const AType* type, const string& sym, CVal val);
CVal getGlobal(CEnv& cenv, const string& sym, CVal val);
@@ -351,7 +351,7 @@ LLVMEngine::pushFunctionArgs(CEnv& cenv, const AFn* fn, const AType* type, CFunc
}
CVal
-LLVMEngine::compileIf(CEnv& cenv, const AIf* aif)
+LLVMEngine::compileIf(CEnv& cenv, const ACall* aif)
{
typedef vector< pair<Value*, BasicBlock*> > Branches;
LLVMEngine* engine = reinterpret_cast<LLVMEngine*>(cenv.engine());
@@ -402,7 +402,7 @@ LLVMEngine::compileIf(CEnv& cenv, const AIf* aif)
}
CVal
-LLVMEngine::compileMatch(CEnv& cenv, const AMatch* match)
+LLVMEngine::compileMatch(CEnv& cenv, const ACall* match)
{
typedef vector< pair<Value*, BasicBlock*> > Branches;
Value* matchee = llVal(resp_compile(cenv, match->list_ref(1)));
diff --git a/src/resp.hpp b/src/resp.hpp
index d429168..d9c85fe 100644
--- a/src/resp.hpp
+++ b/src/resp.hpp
@@ -786,8 +786,8 @@ struct Engine {
virtual CVal compileString(CEnv& cenv, const char* str) = 0;
virtual CVal compileCall(CEnv& cenv, CFunc f, const AType* fT, ValVec& args) = 0;
virtual CVal compilePrimitive(CEnv& cenv, const APrimitive* prim) = 0;
- virtual CVal compileIf(CEnv& cenv, const AIf* aif) = 0;
- virtual CVal compileMatch(CEnv& cenv, const AMatch* match) = 0;
+ virtual CVal compileIf(CEnv& cenv, const ACall* aif) = 0;
+ virtual CVal compileMatch(CEnv& cenv, const ACall* match) = 0;
virtual CVal compileGlobal(CEnv& cenv, const AType* t, const string& sym, CVal val) = 0;
virtual CVal getGlobal(CEnv& cenv, const string& sym, CVal val) = 0;
virtual void writeModule(CEnv& cenv, std::ostream& os) = 0;