aboutsummaryrefslogtreecommitdiffstats
path: root/src/tuplr.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/tuplr.hpp')
-rw-r--r--src/tuplr.hpp68
1 files changed, 34 insertions, 34 deletions
diff --git a/src/tuplr.hpp b/src/tuplr.hpp
index 2814578..7295c5e 100644
--- a/src/tuplr.hpp
+++ b/src/tuplr.hpp
@@ -120,8 +120,8 @@ AST* readExpression(Cursor& cur, std::istream& in);
* Backend Types *
***************************************************************************/
-typedef void* CValue; ///< Compiled value (opaque)
-typedef void* CFunction; ///< Compiled function (opaque)
+typedef void* CVal; ///< Compiled value (opaque)
+typedef void* CFunc; ///< Compiled function (opaque)
/***************************************************************************
@@ -193,7 +193,7 @@ struct AST : public Object {
virtual void constrain(TEnv& tenv, Constraints& c) const {}
virtual AST* cps(TEnv& tenv, AST* cont);
virtual void lift(CEnv& cenv) {}
- virtual CValue compile(CEnv& cenv) = 0;
+ virtual CVal compile(CEnv& cenv) = 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); }
@@ -227,7 +227,7 @@ struct ALiteral : public AST {
return (r && (val == r->val));
}
void constrain(TEnv& tenv, Constraints& c) const;
- CValue compile(CEnv& cenv);
+ CVal compile(CEnv& cenv);
const T val;
};
@@ -236,14 +236,14 @@ 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;
- CValue compile(CEnv& cenv) { return NULL; }
+ CVal compile(CEnv& cenv) { return NULL; }
};
/// Symbol, e.g. "a"
struct ASymbol : public AST {
bool operator==(const AST& rhs) const { return this == &rhs; }
void constrain(TEnv& tenv, Constraints& c) const;
- CValue compile(CEnv& cenv);
+ CVal compile(CEnv& cenv);
mutable LAddr addr;
const string cppstr;
private:
@@ -302,7 +302,7 @@ struct ATuple : public AST {
void constrain(TEnv& tenv, Constraints& c) const;
void lift(CEnv& cenv) { FOREACH(iterator, t, *this) (*t)->lift(cenv); }
- CValue compile(CEnv& cenv) { throw Error(loc, "tuple compiled"); }
+ CVal compile(CEnv& cenv) { throw Error(loc, "tuple compiled"); }
private:
size_t _len;
@@ -315,7 +315,7 @@ struct AType : public ATuple {
AType(Cursor c, unsigned i) : ATuple(c), kind(VAR), id(i) {}
AType(Cursor c) : ATuple(c), kind(EXPR), id(0) {}
AType(Cursor c, AST* ast, va_list args) : ATuple(c, ast, args), kind(EXPR), id(0) {}
- CValue compile(CEnv& cenv) { return NULL; }
+ CVal compile(CEnv& cenv) { return NULL; }
bool concrete() const {
switch (kind) {
case VAR: return false;
@@ -392,12 +392,12 @@ struct AFn : public ATuple {
void constrain(TEnv& tenv, Constraints& c) const;
AST* cps(TEnv& tenv, AST* cont);
void lift(CEnv& cenv);
- CValue compile(CEnv& cenv);
+ CVal compile(CEnv& cenv);
const ATuple* prot() const { return at(1)->to<const ATuple*>(); }
ATuple* prot() { return at(1)->to<ATuple*>(); }
/// System level implementations of this (polymorphic) fn
- struct Impls : public list< pair<AType*, CFunction> > {
- CFunction find(AType* type) const {
+ struct Impls : public list< pair<AType*, CFunc> > {
+ CFunc find(AType* type) const {
for (const_iterator f = begin(); f != end(); ++f)
if (*f->first == *type)
return f->second;
@@ -416,7 +416,7 @@ struct ACall : public ATuple {
void constrain(TEnv& tenv, Constraints& c) const;
AST* cps(TEnv& tenv, AST* cont);
void lift(CEnv& cenv);
- CValue compile(CEnv& cenv);
+ CVal compile(CEnv& cenv);
};
/// Definition special form, e.g. "(def x 2)"
@@ -435,7 +435,7 @@ struct ADef : public ACall {
void constrain(TEnv& tenv, Constraints& c) const;
AST* cps(TEnv& tenv, AST* cont);
void lift(CEnv& cenv);
- CValue compile(CEnv& cenv);
+ CVal compile(CEnv& cenv);
};
/// Conditional special form, e.g. "(if cond thenexp elseexp)"
@@ -444,7 +444,7 @@ struct AIf : public ACall {
AIf(Cursor c, AST* ast, va_list args) : ACall(c, ast, args) {}
void constrain(TEnv& tenv, Constraints& c) const;
AST* cps(TEnv& tenv, AST* cont);
- CValue compile(CEnv& cenv);
+ CVal compile(CEnv& cenv);
};
/// Primitive (builtin arithmetic function), e.g. "(+ 2 3)"
@@ -459,7 +459,7 @@ struct APrimitive : public ACall {
}
void constrain(TEnv& tenv, Constraints& c) const;
AST* cps(TEnv& tenv, AST* cont);
- CValue compile(CEnv& cenv);
+ CVal compile(CEnv& cenv);
};
@@ -620,23 +620,23 @@ Subst unify(const Constraints& c);
/// Compiler backend
struct Engine {
- virtual CFunction startFunction(
+ virtual CFunc startFunction(
CEnv& cenv,
const std::string& name,
const AType* retT,
const ATuple& argsT,
const vector<string> argNames=vector<string>()) = 0;
- virtual void finishFunction(CEnv& cenv, CFunction f, const AType* retT, CValue ret) = 0;
- virtual void eraseFunction(CEnv& cenv, CFunction f) = 0;
- virtual CFunction compileFunction(CEnv& cenv, AFn* fn, const AType& argsT) = 0;
- virtual CValue compileLiteral(CEnv& cenv, AST* lit) = 0;
- virtual CValue compileCall(CEnv& cenv, CFunction f, const vector<CValue>& args) = 0;
- virtual CValue compilePrimitive(CEnv& cenv, APrimitive* prim) = 0;
- virtual CValue compileIf(CEnv& cenv, AIf* aif) = 0;
- virtual void writeModule(CEnv& cenv, std::ostream& os) = 0;
+ virtual void finishFunction(CEnv& cenv, CFunc f, const AType* retT, CVal ret) = 0;
+ virtual void eraseFunction(CEnv& cenv, CFunc f) = 0;
+ virtual CFunc compileFunction(CEnv& cenv, AFn* fn, const AType& argsT) = 0;
+ virtual CVal compileLiteral(CEnv& cenv, AST* lit) = 0;
+ virtual CVal compileCall(CEnv& cenv, CFunc f, const vector<CVal>& args) = 0;
+ virtual CVal compilePrimitive(CEnv& cenv, APrimitive* prim) = 0;
+ virtual CVal compileIf(CEnv& cenv, AIf* aif) = 0;
+ virtual void writeModule(CEnv& cenv, std::ostream& os) = 0;
- virtual const string call(CEnv& cenv, CFunction f, AType* retT) = 0;
+ virtual const string call(CEnv& cenv, CFunc f, AType* retT) = 0;
};
Engine* tuplr_new_llvm_engine();
@@ -650,14 +650,14 @@ struct CEnv {
~CEnv() { Object::pool.collect(GC::Roots()); }
- typedef Env<const AST*, CValue> Vals;
+ typedef Env<const AST*, CVal> Vals;
Engine* engine() { return _engine; }
void push() { tenv.push(); vals.push(); }
void pop() { tenv.pop(); vals.pop(); }
- void precompile(AST* obj, CValue value) { vals.def(obj, value); }
- CValue compile(AST* obj) {
- CValue* v = vals.ref(obj);
+ void precompile(AST* obj, CVal value) { vals.def(obj, value); }
+ CVal compile(AST* obj) {
+ CVal* v = vals.ref(obj);
return (v && *v) ? *v : vals.def(obj, obj->compile(*this));
}
void lock(AST* ast) { Object::pool.addRoot(ast); Object::pool.addRoot(type(ast)); }
@@ -667,7 +667,7 @@ struct CEnv {
return sym->addr ? tenv.deref(sym->addr).second : NULL;
return tsubst.apply(subst.apply(tenv.vars[ast]))->to<AType*>();
}
- void def(const ASymbol* sym, AST* c, AType* t, CValue v) {
+ void def(const ASymbol* sym, AST* c, AType* t, CVal v) {
tenv.def(sym, make_pair(c, t));
vals.def(sym, v);
}
@@ -691,9 +691,9 @@ private:
* EVAL/REPL/MAIN *
***************************************************************************/
-void pprint(std::ostream& out, const AST* ast);
-void initLang(PEnv& penv, TEnv& tenv);
-int eval(CEnv& cenv, const string& name, istream& is, bool execute);
-int repl(CEnv& cenv);
+void pprint(std::ostream& out, const AST* ast);
+void initLang(PEnv& penv, TEnv& tenv);
+int eval(CEnv& cenv, const string& name, istream& is, bool execute);
+int repl(CEnv& cenv);
#endif // TUPLR_HPP