[m-rev.] for review: std_util__arg_name

Fergus Henderson fjh at cs.mu.OZ.AU
Mon Sep 24 15:01:52 AEST 2001


On 24-Sep-2001, Michael Day <mikeday at bigpond.net.au> wrote:
> 
> Adding std_util__arg_name for retrieving the field name (if any) of a
> functor argument.
> 
> (I haven't been able to actually compile this as I haven't been able to
> install a recent enough version of the compiler, so anyone who feels like
> looking at it please look carefully... sorry)

Is there some problem in the release-of-the-day binaries or sources
that is preventing their installation?

> Index: library/std_util.m
...
> +bool
> +ML_arg_name(MR_TypeInfo type_info, MR_Word *term_ptr, int arg_index,
> +    MR_String *arg_name)
> +{
> +    ML_Expand_Chosen_Arg_Only_Info	expand_info;
> +
> +    ML_expand_chosen_arg_only(type_info, term_ptr, arg_index, &expand_info);
> +    ML_abort_if_type_is_noncanonical(expand_info, ""argument/2"");
> +
> +        /* Check range */
> +    if (expand_info.chosen_index_exists) {
> +        *arg_name = expand_info.chosen_arg_name;

That line is not correctly indented.

> +		return TRUE;
> +    }
> +
> +    return FALSE;
> +}
> +
> +/*
>  ** ML_named_arg_num() takes the address of a term, its type, and an argument
>  ** name. If the given term has an argument with the given name, it succeeds and
>  ** returns the argument number (counted starting from 0) of the argument;
> @@ -3277,6 +3324,31 @@
>          if (success) {
>              Argument = *argument_ptr;
>          }
> +    }
> +
> +    MR_restore_transient_registers();
> +    SUCCESS_INDICATOR = success;
> +}").
> +
> +arg_name(T, ArgIndex) =
> +    ( if Res = 0 then no else yes(Name) ) :- arg_name0(T, ArgIndex, Name, Res).
> +
> +:- pred arg_name0(T, int, string, int).
> +:- mode arg_name0(in, in, out, out) is semidet.
> +
> +:- pragma foreign_proc("C",
> +	arg_name0(Term::in, ArgIndex::in, Name::out, Res::out),
> +        will_not_call_mercury, "
> +{
> +    MR_String   argument_name;
> +    bool        success;
> +
> +    MR_save_transient_registers();
> +    success = ML_arg_name(type_info, &Term, ArgumentIndex, argument_name);

- Where is `type_info' supposed to come from here?
- There's a bug with `ArgIndex' versus `ArgumentIndex'.
- Shouldn't that be `&argument_name' rather than `argument_name'?

Please install an up-to-date compiler and make sure that
there aren't any compile errors.

Also s/arg_name0/arg_name_2/g

> Index: runtime/mercury_ml_expand_body.h
> ===================================================================
> RCS file: /home/mercury1/repository/mercury/runtime/mercury_ml_expand_body.h,v
> retrieving revision 1.2
> diff -u -r1.2 mercury_ml_expand_body.h
> --- runtime/mercury_ml_expand_body.h	2001/07/12 01:30:30	1.2
> +++ runtime/mercury_ml_expand_body.h	2001/09/24 01:50:46
> @@ -310,6 +310,12 @@
>                              MR_pseudo_type_info_is_ground(
>                                  functor_desc->MR_du_functor_arg_types[chosen]);
>                      }
> +		    if (functor_desc->MR_du_functor_arg_names != NULL) {
> +			expand_info->chosen_arg_name =
> +			    functor_desc->MR_du_functor_arg_names[chosen];
> +		    } else {
> +			expand_info->chosen_arg_name = NULL;
> +		    }
>                  } else {
>                      expand_info->chosen_index_exists = FALSE;
>                  }

Here you only handle the MR_TYPECTOR_REP_DU case.  You also need to handle
the MR_TYPECTOR_REP_NOTAG and MR_TYPECTOR_REP_NOTAG_GROUND cases.

Please post another diff for review when you've addressed these issues.

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