* Aspects, rep specs, shifts, conditional expressions, expression functions
@ 2011-12-22 4:19 Bill Findlay
2011-12-23 1:01 ` Randy Brukardt
0 siblings, 1 reply; 3+ messages in thread
From: Bill Findlay @ 2011-12-22 4:19 UTC (permalink / raw)
The topics listed in the subject have been controversial recently.
I wonder what people think of my first attempt at an Ada 2012 package,
which seems to use them all, in what I hope is a judicious mix?
----
with Unchecked_Conversion;
with KDF9.CPU;
package KDF9.K5_stuff is
-- PHU, the Program Hold-Up register is internal to I/O Control.
-- A subset is exposed to Director by means of the K5 order.
-- It has one element for each of the 4 program priority levels.
type blockage is (buffer_busy, locked_out) with Size => 1;
type group_address is mod 1024 with Size => 10;
type PHU_store (hold_up : one_bit := 0;
reason : blockage := buffer_busy) is
record
case hold_up is
when 0 =>
null;
when 1 =>
case reason is
when buffer_busy =>
buffer_nr : buffer_number;
when locked_out =>
group_nr : group_address;
end case;
end case;
end record;
PHU : array (priority) of PHU_store;
type PHU_subset is
record
hold_up : one_bit;
reason : blockage;
parameter : buffer_number;
end record
with Size => 6, Bit_Order => Low_Order_First;
for PHU_subset use
record
hold_up at 0 range 5 .. 5;
reason at 0 range 4 .. 4;
parameter at 0 range 0 .. 3;
end record;
type PHU_as_6_bits is mod 2**6 with Size => 6;
function as_6_bits is
new Unchecked_Conversion(Source => PHU_subset,
Target => PHU_as_6_bits);
function K5_word (short_PHU : PHU_subset) return word is
(word(as_6_bits(short_PHU)));
function short_PHU (p : priority) return word is
(K5_word((
hold_up => PHU(p).hold_up,
reason => (
if PHU(p).hold_up = 0 then
buffer_busy -- A non-significant 0 bit.
else
PHU(p).reason
),
parameter => (
if PHU(p).hold_up = 0 then
0
elsif PHU(p).reason = buffer_busy then
PHU(p).buffer_nr
else
buffer_number(PHU(p).group_nr mod 2**4)
)
))
);
-- A K5_operand is a KDF9 word, D00-D47, with the content:
-- short_PHU(0) in D00 .. D05
-- short_PHU(1) in D06 .. D11
-- short_PHU(2) in D12 .. D17
-- short_PHU(3) in D18 .. D23
function K5_operand return word is
(
KDF9.CPU.shift_word_left(short_PHU(0), 47-05) or
KDF9.CPU.shift_word_left(short_PHU(1), 47-11) or
KDF9.CPU.shift_word_left(short_PHU(2), 47-17) or
KDF9.CPU.shift_word_left(short_PHU(3), 47-23)
);
end KDF9.K5_stuff;
--
Bill Findlay
with blueyonder.co.uk;
use surname & forename;
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Aspects, rep specs, shifts, conditional expressions, expression functions
2011-12-22 4:19 Aspects, rep specs, shifts, conditional expressions, expression functions Bill Findlay
@ 2011-12-23 1:01 ` Randy Brukardt
2011-12-23 17:50 ` Bill Findlay
0 siblings, 1 reply; 3+ messages in thread
From: Randy Brukardt @ 2011-12-23 1:01 UTC (permalink / raw)
"Bill Findlay" <yaldnif.w@blueyonder.co.uk> wrote in message
news:CB186063.D1C0%yaldnif.w@blueyonder.co.uk...
...
> type blockage is (buffer_busy, locked_out) with Size => 1;
Minor stylistic comment:
The intended style for aspect_specifications is to have them indented on the
line following the declaration, as follows:
type blockage is (buffer_busy, locked_out)
with Size => 1;
We had a huge argument about this in the ARG. Note that the recommended
indentation style for any Ada construct is that shown in the syntax diagrams
in the RM. (The layout of those productions is not random, even if a lot of
people think it is!)
Of course, you can do whatever you want -- just keep in mind that there is
an intended style for Ada.
Randy.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Aspects, rep specs, shifts, conditional expressions, expression functions
2011-12-23 1:01 ` Randy Brukardt
@ 2011-12-23 17:50 ` Bill Findlay
0 siblings, 0 replies; 3+ messages in thread
From: Bill Findlay @ 2011-12-23 17:50 UTC (permalink / raw)
On 23/12/2011 01:01, in article jd0jtn$21o$1@munin.nbi.dk, "Randy Brukardt"
<randy@rrsoftware.com> wrote:
> "Bill Findlay" <yaldnif.w@blueyonder.co.uk> wrote in message
> news:CB186063.D1C0%yaldnif.w@blueyonder.co.uk...
> ...
>
>> type blockage is (buffer_busy, locked_out) with Size => 1;
>
> Minor stylistic comment:
Thanks, Randy. I had not realized that the RM authors were setting a
precedent with the layout.
One aspect (!) of my code thatI do not like is that the auxiliary type,
PHU_as_6_bits, and functions, as_6_bits and short_PHU, are exposed to view.
I'm going back to a more conventional package with a body.
--
Bill Findlay
with blueyonder.co.uk;
use surname & forename;
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2011-12-23 17:50 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-12-22 4:19 Aspects, rep specs, shifts, conditional expressions, expression functions Bill Findlay
2011-12-23 1:01 ` Randy Brukardt
2011-12-23 17:50 ` Bill Findlay
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox