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
const
in cpp.
- Kind of like
Hello world
with Ada.Text_IO;
use Ada.Text_IO;
procedure Hello is begin
"Hello world!");
Put_Line (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:
gnatmake
orgprbuild
'Image and ~'Value
Convert a value to string and vice-versa.
declare
Integer := 10;
X : begin
-- "10"
Put_Line (Integer'Image (X));
-- 20
"20");
X := Integer'Value (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
array (0 .. 9) of Character; Name :
Enums
type Day is
(Mon,
Tue,
Wed,
Thu,
Fri,
Sat, Sun);
Representation clause ?? can be used if needed:
for Day use
10,
(Mon => 11,
Tue => 12,
Wed => 13,
Thu => 14,
Fri => 15,
Sat => 16); Sun =>
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 ??
parallel
blocks- 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