❌ About FreshRSS

Normal view

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

Where is Sparklib?

By: wutka
5 December 2022 at 20:51

I wanted to try out some of the formal containers for SPARK, but I am having trouble finding the Sparklib mentioned in the Spark docs. My GNAT Studio doesn’t have a SPARK category under Help, as the SPARK manual mentions, and I usually do everything with ALR. I do see the SPARK Lemma libraries in my ALR cache of Gnatprove, but not the other libraries.

3 posts - 3 participants

Read full topic

Object-oriented methods in Ada

By: Roald
7 December 2022 at 23:38

Having written Java code for a few decades, there are some facets that I find to be a “must” (without having any good reason for it). One such thing is the way object-orientation makes use of methods. So, while I now try to learn myself Ada (have some PL/SQL experience), I find myself searching for method declaration.

As everyone who has coded Java knows, a method is written as a function within the class declaration. When the method is called, it is called as something that belongs to the class (or rather the object).

Ex. A Java class C may have a method m(x, y, …). And object o of class C can then use this method through the call:
o.m(x, y, …)

Having search (or skimmed) through both literature and the net, it is my understanding that the closet we get in Ada is to have a procedure or a function, with the first argument being of the containing type, declared in the type declaration, and then calling that proc/func by passing a variable of that type as the parameter (sorry if I mess this up, I know what I’m thinking, but putting it in writing is less clear). This would lead to a proc/func call similar to:

m(o, x, y, …)

Or have I missed something?

What is the “correct” object oriented way of writing the following in Ada?
public class Hello
{
public void SayHello()
{
System.out.println( “Hello World!”);
}
}

And similar upon use:
{
Hello greeting = new Hello();
greeting.SayHello();
}

Your help and patience are appreciated.

:slight_smile: Roald

15 posts - 10 participants

Read full topic

What is the purpose of "=" in Containers.Hashed_Sets?

By: OPi
8 December 2022 at 21:57

Containers.Hashed_Sets is a generic package that reclaims Element_Type, Hash function, Equivalent_Elements function and "=" function.
Why there is two functions to specify equivalence/equality?

generic
   type Element_Type is private;
   with function Hash (Element : Element_Type) return Hash_Type;
   with function Equivalent_Elements (Left, Right : Element_Type)
                 return Boolean;
   with function "=" (Left, Right : Element_Type) return Boolean is <>;
package Ada.Containers.Hashed_Sets is

https://docs.adacore.com/live/wave/arm12/html/arm12/arm12-A-18-8.html

8 posts - 3 participants

Read full topic

Ada.Containers.Hash_Type'Size

9 December 2022 at 23:51

I’ve been playing with optimizations for an instance of Ada.Containers.Hashed_Sets for the Advent of Code Day 9 puzzle.

RM A.18.1 The Package Containers says:

type Hash_Type is mod implementation-defined;

With the Implementation advice:

Hash_Type'Modulus should be at least 2**32.

The annotated RM expands upon this:

This is not a requirement so that these types can be declared properly on machines with native sizes that are not 32 bits. For instance, a 24-bit target could use 2**24 for Hash_Type'Modulus.

In GNAT’s a-contai.ads, the definition is simply:

type Hash_Type is mod 2**32;

Would it make sense to use System.Max_Binary_Modulus instead, so that 64-bit systems can benefit from a larger hash space?

type Hash_Type is mod System.Max_Binary_Modulus;

If we want to retain the minimum 32-bit size, a conditional could be added:

type Hash_Type is mod (if System.Max_Binary_Modulus >= 32 then System.Max_Binary_Modulus else 32);

1 post - 1 participant

Read full topic

Aggregates as initial value of an array

10 December 2022 at 10:41

Hello!
I’m stuck with this array construct.
Can’t find the syntax clue to initialize an array of records, with the particularity I aim to pass the array as an in out variable, without needing to pass en extra index (ID) info.

(for K_ID in Knot_ID => ^
Compile error: missing “,” at ^

even with -gnat2022 and -gnatX switches, or pragma Ada_2022;

   subtype Knot_ID is Integer range Head_Knot .. Tail_Knot;
   type Grid_Position is record 
      X : X_Dimension;
      Y : Y_Dimension; 
   end record;

   type Knot_record is record
      ID : Knot_ID;
      Pos : Grid_Position;
   end record;

   type Rope_array is array (Knot_ID'Range) of Knot_record;

(...)

   Rope_Positions, Previous_Rope_Positions : Rope_array := 
--    (others => (ID => Head_Knot, Pos => (0,0)));  --:FIXME:  ID => Knot_ID'Range
      (for K_ID in Knot_ID => (ID => K_ID => (ID => K_ID, Pos => (0,0))));

see Ada 2012/2012 Array Aggregates
see Overview of Ada 2022
Compiler is FSF gcc-gnat 12.2.0

William

3 posts - 2 participants

Read full topic

Various questions about Ada

By: HonkiTonk
10 December 2022 at 16:38

I have a few Ada questions that I’ll just summarize in one post.

If I always have to completely rewrite a file, then it makes no difference whether I use Open or Create. Is that correct or did I miss something?

Currently I use Stream_IO to write files, the files contain different data types. Do other writing methods, such as Sequential_IO, produce smaller files that justify the extra effort to use them? Or are they practically all equally efficient?

I use Pure, Preelaborate and Elaborate_Body whenever possible. However, I have some files that don’t allow Pure/Preelaborate and since they don’t have a body, Elaborate_Body isn’t possible either. However, I would still like to know if there is a circular dependency. Are there any other options besides giving all files a body?

Is there a standard function that returns the number of elements in an enum subtype, or do I have to write it myself?

6 posts - 4 participants

Read full topic

Ada Behind A Historical Milestone

13 December 2022 at 18:30

Many of you have probably heard the news that Lawrence Livermore’s National Ignition Facility (NIF) has achieved net-energy production fusion (ignition): https://www.llnl.gov/news/national-ignition-facility-achieves-fusion-ignition

Well it turns out that, at a minimum, the control system of the giant laser that makes NIF possible was written in Ada.

So looks like Ada software has now had a key role in what could be a new era in human achievement!

Very cool stuff.

12 posts - 6 participants

Read full topic

Treesitter grammar for Ada

By: ebriot
15 December 2022 at 08:15

I have recently completed an Ada grammar for TreeSitter.

TreeSitter is meant to be a fast parser used by editors (currently Emacs and neovim, that I know of) or various platforms when they syntax-highlight code (github uses treesitter I believe). The tree-sitter-ada page above gives some hints on how things should be setup in neovim, but I have no recent experience with Emacs.

I am in the process of submitted that to treesitter-nvim and treesitter projects, to make the whole setup easier.

The grammar is strongly based on the one in the Ada Reference Manual, but also draws some ideas from the similar grammar that Stephen Leak has written for the Emacs ada-mode.

There is a reasonable testsuite in place, and I am able to parse all sources from the GNAT runtime and the 3 million lines of Ada code at my company without errors (which of course doesn’t mean that I get a meaningful tree in all cases).

TreeSitter is actually a multi-staged process:

  • we need a grammar to create a tree (which is supposed to be much simpler than an AST like a compiler or libadalang would use, and could even have ambiguities).
  • each editor then needs various modules to take advantage of treesitter, like supporting syntax highlighting, code folding, jumping to various constructs, indentation,…
  • each language need to provide the actual queries. My github repository provides support for syntax-highlighting, block folding and jumping, but not indentation yet.

Syntax-highlighting is a nice example: compared to regex-based highlighting, we can perform more advanced things, like highlighting subprogram specs, underlining parameter names, italicizing gnatprep if-statements, …

Compared to the current vim ada mode, treesitter provides much better support for code folding (“za”), since it knows the bounds for a subprogram or package body, if-statement and other loops.

Emmanuel

5 posts - 4 participants

Read full topic

Ada Drivers Library

By: ptihanyi
15 December 2022 at 15:02

Hello!
Could you help me how I can build an arbitrary stm32f429-discovery example project from Ada_Drivers_Library?
I am using Ubuntu linux, installed on Ali and can create/build native projects.
I installed the gnat-arm-elf toolchain with alr.
I tried the following:
I cloned the repository, and created a library project in-place with alr in the repo directory. Then I selected gnat-arm-elf toolchain.
Then I issued this:
alr exec – ./scripts/install_dependencies.py

The process stops with the following error:

ROOT_DIR :/home/ptihanyi/adawsp/Ada_Drivers_Library
/home/ptihanyi/adawsp/Ada_Drivers_Library/bb-runtimes already cloned
Running build command:
$ /usr/bin/python3 /home/ptihanyi/adawsp/Ada_Drivers_Library/bb-runtimes/install.py --arch=arm-eabi --prefix=/home/ptihanyi/.config/alire/cache/dependencies/gnat_arm_elf_12.2.1_9be2ca0e/bin/../arm-eabi/lib/gnat
install runtime sources for stm32f4

Dependency install command error (returned 1):
Traceback (most recent call last):
  File "/home/ptihanyi/adawsp/Ada_Drivers_Library/bb-runtimes/./build_rts.py", line 317, in <module>
    main()
  File "/home/ptihanyi/adawsp/Ada_Drivers_Library/bb-runtimes/./build_rts.py", line 293, in main
    projects += installer.install(
  File "/home/ptihanyi/adawsp/Ada_Drivers_Library/bb-runtimes/support/bsp_sources/installer.py", line 168, in install
    runtime_sources = self._find_rts_sources(destination, rts_descriptor)
  File "/home/ptihanyi/adawsp/Ada_Drivers_Library/bb-runtimes/support/bsp_sources/installer.py", line 145, in _find_rts_sources
    assert ret is not None, "Cannot find %s" % rts_json_file
AssertionError: Cannot find rts-sources.json
Traceback (most recent call last):
  File "/home/ptihanyi/adawsp/Ada_Drivers_Library/bb-runtimes/install.py", line 74, in <module>
    main()
  File "/home/ptihanyi/adawsp/Ada_Drivers_Library/bb-runtimes/install.py", line 70, in main
    subprocess.check_call(cmd)
  File "/usr/lib/python3.10/subprocess.py", line 369, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['/usr/bin/python3', './build_rts.py', '--build', '--force', '--output=/home/ptihanyi/.config/alire/cache/dependencies/gnat_arm_elf_12.2.1_9be2ca0e/arm-eabi/lib/gnat', 'stm32f4', 'nucleo_f401re', 'stm32f429disco', 'stm32f469disco', 'stm32f746disco', 'stm32756geval', 'stm32f769disco', 'samg55', 'sam4s', 'samv71', 'openmv2', 'rpi2', 'feather_stm32f405', 'stm32f051r8-hsi', 'nrf52832', 'nrf52840', 'cortex-m0', 'cortex-m0p', 'cortex-m1', 'cortex-m3', 'cortex-m4', 'cortex-m4f', 'cortex-m7f', 'cortex-m7df', 'cortex-m23', 'cortex-m33f', 'cortex-m33df', 'rpi-pico', 'rpi-pico-smp']' returned non-zero exit status 1.

Many thanks!

9 posts - 3 participants

Read full topic

Am I doing something wrong here?

By: cantanima
19 December 2022 at 00:38

I use Ada for my personal projects, largely out of admiration for the language, but I’m entirely self-taught in Ada, and the literature on its usage is… well, somewhat scant in comparison to, say, C++.

Not every language is perfect, but some things in the standard Ada library seem far too cumbersome. So much so, that I have to wonder if I’m doing things right. I’ve looked at the ARM, perhaps not well, and rosetta code is down at the moment, so I thought I’d inquire here.

Queues

Setting up a queue seems to involve way more effort than it should:

  • You have to include two separate packages:
    • Containers.Synchronized_Queue_Interfaces
    • Containers.Unbounded_Synchronized_Queues or one of the other three variants
  • You have to use all type Ada.Containers.Count_Type if you want to check whether it’s empty.

The payoff? For all the effort you put into creating it, the resulting queue offers less functionality than other languages’. All you can do is Enqueue, Dequeue, and check usage. You can’t iterate through the queue to see what’s there and possibly modify it, nor search through it, let alone split the queue. There isn’t even an .Is_Empty method to tell you when it’s exhausted.

Queues are pretty common, and I’ve never seen one so bare bones. Is there something more functional than this in the standard library? If not, do people recommend a different library (e.g,. the Simple Components library) or do you typically roll your own?

(I realize there may be good reasons for the library to do things this way; I’m just wondering what people do about it.)

Iteration through maps

Suppose I set up a map M and want to iterate through it.

  • for E of M iterates through the map’s elements, not through its keys. I wish they had returned the keys instead, since often that’s what I want, and it’s easy to obtain the elements from the keys, and not so much the converse. But this does make sense.
  • for C in M.Iterate iterates a cursor through the key/pair combinations. This makes sense, too. But…
  • Using Cursor is, again, cumbersome. As far as I can tell, I can’t do this: C.Key or C.Element. Instead, I have to with all type Map_Type.Cursor to get Key(C) and Element(C), or else qualify the functions fully: Map_Type.Key(C) or Map_Type.Element(C).

(I think Ada 2022 introduces functionality to let me treat a cursor the way I want, but if so, I have to update my gnat: version 20210519-103.)

So what am I doing wrong?

Have I missed something, or is this indeed the standard way of doing these things in Ada? I would be grateful for any direction, because I don’t use Ada often enough to remember these two things, and the compiler’s help error messages are not the greatest.

Honestly!

I apologize if it comes across as a complaint. I realize there’s no perfect language, and just want to know if I’m missing something, because Ada does so many things right. I can make much, much longer lists of my complaints with C++, and a somewhat longer list of complaints with Rust, than I can with Ada.

9 posts - 4 participants

Read full topic

AEiC 2023 - Ada-Europe conference - Call for Contributions

20 December 2022 at 17:22

The 27th Ada-Europe International Conference on Reliable Software Technologies (AEiC 2023) will take place in Lisbon, Portugal, in the week of 13-16 June.

The conference schedule comprises a journal track, an industrial track, a work-in-progress track, a vendor exhibition, parallel tutorials, and satellite workshops.

Deadlines: 13 February 2023 for journal-track papers (extended); 27 February 2023 for industrial-track and work-in-progress-track papers, tutorial and workshop proposals.

Full details are available on the conference site, including an extensive list of topics and more information on the call for various kinds of contributions.

http://www.ada-europe.org/conference2023

#AEiC2023 #AdaEurope #AdaProgramming

2 posts - 1 participant

Read full topic

Opening a file Ada.Text_IO.Open (...) using GNAT compiler makes a heap allocation

24 December 2022 at 13:48

While doing advent of code challenges and making sure the solutions do not make any heap allocations during run-time except for application start up (elaboration time), I’ve discovered that opening a file with Ada.Text_IO.Open (…) generates a heap allocation. It means that if one does not closes the file, either deliberately or by mistake due to raising of an exception not only would make an application leak file handles but also memory.

One may wonder about why this is so. I did not expect a heap allocation opening a file. Maybe this is applies only to the implementation of the standard library Ada.Text_IO package of the GNAT compiler, but not for example to the Ada.Streams.Stream_IO package (I haven’t checked!). One reason that I can imagine is usage of Taft Types (Opaque types). It means a File_Type is defined in the public part of the specification package of Text_IO but the exact details of File_Type is defined in the body of the Text_IO package. It is smart because one only needs to replace the body of Text_IO package when porting the standard library to another platform or operating system. The down side is that Taft Types, introduced in Ada83, is closely connected with heap allocations (my experience is that it is hard to avoid heap allocations when using Taft Types).

Any other reason for making heap allocation when opening file?

5 posts - 4 participants

Read full topic

`alr --bin init` creates crates GPS can't make sense of?

By: cantanima
29 December 2022 at 03:52

I do the following, per the Alire Quickstart instructions:

alr init --bin my_proj
cd my_proj
alr build
alr run

Next I try to edit it:

alr edit

The most recent gnatstudio is in my path, so the editor pops up in the crate. Trouble is, it doesn’t seem to understand the project file at all. (Screenshot below.) To wit:

  • src has a source file in it, but the icon isn’t expandable.
  • While there are “build” and “run” buttons, they doesn’t actually build and run the program; rather, they seem good only for generating Uncaught Exceptions; see output below.
  • This is not a problem with pre-existing alire crates; it’s only a problem for anything I try to generate now.

Weirdly, this was working earlier today, which makes me think I broke something at some point. Does anyone have any suggestions for figuring out how to fix it?

Uncaught exception in workflows:
Traceback (most recent call last):
  File "/path/to/opt/gnatstudio/share/gnatstudio/support/ui/workflow_buttons.py", line 133, in build_main
    r0 = yield builder.wait_on_execute(main_name)
  File "/path/to/opt/gnatstudio/share/gnatstudio/support/ui/workflows/promises.py", line 1108, in wait_on_execute
    self.__target.execute(main_name=main_name,
  File "/path/to/opt/gnatstudio/share/gnatstudio/support/core/extensions/__init__.py", line 380, in execute
    self._internal_execute(
GPS.Unexpected_Exception: unexpected internal exception raised CONSTRAINT_ERROR : gnatcoll-projects.adb:5729 index check failed
[/path/to/opt/gnatstudio/bin/../lib/gnatstudio/libgnatcoll.so.23.0w]
0x7f1c6cc179c1 gnatcoll__projects__compute_scenario_variables__register_untyped_var.1798.constprop.0 at ???
0x7f1c6cc17d06 gnatcoll__projects__compute_scenario_variables__register_var.1778 at ???
0x7f1c6cc238c7 gnatcoll__projects__for_each_external_variable_declaration at ???
0x7f1c6cc26235 gnatcoll__projects__compute_scenario_variables at ???
0x7f1c6cc271aa gnatcoll__projects__scenario_variables__3.part.0 at ???
0x7f1c6cc27319 gnatcoll__projects__scenario_variables at ???
[/path/to/opt/gnatstudio/bin/gnatstudio_exe]
0x3cdd374

…and after that, a bunch more hexadecimal numbers and suchnot.

Screenshot_20221228_214507

6 posts - 3 participants

Read full topic

Gnat arm elf 12.2.1 (alire) undefined reference to strlen

By: kevlar700
29 December 2022 at 19:33

Merry xmas all.

I simplified my Last Chance Handler by using

Interfaces.C.Strings.Value

The compiler output undefined reference to ‘strlen’

light-cortex-m4f/adalib/libgnat.a(i-cstrin.o)

I could go back to my manual string null termination finding function. Or should I look into Gnat. Could someone point me to the right place to report and or submit a patch (is it gerrit that GCC uses or something)?

7 posts - 3 participants

Read full topic

New process for submitting comments about Ada Reference Manual and Ada evolution process

By: sttaft
5 January 2023 at 14:36

The Ada Rapporteur Group (ARG) of Working Group 9 (ISO WG9), within ISO/IEC JTC1 SC22, is responsible for maintaining and advancing the International Ada Programming Language Standard. In the past we have used an “ada-comment” mailing list as the official place to file comments or suggestions about the Standard. Over the past six months we have been moving to an online approach using a website and a GitHub issue repository. The new process seems to be working, so we ask all those with comments about the Ada Standard or the Ada Reference Manual to visit the new ARG website:

arg.adaic.org

and select the “Community Input” page. There you will find forms for filing comments, or for requesting the formation of a “language study group” to focus on particular thorny topics associated with the language (an example might be “distributed computing” or “tree pattern matching”).

Rather than filling out a form, you can head over to the ARG GitHub repository:

github.com/Ada-Rapporteur-Group/User-Community-Input

and select the GitHub “issue” tab to post your comments, or join a discussion on issues already there.

We would also welcome “meta” comments if you have thoughts on how to improve the ARG process itself.

Thanks!
-Tucker Taft on behalf of the Ada Rapporteur Group

2 posts - 2 participants

Read full topic

Our Contribution to the Ada Logo Discussion (blog.adacore.com)

By: Fabien.C
10 January 2023 at 16:07

AdaCore is releasing the Ada Horizon logo in the public domain:

ada-png-black-transparent_square

There’s also a small website to make your own version: ada-logo-editor | Static website that provides easy customization of the Ada horizon logo

20 posts - 9 participants

Read full topic

❌
❌