Ada Planet

❌ About FreshRSS
There are new articles available, click to refresh the page.
Yesterday β€” February 24th 2021News from the Ada programming language world

Access Ada (in a .so) from Java JNI

I'm trying to call Ada code from a Java app in Linux. The Ada code resides in a dynamic lib with a C-api.

Linking the .so from Java works. Likewise calling the C-functions in the .so and extending execution into Ada work. But that's where it ends...

The call to Ada works fine, but it seems that Ada doesn't have a (secondary) stack?

When building the .so I've tried binding with -Dnn (like -D20k and -D10m) and also tried to call a task with the 'secondary_stack_size' directive. But the task itself won't be created due to no stack, neither static or dynamic creation works.

Any ideas?

Version 1.1 Release of aShell.

February 23rd 2021 at 23:39
By: Rod Kay
- Factored out command code into a separate package. - Simplified the specs. - Added better error handling. - Added several tests. - Improvements for pipelines. Regards.
  • February 23rd 2021 at 23:39
Before yesterdayNews from the Ada programming language world

Implementation of arrays in Ada compilers.

February 23rd 2021 at 18:10
Hello, I would like to know what is the runtime implementation of arrays used by compilers, and GNAT in particular. Does an array is represented as an address, a starting index (First) and an ending index (Last) ? Or a First index and a Length. Is the address the A’First’Address ? And what
  • February 23rd 2021 at 18:10

Ada: How to Iterate over a private map?

Consider the following:

with Ada.Containers.Hashed_Maps;
with Ada.Containers; use Ada.Containers;
with Ada.Text_IO; use Ada.Text_IO;
procedure Main is
   package Tiles is
      -- Implementation is completely hidden
      type Tile_Type is private;
      type Tile_Set is tagged private;
      type Tile_Key is private;
      procedure Add (Collection : in out Tile_Set; Tile : Tile_Type);
      function Get (Collection : in Tile_Set; Key : Natural) return Tile_Type;
      function Make (Key : Natural; Data : Integer) return Tile_Type;
      function Image (Tile : Tile_Type) return String;

      type Tile_Key is record
         X : Natural;
      end record;
      function Tile_Hash (K : Tile_Key) return Hash_Type is
        (Hash_Type (K.X));
      type Tile_Type is record
         Key    : Tile_Key;
         Data   : Integer;
      end record;
      package Tile_Matrix is new Ada.Containers.Hashed_Maps
        (Element_Type        => Tile_Type,
         Key_Type            => Tile_Key,
         Hash                => Tile_Hash,
         Equivalent_Keys     => "=");

      use Tile_Matrix;

      type Tile_Set is new Tile_Matrix.Map with null record;

   end Tiles;
   package body Tiles is
      procedure Add (Collection : in out Tile_Set; Tile : Tile_Type) is
         Collection.Include (Key => Tile.Key, New_Item => Tile);
      end Add;
      function Get (Collection : in Tile_Set; Key : Natural) return Tile_Type is
         K       : Tile_Key := (X => Key);
         C       : Cursor := Collection.Find (Key => K);
      begin -- For illustration, would need to handle missing keys
         return Result : Tile_Type do
            Result := Collection (C);
         end return;
      end Get;
      function Image (Tile : Tile_Type) return String is
        (Tile.Key.X'Image & '=' & Tile.Data'Image);
      function Make (Key : Natural; Data : Integer) return Tile_Type is
         New_Key : Tile_Key := (X => Key);
         return Result : Tile_Type do
            Result.Key := New_Key;
            Result.Data := Data;
         end return;
      end Make;
   end Tiles;
   use Tiles;

   S  : Tile_Set;
   T  : Tile_Type;
   S.Add (Make (Key => 1, Data => 10));
   T := S.Get (1);
   Put_Line (Image (T)); -- 1, 10
   S.Add (Make (Key => 2, Data => 20));
   T := S.Get (2);
   Put_Line (Image (T)); -- 1, 20
   for X in S loop -- Fails: cannot iterate over "Tile_Set"
                   --     +: to iterate directly over the elements of a container, write "of S"
                   -- but "for X of S" doesn't work either.
      T := S (X);  -- Fails: array type required in indexed component
                   -- presumably because X isn't a cursor?
      Put_Line (Image (T));
   end loop;

It seems to me that the compiler has enough knowledge to iterate over a Tile_Set and I'm supposing it won't because I haven't exposed an iterator.

How should I modify this so that 'for X is S loop' is valid?

More generally, what is the idiom for hiding the implementation of underlying containers, whilst exposing indexing, iterating etc.?

Any Ada in Perseverance?

February 23rd 2021 at 09:20
Hi all, I was listening to a podcast on the recent landing and they mentioned in passing VxWorks for the OS and C for the navigation subsystem... Which "suspiciously" matches the only line in Wikipedia about it: I have found a few
  • February 23rd 2021 at 09:20

Ada: Importing the inequality operator "/="

I don't want to use an entire package, but I do want to import a few features, such as the "/=" operator. I know that renames allows me to do this with most functions, but with the inequality operator I get the error, explicit definition of inequality not allowed. How do I import this operator without raising the error?

package Integer_Maps is new Ada.Containers.Ordered_Maps
 Key_Type => Integer,
 Element_Type => Integer

-- the next line fails!
function "/=" ( Left, Right: Integer_Maps.Cursor ) return Boolean
   renames Integer_Maps."/=";

How do I modify the Ada record type to be a union type supporting two variants?

The program contains some type definitions that can be used in a program for playing noughts and crosses (also known as tic-tac-toe). gamePos2 describes a completed position where one player has won

I am trying to change the record type GamePos to be a union type supporting two variants: a position of a completed game and a position of a game in progress.

Feel free to ask any questions so I can elaborate on my problem

type GamePos is
            board : TTTBoard;
            turn : Player;
            value : Float;
        end record;

    procedure Put_Pos(pos : GamePos) is
        Put("Player to make the next move: ");
        Put("Estimated advantage of player X over player O is: ");
        Put(pos.value, 0, 0, 0);
    end Put_Pos;

    gamePos1 : GamePos
        := (board =>
                ((X, X, O),
                 (O, B, X),
                 (O, B, B)),
            turn => Player_X,
            value => 0.0);

     gamePos2 : GamePos
         := (pos_variant => WON, -- the discriminant
             board =>
                 ((X, X, O),
                  (O, X, X),
                  (O, O, X)),
             winner => Player_X);

end TTT;

"unconstrained subtype in component declaration" vs "discriminant in constraint must appear alone"

February 22nd 2021 at 00:14
this message "unconstrained subtype in component declaration" arises from this: subtype Limit_number is Natural range 0..51; type CARDS is new Natural range Limit_number'Range; type Sets_of_Card is array (Limit_number range ) of Cards; function INITIALIZATION (Nb: Nombre_cart
  • February 22nd 2021 at 00:14

Has anyone successfully installed adaopengl library in linux? [closed]

I am trying to install ada library adaopengl in opensuse. Unfortunately, it was unsuccessful with make command. Also tried by keeping all files under one directory and test the code there. Make object was okay but build failed. Error message shows undefined reference to functions. The problem is linking the files. Did anyone successfully installed adaopengl library found in (

set_index and and end_of_file with just a stream reference

February 20th 2021 at 15:26
In term of design, I have a file inside a protected type, to ensure validity for concurrrent readings/writings. An entry guarded by "Is_Open" provide with an "out" stream_access, a means to read/write from the stream file. But in the procedure I wish to also use End_Of_File and Set_Index, which
  • February 20th 2021 at 15:26

Ada: How to organise nested packages

Suppose we have a vehicle, which gets its position from an IMU. The IMU package consists of several private components, which it orchestrates to calculate the vehicle's state in space:

with IMU; use IMU;
Package Vehicle is
end vehicle; 

Package IMU is

    type Attitude is record
        Lat, Lon: Angle;
        Pitch, Roll, Yaw: Angle;
        GroundSpeed: Speed;
    end record
    function Get_Position return Attitude is ...
    Package GPS is
    end GPS;
    Package Accelerometer is
    end Accelerometer;
    Package Gyro is
    end Gyro;
end IMU;

The internals of GPS, Accelerometer and Gyro only make sense in the context of the IMU; they must be completely hidden from Vehicle.

Declaring the IMU and all of its sub-components in a single source file will be difficult to read and maintain; I'd like to have each sub-component in it's own source file. If I code them all at the IMU level, the vehicle will be able to access the GPS, which is wrong.

What is the best practice for structuring nested packages?

Ada: How to get Access to Vector element?

I have a collection of things, which I deliberately want to allocate on the heap and access them 'by reference':

with Ada.Text_IO; use Ada.Text_IO;
with Ada.Containers.Indefinite_Hashed_Maps;
with Ada.Containers; use Ada.Containers;

procedure Main is
    type Thing_Key is new Integer;
    type Thing is record
        Key  : Thing_Key;
        Data : Integer;
    end record;
    type Thing_Access is access all Thing;
    function Image (T : Thing) return String is
      (T.Key'Image & '(' & T.Data'Image & ')');
    function "=" (A, B : Thing) return Boolean is
      (A.Key = B.Key);
    function Thing_Hash (K : Thing_Key) return Hash_Type is
      (Hash_Type (K));

    package Thing_Map is new
         (Key_Type        => Thing_Key,
     Element_Type    => Thing,
     Hash            => Thing_Hash,
     Equivalent_Keys => "=");
    use Thing_Map;
    Map : Thing_Map.Map;
    C : Cursor;
    P : Thing_Access;
    P := new Thing '(Key => 1, Data => 2);  -- on the heap
    Map.Insert (P.Key, P.all);
    Put_Line (Image (P.all)); -- '1( 2)', as expected

    P.Data := 99;
    Put_Line (Image (P.all)); -- '1( 99)', as expected

    C := Map.Find (1); -- Get cursor to thing
    -- Set P to point at the thing at the cursor?
    -- Following lines don't compile
    P := Map (C)'Access; -- access-to-variable designates constant
    P := Map (C).Reference; -- undefined selector "Reference" for overloaded prefix
    P := Map (C).Get_Element_Access; -- undefined selector "Get_Element_Access" for overloaded prefix
    P := Map.Reference (C); -- no visible interpretation of "Reference" matches expected type "Thing_Access"
end Main;

What is the syntax to get a pointer from a cursor?