Index: doc/proposals/concurrency/thePlan.md
===================================================================
--- doc/proposals/concurrency/thePlan.md	(revision 6acb935ec45eabc0c4c2c47501d76a9c231f7219)
+++ doc/proposals/concurrency/thePlan.md	(revision a362f977ce917e9868e8b98a81cc260e0aee5cf9)
@@ -1,16 +1,18 @@
 _Phase 1_ : Prototype
-Threads and Processors.
-Main needs to call process
+done - Threads.
+done - Main thread is a cfa thread.
+done - SimpleBlockingLock.
+done - Synchronisation points in thread destructors.
+done - Processors & SpinLock.
 
 _Phase 2_ : Minimum Viable Product
-Main thread is a cfa thread
-Basic monitors for synchronisation and minimal lock support.
-No internal/external scheduling.
-Synchronisation points in thread destructors.
+Monitor type and enter/leave mutex member routines
+Monitors as a language feature (not calling enter/leave by hand)
+Internal scheduling
 
 _Phase 3_ : Kernel features
-Threads features ex: detach
-Internal scheduling
-Clusters
+Detach thread
+Cluster migration
+Preemption
 
 _Phase 4_ : Monitor features
Index: doc/proposals/ctordtor/Makefile
===================================================================
--- doc/proposals/ctordtor/Makefile	(revision a362f977ce917e9868e8b98a81cc260e0aee5cf9)
+++ doc/proposals/ctordtor/Makefile	(revision a362f977ce917e9868e8b98a81cc260e0aee5cf9)
@@ -0,0 +1,81 @@
+## Define the appropriate configuration variables.
+
+MACROS = ../../LaTeXmacros
+BIB = ../../bibliography
+
+TeXLIB = .:$(MACROS):$(MACROS)/listings:$(MACROS)/enumitem:$(BIB)/:
+LaTeX  = TEXINPUTS=${TeXLIB} && export TEXINPUTS && latex -halt-on-error
+BibTeX = BIBINPUTS=${TeXLIB} && export BIBINPUTS && bibtex
+
+## Define the text source files.
+
+SOURCES = ${addsuffix .tex, \
+ctor \
+}
+
+FIGURES = ${addsuffix .tex, \
+}
+
+PICTURES = ${addsuffix .pstex, \
+}
+
+PROGRAMS = ${addsuffix .tex, \
+}
+
+GRAPHS = ${addsuffix .tex, \
+}
+
+## Define the documents that need to be made.
+
+DOCUMENT = ctor.pdf
+
+# Directives #
+
+all : ${DOCUMENT}
+
+clean :
+	rm -f *.bbl *.aux *.dvi *.idx *.ilg *.ind *.brf *.out *.log *.toc *.blg *.pstex_t *.cf \
+		${FIGURES} ${PICTURES} ${PROGRAMS} ${GRAPHS} ${basename ${DOCUMENT}}.ps ${DOCUMENT}
+
+# File Dependencies #
+
+${DOCUMENT} : ${basename ${DOCUMENT}}.ps
+	ps2pdf $<
+
+${basename ${DOCUMENT}}.ps : ${basename ${DOCUMENT}}.dvi
+	dvips $< -o $@
+
+${basename ${DOCUMENT}}.dvi : Makefile ${GRAPHS} ${PROGRAMS} ${PICTURES} ${FIGURES} ${SOURCES} ${basename ${DOCUMENT}}.tex \
+		$(MACROS)/common.tex $(MACROS)/indexstyle $(BIB)/cfa.bib
+	# Conditionally create an empty *.ind (index) file for inclusion until makeindex is run.
+	if [ ! -r ${basename $@}.ind ] ; then touch ${basename $@}.ind ; fi
+	# Must have *.aux file containing citations for bibtex
+	if [ ! -r ${basename $@}.aux ] ; then ${LaTeX} ${basename $@}.tex ; fi
+	-${BibTeX} ${basename $@}
+	# Some citations reference others so run steps again to resolve these citations
+	${LaTeX} ${basename $@}.tex
+	-${BibTeX} ${basename $@}
+	# Make index from *.aux entries and input index at end of document
+	makeindex -s $(MACROS)/indexstyle ${basename $@}.idx
+	${LaTeX} ${basename $@}.tex
+	# Run again to get index title into table of contents
+	${LaTeX} ${basename $@}.tex
+
+predefined :
+	sed -f predefined.sed ${basename ${DOCUMENT}}.tex > ${basename $@}.cf
+
+## Define the default recipes.
+
+%.tex : %.fig
+	fig2dev -L eepic $< > $@
+
+%.ps : %.fig
+	fig2dev -L ps $< > $@
+
+%.pstex : %.fig
+	fig2dev -L pstex $< > $@
+	fig2dev -L pstex_t -p $@ $< > $@_t
+
+# Local Variables: #
+# compile-command: "make" #
+# End: #
Index: doc/proposals/ctordtor/ctor.tex
===================================================================
--- doc/proposals/ctordtor/ctor.tex	(revision a362f977ce917e9868e8b98a81cc260e0aee5cf9)
+++ doc/proposals/ctordtor/ctor.tex	(revision a362f977ce917e9868e8b98a81cc260e0aee5cf9)
@@ -0,0 +1,330 @@
+% inline code ©...© (copyright symbol) emacs: C-q M-)
+% red highlighting ®...® (registered trademark symbol) emacs: C-q M-.
+% blue highlighting ß...ß (sharp s symbol) emacs: C-q M-_
+% green highlighting ¢...¢ (cent symbol) emacs: C-q M-"
+% LaTex escape §...§ (section symbol) emacs: C-q M-'
+% keyword escape ¶...¶ (pilcrow symbol) emacs: C-q M-^
+% math escape $...$ (dollar symbol)
+
+\documentclass[twoside,11pt]{article}
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+% Latex packages used in the document (copied from CFA user manual).
+\usepackage[T1]{fontenc}                                % allow Latin1 (extended ASCII) characters
+\usepackage{textcomp}
+\usepackage[latin1]{inputenc}
+\usepackage{fullpage,times,comment}
+\usepackage{epic,eepic}
+\usepackage{upquote}									% switch curled `'" to straight
+\usepackage{calc}
+\usepackage{xspace}
+\usepackage{graphicx}
+\usepackage{varioref}									% extended references
+\usepackage{listings}									% format program code
+\usepackage[flushmargin]{footmisc}						% support label/reference in footnote
+\usepackage{latexsym}                                   % \Box glyph
+\usepackage{mathptmx}                                   % better math font with "times"
+\usepackage[usenames]{color}
+\usepackage[pagewise]{lineno}
+\renewcommand{\linenumberfont}{\scriptsize\sffamily}
+\input{common}                                          % bespoke macros used in the document
+\usepackage[dvips,plainpages=false,pdfpagelabels,pdfpagemode=UseNone,colorlinks=true,pagebackref=true,linkcolor=blue,citecolor=blue,urlcolor=blue,pagebackref=true,breaklinks=true]{hyperref}
+\usepackage{breakurl}
+\renewcommand{\UrlFont}{\small\sf}
+
+\setlength{\topmargin}{-0.45in}							% move running title into header
+\setlength{\headsep}{0.25in}
+
+\usepackage{caption}
+\usepackage{subcaption}
+\usepackage{bigfoot}
+\usepackage{amsmath}
+
+\interfootnotelinepenalty=10000
+
+\title{
+\Huge \vspace*{1in} Constructors and Destructors in \CFA \\
+\vspace*{1in}
+}
+
+\author{
+\huge Rob Schluntz \\
+\Large \vspace*{0.1in} \texttt{rschlunt@uwaterloo.ca} \\
+\Large Cheriton School of Computer Science \\
+\Large University of Waterloo
+}
+
+\date{
+\today
+}
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+\newcommand{\bigO}[1]{O\!\left( #1 \right)}
+
+\begin{document}
+\pagestyle{headings}
+% changed after setting pagestyle
+\renewcommand{\sectionmark}[1]{\markboth{\thesection\quad #1}{\thesection\quad #1}}
+\renewcommand{\subsectionmark}[1]{\markboth{\thesubsection\quad #1}{\thesubsection\quad #1}}
+\pagenumbering{roman}
+% \linenumbers                                            % comment out to turn off line numbering
+
+\maketitle
+\thispagestyle{empty}
+
+\clearpage
+\thispagestyle{plain}
+\pdfbookmark[1]{Contents}{section}
+\tableofcontents
+
+\clearpage
+\thispagestyle{plain}
+\pagenumbering{arabic}
+
+
+
+\section{Introduction}
+Unguided manual resource management is difficult.
+Part of the difficulty results from not having any guarantees about the current state of an object.
+Objects can be internally composed of pointers which may reference resources that may or may not need to be manually released, and keeping track of that state for each object can be difficult for the end user.
+
+Constructors and destructors provide a mechanism which bookend the lifetime of an object, allowing the designer of an object to establish invariants for objects of a specific type.
+Constructors guarantee that object initialization code is run before the object can be used, while destructors provide a mechanism that is guaranteed to be run immediately before an object's lifetime ends.
+Constructors and destructors can help to simplify resource management when used in a disciplined way.
+In particular, when all resources are acquired in a constructor, and all resources are released in a destructor, no resource leaks are possible.
+This pattern is a popular idiom in several languages, such as \CC, known as RAII (Resource Acquisition Is Initialization).
+
+
+\section{Design}
+\label{s:Design}
+In designing constructors and destructors for \CFA, the primary goals were ease of use and maintaining backwards compatibility.
+
+In C, when a variable is defined, its value is initially undefined unless it is explicitly initialized or allocated in the static area.
+\begin{lstlisting}
+int main() {
+  int x;
+  int y = 5;
+  x = y;
+}
+\end{lstlisting}
+In the example above, ©x© is defined and left uninitialized, while ©y© is defined and initialized to 5.
+In the last line, ©x© is assigned the value of ©y©.
+The key difference between assignment and initialization being that assignment occurs on a live object (i.e. an object that contains data).
+It is important to note that this means ©x© could have been used uninitialized prior to being assigned, while ©y© could not be used uninitialized.
+Use of uninitialized variables commonly yields undefined behaviour, which is a common source of bugs in C programs. % TODO: *citation*
+
+A constructor is a special function which provides a way of ensuring that some form of object initialization is performed.
+This goal is achieved through a guarantee that a constructor will be called implicitly on every object that is allocated, immediately after the object's definition.
+Since a constructor is called on every object, it is impossible to forget to initialize a single object, as long as all constructors perform some sensible form of initialization.
+
+In \CFA, a constructor is a function with the name ©?{}©.
+Every constructor must have a return type of ©void© and at least one parameter, the first of which is colloquially referred to as the \emph{this} parameter, as in many object-oriented programming languages.
+The ©this© parameter must have a pointer type, whose base type is the type of object that the function constructs.
+There is currently a proposal to add reference types to \CFA.
+Once this proposal has been implemented, the ©this© parameter should instead be a reference type with the same restrictions.
+
+% \begin{lstlisting}
+% void ?{}(int * i) {
+%   *i = 0;
+% }
+% int x, y = 1, z;
+% \end{lstlisting}
+% In this example, a constructor is defined which initializes variables of type ©int© to 0.
+
+Consider the definition of a simple type which encapsulates a dynamic array of ©int©s.
+
+\begin{lstlisting}
+struct Array {
+  int * data;
+  int len;
+}
+\end{lstlisting}
+
+In C, if the user creates an ©Array© object, the fields ©data© and ©len© will be uninitialized by default.
+It is the user's responsibility to remember to initialize both of the fields to sensible values.
+In \CFA, the user can define a constructor to handle initialization of ©Array© objects.
+
+\begin{lstlisting}
+void ?{}(Array * arr){
+  arr->len = 10;
+  arr->data = malloc(sizeof(int)*len);
+  for (int i = 0; i < arr->len; ++i) {
+    arr->data[i] = 0;
+  }
+}
+Array x;
+\end{lstlisting}
+
+This constructor will initialize ©x© so that its ©length© field has the value 10, and its ©data© field holds a pointer to a block of memory large enough to hold 10 ©int©s, and sets the value of each element of the array to 0.
+This particular form of constructor is called the \emph{default constructor}, because it is called an object defined without an initializer.
+A default constructor is a constructor which takes a single argument, the ©this© parameter.
+
+In \CFA, a destructor is a function much like a constructor, except that its name is ©^?{}©.
+A destructor for the ©Array© type can be defined as such.
+\begin{lstlisting}
+void ^?{}(Array * arr) {
+  free(arr->data);
+}
+\end{lstlisting}
+Since the destructor is automatically called for all objects of type ©Array©, the memory associated with an ©Array© will automatically be freed when the object's lifetime ends.
+% The exact guarantees made by \CFA with respect to the calling of destructors will be discussed in detail [later].
+
+As discussed previously, the distinction between initialization and assignment is important.
+Consider the following example.
+\begin{lstlisting}
+Array x;
+Array y;
+Array z = x;
+y = x;
+\end{lstlisting}
+By the previous definition of the default constructor for ©Array©, ©x© and ©y© are initialized to valid arrays of length 10 after their respective definitions.
+On line 3, ©z© is initialized with the value of ©x©, while on line ©4©, ©y© is assigned the value of ©x©.
+The key distinction between initialization and assignment is that a value about to be initialized does not hold any meaningful values, whereas an object about to be assigned might.
+In particular, these cases cannot be handled the same way because in the former case ©z© does not currently own an array, while ©y© does.
+
+\begin{lstlisting}
+void ?{}(Array * arr, Array other) {
+  arr->len = other.len;
+  arr->data = malloc(sizeof(int)*arr->len)
+  for (int i = 0; i < arr->len; ++i) {
+    arr->data[i] = other.data[i];
+  }
+}
+Array ?=?(Array * arr, Array other) {
+  ^?{}(arr);
+  ?{}(arr, other);
+  return *arr;
+}
+\end{lstlisting}
+The two functions above handle these cases.
+The first function is called a \emph{copy constructor}, because it constructs its argument from a single value of the same type.
+The second function is the standard copy assignment operator.
+These four functions are special in that they control the state of most objects.
+
+% TODO: start new section here? this is where the definition of the rules begins to become more formal, whereas everything leading up to this was mostly exposition by example
+\subsection{Function Generation Details}
+By default, every type is defined to have the core set of functions described previously.
+To mimic the behaviour of plain C, the default constructor and destructor for all of the basic types are defined to do nothing, while the copy constructor and assignment operator perform a bitwise copy of the source parameter.
+
+There are several options for user-defined types: structures, unions, and enumerations.
+To aid in ease of use, the standard set of four functions is automatically generated for a user-defined type after its definition is completed.
+
+The generated functions for enumerations are the simplest.
+Since enumerations in C are essentially just another integral type, the generated functions behave in the same way that the builtin functions for the basic types work.
+
+For structures, the situation is more complicated.
+For a structure ©S© with members ©M$_0$©, ©M$_1$©, ... ©M$_{N-1}$©, each function ©f© in the standard set will call ©f(s->M$_i$, ...)© for each ©$i$©.
+That is, a default constructor for ©S© will default construct the members of ©S©, the copy constructor with copy construct them, and so on.
+ % TODO: description VERY weak. Flesh out details
+For example given the struct definition
+\begin{lstlisting}
+struct A {
+  B b;
+  C c;
+}
+\end{lstlisting}
+The following functions are implicitly generated.
+\begin{lstlisting}
+void ?{}(A * this) {
+  ?{}(&this->b);
+  ?{}(&this->c);
+}
+void ?{}(A * this, A other) {
+  ?{}(&this->b, other.b);
+  ?{}(&this->c, other.c);
+}
+A ?=?(A * this, A other) {
+  ?=?(&this->b, other.b);
+  ?=?(&this->c, other.c);
+}
+void ^?{}(A * this) {
+  ^?{}(&this->b);
+  ^?{}(&this->c);
+}
+\end{lstlisting}
+
+In addition to the standard set, a set of \emph{field constructors} is also generated for structures.
+The field constructors are constructors that consume a prefix of the struct's member list.
+That is, $N$ constructors are built of the form ©void ?{}(S *, T$_{\text{M}_0}$)©, ©void ?{}(S *, T$_{\text{M}_0}$, T$_{\text{M}_1}$)©, ..., ©void ?{}(S *, T$_{\text{M}_0}$, T$_{\text{M}_1}$, ..., T$_{\text{M}_{N-1}}$)©, where members are copy constructed if they have a corresponding positional argument and are default constructed otherwise.
+The addition of field constructors allows structs in \CFA to be used naturally in the same ways that they could be used in C (i.e. to initialize any prefix of the struct).
+Extending the previous example, the following constructors are implicitly generated for ©A©.
+\begin{lstlisting}
+void ?{}(A * this, B b) {
+  ?{}(&this->b, b);
+  ?{}(&this->c);
+}
+void ?{}(A * this, B b, C c) {
+  ?{}(&this->b, b);
+  ?{}(&this->c, c);
+}
+\end{lstlisting}
+
+For unions, the default constructor and destructor do nothing, as it's not obvious which member if any should be constructed.
+For copy constructor and assignment operations, a bitwise ©memcpy© is applied.
+An alterantive to this design is to always construct and destruct the first member of a union, to match with the C semantics of initializing the first member of the union.
+This approach ultimately feels subtle and unsafe.
+Another option is to, like \CC, disallow unions from containing members which are themselves managed types.
+This is a reasonable approach from a safety standpoint, but is not very C-like.
+Since the primary purpose of a union is to provide low-level memory optimization, it is assumed that the user has a certain level of maturity.
+It is therefore the responsibility of the user to define the special functions explicitly if they are appropriate, since it is impossible to accurately predict the ways that a union is intended to be used at compile-time.
+
+Arrays are a special case in the C type system.
+C arrays do not carry around their size, making it impossible to write a standalone \CFA function which constructs or destructs an array while maintaining the standard interface for constructors and destructors.
+Instead, \CFA defines the initialization and destruction of an array recursively.
+That is, when an array is defined, each of its elements will be constructed in order from element 0 up to element $n-1$.
+When an array is to be implicitly destructed, each of its elements is destructed in reverse order from element $n-1$ down to element 0.
+
+\subsection{Using Constructors and Destructors}
+Implicitly generated constructor and destructor calls ignore the outermost type qualifiers on a type by way of a cast on the first argument to the function.
+This mechanism allows the same constructors and destructors to be used for qualified objects as for unqualified objects.
+Since this applies only to implicitly generated constructor calls, the language will not allow qualified objects to be re-initialized with a constructor without an explicit cast.
+
+Unlike \CC, \CFA provides an escape hatch that allows a user to decide at an object's definition whether it should be managed or not.
+An object initialized with \lstinline{@=} is guaranteed to be initialized like a C object, and will not be implicitly destructed.
+This feature provides all of the freedom that C programmers are used to having to optimize the program, while maintaining safety as a sensible default.
+In addition to freedom, \lstinline{@=} provides a simple path to migrating legacy C code to Cforall, in that objects can be moved from C-style initialization to \CFA gradually and individually.
+It is worth noting that the use of unmanaged objects can be tricky to get right, since there is no guarantee that the proper invariants will be established on an unmanaged object.
+It is recommended that most objects are managed by sensible constructors and destructors, except where absolutely necessary.
+
+When the user defines any constructor, the intrinsic/generated functions become invisible.
+In the current implementation, the default constructor and copy constructor are only hidden when explicitly overriden, since the derefence operator ©*?© is currently an ©otype© function, which would make it impossible to override a constructor, due to the lack of assertion-satifying funcitons.
+There is a proposal which decouples size/alignment type information from ©otype©, and implementing this would allow constructors and destructors to be hidden by the same rules that \CC uses.
+
+% TODO discuss compile time "checks" for subobjects when defining ctor/dtor for struct
+When defining a constructor or destructor for a struct ©S©, any members that are not explicitly constructed or destructed will be implicitly constructed or destructed automatically.
+If an explicit call is present, then that call is taken in preference to any implicitly generated call.
+A consequence of this rule is that it is possible, unlike \CC, to precisely control the order of construction and destruction of subobjects on a per-constructor basis, whereas in \CC subobject initialization and destruction is always performed based on the declaration order.
+Finally, it is illegal for a subobject to be explicitly constructed after it is used for the first time.
+If the translator cannot be reasonably sure that an object is constructed prior to its first use, but may be constructed afterward, and error is emitted.
+To override this rule, \lstinline{@=} can be used to force the translator to trust the programmer's discretion.
+This form of \lstinline{@=} is not yet implemented.
+
+% TODO discuss error if initializer nesting is too deep or contains designations
+Despite great effort, some forms of C syntax do not work well with constructors in \CFA.
+In particular, constructor calls cannot contain designations, since this is equivalent to allowing designations on the arguments to arbitrary function calls.
+In C, function prototypes are permitted to have arbitrary parameter names, including no names at all, which may have no connection to the actual names used at function definition.
+Furthermore, a function prototype can be repeated an arbitrary number of times, each time using different names.
+As a result, it was decided that any attempt to resolve designated function calls with C's function prototype rules would be brittle, and thus it is not sensible to allow designations in constructor calls.
+In addition, constructor calls cannot have a nesting depth greater than the number of array components in the type of the initialized object, plus one.
+In C, having a greater nesting depth would mean that the programmer intends to initialize subobjects with the nested initializer.
+The reason for this omission is to both simplify the mental model for using constructors, and to make the case of initialization simpler for the resolver.
+If this were allowed, it would be necessary for the expression resolver to decide whether each argument to the constructor call could initialize to some argument to one of the available constructors, making the problem highly recursive and potentially much more expensive.
+It should be noted that if an object does not have a non-trivial constructor, it can still make use of designations and nested initializers in \CFA.
+
+% TODO section on where destruction occurs - probably belongs in implementation section? or part of it does, anyway
+Destructors are automatically called at the end of the block in which the object was declared.
+In addition to this, destructors are automatically called when statements manipulate control flow to leave the block in which the object is declared, e.g. with return, break, continue, and goto statements.
+
+% TODO discuss copy construction for function parameters and return values
+When a function is called, the arguments supplied to the call are subject to implicit copy construction, and the return value is subject to destruction.
+When a value is returned from a function, the copy constructor is called to pass the value back to the call site.
+Exempt from these rules are intrinsic and builtin functions.
+
+% TODO discuss ©= + copy construction?
+
+% \subsection{Implementation}
+% Discuss the implementation details of constructors and destructors.
+
+\end{document}
Index: doc/proposals/tuples/Makefile
===================================================================
--- doc/proposals/tuples/Makefile	(revision a362f977ce917e9868e8b98a81cc260e0aee5cf9)
+++ doc/proposals/tuples/Makefile	(revision a362f977ce917e9868e8b98a81cc260e0aee5cf9)
@@ -0,0 +1,81 @@
+## Define the appropriate configuration variables.
+
+MACROS = ../../LaTeXmacros
+BIB = ../../bibliography
+
+TeXLIB = .:$(MACROS):$(MACROS)/listings:$(MACROS)/enumitem:$(BIB)/:
+LaTeX  = TEXINPUTS=${TeXLIB} && export TEXINPUTS && latex -halt-on-error
+BibTeX = BIBINPUTS=${TeXLIB} && export BIBINPUTS && bibtex
+
+## Define the text source files.
+
+SOURCES = ${addsuffix .tex, \
+tuples \
+}
+
+FIGURES = ${addsuffix .tex, \
+}
+
+PICTURES = ${addsuffix .pstex, \
+}
+
+PROGRAMS = ${addsuffix .tex, \
+}
+
+GRAPHS = ${addsuffix .tex, \
+}
+
+## Define the documents that need to be made.
+
+DOCUMENT = tuples.pdf
+
+# Directives #
+
+all : ${DOCUMENT}
+
+clean :
+	rm -f *.bbl *.aux *.dvi *.idx *.ilg *.ind *.brf *.out *.log *.toc *.blg *.pstex_t *.cf \
+		${FIGURES} ${PICTURES} ${PROGRAMS} ${GRAPHS} ${basename ${DOCUMENT}}.ps ${DOCUMENT}
+
+# File Dependencies #
+
+${DOCUMENT} : ${basename ${DOCUMENT}}.ps
+	ps2pdf $<
+
+${basename ${DOCUMENT}}.ps : ${basename ${DOCUMENT}}.dvi
+	dvips $< -o $@
+
+${basename ${DOCUMENT}}.dvi : Makefile ${GRAPHS} ${PROGRAMS} ${PICTURES} ${FIGURES} ${SOURCES} ${basename ${DOCUMENT}}.tex \
+		$(MACROS)/common.tex $(MACROS)/indexstyle $(BIB)/cfa.bib
+	# Conditionally create an empty *.ind (index) file for inclusion until makeindex is run.
+	if [ ! -r ${basename $@}.ind ] ; then touch ${basename $@}.ind ; fi
+	# Must have *.aux file containing citations for bibtex
+	if [ ! -r ${basename $@}.aux ] ; then ${LaTeX} ${basename $@}.tex ; fi
+	-${BibTeX} ${basename $@}
+	# Some citations reference others so run steps again to resolve these citations
+	${LaTeX} ${basename $@}.tex
+	-${BibTeX} ${basename $@}
+	# Make index from *.aux entries and input index at end of document
+	makeindex -s $(MACROS)/indexstyle ${basename $@}.idx
+	${LaTeX} ${basename $@}.tex
+	# Run again to get index title into table of contents
+	${LaTeX} ${basename $@}.tex
+
+predefined :
+	sed -f predefined.sed ${basename ${DOCUMENT}}.tex > ${basename $@}.cf
+
+## Define the default recipes.
+
+%.tex : %.fig
+	fig2dev -L eepic $< > $@
+
+%.ps : %.fig
+	fig2dev -L ps $< > $@
+
+%.pstex : %.fig
+	fig2dev -L pstex $< > $@
+	fig2dev -L pstex_t -p $@ $< > $@_t
+
+# Local Variables: #
+# compile-command: "make" #
+# End: #
Index: doc/proposals/tuples/tuples.tex
===================================================================
--- doc/proposals/tuples/tuples.tex	(revision a362f977ce917e9868e8b98a81cc260e0aee5cf9)
+++ doc/proposals/tuples/tuples.tex	(revision a362f977ce917e9868e8b98a81cc260e0aee5cf9)
@@ -0,0 +1,336 @@
+% inline code ©...© (copyright symbol) emacs: C-q M-)
+% red highlighting ®...® (registered trademark symbol) emacs: C-q M-.
+% blue highlighting ß...ß (sharp s symbol) emacs: C-q M-_
+% green highlighting ¢...¢ (cent symbol) emacs: C-q M-"
+% LaTex escape §...§ (section symbol) emacs: C-q M-'
+% keyword escape ¶...¶ (pilcrow symbol) emacs: C-q M-^
+% math escape $...$ (dollar symbol)
+
+\documentclass[twoside,11pt]{article}
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+% Latex packages used in the document (copied from CFA user manual).
+\usepackage[T1]{fontenc}                                % allow Latin1 (extended ASCII) characters
+\usepackage{textcomp}
+\usepackage[latin1]{inputenc}
+\usepackage{fullpage,times,comment}
+\usepackage{epic,eepic}
+\usepackage{upquote}									% switch curled `'" to straight
+\usepackage{calc}
+\usepackage{xspace}
+\usepackage{graphicx}
+\usepackage{varioref}									% extended references
+\usepackage{listings}									% format program code
+\usepackage[flushmargin]{footmisc}						% support label/reference in footnote
+\usepackage{latexsym}                                   % \Box glyph
+\usepackage{mathptmx}                                   % better math font with "times"
+\usepackage[usenames]{color}
+\usepackage[pagewise]{lineno}
+\renewcommand{\linenumberfont}{\scriptsize\sffamily}
+\input{common}                                          % bespoke macros used in the document
+\usepackage[dvips,plainpages=false,pdfpagelabels,pdfpagemode=UseNone,colorlinks=true,pagebackref=true,linkcolor=blue,citecolor=blue,urlcolor=blue,pagebackref=true,breaklinks=true]{hyperref}
+\usepackage{breakurl}
+\renewcommand{\UrlFont}{\small\sf}
+
+\setlength{\topmargin}{-0.45in}							% move running title into header
+\setlength{\headsep}{0.25in}
+
+\usepackage{caption}
+\usepackage{subcaption}
+\usepackage{bigfoot}
+
+\interfootnotelinepenalty=10000
+
+\title{
+\Huge \vspace*{1in} Tuple Design in \CFA \\
+\vspace*{1in}
+}
+
+\author{
+\huge Rob Schluntz \\
+\Large \vspace*{0.1in} \texttt{rschlunt@uwaterloo.ca} \\
+\Large Cheriton School of Computer Science \\
+\Large University of Waterloo
+}
+
+\date{
+\today
+}
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+\newcommand{\bigO}[1]{O\!\left( #1 \right)}
+
+\begin{document}
+\pagestyle{headings}
+% changed after setting pagestyle
+\renewcommand{\sectionmark}[1]{\markboth{\thesection\quad #1}{\thesection\quad #1}}
+\renewcommand{\subsectionmark}[1]{\markboth{\thesubsection\quad #1}{\thesubsection\quad #1}}
+\pagenumbering{roman}
+% \linenumbers                                            % comment out to turn off line numbering
+
+\maketitle
+\thispagestyle{empty}
+
+\clearpage
+\thispagestyle{plain}
+\pdfbookmark[1]{Contents}{section}
+\tableofcontents
+
+\clearpage
+\thispagestyle{plain}
+\pagenumbering{arabic}
+
+
+\section{Introduction}
+This document describes my understanding of the existing tuple design~\cite{Buhr94a,Till89}, mixed with my thoughts on improvements after various discussions with Peter, Aaron, and Thierry.
+
+\section{Tuple Expressions}
+A tuple expression is an expression which produces a fixed-size, ordered list of values of heterogeneous types.
+The type of a tuple expression is the tuple of the subexpression types.
+In Cforall, a tuple expression is denoted by a list of expressions enclosed in square brackets.
+
+For example, the expression ©[5, 'x', 10.5]© has type ©[int, char, double]©.
+Tuples are a compile-time phenomenon and have little to no run-time presence.
+
+\subsection{Tuple Variables}
+It is possible to have variables of tuple type, pointer to tuple type, and array of tuple type.
+Tuple types can be composed of any types, except for array types \footnote{I did not see this issue mentioned at all in the original design. A tuple containing an array type seems to make sense up until you try to use a tuple containing an array type as a function parameter. At this point you lose information about the size of the array, which makes tuple assignment difficult. Rather than allowing arrays in most situations and disallowing only as function parameters, it seems like it would be better to be consistent across the board.}.
+
+\begin{lstlisting}
+[double, int] di;
+[double, int] * pdi
+[double, int] adi[10];
+\end{lstlisting}
+The program above declares a variable of type ©[double, int]©, a variable of type pointer to ©[double, int]©, and an array of ten ©[double, int]©.
+
+\subsection{Flattening and Structuring}
+In Cforall, tuples do not have a rigid structure.
+In function call contexts, tuples support implicit flattening and restructuring \footnote{In the original tuple design, four tuple coercions were described: opening, closing, flattening, and structuring. I've combined flattening with opening and structuring with closing in my description, as the distinctions do not seem useful in Cforall since these coercions happen only as arguments to function calls, and I believe all of the semantics are properly covered by the simplified descriptions.}. Tuple flattening recursively expands a tuple into the list of its basic components. Tuple structuring packages a list of expressions into a value of tuple type.
+
+\begin{lstlisting}
+int f(int, int);
+int g([int, int]);
+int h(int, [int, int]);
+[int, int] x;
+int y;
+
+f(x);
+g(y, 10);
+h(x, y);
+\end{lstlisting}
+In Cforall, each of these calls is valid.
+In the call to ©f©, ©x© is implicitly flattened so that the components of ©x© are passed as the two arguments to ©f©.
+For the call to ©g©, the values ©y© and ©10© are structured into a single argument of type ©[int, int]© to match the type of the parameter of ©g©.
+Finally, in the call to ©h©, ©y© is flattened to yield an argument list of length 3, of which the first component of ©x© is passed as the first parameter of ©h©, and the second component of ©x© and ©y© are structured into the second argument of type ©[int, int]©.
+
+\section{Functions}
+\subsection{Argument Passing}
+In resolving a function call, all of the arguments to the call are flattened.
+While determining if a particular function/argument-list combination is valid, the arguments are structured to match the shape of each formal parameter, in order.
+
+For example, given a function declaration ©[int] f(int, [double, int])©, the call ©f([5, 10.2], 0)© can be satisfied by first flattening the tuple to yield the expression ©f(5, 10.2, 0)© and then structuring the argument list to match the formal parameter list structure as ©f(5, [10.2, 0])©.
+
+\subsection{Multiple-Return-Value Functions}
+Functions can be declared to return more than one value.
+Multiple return values are packaged into a tuple value when the function returns.
+A multiple-returning function with return type ©T© can return any expression which is implicitly convertible to ©T©.
+
+\subsection{Tuple Assignment}
+An assignment where the left side of the assignment operator has a tuple type is called tuple assignment.
+There are two kinds of tuple assignment depending on whether the right side of the assignment operator has a tuple type or a non-tuple type, called Multiple Assignment and Mass Assignment respectively.
+Let $L_i$ for $i$ in $[0, n)$ represent each component of the flattened left side, $R_i$ represent each component of the flattened right side of a multiple assignment, and $R$ represent the right side of a mass assignment.
+
+For a multiple assignment to be valid, both tuples must have the same number of elements when flattened. Multiple assignment assigns $R_i$ to $L_i$ for each $i$.
+That is, ©?=?(&$L_i$, $R_i$)© must be a well-typed expression.
+
+Mass assignment assigns the value $R$ to each $L_i$. For a mass assignment to be valid, ©?=?(&$L_i$, $R$)© must be a well-typed expression.
+This differs from C cascading assignment (e.g. ©a=b=c©) in that conversions are applied to $R$ in each individual assignment, which prevents data loss from the chain of conversions that can happen during a cascading assignment.
+
+Both kinds of tuple assignment have parallel semantics, such that each value on the left side and right side is evaluated \emph{before} any assignments occur.
+Tuple assignment is an expression where the result type is the type of the left side of the assignment, as in normal assignment (i.e. the tuple of the types of the left side expressions) \footnote{This is a change from the original tuple design, wherein tuple assignment was a statement. This decision appears to have been made in an attempt to fix what was seen as a problem with assignment, but at the same time this doesn't seem to fit C or Cforall very well. In another language, tuple assignment as a statement could be reasonable, but I don't see a good justification for making this the only kind of assignment that isn't an expression. In this case, I would value consistency over idealism}.
+These semantics allow cascading tuple assignment to work out naturally in any context where a tuple is permitted.
+
+The following example shows multiple, mass, and cascading assignment in one expression
+\begin{lstlisting}
+  int a, b;
+  double c, d;
+  [void] f([int, int]);
+  f([c, a] = [b, d] = 1.5);
+\end{lstlisting}
+First a mass assignment of ©1.5© into ©[b, d]©, which assigns ©1.5© into ©b©, which is truncated to ©1©, and ©1© into ©d©, producing the tuple ©[1, 1.5]© as a result.
+That tuple is used as the right side of the multiple assignment (i.e. ©[c, a] = [1, 1.5]©) which assigns ©1© into ©c© and ©1.5© into ©a©, which is truncated to ©1©, producing the result ©[1, 1]©.
+Finally, the tuple ©[1, 1]© is used as an expression in the call to ©f©.
+
+\subsection{Tuple Construction}
+Tuple construction and destruction follow the same rules and semantics as tuple assignment, except that in the case where there is no right side, the default constructor or destructor is called on each component of the tuple.
+
+It is possible to define constructors and assignment functions for tuple types that provide new semantics.
+For example, the function ©void ?{}([T, U] *, S);© can be defined to allow a tuple variable to be constructed from a value of type ©S©. Due to the structure of generated constructors, it is possible to pass a tuple to a generated constructor for a type with a member prefix that matches the type of the tuple (e.g. an instance of ©struct S { int x; double y; int z }© can be constructed with a tuple of type ©[int, double]©, `out of the box').
+
+\section{Other Tuple Expressions}
+\subsection{Member Tuple Expression}
+It is possible to access multiple fields from a single expression using a Member Tuple Expression \footnote{Called ``record field tuple'' in the original design, but there's no reason to limit this feature to only structs, so ``field tuple'' or ``member tuple'' feels more appropriate.}.
+The result is a single tuple-valued expression whose type is the tuple of the types of the members.
+A member tuple expression has the form ©a.[x, y, z];© where ©a© is an expression with type ©T©, where ©T© supports member access expressions, and ©x, y, z© are all members of ©T© with types ©T$_x$©, ©T$_y$©, and ©T$_z$© respectively.
+Then the type of ©a.[x, y, z]© is ©[T$_x$, T$_y$, T$_z$]©.
+It is possible for a member tuple expression to contain other member access expressions, e.g. ©a.[x, y.[i, j], z.k]©.
+This expression is equivalent to ©[a.x, [a.y.i, a.y.j], a.z.k]©.
+It is guaranteed that the aggregate expression to the left of the ©.© on a member tuple expression is evaluated once.
+
+\subsection{Tuple Indexing}
+Sometimes it is desirable to access a single component of a tuple-valued expression without creating unnecessary temporary variables to assign to.
+Given a tuple-valued expression ©e© and a compile-time constant integer $i$ where $0 \leq i < n$, where $n$ is the number of components in ©e©, ©e.i© will access the $i$\textsuperscript{th} component of ©e©.
+% \footnote{If this syntax cannot be parsed, we can make it ©_i©, and a semantic check ensures that ©_i© has the right form. The capability to access a component of a tuple is helpful internally, and there doesn't seem to be a disadvantage to exposing it to users. On the other hand, it is more general than casting and much more explicit, while also being less verbose.}.
+It is possible to use a member tuple expression with tuple indexing to manually restructure a tuple (rearrange components, drop components, duplicate components, etc.).
+
+% TODO: mention that Tuple.member_name and Aggregate.index could have sensible semantics, but introduce complexity into the model. Agg.idx could mean get the ith member of the aggregate (further, this could be extended for enumerations as well, where the LHS is a type instead of a value), but it's not clear there is a compelling use-case. Tuple.member_name can either mean "distribute the member across the elements of the tuple" [effectively a compile-time map], or alternatively array.member_name (to mean basically the same thing). The problem with this is that it takes this expression's meaning from being clear at compile-time to needing resolver support, as the member name needs to appropriately distribute across every member of the tuple, which could itself be a tuple, etc. Again, the extra complexity is not currently justified.
+
+For example
+\begin{lstlisting}
+  [int, double] x;
+  [double, int, double] y = [x.1, x.0, x.1];  // (1)
+
+  [int, int, int] f();
+  [x.0, y.1] = f().[0, 2];                    // (2)
+\end{lstlisting}
+
+(1) ©y© is initialized using a tuple expression which selects components from the tuple variable ©x©.
+
+(2) A mass assignment of the first and third components from the return value of ©f© into the first component of ©x© and the second component of ©y©.
+
+\subsection{Casting}
+A cast to tuple type is valid when $T_n \leq S_m$, where $T_n$ is the number of components in the target type and $S_m$ is the number of components in the source type, and for each $i$ in $[0, n)$, $S_i$ can be cast to $T_i$.
+Excess elements ($S_j$ for all $j$ in $[n, m)$) are evaluated, but their values are discarded so that they are not included in the result expression.
+This naturally follows the way that a cast to void works in C.
+
+For example,
+\begin{lstlisting}
+  [int, int, int] f();
+  [int, [int, int], int] g();
+
+  ([int, double])f();           // (1)
+  ([int, int, int])g();         // (2)
+  ([void, [int, int]])g();      // (3)
+  ([int, int, int, int])g();    // (4)
+  ([int, [int, int, int]])g();  // (5)
+\end{lstlisting}
+
+(1) discards the last element of the return value and converts the second element to type double.
+
+(2) discards the second component of the second element of the return value of ©g© (if ©g© is free of side effects, this is equivalent to ©[(int)(g().0), (int)(g().1.0), (int)(g().2)]©).
+
+(3) discards the first and third return values (equivalent to ©[(int)(g().1.0), (int)(g().1.1)]©).
+
+(4) is invalid because the cast target type contains 4 components, while the source type contains only 3.
+
+(5) is invalid because the cast ©([int, int, int])(g().1)© is invalid (i.e. it is invalid to cast ©[int, int]© to ©[int, int, int]©)
+
+
+\section{Tuples for Variadic Functions}
+Functions with tuple parameters can be used to provide type-safe variadic functions.
+It appears that it would be possible to leverage tuples to get similar power to what \CC vardiadic templates provide, but with the ability to separately compile them.
+
+\subsection{Option 1: Allow type parameters to match whole tuples, rather than just their components}
+This option could be implemented with two phases of argument matching when a function contains type parameters and the argument list contains tuple arguments.
+If flattening and structuring fail to produce a match, a second attempt at matching the function and argument combination is made where tuple arguments are not expanded and structure must match exactly, modulo implicit conversions. \footnote{It may be desirable to skip the exact matching rule if flattening and structuring produce a match that fails when inferring assertion parameters, at least in the current resolver since our assertion inference appears to be very inefficient.}
+
+For example:
+\begin{lstlisting}
+  forall(otype T, otype U | { T g(U); })
+  void f(T, U);
+
+  [int, int] g([int, int, int, int]);
+
+  f([1, 2], [3, 4, 5, 6]);
+\end{lstlisting}
+With flattening and structuring, the call is first transformed into ©f(1, 2, 3, 4, 5, 6)©.
+Since the first argument of type ©T© does not have a tuple type, unification decides that ©T=int© and ©1© is matched as the first parameter.
+Likewise, ©U© does not have a tuple type, so ©U=int© and ©2© is accepted as the second parameter.
+There are now no remaining formal parameters, there are remaining arguments, and the function is not variadic, so the match fails.
+
+With exact matching, ©T=[int,int]© and ©U=[int,int,int,int]© and so the arguments type check.
+When inferring assertion ©g©, a match is found.
+\footnote{This type of interaction between tuple arguments and type parameters is desirable for perfect forwarding, but it's not obvious to me exactly how this should interact with assertion inference. Ideally, the same rules should apply for assertion satisfaction as apply to argument matching (i.e. flattening \& structuring should be attempted, followed by an exact match attempt on failure), but this may be more complicated than it sounds for assertion satisfaction. Aaron, I'm especially interested to hear your thoughts on this with respect to efficiency in the resolver redesign.
+
+For example, should we allow this to match?
+\begin{lstlisting}
+  forall(otype T, otype U | { T g(U); })
+  void f(T, U);
+
+  [int, int] g(int, ®[int, int]®, int);
+
+  f([1, 2], [3, 4, 5, 6]);
+\end{lstlisting}
+To only have an exact matching rule here feels too strict. At the very least, it would be nice to accept ©[int, int] g(int, int, int, int)©, since that would allow for argument lists to be packaged and sent off to polymorphic functions and then directly forwarded to other functions.}.
+
+The addition of an exact matching rule only affects the outcome for polymorphic type binding when tuples are involved.
+For non-tuple arguments, exact matching and flattening \& structuring are equivalent. For tuple arguments to a function without polymorphic formal parameters, flattening and structuring work whenever an exact match would have worked (the tuple is flattened and implicitly restructured to its original structure).
+Thus there is nothing to be gained from permitting the exact matching rule to take effect when a function does not contain polymorphism and none of the arguments are tuples.
+
+\subsection{Option 2: Add another type parameter kind}
+Perhaps a simpler alternative would be to add another kind of type parameter (e.g., ©ttype©).
+There should be at most one ©ttype© parameter which must occur last in a parameter list.
+Matching against a ©ttype© parameter would consume/package all remaining argument components into a tuple, and would also match no arguments.
+These semantics more closely match normal variadic semantics, while being type-safe. C variadic syntax and ©ttype© polymorphism probably should not be mixed, since it is not clear where to draw the line to decide which arguments belong where.\footnote{In fact, if we go with this proposal, it might be desirable to disallow polymorphic functions to use C variadic syntax to encourage a Cforall style. Aside from maybe calling C variadic functions, it's not obvious to me there would be anything you can do with C variadics that couldn't also be done with ©ttype© parameters. }
+
+Example 1: taken from Wikipedia, demonstrates variadic templates done in a Cforall style
+\begin{lstlisting}
+  void func(void) {}                           // termination version (1)
+  forall(otype T, ttype Params | { void process(const T &); void func(const Params &); })
+  void func(const T& arg1, const Params & p) { // (2)
+    process(arg1);
+    func(p);
+  }
+  void process(int);                           // (3)
+  void process(double);                        // (4)
+  func(1, 2.0, 3.5, 4);
+\end{lstlisting}
+In the call to ©func©, the value ©1© is taken as the first parameter, so ©T© unifies with ©int©, and the arguments ©2.0©, ©3.5©, and ©4© are consumed to form a tuple argument of type ©[double, double, int]©.
+To satisfy the assertions to ©func©, the functions (3) and (2) are implicitly selected to satisfy the requirements of ©void process(const T &)© and ©void func(const Params &)© respectively.
+Since (2) requires assertion parameters, the process repeats selecting (4) and (2).
+The matching process continues recursively until reaching the base case where (3) and (1) are selected.
+The end result is semantically equivalent to ©process(1), process(2.0), process(3.5), process(4)©.
+
+Since (2) is not an exact match for the expected assertion parameter, a thunk is generated that wraps a call to ©func© that accepts an argument of type ©[double, double, int]©.
+This conversion already occurs in the Cforall translator, but may require some modification to handle all of the cases present here.
+
+Example 2: new (i.e. type-safe malloc + constructors)
+\begin{lstlisting}
+  forall(dtype T, ttype Params | sized(T) | { void ?{}(T *, Params); })
+  T * new(Params p) {
+    return malloc(){ p };
+  }
+  array(int) * x = new(1, 2, 3, 4);
+\end{lstlisting}
+In the call to ©new©, ©array(int)© is selected to match ©T©, and ©Params© is expanded ot match ©[int, int, int, int]©. To satisfy the assertions, a constructor with an interface compatible with ©void ?{}(array(int) *, int, int, int, int)© must exist in the current scope.
+
+Assertion inference can also be special cased to match functions that take tuples of any structure only for ttype parameters, if desired.
+
+
+\subsection{Conclusions}
+With either option, we can generate a thunk to perform the conversion from the actual argument's structure to the structure expected by the assertion parameter and that function would be passed as the assertion argument, in a manner similar to the other thunks that are already generated.
+
+I prefer option 2, because it is simpler and I think the semantics are clearer.
+I wouldn't be surprised if it was also noticeably more efficient, because of the lack of backtracking.
+
+As a side note, option 1 also requires calls to be written explicitly, e.g. ©array(int) * x = new([1, 2, 3, 4]);©, which isn't particularly appealing.
+It shifts the burden from the compiler to the programmer, which is almost always wrong, and doesn't match with the way our tuples can be used elsewhere.
+The more I think about it, the more I'm convinced option 1 is the wrong approach, but I'm putting it out anyway in case someone has a good thought on how to make it work correctly.
+
+\addcontentsline{toc}{section}{\refname}
+\bibliographystyle{plain}
+\bibliography{cfa}
+
+%\addcontentsline{toc}{section}{\indexname} % add index name to table of contents
+%\begin{theindex}
+%Italic page numbers give the location of the main entry for the referenced term.
+%Plain page numbers denote uses of the indexed term.
+%Entries for grammar non-terminals are italicized.
+%A typewriter font is used for grammar terminals and program identifiers.
+%\indexspace
+%\input{comp_II.ind}
+%\end{theindex}
+
+\end{document}
Index: src/Common/utility.h
===================================================================
--- src/Common/utility.h	(revision 6acb935ec45eabc0c4c2c47501d76a9c231f7219)
+++ src/Common/utility.h	(revision a362f977ce917e9868e8b98a81cc260e0aee5cf9)
@@ -252,8 +252,8 @@
 
 template< typename T >
-struct reverseIterate_t {
+struct reverse_iterate_t {
 	T& ref;
 
-	reverseIterate_t( T & ref ) : ref(ref) {}
+	reverse_iterate_t( T & ref ) : ref(ref) {}
 
 	typedef typename T::reverse_iterator iterator;
@@ -263,8 +263,44 @@
 
 template< typename T >
-reverseIterate_t< T > reverseIterate( T & ref ) {
-	return reverseIterate_t< T >( ref );
-}
-
+reverse_iterate_t< T > reverseIterate( T & ref ) {
+	return reverse_iterate_t< T >( ref );
+}
+
+// -----------------------------------------------------------------------------
+// Helper struct and function to support
+// for ( val : group_iterate( container1, container2, ... ) ) {}
+// syntax to have a for each that iterates multiple containers of the same length
+// TODO: update to use variadic arguments
+
+template< typename T1, typename T2 >
+struct group_iterate_t {
+	group_iterate_t( const T1 & v1, const T2 & v2 ) : args(v1, v2) {
+		assertf(v1.size() == v2.size(), "group iteration requires containers of the same size.");
+	};
+
+	struct iterator {
+		typedef std::tuple<typename T1::value_type, typename T2::value_type> value_type;
+		typedef typename T1::iterator T1Iter;
+		typedef typename T2::iterator T2Iter;
+		typedef std::tuple<T1Iter, T2Iter> IterTuple;
+		IterTuple it;
+		iterator( T1Iter i1, T2Iter i2 ) : it( i1, i2 ) {}
+		iterator operator++() {
+			return iterator( ++std::get<0>(it), ++std::get<1>(it) );
+		}
+		bool operator!=( const iterator &other ) const { return it != other.it; }
+		value_type operator*() const { return std::make_tuple( *std::get<0>(it), *std::get<1>(it) ); }
+	};
+	iterator begin() { return iterator( std::get<0>(args).begin(), std::get<1>(args).begin() ); }
+	iterator end() { return iterator( std::get<0>(args).end(), std::get<1>(args).end() ); }
+
+private:
+	std::tuple<T1, T2> args;
+};
+
+template< typename... Args >
+group_iterate_t<Args...> group_iterate( const Args &... args ) {
+	return group_iterate_t<Args...>(args...);
+}
 #endif // _UTILITY_H
 
Index: src/GenPoly/InstantiateGeneric.cc
===================================================================
--- src/GenPoly/InstantiateGeneric.cc	(revision 6acb935ec45eabc0c4c2c47501d76a9c231f7219)
+++ src/GenPoly/InstantiateGeneric.cc	(revision a362f977ce917e9868e8b98a81cc260e0aee5cf9)
@@ -220,22 +220,23 @@
 			assert(paramType && "Aggregate parameters should be type expressions");
 
-			switch ( (*baseParam)->get_kind() ) {
-			case TypeDecl::Any: {
-				// substitute parameter for otype; makes the type concrete or dynamic depending on the parameter
+			if ( (*baseParam)->isComplete() ) {
+				// substitute parameter for complete (otype or sized dtype) type; makes the struct concrete or dynamic depending on the parameter
 				out.push_back( paramType->clone() );
 				gt |= isPolyType( paramType->get_type() ) ? genericType::dynamic : genericType::concrete;
-				break;
-			}
-			case TypeDecl::Dtype:
-				// can pretend that any dtype is `void`
-				out.push_back( new TypeExpr( new VoidType( Type::Qualifiers() ) ) );
-				break;
-			case TypeDecl::Ftype:
-				// can pretend that any ftype is `void (*)(void)`
-				out.push_back( new TypeExpr( new FunctionType( Type::Qualifiers(), false ) ) );
-				break;
-			case TypeDecl::Ttype:
-				assertf( false, "Ttype parameters are not currently allowed as parameters to generic types." );
-				break;
+			} else switch ( (*baseParam)->get_kind() ) {
+				case TypeDecl::Dtype:
+					// can pretend that any incomplete dtype is `void`
+					out.push_back( new TypeExpr( new VoidType( Type::Qualifiers() ) ) );
+					break;
+				case TypeDecl::Ftype:
+					// can pretend that any ftype is `void (*)(void)`
+					out.push_back( new TypeExpr( new FunctionType( Type::Qualifiers(), false ) ) );
+					break;
+				case TypeDecl::Ttype:
+					assertf( false, "Ttype parameters are not currently allowed as parameters to generic types." );
+					break;
+				case TypeDecl::Any:
+					assertf( false, "otype parameters handled by baseParam->isComplete()." );
+					break;
 			}
 		}
Index: src/GenPoly/Specialize.cc
===================================================================
--- src/GenPoly/Specialize.cc	(revision 6acb935ec45eabc0c4c2c47501d76a9c231f7219)
+++ src/GenPoly/Specialize.cc	(revision a362f977ce917e9868e8b98a81cc260e0aee5cf9)
@@ -35,7 +35,5 @@
 
 namespace GenPoly {
-	class Specializer;
 	class Specialize final : public PolyMutator {
-		friend class Specializer;
 	  public:
 		using PolyMutator::mutate;
@@ -47,40 +45,13 @@
 		// virtual Expression * mutate( CommaExpr *commaExpr );
 
-		Specializer * specializer = nullptr;
 		void handleExplicitParams( ApplicationExpr *appExpr );
+		Expression * createThunkFunction( FunctionType *funType, Expression *actual, InferredParams *inferParams );
+		Expression * doSpecialization( Type *formalType, Expression *actual, InferredParams *inferParams = nullptr );
+
+		std::string paramPrefix = "_p";
 	};
 
-	class Specializer {
-	  public:
-		Specializer( Specialize & spec ) : spec( spec ), env( spec.env ), stmtsToAdd( spec.stmtsToAdd ) {}
-		virtual bool needsSpecialization( Type * formalType, Type * actualType, TypeSubstitution * env ) = 0;
-		virtual Expression *createThunkFunction( FunctionType *funType, Expression *actual, InferredParams *inferParams ) = 0;
-		virtual Expression *doSpecialization( Type *formalType, Expression *actual, InferredParams *inferParams = 0 );
-
-	  protected:
-		Specialize & spec;
-		std::string paramPrefix = "_p";
-		TypeSubstitution *& env;
-		std::list< Statement * > & stmtsToAdd;
-	};
-
-	// for normal polymorphic -> monomorphic function conversion
-	class PolySpecializer : public Specializer {
-	  public:
-		PolySpecializer( Specialize & spec ) : Specializer( spec ) {}
-		virtual bool needsSpecialization( Type * formalType, Type * actualType, TypeSubstitution * env ) override;
-		virtual Expression *createThunkFunction( FunctionType *funType, Expression *actual, InferredParams *inferParams ) override;
-	};
-
-	// // for tuple -> non-tuple function conversion
-	class TupleSpecializer : public Specializer {
-	  public:
-		TupleSpecializer( Specialize & spec ) : Specializer( spec ) {}
-		virtual bool needsSpecialization( Type * formalType, Type * actualType, TypeSubstitution * env ) override;
-		virtual Expression *createThunkFunction( FunctionType *funType, Expression *actual, InferredParams *inferParams ) override;
-	};
-
 	/// Looks up open variables in actual type, returning true if any of them are bound in the environment or formal type.
-	bool PolySpecializer::needsSpecialization( Type *formalType, Type *actualType, TypeSubstitution *env ) {
+	bool needsPolySpecialization( Type *formalType, Type *actualType, TypeSubstitution *env ) {
 		if ( env ) {
 			using namespace ResolvExpr;
@@ -106,62 +77,16 @@
 	}
 
-	/// Generates a thunk that calls `actual` with type `funType` and returns its address
-	Expression * PolySpecializer::createThunkFunction( FunctionType *funType, Expression *actual, InferredParams *inferParams ) {
-		static UniqueName thunkNamer( "_thunk" );
-
-		FunctionType *newType = funType->clone();
-		if ( env ) {
-			// it is important to replace only occurrences of type variables that occur free in the
-			// thunk's type
-			env->applyFree( newType );
-		} // if
-		// create new thunk with same signature as formal type (C linkage, empty body)
-		FunctionDecl *thunkFunc = new FunctionDecl( thunkNamer.newName(), DeclarationNode::NoStorageClass, LinkageSpec::C, newType, new CompoundStmt( noLabels ), false, false );
-		thunkFunc->fixUniqueId();
-
-		// thunks may be generated and not used - silence warning with attribute
-		thunkFunc->get_attributes().push_back( new Attribute( "unused" ) );
-
-		// thread thunk parameters into call to actual function, naming thunk parameters as we go
-		UniqueName paramNamer( paramPrefix );
-		ApplicationExpr *appExpr = new ApplicationExpr( actual );
-		for ( std::list< DeclarationWithType* >::iterator param = thunkFunc->get_functionType()->get_parameters().begin(); param != thunkFunc->get_functionType()->get_parameters().end(); ++param ) {
-			(*param )->set_name( paramNamer.newName() );
-			appExpr->get_args().push_back( new VariableExpr( *param ) );
-		} // for
-		appExpr->set_env( maybeClone( env ) );
-		if ( inferParams ) {
-			appExpr->get_inferParams() = *inferParams;
-		} // if
-
-		// handle any specializations that may still be present
-		std::string oldParamPrefix = paramPrefix;
-		paramPrefix += "p";
-		// save stmtsToAdd in oldStmts
-		std::list< Statement* > oldStmts;
-		oldStmts.splice( oldStmts.end(), stmtsToAdd );
-		spec.handleExplicitParams( appExpr );
-		paramPrefix = oldParamPrefix;
-		// write any statements added for recursive specializations into the thunk body
-		thunkFunc->get_statements()->get_kids().splice( thunkFunc->get_statements()->get_kids().end(), stmtsToAdd );
-		// restore oldStmts into stmtsToAdd
-		stmtsToAdd.splice( stmtsToAdd.end(), oldStmts );
-
-		// add return (or valueless expression) to the thunk
-		Statement *appStmt;
-		if ( funType->get_returnVals().empty() ) {
-			appStmt = new ExprStmt( noLabels, appExpr );
-		} else {
-			appStmt = new ReturnStmt( noLabels, appExpr );
-		} // if
-		thunkFunc->get_statements()->get_kids().push_back( appStmt );
-
-		// add thunk definition to queue of statements to add
-		stmtsToAdd.push_back( new DeclStmt( noLabels, thunkFunc ) );
-		// return address of thunk function as replacement expression
-		return new AddressExpr( new VariableExpr( thunkFunc ) );
-	}
-
-	Expression * Specializer::doSpecialization( Type *formalType, Expression *actual, InferredParams *inferParams ) {
+	bool needsTupleSpecialization( Type *formalType, Type *actualType, TypeSubstitution *env ) {
+		if ( FunctionType * ftype = getFunctionType( formalType ) ) {
+			return ftype->isTtype();
+		}
+		return false;
+	}
+
+	bool needsSpecialization( Type *formalType, Type *actualType, TypeSubstitution *env ) {
+		return needsPolySpecialization( formalType, actualType, env ) || needsTupleSpecialization( formalType, actualType, env );
+	}
+
+	Expression * Specialize::doSpecialization( Type *formalType, Expression *actual, InferredParams *inferParams ) {
 		assertf( actual->has_result(), "attempting to specialize an untyped expression" );
 		if ( needsSpecialization( formalType, actual->get_result(), env ) ) {
@@ -185,11 +110,4 @@
 	}
 
-	bool TupleSpecializer::needsSpecialization( Type *formalType, Type *actualType, TypeSubstitution *env ) {
-		if ( FunctionType * ftype = getFunctionType( formalType ) ) {
-			return ftype->isTtype();
-		}
-		return false;
-	}
-
 	/// restructures arg to match the structure of a single formal parameter. Assumes that atomic types are compatible (as the Resolver should have ensured this)
 	template< typename OutIterator >
@@ -207,21 +125,26 @@
 
 	/// restructures the ttype argument to match the structure of the formal parameters of the actual function.
-	// [begin, end) are the formal parameters.
-	// args is the list of arguments currently given to the actual function, the last of which needs to be restructured.
+	/// [begin, end) are the formal parameters.
+	/// args is the list of arguments currently given to the actual function, the last of which needs to be restructured.
 	template< typename Iterator, typename OutIterator >
 	void fixLastArg( Expression * last, Iterator begin, Iterator end, OutIterator out ) {
-		// safe_dynamic_cast for the assertion
-		safe_dynamic_cast< TupleType * >( last->get_result() );
-		unsigned idx = 0;
-		for ( ; begin != end; ++begin ) {
-			DeclarationWithType * formal = *begin;
-			Type * formalType = formal->get_type();
-			matchOneFormal( last, idx, formalType, out );
-		}
-		delete last;
-	}
-
-	Expression * TupleSpecializer::createThunkFunction( FunctionType *funType, Expression *actual, InferredParams *inferParams ) {
-		static UniqueName thunkNamer( "_tupleThunk" );
+		if ( Tuples::isTtype( last->get_result() ) ) {
+			*out++ = last;
+		} else {
+			// safe_dynamic_cast for the assertion
+			safe_dynamic_cast< TupleType * >( last->get_result() );
+			unsigned idx = 0;
+			for ( ; begin != end; ++begin ) {
+				DeclarationWithType * formal = *begin;
+				Type * formalType = formal->get_type();
+				matchOneFormal( last, idx, formalType, out );
+			}
+			delete last;
+		}
+	}
+
+	/// Generates a thunk that calls `actual` with type `funType` and returns its address
+	Expression * Specialize::createThunkFunction( FunctionType *funType, Expression *actual, InferredParams *inferParams ) {
+		static UniqueName thunkNamer( "_thunk" );
 
 		FunctionType *newType = funType->clone();
@@ -253,5 +176,4 @@
 		std::list< DeclarationWithType * >::iterator formalEnd = funType->get_parameters().end();
 
-		Expression * last = nullptr;
 		for ( DeclarationWithType* param : thunkFunc->get_functionType()->get_parameters() ) {
 			// walk the parameters to the actual function alongside the parameters to the thunk to find the location where the ttype parameter begins to satisfy parameters in the actual function.
@@ -259,5 +181,5 @@
 			assertf( formalBegin != formalEnd, "Reached end of formal parameters before finding ttype parameter" );
 			if ( Tuples::isTtype((*formalBegin)->get_type()) ) {
-				last = new VariableExpr( param );
+				fixLastArg( new VariableExpr( param ), actualBegin, actualEnd, back_inserter( appExpr->get_args() ) );
 				break;
 			}
@@ -268,6 +190,4 @@
 			appExpr->get_args().push_back( new VariableExpr( param ) );
 		} // for
-		assert( last );
-		fixLastArg( last, actualBegin, actualEnd, back_inserter( appExpr->get_args() ) );
 		appExpr->set_env( maybeClone( env ) );
 		if ( inferParams ) {
@@ -281,5 +201,5 @@
 		std::list< Statement* > oldStmts;
 		oldStmts.splice( oldStmts.end(), stmtsToAdd );
-		spec.mutate( appExpr );
+		mutate( appExpr );
 		paramPrefix = oldParamPrefix;
 		// write any statements added for recursive specializations into the thunk body
@@ -311,5 +231,5 @@
 		std::list< Expression* >::iterator actual;
 		for ( formal = function->get_parameters().begin(), actual = appExpr->get_args().begin(); formal != function->get_parameters().end() && actual != appExpr->get_args().end(); ++formal, ++actual ) {
-			*actual = specializer->doSpecialization( (*formal )->get_type(), *actual, &appExpr->get_inferParams() );
+			*actual = doSpecialization( (*formal )->get_type(), *actual, &appExpr->get_inferParams() );
 		}
 	}
@@ -322,8 +242,10 @@
 			// create thunks for the inferred parameters
 			// don't need to do this for intrinsic calls, because they aren't actually passed
+			// need to handle explicit params before inferred params so that explicit params do not recieve a changed set of inferParams (and change them again)
+			// alternatively, if order starts to matter then copy appExpr's inferParams and pass them to handleExplicitParams.
+			handleExplicitParams( appExpr );
 			for ( InferredParams::iterator inferParam = appExpr->get_inferParams().begin(); inferParam != appExpr->get_inferParams().end(); ++inferParam ) {
-				inferParam->second.expr = specializer->doSpecialization( inferParam->second.formalType, inferParam->second.expr, inferParam->second.inferParams.get() );
+				inferParam->second.expr = doSpecialization( inferParam->second.formalType, inferParam->second.expr, inferParam->second.inferParams.get() );
 			}
-			handleExplicitParams( appExpr );
 		}
 		return appExpr;
@@ -333,5 +255,5 @@
 		addrExpr->get_arg()->acceptMutator( *this );
 		assert( addrExpr->has_result() );
-		addrExpr->set_arg( specializer->doSpecialization( addrExpr->get_result(), addrExpr->get_arg() ) );
+		addrExpr->set_arg( doSpecialization( addrExpr->get_result(), addrExpr->get_arg() ) );
 		return addrExpr;
 	}
@@ -343,5 +265,5 @@
 			return castExpr;
 		}
-		Expression *specialized = specializer->doSpecialization( castExpr->get_result(), castExpr->get_arg() );
+		Expression *specialized = doSpecialization( castExpr->get_result(), castExpr->get_arg() );
 		if ( specialized != castExpr->get_arg() ) {
 			// assume here that the specialization incorporates the cast
@@ -370,11 +292,4 @@
 	void convertSpecializations( std::list< Declaration* >& translationUnit ) {
 		Specialize spec;
-
-		TupleSpecializer tupleSpec( spec );
-		spec.specializer = &tupleSpec;
-		mutateAll( translationUnit, spec );
-
-		PolySpecializer polySpec( spec );
-		spec.specializer = &polySpec;
 		mutateAll( translationUnit, spec );
 	}
Index: src/InitTweak/FixGlobalInit.cc
===================================================================
--- src/InitTweak/FixGlobalInit.cc	(revision 6acb935ec45eabc0c4c2c47501d76a9c231f7219)
+++ src/InitTweak/FixGlobalInit.cc	(revision a362f977ce917e9868e8b98a81cc260e0aee5cf9)
@@ -84,6 +84,6 @@
 			// for library code are run before constructors and destructors for user code,
 			// specify a priority when building the library. Priorities 0-100 are reserved by gcc.
-			ctorParameters.push_back( new ConstantExpr( Constant::from_int( 101 ) ) );
-			dtorParameters.push_back( new ConstantExpr( Constant::from_int( 101 ) ) );
+			ctorParameters.push_back( new ConstantExpr( Constant::from_int( 102 ) ) );
+			dtorParameters.push_back( new ConstantExpr( Constant::from_int( 102 ) ) );
 		}
 		initFunction = new FunctionDecl( "_init_" + fixedName, DeclarationNode::Static, LinkageSpec::C, new FunctionType( Type::Qualifiers(), false ), new CompoundStmt( noLabels ), false, false );
Index: src/InitTweak/FixInit.cc
===================================================================
--- src/InitTweak/FixInit.cc	(revision 6acb935ec45eabc0c4c2c47501d76a9c231f7219)
+++ src/InitTweak/FixInit.cc	(revision a362f977ce917e9868e8b98a81cc260e0aee5cf9)
@@ -21,4 +21,5 @@
 #include <unordered_set>
 #include "InitTweak.h"
+#include "GenInit.h"
 #include "FixInit.h"
 #include "FixGlobalInit.h"
@@ -86,9 +87,8 @@
 			/// create and resolve ctor/dtor expression: fname(var, [cpArg])
 			Expression * makeCtorDtor( const std::string & fname, ObjectDecl * var, Expression * cpArg = NULL );
-			Expression * makeCtorDtor( const std::string & fname, Expression * thisArg, Expression * cpArg = NULL );
 			/// true if type does not need to be copy constructed to ensure correctness
 			bool skipCopyConstruct( Type * type );
 			void copyConstructArg( Expression *& arg, ImplicitCopyCtorExpr * impCpCtorExpr );
-			void destructRet( Expression * ret, ImplicitCopyCtorExpr * impCpCtorExpr );
+			void destructRet( ObjectDecl * ret, ImplicitCopyCtorExpr * impCpCtorExpr );
 
 			TypeSubstitution * env;
@@ -398,12 +398,8 @@
 		Expression * ResolveCopyCtors::makeCtorDtor( const std::string & fname, ObjectDecl * var, Expression * cpArg ) {
 			assert( var );
-			return makeCtorDtor( fname, new AddressExpr( new VariableExpr( var ) ), cpArg );
-		}
-
-		Expression * ResolveCopyCtors::makeCtorDtor( const std::string & fname, Expression * thisArg, Expression * cpArg ) {
-			assert( thisArg );
-			UntypedExpr * untyped = new UntypedExpr( new NameExpr( fname ) );
-			untyped->get_args().push_back( thisArg );
-			if (cpArg) untyped->get_args().push_back( cpArg->clone() );
+			// arrays are not copy constructed, so this should always be an ExprStmt
+			ImplicitCtorDtorStmt * stmt = genCtorDtor( fname, var, cpArg );
+			ExprStmt * exprStmt = safe_dynamic_cast< ExprStmt * >( stmt->get_callStmt() );
+			Expression * untyped = exprStmt->get_expr();
 
 			// resolve copy constructor
@@ -420,5 +416,5 @@
 			} // if
 
-			delete untyped;
+			delete stmt;
 			return resolved;
 		}
@@ -456,6 +452,6 @@
 		}
 
-		void ResolveCopyCtors::destructRet( Expression * ret, ImplicitCopyCtorExpr * impCpCtorExpr ) {
-			impCpCtorExpr->get_dtors().push_front( makeCtorDtor( "^?{}", new AddressExpr( ret ) ) );
+		void ResolveCopyCtors::destructRet( ObjectDecl * ret, ImplicitCopyCtorExpr * impCpCtorExpr ) {
+			impCpCtorExpr->get_dtors().push_front( makeCtorDtor( "^?{}", ret ) );
 		}
 
@@ -487,5 +483,5 @@
 				if ( ! result->get_isLvalue() ) {
 					// destructing lvalue returns is bad because it can cause multiple destructor calls to the same object - the returned object is not a temporary
-					destructRet( new VariableExpr( ret ), impCpCtorExpr );
+					destructRet( ret, impCpCtorExpr );
 				}
 			} // for
@@ -515,5 +511,5 @@
 				last->set_expr( makeCtorDtor( "?{}", ret, last->get_expr() ) );
 
-				stmtExpr->get_dtors().push_front( makeCtorDtor( "^?{}", new AddressExpr( new VariableExpr( ret ) ) ) );
+				stmtExpr->get_dtors().push_front( makeCtorDtor( "^?{}", ret ) );
 			} // if
 
Index: src/InitTweak/GenInit.cc
===================================================================
--- src/InitTweak/GenInit.cc	(revision 6acb935ec45eabc0c4c2c47501d76a9c231f7219)
+++ src/InitTweak/GenInit.cc	(revision a362f977ce917e9868e8b98a81cc260e0aee5cf9)
@@ -247,4 +247,14 @@
 			managedTypes.insert( SymTab::Mangler::mangle( type->get_base() ) );
 		}
+	}
+
+	ImplicitCtorDtorStmt * genCtorDtor( const std::string & fname, ObjectDecl * objDecl, Expression * arg ) {
+		// call into genImplicitCall from Autogen.h to generate calls to ctor/dtor
+		assertf( objDecl, "genCtorDtor passed null objDecl" );
+		std::list< Statement * > stmts;
+		InitExpander srcParam( maybeClone( arg ) );
+		SymTab::genImplicitCall( srcParam, new VariableExpr( objDecl ), fname, back_inserter( stmts ), objDecl );
+		assert( stmts.size() <= 1 );
+		return stmts.size() == 1 ? safe_dynamic_cast< ImplicitCtorDtorStmt * >( stmts.front() ) : nullptr;
 	}
 
Index: src/InitTweak/GenInit.h
===================================================================
--- src/InitTweak/GenInit.h	(revision 6acb935ec45eabc0c4c2c47501d76a9c231f7219)
+++ src/InitTweak/GenInit.h	(revision a362f977ce917e9868e8b98a81cc260e0aee5cf9)
@@ -28,4 +28,7 @@
 	void genInit( std::list< Declaration * > & translationUnit );
 
+  /// generates a single ctor/dtor statement using objDecl as the 'this' parameter and arg as the optional argument
+  ImplicitCtorDtorStmt * genCtorDtor( const std::string & fname, ObjectDecl * objDecl, Expression * arg = nullptr );
+
 	/// creates an appropriate ConstructorInit node which contains a constructor, destructor, and C-initializer
 	ConstructorInit * genCtorInit( ObjectDecl * objDecl );
Index: src/InitTweak/InitTweak.cc
===================================================================
--- src/InitTweak/InitTweak.cc	(revision 6acb935ec45eabc0c4c2c47501d76a9c231f7219)
+++ src/InitTweak/InitTweak.cc	(revision a362f977ce917e9868e8b98a81cc260e0aee5cf9)
@@ -327,4 +327,6 @@
 			} else if ( ApplicationExpr * appExpr = dynamic_cast< ApplicationExpr * > ( expr ) ) {
 				return handleDerefCalledFunction( appExpr );
+			} else if ( AddressExpr * addrExpr = dynamic_cast< AddressExpr * >( expr ) ) {
+				return getCalledFunction( addrExpr->get_arg() );
 			}
 			return nullptr;
@@ -336,5 +338,5 @@
 		if ( ! appExpr ) return NULL;
 		DeclarationWithType * function = getCalledFunction( appExpr->get_function() );
-		assert( function );
+		assertf( function, "getCalledFunction returned nullptr: %s", toString( appExpr->get_function() ).c_str() );
 		// check for Intrinsic only - don't want to remove all overridable ctor/dtors because autogenerated ctor/dtor
 		// will call all member dtors, and some members may have a user defined dtor.
@@ -386,6 +388,13 @@
 		} else if ( UntypedExpr * untypedExpr = dynamic_cast< UntypedExpr * >( callExpr ) ) {
 			return callArg( untypedExpr, pos );
+		} else if ( TupleAssignExpr * tupleExpr = dynamic_cast< TupleAssignExpr * > ( callExpr ) ) {
+			std::list< Statement * > & stmts = tupleExpr->get_stmtExpr()->get_statements()->get_kids();
+			assertf( ! stmts.empty(), "TupleAssignExpr somehow has no statements." );
+			ExprStmt * stmt = safe_dynamic_cast< ExprStmt * >( stmts.back() );
+			TupleExpr * tuple = safe_dynamic_cast< TupleExpr * >( stmt->get_expr() );
+			assertf( ! tuple->get_exprs().empty(), "TupleAssignExpr somehow has empty tuple expr." );
+			return getCallArg( tuple->get_exprs().front(), pos );
 		} else {
-			assertf( false, "Unexpected expression type passed to getCallArg" );
+			assertf( false, "Unexpected expression type passed to getCallArg: %s", toString( callExpr ).c_str() );
 		}
 	}
@@ -538,4 +547,23 @@
 	}
 
+	FunctionDecl * isAssignment( Declaration * decl ) {
+		return isCopyFunction( decl, "?=?" );
+	}
+	FunctionDecl * isDestructor( Declaration * decl ) {
+		if ( isDestructor( decl->get_name() ) ) {
+			return dynamic_cast< FunctionDecl * >( decl );
+		}
+		return nullptr;
+	}
+	FunctionDecl * isDefaultConstructor( Declaration * decl ) {
+		if ( isConstructor( decl->get_name() ) ) {
+			if ( FunctionDecl * func = dynamic_cast< FunctionDecl * >( decl ) ) {
+				if ( func->get_functionType()->get_parameters().size() == 1 ) {
+					return func;
+				}
+			}
+		}
+		return nullptr;
+	}
 	FunctionDecl * isCopyConstructor( Declaration * decl ) {
 		return isCopyFunction( decl, "?{}" );
Index: src/InitTweak/InitTweak.h
===================================================================
--- src/InitTweak/InitTweak.h	(revision 6acb935ec45eabc0c4c2c47501d76a9c231f7219)
+++ src/InitTweak/InitTweak.h	(revision a362f977ce917e9868e8b98a81cc260e0aee5cf9)
@@ -32,4 +32,7 @@
 	bool isCtorDtorAssign( const std::string & );
 
+	FunctionDecl * isAssignment( Declaration * decl );
+	FunctionDecl * isDestructor( Declaration * decl );
+	FunctionDecl * isDefaultConstructor( Declaration * decl );
 	FunctionDecl * isCopyConstructor( Declaration * decl );
 	FunctionDecl * isCopyFunction( Declaration * decl, const std::string & fname );
Index: src/Parser/TypeData.cc
===================================================================
--- src/Parser/TypeData.cc	(revision 6acb935ec45eabc0c4c2c47501d76a9c231f7219)
+++ src/Parser/TypeData.cc	(revision a362f977ce917e9868e8b98a81cc260e0aee5cf9)
@@ -57,4 +57,5 @@
 		aggregate.actuals = nullptr;
 		aggregate.fields = nullptr;
+		aggregate.body = false;
 		break;
 	  case AggregateInst:
Index: src/ResolvExpr/Unify.cc
===================================================================
--- src/ResolvExpr/Unify.cc	(revision 6acb935ec45eabc0c4c2c47501d76a9c231f7219)
+++ src/ResolvExpr/Unify.cc	(revision a362f977ce917e9868e8b98a81cc260e0aee5cf9)
@@ -123,31 +123,4 @@
 	}
 
-	struct CompleteTypeChecker : public Visitor {
-		virtual void visit( VoidType *basicType ) { status = false; }
-		virtual void visit( BasicType *basicType ) {}
-		virtual void visit( PointerType *pointerType ) {}
-		virtual void visit( ArrayType *arrayType ) { status = ! arrayType->get_isVarLen(); }
-		virtual void visit( FunctionType *functionType ) {}
-		virtual void visit( StructInstType *aggregateUseType ) { status = aggregateUseType->get_baseStruct()->has_body(); }
-		virtual void visit( UnionInstType *aggregateUseType ) { status = aggregateUseType->get_baseUnion()->has_body(); }
-		// xxx - enum inst does not currently contain a pointer to base, this should be fixed.
-		virtual void visit( EnumInstType *aggregateUseType ) { /* status = aggregateUseType->get_baseEnum()->hasBody(); */ }
-		virtual void visit( TraitInstType *aggregateUseType ) { assert( false ); }
-		virtual void visit( TypeInstType *aggregateUseType ) { status = aggregateUseType->get_baseType()->isComplete(); }
-		virtual void visit( TupleType *tupleType ) {} // xxx - not sure if this is right, might need to recursively check complete-ness
-		virtual void visit( TypeofType *typeofType ) { assert( false ); }
-		virtual void visit( AttrType *attrType ) { assert( false ); } // xxx - not sure what to do here
-		virtual void visit( VarArgsType *varArgsType ){} // xxx - is this right?
-		virtual void visit( ZeroType *zeroType ) {}
-		virtual void visit( OneType *oneType ) {}
-		bool status = true;
-	};
-	bool isComplete( Type * type ) {
-		CompleteTypeChecker checker;
-		assert( type );
-		type->accept( checker );
-		return checker.status;
-	}
-
 	bool tyVarCompatible( const TypeDecl::Data & data, Type *type, const SymTab::Indexer &indexer ) {
 		switch ( data.kind ) {
@@ -158,10 +131,10 @@
 			// type must also be complete
 			// xxx - should this also check that type is not a tuple type and that it's not a ttype?
-			return ! isFtype( type, indexer ) && (! data.isComplete || isComplete( type ));
+			return ! isFtype( type, indexer ) && (! data.isComplete || type->isComplete() );
 		  case TypeDecl::Ftype:
 			return isFtype( type, indexer );
 			case TypeDecl::Ttype:
 			// ttype unifies with any tuple type
-			return dynamic_cast< TupleType * >( type );
+			return dynamic_cast< TupleType * >( type ) || Tuples::isTtype( type );
 		} // switch
 		return false;
@@ -488,10 +461,10 @@
 	}
 
-	template< typename Iterator >
-	std::unique_ptr<Type> combineTypes( Iterator begin, Iterator end ) {
+	template< typename Iterator, typename Func >
+	std::unique_ptr<Type> combineTypes( Iterator begin, Iterator end, Func & toType ) {
 		std::list< Type * > types;
 		for ( ; begin != end; ++begin ) {
 			// it's guaranteed that a ttype variable will be bound to a flat tuple, so ensure that this results in a flat tuple
-			flatten( (*begin)->get_type(), back_inserter( types ) );
+			flatten( toType( *begin ), back_inserter( types ) );
 		}
 		return std::unique_ptr<Type>( new TupleType( Type::Qualifiers(), types ) );
@@ -500,4 +473,5 @@
 	template< typename Iterator1, typename Iterator2 >
 	bool unifyDeclList( Iterator1 list1Begin, Iterator1 list1End, Iterator2 list2Begin, Iterator2 list2End, TypeEnvironment &env, AssertionSet &needAssertions, AssertionSet &haveAssertions, const OpenVarSet &openVars, const SymTab::Indexer &indexer ) {
+		auto get_type = [](DeclarationWithType * dwt){ return dwt->get_type(); };
 		for ( ; list1Begin != list1End && list2Begin != list2End; ++list1Begin, ++list2Begin ) {
 			Type * t1 = (*list1Begin)->get_type();
@@ -509,8 +483,8 @@
 			if ( isTtype1 && ! isTtype2 ) {
 				// combine all of the things in list2, then unify
-				return unifyExact( t1, combineTypes( list2Begin, list2End ).get(), env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer );
+				return unifyExact( t1, combineTypes( list2Begin, list2End, get_type ).get(), env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer );
 			} else if ( isTtype2 && ! isTtype1 ) {
 				// combine all of the things in list1, then unify
-				return unifyExact( combineTypes( list1Begin, list1End ).get(), t2, env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer );
+				return unifyExact( combineTypes( list1Begin, list1End, get_type ).get(), t2, env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer );
 			} else if ( ! unifyExact( t1, t2, env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer ) ) {
 				return false;
@@ -522,5 +496,5 @@
 			Type * t1 = (*list1Begin)->get_type();
 			if ( Tuples::isTtype( t1 ) ) {
-				return unifyExact( t1, combineTypes( list2Begin, list2End ).get(), env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer );
+				return unifyExact( t1, combineTypes( list2Begin, list2End, get_type ).get(), env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer );
 			} else return false;
 		} else if ( list2Begin != list2End ) {
@@ -528,5 +502,5 @@
 			Type * t2 = (*list2Begin)->get_type();
 			if ( Tuples::isTtype( t2 ) ) {
-				return unifyExact( combineTypes( list1Begin, list1End ).get(), t2, env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer );
+				return unifyExact( combineTypes( list1Begin, list1End, get_type ).get(), t2, env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer );
 			} else return false;
 		} else {
@@ -665,21 +639,54 @@
 	template< typename Iterator1, typename Iterator2 >
 	bool unifyList( Iterator1 list1Begin, Iterator1 list1End, Iterator2 list2Begin, Iterator2 list2End, TypeEnvironment &env, AssertionSet &needAssertions, AssertionSet &haveAssertions, const OpenVarSet &openVars, WidenMode widenMode, const SymTab::Indexer &indexer ) {
+		auto get_type = [](Type * t) { return t; };
 		for ( ; list1Begin != list1End && list2Begin != list2End; ++list1Begin, ++list2Begin ) {
-			Type *commonType = 0;
-			if ( ! unifyInexact( *list1Begin, *list2Begin, env, needAssertions, haveAssertions, openVars, widenMode, indexer, commonType ) ) {
+			Type * t1 = *list1Begin;
+			Type * t2 = *list2Begin;
+			bool isTtype1 = Tuples::isTtype( t1 );
+			bool isTtype2 = Tuples::isTtype( t2 );
+			// xxx - assumes ttype must be last parameter
+			// xxx - there may be a nice way to refactor this, but be careful because the argument positioning might matter in some cases.
+			if ( isTtype1 && ! isTtype2 ) {
+				// combine all of the things in list2, then unify
+				return unifyExact( t1, combineTypes( list2Begin, list2End, get_type ).get(), env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer );
+			} else if ( isTtype2 && ! isTtype1 ) {
+				// combine all of the things in list1, then unify
+				return unifyExact( combineTypes( list1Begin, list1End, get_type ).get(), t2, env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer );
+			} else if ( ! unifyExact( t1, t2, env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer ) ) {
 				return false;
-			}
-			delete commonType;
+			} // if
+
 		} // for
-		if ( list1Begin != list1End || list2Begin != list2End ) {
-			return false;
+		if ( list1Begin != list1End ) {
+			// try unifying empty tuple type with ttype
+			Type * t1 = *list1Begin;
+			if ( Tuples::isTtype( t1 ) ) {
+				return unifyExact( t1, combineTypes( list2Begin, list2End, get_type ).get(), env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer );
+			} else return false;
+		} else if ( list2Begin != list2End ) {
+			// try unifying empty tuple type with ttype
+			Type * t2 = *list2Begin;
+			if ( Tuples::isTtype( t2 ) ) {
+				return unifyExact( combineTypes( list1Begin, list1End, get_type ).get(), t2, env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer );
+			} else return false;
 		} else {
 			return true;
-		} //if
+		} // if
 	}
 
 	void Unify::visit(TupleType *tupleType) {
 		if ( TupleType *otherTuple = dynamic_cast< TupleType* >( type2 ) ) {
-			result = unifyList( tupleType->get_types().begin(), tupleType->get_types().end(), otherTuple->get_types().begin(), otherTuple->get_types().end(), env, needAssertions, haveAssertions, openVars, widenMode, indexer );
+			std::unique_ptr<TupleType> flat1( tupleType->clone() );
+			std::unique_ptr<TupleType> flat2( otherTuple->clone() );
+			std::list<Type *> types1, types2;
+
+			TtypeExpander expander( env );
+			flat1->acceptMutator( expander );
+			flat2->acceptMutator( expander );
+
+			flatten( flat1.get(), back_inserter( types1 ) );
+			flatten( flat2.get(), back_inserter( types2 ) );
+
+			result = unifyList( types1.begin(), types1.end(), types2.begin(), types2.end(), env, needAssertions, haveAssertions, openVars, widenMode, indexer );
 		} // if
 	}
Index: src/SymTab/Autogen.cc
===================================================================
--- src/SymTab/Autogen.cc	(revision 6acb935ec45eabc0c4c2c47501d76a9c231f7219)
+++ src/SymTab/Autogen.cc	(revision a362f977ce917e9868e8b98a81cc260e0aee5cf9)
@@ -25,4 +25,5 @@
 #include "Autogen.h"
 #include "GenPoly/ScopedSet.h"
+#include "Common/ScopedMap.h"
 #include "SymTab/Mangler.h"
 #include "GenPoly/DeclMutator.h"
@@ -30,6 +31,16 @@
 namespace SymTab {
 	Type * SizeType = 0;
-
-	class AutogenerateRoutines : public Visitor {
+	typedef ScopedMap< std::string, bool > TypeMap;
+
+	/// Data used to generate functions generically. Specifically, the name of the generated function, a function which generates the routine protoype, and a map which contains data to determine whether a function should be generated.
+	struct FuncData {
+		typedef FunctionType * (*TypeGen)( Type * );
+		FuncData( const std::string & fname, const TypeGen & genType, TypeMap & map ) : fname( fname ), genType( genType ), map( map ) {}
+		std::string fname;
+		TypeGen genType;
+		TypeMap & map;
+	};
+
+	class AutogenerateRoutines final : public Visitor {
 	  public:
 		std::list< Declaration * > &get_declsToAdd() { return declsToAdd; }
@@ -37,4 +48,6 @@
 		typedef Visitor Parent;
 		using Parent::visit;
+
+		AutogenerateRoutines();
 
 		virtual void visit( EnumDecl *enumDecl );
@@ -57,4 +70,9 @@
 		std::set< std::string > structsDone;
 		unsigned int functionNesting = 0;     // current level of nested functions
+		/// Note: the following maps could be ScopedSets, but it should be easier to work
+		/// deleted functions in if they are maps, since the value false can be inserted
+		/// at the current scope without affecting outer scopes or requiring copies.
+		TypeMap copyable, assignable, constructable, destructable;
+		std::vector< FuncData > data;
 	};
 
@@ -144,4 +162,66 @@
 		decl->fixUniqueId();
 		return decl;
+	}
+
+	/// inserts base type of first argument into map if pred(funcDecl) is true
+	void insert( FunctionDecl *funcDecl, TypeMap & map, FunctionDecl * (*pred)(Declaration *) ) {
+		// insert type into constructable, etc. map if appropriate
+		if ( pred( funcDecl ) ) {
+			FunctionType * ftype = funcDecl->get_functionType();
+			assert( ! ftype->get_parameters().empty() );
+			Type * t = safe_dynamic_cast< PointerType * >( ftype->get_parameters().front()->get_type() )->get_base();
+			map.insert( Mangler::mangleType( t ), true );
+		}
+	}
+
+	/// using map and t, determines if is constructable, etc.
+	bool lookup( const TypeMap & map, Type * t ) {
+		if ( dynamic_cast< PointerType * >( t ) ) {
+			// will need more complicated checking if we want this to work with pointer types, since currently
+			return true;
+		} else if ( ArrayType * at = dynamic_cast< ArrayType * >( t ) ) {
+			// an array's constructor, etc. is generated on the fly based on the base type's constructor, etc.
+			return lookup( map, at->get_base() );
+		}
+		TypeMap::const_iterator it = map.find( Mangler::mangleType( t ) );
+		if ( it != map.end() ) return it->second;
+		// something that does not appear in the map is by default not constructable, etc.
+		return false;
+	}
+
+	/// using map and aggr, examines each member to determine if constructor, etc. should be generated
+	template<typename AggrDecl>
+	bool shouldGenerate( const TypeMap & map, AggrDecl * aggr ) {
+		for ( Declaration * dcl : aggr->get_members() ) {
+			if ( DeclarationWithType * dwt = dynamic_cast< DeclarationWithType * >( dcl ) ) {
+				if ( ! lookup( map, dwt->get_type() ) ) return false;
+			}
+		}
+		return true;
+	}
+
+	/// data structure for abstracting the generation of special functions
+	template< typename OutputIterator >
+	struct FuncGenerator {
+		StructDecl *aggregateDecl;
+		StructInstType *refType;
+		unsigned int functionNesting;
+		const std::list< TypeDecl* > & typeParams;
+		OutputIterator out;
+		FuncGenerator( StructDecl *aggregateDecl, StructInstType *refType, unsigned int functionNesting, const std::list< TypeDecl* > & typeParams, OutputIterator out ) : aggregateDecl( aggregateDecl ), refType( refType ), functionNesting( functionNesting ), typeParams( typeParams ), out( out ) {}
+
+		/// generates a function (?{}, ?=?, ^?{}) based on the data argument and members. If function is generated, inserts the type into the map.
+		void gen( const FuncData & data ) {
+			if ( ! shouldGenerate( data.map, aggregateDecl ) ) return;
+			FunctionType * ftype = data.genType( refType );
+			cloneAll( typeParams, ftype->get_forall() );
+			*out++ = genFunc( data.fname, ftype, functionNesting );
+			data.map.insert( Mangler::mangleType( refType ), true );
+		}
+	};
+
+	template< typename OutputIterator >
+	FuncGenerator<OutputIterator> makeFuncGenerator( StructDecl *aggregateDecl, StructInstType *refType, unsigned int functionNesting, const std::list< TypeDecl* > & typeParams, OutputIterator out ) {
+		return FuncGenerator<OutputIterator>( aggregateDecl, refType, functionNesting, typeParams, out );
 	}
 
@@ -308,28 +388,17 @@
 
 	/// generates struct constructors, destructor, and assignment functions
-	void makeStructFunctions( StructDecl *aggregateDecl, StructInstType *refType, unsigned int functionNesting, std::list< Declaration * > & declsToAdd ) {
-
+	void makeStructFunctions( StructDecl *aggregateDecl, StructInstType *refType, unsigned int functionNesting, std::list< Declaration * > & declsToAdd, const std::vector< FuncData > & data ) {
 		// Make function polymorphic in same parameters as generic struct, if applicable
 		const std::list< TypeDecl* > & typeParams = aggregateDecl->get_parameters(); // List of type variables to be placed on the generated functions
 		bool isDynamicLayout = hasDynamicLayout( aggregateDecl );  // NOTE this flag is an incredibly ugly kludge; we should fix the assignment signature instead (ditto for union)
 
-		// T ?=?(T *, T);
-		FunctionType *assignType = genAssignType( refType );
-		cloneAll( typeParams, assignType->get_forall() );
-
-		// void ?{}(T *); void ^?{}(T *);
-		FunctionType *ctorType = genDefaultType( refType );
-		cloneAll( typeParams, ctorType->get_forall() );
-		FunctionType *dtorType = genDefaultType( refType );
-		cloneAll( typeParams, dtorType->get_forall() );
-
-		// void ?{}(T *, T);
-		FunctionType *copyCtorType = genCopyType( refType );
-		cloneAll( typeParams, copyCtorType->get_forall() );
-
-		FunctionDecl *assignDecl = genFunc( "?=?", assignType, functionNesting );
-		FunctionDecl *ctorDecl = genFunc( "?{}", ctorType, functionNesting );
-		FunctionDecl *copyCtorDecl = genFunc( "?{}", copyCtorType, functionNesting );
-		FunctionDecl *dtorDecl = genFunc( "^?{}", dtorType, functionNesting );
+		// generate each of the functions based on the supplied FuncData objects
+		std::list< FunctionDecl * > newFuncs;
+		auto generator = makeFuncGenerator( aggregateDecl, refType, functionNesting, typeParams, back_inserter( newFuncs ) );
+		for ( const FuncData & d : data ) {
+			generator.gen( d );
+		}
+		// field ctors are only generated if default constructor and copy constructor are both generated
+		unsigned numCtors = std::count_if( newFuncs.begin(), newFuncs.end(), [](FunctionDecl * dcl) { return InitTweak::isConstructor( dcl->get_name() ); } );
 
 		if ( functionNesting == 0 ) {
@@ -338,54 +407,58 @@
 			// Note: this is necessary if we want structs which contain
 			// generic (otype) structs as members.
-			addForwardDecl( assignDecl, declsToAdd );
-			addForwardDecl( ctorDecl, declsToAdd );
-			addForwardDecl( copyCtorDecl, declsToAdd );
-			addForwardDecl( dtorDecl, declsToAdd );
+			for ( FunctionDecl * dcl : newFuncs ) {
+				addForwardDecl( dcl, declsToAdd );
+			}
+		}
+
+		for ( FunctionDecl * dcl : newFuncs ) {
+			// generate appropriate calls to member ctor, assignment
+			// destructor needs to do everything in reverse, so pass "forward" based on whether the function is a destructor
+			if ( ! InitTweak::isDestructor( dcl->get_name() ) ) {
+				makeStructFunctionBody( aggregateDecl->get_members().begin(), aggregateDecl->get_members().end(), dcl, isDynamicLayout );
+			} else {
+				makeStructFunctionBody( aggregateDecl->get_members().rbegin(), aggregateDecl->get_members().rend(), dcl, isDynamicLayout, false );
+			}
+			if ( InitTweak::isAssignment( dcl->get_name() ) ) {
+				// assignment needs to return a value
+				FunctionType * assignType = dcl->get_functionType();
+				assert( assignType->get_parameters().size() == 2 );
+				ObjectDecl * srcParam = safe_dynamic_cast< ObjectDecl * >( assignType->get_parameters().back() );
+				dcl->get_statements()->get_kids().push_back( new ReturnStmt( noLabels, new VariableExpr( srcParam ) ) );
+			}
+			declsToAdd.push_back( dcl );
 		}
 
 		// create constructors which take each member type as a parameter.
 		// for example, for struct A { int x, y; }; generate
-		// void ?{}(A *, int) and void ?{}(A *, int, int)
-		std::list<Declaration *> memCtors;
-		FunctionType * memCtorType = ctorType->clone();
-		for ( std::list<Declaration *>::iterator i = aggregateDecl->get_members().begin(); i != aggregateDecl->get_members().end(); ++i ) {
-			DeclarationWithType * member = dynamic_cast<DeclarationWithType *>( *i );
-			assert( member );
-			if ( isUnnamedBitfield( dynamic_cast< ObjectDecl * > ( member ) ) ) {
-				// don't make a function whose parameter is an unnamed bitfield
-				continue;
-			} else if ( member->get_name() == "" ) {
-				// don't assign to anonymous members
-				// xxx - this is a temporary fix. Anonymous members tie into
-				// our inheritance model. I think the correct way to handle this is to
-				// cast the structure to the type of the member and let the resolver
-				// figure out whether it's valid and have a pass afterwards that fixes
-				// the assignment to use pointer arithmetic with the offset of the
-				// member, much like how generic type members are handled.
-				continue;
-			}
-			memCtorType->get_parameters().push_back( new ObjectDecl( member->get_name(), DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, member->get_type()->clone(), 0 ) );
-			FunctionDecl * ctor = genFunc( "?{}", memCtorType->clone(), functionNesting );
-			makeStructFieldCtorBody( aggregateDecl->get_members().begin(), aggregateDecl->get_members().end(), ctor, isDynamicLayout );
-			memCtors.push_back( ctor );
-		}
-		delete memCtorType;
-
-		// generate appropriate calls to member ctor, assignment
-		makeStructFunctionBody( aggregateDecl->get_members().begin(), aggregateDecl->get_members().end(), assignDecl, isDynamicLayout );
-		makeStructFunctionBody( aggregateDecl->get_members().begin(), aggregateDecl->get_members().end(), ctorDecl, isDynamicLayout );
-		makeStructFunctionBody( aggregateDecl->get_members().begin(), aggregateDecl->get_members().end(), copyCtorDecl, isDynamicLayout );
-		// needs to do everything in reverse, so pass "forward" as false
-		makeStructFunctionBody( aggregateDecl->get_members().rbegin(), aggregateDecl->get_members().rend(), dtorDecl, isDynamicLayout, false );
-
-		assert( assignType->get_parameters().size() == 2 );
-		ObjectDecl * srcParam = safe_dynamic_cast< ObjectDecl * >( assignType->get_parameters().back() );
-		assignDecl->get_statements()->get_kids().push_back( new ReturnStmt( noLabels, new VariableExpr( srcParam ) ) );
-
-		declsToAdd.push_back( ctorDecl );
-		declsToAdd.push_back( copyCtorDecl );
-		declsToAdd.push_back( dtorDecl );
-		declsToAdd.push_back( assignDecl ); // assignment should come last since it uses copy constructor in return
-		declsToAdd.splice( declsToAdd.end(), memCtors );
+		//   void ?{}(A *, int) and void ?{}(A *, int, int)
+		// Field constructors are only generated if default and copy constructor
+		// are generated, since they need access to both
+		if ( numCtors == 2 ) {
+			FunctionType * memCtorType = genDefaultType( refType );
+			cloneAll( typeParams, memCtorType->get_forall() );
+			for ( std::list<Declaration *>::iterator i = aggregateDecl->get_members().begin(); i != aggregateDecl->get_members().end(); ++i ) {
+				DeclarationWithType * member = dynamic_cast<DeclarationWithType *>( *i );
+				assert( member );
+				if ( isUnnamedBitfield( dynamic_cast< ObjectDecl * > ( member ) ) ) {
+					// don't make a function whose parameter is an unnamed bitfield
+					continue;
+				} else if ( member->get_name() == "" ) {
+					// don't assign to anonymous members
+					// xxx - this is a temporary fix. Anonymous members tie into
+					// our inheritance model. I think the correct way to handle this is to
+					// cast the structure to the type of the member and let the resolver
+					// figure out whether it's valid and have a pass afterwards that fixes
+					// the assignment to use pointer arithmetic with the offset of the
+					// member, much like how generic type members are handled.
+					continue;
+				}
+				memCtorType->get_parameters().push_back( new ObjectDecl( member->get_name(), DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, member->get_type()->clone(), 0 ) );
+				FunctionDecl * ctor = genFunc( "?{}", memCtorType->clone(), functionNesting );
+				makeStructFieldCtorBody( aggregateDecl->get_members().begin(), aggregateDecl->get_members().end(), ctor, isDynamicLayout );
+				declsToAdd.push_back( ctor );
+			}
+			delete memCtorType;
+		}
 	}
 
@@ -481,4 +554,13 @@
 	}
 
+	AutogenerateRoutines::AutogenerateRoutines() {
+		// the order here determines the order that these functions are generated.
+		// assignment should come last since it uses copy constructor in return.
+		data.push_back( FuncData( "?{}", genDefaultType, constructable ) );
+		data.push_back( FuncData( "?{}", genCopyType, copyable ) );
+		data.push_back( FuncData( "^?{}", genDefaultType, destructable ) );
+		data.push_back( FuncData( "?=?", genAssignType, assignable ) );
+	}
+
 	void AutogenerateRoutines::visit( EnumDecl *enumDecl ) {
 		if ( ! enumDecl->get_members().empty() ) {
@@ -491,11 +573,13 @@
 
 	void AutogenerateRoutines::visit( StructDecl *structDecl ) {
-		if ( ! structDecl->get_members().empty() && structsDone.find( structDecl->get_name() ) == structsDone.end() ) {
+		if ( structDecl->has_body() && structsDone.find( structDecl->get_name() ) == structsDone.end() ) {
 			StructInstType structInst( Type::Qualifiers(), structDecl->get_name() );
 			for ( TypeDecl * typeDecl : structDecl->get_parameters() ) {
+				// need to visit assertions so that they are added to the appropriate maps
+				acceptAll( typeDecl->get_assertions(), *this );
 				structInst.get_parameters().push_back( new TypeExpr( new TypeInstType( Type::Qualifiers(), typeDecl->get_name(), typeDecl ) ) );
 			}
 			structInst.set_baseStruct( structDecl );
-			makeStructFunctions( structDecl, &structInst, functionNesting, declsToAdd );
+			makeStructFunctions( structDecl, &structInst, functionNesting, declsToAdd, data );
 			structsDone.insert( structDecl->get_name() );
 		} // if
@@ -564,4 +648,10 @@
 
 	void AutogenerateRoutines::visit( FunctionDecl *functionDecl ) {
+		// record the existence of this function as appropriate
+		insert( functionDecl, constructable, InitTweak::isDefaultConstructor );
+		insert( functionDecl, assignable, InitTweak::isAssignment );
+		insert( functionDecl, copyable, InitTweak::isCopyConstructor );
+		insert( functionDecl, destructable, InitTweak::isDestructor );
+
 		maybeAccept( functionDecl->get_functionType(), *this );
 		acceptAll( functionDecl->get_oldDecls(), *this );
@@ -572,5 +662,13 @@
 
 	void AutogenerateRoutines::visit( CompoundStmt *compoundStmt ) {
+		constructable.beginScope();
+		assignable.beginScope();
+		copyable.beginScope();
+		destructable.beginScope();
 		visitStatement( compoundStmt );
+		constructable.endScope();
+		assignable.endScope();
+		copyable.endScope();
+		destructable.endScope();
 	}
 
Index: src/SymTab/FixFunction.cc
===================================================================
--- src/SymTab/FixFunction.cc	(revision 6acb935ec45eabc0c4c2c47501d76a9c231f7219)
+++ src/SymTab/FixFunction.cc	(revision a362f977ce917e9868e8b98a81cc260e0aee5cf9)
@@ -25,5 +25,6 @@
 
 	DeclarationWithType * FixFunction::mutate(FunctionDecl *functionDecl) {
-		ObjectDecl *pointer = new ObjectDecl( functionDecl->get_name(), functionDecl->get_storageClass(), functionDecl->get_linkage(), 0, new PointerType( Type::Qualifiers(), functionDecl->get_type()->clone() ), 0 );
+		ObjectDecl *pointer = new ObjectDecl( functionDecl->get_name(), functionDecl->get_storageClass(), functionDecl->get_linkage(), 0, new PointerType( Type::Qualifiers(), functionDecl->get_type()->clone() ), 0, functionDecl->get_attributes() );
+		functionDecl->get_attributes().clear();
 		delete functionDecl;
 		return pointer;
Index: src/SymTab/Validate.cc
===================================================================
--- src/SymTab/Validate.cc	(revision 6acb935ec45eabc0c4c2c47501d76a9c231f7219)
+++ src/SymTab/Validate.cc	(revision a362f977ce917e9868e8b98a81cc260e0aee5cf9)
@@ -114,5 +114,5 @@
 		LinkReferenceToTypes( bool doDebug, const Indexer *indexer );
 	  private:
-  		using Indexer::visit;
+  		using Parent::visit;
 		void visit( StructInstType *structInst ) final;
 		void visit( UnionInstType *unionInst ) final;
@@ -131,11 +131,12 @@
 
 	/// Replaces array and function types in forall lists by appropriate pointer type
-	class Pass3 : public Indexer {
+	class Pass3 final : public Indexer {
 		typedef Indexer Parent;
 	  public:
+	  	using Parent::visit;
 		Pass3( const Indexer *indexer );
 	  private:
-		virtual void visit( ObjectDecl *object );
-		virtual void visit( FunctionDecl *func );
+		virtual void visit( ObjectDecl *object ) override;
+		virtual void visit( FunctionDecl *func ) override;
 
 		const Indexer *indexer;
@@ -375,12 +376,12 @@
 	}
 
-	void LinkReferenceToTypes::visit( TraitInstType *contextInst ) {
-		Parent::visit( contextInst );
-		if ( contextInst->get_name() == "sized" ) {
+	void LinkReferenceToTypes::visit( TraitInstType *traitInst ) {
+		Parent::visit( traitInst );
+		if ( traitInst->get_name() == "sized" ) {
 			// "sized" is a special trait with no members - just flick the sized status on for the type variable
-			if ( contextInst->get_parameters().size() != 1 ) {
-				throw SemanticError( "incorrect number of context parameters: ", contextInst );
+			if ( traitInst->get_parameters().size() != 1 ) {
+				throw SemanticError( "incorrect number of trait parameters: ", traitInst );
 			}
-			TypeExpr * param = safe_dynamic_cast< TypeExpr * > ( contextInst->get_parameters().front() );
+			TypeExpr * param = safe_dynamic_cast< TypeExpr * > ( traitInst->get_parameters().front() );
 			TypeInstType * inst = safe_dynamic_cast< TypeInstType * > ( param->get_type() );
 			TypeDecl * decl = inst->get_baseType();
@@ -389,27 +390,33 @@
 			return;
 		}
-		TraitDecl *ctx = indexer->lookupTrait( contextInst->get_name() );
-		if ( ! ctx ) {
-			throw SemanticError( "use of undeclared context " + contextInst->get_name() );
-		} // if
-		for ( std::list< TypeDecl * >::const_iterator i = ctx->get_parameters().begin(); i != ctx->get_parameters().end(); ++i ) {
-			for ( std::list< DeclarationWithType * >::const_iterator assert = (*i )->get_assertions().begin(); assert != (*i )->get_assertions().end(); ++assert ) {
-				if ( TraitInstType *otherCtx = dynamic_cast< TraitInstType * >(*assert ) ) {
-					cloneAll( otherCtx->get_members(), contextInst->get_members() );
-				} else {
-					contextInst->get_members().push_back( (*assert )->clone() );
-				} // if
+		TraitDecl *traitDecl = indexer->lookupTrait( traitInst->get_name() );
+		if ( ! traitDecl ) {
+			throw SemanticError( "use of undeclared trait " + traitInst->get_name() );
+		} // if
+		if ( traitDecl->get_parameters().size() != traitInst->get_parameters().size() ) {
+			throw SemanticError( "incorrect number of trait parameters: ", traitInst );
+		} // if
+
+		for ( TypeDecl * td : traitDecl->get_parameters() ) {
+			for ( DeclarationWithType * assert : td->get_assertions() ) {
+				traitInst->get_members().push_back( assert->clone() );
 			} // for
 		} // for
 
-		if ( ctx->get_parameters().size() != contextInst->get_parameters().size() ) {
-			throw SemanticError( "incorrect number of context parameters: ", contextInst );
-		} // if
-
-		// need to clone members of the context for ownership purposes
+		// need to clone members of the trait for ownership purposes
 		std::list< Declaration * > members;
-		std::transform( ctx->get_members().begin(), ctx->get_members().end(), back_inserter( members ), [](Declaration * dwt) { return dwt->clone(); } );
-
-		applySubstitution( ctx->get_parameters().begin(), ctx->get_parameters().end(), contextInst->get_parameters().begin(), members.begin(), members.end(), back_inserter( contextInst->get_members() ) );
+		std::transform( traitDecl->get_members().begin(), traitDecl->get_members().end(), back_inserter( members ), [](Declaration * dwt) { return dwt->clone(); } );
+
+		applySubstitution( traitDecl->get_parameters().begin(), traitDecl->get_parameters().end(), traitInst->get_parameters().begin(), members.begin(), members.end(), back_inserter( traitInst->get_members() ) );
+
+		// need to carry over the 'sized' status of each decl in the instance
+		for ( auto p : group_iterate( traitDecl->get_parameters(), traitInst->get_parameters() ) ) {
+			TypeExpr * expr = safe_dynamic_cast< TypeExpr * >( std::get<1>(p) );
+			if ( TypeInstType * inst = dynamic_cast< TypeInstType * >( expr->get_type() ) ) {
+				TypeDecl * formalDecl = std::get<0>(p);
+				TypeDecl * instDecl = inst->get_baseType();
+				if ( formalDecl->get_sized() ) instDecl->set_sized( true );
+			}
+		}
 	}
 
@@ -457,25 +464,26 @@
 	}
 
-	/// Fix up assertions
-	void forallFixer( Type *func ) {
-		for ( Type::ForallList::iterator type = func->get_forall().begin(); type != func->get_forall().end(); ++type ) {
+	/// Fix up assertions - flattens assertion lists, removing all trait instances
+	void forallFixer( Type * func ) {
+		for ( TypeDecl * type : func->get_forall() ) {
 			std::list< DeclarationWithType * > toBeDone, nextRound;
-			toBeDone.splice( toBeDone.end(), (*type )->get_assertions() );
+			toBeDone.splice( toBeDone.end(), type->get_assertions() );
 			while ( ! toBeDone.empty() ) {
-				for ( std::list< DeclarationWithType * >::iterator assertion = toBeDone.begin(); assertion != toBeDone.end(); ++assertion ) {
-					if ( TraitInstType *ctx = dynamic_cast< TraitInstType * >( (*assertion )->get_type() ) ) {
-						for ( std::list< Declaration * >::const_iterator i = ctx->get_members().begin(); i != ctx->get_members().end(); ++i ) {
-							DeclarationWithType *dwt = dynamic_cast< DeclarationWithType * >( *i );
-							assert( dwt );
+				for ( DeclarationWithType * assertion : toBeDone ) {
+					if ( TraitInstType *traitInst = dynamic_cast< TraitInstType * >( assertion->get_type() ) ) {
+						// expand trait instance into all of its members
+						for ( Declaration * member : traitInst->get_members() ) {
+							DeclarationWithType *dwt = safe_dynamic_cast< DeclarationWithType * >( member );
 							nextRound.push_back( dwt->clone() );
 						}
-						delete ctx;
+						delete traitInst;
 					} else {
+						// pass assertion through
 						FixFunction fixer;
-						*assertion = (*assertion )->acceptMutator( fixer );
+						assertion = assertion->acceptMutator( fixer );
 						if ( fixer.get_isVoid() ) {
 							throw SemanticError( "invalid type void in assertion of function ", func );
 						}
-						(*type )->get_assertions().push_back( *assertion );
+						type->get_assertions().push_back( assertion );
 					} // if
 				} // for
@@ -629,5 +637,8 @@
 		if ( FunctionType *funtype = dynamic_cast<FunctionType *>( ret->get_type() ) ) {
 			// replace the current object declaration with a function declaration
-			return new FunctionDecl( ret->get_name(), ret->get_storageClass(), ret->get_linkage(), funtype, 0, ret->get_isInline(), ret->get_isNoreturn() );
+			FunctionDecl * newDecl = new FunctionDecl( ret->get_name(), ret->get_storageClass(), ret->get_linkage(), funtype, 0, ret->get_isInline(), ret->get_isNoreturn(), objDecl->get_attributes() );
+			objDecl->get_attributes().clear();
+			delete objDecl;
+			return newDecl;
 		} else if ( objDecl->get_isInline() || objDecl->get_isNoreturn() ) {
 			throw SemanticError( "invalid inline or _Noreturn specification in declaration of ", objDecl );
Index: src/SynTree/AggregateDecl.cc
===================================================================
--- src/SynTree/AggregateDecl.cc	(revision 6acb935ec45eabc0c4c2c47501d76a9c231f7219)
+++ src/SynTree/AggregateDecl.cc	(revision a362f977ce917e9868e8b98a81cc260e0aee5cf9)
@@ -69,5 +69,5 @@
 std::string EnumDecl::typeString() const { return "enum"; }
 
-std::string TraitDecl::typeString() const { return "context"; }
+std::string TraitDecl::typeString() const { return "trait"; }
 
 // Local Variables: //
Index: src/SynTree/ReferenceToType.cc
===================================================================
--- src/SynTree/ReferenceToType.cc	(revision 6acb935ec45eabc0c4c2c47501d76a9c231f7219)
+++ src/SynTree/ReferenceToType.cc	(revision a362f977ce917e9868e8b98a81cc260e0aee5cf9)
@@ -64,4 +64,6 @@
 }
 
+bool StructInstType::isComplete() const { return baseStruct->has_body(); }
+
 void StructInstType::lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const {
 	assert( baseStruct );
@@ -90,4 +92,6 @@
 }
 
+bool UnionInstType::isComplete() const { return baseUnion->has_body(); }
+
 void UnionInstType::lookup( const std::string &name, std::list< Declaration* > &foundDecls ) const {
 	assert( baseUnion );
@@ -111,5 +115,5 @@
 std::string EnumInstType::typeString() const { return "enum"; }
 
-std::string TraitInstType::typeString() const { return "context"; }
+std::string TraitInstType::typeString() const { return "trait"; }
 
 TraitInstType::TraitInstType( const TraitInstType &other ) : Parent( other ) {
@@ -120,4 +124,6 @@
 	deleteAll( members );
 }
+
+bool TraitInstType::isComplete() const { assert( false ); }
 
 TypeInstType::TypeInstType( const Type::Qualifiers &tq, const std::string &name, TypeDecl *baseType ) : Parent( tq, name ) {
@@ -143,4 +149,6 @@
 std::string TypeInstType::typeString() const { return "type"; }
 
+bool TypeInstType::isComplete() const { return baseType->isComplete(); }
+
 void TypeInstType::print( std::ostream &os, int indent ) const {
 	using std::endl;
Index: src/SynTree/Type.h
===================================================================
--- src/SynTree/Type.h	(revision 6acb935ec45eabc0c4c2c47501d76a9c231f7219)
+++ src/SynTree/Type.h	(revision a362f977ce917e9868e8b98a81cc260e0aee5cf9)
@@ -74,4 +74,6 @@
 	virtual Type * getComponent( unsigned i ) { assertf( size() == 1 && i == 0, "Type::getComponent was called with size %d and index %d\n", size(), i ); return this; }
 
+	virtual bool isComplete() const { return true; }
+
 	virtual Type *clone() const = 0;
 	virtual void accept( Visitor &v ) = 0;
@@ -90,4 +92,5 @@
 
 	virtual unsigned size() const { return 0; };
+	virtual bool isComplete() const { return false; }
 
 	virtual VoidType *clone() const { return new VoidType( *this ); }
@@ -185,4 +188,6 @@
 	void set_isStatic( bool newValue ) { isStatic = newValue; }
 
+	virtual bool isComplete() const { return ! isVarLen; }
+
 	virtual ArrayType *clone() const { return new ArrayType( *this ); }
 	virtual void accept( Visitor &v ) { v.visit( this ); }
@@ -258,4 +263,6 @@
 	std::list<TypeDecl*> * get_baseParameters();
 
+	virtual bool isComplete() const;
+
 	/// Looks up the members of this struct named "name" and places them into "foundDecls".
 	/// Clones declarations into "foundDecls", caller responsible for freeing
@@ -287,4 +294,6 @@
 	std::list<TypeDecl*> * get_baseParameters();
 
+	virtual bool isComplete() const;
+
 	/// looks up the members of this union named "name" and places them into "foundDecls"
 	/// Clones declarations into "foundDecls", caller responsible for freeing
@@ -310,4 +319,7 @@
 	EnumInstType( const EnumInstType &other ) : Parent( other ) {}
 
+	// xxx - enum inst does not currently contain a pointer to base, this should be fixed.
+	// virtual bool isComplete() const { return baseEnum()->hasBody(); }
+
 	virtual EnumInstType *clone() const { return new EnumInstType( *this ); }
 	virtual void accept( Visitor &v ) { v.visit( this ); }
@@ -325,4 +337,6 @@
 
 	std::list< Declaration* >& get_members() { return members; }
+
+	virtual bool isComplete() const;
 
 	virtual TraitInstType *clone() const { return new TraitInstType( *this ); }
@@ -349,4 +363,6 @@
 	bool get_isFtype() const { return isFtype; }
 	void set_isFtype( bool newValue ) { isFtype = newValue; }
+
+	virtual bool isComplete() const;
 
 	virtual TypeInstType *clone() const { return new TypeInstType( *this ); }
@@ -382,4 +398,6 @@
 	}
 
+	// virtual bool isComplete() const { return true; } // xxx - not sure if this is right, might need to recursively check complete-ness
+
 	virtual TupleType *clone() const { return new TupleType( *this ); }
 	virtual void accept( Visitor &v ) { v.visit( this ); }
@@ -398,4 +416,6 @@
 	Expression *get_expr() const { return expr; }
 	void set_expr( Expression *newValue ) { expr = newValue; }
+
+	virtual bool isComplete() const { assert( false ); return false; }
 
 	virtual TypeofType *clone() const { return new TypeofType( *this ); }
@@ -423,4 +443,6 @@
 	void set_isType( bool newValue ) { isType = newValue; }
 
+	virtual bool isComplete() const { assert( false ); } // xxx - not sure what to do here
+
 	virtual AttrType *clone() const { return new AttrType( *this ); }
 	virtual void accept( Visitor &v ) { v.visit( this ); }
@@ -439,4 +461,6 @@
 	VarArgsType();
 	VarArgsType( Type::Qualifiers tq );
+
+	virtual bool isComplete() const{ return true; } // xxx - is this right?
 
 	virtual VarArgsType *clone() const { return new VarArgsType( *this ); }
Index: src/driver/cfa.cc
===================================================================
--- src/driver/cfa.cc	(revision 6acb935ec45eabc0c4c2c47501d76a9c231f7219)
+++ src/driver/cfa.cc	(revision a362f977ce917e9868e8b98a81cc260e0aee5cf9)
@@ -267,4 +267,6 @@
 		}
 		nargs += 1;
+		args[nargs] = "-lpthread";
+		nargs += 1;
 	} // if
 #endif //HAVE_LIBCFA
Index: src/examples/thread.c
===================================================================
--- src/examples/thread.c	(revision 6acb935ec45eabc0c4c2c47501d76a9c231f7219)
+++ src/examples/thread.c	(revision a362f977ce917e9868e8b98a81cc260e0aee5cf9)
@@ -1,2 +1,3 @@
+#include <fstream>
 #include <kernel>
 #include <stdlib>
@@ -4,24 +5,13 @@
 
 // Start coroutine routines
-extern "C" {
-      forall(dtype T | is_coroutine(T))
-      void CtxInvokeCoroutine(T * this);
-
-      forall(dtype T | is_coroutine(T))
-      void CtxStart(T * this, void ( *invoke)(T *));
-
-	forall(dtype T | is_coroutine(T))
-      void CtxInvokeThread(T * this);
-}
-
 struct MyThread {
-	thread_h t;
+	thread t;
 	unsigned id;
 	unsigned count;
 };
 
+DECL_THREAD(MyThread)
+
 void ?{}( MyThread * this ) {
-	this->id = 0;
-	this->count = 10;
 }
 
@@ -31,37 +21,34 @@
 }
 
-void ^?{}( MyThread * this ) {}
-
 void main(MyThread* this) {
-	printf("Main called with %p\n", this);
-	printf("Thread %d : Suspending %d times\n", this->id, this->count);
+	sout | "Thread" | this->id | " : Suspending" | this->count | "times" | endl;
+	yield();
 
 	for(int i = 0; i < this->count; i++) {
-		printf("Thread %d : Suspend No. %d\n", this->id, i + 1);
-		printf("Back to %p\n", &this->t.c);
-		suspend();
+		sout | "Thread" | this->id | " : Suspend No." | i + 1 | endl;
+		yield();
 	}
 }
 
-thread_h* get_thread(MyThread* this) {
-	return &this->t;
-}
+int main(int argc, char* argv[]) {
 
-coroutine* get_coroutine(MyThread* this) {
-	return &this->t.c;
-}
+	unsigned itterations = 10u;
+	if(argc == 2) { 
+		int val = ato(argv[1]);
+		assert(val >= 0);
+		itterations = val;
+	}
 
-int main() {
+	sout | "User main begin" | endl;
 
-	thread(MyThread) thread1;
-	thread(MyThread) thread2;
+	{
+		processor p;
+		{
+			scoped(MyThread) thread1 = { 1u, itterations };
+			scoped(MyThread) thread2 = { 2u, itterations };
+		}
+	}
 
-	thread2.handle.id = 1;
-
-	printf("\n\nMain is %p\n", this_coroutine());
-
-	kernel_run();
-
-	printf("Kernel terminated correctly\n");
+	sout | "User main end" | endl;
 
 	return 0;
Index: src/libcfa/concurrency/CtxSwitch-i386.S
===================================================================
--- src/libcfa/concurrency/CtxSwitch-i386.S	(revision 6acb935ec45eabc0c4c2c47501d76a9c231f7219)
+++ src/libcfa/concurrency/CtxSwitch-i386.S	(revision a362f977ce917e9868e8b98a81cc260e0aee5cf9)
@@ -86,4 +86,13 @@
 	ret
 
+.text
+	.align 2
+.globl	CtxGet
+CtxGet:
+	movl %esp,SP_OFFSET(%eax)
+	movl %ebp,FP_OFFSET(%eax)
+
+	ret
+
 // Local Variables: //
 // compile-command: "make install" //
Index: src/libcfa/concurrency/CtxSwitch-x86_64.S
===================================================================
--- src/libcfa/concurrency/CtxSwitch-x86_64.S	(revision 6acb935ec45eabc0c4c2c47501d76a9c231f7219)
+++ src/libcfa/concurrency/CtxSwitch-x86_64.S	(revision a362f977ce917e9868e8b98a81cc260e0aee5cf9)
@@ -84,4 +84,13 @@
 	jmp *%r12
 
+.text
+	.align 2
+.globl	CtxGet
+CtxGet:
+	movq %rsp,SP_OFFSET(%rdi)
+	movq %rbp,FP_OFFSET(%rdi)
+
+	ret
+
 // Local Variables: //
 // mode: c //
Index: src/libcfa/concurrency/coroutines
===================================================================
--- src/libcfa/concurrency/coroutines	(revision 6acb935ec45eabc0c4c2c47501d76a9c231f7219)
+++ src/libcfa/concurrency/coroutines	(revision a362f977ce917e9868e8b98a81cc260e0aee5cf9)
@@ -62,8 +62,5 @@
 
 // Get current coroutine
-extern coroutine * current_coroutine; //PRIVATE, never use directly
-static inline coroutine * this_coroutine(void) {
-	return current_coroutine;
-}
+coroutine * this_coroutine(void);
 
 // Private wrappers for context switch and stack creation
@@ -76,9 +73,9 @@
 
 	assertf( src->last != 0,
-		"Attempt to suspend coroutine %.256s (%p) that has never been resumed.\n"
+		"Attempt to suspend coroutine \"%.256s\" (%p) that has never been resumed.\n"
 		"Possible cause is a suspend executed in a member called by a coroutine user rather than by the coroutine main.",
 		src->name, src );
 	assertf( src->last->notHalted,
-		"Attempt by coroutine %.256s (%p) to suspend back to terminated coroutine %.256s (%p).\n"
+		"Attempt by coroutine \"%.256s\" (%p) to suspend back to terminated coroutine \"%.256s\" (%p).\n"
 		"Possible cause is terminated coroutine's main routine has already returned.",
 		src->name, src, src->last->name, src->last );
Index: src/libcfa/concurrency/coroutines.c
===================================================================
--- src/libcfa/concurrency/coroutines.c	(revision 6acb935ec45eabc0c4c2c47501d76a9c231f7219)
+++ src/libcfa/concurrency/coroutines.c	(revision a362f977ce917e9868e8b98a81cc260e0aee5cf9)
@@ -1,2 +1,3 @@
+//                              -*- Mode: CFA -*-
 //
 // Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
@@ -14,4 +15,6 @@
 //
 
+#include "coroutines"
+
 extern "C" {
 #include <stddef.h>
@@ -23,9 +26,11 @@
 }
 
-#include "coroutines"
+#include "kernel"
 #include "libhdr.h"
 
 #define __CFA_INVOKE_PRIVATE__
 #include "invoke.h"
+
+extern processor * get_this_processor();
 
 //-----------------------------------------------------------------------------
@@ -35,19 +40,4 @@
 #define MinStackSize 1000
 static size_t pageSize = 0;				// architecture pagesize HACK, should go in proper runtime singleton
-
-//Extra private desctructor for the main
-//FIXME the main should not actually allocate a stack
-//Since the main is never resumed the extra stack does not cause 
-//any problem but it is wasted memory
-void ?{}(coStack_t* this, size_t size);
-void ?{}(coroutine* this, size_t size);
-
-//Main coroutine
-//FIXME do not construct a stack for the main
-coroutine main_coroutine = { 1000 };
-
-//Current coroutine
-//Will need to be in TLS when multi-threading is added
-coroutine* current_coroutine = &main_coroutine;
 
 //-----------------------------------------------------------------------------
@@ -111,6 +101,4 @@
 // is not inline (We can't inline Cforall in C)
 void suspend_no_inline(void) {
-	LIB_DEBUG_PRINTF("Suspending back : to %p from %p\n", this_coroutine(), this_coroutine() ? this_coroutine()->last : (void*)-1);
-
 	suspend();
 }
@@ -123,5 +111,5 @@
 
 	// set new coroutine that task is executing
-	current_coroutine = dst;			
+	get_this_processor()->current_coroutine = dst;			
 
 	// context switch to specified coroutine
Index: src/libcfa/concurrency/invoke.c
===================================================================
--- src/libcfa/concurrency/invoke.c	(revision 6acb935ec45eabc0c4c2c47501d76a9c231f7219)
+++ src/libcfa/concurrency/invoke.c	(revision a362f977ce917e9868e8b98a81cc260e0aee5cf9)
@@ -1,2 +1,17 @@
+//                              -*- Mode: C -*-
+//
+// 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.
+//
+// invoke.c --
+//
+// Author           : Thierry Delisle
+// Created On       : Tue Jan 17 12:27:26 2016
+// Last Modified By : Thierry Delisle
+// Last Modified On : --
+// Update Count     : 0
+//
 
 #include <stdbool.h>
@@ -14,5 +29,5 @@
 
 extern void __suspend_no_inline__F___1(void);
-extern void __scheduler_remove__F_P9sthread_h__1(struct thread_h*);
+extern void __signal_termination__F_P7sthread__1(struct thread*);
 
 void CtxInvokeCoroutine(
@@ -33,4 +48,7 @@
       main( this );
 
+      cor->state = Halt;
+      cor->notHalted = false;
+
       //Final suspend, should never return
       __suspend_no_inline__F___1();
@@ -40,5 +58,5 @@
 void CtxInvokeThread(
       void (*main)(void *), 
-      struct thread_h *(*get_thread)(void *), 
+      struct thread *(*get_thread)(void *), 
       void *this
 ) {
@@ -47,5 +65,5 @@
       __suspend_no_inline__F___1();
 
-      struct thread_h* thrd = get_thread( this );
+      struct thread* thrd = get_thread( this );
       struct coroutine* cor = &thrd->c;
       cor->state = Active;
@@ -54,5 +72,5 @@
       main( this );
 
-      __scheduler_remove__F_P9sthread_h__1(thrd);
+      __signal_termination__F_P7sthread__1(thrd);
 
       //Final suspend, should never return
Index: src/libcfa/concurrency/invoke.h
===================================================================
--- src/libcfa/concurrency/invoke.h	(revision 6acb935ec45eabc0c4c2c47501d76a9c231f7219)
+++ src/libcfa/concurrency/invoke.h	(revision a362f977ce917e9868e8b98a81cc260e0aee5cf9)
@@ -1,2 +1,18 @@
+//                              -*- Mode: C -*-
+//
+// 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.
+//
+// invoke.h --
+//
+// Author           : Thierry Delisle
+// Created On       : Tue Jan 17 12:27:26 2016
+// Last Modified By : Thierry Delisle
+// Last Modified On : --
+// Update Count     : 0
+//
+
 #include <stdbool.h>
 #include <stdint.h>
@@ -11,4 +27,19 @@
 
       #define unlikely(x)    __builtin_expect(!!(x), 0)
+      #define thread_local _Thread_local
+      #define SCHEDULER_CAPACITY 10
+
+      struct simple_thread_list {
+            struct thread * head;
+            struct thread ** tail;
+      };
+
+      #ifdef __CFORALL__
+      extern "Cforall" {
+            void ?{}( struct simple_thread_list * );
+            void append( struct simple_thread_list *, struct thread * );
+            struct thread * pop_head( struct simple_thread_list * );
+      }
+      #endif
 
       struct coStack_t {
@@ -35,6 +66,12 @@
       };
 
-      struct thread_h {
+      struct simple_lock {
+      	struct simple_thread_list blocked;
+      };
+
+      struct thread {
             struct coroutine c;
+            struct simple_lock lock;
+            struct thread * next;
       };
 
@@ -52,5 +89,6 @@
       // assembler routines that performs the context switch
       extern void CtxInvokeStub( void );
-      void CtxSwitch( void *from, void *to ) asm ("CtxSwitch");
+      void CtxSwitch( void * from, void * to ) asm ("CtxSwitch");
+      void CtxGet( void * this ) asm ("CtxGet");
 
 #endif //_INVOKE_PRIVATE_H_
Index: src/libcfa/concurrency/kernel
===================================================================
--- src/libcfa/concurrency/kernel	(revision 6acb935ec45eabc0c4c2c47501d76a9c231f7219)
+++ src/libcfa/concurrency/kernel	(revision a362f977ce917e9868e8b98a81cc260e0aee5cf9)
@@ -20,18 +20,82 @@
 #include <stdbool.h>
 
+#include "invoke.h"
+
+extern "C" {
+#include <pthread.h>
+}
+
+//-----------------------------------------------------------------------------
+// Cluster
+struct cluster {
+	simple_thread_list ready_queue;
+	pthread_spinlock_t lock;
+};
+
+void ?{}(cluster * this);
+void ^?{}(cluster * this);
+
+//-----------------------------------------------------------------------------
+// Processor
 struct processor {
-	struct proc_coroutine * cor;
-	unsigned int thread_index;
-	unsigned int thread_count;
-	struct thread_h * threads[10];
-	bool terminated;
+	struct processorCtx_t * ctx;
+	cluster * cltr;
+	coroutine * current_coroutine;
+	thread * current_thread;
+	pthread_t kernel_thread;
+	simple_lock lock;
+	volatile bool terminated;
 };
 
 void ?{}(processor * this);
+void ?{}(processor * this, cluster * cltr);
 void ^?{}(processor * this);
 
-void scheduler_add( struct thread_h * thrd );
-void scheduler_remove( struct thread_h * thrd );
-void kernel_run( void );
+
+//-----------------------------------------------------------------------------
+// Locks
+
+void ?{}(simple_lock * this);
+void ^?{}(simple_lock * this);
+
+void lock( simple_lock * );
+void unlock( simple_lock * );
+
+struct pthread_spinlock_guard {
+	pthread_spinlock_t * lock;
+};
+
+static inline void ?{}( pthread_spinlock_guard * this, pthread_spinlock_t * lock ) {
+	this->lock = lock;
+	pthread_spin_lock( this->lock );
+}
+
+static inline void ^?{}( pthread_spinlock_guard * this ) {
+	pthread_spin_unlock( this->lock );
+}
+
+// //Simple spinlock implementation from 
+// //http://stackoverflow.com/questions/1383363/is-my-spin-lock-implementation-correct-and-optimal
+// //Not optimal but correct
+// #define VOL 
+
+// struct simple_spinlock {
+// 	VOL int lock;
+// };
+
+// extern VOL int __sync_lock_test_and_set( VOL int *, VOL int);
+// extern void __sync_synchronize();
+
+// static inline void lock( simple_spinlock * this ) {
+//     while (__sync_lock_test_and_set(&this->lock, 1)) {
+//         // Do nothing. This GCC builtin instruction
+//         // ensures memory barrier.
+//     }
+// }
+
+// static inline void unlock( simple_spinlock * this ) {
+//     __sync_synchronize(); // Memory barrier.
+//     this->lock = 0;
+// }
 
 #endif //KERNEL_H
Index: src/libcfa/concurrency/kernel.c
===================================================================
--- src/libcfa/concurrency/kernel.c	(revision 6acb935ec45eabc0c4c2c47501d76a9c231f7219)
+++ src/libcfa/concurrency/kernel.c	(revision a362f977ce917e9868e8b98a81cc260e0aee5cf9)
@@ -20,4 +20,7 @@
 //C Includes
 #include <stddef.h>
+extern "C" {
+#include <sys/resource.h>
+}
 
 //CFA Includes
@@ -29,67 +32,167 @@
 #include "invoke.h"
 
-processor systemProcessorStorage = {};
-processor * systemProcessor = &systemProcessorStorage;
-
-void ?{}(processor * this) {
-	this->cor = NULL;
-	this->thread_index = 0;
-	this->thread_count = 10;
-	this->terminated = false;
-
-	for(int i = 0; i < 10; i++) {
-		this->threads[i] = NULL;
-	}
-
-	LIB_DEBUG_PRINTF("Processor : ctor for core %p (core spots %d)\n", this, this->thread_count);
-}
-
-void ^?{}(processor * this) {
-
-}
-
-//-----------------------------------------------------------------------------
-// Processor coroutine
-struct proc_coroutine {
+//-----------------------------------------------------------------------------
+// Kernel storage
+struct processorCtx_t {
 	processor * proc;
 	coroutine c;
 };
 
-void ?{}(coroutine * this, processor * proc) {
-	this{};
-}
-
-DECL_COROUTINE(proc_coroutine)
-
-void ?{}(proc_coroutine * this, processor * proc) {
-	(&this->c){proc};
+DECL_COROUTINE(processorCtx_t)
+
+#define KERNEL_STORAGE(T,X) static char X##_storage[sizeof(T)]
+
+KERNEL_STORAGE(processorCtx_t, systemProcessorCtx);
+KERNEL_STORAGE(cluster, systemCluster);
+KERNEL_STORAGE(processor, systemProcessor);
+KERNEL_STORAGE(thread, mainThread);
+KERNEL_STORAGE(machine_context_t, mainThread_context);
+
+cluster * systemCluster;
+processor * systemProcessor;
+thread * mainThread;
+
+void kernel_startup(void)  __attribute__((constructor(101)));
+void kernel_shutdown(void) __attribute__((destructor(101)));
+
+//-----------------------------------------------------------------------------
+// Global state
+
+thread_local processor * this_processor;
+
+processor * get_this_processor() {
+	return this_processor;
+}
+
+coroutine * this_coroutine(void) {
+	return this_processor->current_coroutine;
+}
+
+thread * this_thread(void) {
+	return this_processor->current_thread;
+}
+
+//-----------------------------------------------------------------------------
+// Main thread construction
+struct current_stack_info_t {
+	machine_context_t ctx;	
+	unsigned int size;		// size of stack
+	void *base;				// base of stack
+	void *storage;			// pointer to stack
+	void *limit;			// stack grows towards stack limit
+	void *context;			// address of cfa_context_t
+	void *top;				// address of top of storage
+};
+
+void ?{}( current_stack_info_t * this ) {
+	CtxGet( &this->ctx );
+	this->base = this->ctx.FP;
+	this->storage = this->ctx.SP;
+
+	rlimit r;
+	int ret = getrlimit( RLIMIT_STACK, &r);
+	this->size = r.rlim_cur;
+
+	this->limit = (void *)(((intptr_t)this->base) - this->size);
+	this->context = &mainThread_context_storage;
+	this->top = this->base;
+}
+
+void ?{}( coStack_t * this, current_stack_info_t * info) {
+	this->size = info->size;
+	this->storage = info->storage;
+	this->limit = info->limit;
+	this->base = info->base;
+	this->context = info->context;
+	this->top = info->top;
+	this->userStack = true;
+}
+
+void ?{}( coroutine * this, current_stack_info_t * info) {
+	(&this->stack){ info };	
+	this->name = "Main Thread";
+	this->errno_ = 0;
+	this->state = Inactive;
+	this->notHalted = true;
+}
+
+void ?{}( thread * this, current_stack_info_t * info) {
+	(&this->c){ info };
+}
+
+//-----------------------------------------------------------------------------
+// Processor coroutine
+void ?{}(processorCtx_t * this, processor * proc) {
+	(&this->c){};
 	this->proc = proc;
-	proc->cor = this;
-}
-
-void ^?{}(proc_coroutine * this) {
-	^(&this->c){};
-}
-
-void CtxInvokeProcessor(processor * proc) {
-	proc_coroutine proc_cor_storage = {proc};
-	resume( &proc_cor_storage );
+	proc->ctx = this;
+}
+
+void ?{}(processorCtx_t * this, processor * proc, current_stack_info_t * info) {
+	(&this->c){ info };
+	this->proc = proc;
+	proc->ctx = this;
+}
+
+void start(processor * this);
+
+void ?{}(processor * this) {
+	this{ systemCluster };
+}
+
+void ?{}(processor * this, cluster * cltr) {
+	this->cltr = cltr;
+	this->current_coroutine = NULL;
+	this->current_thread = NULL;
+	(&this->lock){};
+	this->terminated = false;
+
+	start( this );
+}
+
+void ?{}(processor * this, cluster * cltr, processorCtx_t * ctx) {
+	this->cltr = cltr;
+	this->current_coroutine = NULL;
+	this->current_thread = NULL;
+	(&this->lock){};
+	this->terminated = false;
+
+	this->ctx = ctx;
+	LIB_DEBUG_PRINTF("Kernel : constructing processor context %p\n", ctx);
+	ctx{ this };
+}
+
+void ^?{}(processor * this) {
+	if( ! this->terminated ) {
+		LIB_DEBUG_PRINTF("Kernel : core %p signaling termination\n", this);
+		this->terminated = true;
+		lock( &this->lock );
+	}
+}
+
+void ?{}(cluster * this) {
+	( &this->ready_queue ){};
+	pthread_spin_init( &this->lock, PTHREAD_PROCESS_PRIVATE );
+}
+
+void ^?{}(cluster * this) {
+	pthread_spin_destroy( &this->lock );
 }
 
 //-----------------------------------------------------------------------------
 // Processor running routines
-void main(proc_coroutine * cor);
-thread_h * nextThread(processor * this);
-void runThread(processor * this, thread_h * dst);
+void main(processorCtx_t * ctx);
+thread * nextThread(cluster * this);
+void runThread(processor * this, thread * dst);
 void spin(processor * this, unsigned int * spin_count);
 
-void main(proc_coroutine * cor) {
-	processor * this;
-	this = cor->proc;
-
-	thread_h * readyThread = NULL;
+void main(processorCtx_t * ctx) {
+	processor * this = ctx->proc;
+	LIB_DEBUG_PRINTF("Kernel : core %p starting\n", this);
+
+	thread * readyThread = NULL;
 	for( unsigned int spin_count = 0; ! this->terminated; spin_count++ ) {
 		
-		readyThread = nextThread(this);
+		readyThread = nextThread( this->cltr );
 
 		if(readyThread) {
@@ -101,20 +204,11 @@
 	}
 
+	LIB_DEBUG_PRINTF("Kernel : core %p unlocking thread\n", this);
+	unlock( &this->lock );
 	LIB_DEBUG_PRINTF("Kernel : core %p terminated\n", this);
 }
 
-thread_h * nextThread(processor * this) {
-	for(int i = 0; i < this->thread_count; i++) {
-		this->thread_index = (this->thread_index + 1) % this->thread_count;	
-		
-		thread_h * thrd = this->threads[this->thread_index];
-		if(thrd) return thrd;
-	}
-
-	return NULL;
-}
-
-void runThread(processor * this, thread_h * dst) {
-	coroutine * proc_ctx = get_coroutine(this->cor);
+void runThread(processor * this, thread * dst) {
+	coroutine * proc_ctx = get_coroutine(this->ctx);
 	coroutine * thrd_ctx = get_coroutine(dst);
 	thrd_ctx->last = proc_ctx;
@@ -122,9 +216,10 @@
 	// context switch to specified coroutine
 	// Which is now the current_coroutine
-	LIB_DEBUG_PRINTF("Kernel : switching to ctx %p (from %p, current %p)\n", thrd_ctx, proc_ctx, current_coroutine);
-	current_coroutine = thrd_ctx;
+	// LIB_DEBUG_PRINTF("Kernel : switching to ctx %p (from %p, current %p)\n", thrd_ctx, proc_ctx, current_coroutine);
+	this->current_thread = dst;
+	this->current_coroutine = thrd_ctx;
 	CtxSwitch( proc_ctx->stack.context, thrd_ctx->stack.context );
-	current_coroutine = proc_ctx;
-	LIB_DEBUG_PRINTF("Kernel : returned from ctx %p (to %p, current %p)\n", thrd_ctx, proc_ctx, current_coroutine);
+	this->current_coroutine = proc_ctx;
+	// LIB_DEBUG_PRINTF("Kernel : returned from ctx %p (to %p, current %p)\n", thrd_ctx, proc_ctx, current_coroutine);
 
 	// when CtxSwitch returns we are back in the processor coroutine
@@ -135,39 +230,196 @@
 }
 
-//-----------------------------------------------------------------------------
-// Kernel runner (Temporary)
-
-void scheduler_add( struct thread_h * thrd ) {
-	LIB_DEBUG_PRINTF("Kernel : scheduling %p on core %p (%d spots)\n", thrd, systemProcessor, systemProcessor->thread_count);
-	for(int i = 0; i < systemProcessor->thread_count; i++) {
-		if(systemProcessor->threads[i] == NULL) {
-			systemProcessor->threads[i] = thrd;
-			return;
+void * CtxInvokeProcessor(void * arg) {
+	processor * proc = (processor *) arg;
+	this_processor = proc;
+	// SKULLDUGGERY: We want to create a context for the processor coroutine
+	// which is needed for the 2-step context switch. However, there is no reason
+	// to waste the perfectly valid stack create by pthread. 
+	current_stack_info_t info;
+	machine_context_t ctx;
+	info.context = &ctx;
+	processorCtx_t proc_cor_storage = { proc, &info };
+
+	proc->current_coroutine = &proc->ctx->c;
+	proc->current_thread = NULL;
+
+	LIB_DEBUG_PRINTF("Kernel : core %p created (%p)\n", proc, proc->ctx);
+
+	// LIB_DEBUG_PRINTF("Kernel : core    base : %p \n", info.base );
+	// LIB_DEBUG_PRINTF("Kernel : core storage : %p \n", info.storage );
+	// LIB_DEBUG_PRINTF("Kernel : core    size : %x \n", info.size );
+	// LIB_DEBUG_PRINTF("Kernel : core   limit : %p \n", info.limit );
+	// LIB_DEBUG_PRINTF("Kernel : core context : %p \n", info.context );
+	// LIB_DEBUG_PRINTF("Kernel : core     top : %p \n", info.top );
+
+	//We now have a proper context from which to schedule threads
+
+	// SKULLDUGGERY: Since the coroutine doesn't have its own stack, we can't 
+	// resume it to start it like it normally would, it will just context switch 
+	// back to here. Instead directly call the main since we already are on the 
+	// appropriate stack.
+	proc_cor_storage.c.state = Active;
+      main( &proc_cor_storage );
+      proc_cor_storage.c.state = Halt;
+      proc_cor_storage.c.notHalted = false;
+
+	LIB_DEBUG_PRINTF("Kernel : core %p main ended (%p)\n", proc, proc->ctx);	
+
+	return NULL;
+}
+
+void start(processor * this) {
+	LIB_DEBUG_PRINTF("Kernel : Starting core %p\n", this);
+	
+	pthread_attr_t attributes;
+	pthread_attr_init( &attributes );
+
+	pthread_create( &this->kernel_thread, &attributes, CtxInvokeProcessor, (void*)this );
+
+	pthread_attr_destroy( &attributes );
+
+	LIB_DEBUG_PRINTF("Kernel : core %p started\n", this);	
+}
+
+//-----------------------------------------------------------------------------
+// Scheduler routines
+void thread_schedule( thread * thrd ) {
+	assertf( thrd->next == NULL, "Expected null got %p", thrd->next );
+	
+	pthread_spinlock_guard guard = { &systemProcessor->cltr->lock };
+	append( &systemProcessor->cltr->ready_queue, thrd );
+}
+
+thread * nextThread(cluster * this) {
+	pthread_spinlock_guard guard = { &this->lock };
+	return pop_head( &this->ready_queue );
+}
+
+//-----------------------------------------------------------------------------
+// Kernel boot procedures
+void kernel_startup(void) {
+
+	// SKULLDUGGERY: the mainThread steals the process main thread 
+	// which will then be scheduled by the systemProcessor normally
+	LIB_DEBUG_PRINTF("Kernel : Starting\n");	
+
+	current_stack_info_t info;
+
+	// LIB_DEBUG_PRINTF("Kernel : core    base : %p \n", info.base );
+	// LIB_DEBUG_PRINTF("Kernel : core storage : %p \n", info.storage );
+	// LIB_DEBUG_PRINTF("Kernel : core    size : %x \n", info.size );
+	// LIB_DEBUG_PRINTF("Kernel : core   limit : %p \n", info.limit );
+	// LIB_DEBUG_PRINTF("Kernel : core context : %p \n", info.context );
+	// LIB_DEBUG_PRINTF("Kernel : core     top : %p \n", info.top );
+
+	// Start by initializing the main thread
+	mainThread = (thread *)&mainThread_storage;
+	mainThread{ &info };
+
+	// Initialize the system cluster
+	systemCluster = (cluster *)&systemCluster_storage;
+	systemCluster{};
+
+	// Initialize the system processor and the system processor ctx
+	// (the coroutine that contains the processing control flow)
+	systemProcessor = (processor *)&systemProcessor_storage;
+	systemProcessor{ systemCluster, (processorCtx_t *)&systemProcessorCtx_storage };
+
+	// Add the main thread to the ready queue 
+	// once resume is called on systemProcessor->ctx the mainThread needs to be scheduled like any normal thread
+	thread_schedule(mainThread);
+
+	//initialize the global state variables
+	this_processor = systemProcessor;
+	this_processor->current_thread = mainThread;
+	this_processor->current_coroutine = &mainThread->c;
+
+	// SKULLDUGGERY: Force a context switch to the system processor to set the main thread's context to the current UNIX
+	// context. Hence, the main thread does not begin through CtxInvokeThread, like all other threads. The trick here is that
+	// mainThread is on the ready queue when this call is made. 
+	resume(systemProcessor->ctx);
+
+
+
+	// THE SYSTEM IS NOW COMPLETELY RUNNING
+
+
+
+	LIB_DEBUG_PRINTF("Kernel : Started\n--------------------------------------------------\n\n");
+}
+
+void kernel_shutdown(void) {
+	LIB_DEBUG_PRINTF("\n--------------------------------------------------\nKernel : Shutting down\n");
+
+	// SKULLDUGGERY: Notify the systemProcessor it needs to terminates.
+	// When its coroutine terminates, it return control to the mainThread
+	// which is currently here
+	systemProcessor->terminated = true;
+	suspend();
+
+	// THE SYSTEM IS NOW COMPLETELY STOPPED
+
+	// Destroy the system processor and its context in reverse order of construction
+	// These were manually constructed so we need manually destroy them
+	^(systemProcessor->ctx){};
+	^(systemProcessor){};
+
+	// Final step, destroy the main thread since it is no longer needed
+	// Since we provided a stack to this taxk it will not destroy anything
+	^(mainThread){};
+
+	LIB_DEBUG_PRINTF("Kernel : Shutdown complete\n");	
+}
+
+//-----------------------------------------------------------------------------
+// Locks
+void ?{}( simple_lock * this ) {
+	( &this->blocked ){};
+}
+
+void ^?{}( simple_lock * this ) {
+
+}
+
+void lock( simple_lock * this ) {
+	{
+		pthread_spinlock_guard guard = { &systemCluster->lock };  	//HUGE TEMP HACK which only works if we have a single cluster and is stupid
+		append( &this->blocked, this_thread() );
+	}
+	suspend();
+}
+
+void unlock( simple_lock * this ) {
+	thread * it;
+	while( it = pop_head( &this->blocked) ) {
+		thread_schedule( it );
+	}
+}
+
+//-----------------------------------------------------------------------------
+// Queues
+void ?{}( simple_thread_list * this ) {
+	this->head = NULL;
+	this->tail = &this->head;
+}
+
+void append( simple_thread_list * this, thread * t ) {
+	assert( t->next == NULL );
+	*this->tail = t;
+	this->tail = &t->next;
+}
+
+thread * pop_head( simple_thread_list * this ) {
+	thread * head = this->head;
+	if( head ) {
+		this->head = head->next;
+		if( !head->next ) {
+			this->tail = &this->head;
 		}
-	}
-	assert(false);
-}
-
-void scheduler_remove( struct thread_h * thrd ) {
-	LIB_DEBUG_PRINTF("Kernel : unscheduling %p from core %p\n", thrd, systemProcessor);
-	for(int i = 0; i < systemProcessor->thread_count; i++) {
-		if(systemProcessor->threads[i] == thrd) {
-			systemProcessor->threads[i] = NULL;
-			break;
-		}
-	}
-	for(int i = 0; i < systemProcessor->thread_count; i++) {
-		if(systemProcessor->threads[i] != NULL) {
-			return;
-		}
-	}
-	LIB_DEBUG_PRINTF("Kernel : terminating core %p\n\n\n", systemProcessor);	
-	systemProcessor->terminated = true;
-}
-
-void kernel_run( void ) {
-	CtxInvokeProcessor(systemProcessor);
-}
-
+		head->next = NULL;
+	}	
+	
+	return head;
+}
 // Local Variables: //
 // mode: c //
Index: src/libcfa/concurrency/threads
===================================================================
--- src/libcfa/concurrency/threads	(revision 6acb935ec45eabc0c4c2c47501d76a9c231f7219)
+++ src/libcfa/concurrency/threads	(revision a362f977ce917e9868e8b98a81cc260e0aee5cf9)
@@ -27,44 +27,45 @@
 // Anything that implements this trait can be resumed.
 // Anything that is resumed is a coroutine.
-trait is_thread(dtype T /*| sized(T)*/) {
+trait is_thread(dtype T | sized(T)) {
       void main(T* this);
-      thread_h* get_thread(T* this);
-	/*void ?{}(T*);
-	void ^?{}(T*);*/
+      thread* get_thread(T* this);
 };
 
-forall(otype T | is_thread(T) )
+#define DECL_THREAD(X) static inline thread* get_thread(X* this) { return &this->t; } void main(X* this);
+
+forall( dtype T | sized(T) | is_thread(T) )
 static inline coroutine* get_coroutine(T* this) {
 	return &get_thread(this)->c;
 }
 
-static inline coroutine* get_coroutine(thread_h* this) {
+static inline coroutine* get_coroutine(thread* this) {
 	return &this->c;
 }
 
+thread * this_thread(void);
+
 //-----------------------------------------------------------------------------
 // Ctors and dtors
-void ?{}(thread_h* this);
-void ^?{}(thread_h* this);
+void ?{}(thread* this);
+void ^?{}(thread* this);
 
 //-----------------------------------------------------------------------------
 // thread runner
 // Structure that actually start and stop threads
-forall(otype T | is_thread(T) )
-struct thread {
+forall( dtype T | sized(T) | is_thread(T) )
+struct scoped {
 	T handle;
 };
 
-forall(otype T | is_thread(T) )
-void ?{}( thread(T)* this );
+forall( dtype T | sized(T) | is_thread(T) | { void ?{}(T*); } )
+void ?{}( scoped(T)* this );
 
-forall(otype T, ttype P | is_thread(T) | { void ?{}(T*, P); } )
-void ?{}( thread(T)* this, P params );
+forall( dtype T, ttype P | sized(T) | is_thread(T) | { void ?{}(T*, P); } )
+void ?{}( scoped(T)* this, P params );
 
-forall(otype T | is_thread(T) )
-void ^?{}( thread(T)* this );
+forall( dtype T | sized(T) | is_thread(T) | { void ^?{}(T*); } )
+void ^?{}( scoped(T)* this );
 
-//-----------------------------------------------------------------------------
-// PRIVATE exposed because of inline
+void yield();
 
 #endif //THREADS_H
Index: src/libcfa/concurrency/threads.c
===================================================================
--- src/libcfa/concurrency/threads.c	(revision 6acb935ec45eabc0c4c2c47501d76a9c231f7219)
+++ src/libcfa/concurrency/threads.c	(revision a362f977ce917e9868e8b98a81cc260e0aee5cf9)
@@ -23,41 +23,47 @@
 #include "invoke.h"
 
-#include <stdlib>
+extern "C" {
+	#include <stddef.h>
+}
+
+extern processor * get_this_processor();
 
 //-----------------------------------------------------------------------------
 // Forward declarations
-forall(otype T | is_thread(T) )
-void start( thread(T)* this );
+forall( dtype T | sized(T) | is_thread(T) )
+void start( T* this );
 
-forall(otype T | is_thread(T) )
-void stop( thread(T)* this );
+forall( dtype T | sized(T) | is_thread(T) )
+void stop( T* this );
 
 //-----------------------------------------------------------------------------
 // Thread ctors and dtors
 
-void ?{}(thread_h* this) {
+void ?{}(thread* this) {
 	(&this->c){};
+	this->c.name = "Anonymous Coroutine";
+	(&this->lock){};
+	this->next = NULL;
 }
 
-void ^?{}(thread_h* this) {
+void ^?{}(thread* this) {
 	^(&this->c){};
 }
 
-forall(otype T | is_thread(T) )
-void ?{}( thread(T)* this ) {
-	printf("thread() ctor\n");
+forall( dtype T | sized(T) | is_thread(T) | { void ?{}(T*); } )
+void ?{}( scoped(T)* this ) {
 	(&this->handle){};
-	start(this);
+	start(&this->handle);
 }
 
-forall(otype T, ttype P | is_thread(T) | { void ?{}(T*, P); } )
-void ?{}( thread(T)* this, P params ) {
+forall( dtype T, ttype P | sized(T) | is_thread(T) | { void ?{}(T*, P); } )
+void ?{}( scoped(T)* this, P params ) {
 	(&this->handle){ params };
-	start(this);
+	start(&this->handle);
 }
 
-forall(otype T | is_thread(T) )
-void ^?{}( thread(T)* this ) {
-	stop(this);
+forall( dtype T | sized(T) | is_thread(T) | { void ^?{}(T*); } )
+void ^?{}( scoped(T)* this ) {
+	stop(&this->handle);
 	^(&this->handle){};
 }
@@ -70,24 +76,39 @@
 }
 
-forall(otype T | is_thread(T))
-void start( thread(T)* this ) {
-	T* handle  = &this->handle;
-	coroutine* thrd_c = get_coroutine(handle);
-	thread_h*  thrd_h = get_thread   (handle);
+extern void thread_schedule( thread * );
+
+forall( dtype T | sized(T) | is_thread(T) )
+void start( T* this ) {
+	coroutine* thrd_c = get_coroutine(this);
+	thread*  thrd_h = get_thread   (this);
 	thrd_c->last = this_coroutine();
-	current_coroutine = thrd_c;
+	get_this_processor()->current_coroutine = thrd_c;
 
 	// LIB_DEBUG_PRINTF("Thread start : %p (t %p, c %p)\n", handle, thrd_c, thrd_h);
 
 	create_stack(&thrd_c->stack, thrd_c->stack.size);
-	CtxStart(handle, CtxInvokeThread);
+	CtxStart(this, CtxInvokeThread);
 	CtxSwitch( thrd_c->last->stack.context, thrd_c->stack.context );
 
-	scheduler_add(thrd_h);
+	thread_schedule(thrd_h);
 }
 
-forall(otype T | is_thread(T) )
-void stop( thread(T)* this ) {
+forall( dtype T | sized(T) | is_thread(T) )
+void stop( T* this ) {
+	thread*  thrd = get_thread(this);
+	if( thrd->c.notHalted ) {
+		lock( &thrd->lock );
+	}
+}
 
+void signal_termination( thread * this ) {
+	this->c.state = Halt;
+      this->c.notHalted = false;
+	unlock( &this->lock );
+}
+
+void yield( void ) {
+	thread_schedule( this_thread() );
+	suspend();
 }
 
Index: src/tests/.expect/32/declarationSpecifier.txt
===================================================================
--- src/tests/.expect/32/declarationSpecifier.txt	(revision 6acb935ec45eabc0c4c2c47501d76a9c231f7219)
+++ src/tests/.expect/32/declarationSpecifier.txt	(revision a362f977ce917e9868e8b98a81cc260e0aee5cf9)
@@ -1,7 +1,7 @@
-extern void *malloc(unsigned int __size);
-extern void free(void *__ptr);
-extern void abort(void);
-extern int atexit(void (*__func)(void));
-extern void exit(int __status);
+__attribute__ ((__malloc__,__nothrow__,__leaf__)) extern void *malloc(unsigned int __size);
+__attribute__ ((__nothrow__,__leaf__)) extern void free(void *__ptr);
+__attribute__ ((__noreturn__,__nothrow__,__leaf__)) extern void abort(void);
+__attribute__ ((__nonnull__(1),__nothrow__,__leaf__)) extern int atexit(void (*__func)(void));
+__attribute__ ((__noreturn__,__nothrow__,__leaf__)) extern void exit(int __status);
 extern int printf(const char *__restrict __format, ...);
 volatile const short __x1__CVs_1;
@@ -16,8 +16,8 @@
     int __i__i_1;
 };
-static inline struct __anonymous0 ___operator_assign__F13s__anonymous0_P13s__anonymous013s__anonymous0_autogen___1(struct __anonymous0 *___dst__P13s__anonymous0_1, struct __anonymous0 ___src__13s__anonymous0_1);
 static inline void ___constructor__F_P13s__anonymous0_autogen___1(struct __anonymous0 *___dst__P13s__anonymous0_1);
 static inline void ___constructor__F_P13s__anonymous013s__anonymous0_autogen___1(struct __anonymous0 *___dst__P13s__anonymous0_1, struct __anonymous0 ___src__13s__anonymous0_1);
 static inline void ___destructor__F_P13s__anonymous0_autogen___1(struct __anonymous0 *___dst__P13s__anonymous0_1);
+static inline struct __anonymous0 ___operator_assign__F13s__anonymous0_P13s__anonymous013s__anonymous0_autogen___1(struct __anonymous0 *___dst__P13s__anonymous0_1, struct __anonymous0 ___src__13s__anonymous0_1);
 static inline void ___constructor__F_P13s__anonymous0_autogen___1(struct __anonymous0 *___dst__P13s__anonymous0_1){
     ((void)((*((int *)(&(*___dst__P13s__anonymous0_1).__i__i_1)))) /* ?{} */);
@@ -40,8 +40,8 @@
     int __i__i_1;
 };
-static inline struct __anonymous1 ___operator_assign__F13s__anonymous1_P13s__anonymous113s__anonymous1_autogen___1(struct __anonymous1 *___dst__P13s__anonymous1_1, struct __anonymous1 ___src__13s__anonymous1_1);
 static inline void ___constructor__F_P13s__anonymous1_autogen___1(struct __anonymous1 *___dst__P13s__anonymous1_1);
 static inline void ___constructor__F_P13s__anonymous113s__anonymous1_autogen___1(struct __anonymous1 *___dst__P13s__anonymous1_1, struct __anonymous1 ___src__13s__anonymous1_1);
 static inline void ___destructor__F_P13s__anonymous1_autogen___1(struct __anonymous1 *___dst__P13s__anonymous1_1);
+static inline struct __anonymous1 ___operator_assign__F13s__anonymous1_P13s__anonymous113s__anonymous1_autogen___1(struct __anonymous1 *___dst__P13s__anonymous1_1, struct __anonymous1 ___src__13s__anonymous1_1);
 static inline void ___constructor__F_P13s__anonymous1_autogen___1(struct __anonymous1 *___dst__P13s__anonymous1_1){
     ((void)((*((int *)(&(*___dst__P13s__anonymous1_1).__i__i_1)))) /* ?{} */);
@@ -64,8 +64,8 @@
     int __i__i_1;
 };
-static inline struct __anonymous2 ___operator_assign__F13s__anonymous2_P13s__anonymous213s__anonymous2_autogen___1(struct __anonymous2 *___dst__P13s__anonymous2_1, struct __anonymous2 ___src__13s__anonymous2_1);
 static inline void ___constructor__F_P13s__anonymous2_autogen___1(struct __anonymous2 *___dst__P13s__anonymous2_1);
 static inline void ___constructor__F_P13s__anonymous213s__anonymous2_autogen___1(struct __anonymous2 *___dst__P13s__anonymous2_1, struct __anonymous2 ___src__13s__anonymous2_1);
 static inline void ___destructor__F_P13s__anonymous2_autogen___1(struct __anonymous2 *___dst__P13s__anonymous2_1);
+static inline struct __anonymous2 ___operator_assign__F13s__anonymous2_P13s__anonymous213s__anonymous2_autogen___1(struct __anonymous2 *___dst__P13s__anonymous2_1, struct __anonymous2 ___src__13s__anonymous2_1);
 static inline void ___constructor__F_P13s__anonymous2_autogen___1(struct __anonymous2 *___dst__P13s__anonymous2_1){
     ((void)((*((int *)(&(*___dst__P13s__anonymous2_1).__i__i_1)))) /* ?{} */);
@@ -88,8 +88,8 @@
     int __i__i_1;
 };
-static inline struct __anonymous3 ___operator_assign__F13s__anonymous3_P13s__anonymous313s__anonymous3_autogen___1(struct __anonymous3 *___dst__P13s__anonymous3_1, struct __anonymous3 ___src__13s__anonymous3_1);
 static inline void ___constructor__F_P13s__anonymous3_autogen___1(struct __anonymous3 *___dst__P13s__anonymous3_1);
 static inline void ___constructor__F_P13s__anonymous313s__anonymous3_autogen___1(struct __anonymous3 *___dst__P13s__anonymous3_1, struct __anonymous3 ___src__13s__anonymous3_1);
 static inline void ___destructor__F_P13s__anonymous3_autogen___1(struct __anonymous3 *___dst__P13s__anonymous3_1);
+static inline struct __anonymous3 ___operator_assign__F13s__anonymous3_P13s__anonymous313s__anonymous3_autogen___1(struct __anonymous3 *___dst__P13s__anonymous3_1, struct __anonymous3 ___src__13s__anonymous3_1);
 static inline void ___constructor__F_P13s__anonymous3_autogen___1(struct __anonymous3 *___dst__P13s__anonymous3_1){
     ((void)((*((int *)(&(*___dst__P13s__anonymous3_1).__i__i_1)))) /* ?{} */);
@@ -112,8 +112,8 @@
     int __i__i_1;
 };
-static inline struct __anonymous4 ___operator_assign__F13s__anonymous4_P13s__anonymous413s__anonymous4_autogen___1(struct __anonymous4 *___dst__P13s__anonymous4_1, struct __anonymous4 ___src__13s__anonymous4_1);
 static inline void ___constructor__F_P13s__anonymous4_autogen___1(struct __anonymous4 *___dst__P13s__anonymous4_1);
 static inline void ___constructor__F_P13s__anonymous413s__anonymous4_autogen___1(struct __anonymous4 *___dst__P13s__anonymous4_1, struct __anonymous4 ___src__13s__anonymous4_1);
 static inline void ___destructor__F_P13s__anonymous4_autogen___1(struct __anonymous4 *___dst__P13s__anonymous4_1);
+static inline struct __anonymous4 ___operator_assign__F13s__anonymous4_P13s__anonymous413s__anonymous4_autogen___1(struct __anonymous4 *___dst__P13s__anonymous4_1, struct __anonymous4 ___src__13s__anonymous4_1);
 static inline void ___constructor__F_P13s__anonymous4_autogen___1(struct __anonymous4 *___dst__P13s__anonymous4_1){
     ((void)((*((int *)(&(*___dst__P13s__anonymous4_1).__i__i_1)))) /* ?{} */);
@@ -136,8 +136,8 @@
     int __i__i_1;
 };
-static inline struct __anonymous5 ___operator_assign__F13s__anonymous5_P13s__anonymous513s__anonymous5_autogen___1(struct __anonymous5 *___dst__P13s__anonymous5_1, struct __anonymous5 ___src__13s__anonymous5_1);
 static inline void ___constructor__F_P13s__anonymous5_autogen___1(struct __anonymous5 *___dst__P13s__anonymous5_1);
 static inline void ___constructor__F_P13s__anonymous513s__anonymous5_autogen___1(struct __anonymous5 *___dst__P13s__anonymous5_1, struct __anonymous5 ___src__13s__anonymous5_1);
 static inline void ___destructor__F_P13s__anonymous5_autogen___1(struct __anonymous5 *___dst__P13s__anonymous5_1);
+static inline struct __anonymous5 ___operator_assign__F13s__anonymous5_P13s__anonymous513s__anonymous5_autogen___1(struct __anonymous5 *___dst__P13s__anonymous5_1, struct __anonymous5 ___src__13s__anonymous5_1);
 static inline void ___constructor__F_P13s__anonymous5_autogen___1(struct __anonymous5 *___dst__P13s__anonymous5_1){
     ((void)((*((int *)(&(*___dst__P13s__anonymous5_1).__i__i_1)))) /* ?{} */);
@@ -160,8 +160,8 @@
     int __i__i_1;
 };
-static inline struct __anonymous6 ___operator_assign__F13s__anonymous6_P13s__anonymous613s__anonymous6_autogen___1(struct __anonymous6 *___dst__P13s__anonymous6_1, struct __anonymous6 ___src__13s__anonymous6_1);
 static inline void ___constructor__F_P13s__anonymous6_autogen___1(struct __anonymous6 *___dst__P13s__anonymous6_1);
 static inline void ___constructor__F_P13s__anonymous613s__anonymous6_autogen___1(struct __anonymous6 *___dst__P13s__anonymous6_1, struct __anonymous6 ___src__13s__anonymous6_1);
 static inline void ___destructor__F_P13s__anonymous6_autogen___1(struct __anonymous6 *___dst__P13s__anonymous6_1);
+static inline struct __anonymous6 ___operator_assign__F13s__anonymous6_P13s__anonymous613s__anonymous6_autogen___1(struct __anonymous6 *___dst__P13s__anonymous6_1, struct __anonymous6 ___src__13s__anonymous6_1);
 static inline void ___constructor__F_P13s__anonymous6_autogen___1(struct __anonymous6 *___dst__P13s__anonymous6_1){
     ((void)((*((int *)(&(*___dst__P13s__anonymous6_1).__i__i_1)))) /* ?{} */);
@@ -184,8 +184,8 @@
     int __i__i_1;
 };
-static inline struct __anonymous7 ___operator_assign__F13s__anonymous7_P13s__anonymous713s__anonymous7_autogen___1(struct __anonymous7 *___dst__P13s__anonymous7_1, struct __anonymous7 ___src__13s__anonymous7_1);
 static inline void ___constructor__F_P13s__anonymous7_autogen___1(struct __anonymous7 *___dst__P13s__anonymous7_1);
 static inline void ___constructor__F_P13s__anonymous713s__anonymous7_autogen___1(struct __anonymous7 *___dst__P13s__anonymous7_1, struct __anonymous7 ___src__13s__anonymous7_1);
 static inline void ___destructor__F_P13s__anonymous7_autogen___1(struct __anonymous7 *___dst__P13s__anonymous7_1);
+static inline struct __anonymous7 ___operator_assign__F13s__anonymous7_P13s__anonymous713s__anonymous7_autogen___1(struct __anonymous7 *___dst__P13s__anonymous7_1, struct __anonymous7 ___src__13s__anonymous7_1);
 static inline void ___constructor__F_P13s__anonymous7_autogen___1(struct __anonymous7 *___dst__P13s__anonymous7_1){
     ((void)((*((int *)(&(*___dst__P13s__anonymous7_1).__i__i_1)))) /* ?{} */);
@@ -216,8 +216,8 @@
     short __i__s_1;
 };
-static inline struct __anonymous8 ___operator_assign__F13s__anonymous8_P13s__anonymous813s__anonymous8_autogen___1(struct __anonymous8 *___dst__P13s__anonymous8_1, struct __anonymous8 ___src__13s__anonymous8_1);
 static inline void ___constructor__F_P13s__anonymous8_autogen___1(struct __anonymous8 *___dst__P13s__anonymous8_1);
 static inline void ___constructor__F_P13s__anonymous813s__anonymous8_autogen___1(struct __anonymous8 *___dst__P13s__anonymous8_1, struct __anonymous8 ___src__13s__anonymous8_1);
 static inline void ___destructor__F_P13s__anonymous8_autogen___1(struct __anonymous8 *___dst__P13s__anonymous8_1);
+static inline struct __anonymous8 ___operator_assign__F13s__anonymous8_P13s__anonymous813s__anonymous8_autogen___1(struct __anonymous8 *___dst__P13s__anonymous8_1, struct __anonymous8 ___src__13s__anonymous8_1);
 static inline void ___constructor__F_P13s__anonymous8_autogen___1(struct __anonymous8 *___dst__P13s__anonymous8_1){
     ((void)((*((short *)(&(*___dst__P13s__anonymous8_1).__i__s_1)))) /* ?{} */);
@@ -240,8 +240,8 @@
     short __i__s_1;
 };
-static inline struct __anonymous9 ___operator_assign__F13s__anonymous9_P13s__anonymous913s__anonymous9_autogen___1(struct __anonymous9 *___dst__P13s__anonymous9_1, struct __anonymous9 ___src__13s__anonymous9_1);
 static inline void ___constructor__F_P13s__anonymous9_autogen___1(struct __anonymous9 *___dst__P13s__anonymous9_1);
 static inline void ___constructor__F_P13s__anonymous913s__anonymous9_autogen___1(struct __anonymous9 *___dst__P13s__anonymous9_1, struct __anonymous9 ___src__13s__anonymous9_1);
 static inline void ___destructor__F_P13s__anonymous9_autogen___1(struct __anonymous9 *___dst__P13s__anonymous9_1);
+static inline struct __anonymous9 ___operator_assign__F13s__anonymous9_P13s__anonymous913s__anonymous9_autogen___1(struct __anonymous9 *___dst__P13s__anonymous9_1, struct __anonymous9 ___src__13s__anonymous9_1);
 static inline void ___constructor__F_P13s__anonymous9_autogen___1(struct __anonymous9 *___dst__P13s__anonymous9_1){
     ((void)((*((short *)(&(*___dst__P13s__anonymous9_1).__i__s_1)))) /* ?{} */);
@@ -264,8 +264,8 @@
     short __i__s_1;
 };
-static inline struct __anonymous10 ___operator_assign__F14s__anonymous10_P14s__anonymous1014s__anonymous10_autogen___1(struct __anonymous10 *___dst__P14s__anonymous10_1, struct __anonymous10 ___src__14s__anonymous10_1);
 static inline void ___constructor__F_P14s__anonymous10_autogen___1(struct __anonymous10 *___dst__P14s__anonymous10_1);
 static inline void ___constructor__F_P14s__anonymous1014s__anonymous10_autogen___1(struct __anonymous10 *___dst__P14s__anonymous10_1, struct __anonymous10 ___src__14s__anonymous10_1);
 static inline void ___destructor__F_P14s__anonymous10_autogen___1(struct __anonymous10 *___dst__P14s__anonymous10_1);
+static inline struct __anonymous10 ___operator_assign__F14s__anonymous10_P14s__anonymous1014s__anonymous10_autogen___1(struct __anonymous10 *___dst__P14s__anonymous10_1, struct __anonymous10 ___src__14s__anonymous10_1);
 static inline void ___constructor__F_P14s__anonymous10_autogen___1(struct __anonymous10 *___dst__P14s__anonymous10_1){
     ((void)((*((short *)(&(*___dst__P14s__anonymous10_1).__i__s_1)))) /* ?{} */);
@@ -288,8 +288,8 @@
     short __i__s_1;
 };
-static inline struct __anonymous11 ___operator_assign__F14s__anonymous11_P14s__anonymous1114s__anonymous11_autogen___1(struct __anonymous11 *___dst__P14s__anonymous11_1, struct __anonymous11 ___src__14s__anonymous11_1);
 static inline void ___constructor__F_P14s__anonymous11_autogen___1(struct __anonymous11 *___dst__P14s__anonymous11_1);
 static inline void ___constructor__F_P14s__anonymous1114s__anonymous11_autogen___1(struct __anonymous11 *___dst__P14s__anonymous11_1, struct __anonymous11 ___src__14s__anonymous11_1);
 static inline void ___destructor__F_P14s__anonymous11_autogen___1(struct __anonymous11 *___dst__P14s__anonymous11_1);
+static inline struct __anonymous11 ___operator_assign__F14s__anonymous11_P14s__anonymous1114s__anonymous11_autogen___1(struct __anonymous11 *___dst__P14s__anonymous11_1, struct __anonymous11 ___src__14s__anonymous11_1);
 static inline void ___constructor__F_P14s__anonymous11_autogen___1(struct __anonymous11 *___dst__P14s__anonymous11_1){
     ((void)((*((short *)(&(*___dst__P14s__anonymous11_1).__i__s_1)))) /* ?{} */);
@@ -312,8 +312,8 @@
     short __i__s_1;
 };
-static inline struct __anonymous12 ___operator_assign__F14s__anonymous12_P14s__anonymous1214s__anonymous12_autogen___1(struct __anonymous12 *___dst__P14s__anonymous12_1, struct __anonymous12 ___src__14s__anonymous12_1);
 static inline void ___constructor__F_P14s__anonymous12_autogen___1(struct __anonymous12 *___dst__P14s__anonymous12_1);
 static inline void ___constructor__F_P14s__anonymous1214s__anonymous12_autogen___1(struct __anonymous12 *___dst__P14s__anonymous12_1, struct __anonymous12 ___src__14s__anonymous12_1);
 static inline void ___destructor__F_P14s__anonymous12_autogen___1(struct __anonymous12 *___dst__P14s__anonymous12_1);
+static inline struct __anonymous12 ___operator_assign__F14s__anonymous12_P14s__anonymous1214s__anonymous12_autogen___1(struct __anonymous12 *___dst__P14s__anonymous12_1, struct __anonymous12 ___src__14s__anonymous12_1);
 static inline void ___constructor__F_P14s__anonymous12_autogen___1(struct __anonymous12 *___dst__P14s__anonymous12_1){
     ((void)((*((short *)(&(*___dst__P14s__anonymous12_1).__i__s_1)))) /* ?{} */);
@@ -336,8 +336,8 @@
     short __i__s_1;
 };
-static inline struct __anonymous13 ___operator_assign__F14s__anonymous13_P14s__anonymous1314s__anonymous13_autogen___1(struct __anonymous13 *___dst__P14s__anonymous13_1, struct __anonymous13 ___src__14s__anonymous13_1);
 static inline void ___constructor__F_P14s__anonymous13_autogen___1(struct __anonymous13 *___dst__P14s__anonymous13_1);
 static inline void ___constructor__F_P14s__anonymous1314s__anonymous13_autogen___1(struct __anonymous13 *___dst__P14s__anonymous13_1, struct __anonymous13 ___src__14s__anonymous13_1);
 static inline void ___destructor__F_P14s__anonymous13_autogen___1(struct __anonymous13 *___dst__P14s__anonymous13_1);
+static inline struct __anonymous13 ___operator_assign__F14s__anonymous13_P14s__anonymous1314s__anonymous13_autogen___1(struct __anonymous13 *___dst__P14s__anonymous13_1, struct __anonymous13 ___src__14s__anonymous13_1);
 static inline void ___constructor__F_P14s__anonymous13_autogen___1(struct __anonymous13 *___dst__P14s__anonymous13_1){
     ((void)((*((short *)(&(*___dst__P14s__anonymous13_1).__i__s_1)))) /* ?{} */);
@@ -360,8 +360,8 @@
     short __i__s_1;
 };
-static inline struct __anonymous14 ___operator_assign__F14s__anonymous14_P14s__anonymous1414s__anonymous14_autogen___1(struct __anonymous14 *___dst__P14s__anonymous14_1, struct __anonymous14 ___src__14s__anonymous14_1);
 static inline void ___constructor__F_P14s__anonymous14_autogen___1(struct __anonymous14 *___dst__P14s__anonymous14_1);
 static inline void ___constructor__F_P14s__anonymous1414s__anonymous14_autogen___1(struct __anonymous14 *___dst__P14s__anonymous14_1, struct __anonymous14 ___src__14s__anonymous14_1);
 static inline void ___destructor__F_P14s__anonymous14_autogen___1(struct __anonymous14 *___dst__P14s__anonymous14_1);
+static inline struct __anonymous14 ___operator_assign__F14s__anonymous14_P14s__anonymous1414s__anonymous14_autogen___1(struct __anonymous14 *___dst__P14s__anonymous14_1, struct __anonymous14 ___src__14s__anonymous14_1);
 static inline void ___constructor__F_P14s__anonymous14_autogen___1(struct __anonymous14 *___dst__P14s__anonymous14_1){
     ((void)((*((short *)(&(*___dst__P14s__anonymous14_1).__i__s_1)))) /* ?{} */);
@@ -384,8 +384,8 @@
     short __i__s_1;
 };
-static inline struct __anonymous15 ___operator_assign__F14s__anonymous15_P14s__anonymous1514s__anonymous15_autogen___1(struct __anonymous15 *___dst__P14s__anonymous15_1, struct __anonymous15 ___src__14s__anonymous15_1);
 static inline void ___constructor__F_P14s__anonymous15_autogen___1(struct __anonymous15 *___dst__P14s__anonymous15_1);
 static inline void ___constructor__F_P14s__anonymous1514s__anonymous15_autogen___1(struct __anonymous15 *___dst__P14s__anonymous15_1, struct __anonymous15 ___src__14s__anonymous15_1);
 static inline void ___destructor__F_P14s__anonymous15_autogen___1(struct __anonymous15 *___dst__P14s__anonymous15_1);
+static inline struct __anonymous15 ___operator_assign__F14s__anonymous15_P14s__anonymous1514s__anonymous15_autogen___1(struct __anonymous15 *___dst__P14s__anonymous15_1, struct __anonymous15 ___src__14s__anonymous15_1);
 static inline void ___constructor__F_P14s__anonymous15_autogen___1(struct __anonymous15 *___dst__P14s__anonymous15_1){
     ((void)((*((short *)(&(*___dst__P14s__anonymous15_1).__i__s_1)))) /* ?{} */);
@@ -424,8 +424,8 @@
     int __i__i_1;
 };
-static inline struct __anonymous16 ___operator_assign__F14s__anonymous16_P14s__anonymous1614s__anonymous16_autogen___1(struct __anonymous16 *___dst__P14s__anonymous16_1, struct __anonymous16 ___src__14s__anonymous16_1);
 static inline void ___constructor__F_P14s__anonymous16_autogen___1(struct __anonymous16 *___dst__P14s__anonymous16_1);
 static inline void ___constructor__F_P14s__anonymous1614s__anonymous16_autogen___1(struct __anonymous16 *___dst__P14s__anonymous16_1, struct __anonymous16 ___src__14s__anonymous16_1);
 static inline void ___destructor__F_P14s__anonymous16_autogen___1(struct __anonymous16 *___dst__P14s__anonymous16_1);
+static inline struct __anonymous16 ___operator_assign__F14s__anonymous16_P14s__anonymous1614s__anonymous16_autogen___1(struct __anonymous16 *___dst__P14s__anonymous16_1, struct __anonymous16 ___src__14s__anonymous16_1);
 static inline void ___constructor__F_P14s__anonymous16_autogen___1(struct __anonymous16 *___dst__P14s__anonymous16_1){
     ((void)((*((int *)(&(*___dst__P14s__anonymous16_1).__i__i_1)))) /* ?{} */);
@@ -448,8 +448,8 @@
     int __i__i_1;
 };
-static inline struct __anonymous17 ___operator_assign__F14s__anonymous17_P14s__anonymous1714s__anonymous17_autogen___1(struct __anonymous17 *___dst__P14s__anonymous17_1, struct __anonymous17 ___src__14s__anonymous17_1);
 static inline void ___constructor__F_P14s__anonymous17_autogen___1(struct __anonymous17 *___dst__P14s__anonymous17_1);
 static inline void ___constructor__F_P14s__anonymous1714s__anonymous17_autogen___1(struct __anonymous17 *___dst__P14s__anonymous17_1, struct __anonymous17 ___src__14s__anonymous17_1);
 static inline void ___destructor__F_P14s__anonymous17_autogen___1(struct __anonymous17 *___dst__P14s__anonymous17_1);
+static inline struct __anonymous17 ___operator_assign__F14s__anonymous17_P14s__anonymous1714s__anonymous17_autogen___1(struct __anonymous17 *___dst__P14s__anonymous17_1, struct __anonymous17 ___src__14s__anonymous17_1);
 static inline void ___constructor__F_P14s__anonymous17_autogen___1(struct __anonymous17 *___dst__P14s__anonymous17_1){
     ((void)((*((int *)(&(*___dst__P14s__anonymous17_1).__i__i_1)))) /* ?{} */);
@@ -472,8 +472,8 @@
     int __i__i_1;
 };
-static inline struct __anonymous18 ___operator_assign__F14s__anonymous18_P14s__anonymous1814s__anonymous18_autogen___1(struct __anonymous18 *___dst__P14s__anonymous18_1, struct __anonymous18 ___src__14s__anonymous18_1);
 static inline void ___constructor__F_P14s__anonymous18_autogen___1(struct __anonymous18 *___dst__P14s__anonymous18_1);
 static inline void ___constructor__F_P14s__anonymous1814s__anonymous18_autogen___1(struct __anonymous18 *___dst__P14s__anonymous18_1, struct __anonymous18 ___src__14s__anonymous18_1);
 static inline void ___destructor__F_P14s__anonymous18_autogen___1(struct __anonymous18 *___dst__P14s__anonymous18_1);
+static inline struct __anonymous18 ___operator_assign__F14s__anonymous18_P14s__anonymous1814s__anonymous18_autogen___1(struct __anonymous18 *___dst__P14s__anonymous18_1, struct __anonymous18 ___src__14s__anonymous18_1);
 static inline void ___constructor__F_P14s__anonymous18_autogen___1(struct __anonymous18 *___dst__P14s__anonymous18_1){
     ((void)((*((int *)(&(*___dst__P14s__anonymous18_1).__i__i_1)))) /* ?{} */);
@@ -496,8 +496,8 @@
     int __i__i_1;
 };
-static inline struct __anonymous19 ___operator_assign__F14s__anonymous19_P14s__anonymous1914s__anonymous19_autogen___1(struct __anonymous19 *___dst__P14s__anonymous19_1, struct __anonymous19 ___src__14s__anonymous19_1);
 static inline void ___constructor__F_P14s__anonymous19_autogen___1(struct __anonymous19 *___dst__P14s__anonymous19_1);
 static inline void ___constructor__F_P14s__anonymous1914s__anonymous19_autogen___1(struct __anonymous19 *___dst__P14s__anonymous19_1, struct __anonymous19 ___src__14s__anonymous19_1);
 static inline void ___destructor__F_P14s__anonymous19_autogen___1(struct __anonymous19 *___dst__P14s__anonymous19_1);
+static inline struct __anonymous19 ___operator_assign__F14s__anonymous19_P14s__anonymous1914s__anonymous19_autogen___1(struct __anonymous19 *___dst__P14s__anonymous19_1, struct __anonymous19 ___src__14s__anonymous19_1);
 static inline void ___constructor__F_P14s__anonymous19_autogen___1(struct __anonymous19 *___dst__P14s__anonymous19_1){
     ((void)((*((int *)(&(*___dst__P14s__anonymous19_1).__i__i_1)))) /* ?{} */);
@@ -520,8 +520,8 @@
     int __i__i_1;
 };
-static inline struct __anonymous20 ___operator_assign__F14s__anonymous20_P14s__anonymous2014s__anonymous20_autogen___1(struct __anonymous20 *___dst__P14s__anonymous20_1, struct __anonymous20 ___src__14s__anonymous20_1);
 static inline void ___constructor__F_P14s__anonymous20_autogen___1(struct __anonymous20 *___dst__P14s__anonymous20_1);
 static inline void ___constructor__F_P14s__anonymous2014s__anonymous20_autogen___1(struct __anonymous20 *___dst__P14s__anonymous20_1, struct __anonymous20 ___src__14s__anonymous20_1);
 static inline void ___destructor__F_P14s__anonymous20_autogen___1(struct __anonymous20 *___dst__P14s__anonymous20_1);
+static inline struct __anonymous20 ___operator_assign__F14s__anonymous20_P14s__anonymous2014s__anonymous20_autogen___1(struct __anonymous20 *___dst__P14s__anonymous20_1, struct __anonymous20 ___src__14s__anonymous20_1);
 static inline void ___constructor__F_P14s__anonymous20_autogen___1(struct __anonymous20 *___dst__P14s__anonymous20_1){
     ((void)((*((int *)(&(*___dst__P14s__anonymous20_1).__i__i_1)))) /* ?{} */);
@@ -544,8 +544,8 @@
     int __i__i_1;
 };
-static inline struct __anonymous21 ___operator_assign__F14s__anonymous21_P14s__anonymous2114s__anonymous21_autogen___1(struct __anonymous21 *___dst__P14s__anonymous21_1, struct __anonymous21 ___src__14s__anonymous21_1);
 static inline void ___constructor__F_P14s__anonymous21_autogen___1(struct __anonymous21 *___dst__P14s__anonymous21_1);
 static inline void ___constructor__F_P14s__anonymous2114s__anonymous21_autogen___1(struct __anonymous21 *___dst__P14s__anonymous21_1, struct __anonymous21 ___src__14s__anonymous21_1);
 static inline void ___destructor__F_P14s__anonymous21_autogen___1(struct __anonymous21 *___dst__P14s__anonymous21_1);
+static inline struct __anonymous21 ___operator_assign__F14s__anonymous21_P14s__anonymous2114s__anonymous21_autogen___1(struct __anonymous21 *___dst__P14s__anonymous21_1, struct __anonymous21 ___src__14s__anonymous21_1);
 static inline void ___constructor__F_P14s__anonymous21_autogen___1(struct __anonymous21 *___dst__P14s__anonymous21_1){
     ((void)((*((int *)(&(*___dst__P14s__anonymous21_1).__i__i_1)))) /* ?{} */);
@@ -568,8 +568,8 @@
     int __i__i_1;
 };
-static inline struct __anonymous22 ___operator_assign__F14s__anonymous22_P14s__anonymous2214s__anonymous22_autogen___1(struct __anonymous22 *___dst__P14s__anonymous22_1, struct __anonymous22 ___src__14s__anonymous22_1);
 static inline void ___constructor__F_P14s__anonymous22_autogen___1(struct __anonymous22 *___dst__P14s__anonymous22_1);
 static inline void ___constructor__F_P14s__anonymous2214s__anonymous22_autogen___1(struct __anonymous22 *___dst__P14s__anonymous22_1, struct __anonymous22 ___src__14s__anonymous22_1);
 static inline void ___destructor__F_P14s__anonymous22_autogen___1(struct __anonymous22 *___dst__P14s__anonymous22_1);
+static inline struct __anonymous22 ___operator_assign__F14s__anonymous22_P14s__anonymous2214s__anonymous22_autogen___1(struct __anonymous22 *___dst__P14s__anonymous22_1, struct __anonymous22 ___src__14s__anonymous22_1);
 static inline void ___constructor__F_P14s__anonymous22_autogen___1(struct __anonymous22 *___dst__P14s__anonymous22_1){
     ((void)((*((int *)(&(*___dst__P14s__anonymous22_1).__i__i_1)))) /* ?{} */);
@@ -592,8 +592,8 @@
     int __i__i_1;
 };
-static inline struct __anonymous23 ___operator_assign__F14s__anonymous23_P14s__anonymous2314s__anonymous23_autogen___1(struct __anonymous23 *___dst__P14s__anonymous23_1, struct __anonymous23 ___src__14s__anonymous23_1);
 static inline void ___constructor__F_P14s__anonymous23_autogen___1(struct __anonymous23 *___dst__P14s__anonymous23_1);
 static inline void ___constructor__F_P14s__anonymous2314s__anonymous23_autogen___1(struct __anonymous23 *___dst__P14s__anonymous23_1, struct __anonymous23 ___src__14s__anonymous23_1);
 static inline void ___destructor__F_P14s__anonymous23_autogen___1(struct __anonymous23 *___dst__P14s__anonymous23_1);
+static inline struct __anonymous23 ___operator_assign__F14s__anonymous23_P14s__anonymous2314s__anonymous23_autogen___1(struct __anonymous23 *___dst__P14s__anonymous23_1, struct __anonymous23 ___src__14s__anonymous23_1);
 static inline void ___constructor__F_P14s__anonymous23_autogen___1(struct __anonymous23 *___dst__P14s__anonymous23_1){
     ((void)((*((int *)(&(*___dst__P14s__anonymous23_1).__i__i_1)))) /* ?{} */);
@@ -629,9 +629,9 @@
 }
 static inline int invoke_main(int argc, char* argv[], char* envp[]) { (void)argc; (void)argv; (void)envp; return __main__Fi_iPPCc__1(argc, argv); }
-extern void *malloc(unsigned int __size);
-extern void free(void *__ptr);
-extern void abort(void);
-extern int atexit(void (*__func)(void));
-extern void exit(int __status);
+__attribute__ ((__malloc__,__nothrow__,__leaf__)) extern void *malloc(unsigned int __size);
+__attribute__ ((__nothrow__,__leaf__)) extern void free(void *__ptr);
+__attribute__ ((__noreturn__,__nothrow__,__leaf__)) extern void abort(void);
+__attribute__ ((__nonnull__(1),__nothrow__,__leaf__)) extern int atexit(void (*__func)(void));
+__attribute__ ((__noreturn__,__nothrow__,__leaf__)) extern void exit(int __status);
 extern int printf(const char *__restrict __format, ...);
 static inline int invoke_main(int argc, char **argv, char **envp);
@@ -640,5 +640,5 @@
     int _tmp_cp_ret0;
     ((void)(___retval_main__i_1=((_tmp_cp_ret0=invoke_main(__argc__i_1, __argv__PPc_1, __envp__PPc_1)) , _tmp_cp_ret0)) /* ?{} */);
-    ((void)(_tmp_cp_ret0) /* ^?{} */);
+    ((void)((*((int *)(&_tmp_cp_ret0)))) /* ^?{} */);
     return ((int )___retval_main__i_1);
 }
Index: src/tests/.expect/32/extension.txt
===================================================================
--- src/tests/.expect/32/extension.txt	(revision 6acb935ec45eabc0c4c2c47501d76a9c231f7219)
+++ src/tests/.expect/32/extension.txt	(revision a362f977ce917e9868e8b98a81cc260e0aee5cf9)
@@ -1,7 +1,7 @@
-extern void *malloc(unsigned int __size);
-extern void free(void *__ptr);
-extern void abort(void);
-extern int atexit(void (*__func)(void));
-extern void exit(int __status);
+__attribute__ ((__malloc__,__nothrow__,__leaf__)) extern void *malloc(unsigned int __size);
+__attribute__ ((__nothrow__,__leaf__)) extern void free(void *__ptr);
+__attribute__ ((__noreturn__,__nothrow__,__leaf__)) extern void abort(void);
+__attribute__ ((__nonnull__(1),__nothrow__,__leaf__)) extern int atexit(void (*__func)(void));
+__attribute__ ((__noreturn__,__nothrow__,__leaf__)) extern void exit(int __status);
 extern int printf(const char *__restrict __format, ...);
 __extension__ int __a__i_1;
@@ -13,8 +13,8 @@
     __extension__ int __c__i_1;
 };
-static inline struct S ___operator_assign__F2sS_P2sS2sS_autogen___1(struct S *___dst__P2sS_1, struct S ___src__2sS_1);
 static inline void ___constructor__F_P2sS_autogen___1(struct S *___dst__P2sS_1);
 static inline void ___constructor__F_P2sS2sS_autogen___1(struct S *___dst__P2sS_1, struct S ___src__2sS_1);
 static inline void ___destructor__F_P2sS_autogen___1(struct S *___dst__P2sS_1);
+static inline struct S ___operator_assign__F2sS_P2sS2sS_autogen___1(struct S *___dst__P2sS_1, struct S ___src__2sS_1);
 static inline void ___constructor__F_P2sS_autogen___1(struct S *___dst__P2sS_1){
     ((void)((*((int *)(&(*___dst__P2sS_1).__a__i_1)))) /* ?{} */);
@@ -93,5 +93,5 @@
     int _tmp_cp_ret0;
     ((void)((_tmp_cp_ret0=__extension__ __fred__Fi_i__1(3)) , _tmp_cp_ret0));
-    ((void)(_tmp_cp_ret0) /* ^?{} */);
+    ((void)((*((int *)(&_tmp_cp_ret0)))) /* ^?{} */);
     ((void)__extension__ sizeof(3));
     ((void)__extension__ (((int )(3!=((int )0))) || ((int )(4!=((int )0)))));
Index: src/tests/.expect/32/gccExtensions.txt
===================================================================
--- src/tests/.expect/32/gccExtensions.txt	(revision 6acb935ec45eabc0c4c2c47501d76a9c231f7219)
+++ src/tests/.expect/32/gccExtensions.txt	(revision a362f977ce917e9868e8b98a81cc260e0aee5cf9)
@@ -1,7 +1,7 @@
-extern void *malloc(unsigned int __size);
-extern void free(void *__ptr);
-extern void abort(void);
-extern int atexit(void (*__func)(void));
-extern void exit(int __status);
+__attribute__ ((__malloc__,__nothrow__,__leaf__)) extern void *malloc(unsigned int __size);
+__attribute__ ((__nothrow__,__leaf__)) extern void free(void *__ptr);
+__attribute__ ((__noreturn__,__nothrow__,__leaf__)) extern void abort(void);
+__attribute__ ((__nonnull__(1),__nothrow__,__leaf__)) extern int atexit(void (*__func)(void));
+__attribute__ ((__noreturn__,__nothrow__,__leaf__)) extern void exit(int __status);
 extern int printf(const char *__restrict __format, ...);
 extern int __x__i_1 asm ( "xx" );
@@ -166,9 +166,9 @@
 }
 static inline int invoke_main(int argc, char* argv[], char* envp[]) { (void)argc; (void)argv; (void)envp; return __main__Fi_iPPCc__1(argc, argv); }
-extern void *malloc(unsigned int __size);
-extern void free(void *__ptr);
-extern void abort(void);
-extern int atexit(void (*__func)(void));
-extern void exit(int __status);
+__attribute__ ((__malloc__,__nothrow__,__leaf__)) extern void *malloc(unsigned int __size);
+__attribute__ ((__nothrow__,__leaf__)) extern void free(void *__ptr);
+__attribute__ ((__noreturn__,__nothrow__,__leaf__)) extern void abort(void);
+__attribute__ ((__nonnull__(1),__nothrow__,__leaf__)) extern int atexit(void (*__func)(void));
+__attribute__ ((__noreturn__,__nothrow__,__leaf__)) extern void exit(int __status);
 extern int printf(const char *__restrict __format, ...);
 static inline int invoke_main(int argc, char **argv, char **envp);
@@ -177,5 +177,5 @@
     int _tmp_cp_ret0;
     ((void)(___retval_main__i_1=((_tmp_cp_ret0=invoke_main(__argc__i_1, __argv__PPc_1, __envp__PPc_1)) , _tmp_cp_ret0)) /* ?{} */);
-    ((void)(_tmp_cp_ret0) /* ^?{} */);
+    ((void)((*((int *)(&_tmp_cp_ret0)))) /* ^?{} */);
     return ((int )___retval_main__i_1);
 }
Index: src/tests/.expect/64/declarationSpecifier.txt
===================================================================
--- src/tests/.expect/64/declarationSpecifier.txt	(revision 6acb935ec45eabc0c4c2c47501d76a9c231f7219)
+++ src/tests/.expect/64/declarationSpecifier.txt	(revision a362f977ce917e9868e8b98a81cc260e0aee5cf9)
@@ -16,8 +16,8 @@
     int __i__i_1;
 };
-static inline struct __anonymous0 ___operator_assign__F13s__anonymous0_P13s__anonymous013s__anonymous0_autogen___1(struct __anonymous0 *___dst__P13s__anonymous0_1, struct __anonymous0 ___src__13s__anonymous0_1);
 static inline void ___constructor__F_P13s__anonymous0_autogen___1(struct __anonymous0 *___dst__P13s__anonymous0_1);
 static inline void ___constructor__F_P13s__anonymous013s__anonymous0_autogen___1(struct __anonymous0 *___dst__P13s__anonymous0_1, struct __anonymous0 ___src__13s__anonymous0_1);
 static inline void ___destructor__F_P13s__anonymous0_autogen___1(struct __anonymous0 *___dst__P13s__anonymous0_1);
+static inline struct __anonymous0 ___operator_assign__F13s__anonymous0_P13s__anonymous013s__anonymous0_autogen___1(struct __anonymous0 *___dst__P13s__anonymous0_1, struct __anonymous0 ___src__13s__anonymous0_1);
 static inline void ___constructor__F_P13s__anonymous0_autogen___1(struct __anonymous0 *___dst__P13s__anonymous0_1){
     ((void)((*((int *)(&(*___dst__P13s__anonymous0_1).__i__i_1)))) /* ?{} */);
@@ -40,8 +40,8 @@
     int __i__i_1;
 };
-static inline struct __anonymous1 ___operator_assign__F13s__anonymous1_P13s__anonymous113s__anonymous1_autogen___1(struct __anonymous1 *___dst__P13s__anonymous1_1, struct __anonymous1 ___src__13s__anonymous1_1);
 static inline void ___constructor__F_P13s__anonymous1_autogen___1(struct __anonymous1 *___dst__P13s__anonymous1_1);
 static inline void ___constructor__F_P13s__anonymous113s__anonymous1_autogen___1(struct __anonymous1 *___dst__P13s__anonymous1_1, struct __anonymous1 ___src__13s__anonymous1_1);
 static inline void ___destructor__F_P13s__anonymous1_autogen___1(struct __anonymous1 *___dst__P13s__anonymous1_1);
+static inline struct __anonymous1 ___operator_assign__F13s__anonymous1_P13s__anonymous113s__anonymous1_autogen___1(struct __anonymous1 *___dst__P13s__anonymous1_1, struct __anonymous1 ___src__13s__anonymous1_1);
 static inline void ___constructor__F_P13s__anonymous1_autogen___1(struct __anonymous1 *___dst__P13s__anonymous1_1){
     ((void)((*((int *)(&(*___dst__P13s__anonymous1_1).__i__i_1)))) /* ?{} */);
@@ -64,8 +64,8 @@
     int __i__i_1;
 };
-static inline struct __anonymous2 ___operator_assign__F13s__anonymous2_P13s__anonymous213s__anonymous2_autogen___1(struct __anonymous2 *___dst__P13s__anonymous2_1, struct __anonymous2 ___src__13s__anonymous2_1);
 static inline void ___constructor__F_P13s__anonymous2_autogen___1(struct __anonymous2 *___dst__P13s__anonymous2_1);
 static inline void ___constructor__F_P13s__anonymous213s__anonymous2_autogen___1(struct __anonymous2 *___dst__P13s__anonymous2_1, struct __anonymous2 ___src__13s__anonymous2_1);
 static inline void ___destructor__F_P13s__anonymous2_autogen___1(struct __anonymous2 *___dst__P13s__anonymous2_1);
+static inline struct __anonymous2 ___operator_assign__F13s__anonymous2_P13s__anonymous213s__anonymous2_autogen___1(struct __anonymous2 *___dst__P13s__anonymous2_1, struct __anonymous2 ___src__13s__anonymous2_1);
 static inline void ___constructor__F_P13s__anonymous2_autogen___1(struct __anonymous2 *___dst__P13s__anonymous2_1){
     ((void)((*((int *)(&(*___dst__P13s__anonymous2_1).__i__i_1)))) /* ?{} */);
@@ -88,8 +88,8 @@
     int __i__i_1;
 };
-static inline struct __anonymous3 ___operator_assign__F13s__anonymous3_P13s__anonymous313s__anonymous3_autogen___1(struct __anonymous3 *___dst__P13s__anonymous3_1, struct __anonymous3 ___src__13s__anonymous3_1);
 static inline void ___constructor__F_P13s__anonymous3_autogen___1(struct __anonymous3 *___dst__P13s__anonymous3_1);
 static inline void ___constructor__F_P13s__anonymous313s__anonymous3_autogen___1(struct __anonymous3 *___dst__P13s__anonymous3_1, struct __anonymous3 ___src__13s__anonymous3_1);
 static inline void ___destructor__F_P13s__anonymous3_autogen___1(struct __anonymous3 *___dst__P13s__anonymous3_1);
+static inline struct __anonymous3 ___operator_assign__F13s__anonymous3_P13s__anonymous313s__anonymous3_autogen___1(struct __anonymous3 *___dst__P13s__anonymous3_1, struct __anonymous3 ___src__13s__anonymous3_1);
 static inline void ___constructor__F_P13s__anonymous3_autogen___1(struct __anonymous3 *___dst__P13s__anonymous3_1){
     ((void)((*((int *)(&(*___dst__P13s__anonymous3_1).__i__i_1)))) /* ?{} */);
@@ -112,8 +112,8 @@
     int __i__i_1;
 };
-static inline struct __anonymous4 ___operator_assign__F13s__anonymous4_P13s__anonymous413s__anonymous4_autogen___1(struct __anonymous4 *___dst__P13s__anonymous4_1, struct __anonymous4 ___src__13s__anonymous4_1);
 static inline void ___constructor__F_P13s__anonymous4_autogen___1(struct __anonymous4 *___dst__P13s__anonymous4_1);
 static inline void ___constructor__F_P13s__anonymous413s__anonymous4_autogen___1(struct __anonymous4 *___dst__P13s__anonymous4_1, struct __anonymous4 ___src__13s__anonymous4_1);
 static inline void ___destructor__F_P13s__anonymous4_autogen___1(struct __anonymous4 *___dst__P13s__anonymous4_1);
+static inline struct __anonymous4 ___operator_assign__F13s__anonymous4_P13s__anonymous413s__anonymous4_autogen___1(struct __anonymous4 *___dst__P13s__anonymous4_1, struct __anonymous4 ___src__13s__anonymous4_1);
 static inline void ___constructor__F_P13s__anonymous4_autogen___1(struct __anonymous4 *___dst__P13s__anonymous4_1){
     ((void)((*((int *)(&(*___dst__P13s__anonymous4_1).__i__i_1)))) /* ?{} */);
@@ -136,8 +136,8 @@
     int __i__i_1;
 };
-static inline struct __anonymous5 ___operator_assign__F13s__anonymous5_P13s__anonymous513s__anonymous5_autogen___1(struct __anonymous5 *___dst__P13s__anonymous5_1, struct __anonymous5 ___src__13s__anonymous5_1);
 static inline void ___constructor__F_P13s__anonymous5_autogen___1(struct __anonymous5 *___dst__P13s__anonymous5_1);
 static inline void ___constructor__F_P13s__anonymous513s__anonymous5_autogen___1(struct __anonymous5 *___dst__P13s__anonymous5_1, struct __anonymous5 ___src__13s__anonymous5_1);
 static inline void ___destructor__F_P13s__anonymous5_autogen___1(struct __anonymous5 *___dst__P13s__anonymous5_1);
+static inline struct __anonymous5 ___operator_assign__F13s__anonymous5_P13s__anonymous513s__anonymous5_autogen___1(struct __anonymous5 *___dst__P13s__anonymous5_1, struct __anonymous5 ___src__13s__anonymous5_1);
 static inline void ___constructor__F_P13s__anonymous5_autogen___1(struct __anonymous5 *___dst__P13s__anonymous5_1){
     ((void)((*((int *)(&(*___dst__P13s__anonymous5_1).__i__i_1)))) /* ?{} */);
@@ -160,8 +160,8 @@
     int __i__i_1;
 };
-static inline struct __anonymous6 ___operator_assign__F13s__anonymous6_P13s__anonymous613s__anonymous6_autogen___1(struct __anonymous6 *___dst__P13s__anonymous6_1, struct __anonymous6 ___src__13s__anonymous6_1);
 static inline void ___constructor__F_P13s__anonymous6_autogen___1(struct __anonymous6 *___dst__P13s__anonymous6_1);
 static inline void ___constructor__F_P13s__anonymous613s__anonymous6_autogen___1(struct __anonymous6 *___dst__P13s__anonymous6_1, struct __anonymous6 ___src__13s__anonymous6_1);
 static inline void ___destructor__F_P13s__anonymous6_autogen___1(struct __anonymous6 *___dst__P13s__anonymous6_1);
+static inline struct __anonymous6 ___operator_assign__F13s__anonymous6_P13s__anonymous613s__anonymous6_autogen___1(struct __anonymous6 *___dst__P13s__anonymous6_1, struct __anonymous6 ___src__13s__anonymous6_1);
 static inline void ___constructor__F_P13s__anonymous6_autogen___1(struct __anonymous6 *___dst__P13s__anonymous6_1){
     ((void)((*((int *)(&(*___dst__P13s__anonymous6_1).__i__i_1)))) /* ?{} */);
@@ -184,8 +184,8 @@
     int __i__i_1;
 };
-static inline struct __anonymous7 ___operator_assign__F13s__anonymous7_P13s__anonymous713s__anonymous7_autogen___1(struct __anonymous7 *___dst__P13s__anonymous7_1, struct __anonymous7 ___src__13s__anonymous7_1);
 static inline void ___constructor__F_P13s__anonymous7_autogen___1(struct __anonymous7 *___dst__P13s__anonymous7_1);
 static inline void ___constructor__F_P13s__anonymous713s__anonymous7_autogen___1(struct __anonymous7 *___dst__P13s__anonymous7_1, struct __anonymous7 ___src__13s__anonymous7_1);
 static inline void ___destructor__F_P13s__anonymous7_autogen___1(struct __anonymous7 *___dst__P13s__anonymous7_1);
+static inline struct __anonymous7 ___operator_assign__F13s__anonymous7_P13s__anonymous713s__anonymous7_autogen___1(struct __anonymous7 *___dst__P13s__anonymous7_1, struct __anonymous7 ___src__13s__anonymous7_1);
 static inline void ___constructor__F_P13s__anonymous7_autogen___1(struct __anonymous7 *___dst__P13s__anonymous7_1){
     ((void)((*((int *)(&(*___dst__P13s__anonymous7_1).__i__i_1)))) /* ?{} */);
@@ -216,8 +216,8 @@
     short __i__s_1;
 };
-static inline struct __anonymous8 ___operator_assign__F13s__anonymous8_P13s__anonymous813s__anonymous8_autogen___1(struct __anonymous8 *___dst__P13s__anonymous8_1, struct __anonymous8 ___src__13s__anonymous8_1);
 static inline void ___constructor__F_P13s__anonymous8_autogen___1(struct __anonymous8 *___dst__P13s__anonymous8_1);
 static inline void ___constructor__F_P13s__anonymous813s__anonymous8_autogen___1(struct __anonymous8 *___dst__P13s__anonymous8_1, struct __anonymous8 ___src__13s__anonymous8_1);
 static inline void ___destructor__F_P13s__anonymous8_autogen___1(struct __anonymous8 *___dst__P13s__anonymous8_1);
+static inline struct __anonymous8 ___operator_assign__F13s__anonymous8_P13s__anonymous813s__anonymous8_autogen___1(struct __anonymous8 *___dst__P13s__anonymous8_1, struct __anonymous8 ___src__13s__anonymous8_1);
 static inline void ___constructor__F_P13s__anonymous8_autogen___1(struct __anonymous8 *___dst__P13s__anonymous8_1){
     ((void)((*((short *)(&(*___dst__P13s__anonymous8_1).__i__s_1)))) /* ?{} */);
@@ -240,8 +240,8 @@
     short __i__s_1;
 };
-static inline struct __anonymous9 ___operator_assign__F13s__anonymous9_P13s__anonymous913s__anonymous9_autogen___1(struct __anonymous9 *___dst__P13s__anonymous9_1, struct __anonymous9 ___src__13s__anonymous9_1);
 static inline void ___constructor__F_P13s__anonymous9_autogen___1(struct __anonymous9 *___dst__P13s__anonymous9_1);
 static inline void ___constructor__F_P13s__anonymous913s__anonymous9_autogen___1(struct __anonymous9 *___dst__P13s__anonymous9_1, struct __anonymous9 ___src__13s__anonymous9_1);
 static inline void ___destructor__F_P13s__anonymous9_autogen___1(struct __anonymous9 *___dst__P13s__anonymous9_1);
+static inline struct __anonymous9 ___operator_assign__F13s__anonymous9_P13s__anonymous913s__anonymous9_autogen___1(struct __anonymous9 *___dst__P13s__anonymous9_1, struct __anonymous9 ___src__13s__anonymous9_1);
 static inline void ___constructor__F_P13s__anonymous9_autogen___1(struct __anonymous9 *___dst__P13s__anonymous9_1){
     ((void)((*((short *)(&(*___dst__P13s__anonymous9_1).__i__s_1)))) /* ?{} */);
@@ -264,8 +264,8 @@
     short __i__s_1;
 };
-static inline struct __anonymous10 ___operator_assign__F14s__anonymous10_P14s__anonymous1014s__anonymous10_autogen___1(struct __anonymous10 *___dst__P14s__anonymous10_1, struct __anonymous10 ___src__14s__anonymous10_1);
 static inline void ___constructor__F_P14s__anonymous10_autogen___1(struct __anonymous10 *___dst__P14s__anonymous10_1);
 static inline void ___constructor__F_P14s__anonymous1014s__anonymous10_autogen___1(struct __anonymous10 *___dst__P14s__anonymous10_1, struct __anonymous10 ___src__14s__anonymous10_1);
 static inline void ___destructor__F_P14s__anonymous10_autogen___1(struct __anonymous10 *___dst__P14s__anonymous10_1);
+static inline struct __anonymous10 ___operator_assign__F14s__anonymous10_P14s__anonymous1014s__anonymous10_autogen___1(struct __anonymous10 *___dst__P14s__anonymous10_1, struct __anonymous10 ___src__14s__anonymous10_1);
 static inline void ___constructor__F_P14s__anonymous10_autogen___1(struct __anonymous10 *___dst__P14s__anonymous10_1){
     ((void)((*((short *)(&(*___dst__P14s__anonymous10_1).__i__s_1)))) /* ?{} */);
@@ -288,8 +288,8 @@
     short __i__s_1;
 };
-static inline struct __anonymous11 ___operator_assign__F14s__anonymous11_P14s__anonymous1114s__anonymous11_autogen___1(struct __anonymous11 *___dst__P14s__anonymous11_1, struct __anonymous11 ___src__14s__anonymous11_1);
 static inline void ___constructor__F_P14s__anonymous11_autogen___1(struct __anonymous11 *___dst__P14s__anonymous11_1);
 static inline void ___constructor__F_P14s__anonymous1114s__anonymous11_autogen___1(struct __anonymous11 *___dst__P14s__anonymous11_1, struct __anonymous11 ___src__14s__anonymous11_1);
 static inline void ___destructor__F_P14s__anonymous11_autogen___1(struct __anonymous11 *___dst__P14s__anonymous11_1);
+static inline struct __anonymous11 ___operator_assign__F14s__anonymous11_P14s__anonymous1114s__anonymous11_autogen___1(struct __anonymous11 *___dst__P14s__anonymous11_1, struct __anonymous11 ___src__14s__anonymous11_1);
 static inline void ___constructor__F_P14s__anonymous11_autogen___1(struct __anonymous11 *___dst__P14s__anonymous11_1){
     ((void)((*((short *)(&(*___dst__P14s__anonymous11_1).__i__s_1)))) /* ?{} */);
@@ -312,8 +312,8 @@
     short __i__s_1;
 };
-static inline struct __anonymous12 ___operator_assign__F14s__anonymous12_P14s__anonymous1214s__anonymous12_autogen___1(struct __anonymous12 *___dst__P14s__anonymous12_1, struct __anonymous12 ___src__14s__anonymous12_1);
 static inline void ___constructor__F_P14s__anonymous12_autogen___1(struct __anonymous12 *___dst__P14s__anonymous12_1);
 static inline void ___constructor__F_P14s__anonymous1214s__anonymous12_autogen___1(struct __anonymous12 *___dst__P14s__anonymous12_1, struct __anonymous12 ___src__14s__anonymous12_1);
 static inline void ___destructor__F_P14s__anonymous12_autogen___1(struct __anonymous12 *___dst__P14s__anonymous12_1);
+static inline struct __anonymous12 ___operator_assign__F14s__anonymous12_P14s__anonymous1214s__anonymous12_autogen___1(struct __anonymous12 *___dst__P14s__anonymous12_1, struct __anonymous12 ___src__14s__anonymous12_1);
 static inline void ___constructor__F_P14s__anonymous12_autogen___1(struct __anonymous12 *___dst__P14s__anonymous12_1){
     ((void)((*((short *)(&(*___dst__P14s__anonymous12_1).__i__s_1)))) /* ?{} */);
@@ -336,8 +336,8 @@
     short __i__s_1;
 };
-static inline struct __anonymous13 ___operator_assign__F14s__anonymous13_P14s__anonymous1314s__anonymous13_autogen___1(struct __anonymous13 *___dst__P14s__anonymous13_1, struct __anonymous13 ___src__14s__anonymous13_1);
 static inline void ___constructor__F_P14s__anonymous13_autogen___1(struct __anonymous13 *___dst__P14s__anonymous13_1);
 static inline void ___constructor__F_P14s__anonymous1314s__anonymous13_autogen___1(struct __anonymous13 *___dst__P14s__anonymous13_1, struct __anonymous13 ___src__14s__anonymous13_1);
 static inline void ___destructor__F_P14s__anonymous13_autogen___1(struct __anonymous13 *___dst__P14s__anonymous13_1);
+static inline struct __anonymous13 ___operator_assign__F14s__anonymous13_P14s__anonymous1314s__anonymous13_autogen___1(struct __anonymous13 *___dst__P14s__anonymous13_1, struct __anonymous13 ___src__14s__anonymous13_1);
 static inline void ___constructor__F_P14s__anonymous13_autogen___1(struct __anonymous13 *___dst__P14s__anonymous13_1){
     ((void)((*((short *)(&(*___dst__P14s__anonymous13_1).__i__s_1)))) /* ?{} */);
@@ -360,8 +360,8 @@
     short __i__s_1;
 };
-static inline struct __anonymous14 ___operator_assign__F14s__anonymous14_P14s__anonymous1414s__anonymous14_autogen___1(struct __anonymous14 *___dst__P14s__anonymous14_1, struct __anonymous14 ___src__14s__anonymous14_1);
 static inline void ___constructor__F_P14s__anonymous14_autogen___1(struct __anonymous14 *___dst__P14s__anonymous14_1);
 static inline void ___constructor__F_P14s__anonymous1414s__anonymous14_autogen___1(struct __anonymous14 *___dst__P14s__anonymous14_1, struct __anonymous14 ___src__14s__anonymous14_1);
 static inline void ___destructor__F_P14s__anonymous14_autogen___1(struct __anonymous14 *___dst__P14s__anonymous14_1);
+static inline struct __anonymous14 ___operator_assign__F14s__anonymous14_P14s__anonymous1414s__anonymous14_autogen___1(struct __anonymous14 *___dst__P14s__anonymous14_1, struct __anonymous14 ___src__14s__anonymous14_1);
 static inline void ___constructor__F_P14s__anonymous14_autogen___1(struct __anonymous14 *___dst__P14s__anonymous14_1){
     ((void)((*((short *)(&(*___dst__P14s__anonymous14_1).__i__s_1)))) /* ?{} */);
@@ -384,8 +384,8 @@
     short __i__s_1;
 };
-static inline struct __anonymous15 ___operator_assign__F14s__anonymous15_P14s__anonymous1514s__anonymous15_autogen___1(struct __anonymous15 *___dst__P14s__anonymous15_1, struct __anonymous15 ___src__14s__anonymous15_1);
 static inline void ___constructor__F_P14s__anonymous15_autogen___1(struct __anonymous15 *___dst__P14s__anonymous15_1);
 static inline void ___constructor__F_P14s__anonymous1514s__anonymous15_autogen___1(struct __anonymous15 *___dst__P14s__anonymous15_1, struct __anonymous15 ___src__14s__anonymous15_1);
 static inline void ___destructor__F_P14s__anonymous15_autogen___1(struct __anonymous15 *___dst__P14s__anonymous15_1);
+static inline struct __anonymous15 ___operator_assign__F14s__anonymous15_P14s__anonymous1514s__anonymous15_autogen___1(struct __anonymous15 *___dst__P14s__anonymous15_1, struct __anonymous15 ___src__14s__anonymous15_1);
 static inline void ___constructor__F_P14s__anonymous15_autogen___1(struct __anonymous15 *___dst__P14s__anonymous15_1){
     ((void)((*((short *)(&(*___dst__P14s__anonymous15_1).__i__s_1)))) /* ?{} */);
@@ -424,8 +424,8 @@
     int __i__i_1;
 };
-static inline struct __anonymous16 ___operator_assign__F14s__anonymous16_P14s__anonymous1614s__anonymous16_autogen___1(struct __anonymous16 *___dst__P14s__anonymous16_1, struct __anonymous16 ___src__14s__anonymous16_1);
 static inline void ___constructor__F_P14s__anonymous16_autogen___1(struct __anonymous16 *___dst__P14s__anonymous16_1);
 static inline void ___constructor__F_P14s__anonymous1614s__anonymous16_autogen___1(struct __anonymous16 *___dst__P14s__anonymous16_1, struct __anonymous16 ___src__14s__anonymous16_1);
 static inline void ___destructor__F_P14s__anonymous16_autogen___1(struct __anonymous16 *___dst__P14s__anonymous16_1);
+static inline struct __anonymous16 ___operator_assign__F14s__anonymous16_P14s__anonymous1614s__anonymous16_autogen___1(struct __anonymous16 *___dst__P14s__anonymous16_1, struct __anonymous16 ___src__14s__anonymous16_1);
 static inline void ___constructor__F_P14s__anonymous16_autogen___1(struct __anonymous16 *___dst__P14s__anonymous16_1){
     ((void)((*((int *)(&(*___dst__P14s__anonymous16_1).__i__i_1)))) /* ?{} */);
@@ -448,8 +448,8 @@
     int __i__i_1;
 };
-static inline struct __anonymous17 ___operator_assign__F14s__anonymous17_P14s__anonymous1714s__anonymous17_autogen___1(struct __anonymous17 *___dst__P14s__anonymous17_1, struct __anonymous17 ___src__14s__anonymous17_1);
 static inline void ___constructor__F_P14s__anonymous17_autogen___1(struct __anonymous17 *___dst__P14s__anonymous17_1);
 static inline void ___constructor__F_P14s__anonymous1714s__anonymous17_autogen___1(struct __anonymous17 *___dst__P14s__anonymous17_1, struct __anonymous17 ___src__14s__anonymous17_1);
 static inline void ___destructor__F_P14s__anonymous17_autogen___1(struct __anonymous17 *___dst__P14s__anonymous17_1);
+static inline struct __anonymous17 ___operator_assign__F14s__anonymous17_P14s__anonymous1714s__anonymous17_autogen___1(struct __anonymous17 *___dst__P14s__anonymous17_1, struct __anonymous17 ___src__14s__anonymous17_1);
 static inline void ___constructor__F_P14s__anonymous17_autogen___1(struct __anonymous17 *___dst__P14s__anonymous17_1){
     ((void)((*((int *)(&(*___dst__P14s__anonymous17_1).__i__i_1)))) /* ?{} */);
@@ -472,8 +472,8 @@
     int __i__i_1;
 };
-static inline struct __anonymous18 ___operator_assign__F14s__anonymous18_P14s__anonymous1814s__anonymous18_autogen___1(struct __anonymous18 *___dst__P14s__anonymous18_1, struct __anonymous18 ___src__14s__anonymous18_1);
 static inline void ___constructor__F_P14s__anonymous18_autogen___1(struct __anonymous18 *___dst__P14s__anonymous18_1);
 static inline void ___constructor__F_P14s__anonymous1814s__anonymous18_autogen___1(struct __anonymous18 *___dst__P14s__anonymous18_1, struct __anonymous18 ___src__14s__anonymous18_1);
 static inline void ___destructor__F_P14s__anonymous18_autogen___1(struct __anonymous18 *___dst__P14s__anonymous18_1);
+static inline struct __anonymous18 ___operator_assign__F14s__anonymous18_P14s__anonymous1814s__anonymous18_autogen___1(struct __anonymous18 *___dst__P14s__anonymous18_1, struct __anonymous18 ___src__14s__anonymous18_1);
 static inline void ___constructor__F_P14s__anonymous18_autogen___1(struct __anonymous18 *___dst__P14s__anonymous18_1){
     ((void)((*((int *)(&(*___dst__P14s__anonymous18_1).__i__i_1)))) /* ?{} */);
@@ -496,8 +496,8 @@
     int __i__i_1;
 };
-static inline struct __anonymous19 ___operator_assign__F14s__anonymous19_P14s__anonymous1914s__anonymous19_autogen___1(struct __anonymous19 *___dst__P14s__anonymous19_1, struct __anonymous19 ___src__14s__anonymous19_1);
 static inline void ___constructor__F_P14s__anonymous19_autogen___1(struct __anonymous19 *___dst__P14s__anonymous19_1);
 static inline void ___constructor__F_P14s__anonymous1914s__anonymous19_autogen___1(struct __anonymous19 *___dst__P14s__anonymous19_1, struct __anonymous19 ___src__14s__anonymous19_1);
 static inline void ___destructor__F_P14s__anonymous19_autogen___1(struct __anonymous19 *___dst__P14s__anonymous19_1);
+static inline struct __anonymous19 ___operator_assign__F14s__anonymous19_P14s__anonymous1914s__anonymous19_autogen___1(struct __anonymous19 *___dst__P14s__anonymous19_1, struct __anonymous19 ___src__14s__anonymous19_1);
 static inline void ___constructor__F_P14s__anonymous19_autogen___1(struct __anonymous19 *___dst__P14s__anonymous19_1){
     ((void)((*((int *)(&(*___dst__P14s__anonymous19_1).__i__i_1)))) /* ?{} */);
@@ -520,8 +520,8 @@
     int __i__i_1;
 };
-static inline struct __anonymous20 ___operator_assign__F14s__anonymous20_P14s__anonymous2014s__anonymous20_autogen___1(struct __anonymous20 *___dst__P14s__anonymous20_1, struct __anonymous20 ___src__14s__anonymous20_1);
 static inline void ___constructor__F_P14s__anonymous20_autogen___1(struct __anonymous20 *___dst__P14s__anonymous20_1);
 static inline void ___constructor__F_P14s__anonymous2014s__anonymous20_autogen___1(struct __anonymous20 *___dst__P14s__anonymous20_1, struct __anonymous20 ___src__14s__anonymous20_1);
 static inline void ___destructor__F_P14s__anonymous20_autogen___1(struct __anonymous20 *___dst__P14s__anonymous20_1);
+static inline struct __anonymous20 ___operator_assign__F14s__anonymous20_P14s__anonymous2014s__anonymous20_autogen___1(struct __anonymous20 *___dst__P14s__anonymous20_1, struct __anonymous20 ___src__14s__anonymous20_1);
 static inline void ___constructor__F_P14s__anonymous20_autogen___1(struct __anonymous20 *___dst__P14s__anonymous20_1){
     ((void)((*((int *)(&(*___dst__P14s__anonymous20_1).__i__i_1)))) /* ?{} */);
@@ -544,8 +544,8 @@
     int __i__i_1;
 };
-static inline struct __anonymous21 ___operator_assign__F14s__anonymous21_P14s__anonymous2114s__anonymous21_autogen___1(struct __anonymous21 *___dst__P14s__anonymous21_1, struct __anonymous21 ___src__14s__anonymous21_1);
 static inline void ___constructor__F_P14s__anonymous21_autogen___1(struct __anonymous21 *___dst__P14s__anonymous21_1);
 static inline void ___constructor__F_P14s__anonymous2114s__anonymous21_autogen___1(struct __anonymous21 *___dst__P14s__anonymous21_1, struct __anonymous21 ___src__14s__anonymous21_1);
 static inline void ___destructor__F_P14s__anonymous21_autogen___1(struct __anonymous21 *___dst__P14s__anonymous21_1);
+static inline struct __anonymous21 ___operator_assign__F14s__anonymous21_P14s__anonymous2114s__anonymous21_autogen___1(struct __anonymous21 *___dst__P14s__anonymous21_1, struct __anonymous21 ___src__14s__anonymous21_1);
 static inline void ___constructor__F_P14s__anonymous21_autogen___1(struct __anonymous21 *___dst__P14s__anonymous21_1){
     ((void)((*((int *)(&(*___dst__P14s__anonymous21_1).__i__i_1)))) /* ?{} */);
@@ -568,8 +568,8 @@
     int __i__i_1;
 };
-static inline struct __anonymous22 ___operator_assign__F14s__anonymous22_P14s__anonymous2214s__anonymous22_autogen___1(struct __anonymous22 *___dst__P14s__anonymous22_1, struct __anonymous22 ___src__14s__anonymous22_1);
 static inline void ___constructor__F_P14s__anonymous22_autogen___1(struct __anonymous22 *___dst__P14s__anonymous22_1);
 static inline void ___constructor__F_P14s__anonymous2214s__anonymous22_autogen___1(struct __anonymous22 *___dst__P14s__anonymous22_1, struct __anonymous22 ___src__14s__anonymous22_1);
 static inline void ___destructor__F_P14s__anonymous22_autogen___1(struct __anonymous22 *___dst__P14s__anonymous22_1);
+static inline struct __anonymous22 ___operator_assign__F14s__anonymous22_P14s__anonymous2214s__anonymous22_autogen___1(struct __anonymous22 *___dst__P14s__anonymous22_1, struct __anonymous22 ___src__14s__anonymous22_1);
 static inline void ___constructor__F_P14s__anonymous22_autogen___1(struct __anonymous22 *___dst__P14s__anonymous22_1){
     ((void)((*((int *)(&(*___dst__P14s__anonymous22_1).__i__i_1)))) /* ?{} */);
@@ -592,8 +592,8 @@
     int __i__i_1;
 };
-static inline struct __anonymous23 ___operator_assign__F14s__anonymous23_P14s__anonymous2314s__anonymous23_autogen___1(struct __anonymous23 *___dst__P14s__anonymous23_1, struct __anonymous23 ___src__14s__anonymous23_1);
 static inline void ___constructor__F_P14s__anonymous23_autogen___1(struct __anonymous23 *___dst__P14s__anonymous23_1);
 static inline void ___constructor__F_P14s__anonymous2314s__anonymous23_autogen___1(struct __anonymous23 *___dst__P14s__anonymous23_1, struct __anonymous23 ___src__14s__anonymous23_1);
 static inline void ___destructor__F_P14s__anonymous23_autogen___1(struct __anonymous23 *___dst__P14s__anonymous23_1);
+static inline struct __anonymous23 ___operator_assign__F14s__anonymous23_P14s__anonymous2314s__anonymous23_autogen___1(struct __anonymous23 *___dst__P14s__anonymous23_1, struct __anonymous23 ___src__14s__anonymous23_1);
 static inline void ___constructor__F_P14s__anonymous23_autogen___1(struct __anonymous23 *___dst__P14s__anonymous23_1){
     ((void)((*((int *)(&(*___dst__P14s__anonymous23_1).__i__i_1)))) /* ?{} */);
@@ -640,5 +640,5 @@
     int _tmp_cp_ret0;
     ((void)(___retval_main__i_1=((_tmp_cp_ret0=invoke_main(__argc__i_1, __argv__PPc_1, __envp__PPc_1)) , _tmp_cp_ret0)) /* ?{} */);
-    ((void)(_tmp_cp_ret0) /* ^?{} */);
+    ((void)((*((int *)(&_tmp_cp_ret0)))) /* ^?{} */);
     return ((int )___retval_main__i_1);
 }
Index: src/tests/.expect/64/extension.txt
===================================================================
--- src/tests/.expect/64/extension.txt	(revision 6acb935ec45eabc0c4c2c47501d76a9c231f7219)
+++ src/tests/.expect/64/extension.txt	(revision a362f977ce917e9868e8b98a81cc260e0aee5cf9)
@@ -13,8 +13,8 @@
     __extension__ int __c__i_1;
 };
-static inline struct S ___operator_assign__F2sS_P2sS2sS_autogen___1(struct S *___dst__P2sS_1, struct S ___src__2sS_1);
 static inline void ___constructor__F_P2sS_autogen___1(struct S *___dst__P2sS_1);
 static inline void ___constructor__F_P2sS2sS_autogen___1(struct S *___dst__P2sS_1, struct S ___src__2sS_1);
 static inline void ___destructor__F_P2sS_autogen___1(struct S *___dst__P2sS_1);
+static inline struct S ___operator_assign__F2sS_P2sS2sS_autogen___1(struct S *___dst__P2sS_1, struct S ___src__2sS_1);
 static inline void ___constructor__F_P2sS_autogen___1(struct S *___dst__P2sS_1){
     ((void)((*((int *)(&(*___dst__P2sS_1).__a__i_1)))) /* ?{} */);
@@ -93,5 +93,5 @@
     int _tmp_cp_ret0;
     ((void)((_tmp_cp_ret0=__extension__ __fred__Fi_i__1(3)) , _tmp_cp_ret0));
-    ((void)(_tmp_cp_ret0) /* ^?{} */);
+    ((void)((*((int *)(&_tmp_cp_ret0)))) /* ^?{} */);
     ((void)__extension__ sizeof(3));
     ((void)__extension__ (((int )(3!=((int )0))) || ((int )(4!=((int )0)))));
Index: src/tests/.expect/64/gccExtensions.txt
===================================================================
--- src/tests/.expect/64/gccExtensions.txt	(revision 6acb935ec45eabc0c4c2c47501d76a9c231f7219)
+++ src/tests/.expect/64/gccExtensions.txt	(revision a362f977ce917e9868e8b98a81cc260e0aee5cf9)
@@ -177,5 +177,5 @@
     int _tmp_cp_ret0;
     ((void)(___retval_main__i_1=((_tmp_cp_ret0=invoke_main(__argc__i_1, __argv__PPc_1, __envp__PPc_1)) , _tmp_cp_ret0)) /* ?{} */);
-    ((void)(_tmp_cp_ret0) /* ^?{} */);
+    ((void)((*((int *)(&_tmp_cp_ret0)))) /* ^?{} */);
     return ((int )___retval_main__i_1);
 }
Index: src/tests/Makefile.am
===================================================================
--- src/tests/Makefile.am	(revision 6acb935ec45eabc0c4c2c47501d76a9c231f7219)
+++ src/tests/Makefile.am	(revision a362f977ce917e9868e8b98a81cc260e0aee5cf9)
@@ -30,5 +30,5 @@
 
 all-local :
-	@+python test.py vector_test avl_test operators numericConstants expression enum array typeof cast dtor-early-exit init_once
+	@+python test.py vector_test avl_test operators numericConstants expression enum array typeof cast dtor-early-exit init_once coroutine
 
 all-tests :
Index: src/tests/Makefile.in
===================================================================
--- src/tests/Makefile.in	(revision 6acb935ec45eabc0c4c2c47501d76a9c231f7219)
+++ src/tests/Makefile.in	(revision a362f977ce917e9868e8b98a81cc260e0aee5cf9)
@@ -651,5 +651,5 @@
 
 all-local :
-	@+python test.py vector_test avl_test operators numericConstants expression enum array typeof cast dtor-early-exit init_once
+	@+python test.py vector_test avl_test operators numericConstants expression enum array typeof cast dtor-early-exit init_once coroutine
 
 all-tests :
Index: src/tests/vector/array.c
===================================================================
--- src/tests/vector/array.c	(revision 6acb935ec45eabc0c4c2c47501d76a9c231f7219)
+++ src/tests/vector/array.c	(revision a362f977ce917e9868e8b98a81cc260e0aee5cf9)
@@ -16,11 +16,8 @@
 #include "array.h"
 
-/// forall( otype array_type, elt_type | bounded_array( array_type, elt_type ) )
-/// [ array_iterator begin, array_iterator end ]
-/// get_iterators( array_type array )
-/// {
-///   begin = 0;
-///   end = last( array );
-/// }
+forall( otype array_type, otype elt_type | bounded_array( array_type, elt_type ) )
+[ elt_type * begin, elt_type * end ] get_iterators( array_type * array ) {
+	return [ begin( array ), end( array ) ];
+}
 
 // The first element is always at index 0.
Index: src/tests/vector/array.h
===================================================================
--- src/tests/vector/array.h	(revision 6acb935ec45eabc0c4c2c47501d76a9c231f7219)
+++ src/tests/vector/array.h	(revision a362f977ce917e9868e8b98a81cc260e0aee5cf9)
@@ -32,8 +32,6 @@
 // implement iterator_for
 
-typedef int array_iterator;
-
-/// forall( otype array_type, elt_type | bounded_array( array_type, elt_type ) )
-/// [ array_iterator begin, array_iterator end ] get_iterators( array_type );
+forall( otype array_type, otype elt_type | bounded_array( array_type, elt_type ) )
+[ elt_type * begin, elt_type * end ] get_iterators( array_type * );
 
 
