From 1b61928f542f1c54ac67791f382b20b39927eac5 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Thu, 2 Dec 2010 18:36:49 +0000 Subject: Remove use of ACall class hierarchy from compile phase. git-svn-id: http://svn.drobilla.net/resp/resp@281 ad02d1e2-f140-0410-9f75-f8b11f17cedd --- src/compile.cpp | 88 +++++++++++++++++++++++++-------------------------------- 1 file changed, 39 insertions(+), 49 deletions(-) (limited to 'src/compile.cpp') diff --git a/src/compile.cpp b/src/compile.cpp index 8518051..9f9168a 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -66,6 +66,21 @@ compile_fn(CEnv& cenv, const AFn* fn) throw() return f; } +static CVal +compile_type(CEnv& cenv, const AType* type) throw() +{ + const ASymbol* sym = type->head()->as(); + 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() { @@ -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 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(cons->head()->as()), 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(); - 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(); - if (quote) - return resp_compile(cenv, quote->list_ref(1)); - const ALexeme* lexeme = ast->to(); 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(); if (fn) return compile_fn(cenv, fn); - - const ADef* def = ast->to(); - if (def) - return compile_def(cenv, def); - - const AIf* aif = ast->to(); - if (aif) - return cenv.engine()->compileIf(cenv, aif); - - const ACons* cons = ast->to(); - if (cons) - return compile_cons(cenv, cons); const APrimitive* prim = ast->to(); if (prim) return cenv.engine()->compilePrimitive(cenv, prim); - const AMatch* match = ast->to(); - if (match) - return cenv.engine()->compileMatch(cenv, match); - const AType* type = ast->to(); if (type) return compile_type(cenv, type); - const ADot* dot = ast->to(); - if (dot) - return compile_dot(cenv, dot); - - const ADefType* deftype = ast->to(); - if (deftype) - return NULL; - - const ACall* call = ast->to(); - if (call) - return compile_call(cenv, call); + const ACall* const call = ast->to(); + if (call) { + const ASymbol* const sym = call->head()->to(); + 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); -- cgit v1.2.1