[m-rev.] diff: trivial MC++ to C#

Peter Ross pro at missioncriticalit.com
Sat Nov 8 04:04:00 AEDT 2003


Hi,


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


Estimated hours taken: 2
Branches: main

Begin porting the the library just to use C# as its foreign_proc
language.

library/array.m:
library/char.m:
library/exception.m:
library/float.m:
library/int.m:
library/math.m:
library/private_builtin.m:
library/rtti_implementation.m:
library/std_util.m:
	Trivial changes to convert MC++ to C#.

library/table_builtin.m:
	Delete some unused MC++ functions.

Index: library/array.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/array.m,v
retrieving revision 1.126
diff -u -r1.126 array.m
--- library/array.m	20 Oct 2003 07:29:26 -0000	1.126
+++ library/array.m	7 Nov 2003 16:48:58 -0000
@@ -456,14 +456,14 @@
 #endif
 ").		
 
-:- pragma foreign_proc("MC++",
+:- pragma foreign_proc("C#",
 	bounds_checks,
 	[will_not_call_mercury, promise_pure, thread_safe],
 "
 #if ML_OMIT_ARRAY_BOUNDS_CHECKS
-	SUCCESS_INDICATOR = MR_FALSE;
+	SUCCESS_INDICATOR = false;
 #else
-	SUCCESS_INDICATOR = MR_TRUE;
+	SUCCESS_INDICATOR = true;
 #endif
 ").		
 
Index: library/char.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/char.m,v
retrieving revision 1.43
diff -u -r1.43 char.m
--- library/char.m	15 May 2003 09:44:50 -0000	1.43
+++ library/char.m	7 Nov 2003 16:48:59 -0000
@@ -455,25 +455,25 @@
 	SUCCESS_INDICATOR = ((MR_UnsignedChar) Character == Int);
 ").
 
-:- pragma foreign_proc("MC++",
+:- pragma foreign_proc("C#",
 	char__to_int(Character::in, Int::out),
 	[will_not_call_mercury, promise_pure, thread_safe],
 "
 	Int = Character;
 ").
 
-:- pragma foreign_proc("MC++",
+:- pragma foreign_proc("C#",
 	char__to_int(Character::in, Int::in),
 	[will_not_call_mercury, promise_pure, thread_safe],
 "
 	SUCCESS_INDICATOR = (Character == Int);
 ").
 
-:- pragma foreign_proc("MC++",
+:- pragma foreign_proc("C#",
 	char__to_int(Character::out, Int::in),
 	[will_not_call_mercury, promise_pure, thread_safe],
 "
-	Character = Int;
+	Character = (char) Int;
 	SUCCESS_INDICATOR = (Character == Int);
 ").
 
Index: library/exception.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/exception.m,v
retrieving revision 1.81
diff -u -r1.81 exception.m
--- library/exception.m	17 Aug 2003 13:30:11 -0000	1.81
+++ library/exception.m	7 Nov 2003 16:48:59 -0000
@@ -549,13 +549,13 @@
 :- impure pred make_io_state(io__state::uo) is det.
 :- pragma foreign_proc("C", make_io_state(_IO::uo),
 		[will_not_call_mercury, thread_safe], "").
-:- pragma foreign_proc("MC++", make_io_state(_IO::uo),
+:- pragma foreign_proc("C#", make_io_state(_IO::uo),
 		[will_not_call_mercury, thread_safe], "").
 
 :- impure pred consume_io_state(io__state::di) is det.
 :- pragma foreign_proc("C", consume_io_state(_IO::di),
 		[will_not_call_mercury, thread_safe], "").
-:- pragma foreign_proc("MC++", consume_io_state(_IO::di),
+:- pragma foreign_proc("C#", consume_io_state(_IO::di),
 		[will_not_call_mercury, thread_safe], "").
 
 :- pred wrap_exception(univ::in, exception_result(T)::out) is det.
@@ -1186,17 +1186,16 @@
 	% For the .NET backend we override throw_impl as it is easier to 
 	% implement these things using foreign_proc.
 
-:- pragma foreign_decl("MC++", "
+:- pragma foreign_decl("C#", "
 namespace mercury {
 	namespace runtime {
-		__gc public class Exception : public System::Exception
+		public class Exception : System.Exception
 		{
-		public:
-		   Exception(MR_Univ data) 
+		   public Exception(object[] data) 
 		   {
 			mercury_exception = data;	
 		   }
-		   MR_Univ mercury_exception;
+		   public object[] mercury_exception;
 		};
 	}
 }
Index: library/float.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/float.m,v
retrieving revision 1.56
diff -u -r1.56 float.m
--- library/float.m	13 Jun 2003 05:39:42 -0000	1.56
+++ library/float.m	7 Nov 2003 16:48:59 -0000
@@ -257,14 +257,14 @@
 #endif
 ").
 
-:- pragma foreign_proc("MC++",
+:- pragma foreign_proc("C#",
 	domain_checks,
 	[thread_safe, promise_pure],
 "
 #if ML_OMIT_MATH_DOMAIN_CHECKS
-	SUCCESS_INDICATOR = MR_FALSE;
+	SUCCESS_INDICATOR = false;
 #else
-	SUCCESS_INDICATOR = MR_TRUE;
+	SUCCESS_INDICATOR = true;
 #endif
 ").
 
Index: library/int.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/int.m,v
retrieving revision 1.92
diff -u -r1.92 int.m
--- library/int.m	15 May 2003 09:44:51 -0000	1.92
+++ library/int.m	7 Nov 2003 16:48:59 -0000
@@ -343,12 +343,12 @@
 #endif
 ").
 
-:- pragma foreign_proc("MC++", domain_checks,
+:- pragma foreign_proc("C#", domain_checks,
 		[thread_safe, promise_pure], "
 #if ML_OMIT_MATH_DOMAIN_CHECKS
-	SUCCESS_INDICATOR = MR_FALSE;
+	SUCCESS_INDICATOR = false;
 #else
-	SUCCESS_INDICATOR = MR_TRUE;
+	SUCCESS_INDICATOR = true;
 #endif
 ").
 
@@ -509,11 +509,11 @@
 "
 	FloatVal = IntVal;
 ").
-:- pragma foreign_proc("MC++",
+:- pragma foreign_proc("C#",
 	int__to_float(IntVal::in, FloatVal::out),
 	[will_not_call_mercury, promise_pure],
 "
-	FloatVal = (MR_Float) IntVal;
+	FloatVal = (double) IntVal;
 ").
 
 %-----------------------------------------------------------------------------%
@@ -524,16 +524,6 @@
 	#define ML_BITS_PER_INT		(sizeof(MR_Integer) * CHAR_BIT)
 ").
 
-:- pragma foreign_decl("MC++", "
-	#include <limits.h>
-
-	// XXX this should work, but it would be nice to have a more robust
-	// technique that used the fact we map to System.Int32 in the compiler.
-
-	#define ML_BITS_PER_INT		(sizeof(MR_Integer) * CHAR_BIT)
-
-").
-
 :- pragma foreign_proc("C",
 	int__max_int(Max::out),
 	[will_not_call_mercury, promise_pure, thread_safe],
@@ -586,25 +576,26 @@
 	Rem = Int % ML_BITS_PER_INT;
 ").
 
-:- pragma foreign_proc("MC++",
+:- pragma foreign_proc("C#",
 	int__max_int(Max::out),
 	[will_not_call_mercury, promise_pure, thread_safe],
 "
-	Max = System::Int32::MaxValue;
+	Max = System.Int32.MaxValue;
 ").
 
-:- pragma foreign_proc("MC++",
+:- pragma foreign_proc("C#",
 	int__min_int(Min::out),
 	[will_not_call_mercury, promise_pure, thread_safe],
 "
-	Min = System::Int32::MinValue;
+	Min = System.Int32.MinValue;
 ").
 
-:- pragma foreign_proc("MC++",
+:- pragma foreign_proc("C#",
 	int__bits_per_int(Bits::out),
 	[will_not_call_mercury, promise_pure, thread_safe],
 "
-	Bits = ML_BITS_PER_INT;
+	// XXX we are using int32 in the compiler.
+	Bits = 32;
 ").
 
 int__quot_bits_per_int(Int::in) = (Result::out) :-
Index: library/math.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/math.m,v
retrieving revision 1.44
diff -u -r1.44 math.m
--- library/math.m	28 Aug 2003 06:56:50 -0000	1.44
+++ library/math.m	7 Nov 2003 16:48:59 -0000
@@ -255,12 +255,12 @@
 #endif
 ").
 
-:- pragma foreign_proc("MC++", domain_checks,
+:- pragma foreign_proc("C#", domain_checks,
 		[thread_safe, promise_pure], "
 #if ML_OMIT_MATH_DOMAIN_CHECKS
-	SUCCESS_INDICATOR = MR_FALSE;
+	SUCCESS_INDICATOR = false;
 #else
-	SUCCESS_INDICATOR = MR_TRUE;
+	SUCCESS_INDICATOR = true;
 #endif
 ").
 
Index: library/private_builtin.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/private_builtin.m,v
retrieving revision 1.125
diff -u -r1.125 private_builtin.m
--- library/private_builtin.m	24 Oct 2003 11:31:53 -0000	1.125
+++ library/private_builtin.m	7 Nov 2003 16:48:59 -0000
@@ -164,10 +164,10 @@
 	[will_not_call_mercury, promise_pure, thread_safe],
 	"Res = strcmp(S1, S2);").
 
-:- pragma foreign_proc("MC++", builtin_strcmp(Res::out, S1::in, S2::in),
+:- pragma foreign_proc("C#", builtin_strcmp(Res::out, S1::in, S2::in),
 	[will_not_call_mercury, promise_pure, thread_safe],
 "
-	Res = System::String::Compare(S1, S2);
+	Res = System.String.Compare(S1, S2);
 ").
 :- pragma foreign_proc("Java", builtin_strcmp(Res::out, S1::in, S2::in),
 	[will_not_call_mercury, promise_pure, thread_safe],
Index: library/rtti_implementation.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/rtti_implementation.m,v
retrieving revision 1.44
diff -u -r1.44 rtti_implementation.m
--- library/rtti_implementation.m	22 Jun 2003 11:56:27 -0000	1.44
+++ library/rtti_implementation.m	7 Nov 2003 16:48:59 -0000
@@ -720,50 +720,50 @@
 
 	% We override the above definitions in the .NET backend.
 
-:- pragma foreign_proc("MC++",
+:- pragma foreign_proc("C#",
 	semidet_call_3(Pred::in, X::in, Y::in), 
 	[will_not_call_mercury, promise_pure, thread_safe],
 "
 	SUCCESS_INDICATOR =
-		mercury::runtime::GenericCall::semidet_call_3(Pred, X, Y);
+		mercury.runtime.GenericCall.semidet_call_3(Pred, X, Y);
 ").
-:- pragma foreign_proc("MC++",
+:- pragma foreign_proc("C#",
 	semidet_call_4(Pred::in, A::in, X::in, Y::in), 
 	[will_not_call_mercury, promise_pure, thread_safe],
 "
 	SUCCESS_INDICATOR =
-		mercury::runtime::GenericCall::semidet_call_4(Pred, A, X, Y);
+		mercury.runtime.GenericCall.semidet_call_4(Pred, A, X, Y);
 ").
-:- pragma foreign_proc("MC++",
+:- pragma foreign_proc("C#",
 	semidet_call_5(Pred::in, A::in, B::in, X::in, Y::in), 
 	[will_not_call_mercury, promise_pure, thread_safe],
 "
 	SUCCESS_INDICATOR =
-		mercury::runtime::GenericCall::semidet_call_5(Pred, A, B, X, Y);
+		mercury.runtime.GenericCall.semidet_call_5(Pred, A, B, X, Y);
 ").
-:- pragma foreign_proc("MC++",
+:- pragma foreign_proc("C#",
 	semidet_call_6(Pred::in, A::in, B::in, C::in, X::in, Y::in), 
 	[will_not_call_mercury, promise_pure, thread_safe],
 "
 	SUCCESS_INDICATOR =
-		mercury::runtime::GenericCall::semidet_call_6(Pred, A, B, C,
+		mercury.runtime.GenericCall.semidet_call_6(Pred, A, B, C,
 			X, Y);
 ").
-:- pragma foreign_proc("MC++",
+:- pragma foreign_proc("C#",
 	semidet_call_7(Pred::in, A::in, B::in, C::in, D::in, X::in, Y::in), 
 	[will_not_call_mercury, promise_pure, thread_safe],
 "
 	SUCCESS_INDICATOR =
-		mercury::runtime::GenericCall::semidet_call_7(Pred, A, B, C, D,
+		mercury.runtime.GenericCall.semidet_call_7(Pred, A, B, C, D,
 			X, Y);
 ").
-:- pragma foreign_proc("MC++",
+:- pragma foreign_proc("C#",
 	semidet_call_8(Pred::in, A::in, B::in, C::in, D::in, E::in,
 		X::in, Y::in), 
 	[will_not_call_mercury, promise_pure, thread_safe],
 "
 	SUCCESS_INDICATOR =
-		mercury::runtime::GenericCall::semidet_call_8(Pred, A, B, C, D,
+		mercury.runtime.GenericCall.semidet_call_8(Pred, A, B, C, D,
 			E, X, Y);
 ").
 
@@ -1348,14 +1348,14 @@
 
 :- pred high_level_data is semidet.
 :- pragma promise_pure(high_level_data/0).
-:- pragma foreign_proc("MC++",
+:- pragma foreign_proc("C#",
 	high_level_data,
 	[will_not_call_mercury, thread_safe],
 "
-#ifdef MR_HIGHLEVEL_DATA
-	SUCCESS_INDICATOR = MR_TRUE;
+#if MR_HIGHLEVEL_DATA
+	SUCCESS_INDICATOR = true;
 #else
-	SUCCESS_INDICATOR = MR_FALSE;
+	SUCCESS_INDICATOR = false;
 #endif
 ").
 high_level_data :-
@@ -1672,7 +1672,7 @@
 
 same_pointer_value(X, Y) :- same_pointer_value_untyped(X, Y).
 
-:- pragma foreign_proc("MC++",
+:- pragma foreign_proc("C#",
 	same_pointer_value_untyped(T1::in, T2::in),
 	[will_not_call_mercury, promise_pure, thread_safe],
 "
@@ -2245,11 +2245,11 @@
 "
 	SUCCESS_INDICATOR = ((void *)S == NULL);
 ").
-:- pragma foreign_proc("MC++",
+:- pragma foreign_proc("C#",
 	null(S::in),
 	[will_not_call_mercury, thread_safe, promise_pure],
 "
-	SUCCESS_INDICATOR = (S == 0);
+	SUCCESS_INDICATOR = (S == null);
 ").
 null(_) :-
 	% This version is only used for back-ends for which there is no
@@ -2265,7 +2265,7 @@
 "
 	T = (MR_Word) NULL;
 ").
-:- pragma foreign_proc("MC++",
+:- pragma foreign_proc("C#",
 	null = (T::out),
 	[will_not_call_mercury, thread_safe, promise_pure],
 "
Index: library/std_util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/std_util.m,v
retrieving revision 1.285
diff -u -r1.285 std_util.m
--- library/std_util.m	20 Oct 2003 07:29:27 -0000	1.285
+++ library/std_util.m	7 Nov 2003 16:49:00 -0000
@@ -1115,15 +1115,15 @@
 #endif
 }").
 
-:- pragma foreign_proc("MC++", 
+:- pragma foreign_proc("C#", 
 	swap_heap_and_solutions_heap,
 	[will_not_call_mercury, thread_safe],
 "
-	/*
-	** For the .NET back-end, we use the system heap, rather
-	** than defining our own heaps.  So we don't need to
-	** worry about swapping them.  Hence do nothing here.
-	*/
+	//
+	// For the .NET back-end, we use the system heap, rather
+	// than defining our own heaps.  So we don't need to
+	// worry about swapping them.  Hence do nothing here.
+	//
 ").
 
 %
@@ -1184,24 +1184,24 @@
 	MR_PARTIAL_DEEP_COPY(SolutionsHeapPtr, OldVal, NewVal, TypeInfo_for_T);
 ").
 
-:- pragma foreign_proc("MC++",
+:- pragma foreign_proc("C#",
 	partial_deep_copy(_SolutionsHeapPtr::in, OldVal::in, NewVal::out),
 	[will_not_call_mercury, thread_safe, promise_pure],
 "
-	/*
-	** For the IL back-end, we don't do heap reclamation on failure,
-	** so we don't need to worry about making deep copies here.
-	** Shallow copies will suffice.
-	*/
+	//
+	// For the IL back-end, we don't do heap reclamation on failure,
+	// so we don't need to worry about making deep copies here.
+	// Shallow copies will suffice.
+	//
 	NewVal = OldVal;
 ").
-:- pragma foreign_proc("MC++", 
+:- pragma foreign_proc("C#", 
 	partial_deep_copy(_SolutionsHeapPtr::in, OldVal::mdi, NewVal::muo),
 	[will_not_call_mercury, thread_safe, promise_pure],
 "
 	NewVal = OldVal;
 ").
-:- pragma foreign_proc("MC++",
+:- pragma foreign_proc("C#",
 	partial_deep_copy(_SolutionsHeapPtr::in, OldVal::di, NewVal::uo),
 	[will_not_call_mercury, thread_safe, promise_pure],
 "
@@ -1225,14 +1225,14 @@
 #endif
 ").
 
-:- pragma foreign_proc("MC++", 
+:- pragma foreign_proc("C#", 
 	reset_solutions_heap(_SolutionsHeapPtr::in),
 	[will_not_call_mercury, thread_safe],
 "
-	/*
-	** For the IL back-end, we don't have a separate `solutions heap'.
-	** Hence this operation is a NOP.
-	*/
+	//
+	// For the IL back-end, we don't have a separate `solutions heap'.
+	// Hence this operation is a NOP.
+	//
 ").
 
 %-----------------------------------------------------------------------------%
@@ -1407,19 +1407,19 @@
 	[will_not_call_mercury, thread_safe, promise_pure],
 	"Y = X;").
 
-:- pragma foreign_proc("MC++",
+:- pragma foreign_proc("C#",
 	semidet_succeed, 
 	[will_not_call_mercury, thread_safe, promise_pure],
-	"SUCCESS_INDICATOR = MR_TRUE;").
-:- pragma foreign_proc("MC++",
+	"SUCCESS_INDICATOR = true;").
+:- pragma foreign_proc("C#",
 	semidet_fail, 
 	[will_not_call_mercury, thread_safe, promise_pure],
-	"SUCCESS_INDICATOR = MR_FALSE;").
-:- pragma foreign_proc("MC++",
+	"SUCCESS_INDICATOR = false;").
+:- pragma foreign_proc("C#",
 	cc_multi_equal(X::in, Y::out),
 	[will_not_call_mercury, thread_safe, promise_pure],
 	"Y = X;").
-:- pragma foreign_proc("MC++",
+:- pragma foreign_proc("C#",
 	cc_multi_equal(X::di, Y::uo),
 	[will_not_call_mercury, thread_safe, promise_pure],
 	"Y = X;").
Index: library/table_builtin.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/table_builtin.m,v
retrieving revision 1.32
diff -u -r1.32 table_builtin.m
--- library/table_builtin.m	3 Jul 2003 12:00:18 -0000	1.32
+++ library/table_builtin.m	7 Nov 2003 16:49:00 -0000
@@ -769,28 +769,6 @@
 :- external(table_nondet_suspend/2).
 :- external(table_nondet_resume/1).
 
-/*
-
-XXX :- external stops us from using these two definitions
-
-:- pragma foreign_proc("MC++",
-	table_nondet_suspend(_A::in, _B::out), [will_not_call_mercury, promise_pure],
-	local_vars(""),
-	first_code(""),
-	retry_code(""),
-	common_code("
-		mercury::runtime::Errors::SORRY(
-			S""foreign code for this function"");
-	")
-).
-
-:- pragma foreign_proc("MC++",
-	table_nondet_resume(_A::in), [will_not_call_mercury, promise_pure], "
-	mercury::runtime::Errors::SORRY(S""foreign code for this function"");
-").
-
-*/
-
 :- pragma foreign_proc("C",
 	table_nondet_is_complete(Subgoal::in),
 	[will_not_call_mercury],


-- 
Peter Ross		
Software Engineer                                (Work)   +32 2 757 10 15
Mission Critical                                 (Mobile) +32 485 482 559
--------------------------------------------------------------------------
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