[m-dev.] for review: add type_ctor_reps

Tyson Dowd trd at cs.mu.OZ.AU
Wed Jun 30 08:49:13 AEST 1999


On 30-Jun-1999, Fergus Henderson <fjh at cs.mu.OZ.AU> wrote:
> On 29-Jun-1999, Tyson Dowd <trd at cs.mu.OZ.AU> wrote:
> > Add MR_TYPECTOR_REP_* to the type_ctor_info to describe the
> > representation of this type.
> > 
> > Use this representation in code that uses RTTI.
> 
> The rationale here could explain things in a little more detail.
> (For instance, what did we use previously? What's the advantage of
> using MR_TYPECTOR_REP_* instead?)

I've added:

We want to do this because it allows us to check quickly to see
what kind of data representation is being used.  Previously this
information was spread throughout the type_ctor_layout and
type_ctor_functors data structures.  It was complex to interpret
and contained a lot of unnecessary duplication.

We can now omit data structures such as the type_ctor_layout in many
cases (it is only necessary for discriminated unions).  Because we rule
out some of the possible alternatives, the encodings used in the
type_ctor_layout can be simplified.  Also, the functors indicator in
type_ctor_functors can be removed, as it subsumed by this data
structure.

> > runtime/mercury_deep_copy_body.h:
> ...
> > 	Also, fix a bug in deep_copy when copying floating point values.
> > 	I'm not sure when this stopped working, or if this is exactly
> > 	the right fix, but it is more correct than the previous code.
> > 
> > Index: runtime/mercury_deep_copy_body.h
> ...
> > -        case MR_DATAREP_FLOAT:
> > +        case MR_TYPECTOR_REP_FLOAT:
> >              #ifdef BOXED_FLOAT
> >                  if (in_range(data_value)) {
> > -                    incr_saved_hp(new_data, FLOAT_WORDS);
> > -                    field(0, new_data, 0) = *data_value;
> > +		    new_data = word_to_float(float_to_word(data));
> > +//                    incr_saved_hp(new_data, FLOAT_WORDS);
> > +//                   field(0, new_data, 0) = *data_value;
> >                      leave_forwarding_pointer(data_ptr, new_data);
> >                  } else {
> >                      new_data = data;
> 
> You should definitely not commit anything containing "//" comments,
> because they are not supported by the (1989) ANSI/ISO C standard.

Oops, sorry that was supposed to be removed.  I am quite surprised
that it worked at all.

> 
> Your fix won't quite work, because word_to_float() uses
> incr_hp() not incr_saved_hp().  You should add calls to
> restore_transient_hp() and save_transient_hp() before and
> after the memory allocation:
> 
>                 if (in_range(data_value)) {
> 		    restore_transient_hp();
> 		    new_data = word_to_float(float_to_word(data));
> 		    save_transient_hp();
>                     leave_forwarding_pointer(data_ptr, new_data);
>                 } else {

Fixed now.  Thanks.

> 
> > +++ mercury_type_info.h	1999/06/22 17:31:00
> > @@ -250,9 +250,9 @@
> >  */
> >  
> >  #define MR_TYPE_CTOR_INFO_HO_PRED				\
> > -	((const Word *) &mercury_data___type_ctor_info_pred_0)
> > +	((MR_TypeCtorInfo) (const Word *) &mercury_data___type_ctor_info_pred_0)
> >  #define MR_TYPE_CTOR_INFO_HO_FUNC				\
> > -	((const Word *) &mercury_data___type_ctor_info_func_0)
> > +	((MR_TypeCtorInfo) (const Word *) &mercury_data___type_ctor_info_func_0)
> 
> Why are the double casts needed here?

They aren't.  I've removed them.


-- 
The quantum sort: 
	while (!sorted) { do_nothing(); }
Tyson Dowd   <tyson at tyse.net>   http://tyse.net/
--------------------------------------------------------------------------
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