Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,11 @@ jobs:
with:
toolchain: gnat_native^${{ matrix.gnat_version }} gprbuild

- name: Show GNAT version
run: cd ${{inputs.crate}} && alr exec -- gnat --version

- name: Build
run: cd ${{inputs.crate}} && alr -q build
run: cd ${{inputs.crate}} && alr build

- name: Run tests
run: cd ${{inputs.crate}}/test && alr -q run
run: cd ${{inputs.crate}}/test && alr run
39 changes: 39 additions & 0 deletions .github/workflows/build_old.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Build (old GNATs)

on:
pull_request:
workflow_dispatch:

jobs:
crate:
strategy:
fail-fast: false
matrix:
os:
- windows-latest
- ubuntu-22.04 # Later Ubuntu no longer work with GNAT<=11
gnat_version: [10, 11]
# Pre -12 don't support Ada 2022, so we only test Yeison_12

runs-on: ${{ matrix.os }}

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Set up Alire and toolchain
uses: alire-project/setup-alire@v4
with:
toolchain: gnat_native^${{ matrix.gnat_version }} gprbuild

- name: Show GNAT version
run: cd yeison_12 && alr exec -- gnat --version

# - name: Setup tmate session
# uses: mxschmitt/action-tmate@v3

- name: Build
run: cd yeison_12 && alr build

- name: Run tests
run: cd yeison_12/test && alr run
4 changes: 4 additions & 0 deletions dev/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/obj/
/bin/
/alire/
/config/
23 changes: 23 additions & 0 deletions dev/alire.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name = "dev"
description = ""
version = "0.1.0-dev"

authors = ["Alejandro R. Mosteo"]
maintainers = ["Alejandro R. Mosteo <alejandro@mosteo.com>"]
maintainers-logins = ["mosteo"]
licenses = "MIT OR Apache-2.0 WITH LLVM-exception"
website = ""
tags = []

executables = ["dev"]

[build-profiles]
"*" = "validation"

[[depends-on]]
test_12 = "~0.1.0-dev"
test = "~0.1.0-dev"

[[pins]]
test_12 = { path='../yeison_12/test' }
test = { path='../yeison_22/test' }
22 changes: 22 additions & 0 deletions dev/dev.gpr
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
with "config/dev_config.gpr";
project Dev is

for Source_Dirs use ("src/", "config/");
for Object_Dir use "obj/" & Dev_Config.Build_Profile;
for Create_Missing_Dirs use "True";
for Exec_Dir use "bin";
for Main use ("dev.adb");

package Compiler is
for Default_Switches ("Ada") use Dev_Config.Ada_Compiler_Switches;
end Compiler;

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

package Install is
for Artifacts (".") use ("share");
end Install;

end Dev;
4 changes: 4 additions & 0 deletions dev/src/dev.adb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
procedure Dev is
begin
null;
end Dev;
2 changes: 1 addition & 1 deletion yeison_12/alire.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "yeison_12"
description = "A JSON-like data structure (Ada 2012 version)"
version = "0.2.0-dev"
version = "0.2.0"
licenses = "MIT"

authors = ["Alejandro R. Mosteo"]
Expand Down
2 changes: 1 addition & 1 deletion yeison_12/config/yeison_12_config.ads
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pragma Style_Checks (Off);
package Yeison_12_Config is
pragma Pure;

Crate_Version : constant String := "0.2.0-dev";
Crate_Version : constant String := "0.2.0";
Crate_Name : constant String := "yeison_12";

Alire_Host_OS : constant String := "linux";
Expand Down
2 changes: 1 addition & 1 deletion yeison_12/config/yeison_12_config.gpr
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-- Configuration for yeison_12 generated by Alire
abstract project Yeison_12_Config is
Crate_Version := "0.2.0-dev";
Crate_Version := "0.2.0";
Crate_Name := "yeison_12";

Alire_Host_OS := "linux";
Expand Down
2 changes: 1 addition & 1 deletion yeison_12/config/yeison_12_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#ifndef YEISON_12_CONFIG_H
#define YEISON_12_CONFIG_H

#define CRATE_VERSION "0.2.0-dev"
#define CRATE_VERSION "0.2.0"
#define CRATE_NAME "yeison_12"

#define ALIRE_HOST_OS "linux"
Expand Down
33 changes: 30 additions & 3 deletions yeison_12/src/yeison_12.ads
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
pragma Ada_2012;

with Yeison_Generic;
with Yeison_Generic.Operators;
with Yeison_Utils;

package Yeison_12 with Preelaborate is

Expand All @@ -10,19 +11,32 @@ package Yeison_12 with Preelaborate is

subtype Big_Real is Long_Long_Float;

function Nicer_Image (R : Big_Real) return Wide_Wide_String;
-- Avoid scientific notation when easy to do so

package Reals is new Yeison_Utils.General_Reals (Big_Real,
"<",
Nicer_Image);

package Impl is
new Yeison_Generic (Big_Int, Identity, Big_Int'Wide_Wide_Image,
Big_Real, Big_Real'Wide_Wide_Image);
Reals.General_Real, Reals.Image,
"<", Reals."<");

type Any is new Impl.Any with null record with
-- Constant_Indexing => Const_Ref,
Variable_Indexing => Reference;
-- Enabling constant indexing limits how we can use indexing in transient
-- expressions. Not sure this is entirely a good idea...

subtype Scalar is Impl.Scalar;

package Scalars renames Impl.Scalars;

subtype Bool is Any with Dynamic_Predicate => Bool.Kind = Bool_Kind;
subtype Int is Any with Dynamic_Predicate => Int.Kind = Int_Kind;
subtype Map is Any with Dynamic_Predicate => Map.Kind = Map_Kind;
-- subtype Map is Any with Dynamic_Predicate => Map.Kind = Map_Kind;
-- Triggers bug in GNAT 10
subtype Real is Any with Dynamic_Predicate => Real.Kind = Real_Kind;
subtype Str is Any with Dynamic_Predicate => Str.Kind = Str_Kind;
subtype Vec is Any with Dynamic_Predicate => Vec.Kind = Vec_Kind;
Expand All @@ -39,6 +53,9 @@ package Yeison_12 with Preelaborate is

subtype Text is Impl.Text;

function True return Any;
function False return Any;

----------------
-- Indexing --
----------------
Expand Down Expand Up @@ -93,4 +110,14 @@ private

Unimplemented : exception;

function True return Any renames Make.True;
function False return Any renames Make.False;

-----------------
-- Nicer_Image --
-----------------

function Nicer_Image (R : Big_Real) return Wide_Wide_String
is (Yeison_Utils.Nicer_Real_Image (R'Wide_Wide_Image));

end Yeison_12;
114 changes: 114 additions & 0 deletions yeison_12/src/yeison_generic-operators.adb
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
package body Yeison_Generic.Operators is

-- This whole package is an attempt at working around a bug in GNAT 10/11
-- related to case records in nested generic packages. Or something.

---------
-- "/" --
---------

function "/" (L, R : Client_Any) return Client_Any is
begin
if L.Kind in Scalar_Kinds then
return Result : Client_Any := Empty_Vec do
Result.Append (L);
Result.Append (R);
end return;
elsif L.Kind in Vec_Kind then
return Result : Client_Any := L do
Result.Append (R);
end return;
else
raise Constraint_Error with
"Cannot append using ""/"" when left operator is: "
& L.Kind'Image;
end if;
end "/";

----------
-- Make --
----------

package body Make is

---------
-- Nil --
---------

function Nil return Client_Any
is (To_Any (Base.New_Nil));

------------
-- Scalar --
------------

function Scalar (This : Yeison_Generic.Scalar) return Client_Any
is
Pre : constant Any'Class :=
(case This.Data.Kind is
when Bool_Kind => Base.New_Bool (This.Data.Bool),
when Int_Kind => Base.New_Int (This.Data.Int),
when Real_Kind => Base.New_Real (This.Data.Real),
when Str_Kind => Base.New_Text (S (This.Data.Str)));
begin
return To_Any (Any (Pre));
end Scalar;

-----------
-- False --
-----------

function False return Client_Any
is (Make.Scalar (Scalars.New_Bool (False)));

----------
-- True --
----------

function True return Client_Any
is (Make.Scalar (Scalars.New_Bool (True)));

----------
-- Bool --
----------

function Bool (This : Boolean) return Client_Any
is (Make.Scalar (Scalars.New_Bool (This)));

---------
-- Int --
---------

function Int (This : Int_Type) return Client_Any
is (Make.Scalar (Scalars.New_Int (This)));

----------
-- Real --
----------

function Real (This : Real_Type) return Client_Any
is (Make.Scalar (Scalars.New_Real (This)));

---------
-- Str --
---------

function Str (This : Wide_Wide_String) return Client_Any
is (Make.Scalar (Scalars.New_Text (This)));

end Make;

---------
-- Vec --
---------

function Vec (This : Any_Array) return Client_Any is
begin
return Result : Client_Any := Empty_Vec do
for Elem of This loop
Result.Append (Elem);
end loop;
end return;
end Vec;

end Yeison_Generic.Operators;
45 changes: 45 additions & 0 deletions yeison_12/src/yeison_generic-operators.ads
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---------------
-- Operators --
---------------

generic
type Client_Any is new Yeison_Generic.Any with private;
with function To_Any (This : Yeison_Generic.Any) return Client_Any is <>;
package Yeison_Generic.Operators with Preelaborate is

---------
-- "/" --
---------

function "/" (L, R : Client_Any) return Client_Any with
Pre => L.Kind in Scalar_Kinds | Vec_Kind,
Post => "/"'Result.Kind = Vec_Kind;

-- Temporary workaround until both Add_Named and Add_Unnamed can be used
-- simultaneously on the same type. It's convenient having it here so
-- "+" becomes visible with the rest.

type Any_Array is array (Positive range <>) of Client_Any;

function Vec (This : Any_Array) return Client_Any with
Post => Vec'Result.Kind = Vec_Kind;

----------
-- Make --
----------

package Make is
function Nil return Client_Any;

function True return Client_Any;
function False return Client_Any;

function Bool (This : Boolean) return Client_Any;
function Int (This : Int_Type) return Client_Any;
function Real (This : Real_Type) return Client_Any;
function Str (This : Text) return Client_Any;

function Scalar (This : Yeison_Generic.Scalar) return Client_Any;
end Make;

end Yeison_Generic.Operators;
Loading