diff options
Diffstat (limited to 'tuplr.hpp')
-rw-r--r-- | tuplr.hpp | 21 |
1 files changed, 13 insertions, 8 deletions
@@ -565,24 +565,30 @@ void tuplr_free_engine(CEngine engine); void finishFunction(CEnv& cenv, CFunction f, CValue ret); void eraseFunction(CEnv& cenv, CFunction f); +void writeModule(CEnv& cenv, std::ostream& os); + const string call(CEnv& cenv, CFunction f, AType* retT); /// Compile-Time Environment struct CEnv { - CEnv(PEnv& p, TEnv& t, CEngine e, ostream& os=std::cout, ostream& es=std::cerr); - ~CEnv(); + CEnv(PEnv& p, TEnv& t, CEngine e, ostream& os=std::cout, ostream& es=std::cerr) + : out(os), err(es), penv(p), tenv(t), symID(0), _engine(e) + {} + + ~CEnv() { Object::pool.collect(GC::Roots()); } typedef Env<const ASymbol*, AST*> Code; typedef Env<const AST*, CValue> Vals; - CEngine engine(); + CEngine 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(); } void precompile(AST* obj, CValue value) { vals.def(obj, value); } - CValue compile(AST* obj); - void optimise(CFunction f); - void write(std::ostream& os); + CValue compile(AST* obj) { + CValue* 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)); } AType* type(AST* ast, const Subst& subst = Subst()) const { ASymbol* sym = ast->to<ASymbol*>(); @@ -607,8 +613,7 @@ struct CEnv { map<string,string> args; private: - struct PImpl; ///< Private Implementation - PImpl* _pimpl; + CEngine _engine; }; |