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

Fergus Henderson fjh at cs.mu.OZ.AU
Tue Dec 3 18:55:40 AEDT 2002


On 03-Dec-2002, Peter Ross <pro at missioncriticalit.com> wrote:
> 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.

Well, I guess that is OK for now.
But there should be an XXX comment in the source explaining this issue.

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