comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: setting an address with pure?
Date: Mon, 13 Jul 2015 14:10:07 -0500
Date: 2015-07-13T14:10:07-05:00	[thread overview]
Message-ID: <mo12eh$als$1@loke.gir.dk> (raw)
In-Reply-To: lypp3zkueh.fsf@pushface.org

"Simon Wright" <simon@pushface.org> wrote in message 
news:lypp3zkueh.fsf@pushface.org...
> "Randy Brukardt" <randy@rrsoftware.com> writes:
>
>> "Simon Wright" <simon@pushface.org> wrote in message
>> news:lyy4iokzci.fsf@pushface.org...
>>>I need to specify the address at which a hardware object appears.
>>>
>>> This works:
>>>
>>>   PIOA : PIO
>>>     with
>>>       Import,
>>>       Convention => Ada,
>>>       Address => System.Storage_Elements.To_Address (16#400E0E00#);
>>>
>>> but means that I can't declare the package Pure (or even Preelaborate).
>>
>> You can't have a variable at library level in a Pure package (there
>> shall be no state), so it makes no sense at all for such a package to
>> contain any hardware objects.
>>
>> I don't see any reason why this can't be Preelaborated
>> (System.Storage_Elements is Pure, after all); that depends on the
>> initialization of the type PIO (it needs to have
>> "preelaborable_initialization"; use the pragma if in doubt).
>
> GNAT says that the call to System.Storage_Elements.To_Address is invalid
> because "non-static call not allowed in preelaborated unit", whether
> Preelaborable_Initialization is applied or not. I take it that
> To_Address isn't static because its result type isn't scalar? (4.9(19))

To_Address is a function, not an operator. 4.9(19) does not apply (it only 
applies to predefined operators, and To_Address is neither an operator nor 
predefined [language-defined /= predefined]). There is no way to have a 
static function in Ada to date. (We've been taking about adding an aspect on 
expression functions to allow that.)

This seems like a bug in Ada to me, it's a consequence of making Address a 
private type (it's not private in Janus/Ada because we didn't want the 
incompatibility that would have resulted, so I've never seen this before). 
It certainly seems wrong that an address clause for a hardware entity can't 
be used in a preelaborated unit.

> I think this may be a failure in a GNAT extension; To_Address has pragma
> Pure_Function applied to it, and[2]
>
>   "It specifies that the function Entity is to be considered pure for
>   the purposes of code generation. This means that the compiler can
>   assume that there are no side effects, and in particular that two
>   calls with identical arguments produce the same result. It also means
>   that the function can be used in an address clause."
>
> [1] http://www.ada-auth.org/standards/12rm/html/RM-4-9.html#p19
> [2] https://gcc.gnu.org/onlinedocs/gnat_rm/Pragma-Pure_005fFunction.html

Possibly. In "pedantic" mode, the function would have to be an error because 
implementation-defined stuff shouldn't be changing basic properties (like 
staticness) of language-defined subprograms. But it certainly makes sense to 
work-around this language design flaw.

I'd encourage you to post this problem on Ada-Comment, so that it gets on 
the ARG agenda. (If we end up with a static function aspect, it would make 
sense to apply it to To_Address.)

                                    Randy.


  reply	other threads:[~2015-07-13 19:10 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-10 11:48 Q: setting an address with pure? Simon Wright
2015-07-10 12:03 ` G.B.
2015-07-10 14:38   ` Simon Wright
2015-07-10 22:37 ` Randy Brukardt
2015-07-11  7:47   ` Simon Wright
2015-07-13 19:10     ` Randy Brukardt [this message]
2015-07-14  9:36       ` Mark Lorenzen
2015-07-13 23:41   ` RasikaSrinivasan
2015-07-14  7:38     ` Simon Wright
2015-07-14  7:42       ` Simon Wright
2015-07-11 10:35 ` Q: " Brian Drummond
2015-07-11 13:30   ` Simon Wright
2015-07-11 14:03     ` AdaMagica
2015-07-11 14:27       ` Simon Wright
2015-07-13 18:53         ` Randy Brukardt
2015-07-13 19:50           ` Simon Wright
2015-07-14 12:24     ` Brian Drummond
2015-07-15 15:50       ` rrr.eee.27
2015-07-15 18:45         ` Simon Wright
2015-07-16  9:21         ` Brian Drummond
2015-07-16 18:54           ` Simon Wright
2015-07-16 19:14           ` Randy Brukardt
replies disabled

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