comp.lang.ada
 help / color / mirror / Atom feed
From: Fraser Wilson <fwilson@anago.nl>
Subject: Re: Safe Units Handling in Ada
Date: Thu, 23 May 2002 12:01:25 +0200
Date: 2002-05-23T10:02:22+00:00	[thread overview]
Message-ID: <3CECBDF5.8050002@anago.nl> (raw)
In-Reply-To: bebbba07.0205230104.7b071a66@posting.google.com

Russ wrote:

 > I downloaded this, and it contains a large number of files.

Yes, this is a problem.  That's mainly because none of you have WL, GCS
or Sourcegen installed (but since I've never released them, you don't
have to feel bad).

 > Perhaps you could
 > explain how it works and give a simple example.

Yes, that's a good idea.  The important bits as far as units are
concerned is under the Macks package hierarchy.  Macks.Parser reads a
source file which describes the system, and Macks.Writer emits Ada
source code.  Macks.Table is a simple symbol table.

Each unit type in the Macks source file has a number of operator
functions generated for it.  Common to all units are the following:

    function "*" (Left, Right : Unit) return Unit is abstract;
    function "/" (Left, Right : Unit) return Unit is abstract;
    function "*" (Left : Float_Type; Right : Unit) return Unit;
    function "*" (Left : Unit; Right : Float_Type) return Unit;
    function "/" (Left : Unit; Right : Float_Type) return Unit;
    function "/" (Left : Unit; Right : Unit) return Float_Type;

Derived units have in addition operators corresponding to their 
definition or definitions in the .macks file; for example, if

    Speed is Meter / Second;

then the following operators are generated:

    function "/" (Left : Meter; Right : Second) return Speed;
    function "*" (Left : Speed; Right : Second) return Meter;
    function "*" (Left : Second; Right : Speed) return Meter;
    function "/" (Left : Meter; Right : Speed) return Second;

The file example.macks contains a simple Macks specification, which only
deals with a few derived units.  However, that's enough to create an 800
line Ada package spec (which is what motivated this sort of thing in the
first place).

Macks.Driver is the main procedure; with Gnat you can use the command
    gnatmake -o macks macks-driver.adb
to get an executable; this can be invoked with
    macks example.macks
for example.

<filename>.macks generates <filename>.ads and <filename>.adb.  To use 
the generated files, with and use/use type them, then declare your 
quantities and act natural.  If operations that should work don't, let 
me know.

I hope this helps; more thorough documentation is expected shortly.

cheers,
Fraser.




      reply	other threads:[~2002-05-23 10:01 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-05-21 10:01 Safe Units Handling in Ada Fraser Wilson
2002-05-21 14:21 ` Pat Rogers
2002-05-21 15:58 ` Stephen Leake
2002-05-22  8:32   ` Fraser
2002-05-22 10:21 ` Fraser
2002-05-22 16:37   ` Stephen Leake
2002-05-23 10:16     ` Fraser
2002-05-23 16:03       ` Stephen Leake
2002-05-22 22:44   ` William C. Brennan
2002-05-23  8:55     ` Russ
2002-05-23  9:28     ` Fraser
2002-05-23 10:03       ` martin.m.dowie
2002-05-23 10:24         ` Fraser
2002-05-23 11:03           ` martin.m.dowie
2002-05-23 15:57     ` Dan Andreatta
2002-05-23 16:15       ` Fraser Wilson
2002-05-23 16:48       ` martin.m.dowie
2002-05-23  9:04 ` Russ
2002-05-23 10:01   ` Fraser Wilson [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