Index: src/Concurrency/Keywords.cpp
===================================================================
--- src/Concurrency/Keywords.cpp	(revision 1fb0a883af54d021e91c232a243e29af394350ff)
+++ src/Concurrency/Keywords.cpp	(revision 35eef3b603d8e04d019650f3104cb617f330e97a)
@@ -10,6 +10,6 @@
 // Created On       : Tue Nov 16  9:53:00 2021
 // Last Modified By : Peter A. Buhr
-// Last Modified On : Thu Dec 14 18:02:25 2023
-// Update Count     : 6
+// Last Modified On : Sun Jan 26 15:16:16 2025
+// Update Count     : 15
 //
 
@@ -69,6 +69,6 @@
 }
 
-// Describe that it adds the generic parameters and the uses of the generic
-// parameters on the function and first "this" argument.
+// Describe that it adds the generic parameters and the uses of the generic parameters on the
+// function and first "this" argument.
 ast::FunctionDecl * fixupGenerics(
 		const ast::FunctionDecl * func, const ast::StructDecl * decl ) {
@@ -117,4 +117,12 @@
 
 // --------------------------------------------------------------------------
+
+// This type describes the general information used to transform a generator, coroutine, monitor, or
+// thread aggregate kind.  A pass is made over the AST in ConcurrentSueKeyword::postvisit looking
+// for each of these kinds. When found, this data structure is filled in with the information from
+// the specific structures below, and handleStruct is called to perform the common changes that
+// augment the aggregate kind with fields and generate appropriate companion routines.  The location
+// of any extra fields is specified in addField.
+
 struct ConcurrentSueKeyword : public ast::WithDeclsToAdd {
 	ConcurrentSueKeyword(
@@ -171,25 +179,24 @@
 };
 
-// Handles thread type declarations:
+// Handles generator type declarations:
 //
-// thread Mythread {                         struct MyThread {
-//  int data;                                  int data;
-//  a_struct_t more_data;                      a_struct_t more_data;
-//                                =>             thread$ __thrd_d;
+// generator MyGenerator {                   struct MyGenerator {
+//                                =>             int __generator_state;
+//    int data;                                  int data;
+//    a_struct_t more_data;                      a_struct_t more_data;
 // };                                        };
-//                                           static inline thread$ * get_thread( MyThread * this ) { return &this->__thrd_d; }
 //
-struct ThreadKeyword final : public ConcurrentSueKeyword {
-	ThreadKeyword() : ConcurrentSueKeyword(
-		"thread$",
-		"__thrd",
-		"get_thread",
-		"thread keyword requires threads to be in scope, add #include <thread.hfa>\n",
-		"ThreadCancelled",
+struct GeneratorKeyword final : public ConcurrentSueKeyword {
+	GeneratorKeyword() : ConcurrentSueKeyword(
+		"generator$",
+		"__generator_state",
+		"get_generator",
+		"Unable to find builtin type generator$\n",
+		"",
 		true,
-		ast::AggregateDecl::Thread )
+		ast::AggregateDecl::Generator )
 	{}
 
-	virtual ~ThreadKeyword() {}
+	virtual ~GeneratorKeyword() {}
 };
 
@@ -197,7 +204,7 @@
 //
 // coroutine MyCoroutine {                   struct MyCoroutine {
-//  int data;                                  int data;
-//  a_struct_t more_data;                      a_struct_t more_data;
 //                                =>             coroutine$ __cor_d;
+//    int data;                                  int data;
+//    a_struct_t more_data;                      a_struct_t more_data;
 // };                                        };
 //                                           static inline coroutine$ * get_coroutine( MyCoroutine * this ) { return &this->__cor_d; }
@@ -220,7 +227,7 @@
 //
 // monitor MyMonitor {                       struct MyMonitor {
-//  int data;                                  int data;
-//  a_struct_t more_data;                      a_struct_t more_data;
 //                                =>             monitor$ __mon_d;
+//    int data;                                  int data;
+//    a_struct_t more_data;                      a_struct_t more_data;
 // };                                        };
 //                                           static inline monitor$ * get_coroutine( MyMonitor * this ) {
@@ -248,24 +255,25 @@
 };
 
-// Handles generator type declarations:
+// Handles thread type declarations:
 //
-// generator MyGenerator {                   struct MyGenerator {
-//  int data;                                  int data;
-//  a_struct_t more_data;                      a_struct_t more_data;
-//                                =>             int __generator_state;
+// thread Mythread {                         struct MyThread {
+//                                =>             thread$ __thrd_d;
+//    int data;                                  int data;
+//    a_struct_t more_data;                      a_struct_t more_data;
 // };                                        };
+//                                           static inline thread$ * get_thread( MyThread * this ) { return &this->__thrd_d; }
 //
-struct GeneratorKeyword final : public ConcurrentSueKeyword {
-	GeneratorKeyword() : ConcurrentSueKeyword(
-		"generator$",
-		"__generator_state",
-		"get_generator",
-		"Unable to find builtin type generator$\n",
-		"",
+struct ThreadKeyword final : public ConcurrentSueKeyword {
+	ThreadKeyword() : ConcurrentSueKeyword(
+		"thread$",
+		"__thrd",
+		"get_thread",
+		"thread keyword requires threads to be in scope, add #include <thread.hfa>\n",
+		"ThreadCancelled",
 		true,
-		ast::AggregateDecl::Generator )
+		ast::AggregateDecl::Thread )
 	{}
 
-	virtual ~GeneratorKeyword() {}
+	virtual ~ThreadKeyword() {}
 };
 
@@ -354,5 +362,5 @@
 
 	if ( !exception_name.empty() ) {
-		if( !typeid_decl || !vtable_decl ) {
+		if ( !typeid_decl || !vtable_decl ) {
 			SemanticError( decl, context_error );
 		}
@@ -419,6 +427,6 @@
 	declsToAddBefore.push_back(
 		Virtual::makeTypeIdInstance( location, typeid_type ) );
-	// If the typeid_type is going to be kept, the other reference will have
-	// been made by now, but we also get to avoid extra mutates.
+	// If the typeid_type is going to be kept, the other reference will have been made by now, but
+	// we also get to avoid extra mutates.
 	ast::ptr<ast::StructInstType> typeid_cleanup = typeid_type;
 }
@@ -525,4 +533,6 @@
 
 	auto mutDecl = ast::mutate( decl );
+	// Insert at start of special aggregate structures => front of vector
+	//mutDecl->members.insert( mutDecl->members.begin(), field );
 	mutDecl->members.push_back( field );
 
@@ -917,5 +927,5 @@
 
 			// If it is a monitor, then it is a monitor.
-			if( baseStruct->base->is_monitor() || baseStruct->base->is_thread() ) {
+			if ( baseStruct->base->is_monitor() || baseStruct->base->is_thread() ) {
 				SemanticError( decl, "destructors for structures declared as \"monitor\" must use mutex parameters " );
 			}
@@ -1031,5 +1041,5 @@
 
 	// Make sure that only the outer reference is mutex.
-	if( baseStruct->is_mutex() ) {
+	if ( baseStruct->is_mutex() ) {
 		SemanticError( decl, "mutex keyword may only appear once per argument " );
 	}
@@ -1179,6 +1189,6 @@
 }
 
-// generates a cast to the void ptr to the appropriate lock type and dereferences it before calling lock or unlock on it
-// used to undo the type erasure done by storing all the lock pointers as void
+// Generates a cast to the void ptr to the appropriate lock type and dereferences it before calling
+// lock or unlock on it used to undo the type erasure done by storing all the lock pointers as void.
 ast::ExprStmt * MutexKeyword::genVirtLockUnlockExpr( const std::string & fnName, ast::ptr<ast::Expr> expr, const CodeLocation & location, ast::Expr * param ) {
 	return new ast::ExprStmt( location,
