diff options
Diffstat (limited to 'src/resp.hpp')
-rw-r--r-- | src/resp.hpp | 48 |
1 files changed, 30 insertions, 18 deletions
diff --git a/src/resp.hpp b/src/resp.hpp index acf7725..57880f5 100644 --- a/src/resp.hpp +++ b/src/resp.hpp @@ -71,8 +71,9 @@ struct Error { * Backend Types * ***************************************************************************/ -typedef void* CVal; ///< Compiled value (opaque) -typedef void* CFunc; ///< Compiled function (opaque) +typedef const void* CType; ///< Compiled type (opaque) +typedef void* CVal; ///< Compiled value (opaque) +typedef void* CFunc; ///< Compiled function (opaque) /*************************************************************************** @@ -205,9 +206,12 @@ struct ATuple : public AST { ATuple(const AST* fst, const ATuple* rst, Cursor c=Cursor()) : AST(T_TUPLE, c), _fst(fst), _rst(rst) {} - const AST* fst() const { return _fst; } - const ATuple* rst() const { return _rst; } - bool empty() const { return _fst == 0 && _rst ==0; } + inline const AST* fst() const { return _fst; } + inline const ATuple* rst() const { return _rst; } + inline const AST* frst() const { return _rst->_fst; } + inline const AST* frrst() const { return _rst->_rst->_fst; } + + bool empty() const { return _fst == 0 && _rst ==0; } size_t list_len() const { size_t ret = 0; @@ -272,7 +276,7 @@ private: const ATuple* _rst; }; -inline ATuple* tup(Cursor c, AST* ast, ...) { +inline ATuple* tup(Cursor c, const AST* ast, ...) { ATuple* const head = new ATuple(ast, 0, c); if (!ast) return head; @@ -468,6 +472,7 @@ ostream& operator<<(ostream& out, const Env<V>& env) { /// Parse Time Environment (really just a symbol table) struct PEnv : private map<const string, const char*> { PEnv() : symID(0) {} + ~PEnv() { FOREACHP(const_iterator, i, this) free(const_cast<char*>(i->second)); } string gensymstr(const char* s="_") { return (format("%s_%d") % s % symID++).str(); } ASymbol* gensym(const char* s="_") { return sym(gensymstr(s)); } ASymbol* sym(const string& s, Cursor c=Cursor()) { @@ -580,6 +585,8 @@ struct TEnv : public Env<const AST*> { , Closure(penv.sym("Closure")) , Dots(penv.sym("...")) , Fn(penv.sym("Fn")) + , List(penv.sym("List")) + , Empty(penv.sym("Empty")) , Tup(penv.sym("Tup")) , U(penv.sym("U")) { @@ -616,6 +623,8 @@ struct TEnv : public Env<const AST*> { ASymbol* Closure; ASymbol* Dots; ASymbol* Fn; + ASymbol* List; + ASymbol* Empty; ASymbol* Tup; ASymbol* U; }; @@ -643,18 +652,21 @@ struct Engine { const ATuple* type, CFunc f) = 0; - virtual void finishFn(CEnv& cenv, CFunc f, CVal ret) = 0; - virtual void eraseFn(CEnv& cenv, CFunc f) = 0; - - virtual CVal compileCall(CEnv& cenv, CFunc f, const ATuple* fT, CVals& args) = 0; - virtual CVal compileCons(CEnv& cenv, const ATuple* t, CVal rtti, CVals& f) = 0; - virtual CVal compileDot(CEnv& cenv, CVal tup, int32_t index) = 0; - virtual CVal compileGlobalSet(CEnv& cenv, const string& s, CVal v, const AST* t) = 0; - virtual CVal compileGlobalGet(CEnv& cenv, const string& s, CVal v) = 0; - virtual CVal compileIf(CEnv& cenv, const AST* cond, const AST* then, const AST* aelse) = 0; - virtual CVal compileLiteral(CEnv& cenv, const AST* lit) = 0; - virtual CVal compilePrimitive(CEnv& cenv, const ATuple* prim) = 0; - virtual CVal compileString(CEnv& cenv, const char* str) = 0; + virtual void finishFn(CEnv& cenv, CFunc f, CVal ret, const AST* retT) = 0; + virtual void eraseFn(CEnv& cenv, CFunc f) = 0; + + virtual CVal compileCall(CEnv& cenv, CFunc f, const ATuple* fT, CVals& args) = 0; + virtual CVal compileCons(CEnv& cenv, const ATuple* t, CVal rtti, CVals& f) = 0; + virtual CVal compileDot(CEnv& cenv, CVal tup, int32_t index) = 0; + virtual CVal compileGlobalSet(CEnv& cenv, const string& s, CVal v, const AST* t) = 0; + virtual CVal compileGlobalGet(CEnv& cenv, const string& s, CVal v) = 0; + virtual CVal compileIf(CEnv& cenv, const AST* cond, const AST* then, const AST* aelse) = 0; + virtual CVal compileLiteral(CEnv& cenv, const AST* lit) = 0; + virtual CVal compilePrimitive(CEnv& cenv, const ATuple* prim) = 0; + virtual CVal compileString(CEnv& cenv, const char* str) = 0; + virtual CType compileType(CEnv& cenv, const char* name, const AST* exp) = 0; + + virtual CType objectType(CEnv& cenv) = 0; virtual void writeModule(CEnv& cenv, std::ostream& os) = 0; |