[m-rev.] [dotnet-foreign] diff: use System.Array for mercury arrays

Fergus Henderson fjh at cs.mu.OZ.AU
Thu Aug 2 20:26:55 AEST 2001


On 02-Aug-2001, Tyson Dowd <trd at cs.mu.OZ.AU> wrote:
> On 02-Aug-2001, Fergus Henderson <fjh at cs.mu.OZ.AU> wrote:
> > This approach will require upcasts to convert from System.Array
> > to e.g. int32[] when calling routines such as e.g. array__init or
> > array__make_empty_array, which return values of type array(T),
> > from a context that is expecting a specific array type, e.g. array(int).
> 
> Upcasts?  Isn't this a downcast?

Yes, I meant to say downcast, sorry.

> > These upcasts will be similar to the unboxing that we currently do
> > to convert from System.Array to e.g. int when calling routines
> > that return values whose type is a type variable,
> > from a context that is expecting a specific type.
> 
> I think you meant System.Object to e.g. int

Yes, another typo/thinko, sorry.

> Note that I'm not adding any special support for safe arrays in C, the
> C backend will just map mlds__mercury_array_type to MR_Word and use the
> handwritten implementation.

Note that mapping to MR_Word is not right for the --high-level-data case.
It should continue to map `struct mercury__array__array_1_s *' in that
case, like it does currently.

> Yes, arrays are covariant.  It is a bit disturbing, but it does work.

I thought about it long and hard, and didn't find any holes...
so yes, it probably does work ;-)

I think that the reliance on array covariance is a definite drawback
to this proposal.  However, I suppose the advantages for interoperability
probably outweigh that.  So, I'm (grudgingly ;-) willing to go along with
this approach.

Note that for this scheme to work, the Mercury type_info will
need to contain a System.Type value, so that it can be passed to
Array.CreateInstance() in array__make_empty_array.
(The current code for array__make_empty_array won't work,
because it always creates arrays with type object[], which is
wrong in the case when you're trying to create an array with type int32[].)
I considered another alternative, namely using System.Type::GetType()
and passing it the appropriate type name string, which can be obtained
from names in the Mercury type_info, but that won't work for private
types.

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