changeset 20:1628b221808d

Fleshed out more unimplemented methods.
author Robert Clipsham <robert@octarineparrot.com>
date Wed, 07 Apr 2010 00:29:13 +0100
parents 01cadcfa4842
children 26b9f97f6162
files commands.linux.txt dmd/ArrayExp.d dmd/AssocArrayLiteralExp.d dmd/EnumDeclaration.d dmd/EnumMember.d dmd/IntegerExp.d dmd/ScopeDsymbol.d dmd/StaticAssert.d dmd/StaticIfCondition.d dmd/StaticIfDeclaration.d dmd/StringExp.d dmd/TemplateInstance.d dmd/TemplateMixin.d dmd/Type.d dmd/Utf.d dmd/XorAssignExp.d dmd/backend/iasm.d
diffstat 17 files changed, 519 insertions(+), 207 deletions(-) [+]
line wrap: on
line diff
--- a/commands.linux.txt	Tue Apr 06 02:21:04 2010 +0100
+++ b/commands.linux.txt	Wed Apr 07 00:29:13 2010 +0100
@@ -1,5 +1,6 @@
 -gc
 -debug
+-release
 -version=Bug3602
 -version=Bug4054
 -version=Bug4059
--- a/dmd/ArrayExp.d	Tue Apr 06 02:21:04 2010 +0100
+++ b/dmd/ArrayExp.d	Wed Apr 07 00:29:13 2010 +0100
@@ -31,7 +31,7 @@
 
 	Expression syntaxCopy()
 	{
-		assert(false);
+	    return new ArrayExp(loc, e1.syntaxCopy(), arraySyntaxCopy(arguments));
 	}
 
 	Expression semantic(Scope sc)
--- a/dmd/AssocArrayLiteralExp.d	Tue Apr 06 02:21:04 2010 +0100
+++ b/dmd/AssocArrayLiteralExp.d	Wed Apr 07 00:29:13 2010 +0100
@@ -5,6 +5,7 @@
 import dmd.InterState;
 import dmd.MATCH;
 import dmd.Type;
+import dmd.TypeAArray;
 import dmd.OutBuffer;
 import dmd.Loc;
 import dmd.Scope;
@@ -15,97 +16,190 @@
 import dmd.InlineScanState;
 import dmd.ArrayTypes;
 import dmd.TOK;
+import dmd.PREC;
+import dmd.expression.Util;
 
-class AssocArrayLiteralExp : Expression
-{
-	Expressions keys;
-
-	Expressions values;
-
-	this(Loc loc, Expressions keys, Expressions values)
-	{
+class AssocArrayLiteralExp : Expression
+{
+	Expressions keys;
+
+	Expressions values;
+
+	this(Loc loc, Expressions keys, Expressions values)
+	{
+		super(loc, TOK.TOKassocarrayliteral, this.sizeof);
+		assert(keys.dim == values.dim);
+		this.keys = keys;
+		this.values = values;	
+	}
+
+	Expression syntaxCopy()
+	{
+		return new AssocArrayLiteralExp(loc,
+				arraySyntaxCopy(keys), arraySyntaxCopy(values));
+	}
+
+	Expression semantic(Scope sc)
+	{
+		Expression e;
+		Type tkey = null;
+		Type tvalue = null;
+
+		version (LOGSEMANTIC) {
+			printf("AssocArrayLiteralExp.semantic('%s')\n", toChars());
+		}
+
+		// Run semantic() on each element
+		for (size_t i = 0; i < keys.dim; i++)
+		{	Expression key = cast(Expression)keys.data[i];
+			Expression value = cast(Expression)values.data[i];
+
+			key = key.semantic(sc);
+			value = value.semantic(sc);
+
+			keys.data[i] = cast(void *)key;
+			values.data[i] = cast(void *)value;
+		}
+		expandTuples(keys);
+		expandTuples(values);
+		if (keys.dim != values.dim)
+		{
+			error("number of keys is %u, must match number of values %u", keys.dim, values.dim);
+			keys.setDim(0);
+			values.setDim(0);
+		}
+		for (size_t i = 0; i < keys.dim; i++)
+		{	Expression key = cast(Expression)keys.data[i];
+			Expression value = cast(Expression)values.data[i];
+
+			if (!key.type)
+				error("%s has no value", key.toChars());
+			if (!value.type)
+				error("%s has no value", value.toChars());
+			key = resolveProperties(sc, key);
+			value = resolveProperties(sc, value);
+
+			if (!tkey)
+				tkey = key.type;
+			else
+				key = key.implicitCastTo(sc, tkey);
+			keys.data[i] = cast(void *)key;
+
+			if (!tvalue)
+				tvalue = value.type;
+			else
+				value = value.implicitCastTo(sc, tvalue);
+			values.data[i] = cast(void *)value;
+		}
+
+		if (!tkey)
+			tkey = Type.tvoid;
+		if (!tvalue)
+			tvalue = Type.tvoid;
+		type = new TypeAArray(tvalue, tkey);
+		type = type.semantic(loc, sc);
+		return this;
+	}
+
+	bool isBool(bool result)
+	{
+		size_t dim = keys.dim;
+		return result ? (dim != 0) : (dim == 0);
+	}
+
+	elem* toElem(IRState* irs)
+	{
 		assert(false);
-		super(loc, TOK.init, 0);
-	}
-
-	Expression syntaxCopy()
-	{
-		assert(false);
-	}
-
-	Expression semantic(Scope sc)
-	{
-		assert(false);
-	}
-
-	bool isBool(bool result)
-	{
-		assert(false);
-	}
-
-	elem* toElem(IRState* irs)
-	{
-		assert(false);
-	}
-
-	bool checkSideEffect(int flag)
-	{
-		assert(false);
-	}
-
-	void toCBuffer(OutBuffer buf, HdrGenState* hgs)
-	{
-		assert(false);
-	}
-
-	void toMangleBuffer(OutBuffer buf)
-	{
-		assert(false);
-	}
-
-	void scanForNestedRef(Scope sc)
-	{
-		assert(false);
-	}
-
-	Expression optimize(int result)
-	{
-		assert(false);
-	}
-
-	Expression interpret(InterState* istate)
-	{
-		assert(false);
-	}
-
-	MATCH implicitConvTo(Type t)
-	{
-		assert(false);
-	}
-
-	Expression castTo(Scope sc, Type t)
-	{
-		assert(false);
-	}
-
-	bool canThrow()
-	{
-		assert(false);
-	}
-
-	int inlineCost(InlineCostState* ics)
-	{
-		assert(false);
-	}
-
-	Expression doInline(InlineDoState ids)
-	{
-		assert(false);
-	}
-
-	Expression inlineScan(InlineScanState* iss)
-	{
-		assert(false);
-	}
-}
-
+	}
+
+	bool checkSideEffect(int flag)
+	{
+		bool f = false;
+
+		for (size_t i = 0; i < keys.dim; i++)
+		{	Expression key = cast(Expression)keys.data[i];
+			Expression value = cast(Expression)values.data[i];
+
+			f |= key.checkSideEffect(2);
+			f |= value.checkSideEffect(2);
+		}
+		if (flag == 0 && f == 0)
+			Expression.checkSideEffect(0);
+		return f;
+	}
+
+	void toCBuffer(OutBuffer buf, HdrGenState* hgs)
+	{
+		buf.writeByte('[');
+		for (size_t i = 0; i < keys.dim; i++)
+		{	Expression key = cast(Expression)keys.data[i];
+			Expression value = cast(Expression)values.data[i];
+
+			if (i)
+				buf.writeByte(',');
+			expToCBuffer(buf, hgs, key, PREC.PREC_assign);
+			buf.writeByte(':');
+			expToCBuffer(buf, hgs, value, PREC.PREC_assign);
+		}
+		buf.writeByte(']');
+	}
+
+	void toMangleBuffer(OutBuffer buf)
+	{
+		size_t dim = keys.dim;
+		buf.printf("A%u", dim);
+		for (size_t i = 0; i < dim; i++)
+		{	Expression key = cast(Expression)keys.data[i];
+			Expression value = cast(Expression)values.data[i];
+
+			key.toMangleBuffer(buf);
+			value.toMangleBuffer(buf);
+		}
+	}
+
+	void scanForNestedRef(Scope sc)
+	{
+		assert(false);
+	}
+
+	Expression optimize(int result)
+	{
+		assert(false);
+	}
+
+	Expression interpret(InterState* istate)
+	{
+		assert(false);
+	}
+
+	MATCH implicitConvTo(Type t)
+	{
+		assert(false);
+	}
+
+	Expression castTo(Scope sc, Type t)
+	{
+		assert(false);
+	}
+
+	bool canThrow()
+	{
+		return true;
+	}
+
+	int inlineCost(InlineCostState* ics)
+	{
+		assert(false);
+	}
+
+	Expression doInline(InlineDoState ids)
+	{
+		assert(false);
+	}
+
+	Expression inlineScan(InlineScanState* iss)
+	{
+		assert(false);
+	}
+}
+
--- a/dmd/EnumDeclaration.d	Tue Apr 06 02:21:04 2010 +0100
+++ b/dmd/EnumDeclaration.d	Wed Apr 07 00:29:13 2010 +0100
@@ -64,7 +64,19 @@
 	
     Dsymbol syntaxCopy(Dsymbol s)
 	{
-		assert(false);
+	    Type t = null;
+	    if (memtype)
+		t = memtype.syntaxCopy();
+
+	    EnumDeclaration ed;
+	    if (s)
+	    {	ed = cast(EnumDeclaration)s;
+		ed.memtype = t;
+	    }
+	    else
+		ed = new EnumDeclaration(loc, ident, t);
+	    ScopeDsymbol.syntaxCopy(ed);
+	    return ed;
 	}
 	
     void semantic(Scope sc)
@@ -285,12 +297,46 @@
 	
     bool oneMember(Dsymbol* ps)
 	{
-		assert(false);
+    		if (isAnonymous())
+			return Dsymbol.oneMembers(members, ps);
+	    	return Dsymbol.oneMember(ps);
 	}
 	
     void toCBuffer(OutBuffer buf, HdrGenState* hgs)
 	{
-		assert(false);
+	   int i;
+
+	    buf.writestring("enum ");
+	    if (ident)
+	    {	buf.writestring(ident.toChars());
+		buf.writeByte(' ');
+	    }
+	    if (memtype)
+	    {
+		buf.writestring(": ");
+		memtype.toCBuffer(buf, null, hgs);
+	    }
+	    if (!members)
+	    {
+		buf.writeByte(';');
+		buf.writenl();
+		return;
+	    }
+	    buf.writenl();
+	    buf.writeByte('{');
+	    buf.writenl();
+	    for (i = 0; i < members.dim; i++)
+	    {
+		EnumMember em = (cast(Dsymbol)members.data[i]).isEnumMember();
+		if (!em)
+		    continue;
+		//buf.writestring("    ");
+		em.toCBuffer(buf, hgs);
+		buf.writeByte(',');
+		buf.writenl();
+	    }
+	    buf.writeByte('}');
+	    buf.writenl();
 	}
 	
     Type getType()
@@ -306,7 +352,7 @@
 version (DMDV2) {
     Dsymbol search(Loc, Identifier ident, int flags)
 	{
-		//printf("%s.EnumDeclaration::search('%s')\n", toChars(), ident->toChars());
+		//printf("%s.EnumDeclaration.search('%s')\n", toChars(), ident.toChars());
 		if (scope_)
 			// Try one last time to resolve this enum
 			semantic(scope_);
@@ -340,7 +386,7 @@
 
     void toObjFile(int multiobj)			// compile to .obj file
 	{
-		//printf("EnumDeclaration::toObjFile('%s')\n", toChars());
+		//printf("EnumDeclaration.toObjFile('%s')\n", toChars());
 	version (DMDV2) {
 		if (isAnonymous())
 			return;
@@ -371,7 +417,7 @@
 		}
 		version (DMDV1) {
 			dtnbytes(&sinit.Sdt, tc.size(0), cast(char*)&tc.sym.defaultval);
-			//sinit->Sdt = tc->sym->init->toDt();
+			//sinit.Sdt = tc.sym.init.toDt();
 		}
 		version (DMDV2) {
 			tc.sym.defaultval.toDt(&sinit.Sdt);
@@ -413,4 +459,4 @@
 
 		return sinit;
 	}
-};
\ No newline at end of file
+};
--- a/dmd/EnumMember.d	Tue Apr 06 02:21:04 2010 +0100
+++ b/dmd/EnumMember.d	Wed Apr 07 00:29:13 2010 +0100
@@ -11,42 +11,67 @@
 
 class EnumMember : Dsymbol
 {
-    Expression value;
-    Type type;
+	Expression value;
+	Type type;
 
-    this(Loc loc, Identifier id, Expression value, Type type)
+	this(Loc loc, Identifier id, Expression value, Type type)
 	{
 		super(id);
-		
+
 		this.value = value;
 		this.type = type;
 		this.loc = loc;
 	}
-	
-    Dsymbol syntaxCopy(Dsymbol s)
+
+	Dsymbol syntaxCopy(Dsymbol s)
 	{
-		assert(false);
+		Expression e = null;
+		if (value)
+			e = value.syntaxCopy();
+
+		Type t = null;
+		if (type)
+			t = type.syntaxCopy();
+
+		EnumMember em;
+		if (s)
+		{	em = cast(EnumMember)s;
+			em.loc = loc;
+			em.value = e;
+			em.type = t;
+		}
+		else
+			em = new EnumMember(loc, ident, e, t);
+		return em;
 	}
-	
-    void toCBuffer(OutBuffer buf, HdrGenState* hgs)
+
+	void toCBuffer(OutBuffer buf, HdrGenState* hgs)
 	{
-		assert(false);
+		if (type)
+			type.toCBuffer(buf, ident, hgs);
+		else
+			buf.writestring(ident.toChars());
+		if (value)
+		{
+			buf.writestring(" = ");
+			value.toCBuffer(buf, hgs);
+		}
 	}
-	
-    string kind()
+
+	string kind()
+	{
+		return "enum member";
+	}
+
+	void emitComment(Scope sc)
 	{
 		assert(false);
 	}
 
-    void emitComment(Scope sc)
-	{
-		assert(false);
-	}
-	
-    void toDocBuffer(OutBuffer buf)
+	void toDocBuffer(OutBuffer buf)
 	{
 		assert(false);
 	}
 
-    EnumMember isEnumMember() { return this; }
-}
\ No newline at end of file
+	EnumMember isEnumMember() { return this; }
+}
--- a/dmd/IntegerExp.d	Tue Apr 06 02:21:04 2010 +0100
+++ b/dmd/IntegerExp.d	Wed Apr 07 00:29:13 2010 +0100
@@ -514,7 +514,10 @@
 
 	void toMangleBuffer(OutBuffer buf)
 	{
-		assert(false);
+	    if (cast(long)value < 0)
+		buf.printf("N%d", -value);
+	    else
+		buf.printf("%d", value);
 	}
 
 	Expression toLvalue(Scope sc, Expression e)
--- a/dmd/ScopeDsymbol.d	Tue Apr 06 02:21:04 2010 +0100
+++ b/dmd/ScopeDsymbol.d	Wed Apr 07 00:29:13 2010 +0100
@@ -38,7 +38,15 @@
 	
     Dsymbol syntaxCopy(Dsymbol s)
 	{
-		assert(false);
+	    //printf("ScopeDsymbol.syntaxCopy('%s')\n", toChars());
+
+	    ScopeDsymbol sd;
+	    if (s)
+		sd = cast(ScopeDsymbol)s;
+	    else
+		sd = new ScopeDsymbol(ident);
+	    sd.members = arraySyntaxCopy(members);
+	    return sd;
 	}
 	
     Dsymbol search(Loc loc, Identifier ident, int flags)
@@ -269,4 +277,4 @@
 	}
 
     ScopeDsymbol isScopeDsymbol() { return this; }
-}
\ No newline at end of file
+}
--- a/dmd/StaticAssert.d	Tue Apr 06 02:21:04 2010 +0100
+++ b/dmd/StaticAssert.d	Wed Apr 07 00:29:13 2010 +0100
@@ -14,33 +14,37 @@
 
 class StaticAssert : Dsymbol
 {
-    Expression exp;
-    Expression msg;
+	Expression exp;
+	Expression msg;
 
-    this(Loc loc, Expression exp, Expression msg)
+	this(Loc loc, Expression exp, Expression msg)
 	{
 		super(Id.empty);
-		
+
 		this.loc = loc;
 		this.exp = exp;
 		this.msg = msg;
 	}
 
-    Dsymbol syntaxCopy(Dsymbol s)
+	Dsymbol syntaxCopy(Dsymbol s)
 	{
-		assert(false);
+		StaticAssert sa;
+
+		assert(!s);
+		sa = new StaticAssert(loc, exp.syntaxCopy(), msg ? msg.syntaxCopy() : null);
+		return sa;
 	}
-	
-    bool addMember(Scope sc, ScopeDsymbol sd, int memnum)
+
+	bool addMember(Scope sc, ScopeDsymbol sd, int memnum)
 	{
 		return false;		// we didn't add anything
 	}
-	
-    void semantic(Scope sc)
+
+	void semantic(Scope sc)
 	{
 	}
-	
-    void semantic2(Scope sc)
+
+	void semantic2(Scope sc)
 	{
 		Expression e;
 
@@ -75,29 +79,38 @@
 			error("(%s) is not evaluatable at compile time", exp.toChars());
 		}
 	}
-	
-    void inlineScan()
+
+	void inlineScan()
 	{
-		assert(false);
 	}
-	
-    bool oneMember(Dsymbol* ps)
+
+	bool oneMember(Dsymbol* ps)
 	{
-		assert(false);
+		//printf("StaticAssert::oneMember())\n");
+		*ps = null;
+		return true;
 	}
-	
-    void toObjFile(int multiobj)
+
+	void toObjFile(int multiobj)
 	{
-		assert(false);
 	}
-	
-    string kind()
+
+	string kind()
 	{
 		return "static assert";
 	}
-	
-    void toCBuffer(OutBuffer buf, HdrGenState* hgs)
+
+	void toCBuffer(OutBuffer buf, HdrGenState* hgs)
 	{
-		assert(false);
+		buf.writestring(kind());
+		buf.writeByte('(');
+		exp.toCBuffer(buf, hgs);
+		if (msg)
+		{
+			buf.writeByte(',');
+			msg.toCBuffer(buf, hgs);
+		}
+		buf.writestring(");");
+		buf.writenl();
 	}
-}
\ No newline at end of file
+}
--- a/dmd/StaticIfCondition.d	Tue Apr 06 02:21:04 2010 +0100
+++ b/dmd/StaticIfCondition.d	Wed Apr 07 00:29:13 2010 +0100
@@ -22,7 +22,7 @@
 
 	Condition syntaxCopy()
 	{
-		assert(false);
+	    return new StaticIfCondition(loc, exp.syntaxCopy());
 	}
 
 	bool include(Scope sc, ScopeDsymbol s)
--- a/dmd/StaticIfDeclaration.d	Tue Apr 06 02:21:04 2010 +0100
+++ b/dmd/StaticIfDeclaration.d	Wed Apr 07 00:29:13 2010 +0100
@@ -21,7 +21,13 @@
 	
     Dsymbol syntaxCopy(Dsymbol s)
 	{
-		assert(false);
+	    StaticIfDeclaration dd;
+
+	    assert(!s);
+	    dd = new StaticIfDeclaration(condition.syntaxCopy(),
+		Dsymbol.arraySyntaxCopy(decl),
+		Dsymbol.arraySyntaxCopy(elsedecl));
+	    return dd;
 	}
 
     bool addMember(Scope sc, ScopeDsymbol sd, int memnum)
@@ -75,4 +81,4 @@
 	{
 		assert(false);
 	}
-}
\ No newline at end of file
+}
--- a/dmd/StringExp.d	Tue Apr 06 02:21:04 2010 +0100
+++ b/dmd/StringExp.d	Wed Apr 07 00:29:13 2010 +0100
@@ -17,6 +17,7 @@
 import dmd.StringExp;
 import dmd.HdrGenState;
 import dmd.Utf;
+import dmd.Util;
 import dmd.backend.dt_t;
 import dmd.backend.Symbol;
 import dmd.backend.StringTab;
@@ -572,7 +573,55 @@
 
 	void toMangleBuffer(OutBuffer buf)
 	{
-		assert(false);
+	    char m;
+	    OutBuffer tmp = new OutBuffer();
+	    string p;
+	    dchar c;
+	    size_t u;
+	    ubyte *q;
+	    uint qlen;
+
+	    /* Write string in UTF-8 format
+	     */
+	    switch (sz)
+	    {	case 1:
+		    m = 'a';
+		    q = cast(ubyte *)string_;
+		    qlen = len;
+		    break;
+		case 2:
+		    m = 'w';
+		    for (u = 0; u < len; )
+		    {
+			p = utf_decodeWchar(cast(wstring)string_[0..len], &u, &c);
+			if (p)
+			    error("%s", p);
+			else
+			    tmp.writeUTF8(c);
+		    }
+		    q = tmp.data;
+		    qlen = tmp.offset;
+		    break;
+		case 4:
+		    m = 'd';
+		    for (u = 0; u < len; u++)
+		    {
+			c = (cast(uint*)string_)[u];
+			if (!utf_isValidDchar(c))
+			    error("invalid UCS-32 char \\U%08x", c);
+			else
+			    tmp.writeUTF8(c);
+		    }
+		    q = tmp.data;
+		    qlen = tmp.offset;
+		    break;
+		default:
+		    assert(0);
+	    }
+	    buf.writeByte(m);
+	    buf.printf("%d_", qlen);
+	    for (size_t i = 0; i < qlen; i++)
+		buf.printf("%02x", q[i]);
 	}
 
 	elem* toElem(IRState* irs)
--- a/dmd/TemplateInstance.d	Tue Apr 06 02:21:04 2010 +0100
+++ b/dmd/TemplateInstance.d	Wed Apr 07 00:29:13 2010 +0100
@@ -36,6 +36,7 @@
 import dmd.FuncExp;
 import dmd.Declaration;
 import dmd.MATCH;
+import dmd.templates.Util;
 
 import dmd.backend.glue;
 
@@ -229,12 +230,31 @@
 
     static Objects arraySyntaxCopy(Objects objs)
 	{
-		assert(false);
+	    Objects a = null;
+	    if (objs)
+	    {	a = new Objects();
+		a.setDim(objs.dim);
+		for (size_t i = 0; i < objs.dim; i++)
+		{
+		    a.data[i] = cast(void*)objectSyntaxCopy(cast(Object)objs.data[i]);
+		}
+	    }
+	    return a;
 	}
 
-    Dsymbol syntaxCopy(Dsymbol)
+    Dsymbol syntaxCopy(Dsymbol s)
 	{
-		assert(false);
+	    TemplateInstance ti;
+
+	    if (s)
+		ti = cast(TemplateInstance)s;
+	    else
+		ti = new TemplateInstance(loc, name);
+
+	    ti.tiargs = arraySyntaxCopy(tiargs);
+
+	    ScopeDsymbol.syntaxCopy(ti);
+	    return ti;
 	}
 
     void semantic(Scope sc)
@@ -527,7 +547,7 @@
 			}
 			--nest;
 		}
-		catch
+		catch (Exception e)
 		{
 			global.gag = 0;			// ensure error message gets printed
 			error("recursive expansion");
@@ -596,7 +616,7 @@
 
 		semanticRun = 2;
 	version (LOG) {
-		printf("+TemplateInstance::semantic2('%s')\n", toChars());
+		printf("+TemplateInstance.semantic2('%s')\n", toChars());
 	}
 
 		if (!errors && members)
@@ -621,7 +641,7 @@
 		}
 
 	version (LOG) {
-		printf("-TemplateInstance::semantic2('%s')\n", toChars());
+		printf("-TemplateInstance.semantic2('%s')\n", toChars());
 	}
 	}
 
@@ -693,7 +713,7 @@
     Dsymbol toAlias()			// resolve real symbol
 	{
 	version (LOG) {
-		printf("TemplateInstance::toAlias()\n");
+		printf("TemplateInstance.toAlias()\n");
 	}
 		if (!inst)
 		{	
@@ -714,12 +734,13 @@
 	
     string kind()
 	{
-		assert(false);
+	    return "template instance";
 	}
 	
     bool oneMember(Dsymbol* ps)
 	{
-		assert(false);
+	    *ps = null;
+	    return true;
 	}
 	
     string toChars()
@@ -733,12 +754,36 @@
 	
     string mangle()
 	{
-		assert(false);
+	    OutBuffer buf = new OutBuffer();
+	    string id;
+
+	static if (0) {
+	    printf("TemplateInstance.mangle() %s", toChars());
+	    if (parent)
+		printf("  parent = %s %s", parent.kind(), parent.toChars());
+	    printf("\n");
+	}
+	    id = ident ? ident.toChars() : toChars();
+	    if (!tempdecl)
+		error("is not defined");
+	    else if (tempdecl.parent)
+	    {
+		string p = tempdecl.parent.mangle();
+		if (p[0] == '_' && p[1] == 'D')
+		    p = p[2..$];
+		buf.writestring(p);
+	    }
+	    buf.printf("%d%s", id.length, id);
+	    id = buf.toChars();
+	    buf.data = null;
+	    //printf("TemplateInstance.mangle() %s = %s\n", toChars(), id);
+	    return id;
 	}
 	
     void printInstantiationTrace()
 	{
-		assert(false);
+	    if (global.gag)
+		return;
 	}
 
     void toObjFile(int multiobj)			// compile to .obj file
@@ -1159,7 +1204,7 @@
 	 */
     void declareParameters(Scope sc)
 	{
-		//printf("TemplateInstance::declareParameters()\n");
+		//printf("TemplateInstance.declareParameters()\n");
 		for (int i = 0; i < tdtypes.dim; i++)
 		{
 			TemplateParameter tp = cast(TemplateParameter)tempdecl.parameters.data[i];
@@ -1178,7 +1223,7 @@
     bool hasNestedArgs(Objects args)
 	{
 		bool nested = false;
-		//printf("TemplateInstance::hasNestedArgs('%s')\n", tempdecl.ident.toChars());
+		//printf("TemplateInstance.hasNestedArgs('%s')\n", tempdecl.ident.toChars());
 
 		/* A nested instance happens when an argument references a local
 		 * symbol that is on the stack.
@@ -1274,7 +1319,7 @@
 		string id;
 		Objects args;
 
-		//printf("TemplateInstance::genIdent('%s')\n", tempdecl.ident.toChars());
+		//printf("TemplateInstance.genIdent('%s')\n", tempdecl.ident.toChars());
 		id = tempdecl.ident.toChars();
 		buf.printf("__T%d%s", id.length, id);	///!
 		args = tiargs;
@@ -1383,4 +1428,4 @@
 	{
 		assert(false);
 	}
-}
\ No newline at end of file
+}
--- a/dmd/TemplateMixin.d	Tue Apr 06 02:21:04 2010 +0100
+++ b/dmd/TemplateMixin.d	Wed Apr 07 00:29:13 2010 +0100
@@ -431,7 +431,7 @@
 
 	string toChars()
 	{
-		OutBuffer buf;
+		OutBuffer buf = new OutBuffer();
 		HdrGenState hgs;
 		string s;
 
--- a/dmd/Type.d	Tue Apr 06 02:21:04 2010 +0100
+++ b/dmd/Type.d	Wed Apr 07 00:29:13 2010 +0100
@@ -713,7 +713,7 @@
 	 *	flag	0x100	do not do const/invariant
 	 */
     void toDecoBuffer(OutBuffer buf, int flag = 0)
-	{ if( buf is null )asm { int 3; }
+	{
 		if (flag != mod && flag != 0x100)
 		{
 			if (mod & MOD.MODshared)
--- a/dmd/Utf.d	Tue Apr 06 02:21:04 2010 +0100
+++ b/dmd/Utf.d	Wed Apr 07 00:29:13 2010 +0100
@@ -17,7 +17,13 @@
 
 string utf_decodeWchar(const(wchar)[] s, size_t* pidx, dchar* presult)
 {
-	assert(false);
+	try {
+		*presult = decode(s, *pidx);
+	} catch (Exception e) {
+		return e.toString();
+	}
+
+	return null;
 }
 
 bool utf_isValidDchar(uint c)
@@ -25,4 +31,4 @@
 	return isValidDchar(c);
 }
 
-extern (C++) extern int HtmlNamedEntity(ubyte* p, int length);
\ No newline at end of file
+extern (C++) extern int HtmlNamedEntity(ubyte* p, int length);
--- a/dmd/XorAssignExp.d	Tue Apr 06 02:21:04 2010 +0100
+++ b/dmd/XorAssignExp.d	Wed Apr 07 00:29:13 2010 +0100
@@ -17,13 +17,12 @@
 {
     this(Loc loc, Expression e1, Expression e2)
 	{
-		assert(false);
-		super(loc, TOK.init, 0, e1, e2);
+		super(loc, TOK.TOKxorass, this.sizeof, e1, e2);
 	}
 	
     Expression semantic(Scope sc)
 	{
-		assert(false);
+    		return commonSemanticAssignIntegral(sc);
 	}
 	
     Expression interpret(InterState* istate)
@@ -50,4 +49,4 @@
 	{
 		assert(false);
 	}
-}
\ No newline at end of file
+}
--- a/dmd/backend/iasm.d	Tue Apr 06 02:21:04 2010 +0100
+++ b/dmd/backend/iasm.d	Wed Apr 07 00:29:13 2010 +0100
@@ -1035,10 +1035,12 @@
 			}
 			else
 			{	
-				asm_make_modrm_byte(
-///debug {
+				debug asm_make_modrm_byte(
 				auchOpcode, &usIdx,
-///}
+				pc, 
+				ptb.pptb1.usFlags,
+				popnd1, null);
+				else asm_make_modrm_byte(
 				pc, 
 				ptb.pptb1.usFlags,
 				popnd1, null);
@@ -1128,23 +1130,21 @@
 					ptb.pptb0.usOpcode == 0x660F7E	// MOVD _rm32,_xmm
 				   )
 				{
-					asm_make_modrm_byte(
-///debug {
-					auchOpcode, &usIdx,
-///}
-					pc, 
-					ptb.pptb1.usFlags,
-					popnd1, popnd2);
+					debug asm_make_modrm_byte(
+						auchOpcode, &usIdx,
+						pc, 
+						ptb.pptb1.usFlags,
+						popnd1, popnd2);
+					else asm_make_modrm_byte(pc, ptb.pptb1.usFlags, popnd1, popnd2);
 				}
 				else
 				{
-					asm_make_modrm_byte(
-///debug {
-					auchOpcode, &usIdx,
-///}
-					pc, 
-					ptb.pptb1.usFlags,
-					popnd2, popnd1);
+					debug asm_make_modrm_byte(
+						auchOpcode, &usIdx,
+						pc, 
+						ptb.pptb1.usFlags,
+						popnd2, popnd1);
+					else asm_make_modrm_byte(pc, ptb.pptb1.usFlags, popnd2, popnd1);
 				}
 				popndTmp = popnd1;
 				aoptyTmp = aoptyTable1;
@@ -1188,23 +1188,31 @@
 					 ptb.pptb0.usOpcode == 0x660FD7 ||
 					 ptb.pptb0.usOpcode == 0x0FD7)
 				{
-					asm_make_modrm_byte(
+					debug asm_make_modrm_byte(
 ///debug {
 						auchOpcode, &usIdx,
 ///}
 						pc, 
 						ptb.pptb1.usFlags,
 						popnd2, popnd1);
+					else asm_make_modrm_byte(
+						pc, 
+						ptb.pptb1.usFlags,
+						popnd2, popnd1); 
 				}
 				else
 				{
-					asm_make_modrm_byte(
+					debug asm_make_modrm_byte(
 ///debug {
 						auchOpcode, &usIdx,
 ///}
 						pc, 
 						ptb.pptb1.usFlags,
 						popnd1, popnd2);
+					else asm_make_modrm_byte(
+						pc, 
+						ptb.pptb1.usFlags,
+						popnd1, popnd2); 
 
 				}
 				if (aoptyTable1 == ASM_OPERAND_TYPE._imm)
@@ -1226,13 +1234,17 @@
 			if (aoptyTable2 == ASM_OPERAND_TYPE._m || aoptyTable2 == ASM_OPERAND_TYPE._rm ||
 				usOpcode == 0x0FC5) // PEXTRW
 			{
-				asm_make_modrm_byte(
+				debug asm_make_modrm_byte(
 ///debug {
 					auchOpcode, &usIdx,
 ///}
 					pc, 
 					ptb.pptb1.usFlags,
 					popnd2, popnd1);
+				else asm_make_modrm_byte(
+					pc, 
+					ptb.pptb1.usFlags,
+					popnd2, popnd1); 
 				popndTmp = popnd3;
 				aoptyTmp = aoptyTable3;
 				uSizemaskTmp = cast(ushort)uSizemaskTable3;
@@ -1266,14 +1278,19 @@
 }
 				}
 				else
-					asm_make_modrm_byte(
+				{
+					debug asm_make_modrm_byte(
 ///debug {
 						auchOpcode, &usIdx,
 ///}
 						pc, 
 						ptb.pptb1.usFlags,
 						popnd1, popnd2);
-
+					else asm_make_modrm_byte(
+						pc, 
+						ptb.pptb1.usFlags,
+						popnd1, popnd2); 
+				}
 				popndTmp = popnd3;
 				aoptyTmp = aoptyTable3;
 				uSizemaskTmp = cast(ushort)uSizemaskTable3;
@@ -2230,16 +2247,16 @@
 	return X(r1, 9);
 }
 
-void asm_make_modrm_byte(
-///debug {
-	ubyte[] puchOpcode, uint* pusIdx,
-///}
-	code *pc,
-	ushort usFlags,
-	OPND *popnd, OPND *popnd2)
+// Save a copy/pasted function
+template Tuple(T...) { alias T Tuple; }
+debug alias Tuple!(ubyte[], uint*) asm_make_modrm_args;
+else alias Tuple!() asm_make_modrm_args;
+
+void asm_make_modrm_byte(asm_make_modrm_args ocidx, code *pc, ushort usFlags, OPND *popnd, OPND *popnd2)
 {
 ///    #undef modregrm
-
+debug alias ocidx[0] puchOpcode;
+debug alias ocidx[1] pusIdx;
     union MODRM_BYTE			// mrmb
 	{
 		struct MODRM