comp.lang.ada
 help / color / mirror / Atom feed
From: Warren <ve3wwg@gmail.com>
Subject: Re: Dynamic Variant Record Creation
Date: Tue, 16 Mar 2010 20:59:53 +0000 (UTC)
Date: 2010-03-16T20:59:53+00:00	[thread overview]
Message-ID: <Xns9D3DACEA49216WarrensBlatherings@188.40.43.213> (raw)
In-Reply-To: wccljdsnh48.fsf@shell01.TheWorld.com

Robert A Duff expounded in news:wccljdsnh48.fsf@shell01.TheWorld.com:

> Warren <ve3wwg@gmail.com> writes:
>>...I am simply laying out a "problem" and looking for a
>> suitable "solution".
> 
> Sure.  It's a real problem.  I've run into it myself.

The other way for me to solve this is simply provide
a discrimanant that only identifies the few variants. But 
to keep to 32-bits, I'd have to find a way to specify the
discriminant as 3-bits, which I don't think is possible.

I'm thinking of bitwise layouts like (random example):

for DeviceDetails use
  record at mod 2;
    status at 0 range 0 .. 7;
    rd_stat at 1 range 0 .. 3;
    wr_stat at 1 range 4 .. 7;
  end record;

except that the discriminant also be described somehow
as 3-bits.

> I don't see it either.  My guess is it involves creating an object
> constrained to the right discriminant, without using an
> aggregate.

I see it now.. yes, same idea.

>> I wasn't looking for compiler-implementation/language amendments.
>> Just looking for good advice on how others would takle this problem.
>> Perhaps the full case statement is the right way, but I gotta say
>> that it puts a damper on readability.
> 
> One solution is to write the aggregates out at each place.

No, that won't work because after I have an "identifier", I
look it up in keyword (and function name) tables. Once it is 
recognized as a keyword, LEX_IDENT is replaced with the 
returned specific keyword id. This simplifies the parser pass
later.

The character case, is an "others =>" case. Once completed,
there will not be many aside from the usual single operators,
brackets, comma and colon etc.  There's just enough there to be
a nuisance.

> You said you wanted efficiency.  Well, this:
> 
>             T : Token_Type := Token_Type'Val(Character'Pos(Ch));
> 
> is unlikely to be efficient.  The case statement will be better
> in that regard.

If true, I'd like to know why. I can't see that in the compiled
code being much other than a move short.  If I get time tonight,
I'll investigate it.

> Another solution is to make the record non-variant.
> Store Func and Id in the same component, and use
> whatever conversions you need.  Wrap this in accessor
> functions.  

Ya, or I could use a 2005 union perhaps. I'm just trying
to keep overhead down and safety "up". This is an experimental
rewrite of a C project of mine.

Warren



  reply	other threads:[~2010-03-16 20:59 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-16 17:11 Dynamic Variant Record Creation Warren
2010-03-16 18:31 ` Georg Bauhaus
2010-03-16 18:57 ` Adam Beneschan
2010-03-16 20:01   ` Warren
2010-03-16 20:09     ` Jeffrey R. Carter
2010-03-16 20:24       ` Warren
2010-03-16 20:40         ` Robert A Duff
2010-03-16 20:44           ` Warren
2010-03-16 20:31     ` Robert A Duff
2010-03-16 20:59       ` Warren [this message]
2010-03-16 21:55         ` Jeffrey R. Carter
2010-03-17 14:40           ` Warren
2010-03-18 12:57           ` Warren
2010-03-16 21:58         ` Robert A Duff
2010-03-17 14:22           ` Charmed Snark
2010-03-17 14:49             ` Robert A Duff
2010-03-17 16:30               ` Warren
2010-03-16 21:15       ` Adam Beneschan
2010-03-16 23:24       ` Adam Beneschan
2010-03-16 20:15   ` Robert A Duff
2010-03-16 21:00     ` Warren
2010-03-16 23:39   ` Randy Brukardt
2010-03-16 23:43     ` Randy Brukardt
2010-03-17  0:15     ` Robert A Duff
2010-03-17 14:28       ` Warren
2010-03-18  0:02       ` Randy Brukardt
2010-03-17  4:20     ` Adam Beneschan
2010-03-18  0:13       ` Randy Brukardt
2010-03-18 13:00         ` Warren
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox