โŒ About FreshRSS

Normal view

There are new articles available, click to refresh the page.
Before yesterdayNews from the Ada programming language world

Unbounded string `ENCODING_ERROR : bad input at Item`

Why is the following code failing ?

I have picked Characters.Latin_1.Reserved_128 on purpose.

-- File 'print_non_graphic_character.adb'
with Ada.Characters.Latin_1;
with Ada.Text_IO;
with Ada.Strings.Unbounded;

procedure Print_Non_Graphic_Character is
   Text_String : constant String := "Non Graphic Character: " & Ada.Characters.Latin_1.Reserved_128;
   Text_Unbounded_String : constant Ada.Strings.Unbounded.Unbounded_String :=
      Ada.Strings.Unbounded.To_Unbounded_String (Text_String);
begin
   Ada.Text_IO.Put_Line (Text_String);
   Ada.Text_IO.Put_Line (Ada.Strings.Unbounded.To_String (Text_Unbounded_String));
   Ada.Text_IO.Put_Line (Text_Unbounded_String'Image);
end Print_Non_Graphic_Character;

Note that it also fails with:

Ada.Text_IO.Put_Line (Ada.Strings.Unbounded.Unbounded_String'Image (Text_Unbounded_String));
-- File 'print_non_graphic_character.gpr'
project Print_Non_Graphic_Character is
   for Main use ("print_non_graphic_character.adb");
   for Object_Dir use ".objs";

   package Compiler is
      -- "-Og" -- Optimize for debug
      -- "-g" -- Generate debug info
      for Default_Switches ("Ada") use ("-g", "-gnat2020", "-Og");
   end Compiler;

   package Binder is
      for Switches ("Ada") use ("-Es"); --  Symbolic traceback
   end Binder;
end Print_Non_Graphic_Character;

It gives me with GNAT 12.2.0

Non Graphic Character: ๏ฟฝ
Non Graphic Character: ๏ฟฝ

raised ADA.STRINGS.UTF_ENCODING.ENCODING_ERROR : bad input at Item (25)
[./non_graphic_character/.objs/print_non_graphic_character]
0x40e8fb Ada.Strings.Utf_Encoding.Raise_Encoding_Error at a-stuten.adb:126
0x40f38b Ada.Strings.Utf_Encoding.Strings.Decode at a-suenst.adb:163
0x4049a8 Print_Non_Graphic_Character at print_non_graphic_character.adb:13
0x404efa Main at b__print_non_graphic_character.adb:279
[/lib/x86_64-linux-gnu/libc.so.6]
0x7f5e62118d08
[./non_graphic_character/.objs/print_non_graphic_character]
0x404658 _start at ???
0xfffffffffffffffe

It is annoying because, when I want to print a record which is commposed with Unbounded_String, I cannot use the 'Image attribute because of the above error and have to print each field and use To_String for Unbounded_String (which is annoying to have when I couple that with generic functions/packages).

Linking erros xerces-c on GNAT

I have to use a C++ library that uses xerces-c. Then I have an Ada project that imports two symbols from the previously mentioned C++ library. When I try to build the main of the Ada project, a bunch of undefined references arises, so I suppose I'm not linking correctly to xerces-c. I've ensured y have the libxerces-c.a and the headers in my path (I'm using CentOS).

This is the package Linker I'm using in my gpr, which I found by googling post of people having similar link errors:

package Linker is
  for Linker_Options use ("-Wl", "-Bstatic", "-lxerces-c", "-Wl", "-Bdynamic");
end Linker;

This is an example of one of the linking erros: undefined reference to `xercesc_3_2::XMLPlatformUtils::Initialize(char const*, char const*, xercesc_3_2::PanicHandler*, xercesc_3_2::MemoryManager*)'

I'm solving the problems for now by creating a gpr library project for xerces-c with for Externally_Built use "True"; and placing the libxerces-c.a manually in the lib directory of that project, but it really sounds weird to me. This way the linking erros disappear and everything seems to work.

Has anybody faced similar problems?

Ada scale exceeds maximum value of 18

Dear Ada Enthusiasts,

type Long_Money_Type is delta 10.0**(-22) digits 38;

On The First Machine Ubuntu Linux 64 bit GNAT 8.3.0 this works.
On The Second Machine Alpine Linux 64 Bit GNAT 10.3.1 20211027 i get this error:

adx-lib-money.ads:14:29: scale exceeds maximum value of 18
adx-lib-money.ads:14:54: digits value out of range, maximum is 18

Is There an way to change the maximum value ?

Unexpected Ada Type Compatibility

Why are Volts, Amps, and Ohms compatible?


with ada.text_io; use ada.text_io;
                                                                    
procedure main is                                                   
    type Volts is delta 1.0 / 2.0 ** 12 range -45_000.0 .. 45_000.0;
    type Amps is delta 1.0 / 2.0 ** 16 range -1_000.0 .. 1_000.0;   
    type Ohms is delta 0.125 range 0.0 .. 1.0E8;                    
                                                                    
    V : Volts := 1.0;                                               
    A : Amps := 1.0;                                                
    R1 : Ohms := 1.0;                                               
    R2 : Ohms := 1.0;                                               
                                                                   
begin                                             
                     
    v := A * (R1 + R2);
                       
    put_line(V'Img);   
                       
end main;  

If the types the types are defined as new Float I get the following exception during compilation:


main.adb:22:12: error: invalid operand types for operator "*"
main.adb:22:12: error: left operand has type "Amps" defined at line 5
main.adb:22:12: error: right operand has type "Ohms" defined at line 6

I expected the use of type with Volts to define a new type that was incompatible with the other types as it wasn't an explicit subtype of the fixed point type.

Installing Gnatstudio on RPI 4 v7

When executing ./configure for Gnatstudio I receive the following error. I have searched for references related to this but can't anything associated with it. Gprconfig has been configured without incident.

checking that your gnat compiler works with a simple example... GNAT-TEMP-000001.TMP:108:11: undefined attribute "bindfile_option_substitution" GNAT-TEMP-000001.TMP:109:11: undefined attribute "bindfile_option_substitution" gprbuild: processing of configuration project "/tmp/GNAT-TEMP-000001.TMP" failed

Locating variable "bindfile_option_substitution." Don't know where this is located.

Unable to link C source code with Ada static library (Error: libnewapi.a(unit1.o):unit1.adb:undefined reference to `__gnat_rcheck_CE_Overflow_Check')

I want to integrate my Ada static library (libnewapi.a) with my C source code (main.c). I do not have any issues generating the static library but when trying to link it with main.c. I get the below link error, libnewapi.a(unit1.o):unit1.adb:(.text+0x31): undefined reference to `__gnat_rcheck_CE_Overflow_Check' I am not using this reference in my main.c not in any of my Ada files. I do not know why this reference was added automatically. It is crucial that I need to link my main.c using a static Ada library for my project. I do not know where I am going wrong. Help is much appreciated. Thanks!

I am generating libnewapi.a using a GPR as below,

    -- ada_gen_a.gpr
    project ada_gen_a is
       for Languages use ("Ada");
       for Source_Dirs use ("./");
       for Library_Name use "newapi";
       for Library_Dir use "./Lib/";
       for Library_Kind use "static";

       package Naming is
          for Spec_Suffix ("ada") use ".ads";
          for Body_Suffix ("ada") use ".adb";
          for Separate_Suffix use ".adb";
          for Dot_Replacement use ".";
          for Casing use "mixedcase";
       end Naming;

       Ada_Switches := ("-gnato", "-O2");

       package Compiler is
          for Default_Switches ("ada") use Ada_Switches;
       end Compiler;

       package Binder is
          for Default_Switches ("Ada") use ("-n","-Lada");
       end Binder;
    end ada_gen_a;

Ada Sourcefiles:

    --  unit1.ads
    package Unit1 is
       function Add (A, B : Integer) return Integer;
       pragma Export (C, Add, "ada_add");
    end Unit1;
    -- unit1.adb
    package body Unit1 is
       function Add (A, B : Integer) return Integer is
       begin
          return A + B;
       end Add;
    end Unit1;

C Source File:

    /* main.c */
    #include <stdio.h>
    extern void ada_add (void);
    int main (int argc, char *argv[])
    {
       int a = 21, b = 7, c = 0;
       printf ("%d", a);
       printf ("%d", b);
       c = ada_add(a,b);
       printf ("%d", c);
       return 0;
    }

I am using the below GPR to link the above main.c with the Ada static library generated using ada_gen_a.gpr.

    -- Ada_Use_A.gpr
    with "newapi.gpr";
    project Ada_Use_A is

       for Languages use ("C");
       for Source_Dirs use (".");
       for Source_Files use ("main.c");

       package Naming is
          for Casing use "mixedcase";
       end Naming;

       Ada_Switches := ("-gnato", "-O2");

       package Compiler is
          for Default_Switches ("C") use ("-O2", "-Wall");
          for Default_Switches ("Ada") use Ada_Switches;
       end Compiler;

       package Binder is
          for Default_Switches ("Ada") use ("-n","-Lada");
       end Binder;

       for Main use ("main.c");

    end Ada_Use_A;
    -- newapi.gpr
    project newapi is
       for Externally_Built use "true";
       for Source_Files use ();
       for Library_Dir use ".\lib\";
       for Library_Name use "newapi";
       for Library_Kind use "static";
    end newapi;

When I try to build the Ada_Use_A.gpr GPS I get the below linker error, libnewapi.a(unit1.o):unit1.adb:(.text+0x31): undefined reference to __gnat_rcheck_CE_Overflow_Check' gprbuild: link of main.c failed`

Bug in GNAT Get(FRom => SomeString, Item => SomeInteger, Last => Last)?

Get(TheFile, IntValue); works great with strings formatted like 16#12# to read hex values. Shouldn't Get from a string function the same way?

I tried this, but passing 16#12# only yields 16. Pure hex, eg F8 results in an exception

with Ada.Text_IO;         use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;

procedure hex is
   IntValue  : Integer;
   Last : Positive;
begin
   Put("Enter a hexadecimal string: ");
   Get(HexString);

   -- Convert the hexadecimal string to an integer
   Get(From => HexString, Item => IntValue, Last => Last);

   Put ("The integer value is: ");
   Put (IntValue, Width => 0);
   New_Line;
end hex;

Errors trying to run gnattest

I'm trying to run gnattest on a Ada project file:

gnattest -P(projectname)

and I get the following errors:

object path not found for runtime native gnattest: initialization failed

I made sure the gnatpro-v20.2/bin directory was part of the path. I tried adding other gnat directories to the path. I tried running the command inside of GPS and from command line.

Getting the error "error: No index.toml file found in index", when trying to do "alr get gnat_native" and "alr get gprbuild" on Debian

I'm recieving the error error: No index.toml file found in index when I'm trying to use alr get gnat_native and alr get gprbuild on Debian. I made sure that Alire is installed, by using the 'alr' command I get 'alr 1.2.2' when I do the command.

I expected to download the Alire tools, and not to recieve a error when I do alr get gnat_native and `alr get gprbuild'. I made sure that Alire is installed, by using the 'alr' command I get 'alr 1.2.2' when I do the command.

Create a record with a private part

According to this post, I'v try to do a record with a private part. What I've done :

MyFile.ads :

package MyPackage is
  type T_MyType is tagged private;
private
  type T_MyType_Private_Part;
  type T_MyType_Private_Part_Access is access T_MyType_Pirvate_Part;
  type T_MyType is tagged record
    Toto : Boolean;
  end record
end MyPackage;

MyFile.adb :

package body MyPackage is
   type T_MyType_Private_Part is record
     Private_Toto : Boolean;
   end record
end MyPackage;

But when an other package do MyVar.Toto where MyVar is T_MyType I have the error :

no selector "Toto" for type "T_MyType" defined at MyFile.ads

How can I fix this ?

Is there a way to disable arithmetic operators on a specific type in Ada?

I would like to define HTML response status code numbers as a type but disallow arithmetic operators because it wouldn't make sense for them.

type Status_Code is range 100 .. 599;

function "+" (Left, Right : Status_Code) return Status_Code is
begin
      pragma Assert (1 = -1);
      return Left + Right;
end;

The code snippet above on GNAT will give an error saying assertion will fail on runtime, but that is false when I add two of the numbers together. Is there a way to force a compiler error or at least a warning when arithmetic attempted on a type like this?

Error setting the video mode when trying to run the compiled Game_Support example; GNAT Studio;

Trying to compile example /opt/gnatstudio/share/examples/training/games/bouncing/bouncing.gpr

There are no problems when compiling, but when running -

Error setting the video mode
UNCAUGHT EXCEPTION ===
raised STORAGE_ERROR : s-intman.adb:136 explicit raise

Code sample, which I used (it had been moved to another folder, because it does not want to compile in /opt/ - no rights).

with Display; use Display;
with Display.Basic; use Display.Basic;
with Ada.Numerics; use Ada.Numerics;
with Ada.Numerics.Generic_Elementary_Functions;
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Numerics.Float_Random; use Ada.Numerics.Float_Random;

procedure Bouncing is
Seed : Generator;
Buffer_Size : constant := 1_200;

package F_Numeri is new Ada.Numerics.Generic_Elementary_Functions (Float);
use F_Numeri;

Base_Immunity : constant := 500;

type Ball is record
X, Y     : Float := 0.0;
Dx, Dy   : Float := 0.0;
Size     : Float := 0.0;
Mass     : Float := 1.0;
S        : Shape_Id := Null_Shape_Id;
Immunity : Integer := Base_Immunity;
end record
with Dynamic_Predicate => Ball.Mass > 0.0;

type Shape_Array_Type is array (Integer range <>) of Shape_Id;
type Ball_Array_Type is array (Integer range <>) of Ball;

Null_Ball : constant Ball := Ball'(X      => 0.0,
Y      => 0.0,
Dx     => 0.0,
Dy     => 0.0,
Size   => 0.0,
Mass   => 1.0,
S      => Null_Shape_Id,
Immunity => Base_Immunity);
Total_Ball : Integer := 0;

function Speed (B : Ball) return Float is
     (Sqrt (B.Dx * B.Dx + B.Dy * B.Dy));

function Cynetic_Energy (B : Ball) return Float is
     (1.0 / 2.0 * B.Mass * Speed (B) * Speed (B));

function Speed (Cy : Float; Mass : Float) return Float is
     (Sqrt (Cy * 2.0 / Mass));


procedure Create_Ball
     (X : Float; Y : Float; Mass : Float; Velocity : Float; Balls : in out Ball_Array_Type; J : Integer);


type Int_Array is array (Integer range <>) of Integer range 0 .. Buffer_Size;
type Bool_Array is array (Integer range <>) of Boolean;

protected Collision_Manager is
procedure Reset;
procedure Set_Collision (J, K : Integer);
procedure Keep_Immunity (J : Integer);
function Collision_With (J : Integer) return Integer;
function Should_Keep_Immunity (J : Integer) return Boolean;
private
Collision_Vector : Int_Array (1 .. Buffer_Size);
Immunity_Vector : Bool_Array (1 .. Buffer_Size);
end Collision_Manager;

protected body Collision_Manager is
procedure Reset is
begin
Collision_Vector := (others => 0);
Immunity_Vector := (others => False);
end Reset;

procedure Set_Collision (J, K : Integer) is
begin
Collision_Vector (J) := K;
end Set_Collision;

procedure Keep_Immunity (J : Integer) is
begin
Immunity_Vector (J) := True;
end Keep_Immunity;

function Collision_With (J : Integer) return Integer is
begin
return Collision_Vector (J);
end Collision_With;

function Should_Keep_Immunity (J : Integer) return Boolean is
begin
return Immunity_Vector (J);
end Should_Keep_Immunity;

end Collision_Manager;


procedure Create_Graphic (B : in out Ball) is
begin
B.S := New_Circle
        (B.X, B.Y, B.Size,
         (if B.Size > 15.0 then Blue
elsif B.Size > 10.0 then Green
elsif B.Size > 5.0 then Yellow
elsif B.Size > 2.0 then Magenta
else Red));
end Create_Graphic;

function Collision (B1, B2 : Ball) return Boolean is
Dx, Dy : Float;
Size : Float;
begin
if B1 = Null_Ball or else B2 = Null_Ball then
return False;
end if;

Dx := B1.X - B2.X;
Dy := B1.Y - B2.Y;
Size := B1.Size + B2.Size;

return Dx * Dx + Dy * Dy <= Size * Size;
end Collision;

procedure Bounce (B1, B2 : in out Ball) is
Dx : Float;
Dy : Float;
Length : Float;
Dvx : Float;
Dvy : Float;
Impulse : Float;
begin
Dx := B1.X - B2.X;
Dy := B1.Y - B2.Y;
Length := Sqrt (Dx * Dx + Dy * Dy);

if Length /= 0.0 then
Dx := Dx / Length;
Dy := Dy / Length;
Dvx := B1.Dx - B2.Dx;
Dvy := B1.Dy - B2.Dy;
Impulse := -2.0 *  (Dx * Dvx + Dy * Dvy);
Impulse := Impulse / (1.0 / B1.Mass + 1.0 / B2.Mass);

B1.Dx := B1.Dx + Dx * (Impulse / B1.Mass);
B1.Dy := B1.Dy + Dy * (Impulse / B1.Mass);

B2.Dx := B2.Dx - Dx * (Impulse / B2.Mass);
B2.Dy := B2.Dy - Dy * (Impulse / B2.Mass);
end if;
end Bounce;

procedure Explode (Balls : in out Ball_Array_Type; Index : Integer) is
B : Ball := Balls (Index);
V : Float;
Cy : Float;
Sub_Particles : Integer;
begin
Sub_Particles := Integer (Log (X => B.Mass, Base => 2.0) + 1.0);

Total_Ball := Total_Ball - 1;
V := Sqrt (B.Dx * B.Dx + B.Dy * B.Dy);
Cy := 1.0 / 2.0 * B.Mass * V * V;

Delete (Balls (Index).S);
Balls (Index) := Null_Ball;

for J in 1 .. Sub_Particles loop
for K in Balls'Range loop
if Balls (K) = Null_Ball then
Create_Ball
                 (X       => B.X + Random (Seed) * B.Size - B.Size / 2.0,
Y       => B.Y + Random (Seed) * B.Size - B.Size / 2.0,
Mass     => B.Mass / Float (Sub_Particles),
Velocity => Speed
                    (Cy / Float (Sub_Particles),
B.Mass / Float (Sub_Particles)),
Balls => Balls,
J => K);

Create_Graphic (Balls (K));

exit;
end if;
end loop;
end loop;
end Explode;

procedure Combine (Balls : in out Ball_Array_Type; J, K : Integer) is
B1 : Ball := Balls (J);
B2 : Ball := Balls (K);
Cy : Float := Cynetic_Energy (B1) + Cynetic_Energy (B2);
begin
Total_Ball := Total_Ball - 2;

Delete (Balls (K).S);
Balls (K) := Null_Ball;

Delete (Balls (J).S);

Create_Ball
        (B1.X + (B1.X - B2.X) / 2.0,
B1.Y + (B1.Y - B2.Y) / 2.0,
B1.Mass + B2.Mass,
Speed (Cy, B1.Mass + B2.Mass),
Balls,
J);

Create_Graphic (Balls (J));
end Combine;

procedure Create_Ball
     (X : Float; Y : Float; Mass : Float;
Velocity : Float; Balls : in out Ball_Array_Type; J : Integer)
is
B : Ball renames Balls (J);
Angle : Float := Random (Seed) * 2.0 * Pi;
begin
Total_Ball := Total_Ball + 1;
B.X := X;
B.Y := Y;


B.Dx := Cos (Angle) * Velocity;
B.Dy := Sin (Angle) * Velocity;

B.Mass := Mass;
B.Size := Sqrt (B.Mass);
B.Immunity := Base_Immunity;
Collision_Manager.Keep_Immunity (J);
end Create_Ball;


Lines : constant Shape_Array_Type (1 .. 4) :=
     (New_Line (-100.0, -100.0, 100.0, -100.0, Blue),
New_Line (-100.0, -100.0, -100.0, 100.0, Blue),
New_Line (100.0, 100.0, 100.0, -100.0, Blue),
New_Line (100.0, 100.0, -100.0, 100.0, Blue));

R : Float;

Balls_Txt : Shape_Id := New_Text (110.0, 90.0, "0", White);
Explode_Txt : Shape_Id := New_Text (110.0, 80.0, "0", White);
Combine_Txt : Shape_Id := New_Text (110.0, 70.0, "0", White);

Combine_Prob : Float := 0.04;
Explode_Prob : Float := 0.02;

Ball_Array : Ball_Array_Type (1 .. Buffer_Size) := (others => Null_Ball);


task type Collision_Detection (Size, Modulus, Ind : Integer) is
entry Compute;
entry Finished;
entry Stop;
end Collision_Detection;

task body Collision_Detection is
Do_Work : Boolean := True;
J : Integer;
begin
while Do_Work loop
select
accept Compute;

J := Ind;

if J = 0 then
J := J + Modulus;
end if;

while J <= Size loop
if Ball_Array (J) /= Null_Ball then
for K in J + 1 .. Ball_Array'Last loop
if Collision (Ball_Array (J), Ball_Array (K)) then
if Ball_Array (J).Immunity = 0
and then Ball_Array (K).Immunity = 0
then
Collision_Manager.Set_Collision (J, K);
end if;

Collision_Manager.Keep_Immunity (J);
Collision_Manager.Keep_Immunity (K);
end if;
end loop;
end if;

J := J + Modulus;
end loop;

accept Finished;
or
accept Stop;

Do_Work := False;
end select;
end loop;
end Collision_Detection;

D1 : Collision_Detection (1200, 4, 0);
D2 : Collision_Detection (1200, 4, 1);
D3 : Collision_Detection (1200, 4, 2);
D4 : Collision_Detection (1200, 4, 3);
begin
for J in 1 .. 20 loop
declare
B : Ball renames Ball_Array (J);
begin
Create_Ball (0.0, 0.0, Random (Seed) * 75.0 + 4.0, 0.5, Ball_Array, J);
Create_Graphic (B);
end;
end loop;

loop
Collision_Manager.Reset;

D1.Compute;
D2.Compute;
D3.Compute;
D4.Compute;

D1.Finished;
D2.Finished;
D3.Finished;
D4.Finished;

for J in Ball_Array'Range loop
if Ball_Array (J) /= Null_Ball then
declare
K : Integer;
begin
if not Collision_Manager.Should_Keep_Immunity (J) then
Ball_Array (J).Immunity := 0;
end if;

K := Collision_Manager.Collision_With (J);

if K /= 0 and then Ball_Array (K) /= Null_Ball then
R := Random (Seed);

if R in 1.0 - Explode_Prob - Combine_Prob
1.0 - Combine_Prob
then
if Ball_Array (J).Mass > Ball_Array (K).Mass then
Explode (Ball_Array, J);
else
Explode (Ball_Array, K);
end if;
elsif R in 1.0 - Combine_Prob .. 1.0 then
Combine (Ball_Array, J, K);
else
Bounce (Ball_Array (J), Ball_Array (K));
end if;
end if;
end;
end if;
end loop;

for J in Ball_Array'Range loop
declare
B : Ball renames Ball_Array (J);
begin
if B /= Null_Ball then
if (B.X - B.Size < -100.0 and then B.Dx < 0.0)
or else (B.X + B.Size > 100.0 and then B.Dx > 0.0)
then
B.Dx := -B.Dx;
end if;

if (B.Y - B.Size< -100.0 and then B.Dy < 0.0)
or else (B.Y + B.Size> 100.0 and then B.Dy > 0.0)
then
B.Dy := -B.Dy;
end if;

B.X := B.X + B.Dx;
B.Y := B.Y + B.Dy;

if B.Immunity > 0 then
B.Immunity := B.Immunity - 1;
end if;

Set_X (B.S, B.X);
Set_Y (B.S, B.Y);
end if;
end;
end loop;

Set_Text (Balls_Txt, "Balls:" & Total_Ball'Img);
Set_Text (Explode_Txt, "Explode Prob:" & Integer (Explode_Prob * 1000.0)'Img & " / 1000");
Set_Text (Combine_Txt, "Combine Prob:" & Integer (Combine_Prob * 1000.0)'Img & " / 1000");

declare
Last_Key : Key_Type := Current_Key_Press;
begin
if To_Character (Last_Key) = 'q' then
Explode_Prob := Explode_Prob - 0.001;
elsif To_Character (Last_Key) = 'w' then
Explode_Prob := Explode_Prob + 0.001;
elsif To_Character (Last_Key) = 'a' then
Combine_Prob := Combine_Prob - 0.001;
elsif To_Character (Last_Key) = 's' then
Combine_Prob := Combine_Prob + 0.001;
end if;
end;

delay 0.01;
end loop;
end Bouncing;

The project file itself

bouncing.gpr

with "/opt/gnatstudio/share/gpr/game_support.gpr";
with "/opt/gnatstudio/share/gpr/gnat_sdl.gpr";

project bouncing is

for Main use("bouncing.adb");

for Object_Dir use "obj";
for Source_Dirs use("src");

end Bouncing;


tually, I had been compile and run some more simple example with the same result:

with Display; use Display;
with Display.Basic; use Display.Basic;

procedure Main is
Ball : Shape_Id := New_Circle
     (X      => 0.0,
Y      => 0.0,
Radius => 10.0,
Color  => Blue);
Step : Float := 0.05;
begin
loop
if Get_X (Ball) > 100.0 then
Step := -0.05;
elsif Get_X (Ball) < -100.0 then
Step := 0.05;
end if;

Set_X (Ball, Get_X (Ball) + Step);

delay 0.001;
end loop;
end Main;

I had tried to recompile Game_Support, git cloned from here.

I had tried to reinstall GNAT, Gnat Studio, etc.

I CAN run and compile another simple projects, for example with TEXT_IO package, I can run Gnat Studio, but I cannot run this app. I can run analogue, wrote with C++, so the problem is not in my OpenGl 1.3 hardware support.

  • System: Arch Linux.
  • IDE: Gnat Studio. (Install from AUR).
  • Dependencies (SDL, SDL2) - installed.

Test harness file is not creating for generic "when trying to test with generic instance"

while testing generic file thruogh instance in GNAT test AUnit framework.I am getting below error. Test harness is not creating for the file under test, which has generic; instead of that it is creating all other unwanted test harness files.

pal_api-btm-commands.ads:45:3: 
    error: corresponding test FAILED: Test not implemented. 
    (pal_api-btm-commands-test_data-tests.adb:44) 

pal_api-btm-commands.ads:55:3: 
    error: corresponding test FAILED: Test not implemented. 
    (pal_api-btm-commands-test_data-tests.adb:65)

Please let me know how to generate test harness file for generics which is implemented with its instance

How do I get useful data from a UDP socket using GNAT.Sockets in Ada?

Summary:

I am writing a server in Ada that should listen and reply to messages received over UDP. I am using the GNAT.Sockets library and have created a socket and bound it to a port. However, I am not sure how to listen for and receive messages on the socket. The Listen_Socket function is for TCP sockets and it seems that using Stream with UDP sockets is not recommended. I have seen the receive_socket and receive_vector procedures as alternatives, but I am not sure how to use them or how to convert the output to a usable format.

More details:

I am writing a server that should reply to messages that it gets over UDP. A minimal example of what I have so far would look like this:

with GNAT.Sockets;use GNAT.Sockets;

procedure udp is
    sock: Socket_Type;
    family: Family_Type:=Family_Inet;
    port: Port_Type:=12345;
    addr: Sock_Addr_Type(family);
begin
    Create_Socket(sock,family,Socket_Datagram);
    addr.Addr:=Any_Inet_Addr;
    addr.Port:=port;
    Bind_Socket(sock,addr);
    -- Listen_Socket(sock); -- A TCP thing, not for UDP.
    -- now what?
end UDP;

For a TCP socket, I can listen, accept, then use the Stream function to get a nice way to read the data (as in 'Read and 'Input). While the Stream function still exists, I have found an archive of a ten year old comp.lang.ada thread in which multiple people say not to use streams with UDP.

Looking in g-socket.ads, I do see alternatives: the receive_socket and receive_vector procedures. However, the output of the former is a Stream_Element_Array (with an offset indicating the length), and the latter has something similar, just with some kind of length associated with each Stream_Element.

According to https://stackoverflow.com/a/40045312/7105391, the way to change these types into a stream, is to not get them in the first place, and instead get a stream, which is not particularly helpful here.

Over at this github gist I found , Unchecked_Conversion is being used to turn the arrays into strings and vice versa, but given that the reference manual (13.13.1) says that type Stream_Element is mod <implementation-defined>;, I'm not entirely comfortable using that approach.

All in all, I'm pretty confused about how I'm supposed to do this. I'm even more confused about the lack of examples online, as this should be a pretty basic thing to do.

How would I define the __builtin_blendvps256 GCC intrinsic in Ada using GNAT?

I am trying to define a library in Ada (built on GNAT specifically) for x86 ISA extensions. (This question is specific to AVX/AVX2).

Here is some example code below:

-- 256-bit Vector of Single Precision Floating Point Numbers
type Vector_256_Float_32 is array (0 .. 7) of IEEE_Float_32 with
  Alignment => 32, Size => 256, Object_Size => 256;
pragma Machine_Attribute (Vector_256_Float_32, "vector_type");
pragma Machine_Attribute (Vector_256_Float_32, "may_alias");

-- 256-bit Vector of 32-bit Signed Integers
type Vector_256_Integer_32 is array (0 .. 7) of Integer_32 with
  Alignment => 32, Size => 256, Object_Size => 256;
pragma Machine_Attribute (Vector_256_Integer_32, "vector_type");
pragma Machine_Attribute (Vector_256_Integer_32, "may_alias");

-- 256-bit Vector of 32-bit Unsigned Integers
type Vector_256_Unsigned_32 is array (0 .. 7) of Unsigned_32 with
  Alignment => 32, Size => 256, Object_Size => 256;
pragma Machine_Attribute (Vector_256_Unsigned_32, "vector_type");
pragma Machine_Attribute (Vector_256_Unsigned_32, "may_alias");

function vblendvps
  (Left, Right, Mask : Vector_256_Float_32)
   return Vector_256_Float_32 with
  Inline_Always => True, Convention => Intrinsic, Import => True,
  External_Name => "__builtin_ia32_blendvps256";

For the sake of education, I want to know how to do this in assembly.

I have tried to define the vblendvps function using the Asm function from System.Machine_Code. However, as I am not knowledgeable about assembly programming, I am struggling to find resources on how to do this.

This is what I have so far:

with System.Machine_Code; use System.Machine_Code;

function vblendvps
(Left, Right, Mask : Vector_256_Float_32)
return Vector_256_Float_32
is
result : Vector_256_Float_32;
begin
Asm
(Template => "vblendvps %3, %0, %1, %2",
 Outputs  => Vector_256_Float_32'Asm_Output ("=g", result),
 Inputs   =>
   (Vector_256_Float_32'Asm_Input ("g", Left),
    Vector_256_Float_32'Asm_Input ("g", Right),
    Vector_256_Unsigned_32'Asm_Input ("g", Mask)));
return result;
end vblendvps;

When compiling the complete code, I get

Error: too many memory references for `vblendvps'

I believe this means that I need to move the arguments from memory to registers, but I am not sure. If there are some helpful references that explain every instruction, I would greatly appreciate that. (I had quite some trouble looking up the arguments to vblendvps).

My understanding is that the instruction is of the form (from ymm registers in my case)

vblendvps RESULT, LEFT, RIGHT, MASK

Please let me know how I would do this. Even if it is not in Ada, I'm sure I can figure out how to translate it.

Ada2012 & GNAT: compile library under a namespace

Can I compile a library adding a namespace at compile time using GNAT? I have to link to a legacy library that don't use a root package and child packages, so it's very annoying having hundred of options when I have to include something.

The other option I have is to write a Python script to add the root package to all files to reduce the problem.

โŒ
โŒ