Browse Source

2001-08-28 Dietmar Maurer <[email protected]>

	* interp.c (ves_exec_method): better check for value types (get
	the class to detect if we have a value type), implemented CEE_CONV_U1,
	CEE_CONV_U2, CEE_CEQ

	* class.c (mono_class_metadata_init): delayed computing of the
	class size to mono_class_metadata_init ()

	* mono/tests/console.cs: impl.

	* mono/tests/box.cs: impl.

	* mono/tests/stream-writer.cs: impl.

svn path=/trunk/mono/; revision=655
Dietmar Maurer 24 years ago
parent
commit
abaa8e2d48

+ 7 - 0
ChangeLog

@@ -1,3 +1,10 @@
+2001-08-28  Dietmar Maurer  <[email protected]>
+
+	* mono/tests/console.cs: impl.
+
+	* mono/tests/box.cs: impl.
+
+	* mono/tests/stream-writer.cs: impl.
 
 Mon Aug 27 20:24:26 CEST 2001 Paolo Molaro <[email protected]>
 

+ 6 - 0
mono/interpreter/ChangeLog

@@ -1,3 +1,9 @@
+2001-08-28  Dietmar Maurer  <[email protected]>
+
+	* interp.c (ves_exec_method): better check for value types (get
+	the class to detect if we have a value type), implemented CEE_CONV_U1,
+	CEE_CONV_U2, CEE_CEQ
+	
 
 Mon Aug 27 21:30:30 CEST 2001 Paolo Molaro <[email protected]>
 

+ 55 - 30
mono/interpreter/interp.c

@@ -878,17 +878,19 @@ ves_exec_method (MonoInvocation *frame)
 			BREAK;
 		CASE (CEE_LDARGA_S) {
 			MonoType *t;
+			MonoClass *c;
+
 			++ip;
 			t = ARG_TYPE (signature, *ip);
-			if (t->type == MONO_TYPE_VALUETYPE) {
+			c = mono_class_from_mono_type (t);
+			sp->data.vt.klass = c;
+			sp->data.vt.vt = ARG_POS (*ip);
+
+			if (c->valuetype)
 				sp->type = VAL_VALUETA;
-				sp->data.vt.vt = ARG_POS (*ip);
-				sp->data.vt.klass = t->data.klass;
-			} else {
+			else
 				sp->type = VAL_TP;
-				sp->data.p = ARG_POS (*ip);
-				sp->data.vt.klass = mono_class_from_mono_type (t);
-			}
+
 			++sp;
 			++ip;
 			BREAK;
@@ -909,17 +911,19 @@ ves_exec_method (MonoInvocation *frame)
 			BREAK;
 		CASE (CEE_LDLOCA_S) {
 			MonoType *t;
+			MonoClass *c;
+
 			++ip;
 			t = LOCAL_TYPE (header, *ip);
-			if (t->type == MONO_TYPE_VALUETYPE) {
+			c =  mono_class_from_mono_type (t);
+			sp->data.vt.klass = c;
+			sp->data.p = LOCAL_POS (*ip);
+
+			if (c->valuetype)
 				sp->type = VAL_VALUETA;
-				sp->data.vt.vt = LOCAL_POS (*ip);
-				sp->data.vt.klass = t->data.klass;
-			} else {
+			else 
 				sp->type = VAL_TP;
-				sp->data.p = LOCAL_POS (*ip);
-				sp->data.vt.klass = mono_class_from_mono_type (t);
-			}
+
 			++sp;
 			++ip;
 			BREAK;
@@ -1040,7 +1044,6 @@ ves_exec_method (MonoInvocation *frame)
 				child_frame.method = mono_get_method (image, token, NULL);
 			csignature = child_frame.method->signature;
 			g_assert (csignature->call_convention == MONO_CALL_DEFAULT);
-
 			/* decrement by the actual number of args */
 			if (csignature->param_count) {
 				sp -= csignature->param_count;
@@ -1669,6 +1672,7 @@ ves_exec_method (MonoInvocation *frame)
 			else if (sp->type == VAL_NATI)
 				sp->data.p = (gpointer)(~ (int)sp->data.p);
 			BREAK;
+		CASE (CEE_CONV_U1) // fall through
 		CASE (CEE_CONV_I1) {
 			++ip;
 			switch (sp [-1].type) {
@@ -1690,6 +1694,7 @@ ves_exec_method (MonoInvocation *frame)
 			sp [-1].type = VAL_I32;
 			BREAK;
 		}
+		CASE (CEE_CONV_U2) // fall through
 		CASE (CEE_CONV_I2) {
 			++ip;
 			switch (sp [-1].type) {
@@ -1816,8 +1821,7 @@ ves_exec_method (MonoInvocation *frame)
 			name = mono_metadata_user_string (image, index);
 			len = mono_metadata_decode_blob_size (name, &name);
 
-			o = mono_new_utf16_string (name, len);
-
+			o = mono_new_utf16_string (name, len >> 1);
 			sp->type = VAL_OBJ;
 			sp->data.p = o;
 			sp->data.vt.klass = NULL;
@@ -1970,12 +1974,13 @@ ves_exec_method (MonoInvocation *frame)
 				offset = field->offset - sizeof (MonoObject);
 			}
 			if (load_addr) {
-				sp->type = VAL_TP;
-				sp->data.p = (char*)obj + offset;
-				sp->data.vt.klass = mono_class_from_mono_type (field->type);
+				sp [-1].type = VAL_TP;
+				sp [-1].data.p = (char*)obj + offset;
+				sp [-1].data.vt.klass = mono_class_from_mono_type (field->type);
 			} else {
 				vt_alloc (field->type, &sp [-1]);
 				stackval_from_data (field->type, &sp [-1], (char*)obj + offset);
+				
 			}
 			BREAK;
 		}
@@ -2000,6 +2005,7 @@ ves_exec_method (MonoInvocation *frame)
 				field = mono_class_get_field (sp [0].data.vt.klass, token);
 				offset = field->offset - sizeof (MonoObject);
 			}
+
 			stackval_to_data (field->type, &sp [1], (char*)obj + offset);
 			vt_free (&sp [1]);
 			BREAK;
@@ -2345,8 +2351,6 @@ ves_exec_method (MonoInvocation *frame)
 		CASE (CEE_UNUSED66) 
 		CASE (CEE_UNUSED67) ves_abort(); BREAK;
 		CASE (CEE_LDTOKEN)
-		CASE (CEE_CONV_U2) ves_abort(); BREAK;
-		CASE (CEE_CONV_U1) ves_abort(); BREAK;
 		//CASE (CEE_CONV_I) ves_abort(); BREAK;
 		CASE (CEE_CONV_OVF_I) ves_abort(); BREAK;
 		CASE (CEE_CONV_OVF_U) ves_abort(); BREAK;
@@ -2430,7 +2434,26 @@ ves_exec_method (MonoInvocation *frame)
 			++ip;
 			switch (*ip) {
 			case CEE_ARGLIST: ves_abort(); break;
-			case CEE_CEQ: ves_abort(); break;
+			case CEE_CEQ: {
+				gint32 result;
+				++ip;
+				sp -= 2;
+
+				if (sp->type == VAL_I32)
+					result = sp [0].data.i == GET_NATI (sp [1]);
+				else if (sp->type == VAL_I64)
+					result = sp [0].data.l == sp [1].data.l;
+				else if (sp->type == VAL_DOUBLE)
+					result = sp [0].data.f == sp [1].data.f;
+				else
+					result = GET_NATI (sp [0]) == GET_NATI (sp [1]);
+				sp->type = VAL_I32;
+				sp->data.i = result;
+
+				sp++;
+						
+				break;
+			}
 			case CEE_CGT: ves_abort(); break;
 			case CEE_CGT_UN: ves_abort(); break;
 			case CEE_CLT: ves_abort(); break;
@@ -2471,20 +2494,22 @@ ves_exec_method (MonoInvocation *frame)
 			}
 			case CEE_LDLOCA: {
 				MonoType *t;
+				MonoClass *c;
 				guint32 loc_pos;
+
 				++ip;
 				loc_pos = read32 (ip);
 				ip += 4;
 				t = LOCAL_TYPE (header, loc_pos);
-				if (t->type == MONO_TYPE_VALUETYPE) {
+				c =  mono_class_from_mono_type (t);
+				sp->data.vt.vt = LOCAL_POS (loc_pos);
+				sp->data.vt.klass = c;
+
+				if (c->valuetype) 
 					sp->type = VAL_VALUETA;
-					sp->data.vt.vt = LOCAL_POS (loc_pos);
-					sp->data.vt.klass = t->data.klass;
-				} else {
+				else
 					sp->type = VAL_TP;
-					sp->data.p = LOCAL_POS (loc_pos);
-					sp->data.vt.klass = mono_class_from_mono_type (t);
-				}
+
 				++sp;
 				break;
 			}

+ 4 - 0
mono/metadata/ChangeLog

@@ -1,3 +1,7 @@
+2001-08-28  Dietmar Maurer  <[email protected]>
+
+	* class.c (mono_class_metadata_init): delayed computing of the
+	class size to mono_class_metadata_init ()
 
 Tue Aug 28 15:47:15 CEST 2001 Paolo Molaro <[email protected]>
 

+ 7 - 8
mono/metadata/class.c

@@ -156,12 +156,15 @@ mono_class_metadata_init (MonoClass *class)
 	if (class->metadata_inited)
 		return;
 
-	if (class->parent && !class->parent->metadata_inited)
-		 mono_class_metadata_init (class->parent);
+	if (class->parent) {
+		if (!class->parent->metadata_inited)
+			mono_class_metadata_init (class->parent);
+		class->instance_size = class->parent->instance_size;
+		class->class_size = class->parent->class_size;
+	}
 
 	class->metadata_inited = 1;
 
-
 	/*
 	 * Computes the size used by the fields, and their locations
 	 */
@@ -210,20 +213,17 @@ mono_class_create_from_typedef (MonoImage *image, guint32 type_token)
 	class->type_token = type_token;
 	class->flags = cols [0];
 
-
 	/*g_print ("Init class %s\n", name);*/
 
 	/* if root of the hierarchy */
 	if (!strcmp (nspace, "System") && !strcmp (name, "Object")) {
-		class->instance_size = sizeof (MonoObject);
 		class->parent = NULL;
+		class->instance_size = sizeof (MonoObject);
 	} else if (!(cols [0] & TYPE_ATTRIBUTE_INTERFACE)) {
 		parent_token = mono_metadata_token_from_dor (cols [3]);
 		class->parent = mono_class_get (image, parent_token);
-		class->instance_size = class->parent->instance_size;
 		class->valuetype = class->parent->valuetype;
 		class->enumtype = class->parent->enumtype;
-		g_assert (class->instance_size);
 	}
 
 	if (!strcmp (nspace, "System")) {
@@ -269,7 +269,6 @@ mono_class_create_from_typedef (MonoImage *image, guint32 type_token)
 	if (!strcmp (nspace, "System") && !strcmp (name, "Array")) {
 		class->instance_size += 2 * sizeof (gpointer);
 		g_assert (class->field.count == 0);
-		g_assert (class->instance_size == sizeof (MonoArrayObject));
 	}
 
 	class->interfaces = mono_metadata_interfaces_from_typedef (image, type_token);

+ 1 - 1
mono/metadata/object.c

@@ -131,7 +131,7 @@ mono_new_szarray (MonoClass *eclass, guint32 n)
 	ao->bounds = g_malloc0 (sizeof (MonoArrayBounds));
 	ao->bounds [0].length = n;
 	ao->bounds [0].lower_bound = 0;
-	
+
 	ao->vector = g_malloc0 (n * mono_array_element_size (ac));
 
 	return o;

+ 8 - 5
mono/tests/Makefile.am

@@ -14,15 +14,18 @@ TESTSRC=			\
 	exception3.cs		\
 	exception4.cs		\
 	struct.cs		\
-	static-constructor.cs		\
+	static-constructor.cs	\
 	pinvoke.cs		\
+	box.cs			\
 	array.cs		\
-	enum.cs		\
+	enum.cs			\
 	property.cs		\
 	interface.cs		\
-	virtual-method.cs		\
-	intptrcast.cs	\
-	stream.cs
+	virtual-method.cs	\
+	intptrcast.cs		\
+	stream.cs		\
+	stream-writer.cs	\
+	console.cs
 
 TESTS=$(TESTSRC:.cs=.exe)
 TESTBS=$(BENCHSRC:.cs=.exe)

+ 1 - 15
mono/tests/array.cs

@@ -95,23 +95,9 @@ public class Test {
 		return 0;
 	}
 	
-	public static int boxtest ()
-	{
-		int i = 123;
-		object o = i;
-		int j = (int) o;
-
-		if (i != j)
-			return 1;
-		
-		return 0;
-	}
 
 	public static int Main () {
-	       
-		if (boxtest () != 0)
-			return 1;
-	       
+	       	       
 		if (atest () != 0)
 			return 1;
 		

+ 32 - 0
mono/tests/box.cs

@@ -0,0 +1,32 @@
+using System;
+using System.IO;
+
+public class Test {
+
+	public static int boxtest ()
+	{
+		int i = 123;
+		object o = i;
+		int j = (int) o;
+
+		if (i != j)
+			return 1;
+		
+		return 0;
+	}
+
+	public static int Main () {
+		string t = 123.ToString();
+
+		if (t != "123")
+			return 1;
+
+		if (boxtest () != 0)
+			return 1;
+
+		
+		return 0;
+	}
+}
+
+

+ 13 - 0
mono/tests/console.cs

@@ -0,0 +1,13 @@
+using System;
+
+public class Test {
+
+	public static int Main () {
+		
+		Console.WriteLine ("We can now write to the console");
+
+		return 0;
+	}
+}
+
+

+ 19 - 0
mono/tests/stream-writer.cs

@@ -0,0 +1,19 @@
+using System;
+using System.IO;
+
+public class Test {
+
+	public static int Main () {
+		FileStream s = new FileStream ((IntPtr)1, FileAccess.Write);
+		StreamWriter sw = new StreamWriter (s);
+		string ts = "This is another test";
+
+		sw.WriteLine (ts);
+
+		sw.WriteLine (123456);
+
+		return 0;
+	}
+}
+
+