aboutsummaryrefslogtreecommitdiffstats
path: root/tuplr.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'tuplr.hpp')
-rw-r--r--tuplr.hpp26
1 files changed, 14 insertions, 12 deletions
diff --git a/tuplr.hpp b/tuplr.hpp
index 2da326a..268d0b1 100644
--- a/tuplr.hpp
+++ b/tuplr.hpp
@@ -556,22 +556,24 @@ struct TEnv : public Env< const ASymbol*, pair<AST*, AType*> > {
* Code Generation *
***************************************************************************/
-CFunction startFunction(CEnv& cenv, const std::string& name,
- const AType* retT, const ATuple& argsT,
- const vector<string> argNames=vector<string>());
+struct Engine {
+ virtual CFunction startFunction(CEnv& cenv, const std::string& name,
+ const AType* retT, const ATuple& argsT,
+ const vector<string> argNames=vector<string>()) = 0;
-CEngine tuplr_new_engine();
-void tuplr_free_engine(CEngine engine);
+ virtual void finishFunction(CEnv& cenv, CFunction f, CValue ret) = 0;
+ virtual void eraseFunction(CEnv& cenv, CFunction f) = 0;
+ virtual void writeModule(CEnv& cenv, std::ostream& os) = 0;
-void finishFunction(CEnv& cenv, CFunction f, CValue ret);
-void eraseFunction(CEnv& cenv, CFunction f);
-void writeModule(CEnv& cenv, std::ostream& os);
+ virtual const string call(CEnv& cenv, CFunction f, AType* retT) = 0;
+};
-const string call(CEnv& cenv, CFunction f, AType* retT);
+Engine* tuplr_new_engine();
+void tuplr_free_engine(Engine* engine);
/// Compile-Time Environment
struct CEnv {
- CEnv(PEnv& p, TEnv& t, CEngine e, ostream& os=std::cout, ostream& es=std::cerr)
+ CEnv(PEnv& p, TEnv& t, Engine* e, ostream& os=std::cout, ostream& es=std::cerr)
: out(os), err(es), penv(p), tenv(t), symID(0), _engine(e)
{}
@@ -580,7 +582,7 @@ struct CEnv {
typedef Env<const ASymbol*, AST*> Code;
typedef Env<const AST*, CValue> Vals;
- CEngine engine() { return _engine; }
+ Engine* engine() { return _engine; }
string gensym(const char* s="_") { return (format("%s%d") % s % symID++).str(); }
void push() { tenv.push(); vals.push(); }
void pop() { tenv.pop(); vals.pop(); }
@@ -613,7 +615,7 @@ struct CEnv {
map<string,string> args;
private:
- CEngine _engine;
+ Engine* _engine;
};