General
File extension:
- Source file:
.adb - Specification file:
.ads(like mli file in ocaml)
- Source file:
Attributes of a name are accessed using
'(called a 'tick')- Eg:
Integer'size
- Eg:
Ada is case insensitive.
- Even for variable names.
- Explains why keywords (but not variable names) in vhdl are case insensitive..
Comments: starts with
--- No way to make multi-line comments.
- This is intentional to avoid problems with nested comments.
Functions are called 'subprograms'
Apparently, we can't control variance of subtypes in ada.
Strong typing
- Got to give a type to everything
- No type inference ??
- Quite verbose as a result ??
- No implicit type conversion
- Type casts are there though.
- See where VHDL gets it from? 😃
SPARK
- A subset of ada
- Testing and verification is easier in this??
ARM: Ada reference manual
- An ISO standard, that is free. Unlike that of C++.
GNAT: ada compiler that is part of gcc
gnatmake: basic build manager
gprbuild: gnat project manager
Alire: a package manager for ada
Community: https://groups.google.com/g/comp.lang.ada/ (looks unmoderated though..)
Emacs mode: https://www.gnu.org/software/emacs/manual/html_mono/ada-mode.html
limited: makes assignment to declared variable impossible- Kind of like
constin cpp.
- Kind of like
Hello world
with Ada.Text_IO;
use Ada.Text_IO;
procedure Hello is begin
Put_Line ("Hello world!");
end Hello;https://gcc.gnu.org/onlinedocs/gnat_ugn/Running-a-Simple-Ada-Program.html
with: make a package available to current fileuse: opens the namespace ??
- For generating executable, use a builder:
gnatmakeorgprbuild
'Image and ~'Value
Convert a value to string and vice-versa.
declare
X : Integer := 10;
begin
-- "10"
Put_Line (Integer'Image (X));
-- 20
X := Integer'Value ("20");
end;Built-in types
- Character: char
- Integer: int
- Float: float
- Boolean: bool
New types
-- A new type. Like {x: Integer | x ∈ [0,23]}
type Hours24 is new Integer range 0 .. 23;
-- A subtype
subtype Hours is Hours24 range 0 .. 11;Arrays
-- a char array of size 10
Name : array (0 .. 9) of Character;Enums
type Day is
(Mon,
Tue,
Wed,
Thu,
Fri,
Sat,
Sun);Representation clause ?? can be used if needed:
for Day use
(Mon => 10,
Tue => 11,
Wed => 12,
Thu => 13,
Fri => 14,
Sat => 15,
Sun => 16);https://learn.adacore.com/courses/Ada_For_The_CPP_Java_Developer/chapters/05_Type_System.html
Some Info
- Used to be used in defense application in US and Europe earlier
- Used to mandatory for defense contractors
- Named after Ada Lovelace.
- Introduced many PL-related concepts
- Influenced design of many languages which are now popular
- Though ada itself never found popularity outside of a very niche world
- ghdl has a lot of ada code
- One of the few projects that still has significant ada
Todo
- variant type, union type
- record type
- vectors ??
- loops
- generics library
- stream
- task
- null. Looks like it is a no-op/undefined
- pointers ??
parallelblocks- concurrency
- garbage collection is optional ??
- Ada type safety can be broken??
- SPARK: https://www.electronicdesign.com/markets/automation/article/21804924/rust-and-spark-software-reliability-for-everyone