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=0.6 required=5.0 tests=BAYES_00,FROM_WORDY autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,571930b4ff0bc1ee X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-03-27 05:34:06 PST Path: supernews.google.com!sn-xit-03!supernews.com!hermes2.visi.com!news-out.visi.com!news-out.visi.com!hermes.visi.com!nycmny1-snh1.gtei.net!news.gtei.net!newsfeed.mathworks.com!wn3feed!wn4feed!worldnet.att.net!207.115.63.142!newscon02.news.prodigy.com!newscon06.news.prodigy.com!prodigy.com!newsmst01!postmaster.news.prodigy.com!newssvr16.news.prodigy.com.POSTED!not-for-mail From: "Ken Garlington" Newsgroups: comp.lang.ada References: <3AC03CCE.70E3C2D5@mida.se> Subject: Re: Compile time executed functions Organization: ex-FlashNet, now Prodigy X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4522.1200 X-Mimeole: Produced By Microsoft MimeOLE V5.50.4522.1200 Message-ID: NNTP-Posting-Host: 65.65.210.140 X-Complaints-To: abuse@prodigy.net X-Trace: newssvr16.news.prodigy.com 985699822 6207069 65.65.210.140 (Tue, 27 Mar 2001 08:30:22 EST) NNTP-Posting-Date: Tue, 27 Mar 2001 08:30:22 EST Date: Tue, 27 Mar 2001 13:30:22 GMT Xref: supernews.google.com comp.lang.ada:6108 Date: 2001-03-27T13:30:22+00:00 List-Id: I think the key statement is "The constant is really a constant and should therefore be placed in ROM." AFAIK, you can create an _Ada_ constant from a function. Whether it's placed in ROM is a concept outside the scope of the language, and is a function of compiler optimizations. For example, my company spent a lot of time and money in order to get the result of an Unchecked_Conversion between a System.Address and a compatible access type placed into ROM for a particular Ada 83 compiler/linker. Before we paid for this, the result would be placed in RAM. Both implementations were legal with respect to the language definition. A more general solution, as you noted, is to write an Ada program that writes an easier-to-optimize Ada program (or, in some cases, assembly instructions). We have several of those for commonly-used capabilities in our domain. "Mats Karlssohn" wrote in message news:3AC03CCE.70E3C2D5@mida.se... : After following the thread on C style preprocessing, an old wish of : mine popped up in my brain (or whatever is inside the scull :). : : Sometimes, especially when doing embedded programming, I feel a great : need to execute a function to get literal initialization a constant. : That is I'd like to have the compiler to execute a function for me (at : compiletime!) and use the return of that function to initialize the : constant. : : Example (pleas, this is just an example, it hasn't been compiled): : : type Byte is mod 2**8; : type Word is mod 2**16; : type CRC_Lookup_Table is array(0..255) of Byte; : : constant CRC_Polynom := 4711; -- replace with a 'correct' polunom : : function Generate_CRC_Table(Polynom : in Word) return CRC_Lookup_Table : is : begin : -- Implementation : end Generate_CRC_Table; : : package Package_Using_CRC is : constant CRC_Lookup_Table := Generate_CRC_Table(CRC16_Polynom); : : -- : end Package_Using_CRC; : : : - The constant is really a constant an should therefore be placed in : ROM. : - Therefore the function Generate_CRC_Table isn't needed in the output : at all and since it may be quite large and/or time consuming it would : be nice to do the job once, at compile time. : : : The way I'm currently doing this is by building a small external program : that generates an appropriate code fragment, that gets pasted into the : right place. This gives both maintenance and configuration management : headaches. : : I must admit that I havn't researched enough to say that I can't get the : same effect using generice and/or other techniques in Ada. : : Now, first I wonder have somebody out there solved this issue in a way : that complies with the first to points above ? : : I realize that a lot of limitations must be put on the : Generate_CRC_Table function, but, have something along these lines been : considered by the language designers. : : I have hoped to get the time to either build a small preprocessor to do : this kind of execution/substitution trick, or to add the same trick into : GNAT using some pragma(Compiler_Executed, func). Sorry to say, I don't : see that ammount of time in the near future. : : : Finally, as usual, I beg you to bear with my english. : : -- : Mats Karlssohn, developer mailto:mats@mida.se : Mida Systemutveckling AB http://www.mida.se : Box 64, S-732 22 ARBOGA, SWEDEN : Phone: +46-(0)589-89808 Fax: +46-(0)589-89809