[m-rev.] diff: implement array__make_empty_array on il backend.

Peter Ross pro at missioncriticalit.com
Tue Dec 3 18:25:52 AEDT 2002


fjh wrote:

> On 02-Dec-2002, Peter Ross <pro at missioncriticalit.com> wrote:
> > Implement array__make_empty_array on the IL backend.
> >
> > library/array.m:
> > Use the null pointer to signify an empty array in
> > array__make_empty_array.  Check for this null pointer before
> > manipulating an array object in all the relevant places.
>
> I think this is a bad idea.  IMHO we should represent empty arrays as
> arrays of length zero, not as null pointers.  This is important for
> interoperability with other languages.  Also, it's more efficient in
> the common case of non-empty arrays.
>
I tried that first, by creating an array of size 0 with elem type of
System.Object.  Unfortunately we will attempt to cast this array to a more
specific type in the code which uses this result, and get an invalid cast
exception.  So there were two solutions.  The easy one which was to use null
to signify the empty array.  The more difficult one which was to write a lot
of code to determine the correct type name from the RTTI, remembering that
not all types map to high-level data names, and use the reflection framework
to get the representation of the type from the name.  I took the easy one.

A possible third solution would be to add an extra field to the RTTI which
has the type of a pointer to the IL representation of the Mercury type.
Then we could use the reflection framework to get the type.  This I think
would be the best option, but again would take quite a lot of work.

The current solution is the minimum amount of work which allows arrays to be
used.


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.423 / Virus Database: 238 - Release Date: 27/11/2002

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