From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,1116ece181be1aea X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-10-17 14:17:50 PST Path: archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-post-01!supernews.com!corp.supernews.com!not-for-mail From: "Randy Brukardt" Newsgroups: comp.lang.ada Subject: Re: Counter-proposal for variable arrays Date: Fri, 17 Oct 2003 16:20:12 -0500 Organization: Posted via Supernews, http://www.supernews.com Message-ID: References: <1065215180.95094@master.nyc.kbcfp.com> <19p2ovk1jh4krn2h5cql44p37ovf6va99i@4ax.com> <4pe7ov0gsepk8p8cq88ropvq4sookdhatk@4ax.com> <1065635640.270857@master.nyc.kbcfp.com> <725aovsqh10dv5p5nh1e7k2qvjjcqustsa@4ax.com> <1065709998.992831@master.nyc.kbcfp.com> <7aisov0u9cha33e1fgvpli7mmdqqmmh7l9@4ax.com> X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4807.1700 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300 X-Complaints-To: abuse@supernews.com Xref: archiver1.google.com comp.lang.ada:1105 Date: 2003-10-17T16:20:12-05:00 List-Id: "Dmitry A. Kazakov" wrote in message news:7aisov0u9cha33e1fgvpli7mmdqqmmh7l9@4ax.com... > On Wed, 15 Oct 2003 19:52:22 -0500, "Randy Brukardt" > wrote: > > >"Hyman Rosen" wrote in message > >news:1065709998.992831@master.nyc.kbcfp.com... > >> Dmitry A. Kazakov wrote: > >> > It is already so. Consider: > >> > type Tricky (I, J : Positive) is record > >> > X : String (1..I); > >> > Y : String (1..J); > >> > end record; > >> > The offset to Y is variable and depends on the value of I. > >> > >> I Didn't Know You Could Do That In Ada(tm). :-) > >> It really works that way? And you can have procedures > >> which just take unconstrained Tricky parameters, and > >> they'll know how to deal with all instances? Cool! > > > >You can write this, but it often isn't implemented with variable offsets. > >What Janus/Ada does is to use discontinous storage for > >depends-on-discriminant components. The component itself is a descriptor, > >and has fixed size. The array data is allocated separately. That way, we can > >actually change the data memory when the discriminants are changed by > >assignment, and we don't use more memory than necessary. > > An interesting approach. But what will happen if I write: > > type Tricky_Ptr is access Tricky; > for Tricky_Ptr'Storage_Pool use My_Stack_Pool; > > Do you switch between representations? Huh? We just use whatever pool is the correct one. To expand on that: For record types, we declare a number of subprograms with the type (unless it is very simple). One of those is the allocation subprogram; it takes the object address and a storage pool parameter. This routine is called whenever an object is constructed (even on the stack); of course, there is a pool for memory which is recovered when the stack frame is destroyed. (Tuck has convinced me that our implementation is subtly wrong; it will need major surgury, but the basic idea will be remain the same. The main change will be that every stack frame will (logically) have its own pool - currently, there is one global stack pool.) > --- > As I see, your compiler is ready for: > > type Crazy (T : Tag) is record > Anything : Root_Type'Class (T); > end record; > > (:-)) Yup, the design is very flexible. More flexible than is really needed to implement Ada 95, but perhaps it will work well for Dmitry 2009. :-) Randy.