comp.lang.ada
 help / color / mirror / Atom feed
From: Adam Beneschan <adambeneschan@gmail.com>
Subject: Re: Rough proposal to make some generic types static
Date: Mon, 21 Jul 2014 14:39:54 -0700 (PDT)
Date: 2014-07-21T14:39:54-07:00	[thread overview]
Message-ID: <45b2d813-f991-4c1c-b280-a1037bae8a66@googlegroups.com> (raw)
In-Reply-To: <lqju32$r3i$1@speranza.aioe.org>

On Monday, July 21, 2014 1:44:21 PM UTC-7, Victor Porton wrote:
> What in the RM signifies that Enum_Type (below) is not a static scalar
> type?
> 
> We should work on an amendment for a future version of Ada to make
> Enum_Type static?
> 
> Is it difficult to implement this?
> 
> Rationale is that the below code is useful in practice.
> 

Generics in the Ada language are designed so that they can be implemented either by "macro expansion" or "code sharing" [1].  In macro expansion, every time you instantiate a generic, the compiler treats it as if you had written all the code, substituting actual for formal types; the compiler thus generates code for each instantiation.  In code sharing, the compiler generates the code for the generic *once*, when it sees the generic; when you instantiate the generic, the compiler arranges things so that all the information it needs to know about the actual types is passed as parameters.

Using code sharing, it is not feasible for the compiler to generate code for a modular type if it doesn't know the type size in advance.  (Or at least that was the thinking when the decision was made to require the modulus to be static.  It may actually be possible to generate reasonably efficient code when the modulus is specifically of the form 2**N, where N is non-static.)

But, anyway, that's the rationale.

                                -- Adam


[1] Note that the language specification doesn't actually refer to those two models.  So if someone came up with a third model that would obey all the Ada rules, that would be legal also.


  parent reply	other threads:[~2014-07-21 21:39 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-21 20:44 Rough proposal to make some generic types static Victor Porton
2014-07-21 20:54 ` Victor Porton
2014-07-21 21:28   ` Niklas Holsti
2014-07-21 21:32     ` Victor Porton
2014-07-21 21:43       ` Niklas Holsti
2014-07-21 23:10       ` Randy Brukardt
2014-07-21 21:39 ` Adam Beneschan [this message]
2014-07-21 21:44   ` Victor Porton
2014-07-21 21:54     ` Adam Beneschan
2014-07-21 21:58       ` Victor Porton
2014-07-22  0:20         ` Randy Brukardt
2014-07-23 21:36         ` Robert A Duff
2014-07-21 22:06       ` Shark8
2014-07-21 23:12     ` Randy Brukardt
2014-07-22  9:53       ` AdaMagica
2014-07-22 21:10         ` 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