aboutsummaryrefslogtreecommitdiffstats
path: root/src/tuplr.hpp
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2009-10-16 01:53:16 +0000
committerDavid Robillard <d@drobilla.net>2009-10-16 01:53:16 +0000
commitc2d75892af2fdc6b9bf25365a15de5dc63bcc852 (patch)
tree22234de7261ca54f6c1d01e0ff271cbde5af0699 /src/tuplr.hpp
parent474b2a748bfdb55aac43bba998bc79a5c9d18675 (diff)
downloadresp-c2d75892af2fdc6b9bf25365a15de5dc63bcc852.tar.gz
resp-c2d75892af2fdc6b9bf25365a15de5dc63bcc852.tar.bz2
resp-c2d75892af2fdc6b9bf25365a15de5dc63bcc852.zip
Cons.
git-svn-id: http://svn.drobilla.net/resp/tuplr@235 ad02d1e2-f140-0410-9f75-f8b11f17cedd
Diffstat (limited to 'src/tuplr.hpp')
-rw-r--r--src/tuplr.hpp31
1 files changed, 25 insertions, 6 deletions
diff --git a/src/tuplr.hpp b/src/tuplr.hpp
index dce52b2..31585d2 100644
--- a/src/tuplr.hpp
+++ b/src/tuplr.hpp
@@ -129,19 +129,29 @@ private:
/// Garbage collected object (including AST and runtime data)
struct Object {
+ enum Tag { OBJECT = 123, AST = 456 };
+
struct Header {
- uint8_t mark;
+ uint32_t mark;
+ uint32_t tag;
};
- /// Always allocated with pool.alloc, so this - sizeof(Header) is a valid Header*.
- inline Header* header() const { return (Header*)((char*)this - sizeof(Header)); }
-
+ inline Tag tag() const { return (Tag)header()->tag; }
+ inline void tag(Tag t) { header()->tag = t; }
inline bool marked() const { return header()->mark != 0; }
inline void mark(bool b) const { header()->mark = 1; }
- static void* operator new(size_t size) { return pool.alloc(size); }
+ static void* operator new(size_t size) { return pool.alloc(size); }
static void operator delete(void* ptr) {}
+
+ // Memory used with placement new MUST always be allocated with pool.alloc!
+ static void* operator new(size_t size, void* ptr) { return ptr; }
+
static GC pool;
+
+private:
+ /// Always allocated with pool.alloc, so this - sizeof(Header) is a valid Header*.
+ inline Header* header() const { return (Header*)((char*)this - sizeof(Header)); }
};
@@ -424,6 +434,12 @@ struct AIf : public ACall {
CVal compile(CEnv& cenv);
};
+struct ACons : public ACall {
+ ACons(const ATuple* exp) : ACall(exp) {}
+ void constrain(TEnv& tenv, Constraints& c) const;
+ CVal compile(CEnv& cenv);
+};
+
/// Primitive (builtin arithmetic function), e.g. "(+ 2 3)"
struct APrimitive : public ACall {
APrimitive(const ATuple* exp) : ACall(exp) {}
@@ -546,7 +562,8 @@ inline ostream& operator<<(ostream& out, const Constraints& c) {
/// Type-Time Environment
struct TEnv : public Env<const ASymbol*, AType*> {
- TEnv(PEnv& p) : penv(p), varID(1), Fn(new AType(penv.sym("Fn"))) {
+ TEnv(PEnv& p) : penv(p), varID(1),
+ Fn(new AType(penv.sym("Fn"))), Tup(new AType(penv.sym("Tup"))) {
Object::pool.addRoot(Fn);
}
AType* fresh(const ASymbol* sym) {
@@ -579,6 +596,7 @@ struct TEnv : public Env<const ASymbol*, AType*> {
unsigned varID;
AType* Fn;
+ AType* Tup;
};
Subst unify(const Constraints& c);
@@ -600,6 +618,7 @@ struct Engine {
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 compileTup(CEnv& cenv, const AType* t, const vector<CVal>& f) = 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;