Index: c/theses/andrew_beach_MMath/callreturn.fig
===================================================================
--- doc/theses/andrew_beach_MMath/callreturn.fig	(revision 0640189e9e66678dab5d7f80793687fa10ff24c3)
+++ 	(revision )
@@ -1,33 +1,0 @@
-#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 0 1 0 2097.794 1947.794 2025 1350 2700 1950 2100 2550
-	1 1 1.00 45.00 90.00
-5 1 0 1 0 7 100 0 -1 0.000 0 0 1 0 1862.500 1650.000 1950 1350 2175 1650 1950 1950
-	1 1 1.00 45.00 90.00
-5 1 0 1 0 7 100 0 -1 0.000 0 0 1 0 1862.500 2250.000 1950 1950 2175 2250 1950 2550
-	1 1 1.00 45.00 90.00
-6 825 1275 1275 2700
-2 1 0 1 0 7 100 0 -1 4.000 0 0 -1 1 0 2
-	1 1 1.00 45.00 90.00
-	 1050 2700 1050 1500
-4 1 0 100 0 0 12 0.0000 2 135 420 1050 1425 stack\001
--6
-2 1 0 1 0 7 100 0 -1 0.000 0 0 -1 1 0 2
-	1 1 1.00 45.00 90.00
-	 1800 2475 1800 2100
-2 1 0 1 0 7 100 0 -1 0.000 0 0 -1 1 0 2
-	1 1 1.00 45.00 90.00
-	 1800 1875 1800 1500
-4 1 0 100 0 5 12 0.0000 2 120 120 1800 2025 g\001
-4 1 0 100 0 5 12 0.0000 2 120 120 1800 2700 h\001
-4 1 0 100 0 5 12 0.0000 2 120 120 1800 1425 f\001
-4 2 0 100 0 0 12 0.0000 2 135 300 1650 2025 call\001
-4 0 0 100 0 0 12 0.0000 2 135 465 2775 2025 throw\001
-4 0 0 100 0 0 12 0.0000 2 120 480 2100 2025 return\001
Index: doc/theses/andrew_beach_MMath/code/ThrowFinally.java
===================================================================
--- doc/theses/andrew_beach_MMath/code/ThrowFinally.java	(revision 0640189e9e66678dab5d7f80793687fa10ff24c3)
+++ doc/theses/andrew_beach_MMath/code/ThrowFinally.java	(revision 5541ea3d192c866061ad89a360daabc4e33e3429)
@@ -7,5 +7,9 @@
 			throws EmptyException {
 		if (0 < frames) {
-			unwind_finally(frames - 1);
+			try {
+				unwind_finally(frames - 1);
+			} finally {
+				// ...
+			}
 		} else {
 			throw new EmptyException();
Index: doc/theses/andrew_beach_MMath/code/ThrowOther.java
===================================================================
--- doc/theses/andrew_beach_MMath/code/ThrowOther.java	(revision 0640189e9e66678dab5d7f80793687fa10ff24c3)
+++ doc/theses/andrew_beach_MMath/code/ThrowOther.java	(revision 5541ea3d192c866061ad89a360daabc4e33e3429)
@@ -16,8 +16,7 @@
 				// ...
 			}
+		} else if (should_throw) {
+			throw new NotRaisedException();
 		} else {
-			if (should_throw) {
-				throw new NotRaisedException();
-			}
 			throw new EmptyException();
 		}
Index: doc/theses/andrew_beach_MMath/code/cond-catch.cfa
===================================================================
--- doc/theses/andrew_beach_MMath/code/cond-catch.cfa	(revision 0640189e9e66678dab5d7f80793687fa10ff24c3)
+++ doc/theses/andrew_beach_MMath/code/cond-catch.cfa	(revision 5541ea3d192c866061ad89a360daabc4e33e3429)
@@ -19,5 +19,5 @@
 		throw_exception();
 	} catch (empty_exception * exc ; should_catch) {
-		// ...
+		asm volatile ("# catch block (conditional)");
 	}
 }
@@ -37,5 +37,5 @@
 			cond_catch();
 		} catch (empty_exception * exc) {
-			// ...
+			asm volatile ("# catch block (unconditional)");
 		}
 	}
Index: doc/theses/andrew_beach_MMath/code/cond-catch.cpp
===================================================================
--- doc/theses/andrew_beach_MMath/code/cond-catch.cpp	(revision 0640189e9e66678dab5d7f80793687fa10ff24c3)
+++ doc/theses/andrew_beach_MMath/code/cond-catch.cpp	(revision 5541ea3d192c866061ad89a360daabc4e33e3429)
@@ -22,4 +22,5 @@
 			throw;
 		}
+		asm volatile ("# catch block (conditional)");
 	}
 }
@@ -39,5 +40,5 @@
 			cond_catch();
 		} catch (EmptyException &) {
-			// ...
+			asm volatile ("# catch block (unconditional)");
 		}
     }
Index: doc/theses/andrew_beach_MMath/code/cond-fixup.cfa
===================================================================
--- doc/theses/andrew_beach_MMath/code/cond-fixup.cfa	(revision 0640189e9e66678dab5d7f80793687fa10ff24c3)
+++ doc/theses/andrew_beach_MMath/code/cond-fixup.cfa	(revision 5541ea3d192c866061ad89a360daabc4e33e3429)
@@ -12,5 +12,5 @@
 
 void throw_exception() {
-	throw (empty_exception){&empty_vt};
+	throwResume (empty_exception){&empty_vt};
 }
 
@@ -18,6 +18,6 @@
 	try {
 		throw_exception();
-	} catch (empty_exception * exc ; should_catch) {
-		// ...
+	} catchResume (empty_exception * exc ; should_catch) {
+		asm volatile ("# fixup block (conditional)");
 	}
 }
@@ -36,6 +36,6 @@
 		try {
 			cond_catch();
-		} catch (empty_exception * exc) {
-			// ...
+		} catchResume (empty_exception * exc) {
+			asm volatile ("# fixup block (unconditional)");
 		}
 	}
Index: doc/theses/andrew_beach_MMath/code/cross-catch.cfa
===================================================================
--- doc/theses/andrew_beach_MMath/code/cross-catch.cfa	(revision 0640189e9e66678dab5d7f80793687fa10ff24c3)
+++ doc/theses/andrew_beach_MMath/code/cross-catch.cfa	(revision 5541ea3d192c866061ad89a360daabc4e33e3429)
@@ -7,12 +7,11 @@
 EHM_EXCEPTION(not_raised_exception)();
 
+EHM_VIRTUAL_TABLE(not_raised_exception, not_vt);
+
 int main(int argc, char * argv[]) {
 	unsigned int times = 1;
-	unsigned int total_frames = 1;
+	volatile bool should_throw = false;
 	if (1 < argc) {
 		times = strtol(argv[1], 0p, 10);
-	}
-	if (2 < argc) {
-		total_frames = strtol(argv[2], 0p, 10);
 	}
 
@@ -20,7 +19,10 @@
 	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");
 		}
 	}
Index: doc/theses/andrew_beach_MMath/code/cross-catch.cpp
===================================================================
--- doc/theses/andrew_beach_MMath/code/cross-catch.cpp	(revision 0640189e9e66678dab5d7f80793687fa10ff24c3)
+++ doc/theses/andrew_beach_MMath/code/cross-catch.cpp	(revision 5541ea3d192c866061ad89a360daabc4e33e3429)
@@ -11,4 +11,5 @@
 int main(int argc, char * argv[]) {
 	unsigned int times = 1;
+	volatile bool should_throw = false;
 	if (1 < argc) {
 		times = strtol(argv[1], nullptr, 10);
@@ -18,7 +19,10 @@
 	for (unsigned int count = 0 ; count < times ; ++count) {
 		try {
-			// ...
+			asm volatile ("# try block");
+			if (should_throw) {
+				throw NotRaisedException();
+			}
 		} catch (NotRaisedException &) {
-			// ...
+			asm volatile ("# catch block");
 		}
 	}
Index: doc/theses/andrew_beach_MMath/code/cross-finally.cfa
===================================================================
--- doc/theses/andrew_beach_MMath/code/cross-finally.cfa	(revision 0640189e9e66678dab5d7f80793687fa10ff24c3)
+++ doc/theses/andrew_beach_MMath/code/cross-finally.cfa	(revision 5541ea3d192c866061ad89a360daabc4e33e3429)
@@ -5,20 +5,24 @@
 #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;
-	unsigned int total_frames = 1;
+	volatile bool should_throw = false;
 	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 {
-			// ...
+		try {
+			asm volatile ("# try block");
+			if (should_throw) {
+				throw (not_raised_exception){&not_vt};
+			}
 		} finally {
-			// ...
+			asm volatile ("# finally block");
 		}
 	}
Index: doc/theses/andrew_beach_MMath/code/cross-resume.cfa
===================================================================
--- doc/theses/andrew_beach_MMath/code/cross-resume.cfa	(revision 0640189e9e66678dab5d7f80793687fa10ff24c3)
+++ doc/theses/andrew_beach_MMath/code/cross-resume.cfa	(revision 5541ea3d192c866061ad89a360daabc4e33e3429)
@@ -20,7 +20,7 @@
 	for (unsigned int count = 0 ; count < times ; ++count) {
 		try {
-			// ...
+			asm volatile ("");
 		} catchResume (not_raised_exception *) {
-			// ...
+			asm volatile ("");
 		}
 	}
Index: doc/theses/andrew_beach_MMath/code/resume-detor.cfa
===================================================================
--- doc/theses/andrew_beach_MMath/code/resume-detor.cfa	(revision 0640189e9e66678dab5d7f80793687fa10ff24c3)
+++ doc/theses/andrew_beach_MMath/code/resume-detor.cfa	(revision 5541ea3d192c866061ad89a360daabc4e33e3429)
@@ -12,15 +12,15 @@
 
 void ^?{}(WithDestructor & this) {
-    // ...
+	asm volatile ("# destructor body");
 }
 
 void unwind_destructor(unsigned int frames) {
-    if (frames) {
+	if (frames) {
 
-        WithDestructor object;
-        unwind_destructor(frames - 1);
-    } else {
-        throwResume (empty_exception){&empty_vt};
-    }
+		WithDestructor object;
+		unwind_destructor(frames - 1);
+	} else {
+		throwResume (empty_exception){&empty_vt};
+	}
 }
 
@@ -36,11 +36,11 @@
 
 	Time start_time = timeHiRes();
-    for (int count = 0 ; count < times ; ++count) {
-        try {
-            unwind_destructor(total_frames);
-        } catchResume (empty_exception *) {
-            // ...
-        }
-    }
+	for (int count = 0 ; count < times ; ++count) {
+		try {
+			unwind_destructor(total_frames);
+		} catchResume (empty_exception *) {
+			asm volatile ("# fixup block");
+		}
+	}
 	Time end_time = timeHiRes();
 	sout | "Run-Time (ns): " | (end_time - start_time)`ns;
Index: doc/theses/andrew_beach_MMath/code/resume-empty.cfa
===================================================================
--- doc/theses/andrew_beach_MMath/code/resume-empty.cfa	(revision 0640189e9e66678dab5d7f80793687fa10ff24c3)
+++ doc/theses/andrew_beach_MMath/code/resume-empty.cfa	(revision 5541ea3d192c866061ad89a360daabc4e33e3429)
@@ -13,5 +13,5 @@
 		unwind_empty(frames - 1);
 	} else {
-		throw (empty_exception){&empty_vt};
+		throwResume (empty_exception){&empty_vt};
 	}
 }
@@ -31,6 +31,6 @@
 		try {
 			unwind_empty(total_frames);
-		} catch (empty_exception *) {
-			// ...
+		} catchResume (empty_exception *) {
+			asm volatile ("# fixup block");
 		}
 	}
Index: doc/theses/andrew_beach_MMath/code/resume-finally.cfa
===================================================================
--- doc/theses/andrew_beach_MMath/code/resume-finally.cfa	(revision 0640189e9e66678dab5d7f80793687fa10ff24c3)
+++ doc/theses/andrew_beach_MMath/code/resume-finally.cfa	(revision 5541ea3d192c866061ad89a360daabc4e33e3429)
@@ -14,5 +14,5 @@
 			unwind_finally(frames - 1);
 		} finally {
-			// ...
+			asm volatile ("# finally block");
 		}
 	} else {
@@ -36,5 +36,5 @@
 			unwind_finally(total_frames);
 		} catchResume (empty_exception *) {
-			// ...
+			asm volatile ("# fixup block");
 		}
 	}
Index: doc/theses/andrew_beach_MMath/code/resume-other.cfa
===================================================================
--- doc/theses/andrew_beach_MMath/code/resume-other.cfa	(revision 0640189e9e66678dab5d7f80793687fa10ff24c3)
+++ doc/theses/andrew_beach_MMath/code/resume-other.cfa	(revision 5541ea3d192c866061ad89a360daabc4e33e3429)
@@ -16,5 +16,5 @@
 			unwind_other(frames - 1);
 		} catchResume (not_raised_exception *) {
-			// ...
+			asm volatile ("# fixup block (stack)");
 		}
 	} else {
@@ -38,5 +38,5 @@
 			unwind_other(total_frames);
 		} catchResume (empty_exception *) {
-			// ...
+			asm volatile ("# fixup block (base)");
 		}
 	}
Index: doc/theses/andrew_beach_MMath/code/run.sh
===================================================================
--- doc/theses/andrew_beach_MMath/code/run.sh	(revision 5541ea3d192c866061ad89a360daabc4e33e3429)
+++ doc/theses/andrew_beach_MMath/code/run.sh	(revision 5541ea3d192c866061ad89a360daabc4e33e3429)
@@ -0,0 +1,33 @@
+#!/usr/bin/env bash
+
+readonly ALL_TESTS=(cond-match-{all,none} cross-{catch,finally} \
+		raise-{detor,empty,finally,other})
+
+gen-file-name() (
+	if echo "$1" | grep -q -E '^[^%]*%[^%]*$' -; then
+		for L in {a..z}; do
+			file_name=${1//%/$L}
+			if ! [ -e $file_name ]; then
+				break
+			fi
+		done
+		echo $file_name
+	else
+		echo "$1"
+	fi
+)
+
+readonly N=${1:-5}
+readonly OUT_FILE=$(gen-file-name ${2:-run-%-$N})
+
+run-tests() (
+	for ((i = 0 ; i < N ; ++i)); do
+		for test in ${ALL_TESTS[@]}; do
+			for lang in cfa-t cfa-r cpp java python; do
+				./test.sh $lang $test
+			done
+		done
+	done
+)
+
+run-tests > $OUT_FILE
Index: doc/theses/andrew_beach_MMath/code/test.sh
===================================================================
--- doc/theses/andrew_beach_MMath/code/test.sh	(revision 0640189e9e66678dab5d7f80793687fa10ff24c3)
+++ doc/theses/andrew_beach_MMath/code/test.sh	(revision 5541ea3d192c866061ad89a360daabc4e33e3429)
@@ -1,5 +1,11 @@
 #!/usr/bin/env bash
 
-# Usage: LANGUAGE TEST | -b SOURCE_FILE
+# Usage:
+# test.sh LANGUAGE TEST
+#   Run the TEST in LANGUAGE.
+# test.sh -b SOURCE_FILE...
+#   Build a test from SOURCE_FILE(s).
+# test.sh -v LANGUAGE TEST FILE
+#   View the result from TEST in LANGUAGE stored in FILE.
 
 readonly ITERATIONS=1000000 # 1 000 000, one million
@@ -38,4 +44,8 @@
 	done
 	exit 0
+elif [ "-v" = "$1" -a 4 = "$#" ]; then
+    TEST_LANG="$2"
+    TEST_CASE="$3"
+    VIEW_FILE="$4"
 elif [ 2 -eq "$#" ]; then
 	TEST_LANG="$1"
@@ -116,9 +126,9 @@
 
 case "$TEST_LANG" in
-cfa-t) echo $CFAT; $CFAT;;
-cfa-r) echo $CFAR; $CFAR;;
-cpp) echo $CPP; $CPP;;
-java) echo $JAVA; $JAVA;;
-python) echo $PYTHON; $PYTHON;;
+cfa-t) CALL="$CFAT";;
+cfa-r) CALL="$CFAR";;
+cpp) CALL="$CPP";;
+java) CALL="$JAVA";;
+python) CALL="$PYTHON";;
 *)
 	echo "No such language: $TEST_LANG" >&2
@@ -126,2 +136,11 @@
 	;;
 esac
+
+echo $CALL
+
+if [ -n "$VIEW_FILE" ]; then
+    grep -A 1 -B 0 "$CALL" "$VIEW_FILE" | sed -n -e 's!Run-Time (ns): !!;T;p'
+    exit
+fi
+
+$CALL
Index: doc/theses/andrew_beach_MMath/code/throw-detor.cfa
===================================================================
--- doc/theses/andrew_beach_MMath/code/throw-detor.cfa	(revision 0640189e9e66678dab5d7f80793687fa10ff24c3)
+++ doc/theses/andrew_beach_MMath/code/throw-detor.cfa	(revision 5541ea3d192c866061ad89a360daabc4e33e3429)
@@ -12,5 +12,5 @@
 
 void ^?{}(WithDestructor & this) {
-	// ...
+	asm volatile ("# destructor body");
 }
 
@@ -39,5 +39,5 @@
 			unwind_destructor(total_frames);
 		} catch (empty_exception *) {
-			// ...
+			asm volatile ("# catch block");
 		}
 	}
Index: doc/theses/andrew_beach_MMath/code/throw-detor.cpp
===================================================================
--- doc/theses/andrew_beach_MMath/code/throw-detor.cpp	(revision 0640189e9e66678dab5d7f80793687fa10ff24c3)
+++ doc/theses/andrew_beach_MMath/code/throw-detor.cpp	(revision 5541ea3d192c866061ad89a360daabc4e33e3429)
@@ -10,5 +10,7 @@
 
 struct WithDestructor {
-	~WithDestructor() {}
+	~WithDestructor() {
+		asm volatile ("# destructor body");
+	}
 };
 
@@ -37,5 +39,5 @@
 			unwind_destructor(total_frames);
 		} catch (EmptyException &) {
-			// ...
+			asm volatile ("# catch block");
 		}
 	}
Index: doc/theses/andrew_beach_MMath/code/throw-empty.cfa
===================================================================
--- doc/theses/andrew_beach_MMath/code/throw-empty.cfa	(revision 0640189e9e66678dab5d7f80793687fa10ff24c3)
+++ doc/theses/andrew_beach_MMath/code/throw-empty.cfa	(revision 5541ea3d192c866061ad89a360daabc4e33e3429)
@@ -32,5 +32,5 @@
 			unwind_empty(total_frames);
 		} catch (empty_exception *) {
-			// ...
+			asm volatile ("# catch block");
 		}
 	}
Index: doc/theses/andrew_beach_MMath/code/throw-empty.cpp
===================================================================
--- doc/theses/andrew_beach_MMath/code/throw-empty.cpp	(revision 0640189e9e66678dab5d7f80793687fa10ff24c3)
+++ doc/theses/andrew_beach_MMath/code/throw-empty.cpp	(revision 5541ea3d192c866061ad89a360daabc4e33e3429)
@@ -32,5 +32,5 @@
 			unwind_empty(total_frames);
 		} catch (EmptyException &) {
-			// ...
+			asm volatile ("# catch block");
 		}
 	}
Index: doc/theses/andrew_beach_MMath/code/throw-finally.cfa
===================================================================
--- doc/theses/andrew_beach_MMath/code/throw-finally.cfa	(revision 0640189e9e66678dab5d7f80793687fa10ff24c3)
+++ doc/theses/andrew_beach_MMath/code/throw-finally.cfa	(revision 5541ea3d192c866061ad89a360daabc4e33e3429)
@@ -14,5 +14,5 @@
 			unwind_finally(frames - 1);
 		} finally {
-			// ...
+			asm volatile ("# finally block");
 		}
 	} else {
@@ -36,5 +36,5 @@
 			unwind_finally(total_frames);
 		} catch (empty_exception *) {
-			// ...
+			asm volatile ("# catch block");
 		}
 	}
Index: doc/theses/andrew_beach_MMath/code/throw-other.cfa
===================================================================
--- doc/theses/andrew_beach_MMath/code/throw-other.cfa	(revision 0640189e9e66678dab5d7f80793687fa10ff24c3)
+++ doc/theses/andrew_beach_MMath/code/throw-other.cfa	(revision 5541ea3d192c866061ad89a360daabc4e33e3429)
@@ -16,5 +16,5 @@
 			unwind_other(frames - 1);
 		} catch (not_raised_exception *) {
-			// ...
+			asm volatile ("# catch block (stack)");
 		}
 	} else {
@@ -38,5 +38,5 @@
 			unwind_other(total_frames);
 		} catch (empty_exception *) {
-			// ...
+			asm volatile ("# catch block (base)");
 		}
 	}
Index: doc/theses/andrew_beach_MMath/code/throw-other.cpp
===================================================================
--- doc/theses/andrew_beach_MMath/code/throw-other.cpp	(revision 0640189e9e66678dab5d7f80793687fa10ff24c3)
+++ doc/theses/andrew_beach_MMath/code/throw-other.cpp	(revision 5541ea3d192c866061ad89a360daabc4e33e3429)
@@ -16,5 +16,5 @@
 			unwind_other(frames - 1);
 		} catch (NotRaisedException &) {
-			// ...
+			asm volatile ("# catch block (stack)");
 		}
 	} else {
@@ -38,5 +38,5 @@
 			unwind_other(total_frames);
 		} catch (EmptyException &) {
-			// ...
+			asm volatile ("# catch block (base)");
 		}
 	}
Index: doc/theses/andrew_beach_MMath/existing.tex
===================================================================
--- doc/theses/andrew_beach_MMath/existing.tex	(revision 0640189e9e66678dab5d7f80793687fa10ff24c3)
+++ doc/theses/andrew_beach_MMath/existing.tex	(revision 5541ea3d192c866061ad89a360daabc4e33e3429)
@@ -10,5 +10,6 @@
 
 Only those \CFA features pertaining to this thesis are discussed.
-Also, only new features of \CFA will be discussed, a familiarity with
+% Also, only new features of \CFA will be discussed,
+A familiarity with
 C or C-like languages is assumed.
 
@@ -16,9 +17,9 @@
 \CFA has extensive overloading, allowing multiple definitions of the same name
 to be defined~\cite{Moss18}.
-\begin{cfa}
-char i; int i; double i;
-int f(); double f();
-void g( int ); void g( double );
-\end{cfa}
+\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}
 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
@@ -62,5 +63,5 @@
 int && rri = ri;
 rri = 3;
-&ri = &j;
+&ri = &j; // rebindable
 ri = 5;
 \end{cfa}
@@ -78,6 +79,6 @@
 \end{minipage}
 
-References are intended to be used when you would use pointers but would
-be dereferencing them (almost) every usage.
+References are intended for pointer situations where dereferencing is the common usage,
+\ie the value is more important than the pointer.
 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
@@ -85,70 +86,75 @@
 \section{Operators}
 
-\CFA implements operator overloading by providing special names.
-Operator uses are translated into function calls using these names.
-These names are created by taking the operator symbols and joining them with
+\CFA implements operator overloading by providing special names, where
+operator usages 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 @*?@.
+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.
 \begin{cfa}
 point ?+?(point a, point b) { return point{a.x + b.x, a.y + b.y}; }
-bool ?==?(point a, point b) { return a.x == b.x && a.y == b.y; }
+int ?==?(point a, point b) { return a.x == b.x && a.y == b.y; }
 {
 	assert(point{1, 2} + point{3, 4} == point{4, 6});
 }
 \end{cfa}
-Note that these special names are not limited to just being used for these
-operator functions, and may be used name other declarations.
-Some ``near misses", that will not match an operator form but looks like
-it may have been supposed to, will generate wantings but otherwise they are
-left alone.
+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.
 
 %\subsection{Constructors and Destructors}
 
-Both constructors and destructors are operators, which means they are
-functions with special operator names rather than type names in \Cpp. The
-special operator names may be used to call the functions explicitly.
-% Placement new means that this is actually equivant to C++.
+\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++.
 
 The special name for a constructor is @?{}@, which comes from the
 initialization syntax in C, \eg @Example e = { ... }@.
-\CFA will generate a constructor call each time a variable is declared,
-passing the initialization arguments to the constructort.
+\CFA generates a constructor call each time a variable is declared,
+passing the initialization arguments to the constructor.
 \begin{cfa}
 struct Example { ... };
 void ?{}(Example & this) { ... }
-{
-	Example a;
-	Example b = {};
-}
 void ?{}(Example & this, char first, int num) { ... }
-{
-	Example c = {'a', 2};
-}
-\end{cfa}
-Both @a@ and @b@ will be initalized with the first constructor,
-while @c@ will be initalized with the second.
-Currently, there is no general way to skip initialation.
-
+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}
 % I don't like the \^{} symbol but $^\wedge$ isn't better.
-Similarly destructors use the special name @^?{}@ (the @^@ has no special
+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.
+% 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 d;
-} // <- implicit destructor call
-\end{cfa}
-
-Whenever a type is defined, \CFA will create a default zero-argument
+	Example e;	// implicit constructor call
+	^?{}(e);		// explicit destructor call
+	?{}(e);		// explicit constructor call
+} // implicit destructor call
+\end{cfa}
+
+Whenever a type is defined, \CFA creates a default zero-argument
 constructor, a copy constructor, a series of argument-per-field constructors
 and a destructor. All user constructors are defined after this.
-Because operators are never part of the type definition they may be added
-at any time, including on built-in types.
 
 \section{Polymorphism}
@@ -202,5 +208,5 @@
 Note, a function named @do_once@ is not required in the scope of @do_twice@ to
 compile it, unlike \Cpp template expansion. Furthermore, call-site inferencing
-allows local replacement of the most specific parametric functions needs for a
+allows local replacement of the specific parametric functions needs for a
 call.
 \begin{cfa}
@@ -218,10 +224,10 @@
 to @do_twice@ and called within it.
 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
-would be a better match.
+@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 packages called a @trait@, which can then be used in an assertion
+convenient package called a @trait@, which can then be used in an assertion
 instead of the individual constraints.
 \begin{cfa}
@@ -239,5 +245,5 @@
 functionality, like @sumable@, @listable@, \etc.
 
-Polymorphic structures and unions are defined by qualifying the aggregate type
+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.
@@ -285,14 +291,15 @@
 coroutine CountUp {
 	unsigned int next;
-}
+};
 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}
+\begin{cfa}[numbers=left,numberstyle=\scriptsize\sf]
 void main(CountUp & this) {
-	for (unsigned int next = 0 ; true ; ++next) {
-		next = up;
+	for (unsigned int up = 0;; ++up) {
+		this.next = up;
 		suspend;$\label{suspend}$
 	}
@@ -300,6 +307,6 @@
 \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 caller
-without terminating the coroutine's function.
+@suspend@ statement is used to return execution to the coroutine's resumer
+without terminating the coroutine's function(s).
 
 A coroutine is resumed by calling the @resume@ function, \eg @resume(countup)@.
@@ -323,7 +330,7 @@
 exclusion on a monitor object by qualifying an object reference parameter with
 @mutex@.
-\begin{cfa}
-void example(MonitorA & mutex argA, MonitorB & mutex argB);
-\end{cfa}
+\begin{lstlisting}[language=CFA,{moredelim=**[is][\color{red}]{@}{@}}]
+void example(MonitorA & @mutex@ argA, MonitorB & @mutex@ argB);
+\end{lstlisting}
 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
@@ -355,5 +362,5 @@
 {
 	StringWorker stringworker; // fork thread running in "main"
-} // <- implicitly join with thread / wait for completion
+} // implicitly join with thread / wait for completion
 \end{cfa}
 The thread main is where a new thread starts execution after a fork operation
Index: doc/theses/andrew_beach_MMath/handler.fig
===================================================================
--- doc/theses/andrew_beach_MMath/handler.fig	(revision 5541ea3d192c866061ad89a360daabc4e33e3429)
+++ doc/theses/andrew_beach_MMath/handler.fig	(revision 5541ea3d192c866061ad89a360daabc4e33e3429)
@@ -0,0 +1,46 @@
+#FIG 3.2  Produced by xfig version 3.2.7b
+Landscape
+Center
+Inches
+Letter
+100.00
+Single
+-2
+1200 2
+6 1050 2175 1500 3600
+2 1 0 1 0 7 100 0 -1 4.000 0 0 -1 1 0 2
+	1 1 1.00 45.00 90.00
+	 1275 3600 1275 2400
+4 1 0 100 0 0 12 0.0000 2 135 420 1275 2325 stack\001
+-6
+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
+	 2175 2700 2175 2400
+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
+	 2175 2175 2175 1875
+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
+	 2175 1575 2175 1275
+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
+	 2175 3225 2175 2925
+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
+	 2175 3750 2175 3450
+2 1 0 1 0 7 50 -1 -1 0.000 0 0 -1 1 0 4
+	1 1 1.00 45.00 90.00
+	 2700 1125 3300 1125 3300 3300 2700 3300
+4 1 0 50 -1 5 12 0.0000 2 165 600 2175 2850 h$_0$\001
+4 0 0 50 -1 5 12 0.0000 2 165 1320 2325 3000 handler$_0$\001
+4 1 0 50 -1 5 12 0.0000 2 135 120 2175 2325 g\001
+4 1 0 50 -1 5 12 0.0000 2 120 120 2175 1800 f\001
+4 1 0 50 -1 5 12 0.0000 2 165 1320 2175 1200 handler$_1$\001
+4 2 0 100 0 0 12 0.0000 2 135 375 1725 3000 calls\001
+4 0 0 50 -1 5 12 0.0000 2 165 1320 2325 3525 handler$_1$\001
+4 1 0 50 -1 5 12 0.0000 2 165 600 2175 3900 h$_2$\001
+4 0 0 50 -1 5 12 0.0000 2 165 1320 2325 4050 handler$_2$\001
+4 1 0 50 -1 5 12 0.0000 2 165 600 2175 3375 h$_1$\001
+4 2 0 100 0 5 12 0.0000 2 120 120 2550 3375 i\001
+4 0 0 100 0 0 12 0.0000 2 135 555 3450 2100 lexical\001
+4 0 0 100 0 0 12 0.0000 2 135 330 3450 2325 link\001
Index: doc/theses/andrew_beach_MMath/intro.tex
===================================================================
--- doc/theses/andrew_beach_MMath/intro.tex	(revision 0640189e9e66678dab5d7f80793687fa10ff24c3)
+++ doc/theses/andrew_beach_MMath/intro.tex	(revision 5541ea3d192c866061ad89a360daabc4e33e3429)
@@ -2,42 +2,81 @@
 
 % The highest level overview of Cforall and EHMs. Get this done right away.
-This thesis goes over the design and implementation of the exception handling
+This thesis covers the design and implementation of the exception handling
 mechanism (EHM) of
 \CFA (pronounced sea-for-all and may be written Cforall or CFA).
-\CFA is a new programming language that extends C, that maintains
+\CFA is a new programming language that extends C, which maintains
 backwards-compatibility while introducing modern programming features.
 Adding exception handling to \CFA gives it new ways to handle errors and
-make other large control-flow jumps.
+make large control-flow jumps.
 
 % Now take a step back and explain what exceptions are generally.
+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.
 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
-This seperation is uncommon because termination exception handling is so
-much more common that it is often assumed.
+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?
-A language's EHM is the combination of language syntax and run-time
-components that are used to construct, raise and handle exceptions,
-including all control flow.
-
-Termination exception handling allows control to return to any previous
-function on the stack directly, skipping any functions between it and the
-current function.
+
+Exception handling relies on the concept of nested functions to create handlers that deal with exceptions.
 \begin{center}
-\input{callreturn}
+\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}
 \end{center}
-
-Resumption exception handling seaches the stack for a handler and then calls
-it without adding or removing any other stack frames.
-\todo{Add a diagram showing control flow for resumption.}
+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.
+\begin{center}
+\input{termination}
+\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
-so they are often limited to unusual or ``exceptional" cases.
-The classic example of this is error handling, exceptions can be used to
-remove error handling logic from the main execution path and while paying
+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
 most of the cost only when the error actually occurs.
 
@@ -49,18 +88,17 @@
 some of the underlying tools used to implement and express exception handling
 in other languages are absent in \CFA.
-Still the resulting syntax resembles that of other languages:
-\begin{cfa}
-try {
+Still the resulting basic syntax resembles that of other languages:
+\begin{lstlisting}[language=CFA,{moredelim=**[is][\color{red}]{@}{@}}]
+@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{cfa}
-
+\end{lstlisting}
 % A note that yes, that was a very fast overview.
 The design and implementation of all of \CFA's EHM's features are
@@ -69,126 +107,146 @@
 
 % The current state of the project and what it contributes.
-All of these features have been implemented in \CFA, along with
-a suite of test cases as part of this project.
-The implementation techniques are generally applicable in other programming
+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
 languages and much of the design is as well.
-Some parts of the EHM use other features unique to \CFA and these would be
-harder to replicate in other programming languages.
-
+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.
-Some existing programming languages that include EHMs/exception handling
-include C++, Java and Python. All three examples focus on termination
-exceptions which unwind the stack as part of the
-Exceptions also can replace return codes and return unions.
+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.
 
 The contributions of this work are:
 \begin{enumerate}
 \item Designing \CFA's exception handling mechanism, adapting designs from
-other programming languages and the creation of new features.
-\item Implementing stack unwinding and the EHM in \CFA, including updating
-the compiler and the run-time environment.
-\item Designed and implemented a prototype virtual system.
+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.
+\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.
 \end{enumerate}
 
-\todo{I can't figure out a good lead-in to the roadmap.}
-The next section covers the existing state of exceptions.
-The existing state of \CFA is also covered in \autoref{c:existing}.
-The new features are introduced in \autoref{c:features},
-which explains their usage and design.
-That is followed by the implementation of those features in
+%\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},
+covering their usage and design.
+That is followed by the implementation of these features in
 \autoref{c:implement}.
-The performance results are examined in \autoref{c:performance}.
-Possibilities to extend this project are discussed in \autoref{c:future}.
+Performance results are presented in \autoref{c:performance}.
+Summing up and possibilities for extending this project are discussed in \autoref{c:future}.
 
 \section{Background}
 \label{s:background}
 
-Exception handling is not a new concept,
-with papers on the subject dating back 70s.
-
-Their were popularised by \Cpp,
+Exception handling is a well examined area in programming languages,
+with papers on the subject dating back the 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,
 which added them in its first major wave of non-object-orientated features
 in 1990.
 % https://en.cppreference.com/w/cpp/language/history
-
-Java was the next popular language to use exceptions. It is also the most
-popular language with checked exceptions.
-Checked exceptions are part of the function interface they are raised from.
-This includes functions they propogate through, until a handler for that
-type of exception is found.
-This makes exception information explicit, which can improve clarity and
+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
+\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
+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}
+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.
-Some of these, such as dealing with high-order methods or an overly specified
-throws clause, are technical. However some of the issues are much more
-human, in that writing/updating all the exception signatures can be enough
-of a burden people will hack the system to avoid them.
-Including the ``catch-and-ignore" pattern where a catch block is used without
-anything to repair or recover from the exception.
-
-%\subsection
-Resumption exceptions have been much less popular.
-Although resumption has a history as old as termination's, very few
-programming languages have implement them.
+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.
+
+%\subsection
+Resumption exceptions are less popular,
+although resumption is as old as termination;
+hence, 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 is one programming languages that did and experiance with that
-languages is quoted as being one of the reasons resumptions were not
+Mesa~\cite{Mesa} is one programming languages that did. Experience with Mesa
+is quoted as being one of the reasons resumptions are not
 included in the \Cpp standard.
 % https://en.wikipedia.org/wiki/Exception_handling
-\todo{A comment about why we did include them when they are so unpopular
-might be approprate.}
-
-%\subsection
-Functional languages, tend to use solutions like the return union, but some
-exception-like constructs still appear.
-
-For instance Haskell's built in error mechanism can make the result of any
-expression, including function calls. Any expression that examines an
-error value will in-turn produce an error. This continues until the main
-function produces an error or until it is handled by one of the catch
-functions.
-
-%\subsection
-More recently exceptions seem to be vanishing from newer programming
-languages.
-Rust and Go reduce this feature to panics.
-Panicing is somewhere between a termination exception and a program abort.
-Notably in Rust a panic can trigger either, a panic may unwind the stack or
-simply kill the process.
+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.
+% 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.
+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
-Go's panic is much more similar to a termination exception but there is
-only a catch-all function with \code{Go}{recover()}.
-So exceptions still are appearing, just in reduced forms.
-
-%\subsection
-Exception handling's most common use cases are in error handling.
-Here are some other ways to handle errors and comparisons with exceptions.
+In Go~\cite{Go}, a panic 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.
 \begin{itemize}
 \item\emph{Error Codes}:
-This pattern uses an enumeration (or just a set of fixed values) to indicate
-that an error has occured and which error it was.
-
-There are some issues if a function wants to return an error code and another
-value. The main issue is that it can be easy to forget checking the error
-code, which can lead to an error being quitely and implicitly ignored.
-Some new languages have tools that raise warnings if the return value is
-discarded to avoid this.
-It also puts more code on the main execution path.
+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,
+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..
+
 \item\emph{Special Return with Global Store}:
-A function that encounters an error returns some value indicating that it
-encountered a value but store which error occured in a fixed global location.
-
-Perhaps the C standard @errno@ is the most famous example of this,
-where some standard library functions will return some non-value (often a
-NULL pointer) and set @errno@.
-
-This avoids the multiple results issue encountered with straight error codes
-but otherwise many of the same advantages and disadvantages.
-It does however introduce one other major disadvantage:
-Everything that uses that global location must agree on all possible errors.
+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.
+
 \item\emph{Return Union}:
-Replaces error codes with a tagged union.
+This pattern replaces error codes with a tagged union.
 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
@@ -196,40 +254,39 @@
 so that one type can be used everywhere in error handling code.
 
-This pattern is very popular in functional or semi-functional language,
-anything with primitive support for tagged unions (or algebraic data types).
+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.
 % Rust's \code{rust}{Result<T, E>}
-
-The main disadvantage is again it puts code on the main execution path.
-This is also the first technique that allows for more information about an
-error, other than one of a fix-set of ids, to be sent.
-They can be missed but some languages can force that they are checked.
-It is also implicitly forced in any languages with checked union access.
+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.
+
 \item\emph{Handler Functions}:
-On error the function that produced the error calls another function to
+This pattern implicitly associates functions with errors.
+On error, the function that produced the error implicitly 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 as its fallback system if exception handling fails.
+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.
-The difference is they are more expencive to set up but cheaper to use, and
-so are more suited to more fequent errors.
-The exception being global handlers if they are rarely change as the time
-in both cases strinks towards zero.
+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.
 \end{itemize}
 
 %\subsection
-Because of their cost exceptions are rarely used for hot paths of execution.
-There is an element of self-fulfilling prophocy here as implementation
-techniques have been designed to make exceptions cheap to set-up at the cost
-of making them expencive to use.
-Still, use of exceptions for other tasks is more common in higher-level
-scripting languages.
-An iconic example is Python's StopIteration exception which is thrown by
-an iterator to indicate that it is exausted. Combined with Python's heavy
-use of the iterator based for-loop.
+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
Index: doc/theses/andrew_beach_MMath/performance.tex
===================================================================
--- doc/theses/andrew_beach_MMath/performance.tex	(revision 0640189e9e66678dab5d7f80793687fa10ff24c3)
+++ doc/theses/andrew_beach_MMath/performance.tex	(revision 5541ea3d192c866061ad89a360daabc4e33e3429)
@@ -1,7 +1,4 @@
 \chapter{Performance}
 \label{c:performance}
-
-\textbf{Just because of the stage of testing there are design notes for
-the tests as well as commentary on them.}
 
 Performance has been of secondary importance for most of this project.
@@ -11,5 +8,7 @@
 
 \section{Test Set-Up}
-Tests will be run on \CFA, C++ and Java.
+Tests will be run in \CFA, C++, Java and Python.
+In addition there are two sets of tests for \CFA,
+one for termination exceptions and once with resumption exceptions.
 
 C++ is the most comparable language because both it and \CFA use the same
@@ -18,5 +17,6 @@
 comparison. \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 does not handle.
+there are some features it does not handle, through utility functions,
+but otherwise \Cpp has a significant advantage.
 
 Java is another very popular language with similar termination semantics.
@@ -25,21 +25,46 @@
 It also implements the finally clause on try blocks allowing for a direct
 feature-to-feature comparison.
+As with \Cpp, Java's implementation is more mature, has more optimizations
+and more extra features.
+
+Python was used as a point of comparison because of the \CFA EHM's
+current performance goals, which is 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.
+
+Unfortunately there are no notable modern programming languages with
+resumption exceptions. Even the older programming languages with resumptions
+seem to be notable only for having resumptions.
+So instead resumptions are compared to a less similar but much more familiar
+feature, termination exceptions.
 
 All tests are run inside a main loop which will perform the test
 repeatedly. This is to avoids start-up or tear-down time from
 affecting the timing results.
-A consequence of this is that tests cannot terminate the program,
-which does limit how tests can be implemented.
-There are catch-alls to keep unhandled
-exceptions from terminating tests.
+Most test were run 1 000 000 (a million) times.
+The Java versions of the test also run this loop an extra 1000 times before
+beginning to time the results to ``warm-up" the JVM.
+
+Timing is done internally, with time measured immediately before and
+immediately after the test loop. The difference is calculated and printed.
+
+The loop structure and internal timing means it is impossible to test
+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
+critical.
 
 The exceptions used in these tests will always be a exception based off of
 the base exception. This requirement minimizes performance differences based
-on the object model.
-Catch-alls are done by catching the root exception type (not using \Cpp's
-\code{C++}{catch(...)}).
+on the object model used to repersent the exception.
 
-Tests run in Java were not warmed because exception code paths should not be
-hot.
+All tests were designed to be as minimal as possible while still preventing
+exessive optimizations.
+For example, empty inline assembly blocks are used in \CFA and \Cpp to
+prevent excessive optimizations while adding no actual work.
+
+% 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(...)}).
 
 \section{Tests}
@@ -47,12 +72,4 @@
 components of the exception system.
 The should provide a guide as to where the EHM's costs can be found.
-
-Tests are run in \CFA, \Cpp and Java.
-Not every test is run in every language, if the feature under test is missing
-the test is skipped. These cases will be noted.
-In addition to the termination tests for every language,
-\CFA has a second set of tests that test resumption. These are the same
-except that the raise statements and handler clauses are replaced with the
-resumption variants.
 
 \paragraph{Raise and Handle}
@@ -62,5 +79,5 @@
 start-up and shutdown on the results.
 Each iteration of the main loop
-\begin{itemize}
+\begin{itemize}[nosep]
 \item Empty Function:
 The repeating function is empty except for the necessary control code.
@@ -68,9 +85,7 @@
 The repeating function creates an object with a destructor before calling
 itself.
-(Java is skipped as it does not destructors.)
 \item Finally:
 The repeating function calls itself inside a try block with a finally clause
 attached.
-(\Cpp is skipped as it does not have finally clauses.)
 \item Other Handler:
 The repeating function calls itself inside a try block with a handler that
@@ -84,5 +99,5 @@
 In each iteration, a try statement is executed. Entering and leaving a loop
 is all the test wants to do.
-\begin{itemize}
+\begin{itemize}[nosep]
 \item Handler:
 The try statement has a handler (of the matching kind).
@@ -95,9 +110,10 @@
 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.
-\begin{itemize}
-\item Catch All:
+checks the exception's type) and conditional re-raise if it was not supposed
+to handle that exception.
+\begin{itemize}[nosep]
+\item Match All:
 The condition is always true. (Always matches or never re-raises.)
-\item Catch None:
+\item Match None:
 The condition is always false. (Never matches or always re-raises.)
 \end{itemize}
@@ -113,9 +129,25 @@
 %related to -fexceptions.)
 
-% Some languages I left out:
-% Python: Its a scripting language, different
-% uC++: Not well known and should the same results as C++, except for
-%   resumption which should be the same.
+\section{Results}
+Each test is was run five times, the best and worst result were discarded and
+the remaining values were averaged.
 
-%\section{Resumption Comparison}
-\todo{Can we find a good language to compare resumptions in.}
+In cases where a feature is not supported by a language the test is skipped
+for that language. Similarly, if a test is does not change between resumption
+and termination in \CFA, then only one test is written and the result
+was put into the termination column.
+
+\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 \\
+\hline
+\end{tabular}
Index: doc/theses/andrew_beach_MMath/resumption.fig
===================================================================
--- doc/theses/andrew_beach_MMath/resumption.fig	(revision 5541ea3d192c866061ad89a360daabc4e33e3429)
+++ doc/theses/andrew_beach_MMath/resumption.fig	(revision 5541ea3d192c866061ad89a360daabc4e33e3429)
@@ -0,0 +1,39 @@
+#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 0 1 0 2397.794 1872.794 2325 1275 3000 1875 2400 2475
+	1 1 1.00 45.00 90.00
+5 1 0 1 0 7 100 0 -1 0.000 0 0 1 0 2162.500 1575.000 2250 1275 2475 1575 2250 1875
+	1 1 1.00 45.00 90.00
+5 1 0 1 0 7 100 0 -1 0.000 0 0 1 0 2162.500 2175.000 2250 1875 2475 2175 2250 2475
+	1 1 1.00 45.00 90.00
+6 1125 1200 1575 2625
+2 1 0 1 0 7 100 0 -1 4.000 0 0 -1 1 0 2
+	1 1 1.00 45.00 90.00
+	 1350 2625 1350 1425
+4 1 0 100 0 0 12 0.0000 2 135 420 1350 1350 stack\001
+-6
+2 1 0 1 0 7 100 0 -1 0.000 0 0 -1 1 0 2
+	1 1 1.00 45.00 90.00
+	 2100 2400 2100 2025
+2 1 0 1 0 7 100 0 -1 0.000 0 0 -1 1 0 2
+	1 1 1.00 45.00 90.00
+	 2100 1800 2100 1425
+2 1 0 1 0 7 100 0 -1 0.000 0 0 -1 1 0 2
+	1 1 1.00 45.00 90.00
+	 2100 1125 2100 750
+4 1 0 100 0 5 12 0.0000 2 135 120 2100 1950 g\001
+4 1 0 100 0 5 12 0.0000 2 120 120 2100 2625 h\001
+4 1 0 100 0 5 12 0.0000 2 120 120 2100 1350 f\001
+4 0 0 100 0 0 12 0.0000 2 120 555 2375 1950 returns\001
+4 2 0 100 0 0 12 0.0000 2 135 375 1875 1950 calls\001
+4 0 0 100 0 5 12 0.0000 2 120 840 2250 2775 handler\001
+4 0 0 100 0 0 12 0.0000 2 135 510 3075 2100 search\001
+4 0 0 100 0 0 12 0.0000 2 90 570 3075 1875 resume\001
+4 1 0 100 0 5 12 0.0000 2 120 840 2100 675 handler\001
Index: doc/theses/andrew_beach_MMath/termination.fig
===================================================================
--- doc/theses/andrew_beach_MMath/termination.fig	(revision 5541ea3d192c866061ad89a360daabc4e33e3429)
+++ doc/theses/andrew_beach_MMath/termination.fig	(revision 5541ea3d192c866061ad89a360daabc4e33e3429)
@@ -0,0 +1,42 @@
+#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 0 1 0 2397.794 1872.794 2325 1275 3000 1875 2400 2475
+	1 1 1.00 45.00 90.00
+5 1 0 1 0 7 100 0 -1 0.000 0 0 1 0 2162.500 1575.000 2250 1275 2475 1575 2250 1875
+	1 1 1.00 45.00 90.00
+5 1 0 1 0 7 100 0 -1 0.000 0 0 1 0 2162.500 2175.000 2250 1875 2475 2175 2250 2475
+	1 1 1.00 45.00 90.00
+6 1125 1200 1575 2625
+2 1 0 1 0 7 100 0 -1 4.000 0 0 -1 1 0 2
+	1 1 1.00 45.00 90.00
+	 1350 2625 1350 1425
+4 1 0 100 0 0 12 0.0000 2 135 420 1350 1350 stack\001
+-6
+2 1 0 1 0 7 100 0 -1 0.000 0 0 -1 1 0 2
+	1 1 1.00 45.00 90.00
+	 2100 2400 2100 2025
+2 1 0 1 0 7 100 0 -1 0.000 0 0 -1 1 0 2
+	1 1 1.00 45.00 90.00
+	 2100 1800 2100 1425
+2 1 0 1 0 7 100 0 -1 0.000 0 0 -1 1 0 2
+	1 1 1.00 45.00 90.00
+	 4800 2400 4800 2025
+4 1 0 100 0 5 12 0.0000 2 135 120 2100 1950 g\001
+4 1 0 100 0 5 12 0.0000 2 120 120 2100 2625 h\001
+4 1 0 100 0 5 12 0.0000 2 120 120 2100 1350 f\001
+4 0 0 100 0 0 12 0.0000 2 120 555 2375 1950 returns\001
+4 2 0 100 0 0 12 0.0000 2 135 375 1875 1950 calls\001
+4 1 0 100 0 5 12 0.0000 2 120 120 4800 2625 h\001
+4 0 0 100 0 5 12 0.0000 2 120 840 2250 2775 handler\001
+4 0 0 100 0 5 12 0.0000 2 120 840 4950 2775 handler\001
+4 1 0 100 0 5 12 0.0000 2 120 840 4800 1950 handler\001
+4 0 0 100 0 0 12 0.0000 2 135 465 3075 1725 throw\001
+4 0 0 100 0 0 12 0.0000 2 135 510 3075 1950 search\001
+4 0 0 100 0 0 12 0.0000 2 165 735 3000 2175 (unwind)\001
Index: doc/theses/andrew_beach_MMath/uw-ethesis.tex
===================================================================
--- doc/theses/andrew_beach_MMath/uw-ethesis.tex	(revision 0640189e9e66678dab5d7f80793687fa10ff24c3)
+++ doc/theses/andrew_beach_MMath/uw-ethesis.tex	(revision 5541ea3d192c866061ad89a360daabc4e33e3429)
@@ -210,5 +210,6 @@
 \lstMakeShortInline@
 \lstset{language=CFA,style=cfacommon,basicstyle=\linespread{0.9}\tt}
-\lstset{moredelim=**[is][\protect\color{red}]{@}{@}}
+% PAB causes problems with inline @=
+%\lstset{moredelim=**[is][\protect\color{red}]{@}{@}}
 % Annotations from Peter:
 \newcommand{\PAB}[1]{{\color{blue}PAB: #1}}
Index: doc/theses/mubeen_zulfiqar_MMath/allocator.tex
===================================================================
--- doc/theses/mubeen_zulfiqar_MMath/allocator.tex	(revision 0640189e9e66678dab5d7f80793687fa10ff24c3)
+++ doc/theses/mubeen_zulfiqar_MMath/allocator.tex	(revision 5541ea3d192c866061ad89a360daabc4e33e3429)
@@ -111,13 +111,335 @@
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
-\section{Added Features}
-
-
-\subsection{Methods}
-Why did we need it?
-The added benefits.
-
+\section{Added Features and Methods}
+To improve the UHeapLmmm allocator (FIX ME: cite uHeapLmmm) interface and make it more user friendly, we added a few more routines to the C allocator. Also, we built a CFA (FIX ME: cite cforall) interface on top of C interface to increase the usability of the allocator.
+
+\subsection{C Interface}
+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 )
+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
+dim: number of objects in the array
+\item
+elemSize: size of the object in the array.
+\end{itemize}
+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 )
+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
+oaddr: the address of the old object that needs to be resized.
+\item
+size: the new size requirement of the to which the old object needs to be resized.
+\end{itemize}
+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 )
+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
+oaddr: the address of the old object that needs to be resized.
+\item
+nalign: the new alignment to which the old object needs to be realigned.
+\item
+size: the new size requirement of the to which the old object needs to be resized.
+\end{itemize}
+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 )
+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
+alignment: the alignment to which the dynamic array needs to be aligned.
+\item
+dim: number of objects in the array
+\item
+elemSize: size of the object in the array.
+\end{itemize}
+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 )
+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
+alignment: the alignment to which the dynamic array needs to be aligned.
+\item
+dim: number of objects in the array
+\item
+elemSize: size of the object in the array.
+\end{itemize}
+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.
+\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.
+\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.
+\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 )
+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
+oaddr: the address of the old object that needs to be reallocated.
+\item
+nalign: the new alignment to which the old object needs to be realigned.
+\item
+size: the new size requirement of the to which the old object needs to be resized.
+\end{itemize}
+It returns an object with the size and alignment given in the parameters that preserves the data in the old object. On failure, it returns a NULL pointer.
+
+\subsection{CFA Malloc Interface}
+We added some routines to the malloc interface of CFA. These routines can only be used in CFA and not in our standalone uHeapLmmm allocator as these routines use some features that are only provided by CFA and not by C. It makes the allocator even more usable to the programmers.
+CFA provides the liberty to know the returned type of a call to the allocator. So, mainly in these added routines, we removed the object size parameter from the routine as allocator can calculate the size of the object from the returned type.
+
+\subsubsection T * malloc( void )
+This malloc is a simplified polymorphic form of defualt malloc (FIX ME: cite malloc). It does not take any parameter as compared to default malloc that takes one parameter.
+\paragraph{Usage}
+This malloc takes no parameters.
+It returns a dynamic object of the size of type T. On failure, it return NULL pointer.
+
+\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
+dim: required number of objects in the array.
+\end{itemize}
+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 )
+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
+dim: required number of objects in the array.
+\end{itemize}
+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 )
+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
+ptr: address of the old object.
+\item
+size: the required size of the new object.
+\end{itemize}
+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 )
+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
+ptr: address of the old object.
+\item
+size: the required size of the new object.
+\end{itemize}
+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 )
+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
+align: the required alignment of the dynamic object.
+\end{itemize}
+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 )
+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
+align: required alignment of the dynamic array.
+\item
+dim: required number of objects in the array.
+\end{itemize}
+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  )
+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
+align: required alignment of the dynamic array.
+\item
+dim: required number of objects in the array.
+\end{itemize}
+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.
+\begin{itemize}
+\item
+align: required alignment of the dynamic object.
+\end{itemize}
+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.
+\begin{itemize}
+\item
+ptr: variable address to store the address of the allocated object.
+\item
+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.
+
+\subsubsection T * valloc( void )
+This valloc is a simplified polymorphic form of defualt valloc (FIX ME: cite valloc). It takes no parameters as compared to the default valloc that takes one parameter.
+\paragraph{Usage}
+valloc takes no parameters.
+It returns a dynamic object of the size of type T that is aligned to the page size. On failure, it return NULL pointer.
+
+\subsubsection T * pvalloc( void )
+This pcvalloc is a simplified polymorphic form of defualt pcvalloc (FIX ME: cite pcvalloc). It takes no parameters as compared to the default pcvalloc that takes one parameter.
+\paragraph{Usage}
+pvalloc takes no parameters.
+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}
-Why did we need it?
-The added benefits.
+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
+Routine Name: alloc interfce frees programmers from remmebring different routine names for different kind of dynamic allocations.
+\item
+Parametre Positions: alloc interface frees programmers from remembering parameter postions in call to routines.
+\item
+Object Size: alloc interface does not require programmer to mention the object size as CFA allows allocator to determince the object size from returned type of alloc call.
+\end{itemize}
+
+Alloc interface uses polymorphism, backtick routines (FIX ME: cite backtick) and ttype parameters of CFA (FIX ME: cite ttype) to provide a very simple dynamic memory allocation interface to the programmers. The new interfece has just one routine name alloc that can be used to perform a wide range of dynamic allocations. The parameters use backtick functions to provide a similar-to named parameters feature for our alloc interface so that programmers do not have to remember parameter positions in alloc call except the position of dimension (dim) parameter.
+
+\subsubsection{Routine: T * alloc( ... )}
+Call to alloc wihout any parameter returns one object of size of type T allocated dynamically.
+Only the dimension (dim) parameter for array allocation has the fixed position in the alloc routine. If programmer wants to allocate an array of objects that the required number of members in the array has to be given as the first parameter to the alloc routine.
+alocc routine accepts six kinds of arguments. Using different combinations of tha parameters, different kind of allocations can be performed. Any combincation of parameters can be used together except `realloc and `resize that should not be used simultanously in one call to routine as it creates ambiguity about whether to reallocate or resize a currently allocated dynamic object. If both `resize and `realloc are used in a call to alloc then the latter one will take effect or unexpected resulted might be produced.
+
+\paragraph{Dim}
+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.
+
+Example: int a = alloc( 5 )
+This call will return a dynamic array of five integers.
+
+\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.
+
+Example: int b = alloc( 5 , 64`align )
+This call will return a dynamic array of five integers. It will align the allocated object to 64.
+
+\paragraph{Fill}
+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
+char: A char can be passed with `fill to fill the whole dynamic allocation with the given char recursively till the end of required allocation.
+\item
+Object of returned type: An object of type of returned type can be passed with `fill to fill the whole dynamic allocation with the given object recursively till the end of required allocation.
+\item
+Dynamic object of returned type: A dynamic object of type of returned type can be passed with `fill to fill the dynamic allocation with the given dynamic object. In this case, the allocated memory is not filled recursively till the end of allocation. The filling happen untill the end object passed to `fill or the end of requested allocation reaches.
+\end{itemize}
+
+Example: int b = alloc( 5 , 'a'`fill )
+This call will return a dynamic array of five integers. It will fill the allocated object with character 'a' recursively till the end of requested allocation size.
+
+Example: int b = alloc( 5 , 4`fill )
+This call will return a dynamic array of five integers. It will fill the allocated object with integer 4 recursively till the end of requested allocation size.
+
+Example: int b = alloc( 5 , a`fill ) where a is a pointer of int type
+This call will return a dynamic array of five integers. It will copy data in a to the returned object non-recursively untill end of a or the newly allocated object is reached.
+
+\paragraph{Resize}
+This parameter is position-free and uses a backtick routine resize (`resize). It represents the old dynamic object (oaddr) that the programmer wants to
+\begin{itemize}
+\item
+resize to a new size.
+\item
+realign to a new alignment
+\item
+fill with something.
+\end{itemize}
+The data in old dynamic object will not be preserved in the new object. The type of object passed to `resize and the returned type of alloc call can be different.
+
+Example: int b = alloc( 5 , a`resize )
+This call will resize object a to a dynamic array that can contain 5 integers.
+
+Example: int b = alloc( 5 , a`resize , 32`align )
+This call will resize object a to a dynamic array that can contain 5 integers. The returned object will also be aligned to 32.
+
+Example: int b = alloc( 5 , a`resize , 32`align , 2`fill)
+This call will resize object a to a dynamic array that can contain 5 integers. The returned object will also be aligned to 32 and will be filled with 2.
+
+\paragraph{Realloc}
+This parameter is position-free and uses a backtick routine realloc (`realloc). It represents the old dynamic object (oaddr) that the programmer wants to
+\begin{itemize}
+\item
+realloc to a new size.
+\item
+realign to a new alignment
+\item
+fill with something.
+\end{itemize}
+The data in old dynamic object will be preserved in the new object. The type of object passed to `realloc and the returned type of alloc call cannot be different.
+
+Example: int b = alloc( 5 , a`realloc )
+This call will realloc object a to a dynamic array that can contain 5 integers.
+
+Example: int b = alloc( 5 , a`realloc , 32`align )
+This call will realloc object a to a dynamic array that can contain 5 integers. The returned object will also be aligned to 32.
+
+Example: int b = alloc( 5 , a`realloc , 32`align , 2`fill)
+This call will resize object a to a dynamic array that can contain 5 integers. The returned object will also be aligned to 32. The extra space after copying data of a to the returned object will be filled with 2.
Index: doc/theses/mubeen_zulfiqar_MMath/benchmarks.tex
===================================================================
--- doc/theses/mubeen_zulfiqar_MMath/benchmarks.tex	(revision 0640189e9e66678dab5d7f80793687fa10ff24c3)
+++ doc/theses/mubeen_zulfiqar_MMath/benchmarks.tex	(revision 5541ea3d192c866061ad89a360daabc4e33e3429)
@@ -149,5 +149,5 @@
 *** FIX ME: Insert a figure of above benchmark with description
 
-\subsubsection{Relevant Knobs}
+\paragrpah{Relevant Knobs}
 *** FIX ME: Insert Relevant Knobs
 
@@ -202,39 +202,2 @@
 \paragraph{Relevant Knobs}
 *** FIX ME: Insert Relevant Knobs
-
-\section{Results}
-*** FIX ME: add configuration details of memory allocators
-
-\subsection{Memory Benchmark}
-
-\subsubsection{Relevant Knobs}
-
-\subsection{Speed Benchmark}
-
-\subsubsection{Speed Time}
-
-\paragraph{Relevant Knobs}
-
-\subsubsection{Speed Workload}
-
-\paragraph{Relevant Knobs}
-
-\subsection{Cache Scratch}
-
-\subsubsection{Cache Scratch Time}
-
-\paragraph{Relevant Knobs}
-
-\subsubsection{Cache Scratch Layout}
-
-\paragraph{Relevant Knobs}
-
-\subsection{Cache Thrash}
-
-\subsubsection{Cache Thrash Time}
-
-\paragraph{Relevant Knobs}
-
-\subsubsection{Cache Thrash Layout}
-
-\paragraph{Relevant Knobs}
Index: doc/theses/mubeen_zulfiqar_MMath/intro.tex
===================================================================
--- doc/theses/mubeen_zulfiqar_MMath/intro.tex	(revision 0640189e9e66678dab5d7f80793687fa10ff24c3)
+++ doc/theses/mubeen_zulfiqar_MMath/intro.tex	(revision 5541ea3d192c866061ad89a360daabc4e33e3429)
@@ -24,2 +24,90 @@
 \noindent
 ====================
+
+\section{Introduction}
+Dynamic memory allocation and management is one of the core features of C. It gives programmer the freedom to allocate, free, use, and manage dynamic memory himself. The programmer is not given the complete control of the dynamic memory management instead an interface of memory allocator is given to the progrmmer that can be used to allocate/free dynamic memory for the application's use.
+
+Memory allocator is a layer between thr programmer and the system. Allocator gets dynamic memory from the system in heap/mmap area of application storage and manages it for programmer's use.
+
+GNU C Library (FIX ME: cite this) provides an interchangeable memory allocator that can be replaced with a custom memory allocator that supports required features and fulfills application's custom needs. It also allows others to innovate in memory allocation and design their own memory allocator. GNU C Library has set guidelines that should be followed when designing a standalone memory allocator. GNU C Library requires new memory allocators to have atlease following set of functions in their allocator's interface:
+
+\begin{itemize}
+\item
+malloc: it allocates and returns a chunk of dynamic memory of requested size (FIX ME: cite man page).
+\item
+calloc: it allocates and returns an array in dynamic memory of requested size (FIX ME: cite man page).
+\item
+realloc: it reallocates and returns an already allocated chunk of dynamic memory to a new size (FIX ME: cite man page).
+\item
+free: it frees an already allocated piece of dynamic memory (FIX ME: cite man page).
+\end{itemize}
+
+In addition to the above functions, GNU C Library also provides some more functions to increase the usability of the dynamic memory allocator. Most standalone allocators also provide all or some of the above additional functions.
+
+\begin{itemize}
+\item
+aligned_alloc
+\item
+malloc_usable_size
+\item
+memalign
+\item
+posix_memalign
+\item
+pvalloc
+\item
+valloc
+\end{itemize}
+
+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}
+Our research objective in this thesis is to:
+
+\begin{itemize}
+\item
+Design a lightweight concurrent memory allocator with added features and usability that are currently not present in the other memory allocators.
+\item
+Design a suite of benchmarks to evalute multiple aspects of a memory allocator.
+\end{itemize}
+
+\section{An outline of the thesis}
+LAST FIX ME: add outline at the end
Index: doc/theses/mubeen_zulfiqar_MMath/performance.tex
===================================================================
--- doc/theses/mubeen_zulfiqar_MMath/performance.tex	(revision 0640189e9e66678dab5d7f80793687fa10ff24c3)
+++ doc/theses/mubeen_zulfiqar_MMath/performance.tex	(revision 5541ea3d192c866061ad89a360daabc4e33e3429)
@@ -1,1 +1,83 @@
 \chapter{Performance}
+
+\noindent
+====================
+
+Writing Points:
+\begin{itemize}
+\item
+Machine Specification
+\item
+Allocators and their details
+\item
+Benchmarks and their details
+\item
+Results
+\end{itemize}
+
+\noindent
+====================
+
+\section{Memory Allocators}
+For these experiments, we used 7 memory allocators excluding our standalone memory allocator uHeapLmmm.
+
+\begin{tabularx}{0.8\textwidth} {
+	| >{\raggedright\arraybackslash}X
+	| >{\centering\arraybackslash}X
+	| >{\raggedleft\arraybackslash}X |
+}
+\hline
+Memory Allocator & Version     & Configurations \\
+\hline
+dl               &             &  \\
+\hline
+hoard            &             &  \\
+\hline
+je               &             &  \\
+\hline
+pt3              &             &  \\
+\hline
+rp               &             &  \\
+\hline
+tbb              &             &  \\
+\hline
+tc               &             &  \\
+\end{tabularx}
+(FIX ME: complete table)
+
+\section{Experiment Environment}
+We conducted these experiments ... (FIX ME: what machine and which specifications to add).
+
+We used our micro becnhmark suite (FIX ME: cite mbench) to evaluate other memory allocators (FIX ME: cite above memory allocators) and our uHeapLmmm.
+
+\section{Results}
+
+\subsection{Memory Benchmark}
+FIX ME: add experiment, knobs, graphs, and description
+
+\subsection{Speed Benchmark}
+FIX ME: add experiment, knobs, graphs, and description
+
+\subsubsection{Speed Time}
+FIX ME: add experiment, knobs, graphs, and description
+
+\subsubsection{Speed Workload}
+FIX ME: add experiment, knobs, graphs, and description
+
+\subsection{Cache Scratch}
+FIX ME: add experiment, knobs, graphs, and description
+
+\subsubsection{Cache Scratch Time}
+FIX ME: add experiment, knobs, graphs, and description
+
+\subsubsection{Cache Scratch Layout}
+FIX ME: add experiment, knobs, graphs, and description
+
+\subsection{Cache Thrash}
+FIX ME: add experiment, knobs, graphs, and description
+
+\subsubsection{Cache Thrash Time}
+FIX ME: add experiment, knobs, graphs, and description
+
+\subsubsection{Cache Thrash Layout}
+FIX ME: add experiment, knobs, graphs, and description
Index: driver/cc1.cc
===================================================================
--- driver/cc1.cc	(revision 0640189e9e66678dab5d7f80793687fa10ff24c3)
+++ driver/cc1.cc	(revision 5541ea3d192c866061ad89a360daabc4e33e3429)
@@ -10,6 +10,6 @@
 // Created On       : Fri Aug 26 14:23:51 2005
 // Last Modified By : Peter A. Buhr
-// Last Modified On : Wed Jul 14 15:42:08 2021
-// Update Count     : 418
+// Last Modified On : Wed Jul 21 09:46:24 2021
+// Update Count     : 419
 //
 
@@ -587,5 +587,5 @@
 		Stage2( argc, argv );
 	} else {
-		cerr << "Usage: " << argv[0] << " input-file [output-file] [options]" << endl;
+		cerr << "Usage: " << argv[0] << " [-E input-file [output-file] ] | [-fpreprocessed input-file output-file] [options]" << endl;
 		exit( EXIT_FAILURE );
 	} // if
Index: libcfa/prelude/builtins.c
===================================================================
--- libcfa/prelude/builtins.c	(revision 0640189e9e66678dab5d7f80793687fa10ff24c3)
+++ libcfa/prelude/builtins.c	(revision 5541ea3d192c866061ad89a360daabc4e33e3429)
@@ -10,6 +10,6 @@
 // Created On       : Fri Jul 21 16:21:03 2017
 // Last Modified By : Peter A. Buhr
-// Last Modified On : Tue Apr 13 17:26:32 2021
-// Update Count     : 117
+// Last Modified On : Wed Jul 21 13:31:34 2021
+// Update Count     : 129
 //
 
@@ -77,19 +77,21 @@
 // implicit increment, decrement if += defined, and implicit not if != defined
 
+// C11 reference manual Section 6.5.16 (page101): "An assignment expression has the value of the left operand after the
+// assignment, but is not an lvalue." Hence, return a value not a reference.
 static inline {
-	forall( DT & | { DT & ?+=?( DT &, one_t ); } )
-	DT & ++?( DT & x ) { return x += 1; }
+	forall( T | { T ?+=?( T &, one_t ); } )
+	T ++?( T & x ) { return x += 1; }
 
-	forall( DT & | sized(DT) | { void ?{}( DT &, DT ); void ^?{}( DT & ); DT & ?+=?( DT &, one_t ); } )
-	DT & ?++( DT & x ) { DT tmp = x; x += 1; return tmp; }
+	forall( T | { T ?+=?( T &, one_t ); } )
+	T ?++( T & x ) { T tmp = x; x += 1; return tmp; }
 
-	forall( DT & | { DT & ?-=?( DT &, one_t ); } )
-	DT & --?( DT & x ) { return x -= 1; }
+	forall( T | { T ?-=?( T &, one_t ); } )
+	T --?( T & x ) { return x -= 1; }
 
-	forall( DT & | sized(DT) | { void ?{}( DT &, DT ); void ^?{}( DT & ); DT & ?-=?( DT &, one_t ); } )
-	DT & ?--( DT & x ) { DT tmp = x; x -= 1; return tmp; }
+	forall( T | { T ?-=?( T &, one_t ); } )
+	T ?--( T & x ) { T tmp = x; x -= 1; return tmp; }
 
-	forall( DT & | { int ?!=?( const DT &, zero_t ); } )
-	int !?( const DT & x ) { return !( x != 0 ); }
+	forall( T | { int ?!=?( T, zero_t ); } )
+	int !?( T & x ) { return !( x != 0 ); }
 } // distribution
 
Index: libcfa/src/Makefile.am
===================================================================
--- libcfa/src/Makefile.am	(revision 0640189e9e66678dab5d7f80793687fa10ff24c3)
+++ libcfa/src/Makefile.am	(revision 5541ea3d192c866061ad89a360daabc4e33e3429)
@@ -11,6 +11,6 @@
 ## Created On       : Sun May 31 08:54:01 2015
 ## Last Modified By : Peter A. Buhr
-## Last Modified On : Sat Apr 24 09:09:56 2021
-## Update Count     : 254
+## Last Modified On : Fri Jul 16 16:00:40 2021
+## Update Count     : 255
 ###############################################################################
 
@@ -45,4 +45,5 @@
 	exception.h \
 	gmp.hfa \
+	math.trait.hfa \
 	math.hfa \
 	time_t.hfa \
Index: libcfa/src/concurrency/locks.cfa
===================================================================
--- libcfa/src/concurrency/locks.cfa	(revision 0640189e9e66678dab5d7f80793687fa10ff24c3)
+++ libcfa/src/concurrency/locks.cfa	(revision 5541ea3d192c866061ad89a360daabc4e33e3429)
@@ -120,5 +120,5 @@
 	owner = t;
 	recursion_count = ( t ? 1 : 0 );
-	wait_count--;
+	if ( t ) wait_count--;
 	unpark( t );
 }
Index: libcfa/src/fstream.cfa
===================================================================
--- libcfa/src/fstream.cfa	(revision 0640189e9e66678dab5d7f80793687fa10ff24c3)
+++ libcfa/src/fstream.cfa	(revision 5541ea3d192c866061ad89a360daabc4e33e3429)
@@ -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:53 2021
-// Update Count     : 445
+// Last Modified On : Thu Jul 29 22:34:10 2021
+// Update Count     : 454
 //
 
@@ -142,5 +142,6 @@
 
 	if ( fclose( (FILE *)(os.file$) ) == EOF ) {
-		abort | IO_MSG "close output" | nl | strerror( errno );
+		throw (Close_Failure){ os };
+		// abort | IO_MSG "close output" | nl | strerror( errno );
 	} // if
 	os.file$ = 0p;
@@ -149,9 +150,11 @@
 ofstream & write( ofstream & os, const char data[], size_t size ) {
 	if ( fail( os ) ) {
-		abort | IO_MSG "attempt write I/O on failed stream";
+		throw (Write_Failure){ os };
+		// abort | IO_MSG "attempt write I/O on failed stream";
 	} // if
 
 	if ( fwrite( data, 1, size, (FILE *)(os.file$) ) != size ) {
-		abort | IO_MSG "write" | nl | strerror( errno );
+		throw (Write_Failure){ os };
+		// abort | IO_MSG "write" | nl | strerror( errno );
 	} // if
 	return os;
@@ -277,5 +280,6 @@
 
 	if ( fclose( (FILE *)(is.file$) ) == EOF ) {
-		abort | IO_MSG "close input" | nl | strerror( errno );
+		throw (Close_Failure){ is };
+		// abort | IO_MSG "close input" | nl | strerror( errno );
 	} // if
 	is.file$ = 0p;
@@ -284,9 +288,11 @@
 ifstream & read( ifstream & is, char data[], size_t size ) {
 	if ( fail( is ) ) {
-		abort | IO_MSG "attempt read I/O on failed stream";
+		throw (Read_Failure){ is };
+		// abort | IO_MSG "attempt read I/O on failed stream";
 	} // if
 
 	if ( fread( data, size, 1, (FILE *)(is.file$) ) == 0 ) {
-		abort | IO_MSG "read" | nl | strerror( errno );
+		throw (Read_Failure){ is };
+		// abort | IO_MSG "read" | nl | strerror( errno );
 	} // if
 	return is;
@@ -338,21 +344,74 @@
 
 
-EHM_VIRTUAL_TABLE(Open_Failure, Open_Failure_main_table);
+static vtable(Open_Failure) Open_Failure_vt;
+
+// exception I/O constructors
 void ?{}( Open_Failure & this, ofstream & ostream ) {
-	this.virtual_table = &Open_Failure_main_table;
+	this.virtual_table = &Open_Failure_vt;
 	this.ostream = &ostream;
 	this.tag = 1;
-}
+} // ?{}
+
 void ?{}( Open_Failure & this, ifstream & istream ) {
-	this.virtual_table = &Open_Failure_main_table;
+	this.virtual_table = &Open_Failure_vt;
 	this.istream = &istream;
 	this.tag = 0;
-}
-void throwOpen_Failure( ofstream & ostream ) {
-	Open_Failure exc = { ostream };
-}
-void throwOpen_Failure( ifstream & istream ) {
-	Open_Failure exc = { istream };
-}
+} // ?{}
+
+
+static vtable(Close_Failure) Close_Failure_vt;
+
+// 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;
+} // ?{}
+
+
+static vtable(Write_Failure) Write_Failure_vt;
+
+// 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;
+} // ?{}
+
+
+static vtable(Read_Failure) Read_Failure_vt;
+
+// 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 throwOpen_Failure( ofstream & ostream ) {
+// 	Open_Failure exc = { ostream };
+// }
+
+// void throwOpen_Failure( ifstream & istream ) {
+// 	Open_Failure exc = { istream };
+// }
 
 // Local Variables: //
Index: libcfa/src/fstream.hfa
===================================================================
--- libcfa/src/fstream.hfa	(revision 0640189e9e66678dab5d7f80793687fa10ff24c3)
+++ libcfa/src/fstream.hfa	(revision 5541ea3d192c866061ad89a360daabc4e33e3429)
@@ -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:57 2021
-// Update Count     : 230
+// Last Modified On : Wed Jul 28 07:35:50 2021
+// Update Count     : 234
 //
 
@@ -148,15 +148,51 @@
 
 
-EHM_EXCEPTION(Open_Failure)(
-	union {
-		ofstream * ostream;
-		ifstream * istream;
-	};
-	// TEMPORARY: need polymorphic exceptions
-	int tag;											// 1 => ostream; 0 => istream
-);
+exception Open_Failure {
+	union {
+		ofstream * ostream;
+		ifstream * istream;
+	};
+	// TEMPORARY: need polymorphic exceptions
+	int tag;											// 1 => ostream; 0 => istream
+};
 
 void ?{}( Open_Failure & this, ofstream & );
 void ?{}( Open_Failure & this, ifstream & );
+
+exception Close_Failure {
+	union {
+		ofstream * ostream;
+		ifstream * istream;
+	};
+	// TEMPORARY: need polymorphic exceptions
+	int tag;											// 1 => ostream; 0 => istream
+};
+
+void ?{}( Close_Failure & this, ofstream & );
+void ?{}( Close_Failure & this, ifstream & );
+
+exception Write_Failure {
+	union {
+		ofstream * ostream;
+		ifstream * istream;
+	};
+	// TEMPORARY: need polymorphic exceptions
+	int tag;											// 1 => ostream; 0 => istream
+};
+
+void ?{}( Write_Failure & this, ofstream & );
+void ?{}( Write_Failure & this, ifstream & );
+
+exception Read_Failure {
+	union {
+		ofstream * ostream;
+		ifstream * istream;
+	};
+	// TEMPORARY: need polymorphic exceptions
+	int tag;											// 1 => ostream; 0 => istream
+};
+
+void ?{}( Read_Failure & this, ofstream & );
+void ?{}( Read_Failure & this, ifstream & );
 
 // Local Variables: //
Index: libcfa/src/math.trait.hfa
===================================================================
--- libcfa/src/math.trait.hfa	(revision 5541ea3d192c866061ad89a360daabc4e33e3429)
+++ libcfa/src/math.trait.hfa	(revision 5541ea3d192c866061ad89a360daabc4e33e3429)
@@ -0,0 +1,69 @@
+//
+// 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.
+//
+// math.trait.hfa -- 
+//
+// Author           : Peter A. Buhr
+// Created On       : Fri Jul 16 15:40:52 2021
+// Last Modified By : Peter A. Buhr
+// Last Modified On : Tue Jul 20 17:47:19 2021
+// Update Count     : 19
+// 
+
+#pragma once
+
+trait Not( T ) {
+	void ?{}( T &, zero_t );
+	int !?( T );
+}; // Not
+
+trait Equality( T | Not( T ) ) {
+	int ?==?( T, T );
+	int ?!=?( T, T );
+}; // Equality
+
+trait Relational( T | Equality( T ) ) {
+	int ?<?( T, T );
+	int ?<=?( T, T );
+	int ?>?( T, T );
+	int ?>=?( T, T );
+}; // Relational
+
+trait Signed( T ) {
+	T +?( T );
+	T -?( T );
+	T abs( T );
+}; // Signed
+
+trait Additive( T | Signed( T ) ) {
+	T ?+?( T, T );
+	T ?-?( T, T );
+	T ?+=?( T &, T );
+	T ?-=?( T &, T );
+}; // Additive
+
+trait Incdec( T | Additive( T ) ) {
+	void ?{}( T &, one_t );
+	// T ?++( T & );
+	// T ++?( T &);
+	// T ?--( T & );
+	// T --?( T & );
+}; // Incdec
+
+trait Multiplicative( T | Incdec( T ) ) {
+	T ?*?( T, T );
+	T ?/?( T, T );
+	T ?%?( T, T );
+	T ?/=?( T &, T );
+}; // Multiplicative
+
+trait Arithmetic( T | Relational( T ) | Multiplicative( T ) ) {
+}; // Arithmetic
+
+// Local Variables: //
+// mode: c //
+// tab-width: 4 //
+// End: //
Index: libcfa/src/rational.cfa
===================================================================
--- libcfa/src/rational.cfa	(revision 0640189e9e66678dab5d7f80793687fa10ff24c3)
+++ libcfa/src/rational.cfa	(revision 5541ea3d192c866061ad89a360daabc4e33e3429)
@@ -10,6 +10,6 @@
 // Created On       : Wed Apr  6 17:54:28 2016
 // Last Modified By : Peter A. Buhr
-// Last Modified On : Sat Feb  8 17:56:36 2020
-// Update Count     : 187
+// Last Modified On : Tue Jul 20 16:30:06 2021
+// Update Count     : 193
 //
 
@@ -18,13 +18,13 @@
 #include "stdlib.hfa"
 
-forall( RationalImpl | arithmetic( RationalImpl ) ) {
+forall( T | Arithmetic( T ) ) {
 	// helper routines
 
 	// Calculate greatest common denominator of two numbers, the first of which may be negative. Used to reduce
 	// rationals.  alternative: https://en.wikipedia.org/wiki/Binary_GCD_algorithm
-	static RationalImpl gcd( RationalImpl a, RationalImpl b ) {
+	static T gcd( T a, T b ) {
 		for ( ;; ) {									// Euclid's algorithm
-			RationalImpl r = a % b;
-		  if ( r == (RationalImpl){0} ) break;
+			T r = a % b;
+		  if ( r == (T){0} ) break;
 			a = b;
 			b = r;
@@ -33,9 +33,9 @@
 	} // gcd
 
-	static RationalImpl simplify( RationalImpl & n, RationalImpl & d ) {
-		if ( d == (RationalImpl){0} ) {
+	static T simplify( T & n, T & d ) {
+		if ( d == (T){0} ) {
 			abort | "Invalid rational number construction: denominator cannot be equal to 0.";
 		} // exit
-		if ( d < (RationalImpl){0} ) { d = -d; n = -n; } // move sign to numerator
+		if ( d < (T){0} ) { d = -d; n = -n; } // move sign to numerator
 		return gcd( abs( n ), d );						// simplify
 	} // Rationalnumber::simplify
@@ -43,36 +43,36 @@
 	// constructors
 
-	void ?{}( Rational(RationalImpl) & r ) {
-		r{ (RationalImpl){0}, (RationalImpl){1} };
-	} // rational
-
-	void ?{}( Rational(RationalImpl) & r, RationalImpl n ) {
-		r{ n, (RationalImpl){1} };
-	} // rational
-
-	void ?{}( Rational(RationalImpl) & r, RationalImpl n, RationalImpl d ) {
-		RationalImpl t = simplify( n, d );				// simplify
+	void ?{}( Rational(T) & r, zero_t ) {
+		r{ (T){0}, (T){1} };
+	} // rational
+
+	void ?{}( Rational(T) & r, one_t ) {
+		r{ (T){1}, (T){1} };
+	} // rational
+
+	void ?{}( Rational(T) & r ) {
+		r{ (T){0}, (T){1} };
+	} // rational
+
+	void ?{}( Rational(T) & r, T n ) {
+		r{ n, (T){1} };
+	} // rational
+
+	void ?{}( Rational(T) & r, T n, T d ) {
+		T t = simplify( n, d );				// simplify
 		r.[numerator, denominator] = [n / t, d / t];
 	} // rational
 
-	void ?{}( Rational(RationalImpl) & r, zero_t ) {
-		r{ (RationalImpl){0}, (RationalImpl){1} };
-	} // rational
-
-	void ?{}( Rational(RationalImpl) & r, one_t ) {
-		r{ (RationalImpl){1}, (RationalImpl){1} };
-	} // rational
-
 	// getter for numerator/denominator
 
-	RationalImpl numerator( Rational(RationalImpl) r ) {
+	T numerator( Rational(T) r ) {
 		return r.numerator;
 	} // numerator
 
-	RationalImpl denominator( Rational(RationalImpl) r ) {
+	T denominator( Rational(T) r ) {
 		return r.denominator;
 	} // denominator
 
-	[ RationalImpl, RationalImpl ] ?=?( & [ RationalImpl, RationalImpl ] dest, Rational(RationalImpl) src ) {
+	[ T, T ] ?=?( & [ T, T ] dest, Rational(T) src ) {
 		return dest = src.[ numerator, denominator ];
 	} // ?=?
@@ -80,14 +80,14 @@
 	// setter for numerator/denominator
 
-	RationalImpl numerator( Rational(RationalImpl) r, RationalImpl n ) {
-		RationalImpl prev = r.numerator;
-		RationalImpl t = gcd( abs( n ), r.denominator ); // simplify
+	T numerator( Rational(T) r, T n ) {
+		T prev = r.numerator;
+		T t = gcd( abs( n ), r.denominator ); // simplify
 		r.[numerator, denominator] = [n / t, r.denominator / t];
 		return prev;
 	} // numerator
 
-	RationalImpl denominator( Rational(RationalImpl) r, RationalImpl d ) {
-		RationalImpl prev = r.denominator;
-		RationalImpl t = simplify( r.numerator, d );	// simplify
+	T denominator( Rational(T) r, T d ) {
+		T prev = r.denominator;
+		T t = simplify( r.numerator, d );	// simplify
 		r.[numerator, denominator] = [r.numerator / t, d / t];
 		return prev;
@@ -96,25 +96,29 @@
 	// comparison
 
-	int ?==?( Rational(RationalImpl) l, Rational(RationalImpl) r ) {
+	int ?==?( Rational(T) l, Rational(T) r ) {
 		return l.numerator * r.denominator == l.denominator * r.numerator;
 	} // ?==?
 
-	int ?!=?( Rational(RationalImpl) l, Rational(RationalImpl) r ) {
+	int ?!=?( Rational(T) l, Rational(T) r ) {
 		return ! ( l == r );
 	} // ?!=?
 
-	int ?<?( Rational(RationalImpl) l, Rational(RationalImpl) r ) {
+	int ?!=?( Rational(T) l, zero_t ) {
+		return ! ( l == (Rational(T)){ 0 } );
+	} // ?!=?
+
+	int ?<?( Rational(T) l, Rational(T) r ) {
 		return l.numerator * r.denominator < l.denominator * r.numerator;
 	} // ?<?
 
-	int ?<=?( Rational(RationalImpl) l, Rational(RationalImpl) r ) {
+	int ?<=?( Rational(T) l, Rational(T) r ) {
 		return l.numerator * r.denominator <= l.denominator * r.numerator;
 	} // ?<=?
 
-	int ?>?( Rational(RationalImpl) l, Rational(RationalImpl) r ) {
+	int ?>?( Rational(T) l, Rational(T) r ) {
 		return ! ( l <= r );
 	} // ?>?
 
-	int ?>=?( Rational(RationalImpl) l, Rational(RationalImpl) r ) {
+	int ?>=?( Rational(T) l, Rational(T) r ) {
 		return ! ( l < r );
 	} // ?>=?
@@ -122,45 +126,73 @@
 	// arithmetic
 
-	Rational(RationalImpl) +?( Rational(RationalImpl) r ) {
-		return (Rational(RationalImpl)){ r.numerator, r.denominator };
+	Rational(T) +?( Rational(T) r ) {
+		return (Rational(T)){ r.numerator, r.denominator };
 	} // +?
 
-	Rational(RationalImpl) -?( Rational(RationalImpl) r ) {
-		return (Rational(RationalImpl)){ -r.numerator, r.denominator };
+	Rational(T) -?( Rational(T) r ) {
+		return (Rational(T)){ -r.numerator, r.denominator };
 	} // -?
 
-	Rational(RationalImpl) ?+?( Rational(RationalImpl) l, Rational(RationalImpl) r ) {
+	Rational(T) ?+?( Rational(T) l, Rational(T) r ) {
 		if ( l.denominator == r.denominator ) {			// special case
-			return (Rational(RationalImpl)){ l.numerator + r.numerator, l.denominator };
+			return (Rational(T)){ l.numerator + r.numerator, l.denominator };
 		} else {
-			return (Rational(RationalImpl)){ l.numerator * r.denominator + l.denominator * r.numerator, l.denominator * r.denominator };
+			return (Rational(T)){ l.numerator * r.denominator + l.denominator * r.numerator, l.denominator * r.denominator };
 		} // if
 	} // ?+?
 
-	Rational(RationalImpl) ?-?( Rational(RationalImpl) l, Rational(RationalImpl) r ) {
+	Rational(T) ?+=?( Rational(T) & l, Rational(T) r ) {
+		l = l + r;
+		return l;
+	} // ?+?
+
+	Rational(T) ?+=?( Rational(T) & l, one_t ) {
+		l = l + (Rational(T)){ 1 };
+		return l;
+	} // ?+?
+
+	Rational(T) ?-?( Rational(T) l, Rational(T) r ) {
 		if ( l.denominator == r.denominator ) {			// special case
-			return (Rational(RationalImpl)){ l.numerator - r.numerator, l.denominator };
+			return (Rational(T)){ l.numerator - r.numerator, l.denominator };
 		} else {
-			return (Rational(RationalImpl)){ l.numerator * r.denominator - l.denominator * r.numerator, l.denominator * r.denominator };
+			return (Rational(T)){ l.numerator * r.denominator - l.denominator * r.numerator, l.denominator * r.denominator };
 		} // if
 	} // ?-?
 
-	Rational(RationalImpl) ?*?( Rational(RationalImpl) l, Rational(RationalImpl) r ) {
-		return (Rational(RationalImpl)){ l.numerator * r.numerator, l.denominator * r.denominator };
+	Rational(T) ?-=?( Rational(T) & l, Rational(T) r ) {
+		l = l - r;
+		return l;
+	} // ?-?
+
+	Rational(T) ?-=?( Rational(T) & l, one_t ) {
+		l = l - (Rational(T)){ 1 };
+		return l;
+	} // ?-?
+
+	Rational(T) ?*?( Rational(T) l, Rational(T) r ) {
+		return (Rational(T)){ l.numerator * r.numerator, l.denominator * r.denominator };
 	} // ?*?
 
-	Rational(RationalImpl) ?/?( Rational(RationalImpl) l, Rational(RationalImpl) r ) {
-		if ( r.numerator < (RationalImpl){0} ) {
+	Rational(T) ?*=?( Rational(T) & l, Rational(T) r ) {
+		return l = l * r;
+	} // ?*?
+
+	Rational(T) ?/?( Rational(T) l, Rational(T) r ) {
+		if ( r.numerator < (T){0} ) {
 			r.[numerator, denominator] = [-r.numerator, -r.denominator];
 		} // if
-		return (Rational(RationalImpl)){ l.numerator * r.denominator, l.denominator * r.numerator };
+		return (Rational(T)){ l.numerator * r.denominator, l.denominator * r.numerator };
 	} // ?/?
 
+	Rational(T) ?/=?( Rational(T) & l, Rational(T) r ) {
+		return l = l / r;
+	} // ?/?
+
 	// I/O
 
-	forall( istype & | istream( istype ) | { istype & ?|?( istype &, RationalImpl & ); } )
-	istype & ?|?( istype & is, Rational(RationalImpl) & r ) {
+	forall( istype & | istream( istype ) | { istype & ?|?( istype &, T & ); } )
+	istype & ?|?( istype & is, Rational(T) & r ) {
 		is | r.numerator | r.denominator;
-		RationalImpl t = simplify( r.numerator, r.denominator );
+		T t = simplify( r.numerator, r.denominator );
 		r.numerator /= t;
 		r.denominator /= t;
@@ -168,10 +200,10 @@
 	} // ?|?
 
-	forall( ostype & | ostream( ostype ) | { ostype & ?|?( ostype &, RationalImpl ); } ) {
-		ostype & ?|?( ostype & os, Rational(RationalImpl) r ) {
+	forall( ostype & | ostream( ostype ) | { ostype & ?|?( ostype &, T ); } ) {
+		ostype & ?|?( ostype & os, Rational(T) r ) {
 			return os | r.numerator | '/' | r.denominator;
 		} // ?|?
 
-		void ?|?( ostype & os, Rational(RationalImpl) r ) {
+		void ?|?( ostype & os, Rational(T) r ) {
 			(ostype &)(os | r); ends( os );
 		} // ?|?
@@ -179,30 +211,35 @@
 } // distribution
 
-forall( RationalImpl | arithmetic( RationalImpl ) | { RationalImpl ?\?( RationalImpl, unsigned long ); } )
-Rational(RationalImpl) ?\?( Rational(RationalImpl) x, long int y ) {
-	if ( y < 0 ) {
-		return (Rational(RationalImpl)){ x.denominator \ -y, x.numerator \ -y };
-	} else {
-		return (Rational(RationalImpl)){ x.numerator \ y, x.denominator \ y };
-	} // if
-}
+forall( T | Arithmetic( T ) | { T ?\?( T, unsigned long ); } ) {
+	Rational(T) ?\?( Rational(T) x, long int y ) {
+		if ( y < 0 ) {
+			return (Rational(T)){ x.denominator \ -y, x.numerator \ -y };
+		} else {
+			return (Rational(T)){ x.numerator \ y, x.denominator \ y };
+		} // if
+	} // ?\?
+
+	Rational(T) ?\=?( Rational(T) & x, long int y ) {
+		return x = x \ y;
+	} // ?\?
+} // distribution
 
 // conversion
 
-forall( RationalImpl | arithmetic( RationalImpl ) | { double convert( RationalImpl ); } )
-double widen( Rational(RationalImpl) r ) {
+forall( T | Arithmetic( T ) | { double convert( T ); } )
+double widen( Rational(T) r ) {
  	return convert( r.numerator ) / convert( r.denominator );
 } // widen
 
-forall( RationalImpl | arithmetic( RationalImpl ) | { double convert( RationalImpl ); RationalImpl convert( double ); } )
-Rational(RationalImpl) narrow( double f, RationalImpl md ) {
+forall( T | Arithmetic( T ) | { double convert( T ); T convert( double ); } )
+Rational(T) narrow( double f, T md ) {
 	// http://www.ics.uci.edu/~eppstein/numth/frap.c
-	if ( md <= (RationalImpl){1} ) {					// maximum fractional digits too small?
-		return (Rational(RationalImpl)){ convert( f ), (RationalImpl){1}}; // truncate fraction
+	if ( md <= (T){1} ) {					// maximum fractional digits too small?
+		return (Rational(T)){ convert( f ), (T){1}}; // truncate fraction
 	} // if
 
 	// continued fraction coefficients
-	RationalImpl m00 = {1}, m11 = { 1 }, m01 = { 0 }, m10 = { 0 };
-	RationalImpl ai, t;
+	T m00 = {1}, m11 = { 1 }, m01 = { 0 }, m10 = { 0 };
+	T ai, t;
 
 	// find terms until denom gets too big
@@ -221,5 +258,5 @@
 	  if ( f > (double)0x7FFFFFFF ) break;				// representation failure
 	} // for
-	return (Rational(RationalImpl)){ m00, m10 };
+	return (Rational(T)){ m00, m10 };
 } // narrow
 
Index: libcfa/src/rational.hfa
===================================================================
--- libcfa/src/rational.hfa	(revision 0640189e9e66678dab5d7f80793687fa10ff24c3)
+++ libcfa/src/rational.hfa	(revision 5541ea3d192c866061ad89a360daabc4e33e3429)
@@ -12,6 +12,6 @@
 // Created On       : Wed Apr  6 17:56:25 2016
 // Last Modified By : Peter A. Buhr
-// Last Modified On : Tue Mar 26 23:16:10 2019
-// Update Count     : 109
+// Last Modified On : Tue Jul 20 17:45:29 2021
+// Update Count     : 118
 //
 
@@ -19,91 +19,77 @@
 
 #include "iostream.hfa"
-
-trait scalar( T ) {
-};
-
-trait arithmetic( T | scalar( T ) ) {
-	int !?( T );
-	int ?==?( T, T );
-	int ?!=?( T, T );
-	int ?<?( T, T );
-	int ?<=?( T, T );
-	int ?>?( T, T );
-	int ?>=?( T, T );
-	void ?{}( T &, zero_t );
-	void ?{}( T &, one_t );
-	T +?( T );
-	T -?( T );
-	T ?+?( T, T );
-	T ?-?( T, T );
-	T ?*?( T, T );
-	T ?/?( T, T );
-	T ?%?( T, T );
-	T ?/=?( T &, T );
-	T abs( T );
-};
+#include "math.trait.hfa"								// Arithmetic
 
 // implementation
 
-forall( RationalImpl | arithmetic( RationalImpl ) ) {
+forall( T | Arithmetic( T ) ) {
 	struct Rational {
-		RationalImpl numerator, denominator;			// invariant: denominator > 0
+		T numerator, denominator;						// invariant: denominator > 0
 	}; // Rational
 
 	// constructors
 
-	void ?{}( Rational(RationalImpl) & r );
-	void ?{}( Rational(RationalImpl) & r, RationalImpl n );
-	void ?{}( Rational(RationalImpl) & r, RationalImpl n, RationalImpl d );
-	void ?{}( Rational(RationalImpl) & r, zero_t );
-	void ?{}( Rational(RationalImpl) & r, one_t );
+	void ?{}( Rational(T) & r );
+	void ?{}( Rational(T) & r, zero_t );
+	void ?{}( Rational(T) & r, one_t );
+	void ?{}( Rational(T) & r, T n );
+	void ?{}( Rational(T) & r, T n, T d );
 
 	// numerator/denominator getter
 
-	RationalImpl numerator( Rational(RationalImpl) r );
-	RationalImpl denominator( Rational(RationalImpl) r );
-	[ RationalImpl, RationalImpl ] ?=?( & [ RationalImpl, RationalImpl ] dest, Rational(RationalImpl) src );
+	T numerator( Rational(T) r );
+	T denominator( Rational(T) r );
+	[ T, T ] ?=?( & [ T, T ] dest, Rational(T) src );
 
 	// numerator/denominator setter
 
-	RationalImpl numerator( Rational(RationalImpl) r, RationalImpl n );
-	RationalImpl denominator( Rational(RationalImpl) r, RationalImpl d );
+	T numerator( Rational(T) r, T n );
+	T denominator( Rational(T) r, T d );
 
 	// comparison
 
-	int ?==?( Rational(RationalImpl) l, Rational(RationalImpl) r );
-	int ?!=?( Rational(RationalImpl) l, Rational(RationalImpl) r );
-	int ?<?( Rational(RationalImpl) l, Rational(RationalImpl) r );
-	int ?<=?( Rational(RationalImpl) l, Rational(RationalImpl) r );
-	int ?>?( Rational(RationalImpl) l, Rational(RationalImpl) r );
-	int ?>=?( Rational(RationalImpl) l, Rational(RationalImpl) r );
+	int ?==?( Rational(T) l, Rational(T) r );
+	int ?!=?( Rational(T) l, Rational(T) r );
+	int ?!=?( Rational(T) l, zero_t );					// => !
+	int ?<?( Rational(T) l, Rational(T) r );
+	int ?<=?( Rational(T) l, Rational(T) r );
+	int ?>?( Rational(T) l, Rational(T) r );
+	int ?>=?( Rational(T) l, Rational(T) r );
 
 	// arithmetic
 
-	Rational(RationalImpl) +?( Rational(RationalImpl) r );
-	Rational(RationalImpl) -?( Rational(RationalImpl) r );
-	Rational(RationalImpl) ?+?( Rational(RationalImpl) l, Rational(RationalImpl) r );
-	Rational(RationalImpl) ?-?( Rational(RationalImpl) l, Rational(RationalImpl) r );
-	Rational(RationalImpl) ?*?( Rational(RationalImpl) l, Rational(RationalImpl) r );
-	Rational(RationalImpl) ?/?( Rational(RationalImpl) l, Rational(RationalImpl) r );
+	Rational(T) +?( Rational(T) r );
+	Rational(T) -?( Rational(T) r );
+	Rational(T) ?+?( Rational(T) l, Rational(T) r );
+	Rational(T) ?+=?( Rational(T) & l, Rational(T) r );
+	Rational(T) ?+=?( Rational(T) & l, one_t );			// => ++?, ?++
+	Rational(T) ?-?( Rational(T) l, Rational(T) r );
+	Rational(T) ?-=?( Rational(T) & l, Rational(T) r );
+	Rational(T) ?-=?( Rational(T) & l, one_t );			// => --?, ?--
+	Rational(T) ?*?( Rational(T) l, Rational(T) r );
+	Rational(T) ?*=?( Rational(T) & l, Rational(T) r );
+	Rational(T) ?/?( Rational(T) l, Rational(T) r );
+	Rational(T) ?/=?( Rational(T) & l, Rational(T) r );
 
 	// I/O
-	forall( istype & | istream( istype ) | { istype & ?|?( istype &, RationalImpl & ); } )
-	istype & ?|?( istype &, Rational(RationalImpl) & );
+	forall( istype & | istream( istype ) | { istype & ?|?( istype &, T & ); } )
+	istype & ?|?( istype &, Rational(T) & );
 
-	forall( ostype & | ostream( ostype ) | { ostype & ?|?( ostype &, RationalImpl ); } ) {
-		ostype & ?|?( ostype &, Rational(RationalImpl) );
-		void ?|?( ostype &, Rational(RationalImpl) );
+	forall( ostype & | ostream( ostype ) | { ostype & ?|?( ostype &, T ); } ) {
+		ostype & ?|?( ostype &, Rational(T) );
+		void ?|?( ostype &, Rational(T) );
 	} // distribution
 } // distribution
 
-forall( RationalImpl | arithmetic( RationalImpl ) |{RationalImpl ?\?( RationalImpl, unsigned long );} )
-Rational(RationalImpl) ?\?( Rational(RationalImpl) x, long int y );
+forall( T | Arithmetic( T ) | { T ?\?( T, unsigned long ); } ) {
+	Rational(T) ?\?( Rational(T) x, long int y );
+	Rational(T) ?\=?( Rational(T) & x, long int y );
+} // distribution
 
 // conversion
-forall( RationalImpl | arithmetic( RationalImpl ) | { double convert( RationalImpl ); } )
-double widen( Rational(RationalImpl) r );
-forall( RationalImpl | arithmetic( RationalImpl ) | { double convert( RationalImpl );  RationalImpl convert( double );} )
-Rational(RationalImpl) narrow( double f, RationalImpl md );
+forall( T | Arithmetic( T ) | { double convert( T ); } )
+double widen( Rational(T) r );
+forall( T | Arithmetic( T ) | { double convert( T );  T convert( double );} )
+Rational(T) narrow( double f, T md );
 
 // Local Variables: //
Index: src/CompilationState.cc
===================================================================
--- src/CompilationState.cc	(revision 0640189e9e66678dab5d7f80793687fa10ff24c3)
+++ src/CompilationState.cc	(revision 5541ea3d192c866061ad89a360daabc4e33e3429)
@@ -9,7 +9,7 @@
 // Author           : Rob Schluntz
 // Created On       : Mon Ju1 30 10:47:01 2018
-// Last Modified By : Peter A. Buhr
-// Last Modified On : Fri May  3 13:45:23 2019
-// Update Count     : 4
+// Last Modified By : Henry Xue
+// Last Modified On : Tue Jul 20 04:27:35 2021
+// Update Count     : 5
 //
 
@@ -23,4 +23,5 @@
 	ctorinitp = false,
 	declstatsp = false,
+	exdeclp = false,
 	exprp = false,
 	expraltp = false,
Index: src/CompilationState.h
===================================================================
--- src/CompilationState.h	(revision 0640189e9e66678dab5d7f80793687fa10ff24c3)
+++ src/CompilationState.h	(revision 5541ea3d192c866061ad89a360daabc4e33e3429)
@@ -9,7 +9,7 @@
 // Author           : Rob Schluntz
 // Created On       : Mon Ju1 30 10:47:01 2018
-// Last Modified By : Peter A. Buhr
-// Last Modified On : Fri May  3 13:43:21 2019
-// Update Count     : 4
+// Last Modified By : Henry Xue
+// Last Modified On : Tue Jul 20 04:27:35 2021
+// Update Count     : 5
 //
 
@@ -22,4 +22,5 @@
 	ctorinitp,
 	declstatsp,
+	exdeclp,
 	exprp,
 	expraltp,
Index: src/ControlStruct/ExceptDecl.cc
===================================================================
--- src/ControlStruct/ExceptDecl.cc	(revision 5541ea3d192c866061ad89a360daabc4e33e3429)
+++ src/ControlStruct/ExceptDecl.cc	(revision 5541ea3d192c866061ad89a360daabc4e33e3429)
@@ -0,0 +1,464 @@
+//
+// 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.
+//
+// ExceptDecl.cc --
+//
+// Author           : Henry Xue
+// Created On       : Tue Jul 20 04:10:50 2021
+// Last Modified By : Henry Xue
+// Last Modified On : Tue Aug 03 10:42:26 2021
+// Update Count     : 4
+//
+
+#include "ExceptDecl.h"
+
+#include <cassert>               // for assert
+#include <string>                // for string
+#include <sstream>               // for stringstream
+
+#include "Common/PassVisitor.h"  // for PassVisitor
+#include "Common/utility.h"      // for cloneAll
+#include "SynTree/Mutator.h"     // for mutateAll
+#include "Virtual/Tables.h"      // for helpers
+
+namespace ControlStruct {
+
+const std::list< Expression *> & makeParameters(
+	const std::list< TypeDecl *> & forallClause
+) {
+	auto parameters = new std::list< Expression *>();
+	for ( auto it = forallClause.begin(); it != forallClause.end(); it++ ) {
+		parameters->emplace_back( new TypeExpr(
+			new TypeInstType( noQualifiers, ( *it )->get_name(), false )
+		) );
+	}
+	return *parameters;
+}
+
+TypeInstType * makeExceptInstType(
+	const std::string & exceptionName,
+	const std::list< Expression *> & parameters
+) {
+	TypeInstType * exceptInstType = new TypeInstType(
+		noQualifiers,
+		exceptionName,
+		false
+	);
+	cloneAll( parameters, exceptInstType->parameters );
+	return exceptInstType;
+}
+
+// void (*copy)(exception_name parameters * this, exception_name parameters * that);
+FunctionType * makeCopyFnType(
+	const std::string & exceptionName,
+	const std::list< Expression *> & parameters
+) {
+	FunctionType * copyFnType = new FunctionType( noQualifiers, false );
+	copyFnType->get_parameters().push_back( new ObjectDecl(
+		"this",
+		noStorageClasses,
+		LinkageSpec::Cforall,
+		nullptr,
+		new PointerType( noQualifiers,
+			makeExceptInstType( exceptionName, parameters ) ),
+		nullptr
+	) );
+	copyFnType->get_parameters().push_back( new ObjectDecl(
+		"that",
+		noStorageClasses,
+		LinkageSpec::Cforall,
+		nullptr,
+		new PointerType( noQualifiers,
+			makeExceptInstType( exceptionName, parameters ) ),
+		nullptr
+	) );
+	copyFnType->get_returnVals().push_back( new ObjectDecl(
+		"",
+		noStorageClasses,
+		LinkageSpec::Cforall,
+		nullptr,
+		new VoidType( noQualifiers ),
+		nullptr
+	) );
+	return copyFnType;
+}
+
+// void (*^?{})(exception_name parameters & this);
+FunctionType * makeDtorFnType(
+	const std::string & exceptionName,
+	const std::list< Expression *> & parameters
+) {
+	FunctionType * dtorFnType = new FunctionType( noQualifiers, false );
+	dtorFnType->get_parameters().push_back( new ObjectDecl(
+		"this",
+		noStorageClasses,
+		LinkageSpec::Cforall,
+		nullptr,
+		new ReferenceType( noQualifiers,
+			makeExceptInstType( exceptionName, parameters ) ),
+		nullptr
+	) );
+	dtorFnType->get_returnVals().push_back( new ObjectDecl(
+		"",
+		noStorageClasses,
+		LinkageSpec::Cforall,
+		nullptr,
+		new VoidType( noQualifiers ),
+		nullptr
+	) );
+	return dtorFnType;
+}
+
+// const char * (*msg)(exception_name parameters * this);
+FunctionType * makeMsgFnType(
+	const std::string & exceptionName,
+	const std::list< Expression *> & parameters
+) {
+	FunctionType * msgFnType = new FunctionType( noQualifiers, false );
+	msgFnType->get_parameters().push_back( new ObjectDecl(
+		"this",
+		noStorageClasses,
+		LinkageSpec::Cforall,
+		nullptr,
+		new PointerType( noQualifiers,
+			makeExceptInstType( exceptionName, parameters ) ),
+		nullptr
+	) );
+	msgFnType->get_returnVals().push_back( new ObjectDecl(
+		"",
+		noStorageClasses,
+		LinkageSpec::Cforall,
+		nullptr,
+		new PointerType( noQualifiers,
+			new BasicType( Type::Const, BasicType::Char ) ),
+		nullptr
+	) );
+	return msgFnType;
+}
+
+StructDecl * ehmTypeIdStruct(
+	const std::string & exceptionName,
+	const std::list< TypeDecl *> & forallClause
+) {
+	StructDecl * structDecl = new StructDecl( Virtual::typeIdType( exceptionName ) );
+	structDecl->members.push_back( new ObjectDecl(
+		"parent",
+		noStorageClasses,
+		LinkageSpec::Cforall,
+		nullptr,
+		new PointerType( noQualifiers,
+			new TypeInstType( Type::Const, "__cfavir_type_info", false ) ),
+		nullptr
+	) );
+	structDecl->set_body( true );
+	cloneAll( forallClause, structDecl->parameters );
+	return structDecl;
+}
+
+ObjectDecl * ehmTypeIdValue(
+	const std::string & exceptionName,
+	const std::list< Expression *> & parameters
+) {
+	StructInstType * typeIdType = new StructInstType(
+		Type::Const,
+		Virtual::typeIdType( exceptionName )
+	);
+	cloneAll( parameters, typeIdType->parameters );
+	return new ObjectDecl(
+		Virtual::typeIdName( exceptionName ),
+		noStorageClasses,
+		LinkageSpec::Cforall,
+		nullptr,
+		typeIdType,
+		new ListInit( { new SingleInit(
+			new AddressExpr( new NameExpr( "__cfatid_exception_t" ) )
+			) }, {}, true ),
+		{ new Attribute( "cfa_linkonce" ) }
+	);
+}
+
+StructDecl * ehmExceptionStructDecl(
+	const std::string & exceptionName,
+	const std::list< TypeDecl *> & forallClause
+) {
+	StructDecl * structDecl = new StructDecl( exceptionName );
+	cloneAll( forallClause, structDecl->parameters );
+	return structDecl;
+}
+
+StructDecl * ehmVirtualTableStruct(
+	const std::string & exceptionName,
+	const std::list< TypeDecl *> & forallClause,
+	const std::list< Expression *> & parameters
+) {
+	StructInstType * typeIdType = new StructInstType(
+		Type::Const,
+		Virtual::typeIdType( exceptionName )
+	);
+	cloneAll( parameters, typeIdType->parameters );
+	ObjectDecl * typeId = new ObjectDecl(
+		"__cfavir_typeid",
+		noStorageClasses,
+		LinkageSpec::Cforall,
+		nullptr,
+		new PointerType( noQualifiers, typeIdType ),
+		nullptr
+	);
+	ObjectDecl * size = new ObjectDecl(
+		"size",
+		noStorageClasses,
+		LinkageSpec::Cforall,
+		nullptr,
+		new TypeInstType( noQualifiers, "size_t", false ),
+		nullptr
+	);
+	ObjectDecl * copy = new ObjectDecl(
+		"copy",
+		noStorageClasses,
+		LinkageSpec::Cforall,
+		nullptr,
+		new PointerType( noQualifiers,
+			makeCopyFnType( exceptionName, parameters ) ),
+		nullptr
+	);
+	ObjectDecl * dtor = new ObjectDecl(
+		"^?{}",
+		noStorageClasses,
+		LinkageSpec::Cforall,
+		nullptr,
+		new PointerType( noQualifiers,
+			makeDtorFnType( exceptionName, parameters ) ),
+		nullptr
+	);
+	ObjectDecl * msg = new ObjectDecl(
+		"msg",
+		noStorageClasses,
+		LinkageSpec::Cforall,
+		nullptr,
+		new PointerType( noQualifiers,
+			makeMsgFnType( exceptionName, parameters ) ),
+		nullptr
+	);
+	StructDecl * structDecl = new StructDecl( Virtual::vtableTypeName( exceptionName ) );
+	structDecl->members.push_back( typeId );
+	structDecl->members.push_back( size );
+	structDecl->members.push_back( copy );
+	structDecl->members.push_back( dtor );
+	structDecl->members.push_back( msg );
+	structDecl->set_body( true );
+	cloneAll( forallClause, structDecl->parameters );
+	return structDecl;
+}
+
+StructDecl * ehmExceptionStruct(
+	const std::string & exceptionName,
+	const std::list< TypeDecl *> & forallClause,
+	const std::list< Expression *> & parameters, 
+	const std::list< Declaration *> & members
+) {
+	StructInstType * vtableType = new StructInstType(
+		Type::Const,
+		Virtual::vtableTypeName( exceptionName )
+	);
+	cloneAll( parameters, vtableType->parameters );
+	StructDecl * structDecl = new StructDecl( exceptionName );
+	structDecl->members = members;
+	structDecl->members.push_front( new ObjectDecl(
+		"virtual_table",
+		noStorageClasses,
+		LinkageSpec::Cforall,
+		nullptr,
+		new PointerType( noQualifiers, vtableType ),
+		nullptr
+	) );
+	structDecl->set_body( true );
+	cloneAll( forallClause, structDecl->parameters );
+	return structDecl;
+}
+
+ObjectDecl * ehmTypeIdExtern(
+	const std::string & exceptionName,
+	const std::list< Expression *> & parameters
+) {
+	StructInstType * typeIdType = new StructInstType(
+		Type::Const,
+		Virtual::typeIdType( exceptionName )
+	);
+	cloneAll( parameters, typeIdType->parameters );
+	return new ObjectDecl(
+		Virtual::typeIdName( exceptionName ),
+		Type::Extern,
+		LinkageSpec::Cforall,
+		nullptr,
+		typeIdType,
+		nullptr,
+		{ new Attribute( "cfa_linkonce" ) }
+	);
+}
+
+ObjectDecl * ehmExternVtable(
+	const std::string & exceptionName,
+	const std::list< Expression *> & parameters, 
+	const std::string & tableName
+) {
+	StructInstType * vtableType = new StructInstType(
+		Type::Const,
+		Virtual::vtableTypeName( exceptionName )
+	);
+	cloneAll( parameters, vtableType->parameters );
+	return new ObjectDecl(
+		tableName,
+		Type::Extern,
+		LinkageSpec::Cforall,
+		nullptr,
+		vtableType,
+		nullptr
+	);
+}
+
+FunctionDecl * ehmDefineCopy(
+	const std::string & exceptionName,
+	const std::list< Expression *> & parameters
+) {
+	return new FunctionDecl(
+		"copy",
+		noStorageClasses,
+		LinkageSpec::Cforall,
+		makeCopyFnType( exceptionName, parameters ),
+		new CompoundStmt( {
+			new ExprStmt( new UntypedExpr( new NameExpr( "?=?" ), {
+				new UntypedExpr( new NameExpr( "*?" ), { new NameExpr( "this" ) } ),
+				new UntypedExpr( new NameExpr( "*?" ), { new NameExpr( "that" ) } )
+			} ) )
+		} )
+	);
+}
+
+FunctionDecl * ehmDefineMsg(
+	const std::string & exceptionName,
+	const std::list< Expression *> & parameters
+) {
+	std::stringstream msg;
+	msg << exceptionName;
+	if ( !parameters.empty() ) { // forall variant, add parameters
+		msg << "(";
+		for ( auto it = parameters.begin(); it != parameters.end(); it++ ) {
+			( *it )->print( msg );
+			if ( it + 1 == parameters.end() ) {
+				msg << ")"; // end of list, close bracket
+			} else {
+				msg << ", "; // otherwise use comma as separator
+			}
+		}
+	}
+	return new FunctionDecl(
+		"msg",
+		noStorageClasses,
+		LinkageSpec::Cforall,
+		makeMsgFnType( exceptionName, parameters ),
+		new CompoundStmt( {
+			new ReturnStmt( new ConstantExpr( Constant::from_string( msg.str() ) ) )
+		} )
+	);
+}
+
+ObjectDecl * ehmVirtualTable(
+	const std::string & exceptionName,
+	const std::list< Expression *> & parameters,
+	const std::string & tableName
+) {
+	StructInstType * sizeofType = new StructInstType( noQualifiers, exceptionName );
+	cloneAll( parameters, sizeofType->parameters );
+	std::list< Initializer *> inits {
+		new SingleInit( new AddressExpr(
+			new NameExpr( Virtual::typeIdName( exceptionName ) ) ) ),
+		new SingleInit( new SizeofExpr( sizeofType ) ),
+		new SingleInit( new NameExpr( "copy" ) ),
+		new SingleInit( new NameExpr( "^?{}" ) ),
+		new SingleInit( new NameExpr( "msg" ) )
+	};
+	std::list< Designation *> desig {
+		new Designation( { new NameExpr( "__cfavir_typeid" ) } ),
+		new Designation( { new NameExpr( "size" ) } ),
+		new Designation( { new NameExpr( "copy" ) } ),
+		new Designation( { new NameExpr( "^?{}" ) } ),
+		new Designation( { new NameExpr( "msg" ) } )
+	};
+	StructInstType * vtableType = new StructInstType(
+		Type::Const,
+		Virtual::vtableTypeName( exceptionName )
+	);
+	cloneAll( parameters, vtableType->parameters );
+	return new ObjectDecl(
+		tableName,
+		noStorageClasses,
+		LinkageSpec::Cforall,
+		nullptr,
+		vtableType,
+		new ListInit( inits, desig )
+	);
+}
+
+class ExceptDeclCore : public WithDeclsToAdd {
+public:
+	// translates exception decls
+	Declaration * postmutate( StructDecl * structDecl );
+
+	// translates vtable decls
+	DeclarationWithType * postmutate( ObjectDecl * objectDecl );
+};
+
+Declaration * ExceptDeclCore::postmutate( StructDecl * structDecl ) {
+	if ( structDecl->is_exception() ) {
+		const std::string & exceptionName = structDecl->get_name();
+		const std::list< TypeDecl *> & forallClause = structDecl->get_parameters();
+		const std::list< Expression *> & parameters = makeParameters( forallClause );
+		const std::list< Declaration *> & members = structDecl->get_members();
+
+		declsToAddBefore.push_back( ehmTypeIdStruct( exceptionName, forallClause ) );
+		if ( forallClause.empty() ) { // non-forall variant
+			declsToAddBefore.push_back( ehmTypeIdValue( exceptionName, parameters ) );
+		}
+		declsToAddBefore.push_back( ehmExceptionStructDecl( exceptionName, forallClause ) );
+		declsToAddBefore.push_back( ehmVirtualTableStruct( exceptionName, forallClause, parameters ) );
+		return ehmExceptionStruct( exceptionName, forallClause, parameters, members );
+	}
+	return structDecl;
+}
+
+DeclarationWithType * ExceptDeclCore::postmutate( ObjectDecl * objectDecl ) {
+	// Check if it is VTableType
+	VTableType * vtableType = dynamic_cast< VTableType *>( objectDecl->get_type() );
+	if ( vtableType ) {
+		TypeInstType * base = dynamic_cast< TypeInstType *>( vtableType->get_base() );
+		assert( base ); // should be a TypeInstType
+		const std::string & exceptionName = base->get_name();
+		const std::string & tableName = objectDecl->get_name();
+		const std::list< Expression *> parameters = base->get_parameters();
+
+		if ( objectDecl->get_storageClasses().is_extern ) { // if extern
+			if ( !parameters.empty() ) { // forall variant
+				declsToAddBefore.push_back( ehmTypeIdExtern( exceptionName, parameters ) );
+			}
+			return ehmExternVtable( exceptionName, parameters, tableName );
+		}
+		// else, non-extern
+		if ( !parameters.empty() ) { // forall variant
+			declsToAddBefore.push_back( ehmTypeIdValue( exceptionName, parameters ) );
+		}
+		declsToAddBefore.push_back( ehmDefineCopy( exceptionName, parameters ) );
+		declsToAddBefore.push_back( ehmDefineMsg( exceptionName, parameters ) );
+		return ehmVirtualTable( exceptionName, parameters, tableName );
+	}
+	return objectDecl;
+}
+
+void translateExcept( std::list< Declaration *> & translationUnit ) {
+	PassVisitor<ExceptDeclCore> translator;
+	mutateAll( translationUnit, translator );
+}
+
+}
Index: src/ControlStruct/ExceptDecl.h
===================================================================
--- src/ControlStruct/ExceptDecl.h	(revision 5541ea3d192c866061ad89a360daabc4e33e3429)
+++ src/ControlStruct/ExceptDecl.h	(revision 5541ea3d192c866061ad89a360daabc4e33e3429)
@@ -0,0 +1,24 @@
+//
+// 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.
+//
+// ExceptDecl.h --
+//
+// Author           : Henry Xue
+// Created On       : Tue Jul 20 04:10:50 2021
+// Last Modified By : Henry Xue
+// Last Modified On : Tue Jul 20 04:10:50 2021
+// Update Count     : 1
+//
+
+#pragma once
+
+#include <list>  // for list
+
+class Declaration;
+
+namespace ControlStruct {
+	void translateExcept( std::list< Declaration *> & translationUnit );
+}
Index: src/ControlStruct/ExceptTranslate.cc
===================================================================
--- src/ControlStruct/ExceptTranslate.cc	(revision 0640189e9e66678dab5d7f80793687fa10ff24c3)
+++ src/ControlStruct/ExceptTranslate.cc	(revision 5541ea3d192c866061ad89a360daabc4e33e3429)
@@ -9,7 +9,7 @@
 // Author           : Andrew Beach
 // Created On       : Wed Jun 14 16:49:00 2017
-// Last Modified By : Andrew Beach
-// Last Modified On : Wed Jun 24 11:18:00 2020
-// Update Count     : 17
+// Last Modified By : Henry Xue
+// Last Modified On : Tue Aug 03 10:05:51 2021
+// Update Count     : 18
 //
 
@@ -320,11 +320,10 @@
 				static_cast<ObjectDecl *>( handler->get_decl() );
 			ObjectDecl * local_except = handler_decl->clone();
-			local_except->set_init(
-				new ListInit({ new SingleInit(
-					new VirtualCastExpr( nameOf( except_obj ),
-						local_except->get_type()
-						)
-					) })
+			VirtualCastExpr * vcex = new VirtualCastExpr(
+				nameOf( except_obj ),
+				local_except->get_type()
 				);
+			vcex->location = handler->location;
+			local_except->set_init( new ListInit({ new SingleInit( vcex ) }) );
 			block->push_back( new DeclStmt( local_except ) );
 
@@ -392,7 +391,11 @@
 
 		// Check for type match.
-		Expression * cond = UntypedExpr::createAssign( nameOf( local_except ),
-			new VirtualCastExpr( nameOf( except_obj ),
-				local_except->get_type()->clone() ) );
+		VirtualCastExpr * vcex = new VirtualCastExpr(
+			nameOf( except_obj ),
+			local_except->get_type()->clone()
+			);
+		vcex->location = modded_handler->location;
+		Expression * cond = UntypedExpr::createAssign(
+			nameOf( local_except ), vcex );
 
 		// Add the check on the conditional if it is provided.
Index: src/ControlStruct/module.mk
===================================================================
--- src/ControlStruct/module.mk	(revision 0640189e9e66678dab5d7f80793687fa10ff24c3)
+++ src/ControlStruct/module.mk	(revision 5541ea3d192c866061ad89a360daabc4e33e3429)
@@ -10,10 +10,12 @@
 ## Author           : Richard C. Bilson
 ## Created On       : Mon Jun  1 17:49:17 2015
-## Last Modified By : Andrew Beach
-## Last Modified On : Wed Jun 28 16:15:00 2017
-## Update Count     : 4
+## Last Modified By : Henry Xue
+## Last Modified On : Tue Jul 20 04:10:50 2021
+## Update Count     : 5
 ###############################################################################
 
 SRC_CONTROLSTRUCT = \
+	ControlStruct/ExceptDecl.cc \
+	ControlStruct/ExceptDecl.h \
 	ControlStruct/ForExprMutator.cc \
 	ControlStruct/ForExprMutator.h \
Index: src/Parser/TypeData.cc
===================================================================
--- src/Parser/TypeData.cc	(revision 0640189e9e66678dab5d7f80793687fa10ff24c3)
+++ src/Parser/TypeData.cc	(revision 5541ea3d192c866061ad89a360daabc4e33e3429)
@@ -9,7 +9,7 @@
 // Author           : Rodolfo G. Esteves
 // Created On       : Sat May 16 15:12:51 2015
-// Last Modified By : Peter A. Buhr
-// Last Modified On : Wed Jul 14 18:57:31 2021
-// Update Count     : 672
+// Last Modified By : Henry Xue
+// Last Modified On : Tue Jul 20 04:10:50 2021
+// Update Count     : 673
 //
 
@@ -778,4 +778,5 @@
 	  case AggregateDecl::Struct:
 	  case AggregateDecl::Coroutine:
+	  case AggregateDecl::Exception:
 	  case AggregateDecl::Generator:
 	  case AggregateDecl::Monitor:
Index: src/Parser/parser.yy
===================================================================
--- src/Parser/parser.yy	(revision 0640189e9e66678dab5d7f80793687fa10ff24c3)
+++ src/Parser/parser.yy	(revision 5541ea3d192c866061ad89a360daabc4e33e3429)
@@ -10,6 +10,6 @@
 // Created On       : Sat Sep  1 20:22:55 2001
 // Last Modified By : Peter A. Buhr
-// Last Modified On : Wed Jul 14 17:27:54 2021
-// Update Count     : 5030
+// Last Modified On : Tue Jul 20 22:03:04 2021
+// Update Count     : 5031
 //
 
@@ -1923,5 +1923,5 @@
 
 vtable:
-	VTABLE '(' typedef_name ')' default_opt
+	VTABLE '(' type_name ')' default_opt
 		{ $$ = DeclarationNode::newVtableType( $3 ); }
 		// { SemanticError( yylloc, "vtable is currently unimplemented." ); $$ = nullptr; }
Index: src/SynTree/Declaration.h
===================================================================
--- src/SynTree/Declaration.h	(revision 0640189e9e66678dab5d7f80793687fa10ff24c3)
+++ src/SynTree/Declaration.h	(revision 5541ea3d192c866061ad89a360daabc4e33e3429)
@@ -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 Mar 12 18:35:36 2021
-// Update Count     : 159
+// Last Modified By : Henry Xue
+// Last Modified On : Tue Jul 20 04:10:50 2021
+// Update Count     : 160
 //
 
@@ -300,4 +300,5 @@
 
 	bool is_coroutine() { return kind == Coroutine; }
+	bool is_exception() { return kind == Exception; }
 	bool is_generator() { return kind == Generator; }
 	bool is_monitor  () { return kind == Monitor  ; }
Index: src/main.cc
===================================================================
--- src/main.cc	(revision 0640189e9e66678dab5d7f80793687fa10ff24c3)
+++ src/main.cc	(revision 5541ea3d192c866061ad89a360daabc4e33e3429)
@@ -9,7 +9,7 @@
 // Author           : Peter Buhr and Rob Schluntz
 // Created On       : Fri May 15 23:12:02 2015
-// Last Modified By : Peter A. Buhr
-// Last Modified On : Sat Mar  6 15:49:00 2021
-// Update Count     : 656
+// Last Modified By : Henry Xue
+// Last Modified On : Tue Jul 20 04:27:35 2021
+// Update Count     : 658
 //
 
@@ -49,4 +49,5 @@
 #include "Common/utility.h"                 // for deleteAll, filter, printAll
 #include "Concurrency/Waitfor.h"            // for generateWaitfor
+#include "ControlStruct/ExceptDecl.h"       // for translateExcept
 #include "ControlStruct/ExceptTranslate.h"  // for translateEHM
 #include "ControlStruct/Mutate.h"           // for mutate
@@ -305,4 +306,10 @@
 		CodeTools::fillLocations( translationUnit );
 		Stats::Time::StopBlock();
+
+		PASS( "Translate Exception Declarations", ControlStruct::translateExcept( translationUnit ) );
+		if ( exdeclp ) {
+			dump( translationUnit );
+			return EXIT_SUCCESS;
+		} // if
 
 		// add the assignment statement after the initialization of a type parameter
@@ -549,4 +556,5 @@
 	// code dumps
 	{ "ast", astp, true, "print AST after parsing" },
+	{ "exdecl", exdeclp, true, "print AST after translating exception decls" },
 	{ "symevt", symtabp, true, "print AST after symbol table events" },
 	{ "altexpr", expraltp, true, "print alternatives for expressions" },
Index: tests/.expect/counter.txt
===================================================================
--- tests/.expect/counter.txt	(revision 0640189e9e66678dab5d7f80793687fa10ff24c3)
+++ tests/.expect/counter.txt	(revision 5541ea3d192c866061ad89a360daabc4e33e3429)
@@ -1,2 +1,2 @@
-45
-42
+inc 45
+dec 42
Index: tests/.expect/rational.txt
===================================================================
--- tests/.expect/rational.txt	(revision 0640189e9e66678dab5d7f80793687fa10ff24c3)
+++ tests/.expect/rational.txt	(revision 5541ea3d192c866061ad89a360daabc4e33e3429)
@@ -1,20 +1,37 @@
 constructor
-3/1 4/1 0/1 0/1 1/1
-1/2 5/7
-2/3 -3/2
--2/3 3/2
-logical
--2/1 -3/2
-1
-1
-1
-0
-0
+a : 3/1 b : 4/1 c : 0/1 d : 0/1 e : 1/1
+a : 1/2 b : 5/7
+a : 2/3 b : -3/2
+a : -2/3 b : 3/2
+
+comparison
+a : -2/1 b : -3/2
+a == 0 : 0
+a == 1 : 0
+a != 0 : 1
+! a : 0
+a != b : 1
+a <  b : 1
+a <=  b : 1
+a >  b : 0
+a >=  b : 0
+
 arithmetic
--2/1 -3/2
--7/2
--1/2
-3/1
-4/3
+a : -2/1 b : -3/2
+a + b : -7/2
+a += b : -7/2
+++a : -5/2
+a++ : -5/2
+a : -3/2
+a - b : 0/1
+a -= b : 0/1
+--a : -1/1
+a-- : -1/1
+a : -2/1
+a * b : 3/1
+a / b : 4/3
+a \ 2 : 4/1 b \ 2 : 9/4
+a \ -2 : 1/4 b \ -2 : 4/9
+
 conversion
 0.75
@@ -24,5 +41,5 @@
 1/7
 355/113
-decompose
+
 more tests
 -3/2
Index: tests/counter.cfa
===================================================================
--- tests/counter.cfa	(revision 0640189e9e66678dab5d7f80793687fa10ff24c3)
+++ tests/counter.cfa	(revision 5541ea3d192c866061ad89a360daabc4e33e3429)
@@ -10,7 +10,9 @@
 // Created On       : Thu Feb 22 15:27:00 2018
 // Last Modified By : Peter A. Buhr
-// Last Modified On : Tue Nov  6 17:50:23 2018
-// Update Count     : 2
+// Last Modified On : Tue Jul 20 21:25:30 2021
+// Update Count     : 4
 // 
+
+#include <fstream.hfa>
 
 // Tests unified increment/decrement builtin functions.
@@ -19,7 +21,6 @@
 struct counter { int x; };
 
-counter& ?+=?( counter& c, one_t ) { ++c.x; return c; }
-
-counter& ?-=?( counter& c, one_t ) { --c.x; return c; }
+counter ?+=?( counter & c, one_t ) { ++c.x; return c; }
+counter ?-=?( counter & c, one_t ) { --c.x; return c; }
 
 int main() {
@@ -28,9 +29,9 @@
     ++c;
     c++;
-    printf("%d\n", c.x);
+    sout | "inc" | c.x;
     c -= 1;
     --c;
     c--;
-    printf("%d\n", c.x);
+    sout | "dec" | c.x;
 }
 
Index: tests/polymorphism.cfa
===================================================================
--- tests/polymorphism.cfa	(revision 0640189e9e66678dab5d7f80793687fa10ff24c3)
+++ tests/polymorphism.cfa	(revision 5541ea3d192c866061ad89a360daabc4e33e3429)
@@ -71,5 +71,5 @@
 		printf("  offset of inner float:  %ld\n", ((char *) & x_inner_float ) - ((char *) & x) );
 
-	void showStatic( thing(int) & x ) {
+	void showStatic( thing(long long int) & x ) {
 		printf("static:\n");
 		SHOW_OFFSETS
@@ -85,5 +85,5 @@
 
 	printf("=== checkPlan9offsets\n");
-	thing(int) x;
+	thing(long long int) x;
 	showStatic(x);
 	showDynamic(x);
Index: tests/rational.cfa
===================================================================
--- tests/rational.cfa	(revision 0640189e9e66678dab5d7f80793687fa10ff24c3)
+++ tests/rational.cfa	(revision 5541ea3d192c866061ad89a360daabc4e33e3429)
@@ -10,6 +10,6 @@
 // Created On       : Mon Mar 28 08:43:12 2016
 // Last Modified By : Peter A. Buhr
-// Last Modified On : Sat Feb  8 18:46:23 2020
-// Update Count     : 86
+// Last Modified On : Tue Jul 20 18:13:40 2021
+// Update Count     : 107
 //
 
@@ -26,35 +26,49 @@
 	sout | "constructor";
 	RatInt a = { 3 }, b = { 4 }, c, d = 0, e = 1;
-	sout | a | b | c | d | e;
+	sout | "a : " | a | "b : " | b | "c : " | c | "d : " | d | "e : " | e;
 
 	a = (RatInt){ 4, 8 };
 	b = (RatInt){ 5, 7 };
-	sout | a | b;
+	sout | "a : " | a | "b : " | b;
 	a = (RatInt){ -2, -3 };
 	b = (RatInt){ 3, -2 };
-	sout | a | b;
+	sout | "a : " | a | "b : " | b;
 	a = (RatInt){ -2, 3 };
 	b = (RatInt){ 3, 2 };
-	sout | a | b;
+	sout | "a : " | a | "b : " | b;
+	sout | nl;
 
-	sout | "logical";
+	sout | "comparison";
 	a = (RatInt){ -2 };
 	b = (RatInt){ -3, 2 };
-	sout | a | b;
-//	sout | a == 1; // FIX ME
-	sout | a != b;
-	sout | a <  b;
-	sout | a <= b;
-	sout | a >  b;
-	sout | a >= b;
+	sout | "a : " | a | "b : " | b;
+	sout | "a == 0 : " | a == (Rational(int)){0}; // FIX ME
+	sout | "a == 1 : " | a == (Rational(int)){1}; // FIX ME
+	sout | "a != 0 : " | a != 0;
+	sout | "! a : " | ! a;
+	sout | "a != b : " | a != b;
+	sout | "a <  b : " | a <  b;
+	sout | "a <=  b : " | a <= b;
+	sout | "a >  b : " | a >  b;
+	sout | "a >=  b : " | a >= b;
+	sout | nl;
 
 	sout | "arithmetic";
-	sout | a | b;
-	sout | a + b;
-	sout | a - b;
-	sout | a * b;
-	sout | a / b;
-//	sout | a \ 2 | b \ 2; // FIX ME
-//	sout | a \ -2 | b \ -2;
+	sout | "a : " | a | "b : " | b;
+	sout | "a + b : " | a + b;
+	sout | "a += b : " | (a += b);
+	sout | "++a : " | ++a;
+	sout | "a++ : " | a++;
+	sout | "a : " | a;
+	sout | "a - b : " | a - b;
+	sout | "a -= b : " | (a -= b);
+	sout | "--a : " | --a;
+	sout | "a-- : " | a--;
+	sout | "a : " | a;
+	sout | "a * b : " | a * b;
+	sout | "a / b : " | a / b;
+	sout | "a \\ 2 : " | a \ 2u | "b \\ 2 : " | b \ 2u;
+	sout | "a \\ -2 : " | a \ -2 | "b \\ -2 : " | b \ -2;
+	sout | nl;
 
 	sout | "conversion";
@@ -68,9 +82,10 @@
 	sout | narrow( 0.14285714285714, 16 );
 	sout | narrow( 3.14159265358979, 256 );
+	sout | nl;
 
-	sout | "decompose";
-	int n, d;
-//	[n, d] = a;
-//	sout | a | n | d;
+	// sout | "decompose";
+	// int n, d;
+	// [n, d] = a;
+	// sout | a | n | d;
 
 	sout | "more tests";
