Index: c/working/exception/impl/except.c
===================================================================
--- doc/working/exception/impl/except.c	(revision 6a48cc99246032383e91b8f51147a1e389f1786b)
+++ 	(revision )
@@ -1,229 +1,0 @@
-#include <stdlib.h>
-#include <stdio.h>
-#include <unwind.h>
-
-#include "lsda.h"
-
-// This macro should be the only thing that needs to change across machines.
-// struct _Unwind_Context * -> _Unwind_Reason_Code(*)()
-#define MATCHER_FROM_CONTEXT(ptr_to_context) \
-	(*(_Unwind_Reason_Code(**)())(_Unwind_GetCFA(ptr_to_context) + 8))
-
-
-//Global which defines the current exception
-//Currently an int just to make matching easier
-int this_exception;
-
-//This is our personality routine
-//For every stack frame anotated with ".cfi_personality 0x3,__gcfa_personality_v0"
-//This function will be called twice when unwinding
-//Once in the search phased and once in the cleanup phase
-_Unwind_Reason_Code __gcfa_personality_v0 (
-                     int version, _Unwind_Action actions, unsigned long long exceptionClass,
-                     struct _Unwind_Exception* unwind_exception, struct _Unwind_Context* context)
-{
-	printf("CFA: 0x%lx\n", _Unwind_GetCFA(context));
-
-	//DEBUG
-	printf("Personality function (%d, %x, %llu, %p, %p):", version, actions, exceptionClass, unwind_exception, context);
-
-	//If we've reached the end of the stack then there is nothing much we can do...
-	if( actions & _UA_END_OF_STACK ) return _URC_END_OF_STACK;
-	
-	//DEBUG
-	if (actions & _UA_SEARCH_PHASE) {
-		printf(" lookup phase");
-	} 
-	//DEBUG
-	else if (actions & _UA_CLEANUP_PHASE) {
-		printf(" cleanup phase");
-	}
-	//Just in case, probably can't actually happen
-	else {
-		printf(" error\n");
-		return _URC_FATAL_PHASE1_ERROR;
-	}
-	
-	//Get a pointer to the language specific data from which we will read what we need
-	const unsigned char * lsd = (const unsigned char*) _Unwind_GetLanguageSpecificData( context );
-
-	if( !lsd ) {	//Nothing to do, keep unwinding
-		printf(" no LSD");
-		goto UNWIND;
-	}
-
-	//Get the instuction pointer and a reading pointer into the exception table
-	lsda_header_info lsd_info;
-	const unsigned char * cur_ptr = parse_lsda_header( context, lsd, &lsd_info);
-	_Unwind_Ptr instruction_ptr = _Unwind_GetIP( context );
-
-	//Linearly search the table for stuff to do
-	while( cur_ptr < lsd_info.action_table ) {
-		_Unwind_Ptr callsite_start;
-		_Unwind_Ptr callsite_len;
-		_Unwind_Ptr callsite_landing_pad;
-		_uleb128_t  callsite_action;
-
-		//Decode the common stuff we have in here
-		cur_ptr = read_encoded_value (0, lsd_info.call_site_encoding, cur_ptr, &callsite_start);
-		cur_ptr = read_encoded_value (0, lsd_info.call_site_encoding, cur_ptr, &callsite_len);
-		cur_ptr = read_encoded_value (0, lsd_info.call_site_encoding, cur_ptr, &callsite_landing_pad);
-		cur_ptr = read_uleb128 (cur_ptr, &callsite_action);
-
-		//Have we reach the correct frame info yet?
-		if( lsd_info.Start + callsite_start + callsite_len < instruction_ptr ) {
-			//DEBUG BEGIN
-			void * ls = (void*)lsd_info.Start;
-			void * cs = (void*)callsite_start;
-			void * cl = (void*)callsite_len;
-			void * bp = (void*)lsd_info.Start + callsite_start;
-			void * ep = (void*)lsd_info.Start + callsite_start + callsite_len;
-			void * ip = (void*)instruction_ptr;
-			printf("\nfound %p - %p (%p, %p, %p), looking for %p\n", bp, ep, ls, cs, cl, ip);
-			//DEBUG END
-			continue;
-		}
-		
-		//Have we gone too far
-		if( lsd_info.Start + callsite_start > instruction_ptr ) {
-			printf(" gone too far");
-			break;
-		}
-
-		//Something to do?
-		if( callsite_landing_pad ) {
-			//Which phase are we in
-			if (actions & _UA_SEARCH_PHASE) {
-				//Search phase, this means we probably found a potential handler and must check if it is a match
-
-				//If we have arbitrarily decided that 0 means nothing to do and 1 means there is a potential handler
-				//This doesn't seem to conflict the gcc default behavior
-				if (callsite_action != 0) {
-					//Now we want to run some code to see if the handler matches
-					//This is the tricky part where we want to the power to run arbitrary code
-					//However, generating a new exception table entry and try routine every time 
-					//is way more expansive than we might like
-					//The information we have is :
-					//  - The GR (Series of registers)
-					//    GR1=GP Global Pointer of frame ref by context
-					//  - The instruction pointer
-					//  - The instruction pointer info (???)
-					//  - The CFA (Canonical Frame Address)
-					//  - The BSP (Probably the base stack pointer)
-
-
-					//The current apprach uses one exception table entry per try block
-					_uleb128_t imatcher;
-					//Get the relative offset to the 
-					cur_ptr = read_uleb128 (cur_ptr, &imatcher);
-
-					//Get a function pointer from the relative offset and call it
-					// _Unwind_Reason_Code (*matcher)() = (_Unwind_Reason_Code (*)())lsd_info.LPStart + imatcher;					
-
-					_Unwind_Reason_Code (*matcher)() =
-						MATCHER_FROM_CONTEXT(context);
-					_Unwind_Reason_Code ret = matcher();
-
-					//Based on the return value, check if we matched the exception
-					if( ret == _URC_HANDLER_FOUND) printf(" handler found\n");
-					else printf(" no handler\n");
-					return ret;
-				}
-
-				//This is only a cleanup handler, ignore it
-				printf(" no action");
-			} 
-			else if (actions & _UA_CLEANUP_PHASE) {
-
-				if( (callsite_action != 0) && !(actions & _UA_HANDLER_FRAME) ){
-					//If this is a potential exception handler 
-					//but not the one that matched the exception in the seach phase,
-					//just ignore it
-					goto UNWIND;
-				}
-
-				//We need to run some clean-up or a handler
-				//These statment do the right thing but I don't know any specifics at all
-				_Unwind_SetGR( context, __builtin_eh_return_data_regno(0), (_Unwind_Ptr) unwind_exception );
-				_Unwind_SetGR( context, __builtin_eh_return_data_regno(1), 0 );
-
-				//I assume this sets the instruction pointer to the adress of the landing pad
-				//It doesn't actually set it, it only state the value that needs to be set once we return _URC_INSTALL_CONTEXT
-				_Unwind_SetIP( context, lsd_info.LPStart + callsite_landing_pad );
-
-				//DEBUG
-				printf(" action\n");
-
-				//Return have some action to run
-				return _URC_INSTALL_CONTEXT;
-			}
-		}
-
-		//Nothing to do, move along
-		printf(" no landing pad");
-	}
-	//No handling found
-	printf(" table end reached\n");
-
-	//DEBUG
-	UNWIND:
-	printf(" unwind\n");
-
-	//Keep unwinding the stack
-	return _URC_CONTINUE_UNWIND;
-}
-
-//We need a piece of storage to raise the exception
-struct _Unwind_Exception this_exception_storage;
-
-//Function needed by force unwind
-//It basically says to unwind the whole stack and then exit when we reach the end of the stack
-static _Unwind_Reason_Code _Stop_Fn(	
-	int version, 
-	_Unwind_Action actions, 
-	_Unwind_Exception_Class exceptionClass, 
-	struct _Unwind_Exception * unwind_exception, 
-	struct _Unwind_Context * context, 
-	void * some_param
-) {
-	if( actions & _UA_END_OF_STACK  ) exit(1);
-	if( actions & _UA_CLEANUP_PHASE ) return _URC_NO_REASON;
-
-	return _URC_FATAL_PHASE2_ERROR;
-}
-
-//Example throw routine
-void throw( int val ) {
-	//Store the current exception
-	this_exception = val;
-
-	//DEBUG
-	printf("Throwing exception %d\n", this_exception);
-
-	//Call stdlibc to raise the exception
-	_Unwind_Reason_Code ret = _Unwind_RaiseException( &this_exception_storage );
-
-	//If we reach here it means something happened
-	//For resumption to work we need to find a way to return back to here
-	//Most of them will probably boil down to setting a global flag and making the phase 1 either stop or fail.
-	//Causing an error on purpose may help avoiding unnecessary work but it might have some weird side effects.
-	//If we just pretend no handler was found that would work but may be expensive for no reason since we will always
-	//search the whole stack
-
-	if( ret == _URC_END_OF_STACK ) {
-		//No proper handler was found
-		//This can be handled in several way
-		//C++ calls std::terminate
-		//Here we force unwind the stack, basically raising a cancellation
-		printf("Uncaught exception %p\n", &this_exception_storage);
-		
-		ret = _Unwind_ForcedUnwind( &this_exception_storage, _Stop_Fn, (void*)0x22 );
-		printf("UNWIND ERROR %d after force unwind\n", ret);
-		abort();
-	}
-
-	//We did not simply reach the end of the stack without finding a handler,
-	//Something wen't wrong
-	printf("UNWIND ERROR %d after raise exception\n", ret);
-	abort();
-}
Index: c/working/exception/impl/except.h
===================================================================
--- doc/working/exception/impl/except.h	(revision 6a48cc99246032383e91b8f51147a1e389f1786b)
+++ 	(revision )
@@ -1,3 +1,0 @@
-#include <unwind.h>
-
-void throw( int val );
Index: c/working/exception/impl/main.c
===================================================================
--- doc/working/exception/impl/main.c	(revision 6a48cc99246032383e91b8f51147a1e389f1786b)
+++ 	(revision )
@@ -1,191 +1,0 @@
-#include <stdio.h>
-#include "except.h"
-
-// Requires -fexceptions to work.
-
-#define EXCEPTION 2
-
-struct type_raii_t {
-	char * msg;
-};
-
-//Dtor function to test clean up routines
-void dtor( struct type_raii_t * this ) {
-	printf("%s\n", this->msg);
-}
-
-//Type macro use to make scope unwinding easier to see.
-#define raii_t __attribute__(( cleanup(dtor) )) struct type_raii_t
-
-//Leaf functions that raises exception
-void bar() {
-	raii_t a = { "Bar dtor" };
-
-	throw( EXCEPTION );
-}
-
-//Matcher function which will check if the exception was correctly caught
-extern int this_exception;
-_Unwind_Reason_Code foo_try_match() {
-	printf(" (foo_try_match called)");
-	return this_exception == EXCEPTION ? _URC_HANDLER_FOUND : _URC_CONTINUE_UNWIND;
-}
-
-//Try statements are hoisted out see comments for details
-//With this could probably be unique and simply linked from
-//libcfa but there is one problem left, see the exception table 
-//for details
-__attribute__((noinline))
-void try( void (*try_block)(), void (*catch_block)(),
-          _Unwind_Reason_Code (*match_block)() )
-{
-	volatile int xy = 0;
-	printf("%p %p %p %p\n", &try_block, &catch_block, &match_block, &xy);
-
-	//Setup statments
-	//These 2 statments won't actually result in any code,
-	//they only setup global tables.
-	//However, they clobber gcc cancellation support from gcc.
-	//We can replace the personality routine but replacing the exception
-	//table gcc generates is not really doable, it generates labels based
-	//on how the assembly works.
-	//Setup the personality routine
-	asm volatile (".cfi_personality 0x3,__gcfa_personality_v0");
-	//Setup the exception table
-	asm volatile (".cfi_lsda 0x3, .LLSDACFA2");
-
-	//Label which defines the start of the area for which the handler is setup
-	asm volatile (".TRYSTART:");
-
-	//The actual statements of the try blocks
-	try_block();
-
-	//asm statement to prevent deadcode removal
-	asm volatile goto ("" : : : : CATCH );
-
-	//Normal return
-	return;
-
-	//Exceptionnal path
-	CATCH : __attribute__(( unused ));
-	//Label which defines the end of the area for which the handler is setup
-	asm volatile (".TRYEND:");
-	//Label which defines the start of the exception landing pad
-	//basically what will be called when the exception is caught
-	//Note, if multiple handlers are given, the multiplexing should be done
-	//by the generated code, not the exception runtime
-	asm volatile (".CATCH:");
-
-	//Exception handler
-	catch_block();
-}
-
-//Exception table data we need to generate
-//While this is almost generic, the custom data refers to
-//foo_try_match try match, which is no way generic
-//Some more works need to be done if we want to have a single 
-//call to the try routine
-asm (
-	//HEADER
-	".LFECFA1:\n"
-	"	.globl	__gcfa_personality_v0\n"
-	"	.section	.gcc_except_table,\"a\",@progbits\n"
-	".LLSDACFA2:\n"							//TABLE header
-	"	.byte	0xff\n"
-	"	.byte	0xff\n"
-	"	.byte	0x1\n"
-	"	.uleb128 .LLSDACSECFA2-.LLSDACSBCFA2\n"		//BODY length
-	//Body uses language specific data and therefore could be modified arbitrarily
-	".LLSDACSBCFA2:\n"						//BODY start
-	"	.uleb128 .TRYSTART-try\n"				//Handled area start  (relative to start of function)
-	"	.uleb128 .TRYEND-.TRYSTART\n"				//Handled area length
-	"	.uleb128 .CATCH-try\n"				//Hanlder landing pad adress  (relative to start of function)
-	"	.uleb128 1\n"						//Action code, gcc seems to use always 0
-	".LLSDACSECFA2:\n"						//BODY end
-	"	.text\n"							//TABLE footer
-	"	.size	try, .-try\n"
-	"	.ident	\"GCC: (Ubuntu 6.2.0-3ubuntu11~16.04) 6.2.0 20160901\"\n"
-	"	.section	.note.GNU-stack,\"x\",@progbits\n"
-);
-
-void foo() {
-	raii_t a = { "Foo dtor" };
-
-	//Since try will clobber the gcc exception table assembly,
-	//We need to nest this to have gcc regenerate the data
-	void foo_try_block() {
-		raii_t b = { "Foo try dtor" };
-
-		bar();
-
-		printf("Called bar successfully\n");
-	}
-
-	void foo_catch_block() {
-		printf("Exception caught\n");
-	}
-
-	//Actual call to the try block
-	try( foo_try_block, foo_catch_block, foo_try_match );
-
-	printf( "Foo exited normally\n" );
-}
-
-// Not in main.cfa
-void fy() {
-	// Currently not destroyed if the exception is caught in fee.
-	raii_t a = { "Fy dtor" };
-
-	void fy_try_block() {
-		raii_t b = { "Fy try dtor" };
-
-		throw( 3 );
-	}
-
-	void fy_catch_block() {
-		printf("Fy caught exception\n");
-	}
-
-	_Unwind_Reason_Code fy_match_block() {
-		return this_exception == 2 ? _URC_HANDLER_FOUND : _URC_CONTINUE_UNWIND;
-	}
-
-	try(fy_try_block, fy_catch_block, fy_match_block);
-
-	printf( "Fy exited normally\n" );
-}
-
-void fee() {
-	raii_t a = { "Fee dtor" };
-
-	void fee_try_block() {
-		raii_t b = { "Fee try dtor" };
-
-		fy();
-
-		printf("fy returned\n");
-	}
-
-	void fee_catch_block() {
-		printf("Fee caught exception\n");
-	}
-
-	_Unwind_Reason_Code fee_match_block() {
-		return this_exception == 3 ? _URC_HANDLER_FOUND : _URC_CONTINUE_UNWIND;
-	}
-
-	try(fee_try_block, fee_catch_block, fee_match_block);
-
-	printf( "Fee exited normally\n" );
-}
-// End not in main.cfa
-
-int main() {
-	raii_t a = { "Main dtor" };
-
-	//for (unsigned int i = 0 ; i < 100000000 ; ++i)
-	foo();
-	fee();
-
-	printf("End of program reached\n");
-}
Index: c/working/exception/impl/resume-main.c
===================================================================
--- doc/working/exception/impl/resume-main.c	(revision 6a48cc99246032383e91b8f51147a1e389f1786b)
+++ 	(revision )
@@ -1,152 +1,0 @@
-#include <stdio.h>
-#include <stdbool.h>
-
-// Proof of concept for resumption exception handling.
-// Names, checks promises and so on all would have to be improved.
-
-struct resume_group;
-
-// Stackwise information (global for single stack)
-struct code_stack_data {
-	struct resume_group * top_resume;
-	struct resume_group * current_resume;
-} stack = {NULL, NULL};
-
-// private exception header begin ============================================
-
-struct resume_group {
-	struct resume_group * next;
-	bool (*try_to_handle)(int);
-};
-
-void __resume_group_dtor(struct resume_group * this) {
-	stack.top_resume = this->next;
-}
-
-void __cfa_eh__throw_resume(int except) {
-	struct resume_group * original_head = stack.current_resume;
-	struct resume_group * current =
-		(original_head) ? original_head->next : stack.top_resume;
-
-	for ( ; current ; current = current->next) {
-		stack.current_resume = current;
-		if (current->try_to_handle(except)) {
-			stack.current_resume = original_head;
-			return;
-		}
-	}
-
-	printf("Unhandled exception %d\n", except);
-}
-
-// private exception header end ==============================================
-
-// Set up of unwind checker type.
-struct type_raii_t {
-	char * msg;
-};
-
-void dtor( struct type_raii_t * this ) {
-	printf("%s\n", this->msg);
-}
-
-#define raii_t __attribute__((cleanup(dtor))) struct type_raii_t
-
-void bar() {
-	raii_t a = { "Bar dtor" };
-
-	__cfa_eh__throw_resume( 3 );
-}
-
-void foo() {
-	raii_t a = { "Foo dtor" };
-
-	{
-		bool foo_catch_resume(int exception_id) {
-			if (exception_id == 3) {
-				printf("Exception caught\n");
-				return true;
-			}
-			return false;
-		}
-		struct resume_group __attribute__((cleanup(__resume_group_dtor)))
-			foo_try_resume = {stack.top_resume, foo_catch_resume};
-		stack.top_resume = &foo_try_resume;
-		{
-			raii_t b = { "Foo try dtor" };
-
-			bar();
-
-			printf("Called bar successfully\n");
-		}
-	}
-	printf( "Foo exited normally\n" );
-}
-
-// Not in main.cfa
-void foe() {
-	raii_t a = { "Foe dtor" };
-
-	printf("Foe throws\n");
-	__cfa_eh__throw_resume( 4 );
-
-	printf("Foe exits normally\n");
-}
-
-void fy() {
-	raii_t a = { "Fy dtor" };
-
-	{
-		bool fy_catch_resume(int exception_id) {
-			if (4 == exception_id) {
-				printf("Rethrow in fy\n");
-				__cfa_eh__throw_resume(exception_id);
-				return true;
-			}
-			return false;
-		}
-		struct resume_group __attribute__((cleanup(__resume_group_dtor)))
-			fy_try_resume = {stack.top_resume, fy_catch_resume};
-		stack.top_resume = &fy_try_resume;
-		{
-			raii_t b = { "Fy try dtor" };
-			foe();
-		}
-	}
-
-	printf("Fy exits normally\n");
-}
-
-void fee() {
-	raii_t a = { "Fee dtor" };
-
-	{
-		bool fee_catch_resume(int exception_id) {
-			if (4 == exception_id) {
-				printf("fee caught exception\n");
-				return true;
-			}
-			return false;
-		}
-		struct resume_group __attribute__((cleanup(__resume_group_dtor)))
-			fee_try_resume = {stack.top_resume, fee_catch_resume};
-		stack.top_resume = &fee_try_resume;
-		{
-			raii_t b = { "Fee try dtor" };
-			fy();
-		}
-	}
-
-	printf("Fee exits normally\n");
-}
-// End not in main.cfa
-
-int main() {
-	raii_t a = { "Main dtor" };
-
-	foo();
-
-	fee();
-
-	printf("End of program reached\n");
-}
