[m-dev.] for review: accessing fields by name in mdb

Fergus Henderson fjh at cs.mu.OZ.AU
Mon Dec 18 17:34:56 AEDT 2000


On 18-Dec-2000, Zoltan Somogyi <zs at cs.mu.OZ.AU> wrote:
> For review by Tyson, Mark or Fergus.
> 
> The bug fix for ML_arg must be included in the release. The rest of this
> does not need to be, but it would be nice.

I'm not very keen on adding lots of new code this late.
But if you're very confident that it won't cause any problems,
it's OK with me.

> Also, for now I took field names to contain letters, numbers and/or
> underscores. Simon, are there restrictions on what characters can appear
> in field names? I could not find any in the reference manual.

The reference manual is indeed unclear on this point, but a field name
can be any nullary functor (i.e. functor with no arguments).

A nullary functor is either a name token (see the "Tokens" section of
the "Syntax" chapter), `{}' or `[]'.  Name tokens can be either quoted
or unquoted.  Unquoted name tokens are letters, digits, and/or
underscores, but they must start with a lowercase letter.  Quoted name
tokens use 'single quotes'.  It's probably OK for now if mdb doesn't
support quoted field names, `{}' or `[]'.

> ----------------------------------------------------
> 
> In mdb's print and browse commands, allow the field to be printed to be
> specified by name as well as by number. This required extending the RTTI
> for notag types to record field names.
> 
> +++ library/std_util.m	2000/12/18 00:28:42
> +    /*
> +    ** NB. ML_named_arg_num() is used in mercury_trace_vars.c.
> +    */
> +extern  bool    ML_named_arg_num(MR_TypeInfo type_info, MR_Word *term_ptr,
> +                    char *arg_name, int *arg_num_ptr);
> +
>  ").

s/char */const char */

> +/*
> +** ML_named_arg() 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;
> +** if it doesn't, it fails (i.e. returns FALSE).
> +*/
...
> +        case MR_TYPECTOR_REP_EQUIV:
> +            eqv_type_info = MR_create_type_info(
> +                MR_TYPEINFO_GET_FIRST_ORDER_ARG_VECTOR(type_info),
> +                type_ctor_info->type_layout.layout_equiv);


The documentation for ML_named_arg() should contain the same warning
as for MR_create_type_info: you need to wrap MR_save_transient_hp()
and MR_restore_transient_hp() around calls to ML_named_arg(), since
ML_named_arg() calls MR_create_type_info().  (The call from
trace/mercury_trace_vars.c is OK, since we do MR_save_transient_hp()
and MR_restore_transient_hp() around the call to MR_trace().  But the
documentation should warn about this in case we add other calls.)

> Index: trace/mercury_trace_vars.c
...
> +/* ML_named_arg_num() is defined in std_util.m */
> +extern	bool 	ML_named_arg_num(MR_TypeInfo term_type_info, MR_Word *term,
> +			char *arg_name, int *arg_num_ptr);

s/char */const char */

Apart from that, this change looks fine.

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