[m-dev.] for review: tuples [1]

Simon Taylor stayl at cs.mu.OZ.AU
Mon Sep 18 22:20:12 AEDT 2000


Hi,

I'll commit this now.

> > +* We've added support for tuple types, similar to those in most
> > +  other functional languages.
> 
> I think it would be a good idea here to mention the syntax used,
> and to say where to go for more information.

I've changed that to:
 
+* We've added support for tuple types, similar to those in most
+  other functional languages. Tuples use the syntax `{A, B, ...}'.
+  See the "Builtin types" section of the "Types" chapter of the
+  Mercury Language Reference Manual for details.

I've also made some minor changes to avoid attempting to allocate
memory for `{}/0' constructurs. It doesn't cause any problems, but
GC_MALLOC appears to allocate memory even when the amount requested
is zero.

--- runtime/mercury_deep_copy_body.h	2000/09/16 03:03:50	1.2
+++ runtime/mercury_deep_copy_body.h	2000/09/18 11:11:51
@@ -459,19 +459,23 @@
 
                 arity = MR_TYPEINFO_GET_TUPLE_ARITY(type_info);
 
-                /* allocate space for the new tuple */
-                incr_saved_hp(new_data, arity);
-                new_data_ptr = (MR_Word *) new_data;
+                if (arity == 0) {
+                        new_data = NULL;
+                } else {
+                        /* allocate space for the new tuple */
+                        incr_saved_hp(new_data, arity);
+                        new_data_ptr = (MR_Word *) new_data;
 
-                arg_typeinfo_vector =
-                    MR_TYPEINFO_GET_TUPLE_ARG_VECTOR(type_info);
-                for (i = 0; i < arity; i++) {
-                   /* type_infos are counted from one */
-                   new_data_ptr[i] = copy(&data_value[i],
-                        (const MR_TypeInfo) arg_typeinfo_vector[i + 1],
-                        lower_limit, upper_limit);
+                        arg_typeinfo_vector =
+                            MR_TYPEINFO_GET_TUPLE_ARG_VECTOR(type_info);
+                        for (i = 0; i < arity; i++) {
+                           /* type_infos are counted from one */
+                           new_data_ptr[i] = copy(&data_value[i],
+                                (const MR_TypeInfo) arg_typeinfo_vector[i + 1],
+                                lower_limit, upper_limit);
+                        }
+                        leave_forwarding_pointer(data_ptr, new_data);
                 }
-                leave_forwarding_pointer(data_ptr, new_data);
             } else {
                 new_data = data;
                 found_forwarding_pointer(data);


--- library/std_util.m	2000/09/16 03:30:53	1.1
+++ library/std_util.m	2000/09/17 12:13:01
@@ -1915,19 +1915,24 @@
 
                 arity = MR_TYPEINFO_GET_TUPLE_ARITY(type_info);
     
-                incr_hp_msg(new_data, arity, MR_PROC_LABEL,
-                    ""<created by std_util:construct/3>"");
-    
-                arg_list = ArgList;
-                for (i = 0; i < arity; i++) {
-                    MR_field(MR_mktag(0), new_data, i) =
-                        MR_field(MR_mktag(0), MR_list_head(arg_list),
-                            UNIV_OFFSET_FOR_DATA);
-                    arg_list = MR_list_tail(arg_list);
-                }
-
-                if (! MR_list_is_empty(arg_list)) {
-                    MR_fatal_error(""excess arguments in std_util:construct"");
+                if (arity == 0) {
+                    new_data = NULL;
+                } else {
+                    incr_hp_msg(new_data, arity, MR_PROC_LABEL,
+                            ""<created by std_util:construct/3>"");
+            
+                    arg_list = ArgList;
+                    for (i = 0; i < arity; i++) {
+                        MR_field(MR_mktag(0), new_data, i) =
+                                MR_field(MR_mktag(0), MR_list_head(arg_list),
+                                UNIV_OFFSET_FOR_DATA);
+                        arg_list = MR_list_tail(arg_list);
+                    }
+
+                    if (! MR_list_is_empty(arg_list)) {
+                        MR_fatal_error(
+                                ""excess arguments in std_util:construct"");
+                    }
                 }
             }
             break;
@@ -1976,13 +1981,17 @@
 	/*
 	** Create the tuple.
 	*/
-	incr_hp_msg(new_data, Arity, MR_PROC_LABEL,
-		""<created by std_util:construct_tuple/1>"");
-	for (i = 0; i < Arity; i++) {
-		arg_value = MR_field(MR_mktag(0), MR_list_head(Args),
-				UNIV_OFFSET_FOR_DATA);
-		MR_field(MR_mktag(0), new_data, i) = arg_value;
-		Args = MR_list_tail(Args);
+	if (Arity == 0) {
+		new_data = NULL;
+	} else {
+		incr_hp_msg(new_data, Arity, MR_PROC_LABEL,
+			""<created by std_util:construct_tuple/1>"");
+		for (i = 0; i < Arity; i++) {
+			arg_value = MR_field(MR_mktag(0), MR_list_head(Args),
+					UNIV_OFFSET_FOR_DATA);
+			MR_field(MR_mktag(0), new_data, i) = arg_value;
+			Args = MR_list_tail(Args);
+		}
 	}
 
 	/*
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list