comp.lang.ada
 help / color / mirror / Atom feed
From: Robert A Duff <bobduff@world.std.com>
Subject: Re: Array 'downto' [Was: Implementing an elegant range type]
Date: Wed, 28 Mar 2001 22:35:30 GMT
Date: 2001-03-28T22:35:30+00:00	[thread overview]
Message-ID: <wccwv99serx.fsf@world.std.com> (raw)
In-Reply-To: 99ggfn$14lpr$2@ID-25716.news.dfncis.de

"Nick Roberts" <nickroberts@adaos.worldonline.co.uk> writes:

> I intend (eventually ;-) to provide a representation attribute for this
> purpose, for array objects and types, in my compiler.
> 
> For any array object or type A, if
> 
>    A(n)'Reverse_Element_Order
> 
> of type Standard.Boolean, is False, the elements of the nth dimension of A
> will be placed in memory with the element corresponding to the lowest index
> value in the lowest memory address. If it is True, the elements will be
> placed with the element corresponding to the highest index value in the
> lowest memory address. The default will be False. The subscript can be
> omitted for the first dimension.

I've toyed with that idea myself, but I'm not sure what use it is in
practise.

> Additionally, for any multidimensional array object or type A,
> 
>    pragma Convention(Fortran,A);
> 
> will cause the representation to be leftmost dimension varying fastest. All
> other conventions will cause the representation to be rightmost dimension
> varying fastest.

For types, that's what the RM already says, and I think many compilers
implement it.  But it seems problematic for objects.  At least, you
would have to have various restrictions.  For example, if the array is a
by-reference type, you can't be representing different objects
differently, because you might pass them as parameters.  For a type that
allowed by-copy parameter passing, you could do a massive conversion on
parameter passing, I suppose.

> Other implementors should feel free to copy these ideas if they fancy. It
> should be understood that for certain environments (e.g. a virtual machine),
> they will be unimplementable.

I don't understand why.  I can see cases where they are unimplementable,
but I don't see what it has to do with the environment.

> I am toying with the idea of a pragma Split_Array, which, when applied to an
> array object or type, causes the array to be placed in memory as a set of
> arrays (called 'columns'), one for each indivisible subcomponent of the
> array's component type. If this causes columns to have a convenient width
> (e.g. a byte or word), it could make some accesses to the array much faster
> (at the expense of making some other accesses more complicated and slower).
> Split_Array would be a kindred pragma to Pack (but they would not be
> mutually exclusive, as one may wish to pack the columns).

I've pondered the same idea myself.  Basically, you are laying things
out "inside out" -- that is, you're turning (eg) an array of records
into a record of arrays.  It sounds awfully hard to get this right, in
general, and you will need certain restrictions.  Consider passing a
component of the array-of-records as a parameter -- you need to gin up a
record, but you can only do that if by-copy is allowed.  (Or if you're
willing to implement by-ref in an extraordinarily complicated and
inefficient manner.)

In the end, I decided this kind of thing isn't worth the trouble.
Let the programmer declare a record-of-arrays, if that's more
efficient.  And if that's ugly, hide the ugliness in a package body.

- Bob



  parent reply	other threads:[~2001-03-28 22:35 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-03-19 17:45 Implementing an elegant range type Chad R. Meiners
2001-03-19 18:38 ` Mark Lundquist
2001-03-19 20:50   ` Chad R. Meiners
2001-03-22 22:20     ` Nick Roberts
2001-03-23 22:29       ` Brian Rogoff
2001-03-20  4:48   ` Dr Adrian Wrigley
2001-03-20 15:31     ` Robert A Duff
2001-03-21  1:21       ` Dr Adrian Wrigley
2001-03-21  3:58         ` Brian Rogoff
2001-03-22 23:00         ` Array 'downto' [Was: Implementing an elegant range type] Nick Roberts
2001-03-26 18:28           ` Stephen Leake
2001-03-28 22:35           ` Robert A Duff [this message]
2001-03-21 22:55 ` Implementing an elegant range type Chad R. Meiners
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox