Index: benchmark/Cargo.toml.in
===================================================================
--- benchmark/Cargo.toml.in	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ benchmark/Cargo.toml.in	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -6,10 +6,18 @@
 
 [[bin]]
-name = "cycle-tokio"
+name = "rdq-cycle-tokio"
 path = "@abs_srcdir@/readyQ/cycle.rs"
 
 [[bin]]
-name = "locality-tokio"
+name = "rdq-locality-tokio"
 path = "@abs_srcdir@/readyQ/locality.rs"
+
+[[bin]]
+name = "rdq-transfer-tokio"
+path = "@abs_srcdir@/readyQ/transfer.rs"
+
+[[bin]]
+name = "rdq-yield-tokio"
+path = "@abs_srcdir@/readyQ/yield.rs"
 
 [features]
Index: benchmark/Makefile.am
===================================================================
--- benchmark/Makefile.am	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ benchmark/Makefile.am	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -21,5 +21,5 @@
 include $(top_srcdir)/tools/build/cfa.make
 
-AM_CFLAGS = -O2 -Wall -Wextra -I$(srcdir) -lrt -pthread # -Werror
+AM_CFLAGS = -O3 -Wall -Wextra -I$(srcdir) -lrt -pthread # -Werror
 AM_CFAFLAGS = -quiet -nodebug
 AM_UPPFLAGS = -quiet -nodebug -multi -std=c++14
@@ -197,4 +197,21 @@
 	$(srcdir)/fixcsv.sh $@
 
+# use --no-print-directory to generate csv appropriately
+mutexStmt.csv:
+	echo "building $@"
+	echo "1-lock,2-lock,4-lock,8-lock,1-no-stmt-lock,2-no-stmt-lock,4-no-stmt-lock,8-no-stmt-lock,1-monitor,2-monitor,4-monitor" > $@
+	+make mutexStmt-lock1.runquiet >> $@ && echo -n ',' >> $@
+	+make mutexStmt-lock2.runquiet >> $@ && echo -n ',' >> $@
+	+make mutexStmt-lock4.runquiet >> $@ && echo -n ',' >> $@
+	+make mutexStmt-lock8.runquiet >> $@ && echo -n ',' >> $@
+	+make mutexStmt-no-stmt-lock1.runquiet >> $@ && echo -n ',' >> $@
+	+make mutexStmt-no-stmt-lock2.runquiet >> $@ && echo -n ',' >> $@
+	+make mutexStmt-no-stmt-lock4.runquiet >> $@ && echo -n ',' >> $@
+	+make mutexStmt-no-stmt-lock8.runquiet >> $@ && echo -n ',' >> $@
+	+make mutexStmt-monitor1.runquiet >> $@ && echo -n ',' >> $@
+	+make mutexStmt-monitor2.runquiet >> $@ && echo -n ',' >> $@
+	+make mutexStmt-monitor4.runquiet >> $@
+	$(srcdir)/fixcsv.sh $@
+
 schedint.csv:
 	echo "building $@"
@@ -357,4 +374,75 @@
 ## =========================================================================================================
 
+mutexStmt$(EXEEXT) :		    \
+	mutexStmt-cpp1.run			\
+	mutexStmt-cpp2.run			\
+	mutexStmt-cpp4.run			\
+	mutexStmt-cpp8.run			\
+	mutexStmt-java.run			\
+	mutexStmt-lock1.run		    \
+	mutexStmt-lock2.run		    \
+	mutexStmt-lock4.run		    \
+	mutexStmt-lock8.run		    \
+	mutexStmt-no-stmt-lock1.run \
+	mutexStmt-no-stmt-lock2.run \
+	mutexStmt-no-stmt-lock4.run \
+	mutexStmt-no-stmt-lock8.run \
+	mutexStmt-monitor1.run      \
+	mutexStmt-monitor2.run      \
+	mutexStmt-monitor4.run
+
+mutexStmt-lock1$(EXEEXT):
+	$(BENCH_V_CFA)$(CFACOMPILE) $(srcdir)/mutexStmt/lock1.cfa
+
+mutexStmt-lock2$(EXEEXT):
+	$(BENCH_V_CFA)$(CFACOMPILE) $(srcdir)/mutexStmt/lock2.cfa
+
+mutexStmt-lock4$(EXEEXT):
+	$(BENCH_V_CFA)$(CFACOMPILE) $(srcdir)/mutexStmt/lock4.cfa
+
+mutexStmt-lock8$(EXEEXT):
+	$(BENCH_V_CFA)$(CFACOMPILE) $(srcdir)/mutexStmt/lock8.cfa
+
+mutexStmt-cpp1$(EXEEXT):
+	$(BENCH_V_CXX)$(CXXCOMPILE) -std=c++17 $(srcdir)/mutexStmt/cpp1.cc
+
+mutexStmt-cpp2$(EXEEXT):
+	$(BENCH_V_CXX)$(CXXCOMPILE) -std=c++17 $(srcdir)/mutexStmt/cpp2.cc
+
+mutexStmt-cpp4$(EXEEXT):
+	$(BENCH_V_CXX)$(CXXCOMPILE) -std=c++17 $(srcdir)/mutexStmt/cpp4.cc
+
+mutexStmt-cpp8$(EXEEXT):
+	$(BENCH_V_CXX)$(CXXCOMPILE) -std=c++17 $(srcdir)/mutexStmt/cpp8.cc
+
+mutexStmt-monitor1$(EXEEXT):
+	$(BENCH_V_CFA)$(CFACOMPILE) $(srcdir)/mutexStmt/monitor1.cfa
+
+mutexStmt-monitor2$(EXEEXT):
+	$(BENCH_V_CFA)$(CFACOMPILE) $(srcdir)/mutexStmt/monitor2.cfa
+
+mutexStmt-monitor4$(EXEEXT):
+	$(BENCH_V_CFA)$(CFACOMPILE) $(srcdir)/mutexStmt/monitor4.cfa
+
+mutexStmt-no-stmt-lock1$(EXEEXT):
+	$(BENCH_V_CFA)$(CFACOMPILE) $(srcdir)/mutexStmt/no_stmt_lock1.cfa
+
+mutexStmt-no-stmt-lock2$(EXEEXT):
+	$(BENCH_V_CFA)$(CFACOMPILE) $(srcdir)/mutexStmt/no_stmt_lock2.cfa
+
+mutexStmt-no-stmt-lock4$(EXEEXT):
+	$(BENCH_V_CFA)$(CFACOMPILE) $(srcdir)/mutexStmt/no_stmt_lock4.cfa
+
+mutexStmt-no-stmt-lock8$(EXEEXT):
+	$(BENCH_V_CFA)$(CFACOMPILE) $(srcdir)/mutexStmt/no_stmt_lock8.cfa
+
+mutexStmt-java$(EXEEXT):
+	$(BENCH_V_JAVAC)javac -d $(builddir) $(srcdir)/mutexStmt/JavaThread.java
+	echo "#!/bin/sh" > a.out
+	echo "java JavaThread \"$$""@\"" >> a.out
+	chmod a+x a.out
+
+## =========================================================================================================
+
 schedint$(EXEEXT) :		\
 	schedint-cfa1.run	\
@@ -524,5 +612,54 @@
 ## =========================================================================================================
 
-%-tokio$(EXEEXT): $(srcdir)/readyQ/%.rs $(srcdir)/bench.rs
-	cd $(builddir) && cargo build --release
-	cp $(builddir)/target/release/$(basename $@) $@
+RDQBENCHES = \
+	rdq-cycle-cfa \
+	rdq-cycle-tokio \
+	rdq-cycle-go \
+	rdq-cycle-fibre \
+	rdq-yield-cfa \
+	rdq-yield-tokio \
+	rdq-yield-go \
+	rdq-yield-fibre \
+	rdq-locality-cfa \
+	rdq-locality-tokio \
+	rdq-locality-go \
+	rdq-locality-fibre \
+	rdq-transfer-cfa \
+	rdq-transfer-tokio \
+	rdq-transfer-go \
+	rdq-transfer-fibre
+
+rdq-benches:
+	+make $(RDQBENCHES)
+
+clean-rdq-benches:
+	rm -rf $(RDQBENCHES) $(builddir)/target go.mod
+
+rdq-%-tokio$(EXEEXT): $(builddir)/target/release/rdq-%-tokio$(EXEEXT)
+	$(BENCH_V_RUSTC)cp $(builddir)/target/release/$(basename $@) $@
+
+$(builddir)/target/release/rdq-%-tokio$(EXEEXT): $(srcdir)/readyQ/%.rs $(srcdir)/bench.rs
+	$(BENCH_V_RUSTC)cd $(builddir) && cargo build --release
+
+rdq-%-cfa$(EXEEXT): $(srcdir)/readyQ/%.cfa $(srcdir)/readyQ/rq_bench.hfa
+	$(BENCH_V_CFA)$(CFACOMPILE) $< -o $@
+
+go.mod:
+	touch $@
+	go mod edit -module=rdq.bench
+	go get golang.org/x/sync/semaphore
+	go get golang.org/x/text/language
+	go get golang.org/x/text/message
+
+rdq-%-go$(EXEEXT): $(srcdir)/readyQ/%.go $(srcdir)/readyQ/bench.go go.mod
+	$(BENCH_V_GOC)go build -o $@ $< $(srcdir)/readyQ/bench.go
+
+rdq-%-fibre$(EXEEXT): $(srcdir)/readyQ/%.cpp
+	$(BENCH_V_CXX)$(CXXCOMPILE) $< -o $@ -lfibre -std=c++17 $(AM_CFLAGS)
+
+# ## =========================================================================================================
+
+CLEANFILES = $(RDQBENCHES) go.mod go.sum
+
+clean-local:
+	-rm -rf target
Index: benchmark/bench.h
===================================================================
--- benchmark/bench.h	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ benchmark/bench.h	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -21,4 +21,21 @@
 	return 1000000000LL * ts.tv_sec + ts.tv_nsec;
 } // bench_time
+
+
+#if defined(__cforall)
+struct test_spinlock {
+	volatile bool lock;
+};
+
+static inline void lock( test_spinlock & this ) {
+	for ( ;; ) {
+		if ( (this.lock == 0) && (__atomic_test_and_set( &this.lock, __ATOMIC_ACQUIRE ) == 0) ) break;
+	}
+}
+
+static inline void unlock( test_spinlock & this ) {
+	__atomic_clear( &this.lock, __ATOMIC_RELEASE );
+}
+#endif
 
 #ifndef BENCH_N
Index: benchmark/bench.rs
===================================================================
--- benchmark/bench.rs	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ benchmark/bench.rs	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -1,5 +1,7 @@
 use std::io::{self, Write};
+use std::option;
 use std::sync::atomic::{AtomicU64, AtomicBool, Ordering};
 use std::time::{Instant,Duration};
+use std::u128;
 
 use clap::{Arg, ArgMatches};
@@ -27,8 +29,12 @@
 
 impl BenchData {
-	pub fn new(options: ArgMatches, nthreads: usize) -> BenchData {
+	pub fn new(options: ArgMatches, nthreads: usize, default_it: option::Option<u64>) -> BenchData {
 		let (clock_mode, stop_count, duration) = if options.is_present("iterations") {
 			(false,
 			options.value_of("iterations").unwrap().parse::<u64>().unwrap(),
+			-1.0)
+		} else if !default_it.is_none() {
+			(false,
+			default_it.unwrap(),
 			-1.0)
 		} else {
@@ -48,4 +54,5 @@
 	}
 
+	#[allow(dead_code)]
 	pub async fn wait(&self, start: &Instant) -> Duration{
 		loop {
@@ -69,2 +76,7 @@
 }
 
+// ==================================================
+pub fn _lehmer64( state: &mut u128 ) -> u64 {
+	*state = state.wrapping_mul(0xda942042e4dd58b5);
+	return (*state >> 64) as u64;
+}
Index: benchmark/io/http/filecache.cfa
===================================================================
--- benchmark/io/http/filecache.cfa	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ benchmark/io/http/filecache.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -185,5 +185,5 @@
 	sout | "Filled cache from path \"" | path | "\" with" | fcount | "files";
 	if( conflicts > 0 ) {
-		sout | "Found" | conflicts | "conflicts (seed: " | options.file_cache.hash_seed | ")";
+		sout | "Found" | conflicts | "conflicts (size: " | file_cache.size | ", seed: " | options.file_cache.hash_seed | ")";
 		#if defined(REJECT_CONFLICTS)
 			abort("Conflicts found in the cache");
Index: benchmark/io/http/http_ring.cpp
===================================================================
--- benchmark/io/http/http_ring.cpp	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ benchmark/io/http/http_ring.cpp	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -118,11 +118,11 @@
 // Get a fix reply based on the return code
 const char * http_msgs[] = {
-	"HTTP/1.1 200 OK\r\nServer: HttoForall\r\nContent-Type: text/plain\r\nContent-Length: 15\r\nConnection: keep-alive\r\n\r\nHello, World!\r\n",
-	"HTTP/1.1 400 Bad Request\r\nServer: HttoForall\r\nContent-Type: text/plain\r\nContent-Length: 0 \r\n\r\n",
-	"HTTP/1.1 404 Not Found\r\nServer: HttoForall\r\nContent-Type: text/plain\r\nContent-Length: 0 \r\n\r\n",
-	"HTTP/1.1 405 Method Not \r\nServer: HttoForall\r\nContent-Type: text/plain\r\nContent-Length: 0 \r\n\r\n",
-	"HTTP/1.1 408 Request Timeout\r\nServer: HttoForall\r\nContent-Type: text/plain\r\nContent-Length: 0 \r\n\r\n",
-	"HTTP/1.1 413 Payload Too Large\r\nServer: HttoForall\r\nContent-Type: text/plain\r\nContent-Length: 0 \r\n\r\n",
-	"HTTP/1.1 414 URI Too Long\r\nServer: HttoForall\r\nContent-Type: text/plain\r\nContent-Length: 0 \r\n\r\n",
+	"HTTP/1.1 200 OK\r\nServer: HttpForall\r\nContent-Type: text/plain\r\nContent-Length: 15\r\nConnection: keep-alive\r\n\r\nHello, World!\r\n",
+	"HTTP/1.1 400 Bad Request\r\nServer: HttpForall\r\nContent-Type: text/plain\r\nContent-Length: 0 \r\n\r\n",
+	"HTTP/1.1 404 Not Found\r\nServer: HttpForall\r\nContent-Type: text/plain\r\nContent-Length: 0 \r\n\r\n",
+	"HTTP/1.1 405 Method Not \r\nServer: HttpForall\r\nContent-Type: text/plain\r\nContent-Length: 0 \r\n\r\n",
+	"HTTP/1.1 408 Request Timeout\r\nServer: HttpForall\r\nContent-Type: text/plain\r\nContent-Length: 0 \r\n\r\n",
+	"HTTP/1.1 413 Payload Too Large\r\nServer: HttpForall\r\nContent-Type: text/plain\r\nContent-Length: 0 \r\n\r\n",
+	"HTTP/1.1 414 URI Too Long\r\nServer: HttpForall\r\nContent-Type: text/plain\r\nContent-Length: 0 \r\n\r\n",
 };
 static_assert( KNOWN_CODES == (sizeof(http_msgs) / sizeof(http_msgs[0])) );
Index: benchmark/io/http/main.cfa
===================================================================
--- benchmark/io/http/main.cfa	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ benchmark/io/http/main.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -190,5 +190,5 @@
 			init_protocol();
 			{
-				Worker workers[options.clopts.nworkers];
+				Worker * workers = anew(options.clopts.nworkers);
 				for(i; options.clopts.nworkers) {
 					// if( options.file_cache.fixed_fds ) {
@@ -212,4 +212,5 @@
 				}
 				sout | nl;
+				if(!options.interactive) park();
 				{
 					char buffer[128];
@@ -249,4 +250,5 @@
 
 				sout | "Stopping connection threads..." | nonl; flush( sout );
+				adelete(workers);
 			}
 			sout | "done";
Index: benchmark/io/http/options.cfa
===================================================================
--- benchmark/io/http/options.cfa	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ benchmark/io/http/options.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -21,4 +21,7 @@
 	false, // log
 	false, // stats
+	true, // interactive
+	0, // redirect
+	0, // redirect
 
 	{ // file_cache
@@ -52,5 +55,5 @@
 	// bool sqkpoll = false;
 	// bool iokpoll = false;
-	unsigned nentries = 16;
+	unsigned nentries = 0;
 	bool isolate = false;
 
@@ -62,5 +65,8 @@
 		{'\0', "isolate",        "Create one cluster per processor", isolate, parse_settrue},
 		{'\0', "log",            "Enable logs", options.log, parse_settrue},
+		{'\0', "sout",           "Redirect standard out to file", options.reopen_stdout},
+		{'\0', "serr",           "Redirect standard error to file", options.reopen_stderr},
 		{'\0', "stats",          "Enable statistics", options.stats, parse_settrue},
+		{'\0', "shell",          "Disable interactive mode", options.interactive, parse_setfalse},
 		{'\0', "accept-backlog", "Maximum number of pending accepts", options.socket.backlog},
 		{'\0', "request_len",    "Maximum number of bytes in the http request, requests with more data will be answered with Http Code 414", options.socket.buflen},
@@ -79,5 +85,5 @@
 	parse_args( argc, argv, opt, opt_cnt, "[OPTIONS]... [PATH]\ncforall http server", left );
 
-	if( !is_pow2(nentries) ) {
+	if( nentries != 0 && !is_pow2(nentries) ) {
 		unsigned v = nentries;
 		v--;
@@ -131,3 +137,26 @@
 
 	options.file_cache.path = path;
+
+	if( options.reopen_stdout && options.reopen_stderr && 0 == strcmp(options.reopen_stdout, options.reopen_stderr) ) {
+		serr | "Redirect sout and serr to the same file is not supported";
+		exit(EXIT_FAILURE);
+	}
+
+	if( options.reopen_stdout ) {
+		sout | "redirecting sout to '" | options.reopen_stdout | "'";
+		FILE  * ret = freopen( options.reopen_stdout, "w", stdout);
+		if( ret == 0p ) {
+			serr | "Failed to redirect sout to '" | options.reopen_stdout | "'";
+			exit(EXIT_FAILURE);
+		}
+	}
+
+	if( options.reopen_stderr ) {
+		sout | "redirecting serr to '" | options.reopen_stderr | "'";
+		FILE  * ret = freopen( options.reopen_stderr, "w", stderr);
+		if( ret == 0p ) {
+			serr | "Failed to redirect serr to '" | options.reopen_stderr | "'";
+			exit(EXIT_FAILURE);
+		}
+	}
 }
Index: benchmark/io/http/options.hfa
===================================================================
--- benchmark/io/http/options.hfa	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ benchmark/io/http/options.hfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -10,4 +10,7 @@
 	bool log;
 	bool stats;
+	bool interactive;
+	const char * reopen_stdout;
+	const char * reopen_stderr;
 
 	struct {
Index: benchmark/io/http/protocol.cfa
===================================================================
--- benchmark/io/http/protocol.cfa	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ benchmark/io/http/protocol.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -11,4 +11,6 @@
 #include <fstream.hfa>
 #include <iofwd.hfa>
+#include <io/types.hfa>
+#include <mutex_stmt.hfa>
 
 #include <assert.h>
@@ -26,4 +28,5 @@
 #define PLAINTEXT_MEMCPY
 #define PLAINTEXT_NOCOPY
+#define LINKED_IO
 
 struct https_msg_str {
@@ -53,10 +56,10 @@
 }
 
-static inline int answer( int fd, const char * it, int len) {
+static inline int answer( int fd, const char * it, int len ) {
 	while(len > 0) {
 		// Call write
 		int ret = cfa_send(fd, it, len, 0, CFA_IO_LAZY);
 		if( ret < 0 ) {
-			if( errno == ECONNRESET || errno == EPIPE ) return -ECONNRESET;
+			if( errno == ECONNRESET || errno == EPIPE ) { close(fd); return -ECONNRESET; }
 			if( errno == EAGAIN || errno == EWOULDBLOCK) return -EAGAIN;
 
@@ -77,11 +80,15 @@
 }
 
-int answer_header( int fd, size_t size ) {
-	char buffer[512];
-	char * it = buffer;
+static int fill_header(char * it, size_t size) {
 	memcpy(it, http_msgs[OK200]->msg, http_msgs[OK200]->len);
 	it += http_msgs[OK200]->len;
 	int len = http_msgs[OK200]->len;
 	len += snprintf(it, 512 - len, "%d \n\n", size);
+	return len;
+}
+
+static int answer_header( int fd, size_t size ) {
+	char buffer[512];
+	int len = fill_header(buffer, size);
 	return answer( fd, buffer, len );
 }
@@ -135,46 +142,5 @@
 }
 
-
-[HttpCode code, bool closed, * const char file, size_t len] http_read(int fd, []char buffer, size_t len) {
-	char * it = buffer;
-	size_t count = len - 1;
-	int rlen = 0;
-	READ:
-	for() {
-		int ret = cfa_recv(fd, (void*)it, count, 0, CFA_IO_LAZY);
-		// int ret = read(fd, (void*)it, count);
-		if(ret == 0 ) return [OK200, true, 0, 0];
-		if(ret < 0 ) {
-			if( errno == EAGAIN || errno == EWOULDBLOCK) continue READ;
-			if( errno == ECONNRESET ) return [E408, true, 0, 0];
-			if( errno == EPIPE ) return [E408, true, 0, 0];
-			abort( "read error: (%d) %s\n", (int)errno, strerror(errno) );
-		}
-		it[ret + 1] = '\0';
-		rlen += ret;
-
-		if( strstr( it, "\r\n\r\n" ) ) break;
-
-		it += ret;
-		count -= ret;
-
-		if( count < 1 ) return [E414, false, 0, 0];
-	}
-
-	if( options.log ) {
-		write(sout, buffer, rlen);
-		sout | nl;
-	}
-
-	it = buffer;
-	int ret = memcmp(it, "GET /", 5);
-	if( ret != 0 ) return [E400, false, 0, 0];
-	it += 5;
-
-	char * end = strstr( it, " " );
-	return [OK200, false, it, end - it];
-}
-
-int sendfile( int pipe[2], int fd, int ans_fd, size_t count ) {
+static int sendfile( int pipe[2], int fd, int ans_fd, size_t count ) {
 	unsigned sflags = SPLICE_F_MOVE; // | SPLICE_F_MORE;
 	off_t offset = 0;
@@ -207,4 +173,367 @@
 }
 
+static void zero_sqe(struct io_uring_sqe * sqe) {
+	sqe->flags = 0;
+	sqe->ioprio = 0;
+	sqe->fd = 0;
+	sqe->off = 0;
+	sqe->addr = 0;
+	sqe->len = 0;
+	sqe->fsync_flags = 0;
+	sqe->__pad2[0] = 0;
+	sqe->__pad2[1] = 0;
+	sqe->__pad2[2] = 0;
+	sqe->fd = 0;
+	sqe->off = 0;
+	sqe->addr = 0;
+	sqe->len = 0;
+}
+
+enum FSM_STATE {
+	Initial,
+	Retry,
+	Error,
+	Done,
+};
+
+struct FSM_Result {
+	FSM_STATE state;
+	int error;
+};
+
+static inline void ?{}(FSM_Result & this) { this.state = Initial; this.error = 0; }
+static inline bool is_error(FSM_Result & this) { return Error == this.state; }
+static inline bool is_done(FSM_Result & this) { return Done == this.state; }
+
+static inline int error(FSM_Result & this, int error) {
+	this.error = error;
+	this.state = Error;
+	return error;
+}
+
+static inline int done(FSM_Result & this) {
+	this.state = Done;
+	return 0;
+}
+
+static inline int retry(FSM_Result & this) {
+	this.state = Retry;
+	return 0;
+}
+
+static inline int need(FSM_Result & this) {
+	switch(this.state) {
+		case Initial:
+		case Retry:
+			return 1;
+		case Error:
+			if(this.error == 0) mutex(serr) serr | "State marked error but code is 0";
+		case Done:
+			return 0;
+	}
+}
+
+// Generator that handles sending the header
+generator header_g {
+	io_future_t f;
+	const char * next;
+	int fd; size_t len;
+	FSM_Result res;
+};
+
+static inline void ?{}(header_g & this, int fd, const char * it, size_t len ) {
+	this.next = it;
+	this.fd = fd;
+	this.len = len;
+}
+
+static inline void fill(header_g & this, struct io_uring_sqe * sqe) {
+	zero_sqe(sqe);
+	sqe->opcode = IORING_OP_SEND;
+	sqe->user_data = (uintptr_t)&this.f;
+	sqe->flags = IOSQE_IO_LINK;
+	sqe->fd = this.fd;
+	sqe->addr = (uintptr_t)this.next;
+	sqe->len = this.len;
+}
+
+static inline int error(header_g & this, int error) {
+	int ret = close(this.fd);
+	if( ret != 0 ) {
+		mutex(serr) serr | "Failed to close fd" | errno;
+	}
+	return error(this.res, error);
+}
+
+static inline int wait_and_process(header_g & this) {
+	wait(this.f);
+
+	// Did something crazy happen?
+	if(this.f.result > this.len) {
+		mutex(serr) serr | "HEADER sent too much!";
+		return error(this, -ERANGE);
+	}
+
+	// Something failed?
+	if(this.f.result < 0) {
+		int error = -this.f.result;
+		if( error == ECONNRESET ) return error(this, -ECONNRESET);
+		if( error == EPIPE ) return error(this, -EPIPE);
+		if( error == ECANCELED ) {
+			mutex(serr) serr | "HEADER was cancelled, WTF!";
+			return error(this, -ECONNRESET);
+		}
+		if( error == EAGAIN || error == EWOULDBLOCK) {
+			mutex(serr) serr | "HEADER got eagain, WTF!";
+			return error(this, -ECONNRESET);
+		}
+	}
+
+	// Done?
+	if(this.f.result == this.len) {
+		return done(this.res);
+	}
+
+	// It must be a Short read
+	this.len  -= this.f.result;
+	this.next += this.f.result;
+	reset(this.f);
+	return retry(this.res);
+}
+
+// Generator that handles splicing in a file
+struct splice_in_t {
+	io_future_t f;
+	int fd; int pipe; size_t len; off_t off;
+	FSM_Result res;
+};
+
+static inline void ?{}(splice_in_t & this, int fd, int pipe, size_t len) {
+	this.fd = fd;
+	this.pipe = pipe;
+	this.len = len;
+	this.off = 0;
+}
+
+static inline void fill(splice_in_t & this, struct io_uring_sqe * sqe) {
+	zero_sqe(sqe);
+	sqe->opcode = IORING_OP_SPLICE;
+	sqe->user_data = (uintptr_t)&this.f;
+	sqe->flags = 0;
+	sqe->splice_fd_in = this.fd;
+	sqe->splice_off_in = this.off;
+	sqe->fd = this.pipe;
+	sqe->off = (__u64)-1;
+	sqe->len = this.len;
+	sqe->splice_flags = SPLICE_F_MOVE;
+}
+
+static inline int wait_and_process(splice_in_t & this) {
+	wait(this.f);
+
+	// Did something crazy happen?
+	if(this.f.result > this.len) {
+		mutex(serr) serr | "SPLICE IN spliced too much!";
+		return error(this.res, -ERANGE);
+	}
+
+	// Something failed?
+	if(this.f.result < 0) {
+		int error = -this.f.result;
+		if( error == ECONNRESET ) return error(this.res, -ECONNRESET);
+		if( error == EPIPE ) return error(this.res, -EPIPE);
+		if( error == ECANCELED ) {
+			mutex(serr) serr | "SPLICE IN was cancelled, WTF!";
+			return error(this.res, -ECONNRESET);
+		}
+		if( error == EAGAIN || error == EWOULDBLOCK) {
+			mutex(serr) serr | "SPLICE IN got eagain, WTF!";
+			return error(this.res, -ECONNRESET);
+		}
+	}
+
+	// Done?
+	if(this.f.result == this.len) {
+		return done(this.res);
+	}
+
+	// It must be a Short read
+	this.len -= this.f.result;
+	this.off += this.f.result;
+	reset(this.f);
+	return retry(this.res);
+}
+
+generator splice_out_g {
+	io_future_t f;
+	int pipe; int fd; size_t len;
+	FSM_Result res;
+};
+
+static inline void ?{}(splice_out_g & this, int pipe, int fd, size_t len) {
+	this.pipe = pipe;
+	this.fd = fd;
+	this.len = len;
+}
+
+static inline void fill(splice_out_g & this, struct io_uring_sqe * sqe) {
+	zero_sqe(sqe);
+	sqe->opcode = IORING_OP_SPLICE;
+	sqe->user_data = (uintptr_t)&this.f;
+	sqe->flags = 0;
+	sqe->splice_fd_in = this.pipe;
+	sqe->splice_off_in = (__u64)-1;
+	sqe->fd = this.fd;
+	sqe->off = (__u64)-1;
+	sqe->len = this.len;
+	sqe->splice_flags = SPLICE_F_MOVE;
+}
+
+static inline int error(splice_out_g & this, int error) {
+	int ret = close(this.fd);
+	if( ret != 0 ) {
+		mutex(serr) serr | "Failed to close fd" | errno;
+	}
+	return error(this.res, error);
+}
+
+static inline void wait_and_process(splice_out_g & this) {
+	wait(this.f);
+
+	// Did something crazy happen?
+	if(this.f.result > this.len) {
+		mutex(serr) serr | "SPLICE OUT spliced too much!";
+		return error(this.res, -ERANGE);
+	}
+
+	// Something failed?
+	if(this.f.result < 0) {
+		int error = -this.f.result;
+		if( error == ECONNRESET ) return error(this, -ECONNRESET);
+		if( error == EPIPE ) return error(this, -EPIPE);
+		if( error == ECANCELED ) {
+			this.f.result = 0;
+			goto SHORT_WRITE;
+		}
+		if( error == EAGAIN || error == EWOULDBLOCK) {
+			mutex(serr) serr | "SPLICE OUT got eagain, WTF!";
+			return error(this, -ECONNRESET);
+		}
+	}
+
+	// Done?
+	if(this.f.result == this.len) {
+		return done(this.res);
+	}
+
+SHORT_WRITE:
+	// It must be a Short Write
+	this.len -= this.f.result;
+	reset(this.f);
+	return retry(this.res);
+}
+
+int answer_sendfile( int pipe[2], int fd, int ans_fd, size_t fsize ) {
+	#if defined(LINKED_IO)
+		char buffer[512];
+		int len = fill_header(buffer, fsize);
+		header_g header = { fd, buffer, len };
+		splice_in_t splice_in = { ans_fd, pipe[1], fsize };
+		splice_out_g splice_out = { pipe[0], fd, fsize };
+
+		RETRY_LOOP: for() {
+			int have = need(header.res) + need(splice_in.res) + 1;
+			int idx = 0;
+			struct io_uring_sqe * sqes[3];
+			__u32 idxs[3];
+			struct $io_context * ctx = cfa_io_allocate(sqes, idxs, have);
+
+			if(need(splice_in.res)) { fill(splice_in, sqes[idx++]); }
+			if(need(   header.res)) { fill(header   , sqes[idx++]); }
+			fill(splice_out, sqes[idx]);
+
+			// Submit everything
+			asm volatile("": : :"memory");
+			cfa_io_submit( ctx, idxs, have, false );
+
+			// wait for the results
+			// Always wait for splice-in to complete as
+			// we may need to kill the connection if it fails
+			// If it already completed, this is a no-op
+			wait_and_process(splice_in);
+
+			if(is_error(splice_in.res)) {
+				mutex(serr) serr | "SPLICE IN failed with" | splice_in.res.error;
+				close(fd);
+			}
+
+			// Process the other 2
+			wait_and_process(header);
+			wait_and_process(splice_out);
+
+			if(is_done(splice_out.res)) {
+				break RETRY_LOOP;
+			}
+
+			// We need to wait for the completion if
+			// - both completed
+			// - the header failed
+			// -
+
+			if(  is_error(header.res)
+			  || is_error(splice_in.res)
+			  || is_error(splice_out.res)) {
+				return -ECONNRESET;
+			}
+		}
+
+		return len + fsize;
+	#else
+		int ret = answer_header(fd, fsize);
+		if( ret < 0 ) { close(fd); return ret; }
+		return sendfile(pipe, fd, ans_fd, fsize);
+	#endif
+}
+
+[HttpCode code, bool closed, * const char file, size_t len] http_read(int fd, []char buffer, size_t len) {
+	char * it = buffer;
+	size_t count = len - 1;
+	int rlen = 0;
+	READ:
+	for() {
+		int ret = cfa_recv(fd, (void*)it, count, 0, CFA_IO_LAZY);
+		// int ret = read(fd, (void*)it, count);
+		if(ret == 0 ) return [OK200, true, 0, 0];
+		if(ret < 0 ) {
+			if( errno == EAGAIN || errno == EWOULDBLOCK) continue READ;
+			if( errno == ECONNRESET ) { close(fd); return [E408, true, 0, 0]; }
+			if( errno == EPIPE ) { close(fd); return [E408, true, 0, 0]; }
+			abort( "read error: (%d) %s\n", (int)errno, strerror(errno) );
+		}
+		it[ret + 1] = '\0';
+		rlen += ret;
+
+		if( strstr( it, "\r\n\r\n" ) ) break;
+
+		it += ret;
+		count -= ret;
+
+		if( count < 1 ) return [E414, false, 0, 0];
+	}
+
+	if( options.log ) {
+		write(sout, buffer, rlen);
+		sout | nl;
+	}
+
+	it = buffer;
+	int ret = memcmp(it, "GET /", 5);
+	if( ret != 0 ) return [E400, false, 0, 0];
+	it += 5;
+
+	char * end = strstr( it, " " );
+	return [OK200, false, it, end - it];
+}
+
 //=============================================================================================
 
@@ -214,12 +543,12 @@
 
 const char * original_http_msgs[] = {
-	"HTTP/1.1 200 OK\nServer: HttoForall\nDate: %s \nContent-Type: text/plain\nContent-Length: ",
-	"HTTP/1.1 200 OK\nServer: HttoForall\nDate: %s \nContent-Type: text/plain\nContent-Length: 15\n\nHello, World!\n\n",
-	"HTTP/1.1 400 Bad Request\nServer: HttoForall\nDate: %s \nContent-Type: text/plain\nContent-Length: 0 \n\n",
-	"HTTP/1.1 404 Not Found\nServer: HttoForall\nDate: %s \nContent-Type: text/plain\nContent-Length: 0 \n\n",
-	"HTTP/1.1 405 Method Not Allowed\nServer: HttoForall\nDate: %s \nContent-Type: text/plain\nContent-Length: 0 \n\n",
-	"HTTP/1.1 408 Request Timeout\nServer: HttoForall\nDate: %s \nContent-Type: text/plain\nContent-Length: 0 \n\n",
-	"HTTP/1.1 413 Payload Too Large\nServer: HttoForall\nDate: %s \nContent-Type: text/plain\nContent-Length: 0 \n\n",
-	"HTTP/1.1 414 URI Too Long\nServer: HttoForall\nDate: %s \nContent-Type: text/plain\nContent-Length: 0 \n\n",
+	"HTTP/1.1 200 OK\nServer: HttpForall\nDate: %s \nContent-Type: text/plain\nContent-Length: ",
+	"HTTP/1.1 200 OK\r\nServer: HttpForall\r\nDate\r\nConnection: keep-alive\r\nContent-Length: 15\r\nContent-Type: text/html: %s \r\n\r\nHello, World!\r\n",
+	"HTTP/1.1 400 Bad Request\nServer: HttpForall\nDate: %s \nContent-Type: text/plain\nContent-Length: 0 \n\n",
+	"HTTP/1.1 404 Not Found\nServer: HttpForall\nDate: %s \nContent-Type: text/plain\nContent-Length: 0 \n\n",
+	"HTTP/1.1 405 Method Not Allowed\nServer: HttpForall\nDate: %s \nContent-Type: text/plain\nContent-Length: 0 \n\n",
+	"HTTP/1.1 408 Request Timeout\nServer: HttpForall\nDate: %s \nContent-Type: text/plain\nContent-Length: 0 \n\n",
+	"HTTP/1.1 413 Payload Too Large\nServer: HttpForall\nDate: %s \nContent-Type: text/plain\nContent-Length: 0 \n\n",
+	"HTTP/1.1 414 URI Too Long\nServer: HttpForall\nDate: %s \nContent-Type: text/plain\nContent-Length: 0 \n\n",
 };
 
@@ -251,5 +580,5 @@
 		Time now = timeHiRes();
 		strftime( buff, 100, "%a, %d %b %Y %H:%M:%S %Z", now );
-		sout | "Updated date to '" | buff | "'";
+		// if( options.log ) sout | "Updated date to '" | buff | "'";
 
 		for(i; KNOWN_CODES) {
@@ -264,5 +593,5 @@
 		this.idx = (this.idx + 1) % 2;
 
-		sout | "Date thread sleeping";
+		// if( options.log ) sout | "Date thread sleeping";
 
 		sleep(1`s);
Index: benchmark/io/http/protocol.hfa
===================================================================
--- benchmark/io/http/protocol.hfa	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ benchmark/io/http/protocol.hfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -16,9 +16,7 @@
 
 int answer_error( int fd, HttpCode code );
-int answer_header( int fd, size_t size );
 int answer_plaintext( int fd );
 int answer_empty( int fd );
+int answer_sendfile( int pipe[2], int fd, int ans_fd, size_t count );
 
 [HttpCode code, bool closed, * const char file, size_t len] http_read(int fd, []char buffer, size_t len);
-
-int sendfile( int pipe[2], int fd, int ans_fd, size_t count );
Index: benchmark/io/http/worker.cfa
===================================================================
--- benchmark/io/http/worker.cfa	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ benchmark/io/http/worker.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -122,10 +122,6 @@
 			}
 
-			// Send the header
-			int ret = answer_header(fd, count);
-			if( ret == -ECONNRESET ) break REQUEST;
-
 			// Send the desired file
-			ret = sendfile( this.pipe, fd, ans_fd, count);
+			int ret = answer_sendfile( this.pipe, fd, ans_fd, count);
 			if( ret == -ECONNRESET ) break REQUEST;
 
@@ -134,5 +130,4 @@
 
 		if( options.log ) sout | "=== Connection closed ===";
-		close(fd);
 		continue CONNECTION;
 	}
Index: benchmark/mutexStmt/JavaThread.java
===================================================================
--- benchmark/mutexStmt/JavaThread.java	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
+++ benchmark/mutexStmt/JavaThread.java	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -0,0 +1,64 @@
+public class JavaThread {
+	// Simplistic low-quality Marsaglia Shift-XOR pseudo-random number generator.
+	// Bijective
+	// Cycle length for non-zero values is 4G-1.
+	// 0 is absorbing and should be avoided -- fixed point.
+	// The returned value is typically masked to produce a positive value.
+	static volatile int Ticket = 0 ;
+
+	private static int nextRandom (int x) {
+		if (x == 0) {
+			// reseed the PRNG
+			// Ticket is accessed infrequently and does not constitute a coherence hot-spot.
+			// Note that we use a non-atomic racy increment -- the race is rare and benign.
+			// If the race is a concern switch to an AtomicInteger.
+			// In addition accesses to the RW volatile global "Ticket"  variable are not
+			// (readily) predictable at compile-time so the JIT will not be able to elide
+			// nextRandom() invocations.
+			x = ++Ticket ;
+			if (x == 0) x = 1 ;
+		}
+		x ^= x << 6;
+		x ^= x >>> 21;
+		x ^= x << 7;
+		return x ;
+	}
+	static int x = 2;
+
+	static private long times = Long.parseLong("100000000");
+
+	public static void helper() throws InterruptedException {
+		JavaThread j = new JavaThread();
+		// Inhibit biased locking ...
+		x = (j.hashCode() ^ System.identityHashCode(j)) | 1 ;
+		for(long i = 1; i <= times; i += 1) {
+			x = nextRandom(x);
+			synchronized( j ) {
+                x = nextRandom( x );
+            }
+		}
+	}
+
+	public static void InnerMain() throws InterruptedException {
+		long start = System.nanoTime();
+		helper();
+		long end = System.nanoTime();
+		System.out.println( (end - start) / times );
+	}
+    
+	public static void main(String[] args) throws InterruptedException {
+		if ( args.length > 1 ) System.exit( 1 );
+		if ( args.length == 1 ) { times = Long.parseLong(args[0]); }
+
+		//for (int n = Integer.parseInt("5"); --n >= 0 ; ) {
+			InnerMain();
+			Thread.sleep(2000);     // 2 seconds
+			x = nextRandom(x);
+		//}
+		if ( x == 0 ) System.out.println(x);
+	}
+}
+
+// Local Variables: //
+// tab-width: 4 //
+// End: //
Index: benchmark/mutexStmt/cpp1.cc
===================================================================
--- benchmark/mutexStmt/cpp1.cc	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
+++ benchmark/mutexStmt/cpp1.cc	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -0,0 +1,21 @@
+#include <cstdio>
+#include <mutex>
+#include "bench.h"
+#include "cppLock.hpp"
+
+cpp_test_spinlock l1;
+
+int main( int argc, char * argv[] ) {
+	BENCH_START()
+	BENCH(
+		for ( size_t i = 0; i < times; i++ ) {
+			std::scoped_lock lock(l1);
+		},
+		result
+	)
+	printf( "%g\n", result );
+}
+
+// Local Variables: //
+// tab-width: 4 //
+// End: //
Index: benchmark/mutexStmt/cpp2.cc
===================================================================
--- benchmark/mutexStmt/cpp2.cc	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
+++ benchmark/mutexStmt/cpp2.cc	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -0,0 +1,21 @@
+#include <cstdio>
+#include <mutex>
+#include "bench.h"
+#include "cppLock.hpp"
+
+cpp_test_spinlock l1, l2;
+
+int main( int argc, char * argv[] ) {
+	BENCH_START()
+	BENCH(
+		for ( size_t i = 0; i < times; i++ ) {
+			std::scoped_lock lock(l1, l2);
+		},
+		result
+	)
+	printf( "%g\n", result );
+}
+
+// Local Variables: //
+// tab-width: 4 //
+// End: //
Index: benchmark/mutexStmt/cpp4.cc
===================================================================
--- benchmark/mutexStmt/cpp4.cc	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
+++ benchmark/mutexStmt/cpp4.cc	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -0,0 +1,21 @@
+#include <cstdio>
+#include <mutex>
+#include "bench.h"
+#include "cppLock.hpp"
+
+cpp_test_spinlock l1, l2, l3, l4;
+
+int main( int argc, char * argv[] ) {
+	BENCH_START()
+	BENCH(
+		for ( size_t i = 0; i < times; i++ ) {
+			std::scoped_lock lock(l1, l2, l3, l4);
+		},
+		result
+	)
+	printf( "%g\n", result );
+}
+
+// Local Variables: //
+// tab-width: 4 //
+// End: //
Index: benchmark/mutexStmt/cpp8.cc
===================================================================
--- benchmark/mutexStmt/cpp8.cc	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
+++ benchmark/mutexStmt/cpp8.cc	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -0,0 +1,21 @@
+#include <cstdio>
+#include <mutex>
+#include "bench.h"
+#include "cppLock.hpp"
+
+cpp_test_spinlock l1, l2, l3, l4, l5, l6, l7, l8;
+
+int main( int argc, char * argv[] ) {
+	BENCH_START()
+	BENCH(
+		for ( size_t i = 0; i < times; i++ ) {
+			std::scoped_lock lock(l1, l2, l3, l4, l5, l6, l7, l8);
+		},
+		result
+	)
+	printf( "%g\n", result );
+}
+
+// Local Variables: //
+// tab-width: 4 //
+// End: //
Index: benchmark/mutexStmt/cppLock.hpp
===================================================================
--- benchmark/mutexStmt/cppLock.hpp	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
+++ benchmark/mutexStmt/cppLock.hpp	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -0,0 +1,18 @@
+class cpp_test_spinlock {
+	volatile bool lockBool = 0;
+
+  public:
+	inline void lock() {
+		for ( ;; ) {
+			if ( (this->lockBool == 0) && (__atomic_test_and_set( &this->lockBool, __ATOMIC_ACQUIRE ) == 0) ) break;
+		}
+	}
+
+	inline bool try_lock() {
+		return (this->lockBool == 0) && (__atomic_test_and_set( &this->lockBool, __ATOMIC_ACQUIRE ) == 0);
+	}
+
+	inline void unlock() {
+		__atomic_clear( &this->lockBool, __ATOMIC_RELEASE );
+	}
+};
Index: benchmark/mutexStmt/lock1.cfa
===================================================================
--- benchmark/mutexStmt/lock1.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
+++ benchmark/mutexStmt/lock1.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -0,0 +1,22 @@
+#include <locks.hfa>
+#include <mutex_stmt.hfa>
+#include <stdio.h>
+
+#include "bench.h"
+
+test_spinlock l1;
+
+int main( int argc, char * argv[] ) {
+	BENCH_START()
+	BENCH(
+		for ( times ) {
+			mutex ( l1 ) { }
+		},
+		result
+	)
+	printf( "%g\n", result );
+}
+
+// Local Variables: //
+// tab-width: 4 //
+// End: //
Index: benchmark/mutexStmt/lock2.cfa
===================================================================
--- benchmark/mutexStmt/lock2.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
+++ benchmark/mutexStmt/lock2.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -0,0 +1,22 @@
+#include <locks.hfa>
+#include <mutex_stmt.hfa>
+#include <stdio.h>
+
+#include "bench.h"
+
+test_spinlock l1, l2;
+
+int main( int argc, char * argv[] ) {
+	BENCH_START()
+	BENCH(
+		for ( times ) {
+			mutex ( l1, l2 ) { }
+		},
+		result
+	)
+	printf( "%g\n", result );
+}
+
+// Local Variables: //
+// tab-width: 4 //
+// End: //
Index: benchmark/mutexStmt/lock4.cfa
===================================================================
--- benchmark/mutexStmt/lock4.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
+++ benchmark/mutexStmt/lock4.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -0,0 +1,22 @@
+#include <locks.hfa>
+#include <mutex_stmt.hfa>
+#include <stdio.h>
+
+#include "bench.h"
+
+test_spinlock l1, l2, l3, l4;
+
+int main( int argc, char * argv[] ) {
+	BENCH_START()
+	BENCH(
+		for ( times ) {
+			mutex ( l1, l2, l3, l4 ) { }
+		},
+		result
+	)
+	printf( "%g\n", result );
+}
+
+// Local Variables: //
+// tab-width: 4 //
+// End: //
Index: benchmark/mutexStmt/lock8.cfa
===================================================================
--- benchmark/mutexStmt/lock8.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
+++ benchmark/mutexStmt/lock8.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -0,0 +1,22 @@
+#include <locks.hfa>
+#include <mutex_stmt.hfa>
+#include <stdio.h>
+
+#include "bench.h"
+
+test_spinlock l1, l2, l3, l4, l5, l6, l7, l8;
+
+int main( int argc, char * argv[] ) {
+	BENCH_START()
+	BENCH(
+		for ( times ) {
+			mutex ( l1, l2, l3, l4, l5, l6, l7, l8 ) { }
+		},
+		result
+	)
+	printf( "%g\n", result );
+}
+
+// Local Variables: //
+// tab-width: 4 //
+// End: //
Index: benchmark/mutexStmt/monitor1.cfa
===================================================================
--- benchmark/mutexStmt/monitor1.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
+++ benchmark/mutexStmt/monitor1.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -0,0 +1,22 @@
+#include <monitor.hfa>
+#include <mutex_stmt.hfa>
+#include <stdio.h>
+
+#include "bench.h"
+
+monitor M {} m1;
+
+int main( int argc, char * argv[] ) {
+	BENCH_START()
+	BENCH(
+		for ( times ) {
+			mutex ( m1 ) { }
+		},
+		result
+	)
+	printf( "%g\n", result );
+}
+
+// Local Variables: //
+// tab-width: 4 //
+// End: //
Index: benchmark/mutexStmt/monitor2.cfa
===================================================================
--- benchmark/mutexStmt/monitor2.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
+++ benchmark/mutexStmt/monitor2.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -0,0 +1,22 @@
+#include <monitor.hfa>
+#include <mutex_stmt.hfa>
+#include <stdio.h>
+
+#include "bench.h"
+
+monitor M {} m1, m2;
+
+int main( int argc, char * argv[] ) {
+	BENCH_START()
+	BENCH(
+		for ( times ) {
+			mutex( m1, m2 ) { }
+		},
+		result
+	)
+	printf( "%g\n", result );
+}
+
+// Local Variables: //
+// tab-width: 4 //
+// End: //
Index: benchmark/mutexStmt/monitor4.cfa
===================================================================
--- benchmark/mutexStmt/monitor4.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
+++ benchmark/mutexStmt/monitor4.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -0,0 +1,22 @@
+#include <monitor.hfa>
+#include <mutex_stmt.hfa>
+#include <stdio.h>
+
+#include "bench.h"
+
+monitor M {} m1, m2, m3, m4;
+
+int main( int argc, char * argv[] ) {
+	BENCH_START()
+	BENCH(
+		for ( times ) {
+			mutex( m1, m2, m3, m4 ) { }
+		},
+		result
+	)
+	printf( "%g\n", result );
+}
+
+// Local Variables: //
+// tab-width: 4 //
+// End: //
Index: benchmark/mutexStmt/no_stmt_lock1.cfa
===================================================================
--- benchmark/mutexStmt/no_stmt_lock1.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
+++ benchmark/mutexStmt/no_stmt_lock1.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -0,0 +1,23 @@
+#include <locks.hfa>
+#include <mutex_stmt.hfa>
+#include <stdio.h>
+
+#include "bench.h"
+
+test_spinlock l1;
+
+int main( int argc, char * argv[] ) {
+	BENCH_START()
+	BENCH(
+		for ( times ) {
+			lock( l1 );
+            unlock( l1 );
+		},
+		result
+	)
+	printf( "%g\n", result );
+}
+
+// Local Variables: //
+// tab-width: 4 //
+// End: //
Index: benchmark/mutexStmt/no_stmt_lock2.cfa
===================================================================
--- benchmark/mutexStmt/no_stmt_lock2.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
+++ benchmark/mutexStmt/no_stmt_lock2.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -0,0 +1,25 @@
+#include <locks.hfa>
+#include <mutex_stmt.hfa>
+#include <stdio.h>
+
+#include "bench.h"
+
+test_spinlock l1, l2;
+
+int main( int argc, char * argv[] ) {
+	BENCH_START()
+	BENCH(
+		for ( times ) {
+			lock( l1 );
+            lock( l2 ); 
+            unlock( l2 );
+            unlock( l1 );
+		},
+		result
+	)
+	printf( "%g\n", result );
+}
+
+// Local Variables: //
+// tab-width: 4 //
+// End: //
Index: benchmark/mutexStmt/no_stmt_lock4.cfa
===================================================================
--- benchmark/mutexStmt/no_stmt_lock4.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
+++ benchmark/mutexStmt/no_stmt_lock4.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -0,0 +1,29 @@
+#include <locks.hfa>
+#include <mutex_stmt.hfa>
+#include <stdio.h>
+
+#include "bench.h"
+
+test_spinlock l1, l2, l3, l4;
+
+int main( int argc, char * argv[] ) {
+	BENCH_START()
+	BENCH(
+		for ( times ) {
+			lock( l1 );
+            lock( l2 );
+            lock( l3 );
+            lock( l4 ); 
+            unlock( l4 );
+            unlock( l3 );
+            unlock( l2 );
+            unlock( l1 );
+		},
+		result
+	)
+	printf( "%g\n", result );
+}
+
+// Local Variables: //
+// tab-width: 4 //
+// End: //
Index: benchmark/mutexStmt/no_stmt_lock8.cfa
===================================================================
--- benchmark/mutexStmt/no_stmt_lock8.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
+++ benchmark/mutexStmt/no_stmt_lock8.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -0,0 +1,37 @@
+#include <locks.hfa>
+#include <mutex_stmt.hfa>
+#include <stdio.h>
+
+#include "bench.h"
+
+test_spinlock l1, l2, l3, l4, l5, l6, l7, l8;
+
+int main( int argc, char * argv[] ) {
+	BENCH_START()
+	BENCH(
+		for ( times ) {
+			lock( l1 );
+            lock( l2 );
+            lock( l3 );
+            lock( l4 );
+            lock( l5 );
+            lock( l6 );
+            lock( l7 );
+            lock( l8 ); 
+            unlock( l8 );
+            unlock( l7 );
+            unlock( l6 );
+            unlock( l5 );
+            unlock( l4 );
+            unlock( l3 );
+            unlock( l2 );
+            unlock( l1 );
+		},
+		result
+	)
+	printf( "%g\n", result );
+}
+
+// Local Variables: //
+// tab-width: 4 //
+// End: //
Index: benchmark/readyQ/cycle.cpp
===================================================================
--- benchmark/readyQ/cycle.cpp	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ benchmark/readyQ/cycle.cpp	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -41,9 +41,9 @@
 			Fibre * threads[tthreads];
 			Partner thddata[tthreads];
-			for(int i = 0; i < tthreads; i++) {
+			for(unsigned i = 0; i < tthreads; i++) {
 				unsigned pi = (i + nthreads) % tthreads;
 				thddata[i].next = &thddata[pi].self;
 			}
-			for(int i = 0; i < tthreads; i++) {
+			for(unsigned i = 0; i < tthreads; i++) {
 				threads[i] = new Fibre( reinterpret_cast<void (*)(void *)>(partner_main), &thddata[i] );
 			}
@@ -53,5 +53,5 @@
 			start = timeHiRes();
 
-			for(int i = 0; i < nthreads; i++) {
+			for(unsigned i = 0; i < nthreads; i++) {
 				thddata[i].self.post();
 			}
@@ -62,5 +62,5 @@
 			printf("\nDone\n");
 
-			for(int i = 0; i < tthreads; i++) {
+			for(unsigned i = 0; i < tthreads; i++) {
 				thddata[i].self.post();
 				fibre_join( threads[i], nullptr );
Index: benchmark/readyQ/cycle.go
===================================================================
--- benchmark/readyQ/cycle.go	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ benchmark/readyQ/cycle.go	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -60,5 +60,5 @@
 	atomic.StoreInt32(&stop, 1)
 	end := time.Now()
-	delta := end.Sub(start)
+	duration := end.Sub(start)
 
 	fmt.Printf("\nDone\n")
@@ -74,15 +74,15 @@
 
 	p := message.NewPrinter(language.English)
-	p.Printf("Duration (ms)        : %f\n", delta.Seconds());
+	p.Printf("Duration (ms)        : %d\n", duration.Milliseconds())
 	p.Printf("Number of processors : %d\n", nprocs);
 	p.Printf("Number of threads    : %d\n", tthreads);
 	p.Printf("Cycle size (# thrds) : %d\n", ring_size);
 	p.Printf("Total Operations(ops): %15d\n", global_counter)
-	p.Printf("Ops per second       : %18.2f\n", float64(global_counter) / delta.Seconds())
-	p.Printf("ns per ops           : %18.2f\n", float64(delta.Nanoseconds()) / float64(global_counter))
+	p.Printf("Ops per second       : %18.2f\n", float64(global_counter) / duration.Seconds())
+	p.Printf("ns per ops           : %18.2f\n", float64(duration.Nanoseconds()) / float64(global_counter))
 	p.Printf("Ops per threads      : %15d\n", global_counter / uint64(tthreads))
 	p.Printf("Ops per procs        : %15d\n", global_counter / uint64(nprocs))
-	p.Printf("Ops/sec/procs        : %18.2f\n", (float64(global_counter) / float64(nprocs)) / delta.Seconds())
-	p.Printf("ns per ops/procs     : %18.2f\n", float64(delta.Nanoseconds()) / (float64(global_counter) / float64(nprocs)))
+	p.Printf("Ops/sec/procs        : %18.2f\n", (float64(global_counter) / float64(nprocs)) / duration.Seconds())
+	p.Printf("ns per ops/procs     : %18.2f\n", float64(duration.Nanoseconds()) / (float64(global_counter) / float64(nprocs)))
 
 }
Index: benchmark/readyQ/cycle.rs
===================================================================
--- benchmark/readyQ/cycle.rs	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ benchmark/readyQ/cycle.rs	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -46,5 +46,5 @@
 
 	let tthreads = nthreads * ring_size;
-	let exp = Arc::new(bench::BenchData::new(options, tthreads));
+	let exp = Arc::new(bench::BenchData::new(options, tthreads, None));
 
 	let s = (1000000 as u64).to_formatted_string(&Locale::en);
Index: benchmark/readyQ/locality.go
===================================================================
--- benchmark/readyQ/locality.go	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ benchmark/readyQ/locality.go	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -286,5 +286,5 @@
 	// Print with nice 's, i.e. 1'000'000 instead of 1000000
 	p := message.NewPrinter(language.English)
-	p.Printf("Duration (s)           : %f\n", delta.Seconds());
+	p.Printf("Duration (ms)          : %f\n", delta.Milliseconds());
 	p.Printf("Number of processors   : %d\n", nprocs);
 	p.Printf("Number of threads      : %d\n", nthreads);
Index: benchmark/readyQ/locality.rs
===================================================================
--- benchmark/readyQ/locality.rs	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ benchmark/readyQ/locality.rs	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -124,6 +124,6 @@
 						return (r as *mut MyData, true);
 					}
-					let got = self.ptr.compare_and_swap(expected, ctx as *mut MyCtx as u64, Ordering::SeqCst);
-					if got == expected {
+					let got = self.ptr.compare_exchange_weak(expected, ctx as *mut MyCtx as u64, Ordering::SeqCst, Ordering::SeqCst);
+					if got == Ok(expected) {
 						break expected;// We got the seat
 					}
@@ -285,5 +285,5 @@
 	assert_eq!(&s, "1,000,000");
 
-	let exp = Arc::new(bench::BenchData::new(options, nprocs));
+	let exp = Arc::new(bench::BenchData::new(options, nprocs, None));
 	let mut results = Result::new();
 
Index: benchmark/readyQ/transfer.cfa
===================================================================
--- benchmark/readyQ/transfer.cfa	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ benchmark/readyQ/transfer.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -39,4 +39,5 @@
 			Pause();
 			if( (timeHiRes() - start) > 5`s ) {
+				print_stats_now( bench_cluster, CFA_STATS_READY_Q | CFA_STATS_IO );
 				serr | "Programs has been blocked for more than 5 secs";
 				exit(1);
@@ -110,5 +111,5 @@
 	cfa_option opt[] = {
 		BENCH_OPT,
-		{ 'e', "exhaust", "Whether or not threads that have seen the new epoch should yield or park.", exhaust, parse_yesno}
+		{ 'e', "exhaust", "Whether or not threads that have seen the new epoch should park instead of yielding.", exhaust, parse_yesno}
 	};
 	BENCH_OPT_PARSE("cforall transition benchmark");
@@ -166,5 +167,5 @@
 	}
 
-	sout | "Duration                : " | ws(3, 3, unit(eng((end - start)`ds))) | 's';
+	sout | "Duration (ms)           : " | ws(3, 3, unit(eng((end - start)`dms)));
 	sout | "Number of processors    : " | nprocs;
 	sout | "Number of threads       : " | nthreads;
Index: benchmark/readyQ/transfer.cpp
===================================================================
--- benchmark/readyQ/transfer.cpp	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ benchmark/readyQ/transfer.cpp	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -173,5 +173,5 @@
 	}
 
-	std::cout << "Duration                : " << to_miliseconds(end - start) << "ms" << std::endl;
+	std::cout << "Duration (ms)           : " << to_miliseconds(end - start) << std::endl;
 	std::cout << "Number of processors    : " << nprocs << std::endl;
 	std::cout << "Number of threads       : " << nthreads << std::endl;
Index: benchmark/readyQ/transfer.go
===================================================================
--- benchmark/readyQ/transfer.go	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
+++ benchmark/readyQ/transfer.go	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -0,0 +1,223 @@
+package main
+
+import (
+	"flag"
+	"fmt"
+	"math/rand"
+	"os"
+	"runtime"
+	"sync/atomic"
+	"time"
+	"golang.org/x/text/language"
+	"golang.org/x/text/message"
+)
+
+type LeaderInfo struct {
+	id uint64
+	idx uint64
+	seed uint64
+}
+
+func __xorshift64( state * uint64 ) (uint64) {
+	x := *state
+	x ^= x << 13
+	x ^= x >> 7
+	x ^= x << 17
+	*state = x
+	return x
+}
+
+func (this * LeaderInfo) next(len uint64) {
+	n := __xorshift64( &this.seed )
+	atomic.StoreUint64( &this.id, n % len )
+}
+
+func NewLeader(size uint64) (*LeaderInfo) {
+	this := &LeaderInfo{0, 0, uint64(os.Getpid())}
+
+	r := rand.Intn(10)
+
+	for i := 0; i < r; i++ {
+		this.next( uint64(nthreads) )
+	}
+
+	return this
+}
+
+type MyThread struct {
+	id uint64
+	idx uint64
+	sem chan struct{}
+}
+
+func waitgroup(idx uint64, threads [] MyThread) {
+	start := time.Now()
+	for i := 0; i < len(threads); i++ {
+		// fmt.Fprintf(os.Stderr, "Waiting for :%d (%d)\n", threads[i].id, atomic.LoadUint64(&threads[i].idx) );
+		for atomic.LoadUint64( &threads[i].idx ) != idx {
+			// hint::spin_loop();
+			end := time.Now()
+			delta := end.Sub(start)
+			if delta.Seconds() > 5 {
+				fmt.Fprintf(os.Stderr, "Programs has been blocked for more than 5 secs")
+				os.Exit(1)
+			}
+		}
+	}
+	// debug!( "Waiting done" );
+}
+
+func wakegroup(exhaust bool, me uint64, threads [] MyThread) {
+	if !exhaust { return; }
+
+	for i := uint64(0); i < uint64(len(threads)); i++ {
+		if i != me {
+			// debug!( "Leader waking {}", i);
+			threads[i].sem <- (struct {}{})
+		}
+	}
+}
+
+func lead(exhaust bool, leader * LeaderInfo, this * MyThread, threads [] MyThread, main_sem chan struct {}) {
+	nidx := atomic.LoadUint64(&leader.idx) + 1;
+	atomic.StoreUint64(&this.idx, nidx);
+	atomic.StoreUint64(&leader.idx, nidx);
+
+	if nidx > stop_count {
+		// debug!( "Leader {} done", this.id);
+		main_sem <- (struct {}{})
+		return
+	}
+
+	// debug!( "====================\nLeader no {} : {}", nidx, this.id);
+
+	waitgroup(nidx, threads);
+
+	leader.next( uint64(len(threads)) );
+
+	wakegroup(exhaust, this.id, threads);
+
+	// debug!( "Leader no {} : {} done\n====================", nidx, this.id);
+}
+
+func waitleader(exhaust bool, leader * LeaderInfo, this * MyThread, rechecks * uint64) {
+	runtime.Gosched()
+
+	if atomic.LoadUint64(&leader.idx) == atomic.LoadUint64(&this.idx) {
+		// debug!("Waiting {} recheck", this.id);
+		*rechecks += uint64(1)
+		return
+	}
+
+	// debug!("Waiting {}", this.id);
+
+	// debug_assert!( (leader.idx.load(Ordering::Relaxed) - 1) == this.idx.load(Ordering::Relaxed) );
+	atomic.AddUint64(&this.idx, 1)
+	if exhaust {
+		// debug!("Waiting {} sem", this.id);
+		<- this.sem
+	} else {
+		// debug!("Waiting {} yield", this.id);
+		runtime.Gosched()
+	}
+
+	// debug!("Waiting {} done", this.id);
+}
+
+func transfer_main( result chan uint64, me uint64, leader * LeaderInfo, threads [] MyThread, exhaust bool, start chan struct{}, main_sem chan struct{}) {
+	// assert!( me == threads[me].id );
+
+	// debug!("Ready {}: {:p}", me, &threads[me].sem as *const sync::Semaphore);
+
+	// Wait for start
+	<- start
+
+	// debug!( "Start {}", me );
+
+	// Prepare results
+	r := uint64(0)
+
+	// Main loop
+	for true {
+		if atomic.LoadUint64(&leader.id) == me {
+			lead( exhaust, leader, &threads[me], threads, main_sem )
+			runtime.Gosched()
+		} else {
+			waitleader( exhaust, leader, &threads[me], &r )
+		}
+		if atomic.LoadUint64(&leader.idx) > stop_count { break; }
+	}
+
+	// return result
+	result <- r
+}
+
+func main() {
+	// Benchmark specific command line arguments
+	exhaustOpt := flag.Bool("e", false, "Whether or not threads that have seen the new epoch should park instead of yielding.")
+
+	// General benchmark initialization and deinitialization
+	defer bench_init()()
+
+	exhaust := *exhaustOpt;
+	if clock_mode {
+		fmt.Fprintf(os.Stderr, "Programs does not support fixed duration mode")
+		os.Exit(1)
+	}
+
+	var es string
+	if exhaust {
+		es = "with"
+	} else {
+		es = "without"
+	}
+	fmt.Printf("Running %d threads on %d processors, doing %d iterations, %s exhaustion\n", nthreads, nprocs, stop_count, es );
+
+	main_sem := make(chan struct{})
+	leader := NewLeader(uint64(nthreads))
+	barr := make(chan struct{})
+	result := make(chan uint64)
+
+	thddata := make([]MyThread, nthreads)
+	for i := range thddata {
+		thddata[i] = MyThread{ uint64(i), 0, make(chan struct {}) }
+	}
+
+	rechecks := uint64(0)
+	for i := range thddata {
+		go transfer_main(result, uint64(i), leader, thddata, exhaust, barr, main_sem)
+	}
+	fmt.Printf("Starting\n");
+
+	start := time.Now()
+	close(barr) // release barrier
+
+	<- main_sem
+
+	end := time.Now()
+	delta := end.Sub(start)
+
+	fmt.Printf("\nDone\n")
+
+	// release all the blocked threads
+	for i := range thddata {
+		close(thddata[i].sem)
+	}
+	for range thddata {
+		rechecks += <- result
+	}
+
+	p := message.NewPrinter(language.English)
+	var ws string
+	if exhaust {
+		ws = "yes"
+	} else {
+		ws = "no"
+	}
+	p.Printf("Duration (ms)           : %f\n", delta.Milliseconds() )
+	p.Printf("Number of processors    : %d\n", nprocs )
+	p.Printf("Number of threads       : %d\n", nthreads )
+	p.Printf("Total Operations(ops)   : %15d\n", stop_count )
+	p.Printf("Threads parking on wait : %s\n", ws)
+	p.Printf("Rechecking              : %d\n", rechecks )
+}
Index: benchmark/readyQ/transfer.rs
===================================================================
--- benchmark/readyQ/transfer.rs	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
+++ benchmark/readyQ/transfer.rs	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -0,0 +1,278 @@
+#[cfg(debug_assertions)]
+use std::io::{self, Write};
+
+use std::process;
+use std::option;
+use std::hint;
+use std::sync::Arc;
+use std::sync::atomic::{AtomicUsize, Ordering};
+use std::time::{Instant,Duration};
+
+use tokio::runtime::Builder;
+use tokio::sync;
+use tokio::task;
+
+use rand::Rng;
+
+use clap::{Arg, App};
+use num_format::{Locale, ToFormattedString};
+
+#[path = "../bench.rs"]
+mod bench;
+
+#[cfg(debug_assertions)]
+macro_rules! debug {
+	($x:expr) => {
+		println!( $x );
+		io::stdout().flush().unwrap();
+	};
+	($x:expr, $($more:expr),+) => {
+		println!( $x, $($more), * );
+		io::stdout().flush().unwrap();
+	};
+}
+
+#[cfg(not(debug_assertions))]
+macro_rules! debug {
+    ($x:expr   ) => { () };
+    ($x:expr, $($more:expr),+) => { () };
+}
+
+fn parse_yes_no(opt: option::Option<&str>, default: bool) -> bool {
+	match opt {
+		Some(val) => {
+			match val {
+				"yes" => true,
+				"no"  => false,
+				"maybe" | "I don't know" | "Can you repeat the question?" => {
+					eprintln!("Lines for 'Malcolm in the Middle' are not acceptable values of parameter 'exhaust'");
+					std::process::exit(1);
+				},
+				_ => {
+					eprintln!("parameter 'exhaust' must have value 'yes' or 'no', was {}", val);
+					std::process::exit(1);
+				},
+			}
+		},
+		_ => {
+			default
+		},
+	}
+}
+
+struct LeaderInfo {
+	id: AtomicUsize,
+	idx: AtomicUsize,
+	seed: u128,
+}
+
+impl LeaderInfo {
+	pub fn new(nthreads: usize) -> LeaderInfo {
+		let this = LeaderInfo{
+			id: AtomicUsize::new(nthreads),
+			idx: AtomicUsize::new(0),
+			seed: process::id() as u128
+		};
+
+		let mut rng = rand::thread_rng();
+
+		for _ in 0..rng.gen_range(0..10) {
+			this.next( nthreads );
+		}
+
+		this
+	}
+
+	pub fn next(&self, len: usize) {
+		let n = bench::_lehmer64( unsafe {
+			let r1 = &self.seed as *const u128;
+			let r2 = r1 as *mut u128;
+			&mut *r2
+		} ) as usize;
+		self.id.store( n % len , Ordering::SeqCst );
+	}
+}
+
+struct MyThread {
+	id: usize,
+	idx: AtomicUsize,
+	sem: sync::Semaphore,
+}
+
+fn waitgroup(idx: usize, threads: &Vec<Arc<MyThread>>) {
+	let start = Instant::now();
+	for t in threads {
+		debug!( "Waiting for :{} ({})", t.id, t.idx.load(Ordering::Relaxed) );
+		while t.idx.load(Ordering::Relaxed) != idx {
+			hint::spin_loop();
+			if start.elapsed() > Duration::from_secs(5) {
+				eprintln!("Programs has been blocked for more than 5 secs");
+				std::process::exit(1);
+			}
+		}
+	}
+	debug!( "Waiting done" );
+}
+
+fn wakegroup(exhaust: bool, me: usize, threads: &Vec<Arc<MyThread>>) {
+	if !exhaust { return; }
+
+	for i in 0..threads.len() {
+		if i != me {
+			debug!( "Leader waking {}", i);
+			threads[i].sem.add_permits(1);
+		}
+	}
+}
+
+fn lead(exhaust: bool, leader: &LeaderInfo, this: & MyThread, threads: &Vec<Arc<MyThread>>, main_sem: &sync::Semaphore, exp: &bench::BenchData) {
+	let nidx = leader.idx.load(Ordering::Relaxed) + 1;
+	this.idx.store(nidx, Ordering::Relaxed);
+	leader.idx.store(nidx, Ordering::Relaxed);
+
+	if nidx as u64 > exp.stop_count {
+		debug!( "Leader {} done", this.id);
+		main_sem.add_permits(1);
+		return;
+	}
+
+	debug!( "====================\nLeader no {} : {}", nidx, this.id);
+
+	waitgroup(nidx, threads);
+
+	leader.next( threads.len() );
+
+	wakegroup(exhaust, this.id, threads);
+
+	debug!( "Leader no {} : {} done\n====================", nidx, this.id);
+}
+
+async fn wait(exhaust: bool, leader: &LeaderInfo, this: &MyThread, rechecks: &mut usize) {
+	task::yield_now().await;
+
+	if leader.idx.load(Ordering::Relaxed) == this.idx.load(Ordering::Relaxed) {
+		debug!("Waiting {} recheck", this.id);
+		*rechecks += 1;
+		return;
+	}
+
+	debug!("Waiting {}", this.id);
+
+	debug_assert!( (leader.idx.load(Ordering::Relaxed) - 1) == this.idx.load(Ordering::Relaxed) );
+	this.idx.fetch_add(1, Ordering::SeqCst);
+	if exhaust {
+		debug!("Waiting {} sem", this.id);
+		this.sem.acquire().await.forget();
+	}
+	else {
+		debug!("Waiting {} yield", this.id);
+		task::yield_now().await;
+	}
+
+	debug!("Waiting {} done", this.id);
+}
+
+async fn transfer_main( me: usize, leader: Arc<LeaderInfo>, threads: Arc<Vec<Arc<MyThread>>>, exhaust: bool, start: Arc<sync::Barrier>, main_sem: Arc<sync::Semaphore>, exp: Arc<bench::BenchData>) -> usize{
+	assert!( me == threads[me].id );
+
+	debug!("Ready {}: {:p}", me, &threads[me].sem as *const sync::Semaphore);
+
+	start.wait().await;
+
+	debug!( "Start {}", me );
+
+	let mut rechecks: usize = 0;
+
+	loop {
+		if leader.id.load(Ordering::Relaxed) == me {
+			lead( exhaust, &leader, &threads[me], &threads, &main_sem, &exp );
+			task::yield_now().await;
+		}
+		else {
+			wait( exhaust, &leader, &threads[me], &mut rechecks ).await;
+		}
+		if leader.idx.load(Ordering::Relaxed) as u64 > exp.stop_count { break; }
+	}
+
+	rechecks
+}
+
+fn main() {
+	let options = App::new("Transfer Tokio")
+		.args(&bench::args())
+		.arg(Arg::with_name("exhaust")  .short("e").long("exhaust")  .takes_value(true).default_value("no").help("Whether or not threads that have seen the new epoch should park instead of yielding."))
+		.get_matches();
+
+	let exhaust  = parse_yes_no( options.value_of("exhaust"), false );
+	let nthreads = options.value_of("nthreads").unwrap().parse::<usize>().unwrap();
+	let nprocs   = options.value_of("nprocs").unwrap().parse::<usize>().unwrap();
+
+
+	let exp = Arc::new(bench::BenchData::new(options, nthreads, Some(100)));
+	if exp.clock_mode {
+		eprintln!("Programs does not support fixed duration mode");
+		std::process::exit(1);
+	}
+
+	println!("Running {} threads on {} processors, doing {} iterations, {} exhaustion", nthreads, nprocs, exp.stop_count, if exhaust { "with" } else { "without" });
+
+	let s = (1000000 as u64).to_formatted_string(&Locale::en);
+	assert_eq!(&s, "1,000,000");
+
+	let main_sem = Arc::new(sync::Semaphore::new(0));
+	let leader = Arc::new(LeaderInfo::new(nthreads));
+	let barr = Arc::new(sync::Barrier::new(nthreads + 1));
+	let thddata : Arc<Vec<Arc<MyThread>>> = Arc::new(
+		(0..nthreads).map(|i| {
+			Arc::new(MyThread{
+				id: i,
+				idx: AtomicUsize::new(0),
+				sem: sync::Semaphore::new(0),
+			})
+		}).collect()
+	);
+
+	let mut rechecks: usize = 0;
+	let mut duration : std::time::Duration = std::time::Duration::from_secs(0);
+
+	let runtime = Builder::new_multi_thread()
+		.worker_threads(nprocs)
+		.enable_all()
+		.build()
+		.unwrap();
+
+	runtime.block_on(async {
+		let threads: Vec<_> = (0..nthreads).map(|i| {
+			tokio::spawn(transfer_main(i, leader.clone(), thddata.clone(), exhaust, barr.clone(), main_sem.clone(), exp.clone()))
+		}).collect();
+		println!("Starting");
+
+		let start = Instant::now();
+
+		barr.wait().await;
+		debug!("Unlocked all");
+
+
+		main_sem.acquire().await.forget();
+
+		duration = start.elapsed();
+
+		println!("\nDone");
+
+
+		for i in 0..nthreads {
+			thddata[i].sem.add_permits(1);
+		}
+
+		for t in threads {
+			rechecks += t.await.unwrap();
+		}
+	});
+
+	println!("Duration (ms)           : {}", (duration.as_millis()).to_formatted_string(&Locale::en));
+	println!("Number of processors    : {}", (nprocs).to_formatted_string(&Locale::en));
+	println!("Number of threads       : {}", (nthreads).to_formatted_string(&Locale::en));
+	println!("Total Operations(ops)   : {:>15}", (exp.stop_count).to_formatted_string(&Locale::en));
+	println!("Threads parking on wait : {}", if exhaust { "yes" } else { "no" });
+	println!("Rechecking              : {}", rechecks );
+}
Index: benchmark/readyQ/yield.cfa
===================================================================
--- benchmark/readyQ/yield.cfa	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ benchmark/readyQ/yield.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -80,8 +80,10 @@
 		}
 
-		printf("Took %'ld ms\n", (end - start)`ms);
+		printf("Duration (ms)       : %'ld\n", (end - start)`dms);
+		printf("Number of processors: %'d\n", nprocs);
+		printf("Number of threads   : %'d\n", nthreads);
+		printf("Total yields        : %'15llu\n", global_counter);
 		printf("Yields per second   : %'18.2lf\n", ((double)global_counter) / (end - start)`s);
 		printf("ns per yields       : %'18.2lf\n", ((double)(end - start)`ns) / global_counter);
-		printf("Total yields        : %'15llu\n", global_counter);
 		printf("Yields per procs    : %'15llu\n", global_counter / nprocs);
 		printf("Yields/sec/procs    : %'18.2lf\n", (((double)global_counter) / nprocs) / (end - start)`s);
Index: benchmark/readyQ/yield.cpp
===================================================================
--- benchmark/readyQ/yield.cpp	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ benchmark/readyQ/yield.cpp	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -154,6 +154,7 @@
 
 		auto dur_nano = duration_cast<std::nano>(duration);
+		auto dur_dms  = duration_cast<std::milli>(duration);
 
-		std::cout << "Took " << duration << " s\n";
+		printf("Duration (ms)       : %'.2lf\n", dur_dms );
 		printf("Total yields        : %'15llu\n", global_counter );
 		printf("Yields per procs    : %'15llu\n", global_counter / nprocs );
Index: benchmark/readyQ/yield.go
===================================================================
--- benchmark/readyQ/yield.go	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
+++ benchmark/readyQ/yield.go	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -0,0 +1,67 @@
+package main
+
+import (
+	"fmt"
+	"runtime"
+	"sync"
+	"sync/atomic"
+	"time"
+	"golang.org/x/text/language"
+	"golang.org/x/text/message"
+)
+
+func yielder(result chan uint64, start *sync.WaitGroup) {
+	count := uint64(0)
+	start.Wait()
+	for true {
+		runtime.Gosched()
+		count += 1
+		if  clock_mode && atomic.LoadInt32(&stop) == 1 { break }
+		if !clock_mode && count >= stop_count { break }
+	}
+
+	atomic.AddInt64(&threads_left, -1);
+	result <- count
+}
+
+func main() {
+	bench_init()
+
+	threads_left = int64(nthreads)
+
+	result := make(chan uint64)
+	var wg sync.WaitGroup
+	wg.Add(1)
+
+	for i := 0; i < nthreads; i++ {
+		go yielder(result, &wg)
+	}
+	fmt.Printf("Starting\n");
+	atomic.StoreInt32(&stop, 0)
+	start := time.Now()
+	wg.Done();
+	wait(start, true);
+
+	atomic.StoreInt32(&stop, 1)
+	end := time.Now()
+	duration := end.Sub(start)
+
+	fmt.Printf("\nDone\n")
+
+	global_counter := uint64(0)
+	for i := 0; i < nthreads; i++ {
+		global_counter += <- result
+	}
+
+	p := message.NewPrinter(language.English)
+	p.Printf("Duration (ms)        : %d\n", duration.Milliseconds())
+	p.Printf("Number of processors : %d\n", nprocs)
+	p.Printf("Number of threads    : %d\n", nthreads)
+	p.Printf("Total Operations(ops): %15d\n", global_counter)
+	p.Printf("Ops per second       : %18.2f\n", float64(global_counter) / duration.Seconds())
+	p.Printf("ns per ops           : %18.2f\n", float64(duration.Nanoseconds()) / float64(global_counter))
+	p.Printf("Ops per threads      : %15d\n", global_counter / uint64(nthreads))
+	p.Printf("Ops per procs        : %15d\n", global_counter / uint64(nprocs))
+	p.Printf("Ops/sec/procs        : %18.2f\n", (float64(global_counter) / float64(nprocs)) / duration.Seconds())
+	p.Printf("ns per ops/procs     : %18.2f\n", float64(duration.Nanoseconds()) / (float64(global_counter) / float64(nprocs)))
+}
Index: benchmark/readyQ/yield.rs
===================================================================
--- benchmark/readyQ/yield.rs	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
+++ benchmark/readyQ/yield.rs	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -0,0 +1,102 @@
+use std::sync::Arc;
+use std::sync::atomic::Ordering;
+use std::time::Instant;
+
+use tokio::runtime::Builder;
+use tokio::sync;
+use tokio::task;
+
+use clap::App;
+use num_format::{Locale, ToFormattedString};
+
+#[path = "../bench.rs"]
+mod bench;
+
+// ==================================================
+struct Yielder {
+	sem: sync::Semaphore,
+}
+
+async fn yield_main(idx: usize, others: Arc<Vec<Arc<Yielder>>>, exp: Arc<bench::BenchData> ) -> u64 {
+	let this = &others[idx];
+	this.sem.acquire().await.forget();
+
+	let mut count:u64 = 0;
+	loop {
+		task::yield_now().await;
+		count += 1;
+
+		if  exp.clock_mode && exp.stop.load(Ordering::Relaxed) { break; }
+		if !exp.clock_mode && count >= exp.stop_count { break; }
+	}
+
+	exp.threads_left.fetch_sub(1, Ordering::SeqCst);
+	count
+}
+
+// ==================================================
+fn main() {
+	let options = App::new("Yield Tokio")
+		.args(&bench::args())
+		.get_matches();
+
+	let nthreads  = options.value_of("nthreads").unwrap().parse::<usize>().unwrap();
+	let nprocs    = options.value_of("nprocs").unwrap().parse::<usize>().unwrap();
+
+	let exp = Arc::new(bench::BenchData::new(options, nthreads, None));
+
+	let s = (1000000 as u64).to_formatted_string(&Locale::en);
+	assert_eq!(&s, "1,000,000");
+
+	let thddata : Arc<Vec<Arc<Yielder>>> = Arc::new(
+		(0..nthreads).map(|_i| {
+			Arc::new(Yielder{
+				sem: sync::Semaphore::new(0),
+			})
+		}).collect()
+	);
+
+	let mut global_counter :u64 = 0;
+	let mut duration : std::time::Duration = std::time::Duration::from_secs(0);
+	let runtime = Builder::new_multi_thread()
+		.worker_threads(nprocs)
+		.enable_all()
+		.build()
+		.unwrap();
+
+	runtime.block_on(async {
+		let threads: Vec<_> = (0..nthreads).map(|i| {
+			tokio::spawn(yield_main(i, thddata.clone(), exp.clone()))
+		}).collect();
+		println!("Starting");
+
+		let start = Instant::now();
+
+		for i in 0..nthreads {
+			thddata[i].sem.add_permits(1);
+		}
+
+		duration = exp.wait(&start).await;
+
+		println!("\nDone");
+
+		for i in 0..nthreads {
+			thddata[i].sem.add_permits(1);
+		}
+
+		for t in threads {
+			global_counter += t.await.unwrap();
+		}
+	});
+
+	println!("Duration (ms)       : {}", (duration.as_millis()).to_formatted_string(&Locale::en));
+	println!("Number of processors: {}", (nprocs).to_formatted_string(&Locale::en));
+	println!("Number of threads   : {}", (nthreads).to_formatted_string(&Locale::en));
+	println!("Total yields        : {:>15}", (global_counter).to_formatted_string(&Locale::en));
+	println!("Yields per second   : {:>15}", (((global_counter as f64) / duration.as_secs() as f64) as u64).to_formatted_string(&Locale::en));
+	println!("ns per yields       : {:>15}", ((duration.as_nanos() as f64 / global_counter as f64) as u64).to_formatted_string(&Locale::en));
+	println!("Yields per threads  : {:>15}", (global_counter / nthreads as u64).to_formatted_string(&Locale::en));
+	println!("Yields per procs    : {:>15}", (global_counter / nprocs as u64).to_formatted_string(&Locale::en));
+	println!("Yields/sec/procs    : {:>15}", ((((global_counter as f64) / nprocs as f64) / duration.as_secs() as f64) as u64).to_formatted_string(&Locale::en));
+	println!("ns per yields/procs : {:>15}", ((duration.as_nanos() as f64 / (global_counter as f64 / nprocs as f64)) as u64).to_formatted_string(&Locale::en));
+}
Index: benchmark/rmit.py
===================================================================
--- benchmark/rmit.py	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ benchmark/rmit.py	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -16,4 +16,5 @@
 import random
 import re
+import socket
 import subprocess
 import sys
@@ -95,15 +96,65 @@
 	return nopts
 
+# returns the first option with key 'opt'
+def search_option(action, opt):
+	i = 0
+	while i < len(action):
+		if action[i] == opt:
+			i += 1
+			if i != len(action):
+				return action[i]
+		i += 1
+
+	return None
+
 def actions_eta(actions):
 	time = 0
 	for a in actions:
-		i = 0
-		while i < len(a):
-			if a[i] == '-d':
-				i += 1
-				if i != len(a):
-					time += int(a[i])
-			i += 1
+		o = search_option(a, '-d')
+		if o :
+			time += int(o)
 	return time
+
+taskset_maps = None
+
+def init_taskset_maps():
+	global taskset_maps
+	known_hosts = {
+		"jax": {
+			range(  1,  24) : "48-71",
+			range( 25,  48) : "48-71,144-167",
+			range( 49,  96) : "48-95,144-191",
+			range( 97, 144) : "24-95,120-191",
+			range(145, 192) : "0-95,96-191",
+		},
+	}
+
+	if (host := socket.gethostname()) in known_hosts:
+		taskset_maps = known_hosts[host]
+		return True
+
+	print("Warning unknown host '{}', disable taskset usage".format(host), file=sys.stderr)
+	return False
+
+
+def settaskset_one(action):
+	o = search_option(action, '-p')
+	if not o:
+		return action
+	try:
+		oi = int(o)
+	except ValueError:
+		return action
+
+	m = "Not found"
+	for key in taskset_maps:
+		if oi in key:
+			return ['taskset', '-c', taskset_maps[key], *action]
+
+	print("Warning no mapping for {} cores".format(oi), file=sys.stderr)
+	return action
+
+def settaskset(actions):
+	return [settaskset_one(a) for a in actions]
 
 if __name__ == "__main__":
@@ -115,4 +166,5 @@
 	parser.add_argument('--file', nargs='?', type=argparse.FileType('w'), default=sys.stdout)
 	parser.add_argument('--trials', help='Number of trials to run per combinaison', type=int, default=3)
+	parser.add_argument('--notaskset', help='If specified, the trial will not use taskset to match the -p option', action='store_true')
 	parser.add_argument('command', metavar='command', type=str, nargs=1, help='the command prefix to run')
 	parser.add_argument('candidates', metavar='candidates', type=str, nargs='*', help='the candidate suffix to run')
@@ -170,5 +222,19 @@
 
 	# ================================================================================
-	# Figure out all the combinations to run
+	# Fixup the different commands
+
+	# Add tasksets
+	withtaskset = False
+	if not options.notaskset and init_taskset_maps():
+		withtaskset = True
+		actions = settaskset(actions)
+
+	# ================================================================================
+	# Now that we know what to run, print it.
+	# find expected time
+	time = actions_eta(actions)
+	print("Running {} trials{}".format(len(actions), "" if time == 0 else " (expecting to take {})".format(str(datetime.timedelta(seconds=int(time)))) ))
+
+	# dry run if options ask for it
 	if options.list:
 		for a in actions:
@@ -180,8 +246,4 @@
 	# Prepare to run
 
-	# find expected time
-	time = actions_eta(actions)
-	print("Running {} trials{}".format(len(actions), "" if time == 0 else " (expecting to take {})".format(str(datetime.timedelta(seconds=int(time)))) ))
-
 	random.shuffle(actions)
 
@@ -191,5 +253,5 @@
 	first = True
 	for i, a in enumerate(actions):
-		sa = " ".join(a)
+		sa = " ".join(a[3:] if withtaskset else a)
 		if first:
 			first = False
@@ -208,7 +270,10 @@
 				match = re.search("^(.*):(.*)$", s)
 				if match:
-					fields[match.group(1).strip()] = float(match.group(2).strip().replace(',',''))
-
-		options.file.write(json.dumps([a[0][2:], sa, fields]))
+					try:
+						fields[match.group(1).strip()] = float(match.group(2).strip().replace(',',''))
+					except:
+						pass
+
+		options.file.write(json.dumps([a[3 if withtaskset else 0][2:], sa, fields]))
 		options.file.flush()
 
Index: doc/theses/andrew_beach_MMath/Makefile
===================================================================
--- doc/theses/andrew_beach_MMath/Makefile	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ doc/theses/andrew_beach_MMath/Makefile	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -31,5 +31,5 @@
 
 # The main rule, it does all the tex/latex processing.
-${BUILD}/${BASE}.dvi: ${RAWSRC} ${FIGTEX} Makefile | ${BUILD}
+${BUILD}/${BASE}.dvi: ${RAWSRC} ${FIGTEX} termhandle.pstex resumhandle.pstex Makefile | ${BUILD}
 	${LATEX} ${BASE}
 	${BIBTEX} ${BUILD}/${BASE}
@@ -40,4 +40,8 @@
 ${FIGTEX}: ${BUILD}/%.tex: %.fig | ${BUILD}
 	fig2dev -L eepic $< > $@
+
+%.pstex : %.fig | ${Build}
+	fig2dev -L pstex $< > ${BUILD}/$@
+	fig2dev -L pstex_t -p ${BUILD}/$@ $< > ${BUILD}/$@_t
 
 # Step through dvi & postscript to handle xfig specials.
Index: doc/theses/andrew_beach_MMath/code/CondCatch.java
===================================================================
--- doc/theses/andrew_beach_MMath/code/CondCatch.java	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ doc/theses/andrew_beach_MMath/code/CondCatch.java	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -6,23 +6,15 @@
 	static boolean should_catch = false;
 
-	static void throw_exception() throws EmptyException {
-		throw new EmptyException();
-	}
-
-	static void cond_catch() throws EmptyException {
-		try {
-			throw_exception();
-		} catch (EmptyException exc) {
-			if (!should_catch) {
-				throw exc;
-			}
-		}
-	}
-
 	private static long loop(int times) {
 		long startTime = System.nanoTime();
 		for (int count = 0 ; count < times ; ++count) {
 			try {
-				cond_catch();
+				try {
+					throw new EmptyException();
+				} catch (EmptyException exc) {
+					if (!should_catch) {
+						throw exc;
+					}
+				}
 			} catch (EmptyException exc) {
 				// ...
@@ -46,5 +38,5 @@
 
 		long time = loop(times);
-		System.out.println("Run-Time (ns): " + time);
+		System.out.format("Run-Time (s): %.1f%n", time / 1_000_000_000.);
 	}
 }
Index: c/theses/andrew_beach_MMath/code/CrossCatch.java
===================================================================
--- doc/theses/andrew_beach_MMath/code/CrossCatch.java	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ 	(revision )
@@ -1,35 +1,0 @@
-// Enter and Leave a Try Statement with a Termination Handler
-
-class NotRaisedException extends Exception {}
-
-public class CrossCatch {
-	private static boolean shouldThrow = false;
-
-	private static long loop(int times) {
-		long startTime = System.nanoTime();
-		for (int count = 0 ; count < times ; ++count) {
-			try {
-				if (shouldThrow) {
-					throw new NotRaisedException();
-				}
-			} catch (NotRaisedException e) {
-				// ...
-			}
-		}
-		long endTime = System.nanoTime();
-		return endTime - startTime;
-	}
-
-	public static void main(String[] args) {
-		int times = 1;
-		if (0 < args.length) {
-			times = Integer.parseInt(args[0]);
-		}
-
-		// Warm-Up:
-		loop(1000);
-
-		long time = loop(times);
-		System.out.println("Run-Time (ns): " + time);
-	}
-}
Index: c/theses/andrew_beach_MMath/code/CrossFinally.java
===================================================================
--- doc/theses/andrew_beach_MMath/code/CrossFinally.java	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ 	(revision )
@@ -1,31 +1,0 @@
-// Cross a Try Statement with a Finally Clause
-
-public class CrossFinally {
-	private static boolean shouldThrow = false;
-
-	private static long loop(int times) {
-		long startTime = System.nanoTime();
-		for (int count = 0 ; count < times ; ++count) {
-			try {
-				// ...
-			} finally {
-				// ...
-			}
-		}
-		long endTime = System.nanoTime();
-		return endTime - startTime;
-	}
-
-	public static void main(String[] args) {
-		int times = 1;
-		if (0 < args.length) {
-			times = Integer.parseInt(args[0]);
-		}
-
-		// Warm-Up:
-		loop(1000);
-
-		long time = loop(times);
-		System.out.println("Run-Time (ns): " + time);
-	}
-}
Index: doc/theses/andrew_beach_MMath/code/FixupEmpty.java
===================================================================
--- doc/theses/andrew_beach_MMath/code/FixupEmpty.java	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
+++ doc/theses/andrew_beach_MMath/code/FixupEmpty.java	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -0,0 +1,42 @@
+public class FixupEmpty {
+	public interface Fixup {
+		public int op(int fixup);
+	}
+
+	static void nounwind_fixup(int frames, Fixup raised_rtn) {
+		if (0 < frames) {
+			nounwind_fixup(frames - 1, raised_rtn);
+		} else {
+			int fixup = frames;
+			fixup = raised_rtn.op(fixup);
+		}
+	}
+
+	private static long loop(int times, int total_frames) {
+		Fixup raised = (int fixup) -> total_frames + 42; // use local scope => lexical link
+
+		long startTime = System.nanoTime();
+		for (int count = 0 ; count < times ; ++count) {
+			nounwind_fixup(total_frames, raised);
+		}
+		long endTime = System.nanoTime();
+		return endTime - startTime;
+	}
+
+	public static void main(String[] args) {
+		int times = 1;
+		int total_frames = 1;
+		if (0 < args.length) {
+			times = Integer.parseInt(args[0]);
+		}
+		if (1 < args.length) {
+			total_frames = Integer.parseInt(args[1]);
+		}
+
+		// Warm-Up:
+		loop(1000, total_frames);
+
+		long time = loop(times, total_frames);
+		System.out.format("Run-Time (s): %.1f%n", time / 1_000_000_000.);
+	}
+}
Index: doc/theses/andrew_beach_MMath/code/FixupOther.java
===================================================================
--- doc/theses/andrew_beach_MMath/code/FixupOther.java	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
+++ doc/theses/andrew_beach_MMath/code/FixupOther.java	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -0,0 +1,44 @@
+public class FixupOther {
+	public interface Fixup {
+		public int op(int fixup);
+	}
+
+	static void nounwind_fixup(int frames, Fixup raised_rtn, Fixup not_raised_rtn) {
+	 	Fixup not_raised = (int fixup) -> frames + 42; // use local scope => lexical link
+		if (0 < frames) {
+			nounwind_fixup(frames - 1, raised_rtn, not_raised);
+		} else {
+			int fixup = 17;
+			fixup = raised_rtn.op(fixup);
+		}
+	}
+
+	private static long loop(int times, int total_frames) {
+		Fixup raised = (int fixup) -> total_frames + 42; // use local scope => lexical link
+		Fixup not_raised = (int fixup) -> total_frames + 42; // use local scope => lexical link
+
+		long startTime = System.nanoTime();
+		for (int count = 0 ; count < times ; ++count) {
+		    nounwind_fixup(total_frames, raised, not_raised);
+		}
+		long endTime = System.nanoTime();
+		return endTime - startTime;
+	}
+
+	public static void main(String[] args) {
+		int times = 1;
+		int total_frames = 1;
+		if (0 < args.length) {
+			times = Integer.parseInt(args[0]);
+		}
+		if (1 < args.length) {
+			total_frames = Integer.parseInt(args[1]);
+		}
+
+		// Warm-Up:
+		loop(1000, total_frames);
+
+		long time = loop(times, total_frames);
+		System.out.format("Run-Time (s): %.1f%n", time / 1_000_000_000.);
+	}
+}
Index: doc/theses/andrew_beach_MMath/code/ThrowEmpty.java
===================================================================
--- doc/theses/andrew_beach_MMath/code/ThrowEmpty.java	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ doc/theses/andrew_beach_MMath/code/ThrowEmpty.java	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -39,5 +39,5 @@
 
 		long time = loop(times, total_frames);
-		System.out.println("Run-Time (ns): " + time);
+		System.out.format("Run-Time (s): %.1f%n", time / 1_000_000_000.);
 	}
 }
Index: doc/theses/andrew_beach_MMath/code/ThrowFinally.java
===================================================================
--- doc/theses/andrew_beach_MMath/code/ThrowFinally.java	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ doc/theses/andrew_beach_MMath/code/ThrowFinally.java	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -44,5 +44,5 @@
 
 		long time = loop(times, total_frames);
-		System.out.println("Run-Time (ns): " + time);
+		System.out.format("Run-Time (s): %.1f%n", time / 1_000_000_000.);
 	}
 }
Index: doc/theses/andrew_beach_MMath/code/ThrowOther.java
===================================================================
--- doc/theses/andrew_beach_MMath/code/ThrowOther.java	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ doc/theses/andrew_beach_MMath/code/ThrowOther.java	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -52,5 +52,5 @@
 
 		long time = loop(times, total_frames);
-		System.out.println("Run-Time (ns): " + time);
+		System.out.format("Run-Time (s): %.1f%n", time / 1_000_000_000.);
 	}
 }
Index: doc/theses/andrew_beach_MMath/code/TryCatch.java
===================================================================
--- doc/theses/andrew_beach_MMath/code/TryCatch.java	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
+++ doc/theses/andrew_beach_MMath/code/TryCatch.java	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -0,0 +1,35 @@
+// Enter and Leave a Try Statement with a Termination Handler
+
+class NotRaisedException extends Exception {}
+
+public class TryCatch {
+	private static boolean shouldThrow = false;
+
+	private static long loop(int times) {
+		long startTime = System.nanoTime();
+		for (int count = 0 ; count < times ; ++count) {
+			try {
+				if (shouldThrow) {
+					throw new NotRaisedException();
+				}
+			} catch (NotRaisedException e) {
+				// ...
+			}
+		}
+		long endTime = System.nanoTime();
+		return endTime - startTime;
+	}
+
+	public static void main(String[] args) {
+		int times = 1;
+		if (0 < args.length) {
+			times = Integer.parseInt(args[0]);
+		}
+
+		// Warm-Up:
+		loop(1000);
+
+		long time = loop(times);
+		System.out.format("Run-Time (s): %.1f%n", time / 1_000_000_000.);
+	}
+}
Index: doc/theses/andrew_beach_MMath/code/TryFinally.java
===================================================================
--- doc/theses/andrew_beach_MMath/code/TryFinally.java	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
+++ doc/theses/andrew_beach_MMath/code/TryFinally.java	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -0,0 +1,31 @@
+// Enter and Leave a Try Statement with a Finally Handler
+
+public class TryFinally {
+	private static boolean shouldThrow = false;
+
+	private static long loop(int times) {
+		long startTime = System.nanoTime();
+		for (int count = 0 ; count < times ; ++count) {
+			try {
+				// ...
+			} finally {
+				// ...
+			}
+		}
+		long endTime = System.nanoTime();
+		return endTime - startTime;
+	}
+
+	public static void main(String[] args) {
+		int times = 1;
+		if (0 < args.length) {
+			times = Integer.parseInt(args[0]);
+		}
+
+		// Warm-Up:
+		loop(1000);
+
+		long time = loop(times);
+		System.out.format("Run-Time (s): %.1f%n", time / 1_000_000_000.);
+	}
+}
Index: doc/theses/andrew_beach_MMath/code/cond-catch.cfa
===================================================================
--- doc/theses/andrew_beach_MMath/code/cond-catch.cfa	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ doc/theses/andrew_beach_MMath/code/cond-catch.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -3,31 +3,18 @@
 #include <exception.hfa>
 #include <fstream.hfa>
-#include <stdlib.h>
+#include <stdlib.hfa>									// strto
 
-EHM_EXCEPTION(empty_exception)();
-
-EHM_VIRTUAL_TABLE(empty_exception, empty_vt);
+exception empty_exception;
+vtable(empty_exception) empty_vt;
 
 bool should_catch = false;
-
-void throw_exception() {
-	throw (empty_exception){&empty_vt};
-}
-
-void cond_catch() {
-	try {
-		throw_exception();
-	} catch (empty_exception * exc ; should_catch) {
-		asm volatile ("# catch block (conditional)");
-	}
-}
 
 int main(int argc, char * argv[]) {
 	unsigned int times = 1;
 	if (1 < argc) {
-		times = strtol(argv[1], 0p, 10);
+		times = strto(argv[1], 0p, 10);
 	}
 	if (2 < argc) {
-		should_catch = strtol(argv[2], 0p, 10);
+		should_catch = (unsigned int)strto(argv[2], 0p, 2);
 	}
 
@@ -35,5 +22,7 @@
 	for (unsigned int count = 0 ; count < times ; ++count) {
 		try {
-			cond_catch();
+			throw (empty_exception){&empty_vt};
+		} catch (empty_exception * exc ; should_catch) {
+			asm volatile ("# catch block (conditional)");
 		} catch (empty_exception * exc) {
 			asm volatile ("# catch block (unconditional)");
@@ -41,4 +30,4 @@
 	}
 	Time end_time = timeHiRes();
-	sout | "Run-Time (ns): " | (end_time - start_time)`ns;
+	sout | "Run-Time (s): " | wd(0,1, (end_time - start_time)`ns / 1_000_000_000.);
 }
Index: doc/theses/andrew_beach_MMath/code/cond-catch.cpp
===================================================================
--- doc/theses/andrew_beach_MMath/code/cond-catch.cpp	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ doc/theses/andrew_beach_MMath/code/cond-catch.cpp	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -4,5 +4,7 @@
 #include <exception>
 #include <iostream>
+#include <iomanip>
 
+using namespace std;
 using namespace std::chrono;
 
@@ -10,19 +12,4 @@
 
 bool should_catch = false;
-
-void throw_exception() {
-	throw EmptyException();
-}
-
-void cond_catch() {
-	try {
-		throw_exception();
-	} catch (EmptyException & exc) {
-		if (!should_catch) {
-			throw;
-		}
-		asm volatile ("# catch block (conditional)");
-	}
-}
 
 int main(int argc, char * argv[]) {
@@ -38,5 +25,12 @@
     for (unsigned int count = 0 ; count < times ; ++count) {
         try {
-			cond_catch();
+			try {
+				throw EmptyException();
+			} catch (EmptyException & exc) {
+				if (!should_catch) {
+					throw;
+				}
+				asm volatile ("# catch block (conditional)");
+			}
 		} catch (EmptyException &) {
 			asm volatile ("# catch block (unconditional)");
@@ -45,4 +39,4 @@
 	time_point<steady_clock> end_time = steady_clock::now();
 	nanoseconds duration = duration_cast<nanoseconds>(end_time - start_time);
-	std::cout << "Run-Time (ns): " << duration.count() << std::endl;
+	cout << "Run-Time (s): " << fixed << setprecision(1) << duration.count() / 1'000'000'000. << endl;
 }
Index: doc/theses/andrew_beach_MMath/code/cond-catch.py
===================================================================
--- doc/theses/andrew_beach_MMath/code/cond-catch.py	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
+++ doc/theses/andrew_beach_MMath/code/cond-catch.py	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -0,0 +1,39 @@
+#!/usr/bin/env python3
+
+# Conditional Match (or Re-Raise)
+
+from time import thread_time_ns
+
+
+class EmptyException(Exception):
+    pass
+
+
+should_catch = False
+
+
+def main(argv):
+    times = 1
+    if 1 < len(argv):
+        times = int(argv[1])
+    if 2 < len(argv):
+        should_catch = 0 < int(argv[2])
+
+    start_time = thread_time_ns()
+    for count in range(times):
+        try:
+            try:
+                raise EmptyException()
+            except EmptyException as exc:
+                if not should_catch:
+                    raise
+        except EmptyException:
+            pass
+
+    end_time = thread_time_ns()
+    print('Run-Time (s): {:.1f}'.format((end_time - start_time) / 1_000_000_000.))
+
+
+if '__main__' == __name__:
+    import sys
+    main(sys.argv)
Index: doc/theses/andrew_beach_MMath/code/cond-fixup.cfa
===================================================================
--- doc/theses/andrew_beach_MMath/code/cond-fixup.cfa	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ doc/theses/andrew_beach_MMath/code/cond-fixup.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -3,31 +3,18 @@
 #include <exception.hfa>
 #include <fstream.hfa>
-#include <stdlib.hfa>
+#include <stdlib.hfa>									// strto
 
-EHM_EXCEPTION(empty_exception)();
-
-EHM_VIRTUAL_TABLE(empty_exception, empty_vt);
+exception empty_exception;
+vtable(empty_exception) empty_vt;
 
 bool should_catch = false;
-
-void throw_exception() {
-	throwResume (empty_exception){&empty_vt};
-}
-
-void cond_catch() {
-	try {
-		throw_exception();
-	} catchResume (empty_exception * exc ; should_catch) {
-		asm volatile ("# fixup block (conditional)");
-	}
-}
 
 int main(int argc, char * argv[]) {
 	unsigned int times = 1;
 	if (1 < argc) {
-		times = strtol(argv[1], 0p, 10);
+		times = strto(argv[1], 0p, 10);
 	}
 	if (2 < argc) {
-		should_catch = strtol(argv[2], 0p, 10);
+		should_catch = (unsigned int)strto(argv[2], 0p, 2);
 	}
 
@@ -35,5 +22,7 @@
 	for (unsigned int count = 0 ; count < times ; ++count) {
 		try {
-			cond_catch();
+			throwResume (empty_exception){&empty_vt};
+		} catchResume (empty_exception * exc ; should_catch) {
+			asm volatile ("# fixup block (conditional)");
 		} catchResume (empty_exception * exc) {
 			asm volatile ("# fixup block (unconditional)");
@@ -41,4 +30,4 @@
 	}
 	Time end_time = timeHiRes();
-	sout | "Run-Time (ns): " | (end_time - start_time)`ns;
+	sout | "Run-Time (s): " | wd(0,1, (end_time - start_time)`ns / 1_000_000_000.);
 }
Index: c/theses/andrew_beach_MMath/code/cond_catch.py
===================================================================
--- doc/theses/andrew_beach_MMath/code/cond_catch.py	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ 	(revision )
@@ -1,47 +1,0 @@
-#!/usr/bin/env python3
-
-# Conditional Match (or Re-Raise)
-
-from time import thread_time_ns
-
-
-class EmptyException(Exception):
-    pass
-
-
-should_catch = False
-
-
-def throw_exception():
-    raise EmptyException()
-
-
-def cond_catch():
-    try:
-        throw_exception()
-    except EmptyException as exc:
-        if not should_catch:
-            raise
-
-
-def main(argv):
-    times = 1
-    if 1 < len(argv):
-        times = int(argv[1])
-    if 2 < len(argv):
-        should_catch = 0 < int(argv[2])
-
-    start_time = thread_time_ns()
-    for count in range(times):
-        try:
-            cond_catch();
-        except EmptyException:
-            pass
-
-    end_time = thread_time_ns()
-    print('Run-Time (ns):', end_time - start_time)
-
-
-if '__main__' == __name__:
-    import sys
-    main(sys.argv)
Index: c/theses/andrew_beach_MMath/code/cross-catch.cfa
===================================================================
--- doc/theses/andrew_beach_MMath/code/cross-catch.cfa	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ 	(revision )
@@ -1,31 +1,0 @@
-// Cross a Try Statement with a Termination Handler
-#include <clock.hfa>
-#include <exception.hfa>
-#include <fstream.hfa>
-#include <stdlib.hfa>
-
-EHM_EXCEPTION(not_raised_exception)();
-
-EHM_VIRTUAL_TABLE(not_raised_exception, not_vt);
-
-int main(int argc, char * argv[]) {
-	unsigned int times = 1;
-	volatile bool should_throw = false;
-	if (1 < argc) {
-		times = strtol(argv[1], 0p, 10);
-	}
-
-	Time start_time = timeHiRes();
-	for (unsigned int count = 0 ; count < times ; ++count) {
-		try {
-			asm volatile ("# try block");
-			if (should_throw) {
-				throw (not_raised_exception){&not_vt};
-			}
-		} catch (not_raised_exception *) {
-			asm volatile ("# catch block");
-		}
-	}
-	Time end_time = timeHiRes();
-	sout | "Run-Time (ns): " | (end_time - start_time)`ns;
-}
Index: c/theses/andrew_beach_MMath/code/cross-catch.cpp
===================================================================
--- doc/theses/andrew_beach_MMath/code/cross-catch.cpp	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ 	(revision )
@@ -1,32 +1,0 @@
-// Cross a Try Statement with a Termination Handler
-#include <chrono>
-#include <cstdlib>
-#include <exception>
-#include <iostream>
-
-using namespace std::chrono;
-
-struct NotRaisedException : public std::exception {};
-
-int main(int argc, char * argv[]) {
-	unsigned int times = 1;
-	volatile bool should_throw = false;
-	if (1 < argc) {
-		times = strtol(argv[1], nullptr, 10);
-	}
-
-	time_point<steady_clock> start_time = steady_clock::now();
-	for (unsigned int count = 0 ; count < times ; ++count) {
-		try {
-			asm volatile ("# try block");
-			if (should_throw) {
-				throw NotRaisedException();
-			}
-		} catch (NotRaisedException &) {
-			asm volatile ("# catch block");
-		}
-	}
-	time_point<steady_clock> end_time = steady_clock::now();
-	nanoseconds duration = duration_cast<nanoseconds>(end_time - start_time);
-	std::cout << "Run-Time (ns): " << duration.count() << std::endl;
-}
Index: c/theses/andrew_beach_MMath/code/cross-finally.cfa
===================================================================
--- doc/theses/andrew_beach_MMath/code/cross-finally.cfa	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ 	(revision )
@@ -1,31 +1,0 @@
-// Cross a Try Statement With Finally Clause
-#include <clock.hfa>
-#include <exception.hfa>
-#include <fstream.hfa>
-#include <stdlib.hfa>
-
-EHM_EXCEPTION(not_raised_exception)();
-
-EHM_VIRTUAL_TABLE(not_raised_exception, not_vt);
-
-int main(int argc, char * argv[]) {
-	unsigned int times = 1;
-	volatile bool should_throw = false;
-	if (1 < argc) {
-		times = strtol(argv[1], 0p, 10);
-	}
-
-	Time start_time = timeHiRes();
-	for (unsigned int count = 0 ; count < times ; ++count) {
-		try {
-			asm volatile ("# try block");
-			if (should_throw) {
-				throw (not_raised_exception){&not_vt};
-			}
-		} finally {
-			asm volatile ("# finally block");
-		}
-	}
-	Time end_time = timeHiRes();
-	sout | "Run-Time (ns): " | (end_time - start_time)`ns;
-}
Index: c/theses/andrew_beach_MMath/code/cross-resume.cfa
===================================================================
--- doc/theses/andrew_beach_MMath/code/cross-resume.cfa	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ 	(revision )
@@ -1,29 +1,0 @@
-// Cross a Try Statement With Finally Clause
-#include <clock.hfa>
-#include <exception.hfa>
-#include <fstream.hfa>
-#include <stdlib.hfa>
-
-EHM_EXCEPTION(not_raised_exception)();
-
-int main(int argc, char * argv[]) {
-	unsigned int times = 1;
-	unsigned int total_frames = 1;
-	if (1 < argc) {
-		times = strtol(argv[1], 0p, 10);
-	}
-	if (2 < argc) {
-		total_frames = strtol(argv[2], 0p, 10);
-	}
-
-	Time start_time = timeHiRes();
-	for (unsigned int count = 0 ; count < times ; ++count) {
-		try {
-			asm volatile ("");
-		} catchResume (not_raised_exception *) {
-			asm volatile ("");
-		}
-	}
-	Time end_time = timeHiRes();
-	sout | "Run-Time (ns): " | (end_time - start_time)`ns;
-}
Index: c/theses/andrew_beach_MMath/code/cross_catch.py
===================================================================
--- doc/theses/andrew_beach_MMath/code/cross_catch.py	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ 	(revision )
@@ -1,30 +1,0 @@
-#!/usr/bin/env python3
-
-# Cross a Try Statement with a Termination Handler
-
-from time import thread_time_ns
-
-
-class NotRaisedException(Exception):
-    pass
-
-
-def main(argv):
-    times = 1;
-    if 1 < len(argv):
-        times = int(argv[1])
-
-    start_time = thread_time_ns()
-    for count in range(times):
-        try:
-            pass
-        except NotRaisedException:
-            pass
-
-    end_time = thread_time_ns()
-    print('Run-Time (ns):', end_time - start_time)
-
-
-if '__main__' == __name__:
-    import sys
-    main(sys.argv)
Index: c/theses/andrew_beach_MMath/code/cross_finally.py
===================================================================
--- doc/theses/andrew_beach_MMath/code/cross_finally.py	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ 	(revision )
@@ -1,29 +1,0 @@
-#!/usr/bin/env python3
-
-# Cross a Try Statement With Finally Clause
-
-from time import thread_time_ns
-
-
-def main(argv):
-    times = 1;
-    total_frames = 1;
-    if 1 < len(argv):
-        times = int(argv[1])
-    if 2 < len(argv):
-        total_frames = int(argv[2])
-
-    start_time = thread_time_ns()
-    for count in range(times):
-        try:
-            pass
-        finally:
-            pass
-
-    end_time = thread_time_ns()
-    print('Run-Time (ns):', end_time - start_time)
-
-
-if '__main__' == __name__:
-    import sys
-    main(sys.argv)
Index: doc/theses/andrew_beach_MMath/code/fixup-empty-f.cfa
===================================================================
--- doc/theses/andrew_beach_MMath/code/fixup-empty-f.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
+++ doc/theses/andrew_beach_MMath/code/fixup-empty-f.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -0,0 +1,39 @@
+// Resume Across Fixup
+#include <clock.hfa>
+#include <fstream.hfa>
+#include <stdlib.hfa>
+
+void nounwind_fixup(unsigned int frames, void (*raised_rtn)(int &)) {
+	if (frames) {
+		nounwind_fixup(frames - 1, raised_rtn);
+		// "Always" false, but prevents recursion elimination.
+		if (-1 == frames) printf("~");
+	} else {
+		int fixup = 17;
+		raised_rtn(fixup);
+	}
+}
+
+int main(int argc, char * argv[]) {
+	unsigned int times = 1;
+	unsigned int total_frames = 1;
+	if (1 < argc) {
+		times = strto(argv[1], 0p, 10);
+	}
+	if (2 < argc) {
+		total_frames = strto(argv[2], 0p, 10);
+	}
+
+	// Closures at the top level are allowed to be true closures.
+	void raised(int & fixup) {
+		fixup = total_frames + 42;
+		if (total_frames == 42) printf("42");
+	}
+
+	Time start_time = timeHiRes();
+	for (unsigned int count = 0 ; count < times ; ++count) {
+		nounwind_fixup(total_frames, raised);
+	}
+	Time end_time = timeHiRes();
+	sout | "Run-Time (s): " | wd(0,1, (end_time - start_time)`ns / 1_000_000_000.);
+}
Index: doc/theses/andrew_beach_MMath/code/fixup-empty-r.cfa
===================================================================
--- doc/theses/andrew_beach_MMath/code/fixup-empty-r.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
+++ doc/theses/andrew_beach_MMath/code/fixup-empty-r.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -0,0 +1,43 @@
+// Resume Across Empty Function
+#include <clock.hfa>
+#include <exception.hfa>
+#include <fstream.hfa>
+#include <stdlib.hfa>
+
+exception fixup_exception {
+	int & fixup;
+};
+vtable(fixup_exception) fixup_vt;
+
+void nounwind_empty(unsigned int frames) {
+	if (frames) {
+		nounwind_empty(frames - 1);
+		// "Always" false, but prevents recursion elimination.
+		if (-1 == frames) printf("~");
+	} else {
+		int fixup = 17;
+		throwResume (fixup_exception){&fixup_vt, fixup};
+	}
+}
+
+int main(int argc, char * argv[]) {
+	unsigned int times = 1;
+	unsigned int total_frames = 1;
+	if (1 < argc) {
+		times = strto(argv[1], 0p, 10);
+	}
+	if (2 < argc) {
+		total_frames = strto(argv[2], 0p, 10);
+	}
+
+	Time start_time = timeHiRes();
+	for (unsigned int count = 0 ; count < times ; ++count) {
+		try {
+			nounwind_empty(total_frames);
+		} catchResume (fixup_exception * ex) {
+			ex->fixup = total_frames + 42;
+		}
+	}
+	Time end_time = timeHiRes();
+	sout | "Run-Time (s): " | wd(0,1, (end_time - start_time)`ns / 1_000_000_000.);
+}
Index: doc/theses/andrew_beach_MMath/code/fixup-empty.cpp
===================================================================
--- doc/theses/andrew_beach_MMath/code/fixup-empty.cpp	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
+++ doc/theses/andrew_beach_MMath/code/fixup-empty.cpp	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -0,0 +1,41 @@
+// Resume Across Fixup
+#include <chrono>
+#include <cstdlib>
+#include <exception>
+#include <iostream>
+#include <iomanip>
+#include <functional>
+
+using namespace std;
+using namespace chrono;
+
+void nounwind_fixup(unsigned int frames, function<void (int &)> raised_rtn ) {
+	if (frames) {
+		nounwind_fixup(frames - 1, raised_rtn);
+	} else {
+		int fixup = 17;
+		raised_rtn(fixup);
+	}
+}
+
+int main(int argc, char * argv[]) {
+	unsigned int times = 1;
+	unsigned int total_frames = 1;
+	if (1 < argc) {
+		times = strtol(argv[1], nullptr, 10);
+	}
+	if (2 < argc) {
+		total_frames = strtol(argv[2], nullptr, 10);
+	}
+
+	auto raised = [=] (int & fixup) -> void {
+					  fixup = total_frames + 42;		// use local scope => lexical link
+				  };
+	time_point<steady_clock> start_time = steady_clock::now();
+	for (unsigned int count = 0 ; count < times ; ++count) {
+		nounwind_fixup(total_frames, raised);
+	}
+	time_point<steady_clock> end_time = steady_clock::now();
+	nanoseconds duration = duration_cast<nanoseconds>(end_time - start_time);
+	cout << "Run-Time (s): " << fixed << setprecision(1) << duration.count() / 1'000'000'000. << endl;
+}
Index: doc/theses/andrew_beach_MMath/code/fixup-empty.py
===================================================================
--- doc/theses/andrew_beach_MMath/code/fixup-empty.py	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
+++ doc/theses/andrew_beach_MMath/code/fixup-empty.py	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -0,0 +1,32 @@
+#!/usr/bin/env python3
+
+from time import thread_time_ns
+
+def nounwind_fixup(frames, raised_rtn):
+    if 0 < frames:
+        nounwind_fixup(frames - 1, raised_rtn)
+    else:
+        fixup = 17;
+        raised_rtn(fixup);
+
+
+def main(argv):
+    times = 1
+    total_frames = 1
+    if 1 < len(argv):
+        times = int(argv[1])
+    if 2 < len(argv):
+        total_frames = int(argv[2])
+
+    raised = lambda lfixup : total_frames + 42		# use local scope => lexical link
+    start_time = thread_time_ns()
+    for count in range(times):
+        nounwind_fixup(total_frames, raised)
+
+    end_time = thread_time_ns()
+    print('Run-Time (s): {:.1f}'.format((end_time - start_time) / 1_000_000_000.))
+
+
+if '__main__' == __name__:
+    import sys
+    main(sys.argv)
Index: doc/theses/andrew_beach_MMath/code/fixup-other-f.cfa
===================================================================
--- doc/theses/andrew_beach_MMath/code/fixup-other-f.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
+++ doc/theses/andrew_beach_MMath/code/fixup-other-f.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -0,0 +1,50 @@
+// Resume Across Fixup
+#include <clock.hfa>
+#include <fstream.hfa>
+#include <stdlib.hfa>
+
+// Using a global value to allow hoisting (and avoid thunks).
+unsigned int frames;
+
+void nounwind_fixup(unsigned int dummy, void (*raised_rtn)(int &), void (*not_raised_rtn)(int &)) {
+	void not_raised(int & fixup) {
+		fixup = frames + 42;
+	}
+
+	if (frames) {
+		frames -= 1;
+		nounwind_fixup(42, raised_rtn, not_raised);
+		// Always false, but prevents recursion elimination.
+		if (-1 == frames) printf("~");
+	} else {
+		int fixup = dummy;
+		raised_rtn(fixup);
+	}
+}
+
+int main(int argc, char * argv[]) {
+	unsigned int times = 1;
+	unsigned int total_frames = 1;
+	if (1 < argc) {
+		times = strto(argv[1], 0p, 10);
+	}
+	if (2 < argc) {
+		total_frames = strto(argv[2], 0p, 10);
+	}
+	frames = total_frames;
+
+	// Closures at the top level are allowed to be true closures.
+	void raised(int & fixup) {
+		fixup = total_frames + 42;
+	}
+	void not_raised(int & fixup) {
+		fixup = total_frames + 42;
+	}
+
+	Time start_time = timeHiRes();
+	for (int count = 0 ; count < times ; ++count) {
+		nounwind_fixup(42, raised, not_raised);
+	}
+	Time end_time = timeHiRes();
+	sout | "Run-Time (s): " | wd(0,1, (end_time - start_time)`ns / 1_000_000_000.);
+}
Index: doc/theses/andrew_beach_MMath/code/fixup-other-r.cfa
===================================================================
--- doc/theses/andrew_beach_MMath/code/fixup-other-r.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
+++ doc/theses/andrew_beach_MMath/code/fixup-other-r.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -0,0 +1,55 @@
+// Resume Across Other Handler
+#include <clock.hfa>
+#include <exception.hfa>
+#include <fstream.hfa>
+#include <stdlib.hfa>
+
+exception fixup_exception {
+	int & fixup;
+};
+vtable(fixup_exception) fixup_vt;
+exception not_raised_exception {
+	int & fixup;
+};
+
+// Using a global value to allow hoisting (and avoid thunks).
+unsigned int frames;
+
+void nounwind_other(unsigned int dummy) {
+	if (frames) {
+		frames -= 1;
+		try {
+			nounwind_other(42);
+			// Always false, but prevents recursion elimination.
+			if (-1 == frames) printf("~");
+		} catchResume (not_raised_exception * ex) {
+			ex->fixup = frames + 42;
+		}
+	} else {
+		int fixup = dummy;
+		throwResume (fixup_exception){&fixup_vt, fixup};
+	}
+}
+
+int main(int argc, char * argv[]) {
+	unsigned int times = 1;
+	unsigned int total_frames = 1;
+	if (1 < argc) {
+		times = strto(argv[1], 0p, 10);
+	}
+	if (2 < argc) {
+		total_frames = strto(argv[2], 0p, 10);
+	}
+	frames = total_frames;
+
+	Time start_time = timeHiRes();
+	for (int count = 0 ; count < times ; ++count) {
+		try {
+			nounwind_other(42);
+		} catchResume (fixup_exception * ex) {
+			ex->fixup = total_frames + 42;
+		}
+	}
+	Time end_time = timeHiRes();
+	sout | "Run-Time (s): " | wd(0,1, (end_time - start_time)`ns / 1_000_000_000.);
+}
Index: doc/theses/andrew_beach_MMath/code/fixup-other.cpp
===================================================================
--- doc/theses/andrew_beach_MMath/code/fixup-other.cpp	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
+++ doc/theses/andrew_beach_MMath/code/fixup-other.cpp	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -0,0 +1,49 @@
+// Resume Across Fixup
+#include <chrono>
+#include <cstdlib>
+#include <exception>
+#include <iostream>
+#include <iomanip>
+#include <functional>
+
+using namespace std;
+using namespace chrono;
+
+void nounwind_fixup(unsigned int frames, function<void (int &)> raised_rtn, function<void (int &)> not_raised_rtn ) {
+	auto not_raised = [=](int & fixup) -> void {
+						  fixup = frames + 42;			// use local scope => lexical link
+					  };
+
+	if (frames) {
+		nounwind_fixup(frames - 1, raised_rtn, not_raised);
+	} else {
+		int fixup = 17;
+		raised_rtn(fixup);
+	}
+}
+
+int main(int argc, char * argv[]) {
+	unsigned int times = 1;
+	unsigned int total_frames = 1;
+	if (1 < argc) {
+		times = strtol(argv[1], nullptr, 10);
+	}
+	if (2 < argc) {
+		total_frames = strtol(argv[2], nullptr, 10);
+	}
+
+	auto raised = [=] (int & fixup) -> void {
+					  fixup = total_frames + 42;		// use local scope => lexical link
+				  };
+	auto not_raised = [=] (int & fixup) -> void {
+						  fixup = total_frames + 42;	// use local scope => lexical link
+					  };
+
+	time_point<steady_clock> start_time = steady_clock::now();
+	for (unsigned int count = 0 ; count < times ; ++count) {
+		nounwind_fixup(total_frames, raised, not_raised);
+	}
+	time_point<steady_clock> end_time = steady_clock::now();
+	nanoseconds duration = duration_cast<nanoseconds>(end_time - start_time);
+	cout << "Run-Time (s): " << fixed << setprecision(1) << duration.count() / 1'000'000'000. << endl;
+}
Index: doc/theses/andrew_beach_MMath/code/fixup-other.py
===================================================================
--- doc/theses/andrew_beach_MMath/code/fixup-other.py	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
+++ doc/theses/andrew_beach_MMath/code/fixup-other.py	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -0,0 +1,34 @@
+#!/usr/bin/env python3
+
+from time import thread_time_ns
+
+def nounwind_fixup(frames, raised_rtn, not_raised_rtn):
+    not_raised = lambda lfixup : frames + 42		# use local scope => lexical link
+    if 0 < frames:
+        nounwind_fixup(frames - 1, raised_rtn, not_raised)
+    else:
+        fixup = 17;
+        raised_rtn(fixup);
+
+
+def main(argv):
+    times = 1
+    total_frames = 1
+    if 1 < len(argv):
+        times = int(argv[1])
+    if 2 < len(argv):
+        total_frames = int(argv[2])
+
+    raised = lambda lfixup : total_frames + 42		# use local scope => lexical link
+    not_raised = lambda lfixup : total_frames + 42	# use local scope => lexical link
+    start_time = thread_time_ns()
+    for count in range(times):
+        nounwind_fixup(total_frames, raised, not_raised)
+
+    end_time = thread_time_ns()
+    print('Run-Time (s): {:.1f}'.format((end_time - start_time) / 1_000_000_000.))
+
+
+if '__main__' == __name__:
+    import sys
+    main(sys.argv)
Index: doc/theses/andrew_beach_MMath/code/resume-detor.cfa
===================================================================
--- doc/theses/andrew_beach_MMath/code/resume-detor.cfa	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ doc/theses/andrew_beach_MMath/code/resume-detor.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -3,9 +3,8 @@
 #include <exception.hfa>
 #include <fstream.hfa>
-#include <stdlib.hfa>
+#include <stdlib.hfa>									// strto
 
-EHM_EXCEPTION(empty_exception)();
-
-EHM_VIRTUAL_TABLE(empty_exception, empty_vt);
+exception empty_exception;
+vtable(empty_exception) empty_vt;
 
 struct WithDestructor {};
@@ -17,5 +16,4 @@
 void unwind_destructor(unsigned int frames) {
 	if (frames) {
-
 		WithDestructor object;
 		unwind_destructor(frames - 1);
@@ -29,8 +27,8 @@
 	unsigned int total_frames = 1;
 	if (1 < argc) {
-		times = strtol(argv[1], 0p, 10);
+		times = strto(argv[1], 0p, 10);
 	}
 	if (2 < argc) {
-		total_frames = strtol(argv[2], 0p, 10);
+		total_frames = strto(argv[2], 0p, 10);
 	}
 
@@ -44,4 +42,4 @@
 	}
 	Time end_time = timeHiRes();
-	sout | "Run-Time (ns): " | (end_time - start_time)`ns;
+	sout | "Run-Time (s): " | wd(0,1, (end_time - start_time)`ns / 1_000_000_000.);
 }
Index: doc/theses/andrew_beach_MMath/code/resume-empty.cfa
===================================================================
--- doc/theses/andrew_beach_MMath/code/resume-empty.cfa	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ doc/theses/andrew_beach_MMath/code/resume-empty.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -3,13 +3,13 @@
 #include <exception.hfa>
 #include <fstream.hfa>
-#include <stdlib.hfa>
+#include <stdlib.hfa>									// strto
 
-EHM_EXCEPTION(empty_exception)();
+exception empty_exception;
+vtable(empty_exception) empty_vt;
 
-EHM_VIRTUAL_TABLE(empty_exception, empty_vt);
-
-void unwind_empty(unsigned int frames) {
+void nounwind_empty(unsigned int frames) {
 	if (frames) {
-		unwind_empty(frames - 1);
+		nounwind_empty(frames - 1);
+		if ( frames == -1 ) printf( "42" );				// prevent recursion optimizations
 	} else {
 		throwResume (empty_exception){&empty_vt};
@@ -21,14 +21,14 @@
 	unsigned int total_frames = 1;
 	if (1 < argc) {
-		times = strtol(argv[1], 0p, 10);
+		times = strto(argv[1], 0p, 10);
 	}
 	if (2 < argc) {
-		total_frames = strtol(argv[2], 0p, 10);
+		total_frames = strto(argv[2], 0p, 10);
 	}
 
 	Time start_time = timeHiRes();
-	for (int count = 0 ; count < times ; ++count) {
+	for (unsigned int count = 0 ; count < times ; ++count) {
 		try {
-			unwind_empty(total_frames);
+			nounwind_empty(total_frames);
 		} catchResume (empty_exception *) {
 			asm volatile ("# fixup block");
@@ -36,4 +36,4 @@
 	}
 	Time end_time = timeHiRes();
-	sout | "Run-Time (ns): " | (end_time - start_time)`ns;
+	sout | "Run-Time (s): " | wd(0,1, (end_time - start_time)`ns / 1_000_000_000.);
 }
Index: doc/theses/andrew_beach_MMath/code/resume-finally.cfa
===================================================================
--- doc/theses/andrew_beach_MMath/code/resume-finally.cfa	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ doc/theses/andrew_beach_MMath/code/resume-finally.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -3,9 +3,8 @@
 #include <exception.hfa>
 #include <fstream.hfa>
-#include <stdlib.hfa>
+#include <stdlib.hfa>									// strto
 
-EHM_EXCEPTION(empty_exception)();
-
-EHM_VIRTUAL_TABLE(empty_exception, empty_vt);
+exception empty_exception;
+vtable(empty_exception) empty_vt;
 
 void unwind_finally(unsigned int frames) {
@@ -25,8 +24,8 @@
 	unsigned int total_frames = 1;
 	if (1 < argc) {
-		times = strtol(argv[1], 0p, 10);
+		times = strto(argv[1], 0p, 10);
 	}
 	if (2 < argc) {
-		total_frames = strtol(argv[2], 0p, 10);
+		total_frames = strto(argv[2], 0p, 10);
 	}
 
@@ -40,4 +39,4 @@
 	}
 	Time end_time = timeHiRes();
-	sout | "Run-Time (ns): " | (end_time - start_time)`ns;
+	sout | "Run-Time (s): " | wd(0,1, (end_time - start_time)`ns / 1_000_000_000.);
 }
Index: doc/theses/andrew_beach_MMath/code/resume-other.cfa
===================================================================
--- doc/theses/andrew_beach_MMath/code/resume-other.cfa	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ doc/theses/andrew_beach_MMath/code/resume-other.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -3,16 +3,14 @@
 #include <exception.hfa>
 #include <fstream.hfa>
-#include <stdlib.hfa>
+#include <stdlib.hfa>									// strto
 
-EHM_EXCEPTION(empty_exception)();
+exception empty_exception;
+vtable(empty_exception) empty_vt;
+exception not_raised_exception;
 
-EHM_VIRTUAL_TABLE(empty_exception, empty_vt);
-
-EHM_EXCEPTION(not_raised_exception)();
-
-void unwind_other(unsigned int frames) {
+void nounwind_other(unsigned int frames) {
 	if (frames) {
 		try {
-			unwind_other(frames - 1);
+			nounwind_other(frames - 1);
 		} catchResume (not_raised_exception *) {
 			asm volatile ("# fixup block (stack)");
@@ -27,8 +25,8 @@
 	unsigned int total_frames = 1;
 	if (1 < argc) {
-		times = strtol(argv[1], 0p, 10);
+		times = strto(argv[1], 0p, 10);
 	}
 	if (2 < argc) {
-		total_frames = strtol(argv[2], 0p, 10);
+		total_frames = strto(argv[2], 0p, 10);
 	}
 
@@ -36,5 +34,5 @@
 	for (int count = 0 ; count < times ; ++count) {
 		try {
-			unwind_other(total_frames);
+			nounwind_other(total_frames);
 		} catchResume (empty_exception *) {
 			asm volatile ("# fixup block (base)");
@@ -42,4 +40,4 @@
 	}
 	Time end_time = timeHiRes();
-	sout | "Run-Time (ns): " | (end_time - start_time)`ns;
+	sout | "Run-Time (s): " | wd(0,1, (end_time - start_time)`ns / 1_000_000_000.);
 }
Index: doc/theses/andrew_beach_MMath/code/run.sh
===================================================================
--- doc/theses/andrew_beach_MMath/code/run.sh	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ doc/theses/andrew_beach_MMath/code/run.sh	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -1,6 +1,6 @@
 #!/usr/bin/env bash
 
-readonly ALL_TESTS=(cond-match-{all,none} cross-{catch,finally} \
-		raise-{detor,empty,finally,other})
+readonly ALL_TESTS=(raise-{empty,detor,finally,other} try-{catch,finally} \
+			cond-match-{all,none} fixup-{empty,other})
 
 gen-file-name() (
@@ -18,5 +18,5 @@
 )
 
-readonly N=${1:-5}
+readonly N=${1:-1}
 readonly OUT_FILE=$(gen-file-name ${2:-run-%-$N})
 
Index: doc/theses/andrew_beach_MMath/code/test.sh
===================================================================
--- doc/theses/andrew_beach_MMath/code/test.sh	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ doc/theses/andrew_beach_MMath/code/test.sh	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -4,10 +4,22 @@
 # test.sh LANGUAGE TEST
 #   Run the TEST in LANGUAGE.
+# test.sh -a
+#   Build all tests.
 # test.sh -b SOURCE_FILE...
 #   Build a test from SOURCE_FILE(s).
+# test.sh -c
+#   Clean all executables.
 # test.sh -v LANGUAGE TEST FILE
 #   View the result from TEST in LANGUAGE stored in FILE.
 
-readonly ITERATIONS=1000000 # 1 000 000, one million
+readonly DIR=$(dirname "$(readlink -f "$0")")
+cd $DIR
+
+readonly MIL=000000
+# Various preset values used as arguments.
+readonly ITERS_1M=1$MIL
+readonly ITERS_10M=10$MIL
+readonly ITERS_100M=100$MIL
+readonly ITERS_1000M=1000$MIL
 readonly STACK_HEIGHT=100
 
@@ -23,9 +35,13 @@
 	case "$1" in
 	*.cfa)
-		# Requires a symbolic link.
-		mmake "${1%.cfa}" "$1" ./cfa -DNDEBUG -nodebug -O3 "$1" -o "${1%.cfa}"
+		# A symbolic link/local copy can be used as an override.
+		cmd=./cfa
+		if [ ! -x $cmd ]; then
+			cmd=cfa
+		fi
+		mmake "${1%.cfa}" "$1" $cmd -DNDEBUG -nodebug -O3 "$1" -o "${1%.cfa}"
 		;;
 	*.cpp)
-		mmake "${1%.cpp}-cpp" "$1" g++ -DNDEBUG -O3 "$1" -o "${1%.cpp}-cpp"
+		mmake "${1%.cpp}-cpp" "$1" g++-10 -DNDEBUG -O3 "$1" -o "${1%.cpp}-cpp"
 		;;
 	*.java)
@@ -39,13 +55,24 @@
 )
 
-if [ "-b" = "$1" ]; then
+if [ "-a" = "$1" ]; then
+	for file in *.cfa *.cpp *.java; do
+		build $file
+	done
+	exit 0
+elif [ "-b" = "$1" ]; then
 	for file in "${@:2}"; do
 		build $file
 	done
 	exit 0
+elif [ "-c" = "$1" ]; then
+	rm $(basename -s ".cfa" -a *.cfa)
+	rm $(basename -s ".cpp" -a *.cpp)
+	rm *-cpp
+	rm *.class
+	exit 0
 elif [ "-v" = "$1" -a 4 = "$#" ]; then
-    TEST_LANG="$2"
-    TEST_CASE="$3"
-    VIEW_FILE="$4"
+	TEST_LANG="$2"
+	TEST_CASE="$3"
+	VIEW_FILE="$4"
 elif [ 2 -eq "$#" ]; then
 	TEST_LANG="$1"
@@ -63,59 +90,73 @@
 
 case "$TEST_CASE" in
-cond-match-all)
-	CFAT="./cond-catch $ITERATIONS 1"
-	CFAR="./cond-fixup $ITERATIONS 1"
-	CPP="./cond-catch-cpp $ITERATIONS 1"
-	JAVA="java CondCatch $ITERATIONS 1"
-	PYTHON="./cond_catch.py $ITERATIONS 1"
-	;;
-cond-match-none)
-	CFAT="./cond-catch $ITERATIONS 0"
-	CFAR="./cond-fixup $ITERATIONS 0"
-	CPP="./cond-catch-cpp $ITERATIONS 0"
-	JAVA="java CondCatch $ITERATIONS 0"
-	PYTHON="./cond_catch.py $ITERATIONS 0"
-	;;
-cross-catch)
-	CFAT="./cross-catch $ITERATIONS"
-	CFAR="./cross-resume $ITERATIONS"
-	CPP="./cross-catch-cpp $ITERATIONS"
-	JAVA="java CrossCatch $ITERATIONS"
-	PYTHON="./cross_catch.py $ITERATIONS"
-	;;
-cross-finally)
-	CFAT="./cross-finally $ITERATIONS"
-	CFAR=unsupported
-	CPP=unsupported
-	JAVA="java CrossFinally $ITERATIONS"
-	PYTHON="./cross_finally.py $ITERATIONS"
+raise-empty)
+	CFAT="./throw-empty $ITERS_1M $STACK_HEIGHT"
+	CFAR="./resume-empty $ITERS_10M $STACK_HEIGHT"
+	CPP="./throw-empty-cpp $ITERS_1M $STACK_HEIGHT"
+	JAVA="java ThrowEmpty $ITERS_1M $STACK_HEIGHT"
+	PYTHON="./throw-empty.py $ITERS_1M $STACK_HEIGHT"
 	;;
 raise-detor)
-	CFAT="./throw-detor $ITERATIONS $STACK_HEIGHT"
-	CFAR="./resume-detor $ITERATIONS $STACK_HEIGHT"
-	CPP="./throw-detor-cpp $ITERATIONS $STACK_HEIGHT"
+	CFAT="./throw-detor $ITERS_1M $STACK_HEIGHT"
+	CFAR="./resume-detor $ITERS_10M $STACK_HEIGHT"
+	CPP="./throw-detor-cpp $ITERS_1M $STACK_HEIGHT"
 	JAVA=unsupported
 	PYTHON=unsupported
 	;;
-raise-empty)
-	CFAT="./throw-empty $ITERATIONS $STACK_HEIGHT"
-	CFAR="./resume-empty $ITERATIONS $STACK_HEIGHT"
-	CPP="./throw-empty-cpp $ITERATIONS $STACK_HEIGHT"
-	JAVA="java ThrowEmpty $ITERATIONS $STACK_HEIGHT"
-	PYTHON="./throw_empty.py $ITERATIONS $STACK_HEIGHT"
-	;;
 raise-finally)
-	CFAT="./throw-finally $ITERATIONS $STACK_HEIGHT"
-	CFAR="./resume-finally $ITERATIONS $STACK_HEIGHT"
+	CFAT="./throw-finally $ITERS_1M $STACK_HEIGHT"
+	CFAR="./resume-finally $ITERS_10M $STACK_HEIGHT"
 	CPP=unsupported
-	JAVA="java ThrowFinally $ITERATIONS $STACK_HEIGHT"
-	PYTHON="./throw_finally.py $ITERATIONS $STACK_HEIGHT"
+	JAVA="java ThrowFinally $ITERS_1M $STACK_HEIGHT"
+	PYTHON="./throw-finally.py $ITERS_1M $STACK_HEIGHT"
 	;;
 raise-other)
-	CFAT="./throw-other $ITERATIONS $STACK_HEIGHT"
-	CFAR="./resume-other $ITERATIONS $STACK_HEIGHT"
-	CPP="./throw-other-cpp $ITERATIONS $STACK_HEIGHT"
-	JAVA="java ThrowOther $ITERATIONS $STACK_HEIGHT"
-	PYTHON="./throw_other.py $ITERATIONS $STACK_HEIGHT"
+	CFAT="./throw-other $ITERS_1M $STACK_HEIGHT"
+	CFAR="./resume-other $ITERS_10M $STACK_HEIGHT"
+	CPP="./throw-other-cpp $ITERS_1M $STACK_HEIGHT"
+	JAVA="java ThrowOther $ITERS_1M $STACK_HEIGHT"
+	PYTHON="./throw-other.py $ITERS_1M $STACK_HEIGHT"
+	;;
+try-catch)
+	CFAT="./try-catch $ITERS_1000M"
+	CFAR="./try-resume $ITERS_1000M"
+	CPP="./try-catch-cpp $ITERS_1000M"
+	JAVA="java TryCatch $ITERS_1000M"
+	PYTHON="./try-catch.py $ITERS_1000M"
+	;;
+try-finally)
+	CFAT="./try-finally $ITERS_1000M"
+	CFAR=unsupported
+	CPP=unsupported
+	JAVA="java TryFinally $ITERS_1000M"
+	PYTHON="./try-finally.py $ITERS_1000M"
+	;;
+cond-match-all)
+	CFAT="./cond-catch $ITERS_10M 1"
+	CFAR="./cond-fixup $ITERS_100M 1"
+	CPP="./cond-catch-cpp $ITERS_10M 1"
+	JAVA="java CondCatch $ITERS_10M 1"
+	PYTHON="./cond-catch.py $ITERS_10M 1"
+	;;
+cond-match-none)
+	CFAT="./cond-catch $ITERS_10M 0"
+	CFAR="./cond-fixup $ITERS_100M 0"
+	CPP="./cond-catch-cpp $ITERS_10M 0"
+	JAVA="java CondCatch $ITERS_10M 0"
+	PYTHON="./cond-catch.py $ITERS_10M 0"
+	;;
+fixup-empty)
+	CFAT="./fixup-empty-f $ITERS_10M $STACK_HEIGHT"
+	CFAR="./fixup-empty-r $ITERS_10M $STACK_HEIGHT"
+	CPP="./fixup-empty-cpp $ITERS_10M $STACK_HEIGHT"
+	JAVA="java FixupEmpty $ITERS_10M $STACK_HEIGHT"
+	PYTHON="./fixup-empty.py $ITERS_10M $STACK_HEIGHT"
+	;;
+fixup-other)
+	CFAT="./fixup-other-f $ITERS_10M $STACK_HEIGHT"
+	CFAR="./fixup-other-r $ITERS_10M $STACK_HEIGHT"
+	CPP="./fixup-other-cpp $ITERS_10M $STACK_HEIGHT"
+	JAVA="java FixupOther $ITERS_10M $STACK_HEIGHT"
+	PYTHON="./fixup-other.py $ITERS_10M $STACK_HEIGHT"
 	;;
 *)
@@ -140,6 +181,6 @@
 
 if [ -n "$VIEW_FILE" ]; then
-    grep -A 1 -B 0 "$CALL" "$VIEW_FILE" | sed -n -e 's!Run-Time (ns): !!;T;p'
-    exit
+	grep -A 1 -B 0 "$CALL" "$VIEW_FILE" | sed -n -e 's!Run-Time.*: !!;T;p'
+	exit
 fi
 
Index: doc/theses/andrew_beach_MMath/code/throw-detor.cfa
===================================================================
--- doc/theses/andrew_beach_MMath/code/throw-detor.cfa	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ doc/theses/andrew_beach_MMath/code/throw-detor.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -3,9 +3,8 @@
 #include <exception.hfa>
 #include <fstream.hfa>
-#include <stdlib.hfa>
+#include <stdlib.hfa>									// strto
 
-EHM_EXCEPTION(empty_exception)();
-
-EHM_VIRTUAL_TABLE(empty_exception, empty_vt);
+exception empty_exception;
+vtable(empty_exception) empty_vt;
 
 struct WithDestructor {};
@@ -28,8 +27,8 @@
 	unsigned int total_frames = 1;
 	if (1 < argc) {
-		times = strtol(argv[1], 0p, 10);
+		times = strto(argv[1], 0p, 10);
 	}
 	if (2 < argc) {
-		total_frames = strtol(argv[2], 0p, 10);
+		total_frames = strto(argv[2], 0p, 10);
 	}
 
@@ -43,4 +42,4 @@
 	}
 	Time end_time = timeHiRes();
-	sout | "Run-Time (ns): " | (end_time - start_time)`ns;
+	sout | "Run-Time (s): " | wd(0,1, (end_time - start_time)`ns / 1_000_000_000.);
 }
Index: doc/theses/andrew_beach_MMath/code/throw-detor.cpp
===================================================================
--- doc/theses/andrew_beach_MMath/code/throw-detor.cpp	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ doc/theses/andrew_beach_MMath/code/throw-detor.cpp	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -4,5 +4,7 @@
 #include <exception>
 #include <iostream>
+#include <iomanip>
 
+using namespace std;
 using namespace std::chrono;
 
@@ -44,4 +46,4 @@
 	time_point<steady_clock> end_time = steady_clock::now();
 	nanoseconds duration = duration_cast<nanoseconds>(end_time - start_time);
-	std::cout << "Run-Time (ns): " << duration.count() << std::endl;
+	cout << "Run-Time (s): " << fixed << setprecision(1) << duration.count() / 1'000'000'000. << endl;
 }
Index: doc/theses/andrew_beach_MMath/code/throw-empty.cfa
===================================================================
--- doc/theses/andrew_beach_MMath/code/throw-empty.cfa	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ doc/theses/andrew_beach_MMath/code/throw-empty.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -3,13 +3,13 @@
 #include <exception.hfa>
 #include <fstream.hfa>
-#include <stdlib.hfa>
+#include <stdlib.hfa>									// strto
 
-EHM_EXCEPTION(empty_exception)();
-
-EHM_VIRTUAL_TABLE(empty_exception, empty_vt);
+exception empty_exception;
+vtable(empty_exception) empty_vt;
 
 void unwind_empty(unsigned int frames) {
 	if (frames) {
 		unwind_empty(frames - 1);
+		if ( frames == -1 ) printf( "42" );                             // prevent recursion optimizations
 	} else {
 		throw (empty_exception){&empty_vt};
@@ -21,8 +21,8 @@
 	unsigned int total_frames = 1;
 	if (1 < argc) {
-		times = strtol(argv[1], 0p, 10);
+		times = strto(argv[1], 0p, 10);
 	}
 	if (2 < argc) {
-		total_frames = strtol(argv[2], 0p, 10);
+		total_frames = strto(argv[2], 0p, 10);
 	}
 
@@ -36,4 +36,4 @@
 	}
 	Time end_time = timeHiRes();
-	sout | "Run-Time (ns): " | (end_time - start_time)`ns;
+	sout | "Run-Time (s): " | wd(0,1, (end_time - start_time)`ns / 1_000_000_000.);
 }
Index: doc/theses/andrew_beach_MMath/code/throw-empty.cpp
===================================================================
--- doc/theses/andrew_beach_MMath/code/throw-empty.cpp	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ doc/theses/andrew_beach_MMath/code/throw-empty.cpp	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -1,8 +1,11 @@
 // Throw Across Empty Function
 #include <chrono>
+#include <cstdio>
 #include <cstdlib>
 #include <exception>
 #include <iostream>
+#include <iomanip>
 
+using namespace std;
 using namespace std::chrono;
 
@@ -12,4 +15,5 @@
 	if (frames) {
 		unwind_empty(frames - 1);
+		if (-1 == frames) printf("~");
 	} else {
 		throw (EmptyException){};
@@ -37,4 +41,4 @@
 	time_point<steady_clock> end_time = steady_clock::now();
 	nanoseconds duration = duration_cast<nanoseconds>(end_time - start_time);
-	std::cout << "Run-Time (ns): " << duration.count() << std::endl;
+	cout << "Run-Time (s): " << fixed << setprecision(1) << duration.count() / 1'000'000'000. << endl;
 }
Index: doc/theses/andrew_beach_MMath/code/throw-empty.py
===================================================================
--- doc/theses/andrew_beach_MMath/code/throw-empty.py	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
+++ doc/theses/andrew_beach_MMath/code/throw-empty.py	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -0,0 +1,40 @@
+#!/usr/bin/env python3
+
+# Throw Across Empty Function
+
+from time import thread_time_ns
+
+
+class EmptyException(Exception):
+    pass
+
+
+def unwind_empty(frames):
+    if 0 < frames:
+        unwind_empty(frames - 1)
+    else:
+        raise EmptyException()
+
+
+def main(argv):
+    times = 1
+    total_frames = 1
+    if 1 < len(argv):
+        times = int(argv[1])
+    if 2 < len(argv):
+        total_frames = int(argv[2])
+
+    start_time = thread_time_ns()
+    for count in range(times):
+        try:
+            unwind_empty(total_frames)
+        except EmptyException:
+            pass
+
+    end_time = thread_time_ns()
+    print('Run-Time (s): {:.1f}'.format((end_time - start_time) / 1_000_000_000.))
+
+
+if '__main__' == __name__:
+    import sys
+    main(sys.argv)
Index: doc/theses/andrew_beach_MMath/code/throw-finally.cfa
===================================================================
--- doc/theses/andrew_beach_MMath/code/throw-finally.cfa	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ doc/theses/andrew_beach_MMath/code/throw-finally.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -3,18 +3,21 @@
 #include <exception.hfa>
 #include <fstream.hfa>
-#include <stdlib.hfa>
+#include <stdlib.hfa>									// strto
 
-EHM_EXCEPTION(empty_exception)();
+exception empty_exception;
+vtable(empty_exception) empty_vt;
 
-EHM_VIRTUAL_TABLE(empty_exception, empty_vt);
+unsigned int frames;									// use global because of gcc thunk problem
 
-void unwind_finally(unsigned int frames) {
+void unwind_finally(unsigned int dummy) {
 	if (frames) {
+		frames -= 1;
 		try {
-			unwind_finally(frames - 1);
+			unwind_finally(42);
 		} finally {
 			asm volatile ("# finally block");
 		}
 	} else {
+		dummy = 42;
 		throw (empty_exception){&empty_vt};
 	}
@@ -25,14 +28,15 @@
 	unsigned int total_frames = 1;
 	if (1 < argc) {
-		times = strtol(argv[1], 0p, 10);
+		times = strto(argv[1], 0p, 10);
 	}
 	if (2 < argc) {
-		total_frames = strtol(argv[2], 0p, 10);
+		total_frames = strto(argv[2], 0p, 10);
 	}
+	frames = total_frames;
 
 	Time start_time = timeHiRes();
 	for (int count = 0 ; count < times ; ++count) {
 		try {
-			unwind_finally(total_frames);
+			unwind_finally(42);
 		} catch (empty_exception *) {
 			asm volatile ("# catch block");
@@ -40,4 +44,4 @@
 	}
 	Time end_time = timeHiRes();
-	sout | "Run-Time (ns): " | (end_time - start_time)`ns;
+	sout | "Run-Time (s): " | wd(0,1, (end_time - start_time)`ns / 1_000_000_000.);
 }
Index: doc/theses/andrew_beach_MMath/code/throw-finally.py
===================================================================
--- doc/theses/andrew_beach_MMath/code/throw-finally.py	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
+++ doc/theses/andrew_beach_MMath/code/throw-finally.py	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -0,0 +1,43 @@
+#!/usr/bin/env python3
+
+# Throw Across Finally
+
+from time import thread_time_ns
+
+
+class EmptyException(Exception):
+    pass
+
+
+def unwind_finally(frames):
+    if 0 < frames:
+        try:
+            unwind_finally(frames - 1)
+        finally:
+            pass
+    else:
+        raise EmptyException()
+
+
+def main(argv):
+    times = 1
+    total_frames = 1
+    if 1 < len(argv):
+        times = int(argv[1])
+    if 2 < len(argv):
+        total_frames = int(argv[2])
+
+    start_time = thread_time_ns()
+    for count in range(times):
+        try:
+            unwind_finally(total_frames)
+        except EmptyException:
+            pass
+
+    end_time = thread_time_ns()
+    print('Run-Time (s): {:.1f}'.format((end_time - start_time) / 1_000_000_000.))
+
+
+if '__main__' == __name__:
+    import sys
+    main(sys.argv)
Index: doc/theses/andrew_beach_MMath/code/throw-other.cfa
===================================================================
--- doc/theses/andrew_beach_MMath/code/throw-other.cfa	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ doc/theses/andrew_beach_MMath/code/throw-other.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -3,20 +3,22 @@
 #include <exception.hfa>
 #include <fstream.hfa>
-#include <stdlib.hfa>
+#include <stdlib.hfa>									// strto
 
-EHM_EXCEPTION(empty_exception)();
+exception empty_exception;
+vtable(empty_exception) empty_vt;
+exception not_raised_exception;
 
-EHM_VIRTUAL_TABLE(empty_exception, empty_vt);
+unsigned int frames;									// use global because of gcc thunk problem
 
-EHM_EXCEPTION(not_raised_exception)();
-
-void unwind_other(unsigned int frames) {
+void unwind_other(unsigned int dummy) {
 	if (frames) {
+		frames -= 1;
 		try {
-			unwind_other(frames - 1);
+			unwind_other(42);
 		} catch (not_raised_exception *) {
 			asm volatile ("# catch block (stack)");
 		}
 	} else {
+		dummy = 42;
 		throw (empty_exception){&empty_vt};
 	}
@@ -27,14 +29,15 @@
 	unsigned int total_frames = 1;
 	if (1 < argc) {
-		times = strtol(argv[1], 0p, 10);
+		times = strto(argv[1], 0p, 10);
 	}
 	if (2 < argc) {
-		total_frames = strtol(argv[2], 0p, 10);
+		total_frames = strto(argv[2], 0p, 10);
 	}
+	frames = total_frames;
 
 	Time start_time = timeHiRes();
 	for (int count = 0 ; count < times ; ++count) {
 		try {
-			unwind_other(total_frames);
+			unwind_other(42);
 		} catch (empty_exception *) {
 			asm volatile ("# catch block (base)");
@@ -42,4 +45,4 @@
 	}
 	Time end_time = timeHiRes();
-	sout | "Run-Time (ns): " | (end_time - start_time)`ns;
+	sout | "Run-Time (s): " | wd(0,1, (end_time - start_time)`ns / 1_000_000_000.);
 }
Index: doc/theses/andrew_beach_MMath/code/throw-other.cpp
===================================================================
--- doc/theses/andrew_beach_MMath/code/throw-other.cpp	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ doc/theses/andrew_beach_MMath/code/throw-other.cpp	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -4,5 +4,7 @@
 #include <exception>
 #include <iostream>
+#include <iomanip>
 
+using namespace std;
 using namespace std::chrono;
 
@@ -43,4 +45,4 @@
 	time_point<steady_clock> end_time = steady_clock::now();
 	nanoseconds duration = duration_cast<nanoseconds>(end_time - start_time);
-	std::cout << "Run-Time (ns): " << duration.count() << std::endl;
+	cout << "Run-Time (s): " << fixed << setprecision(1) << duration.count() / 1'000'000'000. << endl;
 }
Index: doc/theses/andrew_beach_MMath/code/throw-other.py
===================================================================
--- doc/theses/andrew_beach_MMath/code/throw-other.py	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
+++ doc/theses/andrew_beach_MMath/code/throw-other.py	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -0,0 +1,47 @@
+#!/usr/bin/env python3
+
+# Throw Across Other Handler
+
+from time import thread_time_ns
+
+
+class EmptyException(Exception):
+    pass
+
+
+class NotRaisedException(Exception):
+    pass
+
+
+def unwind_other(frames):
+    if 0 < frames:
+        try:
+            unwind_other(frames - 1)
+        except NotRaisedException:
+            pass
+    else:
+        raise EmptyException()
+
+
+def main(argv):
+    times = 1
+    total_frames = 1
+    if 1 < len(argv):
+        times = int(argv[1])
+    if 2 < len(argv):
+        total_frames = int(argv[2])
+
+    start_time = thread_time_ns()
+    for count in range(times):
+        try:
+            unwind_other(total_frames)
+        except EmptyException:
+            pass
+
+    end_time = thread_time_ns()
+    print('Run-Time (s): {:.1f}'.format((end_time - start_time) / 1_000_000_000.))
+
+
+if '__main__' == __name__:
+    import sys
+    main(sys.argv)
Index: doc/theses/andrew_beach_MMath/code/throw-with.py
===================================================================
--- doc/theses/andrew_beach_MMath/code/throw-with.py	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
+++ doc/theses/andrew_beach_MMath/code/throw-with.py	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -0,0 +1,50 @@
+#!/usr/bin/env python3
+
+# Throw Across With Statement (closest thing Python has to a destructor)
+
+from time import thread_time_ns
+
+
+class EmptyException(Exception):
+    pass
+
+
+class EmptyContextManager:
+
+    def __enter__(self):
+        pass
+
+    def __exit__(self, exception_type, exception_value, traceback):
+        pass
+
+
+def unwind_with(frames):
+    if 0 < frames:
+        with EmptyContextManager():
+            unwind_with(frames - 1)
+    else:
+        raise EmptyException()
+
+
+def main(argv):
+    times = 1
+    total_frames = 1
+    if 1 < len(argv):
+        times = int(argv[1])
+    if 2 < len(argv):
+        total_frames = int(argv[2])
+
+    start_time = thread_time_ns()
+    for count in range(times):
+        try:
+            unwind_with(total_frames)
+        except EmptyException:
+            pass
+
+    end_time = thread_time_ns()
+    print('Run-Time (s): {:.1f}'.format((end_time - start_time) / 1_000_000_000.))
+
+
+if '__main__' == __name__:
+    import sys
+    main(sys.argv)
Index: c/theses/andrew_beach_MMath/code/throw_empty.py
===================================================================
--- doc/theses/andrew_beach_MMath/code/throw_empty.py	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ 	(revision )
@@ -1,40 +1,0 @@
-#!/usr/bin/env python3
-
-# Throw Across Empty Function
-
-from time import thread_time_ns
-
-
-class EmptyException(Exception):
-    pass
-
-
-def unwind_empty(frames):
-    if 0 < frames:
-        unwind_empty(frames - 1)
-    else:
-        raise EmptyException()
-
-
-def main(argv):
-    times = 1
-    total_frames = 1
-    if 1 < len(argv):
-        times = int(argv[1])
-    if 2 < len(argv):
-        total_frames = int(argv[2])
-
-    start_time = thread_time_ns()
-    for count in range(times):
-        try:
-            unwind_empty(total_frames)
-        except EmptyException:
-            pass
-
-    end_time = thread_time_ns()
-    print('Run-Time (ns):', end_time - start_time)
-
-
-if '__main__' == __name__:
-    import sys
-    main(sys.argv)
Index: c/theses/andrew_beach_MMath/code/throw_finally.py
===================================================================
--- doc/theses/andrew_beach_MMath/code/throw_finally.py	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ 	(revision )
@@ -1,43 +1,0 @@
-#!/usr/bin/env python3
-
-# Throw Across Finally
-
-from time import thread_time_ns
-
-
-class EmptyException(Exception):
-    pass
-
-
-def unwind_finally(frames):
-    if 0 < frames:
-        try:
-            unwind_finally(frames - 1)
-        finally:
-            pass
-    else:
-        raise EmptyException()
-
-
-def main(argv):
-    times = 1
-    total_frames = 1
-    if 1 < len(argv):
-        times = int(argv[1])
-    if 2 < len(argv):
-        total_frames = int(argv[2])
-
-    start_time = thread_time_ns()
-    for count in range(times):
-        try:
-            unwind_finally(total_frames)
-        except EmptyException:
-            pass
-
-    end_time = thread_time_ns()
-    print('Run-Time (ns):', end_time - start_time)
-
-
-if '__main__' == __name__:
-    import sys
-    main(sys.argv)
Index: c/theses/andrew_beach_MMath/code/throw_other.py
===================================================================
--- doc/theses/andrew_beach_MMath/code/throw_other.py	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ 	(revision )
@@ -1,47 +1,0 @@
-#!/usr/bin/env python3
-
-# Throw Across Other Handler
-
-from time import thread_time_ns
-
-
-class EmptyException(Exception):
-    pass
-
-
-class NotRaisedException(Exception):
-    pass
-
-
-def unwind_other(frames):
-    if 0 < frames:
-        try:
-            unwind_other(frames - 1)
-        except NotRaisedException:
-            pass
-    else:
-        raise EmptyException()
-
-
-def main(argv):
-    times = 1
-    total_frames = 1
-    if 1 < len(argv):
-        times = int(argv[1])
-    if 2 < len(argv):
-        total_frames = int(argv[2])
-
-    start_time = thread_time_ns()
-    for count in range(times):
-        try:
-            unwind_other(total_frames)
-        except EmptyException:
-            pass
-
-    end_time = thread_time_ns()
-    print('Run-Time (ns):', end_time - start_time)
-
-
-if '__main__' == __name__:
-    import sys
-    main(sys.argv)
Index: c/theses/andrew_beach_MMath/code/throw_with.py
===================================================================
--- doc/theses/andrew_beach_MMath/code/throw_with.py	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ 	(revision )
@@ -1,50 +1,0 @@
-#!/usr/bin/env python3
-
-# Throw Across With Statement (closest thing Python has to a destructor)
-
-from time import thread_time_ns
-
-
-class EmptyException(Exception):
-    pass
-
-
-class EmptyContextManager:
-
-    def __enter__(self):
-        pass
-
-    def __exit__(self, exception_type, exception_value, traceback):
-        pass
-
-
-def unwind_with(frames):
-    if 0 < frames:
-        with EmptyContextManager():
-            unwind_with(frames - 1)
-    else:
-        raise EmptyException()
-
-
-def main(argv):
-    times = 1
-    total_frames = 1
-    if 1 < len(argv):
-        times = int(argv[1])
-    if 2 < len(argv):
-        total_frames = int(argv[2])
-
-    start_time = thread_time_ns()
-    for count in range(times):
-        try:
-            unwind_with(total_frames)
-        except EmptyException:
-            pass
-
-    end_time = thread_time_ns()
-    print('Run-Time (ns):', end_time - start_time)
-
-
-if '__main__' == __name__:
-    import sys
-    main(sys.argv)
Index: doc/theses/andrew_beach_MMath/code/try-catch.cfa
===================================================================
--- doc/theses/andrew_beach_MMath/code/try-catch.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
+++ doc/theses/andrew_beach_MMath/code/try-catch.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -0,0 +1,30 @@
+// Cross a Try Statement with a Termination Handler
+#include <clock.hfa>
+#include <exception.hfa>
+#include <fstream.hfa>
+#include <stdlib.hfa>									// strto
+
+exception not_raised_exception;
+vtable(not_raised_exception) not_vt;
+
+int main(int argc, char * argv[]) {
+	unsigned int times = 1;
+	volatile bool should_throw = false;
+	if (1 < argc) {
+		times = strto(argv[1], 0p, 10);
+	}
+
+	Time start_time = timeHiRes();
+	for (unsigned int count = 0 ; count < times ; ++count) {
+		try {
+			asm volatile ("# try block");
+			if (should_throw) {
+				throw (not_raised_exception){&not_vt};
+			}
+		} catch (not_raised_exception *) {
+			asm volatile ("# catch block");
+		}
+	}
+	Time end_time = timeHiRes();
+	sout | "Run-Time (s): " | wd(0,1, (end_time - start_time)`ns / 1_000_000_000.);
+}
Index: doc/theses/andrew_beach_MMath/code/try-catch.cpp
===================================================================
--- doc/theses/andrew_beach_MMath/code/try-catch.cpp	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
+++ doc/theses/andrew_beach_MMath/code/try-catch.cpp	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -0,0 +1,34 @@
+// Cross a Try Statement with a Termination Handler
+#include <chrono>
+#include <cstdlib>
+#include <exception>
+#include <iostream>
+#include <iomanip>
+
+using namespace std;
+using namespace std::chrono;
+
+struct NotRaisedException : public std::exception {};
+
+int main(int argc, char * argv[]) {
+	unsigned int times = 1;
+	volatile bool should_throw = false;
+	if (1 < argc) {
+		times = strtol(argv[1], nullptr, 10);
+	}
+
+	time_point<steady_clock> start_time = steady_clock::now();
+	for (unsigned int count = 0 ; count < times ; ++count) {
+		try {
+			asm volatile ("# try block");
+			if (should_throw) {
+				throw NotRaisedException();
+			}
+		} catch (NotRaisedException &) {
+			asm volatile ("# catch block");
+		}
+	}
+	time_point<steady_clock> end_time = steady_clock::now();
+	nanoseconds duration = duration_cast<nanoseconds>(end_time - start_time);
+	cout << "Run-Time (s): " << fixed << setprecision(1) << duration.count() / 1'000'000'000. << endl;
+}
Index: doc/theses/andrew_beach_MMath/code/try-catch.py
===================================================================
--- doc/theses/andrew_beach_MMath/code/try-catch.py	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
+++ doc/theses/andrew_beach_MMath/code/try-catch.py	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -0,0 +1,30 @@
+#!/usr/bin/env python3
+
+# Cross a Try Statement with a Termination Handler
+
+from time import thread_time_ns
+
+
+class NotRaisedException(Exception):
+    pass
+
+
+def main(argv):
+    times = 1;
+    if 1 < len(argv):
+        times = int(argv[1])
+
+    start_time = thread_time_ns()
+    for count in range(times):
+        try:
+            pass
+        except NotRaisedException:
+            pass
+
+    end_time = thread_time_ns()
+    print('Run-Time (s): {:.1f}'.format((end_time - start_time) / 1_000_000_000.))
+
+
+if '__main__' == __name__:
+    import sys
+    main(sys.argv)
Index: doc/theses/andrew_beach_MMath/code/try-finally.cfa
===================================================================
--- doc/theses/andrew_beach_MMath/code/try-finally.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
+++ doc/theses/andrew_beach_MMath/code/try-finally.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -0,0 +1,30 @@
+// Cross a Try Statement With Finally Clause
+#include <clock.hfa>
+#include <exception.hfa>
+#include <fstream.hfa>
+#include <stdlib.hfa>									// strto
+
+exception not_raised_exception;
+vtable(not_raised_exception) not_vt;
+
+int main(int argc, char * argv[]) {
+	unsigned int times = 1;
+	volatile bool should_throw = false;
+	if (1 < argc) {
+		times = strto(argv[1], 0p, 10);
+	}
+
+	Time start_time = timeHiRes();
+	for (unsigned int count = 0 ; count < times ; ++count) {
+		try {
+			asm volatile ("# try block");
+			if (should_throw) {
+				throw (not_raised_exception){&not_vt};
+			}
+		} finally {
+			asm volatile ("# finally block");
+		}
+	}
+	Time end_time = timeHiRes();
+	sout | "Run-Time (s): " | wd(0,1, (end_time - start_time)`ns / 1_000_000_000.);
+}
Index: doc/theses/andrew_beach_MMath/code/try-finally.py
===================================================================
--- doc/theses/andrew_beach_MMath/code/try-finally.py	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
+++ doc/theses/andrew_beach_MMath/code/try-finally.py	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -0,0 +1,29 @@
+#!/usr/bin/env python3
+
+# Cross a Try Statement With Finally Clause
+
+from time import thread_time_ns
+
+
+def main(argv):
+    times = 1;
+    total_frames = 1;
+    if 1 < len(argv):
+        times = int(argv[1])
+    if 2 < len(argv):
+        total_frames = int(argv[2])
+
+    start_time = thread_time_ns()
+    for count in range(times):
+        try:
+            pass
+        finally:
+            pass
+
+    end_time = thread_time_ns()
+    print('Run-Time (s): {:.1f}'.format((end_time - start_time) / 1_000_000_000.))
+
+
+if '__main__' == __name__:
+    import sys
+    main(sys.argv)
Index: doc/theses/andrew_beach_MMath/code/try-resume.cfa
===================================================================
--- doc/theses/andrew_beach_MMath/code/try-resume.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
+++ doc/theses/andrew_beach_MMath/code/try-resume.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -0,0 +1,29 @@
+// Cross a Try Statement With Finally Clause
+#include <clock.hfa>
+#include <exception.hfa>
+#include <fstream.hfa>
+#include <stdlib.hfa>									// strto
+
+exception not_raised_exception;
+
+int main(int argc, char * argv[]) {
+	unsigned int times = 1;
+	unsigned int total_frames = 1;
+	if (1 < argc) {
+		times = strto(argv[1], 0p, 10);
+	}
+	if (2 < argc) {
+		total_frames = strto(argv[2], 0p, 10);
+	}
+
+	Time start_time = timeHiRes();
+	for (unsigned int count = 0 ; count < times ; ++count) {
+		try {
+			asm volatile ("");
+		} catchResume (not_raised_exception *) {
+			asm volatile ("");
+		}
+	}
+	Time end_time = timeHiRes();
+	sout | "Run-Time (s): " | wd(0,1, (end_time - start_time)`ns / 1_000_000_000.);
+}
Index: doc/theses/andrew_beach_MMath/conclusion.tex
===================================================================
--- doc/theses/andrew_beach_MMath/conclusion.tex	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ doc/theses/andrew_beach_MMath/conclusion.tex	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -1,19 +1,28 @@
 \chapter{Conclusion}
+\label{c:conclusion}
 % Just a little knot to tie the paper together.
 
-In the previous chapters this thesis presents the design and implementation
+In the previous chapters, this thesis presents the design and implementation
 of \CFA's exception handling mechanism (EHM).
-Both the design and implementation are based off of tools and techniques
-developed for other programming languages but they were adapted to better fit
-\CFA's feature set.
+Both the design and implementation are based off of tools and
+techniques developed for other programming languages but they were adapted to
+better fit \CFA's feature set and add a few features that do not exist in
+other EHMs,
+including conditional matching, default handlers for unhandled exceptions
+and cancellation though coroutines and threads back to the program main stack.
 
 The resulting features cover all of the major use cases of the most popular
 termination EHMs of today, along with reintroducing resumption exceptions and
-creating some new features that fix with \CFA's larger programming patterns.
+creating some new features that fit with \CFA's larger programming patterns,
+such as virtuals independent of traditional objects.
 
-The implementation has been tested and compared to other implementations.
+The \CFA project's test suite has been expanded to test the EHM.
+The implementation's performance has also been
+compared to other implementations with a small set of targeted
+micro-benchmarks.
 The results, while not cutting edge, are good enough for prototyping, which
-is \CFA's stage of development.
+is \CFA's current stage of development.
 
-This is a valuable new feature for \CFA in its own right but also serves
-as a tool (and motivation) for other developments in the language.
+This initial EHM will bring valuable new features to \CFA in its own right
+but also serves as a tool and motivation for other developments in the
+language.
Index: doc/theses/andrew_beach_MMath/exception-layout.fig
===================================================================
--- doc/theses/andrew_beach_MMath/exception-layout.fig	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ doc/theses/andrew_beach_MMath/exception-layout.fig	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -28,8 +28,8 @@
 	0 0 1.00 240.00 240.00
 	 360 405 360 2070
-4 0 0 50 -1 0 12 0.0000 4 135 1080 2700 585 Fixed Header\001
-4 0 0 50 -1 0 12 0.0000 4 135 1710 540 990 Cforall Information\001
-4 0 0 50 -1 0 12 0.0000 4 165 1530 540 585 _Unwind_Exception\001
-4 0 0 50 -1 0 12 0.0000 4 165 1260 540 1530 User Exception\001
-4 0 0 50 -1 0 12 0.0000 4 165 1170 2655 1530 Variable Body\001
-4 0 0 50 -1 0 12 0.0000 4 165 1260 2655 1215 (Fixed Offset)\001
+4 0 0 50 -1 0 12 0.0000 0 135 1080 2700 585 Fixed Header\001
+4 0 0 50 -1 0 12 0.0000 0 135 1575 540 990 Cforall Information\001
+4 0 0 50 -1 0 12 0.0000 0 180 1695 540 585 _Unwind_Exception\001
+4 0 0 50 -1 0 12 0.0000 0 180 1245 540 1530 User Exception\001
+4 0 0 50 -1 0 12 0.0000 0 180 1185 2655 1530 Variable Body\001
+4 0 0 50 -1 0 12 0.0000 0 165 1110 2655 1215 (Fixed Offset)\001
Index: doc/theses/andrew_beach_MMath/existing.tex
===================================================================
--- doc/theses/andrew_beach_MMath/existing.tex	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ doc/theses/andrew_beach_MMath/existing.tex	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -6,9 +6,9 @@
 compatibility with C and its programmers.  \CFA is designed to have an
 orthogonal feature-set based closely on the C programming paradigm
-(non-object-oriented) and these features can be added incrementally to an
-existing C code-base allowing programmers to learn \CFA on an as-needed basis.
+(non-object-oriented), and these features can be added incrementally to an
+existing C code-base,
+allowing programmers to learn \CFA on an as-needed basis.
 
 Only those \CFA features pertaining to this thesis are discussed.
-% Also, only new features of \CFA will be discussed,
 A familiarity with
 C or C-like languages is assumed.
@@ -17,9 +17,9 @@
 \CFA has extensive overloading, allowing multiple definitions of the same name
 to be defined~\cite{Moss18}.
-\begin{lstlisting}[language=CFA,{moredelim=**[is][\color{red}]{@}{@}}]
-char @i@; int @i@; double @i@;
-int @f@(); double @f@();
-void @g@( int ); void @g@( double );
-\end{lstlisting}
+\begin{cfa}
+char i; int i; double i;
+int f(); double f();
+void g( int ); void g( double );
+\end{cfa}
 This feature requires name mangling so the assembly symbols are unique for
 different overloads. For compatibility with names in C, there is also a syntax
@@ -46,9 +46,10 @@
 \CFA adds a reference type to C as an auto-dereferencing pointer.
 They work very similarly to pointers.
-Reference-types are written the same way as a pointer-type but each
+Reference-types are written the same way as pointer-types, but each
 asterisk (@*@) is replaced with a ampersand (@&@);
-this includes cv-qualifiers and multiple levels of reference.
-
-Generally, references act like pointers with an implicate dereferencing
+this includes cv-qualifiers (\snake{const} and \snake{volatile})
+and multiple levels of reference.
+
+Generally, references act like pointers with an implicit dereferencing
 operation added to each use of the variable.
 These automatic dereferences may be disabled with the address-of operator
@@ -63,5 +64,5 @@
 int && rri = ri;
 rri = 3;
-&ri = &j; // rebindable
+&ri = &j;
 ri = 5;
 \end{cfa}
@@ -79,20 +80,22 @@
 \end{minipage}
 
-References are intended for pointer situations where dereferencing is the common usage,
-\ie the value is more important than the pointer.
+References are intended to be used when the indirection of a pointer is
+required, but the address is not as important as the value and dereferencing
+is the common usage.
 Mutable references may be assigned to by converting them to a pointer
-with a @&@ and then assigning a pointer to them, as in @&ri = &j;@ above
+with a @&@ and then assigning a pointer to them, as in @&ri = &j;@ above.
 
 \section{Operators}
 
 \CFA implements operator overloading by providing special names, where
-operator usages are translated into function calls using these names.
+operator expressions are translated into function calls using these names.
 An operator name is created by taking the operator symbols and joining them with
 @?@s to show where the arguments go.
 For example,
 infixed multiplication is @?*?@, while prefix dereference is @*?@.
-This syntax make it easy to tell the difference between prefix operations
-(such as @++?@) and post-fix operations (@?++@).
-For example, plus and equality operators are defined for a point type.
+This syntax makes it easy to tell the difference between prefix operations
+(such as @++?@) and postfix operations (@?++@).
+
+As an example, here are the addition and equality operators for a point type.
 \begin{cfa}
 point ?+?(point a, point b) { return point{a.x + b.x, a.y + b.y}; }
@@ -102,23 +105,17 @@
 }
 \end{cfa}
-Note these special names are not limited to builtin
-operators, and hence, may be used with arbitrary types.
-\begin{cfa}
-double ?+?( int x, point y ); // arbitrary types
-\end{cfa}
-% Some ``near misses", that are that do not match an operator form but looks like
-% it may have been supposed to, will generate warning but otherwise they are
-% left alone.
-Because operators are never part of the type definition they may be added
-at any time, including on built-in types.
+Note that this syntax works effectively as a textual transformation;
+the compiler converts all operators into functions and then resolves them
+normally. This means any combination of types may be used,
+although nonsensical ones (like @double ?==?(point, int);@) are discouraged.
+This feature is also used for all builtin operators as well,
+although those are implicitly provided by the language.
 
 %\subsection{Constructors and Destructors}
-
-\CFA also provides constructors and destructors as operators, which means they
-are functions with special operator names rather than type names in \Cpp.
-While constructors and destructions are normally called implicitly by the compiler,
-the special operator names, allow explicit calls.
-
-% Placement new means that this is actually equivalent to C++.
+In \CFA, constructors and destructors are operators, which means they are
+functions with special operator names, rather than type names as in \Cpp.
+Both constructors and destructors can be implicity called by the compiler,
+however the operator names allow explicit calls.
+% Placement new means that this is actually equivant to C++.
 
 The special name for a constructor is @?{}@, which comes from the
@@ -129,27 +126,30 @@
 struct Example { ... };
 void ?{}(Example & this) { ... }
+{
+	Example a;
+	Example b = {};
+}
 void ?{}(Example & this, char first, int num) { ... }
-Example a;		// implicit constructor calls
-Example b = {};
-Example c = {'a', 2};
-\end{cfa}
-Both @a@ and @b@ are initialized with the first constructor,
-while @c@ is initialized with the second.
-Constructor calls can be replaced with C initialization using special operator \lstinline{@=}.
-\begin{cfa}
-Example d @= {42};
-\end{cfa}
+{
+	Example c = {'a', 2};
+}
+\end{cfa}
+Both @a@ and @b@ will be initalized with the first constructor,
+@b@ because of the explicit call and @a@ implicitly.
+@c@ will be initalized with the second constructor.
+Currently, there is no general way to skip initialization.
+% I don't use @= anywhere in the thesis.
+
 % I don't like the \^{} symbol but $^\wedge$ isn't better.
 Similarly, destructors use the special name @^?{}@ (the @^@ has no special
 meaning).
-% These are a normally called implicitly called on a variable when it goes out
-% of scope. They can be called explicitly as well.
 \begin{cfa}
 void ^?{}(Example & this) { ... }
 {
-	Example e;	// implicit constructor call
-	^?{}(e);		// explicit destructor call
-	?{}(e);		// explicit constructor call
-} // implicit destructor call
+	Example d;
+	^?{}(d);
+
+	Example e;
+} // Implicit call of ^?{}(e);
 \end{cfa}
 
@@ -203,5 +203,5 @@
 do_twice(i);
 \end{cfa}
-Any object with a type fulfilling the assertion may be passed as an argument to
+Any value with a type fulfilling the assertion may be passed as an argument to
 a @do_twice@ call.
 
@@ -223,11 +223,10 @@
 function. The matched assertion function is then passed as a function pointer
 to @do_twice@ and called within it.
-The global definition of @do_once@ is ignored, however if quadruple took a
+The global definition of @do_once@ is ignored, however if @quadruple@ took a
 @double@ argument, then the global definition would be used instead as it
-is a better match.
-% Aaron's thesis might be a good reference here.
-
-To avoid typing long lists of assertions, constraints can be collect into
-convenient package called a @trait@, which can then be used in an assertion
+would then be a better match.\cite{Moss19}
+
+To avoid typing long lists of assertions, constraints can be collected into
+a convenient package called a @trait@, which can then be used in an assertion
 instead of the individual constraints.
 \begin{cfa}
@@ -243,9 +242,9 @@
 functions and variables, and are usually used to create a shorthand for, and
 give descriptive names to, common groupings of assertions describing a certain
-functionality, like @sumable@, @listable@, \etc.
+functionality, like @summable@, @listable@, \etc.
 
 Polymorphic structures and unions are defined by qualifying an aggregate type
 with @forall@. The type variables work the same except they are used in field
-declarations instead of parameters, returns, and local variable declarations.
+declarations instead of parameters, returns and local variable declarations.
 \begin{cfa}
 forall(dtype T)
@@ -253,5 +252,5 @@
 	node(T) * next;
 	T * data;
-}
+};
 node(int) inode;
 \end{cfa}
@@ -263,5 +262,6 @@
 
 \section{Control Flow}
-\CFA has a number of advanced control-flow features: @generator@, @coroutine@, @monitor@, @mutex@ parameters, and @thread@.
+\CFA has a number of advanced control-flow features: @generator@, @coroutine@,
+@monitor@, @mutex@ parameters, and @thread@.
 The two features that interact with
 the exception system are @coroutine@ and @thread@; they and their supporting
@@ -270,11 +270,12 @@
 \subsection{Coroutine}
 A coroutine is a type with associated functions, where the functions are not
-required to finish execution when control is handed back to the caller. Instead
+required to finish execution when control is handed back to the caller.
+Instead,
 they may suspend execution at any time and be resumed later at the point of
-last suspension. (Generators are stackless and coroutines are stackful.) These
+last suspension.
+Coroutine
 types are not concurrent but share some similarities along with common
-underpinnings, so they are combined with the \CFA threading library. Further
-discussion in this section only refers to the coroutine because generators are
-similar.
+underpinnings, so they are combined with the \CFA threading library.
+% I had mention of generators, but they don't actually matter here.
 
 In \CFA, a coroutine is created using the @coroutine@ keyword, which is an
@@ -293,13 +294,12 @@
 };
 CountUp countup;
-for (10) sout | resume(countup).next; // print 10 values
 \end{cfa}
 Each coroutine has a @main@ function, which takes a reference to a coroutine
 object and returns @void@.
 %[numbers=left] Why numbers on this one?
-\begin{cfa}[numbers=left,numberstyle=\scriptsize\sf]
+\begin{cfa}
 void main(CountUp & this) {
-	for (unsigned int up = 0;; ++up) {
-		this.next = up;
+	for (unsigned int next = 0 ; true ; ++next) {
+		this.next = next;
 		suspend;$\label{suspend}$
 	}
@@ -307,19 +307,27 @@
 \end{cfa}
 In this function, or functions called by this function (helper functions), the
-@suspend@ statement is used to return execution to the coroutine's resumer
-without terminating the coroutine's function(s).
+@suspend@ statement is used to return execution to the coroutine's caller
+without terminating the coroutine's function.
 
 A coroutine is resumed by calling the @resume@ function, \eg @resume(countup)@.
 The first resume calls the @main@ function at the top. Thereafter, resume calls
 continue a coroutine in the last suspended function after the @suspend@
-statement, in this case @main@ line~\ref{suspend}.  The @resume@ function takes
-a reference to the coroutine structure and returns the same reference. The
-return value allows easy access to communication variables defined in the
-coroutine object. For example, the @next@ value for coroutine object @countup@
-is both generated and collected in the single expression:
-@resume(countup).next@.
+statement. In this case there is only one and, hence, the difference between
+subsequent calls is the state of variables inside the function and the
+coroutine object.
+The return value of @resume@ is a reference to the coroutine, to make it
+convent to access fields of the coroutine in the same expression.
+Here is a simple example in a helper function:
+\begin{cfa}
+unsigned int get_next(CountUp & this) {
+	return resume(this).next;
+}
+\end{cfa}
+
+When the main function returns, the coroutine halts and can no longer be
+resumed.
 
 \subsection{Monitor and Mutex Parameter}
-Concurrency does not guarantee ordering; without ordering results are
+Concurrency does not guarantee ordering; without ordering, results are
 non-deterministic. To claw back ordering, \CFA uses monitors and @mutex@
 (mutual exclusion) parameters. A monitor is another kind of aggregate, where
@@ -327,10 +335,10 @@
 @mutex@ parameters.
 
-A function that requires deterministic (ordered) execution, acquires mutual
+A function that requires deterministic (ordered) execution acquires mutual
 exclusion on a monitor object by qualifying an object reference parameter with
-@mutex@.
-\begin{lstlisting}[language=CFA,{moredelim=**[is][\color{red}]{@}{@}}]
-void example(MonitorA & @mutex@ argA, MonitorB & @mutex@ argB);
-\end{lstlisting}
+the @mutex@ qualifier.
+\begin{cfa}
+void example(MonitorA & mutex argA, MonitorB & mutex argB);
+\end{cfa}
 When the function is called, it implicitly acquires the monitor lock for all of
 the mutex parameters without deadlock.  This semantics means all functions with
@@ -339,10 +347,10 @@
 
 \subsection{Thread}
-Functions, generators, and coroutines are sequential so there is only a single
+Functions, generators and coroutines are sequential, so there is only a single
 (but potentially sophisticated) execution path in a program. Threads introduce
 multiple execution paths that continue independently.
 
 For threads to work safely with objects requires mutual exclusion using
-monitors and mutex parameters. For threads to work safely with other threads,
+monitors and mutex parameters. For threads to work safely with other threads
 also requires mutual exclusion in the form of a communication rendezvous, which
 also supports internal synchronization as for mutex objects. For exceptions,
@@ -362,5 +370,5 @@
 {
 	StringWorker stringworker; // fork thread running in "main"
-} // implicitly join with thread / wait for completion
+} // Implicit call to join(stringworker), waits for completion.
 \end{cfa}
 The thread main is where a new thread starts execution after a fork operation
Index: doc/theses/andrew_beach_MMath/features.tex
===================================================================
--- doc/theses/andrew_beach_MMath/features.tex	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ doc/theses/andrew_beach_MMath/features.tex	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -5,5 +5,5 @@
 and begins with a general overview of EHMs. It is not a strict
 definition of all EHMs nor an exhaustive list of all possible features.
-However it does cover the most common structure and features found in them.
+However, it does cover the most common structure and features found in them.
 
 \section{Overview of EHMs}
@@ -19,5 +19,5 @@
 
 \paragraph{Raise}
-The raise is the starting point for exception handling
+The raise is the starting point for exception handling,
 by raising an exception, which passes it to
 the EHM.
@@ -30,9 +30,10 @@
 \paragraph{Handle}
 The primary purpose of an EHM is to run some user code to handle a raised
-exception. This code is given, with some other information, in a handler.
+exception. This code is given, along with some other information,
+in a handler.
 
 A handler has three common features: the previously mentioned user code, a
-region of code it guards, and an exception label/condition that matches
-the raised exception.
+region of code it guards and an exception label/condition that matches
+against the raised exception.
 Only raises inside the guarded region and raising exceptions that match the
 label can be handled by a given handler.
@@ -41,18 +42,11 @@
 
 The @try@ statements of \Cpp, Java and Python are common examples. All three
-show the common features of guarded region, raise, matching and handler.
-\begin{cfa}
-try {				// guarded region
-	...	 
-	throw exception;	// raise
-	...	 
-} catch( exception ) {	// matching condition, with exception label
-	...				// handler code
-}
-\end{cfa}
+also show another common feature of handlers: they are grouped by the guarded
+region.
 
 \subsection{Propagation}
 After an exception is raised comes what is usually the biggest step for the
-EHM: finding and setting up the handler for execution. The propagation from raise to
+EHM: finding and setting up the handler for execution.
+The propagation from raise to
 handler can be broken up into three different tasks: searching for a handler,
 matching against the handler and installing the handler.
@@ -60,6 +54,6 @@
 \paragraph{Searching}
 The EHM begins by searching for handlers that might be used to handle
-the exception. The search is restricted to
-handlers that have the raise site in their guarded
+the exception.
+The search will find handlers that have the raise site in their guarded
 region.
 The search includes handlers in the current function, as well as any in
@@ -67,7 +61,8 @@
 
 \paragraph{Matching}
-Each handler found is matched with the raised exception. The exception
+Each handler found is with the raised exception. The exception
 label defines a condition that is used with the exception and decides if
 there is a match or not.
+%
 In languages where the first match is used, this step is intertwined with
 searching; a match check is performed immediately after the search finds
@@ -84,10 +79,10 @@
 different course of action for this case.
 This situation only occurs with unchecked exceptions as checked exceptions
-(such as in Java) are guaranteed to find a matching handler.
+(such as in Java) can make the guarantee.
 The unhandled action is usually very general, such as aborting the program.
 
 \paragraph{Hierarchy}
 A common way to organize exceptions is in a hierarchical structure.
-This pattern comes from object-orientated languages where the
+This pattern comes from object-oriented languages where the
 exception hierarchy is a natural extension of the object hierarchy.
 
@@ -98,13 +93,13 @@
 A handler labeled with any given exception can handle exceptions of that
 type or any child type of that exception. The root of the exception hierarchy
-(here \code{C}{exception}) acts as a catch-all, leaf types catch single types,
+(here \code{C}{exception}) acts as a catch-all, leaf types catch single types
 and the exceptions in the middle can be used to catch different groups of
 related exceptions.
 
 This system has some notable advantages, such as multiple levels of grouping,
-the ability for libraries to add new exception types, and the isolation
+the ability for libraries to add new exception types and the isolation
 between different sub-hierarchies.
 This design is used in \CFA even though it is not a object-orientated
-language; so different tools are used to create the hierarchy.
+language, so different tools are used to create the hierarchy.
 
 % Could I cite the rational for the Python IO exception rework?
@@ -124,23 +119,33 @@
 from the raise to the handler and back again.
 So far, only communication of the exception's identity is covered.
-A common communication method for passing more information is putting fields into the exception instance
+A common communication method for adding information to an exception
+is putting fields into the exception instance
 and giving the handler access to them.
-Using reference fields pointing to data at the raise location allows data to be
-passed in both directions.
+% You can either have pointers/references in the exception, or have p/rs to
+% the exception when it doesn't have to be copied.
+Passing references or pointers allows data at the raise location to be
+updated, passing information in both directions.
 
 \section{Virtuals}
-\label{s:Virtuals}
+\label{s:virtuals}
+A common feature in many programming languages is a tool to pair code
+(behaviour) with data.
+In \CFA, this is done with the virtual system,
+which allow type information to be abstracted away, recovered and allow
+operations to be performed on the abstract objects.
+
 Virtual types and casts are not part of \CFA's EHM nor are they required for
 an EHM.
 However, one of the best ways to support an exception hierarchy
 is via a virtual hierarchy and dispatch system.
-Ideally, the virtual system should have been part of \CFA before the work
+Ideally, the virtual system would have been part of \CFA before the work
 on exception handling began, but unfortunately it was not.
 Hence, only the features and framework needed for the EHM were
-designed and implemented for this thesis. Other features were considered to ensure that
+designed and implemented for this thesis.
+Other features were considered to ensure that
 the structure could accommodate other desirable features in the future
 but are not implemented.
 The rest of this section only discusses the implemented subset of the
-virtual-system design.
+virtual system design.
 
 The virtual system supports multiple ``trees" of types. Each tree is
@@ -149,57 +154,86 @@
 number of children.
 Any type that belongs to any of these trees is called a virtual type.
-For example, the following hypothetical syntax creates two virtual-type trees.
-\begin{flushleft}
-\lstDeleteShortInline@
-\begin{tabular}{@{\hspace{20pt}}l@{\hspace{20pt}}l}
-\begin{cfa}
-vtype V0, V1(V0), V2(V0);
-vtype W0, W1(W0), W2(W1);
-\end{cfa}
-&
-\raisebox{-0.6\totalheight}{\input{vtable}}
-\end{tabular}
-\lstMakeShortInline@
-\end{flushleft}
 % A type's ancestors are its parent and its parent's ancestors.
 % The root type has no ancestors.
 % A type's descendants are its children and its children's descendants.
-Every virtual type (tree node) has a pointer to a virtual table with a unique
-@Id@ and a list of virtual members (see \autoref{s:VirtualSystem} for
-details). Children inherit their parent's list of virtual members but may add
-and/or replace members.  For example,
-\begin{cfa}
-vtable W0 | { int ?<?( int, int ); int ?+?( int, int ); }
-vtable W1 | { int ?+?( int, int ); int w, int ?-?( int, int ); }
-\end{cfa}
-creates a virtual table for @W0@ initialized with the matching @<@ and @+@
-operations visible at this declaration context.  Similarly, @W1@ is initialized
-with @<@ from inheritance with @W0@, @+@ is replaced, and @-@ is added, where
-both operations are matched at this declaration context. It is important to
-note that these are virtual members, not virtual methods of object-orientated
-programming, and can be of any type. Finally, trait names can be used to
-specify the list of virtual members.
-
-\PAB{Need to look at these when done.
-
-\CFA still supports virtual methods as a special case of virtual members.
-Function pointers that take a pointer to the virtual type are modified
-with each level of inheritance so that refers to the new type.
-This means an object can always be passed to a function in its virtual table
-as if it were a method.
-\todo{Clarify (with an example) virtual methods.}
-}%
-
-Up until this point the virtual system is similar to ones found in
-object-orientated languages but this is where \CFA diverges. Objects encapsulate a
-single set of methods in each type, universally across the entire program,
-and indeed all programs that use that type definition. Even if a type inherits and adds methods, it still encapsulate a
-single set of methods. In this sense,
-object-oriented types are ``closed" and cannot be altered.
-
-In \CFA, types do not encapsulate any code. Traits are local for each function and
-types can satisfy a local trait, stop satisfying it or, satisfy the same
-trait in a different way at any lexical location in the program where a function is call.
-In this sense, the set of functions/variables that satisfy a trait for a type is ``open" as the set can change at every call site.
+
+For the purposes of illustration, a proposed, but unimplemented, syntax
+will be used. Each virtual type is represented by a trait with an annotation
+that makes it a virtual type. This annotation is empty for a root type, which
+creates a new tree:
+\begin{cfa}
+trait root_type(T) virtual() {}
+\end{cfa}
+The annotation may also refer to any existing virtual type to make this new
+type a child of that type and part of the same tree. The parent may itself
+be a child or a root type and may have any number of existing children.
+
+% OK, for some reason the b and t positioning options are reversed here.
+\begin{minipage}[b]{0.6\textwidth}
+\begin{cfa}
+trait child_a(T) virtual(root_type) {}
+trait grandchild(T) virtual(child_a) {}
+trait child_b(T) virtual(root_type) {}
+\end{cfa}
+\end{minipage}
+\begin{minipage}{0.4\textwidth}
+\begin{center}
+\input{virtual-tree}
+\end{center}
+\end{minipage}
+
+Every virtual type also has a list of virtual members and a unique id.
+Both are stored in a virtual table.
+Every instance of a virtual type also has a pointer to a virtual table stored
+in it, although there is no per-type virtual table as in many other languages.
+
+The list of virtual members is accumulated from the root type down the tree.
+Every virtual type
+inherits the list of virtual members from its parent and may add more
+virtual members to the end of the list which are passed on to its children.
+Again, using the unimplemented syntax this might look like:
+\begin{cfa}
+trait root_type(T) virtual() {
+	const char * to_string(T const & this);
+	unsigned int size;
+}
+
+trait child_type(T) virtual(root_type) {
+	char * irrelevant_function(int, char);
+}
+\end{cfa}
+% Consider adding a diagram, but we might be good with the explanation.
+
+As @child_type@ is a child of @root_type@, it has the virtual members of
+@root_type@ (@to_string@ and @size@) as well as the one it declared
+(@irrelevant_function@).
+
+It is important to note that these are virtual members, and may contain   
+arbitrary fields, functions or otherwise.
+The names ``size" and ``align" are reserved for the size and alignment of the
+virtual type, and are always automatically initialized as such.
+The other special case is uses of the trait's polymorphic argument
+(@T@ in the example), which are always updated to refer to the current
+virtual type. This allows functions that refer to the polymorphic argument
+to act as traditional virtual methods (@to_string@ in the example), as the
+object can always be passed to a virtual method in its virtual table.
+
+Up until this point, the virtual system is similar to ones found in
+object-oriented languages, but this is where \CFA diverges.
+Objects encapsulate a single set of methods in each type,
+universally across the entire program,
+and indeed all programs that use that type definition.
+The only way to change any method is to inherit and define a new type with
+its own universal implementation. In this sense,
+these object-oriented types are ``closed" and cannot be altered.
+% Because really they are class oriented.
+
+In \CFA, types do not encapsulate any code.
+Whether or not a type satisfies any given assertion, and hence any trait, is
+context sensitive. Types can begin to satisfy a trait, stop satisfying it or
+satisfy the same trait at any lexical location in the program.
+In this sense, a type's implementation in the set of functions and variables
+that allow it to satisfy a trait is ``open" and can change
+throughout the program.
 This capability means it is impossible to pick a single set of functions
 that represent a type's implementation across a program.
@@ -208,11 +242,36 @@
 type. A user can define virtual tables that are filled in at their
 declaration and given a name. Anywhere that name is visible, even if it is
-defined locally inside a function \PAB{What does this mean? (although that means it does not have a
-static lifetime)}, it can be used.
+defined locally inside a function (although in this case the user must ensure
+it outlives any objects that use it), it can be used.
 Specifically, a virtual type is ``bound" to a virtual table that
 sets the virtual members for that object. The virtual members can be accessed
 through the object.
 
-While much of the virtual infrastructure is created, it is currently only used
+This means virtual tables are declared and named in \CFA.
+They are declared as variables, using the type
+@vtable(VIRTUAL_TYPE)@ and any valid name. For example:
+\begin{cfa}
+vtable(virtual_type_name) table_name;
+\end{cfa}
+
+Like any variable, they may be forward declared with the @extern@ keyword.
+Forward declaring virtual tables is relatively common.
+Many virtual types have an ``obvious" implementation that works in most
+cases.
+A pattern that has appeared in the early work using virtuals is to
+implement a virtual table with the the obvious definition and place a forward
+declaration of it in the header beside the definition of the virtual type.
+
+Even on the full declaration, no initializer should be used.
+Initialization is automatic.
+The type id and special virtual members ``size" and ``align" only depend on
+the virtual type, which is fixed given the type of the virtual table, and
+so the compiler fills in a fixed value.
+The other virtual members are resolved using the best match to the member's
+name and type, in the same context as the virtual table is declared using
+\CFA's normal resolution rules.
+
+While much of the virtual infrastructure has been created,
+it is currently only used
 internally for exception handling. The only user-level feature is the virtual
 cast, which is the same as the \Cpp \code{C++}{dynamic_cast}.
@@ -223,16 +282,55 @@
 Note, the syntax and semantics matches a C-cast, rather than the function-like
 \Cpp syntax for special casts. Both the type of @EXPRESSION@ and @TYPE@ must be
-a pointer to a virtual type.
+pointers to virtual types.
 The cast dynamically checks if the @EXPRESSION@ type is the same or a sub-type
 of @TYPE@, and if true, returns a pointer to the
 @EXPRESSION@ object, otherwise it returns @0p@ (null pointer).
-
-\section{Exception}
-% Leaving until later, hopefully it can talk about actual syntax instead
-% of my many strange macros. Syntax aside I will also have to talk about the
-% features all exceptions support.
-
-Exceptions are defined by the trait system; there are a series of traits, and
-if a type satisfies them, then it can be used as an exception. The following
+This allows the expression to be used as both a cast and a type check.
+
+\section{Exceptions}
+
+The syntax for declaring an exception is the same as declaring a structure
+except the keyword:
+\begin{cfa}
+exception TYPE_NAME {
+	FIELDS
+};
+\end{cfa}
+
+Fields are filled in the same way as a structure as well. However, an extra
+field is added that contains the pointer to the virtual table.
+It must be explicitly initialized by the user when the exception is
+constructed.
+
+Here is an example of declaring an exception type along with a virtual table,
+assuming the exception has an ``obvious" implementation and a default
+virtual table makes sense.
+
+\begin{minipage}[t]{0.4\textwidth}
+Header (.hfa):
+\begin{cfa}
+exception Example {
+	int data;
+};
+
+extern vtable(Example)
+	example_base_vtable;
+\end{cfa}
+\end{minipage}
+\begin{minipage}[t]{0.6\textwidth}
+Implementation (.cfa):
+\begin{cfa}
+vtable(Example) example_base_vtable
+\end{cfa}
+\vfil
+\end{minipage}
+
+%\subsection{Exception Details}
+This is the only interface needed when raising and handling exceptions.
+However, it is actually a shorthand for a more complex
+trait-based interface.
+
+The language views exceptions through a series of traits.
+If a type satisfies them, then it can be used as an exception. The following
 is the base trait all exceptions need to match.
 \begin{cfa}
@@ -241,5 +339,5 @@
 };
 \end{cfa}
-The trait is defined over two types, the exception type and the virtual table
+The trait is defined over two types: the exception type and the virtual table
 type. Each exception type should have a single virtual table type.
 There are no actual assertions in this trait because the trait system
@@ -247,6 +345,7 @@
 completing the virtual system). The imaginary assertions would probably come
 from a trait defined by the virtual system, and state that the exception type
-is a virtual type, is a descendant of @exception_t@ (the base exception type),
-and note its virtual table type.
+is a virtual type,
+that that the type is a descendant of @exception_t@ (the base exception type)
+and allow the user to find the virtual table type.
 
 % I did have a note about how it is the programmer's responsibility to make
@@ -266,15 +365,15 @@
 };
 \end{cfa}
-Both traits ensure a pair of types are an exception type, its virtual table
-type,
+Both traits ensure a pair of types is an exception type and
+its virtual table type,
 and defines one of the two default handlers. The default handlers are used
-as fallbacks and are discussed in detail in \vref{s:ExceptionHandling}.
+as fallbacks and are discussed in detail in \autoref{s:ExceptionHandling}.
 
 However, all three of these traits can be tricky to use directly.
 While there is a bit of repetition required,
 the largest issue is that the virtual table type is mangled and not in a user
-facing way. So these three macros are provided to wrap these traits to
+facing way. So, these three macros are provided to wrap these traits to
 simplify referring to the names:
-@IS_EXCEPTION@, @IS_TERMINATION_EXCEPTION@, and @IS_RESUMPTION_EXCEPTION@.
+@IS_EXCEPTION@, @IS_TERMINATION_EXCEPTION@ and @IS_RESUMPTION_EXCEPTION@.
 
 All three take one or two arguments. The first argument is the name of the
@@ -282,9 +381,9 @@
 The second (optional) argument is a parenthesized list of polymorphic
 arguments. This argument is only used with polymorphic exceptions and the
-list is be passed to both types.
+list is passed to both types.
 In the current set-up, the two types always have the same polymorphic
-arguments so these macros can be used without losing flexibility.
-
-For example consider a function that is polymorphic over types that have a
+arguments, so these macros can be used without losing flexibility.
+
+For example, consider a function that is polymorphic over types that have a
 defined arithmetic exception:
 \begin{cfa}
@@ -303,17 +402,20 @@
 Both operations follow the same set of steps.
 First, a user raises an exception.
-Second, the exception propagates up the stack.
+Second, the exception propagates up the stack, searching for a handler.
 Third, if a handler is found, the exception is caught and the handler is run.
 After that control continues at a raise-dependent location.
-Fourth, if a handler is not found, a default handler is run and, if it returns, then control
+As an alternate to the third step,
+if a handler is not found, a default handler is run and, if it returns,
+then control
 continues after the raise.
 
-%This general description covers what the two kinds have in common.
-The differences in the two operations include how propagation is performed, where execution continues
-after an exception is caught and handled, and which default handler is run.
+The differences between the two operations include how propagation is
+performed, where execution continues after an exception is handled
+and which default handler is run.
 
 \subsection{Termination}
 \label{s:Termination}
-Termination handling is the familiar EHM and used in most programming
+Termination handling is the familiar kind of handling
+used in most programming
 languages with exception handling.
 It is a dynamic, non-local goto. If the raised exception is matched and
@@ -347,5 +449,5 @@
 Then propagation starts with the search. \CFA uses a ``first match" rule so
 matching is performed with the copied exception as the search key.
-It starts from the raise in the throwing function and proceeds towards the base of the stack,
+It starts from the raise site and proceeds towards base of the stack,
 from callee to caller.
 At each stack frame, a check is made for termination handlers defined by the
@@ -361,5 +463,5 @@
 \end{cfa}
 When viewed on its own, a try statement simply executes the statements
-in the \snake{GUARDED_BLOCK}, and when those are finished,
+in the \snake{GUARDED_BLOCK} and when those are finished,
 the try statement finishes.
 
@@ -387,12 +489,30 @@
 termination exception types.
 The global default termination handler performs a cancellation
-(see \vref{s:Cancellation} for the justification) on the current stack with the copied exception.
-Since it is so general, a more specific handler is usually
-defined, possibly with a detailed message, and used for specific exception type, effectively overriding the default handler.
+(as described in \vref{s:Cancellation})
+on the current stack with the copied exception.
+Since it is so general, a more specific handler can be defined,
+overriding the default behaviour for the specific exception types.
+
+For example, consider an error reading a configuration file.
+This is most likely a problem with the configuration file (@config_error@),
+but the function could have been passed the wrong file name (@arg_error@).
+In this case the function could raise one exception and then, if it is
+unhandled, raise the other.
+This is not usual behaviour for either exception so changing the
+default handler will be done locally:
+\begin{cfa}
+{
+	void defaultTerminationHandler(config_error &) {
+		throw (arg_error){arg_vt};
+	}
+	throw (config_error){config_vt};
+}
+\end{cfa}
 
 \subsection{Resumption}
 \label{s:Resumption}
 
-Resumption exception handling is the less familar EHM, but is
+Resumption exception handling is less familar form of exception handling,
+but is
 just as old~\cite{Goodenough75} and is simpler in many ways.
 It is a dynamic, non-local function call. If the raised exception is
@@ -403,5 +523,9 @@
 function once the error is corrected, and
 ignorable events, such as logging where nothing needs to happen and control
-should always continue from the raise point.
+should always continue from the raise site.
+
+Except for the changes to fit into that pattern, resumption exception
+handling is symmetric with termination exception handling, by design
+(see \autoref{s:Termination}).
 
 A resumption raise is started with the @throwResume@ statement:
@@ -409,21 +533,19 @@
 throwResume EXPRESSION;
 \end{cfa}
-\todo{Decide on a final set of keywords and use them everywhere.}
-It works much the same way as the termination throw.
-The expression must return a reference to a resumption exception,
-where the resumption exception is any type that satisfies the trait
-@is_resumption_exception@ at the call site.
-The assertions from this trait are available to
-the exception system while handling the exception.
-
-At run-time, no exception copy is made, since
+% The new keywords are currently ``experimental" and not used in this work.
+It works much the same way as the termination raise, except the
+type must satisfy the \snake{is_resumption_exception} that uses the
+default handler: \defaultResumptionHandler.
+This can be specialized for particular exception types.
+
+At run-time, no exception copy is made. Since
 resumption does not unwind the stack nor otherwise remove values from the
-current scope, so there is no need to manage memory to keep the exception in scope.
-
-Then propagation starts with the search. It starts from the raise in the
-resuming function and proceeds towards the base of the stack,
-from callee to caller.
-At each stack frame, a check is made for resumption handlers defined by the
-@catchResume@ clauses of a @try@ statement.
+current scope, there is no need to manage memory to keep the exception
+allocated.
+
+Then propagation starts with the search,
+following the same search path as termination,
+from the raise site to the base of stack and top of try statement to bottom.
+However, the handlers on try statements are defined by @catchResume@ clauses.
 \begin{cfa}
 try {
@@ -435,64 +557,29 @@
 }
 \end{cfa}
-% PAB, you say this above.
-% When a try statement is executed, it simply executes the statements in the
-% @GUARDED_BLOCK@ and then finishes.
-% 
-% However, while the guarded statements are being executed, including any
-% invoked functions, all the handlers in these statements are included in the
-% search path.
-% Hence, if a resumption exception is raised, these handlers may be matched
-% against the exception and may handle it.
-% 
-% Exception matching checks the handler in each catch clause in the order
-% they appear, top to bottom. If the representation of the raised exception type
-% is the same or a descendant of @EXCEPTION_TYPE@$_i$, then @NAME@$_i$
-% (if provided) is bound to a pointer to the exception and the statements in
-% @HANDLER_BLOCK@$_i$ are executed.
-% If control reaches the end of the handler, execution continues after the
-% the raise statement that raised the handled exception.
-% 
-% Like termination, if no resumption handler is found during the search,
-% then the default handler (\defaultResumptionHandler) visible at the raise
-% statement is called. It will use the best match at the raise sight according
-% to \CFA's overloading rules. The default handler is
-% passed the exception given to the raise. When the default handler finishes
-% execution continues after the raise statement.
-% 
-% There is a global @defaultResumptionHandler{} is polymorphic over all
-% resumption exceptions and performs a termination throw on the exception.
-% The \defaultTerminationHandler{} can be overridden by providing a new
-% function that is a better match.
-
-The @GUARDED_BLOCK@ and its associated nested guarded statements work the same
-for resumption as for termination, as does exception matching at each
-@catchResume@. Similarly, if no resumption handler is found during the search,
-then the currently visible default handler (\defaultResumptionHandler) is
-called and control continues after the raise statement if it returns. Finally,
-there is also a global @defaultResumptionHandler@, which can be overridden,
-that is polymorphic over all resumption exceptions but performs a termination
-throw on the exception rather than a cancellation.
-
-Throwing the exception in @defaultResumptionHandler@ has the positive effect of
-walking the stack a second time for a recovery handler. Hence, a programmer has
-two chances for help with a problem, fixup or recovery, should either kind of
-handler appear on the stack. However, this dual stack walk leads to following
-apparent anomaly:
-\begin{cfa}
-try {
-	throwResume E;
-} catch (E) {
-	// this handler runs
-}
-\end{cfa}
-because the @catch@ appears to handle a @throwResume@, but a @throwResume@ only
-matches with @catchResume@. The anomaly results because the unmatched
-@catchResuem@, calls @defaultResumptionHandler@, which in turn throws @E@.
-
-% I wonder if there would be some good central place for this.
-Note, termination and resumption handlers may be used together
+Note that termination handlers and resumption handlers may be used together
 in a single try statement, intermixing @catch@ and @catchResume@ freely.
 Each type of handler only interacts with exceptions from the matching
 kind of raise.
+Like @catch@ clauses, @catchResume@ clauses have no effect if an exception
+is not raised.
+
+The matching rules are exactly the same as well.
+The first major difference here is that after
+@EXCEPTION_TYPE@$_i$ is matched and @NAME@$_i$ is bound to the exception,
+@HANDLER_BLOCK@$_i$ is executed right away without first unwinding the stack.
+After the block has finished running, control jumps to the raise site, where
+the just handled exception came from, and continues executing after it,
+not after the try statement.
+
+For instance, a resumption used to send messages to the logger may not
+need to be handled at all. Putting the following default handler
+at the global scope can make handling that exception optional by default.
+\begin{cfa}
+void defaultResumptionHandler(log_message &) {
+    // Nothing, it is fine not to handle logging.
+}
+// ... No change at raise sites. ...
+throwResume (log_message){strlit_log, "Begin event processing."}
+\end{cfa}
 
 \subsubsection{Resumption Marking}
@@ -501,6 +588,7 @@
 not unwind the stack. A side effect is that, when a handler is matched
 and run, its try block (the guarded statements) and every try statement
-searched before it are still on the stack. There presence can lead to
-the \emph{recursive resumption problem}.
+searched before it are still on the stack. Their presence can lead to
+the recursive resumption problem.\cite{Buhr00a}
+% Other possible citation is MacLaren77, but the form is different.
 
 The recursive resumption problem is any situation where a resumption handler
@@ -516,17 +604,14 @@
 When this code is executed, the guarded @throwResume@ starts a
 search and matches the handler in the @catchResume@ clause. This
-call is placed on the stack above the try-block. Now the second raise in the handler
-searches the same try block, matches, and puts another instance of the
+call is placed on the stack above the try-block.
+Now the second raise in the handler searches the same try block,
+matches again and then puts another instance of the
 same handler on the stack leading to infinite recursion.
 
-While this situation is trivial and easy to avoid, much more complex cycles can
-form with multiple handlers and different exception types.  The key point is
-that the programmer's intuition expects every raise in a handler to start
-searching \emph{below} the @try@ statement, making it difficult to understand
-and fix the problem.
-
+While this situation is trivial and easy to avoid, much more complex cycles
+can form with multiple handlers and different exception types.
 To prevent all of these cases, each try statement is ``marked" from the
-time the exception search reaches it to either when a matching handler
-completes or when the search reaches the base
+time the exception search reaches it to either when a handler completes
+handling that exception or when the search reaches the base
 of the stack.
 While a try statement is marked, its handlers are never matched, effectively
@@ -537,11 +622,11 @@
 \end{center}
 
-There are other sets of marking rules that could be used,
-for instance, marking just the handlers that caught the exception,
+There are other sets of marking rules that could be used.
+For instance, marking just the handlers that caught the exception
 would also prevent recursive resumption.
-However, the rule selected mirrors what happens with termination,
-and hence, matches programmer intuition that a raise searches below a try.
-
-In detail, the marked try statements are the ones that would be removed from
+However, the rules selected mirror what happens with termination,
+so this reduces the amount of rules and patterns a programmer has to know.
+
+The marked try statements are the ones that would be removed from
 the stack for a termination exception, \ie those on the stack
 between the handler and the raise statement.
@@ -580,5 +665,5 @@
 // Handle a failure relating to f2 further down the stack.
 \end{cfa}
-In this example the file that experienced the IO error is used to decide
+In this example, the file that experienced the IO error is used to decide
 which handler should be run, if any at all.
 
@@ -609,26 +694,77 @@
 
 \subsection{Comparison with Reraising}
-Without conditional catch, the only approach to match in more detail is to reraise
-the exception after it has been caught, if it could not be handled.
+In languages without conditional catch -- that is, no ability to match an
+exception based on something other than its type -- it can be mimicked
+by matching all exceptions of the right type, checking any additional
+conditions inside the handler and re-raising the exception if it does not
+match those.
+
+Here is a minimal example comparing both patterns, using @throw;@
+(no operand) to start a re-raise.
 \begin{center}
-\begin{tabular}{l|l}
+\begin{tabular}{l r}
 \begin{cfa}
 try {
-	do_work_may_throw();
-} catch(excep_t * ex; can_handle(ex)) {
-
-	handle(ex);
-
-
-
-}
+    do_work_may_throw();
+} catch(exception_t * exc ;
+		can_handle(exc)) {
+    handle(exc);
+}
+
+
+
 \end{cfa}
 &
 \begin{cfa}
 try {
-	do_work_may_throw();
-} catch(excep_t * ex) { 
-	if (can_handle(ex)) {
-		handle(ex);
+    do_work_may_throw();
+} catch(exception_t * exc) {
+    if (can_handle(exc)) {
+        handle(exc);
+    } else {
+        throw;
+    }
+}
+\end{cfa}
+\end{tabular}
+\end{center}
+At first glance, catch-and-reraise may appear to just be a quality-of-life 
+feature, but there are some significant differences between the two
+strategies.
+
+A simple difference that is more important for \CFA than many other languages
+is that the raise site changes with a re-raise, but does not with a
+conditional catch.
+This is important in \CFA because control returns to the raise site to run
+the per-site default handler. Because of this, only a conditional catch can
+allow the original raise to continue.
+
+The more complex issue comes from the difference in how conditional
+catches and re-raises handle multiple handlers attached to a single try
+statement. A conditional catch will continue checking later handlers while
+a re-raise will skip them.
+If the different handlers could handle some of the same exceptions,
+translating a try statement that uses one to use the other can quickly
+become non-trivial:
+
+\noindent
+Original, with conditional catch:
+\begin{cfa}
+...
+} catch (an_exception * e ; check_a(e)) {
+	handle_a(e);
+} catch (exception_t * e ; check_b(e)) {
+	handle_b(e);
+}
+\end{cfa}
+Translated, with re-raise:
+\begin{cfa}
+...
+} catch (exception_t * e) {
+	an_exception * an_e = (virtual an_exception *)e;
+	if (an_e && check_a(an_e)) {
+		handle_a(an_e);
+	} else if (check_b(e)) {
+		handle_b(e);
 	} else {
 		throw;
@@ -636,123 +772,34 @@
 }
 \end{cfa}
-\end{tabular}
-\end{center}
-Notice catch-and-reraise increases complexity by adding additional data and
-code to the exception process. Nevertheless, catch-and-reraise can simulate
-conditional catch straightforwardly, when exceptions are disjoint, \ie no
-inheritance.
-
-However, catch-and-reraise simulation becomes unusable for exception inheritance.
-\begin{flushleft}
-\begin{cfa}[xleftmargin=6pt]
-exception E1;
-exception E2(E1); // inheritance
-\end{cfa}
-\begin{tabular}{l|l}
-\begin{cfa}
-try {
-	... foo(); ... // raise E1/E2
-	... bar(); ... // raise E1/E2
-} catch( E2 e; e.rtn == foo ) {
-	...
-} catch( E1 e; e.rtn == foo ) {
-	...
-} catch( E1 e; e.rtn == bar ) {
-	...
-}
-
-\end{cfa}
-&
-\begin{cfa}
-try {
-	... foo(); ...
-	... bar(); ...
-} catch( E2 e ) {
-	if ( e.rtn == foo ) { ...
-	} else throw; // reraise
-} catch( E1 e ) {
-	if (e.rtn == foo) { ...
-	} else if (e.rtn == bar) { ...
-	else throw; // reraise
-}
-\end{cfa}
-\end{tabular}
-\end{flushleft}
-The derived exception @E2@ must be ordered first in the catch list, otherwise
-the base exception @E1@ catches both exceptions. In the catch-and-reraise code
-(right), the @E2@ handler catches exceptions from both @foo@ and
-@bar@. However, the reraise misses the following catch clause. To fix this
-problem, an enclosing @try@ statement is need to catch @E2@ for @bar@ from the
-reraise, and its handler must duplicate the inner handler code for @bar@. To
-generalize, this fix for any amount of inheritance and complexity of try
-statement requires a technique called \emph{try-block
-splitting}~\cite{Krischer02}, which is not discussed in this thesis. It is
-sufficient to state that conditional catch is more expressive than
-catch-and-reraise in terms of complexity.
-
-\begin{comment}
-That is, they have the same behaviour in isolation.
-Two things can expose differences between these cases.
-
-One is the existence of multiple handlers on a single try statement.
-A reraise skips all later handlers for a try statement but a conditional
-catch does not.
-% Hence, if an earlier handler contains a reraise later handlers are
-% implicitly skipped, with a conditional catch they are not.
-Still, they are equivalently powerful,
-both can be used two mimic the behaviour of the other,
-as reraise can pack arbitrary code in the handler and conditional catches
-can put arbitrary code in the predicate.
-% I was struggling with a long explanation about some simple solutions,
-% like repeating a condition on later handlers, and the general solution of
-% merging everything together. I don't think it is useful though unless its
-% for a proof.
-% https://en.cppreference.com/w/cpp/language/throw
-
-The question then becomes ``Which is a better default?"
-We believe that not skipping possibly useful handlers is a better default.
-If a handler can handle an exception it should and if the handler can not
-handle the exception then it is probably safer to have that explicitly
-described in the handler itself instead of implicitly described by its
-ordering with other handlers.
-% Or you could just alter the semantics of the throw statement. The handler
-% index is in the exception so you could use it to know where to start
-% searching from in the current try statement.
-% No place for the `goto else;` metaphor.
-
-The other issue is all of the discussion above assumes that the only
-way to tell apart two raises is the exception being raised and the remaining
-search path.
-This is not true generally, the current state of the stack can matter in
-a number of cases, even only for a stack trace after an program abort.
-But \CFA has a much more significant need of the rest of the stack, the
-default handlers for both termination and resumption.
-
-% For resumption it turns out it is possible continue a raise after the
-% exception has been caught, as if it hadn't been caught in the first place.
-This becomes a problem combined with the stack unwinding used in termination
-exception handling.
-The stack is unwound before the handler is installed, and hence before any
-reraises can run. So if a reraise happens the previous stack is gone,
-the place on the stack where the default handler was supposed to run is gone,
-if the default handler was a local function it may have been unwound too.
-There is no reasonable way to restore that information, so the reraise has
-to be considered as a new raise.
-This is the strongest advantage conditional catches have over reraising,
-they happen before stack unwinding and avoid this problem.
-
-% The one possible disadvantage of conditional catch is that it runs user
-% code during the exception search. While this is a new place that user code
-% can be run destructors and finally clauses are already run during the stack
-% unwinding.
+(There is a simpler solution if @handle_a@ never raises exceptions,
+using nested try statements.)
+
+% } catch (an_exception * e ; check_a(e)) {
+%     handle_a(e);
+% } catch (exception_t * e ; !(virtual an_exception *)e && check_b(e)) {
+%     handle_b(e);
+% }
 %
-% https://www.cplusplus.com/reference/exception/current_exception/
-%   `exception_ptr current_exception() noexcept;`
-% https://www.python.org/dev/peps/pep-0343/
-\end{comment}
+% } catch (an_exception * e)
+%   if (check_a(e)) {
+%     handle_a(e);
+%   } else throw;
+% } catch (exception_t * e)
+%   if (check_b(e)) {
+%     handle_b(e);
+%   } else throw;
+% }
+In similar simple examples, translating from re-raise to conditional catch
+takes less code but it does not have a general, trivial solution either.
+
+So, given that the two patterns do not trivially translate into each other,
+it becomes a matter of which on should be encouraged and made the default.
+From the premise that if a handler could handle an exception then it
+should, it follows that checking as many handlers as possible is preferred.
+So, conditional catch and checking later handlers is a good default.
 
 \section{Finally Clauses}
 \label{s:FinallyClauses}
-Finally clauses are used to preform unconditional clean-up when leaving a
+Finally clauses are used to perform unconditional cleanup when leaving a
 scope and are placed at the end of a try statement after any handler clauses:
 \begin{cfa}
@@ -766,5 +813,5 @@
 The @FINALLY_BLOCK@ is executed when the try statement is removed from the
 stack, including when the @GUARDED_BLOCK@ finishes, any termination handler
-finishes, or during an unwind.
+finishes or during an unwind.
 The only time the block is not executed is if the program is exited before
 the stack is unwound.
@@ -772,23 +819,23 @@
 Execution of the finally block should always finish, meaning control runs off
 the end of the block. This requirement ensures control always continues as if
-the finally clause is not present, \ie finally is for cleanup not changing
+the finally clause is not present, \ie finally is for cleanup, not changing
 control flow.
 Because of this requirement, local control flow out of the finally block
 is forbidden. The compiler precludes any @break@, @continue@, @fallthru@ or
 @return@ that causes control to leave the finally block. Other ways to leave
-the finally block, such as a long jump or termination are much harder to check,
-and at best requiring additional run-time overhead, and so are only
+the finally block, such as a @longjmp@ or termination are much harder to check,
+and at best require additional run-time overhead, and so are only
 discouraged.
 
-Not all languages with unwinding have finally clauses. Notably \Cpp does
+Not all languages with unwinding have finally clauses. Notably, \Cpp does
 without it as destructors, and the RAII design pattern, serve a similar role.
 Although destructors and finally clauses can be used for the same cases,
 they have their own strengths, similar to top-level function and lambda
 functions with closures.
-Destructors take more work for their creation, but if there is clean-up code
+Destructors take more work to create, but if there is clean-up code
 that needs to be run every time a type is used, they are much easier
-to set-up.
-On the other hand finally clauses capture the local context, so is easy to
-use when the clean-up is not dependent on the type of a variable or requires
+to set up for each use. % It's automatic.
+On the other hand, finally clauses capture the local context, so are easy to
+use when the cleanup is not dependent on the type of a variable or requires
 information from multiple variables.
 
@@ -797,28 +844,29 @@
 Cancellation is a stack-level abort, which can be thought of as as an
 uncatchable termination. It unwinds the entire current stack, and if
-possible forwards the cancellation exception to a different stack.
+possible, forwards the cancellation exception to a different stack.
 
 Cancellation is not an exception operation like termination or resumption.
 There is no special statement for starting a cancellation; instead the standard
-library function @cancel_stack@ is called passing an exception. Unlike a
-raise, this exception is not used in matching only to pass information about
+library function @cancel_stack@ is called, passing an exception. Unlike a
+raise, this exception is not used in matching, only to pass information about
 the cause of the cancellation.
-Finaly, since a cancellation only unwinds and forwards, there is no default handler.
-
-After @cancel_stack@ is called the exception is copied into the EHM's memory
+Finally, as no handler is provided, there is no default handler.
+
+After @cancel_stack@ is called, the exception is copied into the EHM's memory
 and the current stack is unwound.
 The behaviour after that depends on the kind of stack being cancelled.
 
 \paragraph{Main Stack}
-The main stack is the one used by the program main at the start of execution,
+The main stack is the one used by
+the program's main function at the start of execution,
 and is the only stack in a sequential program.
-After the main stack is unwound there is a program-level abort. 
-
-The reasons for this semantics in a sequential program is that there is no more code to execute.
-This semantics also applies to concurrent programs, too, even if threads are running.
-That is, if any threads starts a cancellation, it implies all threads terminate.
-Keeping the same behaviour in sequential and concurrent programs is simple.
-Also, even in concurrent programs there may not currently be any other stacks
-and even if other stacks do exist, main has no way to know where they are.
+After the main stack is unwound, there is a program-level abort. 
+
+The first reason for this behaviour is for sequential programs where there
+is only one stack, and hence no stack to pass information to.
+Second, even in concurrent programs, the main stack has no dependency
+on another stack and no reliable way to find another living stack.
+Finally, keeping the same behaviour in both sequential and concurrent
+programs is simple and easy to understand.
 
 \paragraph{Thread Stack}
@@ -832,5 +880,5 @@
 and an implicit join (from a destructor call). The explicit join takes the
 default handler (@defaultResumptionHandler@) from its calling context while
-the implicit join provides its own; which does a program abort if the
+the implicit join provides its own, which does a program abort if the
 @ThreadCancelled@ exception cannot be handled.
 
@@ -850,5 +898,7 @@
 
 With explicit join and a default handler that triggers a cancellation, it is
-possible to cascade an error across any number of threads, cleaning up each
+possible to cascade an error across any number of threads,
+alternating between the resumption (possibly termination) and cancellation,
+cleaning up each
 in turn, until the error is handled or the main thread is reached.
 
@@ -858,10 +908,11 @@
 After a coroutine stack is unwound, control returns to the @resume@ function
 that most recently resumed it. @resume@ reports a
-@CoroutineCancelled@ exception, which contains a references to the cancelled
+@CoroutineCancelled@ exception, which contains a reference to the cancelled
 coroutine and the exception used to cancel it.
 The @resume@ function also takes the \defaultResumptionHandler{} from the
 caller's context and passes it to the internal report.
 
-A coroutine only knows of two other coroutines, its starter and its last resumer.
+A coroutine only knows of two other coroutines,
+its starter and its last resumer.
 The starter has a much more distant connection, while the last resumer just
 (in terms of coroutine state) called resume on this coroutine, so the message
@@ -869,7 +920,6 @@
 
 With a default handler that triggers a cancellation, it is possible to
-cascade an error across any number of coroutines, cleaning up each in turn,
+cascade an error across any number of coroutines,
+alternating between the resumption (possibly termination) and cancellation,
+cleaning up each in turn,
 until the error is handled or a thread stack is reached.
-
-\PAB{Part of this I do not understand. A cancellation cannot be caught. But you
-talk about handling a cancellation in the last sentence. Which is correct?}
Index: doc/theses/andrew_beach_MMath/future.tex
===================================================================
--- doc/theses/andrew_beach_MMath/future.tex	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ doc/theses/andrew_beach_MMath/future.tex	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -2,20 +2,18 @@
 \label{c:future}
 
+The following discussion covers both possible interesting research
+that could follow from this work as well as simple implementation
+improvements.
+
 \section{Language Improvements}
-\todo{Future/Language Improvements seems to have gotten mixed up. It is
-presented as ``waiting on language improvements" but really its more
-non-research based impovements.}
+
 \CFA is a developing programming language. As such, there are partially or
-unimplemented features of the language (including several broken components)
-that I had to workaround while building an exception handling system largely in
-the \CFA language (some C components).  The following are a few of these
-issues, and once implemented/fixed, how they would affect the exception system.
+unimplemented features (including several broken components)
+that I had to work around while building the EHM largely in
+the \CFA language (some C components). Below are a few of these issues
+and how implementing/fixing them would affect the EHM.
+In addition, there are some simple improvements that had no interesting
+research attached to them but would make using the language easier.
 \begin{itemize}
-\item
-The implementation of termination is not portable because it includes
-hand-crafted assembly statements.
-The existing compilers cannot translate that for other platforms and those
-sections must be ported by hand to
-support more hardware architectures, such as the ARM processor.
 \item
 Due to a type-system problem, the catch clause cannot bind the exception to a
@@ -24,21 +22,30 @@
 result in little or no change in the exception system but simplify usage.
 \item
+The @copy@ function in the exception virtual table is an adapter to address
+some limitations in the \CFA copy constructor. If the copy constructor is
+improved it can be used directly without the adapter.
+\item
 Termination handlers cannot use local control-flow transfers, \eg by @break@,
 @return@, \etc. The reason is that current code generation hoists a handler
-into a nested function for convenience (versus assemble-code generation at the
-@try@ statement). Hence, when the handler runs, its code is not in the lexical
-scope of the @try@ statement, where the local control-flow transfers are
-meaningful.
+into a nested function for convenience (versus assembly-code generation at the
+try statement). Hence, when the handler runs, it can still access local
+variables in the lexical scope of the try statement. Still, it does mean
+that seemingly local control flow is not in fact local and crosses a function
+boundary.
+Making the termination handler's code within the surrounding
+function would remove this limitation.
+% Try blocks are much more difficult to do practically (requires our own
+% assembly) and resumption handlers have some theoretical complexity.
 \item
-There is no detection of colliding unwinds. It is possible for clean-up code
-run during an unwind to trigger another unwind that escapes the clean-up code
-itself; such as a termination exception caught further down the stack or a
-cancellation. There do exist ways to handle this but currently they are not
-even detected and the first unwind will simply be forgotten, often leaving
+There is no detection of colliding unwinds. It is possible for cleanup code
+run during an unwind to trigger another unwind that escapes the cleanup code
+itself, such as a termination exception caught further down the stack or a
+cancellation. There do exist ways to handle this case, but currently there is
+no detection and the first unwind will simply be forgotten, often leaving
 it in a bad state.
 \item
-Also the exception system did not have a lot of time to be tried and tested.
-So just letting people use the exception system more will reveal new
-quality of life upgrades that can be made with time.
+Finally, the exception system has not had a lot of programmer testing.
+More time with encouraged usage will reveal new
+quality of life upgrades that can be made.
 \end{itemize}
 
@@ -47,5 +54,5 @@
 project, but was thrust upon it to do exception inheritance; hence, only
 minimal work is done. A draft for a complete virtual system is available but
-it is not finalized.  A future \CFA project is to complete that work and then
+not finalized. A future \CFA project is to complete that work and then
 update the exception system that uses the current version.
 
@@ -53,14 +60,19 @@
 exception traits. The most important one is an assertion to check one virtual
 type is a child of another. This check precisely captures many of the
-correctness requirements.
+current ad-hoc correctness requirements.
+
+Other features of the virtual system could also remove some of the
+special cases around exception virtual tables, such as the generation
+of the @msg@ function.
 
 The full virtual system might also include other improvement like associated
 types to allow traits to refer to types not listed in their header. This
 feature allows exception traits to not refer to the virtual-table type
-explicitly, removing the need for the current interface macros.
+explicitly, removing the need for the current interface macros,
+such as @EHM_IS_EXCEPTION@.
 
 \section{Additional Raises}
 Several other kinds of exception raises were considered beyond termination
-(@throw@), resumption (@throwResume@), and reraise.
+(@throw@), resumption (@throwResume@), and re-raise.
 
 The first is a non-local/concurrent raise providing asynchronous exceptions,
@@ -74,5 +86,5 @@
 Non-local/concurrent raise requires more
 coordination between the concurrency system
-and the exception system. Many of the interesting design decisions centre
+and the exception system. Many of the interesting design decisions center
 around masking, \ie controlling which exceptions may be thrown at a stack. It
 would likely require more of the virtual system and would also effect how
@@ -93,17 +105,17 @@
 Checked exceptions make exceptions part of a function's type by adding an
 exception signature. An exception signature must declare all checked
-exceptions that could propagate from the function (either because they were
-raised inside the function or came from a sub-function). This improves safety
+exceptions that could propagate from the function, either because they were
+raised inside the function or came from a sub-function. This improves safety
 by making sure every checked exception is either handled or consciously
 passed on.
 
-However checked exceptions were never seriously considered for this project
-because they have significant trade-offs in usablity and code reuse in
+Checked exceptions were never seriously considered for this project
+because they have significant trade-offs in usability and code reuse in
 exchange for the increased safety.
 These trade-offs are most problematic when trying to pass exceptions through
 higher-order functions from the functions the user passed into the
 higher-order function. There are no well known solutions to this problem
-that were satisfactory for \CFA (which carries some of C's flexibility
-over safety design) so additional research is needed.
+that were satisfactory for \CFA (which carries some of C's
+flexibility-over-safety design) so additional research is needed.
 
 Follow-up work might add some form of checked exceptions to \CFA,
@@ -128,9 +140,9 @@
 Zero-cost resumptions is still an open problem. First, because libunwind does
 not support a successful-exiting stack-search without doing an unwind.
-Workarounds are possible but awkward. Ideally an extension to libunwind could
-be made, but that would either require separate maintenance or gain enough
-support to have it folded into the standard.
+Workarounds are possible but awkward. Ideally, an extension to libunwind could
+be made, but that would either require separate maintenance or gaining enough
+support to have it folded into the official library itself.
 
-Also new techniques to skip previously searched parts of the stack need to be
+Also, new techniques to skip previously searched parts of the stack need to be
 developed to handle the recursive resume problem and support advanced algebraic
 effects.
@@ -158,5 +170,5 @@
 to leave the handler.
 Currently, mimicking this behaviour in \CFA is possible by throwing a
-termination inside a resumption handler.
+termination exception inside a resumption handler.
 
 % Maybe talk about the escape; and escape CONTROL_STMT; statements or how
Index: doc/theses/andrew_beach_MMath/implement.tex
===================================================================
--- doc/theses/andrew_beach_MMath/implement.tex	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ doc/theses/andrew_beach_MMath/implement.tex	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -14,76 +14,112 @@
 \label{s:VirtualSystem}
 % Virtual table rules. Virtual tables, the pointer to them and the cast.
-While the \CFA virtual system currently has only one public feature, virtual
-cast (see the virtual cast feature \vpageref{p:VirtualCast}),
-substantial structure is required to support it,
+While the \CFA virtual system currently has only two public features, virtual
+cast and virtual tables,
+substantial structure is required to support them,
 and provide features for exception handling and the standard library.
 
 \subsection{Virtual Type}
-Virtual types only have one change to their structure: the addition of a
-pointer to the virtual table, which is called the \emph{virtual-table pointer}.
-Internally, the field is called \snake{virtual_table}.
-The field is fixed after construction. It is always the first field in the
+A virtual type~(see \autoref{s:virtuals}) has a pointer to a virtual table,
+called the \emph{virtual-table pointer},
+which binds each instance of a virtual type to a virtual table.
+Internally, the field is called \snake{virtual_table}
+and is fixed after construction.
+This pointer is also the table's id and how the system accesses the
+virtual table and the virtual members there.
+It is always the first field in the
 structure so that its location is always known.
-\todo{Talk about constructors for virtual types (after they are working).}
-
-The virtual table pointer binds an instance of a virtual type
-to a virtual table.
-The pointer is also the table's id and how the system accesses the
-virtual table and the virtual members there.
-
-\subsection{Type Id}
-Every virtual type has a unique id.
-Type ids can be compared for equality,
-which checks if the types reperented are the same,
-or used to access the type's type information.
-The type information currently is only the parent's type id or, if the
+
+% We have no special rules for these constructors.
+Virtual table pointers are passed to the constructors of virtual types
+as part of field-by-field construction.
+
+\subsection{Type ID}
+Every virtual type has a unique ID.
+These are used in type equality, to check if the representation of two values
+are the same, and to access the type's type information.
+This uniqueness means across a program composed of multiple translation
+units (TU), not uniqueness across all programs or even across multiple
+processes on the same machine.
+
+Our approach for program uniqueness is using a static declaration for each
+type ID, where the run-time storage address of that variable is guaranteed to
+be unique during program execution.
+The type ID storage can also be used for other purposes,
+and is used for type information.
+
+The problem is that a type ID may appear in multiple TUs that compose a
+program (see \autoref{ss:VirtualTable}), so the initial solution would seem
+to be make it external in each translation unit. However, the type ID must
+have a declaration in (exactly) one of the TUs to create the storage.
+No other declaration related to the virtual type has this property, so doing
+this through standard C declarations would require the user to do it manually.
+
+Instead, the linker is used to handle this problem.
+% I did not base anything off of C++17; they are solving the same problem.
+A new feature has been added to \CFA for this purpose, the special attribute
+\snake{cfa_linkonce}, which uses the special section @.gnu.linkonce@.
+When used as a prefix (\eg @.gnu.linkonce.example@), the linker does
+not combine these sections, but instead discards all but one with the same
+full name.
+
+So, each type ID must be given a unique section name with the \snake{linkonce}
+prefix. Luckily, \CFA already has a way to get unique names, the name mangler.
+For example, this could be written directly in \CFA:
+\begin{cfa}
+__attribute__((cfa_linkonce)) void f() {}
+\end{cfa}
+This is translated to:
+\begin{cfa}
+__attribute__((section(".gnu.linkonce._X1fFv___1"))) void _X1fFv___1() {}
+\end{cfa}
+This is done internally to access the name mangler.
+This attribute is useful for other purposes, any other place a unique
+instance required, and should eventually be made part of a public and
+stable feature in \CFA.
+
+\subsection{Type Information}
+
+There is data stored at the type ID's declaration, the type information.
+The type information currently is only the parent's type ID or, if the
 type has no parent, the null pointer.
-
-The id's are implemented as pointers to the type's type information instance.
-Dereferencing the pointer gets the type information.
-The ancestors of a virtual type are found by traversing type ids through
+The ancestors of a virtual type are found by traversing type IDs through
 the type information.
-The information pushes the issue of creating a unique value (for
-the type id) to the problem of creating a unique instance (for type
-information), which the linker can solve.
-
-The advanced linker support is used here to avoid having to create
-a new declaration to attach this data to.
-With C/\CFA's header/implementation file divide for something to appear
-exactly once it must come from a declaration that appears in exactly one
-implementation file; the declarations in header files may exist only once
-they can be included in many different translation units.
-Therefore, structure's declaration will not work.
-Neither will attaching the type information to the virtual table -- although
-a vtable declarations are in implemention files they are not unique, see
-\autoref{ss:VirtualTable}.
-Instead the same type information is generated multiple times and then
-the new attribute \snake{cfa_linkone} is used to removed duplicates.
+An example using helper macros looks like:
+\begin{cfa}
+struct INFO_TYPE(TYPE) {
+	INFO_TYPE(PARENT) const * parent;
+};
+
+__attribute__((cfa_linkonce))
+INFO_TYPE(TYPE) const INFO_NAME(TYPE) = {
+	&INFO_NAME(PARENT),
+};
+\end{cfa}
 
 Type information is constructed as follows:
-\begin{enumerate}
+\begin{enumerate}[nosep]
 \item
-Use the type's name to generate a name for the type information structure.
-This is saved so it may be reused.
+Use the type's name to generate a name for the type information structure,
+which is saved so it can be reused.
 \item
 Generate a new structure definition to store the type
-information. The layout is the same in each case, just the parent's type id,
+information. The layout is the same in each case, just the parent's type ID,
 but the types used change from instance to instance.
-The generated name is used for both this structure and, if relivant, the
+The generated name is used for both this structure and, if relevant, the
 parent pointer.
 If the virtual type is polymorphic then the type information structure is
 polymorphic as well, with the same polymorphic arguments.
 \item
-A seperate name for instances is generated from the type's name.
+A separate name for instances is generated from the type's name.
 \item
-The definition is generated and initialised.
-The parent id is set to the null pointer or to the address of the parent's
+The definition is generated and initialized.
+The parent ID is set to the null pointer or to the address of the parent's
 type information instance. Name resolution handles the rest.
 \item
 \CFA's name mangler does its regular name mangling encoding the type of
-the declaration into the instance name. This gives a completely unique name
+the declaration into the instance name.
+This process gives a completely unique name
 including different instances of the same polymorphic type.
 \end{enumerate}
-\todo{The list is making me realise, some of this isn't ordered.}
 
 Writing that code manually, with helper macros for the early name mangling,
@@ -100,6 +136,7 @@
 \end{cfa}
 
+\begin{comment}
 \subsubsection{\lstinline{cfa\_linkonce} Attribute}
-% I just realised: This is an extension of the inline keyword.
+% I just realized: This is an extension of the inline keyword.
 % An extension of C's at least, it is very similar to C++'s.
 Another feature added to \CFA is a new attribute: \texttt{cfa\_linkonce}.
@@ -113,5 +150,5 @@
 file as if it was a forward declaration, except no definition is required.
 
-This technique is used for type-id instances. A link-once definition is
+This technique is used for type ID instances. A link-once definition is
 generated each time the structure is seen. This will result in multiple
 copies but the link-once attribute ensures all but one are removed for a
@@ -126,22 +163,23 @@
 everything that comes after the special prefix, then only one is used
 and the other is discarded.
+\end{comment}
 
 \subsection{Virtual Table}
 \label{ss:VirtualTable}
-Each virtual type has a virtual table type that stores its type id and
+Each virtual type has a virtual table type that stores its type ID and
 virtual members.
-Each virtual type instance is bound to a table instance that is filled with
-the values of virtual members.
-Both the layout of the fields and their value are decided by the rules given
+An instance of a virtual type is bound to a virtual table instance,
+which have the values of the virtual members.
+Both the layout of the fields (in the virtual table type)
+and their value (in the virtual table instance) are decided by the rules given
 below.
 
-The layout always comes in three parts.
-\todo{Add labels to the virtual table layout figure.}
-The first section is just the type id at the head of the table. It is always
+The layout always comes in three parts (see \autoref{f:VirtualTableLayout}).
+The first section is just the type ID at the head of the table. It is always
 there to ensure that it can be found even when the accessing code does not
 know which virtual type it has.
-The second section are all the virtual members of the parent, in the same
+The second section is all the virtual members of the parent, in the same
 order as they appear in the parent's virtual table. Note that the type may
-change slightly as references to the ``this" will change. This is limited to
+change slightly as references to the ``this" change. This is limited to
 inside pointers/references and via function pointers so that the size (and
 hence the offsets) are the same.
@@ -150,8 +188,9 @@
 
 \begin{figure}
+\begin{center}
 \input{vtable-layout}
+\end{center}
 \caption{Virtual Table Layout}
 \label{f:VirtualTableLayout}
-\todo*{Improve the Virtual Table Layout diagram.}
 \end{figure}
 
@@ -160,5 +199,5 @@
 This, combined with the fixed offset to the virtual table pointer, means that
 for any virtual type, it is always safe to access its virtual table and,
-from there, it is safe to check the type id to identify the exact type of the
+from there, it is safe to check the type ID to identify the exact type of the
 underlying object, access any of the virtual members and pass the object to
 any of the method-like virtual members.
@@ -168,13 +207,40 @@
 the context of the declaration.
 
-The type id is always fixed; with each virtual table type having
-exactly one possible type id.
+The type ID is always fixed, with each virtual table type having
+exactly one possible type ID.
 The virtual members are usually filled in by type resolution.
 The best match for a given name and type at the declaration site is used.
 There are two exceptions to that rule: the @size@ field, the type's size,
-is set using a @sizeof@ expression and the @align@ field, the
+is set using a @sizeof@ expression, and the @align@ field, the
 type's alignment, is set using an @alignof@ expression.
 
-\subsubsection{Concurrency Integration}
+Most of these tools are already inside the compiler. Using simple
+code transformations early on in compilation allows most of that work to be
+handed off to the existing tools. \autoref{f:VirtualTableTransformation}
+shows an example transformation; this example shows an exception virtual table.
+It also shows the transformation on the full declaration.
+For a forward declaration, the @extern@ keyword is preserved and the
+initializer is not added.
+
+\begin{figure}[htb]
+\begin{cfa}
+vtable(example_type) example_name;
+\end{cfa}
+\transformline
+% Check mangling.
+\begin{cfa}
+const struct example_type_vtable example_name = {
+	.__cfavir_typeid : &__cfatid_example_type,
+	.size : sizeof(example_type),
+	.copy : copy,
+	.^?{} : ^?{},
+	.msg : msg,
+};
+\end{cfa}
+\caption{Virtual Table Transformation}
+\label{f:VirtualTableTransformation}
+\end{figure}
+
+\subsection{Concurrency Integration}
 Coroutines and threads need instances of @CoroutineCancelled@ and
 @ThreadCancelled@ respectively to use all of their functionality. When a new
@@ -183,11 +249,12 @@
 at the definition of the main function.
 
-This is showned through code re-writing in
-\autoref{f:ConcurrencyTypeTransformation} and
-\autoref{f:ConcurrencyMainTransformation}.
-In both cases the original declaration is not modified,
+These transformations are shown through code re-writing in
+\autoref{f:CoroutineTypeTransformation} and
+\autoref{f:CoroutineMainTransformation}.
+Threads use the same pattern, with some names and types changed.
+In both cases, the original declaration is not modified,
 only new ones are added.
 
-\begin{figure}
+\begin{figure}[htb]
 \begin{cfa}
 coroutine Example {
@@ -207,9 +274,9 @@
 extern CoroutineCancelled_vtable & _default_vtable;
 \end{cfa}
-\caption{Concurrency Type Transformation}
-\label{f:ConcurrencyTypeTransformation}
+\caption{Coroutine Type Transformation}
+\label{f:CoroutineTypeTransformation}
 \end{figure}
 
-\begin{figure}
+\begin{figure}[htb]
 \begin{cfa}
 void main(Example & this) {
@@ -229,6 +296,6 @@
 	&_default_vtable_object_declaration;
 \end{cfa}
-\caption{Concurrency Main Transformation}
-\label{f:ConcurrencyMainTransformation}
+\caption{Coroutine Main Transformation}
+\label{f:CoroutineMainTransformation}
 \end{figure}
 
@@ -242,11 +309,11 @@
 \begin{cfa}
 void * __cfa__virtual_cast(
-	struct __cfavir_type_td parent,
-	struct __cfavir_type_id const * child );
-\end{cfa}
-The type id of target type of the virtual cast is passed in as @parent@ and
+	struct __cfavir_type_id * parent,
+	struct __cfavir_type_id * const * child );
+\end{cfa}
+The type ID for the target type of the virtual cast is passed in as
+@parent@ and
 the cast target is passed in as @child@.
-
-For generated C code wraps both arguments and the result with type casts.
+The generated C code wraps both arguments and the result with type casts.
 There is also an internal check inside the compiler to make sure that the
 target type is a virtual type.
@@ -255,10 +322,59 @@
 The virtual cast either returns the original pointer or the null pointer
 as the new type.
-So the function does the parent check and returns the appropriate value.
-The parent check is a simple linear search of child's ancestors using the
+The function does the parent check and returns the appropriate value.
+The parent check is a simple linear search of the child's ancestors using the
 type information.
 
 \section{Exceptions}
-% Anything about exception construction.
+% The implementation of exception types.
+
+Creating exceptions can be roughly divided into two parts:
+the exceptions themselves and the virtual system interactions.
+
+Creating an exception type is just a matter of prepending the field  
+with the virtual table pointer to the list of the fields
+(see \autoref{f:ExceptionTypeTransformation}).
+
+\begin{figure}[htb]
+\begin{cfa}
+exception new_exception {
+	// EXISTING FIELDS
+};
+\end{cfa}
+\transformline
+\begin{cfa}
+struct new_exception {
+	struct new_exception_vtable const * virtual_table;
+	// EXISTING FIELDS
+};
+\end{cfa}
+\caption{Exception Type Transformation}
+\label{f:ExceptionTypeTransformation}
+\end{figure}
+
+The integration between exceptions and the virtual system is a bit more
+complex simply because of the nature of the virtual system prototype.
+The primary issue is that the virtual system has no way to detect when it
+should generate any of its internal types and data. This is handled by
+the exception code, which tells the virtual system when to generate
+its components.
+
+All types associated with a virtual type,
+the types of the virtual table and the type ID,
+are generated when the virtual type (the exception) is first found.
+The type ID (the instance) is generated with the exception, if it is
+a monomorphic type.
+However, if the exception is polymorphic, then a different type ID has to
+be generated for every instance. In this case, generation is delayed
+until a virtual table is created.
+% There are actually some problems with this, which is why it is not used
+% for monomorphic types.
+When a virtual table is created and initialized, two functions are created
+to fill in the list of virtual members.
+The first is the @copy@ function that adapts the exception's copy constructor
+to work with pointers, avoiding some issues with the current copy constructor
+interface.
+Second is the @msg@ function that returns a C-string with the type's name,
+including any polymorphic parameters.
 
 \section{Unwinding}
@@ -274,10 +390,8 @@
 stack. On function entry and return, unwinding is handled directly by the
 call/return code embedded in the function.
-In many cases, the position of the instruction pointer (relative to parameter
-and local declarations) is enough to know the current size of the stack
-frame.
-
+
+% Discussing normal stack unwinding:
 Usually, the stack-frame size is known statically based on parameter and
-local variable declarations. Even with dynamic stack-size, the information
+local variable declarations. Even for a dynamic stack-size, the information
 to determine how much of the stack has to be removed is still contained
 within the function.
@@ -285,31 +399,36 @@
 bumping the hardware stack-pointer up or down as needed.
 Constructing/destructing values within a stack frame has
-a similar complexity but can add additional work and take longer.
-
-Unwinding across multiple stack frames is more complex because that
+a similar complexity but larger constants.
+
+% Discussing multiple frame stack unwinding:
+Unwinding across multiple stack frames is more complex, because that
 information is no longer contained within the current function.
-With seperate compilation a function has no way of knowing what its callers
-are so it can't know how large those frames are.
-Without altering the main code path it is also hard to pass that work off
-to the caller.
-
-The traditional unwinding mechanism for C is implemented by saving a snap-shot
-of a function's state with @setjmp@ and restoring that snap-shot with
+With separate compilation,
+a function does not know its callers nor their frame layout.
+Even using the return address, that information is encoded in terms of
+actions in code, intermixed with the actions required to finish the function.
+Without changing the main code path it is impossible to select one of those
+two groups of actions at the return site.
+
+The traditional unwinding mechanism for C is implemented by saving a snapshot
+of a function's state with @setjmp@ and restoring that snapshot with
 @longjmp@. This approach bypasses the need to know stack details by simply
-reseting to a snap-shot of an arbitrary but existing function frame on the
-stack. It is up to the programmer to ensure the snap-shot is valid when it is
-reset and that all required clean-up from the unwound stacks is performed.
-This approach is fragile and requires extra work in the surrounding code.
-
-With respect to the extra work in the surounding code,
-many languages define clean-up actions that must be taken when certain
-sections of the stack are removed. Such as when the storage for a variable
-is removed from the stack or when a try statement with a finally clause is
+resetting to a snapshot of an arbitrary but existing function frame on the
+stack. It is up to the programmer to ensure the snapshot is valid when it is
+reset and that all required cleanup from the unwound stacks is performed.
+Because it does not automate or check any of this cleanup,
+it can be easy to make mistakes and always must be handled manually.
+
+With respect to the extra work in the surrounding code,
+many languages define cleanup actions that must be taken when certain
+sections of the stack are removed, such as when the storage for a variable
+is removed from the stack, possibly requiring a destructor call,
+or when a try statement with a finally clause is
 (conceptually) popped from the stack.
-None of these should be handled by the user --- that would contradict the
-intention of these features --- so they need to be handled automatically.
+None of these cases should be handled by the user -- that would contradict the
+intention of these features -- so they need to be handled automatically.
 
 To safely remove sections of the stack, the language must be able to find and
-run these clean-up actions even when removing multiple functions unknown at
+run these cleanup actions even when removing multiple functions unknown at
 the beginning of the unwinding.
 
@@ -317,6 +436,7 @@
 library that provides tools for stack walking, handler execution, and
 unwinding. What follows is an overview of all the relevant features of
-libunwind needed for this work, and how \CFA uses them to implement exception
-handling.
+libunwind needed for this work.
+Following that is the description of the \CFA code that uses libunwind
+to implement termination.
 
 \subsection{libunwind Usage}
@@ -348,4 +468,5 @@
 In plain C (which \CFA currently compiles down to) this
 flag only handles the cleanup attribute:
+%\label{code:cleanup}
 \begin{cfa}
 void clean_up( int * var ) { ... }
@@ -355,9 +476,9 @@
 in this case @clean_up@, run when the variable goes out of scope.
 This feature is enough to mimic destructors,
-but not try statements which can effect
+but not try statements that affect
 the unwinding.
 
 To get full unwinding support, all of these features must be handled directly
-in assembly and assembler directives; partiularly the cfi directives
+in assembly and assembler directives; particularly the cfi directives
 \snake{.cfi_lsda} and \snake{.cfi_personality}.
 
@@ -399,10 +520,10 @@
 @_UA_FORCE_UNWIND@ specifies a forced unwind call. Forced unwind only performs
 the cleanup phase and uses a different means to decide when to stop
-(see \vref{s:ForcedUnwind}).
+(see \autoref{s:ForcedUnwind}).
 \end{enumerate}
 
 The @exception_class@ argument is a copy of the
 \code{C}{exception}'s @exception_class@ field,
-which is a number that identifies the exception handling mechanism
+which is a number that identifies the EHM
 that created the exception.
 
@@ -410,5 +531,5 @@
 provided storage object. It has two public fields: the @exception_class@,
 which is described above, and the @exception_cleanup@ function.
-The clean-up function is used by the EHM to clean-up the exception, if it
+The cleanup function is used by the EHM to clean up the exception. If it
 should need to be freed at an unusual time, it takes an argument that says
 why it had to be cleaned up.
@@ -432,14 +553,14 @@
 of the most recent stack frame. It continues to call personality functions
 traversing the stack from newest to oldest until a function finds a handler or
-the end of the stack is reached. In the latter case, raise exception returns
-@_URC_END_OF_STACK@.
-
-Second, when a handler is matched, raise exception moves to the clean-up
-phase and walks the stack a second time.
+the end of the stack is reached. In the latter case,
+@_Unwind_RaiseException@ returns @_URC_END_OF_STACK@.
+
+Second, when a handler is matched, @_Unwind_RaiseException@
+moves to the cleanup phase and walks the stack a second time.
 Once again, it calls the personality functions of each stack frame from newest
 to oldest. This pass stops at the stack frame containing the matching handler.
-If that personality function has not install a handler, it is an error.
-
-If an error is encountered, raise exception returns either
+If that personality function has not installed a handler, it is an error.
+
+If an error is encountered, @_Unwind_RaiseException@ returns either
 @_URC_FATAL_PHASE1_ERROR@ or @_URC_FATAL_PHASE2_ERROR@ depending on when the
 error occurred.
@@ -452,7 +573,9 @@
 	_Unwind_Stop_Fn, void *);
 \end{cfa}
-It also unwinds the stack but it does not use the search phase. Instead another
+It also unwinds the stack but it does not use the search phase. Instead,
+another
 function, the stop function, is used to stop searching. The exception is the
-same as the one passed to raise exception. The extra arguments are the stop
+same as the one passed to @_Unwind_RaiseException@.
+The extra arguments are the stop
 function and the stop parameter. The stop function has a similar interface as a
 personality function, except it is also passed the stop parameter.
@@ -494,5 +617,5 @@
 needs its own exception context.
 
-The exception context should be retrieved by calling the function
+The current exception context should be retrieved by calling the function
 \snake{this_exception_context}.
 For sequential execution, this function is defined as
@@ -519,5 +642,5 @@
 The first step of a termination raise is to copy the exception into memory
 managed by the exception system. Currently, the system uses @malloc@, rather
-than reserved memory or the stack top. The exception handling mechanism manages
+than reserved memory or the stack top. The EHM manages
 memory for the exception as well as memory for libunwind and the system's own
 per-exception storage.
@@ -554,5 +677,5 @@
 \newsavebox{\stackBox}
 \begin{lrbox}{\codeBox}
-\begin{lstlisting}[language=CFA,{moredelim=**[is][\color{red}]{@}{@}}]
+\begin{cfa}
 unsigned num_exceptions = 0;
 void throws() {
@@ -573,17 +696,17 @@
     throws();
 }
-\end{lstlisting}
+\end{cfa}
 \end{lrbox}
 
 \begin{lrbox}{\stackBox}
 \begin{lstlisting}
-| try-finally
-| try-catch (Example)
+| finally block (Example)
+| try block
 throws()
-| try-finally
-| try-catch (Example)
+| finally block (Example)
+| try block
 throws()
-| try-finally
-| try-catch (Example)
+| finally block (Example)
+| try block
 throws()
 main()
@@ -598,10 +721,9 @@
 \label{f:MultipleExceptions}
 \end{figure}
-\todo*{Work on multiple exceptions code sample.}
 
 All exceptions are stored in nodes, which are then linked together in lists
 one list per stack, with the
 list head stored in the exception context. Within each linked list, the most
-recently thrown exception is at the head followed by older thrown
+recently thrown exception is at the head, followed by older thrown
 exceptions. This format allows exceptions to be thrown, while a different
 exception is being handled. The exception at the head of the list is currently
@@ -614,29 +736,30 @@
 exception into managed memory. After the exception is handled, the free
 function is used to clean up the exception and then the entire node is
-passed to free, returning the memory back to the heap.
+passed to @free@, returning the memory back to the heap.
 
 \subsection{Try Statements and Catch Clauses}
 The try statement with termination handlers is complex because it must
-compensate for the C code-generation versus
+compensate for the C code-generation versus proper
 assembly-code generated from \CFA. Libunwind
 requires an LSDA and personality function for control to unwind across a
 function. The LSDA in particular is hard to mimic in generated C code.
 
-The workaround is a function called @__cfaehm_try_terminate@ in the standard
-library. The contents of a try block and the termination handlers are converted
-into functions. These are then passed to the try terminate function and it
-calls them.
+The workaround is a function called \snake{__cfaehm_try_terminate} in the
+standard \CFA library. The contents of a try block and the termination
+handlers are converted into nested functions. These are then passed to the
+try terminate function and it calls them, appropriately.
 Because this function is known and fixed (and not an arbitrary function that
-happens to contain a try statement), the LSDA can be generated ahead
+happens to contain a try statement), its LSDA can be generated ahead
 of time.
 
-Both the LSDA and the personality function are set ahead of time using
+Both the LSDA and the personality function for \snake{__cfaehm_try_terminate}
+are set ahead of time using
 embedded assembly. This assembly code is handcrafted using C @asm@ statements
 and contains
-enough information for a single try statement the function repersents.
+enough information for the single try statement the function represents.
 
 The three functions passed to try terminate are:
 \begin{description}
-\item[try function:] This function is the try block, it is where all the code
+\item[try function:] This function is the try block. It is where all the code
 from inside the try block is placed. It takes no parameters and has no
 return value. This function is called during regular execution to run the try
@@ -646,7 +769,11 @@
 decides if a catch clause matches the termination exception. It is constructed
 from the conditional part of each handler and runs each check, top to bottom,
-in turn, first checking to see if the exception type matches and then if the
-condition is true. It takes a pointer to the exception and returns 0 if the
-exception is not handled here. Otherwise the return value is the id of the
+in turn, to see if the exception matches this handler.
+The match is performed in two steps: first, a virtual cast is used to check
+if the raised exception is an instance of the declared exception type or
+one of its descendant types, and then the condition is evaluated, if
+present.
+The match function takes a pointer to the exception and returns 0 if the
+exception is not handled here. Otherwise, the return value is the ID of the
 handler that matches the exception.
 
@@ -659,7 +786,9 @@
 \end{description}
 All three functions are created with GCC nested functions. GCC nested functions
-can be used to create closures,
-in other words functions that can refer to the state of other
-functions on the stack. This approach allows the functions to refer to all the
+can be used to create closures;
+in other words,
+functions that can refer to variables in their lexical scope even though
+those variables are part of a different function.
+This approach allows the functions to refer to all the
 variables in scope for the function containing the @try@ statement. These
 nested functions and all other functions besides @__cfaehm_try_terminate@ in
@@ -669,6 +798,5 @@
 
 \autoref{f:TerminationTransformation} shows the pattern used to transform
-a \CFA try statement with catch clauses into the approprate C functions.
-\todo{Explain the Termination Transformation figure.}
+a \CFA try statement with catch clauses into the appropriate C functions.
 
 \begin{figure}
@@ -728,5 +856,4 @@
 \caption{Termination Transformation}
 \label{f:TerminationTransformation}
-\todo*{Improve (compress?) Termination Transformations.}
 \end{figure}
 
@@ -738,5 +865,5 @@
 Instead of storing the data in a special area using assembly,
 there is just a linked list of possible handlers for each stack,
-with each node on the list reperenting a try statement on the stack.
+with each node on the list representing a try statement on the stack.
 
 The head of the list is stored in the exception context.
@@ -744,27 +871,30 @@
 to the head of the list.
 Instead of traversing the stack, resumption handling traverses the list.
-At each node, the EHM checks to see if the try statement the node repersents
+At each node, the EHM checks to see if the try statement the node represents
 can handle the exception. If it can, then the exception is handled and
-the operation finishes, otherwise the search continues to the next node.
+the operation finishes; otherwise, the search continues to the next node.
 If the search reaches the end of the list without finding a try statement
-that can handle the exception, the default handler is executed and the
-operation finishes.
+with a handler clause
+that can handle the exception, the default handler is executed.
+If the default handler returns, control continues after the raise statement.
 
 Each node has a handler function that does most of the work.
 The handler function is passed the raised exception and returns true
 if the exception is handled and false otherwise.
-
 The handler function checks each of its internal handlers in order,
-top-to-bottom, until it funds a match. If a match is found that handler is
+top-to-bottom, until it finds a match. If a match is found that handler is
 run, after which the function returns true, ignoring all remaining handlers.
 If no match is found the function returns false.
-The match is performed in two steps, first a virtual cast is used to see
-if the thrown exception is an instance of the declared exception or one of
-its descendant type, then check to see if passes the custom predicate if one
-is defined. This ordering gives the type guarantee used in the predicate.
+The match is performed in two steps. First a virtual cast is used to see
+if the raised exception is an instance of the declared exception type or one
+of its descendant types, if so, then the second step is to see if the
+exception passes the custom predicate
+if one is defined.
+% You need to make sure the type is correct before running the predicate
+% because the predicate can depend on that.
 
 \autoref{f:ResumptionTransformation} shows the pattern used to transform
-a \CFA try statement with catch clauses into the approprate C functions.
-\todo{Explain the Resumption Transformation figure.}
+a \CFA try statement with catchResume clauses into the appropriate
+C functions.
 
 \begin{figure}
@@ -807,13 +937,13 @@
 \caption{Resumption Transformation}
 \label{f:ResumptionTransformation}
-\todo*{Improve (compress?) Resumption Transformations.}
 \end{figure}
 
 % Recursive Resumption Stuff:
 \autoref{f:ResumptionMarking} shows search skipping
-(see \vpageref{s:ResumptionMarking}), which ignores parts of
+(see \autoref{s:ResumptionMarking}), which ignores parts of
 the stack
-already examined, is accomplished by updating the front of the list as the
-search continues. Before the handler at a node is called, the head of the list
+already examined, and is accomplished by updating the front of the list as
+the search continues.
+Before the handler is called at a matching node, the head of the list
 is updated to the next node of the current node. After the search is complete,
 successful or not, the head of the list is reset.
@@ -822,16 +952,16 @@
 been checked are not on the list while a handler is run. If a resumption is
 thrown during the handling of another resumption, the active handlers and all
-the other handler checked up to this point are not checked again.
+the other handlers checked up to this point are not checked again.
 % No paragraph?
 This structure also supports new handlers added while the resumption is being
 handled. These are added to the front of the list, pointing back along the
-stack --- the first one points over all the checked handlers ---
+stack -- the first one points over all the checked handlers --
 and the ordering is maintained.
 
 \begin{figure}
+\centering
 \input{resumption-marking}
 \caption{Resumption Marking}
 \label{f:ResumptionMarking}
-\todo*{Label Resumption Marking to aid clarity.}
 \end{figure}
 
@@ -851,12 +981,47 @@
 \section{Finally}
 % Uses destructors and GCC nested functions.
-A finally clause is placed into a GCC nested-function with a unique name,
-and no arguments or return values.
-This nested function is then set as the cleanup
-function of an empty object that is declared at the beginning of a block placed
-around the context of the associated @try@ statement.
-
-The rest is handled by GCC. The try block and all handlers are inside this
-block. At completion, control exits the block and the empty object is cleaned
+
+%\autoref{code:cleanup}
+A finally clause is handled by converting it into a once-off destructor.
+The code inside the clause is placed into a GCC nested-function
+with a unique name, and no arguments or return values.
+This nested function is
+then set as the cleanup function of an empty object that is declared at the
+beginning of a block placed around the context of the associated try
+statement, as shown in \autoref{f:FinallyTransformation}.
+
+\begin{figure}
+\begin{cfa}
+try {
+	// TRY BLOCK
+} finally {
+	// FINALLY BLOCK
+}
+\end{cfa}
+
+\transformline
+
+\begin{cfa}
+{
+	void finally(void *__hook){
+		// FINALLY BLOCK
+	}
+	__attribute__ ((cleanup(finally)))
+	struct __cfaehm_cleanup_hook __finally_hook;
+	{
+		// TRY BLOCK
+	}
+}
+\end{cfa}
+
+\caption{Finally Transformation}
+\label{f:FinallyTransformation}
+\end{figure}
+
+The rest is handled by GCC.
+The TRY BLOCK
+contains the try block itself as well as all code generated for handlers.
+Once that code has completed,
+control exits the block and the empty object is cleaned
 up, which runs the function that contains the finally code.
 
@@ -864,7 +1029,7 @@
 % Stack selections, the three internal unwind functions.
 
-Cancellation also uses libunwind to do its stack traversal and unwinding,
-however it uses a different primary function: @_Unwind_ForcedUnwind@. Details
-of its interface can be found in the Section~\vref{s:ForcedUnwind}.
+Cancellation also uses libunwind to do its stack traversal and unwinding.
+However, it uses a different primary function: @_Unwind_ForcedUnwind@. Details
+of its interface can be found in Section~\vref{s:ForcedUnwind}.
 
 The first step of cancellation is to find the cancelled stack and its type:
@@ -887,5 +1052,5 @@
 passed to the forced-unwind function. The general pattern of all three stop
 functions is the same: continue unwinding until the end of stack and
-then preform the appropriate transfer.
+then perform the appropriate transfer.
 
 For main stack cancellation, the transfer is just a program abort.
Index: doc/theses/andrew_beach_MMath/intro.tex
===================================================================
--- doc/theses/andrew_beach_MMath/intro.tex	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ doc/theses/andrew_beach_MMath/intro.tex	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -11,72 +11,59 @@
 
 % Now take a step back and explain what exceptions are generally.
+Exception handling provides dynamic inter-function control flow.
 A language's EHM is a combination of language syntax and run-time
-components that are used to construct, raise, and handle exceptions,
-including all control flow.
-Exceptions are an active mechanism for replacing passive error/return codes and return unions (Go and Rust).
-Exception handling provides dynamic inter-function control flow.
+components that construct, raise, propagate and handle exceptions,
+to provide all of that control flow.
 There are two forms of exception handling covered in this thesis:
 termination, which acts as a multi-level return,
 and resumption, which is a dynamic function call.
-% PAB: Maybe this sentence was suppose to be deleted?
-Termination handling is much more common,
-to the extent that it is often seen as the only form of handling.
-% PAB: I like this sentence better than the next sentence.
-% This separation is uncommon because termination exception handling is so
-% much more common that it is often assumed.
-% WHY: Mention other forms of continuation and \cite{CommonLisp} here?
-
-Exception handling relies on the concept of nested functions to create handlers that deal with exceptions.
+% About other works:
+Often, when this separation is not made, termination exceptions are assumed
+as they are more common and may be the only form of handling provided in
+a language.
+
+All types of exception handling link a raise with a handler.
+Both operations are usually language primitives, although raises can be
+treated as a function that takes an exception argument.
+Handlers are more complex, as they are added to and removed from the stack
+during execution, must specify what they can handle and must give the code to
+handle the exception.
+
+Exceptions work with different execution models but for the descriptions
+that follow a simple call stack, with functions added and removed in a
+first-in-last-out order, is assumed.
+
+Termination exception handling searches the stack for the handler, then
+unwinds the stack to where the handler was found before calling it.
+The handler is run inside the function that defined it and when it finishes
+it returns control to that function.
 \begin{center}
-\begin{tabular}[t]{ll}
-\begin{lstlisting}[aboveskip=0pt,belowskip=0pt,language=CFA,{moredelim=**[is][\color{red}]{@}{@}}]
-void f( void (*hp)() ) {
-	hp();
-}
-void g( void (*hp)() ) {
-	f( hp );
-}
-void h( int @i@, void (*hp)() ) {
-	void @handler@() { // nested
-		printf( "%d\n", @i@ );
-	}
-	if ( i == 1 ) hp = handler;
-	if ( i > 0 ) h( i - 1, hp );
-	else g( hp );
-}
-h( 2, 0 );
-\end{lstlisting}
-&
-\raisebox{-0.5\totalheight}{\input{handler}}
-\end{tabular}
+%\input{termination}
+%
+%\medskip
+\input{termhandle.pstex_t}
+% I hate these diagrams, but I can't access xfig to fix them and they are
+% better than the alternative.
 \end{center}
-The nested function @handler@ in the second stack frame is explicitly passed to function @f@.
-When this handler is called in @f@, it uses the parameter @i@ in the second stack frame, which is accessible by an implicit lexical-link pointer.
-Setting @hp@ in @h@ at different points in the recursion, results in invoking a different handler.
-Exception handling extends this idea by eliminating explicit handler passing, and instead, performing a stack search for a handler that matches some criteria (conditional dynamic call), and calls the handler at the top of the stack.
-It is the runtime search $O(N)$ that differentiates an EHM call (raise) from normal dynamic call $O(1)$ via a function or virtual-member pointer.
-
-Termination exception handling searches the stack for a handler, unwinds the stack to the frame containing the matching handler, and calling the handler at the top of the stack.
+
+Resumption exception handling searches the stack for a handler and then calls
+it without removing any other stack frames.
+The handler is run on top of the existing stack, often as a new function or
+closure capturing the context in which the handler was defined.
+After the handler has finished running, it returns control to the function
+that preformed the raise, usually starting after the raise.
 \begin{center}
-\input{termination}
+%\input{resumption}
+%
+%\medskip
+\input{resumhandle.pstex_t}
+% The other one.
 \end{center}
-Note, since the handler can reference variables in @h@, @h@ must remain on the stack for the handler call.
-After the handler returns, control continues after the lexical location of the handler in @h@ (static return)~\cite[p.~108]{Tennent77}.
-Unwinding allows recover to any previous
-function on the stack, skipping any functions between it and the
-function containing the matching handler.
-
-Resumption exception handling searches the stack for a handler, does \emph{not} unwind the stack to the frame containing the matching handler, and calls the handler at the top of the stack.
-\begin{center}
-\input{resumption}
-\end{center}
-After the handler returns, control continues after the resume in @f@ (dynamic return).
-Not unwinding allows fix up of the problem in @f@ by any previous function on the stack, without disrupting the current set of stack frames.
 
 Although a powerful feature, exception handling tends to be complex to set up
-and expensive to use
+and expensive to use,
 so it is often limited to unusual or ``exceptional" cases.
-The classic example is error handling, where exceptions are used to
-remove error handling logic from the main execution path, while paying
+The classic example is error handling; exceptions can be used to
+remove error handling logic from the main execution path, and pay
 most of the cost only when the error actually occurs.
 
@@ -85,20 +72,20 @@
 The \CFA EHM implements all of the common exception features (or an
 equivalent) found in most other EHMs and adds some features of its own.
-The design of all the features had to be adapted to \CFA's feature set as
+The design of all the features had to be adapted to \CFA's feature set, as
 some of the underlying tools used to implement and express exception handling
 in other languages are absent in \CFA.
-Still the resulting basic syntax resembles that of other languages:
-\begin{lstlisting}[language=CFA,{moredelim=**[is][\color{red}]{@}{@}}]
-@try@ {
+Still, the resulting syntax resembles that of other languages:
+\begin{cfa}
+try {
 	...
 	T * object = malloc(request_size);
 	if (!object) {
-		@throw@ OutOfMemory{fixed_allocation, request_size};
+		throw OutOfMemory{fixed_allocation, request_size};
 	}
 	...
-} @catch@ (OutOfMemory * error) {
+} catch (OutOfMemory * error) {
 	...
 }
-\end{lstlisting}
+\end{cfa}
 % A note that yes, that was a very fast overview.
 The design and implementation of all of \CFA's EHM's features are
@@ -107,143 +94,205 @@
 
 % The current state of the project and what it contributes.
-The majority of the \CFA EHM is implemented in \CFA, except for a small amount of assembler code.
-In addition,
-a suite of tests and performance benchmarks were created as part of this project.
-The \CFA implementation techniques are generally applicable in other programming
+All of these features have been implemented in \CFA,
+covering both changes to the compiler and the run-time.
+In addition, a suite of test cases and performance benchmarks were created
+alongside the implementation.
+The implementation techniques are generally applicable in other programming
 languages and much of the design is as well.
-Some parts of the EHM use features unique to \CFA, and hence,
-are harder to replicate in other programming languages.
-% Talk about other programming languages.
-Three well known programming languages with EHMs, %/exception handling
-C++, Java and Python are examined in the performance work. However, these languages focus on termination
-exceptions, so there is no comparison with resumption.
+Some parts of the EHM use other features unique to \CFA and would be
+harder to replicate in other programming languages.
 
 The contributions of this work are:
 \begin{enumerate}
 \item Designing \CFA's exception handling mechanism, adapting designs from
-other programming languages, and creating new features.
-\item Implementing stack unwinding for the \CFA EHM, including updating
-the \CFA compiler and run-time environment to generate and execute the EHM code.
+other programming languages and creating new features.
+\item Implementing stack unwinding and the \CFA EHM, including updating
+the \CFA compiler and the run-time environment.
 \item Designing and implementing a prototype virtual system.
 % I think the virtual system and per-call site default handlers are the only
 % "new" features, everything else is a matter of implementation.
-\item Creating tests and performance benchmarks to compare with EHM's in other languages.
+\item Creating tests to check the behaviour of the EHM.
+\item Creating benchmarks to check the performance of the EHM,
+as compared to other languages.
 \end{enumerate}
 
-%\todo{I can't figure out a good lead-in to the roadmap.}
-The thesis is organization as follows.
-The next section and parts of \autoref{c:existing} cover existing EHMs.
-New \CFA EHM features are introduced in \autoref{c:features},
+The rest of this thesis is organized as follows.
+The current state of exceptions is covered in \autoref{s:background}.
+The existing state of \CFA is covered in \autoref{c:existing}.
+New EHM features are introduced in \autoref{c:features},
 covering their usage and design.
 That is followed by the implementation of these features in
 \autoref{c:implement}.
-Performance results are presented in \autoref{c:performance}.
-Summing up and possibilities for extending this project are discussed in \autoref{c:future}.
+Performance results are examined in \autoref{c:performance}.
+Possibilities to extend this project are discussed in \autoref{c:future}.
+Finally, the project is summarized in \autoref{c:conclusion}.
 
 \section{Background}
 \label{s:background}
 
-Exception handling is a well examined area in programming languages,
-with papers on the subject dating back the 70s~\cite{Goodenough75}.
+Exception handling has been examined before in programming languages,
+with papers on the subject dating back 70s.\cite{Goodenough75}
 Early exceptions were often treated as signals, which carried no information
-except their identity. Ada~\cite{Ada} still uses this system.
-
-The modern flag-ship for termination exceptions is \Cpp,
+except their identity.
+Ada originally used this system\cite{Ada}, but now allows for a string
+message as a payload\cite{Ada12}.
+
+The modern flagship for termination exceptions -- if one exists -- is \Cpp,
 which added them in its first major wave of non-object-orientated features
-in 1990.
-% https://en.cppreference.com/w/cpp/language/history
-While many EHMs have special exception types,
-\Cpp has the ability to use any type as an exception.
-However, this generality is not particularly useful, and has been pushed aside for classes, with a convention of inheriting from
+in 1990.\cite{CppHistory}
+Many EHMs have special exception types,
+however \Cpp has the ability to use any type as an exception.
+These were found to be not very useful and have been pushed aside for classes
+inheriting from
 \code{C++}{std::exception}.
-While \Cpp has a special catch-all syntax @catch(...)@, there is no way to discriminate its exception type, so nothing can
-be done with the caught value because nothing is known about it.
-Instead the base exception-type \code{C++}{std::exception} is defined with common functionality (such as
-the ability to print a message when the exception is raised but not caught) and all
+Although there is a special catch-all syntax (@catch(...)@), there are no
+operations that can be performed on the caught value, not even type inspection.
+Instead, the base exception-type \code{C++}{std::exception} defines common
+functionality (such as
+the ability to describe the reason the exception was raised) and all
 exceptions have this functionality.
-Having a root exception-type seems to be the standard now, as the guaranteed functionality is worth
-any lost in flexibility from limiting exceptions types to classes.
-
-Java~\cite{Java} was the next popular language to use exceptions.
-Its exception system largely reflects that of \Cpp, except it requires
-exceptions to be a subtype of \code{Java}{java.lang.Throwable}
+That trade-off, restricting usable types to gain guaranteed functionality,
+is almost universal now, as without some common functionality it is almost
+impossible to actually handle any errors.
+
+Java was the next popular language to use exceptions.\cite{Java8}
+Its exception system largely reflects that of \Cpp, except that it requires
+you throw a child type of \code{Java}{java.lang.Throwable}
 and it uses checked exceptions.
-Checked exceptions are part of a function's interface defining all exceptions it or its called functions raise.
-Using this information, it is possible to statically verify if a handler exists for all raised exception, \ie no uncaught exceptions.
-Making exception information explicit, improves clarity and
-safety, but can slow down programming.
-For example, programming complexity increases when dealing with high-order methods or an overly specified
-throws clause. However some of the issues are more
-programming annoyances, such as writing/updating many exception signatures after adding or remove calls.
-Java programmers have developed multiple programming ``hacks'' to circumvent checked exceptions negating the robustness it is suppose to provide.
-For example, the ``catch-and-ignore" pattern, where the handler is empty because the exception does not appear relevant to the programmer versus
-repairing or recovering from the exception.
+Checked exceptions are part of a function's interface,
+the exception signature of the function.
+Every exception that could be raised from a function, either directly or
+because it is not handled from a called function, is given.
+Using this information, it is possible to statically verify if any given
+exception is handled, and guarantee that no exception will go unhandled.
+Making exception information explicit improves clarity and safety,
+but can slow down or restrict programming.
+For example, programming high-order functions becomes much more complex
+if the argument functions could raise exceptions.
+However, as odd it may seem, the worst problems are rooted in the simple
+inconvenience of writing and updating exception signatures.
+This has caused Java programmers to develop multiple programming ``hacks''
+to circumvent checked exceptions, negating their advantages.
+One particularly problematic example is the ``catch-and-ignore'' pattern,
+where an empty handler is used to handle an exception without doing any
+recovery or repair. In theory that could be good enough to properly handle
+the exception, but more often is used to ignore an exception that the       
+programmer does not feel is worth the effort of handling, for instance if
+they do not believe it will ever be raised.
+If they are incorrect, the exception will be silenced, while in a similar
+situation with unchecked exceptions the exception would at least activate    
+the language's unhandled exception code (usually, a program abort with an
+error message).
 
 %\subsection
 Resumption exceptions are less popular,
-although resumption is as old as termination;
-hence, few
+although resumption is as old as termination; that is, few
 programming languages have implemented them.
 % http://bitsavers.informatik.uni-stuttgart.de/pdf/xerox/parc/techReports/
 %   CSL-79-3_Mesa_Language_Manual_Version_5.0.pdf
-Mesa~\cite{Mesa} is one programming languages that did. Experience with Mesa
-is quoted as being one of the reasons resumptions are not
+Mesa is one programming language that did.\cite{Mesa} Experience with Mesa
+is quoted as being one of the reasons resumptions were not
 included in the \Cpp standard.
 % https://en.wikipedia.org/wiki/Exception_handling
-As a result, resumption has ignored in main-stream programming languages.
-However, ``what goes around comes around'' and resumption is being revisited now (like user-level threading).
-While rejecting resumption might have been the right decision in the past, there are decades
-of developments in computer science that have changed the situation.
-Some of these developments, such as functional programming's resumption
-equivalent, algebraic effects\cite{Zhang19}, are enjoying significant success.
-A complete reexamination of resumptions is beyond this thesis, but their re-emergence is
-enough to try them in \CFA.
+Since then, resumptions have been ignored in mainstream programming languages.
+However, resumption is being revisited in the context of decades of other
+developments in programming languages.
+While rejecting resumption may have been the right decision in the past,
+the situation has changed since then.
+Some developments, such as the functional programming equivalent to resumptions,
+algebraic effects\cite{Zhang19}, are enjoying success.
+A complete reexamination of resumption is beyond this thesis,
+but their reemergence is enough reason to try them in \CFA.
 % Especially considering how much easier they are to implement than
-% termination exceptions.
-
-%\subsection
-Functional languages tend to use other solutions for their primary EHM,
-but exception-like constructs still appear.
-Termination appears in error construct, which marks the result of an
-expression as an error; thereafter, the result of any expression that tries to use it is also an
-error, and so on until an appropriate handler is reached.
+% termination exceptions and how much Peter likes them.
+
+%\subsection
+Functional languages tend to use other solutions for their primary error
+handling mechanism, but exception-like constructs still appear.
+Termination appears in the error construct, which marks the result of an
+expression as an error; then the result of any expression that tries to use
+it also results in an error, and so on until an appropriate handler is reached.
 Resumption appears in algebraic effects, where a function dispatches its
 side-effects to its caller for handling.
 
 %\subsection
-Some programming languages have moved to a restricted kind of EHM
-called ``panic".
-In Rust~\cite{Rust}, a panic is just a program level abort that may be implemented by
-unwinding the stack like in termination exception handling.
-% https://doc.rust-lang.org/std/panic/fn.catch_unwind.html
-In Go~\cite{Go}, a panic is very similar to a termination, except it only supports
+More recently, exceptions seem to be vanishing from newer programming
+languages, replaced by ``panic".
+In Rust, a panic is just a program level abort that may be implemented by
+unwinding the stack like in termination exception
+handling.\cite{RustPanicMacro}\cite{RustPanicModule}
+Go's panic though is very similar to a termination, except it only supports
 a catch-all by calling \code{Go}{recover()}, simplifying the interface at
-the cost of flexibility.
-
-%\subsection
-While exception handling's most common use cases are in error handling,
-here are other ways to handle errors with comparisons to exceptions.
+the cost of flexibility.\cite{Go:2021}
+
+%\subsection
+As exception handling's most common use cases are in error handling,
+here are some other ways to handle errors with comparisons with exceptions.
 \begin{itemize}
 \item\emph{Error Codes}:
-This pattern has a function return an enumeration (or just a set of fixed values) to indicate
-if an error occurred and possibly which error it was.
-
-Error codes mix exceptional and normal values, artificially enlarging the type and/or value range.
-Some languages address this issue by returning multiple values or a tuple, separating the error code from the function result.
-However, the main issue with error codes is forgetting to checking them,
+This pattern has a function return an enumeration (or just a set of fixed
+values) to indicate if an error has occurred and possibly which error it was.
+
+Error codes mix exceptional/error and normal values, enlarging the range of
+possible return values. This can be addressed with multiple return values
+(or a tuple) or a tagged union.
+However, the main issue with error codes is forgetting to check them,
 which leads to an error being quietly and implicitly ignored.
-Some new languages have tools that issue warnings, if the error code is
-discarded to avoid this problem.
-Checking error codes also results in bloating the main execution path, especially if an error is not dealt with locally and has to be cascaded down the call stack to a higher-level function..
+Some new languages and tools will try to issue warnings when an error code
+is discarded to avoid this problem.
+Checking error codes also bloats the main execution path,
+especially if the error is not handled immediately and has to be passed
+through multiple functions before it is addressed.
+
+Here is an example of the pattern in Bash, where commands can only  ``return"
+numbers and most output is done through streams of text.
+\begin{lstlisting}[language=bash,escapechar={}]
+# Immediately after running a command:
+case $? in
+0)
+	# Success
+	;;
+1)
+	# Error Code 1
+	;;
+2|3)
+	# Error Code 2 or Error Code 3
+	;;
+# Add more cases as needed.
+asac
+\end{lstlisting}
 
 \item\emph{Special Return with Global Store}:
-Some functions only return a boolean indicating success or failure
-and store the exact reason for the error in a fixed global location.
-For example, many C routines return non-zero or -1, indicating success or failure,
-and write error details into the C standard variable @errno@.
-
-This approach avoids the multiple results issue encountered with straight error codes
-but otherwise has many (if not more) of the disadvantages.
-For example, everything that uses the global location must agree on all possible errors and global variable are unsafe with concurrency.
+Similar to the error codes pattern but the function itself only returns
+that there was an error,
+and stores the reason for the error in a fixed global location.
+For example, many routines in the C standard library will only return some
+error value (such as -1 or a null pointer) and the error code is written into
+the standard variable @errno@.
+
+This approach avoids the multiple results issue encountered with straight
+error codes as only a single error value has to be returned,
+but otherwise has the same disadvantages and more.
+Every function that reads or writes to the global store must agree on all
+possible errors and managing it becomes more complex with concurrency.
+
+This example shows some of what has to be done to robustly handle a C
+standard library function that reports errors this way.
+\begin{lstlisting}[language=C]
+// Now a library function can set the error.
+int handle = open(path_name, flags);
+if (-1 == handle) {
+	switch (errno) {
+    case ENAMETOOLONG:
+		// path_name is a bad argument.
+		break;
+	case ENFILE:
+		// A system resource has been exausted.
+		break;
+	// And many more...
+    }
+}
+\end{lstlisting}
+% cite open man page?
 
 \item\emph{Return Union}:
@@ -251,42 +300,92 @@
 Success is one tag and the errors are another.
 It is also possible to make each possible error its own tag and carry its own
-additional information, but the two branch format is easy to make generic
+additional information, but the two-branch format is easy to make generic
 so that one type can be used everywhere in error handling code.
 
-This pattern is very popular in functional or any semi-functional language with
-primitive support for tagged unions (or algebraic data types).
-% We need listing Rust/rust to format code snipits from it.
+This pattern is very popular in any functional or semi-functional language
+with primitive support for tagged unions (or algebraic data types).
+Return unions can also be expressed as monads (evaluation in a context)
+and often are in languages with special syntax for monadic evaluation,
+such as Haskell's \code{haskell}{do} blocks.
+
+The main advantage is that an arbitrary object can be used to represent an
+error, so it can include a lot more information than a simple error code.
+The disadvantages include that the it does have to be checked along the main
+execution, and if there aren't primitive tagged unions proper, usage can be
+hard to enforce.
+% We need listing Rust/rust to format code snippets from it.
 % Rust's \code{rust}{Result<T, E>}
-The main advantage is providing for more information about an
-error, other than one of a fix-set of ids.
-While some languages use checked union access to force error-code checking,
-it is still possible to bypass the checking.
-The main disadvantage is again significant error code on the main execution path and cascading through called functions.
+
+This is a simple example of examining the result of a failing function in
+Haskell, using its \code{haskell}{Either} type.
+Examining \code{haskell}{error} further would likely involve more matching,
+but the type of \code{haskell}{error} is user defined so there are no
+general cases.
+\begin{lstlisting}[language=haskell]
+case failingFunction argA argB of
+    Right value -> -- Use the successful computed value.
+    Left error -> -- Handle the produced error.
+\end{lstlisting}
+
+Return unions as monads will result in the same code, but can hide most
+of the work to propagate errors in simple cases. The code to actually handle
+the errors, or to interact with other monads (a common case in these
+languages) still has to be written by hand.
+
+If \code{haskell}{failingFunction} is implemented with two helpers that
+use the same error type, then it can be implemented with a \code{haskell}{do}
+block.
+\begin{lstlisting}[language=haskell,literate={}]
+failingFunction x y = do
+	z <- helperOne x
+	helperTwo y z
+\end{lstlisting}
 
 \item\emph{Handler Functions}:
-This pattern implicitly associates functions with errors.
-On error, the function that produced the error implicitly calls another function to
+This pattern associates errors with functions.
+On error, the function that produced the error calls another function to
 handle it.
 The handler function can be provided locally (passed in as an argument,
 either directly as as a field of a structure/object) or globally (a global
 variable).
-C++ uses this approach as its fallback system if exception handling fails, \eg
-\snake{std::terminate_handler} and for a time \snake{std::unexpected_handler}
-
-Handler functions work a lot like resumption exceptions, without the dynamic handler search.
-Therefore, setting setting up the handler can be more complex/expensive, especially if the handle must be passed through multiple function calls, but cheaper to call $O(1)$, and hence,
-are more suited to frequent exceptional situations.
-% The exception being global handlers if they are rarely change as the time
-% in both cases shrinks towards zero.
+C++ uses this approach as its fallback system if exception handling fails,
+such as \snake{std::terminate} and, for a time,
+\snake{std::unexpected}.\footnote{\snake{std::unexpected} was part of the
+Dynamic Exception Specification, which has been removed from the standard
+as of C++20.\cite{CppExceptSpec}}
+
+Handler functions work a lot like resumption exceptions,
+but without the dynamic search for a handler.
+Since setting up the handler can be more complex/expensive,
+especially when the handler has to be passed through multiple layers of
+function calls, but cheaper (constant time) to call,
+they are more suited to more frequent (less exceptional) situations.
+Although, in \Cpp and other languages that do not have checked exceptions,
+they can actually be enforced by the type system be more reliable.
+
+This is a more local example in \Cpp, using a function to provide
+a default value for a mapping.
+\begin{lstlisting}[language=C++]
+ValueT Map::key_or_default(KeyT key, ValueT(*make_default)(KeyT)) {
+	ValueT * value = find_value(key);
+	if (nullptr != value) {
+		return *value;
+	} else {
+		return make_default(key);
+	}
+}
+\end{lstlisting}
 \end{itemize}
 
 %\subsection
 Because of their cost, exceptions are rarely used for hot paths of execution.
-Therefore, there is an element of self-fulfilling prophecy for implementation
-techniques to make exceptions cheap to set-up at the cost
-of expensive usage.
-This cost differential is less important in higher-level scripting languages, where use of exceptions for other tasks is more common.
-An iconic example is Python's @StopIteration@ exception that is thrown by
-an iterator to indicate that it is exhausted, especially when combined with Python's heavy
-use of the iterator-based for-loop.
-% https://docs.python.org/3/library/exceptions.html#StopIteration
+Hence, there is an element of self-fulfilling prophecy as implementation
+techniques have been focused on making them cheap to set up,
+happily making them expensive to use in exchange.
+This difference is less important in higher-level scripting languages,
+where using exceptions for other tasks is more common.
+An iconic example is Python's
+\code{Python}{StopIteration}\cite{PythonExceptions} exception, that
+is thrown by an iterator to indicate that it is exhausted.
+When paired with Python's iterator-based for-loop, this will be thrown every
+time the end of the loop is reached.\cite{PythonForLoop}
Index: doc/theses/andrew_beach_MMath/performance.tex
===================================================================
--- doc/theses/andrew_beach_MMath/performance.tex	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ doc/theses/andrew_beach_MMath/performance.tex	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -3,31 +3,32 @@
 
 Performance is of secondary importance for most of this project.
-Instead, the focus is to get the features working. The only performance
+Instead, the focus was to get the features working. The only performance
 requirement is to ensure the tests for correctness run in a reasonable
-amount of time.
+amount of time. Hence, only a few basic performance tests were performed to
+check this requirement.
 
 \section{Test Set-Up}
 Tests were run in \CFA, C++, Java and Python.
 In addition there are two sets of tests for \CFA,
-one for termination and one for resumption exceptions.
-
-C++ is the most comparable language because both it and \CFA use the same
+one with termination and one with resumption.
+
+GCC C++ is the most comparable language because both it and \CFA use the same
 framework, libunwind.
-In fact, the comparison is almost entirely a quality of implementation
-comparison: \CFA's EHM has had significantly less time to be optimized and
+In fact, the comparison is almost entirely in quality of implementation.
+Specifically, \CFA's EHM has had significantly less time to be optimized and
 does not generate its own assembly. It does have a slight advantage in that
-there are some features it handles directly instead of through utility functions,
-but otherwise \Cpp has a significant advantage.
-
-Java is another very popular language with similar termination semantics.
-It is implemented in a very different environment, a virtual machine with
+\Cpp has to do some extra bookkeeping to support its utility functions,
+but otherwise \Cpp should have a significant advantage.
+
+Java, a popular language with similar termination semantics,
+is implemented in a very different environment, a virtual machine with
 garbage collection.
-It also implements the @finally@ clause on @try@ blocks allowing for a direct
+It also implements the finally clause on try blocks allowing for a direct
 feature-to-feature comparison.
-As with \Cpp, Java's implementation is mature, optimizations
-and has extra features.
-
-Python is used as an alternative point of comparison because of the \CFA EHM's
-current performance goals, which is not to be prohibitively slow while the
+As with \Cpp, Java's implementation is mature, has more optimizations
+and extra features as compared to \CFA.
+
+Python is used as an alternative comparison because of the \CFA EHM's
+current performance goals, which is to not be prohibitively slow while the
 features are designed and examined. Python has similar performance goals for
 creating quick scripts and its wide use suggests it has achieved those goals.
@@ -36,13 +37,20 @@
 resumption exceptions. Even the older programming languages with resumption
 seem to be notable only for having resumption.
-So instead, resumption is compared to a less similar but much more familiar
-feature, termination exceptions.
+On the other hand, the functional equivalents to resumption are too new.
+There does not seem to be any standard implementations in well-known
+languages; so far, they seem confined to extensions and research languages.
+% There was some maybe interesting comparison to an OCaml extension
+% but I'm not sure how to get that working if it is interesting.
+Instead, resumption is compared to its simulation in other programming
+languages: fixup functions that are explicitly passed into a function.
 
 All tests are run inside a main loop that repeatedly performs a test.
 This approach avoids start-up or tear-down time from
 affecting the timing results.
-Each test is run a million times.
-The Java versions of the test run this loop an extra 1000 times before
-beginning to actual test to ``warm-up" the JVM.
+The number of times the loop is run is configurable from the command line;
+the number used in the timing runs is given with the results per test.
+The Java tests run the main loop 1000 times before
+beginning the actual test to ``warm up" the JVM.
+% All other languages are precompiled or interpreted.
 
 Timing is done internally, with time measured immediately before and
@@ -51,9 +59,10 @@
 unhandled exceptions in \Cpp and Java as that would cause the process to
 terminate.
-Luckily, performance on the ``give-up and kill the process" path is not
+Luckily, performance on the ``give up and kill the process" path is not
 critical.
 
 The exceptions used in these tests are always based off of
-a base exception. This requirement minimizes performance differences based
+the base exception for the language.
+This requirement minimizes performance differences based
 on the object model used to represent the exception.
 
@@ -62,19 +71,24 @@
 For example, empty inline assembly blocks are used in \CFA and \Cpp to
 prevent excessive optimizations while adding no actual work.
-Each test was run eleven times. The top three and bottom three results were
-discarded and the remaining five values are averaged.
-
-The tests are compiled with gcc-10 for \CFA and g++-10 for \Cpp. Java is
-compiled with 11.0.11. Python with 3.8. The tests were run on:
-\begin{itemize}[nosep]
-\item
-ARM 2280 Kunpeng 920 48-core 2$\times$socket \lstinline{@} 2.6 GHz running Linux v5.11.0-25
-\item
-AMD 6380 Abu Dhabi 16-core 4$\times$socket \lstinline{@} 2.5 GHz running Linux v5.11.0-25
-\end{itemize}
 
 % We don't use catch-alls but if we did:
 % Catch-alls are done by catching the root exception type (not using \Cpp's
 % \code{C++}{catch(...)}).
+
+When collecting data, each test is run eleven times. The top three and bottom
+three results are discarded and the remaining five values are averaged.
+The test are run with the latest (still pre-release) \CFA compiler,
+using gcc-10 10.3.0 as a backend.
+g++-10 10.3.0 is used for \Cpp.
+Java tests are complied and run with Oracle OpenJDK version 11.0.11.
+Python used CPython version 3.8.10.
+The machines used to run the tests are:
+\begin{itemize}[nosep]
+\item ARM 2280 Kunpeng 920 48-core 2$\times$socket
+      \lstinline{@} 2.6 GHz running Linux v5.11.0-25
+\item AMD 6380 Abu Dhabi 16-core 4$\times$socket
+      \lstinline{@} 2.5 GHz running Linux v5.11.0-25
+\end{itemize}
+These represent the two major families of hardware architecture.
 
 \section{Tests}
@@ -83,95 +97,99 @@
 They should provide a guide as to where the EHM's costs are found.
 
-\paragraph{Raise and Handle}
-The first group measures the cost of a try statement when exceptions are raised
-and \emph{the stack is unwound}.  Each test has has a repeating function like
-the following
+\paragraph{Stack Traversal}
+This group of tests measures the cost of traversing the stack
+(and in termination, unwinding it).
+Inside the main loop is a call to a recursive function.
+This function calls itself F times before raising an exception.
+F is configurable from the command line, but is usually 100.
+This builds up many stack frames, and any contents they may have,
+before the raise.
+The exception is always handled at the base of the stack.
+For example the Empty test for \CFA resumption looks like:
 \begin{cfa}
 void unwind_empty(unsigned int frames) {
 	if (frames) {
 		unwind_empty(frames - 1);
-	} else throw (empty_exception){&empty_vt};
+	} else {
+		throwResume (empty_exception){&empty_vt};
+	}
 }
 \end{cfa}
-which is called M times, where each call recurses to a depth of N, an
-exception is raised, the stack is a unwound, and the exception caught.
+Other test cases have additional code around the recursive call adding
+something besides simple stack frames to the stack.
+Note that both termination and resumption have to traverse over
+the stack but only termination has to unwind it.
 \begin{itemize}[nosep]
+% \item None:
+% Reuses the empty test code (see below) except that the number of frames
+% is set to 0 (this is the only test for which the number of frames is not
+% 100). This isolates the start-up and shut-down time of a throw.
 \item Empty:
-This test measures the cost of raising (stack walking) an exception through empty
-empty stack frames to an empty handler. (see above)
+The repeating function is empty except for the necessary control code.
+As other traversal tests add to this, it is the baseline for the group
+as the cost comes from traversing over and unwinding a stack frame
+that has no other interactions with the exception system.
 \item Destructor:
-
-This test measures the cost of raising an exception through non-empty frames
-where each frame has an object requiring destruction, to an empty
-handler. Hence, there are N destructor calls during unwinding.
-\begin{cfa}
-if (frames) {
-	WithDestructor object;
-	unwind_empty(frames - 1);
-\end{cfa}
+The repeating function creates an object with a destructor before calling
+itself.
+Comparing this to the empty test gives the time to traverse over and
+unwind a destructor.
 \item Finally:
-This test measures the cost of establishing a try block with an empty finally
-clause on the front side of the recursion and running the empty finally clause
-on the back side of the recursion during stack unwinding.
-\begin{cfa}
-if (frames) {
-	try {
-		unwind_finally(frames - 1);
-	} finally {}
-\end{cfa}
+The repeating function calls itself inside a try block with a finally clause
+attached.
+Comparing this to the empty test gives the time to traverse over and
+unwind a finally clause.
 \item Other Handler:
-This test is like the finally test but the try block has a catch clause for an
-exception that is not raised, so catch matching is executed during stack
-unwinding but the match never successes until the catch at the bottom of the
-stack.
-\begin{cfa}
-if (frames) {
-	try {
-		unwind_other(frames - 1);
-	} catch (not_raised_exception *) {}
-\end{cfa}
+The repeating function calls itself inside a try block with a handler that
+does not match the raised exception, but is of the same kind of handler.
+This means that the EHM has to check each handler, and continue
+over all of them until it reaches the base of the stack.
+Comparing this to the empty test gives the time to traverse over and
+unwind a handler.
 \end{itemize}
 
 \paragraph{Cross Try Statement}
-The next group measures just the cost of executing a try statement so
-\emph{there is no stack unwinding}.  Hence, the program main loops N times
-around:
+This group of tests measures the cost for setting up exception handling,
+if it is
+not used because the exceptional case did not occur.
+Tests repeatedly cross (enter, execute and leave) a try statement but never
+perform a raise.
+\begin{itemize}[nosep]
+\item Handler:
+The try statement has a handler (of the appropriate kind).
+\item Finally:
+The try statement has a finally clause.
+\end{itemize}
+
+\paragraph{Conditional Matching}
+This group measures the cost of conditional matching.
+Only \CFA implements the language level conditional match,
+the other languages mimic it with an ``unconditional" match (it still
+checks the exception's type) and conditional re-raise if it is not supposed
+to handle that exception.
+
+Here is the pattern shown in \CFA and \Cpp. Java and Python use the same
+pattern as \Cpp, but with their own syntax.
+
+\begin{minipage}{0.45\textwidth}
 \begin{cfa}
 try {
-} catch (not_raised_exception *) {}
-\end{cfa}
-\begin{itemize}[nosep]
-\item Handler:
-The try statement has a handler.
-\item Finally:
-The try statement replaces the handler with a finally clause.
-\end{itemize}
-
-\paragraph{Conditional Matching}
-This final group measures the cost of conditional matching.
-Only \CFA implements the language level conditional match,
-the other languages must mimic with an ``unconditional" match (it still
-checks the exception's type) and conditional re-raise if it was not supposed
-to handle that exception.
-\begin{center}
-\begin{tabular}{ll}
-\multicolumn{1}{c}{\CFA} & \multicolumn{1}{c}{\Cpp, Java, Python} \\
-\begin{cfa}
-try {
-	throw_exception();
-} catch (empty_exception * exc;
-		 should_catch) {
+	...
+} catch (exception_t * e ;
+		should_catch(e)) {
+	...
 }
 \end{cfa}
-&
-\begin{cfa}
+\end{minipage}
+\begin{minipage}{0.55\textwidth}
+\begin{lstlisting}[language=C++]
 try {
-	throw_exception();
-} catch (EmptyException & exc) {
-	if (!should_catch) throw;
+	...
+} catch (std::exception & e) {
+	if (!should_catch(e)) throw;
+	...
 }
-\end{cfa}
-\end{tabular}
-\end{center}
+\end{lstlisting}
+\end{minipage}
 \begin{itemize}[nosep]
 \item Match All:
@@ -180,4 +198,13 @@
 The condition is always false. (Never matches or always re-raises.)
 \end{itemize}
+
+\paragraph{Resumption Simulation}
+A slightly altered version of the Empty Traversal test is used when comparing
+resumption to fix-up routines.
+The handler, the actual resumption handler or the fix-up routine,
+always captures a variable at the base of the loop,
+and receives a reference to a variable at the raise site, either as a
+field on the exception or an argument to the fix-up routine.
+% I don't actually know why that is here but not anywhere else.
 
 %\section{Cost in Size}
@@ -192,174 +219,246 @@
 
 \section{Results}
-In cases where a feature is not supported by a language the test is skipped
-for that language.
-\PAB{Report all values.
-
-Similarly, if a test does not change between resumption
-and termination in \CFA, then only one test is written and the result
-was put into the termination column.
-}
-
-% Raw Data:
-% run-algol-a.sat
-% ---------------
-% Raise Empty   &  82687046678 &  291616256 &   3252824847 & 15422937623 & 14736271114 \\
-% Raise D'tor   & 219933199603 &  297897792 & 223602799362 &         N/A &         N/A \\
-% Raise Finally & 219703078448 &  298391745 &          N/A &         ... & 18923060958 \\
-% Raise Other   & 296744104920 & 2854342084 & 112981255103 & 15475924808 & 21293137454 \\
-% Cross Handler &      9256648 &   13518430 &       769328 &     3486252 &    31790804 \\
-% Cross Finally &       769319 &        N/A &          N/A &     2272831 &    37491962 \\
-% Match All     &   3654278402 &   47518560 &   3218907794 &  1296748192 &   624071886 \\
-% Match None    &   4788861754 &   58418952 &   9458936430 &  1318065020 &   625200906 \\
-%
-% run-algol-thr-c
-% ---------------
-% Raise Empty   &   3757606400 &   36472972 &   3257803337 & 15439375452 & 14717808642 \\
-% Raise D'tor   &  64546302019 &  102148375 & 223648121635 &         N/A &         N/A \\
-% Raise Finally &  64671359172 &  103285005 &          N/A & 15442729458 & 18927008844 \\
-% Raise Other   & 294143497130 & 2630130385 & 112969055576 & 15448220154 & 21279953424 \\
-% Cross Handler &      9646462 &   11955668 &       769328 &     3453707 &    31864074 \\
-% Cross Finally &       773412 &        N/A &          N/A &     2253825 &    37266476 \\
-% Match All     &   3719462155 &   43294042 &   3223004977 &  1286054154 &   623887874 \\
-% Match None    &   4971630929 &   55311709 &   9481225467 &  1310251289 &   623752624 \\
-%
-% run-algol-04-a
-% --------------
-% Raise Empty   & 0.0 & 0.0 &  3250260945 & 0.0 & 0.0 \\
-% Raise D'tor   & 0.0 & 0.0 & 29017675113 & N/A & N/A \\
-% Raise Finally & 0.0 & 0.0 &         N/A & 0.0 & 0.0 \\
-% Raise Other   & 0.0 & 0.0 & 24411823773 & 0.0 & 0.0 \\
-% Cross Handler & 0.0 & 0.0 &      769334 & 0.0 & 0.0 \\
-% Cross Finally & 0.0 & N/A &         N/A & 0.0 & 0.0 \\
-% Match All     & 0.0 & 0.0 &  3254283504 & 0.0 & 0.0 \\
-% Match None    & 0.0 & 0.0 &  9476060146 & 0.0 & 0.0 \\
-
-\begin{tabular}{|l|c c c c c|}
-\hline
-              & \CFA (Terminate) & \CFA (Resume) & \Cpp & Java & Python \\
-\hline
-Raise Empty   & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\
-Raise D'tor   & 0.0 & 0.0 & 0.0 & N/A & N/A \\
-Raise Finally & 0.0 & 0.0 & N/A & 0.0 & 0.0 \\
-Raise Other   & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\
-Cross Handler & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\
-Cross Finally & 0.0 & N/A & N/A & 0.0 & 0.0 \\
-Match All     & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\
-Match None    & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\
+% First, introduce the tables.
+\autoref{t:PerformanceTermination},
+\autoref{t:PerformanceResumption}
+and~\autoref{t:PerformanceFixupRoutines}
+show the test results.
+In cases where a feature is not supported by a language, the test is skipped
+for that language and the result is marked N/A.
+There are also cases where the feature is supported but measuring its
+cost is impossible. This happened with Java, which uses a JIT that optimizes
+away the tests and cannot be stopped.\cite{Dice21}
+These tests are marked N/C.
+To get results in a consistent range (1 second to 1 minute is ideal,
+going higher is better than going low) N, the number of iterations of the
+main loop in each test, is varied between tests. It is also given in the
+results and has a value in the millions.
+
+An anomaly in some results came from \CFA's use of GCC nested functions.
+These nested functions are used to create closures that can access stack
+variables in their lexical scope.
+However, if they do so, then they can cause the benchmark's run time to
+increase by an order of magnitude.
+The simplest solution is to make those values global variables instead
+of function-local variables.
+% Do we know if editing a global inside nested function is a problem?
+Tests that had to be modified to avoid this problem have been marked
+with a ``*'' in the results.
+
+% Now come the tables themselves:
+% You might need a wider window for this.
+
+\begin{table}[htb]
+\centering
+\caption{Termination Performance Results (sec)}
+\label{t:PerformanceTermination}
+\begin{tabular}{|r|*{2}{|r r r r|}}
+\hline
+                       & \multicolumn{4}{c||}{AMD}         & \multicolumn{4}{c|}{ARM}  \\
+\cline{2-9}
+N\hspace{8pt}          & \multicolumn{1}{c}{\CFA} & \multicolumn{1}{c}{\Cpp} & \multicolumn{1}{c}{Java} & \multicolumn{1}{c||}{Python} &
+                         \multicolumn{1}{c}{\CFA} & \multicolumn{1}{c}{\Cpp} & \multicolumn{1}{c}{Java} & \multicolumn{1}{c|}{Python} \\
+\hline
+Empty Traversal (1M)   & 23.0  & 9.6   & 17.6  & 23.4      & 30.6  & 13.6  & 15.5  & 14.7  \\
+D'tor Traversal (1M)   & 48.1  & 23.5  & N/A   & N/A       & 64.2  & 29.2  & N/A   & N/A   \\
+Finally Traversal (1M) & 3.2*  & N/A   & 17.6  & 29.2      & 3.9*  & N/A   & 15.5  & 19.0  \\
+Other Traversal (1M)   & 3.3*  & 23.9  & 17.7  & 32.8      & 3.9*  & 24.5  & 15.5  & 21.6  \\
+Cross Handler (1B)     & 6.5   & 0.9   & N/C   & 38.0      & 9.6   & 0.8   & N/C   & 32.1  \\
+Cross Finally (1B)     & 0.8   & N/A   & N/C   & 44.6      & 0.6   & N/A   & N/C   & 37.3  \\
+Match All (10M)        & 30.5  & 20.6  & 11.2  & 3.9       & 36.9  & 24.6  & 10.7  & 3.1   \\
+Match None (10M)       & 30.6  & 50.9  & 11.2  & 5.0       & 36.9  & 71.9  & 10.7  & 4.1   \\
 \hline
 \end{tabular}
-
-% run-plg7a-a.sat
-% ---------------
-% Raise Empty   &  57169011329 &  296612564 &   2788557155 & 17511466039 & 23324548496 \\
-% Raise D'tor   & 150599858014 &  318443709 & 149651693682 &         N/A &         N/A \\
-% Raise Finally & 148223145000 &  373325807 &          N/A &         ... & 29074552998 \\
-% Raise Other   & 189463708732 & 3017109322 &  85819281694 & 17584295487 & 32602686679 \\
-% Cross Handler &      8001654 &   13584858 &      1555995 &     6626775 &    41927358 \\
-% Cross Finally &      1002473 &        N/A &          N/A &     4554344 &    51114381 \\
-% Match All     &   3162460860 &   37315018 &   2649464591 &  1523205769 &   742374509 \\
-% Match None    &   4054773797 &   47052659 &   7759229131 &  1555373654 &   744656403 \\
-%
-% run-plg7a-thr-a
-% ---------------
-% Raise Empty   &   3604235388 &   29829965 &   2786931833 & 17576506385 & 23352975105 \\
-% Raise D'tor   &  46552380948 &  178709605 & 149834207219 &         N/A &         N/A \\
-% Raise Finally &  46265157775 &  177906320 &          N/A & 17493045092 & 29170962959 \\
-% Raise Other   & 195659245764 & 2376968982 &  86070431924 & 17552979675 & 32501882918 \\
-% Cross Handler &    397031776 &   12503552 &      1451225 &     6658628 &    42304965 \\
-% Cross Finally &      1136746 &        N/A &          N/A &     4468799 &    46155817 \\
-% Match All     &   3189512499 &   39124453 &   2667795989 &  1525889031 &   733785613 \\
-% Match None    &   4094675477 &   48749857 &   7850618572 &  1566713577 &   733478963 \\
-%
-% run-plg7a-04-a
-% --------------
-% 0.0 are unfilled.
-% Raise Empty   & 0.0 & 0.0 &  2770781479 & 0.0 & 0.0 \\
-% Raise D'tor   & 0.0 & 0.0 & 23530084907 & N/A & N/A \\
-% Raise Finally & 0.0 & 0.0 &         N/A & 0.0 & 0.0 \\
-% Raise Other   & 0.0 & 0.0 & 23816827982 & 0.0 & 0.0 \\
-% Cross Handler & 0.0 & 0.0 &     1422188 & 0.0 & 0.0 \\
-% Cross Finally & 0.0 & N/A &         N/A & 0.0 & 0.0 \\
-% Match All     & 0.0 & 0.0 &  2671989778 & 0.0 & 0.0 \\
-% Match None    & 0.0 & 0.0 &  7829059869 & 0.0 & 0.0 \\
-
-% PLG7A (in seconds)
-\begin{tabular}{|l|c c c c c|}
-\hline
-              & \CFA (Terminate) & \CFA (Resume) & \Cpp & Java & Python \\
-\hline
-Raise Empty   & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\
-Raise D'tor   & 0.0 & 0.0 & 0.0 & N/A & N/A \\
-Raise Finally & 0.0 & 0.0 & N/A & 0.0 & 0.0 \\
-Raise Other   & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\
-Cross Handler & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\
-Cross Finally & 0.0 & N/A & N/A & 0.0 & 0.0 \\
-Match All     & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\
-Match None    & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\
+\end{table}
+
+\begin{table}[htb]
+\centering
+\caption{Resumption Performance Results (sec)}
+\label{t:PerformanceResumption}
+\begin{tabular}{|r||r||r|}
+\hline
+N\hspace{8pt}
+                        & AMD     & ARM  \\
+\hline
+Empty Traversal (10M)   & 1.4     & 1.2  \\
+D'tor Traversal (10M)   & 1.8     & 1.0  \\
+Finally Traversal (10M) & 1.8     & 1.0  \\
+Other Traversal (10M)   & 22.6    & 25.8 \\
+Cross Handler (1B)      & 9.0     & 11.9 \\
+Match All (100M)        & 2.3     & 3.2  \\
+Match None (100M)       & 3.0     & 3.8  \\
 \hline
 \end{tabular}
-
-One result not directly related to \CFA but important to keep in
-mind is that, for exceptions, the standard intuition about which languages
-should go faster often does not hold. For example, there are cases where Python out-performs
-\Cpp and Java. The most likely explanation is that, since exceptions are
-rarely considered to be the common case, the more optimized languages
-make that case expense. In addition, languages with high-level
-representations have a much easier time scanning the stack as there is less
-to decode.
-
-This observation means that while \CFA does not actually keep up with Python in every
-case, it is usually no worse than roughly half the speed of \Cpp. This performance is good
-enough for the prototyping purposes of the project.
-
-The test case where \CFA falls short is Raise Other, the case where the
-stack is unwound including a bunch of non-matching handlers.
-This slowdown seems to come from missing optimizations.
-
-Importantly, there is a huge slowdown in \Cpp's results bringing that brings
-\CFA's performance back in that roughly half speed area. However many other
-\CFA benchmarks increase their run-time by a similar amount falling far
-behind their \Cpp counter-parts.
-
-This suggests that the performance issue in Raise Other is just an
-optimization not being applied. Later versions of gcc may be able to
-optimize this case further, at least down to the half of \Cpp mark.
-A \CFA compiler that directly produced assembly could do even better as it
-would not have to work across some of \CFA's current abstractions, like
-the try terminate function.
-
-Resumption exception handling is also incredibly fast. Often an order of
-magnitude or two better than the best termination speed.
-There is a simple explanation for this; traversing a linked list is much   
-faster than examining and unwinding the stack. When resumption does not do as
-well its when more try statements are used per raise. Updating the internal
-linked list is not very expensive but it does add up.
-
-The relative speed of the Match All and Match None tests (within each
-language) can also show the effectiveness conditional matching as compared
-to catch and rethrow.
-\begin{itemize}[nosep]
-\item
-Java and Python get similar values in both tests.
-Between the interpreted code, a higher level representation of the call
-stack and exception reuse it it is possible the cost for a second
-throw can be folded into the first.
-% Is this due to optimization?
-\item
-Both types of \CFA are slightly slower if there is not a match.
-For termination this likely comes from unwinding a bit more stack through
-libunwind instead of executing the code normally.
-For resumption there is extra work in traversing more of the list and running
-more checks for a matching exceptions.
-% Resumption is a bit high for that but this is my best theory.
-\item
-Then there is \Cpp, which takes 2--3 times longer to catch and rethrow vs.
-just the catch. This is very high, but it does have to repeat the same
-process of unwinding the stack and may have to parse the LSDA of the function
-with the catch and rethrow twice, once before the catch and once after the
-rethrow.
-% I spent a long time thinking of what could push it over twice, this is all
-% I have to explain it.
-\end{itemize}
-The difference in relative performance does show that there are savings to
-be made by performing the check without catching the exception.
+\end{table}
+
+\begin{table}[htb]
+\centering
+\small
+\caption{Resumption/Fixup Routine Comparison (sec)}
+\label{t:PerformanceFixupRoutines}
+\setlength{\tabcolsep}{5pt}
+\begin{tabular}{|r|*{2}{|r r r r r|}}
+\hline
+            & \multicolumn{5}{c||}{AMD}     & \multicolumn{5}{c|}{ARM}  \\
+\cline{2-11}
+N\hspace{8pt}       & \multicolumn{1}{c}{Raise} & \multicolumn{1}{c}{\CFA} & \multicolumn{1}{c}{\Cpp} & \multicolumn{1}{c}{Java} & \multicolumn{1}{c||}{Python} &
+              \multicolumn{1}{c}{Raise} & \multicolumn{1}{c}{\CFA} & \multicolumn{1}{c}{\Cpp} & \multicolumn{1}{c}{Java} & \multicolumn{1}{c|}{Python} \\
+\hline
+Resume Empty (10M)  & 1.4 & 1.4 & 15.4 & 2.3 & 178.0  & 1.2 & 1.2 & 8.9 & 1.2 & 118.4 \\
+\hline
+\end{tabular}
+\end{table}
+
+% Now discuss the results in the tables.
+One result not directly related to \CFA but important to keep in mind is that,
+for exceptions, the standard intuition about which languages should go
+faster often does not hold.
+For example, there are a few cases where Python out-performs
+\CFA, \Cpp and Java.
+% To be exact, the Match All and Match None cases.
+The most likely explanation is that
+the generally faster languages have made ``common cases fast" at the expense
+of the rarer cases. Since exceptions are considered rare, they are made
+expensive to help speed up common actions, such as entering and leaving try
+statements.
+Python, on the other hand, while generally slower than the other languages,
+uses exceptions more and has not sacrificed their performance.
+In addition, languages with high-level representations have a much
+easier time scanning the stack as there is less to decode.
+
+As stated,
+the performance tests are not attempting to show \CFA has a new competitive
+way of implementing exception handling.
+The only performance requirement is to insure the \CFA EHM has reasonable
+performance for prototyping.
+Although that may be hard to exactly quantify, I believe it has succeeded
+in that regard.
+Details on the different test cases follow.
+
+\subsection{Termination \texorpdfstring{(\autoref{t:PerformanceTermination})}{}}
+
+\begin{description}
+\item[Empty Traversal]
+\CFA is slower than \Cpp, but is still faster than the other languages
+and closer to \Cpp than other languages.
+This result is to be expected,
+as \CFA is closer to \Cpp than the other languages.
+
+\item[D'tor Traversal]
+Running destructors causes a huge slowdown in the two languages that support
+them. \CFA has a higher proportionate slowdown but it is similar to \Cpp's.
+Considering the amount of work done in destructors is effectively zero
+(an assembly comment), the cost
+must come from the change of context required to run the destructor.
+
+\item[Finally Traversal]
+Performance is similar to Empty Traversal in all languages that support finally
+clauses. Only Python seems to have a larger than random noise change in
+its run time and it is still not large.
+Despite the similarity between finally clauses and destructors,
+finally clauses seem to avoid the spike that run time destructors have.
+Possibly some optimization removes the cost of changing contexts.
+
+\item[Other Traversal]
+For \Cpp, stopping to check if a handler applies seems to be about as
+expensive as stopping to run a destructor.
+This results in a significant jump.
+
+Other languages experience a small increase in run time.
+The small increase likely comes from running the checks,
+but they could avoid the spike by not having the same kind of overhead for
+switching to the check's context.
+
+\item[Cross Handler]
+Here, \CFA falls behind \Cpp by a much more significant margin.
+This is likely due to the fact that \CFA has to insert two extra function
+calls, while \Cpp does not have to execute any other instructions.
+Python is much further behind.
+
+\item[Cross Finally]
+\CFA's performance now matches \Cpp's from Cross Handler.
+If the code from the finally clause is being inlined,
+which is just an asm comment, than there are no additional instructions
+to execute again when exiting the try statement normally.
+
+\item[Conditional Match]
+Both of the conditional matching tests can be considered on their own.
+However, for evaluating the value of conditional matching itself, the
+comparison of the two sets of results is useful.
+Consider the massive jump in run time for \Cpp going from match all to match
+none, which none of the other languages have.
+Some strange interaction is causing run time to more than double for doing
+twice as many raises.
+Java and Python avoid this problem and have similar run time for both tests,
+possibly through resource reuse or their program representation.
+However, \CFA is built like \Cpp, and avoids the problem as well.
+This matches
+the pattern of the conditional match, which makes the two execution paths
+very similar.
+
+\end{description}
+
+\subsection{Resumption \texorpdfstring{(\autoref{t:PerformanceResumption})}{}}
+
+Moving on to resumption, there is one general note:
+resumption is \textit{fast}. The only test where it fell
+behind termination is Cross Handler.
+In every other case, the number of iterations had to be increased by a
+factor of 10 to get the run time in an appropriate range
+and in some cases resumption still took less time.
+
+% I tried \paragraph and \subparagraph, maybe if I could adjust spacing
+% between paragraphs those would work.
+\begin{description}
+\item[Empty Traversal]
+See above for the general speed-up notes.
+This result is not surprising as resumption's linked-list approach
+means that traversing over stack frames without a resumption handler is
+$O(1)$.
+
+\item[D'tor Traversal]
+Resumption does have the same spike in run time that termination has.
+The run time is actually very similar to Finally Traversal.
+As resumption does not unwind the stack, both destructors and finally
+clauses are run while walking down the stack during the recursive returns.
+So it follows their performance is similar.
+
+\item[Finally Traversal]
+Same as D'tor Traversal,
+except termination did not have a spike in run time on this test case.
+
+\item[Other Traversal]
+Traversing across handlers reduces resumption's advantage as it actually
+has to stop and check each one.
+Resumption still came out ahead (adjusting for iterations) but by much less
+than the other cases.
+
+\item[Cross Handler]
+The only test case where resumption could not keep up with termination,
+although the difference is not as significant as many other cases.
+It is simply a matter of where the costs come from:
+both termination and resumption have some work to set up or tear down a
+handler. It just so happens that resumption's work is slightly slower.
+
+\item[Conditional Match]
+Resumption shows a slight slowdown if the exception is not matched
+by the first handler, which follows from the fact the second handler now has
+to be checked. However, the difference is not large.
+
+\end{description}
+
+\subsection{Resumption/Fixup \texorpdfstring{(\autoref{t:PerformanceFixupRoutines})}{}}
+
+Finally are the results of the resumption/fixup routine comparison.
+These results are surprisingly varied. It is possible that creating a closure
+has more to do with performance than passing the argument through layers of
+calls.
+At 100 stack frames, resumption and manual fixup routines have similar
+performance in \CFA.
+More experiments could try to tease out the exact trade-offs,
+but the prototype's only performance goal is to be reasonable.
+It is already in that range, and \CFA's fixup routine simulation is
+one of the faster simulations as well.
+Plus, exceptions add features and remove syntactic overhead,
+so even at similar performance, resumptions have advantages
+over fixup routines.
Index: doc/theses/andrew_beach_MMath/resumhandle.fig
===================================================================
--- doc/theses/andrew_beach_MMath/resumhandle.fig	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
+++ doc/theses/andrew_beach_MMath/resumhandle.fig	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -0,0 +1,42 @@
+#FIG 3.2  Produced by xfig version 3.2.7b
+Landscape
+Center
+Inches
+Letter
+100.00
+Single
+-2
+1200 2
+6 5550 1200 6450 3600
+2 2 0 1 0 14 50 -1 36 0.000 0 0 -1 0 0 5
+	 5550 1200 6450 1200 6450 3300 5550 3300 5550 1200
+4 1 0 50 -1 4 11 0.0000 2 135 750 6000 3600 Continue\001
+-6
+2 2 0 1 0 14 50 -1 36 0.000 0 0 -1 0 0 5
+	 1200 1200 2100 1200 2100 3300 1200 3300 1200 1200
+2 1 0 1 0 7 30 -1 -1 0.000 0 0 -1 0 0 2
+	 1800 1725 2325 1500
+2 1 0 1 0 14 40 -1 25 0.000 0 0 -1 0 0 8
+	 1700 1200 1700 2025 1575 2025 1800 2250 2025 2025 1900 2025
+	 1900 1200 1700 1200
+2 2 0 1 0 14 50 -1 36 0.000 0 0 -1 0 0 5
+	 3300 1200 4200 1200 4200 3300 3300 3300 3300 1200
+2 1 0 2 14 14 40 -1 -1 0.000 0 0 -1 0 0 8
+	 3800 1200 3800 2025 3675 2025 3900 2250 4125 2025 4000 2025
+	 4000 1200 3800 1200
+2 2 0 1 0 14 50 -1 25 0.000 0 0 -1 0 0 5
+	 3375 1200 4125 1200 4125 900 3375 900 3375 1200
+2 2 0 1 0 14 50 -1 25 0.000 0 0 -1 0 0 5
+	 3375 2250 4125 2250 4125 2325 3375 2325 3375 2250
+2 1 0 1 0 7 30 -1 -1 0.000 0 0 -1 0 0 2
+	 3975 2250 4500 2025
+2 1 0 1 0 7 30 -1 -1 0.000 0 0 -1 0 0 2
+	 3975 1125 4500 900
+4 1 0 50 -1 4 11 0.0000 2 135 1320 1725 3600 Raise \\& Search\001
+4 0 0 50 -1 4 11 0.0000 2 135 375 2400 1650 Path\001
+4 1 0 50 -1 4 11 0.0000 2 135 1050 3750 3600 Run Handler\001
+4 0 0 50 -1 4 11 0.0000 2 135 660 4575 2100 Handler\001
+4 0 0 50 -1 4 11 0.0000 2 135 585 2400 1425 Search\001
+4 0 0 50 -1 4 11 0.0000 2 165 600 4575 1875 Logical\001
+4 0 0 50 -1 4 11 0.0000 2 135 705 4575 2300 Location\001
+4 0 0 50 -1 4 11 0.0000 2 135 660 4575 975 Handler\001
Index: doc/theses/andrew_beach_MMath/resumption-marking.fig
===================================================================
--- doc/theses/andrew_beach_MMath/resumption-marking.fig	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ doc/theses/andrew_beach_MMath/resumption-marking.fig	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -8,53 +8,17 @@
 -2
 1200 2
-6 5985 1530 6165 3105
-1 3 0 1 0 7 50 -1 -1 0.000 1 0.0000 6075 1620 90 90 6075 1620 6075 1710
-1 3 0 1 0 7 50 -1 -1 0.000 1 0.0000 6075 2340 90 90 6075 2340 6075 2430
-1 3 0 1 0 7 50 -1 -1 0.000 1 0.0000 6075 3015 90 90 6075 3015 6075 3105
-2 1 0 1 0 7 50 -1 -1 0.000 0 0 -1 1 0 2
-	1 1 1.00 60.00 120.00
-	 6075 1755 6075 2205
-2 1 0 1 0 7 50 -1 -1 0.000 0 0 -1 1 0 2
-	1 1 1.00 60.00 120.00
-	 6075 2475 6075 2925
--6
-6 3465 1530 3645 3105
-1 3 0 1 0 7 50 -1 -1 0.000 1 0.0000 3555 1620 90 90 3555 1620 3555 1710
-1 3 0 1 0 7 50 -1 -1 0.000 1 0.0000 3555 2340 90 90 3555 2340 3555 2430
-1 3 0 1 0 7 50 -1 -1 0.000 1 0.0000 3555 3015 90 90 3555 3015 3555 3105
-2 1 0 1 0 7 50 -1 -1 0.000 0 0 -1 1 0 2
-	1 1 1.00 60.00 120.00
-	 3555 1755 3555 2205
-2 1 0 1 0 7 50 -1 -1 0.000 0 0 -1 1 0 2
-	1 1 1.00 60.00 120.00
-	 3555 2475 3555 2925
--6
-6 2115 1530 2295 3105
-1 3 0 1 0 7 50 -1 -1 0.000 1 0.0000 2205 1620 90 90 2205 1620 2205 1710
-1 3 0 1 0 7 50 -1 -1 0.000 1 0.0000 2205 2340 90 90 2205 2340 2205 2430
-1 3 0 1 0 7 50 -1 -1 0.000 1 0.0000 2205 3015 90 90 2205 3015 2205 3105
-2 1 0 1 0 7 50 -1 -1 0.000 0 0 -1 1 0 2
-	1 1 1.00 60.00 120.00
-	 2205 1755 2205 2205
-2 1 0 1 0 7 50 -1 -1 0.000 0 0 -1 1 0 2
-	1 1 1.00 60.00 120.00
-	 2205 2475 2205 2925
--6
 1 3 0 1 0 7 50 -1 -1 0.000 1 0.0000 4905 1620 90 90 4905 1620 4905 1710
-1 3 0 1 0 7 50 -1 -1 0.000 1 0.0000 4905 3015 90 90 4905 3015 4905 3105
 1 3 0 1 0 7 50 -1 -1 0.000 1 0.0000 4905 945 90 90 4905 945 4905 1035
 1 3 0 1 0 7 50 -1 -1 0.000 1 0.0000 4905 2340 90 90 4905 2340 4905 2430
-2 1 0 1 0 7 50 -1 -1 0.000 0 0 -1 1 0 2
-	1 1 1.00 60.00 120.00
-	 2790 1620 2430 1620
-2 1 0 1 0 7 50 -1 -1 0.000 0 0 -1 1 0 2
-	1 1 1.00 60.00 120.00
-	 4095 2340 3735 2340
-2 1 0 1 0 7 50 -1 -1 0.000 0 0 -1 1 0 2
-	1 1 1.00 60.00 120.00
-	 6660 1620 6300 1620
-2 1 0 1 0 7 50 -1 -1 0.000 0 0 -1 1 0 2
-	1 1 1.00 60.00 120.00
-	 5490 945 5130 945
+1 3 0 1 0 7 50 -1 -1 0.000 1 0.0000 1665 1620 90 90 1665 1620 1665 1710
+1 3 0 1 0 7 50 -1 -1 0.000 1 0.0000 1665 2340 90 90 1665 2340 1665 2430
+1 3 0 1 0 7 50 -1 -1 0.000 1 0.0000 1665 3060 90 90 1665 3060 1665 3150
+1 3 0 1 0 7 50 -1 -1 0.000 1 0.0000 3195 1620 90 90 3195 1620 3195 1710
+1 3 0 1 0 7 50 -1 -1 0.000 1 0.0000 3195 2340 90 90 3195 2340 3195 2430
+1 3 0 1 0 7 50 -1 -1 0.000 1 0.0000 3195 3060 90 90 3195 3060 3195 3150
+1 3 0 1 0 7 50 -1 -1 0.000 1 0.0000 6525 1620 90 90 6525 1620 6525 1710
+1 3 0 1 0 7 50 -1 -1 0.000 1 0.0000 6525 2340 90 90 6525 2340 6525 2430
+1 3 0 1 0 7 50 -1 -1 0.000 1 0.0000 4905 3060 90 90 4905 3060 4905 3150
+1 3 0 1 0 7 50 -1 -1 0.000 1 0.0000 6525 3060 90 90 6525 3060 6525 3150
 2 1 0 1 0 7 50 -1 -1 0.000 0 0 -1 1 0 2
 	1 1 1.00 60.00 120.00
@@ -66,7 +30,58 @@
 	1 1 1.00 60.00 120.00
 	 4770 1080 4590 1260 4590 2070 4770 2250
-4 0 0 50 -1 0 12 0.0000 4 135 1170 1980 3375 Initial State\001
-4 0 0 50 -1 0 12 0.0000 4 135 1170 3420 3375 Found Handler\001
-4 0 0 50 -1 0 12 0.0000 4 165 810 4770 3375 Try block\001
-4 0 0 50 -1 0 12 0.0000 4 135 900 4770 3555 in Handler\001
-4 0 0 50 -1 0 12 0.0000 4 165 1530 5940 3375 Handling Complete\001
+2 1 0 1 0 7 50 -1 -1 0.000 0 0 -1 1 0 2
+	1 1 1.00 60.00 120.00
+	 1665 1755 1665 2205
+2 1 0 1 0 7 50 -1 -1 0.000 0 0 -1 1 0 2
+	1 1 1.00 60.00 120.00
+	 1665 2475 1665 2925
+2 1 0 1 0 7 50 -1 -1 0.000 0 0 -1 1 0 2
+	1 1 1.00 60.00 120.00
+	 3195 1755 3195 2205
+2 1 0 1 0 7 50 -1 -1 0.000 0 0 -1 1 0 2
+	1 1 1.00 60.00 120.00
+	 3195 2475 3195 2925
+2 1 0 1 0 7 50 -1 -1 0.000 0 0 -1 1 0 2
+	1 1 1.00 60.00 120.00
+	 6525 1755 6525 2205
+2 1 0 1 0 7 50 -1 -1 0.000 0 0 -1 1 0 2
+	1 1 1.00 60.00 120.00
+	 6525 2475 6525 2925
+2 1 0 1 0 7 50 -1 -1 0.000 0 0 -1 1 0 2
+	1 1 1.00 60.00 120.00
+	 1260 1620 1485 1620
+2 1 0 1 0 7 50 -1 -1 0.000 0 0 -1 1 0 2
+	1 1 1.00 60.00 120.00
+	 1980 1440 1755 1440
+2 1 0 1 0 7 50 -1 -1 0.000 0 0 -1 1 0 2
+	1 1 1.00 60.00 120.00
+	 2790 2340 3015 2340
+2 1 0 1 0 7 50 -1 -1 0.000 0 0 -1 1 0 2
+	1 1 1.00 60.00 120.00
+	 3600 1620 3375 1620
+2 1 0 1 0 7 50 -1 -1 0.000 0 0 -1 1 0 2
+	1 1 1.00 60.00 120.00
+	 4500 945 4725 945
+2 1 0 1 0 7 50 -1 -1 0.000 0 0 -1 1 0 2
+	1 1 1.00 60.00 120.00
+	 5265 765 5040 765
+2 1 0 1 0 7 50 -1 -1 0.000 0 0 -1 1 0 2
+	1 1 1.00 60.00 120.00
+	 6120 1620 6345 1620
+2 1 0 1 0 7 50 -1 -1 0.000 0 0 -1 1 0 2
+	1 1 1.00 60.00 120.00
+	 6840 1440 6615 1440
+4 1 0 50 -1 0 12 0.0000 0 135 1170 1665 3375 Initial State\001
+4 1 0 50 -1 0 12 0.0000 0 135 1170 3195 3375 Found Handler\001
+4 1 0 50 -1 0 12 0.0000 0 165 1530 6570 3375 Handling Complete\001
+4 2 0 50 -1 0 12 0.0000 0 135 720 1485 2385 handlers\001
+4 1 0 50 -1 0 12 0.0000 0 135 900 4905 3375 Handler in\001
+4 1 0 50 -1 0 12 0.0000 0 165 810 4905 3600 Try block\001
+4 0 0 50 -1 0 12 0.0000 0 135 360 855 1665 head\001
+4 0 0 50 -1 0 12 0.0000 4 120 810 2025 1485 execution\001
+4 0 0 50 -1 0 12 0.0000 0 135 360 2385 2385 head\001
+4 0 0 50 -1 0 12 0.0000 4 120 810 3645 1665 execution\001
+4 0 0 50 -1 0 12 0.0000 0 135 360 4095 990 head\001
+4 0 0 50 -1 0 12 0.0000 4 120 810 5310 810 execution\001
+4 0 0 50 -1 0 12 0.0000 0 135 360 5715 1665 head\001
+4 0 0 50 -1 0 12 0.0000 4 120 810 6885 1485 execution\001
Index: doc/theses/andrew_beach_MMath/termhandle.fig
===================================================================
--- doc/theses/andrew_beach_MMath/termhandle.fig	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
+++ doc/theses/andrew_beach_MMath/termhandle.fig	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -0,0 +1,40 @@
+#FIG 3.2  Produced by xfig version 3.2.7b
+Landscape
+Center
+Inches
+Letter
+100.00
+Single
+-2
+1200 2
+6 5550 1200 6450 3600
+2 2 0 1 0 14 50 -1 36 0.000 0 0 -1 0 0 5
+	 5550 2250 6450 2250 6450 3300 5550 3300 5550 2250
+2 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
+	 5550 2250 6450 2250 6450 1200 5550 1200 5550 2250
+4 1 0 50 -1 4 11 0.0000 2 135 750 6000 3600 Continue\001
+-6
+2 2 0 1 0 14 50 -1 36 0.000 0 0 -1 0 0 5
+	 1200 1200 2100 1200 2100 3300 1200 3300 1200 1200
+2 1 0 1 0 7 30 -1 -1 0.000 0 0 -1 0 0 2
+	 1800 1725 2325 1500
+2 1 0 1 0 14 40 -1 25 0.000 0 0 -1 0 0 8
+	 1700 1200 1700 2025 1575 2025 1800 2250 2025 2025 1900 2025
+	 1900 1200 1700 1200
+2 2 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 5
+	 3300 2250 4200 2250 4200 1200 3300 1200 3300 2250
+2 2 0 1 0 14 50 -1 25 0.000 0 0 -1 0 0 5
+	 3375 2250 4125 2250 4125 1950 3375 1950 3375 2250
+2 1 0 1 0 7 30 -1 -1 0.000 0 0 -1 0 0 2
+	 3900 1575 4425 1350
+2 1 0 1 0 7 30 -1 -1 0.000 0 0 -1 0 0 2
+	 3900 2100 4425 1875
+2 2 0 1 0 14 50 -1 36 0.000 0 0 -1 0 0 5
+	 3300 2250 4200 2250 4200 3300 3300 3300 3300 2250
+4 0 0 50 -1 4 11 0.0000 2 135 375 2400 1650 Path\001
+4 0 0 50 -1 4 11 0.0000 2 135 450 4500 1500 Stack\001
+4 1 0 50 -1 4 11 0.0000 2 135 1050 3750 3600 Run Handler\001
+4 0 0 50 -1 4 11 0.0000 2 135 660 4500 1875 Handler\001
+4 1 0 50 -1 4 11 0.0000 2 135 1320 1650 3600 Raise \\& Search\001
+4 0 0 50 -1 4 11 0.0000 2 135 585 2400 1425 Search\001
+4 0 0 50 -1 4 11 0.0000 2 135 795 4500 1275 Unwound\001
Index: doc/theses/andrew_beach_MMath/uw-ethesis-frontpgs.tex
===================================================================
--- doc/theses/andrew_beach_MMath/uw-ethesis-frontpgs.tex	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ doc/theses/andrew_beach_MMath/uw-ethesis-frontpgs.tex	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -129,5 +129,23 @@
 \begin{center}\textbf{Abstract}\end{center}
 
-This is the abstract.
+The \CFA (Cforall) programming language is an evolutionary refinement of
+the C programming language, adding modern programming features without
+changing the programming paradigms of C.
+One of these modern programming features is more powerful error handling
+through the addition of an exception handling mechanism (EHM).
+
+This thesis covers the design and implementation of the \CFA EHM,
+along with a review of the other required \CFA features.
+The EHM includes common features of termination exception handling,
+which abandons and recovers from an operation,
+and similar support for resumption exception handling,
+which repairs and continues with an operation.
+The design of both has been adapted to utilize other tools \CFA provides,
+as well as fit with the assertion based interfaces of the language.
+
+The EHM has been implemented into the \CFA compiler and run-time environment.
+Although it has not yet been optimized, performance testing has shown it has
+comparable performance to other EHMs,
+which is sufficient for use in current \CFA programs.
 
 \cleardoublepage
@@ -138,5 +156,29 @@
 \begin{center}\textbf{Acknowledgements}\end{center}
 
-I would like to thank all the little people who made this thesis possible.
+As is tradition and his due, I would like to begin by thanking my
+supervisor Peter Buhr. From accepting me in a first place,
+to helping me run performance tests, I would not be here without him.
+Also if there was an ``artist" field here he would be listed there as well,
+he helped me a lot with the diagrams.
+
+I would like to thank the readers
+Gregor Richards and Yizhou Zhang
+for their feedback and approval.
+The presentation of the thesis has definitely been improved with their
+feedback.
+
+I also thank the entire Cforall Team who built the rest of the
+\CFA compiler. From the existing features I used in my work, to the
+internal tooling that makes further development easier and the optimizations
+that make running tests pass by quickly.
+This includes: Aaron Moss, Rob Schluntz, Thierry Delisle, Michael Brooks,
+Mubeen Zulfieqar \& Fangren Yu.
+
+And thank-you Henry Xue, the co-op student who
+converted my macro implementation of exception declarations into
+the compiler features presented in this thesis.
+
+Finally I thank my family, who are still relieved I learned how to read.
+
 \cleardoublepage
 
Index: doc/theses/andrew_beach_MMath/uw-ethesis.bib
===================================================================
--- doc/theses/andrew_beach_MMath/uw-ethesis.bib	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ doc/theses/andrew_beach_MMath/uw-ethesis.bib	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -1,28 +1,71 @@
 % Bibliography of key references for "LaTeX for Thesis and Large Documents"
 % For use with BibTeX
+% The online reference does not seem to be supported here.
 
-@book{goossens.book,
-	author =	"Michel Goossens and Frank Mittelbach and 
-			 Alexander Samarin",
-	title =		"The \LaTeX\ Companion",
-	year = 		"1994",
-	publisher =	"Addison-Wesley",
-	address = 	"Reading, Massachusetts"
+@misc{Dice21,
+    author	= {Dave Dice},
+    year	= 2021,
+    month	= aug,
+    howpublished= {personal communication}
 }
 
-@book{knuth.book,
-        author =        "Donald Knuth",
-        title =         "The \TeX book",
-        year =          "1986",
-        publisher =     "Addison-Wesley",
-        address =       "Reading, Massachusetts"
+@misc{CforallExceptionBenchmarks,
+    contributer	= {pabuhr@plg},
+    key		= {Cforall Exception Benchmarks},
+    author	= {{\textsf{C}{$\mathbf{\forall}$} Exception Benchmarks}},
+    howpublished= {\href{https://github.com/cforall/ExceptionBenchmarks_SPE20}{https://\-github.com/\-cforall/\-ExceptionBenchmarks\_SPE20}},
 }
 
-@book{lamport.book,
-	author =        "Leslie Lamport",
-	title =         "\LaTeX\ --- A Document Preparation System",
-        edition =       "Second",
-	year = 		"1994",
-	publisher = 	"Addison-Wesley",
-	address =       "Reading, Massachusetts"
+% Could not get `#the-for-statement` to work.
+@misc{PythonForLoop,
+    author={Python Software Foundation},
+    key={Python Compound Statements},
+    howpublished={\href{https://docs.python.org/3/reference/compound_stmts.html}{https://\-docs.python.org/\-3/\-reference/\-compound\_stmts.html}},
+    addendum={Accessed 2021-08-30},
 }
+
+% Again, I would like this to have `#StopIteration`.
+@misc{PythonExceptions,
+    author={Python Software Foundation},
+    key={Python Exceptions},
+    howpublished={\href{https://docs.python.org/3/library/exceptions.html}{https://\-docs.python.org/\-3/\-library/\-exceptions.html}},
+    addendum={Accessed 2021-08-30},
+}
+
+@misc{CppHistory,
+    author={C++ Community},
+    key={Cpp Reference History},
+    howpublished={\href{https://en.cppreference.com/w/cpp/language/history}{https://\-en.cppreference.com/\-w/\-cpp/\-language/\-history}},
+    addendum={Accessed 2021-08-30},
+}
+
+@misc{CppExceptSpec,
+    author={C++ Community},
+    key={Cpp Reference Exception Specification},
+    howpublished={\href{https://en.cppreference.com/w/cpp/language/except_spec}{https://\-en.cppreference.com/\-w/\-cpp/\-language/\-except\_spec}},
+    addendum={Accessed 2021-09-08},
+}
+
+@misc{RustPanicMacro,
+    author={The Rust Team},
+    key={Rust Panic Macro},
+    howpublished={\href{https://doc.rust-lang.org/std/macro.panic.html}{https://\-doc.rust-lang.org/\-std/\-macro.panic.html}},
+    addendum={Accessed 2021-08-31},
+}
+
+@misc{RustPanicModule,
+    author={The Rust Team},
+    key={Rust Panic Module},
+    howpublished={\href{https://doc.rust-lang.org/std/panic/index.html}{https://\-doc.rust-lang.org/\-std/\-panic/\-index.html}},
+    addendum={Accessed 2021-08-31},
+}
+
+@manual{Go:2021,
+    keywords={Go programming language},
+    author={Robert Griesemer and Rob Pike and Ken Thompson},
+    title={{Go} Programming Language},
+    organization={Google},
+    year=2021,
+    note={\href{http://golang.org/ref/spec}{http://\-golang.org/\-ref/\-spec}},
+    addendum={Accessed 2021-08-31},
+}
Index: doc/theses/andrew_beach_MMath/uw-ethesis.tex
===================================================================
--- doc/theses/andrew_beach_MMath/uw-ethesis.tex	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ doc/theses/andrew_beach_MMath/uw-ethesis.tex	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -210,6 +210,4 @@
 \lstMakeShortInline@
 \lstset{language=CFA,style=cfacommon,basicstyle=\linespread{0.9}\tt}
-% PAB causes problems with inline @=
-%\lstset{moredelim=**[is][\protect\color{red}]{@}{@}}
 % Annotations from Peter:
 \newcommand{\PAB}[1]{{\color{blue}PAB: #1}}
Index: doc/theses/andrew_beach_MMath/virtual-tree.fig
===================================================================
--- doc/theses/andrew_beach_MMath/virtual-tree.fig	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
+++ doc/theses/andrew_beach_MMath/virtual-tree.fig	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -0,0 +1,23 @@
+#FIG 3.2  Produced by xfig version 3.2.7b
+Landscape
+Center
+Metric
+A4
+100.00
+Single
+-2
+1200 2
+2 1 0 1 0 7 50 -1 -1 0.000 0 0 -1 1 0 2
+	1 1 1.00 45.00 90.00
+	 2070 1395 2520 1665
+2 1 0 1 0 7 50 -1 -1 0.000 0 0 -1 1 0 2
+	1 1 1.00 45.00 90.00
+	 2070 1395 1530 1665
+2 1 0 1 0 7 50 -1 -1 0.000 0 0 -1 1 0 2
+	1 1 1.00 45.00 90.00
+	 1530 1845 1530 2160
+4 0 0 50 -1 0 12 0.0000 4 165 900 1035 2295 grandchild\001
+4 1 0 50 -1 5 12 0.0000 2 150 720 1485 1800 child\\_a\001
+4 1 0 50 -1 5 12 0.0000 2 150 720 2520 1800 child\\_b\001
+4 1 0 50 -1 5 12 0.0000 2 165 900 2070 1350 root\\_type\001
+4 1 0 50 -1 0 12 0.0000 2 165 1530 2115 1080 Virtual Type Tree\001
Index: doc/theses/andrew_beach_MMath/vtable-layout.fig
===================================================================
--- doc/theses/andrew_beach_MMath/vtable-layout.fig	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ doc/theses/andrew_beach_MMath/vtable-layout.fig	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -8,6 +8,4 @@
 -2
 1200 2
-2 1 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 1
-	 1620 1665
 2 1 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 2
 	 3510 1890 3645 1755
@@ -16,4 +14,10 @@
 2 1 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 2
 	 3645 1305 3645 1755
+2 1 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 2
+	 2115 1935 2250 1935
+2 1 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 4
+	 2250 1170 2115 1170 2115 2475 2250 2475
+2 1 0 1 0 7 50 -1 -1 0.000 0 0 -1 0 0 2
+	 2250 1350 2115 1350
 4 0 0 50 -1 0 12 0.0000 4 165 630 2295 1305 type_id\001
 4 0 0 50 -1 0 12 0.0000 4 165 1170 2295 1500 parent_field0\001
Index: c/theses/andrew_beach_MMath/vtable.fig
===================================================================
--- doc/theses/andrew_beach_MMath/vtable.fig	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ 	(revision )
@@ -1,42 +1,0 @@
-#FIG 3.2  Produced by xfig version 3.2.7b
-Landscape
-Center
-Metric
-A4
-100.00
-Single
--2
-1200 2
-2 1 0 1 0 7 50 -1 -1 0.000 0 0 -1 1 0 2
-	1 1 1.00 45.00 90.00
-	 1260 1350 1485 1665
-2 1 0 1 0 7 50 -1 -1 0.000 0 0 -1 1 0 2
-	1 1 1.00 45.00 90.00
-	 1260 1350 1035 1665
-2 1 1 1 0 7 50 -1 -1 4.000 0 0 -1 1 0 2
-	1 1 1.00 45.00 90.00
-	 1263 1346 1578 1571
-2 1 0 1 0 7 50 -1 -1 0.000 0 0 -1 1 0 2
-	1 1 1.00 45.00 90.00
-	 2520 1350 2520 1665
-2 1 0 1 0 7 50 -1 -1 0.000 0 0 -1 1 0 2
-	1 1 1.00 45.00 90.00
-	 2520 1800 2520 2115
-2 1 1 1 0 7 50 -1 -1 4.000 0 0 -1 1 0 2
-	1 1 1.00 45.00 90.00
-	 2520 1350 2835 1575
-2 1 1 1 0 7 50 -1 -1 4.000 0 0 -1 1 0 2
-	1 1 1.00 45.00 90.00
-	 2517 1804 2832 2029
-4 1 0 50 -1 5 12 0.0000 2 120 240 1035 1800 V1\001
-4 1 0 50 -1 5 12 0.0000 2 120 240 1485 1800 V2\001
-4 1 0 50 -1 5 12 0.0000 2 120 240 1260 1350 V0\001
-4 0 0 50 -1 0 11 0.0000 2 135 420 1620 1665 vtable\001
-4 1 0 50 -1 5 12 0.0000 2 120 240 2520 1350 W0\001
-4 1 0 50 -1 5 12 0.0000 2 120 240 2520 2250 W2\001
-4 1 0 50 -1 5 12 0.0000 2 120 240 2520 1800 W1\001
-4 0 0 50 -1 0 11 0.0000 2 135 420 2880 1620 vtable\001
-4 0 0 50 -1 0 11 0.0000 2 135 420 2880 2070 vtable\001
-4 1 0 50 -1 0 12 0.0000 2 180 1365 1935 1080 virtual type trees\001
-4 0 0 50 -1 5 11 0.0000 2 150 735 3060 1755 Id; <,+\001
-4 0 0 50 -1 5 11 0.0000 2 150 1155 3060 2250 Id; <,+,w,-\001
Index: doc/theses/mubeen_zulfiqar_MMath/allocator.tex
===================================================================
--- doc/theses/mubeen_zulfiqar_MMath/allocator.tex	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ doc/theses/mubeen_zulfiqar_MMath/allocator.tex	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -24,6 +24,7 @@
 \end{itemize}
 
-The new features added to uHeapLmmm (incl. @malloc_size@ routine)
+The new features added to uHeapLmmm (incl. @malloc\_size@ routine)
 \CFA alloc interface with examples.
+
 \begin{itemize}
 \item
@@ -117,8 +118,9 @@
 We added a few more features and routines to the allocator's C interface that can make the allocator more usable to the programmers. THese features will programmer more control on the dynamic memory allocation.
 
-\subsubsection void * aalloc( size_t dim, size_t elemSize )
+\subsubsection void * aalloc( size\_t dim, size\_t elemSize )
 aalloc is an extension of malloc. It allows programmer to allocate a dynamic array of objects without calculating the total size of array explicitly. The only alternate of this routine in the other allocators is calloc but calloc also fills the dynamic memory with 0 which makes it slower for a programmer who only wants to dynamically allocate an array of objects without filling it with 0.
 \paragraph{Usage}
 aalloc takes two parameters.
+
 \begin{itemize}
 \item
@@ -129,8 +131,9 @@
 It returns address of dynamic object allocatoed on heap that can contain dim number of objects of the size elemSize. On failure, it returns NULL pointer.
 
-\subsubsection void * resize( void * oaddr, size_t size )
+\subsubsection void * resize( void * oaddr, size\_t size )
 resize is an extension of relloc. It allows programmer to reuse a cuurently allocated dynamic object with a new size requirement. Its alternate in the other allocators is realloc but relloc also copy the data in old object to the new object which makes it slower for the programmer who only wants to reuse an old dynamic object for a new size requirement but does not want to preserve the data in the old object to the new object.
 \paragraph{Usage}
 resize takes two parameters.
+
 \begin{itemize}
 \item
@@ -141,8 +144,9 @@
 It returns an object that is of the size given but it does not preserve the data in the old object. On failure, it returns NULL pointer.
 
-\subsubsection void * resize( void * oaddr, size_t nalign, size_t size )
+\subsubsection void * resize( void * oaddr, size\_t nalign, size\_t size )
 This resize is an extension of the above resize (FIX ME: cite above resize). In addition to resizing the size of of an old object, it can also realign the old object to a new alignment requirement.
 \paragraph{Usage}
 This resize takes three parameters. It takes an additional parameter of nalign as compared to the above resize (FIX ME: cite above resize).
+
 \begin{itemize}
 \item
@@ -155,8 +159,9 @@
 It returns an object with the size and alignment given in the parameters. On failure, it returns a NULL pointer.
 
-\subsubsection void * amemalign( size_t alignment, size_t dim, size_t elemSize )
+\subsubsection void * amemalign( size\_t alignment, size\_t dim, size\_t elemSize )
 amemalign is a hybrid of memalign and aalloc. It allows programmer to allocate an aligned dynamic array of objects without calculating the total size of the array explicitly. It frees the programmer from calculating the total size of the array.
 \paragraph{Usage}
 amemalign takes three parameters.
+
 \begin{itemize}
 \item
@@ -169,8 +174,9 @@
 It returns a dynamic array of objects that has the capacity to contain dim number of objects of the size of elemSize. The returned dynamic array is aligned to the given alignment. On failure, it returns NULL pointer.
 
-\subsubsection void * cmemalign( size_t alignment, size_t dim, size_t elemSize )
+\subsubsection void * cmemalign( size\_t alignment, size\_t dim, size\_t elemSize )
 cmemalign is a hybrid of amemalign and calloc. It allows programmer to allocate an aligned dynamic array of objects that is 0 filled. The current way to do this in other allocators is to allocate an aligned object with memalign and then fill it with 0 explicitly. This routine provides both features of aligning and 0 filling, implicitly.
 \paragraph{Usage}
 cmemalign takes three parameters.
+
 \begin{itemize}
 \item
@@ -183,38 +189,42 @@
 It returns a dynamic array of objects that has the capacity to contain dim number of objects of the size of elemSize. The returned dynamic array is aligned to the given alignment and is 0 filled. On failure, it returns NULL pointer.
 
-\subsubsection size_t malloc_alignment( void * addr )
-malloc_alignment returns the alignment of a currently allocated dynamic object. It allows the programmer in memory management and personal bookkeeping. It helps the programmer in verofying the alignment of a dynamic object especially in a scenerio similar to prudcer-consumer where a producer allocates a dynamic object and the consumer needs to assure that the dynamic object was allocated with the required alignment.
-\paragraph{Usage}
-malloc_alignment takes one parameters.
+\subsubsection size\_t malloc\_alignment( void * addr )
+malloc\_alignment returns the alignment of a currently allocated dynamic object. It allows the programmer in memory management and personal bookkeeping. It helps the programmer in verofying the alignment of a dynamic object especially in a scenerio similar to prudcer-consumer where a producer allocates a dynamic object and the consumer needs to assure that the dynamic object was allocated with the required alignment.
+\paragraph{Usage}
+malloc\_alignment takes one parameters.
+
 \begin{itemize}
 \item
 addr: the address of the currently allocated dynamic object.
 \end{itemize}
-malloc_alignment returns the alignment of the given dynamic object. On failure, it return the value of default alignment of the uHeapLmmm allocator.
-
-\subsubsection bool malloc_zero_fill( void * addr )
-malloc_zero_fill returns whether a currently allocated dynamic object was initially zero filled at the time of allocation. It allows the programmer in memory management and personal bookkeeping. It helps the programmer in verifying the zero filled property of a dynamic object especially in a scenerio similar to prudcer-consumer where a producer allocates a dynamic object and the consumer needs to assure that the dynamic object was zero filled at the time of allocation.
-\paragraph{Usage}
-malloc_zero_fill takes one parameters.
+malloc\_alignment returns the alignment of the given dynamic object. On failure, it return the value of default alignment of the uHeapLmmm allocator.
+
+\subsubsection bool malloc\_zero\_fill( void * addr )
+malloc\_zero\_fill returns whether a currently allocated dynamic object was initially zero filled at the time of allocation. It allows the programmer in memory management and personal bookkeeping. It helps the programmer in verifying the zero filled property of a dynamic object especially in a scenerio similar to prudcer-consumer where a producer allocates a dynamic object and the consumer needs to assure that the dynamic object was zero filled at the time of allocation.
+\paragraph{Usage}
+malloc\_zero\_fill takes one parameters.
+
 \begin{itemize}
 \item
 addr: the address of the currently allocated dynamic object.
 \end{itemize}
-malloc_zero_fill returns true if the dynamic object was initially zero filled and return false otherwise. On failure, it returns false.
-
-\subsubsection size_t malloc_size( void * addr )
-malloc_size returns the allocation size of a currently allocated dynamic object. It allows the programmer in memory management and personal bookkeeping. It helps the programmer in verofying the alignment of a dynamic object especially in a scenerio similar to prudcer-consumer where a producer allocates a dynamic object and the consumer needs to assure that the dynamic object was allocated with the required size. Its current alternate in the other allocators is malloc_usable_size. But, malloc_size is different from malloc_usable_size as malloc_usabe_size returns the total data capacity of dynamic object including the extra space at the end of the dynamic object. On the other hand, malloc_size returns the size that was given to the allocator at the allocation of the dynamic object. This size is updated when an object is realloced, resized, or passed through a similar allocator routine.
-\paragraph{Usage}
-malloc_size takes one parameters.
+malloc\_zero\_fill returns true if the dynamic object was initially zero filled and return false otherwise. On failure, it returns false.
+
+\subsubsection size\_t malloc\_size( void * addr )
+malloc\_size returns the allocation size of a currently allocated dynamic object. It allows the programmer in memory management and personal bookkeeping. It helps the programmer in verofying the alignment of a dynamic object especially in a scenerio similar to prudcer-consumer where a producer allocates a dynamic object and the consumer needs to assure that the dynamic object was allocated with the required size. Its current alternate in the other allocators is malloc\_usable\_size. But, malloc\_size is different from malloc\_usable\_size as malloc\_usabe\_size returns the total data capacity of dynamic object including the extra space at the end of the dynamic object. On the other hand, malloc\_size returns the size that was given to the allocator at the allocation of the dynamic object. This size is updated when an object is realloced, resized, or passed through a similar allocator routine.
+\paragraph{Usage}
+malloc\_size takes one parameters.
+
 \begin{itemize}
 \item
 addr: the address of the currently allocated dynamic object.
 \end{itemize}
-malloc_size returns the allocation size of the given dynamic object. On failure, it return zero.
-
-\subsubsection void * realloc( void * oaddr, size_t nalign, size_t size )
+malloc\_size returns the allocation size of the given dynamic object. On failure, it return zero.
+
+\subsubsection void * realloc( void * oaddr, size\_t nalign, size\_t size )
 This realloc is an extension of the default realloc (FIX ME: cite default realloc). In addition to reallocating an old object and preserving the data in old object, it can also realign the old object to a new alignment requirement.
 \paragraph{Usage}
 This realloc takes three parameters. It takes an additional parameter of nalign as compared to the default realloc.
+
 \begin{itemize}
 \item
@@ -237,8 +247,9 @@
 It returns a dynamic object of the size of type T. On failure, it return NULL pointer.
 
-\subsubsection T * aalloc( size_t dim )
+\subsubsection T * aalloc( size\_t dim )
 This aalloc is a simplified polymorphic form of above aalloc (FIX ME: cite aalloc). It takes one parameter as compared to the above aalloc that takes two parameters.
 \paragraph{Usage}
 aalloc takes one parameters.
+
 \begin{itemize}
 \item
@@ -247,8 +258,9 @@
 It returns a dynamic object that has the capacity to contain dim number of objects, each of the size of type T. On failure, it return NULL pointer.
 
-\subsubsection T * calloc( size_t dim )
+\subsubsection T * calloc( size\_t dim )
 This calloc is a simplified polymorphic form of defualt calloc (FIX ME: cite calloc). It takes one parameter as compared to the default calloc that takes two parameters.
 \paragraph{Usage}
 This calloc takes one parameter.
+
 \begin{itemize}
 \item
@@ -257,8 +269,9 @@
 It returns a dynamic object that has the capacity to contain dim number of objects, each of the size of type T. On failure, it return NULL pointer.
 
-\subsubsection T * resize( T * ptr, size_t size )
+\subsubsection T * resize( T * ptr, size\_t size )
 This resize is a simplified polymorphic form of above resize (FIX ME: cite resize with alignment). It takes two parameters as compared to the above resize that takes three parameters. It frees the programmer from explicitly mentioning the alignment of the allocation as CFA provides gives allocator the liberty to get the alignment of the returned type.
 \paragraph{Usage}
 This resize takes two parameters.
+
 \begin{itemize}
 \item
@@ -269,8 +282,9 @@
 It returns a dynamic object of the size given in paramters. The returned object is aligned to the alignemtn of type T. On failure, it return NULL pointer.
 
-\subsubsection T * realloc( T * ptr, size_t size )
+\subsubsection T * realloc( T * ptr, size\_t size )
 This realloc is a simplified polymorphic form of defualt realloc (FIX ME: cite realloc with align). It takes two parameters as compared to the above realloc that takes three parameters. It frees the programmer from explicitly mentioning the alignment of the allocation as CFA provides gives allocator the liberty to get the alignment of the returned type.
 \paragraph{Usage}
 This realloc takes two parameters.
+
 \begin{itemize}
 \item
@@ -281,8 +295,9 @@
 It returns a dynamic object of the size given in paramters that preserves the data in the given object. The returned object is aligned to the alignemtn of type T. On failure, it return NULL pointer.
 
-\subsubsection T * memalign( size_t align )
+\subsubsection T * memalign( size\_t align )
 This memalign is a simplified polymorphic form of defualt memalign (FIX ME: cite memalign). It takes one parameters as compared to the default memalign that takes two parameters.
 \paragraph{Usage}
 memalign takes one parameters.
+
 \begin{itemize}
 \item
@@ -291,8 +306,9 @@
 It returns a dynamic object of the size of type T that is aligned to given parameter align. On failure, it return NULL pointer.
 
-\subsubsection T * amemalign( size_t align, size_t dim )
+\subsubsection T * amemalign( size\_t align, size\_t dim )
 This amemalign is a simplified polymorphic form of above amemalign (FIX ME: cite amemalign). It takes two parameter as compared to the above amemalign that takes three parameters.
 \paragraph{Usage}
 amemalign takes two parameters.
+
 \begin{itemize}
 \item
@@ -303,8 +319,9 @@
 It returns a dynamic object that has the capacity to contain dim number of objects, each of the size of type T. The returned object is aligned to the given parameter align. On failure, it return NULL pointer.
 
-\subsubsection T * cmemalign( size_t align, size_t dim  )
+\subsubsection T * cmemalign( size\_t align, size\_t dim  )
 This cmemalign is a simplified polymorphic form of above cmemalign (FIX ME: cite cmemalign). It takes two parameter as compared to the above cmemalign that takes three parameters.
 \paragraph{Usage}
 cmemalign takes two parameters.
+
 \begin{itemize}
 \item
@@ -315,8 +332,9 @@
 It returns a dynamic object that has the capacity to contain dim number of objects, each of the size of type T. The returned object is aligned to the given parameter align and is zero filled. On failure, it return NULL pointer.
 
-\subsubsection T * aligned_alloc( size_t align )
-This aligned_alloc is a simplified polymorphic form of defualt aligned_alloc (FIX ME: cite aligned_alloc). It takes one parameter as compared to the default aligned_alloc that takes two parameters.
-\paragraph{Usage}
-This aligned_alloc takes one parameter.
+\subsubsection T * aligned\_alloc( size\_t align )
+This aligned\_alloc is a simplified polymorphic form of defualt aligned\_alloc (FIX ME: cite aligned\_alloc). It takes one parameter as compared to the default aligned\_alloc that takes two parameters.
+\paragraph{Usage}
+This aligned\_alloc takes one parameter.
+
 \begin{itemize}
 \item
@@ -325,8 +343,9 @@
 It returns a dynamic object of the size of type T that is aligned to the given parameter. On failure, it return NULL pointer.
 
-\subsubsection int posix_memalign( T ** ptr, size_t align )
-This posix_memalign is a simplified polymorphic form of defualt posix_memalign (FIX ME: cite posix_memalign). It takes two parameters as compared to the default posix_memalign that takes three parameters.
-\paragraph{Usage}
-This posix_memalign takes two parameter.
+\subsubsection int posix\_memalign( T ** ptr, size\_t align )
+This posix\_memalign is a simplified polymorphic form of defualt posix\_memalign (FIX ME: cite posix\_memalign). It takes two parameters as compared to the default posix\_memalign that takes three parameters.
+\paragraph{Usage}
+This posix\_memalign takes two parameter.
+
 \begin{itemize}
 \item
@@ -335,4 +354,5 @@
 align: required alignment of the dynamic object.
 \end{itemize}
+
 It stores address of the dynamic object of the size of type T in given parameter ptr. This object is aligned to the given parameter. On failure, it return NULL pointer.
 
@@ -349,7 +369,8 @@
 It returns a dynamic object of the size that is calcutaed by rouding the size of type T. The returned object is also aligned to the page size. On failure, it return NULL pointer.
 
-\subsection{Alloc Interface}
+\subsection Alloc Interface
 In addition to improve allocator interface both for CFA and our standalone allocator uHeapLmmm in C. We also added a new alloc interface in CFA that increases usability of dynamic memory allocation.
 This interface helps programmers in three major ways.
+
 \begin{itemize}
 \item
@@ -371,5 +392,5 @@
 This is the only parameter in the alloc routine that has a fixed-position and it is also the only parameter that does not use a backtick function. It has to be passed at the first position to alloc call in-case of an array allocation of objects of type T.
 It represents the required number of members in the array allocation as in CFA's aalloc (FIX ME: cite aalloc).
-This parameter should be of type size_t.
+This parameter should be of type size\_t.
 
 Example: int a = alloc( 5 )
@@ -377,5 +398,5 @@
 
 \paragraph{Align}
-This parameter is position-free and uses a backtick routine align (`align). The parameter passed with `align should be of type size_t. If the alignment parameter is not a power of two or is less than the default alignment of the allocator (that can be found out using routine libAlign in CFA) then the passed alignment parameter will be rejected and the default alignment will be used.
+This parameter is position-free and uses a backtick routine align (`align). The parameter passed with `align should be of type size\_t. If the alignment parameter is not a power of two or is less than the default alignment of the allocator (that can be found out using routine libAlign in CFA) then the passed alignment parameter will be rejected and the default alignment will be used.
 
 Example: int b = alloc( 5 , 64`align )
@@ -385,4 +406,5 @@
 This parameter is position-free and uses a backtick routine fill (`fill). In case of realloc, only the extra space after copying the data in the old object will be filled with given parameter.
 Three types of parameters can be passed using `fill.
+
 \begin{itemize}
 \item
Index: doc/theses/mubeen_zulfiqar_MMath/background.tex
===================================================================
--- doc/theses/mubeen_zulfiqar_MMath/background.tex	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ doc/theses/mubeen_zulfiqar_MMath/background.tex	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -23,3 +23,42 @@
 ====================
 
-\cite{Wasik08}
+\section{Background}
+
+% FIXME: cite wasik
+\cite{wasik.thesis}
+
+\subsection{Memory Allocation}
+With dynamic allocation being an important feature of C, there are many standalone memory allocators that have been designed for different purposes. For this thesis, we chose 7 of the most popular and widely used memory allocators.
+
+\paragraph{dlmalloc}
+dlmalloc (FIX ME: cite allocator) is a thread-safe allocator that is single threaded and single heap. dlmalloc maintains free-lists of different sizes to store freed dynamic memory. (FIX ME: cite wasik)
+
+\paragraph{hoard}
+Hoard (FIX ME: cite allocator) is a thread-safe allocator that is multi-threaded and using a heap layer framework. It has per-thred heaps that have thread-local free-lists, and a gloabl shared heap. (FIX ME: cite wasik)
+
+\paragraph{jemalloc}
+jemalloc (FIX ME: cite allocator) is a thread-safe allocator that uses multiple arenas. Each thread is assigned an arena. Each arena has chunks that contain contagious memory regions of same size. An arena has multiple chunks that contain regions of multiple sizes.
+
+\paragraph{ptmalloc}
+ptmalloc (FIX ME: cite allocator) is a modification of dlmalloc. It is a thread-safe multi-threaded memory allocator that uses multiple heaps. ptmalloc heap has similar design to dlmalloc's heap.
+
+\paragraph{rpmalloc}
+rpmalloc (FIX ME: cite allocator) is a thread-safe allocator that is multi-threaded and uses per-thread heap. Each heap has multiple size-classes and each size-calss contains memory regions of the relevant size.
+
+\paragraph{tbb malloc}
+tbb malloc (FIX ME: cite allocator) is a thread-safe allocator that is multi-threaded and uses private heap for each thread. Each private-heap has multiple bins of different sizes. Each bin contains free regions of the same size.
+
+\paragraph{tc malloc}
+tcmalloc (FIX ME: cite allocator) is a thread-safe allocator. It uses per-thread cache to store free objects that prevents contention on shared resources in multi-threaded application. A central free-list is used to refill per-thread cache when it gets empty.
+
+\subsection{Benchmarks}
+There are multiple benchmarks that are built individually and evaluate different aspects of a memory allocator. But, there is not standard set of benchamrks that can be used to evaluate multiple aspects of memory allocators.
+
+\paragraph{threadtest}
+(FIX ME: cite benchmark and hoard) Each thread repeatedly allocates and then deallocates 100,000 objects. Runtime of the benchmark evaluates its efficiency.
+
+\paragraph{shbench}
+(FIX ME: cite benchmark and hoard) Each thread allocates and randomly frees a number of random-sized objects. It is a stress test that also uses runtime to determine efficiency of the allocator.
+
+\paragraph{larson}
+(FIX ME: cite benchmark and hoard) Larson simulates a server environment. Multiple threads are created where each thread allocator and free a number of objects within a size range. Some objects are passed from threads to the child threads to free. It caluculates memory operations per second as an indicator of memory allocator's performance.
Index: doc/theses/mubeen_zulfiqar_MMath/benchmarks.tex
===================================================================
--- doc/theses/mubeen_zulfiqar_MMath/benchmarks.tex	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ doc/theses/mubeen_zulfiqar_MMath/benchmarks.tex	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -149,5 +149,5 @@
 *** FIX ME: Insert a figure of above benchmark with description
 
-\paragrpah{Relevant Knobs}
+\paragraph{Relevant Knobs}
 *** FIX ME: Insert Relevant Knobs
 
Index: doc/theses/mubeen_zulfiqar_MMath/intro.tex
===================================================================
--- doc/theses/mubeen_zulfiqar_MMath/intro.tex	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ doc/theses/mubeen_zulfiqar_MMath/intro.tex	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -47,11 +47,11 @@
 \begin{itemize}
 \item
-aligned_alloc
+aligned\_alloc
 \item
-malloc_usable_size
+malloc\_usable\_size
 \item
 memalign
 \item
-posix_memalign
+posix\_memalign
 \item
 pvalloc
@@ -61,42 +61,4 @@
 
 With the rise of concurrent applications, memory allocators should be able to fulfill dynamic memory requests from multiple threads in parallel without causing contention on shared resources. There needs to be a set of a standard benchmarks that can be used to evaluate an allocator's performance in different scenerios.
-
-\section{Background}
-
-\subsection{Memory Allocation}
-With dynamic allocation being an important feature of C, there are many standalone memory allocators that have been designed for different purposes. For this thesis, we chose 7 of the most popular and widely used memory allocators.
-
-\paragraph{dlmalloc}
-dlmalloc (FIX ME: cite allocator) is a thread-safe allocator that is single threaded and single heap. dlmalloc maintains free-lists of different sizes to store freed dynamic memory. (FIX ME: cite wasik)
-
-\paragraph{hoard}
-Hoard (FIX ME: cite allocator) is a thread-safe allocator that is multi-threaded and using a heap layer framework. It has per-thred heaps that have thread-local free-lists, and a gloabl shared heap. (FIX ME: cite wasik)
-
-\paragraph{jemalloc}
-jemalloc (FIX ME: cite allocator) is a thread-safe allocator that uses multiple arenas. Each thread is assigned an arena. Each arena has chunks that contain contagious memory regions of same size. An arena has multiple chunks that contain regions of multiple sizes.
-
-\paragraph{ptmalloc}
-ptmalloc (FIX ME: cite allocator) is a modification of dlmalloc. It is a thread-safe multi-threaded memory allocator that uses multiple heaps. ptmalloc heap has similar design to dlmalloc's heap.
-
-\paragraph{rpmalloc}
-rpmalloc (FIX ME: cite allocator) is a thread-safe allocator that is multi-threaded and uses per-thread heap. Each heap has multiple size-classes and each size-calss contains memory regions of the relevant size.
-
-\paragraph{tbb malloc}
-tbb malloc (FIX ME: cite allocator) is a thread-safe allocator that is multi-threaded and uses private heap for each thread. Each private-heap has multiple bins of different sizes. Each bin contains free regions of the same size.
-
-\paragraph{tc malloc}
-tcmalloc (FIX ME: cite allocator) is a thread-safe allocator. It uses per-thread cache to store free objects that prevents contention on shared resources in multi-threaded application. A central free-list is used to refill per-thread cache when it gets empty.
-
-\subsection{Benchmarks}
-There are multiple benchmarks that are built individually and evaluate different aspects of a memory allocator. But, there is not standard set of benchamrks that can be used to evaluate multiple aspects of memory allocators.
-
-\paragraph{threadtest}
-(FIX ME: cite benchmark and hoard) Each thread repeatedly allocates and then deallocates 100,000 objects. Runtime of the benchmark evaluates its efficiency.
-
-\paragraph{shbench}
-(FIX ME: cite benchmark and hoard) Each thread allocates and randomly frees a number of random-sized objects. It is a stress test that also uses runtime to determine efficiency of the allocator.
-
-\paragraph{larson}
-(FIX ME: cite benchmark and hoard) Larson simulates a server environment. Multiple threads are created where each thread allocator and free a number of objects within a size range. Some objects are passed from threads to the child threads to free. It caluculates memory operations per second as an indicator of memory allocator's performance.
 
 \section{Research Objectives}
Index: doc/theses/mubeen_zulfiqar_MMath/performance.tex
===================================================================
--- doc/theses/mubeen_zulfiqar_MMath/performance.tex	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ doc/theses/mubeen_zulfiqar_MMath/performance.tex	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -44,5 +44,6 @@
 tc               &             &  \\
 \end{tabularx}
-(FIX ME: complete table)
+
+%(FIX ME: complete table)
 
 \section{Experiment Environment}
Index: c/theses/mubeen_zulfiqar_MMath/thesis.tex
===================================================================
--- doc/theses/mubeen_zulfiqar_MMath/thesis.tex	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ 	(revision )
@@ -1,12 +1,0 @@
-\documentclass[letterpaper,12pt,titlepage,oneside,final]{book}
-
-\usepackage{amsmath,amssymb,amsfonts}
-
-\begin{document}
-
-\section{Benchmark Suite}
-
-\section{Memory Allocator}
-
-\end{document}
-
Index: doc/theses/mubeen_zulfiqar_MMath/uw-ethesis.bib
===================================================================
--- doc/theses/mubeen_zulfiqar_MMath/uw-ethesis.bib	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ doc/theses/mubeen_zulfiqar_MMath/uw-ethesis.bib	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -27,2 +27,9 @@
 	address =       "Reading, Massachusetts"
 }
+
+@article{wasik.thesis,
+    author        = "Ayelet Wasik",
+    title         = "Features of A Multi-Threaded Memory Alloator",
+    publisher	  = "University of Waterloo",
+    year          = "2008"
+}
Index: doc/theses/mubeen_zulfiqar_MMath/uw-ethesis.tex
===================================================================
--- doc/theses/mubeen_zulfiqar_MMath/uw-ethesis.tex	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ doc/theses/mubeen_zulfiqar_MMath/uw-ethesis.tex	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -84,4 +84,5 @@
 \usepackage{graphicx}
 \usepackage{comment} % Removes large sections of the document.
+\usepackage{tabularx}
 
 % Hyperlinks make it very easy to navigate an electronic document.
@@ -191,4 +192,6 @@
 % Tip: Putting each sentence on a new line is a way to simplify later editing.
 %----------------------------------------------------------------------
+\begin{sloppypar}
+
 \input{intro}
 \input{background}
@@ -197,4 +200,6 @@
 \input{performance}
 \input{conclusion}
+
+\end{sloppypar}
 
 %----------------------------------------------------------------------
Index: doc/theses/thierry_delisle_PhD/.gitignore
===================================================================
--- doc/theses/thierry_delisle_PhD/.gitignore	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ doc/theses/thierry_delisle_PhD/.gitignore	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -13,4 +13,8 @@
 comp_II/presentation.pdf
 
+seminars/build/
+seminars/img/*.fig.bak
+seminars/*.pdf
+
 thesis/build/
 thesis/fig/*.fig.bak
Index: doc/theses/thierry_delisle_PhD/thesis/Makefile
===================================================================
--- doc/theses/thierry_delisle_PhD/thesis/Makefile	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ doc/theses/thierry_delisle_PhD/thesis/Makefile	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -20,4 +20,6 @@
 	practice \
 	io \
+	eval_micro \
+	eval_macro \
 }}
 
@@ -35,4 +37,5 @@
 	pivot_ring \
 	system \
+	cycle \
 }
 
Index: doc/theses/thierry_delisle_PhD/thesis/fig/cycle.fig
===================================================================
--- doc/theses/thierry_delisle_PhD/thesis/fig/cycle.fig	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
+++ doc/theses/thierry_delisle_PhD/thesis/fig/cycle.fig	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -0,0 +1,34 @@
+#FIG 3.2  Produced by xfig version 3.2.7b
+Landscape
+Center
+Inches
+Letter
+100.00
+Single
+-2
+1200 2
+5 1 0 1 0 7 50 -1 -1 0.000 0 1 1 0 3144.643 2341.072 3525 2250 3375 2025 3150 1950
+	2 0 1.00 60.00 120.00
+5 1 0 1 0 7 50 -1 -1 0.000 0 1 1 0 1955.357 2341.072 1950 1950 1725 2025 1575 2250
+	2 0 1.00 60.00 120.00
+5 1 0 1 0 7 50 -1 -1 0.000 0 1 1 0 3637.500 3487.500 3750 3750 3900 3600 3900 3375
+	2 0 1.00 60.00 120.00
+5 1 0 1 0 7 50 -1 -1 0.000 0 1 1 0 2587.500 4087.500 2325 4500 2550 4575 2850 4500
+	2 0 1.00 60.00 120.00
+5 1 0 1 0 7 50 -1 -1 0.000 0 1 1 0 1612.500 3487.500 1200 3375 1200 3600 1350 3825
+	2 0 1.00 60.00 120.00
+1 3 0 1 0 7 50 -1 -1 0.000 1 0.0000 3675 2850 586 586 3675 2850 4125 3225
+1 3 0 1 0 7 50 -1 -1 0.000 1 0.0000 3300 4125 586 586 3300 4125 3750 4500
+1 3 0 1 0 7 50 -1 -1 0.000 1 0.0000 1875 4125 586 586 1875 4125 2325 4500
+1 3 0 1 0 7 50 -1 -1 0.000 1 0.0000 1425 2850 586 586 1425 2850 1875 3225
+1 3 0 1 0 7 50 -1 -1 0.000 1 0.0000 2550 1950 586 586 2550 1950 3000 2325
+4 0 0 50 -1 0 11 0.0000 2 135 720 1125 2925 Thread 2\001
+4 2 0 50 -1 0 11 0.0000 2 165 540 1650 1950 Unpark\001
+4 0 0 50 -1 0 11 0.0000 2 165 540 4050 3600 Unpark\001
+4 2 0 50 -1 0 11 0.0000 2 165 540 1125 3750 Unpark\001
+4 2 0 50 -1 0 11 0.0000 2 165 540 2850 4800 Unpark\001
+4 0 0 50 -1 0 11 0.0000 2 135 720 2250 2025 Thread 1\001
+4 0 0 50 -1 0 11 0.0000 2 135 720 3000 4200 Thread 4\001
+4 0 0 50 -1 0 11 0.0000 2 135 720 1575 4200 Thread 3\001
+4 0 0 50 -1 0 11 0.0000 2 165 540 3525 2025 Unpark\001
+4 0 0 50 -1 0 11 0.0000 2 135 720 3375 2925 Thread 5\001
Index: doc/theses/thierry_delisle_PhD/thesis/text/eval_macro.tex
===================================================================
--- doc/theses/thierry_delisle_PhD/thesis/text/eval_macro.tex	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
+++ doc/theses/thierry_delisle_PhD/thesis/text/eval_macro.tex	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -0,0 +1,15 @@
+\chapter{Macro-Benchmarks}\label{macrobench}
+
+\section{Static Web-Server}
+
+In Memory Plain Text
+
+Networked Plain Text
+
+Networked ZIPF
+
+\section{Memcached}
+
+In Memory
+
+Networked
Index: doc/theses/thierry_delisle_PhD/thesis/text/eval_micro.tex
===================================================================
--- doc/theses/thierry_delisle_PhD/thesis/text/eval_micro.tex	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
+++ doc/theses/thierry_delisle_PhD/thesis/text/eval_micro.tex	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -0,0 +1,50 @@
+\chapter{Micro-Benchmarks}\label{microbench}
+
+The first step of evaluation is always to test-out small controlled cases, to ensure that the basics are working properly.
+This sections presents four different experimental setup, evaluating some of the basic features of \CFA's scheduler.
+
+\section{Cycling latency}
+The most basic evaluation of any ready queue is to evaluate the latency needed to push and pop one element from the ready-queue.
+While these two operation also describe a \texttt{yield} operation, many systems use this as the most basic benchmark.
+However, yielding can be treated as a special case, since it also carries the information that the length of the ready queue will not change.
+Not all systems use this information, but those which do may appear to have better performance than they would for disconnected push/pop pairs.
+For this reason, I chose a different first benchmark, which I call the Cycle Benchmark.
+This benchmark arranges many threads into multiple rings of threads.
+Each ring is effectively a circular singly-linked list.
+At runtime, each thread unparks the next thread before parking itself.
+This corresponds to the desired pair of ready queue operations.
+Unparking the next thread requires pushing that thread onto the ready queue and the ensuing park will cause the runtime to pop a thread from the ready-queue.
+Figure~\ref{fig:cycle} shows a visual representation of this arrangement.
+
+The goal of this ring is that the underlying runtime cannot rely on the guarantee that the number of ready threads will stay constant over the duration of the experiment.
+In fact, the total number of threads waiting on the ready is expected to vary a little because of the race between the next thread unparking and the current thread parking.
+The size of the cycle is also decided based on this race: cycles that are too small may see the
+chain of unparks go full circle before the first thread can park.
+While this would not be a correctness problem, every runtime system must handle that race, it could lead to pushes and pops being optimized away.
+Since silently omitting ready-queue operations would throw off the measuring of these operations.
+Therefore the ring of threads must be big enough so the threads have the time to fully park before they are unparked.
+Note that this problem is only present on SMP machines and is significantly mitigated by the fact that there are multiple rings in the system.
+
+\begin{figure}
+	\centering
+	\input{cycle.pstex_t}
+	\caption[Cycle benchmark]{Cycle benchmark\smallskip\newline Each thread unparks the next thread in the cycle before parking itself.}
+	\label{fig:cycle}
+\end{figure}
+
+\todo{check term ``idle sleep handling''}
+To avoid this benchmark from being dominated by the idle sleep handling, the number of rings is kept at least as high as the number of processors available.
+Beyond this point, adding more rings serves to mitigate even more the idle sleep handling.
+This is to avoid the case where one of the worker threads runs out of work because of the variation on the number of ready threads mentionned above.
+
+The actual benchmark is more complicated to handle termination, but that simply requires using a binary semphore or a channel instead of raw \texttt{park}/\texttt{unpark} and carefully picking the order of the \texttt{P} and \texttt{V} with respect to the loop condition.
+
+\todo{mention where to get the code.}
+
+\section{Yield}
+For completion, I also include the yield benchmark.
+This benchmark is much simpler than the cycle tests, it simply creates many threads that call \texttt{yield}.
+
+\section{Locality}
+
+\section{Transfer}
Index: doc/theses/thierry_delisle_PhD/thesis/thesis.tex
===================================================================
--- doc/theses/thierry_delisle_PhD/thesis/thesis.tex	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ doc/theses/thierry_delisle_PhD/thesis/thesis.tex	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -1,6 +1,6 @@
 %======================================================================
-% University of Waterloo Thesis Template for LaTeX 
-% Last Updated November, 2020 
-% by Stephen Carr, IST Client Services, 
+% University of Waterloo Thesis Template for LaTeX
+% Last Updated November, 2020
+% by Stephen Carr, IST Client Services,
 % University of Waterloo, 200 University Ave. W., Waterloo, Ontario, Canada
 % FOR ASSISTANCE, please send mail to request@uwaterloo.ca
@@ -15,15 +15,15 @@
 % Some important notes on using this template and making it your own...
 
-% The University of Waterloo has required electronic thesis submission since October 2006. 
+% The University of Waterloo has required electronic thesis submission since October 2006.
 % See the uWaterloo thesis regulations at
 % https://uwaterloo.ca/graduate-studies/thesis.
 % This thesis template is geared towards generating a PDF version optimized for viewing on an electronic display, including hyperlinks within the PDF.
 
-% DON'T FORGET TO ADD YOUR OWN NAME AND TITLE in the "hyperref" package configuration below. 
+% DON'T FORGET TO ADD YOUR OWN NAME AND TITLE in the "hyperref" package configuration below.
 % THIS INFORMATION GETS EMBEDDED IN THE PDF FINAL PDF DOCUMENT.
 % You can view the information if you view properties of the PDF document.
 
-% Many faculties/departments also require one or more printed copies. 
-% This template attempts to satisfy both types of output. 
+% Many faculties/departments also require one or more printed copies.
+% This template attempts to satisfy both types of output.
 % See additional notes below.
 % It is based on the standard "book" document class which provides all necessary sectioning structures and allows multi-part theses.
@@ -32,15 +32,15 @@
 
 % For people who prefer to install their own LaTeX distributions on their own computers, and process the source files manually, the following notes provide the sequence of tasks:
- 
+
 % E.g. to process a thesis called "mythesis.tex" based on this template, run:
 
 % pdflatex mythesis	-- first pass of the pdflatex processor
 % bibtex mythesis	-- generates bibliography from .bib data file(s)
-% makeindex         -- should be run only if an index is used 
+% makeindex         -- should be run only if an index is used
 % pdflatex mythesis	-- fixes numbering in cross-references, bibliographic references, glossaries, index, etc.
 % pdflatex mythesis	-- it takes a couple of passes to completely process all cross-references
 
 % If you use the recommended LaTeX editor, Texmaker, you would open the mythesis.tex file, then click the PDFLaTeX button. Then run BibTeX (under the Tools menu).
-% Then click the PDFLaTeX button two more times. 
+% Then click the PDFLaTeX button two more times.
 % If you have an index as well,you'll need to run MakeIndex from the Tools menu as well, before running pdflatex
 % the last two times.
@@ -51,5 +51,5 @@
 % Tip: Photographs should be cropped and compressed so as not to be too large.
 
-% To create a PDF output that is optimized for double-sided printing: 
+% To create a PDF output that is optimized for double-sided printing:
 % 1) comment-out the \documentclass statement in the preamble below, and un-comment the second \documentclass line.
 % 2) change the value assigned below to the boolean variable "PrintVersion" from " false" to "true".
@@ -67,5 +67,5 @@
 % If you have to, it's easier to make changes to nomenclature once here than in a million places throughout your thesis!
 \newcommand{\package}[1]{\textbf{#1}} % package names in bold text
-\newcommand{\cmmd}[1]{\textbackslash\texttt{#1}} % command name in tt font 
+\newcommand{\cmmd}[1]{\textbackslash\texttt{#1}} % command name in tt font
 \newcommand{\href}[1]{#1} % does nothing, but defines the command so the print-optimized version will ignore \href tags (redefined by hyperref pkg).
 %\newcommand{\texorpdfstring}[2]{#1} % does nothing, but defines the command
@@ -235,7 +235,7 @@
 \part{Evaluation}
 \label{Evaluation}
-\chapter{Theoretical and Existance Proofs}
-\chapter{Micro-Benchmarks}
-\chapter{Larger-Scale applications}
+% \chapter{Theoretical and Existance Proofs}
+\input{text/eval_micro.tex}
+\input{text/eval_macro.tex}
 \part{Conclusion \& Annexes}
 
Index: doc/user/user.tex
===================================================================
--- doc/user/user.tex	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ doc/user/user.tex	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -11,6 +11,6 @@
 %% Created On       : Wed Apr  6 14:53:29 2016
 %% Last Modified By : Peter A. Buhr
-%% Last Modified On : Mon May 31 09:03:34 2021
-%% Update Count     : 5071
+%% Last Modified On : Sun Oct 10 12:45:00 2021
+%% Update Count     : 5095
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
@@ -4444,8 +4444,8 @@
 \CFA provides a fine-grained solution where a \Index{recursive lock} is acquired and released indirectly via a manipulator ©acquire© or instantiating an \Index{RAII} type specific for the kind of stream: ©osacquire©\index{ostream@©ostream©!osacquire@©osacquire©} for output streams and ©isacquire©\index{isacquire@©isacquire©}\index{istream@©istream©!isacquire@©isacquire©} for input streams.
 
-The common usage is manipulator ©acquire©\index{ostream@©ostream©!acquire@©acquire©} to lock a stream during a single cascaded I/O expression, with the manipulator appearing as the first item in a cascade list, \eg:
-\begin{cfa}
-$\emph{thread\(_1\)}$ : sout | ®acquire® | "abc " | "def ";   // manipulator
-$\emph{thread\(_2\)}$ : sout | ®acquire® | "uvw " | "xyz ";
+The common usage is the short form of the mutex statement\index{ostream@©ostream©!mutex@©mutex©} to lock a stream during a single cascaded I/O expression, \eg:
+\begin{cfa}
+$\emph{thread\(_1\)}$ : ®mutex()® sout | "abc " | "def ";
+$\emph{thread\(_2\)}$ : ®mutex()® sout | "uvw " | "xyz ";
 \end{cfa}
 Now, the order of the thread execution is still non-deterministic, but the output is constrained to two possible lines in either order.
@@ -4466,25 +4466,23 @@
 In summary, the stream lock is acquired by the ©acquire© manipulator and implicitly released at the end of the cascaded I/O expression ensuring all operations in the expression occur atomically.
 
-To lock a stream across multiple I/O operations, an object of type ©osacquire© or ©isacquire© is declared to implicitly acquire/release the stream lock providing mutual exclusion for the object's duration, \eg:
-\begin{cfa}
-{	// acquire sout for block duration
-	®osacquire® acq = { sout };				$\C{// named stream locker}$
+To lock a stream across multiple I/O operations, he long form of the mutex statement is used, \eg:
+\begin{cfa}
+®mutex( sout )® {
 	sout | 1;
-	sout | ®acquire® | 2 | 3;				$\C{// unnecessary, but ok to acquire and release again}$
+	®mutex() sout® | 2 | 3;				$\C{// unnecessary, but ok because of recursive lock}$
 	sout | 4;
-}	// implicitly release the lock when "acq" is deallocated
-\end{cfa}
-Note, the unnecessary ©acquire© manipulator works because the recursive stream-lock can be acquired/released multiple times by the owner thread.
+} // implicitly release sout lock
+\end{cfa}
+Note, the unnecessary ©mutex© in the middle of the mutex statement, works because the recursive stream-lock can be acquired/released multiple times by the owner thread.
 Hence, calls to functions that also acquire a stream lock for their output do not result in \Index{deadlock}.
 
 The previous values written by threads 1 and 2 can be read in concurrently:
 \begin{cfa}
-{	// acquire sin lock for block duration
-	®isacquire acq = { sin };®				$\C{// named stream locker}$
+®mutex( sin )® {
 	int x, y, z, w;
 	sin | x;
-	sin | ®acquire® | y | z;				$\C{// unnecessary, but ok to acquire and release again}$
+	®mutex() sin® | y | z;				$\C{// unnecessary, but ok because of recursive lock}$
 	sin | w;
-}	// implicitly release the lock when "acq" is deallocated
+} // implicitly release sin lock
 \end{cfa}
 Again, the order of the reading threads is non-deterministic.
@@ -4493,5 +4491,5 @@
 \Textbf{WARNING:} The general problem of \Index{nested locking} can occur if routines are called in an I/O sequence that block, \eg:
 \begin{cfa}
-sout | ®acquire® | "data:" | rtn( mon );	$\C{// mutex call on monitor}$
+®mutex() sout® | "data:" | rtn( mon );	$\C{// mutex call on monitor}$
 \end{cfa}
 If the thread executing the I/O expression blocks in the monitor with the ©sout© lock, other threads writing to ©sout© also block until the thread holding the lock is unblocked and releases it.
@@ -4500,5 +4498,5 @@
 \begin{cfa}
 int ®data® = rtn( mon );
-sout | acquire | "data:" | ®data®;
+mutex() sout | "data:" | ®data®;
 \end{cfa}
 
@@ -4506,6 +4504,22 @@
 \section{String Stream}
 
-All the stream formatting capabilities are available to format text to/from a C string rather than to a stream file.
-\VRef[Figure]{f:StringStreamProcessing} shows writing (output) and reading (input) from a C string.
+The stream types ©ostrstream© and ©istrstream© provide all the stream formatting capabilities to/from a C string rather than a stream file.
+\VRef[Figure]{f:StringStreamProcessing} shows writing (output) to and reading (input) from a C string.
+The only string stream operations different from a file stream are:
+\begin{itemize}[topsep=4pt,itemsep=2pt,parsep=0pt]
+\item
+constructors to create a stream that writes to a write buffer (©ostrstream©) of ©size©, or reads from a read buffer (©istrstream©) containing a C string terminated with ©'\0'©.
+\begin{cfa}
+void ?{}( ostrstream &, char buf[], size_t size );
+void ?{}( istrstream & is, char buf[] );
+\end{cfa}
+\item
+\Indexc{write} (©ostrstream© only) writes all the buffered characters to the specified stream (©stdout© default).
+\begin{cfa}
+ostrstream & write( ostrstream & os, FILE * stream = stdout );
+\end{cfa}
+There is no ©read© for ©istrstream©.
+\end{itemize}
+
 \begin{figure}
 \begin{cfa}
@@ -4520,46 +4534,24 @@
 	double x = 12345678.9, y = 98765.4321e-11;
 
-	osstr | i | hex(j) | wd(10, k) | sci(x) | unit(eng(y)); $\C{// same lines of output}$
-	write( osstr );
-	printf( "%s", buf );
-	sout | i | hex(j) | wd(10, k) | sci(x) | unit(eng(y));
-
-	char buf2[] = "12 14 15 3.5 7e4"; $\C{// input buffer}$
+	osstr | i | hex(j) | wd(10, k) | sci(x) | unit(eng(y)) | "abc";
+	write( osstr ); $\C{// write string to stdout}$
+	printf( "%s", buf ); $\C{// same lines of output}$
+	sout | i | hex(j) | wd(10, k) | sci(x) | unit(eng(y)) | "abc";
+
+	char buf2[] = "12 14 15 3.5 7e4 abc"; $\C{// input buffer}$
 	®istrstream isstr = { buf2 };®
-	isstr | i | j | k | x | y;
-	sout | i | j | k | x | y;
-}
+	char s[10];
+	isstr | i | j | k | x | y | s;
+	sout  | i | j | k | x | y | s;
+}
+
+3 0x5          7 1.234568e+07 987.654n abc
+3 0x5          7 1.234568e+07 987.654n abc
+3 0x5          7 1.234568e+07 987.654n abc
+12 14 15 3.5 70000. abc
 \end{cfa}
 \caption{String Stream Processing}
 \label{f:StringStreamProcessing}
 \end{figure}
-
-\VRef[Figure]{f:StringStreamFunctions} shows the string stream operations.
-\begin{itemize}[topsep=4pt,itemsep=2pt,parsep=0pt]
-\item
-\Indexc{write} (©ostrstream© only) writes all the buffered characters to the specified stream (©stdout© default).
-\end{itemize}
-The constructor functions:
-\begin{itemize}[topsep=4pt,itemsep=2pt,parsep=0pt]
-\item
-create a bound stream to a write buffer (©ostrstream©) of ©size© or a read buffer (©istrstream©) containing a C string terminated with ©'\0'©.
-\end{itemize}
-
-\begin{figure}
-\begin{cfa}
-// *********************************** ostrstream ***********************************
-
-ostrstream & write( ostrstream & os, FILE * stream = stdout );
-
-void ?{}( ostrstream &, char buf[], size_t size );
-
-// *********************************** istrstream ***********************************
-
-void ?{}( istrstream & is, char buf[] );
-\end{cfa}
-\caption{String Stream Functions}
-\label{f:StringStreamFunctions}
-\end{figure}
-
 
 \begin{comment}
Index: example/cpu.cfa
===================================================================
--- example/cpu.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
+++ example/cpu.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -0,0 +1,10 @@
+#include <fstream.hfa>
+#include <device/cpu.hfa>
+
+int main() {
+	for(i; cpu_info.hthrd_count) {
+		cpu_info.llc_map[i];
+		const cpu_map_entry_t & e = cpu_info.llc_map[i];
+		sout | e.self | e.start | e.count;
+	}
+}
Index: example/maybe-await.rs
===================================================================
--- example/maybe-await.rs	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
+++ example/maybe-await.rs	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -0,0 +1,77 @@
+use futures::executor::block_on;
+use futures::future::Future;
+use std::pin::Pin;
+use std::sync::{Arc,Mutex};
+use std::task::{Context, Poll, Waker};
+
+
+struct FutureState {
+	set: bool,
+	waker: Option<Waker>,
+}
+
+#[derive(Clone)]
+struct MyFuture {
+	state: Arc<Mutex<FutureState>>
+}
+
+impl MyFuture {
+	fn new() -> MyFuture {
+		MyFuture{
+			state: Arc::new(Mutex::new(FutureState{
+				set: false,
+				waker: None
+			}))
+		}
+	}
+
+	fn fulfill(&self) {
+		let mut state = self.state.lock().unwrap();
+		state.set = true;
+		if let Some(waker) = state.waker.take() {
+			waker.wake()
+		}
+	}
+}
+
+impl Future for MyFuture {
+	type Output = ();
+	fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
+		println!("Polling Future");
+		let mut state = self.state.lock().unwrap();
+		if state.set {
+			println!("Ready");
+			Poll::Ready(())
+		} else {
+			println!("Pending");
+			state.waker = Some(cx.waker().clone());
+			Poll::Pending
+		}
+	}
+}
+
+async fn hello_world(f1: MyFuture, f2: MyFuture) {
+	println!("Enter");
+	f1.await;
+	println!("Between");
+	f2.await;
+	println!("Done");
+}
+
+fn main() {
+	block_on(async {
+		let f1 = MyFuture::new();
+		let f2 = MyFuture::new();
+		let f3 = MyFuture::new();
+		let future = hello_world(f1.clone(), f2.clone());
+
+		println!("Before first fulfill");
+		f1.fulfill();
+		println!("Before second fulfill");
+		f2.fulfill();
+		println!("Before first await");
+		future.await;
+		println!("Before second await");
+		// future.await;
+	});
+}
Index: example/unnecessary-arc.rs
===================================================================
--- example/unnecessary-arc.rs	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
+++ example/unnecessary-arc.rs	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -0,0 +1,74 @@
+use std::thread;
+use std::time::Duration;
+
+// This is the version I wished worked.
+// If join was't ingored it would be safe
+fn better() {
+	// let durr = Duration::from_millis(1);
+	{
+		let thrd = thread::spawn(move || {
+			for i in 1..10 {
+				println!("hi number {} from the spawned thread!", i);
+				thread::sleep(durr);
+			}
+		});
+
+		for i in 1..5 {
+			println!("hi number {} from the main thread!", i);
+			thread::sleep(durr);
+		}
+
+		thrd.join().unwrap();
+	}
+}
+
+use std::sync::Arc;
+
+// This uses arc, which should not be needed
+// But it fails to figure out where to clone so it doesn't compile
+fn best() {
+	let durr = Arc::new(Duration::from_millis(1));
+	{
+		let thrd = thread::spawn(|| {
+			for i in 1..10 {
+				println!("hi number {} from the spawned thread!", i);
+				thread::sleep(*durr);
+			}
+		});
+
+		for i in 1..5 {
+			println!("hi number {} from the main thread!", i);
+			thread::sleep(*durr);
+		}
+
+		thrd.join().unwrap();
+	}
+}
+
+// This is what is actually required
+// Note that the clone is explicit
+fn real() {
+	let durr = Arc::new(Duration::from_millis(1));
+	{
+		let durr2 = durr.clone();
+		let thrd = thread::spawn(move || {
+			for i in 1..10 {
+				println!("hi number {} from the spawned thread!", i);
+				thread::sleep(*durr2);
+			}
+		});
+
+		for i in 1..5 {
+			println!("hi number {} from the main thread!", i);
+			thread::sleep(*durr);
+		}
+
+		thrd.join().unwrap();
+	}
+}
+
+fn main() {
+	best();
+	better();
+	real();
+}
Index: libcfa/prelude/bootloader.cf
===================================================================
--- libcfa/prelude/bootloader.cf	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ libcfa/prelude/bootloader.cf	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -3,5 +3,5 @@
 char ** cfa_args_argv;
 char ** cfa_args_envp;
-int cfa_main_returned = 0;
+__attribute__((weak)) extern int cfa_main_returned;
 
 int main(int argc, char* argv[], char* envp[]) {
@@ -10,5 +10,5 @@
 	cfa_args_envp = envp;
 	int ret = invoke_main(argc, argv, envp);
-	cfa_main_returned = 1;
+	if(&cfa_main_returned) cfa_main_returned = 1;
 	return ret;
 }
Index: libcfa/prelude/builtins.c
===================================================================
--- libcfa/prelude/builtins.c	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ libcfa/prelude/builtins.c	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -10,6 +10,6 @@
 // Created On       : Fri Jul 21 16:21:03 2017
 // Last Modified By : Peter A. Buhr
-// Last Modified On : Wed Jul 21 13:31:34 2021
-// Update Count     : 129
+// Last Modified On : Sat Aug 14 08:45:54 2021
+// Update Count     : 133
 //
 
@@ -107,4 +107,8 @@
 #endif // __SIZEOF_INT128__
 
+// for-control index constraints
+// forall( T | { void ?{}( T &, zero_t ); void ?{}( T &, one_t ); T ?+=?( T &, T ); T ?-=?( T &, T ); int ?<?( T, T ); } )
+// static inline T __for_control_index_constraints__( T t ) { return t; }
+
 // exponentiation operator implementation
 
Index: libcfa/src/Makefile.am
===================================================================
--- libcfa/src/Makefile.am	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ libcfa/src/Makefile.am	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -48,4 +48,5 @@
 	math.hfa \
 	time_t.hfa \
+	bits/algorithm.hfa \
 	bits/align.hfa \
 	bits/containers.hfa \
@@ -77,4 +78,5 @@
 	memory.hfa \
 	parseargs.hfa \
+	parseconfig.hfa \
 	rational.hfa \
 	stdlib.hfa \
@@ -85,4 +87,6 @@
 	containers/pair.hfa \
 	containers/result.hfa \
+	containers/string.hfa \
+	containers/string_res.hfa \
 	containers/vector.hfa \
 	device/cpu.hfa
@@ -90,5 +94,4 @@
 libsrc = ${inst_headers_src} ${inst_headers_src:.hfa=.cfa} \
 	assert.cfa \
-	bits/algorithm.hfa \
 	bits/debug.cfa \
 	exception.c \
@@ -106,5 +109,6 @@
 	concurrency/invoke.h \
 	concurrency/future.hfa \
-	concurrency/kernel/fwd.hfa
+	concurrency/kernel/fwd.hfa \
+	concurrency/mutex_stmt.hfa
 
 inst_thread_headers_src = \
@@ -192,4 +196,7 @@
 	$(CFACOMPILE) -quiet -XCFA,-l ${<} -c -o ${@}
 
+concurrency/io/call.cfa: $(srcdir)/concurrency/io/call.cfa.in
+	${AM_V_GEN}python3 $< > $@
+
 #----------------------------------------------------------------------------------------------------------------
 libcfa_la_SOURCES = ${libsrc}
Index: libcfa/src/concurrency/clib/cfathread.cfa
===================================================================
--- libcfa/src/concurrency/clib/cfathread.cfa	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ libcfa/src/concurrency/clib/cfathread.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -14,4 +14,6 @@
 //
 
+// #define EPOLL_FOR_SOCKETS
+
 #include "fstream.hfa"
 #include "locks.hfa"
@@ -23,13 +25,202 @@
 #include "cfathread.h"
 
+extern "C" {
+		#include <string.h>
+		#include <errno.h>
+}
+
 extern void ?{}(processor &, const char[], cluster &, thread$ *);
 extern "C" {
       extern void __cfactx_invoke_thread(void (*main)(void *), void * this);
+	extern int accept4(int sockfd, struct sockaddr *addr, socklen_t *addrlen, int flags);
 }
 
 extern Time __kernel_get_time();
+extern unsigned register_proc_id( void );
 
 //================================================================================
-// Thread run y the C Interface
+// Epoll support for sockets
+
+#if defined(EPOLL_FOR_SOCKETS)
+	extern "C" {
+		#include <sys/epoll.h>
+		#include <sys/resource.h>
+	}
+
+	static pthread_t master_poller;
+	static int master_epollfd = 0;
+	static size_t poller_cnt = 0;
+	static int * poller_fds = 0p;
+	static struct leaf_poller * pollers = 0p;
+
+	struct __attribute__((aligned)) fd_info_t {
+		int pollid;
+		size_t rearms;
+	};
+	rlim_t fd_limit = 0;
+	static fd_info_t * volatile * fd_map = 0p;
+
+	void * master_epoll( __attribute__((unused)) void * args ) {
+		unsigned id = register_proc_id();
+
+		enum { MAX_EVENTS = 5 };
+		struct epoll_event events[MAX_EVENTS];
+		for() {
+			int ret = epoll_wait(master_epollfd, events, MAX_EVENTS, -1);
+			if ( ret < 0 ) {
+				abort | "Master epoll error: " | strerror(errno);
+			}
+
+			for(i; ret) {
+				thread$ * thrd = (thread$ *)events[i].data.u64;
+				unpark( thrd );
+			}
+		}
+
+		return 0p;
+	}
+
+	static inline int epoll_rearm(int epollfd, int fd, uint32_t event) {
+		struct epoll_event eevent;
+		eevent.events = event | EPOLLET | EPOLLONESHOT;
+		eevent.data.u64 = (uint64_t)active_thread();
+
+		if(0 != epoll_ctl(epollfd, EPOLL_CTL_MOD, fd, &eevent))
+		{
+			if(errno == ENOENT) return -1;
+			abort | acquire | "epoll" | epollfd | "ctl rearm" | fd | "error: " | errno | strerror(errno);
+		}
+
+		park();
+		return 0;
+	}
+
+	thread leaf_poller {
+		int epollfd;
+	};
+
+	void ?{}(leaf_poller & this, int fd) { this.epollfd = fd; }
+
+	void main(leaf_poller & this) {
+		enum { MAX_EVENTS = 1024 };
+		struct epoll_event events[MAX_EVENTS];
+		const int max_retries = 5;
+		int retries = max_retries;
+
+		struct epoll_event event;
+		event.events = EPOLLIN | EPOLLET | EPOLLONESHOT;
+		event.data.u64 = (uint64_t)&(thread&)this;
+
+		if(0 != epoll_ctl(master_epollfd, EPOLL_CTL_ADD, this.epollfd, &event))
+		{
+			abort | "master epoll ctl add leaf: " | errno | strerror(errno);
+		}
+
+		park();
+
+		for() {
+			yield();
+			int ret = epoll_wait(this.epollfd, events, MAX_EVENTS, 0);
+			if ( ret < 0 ) {
+				abort | "Leaf epoll error: " | errno | strerror(errno);
+			}
+
+			if(ret) {
+				for(i; ret) {
+					thread$ * thrd = (thread$ *)events[i].data.u64;
+					unpark( thrd, UNPARK_REMOTE );
+				}
+			}
+			else if(0 >= --retries) {
+				epoll_rearm(master_epollfd, this.epollfd, EPOLLIN);
+			}
+		}
+	}
+
+	void setup_epoll( void ) __attribute__(( constructor ));
+	void setup_epoll( void ) {
+		if(master_epollfd) abort | "Master epoll already setup";
+
+		master_epollfd = epoll_create1(0);
+		if(master_epollfd == -1) {
+			abort | "failed to create master epoll: " | errno | strerror(errno);
+		}
+
+		struct rlimit rlim;
+		if(int ret = getrlimit(RLIMIT_NOFILE, &rlim); 0 != ret) {
+			abort | "failed to get nofile limit: " | errno | strerror(errno);
+		}
+
+		fd_limit = rlim.rlim_cur;
+		fd_map = alloc(fd_limit);
+		for(i;fd_limit) {
+			fd_map[i] = 0p;
+		}
+
+		poller_cnt = 2;
+		poller_fds = alloc(poller_cnt);
+		pollers    = alloc(poller_cnt);
+		for(i; poller_cnt) {
+			poller_fds[i] = epoll_create1(0);
+			if(poller_fds[i] == -1) {
+				abort | "failed to create leaf epoll [" | i | "]: " | errno | strerror(errno);
+			}
+
+			(pollers[i]){ poller_fds[i] };
+		}
+
+		pthread_attr_t attr;
+		if (int ret = pthread_attr_init(&attr); 0 != ret) {
+			abort | "failed to create master epoll thread attr: " | ret | strerror(ret);
+		}
+
+		if (int ret = pthread_create(&master_poller, &attr, master_epoll, 0p); 0 != ret) {
+			abort | "failed to create master epoll thread: " | ret | strerror(ret);
+		}
+	}
+
+	static inline int epoll_wait(int fd, uint32_t event) {
+		if(fd_map[fd] >= 1p) {
+			fd_map[fd]->rearms++;
+			epoll_rearm(poller_fds[fd_map[fd]->pollid], fd, event);
+			return 0;
+		}
+
+		for() {
+			fd_info_t * expected = 0p;
+			fd_info_t * sentinel = 1p;
+			if(__atomic_compare_exchange_n( &(fd_map[fd]), &expected, sentinel, true, __ATOMIC_SEQ_CST, __ATOMIC_RELAXED)) {
+				struct epoll_event eevent;
+				eevent.events = event | EPOLLET | EPOLLONESHOT;
+				eevent.data.u64 = (uint64_t)active_thread();
+
+				int id = thread_rand() % poller_cnt;
+				if(0 != epoll_ctl(poller_fds[id], EPOLL_CTL_ADD, fd, &eevent))
+				{
+					abort | "epoll ctl add" | poller_fds[id] | fd | fd_map[fd] | expected | "error: " | errno | strerror(errno);
+				}
+
+				fd_info_t * ninfo = alloc();
+				ninfo->pollid = id;
+				ninfo->rearms = 0;
+				__atomic_store_n( &fd_map[fd], ninfo, __ATOMIC_SEQ_CST);
+
+				park();
+				return 0;
+			}
+
+			if(expected >= 0) {
+				fd_map[fd]->rearms++;
+				epoll_rearm(poller_fds[fd_map[fd]->pollid], fd, event);
+				return 0;
+			}
+
+			Pause();
+		}
+	}
+#endif
+
+//================================================================================
+// Thread run by the C Interface
 
 struct cfathread_object {
@@ -245,5 +436,5 @@
 	// Mutex
 	struct cfathread_mutex {
-		fast_lock impl;
+		linear_backoff_then_block_lock impl;
 	};
 	int cfathread_mutex_init(cfathread_mutex_t *restrict mut, const cfathread_mutexattr_t *restrict) __attribute__((nonnull (1))) { *mut = new(); return 0; }
@@ -260,5 +451,5 @@
 	// Condition
 	struct cfathread_condition {
-		condition_variable(fast_lock) impl;
+		condition_variable(linear_backoff_then_block_lock) impl;
 	};
 	int cfathread_cond_init(cfathread_cond_t *restrict cond, const cfathread_condattr_t *restrict) __attribute__((nonnull (1))) { *cond = new(); return 0; }
@@ -288,5 +479,9 @@
 	// IO operations
 	int cfathread_socket(int domain, int type, int protocol) {
-		return socket(domain, type, protocol);
+		return socket(domain, type
+		#if defined(EPOLL_FOR_SOCKETS)
+			| SOCK_NONBLOCK
+		#endif
+		, protocol);
 	}
 	int cfathread_bind(int socket, const struct sockaddr *address, socklen_t address_len) {
@@ -299,9 +494,34 @@
 
 	int cfathread_accept(int socket, struct sockaddr *restrict address, socklen_t *restrict address_len) {
-		return cfa_accept4(socket, address, address_len, 0, CFA_IO_LAZY);
+		#if defined(EPOLL_FOR_SOCKETS)
+			int ret;
+			for() {
+				yield();
+				ret = accept4(socket, address, address_len, SOCK_NONBLOCK);
+				if(ret >= 0) break;
+				if(errno != EAGAIN && errno != EWOULDBLOCK) break;
+
+				epoll_wait(socket, EPOLLIN);
+			}
+			return ret;
+		#else
+			return cfa_accept4(socket, address, address_len, 0, CFA_IO_LAZY);
+		#endif
 	}
 
 	int cfathread_connect(int socket, const struct sockaddr *address, socklen_t address_len) {
-		return cfa_connect(socket, address, address_len, CFA_IO_LAZY);
+		#if defined(EPOLL_FOR_SOCKETS)
+			int ret;
+			for() {
+				ret = connect(socket, address, address_len);
+				if(ret >= 0) break;
+				if(errno != EAGAIN && errno != EWOULDBLOCK) break;
+
+				epoll_wait(socket, EPOLLIN);
+			}
+			return ret;
+		#else
+			return cfa_connect(socket, address, address_len, CFA_IO_LAZY);
+		#endif
 	}
 
@@ -315,10 +535,38 @@
 
 	ssize_t cfathread_sendmsg(int socket, const struct msghdr *message, int flags) {
-		return cfa_sendmsg(socket, message, flags, CFA_IO_LAZY);
+		#if defined(EPOLL_FOR_SOCKETS)
+			ssize_t ret;
+			__STATS__( false, io.ops.sockwrite++; )
+			for() {
+				ret = sendmsg(socket, message, flags);
+				if(ret >= 0) break;
+				if(errno != EAGAIN && errno != EWOULDBLOCK) break;
+
+				__STATS__( false, io.ops.epllwrite++; )
+				epoll_wait(socket, EPOLLOUT);
+			}
+		#else
+			ssize_t ret = cfa_sendmsg(socket, message, flags, CFA_IO_LAZY);
+		#endif
+		return ret;
 	}
 
 	ssize_t cfathread_write(int fildes, const void *buf, size_t nbyte) {
 		// Use send rather then write for socket since it's faster
-		return cfa_send(fildes, buf, nbyte, 0, CFA_IO_LAZY);
+		#if defined(EPOLL_FOR_SOCKETS)
+			ssize_t ret;
+			// __STATS__( false, io.ops.sockwrite++; )
+			for() {
+				ret = send(fildes, buf, nbyte, 0);
+				if(ret >= 0) break;
+				if(errno != EAGAIN && errno != EWOULDBLOCK) break;
+
+				// __STATS__( false, io.ops.epllwrite++; )
+				epoll_wait(fildes, EPOLLOUT);
+			}
+		#else
+			ssize_t ret = cfa_send(fildes, buf, nbyte, 0, CFA_IO_LAZY);
+		#endif
+		return ret;
 	}
 
@@ -336,5 +584,17 @@
 		msg.msg_controllen = 0;
 
-		ssize_t ret = cfa_recvmsg(socket, &msg, flags, CFA_IO_LAZY);
+		#if defined(EPOLL_FOR_SOCKETS)
+			ssize_t ret;
+			yield();
+			for() {
+				ret = recvmsg(socket, &msg, flags);
+				if(ret >= 0) break;
+				if(errno != EAGAIN && errno != EWOULDBLOCK) break;
+
+				epoll_wait(socket, EPOLLIN);
+			}
+		#else
+			ssize_t ret = cfa_recvmsg(socket, &msg, flags, CFA_IO_LAZY);
+		#endif
 
 		if(address_len) *address_len = msg.msg_namelen;
@@ -344,6 +604,21 @@
 	ssize_t cfathread_read(int fildes, void *buf, size_t nbyte) {
 		// Use recv rather then read for socket since it's faster
-		return cfa_recv(fildes, buf, nbyte, 0, CFA_IO_LAZY);
-	}
-
-}
+		#if defined(EPOLL_FOR_SOCKETS)
+			ssize_t ret;
+			__STATS__( false, io.ops.sockread++; )
+			yield();
+			for() {
+				ret = recv(fildes, buf, nbyte, 0);
+				if(ret >= 0) break;
+				if(errno != EAGAIN && errno != EWOULDBLOCK) break;
+
+				__STATS__( false, io.ops.epllread++; )
+				epoll_wait(fildes, EPOLLIN);
+			}
+		#else
+			ssize_t ret = cfa_recv(fildes, buf, nbyte, 0, CFA_IO_LAZY);
+		#endif
+		return ret;
+	}
+
+}
Index: libcfa/src/concurrency/invoke.h
===================================================================
--- libcfa/src/concurrency/invoke.h	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ libcfa/src/concurrency/invoke.h	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -170,6 +170,4 @@
 		bool corctx_flag;
 
-		int last_cpu;
-
 		//SKULLDUGGERY errno is not save in the thread data structure because returnToKernel appears to be the only function to require saving and restoring it
 
@@ -177,5 +175,5 @@
 		struct cluster * curr_cluster;
 
-		// preferred ready-queue
+		// preferred ready-queue or CPU
 		unsigned preferred;
 
Index: libcfa/src/concurrency/io.cfa
===================================================================
--- libcfa/src/concurrency/io.cfa	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ libcfa/src/concurrency/io.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -90,5 +90,5 @@
 	static inline unsigned __flush( struct $io_context & );
 	static inline __u32 __release_sqes( struct $io_context & );
-	extern void __kernel_unpark( thread$ * thrd );
+	extern void __kernel_unpark( thread$ * thrd, unpark_hint );
 
 	bool __cfa_io_drain( processor * proc ) {
@@ -118,5 +118,5 @@
 			__cfadbg_print_safe( io, "Kernel I/O : Syscall completed : cqe %p, result %d for %p\n", &cqe, cqe.res, future );
 
-			__kernel_unpark( fulfil( *future, cqe.res, false ) );
+			__kernel_unpark( fulfil( *future, cqe.res, false ), UNPARK_LOCAL );
 		}
 
@@ -183,7 +183,5 @@
 		ctx.proc->io.pending = false;
 
-		ready_schedule_lock();
 		__cfa_io_drain( proc );
-		ready_schedule_unlock();
 		// for(i; 2) {
 		// 	unsigned idx = proc->rdq.id + i;
@@ -311,10 +309,12 @@
 		// Make the sqes visible to the submitter
 		__atomic_store_n(sq.kring.tail, tail + have, __ATOMIC_RELEASE);
-		sq.to_submit++;
+		sq.to_submit += have;
 
 		ctx->proc->io.pending = true;
 		ctx->proc->io.dirty   = true;
 		if(sq.to_submit > 30 || !lazy) {
+			ready_schedule_lock();
 			__cfa_io_flush( ctx->proc );
+			ready_schedule_unlock();
 		}
 	}
Index: libcfa/src/concurrency/io/types.hfa
===================================================================
--- libcfa/src/concurrency/io/types.hfa	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ libcfa/src/concurrency/io/types.hfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -188,3 +188,7 @@
 		return wait(this.self);
 	}
+
+	void reset( io_future_t & this ) {
+		return reset(this.self);
+	}
 }
Index: libcfa/src/concurrency/kernel.cfa
===================================================================
--- libcfa/src/concurrency/kernel.cfa	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ libcfa/src/concurrency/kernel.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -22,4 +22,5 @@
 #include <errno.h>
 #include <stdio.h>
+#include <string.h>
 #include <signal.h>
 #include <unistd.h>
@@ -31,4 +32,6 @@
 #include "kernel_private.hfa"
 #include "preemption.hfa"
+#include "strstream.hfa"
+#include "device/cpu.hfa"
 
 //Private includes
@@ -193,5 +196,8 @@
 
 			if( !readyThread ) {
+				ready_schedule_lock();
 				__cfa_io_flush( this );
+				ready_schedule_unlock();
+
 				readyThread = __next_thread_slow( this->cltr );
 			}
@@ -231,8 +237,21 @@
 				__cfadbg_print_safe(runtime_core, "Kernel : core %p waiting on eventfd %d\n", this, this->idle);
 
-				__disable_interrupts_hard();
-				eventfd_t val;
-				eventfd_read( this->idle, &val );
-				__enable_interrupts_hard();
+				{
+					eventfd_t val;
+					ssize_t ret = read( this->idle, &val, sizeof(val) );
+					if(ret < 0) {
+						switch((int)errno) {
+						case EAGAIN:
+						#if EAGAIN != EWOULDBLOCK
+							case EWOULDBLOCK:
+						#endif
+						case EINTR:
+							// No need to do anything special here, just assume it's a legitimate wake-up
+							break;
+						default:
+							abort( "KERNEL : internal error, read failure on idle eventfd, error(%d) %s.", (int)errno, strerror( (int)errno ) );
+						}
+					}
+				}
 
 				#if !defined(__CFA_NO_STATISTICS__)
@@ -261,5 +280,7 @@
 
 			if(this->io.pending && !this->io.dirty) {
+				ready_schedule_lock();
 				__cfa_io_flush( this );
+				ready_schedule_unlock();
 			}
 
@@ -301,5 +322,8 @@
 
 				// Don't block if we are done
-				if( __atomic_load_n(&this->do_terminate, __ATOMIC_SEQ_CST) ) break MAIN_LOOP;
+				if( __atomic_load_n(&this->do_terminate, __ATOMIC_SEQ_CST) ) {
+					ready_schedule_unlock();
+					break MAIN_LOOP;
+				}
 
 				__STATS( __tls_stats()->ready.sleep.halts++; )
@@ -325,11 +349,24 @@
 				}
 
-					__STATS( if(this->print_halts) __cfaabi_bits_print_safe( STDOUT_FILENO, "PH:%d - %lld 0\n", this->unique_id, rdtscl()); )
+				__STATS( if(this->print_halts) __cfaabi_bits_print_safe( STDOUT_FILENO, "PH:%d - %lld 0\n", this->unique_id, rdtscl()); )
 				__cfadbg_print_safe(runtime_core, "Kernel : core %p waiting on eventfd %d\n", this, this->idle);
 
-				// __disable_interrupts_hard();
-				eventfd_t val;
-				eventfd_read( this->idle, &val );
-				// __enable_interrupts_hard();
+				{
+					eventfd_t val;
+					ssize_t ret = read( this->idle, &val, sizeof(val) );
+					if(ret < 0) {
+						switch((int)errno) {
+						case EAGAIN:
+						#if EAGAIN != EWOULDBLOCK
+							case EWOULDBLOCK:
+						#endif
+						case EINTR:
+							// No need to do anything special here, just assume it's a legitimate wake-up
+							break;
+						default:
+							abort( "KERNEL : internal error, read failure on idle eventfd, error(%d) %s.", (int)errno, strerror( (int)errno ) );
+						}
+					}
+				}
 
 					__STATS( if(this->print_halts) __cfaabi_bits_print_safe( STDOUT_FILENO, "PH:%d - %lld 1\n", this->unique_id, rdtscl()); )
@@ -393,14 +430,4 @@
 	/* paranoid */ verifyf( thrd_dst->link.next == 0p, "Expected null got %p", thrd_dst->link.next );
 	__builtin_prefetch( thrd_dst->context.SP );
-
-	int curr = __kernel_getcpu();
-	if(thrd_dst->last_cpu != curr) {
-		int64_t l = thrd_dst->last_cpu;
-		int64_t c = curr;
-		int64_t v = (l << 32) | c;
-		__push_stat( __tls_stats(), v, false, "Processor", this );
-	}
-
-	thrd_dst->last_cpu = curr;
 
 	__cfadbg_print_safe(runtime_core, "Kernel : core %p running thread %p (%s)\n", this, thrd_dst, thrd_dst->self_cor.name);
@@ -457,5 +484,5 @@
 		if(unlikely(thrd_dst->preempted != __NO_PREEMPTION)) {
 			// The thread was preempted, reschedule it and reset the flag
-			schedule_thread$( thrd_dst );
+			schedule_thread$( thrd_dst, UNPARK_LOCAL );
 			break RUNNING;
 		}
@@ -541,5 +568,5 @@
 // Scheduler routines
 // KERNEL ONLY
-static void __schedule_thread( thread$ * thrd ) {
+static void __schedule_thread( thread$ * thrd, unpark_hint hint ) {
 	/* paranoid */ verify( ! __preemption_enabled() );
 	/* paranoid */ verify( ready_schedule_islocked());
@@ -561,8 +588,8 @@
 	// Dereference the thread now because once we push it, there is not guaranteed it's still valid.
 	struct cluster * cl = thrd->curr_cluster;
-	__STATS(bool outside = thrd->last_proc && thrd->last_proc != kernelTLS().this_processor; )
+	__STATS(bool outside = hint == UNPARK_LOCAL && thrd->last_proc && thrd->last_proc != kernelTLS().this_processor; )
 
 	// push the thread to the cluster ready-queue
-	push( cl, thrd, local );
+	push( cl, thrd, hint );
 
 	// variable thrd is no longer safe to use
@@ -589,7 +616,7 @@
 }
 
-void schedule_thread$( thread$ * thrd ) {
+void schedule_thread$( thread$ * thrd, unpark_hint hint ) {
 	ready_schedule_lock();
-		__schedule_thread( thrd );
+		__schedule_thread( thrd, hint );
 	ready_schedule_unlock();
 }
@@ -642,5 +669,5 @@
 }
 
-void __kernel_unpark( thread$ * thrd ) {
+void __kernel_unpark( thread$ * thrd, unpark_hint hint ) {
 	/* paranoid */ verify( ! __preemption_enabled() );
 	/* paranoid */ verify( ready_schedule_islocked());
@@ -650,5 +677,5 @@
 	if(__must_unpark(thrd)) {
 		// Wake lost the race,
-		__schedule_thread( thrd );
+		__schedule_thread( thrd, hint );
 	}
 
@@ -657,5 +684,5 @@
 }
 
-void unpark( thread$ * thrd ) {
+void unpark( thread$ * thrd, unpark_hint hint ) {
 	if( !thrd ) return;
 
@@ -663,5 +690,5 @@
 		disable_interrupts();
 			// Wake lost the race,
-			schedule_thread$( thrd );
+			schedule_thread$( thrd, hint );
 		enable_interrupts(false);
 	}
@@ -920,4 +947,5 @@
 			/* paranoid */ verifyf( it, "Unexpected null iterator, at index %u of %u\n", i, count);
 			/* paranoid */ verify( it->local_data->this_stats );
+			// __print_stats( it->local_data->this_stats, cltr->print_stats, "Processor", it->name, (void*)it );
 			__tally_stats( cltr->stats, it->local_data->this_stats );
 			it = &(*it)`next;
@@ -929,4 +957,5 @@
 		// this doesn't solve all problems but does solve many
 		// so it's probably good enough
+		disable_interrupts();
 		uint_fast32_t last_size = ready_mutate_lock();
 
@@ -936,4 +965,5 @@
 		// Unlock the RWlock
 		ready_mutate_unlock( last_size );
+		enable_interrupts();
 	}
 
Index: libcfa/src/concurrency/kernel.hfa
===================================================================
--- libcfa/src/concurrency/kernel.hfa	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ libcfa/src/concurrency/kernel.hfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -151,7 +151,15 @@
 struct __attribute__((aligned(128))) __timestamp_t {
 	volatile unsigned long long tv;
-};
-
-static inline void  ?{}(__timestamp_t & this) { this.tv = 0; }
+	volatile unsigned long long ma;
+};
+
+// Aligned timestamps which are used by the relaxed ready queue
+struct __attribute__((aligned(128))) __help_cnts_t {
+	volatile unsigned long long src;
+	volatile unsigned long long dst;
+	volatile unsigned long long tri;
+};
+
+static inline void  ?{}(__timestamp_t & this) { this.tv = 0; this.ma = 0; }
 static inline void ^?{}(__timestamp_t & this) {}
 
@@ -169,4 +177,7 @@
 		// Array of times
 		__timestamp_t * volatile tscs;
+
+		// Array of stats
+		__help_cnts_t * volatile help;
 
 		// Number of lanes (empty or not)
Index: libcfa/src/concurrency/kernel/fwd.hfa
===================================================================
--- libcfa/src/concurrency/kernel/fwd.hfa	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ libcfa/src/concurrency/kernel/fwd.hfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -119,6 +119,9 @@
 
 	extern "Cforall" {
+		enum unpark_hint { UNPARK_LOCAL, UNPARK_REMOTE };
+
 		extern void park( void );
-		extern void unpark( struct thread$ * this );
+		extern void unpark( struct thread$ *, unpark_hint );
+		static inline void unpark( struct thread$ * thrd ) { unpark(thrd, UNPARK_LOCAL); }
 		static inline struct thread$ * active_thread () {
 			struct thread$ * t = publicTLS_get( this_thread );
Index: libcfa/src/concurrency/kernel/startup.cfa
===================================================================
--- libcfa/src/concurrency/kernel/startup.cfa	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ libcfa/src/concurrency/kernel/startup.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -100,4 +100,5 @@
 // Other Forward Declarations
 extern void __wake_proc(processor *);
+extern int cfa_main_returned;							// from interpose.cfa
 
 //-----------------------------------------------------------------------------
@@ -200,4 +201,28 @@
 	__cfadbg_print_safe(runtime_core, "Kernel : Main cluster ready\n");
 
+	// Construct the processor context of the main processor
+	void ?{}(processorCtx_t & this, processor * proc) {
+		(this.__cor){ "Processor" };
+		this.__cor.starter = 0p;
+		this.proc = proc;
+	}
+
+	void ?{}(processor & this) with( this ) {
+		( this.terminated ){};
+		( this.runner ){};
+		init( this, "Main Processor", *mainCluster, 0p );
+		kernel_thread = pthread_self();
+
+		runner{ &this };
+		__cfadbg_print_safe(runtime_core, "Kernel : constructed main processor context %p\n", &runner);
+	}
+
+	// Initialize the main processor and the main processor ctx
+	// (the coroutine that contains the processing control flow)
+	mainProcessor = (processor *)&storage_mainProcessor;
+	(*mainProcessor){};
+
+	register_tls( mainProcessor );
+
 	// Start by initializing the main thread
 	// SKULLDUGGERY: the mainThread steals the process main thread
@@ -210,31 +235,4 @@
 	__cfadbg_print_safe(runtime_core, "Kernel : Main thread ready\n");
 
-
-
-	// Construct the processor context of the main processor
-	void ?{}(processorCtx_t & this, processor * proc) {
-		(this.__cor){ "Processor" };
-		this.__cor.starter = 0p;
-		this.proc = proc;
-	}
-
-	void ?{}(processor & this) with( this ) {
-		( this.terminated ){};
-		( this.runner ){};
-		init( this, "Main Processor", *mainCluster, 0p );
-		kernel_thread = pthread_self();
-
-		runner{ &this };
-		__cfadbg_print_safe(runtime_core, "Kernel : constructed main processor context %p\n", &runner);
-	}
-
-	// Initialize the main processor and the main processor ctx
-	// (the coroutine that contains the processing control flow)
-	mainProcessor = (processor *)&storage_mainProcessor;
-	(*mainProcessor){};
-
-	register_tls( mainProcessor );
-	mainThread->last_cpu = __kernel_getcpu();
-
 	//initialize the global state variables
 	__cfaabi_tls.this_processor = mainProcessor;
@@ -252,5 +250,5 @@
 	// Add the main thread to the ready queue
 	// once resume is called on mainProcessor->runner the mainThread needs to be scheduled like any normal thread
-	schedule_thread$(mainThread);
+	schedule_thread$(mainThread, UNPARK_LOCAL);
 
 	// SKULLDUGGERY: Force a context switch to the main processor to set the main thread's context to the current UNIX
@@ -271,4 +269,5 @@
 
 static void __kernel_shutdown(void) {
+	if(!cfa_main_returned) return;
 	/* paranoid */ verify( __preemption_enabled() );
 	disable_interrupts();
@@ -486,5 +485,5 @@
 	link.next = 0p;
 	link.ts   = -1llu;
-	preferred = -1u;
+	preferred = ready_queue_new_preferred();
 	last_proc = 0p;
 	#if defined( __CFA_WITH_VERIFY__ )
Index: libcfa/src/concurrency/kernel_private.hfa
===================================================================
--- libcfa/src/concurrency/kernel_private.hfa	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ libcfa/src/concurrency/kernel_private.hfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -46,5 +46,5 @@
 }
 
-void schedule_thread$( thread$ * ) __attribute__((nonnull (1)));
+void schedule_thread$( thread$ *, unpark_hint hint ) __attribute__((nonnull (1)));
 
 extern bool __preemption_enabled();
@@ -300,5 +300,5 @@
 // push thread onto a ready queue for a cluster
 // returns true if the list was previously empty, false otherwise
-__attribute__((hot)) void push(struct cluster * cltr, struct thread$ * thrd, bool local);
+__attribute__((hot)) void push(struct cluster * cltr, struct thread$ * thrd, unpark_hint hint);
 
 //-----------------------------------------------------------------------
@@ -321,4 +321,8 @@
 
 //-----------------------------------------------------------------------
+// get preferred ready for new thread
+unsigned ready_queue_new_preferred();
+
+//-----------------------------------------------------------------------
 // Increase the width of the ready queue (number of lanes) by 4
 void ready_queue_grow  (struct cluster * cltr);
Index: libcfa/src/concurrency/locks.hfa
===================================================================
--- libcfa/src/concurrency/locks.hfa	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ libcfa/src/concurrency/locks.hfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -324,62 +324,4 @@
 	}
 
-	// linear backoff bounded by spin_count
-	spin = spin_start;
-	int spin_counter = 0;
-	int yield_counter = 0;
-	for ( ;; ) {
-		if(try_lock_contention(this)) return true;
-		if(spin_counter < spin_count) {
-			for (int i = 0; i < spin; i++) Pause();
-			if (spin < spin_end) spin += spin;
-			else spin_counter++;
-		} else if (yield_counter < yield_count) {
-			// after linear backoff yield yield_count times
-			yield_counter++;
-			yield();
-		} else { break; }
-	}
-
-	// block until signalled
-	while (block(this)) if(try_lock_contention(this)) return true;
-
-	// this should never be reached as block(this) always returns true
-	return false;
-}
-
-static inline bool lock_improved(linear_backoff_then_block_lock & this) with(this) {
-	// if owner just return
-	if (active_thread() == owner) return true;
-	size_t compare_val = 0;
-	int spin = spin_start;
-	// linear backoff
-	for( ;; ) {
-		compare_val = 0;
-		if (internal_try_lock(this, compare_val)) return true;
-		if (2 == compare_val) break;
-		for (int i = 0; i < spin; i++) Pause();
-		if (spin >= spin_end) break;
-		spin += spin;
-	}
-
-	// linear backoff bounded by spin_count
-	spin = spin_start;
-	int spin_counter = 0;
-	int yield_counter = 0;
-	for ( ;; ) {
-		compare_val = 0;
-		if(internal_try_lock(this, compare_val)) return true;
-		if (2 == compare_val) break;
-		if(spin_counter < spin_count) {
-			for (int i = 0; i < spin; i++) Pause();
-			if (spin < spin_end) spin += spin;
-			else spin_counter++;
-		} else if (yield_counter < yield_count) {
-			// after linear backoff yield yield_count times
-			yield_counter++;
-			yield();
-		} else { break; }
-	}
-
 	if(2 != compare_val && try_lock_contention(this)) return true;
 	// block until signalled
@@ -402,5 +344,5 @@
 static inline void on_notify(linear_backoff_then_block_lock & this, struct thread$ * t ) { unpark(t); }
 static inline size_t on_wait(linear_backoff_then_block_lock & this) { unlock(this); return 0; }
-static inline void on_wakeup(linear_backoff_then_block_lock & this, size_t recursion ) { lock_improved(this); }
+static inline void on_wakeup(linear_backoff_then_block_lock & this, size_t recursion ) { lock(this); }
 
 //-----------------------------------------------------------------------------
Index: libcfa/src/concurrency/monitor.cfa
===================================================================
--- libcfa/src/concurrency/monitor.cfa	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ libcfa/src/concurrency/monitor.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -990,4 +990,62 @@
 }
 
+//-----------------------------------------------------------------------------
+// Enter routine for mutex stmt
+// Can't be accepted since a mutex stmt is effectively an anonymous routine
+// Thus we do not need a monitor group
+void lock( monitor$ * this ) {
+	thread$ * thrd = active_thread();
+
+	// Lock the monitor spinlock
+	lock( this->lock __cfaabi_dbg_ctx2 );
+
+	__cfaabi_dbg_print_safe( "Kernel : %10p Entering mon %p (%p)\n", thrd, this, this->owner);
+
+	if( unlikely(0 != (0x1 & (uintptr_t)this->owner)) ) {
+		abort( "Attempt by thread \"%.256s\" (%p) to access joined monitor %p.", thrd->self_cor.name, thrd, this );
+	}
+	else if( !this->owner ) {
+		// No one has the monitor, just take it
+		__set_owner( this, thrd );
+
+		__cfaabi_dbg_print_safe( "Kernel :  mon is free \n" );
+	}
+	else if( this->owner == thrd) {
+		// We already have the monitor, just note how many times we took it
+		this->recursion += 1;
+
+		__cfaabi_dbg_print_safe( "Kernel :  mon already owned \n" );
+	}
+	else {
+		__cfaabi_dbg_print_safe( "Kernel :  blocking \n" );
+
+		// Some one else has the monitor, wait in line for it
+		/* paranoid */ verify( thrd->link.next == 0p );
+		append( this->entry_queue, thrd );
+		/* paranoid */ verify( thrd->link.next == 1p );
+
+		unlock( this->lock );
+		park();
+
+		__cfaabi_dbg_print_safe( "Kernel : %10p Entered  mon %p\n", thrd, this);
+
+		/* paranoid */ verifyf( active_thread() == this->owner, "Expected owner to be %p, got %p (r: %i, m: %p)", active_thread(), this->owner, this->recursion, this );
+		return;
+	}
+
+	__cfaabi_dbg_print_safe( "Kernel : %10p Entered  mon %p\n", thrd, this);
+
+	/* paranoid */ verifyf( active_thread() == this->owner, "Expected owner to be %p, got %p (r: %i, m: %p)", active_thread(), this->owner, this->recursion, this );
+	/* paranoid */ verify( this->lock.lock );
+
+	// Release the lock and leave
+	unlock( this->lock );
+	return;
+}
+
+// Leave routine for mutex stmt
+// Is just a wrapper around __leave for the is_lock trait to see
+void unlock( monitor$ * this ) { __leave( this ); }
+
 // Local Variables: //
 // mode: c //
Index: libcfa/src/concurrency/monitor.hfa
===================================================================
--- libcfa/src/concurrency/monitor.hfa	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ libcfa/src/concurrency/monitor.hfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -65,4 +65,15 @@
 	free( th );
 }
+
+static inline forall( T & | sized(T) | { void ^?{}( T & mutex ); } )
+void adelete( T arr[] ) {
+	if ( arr ) {										// ignore null
+		size_t dim = malloc_size( arr ) / sizeof( T );
+		for ( int i = dim - 1; i >= 0; i -= 1 ) {		// reverse allocation order, must be unsigned
+			^(arr[i]){};								// run destructor
+		} // for
+		free( arr );
+	} // if
+} // adelete
 
 //-----------------------------------------------------------------------------
@@ -149,4 +160,8 @@
 void __waitfor_internal( const __waitfor_mask_t & mask, int duration );
 
+// lock and unlock routines for mutex statements to use
+void lock( monitor$ * this );
+void unlock( monitor$ * this );
+
 // Local Variables: //
 // mode: c //
Index: libcfa/src/concurrency/mutex_stmt.hfa
===================================================================
--- libcfa/src/concurrency/mutex_stmt.hfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
+++ libcfa/src/concurrency/mutex_stmt.hfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -0,0 +1,47 @@
+#include "bits/algorithm.hfa"
+#include "bits/defs.hfa"
+
+//-----------------------------------------------------------------------------
+// is_lock
+trait is_lock(L & | sized(L)) {
+	// For acquiring a lock
+	void lock( L & );
+
+	// For releasing a lock
+	void unlock( L & );
+};
+
+forall(L & | is_lock(L)) {
+
+    struct __mutex_stmt_lock_guard {
+        L ** lockarr;
+        __lock_size_t count;
+    };
+    
+    static inline void ?{}( __mutex_stmt_lock_guard(L) & this, L * lockarr [], __lock_size_t count  ) {
+        this.lockarr = lockarr;
+        this.count = count;
+
+        // Sort locks based on address
+        __libcfa_small_sort(this.lockarr, count);
+
+        // acquire locks in order
+        for ( size_t i = 0; i < count; i++ ) {
+            lock(*this.lockarr[i]);
+        }
+    }
+    
+    static inline void ^?{}( __mutex_stmt_lock_guard(L) & this ) with(this) {
+        for ( size_t i = count; i > 0; i-- ) {
+            unlock(*lockarr[i - 1]);
+        }
+    }
+
+    static inline L * __get_ptr( L & this ) {
+        return &this;
+    }
+
+    static inline L __get_type( L & this );
+
+    static inline L __get_type( L * this );
+}
Index: libcfa/src/concurrency/ready_queue.cfa
===================================================================
--- libcfa/src/concurrency/ready_queue.cfa	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ libcfa/src/concurrency/ready_queue.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -100,6 +100,6 @@
 	#define __kernel_rseq_unregister rseq_unregister_current_thread
 #elif defined(CFA_HAVE_LINUX_RSEQ_H)
-	void __kernel_raw_rseq_register  (void);
-	void __kernel_raw_rseq_unregister(void);
+	static void __kernel_raw_rseq_register  (void);
+	static void __kernel_raw_rseq_unregister(void);
 
 	#define __kernel_rseq_register __kernel_raw_rseq_register
@@ -246,4 +246,11 @@
 // Cforall Ready Queue used for scheduling
 //=======================================================================
+unsigned long long moving_average(unsigned long long nval, unsigned long long oval) {
+	const unsigned long long tw = 16;
+	const unsigned long long nw = 4;
+	const unsigned long long ow = tw - nw;
+	return ((nw * nval) + (ow * oval)) / tw;
+}
+
 void ?{}(__ready_queue_t & this) with (this) {
 	#if defined(USE_CPU_WORK_STEALING)
@@ -251,12 +258,20 @@
 		lanes.data = alloc( lanes.count );
 		lanes.tscs = alloc( lanes.count );
+		lanes.help = alloc( cpu_info.hthrd_count );
 
 		for( idx; (size_t)lanes.count ) {
 			(lanes.data[idx]){};
 			lanes.tscs[idx].tv = rdtscl();
+			lanes.tscs[idx].ma = rdtscl();
+		}
+		for( idx; (size_t)cpu_info.hthrd_count ) {
+			lanes.help[idx].src = 0;
+			lanes.help[idx].dst = 0;
+			lanes.help[idx].tri = 0;
 		}
 	#else
 		lanes.data  = 0p;
 		lanes.tscs  = 0p;
+		lanes.help  = 0p;
 		lanes.count = 0;
 	#endif
@@ -270,14 +285,16 @@
 	free(lanes.data);
 	free(lanes.tscs);
+	free(lanes.help);
 }
 
 //-----------------------------------------------------------------------
 #if defined(USE_CPU_WORK_STEALING)
-	__attribute__((hot)) void push(struct cluster * cltr, struct thread$ * thrd, bool push_local) with (cltr->ready_queue) {
+	__attribute__((hot)) void push(struct cluster * cltr, struct thread$ * thrd, unpark_hint hint) with (cltr->ready_queue) {
 		__cfadbg_print_safe(ready_queue, "Kernel : Pushing %p on cluster %p\n", thrd, cltr);
 
 		processor * const proc = kernelTLS().this_processor;
-		const bool external = !push_local || (!proc) || (cltr != proc->cltr);
-
+		const bool external = (!proc) || (cltr != proc->cltr);
+
+		// Figure out the current cpu and make sure it is valid
 		const int cpu = __kernel_getcpu();
 		/* paranoid */ verify(cpu >= 0);
@@ -285,5 +302,15 @@
 		/* paranoid */ verify(cpu * READYQ_SHARD_FACTOR < lanes.count);
 
-		const cpu_map_entry_t & map = cpu_info.llc_map[cpu];
+		// Figure out where thread was last time and make sure it's
+		/* paranoid */ verify(thrd->preferred >= 0);
+		/* paranoid */ verify(thrd->preferred < cpu_info.hthrd_count);
+		/* paranoid */ verify(thrd->preferred * READYQ_SHARD_FACTOR < lanes.count);
+		const int prf = thrd->preferred * READYQ_SHARD_FACTOR;
+
+		const cpu_map_entry_t & map;
+		choose(hint) {
+			case UNPARK_LOCAL : &map = &cpu_info.llc_map[cpu];
+			case UNPARK_REMOTE: &map = &cpu_info.llc_map[prf];
+		}
 		/* paranoid */ verify(map.start * READYQ_SHARD_FACTOR < lanes.count);
 		/* paranoid */ verify(map.self * READYQ_SHARD_FACTOR < lanes.count);
@@ -296,5 +323,8 @@
 			if(unlikely(external)) { r = __tls_rand(); }
 			else { r = proc->rdq.its++; }
-			i = start + (r % READYQ_SHARD_FACTOR);
+			choose(hint) {
+				case UNPARK_LOCAL : i = start + (r % READYQ_SHARD_FACTOR);
+				case UNPARK_REMOTE: i = prf   + (r % READYQ_SHARD_FACTOR);
+			}
 			// If we can't lock it retry
 		} while( !__atomic_try_acquire( &lanes.data[i].lock ) );
@@ -332,19 +362,18 @@
 		processor * const proc = kernelTLS().this_processor;
 		const int start = map.self * READYQ_SHARD_FACTOR;
+		const unsigned long long ctsc = rdtscl();
 
 		// Did we already have a help target
 		if(proc->rdq.target == -1u) {
-			// if We don't have a
-			unsigned long long min = ts(lanes.data[start]);
+			unsigned long long max = 0;
 			for(i; READYQ_SHARD_FACTOR) {
-				unsigned long long tsc = ts(lanes.data[start + i]);
-				if(tsc < min) min = tsc;
-			}
-			proc->rdq.cutoff = min;
-
+				unsigned long long tsc = moving_average(ctsc - ts(lanes.data[start + i]), lanes.tscs[start + i].ma);
+				if(tsc > max) max = tsc;
+			}
+			 proc->rdq.cutoff = (max + 2 * max) / 2;
 			/* paranoid */ verify(lanes.count < 65536); // The following code assumes max 65536 cores.
 			/* paranoid */ verify(map.count < 65536); // The following code assumes max 65536 cores.
 
-			if(0 == (__tls_rand() % 10_000)) {
+			if(0 == (__tls_rand() % 100)) {
 				proc->rdq.target = __tls_rand() % lanes.count;
 			} else {
@@ -358,14 +387,21 @@
 		}
 		else {
-			const unsigned long long bias = 0; //2_500_000_000;
-			const unsigned long long cutoff = proc->rdq.cutoff > bias ? proc->rdq.cutoff - bias : proc->rdq.cutoff;
+			unsigned long long max = 0;
+			for(i; READYQ_SHARD_FACTOR) {
+				unsigned long long tsc = moving_average(ctsc - ts(lanes.data[start + i]), lanes.tscs[start + i].ma);
+				if(tsc > max) max = tsc;
+			}
+			const unsigned long long cutoff = (max + 2 * max) / 2;
 			{
 				unsigned target = proc->rdq.target;
 				proc->rdq.target = -1u;
-				if(lanes.tscs[target].tv < cutoff && ts(lanes.data[target]) < cutoff) {
+				lanes.help[target / READYQ_SHARD_FACTOR].tri++;
+				if(moving_average(ctsc - lanes.tscs[target].tv, lanes.tscs[target].ma) > cutoff) {
 					thread$ * t = try_pop(cltr, target __STATS(, __tls_stats()->ready.pop.help));
 					proc->rdq.last = target;
 					if(t) return t;
+					else proc->rdq.target = -1u;
 				}
+				else proc->rdq.target = -1u;
 			}
 
@@ -428,8 +464,8 @@
 	}
 
-	__attribute__((hot)) void push(struct cluster * cltr, struct thread$ * thrd, bool push_local) with (cltr->ready_queue) {
+	__attribute__((hot)) void push(struct cluster * cltr, struct thread$ * thrd, unpark_hint hint) with (cltr->ready_queue) {
 		__cfadbg_print_safe(ready_queue, "Kernel : Pushing %p on cluster %p\n", thrd, cltr);
 
-		const bool external = !push_local || (!kernelTLS().this_processor) || (cltr != kernelTLS().this_processor->cltr);
+		const bool external = (hint != UNPARK_LOCAL) || (!kernelTLS().this_processor) || (cltr != kernelTLS().this_processor->cltr);
 		/* paranoid */ verify(external || kernelTLS().this_processor->rdq.id < lanes.count );
 
@@ -515,14 +551,14 @@
 #endif
 #if defined(USE_WORK_STEALING)
-	__attribute__((hot)) void push(struct cluster * cltr, struct thread$ * thrd, bool push_local) with (cltr->ready_queue) {
+	__attribute__((hot)) void push(struct cluster * cltr, struct thread$ * thrd, unpark_hint hint) with (cltr->ready_queue) {
 		__cfadbg_print_safe(ready_queue, "Kernel : Pushing %p on cluster %p\n", thrd, cltr);
 
 		// #define USE_PREFERRED
 		#if !defined(USE_PREFERRED)
-		const bool external = !push_local || (!kernelTLS().this_processor) || (cltr != kernelTLS().this_processor->cltr);
+		const bool external = (hint != UNPARK_LOCAL) || (!kernelTLS().this_processor) || (cltr != kernelTLS().this_processor->cltr);
 		/* paranoid */ verify(external || kernelTLS().this_processor->rdq.id < lanes.count );
 		#else
 			unsigned preferred = thrd->preferred;
-			const bool external = push_local || (!kernelTLS().this_processor) || preferred == -1u || thrd->curr_cluster != cltr;
+			const bool external = (hint != UNPARK_LOCAL) || (!kernelTLS().this_processor) || preferred == -1u || thrd->curr_cluster != cltr;
 			/* paranoid */ verifyf(external || preferred < lanes.count, "Invalid preferred queue %u for %u lanes", preferred, lanes.count );
 
@@ -645,4 +681,5 @@
 	// Actually pop the list
 	struct thread$ * thrd;
+	unsigned long long tsc_before = ts(lane);
 	unsigned long long tsv;
 	[thrd, tsv] = pop(lane);
@@ -658,9 +695,15 @@
 	__STATS( stats.success++; )
 
-	#if defined(USE_WORK_STEALING)
+	#if defined(USE_WORK_STEALING) || defined(USE_CPU_WORK_STEALING)
+		unsigned long long now = rdtscl();
 		lanes.tscs[w].tv = tsv;
+		lanes.tscs[w].ma = moving_average(now > tsc_before ? now - tsc_before : 0, lanes.tscs[w].ma);
 	#endif
 
-	thrd->preferred = w;
+	#if defined(USE_CPU_WORK_STEALING)
+		thrd->preferred = w / READYQ_SHARD_FACTOR;
+	#else
+		thrd->preferred = w;
+	#endif
 
 	// return the popped thread
@@ -688,4 +731,25 @@
 
 //-----------------------------------------------------------------------
+// get preferred ready for new thread
+unsigned ready_queue_new_preferred() {
+	unsigned pref = 0;
+	if(struct thread$ * thrd = publicTLS_get( this_thread )) {
+		pref = thrd->preferred;
+	}
+	else {
+		#if defined(USE_CPU_WORK_STEALING)
+			pref = __kernel_getcpu();
+		#endif
+	}
+
+	#if defined(USE_CPU_WORK_STEALING)
+		/* paranoid */ verify(pref >= 0);
+		/* paranoid */ verify(pref < cpu_info.hthrd_count);
+	#endif
+
+	return pref;
+}
+
+//-----------------------------------------------------------------------
 // Check that all the intrusive queues in the data structure are still consistent
 static void check( __ready_queue_t & q ) with (q) {
@@ -915,5 +979,5 @@
 	extern void __enable_interrupts_hard();
 
-	void __kernel_raw_rseq_register  (void) {
+	static void __kernel_raw_rseq_register  (void) {
 		/* paranoid */ verify( __cfaabi_rseq.cpu_id == RSEQ_CPU_ID_UNINITIALIZED );
 
@@ -933,5 +997,5 @@
 	}
 
-	void __kernel_raw_rseq_unregister(void) {
+	static void __kernel_raw_rseq_unregister(void) {
 		/* paranoid */ verify( __cfaabi_rseq.cpu_id >= 0 );
 
Index: libcfa/src/concurrency/ready_subqueue.hfa
===================================================================
--- libcfa/src/concurrency/ready_subqueue.hfa	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ libcfa/src/concurrency/ready_subqueue.hfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -98,5 +98,4 @@
 
 	// Get the relevant nodes locally
-	unsigned long long ts = this.anchor.ts;
 	thread$ * node = this.anchor.next;
 	this.anchor.next = node->link.next;
@@ -116,5 +115,5 @@
 	/* paranoid */ verify( node->link.ts   != 0  );
 	/* paranoid */ verify( this.anchor.ts  != 0  );
-	return [node, ts];
+	return [node, this.anchor.ts];
 }
 
Index: libcfa/src/concurrency/stats.cfa
===================================================================
--- libcfa/src/concurrency/stats.cfa	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ libcfa/src/concurrency/stats.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -48,4 +48,8 @@
 			stats->io.calls.completed   = 0;
 			stats->io.calls.errors.busy = 0;
+			stats->io.ops.sockread      = 0;
+			stats->io.ops.epllread      = 0;
+			stats->io.ops.sockwrite     = 0;
+			stats->io.ops.epllwrite     = 0;
 		#endif
 
@@ -104,4 +108,8 @@
 			tally_one( &cltr->io.calls.completed  , &proc->io.calls.completed   );
 			tally_one( &cltr->io.calls.errors.busy, &proc->io.calls.errors.busy );
+			tally_one( &cltr->io.ops.sockread     , &proc->io.ops.sockread      );
+			tally_one( &cltr->io.ops.epllread     , &proc->io.ops.epllread      );
+			tally_one( &cltr->io.ops.sockwrite    , &proc->io.ops.sockwrite     );
+			tally_one( &cltr->io.ops.epllwrite    , &proc->io.ops.epllwrite     );
 		#endif
 	}
@@ -179,4 +187,7 @@
 				     | " - cmp " | eng3(io.calls.drain) | "/" | eng3(io.calls.completed) | "(" | ws(3, 3, avgcomp) | "/drain)"
 				     | " - " | eng3(io.calls.errors.busy) | " EBUSY";
+				sstr | "- ops blk: "
+				     |   " sk rd: " | eng3(io.ops.sockread)  | "epll: " | eng3(io.ops.epllread)
+				     |   " sk wr: " | eng3(io.ops.sockwrite) | "epll: " | eng3(io.ops.epllwrite);
 				sstr | nl;
 			}
Index: libcfa/src/concurrency/stats.hfa
===================================================================
--- libcfa/src/concurrency/stats.hfa	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ libcfa/src/concurrency/stats.hfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -102,4 +102,10 @@
 				volatile uint64_t sleeps;
 			} poller;
+			struct {
+				volatile uint64_t sockread;
+				volatile uint64_t epllread;
+				volatile uint64_t sockwrite;
+				volatile uint64_t epllwrite;
+			} ops;
 		};
 	#endif
Index: libcfa/src/concurrency/thread.cfa
===================================================================
--- libcfa/src/concurrency/thread.cfa	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ libcfa/src/concurrency/thread.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -25,4 +25,6 @@
 #include "invoke.h"
 
+uint64_t thread_rand();
+
 //-----------------------------------------------------------------------------
 // Thread ctors and dtors
@@ -34,7 +36,4 @@
 	preempted = __NO_PREEMPTION;
 	corctx_flag = false;
-	disable_interrupts();
-	last_cpu = __kernel_getcpu();
-	enable_interrupts();
 	curr_cor = &self_cor;
 	self_mon.owner = &this;
@@ -44,5 +43,5 @@
 	link.next = 0p;
 	link.ts   = -1llu;
-	preferred = -1u;
+	preferred = ready_queue_new_preferred();
 	last_proc = 0p;
 	#if defined( __CFA_WITH_VERIFY__ )
@@ -141,5 +140,5 @@
 	/* paranoid */ verify( this_thrd->context.SP );
 
-	schedule_thread$( this_thrd );
+	schedule_thread$( this_thrd, UNPARK_LOCAL );
 	enable_interrupts();
 }
Index: libcfa/src/containers/string.cfa
===================================================================
--- libcfa/src/containers/string.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
+++ libcfa/src/containers/string.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -0,0 +1,317 @@
+//
+// Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
+//
+// The contents of this file are covered under the licence agreement in the
+// file "LICENCE" distributed with Cforall.
+//
+// string -- variable-length, mutable run of text, with value semantics
+//
+// Author           : Michael L. Brooks
+// Created On       : Fri Sep 03 11:00:00 2021
+// Last Modified By : Michael L. Brooks
+// Last Modified On : Fri Sep 03 11:00:00 2021
+// Update Count     : 1
+//
+
+#include "string.hfa"
+#include "string_res.hfa"
+#include <stdlib.hfa>
+
+
+/*
+Implementation Principle: typical operation translates to the equivalent
+operation on `inner`.  Exceptions are implementing new RAII pattern for value
+semantics and some const-hell handling.
+*/
+
+////////////////////////////////////////////////////////
+// string RAII
+
+
+void ?{}( string & this ) {
+    (this.inner) { malloc() };
+    ?{}( *this.inner );
+}
+
+// private (not in header)
+static void ?{}( string & this, string_res & src, size_t start, size_t end ) {
+    (this.inner) { malloc() };
+    ?{}( *this.inner, src, SHARE_EDITS, start, end );
+}
+
+void ?{}( string & this, const string & other ) {
+    (this.inner) { malloc() };
+    ?{}( *this.inner, *other.inner, COPY_VALUE );
+}
+
+void ?{}( string & this, string & other ) {
+    ?{}( this, (const string &) other );
+}
+
+void ?{}( string & this, const char * val ) {
+    (this.inner) { malloc() };
+    ?{}( *this.inner, val );
+}
+
+void ?{}( string & this, const char* buffer, size_t bsize) {
+    (this.inner) { malloc() };
+    ?{}( *this.inner, buffer, bsize );
+}
+
+void ^?{}( string & this ) {
+    ^(*this.inner){};
+    free( this.inner );
+    this.inner = 0p;
+}
+
+////////////////////////////////////////////////////////
+// Alternate construction: request shared edits
+
+string_WithSharedEdits ?`shareEdits( string & this ) {
+    string_WithSharedEdits ret = { &this };
+    return ret;
+}
+
+void ?{}( string & this, string_WithSharedEdits src ) {
+    ?{}( this, *src.s->inner, 0, src.s->inner->Handle.lnth);
+}
+
+////////////////////////////////////////////////////////
+// Assignment
+
+void ?=?( string & this, const char * val ) {
+    (*this.inner) = val;
+}
+
+void ?=?(string & this, const string & other) {
+    (*this.inner) = (*other.inner);
+}
+
+void ?=?( string & this, char val ) {
+    (*this.inner) = val;
+}
+
+string ?=?(string & this, string other) {
+    (*this.inner) = (*other.inner);
+    return this;
+}
+
+
+////////////////////////////////////////////////////////
+// Output
+
+ofstream & ?|?( ofstream & fs, const string & this ) {
+    return fs | (*this.inner);
+}
+
+void ?|?( ofstream & fs, const string & this ) {
+    fs | (*this.inner);
+}
+
+////////////////////////////////////////////////////////
+// Slicing
+
+string ?()( string & this, size_t start, size_t end ) {
+    string ret = { *this.inner, start, end };
+    return ret`shareEdits;
+}
+
+////////////////////////////////////////////////////////
+// Comparison
+
+bool ?==?(const string &s, const string &other) {
+    return *s.inner == *other.inner;
+}
+
+bool ?!=?(const string &s, const string &other) {
+    return *s.inner != *other.inner;
+}
+
+bool ?==?(const string &s, const char* other) {
+    return *s.inner == other;
+}
+
+bool ?!=?(const string &s, const char* other) {
+    return *s.inner != other;
+}
+
+////////////////////////////////////////////////////////
+// Getter
+
+size_t size(const string &s) {
+    return size( * s.inner );
+}
+
+////////////////////////////////////////////////////////
+// Concatenation
+
+void ?+=?(string &s, char other) {
+    (*s.inner) += other;
+}
+
+void ?+=?(string &s, const string &s2) {
+    (*s.inner) += (*s2.inner);
+}
+
+void ?+=?(string &s, const char* other) {
+    (*s.inner) += other;
+}
+
+string ?+?(const string &s, char other) {
+    string ret = s;
+    ret += other;
+    return ret;
+}
+
+string ?+?(const string &s, const string &s2) {
+    string ret = s;
+    ret += s2;
+    return ret;
+}
+
+string ?+?(const char* s1, const char* s2) {
+    string ret = s1;
+    ret += s2;
+    return ret;
+}
+
+string ?+?(const string &s, const char* other) {
+    string ret = s;
+    ret += other;
+    return ret;
+}
+
+////////////////////////////////////////////////////////
+// Repetition
+
+string ?*?(const string &s, size_t factor) {
+    string ret = "";
+    for (factor) ret += s;
+    return ret;
+}
+
+string ?*?(char c, size_t size) {
+    string ret = "";
+    for ((size_t)size) ret += c;
+    return ret;
+}
+
+string ?*?(const char *s, size_t factor) {
+    string ss = s;
+    return ss * factor;
+}
+
+////////////////////////////////////////////////////////
+// Character access
+
+char ?[?](const string &s, size_t index) {
+    return (*s.inner)[index];
+}
+
+string ?[?](string &s, size_t index) {
+    string ret = { *s.inner, index, index + 1 };
+    return ret`shareEdits;
+}
+
+////////////////////////////////////////////////////////
+// Search
+
+bool contains(const string &s, char ch) {
+    return contains( *s.inner, ch );
+}
+
+int find(const string &s, char search) {
+    return find( *s.inner, search );
+}
+
+int find(const string &s, const string &search) {
+    return find( *s.inner, *search.inner );
+}
+
+int find(const string &s, const char* search) {
+    return find( *s.inner, search);
+}
+
+int find(const string &s, const char* search, size_t searchsize) {
+    return find( *s.inner, search, searchsize);
+}
+
+bool includes(const string &s, const string &search) {
+    return includes( *s.inner, *search.inner );
+}
+
+bool includes(const string &s, const char* search) {
+    return includes( *s.inner, search );
+}
+
+bool includes(const string &s, const char* search, size_t searchsize) {
+    return includes( *s.inner, search, searchsize );
+}
+
+bool startsWith(const string &s, const string &prefix) {
+    return startsWith( *s.inner, *prefix.inner );
+}
+
+bool startsWith(const string &s, const char* prefix) {
+    return startsWith( *s.inner, prefix );
+}
+
+bool startsWith(const string &s, const char* prefix, size_t prefixsize) {
+    return startsWith( *s.inner, prefix, prefixsize );
+}
+
+bool endsWith(const string &s, const string &suffix) {
+    return endsWith( *s.inner, *suffix.inner );
+}
+
+bool endsWith(const string &s, const char* suffix) {
+    return endsWith( *s.inner, suffix );
+}
+
+bool endsWith(const string &s, const char* suffix, size_t suffixsize) {
+    return endsWith( *s.inner, suffix, suffixsize );
+}
+
+
+///////////////////////////////////////////////////////////////////////////
+// charclass, include, exclude
+
+void ?{}( charclass & this, const string & chars) {
+    (this.inner) { malloc() };
+    ?{}( *this.inner, *(const string_res *)chars.inner );
+}
+
+void ?{}( charclass & this, const char * chars ) {
+    (this.inner) { malloc() };
+    ?{}( *this.inner, chars );
+}
+
+void ?{}( charclass & this, const char * chars, size_t charssize ) {
+    (this.inner) { malloc() };
+    ?{}( *this.inner, chars, charssize );
+}
+
+void ^?{}( charclass & this ) {
+    ^(*this.inner){};
+    free( this.inner );
+    this.inner = 0p;
+}
+
+
+int exclude(const string &s, const charclass &mask) {
+    return exclude( *s.inner, *mask.inner );
+}
+/*
+StrSlice exclude(string &s, const charclass &mask) {
+}
+*/
+
+int include(const string &s, const charclass &mask) {
+    return include( *s.inner, *mask.inner );
+}
+
+/*
+StrSlice include(string &s, const charclass &mask) {
+}
+*/
+
Index: libcfa/src/containers/string.hfa
===================================================================
--- libcfa/src/containers/string.hfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
+++ libcfa/src/containers/string.hfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -0,0 +1,138 @@
+//
+// Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
+//
+// The contents of this file are covered under the licence agreement in the
+// file "LICENCE" distributed with Cforall.
+//
+// string -- variable-length, mutable run of text, with value semantics
+//
+// Author           : Michael L. Brooks
+// Created On       : Fri Sep 03 11:00:00 2021
+// Last Modified By : Michael L. Brooks
+// Last Modified On : Fri Sep 03 11:00:00 2021
+// Update Count     : 1
+//
+
+#pragma once
+
+#include <fstream.hfa>
+
+
+// in string_res.hfa
+struct string_res;
+struct charclass_res;
+
+struct string {
+    string_res * inner;
+};
+
+// Getters
+size_t size(const string &s);
+
+// RAII, assignment
+void ?{}( string & this ); // empty string
+void ?{}(string &s, const char* initial); // copy from string literal (NULL-terminated)
+void ?{}(string &s, const char* buffer, size_t bsize); // copy specific length from buffer
+
+void ?{}(string &s, const string & s2);
+void ?{}(string &s, string & s2);
+
+void ?=?(string &s, const char* other); // copy assignment from literal
+void ?=?(string &s, const string &other);
+void ?=?(string &s, char other);
+string ?=?(string &s, string other);  // string tolerates memcpys; still saw calls to autogen 
+
+void ^?{}(string &s);
+
+// Alternate construction: request shared edits
+struct string_WithSharedEdits {
+    string * s;
+};
+string_WithSharedEdits ?`shareEdits( string & this );
+void ?{}( string & this, string_WithSharedEdits src );
+
+// IO Operator
+ofstream & ?|?(ofstream &out, const string &s);
+void ?|?(ofstream &out, const string &s);
+
+// Concatenation
+void ?+=?(string &s, char other); // append a character
+void ?+=?(string &s, const string &s2); // append-concatenate to first string
+void ?+=?(string &s, const char* other); // append-concatenate to first string
+string ?+?(const string &s, char other); // add a character to a copy of the string
+string ?+?(const string &s, const string &s2); // copy and concatenate both strings
+string ?+?(const char* s1, const char* s2); // concatenate both strings
+string ?+?(const string &s, const char* other); // copy and concatenate with NULL-terminated string
+
+// Repetition
+string ?*?(const string &s, size_t factor);
+string ?*?(char c, size_t size);
+string ?*?(const char *s, size_t size);
+
+// Character access
+char ?[?](const string &s, size_t index);
+string ?[?](string &s, size_t index);  // mutable length-1 slice of original
+//char codePointAt(const string &s, size_t index);  // to revisit under Unicode
+
+// Comparisons
+bool ?==?(const string &s, const string &other);
+bool ?!=?(const string &s, const string &other);
+bool ?==?(const string &s, const char* other);
+bool ?!=?(const string &s, const char* other);
+
+// Slicing
+string ?()( string & this, size_t start, size_t end );  // TODO const?
+string ?()( string & this, size_t start);
+
+// String search
+bool contains(const string &s, char ch); // single character
+
+int find(const string &s, char search);
+int find(const string &s, const string &search);
+int find(const string &s, const char* search);
+int find(const string &s, const char* search, size_t searchsize);
+
+bool includes(const string &s, const string &search);
+bool includes(const string &s, const char* search);
+bool includes(const string &s, const char* search, size_t searchsize);
+
+bool startsWith(const string &s, const string &prefix);
+bool startsWith(const string &s, const char* prefix);
+bool startsWith(const string &s, const char* prefix, size_t prefixsize);
+
+bool endsWith(const string &s, const string &suffix);
+bool endsWith(const string &s, const char* suffix);
+bool endsWith(const string &s, const char* suffix, size_t suffixsize);
+
+// Modifiers
+void padStart(string &s, size_t n);
+void padStart(string &s, size_t n, char padding);
+void padEnd(string &s, size_t n);
+void padEnd(string &s, size_t n, char padding);
+
+
+
+struct charclass {
+    charclass_res * inner;
+};
+
+void ?{}( charclass & ) = void;
+void ?{}( charclass &, charclass) = void;
+charclass ?=?( charclass &, charclass) = void;
+
+void ?{}( charclass &, const string & chars);
+void ?{}( charclass &, const char * chars );
+void ?{}( charclass &, const char * chars, size_t charssize );
+void ^?{}( charclass & );
+
+int include(const string &s, const charclass &mask);
+
+int exclude(const string &s, const charclass &mask);
+
+/*
+What to do with?
+StrRet include(string &s, const charclass &mask);
+StrRet exclude(string &s, const charclass &mask);
+*/
+
+
Index: libcfa/src/containers/string_res.cfa
===================================================================
--- libcfa/src/containers/string_res.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
+++ libcfa/src/containers/string_res.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -0,0 +1,919 @@
+//
+// Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
+//
+// The contents of this file are covered under the licence agreement in the
+// file "LICENCE" distributed with Cforall.
+//
+// string_res -- variable-length, mutable run of text, with resource semantics
+//
+// Author           : Michael L. Brooks
+// Created On       : Fri Sep 03 11:00:00 2021
+// Last Modified By : Michael L. Brooks
+// Last Modified On : Fri Sep 03 11:00:00 2021
+// Update Count     : 1
+//
+
+#include "string_res.hfa"
+#include <stdlib.hfa>  // e.g. malloc
+#include <string.h>    // e.g. strlen
+
+//######################### VbyteHeap "header" #########################
+
+
+
+
+
+
+
+
+// DON'T COMMIT:
+// #define VbyteDebug
+
+
+
+
+
+#ifdef VbyteDebug
+HandleNode *HeaderPtr;
+#endif // VbyteDebug
+
+struct VbyteHeap {
+
+    int NoOfCompactions;				// number of compactions of the byte area
+    int NoOfExtensions;					// number of extensions in the size of the byte area
+    int NoOfReductions;					// number of reductions in the size of the byte area
+    
+    int InitSize;					// initial number of bytes in the byte-string area
+    int CurrSize;					// current number of bytes in the byte-string area
+    char *StartVbyte;					// pointer to the `st byte of the start of the byte-string area
+    char *EndVbyte;					// pointer to the next byte after the end of the currently used portion of byte-string area
+    void *ExtVbyte;					// pointer to the next byte after the end of the byte-string area
+
+    HandleNode Header;					// header node for handle list
+}; // VbyteHeap
+
+    
+static inline void compaction( VbyteHeap & );				// compaction of the byte area
+static inline void garbage( VbyteHeap & );				// garbage collect the byte area
+static inline void extend( VbyteHeap &, int );			// extend the size of the byte area
+static inline void reduce( VbyteHeap &, int );			// reduce the size of the byte area
+
+static inline void ?{}( VbyteHeap &, int = 1000 );
+static inline void ^?{}( VbyteHeap & );
+static inline void ByteCopy( VbyteHeap &, char *, int, int, char *, int, int ); // copy a block of bytes from one location in the heap to another
+static inline int ByteCmp( VbyteHeap &, char *, int, int, char *, int, int );	// compare 2 blocks of bytes
+static inline char *VbyteAlloc( VbyteHeap &, int );			// allocate a block bytes in the heap
+
+
+static inline void AddThisAfter( HandleNode &, HandleNode & );
+static inline void DeleteNode( HandleNode & );
+static inline void MoveThisAfter( HandleNode &, const HandleNode & );		// move current handle after parameter handle
+
+
+// Allocate the storage for the variable sized area and intialize the heap variables.
+
+static inline void ?{}( VbyteHeap & this, int Size ) with(this) {
+#ifdef VbyteDebug
+    serr | "enter:VbyteHeap::VbyteHeap, this:" | &this | " Size:" | Size;
+#endif // VbyteDebug
+    NoOfCompactions = NoOfExtensions = NoOfReductions = 0;
+    InitSize = CurrSize = Size;
+    StartVbyte = EndVbyte = alloc(CurrSize);
+    ExtVbyte = (void *)( StartVbyte + CurrSize );
+    Header.flink = Header.blink = &Header;
+#ifdef VbyteDebug
+    HeaderPtr = &Header;
+    serr | "exit:VbyteHeap::VbyteHeap, this:" | &this;
+#endif // VbyteDebug
+} // VbyteHeap
+
+
+// Release the dynamically allocated storage for the byte area.
+
+static inline void ^?{}( VbyteHeap & this ) with(this) {
+    free( StartVbyte );
+} // ~VbyteHeap
+
+
+//######################### HandleNode #########################
+
+
+// Create a handle node. The handle is not linked into the handle list.  This is the responsibilitiy of the handle
+// creator.
+
+void ?{}( HandleNode & this ) with(this) {
+#ifdef VbyteDebug
+    serr | "enter:HandleNode::HandleNode, this:" | &this;
+#endif // VbyteDebug
+    s = 0;
+    lnth = 0;
+#ifdef VbyteDebug
+    serr | "exit:HandleNode::HandleNode, this:" | &this;
+#endif // VbyteDebug
+} // HandleNode
+
+// Create a handle node. The handle is linked into the handle list at the end. This means that this handle will NOT be
+// in order by string address, but this is not a problem because a string with length zero does nothing during garbage
+// collection.
+
+void ?{}( HandleNode & this, VbyteHeap & vh ) with(this) {
+#ifdef VbyteDebug
+    serr | "enter:HandleNode::HandleNode, this:" | &this;
+#endif // VbyteDebug
+    s = 0;
+    lnth = 0;
+    AddThisAfter( this, *vh.Header.blink );
+#ifdef VbyteDebug
+    serr | "exit:HandleNode::HandleNode, this:" | &this;
+#endif // VbyteDebug
+} // HandleNode
+
+
+// Delete a node from the handle list by unchaining it from the list. If the handle node was allocated dynamically, it
+// is the responsibility of the creator to destroy it.
+
+void ^?{}( HandleNode & this ) with(this) {
+#ifdef VbyteDebug
+    serr | "enter:HandleNode::~HandleNode, this:" | & this;
+    {
+	serr | nlOff;
+	serr | " lnth:" | lnth | " s:" | (void *)s | ",\"";
+	for ( int i = 0; i < lnth; i += 1 ) {
+	    serr | s[i];
+	} // for
+	serr | "\" flink:" | flink | " blink:" | blink | nl;
+	serr | nlOn;
+    }
+#endif // VbyteDebug
+    DeleteNode( this );
+} // ~HandleNode
+
+//######################### String Resource #########################
+
+
+VbyteHeap HeapArea;
+
+VbyteHeap * DEBUG_string_heap = & HeapArea;
+
+size_t DEBUG_string_bytes_avail_until_gc( VbyteHeap * heap ) {
+    return ((char*)heap->ExtVbyte) - heap->EndVbyte;
+}
+
+const char * DEBUG_string_heap_start( VbyteHeap * heap ) {
+    return heap->StartVbyte;
+}
+
+
+// Returns the size of the string in bytes
+size_t size(const string_res &s) with(s) {
+    return Handle.lnth;
+}
+
+// Output operator
+ofstream & ?|?(ofstream &out, const string_res &s) {
+    // Store auto-newline state so it can be restored
+    bool anl = getANL$(out);
+    nlOff(out);
+    for (size_t i = 0; i < s.Handle.lnth; i++) {
+        out | s[i];
+    }
+    out | sep;
+    // Re-apply newlines after done, for chaining version
+    if (anl) nlOn(out);
+    return out;
+}
+
+void ?|?(ofstream &out, const string_res &s) {
+    // Store auto-newline state so it can be restored
+    bool anl = getANL$(out);
+    nlOff(out);
+    for (size_t i = 0; i < s.Handle.lnth; i++) {
+        // Need to re-apply on the last output operator, for whole-statement version
+        if (anl && i == s.Handle.lnth-1) nlOn(out);
+        out | s[i];
+    }
+    return out;
+}
+
+// Empty constructor
+void ?{}(string_res &s) with(s) {
+    (Handle){ HeapArea };
+    s.shareEditSet_prev = &s;
+    s.shareEditSet_next = &s;
+}
+
+// Constructor from a raw buffer and size
+void ?{}(string_res &s, const char* rhs, size_t rhslnth) with(s) {
+    (Handle){ HeapArea };
+    Handle.s = VbyteAlloc(HeapArea, rhslnth);
+    Handle.lnth = rhslnth;
+    for ( int i = 0; i < rhslnth; i += 1 ) {		// copy characters
+        Handle.s[i] = rhs[i];
+    } // for
+    s.shareEditSet_prev = &s;
+    s.shareEditSet_next = &s;
+}
+
+// String literal constructor
+void ?{}(string_res &s, const char* rhs) {
+    (s){ rhs, strlen(rhs) };
+}
+
+// General copy constructor
+void ?{}(string_res &s, const string_res & s2, StrResInitMode mode, size_t start, size_t end ) {
+
+    (s.Handle){ HeapArea };
+    s.Handle.s = s2.Handle.s + start;
+    s.Handle.lnth = end - start;
+    MoveThisAfter(s.Handle, s2.Handle );			// insert this handle after rhs handle
+    // ^ bug?  skip others at early point in string
+    
+    if (mode == COPY_VALUE) {
+        // make s alone in its shareEditSet
+        s.shareEditSet_prev = &s;
+        s.shareEditSet_next = &s;
+    } else {
+        assert( mode == SHARE_EDITS );
+
+        // s2 is logically const but not implementation const
+        string_res & s2mod = (string_res &) s2;
+
+        // insert s after s2 on shareEditSet
+        s.shareEditSet_next = s2mod.shareEditSet_next;
+        s.shareEditSet_prev = &s2mod;
+        s.shareEditSet_next->shareEditSet_prev = &s;
+        s.shareEditSet_prev->shareEditSet_next = &s;
+    }
+}
+
+void assign(string_res &this, const char* buffer, size_t bsize) {
+
+    // traverse the incumbent share-edit set (SES) to recover the range of a base string to which `this` belongs
+    string_res * shareEditSetStartPeer = & this;
+    string_res * shareEditSetEndPeer = & this;
+    for (string_res * editPeer = this.shareEditSet_next; editPeer != &this; editPeer = editPeer->shareEditSet_next) {
+        if ( editPeer->Handle.s < shareEditSetStartPeer->Handle.s ) {
+            shareEditSetStartPeer = editPeer;
+        }
+        if ( shareEditSetEndPeer->Handle.s + shareEditSetEndPeer->Handle.lnth < editPeer->Handle.s + editPeer->Handle.lnth) {
+            shareEditSetEndPeer = editPeer;
+        }
+    }
+
+    // full string is from start of shareEditSetStartPeer thru end of shareEditSetEndPeer
+    // `this` occurs in the middle of it, to be replaced
+    // build up the new text in `pasting`
+
+    string_res pasting = {
+        shareEditSetStartPeer->Handle.s,                   // start of SES
+        this.Handle.s - shareEditSetStartPeer->Handle.s }; // length of SES, before this
+    append( pasting,
+        buffer,                                            // start of replacement for this
+        bsize );                                           // length of replacement for this
+    append( pasting,
+        this.Handle.s + this.Handle.lnth,                  // start of SES after this
+        shareEditSetEndPeer->Handle.s + shareEditSetEndPeer->Handle.lnth -
+        (this.Handle.s + this.Handle.lnth) );              // length of SES, after this
+
+    // The above string building can trigger compaction.
+    // The reference points (that are arguments of the string building) may move during that building.
+    // From this point on, they are stable.
+    // So now, capture their values for use in the overlap cases, below.
+    // Do not factor these definitions with the arguments used above.
+
+    char * beforeBegin = shareEditSetStartPeer->Handle.s;
+    size_t beforeLen = this.Handle.s - beforeBegin;
+
+    char * afterBegin = this.Handle.s + this.Handle.lnth;
+    size_t afterLen = shareEditSetEndPeer->Handle.s + shareEditSetEndPeer->Handle.lnth - afterBegin;
+
+    size_t oldLnth = this.Handle.lnth;
+
+    this.Handle.s = pasting.Handle.s + beforeLen;
+    this.Handle.lnth = bsize;
+    MoveThisAfter( this.Handle, pasting.Handle );
+
+    // adjust all substring string and handle locations, and check if any substring strings are outside the new base string
+    char *limit = pasting.Handle.s + pasting.Handle.lnth;
+    for (string_res * p = this.shareEditSet_next; p != &this; p = p->shareEditSet_next) {
+        assert (p->Handle.s >= beforeBegin);
+        if ( p->Handle.s >= afterBegin ) {
+            assert ( p->Handle.s <= afterBegin + afterLen );
+            assert ( p->Handle.s + p->Handle.lnth <= afterBegin + afterLen );
+            // p starts after the edit
+            // take start and end as end-anchored
+            size_t startOffsetFromEnd = afterBegin + afterLen - p->Handle.s;
+            p->Handle.s = limit - startOffsetFromEnd;
+            // p->Handle.lnth unaffected
+        } else if ( p->Handle.s <= beforeBegin + beforeLen ) {
+            // p starts before, or at the start of, the edit
+            if ( p->Handle.s + p->Handle.lnth <= beforeBegin + beforeLen ) {
+                // p ends before the edit
+                // take end as start-anchored too
+                // p->Handle.lnth unaffected
+            } else if ( p->Handle.s + p->Handle.lnth < afterBegin ) {
+                // p ends during the edit; p does not include the last character replaced
+                // clip end of p to end at start of edit
+                p->Handle.lnth = beforeLen - ( p->Handle.s - beforeBegin );
+            } else {
+                // p ends after the edit
+                assert ( p->Handle.s + p->Handle.lnth <= afterBegin + afterLen );
+                // take end as end-anchored
+                // stretch-shrink p according to the edit
+                p->Handle.lnth += this.Handle.lnth;
+                p->Handle.lnth -= oldLnth;
+            }
+            // take start as start-anchored
+            size_t startOffsetFromStart = p->Handle.s - beforeBegin;
+            p->Handle.s = pasting.Handle.s + startOffsetFromStart;
+        } else {
+            assert ( p->Handle.s < afterBegin );
+            // p starts during the edit
+            assert( p->Handle.s + p->Handle.lnth >= beforeBegin + beforeLen );
+            if ( p->Handle.s + p->Handle.lnth < afterBegin ) {
+                // p ends during the edit; p does not include the last character replaced
+                // set p to empty string at start of edit
+                p->Handle.s = this.Handle.s;
+                p->Handle.lnth = 0;
+            } else {
+                // p includes the end of the edit
+                // clip start of p to start at end of edit
+                int charsToClip = afterBegin - p->Handle.s;
+                p->Handle.s = this.Handle.s + this.Handle.lnth;
+                p->Handle.lnth -= charsToClip;
+            }
+        }
+        MoveThisAfter( p->Handle, pasting.Handle );	// move substring handle to maintain sorted order by string position
+    }
+}
+
+void ?=?(string_res &s, const char* other) {
+    assign(s, other, strlen(other));
+}
+
+void ?=?(string_res &s, char other) {
+    assign(s, &other, 1);
+}
+
+// Copy assignment operator
+void ?=?(string_res & this, const string_res & rhs) with( this ) {
+    assign(this, rhs.Handle.s, rhs.Handle.lnth);
+}
+
+void ?=?(string_res & this, string_res & rhs) with( this ) {
+    const string_res & rhs2 = rhs;
+    this = rhs2;
+}
+
+
+// Destructor
+void ^?{}(string_res &s) with(s) {
+    // much delegated to implied ^VbyteSM
+
+    // sever s from its share-edit peers, if any (four no-ops when already solo)
+    s.shareEditSet_prev->shareEditSet_next = s.shareEditSet_next;
+    s.shareEditSet_next->shareEditSet_prev = s.shareEditSet_prev;
+    s.shareEditSet_next = &s;
+    s.shareEditSet_prev = &s;
+}
+
+
+// Returns the character at the given index
+// With unicode support, this may be different from just the byte at the given
+// offset from the start of the string.
+char ?[?](const string_res &s, size_t index) with(s) {
+    //TODO: Check if index is valid (no exceptions yet)
+    return Handle.s[index];
+}
+
+
+///////////////////////////////////////////////////////////////////
+// Concatenation
+
+void append(string_res &str1, const char * buffer, size_t bsize) {
+    size_t clnth = size(str1) + bsize;
+    if ( str1.Handle.s + size(str1) == buffer ) { // already juxtapose ?
+        // no-op
+    } else {						// must copy some text
+        if ( str1.Handle.s + size(str1) == VbyteAlloc(HeapArea, 0) ) { // str1 at end of string area ?
+            VbyteAlloc(HeapArea, bsize); // create room for 2nd part at the end of string area
+        } else {					// copy the two parts
+            char * str1oldBuf = str1.Handle.s;
+            str1.Handle.s = VbyteAlloc( HeapArea, clnth );
+            ByteCopy( HeapArea, str1.Handle.s, 0, str1.Handle.lnth, str1oldBuf, 0, str1.Handle.lnth);
+        } // if
+        ByteCopy( HeapArea, str1.Handle.s, str1.Handle.lnth, bsize, (char*)buffer, 0, (int)bsize);
+        //       VbyteHeap & this, char *Dst, int DstStart, int DstLnth, char *Src, int SrcStart, int SrcLnth 
+    } // if
+    str1.Handle.lnth = clnth;
+}
+
+void ?+=?(string_res &str1, const string_res &str2) {
+    append( str1, str2.Handle.s, str2.Handle.lnth );
+}
+
+void ?+=?(string_res &s, char other) {
+    append( s, &other, 1 );
+}
+
+void ?+=?(string_res &s, const char* other) {
+    append( s, other, strlen(other) );
+}
+
+
+
+
+//////////////////////////////////////////////////////////
+// Comparisons
+
+
+bool ?==?(const string_res &s1, const string_res &s2) {
+    return ByteCmp( HeapArea, s1.Handle.s, 0, s1.Handle.lnth, s2.Handle.s, 0, s2.Handle.lnth) == 0;
+}
+
+bool ?!=?(const string_res &s1, const string_res &s2) {
+    return !(s1 == s2);
+}
+bool ?==?(const string_res &s, const char* other) {
+    string_res sother = other;
+    return s == sother;
+}
+bool ?!=?(const string_res &s, const char* other) {
+    return !(s == other);
+}
+
+
+//////////////////////////////////////////////////////////
+// Search
+
+bool contains(const string_res &s, char ch) {
+    for (i; size(s)) {
+        if (s[i] == ch) return true;
+    }
+    return false;
+}
+
+int find(const string_res &s, char search) {
+    for (i; size(s)) {
+        if (s[i] == search) return i;
+    }
+    return size(s);
+}
+
+    /* Remaining implementations essentially ported from Sunjay's work */
+
+int find(const string_res &s, const string_res &search) {
+    return find(s, search.Handle.s, search.Handle.lnth);
+}
+
+int find(const string_res &s, const char* search) {
+    return find(s, search, strlen(search));
+}
+
+int find(const string_res &s, const char* search, size_t searchsize) {
+    // FIXME: This is a naive algorithm. We probably want to switch to someting
+    // like Boyer-Moore in the future.
+    // https://en.wikipedia.org/wiki/String_searching_algorithm
+
+    // Always find the empty string
+    if (searchsize == 0) {
+        return 0;
+    }
+
+    for (size_t i = 0; i < s.Handle.lnth; i++) {
+        size_t remaining = s.Handle.lnth - i;
+        // Never going to find the search string if the remaining string is
+        // smaller than search
+        if (remaining < searchsize) {
+            break;
+        }
+
+        bool matched = true;
+        for (size_t j = 0; j < searchsize; j++) {
+            if (search[j] != s.Handle.s[i + j]) {
+                matched = false;
+                break;
+            }
+        }
+        if (matched) {
+            return i;
+        }
+    }
+
+    return s.Handle.lnth;
+}
+
+bool includes(const string_res &s, const string_res &search) {
+    return includes(s, search.Handle.s, search.Handle.lnth);
+}
+
+bool includes(const string_res &s, const char* search) {
+    return includes(s, search, strlen(search));
+}
+
+bool includes(const string_res &s, const char* search, size_t searchsize) {
+    return find(s, search, searchsize) < s.Handle.lnth;
+}
+
+bool startsWith(const string_res &s, const string_res &prefix) {
+    return startsWith(s, prefix.Handle.s, prefix.Handle.lnth);
+}
+
+bool startsWith(const string_res &s, const char* prefix) {
+    return startsWith(s, prefix, strlen(prefix));
+}
+
+bool startsWith(const string_res &s, const char* prefix, size_t prefixsize) {
+    if (s.Handle.lnth < prefixsize) {
+        return false;
+    }
+    return memcmp(s.Handle.s, prefix, prefixsize) == 0;
+}
+
+bool endsWith(const string_res &s, const string_res &suffix) {
+    return endsWith(s, suffix.Handle.s, suffix.Handle.lnth);
+}
+
+bool endsWith(const string_res &s, const char* suffix) {
+    return endsWith(s, suffix, strlen(suffix));
+}
+
+bool endsWith(const string_res &s, const char* suffix, size_t suffixsize) {
+    if (s.Handle.lnth < suffixsize) {
+        return false;
+    }
+    // Amount to offset the bytes pointer so that we are comparing the end of s
+    // to suffix. s.bytes + offset should be the first byte to compare against suffix
+    size_t offset = s.Handle.lnth - suffixsize;
+    return memcmp(s.Handle.s + offset, suffix, suffixsize) == 0;
+}
+
+    /* Back to Mike's work */
+
+
+///////////////////////////////////////////////////////////////////////////
+// charclass, include, exclude
+
+void ?{}( charclass_res & this, const string_res & chars) {
+    (this){ chars.Handle.s, chars.Handle.lnth };
+}
+
+void ?{}( charclass_res & this, const char * chars ) {
+    (this){ chars, strlen(chars) };
+}
+
+void ?{}( charclass_res & this, const char * chars, size_t charssize ) {
+    (this.chars){ chars, charssize };
+    // now sort it ?
+}
+
+void ^?{}( charclass_res & this ) {
+    ^(this.chars){};
+}
+
+static bool test( const charclass_res & mask, char c ) {
+    // instead, use sorted char list?
+    return contains( mask.chars, c );
+}
+
+int exclude(const string_res &s, const charclass_res &mask) {
+    for (int i = 0; i < size(s); i++) {
+        if ( test(mask, s[i]) ) return i;
+    }
+    return size(s);
+}
+
+int include(const string_res &s, const charclass_res &mask) {
+    for (int i = 0; i < size(s); i++) {
+        if ( ! test(mask, s[i]) ) return i;
+    }
+    return size(s);
+}
+
+//######################### VbyteHeap "implementation" #########################
+
+
+// Add a new HandleNode node n after the current HandleNode node.
+
+static inline void AddThisAfter( HandleNode & this, HandleNode & n ) with(this) {
+#ifdef VbyteDebug
+    serr | "enter:AddThisAfter, this:" | &this | " n:" | &n;
+#endif // VbyteDebug
+    flink = n.flink;
+    blink = &n;
+    n.flink->blink = &this;
+    n.flink = &this;
+#ifdef VbyteDebug
+    {
+		serr | "HandleList:";
+		serr | nlOff;
+		for ( HandleNode *ni = HeaderPtr->flink; ni != HeaderPtr; ni = ni->flink ) {
+			serr | "\tnode:" | ni | " lnth:" | ni->lnth | " s:" | (void *)ni->s | ",\"";
+			for ( int i = 0; i < ni->lnth; i += 1 ) {
+				serr | ni->s[i];
+			} // for
+			serr | "\" flink:" | ni->flink | " blink:" | ni->blink | nl;
+		} // for
+		serr | nlOn;
+    }
+    serr | "exit:AddThisAfter";
+#endif // VbyteDebug
+} // AddThisAfter
+
+
+// Delete the current HandleNode node.
+
+static inline void DeleteNode( HandleNode & this ) with(this) {
+#ifdef VbyteDebug
+    serr | "enter:DeleteNode, this:" | &this;
+#endif // VbyteDebug
+    flink->blink = blink;
+    blink->flink = flink;
+#ifdef VbyteDebug
+    serr | "exit:DeleteNode";
+#endif // VbyteDebug
+} //  DeleteNode
+
+
+
+// Allocates specified storage for a string from byte-string area. If not enough space remains to perform the
+// allocation, the garbage collection routine is called and a second attempt is made to allocate the space. If the
+// second attempt fails, a further attempt is made to create a new, larger byte-string area.
+
+static inline char * VbyteAlloc( VbyteHeap & this, int size ) with(this) {
+#ifdef VbyteDebug
+    serr | "enter:VbyteAlloc, size:" | size;
+#endif // VbyteDebug
+    uintptr_t NoBytes;
+    char *r;
+
+    NoBytes = ( uintptr_t )EndVbyte + size;
+    if ( NoBytes > ( uintptr_t )ExtVbyte ) {		// enough room for new byte-string ?
+		garbage( this );					// firer up the garbage collector
+		NoBytes = ( uintptr_t )EndVbyte + size;		// try again
+		if ( NoBytes > ( uintptr_t )ExtVbyte ) {	// enough room for new byte-string ?
+assert( 0 && "need to implement actual growth" );
+			// extend( size );				// extend the byte-string area
+		} // if
+    } // if
+    r = EndVbyte;
+    EndVbyte += size;
+#ifdef VbyteDebug
+    serr | "exit:VbyteAlloc, r:" | (void *)r | " EndVbyte:" | (void *)EndVbyte | " ExtVbyte:" | ExtVbyte;
+#endif // VbyteDebug
+    return r;
+} // VbyteAlloc
+
+
+// Move an existing HandleNode node h somewhere after the current HandleNode node so that it is in ascending order by
+// the address in the byte string area.
+
+static inline void MoveThisAfter( HandleNode & this, const HandleNode  & h ) with(this) {
+#ifdef VbyteDebug
+    serr | "enter:MoveThisAfter, this:" | & this | " h:" | & h;
+#endif // VbyteDebug
+    if ( s < h.s ) {					// check argument values
+		// serr | "VbyteSM: Error - Cannot move byte string starting at:" | s | " after byte string starting at:"
+		//      | ( h->s ) | " and keep handles in ascending order";
+		// exit(-1 );
+		assert( 0 && "VbyteSM: Error - Cannot move byte strings as requested and keep handles in ascending order");
+    } // if
+
+    HandleNode *i;
+    for ( i = h.flink; i->s != 0 && s > ( i->s ); i = i->flink ); // find the position for this node after h
+    if ( & this != i->blink ) {
+		DeleteNode( this );
+		AddThisAfter( this, *i->blink );
+    } // if
+#ifdef VbyteDebug
+    {
+	serr | "HandleList:";
+	serr | nlOff;
+	for ( HandleNode *n = HeaderPtr->flink; n != HeaderPtr; n = n->flink ) {
+	    serr | "\tnode:" | n | " lnth:" | n->lnth | " s:" | (void *)n->s | ",\"";
+	    for ( int i = 0; i < n->lnth; i += 1 ) {
+		serr | n->s[i];
+	    } // for
+	    serr | "\" flink:" | n->flink | " blink:" | n->blink | nl;
+	} // for
+	serr | nlOn;
+    }
+    serr | "exit:MoveThisAfter";
+#endif // VbyteDebug
+} // MoveThisAfter
+
+
+
+
+
+//######################### VbyteHeap #########################
+
+// Move characters from one location in the byte-string area to another. The routine handles the following situations:
+//
+// if the |Src| > |Dst| => truncate
+// if the |Dst| > |Src| => pad Dst with blanks
+
+void ByteCopy( VbyteHeap & this, char *Dst, int DstStart, int DstLnth, char *Src, int SrcStart, int SrcLnth ) {
+    for ( int i = 0; i < DstLnth; i += 1 ) {
+      if ( i == SrcLnth ) {				// |Dst| > |Src|
+	    for ( ; i < DstLnth; i += 1 ) {		// pad Dst with blanks
+		Dst[DstStart + i] = ' ';
+	    } // for
+	    break;
+	} // exit
+	Dst[DstStart + i] = Src[SrcStart + i];
+    } // for
+} // ByteCopy
+
+// Compare two byte strings in the byte-string area. The routine returns the following values:
+//
+// 1 => Src1-byte-string > Src2-byte-string
+// 0 => Src1-byte-string = Src2-byte-string
+// -1 => Src1-byte-string < Src2-byte-string
+
+int ByteCmp( VbyteHeap & this, char *Src1, int Src1Start, int Src1Lnth, char *Src2, int Src2Start, int Src2Lnth )  with(this) {
+#ifdef VbyteDebug
+    serr | "enter:ByteCmp, Src1Start:" | Src1Start | " Src1Lnth:" | Src1Lnth | " Src2Start:" | Src2Start | " Src2Lnth:" | Src2Lnth;
+#endif // VbyteDebug
+    int cmp;
+
+    CharZip: for ( int i = 0; ; i += 1 ) {
+	if ( i == Src2Lnth - 1 ) {
+	    for ( ; ; i += 1 ) {
+		if ( i == Src1Lnth - 1 ) {
+		    cmp = 0;
+		    break CharZip;
+		} // exit
+		if ( Src1[Src1Start + i] != ' ') {
+			// SUSPECTED BUG:  this could be be why Peter got the bug report about == " "  (why is this case here at all?)
+		    cmp = 1;
+		    break CharZip;
+		} // exit
+	    } // for
+	} // exit
+	if ( i == Src1Lnth - 1 ) {
+	    for ( ; ; i += 1 ) {
+	    	if ( i == Src2Lnth - 1 ) {
+		    cmp = 0;
+		    break CharZip;
+		} // exit
+	    	if ( Src2[Src2Start + i] != ' ') {
+		    cmp = -1;
+		    break CharZip;
+		} // exit
+	    } // for
+	} // exit
+      if ( Src2[Src2Start + i] != Src1[Src1Start+ i]) {
+	    cmp = Src1[Src1Start + i] > Src2[Src2Start + i] ? 1 : -1;
+	    break CharZip;
+	} // exit
+    } // for
+#ifdef VbyteDebug
+    serr | "exit:ByteCmp, cmp:" | cmp;
+#endif // VbyteDebug
+    return cmp;
+} // ByteCmp
+
+
+// The compaction moves all of the byte strings currently in use to the beginning of the byte-string area and modifies
+// the handles to reflect the new positions of the byte strings. Compaction assumes that the handle list is in ascending
+// order by pointers into the byte-string area.  The strings associated with substrings do not have to be moved because
+// the containing string has been moved. Hence, they only require that their string pointers be adjusted.
+
+void compaction(VbyteHeap & this) with(this) {
+    HandleNode *h;
+    char *obase, *nbase, *limit;
+    
+    NoOfCompactions += 1;
+    EndVbyte = StartVbyte;
+    h = Header.flink;					// ignore header node
+    for (;;) {
+		ByteCopy( this, EndVbyte, 0, h->lnth, h->s, 0, h->lnth );
+		obase = h->s;
+		h->s = EndVbyte;
+		nbase = h->s;
+		EndVbyte += h->lnth;
+		limit = obase + h->lnth;
+		h = h->flink;
+		
+		// check if any substrings are allocated within a string
+		
+		for (;;) {
+			if ( h == &Header ) break;			// end of header list ?
+			if ( h->s >= limit ) break;			// outside of current string ?
+			h->s = nbase + (( uintptr_t )h->s - ( uintptr_t )obase );
+			h = h->flink;
+		} // for
+		if ( h == &Header ) break;			// end of header list ?
+    } // for
+} // compaction
+
+
+// Garbage determines the amount of free space left in the heap and then reduces, leave the same, or extends the size of
+// the heap.  The heap is then compacted in the existing heap or into the newly allocated heap.
+
+void garbage(VbyteHeap & this ) with(this) {
+#ifdef VbyteDebug
+    serr | "enter:garbage";
+    {
+		serr | "HandleList:";
+		for ( HandleNode *n = Header.flink; n != &Header; n = n->flink ) {
+			serr | nlOff;
+			serr | "\tnode:" | n | " lnth:" | n->lnth | " s:" | (void *)n->s | ",\"";
+			for ( int i = 0; i < n->lnth; i += 1 ) {
+				serr | n->s[i];
+			} // for
+			serr | nlOn;
+			serr | "\" flink:" | n->flink | " blink:" | n->blink;
+		} // for
+    }
+#endif // VbyteDebug
+    int AmountUsed, AmountFree;
+
+    AmountUsed = 0;
+    for ( HandleNode *i = Header.flink; i != &Header; i = i->flink ) { // calculate amount of byte area used
+		AmountUsed += i->lnth;
+    } // for
+    AmountFree = ( uintptr_t )ExtVbyte - ( uintptr_t )StartVbyte - AmountUsed;
+    
+    if ( AmountFree < ( int )( CurrSize * 0.1 )) {	// free space less than 10% ?
+
+assert( 0 && "need to implement actual growth" );
+//		extend( CurrSize );				// extend the heap
+
+			//  Peter says, "This needs work before it should be used."
+			//  } else if ( AmountFree > CurrSize / 2 ) {		// free space greater than 3 times the initial allocation ? 
+			//		reduce(( AmountFree / CurrSize - 3 ) * CurrSize ); // reduce the memory
+
+    } // if
+    compaction(this);					// compact the byte area, in the same or new heap area
+#ifdef VbyteDebug
+    {
+		serr | "HandleList:";
+		for ( HandleNode *n = Header.flink; n != &Header; n = n->flink ) {
+			serr | nlOff;
+			serr | "\tnode:" | n | " lnth:" | n->lnth | " s:" | (void *)n->s | ",\"";
+			for ( int i = 0; i < n->lnth; i += 1 ) {
+				serr | n->s[i];
+			} // for
+			serr | nlOn;
+			serr | "\" flink:" | n->flink | " blink:" | n->blink;
+		} // for
+    }
+    serr | "exit:garbage";
+#endif // VbyteDebug
+} // garbage
+
+#undef VbyteDebug
+
+//WIP
+#if 0
+
+
+// Extend the size of the byte-string area by creating a new area and copying the old area into it. The old byte-string
+// area is deleted.
+
+void VbyteHeap::extend( int size ) {
+#ifdef VbyteDebug
+    serr | "enter:extend, size:" | size;
+#endif // VbyteDebug
+    char *OldStartVbyte;
+
+    NoOfExtensions += 1;
+    OldStartVbyte = StartVbyte;				// save previous byte area
+    
+    CurrSize += size > InitSize ? size : InitSize;	// minimum extension, initial size
+    StartVbyte = EndVbyte = new char[CurrSize];
+    ExtVbyte = (void *)( StartVbyte + CurrSize );
+    compaction();					// copy from old heap to new & adjust pointers to new heap
+    delete OldStartVbyte;				// release old heap
+#ifdef VbyteDebug
+    serr | "exit:extend, CurrSize:" | CurrSize;
+#endif // VbyteDebug
+} // extend
+
+
+// Extend the size of the byte-string area by creating a new area and copying the old area into it. The old byte-string
+// area is deleted.
+
+void VbyteHeap::reduce( int size ) {
+#ifdef VbyteDebug
+    serr | "enter:reduce, size:" | size;
+#endif // VbyteDebug
+    char *OldStartVbyte;
+
+    NoOfReductions += 1;
+    OldStartVbyte = StartVbyte;				// save previous byte area
+    
+    CurrSize -= size;
+    StartVbyte = EndVbyte = new char[CurrSize];
+    ExtVbyte = (void *)( StartVbyte + CurrSize );
+    compaction();					// copy from old heap to new & adjust pointers to new heap
+    delete  OldStartVbyte;				// release old heap
+#ifdef VbyteDebug
+    serr | "exit:reduce, CurrSize:" | CurrSize;
+#endif // VbyteDebug
+} // reduce
+
+
+#endif
Index: libcfa/src/containers/string_res.hfa
===================================================================
--- libcfa/src/containers/string_res.hfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
+++ libcfa/src/containers/string_res.hfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -0,0 +1,144 @@
+//
+// Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
+//
+// The contents of this file are covered under the licence agreement in the
+// file "LICENCE" distributed with Cforall.
+//
+// string_res -- variable-length, mutable run of text, with resource semantics
+//
+// Author           : Michael L. Brooks
+// Created On       : Fri Sep 03 11:00:00 2021
+// Last Modified By : Michael L. Brooks
+// Last Modified On : Fri Sep 03 11:00:00 2021
+// Update Count     : 1
+//
+
+#pragma once
+
+#include <fstream.hfa>
+
+    
+//######################### HandleNode #########################
+//private
+
+struct VbyteHeap;
+
+struct HandleNode {
+    HandleNode *flink;					// forward link
+    HandleNode *blink;					// backward link
+
+    char *s;						// pointer to byte string
+    unsigned int lnth;					// length of byte string
+}; // HandleNode
+
+void ?{}( HandleNode & );			// constructor for header node
+
+void ?{}( HandleNode &, VbyteHeap & );		// constructor for nodes in the handle list
+void ^?{}( HandleNode & );			// destructor for handle nodes
+
+extern VbyteHeap * DEBUG_string_heap;
+size_t DEBUG_string_bytes_avail_until_gc( VbyteHeap * heap );
+const char * DEBUG_string_heap_start( VbyteHeap * heap );
+
+
+//######################### String #########################
+
+// A dynamically-sized string
+struct string_res {
+    HandleNode Handle; // chars, start, end, global neighbours
+    string_res * shareEditSet_prev;
+    string_res * shareEditSet_next;
+};
+
+
+//######################### charclass_res #########################
+
+struct charclass_res {
+    string_res chars;
+};
+
+void ?{}( charclass_res & ) = void;
+void ?{}( charclass_res &, charclass_res) = void;
+charclass_res ?=?( charclass_res &, charclass_res) = void;
+void ?{}( charclass_res &, const string_res & chars);
+void ?{}( charclass_res &, const char * chars );
+void ?{}( charclass_res &, const char * chars, size_t charssize );
+void ^?{}( charclass_res & );
+
+
+//######################### String #########################
+
+// Getters
+size_t size(const string_res &s);
+
+// Constructors, Assignment Operators, Destructor
+void ?{}(string_res &s); // empty string
+void ?{}(string_res &s, const char* initial); // copy from string literal (NULL-terminated)
+void ?{}(string_res &s, const char* buffer, size_t bsize); // copy specific length from buffer
+
+void ?{}(string_res &s, const string_res & s2) = void;
+void ?{}(string_res &s, string_res & s2) = void;
+
+enum StrResInitMode { COPY_VALUE, SHARE_EDITS };
+void ?{}(string_res &s, const string_res & src, StrResInitMode, size_t start, size_t end );
+static inline void ?{}(string_res &s, const string_res & src, StrResInitMode mode ) {
+    ?{}( s, src, mode, 0, size(src));
+}
+
+void assign(string_res &s, const char* buffer, size_t bsize); // copy specific length from buffer
+void ?=?(string_res &s, const char* other); // copy from string literal (NULL-terminated)
+void ?=?(string_res &s, const string_res &other);
+void ?=?(string_res &s, string_res &other);
+void ?=?(string_res &s, char other);
+
+void ^?{}(string_res &s);
+
+// IO Operator
+ofstream & ?|?(ofstream &out, const string_res &s);
+void ?|?(ofstream &out, const string_res &s);
+
+// Concatenation
+void ?+=?(string_res &s, char other); // append a character
+void ?+=?(string_res &s, const string_res &s2); // append-concatenate to first string
+void ?+=?(string_res &s, const char* other);
+void append(string_res &s, const char* buffer, size_t bsize);
+
+// Character access
+char ?[?](const string_res &s, size_t index); // Mike changed to ret by val from Sunjay's ref, to match Peter's
+//char codePointAt(const string_res &s, size_t index); // revisit under Unicode
+
+// Comparisons
+bool ?==?(const string_res &s, const string_res &other);
+bool ?!=?(const string_res &s, const string_res &other);
+bool ?==?(const string_res &s, const char* other);
+bool ?!=?(const string_res &s, const char* other);
+
+// String search
+bool contains(const string_res &s, char ch); // single character
+
+int find(const string_res &s, char search);
+int find(const string_res &s, const string_res &search);
+int find(const string_res &s, const char* search);
+int find(const string_res &s, const char* search, size_t searchsize);
+
+bool includes(const string_res &s, const string_res &search);
+bool includes(const string_res &s, const char* search);
+bool includes(const string_res &s, const char* search, size_t searchsize);
+
+bool startsWith(const string_res &s, const string_res &prefix);
+bool startsWith(const string_res &s, const char* prefix);
+bool startsWith(const string_res &s, const char* prefix, size_t prefixsize);
+
+bool endsWith(const string_res &s, const string_res &suffix);
+bool endsWith(const string_res &s, const char* suffix);
+bool endsWith(const string_res &s, const char* suffix, size_t suffixsize);
+
+int include(const string_res &s, const charclass_res &mask);
+int exclude(const string_res &s, const charclass_res &mask);
+
+// Modifiers
+void padStart(string_res &s, size_t n);
+void padStart(string_res &s, size_t n, char padding);
+void padEnd(string_res &s, size_t n);
+void padEnd(string_res &s, size_t n, char padding);
+
Index: libcfa/src/device/cpu.cfa
===================================================================
--- libcfa/src/device/cpu.cfa	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ libcfa/src/device/cpu.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -144,5 +144,5 @@
 // Count number of cpus in the system
 static int count_cpus(void) {
-	const char * fpath = "/sys/devices/system/cpu/present";
+	const char * fpath = "/sys/devices/system/cpu/online";
 	int fd = open(fpath, 0, O_RDONLY);
 	/* paranoid */ verifyf(fd >= 0, "Could not open file %s", fpath);
@@ -422,2 +422,4 @@
 	}
 }
+
+cpu_info_t cpu_info;
Index: libcfa/src/device/cpu.hfa
===================================================================
--- libcfa/src/device/cpu.hfa	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ libcfa/src/device/cpu.hfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -30,3 +30,3 @@
 };
 
-cpu_info_t cpu_info;
+extern cpu_info_t cpu_info;
Index: libcfa/src/fstream.cfa
===================================================================
--- libcfa/src/fstream.cfa	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ libcfa/src/fstream.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -10,6 +10,6 @@
 // Created On       : Wed May 27 17:56:53 2015
 // Last Modified By : Peter A. Buhr
-// Last Modified On : Thu Jul 29 22:34:10 2021
-// Update Count     : 454
+// Last Modified On : Sun Oct 10 11:23:05 2021
+// Update Count     : 512
 //
 
@@ -28,12 +28,12 @@
 #define IO_MSG "I/O error: "
 
-void ?{}( ofstream & os, void * file ) {
-	os.file$ = file;
-	os.sepDefault$ = true;
-	os.sepOnOff$ = false;
-	os.nlOnOff$ = true;
-	os.prt$ = false;
-	os.sawNL$ = false;
-	os.acquired$ = false;
+// private
+void ?{}( ofstream & os, void * file ) with( os ) {
+	file$ = file;
+	sepDefault$ = true;
+	sepOnOff$ = false;
+	nlOnOff$ = true;
+	prt$ = false;
+	sawNL$ = false;
 	sepSetCur$( os, sepGet( os ) );
 	sepSet( os, " " );
@@ -41,30 +41,23 @@
 } // ?{}
 
-// private
-bool sepPrt$( ofstream & os ) { setNL$( os, false ); return os.sepOnOff$; }
-void sepReset$( ofstream & os ) { os.sepOnOff$ = os.sepDefault$; }
-void sepReset$( ofstream & os, bool reset ) { os.sepDefault$ = reset; os.sepOnOff$ = os.sepDefault$; }
-const char * sepGetCur$( ofstream & os ) { return os.sepCur$; }
-void sepSetCur$( ofstream & os, const char sepCur[] ) { os.sepCur$ = sepCur; }
-bool getNL$( ofstream & os ) { return os.sawNL$; }
-void setNL$( ofstream & os, bool state ) { os.sawNL$ = state; }
-bool getANL$( ofstream & os ) { return os.nlOnOff$; }
-bool getPrt$( ofstream & os ) { return os.prt$; }
-void setPrt$( ofstream & os, bool state ) { os.prt$ = state; }
+inline bool sepPrt$( ofstream & os ) { setNL$( os, false ); return os.sepOnOff$; }
+inline void sepReset$( ofstream & os ) { os.sepOnOff$ = os.sepDefault$; }
+inline void sepReset$( ofstream & os, bool reset ) { os.sepDefault$ = reset; os.sepOnOff$ = os.sepDefault$; }
+inline const char * sepGetCur$( ofstream & os ) { return os.sepCur$; }
+inline void sepSetCur$( ofstream & os, const char sepCur[] ) { os.sepCur$ = sepCur; }
+inline bool getNL$( ofstream & os ) { return os.sawNL$; }
+inline void setNL$( ofstream & os, bool state ) { os.sawNL$ = state; }
+inline bool getANL$( ofstream & os ) { return os.nlOnOff$; }
+inline bool getPrt$( ofstream & os ) { return os.prt$; }
+inline void setPrt$( ofstream & os, bool state ) { os.prt$ = state; }
+
+inline void lock( ofstream & os ) with( os ) {	lock( os.lock$ ); }
+inline void unlock( ofstream & os ) { unlock( os.lock$ ); }
 
 // public
 void ?{}( ofstream & os ) { os.file$ = 0p; }
-
-void ?{}( ofstream & os, const char name[], const char mode[] ) {
-	open( os, name, mode );
-} // ?{}
-
-void ?{}( ofstream & os, const char name[] ) {
-	open( os, name, "w" );
-} // ?{}
-
-void ^?{}( ofstream & os ) {
-	close( os );
-} // ^?{}
+void ?{}( ofstream & os, const char name[], const char mode[] ) { open( os, name, mode ); }
+void ?{}( ofstream & os, const char name[] ) { open( os, name, "w" ); }
+void ^?{}( ofstream & os ) { close( os ); }
 
 void sepOn( ofstream & os ) { os.sepOnOff$ = ! getNL$( os ); }
@@ -107,43 +100,43 @@
 	if ( &os == &exit ) exit( EXIT_FAILURE );
 	if ( &os == &abort ) abort();
-	if ( os.acquired$ ) { os.acquired$ = false; release( os ); }
 } // ends
 
-bool fail( ofstream & os ) {
-	return os.file$ == 0 || ferror( (FILE *)(os.file$) );
-} // fail
-
-void clear( ofstream & os ) {
-	clearerr( (FILE *)(os.file$) );
-} // clear
-
-int flush( ofstream & os ) {
-	return fflush( (FILE *)(os.file$) );
-} // flush
+bool fail( ofstream & os ) { return os.file$ == 0 || ferror( (FILE *)(os.file$) ); }
+void clear( ofstream & os ) { clearerr( (FILE *)(os.file$) ); }
+int flush( ofstream & os ) { return fflush( (FILE *)(os.file$) ); }
 
 void open( ofstream & os, const char name[], const char mode[] ) {
-	FILE * file = fopen( name, mode );
-	#ifdef __CFA_DEBUG__
+	FILE * file;
+    for ( cnt; 10 ) {
+		errno = 0;
+		file = fopen( name, mode );
+	  if ( file != 0p || errno != EINTR ) break;		// timer interrupt ?
+	  if ( cnt == 9 ) abort( "ofstream open EINTR spinning exceeded" );
+    } // for
 	if ( file == 0p ) {
 		throw (Open_Failure){ os };
 		// abort | IO_MSG "open output file \"" | name | "\"" | nl | strerror( errno );
 	} // if
-	#endif // __CFA_DEBUG__
-	(os){ file };
+	(os){ file };										// initialize 
 } // open
 
-void open( ofstream & os, const char name[] ) {
-	open( os, name, "w" );
-} // open
-
-void close( ofstream & os ) {
-  if ( (FILE *)(os.file$) == 0p ) return;
-  if ( (FILE *)(os.file$) == (FILE *)stdout || (FILE *)(os.file$) == (FILE *)stderr ) return;
-
-	if ( fclose( (FILE *)(os.file$) ) == EOF ) {
+void open( ofstream & os, const char name[] ) { open( os, name, "w" ); }
+
+void close( ofstream & os ) with( os ) {
+  if ( (FILE *)(file$) == 0p ) return;
+  if ( (FILE *)(file$) == (FILE *)stdout || (FILE *)(file$) == (FILE *)stderr ) return;
+
+	int ret;
+    for ( cnt; 10 ) {
+		errno = 0;
+		ret = fclose( (FILE *)(file$) );
+	  if ( ret != EOF || errno != EINTR ) break;		// timer interrupt ?
+	  if ( cnt == 9 ) abort( "ofstream open EINTR spinning exceeded" );
+    } // for
+	if ( ret == EOF ) {
 		throw (Close_Failure){ os };
 		// abort | IO_MSG "close output" | nl | strerror( errno );
 	} // if
-	os.file$ = 0p;
+	file$ = 0p;											// safety after close
 } // close
 
@@ -164,5 +157,12 @@
 	va_list args;
 	va_start( args, format );
-	int len = vfprintf( (FILE *)(os.file$), format, args );
+		
+	int len;
+    for ( cnt; 10 ) {
+		errno = 0;
+		len = vfprintf( (FILE *)(os.file$), format, args );
+	  if ( len != EOF || errno != EINTR ) break;		// timer interrupt ?
+	  if ( cnt == 9 ) abort( "ofstream fmt EINTR spinning exceeded" );
+    } // for
 	if ( len == EOF ) {
 		if ( ferror( (FILE *)(os.file$) ) ) {
@@ -177,17 +177,4 @@
 } // fmt
 
-inline void acquire( ofstream & os ) {
-	lock( os.lock$ );
-	if ( ! os.acquired$ ) os.acquired$ = true;
-	else unlock( os.lock$ );
-} // acquire
-
-inline void release( ofstream & os ) {
-	unlock( os.lock$ );
-} // release
-
-void ?{}( osacquire & acq, ofstream & os ) { &acq.os = &os; lock( os.lock$ ); }
-void ^?{}( osacquire & acq ) { release( acq.os ); }
-
 static ofstream soutFile = { (FILE *)stdout };
 ofstream & sout = soutFile, & stdout = soutFile;
@@ -207,9 +194,4 @@
 	flush( os );
 	return os;
-	// (ofstream &)(os | '\n');
-	// setPrt$( os, false );							// turn off
-	// setNL$( os, true );
-	// flush( os );
-	// return sepOff( os );							// prepare for next line
 } // nl
 
@@ -219,69 +201,63 @@
 
 // private
-void ?{}( ifstream & is, void * file ) {
-	is.file$ = file;
-	is.nlOnOff$ = false;
-	is.acquired$ = false;
-} // ?{}
+void ?{}( ifstream & is, void * file ) with( is ) {
+	file$ = file;
+	nlOnOff$ = false;
+} // ?{}
+
+bool getANL$( ifstream & os ) { return os.nlOnOff$; }
+
+inline void lock( ifstream & os ) with( os ) { lock( os.lock$ ); }
+inline void unlock( ifstream & os ) { unlock( os.lock$ ); }
 
 // public
 void ?{}( ifstream & is ) { is.file$ = 0p; }
-
-void ?{}( ifstream & is, const char name[], const char mode[] ) {
-	open( is, name, mode );
-} // ?{}
-
-void ?{}( ifstream & is, const char name[] ) {
-	open( is, name, "r" );
-} // ?{}
-
-void ^?{}( ifstream & is ) {
-	close( is );
-} // ^?{}
+void ?{}( ifstream & is, const char name[], const char mode[] ) { open( is, name, mode ); }
+void ?{}( ifstream & is, const char name[] ) { open( is, name, "r" ); }
+void ^?{}( ifstream & is ) { close( is ); }
+
+bool fail( ifstream & is ) { return is.file$ == 0p || ferror( (FILE *)(is.file$) ); }
+void clear( ifstream & is ) { clearerr( (FILE *)(is.file$) ); }
 
 void nlOn( ifstream & os ) { os.nlOnOff$ = true; }
 void nlOff( ifstream & os ) { os.nlOnOff$ = false; }
-bool getANL( ifstream & os ) { return os.nlOnOff$; }
-
-bool fail( ifstream & is ) {
-	return is.file$ == 0p || ferror( (FILE *)(is.file$) );
-} // fail
-
-void clear( ifstream & is ) {
-	clearerr( (FILE *)(is.file$) );
-} // clear
-
-void ends( ifstream & is ) {
-	if ( is.acquired$ ) { is.acquired$ = false; release( is ); }
-} // ends
-
-bool eof( ifstream & is ) {
-	return feof( (FILE *)(is.file$) );
-} // eof
+
+void ends( ifstream & is ) {}
+
+bool eof( ifstream & is ) { return feof( (FILE *)(is.file$) ) != 0; }
 
 void open( ifstream & is, const char name[], const char mode[] ) {
-	FILE * file = fopen( name, mode );
-	#ifdef __CFA_DEBUG__
+	FILE * file;
+    for ( cnt; 10 ) {
+		errno = 0;
+		file = fopen( name, mode );
+	  if ( file != 0p || errno != EINTR ) break;		// timer interrupt ?
+	  if ( cnt == 9 ) abort( "ifstream open EINTR spinning exceeded" );
+    } // for
 	if ( file == 0p ) {
 		throw (Open_Failure){ is };
 		// abort | IO_MSG "open input file \"" | name | "\"" | nl | strerror( errno );
 	} // if
-	#endif // __CFA_DEBUG__
-	is.file$ = file;
+	(is){ file };										// initialize 
 } // open
 
-void open( ifstream & is, const char name[] ) {
-	open( is, name, "r" );
-} // open
-
-void close( ifstream & is ) {
-  if ( (FILE *)(is.file$) == 0p ) return;
-  if ( (FILE *)(is.file$) == (FILE *)stdin ) return;
-
-	if ( fclose( (FILE *)(is.file$) ) == EOF ) {
+void open( ifstream & is, const char name[] ) { open( is, name, "r" ); }
+
+void close( ifstream & is ) with( is ) {
+  if ( (FILE *)(file$) == 0p ) return;
+  if ( (FILE *)(file$) == (FILE *)stdin ) return;
+
+	int ret;
+    for ( cnt; 10 ) {
+		errno = 0;
+		ret = fclose( (FILE *)(file$) );
+	  if ( ret != EOF || errno != EINTR ) break;		// timer interrupt ?
+	  if ( cnt == 9 ) abort( "ifstream close EINTR spinning exceeded" );
+    } // for
+	if ( ret == EOF ) {
 		throw (Close_Failure){ is };
 		// abort | IO_MSG "close input" | nl | strerror( errno );
 	} // if
-	is.file$ = 0p;
+	file$ = 0p;											// safety after close
 } // close
 
@@ -312,7 +288,12 @@
 int fmt( ifstream & is, const char format[], ... ) {
 	va_list args;
-
 	va_start( args, format );
-	int len = vfscanf( (FILE *)(is.file$), format, args );
+
+	int len;
+    for () {											// no check for EINTR limit waiting for keyboard input
+		errno = 0;
+		len = vfscanf( (FILE *)(is.file$), format, args );
+	  if ( len != EOF || errno != EINTR ) break;		// timer interrupt ?
+    } // for
 	if ( len == EOF ) {
 		if ( ferror( (FILE *)(is.file$) ) ) {
@@ -324,17 +305,4 @@
 } // fmt
 
-inline void acquire( ifstream & is ) {
-	lock( is.lock$ );
-	if ( ! is.acquired$ ) is.acquired$ = true;
-	else unlock( is.lock$ );
-} // acquire
-
-inline void release( ifstream & is ) {
-	unlock( is.lock$ );
-} // release
-
-void ?{}( isacquire & acq, ifstream & is ) { &acq.is = &is; lock( is.lock$ ); }
-void ^?{}( isacquire & acq ) { release( acq.is ); }
-
 static ifstream sinFile = { (FILE *)stdin };
 ifstream & sin = sinFile, & stdin = sinFile;
@@ -347,14 +315,14 @@
 
 // exception I/O constructors
-void ?{}( Open_Failure & this, ofstream & ostream ) {
-	this.virtual_table = &Open_Failure_vt;
-	this.ostream = &ostream;
-	this.tag = 1;
-} // ?{}
-
-void ?{}( Open_Failure & this, ifstream & istream ) {
-	this.virtual_table = &Open_Failure_vt;
-	this.istream = &istream;
-	this.tag = 0;
+void ?{}( Open_Failure & ex, ofstream & ostream ) with(ex) {
+	virtual_table = &Open_Failure_vt;
+	ostream = &ostream;
+	tag = 1;
+} // ?{}
+
+void ?{}( Open_Failure & ex, ifstream & istream ) with(ex) {
+	virtual_table = &Open_Failure_vt;
+	istream = &istream;
+	tag = 0;
 } // ?{}
 
@@ -363,14 +331,14 @@
 
 // exception I/O constructors
-void ?{}( Close_Failure & this, ofstream & ostream ) {
-	this.virtual_table = &Close_Failure_vt;
-	this.ostream = &ostream;
-	this.tag = 1;
-} // ?{}
-
-void ?{}( Close_Failure & this, ifstream & istream ) {
-	this.virtual_table = &Close_Failure_vt;
-	this.istream = &istream;
-	this.tag = 0;
+void ?{}( Close_Failure & ex, ofstream & ostream ) with(ex) {
+	virtual_table = &Close_Failure_vt;
+	ostream = &ostream;
+	tag = 1;
+} // ?{}
+
+void ?{}( Close_Failure & ex, ifstream & istream ) with(ex) {
+	virtual_table = &Close_Failure_vt;
+	istream = &istream;
+	tag = 0;
 } // ?{}
 
@@ -379,14 +347,14 @@
 
 // exception I/O constructors
-void ?{}( Write_Failure & this, ofstream & ostream ) {
-	this.virtual_table = &Write_Failure_vt;
-	this.ostream = &ostream;
-	this.tag = 1;
-} // ?{}
-
-void ?{}( Write_Failure & this, ifstream & istream ) {
-	this.virtual_table = &Write_Failure_vt;
-	this.istream = &istream;
-	this.tag = 0;
+void ?{}( Write_Failure & ex, ofstream & ostream ) with(ex) {
+	virtual_table = &Write_Failure_vt;
+	ostream = &ostream;
+	tag = 1;
+} // ?{}
+
+void ?{}( Write_Failure & ex, ifstream & istream ) with(ex) {
+	virtual_table = &Write_Failure_vt;
+	istream = &istream;
+	tag = 0;
 } // ?{}
 
@@ -395,14 +363,14 @@
 
 // exception I/O constructors
-void ?{}( Read_Failure & this, ofstream & ostream ) {
-	this.virtual_table = &Read_Failure_vt;
-	this.ostream = &ostream;
-	this.tag = 1;
-} // ?{}
-
-void ?{}( Read_Failure & this, ifstream & istream ) {
-	this.virtual_table = &Read_Failure_vt;
-	this.istream = &istream;
-	this.tag = 0;
+void ?{}( Read_Failure & ex, ofstream & ostream ) with(ex) {
+	virtual_table = &Read_Failure_vt;
+	ostream = &ostream;
+	tag = 1;
+} // ?{}
+
+void ?{}( Read_Failure & ex, ifstream & istream ) with(ex) {
+	virtual_table = &Read_Failure_vt;
+	istream = &istream;
+	tag = 0;
 } // ?{}
 
Index: libcfa/src/fstream.hfa
===================================================================
--- libcfa/src/fstream.hfa	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ libcfa/src/fstream.hfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -10,6 +10,6 @@
 // Created On       : Wed May 27 17:56:53 2015
 // Last Modified By : Peter A. Buhr
-// Last Modified On : Wed Jul 28 07:35:50 2021
-// Update Count     : 234
+// Last Modified On : Sun Oct 10 09:37:32 2021
+// Update Count     : 243
 //
 
@@ -36,5 +36,4 @@
 	char tupleSeparator$[ofstream_sepSize];
 	multiple_acquisition_lock lock$;
-	bool acquired$;
 }; // ofstream
 
@@ -52,4 +51,7 @@
 bool getPrt$( ofstream & );
 void setPrt$( ofstream &, bool );
+
+void lock( ofstream & );
+void unlock( ofstream & );
 
 // public
@@ -75,14 +77,6 @@
 void open( ofstream &, const char name[] );
 void close( ofstream & );
+
 ofstream & write( ofstream &, const char data[], size_t size );
-
-void acquire( ofstream & );
-void release( ofstream & );
-
-struct osacquire {
-	ofstream & os;
-};
-void ?{}( osacquire & acq, ofstream & );
-void ^?{}( osacquire & acq );
 
 void ?{}( ofstream & );
@@ -107,13 +101,17 @@
 	bool nlOnOff$;
 	multiple_acquisition_lock lock$;
-	bool acquired$;
 }; // ifstream
 
 // Satisfies istream
 
+// private
+bool getANL$( ifstream & );
+
+void lock( ifstream & );
+void unlock( ifstream & );
+
 // public
 void nlOn( ifstream & );
 void nlOff( ifstream & );
-bool getANL( ifstream & );
 void ends( ifstream & );
 int fmt( ifstream &, const char format[], ... ) __attribute__(( format(scanf, 2, 3) ));
@@ -125,15 +123,7 @@
 void open( ifstream & is, const char name[] );
 void close( ifstream & is );
+
 ifstream & read( ifstream & is, char data[], size_t size );
 ifstream & ungetc( ifstream & is, char c );
-
-void acquire( ifstream & is );
-void release( ifstream & is );
-
-struct isacquire {
-	ifstream & is;
-};
-void ?{}( isacquire & acq, ifstream & is );
-void ^?{}( isacquire & acq );
 
 void ?{}( ifstream & is );
Index: libcfa/src/heap.cfa
===================================================================
--- libcfa/src/heap.cfa	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ libcfa/src/heap.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -102,5 +102,5 @@
 } // prtUnfreed
 
-extern int cfa_main_returned;							// from bootloader.cf
+extern int cfa_main_returned;							// from interpose.cfa
 extern "C" {
 	void heapAppStart() {								// called by __cfaabi_appready_startup
Index: libcfa/src/interpose.cfa
===================================================================
--- libcfa/src/interpose.cfa	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ libcfa/src/interpose.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -94,7 +94,10 @@
 } __cabi_libc;
 
+int cfa_main_returned;
+
 extern "C" {
 	void __cfaabi_interpose_startup( void ) {
 		const char *version = 0p;
+		cfa_main_returned = 0;
 
 		preload_libgcc();
Index: libcfa/src/iostream.cfa
===================================================================
--- libcfa/src/iostream.cfa	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ libcfa/src/iostream.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -10,6 +10,6 @@
 // Created On       : Wed May 27 17:56:53 2015
 // Last Modified By : Peter A. Buhr
-// Last Modified On : Sat May 15 09:39:21 2021
-// Update Count     : 1342
+// Last Modified On : Sun Oct 10 09:28:17 2021
+// Update Count     : 1345
 //
 
@@ -398,11 +398,4 @@
 		return os;
 	} // nlOff
-} // distribution
-
-forall( ostype & | ostream( ostype ) ) {
-	ostype & acquire( ostype & os ) {
-		acquire( os );									// call void returning
-		return os;
-	} // acquire
 } // distribution
 
@@ -829,5 +822,5 @@
 			fmt( is, "%c", &temp );						// must pass pointer through varg to fmt
 			// do not overwrite parameter with newline unless appropriate
-			if ( temp != '\n' || getANL( is ) ) { c = temp; break; }
+			if ( temp != '\n' || getANL$( is ) ) { c = temp; break; }
 			if ( eof( is ) ) break;
 		} // for
@@ -1035,11 +1028,4 @@
 		return is;
 	} // nlOff
-} // distribution
-
-forall( istype & | istream( istype ) ) {
-	istype & acquire( istype & is ) {
-		acquire( is );									// call void returning
-		return is;
-	} // acquire
 } // distribution
 
Index: libcfa/src/iostream.hfa
===================================================================
--- libcfa/src/iostream.hfa	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ libcfa/src/iostream.hfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -10,6 +10,6 @@
 // Created On       : Wed May 27 17:56:53 2015
 // Last Modified By : Peter A. Buhr
-// Last Modified On : Wed Apr 28 20:37:56 2021
-// Update Count     : 401
+// Last Modified On : Sun Oct 10 10:02:07 2021
+// Update Count     : 407
 //
 
@@ -58,5 +58,4 @@
 	void close( ostype & );
 	ostype & write( ostype &, const char [], size_t );
-	void acquire( ostype & );							// concurrent access
 }; // ostream
 
@@ -142,8 +141,4 @@
 	ostype & nlOn( ostype & );
 	ostype & nlOff( ostype & );
-} // distribution
-
-forall( ostype & | ostream( ostype ) ) {
-	ostype & acquire( ostype & );
 } // distribution
 
@@ -296,8 +291,9 @@
 
 trait basic_istream( istype & ) {
-	bool getANL( istype & );							// get scan newline (on/off)
+	// private
+	bool getANL$( istype & );							// get scan newline (on/off)
+	// public
 	void nlOn( istype & );								// read newline
 	void nlOff( istype & );								// scan newline
-
 	void ends( istype & os );							// end of output statement
 	int fmt( istype &, const char format[], ... ) __attribute__(( format(scanf, 2, 3) ));
@@ -312,5 +308,4 @@
 	void close( istype & is );
 	istype & read( istype &, char [], size_t );
-	void acquire( istype & );							// concurrent access
 }; // istream
 
@@ -379,8 +374,4 @@
 } // distribution
 
-forall( istype & | istream( istype ) ) {
-	istype & acquire( istype & );
-} // distribution
-
 // *********************************** manipulators ***********************************
 
Index: libcfa/src/memory.cfa
===================================================================
--- libcfa/src/memory.cfa	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ libcfa/src/memory.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -155,4 +155,11 @@
 
 forall(T &)
+T * release(unique_ptr(T) & this) {
+	T * data = this.data;
+	this.data = 0p;
+	return data;
+}
+
+forall(T &)
 int ?==?(unique_ptr(T) const & this, unique_ptr(T) const & that) {
 	return this.data == that.data;
Index: libcfa/src/memory.hfa
===================================================================
--- libcfa/src/memory.hfa	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ libcfa/src/memory.hfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -94,4 +94,7 @@
 
 forall(T &)
+T * release(unique_ptr(T) & this);
+
+forall(T &)
 int ?==?(unique_ptr(T) const & this, unique_ptr(T) const & that);
 forall(T &)
Index: libcfa/src/parseconfig.cfa
===================================================================
--- libcfa/src/parseconfig.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
+++ libcfa/src/parseconfig.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -0,0 +1,230 @@
+#include <fstream.hfa>
+#include <parseargs.hfa>
+#include <stdlib.hfa>
+#include <string.h>
+#include "parseconfig.hfa"
+
+
+// *********************************** exceptions ***********************************
+
+
+// TODO: Add names of missing config entries to exception (see further below)
+static vtable(Missing_Config_Entries) Missing_Config_Entries_vt;
+
+[ void ] ?{}( & Missing_Config_Entries this, unsigned int num_missing ) {
+	this.virtual_table = &Missing_Config_Entries_vt;
+	this.num_missing = num_missing;
+}
+
+// TODO: use string interface when it's ready (and implement exception msg protocol)
+[ void ] msg( * Missing_Config_Entries ex ) {
+	serr | nlOff;
+	serr | "The config file is missing " | ex->num_missing;
+	serr | nlOn;
+	if ( ex->num_missing == 1 ) {
+		serr | " entry.";
+	} else {
+		serr | " entries.";
+	}
+} // msg
+
+
+static vtable(Parse_Failure) Parse_Failure_vt;
+
+[ void ] ?{}( & Parse_Failure this, [] char failed_key, [] char failed_value ) {
+	this.virtual_table = &Parse_Failure_vt;
+
+	this.failed_key = alloc( strlen( failed_key ) );
+	this.failed_value = alloc( strlen( failed_value ) );
+	strcpy( this.failed_key, failed_key );
+	strcpy( this.failed_value, failed_value );
+}
+
+[ void ] ^?{}( & Parse_Failure this ) with ( this ) {
+	free( failed_key );
+	free( failed_value );
+}
+
+// TODO: use string interface when it's ready (and implement exception msg protocol)
+[ void ] msg( * Parse_Failure ex ) {
+	serr | "Config entry " | ex->failed_key | " could not be parsed. It has value " | ex->failed_value | ".";
+}
+
+
+static vtable(Validation_Failure) Validation_Failure_vt;
+
+[ void ] ?{}( & Validation_Failure this, [] char failed_key, [] char failed_value ) {
+	this.virtual_table = &Validation_Failure_vt;
+
+	this.failed_key = alloc( strlen( failed_key ) );
+	this.failed_value = alloc( strlen( failed_value ) );
+	strcpy( this.failed_key, failed_key );
+	strcpy( this.failed_value, failed_value );
+}
+
+[ void ] ^?{}( & Validation_Failure this ) with ( this ) {
+	free( failed_key );
+	free( failed_value );
+}
+
+// TODO: use string interface when it's ready (and implement exception msg protocol)
+[ void ] msg( * Validation_Failure ex ) {
+	serr | "Config entry " | ex->failed_key | " could not be validated. It has value " | ex->failed_value | ".";
+}
+
+
+// *********************************** main code ***********************************
+
+
+[ void ] ?{}( & KVPairs kvp ) with ( kvp ) {				// default constructor
+	size = 0; max_size = 0; data = 0p;
+}
+
+[ void ] ?{}( & KVPairs kvp, size_t size ) { 				// initialization
+	kvp.[ size, max_size ] = [ 0, size ];
+	kvp.data = alloc( size );
+}
+
+[ void ] ^?{}( & KVPairs kvp ) with ( kvp ) {				// destructor
+	for ( i; size ) free( data[i] );
+	free( data );
+	size = 0; max_size = 0; data = 0p;
+}
+
+[ void ] add_kv_pair( & KVPairs kv_pairs, [] char key, [] char value ) with ( kv_pairs ) {
+	if ( max_size == 0 ) {
+		max_size = 1;
+		data = alloc( max_size );
+	} else if ( size == max_size ) {
+		max_size *= 2;
+		data = alloc( max_size, data`realloc );
+	}
+
+	data[size].0 = alloc( strlen( key ) );
+	data[size].1 = alloc( strlen( value ) );
+	strcpy( data[size].0, key );
+	strcpy( data[size].1, value );
+	++size;
+} // add_kv_pair
+
+
+[ bool ] comments( & ifstream in, [] char name ) {
+	while () {
+		in | name;
+	  if ( eof( in ) ) return true;
+	  if ( name[0] != '#' ) return false;
+		in | nl;									// ignore remainder of line
+	} // while
+} // comments
+
+// Parse configuration from a file formatted in tabular (CS 343) style
+[ * KVPairs ] parse_tabular_config_format( [] const char config_file, size_t num_entries ) {
+	// TODO: Change this to a unique_ptr when we fully support returning them (move semantics)
+	* KVPairs kv_pairs = new( num_entries );
+
+	ifstream in;
+	try {
+		open( in, config_file );					// open the configuration file for input
+
+		[64] char key;
+		[256] char value;
+
+		while () {									// parameter names can appear in any order
+		  	// NOTE: Must add check to see if already read in value for this key,
+			// once we switch to using hash table as intermediate storage
+		  if ( comments( in, key ) ) break;			// eof ?
+			in | value;
+
+			add_kv_pair( *kv_pairs, key, value );
+
+		  if ( eof( in ) ) break;
+			in | nl;								// ignore remainder of line
+		} // for
+	} catch( Open_Failure * ex; ex->istream == &in ) {
+		delete( kv_pairs );
+		throw *ex;
+	} // try
+	close( in );
+
+	return kv_pairs;
+} // parse_tabular_config_format
+
+// Parse configuration values from intermediate format
+[ void ] parse_config(
+		[] const char config_file,
+		[] config_entry entries,
+		size_t num_entries,
+		KVPairs * (*parser)(const char [], size_t)
+) {
+	* KVPairs kv_pairs = parser( config_file, num_entries );
+
+	int entries_so_far = 0;
+	for ( i; kv_pairs->size ) {
+	  if ( entries_so_far == num_entries ) break;
+
+		char * src_key, * src_value;
+		[ src_key, src_value ] = kv_pairs->data[i];
+
+		for ( j; num_entries ) {
+		  if ( strcmp( src_key, entries[j].key ) != 0 ) continue;
+		  	// Parse the data
+		  	if ( !entries[j].parse( src_value, entries[j].variable ) ) {
+				* Parse_Failure ex = new( src_key, src_value );
+				delete( kv_pairs );
+				throw *ex;
+			}
+
+			// Validate the data
+			if ( !entries[j].validate( entries[j].variable ) ) {
+				* Validation_Failure ex = new( src_key, src_value );
+				delete( kv_pairs );
+				throw *ex;
+			}
+
+			++entries_so_far;
+
+			break;
+		}
+	}
+	// TODO: Once we get vector2+hash_table, we can more easily add the missing config keys to this error
+	if ( entries_so_far < num_entries ) {
+		delete( kv_pairs );
+		throw (Missing_Config_Entries){ num_entries - entries_so_far };
+	}
+
+	delete( kv_pairs );
+} // parse_config
+
+
+// *********************************** validation ***********************************
+
+
+forall(T | Relational( T ))
+[ bool ] is_nonnegative( & T value ) {
+	T zero_val = 0;
+	return value >= zero_val;
+}
+
+forall(T | Relational( T ))
+[ bool ] is_positive( & T value ) {
+	T zero_val = 0;
+	return value > zero_val;
+}
+
+forall(T | Relational( T ))
+[ bool ] is_nonpositive( & T value ) {
+	T zero_val = 0;
+	return value <= zero_val;
+}
+
+forall(T | Relational( T ))
+[ bool ] is_negative( & T value ) {
+	T zero_val = 0;
+	return value < zero_val;
+}
+
+
+// Local Variables: //
+// tab-width: 4 //
+// compile-command: "cfa parseconfig.cfa" //
+// End: //
Index: libcfa/src/parseconfig.hfa
===================================================================
--- libcfa/src/parseconfig.hfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
+++ libcfa/src/parseconfig.hfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -0,0 +1,125 @@
+#pragma once
+
+#include <math.trait.hfa>
+
+
+// *********************************** initial declarations ***********************************
+
+
+struct config_entry {
+	const char * key;
+	void * variable;
+	bool (*parse)( const char *, void * );
+	bool (*validate)( void * );
+};
+
+bool null_validator( void * ) { return true; }
+
+static inline void ?{}( config_entry & this ) {}
+
+forall(T & | { bool parse( const char *, T & ); })
+static inline void ?{}( config_entry & this, const char * key, T & variable ) {
+	this.key      = key;
+	this.variable = (void *)&variable;
+	this.parse    = (bool (*)(const char *, void *))(bool (*)(const char *, T &))parse;
+	this.validate = null_validator;
+}
+
+forall(T & | { bool parse( const char *, T & ); })
+static inline void ?{}( config_entry & this, const char * key, T & variable, bool (*validate)(T &) ) {
+	this.key      = key;
+	this.variable = (void *)&variable;
+	this.parse    = (bool (*)(const char *, void *))(bool (*)(const char *, T &))parse;
+	this.validate = (bool (*)(void *))(bool (*)(T &))validate;
+}
+
+forall(T &)
+static inline void ?{}( config_entry & this, const char * key, T & variable, bool (*parse)(const char *, T &) ) {
+	this.key      = key;
+	this.variable = (void *)&variable;
+	this.parse    = (bool (*)(const char *, void *))(bool (*)(const char *, T &))parse;
+	this.validate = null_validator;
+}
+
+forall(T &)
+static inline void ?{}( config_entry & this, const char * key, T & variable, bool (*parse)(const char *, T &), bool (*validate)(T &) ) {
+	this.key      = key;
+	this.variable = (void *)&variable;
+	this.parse    = (bool (*)(const char *, void *))(bool (*)(const char *, T &))parse;
+	this.validate = (bool (*)(void *))(bool (*)(T &))validate;
+}
+
+// TODO: Replace KVPairs with vector2 when it's fully functional
+struct KVPairs {
+	size_t size, max_size;
+	* [ * char, * char ] data;
+};
+
+[ void ] add_kv_pair( & KVPairs kv_pairs, [] char key, [] char value );
+
+
+// *********************************** exceptions ***********************************
+
+
+exception Missing_Config_Entries {
+	unsigned int num_missing;
+};
+
+[ void ] msg( * Missing_Config_Entries ex );
+
+exception Parse_Failure {
+	* char failed_key;
+	* char failed_value;
+};
+
+[ void ] msg( * Parse_Failure ex );
+
+exception Validation_Failure {
+	* char failed_key;
+	* char failed_value;
+};
+
+[ void ] msg( * Validation_Failure ex );
+
+
+// *********************************** main code ***********************************
+
+
+[ * KVPairs ] parse_tabular_config_format( [] const char config_file, size_t num_entries );
+
+[ void ] parse_config(
+	[] const char config_file,
+	[] config_entry entries,
+	size_t num_entries,
+	KVPairs * (*parser)(const char [], size_t)  // TODO: add sensible default parser when resolver bug is fixed
+);
+
+bool parse( const char *, const char * & );
+bool parse( const char *, int & );
+bool parse( const char *, unsigned & );
+bool parse( const char *, unsigned long & );
+bool parse( const char *, unsigned long long & );
+bool parse( const char *, float & );
+bool parse( const char *, double & );
+
+
+// *********************************** validation ***********************************
+
+
+forall(T | Relational( T ))
+[ bool ] is_nonnegative( & T );
+
+forall(T | Relational( T ))
+[ bool ] is_positive( & T );
+
+forall(T | Relational( T ))
+[ bool ] is_nonpositive( & T );
+
+forall(T | Relational( T ))
+[ bool ] is_negative( & T );
+
+
+// Local Variables: //
+// mode: c //
+// tab-width: 4 //
+// End: //
Index: libcfa/src/strstream.cfa
===================================================================
--- libcfa/src/strstream.cfa	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ libcfa/src/strstream.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -10,9 +10,10 @@
 // Created On       : Thu Apr 22 22:24:35 2021
 // Last Modified By : Peter A. Buhr
-// Last Modified On : Tue Apr 27 20:59:53 2021
-// Update Count     : 78
+// Last Modified On : Sun Oct 10 16:13:20 2021
+// Update Count     : 101
 // 
 
 #include "strstream.hfa"
+#include "fstream.hfa"									// abort
 
 #include <stdio.h>										// vsnprintf
@@ -30,14 +31,14 @@
 
 // private
-bool sepPrt$( ostrstream & os ) { setNL$( os, false ); return os.sepOnOff$; }
-void sepReset$( ostrstream & os ) { os.sepOnOff$ = os.sepDefault$; }
-void sepReset$( ostrstream & os, bool reset ) { os.sepDefault$ = reset; os.sepOnOff$ = os.sepDefault$; }
-const char * sepGetCur$( ostrstream & os ) { return os.sepCur$; }
-void sepSetCur$( ostrstream & os, const char sepCur[] ) { os.sepCur$ = sepCur; }
-bool getNL$( ostrstream & os ) { return os.sawNL$; }
-void setNL$( ostrstream & os, bool state ) { os.sawNL$ = state; }
-bool getANL$( ostrstream & os ) { return os.nlOnOff$; }
-bool getPrt$( ostrstream & os ) { return os.prt$; }
-void setPrt$( ostrstream & os, bool state ) { os.prt$ = state; }
+inline bool sepPrt$( ostrstream & os ) { setNL$( os, false ); return os.sepOnOff$; }
+inline void sepReset$( ostrstream & os ) { os.sepOnOff$ = os.sepDefault$; }
+inline void sepReset$( ostrstream & os, bool reset ) { os.sepDefault$ = reset; os.sepOnOff$ = os.sepDefault$; }
+inline const char * sepGetCur$( ostrstream & os ) { return os.sepCur$; }
+inline void sepSetCur$( ostrstream & os, const char sepCur[] ) { os.sepCur$ = sepCur; }
+inline bool getNL$( ostrstream & os ) { return os.sawNL$; }
+inline void setNL$( ostrstream & os, bool state ) { os.sawNL$ = state; }
+inline bool getANL$( ostrstream & os ) { return os.nlOnOff$; }
+inline bool getPrt$( ostrstream & os ) { return os.prt$; }
+inline void setPrt$( ostrstream & os, bool state ) { os.prt$ = state; }
 
 // public
@@ -128,4 +129,6 @@
 // *********************************** istrstream ***********************************
 
+// private
+bool getANL$( istrstream & is ) { return is.nlOnOff$; }
 
 // public
@@ -136,14 +139,27 @@
 } // ?{}
 
-bool getANL( istrstream & is ) { return is.nlOnOff$; }
 void nlOn( istrstream & is ) { is.nlOnOff$ = true; }
 void nlOff( istrstream & is ) { is.nlOnOff$ = false; }
 
-void ends( istrstream & is ) {
-} // ends
+void ends( istrstream & is ) {}
+bool eof( istrstream & is ) { return false; }
 
-int eof( istrstream & is ) {
-	return 0;
-} // eof
+int fmt( istrstream & is, const char format[], ... ) with(is) {
+	va_list args;
+	va_start( args, format );
+	// THIS DOES NOT WORK BECAUSE VSSCANF RETURNS NUMBER OF VALUES READ VERSUS BUFFER POSITION SCANNED.
+	int len = vsscanf( buf$ + cursor$, format, args );
+	va_end( args );
+	if ( len == EOF ) {
+		abort | IO_MSG "invalid read";
+	} // if
+	// SKULLDUGGERY: This hack skips over characters read by vsscanf by moving to the next whitespace but it does not
+	// handle C reads with wdi manipulators that leave the cursor at a non-whitespace character.
+	for ( ; buf$[cursor$] != ' ' && buf$[cursor$] != '\t' && buf$[cursor$] != '\0'; cursor$ += 1 ) {
+		//printf( "X \'%c\'\n", buf$[cursor$] );
+	} // for
+	if ( buf$[cursor$] != '\0' ) cursor$ += 1;	// advance to whitespace
+	return len;
+} // fmt
 
 istrstream &ungetc( istrstream & is, char c ) {
@@ -154,18 +170,4 @@
 } // ungetc
 
-int fmt( istrstream & is, const char format[], ... ) {
-	va_list args;
-	va_start( args, format );
-	// This does not work because vsscanf does not return buffer position.
-	int len = vsscanf( is.buf$ + is.cursor$, format, args );
-	va_end( args );
-	if ( len == EOF ) {
-		int j;
-		printf( "X %d%n\n", len, &j );
-	} // if
-	is.cursor$ += len;
-	return len;
-} // fmt
-
 // Local Variables: //
 // tab-width: 4 //
Index: libcfa/src/strstream.hfa
===================================================================
--- libcfa/src/strstream.hfa	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ libcfa/src/strstream.hfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -10,6 +10,6 @@
 // Created On       : Thu Apr 22 22:20:59 2021
 // Last Modified By : Peter A. Buhr
-// Last Modified On : Tue Apr 27 20:58:50 2021
-// Update Count     : 41
+// Last Modified On : Sun Oct 10 10:14:22 2021
+// Update Count     : 47
 // 
 
@@ -85,14 +85,17 @@
 // Satisfies basic_istream
 
+// private
+bool getANL$( istrstream & );
+
 // public
-bool getANL( istrstream & );
 void nlOn( istrstream & );
 void nlOff( istrstream & );
 void ends( istrstream & );
+
 int fmt( istrstream &, const char format[], ... ) __attribute__(( format(scanf, 2, 3) ));
-istrstream & ungetc( istrstream & is, char c );
-int eof( istrstream & is );
+istrstream & ungetc( istrstream &, char );
+bool eof( istrstream & );
 
-void ?{}( istrstream & is, char buf[] );
+void ?{}( istrstream &, char buf[] );
 
 // Local Variables: //
Index: src/AST/Decl.hpp
===================================================================
--- src/AST/Decl.hpp	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ src/AST/Decl.hpp	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -131,4 +131,5 @@
 	// declared type, derived from parameter declarations
 	ptr<FunctionType> type;
+	/// Null for the forward declaration of a function.
 	ptr<CompoundStmt> stmts;
 	std::vector< ptr<Expr> > withExprs;
Index: src/AST/Pass.hpp
===================================================================
--- src/AST/Pass.hpp	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ src/AST/Pass.hpp	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -348,9 +348,11 @@
 
 	/// When this node is finished being visited, restore the value of a variable
+	/// You may assign to the return value to set the new value in the same statement.
 	template< typename T >
-	void GuardValue( T& val ) {
+	T& GuardValue( T& val ) {
 		at_cleanup( [ val ]( void * newVal ) {
 			* static_cast< T * >( newVal ) = val;
 		}, static_cast< void * >( & val ) );
+		return val;
 	}
 
@@ -394,4 +396,14 @@
 };
 
+/// Used to get a pointer to the wrapping TranslationUnit.
+struct WithConstTranslationUnit {
+	const TranslationUnit * translationUnit = nullptr;
+
+	const TranslationUnit & transUnit() const {
+		assertf( translationUnit, "WithConstTranslationUnit not set-up." );
+		return *translationUnit;
+	}
+};
+
 }
 
Index: src/AST/Pass.impl.hpp
===================================================================
--- src/AST/Pass.impl.hpp	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ src/AST/Pass.impl.hpp	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -420,5 +420,11 @@
 template< typename core_t >
 inline void ast::accept_all( ast::TranslationUnit & unit, ast::Pass< core_t > & visitor ) {
-	return ast::accept_all( unit.decls, visitor );
+	if ( auto ptr = __pass::translation_unit::get_cptr( visitor.core, 0 ) ) {
+		ValueGuard<const TranslationUnit *> guard( *ptr );
+		*ptr = &unit;
+		return ast::accept_all( unit.decls, visitor );
+	} else {
+		return ast::accept_all( unit.decls, visitor );
+	}
 }
 
Index: src/AST/Pass.proto.hpp
===================================================================
--- src/AST/Pass.proto.hpp	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ src/AST/Pass.proto.hpp	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -426,4 +426,18 @@
 	} // namespace forall
 
+	// For passes that need access to the global context. Sreaches `translationUnit`
+	namespace translation_unit {
+		template<typename core_t>
+		static inline auto get_cptr( core_t & core, int )
+				-> decltype( &core.translationUnit ) {
+			return &core.translationUnit;
+		}
+
+		template<typename core_t>
+		static inline const TranslationUnit ** get_cptr( core_t &, long ) {
+			return nullptr;
+		}
+	}
+
 	template<typename core_t>
 	static inline auto get_result( core_t & core, char ) -> decltype( core.result() ) {
Index: src/AST/Stmt.hpp
===================================================================
--- src/AST/Stmt.hpp	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ src/AST/Stmt.hpp	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -175,4 +175,5 @@
 class CaseStmt final : public Stmt {
 public:
+	/// Null for the default label.
 	ptr<Expr> cond;
 	std::vector<ptr<Stmt>> stmts;
Index: src/AST/TranslationUnit.hpp
===================================================================
--- src/AST/TranslationUnit.hpp	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ src/AST/TranslationUnit.hpp	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -26,8 +26,8 @@
 	std::list< ptr< Decl > > decls;
 
-	struct Globals {
+	struct Global {
 		std::map< UniqueId, Decl * > idMap;
 
-		const Type * sizeType;
+		ptr<Type> sizeType;
 		const FunctionDecl * dereference;
 		const StructDecl * dtorStruct;
Index: src/AST/porting.md
===================================================================
--- src/AST/porting.md	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ src/AST/porting.md	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -98,4 +98,5 @@
 	* `Initializer` => `ast::Init`
     * `Statement` => `ast::Stmt`
+    * `ReferenceToType` => `ast::BaseInstType`
 	* any field names should follow a similar renaming
   * because they don't really belong to `Type` (and for consistency with `Linkage::Spec`):
Index: src/CodeGen/FixMain.cc
===================================================================
--- src/CodeGen/FixMain.cc	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ src/CodeGen/FixMain.cc	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -22,4 +22,7 @@
 #include <string>                  // for operator<<
 
+#include "AST/Decl.hpp"
+#include "AST/Type.hpp"
+#include "Common/PassVisitor.h"
 #include "Common/SemanticError.h"  // for SemanticError
 #include "CodeGen/GenType.h"       // for GenType
@@ -29,6 +32,23 @@
 
 namespace CodeGen {
+
+namespace {
+
+struct FindMainCore {
+	FunctionDecl * main_signature = nullptr;
+
+	void previsit( FunctionDecl * decl ) {
+		if ( FixMain::isMain( decl ) ) {
+			if ( main_signature ) {
+				SemanticError( decl, "Multiple definition of main routine\n" );
+			}
+			main_signature = decl;
+		}
+	}
+};
+
+}
+
 	bool FixMain::replace_main = false;
-	std::unique_ptr<FunctionDecl> FixMain::main_signature = nullptr;
 
 	template<typename container>
@@ -37,16 +57,13 @@
 	}
 
-	void FixMain::registerMain(FunctionDecl* functionDecl)
-	{
-		if(main_signature) {
-			SemanticError(functionDecl, "Multiple definition of main routine\n");
-		}
-		main_signature.reset( functionDecl->clone() );
-	}
+	void FixMain::fix( std::list< Declaration * > & translationUnit,
+			std::ostream &os, const char* bootloader_filename ) {
+		PassVisitor< FindMainCore > main_finder;
+		acceptAll( translationUnit, main_finder );
+		FunctionDecl * main_signature = main_finder.pass.main_signature;
 
-	void FixMain::fix(std::ostream &os, const char* bootloader_filename) {
 		if( main_signature ) {
 			os << "static inline int invoke_main(int argc, char* argv[], char* envp[]) { (void)argc; (void)argv; (void)envp; return ";
-			main_signature->mangleName = SymTab::Mangler::mangle(main_signature.get());
+			main_signature->mangleName = SymTab::Mangler::mangle(main_signature);
 
 			os << main_signature->get_scopedMangleName() << "(";
@@ -65,3 +82,72 @@
 		}
 	}
+
+namespace {
+
+ObjectDecl * signedIntObj() {
+	return new ObjectDecl(
+		"", Type::StorageClasses(), LinkageSpec::Cforall, 0,
+		new BasicType( Type::Qualifiers(), BasicType::SignedInt ), nullptr );
+}
+
+ObjectDecl * charStarObj() {
+	return new ObjectDecl(
+		"", Type::StorageClasses(), LinkageSpec::Cforall, 0,
+		new PointerType( Type::Qualifiers(),
+			new PointerType( Type::Qualifiers(),
+				new BasicType( Type::Qualifiers(), BasicType::Char ) ) ),
+		nullptr );
+}
+
+std::string create_mangled_main_function_name( FunctionType * function_type ) {
+	std::unique_ptr<FunctionDecl> decl( new FunctionDecl(
+		"main", Type::StorageClasses(), LinkageSpec::Cforall,
+		function_type, nullptr ) );
+	return SymTab::Mangler::mangle( decl.get() );
+}
+
+std::string mangled_0_argument_main() {
+	FunctionType* main_type = new FunctionType( Type::Qualifiers(), true );
+	main_type->get_returnVals().push_back( signedIntObj() );
+	return create_mangled_main_function_name( main_type );
+}
+
+std::string mangled_2_argument_main() {
+	FunctionType* main_type = new FunctionType( Type::Qualifiers(), false );
+	main_type->get_returnVals().push_back( signedIntObj() );
+	main_type->get_parameters().push_back( signedIntObj() );
+	main_type->get_parameters().push_back( charStarObj() );
+	return create_mangled_main_function_name( main_type );
+}
+
+bool is_main( const std::string & mangled_name ) {
+	// This breaks if you move it out of the function.
+	static const std::string mangled_mains[] = {
+		mangled_0_argument_main(),
+		mangled_2_argument_main(),
+		//mangled_3_argument_main(),
+	};
+
+	for ( auto main_name : mangled_mains ) {
+		if ( main_name == mangled_name ) return true;
+	}
+	return false;
+}
+
+} // namespace
+
+bool FixMain::isMain( FunctionDecl * decl ) {
+	if ( std::string("main") != decl->name ) {
+		return false;
+	}
+	return is_main( SymTab::Mangler::mangle( decl, true, true ) );
+}
+
+bool FixMain::isMain( const ast::FunctionDecl * decl ) {
+	if ( std::string("main") != decl->name ) {
+		return false;
+	}
+	return is_main( Mangle::mangle( decl, Mangle::Type ) );
+}
+
 };
Index: src/CodeGen/FixMain.h
===================================================================
--- src/CodeGen/FixMain.h	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ src/CodeGen/FixMain.h	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -9,7 +9,7 @@
 // Author           : Thierry Delisle
 // Created On       : Thr Jan 12 14:11:09 2017
-// Last Modified By : Peter A. Buhr
-// Last Modified On : Sun Feb 16 03:24:32 2020
-// Update Count     : 5
+// Last Modified By : Andrew Beach
+// Last Modified On : Fri Oct 29 16:20:00 2021
+// Update Count     : 8
 //
 
@@ -18,27 +18,35 @@
 #include <iosfwd>
 #include <memory>
+#include <list>
 
 #include "SynTree/LinkageSpec.h"
 
+class Declaration;
 class FunctionDecl;
+namespace ast {
+	class FunctionDecl;
+}
 
 namespace CodeGen {
-	class FixMain {
-	  public :
-		static inline LinkageSpec::Spec mainLinkage() {
-			return replace_main ? LinkageSpec::Cforall : LinkageSpec::C;
-		}
-		
-		static inline void setReplaceMain(bool val) {
-			replace_main = val;
-		}
 
-		static void registerMain(FunctionDecl* val);
+class FixMain {
+public :
+	static inline LinkageSpec::Spec mainLinkage() {
+		return replace_main ? LinkageSpec::Cforall : LinkageSpec::C;
+	}
 
-		static void fix(std::ostream &os, const char* bootloader_filename);
+	static inline void setReplaceMain(bool val) {
+		replace_main = val;
+	}
 
-	  private:
-  		static bool replace_main;
-		static std::unique_ptr<FunctionDecl> main_signature;
-	};
+	static bool isMain(FunctionDecl* decl);
+	static bool isMain(const ast::FunctionDecl * decl);
+
+	static void fix( std::list< Declaration * > & decls,
+			std::ostream &os, const char* bootloader_filename );
+
+private:
+	static bool replace_main;
+};
+
 } // namespace CodeGen
Index: src/CodeGen/FixNames.cc
===================================================================
--- src/CodeGen/FixNames.cc	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ src/CodeGen/FixNames.cc	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -9,7 +9,7 @@
 // Author           : Richard C. Bilson
 // Created On       : Mon May 18 07:44:20 2015
-// Last Modified By : Peter A. Buhr
-// Last Modified On : Fri Dec 13 23:39:14 2019
-// Update Count     : 21
+// Last Modified By : Andrew Beach
+// Last Modified On : Fri Oct 29 15:49:00 2021
+// Update Count     : 23
 //
 
@@ -19,4 +19,7 @@
 #include <string>                  // for string, operator!=, operator==
 
+#include "AST/Chain.hpp"
+#include "AST/Expr.hpp"
+#include "AST/Pass.hpp"
 #include "Common/PassVisitor.h"
 #include "Common/SemanticError.h"  // for SemanticError
@@ -46,53 +49,4 @@
 	};
 
-	std::string mangle_main() {
-		FunctionType* main_type;
-		std::unique_ptr<FunctionDecl> mainDecl { new FunctionDecl( "main", Type::StorageClasses(), LinkageSpec::Cforall,
-																   main_type = new FunctionType( Type::Qualifiers(), true ), nullptr )
-				};
-		main_type->get_returnVals().push_back(
-			new ObjectDecl( "", Type::StorageClasses(), LinkageSpec::Cforall, 0, new BasicType( Type::Qualifiers(), BasicType::SignedInt ), nullptr )
-		);
-
-		auto && name = SymTab::Mangler::mangle( mainDecl.get() );
-		// std::cerr << name << std::endl;
-		return std::move(name);
-	}
-	std::string mangle_main_args() {
-		FunctionType* main_type;
-		std::unique_ptr<FunctionDecl> mainDecl { new FunctionDecl( "main", Type::StorageClasses(), LinkageSpec::Cforall,
-																   main_type = new FunctionType( Type::Qualifiers(), false ), nullptr )
-				};
-		main_type->get_returnVals().push_back(
-			new ObjectDecl( "", Type::StorageClasses(), LinkageSpec::Cforall, 0, new BasicType( Type::Qualifiers(), BasicType::SignedInt ), nullptr )
-		);
-
-		main_type->get_parameters().push_back(
-			new ObjectDecl( "", Type::StorageClasses(), LinkageSpec::Cforall, 0, new BasicType( Type::Qualifiers(), BasicType::SignedInt ), nullptr )
-		);
-
-		main_type->get_parameters().push_back(
-			new ObjectDecl( "", Type::StorageClasses(), LinkageSpec::Cforall, 0,
-			new PointerType( Type::Qualifiers(), new PointerType( Type::Qualifiers(), new BasicType( Type::Qualifiers(), BasicType::Char ) ) ),
-			nullptr )
-		);
-
-		auto&& name = SymTab::Mangler::mangle( mainDecl.get() );
-		// std::cerr << name << std::endl;
-		return std::move(name);
-	}
-
-	bool is_main(const std::string& name) {
-		static std::string mains[] = {
-			mangle_main(),
-			mangle_main_args()
-		};
-
-		for(const auto& m : mains) {
-			if( name == m ) return true;
-		}
-		return false;
-	}
-
 	void fixNames( std::list< Declaration* > & translationUnit ) {
 		PassVisitor<FixNames> fixer;
@@ -118,5 +72,5 @@
 		fixDWT( functionDecl );
 
-		if(is_main( SymTab::Mangler::mangle(functionDecl, true, true) )) {
+		if ( FixMain::isMain( functionDecl ) ) {
 			int nargs = functionDecl->get_functionType()->get_parameters().size();
 			if( !(nargs == 0 || nargs == 2 || nargs == 3) ) {
@@ -124,5 +78,4 @@
 			}
 			functionDecl->get_statements()->get_kids().push_back( new ReturnStmt( new ConstantExpr( Constant::from_int( 0 ) ) ) );
-			CodeGen::FixMain::registerMain( functionDecl );
 		}
 	}
@@ -132,4 +85,56 @@
 		GuardAction( [this](){ scopeLevel--; } );
 	}
+
+/// Does work with the main function and scopeLevels.
+class FixNames_new : public ast::WithGuards {
+	int scopeLevel = 1;
+
+	bool shouldSetScopeLevel( const ast::DeclWithType * dwt ) {
+		return !dwt->name.empty() && dwt->linkage.is_mangled
+			&& dwt->scopeLevel != scopeLevel;
+	}
+public:
+	const ast::ObjectDecl *postvisit( const ast::ObjectDecl *objectDecl ) {
+		if ( shouldSetScopeLevel( objectDecl ) ) {
+			return ast::mutate_field( objectDecl, &ast::ObjectDecl::scopeLevel, scopeLevel );
+		}
+		return objectDecl;
+	}
+
+	const ast::FunctionDecl *postvisit( const ast::FunctionDecl *functionDecl ) {
+		// This store is used to ensure a maximum of one call to mutate.
+		ast::FunctionDecl * mutDecl = nullptr;
+
+		if ( shouldSetScopeLevel( functionDecl ) ) {
+			mutDecl = ast::mutate( functionDecl );
+			mutDecl->scopeLevel = scopeLevel;
+		}
+
+		if ( FixMain::isMain( functionDecl ) ) {
+			if ( !mutDecl ) { mutDecl = ast::mutate( functionDecl ); }
+
+			int nargs = mutDecl->params.size();
+			if ( 0 != nargs && 2 != nargs && 3 != nargs ) {
+				SemanticError( functionDecl, "Main expected to have 0, 2 or 3 arguments\n" );
+			}
+			ast::chain_mutate( mutDecl->stmts )->kids.push_back(
+				new ast::ReturnStmt(
+					mutDecl->location,
+					ast::ConstantExpr::from_int( mutDecl->location, 0 )
+				)
+			);
+		}
+		return mutDecl ? mutDecl : functionDecl;
+	}
+
+	void previsit( const ast::CompoundStmt * ) {
+		GuardValue( scopeLevel ) += 1;
+	}
+};
+
+void fixNames( ast::TranslationUnit & translationUnit ) {
+	ast::Pass<FixNames_new>::run( translationUnit );
+}
+
 } // namespace CodeGen
 
Index: src/CodeGen/FixNames.h
===================================================================
--- src/CodeGen/FixNames.h	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ src/CodeGen/FixNames.h	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -9,7 +9,7 @@
 // Author           : Richard C. Bilson
 // Created On       : Mon May 18 07:44:20 2015
-// Last Modified By : Peter A. Buhr
-// Last Modified On : Fri Jul 21 22:17:33 2017
-// Update Count     : 3
+// Last Modified By : Andrew Beach
+// Last Modified On : Tue Oct 26 13:47:00 2021
+// Update Count     : 4
 //
 
@@ -19,8 +19,12 @@
 
 class Declaration;
+namespace ast {
+	struct TranslationUnit;
+}
 
 namespace CodeGen {
 	/// mangles object and function names
 	void fixNames( std::list< Declaration* > & translationUnit );
+	void fixNames( ast::TranslationUnit & translationUnit );
 } // namespace CodeGen
 
Index: src/CodeTools/DeclStats.cc
===================================================================
--- src/CodeTools/DeclStats.cc	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ src/CodeTools/DeclStats.cc	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -156,6 +156,17 @@
 		/// number of counting bins for linkages
 		static const unsigned n_named_specs = 8;
-		/// map from total number of specs to bins
-		static const unsigned ind_for_linkage[16];
+		/// Mapping function from linkage to bin.
+		static unsigned linkage_index( LinkageSpec::Spec spec ) {
+			switch ( spec ) {
+			case LinkageSpec::Intrinsic:  return 0;
+			case LinkageSpec::C:          return 1;
+			case LinkageSpec::Cforall:    return 2;
+			case LinkageSpec::AutoGen:    return 3;
+			case LinkageSpec::Compiler:   return 4;
+			case LinkageSpec::BuiltinCFA: return 5;
+			case LinkageSpec::BuiltinC:   return 6;
+			default:                      return 7;
+			}
+		}
 
 		Stats for_linkage[n_named_specs];            ///< Stores separate stats per linkage
@@ -366,5 +377,5 @@
 			const std::string& mangleName = decl->get_mangleName().empty() ? decl->name : decl->get_mangleName();
 			if ( seen_names.insert( mangleName ).second ) {
-				Stats& stats = for_linkage[ ind_for_linkage[ decl->linkage ] ];
+				Stats& stats = for_linkage[ linkage_index( decl->linkage ) ];
 
 				++stats.n_decls;
@@ -527,7 +538,4 @@
 	};
 
-	const unsigned DeclStats::ind_for_linkage[]
-		= { 7, 7, 2, 1,   7, 7, 7, 3,   4, 7, 6, 5,   7, 7, 7, 0 };
-
 	void printDeclStats( std::list< Declaration * > &translationUnit ) {
 		PassVisitor<DeclStats> stats;
Index: src/Common/DeclStats.cpp
===================================================================
--- src/Common/DeclStats.cpp	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
+++ src/Common/DeclStats.cpp	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -0,0 +1,575 @@
+//
+// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
+//
+// The contents of this file are covered under the licence agreement in the
+// file "LICENCE" distributed with Cforall.
+//
+// DeclStats.cpp -- Print statistics about a translation unit's declarations.
+//
+// Author           : Andrew Beach
+// Created On       : Fri Oct  1 14:26:00 2021
+// Last Modified By : Andrew Beach
+// Last Modified On : Wed Oct  8 11:24:00 2021
+// Update Count     : 0
+//
+
+#include "DeclStats.hpp"
+
+#include "AST/LinkageSpec.hpp"
+#include "AST/Pass.hpp"
+#include "AST/Print.hpp"
+#include "Common/VectorMap.h"
+
+#include <iostream>
+#include <map>
+#include <unordered_map>
+#include <unordered_set>
+
+// Everything but printDeclStats at the bottom is hidden.
+namespace {
+
+template<typename T>
+void sum( T & l, const T & r ) { l += r; }
+
+void sum( VectorMap<unsigned> & l, const VectorMap<unsigned> & r ) {
+	l.reserve( r.size() );
+	for ( unsigned i = 0 ; i < r.size() ; ++i ) {
+		l[i] += r[i];
+	}
+}
+
+template<typename KeyT>
+void sum( std::map<KeyT, unsigned> & l, const std::map<KeyT, unsigned> & r ) {
+	for ( const auto & entry : r ) {
+		l[ entry.first ] += entry.second;
+	}
+}
+
+template<typename KeyT>
+void sum( std::unordered_map<KeyT, unsigned> & l,
+		const std::unordered_map<KeyT, unsigned> & r ) {
+	for ( const auto & entry : r ) {
+		l[ entry.first ] += entry.second;
+	}
+}
+
+/// Stores statistics on a single group of arguments or return values.
+struct ArgPackStats {
+	/// Count of decls with each number of elements.
+	VectorMap<unsigned> n;
+	/// Count of decls with each number of basic type elements.
+	VectorMap<unsigned> n_basic;
+	/// Count of decls with each number of generic type elements.
+	VectorMap<unsigned> n_generic;
+	/// Count of decls with each number of polymorphic elements.
+	VectorMap<unsigned> n_poly;
+	/// Count of decls with each number of non-generic compound types.
+	VectorMap<unsigned> n_compound;
+	/// Count of decls with each percentage of basic type elements.
+	std::map<unsigned, unsigned> p_basic;
+	/// Count of decls with each percentage of generic type elements.
+	std::map<unsigned, unsigned> p_generic;
+	/// Count of decls with each percentage of polymorphic elements.
+	std::map<unsigned, unsigned> p_poly;
+	/// Count of decls with each percentage of non-generic compound type elements.
+	std::map<unsigned, unsigned> p_compound;
+	/// Count of decls with each number of distinct types in the pack.
+	VectorMap<unsigned> n_types;
+	/// Count of decls with each percentage of new types in lists.
+	/// Types used in the parameter list that recur in the return list are not considered to be new.
+	std::map<unsigned, unsigned> p_new;
+
+	ArgPackStats& operator+=( const ArgPackStats& other ) {
+		sum(n, other.n);
+		sum(n_basic, other.n_basic);
+		sum(n_generic, other.n_generic);
+		sum(n_poly, other.n_poly);
+		sum(n_compound, other.n_compound);
+		sum(p_basic, other.p_basic);
+		sum(p_generic, other.p_generic);
+		sum(p_poly, other.p_poly);
+		sum(p_compound, other.p_compound);
+		sum(n_types, other.n_types);
+		sum(p_new, other.p_new);
+
+		return *this;
+	}
+};
+
+/// Collected statistics on a group of declarations.
+struct Stats {
+	/// Total number of declarations in these statistics.
+	unsigned n_decls;
+	/// Count of declarations with each number of assertion parameters.
+	VectorMap<unsigned> n_type_params;
+	/// Count of generic types with each number of type parameters.
+	VectorMap<unsigned> n_generic_params;
+	/// Count of maximum nesting depth of types.
+	VectorMap<unsigned> n_generic_nesting;
+	/// Count of declarations with each name.
+	std::unordered_map<std::string, unsigned> by_name;
+	/// Count of uses of each basic type.
+	std::unordered_map<std::string, unsigned> basic_type_names;
+	/// Count of uses of each generic type name (includes "*", "[]", "(*)", "[,]").
+	std::unordered_map<std::string, unsigned> generic_type_names;
+	/// Count of uses of each non-generic aggregate type.
+	std::unordered_map<std::string, unsigned> compound_type_names;
+	/// Count of decls using each basic type.
+	std::unordered_map<std::string, unsigned> basic_type_decls;
+	/// Count of decls using each generic type (includes "*", "[]", "(*)", "[,]").
+	std::unordered_map<std::string, unsigned> generic_type_decls;
+	/// Count of decls using each compound type.
+	std::unordered_map<std::string, unsigned> compound_type_decls;
+	/// Stats for the parameter lists.
+	ArgPackStats params;
+	/// Stats for the return lists.
+	ArgPackStats returns;
+
+	/// Count of declarations with each number of assertions.
+	std::map<unsigned, unsigned> n_assns;
+	/// Stats for the assertions' parameters.
+	ArgPackStats assn_params;
+	/// Stats for the assertions' return types.
+	ArgPackStats assn_returns;
+
+	Stats& operator+=( const Stats& other ) {
+		sum( n_decls, other.n_decls );
+		sum( n_type_params, other.n_type_params );
+		sum( n_generic_params, other.n_generic_params );
+		sum( n_generic_nesting, other.n_generic_nesting );
+		sum( by_name, other.by_name );
+		sum( basic_type_names, other.basic_type_names );
+		sum( generic_type_names, other.generic_type_names );
+		sum( compound_type_names, other.compound_type_names );
+		sum( basic_type_decls, other.basic_type_decls );
+		sum( generic_type_decls, other.generic_type_decls );
+		sum( compound_type_decls, other.compound_type_decls );
+		sum( params, other.params );
+		sum( returns, other.returns );
+		sum( n_assns, other.n_assns );
+		sum( assn_params, other.assn_params );
+		sum( assn_returns, other.assn_returns );
+
+		return *this;
+	}
+
+};
+
+void update_max( unsigned & max, unsigned value ) {
+	if ( max < value ) max = value;
+}
+
+// Where all unnamed specs are counted as one named spec group.
+constexpr unsigned num_named_specs = 8;
+
+unsigned linkage_index( ast::Linkage::Spec spec ) {
+	switch ( spec.val ) {
+	case ast::Linkage::Intrinsic.val:  return 0;
+	case ast::Linkage::C.val:          return 1;
+	case ast::Linkage::Cforall.val:    return 2;
+	case ast::Linkage::AutoGen.val:    return 3;
+	case ast::Linkage::Compiler.val:   return 4;
+	case ast::Linkage::BuiltinCFA.val: return 5;
+	case ast::Linkage::BuiltinC.val:   return 6;
+	default:                           return 7;
+	}
+}
+
+struct DeclStats : public ast::WithShortCircuiting {
+	/// Stores separate stats per linkage.
+	Stats by_linkage[num_named_specs];
+	/// Stores manglenames already seen to avoid double-counting.
+	std::unordered_set<std::string> seen_names;
+	/// Overall stats.
+	Stats total;
+	/// Count of expressions with (depth, fanout)
+	std::map<std::pair<unsigned, unsigned>, unsigned> exprs_by_fanout_at_depth;
+
+	/// Count that we have seen a named type.
+	void countType(
+			const std::string & name, unsigned & n,
+			std::unordered_map<std::string, unsigned> & names,
+			std::unordered_map<std::string, unsigned> & decls,
+			std::unordered_set<std::string> & elSeen ) {
+		++n;
+		++names[ name ];
+		if ( elSeen.insert( name ).second ) {
+			++decls[ name ];
+		}
+	}
+
+	/// Perform type analysis on a subtype.
+	void analyzeSubtype( const ast::Type * type, Stats & stats,
+			std::unordered_set<std::string> & elSeen, unsigned & n_poly,
+			bool & seen_poly, unsigned & max_depth, unsigned depth ) {
+		// This kind of gets in the way of grouping arguments.
+		unsigned ignored = 0;
+		analyzeType(
+			type, stats, elSeen, ignored, ignored, n_poly, ignored,
+			seen_poly, max_depth, depth + 1 );
+	}
+
+	/// Perform type analysis on each subtype.
+	void analyzeSubtypes(
+			const std::vector<ast::ptr<ast::Type>> & types, Stats & stats,
+			std::unordered_set<std::string> & elSeen, unsigned & n_poly,
+			bool & seen_poly, unsigned & max_depth, unsigned depth ) {
+		for ( const auto & type : types ) {
+			analyzeSubtype( type, stats, elSeen, n_poly, seen_poly, max_depth, depth );
+		}
+	}
+
+	/// Perform sub-type analysis on each subtype in an argument pack.
+	void analyzeSubPack(
+			const std::vector<ast::ptr<ast::Type>> & types, Stats & stats,
+			std::unordered_set<std::string> & elSeen, unsigned & n_poly,
+			bool & seen_poly, unsigned & max_depth, unsigned depth,
+			unsigned & n_subs ) {
+		// ... and count voids?
+		for ( const auto & type : types ) {
+			if ( type.as<ast::VoidType>() ) {
+				++n_subs;
+			}
+			// Could this be in `else`?
+			analyzeSubtype( type, stats, elSeen, n_poly, seen_poly, max_depth, depth );
+		}
+	}
+
+	/// Analyze and gather stats from a single type.
+	void analyzeType( const ast::ptr<ast::Type> & type, Stats & stats,
+			std::unordered_set<std::string> & elSeen,
+			unsigned & n_basic, unsigned & n_generic, unsigned & n_poly,
+			unsigned & n_agg, bool & seen_poly,
+			unsigned & max_depth, unsigned depth ) {
+		// Almost a visit, except it is only types.
+		if ( const ast::BasicType * t = type.as<ast::BasicType>() ) {
+			const std::string name = ast::BasicType::typeNames[ t->kind ];
+			countType( name, n_basic, stats.basic_type_names, stats.basic_type_decls, elSeen );
+			update_max( max_depth, depth );
+		} else if ( auto t = type.as<ast::PointerType>() ) {
+			static const std::string name = "*";
+			countType( name, n_generic, stats.generic_type_names, stats.generic_type_decls, elSeen );
+			analyzeSubtype( t->base, stats, elSeen, n_poly, seen_poly, max_depth, depth );
+			++stats.n_generic_params.at( 1 );
+		} else if ( auto t = type.as<ast::ArrayType>() ) {
+			static const std::string name = "[]";
+			countType( name, n_generic, stats.generic_type_names, stats.generic_type_decls, elSeen );
+			analyzeSubtype( t->base, stats, elSeen, n_poly, seen_poly, max_depth, depth );
+			++stats.n_generic_params.at( 1 );
+		} else if ( auto t = type.as<ast::ReferenceType>() ) {
+			static const std::string name = "&";
+			countType( name, n_generic, stats.generic_type_names, stats.generic_type_decls, elSeen );
+			analyzeSubtype( t->base, stats, elSeen, n_poly, seen_poly, max_depth, depth );
+			++stats.n_generic_params.at( 1 );
+		} else if ( auto t = type.as<ast::FunctionType>() ) {
+			static const std::string name = "(*)";
+			countType( name, n_generic, stats.generic_type_names, stats.generic_type_decls, elSeen );
+			unsigned n_subs = 0;
+			analyzeSubPack( t->returns, stats, elSeen, n_poly, seen_poly, max_depth, depth, n_subs );
+			analyzeSubPack( t->params, stats, elSeen, n_poly, seen_poly, max_depth, depth, n_subs );
+			++stats.n_generic_params.at( n_subs );
+		} else if ( auto t = type.as<ast::TypeInstType>() ) {
+			if ( !seen_poly ) {
+				++n_poly;
+				seen_poly = true;
+			}
+			countType( t->name, n_agg, stats.compound_type_names,
+					stats.compound_type_decls, elSeen );
+			update_max( max_depth, depth );
+		} else if ( auto t = type.as<ast::BaseInstType>() ) {
+			auto & params = t->params;
+			if ( params.empty() ) {
+				countType( t->name, n_agg, stats.compound_type_names,
+						stats.compound_type_decls, elSeen );
+				update_max( max_depth, depth );
+			} else {
+				countType( t->name, n_generic, stats.generic_type_names,
+						stats.generic_type_decls, elSeen );
+				++stats.n_generic_params.at( params.size() );
+			}
+		} else if ( auto t = type.as<ast::TupleType>() ) {
+			static const std::string name = "[,]";
+			countType( name, n_generic, stats.generic_type_names, stats.generic_type_decls, elSeen);
+			analyzeSubtypes( t->types, stats, elSeen, n_poly, seen_poly, max_depth, depth );
+			++stats.n_generic_params.at( t->size() );
+		} else if ( type.as<ast::VarArgsType>() ) {
+			static const std::string name = "...";
+			countType( name, n_agg, stats.compound_type_names, stats.compound_type_decls, elSeen );
+			update_max( max_depth, depth );
+		} else if ( type.as<ast::ZeroType>() ) {
+			static const std::string name = "0";
+			countType( name, n_basic, stats.basic_type_names, stats.basic_type_decls, elSeen );
+			update_max( max_depth, depth );
+		} else if ( type.as<ast::OneType>() ) {
+			static const std::string name = "1";
+			countType( name, n_basic, stats.basic_type_names, stats.basic_type_decls, elSeen );
+			update_max( max_depth, depth );
+		}
+	}
+
+	/// Update an ArgPackStats based on the list of types it repersents.
+	void analyzeArgPack(
+			const std::vector<ast::ptr<ast::Type>> & types,
+			Stats & stats,
+			ArgPackStats & packStats,
+			// What are these two used for?
+			std::unordered_set<std::string> & seen,
+			std::unordered_set<std::string> & elSeen ) {
+		std::unordered_set<std::string> type_names;
+		unsigned n = 0;
+		unsigned n_basic = 0;
+		unsigned n_generic = 0;
+		unsigned n_poly = 0;
+		unsigned n_compound = 0;
+		unsigned n_new = 0;
+
+		for ( auto & type : types ) {
+			n += type->size();
+
+			std::stringstream ss;
+			ast::print( ss, type );
+			type_names.insert( ss.str() );
+			if ( seen.insert( ss.str() ).second ) {
+				++n_new;
+			}
+
+			bool seen_poly = false;
+			unsigned max_depth = 0;
+			analyzeType(
+				type, stats, elSeen, n_basic, n_generic, n_poly, n_compound,
+				seen_poly, max_depth, 0
+			);
+			++stats.n_generic_nesting.at( max_depth );
+		}
+
+		++packStats.n.at( n );
+		++packStats.n_basic.at( n_basic );
+		++packStats.n_generic.at( n_generic );
+		++packStats.n_poly.at( n_poly );
+		++packStats.n_compound.at( n_compound );
+		if ( n > 0 ) {
+			++packStats.p_basic[ n_basic * 100 / n ];
+			++packStats.p_generic[ n_generic * 100 / n ];
+			++packStats.p_poly[ n_poly * 100 / n ];
+			++packStats.p_compound[ n_compound * 100 / n ];
+			if ( n > 1 ) {
+				++packStats.p_new[ (n_new - 1) * 100 / (n - 1) ];
+			}
+		}
+		++packStats.n_types.at( types.size() );
+	}
+
+	/// Perform type analysis on a function type, storing information in the
+	/// given ArgPackStats.
+	void analyzeFunctionType( const ast::FunctionType * type, Stats& stats,
+			ArgPackStats Stats::* param_pack,
+			ArgPackStats Stats::* return_pack ) {
+		// I still don't know what these are for.
+		std::unordered_set<std::string> seen;
+		std::unordered_set<std::string> elSeen;
+		analyzeArgPack( type->params, stats, stats.*param_pack, seen, elSeen );
+		analyzeArgPack( type->returns, stats, stats.*return_pack, seen, elSeen );
+	}
+
+	/// If the assertion is a function, return the function type.
+	static const ast::FunctionType * getAssertionFunctionType(
+			const ast::ptr<ast::DeclWithType> & assertion ) {
+		if ( auto * assertionObject = assertion.as<ast::ObjectDecl>() ) {
+			if ( auto * ptrTy = assertionObject->type.as<ast::PointerType>() ) {
+				return ptrTy->base.as<ast::FunctionType>();
+			} else {
+				return assertionObject->type.as<ast::FunctionType>();
+			}
+		} else if ( auto * assertionDecl = assertion.as<ast::FunctionDecl>() ) {
+			return assertionDecl->type;
+		}
+		return nullptr;
+	}
+
+	void analyzeFunctionDecl( const ast::FunctionDecl * decl ) {
+		Stats & stats = by_linkage[ linkage_index( decl->linkage ) ];
+
+		++stats.n_decls;
+		const ast::FunctionType * type = decl->type.get();
+		const ast::FunctionType::ForallList & forall = type->forall;
+		++stats.n_type_params.at( forall.size() );
+		unsigned num_assertions = 0;
+		for ( const ast::ptr<ast::TypeInstType> & instType : forall ) {
+			num_assertions += instType->base->assertions.size();
+			for ( const auto & assertion : instType->base->assertions ) {
+				if ( auto assertionType = getAssertionFunctionType( assertion ) ) {
+					analyzeFunctionType( assertionType, stats,
+							&Stats::assn_params, &Stats::assn_returns );
+				}
+			}
+		}
+		++stats.n_assns[ num_assertions ];
+		++stats.by_name[ decl->name ];
+		analyzeFunctionType( type, stats, &Stats::params, &Stats::returns );
+	}
+
+	void analyzeUntypedExpr( const ast::UntypedExpr * expr, unsigned depth ) {
+		unsigned fanout = expr->args.size();
+		++exprs_by_fanout_at_depth[ std::make_pair( depth, fanout ) ];
+
+		for ( const ast::ptr<ast::Expr> & arg : expr->args ) {
+			if ( const auto * untyped = arg.as<ast::UntypedExpr>() ) {
+				analyzeUntypedExpr( untyped, depth + 1 );
+			}
+		}
+	}
+
+public:
+	void previsit( const ast::UntypedExpr * expr ) {
+		visit_children = false;
+		analyzeUntypedExpr( expr, 0 );
+	}
+
+	void previsit( const ast::FunctionDecl * decl ) {
+		const std::string & mangleName = decl->mangleName;
+		const std::string & indexName = mangleName.empty() ? decl->name : mangleName;
+		if ( seen_names.insert( indexName ).second ) {
+			analyzeFunctionDecl( decl );
+		}
+	}
+
+private:
+
+	// Trying to avoid duplication by templates.
+	// I couldn't do it in all cases.
+	template<typename T, typename U>
+	using getter = std::function<U(T const &)>;
+
+	/// Print a single role, for every linkage and the totals.
+	void printRow( const std::string & name, getter<Stats, unsigned> extract ) {
+		std::cout << "\"" << name << "\",";
+		for ( const Stats & stats : by_linkage ) {
+			std::cout << "," << extract( stats );
+		}
+		std::cout << "," << extract( total ) << std::endl;
+	}
+
+	/// Print every row in a group of maps.
+	template<typename Func>
+	void printAllMap( const std::string & name, Func && extract ) {
+		// Get all rows from the total stats.
+		for ( auto & entry : extract( total ) ) {
+			auto & key = entry.first;
+			std::cout << "\"" << name << "\"," << key;
+			for ( const auto & stats : by_linkage ) {
+				const auto & map = extract( stats );
+				auto it = map.find( key );
+				if ( map.end() == it ) {
+					std::cout << ",0";
+				} else {
+					std::cout << "," << it->second;
+				}
+			}
+			std::cout << "," << entry.second << std::endl;
+		}
+	}
+
+	/// Accumalate information, then print every row in the remaining maps.
+	template<typename Func>
+	void printAllSparseHisto( const std::string & name, Func && extract ) {
+		std::map<unsigned, unsigned> histos[num_named_specs];
+		std::map<unsigned, unsigned> histo_total;
+
+		// Collect all data into the histograms.
+		for ( const auto & entry : extract( total ) ) {
+			++histo_total[ entry.second ];
+		}
+
+		for ( unsigned i = 0 ; i < num_named_specs ; ++i ) {
+			for ( const auto & entry : extract( by_linkage[i] ) ) {
+				++histos[ i ][ entry.second ];
+			}
+		}
+
+		// Get all rows from the total stats.
+		for ( const auto & entry : histo_total ) {
+			const unsigned & key = entry.first;
+			std::cout << "\"" << name << "\"," << key;
+			for ( unsigned i = 0 ; i < num_named_specs ; ++i ) {
+				auto it = histos[i].find( key );
+				if ( histos[i].end() == it ) {
+					std::cout << ",0";
+				} else {
+					std::cout << "," << it->second;
+				}
+			}
+			std::cout << "," << entry.second << std::endl;
+		}
+	}
+
+	void printAllPack( const std::string & name, ArgPackStats Stats::* field ) {
+		printAllMap("n_basic_" + name, [&field](const Stats& stats) { return (stats.*field).n_basic; });
+		printAllMap("n_generic_" + name, [&field](const Stats& stats) { return (stats.*field).n_generic; });
+		printAllMap("n_poly_" + name, [&field](const Stats& stats) { return (stats.*field).n_poly; });
+		printAllMap("n_compound_" + name, [&field](const Stats& stats) { return (stats.*field).n_compound; });
+		printAllMap("n_" + name, [&field](const Stats& stats) { return (stats.*field).n; });
+		printAllMap("%_basic_" + name, [&field](const Stats& stats) { return (stats.*field).p_basic; });
+		printAllMap("%_generic_" + name, [&field](const Stats& stats) { return (stats.*field).p_generic; });
+		printAllMap("%_poly_" + name, [&field](const Stats& stats) { return (stats.*field).p_poly; });
+		printAllMap("%_compound_" + name, [&field](const Stats& stats) { return (stats.*field).p_compound; });
+		printAllMap("n_distinct_types_" + name, [&field](const Stats& stats) { return (stats.*field).n_types; });
+		printAllMap("%_new_types_in_" + name, [&field](const Stats& stats) { return (stats.*field).p_new; });
+	}
+
+	static void printPairMap (
+			const std::string & name,
+			const std::map<std::pair<unsigned, unsigned>, unsigned> & map ) {
+		for ( const auto & entry : map ) {
+			const auto & key = entry.first;
+			std::cout << "\"" << name << "\"," << key.first << ','
+				<< key.second << ',' << entry.second << std::endl;
+		}
+	}
+
+public:
+	void print() {
+		for ( auto & stats : by_linkage ) {
+			total += stats;
+		}
+
+		std::cout << ",,\"intrinsic\",\"Cforall\",\"C\",\"autogen\",\"compiler\",\"builtinCFA\",\"builtinC\",\"other\",\"TOTAL\"" << std::endl;
+
+		printAllMap("n_type_params", [](const Stats& stats) { return stats.n_type_params; });
+		printAllMap("n_generic_params", [](const Stats& stats) { return stats.n_generic_params; });
+		printAllMap("n_generic_nesting", [](const Stats& stats) { return stats.n_generic_nesting; });
+		printRow("n_decls", [](const Stats& stats) { return stats.n_decls; });
+		printRow("unique_names", [](const Stats& stats) { return stats.by_name.size(); });
+		printAllSparseHisto("overloads", [](const Stats& stats) { return stats.by_name; });
+		printRow("basic_type_names", [](const Stats& stats) { return stats.basic_type_names.size(); });
+		printAllSparseHisto("basic_type_uses", [](const Stats& stats) { return stats.basic_type_names; });
+		printAllSparseHisto("decls_using_basic_type", [](const Stats& stats) { return stats.basic_type_decls; });
+		printRow("generic_type_names", [](const Stats& stats) { return stats.generic_type_names.size(); });
+		printAllSparseHisto("generic_type_uses", [](const Stats& stats) { return stats.generic_type_names; });
+		printAllSparseHisto("decls_using_generic_type", [](const Stats& stats) { return stats.generic_type_decls; });
+		printRow("compound_type_names", [](const Stats& stats) { return stats.compound_type_names.size(); });
+		printAllSparseHisto("compound_type_uses", [](const Stats& stats) { return stats.compound_type_names; });
+		printAllSparseHisto("decls_using_compound_type", [](const Stats& stats) { return stats.compound_type_decls; });
+		printAllPack("params", &Stats::params);
+		printAllPack("returns", &Stats::returns);
+		printAllMap("n_assns", [](const Stats& stats) { return stats.n_assns; });
+		printAllPack("assn_params", &Stats::assn_params);
+		printAllPack("assn_returns", &Stats::assn_returns);
+		std::cout << std::endl;
+
+		printPairMap( "exprs by depth+fanout", exprs_by_fanout_at_depth );
+	}
+};
+
+} // namespace
+
+void printDeclStats( ast::TranslationUnit & translationUnit ) {
+	ast::Pass<DeclStats> stats;
+	accept_all( translationUnit, stats );
+	stats.core.print();
+}
+
+// Local Variables: //
+// tab-width: 4 //
+// mode: c++ //
+// compile-command: "make install" //
+// End: //
Index: src/Common/DeclStats.hpp
===================================================================
--- src/Common/DeclStats.hpp	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
+++ src/Common/DeclStats.hpp	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -0,0 +1,29 @@
+//
+// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
+//
+// The contents of this file are covered under the licence agreement in the
+// file "LICENCE" distributed with Cforall.
+//
+// DeclStats.hpp -- Print statistics about a translation unit's declarations.
+//
+// Author           : Andrew Beach
+// Created On       : Fri Oct  1 14:20:00 2021
+// Last Modified By : Andrew Beach
+// Last Modified On : Fri Oct  1 14:28:00 2021
+// Update Count     : 0
+//
+
+#pragma once
+
+namespace ast {
+	class TranslationUnit;
+}
+
+/// Print statistics about a translation unit's declarations.
+void printDeclStats( ast::TranslationUnit &translationUnit );
+
+// Local Variables: //
+// tab-width: 4 //
+// mode: c++ //
+// compile-command: "make install" //
+// End: //
Index: src/Common/ResolvProtoDump.cpp
===================================================================
--- src/Common/ResolvProtoDump.cpp	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
+++ src/Common/ResolvProtoDump.cpp	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -0,0 +1,808 @@
+//
+// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
+//
+// The contents of this file are covered under the licence agreement in the
+// file "LICENCE" distributed with Cforall.
+//
+// ResolvProtoDump.cpp -- Prints AST as instances for resolv-proto.
+//
+// Author           : Andrew Beach
+// Created On       : Wed Oct  6 14:10:00 2021
+// Last Modified By : Andrew Beach
+// Last Modified On : Tue Oct 18 11:23:00 2021
+// Update Count     : 0
+//
+
+#include "ResolvProtoDump.hpp"
+
+#include <cctype>
+#include <iostream>
+#include <set>
+#include <unordered_set>
+
+#include "AST/Copy.hpp"
+#include "AST/Pass.hpp"
+#include "AST/TranslationUnit.hpp"
+#include "AST/Type.hpp"
+#include "CodeGen/OperatorTable.h"
+#include "Common/utility.h"
+
+namespace {
+
+/// Add a prefix to an existing name.
+std::string add_prefix( const std::string & prefix, const char * added ) {
+	if ( prefix.empty() ) {
+		return std::string("$") + added;
+	} else {
+		return prefix + added;
+	}
+}
+
+/// Shortens operator names.
+std::string op_name( const std::string & name ) {
+	if ( name.compare( 0, 10, "_operator_" ) == 0 ) {
+		return name.substr( 10 );
+	} else if ( name.compare( "_constructor" ) == 0
+			|| name.compare( "_destructor" ) == 0 ) {
+		return name.substr( 1 );
+	} else if ( name.compare( 0, 11, "__operator_" ) == 0 ) {
+		return name.substr( 11 );
+	} else {
+		return name;
+	}
+}
+
+/// Get the resolv-proto names for operators.
+std::string rp_name( const std::string & name, std::string && pre = "" ) {
+	// Check for anonymous names.
+	if ( name.empty() ) {
+		return add_prefix( pre, "anon" );
+	}
+
+	// Replace operator names.
+	const CodeGen::OperatorInfo * opInfo = CodeGen::operatorLookup( name );
+	if ( nullptr != opInfo ) {
+		return add_prefix( pre, "" ) + op_name( opInfo->outputName );
+	}
+
+	// Replace return value prefix.
+	if ( name.compare( 0, 8, "_retval_" ) == 0 ) {
+		return add_prefix( pre, "rtn_" ) + op_name( name.substr( 8 ) );
+	}
+
+	// Default to just name, with first character in lowercase.
+	if ( std::isupper( name[0] ) ) {
+		std::string copy = name;
+		copy[0] = std::tolower( copy[0] );
+		return pre + copy;
+	}
+	return pre + name;
+}
+
+/// Normalise a type instance name.
+std::string ti_name( const std::string & name ) {
+	// Replace built-in names
+	if ( name == "char16_t" || name == "char32_t" || name == "wchar_t" ) {
+		return std::string("#") + name;
+	}
+
+	// Strip leadng underscores.
+	unsigned i = 0;
+	while ( i < name.size() && name[i] == '_' ) { ++i; }
+	if ( i == name.size() ) {
+		return "Anon";
+	}
+
+	std::string stripped = name.substr( i );
+	// Strip trailing generic from autogen names ()
+	static char generic[] = "_generic_";
+	static size_t n_generic = sizeof(generic) - 1;
+	if ( stripped.size() >= n_generic
+			&& stripped.substr( stripped.size() - n_generic ) == generic ) {
+		stripped.resize( stripped.size() - n_generic );
+	}
+
+	// Uppercase first character.
+	stripped[0] = std::toupper( stripped[0] );
+	return stripped;
+}
+
+std::vector<ast::ptr<ast::Type>> to_types(
+		const std::vector<ast::ptr<ast::Expr>> & data ) {
+	std::vector<ast::ptr<ast::Type>> ret_val;
+	ret_val.reserve( data.size() );
+	for ( auto entry : data ) {
+		if ( auto * typeExpr = entry.as<ast::TypeExpr>() ) {
+			ret_val.emplace_back( typeExpr->type );
+		}
+	}
+	return ret_val;
+}
+
+enum class septype { separated, terminated, preceded };
+
+template<typename V>
+void build(
+		V & visitor,
+		const std::vector<ast::ptr<ast::Type>> & types,
+		std::stringstream & ss,
+		septype mode );
+
+template<typename V>
+void buildAsTuple(
+		V & visitor, const std::vector<ast::ptr<ast::Type>> & types,
+		std::stringstream & ss );
+
+struct TypePrinter : public ast::WithShortCircuiting, ast::WithVisitorRef<TypePrinter> {
+	/// Accumulator for the printed type.
+	std::stringstream ss;
+	/// Closed type variables.
+	const std::unordered_set<std::string> & closed;
+	/// Depth of nesting from root type.
+	unsigned depth;
+
+	TypePrinter( const std::unordered_set<std::string> & closed ) :
+		ss(), closed(closed), depth(0)
+	{}
+
+	std::string result() const {
+		return ss.str();
+	}
+
+	// Basic type represented as an integer type.
+	// TODO: Maybe hard-code conversion graph and make named type.
+	void previsit( const ast::BasicType * type ) {
+		ss << (int)type->kind;
+	}
+
+	// Pointers (except function pointers) are represented as generic type.
+	void previsit( const ast::PointerType * type ) {
+		if ( nullptr == type->base.as<ast::FunctionType>() ) {
+			ss << "#$ptr<";
+			++depth;
+		}
+	}
+	void postvisit( const ast::PointerType * type ) {
+		if ( nullptr == type->base.as<ast::FunctionType>() ) {
+			--depth;
+			ss << '>';
+		}
+	}
+
+	// Arrays repersented as pointers.
+	void previsit( const ast::ArrayType * type ) {
+		ss << "#$ptr<";
+		++depth;
+		type->base->accept( *visitor );
+		--depth;
+		ss << '>';
+		visit_children = false;
+	}
+
+	// Ignore top-level references as they are mostly transparent to resolution.
+	void previsit( const ast::ReferenceType * ) {
+		if ( !atTopLevel() ) { ss << "#$ref<"; }
+		++depth;
+	}
+	void postvisit( const ast::ReferenceType * ) {
+		--depth;
+		if ( !atTopLevel() ) { ss << '>'; }
+	}
+
+	void previsit( const ast::FunctionType * type ) {
+		ss << '[';
+		++depth;
+		build( *visitor, type->returns, ss, septype::preceded );
+		ss << " : ";
+		build( *visitor, type->params, ss, septype::terminated );
+		--depth;
+		ss << ']';
+		visit_children = false;
+	}
+
+private:
+	bool atTopLevel() const {
+		return 0 == depth;
+	}
+
+	void handleAggregate( const ast::BaseInstType * type ) {
+		ss << '#' << type->name;
+		if ( !type->params.empty() ) {
+			ss << '<';
+			++depth;
+			build( *visitor, to_types( type->params ), ss, septype::separated );
+			--depth;
+			ss << '>';
+		}
+		visit_children = false;
+	}
+public:
+
+	void previsit( const ast::StructInstType * type ) {
+		handleAggregate( type );
+	}
+
+	void previsit( const ast::UnionInstType * type ) {
+		handleAggregate( type );
+	}
+
+	void previsit( const ast::EnumInstType * ) {
+		ss << (int)ast::BasicType::SignedInt;
+	}
+
+	void previsit( const ast::TypeInstType * type ) {
+		// Print closed variables as named types.
+		if ( closed.count( type->name ) ) {
+			ss << '#' << type->name;
+		// Otherwise normalize the name.
+		} else {
+			ss << ti_name( type->name );
+		}
+	}
+
+	void previsit( const ast::TupleType * tupleType ) {
+		++depth;
+		buildAsTuple( *visitor, tupleType->types, ss );
+		--depth;
+		visit_children = false;
+	}
+
+	void previsit( const ast::VarArgsType * ) {
+		if ( atTopLevel() ) ss << "#$varargs";
+	}
+
+	// TODO: Support 0 and 1 with their type names and conversions.
+	void previsit( const ast::ZeroType * ) {
+		ss << (int)ast::BasicType::SignedInt;
+	}
+
+	void previsit( const ast::OneType * ) {
+		ss << (int)ast::BasicType::SignedInt;
+	}
+
+	void previsit( const ast::VoidType * ) {
+		if ( !atTopLevel() ) {
+			ss << "#void";
+		}
+	}
+};
+
+struct ExprPrinter : public ast::WithShortCircuiting, ast::WithVisitorRef<ExprPrinter> {
+	// TODO: Change interface to generate multiple expression canditates.
+	/// Accumulator of the printed expression.
+	std::stringstream ss;
+	/// Set of closed type variables.
+	const std::unordered_set<std::string> & closed;
+
+	ExprPrinter( const std::unordered_set<std::string> & closed ) :
+		ss(), closed( closed )
+	{}
+
+	std::string result() const {
+		return ss.str();
+	}
+
+	void previsit( const ast::NameExpr * expr ) {
+		ss << '&' << rp_name( expr->name );
+	}
+
+	/// Handle already resolved variables as type constants.
+	void previsit( const ast::VariableExpr * expr ) {
+		ss << ast::Pass<TypePrinter>::read( expr->var->get_type(), closed );
+		visit_children = false;
+	}
+
+	void previsit( const ast::UntypedExpr * expr ) {
+		// TODO: Handle name extraction more generally.
+		const ast::NameExpr * name = expr->func.as<ast::NameExpr>();
+
+		// TODO: Incorporate function type into resolv-proto.
+		if ( !name ) {
+			expr->func->accept( *visitor );
+			visit_children = false;
+			return;
+		}
+
+		ss << rp_name( name->name );
+		if ( expr->args.empty() ) {
+			ss << "()";
+		} else {
+			ss << "( ";
+			auto it = expr->args.begin();
+			while (true) {
+				(*it)->accept( *visitor );
+				if ( ++it == expr->args.end() ) break;
+				ss << ' ';
+			}
+			ss << " )";
+		}
+		visit_children = false;
+	}
+
+	void previsit( const ast::ApplicationExpr * expr ) {
+		ss << ast::Pass<TypePrinter>::read( static_cast<const ast::Expr *>( expr ), closed );
+		visit_children = false;
+	}
+
+	void previsit( const ast::AddressExpr * expr ) {
+		ss << "$addr( ";
+		expr->arg->accept( *visitor );
+		ss << " )";
+		visit_children = false;
+	}
+
+	void previsit( const ast::CastExpr * expr ) {
+		ss << ast::Pass<TypePrinter>::read( expr->result.get(), closed );
+		visit_children = false;
+	}
+
+	/// Member access handled as function from aggregate to member.
+	void previsit( const ast::UntypedMemberExpr * expr ) {
+		// TODO: Handle name extraction more generally.
+		const ast::NameExpr * name = expr->member.as<ast::NameExpr>();
+
+		// TODO: Incorporate function type into resolve-proto.
+		if ( !name ) {
+			expr->member->accept( *visitor );
+			visit_children = false;
+			return;
+		}
+
+		ss << rp_name( name->name, "$field_" );
+		ss << "( ";
+		expr->aggregate->accept( *visitor );
+		ss << " )";
+		visit_children = false;
+	}
+
+	/// Constant expression replaced by its type.
+	void previsit( const ast::ConstantExpr * expr ) {
+		ss << ast::Pass<TypePrinter>::read( static_cast<const ast::Expr *>( expr ), closed );
+		visit_children = false;
+	}
+
+	/// sizeof, alignof, & offsetof are replaced by constant type.
+	// TODO: Extra expression to resolve argument.
+	void previsit( const ast::SizeofExpr * ) {
+		ss << (int)ast::BasicType::LongUnsignedInt;
+		visit_children = false;
+	}
+	void previsit( const ast::AlignofExpr * ) {
+		ss << (int)ast::BasicType::LongUnsignedInt;
+		visit_children = false;
+	}
+	void previsit( const ast::UntypedOffsetofExpr * ) {
+		ss << (int)ast::BasicType::LongUnsignedInt;
+		visit_children = false;
+	}
+
+	/// Logical expressions represented as operators.
+	void previsit( const ast::LogicalExpr * expr ) {
+		ss << ( (ast::AndExpr == expr->isAnd) ? "$and( " : "$or( " );
+		expr->arg1->accept( *visitor );
+		ss << ' ';
+		expr->arg2->accept( *visitor );
+		ss << " )";
+		visit_children = false;
+	}
+
+	/// Conditional expression represented as an operator.
+	void previsit( const ast::ConditionalExpr * expr ) {
+		ss << "$if( ";
+		expr->arg1->accept( *visitor );
+		ss << ' ';
+		expr->arg2->accept( *visitor );
+		ss << ' ';
+		expr->arg3->accept( *visitor );
+		ss << " )";
+		visit_children = false;
+	}
+
+	/// Comma expression represented as on operator.
+	void previsit( const ast::CommaExpr * expr ) {
+		ss << "$seq( ";
+		expr->arg1->accept( *visitor );
+		ss << ' ';
+		expr->arg2->accept( *visitor );
+		ss << " )";
+		visit_children = false;
+	}
+
+	// TODO: Handle ignored ImplicitCopyCtorExpr and below.
+};
+
+template<typename V>
+void build(
+		V & visitor,
+		const std::vector<ast::ptr<ast::Type>> & types,
+		std::stringstream & ss,
+		septype mode ) {
+	if ( types.empty() ) return;
+
+	if ( septype::preceded == mode ) { ss << ' '; }
+
+	auto it = types.begin();
+	(*it)->accept( visitor );
+
+	while ( ++it != types.end() ) {
+		ss << ' ';
+		(*it)->accept( visitor );
+	}
+
+	if ( septype::terminated == mode ) { ss << ' '; }
+}
+
+std::string buildType(
+		const std::string & name, const ast::Type * type,
+		const std::unordered_set<std::string> & closed );
+
+/// Build a string representing a function type.
+std::string buildFunctionType(
+		const std::string & name, const ast::FunctionType * type,
+		const std::unordered_set<std::string> & closed ) {
+	ast::Pass<TypePrinter> printer( closed );
+	std::stringstream & ss = printer.core.ss;
+
+	build( printer, type->returns, ss, septype::terminated );
+	ss << rp_name( name );
+	build( printer, type->params, ss, septype::preceded );
+	for ( const auto & assertion : type->assertions ) {
+		auto var = assertion->var;
+		ss << " | " << buildType( var->name, var->get_type(), closed );
+	}
+	return ss.str();
+}
+
+/// Build a description of a type.
+std::string buildType(
+		const std::string & name, const ast::Type * type,
+		const std::unordered_set<std::string> & closed ) {
+	const ast::Type * norefs = type->stripReferences();
+
+	if ( const auto & ptrType = dynamic_cast<const ast::PointerType *>( norefs ) ) {
+		if ( const auto & funcType = ptrType->base.as<ast::FunctionType>() ) {
+			return buildFunctionType( name, funcType, closed );
+		}
+	} else if ( const auto & funcType = dynamic_cast<const ast::FunctionType *>( norefs ) ) {
+		return buildFunctionType( name, funcType, closed );
+	}
+
+	std::stringstream ss;
+	ss << ast::Pass<TypePrinter>::read( norefs, closed );
+	ss << " &" << rp_name( name );
+	return ss.str();
+}
+
+/// Builds description of a field access.
+std::string buildAggregateDecl( const std::string & name,
+		const ast::AggregateDecl * agg, const ast::Type * type,
+		const std::unordered_set<std::string> & closed ) {
+	const ast::Type * norefs = type->stripReferences();
+	std::stringstream ss;
+
+	ss << ast::Pass<TypePrinter>::read( norefs, closed ) << ' ';
+	ss << rp_name( name, "$field_" );
+	ss << " #" << agg->name;
+	if ( !agg->params.empty() ) {
+		ss << '<';
+		auto it = agg->params.begin();
+		while (true) {
+			ss << ti_name( (*it)->name );
+			if ( ++it == agg->params.end() ) break;
+			ss << ' ';
+		}
+		ss << '>';
+	}
+	return ss.str();
+}
+
+template<typename V>
+void buildAsTuple(
+		V & visitor, const std::vector<ast::ptr<ast::Type>> & types,
+		std::stringstream & ss ) {
+	switch ( types.size() ) {
+	case 0:
+		ss << "#void";
+		break;
+	case 1:
+		types.front()->accept( visitor );
+		break;
+	default:
+		ss << "#$" << types.size() << '<';
+		build( visitor, types, ss, septype::separated );
+		ss << '>';
+		break;
+	}
+}
+
+/// Adds a return
+std::string buildReturn(
+		const ast::Type * returnType,
+		const ast::Expr * expr,
+		const std::unordered_set<std::string> & closed ) {
+	std::stringstream ss;
+	ss << "$constructor( ";
+	ss << ast::Pass<TypePrinter>::read( returnType, closed );
+	ss << ' ';
+	ss << ast::Pass<ExprPrinter>::read( expr, closed );
+	ss << " )";
+	return ss.str();
+}
+
+void buildInitComponent(
+		std::stringstream & out, const ast::Init * init,
+		const std::unordered_set<std::string> & closed ) {
+	if ( const auto * s = dynamic_cast<const ast::SingleInit *>( init ) ) {
+		out << ast::Pass<ExprPrinter>::read( s->value.get(), closed ) << ' ';
+	} else if ( const auto * l = dynamic_cast<const ast::ListInit *>( init ) ) {
+		for ( const auto & it : l->initializers ) {
+			buildInitComponent( out, it, closed );
+		}
+	}
+}
+
+/// Build a representation of an initializer.
+std::string buildInitializer(
+		const std::string & name, const ast::Init * init,
+		const std::unordered_set<std::string> & closed ) {
+	std::stringstream ss;
+	ss << "$constructor( &";
+	ss << rp_name( name );
+	ss << ' ';
+	buildInitComponent( ss, init, closed );
+	ss << ')';
+	return ss.str();
+}
+
+/// Visitor for collecting and printing resolver prototype output.
+class ProtoDump : public ast::WithShortCircuiting, ast::WithVisitorRef<ProtoDump> {
+	/// Declarations in this scope.
+	// Set is used for ordering of printing.
+	std::set<std::string> decls;
+	/// Expressions in this scope.
+	std::vector<std::string> exprs;
+	/// Sub-scopes
+	std::vector<ProtoDump> subs;
+	/// Closed type variables
+	std::unordered_set<std::string> closed;
+	/// Outer lexical scope
+	const ProtoDump * parent;
+	/// Return type for this scope
+	ast::ptr<ast::Type> returnType;
+
+	/// Is the declaration in this scope or a parent scope?
+	bool hasDecl( const std::string & decl ) const {
+		return decls.count( decl ) || (parent && parent->hasDecl( decl ));
+	}
+
+	/// Adds a declaration to this scope if it is new.
+	void addDecl( const std::string & decl ) {
+		if ( !hasDecl( decl ) ) decls.insert( decl );
+	}
+
+	/// Adds a new expression to this scope.
+	void addExpr( const std::string & expr ) {
+		if ( !expr.empty() ) exprs.emplace_back( expr );
+	}
+
+	/// Adds a new scope as a child scope.
+	void addSub( ast::Pass<ProtoDump> && pass ) {
+		subs.emplace_back( std::move( pass.core ) );
+	}
+
+	/// Adds all named declaration in a list to the local scope.
+	void addAll( const std::vector<ast::ptr<ast::DeclWithType>> & decls ) {
+		for ( auto decl : decls ) {
+			// Skip anonymous decls.
+			if ( decl->name.empty() ) continue;
+
+			if ( const auto & obj = decl.as<ast::ObjectDecl>() ) {
+				previsit( obj );
+			}
+		}
+	}
+
+public:
+	ProtoDump() :
+		parent( nullptr ), returnType( nullptr )
+	{}
+
+	ProtoDump( const ProtoDump * parent, const ast::Type * returnType ) :
+		closed( parent->closed ), parent( parent ), returnType( returnType )
+	{}
+
+	ProtoDump( const ProtoDump & other ) :
+		decls( other.decls ), exprs( other.exprs ), subs( other.subs ),
+		closed( other.closed ), parent( other.parent ),
+		returnType( other.returnType )
+	{}
+
+	ProtoDump( ProtoDump && ) = default;
+
+	ProtoDump & operator=( const ProtoDump & ) = delete;
+	ProtoDump & operator=( ProtoDump && ) = delete;
+
+	void previsit( const ast::ObjectDecl * decl ) {
+		// Add variable as declaration.
+		addDecl( buildType( decl->name, decl->type, closed ) );
+
+		// Add initializer as expression if applicable.
+		if ( decl->init ) {
+			addExpr( buildInitializer( decl->name, decl->init, closed ) );
+		}
+	}
+
+	void previsit( const ast::FunctionDecl * decl ) {
+		visit_children = false;
+
+		// Skips declarations with ftype parameters.
+		for ( const auto & typeDecl : decl->type->forall ) {
+			if ( ast::TypeDecl::Ftype == typeDecl->kind ) {
+				return;
+			}
+		}
+
+		// Add function as declaration.
+		// NOTE: I'm not sure why the assertions are only present on the
+		// declaration and not the function type. Is that an error?
+		ast::FunctionType * new_type = ast::shallowCopy( decl->type.get() );
+		for ( const ast::ptr<ast::DeclWithType> & assertion : decl->assertions ) {
+			new_type->assertions.push_back(
+				new ast::VariableExpr( assertion->location , assertion )
+			);
+		}
+		addDecl( buildFunctionType( decl->name, new_type, closed ) );
+		delete new_type;
+
+		// Add information body if available.
+		if ( !decl->stmts ) return;
+		const std::vector<ast::ptr<ast::Type>> & returns =
+				decl->type->returns;
+
+		// Add the return statement.
+		ast::ptr<ast::Type> retType = nullptr;
+		if ( 1 == returns.size() ) {
+			if ( !returns.front().as<ast::VoidType>() ) {
+				retType = returns.front();
+			}
+		} else if ( 1 < returns.size() ) {
+			retType = new ast::TupleType( copy( returns ) );
+		}
+		ast::Pass<ProtoDump> body( this, retType.get() );
+
+		// Handle the forall clause (type parameters and assertions).
+		for ( const ast::ptr<ast::TypeDecl> & typeDecl : decl->type_params ) {
+			// Add set of "closed" types to body so that it can print them as NamedType.
+			body.core.closed.insert( typeDecl->name );
+
+			// Add assertions to local scope as declarations as well.
+			for ( const ast::DeclWithType * assertion : typeDecl->assertions ) {
+				assertion->accept( body );
+			}
+		}
+
+		// NOTE: Related to the last NOTE; this is where the assertions are now.
+		for ( const ast::ptr<ast::DeclWithType> & assertion : decl->assertions ) {
+			assertion->accept( body );
+		}
+
+		// Add named parameters and returns to local scope.
+		body.core.addAll( decl->returns );
+		body.core.addAll( decl->params );
+
+		// Add contents of the function to a new scope.
+		decl->stmts->accept( body );
+
+		// Store sub-scope
+		addSub( std::move( body ) );
+	}
+
+private:
+	void addAggregateFields( const ast::AggregateDecl * agg ) {
+		for ( const auto & member : agg->members ) {
+			if ( const ast::ObjectDecl * obj = member.as<ast::ObjectDecl>() ) {
+				addDecl( buildAggregateDecl( obj->name, agg, obj->type, closed ) );
+			}
+		}
+		visit_children = false;
+	}
+
+public:
+
+	void previsit( const ast::StructDecl * decl ) {
+		addAggregateFields( decl );
+	}
+
+	void previsit( const ast::UnionDecl * decl ) {
+		addAggregateFields( decl );
+	}
+
+	void previsit( const ast::EnumDecl * decl ) {
+		for ( const auto & member : decl->members ) {
+			if ( const auto * obj = member.as<ast::ObjectDecl>() ) {
+				previsit( obj );
+			}
+		}
+
+		visit_children = false;
+	}
+
+	void previsit( const ast::ReturnStmt * stmt ) {
+		// Do nothing for void-returning functions or statements returning nothing.
+		if ( !returnType || !stmt->expr ) return;
+
+		// Otherwise constuct the return type from the expression.
+		addExpr( buildReturn( returnType.get(), stmt->expr, closed ) );
+		visit_children = false;
+	}
+
+	void previsit( const ast::AsmStmt * ) {
+		// Skip asm statements.
+		visit_children = false;
+	}
+
+	void previsit( const ast::Expr * expr ) {
+		addExpr( ast::Pass<ExprPrinter>::read( expr, closed ) );
+		visit_children = false;
+	}
+
+private:
+	/// Print the pesudo-declarations not in any scope.
+	void printGlobal( std::ostream & out ) const {
+		// &? Address of operator.
+		out << "#$ptr<T> $addr T" << std::endl;
+		const int intId = (int)ast::BasicType::SignedInt;
+		// ?&&? ?||? ?: Logical operators.
+		out << intId << " $and " << intId << ' ' << intId << std::endl;
+		out << intId << " $or " << intId << ' ' << intId << std::endl;
+		out << "T $if " << intId << " T T" << std::endl;
+		// ?,? Sequencing.
+		out << "T $seq X T" << std::endl;
+	}
+
+	/// Print everything in this scope and its child scopes.
+	void printLocal( std::ostream & out, unsigned indent ) const {
+		const std::string tab( indent, '\t' );
+
+		// Print Declarations:
+		for ( const std::string & decl : decls ) {
+			out << tab << decl << std::endl;
+		}
+
+		// Print Divider:
+		out << '\n' << tab << "%%\n" << std::endl;
+
+		// Print Top-Level Expressions:
+		for ( const std::string & expr : exprs ) {
+			out << tab << expr << std::endl;
+		}
+
+		// Print Children Scopes:
+		++indent;
+		for ( const ProtoDump & sub : subs ) {
+			out << tab << '{' << std::endl;
+			sub.printLocal( out, indent );
+			out << tab << '}' << std::endl;
+		}
+	}
+public:
+	/// Start printing, the collected information.
+	void print( std::ostream & out ) const {
+		printGlobal( out );
+		printLocal( out, 0 );
+	}
+};
+
+} // namespace
+
+void dumpAsResolverProto( ast::TranslationUnit & transUnit ) {
+	ast::Pass<ProtoDump> dump;
+	accept_all( transUnit, dump );
+	dump.core.print( std::cout );
+}
+
+// Local Variables: //
+// tab-width: 4 //
+// mode: c++ //
+// compile-command: "make install" //
+// End: //
Index: src/Common/ResolvProtoDump.hpp
===================================================================
--- src/Common/ResolvProtoDump.hpp	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
+++ src/Common/ResolvProtoDump.hpp	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -0,0 +1,29 @@
+//
+// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
+//
+// The contents of this file are covered under the licence agreement in the
+// file "LICENCE" distributed with Cforall.
+//
+// ResolvProtoDump.hpp -- Prints AST as instances for resolv-proto.
+//
+// Author           : Andrew Beach
+// Created On       : Wed Oct  6 14:05:00 2021
+// Last Modified By : Andrew Beach
+// Last Modified On : Wed Oct  6 14:29:00 2021
+// Update Count     : 0
+//
+
+#pragma once
+
+namespace ast {
+	struct TranslationUnit;
+}
+
+/// Prints AST as instances for resolv-proto.
+void dumpAsResolverProto( ast::TranslationUnit & transUnit );
+
+// Local Variables: //
+// tab-width: 4 //
+// mode: c++ //
+// compile-command: "make install" //
+// End: //
Index: src/Common/module.mk
===================================================================
--- src/Common/module.mk	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ src/Common/module.mk	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -22,4 +22,6 @@
       Common/CompilerError.h \
       Common/Debug.h \
+      Common/DeclStats.hpp \
+      Common/DeclStats.cpp \
       Common/ErrorObjects.h \
       Common/Eval.cc \
@@ -33,4 +35,6 @@
       Common/PassVisitor.proto.h \
       Common/PersistentMap.h \
+      Common/ResolvProtoDump.hpp \
+      Common/ResolvProtoDump.cpp \
       Common/ScopedMap.h \
       Common/SemanticError.cc \
Index: src/Concurrency/Keywords.cc
===================================================================
--- src/Concurrency/Keywords.cc	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ src/Concurrency/Keywords.cc	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -93,4 +93,5 @@
 		ObjectDecl * addField( StructDecl * );
 		void addRoutines( ObjectDecl *, FunctionDecl * );
+		void addLockUnlockRoutines( StructDecl * );
 
 		virtual bool is_target( StructDecl * decl ) = 0;
@@ -322,4 +323,5 @@
 		StructDecl* dtor_guard_decl = nullptr;
 		StructDecl* thread_guard_decl = nullptr;
+		StructDecl* lock_guard_decl = nullptr;
 
 		static std::unique_ptr< Type > generic_func;
@@ -463,5 +465,4 @@
 	}
 
-
 	void ConcurrentSueKeyword::handle( StructDecl * decl ) {
 		if( ! decl->body ) return;
@@ -479,5 +480,9 @@
 		FunctionDecl * func = forwardDeclare( decl );
 		ObjectDecl * field = addField( decl );
+
+		// add get_.* routine
 		addRoutines( field, func );
+		// add lock/unlock routines to monitors for use by mutex stmt
+		addLockUnlockRoutines( decl );
 	}
 
@@ -612,4 +617,6 @@
 	}
 
+	// This function adds the get_.* routine body for coroutines, monitors etc
+	// 		after their corresponding struct has been made
 	void ConcurrentSueKeyword::addRoutines( ObjectDecl * field, FunctionDecl * func ) {
 		CompoundStmt * statement = new CompoundStmt();
@@ -634,4 +641,112 @@
 
 		declsToAddAfter.push_back( get_decl );
+	}
+
+	// Generates lock/unlock routines for monitors to be used by mutex stmts
+	void ConcurrentSueKeyword::addLockUnlockRoutines( StructDecl * decl ) {
+		// this routine will be called for all ConcurrentSueKeyword children so only continue if we are a monitor
+		if ( !decl->is_monitor() ) return;
+
+		FunctionType * lock_fn_type = new FunctionType( noQualifiers, false );
+		FunctionType * unlock_fn_type = new FunctionType( noQualifiers, false );
+
+		// create this ptr parameter for both routines
+		ObjectDecl * this_decl = new ObjectDecl(
+			"this",
+			noStorageClasses,
+			LinkageSpec::Cforall,
+			nullptr,
+			new ReferenceType(
+				noQualifiers,
+				new StructInstType(
+					noQualifiers,
+					decl
+				)
+			),
+			nullptr
+		);
+
+		lock_fn_type->get_parameters().push_back( this_decl->clone() );
+		unlock_fn_type->get_parameters().push_back( this_decl->clone() );
+		fixupGenerics(lock_fn_type, decl);
+		fixupGenerics(unlock_fn_type, decl);
+
+		delete this_decl;
+
+
+		//////////////////////////////////////////////////////////////////////
+		// The following generates this lock routine for all monitors
+		/*
+			void lock (monitor_t & this) {
+				lock(get_monitor(this));
+			}	
+		*/
+		FunctionDecl * lock_decl = new FunctionDecl(
+			"lock",
+			Type::Static,
+			LinkageSpec::Cforall,
+			lock_fn_type,
+			nullptr,
+			{ },
+			Type::Inline
+		);
+
+		UntypedExpr * get_monitor_lock =  new UntypedExpr (
+			new NameExpr( "get_monitor" ),
+			{ new VariableExpr( lock_fn_type->get_parameters().front() ) }
+		);
+
+		CompoundStmt * lock_statement = new CompoundStmt();
+		lock_statement->push_back(
+			new ExprStmt( 
+				new UntypedExpr (
+					new NameExpr( "lock" ),
+					{
+						get_monitor_lock
+					}
+				)
+			)
+		);
+		lock_decl->set_statements( lock_statement );
+
+		//////////////////////////////////////////////////////////////////
+		// The following generates this routine for all monitors
+		/*
+			void unlock (monitor_t & this) {
+				unlock(get_monitor(this));
+			}	
+		*/
+		FunctionDecl * unlock_decl = new FunctionDecl(
+			"unlock",
+			Type::Static,
+			LinkageSpec::Cforall,
+			unlock_fn_type,
+			nullptr,
+			{ },
+			Type::Inline
+		);
+
+		CompoundStmt * unlock_statement = new CompoundStmt();
+
+		UntypedExpr * get_monitor_unlock =  new UntypedExpr (
+			new NameExpr( "get_monitor" ),
+			{ new VariableExpr( unlock_fn_type->get_parameters().front() ) }
+		);
+
+		unlock_statement->push_back(
+			new ExprStmt( 
+				new UntypedExpr(
+					new NameExpr( "unlock" ),
+					{
+						get_monitor_unlock
+					}
+				)
+			)
+		);
+		unlock_decl->set_statements( unlock_statement );
+		
+		// pushes routines to declsToAddAfter to add at a later time
+		declsToAddAfter.push_back( lock_decl );
+		declsToAddAfter.push_back( unlock_decl );
 	}
 
@@ -937,4 +1052,8 @@
 			assert( !thread_guard_decl );
 			thread_guard_decl = decl;
+		} 
+		else if ( decl->name == "__mutex_stmt_lock_guard" && decl->body ) {
+			assert( !lock_guard_decl );
+			lock_guard_decl = decl;
 		}
 	}
@@ -1081,7 +1200,9 @@
 				new PointerType(
 					noQualifiers,
-					new StructInstType(
-						noQualifiers,
-						monitor_decl
+					//new TypeofType( noQualifiers, args.front()->clone() )
+					new TypeofType( noQualifiers, new UntypedExpr(
+							new NameExpr( "__get_type" ),
+							{ args.front()->clone() }
+						) 
 					)
 				),
@@ -1093,10 +1214,22 @@
 				map_range < std::list<Initializer*> > ( args, [](Expression * var ){
 					return new SingleInit( new UntypedExpr(
-						new NameExpr( "get_monitor" ),
-						{ var }
+							new NameExpr( "__get_ptr" ),
+							{ var }
 					) );
+					//return new SingleInit( new AddressExpr( var ) );
 				})
 			)
 		);
+
+		StructInstType * lock_guard_struct = new StructInstType( noQualifiers, lock_guard_decl );
+		TypeExpr * lock_type_expr = new TypeExpr( 
+			new TypeofType( noQualifiers, new UntypedExpr(
+				new NameExpr( "__get_type" ),
+				{ args.front()->clone() }
+				) 
+			) 
+		);
+
+		lock_guard_struct->parameters.push_back( lock_type_expr ) ;
 
 		// in reverse order :
@@ -1108,8 +1241,5 @@
 				LinkageSpec::Cforall,
 				nullptr,
-				new StructInstType(
-					noQualifiers,
-					guard_decl
-				),
+				lock_guard_struct,
 				new ListInit(
 					{
Index: src/ControlStruct/ExceptTranslate.cc
===================================================================
--- src/ControlStruct/ExceptTranslate.cc	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ src/ControlStruct/ExceptTranslate.cc	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -5,5 +5,5 @@
 // file "LICENCE" distributed with Cforall.
 //
-// ExceptVisitor.cc --
+// ExceptTranslate.cc -- Conversion of exception control flow structures.
 //
 // Author           : Andrew Beach
Index: src/ControlStruct/ExceptTranslate.h
===================================================================
--- src/ControlStruct/ExceptTranslate.h	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ src/ControlStruct/ExceptTranslate.h	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -5,11 +5,11 @@
 // file "LICENCE" distributed with Cforall.
 //
-// ExceptTranslate.h --
+// ExceptTranslate.h -- Conversion of exception control flow structures.
 //
 // Author           : Andrew Beach
 // Created On       : Tus Jun 06 10:13:00 2017
 // Last Modified By : Andrew Beach
-// Last Modified On : Tus May 19 11:47:00 2020
-// Update Count     : 5
+// Last Modified On : Mon Nov  8 11:43:00 2020
+// Update Count     : 6
 //
 
@@ -19,7 +19,11 @@
 
 class Declaration;
+namespace ast {
+	class TranslationUnit;
+}
 
 namespace ControlStruct {
 	void translateThrows( std::list< Declaration *> & translationUnit );
+	void translateThrows( ast::TranslationUnit & transUnit );
 	/* Replaces all throw & throwResume statements with function calls.
 	 * These still need to be resolved, so call this before the reslover.
Index: src/ControlStruct/ExceptTranslateNew.cpp
===================================================================
--- src/ControlStruct/ExceptTranslateNew.cpp	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
+++ src/ControlStruct/ExceptTranslateNew.cpp	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -0,0 +1,142 @@
+//
+// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
+//
+// The contents of this file are covered under the licence agreement in the
+// file "LICENCE" distributed with Cforall.
+//
+// ExceptTranslateNew.cpp -- Conversion of exception control flow structures.
+//
+// Author           : Andrew Beach
+// Created On       : Mon Nov  8 11:53:00 2021
+// Last Modified By : Andrew Beach
+// Last Modified On : Mon Nov  8 16:50:00 2021
+// Update Count     : 0
+//
+
+#include "ExceptTranslate.h"
+
+#include "AST/Expr.hpp"
+#include "AST/Pass.hpp"
+#include "AST/Stmt.hpp"
+#include "AST/TranslationUnit.hpp"
+
+namespace ControlStruct {
+
+namespace {
+
+class TranslateThrowsCore : public ast::WithGuards {
+	const ast::ObjectDecl * terminateHandlerExcept;
+	enum Context { NoHandler, TerHandler, ResHandler } currentContext;
+
+	const ast::Stmt * createEitherThrow(
+		const ast::ThrowStmt * throwStmt, const char * funcName );
+	const ast::Stmt * createTerminateRethrow( const ast::ThrowStmt * );
+
+public:
+	TranslateThrowsCore() :
+		terminateHandlerExcept( nullptr ), currentContext( NoHandler )
+	{}
+
+	void previsit( const ast::CatchStmt * stmt );
+	const ast::Stmt * postvisit( const ast::ThrowStmt * stmt );
+};
+
+const ast::Stmt * TranslateThrowsCore::createEitherThrow(
+		const ast::ThrowStmt * throwStmt, const char * funcName ) {
+	// `throwFunc`( `throwStmt->name` );
+	ast::UntypedExpr * call = new ast::UntypedExpr( throwStmt->location,
+		new ast::NameExpr( throwStmt->location, funcName )
+	);
+	call->args.push_back( throwStmt->expr );
+	return new ast::ExprStmt( throwStmt->location, call );
+}
+
+ast::VariableExpr * varOf( const ast::DeclWithType * decl ) {
+	return new ast::VariableExpr( decl->location, decl );
+}
+
+const ast::Stmt * TranslateThrowsCore::createTerminateRethrow(
+		const ast::ThrowStmt * stmt ) {
+	// { `terminate_handler_except` = 0p; __rethrow_terminate(); }
+	assert( nullptr == stmt->expr );
+	assert( terminateHandlerExcept );
+
+	ast::CompoundStmt * result = new ast::CompoundStmt(
+		stmt->location, {}, std::vector<ast::Label>( stmt->labels ) );
+	result->push_back( new ast::ExprStmt( stmt->location,
+		ast::UntypedExpr::createAssign(
+			stmt->location,
+			varOf( terminateHandlerExcept ),
+			ast::ConstantExpr::null(
+				stmt->location,
+				terminateHandlerExcept->type
+			)
+		)
+	) );
+	result->push_back( new ast::ExprStmt( stmt->location, new ast::UntypedExpr(
+		stmt->location,
+		new ast::NameExpr( stmt->location, "__cfaehm_rethrow_terminate" )
+	) ) );
+	return result;
+}
+
+void TranslateThrowsCore::previsit( const ast::CatchStmt * stmt ) {
+	// Validate the statement's form.
+	const ast::ObjectDecl * decl = stmt->decl.as<ast::ObjectDecl>();
+	// Also checking the type would be nice.
+	if ( !decl || !decl->type.as<ast::PointerType>() ) {
+		std::string kind = (ast::Terminate == stmt->kind) ? "catch" : "catchResume";
+		SemanticError( stmt->location, kind + " must have pointer to an exception type" );
+	}
+
+	// Track the handler context.
+	if ( ast::Terminate == stmt->kind ) {
+		GuardValue( currentContext ) = TerHandler;
+		GuardValue( terminateHandlerExcept ) = decl;
+	} else {
+		GuardValue( currentContext ) = ResHandler;
+	}
+}
+
+const ast::Stmt * TranslateThrowsCore::postvisit(
+		const ast::ThrowStmt * stmt ) {
+	// Ignoring ThrowStmt::target for now.
+	// Handle Termination (Raise, Reraise, Error):
+	if ( ast::Terminate == stmt->kind ) {
+		if ( stmt->expr ) {
+			return createEitherThrow( stmt, "$throw" );
+		} else if ( TerHandler == currentContext ) {
+			return createTerminateRethrow( stmt );
+		} else {
+			abort( "Invalid throw in %s at %i\n",
+				stmt->location.filename.c_str(),
+				stmt->location.first_line);
+		}
+	// Handle Resumption (Raise, Reraise, Error):
+	} else {
+		if ( stmt->expr ) {
+			return createEitherThrow( stmt, "$throwResume" );
+		} else if ( ResHandler == currentContext ) {
+			// This has to be handled later.
+			return stmt;
+		} else {
+			abort( "Invalid throwResume in %s at %i\n",
+				stmt->location.filename.c_str(),
+				stmt->location.first_line);
+		}
+	}
+}
+
+} // namespace
+
+void translateThrows( ast::TranslationUnit & transUnit ) {
+	ast::Pass<TranslateThrowsCore>::run( transUnit );
+}
+
+} // namespace ControlStruct
+
+// Local Variables: //
+// tab-width: 4 //
+// mode: c++ //
+// compile-command: "make install" //
+// End: //
Index: src/ControlStruct/FixLabels.cpp
===================================================================
--- src/ControlStruct/FixLabels.cpp	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
+++ src/ControlStruct/FixLabels.cpp	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -0,0 +1,118 @@
+//
+// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
+//
+// The contents of this file are covered under the licence agreement in the
+// file "LICENCE" distributed with Cforall.
+//
+// FixLabels.cpp -- Normalizes labels and handles multi-level exit labels.
+//
+// Author           : Andrew Beach
+// Created On       : Mon Nov  1 09:39:00 2021
+// Last Modified By : Andrew Beach
+// Last Modified On : Mon Nov  8 10:53:00 2021
+// Update Count     : 3
+//
+
+#include "FixLabels.hpp"
+
+#include "AST/Label.hpp"
+#include "AST/Pass.hpp"
+#include "AST/Stmt.hpp"
+#include "ControlStruct/MultiLevelExit.hpp"
+
+namespace ControlStruct {
+
+namespace {
+
+class FixLabelsCore final : public ast::WithGuards {
+	LabelToStmt labelTable;
+public:
+	FixLabelsCore() : labelTable() {}
+
+	void previsit( const ast::FunctionDecl * );
+	const ast::FunctionDecl * postvisit( const ast::FunctionDecl * );
+	void previsit( const ast::Stmt * );
+	void previsit( const ast::BranchStmt * );
+	void previsit( const ast::LabelAddressExpr * );
+
+	void setLabelsDef( const std::vector<ast::Label> &, const ast::Stmt * );
+	void setLabelsUsage( const ast::Label & );
+};
+
+void FixLabelsCore::previsit( const ast::FunctionDecl * ) {
+	GuardValue( labelTable ).clear();
+}
+
+const ast::FunctionDecl * FixLabelsCore::postvisit(
+		const ast::FunctionDecl * decl ) {
+	if ( nullptr == decl->stmts ) return decl;
+	for ( auto kvp : labelTable ) {
+		if ( nullptr == kvp.second ) {
+			SemanticError( kvp.first.location,
+				"Use of undefined label: " + kvp.first.name );
+		}
+	}
+	return ast::mutate_field( decl, &ast::FunctionDecl::stmts,
+		multiLevelExitUpdate( decl->stmts.get(), labelTable ) );
+}
+
+void FixLabelsCore::previsit( const ast::Stmt * stmt ) {
+	if ( !stmt->labels.empty() ) {
+		setLabelsDef( stmt->labels, stmt );
+	}
+}
+
+void FixLabelsCore::previsit( const ast::BranchStmt * stmt ) {
+	if ( !stmt->labels.empty() ) {
+		setLabelsDef( stmt->labels, stmt );
+	}
+	if ( !stmt->target.empty() ) {
+		setLabelsUsage( stmt->target );
+	}
+}
+
+void FixLabelsCore::previsit( const ast::LabelAddressExpr * expr ) {
+	assert( !expr->arg.empty() );
+	setLabelsUsage( expr->arg );
+}
+
+void FixLabelsCore::setLabelsDef(
+		const std::vector<ast::Label> & labels, const ast::Stmt * stmt ) {
+	assert( !labels.empty() );
+	assert( stmt );
+
+	for ( auto label : labels ) {
+		if ( labelTable.find( label ) == labelTable.end() ) {
+			// Make sure to only create the entry once.
+			labelTable[ label ] = stmt;
+		} else if ( nullptr != labelTable[ label ] ) {
+			// Duplicate definition, this is an error.
+			SemanticError( label.location,
+				"Duplicate definition of label: " + label.name );
+		} else {
+			// Perviously used, but not defined until now.
+			labelTable[ label ] = stmt;
+		}
+	}
+}
+
+// Label was used, if it is new add it to the table.
+void FixLabelsCore::setLabelsUsage( const ast::Label & label ) {
+	if ( labelTable.find( label ) == labelTable.end() ) {
+		labelTable[ label ] = nullptr;
+	}
+}
+
+} // namespace
+
+void fixLabels( ast::TranslationUnit & translationUnit ) {
+	ast::Pass<FixLabelsCore>::run( translationUnit );
+}
+
+} // namespace ControlStruct
+
+// Local Variables: //
+// tab-width: 4 //
+// mode: c++ //
+// compile-command: "make install" //
+// End: //
Index: src/ControlStruct/FixLabels.hpp
===================================================================
--- src/ControlStruct/FixLabels.hpp	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
+++ src/ControlStruct/FixLabels.hpp	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -0,0 +1,33 @@
+//
+// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
+//
+// The contents of this file are covered under the licence agreement in the
+// file "LICENCE" distributed with Cforall.
+//
+// FixLabels.hpp -- Normalizes labels and handles multi-level exit labels.
+//
+// Author           : Andrew Beach
+// Created On       : Mon Nov  1 09:36:00 2021
+// Last Modified By : Andrew Beach
+// Last Modified On : Mon Nov  1 09:40:00 2021
+// Update Count     : 0
+//
+
+#pragma once
+
+namespace ast {
+	class TranslationUnit;
+}
+
+namespace ControlStruct {
+
+/// normalizes label definitions and generates multi-level exit labels
+void fixLabels( ast::TranslationUnit & translationUnit );
+
+}
+
+// Local Variables: //
+// tab-width: 4 //
+// mode: c++ //
+// compile-command: "make install" //
+// End: //
Index: src/ControlStruct/LabelGenerator.cc
===================================================================
--- src/ControlStruct/LabelGenerator.cc	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ src/ControlStruct/LabelGenerator.cc	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -9,7 +9,7 @@
 // Author           : Rodolfo G. Esteves
 // Created On       : Mon May 18 07:44:20 2015
-// Last Modified By : Peter A. Buhr
-// Last Modified On : Mon Mar 11 22:23:20 2019
-// Update Count     : 15
+// Last Modified By : Andrew Beach
+// Last Modified On : Mon Nov  8 10:18:00 2021
+// Update Count     : 17
 //
 
@@ -19,4 +19,8 @@
 
 #include "LabelGenerator.h"
+
+#include "AST/Attribute.hpp"
+#include "AST/Label.hpp"
+#include "AST/Stmt.hpp"
 #include "SynTree/Attribute.h"  // for Attribute
 #include "SynTree/Label.h"      // for Label, operator<<
@@ -24,5 +28,7 @@
 
 namespace ControlStruct {
-	LabelGenerator * LabelGenerator::labelGenerator = 0;
+
+int LabelGenerator::current = 0;
+LabelGenerator * LabelGenerator::labelGenerator = nullptr;
 
 	LabelGenerator * LabelGenerator::getGenerator() {
@@ -43,4 +49,19 @@
 		return l;
 	}
+
+ast::Label LabelGenerator::newLabel(
+		const std::string & suffix, const ast::Stmt * stmt ) {
+	assert( stmt );
+
+	std::ostringstream os;
+	os << "__L" << current++ << "__" << suffix;
+	if ( stmt && !stmt->labels.empty() ) {
+		os << "_" << stmt->labels.front() << "__";
+	}
+	ast::Label ret_label( stmt->location, os.str() );
+	ret_label.attributes.push_back( new ast::Attribute( "unused" ) );
+	return ret_label;
+}
+
 } // namespace ControlStruct
 
Index: src/ControlStruct/LabelGenerator.h
===================================================================
--- src/ControlStruct/LabelGenerator.h	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ src/ControlStruct/LabelGenerator.h	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -9,7 +9,7 @@
 // Author           : Rodolfo G. Esteves
 // Created On       : Mon May 18 07:44:20 2015
-// Last Modified By : Peter A. Buhr
-// Last Modified On : Sat Jul 22 09:20:14 2017
-// Update Count     : 6
+// Last Modified By : Andrew Beach
+// Last Modified On : Mon Nov  8 10:16:00 2021
+// Update Count     : 8
 //
 
@@ -21,18 +21,24 @@
 
 class Statement;
+namespace ast {
+	class Stmt;
+	class Label;
+}
 
 namespace ControlStruct {
-	class LabelGenerator {
-	  public:
-		static LabelGenerator *getGenerator();
-		Label newLabel(std::string suffix, Statement * stmt = nullptr);
-		void reset() { current = 0; }
-		void rewind() { current--; }
-	  protected:
-		LabelGenerator(): current(0) {}
-	  private:
-		int current;
-		static LabelGenerator *labelGenerator;
-	};
+
+class LabelGenerator {
+	static int current;
+	static LabelGenerator *labelGenerator;
+protected:
+	LabelGenerator() {}
+public:
+	static LabelGenerator *getGenerator();
+	static Label newLabel(std::string suffix, Statement * stmt = nullptr);
+	static ast::Label newLabel( const std::string&, const ast::Stmt * );
+	static void reset() { current = 0; }
+	static void rewind() { current--; }
+};
+
 } // namespace ControlStruct
 
Index: src/ControlStruct/MultiLevelExit.cpp
===================================================================
--- src/ControlStruct/MultiLevelExit.cpp	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
+++ src/ControlStruct/MultiLevelExit.cpp	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -0,0 +1,620 @@
+//
+// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
+//
+// The contents of this file are covered under the licence agreement in the
+// file "LICENCE" distributed with Cforall.
+//
+// MultiLevelExit.cpp -- Replaces CFA's local control flow with C's versions.
+//
+// Author           : Andrew Beach
+// Created On       : Mon Nov  1 13:48:00 2021
+// Last Modified By : Andrew Beach
+// Last Modified On : Mon Nov  8 10:56:00 2021
+// Update Count     : 2
+//
+
+#include "MultiLevelExit.hpp"
+
+#include "AST/Pass.hpp"
+#include "AST/Stmt.hpp"
+#include "ControlStruct/LabelGenerator.h"
+
+#include <set>
+
+namespace ControlStruct {
+
+namespace {
+
+class Entry {
+public:
+	const ast::Stmt * stmt;
+private:
+	// Organized like a manual ADT. Avoids creating a bunch of dead data.
+	struct Target {
+		ast::Label label;
+		bool used = false;
+		Target( const ast::Label & label ) : label( label ) {}
+		Target() : label( CodeLocation() ) {}
+	};
+	Target firstTarget;
+	Target secondTarget;
+
+	enum Kind {
+		ForStmt, WhileStmt, CompoundStmt, IfStmt, CaseStmt, SwitchStmt, TryStmt
+	} kind;
+
+	bool fallDefaultValid = true;
+
+	static ast::Label & useTarget( Target & target ) {
+		target.used = true;
+		return target.label;
+	}
+
+public:
+	Entry( const ast::ForStmt * stmt, ast::Label breakExit, ast::Label contExit ) :
+		stmt( stmt ), firstTarget( breakExit ), secondTarget( contExit ), kind( ForStmt ) {}
+	Entry( const ast::WhileStmt * stmt, ast::Label breakExit, ast::Label contExit ) :
+		stmt( stmt ), firstTarget( breakExit ), secondTarget( contExit ), kind( WhileStmt ) {}
+	Entry( const ast::CompoundStmt *stmt, ast::Label breakExit ) :
+		stmt( stmt ), firstTarget( breakExit ), secondTarget(), kind( CompoundStmt ) {}
+	Entry( const ast::IfStmt *stmt, ast::Label breakExit ) :
+		stmt( stmt ), firstTarget( breakExit ), secondTarget(), kind( IfStmt ) {}
+	Entry( const ast::CaseStmt *stmt, ast::Label fallExit ) :
+		stmt( stmt ), firstTarget( fallExit ), secondTarget(), kind( CaseStmt ) {}
+	Entry( const ast::SwitchStmt *stmt, ast::Label breakExit, ast::Label fallDefaultExit ) :
+		stmt( stmt ), firstTarget( breakExit ), secondTarget( fallDefaultExit ), kind( SwitchStmt ) {}
+	Entry( const ast::TryStmt *stmt, ast::Label breakExit ) :
+		stmt( stmt ), firstTarget( breakExit ), secondTarget(), kind( TryStmt ) {}
+
+	bool isContTarget() const { return kind <= WhileStmt; }
+	bool isBreakTarget() const { return CaseStmt != kind; }
+	bool isFallTarget() const { return CaseStmt == kind; }
+	bool isFallDefaultTarget() const { return SwitchStmt == kind; }
+
+	ast::Label useContExit() { assert( kind <= WhileStmt ); return useTarget(secondTarget); }
+	ast::Label useBreakExit() { assert( CaseStmt != kind ); return useTarget(firstTarget); }
+	ast::Label useFallExit() { assert( CaseStmt == kind );  return useTarget(firstTarget); }
+	ast::Label useFallDefaultExit() { assert( SwitchStmt == kind ); return useTarget(secondTarget); }
+
+	bool isContUsed() const { assert( kind <= WhileStmt ); return secondTarget.used; }
+	bool isBreakUsed() const { assert( CaseStmt != kind ); return firstTarget.used; }
+	bool isFallUsed() const { assert( CaseStmt == kind ); return firstTarget.used; }
+	bool isFallDefaultUsed() const { assert( SwitchStmt == kind ); return secondTarget.used; }
+	void seenDefault() { fallDefaultValid = false; }
+	bool isFallDefaultValid() const { return fallDefaultValid; }
+};
+
+// Helper predicates used in std::find_if calls (it doesn't take methods):
+bool isBreakTarget( const Entry & entry ) {
+	return entry.isBreakTarget();
+}
+
+bool isContinueTarget( const Entry & entry ) {
+	return entry.isContTarget();
+}
+
+bool isFallthroughTarget( const Entry & entry ) {
+	return entry.isFallTarget();
+}
+
+bool isFallthroughDefaultTarget( const Entry & entry ) {
+	return entry.isFallDefaultTarget();
+}
+
+struct MultiLevelExitCore final :
+		public ast::WithVisitorRef<MultiLevelExitCore>,
+		public ast::WithShortCircuiting, public ast::WithGuards {
+	MultiLevelExitCore( const LabelToStmt & lt );
+
+	void previsit( const ast::FunctionDecl * );
+
+	const ast::CompoundStmt * previsit( const ast::CompoundStmt * );
+	const ast::BranchStmt * postvisit( const ast::BranchStmt * );
+	void previsit( const ast::WhileStmt * );
+	const ast::WhileStmt * postvisit( const ast::WhileStmt * );
+	void previsit( const ast::ForStmt * );
+	const ast::ForStmt * postvisit( const ast::ForStmt * );
+	const ast::CaseStmt * previsit( const ast::CaseStmt * );
+	void previsit( const ast::IfStmt * );
+	const ast::IfStmt * postvisit( const ast::IfStmt * );
+	void previsit( const ast::SwitchStmt * );
+	const ast::SwitchStmt * postvisit( const ast::SwitchStmt * );
+	void previsit( const ast::ReturnStmt * );
+	void previsit( const ast::TryStmt * );
+	void postvisit( const ast::TryStmt * );
+	void previsit( const ast::FinallyStmt * );
+
+	const ast::Stmt * mutateLoop( const ast::Stmt * body, Entry& );
+
+	const LabelToStmt & target_table;
+	std::set<ast::Label> fallthrough_labels;
+	std::vector<Entry> enclosing_control_structures;
+	ast::Label break_label;
+	bool inFinally;
+
+	template<typename LoopNode>
+	void prehandleLoopStmt( const LoopNode * loopStmt );
+	template<typename LoopNode>
+	const LoopNode * posthandleLoopStmt( const LoopNode * loopStmt );
+
+	std::list<ast::ptr<ast::Stmt>> fixBlock(
+		const std::list<ast::ptr<ast::Stmt>> & kids, bool caseClause );
+
+	template<typename UnaryPredicate>
+	auto findEnclosingControlStructure( UnaryPredicate pred ) {
+		return std::find_if( enclosing_control_structures.rbegin(),
+			enclosing_control_structures.rend(), pred );
+	}
+};
+
+ast::NullStmt * labelledNullStmt(
+		const CodeLocation & cl, const ast::Label & label ) {
+	return new ast::NullStmt( cl, std::vector<ast::Label>{ label } );
+}
+
+MultiLevelExitCore::MultiLevelExitCore( const LabelToStmt & lt ) :
+	target_table( lt ), break_label( CodeLocation(), "" ),
+	inFinally( false )
+{}
+
+void MultiLevelExitCore::previsit( const ast::FunctionDecl * ) {
+	visit_children = false;
+}
+
+const ast::CompoundStmt * MultiLevelExitCore::previsit(
+		const ast::CompoundStmt * stmt ) {
+	visit_children = false;
+	bool isLabeled = !stmt->labels.empty();
+	if ( isLabeled ) {
+		ast::Label breakLabel = LabelGenerator::newLabel( "blockBreak", stmt );
+		enclosing_control_structures.emplace_back( stmt, breakLabel );
+		GuardAction( [this]() { enclosing_control_structures.pop_back(); } );
+	}
+
+	auto mutStmt = ast::mutate( stmt );
+	// A child statement may set the break label.
+	mutStmt->kids = std::move( fixBlock( stmt->kids, false ) );
+
+	if ( isLabeled ) {
+		assert( !enclosing_control_structures.empty() );
+		Entry & entry = enclosing_control_structures.back();
+		if ( !entry.useBreakExit().empty() ) {
+			break_label = entry.useBreakExit();
+		}
+	}
+	return mutStmt;
+}
+
+size_t getUnusedIndex(
+		const ast::Stmt * stmt, const ast::Label & originalTarget ) {
+	const size_t size = stmt->labels.size();
+
+	// If the label is empty, we can skip adding the unused attribute:
+	if ( originalTarget.empty() ) return size;
+
+	// Search for a label that matches the originalTarget.
+	for ( size_t i = 0 ; i < size ; ++i ) {
+		const ast::Label & label = stmt->labels[i];
+		if ( label == originalTarget ) {
+			for ( const ast::Attribute * attr : label.attributes ) {
+				if ( attr->name == "unused" ) return size;
+			}
+			return i;
+		}
+	}
+	assertf( false, "Could not find label '%s' on statement %s",
+		originalTarget.name.c_str(), toString( stmt ).c_str() );
+}
+
+const ast::Stmt * addUnused(
+		const ast::Stmt * stmt, const ast::Label & originalTarget ) {
+	size_t i = getUnusedIndex( stmt, originalTarget );
+	if ( i == stmt->labels.size() ) {
+		return stmt;
+	}
+	ast::Stmt * mutStmt = ast::mutate( stmt );
+	mutStmt->labels[i].attributes.push_back( new ast::Attribute( "unused" ) );
+	return mutStmt;
+}
+
+const ast::BranchStmt * MultiLevelExitCore::postvisit( const ast::BranchStmt * stmt ) {
+	std::vector<Entry>::reverse_iterator targetEntry =
+		enclosing_control_structures.rend();
+	switch ( stmt->kind ) {
+	case ast::BranchStmt::Goto:
+		return stmt;
+	case ast::BranchStmt::Continue:
+	case ast::BranchStmt::Break: {
+		bool isContinue = stmt->kind == ast::BranchStmt::Continue;
+		// Handle unlabeled break and continue.
+		if ( stmt->target.empty() ) {
+			if ( isContinue ) {
+				targetEntry = findEnclosingControlStructure( isContinueTarget );
+			} else {
+				if ( enclosing_control_structures.empty() ) {
+					SemanticError( stmt->location,
+						"'break' outside a loop, 'switch', or labelled block" );
+				}
+				targetEntry = findEnclosingControlStructure( isBreakTarget );
+			}
+		// Handle labeled break and continue.
+		} else {
+			// Lookup label in table to find attached control structure.
+			targetEntry = findEnclosingControlStructure(
+				[ targetStmt = target_table.at(stmt->target) ](auto entry){
+					return entry.stmt == targetStmt;
+				} );
+		}
+		// Ensure that selected target is valid.
+		if ( targetEntry == enclosing_control_structures.rend() || ( isContinue && !isContinueTarget( *targetEntry ) ) ) {
+			SemanticError(
+				stmt->location,
+				toString( (isContinue ? "'continue'" : "'break'"),
+					" target must be an enclosing ",
+					(isContinue ? "loop: " : "control structure: "),
+					stmt->originalTarget ) );
+		}
+		break;
+	}
+	case ast::BranchStmt::FallThrough: {
+		targetEntry = findEnclosingControlStructure( isFallthroughTarget );
+		// Check that target is valid.
+		if ( targetEntry == enclosing_control_structures.rend() ) {
+			SemanticError( stmt->location, "'fallthrough' must be enclosed in a 'switch' or 'choose'" );
+		}
+		if ( !stmt->target.empty() ) {
+			// Labelled fallthrough: target must be a valid fallthough label.
+			if ( !fallthrough_labels.count( stmt->target ) ) {
+				SemanticError( stmt->location, toString( "'fallthrough' target must be a later case statement: ", stmt->originalTarget ) );
+			}
+			return new ast::BranchStmt(
+				stmt->location, ast::BranchStmt::Goto, stmt->originalTarget );
+		}
+		break;
+	}
+	case ast::BranchStmt::FallThroughDefault: {
+		targetEntry = findEnclosingControlStructure( isFallthroughDefaultTarget );
+
+		// Check that this is in a switch or choose statement.
+		if ( targetEntry == enclosing_control_structures.rend() ) {
+			SemanticError( stmt->location, "'fallthrough' must be enclosed in a 'switch' or 'choose'" );
+		}
+
+		// Check that the switch or choose has a default clause.
+		auto switchStmt = strict_dynamic_cast< const ast::SwitchStmt * >(
+			targetEntry->stmt );
+		bool foundDefault = false;
+		for ( auto subStmt : switchStmt->stmts ) {
+			const ast::CaseStmt * caseStmt = subStmt.strict_as<ast::CaseStmt>();
+			if ( caseStmt->isDefault() ) {
+				foundDefault = true;
+				break;
+			}
+		}
+		if ( !foundDefault ) {
+			SemanticError( stmt->location, "'fallthrough default' must be enclosed in a 'switch' or 'choose' control structure with a 'default' clause" );
+		}
+		break;
+	}
+	default:
+		assert( false );
+	}
+
+	// Branch error checks: get the appropriate label name:
+	// (This label will always be replaced.)
+	ast::Label exitLabel( CodeLocation(), "" );
+	switch ( stmt->kind ) {
+	case ast::BranchStmt::Break:
+		assert( !targetEntry->useBreakExit().empty() );
+		exitLabel = targetEntry->useBreakExit();
+		break;
+	case ast::BranchStmt::Continue:
+		assert( !targetEntry->useContExit().empty() );
+		exitLabel = targetEntry->useContExit();
+		break;
+	case ast::BranchStmt::FallThrough:
+		assert( !targetEntry->useFallExit().empty() );
+		exitLabel = targetEntry->useFallExit();
+		break;
+	case ast::BranchStmt::FallThroughDefault:
+		assert( !targetEntry->useFallDefaultExit().empty() );
+		exitLabel = targetEntry->useFallDefaultExit();
+		// Check that fallthrough default comes before the default clause.
+		if ( !targetEntry->isFallDefaultValid() ) {
+			SemanticError( stmt->location,
+				"'fallthrough default' must precede the 'default' clause" );
+		}
+		break;
+	default:
+		assert(0);
+	}
+
+	// Add unused attribute to silence warnings.
+	targetEntry->stmt = addUnused( targetEntry->stmt, stmt->originalTarget );
+
+	// Replace this with a goto to make later passes more uniform.
+	return new ast::BranchStmt( stmt->location, ast::BranchStmt::Goto, exitLabel );
+}
+
+void MultiLevelExitCore::previsit( const ast::WhileStmt * stmt ) {
+	return prehandleLoopStmt( stmt );
+}
+
+const ast::WhileStmt * MultiLevelExitCore::postvisit( const ast::WhileStmt * stmt ) {
+	return posthandleLoopStmt( stmt );
+}
+
+void MultiLevelExitCore::previsit( const ast::ForStmt * stmt ) {
+	return prehandleLoopStmt( stmt );
+}
+
+const ast::ForStmt * MultiLevelExitCore::postvisit( const ast::ForStmt * stmt ) {
+	return posthandleLoopStmt( stmt );
+}
+
+// Mimic what the built-in push_front would do anyways. It is O(n).
+void push_front(
+		std::vector<ast::ptr<ast::Stmt>> & vec, const ast::Stmt * element ) {
+	vec.emplace_back( nullptr );
+	for ( size_t i = vec.size() - 1 ; 0 < i ; --i ) {
+		vec[ i ] = std::move( vec[ i - 1 ] );
+	}
+	vec[ 0 ] = element;
+}
+
+const ast::CaseStmt * MultiLevelExitCore::previsit( const ast::CaseStmt * stmt ) {
+	visit_children = false;
+
+	// If it is the default, mark the default as seen.
+	if ( stmt->isDefault() ) {
+		assert( !enclosing_control_structures.empty() );
+		enclosing_control_structures.back().seenDefault();
+	}
+
+	// The cond may not exist, but if it does update it now.
+	visitor->maybe_accept( stmt, &ast::CaseStmt::cond );
+
+	// Just save the mutated node for simplicity.
+	ast::CaseStmt * mutStmt = ast::mutate( stmt );
+
+	ast::Label fallLabel = LabelGenerator::newLabel( "fallThrough", stmt );
+	if ( !mutStmt->stmts.empty() ) {
+		// Ensure that the stack isn't corrupted by exceptions in fixBlock.
+		auto guard = makeFuncGuard(
+			[&](){ enclosing_control_structures.emplace_back( mutStmt, fallLabel ); },
+			[this](){ enclosing_control_structures.pop_back(); }
+		);
+
+		// These should already be in a block.
+		auto block = ast::mutate( mutStmt->stmts.front().strict_as<ast::CompoundStmt>() );
+		block->kids = fixBlock( block->kids, true );
+
+		// Add fallthrough label if necessary.
+		assert( !enclosing_control_structures.empty() );
+		Entry & entry = enclosing_control_structures.back();
+		if ( entry.isFallUsed() ) {
+			mutStmt->stmts.push_back(
+				labelledNullStmt( mutStmt->location, entry.useFallExit() ) );
+		}
+	}
+	assert( !enclosing_control_structures.empty() );
+	Entry & entry = enclosing_control_structures.back();
+	assertf( dynamic_cast< const ast::SwitchStmt * >( entry.stmt ),
+		"Control structure enclosing a case clause must be a switch, but is: %s",
+		toString( entry.stmt ).c_str() );
+	if ( mutStmt->isDefault() ) {
+		if ( entry.isFallDefaultUsed() ) {
+			// Add fallthrough default label if necessary.
+			push_front( mutStmt->stmts, labelledNullStmt(
+				stmt->location, entry.useFallDefaultExit()
+			) );
+		}
+	}
+	return mutStmt;
+}
+
+void MultiLevelExitCore::previsit( const ast::IfStmt * stmt ) {
+	bool labeledBlock = !stmt->labels.empty();
+	if ( labeledBlock ) {
+		ast::Label breakLabel = LabelGenerator::newLabel( "blockBreak", stmt );
+		enclosing_control_structures.emplace_back( stmt, breakLabel );
+		GuardAction( [this](){ enclosing_control_structures.pop_back(); } );
+	}
+}
+
+const ast::IfStmt * MultiLevelExitCore::postvisit( const ast::IfStmt * stmt ) {
+	bool labeledBlock = !stmt->labels.empty();
+	if ( labeledBlock ) {
+		auto this_label = enclosing_control_structures.back().useBreakExit();
+		if ( !this_label.empty() ) {
+			break_label = this_label;
+		}
+	}
+	return stmt;
+}
+
+bool isDefaultCase( const ast::ptr<ast::Stmt> & stmt ) {
+	const ast::CaseStmt * caseStmt = stmt.strict_as<ast::CaseStmt>();
+	return caseStmt->isDefault();
+}
+
+void MultiLevelExitCore::previsit( const ast::SwitchStmt * stmt ) {
+	ast::Label label = LabelGenerator::newLabel( "switchBreak", stmt );
+	auto it = std::find_if( stmt->stmts.rbegin(), stmt->stmts.rend(), isDefaultCase );
+
+	const ast::CaseStmt * defaultCase = it != stmt->stmts.rend()
+		? (it)->strict_as<ast::CaseStmt>() : nullptr;
+	ast::Label defaultLabel = defaultCase
+		? LabelGenerator::newLabel( "fallThroughDefault", defaultCase )
+		: ast::Label( stmt->location, "" );
+	enclosing_control_structures.emplace_back( stmt, label, defaultLabel );
+	GuardAction( [this]() { enclosing_control_structures.pop_back(); } );
+
+	// Collect valid labels for fallthrough. It starts with all labels at
+	// this level, then removed as we see them in traversal.
+	for ( const ast::Stmt * stmt : stmt->stmts ) {
+		auto * caseStmt = strict_dynamic_cast< const ast::CaseStmt * >( stmt );
+		if ( caseStmt->stmts.empty() ) continue;
+		auto block = caseStmt->stmts.front().strict_as<ast::CompoundStmt>();
+		for ( const ast::Stmt * stmt : block->kids ) {
+			for ( const ast::Label & l : stmt->labels ) {
+				fallthrough_labels.insert( l );
+			}
+		}
+	}
+}
+
+const ast::SwitchStmt * MultiLevelExitCore::postvisit( const ast::SwitchStmt * stmt ) {
+	assert( !enclosing_control_structures.empty() );
+	Entry & entry = enclosing_control_structures.back();
+	assert( entry.stmt == stmt );
+
+	// Only run if we need to generate the break label.
+	if ( entry.isBreakUsed() ) {
+		// To keep the switch statements uniform (all direct children of a
+		// SwitchStmt should be CastStmts), append the exit label and break
+		// to the last case, create a default case is there are no cases.
+		ast::SwitchStmt * mutStmt = ast::mutate( stmt );
+		if ( mutStmt->stmts.empty() ) {
+			mutStmt->stmts.push_back( new ast::CaseStmt(
+				mutStmt->location, nullptr, {} ));
+		}
+
+		auto caseStmt = mutStmt->stmts.back().strict_as<ast::CaseStmt>();
+		auto mutCase = ast::mutate( caseStmt );
+		mutStmt->stmts.back() = mutCase;
+
+		ast::Label label( mutCase->location, "breakLabel" );
+		auto branch = new ast::BranchStmt( mutCase->location, ast::BranchStmt::Break, label );
+		branch->labels.push_back( entry.useBreakExit() );
+		mutCase->stmts.push_back( branch );
+
+		return mutStmt;
+	}
+	return stmt;
+}
+
+void MultiLevelExitCore::previsit( const ast::ReturnStmt * stmt ) {
+	if ( inFinally ) {
+		SemanticError( stmt->location, "'return' may not appear in a finally clause" );
+	}
+}
+
+void MultiLevelExitCore::previsit( const ast::TryStmt * stmt ) {
+	bool isLabeled = !stmt->labels.empty();
+	if ( isLabeled ) {
+		ast::Label breakLabel = LabelGenerator::newLabel( "blockBreak", stmt );
+		enclosing_control_structures.emplace_back( stmt, breakLabel );
+		GuardAction([this](){ enclosing_control_structures.pop_back(); } );
+	}
+}
+
+void MultiLevelExitCore::postvisit( const ast::TryStmt * stmt ) {
+	bool isLabeled = !stmt->labels.empty();
+	if ( isLabeled ) {
+		auto this_label = enclosing_control_structures.back().useBreakExit();
+		if ( !this_label.empty() ) {
+			break_label = this_label;
+		}
+	}
+}
+
+void MultiLevelExitCore::previsit( const ast::FinallyStmt * ) {
+	GuardAction([this, old = std::move(enclosing_control_structures)](){
+		enclosing_control_structures = std::move(old);
+	});
+	enclosing_control_structures = std::vector<Entry>();
+	GuardValue( inFinally ) = true;
+}
+
+const ast::Stmt * MultiLevelExitCore::mutateLoop(
+		const ast::Stmt * body, Entry & entry ) {
+	if ( entry.isBreakUsed() ) {
+		break_label = entry.useBreakExit();
+	}
+
+	if ( entry.isContUsed() ) {
+		ast::CompoundStmt * new_body = new ast::CompoundStmt( body->location );
+		new_body->kids.push_back( body );
+		new_body->kids.push_back(
+			labelledNullStmt( body->location, entry.useContExit() ) );
+		return new_body;
+	}
+
+	return body;
+}
+
+template<typename LoopNode>
+void MultiLevelExitCore::prehandleLoopStmt( const LoopNode * loopStmt ) {
+	// Remember is loop before going onto mutate the body.
+	// The labels will be folded in if they are used.
+	ast::Label breakLabel = LabelGenerator::newLabel( "loopBreak", loopStmt );
+	ast::Label contLabel = LabelGenerator::newLabel( "loopContinue", loopStmt );
+	enclosing_control_structures.emplace_back( loopStmt, breakLabel, contLabel );
+	GuardAction( [this](){ enclosing_control_structures.pop_back(); } );
+}
+
+template<typename LoopNode>
+const LoopNode * MultiLevelExitCore::posthandleLoopStmt( const LoopNode * loopStmt ) {
+	assert( !enclosing_control_structures.empty() );
+	Entry & entry = enclosing_control_structures.back();
+	assert( entry.stmt == loopStmt );
+
+	// Now we check if the labels are used and add them if so.
+	return ast::mutate_field(
+		loopStmt, &LoopNode::body, mutateLoop( loopStmt->body, entry ) );
+}
+
+std::list<ast::ptr<ast::Stmt>> MultiLevelExitCore::fixBlock(
+		const std::list<ast::ptr<ast::Stmt>> & kids, bool is_case_clause ) {
+	// Unfortunately we can't use the automatic error collection.
+	SemanticErrorException errors;
+
+	std::list<ast::ptr<ast::Stmt>> ret;
+
+	// Manually visit each child.
+	for ( const ast::ptr<ast::Stmt> & kid : kids ) {
+		if ( is_case_clause ) {
+			// Once a label is seen, it's no longer a valid for fallthrough.
+			for ( const ast::Label & l : kid->labels ) {
+				fallthrough_labels.erase( l );
+			}
+		}
+
+		try {
+			ret.push_back( kid->accept( *visitor ) );
+		} catch ( SemanticErrorException & e ) {
+			errors.append( e );
+		}
+
+		if ( !break_label.empty() ) {
+			ret.push_back(
+				labelledNullStmt( ret.back()->location, break_label ) );
+			break_label = ast::Label( CodeLocation(), "" );
+		}
+	}
+
+	if ( !errors.isEmpty() ) {
+		throw errors;
+	}
+	return ret;
+}
+
+} // namespace
+
+const ast::CompoundStmt * multiLevelExitUpdate(
+    	const ast::CompoundStmt * stmt,
+		const LabelToStmt & labelTable ) {
+	// Must start in the body, so FunctionDecls can be a stopping point.
+	ast::Pass<MultiLevelExitCore> visitor( labelTable );
+	const ast::CompoundStmt * ret = stmt->accept( visitor );
+	return ret;
+}
+
+} // namespace ControlStruct
+
+// Local Variables: //
+// tab-width: 4 //
+// mode: c++ //
+// compile-command: "make install" //
+// End: //
Index: src/ControlStruct/MultiLevelExit.hpp
===================================================================
--- src/ControlStruct/MultiLevelExit.hpp	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
+++ src/ControlStruct/MultiLevelExit.hpp	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -0,0 +1,40 @@
+//
+// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
+//
+// The contents of this file are covered under the licence agreement in the
+// file "LICENCE" distributed with Cforall.
+//
+// MultiLevelExit.hpp -- Replaces CFA's local control flow with C's versions.
+//
+// Author           : Andrew Beach
+// Created On       : Mon Nov  1 13:49:00 2021
+// Last Modified By : Andrew Beach
+// Last Modified On : Mon Nov  8 10:53:00 2021
+// Update Count     : 3
+//
+
+#pragma once
+
+#include <map>
+
+namespace ast {
+	class CompoundStmt;
+	class Label;
+	class Stmt;
+}
+
+namespace ControlStruct {
+
+using LabelToStmt = std::map<ast::Label, const ast::Stmt *>;
+
+/// Mutate a function body to handle multi-level exits.
+const ast::CompoundStmt * multiLevelExitUpdate(
+	const ast::CompoundStmt *, const LabelToStmt & );
+
+}
+
+// Local Variables: //
+// tab-width: 4 //
+// mode: c++ //
+// compile-command: "make install" //
+// End: //
Index: src/ControlStruct/module.mk
===================================================================
--- src/ControlStruct/module.mk	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ src/ControlStruct/module.mk	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -18,4 +18,6 @@
 	ControlStruct/ExceptDecl.cc \
 	ControlStruct/ExceptDecl.h \
+	ControlStruct/FixLabels.cpp \
+	ControlStruct/FixLabels.hpp \
 	ControlStruct/ForExprMutator.cc \
 	ControlStruct/ForExprMutator.h \
@@ -26,8 +28,14 @@
 	ControlStruct/MLEMutator.cc \
 	ControlStruct/MLEMutator.h \
+	ControlStruct/MultiLevelExit.cpp \
+	ControlStruct/MultiLevelExit.hpp \
 	ControlStruct/Mutate.cc \
 	ControlStruct/Mutate.h
 
-SRC += $(SRC_CONTROLSTRUCT) ControlStruct/ExceptTranslate.cc ControlStruct/ExceptTranslate.h
+SRC += $(SRC_CONTROLSTRUCT) \
+	ControlStruct/ExceptTranslateNew.cpp \
+	ControlStruct/ExceptTranslate.cc \
+	ControlStruct/ExceptTranslate.h
+
 SRCDEMANGLE += $(SRC_CONTROLSTRUCT)
 
Index: src/InitTweak/GenInit.cc
===================================================================
--- src/InitTweak/GenInit.cc	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ src/InitTweak/GenInit.cc	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -9,7 +9,7 @@
 // Author           : Rob Schluntz
 // Created On       : Mon May 18 07:44:20 2015
-// Last Modified By : Peter A. Buhr
-// Last Modified On : Fri Dec 13 23:15:10 2019
-// Update Count     : 184
+// Last Modified By : Andrew Beach
+// Last Modified On : Mon Oct 25 13:53:00 2021
+// Update Count     : 186
 //
 #include "GenInit.h"
@@ -24,4 +24,5 @@
 #include "AST/Decl.hpp"
 #include "AST/Init.hpp"
+#include "AST/Pass.hpp"
 #include "AST/Node.hpp"
 #include "AST/Stmt.hpp"
@@ -294,4 +295,133 @@
 	}
 
+namespace {
+
+#	warning Remove the _New suffix after the conversion is complete.
+	struct HoistArrayDimension_NoResolve_New final :
+			public ast::WithDeclsToAdd<>, public ast::WithShortCircuiting,
+			public ast::WithGuards, public ast::WithConstTranslationUnit,
+			public ast::WithVisitorRef<HoistArrayDimension_NoResolve_New> {
+		void previsit( const ast::ObjectDecl * decl );
+		const ast::DeclWithType * postvisit( const ast::ObjectDecl * decl );
+		// Do not look for objects inside there declarations (and type).
+		void previsit( const ast::AggregateDecl * ) { visit_children = false; }
+		void previsit( const ast::NamedTypeDecl * ) { visit_children = false; }
+		void previsit( const ast::FunctionType * ) { visit_children = false; }
+
+		const ast::Type * hoist( const ast::Type * type );
+
+		ast::Storage::Classes storageClasses;
+	};
+
+	void HoistArrayDimension_NoResolve_New::previsit(
+			const ast::ObjectDecl * decl ) {
+		GuardValue( storageClasses ) = decl->storage;
+	}
+
+	const ast::DeclWithType * HoistArrayDimension_NoResolve_New::postvisit(
+			const ast::ObjectDecl * objectDecl ) {
+		return mutate_field( objectDecl, &ast::ObjectDecl::type,
+				hoist( objectDecl->type ) );
+	}
+
+	const ast::Type * HoistArrayDimension_NoResolve_New::hoist(
+			const ast::Type * type ) {
+		static UniqueName dimensionName( "_array_dim" );
+
+		if ( !isInFunction() || storageClasses.is_static ) {
+			return type;
+		}
+
+		if ( auto arrayType = dynamic_cast< const ast::ArrayType * >( type ) ) {
+			if ( nullptr == arrayType->dimension ) {
+				return type;
+			}
+
+			if ( !Tuples::maybeImpure( arrayType->dimension ) ) {
+				return type;
+			}
+
+			ast::ptr<ast::Type> dimType = transUnit().global.sizeType;
+			assert( dimType );
+			add_qualifiers( dimType, ast::CV::Qualifiers( ast::CV::Const ) );
+
+			ast::ObjectDecl * arrayDimension = new ast::ObjectDecl(
+				arrayType->dimension->location,
+				dimensionName.newName(),
+				dimType,
+				new ast::SingleInit(
+					arrayType->dimension->location,
+					arrayType->dimension
+				)
+			);
+
+			ast::ArrayType * mutType = ast::mutate( arrayType );
+			mutType->dimension = new ast::VariableExpr(
+					arrayDimension->location, arrayDimension );
+			declsToAddBefore.push_back( arrayDimension );
+
+			mutType->base = hoist( mutType->base );
+			return mutType;
+		}
+		return type;
+	}
+
+	struct ReturnFixer_New final :
+			public ast::WithStmtsToAdd<>, ast::WithGuards {
+		void previsit( const ast::FunctionDecl * decl );
+		const ast::ReturnStmt * previsit( const ast::ReturnStmt * stmt );
+	private:
+		const ast::FunctionDecl * funcDecl = nullptr;
+	};
+
+	void ReturnFixer_New::previsit( const ast::FunctionDecl * decl ) {
+		GuardValue( funcDecl ) = decl;
+	}
+
+	const ast::ReturnStmt * ReturnFixer_New::previsit(
+			const ast::ReturnStmt * stmt ) {
+		auto & returns = funcDecl->returns;
+		assert( returns.size() < 2 );
+		// Hands off if the function returns a reference.
+		// Don't allocate a temporary if the address is returned.
+		if ( stmt->expr && 1 == returns.size() ) {
+			ast::ptr<ast::DeclWithType> retDecl = returns.front();
+			if ( isConstructable( retDecl->get_type() ) ) {
+				// Explicitly construct the return value using the return
+				// expression and the retVal object.
+				assertf( "" != retDecl->name,
+					"Function %s has unnamed return value.\n",
+					funcDecl->name.c_str() );
+
+				auto retVal = retDecl.strict_as<ast::ObjectDecl>();
+				if ( auto varExpr = stmt->expr.as<ast::VariableExpr>() ) {
+					// Check if the return statement is already set up.
+					if ( varExpr->var == retVal ) return stmt;
+				}
+				ast::ptr<ast::Stmt> ctorStmt = genCtorDtor(
+					retVal->location, "?{}", retVal, stmt->expr );
+				assertf( ctorStmt,
+					"ReturnFixer: genCtorDtor returned nllptr: %s / %s",
+					toString( retVal ).c_str(),
+					toString( stmt->expr ).c_str() );
+					stmtsToAddBefore.push_back( ctorStmt );
+
+				// Return the retVal object.
+				ast::ReturnStmt * mutStmt = ast::mutate( stmt );
+				mutStmt->expr = new ast::VariableExpr(
+					stmt->location, retDecl );
+				return mutStmt;
+			}
+		}
+		return stmt;
+	}
+
+} // namespace
+
+	void genInit( ast::TranslationUnit & transUnit ) {
+		ast::Pass<HoistArrayDimension_NoResolve_New>::run( transUnit );
+		ast::Pass<ReturnFixer_New>::run( transUnit );
+	}
+
 	void CtorDtor::generateCtorDtor( std::list< Declaration * > & translationUnit ) {
 		PassVisitor<CtorDtor> ctordtor;
Index: src/InitTweak/GenInit.h
===================================================================
--- src/InitTweak/GenInit.h	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ src/InitTweak/GenInit.h	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -9,7 +9,7 @@
 // Author           : Rodolfo G. Esteves
 // Created On       : Mon May 18 07:44:20 2015
-// Last Modified By : Peter A. Buhr
-// Last Modified On : Sat Jul 22 09:31:19 2017
-// Update Count     : 4
+// Last Modified By : Andrew Beach
+// Last Modified On : Fri Oct 22 16:08:00 2021
+// Update Count     : 6
 //
 
@@ -27,4 +27,5 @@
 	/// Adds return value temporaries and wraps Initializers in ConstructorInit nodes
 	void genInit( std::list< Declaration * > & translationUnit );
+	void genInit( ast::TranslationUnit & translationUnit );
 
 	/// Converts return statements into copy constructor calls on the hidden return variable
Index: src/MakeLibCfa.h
===================================================================
--- src/MakeLibCfa.h	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ src/MakeLibCfa.h	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -19,7 +19,11 @@
 
 class Declaration;
+namespace ast {
+	struct TranslationUnit;
+}
 
 namespace LibCfa {
 	void makeLibCfa( std::list< Declaration* > &prelude );
+	void makeLibCfa( ast::TranslationUnit & translationUnit );
 } // namespace LibCfa
 
Index: src/MakeLibCfaNew.cpp
===================================================================
--- src/MakeLibCfaNew.cpp	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
+++ src/MakeLibCfaNew.cpp	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -0,0 +1,146 @@
+//
+// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
+//
+// The contents of this file are covered under the licence agreement in the
+// file "LICENCE" distributed with Cforall.
+//
+// MakeLibCfaNew.cpp --
+//
+// Author           : Henry Xue
+// Created On       : Fri Aug 27 15:50:14 2021
+// Last Modified By : Henry Xue
+// Last Modified On : Fri Aug 27 15:50:14 2021
+// Update Count     : 1
+//
+
+#include "MakeLibCfa.h"
+
+#include "AST/Fwd.hpp"
+#include "AST/Pass.hpp"
+#include "CodeGen/OperatorTable.h"
+#include "Common/UniqueName.h"
+
+namespace LibCfa {
+namespace {
+	struct MakeLibCfa {
+		const ast::DeclWithType * postvisit( const ast::FunctionDecl * funcDecl );
+		std::list< ast::ptr< ast::Decl > > newDecls;
+	};
+}
+
+void makeLibCfa( ast::TranslationUnit & prelude ) {
+	ast::Pass< MakeLibCfa > maker;
+	accept_all( prelude, maker );
+	prelude.decls.splice( prelude.decls.end(), maker.core.newDecls );
+}
+
+namespace {
+	struct TypeFinder {
+		void postvisit( const ast::TypeInstType * inst ) {
+			// if a type variable is seen, assume all zero_t/one_t in the parameter list
+			//  can be replaced with the equivalent 'general' pointer.
+			if ( type ) return;
+			if ( inst->kind == ast::TypeDecl::Ftype ) {
+				type = new ast::PointerType( new ast::FunctionType() );
+			} else {
+				type = new ast::PointerType( new ast::VoidType() );
+			}
+		}
+		ast::ptr< ast::Type > type;
+	};
+
+	struct ZeroOneReplacer {
+		ZeroOneReplacer( const ast::Type * t ) : type( t ) {}
+		ast::ptr< ast::Type > type;
+
+		const ast::Type * common( const ast::Type * t ) {
+			if ( ! type ) return t;
+			return type;
+		}
+
+		const ast::Type * postvisit( const ast::OneType * t ) { return common( t ); }
+		const ast::Type * postvisit( const ast::ZeroType * t ) { return common( t ); }
+	};
+
+	// const ast::Type * fixZeroOneType( ast::FunctionDecl * origFuncDecl ) {
+	// 	// find appropriate type to replace zero_t/one_t with
+	// 	ast::Pass< TypeFinder > finder;
+	// 	origFuncDecl->type->accept( finder );
+	// 	// replace zero_t/one_t in function type
+	// 	ast::Pass< ZeroOneReplacer > replacer( finder.core.type );
+	// 	//auto funcDecl = mutate( origFuncDecl );
+	// 	return origFuncDecl->type->accept( replacer );
+	// }
+
+	const ast::DeclWithType * MakeLibCfa::postvisit( const ast::FunctionDecl * origFuncDecl ) {
+		// don't change non-intrinsic functions
+		if ( origFuncDecl->linkage != ast::Linkage::Intrinsic ) return origFuncDecl;
+		// replace zero_t/one_t with void */void (*)(void)
+		auto mutDecl = mutate( origFuncDecl );
+		//mutDecl->type = fixZeroOneType( mutDecl );
+
+		// find appropriate type to replace zero_t/one_t with
+		ast::Pass< TypeFinder > finder;
+		mutDecl->type->accept( finder );
+		// replace zero_t/one_t in function type
+		ast::Pass< ZeroOneReplacer > replacer( finder.core.type );
+		mutDecl->type = mutDecl->type->accept( replacer );
+
+		// skip functions already defined
+		if ( mutDecl->has_body() ) return mutDecl;
+
+		const CodeLocation loc = mutDecl->location;
+		auto funcDecl = dynamic_cast<ast::FunctionDecl *>(ast::deepCopy( (ast::DeclWithType*)mutDecl ));
+		const CodeGen::OperatorInfo * opInfo;
+		opInfo = CodeGen::operatorLookup( funcDecl->name );
+		assert( opInfo );
+		assert( ! funcDecl->has_body() );
+		// build a recursive call - this is okay, as the call will actually be codegen'd using operator syntax
+		auto newExpr = new ast::UntypedExpr( loc, new ast::NameExpr( loc, funcDecl->name ) );
+		UniqueName paramNamer( "_p" );
+		auto param = funcDecl->params.begin();
+		assert( param != funcDecl->params.end() );
+
+		for ( ; param != funcDecl->params.end(); ++param ) {
+			// name each unnamed parameter
+			if ( (*param)->name == "" ) {
+				auto _param = param->get_and_mutate();
+				_param->name = paramNamer.newName() ;
+				_param->linkage = ast::Linkage::C;
+			}
+			// add parameter to the expression
+			newExpr->args.push_back( new ast::VariableExpr( loc, *param ) );
+		} // for
+
+		auto stmts = new ast::CompoundStmt( loc );;
+		newDecls.push_back( funcDecl );
+
+		ast::ptr< ast::Stmt > stmt;
+		switch ( opInfo->type ) {
+			case CodeGen::OT_INDEX:
+			case CodeGen::OT_CALL:
+			case CodeGen::OT_PREFIX:
+			case CodeGen::OT_POSTFIX:
+			case CodeGen::OT_INFIX:
+			case CodeGen::OT_PREFIXASSIGN:
+			case CodeGen::OT_POSTFIXASSIGN:
+			case CodeGen::OT_INFIXASSIGN:
+				// return the recursive call
+				stmt = new ast::ReturnStmt( loc, newExpr );
+				break;
+			case CodeGen::OT_CTOR:
+			case CodeGen::OT_DTOR:
+				// execute the recursive call
+				stmt = new ast::ExprStmt( loc, newExpr );
+				break;
+			case CodeGen::OT_CONSTANT:
+			case CodeGen::OT_LABELADDRESS:
+			// there are no intrinsic definitions of 0/1 or label addresses as functions
+			assert( false );
+		} // switch
+		stmts->push_back( stmt );
+		funcDecl->stmts = stmts;
+		return mutDecl;
+	}
+} // namespace
+} // namespace LibCfa
Index: src/Makefile.am
===================================================================
--- src/Makefile.am	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ src/Makefile.am	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -23,4 +23,5 @@
       CompilationState.h \
       MakeLibCfa.cc \
+	  MakeLibCfaNew.cpp \
 	MakeLibCfa.h
 
Index: src/Parser/parser.yy
===================================================================
--- src/Parser/parser.yy	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ src/Parser/parser.yy	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -10,6 +10,6 @@
 // Created On       : Sat Sep  1 20:22:55 2001
 // Last Modified By : Peter A. Buhr
-// Last Modified On : Tue Jul 20 22:03:04 2021
-// Update Count     : 5031
+// Last Modified On : Fri Oct 15 09:20:17 2021
+// Update Count     : 5163
 //
 
@@ -31,5 +31,5 @@
 // from ANSI90 to ANSI11 C are marked with the comment "C99/C11".
 
-// This grammar also has two levels of extensions. The first extensions cover most of the GCC C extensions All of the
+// This grammar also has two levels of extensions. The first extensions cover most of the GCC C extensions. All of the
 // syntactic extensions for GCC C are marked with the comment "GCC". The second extensions are for Cforall (CFA), which
 // fixes several of C's outstanding problems and extends C with many modern language concepts. All of the syntactic
@@ -69,5 +69,5 @@
 	// 2. String encodings are transformed into canonical form (one encoding at start) so the encoding can be found
 	//    without searching the string, e.g.: "abc" L"def" L"ghi" => L"abc" "def" "ghi". Multiple encodings must match,
-	//    i.e., u"a" U"b" L"c" is disallowed.
+	//    e.g., u"a" U"b" L"c" is disallowed.
 
 	if ( from[0] != '"' ) {								// encoding ?
@@ -185,4 +185,5 @@
 		type = new ExpressionNode( new CastExpr( maybeMoveBuild<Expression>(type), new BasicType( Type::Qualifiers(), BasicType::SignedInt ) ) );
 	} // if
+//	type = new ExpressionNode( build_func( new ExpressionNode( build_varref( new string( "__for_control_index_constraints__" ) ) ), type ) );
 	return new ForCtrl(
 		distAttr( DeclarationNode::newTypeof( type, true ), DeclarationNode::newName( index )->addInitializer( new InitializerNode( start ) ) ),
@@ -309,6 +310,5 @@
 %token ATassign											// @=
 
-%type<tok> identifier
-%type<tok> identifier_or_type_name  attr_name
+%type<tok> identifier					identifier_at				identifier_or_type_name		attr_name
 %type<tok> quasi_keyword
 %type<constant> string_literal
@@ -326,5 +326,5 @@
 %type<en> conditional_expression		constant_expression			assignment_expression		assignment_expression_opt
 %type<en> comma_expression				comma_expression_opt
-%type<en> argument_expression_list_opt	argument_expression			default_initializer_opt
+%type<en> argument_expression_list_opt	argument_expression_list	argument_expression			default_initializer_opt
 %type<ifctl> if_control_expression
 %type<fctl> for_control_expression		for_control_expression_list
@@ -558,4 +558,8 @@
 	IDENTIFIER
 	| quasi_keyword
+	;
+
+identifier_at:
+	identifier
 	| '@'												// CFA
 		{ Token tok = { new string( DeclarationNode::anonymous.newName() ), yylval.tok.loc }; $$ = tok; }
@@ -692,5 +696,9 @@
 	// empty
 		{ $$ = nullptr; }
-	| argument_expression
+	| argument_expression_list
+	;
+
+argument_expression_list:
+	argument_expression
 	| argument_expression_list_opt ',' argument_expression
 		{ $$ = (ExpressionNode *)($1->set_last( $3 )); }
@@ -730,5 +738,5 @@
 	| FLOATINGconstant fraction_constants_opt
 		{ $$ = new ExpressionNode( build_field_name_fraction_constants( build_field_name_FLOATINGconstant( *$1 ), $2 ) ); }
-	| identifier fraction_constants_opt
+	| identifier_at fraction_constants_opt				// CFA, allow anonymous fields
 		{
 			$$ = new ExpressionNode( build_field_name_fraction_constants( build_varref( $1 ), $2 ) );
@@ -1083,4 +1091,7 @@
 	comma_expression_opt ';'
 		{ $$ = new StatementNode( build_expr( $1 ) ); }
+	| MUTEX '(' ')' comma_expression ';'
+		{ $$ = new StatementNode( build_mutex( nullptr, new StatementNode( build_expr( $4 ) ) ) ); }
+		// { SemanticError( yylloc, "Mutex expression is currently unimplemented." ); $$ = nullptr; }
 	;
 
@@ -1181,16 +1192,22 @@
 
 iteration_statement:
-	WHILE '(' push if_control_expression ')' statement pop
-		{ $$ = new StatementNode( build_while( $4, maybe_build_compound( $6 ) ) ); }
-	| WHILE '(' ')' statement							// CFA => while ( 1 )
+	WHILE '(' ')' statement								// CFA => while ( 1 )
 		{ $$ = new StatementNode( build_while( new IfCtrl( nullptr, new ExpressionNode( build_constantInteger( *new string( "1" ) ) ) ), maybe_build_compound( $4 ) ) ); }
-	| DO statement WHILE '(' comma_expression ')' ';'
-		{ $$ = new StatementNode( build_do_while( $5, maybe_build_compound( $2 ) ) ); }
+	| WHILE '(' if_control_expression ')' statement		%prec THEN
+		{ $$ = new StatementNode( build_while( $3, maybe_build_compound( $5 ) ) ); }
+	| WHILE '(' if_control_expression ')' statement ELSE statement // CFA
+		{ SemanticError( yylloc, "Loop default block is currently unimplemented." ); $$ = nullptr; }
 	| DO statement WHILE '(' ')' ';'					// CFA => do while( 1 )
 		{ $$ = new StatementNode( build_do_while( new ExpressionNode( build_constantInteger( *new string( "1" ) ) ), maybe_build_compound( $2 ) ) ); }
-	| FOR '(' push for_control_expression_list ')' statement pop
-		{ $$ = new StatementNode( build_for( $4, maybe_build_compound( $6 ) ) ); }
+	| DO statement WHILE '(' comma_expression ')' ';'	%prec THEN
+		{ $$ = new StatementNode( build_do_while( $5, maybe_build_compound( $2 ) ) ); }
+	| DO statement WHILE '(' comma_expression ')' ELSE statement // CFA
+		{ SemanticError( yylloc, "Loop default block is currently unimplemented." ); $$ = nullptr; }
 	| FOR '(' ')' statement								// CFA => for ( ;; )
 		{ $$ = new StatementNode( build_for( new ForCtrl( (ExpressionNode * )nullptr, (ExpressionNode * )nullptr, (ExpressionNode * )nullptr ), maybe_build_compound( $4 ) ) ); }
+	| FOR '(' for_control_expression_list ')' statement	%prec THEN
+	  	{ $$ = new StatementNode( build_for( $3, maybe_build_compound( $5 ) ) ); }
+	| FOR '(' for_control_expression_list ')' statement ELSE statement // CFA
+		{ SemanticError( yylloc, "Loop default block is currently unimplemented." ); $$ = nullptr; }
 	;
 
@@ -1338,12 +1355,10 @@
 with_statement:
 	WITH '(' tuple_expression_list ')' statement
-		{
-			$$ = new StatementNode( build_with( $3, $5 ) );
-		}
+		{ $$ = new StatementNode( build_with( $3, $5 ) ); }
 	;
 
 // If MUTEX becomes a general qualifier, there are shift/reduce conflicts, so change syntax to "with mutex".
 mutex_statement:
-	MUTEX '(' argument_expression_list_opt ')' statement
+	MUTEX '(' argument_expression_list ')' statement
 		{ $$ = new StatementNode( build_mutex( $3, $5 ) ); }
 	;
@@ -2445,4 +2460,5 @@
 	| simple_assignment_operator initializer	{ $$ = $1 == OperKinds::Assign ? $2 : $2->set_maybeConstructed( false ); }
 	| '=' VOID									{ $$ = new InitializerNode( true ); }
+	| '{' initializer_list_opt comma_opt '}'	{ $$ = new InitializerNode( $2, true ); }
 	;
 
@@ -2458,6 +2474,5 @@
 	| designation initializer					{ $$ = $2->set_designators( $1 ); }
 	| initializer_list_opt ',' initializer		{ $$ = (InitializerNode *)( $1->set_last( $3 ) ); }
-	| initializer_list_opt ',' designation initializer
-		{ $$ = (InitializerNode *)($1->set_last( $4->set_designators( $3 ) )); }
+	| initializer_list_opt ',' designation initializer { $$ = (InitializerNode *)($1->set_last( $4->set_designators( $3 ) )); }
 	;
 
@@ -2474,5 +2489,5 @@
 designation:
 	designator_list ':'									// C99, CFA uses ":" instead of "="
-	| identifier ':'									// GCC, field name
+	| identifier_at ':'									// GCC, field name
 		{ $$ = new ExpressionNode( build_varref( $1 ) ); }
 	;
@@ -2486,5 +2501,5 @@
 
 designator:
-	'.' identifier										// C99, field name
+	'.' identifier_at									// C99, field name
 		{ $$ = new ExpressionNode( build_varref( $2 ) ); }
 	| '[' push assignment_expression pop ']'			// C99, single array element
@@ -2918,5 +2933,5 @@
 
 paren_identifier:
-	identifier
+	identifier_at
 		{ $$ = DeclarationNode::newName( $1 ); }
 	| '(' paren_identifier ')'							// redundant parenthesis
Index: src/ResolvExpr/CandidatePrinter.cpp
===================================================================
--- src/ResolvExpr/CandidatePrinter.cpp	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
+++ src/ResolvExpr/CandidatePrinter.cpp	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -0,0 +1,62 @@
+//
+// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
+//
+// The contents of this file are covered under the licence agreement in the
+// file "LICENCE" distributed with Cforall.
+//
+// CandidatePrinter.cpp -- Print expression canditates.
+//
+// Author           : Andrew Beach
+// Created On       : Tue Nov  9  9:54:00 2021
+// Last Modified By : Andrew Beach
+// Last Modified On : Tue Nov  9 15:47:00 2021
+// Update Count     : 0
+//
+
+#include "CandidatePrinter.hpp"
+
+#include "AST/Expr.hpp"
+#include "AST/Pass.hpp"
+#include "AST/Print.hpp"
+#include "AST/Stmt.hpp"
+#include "AST/TranslationUnit.hpp"
+#include "ResolvExpr/CandidateFinder.hpp"
+
+#include <iostream>
+
+namespace ResolvExpr {
+
+namespace {
+
+class CandidatePrintCore : public ast::WithSymbolTable {
+	std::ostream & os;
+public:
+	CandidatePrintCore( std::ostream & os ) : os( os ) {}
+
+	void postvisit( const ast::ExprStmt * stmt ) {
+		ast::TypeEnvironment env;
+		CandidateFinder finder( symtab, env );
+		finder.find( stmt->expr, ResolvMode::withAdjustment() );
+		int count = 1;
+		os << "There are " << finder.candidates.size() << " candidates\n";
+		for ( const std::shared_ptr<Candidate> & cand : finder ) {
+			os << "Candidate " << count++ << " ==============\n";
+			ast::print( os, cand->expr->result.get() );
+			os << std::endl;
+		}
+	}
+};
+
+} // namespace
+
+void printCandidates( ast::TranslationUnit & transUnit ) {
+	ast::Pass<CandidatePrintCore>::run( transUnit, std::cout );
+}
+
+} // namespace ResolvExpr
+
+// Local Variables: //
+// tab-width: 4 //
+// mode: c++ //
+// compile-command: "make install" //
+// End: //
Index: src/ResolvExpr/CandidatePrinter.hpp
===================================================================
--- src/ResolvExpr/CandidatePrinter.hpp	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
+++ src/ResolvExpr/CandidatePrinter.hpp	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -0,0 +1,35 @@
+//
+// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
+//
+// The contents of this file are covered under the licence agreement in the
+// file "LICENCE" distributed with Cforall.
+//
+// CandidatePrinter.hpp -- Print expression canditates.
+//
+// Author           : Andrew Beach
+// Created On       : Tue Nov  9  9:49:00 2021
+// Last Modified By : Andrew Beach
+// Last Modified On : Tue Nov  9 15:33:00 2021
+// Update Count     : 0
+//
+
+#pragma once
+
+namespace ast {
+    class TranslationUnit;
+}
+
+namespace ResolvExpr {
+
+void printCandidates( ast::TranslationUnit & transUnit );
+/* Traverse over the entire translation unit, printing candidates for each
+ * top level expression. See CandidateFinder.
+ */
+
+} // namespace ResolvExpr
+
+// Local Variables: //
+// tab-width: 4 //
+// mode: c++ //
+// compile-command: "make install" //
+// End: //
Index: src/ResolvExpr/module.mk
===================================================================
--- src/ResolvExpr/module.mk	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ src/ResolvExpr/module.mk	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -61,5 +61,9 @@
       ResolvExpr/WidenMode.h
 
+SRC += $(SRC_RESOLVEXPR) \
+	ResolvExpr/AlternativePrinter.cc \
+	ResolvExpr/AlternativePrinter.h \
+	ResolvExpr/CandidatePrinter.cpp \
+	ResolvExpr/CandidatePrinter.hpp
 
-SRC += $(SRC_RESOLVEXPR) ResolvExpr/AlternativePrinter.cc ResolvExpr/AlternativePrinter.h
 SRCDEMANGLE += $(SRC_RESOLVEXPR)
Index: src/Tuples/TupleExpansionNew.cpp
===================================================================
--- src/Tuples/TupleExpansionNew.cpp	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ src/Tuples/TupleExpansionNew.cpp	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -8,11 +8,9 @@
 //
 // Author           : Henry Xue
-// Created On       : Wed Aug 18 12:54:02 2021
+// Created On       : Mon Aug 23 15:36:09 2021
 // Last Modified By : Henry Xue
-// Last Modified On : Wed Aug 18 12:54:02 2021
+// Last Modified On : Mon Aug 23 15:36:09 2021
 // Update Count     : 1
 //
-
-// Currently not working due to unresolved issues with UniqueExpr
 
 #include "Tuples.h"
@@ -20,8 +18,55 @@
 namespace Tuples {
 namespace {
+	struct MemberTupleExpander final : public ast::WithShortCircuiting, public ast::WithVisitorRef< MemberTupleExpander > {
+		void previsit( const ast::UntypedMemberExpr * ) { visit_children = false; }
+        const ast::Expr * postvisit( const ast::UntypedMemberExpr * memberExpr );
+	};
 	struct UniqueExprExpander final : public ast::WithDeclsToAdd<> {
 		const ast::Expr * postvisit( const ast::UniqueExpr * unqExpr );
 		std::map< int, ast::ptr<ast::Expr> > decls; // not vector, because order added may not be increasing order
 	};
+} // namespace
+
+void expandMemberTuples( ast::TranslationUnit & translationUnit ) {
+	ast::Pass< MemberTupleExpander >::run( translationUnit );
+}
+
+namespace {
+	namespace {
+		/// given a expression representing the member and an expression representing the aggregate,
+		/// reconstructs a flattened UntypedMemberExpr with the right precedence
+		const ast::Expr * reconstructMemberExpr( const ast::Expr * member, const ast::Expr * aggr, const CodeLocation & loc ) {
+			if ( auto memberExpr = dynamic_cast< const ast::UntypedMemberExpr * >( member ) ) {
+				// construct a new UntypedMemberExpr with the correct structure , and recursively
+				// expand that member expression.
+				ast::Pass< MemberTupleExpander > expander;
+				auto inner = new ast::UntypedMemberExpr( loc, memberExpr->aggregate, aggr );
+				auto newMemberExpr = new ast::UntypedMemberExpr( loc, memberExpr->member, inner );
+				//delete memberExpr;
+				return newMemberExpr->accept( expander );
+			} else {
+				// not a member expression, so there is nothing to do but attach and return
+				return new ast::UntypedMemberExpr( loc, member, aggr );
+			}
+		}
+	}
+
+	const ast::Expr * MemberTupleExpander::postvisit( const ast::UntypedMemberExpr * memberExpr ) {
+		const CodeLocation loc = memberExpr->location;
+        if ( auto tupleExpr = memberExpr->member.as< ast::UntypedTupleExpr >() ) {
+			auto mutExpr = mutate( tupleExpr );
+			ast::ptr< ast::Expr > aggr = memberExpr->aggregate->accept( *visitor );
+			// aggregate expressions which might be impure must be wrapped in unique expressions
+			if ( Tuples::maybeImpureIgnoreUnique( memberExpr->aggregate ) ) aggr = new ast::UniqueExpr( loc, aggr );
+			for ( auto & expr : mutExpr->exprs ) {
+				expr = reconstructMemberExpr( expr, aggr, loc );
+			}
+			//delete aggr;
+			return mutExpr;
+		} else {
+			// there may be a tuple expr buried in the aggregate
+			return new ast::UntypedMemberExpr( loc, memberExpr->member, memberExpr->aggregate->accept( *visitor ) );
+		}
+	}
 } // namespace
 
Index: src/Tuples/Tuples.h
===================================================================
--- src/Tuples/Tuples.h	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ src/Tuples/Tuples.h	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -9,7 +9,7 @@
 // Author           : Rodolfo G. Esteves
 // Created On       : Mon May 18 07:44:20 2015
-// Last Modified By : Andrew Beach
-// Last Modified On : Tue Jun 18 09:36:00 2019
-// Update Count     : 18
+// Last Modified By : Henry Xue
+// Last Modified On : Mon Aug 23 15:36:09 2021
+// Update Count     : 19
 //
 
@@ -39,4 +39,5 @@
 	/// expands z.[a, b.[x, y], c] into [z.a, z.b.x, z.b.y, z.c], inserting UniqueExprs as appropriate
 	void expandMemberTuples( std::list< Declaration * > & translationUnit );
+	void expandMemberTuples( ast::TranslationUnit & translationUnit );
 
 	/// replaces tuple-related elements, such as TupleType, TupleExpr, TupleAssignExpr, etc.
Index: src/Tuples/module.mk
===================================================================
--- src/Tuples/module.mk	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ src/Tuples/module.mk	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -10,7 +10,7 @@
 ## Author           : Richard C. Bilson
 ## Created On       : Mon Jun  1 17:49:17 2015
-## Last Modified By : Peter A. Buhr
-## Last Modified On : Mon Jun  1 17:54:33 2015
-## Update Count     : 1
+## Last Modified By : Henry Xue
+## Last Modified On : Mon Aug 23 15:36:09 2021
+## Update Count     : 2
 ###############################################################################
 
Index: src/main.cc
===================================================================
--- src/main.cc	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ src/main.cc	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -9,7 +9,7 @@
 // Author           : Peter Buhr and Rob Schluntz
 // Created On       : Fri May 15 23:12:02 2015
-// Last Modified By : Henry Xue
-// Last Modified On : Tue Jul 20 04:27:35 2021
-// Update Count     : 658
+// Last Modified By : Andrew Beach
+// Last Modified On : Tue Nov  9 11:10:00 2021
+// Update Count     : 657
 //
 
@@ -43,4 +43,6 @@
 #include "Common/CodeLocationTools.hpp"     // for forceFillCodeLocations
 #include "Common/CompilerError.h"           // for CompilerError
+#include "Common/DeclStats.hpp"             // for printDeclStats
+#include "Common/ResolvProtoDump.hpp"       // for dumpAsResolverProto
 #include "Common/Stats.h"
 #include "Common/PassVisitor.h"
@@ -51,4 +53,5 @@
 #include "ControlStruct/ExceptDecl.h"       // for translateExcept
 #include "ControlStruct/ExceptTranslate.h"  // for translateEHM
+#include "ControlStruct/FixLabels.hpp"      // for fixLabels
 #include "ControlStruct/Mutate.h"           // for mutate
 #include "GenPoly/Box.h"                    // for box
@@ -62,4 +65,5 @@
 #include "Parser/TypedefTable.h"            // for TypedefTable
 #include "ResolvExpr/AlternativePrinter.h"  // for AlternativePrinter
+#include "ResolvExpr/CandidatePrinter.hpp"  // for printCandidates
 #include "ResolvExpr/Resolver.h"            // for resolve
 #include "SymTab/Validate.h"                // for validate
@@ -315,47 +319,6 @@
 		// add the assignment statement after the initialization of a type parameter
 		PASS( "Validate", SymTab::validate( translationUnit, symtabp ) );
-		if ( symtabp ) {
-			deleteAll( translationUnit );
-			return EXIT_SUCCESS;
-		} // if
-
-		if ( expraltp ) {
-			PassVisitor<ResolvExpr::AlternativePrinter> printer( cout );
-			acceptAll( translationUnit, printer );
-			return EXIT_SUCCESS;
-		} // if
-
-		if ( validp ) {
-			dump( translationUnit );
-			return EXIT_SUCCESS;
-		} // if
-
-		PASS( "Translate Throws", ControlStruct::translateThrows( translationUnit ) );
-		PASS( "Fix Labels", ControlStruct::fixLabels( translationUnit ) );
-		PASS( "Fix Names", CodeGen::fixNames( translationUnit ) );
-		PASS( "Gen Init", InitTweak::genInit( translationUnit ) );
-		PASS( "Expand Member Tuples" , Tuples::expandMemberTuples( translationUnit ) );
-		if ( libcfap ) {
-			// generate the bodies of cfa library functions
-			LibCfa::makeLibCfa( translationUnit );
-		} // if
-
-		if ( declstatsp ) {
-			CodeTools::printDeclStats( translationUnit );
-			deleteAll( translationUnit );
-			return EXIT_SUCCESS;
-		} // if
-
-		if ( bresolvep ) {
-			dump( translationUnit );
-			return EXIT_SUCCESS;
-		} // if
 
 		CodeTools::fillLocations( translationUnit );
-
-		if ( resolvprotop ) {
-			CodeTools::dumpAsResolvProto( translationUnit );
-			return EXIT_SUCCESS;
-		} // if
 
 		if( useNewAST ) {
@@ -365,4 +328,47 @@
 			}
 			auto transUnit = convert( move( translationUnit ) );
+
+			forceFillCodeLocations( transUnit );
+
+			if ( symtabp ) {
+				return EXIT_SUCCESS;
+			} // if
+
+			if ( expraltp ) {
+				ResolvExpr::printCandidates( transUnit );
+				return EXIT_SUCCESS;
+			} // if
+
+			if ( validp ) {
+				dump( move( transUnit ) );
+				return EXIT_SUCCESS;
+			} // if
+
+			PASS( "Translate Throws", ControlStruct::translateThrows( transUnit ) );
+			PASS( "Fix Labels", ControlStruct::fixLabels( transUnit ) );
+			PASS( "Fix Names", CodeGen::fixNames( transUnit ) );
+			PASS( "Gen Init", InitTweak::genInit( transUnit ) );
+			PASS( "Expand Member Tuples" , Tuples::expandMemberTuples( transUnit ) );
+
+			if ( libcfap ) {
+				// Generate the bodies of cfa library functions.
+				LibCfa::makeLibCfa( transUnit );
+			} // if
+
+			if ( declstatsp ) {
+				printDeclStats( transUnit );
+				return EXIT_SUCCESS;
+			} // if
+
+			if ( bresolvep ) {
+				dump( move( transUnit ) );
+				return EXIT_SUCCESS;
+			} // if
+
+			if ( resolvprotop ) {
+				dumpAsResolverProto( transUnit );
+				return EXIT_SUCCESS;
+			} // if
+
 			PASS( "Resolve", ResolvExpr::resolve( transUnit ) );
 			if ( exprp ) {
@@ -385,4 +391,49 @@
 			translationUnit = convert( move( transUnit ) );
 		} else {
+			if ( symtabp ) {
+				deleteAll( translationUnit );
+				return EXIT_SUCCESS;
+			} // if
+
+			if ( expraltp ) {
+				PassVisitor<ResolvExpr::AlternativePrinter> printer( cout );
+				acceptAll( translationUnit, printer );
+				return EXIT_SUCCESS;
+			} // if
+
+			if ( validp ) {
+				dump( translationUnit );
+				return EXIT_SUCCESS;
+			} // if
+
+			PASS( "Translate Throws", ControlStruct::translateThrows( translationUnit ) );
+			PASS( "Fix Labels", ControlStruct::fixLabels( translationUnit ) );
+			PASS( "Fix Names", CodeGen::fixNames( translationUnit ) );
+			PASS( "Gen Init", InitTweak::genInit( translationUnit ) );
+			PASS( "Expand Member Tuples" , Tuples::expandMemberTuples( translationUnit ) );
+
+			if ( libcfap ) {
+				// Generate the bodies of cfa library functions.
+				LibCfa::makeLibCfa( translationUnit );
+			} // if
+
+			if ( declstatsp ) {
+				CodeTools::printDeclStats( translationUnit );
+				deleteAll( translationUnit );
+				return EXIT_SUCCESS;
+			} // if
+
+			if ( bresolvep ) {
+				dump( translationUnit );
+				return EXIT_SUCCESS;
+			} // if
+
+			CodeTools::fillLocations( translationUnit );
+
+			if ( resolvprotop ) {
+				CodeTools::dumpAsResolvProto( translationUnit );
+				return EXIT_SUCCESS;
+			} // if
+
 			PASS( "Resolve", ResolvExpr::resolve( translationUnit ) );
 			if ( exprp ) {
@@ -447,5 +498,6 @@
 		PASS( "Code Gen", CodeGen::generate( translationUnit, *output, ! genproto, prettycodegenp, true, linemarks ) );
 
-		CodeGen::FixMain::fix( *output, (PreludeDirector + "/bootloader.c").c_str() );
+		CodeGen::FixMain::fix( translationUnit, *output,
+				(PreludeDirector + "/bootloader.c").c_str() );
 		if ( output != &cout ) {
 			delete output;
Index: tests/.expect/declarationSpecifier.x64.txt
===================================================================
--- tests/.expect/declarationSpecifier.x64.txt	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ tests/.expect/declarationSpecifier.x64.txt	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -1132,5 +1132,5 @@
 char **_X13cfa_args_argvPPc_1;
 char **_X13cfa_args_envpPPc_1;
-signed int _X17cfa_main_returnedi_1 = ((signed int )0);
+__attribute__ ((weak)) extern signed int _X17cfa_main_returnedi_1;
 signed int main(signed int _X4argci_1, char **_X4argvPPc_1, char **_X4envpPPc_1){
     __attribute__ ((unused)) signed int _X12_retval_maini_1;
@@ -1149,6 +1149,9 @@
     signed int _tmp_cp_ret6;
     signed int _X3reti_2 = (((void)(_tmp_cp_ret6=invoke_main(_X4argci_1, _X4argvPPc_1, _X4envpPPc_1))) , _tmp_cp_ret6);
-    {
-        ((void)(_X17cfa_main_returnedi_1=((signed int )1)));
+    if ( ((&_X17cfa_main_returnedi_1)!=((signed int *)0)) ) {
+        {
+            ((void)(_X17cfa_main_returnedi_1=((signed int )1)));
+        }
+
     }
 
Index: tests/.expect/declarationSpecifier.x86.txt
===================================================================
--- tests/.expect/declarationSpecifier.x86.txt	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ tests/.expect/declarationSpecifier.x86.txt	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -1132,5 +1132,5 @@
 char **_X13cfa_args_argvPPc_1;
 char **_X13cfa_args_envpPPc_1;
-signed int _X17cfa_main_returnedi_1 = ((signed int )0);
+__attribute__ ((weak)) extern signed int _X17cfa_main_returnedi_1;
 signed int main(signed int _X4argci_1, char **_X4argvPPc_1, char **_X4envpPPc_1){
     __attribute__ ((unused)) signed int _X12_retval_maini_1;
@@ -1149,6 +1149,9 @@
     signed int _tmp_cp_ret6;
     signed int _X3reti_2 = (((void)(_tmp_cp_ret6=invoke_main(_X4argci_1, _X4argvPPc_1, _X4envpPPc_1))) , _tmp_cp_ret6);
-    {
-        ((void)(_X17cfa_main_returnedi_1=((signed int )1)));
+    if ( ((&_X17cfa_main_returnedi_1)!=((signed int *)0)) ) {
+        {
+            ((void)(_X17cfa_main_returnedi_1=((signed int )1)));
+        }
+
     }
 
Index: tests/.expect/gccExtensions.x64.txt
===================================================================
--- tests/.expect/gccExtensions.x64.txt	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ tests/.expect/gccExtensions.x64.txt	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -324,5 +324,5 @@
 char **_X13cfa_args_argvPPc_1;
 char **_X13cfa_args_envpPPc_1;
-signed int _X17cfa_main_returnedi_1 = ((signed int )0);
+__attribute__ ((weak)) extern signed int _X17cfa_main_returnedi_1;
 signed int main(signed int _X4argci_1, char **_X4argvPPc_1, char **_X4envpPPc_1){
     __attribute__ ((unused)) signed int _X12_retval_maini_1;
@@ -341,6 +341,9 @@
     signed int _tmp_cp_ret6;
     signed int _X3reti_2 = (((void)(_tmp_cp_ret6=invoke_main(_X4argci_1, _X4argvPPc_1, _X4envpPPc_1))) , _tmp_cp_ret6);
-    {
-        ((void)(_X17cfa_main_returnedi_1=((signed int )1)));
+    if ( ((&_X17cfa_main_returnedi_1)!=((signed int *)0)) ) {
+        {
+            ((void)(_X17cfa_main_returnedi_1=((signed int )1)));
+        }
+
     }
 
Index: tests/.expect/gccExtensions.x86.txt
===================================================================
--- tests/.expect/gccExtensions.x86.txt	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ tests/.expect/gccExtensions.x86.txt	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -302,5 +302,5 @@
 char **_X13cfa_args_argvPPc_1;
 char **_X13cfa_args_envpPPc_1;
-signed int _X17cfa_main_returnedi_1 = ((signed int )0);
+__attribute__ ((weak)) extern signed int _X17cfa_main_returnedi_1;
 signed int main(signed int _X4argci_1, char **_X4argvPPc_1, char **_X4envpPPc_1){
     __attribute__ ((unused)) signed int _X12_retval_maini_1;
@@ -319,6 +319,9 @@
     signed int _tmp_cp_ret6;
     signed int _X3reti_2 = (((void)(_tmp_cp_ret6=invoke_main(_X4argci_1, _X4argvPPc_1, _X4envpPPc_1))) , _tmp_cp_ret6);
-    {
-        ((void)(_X17cfa_main_returnedi_1=((signed int )1)));
+    if ( ((&_X17cfa_main_returnedi_1)!=((signed int *)0)) ) {
+        {
+            ((void)(_X17cfa_main_returnedi_1=((signed int )1)));
+        }
+
     }
 
Index: tests/.expect/parseconfig.txt
===================================================================
--- tests/.expect/parseconfig.txt	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
+++ tests/.expect/parseconfig.txt	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -0,0 +1,33 @@
+Different types of destination addresses
+Stop cost: 1
+Number of students: 2
+Number of stops: 2
+Maximum number of students: 5
+Timer delay: 2
+Groupoff delay: 10
+Conductor delay: 5
+Parental delay: 5
+Number of couriers: 1
+Maximum student delay: 10
+Maximum student trips: 3
+
+Open_Failure thrown when config file does not exist
+Failed to open the config file
+
+Missing_Config_Entries thrown when config file is missing entries we want
+The config file is missing 1 entry.
+
+Parse_Failure thrown when an entry cannot be parsed
+Config entry AnothaOne could not be parsed. It has value DjKhaled.
+
+Validation_Failure thrown when an entry fails validation
+Config entry StopCost could not be validated. It has value -1.
+
+No error is thrown when validation succeeds
+Stop cost: 1
+
+A custom parse function can be accepted
+Stop cost: 100
+
+Custom parse and validation functions can be provided together
+Stop cost: 100
Index: tests/.in/parseconfig-all.txt
===================================================================
--- tests/.in/parseconfig-all.txt	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
+++ tests/.in/parseconfig-all.txt	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -0,0 +1,12 @@
+StopCost				1	# amount to charge per train stop
+NumStudents				2	# number of students to create
+NumStops				2	# number of train stops; minimum of 2
+MaxNumStudents 			5  	# maximum students each train can carry
+TimerDelay 				2	# length of time between each tick of the timer
+# Going to add a comment here
+MaxStudentDelay			10	# maximum random student delay between trips
+MaxStudentTrips 		3	# maximum number of train trips each student takes
+GroupoffDelay			10	# length of time between initializing gift cards
+ConductorDelay			5  	# length of time between checking on passenger POPs
+ParentalDelay			5	# length of time between cash deposits
+NumCouriers				1	# number of WATCard office couriers in the pool
Index: tests/.in/parseconfig-errors.txt
===================================================================
--- tests/.in/parseconfig-errors.txt	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
+++ tests/.in/parseconfig-errors.txt	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -0,0 +1,12 @@
+StopCost				-1	# amount to charge per train stop
+NumStudents				2	# number of students to create
+NumStops				2	# number of train stops; minimum of 2
+MaxNumStudents 			5  	# maximum students each train can carry
+TimerDelay 				2	# length of time between each tick of the timer
+MaxStudentDelay			10	# maximum random student delay between trips
+MaxStudentTrips 		3	# maximum number of train trips each student takes
+GroupoffDelay			10	# length of time between initializing gift cards
+ConductorDelay			5  	# length of time between checking on passenger POPs
+ParentalDelay			5	# length of time between cash deposits
+NumCouriers				1	# number of WATCard office couriers in the pool
+AnothaOne               DjKhaled    # this one will not be used by the user
Index: tests/.in/parseconfig-missing.txt
===================================================================
--- tests/.in/parseconfig-missing.txt	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
+++ tests/.in/parseconfig-missing.txt	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -0,0 +1,12 @@
+StopCost				-1	# amount to charge per train stop
+NumStudents				2	# number of students to create
+NumStops				2	# number of train stops; minimum of 2
+MaxNumStudents 			5  	# maximum students each train can carry
+TimerDelay 				2	# length of time between each tick of the timer
+MaxStudentDelay			10	# maximum random student delay between trips
+MaxStudentTrips 		3	# maximum number of train trips each student takes
+GroupoffDelay			10	# length of time between initializing gift cards
+ConductorDelay			5  	# length of time between checking on passenger POPs
+# ParentalDelay			5	# length of time between cash deposits
+NumCouriers				1	# number of WATCard office couriers in the pool
+# Notice I've commented out one of the wanted entries
Index: tests/Makefile.am
===================================================================
--- tests/Makefile.am	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ tests/Makefile.am	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -75,4 +75,7 @@
 	pybin/tools.py \
 	long_tests.hfa \
+	.in/parseconfig-all.txt \
+	.in/parseconfig-errors.txt \
+	.in/parseconfig-missing.txt \
 	io/.in/io.data \
 	io/.in/many_read.data \
Index: tests/collections/.expect/string-api-coverage.txt
===================================================================
--- tests/collections/.expect/string-api-coverage.txt	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
+++ tests/collections/.expect/string-api-coverage.txt	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -0,0 +1,51 @@
+hello hello hello
+true false
+true false
+true false
+true false
+true false
+true false
+true false
+true false
+true false
+true false
+true false
+true false
+123
+hello
+hello
+world
+hello
+world
+5
+helloworld
+helloworld
+helloworld!
+hello!
+hellohello
+hellohello, friend
+hello, friend
+bye, friend
+hellohellohello
+QQQ
+asdfasdfasdf
+e
+help!!!o
+help!!!!
+help!!!
+p
+true true false
+0 4 7 8
+0 0 25 0 26 3
+true true true true false true
+0 0 26 3
+true true false true
+true false false true
+0 0 26 3
+true true false true
+true false false true
+3 3 1 0 22 0 3 5 3
+true true true true false true true false true
+true true false true true true true true false
+true false true false true true true false true false
+3 0 0 11 26 0
Index: tests/collections/.expect/string-gc.txt
===================================================================
--- tests/collections/.expect/string-gc.txt	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
+++ tests/collections/.expect/string-gc.txt	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -0,0 +1,39 @@
+======================== basicFillCompact
+hello!
+hello!----|
+hello!----|----|
+hello!----|----|----|
+--A
+length of x:21
+padder from 6 to 11
+x from 0 to 21
+--B
+length of x:996
+padder from 6 to 11
+x from 0 to 996
+--C
+xinit from 0 to 6
+padder from 6 to 11
+x from 996 to 997
+--D
+before append, x = q
+after append, x = q----|
+--E
+xinit from 0 to 6
+padder from 6 to 11
+x from 11 to 17
+--F
+983 bytes available before re-fill
+1 bytes available after re-fill
+--G
+after re-fill, x = q----|
+======================== fillCompact_withSharedEdits
+x from 990 to 995
+y from 990 to 995
+-
+before reassign, x = hello
+before reassign, y = hello
+after reassign, x = 0123456789
+after reassign, y = 0123456789
+x from 5 to 15
+y from 5 to 15
Index: tests/collections/.expect/string-overwrite.txt
===================================================================
--- tests/collections/.expect/string-overwrite.txt	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
+++ tests/collections/.expect/string-overwrite.txt	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -0,0 +1,632 @@
+abcdeqqqqqklmnopqrstuvwxyz
+abcde-----qqqqqklmnopqrstuvwxyz
+------------------------------------------------------------------------ warmup
+abcdefghijklmnopqrstuvwxyz
+            --!           
+          ----------?     
+abcdefghijklxxxxxopqrstuvwxyz ( wit = klxxxxxopqrst witlen = 13 )
+abcdefghij?uvwxyz
+------------------------------------------------------------------------ 1
+abcdefghijklmnopqrstuvwxyz
+          !               
+          ?               
+abcdefghij=====klmnopqrstuvwxyz ( wit =  witlen = 0 )
+abcdefghij=====?klmnopqrstuvwxyz
+------------------------------------------------------------------------
+abcdefghijklmnopqrstuvwxyz
+          !               
+          ?               
+abcdefghij==klmnopqrstuvwxyz ( wit =  witlen = 0 )
+abcdefghij==?klmnopqrstuvwxyz
+------------------------------------------------------------------------
+abcdefghijklmnopqrstuvwxyz
+          !               
+          ?               
+abcdefghij=klmnopqrstuvwxyz ( wit =  witlen = 0 )
+abcdefghij=?klmnopqrstuvwxyz
+------------------------------------------------------------------------
+abcdefghijklmnopqrstuvwxyz
+          !               
+          ?               
+abcdefghijklmnopqrstuvwxyz ( wit =  witlen = 0 )
+abcdefghij?klmnopqrstuvwxyz
+------------------------------------------------------------------------ 2
+abcdefghijklmnopqrstuvwxyz
+          --!             
+            ?             
+abcdefghij=====mnopqrstuvwxyz ( wit =  witlen = 0 )
+abcdefghij=====?mnopqrstuvwxyz
+------------------------------------------------------------------------
+abcdefghijklmnopqrstuvwxyz
+          --!             
+            ?             
+abcdefghij==mnopqrstuvwxyz ( wit =  witlen = 0 )
+abcdefghij==?mnopqrstuvwxyz
+------------------------------------------------------------------------
+abcdefghijklmnopqrstuvwxyz
+          --!             
+            ?             
+abcdefghij=mnopqrstuvwxyz ( wit =  witlen = 0 )
+abcdefghij=?mnopqrstuvwxyz
+------------------------------------------------------------------------
+abcdefghijklmnopqrstuvwxyz
+          --!             
+            ?             
+abcdefghijmnopqrstuvwxyz ( wit =  witlen = 0 )
+abcdefghij?mnopqrstuvwxyz
+------------------------------------------------------------------------ 3
+abcdefghijklmnopqrstuvwxyz
+            !             
+          --?             
+abcdefghijkl=====mnopqrstuvwxyz ( wit = kl witlen = 2 )
+abcdefghij?=====mnopqrstuvwxyz
+------------------------------------------------------------------------
+abcdefghijklmnopqrstuvwxyz
+            !             
+          --?             
+abcdefghijkl==mnopqrstuvwxyz ( wit = kl witlen = 2 )
+abcdefghij?==mnopqrstuvwxyz
+------------------------------------------------------------------------
+abcdefghijklmnopqrstuvwxyz
+            !             
+          --?             
+abcdefghijkl=mnopqrstuvwxyz ( wit = kl witlen = 2 )
+abcdefghij?=mnopqrstuvwxyz
+------------------------------------------------------------------------
+abcdefghijklmnopqrstuvwxyz
+            !             
+          --?             
+abcdefghijklmnopqrstuvwxyz ( wit = kl witlen = 2 )
+abcdefghij?mnopqrstuvwxyz
+------------------------------------------------------------------------ 4
+abcdefghijklmnopqrstuvwxyz
+          !               
+            ?             
+abcdefghij=====klmnopqrstuvwxyz ( wit =  witlen = 0 )
+abcdefghij=====kl?mnopqrstuvwxyz
+------------------------------------------------------------------------
+abcdefghijklmnopqrstuvwxyz
+          !               
+            ?             
+abcdefghij==klmnopqrstuvwxyz ( wit =  witlen = 0 )
+abcdefghij==kl?mnopqrstuvwxyz
+------------------------------------------------------------------------
+abcdefghijklmnopqrstuvwxyz
+          !               
+            ?             
+abcdefghij=klmnopqrstuvwxyz ( wit =  witlen = 0 )
+abcdefghij=kl?mnopqrstuvwxyz
+------------------------------------------------------------------------
+abcdefghijklmnopqrstuvwxyz
+          !               
+            ?             
+abcdefghijklmnopqrstuvwxyz ( wit =  witlen = 0 )
+abcdefghijkl?mnopqrstuvwxyz
+------------------------------------------------------------------------ 5
+abcdefghijklmnopqrstuvwxyz
+            !             
+          ?               
+abcdefghijkl=====mnopqrstuvwxyz ( wit =  witlen = 0 )
+abcdefghij?kl=====mnopqrstuvwxyz
+------------------------------------------------------------------------
+abcdefghijklmnopqrstuvwxyz
+            !             
+          ?               
+abcdefghijkl==mnopqrstuvwxyz ( wit =  witlen = 0 )
+abcdefghij?kl==mnopqrstuvwxyz
+------------------------------------------------------------------------
+abcdefghijklmnopqrstuvwxyz
+            !             
+          ?               
+abcdefghijkl=mnopqrstuvwxyz ( wit =  witlen = 0 )
+abcdefghij?kl=mnopqrstuvwxyz
+------------------------------------------------------------------------
+abcdefghijklmnopqrstuvwxyz
+            !             
+          ?               
+abcdefghijklmnopqrstuvwxyz ( wit =  witlen = 0 )
+abcdefghij?klmnopqrstuvwxyz
+------------------------------------------------------------------------ 6
+abcdefghijklmnopqrstuvwxyz
+          --!             
+          --?             
+abcdefghij=====mnopqrstuvwxyz ( wit = ===== witlen = 5 )
+abcdefghij?mnopqrstuvwxyz
+------------------------------------------------------------------------
+abcdefghijklmnopqrstuvwxyz
+          --!             
+          --?             
+abcdefghij==mnopqrstuvwxyz ( wit = == witlen = 2 )
+abcdefghij?mnopqrstuvwxyz
+------------------------------------------------------------------------
+abcdefghijklmnopqrstuvwxyz
+          --!             
+          --?             
+abcdefghij=mnopqrstuvwxyz ( wit = = witlen = 1 )
+abcdefghij?mnopqrstuvwxyz
+------------------------------------------------------------------------
+abcdefghijklmnopqrstuvwxyz
+          --!             
+          --?             
+abcdefghijmnopqrstuvwxyz ( wit =  witlen = 0 )
+abcdefghij?mnopqrstuvwxyz
+------------------------------------------------------------------------ 7
+abcdefghijklmnopqrstuvwxyz
+          --!             
+          ?               
+abcdefghij=====mnopqrstuvwxyz ( wit =  witlen = 0 )
+abcdefghij?=====mnopqrstuvwxyz
+------------------------------------------------------------------------
+abcdefghijklmnopqrstuvwxyz
+          --!             
+          ?               
+abcdefghij==mnopqrstuvwxyz ( wit =  witlen = 0 )
+abcdefghij?==mnopqrstuvwxyz
+------------------------------------------------------------------------
+abcdefghijklmnopqrstuvwxyz
+          --!             
+          ?               
+abcdefghij=mnopqrstuvwxyz ( wit =  witlen = 0 )
+abcdefghij?=mnopqrstuvwxyz
+------------------------------------------------------------------------
+abcdefghijklmnopqrstuvwxyz
+          --!             
+          ?               
+abcdefghijmnopqrstuvwxyz ( wit =  witlen = 0 )
+abcdefghij?mnopqrstuvwxyz
+------------------------------------------------------------------------ 8
+abcdefghijklmnopqrstuvwxyz
+          !               
+          --?             
+abcdefghij=====klmnopqrstuvwxyz ( wit = kl witlen = 2 )
+abcdefghij=====?mnopqrstuvwxyz
+------------------------------------------------------------------------
+abcdefghijklmnopqrstuvwxyz
+          !               
+          --?             
+abcdefghij==klmnopqrstuvwxyz ( wit = kl witlen = 2 )
+abcdefghij==?mnopqrstuvwxyz
+------------------------------------------------------------------------
+abcdefghijklmnopqrstuvwxyz
+          !               
+          --?             
+abcdefghij=klmnopqrstuvwxyz ( wit = kl witlen = 2 )
+abcdefghij=?mnopqrstuvwxyz
+------------------------------------------------------------------------
+abcdefghijklmnopqrstuvwxyz
+          !               
+          --?             
+abcdefghijklmnopqrstuvwxyz ( wit = kl witlen = 2 )
+abcdefghij?mnopqrstuvwxyz
+------------------------------------------------------------------------ 9
+abcdefghijklmnopqrstuvwxyz
+          --!             
+              ?           
+abcdefghij=====mnopqrstuvwxyz ( wit =  witlen = 0 )
+abcdefghij=====mn?opqrstuvwxyz
+------------------------------------------------------------------------
+abcdefghijklmnopqrstuvwxyz
+          --!             
+              ?           
+abcdefghij==mnopqrstuvwxyz ( wit =  witlen = 0 )
+abcdefghij==mn?opqrstuvwxyz
+------------------------------------------------------------------------
+abcdefghijklmnopqrstuvwxyz
+          --!             
+              ?           
+abcdefghij=mnopqrstuvwxyz ( wit =  witlen = 0 )
+abcdefghij=mn?opqrstuvwxyz
+------------------------------------------------------------------------
+abcdefghijklmnopqrstuvwxyz
+          --!             
+              ?           
+abcdefghijmnopqrstuvwxyz ( wit =  witlen = 0 )
+abcdefghijmn?opqrstuvwxyz
+------------------------------------------------------------------------ 10
+abcdefghijklmnopqrstuvwxyz
+          ----!           
+            --?           
+abcdefghij=====opqrstuvwxyz ( wit =  witlen = 0 )
+abcdefghij=====?opqrstuvwxyz
+------------------------------------------------------------------------
+abcdefghijklmnopqrstuvwxyz
+          ----!           
+            --?           
+abcdefghij==opqrstuvwxyz ( wit =  witlen = 0 )
+abcdefghij==?opqrstuvwxyz
+------------------------------------------------------------------------
+abcdefghijklmnopqrstuvwxyz
+          ----!           
+            --?           
+abcdefghij=opqrstuvwxyz ( wit =  witlen = 0 )
+abcdefghij=?opqrstuvwxyz
+------------------------------------------------------------------------
+abcdefghijklmnopqrstuvwxyz
+          ----!           
+            --?           
+abcdefghijopqrstuvwxyz ( wit =  witlen = 0 )
+abcdefghij?opqrstuvwxyz
+------------------------------------------------------------------------ 11
+abcdefghijklmnopqrstuvwxyz
+              !           
+          --?             
+abcdefghijklmn=====opqrstuvwxyz ( wit = kl witlen = 2 )
+abcdefghij?mn=====opqrstuvwxyz
+------------------------------------------------------------------------
+abcdefghijklmnopqrstuvwxyz
+              !           
+          --?             
+abcdefghijklmn==opqrstuvwxyz ( wit = kl witlen = 2 )
+abcdefghij?mn==opqrstuvwxyz
+------------------------------------------------------------------------
+abcdefghijklmnopqrstuvwxyz
+              !           
+          --?             
+abcdefghijklmn=opqrstuvwxyz ( wit = kl witlen = 2 )
+abcdefghij?mn=opqrstuvwxyz
+------------------------------------------------------------------------
+abcdefghijklmnopqrstuvwxyz
+              !           
+          --?             
+abcdefghijklmnopqrstuvwxyz ( wit = kl witlen = 2 )
+abcdefghij?mnopqrstuvwxyz
+------------------------------------------------------------------------ 12
+abcdefghijklmnopqrstuvwxyz
+            --!           
+          ----?           
+abcdefghijkl=====opqrstuvwxyz ( wit = kl===== witlen = 7 )
+abcdefghij?opqrstuvwxyz
+------------------------------------------------------------------------
+abcdefghijklmnopqrstuvwxyz
+            --!           
+          ----?           
+abcdefghijkl==opqrstuvwxyz ( wit = kl== witlen = 4 )
+abcdefghij?opqrstuvwxyz
+------------------------------------------------------------------------
+abcdefghijklmnopqrstuvwxyz
+            --!           
+          ----?           
+abcdefghijkl=opqrstuvwxyz ( wit = kl= witlen = 3 )
+abcdefghij?opqrstuvwxyz
+------------------------------------------------------------------------
+abcdefghijklmnopqrstuvwxyz
+            --!           
+          ----?           
+abcdefghijklopqrstuvwxyz ( wit = kl witlen = 2 )
+abcdefghij?opqrstuvwxyz
+------------------------------------------------------------------------ 13
+abcdefghijklmnopqrstuvwxyz
+          --!             
+            --?           
+abcdefghij=====mnopqrstuvwxyz ( wit = mn witlen = 2 )
+abcdefghij=====?opqrstuvwxyz
+------------------------------------------------------------------------
+abcdefghijklmnopqrstuvwxyz
+          --!             
+            --?           
+abcdefghij==mnopqrstuvwxyz ( wit = mn witlen = 2 )
+abcdefghij==?opqrstuvwxyz
+------------------------------------------------------------------------
+abcdefghijklmnopqrstuvwxyz
+          --!             
+            --?           
+abcdefghij=mnopqrstuvwxyz ( wit = mn witlen = 2 )
+abcdefghij=?opqrstuvwxyz
+------------------------------------------------------------------------
+abcdefghijklmnopqrstuvwxyz
+          --!             
+            --?           
+abcdefghijmnopqrstuvwxyz ( wit = mn witlen = 2 )
+abcdefghij?opqrstuvwxyz
+------------------------------------------------------------------------ 14
+abcdefghijklmnopqrstuvwxyz
+          ----!           
+            ?             
+abcdefghij=====opqrstuvwxyz ( wit =  witlen = 0 )
+abcdefghij?=====opqrstuvwxyz
+------------------------------------------------------------------------
+abcdefghijklmnopqrstuvwxyz
+          ----!           
+            ?             
+abcdefghij==opqrstuvwxyz ( wit =  witlen = 0 )
+abcdefghij?==opqrstuvwxyz
+------------------------------------------------------------------------
+abcdefghijklmnopqrstuvwxyz
+          ----!           
+            ?             
+abcdefghij=opqrstuvwxyz ( wit =  witlen = 0 )
+abcdefghij?=opqrstuvwxyz
+------------------------------------------------------------------------
+abcdefghijklmnopqrstuvwxyz
+          ----!           
+            ?             
+abcdefghijopqrstuvwxyz ( wit =  witlen = 0 )
+abcdefghij?opqrstuvwxyz
+------------------------------------------------------------------------ 15
+abcdefghijklmnopqrstuvwxyz
+            --!           
+          --?             
+abcdefghijkl=====opqrstuvwxyz ( wit = kl witlen = 2 )
+abcdefghij?=====opqrstuvwxyz
+------------------------------------------------------------------------
+abcdefghijklmnopqrstuvwxyz
+            --!           
+          --?             
+abcdefghijkl==opqrstuvwxyz ( wit = kl witlen = 2 )
+abcdefghij?==opqrstuvwxyz
+------------------------------------------------------------------------
+abcdefghijklmnopqrstuvwxyz
+            --!           
+          --?             
+abcdefghijkl=opqrstuvwxyz ( wit = kl witlen = 2 )
+abcdefghij?=opqrstuvwxyz
+------------------------------------------------------------------------
+abcdefghijklmnopqrstuvwxyz
+            --!           
+          --?             
+abcdefghijklopqrstuvwxyz ( wit = kl witlen = 2 )
+abcdefghij?opqrstuvwxyz
+------------------------------------------------------------------------ 16
+abcdefghijklmnopqrstuvwxyz
+            !             
+          ----?           
+abcdefghijkl=====mnopqrstuvwxyz ( wit = kl=====mn witlen = 9 )
+abcdefghij?opqrstuvwxyz
+------------------------------------------------------------------------
+abcdefghijklmnopqrstuvwxyz
+            !             
+          ----?           
+abcdefghijkl==mnopqrstuvwxyz ( wit = kl==mn witlen = 6 )
+abcdefghij?opqrstuvwxyz
+------------------------------------------------------------------------
+abcdefghijklmnopqrstuvwxyz
+            !             
+          ----?           
+abcdefghijkl=mnopqrstuvwxyz ( wit = kl=mn witlen = 5 )
+abcdefghij?opqrstuvwxyz
+------------------------------------------------------------------------
+abcdefghijklmnopqrstuvwxyz
+            !             
+          ----?           
+abcdefghijklmnopqrstuvwxyz ( wit = klmn witlen = 4 )
+abcdefghij?opqrstuvwxyz
+------------------------------------------------------------------------ 17
+abcdefghijklmnopqrstuvwxyz
+          ----!           
+          --?             
+abcdefghij=====opqrstuvwxyz ( wit =  witlen = 0 )
+abcdefghij?=====opqrstuvwxyz
+------------------------------------------------------------------------
+abcdefghijklmnopqrstuvwxyz
+          ----!           
+          --?             
+abcdefghij==opqrstuvwxyz ( wit =  witlen = 0 )
+abcdefghij?==opqrstuvwxyz
+------------------------------------------------------------------------
+abcdefghijklmnopqrstuvwxyz
+          ----!           
+          --?             
+abcdefghij=opqrstuvwxyz ( wit =  witlen = 0 )
+abcdefghij?=opqrstuvwxyz
+------------------------------------------------------------------------
+abcdefghijklmnopqrstuvwxyz
+          ----!           
+          --?             
+abcdefghijopqrstuvwxyz ( wit =  witlen = 0 )
+abcdefghij?opqrstuvwxyz
+------------------------------------------------------------------------ 18
+abcdefghijklmnopqrstuvwxyz
+          !               
+            --?           
+abcdefghij=====klmnopqrstuvwxyz ( wit = mn witlen = 2 )
+abcdefghij=====kl?opqrstuvwxyz
+------------------------------------------------------------------------
+abcdefghijklmnopqrstuvwxyz
+          !               
+            --?           
+abcdefghij==klmnopqrstuvwxyz ( wit = mn witlen = 2 )
+abcdefghij==kl?opqrstuvwxyz
+------------------------------------------------------------------------
+abcdefghijklmnopqrstuvwxyz
+          !               
+            --?           
+abcdefghij=klmnopqrstuvwxyz ( wit = mn witlen = 2 )
+abcdefghij=kl?opqrstuvwxyz
+------------------------------------------------------------------------
+abcdefghijklmnopqrstuvwxyz
+          !               
+            --?           
+abcdefghijklmnopqrstuvwxyz ( wit = mn witlen = 2 )
+abcdefghijkl?opqrstuvwxyz
+------------------------------------------------------------------------ 19
+abcdefghijklmnopqrstuvwxyz
+          --!             
+          ----?           
+abcdefghij=====mnopqrstuvwxyz ( wit = =====mn witlen = 7 )
+abcdefghij?opqrstuvwxyz
+------------------------------------------------------------------------
+abcdefghijklmnopqrstuvwxyz
+          --!             
+          ----?           
+abcdefghij==mnopqrstuvwxyz ( wit = ==mn witlen = 4 )
+abcdefghij?opqrstuvwxyz
+------------------------------------------------------------------------
+abcdefghijklmnopqrstuvwxyz
+          --!             
+          ----?           
+abcdefghij=mnopqrstuvwxyz ( wit = =mn witlen = 3 )
+abcdefghij?opqrstuvwxyz
+------------------------------------------------------------------------
+abcdefghijklmnopqrstuvwxyz
+          --!             
+          ----?           
+abcdefghijmnopqrstuvwxyz ( wit = mn witlen = 2 )
+abcdefghij?opqrstuvwxyz
+------------------------------------------------------------------------ 20
+abcdefghijklmnopqrstuvwxyz
+            --!           
+          ?               
+abcdefghijkl=====opqrstuvwxyz ( wit =  witlen = 0 )
+abcdefghij?kl=====opqrstuvwxyz
+------------------------------------------------------------------------
+abcdefghijklmnopqrstuvwxyz
+            --!           
+          ?               
+abcdefghijkl==opqrstuvwxyz ( wit =  witlen = 0 )
+abcdefghij?kl==opqrstuvwxyz
+------------------------------------------------------------------------
+abcdefghijklmnopqrstuvwxyz
+            --!           
+          ?               
+abcdefghijkl=opqrstuvwxyz ( wit =  witlen = 0 )
+abcdefghij?kl=opqrstuvwxyz
+------------------------------------------------------------------------
+abcdefghijklmnopqrstuvwxyz
+            --!           
+          ?               
+abcdefghijklopqrstuvwxyz ( wit =  witlen = 0 )
+abcdefghij?klopqrstuvwxyz
+------------------------------------------------------------------------ 21
+abcdefghijklmnopqrstuvwxyz
+          --!             
+              --?         
+abcdefghij=====mnopqrstuvwxyz ( wit = op witlen = 2 )
+abcdefghij=====mn?qrstuvwxyz
+------------------------------------------------------------------------
+abcdefghijklmnopqrstuvwxyz
+          --!             
+              --?         
+abcdefghij==mnopqrstuvwxyz ( wit = op witlen = 2 )
+abcdefghij==mn?qrstuvwxyz
+------------------------------------------------------------------------
+abcdefghijklmnopqrstuvwxyz
+          --!             
+              --?         
+abcdefghij=mnopqrstuvwxyz ( wit = op witlen = 2 )
+abcdefghij=mn?qrstuvwxyz
+------------------------------------------------------------------------
+abcdefghijklmnopqrstuvwxyz
+          --!             
+              --?         
+abcdefghijmnopqrstuvwxyz ( wit = op witlen = 2 )
+abcdefghijmn?qrstuvwxyz
+------------------------------------------------------------------------ 22
+abcdefghijklmnopqrstuvwxyz
+          ----!           
+            ----?         
+abcdefghij=====opqrstuvwxyz ( wit = op witlen = 2 )
+abcdefghij=====?qrstuvwxyz
+------------------------------------------------------------------------
+abcdefghijklmnopqrstuvwxyz
+          ----!           
+            ----?         
+abcdefghij==opqrstuvwxyz ( wit = op witlen = 2 )
+abcdefghij==?qrstuvwxyz
+------------------------------------------------------------------------
+abcdefghijklmnopqrstuvwxyz
+          ----!           
+            ----?         
+abcdefghij=opqrstuvwxyz ( wit = op witlen = 2 )
+abcdefghij=?qrstuvwxyz
+------------------------------------------------------------------------
+abcdefghijklmnopqrstuvwxyz
+          ----!           
+            ----?         
+abcdefghijopqrstuvwxyz ( wit = op witlen = 2 )
+abcdefghij?qrstuvwxyz
+------------------------------------------------------------------------ 23
+abcdefghijklmnopqrstuvwxyz
+          ------!         
+            --?           
+abcdefghij=====qrstuvwxyz ( wit =  witlen = 0 )
+abcdefghij?=====qrstuvwxyz
+------------------------------------------------------------------------
+abcdefghijklmnopqrstuvwxyz
+          ------!         
+            --?           
+abcdefghij==qrstuvwxyz ( wit =  witlen = 0 )
+abcdefghij?==qrstuvwxyz
+------------------------------------------------------------------------
+abcdefghijklmnopqrstuvwxyz
+          ------!         
+            --?           
+abcdefghij=qrstuvwxyz ( wit =  witlen = 0 )
+abcdefghij?=qrstuvwxyz
+------------------------------------------------------------------------
+abcdefghijklmnopqrstuvwxyz
+          ------!         
+            --?           
+abcdefghijqrstuvwxyz ( wit =  witlen = 0 )
+abcdefghij?qrstuvwxyz
+------------------------------------------------------------------------ 24
+abcdefghijklmnopqrstuvwxyz
+              --!         
+          --?             
+abcdefghijklmn=====qrstuvwxyz ( wit = kl witlen = 2 )
+abcdefghij?mn=====qrstuvwxyz
+------------------------------------------------------------------------
+abcdefghijklmnopqrstuvwxyz
+              --!         
+          --?             
+abcdefghijklmn==qrstuvwxyz ( wit = kl witlen = 2 )
+abcdefghij?mn==qrstuvwxyz
+------------------------------------------------------------------------
+abcdefghijklmnopqrstuvwxyz
+              --!         
+          --?             
+abcdefghijklmn=qrstuvwxyz ( wit = kl witlen = 2 )
+abcdefghij?mn=qrstuvwxyz
+------------------------------------------------------------------------
+abcdefghijklmnopqrstuvwxyz
+              --!         
+          --?             
+abcdefghijklmnqrstuvwxyz ( wit = kl witlen = 2 )
+abcdefghij?mnqrstuvwxyz
+------------------------------------------------------------------------ 25
+abcdefghijklmnopqrstuvwxyz
+            ----!         
+          ----?           
+abcdefghijkl=====qrstuvwxyz ( wit = kl witlen = 2 )
+abcdefghij?=====qrstuvwxyz
+------------------------------------------------------------------------
+abcdefghijklmnopqrstuvwxyz
+            ----!         
+          ----?           
+abcdefghijkl==qrstuvwxyz ( wit = kl witlen = 2 )
+abcdefghij?==qrstuvwxyz
+------------------------------------------------------------------------
+abcdefghijklmnopqrstuvwxyz
+            ----!         
+          ----?           
+abcdefghijkl=qrstuvwxyz ( wit = kl witlen = 2 )
+abcdefghij?=qrstuvwxyz
+------------------------------------------------------------------------
+abcdefghijklmnopqrstuvwxyz
+            ----!         
+          ----?           
+abcdefghijklqrstuvwxyz ( wit = kl witlen = 2 )
+abcdefghij?qrstuvwxyz
+------------------------------------------------------------------------ 26
+abcdefghijklmnopqrstuvwxyz
+            --!           
+          ------?         
+abcdefghijkl=====opqrstuvwxyz ( wit = kl=====op witlen = 9 )
+abcdefghij?qrstuvwxyz
+------------------------------------------------------------------------
+abcdefghijklmnopqrstuvwxyz
+            --!           
+          ------?         
+abcdefghijkl==opqrstuvwxyz ( wit = kl==op witlen = 6 )
+abcdefghij?qrstuvwxyz
+------------------------------------------------------------------------
+abcdefghijklmnopqrstuvwxyz
+            --!           
+          ------?         
+abcdefghijkl=opqrstuvwxyz ( wit = kl=op witlen = 5 )
+abcdefghij?qrstuvwxyz
+------------------------------------------------------------------------
+abcdefghijklmnopqrstuvwxyz
+            --!           
+          ------?         
+abcdefghijklopqrstuvwxyz ( wit = klop witlen = 4 )
+abcdefghij?qrstuvwxyz
Index: tests/collections/string-api-coverage.cfa
===================================================================
--- tests/collections/string-api-coverage.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
+++ tests/collections/string-api-coverage.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -0,0 +1,291 @@
+#include <containers/string.hfa>
+
+void assertWellFormedHandleList( int maxLen ) { // with(HeapArea)
+    // HandleNode *n;
+    // int limit1 = maxLen;
+    // for ( n = Header.flink; (limit1-- > 0) && n != &Header; n = n->flink ) {}
+    // assert (n == &Header);
+    // int limit2 = maxLen;
+    // for ( n = Header.blink; (limit2-- > 0) && n != &Header; n = n->blink ) {}
+    // assert (n == &Header);
+    // assert (limit1 == limit2);
+}
+
+// The given string is reachable.
+void assertOnHandleList( string & q ) { // with(HeapArea)
+    // HandleNode *n;
+    // for ( n = Header.flink; n != &Header; n = n->flink ) {
+    //     if ( n == & q.inner->Handle ) return;
+    // }
+    // assert( false );
+}
+
+
+// Purpose: call each function in string.hfa, top to bottom
+
+int main () {
+    string s = "hello";
+    string s2 = "hello";
+    string s3 = "world";
+    string frag = "ell";
+
+    // IO operator, x2
+    sout | s | s | s;
+
+    // Comparisons
+    // all print "true false"
+    sout | (s == s2) | (s == s3);
+    sout | (s != s3) | (s != s2);
+    sout | (s == "hello") | (s == "world");
+    sout | (s != "world") | (s != "hello");
+    sout | ( frag == s(1,4) ) | ( s3   == s(1,4) );
+    sout | ( s3   != s(1,4) ) | ( frag != s(1,4) );
+    sout | ( s2(1,4) == s(1,4) ) | ( s3(1,4)   == s(1,4) );
+    sout | ( s3(1,4) != s(1,4) ) | ( s2(1,4)   != s(1,4) );
+    sout | ( s(1,4) == frag ) | ( s(1,4) == s3   );
+    sout | ( s(1,4) != s3   ) | ( s(1,4) != frag );
+    sout | ( s(1,4) == "ell"   ) | ( s(1,4) == "world" );
+    sout | ( s(1,4) != "world" ) | ( s(1,4) != "ell"   );
+
+
+                                            assertWellFormedHandleList( 10 );
+    //
+    // breadth Constructors
+    //
+    {
+        string b1 = { "1234567", 3 };
+        sout | b1; // 123
+
+        string b2 = s;
+        sout | b2; // hello
+
+        // todo: a plain string &
+        const string & s_ref = s;
+        string b3 = s_ref;
+        sout | b3;  // hello
+
+        & s_ref = & s3;
+        b3 = s_ref;
+        sout | b3; // world
+
+        const string & s_constref = s;
+        string b4 = s_constref;
+        sout | b4; // hello
+
+        & s_constref = & s3;
+        b4 = s_constref;
+        sout | b4;  // world
+    }
+                                            assertWellFormedHandleList( 10 );
+
+    sout | size(s); // 5
+
+    //
+    // concatenation/append
+    //
+
+    string sx = s + s3;
+                                            assertWellFormedHandleList( 10 );
+    sout | sx; // helloworld
+                                            assertWellFormedHandleList( 10 );
+    sx = "xx";
+                                            assertWellFormedHandleList( 10 );
+    sx = s + s3;
+                                            assertWellFormedHandleList( 10 );
+    sout | sx; // helloworld
+                                            assertWellFormedHandleList( 10 );
+
+    sx += '!';
+    sout | sx; // helloworld!
+    sx = s + '!';
+    sout | sx; // hello!
+
+    sx = s;
+    sx += s;
+    sout | sx; // hellohello
+                                            assertWellFormedHandleList( 10 );
+    sx += ", friend";    
+    sout | sx; // hellohello, friend
+
+    sx = s + ", friend";
+    sout | sx; // hello, friend
+
+    sx = "bye, " + "friend";
+    sout | sx; // bye, friend
+
+    //
+    // repetition
+    //
+    sx = s * 3;
+    sout | sx; // hellohellohello
+
+    sx = 'Q' * (size_t)3;
+    sout | sx; // QQQ
+
+    sx = "asdf" * 3;
+    sout | sx; // asdfasdfasdf
+
+    //
+    // slicing
+    //
+
+    //...
+
+    //
+    // character access
+    //
+
+    char c = s[1];
+    sout | c;   // e
+
+    s[3] = "p!!!";
+    sout | s;   // help!!!o
+
+    s[7] = '!';
+    sout | s;   // help!!!!
+
+    s[7] = "";
+    sout | s;   // help!!!
+
+    sout | s[3]; // p
+
+    //
+    // search
+    //
+
+    s += '?'; // already tested
+    sout | contains( s, 'h' ) | contains( s, '?' ) | contains( s, 'o' ); // true true false
+
+    sout
+        | find( s, 'h' )  // 0
+        | find( s, '!' )  // 4
+        | find( s, '?' )  // 7
+        | find( s, 'o' ); // 8, not found
+
+    string alphabet = "abcdefghijklmnopqrstuvwxyz";
+
+    sout
+        | find( alphabet, "" )    // 0
+        | find( alphabet, "a" )   // 0
+        | find( alphabet, "z" )   // 25
+        | find( alphabet, "abc" ) // 0
+        | find( alphabet, "abq" ) // 26, not found
+        | find( alphabet, "def"); // 3
+    
+    sout
+        | includes( alphabet, "" )    // true
+        | includes( alphabet, "a" )   // true
+        | includes( alphabet, "z" )   // true
+        | includes( alphabet, "abc" ) // true
+        | includes( alphabet, "abq" ) // false
+        | includes( alphabet, "def"); // true
+    
+    {
+        char *empty_c = "";
+        char *a_c = "a";
+        char *z_c = "z";
+        char *dex_c = "dex";
+
+        sout
+            | find( alphabet, empty_c )   // 0
+            | find( alphabet, a_c )       // 0
+            | find( alphabet, dex_c )     // 26, not found
+            | find( alphabet, dex_c, 2 ); // 3
+
+        sout
+            | includes( alphabet, empty_c )   // true
+            | includes( alphabet, a_c )       // true
+            | includes( alphabet, dex_c )     // false
+            | includes( alphabet, dex_c, 2 ); // true
+
+        sout
+            | startsWith( alphabet, a_c)            // true
+            | endsWith  ( alphabet, a_c)            // false
+            | startsWith( alphabet, z_c)            // false
+            | endsWith  ( alphabet, z_c);           // true
+
+        string empty = empty_c;
+        string a = a_c;
+        string z = z_c;
+        string dex = dex_c;
+
+        sout
+            | find( alphabet, empty )     // 0
+            | find( alphabet, a )         // 0
+            | find( alphabet, dex )       // 26, not found
+            | find( alphabet, dex(0,2) ); // 3
+
+        sout
+            | includes( alphabet, empty )     // true
+            | includes( alphabet, a )         // true
+            | includes( alphabet, dex )       // false
+            | includes( alphabet, dex(0,2) ); // true
+
+        sout
+            | startsWith( alphabet, a)            // true
+            | endsWith  ( alphabet, a)            // false
+            | startsWith( alphabet, z)            // false
+            | endsWith  ( alphabet, z);           // true
+    }
+
+    sout
+        | find( alphabet        , "def")  // 3
+        | find( alphabet( 0, 26), "def")  // 3
+        | find( alphabet( 2, 26), "def")  // 1
+        | find( alphabet( 3, 26), "def")  // 0
+        | find( alphabet( 4, 26), "def")  // 22, not found
+        | find( alphabet( 4, 26),  "ef")  // 0
+        | find( alphabet( 0,  6), "def")  // 3
+        | find( alphabet( 0,  5), "def")  // 5, not found
+        | find( alphabet( 0,  5), "de" ); // 3
+
+    sout
+        | includes( alphabet        , "def")  // true
+        | includes( alphabet( 0, 26), "def")  // true
+        | includes( alphabet( 2, 26), "def")  // true
+        | includes( alphabet( 3, 26), "def")  // true
+        | includes( alphabet( 4, 26), "def")  // false
+        | includes( alphabet( 4, 26),  "ef")  // true
+        | includes( alphabet( 0,  6), "def")  // true
+        | includes( alphabet( 0,  5), "def")  // false
+        | includes( alphabet( 0,  5), "de" ); // true
+
+    sout
+        | startsWith( alphabet        , "abc")  // true
+        | startsWith( alphabet( 0, 26), "abc")  // true
+        | startsWith( alphabet( 1, 26), "abc")  // false
+        | startsWith( alphabet( 1, 26),  "bc")  // true
+        | startsWith( alphabet( 0, 26), "abc")  // true
+        | startsWith( alphabet( 0,  4), "abc")  // true
+        | startsWith( alphabet( 0,  3), "abc")  // true
+        | startsWith( alphabet( 0,  3), "ab" )  // true
+        | startsWith( alphabet        , "xyz"); // false
+
+    sout
+        | endsWith( alphabet        , "xyz")  // true
+        | endsWith( alphabet        , "xyzz") // false
+        | endsWith( alphabet( 0, 26), "xyz")  // true
+        | endsWith( alphabet( 0, 25), "xyz")  // false
+        | endsWith( alphabet( 0, 25), "xy" )  // true
+        | endsWith( alphabet( 0, 26), "xyz")  // true
+        | endsWith( alphabet(23, 26), "xyz")  // true
+        | endsWith( alphabet(24, 26), "xyz")  // false
+        | endsWith( alphabet(24, 26),  "yz")  // true
+        | endsWith( alphabet        , "abc"); // false
+
+    charclass cc_cba = {"cba"};
+    charclass cc_onml = {"onml"};
+    charclass cc_alphabet = {alphabet};
+
+    // include (rest of the) numbers:  tell me where the numbers stop
+    // exclude (until)       numbers:  tell me where the numbers start (include rest of the non-numbers)
+
+    sout
+        | include( alphabet, cc_cba )  // 3
+        | exclude( alphabet, cc_cba )  // 0
+        | include( alphabet, cc_onml )  // 0
+        | exclude( alphabet, cc_onml )  // 11
+        | include( alphabet, cc_alphabet )  // 26
+        | exclude( alphabet, cc_alphabet ); // 0
+}
+
Index: tests/collections/string-gc.cfa
===================================================================
--- tests/collections/string-gc.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
+++ tests/collections/string-gc.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -0,0 +1,125 @@
+#include <string_res.hfa>
+
+size_t bytesRemaining() {
+    return DEBUG_string_bytes_avail_until_gc( DEBUG_string_heap );
+}
+
+size_t heapOffsetStart( string_res & s ) {
+    const char * startByte = DEBUG_string_heap_start( DEBUG_string_heap );
+    assert( s.Handle.s >= startByte );
+    return s.Handle.s - startByte;
+}
+
+void prtStrRep(const char * label, string_res & s) {
+    sout | label | "from" | heapOffsetStart(s) | "to" | (heapOffsetStart(s) + size(s));
+}
+#define PRT_STR_REP(s) prtStrRep( #s, s )
+
+void basicFillCompact() {
+    sout | "======================== basicFillCompact";
+    string_res xinit = "hello!";
+    string_res x = {xinit, COPY_VALUE};
+    string_res padder = "----|";
+    sout | x;
+    for( 3 ) {
+        x += padder;
+        sout | x;
+    }
+
+    // x and padder overlap
+    sout | "--A";
+    sout | "length of x:" | size(x);
+    PRT_STR_REP(padder);
+    PRT_STR_REP(x);
+
+    while ( bytesRemaining() + 1 > 5 ) { // until room for "q" but not another "----|" thereafter
+        x += padder;
+    }
+
+    // x and padder still overlap; now x is huge
+    sout | "--B";
+    sout | "length of x:" | size(x);
+    PRT_STR_REP(padder);
+    PRT_STR_REP(x);
+
+    assert( bytesRemaining() >= 1 );
+    x = "q";
+
+    // x and padder no longer overlap; baseline xinit
+    sout | "--C";
+    PRT_STR_REP(xinit);
+    PRT_STR_REP(padder);
+    PRT_STR_REP(x);
+
+    // want the next edit to straddle the bound
+    assert( bytesRemaining() < size(padder) );
+
+    sout | "--D";
+    sout | "before append, x = " | x;     // q
+    x += padder;                         // trigger compaction
+    sout | "after append, x = " | x;      // q----|
+
+    // x and padder moved to the start
+    sout | "--E";
+    PRT_STR_REP(xinit);
+    PRT_STR_REP(padder);
+    PRT_STR_REP(x);
+
+    // plenty of room now
+    sout | "--F";
+    sout | bytesRemaining() | "bytes available before re-fill";
+
+    // fill it again
+    string_res z = "zzz";
+    while ( bytesRemaining() > 1 ) {
+        z += ".";
+    }
+
+    sout | bytesRemaining() | "bytes available after re-fill";
+
+    // ensure not affected (shows it's not referencing an invalid location that hadn't been overwritten from the original value yet)
+    // black-box criterion that matches earlier "saw it move"
+    sout | "--G";
+    sout | "after re-fill, x = " | x;      // q----|
+
+    // leave the heap basically empty, for the next test
+    z = "";                        // turn used space into gargbage
+    string_res whatever = "asdf";  // trigger compaction
+    assert( bytesRemaining() > 100 );
+}
+
+void fillCompact_withSharedEdits() {
+    // do an assignment that causes a collection to happen, while there are edits shared (substrings)
+
+    sout | "======================== fillCompact_withSharedEdits";
+
+    // mostly fill the pad
+    string_res z = "zzz";
+    while ( bytesRemaining() > 10 ) {
+        z += ".";
+    }
+    z = "";  // leave compaction possible
+
+    // setup
+    string_res x = "hello";
+    string_res y = { x, SHARE_EDITS, 0, 5 };
+    PRT_STR_REP(x);
+    PRT_STR_REP(y);
+    sout | "-";
+
+    sout | "before reassign, x = " | x;     // hello
+    sout | "before reassign, y = " | y;     // hello
+
+    x = "0123456789"; // compact here
+
+    sout | "after reassign, x = " | x;      // 0123456789
+    sout | "after reassign, y = " | y;      // 0123456789
+
+    PRT_STR_REP(x);
+    PRT_STR_REP(y);
+}
+
+int main() {
+    basicFillCompact();
+    fillCompact_withSharedEdits();
+}
Index: tests/collections/string-overwrite.cfa
===================================================================
--- tests/collections/string-overwrite.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
+++ tests/collections/string-overwrite.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -0,0 +1,263 @@
+#include <containers/string.hfa>
+
+/*
+
+Modify a subrange of a string, while a witness is watching another subrange of the same string.
+
+Cases are the relative positions and overlaps of the modifier vs the witness.
+MS = modifier start
+ME = modifier end
+WS = witness start
+WE = witness end
+
+The dest does:
+  starts with the entire string being, initially, the alphabet; prints this entire alphabet
+  sets up modifier and witness as ranges within it, and prints a visualization of those ranges
+  does the main modification
+  prints the result of the main modification, which is always an unsurprising consequence of the modifier range, but shows little about what happened to the witness, particularly if the witness is/became empty
+  modifies the witness to be "?"
+  prints the result of this second modification, which implies what the witness included after the main modification
+
+Deriving the concrete list of cases....
+
+By definition of a string, MS <= ME and WS <= WE.
+This API's convention has Start positions being inclusive and end positions being exclusive.
+
+With 1 equivalence class:
+MS = ME = WS = WE               1
+
+With 2 equivalence classes:
+   <    =    =
+MS   rest                       2
+WS   rest                       3
+
+   =    <    =
+MS   ME   WS   WE               4
+WS   WE   MS   ME               5
+MS   WS   ME   WE               6
+
+   =    =    <
+        rest   ME               7
+        rest   WE               8
+
+With 3 equivalence classes
+   <    <    =
+MS   ME   WS   WE               9
+     WS   ME   WE               10
++2                              11, 12
+
+   <    =    <
+MS   WS   ME   WE               13
+          WE   ME               14
++2                              15, 16
+
+   =    <    <
+MS   WS   WE   ME               17
+     ME   WS   WE               18
++2                              19, 20
+
+With 4 equivalence classes
+   <    <    <
+MS   ME   WS   WE               21
+     WS   ME   WE               22
+          WE   ME               23
++3                              24, 25, 26
+
+
+
+*/
+
+
+void showOneReplacement(string & s, int ms, int me, int ws, int we, const char* replaceWith) {
+
+    assert( ms >= 0 && ms <= me && me <= size(s) );
+    assert( ws >= 0 && ws <= we && we <= size(s) );
+
+    string mod = s(ms, me)`shareEdits;
+    string wit = s(ws, we)`shareEdits;
+
+    string modOld = mod;
+    string witOld = wit;
+
+    // s, before the mode
+    sout | s;
+
+    // visualize the pair of ranges
+    sout | nlOff;
+    for ( i; size(s) ) {
+        if( i < ms || i > me ) {
+            sout | ' ';
+        } else if ( i < me ) {
+            sout | '-';
+        } else {
+            assert ( i == me );
+            sout | '!';
+        }
+    } sout | nl;
+    for ( i; size(s) ) {
+        if( i < ws || i > we ) {
+            sout | ' ';
+        } else if ( i < we ) {
+            sout | '-';
+        } else {
+            assert ( i == we );
+            sout | '?';
+        }
+    }
+    sout | nl;
+    sout | nlOn;
+
+    mod = replaceWith;    // main replacement
+    sout | s | "( wit = " | wit | "witlen = " | size(wit) | " )";
+    wit = "?";            // witness-revelaing replacement
+    sout | s;
+}
+
+void runReplaceCases() {
+    char * alphabetTemplate = "abcdefghijklmnopqrstuvwxyz";
+    struct { int ms; int me; int ws; int we; char *replaceWith; char *label; } cases[] = {
+        { 12, 14, 10, 20, "xxxxx", "warmup" },
+//        { 12, 14, 12, 14, "xxxxx", ""       },  // the bug that got me into this test (should be a dup with case 6)
+        { 10, 10, 10, 10, "=====", "1"      },
+        { 10, 10, 10, 10, "=="   , ""       },
+        { 10, 10, 10, 10, "="    , ""       },
+        { 10, 10, 10, 10, ""     , ""       },
+        { 10, 12, 12, 12, "=====", "2"      },
+        { 10, 12, 12, 12, "=="   , ""       },
+        { 10, 12, 12, 12, "="    , ""       },
+        { 10, 12, 12, 12, ""     , ""       },
+        { 12, 12, 10, 12, "=====", "3"      },
+        { 12, 12, 10, 12, "=="   , ""       },
+        { 12, 12, 10, 12, "="    , ""       },
+        { 12, 12, 10, 12, ""     , ""       },
+        { 10, 10, 12, 12, "=====", "4"      },
+        { 10, 10, 12, 12, "=="   , ""       },
+        { 10, 10, 12, 12, "="    , ""       },
+        { 10, 10, 12, 12, ""     , ""       },
+        { 12, 12, 10, 10, "=====", "5"      },
+        { 12, 12, 10, 10, "=="   , ""       },
+        { 12, 12, 10, 10, "="    , ""       },
+        { 12, 12, 10, 10, ""     , ""       },
+        { 10, 12, 10, 12, "=====", "6"      },
+        { 10, 12, 10, 12, "=="   , ""       },
+        { 10, 12, 10, 12, "="    , ""       },
+        { 10, 12, 10, 12, ""     , ""       },
+        { 10, 12, 10, 10, "=====", "7"      },
+        { 10, 12, 10, 10, "=="   , ""       },
+        { 10, 12, 10, 10, "="    , ""       },
+        { 10, 12, 10, 10, ""     , ""       },
+        { 10, 10, 10, 12, "=====", "8"      },
+        { 10, 10, 10, 12, "=="   , ""       },
+        { 10, 10, 10, 12, "="    , ""       },
+        { 10, 10, 10, 12, ""     , ""       },
+        { 10, 12, 14, 14, "=====", "9"      },
+        { 10, 12, 14, 14, "=="   , ""       },
+        { 10, 12, 14, 14, "="    , ""       },
+        { 10, 12, 14, 14, ""     , ""       },
+        { 10, 14, 12, 14, "=====", "10"     },
+        { 10, 14, 12, 14, "=="   , ""       },
+        { 10, 14, 12, 14, "="    , ""       },  // FORMERLY unrunnable bug: tries to print seemingly infinite string
+        { 10, 14, 12, 14, ""     , ""       },  // ditto
+        { 14, 14, 10, 12, "=====", "11"     },
+        { 14, 14, 10, 12, "=="   , ""       },
+        { 14, 14, 10, 12, "="    , ""       },
+        { 14, 14, 10, 12, ""     , ""       },
+        { 12, 14, 10, 14, "=====", "12"     }, // correctness observation:  watching klmn while mn |-> xxx gives klxxx because the mn is inside what I'm watching
+        { 12, 14, 10, 14, "=="   , ""       },
+        { 12, 14, 10, 14, "="    , ""       },
+        { 12, 14, 10, 14, ""     , ""       },
+        { 10, 12, 12, 14, "=====", "13"     },
+        { 10, 12, 12, 14, "=="   , ""       },
+        { 10, 12, 12, 14, "="    , ""       },
+        { 10, 12, 12, 14, ""     , ""       },
+        { 10, 14, 12, 12, "=====", "14"     },
+        { 10, 14, 12, 12, "=="   , ""       },
+        { 10, 14, 12, 12, "="    , ""       },
+        { 10, 14, 12, 12, ""     , ""       },
+        { 12, 14, 10, 12, "=====", "15"     },
+        { 12, 14, 10, 12, "=="   , ""       },
+        { 12, 14, 10, 12, "="    , ""       },
+        { 12, 14, 10, 12, ""     , ""       },
+        { 12, 12, 10, 14, "=====", "16"     },
+        { 12, 12, 10, 14, "=="   , ""       },
+        { 12, 12, 10, 14, "="    , ""       },
+        { 12, 12, 10, 14, ""     , ""       },
+        { 10, 14, 10, 12, "=====", "17"     },
+        { 10, 14, 10, 12, "=="   , ""       },
+        { 10, 14, 10, 12, "="    , ""       },
+        { 10, 14, 10, 12, ""     , ""       },
+        { 10, 10, 12, 14, "=====", "18"     },
+        { 10, 10, 12, 14, "=="   , ""       },
+        { 10, 10, 12, 14, "="    , ""       },
+        { 10, 10, 12, 14, ""     , ""       },
+        { 10, 12, 10, 14, "=====", "19"     },
+        { 10, 12, 10, 14, "=="   , ""       },
+        { 10, 12, 10, 14, "="    , ""       },
+        { 10, 12, 10, 14, ""     , ""       },
+        { 12, 14, 10, 10, "=====", "20"     },
+        { 12, 14, 10, 10, "=="   , ""       },
+        { 12, 14, 10, 10, "="    , ""       },
+        { 12, 14, 10, 10, ""     , ""       },
+        { 10, 12, 14, 16, "=====", "21"     },
+        { 10, 12, 14, 16, "=="   , ""       },
+        { 10, 12, 14, 16, "="    , ""       },
+        { 10, 12, 14, 16, ""     , ""       },
+        { 10, 14, 12, 16, "=====", "22"     },
+        { 10, 14, 12, 16, "=="   , ""       },
+        { 10, 14, 12, 16, "="    , ""       },
+        { 10, 14, 12, 16, ""     , ""       },
+        { 10, 16, 12, 14, "=====", "23"     },
+        { 10, 16, 12, 14, "=="   , ""       },
+        { 10, 16, 12, 14, "="    , ""       },
+        { 10, 16, 12, 14, ""     , ""       },
+        { 14, 16, 10, 12, "=====", "24"     },
+        { 14, 16, 10, 12, "=="   , ""       },
+        { 14, 16, 10, 12, "="    , ""       },
+        { 14, 16, 10, 12, ""     , ""       },
+        { 12, 16, 10, 14, "=====", "25"     },
+        { 12, 16, 10, 14, "=="   , ""       },
+        { 12, 16, 10, 14, "="    , ""       },
+        { 12, 16, 10, 14, ""     , ""       },
+        { 12, 14, 10, 16, "=====", "26"     },
+        { 12, 14, 10, 16, "=="   , ""       },
+        { 12, 14, 10, 16, "="    , ""       },
+        { 12, 14, 10, 16, ""     , ""       },
+/*
+        { , , , , "=====", "NN"     },
+        {  "=="   , ""       },
+        {  "="    , ""       },
+        {  ""     , ""       },
+*/
+    };
+    for ( i; sizeof(cases)/sizeof(cases[0]) ) {
+        sout | "------------------------------------------------------------------------" | cases[i].label;
+        string replaceIn = alphabetTemplate;
+        showOneReplacement( replaceIn, cases[i].ms, cases[i].me, cases[i].ws, cases[i].we, cases[i].replaceWith );
+    }
+}
+
+
+// void f( string & s, string & toEdit ) {
+
+//     sout | s | "|" | toEdit | "|";
+
+//     s(14, 16) = "-";
+//     sout | s | "|" | toEdit | "|";
+// }
+
+int main() {
+    //          0         1         2
+    //          01234567890123456789012345
+    string s = "abcdefghijklmnopqrstuvwxyz";
+
+    s(5,10) = "qqqqq";  // start=5, end=10, len=5
+
+    sout | s;
+
+
+    s(5,5) = "-----";  // start=5, end=5, len=0
+
+    sout | s;
+
+    runReplaceCases();
+}
Index: tests/concurrent/mutexstmt/.expect/locks.txt
===================================================================
--- tests/concurrent/mutexstmt/.expect/locks.txt	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
+++ tests/concurrent/mutexstmt/.expect/locks.txt	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -0,0 +1,4 @@
+Start Test: single lock mutual exclusion
+End Test: single lock mutual exclusion
+Start Test: multi lock deadlock/mutual exclusion
+End Test: multi lock deadlock/mutual exclusion
Index: tests/concurrent/mutexstmt/locks.cfa
===================================================================
--- tests/concurrent/mutexstmt/locks.cfa	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ tests/concurrent/mutexstmt/locks.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -1,8 +1,8 @@
-#include <mutex_stmt_locks.hfa>
+#include <mutex_stmt.hfa>
 #include <locks.hfa>
 
 const unsigned int num_times = 10000;
 
-owner_lock m1, m2, m3, m4, m5;
+single_acquisition_lock m1, m2, m3, m4, m5;
 
 thread T_Mutex {};
@@ -13,5 +13,5 @@
 	for (unsigned int i = 0; i < num_times; i++) {
 		mutex ( m1 ) count++;
-		mutex ( m1 ) {
+		mutex ( m1 ) { 
 			assert(!insideFlag);
 			insideFlag = true;
Index: tests/concurrent/mutexstmt/monitors.cfa
===================================================================
--- tests/concurrent/mutexstmt/monitors.cfa	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ tests/concurrent/mutexstmt/monitors.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -1,3 +1,4 @@
 #include <monitor.hfa>
+#include <mutex_stmt.hfa>
 #include <stdio.h>
 #include <stdlib.hfa>
@@ -13,4 +14,5 @@
 bool insideFlag = false;
 int count = 0;
+bool startFlag = false;
 
 void main( T_Mutex & this ) {
Index: tests/concurrent/semaphore.cfa
===================================================================
--- tests/concurrent/semaphore.cfa	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ tests/concurrent/semaphore.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -2,4 +2,5 @@
 #include <locks.hfa>
 #include <thread.hfa>
+#include <mutex_stmt.hfa>
 
 enum { num_blockers = 17, num_unblockers = 13 };
@@ -28,5 +29,5 @@
 		thrash();
 		P(ben);
-		if(((thread&)this).seqable.next != 0p) sout | acquire |"Link not invalidated";
+		if(((thread&)this).seqable.next != 0p) mutex(sout) sout | "Link not invalidated";
 		thrash();
 	}
Index: tests/concurrent/sleep.cfa
===================================================================
--- tests/concurrent/sleep.cfa	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ tests/concurrent/sleep.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -1,4 +1,5 @@
 #include <fstream.hfa>
 #include <thread.hfa>
+#include <mutex_stmt.hfa>
 #include <time.hfa>
 
@@ -29,5 +30,5 @@
 
 int main() {
-	sout | acquire | "start";
+	mutex( sout ) sout | "start";
 	{
 		slow_sleeper slow;
@@ -36,5 +37,5 @@
 		yield();
 	}
-	sout | acquire | "done";
+	mutex( sout ) sout | "done";
 }
 
Index: tests/exceptions/.expect/type-check.txt
===================================================================
--- tests/exceptions/.expect/type-check.txt	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ tests/exceptions/.expect/type-check.txt	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -1,4 +1,4 @@
-exceptions/type-check.cfa:8:1 error: catch must have pointer to an exception type
-exceptions/type-check.cfa:9:1 error: catch must have pointer to an exception type
-exceptions/type-check.cfa:10:1 error: catchResume must have pointer to an exception type
-exceptions/type-check.cfa:11:1 error: catchResume must have pointer to an exception type
+exceptions/type-check.cfa:6:1 error: catch must have pointer to an exception type
+exceptions/type-check.cfa:7:1 error: catch must have pointer to an exception type
+exceptions/type-check.cfa:8:1 error: catchResume must have pointer to an exception type
+exceptions/type-check.cfa:9:1 error: catchResume must have pointer to an exception type
Index: tests/exceptions/cancel/coroutine.cfa
===================================================================
--- tests/exceptions/cancel/coroutine.cfa	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ tests/exceptions/cancel/coroutine.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -2,8 +2,7 @@
 
 #include <coroutine.hfa>
-#include <exception.hfa>
 
-EHM_EXCEPTION(internal_error)();
-EHM_VIRTUAL_TABLE(internal_error, internal_vt);
+exception internal_error {};
+vtable(internal_error) internal_vt;
 
 coroutine WillCancel {};
Index: tests/exceptions/cancel/thread.cfa
===================================================================
--- tests/exceptions/cancel/thread.cfa	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ tests/exceptions/cancel/thread.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -2,8 +2,7 @@
 
 #include <thread.hfa>
-#include <exception.hfa>
 
-EHM_EXCEPTION(internal_error)();
-EHM_VIRTUAL_TABLE(internal_error, internal_vt);
+exception internal_error {};
+vtable(internal_error) internal_vt;
 
 thread WillCancel {};
Index: tests/exceptions/conditional.cfa
===================================================================
--- tests/exceptions/conditional.cfa	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ tests/exceptions/conditional.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -4,11 +4,9 @@
 // up the non-trivial exception is reasonable to do.
 
-#include <exception.hfa>
+exception num_error {
+	int num;
+};
 
-EHM_EXCEPTION(num_error)(
-	int num;
-);
-
-EHM_VIRTUAL_TABLE(num_error, num_error_vt);
+vtable(num_error) num_error_vt;
 
 void caught_num_error(int expect, num_error * actual) {
Index: tests/exceptions/data-except.cfa
===================================================================
--- tests/exceptions/data-except.cfa	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ tests/exceptions/data-except.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -1,12 +1,10 @@
 // Test exceptions that add data but no functionality.
 
-#include <exception.hfa>
-
-EHM_EXCEPTION(paired)(
+exception paired {
 	int first;
 	int second;
-);
+};
 
-EHM_VIRTUAL_TABLE(paired, paired_vt);
+vtable(paired) paired_vt;
 
 const char * virtual_msg(paired * this) {
Index: tests/exceptions/defaults.cfa
===================================================================
--- tests/exceptions/defaults.cfa	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ tests/exceptions/defaults.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -4,7 +4,7 @@
 #include <exception.hfa>
 
-EHM_EXCEPTION(log_message)(
+exception log_message {
 	char * msg;
-);
+};
 
 _EHM_DEFINE_COPY(log_message, )
@@ -32,10 +32,10 @@
 
 // I don't have a good use case for doing the same with termination.
-EHM_EXCEPTION(jump)();
+exception jump {};
 void defaultTerminationHandler(jump &) {
 	printf("jump default handler.\n");
 }
 
-EHM_VIRTUAL_TABLE(jump, jump_vt);
+vtable(jump) jump_vt;
 
 void jump_test(void) {
@@ -48,9 +48,9 @@
 }
 
-EHM_EXCEPTION(first)();
-EHM_VIRTUAL_TABLE(first, first_vt);
+exception first {};
+vtable(first) first_vt;
 
-EHM_EXCEPTION(unhandled_exception)();
-EHM_VIRTUAL_TABLE(unhandled_exception, unhandled_vt);
+exception unhandled_exception {};
+vtable(unhandled_exception) unhandled_vt;
 
 void unhandled_test(void) {
@@ -69,6 +69,6 @@
 }
 
-EHM_EXCEPTION(second)();
-EHM_VIRTUAL_TABLE(second, second_vt);
+exception second {};
+vtable(second) second_vt;
 
 void cross_test(void) {
Index: tests/exceptions/finally.cfa
===================================================================
--- tests/exceptions/finally.cfa	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ tests/exceptions/finally.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -1,10 +1,9 @@
 // Finally Clause Tests
 
-#include <exception.hfa>
 #include "except-io.hfa"
 
-EHM_EXCEPTION(myth)();
+exception myth {};
 
-EHM_VIRTUAL_TABLE(myth, myth_vt);
+vtable(myth) myth_vt;
 
 int main(int argc, char * argv[]) {
Index: tests/exceptions/interact.cfa
===================================================================
--- tests/exceptions/interact.cfa	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ tests/exceptions/interact.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -1,12 +1,11 @@
 // Testing Interactions Between Termination and Resumption
 
-#include <exception.hfa>
 #include "except-io.hfa"
 
-EHM_EXCEPTION(star)();
-EHM_EXCEPTION(moon)();
+exception star {};
+exception moon {};
 
-EHM_VIRTUAL_TABLE(star, star_vt);
-EHM_VIRTUAL_TABLE(moon, moon_vt);
+vtable(star) star_vt;
+vtable(moon) moon_vt;
 
 int main(int argc, char * argv[]) {
Index: tests/exceptions/polymorphic.cfa
===================================================================
--- tests/exceptions/polymorphic.cfa	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ tests/exceptions/polymorphic.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -1,10 +1,8 @@
 // Testing polymophic exception types.
 
-#include <exception.hfa>
+forall(T &) exception proxy {};
 
-EHM_FORALL_EXCEPTION(proxy, (T&), (T))();
-
-EHM_FORALL_VIRTUAL_TABLE(proxy, (int), proxy_int);
-EHM_FORALL_VIRTUAL_TABLE(proxy, (char), proxy_char);
+vtable(proxy(int)) proxy_int;
+vtable(proxy(char)) proxy_char;
 
 void proxy_test(void) {
@@ -33,11 +31,11 @@
 }
 
-EHM_FORALL_EXCEPTION(cell, (T), (T))(
+forall(T) exception cell {
 	T data;
-);
+};
 
-EHM_FORALL_VIRTUAL_TABLE(cell, (int), int_cell);
-EHM_FORALL_VIRTUAL_TABLE(cell, (char), char_cell);
-EHM_FORALL_VIRTUAL_TABLE(cell, (bool), bool_cell);
+vtable(cell(int)) int_cell;
+vtable(cell(char)) char_cell;
+vtable(cell(bool)) bool_cell;
 
 void cell_test(void) {
Index: tests/exceptions/resume.cfa
===================================================================
--- tests/exceptions/resume.cfa	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ tests/exceptions/resume.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -1,14 +1,13 @@
 // Resumption Exception Tests
 
-#include <exception.hfa>
 #include "except-io.hfa"
 
-EHM_EXCEPTION(yin)();
-EHM_EXCEPTION(yang)();
-EHM_EXCEPTION(zen)();
+exception yin {};
+exception yang {};
+exception zen {};
 
-EHM_VIRTUAL_TABLE(yin, yin_vt);
-EHM_VIRTUAL_TABLE(yang, yang_vt);
-EHM_VIRTUAL_TABLE(zen, zen_vt);
+vtable(yin) yin_vt;
+vtable(yang) yang_vt;
+vtable(zen) zen_vt;
 
 void in_void(void);
Index: tests/exceptions/terminate.cfa
===================================================================
--- tests/exceptions/terminate.cfa	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ tests/exceptions/terminate.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -1,14 +1,13 @@
 // Termination Exception Tests
 
-#include <exception.hfa>
 #include "except-io.hfa"
 
-EHM_EXCEPTION(yin)();
-EHM_EXCEPTION(yang)();
-EHM_EXCEPTION(zen)();
+exception yin {};
+exception yang {};
+exception zen {};
 
-EHM_VIRTUAL_TABLE(yin, yin_vt);
-EHM_VIRTUAL_TABLE(yang, yang_vt);
-EHM_VIRTUAL_TABLE(zen, zen_vt);
+vtable(yin) yin_vt;
+vtable(yang) yang_vt;
+vtable(zen) zen_vt;
 
 void in_void(void);
Index: tests/exceptions/trash.cfa
===================================================================
--- tests/exceptions/trash.cfa	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ tests/exceptions/trash.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -1,11 +1,9 @@
 // Make sure throw-catch during unwind does not trash internal data.
 
-#include <exception.hfa>
+exception yin {};
+exception yang {};
 
-EHM_EXCEPTION(yin)();
-EHM_EXCEPTION(yang)();
-
-EHM_VIRTUAL_TABLE(yin, yin_vt);
-EHM_VIRTUAL_TABLE(yang, yang_vt);
+vtable(yin) yin_vt;
+vtable(yang) yang_vt;
 
 int main(int argc, char * argv[]) {
Index: tests/exceptions/type-check.cfa
===================================================================
--- tests/exceptions/type-check.cfa	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ tests/exceptions/type-check.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -1,7 +1,5 @@
 // Check that the exception type check works.
 
-#include <exception.hfa>
-
-EHM_EXCEPTION(truth)();
+exception truth {};
 
 int main(int argc, char * argv[]) {
Index: tests/io/io-acquire.cfa
===================================================================
--- tests/io/io-acquire.cfa	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ tests/io/io-acquire.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -10,10 +10,11 @@
 // Created On       : Mon Mar  1 18:40:09 2021
 // Last Modified By : Peter A. Buhr
-// Last Modified On : Tue Apr 27 11:49:34 2021
-// Update Count     : 18
+// Last Modified On : Wed Oct  6 18:04:58 2021
+// Update Count     : 72
 // 
 
 #include <fstream.hfa>
 #include <thread.hfa>
+#include <mutex_stmt.hfa>
 
 thread T {};
@@ -21,9 +22,8 @@
 	// output from parallel threads should not be scrambled
 
-	for ( 100 ) {										// local protection
-		sout | acquire | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
+	for ( 100 ) {										// expression protection
+		mutex(sout) sout | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
 	}
-	{													// global protection (RAII)
-		osacquire acq = { sout };
+	mutex( sout ) {										// statement protection
 		for ( 100 ) {
 			sout | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
@@ -31,9 +31,17 @@
 	}
 	{													// duplicate protection demonstrating recursive lock
-		osacquire acq = { sout };
-		for ( 100 ) {
-			osacquire acq = { sout };
-			sout | acquire | 1 | 2 | 3 | 4 | 5 | acquire | 6 | 7 | 8 | 9;
-			sout | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
+		ofstream & h1( ofstream & os ) {				// helper
+			mutex( os ) return os | 1 | 2 | 3 | 4;		// unnecessary mutex
+		}
+		ofstream & h2( ofstream & os ) {				// helper
+			mutex( os ) return os | 6 | 7 | 8 | 9;		// unnecessary mutex
+		}
+		mutex( sout ) {									// unnecessary mutex
+			for ( 100 ) {
+				mutex( sout ) {
+					sout | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
+					sout | h1 | 5 | h2;					// refactored code
+				}
+			}
 		}
 	}
@@ -42,9 +50,8 @@
 
 	int a, b, c, d, e, f, g, h, i;
-	for ( 100 ) {										// local protection
-		sin | acquire | a | b | c | d | e | f | g | h | i;
+	for ( 100 ) {										// expression protection
+		mutex(sin) sin | a | b | c | d | e | f | g | h | i;
 	}
-	{													// global protection (RAII)
-		isacquire acq = { sin };
+	mutex( sin ) {										// statement protection
 		for ( 100 ) {
 			sin  | a | b | c | d | e | f | g | h | i;
@@ -52,9 +59,17 @@
 	}
 	{													// duplicate protection demonstrating recursive lock
-		isacquire acq = { sin };
-		for ( 100 ) {
-			isacquire acq = { sin };
-			sin | acquire | a | b | c | d | e | acquire | f | g | h | i;
-			sin | a | b | c | d | e | f | g | h | i;
+		ifstream & h1( ifstream & is ) {				// helper
+			mutex( is ) return is | a | b | c | d;		// unnecessary mutex
+		}
+		ifstream & h2( ifstream & is ) {				// helper
+			mutex( is ) return is | f | g | h | i;		// unnecessary mutex
+		}
+		mutex( sin ) {									// unnecessary mutex
+			for ( 5 ) {
+				mutex( sin ) {
+					sin  | a | b | c | d | e | f | g | h | i;
+					sin  | h1 | e | h2;					// refactored code
+				}
+			}
 		}
 	}
Index: tests/linking/io-acquire.cfa
===================================================================
--- tests/linking/io-acquire.cfa	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ tests/linking/io-acquire.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -17,12 +17,13 @@
 #include <fstream.hfa>
 #include <stdlib.hfa>
+#include <mutex_stmt.hfa>
 
 int main() {
 	int i;
 	if(threading_enabled()) {
-		stdout | acquire | "YES";
+		mutex( stdout ) stdout | "YES";
 		stdin | i;
 	} else {
-		stdout | acquire | "NO";
+		mutex( stdout ) stdout | "NO";
 		stdin | i;
 	}
Index: tests/parseconfig.cfa
===================================================================
--- tests/parseconfig.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
+++ tests/parseconfig.cfa	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -0,0 +1,146 @@
+#include <fstream.hfa>
+#include <parseconfig.hfa>
+#include <stdlib.hfa>
+
+extern "C" {
+	extern long long int strtoll( const char* str, char** endptr, int base );
+}
+
+#define xstr(s) str(s)
+#define str(s) #s
+
+bool custom_parse( const char * arg, int & value ) {
+	char * end;
+	int r = strtoll( arg, &end, 10 );
+  if ( *end != '\0' ) return false;
+
+	value = r + 99;
+	return true;
+}
+
+int main() {
+	struct {
+        int stop_cost;
+        int num_students;
+        int num_stops;
+        int max_num_students;
+        int timer_delay;
+        int groupoff_delay;
+    } config_params;
+    int conductor_delay;
+    [2] int parental_delay_and_num_couriers;
+    [ int, int ] max_student_delay_and_trips;
+
+	const size_t NUM_ENTRIES = 11;
+	config_entry entries[NUM_ENTRIES] = {
+		{ "StopCost", config_params.stop_cost },
+        { "NumStudents", config_params.num_students },
+        { "NumStops", config_params.num_stops },
+        { "MaxNumStudents", config_params.max_num_students },
+        { "TimerDelay", config_params.timer_delay },
+        { "GroupoffDelay", config_params.groupoff_delay },
+        { "ConductorDelay", conductor_delay },
+        { "ParentalDelay", parental_delay_and_num_couriers[0] },
+        { "NumCouriers", parental_delay_and_num_couriers[1] },
+        { "MaxStudentDelay", max_student_delay_and_trips.0 },
+        { "MaxStudentTrips", max_student_delay_and_trips.1 }
+    };
+
+
+	sout | "Different types of destination addresses";
+
+	parse_config( xstr(IN_DIR) "parseconfig-all.txt", entries, NUM_ENTRIES, parse_tabular_config_format );
+
+    sout | "Stop cost: " | config_params.stop_cost;
+    sout | "Number of students: " | config_params.num_students;
+    sout | "Number of stops: " | config_params.num_stops;
+    sout | "Maximum number of students: " | config_params.max_num_students;
+    sout | "Timer delay: " | config_params.timer_delay;
+    sout | "Groupoff delay: " | config_params.groupoff_delay;
+    sout | "Conductor delay: " | conductor_delay;
+    sout | "Parental delay: " | parental_delay_and_num_couriers[0];
+    sout | "Number of couriers: " | parental_delay_and_num_couriers[1];
+    sout | "Maximum student delay: " | max_student_delay_and_trips.0;
+    sout | "Maximum student trips: " | max_student_delay_and_trips.1;
+	sout | nl;
+
+
+	sout | "Open_Failure thrown when config file does not exist";
+	try {
+		parse_config( xstr(IN_DIR) "doesnt-exist.txt", entries, NUM_ENTRIES, parse_tabular_config_format );
+	} catch( Open_Failure * ex ) {
+		sout | "Failed to open the config file";
+	}
+	sout | nl;
+
+
+	sout | "Missing_Config_Entries thrown when config file is missing entries we want";
+	try {
+		parse_config( xstr(IN_DIR) "parseconfig-missing.txt", entries, NUM_ENTRIES, parse_tabular_config_format );
+	} catch( Missing_Config_Entries * ex ) {
+		msg( ex );
+	}
+	sout | nl;
+
+
+	sout | "Parse_Failure thrown when an entry cannot be parsed";
+
+	int non_int_val;
+	config_entry entry[1] = {
+		{ "AnothaOne", non_int_val }
+	};
+
+	try {
+		parse_config( xstr(IN_DIR) "parseconfig-errors.txt", entry, 1, parse_tabular_config_format );
+	} catch( Parse_Failure * ex ) {
+		msg( ex );
+	}
+	sout | nl;
+
+
+	sout | "Validation_Failure thrown when an entry fails validation";
+
+	// TODO: Fix compiler bug that makes casting necessary
+	config_entry new_entry1 = { "StopCost", config_params.stop_cost, (bool (*)(int &))is_positive };
+	entries[0] = new_entry1;
+
+	try {
+		parse_config( xstr(IN_DIR) "parseconfig-errors.txt", entries, NUM_ENTRIES, parse_tabular_config_format );
+	} catch( Validation_Failure * ex ) {
+		msg( ex );
+	}
+	sout | nl;
+
+
+	sout | "No error is thrown when validation succeeds";
+	config_params.stop_cost = -1; // Reset value
+	parse_config( xstr(IN_DIR) "parseconfig-all.txt", entries, NUM_ENTRIES, parse_tabular_config_format );
+	sout | "Stop cost: " | config_params.stop_cost;
+	sout | nl;
+
+
+	sout | "A custom parse function can be accepted";
+
+	config_entry new_entry2 = { "StopCost", config_params.stop_cost, custom_parse };
+	entries[0] = new_entry2;
+
+	config_params.stop_cost = -1; // Reset value
+	parse_config( xstr(IN_DIR) "parseconfig-all.txt", entries, NUM_ENTRIES, parse_tabular_config_format );
+
+	sout | "Stop cost: " | config_params.stop_cost;
+	sout | nl;
+
+
+	sout | "Custom parse and validation functions can be provided together";
+
+	// TODO: Fix compiler bug that makes casting necessary
+	config_entry new_entry3 = { "StopCost", config_params.stop_cost, custom_parse, (bool (*)(int &))is_positive };
+	entries[0] = new_entry3;
+
+	config_params.stop_cost = -1; // Reset value
+	parse_config( xstr(IN_DIR) "parseconfig-all.txt", entries, NUM_ENTRIES, parse_tabular_config_format );
+
+	sout | "Stop cost: " | config_params.stop_cost;
+
+	exit( EXIT_SUCCESS );  // This is to avoid memory leak messages from the above exceptions
+}
Index: tests/pybin/test_run.py
===================================================================
--- tests/pybin/test_run.py	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ tests/pybin/test_run.py	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -65,12 +65,12 @@
 	def toString( cls, retcode, duration ):
 		if settings.generating :
-			if   retcode == TestResult.SUCCESS: 	text = "Done   "
-			elif retcode == TestResult.TIMEOUT: 	text = "TIMEOUT"
-			else :						text = "ERROR code %d" % retcode
+			if   retcode == TestResult.SUCCESS: 	key = 'pass'; text = "Done   "
+			elif retcode == TestResult.TIMEOUT: 	key = 'time'; text = "TIMEOUT"
+			else :	key = 'fail';	text = "ERROR code %d" % retcode
 		else :
-			if   retcode == TestResult.SUCCESS: 	text = "PASSED "
-			elif retcode == TestResult.TIMEOUT: 	text = "TIMEOUT"
-			else :						text = "FAILED with code %d" % retcode
+			if   retcode == TestResult.SUCCESS: 	key = 'pass'; text = "PASSED "
+			elif retcode == TestResult.TIMEOUT: 	key = 'time'; text = "TIMEOUT"
+			else :	key = 'fail';	text = "FAILED with code %d" % retcode
 
 		text += "    C%s - R%s" % (fmtDur(duration[0]), fmtDur(duration[1]))
-		return text
+		return key, text
Index: tests/test.py
===================================================================
--- tests/test.py	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ tests/test.py	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -257,5 +257,5 @@
 
 		# update output based on current action
-		result_txt = TestResult.toString( retcode, duration )
+		result_key, result_txt = TestResult.toString( retcode, duration )
 
 		#print result with error if needed
@@ -265,7 +265,7 @@
 			text = text + '\n' + error
 
-		return retcode == TestResult.SUCCESS, text
+		return retcode == TestResult.SUCCESS, result_key, text
 	except KeyboardInterrupt:
-		return False, ""
+		return False, 'keybrd', ""
 	# except Exception as ex:
 	# 	print("Unexpected error in worker thread running {}: {}".format(t.target(), ex), file=sys.stderr)
@@ -283,4 +283,6 @@
 
 	failed = False
+	rescnts = {	'pass': 0, 'fail': 0, 'time': 0, 'keybrd': 0 }
+	other = 0
 
 	# for each test to run
@@ -294,5 +296,10 @@
 		)
 
-		for i, (succ, txt) in enumerate(timed(results, timeout = settings.timeout.total), 1) :
+		for i, (succ, code, txt) in enumerate(timed(results, timeout = settings.timeout.total), 1) :
+			if code in rescnts.keys():
+				rescnts[code] += 1
+			else:
+				other += 1
+
 			if not succ :
 				failed = True
@@ -319,4 +326,6 @@
 	# clean the workspace
 	make('clean', output_file=subprocess.DEVNULL, error=subprocess.DEVNULL)
+
+	print("{} passes, {} failures, {} timeouts, {} cancelled, {} other".format(rescnts['pass'], rescnts['fail'], rescnts['time'], rescnts['keybrd'], other))
 
 	return failed
@@ -443,5 +452,4 @@
 			failed = run_tests(local_tests, options.jobs)
 			if failed:
-				result = 1
 				if not settings.continue_:
 					break
Index: tools/perf/png.py
===================================================================
--- tools/perf/png.py	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
+++ tools/perf/png.py	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -0,0 +1,123 @@
+#!/usr/bin/python3
+
+import argparse, json, math, sys, time
+import multiprocessing
+from PIL import Image
+import numpy as np
+
+class Timed:
+	def __init__(self, text):
+		print(text, end='', flush=True)
+
+	def pretty(self, durr):
+		seconds = int(durr)
+		days, seconds = divmod(seconds, 86400)
+		hours, seconds = divmod(seconds, 3600)
+		minutes, seconds = divmod(seconds, 60)
+		if days > 0:
+			return '%dd%dh%dm%ds' % (days, hours, minutes, seconds)
+		elif hours > 0:
+			return '%dh%dm%ds' % (hours, minutes, seconds)
+		elif minutes > 0:
+			return '%dm%ds' % (minutes, seconds)
+		else:
+			return '%ds' % (seconds,)
+
+	def __enter__(self):
+		self.start = time.time()
+		return self
+
+	def __exit__(self, *args):
+		self.end = time.time()
+		print(self.pretty(self.end - self.start))
+
+
+
+parser = argparse.ArgumentParser()
+parser.add_argument('--infile', type=argparse.FileType('r'), default=sys.stdin)
+parser.add_argument('--outfile', type=str, default='out.png')
+
+args = parser.parse_args()
+
+pool = multiprocessing.Pool()
+
+with Timed("Loading json..."):
+	obj = json.load(args.infile)
+
+min_tsc = int(obj['min-tsc'])
+max_tsc = int(obj['max-tsc'])
+
+def tsc_to_s(tsc):
+	return float(tsc - min_tsc)  / 2500000000.0
+
+max_sec = tsc_to_s(max_tsc)
+print([min_tsc, max_tsc, max_sec])
+
+min_cpu = int(obj['min-cpu'])
+max_cpu = int(obj['max-cpu'])
+cnt_cpu = max_cpu - min_cpu + 1
+nbins = math.ceil(max_sec * 10)
+
+class Bar:
+	def __init__(self):
+		pass
+
+with Timed("Creating bins..."):
+	bins = []
+	for _ in range(0, int(nbins)):
+		bar = Bar()
+		bins.append([bar, *[*([0] * cnt_cpu), bar] * cnt_cpu])
+		# bins.append([0] * cnt_cpu)
+
+	bins = np.array(bins)
+
+
+
+def flatten(val):
+	secs = tsc_to_s(val[1])
+	ratio = secs / max_sec
+	b = int(ratio * (nbins - 1))
+	## from/to
+	from_ = val[2] - min_cpu
+	to_   = val[3] - min_cpu
+	idx = int(1 + ((cnt_cpu + 1) * to_) + from_)
+	return [b, idx, 1]
+	## val per cpu
+	# cnt = val[2]
+	# idx = val[3] - min_cpu
+	# # idx = from_
+	# return [b, idx, cnt]
+
+
+with Timed("Compressing data..."):
+	compress = map(flatten, obj['values'])
+
+highest  = 1
+with Timed("Grouping data..."):
+	for x in compress:
+		bins[x[0]][x[1]] += x[2]
+		highest = max(highest, bins[x[0]][x[1]])
+
+print(highest)
+# highest  = 10000000000
+
+with Timed("Normalizing data..."):
+	def normalize(v):
+		if type(v) is Bar:
+			return np.uint32(0xff008000)
+		v = v * 255 / float(highest)
+		if v > 256:
+			v = 255
+		u8 = np.uint8(v)
+		u32 = np.uint32(u8)
+
+		return (0xff << 24) | (u32 << 16) | (u32 << 8) | (u32 << 0)
+	normalizef = np.vectorize(normalize, [np.uint32])
+
+	bins = normalizef(bins)
+
+print(bins.shape)
+with Timed("Saving image..."):
+	im = Image.fromarray(bins, mode='RGBA')
+	im.show()
+	im.save(args.outfile)
Index: tools/perf/process_stat_array.py
===================================================================
--- tools/perf/process_stat_array.py	(revision f95634ee1f70e0dd4ea661aa832925cf8415519a)
+++ tools/perf/process_stat_array.py	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -1,5 +1,7 @@
 #!/usr/bin/python3
 
-import argparse, os, sys, re
+import argparse, json, math, os, sys, re
+from PIL import Image
+import numpy as np
 
 def dir_path(string):
@@ -11,4 +13,5 @@
 parser = argparse.ArgumentParser()
 parser.add_argument('--path', type=dir_path, default=".cfadata", help= 'paste path to biog.txt file')
+parser.add_argument('--out', type=argparse.FileType('w'), default=sys.stdout)
 
 try :
@@ -23,4 +26,9 @@
 counters = {}
 
+max_cpu = 0
+min_cpu = 1000000
+max_tsc = 0
+min_tsc = 18446744073709551615
+
 #open the files
 for filename in filenames:
@@ -31,12 +39,31 @@
 		with open(os.path.join(root, filename), 'r') as file:
 			for line in file:
-				# data = [int(x.strip()) for x in line.split(',')]
-				data = [int(line.strip())]
-				data = [me, *data]
+				raw = [int(x.strip()) for x in line.split(',')]
+
+				## from/to
+				high = (raw[1] >> 32)
+				low  = (raw[1] & 0xffffffff)
+				data = [me, raw[0], high, low]
+				max_cpu = max(max_cpu, high, low)
+				min_cpu = min(min_cpu, high, low)
+
+				## number
+				# high = (raw[1] >> 8)
+				# low  = (raw[1] & 0xff)
+				# data = [me, raw[0], high, low]
+				# max_cpu = max(max_cpu, low)
+				# min_cpu = min(min_cpu, low)
+
+
+				max_tsc = max(max_tsc, raw[0])
+				min_tsc = min(min_tsc, raw[0])
 				merged.append(data)
 
-	except:
+	except Exception as e:
+		print(e)
 		pass
 
+
+print({"max-cpu": max_cpu, "min-cpu": min_cpu, "max-tsc": max_tsc, "min-tsc": min_tsc})
 
 # Sort by timestamp (the second element)
@@ -47,25 +74,71 @@
 merged.sort(key=takeSecond)
 
-# for m in merged:
-# 	print(m)
+json.dump({"values":merged, "max-cpu": max_cpu, "min-cpu": min_cpu, "max-tsc": max_tsc, "min-tsc": min_tsc}, args.out)
 
-single = []
-curr = 0
+# vmin = merged[ 0][1]
+# vmax = float(merged[-1][1] - vmin) / 2500000000.0
+# # print(vmax)
 
-# merge the data
-# for (me, time, value) in merged:
-for (me, value) in merged:
-	# check now much this changes
-	old = counters[me]
-	change = value - old
-	counters[me] = value
+# bins = []
+# for _ in range(0, int(math.ceil(vmax * 10))):
+# 	bins.append([0] * (32 * 32))
 
-	# add change to the current
-	curr = curr + change
-	single.append( value )
+# # print(len(bins))
+# bins = np.array(bins)
 
-	pass
+# rejected = 0
+# highest  = 0
 
-print(single)
+# for x in merged:
+# 	b = int(float(x[1] - vmin) / 250000000.0)
+# 	from_ = x[2]
+# 	if from_ < 0 or from_ > 32:
+# 		rejected += 1
+# 		continue;
+# 	to_   = x[3]
+# 	if to_ < 0 or to_ > 32:
+# 		rejected += 1
+# 		continue;
+# 	idx = (to_ * 32) + from_
+# 	bins[b][idx] = bins[b][idx] + 1
+# 	highest = max(highest, bins[b][idx])
+
+# bins = np.array(map(lambda x: np.int8(x * 255.0 / float(highest)), bins))
+
+# print([highest, rejected])
+# print(bins.shape)
+
+# im = Image.fromarray(bins)
+# im.save('test.png')
+
+# vmax = merged[-1][1]
+
+# diff = float(vmax - vmin) / 2500000000.0
+# print([vmin, vmax])
+# print([vmax - vmin, diff])
+
+# print(len(merged))
+
+# for b in bins:
+# 	print(b)
+
+# single = []
+# curr = 0
+
+# # merge the data
+# # for (me, time, value) in merged:
+# for (me, value) in merged:
+# 	# check now much this changes
+# 	old = counters[me]
+# 	change = value - old
+# 	counters[me] = value
+
+# 	# add change to the current
+# 	curr = curr + change
+# 	single.append( value )
+
+# 	pass
+
+# print(single)
 
 # single = sorted(single)[:len(single)-100]
Index: tools/perf/sample.py
===================================================================
--- tools/perf/sample.py	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
+++ tools/perf/sample.py	(revision b7fd9daffd1af20c4c7cc80ac4660136917af20f)
@@ -0,0 +1,29 @@
+#!/usr/bin/python3
+
+import argparse, json, random, sys
+
+parser = argparse.ArgumentParser()
+parser.add_argument('--infile', type=argparse.FileType('r'), default=sys.stdin)
+parser.add_argument('--outfile', type=argparse.FileType('w'), default=sys.stdout)
+
+args = parser.parse_args()
+
+data = json.load(args.infile)
+
+
+
+print(len(data['values']))
+print(int(len(data['values']) / 1000))
+
+sample = random.sample(data['values'], int(len(data['values']) / 1000))
+print(len(sample))
+
+# Sort by timestamp (the second element)
+# take second element for sort
+def takeSecond(elem):
+    return elem[1]
+
+sample.sort(key=takeSecond)
+
+data['values'] = sample
+json.dump(data, args.outfile)
