aboutsummaryrefslogtreecommitdiffstats
path: root/src/compile.cpp
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 /src/compile.cpp
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
Diffstat (limited to 'src/compile.cpp')
-rw-r--r--src/compile.cpp88
1 files changed, 39 insertions, 49 deletions
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);