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

Fergus Henderson fjh at cs.mu.OZ.AU
Fri Oct 13 11:32:07 AEDT 2000


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;

> +	}
> +
> +	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);

> +#endif
>  }

Otherwise that looks fine.

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3        |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
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