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,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,4ef5a4648a4a3c50 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-12-21 05:42:20 PST Path: archiver1.google.com!news2.google.com!news.maxwell.syr.edu!in.100proofnews.com!in.100proofnews.com!cycny01.gnilink.net!cyclone1.gnilink.net!small1.nntp.aus1.giganews.com!border1.nntp.aus1.giganews.com!intern1.nntp.aus1.giganews.com!nntp.giganews.com!nntp.comcast.com!news.comcast.com.POSTED!not-for-mail NNTP-Posting-Date: Sun, 21 Dec 2003 07:42:18 -0600 Date: Sun, 21 Dec 2003 08:42:18 -0500 From: "Robert I. Eachus" User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax) X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: what about having ada compile ada on the fly? References: <657ea3e3.0312202132.fd1586c@posting.google.com> In-Reply-To: <657ea3e3.0312202132.fd1586c@posting.google.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Message-ID: NNTP-Posting-Host: 24.34.214.193 X-Trace: sv3-1HO/BMfGYcaEv3xCFMChLchjRAcf07r8zXEdzdqYdiUHlvBI6Uz1teHiDIAhylA5GKHYizzbyQWqtji!/168Y88ogzIa9g12/nwEyLV95f/VDwN2jtWGFFIeNQy3gOvrwrZ1pw3iylz0TQ== X-Complaints-To: abuse@comcast.net X-DMCA-Complaints-To: dmca@comcast.net X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.1 Xref: archiver1.google.com comp.lang.ada:3666 Date: 2003-12-21T08:42:18-05:00 List-Id: Robert C. Leif wrote: > From: Bob Leif > Since the time to compile with the combination of an Ada compiler and > a modern PC has greatly diminished, it may be time to start > considering compiling at run-time instead of the use of complex data > structures based on access types or discriminants. > > For instance at run-time, I can set the size of an array of records; > however, I can not simply create the composition of the record from > precompiled types. If I have 26 sensors consisting of a mixture of > types integer and float, and I wish to have the user select the ones > to log; could I do this in the equivalent of SPARK with the addition > of generics? These precompiled types are: > A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z. The user selects > C, G, N, and W. One could create a program that produced a record type > (Data_Rec_Type) consisting of these fields and instantiating a generic > package to create an array with the user specified array size and type > Data_Rec_Type. The generic would already include the array storage > operations. Could this be compiled and linked as a DLL or similar > structure and used by the program? Again, the actual source to be > compiled would be Ada. What is wrong with doing this in current Ada (or SPARK). You declare a type with 26 boolean discriminants (and no defaults): type Data_Rec_Type (A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z: Boolean) is record case A is when True => ...; when False => null; end case; ... end record; Now you can declare a generic procedure (or more likely package if you need several different subprograms) that takes a generic parameter of Data_Rec_Type, and you instantiate it with a constrained subtype (instantiation occurs at run-time of course). It is possible that your compiler will generate relatively junk code for the type, and not pack it as fiercely as you like, but that is between you and the compiler vendor. Since there are no defaults the compiler should be willing to create objects without stored discriminants and only the data that is actually present. A compiler that notices the special structure and generates efficient code for the generic should not be too hard to find. (What you want is a compiler that not just stores the discriminants as a descriptor for the subtype, but creates an offset table as well.) Generating code (for the procedures) that doesn't test all the discriminants may be too much to ask. But code that tests each discriminant once should not be. As I said, the compiler can pass not only the discriminants of the type as a "hidden" parameter, but a table of offsets for the components as well. This is a generally useful optimization, and some compilers do it. Skipping past or around the code for the discriminant cases where the value is false, though, may be too much to ask. But you can ask, and compiler vendors can do a lot with code generated "on the fly." I know the GNAT compiler does generate some code on the fly using trampolines, ask ACT for more details. -- Robert I. Eachus "The war on terror is a different kind of war, waged capture by capture, cell by cell, and victory by victory. Our security is assured by our perseverance and by our sure belief in the success of liberty." -- George W. Bush