[m-dev.] [reuse] for review: compare and unify for univ

Peter Ross petdr at miscrit.be
Sat Oct 14 01:00:13 AEDT 2000


On Fri, Oct 13, 2000 at 11:32:07AM +1100, Fergus Henderson wrote:
> On 12-Oct-2000, Peter Ross <Peter.Ross at cs.kuleuven.ac.be> wrote:
> > mercury.c:
> >     Implement compare and unify for the univ type.
> > 
> > Index: mercury.c
> > ===================================================================
> > RCS file: /home/mercury1/repository/mercury/runtime/mercury.c,v
> > retrieving revision 1.10.2.1
> > diff -u -r1.10.2.1 mercury.c
> > --- mercury.c	2000/09/25 17:08:53	1.10.2.1
> > +++ mercury.c	2000/10/12 14:44:17
> > @@ -442,7 +442,24 @@
> >  bool
> >  mercury__std_util____Unify____univ_0_0(MR_Univ x, MR_Univ y)
> >  {
> > -	SORRY("unify for univ");
> > +#ifdef MR_HIGHLEVEL_DATA
> > +	SORRY("unify for highlevel data univ");
> 
> I don't think the #ifdef is needed.
> The code you've got should work fine for MR_HIGHLEVEL_DATA too.
> 
> > +#else
> > +	MR_TypeInfo     typeinfo_x, typeinfo_y;
> > +	MR_Word         value_x, value_y;
> > +	int             comp;
> > +
> > +	MR_unravel_univ(x, typeinfo_x, value_x);
> > +	MR_unravel_univ(y, typeinfo_y, value_y);
> > +
> > +	comp = MR_compare_type_info(typeinfo_x, typeinfo_y);
> > +
> > +	if (comp != MR_COMPARE_EQUAL) {
> > +		return FALSE;
> > +	}
> > +
> > +	return mercury__builtin__unify_2_p_0(typeinfo_x, value_x, value_y);
> 
> You should change that to
> 
> 	return mercury__builtin__unify_2_p_0(typeinfo_x,
> 		(MR_Box) value_x, (MR_Box) value_y);
> 
> otherwise you'll get a warning/error from the C compiler.
> 
> > +#endif
> 
> >  
> >  bool
> > @@ -593,7 +610,25 @@
> >  mercury__std_util____Compare____univ_0_0(MR_Comparison_Result *result,
> >  	MR_Univ x, MR_Univ y)
> >  {
> > -	SORRY("compare for univ");
> > +#ifdef MR_HIGHLEVEL_DATA
> > +	SORRY("compare for highlevel data univ");
> > +#else
> > +	MR_TypeInfo     typeinfo_x, typeinfo_y;
> > +	MR_Word         value_x, value_y;
> > +	int             comp;
> > +
> > +	MR_unravel_univ(x, typeinfo_x, value_x);
> > +	MR_unravel_univ(y, typeinfo_y, value_y);
> > +
> > +	comp = MR_compare_type_info(typeinfo_x, typeinfo_y);
> > +
> > +	if (comp != MR_COMPARE_EQUAL) {
> > +		return comp;
> 
> That should be
> 		*result = comp;
> 		return;
> 
Thanks.

> > +	}
> > +
> > +	return mercury__builtin__compare_3_p_0(typeinfo_x, result,
> > +			value_x, value_y);
> 
> That should be just
> 
> 	mercury__builtin__compare_3_p_0(typeinfo_x, result,
> 			value_x, value_y);
> 
I actually needed to add casts here to avoid warnings.

Also why do we have to types MR_TypeInfo and MR_Type_Info, as I have to
cast one to another to avoid warnings.


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


Estimated hours taken: 1

mercury.c:
    Implement compare and unify for the univ type in the hlc grades.

Index: mercury.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury.c,v
retrieving revision 1.11
diff -u -r1.11 mercury.c
--- mercury.c	2000/09/18 11:52:27	1.11
+++ mercury.c	2000/10/13 13:36:14
@@ -442,7 +442,21 @@
 bool
 mercury__std_util____Unify____univ_0_0(MR_Univ x, MR_Univ y)
 {
-	SORRY("unify for univ");
+	MR_TypeInfo     typeinfo_x, typeinfo_y;
+	MR_Word         value_x, value_y;
+	int             comp;
+
+	MR_unravel_univ(x, typeinfo_x, value_x);
+	MR_unravel_univ(y, typeinfo_y, value_y);
+
+	comp = MR_compare_type_info(typeinfo_x, typeinfo_y);
+
+	if (comp != MR_COMPARE_EQUAL) {
+		return FALSE;
+	}
+
+	return mercury__builtin__unify_2_p_0((MR_Type_Info) typeinfo_x,
+			(MR_Box) value_x, (MR_Box) value_y);
 }
 
 bool
@@ -593,7 +607,22 @@
 mercury__std_util____Compare____univ_0_0(MR_Comparison_Result *result,
 	MR_Univ x, MR_Univ y)
 {
-	SORRY("compare for univ");
+	MR_TypeInfo     typeinfo_x, typeinfo_y;
+	MR_Word         value_x, value_y;
+	int             comp;
+
+	MR_unravel_univ(x, typeinfo_x, value_x);
+	MR_unravel_univ(y, typeinfo_y, value_y);
+
+	comp = MR_compare_type_info(typeinfo_x, typeinfo_y);
+
+	if (comp != MR_COMPARE_EQUAL) {
+		*result = comp;
+		return;
+	}
+
+	return mercury__builtin__compare_3_p_0((MR_Type_Info) typeinfo_x,
+			result, (MR_Box) value_x, (MR_Box) value_y);
 }
 
 void

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