aboutsummaryrefslogtreecommitdiffstats
path: root/src/resp.hpp
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2010-12-29 00:35:28 +0000
committerDavid Robillard <d@drobilla.net>2010-12-29 00:35:28 +0000
commit42b51cce2575fa138fddf1cfd4581bf1d1568b24 (patch)
tree03ea8256f19d3418fd4e847391a4b5a84f8b6e0f /src/resp.hpp
parent703f1840af79ca4480c664190cdcf7e6fbd7b90e (diff)
downloadresp-42b51cce2575fa138fddf1cfd4581bf1d1568b24.tar.gz
resp-42b51cce2575fa138fddf1cfd4581bf1d1568b24.tar.bz2
resp-42b51cce2575fa138fddf1cfd4581bf1d1568b24.zip
Literal lists (i.e. list quoting).
Compile type expressions. Only compile a top-level function if program has code to run (i.e. isn't just definitions). Cast tuples to Object when necessary to avoid LLVM IR type mismatches (for cons stores and return values). Fix memory leaks. git-svn-id: http://svn.drobilla.net/resp/resp@369 ad02d1e2-f140-0410-9f75-f8b11f17cedd
Diffstat (limited to 'src/resp.hpp')
-rw-r--r--src/resp.hpp48
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;