Index: libcfa/src/containers/list2.hfa
===================================================================
--- libcfa/src/containers/list2.hfa	(revision 8d1ad36cef9bb7b219f38dfae154e557ae4f238e)
+++ libcfa/src/containers/list2.hfa	(revision 67b421c05a280cde8747b61757656154a9f530c9)
@@ -18,19 +18,32 @@
 #include <assert.h>
 
-extern "C" {
-    void * memset ( void * ptr, int value, size_t num );
-}
-
-trait embedded( tOuter &, tInner & ) {
-    tInner & ?`inner( tOuter & );
+forall( Decorator &, T & )
+struct tytagref {
+    inline T &;
 };
 
-// embedded is reflexive
-forall( tX & )
-static inline tX & ?`inner( tX & this ) { return this; }
+trait embedded( tOuter &, tMid &, tInner & ) {
+    tytagref( tMid, tInner ) ?`inner( tOuter & );
+};
+
+// embedded is reflexive, with no info (void) as the type tag
+forall (T &)
+tytagref(void, T) ?`inner ( T & this ) { tytagref( void, T ) ret = {this}; return ret; }
 
 // use this on every case of plan-9 inheritance, to make embedded a closure of plan-9 inheritance
-#define P9_EMBEDDED( tOuter, tInner ) \
-   static inline tInner & ?`inner( tOuter & this ) { return this; }
+#define P9_EMBEDDED( derived, immedBase ) \
+forall( Tbase &, TdiscardPath & | { tytagref( TdiscardPath, Tbase ) ?`inner( immedBase & ); } ) \
+    static inline tytagref(immedBase, Tbase) ?`inner( derived & this ) { \
+        immedBase & ib = this; \
+        Tbase & b = ib`inner; \
+        tytagref(immedBase, Tbase) result = { b }; \
+        return result; \
+    }
+
+#define EMBEDDED_VIA( OUTER, MID, INNER ) \
+   (struct { tytagref(MID, INNER) ( * ?`inner ) ( OUTER & ); }){ ?`inner } 
+
+#define DLINK_VIA( TE, TLINK ) \
+   EMBEDDED_VIA( TE, TLINK, dlink(TE) )
 
 
@@ -81,18 +94,12 @@
     }
 
-    forall( tLinks & = tE ) {
-
-        struct dlist {
-            inline dlink(tE);
-        };
-
-        struct diref {
-            inline tE &;
-        };
-    }
-
-    forall( tLinks & = tE | embedded( tE, tLinks ) | embedded( tLinks, dlink(tE) ) ) {
+    forall( tLinks & = dlink(tE) )
+    struct dlist {
+        inline dlink(tE);
+    };
+
+    forall( tLinks & | embedded( tE, tLinks, dlink(tE) ) ) {
         static inline tE * $get_list_origin_addr( dlist(tE, tLinks) & lst ) {
-            dlink(tE) & link_from_null = ( * (tE *) 0p )`inner`inner;
+            dlink(tE) & link_from_null = ( * (tE *) 0p )`inner;
             ptrdiff_t link_offset = (ptrdiff_t) & link_from_null;
             size_t origin_addr = ((size_t) & lst) - link_offset;
@@ -105,10 +112,4 @@
             ( ( dlink(tE) & ) this ){ listOrigin, listOrigin } ;
         }
-
-        // redundant
-        // void ?{}( diref(tE, tLinks) & this, tE & target ) {
-        //     tE && ref = this;
-        //     &ref = &target;
-        // }
     }
 
@@ -116,53 +117,57 @@
 
 
-forall( tE &, tLinks & | embedded( tE, tLinks ) | embedded( tLinks, dlink(tE) ) ) {
-
-	static inline void insert_after(diref(tE, tLinks) list_pos, tE &to_insert) {
+forall( tE &, tLinks & | embedded( tE, tLinks, dlink(tE) ) ) {
+
+	static inline void insert_after(tE & list_pos, tE &to_insert) {
 		verify (&list_pos != 0p);
 		verify (&to_insert != 0p);
-        dlink(tE) & linkToInsert = to_insert`inner`inner;
+        dlink(tE) & linkToInsert = to_insert`inner;
 		verify(linkToInsert.prev == 0p);
 		verify(linkToInsert.next == 0p);
         tE & list_pos_raw = list_pos;
         tE & list_pos_elem = * (tE *) ORIGIN_TAG_CLEAR( (size_t) & list_pos_raw );
-        asm( "" : : : "memory" );
-        tE & after_raw = * (list_pos_elem`inner`inner).next;
+        dlink(tE) & list_pos_links = list_pos_elem`inner;
+        asm( "" : : : "memory" );
+        tE & after_raw = * list_pos_links.next;
         tE & after_elem = * (tE *) ORIGIN_TAG_CLEAR( (size_t) & after_raw );
 		linkToInsert.prev = & list_pos_raw;
 		linkToInsert.next = & after_raw;
-        (after_elem`inner`inner).prev = &to_insert;
-		(list_pos_elem`inner`inner).next = &to_insert;
-        asm( "" : : : "memory" );
-	}
-
-	static inline void insert_before(diref(tE, tLinks) list_pos, tE &to_insert) {
+        dlink(tE) & afterLinks = after_elem`inner;
+        afterLinks.prev = &to_insert;
+		list_pos_links.next = &to_insert;
+        asm( "" : : : "memory" );
+	}
+
+	static inline void insert_before(tE & list_pos, tE &to_insert) {
 		verify (&list_pos != 0p);
 		verify (&to_insert != 0p);
-        dlink(tE) & linkToInsert = to_insert`inner`inner;
+        dlink(tE) & linkToInsert = to_insert`inner;
 		verify(linkToInsert.next == 0p);
 		verify(linkToInsert.prev == 0p);
         tE & list_pos_raw = list_pos;
         tE & list_pos_elem = * (tE *) ORIGIN_TAG_CLEAR( (size_t) & list_pos_raw );
-        asm( "" : : : "memory" );
-        tE & before_raw = * (list_pos_elem`inner`inner).prev;
+        dlink(tE) & list_pos_links = list_pos_elem`inner;
+        asm( "" : : : "memory" );
+        tE & before_raw = * (list_pos_links).prev;
         tE & before_elem = * (tE *) ORIGIN_TAG_CLEAR( (size_t) & before_raw );
 		linkToInsert.next = & list_pos_raw;
 		linkToInsert.prev = & before_raw;
-        (before_elem`inner`inner).next = &to_insert;
-		(list_pos_elem`inner`inner).prev = &to_insert;
-        asm( "" : : : "memory" );
-	}
-
-	static inline tE & remove(diref(tE, tLinks) list_pos) {
+        dlink(tE) & beforeLinks = before_elem`inner;
+        beforeLinks.next = &to_insert;
+		(list_pos_links).prev = &to_insert;
+        asm( "" : : : "memory" );
+	}
+
+	static inline tE & remove(tE & list_pos) {
 		verify (&list_pos != 0p);
         tE & list_pos_elem = list_pos;
         verify( ! ORIGIN_TAG_QUERY((size_t) & list_pos_elem) );
-        dlink(tE) & list_pos_links = list_pos_elem`inner`inner;
+        dlink(tE) & list_pos_links = list_pos_elem`inner;
         tE & before_raw = * list_pos_links.prev;
         tE & before_elem = * (tE *) ORIGIN_TAG_CLEAR( (size_t) & before_raw );
-        dlink(tE) & before_links = before_elem`inner`inner;
+        dlink(tE) & before_links = before_elem`inner;
         tE & after_raw = * list_pos_links.next;
         tE & after_elem = * (tE *) ORIGIN_TAG_CLEAR( (size_t) & after_raw );
-        dlink(tE) & after_links = after_elem`inner`inner;
+        dlink(tE) & after_links = after_elem`inner;
         before_links.next = &after_raw;
         after_links.prev = &before_raw;
@@ -174,15 +179,13 @@
 	}
 
-    static inline diref(tE, tLinks) ?`first( dlist(tE, tLinks) &lst ) {
+    static inline tE & ?`first( dlist(tE, tLinks) &lst ) {
         tE * firstPtr = lst.next;
         if (ORIGIN_TAG_QUERY((size_t)firstPtr)) firstPtr = 0p;
-        diref(tE, tLinks) ret = { *firstPtr };
-        return ret;
-    }
-    static inline diref(tE, tLinks) ?`last ( dlist(tE, tLinks) &lst ) {
+        return *firstPtr;
+    }
+    static inline tE & ?`last ( dlist(tE, tLinks) &lst ) {
         tE * lastPtr = lst.prev;
         if (ORIGIN_TAG_QUERY((size_t)lastPtr)) lastPtr = 0p;
-        diref(tE, tLinks) ret = { *lastPtr };
-        return ret;
+        return *lastPtr;
     }
 
@@ -193,62 +196,41 @@
     }
 
-    static inline int ?!=?( const diref(tE, tLinks) & list_pos, zero_t ) {
-        tE & list_pos_elem = list_pos;
-        if (ORIGIN_TAG_QUERY((size_t) & list_pos_elem)) return 0;
-        return & list_pos_elem != 0p;
-    }
-
-    static inline int DUMB_COMPARE( diref(tE, tLinks) list_pos, tE * elem ) {
-        tE & signifiedLhs = list_pos;
-        return &signifiedLhs == elem;
-    }
-
-    static inline diref(tE, tLinks) ?`from( tE & elem ) {
-        diref(tE, tLinks) ret = { elem };
-        return ret;
-    }
-
-    static inline diref(tE, tLinks) ?`elems( dlist(tE, tLinks) & lst ) {
+    static inline tE & ?`elems( dlist(tE, tLinks) & lst ) {
         tE * origin = $get_list_origin_addr( lst );
-        diref(tE, tLinks) ret = { *origin };
-        return ret;
-    }
-
-    static inline bool ?`moveNext( diref(tE, tLinks) & refx ) {
+        return *origin;
+    }
+
+    static inline bool ?`moveNext( tE && refx ) {
         tE && ref_inner = refx;
         tE & oldReferent = * (tE*) ORIGIN_TAG_CLEAR( (size_t) & ref_inner );
-        &ref_inner = oldReferent`inner`inner.next;
+        &ref_inner = oldReferent`inner.next;
         return &ref_inner != 0p  &&
             ! ORIGIN_TAG_QUERY( (size_t) & ref_inner );
     }
 
-    static inline bool ?`movePrev( diref(tE, tLinks) & refx ) {
+    static inline bool ?`movePrev( tE && refx ) {
         tE && ref_inner = refx;
         tE & oldReferent = * (tE*) ORIGIN_TAG_CLEAR( (size_t) & ref_inner );
-        &ref_inner = oldReferent`inner`inner.prev;
+        &ref_inner = oldReferent`inner.prev;
         return &ref_inner != 0p  &&
             ! ORIGIN_TAG_QUERY( (size_t) & ref_inner );
     }
 
-    static inline bool ?`hasNext( diref(tE, tLinks) refx ) {
-        return refx`moveNext;
-    }
-
-    static inline bool ?`hasPrev( diref(tE, tLinks) refx ) {
-        return refx`movePrev;
-    }
-
-    static inline diref(tE, tLinks) ?`next( diref(tE, tLinks) refx ) {
-        if( refx`moveNext ) return refx;
-        tE && ref_inner = refx;
-        & ref_inner = 0p;
-        return refx;
-    }
-
-    static inline diref(tE, tLinks) ?`prev( diref(tE, tLinks) refx ) {
-        if( refx`movePrev ) return refx;
-        tE && ref_inner = refx;
-        & ref_inner = 0p;
-        return refx;
+    static inline bool ?`hasNext( tE & e ) {
+        return e`moveNext;
+    }
+
+    static inline bool ?`hasPrev( tE & e ) {
+        return e`movePrev;
+    }
+
+    static inline tE & ?`next( tE & e ) {
+        if( e`moveNext ) return e;
+        return * 0p;
+    }
+
+    static inline tE & ?`prev( tE & e ) {
+        if( e`movePrev ) return e;
+        return * 0p;
     }
 
@@ -262,5 +244,5 @@
 
     static inline tE & try_pop_front( dlist(tE, tLinks) &lst ) {
-        diref(tE, tLinks) first_inlist = lst`first;
+        tE & first_inlist = lst`first;
         tE & first_item = first_inlist;
         if (&first_item) remove(first_inlist);
@@ -269,5 +251,5 @@
 
     static inline tE & try_pop_back( dlist(tE, tLinks) &lst ) {
-        diref(tE, tLinks) last_inlist = lst`last;
+        tE & last_inlist = lst`last;
         tE & last_item = last_inlist;
         if (&last_item) remove(last_inlist);
@@ -282,5 +264,5 @@
         tE & lagElem = *0p;
 
-        while ( diref(tE, tLinks) it = this`elems; it`moveNext ) {
+        while ( tE & it = this`elems; it`moveNext ) {
             if (& lagElem == 0p &&  &it != & this`first ) return false;
             & lagElem = & it;
@@ -297,5 +279,5 @@
         tE & lagElem = *0p;
 
-        while ( diref(tE, tLinks) it = this`elems; it`movePrev ) {
+        while ( tE & it = this`elems; it`movePrev ) {
             if (& lagElem == 0p &&  &it != & this`last ) return false;
             & lagElem = & it;
@@ -314,42 +296,2 @@
 }
 
-forall( tE & | embedded( tE, dlink(tE) ) ) {
-	static inline void insert_after(tE & list_pos, tE &to_insert ) {
-        diref(tE, tE) list_pos_ref = list_pos`from;
-        insert_after( list_pos_ref, to_insert );
-    }
-	static inline void insert_before(tE & list_pos, tE &to_insert ) {
-        diref(tE, tE) list_pos_ref = list_pos`from;
-        insert_before( list_pos_ref, to_insert );
-    }
-	static inline tE & remove(tE & list_pos ) {
-        diref(tE, tE) list_pos_ref = list_pos`from;
-        return remove( list_pos_ref );
-    }
-    static inline bool ?`moveNext( tE && ref ) {
-        diref(tE, tE) & ref_dird = (diref(tE, tE) &) & ref;
-        return ref_dird`moveNext;
-    }
-    static inline bool ?`movePrev( tE && ref ) {
-        diref(tE, tE) & ref_dird = (diref(tE, tE) &) & ref;
-        return ref_dird`movePrev;
-    }
-    static inline bool ?`hasNext( tE & ref ) {
-        diref(tE, tE) ref_dird = { ref };
-        return ref_dird`hasNext;
-    }
-    static inline bool ?`hasPrev( tE & ref ) {
-        diref(tE, tE) ref_dird = { ref };
-        return ref_dird`hasPrev;
-    }
-    static inline tE & ?`next( tE & ref ) {
-        diref(tE, tE) ref_dird = { ref };
-        diref(tE, tE) rslt = ref_dird`next;
-        return rslt;
-    }
-    static inline tE & ?`prev( tE & ref ) {
-        diref(tE, tE) ref_dird = { ref };
-        diref(tE, tE) rslt = ref_dird`prev;
-        return rslt;
-    }
-}
