diff options
-rw-r--r-- | src/gc.cpp | 1 | ||||
-rw-r--r-- | src/lift.cpp | 2 | ||||
-rw-r--r-- | src/resp.hpp | 22 |
3 files changed, 14 insertions, 11 deletions
@@ -43,7 +43,6 @@ GC::alloc(size_t size) size += (4 - (size % 4)); // Align to 32-bits size += sizeof(Object::Header); void* ret = tlsf_malloc((tlsf_t*)_pool, size); - ((Object::Header*)ret)->mark = 0; ((Object::Header*)ret)->tag = Object::AST; ret = (char*)ret + sizeof(Object::Header); _heap.push_back((Object*)ret); diff --git a/src/lift.cpp b/src/lift.cpp index b2ead08..563fd5d 100644 --- a/src/lift.cpp +++ b/src/lift.cpp @@ -113,7 +113,7 @@ AFn::lift(CEnv& cenv, Code& code) throw() // Create definition for implementation fn ASymbol* implName = cenv.penv.sym(impl->name); - ADef* def = tup<ADef>(loc, cenv.penv.sym("def"), implName, impl, NULL); + ADef* def = tup<ADef>(loc, cenv.penv.sym("def"), implName, impl, NULL); code.push_back(def); AType* implT = new AType(*type); // Type of the implementation function diff --git a/src/resp.hpp b/src/resp.hpp index a7080fe..a972d48 100644 --- a/src/resp.hpp +++ b/src/resp.hpp @@ -57,7 +57,7 @@ struct Cursor { unsigned col; }; -/// Compiler error +/// Compilation error struct Error { Error(Cursor c, const string& m) : loc(c), msg(m) {} const string what() const { return (loc ? loc.str() + ": " : "") + "error: " + msg; } @@ -152,17 +152,21 @@ private: /// Garbage collected object (including AST and runtime data) struct Object { - enum Tag { OBJECT = 123, AST = 456 }; + enum Tag { OBJECT = 1<<1, AST = 1<<2 }; struct Header { - uint32_t mark; - uint32_t tag; + uint32_t tag; ///< Rightmost bit is mark }; - 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 = (b ? 1 : 0); } + inline Tag tag() const { return (Tag)((header()->tag >> 1) << 1); } + inline void tag(Tag t) { header()->tag = (t | (marked() ? 1 : 0)); } + inline bool marked() const { return (header()->tag & 1); } + inline void mark(bool b) const { + if (b) + header()->tag |= 1; + else + header()->tag = ((header()->tag >> 1) << 1); + } static void* operator new(size_t size) { return pool.alloc(size); } static void operator delete(void* ptr) {} @@ -713,7 +717,7 @@ Engine* resp_new_c_engine(); /// Compile-Time Environment struct CEnv { CEnv(PEnv& p, TEnv& t, Engine* e, ostream& os=std::cout, ostream& es=std::cerr) - : out(os), err(es), penv(p), tenv(t), _engine(e) + : out(os), err(es), penv(p), tenv(t), currentFn(NULL), _engine(e) {} ~CEnv() { Object::pool.collect(GC::Roots()); } |