content
stringlengths 23
1.05M
|
|---|
private
with
eGL;
package openGL.Display
--
-- Models an openGL display.
--
is
type Item is tagged private;
function Default return Item;
private
type Item is tagged
record
Thin : eGL.EGLDisplay;
Version_major,
Version_minor : aliased eGL.EGLint;
end record;
end openGL.Display;
|
with Ada.Text_IO; use Ada.Text_IO;
procedure Hello is
begin
Put_Line ("Hello, World!");
end Hello;
|
-------------------------------------------------------------------------------
-- LSE -- L-System Editor
-- Author: Heziode
--
-- License:
-- MIT License
--
-- Copyright (c) 2018 Quentin Dauprat (Heziode) <Heziode@protonmail.com>
--
-- Permission is hereby granted, free of charge, to any person obtaining a
-- copy of this software and associated documentation files (the "Software"),
-- to deal in the Software without restriction, including without limitation
-- the rights to use, copy, modify, merge, publish, distribute, sublicense,
-- and/or sell copies of the Software, and to permit persons to whom the
-- Software is furnished to do so, subject to the following conditions:
--
-- The above copyright notice and this permission notice shall be included in
-- all copies or substantial portions of the Software.
--
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-- FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
-- DEALINGS IN THE SOFTWARE.
-------------------------------------------------------------------------------
with Ada.Characters.Handling;
with Ada.Characters.Latin_1;
with Ada.Integer_Text_IO;
with Ada.Strings;
with Ada.Strings.Fixed;
package body LSE.Utils.Colors is
package L renames Ada.Characters.Latin_1;
function Str_Hex_To_Int (Input : String) return Natural
is
use Ada.Characters.Handling;
Str_Length : Natural := Input'Length;
Result : Natural := 0;
begin
for C of Input loop
case To_Upper (C) is
when 'F' => Result := Result + 15**Str_Length;
when 'E' => Result := Result + 14**Str_Length;
when 'D' => Result := Result + 13**Str_Length;
when 'C' => Result := Result + 12**Str_Length;
when 'B' => Result := Result + 11**Str_Length;
when 'A' => Result := Result + 10**Str_Length;
when '0' .. '9' => Result := Result + Natural'Value (C & "");
when others => raise UNEXPECTED_CHARACTER;
end case;
Str_Length := Str_Length - 1;
end loop;
return Result;
end Str_Hex_To_Int;
function Str_Hex_To_Float (Input : String) return Float
is
begin
return Float (Str_Hex_To_Int (Input)) / 255.0;
end Str_Hex_To_Float;
procedure To_RGB (Input : String; R, G, B : out Natural)
is
use Ada.Text_IO;
Index : Positive := Input'First;
begin
if Input'Length not in 6 .. 7 then
raise STRING_LENGTH;
end if;
if Input (Index) = '#' then
Index := Index + 1;
end if;
R := Str_Hex_To_Int (Input (Index .. Index + 1));
Index := Index + 2;
G := Str_Hex_To_Int (Input (Index .. Index + 1));
Index := Index + 2;
B := Str_Hex_To_Int (Input (Index .. Index + 1));
exception
when STRING_LENGTH =>
Put_Line ("Error: bad length of string for RGB conversion");
when UNEXPECTED_CHARACTER =>
Put_Line ("Error: Unexpected character encountered");
when others =>
Put_Line ("Error: cannot convert string to RGB");
end To_RGB;
procedure To_RGB (Input : String; R, G, B : out Float)
is
use Ada.Text_IO;
Index : Positive := Input'First;
begin
if Input'Length not in 6 .. 7 then
raise STRING_LENGTH;
end if;
if Input (Index) = '#' then
Index := Index + 1;
end if;
R := Str_Hex_To_Float (Input (Index .. Index + 1));
Index := Index + 2;
G := Str_Hex_To_Float (Input (Index .. Index + 1));
Index := Index + 2;
B := Str_Hex_To_Float (Input (Index .. Index + 1));
exception
when STRING_LENGTH =>
Put_Line ("Error: bad length of string for RGB conversion");
when UNEXPECTED_CHARACTER =>
Put_Line ("Error: Unexpected character encountered");
when others =>
Put_Line ("Error: cannot convert string to RGB");
end To_RGB;
-- Convert RGB value to string
function RGB_To_String (R, G, B : Natural) return String
is
use Ada.Strings;
use Ada.Strings.Fixed;
begin
return Trim (Natural'Image (R), Left) & L.Space &
Natural'Image (G) & L.Space & Natural'Image (B);
end RGB_To_String;
-- Convert RGB value to string
function RGB_To_String (R, G, B : Float) return String
is
use Ada.Strings;
use Ada.Strings.Fixed;
begin
return Trim (Fixed_Point'Image (Fixed_Point (R)), Left) &
L.Space & Fixed_Point'Image (Fixed_Point (G)) &
L.Space & Fixed_Point'Image (Fixed_Point (B));
end RGB_To_String;
function RGB_To_Hex_String (R, G, B : Natural) return String
is
use Ada.Strings;
use Ada.Strings.Fixed;
Rs : String (1 .. 6);
Gs : String (1 .. 6);
Bs : String (1 .. 6);
begin
Ada.Integer_Text_IO.Put (Rs, R, 16);
Ada.Integer_Text_IO.Put (Gs, G, 16);
Ada.Integer_Text_IO.Put (Bs, B, 16);
return "#" & (if Rs (4 .. 4) = "#" then "0" else Rs (4 .. 4)) &
(if Rs (4 .. 4) = "#" then Rs (5 .. 5) else Rs (4 .. 4)) &
(if Gs (4 .. 4) = "#" then "0" else Gs (4 .. 4)) &
(if Gs (4 .. 4) = "#" then Gs (5 .. 5) else Gs (4 .. 4)) &
(if Bs (4 .. 4) = "#" then "0" else Bs (4 .. 4)) &
(if Bs (4 .. 4) = "#" then Bs (5 .. 5) else Bs (4 .. 4));
end RGB_To_Hex_String;
function RGB_To_Hex_String (R, G, B : Float) return String
is
begin
return RGB_To_Hex_String (Natural (R * 255.0),
Natural (G * 255.0),
Natural (B * 255.0));
end RGB_To_Hex_String;
end LSE.Utils.Colors;
|
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
procedure Check_Positive2 is
N : Integer;
begin
Put ("Enter an integer value: "); -- Put a String
Get (N); -- Reads in an integer value
Put (N); -- Put an Integer
declare
S : String :=
(if N > 0 then " is a positive number"
else " is not a positive number");
begin
Put_Line (S);
end;
end Check_Positive2;
|
with HAL; use HAL;
with HAL.Time;
package PyGamer.Time is
subtype Time_Ms is UInt64;
function Clock return Time_Ms;
procedure Delay_Ms (Milliseconds : UInt64);
procedure Delay_Until (Wakeup_Time : Time_Ms);
procedure Sleep (Milliseconds : UInt64) renames Delay_Ms;
function Tick_Period return Time_Ms;
type Tick_Callback is access procedure;
function Tick_Subscriber (Callback : not null Tick_Callback) return Boolean;
-- Return True if callback is already a tick event subscriber
function Tick_Subscribe (Callback : not null Tick_Callback) return Boolean
with Pre => not Tick_Subscriber (Callback),
Post => (if Tick_Subscribe'Result then Tick_Subscriber (Callback));
-- Subscribe a callback to the tick event. The function return True on
-- success, False if there's no more room for subscribers.
function Tick_Unsubscribe (Callback : not null Tick_Callback) return Boolean
with Pre => Tick_Subscriber (Callback),
Post => (if Tick_Unsubscribe'Result then not Tick_Subscriber (Callback));
-- Unsubscribe a callback to the tick event. The function return True on
-- success, False if the callback was not a subscriber.
function HAL_Delay return not null HAL.Time.Any_Delays;
private
type PG_Delays is new HAL.Time.Delays with null record;
overriding
procedure Delay_Microseconds (This : in out PG_Delays;
Us : Integer);
overriding
procedure Delay_Milliseconds (This : in out PG_Delays;
Ms : Integer);
overriding
procedure Delay_Seconds (This : in out PG_Delays;
S : Integer);
end PyGamer.Time;
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- P R J . E X T --
-- --
-- S p e c --
-- --
-- $Revision$
-- --
-- Copyright (C) 2000 Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 2, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
-- for more details. You should have received a copy of the GNU General --
-- Public License distributed with GNAT; see file COPYING. If not, write --
-- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
-- MA 02111-1307, USA. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
-- Set, Get and cache External reference, to be used as External functions
-- in project files.
with Types; use Types;
package Prj.Ext is
procedure Add
(External_Name : String;
Value : String);
-- Add an external reference (or modify an existing one).
function Value_Of
(External_Name : Name_Id;
With_Default : String_Id := No_String)
return String_Id;
-- Get the value of an external reference, and cache it for future uses.
function Check (Declaration : String) return Boolean;
-- Check that an external declaration <external>=<value> is correct.
-- If it is correct, the external reference is Added.
end Prj.Ext;
|
------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Ada Modeling Framework --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2011-2012, Vadim Godunko <vgodunko@gmail.com> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with AMF.Internals.UML_Packageable_Elements;
with AMF.UML.Classifiers;
with AMF.UML.Dependencies.Collections;
with AMF.UML.Generalization_Sets;
with AMF.UML.Generalizations.Collections;
with AMF.UML.Named_Elements;
with AMF.UML.Namespaces;
with AMF.UML.Packages.Collections;
with AMF.UML.Parameterable_Elements;
with AMF.UML.String_Expressions;
with AMF.UML.Template_Parameters;
with AMF.Visitors;
package AMF.Internals.UML_Generalization_Sets is
type UML_Generalization_Set_Proxy is
limited new AMF.Internals.UML_Packageable_Elements.UML_Packageable_Element_Proxy
and AMF.UML.Generalization_Sets.UML_Generalization_Set with null record;
overriding function Get_Generalization
(Self : not null access constant UML_Generalization_Set_Proxy)
return AMF.UML.Generalizations.Collections.Set_Of_UML_Generalization;
-- Getter of GeneralizationSet::generalization.
--
-- Designates the instances of Generalization which are members of a given
-- GeneralizationSet.
overriding function Get_Is_Covering
(Self : not null access constant UML_Generalization_Set_Proxy)
return Boolean;
-- Getter of GeneralizationSet::isCovering.
--
-- Indicates (via the associated Generalizations) whether or not the set
-- of specific Classifiers are covering for a particular general
-- classifier. When isCovering is true, every instance of a particular
-- general Classifier is also an instance of at least one of its specific
-- Classifiers for the GeneralizationSet. When isCovering is false, there
-- are one or more instances of the particular general Classifier that are
-- not instances of at least one of its specific Classifiers defined for
-- the GeneralizationSet.
overriding procedure Set_Is_Covering
(Self : not null access UML_Generalization_Set_Proxy;
To : Boolean);
-- Setter of GeneralizationSet::isCovering.
--
-- Indicates (via the associated Generalizations) whether or not the set
-- of specific Classifiers are covering for a particular general
-- classifier. When isCovering is true, every instance of a particular
-- general Classifier is also an instance of at least one of its specific
-- Classifiers for the GeneralizationSet. When isCovering is false, there
-- are one or more instances of the particular general Classifier that are
-- not instances of at least one of its specific Classifiers defined for
-- the GeneralizationSet.
overriding function Get_Is_Disjoint
(Self : not null access constant UML_Generalization_Set_Proxy)
return Boolean;
-- Getter of GeneralizationSet::isDisjoint.
--
-- Indicates whether or not the set of specific Classifiers in a
-- Generalization relationship have instance in common. If isDisjoint is
-- true, the specific Classifiers for a particular GeneralizationSet have
-- no members in common; that is, their intersection is empty. If
-- isDisjoint is false, the specific Classifiers in a particular
-- GeneralizationSet have one or more members in common; that is, their
-- intersection is not empty. For example, Person could have two
-- Generalization relationships, each with the different specific
-- Classifier: Manager or Staff. This would be disjoint because every
-- instance of Person must either be a Manager or Staff. In contrast,
-- Person could have two Generalization relationships involving two
-- specific (and non-covering) Classifiers: Sales Person and Manager. This
-- GeneralizationSet would not be disjoint because there are instances of
-- Person which can be a Sales Person and a Manager.
overriding procedure Set_Is_Disjoint
(Self : not null access UML_Generalization_Set_Proxy;
To : Boolean);
-- Setter of GeneralizationSet::isDisjoint.
--
-- Indicates whether or not the set of specific Classifiers in a
-- Generalization relationship have instance in common. If isDisjoint is
-- true, the specific Classifiers for a particular GeneralizationSet have
-- no members in common; that is, their intersection is empty. If
-- isDisjoint is false, the specific Classifiers in a particular
-- GeneralizationSet have one or more members in common; that is, their
-- intersection is not empty. For example, Person could have two
-- Generalization relationships, each with the different specific
-- Classifier: Manager or Staff. This would be disjoint because every
-- instance of Person must either be a Manager or Staff. In contrast,
-- Person could have two Generalization relationships involving two
-- specific (and non-covering) Classifiers: Sales Person and Manager. This
-- GeneralizationSet would not be disjoint because there are instances of
-- Person which can be a Sales Person and a Manager.
overriding function Get_Powertype
(Self : not null access constant UML_Generalization_Set_Proxy)
return AMF.UML.Classifiers.UML_Classifier_Access;
-- Getter of GeneralizationSet::powertype.
--
-- Designates the Classifier that is defined as the power type for the
-- associated GeneralizationSet.
overriding procedure Set_Powertype
(Self : not null access UML_Generalization_Set_Proxy;
To : AMF.UML.Classifiers.UML_Classifier_Access);
-- Setter of GeneralizationSet::powertype.
--
-- Designates the Classifier that is defined as the power type for the
-- associated GeneralizationSet.
overriding function Get_Client_Dependency
(Self : not null access constant UML_Generalization_Set_Proxy)
return AMF.UML.Dependencies.Collections.Set_Of_UML_Dependency;
-- Getter of NamedElement::clientDependency.
--
-- Indicates the dependencies that reference the client.
overriding function Get_Name_Expression
(Self : not null access constant UML_Generalization_Set_Proxy)
return AMF.UML.String_Expressions.UML_String_Expression_Access;
-- Getter of NamedElement::nameExpression.
--
-- The string expression used to define the name of this named element.
overriding procedure Set_Name_Expression
(Self : not null access UML_Generalization_Set_Proxy;
To : AMF.UML.String_Expressions.UML_String_Expression_Access);
-- Setter of NamedElement::nameExpression.
--
-- The string expression used to define the name of this named element.
overriding function Get_Namespace
(Self : not null access constant UML_Generalization_Set_Proxy)
return AMF.UML.Namespaces.UML_Namespace_Access;
-- Getter of NamedElement::namespace.
--
-- Specifies the namespace that owns the NamedElement.
overriding function Get_Qualified_Name
(Self : not null access constant UML_Generalization_Set_Proxy)
return AMF.Optional_String;
-- Getter of NamedElement::qualifiedName.
--
-- A name which allows the NamedElement to be identified within a
-- hierarchy of nested Namespaces. It is constructed from the names of the
-- containing namespaces starting at the root of the hierarchy and ending
-- with the name of the NamedElement itself.
overriding function Get_Owning_Template_Parameter
(Self : not null access constant UML_Generalization_Set_Proxy)
return AMF.UML.Template_Parameters.UML_Template_Parameter_Access;
-- Getter of ParameterableElement::owningTemplateParameter.
--
-- The formal template parameter that owns this element.
overriding procedure Set_Owning_Template_Parameter
(Self : not null access UML_Generalization_Set_Proxy;
To : AMF.UML.Template_Parameters.UML_Template_Parameter_Access);
-- Setter of ParameterableElement::owningTemplateParameter.
--
-- The formal template parameter that owns this element.
overriding function Get_Template_Parameter
(Self : not null access constant UML_Generalization_Set_Proxy)
return AMF.UML.Template_Parameters.UML_Template_Parameter_Access;
-- Getter of ParameterableElement::templateParameter.
--
-- The template parameter that exposes this element as a formal parameter.
overriding procedure Set_Template_Parameter
(Self : not null access UML_Generalization_Set_Proxy;
To : AMF.UML.Template_Parameters.UML_Template_Parameter_Access);
-- Setter of ParameterableElement::templateParameter.
--
-- The template parameter that exposes this element as a formal parameter.
overriding function All_Owning_Packages
(Self : not null access constant UML_Generalization_Set_Proxy)
return AMF.UML.Packages.Collections.Set_Of_UML_Package;
-- Operation NamedElement::allOwningPackages.
--
-- The query allOwningPackages() returns all the directly or indirectly
-- owning packages.
overriding function Is_Distinguishable_From
(Self : not null access constant UML_Generalization_Set_Proxy;
N : AMF.UML.Named_Elements.UML_Named_Element_Access;
Ns : AMF.UML.Namespaces.UML_Namespace_Access)
return Boolean;
-- Operation NamedElement::isDistinguishableFrom.
--
-- The query isDistinguishableFrom() determines whether two NamedElements
-- may logically co-exist within a Namespace. By default, two named
-- elements are distinguishable if (a) they have unrelated types or (b)
-- they have related types but different names.
overriding function Namespace
(Self : not null access constant UML_Generalization_Set_Proxy)
return AMF.UML.Namespaces.UML_Namespace_Access;
-- Operation NamedElement::namespace.
--
-- Missing derivation for NamedElement::/namespace : Namespace
overriding function Is_Compatible_With
(Self : not null access constant UML_Generalization_Set_Proxy;
P : AMF.UML.Parameterable_Elements.UML_Parameterable_Element_Access)
return Boolean;
-- Operation ParameterableElement::isCompatibleWith.
--
-- The query isCompatibleWith() determines if this parameterable element
-- is compatible with the specified parameterable element. By default
-- parameterable element P is compatible with parameterable element Q if
-- the kind of P is the same or a subtype as the kind of Q. Subclasses
-- should override this operation to specify different compatibility
-- constraints.
overriding function Is_Template_Parameter
(Self : not null access constant UML_Generalization_Set_Proxy)
return Boolean;
-- Operation ParameterableElement::isTemplateParameter.
--
-- The query isTemplateParameter() determines if this parameterable
-- element is exposed as a formal template parameter.
overriding procedure Enter_Element
(Self : not null access constant UML_Generalization_Set_Proxy;
Visitor : in out AMF.Visitors.Abstract_Visitor'Class;
Control : in out AMF.Visitors.Traverse_Control);
-- Dispatch call to corresponding subprogram of visitor interface.
overriding procedure Leave_Element
(Self : not null access constant UML_Generalization_Set_Proxy;
Visitor : in out AMF.Visitors.Abstract_Visitor'Class;
Control : in out AMF.Visitors.Traverse_Control);
-- Dispatch call to corresponding subprogram of visitor interface.
overriding procedure Visit_Element
(Self : not null access constant UML_Generalization_Set_Proxy;
Iterator : in out AMF.Visitors.Abstract_Iterator'Class;
Visitor : in out AMF.Visitors.Abstract_Visitor'Class;
Control : in out AMF.Visitors.Traverse_Control);
-- Dispatch call to corresponding subprogram of iterator interface.
end AMF.Internals.UML_Generalization_Sets;
|
with Ada.Integer_Text_IO;
with Ada.Text_IO;
package body Problem_17 is
package IO renames Ada.Text_IO;
package I_IO renames Ada.Integer_Text_IO;
procedure Solve is
type Length_Array is Array(Positive range <>) of Positive;
first_twenty_length : constant Length_Array := (3, 3, 5, 4, 4, 3, 5, 5, 4, 3, 6, 6, 8, 8, 7, 7, 9, 8, 8);
tens_length : constant Length_Array := (6, 6, 5, 5, 5, 7, 6, 6);
and_length : constant Positive := 3;
hundred_length : constant Positive := 7; -- Length("hundred")
thousand_length : constant Positive := 8; -- Length("thousand")
count : Natural := 0;
function Get_Length(number : in Natural) return Natural is
hundreds : constant natural := number / 100;
tens : constant natural := (number mod 100) / 10;
ones : natural := (number mod 10);
length : Natural := 0;
begin
if hundreds > 0 then
length := first_twenty_length(hundreds) + hundred_length;
if tens > 0 or ones > 0 then
length := length + and_length;
end if;
end if;
if tens >= 2 then
length := length + tens_length(tens - 1);
elsif tens = 1 then
ones := ones + 10;
end if;
if ones > 0 then
length := length + first_twenty_length(ones);
end if;
return length;
end;
begin
for number in 1 .. 1000 loop
declare
thousands : constant natural := number / 1000;
begin
if thousands > 0 then
count := count + thousand_length + Get_Length(number / 1000);
end if;
count := count + Get_Length(number mod 1000);
null;
end;
end loop;
I_IO.Put(count);
IO.New_Line;
end Solve;
end Problem_17;
|
-- This file is covered by the Internet Software Consortium (ISC) License
-- Reference: ../License.txt
-- To enable ncurses support, use sed to change Options_Dialog_Console => Options_Dialog
-- Also change Display.Console => Display.Curses
with Unix;
with Signals;
with Replicant;
with Ada.Exceptions;
with Ada.Directories;
with Ada.Characters.Latin_1;
with PortScan.Log;
with PortScan.Buildcycle;
with Specification_Parser;
with Port_Specification.Makefile;
with Port_Specification.Transform;
with INI_File_Manager;
with Options_Dialog_Console;
with Display.Console;
package body PortScan.Operations is
package EX renames Ada.Exceptions;
package DIR renames Ada.Directories;
package LAT renames Ada.Characters.Latin_1;
package LOG renames PortScan.Log;
package CYC renames PortScan.Buildcycle;
package REP renames Replicant;
package PAR renames Specification_Parser;
package PSM renames Port_Specification.Makefile;
package PST renames Port_Specification.Transform;
package IFM renames INI_File_Manager;
package DLG renames Options_Dialog_Console;
package DPY renames Display;
package DPC renames Display.Console;
--------------------------------------------------------------------------------------------
-- parallel_bulk_run
--------------------------------------------------------------------------------------------
procedure parallel_bulk_run (num_builders : builders; sysrootver : sysroot_characteristics)
is
subtype cycle_count is Natural range 1 .. 9;
subtype refresh_count is Natural range 1 .. 4;
subtype www_count is Natural range 1 .. 3;
subtype alert_count is Natural range 1 .. 200;
procedure text_display (builder : builders; info : String);
procedure common_display (flavor : count_type; info : String);
procedure slave_display (flavor : count_type; builder : builders; info : String);
function slave_name (slave : builders) return String;
function slave_bucket (slave : builders) return String;
instructions : dim_instruction := (others => port_match_failed);
builder_states : dim_builder_state := (others => idle);
cntcycle : cycle_count := cycle_count'First;
cntrefresh : refresh_count := refresh_count'First;
cntalert : alert_count := alert_count'First;
cntwww : www_count := www_count'First;
run_complete : Boolean := False;
available : Positive := Integer (num_builders);
target : port_id;
all_idle : Boolean;
cntskip : Natural;
sumdata : DPY.summary_rec;
procedure text_display (builder : builders; info : String) is
begin
TIO.Put_Line
(LOG.elapsed_now & " => [" & HT.zeropad (Integer (builder), 2) & "] " & info);
end text_display;
procedure slave_display (flavor : count_type; builder : builders; info : String)
is
slavid : constant String := HT.zeropad (Integer (builder), 2);
begin
LOG.scribe
(flavor, LOG.elapsed_now & " [" & slavid & "] => " & info, False);
end slave_display;
procedure common_display (flavor : count_type; info : String) is
begin
LOG.scribe (flavor, LOG.elapsed_now & " " & info, False);
end common_display;
function slave_name (slave : builders) return String is
begin
return get_port_variant (instructions (slave));
end slave_name;
function slave_bucket (slave : builders) return String is
begin
return get_bucket (instructions (slave));
end slave_bucket;
task type build (builder : builders);
task body build
is
build_result : Boolean;
need_procfs : Boolean;
begin
if builder <= num_builders then
if not curses_support then
text_display (builder, "Builder launched");
end if;
loop
exit when builder_states (builder) = shutdown;
if builder_states (builder) = tasked then
builder_states (builder) := busy;
need_procfs := all_ports (instructions (builder)).use_procfs;
begin
REP.launch_slave (builder, need_procfs);
build_result := build_subpackages (builder,
instructions (builder),
sysrootver);
exception
when tremor : others =>
build_result := False;
LOG.scribe (total, LOG.elapsed_now &
" TASK" & builder'Img & " EXCEPTION: " &
EX.Exception_Information (tremor), False);
end;
REP.destroy_slave (builder, need_procfs);
if build_result then
builder_states (builder) := done_success;
else
builder_states (builder) := done_failure;
end if;
else
-- idle or done-(failure|success), just wait a bit
delay 0.1;
end if;
end loop;
if not curses_support then
text_display (builder, " Shutting down");
end if;
end if;
exception
when earthquake : others =>
LOG.scribe (total, LOG.elapsed_now & " UNHANDLED TASK" & builder'Img & " EXCEPTION: " &
EX.Exception_Information (earthquake), False);
Signals.initiate_shutdown;
end build;
builder_01 : build (builder => 1);
builder_02 : build (builder => 2);
builder_03 : build (builder => 3);
builder_04 : build (builder => 4);
builder_05 : build (builder => 5);
builder_06 : build (builder => 6);
builder_07 : build (builder => 7);
builder_08 : build (builder => 8);
builder_09 : build (builder => 9);
builder_10 : build (builder => 10);
builder_11 : build (builder => 11);
builder_12 : build (builder => 12);
builder_13 : build (builder => 13);
builder_14 : build (builder => 14);
builder_15 : build (builder => 15);
builder_16 : build (builder => 16);
builder_17 : build (builder => 17);
builder_18 : build (builder => 18);
builder_19 : build (builder => 19);
builder_20 : build (builder => 20);
builder_21 : build (builder => 21);
builder_22 : build (builder => 22);
builder_23 : build (builder => 23);
builder_24 : build (builder => 24);
builder_25 : build (builder => 25);
builder_26 : build (builder => 26);
builder_27 : build (builder => 27);
builder_28 : build (builder => 28);
builder_29 : build (builder => 29);
builder_30 : build (builder => 30);
builder_31 : build (builder => 31);
builder_32 : build (builder => 32);
builder_33 : build (builder => 33);
builder_34 : build (builder => 34);
builder_35 : build (builder => 35);
builder_36 : build (builder => 36);
builder_37 : build (builder => 37);
builder_38 : build (builder => 38);
builder_39 : build (builder => 39);
builder_40 : build (builder => 40);
builder_41 : build (builder => 41);
builder_42 : build (builder => 42);
builder_43 : build (builder => 43);
builder_44 : build (builder => 44);
builder_45 : build (builder => 45);
builder_46 : build (builder => 46);
builder_47 : build (builder => 47);
builder_48 : build (builder => 48);
builder_49 : build (builder => 49);
builder_50 : build (builder => 50);
builder_51 : build (builder => 51);
builder_52 : build (builder => 52);
builder_53 : build (builder => 53);
builder_54 : build (builder => 54);
builder_55 : build (builder => 55);
builder_56 : build (builder => 56);
builder_57 : build (builder => 57);
builder_58 : build (builder => 58);
builder_59 : build (builder => 59);
builder_60 : build (builder => 60);
builder_61 : build (builder => 61);
builder_62 : build (builder => 62);
builder_63 : build (builder => 63);
builder_64 : build (builder => 64);
-- Expansion of cpu_range from 32 to 64 means 128 possible builders
builder_65 : build (builder => 65);
builder_66 : build (builder => 66);
builder_67 : build (builder => 67);
builder_68 : build (builder => 68);
builder_69 : build (builder => 69);
builder_70 : build (builder => 70);
builder_71 : build (builder => 71);
builder_72 : build (builder => 72);
builder_73 : build (builder => 73);
builder_74 : build (builder => 74);
builder_75 : build (builder => 75);
builder_76 : build (builder => 76);
builder_77 : build (builder => 77);
builder_78 : build (builder => 78);
builder_79 : build (builder => 79);
builder_80 : build (builder => 80);
builder_81 : build (builder => 81);
builder_82 : build (builder => 82);
builder_83 : build (builder => 83);
builder_84 : build (builder => 84);
builder_85 : build (builder => 85);
builder_86 : build (builder => 86);
builder_87 : build (builder => 87);
builder_88 : build (builder => 88);
builder_89 : build (builder => 89);
builder_90 : build (builder => 90);
builder_91 : build (builder => 91);
builder_92 : build (builder => 92);
builder_93 : build (builder => 93);
builder_94 : build (builder => 94);
builder_95 : build (builder => 95);
builder_96 : build (builder => 96);
builder_97 : build (builder => 97);
builder_98 : build (builder => 98);
builder_99 : build (builder => 99);
builder_100 : build (builder => 100);
builder_101 : build (builder => 101);
builder_102 : build (builder => 102);
builder_103 : build (builder => 103);
builder_104 : build (builder => 104);
builder_105 : build (builder => 105);
builder_106 : build (builder => 106);
builder_107 : build (builder => 107);
builder_108 : build (builder => 108);
builder_109 : build (builder => 109);
builder_110 : build (builder => 110);
builder_111 : build (builder => 111);
builder_112 : build (builder => 112);
builder_113 : build (builder => 113);
builder_114 : build (builder => 114);
builder_115 : build (builder => 115);
builder_116 : build (builder => 116);
builder_117 : build (builder => 117);
builder_118 : build (builder => 118);
builder_119 : build (builder => 119);
builder_120 : build (builder => 120);
builder_121 : build (builder => 121);
builder_122 : build (builder => 122);
builder_123 : build (builder => 123);
builder_124 : build (builder => 124);
builder_125 : build (builder => 125);
builder_126 : build (builder => 126);
builder_127 : build (builder => 127);
builder_128 : build (builder => 128);
begin
loop
all_idle := True;
for slave in 1 .. num_builders loop
begin
case builder_states (slave) is
when busy | tasked =>
all_idle := False;
when shutdown =>
null;
when idle =>
if run_complete then
builder_states (slave) := shutdown;
else
target := top_buildable_port;
if target = port_match_failed then
if Signals.graceful_shutdown_requested or else
nothing_left (num_builders)
then
run_complete := True;
builder_states (slave) := shutdown;
if curses_support then
DPY.insert_history
(CYC.assemble_history_record (slave, 0, DPY.action_shutdown));
end if;
else
if shutdown_recommended (available) then
builder_states (slave) := shutdown;
if curses_support then
DPY.insert_history
(CYC.assemble_history_record (slave, 0, DPY.action_shutdown));
end if;
available := available - 1;
end if;
end if;
else
lock_package (target);
instructions (slave) := target;
builder_states (slave) := tasked;
slave_display (total, slave, slave_name (slave));
if not curses_support then
text_display (slave, " Kickoff " & slave_name (slave));
end if;
end if;
end if;
when done_success | done_failure =>
all_idle := False;
if builder_states (slave) = done_success then
if curses_support then
DPY.insert_history
(CYC.assemble_history_record
(slave, instructions (slave), DPY.action_success));
else
text_display
(slave, CYC.elapsed_build (slave) & " Success " & slave_name (slave));
end if;
record_history_built (elapsed => LOG.elapsed_now,
slave_id => slave,
bucket => slave_bucket (slave),
origin => slave_name (slave),
duration => CYC.elapsed_build (slave));
run_package_hook (pkg_success, instructions (slave));
cascade_successful_build (instructions (slave));
LOG.increment_build_counter (success);
common_display (success, slave_name (slave));
common_display (total, slave_name (slave) & " success");
else
common_display (total, slave_name (slave) & " FAILED!");
cascade_failed_build (instructions (slave), cntskip);
LOG.increment_build_counter (skipped, cntskip);
LOG.increment_build_counter (failure);
common_display (total, slave_name (slave) & " failure skips:" & cntskip'Img);
common_display
(failure, slave_name (slave) & " (skipped" & cntskip'Img & ")");
if curses_support then
DPY.insert_history
(CYC.assemble_history_record
(slave, instructions (slave), DPY.action_failure));
else
text_display
(slave, CYC.elapsed_build (slave) & " Failure " & slave_name (slave));
end if;
record_history_failed
(elapsed => LOG.elapsed_now,
slave_id => slave,
bucket => slave_bucket (slave),
origin => slave_name (slave),
duration => CYC.elapsed_build (slave),
die_phase => CYC.last_build_phase (slave),
skips => cntskip);
run_package_hook (pkg_failure, instructions (slave));
end if;
instructions (slave) := port_match_failed;
if run_complete then
builder_states (slave) := shutdown;
if curses_support then
DPY.insert_history
(CYC.assemble_history_record (slave, 0, DPY.action_shutdown));
end if;
else
builder_states (slave) := idle;
end if;
end case;
exception
when earthquake : others =>
LOG.scribe (total, LOG.elapsed_now & " UNHANDLED SLAVE LOOP EXCEPTION: " &
EX.Exception_Information (earthquake), False);
Signals.initiate_shutdown;
end;
end loop;
exit when run_complete and all_idle;
begin
if cntcycle = cycle_count'Last then
cntcycle := cycle_count'First;
LOG.flush_log (success);
LOG.flush_log (failure);
LOG.flush_log (skipped);
LOG.flush_log (total);
if curses_support then
if cntrefresh = refresh_count'Last then
cntrefresh := refresh_count'First;
DPC.set_full_redraw_next_update;
else
cntrefresh := cntrefresh + 1;
end if;
sumdata.Initially := LOG.port_counter_value (total);
sumdata.Built := LOG.port_counter_value (success);
sumdata.Failed := LOG.port_counter_value (failure);
sumdata.Ignored := LOG.port_counter_value (ignored);
sumdata.Skipped := LOG.port_counter_value (skipped);
sumdata.elapsed := LOG.elapsed_now;
sumdata.swap := get_swap_status;
sumdata.load := CYC.load_core (True);
sumdata.pkg_hour := LOG.hourly_build_rate;
sumdata.impulse := LOG.impulse_rate;
DPC.summarize (sumdata);
for b in builders'First .. num_builders loop
if builder_states (b) = shutdown then
DPC.update_builder (CYC.builder_status (b, True, False));
elsif builder_states (b) = idle then
DPC.update_builder (CYC.builder_status (b, False, True));
else
CYC.set_log_lines (b);
DPC.update_builder (CYC.builder_status (b));
end if;
end loop;
DPC.refresh_builder_window;
DPC.refresh_history_window;
else
-- text mode support, periodic status reports
if cntalert = alert_count'Last then
cntalert := alert_count'First;
TIO.Put_Line (LOG.elapsed_now & " => " &
" Left:" & LOG.ports_remaining_to_build'Img &
" Succ:" & LOG.port_counter_value (success)'Img &
" Fail:" & LOG.port_counter_value (failure)'Img &
" Skip:" & LOG.port_counter_value (skipped)'Img &
" Ign:" & LOG.port_counter_value (ignored)'Img);
else
cntalert := cntalert + 1;
end if;
-- Update log lines every 4 seconds for the watchdog
if cntrefresh = refresh_count'Last then
cntrefresh := refresh_count'First;
for b in builders'First .. num_builders loop
if builder_states (b) /= shutdown and then
builder_states (b) /= idle
then
CYC.set_log_lines (b);
end if;
end loop;
else
cntrefresh := cntrefresh + 1;
end if;
end if;
-- Generate latest history file every 3 seconds.
-- With a poll period of 6 seconds, we need twice that frequency to avoid aliasing
-- Note that in text mode, the logs are updated every 4 seconds, so in this mode
-- the log lines will often be identical for a cycle.
if cntwww = www_count'Last then
cntwww := www_count'First;
write_history_json;
write_summary_json (active => True,
states => builder_states,
num_builders => num_builders,
num_history_files => history.segment);
else
cntwww := cntwww + 1;
end if;
else
cntcycle := cntcycle + 1;
end if;
delay 0.10;
exception
when earthquake : others =>
LOG.scribe (total, LOG.elapsed_now & " UNHANDLED BULK RUN EXCEPTION: " &
EX.Exception_Information (earthquake), False);
exit;
end;
end loop;
if PM.configuration.avec_ncurses and then curses_support
then
DPC.terminate_monitor;
end if;
write_history_json;
write_summary_json (active => False,
states => builder_states,
num_builders => num_builders,
num_history_files => history.segment);
run_hook (run_end,
"PORTS_BUILT=" & HT.int2str (LOG.port_counter_value (success)) &
" PORTS_FAILED=" & HT.int2str (LOG.port_counter_value (failure)) &
" PORTS_IGNORED=" & HT.int2str (LOG.port_counter_value (ignored)) &
" PORTS_SKIPPED=" & HT.int2str (LOG.port_counter_value (skipped)));
end parallel_bulk_run;
--------------------------------------------------------------------------------------------
-- initialize_hooks
--------------------------------------------------------------------------------------------
procedure initialize_hooks is
begin
for hook in hook_type'Range loop
declare
script : constant String := HT.USS (hook_location (hook));
begin
active_hook (hook) := DIR.Exists (script) and then file_is_executable (script);
end;
end loop;
end initialize_hooks;
--------------------------------------------------------------------------------------------
-- run_hook
--------------------------------------------------------------------------------------------
procedure run_hook (hook : hook_type; envvar_list : String)
is
function nvpair (name : String; value : HT.Text) return String;
function nvpair (name : String; value : HT.Text) return String is
begin
return
name & LAT.Equals_Sign & HT.replace_char (HT.USS (value), LAT.Space, "\ ") & LAT.Space;
end nvpair;
common_env : constant String :=
nvpair ("PROFILE", PM.configuration.profile) &
nvpair ("DIR_PACKAGES", PM.configuration.dir_packages) &
nvpair ("DIR_LOCALBASE", PM.configuration.dir_localbase) &
nvpair ("DIR_CONSPIRACY", PM.configuration.dir_conspiracy) &
nvpair ("DIR_CUSTOM_PORTS", PM.configuration.dir_unkindness) &
nvpair ("DIR_DISTFILES", PM.configuration.dir_distfiles) &
nvpair ("DIR_LOGS", PM.configuration.dir_logs) &
nvpair ("DIR_BUILDBASE", PM.configuration.dir_buildbase);
-- The follow command works on every platform
command : constant String := "/usr/bin/env -i " & common_env &
envvar_list & " " & HT.USS (hook_location (hook));
begin
if not active_hook (hook) then
return;
end if;
if Unix.external_command (command) then
null;
end if;
end run_hook;
--------------------------------------------------------------------------------------------
-- run_start_hook
--------------------------------------------------------------------------------------------
procedure run_start_hook is
begin
run_hook (run_start, "PORTS_QUEUED=" & HT.int2str (queue_length) & " ");
end run_start_hook;
--------------------------------------------------------------------------------------------
-- run_hook_after_build
--------------------------------------------------------------------------------------------
procedure run_hook_after_build (built : Boolean; id : port_id) is
begin
if built then
run_package_hook (pkg_success, id);
else
run_package_hook (pkg_failure, id);
end if;
end run_hook_after_build;
--------------------------------------------------------------------------------------------
-- run_package_hook
--------------------------------------------------------------------------------------------
procedure run_package_hook (hook : hook_type; id : port_id)
is
tail : String := " ORIGIN=" & get_port_variant (id);
begin
case hook is
when pkg_success => run_hook (hook, "RESULT=success" & tail);
when pkg_failure => run_hook (hook, "RESULT=failure" & tail);
when pkg_ignored => run_hook (hook, "RESULT=ignored" & tail);
when pkg_skipped => run_hook (hook, "RESULT=skipped" & tail);
when others => null;
end case;
end run_package_hook;
--------------------------------------------------------------------------------------------
-- file_is_executable
--------------------------------------------------------------------------------------------
function file_is_executable (filename : String) return Boolean
is
status : Integer;
sysroot : constant String := HT.USS (PM.configuration.dir_sysroot);
command : constant String := sysroot & "/usr/bin/file -m " & sysroot &
"/usr/share/file/magic.mgc -b " & filename;
cmdout : String := HT.USS (Unix.piped_command (command, status));
begin
if status = 0 then
return HT.contains (cmdout, "executable");
else
return False;
end if;
end file_is_executable;
--------------------------------------------------------------------------------------------
-- delete_existing_web_history_files
--------------------------------------------------------------------------------------------
procedure delete_existing_web_history_files
is
search : DIR.Search_Type;
dirent : DIR.Directory_Entry_Type;
pattern : constant String := "*_history.json";
filter : constant DIR.Filter_Type := (DIR.Ordinary_File => True, others => False);
reportdir : constant String := HT.USS (PM.configuration.dir_logs);
begin
if not DIR.Exists (reportdir) then
return;
end if;
DIR.Start_Search (Search => search,
Directory => reportdir,
Pattern => pattern,
Filter => filter);
while DIR.More_Entries (search) loop
DIR.Get_Next_Entry (search, dirent);
DIR.Delete_File (reportdir & "/" & DIR.Simple_Name (dirent));
end loop;
DIR.End_Search (search);
exception
when DIR.Name_Error => null;
end delete_existing_web_history_files;
--------------------------------------------------------------------------------------------
-- delete_existing_packages_of_ports_list
--------------------------------------------------------------------------------------------
procedure delete_existing_packages_of_ports_list
is
procedure force_delete (plcursor : string_crate.Cursor);
compkey : HT.Text := HT.SUS (default_compiler & LAT.Colon & variant_standard);
compiler : constant port_index := ports_keys.Element (compkey);
binutils : constant port_index := ports_keys.Element (HT.SUS (default_binutils));
procedure force_delete (plcursor : string_crate.Cursor)
is
procedure delete_subpackage (position : subpackage_crate.Cursor);
origin : HT.Text := string_crate.Element (plcursor);
pndx : constant port_index := ports_keys.Element (origin);
repo : constant String := HT.USS (PM.configuration.dir_repository) & "/";
procedure delete_subpackage (position : subpackage_crate.Cursor)
is
rec : subpackage_record renames subpackage_crate.Element (position);
subpackage : constant String := HT.USS (rec.subpackage);
tball : constant String := repo &
PortScan.calculate_package_name (pndx, subpackage) & arc_ext;
begin
-- Never delete the port binutils or compiler's packages
if pndx /= compiler and then pndx /= binutils then
if DIR.Exists (tball) then
DIR.Delete_File (tball);
end if;
end if;
end delete_subpackage;
begin
all_ports (pndx).subpackages.Iterate (delete_subpackage'Access);
end force_delete;
begin
portlist.Iterate (Process => force_delete'Access);
end delete_existing_packages_of_ports_list;
--------------------------------------------------------------------------------------------
-- list_subpackages_of_queued_ports
--------------------------------------------------------------------------------------------
procedure list_subpackages_of_queued_ports
is
procedure list (plcursor : string_crate.Cursor);
procedure list (plcursor : string_crate.Cursor)
is
procedure name (position : subpackage_crate.Cursor);
origin : HT.Text renames string_crate.Element (plcursor);
pndx : constant port_index := ports_keys.Element (origin);
procedure name (position : subpackage_crate.Cursor)
is
rec : subpackage_record renames subpackage_crate.Element (position);
subpackage : constant String := HT.USS (rec.subpackage);
begin
TIO.Put (" " & subpackage);
end name;
begin
TIO.Put (HT.USS (origin) & " subpackages:");
all_ports (pndx).subpackages.Iterate (name'Access);
TIO.Put_Line ("");
end list;
begin
portlist.Iterate (list'Access);
end list_subpackages_of_queued_ports;
--------------------------------------------------------------------------------------------
-- next_ignored_port
--------------------------------------------------------------------------------------------
function next_ignored_port return port_id
is
list_len : constant Integer := Integer (rank_queue.Length);
cursor : ranking_crate.Cursor;
QR : queue_record;
result : port_id := port_match_failed;
begin
if list_len = 0 then
return result;
end if;
cursor := rank_queue.First;
for k in 1 .. list_len loop
QR := ranking_crate.Element (Position => cursor);
if all_ports (QR.ap_index).ignored then
result := QR.ap_index;
DPY.insert_history
(CYC.assemble_history_record (1, QR.ap_index, DPY.action_ignored));
run_package_hook (pkg_ignored, QR.ap_index);
exit;
end if;
cursor := ranking_crate.Next (Position => cursor);
end loop;
return result;
end next_ignored_port;
--------------------------------------------------------------------------------------------
-- assimulate_substring
--------------------------------------------------------------------------------------------
procedure assimulate_substring (history : in out progress_history; substring : String)
is
first : constant Positive := history.last_index + 1;
last : constant Positive := history.last_index + substring'Length;
begin
-- silently fail (this shouldn't be practically possible)
if last < kfile_content'Last then
history.content (first .. last) := substring;
end if;
history.last_index := last;
end assimulate_substring;
--------------------------------------------------------------------------------------------
-- nv #1
--------------------------------------------------------------------------------------------
function nv (name, value : String) return String is
begin
return
LAT.Quotation & name & LAT.Quotation & LAT.Colon &
LAT.Quotation & value & LAT.Quotation;
end nv;
--------------------------------------------------------------------------------------------
-- nv #2
--------------------------------------------------------------------------------------------
function nv (name : String; value : Integer) return String is
begin
return LAT.Quotation & name & LAT.Quotation & LAT.Colon & HT.int2str (value);
end nv;
--------------------------------------------------------------------------------------------
-- handle_first_history_entry
--------------------------------------------------------------------------------------------
procedure handle_first_history_entry is
begin
if history.segment_count = 1 then
assimulate_substring (history, "[" & LAT.LF & " {" & LAT.LF);
else
assimulate_substring (history, " ,{" & LAT.LF);
end if;
end handle_first_history_entry;
--------------------------------------------------------------------------------------------
-- write_history_json
--------------------------------------------------------------------------------------------
procedure write_history_json
is
jsonfile : TIO.File_Type;
filename : constant String := HT.USS (PM.configuration.dir_logs) &
"/" & HT.zeropad (history.segment, 2) & "_history.json";
begin
if history.segment_count = 0 then
return;
end if;
if history.last_written = history.last_index then
return;
end if;
TIO.Create (File => jsonfile,
Mode => TIO.Out_File,
Name => filename);
TIO.Put (jsonfile, history.content (1 .. history.last_index));
TIO.Put (jsonfile, "]");
TIO.Close (jsonfile);
history.last_written := history.last_index;
exception
when others =>
if TIO.Is_Open (jsonfile) then
TIO.Close (jsonfile);
end if;
end write_history_json;
--------------------------------------------------------------------------------------------
-- check_history_segment_capacity
--------------------------------------------------------------------------------------------
procedure check_history_segment_capacity is
begin
if history.segment_count = 1 then
history.segment := history.segment + 1;
return;
end if;
if history.segment_count < kfile_units_limit then
return;
end if;
write_history_json;
history.last_index := 0;
history.last_written := 0;
history.segment_count := 0;
end check_history_segment_capacity;
--------------------------------------------------------------------------------------------
-- record_history_ignored
--------------------------------------------------------------------------------------------
procedure record_history_ignored
(elapsed : String;
bucket : String;
origin : String;
reason : String;
skips : Natural)
is
cleantxt : constant String := HT.strip_control (reason);
info : constant String :=
HT.replace_char
(HT.replace_char (cleantxt, LAT.Quotation, " "), LAT.Reverse_Solidus, "\")
& ":|:" & HT.int2str (skips);
begin
history.log_entry := history.log_entry + 1;
history.segment_count := history.segment_count + 1;
handle_first_history_entry;
assimulate_substring (history, " " & nv ("entry", history.log_entry) & LAT.LF);
assimulate_substring (history, " ," & nv ("elapsed", elapsed) & LAT.LF);
assimulate_substring (history, " ," & nv ("ID", "--") & LAT.LF);
assimulate_substring (history, " ," & nv ("result", "ignored") & LAT.LF);
assimulate_substring (history, " ," & nv ("bucket", bucket) & LAT.LF);
assimulate_substring (history, " ," & nv ("origin", origin) & LAT.LF);
assimulate_substring (history, " ," & nv ("info", info) & LAT.LF);
assimulate_substring (history, " ," & nv ("duration", "--:--:--") & LAT.LF);
assimulate_substring (history, " }" & LAT.LF);
check_history_segment_capacity;
end record_history_ignored;
--------------------------------------------------------------------------------------------
-- record_history_skipped
--------------------------------------------------------------------------------------------
procedure record_history_skipped
(elapsed : String;
bucket : String;
origin : String;
reason : String)
is
begin
history.log_entry := history.log_entry + 1;
history.segment_count := history.segment_count + 1;
handle_first_history_entry;
assimulate_substring (history, " " & nv ("entry", history.log_entry) & LAT.LF);
assimulate_substring (history, " ," & nv ("elapsed", elapsed) & LAT.LF);
assimulate_substring (history, " ," & nv ("ID", "--") & LAT.LF);
assimulate_substring (history, " ," & nv ("result", "skipped") & LAT.LF);
assimulate_substring (history, " ," & nv ("bucket", bucket) & LAT.LF);
assimulate_substring (history, " ," & nv ("origin", origin) & LAT.LF);
assimulate_substring (history, " ," & nv ("info", reason) & LAT.LF);
assimulate_substring (history, " ," & nv ("duration", "--:--:--") & LAT.LF);
assimulate_substring (history, " }" & LAT.LF);
check_history_segment_capacity;
end record_history_skipped;
--------------------------------------------------------------------------------------------
-- record_history_built
--------------------------------------------------------------------------------------------
procedure record_history_built
(elapsed : String;
slave_id : builders;
bucket : String;
origin : String;
duration : String)
is
ID : constant String := HT.zeropad (Integer (slave_id), 2);
begin
history.log_entry := history.log_entry + 1;
history.segment_count := history.segment_count + 1;
handle_first_history_entry;
assimulate_substring (history, " " & nv ("entry", history.log_entry) & LAT.LF);
assimulate_substring (history, " ," & nv ("elapsed", elapsed) & LAT.LF);
assimulate_substring (history, " ," & nv ("ID", ID) & LAT.LF);
assimulate_substring (history, " ," & nv ("result", "built") & LAT.LF);
assimulate_substring (history, " ," & nv ("bucket", bucket) & LAT.LF);
assimulate_substring (history, " ," & nv ("origin", origin) & LAT.LF);
assimulate_substring (history, " ," & nv ("info", "") & LAT.LF);
assimulate_substring (history, " ," & nv ("duration", duration) & LAT.LF);
assimulate_substring (history, " }" & LAT.LF);
check_history_segment_capacity;
end record_history_built;
--------------------------------------------------------------------------------------------
-- record_history_built
--------------------------------------------------------------------------------------------
procedure record_history_failed
(elapsed : String;
slave_id : builders;
bucket : String;
origin : String;
duration : String;
die_phase : String;
skips : Natural)
is
info : constant String := die_phase & ":" & HT.int2str (skips);
ID : constant String := HT.zeropad (Integer (slave_id), 2);
begin
history.log_entry := history.log_entry + 1;
history.segment_count := history.segment_count + 1;
handle_first_history_entry;
assimulate_substring (history, " " & nv ("entry", history.log_entry) & LAT.LF);
assimulate_substring (history, " ," & nv ("elapsed", elapsed) & LAT.LF);
assimulate_substring (history, " ," & nv ("ID", ID) & LAT.LF);
assimulate_substring (history, " ," & nv ("result", "failed") & LAT.LF);
assimulate_substring (history, " ," & nv ("bucket", bucket) & LAT.LF);
assimulate_substring (history, " ," & nv ("origin", origin) & LAT.LF);
assimulate_substring (history, " ," & nv ("info", info) & LAT.LF);
assimulate_substring (history, " ," & nv ("duration", duration) & LAT.LF);
assimulate_substring (history, " }" & LAT.LF);
check_history_segment_capacity;
end record_history_failed;
--------------------------------------------------------------------------------------------
-- skip_verified
--------------------------------------------------------------------------------------------
function skip_verified (id : port_id) return Boolean is
begin
if id = port_match_failed then
return False;
end if;
return not all_ports (id).unlist_failed;
end skip_verified;
--------------------------------------------------------------------------------------------
-- delete_rank
--------------------------------------------------------------------------------------------
procedure delete_rank (id : port_id)
is
rank_cursor : ranking_crate.Cursor := rank_arrow (id);
use type ranking_crate.Cursor;
begin
if rank_cursor /= ranking_crate.No_Element then
rank_queue.Delete (Position => rank_cursor);
end if;
end delete_rank;
--------------------------------------------------------------------------------------------
-- still_ranked
--------------------------------------------------------------------------------------------
function still_ranked (id : port_id) return Boolean
is
rank_cursor : ranking_crate.Cursor := rank_arrow (id);
use type ranking_crate.Cursor;
begin
return rank_cursor /= ranking_crate.No_Element;
end still_ranked;
--------------------------------------------------------------------------------------------
-- unlist_first_port
--------------------------------------------------------------------------------------------
function unlist_first_port return port_id
is
origin : HT.Text := string_crate.Element (portlist.First);
id : port_id;
begin
if ports_keys.Contains (origin) then
id := ports_keys.Element (origin);
else
return port_match_failed;
end if;
if id = port_match_failed then
return port_match_failed;
end if;
delete_rank (id);
return id;
end unlist_first_port;
--------------------------------------------------------------------------------------------
-- unlist_port
--------------------------------------------------------------------------------------------
procedure unlist_port (id : port_id) is
begin
if id = port_match_failed then
return;
end if;
if still_ranked (id) then
delete_rank (id);
else
-- don't raise exception. Since we don't prune all_reverse as
-- we go, there's no guarantee the reverse dependency hasn't already
-- been removed (e.g. when it is a common reverse dep)
all_ports (id).unlist_failed := True;
end if;
end unlist_port;
--------------------------------------------------------------------------------------------
-- rank_arrow
--------------------------------------------------------------------------------------------
function rank_arrow (id : port_id) return ranking_crate.Cursor
is
rscore : constant port_index := all_ports (id).reverse_score;
seek_target : constant queue_record := (ap_index => id,
reverse_score => rscore);
begin
return rank_queue.Find (seek_target);
end rank_arrow;
--------------------------------------------------------------------------------------------
-- skip_next_reverse_dependency
--------------------------------------------------------------------------------------------
function skip_next_reverse_dependency (pinnacle : port_id) return port_id
is
rev_cursor : block_crate.Cursor;
next_dep : port_index;
begin
if all_ports (pinnacle).all_reverse.Is_Empty then
return port_match_failed;
end if;
rev_cursor := all_ports (pinnacle).all_reverse.First;
next_dep := block_crate.Element (rev_cursor);
unlist_port (id => next_dep);
all_ports (pinnacle).all_reverse.Delete (rev_cursor);
return next_dep;
end skip_next_reverse_dependency;
--------------------------------------------------------------------------------------------
-- cascade_failed_build
--------------------------------------------------------------------------------------------
procedure cascade_failed_build (id : port_id; numskipped : out Natural)
is
purged : PortScan.port_id;
culprit : constant String := get_port_variant (id);
begin
numskipped := 0;
loop
purged := skip_next_reverse_dependency (id);
exit when purged = port_match_failed;
if skip_verified (purged) then
numskipped := numskipped + 1;
LOG.scribe (PortScan.total, " Skipped: " & get_port_variant (purged), False);
LOG.scribe (PortScan.skipped, get_port_variant (purged) & " by " & culprit, False);
DPY.insert_history (CYC.assemble_history_record (1, purged, DPY.action_skipped));
record_history_skipped (elapsed => LOG.elapsed_now,
bucket => get_bucket (purged),
origin => get_port_variant (purged),
reason => culprit);
run_package_hook (pkg_skipped, purged);
end if;
end loop;
unlist_port (id);
end cascade_failed_build;
--------------------------------------------------------------------------------------------
-- cascade_successful_build
--------------------------------------------------------------------------------------------
procedure cascade_successful_build (id : port_id)
is
procedure cycle (cursor : block_crate.Cursor);
procedure cycle (cursor : block_crate.Cursor)
is
target : port_index renames block_crate.Element (cursor);
begin
if all_ports (target).blocked_by.Contains (id) then
all_ports (target).blocked_by.Delete (id);
else
raise seek_failure
with get_port_variant (target) & " was expected to be blocked by " &
get_port_variant (id);
end if;
end cycle;
begin
all_ports (id).blocks.Iterate (cycle'Access);
delete_rank (id);
end cascade_successful_build;
--------------------------------------------------------------------------------------------
-- integrity_intact
--------------------------------------------------------------------------------------------
function integrity_intact return Boolean
is
procedure check_dep (cursor : block_crate.Cursor);
procedure check_rank (cursor : ranking_crate.Cursor);
intact : Boolean := True;
procedure check_dep (cursor : block_crate.Cursor)
is
did : constant port_index := block_crate.Element (cursor);
begin
if not still_ranked (did) then
intact := False;
end if;
end check_dep;
procedure check_rank (cursor : ranking_crate.Cursor)
is
QR : constant queue_record := ranking_crate.Element (cursor);
begin
if intact then
all_ports (QR.ap_index).blocked_by.Iterate (check_dep'Access);
end if;
end check_rank;
begin
rank_queue.Iterate (check_rank'Access);
return intact;
end integrity_intact;
--------------------------------------------------------------------------------------------
-- located_external_repository
--------------------------------------------------------------------------------------------
function located_external_repository return Boolean
is
command : constant String := host_pkg8 & " -vv";
found : Boolean := False;
inspect : Boolean := False;
status : Integer;
begin
declare
dump : String := HT.USS (Unix.piped_command (command, status));
markers : HT.Line_Markers;
linenum : Natural := 0;
begin
if status /= 0 then
return False;
end if;
HT.initialize_markers (dump, markers);
loop
exit when not HT.next_line_present (dump, markers);
declare
line : constant String := HT.extract_line (dump, markers);
len : constant Natural := line'Length;
begin
if inspect then
if len > 7 and then
line (line'First .. line'First + 1) = " " and then
line (line'Last - 3 .. line'Last) = ": { " and then
line (line'First + 2 .. line'Last - 4) /= "ravenadm"
then
found := True;
external_repository := HT.SUS (line (line'First + 2 .. line'Last - 4));
exit;
end if;
else
if line = "Repositories:" then
inspect := True;
end if;
end if;
end;
end loop;
end;
return found;
end located_external_repository;
--------------------------------------------------------------------------------------------
-- top_external_repository
--------------------------------------------------------------------------------------------
function top_external_repository return String is
begin
return HT.USS (external_repository);
end top_external_repository;
--------------------------------------------------------------------------------------------
-- isolate_arch_from_file_type
--------------------------------------------------------------------------------------------
function isolate_arch_from_file_type (fileinfo : String) return filearch
is
-- DF: ELF 64-bit LSB executable, x86-64
-- FB: ELF 64-bit LSB executable, x86-64
-- FB: ELF 32-bit LSB executable, Intel 80386
-- NB: ELF 64-bit LSB executable, x86-64
-- L: ELF 64-bit LSB executable, x86-64
-- NATIVE Solaris (we use our own file)
-- /usr/bin/sh: ELF 64-bit LSB executable AMD64 Version 1
fragment : constant String := HT.trim (HT.specific_field (fileinfo, 2, ","));
answer : filearch := (others => ' ');
begin
if fragment'Length > filearch'Length then
answer := fragment (fragment'First .. fragment'First + filearch'Length - 1);
else
answer (answer'First .. answer'First + fragment'Length - 1) := fragment;
end if;
return answer;
end isolate_arch_from_file_type;
--------------------------------------------------------------------------------------------
-- isolate_arch_from_macho_file
--------------------------------------------------------------------------------------------
function isolate_arch_from_macho_file (fileinfo : String) return filearch
is
-- Mac: Mach-O 64-bit executable x86_64
fragment : constant String := HT.trim (HT.specific_field (fileinfo, 4));
answer : filearch := (others => ' ');
begin
if fragment'Length > filearch'Length then
answer := fragment (fragment'First .. fragment'First + filearch'Length - 1);
else
answer (answer'First .. answer'First + fragment'Length - 1) := fragment;
end if;
return answer;
end isolate_arch_from_macho_file;
--------------------------------------------------------------------------------------------
-- establish_package_architecture
--------------------------------------------------------------------------------------------
procedure establish_package_architecture (release : String; architecture : supported_arch)
is
function newsuffix return String;
function suffix return String;
function get_version (fileinfo : String; OS : String) return String;
procedure craft_common_endings (release : String);
function suffix return String is
begin
case architecture is
when x86_64 => return "x86:64";
when i386 => return "x86:32";
when aarch64 => return "aarch64:64";
end case;
end suffix;
function newsuffix return String is
begin
case architecture is
when x86_64 => return "amd64";
when i386 => return "i386";
when aarch64 => return "arm64";
end case;
end newsuffix;
procedure craft_common_endings (release : String) is
begin
HT.SU.Append (abi_formats.calculated_abi, release & ":");
HT.SU.Append (abi_formats.calculated_alt_abi, release & ":");
abi_formats.calc_abi_noarch := abi_formats.calculated_abi;
abi_formats.calc_alt_abi_noarch := abi_formats.calculated_alt_abi;
HT.SU.Append (abi_formats.calculated_abi, newsuffix);
HT.SU.Append (abi_formats.calculated_alt_abi, suffix);
HT.SU.Append (abi_formats.calc_abi_noarch, "*");
HT.SU.Append (abi_formats.calc_alt_abi_noarch, "*");
end craft_common_endings;
function get_version (fileinfo : String; OS : String) return String
is
-- GNU/Linux 2.6.32, BuildID[sha1]=03d7a9de009544a1fe82313544a3c36e249858cc, stripped
rest : constant String := HT.part_2 (fileinfo, OS);
begin
return HT.part_1 (rest, ",");
end get_version;
begin
case platform_type is
when dragonfly =>
declare
dfly : constant String := "dragonfly:";
begin
abi_formats.calculated_abi := HT.SUS (dfly);
HT.SU.Append (abi_formats.calculated_abi, release & ":");
abi_formats.calc_abi_noarch := abi_formats.calculated_abi;
HT.SU.Append (abi_formats.calculated_abi, suffix);
HT.SU.Append (abi_formats.calc_abi_noarch, "*");
abi_formats.calculated_alt_abi := abi_formats.calculated_abi;
abi_formats.calc_alt_abi_noarch := abi_formats.calc_abi_noarch;
end;
when freebsd =>
declare
fbsd1 : constant String := "FreeBSD:";
fbsd2 : constant String := "freebsd:";
begin
abi_formats.calculated_abi := HT.SUS (fbsd1);
abi_formats.calculated_alt_abi := HT.SUS (fbsd2);
craft_common_endings (release);
end;
when netbsd =>
declare
net1 : constant String := "NetBSD:";
net2 : constant String := "netbsd:";
begin
abi_formats.calculated_abi := HT.SUS (net1);
abi_formats.calculated_alt_abi := HT.SUS (net2);
craft_common_endings (release);
end;
when openbsd =>
declare
open1 : constant String := "OpenBSD:";
open2 : constant String := "openbsd:";
begin
abi_formats.calculated_abi := HT.SUS (open1);
abi_formats.calculated_alt_abi := HT.SUS (open2);
craft_common_endings (release);
end;
when sunos =>
declare
sol1 : constant String := "Solaris:";
sol2 : constant String := "solaris:";
solrel : constant String := "10"; -- hardcoded in pkg(8), release=5.10
begin
abi_formats.calculated_abi := HT.SUS (sol1);
abi_formats.calculated_alt_abi := HT.SUS (sol2);
craft_common_endings (solrel);
end;
when macos =>
-- Hardcode i386 for now until pkg(8) fixed to provide correct arch
abi_formats.calculated_abi := HT.SUS ("Darwin:" & release & ":");
abi_formats.calculated_alt_abi := HT.SUS ("darwin:" & release & ":");
abi_formats.calc_abi_noarch := abi_formats.calculated_abi;
abi_formats.calc_alt_abi_noarch := abi_formats.calculated_alt_abi;
HT.SU.Append (abi_formats.calculated_abi, "i386");
HT.SU.Append (abi_formats.calculated_alt_abi, "i386:32");
HT.SU.Append (abi_formats.calc_abi_noarch, "*");
HT.SU.Append (abi_formats.calc_alt_abi_noarch, "*");
when linux =>
declare
sysroot : constant String := HT.USS (PM.configuration.dir_sysroot);
command : constant String := sysroot & "/usr/bin/file -m " & sysroot &
"/usr/share/file/magic.mgc -b " & sysroot & "/bin/sh";
status : Integer;
UN : HT.Text;
begin
UN := Unix.piped_command (command, status);
declare
gnu1 : constant String := "Linux:";
gnu2 : constant String := "linux:";
gnurel : constant String := get_version (HT.USS (UN), "GNU/Linux ");
begin
abi_formats.calculated_abi := HT.SUS (gnu1);
abi_formats.calculated_alt_abi := HT.SUS (gnu2);
craft_common_endings (gnurel);
end;
end;
end case;
end establish_package_architecture;
--------------------------------------------------------------------------------------------
-- limited_sanity_check
--------------------------------------------------------------------------------------------
procedure limited_sanity_check
(repository : String;
dry_run : Boolean;
rebuild_compiler : Boolean;
rebuild_binutils : Boolean;
suppress_remote : Boolean;
major_release : String;
architecture : supported_arch)
is
procedure prune_packages (cursor : ranking_crate.Cursor);
procedure check_package (cursor : ranking_crate.Cursor);
procedure determine_fully_built (cursor : subpackage_queue.Cursor);
procedure prune_queue (cursor : subqueue.Cursor);
procedure print (cursor : subpackage_queue.Cursor);
procedure fetch (cursor : subpackage_queue.Cursor);
procedure check (cursor : subpackage_queue.Cursor);
procedure set_delete (Element : in out subpackage_record);
procedure kill_remote (Element : in out subpackage_record);
compkey : HT.Text := HT.SUS (default_compiler & LAT.Colon & variant_standard);
bukey : HT.Text := HT.SUS (default_binutils);
compiler : constant port_index := ports_keys.Element (compkey);
binutils : constant port_index := ports_keys.Element (bukey);
already_built : subpackage_queue.Vector;
fetch_list : subpackage_queue.Vector;
prune_list : subqueue.Vector;
fetch_fail : Boolean := False;
clean_pass : Boolean := False;
listlog : TIO.File_Type;
goodlog : Boolean;
using_screen : constant Boolean := Unix.screen_attached;
filename : constant String := "/tmp/ravenadm_prefetch_list.txt";
package_list : HT.Text := HT.blank;
procedure set_delete (Element : in out subpackage_record) is
begin
Element.deletion_due := True;
end set_delete;
procedure kill_remote (Element : in out subpackage_record) is
begin
Element.remote_pkg := False;
end kill_remote;
procedure check_package (cursor : ranking_crate.Cursor)
is
procedure check_subpackage (position : subpackage_crate.Cursor);
target : port_id := ranking_crate.Element (cursor).ap_index;
procedure check_subpackage (position : subpackage_crate.Cursor)
is
rec : subpackage_record renames subpackage_crate.Element (position);
subpackage : constant String := HT.USS (rec.subpackage);
pkgname : constant String := calculate_package_name (target, subpackage);
available : constant Boolean :=
(rec.remote_pkg or else rec.pkg_present) and then not rec.deletion_due;
newrec : subpackage_identifier := (target, rec.subpackage);
begin
if not available then
return;
end if;
if passed_dependency_check (subpackage => subpackage,
query_result => rec.pkg_dep_query,
id => target)
then
if not
(
(rebuild_binutils and then
target = binutils)
or else
(rebuild_compiler and then
target = compiler)
)
then
already_built.Append (New_Item => newrec);
if rec.remote_pkg then
fetch_list.Append (New_Item => newrec);
end if;
end if;
else
if rec.remote_pkg then
-- silently fail, remote packages are a bonus anyway
all_ports (target).subpackages.Update_Element (Position => position,
Process => kill_remote'Access);
else
TIO.Put_Line (pkgname & " failed dependency check.");
all_ports (target).subpackages.Update_Element (Position => position,
Process => set_delete'Access);
end if;
clean_pass := False;
end if;
end check_subpackage;
begin
all_ports (target).subpackages.Iterate (check_subpackage'Access);
end check_package;
procedure prune_queue (cursor : subqueue.Cursor)
is
id : constant port_index := subqueue.Element (cursor);
begin
cascade_successful_build (id);
end prune_queue;
procedure prune_packages (cursor : ranking_crate.Cursor)
is
procedure check_subpackage (position : subpackage_crate.Cursor);
target : port_id := ranking_crate.Element (cursor).ap_index;
procedure check_subpackage (position : subpackage_crate.Cursor)
is
rec : subpackage_record renames subpackage_crate.Element (position);
delete_it : Boolean := rec.deletion_due;
begin
if delete_it then
declare
subpackage : constant String := HT.USS (rec.subpackage);
pkgname : constant String := calculate_package_name (target, subpackage);
fullpath : constant String := repository & "/" & pkgname & arc_ext;
begin
DIR.Delete_File (fullpath);
exception
when others => null;
end;
end if;
end check_subpackage;
begin
all_ports (target).subpackages.Iterate (check_subpackage'Access);
end prune_packages;
procedure print (cursor : subpackage_queue.Cursor)
is
id : constant port_index := subpackage_queue.Element (cursor).id;
subpkg : constant String := HT.USS (subpackage_queue.Element (cursor).subpackage);
pkgfile : constant String := calculate_package_name (id, subpkg) & arc_ext;
begin
TIO.Put_Line (" => " & pkgfile);
if goodlog then
TIO.Put_Line (listlog, pkgfile);
end if;
end print;
procedure fetch (cursor : subpackage_queue.Cursor)
is
id : constant port_index := subpackage_queue.Element (cursor).id;
subpkg : constant String := HT.USS (subpackage_queue.Element (cursor).subpackage);
pkgbase : constant String := " " & calculate_package_name (id, subpkg);
begin
HT.SU.Append (package_list, pkgbase);
end fetch;
procedure check (cursor : subpackage_queue.Cursor)
is
id : constant port_index := subpackage_queue.Element (cursor).id;
subpkg : constant String := HT.USS (subpackage_queue.Element (cursor).subpackage);
pkgfile : constant String := calculate_package_name (id, subpkg) & arc_ext;
loc : constant String := HT.USS (PM.configuration.dir_repository) & "/" & pkgfile;
begin
if not DIR.Exists (loc) then
TIO.Put_Line ("Download failed: " & pkgfile);
fetch_fail := True;
end if;
end check;
procedure determine_fully_built (cursor : subpackage_queue.Cursor)
is
procedure check_subpackage (cursor : subpackage_crate.Cursor);
glass_full : Boolean := True;
target : port_id := subpackage_queue.Element (cursor).id;
procedure check_subpackage (cursor : subpackage_crate.Cursor)
is
procedure check_already_built (position : subpackage_queue.Cursor);
rec : subpackage_record renames subpackage_crate.Element (cursor);
found : Boolean := False;
procedure check_already_built (position : subpackage_queue.Cursor)
is
builtrec : subpackage_identifier renames subpackage_queue.Element (position);
begin
if not found then
if HT.equivalent (builtrec.subpackage, rec.subpackage) then
found := True;
if rec.deletion_due or else
not (rec.pkg_present or else rec.remote_pkg)
then
glass_full := False;
end if;
end if;
end if;
end check_already_built;
begin
if glass_full then
already_built.Iterate (check_already_built'Access);
end if;
end check_subpackage;
begin
all_ports (target).subpackages.Iterate (check_subpackage'Access);
if glass_full then
if not prune_list.Contains (target) then
prune_list.Append (target);
end if;
end if;
end determine_fully_built;
begin
if Unix.env_variable_defined ("WHYFAIL") then
activate_debugging_code;
end if;
establish_package_architecture (major_release, architecture);
original_queue_len := rank_queue.Length;
for m in scanners'Range loop
mq_progress (m) := 0;
end loop;
LOG.start_obsolete_package_logging;
parallel_package_scan (repository, False, using_screen);
if Signals.graceful_shutdown_requested then
LOG.stop_obsolete_package_logging;
return;
end if;
while not clean_pass loop
clean_pass := True;
already_built.Clear;
rank_queue.Iterate (check_package'Access);
end loop;
if not suppress_remote and then PM.configuration.defer_prebuilt then
-- The defer_prebuilt options has been elected, so check all the
-- missing and to-be-pruned ports for suitable prebuilt packages
-- So we need to an incremental scan (skip valid, present packages)
for m in scanners'Range loop
mq_progress (m) := 0;
end loop;
parallel_package_scan (repository, True, using_screen);
if Signals.graceful_shutdown_requested then
LOG.stop_obsolete_package_logging;
return;
end if;
clean_pass := False;
while not clean_pass loop
clean_pass := True;
already_built.Clear;
fetch_list.Clear;
rank_queue.Iterate (check_package'Access);
end loop;
end if;
LOG.stop_obsolete_package_logging;
if Signals.graceful_shutdown_requested then
return;
end if;
if dry_run then
if not fetch_list.Is_Empty then
begin
TIO.Create (File => listlog, Mode => TIO.Out_File, Name => filename);
goodlog := True;
exception
when others => goodlog := False;
end;
TIO.Put_Line ("These are the packages that would be fetched:");
fetch_list.Iterate (print'Access);
TIO.Put_Line ("Total packages that would be fetched:" & fetch_list.Length'Img);
if goodlog then
TIO.Close (listlog);
TIO.Put_Line ("The complete build list can also be found at:"
& LAT.LF & filename);
end if;
else
if PM.configuration.defer_prebuilt then
TIO.Put_Line ("No packages qualify for prefetching from " &
"official package repository.");
end if;
end if;
else
rank_queue.Iterate (prune_packages'Access);
fetch_list.Iterate (fetch'Access);
if not HT.equivalent (package_list, HT.blank) then
declare
cmd : constant String := host_pkg8 & " fetch -r " &
HT.USS (external_repository) & " -U -y --output " &
HT.USS (PM.configuration.dir_packages) & HT.USS (package_list);
begin
if Unix.external_command (cmd) then
null;
end if;
end;
fetch_list.Iterate (check'Access);
end if;
end if;
if fetch_fail then
TIO.Put_Line ("At least one package failed to fetch, aborting build!");
rank_queue.Clear;
else
-- All subpackages must be "already_built" before we can prune.
-- we have iterate through the rank_queue, then subiterate through subpackages.
-- If all subpackages are present, add port to prune queue.
already_built.Iterate (determine_fully_built'Access);
prune_list.Iterate (prune_queue'Access);
end if;
end limited_sanity_check;
--------------------------------------------------------------------------------------------
-- result_of_dependency_query
--------------------------------------------------------------------------------------------
function result_of_dependency_query
(repository : String;
id : port_id;
subpackage : String) return HT.Text
is
rec : port_record renames all_ports (id);
pkg_base : constant String := PortScan.calculate_package_name (id, subpackage);
fullpath : constant String := repository & "/" & pkg_base & arc_ext;
pkg8 : constant String := HT.USS (PM.configuration.sysroot_pkg8);
command : constant String := pkg8 & " query -F " & fullpath & " %dn-%dv@%do";
remocmd : constant String := pkg8 & " rquery -r " & HT.USS (external_repository) &
" -U %dn-%dv@%do " & pkg_base;
status : Integer;
comres : HT.Text;
begin
if repository = "" then
comres := Unix.piped_command (remocmd, status);
else
comres := Unix.piped_command (command, status);
end if;
if status = 0 then
return comres;
else
return HT.blank;
end if;
end result_of_dependency_query;
--------------------------------------------------------------------------------------------
-- activate_debugging_code
--------------------------------------------------------------------------------------------
procedure activate_debugging_code is
begin
debug_opt_check := True;
debug_dep_check := True;
end activate_debugging_code;
--------------------------------------------------------------------------------------------
-- passed_dependency_check
--------------------------------------------------------------------------------------------
function passed_dependency_check
(subpackage : String;
query_result : HT.Text;
id : port_id) return Boolean
is
procedure get_rundeps (position : subpackage_crate.Cursor);
procedure log_run_deps (position : subpackage_crate.Cursor);
content : String := HT.USS (query_result);
headport : constant String := HT.USS (all_ports (id).port_namebase) & LAT.Colon &
subpackage & LAT.Colon & HT.USS (all_ports (id).port_variant);
counter : Natural := 0;
req_deps : Natural := 0;
markers : HT.Line_Markers;
pkgfound : Boolean := False;
procedure get_rundeps (position : subpackage_crate.Cursor)
is
rec : subpackage_record renames subpackage_crate.Element (position);
begin
if not pkgfound then
if HT.equivalent (rec.subpackage, subpackage) then
req_deps := Natural (rec.spkg_run_deps.Length);
pkgfound := True;
end if;
end if;
end get_rundeps;
procedure log_run_deps (position : subpackage_crate.Cursor)
is
procedure logme (logpos : spkg_id_crate.Cursor);
rec : subpackage_record renames subpackage_crate.Element (position);
procedure logme (logpos : spkg_id_crate.Cursor) is
rec2 : PortScan.subpackage_identifier renames spkg_id_crate.Element (logpos);
message : constant String := get_port_variant (rec2.port) & " (" &
HT.USS (rec2.subpackage) & ")";
begin
LOG.obsolete_notice (message, debug_dep_check);
end logme;
begin
if HT.equivalent (rec.subpackage, subpackage) then
LOG.obsolete_notice ("Port requirements:", debug_dep_check);
rec.spkg_run_deps.Iterate (logme'Access);
end if;
end log_run_deps;
begin
all_ports (id).subpackages.Iterate (get_rundeps'Access);
HT.initialize_markers (content, markers);
loop
exit when not HT.next_line_present (content, markers);
declare
line : constant String := HT.extract_line (content, markers);
deppkg : constant String := HT.part_1 (line, "@");
origin : constant String := HT.part_2 (line, "@");
begin
exit when line = "";
declare
procedure set_available (position : subpackage_crate.Cursor);
subpackage : String := subpackage_from_pkgname (deppkg);
target_id : port_index := ports_keys.Element (HT.SUS (origin));
target_pkg : String := calculate_package_name (target_id, subpackage);
available : Boolean;
procedure set_available (position : subpackage_crate.Cursor)
is
rec : subpackage_record renames subpackage_crate.Element (position);
begin
if not pkgfound and then
HT.equivalent (rec.subpackage, subpackage)
then
available := (rec.remote_pkg or else rec.pkg_present) and then
not rec.deletion_due;
pkgfound := True;
end if;
end set_available;
begin
if valid_port_id (target_id) then
pkgfound := False;
all_ports (target_id).subpackages.Iterate (set_available'Access);
else
-- package seems to have a dependency that has been removed from the conspiracy
LOG.obsolete_notice
(message => origin & " has been removed from Ravenports",
write_to_screen => debug_dep_check);
return False;
end if;
counter := counter + 1;
if counter > req_deps then
-- package has more dependencies than we are looking for
LOG.obsolete_notice
(write_to_screen => debug_dep_check,
message => headport & " package has more dependencies than the " &
"port requires (" & HT.int2str (req_deps) & ")" & LAT.LF &
"Query: " & LAT.LF & HT.USS (query_result) &
"Tripped on: " & line);
all_ports (id).subpackages.Iterate (log_run_deps'Access);
return False;
end if;
if deppkg /= target_pkg then
-- The version that the package requires differs from the
-- version that Ravenports will now produce
declare
-- If the target package is GCC7, let version mismatches slide. We are
-- probably bootstrapping a new sysroot compiler
nbase : constant String := HT.USS (all_ports (target_id).port_namebase);
variant : constant String := HT.USS (all_ports (target_id).port_variant);
begin
if nbase /= default_compiler and then
not (nbase = "binutils" and then variant = "ravensys")
then
LOG.obsolete_notice
(write_to_screen => debug_dep_check,
message => "Current " & headport & " package depends on " &
deppkg & ", but this is a different version than requirement of " &
target_pkg & " (from " & origin & ")");
return False;
else
LOG.obsolete_notice
(write_to_screen => debug_dep_check,
message => "Ignored dependency check failure: " &
"Current " & headport & " package depends on " &
deppkg & ", but this is a different version than requirement of " &
target_pkg & " (from " & origin & ")");
end if;
end;
end if;
if not available then
-- Even if all the versions are matching, we still need
-- the package to be in repository.
LOG.obsolete_notice
(write_to_screen => debug_dep_check,
message => headport & " package depends on " & target_pkg &
" which doesn't exist or has been scheduled for deletion");
return False;
end if;
end;
end;
end loop;
if counter < req_deps then
-- The ports tree requires more dependencies than the existing package does
LOG.obsolete_notice
(write_to_screen => debug_dep_check,
message => headport & " package has less dependencies than the port " &
"requires (" & HT.int2str (req_deps) & ")" & LAT.LF &
"Query: " & LAT.LF & HT.USS (query_result));
all_ports (id).subpackages.Iterate (log_run_deps'Access);
return False;
end if;
-- If we get this far, the package dependencies match what the
-- port tree requires exactly. This package passed sanity check.
return True;
exception
when issue : others =>
LOG.obsolete_notice
(write_to_screen => debug_dep_check,
message => content & "Dependency check exception" & LAT.LF &
EX.Exception_Message (issue));
return False;
end passed_dependency_check;
--------------------------------------------------------------------------------------------
-- package_scan_progress
--------------------------------------------------------------------------------------------
function package_scan_progress return String
is
type percent is delta 0.01 digits 5;
complete : port_index := 0;
pc : percent;
total : constant Float := Float (pkgscan_total);
begin
for k in scanners'Range loop
complete := complete + pkgscan_progress (k);
end loop;
pc := percent (100.0 * Float (complete) / total);
return " progress:" & pc'Img & "% " & LAT.CR;
end package_scan_progress;
--------------------------------------------------------------------------------------------
-- passed_abi_check
--------------------------------------------------------------------------------------------
function passed_abi_check
(repository : String;
id : port_id;
subpackage : String;
skip_exist_check : Boolean := False) return Boolean
is
rec : port_record renames all_ports (id);
pkg_base : constant String := PortScan.calculate_package_name (id, subpackage);
fullpath : constant String := repository & "/" & pkg_base & arc_ext;
pkg8 : constant String := HT.USS (PM.configuration.sysroot_pkg8);
command : constant String := pkg8 & " query -F " & fullpath & " %q";
remocmd : constant String := pkg8 & " rquery -r " & HT.USS (external_repository) &
" -U %q " & pkg_base;
status : Integer;
comres : HT.Text;
begin
if not skip_exist_check and then not DIR.Exists (Name => fullpath)
then
return False;
end if;
if repository = "" then
comres := Unix.piped_command (remocmd, status);
else
comres := Unix.piped_command (command, status);
end if;
if status /= 0 then
return False;
end if;
declare
topline : String := HT.first_line (HT.USS (comres));
begin
if HT.equivalent (abi_formats.calculated_abi, topline) or else
HT.equivalent (abi_formats.calculated_alt_abi, topline) or else
HT.equivalent (abi_formats.calc_abi_noarch, topline) or else
HT.equivalent (abi_formats.calc_alt_abi_noarch, topline)
then
return True;
end if;
end;
return False;
end passed_abi_check;
--------------------------------------------------------------------------------------------
-- passed_option_check
--------------------------------------------------------------------------------------------
function passed_option_check
(repository : String;
id : port_id;
subpackage : String;
skip_exist_check : Boolean := False) return Boolean
is
rec : port_record renames all_ports (id);
pkg_base : constant String := PortScan.calculate_package_name (id, subpackage);
fullpath : constant String := repository & "/" & pkg_base & arc_ext;
pkg8 : constant String := HT.USS (PM.configuration.sysroot_pkg8);
command : constant String := pkg8 & " query -F " & fullpath & " %Ok:%Ov";
remocmd : constant String := pkg8 & " rquery -r " & HT.USS (external_repository) &
" -U %Ok:%Ov " & pkg_base;
status : Integer;
comres : HT.Text;
counter : Natural := 0;
required : constant Natural := Natural (all_ports (id).options.Length);
extquery : constant Boolean := (repository = "");
begin
if id = port_match_failed or else
not all_ports (id).scanned or else
(not skip_exist_check and then not DIR.Exists (fullpath))
then
LOG.obsolete_notice
(write_to_screen => debug_opt_check,
message => pkg_base & " => passed_option_check() failed sanity check.");
return False;
end if;
if extquery then
comres := Unix.piped_command (remocmd, status);
else
comres := Unix.piped_command (command, status);
end if;
if status /= 0 then
if extquery then
LOG.obsolete_notice
(write_to_screen => debug_opt_check,
message => pkg_base & " => failed to execute: " & remocmd);
else
LOG.obsolete_notice
(write_to_screen => debug_opt_check,
message => pkg_base & " => failed to execute: " & command);
end if;
LOG.obsolete_notice
(write_to_screen => debug_opt_check,
message => "output => " & HT.USS (comres));
return False;
end if;
declare
command_result : constant String := HT.USS (comres);
markers : HT.Line_Markers;
begin
HT.initialize_markers (command_result, markers);
loop
exit when not HT.next_line_present (command_result, markers);
declare
line : constant String := HT.extract_line (command_result, markers);
namekey : constant String := HT.part_1 (line, ":");
knob : constant String := HT.part_2 (line, ":");
nametext : HT.Text := HT.SUS (namekey);
knobval : Boolean;
begin
exit when line = "";
if HT.count_char (line, LAT.Colon) /= 1 then
raise unknown_format with line;
end if;
if knob = "on" then
knobval := True;
elsif knob = "off" then
knobval := False;
else
raise unknown_format with "knob=" & knob & "(" & line & ")";
end if;
counter := counter + 1;
if counter > required then
-- package has more options than we are looking for
LOG.obsolete_notice
(write_to_screen => debug_opt_check,
message => "options " & namekey & LAT.LF & pkg_base &
" has more options than required (" & HT.int2str (required) & ")");
return False;
end if;
if all_ports (id).options.Contains (nametext) then
if knobval /= all_ports (id).options.Element (nametext) then
-- port option value doesn't match package option value
if knobval then
LOG.obsolete_notice
(write_to_screen => debug_opt_check,
message => pkg_base & " " & namekey &
" is ON but specifcation says it must be OFF");
else
LOG.obsolete_notice
(write_to_screen => debug_opt_check,
message => pkg_base & " " & namekey &
" is OFF but specifcation says it must be ON");
end if;
return False;
end if;
else
-- Name of package option not found in port options
LOG.obsolete_notice
(write_to_screen => debug_opt_check,
message => pkg_base & " option " & namekey &
" is no longer present in the specification");
return False;
end if;
end;
end loop;
if counter < required then
-- The ports tree has more options than the existing package
LOG.obsolete_notice
(write_to_screen => debug_opt_check,
message => pkg_base & " has less options than required (" &
HT.int2str (required) & ")");
return False;
end if;
-- If we get this far, the package options must match port options
return True;
end;
exception
when issue : others =>
LOG.obsolete_notice
(write_to_screen => debug_opt_check,
message => "option check exception" & LAT.LF & EX.Exception_Message (issue));
return False;
end passed_option_check;
--------------------------------------------------------------------------------------------
-- initial_package_scan
--------------------------------------------------------------------------------------------
procedure initial_package_scan (repository : String; id : port_id; subpackage : String)
is
procedure set_position (position : subpackage_crate.Cursor);
procedure set_delete (Element : in out subpackage_record);
procedure set_present (Element : in out subpackage_record);
procedure set_query (Element : in out subpackage_record);
subpackage_position : subpackage_crate.Cursor := subpackage_crate.No_Element;
query_result : HT.Text;
procedure set_position (position : subpackage_crate.Cursor)
is
rec : subpackage_record renames subpackage_crate.Element (position);
begin
if HT.USS (rec.subpackage) = subpackage then
subpackage_position := position;
end if;
end set_position;
procedure set_delete (Element : in out subpackage_record) is
begin
Element.deletion_due := True;
end set_delete;
procedure set_present (Element : in out subpackage_record) is
begin
Element.pkg_present := True;
end set_present;
procedure set_query (Element : in out subpackage_record) is
begin
Element.pkg_dep_query := query_result;
end set_query;
use type subpackage_crate.Cursor;
begin
if id = port_match_failed or else
not all_ports (id).scanned
then
return;
end if;
all_ports (id).subpackages.Iterate (set_position'Access);
if subpackage_position = subpackage_crate.No_Element then
return;
end if;
declare
pkgname : constant String := calculate_package_name (id, subpackage);
fullpath : constant String := repository & "/" & pkgname & arc_ext;
msg_opt : constant String := pkgname & " failed option check.";
msg_abi : constant String := pkgname & " failed architecture (ABI) check.";
begin
if DIR.Exists (fullpath) then
all_ports (id).subpackages.Update_Element (subpackage_position, set_present'Access);
else
return;
end if;
if not passed_option_check (repository, id, subpackage, True) then
LOG.obsolete_notice (msg_opt, True);
all_ports (id).subpackages.Update_Element (subpackage_position, set_delete'Access);
return;
end if;
if not passed_abi_check (repository, id, subpackage, True) then
LOG.obsolete_notice (msg_abi, True);
all_ports (id).subpackages.Update_Element (subpackage_position, set_delete'Access);
return;
end if;
end;
query_result := result_of_dependency_query (repository, id, subpackage);
all_ports (id).subpackages.Update_Element (subpackage_position, set_query'Access);
end initial_package_scan;
--------------------------------------------------------------------------------------------
-- remote_package_scan
--------------------------------------------------------------------------------------------
procedure remote_package_scan (id : port_id; subpackage : String)
is
procedure set_position (position : subpackage_crate.Cursor);
procedure set_remote_on (Element : in out subpackage_record);
procedure set_remote_off (Element : in out subpackage_record);
procedure set_query (Element : in out subpackage_record);
subpackage_position : subpackage_crate.Cursor := subpackage_crate.No_Element;
query_result : HT.Text;
procedure set_position (position : subpackage_crate.Cursor)
is
rec : subpackage_record renames subpackage_crate.Element (position);
begin
if HT.USS (rec.subpackage) = subpackage then
subpackage_position := position;
end if;
end set_position;
procedure set_remote_on (Element : in out subpackage_record) is
begin
Element.remote_pkg := True;
end set_remote_on;
procedure set_remote_off (Element : in out subpackage_record) is
begin
Element.remote_pkg := False;
end set_remote_off;
procedure set_query (Element : in out subpackage_record) is
begin
Element.pkg_dep_query := query_result;
end set_query;
use type subpackage_crate.Cursor;
begin
all_ports (id).subpackages.Iterate (set_position'Access);
if subpackage_position = subpackage_crate.No_Element then
return;
end if;
if passed_abi_check (repository => "",
id => id,
subpackage => subpackage,
skip_exist_check => True)
then
all_ports (id).subpackages.Update_Element (subpackage_position, set_remote_on'Access);
else
return;
end if;
if not passed_option_check (repository => "",
id => id,
subpackage => subpackage,
skip_exist_check => True)
then
all_ports (id).subpackages.Update_Element (subpackage_position, set_remote_off'Access);
return;
end if;
query_result := result_of_dependency_query ("", id, subpackage);
all_ports (id).subpackages.Update_Element (subpackage_position, set_query'Access);
end remote_package_scan;
--------------------------------------------------------------------------------------------
-- parallel_package_scan
--------------------------------------------------------------------------------------------
procedure parallel_package_scan
(repository : String;
remote_scan : Boolean;
show_progress : Boolean)
is
task type scan (lot : scanners);
finished : array (scanners) of Boolean := (others => False);
combined_wait : Boolean := True;
label_shown : Boolean := False;
aborted : Boolean := False;
task body scan
is
procedure populate (cursor : subqueue.Cursor);
procedure populate (cursor : subqueue.Cursor)
is
procedure check_subpackage (position : subpackage_crate.Cursor);
target_port : port_index := subqueue.Element (cursor);
important : constant Boolean := all_ports (target_port).scanned;
procedure check_subpackage (position : subpackage_crate.Cursor)
is
rec : subpackage_record renames subpackage_crate.Element (position);
subpackage : String := HT.USS (rec.subpackage);
begin
if not aborted and then important then
if remote_scan and then
not rec.never_remote
then
if not rec.pkg_present or else
rec.deletion_due
then
remote_package_scan (target_port, subpackage);
end if;
else
initial_package_scan (repository, target_port, subpackage);
end if;
end if;
end check_subpackage;
begin
all_ports (target_port).subpackages.Iterate (check_subpackage'Access);
mq_progress (lot) := mq_progress (lot) + 1;
end populate;
begin
make_queue (lot).Iterate (populate'Access);
finished (lot) := True;
end scan;
scan_01 : scan (lot => 1);
scan_02 : scan (lot => 2);
scan_03 : scan (lot => 3);
scan_04 : scan (lot => 4);
scan_05 : scan (lot => 5);
scan_06 : scan (lot => 6);
scan_07 : scan (lot => 7);
scan_08 : scan (lot => 8);
scan_09 : scan (lot => 9);
scan_10 : scan (lot => 10);
scan_11 : scan (lot => 11);
scan_12 : scan (lot => 12);
scan_13 : scan (lot => 13);
scan_14 : scan (lot => 14);
scan_15 : scan (lot => 15);
scan_16 : scan (lot => 16);
scan_17 : scan (lot => 17);
scan_18 : scan (lot => 18);
scan_19 : scan (lot => 19);
scan_20 : scan (lot => 20);
scan_21 : scan (lot => 21);
scan_22 : scan (lot => 22);
scan_23 : scan (lot => 23);
scan_24 : scan (lot => 24);
scan_25 : scan (lot => 25);
scan_26 : scan (lot => 26);
scan_27 : scan (lot => 27);
scan_28 : scan (lot => 28);
scan_29 : scan (lot => 29);
scan_30 : scan (lot => 30);
scan_31 : scan (lot => 31);
scan_32 : scan (lot => 32);
-- Expansion of cpu_range from 32 to 64 means 64 possible scanners
scan_33 : scan (lot => 33);
scan_34 : scan (lot => 34);
scan_35 : scan (lot => 35);
scan_36 : scan (lot => 36);
scan_37 : scan (lot => 37);
scan_38 : scan (lot => 38);
scan_39 : scan (lot => 39);
scan_40 : scan (lot => 40);
scan_41 : scan (lot => 41);
scan_42 : scan (lot => 42);
scan_43 : scan (lot => 43);
scan_44 : scan (lot => 44);
scan_45 : scan (lot => 45);
scan_46 : scan (lot => 46);
scan_47 : scan (lot => 47);
scan_48 : scan (lot => 48);
scan_49 : scan (lot => 49);
scan_50 : scan (lot => 50);
scan_51 : scan (lot => 51);
scan_52 : scan (lot => 52);
scan_53 : scan (lot => 53);
scan_54 : scan (lot => 54);
scan_55 : scan (lot => 55);
scan_56 : scan (lot => 56);
scan_57 : scan (lot => 57);
scan_58 : scan (lot => 58);
scan_59 : scan (lot => 59);
scan_60 : scan (lot => 60);
scan_61 : scan (lot => 61);
scan_62 : scan (lot => 62);
scan_63 : scan (lot => 63);
scan_64 : scan (lot => 64);
begin
while combined_wait loop
delay 1.0;
combined_wait := False;
for j in scanners'Range loop
if not finished (j) then
combined_wait := True;
exit;
end if;
end loop;
if combined_wait then
if not label_shown then
label_shown := True;
TIO.Put_Line ("Scanning existing packages.");
end if;
if show_progress then
TIO.Put (scan_progress);
end if;
if Signals.graceful_shutdown_requested then
aborted := True;
end if;
end if;
end loop;
end parallel_package_scan;
--------------------------------------------------------------------------------------------
-- initialize_web_report
--------------------------------------------------------------------------------------------
procedure initialize_web_report (num_builders : builders) is
idle_slaves : constant dim_builder_state := (others => idle);
reportdir : constant String := HT.USS (PM.configuration.dir_logs);
sharedir : constant String := host_localbase & "/share/ravenadm";
ravenlogo : constant String := "/raven-project.png";
favicon : constant String := "/favicon.png";
webjs : constant String := "/progress.js";
webcss : constant String := "/progress.css";
begin
DIR.Create_Path (reportdir);
DIR.Copy_File (sharedir & ravenlogo, reportdir & ravenlogo);
DIR.Copy_File (sharedir & favicon, reportdir & favicon);
DIR.Copy_File (sharedir & webjs, reportdir & webjs);
DIR.Copy_File (sharedir & webcss, reportdir & webcss);
DIR.Copy_File (sharedir & "/progress.html", reportdir & "/index.html");
write_summary_json (active => True,
states => idle_slaves,
num_builders => num_builders,
num_history_files => 0);
end initialize_web_report;
--------------------------------------------------------------------------------------------
-- write_summary_json
--------------------------------------------------------------------------------------------
procedure write_summary_json
(active : Boolean;
states : dim_builder_state;
num_builders : builders;
num_history_files : Natural)
is
function TF (value : Boolean) return Natural;
jsonfile : TIO.File_Type;
filename : constant String := HT.USS (PM.configuration.dir_logs) & "/summary.json";
leftover : constant Integer := LOG.ports_remaining_to_build;
slave : DPY.builder_rec;
function TF (value : Boolean) return Natural is
begin
if value then
return 1;
else
return 0;
end if;
end TF;
begin
TIO.Create (File => jsonfile, Mode => TIO.Out_File, Name => filename);
TIO.Put (jsonfile, "{" & LAT.LF &
" " & nv ("profile", HT.USS (PM.configuration.profile)) & LAT.LF);
TIO.Put
(jsonfile,
" ," & nv ("kickoff", LOG.www_timestamp_start_time) & LAT.LF &
" ," & nv ("kfiles", num_history_files) & LAT.LF &
" ," & nv ("active", TF (active)) & LAT.LF &
" ," & LAT.Quotation & "stats" & LAT.Quotation & LAT.Colon & "{" & LAT.LF);
TIO.Put
(jsonfile,
" " & nv ("queued", LOG.port_counter_value (total)) & LAT.LF &
" ," & nv ("built", LOG.port_counter_value (success)) & LAT.LF &
" ," & nv ("failed", LOG.port_counter_value (failure)) & LAT.LF &
" ," & nv ("ignored", LOG.port_counter_value (ignored)) & LAT.LF &
" ," & nv ("skipped", LOG.port_counter_value (skipped)) & LAT.LF &
" ," & nv ("remains", leftover) & LAT.LF &
" ," & nv ("elapsed", LOG.elapsed_now) & LAT.LF &
" ," & nv ("pkghour", LOG.hourly_build_rate) & LAT.LF &
" ," & nv ("impulse", LOG.impulse_rate) & LAT.LF &
" ," & nv ("swapinfo", DPY.fmtpc (get_swap_status, True)) & LAT.LF &
" ," & nv ("load", DPY.fmtload (CYC.load_core (True))) & LAT.LF &
" }" & LAT.LF &
" ," & LAT.Quotation & "builders" & LAT.Quotation & LAT.Colon & "[" & LAT.LF);
for b in builders'First .. num_builders loop
if states (b) = shutdown then
slave := CYC.builder_status (b, True, False);
elsif states (b) = idle then
slave := CYC.builder_status (b, False, True);
else
slave := CYC.builder_status (b);
end if;
if b = builders'First then
TIO.Put (jsonfile, " {" & LAT.LF);
else
TIO.Put (jsonfile, " ,{" & LAT.LF);
end if;
TIO.Put
(jsonfile,
" " & nv ("ID", slave.slavid) & LAT.LF &
" ," & nv ("elapsed", HT.trim (slave.Elapsed)) & LAT.LF &
" ," & nv ("phase", HT.trim (slave.phase)) & LAT.LF &
" ," & nv ("origin", HT.trim (slave.origin)) & LAT.LF &
" ," & nv ("lines", HT.trim (slave.LLines)) & LAT.LF &
" }" & LAT.LF);
end loop;
TIO.Put (jsonfile, " ]" & LAT.LF & "}" & LAT.LF);
TIO.Close (jsonfile);
exception
when others =>
if TIO.Is_Open (jsonfile) then
TIO.Close (jsonfile);
end if;
end write_summary_json;
--------------------------------------------------------------------------------------------
-- swapinfo_command
--------------------------------------------------------------------------------------------
function swapinfo_command return String is
begin
case platform_type is
when dragonfly | freebsd =>
return "/usr/sbin/swapinfo -k";
when netbsd | openbsd =>
return "/sbin/swapctl -lk";
when linux =>
return "/sbin/swapon --bytes --show=NAME,SIZE,USED,PRIO";
when sunos =>
return "/usr/sbin/swap -l";
when macos =>
return "/usr/bin/vm_stat";
end case;
end swapinfo_command;
--------------------------------------------------------------------------------------------
-- get_swap_status
--------------------------------------------------------------------------------------------
function get_swap_status return Float
is
type memtype is mod 2**64;
command : String := swapinfo_command;
status : Integer;
comres : HT.Text;
blocks_total : memtype := 0;
blocks_used : memtype := 0;
begin
if platform_type = macos then
-- MacOS has no limit, it will keep generating swapfiles as needed, so return 0.0
-- Anything divided by infinity is zero ...
return 0.0;
end if;
comres := Unix.piped_command (command, status);
if status /= 0 then
return 200.0; -- [ERROR] Signal to set swap display to "N/A"
end if;
-- Throw first line away, e.g "Device 1K-blocks Used Avail ..."
-- Distinguishes platforms though:
-- Net/Free/Dragon start with "Device"
-- Linux starts with "NAME"
-- Solaris starts with "swapfile"
-- On FreeBSD (DragonFly too?), when multiple swap used, ignore line starting "Total"
declare
command_result : String := HT.USS (comres);
markers : HT.Line_Markers;
line_present : Boolean;
oneline_total : memtype;
oneline_other : memtype;
begin
HT.initialize_markers (command_result, markers);
-- Throw first line away (valid for all platforms
line_present := HT.next_line_present (command_result, markers);
if line_present then
declare
line : String := HT.extract_line (command_result, markers);
begin
null;
end;
else
return 200.0; -- [ERROR] Signal to set swap display to "N/A"
end if;
case platform_type is
when freebsd | dragonfly | netbsd | openbsd | linux | sunos =>
-- Normally 1 swap line, but there is no limit
loop
exit when not HT.next_line_present (command_result, markers);
declare
line : constant String :=
HT.strip_excessive_spaces (HT.extract_line (command_result, markers));
begin
case platform_type is
when freebsd | dragonfly | netbsd | openbsd =>
if HT.specific_field (line, 1) /= "Total" then
blocks_total := blocks_total +
memtype'Value (HT.specific_field (line, 2));
blocks_used := blocks_used +
memtype'Value (HT.specific_field (line, 3));
end if;
when sunos =>
oneline_total := memtype'Value (HT.specific_field (line, 4));
oneline_other := memtype'Value (HT.specific_field (line, 5));
blocks_total := blocks_total + oneline_total;
blocks_used := blocks_used + (oneline_total - oneline_other);
when linux =>
blocks_total := blocks_total +
memtype'Value (HT.specific_field (line, 2));
blocks_used := blocks_used +
memtype'Value (HT.specific_field (line, 3));
when macos => null;
end case;
exception
when Constraint_Error =>
return 200.0; -- [ERROR] Signal to set swap display to "N/A"
end;
end loop;
when macos =>
null;
end case;
end;
if blocks_total = 0 then
return 200.0; -- Signal to set swap display to "N/A"
else
return 100.0 * Float (blocks_used) / Float (blocks_total);
end if;
end get_swap_status;
--------------------------------------------------------------------------------------------
-- initialize_display
--------------------------------------------------------------------------------------------
procedure initialize_display (num_builders : builders) is
begin
if PM.configuration.avec_ncurses then
curses_support := DPC.launch_monitor (num_builders);
end if;
end initialize_display;
--------------------------------------------------------------------------------------------
-- nothing_left
--------------------------------------------------------------------------------------------
function nothing_left (num_builders : builders) return Boolean
is
list_len : constant Integer := Integer (rank_queue.Length);
begin
return list_len = 0;
end nothing_left;
--------------------------------------------------------------------------------------------
-- shutdown_recommended
--------------------------------------------------------------------------------------------
function shutdown_recommended (active_builders : Positive) return Boolean
is
list_len : constant Natural := Integer (rank_queue.Length);
list_max : constant Positive := 2 * active_builders;
num_wait : Natural := 0;
cursor : ranking_crate.Cursor;
QR : queue_record;
begin
if list_len = 0 or else list_len >= list_max then
return False;
end if;
cursor := rank_queue.First;
for k in 1 .. list_len loop
QR := ranking_crate.Element (Position => cursor);
if not all_ports (QR.ap_index).work_locked then
num_wait := num_wait + 1;
if num_wait >= active_builders then
return False;
end if;
end if;
cursor := ranking_crate.Next (Position => cursor);
end loop;
return True;
end shutdown_recommended;
--------------------------------------------------------------------------------------------
-- lock_package
--------------------------------------------------------------------------------------------
procedure lock_package (id : port_id) is
begin
if id /= port_match_failed then
all_ports (id).work_locked := True;
end if;
end lock_package;
--------------------------------------------------------------------------------------------
-- top_buildable_port
--------------------------------------------------------------------------------------------
function top_buildable_port return port_id
is
list_len : constant Integer := Integer (rank_queue.Length);
cursor : ranking_crate.Cursor;
QR : queue_record;
result : port_id := port_match_failed;
begin
if list_len = 0 then
return result;
end if;
cursor := rank_queue.First;
for k in 1 .. list_len loop
QR := ranking_crate.Element (Position => cursor);
if not all_ports (QR.ap_index).work_locked and then
all_ports (QR.ap_index).blocked_by.Is_Empty
then
result := QR.ap_index;
exit;
end if;
cursor := ranking_crate.Next (Position => cursor);
end loop;
if Signals.graceful_shutdown_requested then
return port_match_failed;
end if;
return result;
end top_buildable_port;
--------------------------------------------------------------------------------------------
-- parse_and_transform_buildsheet
--------------------------------------------------------------------------------------------
procedure parse_and_transform_buildsheet
(specification : in out Port_Specification.Portspecs;
successful : out Boolean;
buildsheet : String;
variant : String;
portloc : String;
excl_targets : Boolean;
avoid_dialog : Boolean;
for_webpage : Boolean;
sysrootver : sysroot_characteristics)
is
function read_option_file return Boolean;
function launch_and_read (optfile, cookie : String) return Boolean;
makefile : String := portloc & "/Makefile";
dir_opt : constant String := HT.USS (PM.configuration.dir_options);
function read_option_file return Boolean
is
result : Boolean := True;
required : Natural := specification.get_list_length (Port_Specification.sp_opts_standard);
begin
IFM.scan_file (directory => dir_opt, filename => specification.get_namebase);
declare
list : constant String := IFM.show_value (section => "parameters",
name => "available");
num_opt : Natural := HT.count_char (list, LAT.Comma) + 1;
begin
if num_opt /= required then
result := False;
end if;
for item in 1 .. num_opt loop
declare
setting : Boolean;
good : Boolean := True;
nv_name : String := HT.specific_field (list, item, ",");
nv_value : String := IFM.show_value ("options", nv_name);
begin
if nv_value = "true" then
setting := True;
elsif nv_value = "false" then
setting := False;
else
good := False;
result := False;
end if;
if good then
if specification.option_exists (nv_name) then
PST.define_option_setting (specification, nv_name, setting);
else
result := False;
end if;
end if;
end;
end loop;
end;
return result;
exception
when others =>
return False;
end read_option_file;
function launch_and_read (optfile, cookie : String) return Boolean is
begin
PST.set_option_to_default_values (specification);
if not avoid_dialog then
if not DLG.launch_dialog (specification) then
return False;
end if;
if DIR.Exists (cookie) then
-- We keep the already-set standard option settings
return True;
end if;
if not DIR.Exists (optfile) then
TIO.Put_Line ("Saved option file and cookie missing after dialog executed. bug?");
return False;
end if;
if not read_option_file then
TIO.Put_Line ("Saved option file invalid after dialog executed. bug?");
return False;
end if;
end if;
return True;
end launch_and_read;
begin
PAR.parse_specification_file (dossier => buildsheet,
spec => specification,
opsys_focus => platform_type,
arch_focus => sysrootver.arch,
success => successful,
stop_at_targets => excl_targets,
extraction_dir => portloc);
if not successful then
TIO.Put_Line ("Failed to parse " & buildsheet);
TIO.Put_Line (specification.get_parse_error);
return;
end if;
if not specification.variant_exists (variant) then
TIO.Put_Line ("The specified variant '" & variant & "' is invalid.");
TIO.Put_Line ("Try again with a valid variant");
successful := False;
return;
end if;
PST.set_option_defaults
(specs => specification,
variant => variant,
opsys => platform_type,
arch_standard => sysrootver.arch,
osrelease => HT.USS (sysrootver.release));
-- If no available options, skip (remember, if variants there are ALWAYS options
-- otherwise
-- if batch mode, ignore cookies. if no option file, use default values.
-- if not batch mode:
-- If option file, use it.
-- if no option file: if cookie exists, used default values, otherwise show dialog
declare
optfile : constant String := dir_opt & "/" & specification.get_namebase;
cookie : constant String := dir_opt & "/defconf_cookies/" & specification.get_namebase;
begin
if variant = variant_standard then
if specification.standard_options_present then
-- This port has at least one user-definable option
if PM.configuration.batch_mode then
-- In batch mode, option settings are optional. Use default values if not set
if DIR.Exists (optfile) then
if not read_option_file then
TIO.Put_Line ("BATCH MODE ERROR: Invalid option configuration of " &
specification.get_namebase & ":standard port");
TIO.Put_Line ("Run ravenadm set-options " & specification.get_namebase &
" to rectify the issue");
TIO.Put_Line ("Alternatively, set configuration option '[Q] Assume " &
"default options' to False");
successful := False;
return;
end if;
else
PST.set_option_to_default_values (specification);
end if;
else
if DIR.Exists (optfile) then
if not read_option_file then
if not launch_and_read (optfile, cookie) then
successful := False;
return;
end if;
end if;
else
if DIR.Exists (cookie) then
PST.set_option_to_default_values (specification);
else
if not launch_and_read (optfile, cookie) then
successful := False;
return;
end if;
end if;
end if;
end if;
end if;
else
-- All defined options are dedicated to variant definition (nothing to configure)
PST.set_option_to_default_values (specification);
end if;
end;
if for_webpage then
specification.do_not_apply_opsys_dependencies;
end if;
PST.apply_directives
(specs => specification,
variant => variant,
arch_standard => sysrootver.arch,
osmajor => HT.USS (sysrootver.major));
PST.set_outstanding_ignore
(specs => specification,
variant => variant,
opsys => platform_type,
arch_standard => sysrootver.arch,
osrelease => HT.USS (sysrootver.release),
osmajor => HT.USS (sysrootver.major));
if portloc /= "" then
PST.shift_extra_patches
(specs => specification,
extract_dir => portloc);
PSM.generator
(specs => specification,
variant => variant,
opsys => platform_type,
arch => sysrootver.arch,
output_file => makefile);
end if;
end parse_and_transform_buildsheet;
--------------------------------------------------------------------------------------------
-- build_subpackages
--------------------------------------------------------------------------------------------
function build_subpackages
(builder : builders;
sequence_id : port_id;
sysrootver : sysroot_characteristics;
interactive : Boolean := False;
enterafter : String := "") return Boolean
is
function get_buildsheet return String;
namebase : String := HT.USS (all_ports (sequence_id).port_namebase);
variant : String := HT.USS (all_ports (sequence_id).port_variant);
bucket : String := all_ports (sequence_id).bucket;
portloc : String := HT.USS (PM.configuration.dir_buildbase) &
"/" & REP.slave_name (builder) & "/port";
function get_buildsheet return String
is
buckname : constant String := "/bucket_" & bucket & "/" & namebase;
begin
if all_ports (sequence_id).unkind_custom then
return HT.USS (PM.configuration.dir_profile) & "/unkindness" & buckname;
else
return HT.USS (PM.configuration.dir_conspiracy) & buckname;
end if;
end get_buildsheet;
buildsheet : constant String := get_buildsheet;
specification : Port_Specification.Portspecs;
successful : Boolean;
begin
parse_and_transform_buildsheet (specification => specification,
successful => successful,
buildsheet => buildsheet,
variant => variant,
portloc => portloc,
excl_targets => False,
avoid_dialog => True,
for_webpage => False,
sysrootver => sysrootver);
if not successful then
return False;
end if;
return CYC.build_package (id => builder,
specification => specification,
sequence_id => sequence_id,
interactive => interactive,
interphase => enterafter);
end build_subpackages;
--------------------------------------------------------------------------------------------
-- eliminate_obsolete_packages
--------------------------------------------------------------------------------------------
procedure eliminate_obsolete_packages
is
procedure search (position : subpackage_crate.Cursor);
procedure kill (position : string_crate.Cursor);
id : port_index;
counter : Natural := 0;
repo : constant String := HT.USS (PM.configuration.dir_repository) & "/";
procedure search (position : subpackage_crate.Cursor)
is
rec : subpackage_record renames subpackage_crate.Element (position);
subpackage : constant String := HT.USS (rec.subpackage);
package_name : HT.Text := HT.SUS (calculate_package_name (id, subpackage) & arc_ext);
begin
if package_list.Contains (package_name) then
package_list.Delete (package_list.Find_Index (package_name));
end if;
end search;
procedure kill (position : string_crate.Cursor)
is
package_name : constant String := HT.USS (string_crate.Element (position));
begin
DIR.Delete_File (repo & package_name);
counter := counter + 1;
exception
when others =>
TIO.Put (LAT.LF & "Failed to remove " & package_name);
end kill;
begin
for index in port_index'First .. last_port loop
id := index;
all_ports (index).subpackages.Iterate (search'Access);
end loop;
TIO.Put ("Removing obsolete packages ... ");
package_list.Iterate (kill'Access);
TIO.Put_Line ("done! (packages deleted: " & HT.int2str (counter) & ")");
end eliminate_obsolete_packages;
end PortScan.Operations;
|
package body Node is
procedure SleepForSomeTime (maxSleep: Natural) is
gen: RAF.Generator;
fraction: Float;
begin
RAF.Reset(gen);
fraction := 1.0 / Float(maxSleep);
delay Duration(fraction * RAF.Random(gen));
end SleepForSomeTime;
task body NodeTask is
target: pNodeObj;
neighbours: pArray_pNodeObj;
stash: pMessage;
exitTask: Boolean := False;
begin
loop
select
accept SendMessage(message: in pMessage) do
logger.LogMessageInTransit(message.all.content, self.all.id);
SleepForSomeTime(maxSleep);
stash := message;
if isLast then
-- allow receiving the message only if the node is the ending node
accept ReceiveMessage(message: out pMessage) do
-- hand over the message
message := stash;
stash := null;
end ReceiveMessage;
end if;
end SendMessage;
or
accept Stop do
SleepForSomeTime(maxSleep);
exitTask := True;
end Stop;
else
SleepForSomeTime(maxSleep);
end select;
if stash /= null then
neighbours := self.all.neighbours;
target := neighbours.all(RAD.Next(neighbours'Length));
target.all.nodeTask.all.SendMessage(stash);
stash := null;
end if;
if exitTask then
exit;
end if;
end loop;
end NodeTask;
end Node;
|
-- { dg-do run }
-- { dg-options "-O2 -fno-inline" }
procedure Opt2 is
function Get return String is
begin
return "[]";
end Get;
Message : String := Get;
F, L : Integer;
begin
for J in Message'Range loop
if Message (J) = '[' then
F := J;
elsif Message (J) = ']' then
L := J;
exit;
end if;
end loop;
declare
M : String :=
Message (Message'First .. F) & Message (L .. Message'Last);
begin
if M /= "[]" then
raise Program_Error;
end if;
end;
end;
|
with Ada.Containers; use Ada.Containers;
with Ada.Directories; use Ada.Directories;
with Blueprint; use Blueprint;
with AAA.Strings; use AAA.Strings;
with Ada.Text_IO;
with Ada.Command_Line;
with Templates_Parser;
with CLIC.TTY;
with Filesystem;
with Commands;
package body Commands.Generate is
package IO renames Ada.Text_IO;
package TT renames CLIC.TTY;
-------------
-- Execute --
-------------
overriding
procedure Execute ( Cmd : in out Command;
Args : AAA.Strings.Vector) is
begin
if Args.Length > 1 then
declare
Name : String := Element (Args, 2);
Blueprint : String := Args.First_Element;
Blueprint_Path : String := Compose(Get_Blueprint_Folder,Blueprint);
Current : String := Current_Directory;
ToDo : Action := Write;
begin
if Cmd.Dry_Run then
IO.Put_Line(TT.Emph("You specified the dry-run flag, so no changes will be written."));
ToDo := DryRun;
end if;
Templates_Parser.Insert
(Commands.Translations, Templates_Parser.Assoc ("NAME", Name));
if Exists (Blueprint_Path) then
Iterate (Blueprint_Path, Current, ToDo);
IO.Put_Line (TT.Success( "Successfully generated " & Blueprint) & " " & TT.Warn (TT.Bold (Name)));
else
IO.Put_Line (TT.Error("Blueprint" & " " & Blueprint_Path & " " & "not found"));
end if;
end;
else
IO.Put_Line(TT.Error("Command requires a blueprint and a name to be specified."));
end if;
end Execute;
overriding
function Long_Description(Cmd : Command) return AAA.Strings.Vector is
Description : AAA.Strings.Vector := AAA.Strings.Empty_Vector;
Blueprints : AAA.Strings.Vector := Filesystem.Read_Directory(Get_Blueprint_Folder, false);
begin
Append(Description, TT.Description("Generates new code from blueprints."));
Description.New_Line;
Description.Append(TT.Underline("Available blueprints"));
for A_Blueprint of Blueprints loop
Append(Description, TT.Emph (A_Blueprint));
end loop;
return Description;
end Long_Description;
--------------------
-- Setup_Switches --
--------------------
overriding
procedure Setup_Switches
(Cmd : in out Command;
Config : in out CLIC.Subcommand.Switches_Configuration)
is
use CLIC.Subcommand;
begin
Define_Switch
(Config, Cmd.Dry_Run'Access, "", "-dry-run", "Dry-run");
end Setup_Switches;
end Commands.Generate;
|
with datos; use datos;
procedure actualizar (
L : in out Lista;
i : in Integer;
Cantidad : in Integer ) is
begin
end actualizar;
|
with Ada.Text_IO;
-- reuse Is_Prime from [[Primality by Trial Division]]
with Is_Prime;
procedure Mersenne is
function Is_Set (Number : Natural; Bit : Positive) return Boolean is
begin
return Number / 2 ** (Bit - 1) mod 2 = 1;
end Is_Set;
function Get_Max_Bit (Number : Natural) return Natural is
Test : Natural := 0;
begin
while 2 ** Test <= Number loop
Test := Test + 1;
end loop;
return Test;
end Get_Max_Bit;
function Modular_Power (Base, Exponent, Modulus : Positive) return Natural is
Maximum_Bit : constant Natural := Get_Max_Bit (Exponent);
Square : Natural := 1;
begin
for Bit in reverse 1 .. Maximum_Bit loop
Square := Square ** 2;
if Is_Set (Exponent, Bit) then
Square := Square * Base;
end if;
Square := Square mod Modulus;
end loop;
return Square;
end Modular_Power;
Not_A_Prime_Exponent : exception;
function Get_Factor (Exponent : Positive) return Natural is
Factor : Positive;
begin
if not Is_Prime (Exponent) then
raise Not_A_Prime_Exponent;
end if;
for K in 1 .. 16384 / Exponent loop
Factor := 2 * K * Exponent + 1;
if Factor mod 8 = 1 or else Factor mod 8 = 7 then
if Is_Prime (Factor) and then Modular_Power (2, Exponent, Factor) = 1 then
return Factor;
end if;
end if;
end loop;
return 0;
end Get_Factor;
To_Test : constant Positive := 929;
Factor : Natural;
begin
Ada.Text_IO.Put ("2 **" & Integer'Image (To_Test) & " - 1 ");
begin
Factor := Get_Factor (To_Test);
if Factor = 0 then
Ada.Text_IO.Put_Line ("is prime.");
else
Ada.Text_IO.Put_Line ("has factor" & Integer'Image (Factor));
end if;
exception
when Not_A_Prime_Exponent =>
Ada.Text_IO.Put_Line ("is not a Mersenne number");
end;
end Mersenne;
|
-----------------------------------------------------------------------
-- html-pages -- HTML Page Components
-- Copyright (C) 2011, 2014 Stephane Carrez
-- Written by Stephane Carrez (Stephane.Carrez@gmail.com)
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
with Util.Strings;
with Util.Beans.Objects;
with ASF.Utils;
-- The <b>Pages</b> package implements various components used when building an HTML page.
--
package body ASF.Components.Html.Pages is
BODY_ATTRIBUTE_NAMES : Util.Strings.String_Set.Set;
HEAD_ATTRIBUTE_NAMES : Util.Strings.String_Set.Set;
-- ------------------------------
-- Head Component
-- ------------------------------
-- ------------------------------
-- Encode the HTML head element.
-- ------------------------------
overriding
procedure Encode_Begin (UI : in UIHead;
Context : in out Contexts.Faces.Faces_Context'Class) is
Writer : constant Response_Writer_Access := Context.Get_Response_Writer;
begin
Writer.Start_Element ("head");
UI.Render_Attributes (Context, HEAD_ATTRIBUTE_NAMES, Writer);
end Encode_Begin;
-- ------------------------------
-- Terminate the HTML head element. Before closing the head, generate the resource
-- links that have been queued for the head generation.
-- ------------------------------
overriding
procedure Encode_End (UI : in UIHead;
Context : in out Contexts.Faces.Faces_Context'Class) is
pragma Unreferenced (UI);
Writer : constant Response_Writer_Access := Context.Get_Response_Writer;
begin
Writer.Write_Scripts;
Writer.End_Element ("head");
end Encode_End;
-- ------------------------------
-- Encode the HTML body element.
-- ------------------------------
overriding
procedure Encode_Begin (UI : in UIBody;
Context : in out Contexts.Faces.Faces_Context'Class) is
Writer : constant Response_Writer_Access := Context.Get_Response_Writer;
begin
Writer.Start_Element ("body");
UI.Render_Attributes (Context, BODY_ATTRIBUTE_NAMES, Writer);
end Encode_Begin;
-- ------------------------------
-- Terminate the HTML body element. Before closing the body, generate the inclusion
-- of differed resources (pending javascript, inclusion of javascript files)
-- ------------------------------
overriding
procedure Encode_End (UI : in UIBody;
Context : in out Contexts.Faces.Faces_Context'Class) is
pragma Unreferenced (UI);
Writer : constant Response_Writer_Access := Context.Get_Response_Writer;
begin
Writer.Write_Scripts;
Writer.End_Element ("body");
end Encode_End;
-- ------------------------------
-- Encode the DOCTYPE element.
-- ------------------------------
overriding
procedure Encode_Begin (UI : in UIDoctype;
Context : in out Contexts.Faces.Faces_Context'Class) is
Writer : constant Response_Writer_Access := Context.Get_Response_Writer;
begin
if UI.Is_Rendered (Context) then
Writer.Write ("<!DOCTYPE ");
Writer.Write (UI.Get_Attribute ("rootElement", Context, ""));
declare
Public : constant Util.Beans.Objects.Object := UI.Get_Attribute (Context, "public");
System : constant Util.Beans.Objects.Object := UI.Get_Attribute (Context, "system");
begin
if not Util.Beans.Objects.Is_Null (Public) then
Writer.Write (" PUBLIC """);
Writer.Write (Public);
Writer.Write ('"');
end if;
if not Util.Beans.Objects.Is_Null (System) then
Writer.Write (" """);
Writer.Write (System);
Writer.Write ('"');
end if;
end;
Writer.Write ('>');
Writer.Write (ASCII.LF);
end if;
end Encode_Begin;
begin
Utils.Set_Head_Attributes (HEAD_ATTRIBUTE_NAMES);
Utils.Set_Text_Attributes (BODY_ATTRIBUTE_NAMES);
Utils.Set_Body_Attributes (BODY_ATTRIBUTE_NAMES);
end ASF.Components.Html.Pages;
|
package FLTK.Widgets.Groups.Spinners is
type Spinner is new Group with private;
type Spinner_Reference (Data : not null access Spinner'Class) is limited null record
with Implicit_Dereference => Data;
type Spinner_Kind is (Float_Spin, Int_Spin);
package Forge is
function Create
(X, Y, W, H : in Integer;
Text : in String)
return Spinner;
end Forge;
function Get_Background_Color
(This : in Spinner)
return Color;
procedure Set_Background_Color
(This : in out Spinner;
To : in Color);
function Get_Selection_Color
(This : in Spinner)
return Color;
procedure Set_Selection_Color
(This : in out Spinner;
To : in Color);
function Get_Text_Color
(This : in Spinner)
return Color;
procedure Set_Text_Color
(This : in out Spinner;
To : in Color);
function Get_Text_Font
(This : in Spinner)
return Font_Kind;
procedure Set_Text_Font
(This : in out Spinner;
To : in Font_Kind);
function Get_Text_Size
(This : in Spinner)
return Font_Size;
procedure Set_Text_Size
(This : in out Spinner;
To : in Font_Size);
function Get_Minimum
(This : in Spinner)
return Long_Float;
procedure Set_Minimum
(This : in out Spinner;
To : in Long_Float);
function Get_Maximum
(This : in Spinner)
return Long_Float;
procedure Set_Maximum
(This : in out Spinner;
To : in Long_Float);
procedure Get_Range
(This : in Spinner;
Min, Max : out Long_Float);
procedure Set_Range
(This : in out Spinner;
Min, Max : in Long_Float);
function Get_Step
(This : in Spinner)
return Long_Float;
procedure Set_Step
(This : in out Spinner;
To : in Long_Float);
function Get_Type
(This : in Spinner)
return Spinner_Kind;
procedure Set_Type
(This : in out Spinner;
To : in Spinner_Kind);
function Get_Value
(This : in Spinner)
return Long_Float;
procedure Set_Value
(This : in out Spinner;
To : in Long_Float);
procedure Draw
(This : in out Spinner);
function Handle
(This : in out Spinner;
Event : in Event_Kind)
return Event_Outcome;
private
type Spinner is new Group with null record;
overriding procedure Finalize
(This : in out Spinner);
pragma Inline (Get_Background_Color);
pragma Inline (Set_Background_Color);
pragma Inline (Get_Selection_Color);
pragma Inline (Set_Selection_Color);
pragma Inline (Get_Text_Color);
pragma Inline (Set_Text_Color);
pragma Inline (Get_Text_Font);
pragma Inline (Set_Text_Font);
pragma Inline (Get_Text_Size);
pragma Inline (Set_Text_Size);
pragma Inline (Get_Minimum);
pragma Inline (Set_Minimum);
pragma Inline (Get_Maximum);
pragma Inline (Set_Maximum);
pragma Inline (Set_Range);
pragma Inline (Get_Step);
pragma Inline (Set_Step);
pragma Inline (Get_Type);
pragma Inline (Set_Type);
pragma Inline (Get_Value);
pragma Inline (Set_Value);
pragma Inline (Draw);
pragma Inline (Handle);
end FLTK.Widgets.Groups.Spinners;
|
with Swaps; use Swaps;
with Ada.Text_IO;
with Sorts; use Sorts;
procedure Main is
V1 : Integer := 42;
V2 : Integer := 43;
T : Integer_List := (2, 7, 1, 9, 40, -1);
begin
Display_List (T);
Sort(T);
Display_List (T);
Ada.Text_IO.Put_Line ("V1 :=" & Integer'Image (V1) &
" V2 :=" & Integer'Image (V2));
Swap (V1, V2);
Ada.Text_IO.Put_Line ("V1 :=" & Integer'Image (V1) &
" V2 :=" & Integer'Image (V2));
end Main;
|
with Predictor_2;
with Text_IO; use Text_IO;
with Orbit_2;
procedure predictor_2_demo_2 is
type Real is digits 15;
package One_Electron_Atom is new Orbit_2 (Real);
use One_Electron_Atom;
package Orb_Integrate is new
Predictor_2 (Real, Dyn_Index, Dynamical_Variable, F, "*", "+", "-");
use Orb_Integrate;
package rio is new Float_IO(Real);
use rio;
package iio is new Integer_IO(Integer);
use iio;
Initial_Y, Initial_Y_dot : Dynamical_Variable;
Previous_Y, Final_Y : Dynamical_Variable;
Previous_Y_dot, Final_Y_dot : Dynamical_Variable;
Final_Time, Starting_Time : Real;
Previous_t, Final_t : Real;
Delta_t : Real;
Initial_Energy : Real;
Steps : Real := 128.0;
begin
-- choose initial conditions
new_line;
put ("The test calculates the trajectory of a body in a circular orbit.");
new_line(2);
put ("Enter number of time steps (try 512): ");
get (Steps);
new_line;
put ("Every time the integration advances this no of steps, ERROR is printed.");
new_line;
Initial_Y(0) := 0.0; -- x
Initial_Y(1) := 1.0; -- z
--Initial_Y_dot(0) := 2.0; -- circular orbit, x_dot
Initial_Y_dot(0) := 1.8; -- near circular orbit, x_dot
Initial_Y_dot(1) := 0.0; -- z_dot
Starting_Time := 0.0;
--Final_Time := 3.14159_26535_89793_23846 * 10.0; --10 orbits, if orbit circular.
Final_Time := 32.0;
Initial_Energy := Energy (Initial_Y, Initial_Y_dot);
Previous_Y := Initial_Y;
Previous_Y_dot := Initial_Y_dot;
Previous_t := Starting_Time;
Delta_t := Final_Time - Starting_Time;
for i in 1..30 loop
Final_t := Previous_t + Delta_t;
Integrate
(Final_Y => Final_Y, -- the result (output).
Final_deriv_Of_Y => Final_Y_dot,
Final_Time => Final_t, -- integrate out to here (input).
Initial_Y => Previous_Y, -- input an initial condition (input).
Initial_deriv_Of_Y => Previous_Y_dot,
Initial_Time => Previous_t, -- start integrating here (input).
No_Of_Steps => Steps); -- use this no_of_steps
Previous_Y := Final_Y;
Previous_Y_dot := Final_Y_dot;
Previous_t := Final_t;
put ("Time = t =");
put (Final_t, Aft => 7);
new_line;
put ("(True Energy - Integrated Energy) = ");
put (Abs (Initial_Energy - Energy (Final_Y, Final_Y_dot)), Aft => 7);
--put (", (x - Integrated x) = "); -- need to integrate integer no of orbits.
--put (Abs (0.0 - Final_Y(0)), Aft => 7);
new_line;
end loop;
end;
|
with Ada.Calendar.Arithmetic;
with Ada.Text_IO;
with Ada.Integer_Text_IO;
with Ada.Strings.Unbounded;
with Ada.Strings.Unbounded.Text_IO;
with Ada.Command_Line;
procedure Discordian is
use Ada.Calendar;
use Ada.Strings.Unbounded;
use Ada.Command_Line;
package UStr_IO renames Ada.Strings.Unbounded.Text_IO;
subtype Year_Number is Integer range 3067 .. 3565;
type Seasons is (Chaos, Discord, Confusion, Bureaucracy, The_Aftermath);
type Days_Of_Week is (Sweetmorn, Boomtime, Pungenday,
Prickle_Prickle, Setting_Orange);
subtype Day_Number is Integer range 1 .. 73;
type Discordian_Date is record
Year : Year_Number;
Season : Seasons;
Day : Day_Number;
Week_Day : Days_Of_Week;
Is_Tibs_Day : Boolean := False;
end record;
function Week_Day_To_Str(Day : Days_Of_Week) return Unbounded_String is
s : Unbounded_String;
begin
case Day is
when Sweetmorn => s := To_Unbounded_String("Sweetmorn");
when Boomtime => s := To_Unbounded_String("Boomtime");
when Pungenday => s := To_Unbounded_String("Pungenday");
when Prickle_Prickle => s := To_Unbounded_String("Prickle-Prickle");
when Setting_Orange => s := To_Unbounded_String("Setting Orange");
end case;
return s;
end Week_Day_To_Str;
function Holiday(Season: Seasons) return Unbounded_String is
s : Unbounded_String;
begin
case Season is
when Chaos => s := To_Unbounded_String("Chaoflux");
when Discord => s := To_Unbounded_String("Discoflux");
when Confusion => s := To_Unbounded_String("Confuflux");
when Bureaucracy => s := To_Unbounded_String("Bureflux");
when The_Aftermath => s := To_Unbounded_String("Afflux");
end case;
return s;
end Holiday;
function Apostle(Season: Seasons) return Unbounded_String is
s : Unbounded_String;
begin
case Season is
when Chaos => s := To_Unbounded_String("Mungday");
when Discord => s := To_Unbounded_String("Mojoday");
when Confusion => s := To_Unbounded_String("Syaday");
when Bureaucracy => s := To_Unbounded_String("Zaraday");
when The_Aftermath => s := To_Unbounded_String("Maladay");
end case;
return s;
end Apostle;
function Season_To_Str(Season: Seasons) return Unbounded_String is
s : Unbounded_String;
begin
case Season is
when Chaos => s := To_Unbounded_String("Chaos");
when Discord => s := To_Unbounded_String("Discord");
when Confusion => s := To_Unbounded_String("Confusion");
when Bureaucracy => s := To_Unbounded_String("Bureaucracy");
when The_Aftermath => s := To_Unbounded_String("The Aftermath");
end case;
return s;
end Season_To_Str;
procedure Convert (From : Time; To : out Discordian_Date) is
use Ada.Calendar.Arithmetic;
First_Day : Time;
Number_Days : Day_Count;
Leap_Year : boolean;
begin
First_Day := Time_Of (Year => Year (From), Month => 1, Day => 1);
Number_Days := From - First_Day;
To.Year := Year (Date => From) + 1166;
To.Is_Tibs_Day := False;
Leap_Year := False;
if Year (Date => From) mod 4 = 0 then
if Year (Date => From) mod 100 = 0 then
if Year (Date => From) mod 400 = 0 then
Leap_Year := True;
end if;
else
Leap_Year := True;
end if;
end if;
if Leap_Year then
if Number_Days > 59 then
Number_Days := Number_Days - 1;
elsif Number_Days = 59 then
To.Is_Tibs_Day := True;
end if;
end if;
To.Day := Day_Number (Number_Days mod 73 + 1);
case Number_Days / 73 is
when 0 => To.Season := Chaos;
when 1 => To.Season := Discord;
when 2 => To.Season := Confusion;
when 3 => To.Season := Bureaucracy;
when 4 => To.Season := The_Aftermath;
when others => raise Constraint_Error;
end case;
case Number_Days mod 5 is
when 0 => To.Week_Day := Sweetmorn;
when 1 => To.Week_Day := Boomtime;
when 2 => To.Week_Day := Pungenday;
when 3 => To.Week_Day := Prickle_Prickle;
when 4 => To.Week_Day := Setting_Orange;
when others => raise Constraint_Error;
end case;
end Convert;
procedure Put (Item : Discordian_Date) is
begin
if Item.Is_Tibs_Day then
Ada.Text_IO.Put ("St. Tib's Day");
else
UStr_IO.Put (Week_Day_To_Str(Item.Week_Day));
Ada.Text_IO.Put (", day" & Integer'Image (Item.Day));
Ada.Text_IO.Put (" of ");
UStr_IO.Put (Season_To_Str (Item.Season));
if Item.Day = 5 then
Ada.Text_IO.Put (", ");
UStr_IO.Put (Apostle(Item.Season));
elsif Item.Day = 50 then
Ada.Text_IO.Put (", ");
UStr_IO.Put (Holiday(Item.Season));
end if;
end if;
Ada.Text_IO.Put (" in the YOLD" & Integer'Image (Item.Year));
Ada.Text_IO.New_Line;
end Put;
Test_Day : Time;
Test_DDay : Discordian_Date;
Year : Integer;
Month : Integer;
Day : Integer;
YYYYMMDD : Integer;
begin
if Argument_Count = 0 then
Test_Day := Clock;
Convert (From => Test_Day, To => Test_DDay);
Put (Test_DDay);
end if;
for Arg in 1..Argument_Count loop
if Argument(Arg)'Length < 8 then
Ada.Text_IO.Put("ERROR: Invalid Argument : '" & Argument(Arg) & "'");
Ada.Text_IO.Put("Input format YYYYMMDD");
raise Constraint_Error;
end if;
begin
YYYYMMDD := Integer'Value(Argument(Arg));
exception
when Constraint_Error =>
Ada.Text_IO.Put("ERROR: Invalid Argument : '" & Argument(Arg) & "'");
raise;
end;
Day := YYYYMMDD mod 100;
if Day < Day_Number'First or Day > Day_Number'Last then
Ada.Text_IO.Put("ERROR: Invalid Day:" & Integer'Image(Day));
raise Constraint_Error;
end if;
Month := ((YYYYMMDD - Day) / 100) mod 100;
if Month < Month_Number'First or Month > Month_Number'Last then
Ada.Text_IO.Put("ERROR: Invalid Month:" & Integer'Image(Month));
raise Constraint_Error;
end if;
Year := ((YYYYMMDD - Day - Month * 100) / 10000);
if Year < 1901 or Year > 2399 then
Ada.Text_IO.Put("ERROR: Invalid Year:" & Integer'Image(Year));
raise Constraint_Error;
end if;
Test_Day := Time_Of (Year => Year, Month => Month, Day => Day);
Convert (From => Test_Day, To => Test_DDay);
Put (Test_DDay);
end loop;
end Discordian;
|
with Test1; use Test1;
package Test2 is
Str: string(Ask_Twice'range) := Ask_Twice;
end Test2;
|
-----------------------------------------------------------------------
-- html -- ASF HTML Components
-- Copyright (C) 2009, 2010, 2011, 2012 Stephane Carrez
-- Written by Stephane Carrez (Stephane.Carrez@gmail.com)
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
package body ASF.Utils is
TITLE_ATTR : aliased constant String := "title";
STYLE_ATTR : aliased constant String := "style";
STYLE_CLASS_ATTR : aliased constant String := "styleClass";
DIR_ATTR : aliased constant String := "dir";
LANG_ATTR : aliased constant String := "lang";
ACCESS_KEY_ATTR : aliased constant String := "accesskey";
ON_BLUR_ATTR : aliased constant String := "onblur";
ON_CLICK_ATTR : aliased constant String := "onclick";
ON_DBLCLICK_ATTR : aliased constant String := "ondblclick";
ON_FOCUS_ATTR : aliased constant String := "onfocus";
ON_KEYDOWN_ATTR : aliased constant String := "onkeydown";
ON_KEYUP_ATTR : aliased constant String := "onkeyup";
ON_MOUSE_DOWN_ATTR : aliased constant String := "onmousedown";
ON_MOUSE_MOVE_ATTR : aliased constant String := "onmousemove";
ON_MOUSE_OUT_ATTR : aliased constant String := "onmouseout";
ON_MOUSE_OVER_ATTR : aliased constant String := "onmouseover";
ON_MOUSE_UP_ATTR : aliased constant String := "onmouseup";
ON_CHANGE_ATTR : aliased constant String := "onchange";
ON_RESET_ATTR : aliased constant String := "onreset";
ON_SUBMIT_ATTR : aliased constant String := "onsubmit";
ENCTYPE_ATTR : aliased constant String := "enctype";
ON_LOAD_ATTR : aliased constant String := "onload";
ON_UNLOAD_ATTR : aliased constant String := "onunload";
TABINDEX_ATTR : aliased constant String := "tabindex";
AUTOCOMPLETE_ATTR : aliased constant String := "autocomplete";
SIZE_ATTR : aliased constant String := "size";
MAXLENGTH_ATTR : aliased constant String := "maxlength";
ALT_ATTR : aliased constant String := "alt";
DISABLED_ATTR : aliased constant String := "disabled";
READONLY_ATTR : aliased constant String := "readonly";
ACCEPT_ATTR : aliased constant String := "accept";
ROWS_ATTR : aliased constant String := "rows";
COLS_ATTR : aliased constant String := "cols";
CHARSET_ATTR : aliased constant String := "charset";
SHAPE_ATTR : aliased constant String := "shape";
REV_ATTR : aliased constant String := "rev";
COORDS_ATTR : aliased constant String := "coords";
TARGET_ATTR : aliased constant String := "target";
HREFLANG_ATTR : aliased constant String := "hreflang";
-- ------------------------------
-- Add in the <b>names</b> set, the basic text attributes that can be set
-- on HTML elements (dir, lang, style, title).
-- ------------------------------
procedure Set_Text_Attributes (Names : in out Util.Strings.String_Set.Set) is
begin
Names.Insert (STYLE_CLASS_ATTR'Access);
Names.Insert (TITLE_ATTR'Access);
Names.Insert (DIR_ATTR'Access);
Names.Insert (LANG_ATTR'Access);
Names.Insert (STYLE_ATTR'Access);
end Set_Text_Attributes;
-- ------------------------------
-- Add in the <b>names</b> set, the onXXX attributes that can be set
-- on HTML elements (accesskey, tabindex, onXXX).
-- ------------------------------
procedure Set_Interactive_Attributes (Names : in out Util.Strings.String_Set.Set) is
begin
Names.Insert (ACCESS_KEY_ATTR'Access);
Names.Insert (TABINDEX_ATTR'Access);
Names.Insert (ON_BLUR_ATTR'Access);
Names.Insert (ON_MOUSE_UP_ATTR'Access);
Names.Insert (ON_MOUSE_OVER_ATTR'Access);
Names.Insert (ON_MOUSE_OUT_ATTR'Access);
Names.Insert (ON_MOUSE_MOVE_ATTR'Access);
Names.Insert (ON_MOUSE_DOWN_ATTR'Access);
Names.Insert (ON_KEYUP_ATTR'Access);
Names.Insert (ON_KEYDOWN_ATTR'Access);
Names.Insert (ON_FOCUS_ATTR'Access);
Names.Insert (ON_DBLCLICK_ATTR'Access);
Names.Insert (ON_CLICK_ATTR'Access);
Names.Insert (ON_CHANGE_ATTR'Access);
end Set_Interactive_Attributes;
-- ------------------------------
-- Add in the <b>names</b> set, the size attributes that can be set
-- on HTML elements.
-- ------------------------------
procedure Set_Input_Attributes (Names : in out Util.Strings.String_Set.Set) is
begin
Names.Insert (SIZE_ATTR'Access);
Names.Insert (AUTOCOMPLETE_ATTR'Access);
Names.Insert (MAXLENGTH_ATTR'Access);
Names.Insert (ALT_ATTR'Access);
Names.Insert (DISABLED_ATTR'Access);
Names.Insert (READONLY_ATTR'Access);
end Set_Input_Attributes;
-- ------------------------------
-- Add in the <b>names</b> set, the size attributes that can be set
-- on <textarea> elements.
-- ------------------------------
procedure Set_Textarea_Attributes (Names : in out Util.Strings.String_Set.Set) is
begin
Names.Insert (ROWS_ATTR'Access);
Names.Insert (COLS_ATTR'Access);
end Set_Textarea_Attributes;
-- ------------------------------
-- Add in the <b>names</b> set, the online and onunload attributes that can be set
-- on <body> elements.
-- ------------------------------
procedure Set_Body_Attributes (Names : in out Util.Strings.String_Set.Set) is
begin
Names.Insert (ON_LOAD_ATTR'Access);
Names.Insert (ON_UNLOAD_ATTR'Access);
end Set_Body_Attributes;
-- ------------------------------
-- Add in the <b>names</b> set, the dir, lang attributes that can be set
-- on <head> elements.
-- ------------------------------
procedure Set_Head_Attributes (Names : in out Util.Strings.String_Set.Set) is
begin
Names.Insert (DIR_ATTR'Access);
Names.Insert (LANG_ATTR'Access);
end Set_Head_Attributes;
--------------------
-- Add in the <b>names</b> set, the onreset and onsubmit attributes that can be set
-- on <form> elements.
-- ------------------------------
procedure Set_Form_Attributes (Names : in out Util.Strings.String_Set.Set) is
begin
Names.Insert (ON_RESET_ATTR'Access);
Names.Insert (ON_SUBMIT_ATTR'Access);
Names.Insert (ENCTYPE_ATTR'Access);
end Set_Form_Attributes;
--------------------
-- Add in the <b>names</b> set, the attributes which are specific to a link.
-- ------------------------------
procedure Set_Link_Attributes (Names : in out Util.Strings.String_Set.Set) is
begin
Names.Insert (CHARSET_ATTR'Access);
Names.Insert (SHAPE_ATTR'Access);
Names.Insert (REV_ATTR'Access);
Names.Insert (COORDS_ATTR'Access);
Names.Insert (TARGET_ATTR'Access);
Names.Insert (HREFLANG_ATTR'Access);
end Set_Link_Attributes;
-- ------------------------------
-- Add in the <b>names</b> set, the attributes which are specific to an input file.
-- ------------------------------
procedure Set_File_Attributes (Names : in out Util.Strings.String_Set.Set) is
begin
Names.Insert (ACCEPT_ATTR'Access);
end Set_File_Attributes;
end ASF.Utils;
|
-- BinToAsc.Base16
-- Binary data to ASCII codecs - Base16 codec as in RFC4648
-- Copyright (c) 2015, James Humphry - see LICENSE file for details
with Ada.Characters.Handling;
package body BinToAsc.Base16 is
use Ada.Characters.Handling;
Reverse_Alphabet : constant Reverse_Alphabet_Lookup
:= Make_Reverse_Alphabet(Alphabet, Case_Sensitive);
--
-- Base16_To_String
--
procedure Reset (C : out Base16_To_String) is
begin
C := (State => Ready);
end Reset;
procedure Process
(C : in out Base16_To_String;
Input : in Bin;
Output : out String;
Output_Length : out Natural)
is
pragma Unreferenced (C);
Input_Index : constant Bin := Bin'Pos(Input);
begin
Output_Length := 2;
Output := (Alphabet(Input_Index / 16),
Alphabet(Input_Index and 2#00001111#),
others => ' ');
end Process;
procedure Process
(C : in out Base16_To_String;
Input : in Bin_Array;
Output : out String;
Output_Length : out Natural)
is
pragma Unreferenced (C);
Output_Index : Integer := Output'First;
Input_Index : Bin;
begin
Output_Length := 2 * Input'Length;
for I in Input'Range loop
Input_Index := Bin'Pos(Input(I));
Output(Output_Index) := Alphabet(Input_Index / 16);
Output(Output_Index + 1) := Alphabet(Input_Index and 2#00001111#);
Output_Index := Output_Index + 2;
end loop;
end Process;
procedure Complete
(C : in out Base16_To_String;
Output : out String;
Output_Length : out Natural)
is
begin
C.State := Completed;
Output := (others => ' ');
Output_Length := 0;
end Complete;
function To_String_Private is
new BinToAsc.To_String(Codec => Base16_To_String);
function To_String (Input : in Bin_Array) return String
renames To_String_Private;
--
-- Base16_To_Bin
--
procedure Reset (C : out Base16_To_Bin) is
begin
C := (State => Ready,
Loaded => False,
Load => 0);
end Reset;
procedure Process (C : in out Base16_To_Bin;
Input : in Character;
Output : out Bin_Array;
Output_Length : out Bin_Array_Index)
is
Input_Bin : Bin;
begin
Input_Bin := Reverse_Alphabet(Input);
if Input_Bin = Invalid_Character_Input then
Output_Length := 0;
C.State := Failed;
else
if C.Loaded then
Output(Output'First) := Bin(C.Load) * 16 or Input_Bin;
Output(Output'First + 1 .. Output'Last) := (others => 0);
Output_Length := 1;
C.Loaded := False;
else
Output := (others => 0);
Output_Length := 0;
C.Loaded := True;
C.Load := Input_Bin;
end if;
end if;
end Process;
procedure Process (C : in out Base16_To_Bin;
Input : in String;
Output : out Bin_Array;
Output_Length : out Bin_Array_Index)
is
Input_Bin : Bin;
Output_Index : Bin_Array_Index := Output'First;
begin
for I in Input'Range loop
Input_Bin := Reverse_Alphabet(Input(I));
if Input_Bin = Invalid_Character_Input then
C.State := Failed;
exit;
end if;
if C.Loaded then
Output(Output_Index) := Bin(C.Load) * 16 or Input_Bin;
Output_Index := Output_Index + 1;
C.Loaded := False;
else
C.Loaded := True;
C.Load := Input_Bin;
end if;
end loop;
if C.State = Failed then
Output := (others => 0);
Output_Length := 0;
else
Output(Output_Index .. Output'Last) := (others => 0);
Output_Length := Output_Index - Output'First;
end if;
end Process;
procedure Complete (C : in out Base16_To_Bin;
Output : out Bin_Array;
Output_Length : out Bin_Array_Index)
is
begin
if C.Loaded then
C.State := Failed;
elsif C.State = Ready then
C.State := Completed;
end if;
Output := (others => 0);
Output_Length := 0;
end Complete;
function To_Bin_Private is new BinToAsc.To_Bin(Codec => Base16_To_Bin);
function To_Bin (Input : in String) return Bin_Array renames To_Bin_Private;
begin
-- The following Compile_Time_Error test is silently ignored by GNAT GPL 2015,
-- although it does appear to be a static boolean expression as required by
-- the user guide. It works if converted to a run-time test so it has been
-- left in, in the hope that in a future version of GNAT it will actually be
-- tested.
pragma Warnings (GNATprove, Off, "Compile_Time_Error");
pragma Compile_Time_Error ((for some X in 1..Alphabet'Last =>
(for some Y in 0..X-1 =>
(Alphabet(Y) = Alphabet(X) or
(not Case_Sensitive and
To_Lower(Alphabet(Y)) = To_Lower(Alphabet(X)))
)
)
),
"Duplicate letter in alphabet for Base16 codec.");
pragma Warnings (GNATprove, On, "Compile_Time_Error");
end BinToAsc.Base16;
|
------------------------------------------------------------------------------
-- AGAR GUI LIBRARY --
-- A G A R . K E Y B O A R D --
-- S p e c --
------------------------------------------------------------------------------
with Interfaces.C;
with Interfaces.C.Strings;
with Agar.Input_Device;
with Agar.Types; use Agar.Types;
package Agar.Keyboard is
package C renames Interfaces.C;
package CS renames Interfaces.C.Strings;
package INDEV renames Agar.Input_Device;
use type C.int;
use type C.unsigned;
---------------------
-- Virtual Keysyms --
---------------------
type Key_Sym is
(KEY_NONE,
KEY_BACKSPACE,
KEY_TAB,
KEY_CLEAR,
KEY_RETURN,
KEY_PAUSE,
KEY_ESCAPE,
KEY_SPACE,
KEY_EXCLAIM,
KEY_QUOTEDBL,
KEY_HASH,
KEY_DOLLAR,
KEY_PERCENT,
KEY_AMPERSAND,
KEY_QUOTE,
KEY_LEFT_PAREN,
KEY_RIGHT_PAREN,
KEY_ASTERISK,
KEY_PLUS,
KEY_COMMA,
KEY_MINUS,
KEY_PERIOD,
KEY_SLASH,
KEY_0,
KEY_1,
KEY_2,
KEY_3,
KEY_4,
KEY_5,
KEY_6,
KEY_7,
KEY_8,
KEY_9,
KEY_COLON,
KEY_SEMICOLON,
KEY_LESS,
KEY_EQUALS,
KEY_GREATER,
KEY_QUESTION,
KEY_AT,
KEY_LEFT_BRACKET,
KEY_BACKSLASH,
KEY_RIGHT_BRACKET,
KEY_CARET,
KEY_UNDERSCORE,
KEY_BACKQUOTE,
KEY_A,
KEY_B,
KEY_C,
KEY_D,
KEY_E,
KEY_F,
KEY_G,
KEY_H,
KEY_I,
KEY_J,
KEY_K,
KEY_L,
KEY_M,
KEY_N,
KEY_O,
KEY_P,
KEY_Q,
KEY_R,
KEY_S,
KEY_T,
KEY_U,
KEY_V,
KEY_W,
KEY_X,
KEY_Y,
KEY_Z,
KEY_DELETE,
KEY_KP0,
KEY_KP1,
KEY_KP2,
KEY_KP3,
KEY_KP4,
KEY_KP5,
KEY_KP6,
KEY_KP7,
KEY_KP8,
KEY_KP9,
KEY_KP_PERIOD,
KEY_KP_DIVIDE,
KEY_KP_MULTIPLY,
KEY_KP_MINUS,
KEY_KP_PLUS,
KEY_KP_ENTER,
KEY_KP_EQUALS,
KEY_UP,
KEY_DOWN,
KEY_RIGHT,
KEY_LEFT,
KEY_INSERT,
KEY_HOME,
KEY_END,
KEY_PAGE_UP,
KEY_PAGE_DOWN,
KEY_F1,
KEY_F2,
KEY_F3,
KEY_F4,
KEY_F5,
KEY_F6,
KEY_F7,
KEY_F8,
KEY_F9,
KEY_F10,
KEY_F11,
KEY_F12,
KEY_F13,
KEY_F14,
KEY_F15,
KEY_NUM_LOCK,
KEY_CAPS_LOCK,
KEY_SCROLL_LOCK,
KEY_RIGHT_SHIFT,
KEY_LEFT_SHIFT,
KEY_RIGHT_CTRL,
KEY_LEFT_CTRL,
KEY_RIGHT_ALT,
KEY_LEFT_ALT,
KEY_RIGHT_META,
KEY_LEFT_META,
KEY_LEFT_SUPER,
KEY_RIGHT_SUPER,
KEY_MODE,
KEY_COMPOSE,
KEY_HELP,
KEY_PRINT,
KEY_SYSREQ,
KEY_BREAK,
KEY_MENU,
KEY_POWER,
KEY_EURO,
KEY_UNDO,
KEY_GRAVE,
KEY_KP_CLEAR,
KEY_COMMAND,
KEY_FUNCTION,
KEY_VOLUME_UP,
KEY_VOLUME_DOWN,
KEY_VOLUME_MUTE,
KEY_F16,
KEY_F17,
KEY_F18,
KEY_F19,
KEY_F20,
KEY_F21,
KEY_F22,
KEY_F23,
KEY_F24,
KEY_F25,
KEY_F26,
KEY_F27,
KEY_F28,
KEY_F29,
KEY_F30,
KEY_F31,
KEY_F32,
KEY_F33,
KEY_F34,
KEY_F35,
KEY_BEGIN,
KEY_RESET,
KEY_STOP,
KEY_USER,
KEY_SYSTEM,
KEY_PRINT_SCREEN,
KEY_CLEAR_LINE,
KEY_CLEAR_DISPLAY,
KEY_INSERT_LINE,
KEY_DELETE_LINE,
KEY_INSERT_CHAR,
KEY_DELETE_CHAR,
KEY_PREV,
KEY_NEXT,
KEY_SELECT,
KEY_EXECUTE,
KEY_REDO,
KEY_FIND,
KEY_MODE_SWITCH,
KEY_LAST,
KEY_ANY);
for Key_Sym use
(KEY_NONE => 16#00_00#,
KEY_BACKSPACE => 16#00_08#,
KEY_TAB => 16#00_09#,
KEY_CLEAR => 16#00_0c#,
KEY_RETURN => 16#00_0d#,
KEY_PAUSE => 16#00_13#,
KEY_ESCAPE => 16#00_1b#,
KEY_SPACE => 16#00_20#, -- --
KEY_EXCLAIM => 16#00_21#, -- ! --
KEY_QUOTEDBL => 16#00_22#, -- " --
KEY_HASH => 16#00_23#, -- # --
KEY_DOLLAR => 16#00_24#, -- $ --
KEY_PERCENT => 16#00_25#, -- % --
KEY_AMPERSAND => 16#00_26#, -- & --
KEY_QUOTE => 16#00_27#, -- ' --
KEY_LEFT_PAREN => 16#00_28#, -- ( --
KEY_RIGHT_PAREN => 16#00_29#, -- ) --
KEY_ASTERISK => 16#00_2a#, -- * --
KEY_PLUS => 16#00_2b#, -- + --
KEY_COMMA => 16#00_2c#, -- , --
KEY_MINUS => 16#00_2d#, -- - --
KEY_PERIOD => 16#00_2e#, -- . --
KEY_SLASH => 16#00_2f#, -- / --
KEY_0 => 16#00_30#, -- 0 --
KEY_1 => 16#00_31#, -- 1 --
KEY_2 => 16#00_32#, -- 2 --
KEY_3 => 16#00_33#, -- 3 --
KEY_4 => 16#00_34#, -- 4 --
KEY_5 => 16#00_35#, -- 5 --
KEY_6 => 16#00_36#, -- 6 --
KEY_7 => 16#00_37#, -- 7 --
KEY_8 => 16#00_38#, -- 8 --
KEY_9 => 16#00_39#, -- 9 --
KEY_COLON => 16#00_3a#, -- : --
KEY_SEMICOLON => 16#00_3b#, -- ; --
KEY_LESS => 16#00_3c#, -- < --
KEY_EQUALS => 16#00_3d#, -- = --
KEY_GREATER => 16#00_3e#, -- > --
KEY_QUESTION => 16#00_3f#, -- ? --
KEY_AT => 16#00_40#, -- @ --
KEY_LEFT_BRACKET => 16#00_5b#, -- [ --
KEY_BACKSLASH => 16#00_5c#, -- \ --
KEY_RIGHT_BRACKET => 16#00_5d#, -- ] --
KEY_CARET => 16#00_5e#, -- ^ --
KEY_UNDERSCORE => 16#00_5f#, -- _ --
KEY_BACKQUOTE => 16#00_60#, -- ` --
KEY_A => 16#00_61#, -- a --
KEY_B => 16#00_62#, -- b --
KEY_C => 16#00_63#, -- c --
KEY_D => 16#00_64#, -- d --
KEY_E => 16#00_65#, -- e --
KEY_F => 16#00_66#, -- f --
KEY_G => 16#00_67#, -- g --
KEY_H => 16#00_68#, -- h --
KEY_I => 16#00_69#, -- i --
KEY_J => 16#00_6a#, -- j --
KEY_K => 16#00_6b#, -- k --
KEY_L => 16#00_6c#, -- l --
KEY_M => 16#00_6d#, -- m --
KEY_N => 16#00_6e#, -- n --
KEY_O => 16#00_6f#, -- o --
KEY_P => 16#00_70#, -- p --
KEY_Q => 16#00_71#, -- q --
KEY_R => 16#00_72#, -- r --
KEY_S => 16#00_73#, -- s --
KEY_T => 16#00_74#, -- t --
KEY_U => 16#00_75#, -- u --
KEY_V => 16#00_76#, -- v --
KEY_W => 16#00_77#, -- w --
KEY_X => 16#00_78#, -- x --
KEY_Y => 16#00_79#, -- y --
KEY_Z => 16#00_7a#, -- z --
KEY_DELETE => 16#00_7f#,
KEY_KP0 => 16#01_00#,
KEY_KP1 => 16#01_01#,
KEY_KP2 => 16#01_02#,
KEY_KP3 => 16#01_03#,
KEY_KP4 => 16#01_04#,
KEY_KP5 => 16#01_05#,
KEY_KP6 => 16#01_06#,
KEY_KP7 => 16#01_07#,
KEY_KP8 => 16#01_08#,
KEY_KP9 => 16#01_09#,
KEY_KP_PERIOD => 16#01_0a#,
KEY_KP_DIVIDE => 16#01_0b#,
KEY_KP_MULTIPLY => 16#01_0c#,
KEY_KP_MINUS => 16#01_0d#,
KEY_KP_PLUS => 16#01_0e#,
KEY_KP_ENTER => 16#01_0f#,
KEY_KP_EQUALS => 16#01_10#,
KEY_UP => 16#01_11#,
KEY_DOWN => 16#01_12#,
KEY_RIGHT => 16#01_13#,
KEY_LEFT => 16#01_14#,
KEY_INSERT => 16#01_15#,
KEY_HOME => 16#01_16#,
KEY_END => 16#01_17#,
KEY_PAGE_UP => 16#01_18#,
KEY_PAGE_DOWN => 16#01_19#,
KEY_F1 => 16#01_1a#,
KEY_F2 => 16#01_1b#,
KEY_F3 => 16#01_1c#,
KEY_F4 => 16#01_1d#,
KEY_F5 => 16#01_1e#,
KEY_F6 => 16#01_1f#,
KEY_F7 => 16#01_20#,
KEY_F8 => 16#01_21#,
KEY_F9 => 16#01_22#,
KEY_F10 => 16#01_23#,
KEY_F11 => 16#01_24#,
KEY_F12 => 16#01_25#,
KEY_F13 => 16#01_26#,
KEY_F14 => 16#01_27#,
KEY_F15 => 16#01_28#,
KEY_NUM_LOCK => 16#01_2c#,
KEY_CAPS_LOCK => 16#01_2d#,
KEY_SCROLL_LOCK => 16#01_2e#,
KEY_RIGHT_SHIFT => 16#01_2f#,
KEY_LEFT_SHIFT => 16#01_30#,
KEY_RIGHT_CTRL => 16#01_31#,
KEY_LEFT_CTRL => 16#01_32#,
KEY_RIGHT_ALT => 16#01_33#,
KEY_LEFT_ALT => 16#01_34#,
KEY_RIGHT_META => 16#01_35#,
KEY_LEFT_META => 16#01_36#,
KEY_LEFT_SUPER => 16#01_37#,
KEY_RIGHT_SUPER => 16#01_38#,
KEY_MODE => 16#01_39#,
KEY_COMPOSE => 16#01_3a#,
KEY_HELP => 16#01_3b#,
KEY_PRINT => 16#01_3c#,
KEY_SYSREQ => 16#01_3d#,
KEY_BREAK => 16#01_3e#,
KEY_MENU => 16#01_3f#,
KEY_POWER => 16#01_40#,
KEY_EURO => 16#01_41#,
KEY_UNDO => 16#01_42#,
KEY_GRAVE => 16#01_43#,
KEY_KP_CLEAR => 16#01_44#,
KEY_COMMAND => 16#01_45#,
KEY_FUNCTION => 16#01_46#,
KEY_VOLUME_UP => 16#01_47#,
KEY_VOLUME_DOWN => 16#01_48#,
KEY_VOLUME_MUTE => 16#01_49#,
KEY_F16 => 16#01_4a#,
KEY_F17 => 16#01_4b#,
KEY_F18 => 16#01_4c#,
KEY_F19 => 16#01_4d#,
KEY_F20 => 16#01_4e#,
KEY_F21 => 16#01_4f#,
KEY_F22 => 16#01_50#,
KEY_F23 => 16#01_51#,
KEY_F24 => 16#01_52#,
KEY_F25 => 16#01_53#,
KEY_F26 => 16#01_54#,
KEY_F27 => 16#01_55#,
KEY_F28 => 16#01_56#,
KEY_F29 => 16#01_57#,
KEY_F30 => 16#01_58#,
KEY_F31 => 16#01_59#,
KEY_F32 => 16#01_5a#,
KEY_F33 => 16#01_5b#,
KEY_F34 => 16#01_5c#,
KEY_F35 => 16#01_5d#,
KEY_BEGIN => 16#01_5e#,
KEY_RESET => 16#01_5f#,
KEY_STOP => 16#01_60#,
KEY_USER => 16#01_61#,
KEY_SYSTEM => 16#01_62#,
KEY_PRINT_SCREEN => 16#01_63#,
KEY_CLEAR_LINE => 16#01_64#,
KEY_CLEAR_DISPLAY => 16#01_65#,
KEY_INSERT_LINE => 16#01_66#,
KEY_DELETE_LINE => 16#01_67#,
KEY_INSERT_CHAR => 16#01_68#,
KEY_DELETE_CHAR => 16#01_69#,
KEY_PREV => 16#01_6a#,
KEY_NEXT => 16#01_6b#,
KEY_SELECT => 16#01_6c#,
KEY_EXECUTE => 16#01_6d#,
KEY_REDO => 16#01_6e#,
KEY_FIND => 16#01_6f#,
KEY_MODE_SWITCH => 16#01_70#,
KEY_LAST => 16#01_71#,
KEY_ANY => 16#ff_ff#);
for Key_Sym'Size use C.int'Size;
-------------------
-- Key Modifiers --
-------------------
KEYMOD_NONE : constant C.unsigned := 16#00_00#;
KEYMOD_LEFT_SHIFT : constant C.unsigned := 16#00_01#;
KEYMOD_RIGHT_SHIFT : constant C.unsigned := 16#00_02#;
KEYMOD_LEFT_CTRL : constant C.unsigned := 16#00_40#;
KEYMOD_RIGHT_CTRL : constant C.unsigned := 16#00_80#;
KEYMOD_LEFT_ALT : constant C.unsigned := 16#01_00#;
KEYMOD_RIGHT_ALT : constant C.unsigned := 16#02_00#;
KEYMOD_LEFT_META : constant C.unsigned := 16#04_00#;
KEYMOD_RIGHT_META : constant C.unsigned := 16#08_00#;
KEYMOD_NUM_LOCK : constant C.unsigned := 16#10_00#;
KEYMOD_CAPS_LOCK : constant C.unsigned := 16#20_00#;
KEYMOD_MODE : constant C.unsigned := 16#40_00#;
KEYMOD_ANY : constant C.unsigned := 16#ff_ff#;
KEYMOD_CTRL : constant C.unsigned := KEYMOD_LEFT_CTRL or KEYMOD_RIGHT_CTRL;
KEYMOD_SHIFT : constant C.unsigned := KEYMOD_LEFT_SHIFT or KEYMOD_RIGHT_SHIFT;
KEYMOD_ALT : constant C.unsigned := KEYMOD_LEFT_ALT or KEYMOD_RIGHT_ALT;
KEYMOD_META : constant C.unsigned := KEYMOD_LEFT_META or KEYMOD_RIGHT_META;
type Virtual_Key_t is record
Symbol : Key_Sym; -- Virtual key
Modifier : C.int; -- Virtual key modifier mask
Unicode : AG_Char; -- Corresponding Unicode (or 0)
end record
with Convention => C;
---------------------
-- Keyboard Device --
---------------------
type Keyboard_Keys_Access is access all C.int with Convention => C;
type Keyboard_Device is limited record
Super : aliased INDEV.Input_Device; -- [Input_Device -> Keyboard]
Keys : Keyboard_Keys_Access; -- Key state
Key_Count : C.unsigned; -- Number of keys
Mod_State : C.unsigned; -- State of modifier keys
end record
with Convention => C;
type Keyboard_Device_Access is access all Keyboard_Device with Convention => C;
subtype Keyboard_Device_not_null_Access is not null Keyboard_Device_Access;
end Agar.Keyboard;
|
with Ada.Task_Identification; use Ada.Task_Identification;
with Ada.Containers.Hashed_Sets; use Ada.Containers;
-- Author : Wenjun Yang
-- u_id : u6251843
package Vehicle_Task_Type is
task type Vehicle_Task is
entry Identify (Set_Vehicle_No : Positive; Local_Task_Id : out Task_Id);
end Vehicle_Task;
-- Hash function used for the following HashSet and HashMap in veicle_task_type.adb file.
function ID_Hashed (id : Positive) return Hash_Type is (Hash_Type (id));
-- Define a HashSet to store the live and dead vehicles' number for every drone.
package My_Set is new Ada.Containers.Hashed_Sets (Element_Type => Positive,
Hash => ID_Hashed,
Equivalent_Elements => "=");
use My_Set;
-- Discuss the use of subtype with Yiluo Wei (u6227375)
-- Define a subtype of My_Set, the type of live and dead vehicles' number set (Two sets).
subtype No_Set is My_Set.Set;
end Vehicle_Task_Type;
|
-----------------------------------------------------------------------
-- applications.messages -- Application Messages
-- Copyright (C) 2010 Stephane Carrez
-- Written by Stephane Carrez (Stephane.Carrez@gmail.com)
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
package body ASF.Applications.Messages is
use Ada.Strings.Unbounded;
-- ------------------------------
-- Return the message severity level.
-- ------------------------------
function Get_Severity (Msg : in Message) return Severity is
begin
return Msg.Kind;
end Get_Severity;
-- ------------------------------
-- Sets the message severity level.
-- ------------------------------
procedure Set_Severity (Msg : in out Message;
Kind : in Severity) is
begin
Msg.Kind := Kind;
end Set_Severity;
-- ------------------------------
-- Return the localized message summary.
-- ------------------------------
function Get_Summary (Msg : in Message) return String is
begin
return To_String (Msg.Summary);
end Get_Summary;
-- ------------------------------
-- Sets the localized message summary.
-- ------------------------------
procedure Set_Summary (Msg : in out Message;
Summary : in String) is
begin
Msg.Summary := To_Unbounded_String (Summary);
end Set_Summary;
-- ------------------------------
-- Return the localized message detail. If the message detail was
-- not provided, returns the message summary.
-- ------------------------------
function Get_Detail (Msg : in Message) return String is
begin
if Length (Msg.Detail) = 0 then
return To_String (Msg.Summary);
else
return To_String (Msg.Detail);
end if;
end Get_Detail;
-- ------------------------------
-- Sets the localized message detail.
-- ------------------------------
procedure Set_Detail (Msg : in out Message;
Detail : in String) is
begin
Msg.Detail := To_Unbounded_String (Detail);
end Set_Detail;
-- ------------------------------
-- Returns true if both messages are identical (same severity, same messages)
-- ------------------------------
function "=" (Left, Right : in Message) return Boolean is
begin
return Left.Kind = Right.Kind and Left.Summary = Right.Summary
and Left.Detail = Right.Detail;
end "=";
end ASF.Applications.Messages;
|
package calc with SPARK_Mode is
procedure Forgetful_Assert (X, Y : out Integer);
end calc;
|
with RASCAL.ToolboxQuit; use RASCAL.ToolboxQuit;
with RASCAL.Toolbox; use RASCAL.Toolbox;
with RASCAL.OS; use RASCAL.OS;
package Controller_DataMenu is
type TEL_DataMenuOpen_Type is new Toolbox_UserEventListener(16#34#,-1,-1) with null record;
type TEL_DataEntrySelected_Type is new Toolbox_UserEventListener(16#35#,-1,-1) with null record;
type TEL_ViewDataDir_Type is new Toolbox_UserEventListener(16#32#,-1,-1) with null record;
procedure Handle (The : in TEL_ViewDataDir_Type);
procedure Handle (The : in TEL_DataMenuOpen_Type);
procedure Handle (The : in TEL_DataEntrySelected_Type);
end Controller_DataMenu;
|
pragma restrictions (no_secondary_stack);
pragma restrictions (no_elaboration_code);
pragma restrictions (no_finalization);
pragma restrictions (no_exception_handlers);
-- These types are not SPARK compliant
package types.unsafe
with spark_mode => off
is
type string_access is access all string;
end types.unsafe;
|
with Interfaces;
with Ada.Streams.Stream_IO;
use Interfaces;
use Ada.Streams.Stream_IO;
package body Bitmap is
procedure Init(im : out Image; w : Integer; h : Integer) is
begin
im.width := w;
im.height := h;
im.data := new PixelData(0 .. w*h-1);
end Init;
procedure Delete(im : in out Image) is
begin
im.width := 0;
im.height := 0;
delete(im.data);
im.data := null;
end Delete;
procedure LoadBMP(im : in out Image; a_fileName : String) is
begin
null;
end LoadBMP;
procedure SaveBMP(im : Image; a_fileName : String) is
BMP_File : File_Type;
S : Stream_Access;
header : BITBAPFILEHEADER;
info : BITMAPINFOHEADER;
px : Pixel;
pxU : Unsigned_32;
begin
header.bfType := 16#4d42#;
header.bfSize := 14 + 40 + DWORD(im.width*im.height*3);
header.bfReserved1 := 0;
header.bfReserved2 := 0;
header.bfOffBits := 14 + 40;
info.biSize := 40;
info.biWidth := DWORD(im.width);
info.biHeight := DWORD(im.height);
info.biPlanes := 1;
info.biBitCount := 24;
info.biCompression := 0;
info.biSizeImage := 0;
info.biXPelsPerMeter := 0;
info.biYPelsPerMeter := 0;
info.biClrUsed := 0;
info.biClrImportant := 0;
Create(File => BMP_File,
Mode => Out_File,
Name => a_fileName,
Form => "");
S := Stream(BMP_File);
BITBAPFILEHEADER'Write(S, header);
BITMAPINFOHEADER'Write(S, info);
for i in im.data'First .. im.data'Last loop
pxU := im.data(i);
px.b := Unsigned_8(Shift_Right(pxU,0) and 255);
px.g := Unsigned_8(Shift_Right(pxU,8) and 255);
px.r := Unsigned_8(Shift_Right(pxU,16) and 255);
Pixel'Write(S, px);
end loop;
Close(BMP_File);
end SaveBMP;
end Bitmap;
|
with Ada.Unchecked_Conversion;
pragma Warnings (Off);
with System.Finalization_Root;
pragma Warnings (On);
with C.gc.gc;
with C.gc.gc_typed;
package body GC.Pools is
use type System.Address;
use type System.Storage_Elements.Storage_Count;
use type C.size_t;
package Finalization is
Initialized : Boolean := False;
procedure Initialize;
function Controlled_Size_In_Storage_Elements
return System.Storage_Elements.Storage_Count;
procedure After_Allocation (Storage_Address : in System.Address);
procedure Finalize_Controlled (obj : C.void_ptr; cd : C.void_ptr)
with Convention => C;
end Finalization;
package body Finalization is separate;
-- implementation
overriding procedure Allocate (
Pool : in out GC_Storage_Pool;
Storage_Address : out System.Address;
Size_In_Storage_Elements : in System.Storage_Elements.Storage_Count;
Alignment : in System.Storage_Elements.Storage_Count)
is
pragma Unreferenced (Pool);
begin
Storage_Address :=
System.Address (C.gc.gc.GC_malloc (C.size_t (Size_In_Storage_Elements)));
if Storage_Address = System.Null_Address
or else (Alignment > 1 and then Storage_Address mod Alignment /= 0)
then
raise Storage_Error;
end if;
end Allocate;
overriding procedure Deallocate (
Pool : in out GC_Storage_Pool;
Storage_Address : in System.Address;
Size_In_Storage_Elements : in System.Storage_Elements.Storage_Count;
Alignment : in System.Storage_Elements.Storage_Count)
is
pragma Unreferenced (Pool);
pragma Unreferenced (Size_In_Storage_Elements);
pragma Unreferenced (Alignment);
begin
C.gc.gc.GC_free (C.void_ptr (Storage_Address));
end Deallocate;
overriding function Storage_Size (Pool : GC_Storage_Pool)
return System.Storage_Elements.Storage_Count
is
pragma Unreferenced (Pool);
begin
return System.Storage_Elements.Storage_Offset (C.gc.gc.GC_get_heap_size);
end Storage_Size;
overriding procedure Allocate (
Pool : in out GC_Controlled_Storage_Pool;
Storage_Address : out System.Address;
Size_In_Storage_Elements : in System.Storage_Elements.Storage_Count;
Alignment : in System.Storage_Elements.Storage_Count)
is
pragma Unreferenced (Pool);
begin
if not Finalization.Initialized then
Finalization.Initialized := True;
Finalization.Initialize;
end if;
declare
Words : constant C.size_t :=
C.size_t (
(Size_In_Storage_Elements * System.Storage_Unit + System.Word_Size - 1)
/ System.Word_Size);
Controlled_Words : constant C.size_t :=
C.size_t (Finalization.Controlled_Size_In_Storage_Elements);
type Bits_Array is array (1 .. Words) of Boolean;
pragma Pack (Bits_Array);
type Bits_Array_Access is access all Bits_Array;
function To_GC_bitmap is
new Ada.Unchecked_Conversion (Bits_Array_Access, C.gc.gc_typed.GC_bitmap);
Bitmap : aliased Bits_Array;
Desc : C.gc.gc_typed.GC_descr;
begin
Bitmap (1 .. Controlled_Words) := (others => False);
Bitmap (Controlled_Words + 1 .. Words) := (others => True);
Desc := C.gc.gc_typed.GC_make_descriptor (To_GC_bitmap (Bitmap'Access), Words);
Storage_Address :=
System.Address (
C.gc.gc_typed.GC_malloc_explicitly_typed (
C.size_t (Size_In_Storage_Elements),
Desc));
if Storage_Address = System.Null_Address
or else (Alignment > 1 and then Storage_Address mod Alignment /= 0)
then
raise Storage_Error;
end if;
end;
C.gc.gc.GC_register_finalizer_no_order (
C.void_ptr (Storage_Address),
Finalization.Finalize_Controlled'Access,
C.void_ptr (System.Null_Address),
null,
null);
Finalization.After_Allocation (Storage_Address);
end Allocate;
overriding procedure Deallocate (
Pool : in out GC_Controlled_Storage_Pool;
Storage_Address : in System.Address;
Size_In_Storage_Elements : in System.Storage_Elements.Storage_Count;
Alignment : in System.Storage_Elements.Storage_Count)
is
pragma Unreferenced (Pool);
pragma Unreferenced (Size_In_Storage_Elements);
pragma Unreferenced (Alignment);
begin
C.gc.gc.GC_register_finalizer_no_order (
C.void_ptr (Storage_Address),
null,
C.void_ptr (System.Null_Address),
null,
null);
C.gc.gc.GC_free (C.void_ptr (Storage_Address));
end Deallocate;
begin
C.gc.gc.GC_init;
end GC.Pools;
|
-- SPDX-FileCopyrightText: 2019 Max Reznik <reznikmm@gmail.com>
--
-- SPDX-License-Identifier: MIT
-------------------------------------------------------------
with Program.Elements.Statements;
with Program.Elements.Defining_Identifiers;
with Program.Lexical_Elements;
with Program.Element_Vectors;
with Program.Elements.Exception_Handlers;
with Program.Elements.Identifiers;
package Program.Elements.Block_Statements is
pragma Pure (Program.Elements.Block_Statements);
type Block_Statement is
limited interface and Program.Elements.Statements.Statement;
type Block_Statement_Access is access all Block_Statement'Class
with Storage_Size => 0;
not overriding function Statement_Identifier
(Self : Block_Statement)
return Program.Elements.Defining_Identifiers.Defining_Identifier_Access
is abstract;
not overriding function Declarations
(Self : Block_Statement)
return Program.Element_Vectors.Element_Vector_Access is abstract;
not overriding function Statements
(Self : Block_Statement)
return not null Program.Element_Vectors.Element_Vector_Access
is abstract;
not overriding function Exception_Handlers
(Self : Block_Statement)
return Program.Elements.Exception_Handlers
.Exception_Handler_Vector_Access is abstract;
not overriding function End_Statement_Identifier
(Self : Block_Statement)
return Program.Elements.Identifiers.Identifier_Access is abstract;
type Block_Statement_Text is limited interface;
type Block_Statement_Text_Access is access all Block_Statement_Text'Class
with Storage_Size => 0;
not overriding function To_Block_Statement_Text
(Self : in out Block_Statement)
return Block_Statement_Text_Access is abstract;
not overriding function Colon_Token
(Self : Block_Statement_Text)
return Program.Lexical_Elements.Lexical_Element_Access is abstract;
not overriding function Declare_Token
(Self : Block_Statement_Text)
return Program.Lexical_Elements.Lexical_Element_Access is abstract;
not overriding function Begin_Token
(Self : Block_Statement_Text)
return not null Program.Lexical_Elements.Lexical_Element_Access
is abstract;
not overriding function Exception_Token
(Self : Block_Statement_Text)
return Program.Lexical_Elements.Lexical_Element_Access is abstract;
not overriding function End_Token
(Self : Block_Statement_Text)
return not null Program.Lexical_Elements.Lexical_Element_Access
is abstract;
not overriding function Semicolon_Token
(Self : Block_Statement_Text)
return not null Program.Lexical_Elements.Lexical_Element_Access
is abstract;
end Program.Elements.Block_Statements;
|
with Lto19_Pkg2;
package Lto19_Pkg1 is
type Arr is array (1 .. Lto19_Pkg2.UB) of Integer;
type Rec is record
A : Arr;
I : Integer;
end record;
procedure Proc (R : Rec);
end Lto19_Pkg1;
|
separate (Numerics.Sparse_Matrices)
procedure Print (Mat : in Sparse_Matrix) is
use Ada.Text_IO, Sparse_Matrix_Format_IO, Int_IO, Real_IO;
begin
Put (" (");
Put (Mat.N_Row, Width => 0); Put (" x ");
Put (Mat.N_Col, Width => 0);
Put (") matrix in "); Put (Mat.Format); Put (" format.");
New_Line;
Put ("I: ");
for I of Mat.I loop
Put (", "); Put (I, Width => 4);
end loop;
New_Line;
Put ("P: ");
for P of Mat.P loop
Put (", "); Put (P, Width => 4);
end loop;
New_Line;
Put ("X: ");
for X of Mat.X loop
Put (", "); Put (X, Aft => 3, Exp => 2, Fore => 3);
end loop;
New_Line;
end Print;
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- L I B . U T I L --
-- --
-- B o d y --
-- --
-- Copyright (C) 1992-1999 Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 2, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
-- for more details. You should have received a copy of the GNU General --
-- Public License distributed with GNAT; see file COPYING. If not, write --
-- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
-- Boston, MA 02110-1301, USA. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
package Lib.Util is
-- This package implements a buffered write of library information
procedure Write_Info_Char (C : Character);
pragma Inline (Write_Info_Char);
-- Adds one character to the info
procedure Write_Info_Char_Code (Code : Char_Code);
-- Write a single character code. Upper half values in the range
-- 16#80..16#FF are written as Uhh (hh = 2 hex digits), and values
-- greater than 16#FF are written as Whhhh (hhhh = 4 hex digits).
function Write_Info_Col return Positive;
-- Returns the column in which the next character will be written
procedure Write_Info_EOL;
-- Terminate current info line. This only flushes the buffer
-- if there is not enough room for another complete line or
-- if the host system needs a write for each line.
procedure Write_Info_Initiate (Key : Character);
-- Initiates write of new line to info file, the parameter is the
-- keyword character for the line. The caller is responsible for
-- writing the required blank after the key character.
procedure Write_Info_Nat (N : Nat);
-- Adds image of N to Info_Buffer with no leading or trailing blanks
procedure Write_Info_Name (Name : Name_Id);
-- Adds characters of Name to Info_Buffer
procedure Write_Info_Str (Val : String);
-- Adds characters of Val to Info_Buffer surrounded by quotes
procedure Write_Info_Tab (Col : Positive);
-- Tab out with blanks and HT's to column Col. If already at or past
-- Col, writes a single blank, so that we do get a required field
-- separation.
procedure Write_Info_Terminate;
-- Terminate current info line and output lines built in Info_Buffer
end Lib.Util;
|
-- Ada regular expression library
-- (c) Kristian Klomsten Skordal 2020 <kristian.skordal@wafflemail.net>
-- Report bugs and issues on <https://github.com/skordal/ada-regex>
with AUnit.Test_Suites;
package Regex_Test_Suite is
-- Creates the Regex library test suite:
function Test_Suite return AUnit.Test_Suites.Access_Test_Suite;
end Regex_Test_Suite;
|
package FSmaker.TOML is
procedure Build_From_TOML (Path_To_TOML, Path_To_Output : String);
end FSmaker.TOML;
|
with Ada.Text_IO;
procedure Test is
My_Type : Boolean := True;
procedure Tagged_Procedure is
function Boolean_As_String return String is
(case My_Type is
when True => "True Value",
when False => "False Value");
function Another_Boolean_As_String return String is
(case My_Type is when True => "; function dummy0 return String is (",
when False => "; function dummy1 return String is (");
procedure p0 is
begin
Ada.Text_IO.put ("-0");
end p0;
function Yet_Boolean_As_String return String is
(case My_Type is
when True => "1",
when False => "0");
procedure p1 is
begin
Ada.Text_IO.put ("-1");
end p1;
begin
null;
end Tagged_Procedure;
procedure Not_Tagged_Procedure is
begin
null;
end Not_Tagged_Procedure;
begin
null;
end Test;
|
with Ada.Integer_Text_IO;
procedure Sum is
N : Integer;
Sum : Integer := 1;
begin
Ada.Integer_Text_IO.Get( N );
for I in 1..N loop
Sum := Sum + I;
end loop;
Ada.Integer_Text_IO.Put( Sum );
end Sum;
|
-- Abstract:
--
-- see spec
--
-- Copyright (C) 1998, 2003, 2009, 2015, 2017 - 2019 Free Software Foundation, Inc.
--
-- SAL is free software; you can redistribute it and/or modify it
-- under terms of the GNU General Public License as published by the
-- Free Software Foundation; either version 3, or (at your option)
-- any later version. SAL is distributed in the hope that it will be
-- useful, but WITHOUT ANY WARRANTY; without even the implied
-- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-- See the GNU General Public License for more details. You should
-- have received a copy of the GNU General Public License distributed
-- with SAL; see file COPYING. If not, write to the Free Software
-- Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
-- USA.
--
-- As a special exception, if other files instantiate generics from
-- SAL, or you link SAL object files with other files to produce an
-- executable, that does not by itself cause the resulting executable
-- to be covered by the GNU General Public License. This exception
-- does not however invalidate any other reasons why the executable
-- file might be covered by the GNU Public License.
pragma License (Modified_GPL);
package body SAL.Gen_Unbounded_Definite_Stacks is
----------
-- local subprogram bodies
procedure Grow (Stack : in out Sguds.Stack; Desired_Size : in Base_Peek_Type)
is
New_Data : constant Element_Array_Access := new Element_Array (1 .. Desired_Size);
begin
New_Data (1 .. Stack.Top) := Stack.Data (1 .. Stack.Top);
Free (Stack.Data);
Stack.Data := New_Data;
end Grow;
----------
-- Spec visible subprograms
overriding procedure Finalize (Stack : in out Sguds.Stack)
is begin
if Stack.Data /= null then
Free (Stack.Data);
Stack.Top := Invalid_Peek_Index;
end if;
end Finalize;
overriding procedure Adjust (Stack : in out Sguds.Stack)
is begin
if Stack.Data /= null then
Stack.Data := new Element_Array'(Stack.Data.all);
end if;
end Adjust;
overriding
function "=" (Left, Right : in Sguds.Stack) return Boolean
is begin
if Left.Data = null then
return Right.Data = null;
elsif Left.Top /= Right.Top then
return False;
else
-- Assume stacks differ near top.
for I in reverse 1 .. Left.Top loop
if Left.Data (I) /= Right.Data (I) then
return False;
end if;
end loop;
return True;
end if;
end "=";
procedure Clear (Stack : in out Sguds.Stack)
is begin
-- We don't change the reserved capacity, on the assumption the
-- stack will be used again.
Stack.Top := 0;
end Clear;
function Depth (Stack : in Sguds.Stack) return Base_Peek_Type
is begin
return Stack.Top;
end Depth;
function Is_Empty (Stack : in Sguds.Stack) return Boolean
is begin
return Stack.Top = 0;
end Is_Empty;
function Peek
(Stack : in Sguds.Stack;
Index : in Peek_Type := 1)
return Element_Type
is begin
return Stack.Data (Stack.Top - Index + 1);
end Peek;
procedure Pop (Stack : in out Sguds.Stack; Count : in Base_Peek_Type := 1)
is begin
if Stack.Top < Count then
raise Container_Empty;
else
Stack.Top := Stack.Top - Count;
end if;
end Pop;
function Pop (Stack : in out Sguds.Stack) return Element_Type
is begin
if Stack.Top = 0 then
raise Container_Empty;
else
return Result : constant Element_Type := Stack.Peek (1)
do
Stack.Top := Stack.Top - 1;
end return;
end if;
end Pop;
procedure Push (Stack : in out Sguds.Stack; Item : in Element_Type)
is begin
if Stack.Data = null then
-- Adding a generic parameter for a reasonably large default initial
-- size here makes Wisitoken McKenzie recover slightly slower,
-- presumably due to increased cache thrashing.
Stack.Data := new Element_Array (1 .. 2);
elsif Stack.Top = Stack.Data'Last then
Grow (Stack, Desired_Size => 2 * Stack.Data'Last);
end if;
Stack.Top := Stack.Top + 1;
Stack.Data (Stack.Top) := Item;
end Push;
function Top (Stack : in Sguds.Stack) return Element_Type
is begin
if Stack.Top < 1 then
raise SAL.Container_Empty;
else
return Peek (Stack, 1);
end if;
end Top;
procedure Set_Depth
(Stack : in out Sguds.Stack;
Depth : in Peek_Type)
is begin
if Stack.Data = null then
Stack.Data := new Element_Array (1 .. 2 * Depth);
elsif Depth > Stack.Data'Last then
Grow (Stack, Desired_Size => 2 * Depth);
end if;
end Set_Depth;
procedure Set
(Stack : in out Sguds.Stack;
Index : in Peek_Type;
Depth : in Peek_Type;
Element : in Element_Type)
is begin
-- Same Position algorithm as in Peek
Stack.Top := Depth;
Stack.Data (Depth - Index + 1) := Element;
end Set;
function Constant_Ref
(Container : aliased in Stack'Class;
Position : in Peek_Type)
return Constant_Ref_Type
is begin
return
(Element => Container.Data (Container.Top - Position + 1)'Access,
Dummy => 1);
end Constant_Ref;
function Constant_Ref
(Container : aliased in Stack'Class;
Position : in Cursor)
return Constant_Ref_Type
is begin
return
(Element => Container.Data (Container.Top - Position.Ptr + 1)'Access,
Dummy => 1);
end Constant_Ref;
function Has_Element (Position : in Cursor) return Boolean
is begin
return Position.Container.Depth >= Position.Ptr;
end Has_Element;
function Iterate (Container : aliased in Stack) return Iterator_Interfaces.Forward_Iterator'Class
is begin
return Iterator'(Container => Container'Unrestricted_Access);
end Iterate;
overriding function First (Object : Iterator) return Cursor
is begin
return (Object.Container, 1);
end First;
overriding function Next (Object : in Iterator; Position : in Cursor) return Cursor
is
pragma Unreferenced (Object);
begin
return (Position.Container, Position.Ptr + 1);
end Next;
end SAL.Gen_Unbounded_Definite_Stacks;
|
-- SPDX-License-Identifier: Apache-2.0
--
-- Copyright (c) 2020 onox <denkpadje@gmail.com>
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
with GL.Types;
with Orka.Contexts.AWT;
with Orka.OS;
with Orka.Rendering.Buffers.MDI;
with Orka.Rendering.Drawing;
with Orka.Rendering.Framebuffers;
with Orka.Rendering.Programs.Modules;
with Orka.Rendering.Programs.Uniforms;
with Orka.Resources.Locations.Directories;
with Orka.Types;
with Orka.Windows;
with AWT.Inputs;
procedure Orka_4_MDI is
Context : constant Orka.Contexts.Context'Class := Orka.Contexts.AWT.Create_Context
(Version => (4, 2), Flags => (Debug => True, others => False));
Window : constant Orka.Windows.Window'Class
:= Orka.Contexts.AWT.Create_Window (Context, Width => 500, Height => 500, Resizable => False);
use Orka.Resources;
use Orka.Rendering.Buffers;
use Orka.Rendering.Framebuffers;
use Orka.Rendering.Programs;
use type Orka.Float_32;
use GL.Types;
Vertices_1 : constant Single_Array
:= (-0.25, 0.5,
-0.75, -0.5,
0.25, -0.5);
Vertices_2 : constant Single_Array
:= (-0.25, 0.5,
0.25, -0.5,
0.75, 0.5);
Indices_1 : constant UInt_Array := (0, 1, 2);
Indices_2 : constant UInt_Array := (0, 1, 2);
Batch_1 : MDI.Batch := MDI.Create_Batch
(Orka.Types.Single_Type, Orka.Types.UInt_Type, 2,
Vertices_1'Length + Vertices_2'Length,
Indices_1'Length + Indices_2'Length);
procedure Append_Draw_Call
(Instances : Natural; Vertices : Single_Array; Indices : UInt_Array)
is
Vertex_Elements : constant := 2;
procedure Append_Vertices (Offset, Count : Natural) is
begin
Batch_1.Data.Write_Data (Vertices, Offset => Offset * Vertex_Elements);
end Append_Vertices;
procedure Append_Indices (Offset, Count : Natural) is
begin
Batch_1.Indices.Write_Data (Indices, Offset => Offset);
end Append_Indices;
begin
Batch_1.Append (Instances, Vertices'Length / Vertex_Elements, Indices'Length,
Append_Vertices'Access, Append_Indices'Access);
end Append_Draw_Call;
Location_Shaders : constant Locations.Location_Ptr
:= Locations.Directories.Create_Location ("data/shaders");
Program_1 : Program := Create_Program (Modules.Create_Module
(Location_Shaders, VS => "test-4-module-1.vert", FS => "test-4-module-1.frag"));
Uniform_Mode : constant Uniforms.Uniform := Program_1.Uniform ("mode");
FB_D : Framebuffer := Create_Default_Framebuffer (Window.Width, Window.Height);
type Color_Mode is (Draw_ID, Instance_ID, Object_ID);
Mode : Color_Mode := Object_ID;
begin
FB_D.Set_Default_Values ((Color => (0.0, 0.0, 0.0, 1.0), others => <>));
Append_Draw_Call (2, Vertices_1, Indices_1);
Append_Draw_Call (3, Vertices_2, Indices_2);
Batch_1.Finish_Batch;
FB_D.Use_Framebuffer;
Program_1.Use_Program;
Batch_1.Data.Bind (Shader_Storage, 0);
Orka.OS.Put_Line ("Usage: Press space key to cycle between coloring modes");
while not Window.Should_Close loop
AWT.Process_Events (0.001);
declare
Keyboard : constant AWT.Inputs.Keyboard_State := Window.State;
use all type AWT.Inputs.Keyboard_Button;
begin
if Keyboard.Pressed (Key_Escape) then
Window.Close;
end if;
if Keyboard.Pressed (Key_Space) then
if Mode /= Color_Mode'Last then
Mode := Color_Mode'Succ (Mode);
else
Mode := Color_Mode'First;
end if;
end if;
end;
Uniform_Mode.Set_Integer (Color_Mode'Pos (Mode));
Window.Set_Title ("Color mode: " & Mode'Image);
FB_D.Clear ((Color => True, others => False));
Orka.Rendering.Drawing.Draw_Indexed_Indirect
(Mode => Triangles,
Index_Buffer => Batch_1.Indices.Buffer,
Buffer => Batch_1.Commands.Buffer);
Window.Swap_Buffers;
end loop;
end Orka_4_MDI;
|
generic
type Element is mod <>;
type Index is range <>;
type Element_Array is array (Index range <>) of Element;
Digest_Length : Index;
Block_Length : Index;
type Hash_Context is private;
with function Hash_Initialize return Hash_Context;
with procedure Hash_Update
(Ctx : in out Hash_Context; Input : Element_Array);
with function Hash_Finalize (Ctx : Hash_Context) return Element_Array;
package HMAC_Generic with
Pure,
Preelaborate
is
pragma Compile_Time_Error
(Element'Modulus /= 256,
"'Element' type must be mod 2**8, i.e. represent a byte");
subtype Digest is Element_Array (0 .. Digest_Length - 1);
type Context is private;
function Initialize (Key : String) return Context;
function Initialize (Key : Element_Array) return Context;
procedure Initialize (Ctx : out Context; Key : String);
procedure Initialize (Ctx : out Context; Key : Element_Array);
procedure Update (Ctx : in out Context; Input : String);
procedure Update (Ctx : in out Context; Input : Element_Array);
function Finalize (Ctx : Context) return Digest;
procedure Finalize (Ctx : Context; Output : out Digest);
function HMAC (Key : String; Message : String) return Digest;
function HMAC (Key : Element_Array; Message : Element_Array) return Digest;
private
type Context is record
Inner : Hash_Context;
Outer : Hash_Context;
end record;
end HMAC_Generic;
|
with Ada.Text_IO;
use Ada.Text_IO;
with Ada.Integer_Text_IO;
use Ada.Integer_Text_IO;
with Ada.Text_IO.Text_Streams;
use Ada.Text_IO.Text_Streams;
with Ada.Text_IO.Unbounded_IO;
use Ada.Text_IO.Unbounded_IO;
with Ada.Real_Time;
use Ada.Real_Time;
procedure CommsTime is
-- Parameters for the experimental run.
-- Experiments - number of data points collected
-- Iterations_Experiment - number of cycles round commstime for a single data point
Experiments : CONSTANT INTEGER := 100;
Iterations_Experiment : CONSTANT INTEGER := 10000;
task PREFIX is
entry Send(Value : in INTEGER);
end PREFIX;
task SEQ_DELTA is
entry Send(Value : in INTEGER);
end SEQ_DELTA;
task SUCC is
entry Send(Value : in INTEGER);
end SUCC;
task PRINTER is
entry Send(Value : in INTEGER);
end PRINTER;
task body PREFIX is
N : INTEGER;
begin
for i in 0..Experiments loop
SEQ_DELTA.Send(0);
for j in 0..Iterations_Experiment loop
accept Send(Value : in INTEGER) do
N := Value;
end;
SEQ_DELTA.Send(N);
end loop;
-- Accept last value in
accept Send(Value : in INTEGER);
end loop;
end PREFIX;
task body SEQ_DELTA is
N : INTEGER;
begin
for i in 0..Experiments loop
for j in 0..Iterations_Experiment loop
accept Send(Value : in INTEGER) do
N := Value;
end;
PRINTER.Send(Value => N);
SUCC.Send(Value => N);
end loop;
end loop;
end SEQ_DELTA;
task body SUCC is
N : INTEGER;
begin
for i in 0..Experiments loop
for j in 0..Iterations_Experiment loop
accept Send(Value : in INTEGER) do
N := Value;
end;
PREFIX.Send(N + 1);
end loop;
end loop;
end SUCC;
task body PRINTER is
N : INTEGER;
Start : Time;
Total : Time_Span;
Results : File_Type;
begin
Create(File => Results, Mode => Out_File, Name => "ct_ada.csv");
for i in 0..Experiments loop
Start := Clock;
for j in 0..Iterations_Experiment loop
accept Send(Value : in INTEGER) do
N := Value;
end;
end loop;
-- Divide by iterations, then convert to nanos.
-- Four communications.
Total := (((Clock - Start) / Iterations_Experiment) * 1000000000) / 4;
Put_Line(results, Float'Image(Float(To_Duration(Total))));
Put(".");
end loop;
Close(Results);
end PRINTER;
begin
Put_Line("Communication Time Benchmark");
end CommsTime;
|
<ADSWorkspace Revision="1" Version="100">
<Workspace Name="">
<LibraryDefs Name="lib.defs" />
<ConfigFile Name="de_sim.cfg" />
<Library Name="ads_standard_layers" />
<Library Name="ads_schematic_layers" />
<Library Name="empro_standard_layers" />
<Library Name="ads_builtin" />
<Library Name="ads_standard_layers_ic" />
<Library Name="ads_schematic_layers_ic" />
<Library Name="ads_schematic_ports_ic" />
<Library Name="ads_rflib" />
<Library Name="ads_sources" />
<Library Name="ads_simulation" />
<Library Name="ads_tlines" />
<Library Name="ads_bondwires" />
<Library Name="ads_datacmps" />
<Library Name="ads_behavioral" />
<Library Name="ads_textfonts" />
<Library Name="ads_common_cmps" />
<Library Name="ads_designs" />
<Library Name="ads_pelib" />
<Library Name="projet_lib" />
<ConfigFile Name="hpeesofsim.cfg" />
</Workspace>
</ADSWorkspace>
|
-- This package has been generated automatically by GNATtest.
-- Do not edit any part of it, see GNATtest documentation for more details.
-- begin read only
with GNATtest_Generated;
package Tk.TopLevel.Toplevel_Options_Test_Data.Toplevel_Options_Tests is
type Test_Toplevel_Options is new GNATtest_Generated.GNATtest_Standard.Tk
.TopLevel
.Toplevel_Options_Test_Data
.Test_Toplevel_Options with
null record;
procedure Test_Configure_0076be_a80d92
(Gnattest_T: in out Test_Toplevel_Options);
-- tk-toplevel.ads:84:4:Configure:Test_Configure_TopLevel
end Tk.TopLevel.Toplevel_Options_Test_Data.Toplevel_Options_Tests;
-- end read only
|
with Ada.Text_IO, Numerics, Numerics.Sparse_Matrices, Chebyshev;
use Ada.Text_IO, Numerics, Numerics.Sparse_Matrices, Chebyshev;
procedure Forward_AD.Test is
use Real_Functions;
function Lagrangian (Pos, Vel : in Real_Array; T : in Real) return AD_Type;
function Lagrangian (Pos, Vel : in Real_Array; T : in Real) return AD_Type is
Q : AD_Vector := Var (Pos);
N : constant Nat := Pos'Length;
Result : AD_Type := Q (1); -- ** 2;
begin
for K in 2 .. N loop
Result := Result + Q (K); -- * Q (K);
end loop;
return Result;
end Lagrangian;
N : constant Nat := 4;
A : AD_Type;
Q, V : Real_Array (1 .. N);
L : constant Real := -1.7;
R : constant Real := 12.0;
X : Real_Array := Chebyshev_Gauss_Lobatto (N, L, R);
D : Real_Matrix := Derivative_Matrix (N, L, R);
Mat : Sparse_Matrix := Sparse (D);
B : Sparse_Vector;
begin
for I in X'Range loop
Q (I) := Sin (X (I));
Put_Line (Real'Image (X (I)) & " " & Real'Image (Cos (X (I))));
end loop;
V := Q;
A := Lagrangian (Q, V, 0.0);
B := Grad (A);
Print (B);
Print (D * Sparse (Q));
Put ("2nd: ");
Print (Mat * Sparse (Q));
Print (D * Sparse (Q));
Put_Line ("length = " & Int'Image (Length (B)));
null;
end Forward_AD.Test;
|
package body iconv.Generic_Strings is
use type Ada.Streams.Stream_Element_Offset;
pragma Compile_Time_Error (
String_Type'Component_Size /= Character_Type'Size,
"String_Type is not packed");
pragma Compile_Time_Error (
Character_Type'Size rem Ada.Streams.Stream_Element'Size /= 0,
"String_Type could not be treated as Stream_Element_Array");
-- decoder
function From (
From_Encoding : String;
To_Encoding : String := Default_Encoding)
return Decoder is
begin
return Result : Decoder do
Do_Open (Converter (Result), To => To_Encoding, From => From_Encoding);
end return;
end From;
procedure Decode (
Object : in Decoder;
In_Item : in Ada.Streams.Stream_Element_Array;
In_Last : out Ada.Streams.Stream_Element_Offset;
Out_Item : out String_Type;
Out_Last : out Natural;
Finish : in Boolean;
Status : out Subsequence_Status_Type)
is
CS_In_SE : constant Ada.Streams.Stream_Element_Count :=
Character_Type'Size / Ada.Streams.Stream_Element'Size;
Out_Item_2 :
Ada.Streams.Stream_Element_Array (1 .. Out_Item'Length * CS_In_SE);
for Out_Item_2'Address use Out_Item'Address;
Out_Last_2 : Ada.Streams.Stream_Element_Offset;
begin
Convert (
Object,
In_Item,
In_Last,
Out_Item_2,
Out_Last_2,
Finish => Finish,
Status => Status);
pragma Assert (Out_Last_2 rem CS_In_SE = 0);
Out_Last := Out_Item'First + Natural (Out_Last_2 / CS_In_SE) - 1;
end Decode;
procedure Decode (
Object : in Decoder;
In_Item : in Ada.Streams.Stream_Element_Array;
In_Last : out Ada.Streams.Stream_Element_Offset;
Out_Item : out String_Type;
Out_Last : out Natural;
Status : out Continuing_Status_Type)
is
CS_In_SE : constant Ada.Streams.Stream_Element_Count :=
Character_Type'Size / Ada.Streams.Stream_Element'Size;
Out_Item_2 :
Ada.Streams.Stream_Element_Array (1 .. Out_Item'Length * CS_In_SE);
for Out_Item_2'Address use Out_Item'Address;
Out_Last_2 : Ada.Streams.Stream_Element_Offset;
begin
Convert (
Object,
In_Item,
In_Last,
Out_Item_2,
Out_Last_2,
Status => Status);
pragma Assert (Out_Last_2 rem CS_In_SE = 0);
Out_Last := Out_Item'First + Natural (Out_Last_2 / CS_In_SE) - 1;
end Decode;
procedure Decode (
Object : in Decoder;
Out_Item : out String_Type;
Out_Last : out Natural;
Finish : in True_Only;
Status : out Finishing_Status_Type)
is
CS_In_SE : constant Ada.Streams.Stream_Element_Count :=
Character_Type'Size / Ada.Streams.Stream_Element'Size;
Out_Item_2 :
Ada.Streams.Stream_Element_Array (1 .. Out_Item'Length * CS_In_SE);
for Out_Item_2'Address use Out_Item'Address;
Out_Last_2 : Ada.Streams.Stream_Element_Offset;
begin
Convert (
Object,
Out_Item_2,
Out_Last_2,
Finish => Finish,
Status => Status);
pragma Assert (Out_Last_2 rem CS_In_SE = 0);
Out_Last := Out_Item'First + Natural (Out_Last_2 / CS_In_SE) - 1;
end Decode;
procedure Decode (
Object : in Decoder;
In_Item : in Ada.Streams.Stream_Element_Array;
In_Last : out Ada.Streams.Stream_Element_Offset;
Out_Item : out String_Type;
Out_Last : out Natural;
Finish : in True_Only;
Status : out Status_Type)
is
CS_In_SE : constant Ada.Streams.Stream_Element_Count :=
Character_Type'Size / Ada.Streams.Stream_Element'Size;
Out_Item_2 :
Ada.Streams.Stream_Element_Array (1 .. Out_Item'Length * CS_In_SE);
for Out_Item_2'Address use Out_Item'Address;
Out_Last_2 : Ada.Streams.Stream_Element_Offset;
begin
Convert (
Object,
In_Item,
In_Last,
Out_Item_2,
Out_Last_2,
Finish => Finish,
Status => Status);
pragma Assert (Out_Last_2 rem CS_In_SE = 0);
Out_Last := Out_Item'First + Natural (Out_Last_2 / CS_In_SE) - 1;
end Decode;
procedure Decode (
Object : in Decoder;
In_Item : in Ada.Streams.Stream_Element_Array;
In_Last : out Ada.Streams.Stream_Element_Offset;
Out_Item : out String_Type;
Out_Last : out Natural;
Finish : in True_Only;
Status : out Substituting_Status_Type)
is
CS_In_SE : constant Ada.Streams.Stream_Element_Count :=
Character_Type'Size / Ada.Streams.Stream_Element'Size;
Out_Item_2 :
Ada.Streams.Stream_Element_Array (1 .. Out_Item'Length * CS_In_SE);
for Out_Item_2'Address use Out_Item'Address;
Out_Last_2 : Ada.Streams.Stream_Element_Offset;
begin
Convert (
Object,
In_Item,
In_Last,
Out_Item_2,
Out_Last_2,
Finish => Finish,
Status => Status);
pragma Assert (Out_Last_2 rem CS_In_SE = 0);
Out_Last := Out_Item'First + Natural (Out_Last_2 / CS_In_SE) - 1;
end Decode;
function Decode (Object : Decoder; S : Ada.Streams.Stream_Element_Array)
return String_Type
is
In_Last : Ada.Streams.Stream_Element_Offset := S'First - 1;
Result : String_Type (1 .. Max_Length_Of_Single_Character * S'Length);
Out_Last : Natural := 0;
Status : Substituting_Status_Type;
begin
loop
Decode (
Object,
S (In_Last + 1 .. S'Last),
In_Last,
Result (Out_Last + 1 .. Result'Last),
Out_Last,
Finish => True,
Status => Status);
case Status is
when Finished =>
exit;
when Success =>
null;
when Overflow =>
raise Constraint_Error;
end case;
end loop;
return Result (Result'First .. Out_Last);
end Decode;
-- encoder
function To (
To_Encoding : String;
From_Encoding : String := Default_Encoding)
return Encoder is
begin
return Result : Encoder do
Do_Open (Converter (Result), To => To_Encoding, From => From_Encoding);
end return;
end To;
procedure Encode (
Object : in Encoder;
In_Item : in String_Type;
In_Last : out Natural;
Out_Item : out Ada.Streams.Stream_Element_Array;
Out_Last : out Ada.Streams.Stream_Element_Offset;
Finish : in Boolean;
Status : out Subsequence_Status_Type)
is
CS_In_SE : constant Ada.Streams.Stream_Element_Count :=
Character_Type'Size / Ada.Streams.Stream_Element'Size;
In_Item_2 : Ada.Streams.Stream_Element_Array (1 .. In_Item'Length * CS_In_SE);
for In_Item_2'Address use In_Item'Address;
In_Last_2 : Ada.Streams.Stream_Element_Offset;
begin
Convert (
Object,
In_Item_2,
In_Last_2,
Out_Item,
Out_Last,
Finish => Finish,
Status => Status);
pragma Assert (In_Last_2 rem CS_In_SE = 0);
In_Last := In_Item'First + Natural (In_Last_2 / CS_In_SE) - 1;
end Encode;
procedure Encode (
Object : in Encoder;
In_Item : in String_Type;
In_Last : out Natural;
Out_Item : out Ada.Streams.Stream_Element_Array;
Out_Last : out Ada.Streams.Stream_Element_Offset;
Status : out Continuing_Status_Type)
is
CS_In_SE : constant Ada.Streams.Stream_Element_Count :=
Character_Type'Size / Ada.Streams.Stream_Element'Size;
In_Item_2 : Ada.Streams.Stream_Element_Array (1 .. In_Item'Length * CS_In_SE);
for In_Item_2'Address use In_Item'Address;
In_Last_2 : Ada.Streams.Stream_Element_Offset;
begin
Convert (
Object,
In_Item_2,
In_Last_2,
Out_Item,
Out_Last,
Status => Status);
pragma Assert (In_Last_2 rem CS_In_SE = 0);
In_Last := In_Item'First + Natural (In_Last_2 / CS_In_SE) - 1;
end Encode;
procedure Encode (
Object : in Encoder;
In_Item : in String_Type;
In_Last : out Natural;
Out_Item : out Ada.Streams.Stream_Element_Array;
Out_Last : out Ada.Streams.Stream_Element_Offset;
Finish : in True_Only;
Status : out Status_Type)
is
CS_In_SE : constant Ada.Streams.Stream_Element_Count :=
Character_Type'Size / Ada.Streams.Stream_Element'Size;
In_Item_2 : Ada.Streams.Stream_Element_Array (1 .. In_Item'Length * CS_In_SE);
for In_Item_2'Address use In_Item'Address;
In_Last_2 : Ada.Streams.Stream_Element_Offset;
begin
Convert (
Object,
In_Item_2,
In_Last_2,
Out_Item,
Out_Last,
Finish => Finish,
Status => Status);
pragma Assert (In_Last_2 rem CS_In_SE = 0);
In_Last := In_Item'First + Natural (In_Last_2 / CS_In_SE) - 1;
end Encode;
procedure Encode (
Object : in Encoder;
In_Item : in String_Type;
In_Last : out Natural;
Out_Item : out Ada.Streams.Stream_Element_Array;
Out_Last : out Ada.Streams.Stream_Element_Offset;
Finish : in True_Only;
Status : out Substituting_Status_Type)
is
CS_In_SE : constant Ada.Streams.Stream_Element_Count :=
Character_Type'Size / Ada.Streams.Stream_Element'Size;
In_Item_2 : Ada.Streams.Stream_Element_Array (1 .. In_Item'Length * CS_In_SE);
for In_Item_2'Address use In_Item'Address;
In_Last_2 : Ada.Streams.Stream_Element_Offset;
begin
Convert (
Object,
In_Item_2,
In_Last_2,
Out_Item,
Out_Last,
Finish => Finish,
Status => Status);
pragma Assert (In_Last_2 rem CS_In_SE = 0);
In_Last := In_Item'First + Natural (In_Last_2 / CS_In_SE) - 1;
end Encode;
function Encode (Object : Encoder; S : String_Type)
return Ada.Streams.Stream_Element_Array
is
CS_In_SE : constant Ada.Streams.Stream_Element_Count :=
Character_Type'Size / Ada.Streams.Stream_Element'Size;
In_Last : Natural := S'First - 1;
Result :
Ada.Streams.Stream_Element_Array (
0 .. CS_In_SE * Max_Length_Of_Single_Character * S'Length - 1);
Out_Last : Ada.Streams.Stream_Element_Offset := -1;
Status : Substituting_Status_Type;
begin
loop
Encode (
Object,
S (In_Last + 1 .. S'Last),
In_Last,
Result (Out_Last + 1 .. Result'Last),
Out_Last,
Finish => True,
Status => Status);
case Status is
when Finished =>
exit;
when Success =>
null;
when Overflow =>
raise Constraint_Error;
end case;
end loop;
return Result (Result'First .. Out_Last);
end Encode;
end iconv.Generic_Strings;
|
with AVTAS.LMCP.Types;
with LMCP_Message_Conversions; use LMCP_Message_Conversions;
package body Assignment_Tree_Branch_Bound_Communication is
----------------
-- Initialize --
----------------
procedure Initialize
(This : out Assignment_Tree_Branch_Bound_Mailbox;
Source_Group : String;
Unique_Id : Int64;
Entity_Id : UInt32;
Service_Id : UInt32)
is
begin
-- The procedure UxAS.Comms.LMCP_Net_Client.Initialize_Network_Client()
-- will also initialize its Message_Sender_Pipe component but will not
-- use it for sending:
--
-- This.Message_Sender_Pipe.Initialize_Push
-- (Source_Group => Value (This.Message_Source_Group),
-- Entity_Id => This.Entity_Id,
-- Service_Id => UInt32 (This.Network_Id));
This.Message_Sender_Pipe.Initialize_Push
(Source_Group => Source_Group,
Entity_Id => AVTAS.LMCP.Types.UInt32 (Entity_Id),
Service_Id => AVTAS.LMCP.Types.UInt32 (Service_Id));
This.Unique_Entity_Send_Message_Id := Unique_Id;
end Initialize;
--------------------------
-- sendBroadcastMessage --
--------------------------
-- this is sendSharedLMCPObjectBroadcastMessage(), in our code Send_Shared_LMCP_Object_Broadcast_Message
procedure sendBroadcastMessage
(This : in out Assignment_Tree_Branch_Bound_Mailbox;
Msg : Message_Root'Class)
is
begin
This.Unique_Entity_Send_Message_Id := This.Unique_Entity_Send_Message_Id + 1;
-- This.Message_Sender_Pipe.Send_Shared_Broadcast_Message (Msg);
This.Message_Sender_Pipe.Send_Shared_Broadcast_Message (As_Object_Any (Msg));
end sendBroadcastMessage;
----------------------
-- sendErrorMessage --
----------------------
procedure sendErrorMessage
(This : in out Assignment_Tree_Branch_Bound_Mailbox;
Error_String : Unbounded_String)
is
KVP : KeyValuePair := (Key => To_Unbounded_String ("No UniqueAutomationResponse"),
Value => Error_String);
Message : ServiceStatus;
begin
Message.StatusType := Error;
Message.Info := Add (Message.Info, KVP);
This.Unique_Entity_Send_Message_Id := This.Unique_Entity_Send_Message_Id + 1;
This.Message_Sender_Pipe.Send_Shared_Broadcast_Message (As_Object_Any (Message));
end sendErrorMessage;
end Assignment_Tree_Branch_Bound_Communication;
|
with Text_Io;
with Ccl;
with Nfa;
with Parse_Shift_Reduce;
with Parse_Goto;
with Misc_Defs;
use Misc_Defs;
with External_File_Manager;
use External_File_Manager;
package Parse_Tokens is
subtype YYSType is Integer;
YYLVal, YYVal : YYSType;
type Token is
(End_Of_Input, Error, Char, Number,
Sectend, Scdecl, Xscdecl,
Whitespace, Name, Prevccl,
Eof_Op, Newline, '^',
'<', '>', ',',
'$', '|', '/',
'*', '+', '?',
'{', '}', '.',
'"', '(', ')',
'[', ']', '-' );
Syntax_Error : exception;
end Parse_Tokens;
|
------------------------------------------------------------------------------
-- --
-- GNAT RUN-TIME COMPONENTS --
-- --
-- A D A . N U M E R I C S . D I S C R E T E _ R A N D O M --
-- --
-- B o d y --
-- --
-- Copyright (C) 1992-2005, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 2, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
-- for more details. You should have received a copy of the GNU General --
-- Public License distributed with GNAT; see file COPYING. If not, write --
-- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
-- Boston, MA 02110-1301, USA. --
-- --
-- As a special exception, if other files instantiate generics from this --
-- unit, or you link this unit with other files to produce an executable, --
-- this unit does not by itself cause the resulting executable to be --
-- covered by the GNU General Public License. This exception does not --
-- however invalidate any other reasons why the executable file might be --
-- covered by the GNU Public License. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
with Ada.Calendar;
with Interfaces; use Interfaces;
package body Ada.Numerics.Discrete_Random is
-------------------------
-- Implementation Note --
-------------------------
-- The design of this spec is very awkward, as a result of Ada 95 not
-- permitting in-out parameters for function formals (most naturally
-- Generator values would be passed this way). In pure Ada 95, the only
-- solution is to use the heap and pointers, and, to avoid memory leaks,
-- controlled types.
-- This is awfully heavy, so what we do is to use Unrestricted_Access to
-- get a pointer to the state in the passed Generator. This works because
-- Generator is a limited type and will thus always be passed by reference.
type Pointer is access all State;
Need_64 : constant Boolean := Rst'Pos (Rst'Last) > Int'Last;
-- Set if we need more than 32 bits in the result. In practice we will
-- only use the meaningful 48 bits of any 64 bit number generated, since
-- if more than 48 bits are required, we split the computation into two
-- separate parts, since the algorithm does not behave above 48 bits.
-----------------------
-- Local Subprograms --
-----------------------
function Square_Mod_N (X, N : Int) return Int;
pragma Inline (Square_Mod_N);
-- Computes X**2 mod N avoiding intermediate overflow
-----------
-- Image --
-----------
function Image (Of_State : State) return String is
begin
return Int'Image (Of_State.X1) &
',' &
Int'Image (Of_State.X2) &
',' &
Int'Image (Of_State.Q);
end Image;
------------
-- Random --
------------
function Random (Gen : Generator) return Rst is
Genp : constant Pointer := Gen.Gen_State'Unrestricted_Access;
Temp : Int;
TF : Flt;
begin
-- Check for flat range here, since we are typically run with checks
-- off, note that in practice, this condition will usually be static
-- so we will not actually generate any code for the normal case.
if Rst'Last < Rst'First then
raise Constraint_Error;
end if;
-- Continue with computation if non-flat range
Genp.X1 := Square_Mod_N (Genp.X1, Genp.P);
Genp.X2 := Square_Mod_N (Genp.X2, Genp.Q);
Temp := Genp.X2 - Genp.X1;
-- Following duplication is not an error, it is a loop unwinding!
if Temp < 0 then
Temp := Temp + Genp.Q;
end if;
if Temp < 0 then
Temp := Temp + Genp.Q;
end if;
TF := Offs + (Flt (Temp) * Flt (Genp.P) + Flt (Genp.X1)) * Genp.Scl;
-- Pathological, but there do exist cases where the rounding implicit
-- in calculating the scale factor will cause rounding to 'Last + 1.
-- In those cases, returning 'First results in the least bias.
if TF >= Flt (Rst'Pos (Rst'Last)) + 0.5 then
return Rst'First;
elsif Need_64 then
return Rst'Val (Interfaces.Integer_64 (TF));
else
return Rst'Val (Int (TF));
end if;
end Random;
-----------
-- Reset --
-----------
procedure Reset (Gen : Generator; Initiator : Integer) is
Genp : constant Pointer := Gen.Gen_State'Unrestricted_Access;
X1, X2 : Int;
begin
X1 := 2 + Int (Initiator) mod (K1 - 3);
X2 := 2 + Int (Initiator) mod (K2 - 3);
for J in 1 .. 5 loop
X1 := Square_Mod_N (X1, K1);
X2 := Square_Mod_N (X2, K2);
end loop;
-- Eliminate effects of small Initiators
Genp.all :=
(X1 => X1,
X2 => X2,
P => K1,
Q => K2,
FP => K1F,
Scl => Scal);
end Reset;
-----------
-- Reset --
-----------
procedure Reset (Gen : Generator) is
Genp : constant Pointer := Gen.Gen_State'Unrestricted_Access;
Now : constant Calendar.Time := Calendar.Clock;
X1 : Int;
X2 : Int;
begin
X1 := Int (Calendar.Year (Now)) * 12 * 31 +
Int (Calendar.Month (Now) * 31) +
Int (Calendar.Day (Now));
X2 := Int (Calendar.Seconds (Now) * Duration (1000.0));
X1 := 2 + X1 mod (K1 - 3);
X2 := 2 + X2 mod (K2 - 3);
-- Eliminate visible effects of same day starts
for J in 1 .. 5 loop
X1 := Square_Mod_N (X1, K1);
X2 := Square_Mod_N (X2, K2);
end loop;
Genp.all :=
(X1 => X1,
X2 => X2,
P => K1,
Q => K2,
FP => K1F,
Scl => Scal);
end Reset;
-----------
-- Reset --
-----------
procedure Reset (Gen : Generator; From_State : State) is
Genp : constant Pointer := Gen.Gen_State'Unrestricted_Access;
begin
Genp.all := From_State;
end Reset;
----------
-- Save --
----------
procedure Save (Gen : Generator; To_State : out State) is
begin
To_State := Gen.Gen_State;
end Save;
------------------
-- Square_Mod_N --
------------------
function Square_Mod_N (X, N : Int) return Int is
begin
return Int ((Integer_64 (X) ** 2) mod (Integer_64 (N)));
end Square_Mod_N;
-----------
-- Value --
-----------
function Value (Coded_State : String) return State is
Last : constant Natural := Coded_State'Last;
Start : Positive := Coded_State'First;
Stop : Positive := Coded_State'First;
Outs : State;
begin
while Stop <= Last and then Coded_State (Stop) /= ',' loop
Stop := Stop + 1;
end loop;
if Stop > Last then
raise Constraint_Error;
end if;
Outs.X1 := Int'Value (Coded_State (Start .. Stop - 1));
Start := Stop + 1;
loop
Stop := Stop + 1;
exit when Stop > Last or else Coded_State (Stop) = ',';
end loop;
if Stop > Last then
raise Constraint_Error;
end if;
Outs.X2 := Int'Value (Coded_State (Start .. Stop - 1));
Outs.Q := Int'Value (Coded_State (Stop + 1 .. Last));
Outs.P := Outs.Q * 2 + 1;
Outs.FP := Flt (Outs.P);
Outs.Scl := (RstL - RstF + 1.0) / (Flt (Outs.P) * Flt (Outs.Q));
-- Now do *some* sanity checks
if Outs.Q < 31
or else Outs.X1 not in 2 .. Outs.P - 1
or else Outs.X2 not in 2 .. Outs.Q - 1
then
raise Constraint_Error;
end if;
return Outs;
end Value;
end Ada.Numerics.Discrete_Random;
|
-- { dg-do compile }
with Unchecked_Conversion;
procedure warn2 is
type R1 is record X : Integer; end record;
type R2 is record X, Y : Integer; end record;
pragma Warnings
(Off, "types for unchecked conversion have different sizes");
function F is new Unchecked_Conversion (R1, R2);
pragma Warnings
(On, "types for unchecked conversion have different sizes");
begin
null;
end warn2;
|
------------------------------------------------------------------------------
-- --
-- GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS --
-- --
-- S Y S T E M . S T A C K _ C H E C K I N G . O P E R A T I O N S --
-- --
-- S p e c --
-- --
-- Copyright (C) 1999-2020, Free Software Foundation, Inc. --
-- --
-- GNARL is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. --
-- --
-- As a special exception under Section 7 of GPL version 3, you are granted --
-- additional permissions described in the GCC Runtime Library Exception, --
-- version 3.1, as published by the Free Software Foundation. --
-- --
-- You should have received a copy of the GNU General Public License and --
-- a copy of the GCC Runtime Library Exception along with this program; --
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
-- <http://www.gnu.org/licenses/>. --
-- --
-- GNARL was developed by the GNARL team at Florida State University. --
-- Extensive contributions were provided by Ada Core Technologies, Inc. --
-- --
------------------------------------------------------------------------------
-- This package provides a implementation of stack checking operations using
-- comparison with stack base and limit.
pragma Restrictions (No_Elaboration_Code);
-- We want to guarantee the absence of elaboration code because the binder
-- does not handle references to this package.
with System.Storage_Elements;
package System.Stack_Checking.Operations is
pragma Preelaborate;
procedure Update_Stack_Cache (Stack : Stack_Access);
-- Set the stack cache for the current task. Note that this is only for
-- optimization purposes, nothing can be assumed about the contents of the
-- cache at any time, see Set_Stack_Info.
--
-- The stack cache should contain the bounds of the current task. But
-- because the RTS is not aware of task switches, the stack cache may be
-- incorrect. So when the stack pointer is not within the bounds of the
-- stack cache, Stack_Check first update the cache (which is a costly
-- operation hence the need of a cache).
procedure Invalidate_Stack_Cache (Any_Stack : Stack_Access);
-- Invalidate cache entries for the task T that owns Any_Stack. This causes
-- the Set_Stack_Info function to be called during the next stack check
-- done by T. This can be used to interrupt task T asynchronously.
-- Stack_Check should be called in loops for this to work reliably.
function Stack_Check (Stack_Address : System.Address) return Stack_Access;
-- This version of Stack_Check should not be inlined
procedure Notify_Stack_Attributes
(Initial_SP : System.Address;
Size : System.Storage_Elements.Storage_Offset);
-- Register Initial_SP as the initial stack pointer value for the current
-- task when it starts and Size as the associated stack area size. This
-- should be called once, after the soft-links have been initialized and
-- prior to the first "Stack_Check" call.
private
Cache : aliased Stack_Access := Null_Stack;
pragma Export (C, Cache, "_gnat_stack_cache");
pragma Export (C, Stack_Check, "_gnat_stack_check");
end System.Stack_Checking.Operations;
|
with kv.avm.Actor_References;
with kv.avm.Control;
package kv.avm.Services is
-- Machines have a collection of services that will send messages
-- to their destination when the time is right. The messages are
-- service dependent, as is the timing.
--
-- Since services may monitor asynchronous events, they may involve
-- different threads of execution. This must be managed in their
-- Execute method which is called from the Machine's thread. If
-- a message is to be sent, it must be sent from this call tree.
type Service_Interface is interface;
type Service_Access is access Service_Interface'CLASS;
procedure Set_Destination
(Self : in out Service_Interface;
Destination : in kv.avm.Actor_References.Actor_Reference_Type) is abstract;
procedure Set_Machine
(Self : in out Service_Interface;
Machine : in kv.avm.Control.Control_Access) is abstract;
procedure Execute
(Self : in out Service_Interface) is abstract;
function Get_Destination(Self : Service_Interface) return kv.avm.Actor_References.Actor_Reference_Type is abstract;
procedure Foo;
end kv.avm.Services;
|
-- BinToAsc.Base16
-- Binary data to ASCII codecs - Base16 codec as in RFC4648
-- Copyright (c) 2015, James Humphry - see LICENSE file for details
generic
Alphabet : Alphabet_16;
Case_Sensitive : Boolean;
package BinToAsc.Base16 is
type Base16_To_String is new Codec_To_String with null record;
overriding
procedure Reset (C : out Base16_To_String);
overriding
function Input_Group_Size (C : in Base16_To_String) return Positive is (1);
overriding
function Output_Group_Size (C : in Base16_To_String) return Positive is (2);
overriding
procedure Process (C : in out Base16_To_String;
Input : in Bin;
Output : out String;
Output_Length : out Natural)
with Post => (Output_Length = 2);
overriding
procedure Process (C : in out Base16_To_String;
Input : in Bin_Array;
Output : out String;
Output_Length : out Natural)
with Post => (Output_Length / 2 = Input'Length and
Output_Length mod 2 = 0);
overriding
procedure Complete (C : in out Base16_To_String;
Output : out String;
Output_Length : out Natural)
with Post => (Output_Length = 0 or Output_Length = 2);
function To_String (Input : in Bin_Array) return String;
type Base16_To_Bin is new Codec_To_Bin with private;
overriding
procedure Reset (C : out Base16_To_Bin);
overriding
function Input_Group_Size (C : in Base16_To_Bin) return Positive is (2);
overriding
function Output_Group_Size (C : in Base16_To_Bin) return Positive is (1);
overriding
procedure Process (C : in out Base16_To_Bin;
Input : in Character;
Output : out Bin_Array;
Output_Length : out Bin_Array_Index)
with Post => (Output_Length = 0 or Output_Length = 1);
overriding
procedure Process (C : in out Base16_To_Bin;
Input : in String;
Output : out Bin_Array;
Output_Length : out Bin_Array_Index)
with Post => (Output_Length = Input'Length / 2 or
Output_Length = Input'Length / 2 + 1 or
C.State = Failed);
overriding
procedure Complete (C : in out Base16_To_Bin;
Output : out Bin_Array;
Output_Length : out Bin_Array_Index)
with Post => (Output_Length = 0);
function To_Bin (Input : in String) return Bin_Array;
private
subtype Half_Bin is Bin range 0..15;
type Base16_To_Bin is new Codec_To_Bin with
record
Loaded : Boolean := False;
Load : Half_Bin := 0;
end record;
end BinToAsc.Base16;
|
-- Copyright (c) 2011, Felix Krause <flyx@isobeef.org>
--
-- Permission to use, copy, modify, and/or distribute this software for any
-- purpose with or without fee is hereby granted, provided that the above
-- copyright notice and this permission notice appear in all copies.
--
-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
with System;
with Interfaces.C.Pointers;
with Interfaces.C.Extensions;
with Interfaces.C.Strings;
package GL.CGL is
-- CGL types and constants
subtype CGLContextObject is System.Address;
subtype CGLPixelFormatObject is System.Address;
subtype CGLRendererInfoObject is System.Address;
subtype CGLPBufferObject is System.Address;
type CGLPixelFormatAttribute is (Terminator ,
kCGLPFAAllRenderers ,
kCGLPFATripleBuffer ,
kCGLPFADoubleBuffer ,
kCGLPFAStereo ,
kCGLPFAAuxBuffers ,
kCGLPFAColorSize ,
kCGLPFAAlphaSize ,
kCGLPFADepthSize ,
kCGLPFAStencilSize ,
kCGLPFAAccumSize ,
kCGLPFAMinimumPolicy ,
kCGLPFAMaximumPolicy ,
kCGLPFAOffScreen ,
kCGLPFAFullScreen ,
kCGLPFASampleBuffers ,
kCGLPFASamples ,
kCGLPFAAuxDepthStencil ,
kCGLPFAColorFloat ,
kCGLPFAMultisample ,
kCGLPFASupersample ,
kCGLPFASampleAlpha ,
kCGLPFARendererID ,
kCGLPFASingleRenderer ,
kCGLPFANoRecovery ,
kCGLPFAAccelerated ,
kCGLPFAClosestPolicy ,
kCGLPFARobust ,
kCGLPFABackingStore ,
kCGLPFAMPSafe ,
kCGLPFAWindow ,
kCGLPFAMultiScreen ,
kCGLPFACompliant ,
kCGLPFADisplayMask ,
kCGLPFAPBuffer ,
kCGLPFARemotePBuffer ,
kCGLPFAAllowOfflineRenderers,
kCGLPFAAcceleratedCompute,
kCGLPFAOpenGLProfile ,
kCGLPFAVirtualScreenCount
);
type CGLRendererProperty is (kCGLRPOffScreen ,
kCGLRPFullScreen ,
kCGLRPRendererID ,
kCGLRPAccelerated ,
kCGLRPRobust ,
kCGLRPBackingStore ,
kCGLRPMPSafe ,
kCGLRPWindow ,
kCGLRPMultiScreen ,
kCGLRPCompliant ,
kCGLRPDisplayMask ,
kCGLRPBufferModes ,
kCGLRPColorModes ,
kCGLRPAccumModes ,
kCGLRPDepthModes ,
kCGLRPStencilModes ,
kCGLRPMaxAuxBuffers ,
kCGLRPMaxSampleBuffers ,
kCGLRPMaxSamples ,
kCGLRPSampleModes ,
kCGLRPSampleAlpha ,
kCGLRPVideoMemory ,
kCGLRPTextureMemory ,
kCGLRPGPUVertProcCapable ,
kCGLRPGPUFragProcCapable ,
kCGLRPRendererCount ,
kCGLRPOnline ,
kCGLRPAcceleratedCompute ,
kCGLRPVideoMemoryMegabytes ,
kCGLRPTextureMemoryMegabytes
);
type CGLContextEnable is (kCGLCESwapRectangle ,
kCGLCESwapLimit ,
kCGLCERasterization ,
kCGLCEStateValidation,
kCGLCESurfaceBackingSize,
kCGLCEDisplayListOptimization,
kCGLCEMPEngine ,
kCGLCECrashOnRemovedFunctions
);
type CGLContextParameter is (kCGLCPSwapRectangle ,
kCGLCPSwapInterval ,
kCGLCPDispatchTableSize ,
kCGLCPClientStorage ,
kCGLCPSurfaceTexture ,
kCGLCPSurfaceOrder ,
kCGLCPSurfaceOpacity ,
kCGLCPSurfaceBackingSize ,
kCGLCPSurfaceSurfaceVolatile,
kCGLCPReclaimResources ,
kCGLCPCurrentRendererID ,
kCGLCPGPUVertexProcessing ,
kCGLCPGPUFragmentProcessing ,
kCGLCPHasDrawable ,
kCGLCPMPSwapsInFlight
);
type CGLGlobalOption is (kCGLGOFormatCacheSize ,
kCGLGOClearFormatCache,
kCGLGORetainRenderers ,
kCGLGOResetLibrary ,
kCGLGOUseErrorHandler ,
kCGLGOUseBuildCache
);
type CGLOpenGLProfile is (kCGLOGLPVersion_Legacy ,
kCGLOGLPVersion_3_2_Core
);
type CGLError is (kCGLNoError ,
kCGLBadAttribute ,
kCGLBadProperty ,
kCGLBadPixelFormat ,
kCGLBadRendererInfo ,
kCGLBadContext ,
kCGLBadDrawable ,
kCGLBadDisplay ,
kCGLBadState ,
kCGLBadValue ,
kCGLBadMatch ,
kCGLBadEnumeration ,
kCGLBadOffScreen ,
kCGLBadFullScreen ,
kCGLBadWindow ,
kCGLBadAddress ,
kCGLBadCodeModule ,
kCGLBadAlloc ,
kCGLBadConnection
);
kCGLMonoscopicBit : constant := 16#00000001#;
kCGLStereoscopicBit: constant := 16#00000002#;
kCGLSingleBufferBit: constant := 16#00000004#;
kCGLDoubleBufferBit: constant := 16#00000008#;
kCGLTripleBufferBit: constant := 16#00000010#;
kCGL0Bit : constant := 16#00000001#;
kCGL1Bit : constant := 16#00000002#;
kCGL2Bit : constant := 16#00000004#;
kCGL3Bit : constant := 16#00000008#;
kCGL4Bit : constant := 16#00000010#;
kCGL5Bit : constant := 16#00000020#;
kCGL6Bit : constant := 16#00000040#;
kCGL8Bit : constant := 16#00000080#;
kCGL10Bit : constant := 16#00000100#;
kCGL12Bit : constant := 16#00000200#;
kCGL16Bit : constant := 16#00000400#;
kCGL24Bit : constant := 16#00000800#;
kCGL32Bit : constant := 16#00001000#;
kCGL48Bit : constant := 16#00002000#;
kCGL64Bit : constant := 16#00004000#;
kCGL96Bit : constant := 16#00008000#;
kCGL128Bit : constant := 16#00010000#;
kCGLRGB444Bit : constant := 16#00000040#;
kCGLARGB4444Bit : constant := 16#00000080#;
kCGLRGB444A8Bit : constant := 16#00000100#;
kCGLRGB555Bit : constant := 16#00000200#;
kCGLARGB1555Bit : constant := 16#00000400#;
kCGLRGB555A8Bit : constant := 16#00000800#;
kCGLRGB565Bit : constant := 16#00001000#;
kCGLRGB565A8Bit : constant := 16#00002000#;
kCGLRGB888Bit : constant := 16#00004000#;
kCGLARGB8888Bit : constant := 16#00008000#;
kCGLRGB888A8Bit : constant := 16#00010000#;
kCGLRGB101010Bit : constant := 16#00020000#;
kCGLARGB2101010Bit : constant := 16#00040000#;
kCGLRGB101010_A8Bit: constant := 16#00080000#;
kCGLRGB121212Bit : constant := 16#00100000#;
kCGLARGB12121212Bit: constant := 16#00200000#;
kCGLRGB161616Bit : constant := 16#00400000#;
kCGLRGBA16161616Bit: constant := 16#00800000#;
kCGLRGBFloat64Bit : constant := 16#01000000#;
kCGLRGBAFloat64Bit : constant := 16#02000000#;
kCGLRGBFloat128Bit : constant := 16#04000000#;
kCGLRGBAFloat128Bit: constant := 16#08000000#;
kCGLRGBFloat256Bit : constant := 16#10000000#;
kCGLRGBAFloat256Bit: constant := 16#20000000#;
kCGLSupersampleBit : constant := 16#00000001#;
kCGLMultisampleBit : constant := 16#00000002#;
type CGLPixelFormatAttribute_Array is array (Positive range <>) of
aliased CGLPixelFormatAttribute;
-- Pixel format functions
function CGLChoosePixelFormat (attribs : access CGLPixelFormatAttribute;
pix : access CGLPixelFormatObject;
npix : access GLint) return CGLError;
function CGLDestroyPixelFormat (pix : CGLPixelFormatObject) return CGLError;
function CGLDescribePixelFormat (pix : CGLPixelFormatObject; pix_num : GLint;
attrib : CGLPixelFormatAttribute;
value : access GLint) return CGLError;
procedure CGLReleasePixelFormat (pix : in CGLPixelFormatObject);
function CGLRetainPixelFormat (pix : CGLPixelFormatObject)
return CGLPixelFormatObject;
function CGLGetPixelFormatRetainCount (pix : CGLPixelFormatObject)
return GLuint;
function CGLQueryRendererInfo (display_mask : GLuint;
rend : access CGLRendererInfoObject;
nrend : access GLint) return CGLError;
function CGLDestroyRendererInfo (rend : CGLRendererInfoObject)
return CGLError;
function CGLDescribeRenderer (rend : CGLRendererInfoObject; rend_num : GLint;
prop : CGLRendererProperty;
value : access GLint) return CGLError;
function CGLCreateContext (pix : CGLPixelFormatObject;
share : CGLContextObject;
ctx : access CGLContextObject) return CGLError;
function CGLDestroyContext (ctx : CGLContextObject) return CGLError;
function CGLCopyContext (src, dst : CGLContextObject;
mask : GLbitfield) return CGLError;
function CGLRetainContext (ctx : CGLContextObject) return CGLContextObject;
procedure CGLReleaseContext (ctx : in CGLContextObject);
function CGLGetContextRetainCount (ctx : CGLContextObject) return GLuint;
function CGLGetPixelFormat (ctx : CGLContextObject) return CGLPixelFormatObject;
function CGLCreatePBuffer (width, height : GLsizei;
target, internalFormat : GLenum;
max_level : GLint;
pbuffer : access CGLPBufferObject)
return CGLError;
function CGLDestroyPBuffer (pbuffer : CGLPBufferObject) return CGLError;
function CGLDescribePBuffer (obj : CGLPBufferObject;
width, height : access GLsizei;
target, internalFormat : access GLenum;
mipmap : access GLint) return CGLError;
function CGLTexImagePBuffer (ctx : CGLContextObject;
pbuffer : CGLPBufferObject;
source : GLenum) return CGLError;
function CGLRetainPBuffer (pbuffer : CGLPBufferObject)
return CGLPBufferObject;
procedure CGLReleasePBuffer (pbuffer : in CGLPBufferObject);
function CGLGetPBufferRetainCount (pbuffer : CGLPBufferObject) return GLuint;
function CGLSetOffScreen (ctx : CGLContextObject;
width, height : GLsizei;
rowbytes : GLint;
baseaddr : Interfaces.C.Extensions.void_ptr)
return CGLError;
function CGLGetOffScreen (ctx : CGLContextObject;
width, height : access GLsizei;
rowbytes : access GLint;
baseaddr : access Interfaces.C.Extensions.void_ptr)
return CGLError;
function CGLSetFullScreen (ctx : CGLContextObject) return CGLError;
function CGLSetFullScreenOnDisplay (ctx : CGLContextObject;
display_mask : GLuint) return CGLError;
function CGLSetPBuffer (ctx : CGLContextObject;
pbuffer : CGLPBufferObject;
face : GLenum;
level, screen : GLint) return CGLError;
function CGLGetPBuffer (ctx : CGLContextObject;
pbuffer : access CGLPBufferObject;
face : access GLenum;
level, screen : access GLint) return CGLError;
function CGLClearDrawable (ctx : CGLContextObject) return CGLError;
function CGLFlushDrawable (ctx : CGLContextObject) return CGLError;
function CGLEnable (ctx : CGLContextObject; pname : CGLContextEnable)
return CGLError;
function CGLDisable (ctx : CGLContextObject; pname : CGLContextEnable)
return CGLError;
function CGLIsEnabled (ctx : CGLContextObject; pname : CGLContextEnable;
enable : access GLint) return CGLError;
function CGLSetParameter (ctx : CGLContextObject;
pname : CGLContextParameter;
params : access constant GLint) return CGLError;
function CGLGetParameter (ctx : CGLContextObject;
pname : CGLContextParameter;
params : access GLint) return CGLError;
function CGLSetVirtualScreen (ctx : CGLContextObject; screen : GLint)
return CGLError;
function CGLGetVirtualScreen (ctx : CGLContextObject; screen : access GLint)
return CGLError;
function CGLUpdateContext (ctx : CGLContextObject) return CGLError;
function CGLSetGlobalOption (pname : CGLGlobalOption;
params : access constant GLint) return CGLError;
function CGLGetGlobalOption (pname : CGLGlobalOption;
params : access GLint) return CGLError;
function CGLSetOption (pname : CGLGlobalOption; param : GLint)
return CGLError;
function CGLGetOption (pname : CGLGlobalOption;
param : access GLint) return CGLError;
function CGLLockContext (ctx : CGLContextObject) return CGLError;
function CGLUnlockContext (ctx : CGLContextObject) return CGLError;
procedure CGLGetVersion (majorvers, minorvers : out GLint);
function CGLErrorString (error : CGLError)
return Interfaces.C.Strings.chars_ptr;
function CGLSetCurrentContext (ctx : CGLContextObject) return CGLError;
function CGLGetCurrentContext return CGLContextObject;
private
C_Enum_Size : constant := 32;
for CGLPixelFormatAttribute use (Terminator => 0,
kCGLPFAAllRenderers => 1,
kCGLPFATripleBuffer => 3,
kCGLPFADoubleBuffer => 5,
kCGLPFAStereo => 6,
kCGLPFAAuxBuffers => 7,
kCGLPFAColorSize => 8,
kCGLPFAAlphaSize => 11,
kCGLPFADepthSize => 12,
kCGLPFAStencilSize => 13,
kCGLPFAAccumSize => 14,
kCGLPFAMinimumPolicy => 51,
kCGLPFAMaximumPolicy => 52,
kCGLPFAOffScreen => 53,
kCGLPFAFullScreen => 54,
kCGLPFASampleBuffers => 55,
kCGLPFASamples => 56,
kCGLPFAAuxDepthStencil => 57,
kCGLPFAColorFloat => 58,
kCGLPFAMultisample => 59,
kCGLPFASupersample => 60,
kCGLPFASampleAlpha => 61,
kCGLPFARendererID => 70,
kCGLPFASingleRenderer => 71,
kCGLPFANoRecovery => 72,
kCGLPFAAccelerated => 73,
kCGLPFAClosestPolicy => 74,
kCGLPFARobust => 75,
kCGLPFABackingStore => 76,
kCGLPFAMPSafe => 78,
kCGLPFAWindow => 80,
kCGLPFAMultiScreen => 81,
kCGLPFACompliant => 83,
kCGLPFADisplayMask => 84,
kCGLPFAPBuffer => 90,
kCGLPFARemotePBuffer => 91,
kCGLPFAAllowOfflineRenderers => 96,
kCGLPFAAcceleratedCompute => 97,
kCGLPFAOpenGLProfile => 99,
kCGLPFAVirtualScreenCount => 128
);
for CGLPixelFormatAttribute'Size use C_Enum_Size;
pragma Convention (C, CGLPixelFormatAttribute);
for CGLRendererProperty use (kCGLRPOffScreen => 53,
kCGLRPFullScreen => 54,
kCGLRPRendererID => 70,
kCGLRPAccelerated => 73,
kCGLRPRobust => 75,
kCGLRPBackingStore => 76,
kCGLRPMPSafe => 78,
kCGLRPWindow => 80,
kCGLRPMultiScreen => 81,
kCGLRPCompliant => 83,
kCGLRPDisplayMask => 84,
kCGLRPBufferModes => 100,
kCGLRPColorModes => 103,
kCGLRPAccumModes => 104,
kCGLRPDepthModes => 105,
kCGLRPStencilModes => 106,
kCGLRPMaxAuxBuffers => 107,
kCGLRPMaxSampleBuffers => 108,
kCGLRPMaxSamples => 109,
kCGLRPSampleModes => 110,
kCGLRPSampleAlpha => 111,
kCGLRPVideoMemory => 120,
kCGLRPTextureMemory => 121,
kCGLRPGPUVertProcCapable => 122,
kCGLRPGPUFragProcCapable => 123,
kCGLRPRendererCount => 128,
kCGLRPOnline => 129,
kCGLRPAcceleratedCompute => 130,
kCGLRPVideoMemoryMegabytes => 131,
kCGLRPTextureMemoryMegabytes => 132
);
for CGLRendererProperty'Size use C_Enum_Size;
pragma Convention (C, CGLRendererProperty);
for CGLContextEnable use (kCGLCESwapRectangle => 201,
kCGLCESwapLimit => 203,
kCGLCERasterization => 221,
kCGLCEStateValidation => 301,
kCGLCESurfaceBackingSize => 305,
kCGLCEDisplayListOptimization => 307,
kCGLCEMPEngine => 313,
kCGLCECrashOnRemovedFunctions => 316
);
for CGLContextEnable'Size use C_Enum_Size;
pragma Convention (C, CGLContextEnable);
for CGLContextParameter use (kCGLCPSwapRectangle => 200,
kCGLCPSwapInterval => 222,
kCGLCPDispatchTableSize => 224,
kCGLCPClientStorage => 226,
kCGLCPSurfaceTexture => 228,
kCGLCPSurfaceOrder => 235,
kCGLCPSurfaceOpacity => 236,
kCGLCPSurfaceBackingSize => 304,
kCGLCPSurfaceSurfaceVolatile => 306,
kCGLCPReclaimResources => 308,
kCGLCPCurrentRendererID => 309,
kCGLCPGPUVertexProcessing => 310,
kCGLCPGPUFragmentProcessing => 311,
kCGLCPHasDrawable => 314,
kCGLCPMPSwapsInFlight => 315
);
for CGLContextParameter'Size use C_Enum_Size;
pragma Convention (C, CGLContextParameter);
for CGLGlobalOption use (kCGLGOFormatCacheSize => 501,
kCGLGOClearFormatCache => 502,
kCGLGORetainRenderers => 503,
kCGLGOResetLibrary => 504,
kCGLGOUseErrorHandler => 505,
kCGLGOUseBuildCache => 506
);
for CGLGlobalOption'Size use C_Enum_Size;
pragma Convention (C, CGLGlobalOption);
for CGLOpenGLProfile use (kCGLOGLPVersion_Legacy => 16#1000#,
kCGLOGLPVersion_3_2_Core => 16#3200#
);
for CGLOpenGLProfile'Size use C_Enum_Size;
pragma Convention (C, CGLOpenGLProfile);
for CGLError use (kCGLNoError => 0,
kCGLBadAttribute => 10000,
kCGLBadProperty => 10001,
kCGLBadPixelFormat => 10002,
kCGLBadRendererInfo => 10003,
kCGLBadContext => 10004,
kCGLBadDrawable => 10005,
kCGLBadDisplay => 10006,
kCGLBadState => 10007,
kCGLBadValue => 10008,
kCGLBadMatch => 10009,
kCGLBadEnumeration => 10010,
kCGLBadOffScreen => 10011,
kCGLBadFullScreen => 10012,
kCGLBadWindow => 10013,
kCGLBadAddress => 10014,
kCGLBadCodeModule => 10015,
kCGLBadAlloc => 10016,
kCGLBadConnection => 10017
);
for CGLError'Size use C_Enum_Size;
pragma Convention (C, CGLError);
pragma Import (C, CGLChoosePixelFormat, "CGLChoosePixelFormat");
pragma Import (C, CGLDestroyPixelFormat, "CGLDestroyPixelFormat");
pragma Import (C, CGLDescribePixelFormat, "CGLDescribePixelFormat");
pragma Import (C, CGLReleasePixelFormat, "CGLReleasePixelFormat");
pragma Import (C, CGLRetainPixelFormat, "CGLRetainPixelFormat");
pragma Import (C, CGLGetPixelFormatRetainCount, "CGLGetPixelFormatRetainCount");
pragma Import (C, CGLQueryRendererInfo, "CGLQueryRendererInfo");
pragma Import (C, CGLDestroyRendererInfo, "CGLDestroyRendererInfo");
pragma Import (C, CGLDescribeRenderer, "CGLDescribeRenderer");
pragma Import (C, CGLCreateContext, "CGLCreateContext");
pragma Import (C, CGLDestroyContext, "CGLDestroyContext");
pragma Import (C, CGLCopyContext, "CGLCopyContext");
pragma Import (C, CGLRetainContext, "CGLRetainContext");
pragma Import (C, CGLReleaseContext, "CGLReleaseContext");
pragma Import (C, CGLGetContextRetainCount, "CGLGetContextRetainCount");
pragma Import (C, CGLGetPixelFormat, "CGLGetPixelFormat");
pragma Import (C, CGLCreatePBuffer, "CGLCreatePBuffer");
pragma Import (C, CGLDestroyPBuffer, "CGLDestroyPBuffer");
pragma Import (C, CGLDescribePBuffer, "CGLDescribePBuffer");
pragma Import (C, CGLTexImagePBuffer, "CGLTexImagePBuffer");
pragma Import (C, CGLRetainPBuffer, "CGLRetainPBuffer");
pragma Import (C, CGLReleasePBuffer, "CGLReleasePBuffer");
pragma Import (C, CGLGetPBufferRetainCount, "CGLGetPBufferRetainCount");
pragma Import (C, CGLSetOffScreen, "CGLSetOffScreen");
pragma Import (C, CGLGetOffScreen, "CGLGetOffScreen");
pragma Import (C, CGLSetFullScreen, "CGLSetFullScreen");
pragma Import (C, CGLSetFullScreenOnDisplay, "CGLSetFullScreenOnDisplay");
pragma Import (C, CGLSetPBuffer, "CGLSetPBuffer");
pragma Import (C, CGLGetPBuffer, "CGLGetPBuffer");
pragma Import (C, CGLClearDrawable, "CGLClearDrawable");
pragma Import (C, CGLFlushDrawable, "CGLFlushDrawable");
pragma Import (C, CGLEnable, "CGLEnable");
pragma Import (C, CGLDisable, "CGLDisable");
pragma Import (C, CGLIsEnabled, "CGLIsEnabled");
pragma Import (C, CGLSetParameter, "CGLSetParameter");
pragma Import (C, CGLGetParameter, "CGLGetParameter");
pragma Import (C, CGLSetVirtualScreen, "CGLSetVirtualScreen");
pragma Import (C, CGLGetVirtualScreen, "CGLGetVirtualScreen");
pragma Import (C, CGLUpdateContext, "CGLUpdateContext");
pragma Import (C, CGLSetGlobalOption, "CGLSetGlobalOption");
pragma Import (C, CGLGetGlobalOption, "CGLGetGlobalOption");
pragma Import (C, CGLSetOption, "CGLSetOption");
pragma Import (C, CGLGetOption, "CGLGetOption");
pragma Import (C, CGLLockContext, "CGLLockContext");
pragma Import (C, CGLUnlockContext, "CGLUnlockContext");
pragma Import (C, CGLGetVersion, "CGLGetVersion");
pragma Import (C, CGLErrorString, "CGLErrorString");
pragma Import (C, CGLSetCurrentContext, "CGLSetCurrentContext");
pragma Import (C, CGLGetCurrentContext, "CGLGetCurrentContext");
end GL.CGL;
|
package CSV is
type Row(<>) is tagged private;
function Line(S: String; Separator: Character := ',') return Row;
function Next(R: in out Row) return Boolean;
-- if there is still an item in R, Next advances to it and returns True
function Item(R: Row) return String;
-- after calling R.Next i times, this returns the i'th item (if any)
private
type Row(Length: Natural) is tagged record
Str: String(1 .. Length);
Fst: Positive;
Lst: Natural;
Nxt: Positive;
Sep: Character;
end record;
end CSV;
|
with Ada.Text_IO, Random_57;
procedure R57 is
use Random_57;
type Fun is access function return Mod_7;
function Rand return Mod_7 renames Random_57.Random7;
-- change this to "... renames Random_57.Simple_Random;" if you like
procedure Test(Sample_Size: Positive; Rand: Fun; Precision: Float := 0.3) is
Counter: array(Mod_7) of Natural := (others => 0);
Expected: Natural := Sample_Size/7;
Small: Mod_7 := Mod_7'First;
Large: Mod_7 := Mod_7'First;
Result: Mod_7;
begin
Ada.Text_IO.New_Line;
Ada.Text_IO.Put_Line("Sample Size: " & Integer'Image(Sample_Size));
Ada.Text_IO.Put( " Bins:");
for I in 1 .. Sample_Size loop
Result := Rand.all;
Counter(Result) := Counter(Result) + 1;
end loop;
for J in Mod_7 loop
Ada.Text_IO.Put(Integer'Image(Counter(J)));
if Counter(J) < Counter(Small) then Small := J; end if;
if Counter(J) > Counter(Large) then Large := J; end if;
end loop;
Ada.Text_IO.New_Line;
Ada.Text_IO.Put_Line(" Small Bin:" & Integer'Image(Counter(Small)));
Ada.Text_IO.Put_Line(" Large Bin: " & Integer'Image(Counter(Large)));
if Float(Counter(Small)*7) * (1.0+Precision) < Float(Sample_Size) then
Ada.Text_IO.Put_Line("Failed! Small too small!");
elsif Float(Counter(Large)*7) * (1.0-Precision) > Float(Sample_Size) then
Ada.Text_IO.Put_Line("Failed! Large too large!");
else
Ada.Text_IO.Put_Line("Passed");
end if;
end Test;
begin
Test( 10_000, Rand'Access, 0.08);
Test( 100_000, Rand'Access, 0.04);
Test( 1_000_000, Rand'Access, 0.02);
Test(10_000_000, Rand'Access, 0.01);
end R57;
|
--
-- Copyright (C) 2022 Jeremy Grosser <jeremy@synack.me>
--
-- SPDX-License-Identifier: BSD-3-Clause
--
with Ada.Unchecked_Conversion;
package body PMS is
function Name
(F : Field)
return String
is
begin
case F is
when Start => return "(start)";
when Length => return "(length)";
when CF1_PM_1 => return "PM1.0";
when CF1_PM_2_5 => return "PM2.5";
when CF1_PM_10 => return "PM10";
when ATM_PM_1 => return "PM1.0 atmosphere";
when ATM_PM_2_5 => return "PM2.5 atmosphere";
when ATM_PM_10 => return "PM10 atmosphere";
when PART_0_3 => return "0.3";
when PART_0_5 => return "0.5";
when PART_1 => return "1.0";
when PART_2_5 => return "2.5";
when PART_5 => return "5.0";
when PART_10 => return "10.0";
when Reserved => return "(reserved)";
when Checksum => return "(checksum)";
end case;
end Name;
function Calculate_Checksum
(Data : Frame)
return UInt16
is
Sum : UInt16 := 0;
begin
for I in Start .. Reserved loop
Sum := Sum + Data (I);
end loop;
return Sum;
end Calculate_Checksum;
procedure Receive
(Port : not null Any_UART_Port;
Data : out Frame;
Status : out UART_Status;
Timeout : Natural := 1_000)
is
function Byte_Swap (Word : UInt16) return UInt16
is (Shift_Right (Word, 8) or Shift_Left (Word, 8));
subtype Raw_Frame is UART_Data_8b (1 .. Frame'Length * 2);
function To_Frame is new Ada.Unchecked_Conversion
(Raw_Frame, Frame);
S : UART_Status;
RF : Raw_Frame;
F : Frame;
begin
Port.Receive (RF, S, Timeout);
Status := S;
if S /= Ok then
return;
end if;
F := To_Frame (RF);
for I in F'Range loop
F (I) := Byte_Swap (F (I));
end loop;
Data := F;
if F (Checksum) /= Calculate_Checksum (F) then
Status := Err_Error;
end if;
end Receive;
end PMS;
|
with Ada.Assertions; use Ada.Assertions;
with Memory.Container; use Memory.Container;
package body Memory.Join is
function Create_Join(parent : access Wrapper_Type'Class;
index : Natural) return Join_Pointer is
result : constant Join_Pointer := new Join_Type;
begin
result.parent := parent;
result.index := index;
return result;
end Create_Join;
function Clone(mem : Join_Type) return Memory_Pointer is
result : constant Join_Pointer := new Join_Type'(mem);
begin
return Memory_Pointer(result);
end Clone;
procedure Read(mem : in out Join_Type;
address : in Address_Type;
size : in Positive) is
begin
Forward_Read(mem.parent.all, mem.index, address, size);
end Read;
procedure Write(mem : in out Join_Type;
address : in Address_Type;
size : in Positive) is
begin
Forward_Write(mem.parent.all, mem.index, address, size);
end Write;
function Get_Writes(mem : Join_Type) return Long_Integer is
begin
Assert(False, "Memory.Join.Get_Writes not implemented");
return 0;
end Get_Writes;
function To_String(mem : Join_Type) return Unbounded_String is
begin
return To_Unbounded_String("(join)");
end To_String;
function Get_Cost(mem : Join_Type) return Cost_Type is
begin
return 0;
end Get_Cost;
function Get_Word_Size(mem : Join_Type) return Positive is
begin
return Get_Word_Size(mem.parent.all);
end Get_Word_Size;
function Get_Ports(mem : Join_Type) return Port_Vector_Type is
result : Port_Vector_Type;
begin
Assert(False, "Memory.Join.Get_Ports should not be called");
return result;
end Get_Ports;
procedure Generate(mem : in Join_Type;
sigs : in out Unbounded_String;
code : in out Unbounded_String) is
name : constant String := "m" & To_String(Get_ID(mem));
word_bits : constant Natural := 8 * Get_Word_Size(mem);
begin
Declare_Signals(sigs, name, word_bits);
end Generate;
function Get_Path_Length(mem : Join_Type) return Natural is
next : constant Memory_Pointer := Get_Memory(mem.parent.all);
jl : constant Natural := Get_Join_Length(mem.parent.all);
begin
return jl + Get_Path_Length(next.all);
end Get_Path_Length;
procedure Adjust(mem : in out Join_Type) is
begin
Adjust(Memory_Type(mem));
mem.parent := null;
end Adjust;
procedure Set_Parent(mem : in out Join_Type;
parent : access Wrapper_Type'Class) is
begin
mem.parent := parent;
end Set_Parent;
function Find_Join(mem : Memory_Pointer) return Join_Pointer is
begin
if mem.all in Join_Type'Class then
return Join_Pointer(mem);
else
declare
cp : constant Container_Pointer := Container_Pointer(mem);
begin
return Find_Join(Get_Memory(cp.all));
end;
end if;
end Find_Join;
end Memory.Join;
|
with Numerics;
use Numerics;
package Numerics.Dense_Matrices is
Error : exception;
function Outer (X, Y : in Real_Vector) return Real_Matrix;
function "*" (X, Y : in Real_Vector) return Real_Matrix renames Outer;
function "*" (X : in Real;
A : in Real_Matrix) return Real_Matrix;
function "*" (A : in Real_Matrix;
X : in Real) return Real_Matrix is (X * A);
function "+" (A : in Real_Matrix) return Real_Matrix is (A);
function "-" (A : in Real_Matrix) return Real_Matrix;
function "+" (A : in Real_Matrix;
B : in Real_Matrix) return Real_Matrix
with Pre => A'Length (1) = B'Length (1) and A'Length (2) = B'Length (2);
function "-" (A : in Real_Matrix;
B : in Real_Matrix) return Real_Matrix
with Pre => A'Length (1) = B'Length (1) and A'Length (2) = B'Length (2);
function "*" (A : in Real_Matrix;
B : in Real_Matrix) return Real_Matrix
with Pre => A'Length (2) = B'Length (1);
function Transpose (A : in Real_Matrix) return Real_Matrix;
function Eye (N : in Pos) return Real_Matrix;
function Eye (N : in Pos) return Int_Matrix;
procedure LU_Decomposition (A : in Real_Matrix;
P : out Int_Array;
L : out Real_Matrix;
U : out Real_Matrix)
with Pre => A'Length (1) = A'Length (2);
procedure Print (X : in Real_Vector);
procedure Print (A : in Real_Matrix);
procedure Print (A : in Int_Matrix);
function Determinant (P : in Int_Array;
L : in Real_Matrix;
U : in Real_Matrix) return Real
with Pre => L'Length (1) = L'Length (2)
and U'Length (1) = U'Length (2)
and L'Length (1) = U'Length (1)
and L'Length (1) = P'Length;
function Determinant (A : in Real_Matrix) return Real
with Pre => A'Length (1) = A'Length (2);
function Solve_Upper (U : in Real_Matrix;
B : in Real_Vector) return Real_Vector
with Pre => U'Length (1) = U'Length (2) and U'Length (1) = B'Length;
function Solve_Lower (L : in Real_Matrix;
B : in Real_Vector) return Real_Vector
with Pre => L'Length (1) = L'Length (2) and L'Length (1) = B'Length;
function Solve (P : in Int_Array;
L : in Real_Matrix;
U : in Real_Matrix;
B : in Real_Vector) return Real_Vector
with Pre => L'Length (1) = L'Length (2)
and U'Length (1) = U'Length (2)
and L'Length (1) = U'Length (1)
and L'Length (1) = P'Length
and L'Length (1) = B'Length;
function Solve (A : in Real_Matrix;
B : in Real_Vector) return Real_Vector
with Pre => A'Length (1) = A'Length (2)
and A'Length (1) = B'Length;
function Inverse (A : in Real_Matrix) return Real_Matrix
with Pre => A'Length (1) = A'Length (2);
function Diag (A : in Real_Matrix) return Real_Vector
with Pre => A'Length (1) = A'Length (2);
function Diag (X : in Real_Vector) return Real_Matrix;
function "and" (A, B : in Real_Matrix) return Real_Matrix;
function "or" (A, B : in Real_Matrix) return Real_Matrix;
function Remove_1st_N (X : in Real_Vector;
N : in Pos) return Real_Vector
with Pre => X'Length > N;
function Remove_1st_N (A : in Real_Matrix;
N : in Pos) return Real_Matrix
with Pre => A'Length (1) > N and A'Length (2) > N;
procedure Copy (From : in Real_Vector;
To : in out Real_Vector;
Start : in Pos)
with Pre => To'Length >= From'Length and To'First <= Start;
procedure Copy (From : in Real_Matrix;
To : in out Real_Matrix;
Start_I : in Pos;
Start_J : in Pos)
with Pre => To'Length (1) >= From'Length (1)
and To'Length (2) >= From'Length (2)
and To'First (1) <= Start_I
and To'First (2) <= Start_J;
private
function Pivoting_Array (A : in Real_Matrix) return Int_Array;
function Permute_Row (A : in Real_Matrix;
P : in Int_Array) return Real_Matrix
with Pre => A'Length (1) = P'Length;
function Permute_Row (X : in Real_Vector;
P : in Int_Array) return Real_Vector
with Pre => X'Length = P'Length;
function Number_Of_Swaps (P : in Int_Array) return Pos;
-- procedure Permute_Col (A : in out Real_Matrix;
-- P : in Int_Array)
-- with Pre => A'Length (2) = P'Length;
end Numerics.Dense_Matrices;
|
-----------------------------------------------------------------------
-- ado-schemas-entities -- Entity types cache
-- Copyright (C) 2011, 2012, 2017, 2018 Stephane Carrez
-- Written by Stephane Carrez (Stephane.Carrez@gmail.com)
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
with Util.Log.Loggers;
with Util.Strings;
with ADO.SQL;
with ADO.Statements;
with ADO.Model;
package body ADO.Schemas.Entities is
Log : constant Util.Log.Loggers.Logger := Util.Log.Loggers.Create ("ADO.Schemas.Entities");
-- ------------------------------
-- Expand the name into a target parameter value to be used in the SQL query.
-- The Expander can return a T_NULL when a value is not found or
-- it may also raise some exception.
-- ------------------------------
overriding
function Expand (Instance : in out Entity_Cache;
Name : in String) return ADO.Parameters.Parameter is
Pos : constant Entity_Map.Cursor := Instance.Entities.Find (Name);
begin
if not Entity_Map.Has_Element (Pos) then
Log.Error ("No entity type associated with table {0}", Name);
raise No_Entity_Type with "No entity type associated with table " & Name;
end if;
return ADO.Parameters.Parameter '(T => ADO.Parameters.T_INTEGER,
Len => 0, Value_Len => 0, Position => 0,
Name => "",
Num => Entity_Type'Pos (Entity_Map.Element (Pos)));
end Expand;
-- ------------------------------
-- Find the entity type index associated with the given database table.
-- Raises the No_Entity_Type exception if no such mapping exist.
-- ------------------------------
function Find_Entity_Type (Cache : in Entity_Cache;
Table : in Class_Mapping_Access) return ADO.Entity_Type is
begin
return Find_Entity_Type (Cache, Table.Table);
end Find_Entity_Type;
-- ------------------------------
-- Find the entity type index associated with the given database table.
-- Raises the No_Entity_Type exception if no such mapping exist.
-- ------------------------------
function Find_Entity_Type (Cache : in Entity_Cache;
Name : in Util.Strings.Name_Access) return ADO.Entity_Type is
Pos : constant Entity_Map.Cursor := Cache.Entities.Find (Name.all);
begin
if not Entity_Map.Has_Element (Pos) then
Log.Error ("No entity type associated with table {0}", Name.all);
raise No_Entity_Type with "No entity type associated with table " & Name.all;
end if;
return Entity_Type (Entity_Map.Element (Pos));
end Find_Entity_Type;
-- ------------------------------
-- Initialize the entity cache by reading the database entity table.
-- ------------------------------
procedure Initialize (Cache : in out Entity_Cache;
Session : in out ADO.Sessions.Session'Class) is
Query : ADO.SQL.Query;
Stmt : ADO.Statements.Query_Statement
:= Session.Create_Statement (ADO.Model.ENTITY_TYPE_TABLE'Access);
Count : Natural := 0;
begin
Stmt.Set_Parameters (Query);
Stmt.Execute;
while Stmt.Has_Elements loop
declare
Id : constant ADO.Entity_Type := ADO.Entity_Type (Stmt.Get_Integer (0));
Name : constant String := Stmt.Get_String (1);
begin
Cache.Entities.Insert (Key => Name, New_Item => Id);
end;
Count := Count + 1;
Stmt.Next;
end loop;
Log.Info ("Loaded {0} table entities", Util.Strings.Image (Count));
exception
when others =>
null;
end Initialize;
end ADO.Schemas.Entities;
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- S Y S T E M . D O U B L E _ R E A L --
-- --
-- S p e c --
-- --
-- Copyright (C) 2021, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. --
-- --
-- --
-- --
-- --
-- --
-- You should have received a copy of the GNU General Public License and --
-- a copy of the GCC Runtime Library Exception along with this program; --
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
-- <http://www.gnu.org/licenses/>. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
-- This package contains routines for supporting floating-point computations
-- in double precision, i.e. using a second number to estimate the error due
-- to rounding and more generally performing computations with twice as many
-- bits of mantissa. It is based on the Double-Double library available at
-- https://www.davidhbailey.com/dhbsoftware written by David H.Bailey et al.
generic
type Num is digits <>;
package System.Double_Real is
pragma Pure;
type Double_T is record
Hi, Lo : Num;
end record;
function To_Double (N : Num) return Double_T is ((Hi => N, Lo => 0.0));
-- Convert a single to a double real
function To_Single (D : Double_T) return Num is (D.Hi);
-- Convert a double to a single real
function Quick_Two_Sum (A, B : Num) return Double_T
with Pre => A = 0.0 or else abs (A) >= abs (B);
-- Compute A + B and its rounding error exactly, but assume |A| >= |B|
function Two_Sum (A, B : Num) return Double_T;
-- Compute A + B and its rounding error exactly
function Two_Diff (A, B : Num) return Double_T;
-- Compute A - B and its rounding error exactly
function Two_Prod (A, B : Num) return Double_T;
-- Compute A * B and its rounding error exactly
function Two_Sqr (A : Num) return Double_T;
-- Compute A * A and its rounding error exactly
function "+" (A : Double_T; B : Num) return Double_T;
function "-" (A : Double_T; B : Num) return Double_T;
function "*" (A : Double_T; B : Num) return Double_T;
function "/" (A : Double_T; B : Num) return Double_T
with Pre => B /= 0.0;
-- Mixed precision arithmetic operations
function "+" (A, B : Double_T) return Double_T;
function "-" (A, B : Double_T) return Double_T;
function "*" (A, B : Double_T) return Double_T;
function "/" (A, B : Double_T) return Double_T
with Pre => B.Hi /= 0.0;
-- Double precision arithmetic operations
function Sqr (A : Double_T) return Double_T;
-- Faster version of A * A
function "=" (A : Double_T; B : Num) return Boolean is
(A.Hi = B and then A.Lo = 0.0);
function "<" (A : Double_T; B : Num) return Boolean is
(A.Hi < B or else (A.Hi = B and then A.Lo < 0.0));
function "<=" (A : Double_T; B : Num) return Boolean is
(A.Hi < B or else (A.Hi = B and then A.Lo <= 0.0));
function ">" (A : Double_T; B : Num) return Boolean is
(A.Hi > B or else (A.Hi = B and then A.Lo > 0.0));
function ">=" (A : Double_T; B : Num) return Boolean is
(A.Hi > B or else (A.Hi = B and then A.Lo >= 0.0));
-- Mixed precision comparisons
function "=" (A, B : Double_T) return Boolean is
(A.Hi = B.Hi and then A.Lo = B.Lo);
function "<" (A, B : Double_T) return Boolean is
(A.Hi < B.Hi or else (A.Hi = B.Hi and then A.Lo < B.Lo));
function "<=" (A, B : Double_T) return Boolean is
(A.Hi < B.Hi or else (A.Hi = B.Hi and then A.Lo <= B.Lo));
function ">" (A, B : Double_T) return Boolean is
(A.Hi > B.Hi or else (A.Hi = B.Hi and then A.Lo > B.Lo));
function ">=" (A, B : Double_T) return Boolean is
(A.Hi > B.Hi or else (A.Hi = B.Hi and then A.Lo >= B.Lo));
-- Double precision comparisons
generic
type Uns is mod <>;
function From_Unsigned (U : Uns) return Double_T;
-- Convert Uns to Double_T
generic
type Uns is mod <>;
function To_Unsigned (D : Double_T) return Uns
with Pre => D >= 0.0;
-- Convert Double_T to Uns with truncation
end System.Double_Real;
|
-----------------------------------------------------------------------
-- awa-permissions-services -- Permissions controller
-- Copyright (C) 2011, 2012, 2013 Stephane Carrez
-- Written by Stephane Carrez (Stephane.Carrez@gmail.com)
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
with ADO.Queries;
with ADO.Sessions.Entities;
with ADO.Statements;
with Util.Log.Loggers;
with Security.Policies.Roles;
with Security.Policies.URLs;
with AWA.Permissions.Models;
with AWA.Services.Contexts;
package body AWA.Permissions.Services is
use ADO.Sessions;
Log : constant Util.Log.Loggers.Logger := Util.Log.Loggers.Create ("AWA.Permissions.Services");
-- ------------------------------
-- Check if the permission with the name <tt>Name</tt> is granted for the current user.
-- If the <tt>Entity</tt> is defined, an <tt>Entity_Permission</tt> is created and verified.
-- Returns True if the user is granted the given permission.
-- ------------------------------
function Has_Permission (Name : in Util.Beans.Objects.Object;
Entity : in Util.Beans.Objects.Object)
return Util.Beans.Objects.Object is
use type Security.Contexts.Security_Context_Access;
Context : constant Security.Contexts.Security_Context_Access := Security.Contexts.Current;
Perm : constant String := Util.Beans.Objects.To_String (Name);
Result : Boolean;
begin
if Util.Beans.Objects.Is_Empty (Name) or Context = null then
Result := False;
elsif Util.Beans.Objects.Is_Empty (Entity) then
Result := Context.Has_Permission (Perm);
else
declare
P : Entity_Permission (Security.Permissions.Get_Permission_Index (Perm));
begin
P.Entity := ADO.Identifier (Util.Beans.Objects.To_Long_Long_Integer (Entity));
Result := Context.Has_Permission (P);
end;
end if;
return Util.Beans.Objects.To_Object (Result);
exception
when Security.Permissions.Invalid_Name =>
Log.Error ("Invalid permission {0}", Perm);
raise;
end Has_Permission;
URI : aliased constant String := "http://code.google.com/p/ada-awa/auth";
-- ------------------------------
-- Register the security EL functions in the EL mapper.
-- ------------------------------
procedure Set_Functions (Mapper : in out EL.Functions.Function_Mapper'Class) is
begin
Mapper.Set_Function (Name => "hasPermission",
Namespace => URI,
Func => Has_Permission'Access,
Optimize => False);
end Set_Functions;
-- ------------------------------
-- Get the permission manager associated with the security context.
-- Returns null if there is none.
-- ------------------------------
function Get_Permission_Manager (Context : in Security.Contexts.Security_Context'Class)
return Permission_Manager_Access is
use type Security.Policies.Policy_Manager_Access;
M : constant Security.Policies.Policy_Manager_Access
:= Context.Get_Permission_Manager;
begin
if M = null then
Log.Info ("There is no permission manager");
return null;
elsif not (M.all in Permission_Manager'Class) then
Log.Info ("Permission manager is not a AWA permission manager");
return null;
else
return Permission_Manager'Class (M.all)'Access;
end if;
end Get_Permission_Manager;
-- ------------------------------
-- Get the application instance.
-- ------------------------------
function Get_Application (Manager : in Permission_Manager)
return AWA.Applications.Application_Access is
begin
return Manager.App;
end Get_Application;
-- ------------------------------
-- Set the application instance.
-- ------------------------------
procedure Set_Application (Manager : in out Permission_Manager;
App : in AWA.Applications.Application_Access) is
begin
Manager.App := App;
end Set_Application;
-- ------------------------------
-- Add a permission for the current user to access the entity identified by
-- <b>Entity</b> and <b>Kind</b>.
-- ------------------------------
procedure Add_Permission (Manager : in Permission_Manager;
Entity : in ADO.Identifier;
Kind : in ADO.Entity_Type;
Permission : in Permission_Type) is
pragma Unreferenced (Manager);
Ctx : constant AWA.Services.Contexts.Service_Context_Access
:= AWA.Services.Contexts.Current;
DB : Master_Session := AWA.Services.Contexts.Get_Master_Session (Ctx);
Perm : AWA.Permissions.Models.ACL_Ref;
begin
Log.Info ("Adding permission");
Ctx.Start;
Perm.Set_Entity_Type (Kind);
Perm.Set_User_Id (Ctx.Get_User_Identifier);
Perm.Set_Entity_Id (Entity);
Perm.Set_Writeable (Permission = AWA.Permissions.WRITE);
Perm.Save (DB);
Ctx.Commit;
end Add_Permission;
-- ------------------------------
-- Check that the current user has the specified permission.
-- Raise NO_PERMISSION exception if the user does not have the permission.
-- ------------------------------
procedure Check_Permission (Manager : in Permission_Manager;
Entity : in ADO.Identifier;
Kind : in ADO.Entity_Type;
Permission : in Permission_Type) is
pragma Unreferenced (Manager, Permission);
use AWA.Services;
Ctx : constant Contexts.Service_Context_Access := AWA.Services.Contexts.Current;
User : constant ADO.Identifier := Ctx.Get_User_Identifier;
DB : constant Session := AWA.Services.Contexts.Get_Session (Ctx);
Query : ADO.Queries.Context;
begin
Query.Set_Query (AWA.Permissions.Models.Query_Check_Entity_Permission);
Query.Bind_Param ("user_id", User);
Query.Bind_Param ("entity_id", Entity);
Query.Bind_Param ("entity_type", Integer (Kind));
declare
Stmt : ADO.Statements.Query_Statement := DB.Create_Statement (Query);
begin
Stmt.Execute;
if not Stmt.Has_Elements then
Log.Info ("User {0} does not have permission to access entity {1}/{2}",
ADO.Identifier'Image (User), ADO.Identifier'Image (Entity),
ADO.Entity_Type'Image (Kind));
raise NO_PERMISSION;
end if;
end;
end Check_Permission;
-- ------------------------------
-- Add a permission for the user <b>User</b> to access the entity identified by
-- <b>Entity</b> which is of type <b>Kind</b>.
-- ------------------------------
procedure Add_Permission (Session : in out ADO.Sessions.Master_Session;
User : in ADO.Identifier;
Entity : in ADO.Identifier;
Kind : in ADO.Entity_Type;
Permission : in Permission_Type := READ) is
Acl : AWA.Permissions.Models.ACL_Ref;
begin
Acl.Set_User_Id (User);
Acl.Set_Entity_Type (Kind);
Acl.Set_Entity_Id (Entity);
Acl.Set_Writeable (Permission = WRITE);
Acl.Save (Session);
Log.Info ("Permission created for {0} to access {1}, entity type {2}",
ADO.Identifier'Image (User),
ADO.Identifier'Image (Entity),
ADO.Entity_Type'Image (Kind));
end Add_Permission;
-- ------------------------------
-- Add a permission for the user <b>User</b> to access the entity identified by
-- <b>Entity</b>.
-- ------------------------------
procedure Add_Permission (Session : in out ADO.Sessions.Master_Session;
User : in ADO.Identifier;
Entity : in ADO.Objects.Object_Ref'Class;
Permission : in Permission_Type := READ) is
Key : constant ADO.Objects.Object_Key := Entity.Get_Key;
Kind : constant ADO.Entity_Type
:= ADO.Sessions.Entities.Find_Entity_Type (Session => Session,
Object => Key);
begin
Add_Permission (Session, User, ADO.Objects.Get_Value (Key), Kind, Permission);
end Add_Permission;
-- ------------------------------
-- Create a permission manager for the given application.
-- ------------------------------
function Create_Permission_Manager (App : in AWA.Applications.Application_Access)
return Security.Policies.Policy_Manager_Access is
Result : constant AWA.Permissions.Services.Permission_Manager_Access
:= new AWA.Permissions.Services.Permission_Manager (10);
RP : constant Security.Policies.Roles.Role_Policy_Access
:= new Security.Policies.Roles.Role_Policy;
RU : constant Security.Policies.URLs.URL_Policy_Access
:= new Security.Policies.URLs.URL_Policy;
RE : constant Entity_Policy_Access
:= new Entity_Policy;
begin
Result.Add_Policy (RP.all'Access);
Result.Add_Policy (RU.all'Access);
Result.Add_Policy (RE.all'Access);
Result.Set_Application (App);
Log.Info ("Creation of the AWA Permissions manager");
return Result.all'Access;
end Create_Permission_Manager;
end AWA.Permissions.Services;
|
with Ada.Text_IO;
use Ada.Text_IO;
procedure Main is
begin
Put_Line ("Hello, World!");
end Main;
|
------------------------------------------------------------------------------
-- AGAR GUI LIBRARY --
-- A G A R . S U R F A C E --
-- B o d y --
-- --
-- Copyright (c) 2018-2019 Julien Nadeau Carriere (vedge@csoft.net) --
-- --
-- Permission to use, copy, modify, and/or distribute this software for any --
-- purpose with or without fee is hereby granted, provided that the above --
-- copyright notice and this permission notice appear in all copies. --
-- --
-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES --
-- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF --
-- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR --
-- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES --
-- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN --
-- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF --
-- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. --
------------------------------------------------------------------------------
with Agar.Error;
with Ada.Text_IO;
package body Agar.Surface is
procedure Pixel_Format_RGB
(Format : in Pixel_Format_not_null_Access;
#if AG_MODEL = AG_LARGE
Bits_per_Pixel : in Positive := 64;
R_Mask : in AG_Pixel := 16#000000000000ffff#;
G_Mask : in AG_Pixel := 16#00000000ffff0000#;
B_Mask : in AG_Pixel := 16#0000ffff00000000#) is
#else
Bits_per_Pixel : in Positive := 32;
R_Mask : in AG_Pixel := 16#000000ff#;
G_Mask : in AG_Pixel := 16#0000ff00#;
B_Mask : in AG_Pixel := 16#00ff0000#) is
#end if;
begin
AG_PixelFormatRGB
(Format => Format,
Bits_per_Pixel => C.int(Bits_per_Pixel),
R_Mask => R_Mask,
G_Mask => G_Mask,
B_Mask => B_Mask);
end;
procedure Pixel_Format_RGBA
(Format : Pixel_Format_not_null_Access;
#if AG_MODEL = AG_LARGE
Bits_per_Pixel : in Positive := 64;
R_Mask : in AG_Pixel := 16#000000000000ffff#;
G_Mask : in AG_Pixel := 16#00000000ffff0000#;
B_Mask : in AG_Pixel := 16#0000ffff00000000#;
A_Mask : in AG_Pixel := 16#ffff000000000000#) is
#else
Bits_per_Pixel : in Positive := 32;
R_Mask : in AG_Pixel := 16#000000ff#;
G_Mask : in AG_Pixel := 16#0000ff00#;
B_Mask : in AG_Pixel := 16#00ff0000#;
A_Mask : in AG_Pixel := 16#ff000000#) is
#end if;
begin
AG_PixelFormatRGBA
(Format => Format,
Bits_per_Pixel => C.int(Bits_per_Pixel),
R_Mask => R_Mask,
G_Mask => G_Mask,
B_Mask => B_Mask,
A_Mask => A_Mask);
end;
procedure Pixel_Format_Indexed
(Format : Pixel_Format_not_null_Access;
Bits_per_Pixel : Positive := 8) is
begin
AG_PixelFormatIndexed
(Format => Format,
Bits_per_Pixel => C.int(Bits_per_Pixel));
end;
procedure Pixel_Format_Grayscale
(Format : Pixel_Format_not_null_Access;
Bits_per_Pixel : Positive := 32) is
begin
AG_PixelFormatGrayscale
(Format => Format,
Bits_per_Pixel => C.int(Bits_per_Pixel));
end;
--
-- Compare the contents of two Pixel formats (if both are indexed,
-- then compare their palettes as well).
--
--function "=" (Left, Right : Pixel_Format_Access) return Boolean is
--begin
-- if Left = null and Right = null then
-- return True;
-- end if;
-- if Left = null or Right = null then
-- return False;
-- end if;
-- return 0 = AG_PixelFormatCompare (Left, Right);
--end;
--
-- Create a new surface in PACKED, INDEXED or GRAYSCALE pixel format.
--
-- With PACKED mode, masks can be specified optionally in the Format
-- argument (if Format is null then the default RGBA masks are used).
--
-- Src_Colorkey enables colorkey transparency and Src_Alpha enables
-- overall per-surface alpha in blits where Surface is the source.
-- GL_Texture advises that the surface is a valid OpenGL texture.
--
function New_Surface
(Mode : in Surface_Mode := PACKED;
W,H : in Natural := 0;
Bits_per_Pixel : in Positive := 32;
Format : in Pixel_Format_Access := null;
Src_Colorkey : in Boolean := false;
Src_Alpha : in Boolean := false;
GL_Texture : in Boolean := false) return Surface_Access
is
Flags : C.unsigned := 0;
begin
if Src_Colorkey then Flags := Flags or SURFACE_COLORKEY; end if;
if Src_Alpha then Flags := Flags or SURFACE_ALPHA; end if;
if GL_Texture then Flags := Flags or SURFACE_GL_TEXTURE; end if;
if Format = null then
Ada.Text_IO.Put_Line("Format is null, auto-selecting");
case (Mode) is
when PACKED =>
#if AG_MODEL = AG_LARGE
case (Bits_per_Pixel) is
when 64 =>
Ada.Text_IO.Put_Line("64-bit RGBA");
return AG_SurfaceRGBA
(W => C.unsigned(W),
H => C.unsigned(H),
Bits_per_Pixel => C.unsigned(Bits_per_Pixel),
Flags => Flags,
R_Mask => 16#000000000000ffff#,
G_Mask => 16#00000000ffff0000#,
B_Mask => 16#0000ffff00000000#,
A_Mask => 16#ffff000000000000#);
when 48 =>
Ada.Text_IO.Put_Line("48-bit RGB");
return AG_SurfaceRGBA
(W => C.unsigned(W),
H => C.unsigned(H),
Bits_per_Pixel => C.unsigned(Bits_per_Pixel),
Flags => Flags,
R_Mask => 16#000000000000ffff#,
G_Mask => 16#00000000ffff0000#,
B_Mask => 16#0000ffff00000000#,
A_Mask => 0);
when others =>
null;
end case;
#end if;
case (Bits_per_Pixel) is
when 32 =>
Ada.Text_IO.Put_Line("32-bit RGBA");
return AG_SurfaceRGBA
(W => C.unsigned(W),
H => C.unsigned(H),
Bits_per_Pixel => C.unsigned(Bits_per_Pixel),
Flags => Flags,
R_Mask => 16#000000ff#,
G_Mask => 16#0000ff00#,
B_Mask => 16#00ff0000#,
A_Mask => 16#ff000000#);
when 24 =>
Ada.Text_IO.Put_Line("24-bit RGB");
return AG_SurfaceRGBA
(W => C.unsigned(W),
H => C.unsigned(H),
Bits_per_Pixel => C.unsigned(Bits_per_Pixel),
Flags => Flags,
R_Mask => 16#000000ff#,
G_Mask => 16#0000ff00#,
B_Mask => 16#00ff0000#,
A_Mask => 0);
when 16 =>
Ada.Text_IO.Put_Line("16-bit RGBA");
return AG_SurfaceRGBA
(W => C.unsigned(W),
H => C.unsigned(H),
Bits_per_Pixel => C.unsigned(Bits_per_Pixel),
Flags => Flags,
R_Mask => 16#000f#,
G_Mask => 16#00f0#,
B_Mask => 16#0f00#,
A_Mask => 16#f000#);
when 12 =>
Ada.Text_IO.Put_Line("12-bit RGB");
return AG_SurfaceRGBA
(W => C.unsigned(W),
H => C.unsigned(H),
Bits_per_Pixel => C.unsigned(Bits_per_Pixel),
Flags => Flags,
R_Mask => 16#000f#,
G_Mask => 16#00f0#,
B_Mask => 16#0f00#,
A_Mask => 0);
when others =>
null;
end case;
when INDEXED =>
Ada.Text_IO.Put_Line(Integer'Image(Bits_per_Pixel) & "-bit Indexed");
return AG_SurfaceIndexed
(W => C.unsigned(W),
H => C.unsigned(H),
Bits_per_Pixel => C.unsigned(Bits_per_Pixel),
Flags => Flags);
when GRAYSCALE =>
Ada.Text_IO.Put_Line(Integer'Image(Bits_per_Pixel) & "-bit Grayscale");
return AG_SurfaceGrayscale
(W => C.unsigned(W),
H => C.unsigned(H),
Bits_per_Pixel => C.unsigned(Bits_per_Pixel),
Flags => Flags);
end case; -- Mode
end if; -- Format = null
return AG_SurfaceNew
(Format => Format,
W => C.unsigned(W),
H => C.unsigned(H),
Flags => Flags);
end;
--
-- Create a new surface in PACKED pixel format with RGBA masks.
--
function New_Surface
(W,H : in Natural := 0;
#if AG_MODEL = AG_LARGE
Bits_per_Pixel : in Positive := 64;
R_Mask : in AG_Pixel := 16#000000000000ffff#;
G_Mask : in AG_Pixel := 16#00000000ffff0000#;
B_Mask : in AG_Pixel := 16#0000ffff00000000#;
A_Mask : in AG_Pixel := 16#ffff000000000000#;
#else
Bits_per_Pixel : in Positive := 32;
R_Mask : in AG_Pixel := 16#000000ff#;
G_Mask : in AG_Pixel := 16#0000ff00#;
B_Mask : in AG_Pixel := 16#00ff0000#;
A_Mask : in AG_Pixel := 16#ff000000#;
#end if;
Src_Colorkey : in Boolean := false;
Src_Alpha : in Boolean := false;
GL_Texture : in Boolean := false) return Surface_Access
is
Flags : C.unsigned := 0;
begin
if Src_Colorkey then Flags := Flags or SURFACE_COLORKEY; end if;
if Src_Alpha then Flags := Flags or SURFACE_ALPHA; end if;
if GL_Texture then Flags := Flags or SURFACE_GL_TEXTURE; end if;
if A_Mask /= 0 then
return AG_SurfaceRGBA
(W => C.unsigned(W),
H => C.unsigned(H),
Bits_per_Pixel => C.unsigned(Bits_per_Pixel),
Flags => Flags,
R_Mask => R_Mask,
G_Mask => G_Mask,
B_Mask => B_Mask,
A_Mask => A_Mask);
else
return AG_SurfaceRGB
(W => C.unsigned(W),
H => C.unsigned(H),
Bits_per_Pixel => C.unsigned(Bits_per_Pixel),
Flags => Flags,
R_Mask => R_Mask,
G_Mask => G_Mask,
B_Mask => B_Mask);
end if;
end New_Surface;
--
-- Create a new PACKED surface (with given RGBA masks),
-- and initialize its contents from existing pixel data.
--
function New_Surface
(Pixels : in Pixel_not_null_Access;
W,H : in Natural;
#if AG_MODEL = AG_LARGE
Bits_per_Pixel : in Positive := 64;
R_Mask : in AG_Pixel := 16#000000000000ffff#;
G_Mask : in AG_Pixel := 16#00000000ffff0000#;
B_Mask : in AG_Pixel := 16#0000ffff00000000#;
A_Mask : in AG_Pixel := 16#ffff000000000000#;
#else
Bits_per_Pixel : in Positive := 32;
R_Mask : in AG_Pixel := 16#000000ff#;
G_Mask : in AG_Pixel := 16#0000ff00#;
B_Mask : in AG_Pixel := 16#00ff0000#;
A_Mask : in AG_Pixel := 16#ff000000#;
#end if;
Src_Colorkey : in Boolean := false;
Src_Alpha : in Boolean := false;
GL_Texture : in Boolean := false) return Surface_Access
is
S : Surface_Access;
begin
if A_Mask /= 0 then
S := AG_SurfaceFromPixelsRGBA
(Pixels => Pixels,
W => C.unsigned(W),
H => C.unsigned(H),
Bits_per_Pixel => C.int(Bits_per_Pixel),
R_Mask => R_Mask,
G_Mask => G_Mask,
B_Mask => B_Mask,
A_Mask => A_Mask);
else
S := AG_SurfaceFromPixelsRGB
(Pixels => Pixels,
W => C.unsigned(W),
H => C.unsigned(H),
Bits_per_Pixel => C.int(Bits_per_Pixel),
R_Mask => R_Mask,
G_Mask => G_Mask,
B_Mask => B_Mask);
end if;
if S = null then
return null;
end if;
if Src_Colorkey then S.Flags := S.Flags or SURFACE_COLORKEY; end if;
if Src_Alpha then S.Flags := S.Flags or SURFACE_ALPHA; end if;
if GL_Texture then S.Flags := S.Flags or SURFACE_GL_TEXTURE; end if;
return S;
end New_Surface;
--
-- Create a new surface by loading a BMP, PNG or JPEG image file.
--
function New_Surface
(File : in String;
Src_Colorkey : in Boolean := false;
Src_Alpha : in Boolean := false;
GL_Texture : in Boolean := false) return Surface_Access
is
Ch_File : aliased C.char_array := C.To_C(File);
S : Surface_Access;
begin
S := AG_SurfaceFromFile
(File => CS.To_Chars_Ptr(Ch_File'Unchecked_Access));
if S = null then
return null;
end if;
if Src_Colorkey then S.Flags := S.Flags or SURFACE_COLORKEY; end if;
if Src_Alpha then S.Flags := S.Flags or SURFACE_ALPHA; end if;
if GL_Texture then S.Flags := S.Flags or SURFACE_GL_TEXTURE; end if;
return S;
end;
--
-- Create a surface in the "best" format suitable for OpenGL textures.
--
function New_Surface_GL
(W,H : in Natural) return Surface_Access
is
begin
return AG_SurfaceStdGL
(W => C.unsigned(W),
H => C.unsigned(H));
end;
--
-- Return a Color from 8-bit RGBA components.
--
function Color_8
(R,G,B : in Unsigned_8;
A : in Unsigned_8 := 255) return AG_Color
is
#if AG_MODEL = AG_LARGE
Color : constant AG_Color := (Unsigned_16(Float(R) / 255.0 * 65535.0),
Unsigned_16(Float(G) / 255.0 * 65535.0),
Unsigned_16(Float(B) / 255.0 * 65535.0),
Unsigned_16(Float(A) / 255.0 * 65535.0));
#else
Color : constant AG_Color := (R,G,B,A);
#end if;
begin
return Color;
end;
--
-- Return an AG_Color from 16-bit RGBA components.
--
function Color_16
(R,G,B : in Unsigned_16;
A : in Unsigned_16 := 65535) return AG_Color
is
#if AG_MODEL = AG_LARGE
Color : constant AG_Color := (R,G,B,A);
#else
Color : constant AG_Color := (Unsigned_8(Float(R) / 65535.0 * 255.0),
Unsigned_8(Float(G) / 65535.0 * 255.0),
Unsigned_8(Float(B) / 65535.0 * 255.0),
Unsigned_8(Float(A) / 65535.0 * 255.0));
#end if;
begin
return Color;
end;
--
-- Return a Color from Hue, Saturation, Value and Alpha components.
--
function Color_HSV
(H,S,V : in Intensity;
A : in Intensity := 1.0) return AG_Color
is
Color : aliased AG_Color;
begin
AG_HSV2Color
(H => C.c_float(H),
S => C.c_float(S),
V => C.c_float(V),
Color => Color'Unchecked_Access);
#if AG_MODEL = AG_LARGE
Color.A := AG_Component(A * 65535.0);
#else
Color.A := AG_Component(A * 255.0);
#end if;
return Color;
end;
--
-- Return a native component offset amount for a given 8-bit component.
--
function Component_Offset_8
(X : in Unsigned_8) return AG_Component is
begin
#if AG_MODEL = AG_LARGE
return AG_Component(Float(X) / 255.0 * 65535.0);
#else
return AG_Component(X);
#end if;
end;
--
-- Return a native component offset amount for a given 16-bit component.
--
function Component_Offset_16
(X : in Unsigned_16) return AG_Component is
begin
#if AG_MODEL = AG_LARGE
return AG_Component(X);
#else
return AG_Component(Float(X) / 65535.0 * 255.0);
#end if;
end;
--
-- Set a color palette entry of an Indexed surface (AG_Color argument)
--
procedure Set_Color
(Surface : in Surface_not_null_Access;
Index : in Natural;
Color : in AG_Color)
is
C_Color : aliased AG_Color := Color;
begin
AG_SurfaceSetColors
(Surface => Surface,
Color => C_Color'Unchecked_Access,
Offset => C.unsigned(Index),
Count => 1);
end;
--
-- Set a color palette entry of an Indexed surface (AG_Color access argument)
--
procedure Set_Color
(Surface : in Surface_not_null_Access;
Index : in Natural;
Color : in Color_not_null_Access) is
begin
AG_SurfaceSetColors
(Surface => Surface,
Color => Color,
Offset => C.unsigned(Index),
Count => 1);
end;
--
-- Copy a Source surface (or a region of its pixels) to a Target surface
-- which can be of a different format. Handle format conversion, clipping
-- and blending according to the pixel formats of the surfaces (and their
-- Colorkey and Src_Alpha settings).
--
procedure Blit_Surface
(Source : in Surface_not_null_Access;
Src_Rect : in Rect_access := null;
Target : in Surface_not_null_Access;
Dst_X : in Natural := 0;
Dst_Y : in Natural := 0) is
begin
AG_SurfaceBlit
(Source => Source,
Src_Rect => Src_Rect,
Target => Target,
X => C.int(Dst_X),
Y => C.int(Dst_Y));
end;
--
-- Change the dimensions of a surface without scaling its contents. Pixel
-- data is reallocated (if growing the surface, then then new pixels are
-- left uninitialized).
--
function Resize_Surface
(Surface : in Surface_not_null_Access;
W,H : in Natural) return Boolean is
begin
return 0 = AG_SurfaceResize
(Surface => Surface,
W => C.unsigned(W),
H => C.unsigned(H));
end;
procedure Resize_Surface
(Surface : in Surface_not_null_Access;
W,H : in Natural)
is
Result : C.int;
begin
Result := AG_SurfaceResize
(Surface => Surface,
W => C.unsigned(W),
H => C.unsigned(H));
if Result /= 0 then
raise Program_Error with Agar.Error.Get_Error;
end if;
end;
--
-- Export the surface to a BMP, PNG or JPEG image file.
--
function Export_Surface
(Surface : in Surface_not_null_Access;
File : in String) return Boolean
is
Ch_File : aliased C.char_array := C.To_C(File);
begin
return 0 = AG_SurfaceExportFile
(Surface => Surface,
File => CS.To_Chars_Ptr(Ch_File'Unchecked_Access));
end;
--
-- Export the surface to a Windows bitmap image file.
--
function Export_BMP
(Surface : in Surface_not_null_Access;
File : in String := "output.bmp") return Boolean
is
Ch_File : aliased C.char_array := C.To_C(File);
begin
return 0 = AG_SurfaceExportBMP
(Surface => Surface,
File => CS.To_Chars_Ptr(Ch_File'Unchecked_Access));
end;
--
-- Export the surface to a PNG image file.
--
function Export_PNG
(Surface : in Surface_not_null_Access;
File : in String := "output.png";
Adam7 : in Boolean := false) return Boolean
is
Ch_File : aliased C.char_array := C.To_C(File);
Flags : C.unsigned := 0;
begin
if Adam7 then
Flags := EXPORT_PNG_ADAM7;
end if;
return 0 = AG_SurfaceExportPNG
(Surface => Surface,
File => CS.To_Chars_Ptr(Ch_File'Unchecked_Access),
Flags => Flags);
end;
--
-- Export the surface to a JPEG image file.
--
function Export_JPEG
(Surface : in Surface_not_null_Access;
File : in String := "output.jpg";
Quality : in JPEG_Quality := 100;
Method : in JPEG_Method := JDCT_ISLOW) return Boolean
is
Ch_File : aliased C.char_array := C.To_C(File);
Flags : C.unsigned := 0;
begin
case (Method) is
when JDCT_ISLOW => Flags := EXPORT_JPEG_JDCT_ISLOW;
when JDCT_IFAST => Flags := EXPORT_JPEG_JDCT_IFAST;
when JDCT_FLOAT => Flags := EXPORT_JPEG_JDCT_FLOAT;
end case;
return 0 = AG_SurfaceExportJPEG
(Surface => Surface,
File => CS.To_Chars_Ptr(Ch_File'Unchecked_Access),
Quality => C.unsigned(Quality),
Flags => Flags);
end;
--
-- Return a string describing a blending function.
--
function Alpha_Func_Name
(Func : Alpha_Func) return String is
begin
case Func is
when ALPHA_OVERLAY => return "src+dst";
when ALPHA_ZERO => return "zero";
when ALPHA_ONE => return "one";
when ALPHA_SRC => return "src";
when ALPHA_DST => return "dst";
when ALPHA_ONE_MINUS_DST => return "1-dst";
when ALPHA_ONE_MINUS_SRC => return "1-src";
end case;
end;
--
-- Blend a target pixel against a specified color. The target pixel's
-- alpha component is computed according to Func (by pixel address).
--
procedure Blend_Pixel
(Surface : in Surface_not_null_Access;
Pixel : in Pixel_not_null_Access;
Color : in Color_not_null_Access;
Func : in Alpha_Func := ALPHA_OVERLAY) is
begin
AG_SurfaceBlend_At
(Surface => Surface,
Pixel => Pixel,
Color => Color,
Func => Alpha_Func'Pos(Func));
end;
--
-- Blend a target pixel against a specified color. The target pixel's
-- alpha component is computed according to Func (by X,Y coordinates).
--
procedure Blend_Pixel
(Surface : in Surface_not_null_Access;
X,Y : in Natural;
Color : in Color_not_null_Access;
Func : in Alpha_Func := ALPHA_OVERLAY) is
begin
AG_SurfaceBlend
(Surface => Surface,
X => C.int(X),
Y => C.int(Y),
Color => Color,
Func => Alpha_Func'Pos(Func));
end;
--
-- Return the native-width packed pixel corresponding to an AG_Color
-- (under the pixel format of Surface).
--
function Map_Pixel
(Surface : in Surface_not_null_Access;
Color : in AG_Color) return AG_Pixel
is
C_Color : aliased AG_Color := Color;
begin
#if AG_MODEL = AG_LARGE
return AG_MapPixel64
(Format => Surface.Format'Access,
Color => C_Color'Unchecked_Access);
#else
return AG_MapPixel32
(Format => Surface.Format'Access,
Color => C_Color'Unchecked_Access);
#end if;
end;
--
-- Return the native-width packed pixel corresponding to an AG_Color
-- (under the specified pixel format).
--
function Map_Pixel
(Format : in Pixel_Format_not_null_Access;
Color : in AG_Color) return AG_Pixel
is
C_Color : aliased AG_Color := Color;
begin
#if AG_MODEL = AG_LARGE
return AG_MapPixel64
(Format => Format,
Color => C_Color'Unchecked_Access);
#else
return AG_MapPixel32
(Format => Format,
Color => C_Color'Unchecked_Access);
#end if;
end;
--
-- Return the native-width packed pixel corresponding to an AG_Color
-- (under the pixel format of Surface).
--
function Map_Pixel
(Surface : in Surface_not_null_Access;
Color : in Color_not_null_access) return AG_Pixel is
begin
#if AG_MODEL = AG_LARGE
return AG_MapPixel64
(Format => Surface.Format'Access,
Color => Color);
#else
return AG_MapPixel32
(Format => Surface.Format'Access,
Color => Color);
#end if;
end;
--
-- Return a new surface generated by scaling an Input surface to specified
-- dimensions. Function form may fail and return null.
--
function Scale_Surface
(Surface : in Surface_not_null_Access;
W,H : in Natural) return Surface_Access is
begin
return AG_SurfaceScale
(Surface => Surface,
W => C.unsigned(W),
H => C.unsigned(H),
Flags => C.unsigned(0));
end;
--
-- Return a new surface generated by scaling an Input surface to specified
-- dimensions. Procedure form raises fatal exception on failure.
--
procedure Scale_Surface
(Original : in Surface_not_null_Access;
W,H : in Natural;
Scaled : out Surface_not_null_Access)
is
Result : Surface_Access;
begin
Result := AG_SurfaceScale
(Surface => Original,
W => C.unsigned(W),
H => C.unsigned(H),
Flags => C.unsigned(0));
if Result = null then
raise Program_Error with Agar.Error.Get_Error;
end if;
Scaled := Result;
end;
--
-- Fill a rectangle of pixels with a specified color (AG_Color argument).
--
procedure Fill_Rect
(Surface : in Surface_not_null_Access;
Rect : in Rect_Access := null;
Color : in AG_Color)
is
C_Color : aliased AG_Color := Color;
begin
AG_FillRect
(Surface => Surface,
Rect => Rect,
Color => C_Color'Unchecked_Access);
end;
--
-- Extract a native-width packed pixel from a surface (by coordinates).
--
function Get_Pixel
(Surface : in Surface_not_null_Access;
X,Y : in Natural) return AG_Pixel is
begin
#if AG_MODEL = AG_LARGE
return AG_SurfaceGet64
(Surface => Surface,
X => C.int(X),
Y => C.int(Y));
#else
return AG_SurfaceGet32
(Surface => Surface,
X => C.int(X),
Y => C.int(Y));
#end if;
end;
--
-- Extract a 32-bit packed pixel from a surface (by coordinates).
--
function Get_Pixel_32
(Surface : in Surface_not_null_Access;
X,Y : in Natural) return Unsigned_32 is
begin
return AG_SurfaceGet32
(Surface => Surface,
X => C.int(X),
Y => C.int(Y));
end;
#if AG_MODEL = AG_LARGE
--
-- Extract a 64-bit packed pixel from a surface (by coordinates).
--
function Get_Pixel_64
(Surface : in Surface_not_null_Access;
X,Y : in Natural) return Unsigned_64 is
begin
return AG_SurfaceGet64
(Surface => Surface,
X => C.int(X),
Y => C.int(Y));
end;
#end if;
--
-- Set a native-width packed pixel in a surface (by coordinates).
--
procedure Put_Pixel
(Surface : in Surface_not_null_Access;
X,Y : in Natural;
Pixel : in AG_Pixel;
Clipping : in Boolean := true) is
begin
if Clipping then
if C.int(X) < Surface.Clip_Rect.X or
C.int(Y) < Surface.Clip_Rect.Y or
C.int(X) >= Surface.Clip_Rect.X+Surface.Clip_Rect.W or
C.int(Y) >= Surface.Clip_Rect.Y+Surface.Clip_Rect.H then
return;
end if;
end if;
#if AG_MODEL = AG_LARGE
AG_SurfacePut64
(Surface => Surface,
X => C.int(X),
Y => C.int(Y),
Pixel => Pixel);
#else
AG_SurfacePut32
(Surface => Surface,
X => C.int(X),
Y => C.int(Y),
Pixel => Pixel);
#end if;
end;
--
-- Set a 32-bit packed pixel in a surface (by coordinates).
--
procedure Put_Pixel_32
(Surface : in Surface_not_null_Access;
X,Y : in Natural;
Pixel : in Unsigned_32;
Clipping : in Boolean := true) is
begin
if Clipping then
if C.int(X) < Surface.Clip_Rect.X or
C.int(Y) < Surface.Clip_Rect.Y or
C.int(X) >= Surface.Clip_Rect.X+Surface.Clip_Rect.W or
C.int(Y) >= Surface.Clip_Rect.Y+Surface.Clip_Rect.H then
return;
end if;
end if;
AG_SurfacePut32
(Surface => Surface,
X => C.int(X),
Y => C.int(Y),
Pixel => Pixel);
end;
#if AG_MODEL = AG_LARGE
--
-- Set a 64-bit packed pixel in a surface (by coordinates).
--
procedure Put_Pixel_64
(Surface : in Surface_not_null_Access;
X,Y : in Natural;
Pixel : in Unsigned_64;
Clipping : in Boolean := true) is
begin
if Clipping then
if C.int(X) < Surface.Clip_Rect.X or
C.int(Y) < Surface.Clip_Rect.Y or
C.int(X) >= Surface.Clip_Rect.X+Surface.Clip_Rect.W or
C.int(Y) >= Surface.Clip_Rect.Y+Surface.Clip_Rect.H then
return;
end if;
end if;
AG_SurfacePut64
(Surface => Surface,
X => C.int(X),
Y => C.int(Y),
Pixel => Pixel);
end;
#end if;
procedure Unpack_Pixel
(Pixel : in AG_Pixel;
Format : in Pixel_Format_not_null_Access;
R,G,B,A : out AG_Component)
is
Color : aliased AG_Color;
begin
#if AG_MODEL = AG_LARGE
AG_GetColor64
(Color => Color'Unchecked_Access,
Pixel => Pixel,
Format => Format);
#else
AG_GetColor32
(Color => Color'Unchecked_Access,
Pixel => Pixel,
Format => Format);
#end if;
R := Color.R;
G := Color.G;
B := Color.B;
A := Color.A;
end;
--
-- Set source alpha flag and per-surface alpha value.
--
procedure Set_Alpha
(Surface : in Surface_not_null_Access;
Enable : in Boolean := false;
Alpha : in AG_Component := AG_OPAQUE) is
begin
if (Enable) then
Surface.Flags := Surface.Flags or SURFACE_ALPHA;
else
Surface.Flags := Surface.Flags and not SURFACE_ALPHA;
end if;
Surface.Alpha := Alpha;
end;
--
-- Set source colorkey flag and surface colorkey value.
--
procedure Set_Colorkey
(Surface : in Surface_not_null_Access;
Enable : in Boolean := false;
Colorkey : in AG_Pixel := 0) is
begin
if (Enable) then
Surface.Flags := Surface.Flags or SURFACE_COLORKEY;
else
Surface.Flags := Surface.Flags and not SURFACE_COLORKEY;
end if;
Surface.Colorkey := Colorkey;
end;
--
-- Get surface clipping rectangle.
--
procedure Get_Clipping_Rect
(Surface : in Surface_not_null_Access;
X,Y,W,H : out Natural) is
begin
X := Natural(Surface.Clip_Rect.X);
Y := Natural(Surface.Clip_Rect.Y);
W := Natural(Surface.Clip_Rect.W);
H := Natural(Surface.Clip_Rect.H);
end;
procedure Set_Clipping_Rect
(Surface : in Surface_not_null_Access;
X,Y,W,H : in Natural) is
begin
Surface.Clip_Rect.X := C.int(X);
Surface.Clip_Rect.Y := C.int(Y);
Surface.Clip_Rect.W := C.int(W);
Surface.Clip_Rect.H := C.int(H);
end;
end Agar.Surface;
|
with Ada.Assertions; use Ada.Assertions;
with Device; use Device;
with Memory.Join; use Memory.Join;
with Memory.Container; use Memory.Container;
package body Memory.Split is
function Create_Split return Split_Pointer is
result : constant Split_Pointer := new Split_Type;
begin
return result;
end Create_Split;
function Random_Split(next : access Memory_Type'Class;
generator : Distribution_Type;
max_cost : Cost_Type)
return Memory_Pointer is
result : constant Split_Pointer := Create_Split;
wsize : constant Natural := Get_Word_Size(next.all);
begin
Set_Memory(result.all, next);
for i in 1 .. 10 loop
result.offset := Random_Address(generator, wsize);
exit when result.offset /= 0;
end loop;
return Memory_Pointer(result);
end Random_Split;
function Clone(mem : Split_Type) return Memory_Pointer is
result : constant Split_Pointer := new Split_Type'(mem);
begin
return Memory_Pointer(result);
end Clone;
procedure Permute(mem : in out Split_Type;
generator : in Distribution_Type;
max_cost : in Cost_Type) is
wsize : constant Positive := Get_Word_Size(mem);
begin
for i in 1 .. 10 loop
mem.offset := Random_Address(generator, wsize);
exit when mem.offset /= 0;
end loop;
Assert(Get_Cost(mem) <= max_cost, "Invalid Permute in Memory.Split");
end Permute;
function Get_Bank(mem : Split_Type;
index : Natural) return Memory_Pointer is
begin
Assert(index < 2);
return Memory_Pointer(mem.banks(index).mem);
end Get_Bank;
procedure Set_Bank(mem : in out Split_Type;
index : in Natural;
other : access Memory_Type'Class) is
begin
Assert(index < 2);
mem.banks(index).mem := other;
end Set_Bank;
function Get_Offset(mem : Split_Type'Class) return Address_Type is
begin
return mem.offset;
end Get_Offset;
procedure Set_Offset(mem : in out Split_Type'Class;
offset : in Address_Type) is
begin
mem.offset := offset;
end Set_Offset;
procedure Reset(mem : in out Split_Type;
context : in Natural) is
begin
Reset(Container_Type(mem), context);
for i in mem.banks'Range loop
Reset(mem.banks(i).mem.all, context);
end loop;
end Reset;
procedure Do_Process(mem : in out Split_Type;
address : in Address_Type;
size : in Positive;
is_read : in Boolean) is
last : constant Address_Type := address + Address_Type(size) - 1;
start_time : Time_Type;
temp_addr : Address_Type;
temp_size : Positive;
begin
Assert(address <= last, "invalid address in Memory.Split.Do_Process");
if address < mem.offset then
if last <= mem.offset then
temp_size := size;
else
temp_size := Positive(mem.offset - address);
end if;
start_time := Get_Time(mem.banks(0).mem.all);
if is_read then
Read(mem.banks(0).mem.all, address, temp_size);
else
Write(mem.banks(0).mem.all, address, temp_size);
end if;
Advance(mem, Get_Time(mem.banks(0).mem.all) - start_time);
end if;
if last >= mem.offset then
if address >= mem.offset then
temp_addr := address - mem.offset;
temp_size := size;
else
temp_addr := 0;
temp_size := Positive(last - mem.offset + 1);
end if;
start_time := Get_Time(mem.banks(1).mem.all);
if is_read then
Read(mem.banks(1).mem.all, temp_addr, temp_size);
else
Write(mem.banks(1).mem.all, temp_addr, temp_size);
end if;
Advance(mem, Get_Time(mem.banks(1).mem.all) - start_time);
end if;
end Do_Process;
procedure Process(mem : in out Split_Type;
address : in Address_Type;
size : in Positive;
is_read : in Boolean) is
abits : constant Positive := Get_Address_Bits;
max : constant Address_Type := Address_Type(2) ** abits;
amask : constant Address_Type := max - 1;
last : constant Address_Type
:= (address + Address_Type(size - 1)) and amask;
begin
if address > last then
Do_Process(mem, address, Positive(max - address), is_read);
Do_Process(mem, 0, Positive(last + 1), is_read);
else
Do_Process(mem, address, size, is_read);
end if;
end Process;
procedure Read(mem : in out Split_Type;
address : in Address_Type;
size : in Positive) is
begin
Assert(Get_Memory(mem) /= null, "Memory.Split.Read");
Process(mem, address, size, True);
end Read;
procedure Write(mem : in out Split_Type;
address : in Address_Type;
size : in Positive) is
begin
Assert(Get_Memory(mem) /= null, "Memory.Split.Write");
Process(mem, address, size, False);
end Write;
procedure Idle(mem : in out Split_Type;
cycles : in Time_Type) is
begin
Idle(Container_Type(mem), cycles);
for i in mem.banks'Range loop
Idle(mem.banks(i).mem.all, cycles);
end loop;
end Idle;
procedure Show_Access_Stats(mem : in out Split_Type) is
begin
for i in mem.banks'Range loop
Show_Access_Stats(mem.banks(i).mem.all);
end loop;
end Show_Access_Stats;
function To_String(mem : Split_Type) return Unbounded_String is
result : Unbounded_String;
begin
Append(result, "(split ");
Append(result, "(offset" & Address_Type'Image(mem.offset) & ")");
if mem.banks(0).mem /= null then
Append(result, "(bank0 ");
Append(result, To_String(mem.banks(0).mem.all));
Append(result, ")");
end if;
if mem.banks(1).mem /= null then
Append(result, "(bank1 ");
Append(result, To_String(mem.banks(1).mem.all));
Append(result, ")");
end if;
Append(result, "(memory ");
Append(result, To_String(Container_Type(mem)));
Append(result, ")");
Append(result, ")");
return result;
end To_String;
function Get_Cost(mem : Split_Type) return Cost_Type is
result : Cost_Type;
begin
result := Get_Cost(Container_Type(mem));
for i in mem.banks'Range loop
result := result + Get_Cost(mem.banks(i).mem.all);
end loop;
return result;
end Get_Cost;
function Get_Writes(mem : Split_Type) return Long_Integer is
result : Long_Integer := 0;
begin
for i in mem.banks'Range loop
result := result + Get_Writes(mem.banks(i).mem.all);
end loop;
return result;
end Get_Writes;
function Get_Path_Length(mem : Split_Type) return Natural is
bank0 : constant Natural := Get_Path_Length(mem.banks(0).mem.all);
bank1 : constant Natural := Get_Path_Length(mem.banks(1).mem.all);
asize : constant Natural := Get_Address_Bits;
begin
return asize + Natural'Max(bank0, bank1);
end Get_Path_Length;
procedure Generate(mem : in Split_Type;
sigs : in out Unbounded_String;
code : in out Unbounded_String) is
other : constant Memory_Pointer := Get_Memory(mem);
bank0 : constant Memory_Pointer :=
Memory_Pointer(mem.banks(0).mem);
bank1 : constant Memory_Pointer :=
Memory_Pointer(mem.banks(1).mem);
join0 : constant Join_Pointer := Find_Join(bank0);
join1 : constant Join_Pointer := Find_Join(bank1);
word_bits : constant Natural := 8 * Get_Word_Size(mem);
name : constant String := "m" & To_String(Get_ID(mem));
oname : constant String := "m" & To_String(Get_ID(other.all));
b0name : constant String := "m" & To_String(Get_ID(bank0.all));
b1name : constant String := "m" & To_String(Get_ID(bank1.all));
out0name : constant String := "m" & To_String(Get_ID(join0.all));
out1name : constant String := "m" & To_String(Get_ID(join1.all));
wsize : constant Address_Type := Address_Type(Get_Word_Size(mem));
offset : constant Long_Integer := Long_Integer(mem.offset / wsize);
begin
Generate(other.all, sigs, code);
-- Port into bank0 is b0name.
-- Port out of bank0 is out0name.
Generate(bank0.all, sigs, code);
-- Port into bank1 is b1name.
-- Port out of bank1 is out1name.
Generate(bank1.all, sigs, code);
Line(code, name & "_combine : entity work.combine");
Line(code, " generic map (");
Line(code, " ADDR_WIDTH => ADDR_WIDTH,");
Line(code, " WORD_WIDTH => " & To_String(word_bits) & ",");
Line(code, " BOFFSET => " & To_String(Log2(offset) - 1));
Line(code, " )");
Line(code, " port map (");
Line(code, " clk => clk,");
Line(code, " rst => rst,");
Line(code, " addr0 => " & out0name & "_addr,");
Line(code, " din0 => " & out0name & "_din,");
Line(code, " dout0 => " & out0name & "_dout,");
Line(code, " re0 => " & out0name & "_re,");
Line(code, " we0 => " & out0name & "_we,");
Line(code, " mask0 => " & out0name & "_mask,");
Line(code, " ready0 => " & out0name & "_ready,");
Line(code, " addr1 => " & out1name & "_addr,");
Line(code, " din1 => " & out1name & "_din,");
Line(code, " dout1 => " & out1name & "_dout,");
Line(code, " re1 => " & out1name & "_re,");
Line(code, " we1 => " & out1name & "_we,");
Line(code, " mask1 => " & out1name & "_mask,");
Line(code, " ready1 => " & out1name & "_ready,");
Line(code, " maddr => " & oname & "_addr,");
Line(code, " mout => " & oname & "_din,");
Line(code, " min => " & oname & "_dout,");
Line(code, " mre => " & oname & "_re,");
Line(code, " mwe => " & oname & "_we,");
Line(code, " mmask => " & oname & "_mask,");
Line(code, " mready => " & oname & "_ready");
Line(code, " );");
-- Port into the split.
Declare_Signals(sigs, name, word_bits);
Line(code, name & "_sp : entity work.split");
Line(code, " generic map (");
Line(code, " ADDR_WIDTH => ADDR_WIDTH,");
Line(code, " WORD_WIDTH => " & To_String(word_bits) & ",");
Line(code, " BOFFSET => " & To_String(Log2(offset) - 1));
Line(code, " )");
Line(code, " port map (");
Line(code, " clk => clk,");
Line(code, " rst => rst,");
Line(code, " addr => " & name & "_addr,");
Line(code, " din => " & name & "_din,");
Line(code, " dout => " & name & "_dout,");
Line(code, " re => " & name & "_re,");
Line(code, " we => " & name & "_we,");
Line(code, " mask => " & name & "_mask,");
Line(code, " ready => " & name & "_ready,");
Line(code, " maddr0 => " & b0name & "_addr,");
Line(code, " mout0 => " & b0name & "_din,");
Line(code, " min0 => " & b0name & "_dout,");
Line(code, " mre0 => " & b0name & "_re,");
Line(code, " mwe0 => " & b0name & "_we,");
Line(code, " mmask0 => " & b0name & "_mask,");
Line(code, " mready0 => " & b0name & "_ready,");
Line(code, " maddr1 => " & b1name & "_addr,");
Line(code, " mout1 => " & b1name & "_din,");
Line(code, " min1 => " & b1name & "_dout,");
Line(code, " mre1 => " & b1name & "_re,");
Line(code, " mwe1 => " & b1name & "_we,");
Line(code, " mmask1 => " & b1name & "_mask,");
Line(code, " mready1 => " & b1name & "_ready");
Line(code, " );");
end Generate;
procedure Adjust(mem : in out Split_Type) is
ptr : Memory_Pointer;
jp : Join_Pointer;
begin
Adjust(Container_Type(mem));
for i in mem.banks'Range loop
ptr := Clone(mem.banks(i).mem.all);
mem.banks(i).mem := ptr;
jp := Find_Join(ptr);
Set_Parent(jp.all, mem'Unchecked_Access);
end loop;
end Adjust;
procedure Finalize(mem : in out Split_Type) is
begin
for i in mem.banks'Range loop
Destroy(Memory_Pointer(mem.banks(i).mem));
end loop;
Finalize(Container_Type(mem));
end Finalize;
procedure Forward_Read(mem : in out Split_Type;
source : in Natural;
address : in Address_Type;
size : in Positive) is
abits : constant Positive := Get_Address_Bits;
mask : constant Address_Type := Address_Type(2) ** abits - 1;
out_addr : Address_Type := address;
begin
if source = 1 then
out_addr := (address + mem.offset) and mask;
end if;
Read(Container_Type(mem), out_addr, size);
end Forward_Read;
procedure Forward_Write(mem : in out Split_Type;
source : in Natural;
address : in Address_Type;
size : in Positive) is
abits : constant Positive := Get_Address_Bits;
mask : constant Address_Type := Address_Type(2) ** abits - 1;
out_addr : Address_Type := address;
begin
if source = 1 then
out_addr := (address + mem.offset) and mask;
end if;
Write(Container_Type(mem), out_addr, size);
end Forward_Write;
procedure Forward_Idle(mem : in out Split_Type;
source : in Natural;
cycles : in Time_Type) is
begin
Idle(Container_Type(mem), cycles);
end Forward_Idle;
function Forward_Get_Time(mem : Split_Type) return Time_Type is
begin
return Get_Time(Container_Type(mem));
end Forward_Get_Time;
function Get_Join_Length(mem : Split_Type) return Natural is
begin
return Get_Address_Bits;
end Get_Join_Length;
end Memory.Split;
|
package Prot3_Pkg is
type Rec is record
V1 : Short_Integer;
V2 : Short_Integer;
end record with Volatile_Full_Access;
protected type Prot is
procedure Foo (J : Short_Integer);
private
Val : Rec;
end Prot;
P : Prot;
end Prot3_Pkg;
|
package body agar.gui.widget.menu is
use type c.int;
package cbinds is
procedure expand
(menu : menu_access_t;
item : item_access_t;
x : c.int;
y : c.int);
pragma import (c, expand, "AG_MenuExpand");
procedure set_padding
(menu : menu_access_t;
left : c.int;
right : c.int;
top : c.int;
bottom : c.int);
pragma import (c, set_padding, "AG_MenuSetPadding");
procedure set_label_padding
(menu : menu_access_t;
left : c.int;
right : c.int;
top : c.int;
bottom : c.int);
pragma import (c, set_label_padding, "AG_MenuSetLabelPadding");
function node
(parent : item_access_t;
text : cs.chars_ptr;
icon : agar.gui.surface.surface_access_t) return item_access_t;
pragma import (c, node, "AG_MenuNode");
function action
(parent : item_access_t;
text : cs.chars_ptr;
icon : agar.gui.surface.surface_access_t;
func : agar.core.event.callback_t;
fmt : agar.core.types.void_ptr_t) return item_access_t;
pragma import (c, action, "AG_MenuAction");
function action_keyboard
(parent : item_access_t;
text : cs.chars_ptr;
icon : agar.gui.surface.surface_access_t;
key : c.int;
modkey : c.int;
func : agar.core.event.callback_t;
fmt : agar.core.types.void_ptr_t) return item_access_t;
pragma import (c, action_keyboard, "AG_MenuActionKb");
function dynamic_item
(parent : item_access_t;
text : cs.chars_ptr;
icon : agar.gui.surface.surface_access_t;
func : agar.core.event.callback_t;
fmt : agar.core.types.void_ptr_t) return item_access_t;
pragma import (c, dynamic_item, "AG_MenuDynamicItem");
function dynamic_item_keyboard
(parent : item_access_t;
text : cs.chars_ptr;
icon : agar.gui.surface.surface_access_t;
key : c.int;
modkey : c.int;
func : agar.core.event.callback_t;
fmt : agar.core.types.void_ptr_t) return item_access_t;
pragma import (c, dynamic_item_keyboard, "AG_MenuDynamicItemKb");
function toolbar_item
(parent : item_access_t;
toolbar : agar.gui.widget.toolbar.toolbar_access_t;
text : cs.chars_ptr;
icon : agar.gui.surface.surface_access_t;
key : c.int;
modkey : c.int;
func : agar.core.event.callback_t;
fmt : agar.core.types.void_ptr_t) return item_access_t;
pragma import (c, toolbar_item, "AG_MenuTool");
procedure set_label
(item : item_access_t;
label : cs.chars_ptr);
pragma import (c, set_label, "AG_MenuSetLabelS");
procedure set_poll_function
(item : item_access_t;
func : agar.core.event.callback_t;
fmt : agar.core.types.void_ptr_t);
pragma import (c, set_poll_function, "AG_MenuSetPollFn");
function bind_bool
(item : item_access_t;
text : cs.chars_ptr;
icon : agar.gui.surface.surface_access_t;
value : access c.int;
invert : c.int) return item_access_t;
pragma import (c, bind_bool, "agar_gui_widget_menu_bool");
function bind_bool_with_mutex
(item : item_access_t;
text : cs.chars_ptr;
icon : agar.gui.surface.surface_access_t;
value : access c.int;
invert : c.int;
mutex : agar.core.threads.mutex_t) return item_access_t;
pragma import (c, bind_bool_with_mutex, "AG_MenuIntBoolMp");
function bind_flags
(item : item_access_t;
text : cs.chars_ptr;
icon : agar.gui.surface.surface_access_t;
value : access mask_t;
flags : mask_t;
invert : c.int) return item_access_t;
pragma import (c, bind_flags, "agar_gui_widget_menu_int_flags");
function bind_flags_with_mutex
(item : item_access_t;
text : cs.chars_ptr;
icon : agar.gui.surface.surface_access_t;
value : access mask_t;
flags : mask_t;
invert : c.int;
mutex : agar.core.threads.mutex_t) return item_access_t;
pragma import (c, bind_flags_with_mutex, "AG_MenuIntFlagsMp");
function bind_flags8
(item : item_access_t;
text : cs.chars_ptr;
icon : agar.gui.surface.surface_access_t;
value : access mask8_t;
flags : mask8_t;
invert : c.int) return item_access_t;
pragma import (c, bind_flags8, "agar_gui_widget_menu_int_flags8");
function bind_flags8_with_mutex
(item : item_access_t;
text : cs.chars_ptr;
icon : agar.gui.surface.surface_access_t;
value : access mask8_t;
flags : mask8_t;
invert : c.int;
mutex : agar.core.threads.mutex_t) return item_access_t;
pragma import (c, bind_flags8_with_mutex, "AG_MenuInt8FlagsMp");
function bind_flags16
(item : item_access_t;
text : cs.chars_ptr;
icon : agar.gui.surface.surface_access_t;
value : access mask16_t;
flags : mask16_t;
invert : c.int) return item_access_t;
pragma import (c, bind_flags16, "agar_gui_widget_menu_int_flags16");
function bind_flags16_with_mutex
(item : item_access_t;
text : cs.chars_ptr;
icon : agar.gui.surface.surface_access_t;
value : access mask16_t;
flags : mask16_t;
invert : c.int;
mutex : agar.core.threads.mutex_t) return item_access_t;
pragma import (c, bind_flags16_with_mutex, "AG_MenuInt16FlagsMp");
function bind_flags32
(item : item_access_t;
text : cs.chars_ptr;
icon : agar.gui.surface.surface_access_t;
value : access mask32_t;
flags : mask32_t;
invert : c.int) return item_access_t;
pragma import (c, bind_flags32, "agar_gui_widget_menu_int_flags32");
function bind_flags32_with_mutex
(item : item_access_t;
text : cs.chars_ptr;
icon : agar.gui.surface.surface_access_t;
value : access mask32_t;
flags : mask32_t;
invert : c.int;
mutex : agar.core.threads.mutex_t) return item_access_t;
pragma import (c, bind_flags32_with_mutex, "AG_MenuInt32FlagsMp");
procedure section
(item : item_access_t;
text : cs.chars_ptr);
pragma import (c, section, "AG_MenuSectionS");
end cbinds;
procedure expand
(menu : menu_access_t;
item : item_access_t;
x : natural;
y : natural) is
begin
cbinds.expand
(menu => menu,
item => item,
x => c.int (x),
y => c.int (y));
end expand;
procedure set_padding
(menu : menu_access_t;
left : natural;
right : natural;
top : natural;
bottom : natural) is
begin
cbinds.set_padding
(menu => menu,
left => c.int (left),
right => c.int (right),
top => c.int (top),
bottom => c.int (bottom));
end set_padding;
procedure set_label_padding
(menu : menu_access_t;
left : natural;
right : natural;
top : natural;
bottom : natural) is
begin
cbinds.set_label_padding
(menu => menu,
left => c.int (left),
right => c.int (right),
top => c.int (top),
bottom => c.int (bottom));
end set_label_padding;
function node
(parent : item_access_t;
text : string;
icon : agar.gui.surface.surface_access_t) return item_access_t
is
ca_text : aliased c.char_array := c.to_c (text);
begin
return cbinds.node
(parent => parent,
text => cs.to_chars_ptr (ca_text'unchecked_access),
icon => icon);
end node;
function action
(parent : item_access_t;
text : string;
icon : agar.gui.surface.surface_access_t;
func : agar.core.event.callback_t) return item_access_t
is
ca_text : aliased c.char_array := c.to_c (text);
begin
return cbinds.action
(parent => parent,
text => cs.to_chars_ptr (ca_text'unchecked_access),
icon => icon,
func => func,
fmt => agar.core.types.null_ptr);
end action;
function action_keyboard
(parent : item_access_t;
text : string;
icon : agar.gui.surface.surface_access_t;
key : c.int;
modkey : c.int;
func : agar.core.event.callback_t) return item_access_t
is
ca_text : aliased c.char_array := c.to_c (text);
begin
return cbinds.action_keyboard
(parent => parent,
text => cs.to_chars_ptr (ca_text'unchecked_access),
icon => icon,
key => key,
modkey => modkey,
func => func,
fmt => agar.core.types.null_ptr);
end action_keyboard;
function dynamic_item
(parent : item_access_t;
text : string;
icon : agar.gui.surface.surface_access_t;
func : agar.core.event.callback_t) return item_access_t
is
ca_text : aliased c.char_array := c.to_c (text);
begin
return cbinds.dynamic_item
(parent => parent,
text => cs.to_chars_ptr (ca_text'unchecked_access),
icon => icon,
func => func,
fmt => agar.core.types.null_ptr);
end dynamic_item;
function dynamic_item_keyboard
(parent : item_access_t;
text : string;
icon : agar.gui.surface.surface_access_t;
key : c.int;
modkey : c.int;
func : agar.core.event.callback_t) return item_access_t
is
ca_text : aliased c.char_array := c.to_c (text);
begin
return cbinds.dynamic_item_keyboard
(parent => parent,
text => cs.to_chars_ptr (ca_text'unchecked_access),
icon => icon,
key => key,
modkey => modkey,
func => func,
fmt => agar.core.types.null_ptr);
end dynamic_item_keyboard;
function toolbar_item
(parent : item_access_t;
toolbar : agar.gui.widget.toolbar.toolbar_access_t;
text : string;
icon : agar.gui.surface.surface_access_t;
key : c.int;
modkey : c.int;
func : agar.core.event.callback_t) return item_access_t
is
ca_text : aliased c.char_array := c.to_c (text);
begin
return cbinds.toolbar_item
(parent => parent,
toolbar => toolbar,
text => cs.to_chars_ptr (ca_text'unchecked_access),
icon => icon,
key => key,
modkey => modkey,
func => func,
fmt => agar.core.types.null_ptr);
end toolbar_item;
procedure set_label
(item : item_access_t;
label : string)
is
ca_label : aliased c.char_array := c.to_c (label);
begin
cbinds.set_label
(item => item,
label => cs.to_chars_ptr (ca_label'unchecked_access));
end set_label;
procedure set_poll_function
(item : item_access_t;
func : agar.core.event.callback_t) is
begin
cbinds.set_poll_function
(item => item,
func => func,
fmt => agar.core.types.null_ptr);
end set_poll_function;
function bind_bool
(item : item_access_t;
text : string;
icon : agar.gui.surface.surface_access_t;
value : access boolean;
invert : boolean) return item_access_t
is
ca_text : aliased c.char_array := c.to_c (text);
c_invert : c.int := 0;
c_value : aliased c.int;
item_acc : item_access_t;
begin
if invert then c_invert := 1; end if;
item_acc := cbinds.bind_bool
(item => item,
text => cs.to_chars_ptr (ca_text'unchecked_access),
icon => icon,
value => c_value'unchecked_access,
invert => c_invert);
value.all := c_value = 1;
return item_acc;
end bind_bool;
function bind_bool_with_mutex
(item : item_access_t;
text : string;
icon : agar.gui.surface.surface_access_t;
value : access boolean;
invert : boolean;
mutex : agar.core.threads.mutex_t) return item_access_t
is
ca_text : aliased c.char_array := c.to_c (text);
c_invert : c.int := 0;
c_value : aliased c.int;
item_acc : item_access_t;
begin
if invert then c_invert := 1; end if;
item_acc := cbinds.bind_bool_with_mutex
(item => item,
text => cs.to_chars_ptr (ca_text'unchecked_access),
icon => icon,
value => c_value'unchecked_access,
invert => c_invert,
mutex => mutex);
value.all := c_value = 1;
return item_acc;
end bind_bool_with_mutex;
function bind_flags
(item : item_access_t;
text : string;
icon : agar.gui.surface.surface_access_t;
value : access mask_t;
flags : mask_t;
invert : boolean) return item_access_t
is
ca_text : aliased c.char_array := c.to_c (text);
c_invert : c.int := 0;
begin
if invert then c_invert := 1; end if;
return cbinds.bind_flags
(item => item,
text => cs.to_chars_ptr (ca_text'unchecked_access),
icon => icon,
value => value,
flags => flags,
invert => c_invert);
end bind_flags;
function bind_flags_with_mutex
(item : item_access_t;
text : string;
icon : agar.gui.surface.surface_access_t;
value : access mask_t;
flags : mask_t;
invert : boolean;
mutex : agar.core.threads.mutex_t) return item_access_t
is
ca_text : aliased c.char_array := c.to_c (text);
c_invert : c.int := 0;
begin
if invert then c_invert := 1; end if;
return cbinds.bind_flags_with_mutex
(item => item,
text => cs.to_chars_ptr (ca_text'unchecked_access),
icon => icon,
value => value,
flags => flags,
invert => c_invert,
mutex => mutex);
end bind_flags_with_mutex;
function bind_flags8
(item : item_access_t;
text : string;
icon : agar.gui.surface.surface_access_t;
value : access mask8_t;
flags : mask8_t;
invert : boolean) return item_access_t
is
ca_text : aliased c.char_array := c.to_c (text);
c_invert : c.int := 0;
begin
if invert then c_invert := 1; end if;
return cbinds.bind_flags8
(item => item,
text => cs.to_chars_ptr (ca_text'unchecked_access),
icon => icon,
value => value,
flags => flags,
invert => c_invert);
end bind_flags8;
function bind_flags8_with_mutex
(item : item_access_t;
text : string;
icon : agar.gui.surface.surface_access_t;
value : access mask8_t;
flags : mask8_t;
invert : boolean;
mutex : agar.core.threads.mutex_t) return item_access_t
is
ca_text : aliased c.char_array := c.to_c (text);
c_invert : c.int := 0;
begin
if invert then c_invert := 1; end if;
return cbinds.bind_flags8_with_mutex
(item => item,
text => cs.to_chars_ptr (ca_text'unchecked_access),
icon => icon,
value => value,
flags => flags,
invert => c_invert,
mutex => mutex);
end bind_flags8_with_mutex;
function bind_flags16
(item : item_access_t;
text : string;
icon : agar.gui.surface.surface_access_t;
value : access mask16_t;
flags : mask16_t;
invert : boolean) return item_access_t
is
ca_text : aliased c.char_array := c.to_c (text);
c_invert : c.int := 0;
begin
if invert then c_invert := 1; end if;
return cbinds.bind_flags16
(item => item,
text => cs.to_chars_ptr (ca_text'unchecked_access),
icon => icon,
value => value,
flags => flags,
invert => c_invert);
end bind_flags16;
function bind_flags16_with_mutex
(item : item_access_t;
text : string;
icon : agar.gui.surface.surface_access_t;
value : access mask16_t;
flags : mask16_t;
invert : boolean;
mutex : agar.core.threads.mutex_t) return item_access_t
is
ca_text : aliased c.char_array := c.to_c (text);
c_invert : c.int := 0;
begin
if invert then c_invert := 1; end if;
return cbinds.bind_flags16_with_mutex
(item => item,
text => cs.to_chars_ptr (ca_text'unchecked_access),
icon => icon,
value => value,
flags => flags,
invert => c_invert,
mutex => mutex);
end bind_flags16_with_mutex;
function bind_flags32
(item : item_access_t;
text : string;
icon : agar.gui.surface.surface_access_t;
value : access mask32_t;
flags : mask32_t;
invert : boolean) return item_access_t
is
ca_text : aliased c.char_array := c.to_c (text);
c_invert : c.int := 0;
begin
if invert then c_invert := 1; end if;
return cbinds.bind_flags32
(item => item,
text => cs.to_chars_ptr (ca_text'unchecked_access),
icon => icon,
value => value,
flags => flags,
invert => c_invert);
end bind_flags32;
function bind_flags32_with_mutex
(item : item_access_t;
text : string;
icon : agar.gui.surface.surface_access_t;
value : access mask32_t;
flags : mask32_t;
invert : boolean;
mutex : agar.core.threads.mutex_t) return item_access_t
is
ca_text : aliased c.char_array := c.to_c (text);
c_invert : c.int := 0;
begin
if invert then c_invert := 1; end if;
return cbinds.bind_flags32_with_mutex
(item => item,
text => cs.to_chars_ptr (ca_text'unchecked_access),
icon => icon,
value => value,
flags => flags,
invert => c_invert,
mutex => mutex);
end bind_flags32_with_mutex;
procedure section
(item : item_access_t;
text : string)
is
ca_text : aliased c.char_array := c.to_c (text);
begin
cbinds.section
(item => item,
text => cs.to_chars_ptr (ca_text'unchecked_access));
end section;
-- popup menus
package body popup is
package cbinds is
procedure show_at
(menu : popup_menu_access_t;
x : c.int;
y : c.int);
pragma import (c, show_at, "AG_PopupShowAt");
end cbinds;
procedure show_at
(menu : popup_menu_access_t;
x : natural;
y : natural) is
begin
cbinds.show_at
(menu => menu,
x => c.int (x),
y => c.int (y));
end show_at;
end popup;
function widget (menu : menu_access_t) return widget_access_t is
begin
return menu.widget'access;
end widget;
function widget (view : view_access_t) return widget_access_t is
begin
return view.widget'access;
end widget;
end agar.gui.widget.menu;
|
with Ada.Text_IO;
with Bubble;
procedure Main is
A : Bubble.Arr := (2, 1, 3, 7);
begin
Bubble.Sort(A);
for I in A'Range loop
Ada.Text_IO.Put_Line(A(I)'Image);
end loop;
end Main;
|
-- Lua.Util
-- Utility routines to go with the Ada 2012 Lua interface
-- Copyright (c) 2015, James Humphry - see LICENSE for terms
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Long_Float_Text_IO; use Ada.Long_Float_Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
package body Lua.Util is
procedure Print_Stack(L : Lua_State'Class) is
begin
if L.GetTop = 0 then
Put_Line("Stack now contains: -*- Stack is empty -*-");
goto Exit_Point;
end if;
Put_Line("Stack now contains:");
Put_Line("Rel index : Abs index : Type : Contents");
for I in reverse 1..L.GetTop loop
Put(I - L.GetTop - 1); Set_Col(13); Put(": ");
Put(L.AbsIndex(I)); Set_Col(27); Put(": ");
Put(L.TypeName(L.TypeInfo(I))); Set_Col(38); Put(": ");
case L.TypeInfo(I) is
when TBOOLEAN =>
Put((if L.ToBoolean(I) then "true" else "false"));
when TNUMBER =>
Put(L.ToNumber(I), Aft => 0, Exp => 0);
when TSTRING =>
Put("'" & L.ToString(I) & "'");
when TUSERDATA =>
declare
Name : constant String := L.Userdata_Name(I);
begin
if Name = "" then
Put(" - Non-Ada userdata");
else
Put(Name);
end if;
end;
when others =>
Put("-");
end case;
New_Line;
end loop;
<<Exit_Point>>
null;
end Print_Stack;
end Lua.Util;
|
with System;
with Ada.Unchecked_Conversion;
with Interfaces; use Interfaces;
package Unchecked_Convert9 is
type R is record
H : Unsigned_16;
L : Unsigned_16;
end record;
Var : R;
pragma Volatile (Var);
function Conv is new
Ada.Unchecked_Conversion (Source => Unsigned_32, Target => R);
procedure Proc;
end Unchecked_Convert9;
|
with PixelArray;
package Morphology is
function erode(image: PixelArray.ImagePlane; size: Positive) return PixelArray.ImagePlane
with Pre => size mod 2 /= 0;
function dilate(image: PixelArray.ImagePlane; size: Positive) return PixelArray.ImagePlane
with Pre => size mod 2 /= 0;
end Morphology;
|
pragma Ada_2012;
with Ada.Strings.Fixed;
use Ada;
with Ada.Text_IO;
package body Fakedsp.Data_Streams.Text is
Sampling_Frequency_Key : constant String := "Fs";
function Get_Format (Options : Option_List) return Data_Format
is
use Option_Lists.Option_Maps;
Pos : constant Cursor := Find (Options, "fmt");
begin
if Pos /= No_Element and then Element (Pos) = "float" then
return Float_Format;
else
return Sample_Format;
end if;
end Get_Format;
----------
-- Open --
----------
function Open_Source (Filename : String := Standard_IO_Name;
Options : Option_Lists.Option_List := Option_Lists.Empty_List)
return Text_Source_Access is
procedure Parse_Header (Item : Text_Source_Access) is
use Text_IO;
use Strings;
use Strings.Fixed;
procedure Parse_Line (Item : Text_Source_Access;
Line : String;
Colon_Position : Positive)
with Pre => Line (Line'First) = '#';
procedure Parse_Line (Item : Text_Source_Access;
Line : String;
Colon_Position : Positive)
is
Key : constant String :=
Trim (Line (Line'First + 1 .. Colon_Position - 1), Both);
Value : constant String :=
Trim (Line (Colon_Position + 1 .. Line'Last), Both);
begin
if Key = "" then
Put_Line (Standard_Error, "Warning: empty key in '" & Line & "'");
elsif Value = "" then
Put_Line (Standard_Error, "Warning: empty value in '" & Line & "'");
else
if Key = Sampling_Frequency_Key then
Item.Frequency := Frequency_Hz'Value (Value);
else
Put_Line (Standard_Error,
"Warning: unknown key "
& "'" & Key & "'"
& " in "
& "'" & Line & "'");
end if;
end if;
end Parse_Line;
-- function To_Be_Skipped (Line : String) return Boolean
-- is (Line'Length = 0);
begin
Item.Empty := True;
while not End_Of_File (Item.File) loop
declare
Line : constant String := Trim (Get_Line (Item.File), Both);
Colon_Position : Natural;
begin
Put_Line (Standard_Error, "##" & Line & "##");
if Line /= "" then
if Line (Line'First) /= '#' then
Item.Current_Sample := Float'Value (Line);
Item.Empty := False;
Put_Line ("BACK");
return;
end if;
Colon_Position := Index (Source => Line,
Pattern => ":");
if Colon_Position /= 0 then
Parse_Line (Item, Line, Colon_Position);
end if;
end if;
end;
end loop;
end Parse_Header;
Result : constant Text_Source_Access :=
new Text_Source'(File => <>,
Top_Channel => 1,
Frequency => 8000.0,
Current_Sample => 0.0,
Empty => False,
Format => Get_Format (Options));
begin
if Filename = Standard_IO_Name then
Open (Result.File, Text_IO.In_File);
else
Open (File => Result.File,
Name => Filename,
M => Text_IO.In_File);
end if;
Parse_Header (Result);
return Result;
end Open_Source;
----------
-- Read --
----------
procedure Read
(Src : in out Text_Source;
Sample : out Float;
End_Of_Stream : out Boolean;
Channel : Channel_Index := Channel_Index'First)
is
-- use Text_IO;
pragma Unreferenced (Channel);
begin
-- Output sample is always set to the current sample, even if
-- Empty is true and we are at the end of the file. In this way
-- Sample has some sensible value and it makes sense too... It is
-- like the ADC is keeping the last read value active
Sample := Src.Current_Sample;
if Src.Empty then
-- Put_Line (Standard_Error, "FINITO");
End_Of_Stream := True;
return;
else
End_Of_Stream := False;
end if;
while not Hybrid_Files.End_Of_File (Src.File) loop
declare
use Ada.Strings;
use Ada.Strings.Fixed;
Line : constant String := Trim (Hybrid_Files.Get_Line (Src.File), Both);
begin
if Line /= "" then
Src.Current_Sample := (case Src.Format is
when Sample_Format =>
Float (Sample_Type'Value (Line)),
when Float_Format =>
Float'Value (Line));
Src.Empty := False;
return;
end if;
end;
end loop;
pragma Assert (Hybrid_Files.End_Of_File (Src.File));
Src.Empty := True;
end Read;
----------
-- Read --
----------
procedure Read (Src : in out Text_Source;
Sample : out Sample_Type;
End_Of_Stream : out Boolean;
Channel : Channel_Index := Channel_Index'First)
is
Tmp : Float;
begin
Src.Read (Sample => Tmp,
End_Of_Stream => End_Of_Stream,
Channel => Channel);
Sample := Sample_Type (Tmp);
end Read;
-----------
-- Close --
-----------
procedure Close (Src : in out Text_Source) is
begin
Hybrid_Files.Close (Src.File);
Src.Empty := True;
end Close;
----------
-- Open --
----------
function Open_Destination
(Filename : String := Standard_IO_Name;
Sampling : Frequency_Hz := 8000.0;
Last_Channel : Channel_Index := 1;
Options : Option_Lists.Option_List := Option_Lists.Empty_List)
return Text_Destination_Access
is
Result : constant Text_Destination_Access :=
new Text_Destination'(File => <>,
Top_Channel => Last_Channel,
Frequency => Sampling,
Format => Get_Format (Options));
begin
if Filename = Standard_IO_Name then
Hybrid_Files.Open (File => Result.File,
M => Text_IO.Out_File);
else
Hybrid_Files.Create (File => Result.File,
Name => Filename,
M => Text_IO.Out_File);
end if;
Hybrid_Files.Put_Line (Result.File,
"# "
& Sampling_Frequency_Key
& ":"
& Frequency_Hz'Image (Result.Frequency));
Hybrid_Files.New_Line (Result.File);
return Result;
end Open_Destination;
-----------
-- Write --
-----------
procedure Write
(Dst : Text_Destination;
Sample : Sample_Type;
Channel : Channel_Index := Channel_Index'First)
is
begin
case Dst.Format is
when Float_Format =>
Dst.Write (Float (Sample), Channel);
when Sample_Format =>
Hybrid_Files.Put_Line (Dst.File, Sample_Type'Image (Sample));
end case;
end Write;
-----------
-- Write --
-----------
procedure Write (Dst : Text_Destination;
Sample : Float;
Channel : Channel_Index := Channel_Index'First)
is
begin
case Dst.Format is
when Float_Format =>
Hybrid_Files.Put_Line (Dst.File, Float'Image (Sample));
when Sample_Format =>
Dst.Write (Sample_Type (Sample), Channel);
end case;
end Write;
-----------
-- Close --
-----------
procedure Close (Dst : in out Text_Destination) is
begin
Hybrid_Files.Close (Dst.File);
end Close;
end Fakedsp.Data_Streams.Text;
|
------------------------------------------------------------------------------
-- --
-- ASIS-for-GNAT IMPLEMENTATION COMPONENTS --
-- --
-- A S I S . D A T A _ D E C O M P O S I T I O N . V C H E C K --
-- --
-- S p e c --
-- --
-- Copyright (c) 1995-2006, Free Software Foundation, Inc. --
-- --
-- ASIS-for-GNAT is free software; you can redistribute it and/or modify it --
-- under terms of the GNU General Public License as published by the Free --
-- Software Foundation; either version 2, or (at your option) any later --
-- version. ASIS-for-GNAT is distributed in the hope that it will be use- --
-- ful, but WITHOUT ANY WARRANTY; without even the implied warranty of MER- --
-- CHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General --
-- Public License for more details. You should have received a copy of the --
-- GNU General Public License distributed with ASIS-for-GNAT; see file --
-- COPYING. If not, write to the Free Software Foundation, 51 Franklin --
-- Street, Fifth Floor, Boston, MA 02110-1301, USA. --
-- --
-- --
-- --
-- --
-- --
-- --
-- --
-- --
-- ASIS-for-GNAT was originally developed by the ASIS-for-GNAT team at the --
-- Software Engineering Laboratory of the Swiss Federal Institute of --
-- Technology (LGL-EPFL) in Lausanne, Switzerland, in cooperation with the --
-- Scientific Research Computer Center of Moscow State University (SRCC --
-- MSU), Russia, with funding partially provided by grants from the Swiss --
-- National Science Foundation and the Swiss Academy of Engineering --
-- Sciences. ASIS-for-GNAT is now maintained by AdaCore --
-- (http://www.adacore.com). --
-- --
------------------------------------------------------------------------------
-- This package contains validity checks for abstractions declared in
-- Asis.Data_Decomposition (see 22.1, 22.3)
private package Asis.Data_Decomposition.Vcheck is
type Component_Kinds is (Not_A_Component, Arr, Rec);
procedure Check_Validity
(Comp : Record_Component;
Query : String);
-- Checks if Comp is valid in a sense as defined in 22.1. Raises
-- Asis_Failed and sets the corresponding error status and diagnosis in
-- case if the check fails. The Query parameter is supposed to be the name
-- of the query where the check is performad.
procedure Check_Validity
(Comp : Array_Component;
Query : String);
-- Checks if Comp is valid in a sense as defined in 22.3. Raises
-- Asis_Failed and sets the corresponding error status and diagnosis in
-- case if the check fails. The Query parameter is supposed to be the name
-- of the query where the check is performad.
procedure Raise_ASIS_Inappropriate_Component
(Diagnosis : String;
Component_Kind : Component_Kinds);
-- Raises ASIS_Inappropriate_Element with Value_Error Error Status.
-- Diagnosis usially is the name of the query where the exception is
-- raised. Component_Kind, if not equal to Not_A_Component, is used to put
-- in the ASIS diagnosis string some information to distinguish the
-- queries with the same name which are defined for both Record_Component
-- and Array_Component.
end Asis.Data_Decomposition.Vcheck;
|
-- SPDX-License-Identifier: Apache-2.0
--
-- Copyright (c) 2017 onox <denkpadje@gmail.com>
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
with Interfaces.C.Strings;
with System;
with Ada.Characters.Latin_1;
package body Orka.OS is
procedure Set_Task_Name (Name : in String) is
use Interfaces.C;
PR_SET_NAME : constant := 15;
function prctl
(option : int;
arg2 : Strings.chars_ptr;
arg3, arg4, arg5 : unsigned_long := 0) return int
with Import, Convention => C, External_Name => "prctl";
C_Name_Str : Strings.chars_ptr := Strings.New_String (Name);
Result : int;
begin
Result := prctl (PR_SET_NAME, C_Name_Str);
Strings.Free (C_Name_Str);
pragma Assert (Result = 0);
end Set_Task_Name;
----------------------------------------------------------------------------
type Clock_Kind is (Realtime, Monotonic);
for Clock_Kind use
(Realtime => 0,
Monotonic => 1);
for Clock_Kind'Size use Interfaces.C.int'Size;
type Timespec is record
Seconds : aliased Interfaces.C.long;
Nanoseconds : aliased Interfaces.C.long;
end record
with Convention => C;
function C_Clock_Gettime
(Kind : Clock_Kind;
Time : access Timespec) return Interfaces.C.int
with Import, Convention => C, External_Name => "clock_gettime";
function Monotonic_Clock return Duration is
use type Interfaces.C.int;
Value : aliased Timespec;
Result : Interfaces.C.int;
begin
Result := C_Clock_Gettime (Monotonic, Value'Access);
pragma Assert (Result = 0);
-- Makes compiler happy and can be optimized away (unlike raise Program_Error)
return Duration (Value.Seconds) + Duration (Value.Nanoseconds) / 1e9;
end Monotonic_Clock;
function Monotonic_Clock return Time is (Time (Duration'(Monotonic_Clock)));
----------------------------------------------------------------------------
subtype Size_Type is Interfaces.C.unsigned_long;
procedure C_Fwrite
(Value : String;
Size : Size_Type;
Count : Size_Type;
File : System.Address)
with Import, Convention => C, External_Name => "fwrite";
File_Standard_Output : constant System.Address
with Import, Convention => C, External_Name => "stdout";
File_Standard_Error : constant System.Address
with Import, Convention => C, External_Name => "stderr";
procedure Put_Line (Value : String; Kind : File_Kind := Standard_Output) is
package L1 renames Ada.Characters.Latin_1;
C_Value : constant String := Value & L1.LF;
begin
C_Fwrite (C_Value, 1, C_Value'Length,
(case Kind is
when Standard_Output => File_Standard_Output,
when Standard_Error => File_Standard_Error));
end Put_Line;
end Orka.OS;
|
-- Copyright (c) 1990 Regents of the University of California.
-- All rights reserved.
--
-- The primary authors of ayacc were David Taback and Deepak Tolani.
-- Enhancements were made by Ronald J. Schmalz.
--
-- Send requests for ayacc information to ayacc-info@ics.uci.edu
-- Send bug reports for ayacc to ayacc-bugs@ics.uci.edu
--
-- Redistribution and use in source and binary forms are permitted
-- provided that the above copyright notice and this paragraph are
-- duplicated in all such forms and that any documentation,
-- advertising materials, and other materials related to such
-- distribution and use acknowledge that the software was developed
-- by the University of California, Irvine. The name of the
-- University may not be used to endorse or promote products derived
-- from this software without specific prior written permission.
-- THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
-- IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
-- WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
-- Module : set_pack_body.ada
-- Component of : ayacc
-- Version : 1.2
-- Date : 11/21/86 12:35:14
-- SCCS File : disk21~/rschm/hasee/sccs/ayacc/sccs/sxset_pack_body.ada
-- $Header: set_pack_body.a,v 0.1 86/04/01 15:11:59 ada Exp $
-- $Log: set_pack_body.a,v $
-- Revision 0.1 86/04/01 15:11:59 ada
-- This version fixes some minor bugs with empty grammars
-- and $$ expansion. It also uses vads5.1b enhancements
-- such as pragma inline.
--
--
-- Revision 0.0 86/02/19 18:41:30 ada
--
-- These files comprise the initial version of Ayacc
-- designed and implemented by David Taback and Deepak Tolani.
-- Ayacc has been compiled and tested under the Verdix Ada compiler
-- version 4.06 on a vax 11/750 running Unix 4.2BSD.
--
package body Set_Pack is
SCCS_ID : constant String := "@(#) set_pack_body.ada, Version 1.2";
Rcs_ID : constant String := "$Header: set_pack_body.a,v 0.1 86/04/01 15:11:59 ada Exp $";
type Cell is
record
Value : Universe;
Next : Link;
end record;
Extras : Link; -- For garbage collection.
function Get_Node return Link;
--RJS pragma inline(get_node);
function Get_Node return Link is
Temp_Link : Link;
begin
if Extras = null then
return new Cell;
else
Temp_Link := Extras;
Extras := Extras.Next;
Temp_Link.Next := null;
return Temp_Link;
end if;
end Get_Node;
procedure Make_Null (Set_1: in out Set) is
Temp_Link : Link;
begin
if Set_1.Head = null then
Set_1.Size := 0;
return;
end if;
-- Find tail of set_1 --
Temp_Link := Set_1.Head;
while Temp_Link.Next /= null loop
Temp_Link := Temp_Link.Next;
end loop;
-- Add set_1 elements to the extras stack --
Temp_Link.Next := Extras;
Extras := Set_1.Head;
Set_1 := (Size => 0, Head => null);
end Make_Null;
procedure Assign (Object : in out Set; Value : in Set) is
Temp_1, Temp_2: Link;
begin
if Object = Value then
return;
else
Make_Null(Object);
end if;
if Value.Head = null then
return;
end if;
Object.Head := Get_Node;
Object.Head.Value := Value.Head.Value;
Object.Head.Next := null;
Temp_1 := Object.Head;
Temp_2 := Value.Head.Next;
while Temp_2 /= null loop
Temp_1.Next := Get_Node;
Temp_1.Next.all := (Value => Temp_2.Value, Next => null);
Temp_1 := Temp_1.Next;
Temp_2 := Temp_2.Next;
end loop;
Temp_1.Next := null;
Object.Size := Value.Size;
end Assign;
procedure Insert (Element : in Universe; Into : in out Set) is
Temp_Link : Link;
Temp_Link_2 : Link;
begin
if Into.Head = null or else Element < Into.Head.Value then
Temp_Link := Get_Node;
Temp_Link.all := (Value => Element, Next => Into.Head);
Into.Head := Temp_Link;
Into.Size := Into.Size + 1;
return;
end if;
if Into.Head.Value = Element then
return;
end if;
Temp_Link := Into.Head;
while Temp_Link.Next /= null loop
if Element = Temp_Link.Next.Value then -- Already in the list.
return;
elsif Element < Temp_Link.Next.Value then
exit; -- Found place to insert.
else
Temp_Link := Temp_Link.Next;
end if;
end loop;
-- insert element --
Temp_Link_2 := Get_Node;
Temp_Link_2.Next := Temp_Link.Next;
Temp_Link_2.Value := Element;
Temp_Link.Next := Temp_Link_2;
Into.Size := Into.Size + 1;
end Insert;
procedure Insert (Set_1 : in Set; Into : in out Set) is
Temp, Trav1, Trav2 : Link;
begin
if Set_1.Head = null then
return;
elsif Set_1.Head = Into.Head then
return;
elsif Into.Head = null then
Assign(Into, Set_1);
return;
end if;
if Set_1.Head.Value < Into.Head.Value then
Temp := Into.Head;
Into.Head := Get_Node;
Into.Head.all := (Set_1.Head.Value, Temp);
Trav1 := Set_1.Head.Next;
Into.Size := Into.Size + 1;
elsif Set_1.Head.Value = Into.Head.Value then
Trav1 := Set_1.Head.Next;
else
Trav1 := Set_1.Head;
end if;
Trav2 := Into.Head;
while Trav1 /= null loop
while Trav2.Next /= null and then
Trav2.Next.Value < Trav1.Value loop
Trav2 := Trav2.Next;
end loop;
if Trav2.Next = null then
while Trav1 /= null loop
Trav2.Next := Get_Node;
Trav2.Next.all := (Trav1.Value, null);
Trav1 := Trav1.Next;
Trav2 := Trav2.Next;
Into.Size := Into.Size + 1;
end loop;
return;
end if;
if Trav2.Next.Value /= Trav1.Value then
Temp := Trav2.Next;
Trav2.Next := Get_Node;
Trav2.Next.all := (Trav1.Value, Temp);
Trav2 := Trav2.Next;
Into.Size := Into.Size + 1;
end if;
Trav1 := Trav1.Next;
end loop;
end Insert;
procedure Delete (Element : in Universe; From : in out Set) is
Temp_Link : Link;
T : Link;
begin
if From.Head = null then
return;
elsif Element < From.Head.Value then
return;
elsif Element = From.Head.Value then
Temp_Link := From.Head;
From.Head := From.Head.Next;
From.Size := From.Size - 1;
Temp_Link.Next := Extras;
Extras := Temp_Link;
return;
end if;
Temp_Link := From.Head;
while Temp_Link.Next /= null and then
Temp_Link.Next.Value < Element
loop
Temp_Link := Temp_Link.Next;
end loop;
if Temp_Link.Next /= null and then
Temp_Link.Next.Value = Element
then
T := Temp_Link.Next;
Temp_Link.Next := Temp_Link.Next.Next;
T.Next := Extras;
Extras := T;
From.Size := From.Size - 1;
end if;
end Delete;
procedure Fassign (Object : in out Set; Value : in out Set) is
begin
-- Free the contents of OBJECT first.
Object := Value;
Value := (Head => null, Size => 0);
end Fassign;
function Is_Member (Element: Universe; Of_Set: Set) return Boolean is
Temp_Link : Link;
begin
Temp_Link := Of_Set.Head;
while Temp_Link /= null and then Temp_Link.Value < Element loop
Temp_Link := Temp_Link.Next;
end loop;
return Temp_Link /= null and then Temp_Link.Value = Element;
end Is_Member;
function Is_Empty (Set_1: Set) return Boolean is
begin
return Set_1.Head = null;
end Is_Empty;
function Size_of (Set_1: Set) return Natural is
begin
return Set_1.Size;
end Size_of;
function "=" (Set_1 : Set; Set_2 : Set) return Boolean is
Link_1, Link_2: Link;
begin
if Set_1.Size /= Set_2.Size then
return False;
end if;
Link_1 := Set_1.Head;
Link_2 := Set_2.Head;
while Link_1 /= null and then Link_2 /= null loop
if Link_1.Value /= Link_2.Value then
exit;
end if;
Link_1 := Link_1.Next;
Link_2 := Link_2.Next;
end loop;
return Link_1 = Link_2; -- True if both equal to null
end "=";
procedure Initialize (Iterator : in out Set_Iterator; Using : in Set) is
begin
Iterator := Set_Iterator(Using.Head);
end Initialize;
function More (Iterator: Set_Iterator) return Boolean is
begin
return Iterator /= null;
end More;
procedure Next (Iterator: in out Set_Iterator; Element: out Universe) is
begin
Element := Iterator.Value;
Iterator := Set_Iterator(Iterator.Next);
exception
when Constraint_Error =>
raise No_More_Elements;
end Next;
end Set_Pack;
|
-----------------------------------------------------------------------
-- elf -- ELF information
-- Copyright (C) 2015 Stephane Carrez
-- Written by Stephane Carrez (Stephane.Carrez@gmail.com)
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
with Interfaces;
package ELF is
pragma Preelaborate;
subtype Elf32_Word is Interfaces.Unsigned_32;
subtype Elf64_Word is Interfaces.Unsigned_64;
-- Legal values for the ELF header p_type (segment type).
PT_NULL : constant Elf32_Word := 0; -- Program header table entry unused.
PT_LOAD : constant Elf32_Word := 1; -- Loadable program segment
PT_DYNAMIC : constant Elf32_Word := 2; -- Dynamic linking information
PT_INTERP : constant Elf32_Word := 3; -- Program interpreter
PT_NOTE : constant Elf32_Word := 4; -- Auxiliary information
PT_SHLIB : constant Elf32_Word := 5; -- Reserved
PT_PHDR : constant Elf32_Word := 6; -- Entry for header table itself
PT_TLS : constant Elf32_Word := 7; -- Thread-local storage segment
PT_NUM : constant Elf32_Word := 8; -- Number of defined types
PT_LOOS : constant Elf32_Word := 16#60000000#; -- Start of OS-specific
PT_GNU_EH_FRAME : constant Elf32_Word := 16#6474e550#; -- GCC .eh_frame_hdr segment
PT_GNU_STACK : constant Elf32_Word := 16#6474e551#; -- Indicates stack executability
PT_GNU_RELRO : constant Elf32_Word := 16#6474e552#; -- Read-only after relocation
PT_LOSUNW : constant Elf32_Word := 16#6ffffffa#;
PT_SUNWBSS : constant Elf32_Word := 16#6ffffffa#; -- Sun Specific segment
PT_SUNWSTACK : constant Elf32_Word := 16#6ffffffb#; -- Stack segment
PT_HISUNW : constant Elf32_Word := 16#6fffffff#;
PT_HIOS : constant Elf32_Word := 16#6fffffff#; -- End of OS-specific
PT_LOPROC : constant Elf32_Word := 16#70000000#; -- Start of processor-specific
PT_HIPROC : constant Elf32_Word := 16#7fffffff#; -- End of processor-specific
-- Legal values for ELF header p_flags (segment flags).
PF_X : constant Elf32_Word := 1; -- Segment is executable.
PF_W : constant Elf32_Word := 2; -- Segment is writable.
PF_R : constant Elf32_Word := 4; -- Segment is readable.
end ELF;
|
package Benchmark.Tree is
type Tree_Type is new Benchmark_Type with private;
function Create_Tree return Benchmark_Pointer;
overriding
procedure Set_Argument(benchmark : in out Tree_Type;
arg : in String);
overriding
procedure Run(benchmark : in Tree_Type);
private
type Tree_Type is new Benchmark_Type with record
size : Positive := 1024;
iterations : Positive := 10000;
end record;
end Benchmark.Tree;
|
-- Copyright (c) 2019 Maxim Reznik <reznikmm@gmail.com>
--
-- SPDX-License-Identifier: MIT
-- License-Filename: LICENSE
-------------------------------------------------------------
with Ada.Streams;
with Ada.Streams.Stream_IO;
with Ada.Unchecked_Deallocation;
with Ada.Wide_Wide_Text_IO;
with Interfaces;
with System;
with League.IRIs;
with League.Settings;
with League.String_Vectors;
with League.Holders;
with Slim.Menu_Models.JSON;
with Slim.Message_Decoders;
with Slim.Message_Visiters;
with Slim.Messages.audg;
with Slim.Messages.strm;
with Slim.Players.Connected_State_Visiters;
with Slim.Players.Displays;
with Slim.Players.Idle_State_Visiters;
with Slim.Players.Play_Radio_Visiters;
with Slim.Players.Play_Files_Visiters;
package body Slim.Players is
Hearbeat_Period : constant := 5.0;
procedure Read_Message
(Socket : GNAT.Sockets.Socket_Type;
Message : out Slim.Messages.Message_Access);
procedure Send_Hearbeat (Self : in out Player'Class);
procedure Read_Splash
(Splash : out League.Stream_Element_Vectors.Stream_Element_Vector;
File : League.Strings.Universal_String);
procedure Free is new Ada.Unchecked_Deallocation
(Slim.Messages.Message'Class, Slim.Messages.Message_Access);
function Seconds_To_Bytes
(File : League.Strings.Universal_String;
Skip : Positive) return League.Strings.Universal_String;
----------------
-- First_Menu --
----------------
function First_Menu
(Self : Player'Class) return Slim.Menu_Views.Menu_View
is
Ignore : Boolean;
begin
return Result : Slim.Menu_Views.Menu_View do
Result.Initialize
(Menu => Slim.Menu_Models.Menu_Model_Access (Self.Menu),
Font => Self.Font'Unchecked_Access);
end return;
end First_Menu;
-----------------
-- Get_Display --
-----------------
function Get_Display
(Self : Player;
Height : Positive := 32;
Width : Positive := 160) return Slim.Players.Displays.Display
is
Size : constant Ada.Streams.Stream_Element_Offset :=
Ada.Streams.Stream_Element_Offset (Height * Width / 8);
begin
return Result : Slim.Players.Displays.Display (Size) do
Slim.Players.Displays.Initialize (Result, Self);
end return;
end Get_Display;
------------------
-- Get_Position --
------------------
procedure Get_Position
(Self : in out Player'Class;
M3U : League.Strings.Universal_String;
Index : out Positive;
Skip : out Natural)
is
pragma Unreferenced (Self);
Setting : League.Settings.Settings;
Key : League.Strings.Universal_String;
Value : League.Holders.Holder;
begin
Key.Append ("Pause/Index.");
Key.Append (M3U);
Value := Setting.Value (Key);
if League.Holders.Is_Universal_String (Value) then
Key := League.Holders.Element (Value);
Index := Positive'Wide_Wide_Value (Key.To_Wide_Wide_String);
else
Index := 1;
end if;
Key.Clear;
Key.Append ("Pause/Skip.");
Key.Append (M3U);
Value := Setting.Value (Key);
if League.Holders.Is_Universal_String (Value) then
Key := League.Holders.Element (Value);
Skip := Natural'Wide_Wide_Value (Key.To_Wide_Wide_String);
else
Skip := 0;
end if;
end Get_Position;
----------------
-- Initialize --
----------------
procedure Initialize
(Self : in out Player'Class;
Socket : GNAT.Sockets.Socket_Type;
Font : League.Strings.Universal_String;
Splash : League.Strings.Universal_String;
Menu : League.Strings.Universal_String) is
begin
Self.Socket := Socket;
GNAT.Sockets.Set_Socket_Option
(Self.Socket,
GNAT.Sockets.Socket_Level,
(GNAT.Sockets.Receive_Timeout, Hearbeat_Period));
Slim.Fonts.Read (Self.Font, Font);
Read_Splash (Self.Splash, Splash);
Self.Menu :=
new Slim.Menu_Models.JSON.JSON_Menu_Model (Self'Unchecked_Access);
Slim.Menu_Models.JSON.JSON_Menu_Model (Self.Menu.all).Initialize
(File => Menu);
end Initialize;
----------------
-- Play_Files --
----------------
procedure Play_Files
(Self : in out Player'Class;
Root : League.Strings.Universal_String;
M3U : League.Strings.Universal_String;
List : Song_Array;
From : Positive;
Skip : Natural)
is
use type Ada.Calendar.Time;
Playlist : Song_Vectors.Vector;
begin
for X of List loop
Playlist.Append (X);
end loop;
Self.State :=
(Play_Files,
(Volume => 30,
Volume_Set_Time => Ada.Calendar.Clock - 60.0,
Current_Song => List (From).Title,
Paused => False,
Seconds => 0),
Root, M3U, Playlist, From, Skip);
Self.Request_Next_File;
end Play_Files;
--------------------
-- Play_Next_File --
--------------------
procedure Play_Next_File
(Self : in out Player'Class;
Immediate : Boolean := True) is
begin
if Self.State.Kind /= Play_Files then
return;
elsif Immediate then
declare
strm : Slim.Messages.strm.Strm_Message;
begin
strm.Simple_Command (Command => Slim.Messages.strm.Flush);
Write_Message (Self.Socket, strm);
end;
end if;
if Self.State.Index < Self.State.Playlist.Last_Index then
Self.State.Index := Self.State.Index + 1;
Self.State.Offset := 0;
Self.Request_Next_File;
else
Self.Stop;
end if;
end Play_Next_File;
------------------------
-- Play_Previous_File --
------------------------
procedure Play_Previous_File (Self : in out Player'Class;
Immediate : Boolean := True) is
begin
if Self.State.Kind /= Play_Files then
return;
elsif Immediate then
declare
strm : Slim.Messages.strm.Strm_Message;
begin
strm.Simple_Command (Command => Slim.Messages.strm.Flush);
Write_Message (Self.Socket, strm);
end;
end if;
if Self.State.Index > 1 then
Self.State.Index := Self.State.Index - 1;
Self.Request_Next_File;
else
Self.Stop;
end if;
end Play_Previous_File;
----------------
-- Play_Radio --
----------------
procedure Play_Radio
(Self : in out Player'Class;
URL : League.Strings.Universal_String)
is
use type Ada.Calendar.Time;
IRI : constant League.IRIs.IRI :=
League.IRIs.From_Universal_String (URL);
Host : League.Strings.Universal_String := IRI.Get_Host;
Port : constant Natural := IRI.Get_Port;
Port_Image : Wide_Wide_String := Integer'Wide_Wide_Image (Port);
Addr : GNAT.Sockets.Inet_Addr_Type;
Strm : Slim.Messages.strm.Strm_Message;
Request : League.String_Vectors.Universal_String_Vector;
Line : League.Strings.Universal_String;
begin
Self.Stop;
declare
Host_Entry : constant GNAT.Sockets.Host_Entry_Type :=
GNAT.Sockets.Get_Host_By_Name (Host.To_UTF_8_String);
begin
for J in 1 .. Host_Entry.Addresses_Length loop
Addr := GNAT.Sockets.Addresses (Host_Entry, J);
exit when Addr.Family in GNAT.Sockets.Family_Inet;
end loop;
end;
if Addr.Family not in GNAT.Sockets.Family_Inet then
return;
end if;
if Port /= 0 then
Port_Image (1) := ':';
Host.Append (Port_Image);
end if;
Line := +"GET /";
Line.Append (IRI.Get_Path.Join ('/'));
Line.Append (" HTTP/1.0");
Ada.Wide_Wide_Text_IO.Put_Line (Line.To_Wide_Wide_String);
Request.Append (Line);
Line := +"Host: ";
Line.Append (Host);
Request.Append (Line);
Request.Append (+"Icy-Metadata: 1");
Request.Append (+"");
Request.Append (+"");
Strm.Start
(Server => (GNAT.Sockets.Family_Inet,
Addr,
Port => GNAT.Sockets.Port_Type (Port)),
Request => Request);
Write_Message (Self.Socket, Strm);
Self.State :=
(Play_Radio,
(Volume => 30,
Volume_Set_Time => Ada.Calendar.Clock - 60.0,
Current_Song => League.Strings.Empty_Universal_String,
Paused => False,
Seconds => 0));
exception
when GNAT.Sockets.Host_Error =>
return;
end Play_Radio;
---------------------
-- Process_Message --
---------------------
not overriding procedure Process_Message (Self : in out Player) is
use type Ada.Calendar.Time;
function Get_Visiter return Slim.Message_Visiters.Visiter'Class;
function Get_Visiter return Slim.Message_Visiters.Visiter'Class is
begin
case Self.State.Kind is
when Connected =>
return V : Connected_State_Visiters.Visiter
(Self'Unchecked_Access);
when Idle =>
return V : Idle_State_Visiters.Visiter
(Self'Unchecked_Access);
when Play_Radio =>
return V : Play_Radio_Visiters.Visiter
(Self'Unchecked_Access);
when Play_Files =>
return V : Play_Files_Visiters.Visiter
(Self'Unchecked_Access);
end case;
end Get_Visiter;
V : Slim.Message_Visiters.Visiter'Class := Get_Visiter;
begin
if Self.State.Kind /= Connected
and then Ada.Calendar.Clock - Self.Ping > 5.0
then
Send_Hearbeat (Self);
end if;
declare
Message : Slim.Messages.Message_Access;
begin
Read_Message (Self.Socket, Message);
Message.Visit (V);
Free (Message);
exception
when E : GNAT.Sockets.Socket_Error =>
case GNAT.Sockets.Resolve_Exception (E) is
when GNAT.Sockets.Resource_Temporarily_Unavailable =>
Send_Hearbeat (Self);
when others =>
raise;
end case;
end;
end Process_Message;
------------------
-- Read_Message --
------------------
procedure Read_Message
(Socket : GNAT.Sockets.Socket_Type;
Message : out Slim.Messages.Message_Access)
is
use type Ada.Streams.Stream_Element_Offset;
Tag : Slim.Messages.Message_Tag;
Raw_Tag : Ada.Streams.Stream_Element_Array (1 .. 4)
with Address => Tag'Address;
Word : Ada.Streams.Stream_Element_Array (1 .. 4);
Length : Ada.Streams.Stream_Element_Offset := 0;
Last : Ada.Streams.Stream_Element_Offset;
Data : aliased League.Stream_Element_Vectors.Stream_Element_Vector;
Decoder : Slim.Message_Decoders.Decoder;
begin
GNAT.Sockets.Receive_Socket (Socket, Raw_Tag, Last);
if Last = 0 then
-- Timeout
return;
end if;
pragma Assert (Last = Raw_Tag'Length);
GNAT.Sockets.Receive_Socket (Socket, Word, Last);
pragma Assert (Last = Word'Length);
for Byte of Word loop
Length := Length * 256 + Ada.Streams.Stream_Element_Offset (Byte);
end loop;
while Length > 0 loop
declare
Piece : constant Ada.Streams.Stream_Element_Offset :=
Ada.Streams.Stream_Element_Offset'Min (Length, 256);
Input : Ada.Streams.Stream_Element_Array (1 .. Piece);
begin
GNAT.Sockets.Receive_Socket (Socket, Input, Last);
pragma Assert (Last = Input'Length);
Data.Append (Input);
Length := Length - Last;
end;
end loop;
Decoder.Decode (Tag, Data'Unchecked_Access, Message);
end Read_Message;
-----------------
-- Read_Splash --
-----------------
procedure Read_Splash
(Splash : out League.Stream_Element_Vectors.Stream_Element_Vector;
File : League.Strings.Universal_String)
is
Size : constant := 32 * 160 / 8;
Data : Ada.Streams.Stream_Element_Array (1 .. Size);
Last : Ada.Streams.Stream_Element_Offset;
Input : Ada.Streams.Stream_IO.File_Type;
begin
Ada.Streams.Stream_IO.Open
(Input,
Mode => Ada.Streams.Stream_IO.In_File,
Name => File.To_UTF_8_String);
Ada.Streams.Stream_IO.Read (Input, Data, Last);
pragma Assert (Last in Data'Last);
Ada.Streams.Stream_IO.Close (Input);
Splash.Clear;
Splash.Append (Data);
end Read_Splash;
-----------------------
-- Request_Next_File --
-----------------------
procedure Request_Next_File (Self : in out Player'Class) is
use type League.Strings.Universal_String;
Item : constant Song := Self.State.Playlist (Self.State.Index);
File : constant League.Strings.Universal_String := Item.File;
Strm : Slim.Messages.strm.Strm_Message;
Request : League.String_Vectors.Universal_String_Vector;
Line : League.Strings.Universal_String;
begin
Line.Append ("GET /Music/");
Line.Append (File);
Line.Append (" HTTP/1.0");
Ada.Wide_Wide_Text_IO.Put_Line (Line.To_Wide_Wide_String);
Request.Append (Line);
if Self.State.Offset > 0 then
Line.Clear;
Line.Append ("Range: ");
Line.Append
(Seconds_To_Bytes
(Self.State.Root & File, Self.State.Offset));
Request.Append (Line);
Ada.Wide_Wide_Text_IO.Put_Line (Line.To_Wide_Wide_String);
end if;
Request.Append (+"");
Request.Append (+"");
Strm.Start
(Server => (GNAT.Sockets.Family_Inet,
GNAT.Sockets.Inet_Addr ("0.0.0.0"),
Port => 8080),
Request => Request);
Write_Message (Self.Socket, Strm);
Self.State.Play_State.Current_Song := Item.Title;
end Request_Next_File;
-------------------
-- Save_Position --
-------------------
procedure Save_Position (Self : in out Player'Class) is
use type League.Strings.Universal_String;
Setting : League.Settings.Settings;
Value : League.Strings.Universal_String;
Skip : constant Natural :=
Self.State.Offset + Self.State.Play_State.Seconds;
begin
if Self.State.Kind /= Play_Files
or else Self.State.M3U_Name.Is_Empty
then
return;
end if;
Value.Append (Integer'Wide_Wide_Image (Self.State.Index));
Value := Value.Tail_From (2);
Setting.Set_Value
("Pause/Index." & Self.State.M3U_Name,
League.Holders.To_Holder (Value));
Value.Clear;
Value.Append (Integer'Wide_Wide_Image (Skip));
Value := Value.Tail_From (2);
Setting.Set_Value
("Pause/Skip." & Self.State.M3U_Name,
League.Holders.To_Holder (Value));
end Save_Position;
----------------------
-- Seconds_To_Bytes --
----------------------
function Seconds_To_Bytes
(File : League.Strings.Universal_String;
Skip : Positive) return League.Strings.Universal_String
is
procedure Read_ID3 (Input : in out Ada.Streams.Stream_IO.File_Type);
-- Skip ID3 header if any
procedure Read_MP3_Header
(Input : in out Ada.Streams.Stream_IO.File_Type;
Bit_Rate : out Ada.Streams.Stream_Element_Count);
function Image (Value : Ada.Streams.Stream_Element_Count)
return Wide_Wide_String;
-----------
-- Image --
-----------
function Image (Value : Ada.Streams.Stream_Element_Count)
return Wide_Wide_String
is
Img : constant Wide_Wide_String :=
Ada.Streams.Stream_Element_Count'Wide_Wide_Image (Value);
begin
return Img (2 .. Img'Last);
end Image;
--------------
-- Read_ID3 --
--------------
procedure Read_ID3 (Input : in out Ada.Streams.Stream_IO.File_Type) is
use type Ada.Streams.Stream_Element;
use type Ada.Streams.Stream_Element_Count;
use type Ada.Streams.Stream_IO.Count;
Index : constant Ada.Streams.Stream_IO.Positive_Count :=
Ada.Streams.Stream_IO.Index (Input);
Data : Ada.Streams.Stream_Element_Array (1 .. 10);
Last : Ada.Streams.Stream_Element_Count;
Skip : Ada.Streams.Stream_IO.Count := 0;
begin
Ada.Streams.Stream_IO.Read (Input, Data, Last);
if Last = Data'Last
and then Data (1) = Character'Pos ('I')
and then Data (2) = Character'Pos ('D')
and then Data (3) = Character'Pos ('3')
then
for J of Data (7 .. 10) loop
Skip := Skip * 128 + Ada.Streams.Stream_IO.Count (J);
end loop;
Ada.Streams.Stream_IO.Set_Index
(Input, Index + Data'Length + Skip);
else
Ada.Streams.Stream_IO.Set_Index (Input, Index);
end if;
end Read_ID3;
---------------------
-- Read_MP3_Header --
---------------------
procedure Read_MP3_Header
(Input : in out Ada.Streams.Stream_IO.File_Type;
Bit_Rate : out Ada.Streams.Stream_Element_Count)
is
use type Interfaces.Unsigned_16;
use type Ada.Streams.Stream_IO.Count;
type MPEG_Version is (MPEG_2_5, Wrong, MPEG_2, MPEG_1);
pragma Unreferenced (Wrong);
for MPEG_Version use (0, 1, 2, 3);
type MPEG_Layer is (Wrong, Layer_III, Layer_II, Layer_I);
pragma Unreferenced (Wrong);
for MPEG_Layer use (0, 1, 2, 3);
type MPEG_Mode is (Stereo, Joint_Stereo, Dual_Channel, Mono);
pragma Unreferenced (Stereo, Joint_Stereo, Dual_Channel, Mono);
for MPEG_Mode use (0, 1, 2, 3);
type MP3_Header is record
Sync_Word : Interfaces.Unsigned_16 range 0 .. 2 ** 11 - 1;
Version : MPEG_Version;
Layer : MPEG_Layer;
Protection : Boolean;
Bit_Rate : Interfaces.Unsigned_8 range 0 .. 15;
Frequency : Interfaces.Unsigned_8 range 0 .. 3;
Padding : Boolean;
Is_Private : Boolean;
Mode : MPEG_Mode;
Extension : Interfaces.Unsigned_8 range 0 .. 3;
Copy : Boolean;
Original : Boolean;
Emphasis : Interfaces.Unsigned_8 range 0 .. 3;
end record;
for MP3_Header'Object_Size use 32;
for MP3_Header'Bit_Order use System.High_Order_First;
for MP3_Header use record
Sync_Word at 0 range 0 .. 10;
Version at 0 range 11 .. 12;
Layer at 0 range 13 .. 14;
Protection at 0 range 15 .. 15;
Bit_Rate at 0 range 16 .. 19;
Frequency at 0 range 20 .. 21;
Padding at 0 range 22 .. 22;
Is_Private at 0 range 23 .. 23;
Mode at 0 range 24 .. 25;
Extension at 0 range 26 .. 27;
Copy at 0 range 28 .. 28;
Original at 0 range 29 .. 29;
Emphasis at 0 range 30 .. 31;
end record;
procedure Read_Header (Header : out MP3_Header);
MPEG_1_Bit_Rate : constant array
(MPEG_Layer range Layer_III .. Layer_I,
Interfaces.Unsigned_8 range 1 .. 14) of
Ada.Streams.Stream_Element_Count :=
(Layer_I => (32_000, 64_000, 96_000, 128_000, 160_000, 192_000,
224_000, 256_000, 288_000, 320_000, 352_000, 384_000,
416_000, 448_000),
Layer_II => (32_000, 48_000, 56_000, 64_000, 80_000, 96_000,
112_000, 128_000, 160_000, 192_000, 224_000,
256_000, 320_000, 384_000),
Layer_III => (32_000, 40_000, 48_000, 56_000, 64_000, 80_000,
96_000, 112_000, 128_000, 160_000, 192_000,
224_000, 256_000, 320_000));
MPEG_2_Bit_Rate : constant array
(MPEG_Layer range Layer_II .. Layer_I,
Interfaces.Unsigned_8 range 1 .. 14) of
Ada.Streams.Stream_Element_Count :=
(Layer_I => (32_000, 48_000, 56_000, 64_000, 80_000, 96_000,
112_000, 128_000, 144_000, 160_000, 176_000, 192_000,
224_000, 256_000),
Layer_II => (8_000, 16_000, 24_000, 32_000, 40_000, 48_000,
56_000, 64_000, 80_000, 96_000, 112_000,
128_000, 144_000, 160_000));
-----------------
-- Read_Header --
-----------------
procedure Read_Header (Header : out MP3_Header) is
use type System.Bit_Order;
Stream : constant Ada.Streams.Stream_IO.Stream_Access :=
Ada.Streams.Stream_IO.Stream (Input);
Data : Ada.Streams.Stream_Element_Array (1 .. 4)
with Import, Address => Header'Address;
begin
if MP3_Header'Bit_Order = System.Default_Bit_Order then
Ada.Streams.Stream_Element_Array'Read (Stream, Data);
else
for X of reverse Data loop
Ada.Streams.Stream_Element'Read (Stream, X);
end loop;
end if;
end Read_Header;
Header : MP3_Header := (Sync_Word => 0, others => <>);
begin
while not Ada.Streams.Stream_IO.End_Of_File (Input) loop
Read_Header (Header);
exit when Header.Sync_Word = 16#7FF#;
Ada.Streams.Stream_IO.Set_Index
(Input,
Ada.Streams.Stream_IO.Index (Input) - 3);
end loop;
if Header.Sync_Word /= 16#7FF# then
Bit_Rate := 0;
elsif Header.Version = MPEG_1 and
Header.Layer in MPEG_1_Bit_Rate'Range (1) and
Header.Bit_Rate in MPEG_1_Bit_Rate'Range (2)
then
Bit_Rate := MPEG_1_Bit_Rate (Header.Layer, Header.Bit_Rate);
elsif Header.Version in MPEG_2 .. MPEG_2_5 and
Header.Layer in Layer_III .. Layer_I and
Header.Bit_Rate in MPEG_2_Bit_Rate'Range (2)
then
Bit_Rate := MPEG_2_Bit_Rate
(MPEG_Layer'Max (Header.Layer, Layer_II),
Header.Bit_Rate);
else
Bit_Rate := 0;
end if;
end Read_MP3_Header;
use type Ada.Streams.Stream_Element_Count;
Input : Ada.Streams.Stream_IO.File_Type;
Bit_Rate : Ada.Streams.Stream_Element_Count;
Offset : Ada.Streams.Stream_Element_Count;
Result : League.Strings.Universal_String;
begin
Ada.Streams.Stream_IO.Open
(Input, Ada.Streams.Stream_IO.In_File, File.To_UTF_8_String);
Read_ID3 (Input);
Read_MP3_Header (Input, Bit_Rate);
Offset := Bit_Rate * Ada.Streams.Stream_Element_Count (Skip) / 8;
Result.Append ("bytes=");
Result.Append (Image (Offset));
Result.Append ("-");
Ada.Streams.Stream_IO.Close (Input);
return Result;
end Seconds_To_Bytes;
-------------------
-- Send_Hearbeat --
-------------------
procedure Send_Hearbeat (Self : in out Player'Class) is
strm : Slim.Messages.strm.Strm_Message;
begin
strm.Simple_Command
(Command => Slim.Messages.strm.Status);
Write_Message (Self.Socket, strm);
Self.Ping := Ada.Calendar.Clock;
end Send_Hearbeat;
----------
-- Stop --
----------
procedure Stop (Self : in out Player'Class) is
use type Ada.Calendar.Time;
Strm : Slim.Messages.strm.Strm_Message;
begin
if Self.State.Kind in Play_Radio | Play_Files then
Strm.Simple_Command (Slim.Messages.strm.Stop);
Write_Message (Self.Socket, Strm);
Self.State :=
(Idle,
Ada.Calendar.Clock - 60.0,
Self.First_Menu);
Self.Send_Hearbeat; -- A reply to this will update display
end if;
end Stop;
------------
-- Volume --
------------
procedure Volume
(Self : in out Player'Class;
Value : Natural)
is
Audg : Slim.Messages.audg.Audg_Message;
begin
if Self.State.Kind in Play_Radio | Play_Files then
Self.State.Play_State.Volume := Value;
Self.State.Play_State.Volume_Set_Time := Ada.Calendar.Clock;
end if;
Audg.Set_Volume (Value);
Write_Message (Self.Socket, Audg);
end Volume;
-------------------
-- Write_Message --
-------------------
procedure Write_Message
(Socket : GNAT.Sockets.Socket_Type;
Message : Slim.Messages.Message'Class)
is
use type Ada.Streams.Stream_Element_Offset;
use type Ada.Streams.Stream_Element_Array;
Data : League.Stream_Element_Vectors.Stream_Element_Vector;
Tag : Slim.Messages.Message_Tag;
Raw_Tag : Ada.Streams.Stream_Element_Array (1 .. 4)
with Address => Tag'Address;
Word : Ada.Streams.Stream_Element_Array (1 .. 2);
Length : Ada.Streams.Stream_Element_Offset;
Last : Ada.Streams.Stream_Element_Offset;
begin
Message.Write (Tag, Data);
Length := Raw_Tag'Length + Data.Length;
Word (1) := Ada.Streams.Stream_Element
(Length / Ada.Streams.Stream_Element'Modulus);
Word (2) := Ada.Streams.Stream_Element
(Length mod Ada.Streams.Stream_Element'Modulus);
GNAT.Sockets.Send_Socket
(Socket, Word & Raw_Tag & Data.To_Stream_Element_Array, Last);
pragma Assert (Last = Length + Word'Length);
end Write_Message;
end Slim.Players;
|
------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Ada Modeling Framework --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2011-2012, Vadim Godunko <vgodunko@gmail.com> --
-- All rights reserved. --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions --
-- are met: --
-- --
-- * Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- --
-- * Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in the --
-- documentation and/or other materials provided with the distribution. --
-- --
-- * Neither the name of the Vadim Godunko, IE nor the names of its --
-- contributors may be used to endorse or promote products derived from --
-- this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR --
-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --
-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --
-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS --
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with AMF.Elements;
with AMF.Internals.Element_Collections;
with AMF.Internals.Helpers;
with AMF.Internals.Tables.UML_Attributes;
with AMF.Visitors.UML_Iterators;
with AMF.Visitors.UML_Visitors;
with League.Strings.Internals;
with Matreshka.Internals.Strings;
package body AMF.Internals.UML_Primitive_Types is
-------------------
-- Enter_Element --
-------------------
overriding procedure Enter_Element
(Self : not null access constant UML_Primitive_Type_Proxy;
Visitor : in out AMF.Visitors.Abstract_Visitor'Class;
Control : in out AMF.Visitors.Traverse_Control) is
begin
if Visitor in AMF.Visitors.UML_Visitors.UML_Visitor'Class then
AMF.Visitors.UML_Visitors.UML_Visitor'Class
(Visitor).Enter_Primitive_Type
(AMF.UML.Primitive_Types.UML_Primitive_Type_Access (Self),
Control);
end if;
end Enter_Element;
-------------------
-- Leave_Element --
-------------------
overriding procedure Leave_Element
(Self : not null access constant UML_Primitive_Type_Proxy;
Visitor : in out AMF.Visitors.Abstract_Visitor'Class;
Control : in out AMF.Visitors.Traverse_Control) is
begin
if Visitor in AMF.Visitors.UML_Visitors.UML_Visitor'Class then
AMF.Visitors.UML_Visitors.UML_Visitor'Class
(Visitor).Leave_Primitive_Type
(AMF.UML.Primitive_Types.UML_Primitive_Type_Access (Self),
Control);
end if;
end Leave_Element;
-------------------
-- Visit_Element --
-------------------
overriding procedure Visit_Element
(Self : not null access constant UML_Primitive_Type_Proxy;
Iterator : in out AMF.Visitors.Abstract_Iterator'Class;
Visitor : in out AMF.Visitors.Abstract_Visitor'Class;
Control : in out AMF.Visitors.Traverse_Control) is
begin
if Iterator in AMF.Visitors.UML_Iterators.UML_Iterator'Class then
AMF.Visitors.UML_Iterators.UML_Iterator'Class
(Iterator).Visit_Primitive_Type
(Visitor,
AMF.UML.Primitive_Types.UML_Primitive_Type_Access (Self),
Control);
end if;
end Visit_Element;
-------------------------
-- Get_Owned_Attribute --
-------------------------
overriding function Get_Owned_Attribute
(Self : not null access constant UML_Primitive_Type_Proxy)
return AMF.UML.Properties.Collections.Ordered_Set_Of_UML_Property is
begin
return
AMF.UML.Properties.Collections.Wrap
(AMF.Internals.Element_Collections.Wrap
(AMF.Internals.Tables.UML_Attributes.Internal_Get_Owned_Attribute
(Self.Element)));
end Get_Owned_Attribute;
-------------------------
-- Get_Owned_Operation --
-------------------------
overriding function Get_Owned_Operation
(Self : not null access constant UML_Primitive_Type_Proxy)
return AMF.UML.Operations.Collections.Ordered_Set_Of_UML_Operation is
begin
return
AMF.UML.Operations.Collections.Wrap
(AMF.Internals.Element_Collections.Wrap
(AMF.Internals.Tables.UML_Attributes.Internal_Get_Owned_Operation
(Self.Element)));
end Get_Owned_Operation;
-------------------
-- Get_Attribute --
-------------------
overriding function Get_Attribute
(Self : not null access constant UML_Primitive_Type_Proxy)
return AMF.UML.Properties.Collections.Set_Of_UML_Property is
begin
return
AMF.UML.Properties.Collections.Wrap
(AMF.Internals.Element_Collections.Wrap
(AMF.Internals.Tables.UML_Attributes.Internal_Get_Attribute
(Self.Element)));
end Get_Attribute;
---------------------------
-- Get_Collaboration_Use --
---------------------------
overriding function Get_Collaboration_Use
(Self : not null access constant UML_Primitive_Type_Proxy)
return AMF.UML.Collaboration_Uses.Collections.Set_Of_UML_Collaboration_Use is
begin
return
AMF.UML.Collaboration_Uses.Collections.Wrap
(AMF.Internals.Element_Collections.Wrap
(AMF.Internals.Tables.UML_Attributes.Internal_Get_Collaboration_Use
(Self.Element)));
end Get_Collaboration_Use;
-----------------
-- Get_Feature --
-----------------
overriding function Get_Feature
(Self : not null access constant UML_Primitive_Type_Proxy)
return AMF.UML.Features.Collections.Set_Of_UML_Feature is
begin
return
AMF.UML.Features.Collections.Wrap
(AMF.Internals.Element_Collections.Wrap
(AMF.Internals.Tables.UML_Attributes.Internal_Get_Feature
(Self.Element)));
end Get_Feature;
-----------------
-- Get_General --
-----------------
overriding function Get_General
(Self : not null access constant UML_Primitive_Type_Proxy)
return AMF.UML.Classifiers.Collections.Set_Of_UML_Classifier is
begin
return
AMF.UML.Classifiers.Collections.Wrap
(AMF.Internals.Element_Collections.Wrap
(AMF.Internals.Tables.UML_Attributes.Internal_Get_General
(Self.Element)));
end Get_General;
------------------------
-- Get_Generalization --
------------------------
overriding function Get_Generalization
(Self : not null access constant UML_Primitive_Type_Proxy)
return AMF.UML.Generalizations.Collections.Set_Of_UML_Generalization is
begin
return
AMF.UML.Generalizations.Collections.Wrap
(AMF.Internals.Element_Collections.Wrap
(AMF.Internals.Tables.UML_Attributes.Internal_Get_Generalization
(Self.Element)));
end Get_Generalization;
--------------------------
-- Get_Inherited_Member --
--------------------------
overriding function Get_Inherited_Member
(Self : not null access constant UML_Primitive_Type_Proxy)
return AMF.UML.Named_Elements.Collections.Set_Of_UML_Named_Element is
begin
return
AMF.UML.Named_Elements.Collections.Wrap
(AMF.Internals.Element_Collections.Wrap
(AMF.Internals.Tables.UML_Attributes.Internal_Get_Inherited_Member
(Self.Element)));
end Get_Inherited_Member;
---------------------
-- Get_Is_Abstract --
---------------------
overriding function Get_Is_Abstract
(Self : not null access constant UML_Primitive_Type_Proxy)
return Boolean is
begin
return
AMF.Internals.Tables.UML_Attributes.Internal_Get_Is_Abstract
(Self.Element);
end Get_Is_Abstract;
---------------------------------
-- Get_Is_Final_Specialization --
---------------------------------
overriding function Get_Is_Final_Specialization
(Self : not null access constant UML_Primitive_Type_Proxy)
return Boolean is
begin
return
AMF.Internals.Tables.UML_Attributes.Internal_Get_Is_Final_Specialization
(Self.Element);
end Get_Is_Final_Specialization;
---------------------------------
-- Set_Is_Final_Specialization --
---------------------------------
overriding procedure Set_Is_Final_Specialization
(Self : not null access UML_Primitive_Type_Proxy;
To : Boolean) is
begin
AMF.Internals.Tables.UML_Attributes.Internal_Set_Is_Final_Specialization
(Self.Element, To);
end Set_Is_Final_Specialization;
----------------------------------
-- Get_Owned_Template_Signature --
----------------------------------
overriding function Get_Owned_Template_Signature
(Self : not null access constant UML_Primitive_Type_Proxy)
return AMF.UML.Redefinable_Template_Signatures.UML_Redefinable_Template_Signature_Access is
begin
return
AMF.UML.Redefinable_Template_Signatures.UML_Redefinable_Template_Signature_Access
(AMF.Internals.Helpers.To_Element
(AMF.Internals.Tables.UML_Attributes.Internal_Get_Owned_Template_Signature
(Self.Element)));
end Get_Owned_Template_Signature;
----------------------------------
-- Set_Owned_Template_Signature --
----------------------------------
overriding procedure Set_Owned_Template_Signature
(Self : not null access UML_Primitive_Type_Proxy;
To : AMF.UML.Redefinable_Template_Signatures.UML_Redefinable_Template_Signature_Access) is
begin
AMF.Internals.Tables.UML_Attributes.Internal_Set_Owned_Template_Signature
(Self.Element,
AMF.Internals.Helpers.To_Element
(AMF.Elements.Element_Access (To)));
end Set_Owned_Template_Signature;
------------------------
-- Get_Owned_Use_Case --
------------------------
overriding function Get_Owned_Use_Case
(Self : not null access constant UML_Primitive_Type_Proxy)
return AMF.UML.Use_Cases.Collections.Set_Of_UML_Use_Case is
begin
return
AMF.UML.Use_Cases.Collections.Wrap
(AMF.Internals.Element_Collections.Wrap
(AMF.Internals.Tables.UML_Attributes.Internal_Get_Owned_Use_Case
(Self.Element)));
end Get_Owned_Use_Case;
--------------------------
-- Get_Powertype_Extent --
--------------------------
overriding function Get_Powertype_Extent
(Self : not null access constant UML_Primitive_Type_Proxy)
return AMF.UML.Generalization_Sets.Collections.Set_Of_UML_Generalization_Set is
begin
return
AMF.UML.Generalization_Sets.Collections.Wrap
(AMF.Internals.Element_Collections.Wrap
(AMF.Internals.Tables.UML_Attributes.Internal_Get_Powertype_Extent
(Self.Element)));
end Get_Powertype_Extent;
------------------------------
-- Get_Redefined_Classifier --
------------------------------
overriding function Get_Redefined_Classifier
(Self : not null access constant UML_Primitive_Type_Proxy)
return AMF.UML.Classifiers.Collections.Set_Of_UML_Classifier is
begin
return
AMF.UML.Classifiers.Collections.Wrap
(AMF.Internals.Element_Collections.Wrap
(AMF.Internals.Tables.UML_Attributes.Internal_Get_Redefined_Classifier
(Self.Element)));
end Get_Redefined_Classifier;
------------------------
-- Get_Representation --
------------------------
overriding function Get_Representation
(Self : not null access constant UML_Primitive_Type_Proxy)
return AMF.UML.Collaboration_Uses.UML_Collaboration_Use_Access is
begin
return
AMF.UML.Collaboration_Uses.UML_Collaboration_Use_Access
(AMF.Internals.Helpers.To_Element
(AMF.Internals.Tables.UML_Attributes.Internal_Get_Representation
(Self.Element)));
end Get_Representation;
------------------------
-- Set_Representation --
------------------------
overriding procedure Set_Representation
(Self : not null access UML_Primitive_Type_Proxy;
To : AMF.UML.Collaboration_Uses.UML_Collaboration_Use_Access) is
begin
AMF.Internals.Tables.UML_Attributes.Internal_Set_Representation
(Self.Element,
AMF.Internals.Helpers.To_Element
(AMF.Elements.Element_Access (To)));
end Set_Representation;
----------------------
-- Get_Substitution --
----------------------
overriding function Get_Substitution
(Self : not null access constant UML_Primitive_Type_Proxy)
return AMF.UML.Substitutions.Collections.Set_Of_UML_Substitution is
begin
return
AMF.UML.Substitutions.Collections.Wrap
(AMF.Internals.Element_Collections.Wrap
(AMF.Internals.Tables.UML_Attributes.Internal_Get_Substitution
(Self.Element)));
end Get_Substitution;
----------------------------
-- Get_Template_Parameter --
----------------------------
overriding function Get_Template_Parameter
(Self : not null access constant UML_Primitive_Type_Proxy)
return AMF.UML.Classifier_Template_Parameters.UML_Classifier_Template_Parameter_Access is
begin
return
AMF.UML.Classifier_Template_Parameters.UML_Classifier_Template_Parameter_Access
(AMF.Internals.Helpers.To_Element
(AMF.Internals.Tables.UML_Attributes.Internal_Get_Template_Parameter
(Self.Element)));
end Get_Template_Parameter;
----------------------------
-- Set_Template_Parameter --
----------------------------
overriding procedure Set_Template_Parameter
(Self : not null access UML_Primitive_Type_Proxy;
To : AMF.UML.Classifier_Template_Parameters.UML_Classifier_Template_Parameter_Access) is
begin
AMF.Internals.Tables.UML_Attributes.Internal_Set_Template_Parameter
(Self.Element,
AMF.Internals.Helpers.To_Element
(AMF.Elements.Element_Access (To)));
end Set_Template_Parameter;
------------------
-- Get_Use_Case --
------------------
overriding function Get_Use_Case
(Self : not null access constant UML_Primitive_Type_Proxy)
return AMF.UML.Use_Cases.Collections.Set_Of_UML_Use_Case is
begin
return
AMF.UML.Use_Cases.Collections.Wrap
(AMF.Internals.Element_Collections.Wrap
(AMF.Internals.Tables.UML_Attributes.Internal_Get_Use_Case
(Self.Element)));
end Get_Use_Case;
------------------------
-- Get_Element_Import --
------------------------
overriding function Get_Element_Import
(Self : not null access constant UML_Primitive_Type_Proxy)
return AMF.UML.Element_Imports.Collections.Set_Of_UML_Element_Import is
begin
return
AMF.UML.Element_Imports.Collections.Wrap
(AMF.Internals.Element_Collections.Wrap
(AMF.Internals.Tables.UML_Attributes.Internal_Get_Element_Import
(Self.Element)));
end Get_Element_Import;
-------------------------
-- Get_Imported_Member --
-------------------------
overriding function Get_Imported_Member
(Self : not null access constant UML_Primitive_Type_Proxy)
return AMF.UML.Packageable_Elements.Collections.Set_Of_UML_Packageable_Element is
begin
return
AMF.UML.Packageable_Elements.Collections.Wrap
(AMF.Internals.Element_Collections.Wrap
(AMF.Internals.Tables.UML_Attributes.Internal_Get_Imported_Member
(Self.Element)));
end Get_Imported_Member;
----------------
-- Get_Member --
----------------
overriding function Get_Member
(Self : not null access constant UML_Primitive_Type_Proxy)
return AMF.UML.Named_Elements.Collections.Set_Of_UML_Named_Element is
begin
return
AMF.UML.Named_Elements.Collections.Wrap
(AMF.Internals.Element_Collections.Wrap
(AMF.Internals.Tables.UML_Attributes.Internal_Get_Member
(Self.Element)));
end Get_Member;
----------------------
-- Get_Owned_Member --
----------------------
overriding function Get_Owned_Member
(Self : not null access constant UML_Primitive_Type_Proxy)
return AMF.UML.Named_Elements.Collections.Set_Of_UML_Named_Element is
begin
return
AMF.UML.Named_Elements.Collections.Wrap
(AMF.Internals.Element_Collections.Wrap
(AMF.Internals.Tables.UML_Attributes.Internal_Get_Owned_Member
(Self.Element)));
end Get_Owned_Member;
--------------------
-- Get_Owned_Rule --
--------------------
overriding function Get_Owned_Rule
(Self : not null access constant UML_Primitive_Type_Proxy)
return AMF.UML.Constraints.Collections.Set_Of_UML_Constraint is
begin
return
AMF.UML.Constraints.Collections.Wrap
(AMF.Internals.Element_Collections.Wrap
(AMF.Internals.Tables.UML_Attributes.Internal_Get_Owned_Rule
(Self.Element)));
end Get_Owned_Rule;
------------------------
-- Get_Package_Import --
------------------------
overriding function Get_Package_Import
(Self : not null access constant UML_Primitive_Type_Proxy)
return AMF.UML.Package_Imports.Collections.Set_Of_UML_Package_Import is
begin
return
AMF.UML.Package_Imports.Collections.Wrap
(AMF.Internals.Element_Collections.Wrap
(AMF.Internals.Tables.UML_Attributes.Internal_Get_Package_Import
(Self.Element)));
end Get_Package_Import;
---------------------------
-- Get_Client_Dependency --
---------------------------
overriding function Get_Client_Dependency
(Self : not null access constant UML_Primitive_Type_Proxy)
return AMF.UML.Dependencies.Collections.Set_Of_UML_Dependency is
begin
return
AMF.UML.Dependencies.Collections.Wrap
(AMF.Internals.Element_Collections.Wrap
(AMF.Internals.Tables.UML_Attributes.Internal_Get_Client_Dependency
(Self.Element)));
end Get_Client_Dependency;
-------------------------
-- Get_Name_Expression --
-------------------------
overriding function Get_Name_Expression
(Self : not null access constant UML_Primitive_Type_Proxy)
return AMF.UML.String_Expressions.UML_String_Expression_Access is
begin
return
AMF.UML.String_Expressions.UML_String_Expression_Access
(AMF.Internals.Helpers.To_Element
(AMF.Internals.Tables.UML_Attributes.Internal_Get_Name_Expression
(Self.Element)));
end Get_Name_Expression;
-------------------------
-- Set_Name_Expression --
-------------------------
overriding procedure Set_Name_Expression
(Self : not null access UML_Primitive_Type_Proxy;
To : AMF.UML.String_Expressions.UML_String_Expression_Access) is
begin
AMF.Internals.Tables.UML_Attributes.Internal_Set_Name_Expression
(Self.Element,
AMF.Internals.Helpers.To_Element
(AMF.Elements.Element_Access (To)));
end Set_Name_Expression;
-------------------
-- Get_Namespace --
-------------------
overriding function Get_Namespace
(Self : not null access constant UML_Primitive_Type_Proxy)
return AMF.UML.Namespaces.UML_Namespace_Access is
begin
return
AMF.UML.Namespaces.UML_Namespace_Access
(AMF.Internals.Helpers.To_Element
(AMF.Internals.Tables.UML_Attributes.Internal_Get_Namespace
(Self.Element)));
end Get_Namespace;
------------------------
-- Get_Qualified_Name --
------------------------
overriding function Get_Qualified_Name
(Self : not null access constant UML_Primitive_Type_Proxy)
return AMF.Optional_String is
begin
declare
use type Matreshka.Internals.Strings.Shared_String_Access;
Aux : constant Matreshka.Internals.Strings.Shared_String_Access
:= AMF.Internals.Tables.UML_Attributes.Internal_Get_Qualified_Name (Self.Element);
begin
if Aux = null then
return (Is_Empty => True);
else
return (False, League.Strings.Internals.Create (Aux));
end if;
end;
end Get_Qualified_Name;
-----------------
-- Get_Package --
-----------------
overriding function Get_Package
(Self : not null access constant UML_Primitive_Type_Proxy)
return AMF.UML.Packages.UML_Package_Access is
begin
return
AMF.UML.Packages.UML_Package_Access
(AMF.Internals.Helpers.To_Element
(AMF.Internals.Tables.UML_Attributes.Internal_Get_Package
(Self.Element)));
end Get_Package;
-----------------
-- Set_Package --
-----------------
overriding procedure Set_Package
(Self : not null access UML_Primitive_Type_Proxy;
To : AMF.UML.Packages.UML_Package_Access) is
begin
AMF.Internals.Tables.UML_Attributes.Internal_Set_Package
(Self.Element,
AMF.Internals.Helpers.To_Element
(AMF.Elements.Element_Access (To)));
end Set_Package;
-----------------------------------
-- Get_Owning_Template_Parameter --
-----------------------------------
overriding function Get_Owning_Template_Parameter
(Self : not null access constant UML_Primitive_Type_Proxy)
return AMF.UML.Template_Parameters.UML_Template_Parameter_Access is
begin
return
AMF.UML.Template_Parameters.UML_Template_Parameter_Access
(AMF.Internals.Helpers.To_Element
(AMF.Internals.Tables.UML_Attributes.Internal_Get_Owning_Template_Parameter
(Self.Element)));
end Get_Owning_Template_Parameter;
-----------------------------------
-- Set_Owning_Template_Parameter --
-----------------------------------
overriding procedure Set_Owning_Template_Parameter
(Self : not null access UML_Primitive_Type_Proxy;
To : AMF.UML.Template_Parameters.UML_Template_Parameter_Access) is
begin
AMF.Internals.Tables.UML_Attributes.Internal_Set_Owning_Template_Parameter
(Self.Element,
AMF.Internals.Helpers.To_Element
(AMF.Elements.Element_Access (To)));
end Set_Owning_Template_Parameter;
----------------------------
-- Get_Template_Parameter --
----------------------------
overriding function Get_Template_Parameter
(Self : not null access constant UML_Primitive_Type_Proxy)
return AMF.UML.Template_Parameters.UML_Template_Parameter_Access is
begin
return
AMF.UML.Template_Parameters.UML_Template_Parameter_Access
(AMF.Internals.Helpers.To_Element
(AMF.Internals.Tables.UML_Attributes.Internal_Get_Template_Parameter
(Self.Element)));
end Get_Template_Parameter;
----------------------------
-- Set_Template_Parameter --
----------------------------
overriding procedure Set_Template_Parameter
(Self : not null access UML_Primitive_Type_Proxy;
To : AMF.UML.Template_Parameters.UML_Template_Parameter_Access) is
begin
AMF.Internals.Tables.UML_Attributes.Internal_Set_Template_Parameter
(Self.Element,
AMF.Internals.Helpers.To_Element
(AMF.Elements.Element_Access (To)));
end Set_Template_Parameter;
----------------------------------
-- Get_Owned_Template_Signature --
----------------------------------
overriding function Get_Owned_Template_Signature
(Self : not null access constant UML_Primitive_Type_Proxy)
return AMF.UML.Template_Signatures.UML_Template_Signature_Access is
begin
return
AMF.UML.Template_Signatures.UML_Template_Signature_Access
(AMF.Internals.Helpers.To_Element
(AMF.Internals.Tables.UML_Attributes.Internal_Get_Owned_Template_Signature
(Self.Element)));
end Get_Owned_Template_Signature;
----------------------------------
-- Set_Owned_Template_Signature --
----------------------------------
overriding procedure Set_Owned_Template_Signature
(Self : not null access UML_Primitive_Type_Proxy;
To : AMF.UML.Template_Signatures.UML_Template_Signature_Access) is
begin
AMF.Internals.Tables.UML_Attributes.Internal_Set_Owned_Template_Signature
(Self.Element,
AMF.Internals.Helpers.To_Element
(AMF.Elements.Element_Access (To)));
end Set_Owned_Template_Signature;
--------------------------
-- Get_Template_Binding --
--------------------------
overriding function Get_Template_Binding
(Self : not null access constant UML_Primitive_Type_Proxy)
return AMF.UML.Template_Bindings.Collections.Set_Of_UML_Template_Binding is
begin
return
AMF.UML.Template_Bindings.Collections.Wrap
(AMF.Internals.Element_Collections.Wrap
(AMF.Internals.Tables.UML_Attributes.Internal_Get_Template_Binding
(Self.Element)));
end Get_Template_Binding;
-----------------
-- Get_Is_Leaf --
-----------------
overriding function Get_Is_Leaf
(Self : not null access constant UML_Primitive_Type_Proxy)
return Boolean is
begin
return
AMF.Internals.Tables.UML_Attributes.Internal_Get_Is_Leaf
(Self.Element);
end Get_Is_Leaf;
-----------------
-- Set_Is_Leaf --
-----------------
overriding procedure Set_Is_Leaf
(Self : not null access UML_Primitive_Type_Proxy;
To : Boolean) is
begin
AMF.Internals.Tables.UML_Attributes.Internal_Set_Is_Leaf
(Self.Element, To);
end Set_Is_Leaf;
---------------------------
-- Get_Redefined_Element --
---------------------------
overriding function Get_Redefined_Element
(Self : not null access constant UML_Primitive_Type_Proxy)
return AMF.UML.Redefinable_Elements.Collections.Set_Of_UML_Redefinable_Element is
begin
return
AMF.UML.Redefinable_Elements.Collections.Wrap
(AMF.Internals.Element_Collections.Wrap
(AMF.Internals.Tables.UML_Attributes.Internal_Get_Redefined_Element
(Self.Element)));
end Get_Redefined_Element;
------------------------------
-- Get_Redefinition_Context --
------------------------------
overriding function Get_Redefinition_Context
(Self : not null access constant UML_Primitive_Type_Proxy)
return AMF.UML.Classifiers.Collections.Set_Of_UML_Classifier is
begin
return
AMF.UML.Classifiers.Collections.Wrap
(AMF.Internals.Element_Collections.Wrap
(AMF.Internals.Tables.UML_Attributes.Internal_Get_Redefinition_Context
(Self.Element)));
end Get_Redefinition_Context;
-------------
-- Inherit --
-------------
overriding function Inherit
(Self : not null access constant UML_Primitive_Type_Proxy;
Inhs : AMF.UML.Named_Elements.Collections.Set_Of_UML_Named_Element)
return AMF.UML.Named_Elements.Collections.Set_Of_UML_Named_Element is
begin
-- Generated stub: replace with real body!
pragma Compile_Time_Warning (Standard.True, "Inherit unimplemented");
raise Program_Error with "Unimplemented procedure UML_Primitive_Type_Proxy.Inherit";
return Inherit (Self, Inhs);
end Inherit;
------------------
-- All_Features --
------------------
overriding function All_Features
(Self : not null access constant UML_Primitive_Type_Proxy)
return AMF.UML.Features.Collections.Set_Of_UML_Feature is
begin
-- Generated stub: replace with real body!
pragma Compile_Time_Warning (Standard.True, "All_Features unimplemented");
raise Program_Error with "Unimplemented procedure UML_Primitive_Type_Proxy.All_Features";
return All_Features (Self);
end All_Features;
-----------------
-- Conforms_To --
-----------------
overriding function Conforms_To
(Self : not null access constant UML_Primitive_Type_Proxy;
Other : AMF.UML.Classifiers.UML_Classifier_Access)
return Boolean is
begin
-- Generated stub: replace with real body!
pragma Compile_Time_Warning (Standard.True, "Conforms_To unimplemented");
raise Program_Error with "Unimplemented procedure UML_Primitive_Type_Proxy.Conforms_To";
return Conforms_To (Self, Other);
end Conforms_To;
-------------
-- General --
-------------
overriding function General
(Self : not null access constant UML_Primitive_Type_Proxy)
return AMF.UML.Classifiers.Collections.Set_Of_UML_Classifier is
begin
-- Generated stub: replace with real body!
pragma Compile_Time_Warning (Standard.True, "General unimplemented");
raise Program_Error with "Unimplemented procedure UML_Primitive_Type_Proxy.General";
return General (Self);
end General;
-----------------------
-- Has_Visibility_Of --
-----------------------
overriding function Has_Visibility_Of
(Self : not null access constant UML_Primitive_Type_Proxy;
N : AMF.UML.Named_Elements.UML_Named_Element_Access)
return Boolean is
begin
-- Generated stub: replace with real body!
pragma Compile_Time_Warning (Standard.True, "Has_Visibility_Of unimplemented");
raise Program_Error with "Unimplemented procedure UML_Primitive_Type_Proxy.Has_Visibility_Of";
return Has_Visibility_Of (Self, N);
end Has_Visibility_Of;
-------------------------
-- Inheritable_Members --
-------------------------
overriding function Inheritable_Members
(Self : not null access constant UML_Primitive_Type_Proxy;
C : AMF.UML.Classifiers.UML_Classifier_Access)
return AMF.UML.Named_Elements.Collections.Set_Of_UML_Named_Element is
begin
-- Generated stub: replace with real body!
pragma Compile_Time_Warning (Standard.True, "Inheritable_Members unimplemented");
raise Program_Error with "Unimplemented procedure UML_Primitive_Type_Proxy.Inheritable_Members";
return Inheritable_Members (Self, C);
end Inheritable_Members;
----------------------
-- Inherited_Member --
----------------------
overriding function Inherited_Member
(Self : not null access constant UML_Primitive_Type_Proxy)
return AMF.UML.Named_Elements.Collections.Set_Of_UML_Named_Element is
begin
-- Generated stub: replace with real body!
pragma Compile_Time_Warning (Standard.True, "Inherited_Member unimplemented");
raise Program_Error with "Unimplemented procedure UML_Primitive_Type_Proxy.Inherited_Member";
return Inherited_Member (Self);
end Inherited_Member;
-----------------
-- Is_Template --
-----------------
overriding function Is_Template
(Self : not null access constant UML_Primitive_Type_Proxy)
return Boolean is
begin
-- Generated stub: replace with real body!
pragma Compile_Time_Warning (Standard.True, "Is_Template unimplemented");
raise Program_Error with "Unimplemented procedure UML_Primitive_Type_Proxy.Is_Template";
return Is_Template (Self);
end Is_Template;
-------------------------
-- May_Specialize_Type --
-------------------------
overriding function May_Specialize_Type
(Self : not null access constant UML_Primitive_Type_Proxy;
C : AMF.UML.Classifiers.UML_Classifier_Access)
return Boolean is
begin
-- Generated stub: replace with real body!
pragma Compile_Time_Warning (Standard.True, "May_Specialize_Type unimplemented");
raise Program_Error with "Unimplemented procedure UML_Primitive_Type_Proxy.May_Specialize_Type";
return May_Specialize_Type (Self, C);
end May_Specialize_Type;
------------------------
-- Exclude_Collisions --
------------------------
overriding function Exclude_Collisions
(Self : not null access constant UML_Primitive_Type_Proxy;
Imps : AMF.UML.Packageable_Elements.Collections.Set_Of_UML_Packageable_Element)
return AMF.UML.Packageable_Elements.Collections.Set_Of_UML_Packageable_Element is
begin
-- Generated stub: replace with real body!
pragma Compile_Time_Warning (Standard.True, "Exclude_Collisions unimplemented");
raise Program_Error with "Unimplemented procedure UML_Primitive_Type_Proxy.Exclude_Collisions";
return Exclude_Collisions (Self, Imps);
end Exclude_Collisions;
-------------------------
-- Get_Names_Of_Member --
-------------------------
overriding function Get_Names_Of_Member
(Self : not null access constant UML_Primitive_Type_Proxy;
Element : AMF.UML.Named_Elements.UML_Named_Element_Access)
return AMF.String_Collections.Set_Of_String is
begin
-- Generated stub: replace with real body!
pragma Compile_Time_Warning (Standard.True, "Get_Names_Of_Member unimplemented");
raise Program_Error with "Unimplemented procedure UML_Primitive_Type_Proxy.Get_Names_Of_Member";
return Get_Names_Of_Member (Self, Element);
end Get_Names_Of_Member;
--------------------
-- Import_Members --
--------------------
overriding function Import_Members
(Self : not null access constant UML_Primitive_Type_Proxy;
Imps : AMF.UML.Packageable_Elements.Collections.Set_Of_UML_Packageable_Element)
return AMF.UML.Packageable_Elements.Collections.Set_Of_UML_Packageable_Element is
begin
-- Generated stub: replace with real body!
pragma Compile_Time_Warning (Standard.True, "Import_Members unimplemented");
raise Program_Error with "Unimplemented procedure UML_Primitive_Type_Proxy.Import_Members";
return Import_Members (Self, Imps);
end Import_Members;
---------------------
-- Imported_Member --
---------------------
overriding function Imported_Member
(Self : not null access constant UML_Primitive_Type_Proxy)
return AMF.UML.Packageable_Elements.Collections.Set_Of_UML_Packageable_Element is
begin
-- Generated stub: replace with real body!
pragma Compile_Time_Warning (Standard.True, "Imported_Member unimplemented");
raise Program_Error with "Unimplemented procedure UML_Primitive_Type_Proxy.Imported_Member";
return Imported_Member (Self);
end Imported_Member;
---------------------------------
-- Members_Are_Distinguishable --
---------------------------------
overriding function Members_Are_Distinguishable
(Self : not null access constant UML_Primitive_Type_Proxy)
return Boolean is
begin
-- Generated stub: replace with real body!
pragma Compile_Time_Warning (Standard.True, "Members_Are_Distinguishable unimplemented");
raise Program_Error with "Unimplemented procedure UML_Primitive_Type_Proxy.Members_Are_Distinguishable";
return Members_Are_Distinguishable (Self);
end Members_Are_Distinguishable;
------------------
-- Owned_Member --
------------------
overriding function Owned_Member
(Self : not null access constant UML_Primitive_Type_Proxy)
return AMF.UML.Named_Elements.Collections.Set_Of_UML_Named_Element is
begin
-- Generated stub: replace with real body!
pragma Compile_Time_Warning (Standard.True, "Owned_Member unimplemented");
raise Program_Error with "Unimplemented procedure UML_Primitive_Type_Proxy.Owned_Member";
return Owned_Member (Self);
end Owned_Member;
-------------------------
-- All_Owning_Packages --
-------------------------
overriding function All_Owning_Packages
(Self : not null access constant UML_Primitive_Type_Proxy)
return AMF.UML.Packages.Collections.Set_Of_UML_Package is
begin
-- Generated stub: replace with real body!
pragma Compile_Time_Warning (Standard.True, "All_Owning_Packages unimplemented");
raise Program_Error with "Unimplemented procedure UML_Primitive_Type_Proxy.All_Owning_Packages";
return All_Owning_Packages (Self);
end All_Owning_Packages;
-----------------------------
-- Is_Distinguishable_From --
-----------------------------
overriding function Is_Distinguishable_From
(Self : not null access constant UML_Primitive_Type_Proxy;
N : AMF.UML.Named_Elements.UML_Named_Element_Access;
Ns : AMF.UML.Namespaces.UML_Namespace_Access)
return Boolean is
begin
-- Generated stub: replace with real body!
pragma Compile_Time_Warning (Standard.True, "Is_Distinguishable_From unimplemented");
raise Program_Error with "Unimplemented procedure UML_Primitive_Type_Proxy.Is_Distinguishable_From";
return Is_Distinguishable_From (Self, N, Ns);
end Is_Distinguishable_From;
---------------
-- Namespace --
---------------
overriding function Namespace
(Self : not null access constant UML_Primitive_Type_Proxy)
return AMF.UML.Namespaces.UML_Namespace_Access is
begin
-- Generated stub: replace with real body!
pragma Compile_Time_Warning (Standard.True, "Namespace unimplemented");
raise Program_Error with "Unimplemented procedure UML_Primitive_Type_Proxy.Namespace";
return Namespace (Self);
end Namespace;
-----------------
-- Conforms_To --
-----------------
overriding function Conforms_To
(Self : not null access constant UML_Primitive_Type_Proxy;
Other : AMF.UML.Types.UML_Type_Access)
return Boolean is
begin
-- Generated stub: replace with real body!
pragma Compile_Time_Warning (Standard.True, "Conforms_To unimplemented");
raise Program_Error with "Unimplemented procedure UML_Primitive_Type_Proxy.Conforms_To";
return Conforms_To (Self, Other);
end Conforms_To;
------------------------
-- Is_Compatible_With --
------------------------
overriding function Is_Compatible_With
(Self : not null access constant UML_Primitive_Type_Proxy;
P : AMF.UML.Parameterable_Elements.UML_Parameterable_Element_Access)
return Boolean is
begin
-- Generated stub: replace with real body!
pragma Compile_Time_Warning (Standard.True, "Is_Compatible_With unimplemented");
raise Program_Error with "Unimplemented procedure UML_Primitive_Type_Proxy.Is_Compatible_With";
return Is_Compatible_With (Self, P);
end Is_Compatible_With;
---------------------------
-- Is_Template_Parameter --
---------------------------
overriding function Is_Template_Parameter
(Self : not null access constant UML_Primitive_Type_Proxy)
return Boolean is
begin
-- Generated stub: replace with real body!
pragma Compile_Time_Warning (Standard.True, "Is_Template_Parameter unimplemented");
raise Program_Error with "Unimplemented procedure UML_Primitive_Type_Proxy.Is_Template_Parameter";
return Is_Template_Parameter (Self);
end Is_Template_Parameter;
----------------------------
-- Parameterable_Elements --
----------------------------
overriding function Parameterable_Elements
(Self : not null access constant UML_Primitive_Type_Proxy)
return AMF.UML.Parameterable_Elements.Collections.Set_Of_UML_Parameterable_Element is
begin
-- Generated stub: replace with real body!
pragma Compile_Time_Warning (Standard.True, "Parameterable_Elements unimplemented");
raise Program_Error with "Unimplemented procedure UML_Primitive_Type_Proxy.Parameterable_Elements";
return Parameterable_Elements (Self);
end Parameterable_Elements;
------------------------
-- Is_Consistent_With --
------------------------
overriding function Is_Consistent_With
(Self : not null access constant UML_Primitive_Type_Proxy;
Redefinee : AMF.UML.Redefinable_Elements.UML_Redefinable_Element_Access)
return Boolean is
begin
-- Generated stub: replace with real body!
pragma Compile_Time_Warning (Standard.True, "Is_Consistent_With unimplemented");
raise Program_Error with "Unimplemented procedure UML_Primitive_Type_Proxy.Is_Consistent_With";
return Is_Consistent_With (Self, Redefinee);
end Is_Consistent_With;
-----------------------------------
-- Is_Redefinition_Context_Valid --
-----------------------------------
overriding function Is_Redefinition_Context_Valid
(Self : not null access constant UML_Primitive_Type_Proxy;
Redefined : AMF.UML.Redefinable_Elements.UML_Redefinable_Element_Access)
return Boolean is
begin
-- Generated stub: replace with real body!
pragma Compile_Time_Warning (Standard.True, "Is_Redefinition_Context_Valid unimplemented");
raise Program_Error with "Unimplemented procedure UML_Primitive_Type_Proxy.Is_Redefinition_Context_Valid";
return Is_Redefinition_Context_Valid (Self, Redefined);
end Is_Redefinition_Context_Valid;
end AMF.Internals.UML_Primitive_Types;
|
package body Ada.Colors is
function modff (value : Float; iptr : access Float) return Float
with Import, Convention => Intrinsic, External_Name => "__builtin_modff";
function sinf (X : Float) return Float
with Import, Convention => Intrinsic, External_Name => "__builtin_sinf";
function cosf (X : Float) return Float
with Import, Convention => Intrinsic, External_Name => "__builtin_cosf";
function To_Hue (Color : RGB; Diff, Max : Brightness'Base)
return Hue'Base;
function To_Hue (Color : RGB; Diff, Max : Brightness'Base)
return Hue'Base
is
Result : Hue'Base;
begin
pragma Assert (Diff > 0.0);
if Color.Blue = Max then
Result := 4.0 * Diff + (Color.Red - Color.Green);
elsif Color.Green = Max then
Result := 2.0 * Diff + (Color.Blue - Color.Red);
else -- Red
Result := (Color.Green - Color.Blue);
if Result < 0.0 then
Result := Result + 6.0 * Diff;
end if;
end if;
Result := 2.0 * Numerics.Pi / 6.0 * Result / Diff;
return Result;
end To_Hue;
-- implementation
function To_RGB (Color : HSV) return RGB is
H : Hue'Base;
Q : aliased Hue'Base;
Diff : Brightness'Base;
N1, N2, N3 : Brightness'Base;
Red, Green, Blue : Brightness'Base;
begin
H := 6.0 / (2.0 * Numerics.Pi) * Color.Hue;
Diff := modff (H, Q'Access);
N1 := Color.Value * (1.0 - Color.Saturation);
N2 := Color.Value * (1.0 - Color.Saturation * Diff);
N3 := Color.Value * (1.0 - Color.Saturation * (1.0 - Diff));
if Q < 1.0 then
Red := Color.Value;
Green := N3;
Blue := N1;
elsif Q < 2.0 then
Red := N2;
Green := Color.Value;
Blue := N1;
elsif Q < 3.0 then
Red := N1;
Green := Color.Value;
Blue := N3;
elsif Q < 4.0 then
Red := N1;
Green := N2;
Blue := Color.Value;
elsif Q < 5.0 then
Red := N3;
Green := N1;
Blue := Color.Value;
else
Red := Color.Value;
Green := N1;
Blue := N2;
end if;
pragma Assert (
Color.Saturation > 0.0 or else (Red = Green and then Green = Blue));
return (Red => Red, Green => Green, Blue => Blue);
end To_RGB;
function To_RGB (Color : HSL) return RGB is
H : Hue'Base;
Q : aliased Hue'Base;
Diff : Brightness'Base;
X, C, Max, Min : Brightness'Base;
Red, Green, Blue : Brightness'Base;
begin
H := 3.0 / (2.0 * Numerics.Pi) * Color.Hue;
Diff := modff (H, Q'Access);
C := (1.0 - abs (2.0 * Color.Lightness - 1.0)) * Color.Saturation;
Min := Color.Lightness - C / 2.0;
Max := C + Min;
X := C * (1.0 - abs (2.0 * Diff - 1.0)) + Min;
if H < 0.5 then
Red := Max;
Green := X;
Blue := Min;
elsif H < 1.0 then
Red := X;
Green := Max;
Blue := Min;
elsif H < 1.5 then
Red := Min;
Green := Max;
Blue := X;
elsif H < 2.0 then
Red := Min;
Green := X;
Blue := Max;
elsif H < 2.5 then
Red := X;
Green := Min;
Blue := Max;
else
Red := Max;
Green := Min;
Blue := X;
end if;
return (Red => Red, Green => Green, Blue => Blue);
end To_RGB;
function To_HSV (Color : RGB) return HSV is
Max : constant Brightness'Base :=
Brightness'Base'Max (
Color.Red,
Brightness'Base'Max (
Color.Green,
Color.Blue));
Min : constant Brightness'Base :=
Brightness'Base'Min (
Color.Red,
Brightness'Base'Min (
Color.Green,
Color.Blue));
Diff : constant Brightness'Base := Max - Min;
Hue : Colors.Hue'Base;
Saturation : Brightness'Base;
Value : Brightness'Base;
begin
Value := Max;
if Diff > 0.0 then
Saturation := Diff / Max;
Hue := To_Hue (Color, Diff => Diff, Max => Max);
else
Saturation := 0.0;
Hue := 0.0;
end if;
return (Hue => Hue, Saturation => Saturation, Value => Value);
end To_HSV;
function To_HSV (Color : HSL) return HSV is
Hue : constant Colors.Hue'Base := Color.Hue;
Saturation : Brightness'Base;
Value : constant Brightness'Base :=
Color.Lightness
+ Color.Saturation * (1.0 - abs (2.0 * Color.Lightness - 1.0)) / 2.0;
begin
if Value > 0.0 then
Saturation := 2.0 * (Value - Color.Lightness) / Value;
else
Saturation := 0.0;
end if;
return (Hue => Hue, Saturation => Saturation, Value => Value);
end To_HSV;
function To_HSL (Color : RGB) return HSL is
Max : constant Brightness'Base :=
Brightness'Base'Max (
Color.Red,
Brightness'Base'Max (
Color.Green,
Color.Blue));
Min : constant Brightness'Base :=
Brightness'Base'Min (
Color.Red,
Brightness'Base'Min (
Color.Green,
Color.Blue));
Diff : constant Brightness'Base := Max - Min;
Hue : Colors.Hue'Base;
Saturation : Brightness'Base;
Lightness : Brightness'Base;
begin
Lightness := (Max + Min) / 2.0;
if Diff > 0.0 then
Saturation := Diff / (1.0 - abs (2.0 * Lightness - 1.0));
Hue := To_Hue (Color, Diff => Diff, Max => Max);
else
Saturation := 0.0;
Hue := 0.0;
end if;
return (Hue => Hue, Saturation => Saturation, Lightness => Lightness);
end To_HSL;
function To_HSL (Color : HSV) return HSL is
Hue : constant Colors.Hue'Base := Color.Hue;
Saturation : Brightness'Base;
Lightness : constant Brightness'Base :=
Color.Value * (2.0 - Color.Saturation) / 2.0;
begin
if Lightness > 0.0 and then Lightness < 1.0 then
Saturation := Color.Value * Color.Saturation
/ (1.0 - abs (2.0 * Lightness - 1.0));
else
Saturation := 0.0;
end if;
return (Hue => Hue, Saturation => Saturation, Lightness => Lightness);
end To_HSL;
function Luminance (Color : RGB) return Brightness is
begin
return Brightness'Base'Min (
0.30 * Color.Red + 0.59 * Color.Green + 0.11 * Color.Blue,
Brightness'Last);
end Luminance;
function Luminance (Color : HSV) return Brightness is
begin
return Luminance (To_RGB (Color));
end Luminance;
function Luminance (Color : HSL) return Brightness is
begin
return Luminance (To_RGB (Color));
end Luminance;
function RGB_Distance (Left, Right : RGB) return Float is
begin
-- sum of squares
return (Left.Red - Right.Red) ** 2
+ (Left.Green - Right.Green) ** 2
+ (Left.Blue - Right.Blue) ** 2;
end RGB_Distance;
function HSV_Distance (Left, Right : HSV) return Float is
-- cone model
LR : constant Float := Left.Saturation * Left.Value / 2.0;
LX : constant Float := cosf (Left.Hue) * LR;
LY : constant Float := sinf (Left.Hue) * LR;
LZ : constant Float := Left.Value;
RR : constant Float := Right.Saturation * Right.Value / 2.0;
RX : constant Float := cosf (Right.Hue) * RR;
RY : constant Float := sinf (Right.Hue) * RR;
RZ : constant Float := Right.Value;
begin
return (LX - RX) ** 2 + (LY - RY) ** 2 + (LZ - RZ) ** 2;
end HSV_Distance;
function HSL_Distance (Left, Right : HSL) return Float is
-- double cone model
LR : constant Float :=
Left.Saturation * (0.5 - abs (Left.Lightness - 0.5));
LX : constant Float := cosf (Left.Hue) * LR;
LY : constant Float := sinf (Left.Hue) * LR;
LZ : constant Float := Left.Lightness;
RR : constant Float :=
Right.Saturation * (0.5 - abs (Right.Lightness - 0.5));
RX : constant Float := cosf (Right.Hue) * RR;
RY : constant Float := sinf (Right.Hue) * RR;
RZ : constant Float := Right.Lightness;
begin
return (LX - RX) ** 2 + (LY - RY) ** 2 + (LZ - RZ) ** 2;
end HSL_Distance;
end Ada.Colors;
|
with STM32GD.USB.Peripheral;
with STM32GD.Drivers.CDC;
package Peripherals is
package USB is new STM32GD.USB.Peripheral (
EP0_Reset_Callback => STM32GD.Drivers.CDC.EP0_Reset,
EP0_Handler_Callback => STM32GD.Drivers.CDC.EP0_Handler);
end Peripherals;
|
with Ada.Numerics.Generic_Real_Arrays;
with Ada.Numerics.Generic_Elementary_Functions;
generic
type Real_Type is digits <>;
package Math_2D.Types is
package Functions is new Ada.Numerics.Generic_Elementary_Functions (Real_Type);
package Arrays is new Ada.Numerics.Generic_Real_Arrays (Real_Type);
type Point_t is new Arrays.Real_Vector (1 .. 2);
type Vector_t is new Arrays.Real_Vector (1 .. 2);
type Triangle_Point_Index_t is range 1 .. 3;
type Triangle_t is array (Triangle_Point_Index_t) of Point_t;
type Line_Segment_Point_Index_t is range 1 .. 2;
type Line_Segment_t is array (Line_Segment_Point_Index_t) of Point_t;
end Math_2D.Types;
|
generic
package gene is
end gene;
with text_io;
package body gene is
-- Different error message with/without line below commented out
--package flt_io is new text_io.float_io(float);
procedure test is
begin
text_io.new_line;
end;
end gene;
with gene;
procedure bug1 is
package my_pkg is new gene;
begin
null;
end bug1;
|
pragma License (Unrestricted);
-- specialized for Darwin
private with System.Interrupt_Numbers;
private with C.signal;
package Ada.Interrupts.Names is
-- This package is system-specific.
SIGHUP : constant Interrupt_Id;
SIGINT : constant Interrupt_Id;
SIGQUIT : constant Interrupt_Id;
SIGILL : constant Interrupt_Id;
SIGTRAP : constant Interrupt_Id;
SIGABRT : constant Interrupt_Id;
-- SIGIOT : Interrupt_Id renames SIGABRT;
SIGEMT : constant Interrupt_Id;
-- SIGPOLL : Interrupt_Id renames SIGEMT;
SIGFPE : constant Interrupt_Id;
SIGKILL : constant Interrupt_Id;
SIGBUS : constant Interrupt_Id;
SIGSEGV : constant Interrupt_Id;
SIGSYS : constant Interrupt_Id;
SIGPIPE : constant Interrupt_Id;
SIGALRM : constant Interrupt_Id;
SIGTERM : constant Interrupt_Id;
SIGURG : constant Interrupt_Id;
SIGSTOP : constant Interrupt_Id;
SIGTSTP : constant Interrupt_Id;
SIGCONT : constant Interrupt_Id;
SIGCHLD : constant Interrupt_Id;
SIGTTIN : constant Interrupt_Id;
SIGTTOU : constant Interrupt_Id;
SIGIO : constant Interrupt_Id;
SIGXCPU : constant Interrupt_Id;
SIGXFSZ : constant Interrupt_Id;
SIGVTALRM : constant Interrupt_Id;
SIGPROF : constant Interrupt_Id;
SIGWINCH : constant Interrupt_Id;
SIGINFO : constant Interrupt_Id;
SIGUSR1 : constant Interrupt_Id;
SIGUSR2 : constant Interrupt_Id;
First_Interrupt_Id : constant Interrupt_Id;
Last_Interrupt_Id : constant Interrupt_Id;
private
SIGHUP : constant Interrupt_Id := C.signal.SIGHUP;
SIGINT : constant Interrupt_Id := C.signal.SIGINT;
SIGQUIT : constant Interrupt_Id := C.signal.SIGQUIT;
SIGILL : constant Interrupt_Id := C.signal.SIGILL;
SIGTRAP : constant Interrupt_Id := C.signal.SIGTRAP;
SIGABRT : constant Interrupt_Id := C.signal.SIGABRT;
SIGEMT : constant Interrupt_Id := C.signal.SIGEMT;
SIGFPE : constant Interrupt_Id := C.signal.SIGFPE;
SIGKILL : constant Interrupt_Id := C.signal.SIGKILL;
SIGBUS : constant Interrupt_Id := C.signal.SIGBUS;
SIGSEGV : constant Interrupt_Id := C.signal.SIGSEGV;
SIGSYS : constant Interrupt_Id := C.signal.SIGSYS;
SIGPIPE : constant Interrupt_Id := C.signal.SIGPIPE;
SIGALRM : constant Interrupt_Id := C.signal.SIGALRM;
SIGTERM : constant Interrupt_Id := C.signal.SIGTERM;
SIGURG : constant Interrupt_Id := C.signal.SIGURG;
SIGSTOP : constant Interrupt_Id := C.signal.SIGSTOP;
SIGTSTP : constant Interrupt_Id := C.signal.SIGTSTP;
SIGCONT : constant Interrupt_Id := C.signal.SIGCONT;
SIGCHLD : constant Interrupt_Id := C.signal.SIGCHLD;
SIGTTIN : constant Interrupt_Id := C.signal.SIGTTIN;
SIGTTOU : constant Interrupt_Id := C.signal.SIGTTOU;
SIGIO : constant Interrupt_Id := C.signal.SIGIO;
SIGXCPU : constant Interrupt_Id := C.signal.SIGXCPU;
SIGXFSZ : constant Interrupt_Id := C.signal.SIGXFSZ;
SIGVTALRM : constant Interrupt_Id := C.signal.SIGVTALRM;
SIGPROF : constant Interrupt_Id := C.signal.SIGPROF;
SIGWINCH : constant Interrupt_Id := C.signal.SIGWINCH;
SIGINFO : constant Interrupt_Id := C.signal.SIGINFO;
SIGUSR1 : constant Interrupt_Id := C.signal.SIGUSR1;
SIGUSR2 : constant Interrupt_Id := C.signal.SIGUSR2;
First_Interrupt_Id : constant Interrupt_Id :=
System.Interrupt_Numbers.First_Interrupt_Id;
Last_Interrupt_Id : constant Interrupt_Id :=
System.Interrupt_Numbers.Last_Interrupt_Id;
end Ada.Interrupts.Names;
|
-----------------------------------------------------------------------
-- awa-images-services -- Image service
-- Copyright (C) 2012, 2013 Stephane Carrez
-- Written by Stephane Carrez (Stephane.Carrez@gmail.com)
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-----------------------------------------------------------------------
with Util.Processes;
with Util.Beans.Objects;
with Util.Log.Loggers;
with Util.Streams.Pipes;
with Util.Streams.Texts;
with ADO;
with ADO.Sessions;
with AWA.Images.Models;
with AWA.Services.Contexts;
with AWA.Storages.Services;
with AWA.Storages.Modules;
with Ada.Strings.Unbounded;
with EL.Variables.Default;
with EL.Contexts.Default;
-- == Storage Service ==
-- The <tt>Storage_Service</tt> provides the operations to access and use the persisent storage.
-- It controls the permissions that grant access to the service for users.
--
-- Other modules can be notified of storage changes by registering a listener
-- on the storage module.
package body AWA.Images.Services is
package ASC renames AWA.Services.Contexts;
-- ------------------------------
-- Image Service
-- ------------------------------
Log : constant Util.Log.Loggers.Logger := Util.Log.Loggers.Create ("AWA.Images.Services");
-- ------------------------------
-- Initializes the storage service.
-- ------------------------------
overriding
procedure Initialize (Service : in out Image_Service;
Module : in AWA.Modules.Module'Class) is
begin
AWA.Modules.Module_Manager (Service).Initialize (Module);
declare
Ctx : EL.Contexts.Default.Default_Context;
Command : constant String := Module.Get_Config (PARAM_THUMBNAIL_COMMAND);
begin
Service.Thumbnail_Command := EL.Expressions.Create_Expression (Command, Ctx);
exception
when E : others =>
Log.Error ("Invalid thumbnail command: ", E, True);
end;
end Initialize;
procedure Create_Thumbnail (Service : in Image_Service;
Source : in String;
Into : in String;
Width : out Natural;
Height : out Natural) is
Ctx : EL.Contexts.Default.Default_Context;
Variables : aliased EL.Variables.Default.Default_Variable_Mapper;
Proc : Util.Processes.Process;
Pipe : aliased Util.Streams.Pipes.Pipe_Stream;
begin
Variables.Bind ("src", Util.Beans.Objects.To_Object (Source));
Variables.Bind ("dst", Util.Beans.Objects.To_Object (Into));
Ctx.Set_Variable_Mapper (Variables'Unchecked_Access);
declare
Cmd : constant Util.Beans.Objects.Object := Service.Thumbnail_Command.Get_Value (Ctx);
Command : constant String := Util.Beans.Objects.To_String (Cmd);
Input : Util.Streams.Texts.Reader_Stream;
begin
Width := 0;
Height := 0;
Pipe.Open (Command, Util.Processes.READ);
Input.Initialize (null, Pipe'Unchecked_Access, 1024);
while not Input.Is_Eof loop
declare
use Ada.Strings;
Line : Ada.Strings.Unbounded.Unbounded_String;
Pos : Natural;
Sep : Natural;
Last : Natural;
begin
Input.Read_Line (Into => Line, Strip => False);
exit when Ada.Strings.Unbounded.Length (Line) = 0;
Log.Info ("Received: {0}", Line);
-- The '-verbose' option of ImageMagick reports information about the original
-- image. Extract the picture width and height.
-- image.png PNG 120x282 120x282+0+0 8-bit DirectClass 34.4KB 0.000u 0:00.018
Pos := Ada.Strings.Unbounded.Index (Line, " ");
if Pos > 0 and Width = 0 then
Pos := Ada.Strings.Unbounded.Index (Line, " ", Pos + 1);
if Pos > 0 then
Sep := Ada.Strings.Unbounded.Index (Line, "x", Pos + 1);
Last := Ada.Strings.Unbounded.Index (Line, "=", Pos + 1);
if Sep > 0 and Sep < Last then
Log.Info ("Dimension {0} - {1}..{2}",
Ada.Strings.Unbounded.Slice (Line, Pos, Last),
Natural'Image (Pos), Natural'Image (Last));
Width := Natural'Value (Unbounded.Slice (Line, Pos + 1, Sep - 1));
Height := Natural'Value (Unbounded.Slice (Line, Sep + 1, Last - 1));
end if;
end if;
end if;
end;
end loop;
Pipe.Close;
Util.Processes.Wait (Proc);
if Pipe.Get_Exit_Status /= 0 then
Log.Error ("Command {0} exited with status {1}", Command,
Integer'Image (Pipe.Get_Exit_Status));
end if;
end;
end Create_Thumbnail;
-- Save the data object contained in the <b>Data</b> part element into the
-- target storage represented by <b>Into</b>.
procedure Build_Thumbnail (Service : in Image_Service;
Id : in ADO.Identifier;
File : in AWA.Storages.Models.Storage_Ref'Class) is
pragma Unreferenced (File);
Storage_Service : constant AWA.Storages.Services.Storage_Service_Access
:= AWA.Storages.Modules.Get_Storage_Manager;
Ctx : constant ASC.Service_Context_Access := ASC.Current;
DB : ADO.Sessions.Master_Session := ASC.Get_Master_Session (Ctx);
Img : AWA.Images.Models.Image_Ref;
Target_File : AWA.Storages.Storage_File;
Local_File : AWA.Storages.Storage_File;
Width : Natural;
Height : Natural;
begin
Img.Load (DB, Id);
Storage_Service.Get_Local_File (From => Img.Get_Storage.Get_Id, Into => Local_File);
Storage_Service.Create_Local_File (Target_File);
Service.Create_Thumbnail (AWA.Storages.Get_Path (Local_File),
AWA.Storages.Get_Path (Target_File), Width, Height);
Img.Set_Width (Width);
Img.Set_Height (Height);
Img.Set_Thumb_Width (64);
Img.Set_Thumb_Height (64);
Ctx.Start;
Img.Save (DB);
-- Storage_Service.Save (Target_File);
Ctx.Commit;
end Build_Thumbnail;
-- Save the data object contained in the <b>Data</b> part element into the
-- target storage represented by <b>Into</b>.
procedure Create_Image (Service : in Image_Service;
File : in AWA.Storages.Models.Storage_Ref'Class) is
pragma Unreferenced (Service);
Ctx : constant AWA.Services.Contexts.Service_Context_Access := AWA.Services.Contexts.Current;
DB : ADO.Sessions.Master_Session := AWA.Services.Contexts.Get_Master_Session (Ctx);
Img : AWA.Images.Models.Image_Ref;
begin
Ctx.Start;
Img.Set_Width (0);
Img.Set_Height (0);
Img.Set_Thumb_Height (0);
Img.Set_Thumb_Width (0);
Img.Set_Storage (File);
Img.Save (DB);
Ctx.Commit;
end Create_Image;
-- Deletes the storage instance.
procedure Delete_Image (Service : in Image_Service;
File : in AWA.Storages.Models.Storage_Ref'Class) is
begin
null;
end Delete_Image;
end AWA.Images.Services;
|
------------------------------------------------------------------------------
-- --
-- Copyright (C) 2015-2016, AdaCore --
-- --
-- Redistribution and use in source and binary forms, with or without --
-- modification, are permitted provided that the following conditions are --
-- met: --
-- 1. Redistributions of source code must retain the above copyright --
-- notice, this list of conditions and the following disclaimer. --
-- 2. Redistributions in binary form must reproduce the above copyright --
-- notice, this list of conditions and the following disclaimer in --
-- the documentation and/or other materials provided with the --
-- distribution. --
-- 3. Neither the name of STMicroelectronics nor the names of its --
-- contributors may be used to endorse or promote products derived --
-- from this software without specific prior written permission. --
-- --
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS --
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT --
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR --
-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT --
-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT --
-- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, --
-- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY --
-- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT --
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE --
-- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --
-- --
-- --
-- This file is based on: --
-- --
-- @file stm32f4xx_hal_usart.h --
-- @author MCD Application Team --
-- @version V1.1.0 --
-- @date 19-June-2014 --
-- @brief Header file of USARTS HAL module. --
-- --
-- COPYRIGHT(c) 2014 STMicroelectronics --
------------------------------------------------------------------------------
-- This file provides register definitions for the STM32F4 (ARM Cortex M4F)
-- USART from ST Microelectronics.
-- Note that there are board implementation assumptions represented by the
-- private function APB_Clock.
pragma Restrictions (No_Elaboration_Code);
with System;
private with STM32_SVD.USART;
package STM32.USARTs is
type USART is limited private;
procedure Enable (This : in out USART)
with
Post => Enabled (This),
Inline;
procedure Disable (This : in out USART)
with
Post => not Enabled (This),
Inline;
function Enabled (This : USART) return Boolean with Inline;
procedure Receive (This : USART; Data : out UInt9) with Inline;
-- reads Device.DR into Data
function Current_Input (This : USART) return UInt9 with Inline;
-- returns Device.DR
procedure Transmit (This : in out USART; Data : UInt9) with Inline;
function Tx_Ready (This : USART) return Boolean with Inline;
function Rx_Ready (This : USART) return Boolean with Inline;
type Stop_Bits is (Stopbits_1, Stopbits_2)
with Size => 2;
for Stop_Bits use (Stopbits_1 => 0, Stopbits_2 => 2#10#);
procedure Set_Stop_Bits (This : in out USART; To : Stop_Bits);
type Word_Lengths is (Word_Length_8, Word_Length_9);
procedure Set_Word_Length (This : in out USART; To : Word_Lengths);
type Parities is (No_Parity, Even_Parity, Odd_Parity);
procedure Set_Parity (This : in out USART; To : Parities);
subtype Baud_Rates is Word;
procedure Set_Baud_Rate (This : in out USART; To : Baud_Rates);
type Oversampling_Modes is (Oversampling_By_8, Oversampling_By_16);
-- oversampling by 16 is the default
procedure Set_Oversampling_Mode
(This : in out USART;
To : Oversampling_Modes);
type UART_Modes is (Rx_Mode, Tx_Mode, Tx_Rx_Mode);
procedure Set_Mode (This : in out USART; To : UART_Modes);
type Flow_Control is
(No_Flow_Control,
RTS_Flow_Control,
CTS_Flow_Control,
RTS_CTS_Flow_Control);
procedure Set_Flow_Control (This : in out USART; To : Flow_Control);
type USART_Interrupt is
(Parity_Error,
Transmit_Data_Register_Empty,
Transmission_Complete,
Received_Data_Not_Empty,
Idle_Line_Detection,
Line_Break_Detection,
Clear_To_Send,
Error);
procedure Enable_Interrupts
(This : in out USART;
Source : USART_Interrupt)
with
Post => Interrupt_Enabled (This, Source),
Inline;
procedure Disable_Interrupts
(This : in out USART;
Source : USART_Interrupt)
with
Post => not Interrupt_Enabled (This, Source),
Inline;
function Interrupt_Enabled
(This : USART;
Source : USART_Interrupt)
return Boolean
with Inline;
type USART_Status_Flag is
(Parity_Error_Indicated,
Framing_Error_Indicated,
USART_Noise_Error_Indicated,
Overrun_Error_Indicated,
Idle_Line_Detection_Indicated,
Read_Data_Register_Not_Empty,
Transmission_Complete_Indicated,
Transmit_Data_Register_Empty,
Line_Break_Detection_Indicated,
Clear_To_Send_Indicated);
function Status (This : USART; Flag : USART_Status_Flag) return Boolean
with Inline;
procedure Clear_Status (This : in out USART; Flag : USART_Status_Flag)
with Inline;
procedure Enable_DMA_Transmit_Requests (This : in out USART)
with
Inline,
Post => DMA_Transmit_Requests_Enabled (This);
procedure Disable_DMA_Transmit_Requests (This : in out USART)
with
Inline,
Post => not DMA_Transmit_Requests_Enabled (This);
function DMA_Transmit_Requests_Enabled (This : USART) return Boolean
with Inline;
procedure Enable_DMA_Receive_Requests (This : in out USART)
with
Inline,
Post => DMA_Receive_Requests_Enabled (This);
procedure Disable_DMA_Receive_Requests (This : in out USART)
with
Inline,
Post => not DMA_Receive_Requests_Enabled (This);
function DMA_Receive_Requests_Enabled (This : USART) return Boolean
with Inline;
procedure Pause_DMA_Transmission (This : in out USART)
renames Disable_DMA_Transmit_Requests;
procedure Resume_DMA_Transmission (This : in out USART)
with
Inline,
Post => DMA_Transmit_Requests_Enabled (This) and
Enabled (This);
procedure Pause_DMA_Reception (This : in out USART)
renames Disable_DMA_Receive_Requests;
procedure Resume_DMA_Reception (This : in out USART)
with
Inline,
Post => DMA_Receive_Requests_Enabled (This) and
Enabled (This);
function Data_Register_Address (This : USART) return System.Address
with Inline;
-- Returns the address of the USART Data Register. This is exported
-- STRICTLY for the sake of clients driving a USART via DMA. All other
-- clients of this package should use the procedural interfaces Transmit
-- and Receive instead of directly accessing the Data Register!
-- Seriously, don't use this function otherwise.
private
function APB_Clock (This : USART) return Word with Inline;
-- Returns either APB1 or APB2 clock rate, in Hertz, depending on the
-- USART. For the sake of not making this package board-specific, we assume
-- that we are given a valid USART object at a valid address, AND that the
-- USART devices really are configured such that only 1 and 6 are on APB2.
-- Therefore, if a board has additional USARTs beyond USART6, eg USART8 on
-- the F429I Discovery board, they better conform to that assumption.
-- See Note # 2 in each of Tables 139-141 of the RM on pages 970 - 972.
type USART is new STM32_SVD.USART.USART2_Peripheral;
end STM32.USARTs;
|
----------------------------------------------------------------------------
-- Generic Command Line Parser (gclp)
--
-- Copyright (C) 2012, Riccardo Bernardini
--
-- This file is part of gclp.
--
-- gclp is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 2 of the License, or
-- (at your option) any later version.
--
-- gclp is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with gclp. If not, see <http://www.gnu.org/licenses/>.
----------------------------------------------------------------------------
--
with Ada.Command_Line;
with Ada.Strings.Fixed;
with Ada.Strings.Maps.Constants;
with Ada.Containers.Indefinite_Doubly_Linked_Lists;
with Ada.Characters.Handling;
use Ada;
use Ada.Strings;
use Ada.Strings.Fixed;
with Ada.Directories;
package body Line_Parsers is
function To_S (X : Unbounded_String) return String
renames To_String;
function To_U (X : String) return Unbounded_String
renames To_Unbounded_String;
package Name_Lists is
new Ada.Containers.Indefinite_Doubly_Linked_Lists (String);
function Parse_Name (Name : String;
Case_Sensitive : Boolean) return Name_Lists.List;
procedure Add_Parameter
(Parser : in out Line_Parser;
Name : String;
If_Missing : Missing_Action := Ignore;
Default : String;
Handler : Handler_Access)
is
Names : constant Name_Lists.List := Parse_Name (Name, Parser.Case_Sensitive);
begin
Parser.Parameters.Append
(Parameter_Descriptor'(If_Missing => If_Missing,
Name => To_U (Name),
Handler => Handler,
Standard_Name => To_U (Names.First_Element),
Default => To_U (Default)));
for Single_Name of Names loop
if Parser.Name_Table.Contains (Single_Name) then
raise Constraint_Error;
end if;
Parser.Name_Table.Insert (Single_Name, Parser.Parameters.Last_Index);
end loop;
end Add_Parameter;
-- type Parameter_Descriptor_Array is
-- array (Parameter_Index range <>) of Parameter_Descriptor;
--------------------
-- Case_Normalize --
--------------------
-- If the user required case insensitive matching, force the
-- name to lower case
procedure Case_Normalize (Name : in out String;
Case_Sensitive : Boolean) is
begin
if not Case_Sensitive then
Translate (Name, Maps.Constants.Lower_Case_Map);
end if;
end Case_Normalize;
function Parse_Name (Name : String;
Case_Sensitive : Boolean) return Name_Lists.List
is
------------------
-- Trimmed_Name --
------------------
function Trimmed_Name (Name : String)
return String
is
Trimmed : String := Fixed.Trim (Name, Both);
begin
if Trimmed = "" then
raise Constraint_Error
with "Empty alternative in label '" & Name & "'";
else
Case_Normalize (Trimmed, Case_Sensitive);
return Trimmed;
end if;
end Trimmed_Name;
Result : Name_Lists.List;
First : Natural;
Comma_Pos : Natural;
begin
if Fixed.Index (Name, "=") /= 0 then
raise Constraint_Error with "Option label '" & Name & "' has '='";
end if;
if Name (Name'Last) = ',' then
raise Constraint_Error
with "Option label '" & Name & "' ends with ','";
end if;
First := Name'First;
loop
pragma Assert (First <= Name'Last);
Comma_Pos := Fixed.Index (Name (First .. Name'Last), ",");
exit when Comma_Pos = 0;
if First = Comma_Pos then
-- First should always point to the beginning of a
-- label, therefore it cannot be Buffer(First) = ','
raise Constraint_Error
with "Wrong syntax in Option label '" & Name & "'";
end if;
pragma Assert (Comma_Pos > First);
Result.Append (Trimmed_Name (Name (First .. Comma_Pos - 1)));
First := Comma_Pos + 1;
-- It cannot be First > Buffer'Last since Buffer(Comma_Pos) = '='
-- and Buffer(Buffer'Last) /= ','
pragma Assert (First <= Name'Last);
end loop;
pragma Assert (First <= Name'Last);
Result.Append (Trimmed_Name (Name (First .. Name'Last)));
return Result;
end Parse_Name;
------------
-- Create --
------------
function Create
(Case_Sensitive : Boolean := True;
Normalize_Name : Boolean := True;
Help_Line : String := "")
return Line_Parser
is
begin
return Line_Parser'(Case_Sensitive => Case_Sensitive,
Normalize_Name => Normalize_Name,
Help_Line => To_U (Help_Line),
Parameters => Parameter_Vectors.Empty_Vector,
Name_Table => Name_To_Index_Maps.Empty_Map);
end Create;
-----------
-- Slurp --
-----------
function Slurp (Filename : String;
Skip_Comments : Boolean := True;
Comment_Char : Character := '#';
Comment_Strict : Boolean := False)
return String_Vectors.Vector
is
use Ada.Text_IO;
use Ada.Directories;
use Ada.Characters.Handling;
function Is_Empty (X : String) return Boolean
is (for all Ch of X => Is_Space(Ch));
----------------
-- Is_Comment --
----------------
function Is_Comment (X : String) return Boolean
is
Idx : constant Natural := Index (X, Comment_Char & "");
begin
if Idx = 0 then
return False;
end if;
if Comment_Strict then
return Idx = X'First;
else
return (for all N in X'First .. Idx - 1 => Is_Space (X (N)));
end if;
end Is_Comment;
Input : File_Type;
Result : String_Vectors.Vector;
begin
if not Exists (Filename) or else Kind (Filename) /= Ordinary_File then
return String_Vectors.Empty_Vector;
end if;
Open (File => input,
Mode => In_File,
Name => Filename);
while not End_Of_File (Input) loop
declare
Line : constant String := Get_Line (Input);
begin
if not Is_Empty (Line) then
if not Skip_Comments or not Is_Comment (Line) then
Result.Append (Line);
end if;
end if;
end;
end loop;
Close (Input);
return Result;
end Slurp;
------------------------
-- Parse_Command_Line --
------------------------
procedure Parse_Command_Line
(Parser : Line_Parser;
Extend_By : String_Vectors.Vector := String_Vectors.Empty_Vector;
Help_Output : Ada.Text_IO.File_Type := Ada.Text_IO.Standard_Error) is
package String_Lists is
new Ada.Containers.Indefinite_Doubly_Linked_Lists (String);
---------------------
-- Split_Parameter --
---------------------
procedure Split_Parameter (Param : in String;
Name : out Unbounded_String;
Value : out Unbounded_String)
is
Idx : Natural;
begin
Idx := Index (Source => Param,
Pattern => "=");
if (Idx = 0) then
Name := To_U (Param);
Value := Null_Unbounded_String;
else
Name := To_U (Param (Param'First .. Idx - 1));
Value := To_U (Param (Idx + 1 .. Param'Last));
end if;
end Split_Parameter;
function Missing_Message (Missing : String_Lists.List)
return String
is
function Join (Item : String_Lists.List) return String is
Result : Unbounded_String;
procedure Append (Pos : String_Lists.Cursor) is
begin
if Result /= Null_Unbounded_String then
Result := Result & ", ";
end if;
Result := Result & "'" & String_Lists.Element (Pos) & "'";
end Append;
begin
Item.Iterate (Append'Access);
return To_String (Result);
end Join;
use type Ada.Containers.Count_Type;
begin
if Missing.Length = 1 then
return "Missing mandatory option " & Join (Missing);
else
return "Missing mandatory options: " & Join (Missing);
end if;
end Missing_Message;
function Collect_Parameters (Extra : String_Vectors.Vector)
return String_Vectors.Vector
is
Result : String_Vectors.Vector;
begin
for Idx in 1 .. Command_Line.Argument_Count loop
Result.Append (Command_Line.Argument (Idx));
end loop;
Result.Append (Extra);
return Result;
end Collect_Parameters;
Name : Unbounded_String;
Value : Unbounded_String;
use Name_To_Index_Maps;
Position : Name_To_Index_Maps.Cursor;
Param_Idx : Parameter_Index;
Arguments : constant String_Vectors.Vector := Collect_Parameters (Extend_By);
begin
for Pos in Arguments.First_Index .. Arguments.Last_Index loop
Split_Parameter (Arguments (Pos), Name, Value);
declare
N : String := To_S (Name);
V : constant String := To_S (Value);
Handler : Handler_Access;
This_Parameter : Parameter_Descriptor;
begin
Case_Normalize (N, Parser.Case_Sensitive);
Position := Parser.Name_Table.Find (N);
if Position = No_Element then
raise Bad_Command with "Option '" & To_S (Name) & "' unknown";
end if;
Param_Idx := Name_To_Index_Maps.Element (Position);
This_Parameter := Parser.Parameters (Param_Idx);
Handler := This_Parameter.Handler;
if Handler.Is_Set and not Handler.Reusable then
raise Bad_Command with "Option '" & N & "' given twice";
end if;
Handler.Receive (Name => (
if Parser.Normalize_Name then
To_S (This_Parameter.Standard_Name)
else
N
),
Value => V,
Position => Pos);
end;
end loop;
declare
Missing : String_Lists.List;
begin
for Parameter of Parser.Parameters loop
if not Parameter.Handler.Is_Set then
case Parameter.If_Missing is
when Die =>
Missing.Append (To_S (Parameter.Standard_Name));
when Use_Default =>
Parameter.Handler.Receive (Name => To_S (Parameter.Standard_Name),
Value => To_S (Parameter.Default),
Position => No_Position);
when Ignore =>
null;
end case;
end if;
end loop;
if not Missing.Is_Empty then
raise Bad_Command with Missing_Message (Missing);
end if;
end;
exception
when Bad_Command =>
if Parser.Help_Line /= Null_Unbounded_String then
Ada.Text_IO.Put_Line (File => Help_Output,
Item => To_S (Parser.Help_Line));
end if;
raise;
end Parse_Command_Line;
end Line_Parsers;
--
-- ---------------------
-- -- Normalized_Form --
-- ---------------------
--
-- function Normalized_Form (Parser : Line_Parser;
-- X : String) return String
-- is
-- Names : constant Name_Lists.List := Parse_Name (X, Parser.Case_Sensitive);
-- Result : String := Names.First_Element;
-- begin
-- Case_Normalize (Result, Parser.Case_Sensitive);
-- return Result;
-- end Normalized_Form;
--
-- ---------------------
-- -- Fill_Name_Table --
-- ---------------------
-- procedure Fill_Name_Table (Parameters : in Parameter_Descriptor_Array;
-- Name_Table : in out Name_To_Index_Maps.Map;
-- Standard_Names : out Name_Array)
-- with
-- Pre =>
-- Parameters'First = Standard_Names'First
-- and
-- Parameters'Last = Standard_Names'Last;
--
-- -- Fill the Parameter Name -> parameter index table with the
-- -- parameter names
-- procedure Fill_Name_Table (Parser : Line_Parser;
-- Parameters : in Parameter_Descriptor_Array;
-- Name_Table : in out Name_To_Index_Maps.Map;
-- Standard_Names : out Name_Array)
-- is
--
--
-- use Name_Lists;
--
-- ----------------
-- -- Parse_Name --
-- ----------------
--
--
-- Option_Names : Name_Lists.List;
-- Position : Name_Lists.Cursor;
--
-- Name : Unbounded_String;
-- begin
-- for Idx in Parameters'Range loop
-- Option_Names := Parse_Name (Parameters (Idx).Name);
--
-- Position := Option_Names.First;
-- Standard_Names (Idx) := Name_Lists.Element (Position);
--
-- while Position /= No_Element loop
-- Name := Name_Lists.Element (Position);
-- Name_Lists.Next (Position);
--
-- Case_Normalize (Parser, Name);
--
-- if Name_Table.Contains (Name) then
-- raise Constraint_Error
-- with "Ambiguous label '" & To_S (Name) & "'";
-- end if;
--
-- Name_Table.Insert (Name, Idx);
-- end loop;
-- end loop;
-- end Fill_Name_Table;
-- ----------------
-- -- To_Natural --
-- ----------------
--
-- function To_Natural (X : Unbounded_String)
-- return Natural is
-- begin
-- if X = Null_Unbounded_String then
-- raise Bad_Command with "Invalid integer '" & To_S (X) & "'";
-- end if;
--
-- return Natural'Value (To_S (X));
-- end To_Natural;
--
-- --------------
-- -- To_Float --
-- --------------
--
-- function To_Float (X : Unbounded_String)
-- return Float is
-- begin
-- if X = Null_Unbounded_String then
-- raise Bad_Command with "Invalid Float '" & To_S (X) & "'";
-- end if;
--
-- return Float'Value (To_S (X));
-- end To_Float;
|
------------------------------------------------------------------------------
-- --
-- GNU ADA RUN-TIME LIBRARY (GNARL) COMPONENTS --
-- --
-- S Y S T E M . S T A C K _ C H E C K I N G --
-- --
-- S p e c --
-- --
-- $Revision$
-- --
-- Copyright (C) 1999-2001 Free Software Foundation, Inc. --
-- --
-- GNARL is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 2, or (at your option) any later ver- --
-- sion. GNARL is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
-- for more details. You should have received a copy of the GNU General --
-- Public License distributed with GNARL; see file COPYING. If not, write --
-- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
-- MA 02111-1307, USA. --
-- --
-- As a special exception, if other files instantiate generics from this --
-- unit, or you link this unit with other files to produce an executable, --
-- this unit does not by itself cause the resulting executable to be --
-- covered by the GNU General Public License. This exception does not --
-- however invalidate any other reasons why the executable file might be --
-- covered by the GNU Public License. --
-- --
-- GNARL was developed by the GNARL team at Florida State University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
-- This package provides a system-independent implementation of stack
-- checking using comparison with stack base and limit.
with System.Storage_Elements;
pragma Polling (Off);
-- Turn off polling, we do not want polling to take place during stack
-- checking operations. It causes infinite loops and other problems.
package System.Stack_Checking is
type Stack_Info is record
Limit : System.Address := System.Null_Address;
Base : System.Address := System.Null_Address;
Size : System.Storage_Elements.Storage_Offset := 0;
end record;
-- This record may be part of a larger data structure like the
-- task control block in the tasking case.
-- This specific layout has the advantage of being compatible with the
-- Intel x86 BOUNDS instruction.
type Stack_Access is access all Stack_Info;
-- Unique local storage associated with a specific task. This storage is
-- used for the stack base and limit, and is returned by Checked_Self.
-- Only self may write this information, it may be read by any task.
-- At no time the address range Limit .. Base (or Base .. Limit for
-- upgrowing stack) may contain any address that is part of another stack.
-- The Stack_Access may be part of a larger data structure.
Multi_Processor : constant Boolean := False; -- Not supported yet
----------------------
-- Client Interface --
----------------------
procedure Set_Stack_Size
(Stack_Size : System.Storage_Elements.Storage_Offset);
-- Specify the stack size for the current task.
procedure Update_Stack_Cache (Stack : Stack_Access);
-- Set the stack cache for the current task. Note that this is only
-- for optimization purposes, nothing can be assumed about the
-- contents of the cache at any time, see Set_Stack_Info.
procedure Invalidate_Stack_Cache (Any_Stack : Stack_Access);
-- Invalidate cache entries for the task T that owns Any_Stack.
-- This causes the Set_Stack_Info function to be called during
-- the next stack check done by T. This can be used to interrupt
-- task T asynchronously.
-- Stack_Check should be called in loops for this to work reliably.
function Stack_Check (Stack_Address : System.Address) return Stack_Access;
-- This version of Stack_Check should not be inlined.
private
Null_Stack_Info : aliased Stack_Info :=
(Limit => System.Null_Address,
Base => System.Null_Address,
Size => 0);
-- Use explicit assignment to avoid elaboration code (call to _init_proc).
Null_Stack : constant Stack_Access := Null_Stack_Info'Access;
-- Stack_Access value that will return a Stack_Base and Stack_Limit
-- that fail any stack check.
Cache : aliased Stack_Access := Null_Stack;
pragma Export (C, Cache, "_gnat_stack_cache");
pragma Export (C, Stack_Check, "_gnat_stack_check");
end System.Stack_Checking;
|
pragma License (Unrestricted);
-- extended unit
with Ada.Environment_Encoding.Generic_Strings;
package Ada.Environment_Encoding.Strings is
new Generic_Strings (
Character,
String);
-- Encoding / decoding between String and various encodings.
pragma Preelaborate (Ada.Environment_Encoding.Strings);
|
with Ada.Text_IO;
package body Ada_Code is
package ATI renames Ada.Text_Io;
procedure Ada_Proc is
begin
ATI.Put_Line ("Ada_Proc: Begin");
ATI.Put_Line ("Ada_Proc: End");
end Ada_Proc;
procedure Ada_C_Caller is
procedure C_Func;
pragma Import (C, C_Func);
begin
ATI.Put_Line ("Ada_C_Caller: Calling C_Func");
C_Func;
ATI.Put_Line ("Ada_C_Caller: Returned from C_Func");
end Ada_C_Caller;
end Ada_Code;
|
-- Copyright 2016-2019 NXP
-- All rights reserved.SPDX-License-Identifier: BSD-3-Clause
-- This spec has been automatically generated from LPC55S6x.svd
pragma Restrictions (No_Elaboration_Code);
pragma Ada_2012;
pragma Style_Checks (Off);
with HAL;
with System;
package NXP_SVD.PMC is
pragma Preelaborate;
---------------
-- Registers --
---------------
-- Wake-up from DEEP POWER DOWN reset event (either from wake up I/O or RTC
-- or OS Event Timer).
type RESETCTRL_DPDWAKEUPRESETENABLE_Field is
(
-- Reset event from DEEP POWER DOWN mode is disable.
Disable,
-- Reset event from DEEP POWER DOWN mode is enable.
Enable)
with Size => 1;
for RESETCTRL_DPDWAKEUPRESETENABLE_Field use
(Disable => 0,
Enable => 1);
-- BOD VBAT reset enable.
type RESETCTRL_BODVBATRESETENABLE_Field is
(
-- BOD VBAT reset is disable.
Disable,
-- BOD VBAT reset is enable.
Enable)
with Size => 1;
for RESETCTRL_BODVBATRESETENABLE_Field use
(Disable => 0,
Enable => 1);
-- Software reset enable.
type RESETCTRL_SWRRESETENABLE_Field is
(
-- Software reset is disable.
Disable,
-- Software reset is enable.
Enable)
with Size => 1;
for RESETCTRL_SWRRESETENABLE_Field use
(Disable => 0,
Enable => 1);
-- Reset Control [Reset by: PoR, Pin Reset, Brown Out Detectors Reset, Deep
-- Power Down Reset, Software Reset]
type RESETCTRL_Register is record
-- Wake-up from DEEP POWER DOWN reset event (either from wake up I/O or
-- RTC or OS Event Timer).
DPDWAKEUPRESETENABLE : RESETCTRL_DPDWAKEUPRESETENABLE_Field :=
NXP_SVD.PMC.Disable;
-- BOD VBAT reset enable.
BODVBATRESETENABLE : RESETCTRL_BODVBATRESETENABLE_Field :=
NXP_SVD.PMC.Disable;
-- unspecified
Reserved_2_2 : HAL.Bit := 16#0#;
-- Software reset enable.
SWRRESETENABLE : RESETCTRL_SWRRESETENABLE_Field :=
NXP_SVD.PMC.Disable;
-- unspecified
Reserved_4_31 : HAL.UInt28 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for RESETCTRL_Register use record
DPDWAKEUPRESETENABLE at 0 range 0 .. 0;
BODVBATRESETENABLE at 0 range 1 .. 1;
Reserved_2_2 at 0 range 2 .. 2;
SWRRESETENABLE at 0 range 3 .. 3;
Reserved_4_31 at 0 range 4 .. 31;
end record;
-- BoD trigger level.
type BODVBAT_TRIGLVL_Field is
(
-- 1.00 V.
V_1P00,
-- 1.10 V.
V_1P10,
-- 1.20 V.
V_1P20,
-- 1.30 V.
V_1P30,
-- 1.40 V.
V_1P40,
-- 1.50 V.
V_1P50,
-- 1.60 V.
V_1P60,
-- 1.65 V.
V_1P65,
-- 1.70 V.
V_1P70,
-- 1.75 V.
V_1P75,
-- 1.80 V.
V_1P80,
-- 1.90 V.
V_1P90,
-- 2.00 V.
V_2P00,
-- 2.10 V.
V_2P10,
-- 2.20 V.
V_2P20,
-- 2.30 V.
V_2P30,
-- 2.40 V.
V_2P40,
-- 2.50 V.
V_2P50,
-- 2.60 V.
V_2P60,
-- 2.70 V.
V_2P70,
-- 2.806 V.
V_2P80,
-- 2.90 V.
V_2P90,
-- 3.00 V.
V_3P00,
-- 3.10 V.
V_3P10,
-- 3.20 V.
V_3P20,
-- 3.30 V.
V_3P30_2,
-- 3.30 V.
V_3P30_3,
-- 3.30 V.
V_3P30_4,
-- 3.30 V.
V_3P30_5,
-- 3.30 V.
V_3P30_6,
-- 3.30 V.
V_3P30_7,
-- 3.30 V.
V_3P30_8)
with Size => 5;
for BODVBAT_TRIGLVL_Field use
(V_1P00 => 0,
V_1P10 => 1,
V_1P20 => 2,
V_1P30 => 3,
V_1P40 => 4,
V_1P50 => 5,
V_1P60 => 6,
V_1P65 => 7,
V_1P70 => 8,
V_1P75 => 9,
V_1P80 => 10,
V_1P90 => 11,
V_2P00 => 12,
V_2P10 => 13,
V_2P20 => 14,
V_2P30 => 15,
V_2P40 => 16,
V_2P50 => 17,
V_2P60 => 18,
V_2P70 => 19,
V_2P80 => 20,
V_2P90 => 21,
V_3P00 => 22,
V_3P10 => 23,
V_3P20 => 24,
V_3P30_2 => 25,
V_3P30_3 => 26,
V_3P30_4 => 27,
V_3P30_5 => 28,
V_3P30_6 => 29,
V_3P30_7 => 30,
V_3P30_8 => 31);
-- BoD Hysteresis control.
type BODVBAT_HYST_Field is
(
-- 25 mV.
Hyst_25Mv,
-- 50 mV.
Hyst_50Mv,
-- 75 mV.
Hyst_75Mv,
-- 100 mV.
Hyst_100Mv)
with Size => 2;
for BODVBAT_HYST_Field use
(Hyst_25Mv => 0,
Hyst_50Mv => 1,
Hyst_75Mv => 2,
Hyst_100Mv => 3);
-- VBAT Brown Out Dectector (BoD) control register [Reset by: PoR, Pin
-- Reset, Software Reset]
type BODVBAT_Register is record
-- BoD trigger level.
TRIGLVL : BODVBAT_TRIGLVL_Field := NXP_SVD.PMC.V_1P65;
-- BoD Hysteresis control.
HYST : BODVBAT_HYST_Field := NXP_SVD.PMC.Hyst_75Mv;
-- unspecified
Reserved_7_31 : HAL.UInt25 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for BODVBAT_Register use record
TRIGLVL at 0 range 0 .. 4;
HYST at 0 range 5 .. 6;
Reserved_7_31 at 0 range 7 .. 31;
end record;
-- Hysteris when hyst = '1'.
type COMP_HYST_Field is
(
-- Hysteresis is disable.
Disable,
-- Hysteresis is enable.
Enable)
with Size => 1;
for COMP_HYST_Field use
(Disable => 0,
Enable => 1);
-- Dedicated control bit to select between internal VREF and VDDA (for the
-- resistive ladder).
type COMP_VREFINPUT_Field is
(
-- Select internal VREF.
Internalref,
-- Select VDDA.
Vdda)
with Size => 1;
for COMP_VREFINPUT_Field use
(Internalref => 0,
Vdda => 1);
-- Low power mode.
type COMP_LOWPOWER_Field is
(
-- High speed mode.
Highspeed,
-- Low power mode (Low speed).
Lowspeed)
with Size => 1;
for COMP_LOWPOWER_Field use
(Highspeed => 0,
Lowspeed => 1);
-- Control word for P multiplexer:.
type COMP_PMUX_Field is
(
-- VREF (See fiedl VREFINPUT).
Vref,
-- Pin P0_0.
Cmp0_A,
-- Pin P0_9.
Cmp0_B,
-- Pin P0_18.
Cmp0_C,
-- Pin P1_14.
Cmp0_D,
-- Pin P2_23.
Cmp0_E)
with Size => 3;
for COMP_PMUX_Field use
(Vref => 0,
Cmp0_A => 1,
Cmp0_B => 2,
Cmp0_C => 3,
Cmp0_D => 4,
Cmp0_E => 5);
-- Control word for N multiplexer:.
type COMP_NMUX_Field is
(
-- VREF (See field VREFINPUT).
Vref,
-- Pin P0_0.
Cmp0_A,
-- Pin P0_9.
Cmp0_B,
-- Pin P0_18.
Cmp0_C,
-- Pin P1_14.
Cmp0_D,
-- Pin P2_23.
Cmp0_E)
with Size => 3;
for COMP_NMUX_Field use
(Vref => 0,
Cmp0_A => 1,
Cmp0_B => 2,
Cmp0_C => 3,
Cmp0_D => 4,
Cmp0_E => 5);
subtype COMP_VREF_Field is HAL.UInt5;
subtype COMP_FILTERCGF_SAMPLEMODE_Field is HAL.UInt2;
subtype COMP_FILTERCGF_CLKDIV_Field is HAL.UInt3;
-- Analog Comparator control register [Reset by: PoR, Pin Reset, Brown Out
-- Detectors Reset, Deep Power Down Reset, Software Reset]
type COMP_Register is record
-- unspecified
Reserved_0_0 : HAL.Bit := 16#0#;
-- Hysteris when hyst = '1'.
HYST : COMP_HYST_Field := NXP_SVD.PMC.Enable;
-- Dedicated control bit to select between internal VREF and VDDA (for
-- the resistive ladder).
VREFINPUT : COMP_VREFINPUT_Field := NXP_SVD.PMC.Internalref;
-- Low power mode.
LOWPOWER : COMP_LOWPOWER_Field := NXP_SVD.PMC.Lowspeed;
-- Control word for P multiplexer:.
PMUX : COMP_PMUX_Field := NXP_SVD.PMC.Vref;
-- Control word for N multiplexer:.
NMUX : COMP_NMUX_Field := NXP_SVD.PMC.Vref;
-- Control reference voltage step, per steps of (VREFINPUT/31).
VREF : COMP_VREF_Field := 16#0#;
-- unspecified
Reserved_15_15 : HAL.Bit := 16#0#;
-- Filter Sample mode.
FILTERCGF_SAMPLEMODE : COMP_FILTERCGF_SAMPLEMODE_Field := 16#0#;
-- Filter Clock div .
FILTERCGF_CLKDIV : COMP_FILTERCGF_CLKDIV_Field := 16#0#;
-- unspecified
Reserved_21_31 : HAL.UInt11 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for COMP_Register use record
Reserved_0_0 at 0 range 0 .. 0;
HYST at 0 range 1 .. 1;
VREFINPUT at 0 range 2 .. 2;
LOWPOWER at 0 range 3 .. 3;
PMUX at 0 range 4 .. 6;
NMUX at 0 range 7 .. 9;
VREF at 0 range 10 .. 14;
Reserved_15_15 at 0 range 15 .. 15;
FILTERCGF_SAMPLEMODE at 0 range 16 .. 17;
FILTERCGF_CLKDIV at 0 range 18 .. 20;
Reserved_21_31 at 0 range 21 .. 31;
end record;
-- Allows to identify Wake up I/O 0 as the wake-up source from Deep Power
-- Down mode.
type WAKEIOCAUSE_WAKEUP0_Field is
(
-- Last wake up from Deep Power down mode was NOT triggred by wake up
-- I/O 0.
Noevent,
-- Last wake up from Deep Power down mode was triggred by wake up I/O 0.
Event)
with Size => 1;
for WAKEIOCAUSE_WAKEUP0_Field use
(Noevent => 0,
Event => 1);
-- Allows to identify Wake up I/O 1 as the wake-up source from Deep Power
-- Down mode.
type WAKEIOCAUSE_WAKEUP1_Field is
(
-- Last wake up from Deep Power down mode was NOT triggred by wake up
-- I/O 1.
Noevent,
-- Last wake up from Deep Power down mode was triggred by wake up I/O 1.
Event)
with Size => 1;
for WAKEIOCAUSE_WAKEUP1_Field use
(Noevent => 0,
Event => 1);
-- Allows to identify Wake up I/O 2 as the wake-up source from Deep Power
-- Down mode.
type WAKEIOCAUSE_WAKEUP2_Field is
(
-- Last wake up from Deep Power down mode was NOT triggred by wake up
-- I/O 2.
Noevent,
-- Last wake up from Deep Power down mode was triggred by wake up I/O 2.
Event)
with Size => 1;
for WAKEIOCAUSE_WAKEUP2_Field use
(Noevent => 0,
Event => 1);
-- Allows to identify Wake up I/O 3 as the wake-up source from Deep Power
-- Down mode.
type WAKEIOCAUSE_WAKEUP3_Field is
(
-- Last wake up from Deep Power down mode was NOT triggred by wake up
-- I/O 3.
Noevent,
-- Last wake up from Deep Power down mode was triggred by wake up I/O 3.
Event)
with Size => 1;
for WAKEIOCAUSE_WAKEUP3_Field use
(Noevent => 0,
Event => 1);
-- Allows to identify the Wake-up I/O source from Deep Power Down mode
type WAKEIOCAUSE_Register is record
-- Read-only. Allows to identify Wake up I/O 0 as the wake-up source
-- from Deep Power Down mode.
WAKEUP0 : WAKEIOCAUSE_WAKEUP0_Field := NXP_SVD.PMC.Noevent;
-- Allows to identify Wake up I/O 1 as the wake-up source from Deep
-- Power Down mode.
WAKEUP1 : WAKEIOCAUSE_WAKEUP1_Field := NXP_SVD.PMC.Noevent;
-- Allows to identify Wake up I/O 2 as the wake-up source from Deep
-- Power Down mode.
WAKEUP2 : WAKEIOCAUSE_WAKEUP2_Field := NXP_SVD.PMC.Noevent;
-- Allows to identify Wake up I/O 3 as the wake-up source from Deep
-- Power Down mode.
WAKEUP3 : WAKEIOCAUSE_WAKEUP3_Field := NXP_SVD.PMC.Noevent;
-- unspecified
Reserved_4_31 : HAL.UInt28 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for WAKEIOCAUSE_Register use record
WAKEUP0 at 0 range 0 .. 0;
WAKEUP1 at 0 range 1 .. 1;
WAKEUP2 at 0 range 2 .. 2;
WAKEUP3 at 0 range 3 .. 3;
Reserved_4_31 at 0 range 4 .. 31;
end record;
-- XTAL32 KHZ oscillator oscillation failure detection indicator.
type STATUSCLK_XTAL32KOSCFAILURE_Field is
(
-- No oscillation failure has been detetced since the last time this bit
-- has been cleared..
Nofail,
-- At least one oscillation failure has been detetced since the last
-- time this bit has been cleared..
Failure)
with Size => 1;
for STATUSCLK_XTAL32KOSCFAILURE_Field use
(Nofail => 0,
Failure => 1);
-- FRO and XTAL status register [Reset by: PoR, Brown Out Detectors Reset]
type STATUSCLK_Register is record
-- Read-only. XTAL oscillator 32 K OK signal.
XTAL32KOK : Boolean := False;
-- unspecified
Reserved_1_1 : HAL.Bit := 16#1#;
-- XTAL32 KHZ oscillator oscillation failure detection indicator.
XTAL32KOSCFAILURE : STATUSCLK_XTAL32KOSCFAILURE_Field :=
NXP_SVD.PMC.Failure;
-- unspecified
Reserved_3_31 : HAL.UInt29 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for STATUSCLK_Register use record
XTAL32KOK at 0 range 0 .. 0;
Reserved_1_1 at 0 range 1 .. 1;
XTAL32KOSCFAILURE at 0 range 2 .. 2;
Reserved_3_31 at 0 range 3 .. 31;
end record;
subtype AOREG1_BOOTERRORCOUNTER_Field is HAL.UInt4;
-- General purpose always on domain data storage [Reset by: PoR, Brown Out
-- Detectors Reset]
type AOREG1_Register is record
-- unspecified
Reserved_0_3 : HAL.UInt4 := 16#0#;
-- The last chip reset was caused by a Power On Reset.
POR : Boolean := False;
-- The last chip reset was caused by a Pin Reset.
PADRESET : Boolean := False;
-- The last chip reset was caused by a Brown Out Detector (BoD), either
-- VBAT BoD or Core Logic BoD.
BODRESET : Boolean := False;
-- The last chip reset was caused by a System Reset requested by the ARM
-- CPU.
SYSTEMRESET : Boolean := False;
-- The last chip reset was caused by the Watchdog Timer.
WDTRESET : Boolean := False;
-- The last chip reset was caused by a Software event.
SWRRESET : Boolean := False;
-- The last chip reset was caused by a Wake-up I/O reset event during a
-- Deep Power-Down mode.
DPDRESET_WAKEUPIO : Boolean := False;
-- The last chip reset was caused by an RTC (either RTC Alarm or RTC
-- wake up) reset event during a Deep Power-Down mode.
DPDRESET_RTC : Boolean := False;
-- The last chip reset was caused by an OS Event Timer reset event
-- during a Deep Power-Down mode.
DPDRESET_OSTIMER : Boolean := False;
-- unspecified
Reserved_13_15 : HAL.UInt3 := 16#0#;
-- ROM Boot Fatal Error Counter.
BOOTERRORCOUNTER : AOREG1_BOOTERRORCOUNTER_Field := 16#0#;
-- unspecified
Reserved_20_31 : HAL.UInt12 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for AOREG1_Register use record
Reserved_0_3 at 0 range 0 .. 3;
POR at 0 range 4 .. 4;
PADRESET at 0 range 5 .. 5;
BODRESET at 0 range 6 .. 6;
SYSTEMRESET at 0 range 7 .. 7;
WDTRESET at 0 range 8 .. 8;
SWRRESET at 0 range 9 .. 9;
DPDRESET_WAKEUPIO at 0 range 10 .. 10;
DPDRESET_RTC at 0 range 11 .. 11;
DPDRESET_OSTIMER at 0 range 12 .. 12;
Reserved_13_15 at 0 range 13 .. 15;
BOOTERRORCOUNTER at 0 range 16 .. 19;
Reserved_20_31 at 0 range 20 .. 31;
end record;
-- Select the 32K oscillator to be used in Deep Power Down Mode for the RTC
-- (either XTAL32KHz or FRO32KHz) .
type RTCOSC32K_SEL_Field is
(
-- FRO 32 KHz.
Fro32K,
-- XTAL 32KHz.
Xtal32K)
with Size => 1;
for RTCOSC32K_SEL_Field use
(Fro32K => 0,
Xtal32K => 1);
subtype RTCOSC32K_CLK1KHZDIV_Field is HAL.UInt3;
subtype RTCOSC32K_CLK1HZDIV_Field is HAL.UInt11;
-- RTC 1 KHZ and 1 Hz clocks source control register [Reset by: PoR, Brown
-- Out Detectors Reset]
type RTCOSC32K_Register is record
-- Select the 32K oscillator to be used in Deep Power Down Mode for the
-- RTC (either XTAL32KHz or FRO32KHz) .
SEL : RTCOSC32K_SEL_Field := NXP_SVD.PMC.Fro32K;
-- Actual division ratio is : 28 + CLK1KHZDIV.
CLK1KHZDIV : RTCOSC32K_CLK1KHZDIV_Field := 16#4#;
-- unspecified
Reserved_4_14 : HAL.UInt11 := 16#0#;
-- RTC 1KHz clock Divider status flag.
CLK1KHZDIVUPDATEREQ : Boolean := False;
-- Actual division ratio is : 31744 + CLK1HZDIV.
CLK1HZDIV : RTCOSC32K_CLK1HZDIV_Field := 16#3FF#;
-- unspecified
Reserved_27_29 : HAL.UInt3 := 16#0#;
-- Halts the divider counter.
CLK1HZDIVHALT : Boolean := False;
-- RTC 1Hz Divider status flag.
CLK1HZDIVUPDATEREQ : Boolean := False;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for RTCOSC32K_Register use record
SEL at 0 range 0 .. 0;
CLK1KHZDIV at 0 range 1 .. 3;
Reserved_4_14 at 0 range 4 .. 14;
CLK1KHZDIVUPDATEREQ at 0 range 15 .. 15;
CLK1HZDIV at 0 range 16 .. 26;
Reserved_27_29 at 0 range 27 .. 29;
CLK1HZDIVHALT at 0 range 30 .. 30;
CLK1HZDIVUPDATEREQ at 0 range 31 .. 31;
end record;
-- OS Timer control register [Reset by: PoR, Brown Out Detectors Reset]
type OSTIMER_Register is record
-- Active high reset.
SOFTRESET : Boolean := False;
-- Enable OSTIMER 32 KHz clock.
CLOCKENABLE : Boolean := False;
-- Wake up enable in Deep Power Down mode (To be used in Enable Deep
-- Power Down mode).
DPDWAKEUPENABLE : Boolean := False;
-- Oscilator 32KHz (either FRO32KHz or XTAL32KHz according to RTCOSC32K.
OSC32KPD : Boolean := True;
-- unspecified
Reserved_4_31 : HAL.UInt28 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for OSTIMER_Register use record
SOFTRESET at 0 range 0 .. 0;
CLOCKENABLE at 0 range 1 .. 1;
DPDWAKEUPENABLE at 0 range 2 .. 2;
OSC32KPD at 0 range 3 .. 3;
Reserved_4_31 at 0 range 4 .. 31;
end record;
-- Controls power to VBAT Brown Out Detector (BOD).
type PDRUNCFG0_PDEN_BODVBAT_Field is
(
-- BOD VBAT is powered.
Poweredon,
-- BOD VBAT is powered down.
Poweredoff)
with Size => 1;
for PDRUNCFG0_PDEN_BODVBAT_Field use
(Poweredon => 0,
Poweredoff => 1);
-- Controls power to the Free Running Oscillator (FRO) 32 KHz.
type PDRUNCFG0_PDEN_FRO32K_Field is
(
-- FRO32KHz is powered.
Poweredon,
-- FRO32KHz is powered down.
Poweredoff)
with Size => 1;
for PDRUNCFG0_PDEN_FRO32K_Field use
(Poweredon => 0,
Poweredoff => 1);
-- Controls power to crystal 32 KHz.
type PDRUNCFG0_PDEN_XTAL32K_Field is
(
-- Crystal 32KHz is powered.
Poweredon,
-- Crystal 32KHz is powered down.
Poweredoff)
with Size => 1;
for PDRUNCFG0_PDEN_XTAL32K_Field use
(Poweredon => 0,
Poweredoff => 1);
-- Controls power to crystal 32 MHz.
type PDRUNCFG0_PDEN_XTAL32M_Field is
(
-- Crystal 32MHz is powered.
Poweredon,
-- Crystal 32MHz is powered down.
Poweredoff)
with Size => 1;
for PDRUNCFG0_PDEN_XTAL32M_Field use
(Poweredon => 0,
Poweredoff => 1);
-- Controls power to System PLL (also refered as PLL0).
type PDRUNCFG0_PDEN_PLL0_Field is
(
-- PLL0 is powered.
Poweredon,
-- PLL0 is powered down.
Poweredoff)
with Size => 1;
for PDRUNCFG0_PDEN_PLL0_Field use
(Poweredon => 0,
Poweredoff => 1);
-- Controls power to USB PLL (also refered as PLL1).
type PDRUNCFG0_PDEN_PLL1_Field is
(
-- PLL1 is powered.
Poweredon,
-- PLL1 is powered down.
Poweredoff)
with Size => 1;
for PDRUNCFG0_PDEN_PLL1_Field use
(Poweredon => 0,
Poweredoff => 1);
-- Controls power to USB Full Speed phy.
type PDRUNCFG0_PDEN_USBFSPHY_Field is
(
-- USB Full Speed phy is powered.
Poweredon,
-- USB Full Speed phy is powered down.
Poweredoff)
with Size => 1;
for PDRUNCFG0_PDEN_USBFSPHY_Field use
(Poweredon => 0,
Poweredoff => 1);
-- Controls power to USB High Speed Phy.
type PDRUNCFG0_PDEN_USBHSPHY_Field is
(
-- USB HS phy is powered.
Poweredon,
-- USB HS phy is powered down.
Poweredoff)
with Size => 1;
for PDRUNCFG0_PDEN_USBHSPHY_Field use
(Poweredon => 0,
Poweredoff => 1);
-- Controls power to Analog Comparator.
type PDRUNCFG0_PDEN_COMP_Field is
(
-- Analog Comparator is powered.
Poweredon,
-- Analog Comparator is powered down.
Poweredoff)
with Size => 1;
for PDRUNCFG0_PDEN_COMP_Field use
(Poweredon => 0,
Poweredoff => 1);
-- Controls power to USB high speed LDO.
type PDRUNCFG0_PDEN_LDOUSBHS_Field is
(
-- USB high speed LDO is powered.
Poweredon,
-- USB high speed LDO is powered down.
Poweredoff)
with Size => 1;
for PDRUNCFG0_PDEN_LDOUSBHS_Field use
(Poweredon => 0,
Poweredoff => 1);
-- Controls power to auxiliary biasing (AUXBIAS)
type PDRUNCFG0_PDEN_AUXBIAS_Field is
(
-- auxiliary biasing is powered.
Poweredon,
-- auxiliary biasing is powered down.
Poweredoff)
with Size => 1;
for PDRUNCFG0_PDEN_AUXBIAS_Field use
(Poweredon => 0,
Poweredoff => 1);
-- Controls power to crystal 32 MHz LDO.
type PDRUNCFG0_PDEN_LDOXO32M_Field is
(
-- crystal 32 MHz LDO is powered.
Poweredon,
-- crystal 32 MHz LDO is powered down.
Poweredoff)
with Size => 1;
for PDRUNCFG0_PDEN_LDOXO32M_Field use
(Poweredon => 0,
Poweredoff => 1);
-- Controls power to all True Random Number Genetaor (TRNG) clock sources.
type PDRUNCFG0_PDEN_RNG_Field is
(
-- TRNG clocks are powered.
Poweredon,
-- TRNG clocks are powered down.
Poweredoff)
with Size => 1;
for PDRUNCFG0_PDEN_RNG_Field use
(Poweredon => 0,
Poweredoff => 1);
-- Controls power to System PLL (PLL0) Spread Spectrum module.
type PDRUNCFG0_PDEN_PLL0_SSCG_Field is
(
-- PLL0 Sread spectrum module is powered.
Poweredon,
-- PLL0 Sread spectrum module is powered down.
Poweredoff)
with Size => 1;
for PDRUNCFG0_PDEN_PLL0_SSCG_Field use
(Poweredon => 0,
Poweredoff => 1);
-- Controls the power to various analog blocks [Reset by: PoR, Pin Reset,
-- Brown Out Detectors Reset, Deep Power Down Reset, Software Reset]
type PDRUNCFG0_Register is record
-- unspecified
Reserved_0_2 : HAL.UInt3 := 16#4#;
-- Controls power to VBAT Brown Out Detector (BOD).
PDEN_BODVBAT : PDRUNCFG0_PDEN_BODVBAT_Field := NXP_SVD.PMC.Poweredon;
-- unspecified
Reserved_4_5 : HAL.UInt2 := 16#0#;
-- Controls power to the Free Running Oscillator (FRO) 32 KHz.
PDEN_FRO32K : PDRUNCFG0_PDEN_FRO32K_Field := NXP_SVD.PMC.Poweredoff;
-- Controls power to crystal 32 KHz.
PDEN_XTAL32K : PDRUNCFG0_PDEN_XTAL32K_Field := NXP_SVD.PMC.Poweredoff;
-- Controls power to crystal 32 MHz.
PDEN_XTAL32M : PDRUNCFG0_PDEN_XTAL32M_Field := NXP_SVD.PMC.Poweredoff;
-- Controls power to System PLL (also refered as PLL0).
PDEN_PLL0 : PDRUNCFG0_PDEN_PLL0_Field := NXP_SVD.PMC.Poweredoff;
-- Controls power to USB PLL (also refered as PLL1).
PDEN_PLL1 : PDRUNCFG0_PDEN_PLL1_Field := NXP_SVD.PMC.Poweredoff;
-- Controls power to USB Full Speed phy.
PDEN_USBFSPHY : PDRUNCFG0_PDEN_USBFSPHY_Field :=
NXP_SVD.PMC.Poweredoff;
-- Controls power to USB High Speed Phy.
PDEN_USBHSPHY : PDRUNCFG0_PDEN_USBHSPHY_Field :=
NXP_SVD.PMC.Poweredoff;
-- Controls power to Analog Comparator.
PDEN_COMP : PDRUNCFG0_PDEN_COMP_Field := NXP_SVD.PMC.Poweredoff;
-- unspecified
Reserved_14_17 : HAL.UInt4 := 16#B#;
-- Controls power to USB high speed LDO.
PDEN_LDOUSBHS : PDRUNCFG0_PDEN_LDOUSBHS_Field :=
NXP_SVD.PMC.Poweredoff;
-- Controls power to auxiliary biasing (AUXBIAS)
PDEN_AUXBIAS : PDRUNCFG0_PDEN_AUXBIAS_Field := NXP_SVD.PMC.Poweredoff;
-- Controls power to crystal 32 MHz LDO.
PDEN_LDOXO32M : PDRUNCFG0_PDEN_LDOXO32M_Field :=
NXP_SVD.PMC.Poweredoff;
-- unspecified
Reserved_21_21 : HAL.Bit := 16#0#;
-- Controls power to all True Random Number Genetaor (TRNG) clock
-- sources.
PDEN_RNG : PDRUNCFG0_PDEN_RNG_Field := NXP_SVD.PMC.Poweredoff;
-- Controls power to System PLL (PLL0) Spread Spectrum module.
PDEN_PLL0_SSCG : PDRUNCFG0_PDEN_PLL0_SSCG_Field :=
NXP_SVD.PMC.Poweredoff;
-- unspecified
Reserved_24_31 : HAL.UInt8 := 16#0#;
end record
with Volatile_Full_Access, Size => 32,
Bit_Order => System.Low_Order_First;
for PDRUNCFG0_Register use record
Reserved_0_2 at 0 range 0 .. 2;
PDEN_BODVBAT at 0 range 3 .. 3;
Reserved_4_5 at 0 range 4 .. 5;
PDEN_FRO32K at 0 range 6 .. 6;
PDEN_XTAL32K at 0 range 7 .. 7;
PDEN_XTAL32M at 0 range 8 .. 8;
PDEN_PLL0 at 0 range 9 .. 9;
PDEN_PLL1 at 0 range 10 .. 10;
PDEN_USBFSPHY at 0 range 11 .. 11;
PDEN_USBHSPHY at 0 range 12 .. 12;
PDEN_COMP at 0 range 13 .. 13;
Reserved_14_17 at 0 range 14 .. 17;
PDEN_LDOUSBHS at 0 range 18 .. 18;
PDEN_AUXBIAS at 0 range 19 .. 19;
PDEN_LDOXO32M at 0 range 20 .. 20;
Reserved_21_21 at 0 range 21 .. 21;
PDEN_RNG at 0 range 22 .. 22;
PDEN_PLL0_SSCG at 0 range 23 .. 23;
Reserved_24_31 at 0 range 24 .. 31;
end record;
-----------------
-- Peripherals --
-----------------
-- PMC
type PMC_Peripheral is record
-- Reset Control [Reset by: PoR, Pin Reset, Brown Out Detectors Reset,
-- Deep Power Down Reset, Software Reset]
RESETCTRL : aliased RESETCTRL_Register;
-- VBAT Brown Out Dectector (BoD) control register [Reset by: PoR, Pin
-- Reset, Software Reset]
BODVBAT : aliased BODVBAT_Register;
-- Analog Comparator control register [Reset by: PoR, Pin Reset, Brown
-- Out Detectors Reset, Deep Power Down Reset, Software Reset]
COMP : aliased COMP_Register;
-- Allows to identify the Wake-up I/O source from Deep Power Down mode
WAKEIOCAUSE : aliased WAKEIOCAUSE_Register;
-- FRO and XTAL status register [Reset by: PoR, Brown Out Detectors
-- Reset]
STATUSCLK : aliased STATUSCLK_Register;
-- General purpose always on domain data storage [Reset by: PoR, Brown
-- Out Detectors Reset]
AOREG1 : aliased AOREG1_Register;
-- RTC 1 KHZ and 1 Hz clocks source control register [Reset by: PoR,
-- Brown Out Detectors Reset]
RTCOSC32K : aliased RTCOSC32K_Register;
-- OS Timer control register [Reset by: PoR, Brown Out Detectors Reset]
OSTIMER : aliased OSTIMER_Register;
-- Controls the power to various analog blocks [Reset by: PoR, Pin
-- Reset, Brown Out Detectors Reset, Deep Power Down Reset, Software
-- Reset]
PDRUNCFG0 : aliased PDRUNCFG0_Register;
-- Controls the power to various analog blocks [Reset by: PoR, Pin
-- Reset, Brown Out Detectors Reset, Deep Power Down Reset, Software
-- Reset]
PDRUNCFGSET0 : aliased HAL.UInt32;
-- Controls the power to various analog blocks [Reset by: PoR, Pin
-- Reset, Brown Out Detectors Reset, Deep Power Down Reset, Software
-- Reset]
PDRUNCFGCLR0 : aliased HAL.UInt32;
end record
with Volatile;
for PMC_Peripheral use record
RESETCTRL at 16#8# range 0 .. 31;
BODVBAT at 16#30# range 0 .. 31;
COMP at 16#50# range 0 .. 31;
WAKEIOCAUSE at 16#68# range 0 .. 31;
STATUSCLK at 16#74# range 0 .. 31;
AOREG1 at 16#84# range 0 .. 31;
RTCOSC32K at 16#98# range 0 .. 31;
OSTIMER at 16#9C# range 0 .. 31;
PDRUNCFG0 at 16#B8# range 0 .. 31;
PDRUNCFGSET0 at 16#C0# range 0 .. 31;
PDRUNCFGCLR0 at 16#C8# range 0 .. 31;
end record;
-- PMC
PMC_Periph : aliased PMC_Peripheral
with Import, Address => System'To_Address (16#40020000#);
end NXP_SVD.PMC;
|
with
ADA.Containers.Vectors;
package Constraint_Engine is
type Type_Problem is
tagged private;
type Enum_Relational is
(IS_EQUAL, -- =
IS_LESS_EQUAL, -- <=
IS_LESS, -- <
IS_MORE_EQUAL, -- >=
IS_MORE, -- >
IS_INEQUAL); -- /=
type Type_Variable is tagged
record
Low_Interval : Integer;
Top_Interval : Integer;
Curr_Solution : Integer;
end record;
type Type_Constraint is tagged
record
V1_Position : Positive;
Rel : Enum_Relational;
V2_Position : Positive;
V : Integer;
Is_Var_Ctr : Boolean;
end record;
package Var_Vector is new ADA.Containers.Vectors(Index_Type => Positive,
Element_Type => Type_Variable);
package Ctr_Vector is new ADA.Containers.Vectors(Index_Type => Positive,
Element_Type => Type_Constraint);
type Type_Array_Position is
Array( Integer range <> ) of Positive;
function Find_Solution
(Self : in Type_Problem) return Type_Problem;
function Is_Valid_Solution
(Self : Type_Problem) return Boolean;
function Is_Valid_Relation
(Self : Type_Problem; V_1 : Integer; Rel : Enum_Relational; V_2 : Integer) return Boolean;
function Get_Var
(Self : Type_Problem) return Var_Vector.Vector;
function Check_Contradiction
(Self : Type_Problem) return Boolean;
pragma Assertion_Policy (Pre => Check);
procedure Add_Var
(Self : in out Type_Problem; Low_Interval : Integer; Top_Interval : Integer)
with Pre => Low_Interval <= Top_Interval;
procedure Add_Constraint_Var
(Self : in out Type_Problem; V1_Position : Positive; Rel : Enum_Relational; V2_Position : Positive);
pragma Assertion_Policy (Pre => Check);
procedure Add_Constraint_Var_Multiple
(Self : in out Type_Problem; V_All_Position : Type_Array_Position; Rel : Enum_Relational)
with Pre => Rel = IS_EQUAL or Rel = IS_INEQUAL;
procedure Add_Constraint_Int
(Self : in out Type_Problem; V1_Position : Positive; Rel : Enum_Relational; V : Integer);
procedure Add_Constraint_Int_Multiple
(Self : in out Type_Problem; V_All_Position : Type_Array_Position; Rel : Enum_Relational; V : Integer);
--- Exceptions
No_Solution : exception;
Contradicted_Contraint : exception;
private
type Type_Problem is tagged
record
Var_Cur : Integer := 0;
Ctr_Cur : Integer := 0;
Var_List : Var_Vector.Vector;
Ctr_List : Ctr_Vector.Vector;
end record;
end Constraint_Engine;
|
pragma Ada_2005;
pragma Style_Checks (Off);
with Interfaces.C; use Interfaces.C;
with System;
with Interfaces.C.Strings;
package x86_64_linux_gnu_bits_types_h is
-- bits/types.h -- definitions of __*_t types underlying *_t types.
-- Copyright (C) 2002-2018 Free Software Foundation, Inc.
-- This file is part of the GNU C Library.
-- The GNU C Library is free software; you can redistribute it and/or
-- modify it under the terms of the GNU Lesser General Public
-- License as published by the Free Software Foundation; either
-- version 2.1 of the License, or (at your option) any later version.
-- The GNU C Library is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-- Lesser General Public License for more details.
-- You should have received a copy of the GNU Lesser General Public
-- License along with the GNU C Library; if not, see
-- <http://www.gnu.org/licenses/>.
-- * Never include this file directly; use <sys/types.h> instead.
--
-- Convenience types.
subtype uu_u_char is unsigned_char; -- /usr/include/x86_64-linux-gnu/bits/types.h:30
subtype uu_u_short is unsigned_short; -- /usr/include/x86_64-linux-gnu/bits/types.h:31
subtype uu_u_int is unsigned; -- /usr/include/x86_64-linux-gnu/bits/types.h:32
subtype uu_u_long is unsigned_long; -- /usr/include/x86_64-linux-gnu/bits/types.h:33
-- Fixed-size types, underlying types depend on word size and compiler.
subtype uu_int8_t is signed_char; -- /usr/include/x86_64-linux-gnu/bits/types.h:36
subtype uu_uint8_t is unsigned_char; -- /usr/include/x86_64-linux-gnu/bits/types.h:37
subtype uu_int16_t is short; -- /usr/include/x86_64-linux-gnu/bits/types.h:38
subtype uu_uint16_t is unsigned_short; -- /usr/include/x86_64-linux-gnu/bits/types.h:39
subtype uu_int32_t is int; -- /usr/include/x86_64-linux-gnu/bits/types.h:40
subtype uu_uint32_t is unsigned; -- /usr/include/x86_64-linux-gnu/bits/types.h:41
subtype uu_int64_t is long; -- /usr/include/x86_64-linux-gnu/bits/types.h:43
subtype uu_uint64_t is unsigned_long; -- /usr/include/x86_64-linux-gnu/bits/types.h:44
-- quad_t is also 64 bits.
subtype uu_quad_t is long; -- /usr/include/x86_64-linux-gnu/bits/types.h:52
subtype uu_u_quad_t is unsigned_long; -- /usr/include/x86_64-linux-gnu/bits/types.h:53
-- Largest integral types.
subtype uu_intmax_t is long; -- /usr/include/x86_64-linux-gnu/bits/types.h:61
subtype uu_uintmax_t is unsigned_long; -- /usr/include/x86_64-linux-gnu/bits/types.h:62
-- The machine-dependent file <bits/typesizes.h> defines __*_T_TYPE
-- macros for each of the OS types we define below. The definitions
-- of those macros must use the following macros for underlying types.
-- We define __S<SIZE>_TYPE and __U<SIZE>_TYPE for the signed and unsigned
-- variants of each of the following integer types on this machine.
-- 16 -- "natural" 16-bit type (always short)
-- 32 -- "natural" 32-bit type (always int)
-- 64 -- "natural" 64-bit type (long or long long)
-- LONG32 -- 32-bit type, traditionally long
-- QUAD -- 64-bit type, always long long
-- WORD -- natural type of __WORDSIZE bits (int or long)
-- LONGWORD -- type of __WORDSIZE bits, traditionally long
-- We distinguish WORD/LONGWORD, 32/LONG32, and 64/QUAD so that the
-- conventional uses of `long' or `long long' type modifiers match the
-- types we define, even when a less-adorned type would be the same size.
-- This matters for (somewhat) portably writing printf/scanf formats for
-- these types, where using the appropriate l or ll format modifiers can
-- make the typedefs and the formats match up across all GNU platforms. If
-- we used `long' when it's 64 bits where `long long' is expected, then the
-- compiler would warn about the formats not matching the argument types,
-- and the programmer changing them to shut up the compiler would break the
-- program's portability.
-- Here we assume what is presently the case in all the GCC configurations
-- we support: long long is always 64 bits, long is always word/address size,
-- and int is always 32 bits.
-- We want __extension__ before typedef's that use nonstandard base types
-- such as `long long' in C89 mode.
-- No need to mark the typedef with __extension__.
-- Defines __*_T_TYPE macros.
-- Type of device numbers.
subtype uu_dev_t is unsigned_long; -- /usr/include/x86_64-linux-gnu/bits/types.h:133
-- Type of user identifications.
subtype uu_uid_t is unsigned; -- /usr/include/x86_64-linux-gnu/bits/types.h:134
-- Type of group identifications.
subtype uu_gid_t is unsigned; -- /usr/include/x86_64-linux-gnu/bits/types.h:135
-- Type of file serial numbers.
subtype uu_ino_t is unsigned_long; -- /usr/include/x86_64-linux-gnu/bits/types.h:136
-- Type of file serial numbers (LFS).
subtype uu_ino64_t is unsigned_long; -- /usr/include/x86_64-linux-gnu/bits/types.h:137
-- Type of file attribute bitmasks.
subtype uu_mode_t is unsigned; -- /usr/include/x86_64-linux-gnu/bits/types.h:138
-- Type of file link counts.
subtype uu_nlink_t is unsigned_long; -- /usr/include/x86_64-linux-gnu/bits/types.h:139
-- Type of file sizes and offsets.
subtype uu_off_t is long; -- /usr/include/x86_64-linux-gnu/bits/types.h:140
-- Type of file sizes and offsets (LFS).
subtype uu_off64_t is long; -- /usr/include/x86_64-linux-gnu/bits/types.h:141
-- Type of process identifications.
subtype uu_pid_t is int; -- /usr/include/x86_64-linux-gnu/bits/types.h:142
-- Type of file system IDs.
type uu_fsid_t_uu_val_array is array (0 .. 1) of aliased int;
type uu_fsid_t is record
uu_val : aliased uu_fsid_t_uu_val_array; -- /usr/include/x86_64-linux-gnu/bits/types.h:143
end record;
pragma Convention (C_Pass_By_Copy, uu_fsid_t); -- /usr/include/x86_64-linux-gnu/bits/types.h:143
-- skipped anonymous struct anon_0
-- Type of CPU usage counts.
subtype uu_clock_t is long; -- /usr/include/x86_64-linux-gnu/bits/types.h:144
-- Type for resource measurement.
subtype uu_rlim_t is unsigned_long; -- /usr/include/x86_64-linux-gnu/bits/types.h:145
-- Type for resource measurement (LFS).
subtype uu_rlim64_t is unsigned_long; -- /usr/include/x86_64-linux-gnu/bits/types.h:146
-- General type for IDs.
subtype uu_id_t is unsigned; -- /usr/include/x86_64-linux-gnu/bits/types.h:147
-- Seconds since the Epoch.
subtype uu_time_t is long; -- /usr/include/x86_64-linux-gnu/bits/types.h:148
-- Count of microseconds.
subtype uu_useconds_t is unsigned; -- /usr/include/x86_64-linux-gnu/bits/types.h:149
-- Signed count of microseconds.
subtype uu_suseconds_t is long; -- /usr/include/x86_64-linux-gnu/bits/types.h:150
-- The type of a disk address.
subtype uu_daddr_t is int; -- /usr/include/x86_64-linux-gnu/bits/types.h:152
-- Type of an IPC key.
subtype uu_key_t is int; -- /usr/include/x86_64-linux-gnu/bits/types.h:153
-- Clock ID used in clock and timer functions.
subtype uu_clockid_t is int; -- /usr/include/x86_64-linux-gnu/bits/types.h:156
-- Timer ID returned by `timer_create'.
type uu_timer_t is new System.Address; -- /usr/include/x86_64-linux-gnu/bits/types.h:159
-- Type to represent block size.
subtype uu_blksize_t is long; -- /usr/include/x86_64-linux-gnu/bits/types.h:162
-- Types from the Large File Support interface.
-- Type to count number of disk blocks.
subtype uu_blkcnt_t is long; -- /usr/include/x86_64-linux-gnu/bits/types.h:167
subtype uu_blkcnt64_t is long; -- /usr/include/x86_64-linux-gnu/bits/types.h:168
-- Type to count file system blocks.
subtype uu_fsblkcnt_t is unsigned_long; -- /usr/include/x86_64-linux-gnu/bits/types.h:171
subtype uu_fsblkcnt64_t is unsigned_long; -- /usr/include/x86_64-linux-gnu/bits/types.h:172
-- Type to count file system nodes.
subtype uu_fsfilcnt_t is unsigned_long; -- /usr/include/x86_64-linux-gnu/bits/types.h:175
subtype uu_fsfilcnt64_t is unsigned_long; -- /usr/include/x86_64-linux-gnu/bits/types.h:176
-- Type of miscellaneous file system fields.
subtype uu_fsword_t is long; -- /usr/include/x86_64-linux-gnu/bits/types.h:179
-- Type of a byte count, or error.
subtype uu_ssize_t is long; -- /usr/include/x86_64-linux-gnu/bits/types.h:181
-- Signed long type used in system calls.
subtype uu_syscall_slong_t is long; -- /usr/include/x86_64-linux-gnu/bits/types.h:184
-- Unsigned long type used in system calls.
subtype uu_syscall_ulong_t is unsigned_long; -- /usr/include/x86_64-linux-gnu/bits/types.h:186
-- These few don't really vary by system, they always correspond
-- to one of the other defined types.
-- Type of file sizes and offsets (LFS).
subtype uu_loff_t is uu_off64_t; -- /usr/include/x86_64-linux-gnu/bits/types.h:190
type uu_caddr_t is new Interfaces.C.Strings.chars_ptr; -- /usr/include/x86_64-linux-gnu/bits/types.h:191
-- Duplicates info from stdint.h but this is used in unistd.h.
subtype uu_intptr_t is long; -- /usr/include/x86_64-linux-gnu/bits/types.h:194
-- Duplicate info from sys/socket.h.
subtype uu_socklen_t is unsigned; -- /usr/include/x86_64-linux-gnu/bits/types.h:197
-- C99: An integer type that can be accessed as an atomic entity,
-- even in the presence of asynchronous interrupts.
-- It is not currently necessary for this to be machine-specific.
subtype uu_sig_atomic_t is int; -- /usr/include/x86_64-linux-gnu/bits/types.h:202
end x86_64_linux_gnu_bits_types_h;
|
with
Interfaces.C,
System;
use type
Interfaces.C.int,
System.Address;
package body FLTK.Widgets.Groups.Color_Choosers is
procedure color_chooser_set_draw_hook
(W, D : in System.Address);
pragma Import (C, color_chooser_set_draw_hook, "color_chooser_set_draw_hook");
pragma Inline (color_chooser_set_draw_hook);
procedure color_chooser_set_handle_hook
(W, H : in System.Address);
pragma Import (C, color_chooser_set_handle_hook, "color_chooser_set_handle_hook");
pragma Inline (color_chooser_set_handle_hook);
function new_fl_color_chooser
(X, Y, W, H : in Interfaces.C.int;
Text : in Interfaces.C.char_array)
return System.Address;
pragma Import (C, new_fl_color_chooser, "new_fl_color_chooser");
pragma Inline (new_fl_color_chooser);
procedure free_fl_color_chooser
(W : in System.Address);
pragma Import (C, free_fl_color_chooser, "free_fl_color_chooser");
pragma Inline (free_fl_color_chooser);
function fl_color_chooser_r
(N : in System.Address)
return Interfaces.C.double;
pragma Import (C, fl_color_chooser_r, "fl_color_chooser_r");
pragma Inline (fl_color_chooser_r);
function fl_color_chooser_g
(N : in System.Address)
return Interfaces.C.double;
pragma Import (C, fl_color_chooser_g, "fl_color_chooser_g");
pragma Inline (fl_color_chooser_g);
function fl_color_chooser_b
(N : in System.Address)
return Interfaces.C.double;
pragma Import (C, fl_color_chooser_b, "fl_color_chooser_b");
pragma Inline (fl_color_chooser_b);
function fl_color_chooser_rgb
(N : in System.Address;
R, G, B : in Interfaces.C.double)
return Interfaces.C.int;
pragma Import (C, fl_color_chooser_rgb, "fl_color_chooser_rgb");
pragma Inline (fl_color_chooser_rgb);
function fl_color_chooser_hue
(N : in System.Address)
return Interfaces.C.double;
pragma Import (C, fl_color_chooser_hue, "fl_color_chooser_hue");
pragma Inline (fl_color_chooser_hue);
function fl_color_chooser_saturation
(N : in System.Address)
return Interfaces.C.double;
pragma Import (C, fl_color_chooser_saturation, "fl_color_chooser_saturation");
pragma Inline (fl_color_chooser_saturation);
function fl_color_chooser_value
(N : in System.Address)
return Interfaces.C.double;
pragma Import (C, fl_color_chooser_value, "fl_color_chooser_value");
pragma Inline (fl_color_chooser_value);
function fl_color_chooser_hsv
(N : in System.Address;
H, S, V : in Interfaces.C.double)
return Interfaces.C.int;
pragma Import (C, fl_color_chooser_hsv, "fl_color_chooser_hsv");
pragma Inline (fl_color_chooser_hsv);
procedure fl_color_chooser_hsv2rgb
(H, S, V : in Interfaces.C.double;
R, G, B : out Interfaces.C.double);
pragma Import (C, fl_color_chooser_hsv2rgb, "fl_color_chooser_hsv2rgb");
pragma Inline (fl_color_chooser_hsv2rgb);
procedure fl_color_chooser_rgb2hsv
(R, G, B : in Interfaces.C.double;
H, S, V : out Interfaces.C.double);
pragma Import (C, fl_color_chooser_rgb2hsv, "fl_color_chooser_rgb2hsv");
pragma Inline (fl_color_chooser_rgb2hsv);
function fl_color_chooser_get_mode
(N : in System.Address)
return Interfaces.C.int;
pragma Import (C, fl_color_chooser_get_mode, "fl_color_chooser_get_mode");
pragma Inline (fl_color_chooser_get_mode);
procedure fl_color_chooser_set_mode
(N : in System.Address;
M : in Interfaces.C.int);
pragma Import (C, fl_color_chooser_set_mode, "fl_color_chooser_set_mode");
pragma Inline (fl_color_chooser_set_mode);
procedure fl_color_chooser_draw
(W : in System.Address);
pragma Import (C, fl_color_chooser_draw, "fl_color_chooser_draw");
pragma Inline (fl_color_chooser_draw);
function fl_color_chooser_handle
(W : in System.Address;
E : in Interfaces.C.int)
return Interfaces.C.int;
pragma Import (C, fl_color_chooser_handle, "fl_color_chooser_handle");
pragma Inline (fl_color_chooser_handle);
procedure Finalize
(This : in out Color_Chooser) is
begin
if This.Void_Ptr /= System.Null_Address and then
This in Color_Chooser'Class
then
This.Clear;
free_fl_color_chooser (This.Void_Ptr);
This.Void_Ptr := System.Null_Address;
end if;
Finalize (Group (This));
end Finalize;
package body Forge is
function Create
(X, Y, W, H : in Integer;
Text : in String)
return Color_Chooser is
begin
return This : Color_Chooser do
This.Void_Ptr := new_fl_color_chooser
(Interfaces.C.int (X),
Interfaces.C.int (Y),
Interfaces.C.int (W),
Interfaces.C.int (H),
Interfaces.C.To_C (Text));
fl_group_end (This.Void_Ptr);
fl_widget_set_user_data
(This.Void_Ptr,
Widget_Convert.To_Address (This'Unchecked_Access));
color_chooser_set_draw_hook (This.Void_Ptr, Draw_Hook'Address);
color_chooser_set_handle_hook (This.Void_Ptr, Handle_Hook'Address);
end return;
end Create;
end Forge;
function Get_Red
(This : in Color_Chooser)
return Long_Float is
begin
return Long_Float (fl_color_chooser_r (This.Void_Ptr));
end Get_Red;
function Get_Green
(This : in Color_Chooser)
return Long_Float is
begin
return Long_Float (fl_color_chooser_g (This.Void_Ptr));
end Get_Green;
function Get_Blue
(This : in Color_Chooser)
return Long_Float is
begin
return Long_Float (fl_color_chooser_b (This.Void_Ptr));
end Get_Blue;
procedure Set_RGB
(This : in out Color_Chooser;
R, G, B : in Long_Float) is
begin
This.Was_Changed := fl_color_chooser_rgb
(This.Void_Ptr,
Interfaces.C.double (R),
Interfaces.C.double (G),
Interfaces.C.double (B)) /= 0;
end Set_RGB;
function Get_Hue
(This : in Color_Chooser)
return Long_Float is
begin
return Long_Float (fl_color_chooser_hue (This.Void_Ptr));
end Get_Hue;
function Get_Saturation
(This : in Color_Chooser)
return Long_Float is
begin
return Long_Float (fl_color_chooser_saturation (This.Void_Ptr));
end Get_Saturation;
function Get_Value
(This : in Color_Chooser)
return Long_Float is
begin
return Long_Float (fl_color_chooser_value (This.Void_Ptr));
end Get_Value;
procedure Set_HSV
(This : in out Color_Chooser;
H, S, V : in Long_Float) is
begin
This.Was_Changed := fl_color_chooser_hsv
(This.Void_Ptr,
Interfaces.C.double (H),
Interfaces.C.double (S),
Interfaces.C.double (V)) /= 0;
end Set_HSV;
procedure HSV_To_RGB
(H, S, V : in Long_Float;
R, G, B : out Long_Float) is
begin
fl_color_chooser_hsv2rgb
(Interfaces.C.double (H),
Interfaces.C.double (S),
Interfaces.C.double (V),
Interfaces.C.double (R),
Interfaces.C.double (G),
Interfaces.C.double (B));
end HSV_To_RGB;
procedure RGB_To_HSV
(R, G, B : in Long_Float;
H, S, V : out Long_Float) is
begin
fl_color_chooser_rgb2hsv
(Interfaces.C.double (R),
Interfaces.C.double (G),
Interfaces.C.double (B),
Interfaces.C.double (H),
Interfaces.C.double (S),
Interfaces.C.double (V));
end RGB_To_HSV;
function Color_Was_Changed
(This : in Color_Chooser)
return Boolean is
begin
return This.Was_Changed;
end Color_Was_Changed;
procedure Clear_Changed
(This : in out Color_Chooser) is
begin
This.Was_Changed := False;
end Clear_Changed;
function Get_Mode
(This : in Color_Chooser)
return Color_Mode is
begin
return Color_Mode'Val (fl_color_chooser_get_mode (This.Void_Ptr));
end Get_Mode;
procedure Set_Mode
(This : in out Color_Chooser;
To : in Color_Mode) is
begin
fl_color_chooser_set_mode (This.Void_Ptr, Color_Mode'Pos (To));
end Set_Mode;
procedure Draw
(This : in out Color_Chooser) is
begin
fl_color_chooser_draw (This.Void_Ptr);
end Draw;
function Handle
(This : in out Color_Chooser;
Event : in Event_Kind)
return Event_Outcome is
begin
return Event_Outcome'Val
(fl_color_chooser_handle (This.Void_Ptr, Event_Kind'Pos (Event)));
end Handle;
end FLTK.Widgets.Groups.Color_Choosers;
|
procedure main IS
package pack is
function func return integer;
end pack;
package body pack is
function func return integer is
begin
return 1;
end func;
end pack;
begin
null;
exception
when pack.func.error =>
null;
end main;
|
--
-- Copyright (C) 2021 Jeremy Grosser <jeremy@synack.me>
--
-- SPDX-License-Identifier: BSD-3-Clause
--
with Picosystem.LED;
with RP.Clock;
with Console;
with Graphics;
with Sound;
with Game;
with MIDI;
with Ada.Text_IO;
procedure Main is
package PS renames Picosystem;
use type PS.LED.Brightness;
begin
RP.Clock.Initialize (PS.XOSC_Frequency);
RP.Clock.Enable (RP.Clock.PERI);
Console.Initialize;
Ada.Text_IO.New_Line;
Ada.Text_IO.Put_Line ("picosystem");
PS.LED.Initialize;
PS.LED.Set_Color (16#008000#);
PS.LED.Set_Backlight (0);
Sound.Initialize;
Graphics.Initialize;
MIDI.Initialize;
Game.Initialize;
Graphics.HBlank := Game.HBlank'Access;
Graphics.VBlank := Game.VBlank'Access;
-- PS.LED.Set_Color (16#000000#);
-- PS.LED.Set_Backlight ((PS.LED.Brightness'Last / 100) * 70);
loop
-- Graphics.Update;
MIDI.Update;
end loop;
end Main;
|
-- part of OpenGLAda, (c) 2017 Felix Krause
-- released under the terms of the MIT license, see the file "COPYING"
with GL.Low_Level;
with GL.Types.Colors;
with GL.Culling;
package GL.Buffers is
pragma Preelaborate;
use GL.Types;
type Buffer_Bits is record
Depth : Boolean := False;
Accum : Boolean := False;
Stencil : Boolean := False;
Color : Boolean := False;
end record;
subtype Depth is Double range 0.0 .. 1.0;
subtype Stencil_Index is Int;
type Stencil_Action is (Zero, Invert, Keep, Replace,
Increment, Decrement,
Increment_Wrap, Decrement_Wrap);
-- Aux buffer support was dropped with OpenGL 3.
-- this type allows selection of multiple buffers at once
-- (Front => Front_Left and Front_Right and so on)
type Color_Buffer_Selector is (None, Front_Left,
Front_Right, Back_Left, Back_Right,
Front, Back, Left, Right, Front_And_Back);
-- defined here because of following subtype declaration
for Color_Buffer_Selector use (None => 0,
Front_Left => 16#0400#,
Front_Right => 16#0401#,
Back_Left => 16#0402#,
Back_Right => 16#0403#,
Front => 16#0404#,
Back => 16#0405#,
Left => 16#0406#,
Right => 16#0407#,
Front_And_Back => 16#0408#);
for Color_Buffer_Selector'Size use Low_Level.Enum'Size;
subtype Base_Color_Buffer_Selector is Color_Buffer_Selector
range Front .. Front_And_Back;
-- misses Front, Right etc. from above because they may map to multiple
-- buffers.
type Explicit_Color_Buffer_Selector is (None, Front_Left, Front_Right,
Back_Left, Back_Right,
Color_Attachment0,
Color_Attachment1,
Color_Attachment2,
Color_Attachment3,
Color_Attachment4,
Color_Attachment5,
Color_Attachment6,
Color_Attachment7,
Color_Attachment8,
Color_Attachment9,
Color_Attachment10,
Color_Attachment11,
Color_Attachment12,
Color_Attachment13,
Color_Attachment14,
Color_Attachment15);
subtype Draw_Buffer_Index is UInt range 0 .. 15;
type Explicit_Color_Buffer_List is array (Draw_Buffer_Index range <>)
of Explicit_Color_Buffer_Selector;
subtype Single_Face_Selector is Culling.Face_Selector
range Culling.Front .. Culling.Back;
procedure Clear (Bits : Buffer_Bits);
procedure Set_Active_Buffer (Selector : Explicit_Color_Buffer_Selector);
procedure Set_Active_Buffers (List : Explicit_Color_Buffer_List);
procedure Set_Color_Clear_Value (Value : Colors.Color);
function Color_Clear_Value return Colors.Color;
procedure Set_Depth_Clear_Value (Value : Depth);
function Depth_Clear_Value return Depth;
procedure Set_Stencil_Clear_Value (Value : Stencil_Index);
function Stencil_Clear_Value return Stencil_Index;
-- dropped in OpenGL 3
procedure Set_Accum_Clear_Value (Value : Colors.Color);
function Accum_Clear_Value return Colors.Color;
procedure Set_Depth_Function (Func : Compare_Function);
function Depth_Function return Compare_Function;
procedure Depth_Mask (Enabled : Boolean);
function Depth_Mask return Boolean;
procedure Set_Stencil_Function (Func : Compare_Function;
Ref : Int;
Mask : UInt);
procedure Set_Stencil_Function (Face : Culling.Face_Selector;
Func : Compare_Function;
Ref : Int;
Mask : UInt);
function Stencil_Function (Face : Single_Face_Selector) return Compare_Function;
function Stencil_Reference_Value (Face : Single_Face_Selector) return Int;
function Stencil_Value_Mask (Face : Single_Face_Selector) return UInt;
procedure Set_Stencil_Operation (Stencil_Fail : Buffers.Stencil_Action;
Depth_Fail : Buffers.Stencil_Action;
Depth_Pass : Buffers.Stencil_Action);
procedure Set_Stencil_Operation (Face : Culling.Face_Selector;
Stencil_Fail : Buffers.Stencil_Action;
Depth_Fail : Buffers.Stencil_Action;
Depth_Pass : Buffers.Stencil_Action);
function Stencil_Operation_Stencil_Fail (Face : Single_Face_Selector) return Buffers.Stencil_Action;
function Stencil_Operation_Depth_Fail (Face : Single_Face_Selector) return Buffers.Stencil_Action;
function Stencil_Operation_Depth_Pass (Face : Single_Face_Selector) return Buffers.Stencil_Action;
procedure Set_Stencil_Mask (Value : UInt);
procedure Set_Stencil_Mask (Face : Culling.Face_Selector;
Value : UInt);
function Stencil_Mask (Face : Single_Face_Selector) return UInt;
-- The following procedures are available since OpenGL 3.0
-- for one or multiple color buffers
procedure Clear_Color_Buffers (Selector : Base_Color_Buffer_Selector;
Value : Colors.Color);
-- for one specific draw buffer
procedure Clear_Draw_Buffer (Index : Draw_Buffer_Index;
Value : Colors.Color);
procedure Clear_Depth_Buffer (Value : Depth);
procedure Clear_Stencil_Buffer (Value : Stencil_Index);
procedure Clear_Depth_And_Stencil_Buffer (Depth_Value : Depth;
Stencil_Value : Stencil_Index);
private
for Buffer_Bits use record
Depth at 0 range 8 .. 8;
Accum at 0 range 9 .. 9;
Stencil at 0 range 10 .. 10;
Color at 0 range 14 .. 14;
end record;
for Buffer_Bits'Size use Low_Level.Bitfield'Size;
for Stencil_Action use (Zero => 0,
Invert => 16#150A#,
Keep => 16#1E00#,
Replace => 16#1E01#,
Increment => 16#1E02#,
Decrement => 16#1E03#,
Increment_Wrap => 16#8507#,
Decrement_Wrap => 16#8508#);
for Stencil_Action'Size use Low_Level.Enum'Size;
for Explicit_Color_Buffer_Selector use (None => 0,
Front_Left => 16#0400#,
Front_Right => 16#0401#,
Back_Left => 16#0402#,
Back_Right => 16#0403#,
Color_Attachment0 => 16#8CE0#,
Color_Attachment1 => 16#8CE1#,
Color_Attachment2 => 16#8CE2#,
Color_Attachment3 => 16#8CE3#,
Color_Attachment4 => 16#8CE4#,
Color_Attachment5 => 16#8CE5#,
Color_Attachment6 => 16#8CE6#,
Color_Attachment7 => 16#8CE7#,
Color_Attachment8 => 16#8CE8#,
Color_Attachment9 => 16#8CE9#,
Color_Attachment10 => 16#8CEA#,
Color_Attachment11 => 16#8CEB#,
Color_Attachment12 => 16#8CEC#,
Color_Attachment13 => 16#8CED#,
Color_Attachment14 => 16#8CEE#,
Color_Attachment15 => 16#8CEF#);
for Explicit_Color_Buffer_Selector'Size use Low_Level.Enum'Size;
pragma Convention (C, Explicit_Color_Buffer_List);
end GL.Buffers;
|
with SPARKNaCl; use SPARKNaCl;
with SPARKNaCl.Core; use SPARKNaCl.Core;
with SPARKNaCl.Debug; use SPARKNaCl.Debug;
with SPARKNaCl.Secretbox; use SPARKNaCl.Secretbox;
with SPARKNaCl.Stream;
with Ada.Text_IO; use Ada.Text_IO;
procedure Secretbox
is
Firstkey : constant Core.Salsa20_Key :=
Construct ((16#1b#, 16#27#, 16#55#, 16#64#,
16#73#, 16#e9#, 16#85#, 16#d4#,
16#62#, 16#cd#, 16#51#, 16#19#,
16#7a#, 16#9a#, 16#46#, 16#c7#,
16#60#, 16#09#, 16#54#, 16#9e#,
16#ac#, 16#64#, 16#74#, 16#f2#,
16#06#, 16#c4#, 16#ee#, 16#08#,
16#44#, 16#f6#, 16#83#, 16#89#));
Nonce : constant Stream.HSalsa20_Nonce :=
(16#69#, 16#69#, 16#6e#, 16#e9#, 16#55#, 16#b6#, 16#2b#, 16#73#,
16#cd#, 16#62#, 16#bd#, 16#a8#, 16#75#, 16#fc#, 16#73#, 16#d6#,
16#82#, 16#19#, 16#e0#, 16#03#, 16#6b#, 16#7a#, 16#0b#, 16#37#);
M : constant Byte_Seq (0 .. 162) :=
(0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
16#be#, 16#07#, 16#5f#, 16#c5#, 16#3c#, 16#81#, 16#f2#, 16#d5#,
16#cf#, 16#14#, 16#13#, 16#16#, 16#eb#, 16#eb#, 16#0c#, 16#7b#,
16#52#, 16#28#, 16#c5#, 16#2a#, 16#4c#, 16#62#, 16#cb#, 16#d4#,
16#4b#, 16#66#, 16#84#, 16#9b#, 16#64#, 16#24#, 16#4f#, 16#fc#,
16#e5#, 16#ec#, 16#ba#, 16#af#, 16#33#, 16#bd#, 16#75#, 16#1a#,
16#1a#, 16#c7#, 16#28#, 16#d4#, 16#5e#, 16#6c#, 16#61#, 16#29#,
16#6c#, 16#dc#, 16#3c#, 16#01#, 16#23#, 16#35#, 16#61#, 16#f4#,
16#1d#, 16#b6#, 16#6c#, 16#ce#, 16#31#, 16#4a#, 16#db#, 16#31#,
16#0e#, 16#3b#, 16#e8#, 16#25#, 16#0c#, 16#46#, 16#f0#, 16#6d#,
16#ce#, 16#ea#, 16#3a#, 16#7f#, 16#a1#, 16#34#, 16#80#, 16#57#,
16#e2#, 16#f6#, 16#55#, 16#6a#, 16#d6#, 16#b1#, 16#31#, 16#8a#,
16#02#, 16#4a#, 16#83#, 16#8f#, 16#21#, 16#af#, 16#1f#, 16#de#,
16#04#, 16#89#, 16#77#, 16#eb#, 16#48#, 16#f5#, 16#9f#, 16#fd#,
16#49#, 16#24#, 16#ca#, 16#1c#, 16#60#, 16#90#, 16#2e#, 16#52#,
16#f0#, 16#a0#, 16#89#, 16#bc#, 16#76#, 16#89#, 16#70#, 16#40#,
16#e0#, 16#82#, 16#f9#, 16#37#, 16#76#, 16#38#, 16#48#, 16#64#,
16#5e#, 16#07#, 16#05#);
C : Byte_Seq (0 .. 162);
S : Boolean;
begin
Create (C, S, M, Nonce, Firstkey);
Put_Line ("Status is " & S'Img);
DH ("C is", C);
end Secretbox;
|
------------------------------------------------------------------------------
-- AGAR GUI LIBRARY --
-- A G A R . M O U S E --
-- S p e c --
------------------------------------------------------------------------------
with Interfaces;
with Interfaces.C;
with Interfaces.C.Strings;
with Agar.Input_Device;
package Agar.Mouse is
package C renames Interfaces.C;
package CS renames Interfaces.C.Strings;
package INDEV renames Agar.Input_Device;
use type C.int;
use type C.unsigned;
------------------
-- Mouse Button --
------------------
type Mouse_Button is
(NONE,
LEFT,
MIDDLE,
RIGHT,
WHEEL_UP,
WHEEL_DOWN,
X1,
X2,
ANY);
for Mouse_Button use
(NONE => 16#00_00#,
LEFT => 16#00_01#,
MIDDLE => 16#00_02#,
RIGHT => 16#00_03#,
WHEEL_UP => 16#00_04#,
WHEEL_DOWN => 16#00_05#,
X1 => 16#00_06#,
X2 => 16#00_07#,
ANY => 16#00_ff#);
for Mouse_Button'Size use C.unsigned'Size;
-------------------------
-- Mouse Button Action --
-------------------------
type Mouse_Button_Action is
(PRESSED,
RELEASED);
for Mouse_Button_Action use
(PRESSED => 0,
RELEASED => 1);
for Mouse_Button_Action'Size use C.int'Size;
------------------
-- Mouse Device --
------------------
type Mouse_Device is limited record
Super : aliased INDEV.Input_Device; -- [Input_Device -> Mouse]
Button_Count : C.unsigned; -- Button count (or 0)
Button_State : Mouse_Button; -- Last button state
X,Y : C.int; -- Last cursor position
Xrel, Yrel : C.int; -- Last relative motion
end record
with Convention => C;
type Mouse_Device_Access is access all Mouse_Device with Convention => C;
subtype Mouse_Device_not_null_Access is not null Mouse_Device_Access;
--
-- Return the current cursor position and button state.
--
procedure Get_Mouse_State
(Mouse : in Mouse_Device_not_null_Access;
Buttons : out Interfaces.Unsigned_8;
X,Y : out Natural);
--
-- Update the internal mouse state following a motion event.
--
procedure Mouse_Motion_Update
(Mouse : in Mouse_Device_not_null_Access;
X,Y : in Natural);
--
-- Update the internal mouse state following a mouse button event.
--
procedure Mouse_Button_Update
(Mouse : in Mouse_Device_not_null_Access;
Action : in Mouse_Button_Action;
Button : in Mouse_Button);
private
function AG_MouseGetState
(Mouse : Mouse_Device_not_null_Access;
X,Y : access C.int) return Interfaces.Unsigned_8
with Import, Convention => C, Link_Name => "AG_MouseGetState";
procedure AG_MouseMotionUpdate
(Mouse : Mouse_Device_not_null_Access;
X,Y : C.int)
with Import, Convention => C, Link_Name => "AG_MouseMotionUpdate";
procedure AG_MouseButtonUpdate
(Mouse : Mouse_Device_not_null_Access;
Action : Mouse_Button_Action;
Button : C.int)
with Import, Convention => C, Link_Name => "AG_MouseButtonUpdate";
end Agar.Mouse;
|
with Ada.Wide_Wide_Text_IO;
with Ada.Characters.Wide_Wide_Latin_1;
package body Servlets.File is
function "+"
(Text : Wide_Wide_String) return League.Strings.Universal_String
renames League.Strings.To_Universal_String;
----------------------
-- Get_Servlet_Info --
----------------------
overriding function Get_Servlet_Info
(Self : File_Servlet) return League.Strings.Universal_String
is
pragma Unreferenced (Self);
Text : constant Wide_Wide_String :=
"Hello servlet provides WebSocket upgrade responses";
begin
return +Text;
end Get_Servlet_Info;
------------
-- Do_Get --
------------
overriding procedure Do_Get
(Self : in out File_Servlet;
Request : Servlet.HTTP_Requests.HTTP_Servlet_Request'Class;
Response : in out Servlet.HTTP_Responses.HTTP_Servlet_Response'Class)
is
Result : League.Strings.Universal_String;
Input : Ada.Wide_Wide_Text_IO.File_Type;
begin
Ada.Wide_Wide_Text_IO.Open
(Input, Ada.Wide_Wide_Text_IO.In_File, "install/index.html");
while not Ada.Wide_Wide_Text_IO.End_Of_File (Input) loop
Result.Append (Ada.Wide_Wide_Text_IO.Get_Line (Input));
Result.Append (Ada.Characters.Wide_Wide_Latin_1.LF);
end loop;
Ada.Wide_Wide_Text_IO.Close (Input);
Response.Set_Status (Servlet.HTTP_Responses.OK);
Response.Set_Content_Type (+"text/html");
Response.Set_Character_Encoding (+"utf-8");
Response.Get_Output_Stream.Write (Result);
end Do_Get;
-----------------
-- Instantiate --
-----------------
overriding function Instantiate
(Parameters : not null access Servlet.Generic_Servlets
.Instantiation_Parameters'
Class)
return File_Servlet
is
pragma Unreferenced (Parameters);
begin
return (Servlet.HTTP_Servlets.HTTP_Servlet with null record);
end Instantiate;
end Servlets.File;
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.