[m-rev.] for review: implement arg_cc in Mercury

Fergus Henderson fjh at cs.mu.OZ.AU
Sun Dec 1 02:38:43 AEDT 2002


On 30-Nov-2002, Peter Ross <pro at missioncriticalit.com> wrote:
> Implement arg_cc in Mercury using rtti_implementation.
> 
> library/deconstruct.m:
> 	Implement univ_arg_idcc as a cc_multi predicate with the
> 	success of the predicate encoded into a maybe type, as it is
> 	impossible to implement is as cc_nondet.

s/is as /it as/

> 	Change the C code version of univ_arg_idcc to match the
> 	Mercury versions behaviour.
> 	Delete the bogus modes of arg/4 and implement them as arg_cc/3
> 	instead.
> 
> library/std_util.m:
> 	Introduce a new type maybe_arg which is returned by arg_cc to
> 	return its result.
> 	Change arg_cc to have the correct determinism and type
> 	signature.
> 	Add utility predicates which allow us to construct values of
> 	the maybe type from a foreign language.
> 
> runtime/mercury_ml_arg_body.h:
> 	In the MR_NONCANON case this code is used inside a cc_multi
> 	predicate, so setting the SUCCESS_INDICATOR should be
> 	disabled.
> 
> tests/hard_coded/deconstruct_arg.m:
> 	Update the test case to test this new functionality.
> 
> Index: library/deconstruct.m
> ===================================================================
> RCS file: /home/mercury1/repository/mercury/library/deconstruct.m,v
> retrieving revision 1.15
> diff -u -r1.15 deconstruct.m
> --- library/deconstruct.m	30 Nov 2002 08:03:33 -0000	1.15
> +++ library/deconstruct.m	30 Nov 2002 15:14:57 -0000
> @@ -118,8 +118,12 @@
>  :- some [ArgT] pred arg(T, noncanon_handling, int, ArgT).
>  :- mode arg(in, in(do_not_allow), in, out) is semidet.
>  :- mode arg(in, in(canonicalize), in, out) is semidet.
> -:- mode arg(in, in(include_details_cc), in, out) is cc_nondet.
> -:- mode arg(in, in, in, out) is cc_nondet.
> +:- mode arg(in, in(include_details_cc), in, out) is erroneous.
> +:- mode arg(in, in, in, out) is semidet.
> +
> +	% See the documentation of std_util__arg_cc
> +:- pred arg_cc(T, int, std_util__maybe_arg).
> +:- mode arg_cc(in, in, out) is cc_multi.
>  
>  	% named_arg(Data, NonCanon, Name, Argument)
>  	%
> @@ -225,6 +229,7 @@
>  :- implementation.
>  
>  :- import_module int, require, rtti_implementation.
> +:- pragma foreign_import_module("C", std_util).
>  
>  %-----------------------------------------------------------------------------%
>  
> @@ -271,10 +276,18 @@
>  		univ_arg_can(Term, Index, Univ)
>  	;
>  		NonCanon = include_details_cc,
> -		univ_arg_idcc(Term, Index, Univ)
> +		error("deconstruct__arg called with include_details_cc")

This should be mentioned in the documentation for deconstruct__arg.

>  named_arg(Term, NonCanon, Name, Argument) :-
>  	(
>  		NonCanon = do_not_allow,
> @@ -298,7 +311,7 @@
>  			univ_arg_can(Term, Index, Univ)
>  		;
>  			NonCanon = include_details_cc,
> -			univ_arg_idcc(Term, Index, Univ)
> +			error("deconstruct__arg called with include_details_cc")
>  		)
>  	->
>  		Argument = univ_value(Univ)
> @@ -426,7 +439,7 @@
>  
>  :- pred univ_arg_dna(T::in, int::in, univ::out) is semidet.
>  :- pred univ_arg_can(T::in, int::in, univ::out) is semidet.
> -:- pred univ_arg_idcc(T::in, int::in, univ::out) is cc_nondet.
> +:- pred univ_arg_idcc(T::in, int::in, maybe(univ)::out) is cc_multi.
>  
>  :- pred univ_named_arg_dna(T::in, string::in, univ::out) is semidet.
>  :- pred univ_named_arg_can(T::in, string::in, univ::out) is semidet.
> @@ -471,22 +484,30 @@
>  }").
>  
>  :- pragma foreign_proc("C",
> -	univ_arg_idcc(Term::in, Index::in, Argument::out),
> +	univ_arg_idcc(Term::in, Index::in, MaybeArg::out),
>  	[will_not_call_mercury, thread_safe, promise_pure],
>  "{
> -#define	TYPEINFO_ARG		TypeInfo_for_T
> -#define	TERM_ARG		Term
> -#define	SELECTOR_ARG		Index
> -#define	SELECTED_ARG		Argument
> -#define	SELECTED_TYPE_INFO	TypeInfo_for_ArgT
> -#define	NONCANON		MR_NONCANON_CC
> -#include ""mercury_ml_arg_body.h""
> -#undef	TYPEINFO_ARG
> -#undef	TERM_ARG
> -#undef	SELECTOR_ARG
> -#undef	SELECTED_ARG
> -#undef	SELECTED_TYPE_INFO
> -#undef	NONCANON
> +	MR_Word Argument;
> +
> +	#define	TYPEINFO_ARG		TypeInfo_for_T
> +	#define	TERM_ARG		Term
> +	#define	SELECTOR_ARG		Index
> +	#define	SELECTED_ARG		Argument
> +	#define	SELECTED_TYPE_INFO	TypeInfo_for_ArgT
> +	#define	NONCANON		MR_NONCANON_CC
> +	#include ""mercury_ml_arg_body.h""
> +	#undef	TYPEINFO_ARG
> +	#undef	TERM_ARG
> +	#undef	SELECTOR_ARG
> +	#undef	SELECTED_ARG
> +	#undef	SELECTED_TYPE_INFO
> +	#undef	NONCANON
> +
> +	if (success) {
> +		MaybeArg = ML_construct_maybe_yes((MR_Word) NULL, Argument);
> +	} else {
> +		MaybeArg = ML_construct_maybe_no((MR_Word) NULL);
> +	}
>  }").

You should use the type_ctor_info for univ rather than (MR_Word) NULL here.
Otherwise mdb may crash...

(I think I recall a similar issue in one of your earlier diffs which I
did not mention, although I forget exactly which one it was.)

[To be continued.]

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