From 4861eb2317df37c83415debf65480249002f4180 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Fri, 20 Aug 2010 01:58:26 +0000 Subject: Make AST::compile const and make Module compilation API take const AST*. git-svn-id: http://svn.drobilla.net/resp/resp@265 ad02d1e2-f140-0410-9f75-f8b11f17cedd --- src/c.cpp | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'src/c.cpp') diff --git a/src/c.cpp b/src/c.cpp index 7f4a563..66ab971 100644 --- a/src/c.cpp +++ b/src/c.cpp @@ -150,14 +150,14 @@ struct CEngine : public Engine { return varname; } - CFunc compileFunction(CEnv& cenv, AFn* fn, const AType* type); + CFunc compileFunction(CEnv& cenv, const AFn* fn, const AType* type); CVal compileTup(CEnv& cenv, const AType* type, const vector& fields); CVal compileDot(CEnv& cenv, CVal tup, int32_t index); - CVal compileLiteral(CEnv& cenv, AST* lit); + CVal compileLiteral(CEnv& cenv, const AST* lit); CVal compileString(CEnv& cenv, const char* str); - CVal compilePrimitive(CEnv& cenv, APrimitive* prim); - CVal compileIf(CEnv& cenv, AIf* aif); + CVal compilePrimitive(CEnv& cenv, const APrimitive* prim); + CVal compileIf(CEnv& cenv, const AIf* aif); CVal compileGlobal(CEnv& cenv, const AType* type, const string& sym, CVal val); CVal getGlobal(CEnv& cenv, const string& sym, CVal val); @@ -196,7 +196,7 @@ CEngine::compileDot(CEnv& cenv, CVal tup, int32_t index) } CVal -CEngine::compileLiteral(CEnv& cenv, AST* lit) +CEngine::compileLiteral(CEnv& cenv, const AST* lit) { return new Value(lit->str()); } @@ -208,7 +208,7 @@ CEngine::compileString(CEnv& cenv, const char* str) } CFunc -CEngine::compileFunction(CEnv& cenv, AFn* fn, const AType* type) +CEngine::compileFunction(CEnv& cenv, const AFn* fn, const AType* type) { assert(type->concrete()); @@ -242,7 +242,7 @@ CEngine::compileFunction(CEnv& cenv, AFn* fn, const AType* type) // Write function body try { CVal retVal = NULL; - for (AFn::iterator i = fn->begin() + 2; i != fn->end(); ++i) + for (AFn::const_iterator i = fn->begin() + 2; i != fn->end(); ++i) retVal = (*i)->compile(cenv); cenv.engine()->finishFunction(cenv, f, retVal); } catch (Error& e) { @@ -255,13 +255,13 @@ CEngine::compileFunction(CEnv& cenv, AFn* fn, const AType* type) } CVal -CEngine::compileIf(CEnv& cenv, AIf* aif) +CEngine::compileIf(CEnv& cenv, const AIf* aif) { Value* varname = new string(cenv.penv.gensymstr("if")); out += (format("%s %s;\n") % *llType(cenv.type(aif)) % *varname).str(); size_t idx = 1; - for (AIf::iterator i = aif->begin() + 1; ; ++i, idx += 2) { - AIf::iterator next = i; + for (AIf::const_iterator i = aif->begin() + 1; ; ++i, idx += 2) { + AIf::const_iterator next = i; if (++next == aif->end()) break; @@ -287,14 +287,14 @@ CEngine::compileIf(CEnv& cenv, AIf* aif) } CVal -CEngine::compilePrimitive(CEnv& cenv, APrimitive* prim) +CEngine::compilePrimitive(CEnv& cenv, const APrimitive* prim) { - APrimitive::iterator i = prim->begin(); + APrimitive::const_iterator i = prim->begin(); ++i; Value* a = llVal((*i++)->compile(cenv)); Value* b = llVal((*i++)->compile(cenv)); - const string n = prim->head()->to()->str(); + const string n = prim->head()->to()->str(); string op = n; // Convert operator to C operator if they don't match -- cgit v1.2.1