Index: src/examples/gc_no_raii/gc.h
===================================================================
--- src/examples/gc_no_raii/gc.h	(revision e47f529d33f49f6a3d06c4a4bcde0fb84b62eab3)
+++ 	(revision )
@@ -1,9 +1,0 @@
-#pragma once
-
-#include "gcpointers.h"
-
-forall( dtype T )
-gcpointer_t gcmalloc()
-{
-
-}
Index: src/examples/gc_no_raii/gcpointers.c
===================================================================
--- src/examples/gc_no_raii/gcpointers.c	(revision e47f529d33f49f6a3d06c4a4bcde0fb84b62eab3)
+++ 	(revision )
@@ -1,101 +1,0 @@
-#include "gcpointers.h"
-
-#include "gc.h"
-#include "internal/collector.h"
-#include "internal/object_header.h"
-#include "internal/state.h"
-
-void register_ptr(gcpointer_t* this)
-{
-	if(gcpointer_null(this)) return;
-
-	_Bool managed = gc_is_managed(this);
-
-	if(managed)
-	{
-		gc_object_header* obj = gc_get_object_for_ref(this);
-		check(obj);
-		check(gc_obj_is_valide(obj));
-		check(gc_is_managed(this) == gc_is_managed(obj->type_chain) || obj->type_chain == NULL);
-		m_next = obj->type_chain;
-		obj->type_chain = this;
-		check(obj->is_valide());
-	}
-	else
-	{
-		gc_object_header* obj = gc_get_object_ptr(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);
-		m_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 = NULL;
-	this->next = NULL;
-}
-
-void gcpointer_ctor(gcpointer_t* this, void* address)
-{
-	this->ptr = 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 && this->ptr != rhs->ptr)
-	{
-		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 == NULL;
-}
Index: src/examples/gc_no_raii/gcpointers.h
===================================================================
--- src/examples/gc_no_raii/gcpointers.h	(revision e47f529d33f49f6a3d06c4a4bcde0fb84b62eab3)
+++ 	(revision )
@@ -1,21 +1,0 @@
-#pragma once
-
-struct gcpointer_t
-{
-	void* ptr;
-	struct gcpointer_t* next;
-};
-
-void gcpointer_ctor(gcpointer_t* this);
-// void gcpointer_ctor(gcpointer_t* ptr, (int)0);
-void gcpointer_ctor(gcpointer_t* this, void* address);
-void gcpointer_ctor(gcpointer_t* this, gcpointer_t* other);
-
-void gcpointer_dtor(gcpointer_t* this);
-
-gcpointer_t* gcpointer_assign(gcpointer_t* this, gcpointer_t* rhs);
-
-//Logical operators
-int gcpointer_equal(gcpointer_t* this, gcpointer_t* rhs);
-int gcpointer_not_equal(gcpointer_t* this, gcpointer_t* rhs);
-int gcpointer_null(gcpointer_t* this);
Index: src/examples/gc_no_raii/gctest.c
===================================================================
--- src/examples/gc_no_raii/gctest.c	(revision e47f529d33f49f6a3d06c4a4bcde0fb84b62eab3)
+++ 	(revision )
@@ -1,9 +1,0 @@
-
-#include "gc.h"
-#include "fstream.h"
-
-int main() {
-	ofstream *sout = ofstream_stdout();
-	ifstream *sin = ifstream_stdin();
-	sout | "Bonjour au monde!\n";
-}
Index: src/examples/gc_no_raii/internal/collector.h
===================================================================
--- src/examples/gc_no_raii/internal/collector.h	(revision e47f529d33f49f6a3d06c4a4bcde0fb84b62eab3)
+++ 	(revision )
@@ -1,49 +1,0 @@
-#pragma once
-
-#include <stddef.h>
-#include <stdint.h>
-
-#include "tools.h"
-
-#include "gcpointers.h"
-#include "internal/collector.h"
-#include "internal/gc_tools.h"
-#include "internal/globals.h"
-#include "internal/object_header.h"
-#include "internal/state.h"
-
-typedef int worklist_t;
-
-inline bool gc_is_managed(void* address)
-{
-	return gc_is_in_heap(gc_get_state(), address);
-}
-
-inline gc_object_header* gc_get_object_ptr(void* ptr)
-{
-	void* clean = gc_get_aligned_ptr(ptr);
-	return ((gc_object_header*)clean) - 1;
-}
-
-inline struct gc_memory_pool* 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/internal/gc_tools.h
===================================================================
--- src/examples/gc_no_raii/internal/gc_tools.h	(revision e47f529d33f49f6a3d06c4a4bcde0fb84b62eab3)
+++ 	(revision )
@@ -1,40 +1,0 @@
-#pragma once
-
-#include <stddef.h>
-#include <stdint.h>
-
-#include "tools.h"
-#include "globals.h"
-
-inline bool gc_is_aligned(void* address)
-{
-	return (((intptr_t)address) & (~OBJECT_PTR_MASK)) == 0;
-}
-
-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/internal/globals.h
===================================================================
--- src/examples/gc_no_raii/internal/globals.h	(revision e47f529d33f49f6a3d06c4a4bcde0fb84b62eab3)
+++ 	(revision )
@@ -1,16 +1,0 @@
-#pragma once
-
-#include <stddef.h>
-#include <stdint.h>
-
-static const size_t POOL_SIZE_EXP = 24;
-static const size_t POOL_SIZE_BYTES = 0x1 << POOL_SIZE_EXP;
-static const size_t POOL_PTR_MASK = ~(POOL_SIZE_BYTES - 1);
-
-static const size_t CARDS_SIZE_EXP = 12;
-static const size_t CARDS_SIZE_BYTES = 0x1 << CARDS_SIZE_EXP;
-static const size_t CARDS_OFFSET_MASK = (~(CARDS_SIZE_BYTES - 1)) & (POOL_SIZE_BYTES - 1);
-static const size_t CARDS_COUNT = POOL_SIZE_BYTES / CARDS_SIZE_BYTES;
-
-static const size_t OBJECT_ALLIGNMENT = sizeof(size_t);
-static const size_t OBJECT_PTR_MASK = ~(OBJECT_ALLIGNMENT - 1);
Index: src/examples/gc_no_raii/internal/object_header.h
===================================================================
--- src/examples/gc_no_raii/internal/object_header.h	(revision e47f529d33f49f6a3d06c4a4bcde0fb84b62eab3)
+++ 	(revision )
@@ -1,27 +1,0 @@
-#pragma once
-
-#include <stddef.h>
-#include <stdint.h>
-
-#include "tools.h"
-
-static const void* CANARY_VALUE = (void*)0xCAFEBABACAFEBABA;
-
-struct gcpointer_t;
-
-struct gc_object_header
-{
-	#if _DEBUG
-		void* canary_start;
-	#endif
-
-	size_t				size;
-	gcpointer_t* 			root_chain;
-	gcpointer_t*			type_chain;
-	struct gc_object_header*	forward;
-	bool					is_forwarded;
-
-	#if _DEBUG
-		void* canary_end;
-	#endif
-};
Index: src/examples/gc_no_raii/internal/state.c
===================================================================
--- src/examples/gc_no_raii/internal/state.c	(revision e47f529d33f49f6a3d06c4a4bcde0fb84b62eab3)
+++ 	(revision )
@@ -1,15 +1,0 @@
-#include "state.h"
-
-void swap();
-
-void sweep_roots(std::vector<void**>& worklist);
-
-void clear();
-
-void calc_usage();
-
-
-#if DEBUG
-	bool roots_match();
-	bool no_from_space_ref();
-#endif
Index: src/examples/gc_no_raii/internal/state.h
===================================================================
--- src/examples/gc_no_raii/internal/state.h	(revision e47f529d33f49f6a3d06c4a4bcde0fb84b62eab3)
+++ 	(revision )
@@ -1,56 +1,0 @@
-#pragma once
-
-#include <stddef.h>
-#include <stdint.h>
-
-#include "tools.h"
-
-struct gc_state
-{
-	bool is_initialized;
-	uint8_t from_code;
-	struct gc_memory_pool* to_space;
-	struct gc_memory_pool* from_space;
-
-	size_t total_space;
-	size_t used_space;
-
-	const struct memory_pool* 	pools_table;
-	size_t 				pools_table_count;
-};
-
-void gc_state_ctor(gc_state* state);
-
-inline gc_state* get_state()
-{
-	static gc_state s;
-	if(!s.is_initialized) gc_state_ctor(s);
-	return &s;
-}
-
-inline bool needs_collect(gc_state* state)
-{
-	return state->used_space * 2 > state->total_space;
-}
-
-void gc_collect(gc_state* state);
-
-void* gc_try_allocate(gc_state* state, size_t size);
-
-void gc_allocate_pool(gc_state* state);
-
-bool gc_is_in_heap(const gc_state* state, void* address);
-
-bool gc_is_in_to_space(const gc_state* state, void* address);
-
-inline uint8_t gc_from_space_code(const gc_state* state)
-{
-	return state->from_code;
-}
-
-struct gc_object_header* gc_get_object_for_ref(gc_state* state, void*);
-
-inline void gc_register_allocation(gc_state* state, size_t size)
-{
-	state->used_space += size;
-}
Index: src/examples/gc_no_raii/premake4.lua
===================================================================
--- src/examples/gc_no_raii/premake4.lua	(revision e47f529d33f49f6a3d06c4a4bcde0fb84b62eab3)
+++ src/examples/gc_no_raii/premake4.lua	(revision a2b2761456045c52741a58f2397c74bcfbf3c113)
@@ -4,5 +4,5 @@
 
 includeDirList = {
-	"./",
+	"src/",
 	"../",
 }
@@ -23,24 +23,50 @@
 
 solution "GC-no-RAII"
-    configurations { "Debug", "Release" }
+	configurations  { "debug", "release",
+				"cproc-debug", "cproc-release",
+				"cfa-debug", "cfa-release" }
 
-    project "gc-test"
-        kind "ConsoleApp"
-        language "C"
-        location "build"
-        objdir "build"
-        targetdir "."
-        buildoptions (buildOptions)
-        libdirs (libDirectories)
-        links (linkLibs)
-        linkoptions (linkOptionList)
-        includedirs (includeDirList)
-        files { "../fstream.c", "../iostream.c", "../iterator.c", "*.c" }
+	project "gc-test"
+		kind "ConsoleApp"
+		language "C"
+		location "build"
+		objdir "build"
+		targetdir "."
+		buildoptions (buildOptions)
+		libdirs (libDirectories)
+		links (linkLibs)
+		linkoptions (linkOptionList)
+		includedirs (includeDirList)
+		files { "../fstream.c", "../iostream.c", "../iterator.c", "src/*.c" }
 
-    configuration "Debug"
-        defines { "DEBUG", "bool=_Bool" }
-        flags { "Symbols" }
+	configuration "debug"
+		defines { "DEBUG", "bool=_Bool" }
+		flags { "Symbols" }
 
-    configuration "Release"
-        defines { "NDEBUG", "bool=_Bool" }
-        flags { "Optimize" }
+	configuration "release"
+		defines { "NDEBUG", "bool=_Bool" }
+		flags { "Optimize" }
+
+	configuration "cproc-debug"
+		buildoptions ({"-E"})
+		linkoptions ({"-E"})
+	      defines { "DEBUG", "bool=_Bool" }
+	      flags { "Symbols" }
+
+	configuration "cproc-release"
+		buildoptions ({"-E"})
+		linkoptions ({"-E"})
+	      defines { "DEBUG", "bool=_Bool" }
+	      flags { "Symbols" }
+
+	configuration "cfa-debug"
+		linkoptions ({"-E"})
+		files { "build/cproc-debug/*.o" }
+	      defines { "DEBUG", "bool=_Bool" }
+	      flags { "Symbols" }
+
+	configuration "cfa-release"
+		linkoptions ({"-E"})
+		files { "build/cproc-debug/*.o" }
+	      defines { "DEBUG", "bool=_Bool" }
+	      flags { "Symbols" }
Index: src/examples/gc_no_raii/src/gc.h
===================================================================
--- src/examples/gc_no_raii/src/gc.h	(revision a2b2761456045c52741a58f2397c74bcfbf3c113)
+++ src/examples/gc_no_raii/src/gc.h	(revision a2b2761456045c52741a58f2397c74bcfbf3c113)
@@ -0,0 +1,9 @@
+#pragma once
+
+#include "gcpointers.h"
+
+forall( dtype T )
+gcpointer_t gcmalloc()
+{
+
+}
Index: src/examples/gc_no_raii/src/gcpointers.c
===================================================================
--- src/examples/gc_no_raii/src/gcpointers.c	(revision a2b2761456045c52741a58f2397c74bcfbf3c113)
+++ src/examples/gc_no_raii/src/gcpointers.c	(revision a2b2761456045c52741a58f2397c74bcfbf3c113)
@@ -0,0 +1,101 @@
+#include "gcpointers.h"
+
+#include "gc.h"
+#include "internal/collector.h"
+#include "internal/object_header.h"
+#include "internal/state.h"
+
+void register_ptr(gcpointer_t* this)
+{
+	if(gcpointer_null(this)) return;
+
+	_Bool managed = gc_is_managed(this);
+
+	if(managed)
+	{
+		gc_object_header* obj = gc_get_object_for_ref(this);
+		check(obj);
+		check(gc_obj_is_valide(obj));
+		check(gc_is_managed(this) == gc_is_managed(obj->type_chain) || obj->type_chain == NULL);
+		m_next = obj->type_chain;
+		obj->type_chain = this;
+		check(obj->is_valide());
+	}
+	else
+	{
+		gc_object_header* obj = gc_get_object_ptr(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);
+		m_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 = NULL;
+	this->next = NULL;
+}
+
+void gcpointer_ctor(gcpointer_t* this, void* address)
+{
+	this->ptr = 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 && this->ptr != rhs->ptr)
+	{
+		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 == NULL;
+}
Index: src/examples/gc_no_raii/src/gcpointers.h
===================================================================
--- src/examples/gc_no_raii/src/gcpointers.h	(revision a2b2761456045c52741a58f2397c74bcfbf3c113)
+++ src/examples/gc_no_raii/src/gcpointers.h	(revision a2b2761456045c52741a58f2397c74bcfbf3c113)
@@ -0,0 +1,21 @@
+#pragma once
+
+struct gcpointer_t
+{
+	void* ptr;
+	struct gcpointer_t* next;
+};
+
+void gcpointer_ctor(gcpointer_t* this);
+// void gcpointer_ctor(gcpointer_t* ptr, (int)0);
+void gcpointer_ctor(gcpointer_t* this, void* address);
+void gcpointer_ctor(gcpointer_t* this, gcpointer_t* other);
+
+void gcpointer_dtor(gcpointer_t* this);
+
+gcpointer_t* gcpointer_assign(gcpointer_t* this, gcpointer_t* rhs);
+
+//Logical operators
+int gcpointer_equal(gcpointer_t* this, gcpointer_t* rhs);
+int gcpointer_not_equal(gcpointer_t* this, gcpointer_t* rhs);
+int gcpointer_null(gcpointer_t* this);
Index: src/examples/gc_no_raii/src/gctest.c
===================================================================
--- src/examples/gc_no_raii/src/gctest.c	(revision a2b2761456045c52741a58f2397c74bcfbf3c113)
+++ src/examples/gc_no_raii/src/gctest.c	(revision a2b2761456045c52741a58f2397c74bcfbf3c113)
@@ -0,0 +1,9 @@
+
+#include "gc.h"
+#include "fstream.h"
+
+int main() {
+	ofstream *sout = ofstream_stdout();
+	ifstream *sin = ifstream_stdin();
+	sout | "Bonjour au monde!\n";
+}
Index: src/examples/gc_no_raii/src/internal/collector.h
===================================================================
--- src/examples/gc_no_raii/src/internal/collector.h	(revision a2b2761456045c52741a58f2397c74bcfbf3c113)
+++ src/examples/gc_no_raii/src/internal/collector.h	(revision a2b2761456045c52741a58f2397c74bcfbf3c113)
@@ -0,0 +1,49 @@
+#pragma once
+
+#include <stddef.h>
+#include <stdint.h>
+
+#include "tools.h"
+
+#include "gcpointers.h"
+#include "internal/collector.h"
+#include "internal/gc_tools.h"
+#include "internal/globals.h"
+#include "internal/object_header.h"
+#include "internal/state.h"
+
+typedef int worklist_t;
+
+inline bool gc_is_managed(void* address)
+{
+	return gc_is_in_heap(gc_get_state(), address);
+}
+
+inline struct gc_object_header* gc_get_object_ptr(void* ptr)
+{
+	void* clean = gc_get_aligned_ptr(ptr);
+	return ((struct gc_object_header*)clean) - 1;
+}
+
+inline struct gc_memory_pool* 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 a2b2761456045c52741a58f2397c74bcfbf3c113)
+++ src/examples/gc_no_raii/src/internal/gc_tools.h	(revision a2b2761456045c52741a58f2397c74bcfbf3c113)
@@ -0,0 +1,40 @@
+#pragma once
+
+#include <stddef.h>
+#include <stdint.h>
+
+#include "tools.h"
+#include "globals.h"
+
+inline bool gc_is_aligned(void* address)
+{
+	return (((intptr_t)address) & (~OBJECT_PTR_MASK)) == 0;
+}
+
+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/globals.h
===================================================================
--- src/examples/gc_no_raii/src/internal/globals.h	(revision a2b2761456045c52741a58f2397c74bcfbf3c113)
+++ src/examples/gc_no_raii/src/internal/globals.h	(revision a2b2761456045c52741a58f2397c74bcfbf3c113)
@@ -0,0 +1,16 @@
+#pragma once
+
+#include <stddef.h>
+#include <stdint.h>
+
+static const size_t POOL_SIZE_EXP = 24;
+static const size_t POOL_SIZE_BYTES = 0x1 << POOL_SIZE_EXP;
+static const size_t POOL_PTR_MASK = ~(POOL_SIZE_BYTES - 1);
+
+static const size_t CARDS_SIZE_EXP = 12;
+static const size_t CARDS_SIZE_BYTES = 0x1 << CARDS_SIZE_EXP;
+static const size_t CARDS_OFFSET_MASK = (~(CARDS_SIZE_BYTES - 1)) & (POOL_SIZE_BYTES - 1);
+static const size_t CARDS_COUNT = POOL_SIZE_BYTES / CARDS_SIZE_BYTES;
+
+static const size_t OBJECT_ALLIGNMENT = sizeof(size_t);
+static const size_t OBJECT_PTR_MASK = ~(OBJECT_ALLIGNMENT - 1);
Index: src/examples/gc_no_raii/src/internal/object_header.h
===================================================================
--- src/examples/gc_no_raii/src/internal/object_header.h	(revision a2b2761456045c52741a58f2397c74bcfbf3c113)
+++ src/examples/gc_no_raii/src/internal/object_header.h	(revision a2b2761456045c52741a58f2397c74bcfbf3c113)
@@ -0,0 +1,27 @@
+#pragma once
+
+#include <stddef.h>
+#include <stdint.h>
+
+#include "tools.h"
+
+static const void* CANARY_VALUE = (void*)0xCAFEBABACAFEBABA;
+
+struct gcpointer_t;
+
+struct gc_object_header
+{
+	#if _DEBUG
+		void* canary_start;
+	#endif
+
+	size_t				size;
+	gcpointer_t* 			root_chain;
+	gcpointer_t*			type_chain;
+	struct gc_object_header*	forward;
+	bool					is_forwarded;
+
+	#if _DEBUG
+		void* canary_end;
+	#endif
+};
Index: src/examples/gc_no_raii/src/internal/state.c
===================================================================
--- src/examples/gc_no_raii/src/internal/state.c	(revision a2b2761456045c52741a58f2397c74bcfbf3c113)
+++ src/examples/gc_no_raii/src/internal/state.c	(revision a2b2761456045c52741a58f2397c74bcfbf3c113)
@@ -0,0 +1,276 @@
+#include "state.hpp"
+
+#include <algorithm>
+#include <iostream>
+
+//general purpouse includes
+#include "tools.hpp"
+
+//platform abstraction includes
+#include "allocate-pool.h"
+
+//gc internal includes
+#include "globals.hpp"
+#include "memory_pool.hpp"
+#include "memory_pool_iterator.hpp"
+#include "object_header.hpp"
+
+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(nullptr)
+	state->from_space(nullptr)
+	state->total_space(0)
+	state->used_space(0)
+	state->pools_table()
+
+	gc_allocate_pool(gc_state* state);
+}
+
+bool state::is_in_heap(void* address) const
+{
+	memory_pool* target_pool = pool_of(address);
+
+	auto first = pools_table.cbegin();
+	auto last = pools_table.cend();
+	auto result = std::find(first, last, target_pool);
+	return result != last && (*result)->is_from_space();
+}
+
+bool state::is_in_to_space(void* address) const
+{
+	const memory_pool* target_pool = pool_of(address);
+
+	auto first = pools_table.cbegin();
+	auto last = pools_table.cend();
+	auto result = std::find(first, last, target_pool);
+	return result != last && !(*result)->is_from_space();
+}
+
+object_header* state::get_object_for_ref(void* member)
+{
+	intptr_t target = intptr_t(member);
+	if(!is_in_heap(member)) return nullptr;
+
+	memory_pool* pool = pool_of(member);
+	auto it = pool->iterator_for(member);
+	auto end = pool->end();
+
+	while(it != end)
+	{
+		object_header* object = *it;
+		{
+			intptr_t start = intptr_t(object);
+			intptr_t end = intptr_t(start + object->size);
+			if(start < target && end > target)
+			{
+				return object;
+			}
+		}
+		++it;
+	}
+
+	checkf(false, "is_in_heap() and iterator_for() return inconsistent data");
+	abort();
+	return nullptr;
+}
+
+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 state::swap()
+{
+	std::swap(from_space, to_space);
+
+	memory_pool* pool = to_space;
+	while(pool)
+	{
+		pool->reset();
+		pool = pool->next();
+	}
+
+	from_code = (~from_code) & 0x01;
+
+	#if _DEBUG
+		{
+			memory_pool* pool = from_space;
+			while(pool)
+			{
+				check(pool->is_from_space());
+				pool = pool->next();
+			}
+
+			pool = to_space;
+			while(pool)
+			{
+				check(!pool->is_from_space());
+				pool = pool->next();
+			}
+		}
+	#endif
+}
+
+void state::sweep_roots(std::vector<void**>& worklist)
+{
+	memory_pool* pool = from_space;
+	while(pool)
+	{
+		for(object_header* object : *pool)
+		{
+			if(!object->root_chain) continue;
+
+			copy_object(object);
+
+			scan_object(object->forward, worklist);
+		}
+
+		pool = pool->next();
+	}
+}
+
+void state::clear()
+{
+	memory_pool* pool = from_space;
+	while(pool)
+	{
+		pool->reset();
+		pool = pool->next();
+	}
+
+	pool = to_space;
+	while(pool)
+	{
+		pool->reset();
+		pool = pool->next();
+	}
+}
+
+void state::calc_usage()
+{
+	total_space = 0;
+	used_space = 0;
+
+	memory_pool* pool = from_space;
+	while(pool)
+	{
+		size_t size = pool->size();
+		size_t used = size - pool->size_left();
+		check(used <= size);
+		total_space += size;
+		used_space += used;
+
+		pool = pool->next();
+	}
+}
+
+#if _DEBUG
+	bool state::roots_match()
+	{
+		memory_pool* pool = to_space;
+		while(pool)
+		{
+			size_t size = 0;
+			for(object_header* object : *pool)
+			{
+				size += object->size;
+
+				gcpointer_base* ptr = object->root_chain;
+				while(ptr)
+				{
+					check(get_object_ptr(ptr->m_ptr) == object);
+					ptr = ptr->m_next;
+				}
+			}
+
+			check(size + pool->size_left() == pool->size());
+
+			pool = pool->next();
+		}
+
+		return true;
+	}
+
+	bool state::no_from_space_ref()
+	{
+		memory_pool* pool = to_space;
+		while(pool)
+		{
+			void** potential_ref = (void**)pool->m_start;
+			while(potential_ref < (void**)pool->m_free)
+			{
+				check(!is_in_heap(*potential_ref));
+				potential_ref++;
+			}
+
+			pool = pool->next();
+		}
+
+		return true;
+	}
+#endif
Index: src/examples/gc_no_raii/src/internal/state.h
===================================================================
--- src/examples/gc_no_raii/src/internal/state.h	(revision a2b2761456045c52741a58f2397c74bcfbf3c113)
+++ src/examples/gc_no_raii/src/internal/state.h	(revision a2b2761456045c52741a58f2397c74bcfbf3c113)
@@ -0,0 +1,56 @@
+#pragma once
+
+#include <stddef.h>
+#include <stdint.h>
+
+#include "tools.h"
+
+struct gc_state
+{
+	bool is_initialized;
+	uint8_t from_code;
+	struct gc_memory_pool* to_space;
+	struct gc_memory_pool* from_space;
+
+	size_t total_space;
+	size_t used_space;
+
+	const struct memory_pool* 	pools_table;
+	size_t 				pools_table_count;
+};
+
+void gc_state_ctor(gc_state* state);
+
+inline gc_state* get_state()
+{
+	static gc_state s;
+	if(!s.is_initialized) gc_state_ctor(s);
+	return &s;
+}
+
+inline bool needs_collect(gc_state* state)
+{
+	return state->used_space * 2 > state->total_space;
+}
+
+void gc_collect(gc_state* state);
+
+void* gc_try_allocate(gc_state* state, size_t size);
+
+void gc_allocate_pool(gc_state* state);
+
+bool gc_is_in_heap(const gc_state* state, void* address);
+
+bool gc_is_in_to_space(const gc_state* state, void* address);
+
+inline uint8_t gc_from_space_code(const gc_state* state)
+{
+	return state->from_code;
+}
+
+struct gc_object_header* gc_get_object_for_ref(gc_state* state, void*);
+
+inline void gc_register_allocation(gc_state* state, size_t size)
+{
+	state->used_space += size;
+}
Index: src/examples/gc_no_raii/src/tools.h
===================================================================
--- src/examples/gc_no_raii/src/tools.h	(revision a2b2761456045c52741a58f2397c74bcfbf3c113)
+++ src/examples/gc_no_raii/src/tools.h	(revision a2b2761456045c52741a58f2397c74bcfbf3c113)
@@ -0,0 +1,4 @@
+#pragma once
+
+#include "tools/checks.h"
+#include "tools/print.h"
Index: src/examples/gc_no_raii/src/tools/checks.h
===================================================================
--- src/examples/gc_no_raii/src/tools/checks.h	(revision a2b2761456045c52741a58f2397c74bcfbf3c113)
+++ src/examples/gc_no_raii/src/tools/checks.h	(revision a2b2761456045c52741a58f2397c74bcfbf3c113)
@@ -0,0 +1,27 @@
+#pragma once
+
+#if _DEBUG
+
+#include <stdlib.h>
+#include <stdio.h>
+
+#define check(x) do {\
+	if(!(x)) {\
+		printf("CHECK failed : %s at %s:%i\n", #x, __FILE__, __LINE__);\
+		abort();\
+	}}while(0)\
+
+#define checkf(x, ...) do {\
+	if(!(x)) {\
+		printf("CHECK failed : %s at %s:%i\n", #x, __FILE__, __LINE__);\
+		printf(__VA_ARGS__);\
+		abort();\
+	}}while(0)\
+
+#else
+
+#define check(x)
+
+#define checkf(x, format, ...)
+
+#endif //NO_CHECKS
Index: src/examples/gc_no_raii/src/tools/print.c
===================================================================
--- src/examples/gc_no_raii/src/tools/print.c	(revision a2b2761456045c52741a58f2397c74bcfbf3c113)
+++ src/examples/gc_no_raii/src/tools/print.c	(revision a2b2761456045c52741a58f2397c74bcfbf3c113)
@@ -0,0 +1,5 @@
+#include "tools.h"
+
+#if _DEBUG
+	ofstream *sout = ofstream_stdout();
+#endif
Index: src/examples/gc_no_raii/src/tools/print.h
===================================================================
--- src/examples/gc_no_raii/src/tools/print.h	(revision a2b2761456045c52741a58f2397c74bcfbf3c113)
+++ src/examples/gc_no_raii/src/tools/print.h	(revision a2b2761456045c52741a58f2397c74bcfbf3c113)
@@ -0,0 +1,15 @@
+#pragma once
+
+#if _DEBUG
+
+#include "fstream.h"
+
+extern ofstream *sout;
+
+#define DEBUG_OUT(x) sout | x | endl;
+
+#else
+
+#define DEBUG_OUT(x)
+
+#endif //NO_CHECKS
Index: src/examples/gc_no_raii/tools.h
===================================================================
--- src/examples/gc_no_raii/tools.h	(revision e47f529d33f49f6a3d06c4a4bcde0fb84b62eab3)
+++ 	(revision )
@@ -1,4 +1,0 @@
-#pragma once
-
-#include "tools/checks.h"
-#include "tools/print.h"
Index: src/examples/gc_no_raii/tools/checks.h
===================================================================
--- src/examples/gc_no_raii/tools/checks.h	(revision e47f529d33f49f6a3d06c4a4bcde0fb84b62eab3)
+++ 	(revision )
@@ -1,27 +1,0 @@
-#pragma once
-
-#if _DEBUG
-
-#include <stdlib.h>
-#include <stdio.h>
-
-#define check(x) do {\
-	if(!(x)) {\
-		printf("CHECK failed : %s at %s:%i\n", #x, __FILE__, __LINE__);\
-		abort();\
-	}}while(0)\
-
-#define checkf(x, ...) do {\
-	if(!(x)) {\
-		printf("CHECK failed : %s at %s:%i\n", #x, __FILE__, __LINE__);\
-		printf(__VA_ARGS__);\
-		abort();\
-	}}while(0)\
-
-#else
-
-#define check(x)
-
-#define checkf(x, format, ...)
-
-#endif //NO_CHECKS
Index: src/examples/gc_no_raii/tools/print.c
===================================================================
--- src/examples/gc_no_raii/tools/print.c	(revision e47f529d33f49f6a3d06c4a4bcde0fb84b62eab3)
+++ 	(revision )
@@ -1,5 +1,0 @@
-#include "tools.h"
-
-#if _DEBUG
-	ofstream *sout = ofstream_stdout();
-#endif
Index: src/examples/gc_no_raii/tools/print.h
===================================================================
--- src/examples/gc_no_raii/tools/print.h	(revision e47f529d33f49f6a3d06c4a4bcde0fb84b62eab3)
+++ 	(revision )
@@ -1,15 +1,0 @@
-#pragma once
-
-#if _DEBUG
-
-#include "fstream.h"
-
-extern ofstream *sout;
-
-#define DEBUG_OUT(x) sout | x | endl;
-
-#else
-
-#define DEBUG_OUT(x)
-
-#endif //NO_CHECKS
