comp.lang.ada
 help / color / mirror / Atom feed
From: "G.B." <bauhaus@futureapps.invalid>
Subject: Re: Another Ada/ARM Cortex M4F tutorial up, with some interesting results
Date: Mon, 22 Sep 2014 14:14:36 +0200
Date: 2014-09-22T14:14:36+02:00	[thread overview]
Message-ID: <lvp3rc$jd8$1@dont-email.me> (raw)
In-Reply-To: <c90d4637-7df2-43af-8013-64e6a40d8857@googlegroups.com>

On 22.09.14 07:51, Mike Silva wrote:
> Sure wish I had this 20-30 years ago!
>
> http://www.embeddedrelated.com/showarticle/625.php
>

The source uses GNAT's own 'Enum_Rep, in part for use during
compile time checks.  I wonder if the effect can be achieved
in portable Ada, at very little cost.

The following example code is set up to generate static
failures. Is there a way to reliably get rid of the entities
declared for testing only, as, I guess, they can potentially
make it to object code?

package Plain_Ada is

    type Word is mod 2**16;

    type Lights is new Word;
    Red    : constant Lights :=  2#0001#;
    Green  : constant Lights :=  2#0010#;
    Blue   : constant Lights :=  2#0101#;  -- deliberate
    Yellow : constant Lights :=  2#0100#;

    Flashy : constant Lights := Red
      or Green
      or Blue
      or Yellow;

private
    package Compile_Time_Checks is

       type Yes is new Boolean range True .. True;

       Expected_Bits : constant Yes :=
         Yes (Flashy = 2#0111#
                and
              (Blue or 1) /= 2#0000#);

       No_Overlap : constant := (case 1 is
                                    when Red or Green => 1,
                                    when Red or Blue => 1,
                                    when Red or Yellow => 1,
                                    when Green or Blue => 1,
                                    when Green or Yellow => 1,
                                    when Blue or Yellow => 1,
                                    when others => 1);
    end Compile_Time_Checks;
end Plain_Ada;

One way not have traces of the tests in code is, I suppose,
to put the tests into some pramga that establishes Boolean
context, such as pragma Assert.



      reply	other threads:[~2014-09-22 12:14 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-22  5:51 Another Ada/ARM Cortex M4F tutorial up, with some interesting results Mike Silva
2014-09-22 12:14 ` G.B. [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