[m-rev.] diff: clean up box/unbox in runtime and library.

Tyson Dowd trd at cs.mu.OZ.AU
Thu Jul 26 20:52:29 AEST 2001


Hi,

Once I commit this, you will have to make sure you have an up-to-date
compiler or it will generate references to mercury::runtime::convert
which no longer exists.

But since the pace of development on .NET is pretty quick anyway, I'm
not going to have a long wait on bootstrapping.

===================================================================


Estimated hours taken: 2
Branches: main

library/builtin.m:
library/private_builtin.m:
library/sparse_bitset.m:
library/string.m:
	Change calls to mercury::runtime::convert to System::Covert.
	Use __box instead of mercury::runtime::Convert::ToObject 

runtime/mercury_il.il:
	Remove ConvertImpl class, use unbox and ldobj instead of ToInt32.

runtime/mercury_mcpp.cpp:
	Remove Convert class.

runtime/mercury_mcpp.h:
	Use __box instead of mercury::runtime::Convert::ToObject 


Index: library/builtin.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/builtin.m,v
retrieving revision 1.58
diff -u -r1.58 builtin.m
--- library/builtin.m	2001/07/03 08:16:24	1.58
+++ library/builtin.m	2001/07/26 10:33:01
@@ -452,7 +452,7 @@
         if (0) {
             // XXX code for higher order still needs to be written...
         } else {
-            arity = mercury::runtime::Convert::ToInt32(
+            arity = System::Convert::ToInt32(
 		type_ctor_info->GetValue(MR_TYPE_CTOR_INFO_ARITY_SLOT));
         }
 
@@ -569,7 +569,7 @@
         if (0) {
 
         } else {
-            arity = mercury::runtime::Convert::ToInt32(
+            arity = System::Convert::ToInt32(
 		type_ctor_info->GetValue(MR_TYPE_CTOR_INFO_ARITY_SLOT));
         }
 
@@ -794,8 +794,8 @@
 do_unify__int_0_0(MR_Box x, MR_Box y)
 {
 	return mercury::builtin__cpp_code::mercury_code::__Unify____int_0_0(
-		mercury::runtime::Convert::ToInt32(x), 
-		mercury::runtime::Convert::ToInt32(y)); 
+		System::Convert::ToInt32(x), 
+		System::Convert::ToInt32(y)); 
 }
 
 static int
@@ -810,16 +810,16 @@
 do_unify__float_0_0(MR_Box x, MR_Box y)
 {
 	return mercury::builtin__cpp_code::mercury_code::__Unify____float_0_0(
-		mercury::runtime::Convert::ToDouble(x),
-		mercury::runtime::Convert::ToDouble(y));
+		System::Convert::ToDouble(x), 
+		System::Convert::ToDouble(y)); 
 }
 
 static int
 do_unify__character_0_0(MR_Box x, MR_Box y)
 {
 	return mercury::builtin__cpp_code::mercury_code::__Unify____character_0_0(
-		mercury::runtime::Convert::ToChar(x),
-		mercury::runtime::Convert::ToChar(y));
+		System::Convert::ToChar(x), 
+		System::Convert::ToChar(y)); 
 }
 
 static int
@@ -863,8 +863,8 @@
 do_compare__int_0_0(MR_Word_Ref result, MR_Box x, MR_Box y)
 {
 	mercury::builtin__cpp_code::mercury_code::__Compare____int_0_0(result,
-		mercury::runtime::Convert::ToInt32(x),
-		mercury::runtime::Convert::ToInt32(y));
+		System::Convert::ToInt32(x), 
+		System::Convert::ToInt32(y)); 
 }
 
 static void
@@ -879,8 +879,8 @@
 do_compare__float_0_0(MR_Word_Ref result, MR_Box x, MR_Box y)
 {
 	mercury::builtin__cpp_code::mercury_code::__Compare____float_0_0(result,
-		mercury::runtime::Convert::ToDouble(x),
-		mercury::runtime::Convert::ToDouble(y));
+		System::Convert::ToDouble(x), 
+		System::Convert::ToDouble(y)); 
 }
 
 static void
@@ -889,8 +889,8 @@
 {
 	mercury::builtin__cpp_code::mercury_code::__Compare____character_0_0(
 		result, 
-		mercury::runtime::Convert::ToChar(x),
-		mercury::runtime::Convert::ToChar(y));
+		System::Convert::ToChar(x), 
+		System::Convert::ToChar(y)); 
 }
 
 static void
Index: library/private_builtin.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/private_builtin.m,v
retrieving revision 1.78
diff -u -r1.78 private_builtin.m
--- library/private_builtin.m	2001/06/04 13:39:14	1.78
+++ library/private_builtin.m	2001/07/26 10:33:03
@@ -527,7 +527,7 @@
 	int t1;
 
 	tmp = dynamic_cast<MR_Word> (tcinfo[0]);
-	t1 = mercury::runtime::Convert::ToInt32(tmp[0]) + index;
+	t1 = System::Convert::ToInt32(tmp[0]) + index;
 	return dynamic_cast<MR_Word> (tcinfo[t1]);
 }
 
Index: library/sparse_bitset.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/sparse_bitset.m,v
retrieving revision 1.8
diff -u -r1.8 sparse_bitset.m
--- library/sparse_bitset.m	2001/03/18 23:10:10	1.8
+++ library/sparse_bitset.m	2001/07/26 10:33:06
@@ -788,8 +788,8 @@
     #error ""sparse_bitset not implemented for MC++ in .rt grades""
 #endif
 	MR_newobj((Pair), 0, 2);
-	MR_objset((Pair), 1, (mercury::runtime::Convert::ToObject(A)));	
-	MR_objset((Pair), 2, (mercury::runtime::Convert::ToObject(B)));
+	MR_objset((Pair), 1, __box(A));
+	MR_objset((Pair), 2, __box(B));
 }").
 
 %-----------------------------------------------------------------------------%
Index: library/string.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/string.m,v
retrieving revision 1.146
diff -u -r1.146 string.m
--- library/string.m	2001/06/29 03:30:27	1.146
+++ library/string.m	2001/07/26 10:33:06
@@ -788,9 +788,7 @@
         MR_list_nil(prev);
 
         for (i = length - 1; i >= 0; i--) {
-		MR_list_cons(tmp,
-			mercury::runtime::Convert::ToObject(Str->get_Chars(i)),
-			prev);
+		MR_list_cons(tmp, __box(Str->get_Chars(i)), prev);
 		prev = tmp;
         }
         CharList = tmp;
@@ -804,7 +802,7 @@
         tmp = new System::Text::StringBuilder();
         while (1) {
             if (MR_list_is_cons(CharList)) {
-		c = mercury::runtime::Convert::ToChar(MR_list_head(CharList));
+		c = System::Convert::ToChar(MR_list_head(CharList));
                 tmp->Append(c);
                 CharList = MR_list_tail(CharList);
             } else {
@@ -1662,8 +1660,7 @@
         MR_list_nil(prev);
 
         for (i = length - 1; i >= 0; i--) {
-		MR_list_cons(tmp,
-			mercury::runtime::Convert::ToObject(Str->get_Chars(i)),
+		MR_list_cons(tmp, __box(Str->get_Chars(i)),
 			prev);
 		prev = tmp;
         }
@@ -1677,8 +1674,8 @@
        
         tmp = new System::Text::StringBuilder();
         while (1) {
-            if (mercury::runtime::Convert::ToInt32(IntList->GetValue(0))) {
-                tmp->Append(mercury::runtime::Convert::ToChar(
+            if (System::Convert::ToInt32(IntList->GetValue(0))) {
+                tmp->Append(System::Convert::ToChar(
 			IntList->GetValue(1)));
                 IntList = dynamic_cast<MR_Word>(IntList->GetValue(2));
             } else {
Index: runtime/mercury_il.il
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_il.il,v
retrieving revision 1.9
diff -u -r1.9 mercury_il.il
--- runtime/mercury_il.il	2001/06/14 22:36:21	1.9
+++ runtime/mercury_il.il	2001/07/26 10:33:06
@@ -305,47 +305,7 @@
 } // end of class TempHack
 
 // ------------------------------------------------------------------------
-// The implementation of conversion routines.  It would be good to inline
-// this code whenever possible.
 
-.class public ConvertImpl {
-
-
-.method public static default class [mscorlib]System.Object ToObject(int32 ival)
-{
-	ldarg ival
-	box ['mscorlib']System.Int32
-	ret
-}
-
-.method public static default class [mscorlib]System.Object ToObject(float64 fval)
-{
-	ldarg fval
-	box ['mscorlib']System.Float64
-	ret
-}
-
-.method public static default int32 ToInt32(class [mscorlib]System.Object obj)
-{
-	ldarg obj
-	unbox int32
-	ldobj int32
-	ret
-}
-
-.method public static default float64 ToFloat64(class [mscorlib]System.Object obj)
-{
-	ldarg obj
-	unbox float64
-	ldobj float64
-	ret
-}
-
-
-}
-
-// ------------------------------------------------------------------------
-
 // This class implements some specific instances of call/N, mostly used for 
 // doing unify and compare.  You can't call using a function pointer in MC++
 // so we have to do it in IL.
@@ -358,7 +318,8 @@
 	ldarg 'X'
 	ldarg 'Y'
 	ldarg 'procedure'
-	call 	int32 ['mercury']mercury.runtime.ConvertImpl::ToInt32(class [mscorlib]System.Object)
+	unbox int32
+	ldobj int32
 	calli	int32 (class [mscorlib]System.Object, class [mscorlib]System.Object)
 	ret
 }
@@ -372,7 +333,8 @@
 	ldarg 'X'
 	ldarg 'Y'
 	ldarg 'procedure'
-	call 	int32 ['mercury']mercury.runtime.ConvertImpl::ToInt32(class [mscorlib]System.Object)
+	unbox int32
+	ldobj int32
 	calli	int32 (class [mscorlib]System.Object, class [mscorlib]System.Object, class [mscorlib]System.Object)
 	ret
 }
@@ -386,7 +348,8 @@
 	ldarg 'X'
 	ldarg 'Y'
 	ldarg 'procedure'
-	call 	int32 ['mercury']mercury.runtime.ConvertImpl::ToInt32(class [mscorlib]System.Object)
+	unbox int32
+	ldobj int32
 	calli	int32 (class [mscorlib]System.Object, class [mscorlib]System.Object, class [mscorlib]System.Object, class [mscorlib]System.Object)
 	ret
 }
@@ -402,7 +365,8 @@
 	ldarg 'X'
 	ldarg 'Y'
 	ldarg 'procedure'
-	call 	int32 ['mercury']mercury.runtime.ConvertImpl::ToInt32(class [mscorlib]System.Object)
+	unbox int32
+	ldobj int32
 	calli	int32 (class [mscorlib]System.Object, class [mscorlib]System.Object, class [mscorlib]System.Object, class [mscorlib]System.Object, class [mscorlib]System.Object)
 	ret
 }
@@ -419,7 +383,8 @@
 	ldarg 'X'
 	ldarg 'Y'
 	ldarg 'procedure'
-	call 	int32 ['mercury']mercury.runtime.ConvertImpl::ToInt32(class [mscorlib]System.Object)
+	unbox int32
+	ldobj int32
 	calli	int32 (class [mscorlib]System.Object, class [mscorlib]System.Object, class [mscorlib]System.Object, class [mscorlib]System.Object, class [mscorlib]System.Object, class [mscorlib]System.Object)
 	ret
 }
@@ -439,7 +404,8 @@
 	ldarg 'X'
 	ldarg 'Y'
 	ldarg 'procedure'
-	call 	int32 ['mercury']mercury.runtime.ConvertImpl::ToInt32(class [mscorlib]System.Object)
+	unbox int32
+	ldobj int32
 	calli	int32 (class [mscorlib]System.Object, class [mscorlib]System.Object, class [mscorlib]System.Object, class [mscorlib]System.Object, class [mscorlib]System.Object, class [mscorlib]System.Object, class [mscorlib]System.Object)
 	ret
 }
@@ -456,7 +422,8 @@
 	ldarg 'X'
 	ldarg 'Y'
 	ldarg 'procedure'
-	call 	int32 ['mercury']mercury.runtime.ConvertImpl::ToInt32(class [mscorlib]System.Object)
+	unbox int32
+	ldobj int32
 	calli	void (class [mscorlib]System.Object[]&, class [mscorlib]System.Object, class [mscorlib]System.Object)
 	ret
 }
@@ -471,7 +438,8 @@
 	ldarg 'X'
 	ldarg 'Y'
 	ldarg 'procedure'
-	call 	int32 ['mercury']mercury.runtime.ConvertImpl::ToInt32(class [mscorlib]System.Object)
+	unbox int32
+	ldobj int32
 	calli	void (class [mscorlib]System.Object, class [mscorlib]System.Object[]&,
 		class [mscorlib]System.Object, class [mscorlib]System.Object)
 	ret
@@ -489,7 +457,8 @@
 	ldarg 'X'
 	ldarg 'Y'
 	ldarg 'procedure'
-	call 	int32 ['mercury']mercury.runtime.ConvertImpl::ToInt32(class [mscorlib]System.Object)
+	unbox int32
+	ldobj int32
 	calli	void (class [mscorlib]System.Object,
 		class [mscorlib]System.Object, class [mscorlib]System.Object[]&,
 		class [mscorlib]System.Object, class [mscorlib]System.Object)
@@ -509,7 +478,8 @@
 	ldarg 'X'
 	ldarg 'Y'
 	ldarg 'procedure'
-	call 	int32 ['mercury']mercury.runtime.ConvertImpl::ToInt32(class [mscorlib]System.Object)
+	unbox int32
+	ldobj int32
 	calli	void (class [mscorlib]System.Object, class [mscorlib]System.Object,
 		class [mscorlib]System.Object, class [mscorlib]System.Object[]&,
 		class [mscorlib]System.Object, class [mscorlib]System.Object)
@@ -530,7 +500,8 @@
 	ldarg 'X'
 	ldarg 'Y'
 	ldarg 'procedure'
-	call 	int32 ['mercury']mercury.runtime.ConvertImpl::ToInt32(class [mscorlib]System.Object)
+	unbox int32
+	ldobj int32
 	calli	void (class [mscorlib]System.Object, class [mscorlib]System.Object,
 		class [mscorlib]System.Object,
 		class [mscorlib]System.Object, class [mscorlib]System.Object[]&,
@@ -554,7 +525,8 @@
 	ldarg 'X'
 	ldarg 'Y'
 	ldarg 'procedure'
-	call 	int32 ['mercury']mercury.runtime.ConvertImpl::ToInt32(class [mscorlib]System.Object)
+	unbox int32
+	ldobj int32
 	calli	void (class [mscorlib]System.Object, class [mscorlib]System.Object,
 		class [mscorlib]System.Object, class [mscorlib]System.Object,
 		class [mscorlib]System.Object, class [mscorlib]System.Object[]&,
Index: runtime/mercury_mcpp.cpp
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_mcpp.cpp,v
retrieving revision 1.5
diff -u -r1.5 mercury_mcpp.cpp
--- runtime/mercury_mcpp.cpp	2001/05/02 14:44:31	1.5
+++ runtime/mercury_mcpp.cpp	2001/07/26 10:33:06
@@ -37,47 +37,6 @@
 };
 
 
-
-__gc public class Convert
-{
-public:
-    static MR_Box ToObject(MR_Integer x)
-    {
-        return ConvertImpl::ToObject(x);
-    }
-    static MR_Box ToObject(MR_Char x)
-    {
-        return ConvertImpl::ToObject((MR_Integer) x);
-    }
-    static MR_Box ToObject(MR_Word x)
-    {
-        return x;
-    }
-    static MR_Box ToObject(MR_Float x)
-    {
-        return ConvertImpl::ToObject(x);
-    }
-
-
-    static MR_Char ToChar(MR_Box x)
-    {
-        return (MR_Char) ConvertImpl::ToInt32(x);
-    }
-    static MR_Integer ToInt32(MR_Box x)
-    {
-        return ConvertImpl::ToInt32(x);
-    }
-    static MR_Float ToDouble(MR_Box x)
-    {
-        return ConvertImpl::ToFloat64(x);
-    }
-    static MR_Word ToArray(MR_Box x)
-    {
-        return dynamic_cast<MR_Word>(x);
-    }
-};
-
-
 __gc public class Errors {
     public:
     static void SORRY(MR_String s) 
Index: runtime/mercury_mcpp.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_mcpp.h,v
retrieving revision 1.8
diff -u -r1.8 mercury_mcpp.h
--- runtime/mercury_mcpp.h	2001/05/08 10:09:02	1.8
+++ runtime/mercury_mcpp.h	2001/07/26 10:33:07
@@ -1,4 +1,3 @@
-
 //
 // Copyright (C) 2000-2001 The University of Melbourne.
 // This file may only be copied under the terms of the GNU Library General
@@ -21,7 +20,7 @@
 typedef System::Int32	MR_BoxedInt;
 typedef System::Boolean	MR_Bool;
 
-typedef System::Char	MR_Char; // `Char' is MS's name for unicode characters 
+typedef System::Char	MR_Char; // `Char' is MS's name for unicode characters
 
 typedef double 		MR_Float;
 	// XXX using a typedef doesn't seem to work properly when we want
@@ -94,7 +93,7 @@
 // We have to jump through a few hoops to get function pointers -- we do
 // it in IL currently.  We treat function pointers as integers and have
 // to box them.
-#define MR_BOX_INT(a) mercury::runtime::Convert::ToObject(a)
+#define MR_BOX_INT(a) __box(a)
 #define MR_MAYBE_STATIC_CODE(a) \
 	MR_BOX_INT(mercury::runtime::TempHack::get_ftn_ptr_##a())
 #define MR_ENTRY(a) a
@@ -211,10 +210,10 @@
     	MR_newobj(List, 0, 0);
 
 #define MR_list_is_cons(List)	\
-	(mercury::runtime::Convert::ToInt32((List)->GetValue(0)))
+	(System::Convert::ToInt32((List)->GetValue(0)))
 
 #define MR_list_is_nil(List)	\
-	(mercury::runtime::Convert::ToInt32((List)->GetValue(0)) == 0)
+	(System::Convert::ToInt32((List)->GetValue(0)) == 0)
 
 #define MR_list_head(List)	\
 	((List)->GetValue(1))
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list