From: "Robert I. Eachus" <rieachus@comcast.net>
Subject: Re: what about having ada compile ada on the fly?
Date: Sun, 21 Dec 2003 08:42:18 -0500
Date: 2003-12-21T08:42:18-05:00 [thread overview]
Message-ID: <VNydncx4UOynPniiRVn-gQ@comcast.com> (raw)
In-Reply-To: <657ea3e3.0312202132.fd1586c@posting.google.com>
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
prev parent reply other threads:[~2003-12-21 13:42 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-12-20 6:38 what about having ada compile ada on the fly? cl1motorsports
2003-12-20 9:41 ` Ada IDE [was: what about having ada compile ada on the fly?] Nick Roberts
2003-12-20 15:57 ` Ludovic Brenta
2003-12-21 0:39 ` Ekkehard Morgenstern
2004-01-03 19:13 ` Pascal Obry
2004-01-04 0:17 ` Ekkehard Morgenstern
2004-01-04 12:16 ` Pascal Obry
2003-12-20 21:01 ` Pascal Obry
2003-12-21 5:32 ` what about having ada compile ada on the fly? Robert C. Leif
2003-12-21 13:42 ` Robert I. Eachus [this message]
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox