❌ About FreshRSS
There are new articles available, click to refresh the page.
Today — 1 October 2022News from the Ada programming language world

October 2022 What Are You Working On?

Welcome to the monthly r/ada What Are You Working On? post.

Share here what you've worked on during the last month. Anything goes: concepts, change logs, articles, videos, code, commercial products, etc, so long as it's related to Ada. From snippets to theses, from text to video, feel free to let us know what you've done or have ongoing.

Please stay on topic of course--items not related to the Ada programming language will be deleted on sight!

Previous "What Are You Working On" Posts

submitted by /u/marc-kd
[link] [comments]
Yesterday — 30 September 2022News from the Ada programming language world

freeing access-to-task ; calling inherited methods

Two blog posts on:

https://deepbluecap.com/blog/

The first one suggests a pattern to call an inherited primitive operations, when it has been overridden in a derived type.

The second one explains how to free an access-to-task object and avoid invalid memory accesses.

submitted by /u/manubriot
[link] [comments]
Before yesterdayNews from the Ada programming language world

Order in generic

Suppose we have a types:

type ABC is (A, B, C);
type BAC is (B, A, C);
type CBA is (C, B, A);

Is there any way to declare generic package with parameter Order:

generic
   type Order is ...
package Pkg
    
   type Value_Type is ...
    
   type Value_Type_Array is array (Order) of Value_Type;
    
end Pkg;

that after instantiation I can have 3 different types:

AA : Package_ABC.Value_Type_Array;
BB : Package_BAC.Value_Type_Array;
CC : Package_CBA.Value_Type_Array;

2D array range

Let's say I have a type:

type A_Type is array (1..3, 1..5) of Integer;

and I want to get or put the entire array.

I could quite simply do this with two for loops and telling the range as the numbers given in the type.

But how can I do this more generally, say, using A_Type'Range?

my guess is that A_Type'Range refers to 1..3 in this case. How do I refer to the range 1..5 ?

submitted by /u/Ponbe
[link] [comments]

Capturing stderr stream

Here is my situation: I have a program running on Linux. For debugging and for support purpose, I use a custom package to log messages. It basically prepends a timestamp to every message and then calls Ada.Text_IO to Put_Line to specific log files. More specifically, I call this package in "exception" handling statements to log error messages. So far, this is pretty standard I guess...

My problem is that I use libraries that sometime output warnings/errors to stdout/stderr (without raising any error). How could I also capture these and timestamp them inside my Ada program? I know that I could redirect the Linux standard streams to a process that timestamps and logs things in parallel but I have to keep it as single-threaded as possible.

I've experimented with Ada.Text_IO.Set_Error but it seems that it only affects Ada.Text_IO.Current_Error. So for example, if some code raises a runtime error, it is always displayed on stderr and not to the file I've specified in Ada.Text_IO.Set_Error.

with Ada.Text_IO; use Ada.Text_IO; procedure TEST_ERROR_STREAM is ERROR_LOG : FILE_TYPE; begin OPEN (ERROR_LOG, OUT_FILE, "error_log.txt"); SET_ERROR (ERROR_LOG); PUT_LINE (CURRENT_ERROR, "this line is going to error_log.txt"); RAISE_A_RUNTIME_ERROR; -- The message of the error that is raised -- is going to stderr while I wish it could -- go to error_log.txt end TEST_ERROR_STREAM; 
submitted by /u/pea2021
[link] [comments]

Self dependency in Spark 2014

I'm trying to write the flow dependency of a procedure in Ada and Spark 2014 and the compiler give me a medium warning that

medium: missing dependency "null => MyBool"
medium: incorrect dependency "MyBool => MyBool"

Here is my .ads file:

SPARK_Mode (On);
package TestDep is

  pragma Elaborate_Body;

  MyBool: Boolean := False;

  procedure ToFalse with
    Global => (In_Out => MyBool),
    Depends => (MyBool =>+ null),
    Pre => (MyBool = True),
    Post => (MyBool = False);

end TestDep;

and in the .adb:

pragma SPARK_Mode (On);
package body TestDep is

  procedure ToFalse is
  begin
    MyBool := False;
  end ToFalse;

end TestDep;

I'm new to Ada and Spark and I'm still learning it, but from the AdaCore documentation I've saw that Depends => (X =>+ null) should indicate that the value of X at the end of the procedure only depends on the value of X and nothing else.

Why does the compiler give me those warning ? Am I doing something wrong ?

GMP-Ada: An implementation of Ada.Numerics.Big_Numbers using libgmp

Hello, the other day I was looking through Ada 2022's new features and was intrigued by the addition of Big_Numbers. I used the traditional test for large number calculation speed (https://benchmarksgame-team.pages.debian.net/benchmarksgame/performance/pidigits.html) and was saddened to discover that GNAT's current implementation doesn't work past 200 32-bit digits and is rather lethargic if you remove the limit and press ahead anyway.

I was also very interested in trying out Ada 2022's new Put_Image and Integer_Literal aspects, so I gave a try at implementing my own version of Big_Numbers: https://github.com/andrewathalye/libgmp-ada2022. It should work on any platform that GNAT and GMP run on, although it does need Ada 2022 support.

Some brief benchmarks: the C version of pidigits takes about 540 milliseconds on my machine to compute 10000 digits. The Ada version using wrapped libgmp directly takes 580 milliseconds (the wrapping is typesafe, although not super convenient). My simple Big_Integers wrapper takes 1.3 seconds, and the GNAT builtin version takes 8.5 seconds (after removing the hardcoded limit in System.Generic_Bignums), all compiled with -O2 -march=native.

​

This was also a great opportunity to learn how to use Ada.Finalization.Controlled, so it will automatically free the memory used by the mpz_t object and its data after Big_Integer goes out of scope. Hopefully this is useful to some of you, and I'd love to hear any criticism / comments that you have.

​

Edit: As a small update, I'd like to mention that GNAT currently includes an implementation of Big_Integers which uses GMP, although it is not enabled (and there doesn't appear to be a way to enable it without removing the other implementation and renaming it). I was not aware of this, but if you build GNAT from source then that would be a good option as well.

​

Big_Reals is implemented by GNAT using a Big_Integer for the Numerator and Denominator, so this implementation of Big_Integers also improves the performance of Big_Reals (as does the official GNAT __gmp variant). I don't yet have the ability to test the performance of my wrapper against that of GNAT's __gmp variant, but I suspect they're pretty close since they both have a low-level interface using mpz_t from libgmp.

​

A future thing to consider would be using MPFR or simply GMP to implement Big_Reals directly, however I'm not sure if that would give any real performance benefit during calculations, and real numbers are also a bit more complex to handle correctly than Integers :) Thanks for the feedback as always, and I'll be sure to improve my technique following your advice.

submitted by /u/ZENITHSEEKERiii
[link] [comments]
❌
❌