Index: src/examples/gc_no_raii/bug-repro/push_back.c
===================================================================
--- src/examples/gc_no_raii/bug-repro/push_back.c	(revision 385c1309bdc9ace6d6de8377cf50fe8b65bccccb)
+++ src/examples/gc_no_raii/bug-repro/push_back.c	(revision 385c1309bdc9ace6d6de8377cf50fe8b65bccccb)
@@ -0,0 +1,48 @@
+#include <stddef.h>
+#include <stdint.h>
+
+//------------------------------------------------------------------------------
+//Declaration
+trait allocator_c(otype T, otype allocator_t) {
+	void realloc(allocator_t*, size_t);
+	T* data(allocator_t*);
+};
+
+forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
+struct vector
+{
+	allocator_t storage;
+	size_t size;
+};
+
+//------------------------------------------------------------------------------
+//Allocator
+forall(otype T)
+struct heap_allocator
+{
+	T* storage;
+	size_t capacity;
+};
+
+forall(otype T)
+void realloc(heap_allocator(T)* this, size_t size);
+
+forall(otype T)
+inline T* data(heap_allocator(T)* this)
+{
+	return this->storage;
+}
+
+//------------------------------------------------------------------------------
+//Modifiers
+forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
+void push_back(vector(T, allocator_t)* this, T value);
+
+typedef vector(intptr_t*, heap_allocator(intptr_t*)) worklist_t;
+
+inline void test()
+{
+	worklist_t w;
+	intptr_t zero = 0;
+	push_back(&w, &zero);
+}
Index: src/examples/gc_no_raii/bug-repro/test-assert.cpp
===================================================================
--- src/examples/gc_no_raii/bug-repro/test-assert.cpp	(revision 385c1309bdc9ace6d6de8377cf50fe8b65bccccb)
+++ src/examples/gc_no_raii/bug-repro/test-assert.cpp	(revision 385c1309bdc9ace6d6de8377cf50fe8b65bccccb)
@@ -0,0 +1,9 @@
+#include <cassert>
+#include "../src/tools/checks.h"
+
+int main(int argc, char* argv[])
+{
+	//check(false);
+	assert(false);
+	return 0;
+}
Index: src/examples/gc_no_raii/bug-repro/void_pointer.c
===================================================================
--- src/examples/gc_no_raii/bug-repro/void_pointer.c	(revision 356bb95354e95f40bbe00b79e4432f16fc689ecf)
+++ src/examples/gc_no_raii/bug-repro/void_pointer.c	(revision 385c1309bdc9ace6d6de8377cf50fe8b65bccccb)
@@ -2,8 +2,8 @@
 #include <stdint.h>
 
-//inline intptr_t test(void* address)
-//{
-//	return (intptr_t)address;
-//}
+inline void* test(intptr_t address)
+{
+	return (void*)address;
+}
 
 //inline void* test2(void* address)
@@ -12,7 +12,7 @@
 //}
 
-inline int test()
-{
-	void* d = 0;
-	return (int)d;
-}
+// inline int test()
+// {
+// 	void* d = 0;
+// 	return (int)d;
+// }
Index: c/examples/gc_no_raii/cfa
===================================================================
--- src/examples/gc_no_raii/cfa	(revision 356bb95354e95f40bbe00b79e4432f16fc689ecf)
+++ 	(revision )
@@ -1,1 +1,0 @@
-../../../bin/cfa
Index: src/examples/gc_no_raii/regen_makefile.sh
===================================================================
--- src/examples/gc_no_raii/regen_makefile.sh	(revision 356bb95354e95f40bbe00b79e4432f16fc689ecf)
+++ src/examples/gc_no_raii/regen_makefile.sh	(revision 385c1309bdc9ace6d6de8377cf50fe8b65bccccb)
@@ -3,4 +3,4 @@
 premake4 clean
 premake4 gmake
-sed '/# GNU Make project makefile autogenerated by Premake/a CC = ..\/cfa\nCXX = ..\/cfa\n' build/Makefile > out
+sed '/# GNU Make project makefile autogenerated by Premake/a CC = cfa\nCXX = cfa\n' build/Makefile > out
 mv out build/Makefile
Index: src/examples/gc_no_raii/src/gcpointers.c
===================================================================
--- src/examples/gc_no_raii/src/gcpointers.c	(revision 356bb95354e95f40bbe00b79e4432f16fc689ecf)
+++ src/examples/gc_no_raii/src/gcpointers.c	(revision 385c1309bdc9ace6d6de8377cf50fe8b65bccccb)
@@ -6,99 +6,94 @@
 #include "internal/state.h"
 
-// void register_ptr(gcpointer_t* this)
-// {
-// 	if(gcpointer_null(this)) return;
-//
-// 	_Bool managed = gc_is_managed(this);
-//
-//
-// 	gc_state* state = gc_get_state();
-// 	gc_object_header* obj = 0;
-// 	if(managed)
-// 	{
-// 		obj = gc_get_object_for_ref(state, (void*)this);
-// 		check(obj);
-// 		check(gc_obj_is_valide(obj));
-// 		check(gc_is_managed(this) == gc_is_managed(obj->type_chain) || obj->type_chain == NULL);
-// 		this->next = obj->type_chain;
-// 		obj->type_chain = this;
-// 		check(obj->is_valide());
-// 	}
-// 	else
-// 	{
-// 		obj = gc_get_object_ptr(state, (void*)this->ptr);
-// 		check(obj);
-// 		check(gc_obj_is_valide(obj));
-// 		check(gc_is_managed(this) == gc_is_managed(obj->root_chain) || obj->root_chain == NULL);
-// 		this->next = obj->root_chain;
-// 		obj->root_chain = this;
-// 		check(gc_obj_is_valide(obj));
-// 	}
-// }
-//
-// void unregister_ptr(gcpointer_t* this)
-// {
-// 	if(gcpointer_null(this)) return;
-//
-// 	gcpointer_t** prev_next_ptr = gc_find_previous_ref(this);
-// 	check((*prev_next_ptr) == this);
-//
-// 	(*prev_next_ptr) = this->next;
-// }
-//
-// void gcpointer_ctor(gcpointer_t* this)
-// {
-// 	this->ptr = (intptr_t)NULL;
-// 	this->next = NULL;
-// }
-//
-// void gcpointer_ctor(gcpointer_t* this, void* address)
-// {
-// 	this->ptr = (intptr_t)address;
-// 	this->next = NULL;
-//
-// 	register_ptr(this);
-// }
-//
-// void gcpointer_ctor(gcpointer_t* this, gcpointer_t* other)
-// {
-// 	this->ptr = other->ptr;
-// 	this->next = NULL;
-//
-// 	register_ptr(this);
-// }
-//
-// void gcpointer_dtor(gcpointer_t* this)
-// {
-// 	unregister_ptr(this);
-// }
-//
-// gcpointer_t* gcpointer_assign(gcpointer_t* this, gcpointer_t* rhs)
-// {
-// 	if(this != rhs)
-// 	{
-// 		unregister_ptr(this);
-//
-// 		this->ptr = rhs->ptr;
-//
-// 		register_ptr(this);
-// 	}
-//
-// 	return this;
-// }
-//
-// //Logical operators
-// int gcpointer_equal(gcpointer_t* this, gcpointer_t* rhs)
-// {
-// 	return this->ptr == rhs->ptr;
-// }
-//
-// int gcpointer_not_equal(gcpointer_t* this, gcpointer_t* rhs)
-// {
-// 	return this->ptr != rhs->ptr;
-// }
-//
-// int gcpointer_null(gcpointer_t* this)
-// {
-// 	return this->ptr == (intptr_t)NULL;
-// }
+void register_ptr(gcpointer_t* this)
+{
+	if(gcpointer_null(this)) return;
+
+	if(gc_is_managed(this))
+	{
+		gc_object_header* obj = gc_get_object_for_ref(gc_get_state(), (void*)this);
+		check(obj);
+		check(gc_obj_is_valide(obj));
+		check(gc_is_managed(this) == gc_is_managed(obj->type_chain) || obj->type_chain == NULL);
+		this->next = obj->type_chain;
+		obj->type_chain = this;
+		check(obj->is_valide());
+	}
+	else
+	{
+		gc_object_header* obj = gc_get_object_ptr((void*)this->ptr);
+		check(obj);
+		check(gc_obj_is_valide(obj));
+		check(gc_is_managed(this) == gc_is_managed(obj->root_chain) || obj->root_chain == NULL);
+		this->next = obj->root_chain;
+		obj->root_chain = this;
+		check(gc_obj_is_valide(obj));
+	}
+}
+
+void unregister_ptr(gcpointer_t* this)
+{
+	if(gcpointer_null(this)) return;
+
+	gcpointer_t** prev_next_ptr = gc_find_previous_ref(this);
+	check((*prev_next_ptr) == this);
+
+	(*prev_next_ptr) = this->next;
+}
+
+void gcpointer_ctor(gcpointer_t* this)
+{
+	this->ptr = (intptr_t)NULL;
+	this->next = NULL;
+}
+
+void gcpointer_ctor(gcpointer_t* this, void* address)
+{
+	this->ptr = (intptr_t)address;
+	this->next = NULL;
+
+	register_ptr(this);
+}
+
+void gcpointer_ctor(gcpointer_t* this, gcpointer_t* other)
+{
+	this->ptr = other->ptr;
+	this->next = NULL;
+
+	register_ptr(this);
+}
+
+void gcpointer_dtor(gcpointer_t* this)
+{
+	unregister_ptr(this);
+}
+
+gcpointer_t* gcpointer_assign(gcpointer_t* this, gcpointer_t* rhs)
+{
+	if(this != rhs)
+	{
+		unregister_ptr(this);
+
+		this->ptr = rhs->ptr;
+
+		register_ptr(this);
+	}
+
+	return this;
+}
+
+//Logical operators
+int gcpointer_equal(gcpointer_t* this, gcpointer_t* rhs)
+{
+	return this->ptr == rhs->ptr;
+}
+
+int gcpointer_not_equal(gcpointer_t* this, gcpointer_t* rhs)
+{
+	return this->ptr != rhs->ptr;
+}
+
+int gcpointer_null(gcpointer_t* this)
+{
+	return this->ptr == (intptr_t)NULL;
+}
Index: src/examples/gc_no_raii/src/gcpointers.h
===================================================================
--- src/examples/gc_no_raii/src/gcpointers.h	(revision 356bb95354e95f40bbe00b79e4432f16fc689ecf)
+++ src/examples/gc_no_raii/src/gcpointers.h	(revision 385c1309bdc9ace6d6de8377cf50fe8b65bccccb)
@@ -10,5 +10,5 @@
 
 void gcpointer_ctor(gcpointer_t* this);
-// void gcpointer_ctor(gcpointer_t* ptr, (int)0);
+void gcpointer_ctor(gcpointer_t* ptr, int null);
 void gcpointer_ctor(gcpointer_t* this, void* address);
 void gcpointer_ctor(gcpointer_t* this, gcpointer_t* other);
Index: src/examples/gc_no_raii/src/internal/collector.c
===================================================================
--- src/examples/gc_no_raii/src/internal/collector.c	(revision 356bb95354e95f40bbe00b79e4432f16fc689ecf)
+++ src/examples/gc_no_raii/src/internal/collector.c	(revision 385c1309bdc9ace6d6de8377cf50fe8b65bccccb)
@@ -8,137 +8,137 @@
 #include <fstream>
 
-// #include "state.h"
-// #include "gcpointers.h"
-// #include "memory_pool.h"
+#include "state.h"
+#include "gcpointers.h"
+#include "memory_pool.h"
 
-// void* gc_finish_alloc_block(void* block, size_t actual_size, size_t target_size);
-// void gc_assign_reference(void** ref, gc_object_header* ptr);
+void* gc_finish_alloc_block(void* block, size_t actual_size, size_t target_size);
+void gc_assign_reference(void** ref, gc_object_header* ptr);
 
-// gcpointer_t** gc_find_previous_ref(gcpointer_t* target)
-// {
-// 	if(!(target)) return NULL;
-//
-// 	bool managed = gc_is_managed(target);
-// 	gc_object_header* obj = gc_get_object_ptr((void*)target->ptr);
-//
-// 	check(gc_is_valide(obj));
-//
-// 	gcpointer_t** prev_next_ptr = managed ? &obj->type_chain : &obj->root_chain;
-// 	while((*prev_next_ptr) && (*prev_next_ptr) != target)
-// 	{
-// 		prev_next_ptr = &(*prev_next_ptr)->next;
-// 	}
-//
-// 	return prev_next_ptr;
-// }
+gcpointer_t** gc_find_previous_ref(gcpointer_t* target)
+{
+	if(!(target)) return NULL;
 
-// void* gc_allocate(size_t target_size)
-// {
-// 	size_t size = gc_compute_size(target_size + sizeof(gc_object_header));
-//
-// 	check(size < POOL_SIZE_BYTES);
-//
-// 	void* block = NULL;
-// 	gc_state* gc = gc_get_state();
-//
-// 	if((intptr_t)(block = gc_try_allocate(gc, size))) return gc_finish_alloc_block(block, size, target_size);
-//
-// 	gc_collect(gc);
-//
-// 	if((intptr_t)(block = gc_try_allocate(gc, size))) return gc_finish_alloc_block(block, size, target_size);
-//
-// 	gc_allocate_pool(gc);
-//
-// 	if((intptr_t)(block = gc_try_allocate(gc, size))) return gc_finish_alloc_block(block, size, target_size);
-//
-// 	ofstream_stderr() | "ERROR: allocation in new pool failed" | endl;
-// 	abort();
-//
-// 	return NULL;
-// }
-//
-// void* gc_finish_alloc_block(void* block, size_t actual_size, size_t target_size)
-// {
-// 	void* data = (void*)(((intptr_t)block) + sizeof(gc_object_header));
-// 	void* header = block;
-//
-// 	check(((intptr_t)data) > ((intptr_t)block));
-// 	check(((intptr_t)data) >= ((intptr_t)header));
-// 	check(is_aligned(data));
-// 	check(((intptr_t)data) + target_size <= ((intptr_t)block) + actual_size);
-//
-// 	gc_object_header* obj = gc_object_header_placement_ctor(header, actual_size);
-//
-// 	// (void)obj; //remove unsused warning since this is for debug
-// 	check(obj == get_object_ptr(data));
-//
-// 	gc_register_allocation(gc_get_state(), actual_size);
-//
-// 	return data;
-// }
-//
-// void gc_process_reference(void** ref, worklist_t* worklist)
-// {
-// 	check(!gc_is_in_heap(gc_get_state(), ref));
-//
-// 	gc_object_header* ptr = gc_get_object_ptr(*ref);
-// 	if(ptr)
-// 	{
-// 		if(!ptr->is_forwarded)
-// 		{
-// 			gc_copy_object(ptr);
-//
-// 			gc_scan_object(ptr->forward, worklist);
-//
-// 			gc_assign_reference(ref, ptr->forward);
-// 		}
-// 		else
-// 		{
-// 			//duplication to help debug
-// 			gc_assign_reference(ref, ptr->forward);
-// 		}
-// 	}
-// }
-//
-// void gc_assign_reference(void** ref, gc_object_header* ptr)
-// {
-// 	void* address = (void*)(((intptr_t)ptr) + sizeof(gc_object_header));
-//
-// 	gc_write_aligned_ptr(ref, address);
-// }
-//
-// gc_object_header* gc_copy_object(gc_object_header* ptr)
-// {
-// 	check(!ptr->forward);
-// 	check(!ptr->is_forwarded);
-// 	check(gc_is_from_space(gc_pool_of(ptr)));
-//
-// 	gc_memory_pool* pool = gc_pool_of(ptr)->mirror;
-//
-// 	void* new_block = gc_pool_allocate(pool, ptr->size, true);
-//
-// 	memcpy(new_block, ptr, ptr->size);
-//
-// 	gc_object_header* fwd_ptr = gc_object_header_placement_copy_ctor(new_block, ptr);
-//
-// 	ptr->forward = fwd_ptr;
-// 	ptr->is_forwarded = true;
-//
-// 	return fwd_ptr;
-// }
-//
-// void gc_scan_object(gc_object_header* object, worklist_t* worklist)
-// {
-// 	gcpointer_t* field = object->type_chain;
-// 	while(field)
-// 	{
-// 		check(((intptr_t)field) > ((intptr_t)object));
-// 		check(((intptr_t)field) < ((intptr_t)((intptr_t)object) + object->size));
-//
-// 		check(gc_is_in_to_space(gc_get_state(), &type->ptr));
-//
-// 		push_back(worklist, &field->ptr);
-//
-// 		field = field->next;
-// 	}
-// }
+	bool managed = gc_is_managed(target);
+	gc_object_header* obj = gc_get_object_ptr((void*)target->ptr);
+
+	check(gc_is_valide(obj));
+
+	gcpointer_t** prev_next_ptr = managed ? &obj->type_chain : &obj->root_chain;
+	while((*prev_next_ptr) && (*prev_next_ptr) != target)
+	{
+		prev_next_ptr = &(*prev_next_ptr)->next;
+	}
+
+	return prev_next_ptr;
+}
+
+void* gc_allocate(size_t target_size)
+{
+	size_t size = gc_compute_size(target_size + sizeof(gc_object_header));
+
+	check(size < POOL_SIZE_BYTES);
+
+	void* block = NULL;
+	gc_state* gc = gc_get_state();
+
+	if((intptr_t)(block = gc_try_allocate(gc, size))) return gc_finish_alloc_block(block, size, target_size);
+
+	gc_collect(gc);
+
+	if((intptr_t)(block = gc_try_allocate(gc, size))) return gc_finish_alloc_block(block, size, target_size);
+
+	gc_allocate_pool(gc);
+
+	if((intptr_t)(block = gc_try_allocate(gc, size))) return gc_finish_alloc_block(block, size, target_size);
+
+	checkf(false, "ERROR: allocation in new pool failed");
+
+	return NULL;
+}
+
+void* gc_finish_alloc_block(void* block, size_t actual_size, size_t target_size)
+{
+	void* data = (void*)(((intptr_t)block) + sizeof(gc_object_header));
+	void* header = block;
+
+	check(((intptr_t)data) > ((intptr_t)block));
+	check(((intptr_t)data) >= ((intptr_t)header));
+	check(is_aligned(data));
+	check(((intptr_t)data) + target_size <= ((intptr_t)block) + actual_size);
+
+	gc_object_header* obj = gc_object_header_placement_ctor(header, actual_size);
+
+	(void)obj; //remove unsused warning since this is for debug
+	check(obj == get_object_ptr(data));
+
+	gc_register_allocation(gc_get_state(), actual_size);
+
+	return data;
+}
+
+void gc_process_reference(void** ref, worklist_t* worklist)
+{
+	check(!gc_is_in_heap(gc_get_state(), ref));
+
+	gc_object_header* ptr = gc_get_object_ptr(*ref);
+	if(ptr)
+	{
+		if(!ptr->is_forwarded)
+		{
+			gc_copy_object(ptr);
+
+			gc_scan_object(ptr->forward, worklist);
+
+			gc_assign_reference(ref, ptr->forward);
+		}
+		else
+		{
+			//duplication to help debug
+			gc_assign_reference(ref, ptr->forward);
+		}
+	}
+}
+
+void gc_assign_reference(void** ref, gc_object_header* ptr)
+{
+	void* address = (void*)(((intptr_t)ptr) + sizeof(gc_object_header));
+
+	gc_write_aligned_ptr(ref, address);
+}
+
+gc_object_header* gc_copy_object(gc_object_header* ptr)
+{
+	check(!ptr->forward);
+	check(!ptr->is_forwarded);
+	check(gc_is_from_space(gc_pool_of(ptr)));
+
+	gc_memory_pool* pool = gc_pool_of(ptr)->mirror;
+
+	void* new_block = gc_pool_allocate(pool, ptr->size, true);
+
+	memcpy(new_block, ptr, ptr->size);
+
+	gc_object_header* fwd_ptr = gc_object_header_placement_copy_ctor(new_block, ptr);
+
+	ptr->forward = fwd_ptr;
+	ptr->is_forwarded = true;
+
+	return fwd_ptr;
+}
+
+void gc_scan_object(gc_object_header* object, worklist_t* worklist)
+{
+	gcpointer_t* field = object->type_chain;
+	while(field)
+	{
+		check(((intptr_t)field) > ((intptr_t)object));
+		check(((intptr_t)field) < ((intptr_t)((intptr_t)object) + object->size));
+
+		check(gc_is_in_to_space(gc_get_state(), &type->ptr));
+
+		intptr_t* ref = &field->ptr;
+		// push_back(worklist, ref);
+
+		field = field->next;
+	}
+}
Index: src/examples/gc_no_raii/src/internal/collector.h
===================================================================
--- src/examples/gc_no_raii/src/internal/collector.h	(revision 356bb95354e95f40bbe00b79e4432f16fc689ecf)
+++ src/examples/gc_no_raii/src/internal/collector.h	(revision 385c1309bdc9ace6d6de8377cf50fe8b65bccccb)
@@ -4,12 +4,12 @@
 #include <stdint.h>
 
-// #include "tools.h"
+#include "tools.h"
 //
-// #include "gcpointers.h"
+#include "gcpointers.h"
 #include "state.h"
 #include "internal/gc_tools.h"
-// #include "internal/globals.h"
-// #include "internal/object_header.h"
-// #include "internal/state.h"
+#include "internal/globals.h"
+#include "internal/object_header.h"
+#include "internal/state.h"
 #include "tools/worklist.h"
 
@@ -19,30 +19,30 @@
 }
 
-// inline gc_object_header* gc_get_object_ptr(void* ptr)
-// {
-// 	void* clean = gc_get_aligned_ptr(ptr);
-// 	return ((gc_object_header*)clean) - 1;
-// }
+inline gc_object_header* gc_get_object_ptr(void* ptr)
+{
+	void* clean = gc_get_aligned_ptr(ptr);
+	return ((gc_object_header*)clean) - 1;
+}
 
-// inline gc_memory_pool* gc_pool_of(void* address)
-// {
-// 	return (struct gc_memory_pool*)(((intptr_t)address) & POOL_PTR_MASK);
-// }
-//
-// inline void gc_conditional_collect()
-// {
-// 	if(gc_needs_collect(gc_get_state()))
-// 	{
-// 		gc_collect(gc_get_state());
-// 	}
-// }
-//
-// gcpointer_t** gc_find_previous_ref(gcpointer_t* target);
-//
-// void* gc_allocate(size_t size);
-//
-// void gc_process_reference(void** ref, worklist_t* worklist);
-//
-// struct gc_object_header* gc_copy_object(struct gc_object_header* ptr);
-//
-// void gc_scan_object(struct gc_object_header* object, worklist_t* worklist);
+inline struct gc_memory_pool* gc_pool_of(void* address)
+{
+	return (struct gc_memory_pool*)(((intptr_t)address) & POOL_PTR_MASK);
+}
+
+inline void gc_conditional_collect()
+{
+	if(gc_needs_collect(gc_get_state()))
+	{
+		gc_collect(gc_get_state());
+	}
+}
+
+gcpointer_t** gc_find_previous_ref(gcpointer_t* target);
+
+void* gc_allocate(size_t size);
+
+void gc_process_reference(void** ref, worklist_t* worklist);
+
+struct gc_object_header* gc_copy_object(struct gc_object_header* ptr);
+
+void gc_scan_object(struct gc_object_header* object, worklist_t* worklist);
Index: src/examples/gc_no_raii/src/internal/gc_tools.h
===================================================================
--- src/examples/gc_no_raii/src/internal/gc_tools.h	(revision 356bb95354e95f40bbe00b79e4432f16fc689ecf)
+++ src/examples/gc_no_raii/src/internal/gc_tools.h	(revision 385c1309bdc9ace6d6de8377cf50fe8b65bccccb)
@@ -12,29 +12,29 @@
 }
 
-// inline void* gc_get_aligned_ptr(void* address)
-// {
-// 	return (void*)(((intptr_t)address) & (OBJECT_PTR_MASK));
-// }
-//
-// inline void* gc_write_aligned_ptr(void** reference, void* address)
-// {
-// 	size_t ref_last_bits = ((intptr_t)*reference) & (~OBJECT_PTR_MASK);
-//
-//       size_t new_val = ((intptr_t)address) & OBJECT_PTR_MASK;
-//
-//       (*reference) = (void*)(new_val | ref_last_bits);
-//
-// 	return *reference;
-// }
-//
-// inline size_t gc_compute_size(size_t size)
-// {
-// 	size_t word_size = ((size - 1) / OBJECT_ALLIGNMENT) + 1;
-// 	size_t ret = word_size * OBJECT_ALLIGNMENT;
-//
-// 	check(ret >= size);
-// 	check((ret % OBJECT_ALLIGNMENT) == 0);
-// 	check( ((size % OBJECT_ALLIGNMENT) != 0) || (ret == size) );
-//
-// 	return ret;
-// }
+inline void* gc_get_aligned_ptr(void* address)
+{
+	return (void*)(((intptr_t)address) & (OBJECT_PTR_MASK));
+}
+
+inline void* gc_write_aligned_ptr(void** reference, void* address)
+{
+	size_t ref_last_bits = ((intptr_t)*reference) & (~OBJECT_PTR_MASK);
+
+      size_t new_val = ((intptr_t)address) & OBJECT_PTR_MASK;
+
+      (*reference) = (void*)(new_val | ref_last_bits);
+
+	return *reference;
+}
+
+inline size_t gc_compute_size(size_t size)
+{
+	size_t word_size = ((size - 1) / OBJECT_ALLIGNMENT) + 1;
+	size_t ret = word_size * OBJECT_ALLIGNMENT;
+
+	check(ret >= size);
+	check((ret % OBJECT_ALLIGNMENT) == 0);
+	check( ((size % OBJECT_ALLIGNMENT) != 0) || (ret == size) );
+
+	return ret;
+}
Index: src/examples/gc_no_raii/src/internal/memory_pool.h
===================================================================
--- src/examples/gc_no_raii/src/internal/memory_pool.h	(revision 356bb95354e95f40bbe00b79e4432f16fc689ecf)
+++ src/examples/gc_no_raii/src/internal/memory_pool.h	(revision 385c1309bdc9ace6d6de8377cf50fe8b65bccccb)
@@ -24,4 +24,11 @@
 	uint8_t start_p[1];
 };
+
+void gc_memory_pool_ctor(gc_memory_pool *const this,
+	size_t size,
+	gc_memory_pool* next,
+	gc_memory_pool* mirror,
+     uint8_t type
+	);
 
 struct gc_pool_object_iterator
@@ -58,4 +65,9 @@
 void gc_reset_pool(gc_memory_pool* pool);
 
+inline size_t gc_pool_size_used(const gc_memory_pool* pool)
+{
+	return pool->free_p - pool->start_p;
+}
+
 inline size_t gc_pool_size_total(const gc_memory_pool* pool)
 {
Index: src/examples/gc_no_raii/src/internal/state.c
===================================================================
--- src/examples/gc_no_raii/src/internal/state.c	(revision 356bb95354e95f40bbe00b79e4432f16fc689ecf)
+++ src/examples/gc_no_raii/src/internal/state.c	(revision 385c1309bdc9ace6d6de8377cf50fe8b65bccccb)
@@ -1,41 +1,48 @@
 #include "state.h"
 
-// #include <stdlib.h>
-//
-// //general purpouse includes
-// #include "tools.h"
-//
-// //platform abstraction includes
-// #include "allocate-pool.h"
-//
-// //gc internal includes
-// // #include "globals.h"
-// #include "memory_pool.h"
+#include <stdlib.h>
+
+//general purpouse includes
+#include "tools.h"
+
+//platform abstraction includes
+#include "allocate-pool.h"
+
+//gc internal includes
+#include "globals.h"
+#include "memory_pool.h"
 // #include "memory_pool_iterator.h"
-// #include "object_header.h"
-//
-// void swap(gc_state* state);
-// void sweep_roots(worklist_t worklist);
-// void clear(gc_state* state);
-// void calc_usage(gc_state* state);
-//
-// #if DEBUG
-// 	bool roots_match(gc_state* state);
-// 	bool no_from_space_ref(gc_state* state);
-// #endif
-
-// void gc_state_ctor(gc_state* state)
-// {
-// 	state->from_code = 0;
-// 	state->to_space = NULL;
-// 	state->from_space = NULL;
-// 	state->total_space = 0;
-// 	state->used_space = 0;
-// 	// state->pools_table();
-//
-// 	gc_allocate_pool(state);
-//
-// 	state->is_initialized = true;
-// }
+#include "object_header.h"
+
+void gc_state_swap(gc_state *const this);
+void gc_state_sweep_roots(gc_state *const this, worklist_t* worklist);
+void gc_state_clear(gc_state *const this);
+void gc_state_calc_usage(gc_state *const this);
+
+#if DEBUG
+	bool gc_state_roots_match(gc_state *const this);
+	bool gc_state_no_from_space_ref(gc_state *const this);
+#endif
+
+gc_state* gc_get_state()
+{
+	static gc_state s;
+	if(!s.is_initialized) gc_state_ctor(&s);
+	return &s;
+}
+
+void gc_state_ctor(gc_state *const this)
+{
+	this->from_code = 0;
+	this->to_space = NULL;
+	this->from_space = NULL;
+	this->total_space = 0;
+	this->used_space = 0;
+	// state->pools_table();
+
+	gc_allocate_pool(this);
+
+	this->is_initialized = true;
+}
 
 // bool state::is_in_heap(void* address) const
@@ -86,63 +93,65 @@
 // 	return NULL;
 // }
-//
-// void* state::try_allocate(size_t size)
-// {
-// 	memory_pool* pool = from_space;
-// 	while(pool)
-// 	{
-// 		if(pool->size_left() > size)
-// 		{
-// 			return pool->allocate(size, true);
-// 		}
-// 		pool = pool->next();
-// 	}
-//
-// 	return nullptr;
-// }
-//
-// void state::allocate_pool()
-// {
-// 	memory_pool* old_from_space = from_space;
-//       memory_pool* old_to_space = to_space;
-//
-//       from_space = reinterpret_cast<memory_pool*>(pal_allocPool(POOL_SIZE_BYTES, 1));
-//       to_space = reinterpret_cast<memory_pool*>(pal_allocPool(POOL_SIZE_BYTES, 1));
-//
-//       new (from_space) memory_pool(POOL_SIZE_BYTES, old_from_space, to_space, from_code);
-//       new (to_space) memory_pool(POOL_SIZE_BYTES, old_to_space, from_space, (~from_code) & 0x01);
-//
-// 	total_space += from_space->size();
-//
-// 	pools_table.push_back(from_space);
-// 	pools_table.push_back(to_space);
-// }
-//
-// void state::collect()
-// {
-// 	DEBUG("collecting");
-// 	DEBUG("previous usage " << used_space << " / " << total_space);
-//
-// 	std::vector<void**> worklist;
-// 	sweep_roots(worklist);
-//
-// 	while(!worklist.empty())
-// 	{
-// 		void** ref = worklist.back();
-// 		worklist.pop_back();
-// 		process_reference(ref, worklist);
-// 	}
-//
-// 	check(roots_match());
-// 	check(no_from_space_ref());
-//
-// 	swap();
-//
-// 	calc_usage();
-//
-// 	if(needs_collect()) allocate_pool();
-//
-// 	DEBUG("done");
-// }
+
+void* gc_state_try_allocate(gc_state *const this, size_t size)
+{
+	gc_memory_pool* pool = this->from_space;
+	while(pool != (gc_memory_pool*)0)
+	{
+		if(gc_pool_size_left(pool) > size)
+		{
+			return gc_pool_allocate(pool, size, true);
+		}
+		pool = pool->next;
+	}
+
+	return (void*)0;
+}
+
+void gc_state_allocate_pool(gc_state *const this)
+{
+	gc_memory_pool* old_from_space = this->from_space;
+      gc_memory_pool* old_to_space = this->to_space;
+
+      this->from_space = (gc_memory_pool*)(pal_allocPool(POOL_SIZE_BYTES, 1));
+      this->to_space = (gc_memory_pool*)(pal_allocPool(POOL_SIZE_BYTES, 1));
+
+      gc_memory_pool_ctor(this->from_space, POOL_SIZE_BYTES, old_from_space, this->to_space,   this->from_code);
+      gc_memory_pool_ctor(this->to_space,   POOL_SIZE_BYTES, old_to_space,   this->from_space, (~this->from_code) & 0x01);
+
+	this->total_space += gc_pool_size_used(this->from_space);
+
+	// pools_table.push_back(from_space);
+	// pools_table.push_back(to_space);
+}
+
+void gc_state_collect(gc_state *const this)
+{
+	// DEBUG("collecting");
+	// DEBUG("previous usage " << this->used_space << " / " << this->total_space);
+
+	worklist_t worklist;
+	// vector_ctor(&worklist);
+	gc_state_sweep_roots(this, &worklist);
+
+	while(!empty(&worklist))
+	{
+		void** ref = back(&worklist);
+		pop_back(&worklist);
+		gc_state_process_reference(this, ref, &worklist);
+	}
+	//
+	// check(gc_state_roots_match(this));
+	// check(gc_state_no_from_space_ref(this));
+	//
+	// gc_state_swap(this);
+	//
+	// gc_state_calc_usage(this);
+	//
+	// if(gc_state_needs_collect(this)) gc_state_allocate_pool(this);
+
+	// DEBUG("done");
+	// dtor(&worklist);
+}
 //
 // void state::swap()
Index: src/examples/gc_no_raii/src/internal/state.h
===================================================================
--- src/examples/gc_no_raii/src/internal/state.h	(revision 356bb95354e95f40bbe00b79e4432f16fc689ecf)
+++ src/examples/gc_no_raii/src/internal/state.h	(revision 385c1309bdc9ace6d6de8377cf50fe8b65bccccb)
@@ -22,10 +22,5 @@
 void gc_state_ctor(struct gc_state* state);
 
-static inline gc_state* gc_get_state()
-{
-	static gc_state s;
-	if(!s.is_initialized) gc_state_ctor(&s);
-	return &s;
-}
+gc_state* gc_get_state();
 
 inline bool gc_needs_collect(gc_state* state)
Index: src/examples/gc_no_raii/src/tools/worklist.h
===================================================================
--- src/examples/gc_no_raii/src/tools/worklist.h	(revision 356bb95354e95f40bbe00b79e4432f16fc689ecf)
+++ src/examples/gc_no_raii/src/tools/worklist.h	(revision 385c1309bdc9ace6d6de8377cf50fe8b65bccccb)
@@ -5,15 +5,4 @@
 
 #include "vector.h"
-/*
-typedef intptr_t* worklist_element_t;
-
-struct worklist_t
-{
-	size_t count;
-	worklist_element_t* data;
-};
-
-void push_back(worklist_t* worklist, worklist_element_t element);
-*/
 
 typedef vector(intptr_t*, heap_allocator(intptr_t*)) worklist_t;
Index: src/examples/gc_no_raii/src/vector.c
===================================================================
--- src/examples/gc_no_raii/src/vector.c	(revision 385c1309bdc9ace6d6de8377cf50fe8b65bccccb)
+++ src/examples/gc_no_raii/src/vector.c	(revision 385c1309bdc9ace6d6de8377cf50fe8b65bccccb)
@@ -0,0 +1,69 @@
+#include "vector.h"
+
+//------------------------------------------------------------------------------
+//Initialization
+forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
+void vector_ctor(vector(T, allocator_t) *const this)
+{
+	ctor(&this->storage);
+	this->size = 0;
+}
+
+forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
+void dtor(vector(T, allocator_t) *const this)
+{
+	dtor(&this->storage);
+}
+
+//------------------------------------------------------------------------------
+//Modifiers
+forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
+void push_back(vector(T, allocator_t) *const this, T value)
+{
+	realloc(&this->storage, this->size+1);
+	data(&this->storage)[this->size] = value;
+	this->size++;
+}
+
+forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
+void pop_back(vector(T, allocator_t) *const this)
+{
+	this->size--;
+	DESTROY(data(&this->storage)[this->size]);
+}
+
+forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
+void clear(vector(T, allocator_t) *const this)
+{
+	for(size_t i = 0; i < this->size; i++)
+	{
+		DESTROY(data(&this->storage)[this->size]);
+	}
+	this->size = 0;
+}
+
+//------------------------------------------------------------------------------
+//Allocator
+forall(otype T)
+void ctor(heap_allocator(T) *const this)
+{
+	this->storage = 0;
+	this->capacity = 0;
+}
+
+forall(otype T)
+void dtor(heap_allocator(T) *const this)
+{
+	free((void*)this->storage);
+}
+
+forall(otype T)
+inline void realloc(heap_allocator(T) *const this, size_t size)
+{
+	static const size_t GROWTH_RATE = 2;
+	if(size > this->capacity)
+	{
+		this->capacity = GROWTH_RATE * size;
+		this->storage = (T*)realloc((void*)this->storage, this->capacity * sizeof(T));
+	}
+}
Index: src/examples/gc_no_raii/src/vector.h
===================================================================
--- src/examples/gc_no_raii/src/vector.h	(revision 356bb95354e95f40bbe00b79e4432f16fc689ecf)
+++ src/examples/gc_no_raii/src/vector.h	(revision 385c1309bdc9ace6d6de8377cf50fe8b65bccccb)
@@ -8,10 +8,12 @@
 //------------------------------------------------------------------------------
 //Declaration
-context allocator_c(type T, type allocator_t) {
+trait allocator_c(otype T, otype allocator_t) {
+	void ctor(allocator_t*);
+	void dtor(allocator_t*);
 	void realloc(allocator_t*, size_t);
 	T* data(allocator_t*);
 };
 
-forall(type T, type allocator_t | allocator_c(T, allocator_t))
+forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
 struct vector
 {
@@ -21,19 +23,27 @@
 
 //------------------------------------------------------------------------------
+//Initialization
+forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
+void vector_ctor(vector(T, allocator_t) *const this);
+
+forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
+void dtor(vector(T, allocator_t) *const this);
+
+//------------------------------------------------------------------------------
 //Capacity
-forall(type T, type allocator_t | allocator_c(T, allocator_t))
-bool empty(vector(T, allocator_t)* this)
+forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
+inline bool empty(vector(T, allocator_t) *const this)
 {
 	return this->size == 0;
 }
 
-forall(type T, type allocator_t | allocator_c(T, allocator_t))
-bool size(vector(T, allocator_t)* this)
+forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
+inline bool size(vector(T, allocator_t) *const this)
 {
 	return this->size;
 }
 
-forall(type T, type allocator_t | allocator_c(T, allocator_t))
-void reserve(vector(T, allocator_t)* this, size_t size)
+forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
+inline void reserve(vector(T, allocator_t) *const this, size_t size)
 {
 	realloc(&this->storage, this->size+1);
@@ -42,25 +52,25 @@
 //------------------------------------------------------------------------------
 //Element access
-forall(type T, type allocator_t | allocator_c(T, allocator_t))
-T at(vector(T, allocator_t)* this, size_t index)
+forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
+inline T at(vector(T, allocator_t) *const this, size_t index)
 {
-	//assert(index < this->size);
+	// assert(index < this->size);
 	return data(&this->storage)[index];
 }
 
-forall(type T, type allocator_t | allocator_c(T, allocator_t))
-T ?[?](vector(T, allocator_t)* this, size_t index)
+forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
+inline T ?[?](vector(T, allocator_t) *const this, size_t index)
 {
 	return data(&this->storage)[index];
 }
 
-forall(type T, type allocator_t | allocator_c(T, allocator_t))
-T front(vector(T, allocator_t)* this)
+forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
+inline T front(vector(T, allocator_t) *const this)
 {
 	return data(&this->storage)[0];
 }
 
-forall(type T, type allocator_t | allocator_c(T, allocator_t))
-T back(vector(T, allocator_t)* this, size_t index)
+forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
+inline T back(vector(T, allocator_t) *const this, size_t index)
 {
 	return data(&this->storage)[this->size - 1];
@@ -69,32 +79,16 @@
 //------------------------------------------------------------------------------
 //Modifiers
-forall(type T, type allocator_t | allocator_c(T, allocator_t))
-void push_back(vector(T, allocator_t)* this, T value)
-{
-	realloc(&this->storage, this->size+1);
-	data(&this->storage)[this->size] = value;
-	this->size++;
-}
+forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
+void push_back(vector(T, allocator_t) *const this, T value);
 
-forall(type T, type allocator_t | allocator_c(T, allocator_t))
-void pop_back(vector(T, allocator_t)* this)
-{
-	this->size--;
-	DESTROY(data(&this->storage)[this->size]);
-}
+forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
+void pop_back(vector(T, allocator_t) *const this);
 
-forall(type T, type allocator_t | allocator_c(T, allocator_t))
-void clear(vector(T, allocator_t)* this)
-{
-	for(size_t i = 0; i < this->size; i++)
-	{
-		DESTROY(data(&this->storage)[this->size]);
-	}
-	this->size = 0;
-}
+forall(otype T, otype allocator_t | allocator_c(T, allocator_t))
+void clear(vector(T, allocator_t) *const this);
 
 //------------------------------------------------------------------------------
 //Allocator
-forall(type T)
+forall(otype T)
 struct heap_allocator
 {
@@ -103,17 +97,15 @@
 };
 
-forall(type T)
-void realloc(heap_allocator(T)* this, size_t size)
-{
-	static const size_t GROWTH_RATE = 2;
-	if(size > this->capacity)
-	{
-		this->capacity = GROWTH_RATE * size;
-		this->storage = (T*)realloc((void*)this->storage, this->capacity * sizeof(T));
-	}
-}
+forall(otype T)
+void ctor(heap_allocator(T) *const this);
 
-forall(type T)
-T* data(heap_allocator(T)* this)
+forall(otype T)
+void dtor(heap_allocator(T) *const this);
+
+forall(otype T)
+void realloc(heap_allocator(T) *const this, size_t size);
+
+forall(otype T)
+inline T* data(heap_allocator(T) *const this)
 {
 	return this->storage;
