[m-rev.] diff: implement array__make_empty_array on il backend.

Peter Ross pro at missioncriticalit.com
Tue Dec 3 07:47:15 AEDT 2002


Hi,


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


Estimated hours taken: 1
Branches: main

Implement array__make_empty_array on the IL backend.

library/array.m:
	Use the null pointer to signify an empty array in
	array__make_empty_array.  Check for this null pointer before
	manipulating an array object in all the relevant places.

Index: array.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/array.m,v
retrieving revision 1.115
diff -u -r1.115 array.m
--- array.m	24 Sep 2002 06:55:15 -0000	1.115
+++ array.m	2 Dec 2002 20:39:04 -0000
@@ -783,6 +783,11 @@
 		Array.SetValue(Item, i);
 	}
 ").
+:- pragma foreign_proc("C#", 
+		array__make_empty_array(Array::array_uo),
+		[will_not_call_mercury, promise_pure, thread_safe], "
+	Array = null;
+").
 
 array__init_2(_, _, _) :-
 	% This version is only used for back-ends for which there is no
@@ -842,12 +847,20 @@
 :- pragma foreign_proc("C#", 
 		array__max(Array::array_ui, Max::out), 
 		[will_not_call_mercury, promise_pure, thread_safe], "
-	Max = Array.Length - 1;
+	if (Array != null) {
+		Max = Array.Length - 1;
+	} else {
+		Max = -1;
+	}
 ").
 :- pragma foreign_proc("C#",
 		array__max(Array::in, Max::out), 
 		[will_not_call_mercury, promise_pure, thread_safe], "
-	Max = Array.Length - 1;
+	if (Array != null) {
+		Max = Array.Length - 1;
+	} else {
+		Max = -1;
+	}
 ").
 
 array__max(_, _) :-
@@ -875,12 +888,20 @@
 :- pragma foreign_proc("C#",
 		array__size(Array::array_ui, Max::out),
 		[will_not_call_mercury, promise_pure, thread_safe], "
-	Max = Array.Length;
+	if (Array != null) {
+		Max = Array.Length;
+	} else {
+		Max = 0;
+	}
 ").
 :- pragma foreign_proc("C#",
 		array__size(Array::in, Max::out),
 		[will_not_call_mercury, promise_pure, thread_safe], "
-	Max = Array.Length;
+	if (Array != null) {
+		Max = Array.Length;
+	} else {
+		Max = 0;
+	}
 ").
 
 :- pragma promise_pure(array__size/2).
@@ -1051,7 +1072,13 @@
 		Array::array_uo),
 		[will_not_call_mercury, promise_pure, thread_safe], "
 
-	if (Array0.Length == Size) {
+	if (Array0 == null) {
+		Array = System.Array.CreateInstance(Item.GetType(), Size);
+		for (int i = 0; i < Size; i++) {
+			Array.SetValue(Item, i);
+		}
+	}
+	else if (Array0.Length == Size) {
 		Array = Array0;
 	} else if (Array0.Length > Size) {
 		Array = System.Array.CreateInstance(Item.GetType(), Size);

--------------------------------------------------------------------------
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