aboutsummaryrefslogtreecommitdiffstats
path: root/src/resp.hpp
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2010-08-20 01:58:26 +0000
committerDavid Robillard <d@drobilla.net>2010-08-20 01:58:26 +0000
commit4861eb2317df37c83415debf65480249002f4180 (patch)
tree31da803fc9ec29f657587a7539636fda6307a567 /src/resp.hpp
parent594370a2a381545aea8d0631a86f422f84ee2792 (diff)
downloadresp-4861eb2317df37c83415debf65480249002f4180.tar.gz
resp-4861eb2317df37c83415debf65480249002f4180.tar.bz2
resp-4861eb2317df37c83415debf65480249002f4180.zip
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
Diffstat (limited to 'src/resp.hpp')
-rw-r--r--src/resp.hpp60
1 files changed, 30 insertions, 30 deletions
diff --git a/src/resp.hpp b/src/resp.hpp
index e551c0c..1432b0f 100644
--- a/src/resp.hpp
+++ b/src/resp.hpp
@@ -203,7 +203,7 @@ struct AST : public Object {
virtual AST* cps(TEnv& tenv, AST* cont) const;
virtual AST* lift(CEnv& cenv, Code& code) throw() { return this; }
virtual AST* depoly(CEnv& cenv, Code& code) throw() { return this; }
- virtual CVal compile(CEnv& cenv) throw() = 0;
+ virtual CVal compile(CEnv& env) const throw() = 0;
string str() const { ostringstream ss; ss << this; return ss.str(); }
template<typename T> T to() { return dynamic_cast<T>(this); }
template<typename T> T const to() const { return dynamic_cast<T const>(this); }
@@ -237,7 +237,7 @@ struct ALiteral : public AST {
return (r && (val == r->val));
}
void constrain(TEnv& tenv, Constraints& c) const throw(Error);
- CVal compile(CEnv& cenv) throw();
+ CVal compile(CEnv& env) const throw();
const T val;
};
@@ -246,7 +246,7 @@ struct ALexeme : public AST, public std::string {
ALexeme(Cursor c, const string& s) : AST(c), std::string(s) {}
bool operator==(const AST& rhs) const { return this == &rhs; }
void constrain(TEnv& tenv, Constraints& c) const throw(Error);
- CVal compile(CEnv& cenv) throw();
+ CVal compile(CEnv& env) const throw();
};
/// String, e.g. ""a""
@@ -254,7 +254,7 @@ struct AString : public AST, public std::string {
AString(Cursor c, const string& s) : AST(c), std::string(s) {}
bool operator==(const AST& rhs) const { return this == &rhs; }
void constrain(TEnv& tenv, Constraints& c) const throw(Error);
- CVal compile(CEnv& cenv) throw();
+ CVal compile(CEnv& env) const throw();
};
/// Symbol, e.g. "a"
@@ -262,7 +262,7 @@ struct ASymbol : public AST {
bool operator==(const AST& rhs) const { return this == &rhs; }
void constrain(TEnv& tenv, Constraints& c) const throw(Error);
AST* lift(CEnv& cenv, Code& code) throw();
- CVal compile(CEnv& cenv) throw();
+ CVal compile(CEnv& env) const throw();
const string cppstr;
private:
friend class PEnv;
@@ -329,7 +329,7 @@ struct ATuple : public AST {
AST* lift(CEnv& cenv, Code& code) throw();
AST* depoly(CEnv& cenv, Code& code) throw();
- CVal compile(CEnv& cenv) throw();
+ CVal compile(CEnv& env) const throw();
private:
size_t _len;
@@ -344,7 +344,7 @@ struct AType : public ATuple {
AType(Cursor c, Kind k=EXPR) : ATuple(c), kind(k), id(0) {}
AType(Cursor c, AST* ast, va_list args) : ATuple(c, ast, args), kind(EXPR), id(0) {}
AType(const AType& copy) : ATuple(copy), kind(copy.kind), id(copy.id) { }
- CVal compile(CEnv& cenv) throw() { return NULL; }
+ CVal compile(CEnv& env) const throw() { return NULL; }
const ATuple* prot() const { assert(kind == EXPR); return (*(begin() + 1))->to<const ATuple*>(); }
ATuple* prot() { assert(kind == EXPR); return (*(begin() + 1))->to<ATuple*>(); }
bool concrete() const {
@@ -387,7 +387,7 @@ struct AFn : public ATuple {
AST* cps(TEnv& tenv, AST* cont) const;
AST* lift(CEnv& cenv, Code& code) throw();
AST* depoly(CEnv& cenv, Code& code) throw();
- CVal compile(CEnv& cenv) throw();
+ CVal compile(CEnv& env) const throw();
const ATuple* prot() const { return (*(begin() + 1))->to<const ATuple*>(); }
ATuple* prot() { return (*(begin() + 1))->to<ATuple*>(); }
string name;
@@ -401,7 +401,7 @@ struct ACall : public ATuple {
AST* cps(TEnv& tenv, AST* cont) const;
AST* lift(CEnv& cenv, Code& code) throw();
AST* depoly(CEnv& cenv, Code& code) throw();
- CVal compile(CEnv& cenv) throw();
+ CVal compile(CEnv& env) const throw();
};
/// Definition special form, e.g. "(def x 2)"
@@ -424,7 +424,7 @@ struct ADef : public ACall {
AST* cps(TEnv& tenv, AST* cont) const;
AST* lift(CEnv& cenv, Code& code) throw();
AST* depoly(CEnv& cenv, Code& code) throw();
- CVal compile(CEnv& cenv) throw();
+ CVal compile(CEnv& env) const throw();
};
/// Conditional special form, e.g. "(if cond thenexp elseexp)"
@@ -435,7 +435,7 @@ struct AIf : public ACall {
AST* cps(TEnv& tenv, AST* cont) const;
AST* lift(CEnv& cenv, Code& code) throw();
AST* depoly(CEnv& cenv, Code& code) throw();
- CVal compile(CEnv& cenv) throw();
+ CVal compile(CEnv& env) const throw();
};
struct ACons : public ACall {
@@ -444,7 +444,7 @@ struct ACons : public ACall {
void constrain(TEnv& tenv, Constraints& c) const throw(Error);
AST* lift(CEnv& cenv, Code& code) throw();
AST* depoly(CEnv& cenv, Code& code) throw();
- CVal compile(CEnv& cenv) throw();
+ CVal compile(CEnv& env) const throw();
};
struct ADot : public ACall {
@@ -453,7 +453,7 @@ struct ADot : public ACall {
void constrain(TEnv& tenv, Constraints& c) const throw(Error);
AST* lift(CEnv& cenv, Code& code) throw();
AST* depoly(CEnv& cenv, Code& code) throw();
- CVal compile(CEnv& cenv) throw();
+ CVal compile(CEnv& env) const throw();
};
/// Primitive (builtin arithmetic function), e.g. "(+ 2 3)"
@@ -470,14 +470,14 @@ struct APrimitive : public ACall {
AST* cps(TEnv& tenv, AST* cont) const;
AST* lift(CEnv& cenv, Code& code) throw();
AST* depoly(CEnv& cenv, Code& code) throw();
- CVal compile(CEnv& cenv) throw();
+ CVal compile(CEnv& env) const throw();
};
struct AQuote : public ACall {
AQuote(const ATuple* exp) : ACall(exp) {}
void constrain(TEnv& tenv, Constraints& c) const throw(Error);
AST* lift(CEnv& cenv, Code& code) throw();
- CVal compile(CEnv& cenv) throw();
+ CVal compile(CEnv& env) const throw();
};
@@ -665,14 +665,14 @@ struct Engine {
virtual void finishFunction(CEnv& cenv, CFunc f, CVal ret) = 0;
virtual void eraseFunction(CEnv& cenv, CFunc f) = 0;
- virtual CFunc compileFunction(CEnv& cenv, AFn* fn, const AType* type) = 0;
+ virtual CFunc compileFunction(CEnv& cenv, const AFn* fn, const AType* type) = 0;
virtual CVal compileTup(CEnv& cenv, const AType* t, ValVec& f) = 0;
virtual CVal compileDot(CEnv& cenv, CVal tup, int32_t index) = 0;
- virtual CVal compileLiteral(CEnv& cenv, AST* lit) = 0;
+ virtual CVal compileLiteral(CEnv& cenv, const AST* lit) = 0;
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, APrimitive* prim) = 0;
- virtual CVal compileIf(CEnv& cenv, AIf* aif) = 0;
+ virtual CVal compilePrimitive(CEnv& cenv, const APrimitive* prim) = 0;
+ virtual CVal compileIf(CEnv& cenv, const AIf* aif) = 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;
@@ -696,13 +696,13 @@ struct CEnv {
Engine* engine() { return _engine; }
void push() { code.push(); tenv.push(); vals.push(); }
void pop() { code.pop(); tenv.pop(); vals.pop(); }
- void lock(AST* ast) {
+ void lock(const AST* ast) {
Object::pool.addRoot(ast);
if (type(ast))
Object::pool.addRoot(type(ast));
}
- const AType* type(AST* ast, const Subst& subst = Subst()) const {
- ASymbol* sym = ast->to<ASymbol*>();
+ const AType* type(const AST* ast, const Subst& subst = Subst()) const {
+ const ASymbol* sym = ast->to<const ASymbol*>();
if (sym) {
const AType** rec = tenv.ref(sym);
return rec ? *rec : NULL;
@@ -713,14 +713,14 @@ struct CEnv {
}
return NULL;
}
- void def(const ASymbol* sym, AST* c, const AType* t, CVal v) {
+ void def(const ASymbol* sym, const AST* c, const AType* t, CVal v) {
code.def(sym, c);
tenv.def(sym, t);
vals.def(sym, v);
}
- AST* resolve(AST* ast) {
+ const AST* resolve(const AST* ast) {
const ASymbol* sym = ast->to<const ASymbol*>();
- AST** rec = code.ref(sym);
+ const AST** rec = code.ref(sym);
return rec ? *rec : ast;
}
void setType(AST* ast, const AType* type) {
@@ -739,17 +739,17 @@ struct CEnv {
Vals vals;
Subst tsubst;
- Env<const ASymbol*, AST*> code;
+ Env<const ASymbol*, const AST*> code;
- typedef map<AFn*, CFunc> Impls;
+ typedef map<const AFn*, CFunc> Impls;
Impls impls;
- CFunc findImpl(AFn* fn, const AType* type) {
- Impls::iterator i = impls.find(fn);
+ CFunc findImpl(const AFn* fn, const AType* type) {
+ Impls::const_iterator i = impls.find(fn);
return (i != impls.end()) ? i->second : NULL;
}
- void addImpl(AFn* fn, CFunc impl) {
+ void addImpl(const AFn* fn, CFunc impl) {
impls.insert(make_pair(fn, impl));
}