changeset 148:fe2e1b93e88f

phobos compiles now: * fixed upgrade mistake in interpret.Util + implemented missing methods in RealExp,VarExp
author Trass3r
date Wed, 15 Sep 2010 03:58:55 +0200
parents 9a2a1ae6c8e5
children 14feb7ae01a6
files dmd/RealExp.d dmd/TypeFunction.d dmd/VarExp.d dmd/interpret/Util.d
diffstat 4 files changed, 56 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/dmd/RealExp.d	Tue Sep 14 23:49:12 2010 +0100
+++ b/dmd/RealExp.d	Wed Sep 15 03:58:55 2010 +0200
@@ -24,6 +24,7 @@
 import dmd.backend.mTY;
 
 import std.stdio;
+import std.string;
 
 class RealExp : Expression
 {
@@ -52,7 +53,7 @@
 			}
 		}
 		
-		return 0;
+		return false;
 	}
 
 	override Expression semantic(Scope sc)
@@ -66,22 +67,31 @@
 
 	override Expression interpret(InterState istate)
 	{
-		assert(false);
+version(LOG)
+		writef("RealExp::interpret() %s\n", toChars());
+
+		return this;
 	}
 
 	override string toChars()
 	{
-		assert(false);
+		return format(type.isimaginary() ? "%gi" : "%g", value);
 	}
 
 	override ulong toInteger()
 	{
-		assert(false);
+version(IN_GCC)
+		return toReal().toInt();
+else
+		return cast(ulong) toReal();
 	}
 
 	override ulong toUInteger()
 	{
-		assert(false);
+version(IN_GCC)
+		return cast(ulong) toReal().toInt();
+else
+		return cast(ulong) toReal();
 	}
 
 	override real toReal()
@@ -129,7 +139,7 @@
 
 	override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
 	{
-	    floatToBuffer(buf, type, value);
+		floatToBuffer(buf, type, value);
 	}
 
 	override void toMangleBuffer(OutBuffer buf)
@@ -176,7 +186,7 @@
 				print();
 				///type.print();
 				///type.toBasetype().print();
-	    	    printf("ty = %d, tym = %lx\n", type.ty, ty);
+				printf("ty = %d, tym = %lx\n", type.ty, ty);
 				assert(0);
 		}
 		return el_const(ty, &c);
@@ -221,5 +231,4 @@
 		}
 		return pdt;
 	}
-}
-
+}
\ No newline at end of file
--- a/dmd/TypeFunction.d	Tue Sep 14 23:49:12 2010 +0100
+++ b/dmd/TypeFunction.d	Wed Sep 15 03:58:55 2010 +0200
@@ -423,6 +423,8 @@
 	    case TRUST.TRUSTsafe:
 	        buf.writestring("@safe ");
 	        break;
+
+		default:
         }
 
 		if (next && (!ident || ident.toHChars2() == ident.toChars()))
--- a/dmd/VarExp.d	Tue Sep 14 23:49:12 2010 +0100
+++ b/dmd/VarExp.d	Wed Sep 15 03:58:55 2010 +0200
@@ -17,9 +17,11 @@
 import dmd.TOK;
 import dmd.TY;
 import dmd.STC;
+import dmd.SymbolDeclaration;
 import dmd.SymbolExp;
 import dmd.Type;
 import dmd.interpret.Util;
+import dmd.backend.Util;
 import dmd.backend.dt_t;
 import dmd.expression.Util;
 
@@ -258,7 +260,35 @@
 
 	override dt_t** toDt(dt_t** pdt)
 	{
-		assert(false);
+		// writef("VarExp::toDt() %d\n", op);
+		for (; *pdt; pdt = &((*pdt).DTnext))
+		{}
+
+		VarDeclaration v = var.isVarDeclaration();
+		if (v && (v.isConst() || v.isImmutable()) &&
+			type.toBasetype().ty != Tsarray && v.init)
+		{
+			if (v.inuse)
+			{
+				error("recursive reference %s", toChars());
+				return pdt;
+			}
+			v.inuse++;
+			*pdt = v.init.toDt();
+			v.inuse--;
+			return pdt;
+		}
+		SymbolDeclaration sd = var.isSymbolDeclaration();
+		if (sd && sd.dsym)
+		{
+			sd.dsym.toDt(pdt);
+			return pdt;
+		}
+		debug writef("VarExp::toDt(), kind = %s\n", var.kind());
+
+		error("non-constant expression %s", toChars());
+		pdt = dtnzeros(pdt, 1);
+		return pdt;
 	}
 
 	version(DMDV1)
--- a/dmd/interpret/Util.d	Tue Sep 14 23:49:12 2010 +0100
+++ b/dmd/interpret/Util.d	Wed Sep 15 03:58:55 2010 +0200
@@ -144,16 +144,16 @@
 ///} else {
 ///	if (v.isConst() && v.init)
 ///}
-		{   
+		{
 			e = v.init.toExpression();
 			if (e && !e.type)
 				e.type = v.type;
 		}
 		else
-		{   
+		{
 			e = v.value;
-			if (v.isCTFE())
-			{	
+			if (!v.isCTFE())
+			{
 				error(loc, "static variable %s cannot be read at compile time", v.toChars());
 				e = EXP_CANT_INTERPRET;
 			}
@@ -168,7 +168,7 @@
 	else if (s)
 	{
 		if (s.dsym.toInitializer() == s.sym)
-		{   
+		{
 			Expressions exps = new Expressions();
 			e = new StructLiteralExp(Loc(0), s.dsym, exps);
 			e = e.semantic(null);