diff dmd/SliceExp.d @ 63:cab4c37afb89

A bunch of implementations
author korDen
date Mon, 23 Aug 2010 16:52:24 +0400
parents a8b50ff7f201
children 4290d870944a
line wrap: on
line diff
--- a/dmd/SliceExp.d	Mon Aug 23 03:21:32 2010 +0400
+++ b/dmd/SliceExp.d	Mon Aug 23 16:52:24 2010 +0400
@@ -1,6 +1,7 @@
 module dmd.SliceExp;
 
 import dmd.Expression;
+import dmd.expression.ArrayLength;
 import dmd.backend.elem;
 import dmd.UnaExp;
 import dmd.Identifier;
@@ -328,9 +329,46 @@
 		return e;
 	}
 
-	Expression interpret(InterState* istate)
+	Expression interpret(InterState istate)
 	{
-		assert(false);
+		Expression e;
+		Expression e1;
+		Expression lwr;
+		Expression upr;
+
+version (LOG) {
+		printf("SliceExp.interpret() %s\n", toChars());
+}
+		e1 = this.e1.interpret(istate);
+		if (e1 is EXP_CANT_INTERPRET)
+			goto Lcant;
+		if (!this.lwr)
+		{
+			e = e1.castTo(null, type);
+			return e.interpret(istate);
+		}
+
+		/* Set the $ variable
+		 */
+		e = ArrayLength(Type.tsize_t, e1);
+		if (e is EXP_CANT_INTERPRET)
+			goto Lcant;
+		if (lengthVar)
+			lengthVar.value = e;
+
+		/* Evaluate lower and upper bounds of slice
+		 */
+		lwr = this.lwr.interpret(istate);
+		if (lwr is EXP_CANT_INTERPRET)
+			goto Lcant;
+		upr = this.upr.interpret(istate);
+		if (upr is EXP_CANT_INTERPRET)
+			goto Lcant;
+
+		return Slice(type, e1, lwr, upr);
+
+	Lcant:
+		return EXP_CANT_INTERPRET;
 	}
 
 	void dump(int indent)