changeset 174:af724d3510d7

lot os toCBuffer methods implemented moved shared Type.* stuff into Global
author korDen
date Sun, 10 Oct 2010 03:47:23 +0400
parents d237b38b5858
children 94b6033c07f3
files dmd/AliasDeclaration.d dmd/ArrayLengthExp.d dmd/AsmStatement.d dmd/AssertExp.d dmd/BinExp.d dmd/BreakStatement.d dmd/CaseStatement.d dmd/Catch.d dmd/ClassDeclaration.d dmd/ComplexExp.d dmd/CompoundDeclarationStatement.d dmd/CompoundStatement.d dmd/DeleteExp.d dmd/DoStatement.d dmd/ExpInitializer.d dmd/File.d dmd/FileName.d dmd/FuncDeclaration.d dmd/Global.d dmd/Identifier.d dmd/IfStatement.d dmd/Import.d dmd/Lexer.d dmd/Module.d dmd/ModuleDeclaration.d dmd/NewExp.d dmd/OnScopeStatement.d dmd/PostExp.d dmd/PtrExp.d dmd/Statement.d dmd/StringEntry.d dmd/StringTable.d dmd/SwitchStatement.d dmd/SymOffExp.d dmd/ThrowStatement.d dmd/Token.d dmd/TryCatchStatement.d dmd/TryFinallyStatement.d dmd/Type.d dmd/TypeAArray.d dmd/TypeArray.d dmd/TypeDelegate.d dmd/TypeInfoArrayDeclaration.d dmd/TypeInfoAssociativeArrayDeclaration.d dmd/TypeInfoClassDeclaration.d dmd/TypeInfoConstDeclaration.d dmd/TypeInfoDeclaration.d dmd/TypeInfoDelegateDeclaration.d dmd/TypeInfoEnumDeclaration.d dmd/TypeInfoFunctionDeclaration.d dmd/TypeInfoInterfaceDeclaration.d dmd/TypeInfoInvariantDeclaration.d dmd/TypeInfoPointerDeclaration.d dmd/TypeInfoSharedDeclaration.d dmd/TypeInfoStaticArrayDeclaration.d dmd/TypeInfoStructDeclaration.d dmd/TypeInfoTupleDeclaration.d dmd/TypeInfoTypedefDeclaration.d dmd/TypeInfoWildDeclaration.d dmd/TypeStruct.d dmd/Util.d dmd/VersionCondition.d dmd/VoidInitializer.d dmd/VolatileStatement.d dmd/backend/Cstate.d dmd/backend/Util.d dmd/backend/glue.d dmd/backend/iasm.d dmd/backend/symtab_t.d dmd/codegen/Util.d dmd/expression/Util.d
diffstat 71 files changed, 1196 insertions(+), 775 deletions(-) [+]
line wrap: on
line diff
--- a/dmd/AliasDeclaration.d	Sun Oct 10 01:55:35 2010 +0400
+++ b/dmd/AliasDeclaration.d	Sun Oct 10 03:47:23 2010 +0400
@@ -252,7 +252,33 @@
 
 	override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
 	{
-		assert(false);
+		buf.writestring("alias ");
+///	static if (false) { // && _DH
+///		if (hgs.hdrgen)
+///		{
+///			if (haliassym)
+///			{
+///				haliassym.toCBuffer(buf, hgs);
+///				buf.writeByte(' ');
+///				buf.writestring(ident.toChars());
+///			}
+///			else
+///				htype.toCBuffer(buf, ident, hgs);
+///		}
+///		else
+///	}
+		{
+		if (aliassym)
+		{
+			aliassym.toCBuffer(buf, hgs);
+			buf.writeByte(' ');
+			buf.writestring(ident.toChars());
+		}
+		else
+			type.toCBuffer(buf, ident, hgs);
+		}
+		buf.writeByte(';');
+		buf.writenl();
 	}
 
 	version (_DH) {
--- a/dmd/ArrayLengthExp.d	Sun Oct 10 01:55:35 2010 +0400
+++ b/dmd/ArrayLengthExp.d	Sun Oct 10 03:47:23 2010 +0400
@@ -17,6 +17,7 @@
 import dmd.Type;
 import dmd.WANT;
 import dmd.VarExp;
+import dmd.PREC;
 import dmd.VarDeclaration;
 import dmd.PtrExp;
 import dmd.Lexer;
@@ -125,7 +126,8 @@
 
 	override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
 	{
-		assert(false);
+		expToCBuffer(buf, hgs, e1, PREC_primary);
+		buf.writestring(".length");
 	}
 
 	override elem* toElem(IRState* irs)
--- a/dmd/AsmStatement.d	Sun Oct 10 01:55:35 2010 +0400
+++ b/dmd/AsmStatement.d	Sun Oct 10 03:47:23 2010 +0400
@@ -36,6 +36,8 @@
 import core.stdc.string : memset;
 import core.stdc.stdlib : exit, EXIT_FAILURE;
 
+import std.stdio;
+
 class AsmStatement : Statement
 {
     Token* tokens;
@@ -276,7 +278,30 @@
 
     override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
 	{
-		assert(false);
+		buf.writestring("asm { ");
+		Token* t = tokens;
+		while (t)
+		{
+			buf.writestring(t.toChars());
+			if (t.next                         &&
+			   t.value != TOKmin               &&
+			   t.value != TOKcomma             &&
+			   t.next.value != TOKcomma       &&
+			   t.value != TOKlbracket          &&
+			   t.next.value != TOKlbracket    &&
+			   t.next.value != TOKrbracket    &&
+			   t.value != TOKlparen            &&
+			   t.next.value != TOKlparen      &&
+			   t.next.value != TOKrparen      &&
+			   t.value != TOKdot               &&
+			   t.next.value != TOKdot)
+			{
+				buf.writebyte(' ');
+			}
+			t = t.next;
+		}
+		buf.writestring("; }");
+		buf.writenl();
 	}
 	
     override AsmStatement isAsmStatement() { return this; }
@@ -298,6 +323,7 @@
 		list_append(&bpre.Bsucc, basm);
 		basm.Bcode = asmcode;
 		basm.Balign = cast(ubyte)asmalign;
+
 static if (false) {
 		if (label)
 		{	
@@ -312,7 +338,7 @@
 		{	
 			LabelDsymbol label;
 			block* b;
-
+			
 			switch (c.IFL1)
 			{
 				case FLblockoff:
--- a/dmd/AssertExp.d	Sun Oct 10 01:55:35 2010 +0400
+++ b/dmd/AssertExp.d	Sun Oct 10 03:47:23 2010 +0400
@@ -17,6 +17,7 @@
 import dmd.Global;
 import dmd.InvariantDeclaration;
 import dmd.TOK;
+import dmd.PREC;
 import dmd.TY;
 import dmd.TypeClass;
 import dmd.Module;
@@ -34,6 +35,8 @@
 import dmd.backend.SC;
 import dmd.backend.FL;
 
+import dmd.expression.Util;
+
 import core.stdc.string;
 import std.string : toStringz;
 
@@ -81,7 +84,7 @@
 			fd.hasReturnExp |= 4;
 
 			if (!global.params.useAssert)
-			{   
+			{
 				Expression e = new HaltExp(loc);
 				e = e.semantic(sc);
 				return e;
@@ -112,7 +115,14 @@
 }
 	override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
 	{
-		assert(false);
+		buf.writestring("assert(");
+		expToCBuffer(buf, hgs, e1, PREC.PREC_assign);
+		if (msg)
+		{
+			buf.writeByte(',');
+			expToCBuffer(buf, hgs, msg, PREC_assign);
+		}
+		buf.writeByte(')');
 	}
 
 	override int inlineCost(InlineCostState* ics)
@@ -137,7 +147,7 @@
 			msg = msg.inlineScan(iss);
 		return this;
 	}
-	
+
 	static private void* castToVoid(int i)
 	{
 		return cast(void*)i;
@@ -188,7 +198,7 @@
 				 * to a #line directive.
 				 */
 				if (loc.filename && (msg || loc.filename != mname))
-				{	
+				{
 					elem* efilename;
 
 					/* Cache values.
@@ -224,7 +234,7 @@
 					efilename = el_var(assertexp_sfilename);
 
 					if (msg)
-					{   
+					{
 						elem* emsg = msg.toElem(irs);
 						ea = el_var(rtlsym[RTLSYM_DASSERT_MSG]);
 						ea = el_bin(OPcall, TYvoid, ea, el_params(el_long(TYint, loc.linnum), efilename, emsg, null));
@@ -245,7 +255,7 @@
 			}
 		}
 		else
-		{	
+		{
 			// BUG: should replace assert(0); with a HLT instruction
 			e = el_long(TYint, 0);
 		}
--- a/dmd/BinExp.d	Sun Oct 10 01:55:35 2010 +0400
+++ b/dmd/BinExp.d	Sun Oct 10 03:47:23 2010 +0400
@@ -277,7 +277,7 @@
 				goto Lt1;
 			}
 			else if (t1.ty == TY.Tclass && t2.ty == TY.Tclass)
-			{	
+			{
 				TypeClass tc1 = cast(TypeClass)t1;
 				TypeClass tc2 = cast(TypeClass)t2;
 
@@ -399,7 +399,7 @@
 		this.e1 = e1;
 		this.e2 = e2;
 	}
-	
+
     override Expression syntaxCopy()
 	{
 		BinExp e = cast(BinExp)copy();
@@ -429,16 +429,16 @@
 		}
 		return this;
 	}
-	
+
     Expression semanticp(Scope sc)
 	{
 		BinExp.semantic(sc);
-	
+
 		e1 = resolveProperties(sc, e1);
 		e2 = resolveProperties(sc, e2);
 		return this;
 	}
-	
+
 	/***************************
 	 * Common semantic routine for some xxxAssignExp's.
 	 */
@@ -461,9 +461,9 @@
 				e = e.semantic(sc);
 				return e;
 			}
-			
+
 			if (e1.op == TOKslice)
-			{   
+			{
 				// T[] op= ...
 				typeCombine(sc);
 				type = e1.type;
@@ -508,7 +508,7 @@
 				e = e.semantic(sc);
 				return e;
 			}
-			
+
 			if (e1.op == TOK.TOKslice)
 			{   // T[] op= ...
 				typeCombine(sc);
@@ -531,7 +531,7 @@
 
 		return this;
 	}
-	
+
     override bool checkSideEffect(int flag)
 	{
 		switch (op) {
@@ -561,7 +561,7 @@
 				return Expression.checkSideEffect(flag);
 		}
 	}
-	
+
     override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
 	{
 		expToCBuffer(buf, hgs, e1, precedence[op]);
@@ -581,7 +581,7 @@
 		Type t2b = e2.type.toBasetype();
 
 		if (t1b.ty == Tpointer && t2b.isintegral())
-		{   
+		{
 			// Need to adjust operator by the stride
 			// Replace (ptr + int) with (ptr + (int * stride))
 			Type t = Type.tptrdiff_t;
@@ -594,7 +594,7 @@
 			type = e1.type;
 		}
 		else if (t2b.ty == Tpointer && t1b.isintegral())
-		{   
+		{
 			// Need to adjust operator by the stride
 			// Replace (int + ptr) with (ptr + (int * stride))
 			Type t = Type.tptrdiff_t;
@@ -613,7 +613,7 @@
 		}
 		return this;
 	}
-	
+
 	/************************************
 	 * Bring leaves to common type.
 	 */
@@ -663,7 +663,7 @@
 				ulong sz = e1.type.size() * 8;
 
 				if (i2 < 0 || i2 > sz)
-				{   
+				{
 					error("shift assign by %jd is outside the range 0..%zu", i2, sz);
 					e2 = new IntegerExp(0);
 				}
@@ -677,7 +677,7 @@
 	{
 		return e1.type.isunsigned() || e2.type.isunsigned();
 	}
-	
+
     void incompatibleTypes()
 	{
 		error("incompatible types for ((%s) %s (%s)): '%s' and '%s'",
@@ -761,7 +761,7 @@
 	Lcant:
 		return EXP_CANT_INTERPRET;
 	}
-	
+
     Expression interpretAssignCommon(InterState istate, Expression function(Type, Expression, Expression) fp, int post = 0)
 	{
 version (LOG)
@@ -774,7 +774,7 @@
 		if (fp)
 		{
 			if (e1.op == TOKcast)
-			{   
+			{
 				CastExp ce = cast(CastExp)e1;
 				e1 = ce.e1;
 			}
@@ -784,7 +784,7 @@
 		Expression e2 = this.e2.interpret(istate);
 		if (e2 is EXP_CANT_INTERPRET)
 			return e2;
-		
+
 		// Chase down rebinding of out and ref.
 		if (e1.op == TOKvar)
 		{
@@ -794,7 +794,7 @@
 			{
 				VarExp ve2 = cast(VarExp)v.value;
 				if (ve2.var.isSymbolDeclaration())
-				{	
+				{
 					// This can happen if v is a struct initialized to
 					// 0 using an __initZ SymbolDeclaration from
 					// TypeStruct.defaultInit()
@@ -805,7 +805,7 @@
 			else if (v && v.value && (v.value.op==TOKindex || v.value.op == TOKdotvar))
 			{
 				// It is no longer a TOKvar, eg when a[4] is passed by ref.
-				e1 = v.value;	    
+				e1 = v.value;
 			}
 		}
 
@@ -816,9 +816,9 @@
 			aggregate = (cast(DotVarExp)e1).e1;
 		// Get rid of 'this'.
 			if (aggregate.op == TOKthis && istate.localThis)
-				aggregate = istate.localThis;	
+				aggregate = istate.localThis;
 		}
-		
+
 		/* Assignment to variable of the form:
 		 *	v = e2
 		 */
@@ -828,7 +828,7 @@
 			VarDeclaration v = ve.var.isVarDeclaration();
 			assert(v);
 			if (v && !v.isCTFE())
-			{   
+			{
 				// Can't modify global or static data
 				error("%s cannot be modified at compile time", v.toChars());
 				return EXP_CANT_INTERPRET;
@@ -837,14 +837,14 @@
 			{
 				Expression ev = v.value;
 				if (fp && !ev)
-				{	
+				{
 					error("variable %s is used before initialization", v.toChars());
 					return e;
 				}
 				if (fp)
 					e2 = (*fp)(v.type, ev, e2);
 				else
-				{	
+				{
 					/* Look for special case of struct being initialized with 0.
 					 */
 					if (v.type.toBasetype().ty == Tstruct && e2.op == TOKint64)
@@ -862,7 +862,7 @@
 			}
 		}
 		else if (e1.op == TOKdotvar && aggregate.op == TOKdotvar)
-		{	
+		{
 			// eg  v.u.var = e2,  v[3].u.var = e2, etc.
 			error("Nested struct assignment %s is not yet supported in CTFE", toChars());
 		}
@@ -870,11 +870,11 @@
 		 *   v.var = e2
 		 */
 		else if (e1.op == TOKdotvar && aggregate.op == TOKvar)
-		{	
+		{
 			VarDeclaration v = (cast(VarExp)aggregate).var.isVarDeclaration();
 
 			if (!v.isCTFE())
-			{   
+			{
 				// Can't modify global or static data
 				error("%s cannot be modified at compile time", v.toChars());
 				return EXP_CANT_INTERPRET;
@@ -884,7 +884,7 @@
 				{
 					VarExp ve2 = cast(VarExp)v.value;
 					if (ve2.var.isSymbolDeclaration())
-					{	
+					{
 						// This can happen if v is a struct initialized to
 						// 0 using an __initZ SymbolDeclaration from
 						// TypeStruct.defaultInit()
@@ -895,12 +895,12 @@
 				}
 			}
 			if (fp && !v.value)
-			{   
+			{
 				error("variable %s is used before initialization", v.toChars());
 				return e;
 			}
 			if (v.value is null && v.init.isVoidInitializer())
-			{   
+			{
 				/* Since a void initializer initializes to undefined
 				 * values, it is valid here to use the default initializer.
 				 * No attempt is made to determine if someone actually relies
@@ -946,7 +946,7 @@
 		 *   *(symoffexp) = e2
 		 */
 		else if (e1.op == TOKstar && (cast(PtrExp)e1).e1.op == TOKsymoff)
-		{	
+		{
 			SymOffExp soe = cast(SymOffExp)(cast(PtrExp)e1).e1;
 			VarDeclaration v = soe.var.isVarDeclaration();
 
@@ -956,7 +956,7 @@
 				return EXP_CANT_INTERPRET;
 			}
 			if (fp && !v.value)
-			{   
+			{
 				error("variable %s is used before initialization", v.toChars());
 				return e;
 			}
@@ -994,7 +994,7 @@
 		 *   a[i] = e2
 		 */
 		else if (e1.op == TOKindex && (cast(IndexExp)e1).e1.op == TOKvar)
-		{	
+		{
 			IndexExp ie = cast(IndexExp)e1;
 			VarExp ve = cast(VarExp)ie.e1;
 			VarDeclaration v = ve.var.isVarDeclaration();
@@ -1007,7 +1007,7 @@
 			{
 				VarExp ve2 = cast(VarExp)v.value;
 				if (ve2.var.isSymbolDeclaration())
-				{	
+				{
 					// This can happen if v is a struct initialized to
 					// 0 using an __initZ SymbolDeclaration from
 					// TypeStruct.defaultInit()
@@ -1019,7 +1019,7 @@
 			if (!v.value)
 			{
 				if (fp)
-				{   
+				{
 					error("variable %s is used before initialization", v.toChars());
 					return e;
 				}
@@ -1083,7 +1083,7 @@
 				e2 = Cast(type, type, e2);
 			if (e2 is EXP_CANT_INTERPRET)
 				return e2;
-			
+
 			addVarToInterstate(istate, v);
 			if (ae)
 			{
@@ -1103,14 +1103,14 @@
 				valuesx.setDim(aae.values.dim);
 				int updated = 0;
 				for (size_t j = valuesx.dim; j; )
-				{	
+				{
 					j--;
 					Expression ekey = aae.keys[j];
 					Expression ex = Equal(TOKequal, Type.tbool, ekey, index);
 					if (ex is EXP_CANT_INTERPRET)
 						return EXP_CANT_INTERPRET;
 					if (ex.isBool(true))
-					{   
+					{
 						valuesx[j] = e2;
 						updated = 1;
 					}
@@ -1118,7 +1118,7 @@
 						valuesx[j] = aae.values[j];
 				}
 				if (!updated)
-				{	
+				{
 					// Append index/e2 to keysx[]/valuesx[]
 					valuesx.push(e2);
 					keysx = keysx.copy();
@@ -1156,7 +1156,7 @@
 
 			e = Cast(type, type, post ? ev : e2);
 		}
-		
+
 		/* Assignment to struct element in array, of the form:
 		 *  a[i].var = e2
 		 */
@@ -1214,7 +1214,7 @@
 			int elemi = cast(int)index.toInteger();
 			if (elemi >= ae.elements.dim)
 			{
-				error("array index %d is out of bounds %s[0..%d]", elemi, 
+				error("array index %d is out of bounds %s[0..%d]", elemi,
 					v.toChars(), ae.elements.dim);
 				return EXP_CANT_INTERPRET;
 			}
@@ -1232,7 +1232,7 @@
 			int fieldi = se.getFieldIndex(type, vf.offset);
 			if (fieldi == -1)
 				return EXP_CANT_INTERPRET;
-				
+
 			Expression ev = se.getField(type, vf.offset);
 			if (fp)
 				e2 = (*fp)(type, ev, e2);
@@ -1267,7 +1267,7 @@
 			{
 				VarExp ve2 = cast(VarExp)v.value;
 				if (ve2.var.isSymbolDeclaration())
-				{	
+				{
 					// This can happen if v is a struct initialized to
 					// 0 using an __initZ SymbolDeclaration from
 					// TypeStruct.defaultInit()
@@ -1298,7 +1298,7 @@
 			}
 			Type t = v.type.toBasetype();
 			size_t dim;
-			if (t.ty == Tsarray)			
+			if (t.ty == Tsarray)
 				dim = cast(size_t)(cast(TypeSArray)t).dim.toInteger();
 			else if (t.ty == Tarray)
 			{
@@ -1346,7 +1346,7 @@
 			if (e2.op == TOKarrayliteral)
 			{
 				// Static array assignment from literal
-				ArrayLiteralExp ae = cast(ArrayLiteralExp)e2;				
+				ArrayLiteralExp ae = cast(ArrayLiteralExp)e2;
 				if (ae.elements.dim != (upperbound - lowerbound))
 				{
 					error("Array length mismatch assigning [0..%d] to [%d..%d]", ae.elements.dim, lowerbound, upperbound);
@@ -1372,7 +1372,7 @@
 					// value[] = value[0..lower] ~ ae ~ value[upper..$]
 					existing.elements = spliceElements(existing.elements, createBlockDuplicatedArrayLiteral(v.type, e2, upperbound-lowerbound).elements, lowerbound);
 					v.value = existing;
-				}				
+				}
 				return e2;
 			}
 			else if (e2.op == TOKstring)
@@ -1407,7 +1407,7 @@
 	{
 		return e1.canThrow() || e2.canThrow();
 	}
-	
+
 	// generate an error if this is a nonsensical *=,/=, or %=, eg real *= imaginary
 	void checkComplexMulAssign()
 	{
@@ -1417,7 +1417,7 @@
 		if ( e1.type.isreal() && e2.type.iscomplex())
 		{
 			error("%s %s %s is undefined. Did you mean %s %s %s.re ?",
-				e1.type.toChars(), opstr, e2.type.toChars(), 
+				e1.type.toChars(), opstr, e2.type.toChars(),
 				e1.type.toChars(), opstr, e2.type.toChars());
 		}
 		else if (e1.type.isimaginary() && e2.type.iscomplex())
@@ -1439,7 +1439,7 @@
 		// Addition or subtraction of a real and an imaginary is a complex result.
 		// Thus, r+=i, r+=c, i+=r, i+=c are all forbidden operations.
 		if ( (e1.type.isreal() && (e2.type.isimaginary() || e2.type.iscomplex())) ||
-			 (e1.type.isimaginary() && (e2.type.isreal() || e2.type.iscomplex()))        
+			 (e1.type.isimaginary() && (e2.type.isreal() || e2.type.iscomplex()))
 			)
 		{
 			error("%s %s %s is undefined (result is complex)",
@@ -1454,13 +1454,13 @@
     Expression arrayOp(Scope sc)
 	{
 		//printf("BinExp.arrayOp() %s\n", toChars());
-		
+
 		if (type.toBasetype().nextOf().toBasetype().ty == Tvoid)
 		{
 			error("Cannot perform array operations on void[] arrays");
 			return new ErrorExp();
 		}
-		
+
 		auto arguments = new Expressions();
 
 		/* The expression to generate an array operation for is mangled
@@ -1740,7 +1740,7 @@
 	{
 		return 1 + e1.inlineCost(ics) + e2.inlineCost(ics);
 	}
-	
+
     override Expression doInline(InlineDoState ids)
 	{
 		BinExp be = cast(BinExp)copy();
@@ -1749,7 +1749,7 @@
 		be.e2 = e2.doInline(ids);
 		return be;
 	}
-	
+
     override Expression inlineScan(InlineScanState* iss)
 	{
 		e1 = e1.inlineScan(iss);
@@ -1828,12 +1828,12 @@
 					overloadResolveX(&m, fd, null, args2);
 				}
 				else
-				{   
+				{
 					td = s.isTemplateDeclaration();
 					templateResolve(&m, td, sc, loc, null, null, args2);
 				}
 			}
-			
+
 			lastf = m.lastf;
 
 			if (s_r)
@@ -1844,7 +1844,7 @@
 					overloadResolveX(&m, fd, null, args1);
 				}
 				else
-				{  
+				{
 					td = s_r.isTemplateDeclaration();
 					templateResolve(&m, td, sc, loc, null, null, args1);
 				}
@@ -1900,7 +1900,7 @@
 				 */
 
 				if (!argsset)
-				{	
+				{
 					args1.setDim(1);
 					args1[0] = e1;
 					args2.setDim(1);
@@ -2031,24 +2031,24 @@
 		return e;
 	}
 	final void AssignExp_buildArrayIdent(OutBuffer buf, Expressions arguments, string Str)
-	{							
-		/* Evaluate assign expressions right to left	
-		 */							
-		e2.buildArrayIdent(buf, arguments);		
-		e1.buildArrayIdent(buf, arguments);		
-		buf.writestring(Str);				
-		buf.writestring("ass");				
+	{
+		/* Evaluate assign expressions right to left
+		 */
+		e2.buildArrayIdent(buf, arguments);
+		e1.buildArrayIdent(buf, arguments);
+		buf.writestring(Str);
+		buf.writestring("ass");
 	}
-	
+
 	final void Exp_buildArrayIdent(OutBuffer buf, Expressions arguments, string Str)
-	{									
-		/* Evaluate assign expressions left to right			
-		 */									
-		e1.buildArrayIdent(buf, arguments);				
-		e2.buildArrayIdent(buf, arguments);				
-		buf.writestring(Str);						
+	{
+		/* Evaluate assign expressions left to right
+		 */
+		e1.buildArrayIdent(buf, arguments);
+		e2.buildArrayIdent(buf, arguments);
+		buf.writestring(Str);
 	}
-	
+
 	final Expression AssignExp_buildArrayLoop(AssignExpType)(Parameters fparams)// if (is (AssignExpType : AssignExp))
 	{
 		/* Evaluate assign expressions right to left
@@ -2060,7 +2060,7 @@
 		Expression e = new AssignExpType(Loc(0), ex1, ex2);
 		return e;
 	}
-	
+
 	final Expression Exp_buildArrayLoop(ExpType)(Parameters fparams) if (is (ExpType : BinExp))
 	{
 		/* Evaluate assign expressions left to right
@@ -2070,4 +2070,4 @@
 		Expression e = new ExpType(Loc(0), ex1, ex2);
 		return e;
 	}
-}
\ No newline at end of file
+}
--- a/dmd/BreakStatement.d	Sun Oct 10 01:55:35 2010 +0400
+++ b/dmd/BreakStatement.d	Sun Oct 10 03:47:23 2010 +0400
@@ -112,7 +112,14 @@
 
     override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
 	{
-		assert(false);
+		buf.writestring("break");
+		if (ident)
+		{   
+			buf.writebyte(' ');
+			buf.writestring(ident.toChars());
+		}
+		buf.writebyte(';');
+		buf.writenl();
 	}
 
     override void toIR(IRState* irs)
--- a/dmd/CaseStatement.d	Sun Oct 10 01:55:35 2010 +0400
+++ b/dmd/CaseStatement.d	Sun Oct 10 03:47:23 2010 +0400
@@ -158,7 +158,11 @@
 	
     override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
 	{
-		assert(false);
+	    buf.writestring("case ");
+		exp.toCBuffer(buf, hgs);
+		buf.writebyte(':');
+		buf.writenl();
+		statement.toCBuffer(buf, hgs);
 	}
 
     override Statement inlineScan(InlineScanState* iss)
--- a/dmd/Catch.d	Sun Oct 10 01:55:35 2010 +0400
+++ b/dmd/Catch.d	Sun Oct 10 03:47:23 2010 +0400
@@ -85,6 +85,19 @@
 
     void toCBuffer(OutBuffer buf, HdrGenState* hgs)
 	{
-		assert(false);
+		buf.writestring("catch");
+		if (type)
+		{   
+			buf.writebyte('(');
+			type.toCBuffer(buf, ident, hgs);
+			buf.writebyte(')');
+		}
+		buf.writenl();
+		buf.writebyte('{');
+		buf.writenl();
+		if (handler)
+			handler.toCBuffer(buf, hgs);
+		buf.writebyte('}');
+		buf.writenl();
 	}
 }
\ No newline at end of file
--- a/dmd/ClassDeclaration.d	Sun Oct 10 01:55:35 2010 +0400
+++ b/dmd/ClassDeclaration.d	Sun Oct 10 03:47:23 2010 +0400
@@ -146,121 +146,123 @@
 			{
 				if (id is Id.TypeInfo)
 				{	
-					if (Type.typeinfo)
-						Type.typeinfo.error("%s", msg);
-					Type.typeinfo = this;
+					if (global.typeinfo) {
+						global.typeinfo.error("%s", msg);
+					}
+						
+					global.typeinfo = this;
 				}
 
 				if (id is Id.TypeInfo_Class)
 				{	
-					if (Type.typeinfoclass)
-						Type.typeinfoclass.error("%s", msg);
-					Type.typeinfoclass = this;
+					if (global.typeinfoclass)
+						global.typeinfoclass.error("%s", msg);
+					global.typeinfoclass = this;
 				}
 
 				if (id is Id.TypeInfo_Interface)
 				{	
-					if (Type.typeinfointerface)
-						Type.typeinfointerface.error("%s", msg);
-					Type.typeinfointerface = this;
+					if (global.typeinfointerface)
+						global.typeinfointerface.error("%s", msg);
+					global.typeinfointerface = this;
 				}
 
 				if (id is Id.TypeInfo_Struct)
 				{	
-					if (Type.typeinfostruct)
-						Type.typeinfostruct.error("%s", msg);
-					Type.typeinfostruct = this;
+					if (global.typeinfostruct)
+						global.typeinfostruct.error("%s", msg);
+					global.typeinfostruct = this;
 				}
 
 				if (id is Id.TypeInfo_Typedef)
 				{	
-					if (Type.typeinfotypedef)
-						Type.typeinfotypedef.error("%s", msg);
-					Type.typeinfotypedef = this;
+					if (global.typeinfotypedef)
+						global.typeinfotypedef.error("%s", msg);
+					global.typeinfotypedef = this;
 				}
 
 				if (id is Id.TypeInfo_Pointer)
 				{	
-					if (Type.typeinfopointer)
-						Type.typeinfopointer.error("%s", msg);
-					Type.typeinfopointer = this;
+					if (global.typeinfopointer)
+						global.typeinfopointer.error("%s", msg);
+					global.typeinfopointer = this;
 				}
 
 				if (id is Id.TypeInfo_Array)
 				{	
-					if (Type.typeinfoarray)
-						Type.typeinfoarray.error("%s", msg);
-					Type.typeinfoarray = this;
+					if (global.typeinfoarray)
+						global.typeinfoarray.error("%s", msg);
+					global.typeinfoarray = this;
 				}
 
 				if (id is Id.TypeInfo_StaticArray)
-				{	//if (Type.typeinfostaticarray)
-					//Type.typeinfostaticarray.error("%s", msg);
-					Type.typeinfostaticarray = this;
+				{	//if (global.typeinfostaticarray)
+					//global.typeinfostaticarray.error("%s", msg);
+					global.typeinfostaticarray = this;
 				}
 
 				if (id is Id.TypeInfo_AssociativeArray)
 				{	
-					if (Type.typeinfoassociativearray)
-						Type.typeinfoassociativearray.error("%s", msg);
-					Type.typeinfoassociativearray = this;
+					if (global.typeinfoassociativearray)
+						global.typeinfoassociativearray.error("%s", msg);
+					global.typeinfoassociativearray = this;
 				}
 
 				if (id is Id.TypeInfo_Enum)
 				{	
-					if (Type.typeinfoenum)
-						Type.typeinfoenum.error("%s", msg);
-					Type.typeinfoenum = this;
+					if (global.typeinfoenum)
+						global.typeinfoenum.error("%s", msg);
+					global.typeinfoenum = this;
 				}
 
 				if (id is Id.TypeInfo_Function)
 				{	
-					if (Type.typeinfofunction)
-						Type.typeinfofunction.error("%s", msg);
-					Type.typeinfofunction = this;
+					if (global.typeinfofunction)
+						global.typeinfofunction.error("%s", msg);
+					global.typeinfofunction = this;
 				}
 
 				if (id is Id.TypeInfo_Delegate)
 				{	
-					if (Type.typeinfodelegate)
-						Type.typeinfodelegate.error("%s", msg);
-					Type.typeinfodelegate = this;
+					if (global.typeinfodelegate)
+						global.typeinfodelegate.error("%s", msg);
+					global.typeinfodelegate = this;
 				}
 
 				if (id is Id.TypeInfo_Tuple)
 				{	
-					if (Type.typeinfotypelist)
-						Type.typeinfotypelist.error("%s", msg);
-					Type.typeinfotypelist = this;
+					if (global.typeinfotypelist)
+						global.typeinfotypelist.error("%s", msg);
+					global.typeinfotypelist = this;
 				}
 
 	version (DMDV2) {
 				if (id is Id.TypeInfo_Const)
 				{	
-					if (Type.typeinfoconst)
-						Type.typeinfoconst.error("%s", msg);
-					Type.typeinfoconst = this;
+					if (global.typeinfoconst)
+						global.typeinfoconst.error("%s", msg);
+					global.typeinfoconst = this;
 				}
 
 				if (id is Id.TypeInfo_Invariant)
 				{	
-					if (Type.typeinfoinvariant)
-						Type.typeinfoinvariant.error("%s", msg);
-					Type.typeinfoinvariant = this;
+					if (global.typeinfoinvariant)
+						global.typeinfoinvariant.error("%s", msg);
+					global.typeinfoinvariant = this;
 				}
 
 				if (id is Id.TypeInfo_Shared)
 				{	
-					if (Type.typeinfoshared)
-						Type.typeinfoshared.error("%s", msg);
-					Type.typeinfoshared = this;
+					if (global.typeinfoshared)
+						global.typeinfoshared.error("%s", msg);
+					global.typeinfoshared = this;
 				}
 
 	            if (id == Id.TypeInfo_Wild)
 	            {
-                    if (Type.typeinfowild)
-		                Type.typeinfowild.error("%s", msg);
-		            Type.typeinfowild = this;
+                    if (global.typeinfowild)
+		                global.typeinfowild.error("%s", msg);
+		            global.typeinfowild = this;
 	            }
 	}
 			}
--- a/dmd/ComplexExp.d	Sun Oct 10 01:55:35 2010 +0400
+++ b/dmd/ComplexExp.d	Sun Oct 10 03:47:23 2010 +0400
@@ -89,7 +89,7 @@
 		if (type != t)
 		{
 			if (type.iscomplex() && t.iscomplex())
-			{   
+			{
 				e = copy();
 				e.type = t;
 			}
@@ -114,7 +114,22 @@
 
 	override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
 	{
-		assert(false);
+		/* Print as:
+		 *  (re+imi)
+		 */
+version (IN_GCC) {
+		char buf1[sizeof(value) * 3 + 8 + 1];
+		char buf2[sizeof(value) * 3 + 8 + 1];
+		creall(value).format(buf1, sizeof(buf1));
+		cimagl(value).format(buf2, sizeof(buf2));
+		buf.printf("(%s+%si)", buf1, buf2);
+} else {
+		buf.writeByte('(');
+		floatToBuffer(buf, type, value.re);
+		buf.writeByte('+');
+		floatToBuffer(buf, type, value.im);
+		buf.writestring("i)");
+}
 	}
 
 	override void toMangleBuffer(OutBuffer buf)
@@ -126,7 +141,7 @@
 		r = toImaginary();
 		realToMangleBuffer(buf, r);
 	}
-	
+
 version (_DH) {
 	OutBuffer hexp;
 }
@@ -204,7 +219,7 @@
 		}
 		return el_const(ty, &c);
 	}
-	
+
 	static private char[6] zeropad;
 
 	override dt_t** toDt(dt_t** pdt)
--- a/dmd/CompoundDeclarationStatement.d	Sun Oct 10 01:55:35 2010 +0400
+++ b/dmd/CompoundDeclarationStatement.d	Sun Oct 10 03:47:23 2010 +0400
@@ -3,7 +3,15 @@
 import dmd.common;
 import dmd.CompoundStatement;
 import dmd.Loc;
+import dmd.TOK;
 import dmd.ArrayTypes;
+import dmd.VarDeclaration;
+import dmd.AssignExp;
+import dmd.ExpInitializer;
+import dmd.Declaration;
+import dmd.StorageClassDeclaration;
+import dmd.DeclarationStatement;
+import dmd.DeclarationExp;
 import dmd.Statement;
 import dmd.OutBuffer;
 import dmd.HdrGenState;
@@ -15,13 +23,13 @@
 		super(loc, s);
 		///statements = s;
 	}
-	
+
     override Statement syntaxCopy()
 	{
 		Statements a = new Statements();
 		a.setDim(statements.dim);
 		for (size_t i = 0; i < statements.dim; i++)
-		{	
+		{
 			Statement s = statements[i];
 			if (s)
 				s = s.syntaxCopy();
@@ -30,9 +38,60 @@
 		CompoundDeclarationStatement cs = new CompoundDeclarationStatement(loc, a);
 		return cs;
 	}
-	
+
     override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
 	{
-		assert(false);
+		int nwritten = 0;
+		foreach (Statement s; statements)
+		{
+			if (s)
+			{
+				DeclarationStatement ds = s.isDeclarationStatement();
+				assert(ds);
+				DeclarationExp de = cast(DeclarationExp)ds.exp;
+				assert(de.op == TOKdeclaration);
+				Declaration d = de.declaration.isDeclaration();
+				assert(d);
+				VarDeclaration v = d.isVarDeclaration();
+				if (v)
+				{
+					/* This essentially copies the part of VarDeclaration.toCBuffer()
+					 * that does not print the type.
+					 * Should refactor this.
+					 */
+					if (nwritten)
+					{
+						buf.writeByte(',');
+						buf.writestring(v.ident.toChars());
+					}
+					else
+					{
+						StorageClassDeclaration.stcToCBuffer(buf, v.storage_class);
+						if (v.type)
+							v.type.toCBuffer(buf, v.ident, hgs);
+						else
+							buf.writestring(v.ident.toChars());
+					}
+
+					if (v.init)
+					{
+						buf.writestring(" = ");
+///version (DMDV2) {
+						ExpInitializer ie = v.init.isExpInitializer();
+						if (ie && (ie.exp.op == TOKconstruct || ie.exp.op == TOKblit))
+							(cast(AssignExp)ie.exp).e2.toCBuffer(buf, hgs);
+						else
+///}
+							v.init.toCBuffer(buf, hgs);
+					}
+				}
+				else
+					d.toCBuffer(buf, hgs);
+				nwritten++;
+			}
+		}
+		buf.writeByte(';');
+		if (!hgs.FLinit.init)
+			buf.writenl();
 	}
 }
--- a/dmd/CompoundStatement.d	Sun Oct 10 01:55:35 2010 +0400
+++ b/dmd/CompoundStatement.d	Sun Oct 10 03:47:23 2010 +0400
@@ -66,8 +66,10 @@
 	{
 		foreach (s; statements)
 		{
-			if (s)
+			if (s) {
+				s.toChars();
 				s.toCBuffer(buf, hgs);
+			}
 		}
 	}
 	
@@ -369,6 +371,7 @@
 			{
 				if (s !is null)
 				{
+					//writeln(s.classinfo.name);
 					s.toIR(irs);
 				}
 			}
--- a/dmd/DeleteExp.d	Sun Oct 10 01:55:35 2010 +0400
+++ b/dmd/DeleteExp.d	Sun Oct 10 03:47:23 2010 +0400
@@ -11,6 +11,7 @@
 import dmd.HdrGenState;
 import dmd.Type;
 import dmd.IndexExp;
+import dmd.PREC;
 import dmd.Global;
 import dmd.VarExp;
 import dmd.Identifier;
@@ -31,6 +32,7 @@
 import dmd.TypeAArray;
 import dmd.TypeSArray;
 
+import dmd.expression.Util;
 import dmd.codegen.Util;
 import dmd.backend.Util;
 import dmd.backend.OPER;
@@ -57,9 +59,9 @@
 
 		tb = e1.type.toBasetype();
 		switch (tb.ty)
-		{	
+		{
 			case Tclass:
-			{   
+			{
 				TypeClass tc = cast(TypeClass)tb;
 				ClassDeclaration cd = tc.sym;
 
@@ -93,7 +95,7 @@
 					VarDeclaration v;
 
 					if (fd && f)
-					{   
+					{
 						Identifier id = Lexer.idPool("__tmp");
 						v = new VarDeclaration(loc, e1.type, id, new ExpInitializer(loc, e1));
 						v.semantic(sc);
@@ -103,7 +105,7 @@
 					}
 
 					if (fd)
-					{   
+					{
 						Expression e = ea ? new VarExp(loc, v) : e1;
 						e = new DotVarExp(Loc(0), e, fd, 0);
 						eb = new CallExp(loc, e);
@@ -140,13 +142,13 @@
 				error("cannot delete type %s", e1.type.toChars());
 				break;
 		}
-		
+
 		if (e1.op == TOKindex)
 		{
 			IndexExp ae = cast(IndexExp)e1;
 			Type tb1 = ae.e1.type.toBasetype();
 			if (tb1.ty == Taarray)
-			{   
+			{
 				if (!global.params.useDeprecated)
 					error("delete aa[key] deprecated, use aa.remove(key)");
 			}
@@ -167,7 +169,8 @@
 
 	override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
 	{
-		assert(false);
+		buf.writestring("delete ");
+		expToCBuffer(buf, hgs, e1, precedence[op]);
 	}
 
 	override elem* toElem(IRState* irs)
@@ -209,7 +212,7 @@
 		switch (tb.ty)
 		{
 			case Tarray:
-			{   
+			{
 				e = addressElem(e, e1.type);
 				rtl = RTLSYM_DELARRAYT;
 
@@ -218,12 +221,12 @@
 				elem *et = null;
 				Type tv = tb.nextOf().toBasetype();
 				while (tv.ty == Tsarray)
-				{   
+				{
 					TypeSArray ta = cast(TypeSArray)tv;
 					tv = tv.nextOf().toBasetype();
 				}
 				if (tv.ty == Tstruct)
-				{   
+				{
 					TypeStruct ts = cast(TypeStruct)tv;
 					StructDeclaration sd = ts.sym;
 					if (sd.dtor)
@@ -238,7 +241,7 @@
 			}
 			case Tclass:
 				if (e1.op == TOKvar)
-				{	
+				{
 					VarExp ve = cast(VarExp)e1;
 					if (ve.var.isVarDeclaration() &&
 						ve.var.isVarDeclaration().onstack)
--- a/dmd/DoStatement.d	Sun Oct 10 01:55:35 2010 +0400
+++ b/dmd/DoStatement.d	Sun Oct 10 03:47:23 2010 +0400
@@ -161,7 +161,13 @@
 
     override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
 	{
-		assert(false);
+	    buf.writestring("do");
+		buf.writenl();
+		if (body_)
+			body_.toCBuffer(buf, hgs);
+		buf.writestring("while (");
+		condition.toCBuffer(buf, hgs);
+		buf.writebyte(')');
 	}
 
     override Statement inlineScan(InlineScanState* iss)
--- a/dmd/ExpInitializer.d	Sun Oct 10 01:55:35 2010 +0400
+++ b/dmd/ExpInitializer.d	Sun Oct 10 03:47:23 2010 +0400
@@ -109,7 +109,7 @@
 	
     override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
 	{
-		assert(false);
+		exp.toCBuffer(buf, hgs);
 	}
 
     override dt_t* toDt()
--- a/dmd/File.d	Sun Oct 10 01:55:35 2010 +0400
+++ b/dmd/File.d	Sun Oct 10 03:47:23 2010 +0400
@@ -20,6 +20,7 @@
 }
 
 import std.string : toStringz;
+import std.stdio;
 
 import core.memory;
 
@@ -84,7 +85,7 @@
 
 		string name = this.name.toChars();
 
-		//printf("File::read('%s')\n",name);
+		//writefln("File::read('%s')\n",name);
 		int fd = open(toStringz(name), O_RDONLY);
 		if (fd == -1) {
 			result = errno;
@@ -154,7 +155,7 @@
 		int result = 0;
 
 		string name = this.name.toChars();
-		//std.stdio.writeln("Open file ", name);
+		//writeln("Open file ", name);
 
 		h = CreateFileA(toStringz(name), GENERIC_READ, FILE_SHARE_READ, null, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, HANDLE.init);
 		if (h == INVALID_HANDLE_VALUE) {
--- a/dmd/FileName.d	Sun Oct 10 01:55:35 2010 +0400
+++ b/dmd/FileName.d	Sun Oct 10 03:47:23 2010 +0400
@@ -156,7 +156,7 @@
 					break;
 			}
 		}
-		
+
 		return null;
 	}
 
@@ -164,7 +164,7 @@
 	{
 		return ext(str);
 	}
-	
+
 	/********************************
 	 * Return filename with extension removed.
 	 */
@@ -180,7 +180,7 @@
 
 		return str;
 	}
-	
+
 	/********************************
 	 * Return filename name excluding path (read-only).
 	 */
@@ -222,7 +222,7 @@
 	{
 		return name(str);
 	}
-	
+
 	/**************************************
 	 * Return path portion of str.
 	 * Path will does not include trailing path separator.
@@ -252,11 +252,11 @@
 		size_t pathlen = n - str.ptr;
 		return str[0..pathlen];
 	}
-	
+
 	/**************************************
 	 * Replace filename portion of path.
 	 */
-	
+
     static string replaceName(string path, string name)
 	{
 		if (absolute(name))
@@ -294,7 +294,7 @@
 		static assert(false);
 }
 		memcpy(f + pathlen, name.ptr, namelen + 1);
-		
+
 		return assumeUnique(f[0..pathlen+namelen]);
 	}
 
@@ -322,7 +322,7 @@
 }
 else version (Windows)
 {
-		if (path[pathlen - 1] != '\\' && 
+		if (path[pathlen - 1] != '\\' &&
 			path[pathlen - 1] != '/'  &&
 			path[pathlen - 1] != ':')
 		{
@@ -338,14 +338,14 @@
 
 		return assumeUnique(f[0..pathlen+namelen]);
 	}
-	
+
     static string[] splitPath(const(char)[] spath)
 	{
 		char c = 0;				// unnecessary initializer is for VC /W4
 
 		scope OutBuffer buf = new OutBuffer();
 		string[] array;
-		
+
 		if (spath !is null)
 		{
 			const(char)* p = spath.ptr;
@@ -358,7 +358,7 @@
 					p++;
 					--len;
 				}
-				
+
 				buf.reserve(len + 1);	// guess size of path
 				for (; len; p++, len--)
 				{
@@ -414,10 +414,10 @@
 				}
 			} while (len > 0);
 		}
-		
+
 		return array;
 	}
-	
+
     static FileName defaultExt(string name, string ext)
 	{
 		string e = FileName.ext(name);
@@ -452,11 +452,11 @@
 
 		return defaultExt(name, ext);	// doesn't have one
 	}
-	
+
 	/******************************
 	 * Return true if extensions match.
 	 */
-	
+
     bool equalsExt(string ext)
 	{
 		string e = FileName.ext();
@@ -474,7 +474,7 @@
 		static assert(0);
 }
 	}
-	
+
 	/*************************************
 	 * Copy file from this to to.
 	 */
@@ -494,7 +494,7 @@
 		file.name = to;
 		file.writev();
 	}
-	
+
 	/*************************************
 	 * Search Path for file.
 	 * Input:
@@ -506,13 +506,13 @@
 		if (absolute(name)) {
 			return exists(name) ? name : null;
 		}
-		
+
 		if (cwd) {
 			if (exists(name)) {
 				return name;
 			}
 		}
-		
+
 		if (path !is null) {
 			foreach (i; 0..path.dim)
 			{
@@ -523,7 +523,7 @@
 					return n;
 			}
 		}
-		
+
 		return null;
 	}
 
@@ -532,13 +532,13 @@
 		if (absolute(name)) {
 			return exists(name) ? name : null;
 		}
-		
+
 		if (cwd) {
 			if (exists(name)) {
 				return name;
 			}
 		}
-		
+
 		if (path !is null) {
 			foreach (i, p; path)
 			{
@@ -548,7 +548,7 @@
 					return n;
 			}
 		}
-		
+
 		return null;
 	}
 
@@ -567,7 +567,7 @@
 		if (h == INVALID_HANDLE_VALUE) {
 			return 0;
 		}
-		
+
 		CloseHandle(h);
 
 		DWORD dw = GetFileAttributesA(name.ptr);	/// CARE!
@@ -583,7 +583,7 @@
 		static assert(0);
 }
 	}
-	
+
     static void ensurePathExists(string path)
 	{
 		if (path.length == 0)
--- a/dmd/FuncDeclaration.d	Sun Oct 10 01:55:35 2010 +0400
+++ b/dmd/FuncDeclaration.d	Sun Oct 10 03:47:23 2010 +0400
@@ -131,7 +131,7 @@
     Statement frequire;
     Statement fensure;
     Statement fbody;
-	
+
     FuncDeclarations foverrides;	// functions this function overrides
     FuncDeclaration fdrequire;		// function that does the in contract
     FuncDeclaration fdensure;		// function that does the out contract
@@ -252,7 +252,7 @@
 		foverrides = new FuncDeclarations();
 		closureVars = new Dsymbols();
 	}
-	
+
     override Dsymbol syntaxCopy(Dsymbol s)
 	{
 		FuncDeclaration f;
@@ -271,7 +271,7 @@
 
 		return f;
 	}
-	
+
 	// Do the semantic analysis on the external interface to the function.
     override void semantic(Scope sc)
 	{
@@ -313,7 +313,7 @@
 	        sc.stc |= storage_class & STC.STCref;	// forward refness to function type
 	        type = type.semantic(loc, sc);
 	        sc = sc.pop();
-            
+
 			/* Apply const, immutable and shared storage class
 			 * to the function type
 			 */
@@ -339,17 +339,17 @@
 				// Don't use toInvariant(), as that will do a merge()
 				type = type.makeInvariant();
 				goto Lmerge;
-	
+
 				case STC.STCconst:
 	            case STC.STCconst | STC.STCwild:
 				type = type.makeConst();
 				goto Lmerge;
-	
+
 				case STC.STCshared | STC.STCconst:
 	            case STC.STCshared | STC.STCconst | STC.STCwild:
 				type = type.makeSharedConst();
 				goto Lmerge;
-	
+
 				case STC.STCshared:
 				type = type.makeShared();
 		        goto Lmerge;
@@ -368,10 +368,10 @@
 					     */
 						type.deco = type.merge().deco;
 				break;
-	
+
 				case STC.STCundefined:
 				break;
-	
+
 				default:
 				assert(0);
 			}
@@ -556,7 +556,7 @@
 
 			// Verify this doesn't override previous final function
 			if (cd.baseClass)
-			{   
+			{
 				Dsymbol s = cd.baseClass.search(loc, ident, 0);
 				if (s)
 				{
@@ -589,7 +589,7 @@
 			return;
 
 			default:
-			{   
+			{
 				FuncDeclaration fdv = cast(FuncDeclaration)cd.vtbl.data[vi];
 			// This function is covariant with fdv
 			if (fdv.isFinal())
@@ -619,7 +619,7 @@
 			}
 			cd.vtbl.data[vi] = cast(void*)this;
 			vtblIndex = vi;
-			
+
 			/* Remember which functions this overrides
 			 */
 			foverrides.push(fdv);
@@ -669,7 +669,7 @@
 			default:
 			{   FuncDeclaration fdv = cast(FuncDeclaration)b.base.vtbl.data[vi];
 				Type ti = null;
-				
+
 				/* Remember which functions this overrides
 				 */
 				foverrides.push(fdv);
@@ -689,7 +689,7 @@
 					if (offset)
 					ti = fdv.type;
 					else if (type.nextOf().ty == Tclass)
-					{   
+					{
 						ClassDeclaration cdn = (cast(TypeClass)type.nextOf()).sym;
 						if (cdn && cdn.sizeok != 1)
 							ti = fdv.type;
@@ -805,7 +805,7 @@
 			}
 		}
 		}
-		
+
 		if (isVirtual())
 		{
 			/* Rewrite contracts as nested functions, then call them.
@@ -813,7 +813,7 @@
 			 * can call them.
 			 */
 			if (frequire)
-			{   
+			{
 				/*   in { ... }
 				 * becomes:
 				 *   void __require() { ... }
@@ -843,7 +843,7 @@
 				auto arguments = new Parameters();
 				Parameter a = null;
 				if (outId)
-				{	
+				{
 					a = new Parameter(STCref, f.nextOf(), outId, null);
 					arguments.push(a);
 				}
@@ -877,7 +877,7 @@
 		}
 		error("identity assignment operator overload is illegal");
 	}
-	
+
     override void semantic2(Scope sc)
 	{
 	}
@@ -923,7 +923,7 @@
 			error("can only throw classes, not %s", t.toChars());
 		}
 		}
-		
+
 	    frequire = mergeFrequire(frequire);
 		fensure = mergeFensure(fensure);
 
@@ -1038,17 +1038,17 @@
 			Type t;
 
 			if (f.linkage == LINK.LINKd)
-			{	
+			{
 				// Declare _arguments[]
 version (BREAKABI) {
-				v_arguments = new VarDeclaration(Loc(0), Type.typeinfotypelist.type, Id._arguments_typeinfo, null);
+				v_arguments = new VarDeclaration(Loc(0), global.typeinfotypelist.type, Id._arguments_typeinfo, null);
 				v_arguments.storage_class = STCparameter;
 				v_arguments.semantic(sc2);
 				sc2.insert(v_arguments);
 				v_arguments.parent = this;
 
 				//t = Type.typeinfo.type.constOf().arrayOf();
-				t = Type.typeinfo.type.arrayOf();
+				t = global.typeinfo.type.arrayOf();
 				_arguments = new VarDeclaration(Loc(0), t, Id._arguments, null);
 				_arguments.semantic(sc2);
 				sc2.insert(_arguments);
@@ -1197,7 +1197,7 @@
 				error("post conditions are not supported if the return type is inferred");
 				return;
 		    }
-			
+
 			ScopeDsymbol sym = new ScopeDsymbol();
 			sym.parent = sc2.scopesym;
 			sc2 = sc2.push(sym);
@@ -1309,7 +1309,7 @@
 		}
 
 		sc2.incontract--;
-		
+
 		if (fbody)
 		{   ClassDeclaration cd = isClassMember();
 
@@ -1319,7 +1319,7 @@
 			{
 				for (int i = 0; i < cd.fields.dim; i++)
 				{   VarDeclaration v = cast(VarDeclaration)cd.fields[i];
-	
+
 					v.ctorinit = 0;
 				}
 			}
@@ -1340,9 +1340,9 @@
 			}
 			f = cast(TypeFunction)type;
 			}
-			
+
 			if (isStaticCtorDeclaration())
-			{	
+			{
 				/* It's a static constructor. Ensure that all
 				 * ctor consts were initialized.
 				 */
@@ -1425,7 +1425,7 @@
 				else
 				{
 					if (offend)
-					{   
+					{
 						Expression e;
 version (DMDV1) {
 						warning(loc, "no return exp; or assert(0); at end of function");
@@ -1646,7 +1646,7 @@
 					{
 						Expression vsync;
 						if (isStatic())
-						{   
+						{
 							// The monitor is in the ClassInfo
 							vsync = new DotIdExp(loc, new DsymbolExp(loc, cd), Id.classinfo_);
 						}
@@ -1672,7 +1672,7 @@
 		}
 		semanticRun = 4;
 	}
-	
+
     // called from semantic3
     void varArgs(Scope sc, TypeFunction, ref VarDeclaration, ref VarDeclaration)
 	{
@@ -1687,7 +1687,7 @@
 		type.toCBuffer(buf, ident, hgs);
 		bodyToCBuffer(buf, hgs);
 	}
-	
+
 	void bodyToCBuffer(OutBuffer buf, HdrGenState* hgs)
 	{
 		if (fbody &&
@@ -1735,7 +1735,7 @@
 			buf.writenl();
 		}
 	}
-	
+
 	/****************************************************
 	 * Determine if 'this' overrides fd.
 	 * Return true if it does.
@@ -1748,7 +1748,7 @@
 		{
 			int cov = type.covariant(fd.type);
 			if (cov)
-			{   
+			{
 				ClassDeclaration cd1 = toParent().isClassDeclaration();
 				ClassDeclaration cd2 = fd.toParent().isClassDeclaration();
 
@@ -1758,7 +1758,7 @@
 		}
 		return result;
 	}
-	
+
 	/*************************************************
 	 * Find index of function in vtbl[0..dim] that
 	 * this function overrides.
@@ -1839,7 +1839,7 @@
 		 * applied yet.
 		 */
 		if (type)
-		{   
+		{
 			printf("type = %s\n", type.toChars());
 			printf("f.type = %s\n", f.type.toChars());
 		}
@@ -1859,7 +1859,7 @@
 		//printf("\ttrue: no conflict\n");
 		return true;
 	}
-	
+
     FuncDeclaration overloadExactMatch(Type t)
 	{
 		Param1 p;
@@ -1868,7 +1868,7 @@
 		overloadApply(this, p);
 		return p.f;
 	}
-	
+
     FuncDeclaration overloadResolve(Loc loc, Expression ethis, Expressions arguments, int flags = 0)
 	{
 		TypeFunction tf;
@@ -1877,11 +1877,11 @@
 static if (false) {
 		printf("FuncDeclaration.overloadResolve('%s')\n", toChars());
 		if (arguments)
-		{   
+		{
 			int i;
 
 			for (i = 0; i < arguments.dim; i++)
-			{   
+			{
 				Expression arg;
 
 				arg = cast(Expression)arguments.data[i];
@@ -1953,7 +1953,7 @@
 			}
 		}
 	}
-	
+
 	/*************************************
 	 * Determine partial specialization order of 'this' vs g.
 	 * This is very similar to TemplateDeclaration.leastAsSpecialized().
@@ -2031,7 +2031,7 @@
 	}
 		return MATCHnomatch;
 	}
-	
+
 	/********************************
 	 * Labels are in a separate scope, one per function.
 	 */
@@ -2051,7 +2051,7 @@
 
 		return cast(LabelDsymbol)s;
 	}
-	
+
 	/****************************************
 	 * If non-static member function that has a 'this' pointer,
 	 * return the aggregate it is a member of.
@@ -2069,7 +2069,7 @@
 		//printf("-FuncDeclaration.isThis() %p\n", ad);
 		return ad;
 	}
-	
+
     AggregateDeclaration isMember2()
 	{
 		AggregateDeclaration ad = null;
@@ -2091,7 +2091,7 @@
 		//printf("-FuncDeclaration.isMember2() %p\n", ad);
 		return ad;
 	}
-	
+
 	/*****************************************
 	 * Determine lexical level difference from 'this' to nested function 'fd'.
 	 * Error if this cannot call fd.
@@ -2117,7 +2117,7 @@
 			//printf("\ts = '%s'\n", s.toChars());
 			FuncDeclaration thisfd = s.isFuncDeclaration();
 			if (thisfd)
-			{   
+			{
 				if (!thisfd.isNested() && !thisfd.vthis)
 					goto Lerr;
 			}
@@ -2125,7 +2125,7 @@
 			{
 				AggregateDeclaration thiscd = s.isAggregateDeclaration();
 				if (thiscd)
-				{	
+				{
 					if (!thiscd.isNested())
 						goto Lerr;
 				}
@@ -2172,7 +2172,7 @@
 
 		return Declaration.mangle();
 	}
-	
+
     override string toPrettyChars()
 	{
 		if (isMain())
@@ -2180,12 +2180,12 @@
 		else
 			return Dsymbol.toPrettyChars();
 	}
-	
+
     int isMain()
 	{
 		return ident is Id.main && linkage != LINK.LINKc && !isMember() && !isNested();
 	}
-	
+
     int isWinMain()
 	{
 		//printf("FuncDeclaration::isWinMain() %s\n", toChars());
@@ -2248,41 +2248,41 @@
 
 		return builtin;
 	}
-	
+
     override bool isExport()
 	{
 		return protection == PROT.PROTexport;
 	}
-	
+
     override bool isImportedSymbol()
 	{
 		//printf("isImportedSymbol()\n");
 		//printf("protection = %d\n", protection);
 		return (protection == PROT.PROTexport) && !fbody;
 	}
-	
+
     override bool isAbstract()
 	{
 		return (storage_class & STC.STCabstract) != 0;
 	}
-	
+
     override bool isCodeseg()
 	{
 		return true;		// functions are always in the code segment
 	}
-	
+
     override bool isOverloadable()
 	{
 		return 1;			// functions can be overloaded
 	}
-	
+
     bool isPure()
 	{
 		//printf("FuncDeclaration::isPure() '%s'\n", toChars());
 		assert(type.ty == TY.Tfunction);
 		return (cast(TypeFunction)this.type).ispure;
 	}
-	
+
 	int isSafe()
 	{
 		assert(type.ty == TY.Tfunction);
@@ -2294,7 +2294,7 @@
 		assert(type.ty == TY.Tfunction);
 		return (cast(TypeFunction)this.type).trust == TRUST.TRUSTtrusted;
 	}
-	
+
     bool isNested()
 	{
 		//if (!toParent())
@@ -2303,7 +2303,7 @@
 		return ((storage_class & STC.STCstatic) == 0) &&
 		   (toParent2().isFuncDeclaration() !is null);
 	}
-	
+
     override bool needThis()
 	{
 		//printf("FuncDeclaration.needThis() '%s'\n", toChars());
@@ -2318,7 +2318,7 @@
 
 		return needThis;
 	}
-	
+
     bool isVirtual()
 	{
 static if (false) {
@@ -2329,7 +2329,7 @@
 }
 		return isMember() && !(isStatic() || protection == PROT.PROTprivate || protection == PROT.PROTpackage) && toParent().isClassDeclaration();
 	}
-	
+
     override bool isFinal()
 	{
 		ClassDeclaration cd;
@@ -2341,7 +2341,7 @@
 }
 		return isMember() && (Declaration.isFinal() || ((cd = toParent().isClassDeclaration()) !is null && cd.storage_class & STC.STCfinal));
 	}
-	
+
     bool addPreInvariant()
 	{
 		AggregateDeclaration ad = isThis();
@@ -2352,24 +2352,24 @@
 			!naked &&
 			ident !is Id.cpctor);
 	}
-	
+
     bool addPostInvariant()
 	{
 		AggregateDeclaration ad = isThis();
-		return (ad && ad.inv && 
+		return (ad && ad.inv &&
 			//ad.isClassDeclaration() &&
 			global.params.useInvariants &&
 			(protection == PROT.PROTpublic || protection == PROT.PROTexport) &&
 			!naked &&
 			ident !is Id.cpctor);
 	}
-	
+
 	/*************************************
 	 * Attempt to interpret a function given the arguments.
 	 * Input:
 	 *	istate     state for calling function (null if none)
 	 *      arguments  function arguments
-	 *      thisarg    'this', if a needThis() function, null if not.	
+	 *      thisarg    'this', if a needThis() function, null if not.
 	 *
 	 * Return result expression if successful, null if not.
 	 */
@@ -2402,12 +2402,12 @@
 				return interpret_values(istate, thisarg, this);
 		}
 }
-	
+
 		if (cantInterpret || semanticRun == 3)
 			return null;
 
 		if (!fbody)
-		{	
+		{
 			cantInterpret = 1;
 			return null;
 		}
@@ -2426,21 +2426,21 @@
 		TypeFunction tf = cast(TypeFunction)tb;
 		Type tret = tf.next.toBasetype();
 		if (tf.varargs && arguments && parameters && arguments.dim != parameters.dim)
-		{	
+		{
 			cantInterpret = 1;
 			error("C-style variadic functions are not yet implemented in CTFE");
 			return null;
 		}
-		
+
 		// Ensure there are no lazy parameters
 		if (tf.parameters)
-		{	
+		{
 			size_t dim = Parameter.dim(tf.parameters);
 			for (size_t i = 0; i < dim; i++)
-			{   
+			{
 				auto arg = Parameter.getNth(tf.parameters, i);
 				if (arg.storageClass & STClazy)
-				{   
+				{
 					cantInterpret = 1;
 					return null;
 				}
@@ -2455,7 +2455,7 @@
 		scope Expressions vsave = new Expressions();		// place to save previous parameter values
 		size_t dim = 0;
 		if (needThis() && !thisarg)
-		{	
+		{
 			cantInterpret = 1;
 			// error, no this. Prevent segfault.
 			error("need 'this' to access member %s", toChars());
@@ -2474,7 +2474,7 @@
 			eargs.setDim(dim);
 
 			for (size_t i = 0; i < dim; i++)
-			{   
+			{
 				Expression earg = arguments[i];
 				auto arg = Parameter.getNth(tf.parameters, i);
 
@@ -2494,7 +2494,7 @@
 					}
 					earg = earg.interpret(istate ? istate : istatex);
 					if (earg is EXP_CANT_INTERPRET)
-					{   
+					{
 						cantInterpret = 1;
 						return null;
 					}
@@ -2503,7 +2503,7 @@
 			}
 
 			for (size_t i = 0; i < dim; i++)
-			{   
+			{
 				auto earg = eargs[i];
 				auto arg = Parameter.getNth(tf.parameters, i);
 				auto v = cast(VarDeclaration)parameters[i];
@@ -2517,11 +2517,11 @@
 					 * variable v2
 					 */
 					if (!istate)
-					{   
+					{
 						cantInterpret = 1;
 						error("%s cannot be by passed by reference at compile time", earg.toChars());
 						return null;	// can't bind to non-interpreted vars
-					}		
+					}
 					// We need to chase down all of the the passed parameters until
 					// we find something that isn't a TOKvar, then create a variable
 					// containg that expression.
@@ -2531,14 +2531,14 @@
 						VarExp ve = cast(VarExp)earg;
 						v2 = ve.var.isVarDeclaration();
 						if (!v2)
-						{   
+						{
 							cantInterpret = 1;
 							return null;
 						}
 						if (!v2.value || v2.value.op != TOKvar)
 							break;
-						if ((cast(VarExp)v2.value).var.isSymbolDeclaration())		   
-						{	
+						if ((cast(VarExp)v2.value).var.isSymbolDeclaration())
+						{
 							// This can happen if v is a struct initialized to
 							// 0 using an __initZ SymbolDeclaration from
 							// TypeStruct.defaultInit()
@@ -2553,17 +2553,17 @@
 					 */
 					assert(istate);
 					foreach(size_t j, Dsymbol s2; istate.vars)// (size_t j = 0; j < istate.vars.dim; j++)
-					{   
+					{
 						auto vd = cast(VarDeclaration)s2;
 						if (vd == v2)
-						{	
+						{
 							istate.vars[j] = null;
 							break;
 						}
 					}
 				}
 				else
-				{	
+				{
 					// Value parameters and non-trivial references
 					v.value = earg;
 				}
@@ -2576,10 +2576,10 @@
 		if (needThis() && thisarg.op == TOKvar && istate) {
 			VarDeclaration thisvar = (cast(VarExp)thisarg).var.isVarDeclaration();
  			foreach (size_t i, Dsymbol s; istate.vars)
-			{   
+			{
 				auto v = cast(VarDeclaration)s;
 				if (v == thisvar)
-				{	
+				{
 					istate.vars[i] = null;
 					break;
 				}
@@ -2594,7 +2594,7 @@
 			//printf("saving local variables...\n");
 			valueSaves.setDim(istate.vars.dim);
 			foreach (size_t i, Dsymbol s3; istate.vars)
-			{   
+			{
 				if (auto v = cast(VarDeclaration)s3)
 				{
 					//printf("\tsaving [%d] %s = %s\n", i, v.toChars(), v.value ? v.value.toChars() : "");
@@ -2644,9 +2644,9 @@
 			 */
 			//printf("restoring local variables...\n");
 			foreach (size_t i , Dsymbol s3; istate.vars)
-			{   
+			{
 				if (auto v = cast(VarDeclaration)s3)
-				{	
+				{
 					v.value = valueSaves[i];
 					//printf("\trestoring [%d] %s = %s\n", i, v.toChars(), v.value ? v.value.toChars() : "");
 				}
@@ -2654,7 +2654,7 @@
 		}
 		return e;
 	}
-	
+
     override void inlineScan()
 	{
 		InlineScanState iss;
@@ -2671,7 +2671,7 @@
 			inlineNest--;
 		}
 	}
-	
+
     int canInline(int hasthis, int hdrscan = 0)
 	{
 		int cost;
@@ -2715,7 +2715,7 @@
 		}
 
 		if (type)
-		{	
+		{
 			assert(type.ty == Tfunction);
 			TypeFunction tf = cast(TypeFunction)type;
 			if (tf.varargs == 1)	// no variadic parameter lists
@@ -2730,7 +2730,7 @@
 					goto Lno;
 		}
 		else
-		{	
+		{
 			CtorDeclaration ctor = isCtorDeclaration();
 			if (ctor && ctor.varargs == 1)
 				goto Lno;
@@ -2826,7 +2826,7 @@
 
 		version (STRUCTTHISREF) {
 			if (ethis.type.ty == Tpointer)
-			{   
+			{
 				Type t = ethis.type.nextOf();
 				ethis = new PtrExp(ethis.loc, ethis);
 				ethis.type = t;
@@ -2859,7 +2859,7 @@
 			ei.exp.type = ve.type;
 		version (STRUCTTHISREF) {
 			if (ethis.type.ty != Tclass)
-			{   
+			{
 				/* This is a reference initialization, not a simple assignment.
 				 */
 				ei.exp.op = TOKconstruct;
@@ -2935,15 +2935,15 @@
 	{
 		assert(false);
 	}
-	
+
 	FuncDeclaration isUnique()
-	{	
+	{
 		Unique unique;
 		overloadApply(this, unique);
-		
+
 		return unique.f;
 	}
-	
+
 	/*******************************
 	 * Look at all the variables in this function that are referenced
 	 * by nested functions, and determine if a closure needs to be
@@ -2967,7 +2967,7 @@
 
 		//printf("FuncDeclaration.needsClosure() %s\n", toChars());
 		foreach (Dsymbol s3; closureVars)
-		{	
+		{
 			auto v = cast(VarDeclaration)s3;
 			assert(v.isVarDeclaration());
 			//printf("\tv = %s\n", v.toChars());
@@ -2996,7 +2996,7 @@
 		//printf("\tneeds closure\n");
 		return true;
 	}
-	
+
     /****************************************************
 	 * Merge into this function the 'in' contracts of all it overrides.
 	 * 'in's are OR'd together, i.e. only one of them needs to pass.
@@ -3035,7 +3035,7 @@
 				Statement s2 = new ExpStatement(loc, e);
 
 				if (sf)
-				{	
+				{
 					Catch c = new Catch(loc, null, null, sf);
 					Array catches = new Array();
 					catches.push(cast(void*)c);
@@ -3087,12 +3087,12 @@
 		}
 		return sf;
 	}
-	
+
     static FuncDeclaration genCfunc(Type treturn, string name)
 	{
 		return genCfunc(treturn, Lexer.idPool(name));
 	}
-	
+
 	/**********************************
 	 * Generate a FuncDeclaration for a runtime library function.
 	 */
@@ -3124,7 +3124,7 @@
 		}
 		return fd;
 	}
-	
+
     override Symbol* toSymbol()
 	{
 		if (!csym)
@@ -3156,12 +3156,12 @@
 				f.Fstartline.Slinnum = loc.linnum;
 				f.Fstartline.Sfilename = cast(char*)toStringz(loc.filename);
 				if (endloc.linnum)
-				{	
+				{
 					f.Fendline.Slinnum = endloc.linnum;
 					f.Fendline.Sfilename = cast(char*)toStringz(endloc.filename);
 				}
 				else
-				{	
+				{
 					f.Fendline.Slinnum = loc.linnum;
 					f.Fendline.Sfilename = cast(char*)toStringz(loc.filename);
 				}
@@ -3227,7 +3227,7 @@
 		}
 		return csym;
 	}
-	
+
     Symbol* toThunkSymbol(int offset)	// thunk version
 	{
 		Symbol *sthunk;
@@ -3256,14 +3256,14 @@
 		cod3_thunk(sthunk, csym, 0, TYnptr, -offset, -1, 0);
 		return sthunk;
 	}
-	
+
     override void toObjFile(int multiobj)			// compile to .obj file
 	{
 		Symbol* s;
 		func_t* f;
 		Symbol* senter;
 		Symbol* sexit;
-		
+
 		FuncDeclaration func = this;
 		ClassDeclaration cd = func.parent.isClassDeclaration();
 		int reverse;
@@ -3286,7 +3286,7 @@
 }
 
 		if (multiobj && !isStaticDtorDeclaration() && !isStaticCtorDeclaration())
-		{	
+		{
 			obj_append(this);
 			return;
 		}
@@ -3294,8 +3294,6 @@
 		if (semanticRun >= 5)	// if toObjFile() already run
 			return;
 
-		semanticRun = 5;
-
 		if (!func.fbody)
 		{
 			return;
@@ -3309,7 +3307,7 @@
 
 		s = func.toSymbol();
 		f = s.Sfunc;
-		
+
 version (TARGET_WINDOS)
 {
     /* This is done so that the 'this' pointer on the stack is the same
@@ -3416,7 +3414,7 @@
 			sprintf(hiddenparam.ptr, "__HID%d".ptr, ++hiddenparami);
 			shidden = symbol_name(hiddenparam.ptr, SC.SCparameter, thidden);
 			shidden.Sflags |= SFL.SFLtrue | SFL.SFLfree;
-			
+
 version (DMDV1) {
 			bool nestedref = func.nrvo_can && func.nrvo_var && func.nrvo_var.nestedref;
 } else {
@@ -3448,9 +3446,9 @@
 			pi += parameters.dim;
 
 		// Allow extra 2 for sthis and shidden
-		version (Bug4054)
+version (Bug4054)
 		params = cast(Symbol**)GC.malloc((pi + 2) * (Symbol*).sizeof);
-		else
+else
 		params = cast(Symbol**)alloca((pi + 2) * (Symbol*).sizeof);
 
 		// Get the actual number of parameters, pi, and fill in the params[]
@@ -3464,7 +3462,7 @@
 		{
 			size_t i = 0;
 			for ( ; i < parameters.dim; ++i)
-			{   
+			{
 				auto v = cast(VarDeclaration)parameters[i];
 
 				if (v.csym)
@@ -3478,10 +3476,10 @@
 		}
 
 		if (reverse)
-		{	
+		{
 			// Reverse params[] entries
 			for (size_t i = 0; i < pi/2; i++)
-			{   
+			{
 				Symbol* sptmp = params[i];
 				params[i] = params[pi - 1 - i];
 				params[pi - 1 - i] = sptmp;
@@ -3526,7 +3524,7 @@
 		}
 
 		for (size_t i = 0; i < pi; i++)
-		{	
+		{
 			Symbol *sp = params[i];
 			sp.Sclass = SC.SCparameter;
 			sp.Sflags &= ~SFL.SFLspill;
@@ -3539,7 +3537,7 @@
 		{
 			Symbol* sp = params[0];
 			if ((tyf == TYM.TYjfunc || tyf == TYM.TYmfunc) && type_jparam(sp.Stype))
-			{   
+			{
 				sp.Sclass = SC.SCfastpar;
 				sp.Spreg = (tyf == TYM.TYjfunc) ? REG.AX : REG.CX;
 				sp.Sfl = FL.FLauto;
@@ -3548,7 +3546,7 @@
 		}
 
 		if (func.fbody)
-		{  
+		{
 			block* b;
 			Blockx bx;
 			Statement sbody;
@@ -3572,7 +3570,7 @@
 			if (func.isSynchronized())
 			{
 				if (cd)
-				{	
+				{
 					elem *esync;
 					if (func.isStatic())
 					{   // monitor is in ClassInfo
@@ -3637,7 +3635,7 @@
 						b.Belem = el_combine(b.Belem, el_var(sthis));
 					}
 				}
-			} 
+			}
 		}
 
 		// If static constructor
@@ -3660,7 +3658,7 @@
 			StaticDtorDeclaration f2 = isStaticDtorDeclaration();
 			assert(f2);
 			if (f2.vgate)
-			{   
+			{
 				/* Increment destructor's vgate at construction time
 				 */
 				ectorgates.push(cast(void*)f2);
@@ -3682,7 +3680,7 @@
 			return;
 
 		writefunc(s);
-		
+
 		if (isExport()) {
 			obj_export(s, Poffset);
 		}
@@ -3700,19 +3698,19 @@
 		}
 }
 version (DMDV2) {
-		if (irs.startaddress) 
+		if (irs.startaddress)
 		{
 			writef("Setting start address\n");
 			obj_startaddress(irs.startaddress);
 		}
 }
 	}
-	
+
     override int cvMember(ubyte* p)
 	{
 		assert(false);
 	}
-	
+
 	/*************************************
 	 * Closures are implemented by taking the local variables that
 	 * need to survive the scope of the function, and copying them
@@ -3735,7 +3733,7 @@
     void buildClosure(IRState* irs)
 	{
 		if (needsClosure())
-		{   
+		{
 			// Generate closure on the heap
 			// BUG: doesn't capture variadic arguments passed to this function
 
@@ -3762,7 +3760,7 @@
 
 			uint offset = PTRSIZE;	// leave room for previous sthis
 			foreach (Dsymbol s3; closureVars)
-			{   
+			{
 				auto v = cast(VarDeclaration)s3;
 				assert(v.isVarDeclaration());
 
@@ -3843,7 +3841,7 @@
 				ex = el_bin(OPER.OPadd, TYM.TYnptr, el_var(sclosure), el_long(TYM.TYint, v.offset));
 				ex = el_una(OPER.OPind, tym, ex);
 				if (ex.Ety == TYM.TYstruct)
-				{   
+				{
 					ex.Enumbytes = cast(uint)v.type.size();
 					ex = el_bin(OPER.OPstreq, tym, ex, el_var(v.toSymbol()));
 					ex.Enumbytes = cast(uint)v.type.size();
@@ -3892,4 +3890,4 @@
     override FuncDeclaration isFuncDeclaration() { return this; }
 }
 
-alias Vector!FuncDeclaration FuncDeclarations;
\ No newline at end of file
+alias Vector!FuncDeclaration FuncDeclarations;
--- a/dmd/Global.d	Sun Oct 10 01:55:35 2010 +0400
+++ b/dmd/Global.d	Sun Oct 10 03:47:23 2010 +0400
@@ -98,6 +98,27 @@
 
 	// Used in TemplateMixin
 	int nest;
+	
+	// Used in Type
+	StringTable type_stringtable;
+	
+	ClassDeclaration typeinfo;
+    ClassDeclaration typeinfoclass;
+    ClassDeclaration typeinfointerface;
+    ClassDeclaration typeinfostruct;
+    ClassDeclaration typeinfotypedef;
+    ClassDeclaration typeinfopointer;
+    ClassDeclaration typeinfoarray;
+    ClassDeclaration typeinfostaticarray;
+    ClassDeclaration typeinfoassociativearray;
+    ClassDeclaration typeinfoenum;
+    ClassDeclaration typeinfofunction;
+    ClassDeclaration typeinfodelegate;
+    ClassDeclaration typeinfotypelist;
+    ClassDeclaration typeinfoconst;
+    ClassDeclaration typeinfoinvariant;
+    ClassDeclaration typeinfoshared;
+    ClassDeclaration typeinfowild;
 
 	this()
 	{
@@ -111,6 +132,8 @@
 		modules = new DsymbolTable();
 		amodules = new Array();
 		deferred = new Array();
+		
+		type_stringtable = new StringTable();
 
 		init_time();
 	}
--- a/dmd/Identifier.d	Sun Oct 10 01:55:35 2010 +0400
+++ b/dmd/Identifier.d	Sun Oct 10 03:47:23 2010 +0400
@@ -5,8 +5,11 @@
 import dmd.DYNCAST;
 import dmd.Lexer;
 import dmd.Global;
+import dmd.Id;
 import dmd.OutBuffer;
 
+import std.string;
+
 class Identifier
 {
     TOK value;
@@ -17,40 +20,40 @@
 		this.string_ = string_;
 		this.value = value;
 	}
-	
+
     bool equals(Object o)
 	{
 		if (this is o) {
 			return true;
 		}
-		
+
 		if (auto i = cast(Identifier)o) {
 			return string_ == i.string_;
 		}
-		
+
 		return false;
 	}
-	
+
     hash_t hashCode()
 	{
 		assert(false);
 	}
-	
+
     override int opCmp(Object o)
 	{
 		assert(false);
 	}
-	
+
     void print()
 	{
 		assert(false);
 	}
-	
+
     string toChars()
 	{
 		return string_;
 	}
-	
+
 version (_DH) {
     char* toHChars()
 	{
@@ -59,9 +62,31 @@
 }
     string toHChars2()
 	{
-		assert(false);
+		string p;
+
+		if (this == Id.ctor) p = "this";
+		else if (this == Id.dtor) p = "~this";
+		else if (this == Id.classInvariant) p = "invariant";
+		else if (this == Id.unitTest) p = "unittest";
+		else if (this == Id.dollar) p = "$";
+		else if (this == Id.withSym) p = "with";
+		else if (this == Id.result) p = "result";
+		else if (this == Id.returnLabel) p = "return";
+		else
+		{
+			p = toChars();
+			if (p.length != 0 && p[0] == '_')
+			{
+				if (p.startsWith("_staticCtor"))
+                    p = "static this";
+				else if (p.startsWith("_staticDtor"))
+                    p = "static ~this";
+			}
+		}
+
+		return p;
 	}
-	
+
     DYNCAST dyncast()
 	{
 		return DYNCAST.DYNCAST_IDENTIFIER;
@@ -72,7 +97,7 @@
 	{
 		return generateId(prefix, ++global.i);
 	}
-	
+
     static Identifier generateId(string prefix, size_t i)
 	{
 		scope OutBuffer buf = new OutBuffer();
--- a/dmd/IfStatement.d	Sun Oct 10 01:55:35 2010 +0400
+++ b/dmd/IfStatement.d	Sun Oct 10 03:47:23 2010 +0400
@@ -157,7 +157,28 @@
 	
     override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
 	{
-		assert(false);
+		buf.writestring("if (");
+		if (arg)
+		{
+			if (arg.type)
+				arg.type.toCBuffer(buf, arg.ident, hgs);
+			else
+			{   
+				buf.writestring("auto ");
+				buf.writestring(arg.ident.toChars());
+			}
+			buf.writestring(" = ");
+		}
+		condition.toCBuffer(buf, hgs);
+		buf.writebyte(')');
+		buf.writenl();
+		ifbody.toCBuffer(buf, hgs);
+		if (elsebody)
+		{   
+			buf.writestring("else");
+			buf.writenl();
+			elsebody.toCBuffer(buf, hgs);
+		}
 	}
 	
     override bool usesEH()
--- a/dmd/Import.d	Sun Oct 10 01:55:35 2010 +0400
+++ b/dmd/Import.d	Sun Oct 10 03:47:23 2010 +0400
@@ -102,7 +102,7 @@
 	
 	void load(Scope sc)
 	{
-		//writef("Import::load('%s')\n", toChars());
+		//writefln("Import::load('%s')", id.toChars());
 
 		// See if existing module
 		DsymbolTable dst = Package.resolve(packages, null, &pkg);
--- a/dmd/Lexer.d	Sun Oct 10 01:55:35 2010 +0400
+++ b/dmd/Lexer.d	Sun Oct 10 03:47:23 2010 +0400
@@ -654,7 +654,7 @@
 	];
 }
 
-	static ubyte cmtable[256];
+	static __gshared ubyte cmtable[256];
 	enum CMoctal =	0x1;
 	enum  CMhex =	0x2;
 	enum  CMidchar =	0x4;
--- a/dmd/Module.d	Sun Oct 10 01:55:35 2010 +0400
+++ b/dmd/Module.d	Sun Oct 10 03:47:23 2010 +0400
@@ -103,7 +103,7 @@
 	UNKNOWN	= -1,	/* unknown segment		*/
 }
 
-struct seg_data 
+struct seg_data
 {
     int              SDseg;		// omf file segment index
     targ_size_t		 SDoffset;	// starting offset for data
@@ -146,7 +146,7 @@
 	CFpsw	       = 0x40,	// we need the flags result after this instruction
 	CFopsize       = 0x80,	// prefix with operand size
 	CFaddrsize    = 0x100, 	// prefix with address size
-	CFds	      = 0x200,	// need DS override (not with es, ss, or cs )	
+	CFds	      = 0x200,	// need DS override (not with es, ss, or cs )
 	CFcs	      = 0x400,	// need CS override
 	CFfs	      = 0x800,	// need FS override
 	CFgs	= (CFcs | CFfs),	// need GS override
@@ -222,10 +222,10 @@
 	{
 		super(ident);
 		FileName objfilename;
-		
+
 		aimports = new Array();
 
-	    //writef("Module.Module(filename = '%s', ident = '%s')\n", filename, ident.toChars());
+	    //writefln("Module.Module(filename = '%s', ident = '%s')", filename, ident.toChars());
 		this.arg = filename;
 
 		FileName srcfilename = FileName.defaultExt(filename, global.mars_ext);
@@ -267,6 +267,7 @@
 
 		FileName symfilename = FileName.forceExt(filename, global.sym_ext);
 
+		//writeln(srcfilename.toChars());
 		srcfile = new File(srcfilename);
 
 		if (doDocComment) {
@@ -296,10 +297,9 @@
 		if (packages && packages.dim)
 		{
 			scope OutBuffer buf = new OutBuffer();
-			int i;
 
 			foreach (pid; packages)
-			{   
+			{
 				buf.writestring(pid.toChars());
 version (Windows)
 {
@@ -324,7 +324,7 @@
 		FileName fd  = FileName.forceExt(filename, global.mars_ext);
 		string sdi = fdi.toChars();
 		string sd  = fd.toChars();
-		
+
 		if (FileName.exists(sdi)) {
 			result = sdi;
 		} else if (FileName.exists(sd)) {
@@ -353,8 +353,10 @@
 			}
 		}
 
-		if (result)
+		if (result) {
+			writeln("loading ", result);
 			m.srcfile = new File(result);
+		}
 
 		if (global.params.verbose)
 		{
@@ -362,7 +364,7 @@
 			if (packages)
 			{
 				foreach (pid; packages)
-				{   
+				{
 					writef("%s.", pid.toChars());
 				}
 			}
@@ -383,7 +385,7 @@
 	{
 		assert(false);
 	}
-    
+
     override void toJsonBuffer(OutBuffer buf)
     {
 		buf.writestring("{\n");
@@ -417,27 +419,27 @@
 
 		buf.writestring("}\n");
 	}
-	
+
     override string kind()
 	{
 		return "module";
 	}
-	
+
     void setDocfile()	// set docfile member
 	{
 		assert(false);
 	}
-	
+
     void read(Loc loc)	// read file
 	{
-		//writef("Module.read('%s') file '%s'\n", toChars(), srcfile.toChars());
+		//writefln("Module.read('%s') file '%s'", toChars(), srcfile.toChars());
 		if (srcfile.read())
 		{
 			error(loc, "cannot read file '%s'", srcfile.toChars());
 			fatal();
 		}
 	}
-	
+
 version (IN_GCC) {
     void parse(bool dump_source = false)	// syntactic parse
 	{
@@ -487,7 +489,7 @@
 
 			dbuf.reserve(buflen / 4);
 			for (pu += bom; pu < pumax; pu++)
-			{  
+			{
 				uint u = le ? readlongLE(pu) : readlongBE(pu);
 				if (u & ~0x7F)
 				{
@@ -505,7 +507,7 @@
 			buf = cast(ubyte*) dbuf.extractData();
 			}
 			else
-			{   
+			{
 				// UTF-16LE (X86)
 				// Convert it to UTF-8
 				le = 1;
@@ -620,7 +622,7 @@
 		}
 
 version (IN_GCC) {
-		// dump utf-8 encoded source 
+		// dump utf-8 encoded source
 		if (dump_source)
 		{	// %% srcname could contain a path ...
 			d_gcc_dump_source(srcname, "utf-8", buf, buflen);
@@ -678,7 +680,7 @@
 			if (!Lexer.isValidIdentifier(this.ident.toChars()))
 				error("has non-identifier characters in filename, use module declaration instead");
 			}
-			
+
 			// Update global list of modules
 			if (!dst.insert(this))
 			{
@@ -697,7 +699,7 @@
 	override void importAll(Scope prevsc)
 	{
 		//writef("+Module.importAll(this = %p, '%s'): parent = %p\n", this, toChars(), parent);
-	
+
 		if (scope_ !is null)
 			return;			// already done
 
@@ -707,7 +709,7 @@
 		 * Ignore prevsc.
 		 */
 		Scope sc = Scope.createGlobal(this);	// create root scope
-	
+
 		// Add import of "object" if this module isn't "object"
 		if (ident != Id.object)
 		{
@@ -726,7 +728,7 @@
 				s.addMember(null, sc.scopesym, 1);
 		}
 		// anything else should be run after addMember, so version/debug symbols are defined
-	
+
 		/* Set scope for the symbols so that if we forward reference
 		 * a symbol, it can possibly be resolved on the spot.
 		 * If this works out well, it can be extended to all modules
@@ -735,10 +737,10 @@
 		setScope(sc);		// remember module scope for semantic
 		foreach (Dsymbol s; members)
 			s.setScope(sc);
-	
+
 		foreach (Dsymbol s; members)
 			s.importAll(sc);
-	
+
 		sc = sc.pop();
 		sc.pop();		// 2 pops because Scope::createGlobal() created 2
 	}
@@ -775,7 +777,7 @@
 		// Add all symbols into module's symbol table
 		symtab = new DsymbolTable();
 		foreach(s; members)
-		{	
+		{
 			s.addMember(null, sc.scopesym, true);
 		}
 
@@ -790,7 +792,7 @@
 
 		// Pass 1 semantic routines: do public side of the definition
 		foreach (Dsymbol s; members)
-		{	
+		{
 			//writef("\tModule('%s'): '%s'.semantic()\n", toChars(), s.toChars());
 			s.semantic(sc);
 			runDeferredSemantic();
@@ -804,7 +806,7 @@
 		semanticRun = semanticstarted;
 		//printf("-Module.semantic(this = %p, '%s'): parent = %p\n", this, toChars(), parent);
 	}
-	
+
     void semantic2()	// pass 2 semantic analysis
 	{
 		auto deferred = global.deferred;
@@ -839,7 +841,7 @@
 		semanticRun = semanticstarted;
 		//printf("-Module.semantic2('%s'): parent = %p\n", toChars(), parent);
 	}
-	
+
     void semantic3()	// pass 3 semantic analysis
 	{
 		//printf("Module.semantic3('%s'): parent = %p\n", toChars(), parent);
@@ -856,7 +858,7 @@
 
 		// Pass 3 semantic routines: do initializers and function bodies
 		foreach(Dsymbol s; members)
-		{	
+		{
 			//printf("Module %s: %s.semantic3()\n", toChars(), s.toChars());
 			s.semantic3(sc);
 		}
@@ -865,7 +867,7 @@
 		sc.pop();
 		semanticRun = semanticstarted;
 	}
-	
+
     override void inlineScan()	// scan for functions to inline
 	{
 		if (semanticstarted >= 4)
@@ -880,7 +882,7 @@
 		//printf("Module = %p\n", sc.scopesym);
 
 		foreach(Dsymbol s; members)
-		{	
+		{
 			//if (global.params.verbose)
 				//printf("inline scan symbol %s\n", s.toChars());
 			s.inlineScan();
@@ -888,7 +890,7 @@
 
 		semanticRun = semanticstarted;
 	}
-	
+
     void setHdrfile()	// set hdrfile member
 	{
 		FileName hdrfilename;
@@ -901,7 +903,7 @@
 		else
 			arghdr = FileName.name(arg);
 		if (!FileName.absolute(arghdr))
-		{	
+		{
 			//FileName.ensurePathExists(global.params.hdrdir);
 			arghdr = FileName.combine(global.params.hdrdir, arghdr);
 		}
@@ -911,21 +913,21 @@
 			hdrfilename = FileName.forceExt(arghdr, global.hdr_ext);
 
 		if (hdrfilename.str == srcfile.name.str)
-		{   
+		{
 			error("Source file and 'header' file have same name '%s'", srcfile.name.str);
 			fatal();
 		}
 
 		hdrfile = new File(hdrfilename);
 	}
-	
+
 version (_DH) {
     void genhdrfile()  // generate D import file
 	{
 		assert(false);
 	}
 }
-	
+
 	/**************************************
 	 * Generate .obj file for Module.
 	 */
@@ -998,10 +1000,10 @@
 
 			covb = cast(uint*)GC.calloc(((numlines + 32) / 32) * (*covb).sizeof);
 		}
-		
+
 		foreach(Dsymbol member; members)
 			member.toObjFile(multiobj);
-		
+
 		if (global.params.cov)
 		{
 			/* Generate
@@ -1081,7 +1083,7 @@
 				cstate.CSpsymtab = &sctor.Sfunc.Flocsym;
 
 				for (int i = 0; i < ectorgates.dim; i++)
-				{	
+				{
 					StaticDtorDeclaration f = cast(StaticDtorDeclaration)ectorgates.data[i];
 
 					Symbol* s = f.vgate.toSymbol();
@@ -1188,27 +1190,27 @@
 				writefunc(ma);
 			}
 		}
-		
+
 
 static if (true) {
 		// Always generate module info, because of templates and -cov
 		if (1 || needModuleInfo())
 			genmoduleinfo();
 }
-		
+
 		obj_termfile();
 	}
-	
+
     void gensymfile()
 	{
 		assert(false);
 	}
-	
+
     void gendocfile()
 	{
 		assert(false);
 	}
-	
+
 	/**********************************
 	 * Determine if we need to generate an instance of ModuleInfo
 	 * for this Module.
@@ -1218,7 +1220,7 @@
     	// writef("needModuleInfo() %s, %d, %d\n", toChars(), needmoduleinfo, global.params.cov);
 		return needmoduleinfo || global.params.cov;
 	}
-	
+
     override Dsymbol search(Loc loc, Identifier ident, int flags)
 	{
 		/* Since modules can be circularly referenced,
@@ -1247,7 +1249,7 @@
 		}
 		return s;
 	}
-	
+
     void deleteObjFile()
 	{
 		if (global.params.obj)
@@ -1280,7 +1282,7 @@
 	    //printf("Module::addDeferredSemantic('%s')\n", s.toChars());
 	    deferred.push(cast(void*)s);
 	}
-	
+
 	/******************************************
 	 * Run semantic() on deferred symbols.
 	 */
@@ -1291,11 +1293,11 @@
 			return;
 		//if (deferred.dim) printf("+Module.runDeferredSemantic('%s'), len = %d\n", toChars(), deferred.dim);
 		global.nested++;
-		
+
 		size_t len;
 
 		auto deferred = global.deferred;
-		
+
 		do
 		{
 			global.dprogress = 0;
@@ -1424,7 +1426,7 @@
 	{
 		assert(false);
 	}
-	
+
     elem* toEfilename()
 	{
 		elem* efilename;
@@ -1455,7 +1457,7 @@
 		efilename = el_var(sfilename);
 		return efilename;
 	}
-	
+
 	/**************************************
 	 * Generate elem that is a pointer to the module file name.
 	 */
@@ -1465,7 +1467,7 @@
 
 		// Get filename
 		if (needModuleInfo())
-		{   
+		{
 			/* Class ModuleInfo is defined in std.moduleinfo.
 			 * The first member is the name of it, char name[],
 			 * which will be at offset 8.
@@ -1516,7 +1518,7 @@
 		Symbol* msym = toSymbol();
 
 		//dumpSymbol(msym);
-		
+
 		uint offset;
 	version (DMDV2) {
 		uint sizeof_ModuleInfo = 18 * PTRSIZE;
@@ -1551,7 +1553,7 @@
 		if (global.moduleinfo)
 			dtxoff(&dt, global.moduleinfo.toVtblSymbol(), 0, TYM.TYnptr); // vtbl for ModuleInfo
 		else
-		{	
+		{
 			//printf("moduleinfo is null\n");
 			dtdword(&dt, 0);		// BUG: should be an assert()
 		}
@@ -1567,7 +1569,7 @@
 
 		//printf("members.dim = %d\n", members.dim);
 		foreach(Dsymbol member; members)
-		{	
+		{
 			//printf("\tmember '%s'\n", member.toChars());
 			member.addLocalClass(aclasses);
 		}
@@ -1575,7 +1577,7 @@
 		// importedModules[]
 		int aimports_dim = aimports.dim;
 		for (int i = 0; i < aimports.dim; i++)
-		{	
+		{
 			Module m = cast(Module)aimports.data[i];
 			if (!m.needModuleInfo())
 				aimports_dim--;
@@ -1637,11 +1639,11 @@
 		//////////////////////////////////////////////
 
 		for (int i = 0; i < aimports.dim; i++)
-		{	
+		{
 			Module m = cast(Module)aimports.data[i];
 
 			if (m.needModuleInfo())
-			{   
+			{
 				Symbol* s = m.toSymbol();
 
 				/* Weak references don't pull objects in from the library,
--- a/dmd/ModuleDeclaration.d	Sun Oct 10 01:55:35 2010 +0400
+++ b/dmd/ModuleDeclaration.d	Sun Oct 10 03:47:23 2010 +0400
@@ -3,6 +3,7 @@
 import dmd.common;
 import dmd.Identifier;
 import dmd.ArrayTypes;
+import dmd.OutBuffer;
 
 class ModuleDeclaration
 {
@@ -19,6 +20,17 @@
 
     string toChars()
 	{
-		assert(false);
+		scope OutBuffer buf = new OutBuffer();
+		if (packages)
+		{
+			foreach (pid; packages)
+			{
+                buf.writestring(pid.toChars());
+				buf.writeByte('.');
+			}
+		}
+		buf.writestring(id.toChars());
+		buf.writeByte(0);
+		return buf.extractString();
 	}
-}
\ No newline at end of file
+}
--- a/dmd/NewExp.d	Sun Oct 10 01:55:35 2010 +0400
+++ b/dmd/NewExp.d	Sun Oct 10 03:47:23 2010 +0400
@@ -7,6 +7,7 @@
 import dmd.ClassDeclaration;
 import dmd.Type;
 import dmd.OutBuffer;
+import dmd.PREC;
 import dmd.Loc;
 import dmd.Scope;
 import dmd.IRState;
@@ -92,7 +93,7 @@
 
 	Lagain:
 		if (thisexp)
-		{	
+		{
 			thisexp = thisexp.semantic(sc);
 			cdthis = thisexp.type.isClassHandle();
 			if (cdthis)
@@ -122,7 +123,7 @@
 			error("e.new is only for allocating nested classes, not %s", tb.toChars());
 
 		if (tb.ty == Tclass)
-		{	
+		{
 			TypeFunction tf;
 
 			TypeClass tc = cast(TypeClass)tb;
@@ -130,10 +131,10 @@
 			if (cd.isInterfaceDeclaration())
 				error("cannot create instance of interface %s", cd.toChars());
 			else if (cd.isAbstract())
-			{   
+			{
 				error("cannot create instance of abstract class %s", cd.toChars());
 				for (int j = 0; j < cd.vtbl.dim; j++)
-				{	
+				{
 					FuncDeclaration fd = (cast(Dsymbol)cd.vtbl.data[j]).isFuncDeclaration();
 					if (fd && fd.isAbstract())
 						error("function %s is abstract", fd.toChars());
@@ -156,7 +157,7 @@
 						// Supply an implicit 'this' and try again
 						thisexp = new ThisExp(loc);
 						for (Dsymbol sp = sc.parent; 1; sp = sp.parent)
-						{	
+						{
 							if (!sp)
 							{
 								error("outer class %s 'this' needed to 'new' nested class %s", cdn.toChars(), cd.toChars());
@@ -217,7 +218,7 @@
 				}
 	///} else {
 	///			else if (fdn)
-	///			{	
+	///			{
 	///				/* The nested class cd is nested inside a function,
 	///				 * we'll let getEthis() look for errors.
 	///				 */
@@ -342,7 +343,7 @@
 			for (size_t j = 0; j < arguments.dim; j++)
 			{
 				if (tb.ty != Tarray)
-				{	
+				{
 					error("too many arguments for array");
 					arguments.dim = i;
 					break;
@@ -386,7 +387,7 @@
 		if (newargs)
 		{
 			foreach (ref Expression e; newargs)
-			{   
+			{
 				e = e.optimize(WANTvalue);
 			}
 		}
@@ -394,7 +395,7 @@
 		if (arguments)
 		{
 			foreach (ref Expression e; arguments)
-			{   
+			{
 				e = e.optimize(WANTvalue);
 			}
 		}
@@ -432,7 +433,7 @@
 			elem *ez = null;
 
 			if (allocator || onstack)
-			{   
+			{
 				elem *ei;
 				Symbol *si;
 
@@ -501,7 +502,7 @@
 			}
 
 			if (thisexp)
-			{   
+			{
 				ClassDeclaration cdthis = thisexp.type.isClassHandle();
 				assert(cdthis);
 				//printf("cd = %s\n", cd.toChars());
@@ -515,7 +516,7 @@
 				//printf("cdp = %s\n", cdp.toChars());
 				//printf("cdthis = %s\n", cdthis.toChars());
 				if (cdp != cdthis)
-				{	
+				{
 					int i = cdp.isClassDeclaration().isBaseOf(cdthis, &offset);
 					assert(i);
 				}
@@ -538,7 +539,7 @@
 				//printf("ez: "); elem_print(ez);
 			}
 			else if (cd.isNested())
-			{   
+			{
 				/* Initialize cd.vthis:
 				 *	*(ey + cd.vthis.offset) = this;
 				 */
@@ -572,7 +573,7 @@
 			elem* ez = null;
 
 			if (allocator)
-			{   
+			{
 				elem *ei;
 				Symbol *si;
 
@@ -592,7 +593,7 @@
 					ez = el_same(&ex);
 
 				if (!member)
-				{	
+				{
 					/* Statically intialize with default initializer
 					 */
 					ex = el_una(OPind, TYstruct, ex);
@@ -633,7 +634,7 @@
 			}
 
 			if (cd.isNested())
-			{   
+			{
 				/* Initialize cd.vthis:
 				 *	*(ey + cd.vthis.offset) = this;
 				 */
@@ -641,7 +642,7 @@
 			}
 
 			if (member)
-			{   
+			{
 				// Call constructor
 				ez = callfunc(loc, irs, 1, type, ez, ectype, member, member.type, null, arguments);
 		version (STRUCTTHISREF) {
@@ -661,7 +662,7 @@
 
 			assert(arguments && arguments.dim >= 1);
 			if (arguments.dim == 1)
-			{   
+			{
 				// Single dimension array allocations
 				auto arg = arguments[0];	// gives array length
 				e = arg.toElem(irs);
@@ -673,7 +674,7 @@
 				e = el_bin(OPcall,TYdarray,el_var(rtlsym[rtl]),e);
 			}
 			else
-			{   
+			{
 				// Multidimensional array allocations
 				e = el_long(TYint, arguments.dim);
 				foreach (Expression arg; arguments)
@@ -725,7 +726,27 @@
 
 	override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
 	{
-		assert(false);
+		int i;
+
+		if (thisexp)
+		{
+			expToCBuffer(buf, hgs, thisexp, PREC.PREC_primary);
+			buf.writeByte('.');
+		}
+		buf.writestring("new ");
+		if (newargs && newargs.dim)
+		{
+			buf.writeByte('(');
+			argsToCBuffer(buf, newargs, hgs);
+			buf.writeByte(')');
+		}
+		newtype.toCBuffer(buf, null, hgs);
+		if (arguments && arguments.dim)
+		{
+			buf.writeByte('(');
+			argsToCBuffer(buf, arguments, hgs);
+			buf.writeByte(')');
+		}
 	}
 
 	override void scanForNestedRef(Scope sc)
@@ -744,7 +765,7 @@
 		return 1;
 	}
 }
-	
+
 	//int inlineCost(InlineCostState *ics);
 
 	override Expression doInline(InlineDoState ids)
@@ -758,7 +779,7 @@
 		ne.arguments = arrayExpressiondoInline(ne.arguments, ids);
 		return ne;
 	}
-	
+
 	//Expression inlineScan(InlineScanState *iss);
 }
 
--- a/dmd/OnScopeStatement.d	Sun Oct 10 01:55:35 2010 +0400
+++ b/dmd/OnScopeStatement.d	Sun Oct 10 03:47:23 2010 +0400
@@ -11,6 +11,7 @@
 import dmd.BE;
 import dmd.Identifier;
 import dmd.ExpInitializer;
+import dmd.Token;
 import dmd.IntegerExp;
 import dmd.VarDeclaration;
 import dmd.Type;
@@ -31,7 +32,7 @@
     this(Loc loc, TOK tok, Statement statement)
 	{
 		super(loc);
-		
+
 		this.tok = tok;
 		this.statement = statement;
 	}
@@ -51,7 +52,9 @@
 
     override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
 	{
-		assert(false);
+		buf.writestring(Token.toChars(tok));
+		buf.writebyte(' ');
+		statement.toCBuffer(buf, hgs);
 	}
 
     override Statement semantic(Scope sc)
--- a/dmd/PostExp.d	Sun Oct 10 01:55:35 2010 +0400
+++ b/dmd/PostExp.d	Sun Oct 10 03:47:23 2010 +0400
@@ -9,6 +9,7 @@
 import dmd.Loc;
 import dmd.Scope;
 import dmd.IRState;
+import dmd.PREC;
 import dmd.BinExp;
 import dmd.HdrGenState;
 import dmd.IntegerExp;
@@ -17,6 +18,8 @@
 import dmd.TY;
 import dmd.Id;
 
+import dmd.expression.Util;
+
 import dmd.backend.Util;
 import dmd.backend.OPER;
 
@@ -60,7 +63,8 @@
 
 	override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
 	{
-		assert(false);
+		expToCBuffer(buf, hgs, e1, precedence[op]);
+		buf.writestring((op == TOKplusplus) ? "++" : "--");
 	}
 
 	override Identifier opId()
--- a/dmd/PtrExp.d	Sun Oct 10 01:55:35 2010 +0400
+++ b/dmd/PtrExp.d	Sun Oct 10 03:47:23 2010 +0400
@@ -16,6 +16,7 @@
 import dmd.GlobalExpressions;
 import dmd.SymOffExp;
 import dmd.AddrExp;
+import dmd.PREC;
 import dmd.VarDeclaration;
 import dmd.StructLiteralExp;
 import dmd.TypePointer;
@@ -85,12 +86,12 @@
 	{
 		return 1;
 	}
-    
+
     override void checkEscapeRef()
     {
         e1.checkEscape();
     }
-    
+
 	override Expression toLvalue(Scope sc, Expression e)
 	{
 static if (false) {
@@ -110,7 +111,7 @@
 		//printf("PtrExp.modifiableLvalue() %s, type %s\n", toChars(), type.toChars());
 
 		if (e1.op == TOKsymoff)
-		{	
+		{
 			SymOffExp se = cast(SymOffExp)e1;
 			se.var.checkModify(loc, sc, type);
 			//return toLvalue(sc, e);
@@ -121,7 +122,8 @@
 }
 	override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
 	{
-		assert(false);
+		buf.writeByte('*');
+		expToCBuffer(buf, hgs, e1, precedence[op]);
 	}
 
 	override elem* toElem(IRState* irs)
@@ -147,7 +149,7 @@
 		e1 = e1.optimize(result);
 		// Convert *&ex to ex
 		if (e1.op == TOK.TOKaddress)
-		{	
+		{
 			Expression e;
 			Expression ex;
 
@@ -171,12 +173,12 @@
 		}
 
 		if (e1.op == TOK.TOKsymoff)
-		{	
+		{
 			SymOffExp se = cast(SymOffExp)e1;
 			VarDeclaration v = se.var.isVarDeclaration();
 			Expression e = expandVar(result, v);
 			if (e && e.op == TOK.TOKstructliteral)
-			{   
+			{
 				StructLiteralExp sle = cast(StructLiteralExp)e;
 				e = sle.getField(type, se.offset);
 				if (e && e !is EXP_CANT_INTERPRET)
--- a/dmd/Statement.d	Sun Oct 10 01:55:35 2010 +0400
+++ b/dmd/Statement.d	Sun Oct 10 03:47:23 2010 +0400
@@ -25,6 +25,8 @@
 import dmd.GlobalExpressions;
 import dmd.Util;
 
+import std.stdio;
+
 //! startup code used in *Statement.interpret() functions
 enum START = `
 	if (istate.start)
@@ -53,17 +55,21 @@
 	{
 		assert(false);
 	}
-	
+
     string toChars()
 	{
-		assert(false);
+		/*scope*/ OutBuffer buf = new OutBuffer();
+		HdrGenState hgs;
+
+		toCBuffer(buf, &hgs);
+		return buf.toChars();
 	}
 
     void error(T...)(string format, T t)
 	{
 		.error(loc, format, t);
 	}
-	
+
     void warning(T...)(string format, T t)
 	{
 		if (global.params.warnings && !global.gag)
@@ -93,7 +99,7 @@
 	{
 		assert(false);
 	}
-	
+
     Statement semanticScope(Scope sc, Statement sbreak, Statement scontinue)
 	{
 		Scope scd;
@@ -108,43 +114,43 @@
 		scd.pop();
 		return s;
 	}
-	
+
     bool hasBreak()
 	{
 		assert(false);
 	}
-	
+
     bool hasContinue()
 	{
 		assert(false);
 	}
-	
+
 	// TRUE if statement uses exception handling
-	
+
     bool usesEH()
 	{
 		return false;
 	}
-	
+
     BE blockExit()
 	{
 		assert(false);
 	}
-	
+
 	// true if statement 'comes from' somewhere else, like a goto
     bool comeFrom()
 	{
 		//printf("Statement::comeFrom()\n");
 		return false;
 	}
-	
+
 	// Return TRUE if statement has no code in it
     bool isEmpty()
 	{
 		//printf("Statement::isEmpty()\n");
 		return false;
 	}
-	
+
 	/****************************************
 	 * If this statement has code that needs to run in a finally clause
 	 * at the end of the current scope, return that code in the form of
@@ -162,7 +168,7 @@
 		*sexception = null;
 		*sfinally = null;
 	}
-	
+
 	/*********************************
 	 * Flatten out the scope by presenting the statement
 	 * as an array of statements.
@@ -172,7 +178,7 @@
 	{
 		return null;
 	}
-	
+
 	/***********************************
 	 * Interpret the statement.
 	 * Returns:
@@ -194,26 +200,26 @@
 	{
 		return COST_MAX;		// default is we can't inline it
 	}
-	
+
     Expression doInline(InlineDoState ids)
 	{
 		assert(false);
 	}
-	
+
     Statement inlineScan(InlineScanState* iss)
 	{
 		return this;
 	}
-	
+
     // Back end
     void toIR(IRState* irs)
 	{
 		assert(false);
 	}
-	
+
     // Avoid dynamic_cast
     DeclarationStatement isDeclarationStatement() { return null; }
     CompoundStatement isCompoundStatement() { return null; }
     ReturnStatement isReturnStatement() { return null; }
     IfStatement isIfStatement() { return null; }
-}
\ No newline at end of file
+}
--- a/dmd/StringEntry.d	Sun Oct 10 01:55:35 2010 +0400
+++ b/dmd/StringEntry.d	Sun Oct 10 03:47:23 2010 +0400
@@ -14,10 +14,16 @@
     hash_t hash;
 
     StringValue value;
+	
+	this(StringEntry* other)
+	{
+		hash = other.hash;
+		value = other.value;
+	}
 
 	this(immutable(dchar_t)[] s)
 	{
 		hash = Dchar.calcHash(s.ptr, s.length);
 		value.lstring.string_ = s;
 	}
-}
\ No newline at end of file
+}
--- a/dmd/StringTable.d	Sun Oct 10 01:55:35 2010 +0400
+++ b/dmd/StringTable.d	Sun Oct 10 03:47:23 2010 +0400
@@ -10,6 +10,8 @@
 
 import core.memory;
 
+import std.stdio;
+
 class StringTable
 {
     void** table;
@@ -23,7 +25,7 @@
 		tabledim = size;
 		count = 0;
 	}
-	
+
     ~this()
 	{
 		/// TODO: is it *really* needed?
@@ -39,16 +41,16 @@
 
     StringValue* lookup(immutable(dchar_t)[] s)
 	{
-		StringEntry* se = *cast(StringEntry**)search(s);
+		StringEntry* se = *search(s);
 		if (se !is null)
 			return &se.value;
 		else
 			return null;
 	}
-	
+
     StringValue* insert(immutable(dchar_t)[] s)
 	{
-		StringEntry** pse = cast(StringEntry**)search(s);
+		StringEntry** pse = search(s);
 		StringEntry* se = *pse;
 		if (se !is null)
 			return null;		// error: already in table
@@ -56,28 +58,58 @@
 		{
 			se = new StringEntry(s);
 			*pse = se;
+			++count;
 		}
 
 		return &se.value;
 	}
 	
+	void insertCopy(StringEntry* proto)
+	{
+		StringEntry** pse = search(proto.value.lstring.string_);
+		StringEntry* se = *pse;
+		if (se is null)
+		{
+			se = new StringEntry(proto);
+			*pse = se;
+			++count;
+		}
+	}
+
     StringValue* update(immutable(dchar_t)[] s)
 	{
-		StringEntry **pse;
-		StringEntry *se;
-
-		pse = cast(StringEntry**)search(s);
-		se = *pse;
+		StringEntry** pse = search(s);
+		StringEntry* se = *pse;
 		if (se is null)			// not in table: so create new entry
 		{
 			se = new StringEntry(s);
 			*pse = se;
+			++count;
 		}
 		return &se.value;
 	}
 
+	void copyTo(StringTable stringTable)
+	{
+		for (int u = 0; u < tabledim; ++u) {
+			StringEntry** se = cast(StringEntry**)&table[u];
+			copyNode(*se, stringTable);
+		}
+	}
+
 private:
-    void** search(immutable(dchar_t)[] s)
+	void copyNode(StringEntry* node, StringTable stringTable)
+	{
+		if (node is null) {
+			return;
+		}
+
+		copyNode(node.left, stringTable);
+		stringTable.insertCopy(node);
+		copyNode(node.right, stringTable);
+	}
+
+    StringEntry** search(immutable(dchar_t)[] s)
 	{
 		int cmp;
 
@@ -106,6 +138,6 @@
 		}
 
 		//printf("\treturn %p, %p\n",se, (*se));
-		return cast(void**)se;
+		return se;
 	}
-}
\ No newline at end of file
+}
--- a/dmd/SwitchStatement.d	Sun Oct 10 01:55:35 2010 +0400
+++ b/dmd/SwitchStatement.d	Sun Oct 10 03:47:23 2010 +0400
@@ -305,7 +305,25 @@
 	
     override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
 	{
-		assert(false);
+		buf.writestring("switch (");
+		condition.toCBuffer(buf, hgs);
+		buf.writebyte(')');
+		buf.writenl();
+		if (body_)
+		{
+			if (!body_.isScopeStatement())
+			{   
+				buf.writebyte('{');
+				buf.writenl();
+				body_.toCBuffer(buf, hgs);
+				buf.writebyte('}');
+				buf.writenl();
+			}
+			else
+			{
+				body_.toCBuffer(buf, hgs);
+			}
+		}
 	}
 
     override Statement inlineScan(InlineScanState* iss)
--- a/dmd/SymOffExp.d	Sun Oct 10 01:55:35 2010 +0400
+++ b/dmd/SymOffExp.d	Sun Oct 10 03:47:23 2010 +0400
@@ -73,7 +73,10 @@
 
 	override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
 	{
-		assert(false);
+		if (offset)
+			buf.printf("(& %s+%s)", var.toChars(), offset); ///
+		else
+			buf.printf("& %s", var.toChars());
 	}
 
 	override int isConst()
--- a/dmd/ThrowStatement.d	Sun Oct 10 01:55:35 2010 +0400
+++ b/dmd/ThrowStatement.d	Sun Oct 10 03:47:23 2010 +0400
@@ -57,7 +57,10 @@
 	
     override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
 	{
-		assert(false);
+		buf.printf("throw ");
+		exp.toCBuffer(buf, hgs);
+		buf.writeByte(';');
+		buf.writenl();
 	}
 	
     override BE blockExit()
--- a/dmd/Token.d	Sun Oct 10 01:55:35 2010 +0400
+++ b/dmd/Token.d	Sun Oct 10 03:47:23 2010 +0400
@@ -46,7 +46,7 @@
     real float80value; // can't use this in a union!
 }
 
-    static string tochars[TOK.TOKMAX];
+    static __gshared string tochars[TOK.TOKMAX];
 ///    static void *operator new(size_t sz);
 
     int isKeyword()
@@ -61,10 +61,10 @@
 	
     string toChars()
 	{
-		static char buffer[3 + 3 * value.sizeof + 1];
-
 		string p;
-
+		
+		char buffer[3 + 3 * value.sizeof + 1];
+		
 		switch (value)
 		{
 		case TOK.TOKint32v:
@@ -202,7 +202,8 @@
     static string toChars(TOK value)
 	{
 		string p;
-		static char buffer[3 + 3 * value.sizeof + 1];
+		
+		char buffer[3 + 3 * value.sizeof + 1];
 
 		p = tochars[value];
 		if (!p)
--- a/dmd/TryCatchStatement.d	Sun Oct 10 01:55:35 2010 +0400
+++ b/dmd/TryCatchStatement.d	Sun Oct 10 03:47:23 2010 +0400
@@ -206,7 +206,15 @@
 	
     override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
 	{
-		assert(false);
+		buf.writestring("try");
+		buf.writenl();
+		if (body_)
+			body_.toCBuffer(buf, hgs);
+		for (size_t i = 0; i < catches.dim; i++)
+		{
+			Catch c = cast(Catch)catches.data[i];
+			c.toCBuffer(buf, hgs);
+		}
 	}
 	
     override TryCatchStatement isTryCatchStatement() { return this; }
--- a/dmd/TryFinallyStatement.d	Sun Oct 10 01:55:35 2010 +0400
+++ b/dmd/TryFinallyStatement.d	Sun Oct 10 03:47:23 2010 +0400
@@ -37,7 +37,12 @@
 	
     override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
 	{
-		assert(false);
+		buf.printf("try\n{\n");
+		body_.toCBuffer(buf, hgs);
+		buf.printf("}\nfinally\n{\n");
+		finalbody.toCBuffer(buf, hgs);
+		buf.writeByte('}');
+		buf.writenl();
 	}
 	
     override Statement semantic(Scope sc)
--- a/dmd/Type.d	Sun Oct 10 01:55:35 2010 +0400
+++ b/dmd/Type.d	Sun Oct 10 03:47:23 2010 +0400
@@ -79,10 +79,10 @@
  * adjusted for 64 bit code.
  */
 
-int PTRSIZE = 4;
-
-int Tsize_t;
-int Tptrdiff_t;
+__gshared int PTRSIZE = 4;
+
+__gshared int Tsize_t;
+__gshared int Tptrdiff_t;
 
 /* REALSIZE = size a real consumes in memory
  * REALPAD = 'padding' added to the CPU real size to bring it up to REALSIZE
@@ -90,16 +90,16 @@
  */
 version (TARGET_OSX) {
 	extern(C++) __gshared int REALSIZE = 16;
-	int REALPAD = 6;
-	int REALALIGNSIZE = 16;
+	__gshared int REALPAD = 6;
+	__gshared int REALALIGNSIZE = 16;
 } else version (POSIX) { /// TARGET_LINUX || TARGET_FREEBSD || TARGET_SOLARIS
 	extern(C++) __gshared int REALSIZE = 12;
-	int REALPAD = 2;
-	int REALALIGNSIZE = 4;
+	__gshared int REALPAD = 2;
+	__gshared int REALALIGNSIZE = 4;
 } else {
 	extern(C++) __gshared int REALSIZE = 10;
-	int REALPAD = 0;
-	int REALALIGNSIZE = 2;
+	__gshared int REALPAD = 0;
+	__gshared int REALALIGNSIZE = 2;
 }
 
 /****
@@ -110,7 +110,7 @@
 int templateIdentifierLookup(Identifier id, TemplateParameters parameters)
 {
     foreach (size_t i, TemplateParameter tp; parameters)
-    {   
+    {
 		if (tp.ident.equals(id))
 			return i;
     }
@@ -259,32 +259,13 @@
 
     type* ctype;	// for back end
 
-    static ClassDeclaration typeinfo;
-    static ClassDeclaration typeinfoclass;
-    static ClassDeclaration typeinfointerface;
-    static ClassDeclaration typeinfostruct;
-    static ClassDeclaration typeinfotypedef;
-    static ClassDeclaration typeinfopointer;
-    static ClassDeclaration typeinfoarray;
-    static ClassDeclaration typeinfostaticarray;
-    static ClassDeclaration typeinfoassociativearray;
-    static ClassDeclaration typeinfoenum;
-    static ClassDeclaration typeinfofunction;
-    static ClassDeclaration typeinfodelegate;
-    static ClassDeclaration typeinfotypelist;
-    static ClassDeclaration typeinfoconst;
-    static ClassDeclaration typeinfoinvariant;
-    static ClassDeclaration typeinfoshared;
-    static ClassDeclaration typeinfowild;
-
-    static Type basic[TY.TMAX];
-    static ubyte mangleChar[TY.TMAX];
-    static ubyte sizeTy[TY.TMAX];
-    static StringTable stringtable;
+    static __gshared Type basic[TY.TMAX];
+    static __gshared ubyte mangleChar[TY.TMAX];
+    static __gshared ubyte sizeTy[TY.TMAX];
 
     // These tables are for implicit conversion of binary ops;
     // the indices are the type of operand one, followed by operand two.
-    static ubyte impcnvResult[TY.TMAX][TY.TMAX] = [
+    static __gshared ubyte impcnvResult[TY.TMAX][TY.TMAX] = [
 		[37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37],
 		[37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37],
 		[37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37],
@@ -330,7 +311,7 @@
 		[37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37],
 	];
 
-    static ubyte impcnvType1[TY.TMAX][TY.TMAX] = [
+    static __gshared ubyte impcnvType1[TY.TMAX][TY.TMAX] = [
 		[37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37],
 		[37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37],
 		[37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37],
@@ -375,8 +356,8 @@
 		[37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37],
 		[37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37],
 	];
-	
-    static ubyte impcnvType2[TY.TMAX][TY.TMAX] = [
+
+    static __gshared ubyte impcnvType2[TY.TMAX][TY.TMAX] = [
 		[37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37],
 		[37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37],
 		[37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37],
@@ -423,7 +404,7 @@
 	];
 
     // If !=0, give warning on implicit conversion
-    static const(bool) impcnvWarn[TY.TMAX][TY.TMAX] = [
+    static __gshared const(bool) impcnvWarn[TY.TMAX][TY.TMAX] = [
 		[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
 		[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
 		[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
@@ -468,22 +449,12 @@
 		[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
 		[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
 	];
-	
-	static this()
-	{
-		stringtable = new StringTable();
-	}
-	
-	static ~this()
-	{
-		delete stringtable;
-	}
 
     this(TY ty)
 	{
 		this.ty = ty;
 	}
-	
+
     Type syntaxCopy()
 	{
 		assert(false);
@@ -502,7 +473,7 @@
 		//if (deco && t && t.deco) printf("deco = '%s', t.deco = '%s'\n", deco, t.deco);
 		return 0;
 	}
-	
+
     DYNCAST dyncast() { return DYNCAST.DYNCAST_TYPE; } // kludge for template.isType()
 
 	/*******************************
@@ -548,7 +519,7 @@
 				goto Ldistinct;
 
 			for (size_t i = 0; i < dim; i++)
-			{   
+			{
 				auto arg1 = Parameter.getNth(t1.parameters, i);
 				auto arg2 = Parameter.getNth(t2.parameters, i);
 
@@ -662,12 +633,12 @@
 		toCBuffer(buf, null, &hgs);
 		return buf.toChars();
 	}
-	
+
     static char needThisPrefix()
 	{
 		return 'M';		// name mangling prefix for functions needing 'this'
 	}
-	
+
     static void init()
 	{
 		Lexer.initKeywords();
@@ -752,7 +723,7 @@
 		}
 }
 		// Set basic types
-		static TY[] basetab = [
+		enum TY[] basetab = [
 			TY.Tvoid, TY.Tint8, TY.Tuns8, TY.Tint16, TY.Tuns16, TY.Tint32, TY.Tuns32, TY.Tint64, TY.Tuns64,
 			TY.Tfloat32, TY.Tfloat64, TY.Tfloat80,
 			TY.Timaginary32, TY.Timaginary64, TY.Timaginary80,
@@ -798,18 +769,18 @@
 			Tptrdiff_t = TY.Tint32;
 		}
 	}
-	
+
     ulong size()
 	{
 		return size(Loc(0));
 	}
-	
+
     ulong size(Loc loc)
 	{
 		error(loc, "no size for type %s", toChars());
 		return 1;
 	}
-	
+
     uint alignsize()
 	{
 		return cast(uint)size(Loc(0));	///
@@ -819,7 +790,7 @@
 	{
 		return merge();
 	}
-	
+
     Type trySemantic(Loc loc, Scope sc)
 	{
 		uint errors = global.errors;
@@ -847,7 +818,7 @@
 		}
 		buf.writeByte(mangleChar[ty]);
 	}
-	
+
     Type merge()
 	{
 		Type t = this;
@@ -861,7 +832,7 @@
 			//if (next)
 				//next = next.merge();
 			toDecoBuffer(buf);
-			StringValue* sv = stringtable.update(buf.extractString());
+			StringValue* sv = global.type_stringtable.update(buf.extractString());
 			if (sv.ptrvalue)
 			{
 				t = cast(Type) sv.ptrvalue;
@@ -894,9 +865,9 @@
 		if (!t.deco)
 			return t.merge();
 
-		StringValue* sv = stringtable.lookup(t.deco);
+		StringValue* sv = global.type_stringtable.lookup(t.deco);
 		if (sv && sv.ptrvalue)
-		{   
+		{
 			t = cast(Type)sv.ptrvalue;
 			assert(t.deco);
 		}
@@ -919,7 +890,7 @@
     void toCBuffer2(OutBuffer buf, HdrGenState* hgs, MOD mod)
 	{
 		if (mod != this.mod)
-		{	
+		{
 			toCBuffer3(buf, hgs, mod);
 			return;
 		}
@@ -971,47 +942,47 @@
 	{
 		return false;
 	}
-	
+
     bool isfloating()	// real, imaginary, or complex
 	{
 		return false;
 	}
-	
+
     bool isreal()
 	{
 		return false;
 	}
-	
+
     bool isimaginary()
 	{
 		return false;
 	}
-	
+
     bool iscomplex()
 	{
 		return false;
 	}
-	
+
     bool isscalar()
 	{
 		return false;
 	}
-	
+
     bool isunsigned()
 	{
 		return false;
 	}
-	
+
     bool isauto()
 	{
 		return false;
 	}
-	
+
     bool isString()
 	{
 		return false;
 	}
-	
+
 	/**************************
 	 * Given:
 	 *	T a, b;
@@ -1023,7 +994,7 @@
 	{
 		return true;
 	}
-	
+
     bool checkBoolean()	// if can be converted to boolean value
 	{
 		return isscalar();
@@ -1048,7 +1019,7 @@
 	int isShared()	{ return mod & MOD.MODshared; }
 
 	int isSharedConst()	{ return mod == (MOD.MODshared | MOD.MODconst); }
-            
+
     int isWild()	{ return mod & MOD.MODwild; }
 
     int isSharedWild()	{ return mod == (MOD.MODshared | MOD.MODwild); }
@@ -1080,7 +1051,7 @@
 	 * Convert to 'immutable'.
 	 */
     Type invariantOf()
-	{	
+	{
 		//printf("Type.invariantOf() %p %s\n", this, toChars());
 		if (isImmutable())
 		{
@@ -1103,7 +1074,7 @@
 		//printf("Type.mutableOf() %p, %s\n", this, toChars());
 		Type t = this;
 		if (isConst())
-		{	
+		{
 			if (isShared())
 				t = sto;		// shared const => shared
 			else
@@ -1111,7 +1082,7 @@
 			assert(!t || t.isMutable());
 		}
 		else if (isImmutable())
-		{	
+		{
 			t = ito;
 			assert(!t || (t.isMutable() && !t.isShared()));
 		}
@@ -1219,14 +1190,14 @@
 	        t.swto = null;
 			t.vtinfo = null;
 			t = t.merge();
-	
+
 			t.fixTo(this);
 		}
 		assert(!t.isShared());
 		return t;
 	}
 
-            
+
     /********************************
      * Convert to 'wild'.
      */
@@ -1431,7 +1402,7 @@
 		L5:
 			t.scto = this;
 			break;
-            
+
 	    case X(MOD.MODwild, MOD.MODundefined):
 	        wto = null;
 	        goto L6;
@@ -1490,7 +1461,7 @@
 		t.check();
 		//printf("fixTo: %s, %s\n", toChars(), t.toChars());
 	}
-	
+
 	/***************************
 	 * Look for bugs in constructing types.
 	 */
@@ -1542,7 +1513,7 @@
 	        if (wto) assert(wto.mod == MOD.MODwild);
 	        if (swto) assert(swto.mod == (MOD.MODshared | MOD.MODwild));
 			break;
-            
+
 	    case MOD.MODwild:
 	        if (cto) assert(cto.mod == MOD.MODconst);
 	        if (ito) assert(ito.mod == MOD.MODimmutable);
@@ -1641,7 +1612,7 @@
 		}
 		return t;
 	}
-	
+
 	/************************************
 	 * Add MODxxxx bits to existing type.
 	 * We're adding, not replacing, so adding const to
@@ -1684,7 +1655,7 @@
 				case MOD.MODshared | MOD.MODconst:
 					t = sharedConstOf();
 					break;
-                
+
 	            case MOD.MODwild:
 		            if (isConst())
                     {}
@@ -1701,7 +1672,7 @@
 		}
 		return t;
 	}
-	
+
     Type addStorageClass(StorageClass stc)
 	{
 		/* Just translate to MOD bits and let addMod() do the work
@@ -1711,7 +1682,7 @@
 		if (stc & STC.STCimmutable)
 			mod = MOD.MODimmutable;
 		else
-		{	
+		{
 			if (stc & (STC.STCconst | STC.STCin))
 				mod = MOD.MODconst;
 			if (stc & STC.STCshared)
@@ -1722,7 +1693,7 @@
 
 		return addMod(mod);
 	}
-	
+
     Type pointerTo()
 	{
 		if (pto is null)
@@ -1733,7 +1704,7 @@
 
 		return pto;
 	}
-	
+
     Type referenceTo()
 	{
 		assert(false);
@@ -1761,17 +1732,17 @@
 		return cloneTo(new Type(ty));
 	}
 }
-	
+
     Type arrayOf()
 	{
 		if (!arrayof)
-		{	
+		{
 			Type t = new TypeDArray(this);
 			arrayof = t.merge();
 		}
 		return arrayof;
 	}
-	
+
     Type makeConst()
 	{
 		//printf("Type.makeConst() %p, %s\n", this, toChars());
@@ -1780,7 +1751,7 @@
 
 		Type t = clone();
 		t.mod = MOD.MODconst;
-		
+
 		t.deco = null;
 		t.arrayof = null;
 		t.pto = null;
@@ -1792,11 +1763,11 @@
         t.wto = null;
         t.swto = null;
 		t.vtinfo = null;
-		
+
 		//printf("-Type.makeConst() %p, %s\n", t, toChars());
 		return t;
 	}
-	
+
     Type makeInvariant()
 	{
 		if (ito) {
@@ -1820,7 +1791,7 @@
 
 		return t;
 	}
-	
+
     Type makeShared()
 	{
 		if (sto)
@@ -1843,7 +1814,7 @@
 
 		return t;
 	}
-	
+
     Type makeSharedConst()
 	{
 		if (scto)
@@ -1866,12 +1837,12 @@
 
 		return t;
 	}
-	
+
     Type makeWild()
     {
         if (wto)
 	        return wto;
-        
+
         Type t = clone();
         t.mod = MOD.MODwild;
         t.deco = null;
@@ -1892,7 +1863,7 @@
     {
         if (swto)
 	        return swto;
-        
+
         Type t = clone();
         t.mod = MOD.MODshared | MOD.MODwild;
         t.deco = null;
@@ -1926,7 +1897,7 @@
         t.vtinfo = null;
         return t;
     }
-    
+
     Dsymbol toDsymbol(Scope sc)
 	{
 		return null;
@@ -1936,12 +1907,12 @@
 	 * If this is a shell around another type,
 	 * get that other type.
 	 */
-		
+
     Type toBasetype()
 	{
 		return this;
 	}
-	
+
 	/**************************
 	 * Return type with the top level of it being mutable.
 	 */
@@ -1952,12 +1923,12 @@
 
 		return mutableOf();
 	}
-	
+
     bool isBaseOf(Type t, int* poffset)
 	{
 		return false;		// assume not
 	}
-	
+
 	/*******************************
 	 * Determine if converting 'this' to 'to' is an identity operation,
 	 * a conversion to const operation, or the types aren't the same.
@@ -1974,7 +1945,7 @@
 			return MATCH.MATCHconst;
 		return MATCH.MATCHnomatch;
 	}
-	
+
 	/********************************
 	 * Determine if 'this' can be implicitly converted
 	 * to type 'to'.
@@ -1991,7 +1962,7 @@
 
 		return MATCHnomatch;
 	}
-	
+
     ClassDeclaration isClassHandle()
 	{
 		return null;
@@ -2032,7 +2003,7 @@
 		else if (ident is Id.mangleof_)
 		{
 			string s;
-			if (!deco) {  
+			if (!deco) {
 				s = toChars();
 				error(loc, "forward reference of type %s.mangleof", s);
 			} else {
@@ -2044,7 +2015,7 @@
 			e = e.semantic(sc);
 		}
 		else if (ident is Id.stringof_)
-		{	
+		{
 			string s = toChars();
 			e = new StringExp(loc, s, 'c');
 			scope Scope sc = new Scope();
@@ -2057,7 +2028,7 @@
 		}
 		return e;
 	}
-	
+
     Expression dotExp(Scope sc, Expression e, Identifier ident)
 	{
 		VarDeclaration v = null;
@@ -2134,18 +2105,18 @@
 			e = getTypeInfo(sc);
 		}
 		else if (ident is Id.stringof_)
-		{		
+		{
 			string s = e.toChars();
 			e = new StringExp(e.loc, s, 'c');
 		}
         else
     	    e = getProperty(e.loc, ident);
-        
+
 Lreturn:
         e = e.semantic(sc);
         return e;
 	}
-	
+
     /***************************************
      * Figures out what to do with an undefined member reference
      * for classes and structs.
@@ -2214,12 +2185,12 @@
 
         return Type.dotExp(sc, e, ident);
     }
-    
+
     uint memalign(uint salign)
 	{
 		return salign;
 	}
-	
+
     Expression defaultInit(Loc loc)
 	{
 		version (LOGDEFAULTINIT) {
@@ -2227,12 +2198,13 @@
 		}
 		return null;
 	}
-	
+
     /***************************************
      * Use when we prefer the default initializer to be a literal,
      * rather than a global immutable variable.
      */
-    Expression defaultInitLiteral(Loc loc = Loc(0))
+    //Expression defaultInitLiteral(Loc loc = Loc(0))
+    Expression defaultInitLiteral(Loc loc)
     {
 version(LOGDEFAULTINIT) {
         printf("Type::defaultInitLiteral() '%s'\n", toChars());
@@ -2245,14 +2217,14 @@
 	{
 		assert(false);
 	}
-	
+
     dt_t** toDt(dt_t** pdt)
 	{
 		//printf("Type.toDt()\n");
 		Expression e = defaultInit(Loc(0));
 		return e.toDt(pdt);
 	}
-	
+
     Identifier getTypeInfoIdent(int internal)
 	{
 		// _init_10TypeInfo_%s
@@ -2262,7 +2234,7 @@
 		int len;
 
 		if (internal)
-		{	
+		{
 			buf.writeByte(mangleChar[ty]);
 			if (ty == TY.Tarray)
 				buf.writeByte(mangleChar[(cast(TypeArray)this).next.ty]);
@@ -2288,7 +2260,7 @@
 		id = Lexer.idPool(name[0..len-1].idup);
 		return id;
 	}
-	
+
 	/* These form the heart of template argument deduction.
 	 * Given 'this' being the type argument to the template instance,
 	 * it is matched against the template declaration parameter specialization
@@ -2353,7 +2325,7 @@
 
 			// 5*5 == 25 cases
 			static pure int X(int U, int T) { return ((U << 4) | T); }
-			
+
 			switch (X(tparam.mod, mod))
 			{
 				case X(0, 0):
@@ -2532,6 +2504,8 @@
 		*ps = null;
 	}
 	
+	static __gshared TypeInfoDeclaration internalTI[TMAX];
+
 	/*******************************************
 	 * Get a canonicalized form of the TypeInfo for use with the internal
 	 * runtime library routines. Canonicalized in that static arrays are
@@ -2544,7 +2518,6 @@
 		TypeInfoDeclaration tid;
 		Expression e;
 		Type t;
-		static TypeInfoDeclaration internalTI[TMAX];
 
 		//printf("Type.getInternalTypeInfo() %s\n", toChars());
 		t = toBasetype();
@@ -2575,7 +2548,7 @@
 			Linternal:
 				tid = internalTI[t.ty];
 				if (!tid)
-				{	
+				{
 					tid = new TypeInfoDeclaration(t, 1);
 					internalTI[t.ty] = tid;
 				}
@@ -2590,7 +2563,7 @@
 		//printf("\tcalling getTypeInfo() %s\n", t.toChars());
 		return t.getTypeInfo(sc);
 	}
-	
+
 	/****************************************************
 	 * Get the exact TypeInfo.
 	 */
@@ -2625,10 +2598,10 @@
 			 * do not generate a COMDAT for it.
 			 */
 			if (!t.builtinTypeInfo())
-			{   
+			{
 				// Generate COMDAT
 				if (sc)			// if in semantic() pass
-				{	
+				{
 					// Find module that will go all the way to an object file
 					Module m = sc.module_.importedFrom;
 					m.members.push(t.vtinfo);
@@ -2644,13 +2617,13 @@
 		e.type = t.vtinfo.type;		// do this so we don't get redundant dereference
 		return e;
 	}
-	
+
     TypeInfoDeclaration getTypeInfoDeclaration()
 	{
 		//printf("Type.getTypeInfoDeclaration() %s\n", toChars());
 		return new TypeInfoDeclaration(this, 0);
 	}
-	
+
 	/* These decide if there's an instance for them already in std.typeinfo,
 	 * because then the compiler doesn't need to build one.
 	 */
@@ -2658,7 +2631,7 @@
 	{
 		return false;
 	}
-	
+
 	/*******************************
 	 * If one of the subtypes of this type is a TypeIdentifier,
 	 * i.e. it's an unresolved type, return that type.
@@ -2667,7 +2640,7 @@
 	{
 		return null;
 	}
-	
+
     /***************************************
      * Return !=0 if the type or any of its subtypes is wild.
      */
@@ -2685,12 +2658,12 @@
     {
         return 0;
     }
-    
+
     Expression toExpression()
 	{
 		assert(false);
 	}
-	
+
 	/***************************************
 	 * Return true if type has pointers that need to
 	 * be scanned by the GC during a collection cycle.
@@ -2699,7 +2672,7 @@
 	{
 		return false;
 	}
-	
+
 	/*************************************
 	 * If this is a type of something, return that something.
 	 */
@@ -2707,7 +2680,7 @@
 	{
 		return null;
 	}
-	
+
 	/****************************************
 	 * Return the mask that an integral type will
 	 * fit into.
@@ -2735,12 +2708,12 @@
 		}
 		return m;
 	}
-	
+
     static void error(T...)(Loc loc, string format, T t)
 	{
 		.error(loc, format, t);
 	}
-	
+
     static void warning(T...)(Loc loc, string format, T t)
 	{
 		assert(false);
@@ -2847,7 +2820,7 @@
 
 		return t;
 	}
-	
+
 	/***************************************
 	 * Convert from D type to C type.
 	 * This is done so C debug info can be generated.
@@ -2861,17 +2834,17 @@
 		}
 		return ctype;
 	}
-	
+
     type* toCParamtype()
 	{
 		return toCtype();
 	}
-	
+
     Symbol* toSymbol()
 	{
 		assert(false);
 	}
-	
+
     // For eliminating dynamic_cast
     TypeBasic isTypeBasic()
 	{
@@ -2992,7 +2965,7 @@
 	{
 		return basic[TY.Tdchar];
 	}
-	
+
 	// Some special types
     static Type tshiftcnt()
 	{
@@ -3004,14 +2977,14 @@
 	{
 		return tbool;		// result of boolean expression
 	}
-	
+
     static Type tindex()
 	{
 		return tint32;		// array/ptr index
 	}
-	
-    static Type tvoidptr;		// void*
-    static Type tstring;		// immutable(char)[]
+
+    static __gshared Type tvoidptr;		// void*
+    static __gshared Type tstring;		// immutable(char)[]
 
 	static Type terror()
 	{
@@ -3022,12 +2995,12 @@
 	{
 		return basic[Tsize_t];		// matches size_t alias
 	}
-	
+
     static Type tptrdiff_t()
 	{
 		return basic[Tptrdiff_t];	// matches ptrdiff_t alias
 	}
-	
+
     static Type thash_t()
 	{
 		return tsize_t;			// matches hash_t alias
--- a/dmd/TypeAArray.d	Sun Oct 10 01:55:35 2010 +0400
+++ b/dmd/TypeAArray.d	Sun Oct 10 03:47:23 2010 +0400
@@ -414,6 +414,13 @@
 		assert(false);
 	}
 }
+	// Dumb linear symbol table - should use associative array!
+	static __gshared Array sarray;
+	
+	shared static this()
+	{
+		sarray = new Array();
+	}
 
     // Back end
 	/********************************************
@@ -441,9 +448,6 @@
 		Symbol* s;
 		int i;
 
-		// Dumb linear symbol table - should use associative array!
-		static Array sarray = null;
-
 		//printf("aaGetSymbol(func = '%s', flags = %d, key = %p)\n", func, flags, key);
 	static if (false) {
 		scope OutBuffer buf = new OutBuffer();
@@ -467,8 +471,6 @@
 		id = cast(char*)alloca(3 + strlen(func) + 1);
 		sprintf(id, "_aa%s", func);
 	}
-		if (!sarray)
-			sarray = new Array();
 
 		// See if symbol is already in sarray
 		for (i = 0; i < sarray.dim; i++)
@@ -498,6 +500,8 @@
 		sarray.push(s);			// remember it
 		return s;
     }
+	
+	static __gshared Symbol* s;
 
     override type* toCtype()
 	{
@@ -512,8 +516,6 @@
 			 *	struct AArray { size_t length; void* ptr; }
 			 */
 
-			static Symbol* s;
-
 			if (!s)
 			{
 				s = symbol_calloc("_AArray");
--- a/dmd/TypeArray.d	Sun Oct 10 01:55:35 2010 +0400
+++ b/dmd/TypeArray.d	Sun Oct 10 03:47:23 2010 +0400
@@ -43,7 +43,8 @@
 			FuncDeclaration fd;
 			Expressions arguments;
 			string nm;
-			static string name[2] = [ "_adReverseChar", "_adReverseWchar" ];
+			
+			enum string name[2] = [ "_adReverseChar", "_adReverseWchar" ];
 
 			nm = name[n.ty == Twchar];
 			fd = FuncDeclaration.genCfunc(Type.tindex, nm);
@@ -60,7 +61,8 @@
 			FuncDeclaration fd;
 			Expressions arguments;
 			string nm;
-			static string name2[2] = [ "_adSortChar", "_adSortWchar" ];
+			
+			enum string name2[2] = [ "_adSortChar", "_adSortWchar" ];
 
 			nm = name2[n.ty == Twchar];
 			fd = FuncDeclaration.genCfunc(Type.tindex, nm);
--- a/dmd/TypeDelegate.d	Sun Oct 10 01:55:35 2010 +0400
+++ b/dmd/TypeDelegate.d	Sun Oct 10 03:47:23 2010 +0400
@@ -170,6 +170,8 @@
 	}
 }
 
+	static __gshared Symbol* s;
+
     override type* toCtype()
 	{
 		type* t;
@@ -183,8 +185,6 @@
 			 *    _Delegate { void* frameptr; Function *funcptr; }
 			 */
 
-			static Symbol* s;
-
 			if (!s)
 			{
 				s = symbol_calloc("_Delegate");
--- a/dmd/TypeInfoArrayDeclaration.d	Sun Oct 10 01:55:35 2010 +0400
+++ b/dmd/TypeInfoArrayDeclaration.d	Sun Oct 10 03:47:23 2010 +0400
@@ -6,6 +6,7 @@
 import dmd.Type;
 import dmd.TY;
 import dmd.TypeDArray;
+import dmd.Global;
 
 import dmd.backend.dt_t;
 import dmd.backend.Util;
@@ -16,13 +17,13 @@
 	this(Type tinfo)
 	{
 		super(tinfo, 0);
-	    type = Type.typeinfoarray.type;
+	    type = global.typeinfoarray.type;
 	}
 
 	override void toDt(dt_t** pdt)
 	{
 		//printf("TypeInfoArrayDeclaration::toDt()\n");
-		dtxoff(pdt, Type.typeinfoarray.toVtblSymbol(), 0, TYnptr); // vtbl for TypeInfo_Array
+		dtxoff(pdt, global.typeinfoarray.toVtblSymbol(), 0, TYnptr); // vtbl for TypeInfo_Array
 		dtdword(pdt, 0);			    // monitor
 
 		assert(tinfo.ty == Tarray);
--- a/dmd/TypeInfoAssociativeArrayDeclaration.d	Sun Oct 10 01:55:35 2010 +0400
+++ b/dmd/TypeInfoAssociativeArrayDeclaration.d	Sun Oct 10 03:47:23 2010 +0400
@@ -2,6 +2,7 @@
 
 import dmd.common;
 import dmd.Type;
+import dmd.Global;
 import dmd.TypeAArray;
 import dmd.TY;
 import dmd.TypeInfoDeclaration;
@@ -14,13 +15,13 @@
 	this(Type tinfo)
 	{
 		super(tinfo, 0);
-	    type = Type.typeinfoassociativearray.type;
+	    type = global.typeinfoassociativearray.type;
 	}
 
 	override void toDt(dt_t** pdt)
 	{
 		//printf("TypeInfoAssociativeArrayDeclaration.toDt()\n");
-		dtxoff(pdt, Type.typeinfoassociativearray.toVtblSymbol(), 0, TYnptr); // vtbl for TypeInfo_AssociativeArray
+		dtxoff(pdt, global.typeinfoassociativearray.toVtblSymbol(), 0, TYnptr); // vtbl for TypeInfo_AssociativeArray
 		dtdword(pdt, 0);			    // monitor
 
 		assert(tinfo.ty == Taarray);
@@ -32,7 +33,7 @@
 
 		tc.index.getTypeInfo(null);
 		dtxoff(pdt, tc.index.vtinfo.toSymbol(), 0, TYnptr); // TypeInfo for array of type
-		
+
 		tc.getImpl().type.getTypeInfo(null);
 	    dtxoff(pdt, tc.getImpl().type.vtinfo.toSymbol(), 0, TYnptr); // impl
 	}
--- a/dmd/TypeInfoClassDeclaration.d	Sun Oct 10 01:55:35 2010 +0400
+++ b/dmd/TypeInfoClassDeclaration.d	Sun Oct 10 03:47:23 2010 +0400
@@ -5,6 +5,7 @@
 import dmd.TypeInfoDeclaration;
 import dmd.ClassInfoDeclaration;
 import dmd.TypeClass;
+import dmd.Global;
 import dmd.TY;
 import dmd.Util;
 import dmd.backend.dt_t;
@@ -17,7 +18,7 @@
 	this(Type tinfo)
 	{
 		super(tinfo, 0);
-	    type = Type.typeinfostruct.type;
+	    type = global.typeinfoclass.type;
 	}
 
 	override Symbol* toSymbol()
@@ -27,13 +28,13 @@
 	    auto tc = cast(TypeClass)tinfo;
 	    return tc.sym.toSymbol();
 	}
-	
+
 	override void toDt(dt_t** pdt)
 	{
 		//printf("TypeInfoClassDeclaration::toDt() %s\n", tinfo->toChars());
         assert(0);
 static if(false) {
-		dtxoff(pdt, Type.typeinfoclass.toVtblSymbol(), 0, TYnptr); // vtbl for TypeInfoClass
+		dtxoff(pdt, global.typeinfoclass.toVtblSymbol(), 0, TYnptr); // vtbl for TypeInfoClass
 		dtdword(pdt, 0);			    // monitor
 
 		assert(tinfo.ty == Tclass);
--- a/dmd/TypeInfoConstDeclaration.d	Sun Oct 10 01:55:35 2010 +0400
+++ b/dmd/TypeInfoConstDeclaration.d	Sun Oct 10 03:47:23 2010 +0400
@@ -3,7 +3,7 @@
 import dmd.common;
 import dmd.Type;
 import dmd.TypeInfoDeclaration;
-import dmd.Type;
+import dmd.Global;
 import dmd.backend.dt_t;
 import dmd.backend.Util;
 import dmd.backend.TYM;
@@ -14,13 +14,13 @@
 	this(Type tinfo)
 	{
 		super(tinfo, 0);
-	    type = Type.typeinfoconst.type;
+	    type = global.typeinfoconst.type;
 	}
 
 	override void toDt(dt_t** pdt)
 	{
 		//printf("TypeInfoConstDeclaration.toDt() %s\n", toChars());
-		dtxoff(pdt, Type.typeinfoconst.toVtblSymbol(), 0, TYnptr); // vtbl for TypeInfo_Const
+		dtxoff(pdt, global.typeinfoconst.toVtblSymbol(), 0, TYnptr); // vtbl for TypeInfo_Const
 		dtdword(pdt, 0);			    // monitor
 		Type tm = tinfo.mutableOf();
 		tm = tm.merge();
--- a/dmd/TypeInfoDeclaration.d	Sun Oct 10 01:55:35 2010 +0400
+++ b/dmd/TypeInfoDeclaration.d	Sun Oct 10 03:47:23 2010 +0400
@@ -8,6 +8,7 @@
 import dmd.Scope;
 import dmd.Loc;
 import dmd.STC;
+import dmd.Global;
 import dmd.OutBuffer;
 import dmd.PROT;
 import dmd.LINK;
@@ -29,13 +30,13 @@
 
 	this(Type tinfo, int internal)
 	{
-		super(Loc(0), Type.typeinfo.type, tinfo.getTypeInfoIdent(internal), null);
+		super(Loc(0), global.typeinfo.type, tinfo.getTypeInfoIdent(internal), null);
 		this.tinfo = tinfo;
 		storage_class = STC.STCstatic | STC.STCgshared;
 		protection = PROT.PROTpublic;
 		linkage = LINK.LINKc;
 	}
-	
+
 version (DumbClone) {
 } else {
 	Type clone()
--- a/dmd/TypeInfoDelegateDeclaration.d	Sun Oct 10 01:55:35 2010 +0400
+++ b/dmd/TypeInfoDelegateDeclaration.d	Sun Oct 10 03:47:23 2010 +0400
@@ -5,6 +5,7 @@
 import dmd.TypeInfoDeclaration;
 import dmd.TypeDelegate;
 import dmd.TY;
+import dmd.Global;
 
 import dmd.backend.dt_t;
 import dmd.backend.Util;
@@ -15,13 +16,13 @@
 	this(Type tinfo)
 	{
 		super(tinfo, 0);
-	    type = Type.typeinfodelegate.type;
+	    type = global.typeinfodelegate.type;
 	}
 
 	override void toDt(dt_t** pdt)
 	{
 		//printf("TypeInfoDelegateDeclaration.toDt()\n");
-		dtxoff(pdt, Type.typeinfodelegate.toVtblSymbol(), 0, TYnptr); // vtbl for TypeInfo_Delegate
+		dtxoff(pdt, global.typeinfodelegate.toVtblSymbol(), 0, TYnptr); // vtbl for TypeInfo_Delegate
 		dtdword(pdt, 0);			    // monitor
 
 		assert(tinfo.ty == Tdelegate);
--- a/dmd/TypeInfoEnumDeclaration.d	Sun Oct 10 01:55:35 2010 +0400
+++ b/dmd/TypeInfoEnumDeclaration.d	Sun Oct 10 03:47:23 2010 +0400
@@ -5,6 +5,8 @@
 import dmd.Type;
 import dmd.Loc;
 import dmd.TypeEnum;
+import dmd.Type;
+import dmd.Global;
 import dmd.EnumDeclaration;
 import dmd.TypeInfoDeclaration;
 import dmd.backend.dt_t;
@@ -18,13 +20,13 @@
 	this(Type tinfo)
 	{
 		super(tinfo, 0);
-	    type = Type.typeinfoenum.type;
+	    type = global.typeinfoenum.type;
 	}
 
 	override void toDt(dt_t** pdt)
 	{
 		//printf("TypeInfoEnumDeclaration::toDt()\n");
-		dtxoff(pdt, Type.typeinfoenum.toVtblSymbol(), 0, TYnptr); // vtbl for TypeInfo_Enum
+		dtxoff(pdt, global.typeinfoenum.toVtblSymbol(), 0, TYnptr); // vtbl for TypeInfo_Enum
 		dtdword(pdt, 0);			    // monitor
 
 		assert(tinfo.ty == Tenum);
@@ -39,7 +41,7 @@
 		 */
 
 		if (sd.memtype)
-		{	
+		{
 			sd.memtype.getTypeInfo(null);
 			dtxoff(pdt, sd.memtype.vtinfo.toSymbol(), 0, TYnptr);	// TypeInfo for enum members
 		}
@@ -53,7 +55,7 @@
 
 		// void[] init;
 		if (!sd.defaultval || tinfo.isZeroInit(Loc(0)))
-		{	
+		{
 			// 0 initializer, or the same as the base type
 			dtdword(pdt, 0);	// init.length
 			dtdword(pdt, 0);	// init.ptr
--- a/dmd/TypeInfoFunctionDeclaration.d	Sun Oct 10 01:55:35 2010 +0400
+++ b/dmd/TypeInfoFunctionDeclaration.d	Sun Oct 10 03:47:23 2010 +0400
@@ -2,6 +2,7 @@
 
 import dmd.common;
 import dmd.Type;
+import dmd.Global;
 import dmd.TypeInfoDeclaration;
 import dmd.TypeFunction;
 import dmd.TY;
@@ -15,13 +16,13 @@
 	this(Type tinfo)
 	{
 		super(tinfo, 0);
-        type = Type.typeinfofunction.type;
+        type = global.typeinfofunction.type;
 	}
 
 	override void toDt(dt_t** pdt)
 	{
 		//printf("TypeInfoFunctionDeclaration.toDt()\n");
-		dtxoff(pdt, Type.typeinfofunction.toVtblSymbol(), 0, TYnptr); // vtbl for TypeInfo_Function
+		dtxoff(pdt, global.typeinfofunction.toVtblSymbol(), 0, TYnptr); // vtbl for TypeInfo_Function
 		dtdword(pdt, 0);			    // monitor
 
 		assert(tinfo.ty == Tfunction);
--- a/dmd/TypeInfoInterfaceDeclaration.d	Sun Oct 10 01:55:35 2010 +0400
+++ b/dmd/TypeInfoInterfaceDeclaration.d	Sun Oct 10 03:47:23 2010 +0400
@@ -6,6 +6,7 @@
 import dmd.ClassInfoDeclaration;
 import dmd.TypeClass;
 import dmd.TY;
+import dmd.Global;
 import dmd.TypeInfoClassDeclaration;
 
 import dmd.backend.dt_t;
@@ -18,13 +19,13 @@
 	this(Type tinfo)
 	{
 		super(tinfo, 0);
-	    type = Type.typeinfointerface.type;
+	    type = global.typeinfointerface.type;
 	}
 
 	override void toDt(dt_t** pdt)
 	{
 		//printf("TypeInfoInterfaceDeclaration.toDt() %s\n", tinfo.toChars());
-		dtxoff(pdt, Type.typeinfointerface.toVtblSymbol(), 0, TYnptr); // vtbl for TypeInfoInterface
+		dtxoff(pdt, global.typeinfointerface.toVtblSymbol(), 0, TYnptr); // vtbl for TypeInfoInterface
 		dtdword(pdt, 0);			    // monitor
 
 		assert(tinfo.ty == Tclass);
--- a/dmd/TypeInfoInvariantDeclaration.d	Sun Oct 10 01:55:35 2010 +0400
+++ b/dmd/TypeInfoInvariantDeclaration.d	Sun Oct 10 03:47:23 2010 +0400
@@ -2,6 +2,7 @@
 
 import dmd.common;
 import dmd.Type;
+import dmd.Global;
 import dmd.TypeInfoDeclaration;
 import dmd.backend.dt_t;
 import dmd.backend.Util;
@@ -13,13 +14,13 @@
 	this(Type tinfo)
 	{
 		super(tinfo, 0);
-	    type = Type.typeinfoinvariant.type;
+	    type = global.typeinfoinvariant.type;
 	}
 
 	override void toDt(dt_t** pdt)
 	{
 		//printf("TypeInfoInvariantDeclaration.toDt() %s\n", toChars());
-		dtxoff(pdt, Type.typeinfoinvariant.toVtblSymbol(), 0, TYnptr); // vtbl for TypeInfo_Invariant
+		dtxoff(pdt, global.typeinfoinvariant.toVtblSymbol(), 0, TYnptr); // vtbl for TypeInfo_Invariant
 		dtdword(pdt, 0);			    // monitor
 		Type tm = tinfo.mutableOf();
 		tm = tm.merge();
--- a/dmd/TypeInfoPointerDeclaration.d	Sun Oct 10 01:55:35 2010 +0400
+++ b/dmd/TypeInfoPointerDeclaration.d	Sun Oct 10 03:47:23 2010 +0400
@@ -5,6 +5,7 @@
 import dmd.TypeInfoDeclaration;
 import dmd.TypePointer;
 import dmd.TY;
+import dmd.Global;
 import dmd.backend.dt_t;
 import dmd.backend.Util;
 import dmd.backend.TYM;
@@ -14,13 +15,13 @@
 	this(Type tinfo)
 	{
 		super(tinfo, 0);
-	    type = Type.typeinfopointer.type;
+	    type = global.typeinfopointer.type;
 	}
 
 	override void toDt(dt_t** pdt)
 	{
 		//printf("TypeInfoPointerDeclaration::toDt()\n");
-		dtxoff(pdt, Type.typeinfopointer.toVtblSymbol(), 0, TYnptr); // vtbl for TypeInfo_Pointer
+		dtxoff(pdt, global.typeinfopointer.toVtblSymbol(), 0, TYnptr); // vtbl for TypeInfo_Pointer
 		dtdword(pdt, 0);			    // monitor
 
 		assert(tinfo.ty == Tpointer);
--- a/dmd/TypeInfoSharedDeclaration.d	Sun Oct 10 01:55:35 2010 +0400
+++ b/dmd/TypeInfoSharedDeclaration.d	Sun Oct 10 03:47:23 2010 +0400
@@ -2,6 +2,7 @@
 
 import dmd.common;
 import dmd.Type;
+import dmd.Global;
 import dmd.TypeInfoDeclaration;
 import dmd.backend.dt_t;
 import dmd.backend.Util;
@@ -13,17 +14,17 @@
 	this(Type tinfo)
 	{
 		super(tinfo, 0);
-		type = Type.typeinfoshared.type;
+		type = global.typeinfoshared.type;
 	}
 
 	override void toDt(dt_t** pdt)
 	{
 		// writef("TypeInfoSharedDeclaration::toDt() %s\n", toChars());
-		dtxoff(pdt, Type.typeinfoshared.toVtblSymbol(), 0, TYnptr); // vtbl for TypeInfo_Shared
+		dtxoff(pdt, global.typeinfoshared.toVtblSymbol(), 0, TYnptr); // vtbl for TypeInfo_Shared
 		dtdword(pdt, 0);				// monitor
 		Type tm = tinfo.unSharedOf();
 		tm = tm.merge();
 		tm.getTypeInfo(null);
 		dtxoff(pdt, tm.vtinfo.toSymbol(), 0, TYnptr);
 	}
-}
\ No newline at end of file
+}
--- a/dmd/TypeInfoStaticArrayDeclaration.d	Sun Oct 10 01:55:35 2010 +0400
+++ b/dmd/TypeInfoStaticArrayDeclaration.d	Sun Oct 10 03:47:23 2010 +0400
@@ -2,6 +2,7 @@
 
 import dmd.common;
 import dmd.Type;
+import dmd.Global;
 import dmd.TypeInfoDeclaration;
 import dmd.TypeSArray;
 import dmd.TY;
@@ -15,13 +16,13 @@
     this(Type tinfo)
 	{
 		super(tinfo, 0);
-	    type = Type.typeinfostaticarray.type;
+	    type = global.typeinfostaticarray.type;
 	}
 
     override void toDt(dt_t** pdt)
 	{
 		//printf("TypeInfoStaticArrayDeclaration.toDt()\n");
-		dtxoff(pdt, Type.typeinfostaticarray.toVtblSymbol(), 0, TYnptr); // vtbl for TypeInfo_StaticArray
+		dtxoff(pdt, global.typeinfostaticarray.toVtblSymbol(), 0, TYnptr); // vtbl for TypeInfo_StaticArray
 		dtdword(pdt, 0);			    // monitor
 
 		assert(tinfo.ty == Tsarray);
--- a/dmd/TypeInfoStructDeclaration.d	Sun Oct 10 01:55:35 2010 +0400
+++ b/dmd/TypeInfoStructDeclaration.d	Sun Oct 10 03:47:23 2010 +0400
@@ -16,6 +16,7 @@
 import dmd.Scope;
 import dmd.LINK;
 import dmd.Id;
+import dmd.Global;
 import dmd.TypeInfoDeclaration;
 import dmd.backend.dt_t;
 import dmd.backend.TYM;
@@ -29,16 +30,19 @@
 	this(Type tinfo)
 	{
 		super(tinfo, 0);
-	    type = Type.typeinfostruct.type;
+	    type = global.typeinfostruct.type;
 	}
 
+	static __gshared TypeFunction tftohash;
+	static __gshared TypeFunction tftostring;
+
 	override void toDt(dt_t** pdt)
 	{
 		//printf("TypeInfoStructDeclaration.toDt() '%s'\n", toChars());
 
-		uint offset = Type.typeinfostruct.structsize;
+		uint offset = global.typeinfostruct.structsize;
 
-		dtxoff(pdt, Type.typeinfostruct.toVtblSymbol(), 0, TYM.TYnptr); // vtbl for TypeInfo_Struct
+		dtxoff(pdt, global.typeinfostruct.toVtblSymbol(), 0, TYM.TYnptr); // vtbl for TypeInfo_Struct
 		dtdword(pdt, 0);			    // monitor
 
 		assert(tinfo.ty == TY.Tstruct);
@@ -81,9 +85,6 @@
 		Type ta;
 		Dsymbol s;
 
-		static TypeFunction tftohash;
-		static TypeFunction tftostring;
-
 		if (!tftohash)
 		{
 			scope Scope sc = new Scope();
@@ -97,7 +98,7 @@
 		}
 
 		TypeFunction tfeqptr;
-		{	
+		{
 			// bool opEqual(const T*) const;
 			scope sc = new Scope();
 			auto arguments = new Parameters;
@@ -153,7 +154,7 @@
 		s = search_function(sd, Id.tohash);
 		fdx = s ? s.isFuncDeclaration() : null;
 		if (fdx)
-		{	
+		{
 			fd = fdx.overloadExactMatch(tftohash);
 			if (fd)
 				dtxoff(pdt, fd.toSymbol(), 0, TYM.TYnptr);
@@ -186,11 +187,11 @@
 		}
 		else
 			dtdword(pdt, 0);
-	
+
 		s = search_function(sd, Id.tostring);
 		fdx = s ? s.isFuncDeclaration() : null;
 		if (fdx)
-		{	
+		{
 			fd = fdx.overloadExactMatch(tftostring);
 			if (fd)
 				dtxoff(pdt, fd.toSymbol(), 0, TYM.TYnptr);
--- a/dmd/TypeInfoTupleDeclaration.d	Sun Oct 10 01:55:35 2010 +0400
+++ b/dmd/TypeInfoTupleDeclaration.d	Sun Oct 10 03:47:23 2010 +0400
@@ -8,6 +8,7 @@
 import dmd.Parameter;
 import dmd.Expression;
 import dmd.TY;
+import dmd.Global;
 import dmd.backend.TYM;
 import dmd.backend.Symbol;
 import dmd.backend.dt_t;
@@ -19,13 +20,13 @@
     this(Type tinfo)
 	{
 		super(tinfo, 0);
-	    type = Type.typeinfotypelist.type;
+	    type = global.typeinfotypelist.type;
 	}
 
     override void toDt(dt_t **pdt)
 	{
 		//printf("TypeInfoTupleDeclaration.toDt() %s\n", tinfo.toChars());
-		dtxoff(pdt, Type.typeinfotypelist.toVtblSymbol(), 0, TYnptr); // vtbl for TypeInfoInterface
+		dtxoff(pdt, global.typeinfotypelist.toVtblSymbol(), 0, TYnptr); // vtbl for TypeInfoInterface
 		dtdword(pdt, 0);			    // monitor
 
 		assert(tinfo.ty == Ttuple);
@@ -37,7 +38,7 @@
 
 		dt_t* d = null;
 		for (size_t i = 0; i < dim; i++)
-		{	
+		{
 			auto arg = tu.arguments[i];
 			Expression e = arg.type.getTypeInfo(null);
 			e = e.optimize(WANTvalue);
--- a/dmd/TypeInfoTypedefDeclaration.d	Sun Oct 10 01:55:35 2010 +0400
+++ b/dmd/TypeInfoTypedefDeclaration.d	Sun Oct 10 03:47:23 2010 +0400
@@ -6,6 +6,7 @@
 import dmd.TypedefDeclaration;
 import dmd.TypeTypedef;
 import dmd.TY;
+import dmd.Global;
 import dmd.Loc;
 import dmd.backend.dt_t;
 import dmd.backend.TYM;
@@ -18,14 +19,14 @@
 	this(Type tinfo)
 	{
 		super(tinfo, 0);
-	    type = Type.typeinfotypedef.type;
+	    type = global.typeinfotypedef.type;
 	}
 
 	override void toDt(dt_t** pdt)
 	{
 		//printf("TypeInfoTypedefDeclaration.toDt() %s\n", toChars());
 
-		dtxoff(pdt, Type.typeinfotypedef.toVtblSymbol(), 0, TYnptr); // vtbl for TypeInfo_Typedef
+		dtxoff(pdt, global.typeinfotypedef.toVtblSymbol(), 0, TYnptr); // vtbl for TypeInfo_Typedef
 		dtdword(pdt, 0);			    // monitor
 
 		assert(tinfo.ty == Ttypedef);
@@ -52,7 +53,7 @@
 
 		// void[] init;
 		if (tinfo.isZeroInit(Loc(0)) || !sd.init)
-		{	
+		{
 			// 0 initializer, or the same as the base type
 			dtdword(pdt, 0);	// init.length
 			dtdword(pdt, 0);	// init.ptr
--- a/dmd/TypeInfoWildDeclaration.d	Sun Oct 10 01:55:35 2010 +0400
+++ b/dmd/TypeInfoWildDeclaration.d	Sun Oct 10 03:47:23 2010 +0400
@@ -2,6 +2,7 @@
 
 import dmd.TY;
 import dmd.Type;
+import dmd.Global;
 import dmd.TypeInfoDeclaration;
 
 import dmd.backend.dt_t;
@@ -13,13 +14,13 @@
     this(Type tinfo)
     {
         super(tinfo, 0);
-        type = Type.typeinfowild.type;
+        type = global.typeinfowild.type;
     }
 
     override void toDt(dt_t **pdt)
     {
         //printf("TypeInfoWildDeclaration::toDt() %s\n", toChars());
-        dtxoff(pdt, Type.typeinfowild.toVtblSymbol(), 0, TYnptr); // vtbl for TypeInfo_Wild
+        dtxoff(pdt, global.typeinfowild.toVtblSymbol(), 0, TYnptr); // vtbl for TypeInfo_Wild
         dtdword(pdt, 0);			    // monitor
         Type tm = tinfo.mutableOf();
         tm = tm.merge();
--- a/dmd/TypeStruct.d	Sun Oct 10 01:55:35 2010 +0400
+++ b/dmd/TypeStruct.d	Sun Oct 10 03:47:23 2010 +0400
@@ -70,14 +70,14 @@
 		this.sym = sym;
 	}
 version (DumbClone) {
-} else {	
+} else {
 	final TypeStruct cloneTo(TypeStruct t)
 	{
 		super.cloneTo(t);
 		assert(t.sym is sym);
 		return t;
 	}
-	
+
 	TypeStruct clone()
 	{
 		assert(this.classinfo == TypeStruct.classinfo);
@@ -88,7 +88,7 @@
 	{
 		return sym.size(loc);
 	}
-	
+
     override uint alignsize()
 	{
 		uint sz;
@@ -99,7 +99,7 @@
 			sz = sym.structalign;
 		return sz;
 	}
-	
+
     override string toChars()
 	{
 		//printf("sym.parent: %s, deco = %s\n", sym.parent.toChars(), deco);
@@ -112,12 +112,12 @@
 		}
 		return sym.toChars();
 	}
-	
+
     override Type syntaxCopy()
 	{
 		assert(false);
 	}
-	
+
     override Type semantic(Loc loc, Scope sc)
 	{
 		//printf("TypeStruct.semantic('%s')\n", sym.toChars());
@@ -129,12 +129,12 @@
 
 		return merge();
 	}
-	
+
     override Dsymbol toDsymbol(Scope sc)
 	{
 		return sym;
 	}
-	
+
     override void toDecoBuffer(OutBuffer buf, int flag)
 	{
 		string name = sym.mangle();
@@ -142,11 +142,11 @@
 		Type.toDecoBuffer(buf, flag);
 		buf.printf("%s", name);
 	}
-	
+
     override void toCBuffer2(OutBuffer buf, HdrGenState* hgs, MOD mod)
 	{
 		if (mod != this.mod)
-		{	
+		{
 			toCBuffer3(buf, hgs, mod);
 			return;
 		}
@@ -156,7 +156,7 @@
 		else
 			buf.writestring(sym.toChars());
 	}
-	
+
     override Expression dotExp(Scope sc, Expression e, Identifier ident)
 	{
 		uint offset;
@@ -186,7 +186,7 @@
 			auto exps = new Expressions;
 			exps.reserve(sym.fields.dim);
 			for (size_t i = 0; i < sym.fields.dim; i++)
-			{   
+			{
 				VarDeclaration v2 = cast(VarDeclaration)sym.fields[i];
 				Expression fe = new DotVarExp(e.loc, e, v2);
 				exps.push(fe);
@@ -200,7 +200,7 @@
 		}
 
 		if (e.op == TOK.TOKdotexp)
-		{	
+		{
 			DotExp de2 = cast(DotExp)e;
 
 			if (de2.e1.op == TOK.TOKimport)
@@ -232,7 +232,7 @@
 		{
 			Expression ei = v.getConstInitializer();
 			if (ei)
-			{   
+			{
 				e = ei.copy();	// need to copy it if it's a StringExp
 				e = e.semantic(sc);
 				return e;
@@ -270,7 +270,7 @@
 
 		TemplateInstance ti = s.isTemplateInstance();
 		if (ti)
-		{	
+		{
 			if (!ti.semanticRun)
 				ti.semantic(sc);
 			s = ti.inst.toAlias();
@@ -291,7 +291,7 @@
 
 		OverloadSet o = s.isOverloadSet();
 		if (o)
-		{	
+		{
 			/* We really should allow this, triggered by:
 			 *   template c()
 			 *   {
@@ -318,7 +318,7 @@
 		assert(d);
 
 		if (e.op == TOK.TOKtype)
-		{	
+		{
 			FuncDeclaration fd = sc.func;
 
 			if (d.isTupleDeclaration())
@@ -369,13 +369,13 @@
 		de = new DotVarExp(e.loc, e, d);
 		return de.semantic(sc);
 	}
-	
+
     override uint memalign(uint salign)
 	{
 		sym.size(Loc(0));		// give error for forward references
 		return sym.structalign;
 	}
-	
+
     override Expression defaultInit(Loc loc)
 	{
 	version (LOGDEFAULTINIT) {
@@ -387,7 +387,7 @@
 		d.type = this;
 		return new VarExp(sym.loc, d);
 	}
-    
+
     /***************************************
      * Use when we prefer the default initializer to be a literal,
      * rather than a global immutable variable.
@@ -406,7 +406,7 @@
 	        if (vd.init)
 	            e = vd.init.toExpression();
 	        else
-	            e = vd.type.defaultInitLiteral();
+	            e = vd.type.defaultInitLiteral(Loc(0));
 	        structelems[j] = e;
         }
         auto structinit = new StructLiteralExp(loc, cast(StructDeclaration)sym, structelems);
@@ -416,37 +416,37 @@
         return structinit;
     }
 
-	
+
     override bool isZeroInit(Loc loc)
 	{
 		return sym.zeroInit;
 	}
-	
+
     override bool isAssignable()
 	{
 		/* If any of the fields are const or invariant,
 		 * then one cannot assign this struct.
 		 */
 		for (size_t i = 0; i < sym.fields.dim; i++)
-		{   
+		{
 			VarDeclaration v = cast(VarDeclaration)sym.fields[i];
 			if (v.isConst() || v.isImmutable())
 				return false;
 		}
 		return true;
 	}
-	
+
     override bool checkBoolean()
 	{
 		return false;
 	}
-	
+
     override dt_t** toDt(dt_t** pdt)
 	{
 		sym.toDt(pdt);
 		return pdt;
 	}
-	
+
     override MATCH deduceType(Scope sc, Type tparam, TemplateParameters parameters, Objects dedtypes)
 	{
 		//printf("TypeStruct.deduceType()\n");
@@ -499,12 +499,12 @@
 		}
 		return Type.deduceType(sc, tparam, parameters, dedtypes);
 	}
-	
+
     override TypeInfoDeclaration getTypeInfoDeclaration()
 	{
 		return new TypeInfoStructDeclaration(this);
 	}
-	
+
     override bool hasPointers()
 	{
         // Probably should cache this information in sym rather than recompute
@@ -520,14 +520,14 @@
 
 		return false;
 	}
-	
+
     override MATCH implicitConvTo(Type to)
 	{
 		MATCH m;
 
 		//printf("TypeStruct.implicitConvTo(%s => %s)\n", toChars(), to.toChars());
 		if (ty == to.ty && sym == (cast(TypeStruct)to).sym)
-		{	
+		{
 			m = MATCHexact;		// exact match
 			if (mod != to.mod)
 			{
@@ -538,7 +538,7 @@
 					 * allow the conversion.
 					 */
 					foreach (VarDeclaration v; sym.fields)
-					{   
+					{
 						assert(v && v.storage_class & STCfield);
 
 						// 'from' type
@@ -560,7 +560,7 @@
 			m = MATCHnomatch;
 			Declaration d = sym.aliasthis.isDeclaration();
 			if (d)
-			{   
+			{
 				assert(d.type);
 				Type t = d.type.addMod(mod);
 				m = t.implicitConvTo(to);
@@ -570,7 +570,7 @@
 			m = MATCHnomatch;	// no match
 		return m;
 	}
-	
+
     override MATCH constConv(Type to)
 	{
 		if (equals(to))
@@ -580,12 +580,12 @@
 			return MATCHconst;
 		return MATCHnomatch;
 	}
-	
+
     override Type toHeadMutable()
 	{
 		assert(false);
 	}
-	
+
 version (CPP_MANGLE) {
     void toCppMangle(OutBuffer buf, CppMangleState* cms)
 	{
@@ -625,7 +625,7 @@
 		 */
 		if (global.params.symdebug) {
 			for (int i = 0; i < sym.fields.dim; i++)
-			{   
+			{
 				VarDeclaration v = cast(VarDeclaration)sym.fields[i];
 
 				Symbol* s2 = symbol_name(toStringz(v.ident.toChars()), SC.SCmember, v.type.toCtype());
--- a/dmd/Util.d	Sun Oct 10 01:55:35 2010 +0400
+++ b/dmd/Util.d	Sun Oct 10 03:47:23 2010 +0400
@@ -1139,3 +1139,42 @@
 }
 }
 }
+
+extern(C++) void util_assert(char* file,int line)
+{
+    fflush(stdout);
+    printf("Internal error: %s %d\n",file,line);
+    throw new Exception("Internal error");
+}
+
+extern (C++) {
+	void* mem_malloc(uint size)
+	{
+		return GC.malloc(size);
+	}
+	
+	void* mem_calloc(uint size)
+	{
+		return GC.calloc(size);
+	}
+	
+	void* mem_realloc(void* ptr, uint size)
+	{
+		return GC.realloc(ptr, size);
+	}
+	
+	void mem_free(void* ptr)
+	{
+		GC.free(ptr);
+	}
+	
+	void* mem_fmalloc(uint size)
+	{
+		return mem_malloc(size);
+	}
+	
+	void* mem_fcalloc(uint size)
+	{
+		return mem_calloc(size);
+	}
+}
\ No newline at end of file
--- a/dmd/VersionCondition.d	Sun Oct 10 01:55:35 2010 +0400
+++ b/dmd/VersionCondition.d	Sun Oct 10 03:47:23 2010 +0400
@@ -47,7 +47,7 @@
 	{
 version (DMDV2)
 {
-		static string[] reserved = [
+		enum string[] reserved = [
 			"DigitalMars", "X86", "X86_64",
 			"Windows", "Win32", "Win64",
 			"linux",
@@ -63,7 +63,7 @@
 			"none",
 		];
 } else {
-		static string[] reserved = [
+		enum string[] reserved = [
 			"DigitalMars", "X86", "X86_64",
 			"Windows", "Win32", "Win64",
 			"linux",
--- a/dmd/VoidInitializer.d	Sun Oct 10 01:55:35 2010 +0400
+++ b/dmd/VoidInitializer.d	Sun Oct 10 03:47:23 2010 +0400
@@ -40,7 +40,7 @@
 	
     override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
 	{
-		assert(false);
+		buf.writestring("void");
 	}
 
     override dt_t* toDt()
--- a/dmd/VolatileStatement.d	Sun Oct 10 01:55:35 2010 +0400
+++ b/dmd/VolatileStatement.d	Sun Oct 10 03:47:23 2010 +0400
@@ -63,7 +63,15 @@
 	
     override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
 	{
-		assert(false);
+		buf.writestring("volatile");
+		if (statement)
+		{   
+			if (statement.isScopeStatement())
+				buf.writenl();
+			else
+				buf.writebyte(' ');
+			statement.toCBuffer(buf, hgs);
+		}
 	}
 
     override Statement inlineScan(InlineScanState* iss)
--- a/dmd/backend/Cstate.d	Sun Oct 10 01:55:35 2010 +0400
+++ b/dmd/backend/Cstate.d	Sun Oct 10 03:47:23 2010 +0400
@@ -20,7 +20,9 @@
 }
 
 version (Windows) {
-	extern (C++) extern __gshared Cstate cstate;
+	extern (C++) extern __gshared Cstate cstate;		// compiler state
+	extern (C++) extern __gshared symtab_t globsym;		/* global symbol table			*/
+	extern (C++) extern void symtab_free(Symbol** tab);
 } else {
 	extern (C) extern __gshared Cstate cstate;
 }
--- a/dmd/backend/Util.d	Sun Oct 10 01:55:35 2010 +0400
+++ b/dmd/backend/Util.d	Sun Oct 10 03:47:23 2010 +0400
@@ -22,6 +22,7 @@
 import std.string;
 import core.stdc.stdlib;
 import core.stdc.string;
+import core.memory;
 
 alias ubyte mangle_t;
 
@@ -35,17 +36,17 @@
 }
 
 //extern (C++) extern {
-	elem* eictor;
-	Symbol* ictorlocalgot;
-	elem* ector;
-	Array ectorgates;
-	elem* edtor;
-	elem* etest;
-	int dtorcount;
-	Symbol* localgot;
+	__gshared elem* eictor;
+	__gshared Symbol* ictorlocalgot;
+	__gshared elem* ector;
+	__gshared Array ectorgates;
+	__gshared elem* edtor;
+	__gshared elem* etest;
+	__gshared int dtorcount;
+	__gshared Symbol* localgot;
 //}
 
-static this()
+shared static this()
 {
 	ectorgates = new Array();
 }
@@ -119,11 +120,15 @@
 		Symbol* symbol_name(const(char)* name, int sclass, type* t);
 		dt_t** dtabytes(dt_t** pdtend, tym_t ty, targ_size_t offset, targ_size_t size, const(char)* ptr);
 		type* type_setty(type**, int);
-	
+
 		void cod3_thunk(Symbol* sthunk, Symbol* sfunc, uint p, tym_t thisty, targ_size_t d, int i, targ_size_t d2);
 	}
 }
 
+extern (C) {
+    void code_term();
+}
+
 extern (C++) {
 //__gshared:
 	void obj_ehsections();
@@ -174,7 +179,7 @@
 	elem* exp2_copytotemp(elem* e);
 	elem* el_const(tym_t, eve*);
 	elem *el_params(void** args, int length);
-	
+
 	/****************************************
 	 * Allocate a new block, and set the tryblock.
 	 */
@@ -184,7 +189,7 @@
 		b.Btry = blx.tryblock;
 		return b;
 	}
-	
+
 	version (SEH) {
 		void nteh_declarvars(Blockx* bx);
 		elem* nteh_setScopeTableIndex(Blockx* blx, int scope_index);
--- a/dmd/backend/glue.d	Sun Oct 10 01:55:35 2010 +0400
+++ b/dmd/backend/glue.d	Sun Oct 10 03:47:23 2010 +0400
@@ -370,6 +370,8 @@
     objbuf.inc = 0;
 }
 
+static __gshared int count;
+
 void obj_write_deferred(Library library)
 {
 	for (int i = 0; i < obj_symbols_towrite.dim; i++)
@@ -392,7 +394,6 @@
 
 		obj_start(cast(char*)toStringz(mname));
 
-		static int count;
 		count++;		// sequence for generating names
 
 		/* Create a module that's a doppelganger of m, with just
--- a/dmd/backend/iasm.d	Sun Oct 10 01:55:35 2010 +0400
+++ b/dmd/backend/iasm.d	Sun Oct 10 03:47:23 2010 +0400
@@ -106,7 +106,7 @@
 	const(char)* asm_opstr(OP* pop);
 }
 
-static ubyte asm_TKlbra_seen = false;
+static __gshared ubyte asm_TKlbra_seen = false;
 
 struct REG
 {
@@ -1889,7 +1889,7 @@
 
     code* c;
     uint op;
-    static ubyte[7] opsize = [ 1,2,4,8,4,8,10 ];
+    enum ubyte[7] opsize = [ 1,2,4,8,4,8,10 ];
 
     op = pop.usNumops & IT.ITSIZE;
     usSize = opsize[op];
--- a/dmd/backend/symtab_t.d	Sun Oct 10 01:55:35 2010 +0400
+++ b/dmd/backend/symtab_t.d	Sun Oct 10 03:47:23 2010 +0400
@@ -5,9 +5,11 @@
 import dmd.backend.Util;
 import dmd.backend.SYMIDX;
 
-struct symtab_t
+struct SYMTAB_S
 {
     SYMIDX top;			// 1 past end
     SYMIDX symmax;		// max # of entries in tab[] possible
     Symbol** tab;		// local Symbol table
-}
\ No newline at end of file
+}
+
+alias SYMTAB_S symtab_t;
\ No newline at end of file
--- a/dmd/codegen/Util.d	Sun Oct 10 01:55:35 2010 +0400
+++ b/dmd/codegen/Util.d	Sun Oct 10 03:47:23 2010 +0400
@@ -78,7 +78,7 @@
 /************************************
  * Call a function.
  */
-elem* callfunc(Loc loc, 
+elem* callfunc(Loc loc,
 	IRState* irs,
 	int directcall,		// 1: don't do virtual call
 	Type tret,		// return type
@@ -124,7 +124,7 @@
 		ec = el_una(OPER.OPind, tf.totym(), ec);
     }
     else
-    {	
+    {
 		assert(t.ty == TY.Tfunction);
 		tf = cast(TypeFunction)t;
     }
@@ -141,7 +141,7 @@
 		int j = (tf.linkage == LINK.LINKd && tf.varargs == 1);
 
 		foreach (size_t i, Expression arg; arguments)
-		{   
+		{
 			elem* ea;
 
 			//writef("\targ[%d]: %s\n", i, arg.toChars());
@@ -178,7 +178,7 @@
     if (retmethod == RET.RETstack)
     {
 		if (!ehidden)
-		{   
+		{
 			// Don't have one, so create one
 			type* tt;
 
@@ -336,7 +336,7 @@
  */
 
 Classsym* fake_classsym(Identifier id)
-{   
+{
 	TYPE* t;
     Classsym* scc;
 
@@ -378,7 +378,7 @@
 		 * nested inside, so this hack is so they'll pass
 		 */
 		fd.ident == Id.require || fd.ident == Id.ensure)
-    {	
+    {
 		/* Going down one nesting level, i.e. we're calling
 		 * a nested function from its enclosing function.
 		 */
@@ -388,7 +388,7 @@
 		else
 ///}
 		if (irs.sthis)
-		{   
+		{
 			// We have a 'this' pointer for the current function
 			ethis = el_var(irs.sthis);
 
@@ -403,7 +403,7 @@
 			bool cond = thisfd.nestedFrameRef;
 }
 			if (cond)
-			{	
+			{
 				/* Local variables are referenced, can't skip.
 				 * Address of 'this' gives the 'this' for the nested
 				 * function
@@ -412,7 +412,7 @@
 			}
 		}
 		else
-		{   
+		{
 			/* No 'this' pointer for current function,
 			 * use null if no references to the current function's frame
 			 */
@@ -423,7 +423,7 @@
 			bool cond = thisfd.nestedFrameRef;
 }
 			if (cond)
-			{	
+			{
 				/* OPframeptr is an operator that gets the frame pointer
 				 * for the current function, i.e. for the x86 it gets
 				 * the value of EBP
@@ -431,7 +431,7 @@
 				ethis.Eoper = OPER.OPframeptr;
 			}
 		}
-		
+
 		//if (fdparent != thisfd) ethis = el_bin(OPadd, TYnptr, ethis, el_long(TYint, 0x18));
     }
     else
@@ -446,7 +446,7 @@
 			ethis = el_var(irs.sthis);
 			Dsymbol s = thisfd;
 			while (fd != s)
-			{	
+			{
 				/* Go up a nesting level, i.e. we need to find the 'this'
 				 * of an enclosing function.
 				 * Our 'enclosing function' may also be an inner class.
@@ -455,7 +455,7 @@
 				//printf("\ts = '%s'\n", s.toChars());
 				thisfd = s.isFuncDeclaration();
 				if (thisfd)
-				{   
+				{
 					/* Enclosing function is a function.
 					 */
 					if (fdparent == s.toParent2())
@@ -484,7 +484,7 @@
 					}
 				}
 				else
-				{   
+				{
 					/* Enclosed by an aggregate. That means the current
 					 * function must be a member function of that aggregate.
 					 */
@@ -527,7 +527,7 @@
 version (DMDV2) {
 						bool cond = (fdd.closureVars.dim != 0);
 } else {
-						bool cond = fdd.nestedFrameRef;						
+						bool cond = fdd.nestedFrameRef;
 }
 						if (cond) {
 							ethis = el_una(OPER.OPind, TYM.TYnptr, ethis);
@@ -658,7 +658,7 @@
 OPER intrinsic_oper(const(char)* name)
 {
 	version(DMDV1)
-	static const(char) *namearray[] =
+	enum const(char) *namearray[] =
 	[
 		"4math3cosFeZe",
 		"4math3sinFeZe",
@@ -687,7 +687,7 @@
 		"9intrinsic5outpwFktZt",
 	];
 else
-	static const(char) *namearray[] =
+	enum const(char) *namearray[] =
 	[
 		/* The names are mangled differently because of the pure and
 		 * nothrow attributes.
@@ -719,7 +719,7 @@
 		"9intrinsic5outpwFNbktZt",
 	];
 
-	static const OPER ioptab[] =
+	enum OPER ioptab[] =
 	[
 		OPcos,
 		OPsin,
@@ -748,7 +748,7 @@
 		OPoutp,
 	];
 
-	debug 
+	debug
 	{
 		assert(namearray.length == ioptab.length);
 		// assume sorted namearray
@@ -845,13 +845,13 @@
     else if ((td = s.isTupleDeclaration()) !is null)
     {
 		for (size_t i = 0; i < td.objects.dim; i++)
-		{   
+		{
 			auto o = td.objects[i];
 			///if (o.dyncast() == DYNCAST_EXPRESSION)
 			if (auto eo = cast(Expression)o)
-			{	
+			{
 				if (eo.op == TOK.TOKdsymbol)
-				{   
+				{
 					auto se = cast(DsymbolExp)eo;
 					e = el_combine(e, Dsymbol_toElem(se.s, irs));
 				}
@@ -885,12 +885,12 @@
     elem* einit = null;
 
     if (lengthVar && !(lengthVar.storage_class & STC.STCconst))
-    {   
+    {
 		elem* elength;
 		Symbol* slength;
 
 		if (t1.ty == TY.Tsarray)
-		{   
+		{
 			TypeSArray tsa = cast(TypeSArray)t1;
 			long length = tsa.dim.toInteger();
 
@@ -923,7 +923,7 @@
  *	tb	type of evalue
  */
 elem* setArray(elem* eptr, elem* edim, Type tb, elem* evalue, IRState* irs, int op)
-{   
+{
 	int r;
     elem* e;
     int sz = cast(int)tb.size();
@@ -951,7 +951,7 @@
 		{
 			StructDeclaration sd = needsPostblit(tb);
 			if (sd)
-			{   
+			{
 				/* Need to do postblit.
 				 *   void *_d_arraysetassign(void *p, void *value, int dim, TypeInfo ti);
 				 */
@@ -1019,7 +1019,7 @@
 		//printf("setEthis(ad = %s, cdp = %s, thisfd = %s)\n", ad.toChars(), cdp.toChars(), thisfd.toChars());
 
 		if (cdp is thisfd)
-		{   
+		{
 			/* Class we're new'ing is a local class in this function:
 			 *	void thisfd() { class ad { } }
 			 */
@@ -1057,7 +1057,7 @@
 							)
 						)
 				)
-		{   
+		{
 			/* Class we're new'ing is at the same level as thisfd
 			 */
 			assert(offset == 0);	// BUG: should handle this case
@@ -1088,7 +1088,7 @@
 		t = t.nextOf().toBasetype();
 
     if (t.ty == TY.Tstruct)
-    {   
+    {
 		StructDeclaration sd = (cast(TypeStruct)t).sym;
 		if (sd.postblit)
 			return sd;
@@ -1132,7 +1132,7 @@
 					es.Eoper = OPER.OPstring;
 
 					// Match MEM_PH_FREE for OPstring in ztc\el.c
-					es.EV.ss.Vstring = cast(char*)malloc(len);	/// !
+					es.EV.ss.Vstring = cast(char*)GC.malloc(len);	/// !
 					memcpy(es.EV.ss.Vstring, &e.EV, len);
 
 					es.EV.ss.Vstrlen = len;
@@ -1276,7 +1276,7 @@
 
     s = label.statement;
     if (!s.lblock)
-    {	
+    {
 		s.lblock = block_calloc(blx);
 		if (s.isReturnLabel)
 			s.lblock.Btry = null;
@@ -1293,12 +1293,12 @@
  */
 
 elem* fillHole(Symbol* stmp, size_t* poffset, size_t offset2, size_t maxoff)
-{   
+{
 	elem* e = null;
     int basealign = 1;
 
     while (*poffset < offset2)
-    {   
+    {
 		tym_t ty;
 		elem* e1;
 
@@ -1306,14 +1306,14 @@
 			e1 = el_var(stmp);
 		else
 			e1 = el_ptr(stmp);
-			
+
 		if (basealign)
 			*poffset &= ~3;
-			
+
 		basealign = 1;
 		size_t sz = maxoff - *poffset;
 		switch (sz)
-		{   
+		{
 			case 1: ty = TYchar;	break;
 			case 2: ty = TYshort;	break;
 			case 3:
@@ -1331,4 +1331,4 @@
 		*poffset += tysize[ty];
     }
     return e;
-}
\ No newline at end of file
+}
--- a/dmd/expression/Util.d	Sun Oct 10 01:55:35 2010 +0400
+++ b/dmd/expression/Util.d	Sun Oct 10 03:47:23 2010 +0400
@@ -1831,7 +1831,7 @@
     if (r == value)			// if exact duplication
 	    buf.writestring(buffer);
     else
-	    buf.printf("%La", value);	// ensure exact duplication
+	    buf.printf("%s", value);	// ensure exact duplication /// !
 
     if (type)
     {