Hi, Are there cases in the Ada syntax where a discrete_subtype_definition (RM 3.6 (6)) is expected to be determined at compile-time? For instance, for array indices or "for" loops, it can be static or dynamic. Same for subtypes. procedure SD is A : array (1 .. 5) of Integer; type XYZ is (X, Y, Z); begin for I in 1 .. 3 loop declare B : array (1 .. I) of Integer; -- I is a variable begin for J in 1 .. I loop -- I is a variable B (J) := J; end loop; end; end loop; for E in XYZ loop declare subtype S is XYZ range X .. E; -- E is a variable begin null; end; end loop; end; _________________________ Gautier's Ada programming https://hacadacompiler.sourceforge.io/ NB: follow the above link for a valid e-mail address
Le 07/06/2020 à 11:27, gautier_niouzes@hotmail.com a écrit : > Are there cases in the Ada syntax where a discrete_subtype_definition (RM 3.6 (6)) is expected to be determined at compile-time? > > For instance, for array indices or "for" loops, it can be static or dynamic. > Same for subtypes. No. The basic principle is that types are static (they determine the underlying representation) and subtypes are dynamic. But nothing prevents a compiler from optimizing cases where the subtype is actually static... -- J-P. Rosen Adalog 2 rue du Docteur Lombard, 92441 Issy-les-Moulineaux CEDEX Tel: +33 1 45 29 21 52, Fax: +33 1 45 29 25 00 http://www.adalog.fr
On 2020-06-07 13:40, J-P. Rosen wrote:
> Le 07/06/2020 à 11:27, gautier_niouzes@hotmail.com a écrit :
>> Are there cases in the Ada syntax where a discrete_subtype_definition (RM 3.6 (6)) is expected to be determined at compile-time?
>>
>> For instance, for array indices or "for" loops, it can be static or dynamic.
>> Same for subtypes.
>
> No. The basic principle is that types are static (they determine the
> underlying representation) and subtypes are dynamic.
Subtype indications in case statements and record type declarations with
variant parts must be static.
But AFAIK subtypes used as array indices are never required to be static.
--
Niklas Holsti
niklas holsti tidorum fi
. @ .
On 2020-06-07 14:36, Niklas Holsti wrote:
> On 2020-06-07 13:40, J-P. Rosen wrote:
>> Le 07/06/2020 à 11:27, gautier_niouzes@hotmail.com a écrit :
>>> Are there cases in the Ada syntax where a discrete_subtype_definition
>>> (RM 3.6 (6)) is expected to be determined at compile-time?
>>>
>>> For instance, for array indices or "for" loops, it can be static or
>>> dynamic.
>>> Same for subtypes.
>>
>> No. The basic principle is that types are static (they determine the
>> underlying representation) and subtypes are dynamic.
>
> Subtype indications in case statements and record type declarations with
> variant parts must be static.
>
> But AFAIK subtypes used as array indices are never required to be static.
However, RM 4.9.1 defines when two ranges statically match, and refers
to the use that concept in RM 12.5.3, Formal Array Types. This may be a
case where some index subtypes should be static for things to work as
the programmer wants.
--
Niklas Holsti
niklas holsti tidorum fi
. @ .
> No. The basic principle is that types are static (they determine the
> underlying representation) and subtypes are dynamic.
Well, there are obviously exceptions to that basic principle:
procedure SD2 is
begin
for I in 1 .. 3 loop
declare
type T is array (1 .. I) of Integer; -- I is a variable
B: T;
begin
null;
end;
end loop;
end;
:-)
On 6/7/20 11:27 AM, gautier_niouzes@hotmail.com wrote:
>
> procedure SD is
> A : array (1 .. 5) of Integer;
> type XYZ is (X, Y, Z);
> begin
> for I in 1 .. 3 loop
> declare
> B : array (1 .. I) of Integer; -- I is a variable
> begin
> for J in 1 .. I loop -- I is a variable
> B (J) := J;
> end loop;
> end;
> end loop;
> for E in XYZ loop
> declare
> subtype S is XYZ range X .. E; -- E is a variable
> begin
> null;
> end;
> end loop;
> end;
The things you have marked as variables are all constants. They're not static,
but you can't assign to them.
--
Jeff Carter
"How'd you like to hide the egg and gurgitate
a few saucers of mocha java?"
Never Give a Sucker an Even Break
101
On 6/7/20 2:13 PM, gautier_niouzes@hotmail.com wrote:
>> No. The basic principle is that types are static (they determine the
>> underlying representation) and subtypes are dynamic.
>
> Well, there are obviously exceptions to that basic principle:
>
> procedure SD2 is
> begin
> for I in 1 .. 3 loop
> declare
> type T is array (1 .. I) of Integer; -- I is a variable
> B: T;
> begin
> null;
> end;
> end loop;
> end;
Conceptually, this declaration is equivalent to
type /anon/ is array (Integer range <>) of Integer;
subtype T is /anon/ (1 .. I);
So the (anonymous) type is static, but the (first-named) subtype is not.
--
Jeff Carter
"How'd you like to hide the egg and gurgitate
a few saucers of mocha java?"
Never Give a Sucker an Even Break
101
On Sunday, June 7, 2020 at 3:02:56 PM UTC+2, Jeffrey R. Carter wrote:
> On 6/7/20 2:13 PM, gautier_niouzes@hotmail.com wrote:
> >> No. The basic principle is that types are static (they determine the
> >> underlying representation) and subtypes are dynamic.
> >
> > Well, there are obviously exceptions to that basic principle:
> >
> > procedure SD2 is
> > begin
> > for I in 1 .. 3 loop
> > declare
> > type T is array (1 .. I) of Integer; -- I is a variable
> > B: T;
> > begin
> > null;
> > end;
> > end loop;
> > end;
>
> Conceptually, this declaration is equivalent to
>
> type /anon/ is array (Integer range <>) of Integer;
> subtype T is /anon/ (1 .. I);
>
> So the (anonymous) type is static, but the (first-named) subtype is not.
...plus, the keyword "type" is used and not "subtype". And /anon/ could itself be dynamic (an array of a named dynamic (sub)type).
So basically types are static, except when they aren't ;-)
Am Sonntag, 7. Juni 2020 15:14:49 UTC+2 schrieb gautier...@hotmail.com:
> ...plus, the keyword "type" is used and not "subtype". And /anon/ could itself be dynamic (an array of a named dynamic (sub)type).
> So basically types are static, except when they aren't ;-)
Nonono, types in Ada are always anonymous. What you name in a *type declaration* is the *first subtype*.
type My_Int is range 1 .. 10;
The anonymous type of this type declaration comprises the complete set of mathematical integers (only restricted by storage). Named numbers make use of this fact:
Big: constant := My_Int'Base'Last + 10**100;
Here, the "+" operator is that of My_Int'Base.
> Nonono, types in Ada are always anonymous. What you name in a *type declaration* is the *first subtype*.
OK, found the reference (3.2.1 (6)). Thanks.
So, what is declared following the keyword "type" is actually a "first subtype", right ?
Then, to summarize, whether you use the keyword "type" or "subtype", it is actually a subtype and can be dynamic (not too wysiwig, but there are surely some good reasons behind that concept).
Back to the question, the purely static cases of discrete_subtype_definition seem to be quite restricted (Niklas listed 2 cases - thanks!).
Le 07/06/2020 à 13:36, Niklas Holsti a écrit : > On 2020-06-07 13:40, J-P. Rosen wrote: >> Le 07/06/2020 à 11:27, gautier_niouzes@hotmail.com a écrit : >>> Are there cases in the Ada syntax where a discrete_subtype_definition >>> (RM 3.6 (6)) is expected to be determined at compile-time? >>> >>> For instance, for array indices or "for" loops, it can be static or >>> dynamic. >>> Same for subtypes. >> >> No. The basic principle is that types are static (they determine the >> underlying representation) and subtypes are dynamic. > > Subtype indications in case statements and record type declarations with > variant parts must be static. > But these are subtype indications, not subtype definitions. -- J-P. Rosen Adalog 2 rue du Docteur Lombard, 92441 Issy-les-Moulineaux CEDEX Tel: +33 1 45 29 21 52, Fax: +33 1 45 29 25 00 http://www.adalog.fr
On Sunday, June 7, 2020 at 11:02:29 PM UTC+2, J-P. Rosen wrote: > But these are subtype indications, not subtype definitions. RM 3.6 (6) discrete_subtype_definition ::= discrete_subtype_indication | range http://www.ada-auth.org/standards/2xrm/html/RM-3-6.html#p6 I'm afraid, Niklas has won this time :-) .
I have made myself somehow similar questions, and found workarounds using subtype predicates. http://www.ada-auth.org/standards/12rat/html/Rat12-2-5.html reinert søndag 7. juni 2020 11.27.33 UTC+2 skrev gautier...@hotmail.com følgende: > Hi, > > Are there cases in the Ada syntax where a discrete_subtype_definition (RM 3.6 (6)) is expected to be determined at compile-time? > > For instance, for array indices or "for" loops, it can be static or dynamic. > Same for subtypes. > > procedure SD is > A : array (1 .. 5) of Integer; > type XYZ is (X, Y, Z); > begin > for I in 1 .. 3 loop > declare > B : array (1 .. I) of Integer; -- I is a variable > begin > for J in 1 .. I loop -- I is a variable > B (J) := J; > end loop; > end; > end loop; > for E in XYZ loop > declare > subtype S is XYZ range X .. E; -- E is a variable > begin > null; > end; > end loop; > end; > _________________________ > Gautier's Ada programming > https://hacadacompiler.sourceforge.io/ > NB: follow the above link for a valid e-mail address