content
stringlengths 23
1.05M
|
|---|
------------------------------------------------------------------------------
-- Copyright (c) 2013-2014, Natacha Porté --
-- --
-- Permission to use, copy, modify, and 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. --
------------------------------------------------------------------------------
------------------------------------------------------------------------------
-- Natools.Reference_Tests is a test suite for Natools.References --
-- reference-counted object holder. --
-- Note that the task-safety test is quite long and often reports success --
-- on task-unsafe code when run on a single core. For these reasons, it is --
-- not used by All_Tests. --
------------------------------------------------------------------------------
with Natools.Tests;
private with Ada.Finalization;
private with GNAT.Debug_Pools;
private with Natools.References;
private with System.Storage_Pools;
package Natools.Reference_Tests is
package NT renames Natools.Tests;
procedure All_Tests (Report : in out NT.Reporter'Class);
-- All tests except Test_Task_Safety (see the Note above)
procedure Test_Data_Access (Report : in out NT.Reporter'Class);
procedure Test_Double_Finalize (Report : in out NT.Reporter'Class);
procedure Test_Implicit_Dereference (Report : in out NT.Reporter'Class);
procedure Test_Instance_Counts (Report : in out NT.Reporter'Class);
procedure Test_Reference_Counts (Report : in out NT.Reporter'Class);
procedure Test_Reference_Tests (Report : in out NT.Reporter'Class);
procedure Test_Task_Safety (Report : in out NT.Reporter'Class);
private
Instance_Count : Integer := 0;
type Counter is new Ada.Finalization.Limited_Controlled with record
Instance_Number : Natural := 0;
end record;
function Factory return Counter;
overriding procedure Initialize (Object : in out Counter);
overriding procedure Finalize (Object : in out Counter);
Pool : GNAT.Debug_Pools.Debug_Pool;
package Refs is new Natools.References
(Counter,
System.Storage_Pools.Root_Storage_Pool'Class (Pool),
System.Storage_Pools.Root_Storage_Pool'Class (Pool));
end Natools.Reference_Tests;
|
-------------------------------------------------------------------------------
-- Copyright (c) 2016 Daniel King
--
-- 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 Interfaces; use Interfaces;
with STM32.GPIO;
with STM32.RCC;
package body EVB1000.LED
with SPARK_Mode => Off
is
LED_Pin_Mapping : constant array (LED_Number) of Natural :=
(1 => 8,
2 => 6,
3 => 9,
4 => 7);
LED_On_Table : constant array (LED_Number, Boolean) of Unsigned_16
:= (1 => (True => 16#0100#,
False => 0),
2 => (True => 16#0040#,
False => 0),
3 => (True => 16#0200#,
False => 0),
4 => (True => 16#0080#,
False => 0));
LED_Off_Table : constant array (LED_Number, Boolean) of Unsigned_16
:= (1 => (True => 0,
False => 16#0100#),
2 => (True => 0,
False => 16#0040#),
3 => (True => 0,
False => 16#0200#),
4 => (True => 0,
False => 16#0080#));
LED_BSRR_Table : constant
array (LED_Number, Boolean)
of STM32.GPIO.BSRR_Register :=
(1 => (True => (BS => (As_Array => False,
Val => 16#0100#),
BR => (As_Array => False,
Val => 0)),
False => (BS => (As_Array => False,
Val => 0),
BR => (As_Array => False,
Val => 16#0100#))),
2 => (True => (BS => (As_Array => False,
Val => 16#0040#),
BR => (As_Array => False,
Val => 0)),
False => (BS => (As_Array => False,
Val => 0),
BR => (As_Array => False,
Val => 16#0040#))),
3 => (True => (BS => (As_Array => False,
Val => 16#0200#),
BR => (As_Array => False,
Val => 0)),
False => (BS => (As_Array => False,
Val => 0),
BR => (As_Array => False,
Val => 16#0200#))),
4 => (True => (BS => (As_Array => False,
Val => 16#0080#),
BR => (As_Array => False,
Val => 0)),
False => (BS => (As_Array => False,
Val => 0),
BR => (As_Array => False,
Val => 16#0080#))));
procedure Set_LED(LED : in LED_Number;
On : in Boolean)
is
begin
STM32.GPIO.GPIOC_Periph.BSRR := LED_BSRR_Table (LED, On);
end Set_LED;
procedure Set_LEDs(LEDs : in LED_Array)
is
begin
STM32.GPIO.GPIOC_Periph.BSRR :=
(BS => (As_Array => False,
Val => (LED_On_Table (1, LEDs (1))
or LED_On_Table (2, LEDs (2))
or LED_On_Table (3, LEDs (3))
or LED_On_Table (4, LEDs (4)))),
BR => (As_Array => False,
Val => (LED_Off_Table (1, LEDs (1))
or LED_Off_Table (2, LEDs (2))
or LED_Off_Table (3, LEDs (3))
or LED_Off_Table (4, LEDs (4)))));
end Set_LEDs;
procedure Toggle_LED (LED : in LED_Number)
is
use type STM32.Bit;
ODR : constant STM32.GPIO.ODR_Field := STM32.GPIO.GPIOC_Periph.ODR.ODR;
begin
STM32.GPIO.GPIOC_Periph.BSRR := LED_BSRR_Table
(LED, ODR.Arr (LED_Pin_Mapping (LED)) = 0);
end Toggle_LED;
begin
-- Enable peripheral clock
STM32.RCC.RCC_Periph.APB2ENR.IOPCEN := 1;
-- Configure GPIOs (output 50 MHz, push-pull)
declare
CRL : STM32.GPIO.CRL_Register;
CRH : STM32.GPIO.CRH_Register;
begin
CRL := STM32.GPIO.GPIOC_Periph.CRL;
CRH := STM32.GPIO.GPIOC_Periph.CRH;
CRL.MODE6 := 2#11#;
CRL.MODE7 := 2#11#;
CRH.MODE8 := 2#11#;
CRH.MODE9 := 2#11#;
CRL.CNF6 := 2#00#;
CRL.CNF7 := 2#00#;
CRH.CNF8 := 2#00#;
CRH.CNF9 := 2#00#;
STM32.GPIO.GPIOC_Periph.CRL := CRL;
STM32.GPIO.GPIOC_Periph.CRH := CRH;
end;
Set_LEDs ( (others => False) );
end EVB1000.LED;
|
------------------------------------------------------------------------------
-- AGAR GUI LIBRARY --
-- A G A R . T E X T --
-- B o d y --
-- --
-- Copyright (c) 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. --
------------------------------------------------------------------------------
package body Agar.Text is
--
-- Initialize the font engine.
--
function Init_Text_Subsystem return Boolean is
begin
return 0 = AG_InitTextSubsystem;
end;
--
-- Release all resources allocated by the font engine.
--
procedure Destroy_Text_Subsystem is
begin
AG_DestroyTextSubsystem;
end;
--
-- Set the default font from a "<Face>:<Size>:<Flags>" string.
--
procedure Set_Default_Font (Spec : in String)
is
Ch_Spec : aliased C.char_array := C.To_C(Spec);
begin
AG_TextParseFontSpec
(Spec => CS.To_Chars_Ptr(Ch_Spec'Unchecked_Access));
end;
--
-- Load (or fetch from cache) a font.
--
function Fetch_Font
(Family : in String := "_agFontVera";
Size : in AG_Font_Points := AG_Font_Points(12);
Bold : in Boolean := False;
Italic : in Boolean := False;
Underlined : in Boolean := False;
Uppercase : in Boolean := False;
Semibold : in Boolean := False;
Upright_Italic : in Boolean := False;
Semicondensed : in Boolean := False;
Condensed : in Boolean := False) return Font_Access
is
Ch_Family : aliased C.char_array := C.To_C(Family);
C_Size : aliased AG_Font_Points := Size;
Flags : aliased C.unsigned := 0;
begin
if Bold then Flags := Flags or FONT_BOLD; end if;
if Italic then Flags := Flags or FONT_ITALIC; end if;
if Underlined then Flags := Flags or FONT_UNDERLINE; end if;
if Uppercase then Flags := Flags or FONT_UPPERCASE; end if;
if Semibold then Flags := Flags or FONT_SEMIBOLD; end if;
if Upright_Italic then Flags := Flags or FONT_UPRIGHT_ITALIC; end if;
if Semicondensed then Flags := Flags or FONT_SEMICONDENSED; end if;
if Condensed then Flags := Flags or FONT_CONDENSED; end if;
return AG_FetchFont
(Family => CS.To_Chars_Ptr(Ch_Family'Unchecked_Access),
Size => C_Size'Unchecked_Access,
Flags => Flags);
end;
--
-- Set the current font to the specified family+size+style (or just size).
--
procedure Text_Set_Font
(Family : in String := "_agFontVera";
Size : in AG_Font_Points := AG_Font_Points(12);
Bold : in Boolean := False;
Italic : in Boolean := False;
Underlined : in Boolean := False;
Uppercase : in Boolean := False;
Semibold : in Boolean := False;
Upright_Italic : in Boolean := False;
Semicondensed : in Boolean := False;
Condensed : in Boolean := False)
is
Ch_Family : aliased C.char_array := C.To_C(Family);
C_Size : aliased AG_Font_Points := Size;
Flags : aliased C.unsigned := 0;
Result : aliased Font_Access;
begin
if Bold then Flags := Flags or FONT_BOLD; end if;
if Italic then Flags := Flags or FONT_ITALIC; end if;
if Underlined then Flags := Flags or FONT_UNDERLINE; end if;
if Uppercase then Flags := Flags or FONT_UPPERCASE; end if;
if Semibold then Flags := Flags or FONT_SEMIBOLD; end if;
if Upright_Italic then Flags := Flags or FONT_UPRIGHT_ITALIC; end if;
if Semicondensed then Flags := Flags or FONT_SEMICONDENSED; end if;
if Condensed then Flags := Flags or FONT_CONDENSED; end if;
Result := AG_TextFontLookup
(Family => CS.To_Chars_Ptr(Ch_Family'Unchecked_Access),
Size => C_Size'Unchecked_Access,
Flags => Flags);
end;
--
-- Set the current font to a given % of the current font size.
--
procedure Text_Set_Font (Percent : in Natural)
is
Result : aliased Font_Access;
begin
Result := AG_TextFontPct
(Percent => C.int(Percent));
end;
--
-- Return the expected size in pixels of rendered (UTF-8) text.
--
procedure Size_Text
(Text : in String;
W,H : out Natural)
is
Ch_Text : aliased C.char_array := C.To_C(Text);
C_W, C_H : aliased C.int;
begin
AG_TextSize
(Text => CS.To_Chars_Ptr(Ch_Text'Unchecked_Access),
W => C_W'Access,
H => C_H'Access);
W := Natural(C_W);
H := Natural(C_H);
end;
--
-- Return the expected size in pixels of rendered (UTF-8) text,
-- and the line count.
--
procedure Size_Text
(Text : in String;
W,H : out Natural;
Line_Count : out Natural)
is
Ch_Text : aliased C.char_array := C.To_C(Text);
C_W, C_H : aliased C.int;
C_NLines : aliased C.unsigned;
begin
AG_TextSizeMulti
(Text => CS.To_Chars_Ptr(Ch_Text'Unchecked_Access),
W => C_W'Access,
H => C_H'Access,
W_Lines => null,
N_Lines => C_NLines'Access);
W := Natural(C_W);
H := Natural(C_H);
Line_Count := Natural(C_NLines);
end;
--
-- Return the expected size in pixels of rendered (UTF-8) text,
-- and the line count, and the width of each line.
--
procedure Size_Text
(Text : in String;
W,H : out Natural;
Line_Count : out Natural;
Line_Widths : out Text_Line_Widths)
is
use Line_Width_Array;
Ch_Text : aliased C.char_array := C.To_C(Text);
C_W, C_H : aliased C.int;
C_WLines : aliased Line_Width_Array.Pointer;
C_NLines : aliased C.unsigned;
begin
AG_TextSizeMulti
(Text => CS.To_Chars_Ptr(Ch_Text'Unchecked_Access),
W => C_W'Access,
H => C_H'Access,
W_Lines => C_WLines,
N_Lines => C_NLines'Access);
W := Natural(C_W);
H := Natural(C_H);
Line_Count := Natural(C_NLines);
Line_Widths.Clear;
for Index in 1 .. Line_Count loop
declare
Element : Natural;
begin
if C_WLines /= null then
Element := Natural(C_WLines.all);
Line_Widths.Append (Element);
end if;
end;
Increment (C_WLines);
end loop;
end;
--
-- Display an info, warning or error message.
--
procedure Text_Msg
(Title : in AG_Text_Message_Title := INFO;
Text : in String)
is
Ch_Text : aliased C.char_array := C.To_C(Text);
begin
AG_TextMsgS
(Title => Title,
Text => CS.To_Chars_Ptr(Ch_Text'Unchecked_Access));
end;
--
-- Display an info, warning or error message (for a # of milliseconds).
--
#if AG_TIMERS
procedure Text_Msg
(Title : in AG_Text_Message_Title := INFO;
Text : in String;
Time : in Natural := 2000)
is
Ch_Text : aliased C.char_array := C.To_C(Text);
begin
AG_TextTmsgS
(Title => Title,
Time => Unsigned_32(Time),
Text => CS.To_Chars_Ptr(Ch_Text'Unchecked_Access));
end;
#end if;
--
-- Display an info message (with a "Don't tell me again" option
-- tied to the Config setting named by Key).
--
procedure Text_Info (Key, Text : in String)
is
Ch_Key : aliased C.char_array := C.To_C(Key);
Ch_Text : aliased C.char_array := C.To_C(Text);
begin
AG_TextInfoS
(Key => CS.To_Chars_Ptr(Ch_Key'Unchecked_Access),
Text => CS.To_Chars_Ptr(Ch_Text'Unchecked_Access));
end;
--
-- Display a warning message (with a "Don't tell me again" option
-- tied to the Config setting named by Key).
--
procedure Text_Warning (Key, Text : in String)
is
Ch_Key : aliased C.char_array := C.To_C(Key);
Ch_Text : aliased C.char_array := C.To_C(Text);
begin
AG_TextWarningS
(Key => CS.To_Chars_Ptr(Ch_Key'Unchecked_Access),
Text => CS.To_Chars_Ptr(Ch_Text'Unchecked_Access));
end;
--
-- Display an error message alert.
--
procedure Text_Error (Text : in String)
is
Ch_Text : aliased C.char_array := C.To_C(Text);
begin
AG_TextErrorS
(Text => CS.To_Chars_Ptr(Ch_Text'Unchecked_Access));
end;
--
-- Calculate the X,Y offsets required to justify and vertically-align
-- a text surface of a given size within a given area of pixels.
--
procedure Text_Align
(W_Area, H_Area : in Natural;
W_Text, H_Text : in Natural;
L_Pad, R_Pad : in Natural := 0;
T_Pad, B_Pad : in Natural := 0;
Justify : in AG_Text_Justify := CENTER;
Valign : in AG_Text_Valign := MIDDLE;
X,Y : out Integer)
is
C_X, C_Y : aliased C.int;
begin
AG_TextAlign
(X => C_X'Access,
Y => C_Y'Access,
W_Area => C.int(W_Area),
H_Area => C.int(H_Area),
W_Text => C.int(W_Text),
H_Text => C.int(H_Text),
L_Pad => C.int(L_Pad),
R_Pad => C.int(R_Pad),
T_Pad => C.int(T_Pad),
B_Pad => C.int(B_Pad),
Justify => Justify,
Valign => Valign);
X := Integer(C_X);
Y := Integer(C_Y);
end;
--
-- Calculate the X offset required to justify rendered text in an area.
--
function Text_Justify (W_Area, W_Text : in Natural) return Integer
is
Result : C.int;
begin
Result := AG_TextJustifyOffset
(W_Area => C.int(W_Area),
W_Text => C.int(W_Text));
return Integer(Result);
end;
--
-- Calculate the Y offset required to vertically align rendered text
-- in an area.
--
function Text_Valign (H_Area, H_Text : in Natural) return Integer
is
Result : C.int;
begin
Result := AG_TextValignOffset
(H_Area => C.int(H_Area),
H_Text => C.int(H_Text));
return Integer(Result);
end;
--
-- Set State Attribute: Tab Width (in pixels).
--
procedure Text_Set_Tab_Width (Width : Natural) is
begin
AG_TextTabWidth
(Pixels => C.int(Width));
end;
--
-- Render text to a new surface (UTF-8).
--
function Text_Render
(Text : in String) return SU.Surface_not_null_Access
is
Ch_Text : aliased C.char_array := C.To_C(Text);
begin
return AG_TextRender
(Text => CS.To_Chars_Ptr(Ch_Text'Unchecked_Access));
end;
--
-- Render text and blit it to an existing surface (UTF-8).
--
procedure Text_Render
(Text : in String;
Surface : in SU.Surface_not_null_Access;
X,Y : in Natural := 0)
is
Ch_Text : aliased C.char_array := C.To_C(Text);
Tmp_Surface : constant SU.Surface_not_null_Access := AG_TextRender
(Text => CS.To_Chars_Ptr(Ch_Text'Unchecked_Access));
begin
SU.Blit_Surface
(Source => Tmp_Surface,
Target => Surface,
Dst_X => X,
Dst_Y => Y);
SU.Free_Surface
(Surface => Tmp_Surface);
end;
--
-- Render text and blit it to an existing surface (UCS-4 internal).
--
procedure Text_Render
(Text : in AG_Char_not_null_Access;
Surface : in SU.Surface_not_null_Access;
X,Y : in Natural := 0)
is
Text_State : aliased AG_Text_State;
Tmp_Surface : SU.Surface_Access;
begin
Copy_Text_State(Text_State'Unchecked_Access);
Tmp_Surface := Text_Render
(Text => Text,
Font => Text_State.Font,
Color_BG => Text_State.Color_BG'Unchecked_Access,
Color => Text_State.Color'Unchecked_Access);
SU.Blit_Surface
(Source => Tmp_Surface,
Target => Surface,
Dst_X => X,
Dst_Y => Y);
SU.Free_Surface
(Surface => Tmp_Surface);
end;
end Agar.Text;
|
with Ada.Containers.Indefinite_Vectors, Ada.Text_IO;
procedure Here_Doc is
package String_Vec is new Ada.Containers.Indefinite_Vectors
(Index_Type => Positive,
Element_Type => String);
use type String_Vec.Vector;
Document: String_Vec.Vector := String_Vec.Empty_Vector
& "This is a vector of strings with the following properties:"
& " - indention is preserved, and"
& " - a quotation mark '""' must be ""escaped"" by a double-quote '""""'.";
begin
Document := Document & "Have fun!";
for I in Document.First_Index .. Document.Last_Index loop
Ada.Text_IO.Put_Line(Document.Element(I));
end loop;
end Here_Doc;
|
-- PR middle-end/56474
-- Reported by Pavel Zhukov <pavel@zhukoff.net>
-- { dg-do compile }
with Ada.Streams;
package Array3 is
use type Ada.Streams.Stream_Element_Offset;
type Vector (Size : Ada.Streams.Stream_Element_Offset) is record
Value : Ada.Streams.Stream_Element_Array (0 .. Size);
end record;
Empty_Vector : Vector (-1);
end Array3;
|
with HW.GFX.GMA.Config;
private package HW.GFX.GMA.GMCH is
GMCH_PORT_PIPE_SELECT_SHIFT : constant := 30;
GMCH_PORT_PIPE_SELECT_MASK : constant := 1 * 2 ** 30;
type GMCH_PORT_PIPE_SELECT_Array is array (Pipe_Index) of Word32;
GMCH_PORT_PIPE_SELECT : constant GMCH_PORT_PIPE_SELECT_Array :=
(Primary => 0 * 2 ** GMCH_PORT_PIPE_SELECT_SHIFT,
Secondary => 1 * 2 ** GMCH_PORT_PIPE_SELECT_SHIFT,
Tertiary => 0);
end HW.GFX.GMA.GMCH;
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- A U N I T . A S S E R T I O N S --
-- --
-- S p e c --
-- --
-- --
-- Copyright (C) 2000-2011, AdaCore --
-- --
-- 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 is maintained by AdaCore (http://www.adacore.com) --
-- --
------------------------------------------------------------------------------
-- <description>
-- This package provides the Assert methods used by the user to verify test
-- results.
-- Those methods are used to report errors within AUnit tests when a result
-- does not match an expected value.
-- </description>
with GNAT.Source_Info;
with AUnit.Tests;
with AUnit.Test_Results;
with Ada_Containers.AUnit_Lists;
package AUnit.Assertions is
type Throwing_Exception_Proc is access procedure;
procedure Assert
(Condition : Boolean;
Message : String;
Source : String := GNAT.Source_Info.File;
Line : Natural := GNAT.Source_Info.Line);
-- Test "Condition" and record "Message" if false.
-- If the condition is false, an exception is then raised and the running
-- test is aborted.
function Assert
(Condition : Boolean;
Message : String;
Source : String := GNAT.Source_Info.File;
Line : Natural := GNAT.Source_Info.Line) return Boolean;
-- Functional version to allow the calling routine to decide whether to
-- continue or abandon the execution.
-----------------------
-- Simple assertions --
-----------------------
-- The following subprograms provide specialized version of Assert
-- to compare simple types. In case of failure, the error message will
-- contain both the expected and actual values.
procedure Assert
(Actual : String;
Expected : String;
Message : String;
Source : String := GNAT.Source_Info.File;
Line : Natural := GNAT.Source_Info.Line);
-- Specialized versions of Assert, they call the general version that
-- takes a Condition as a parameter
procedure Assert_Exception
(Proc : Throwing_Exception_Proc;
Message : String;
Source : String := GNAT.Source_Info.File;
Line : Natural := GNAT.Source_Info.Line);
-- Test that Proc throws an exception and record "Message" if not.
------------------------------------------------------------
-- The following declarations are for internal use only --
------------------------------------------------------------
Assertion_Error : exception;
-- For run-time libraries that support exception handling, raised when an
-- assertion fails in order to abandon execution of a test routine.
type Test is abstract new AUnit.Tests.Test with private;
-- Test is used as root type for all Test cases, but also for Test fixtures
-- This allows easy access to all Assert procedures from user tests.
type Test_Access is access all Test'Class;
procedure Init_Test (T : in out Test);
-- Init a new test
procedure Clear_Failures (T : Test);
-- Clear all failures related to T
function Has_Failures (T : Test) return Boolean;
-- The number of failures reported by test
type Failure_Iter is private;
-- Iterator used to retrieve failures.
function First_Failure (T : Test) return Failure_Iter;
function Has_Failure (I : Failure_Iter) return Boolean;
function Get_Failure
(I : Failure_Iter) return AUnit.Test_Results.Test_Failure;
procedure Next (I : in out Failure_Iter);
-- Failures list handling
-- The following is used for the non-dispatching Assert methods.
-- This uses global variables, and thus is incompatible with multitasking.
function Current_Test return Test_Access;
procedure Set_Current_Test (T : Test_Access);
procedure Copy_Id (From : Test'Class; To : in out Test'Class);
-- Copy From's Id to To so that failures reported via To are identified as
-- belonging to From.
private
use AUnit.Test_Results;
-- We can't set the results directly within the test as the result list is
-- limited and we don't want Test to be limited.
-- Instead, we initialize tests with a unique id that we use when putting
-- a new error in this global list.
type Test_Id is new Natural;
Null_Id : constant Test_Id := 0;
type Failure_Elt is record
Failure : Test_Failure;
Id : Test_Id := Null_Id;
end record;
package Failure_Lists is
new Ada_Containers.AUnit_Lists (Failure_Elt);
-- Container for failed assertion messages per routine
type Failure_Iter is new Failure_Lists.Cursor;
type Test is abstract new AUnit.Tests.Test with record
Id : Test_Id := Null_Id;
end record;
end AUnit.Assertions;
|
with Memory; use Memory;
-- A function to simplify memory subsystems.
function Simplify_Memory(mem : Memory_Pointer) return Memory_Pointer;
|
-- Copyright (C) 2019 Thierry Rascle <thierr26@free.fr>
-- MIT license. Please refer to the LICENSE file.
generic
type Parent is abstract new Test_Event_Base with private;
package Apsepp.Test_Event_Class.Generic_Exception_Mixin is
type Child_W_Exception is new Parent with private
with Type_Invariant'Class =>
Child_W_Exception.Exception_Access = null
or else
(
Exception_Identity (Child_W_Exception.Exception_Access.all)
/=
Null_Id
);
overriding
procedure Set (Obj : in out Child_W_Exception; Data : Test_Event_Data);
overriding
procedure Clean_Up (Obj : in out Child_W_Exception);
overriding
function Exception_Access
(Obj : Child_W_Exception) return Exception_Occurrence_Access;
overriding
procedure Free_Exception (Obj : in out Child_W_Exception);
private
type Child_W_Exception is new Parent with record
E : Exception_Occurrence_Access;
end record;
end Apsepp.Test_Event_Class.Generic_Exception_Mixin;
|
------------------------------------------------------------------------------
-- --
-- GNAT ncurses Binding --
-- --
-- Terminal_Interface.Curses.Forms.Field_Types.Enumeration --
-- --
-- S P E C --
-- --
------------------------------------------------------------------------------
-- Copyright (c) 1998-2003,2009 Free Software Foundation, Inc. --
-- --
-- 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, distribute with modifications, 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 ABOVE 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. --
-- --
-- Except as contained in this notice, the name(s) of the above copyright --
-- holders shall not be used in advertising or otherwise to promote the --
-- sale, use or other dealings in this Software without prior written --
-- authorization. --
------------------------------------------------------------------------------
-- Author: Juergen Pfeifer, 1996
-- Version Control:
-- $Revision: 1.12 $
-- Binding Version 01.00
------------------------------------------------------------------------------
with Interfaces.C.Strings;
package Terminal_Interface.Curses.Forms.Field_Types.Enumeration is
pragma Preelaborate
(Terminal_Interface.Curses.Forms.Field_Types.Enumeration);
type String_Access is access String;
-- Type_Set is used by the child package Ada
type Type_Set is (Lower_Case, Upper_Case, Mixed_Case);
type Enum_Array is array (Positive range <>)
of String_Access;
type Enumeration_Info (C : Positive) is
record
Names : Enum_Array (1 .. C);
Case_Sensitive : Boolean := False;
Match_Must_Be_Unique : Boolean := False;
end record;
type Enumeration_Field is new Field_Type with private;
function Create (Info : Enumeration_Info;
Auto_Release_Names : Boolean := False)
return Enumeration_Field;
-- Make an fieldtype from the info. Enumerations are special, because
-- they normally don't copy the enum values into a private store, so
-- we have to care for the lifetime of the info we provide.
-- The Auto_Release_Names flag may be used to automatically releases
-- the strings in the Names array of the Enumeration_Info.
function Make_Enumeration_Type (Info : Enumeration_Info;
Auto_Release_Names : Boolean := False)
return Enumeration_Field renames Create;
procedure Release (Enum : in out Enumeration_Field);
-- But we may want to release the field to release the memory allocated
-- by it internally. After that the Enumeration field is no longer usable.
-- The next type defintions are all ncurses extensions. They are typically
-- not available in other curses implementations.
procedure Set_Field_Type (Fld : Field;
Typ : Enumeration_Field);
pragma Inline (Set_Field_Type);
private
type CPA_Access is access Interfaces.C.Strings.chars_ptr_array;
type Enumeration_Field is new Field_Type with
record
Case_Sensitive : Boolean := False;
Match_Must_Be_Unique : Boolean := False;
Arr : CPA_Access := null;
end record;
end Terminal_Interface.Curses.Forms.Field_Types.Enumeration;
|
with Limited_With2;
package Limited_With2_Pkg2 is
type Rec3 is record
F : Limited_With2.Rec1;
end record;
end Limited_With2_Pkg2;
|
-----------------------------------------------------------------------
-- util-http -- HTTP Utility Library
-- Copyright (C) 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.
-----------------------------------------------------------------------
with Util.Strings;
package body Util.Http is
-- Sets a header with the given name and date-value.
-- The date is specified in terms of milliseconds since the epoch.
-- If the header had already been set, the new value overwrites the previous one.
-- The containsHeader method can be used to test for the presence of a header
-- before setting its value.
procedure Set_Date_Header (Request : in out Abstract_Message'Class;
Name : in String;
Date : in Ada.Calendar.Time) is
begin
null;
end Set_Date_Header;
-- Adds a header with the given name and date-value. The date is specified
-- in terms of milliseconds since the epoch. This method allows response headers
-- to have multiple values.
procedure Add_Date_Header (Request : in out Abstract_Message'Class;
Name : in String;
Date : in Ada.Calendar.Time) is
begin
null;
end Add_Date_Header;
-- ------------------------------
-- Sets a header with the given name and integer value.
-- If the header had already been set, the new value overwrites the previous one.
-- The containsHeader method can be used to test for the presence of a header
-- before setting its value.
-- ------------------------------
procedure Set_Int_Header (Request : in out Abstract_Message'Class;
Name : in String;
Value : in Integer) is
begin
Request.Set_Header (Name, Util.Strings.Image (Value));
end Set_Int_Header;
-- ------------------------------
-- Adds a header with the given name and integer value. This method
-- allows headers to have multiple values.
-- ------------------------------
procedure Add_Int_Header (Request : in out Abstract_Message'Class;
Name : in String;
Value : in Integer) is
begin
Request.Add_Header (Name, Util.Strings.Image (Value));
end Add_Int_Header;
end Util.Http;
|
------------------------------------------------------------------------------
-- --
-- GNAT RUN-TIME COMPONENTS --
-- --
-- S Y S T E M . B I T F I E L D _ U T I L S --
-- --
-- B o d y --
-- --
-- Copyright (C) 2019-2020, 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. --
-- --
-- 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/>. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
package body System.Bitfield_Utils is
-- ???
--
-- This code does not yet work for overlapping bit fields. We need to copy
-- backwards in some cases (i.e. from higher to lower bit addresses).
-- Alternatively, we could avoid calling this if Forwards_OK is False.
--
-- ???
package body G is
Val_Bytes : constant Address := Address (Val'Size / Storage_Unit);
-- A Val_2 can cross a memory page boundary (e.g. an 8-byte Val_2 that
-- starts 4 bytes before the end of a page). If the bit field also
-- crosses that boundary, then the second page is known to exist, and we
-- can safely load or store the Val_2. On the other hand, if the bit
-- field is entirely within the first half of the Val_2, then it is
-- possible (albeit highly unlikely) that the second page does not
-- exist, so we must load or store only the first half of the Val_2.
-- Get_Val_2 and Set_Val_2 take care of all this.
function Get_Val_2
(Src_Address : Address;
Src_Offset : Bit_Offset;
Size : Small_Size)
return Val_2;
-- Get the Val_2, taking care to only load the first half when
-- necessary.
procedure Set_Val_2
(Dest_Address : Address;
Dest_Offset : Bit_Offset;
V : Val_2;
Size : Small_Size);
-- Set the Val_2, taking care to only store the first half when
-- necessary.
-- Get_Bitfield and Set_Bitfield are helper functions that get/set small
-- bit fields -- the value fits in Val, and the bit field is placed
-- starting at some offset within the first half of a Val_2.
-- Copy_Bitfield, on the other hand, supports arbitrarily large bit
-- fields. All operations require bit offsets to point within the first
-- Val pointed to by the address.
function Get_Bitfield
(Src : Val_2; Src_Offset : Bit_Offset; Size : Small_Size)
return Val;
-- Returns the bit field in Src starting at Src_Offset, of the given
-- Size. If Size < Small_Size'Last, then high order bits are zero.
function Set_Bitfield
(Src_Value : Val;
Dest : Val_2;
Dest_Offset : Bit_Offset;
Size : Small_Size)
return Val_2;
-- The bit field in Dest starting at Dest_Offset, of the given Size, is
-- set to Src_Value. Src_Value must have high order bits (Size and
-- above) zero. The result is returned as the function result.
procedure Set_Bitfield
(Src_Value : Val;
Dest_Address : Address;
Dest_Offset : Bit_Offset;
Size : Small_Size);
-- This version takes the bit address and size of the destination.
procedure Copy_Small_Bitfield
(Src_Address : Address;
Src_Offset : Bit_Offset;
Dest_Address : Address;
Dest_Offset : Bit_Offset;
Size : Small_Size);
-- Copy_Bitfield in the case where Size <= Val'Size.
-- The Address values must be aligned as for Val and Val_2.
-- This works for overlapping bit fields.
procedure Copy_Large_Bitfield
(Src_Address : Address;
Src_Offset : Bit_Offset;
Dest_Address : Address;
Dest_Offset : Bit_Offset;
Size : Bit_Size);
-- Copy_Bitfield in the case where Size > Val'Size.
-- The Address values must be aligned as for Val and Val_2.
-- This works for overlapping bit fields only if the source
-- bit address is greater than or equal to the destination
-- bit address, because it copies forward (from lower to higher
-- bit addresses).
function Get_Val_2
(Src_Address : Address;
Src_Offset : Bit_Offset;
Size : Small_Size)
return Val_2 is
begin
pragma Assert (Src_Address mod Val'Alignment = 0);
-- Bit field fits in first half; fetch just one Val. On little
-- endian, we want that in the low half, but on big endian, we
-- want it in the high half.
if Src_Offset + Size <= Val'Size then
declare
Result : aliased constant Val with
Import, Address => Src_Address;
begin
return (case Endian is
when Little => Val_2 (Result),
when Big => Shift_Left (Val_2 (Result), Val'Size));
end;
-- Bit field crosses into the second half, so it's safe to fetch the
-- whole Val_2.
else
declare
Result : aliased constant Val_2 with
Import, Address => Src_Address;
begin
return Result;
end;
end if;
end Get_Val_2;
procedure Set_Val_2
(Dest_Address : Address;
Dest_Offset : Bit_Offset;
V : Val_2;
Size : Small_Size) is
begin
pragma Assert (Dest_Address mod Val'Alignment = 0);
-- Comments in Get_Val_2 apply, except we're storing instead of
-- fetching.
if Dest_Offset + Size <= Val'Size then
declare
Dest : aliased Val with Import, Address => Dest_Address;
begin
Dest := (case Endian is
when Little => Val'Mod (V),
when Big => Val (Shift_Right (V, Val'Size)));
end;
else
declare
Dest : aliased Val_2 with Import, Address => Dest_Address;
begin
Dest := V;
end;
end if;
end Set_Val_2;
function Get_Bitfield
(Src : Val_2; Src_Offset : Bit_Offset; Size : Small_Size)
return Val
is
L_Shift_Amount : constant Natural :=
(case Endian is
when Little => Val_2'Size - (Src_Offset + Size),
when Big => Src_Offset);
Temp1 : constant Val_2 :=
Shift_Left (Src, L_Shift_Amount);
Temp2 : constant Val_2 :=
Shift_Right (Temp1, Val_2'Size - Size);
begin
return Val (Temp2);
end Get_Bitfield;
function Set_Bitfield
(Src_Value : Val;
Dest : Val_2;
Dest_Offset : Bit_Offset;
Size : Small_Size)
return Val_2
is
pragma Assert (Size = Val'Size or else Src_Value < 2**Size);
L_Shift_Amount : constant Natural :=
(case Endian is
when Little => Dest_Offset,
when Big => Val_2'Size - (Dest_Offset + Size));
Mask : constant Val_2 :=
Shift_Left (Shift_Left (1, Size) - 1, L_Shift_Amount);
Temp1 : constant Val_2 := Dest and not Mask;
Temp2 : constant Val_2 :=
Shift_Left (Val_2 (Src_Value), L_Shift_Amount);
Result : constant Val_2 := Temp1 or Temp2;
begin
return Result;
end Set_Bitfield;
procedure Set_Bitfield
(Src_Value : Val;
Dest_Address : Address;
Dest_Offset : Bit_Offset;
Size : Small_Size)
is
Old_Dest : constant Val_2 :=
Get_Val_2 (Dest_Address, Dest_Offset, Size);
New_Dest : constant Val_2 :=
Set_Bitfield (Src_Value, Old_Dest, Dest_Offset, Size);
begin
Set_Val_2 (Dest_Address, Dest_Offset, New_Dest, Size);
end Set_Bitfield;
procedure Copy_Small_Bitfield
(Src_Address : Address;
Src_Offset : Bit_Offset;
Dest_Address : Address;
Dest_Offset : Bit_Offset;
Size : Small_Size)
is
Src : constant Val_2 := Get_Val_2 (Src_Address, Src_Offset, Size);
V : constant Val := Get_Bitfield (Src, Src_Offset, Size);
begin
Set_Bitfield (V, Dest_Address, Dest_Offset, Size);
end Copy_Small_Bitfield;
-- Copy_Large_Bitfield does the main work. Copying aligned Vals is more
-- efficient than fiddling with shifting and whatnot. But we can't align
-- both source and destination. We choose to align the destination,
-- because that's more efficient -- Set_Bitfield needs to read, then
-- modify, then write, whereas Get_Bitfield does not.
--
-- So the method is:
--
-- Step 1:
-- If the destination is not already aligned, copy Initial_Size
-- bits, and increment the bit addresses. Initial_Size is chosen to
-- be the smallest size that will cause the destination bit address
-- to be aligned (i.e. have zero bit offset from the already-aligned
-- Address). Get_Bitfield and Set_Bitfield are used here.
--
-- Step 2:
-- Loop, copying Vals. Get_Bitfield is used to fetch a Val-sized
-- bit field, but Set_Bitfield is not needed -- we can set the
-- aligned Val with an array indexing.
--
-- Step 3:
-- Copy remaining smaller-than-Val bits, if any
procedure Copy_Large_Bitfield
(Src_Address : Address;
Src_Offset : Bit_Offset;
Dest_Address : Address;
Dest_Offset : Bit_Offset;
Size : Bit_Size)
is
Sz : Bit_Size := Size;
S_Addr : Address := Src_Address;
S_Off : Bit_Offset := Src_Offset;
D_Addr : Address := Dest_Address;
D_Off : Bit_Offset := Dest_Offset;
begin
if S_Addr < D_Addr or else (S_Addr = D_Addr and then S_Off < D_Off)
then
-- Here, the source bit address is less than the destination bit
-- address. Assert that there is no overlap.
declare
Temp_Off : constant Bit_Offset'Base := S_Off + Size;
After_S_Addr : constant Address :=
S_Addr + Address (Temp_Off / Storage_Unit);
After_S_Off : constant Bit_Offset_In_Byte :=
Temp_Off mod Storage_Unit;
-- (After_S_Addr, After_S_Off) is the bit address of the bit
-- just after the source bit field. Assert that it's less than
-- or equal to the destination bit address.
Overlap_OK : constant Boolean :=
After_S_Addr < D_Addr
or else
(After_S_Addr = D_Addr and then After_S_Off <= D_Off);
begin
pragma Assert (Overlap_OK);
end;
end if;
if D_Off /= 0 then
-- Step 1:
declare
Initial_Size : constant Small_Size := Val'Size - D_Off;
Initial_Val_2 : constant Val_2 :=
Get_Val_2 (S_Addr, S_Off, Initial_Size);
Initial_Val : constant Val :=
Get_Bitfield (Initial_Val_2, S_Off, Initial_Size);
begin
Set_Bitfield
(Initial_Val, D_Addr, D_Off, Initial_Size);
Sz := Sz - Initial_Size;
declare
New_S_Off : constant Bit_Offset'Base := S_Off + Initial_Size;
begin
if New_S_Off > Bit_Offset'Last then
S_Addr := S_Addr + Val_Bytes;
S_Off := New_S_Off - Small_Size'Last;
else
S_Off := New_S_Off;
end if;
end;
D_Addr := D_Addr + Val_Bytes;
pragma Assert (D_Off + Initial_Size = Val'Size);
D_Off := 0;
end;
end if;
-- Step 2:
declare
Dest_Arr : Val_Array (1 .. Sz / Val'Size) with Import,
Address => D_Addr;
begin
for Dest_Comp of Dest_Arr loop
declare
pragma Warnings (Off);
pragma Assert (Dest_Comp in Val);
pragma Warnings (On);
pragma Assert (Dest_Comp'Valid);
Src_V_2 : constant Val_2 :=
Get_Val_2 (S_Addr, S_Off, Val'Size);
Full_V : constant Val :=
Get_Bitfield (Src_V_2, S_Off, Val'Size);
begin
Dest_Comp := Full_V;
S_Addr := S_Addr + Val_Bytes;
-- S_Off remains the same
end;
end loop;
Sz := Sz mod Val'Size;
if Sz /= 0 then
-- Step 3:
declare
Final_Val_2 : constant Val_2 :=
Get_Val_2 (S_Addr, S_Off, Sz);
Final_Val : constant Val :=
Get_Bitfield (Final_Val_2, S_Off, Sz);
begin
Set_Bitfield
(Final_Val, D_Addr + Dest_Arr'Length * Val_Bytes, 0, Sz);
end;
end if;
end;
end Copy_Large_Bitfield;
procedure Copy_Bitfield
(Src_Address : Address;
Src_Offset : Bit_Offset_In_Byte;
Dest_Address : Address;
Dest_Offset : Bit_Offset_In_Byte;
Size : Bit_Size)
is
-- Align the Address values as for Val and Val_2, and adjust the
-- Bit_Offsets accordingly.
Src_Adjust : constant Address := Src_Address mod Val_Bytes;
Al_Src_Address : constant Address := Src_Address - Src_Adjust;
Al_Src_Offset : constant Bit_Offset :=
Src_Offset + Bit_Offset (Src_Adjust * Storage_Unit);
Dest_Adjust : constant Address := Dest_Address mod Val_Bytes;
Al_Dest_Address : constant Address := Dest_Address - Dest_Adjust;
Al_Dest_Offset : constant Bit_Offset :=
Dest_Offset + Bit_Offset (Dest_Adjust * Storage_Unit);
pragma Assert (Al_Src_Address mod Val'Alignment = 0);
pragma Assert (Al_Dest_Address mod Val'Alignment = 0);
begin
if Size in Small_Size then
Copy_Small_Bitfield
(Al_Src_Address, Al_Src_Offset,
Al_Dest_Address, Al_Dest_Offset,
Size);
else
Copy_Large_Bitfield
(Al_Src_Address, Al_Src_Offset,
Al_Dest_Address, Al_Dest_Offset,
Size);
end if;
end Copy_Bitfield;
end G;
end System.Bitfield_Utils;
|
-- { dg-do compile { target *-*-linux* } }
-- { dg-options "-gnatws" }
procedure Trampoline3 is
A : Integer;
type FuncPtr is access function (I : Integer) return Integer;
function F (I : Integer) return Integer is
begin
return A + I;
end F;
P : FuncPtr := F'Access;
I : Integer;
begin
I := P(0);
end;
-- { dg-final { scan-assembler-not "GNU-stack.*x" } }
|
-- SPDX-License-Identifier: Apache-2.0
--
-- Copyright (c) 2016 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.
package Orka.SIMD.SSE2.Doubles.Swizzle is
pragma Pure;
function Shuffle (Left, Right : m128d; Mask : Unsigned_32) return m128d
with Import, Convention => Intrinsic, External_Name => "__builtin_ia32_shufpd";
-- Shuffle the 64-bit doubles in Left and Right using the given Mask. The first
-- double (lower half) is retrieved from Left, the second double (upper half)
-- from Right.
--
-- The compiler needs access to the Mask at compile-time, thus construct it
-- as follows:
--
-- Mask_a_b : constant Unsigned_32 := a or b * 2;
--
-- a selects the double to use from Left, b from Right.
function Unpack_High (Left, Right : m128d) return m128d
with Import, Convention => Intrinsic, External_Name => "__builtin_ia32_unpckhpd";
-- Unpack and interleave the 64-bit doubles from the upper halves of
-- Left and Right as follows: Left (2), Right (2)
function Unpack_Low (Left, Right : m128d) return m128d
with Import, Convention => Intrinsic, External_Name => "__builtin_ia32_unpcklpd";
-- Unpack and interleave the 64-bit doubles from the lower halves of
-- Left and Right as follows: Left (1), Right (1)
function Extract_X (Elements : m128d; Zero : Unsigned_32) return Float_64
with Import, Convention => Intrinsic, External_Name => "__builtin_ia32_vec_ext_v2df";
end Orka.SIMD.SSE2.Doubles.Swizzle;
|
------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- XML Processor --
-- --
-- Testsuite Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2010-2014, 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 Ada.Characters.Conversions;
with Ada.Directories;
with Ada.Exceptions;
with Ada.Wide_Wide_Text_IO;
with League.String_Vectors;
with Put_Line;
with Read_File;
with XML.SAX.Constants;
with XML.SAX.File_Input_Sources;
with XML.SAX.Simple_Readers;
with XMLConf.Canonical_Writers;
with SAX_Events_Writers;
package body XMLConf.Testsuite_Handlers is
use type League.Strings.Universal_String;
Test_Tag : constant League.Strings.Universal_String
:= League.Strings.To_Universal_String ("TEST");
Id_Name : constant League.Strings.Universal_String
:= League.Strings.To_Universal_String ("ID");
URI_Name : constant League.Strings.Universal_String
:= League.Strings.To_Universal_String ("URI");
Type_Name : constant League.Strings.Universal_String
:= League.Strings.To_Universal_String ("TYPE");
Valid_Name : constant League.Strings.Universal_String
:= League.Strings.To_Universal_String ("valid");
Invalid_Name : constant League.Strings.Universal_String
:= League.Strings.To_Universal_String ("invalid");
Not_Wellformed_Name : constant League.Strings.Universal_String
:= League.Strings.To_Universal_String ("not-wf");
Error_Name : constant League.Strings.Universal_String
:= League.Strings.To_Universal_String ("error");
Edition_Name : constant League.Strings.Universal_String
:= League.Strings.To_Universal_String ("EDITION");
Fifth_Name : constant League.Strings.Universal_String
:= League.Strings.To_Universal_String ("5");
Output_Name : constant League.Strings.Universal_String
:= League.Strings.To_Universal_String ("OUTPUT");
Output3_Name : constant League.Strings.Universal_String
:= League.Strings.To_Universal_String ("OUTPUT3");
Namespace_Name : constant League.Strings.Universal_String
:= League.Strings.To_Universal_String ("NAMESPACE");
No_Name : constant League.Strings.Universal_String
:= League.Strings.To_Universal_String ("no");
Yes_Name : constant League.Strings.Universal_String
:= League.Strings.To_Universal_String ("yes");
procedure Execute_Test
(Self : in out Testsuite_Handler;
Id : League.Strings.Universal_String;
URI : League.Strings.Universal_String;
Kind : Test_Kinds;
Namespaces : Boolean;
Output : League.Strings.Universal_String);
------------------
-- Execute_Test --
------------------
procedure Execute_Test
(Self : in out Testsuite_Handler;
Id : League.Strings.Universal_String;
URI : League.Strings.Universal_String;
Kind : Test_Kinds;
Namespaces : Boolean;
Output : League.Strings.Universal_String)
is
Base_URI : constant League.IRIs.IRI
:= Self.Locator.Base_URI;
Expected_Base_URI : constant League.IRIs.IRI
:= Self.Expected_Base_URI.Resolve
(League.IRIs.From_Universal_String
(Base_URI.To_Universal_String.Slice
(Self.Testsuite_Base_URI.To_Universal_String.Length + 2,
Base_URI.To_Universal_String.Length)));
Expected_Data : constant League.Strings.Universal_String
:= Expected_Base_URI.Resolve
(League.IRIs.From_Universal_String (URI)).To_Universal_String;
Validating_Expected_Data : League.Strings.Universal_String;
Failed : Boolean := False;
begin
-- Skip suppressed tests.
if Self.Suppressed.Contains (Id) then
Self.Results (Kind).Suppressed := Self.Results (Kind).Suppressed + 1;
return;
end if;
-- Compute URI of expected data for validating mode.
if Self.Validating then
declare
Paths : League.String_Vectors.Universal_String_Vector
:= URI.Split ('/');
begin
Paths.Insert
(Paths.Length,
League.Strings.To_Universal_String ("validating"));
Validating_Expected_Data :=
Expected_Base_URI.Resolve
(League.IRIs.From_Universal_String
(Paths.Join ('/'))).To_Universal_String;
end;
end if;
-- SAX test.
declare
Source : aliased XML.SAX.File_Input_Sources.File_Input_Source;
Reader : aliased XML.SAX.Simple_Readers.Simple_Reader;
Writer : aliased SAX_Events_Writers.SAX_Events_Writer;
Expected : League.Strings.Universal_String;
begin
-- Check whether expected data for validating mode is available.
if not Validating_Expected_Data.Is_Empty
and then Ada.Directories.Exists
(Ada.Characters.Conversions.To_String
(XML.SAX.File_Input_Sources.URI_To_File_Name
(Validating_Expected_Data).To_Wide_Wide_String))
then
Expected :=
Read_File
(Ada.Characters.Conversions.To_String
(XML.SAX.File_Input_Sources.URI_To_File_Name
(Validating_Expected_Data).To_Wide_Wide_String));
else
Expected :=
Read_File
(Ada.Characters.Conversions.To_String
(XML.SAX.File_Input_Sources.URI_To_File_Name
(Expected_Data).To_Wide_Wide_String));
end if;
select
delay 60.0;
raise Program_Error with "terminated by timeout";
then abort
Writer.Set_Testsuite_URI
(Self.Testsuite_Base_URI.To_Universal_String);
Reader.Set_Content_Handler (Writer'Unchecked_Access);
Reader.Set_DTD_Handler (Writer'Unchecked_Access);
Reader.Set_Error_Handler (Writer'Unchecked_Access);
Reader.Set_Entity_Resolver (Writer'Unchecked_Access);
Reader.Set_Lexical_Handler (Writer'Unchecked_Access);
Reader.Set_Feature
(XML.SAX.Constants.Namespaces_Feature, Namespaces);
if Self.Validating then
Reader.Set_Feature (XML.SAX.Constants.Validation_Feature, True);
end if;
Source.Open_By_URI
(Base_URI.Resolve
(League.IRIs.From_Universal_String (URI)).To_Universal_String);
Reader.Parse (Source'Access);
Writer.Done;
if Writer.Text /= Expected then
Put_Line (Id & ": SAX");
Put_Line ("Expected: '" & Expected & "'");
Put_Line ("Actual : '" & Writer.Text & "'");
Self.Results (Kind).SAX := Self.Results (Kind).SAX + 1;
Failed := True;
else
case Kind is
when Valid =>
if Writer.Has_Fatal_Errors or Writer.Has_Errors then
Put_Line (Id & ": has errors");
Failed := True;
end if;
when Invalid =>
-- In non-validating mode all 'invalid' testcases must
-- pass successfully, while in validating mode they must
-- fail.
if Self.Validating then
if not Writer.Has_Errors then
Put_Line (Id & ": doesn't have errors");
Failed := True;
end if;
else
if Writer.Has_Fatal_Errors or Writer.Has_Errors then
Put_Line (Id & ": has errors");
Failed := True;
end if;
end if;
when Not_Wellformed =>
if not Writer.Has_Fatal_Errors then
Put_Line (Id & ": doesn't have errors");
Failed := True;
end if;
when Error =>
null;
end case;
end if;
end select;
exception
when X : others =>
Self.Results (Kind).Crash := Self.Results (Kind).Crash + 1;
Put_Line (Id & ": crashed");
Put_Line
(League.Strings.To_Universal_String
(Ada.Characters.Conversions.To_Wide_Wide_String
(Ada.Exceptions.Exception_Information (X))));
Failed := True;
end;
-- Canonical output test.
if not Failed and not Output.Is_Empty then
declare
Source : aliased XML.SAX.File_Input_Sources.File_Input_Source;
Reader : aliased XML.SAX.Simple_Readers.Simple_Reader;
Writer : aliased XMLConf.Canonical_Writers.Canonical_Writer;
Expected : League.Strings.Universal_String;
begin
Expected :=
Read_File
(Ada.Characters.Conversions.To_String
(XML.SAX.File_Input_Sources.URI_To_File_Name
(Base_URI.Resolve
(League.IRIs.From_Universal_String
(Output)).To_Universal_String).To_Wide_Wide_String));
select
delay 3.0;
raise Program_Error with "terminated by timeout";
then abort
Reader.Set_Content_Handler (Writer'Unchecked_Access);
Reader.Set_DTD_Handler (Writer'Unchecked_Access);
Reader.Set_Lexical_Handler (Writer'Unchecked_Access);
Reader.Set_Feature
(XML.SAX.Constants.Namespaces_Feature, Namespaces);
if Self.Validating then
Reader.Set_Feature
(XML.SAX.Constants.Validation_Feature, True);
end if;
Source.Open_By_URI
(Base_URI.Resolve
(League.IRIs.From_Universal_String
(URI)).To_Universal_String);
Reader.Parse (Source'Access);
if Expected /= Writer.Text then
Put_Line (Id & ": output");
Put_Line ("Expected output: '" & Expected & "'");
Put_Line ("Actual output : '" & Writer.Text & "'");
Self.Results (Kind).Output := Self.Results (Kind).Output + 1;
Failed := True;
end if;
end select;
exception
when X : others =>
Self.Results (Kind).Crash := Self.Results (Kind).Crash + 1;
Put_Line (Id & ": crashed (output test)");
Put_Line
(League.Strings.To_Universal_String
(Ada.Characters.Conversions.To_Wide_Wide_String
(Ada.Exceptions.Exception_Information (X))));
Failed := True;
end;
end if;
if Failed then
Self.Results (Kind).Failed := Self.Results (Kind).Failed + 1;
else
Self.Results (Kind).Passed := Self.Results (Kind).Passed + 1;
end if;
exception
when X : others =>
Put_Line (Id & ": initialization/finalization crashed");
Put_Line
(League.Strings.To_Universal_String
(Ada.Characters.Conversions.To_Wide_Wide_String
(Ada.Exceptions.Exception_Information (X))));
end Execute_Test;
------------------
-- Error_String --
------------------
overriding function Error_String
(Self : Testsuite_Handler)
return League.Strings.Universal_String
is
pragma Unreferenced (Self);
begin
return League.Strings.Empty_Universal_String;
end Error_String;
-----------------
-- Fatal_Error --
-----------------
overriding procedure Fatal_Error
(Self : in out Testsuite_Handler;
Occurrence : XML.SAX.Parse_Exceptions.SAX_Parse_Exception)
is
pragma Unreferenced (Self);
begin
Put_Line ("FATAL ERROR: " & Occurrence.Message);
end Fatal_Error;
---------------------
-- Read_Suppressed --
---------------------
procedure Read_Suppressed
(Self : in out Testsuite_Handler; File_Name : String)
is
File : Ada.Wide_Wide_Text_IO.File_Type;
Buffer : Wide_Wide_String (1 .. 128);
Last : Natural;
begin
Ada.Wide_Wide_Text_IO.Open
(File, Ada.Wide_Wide_Text_IO.In_File, File_Name);
while not Ada.Wide_Wide_Text_IO.End_Of_File (File) loop
Ada.Wide_Wide_Text_IO.Get_Line (File, Buffer, Last);
if Last < 1 or else Buffer (1 .. 2) /= "--" then
Self.Suppressed.Insert
(League.Strings.To_Universal_String (Buffer (1 .. Last)));
end if;
end loop;
Ada.Wide_Wide_Text_IO.Close (File);
end Read_Suppressed;
--------------------------
-- Set_Document_Locator --
--------------------------
overriding procedure Set_Document_Locator
(Self : in out Testsuite_Handler;
Locator : XML.SAX.Locators.SAX_Locator) is
begin
Self.Locator := Locator;
end Set_Document_Locator;
--------------------
-- Start_Document --
--------------------
overriding procedure Start_Document
(Self : in out Testsuite_Handler;
Success : in out Boolean)
is
pragma Unreferenced (Success);
begin
Self.Testsuite_Base_URI := Self.Locator.Base_URI;
Self.Expected_Base_URI :=
League.IRIs.From_Universal_String
(Self.Locator.Base_URI.To_Universal_String & "-expected-sax");
end Start_Document;
-------------------
-- Start_Element --
-------------------
overriding procedure Start_Element
(Self : in out Testsuite_Handler;
Namespace_URI : League.Strings.Universal_String;
Local_Name : League.Strings.Universal_String;
Qualified_Name : League.Strings.Universal_String;
Attributes : XML.SAX.Attributes.SAX_Attributes;
Success : in out Boolean)
is
pragma Unreferenced (Namespace_URI);
pragma Unreferenced (Local_Name);
pragma Unreferenced (Success);
Index : Natural;
Id : League.Strings.Universal_String;
URI : League.Strings.Universal_String;
Test_Type : League.Strings.Universal_String;
Output : League.Strings.Universal_String;
Test_Kind : Test_Kinds;
Namespaces : Boolean := True;
Skip : Boolean := False;
begin
if Qualified_Name = Test_Tag then
-- <!ELEMENT TEST (#PCDATA | EM | B)*>
-- <!ATTLIST TEST
-- ENTITIES (both|none|parameter|general) "none"
-- ID ID #REQUIRED
-- OUTPUT CDATA #IMPLIED
-- OUTPUT3 CDATA #IMPLIED
-- SECTIONS CDATA #REQUIRED
-- RECOMMENDATION (XML1.0|XML1.1|NS1.0|NS1.1|
-- XML1.0-errata2e|XML1.0-errata3e|XML1.0-errata4e|
-- NS1.0-errata1e) "XML1.0"
-- TYPE (valid|invalid|not-wf|error) #REQUIRED
-- VERSION NMTOKENS #IMPLIED
-- EDITION NMTOKENS #IMPLIED
-- URI CDATA #REQUIRED
-- NAMESPACE (yes|no) "yes"
-- >
Id := Attributes.Value (Attributes.Index (Id_Name));
URI := Attributes.Value (Attributes.Index (URI_Name));
Test_Type := Attributes.Value (Attributes.Index (Type_Name));
if Test_Type = Valid_Name then
Test_Kind := Valid;
elsif Test_Type = Invalid_Name then
Test_Kind := Invalid;
elsif Test_Type = Not_Wellformed_Name then
Test_Kind := Not_Wellformed;
elsif Test_Type = Error_Name then
Test_Kind := Error;
else
raise Constraint_Error;
end if;
Index := Attributes.Index (Edition_Name);
if Index /= 0 then
if Attributes.Value (Index) /= Fifth_Name then
Skip := True;
end if;
end if;
Index := Attributes.Index (Output_Name);
if Index /= 0 then
Output := Attributes.Value (Index);
end if;
Index := Attributes.Index (Output3_Name);
if Index /= 0 then
Output := Attributes.Value (Index);
end if;
Index := Attributes.Index (Namespace_Name);
if Index /= 0 then
if Attributes.Value (Index) = No_Name then
Namespaces := False;
elsif Attributes.Value (Index) = Yes_Name then
Namespaces := True;
else
raise Program_Error;
end if;
end if;
if not Skip and Self.Enabled (Test_Kind) then
Execute_Test (Self, Id, URI, Test_Kind, Namespaces, Output);
end if;
end if;
end Start_Element;
end XMLConf.Testsuite_Handlers;
|
Pragma Ada_2012;
With
Gnoga.Gui.Base
;
Package NSO.JSON.Gnoga_Object is --with Elaborate_Body is
Use Gnoga.Gui.Base;
Subtype JSON_Class is NSO.JSON.Instance'Class;
-- Returns the JSON format of the form parameters from the given object.
-- NOTE: This method does NOT work with multi-select selections; when
-- such is attempted, later values overwrite the former values.
Function Get_JSON( Object : Base_Type'Class ) return JSON_Class;
Type Form_Object is new Base_Type with private;
Function As_Form (Object : Base_Type'Class) return Form_Object;
Function Parameters (Object : Form_Object) return JSON_Class;
-- REPORT_VIEW
-- This function ties together four types:
-- (1) A Form-type, which is the ultimate data-source;
-- (2) The Params-type, which represents the data submitted by the form;
-- (3) The Report-type, which is the filtered/processed Params; and
-- (4) The View-type, which is the rendering-media for the report.
--
-- As an example, consider the situation of the daily-log, within this setup
-- the form has Weather-reports which must be processed (filtered/colated)
-- into an actual report. After this, the report is processed into HTML and
-- sent in an email.
--
-- Process: [HTML_FORM] -> [PARAMETERS] -> [REPORT_OBJECT] -> [HTML_VIEW].
Generic
Type Form (<>) is new Form_Object with private;
Type Params(<>) is limited private;
Type Report(<>) is limited private;
Type View (<>) is limited private;
-- Retrieve the submitted form data.
with Function Submission(Object : Form ) return Params is <>;
-- Filter data and [re]construct the report.
with Function Parameters(Object : Params) return Report is <>;
-- Transform the report-data into some viewable data.
with Function Processing(Object : Report) return View is <>;
Function Report_View (Object : Form_Object'Class) Return View;
-- GENERIC_REPORTER
--
Generic
Type Form (<>) is new Form_Object with private;
Type Params(<>) is limited private;
-- Retrieve the submitted form data.
with Function Parameters(Object : Form) return Params is <>;
This : in Form_Object'Class;
Package Generic_Reporter is
Original_Parameters : Constant Params := Parameters( Form(This) );
Generic
-- The particular report we are getting.
Type Report(<>) is limited private;
-- The type for the final display.
Type View (<>) is limited private;
-- Filter the data and [re]construct the report.
with Function Get_Report(Object : Params:= Original_Parameters) return Report is <>;
-- Transform the report-data into some viewable data.
with Function Processing(Object : Report:= Get_Report) return View is <>;
Function Generate_Report return View;
End Generic_Reporter;
Private
Type Form_Object is new Base_Type with null record;
End NSO.JSON.Gnoga_Object;
|
------------------------------------------------------------------------------
-- --
-- GNAT RUN-TIME COMPONENTS --
-- --
-- A D A . I N T E R R U P T S . N A M E S --
-- --
-- S p e c --
-- --
-- Copyright (C) 2012, 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. --
-- --
-- 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/>. --
-- --
------------------------------------------------------------------------------
-- Definitions for the MPC8349E PowerQUICC II Pro
package Ada.Interrupts.Names is
-- All identifiers in this unit are implementation defined
pragma Implementation_Defined;
IPI_Int_Internal_32 : constant Interrupt_ID := 64;
IPI_Int_Internal_33 : constant Interrupt_ID := 65;
IPI_Int_Internal_34 : constant Interrupt_ID := 66;
IPI_Int_Internal_35 : constant Interrupt_ID := 67;
RTC_ALR : constant Interrupt_ID := 68;
MU : constant Interrupt_ID := 69;
SBA : constant Interrupt_ID := 70;
DMA : constant Interrupt_ID := 71;
TSEC1_Tx : constant Interrupt_ID := 32;
TSEC1_Rx : constant Interrupt_ID := 33;
TSEC1_Err : constant Interrupt_ID := 34;
TSEC2_Tx : constant Interrupt_ID := 35;
TSEC2_Rx : constant Interrupt_ID := 36;
TSEC2_Err : constant Interrupt_ID := 37;
USB_DR : constant Interrupt_ID := 38;
USB_MPH : constant Interrupt_ID := 39;
IPP_Ind_Ext_Int_0 : constant Interrupt_ID := 48;
IPP_Ind_Ext_Int_1 : constant Interrupt_ID := 17;
IPP_Ind_Ext_Int_2 : constant Interrupt_ID := 18;
IPP_Ind_Ext_Int_3 : constant Interrupt_ID := 19;
IRQ4 : constant Interrupt_ID := 20;
IRQ5 : constant Interrupt_ID := 21;
IRQ6 : constant Interrupt_ID := 22;
IRQ7 : constant Interrupt_ID := 23;
UART1 : constant Interrupt_ID := 9;
UART2 : constant Interrupt_ID := 10;
SEC : constant Interrupt_ID := 11;
I2C1 : constant Interrupt_ID := 14;
I2C2 : constant Interrupt_ID := 15;
SPI : constant Interrupt_ID := 16;
GTM4 : constant Interrupt_ID := 72;
GTM8 : constant Interrupt_ID := 73;
GPIO1 : constant Interrupt_ID := 74;
GPIO2 : constant Interrupt_ID := 75;
DDR : constant Interrupt_ID := 76;
LBC : constant Interrupt_ID := 77;
GTM2 : constant Interrupt_ID := 78;
GTM6 : constant Interrupt_ID := 79;
PMC : constant Interrupt_ID := 80;
GTM3 : constant Interrupt_ID := 84;
GTM7 : constant Interrupt_ID := 85;
GTM1 : constant Interrupt_ID := 90;
GTM5 : constant Interrupt_ID := 91;
end Ada.Interrupts.Names;
|
with Ada.Directories; use Ada.Directories;
with Ada.Text_IO;
procedure Test_Directory_Walk is
procedure Walk (Name : String; Pattern : String) is
procedure Print (Item : Directory_Entry_Type) is
begin
Ada.Text_IO.Put_Line (Full_Name (Item));
end Print;
procedure Walk (Item : Directory_Entry_Type) is
begin
if Simple_Name (Item) /= "." and then Simple_Name (Item) /= ".." then
Walk (Full_Name (Item), Pattern);
end if;
exception
when Name_Error => null;
end Walk;
begin
Search (Name, Pattern, (others => True), Print'Access);
Search (Name, "", (Directory => True, others => False), Walk'Access);
end Walk;
begin
Walk (".", "*.adb");
end Test_Directory_Walk;
|
--
-- Jan & Uwe R. Zimmer, Australia, July 2011
--
with Ada.Numerics; use Ada.Numerics;
with Ada.Numerics.Elementary_Functions; use Ada.Numerics.Elementary_Functions;
with Graphics_Configuration; use Graphics_Configuration;
with Graphics_Data; use Graphics_Data;
with GL;
with GLOBE_3D;
-- with GLOBE_3D.Textures;
with GLU;
with GLUT; use GLUT;
with GLUT.Devices;
with Vectors_2D_N; use Vectors_2D_N;
package body Graphics_Setup is
Deg_2_Rad : constant := Pi / 180.0;
------------------
-- Clear For 3D --
------------------
procedure Reset_for_3D is
use GL;
Aspect_Ratio : constant GL.Double := GL.Double (Viewer_Size (x)) / GL.Double (Viewer_Size (y));
Half_Field_of_View : Float := 0.5 * Float (Eye.FOVy) * Deg_2_Rad; -- In Radians
begin
if Aspect_Ratio > 1.0 then -- If Wider than High
Half_Field_of_View := Arctan (Float (Aspect_Ratio) * Tan (Float (Eye.FOVy)));
end if;
Eye.Clipper.max_dot_product := GLOBE_3D.Real (Sin (Half_Field_of_View));
Eye.Clipper.main_clipping := (0, 0, Viewer_Size (x) - 1, Viewer_Size (y) - 1);
GL.Viewport (0, 0, GL.Sizei (Viewer_Size (x)), GL.Sizei (Viewer_Size (y)));
GL.MatrixMode (GL.PROJECTION);
GL.LoadIdentity;
GLU.Perspective (fovy => Eye.FOVy, -- Field of View in the Y
aspect => Aspect_Ratio,
zNear => Camera_Close_Clipping_Plane,
zFar => Camera_Far_Clipping_Plane);
GL.MatrixMode (GL.MODELVIEW);
GL.ShadeModel (GL.SMOOTH); -- Smooth vs. Flat
GL.ClearColor (0.0, 0.0, 0.07, 0.0); -- Clear Value for Colour Buffer
GL.ClearAccum (0.0, 0.0, 0.0, 0.0); -- Clear Value for Accumulation Buffer
end Reset_for_3D;
--------------------
-- Window Resized --
--------------------
procedure Window_Resize (Size_x, Size_y : Integer) is
begin
Viewer_Size := ((x => Size_x, y => Size_y));
Reset_for_3D;
end Window_Resize;
----------------------
-- Initialize Video --
-----------------------
-- Actual_LINE_WIDTH : aliased GL.Float;
procedure Initialize_Graphics (Operations : access procedure) is
GLUT_Options : constant Unsigned := GLUT.DOUBLE or GLUT.RGB or GLUT.DEPTH;
Error : Integer; pragma Unreferenced (Error);
begin
-- GLOBE_3D.Set_global_data_name ("Textures.zip");
-- GLOBE_3D.Textures.Register_textures_from_resources;
Eye.FOVy := Camera_Field_of_View;
-- GLUT Stuff --
-- Get a Window with the correct properties --
GLUT.Init;
GLUT.InitDisplayMode (GLUT_Options);
GLUT.InitWindowSize (Viewer_Size (x), Viewer_Size (y));
GLUT.InitWindowPosition (0, 50);
Error := GLUT.CreateWindow (Viewer_Title);
-- Feedback Procedures --
GLUT.ReshapeFunc (Window_Resize'Address);
GLUT.DisplayFunc (Operations.all'Address);
GLUT.IdleFunc (Operations.all'Address);
GLUT.Devices.Initialize;
-- GL Stuff --
-- Clear Modes --
GL.Disable (GL.BLEND);
GL.Disable (GL.LIGHTING);
GL.Disable (GL.AUTO_NORMAL);
GL.Disable (GL.NORMALIZE);
GL.Disable (GL.DEPTH_TEST);
Reset_for_3D;
-- Enable Lighting --
GL.Enable (GL.LIGHTING);
for Source in Initial_Lights'Range loop
GLOBE_3D.Define (Source, Initial_Lights (Source));
GLOBE_3D.Switch_light (Source, True);
end loop;
-- Reset Eye
Eye.Clipper.Eye_Position := Camera_Initial_Position;
Eye.World_Rotation := GLOBE_3D.Id_33;
Eye.FOVy := Camera_Field_of_View;
-- GL.GetFloatv (GL.LINE_WIDTH_RANGE, Actual_LINE_WIDTH'Access);
-- Put ("Actual_LINE_WIDTH: "); Put (Float (Actual_LINE_WIDTH), 3, 2, 0);
end Initialize_Graphics;
--
end Graphics_Setup;
|
-- NORX.Utils
-- Some utility routines useful when writing the examples.
-- Copyright (c) 2016, James Humphry - see LICENSE file for details
with Ada.Text_IO;
use Ada.Text_IO;
package body NORX.Utils is
package Word_IO is new
Ada.Text_IO.Modular_IO(Num => Word);
use Word_IO;
procedure Put_State(S : in State) is
begin
for I in S'Range loop
Put(S(I), Base => 16);
if I mod 4 = 3 then
New_Line;
else
Put(" ");
end if;
end loop;
end Put_State;
procedure Put_Storage_Array(X : in Storage_Array) is
function To_Hex_String(X : Storage_Element) return String is
Hex : constant String(1..16) := "0123456789ABCDEF";
begin
return Hex(Integer(X/16) + 1) & Hex(Integer(X mod 16) + 1);
end To_Hex_String;
begin
for I in X'Range loop
Put(To_Hex_String(X(I)));
if I mod 16 = 15 then
New_Line;
else
Put(" ");
end if;
end loop;
end Put_Storage_Array;
end NORX.Utils;
|
with agar.gui.window;
package demo is
window : agar.gui.window.window_access_t;
procedure init
(name : string;
video_width : integer := 640;
video_height : integer := 480;
window_width : integer := 320;
window_height : integer := 240);
procedure run;
procedure finish;
end demo;
|
-- { dg-excess-errors "no code generated" }
with Size_Attribute1_Pkg2;
generic
type T is private;
package Size_Attribute1_Pkg1 is
package My_R is new Size_Attribute1_Pkg2 (T);
procedure Dummy;
end Size_Attribute1_Pkg1;
|
-- A71004A.ADA
-- Grant of Unlimited Rights
--
-- Under contracts F33600-87-D-0337, F33600-84-D-0280, MDA903-79-C-0687,
-- F08630-91-C-0015, and DCA100-97-D-0025, the U.S. Government obtained
-- unlimited rights in the software and documentation contained herein.
-- Unlimited rights are defined in DFAR 252.227-7013(a)(19). By making
-- this public release, the Government intends to confer upon all
-- recipients unlimited rights equal to those held by the Government.
-- These rights include rights to use, duplicate, release or disclose the
-- released technical data and computer software in whole or in part, in
-- any manner and for any purpose whatsoever, and to have or permit others
-- to do so.
--
-- DISCLAIMER
--
-- ALL MATERIALS OR INFORMATION HEREIN RELEASED, MADE AVAILABLE OR
-- DISCLOSED ARE AS IS. THE GOVERNMENT MAKES NO EXPRESS OR IMPLIED
-- WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING THE CONDITIONS OF THE
-- SOFTWARE, DOCUMENTATION OR OTHER INFORMATION RELEASED, MADE AVAILABLE
-- OR DISCLOSED, OR THE OWNERSHIP, MERCHANTABILITY, OR FITNESS FOR A
-- PARTICULAR PURPOSE OF SAID MATERIAL.
--*
-- CHECK THAT ALL FORMS OF DECLARATION PERMITTED IN THE PRIVATE PART OF
-- A PACKAGE ARE INDEED ACCEPTED BY THE COMPILER.
-- TASKS, GENERICS, FIXED AND FLOAT DECLARATIONS ARE NOT TESTED.
-- DAT 5/6/81
-- VKG 2/16/83
WITH REPORT; USE REPORT;
PROCEDURE A71004A IS
BEGIN
TEST ("A71004A", "ALL FORMS OF DECLARATIONS IN PRIVATE PART");
DD:
DECLARE
PACKAGE P1 IS
TYPE P IS PRIVATE;
TYPE L IS LIMITED PRIVATE;
CP : CONSTANT P;
CL : CONSTANT L;
PRIVATE
ONE : CONSTANT := 1;
TWO : CONSTANT := ONE * 1.0 + 1.0;
N1, N2, N3 : CONSTANT := TWO;
TYPE I IS RANGE -10 .. 10;
X4, X5 : CONSTANT I := I(IDENT_INT(3));
X6, X7 : I := X4 + X5;
TYPE AR IS ARRAY (I) OF L;
X10 : ARRAY (IDENT_INT(1) .. IDENT_INT (10)) OF I;
X11 : CONSTANT ARRAY (1..10) OF I := (1..10=>3);
TYPE T3 IS (E12);
TYPE T4 IS NEW T3;
TYPE REC1 (D:BOOLEAN:=TRUE) IS RECORD NULL; END RECORD;
SUBTYPE REC1TRUE IS REC1( D => TRUE ) ;
TYPE L IS NEW REC1TRUE ;
X8 , X9 : AR;
TYPE A6 IS ACCESS REC1 ;
SUBTYPE L1 IS L ;
SUBTYPE A7 IS A6(D=>TRUE);
SUBTYPE I14 IS I RANGE 1 .. 1;
TYPE UA1 IS ARRAY (I14 RANGE <> ) OF I14;
TYPE UA2 IS NEW UA1;
USE STANDARD.ASCII;
PROCEDURE P1 ;
FUNCTION F1 (X : UA1) RETURN UA1;
FUNCTION "+" (X : UA1) RETURN UA1;
PACKAGE PK IS
PRIVATE
END;
PACKAGE PK1 IS
PACKAGE PK2 IS END;
PRIVATE
PACKAGE PK3 IS PRIVATE END;
END PK1;
EX : EXCEPTION;
EX1, EX2 : EXCEPTION;
X99 : I RENAMES X7;
EX3 : EXCEPTION RENAMES EX1;
PACKAGE PQ1 RENAMES DD.P1;
PACKAGE PQ2 RENAMES PK1;
PACKAGE PQ3 RENAMES PQ2 . PK2;
FUNCTION "-" (X : UA1) RETURN UA1 RENAMES "+";
PROCEDURE P98 RENAMES P1;
TYPE P IS NEW L;
CP : CONSTANT P := (D=> TRUE);
CL : CONSTANT L := L(CP);
END P1;
PACKAGE BODY P1 IS
PROCEDURE P1 IS BEGIN NULL; END P1;
FUNCTION F1 (X : UA1) RETURN UA1 IS
BEGIN RETURN X; END F1;
FUNCTION "+" (X : UA1) RETURN UA1 IS
BEGIN RETURN F1(X); END "+";
PACKAGE BODY PK1 IS
PACKAGE BODY PK3 IS END;
END PK1;
BEGIN
NULL ;
END P1;
BEGIN
NULL;
END DD;
RESULT;
END A71004A;
|
pragma Style_Checks (Off);
-- This spec has been automatically generated from STM32G474xx.svd
pragma Restrictions (No_Elaboration_Code);
with HAL;
with System;
package STM32_SVD.DBGMCU is
pragma Preelaborate;
---------------
-- Registers --
---------------
subtype IDCODE_DEV_ID_Field is HAL.UInt16;
subtype IDCODE_REV_ID_Field is HAL.UInt16;
-- MCU Device ID Code Register
type IDCODE_Register is record
-- Read-only. Device Identifier
DEV_ID : IDCODE_DEV_ID_Field;
-- Read-only. Revision Identifier
REV_ID : IDCODE_REV_ID_Field;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for IDCODE_Register use record
DEV_ID at 0 range 0 .. 15;
REV_ID at 0 range 16 .. 31;
end record;
subtype CR_TRACE_MODE_Field is HAL.UInt2;
-- Debug MCU Configuration Register
type CR_Register is record
-- Debug Sleep Mode
DBG_SLEEP : Boolean := False;
-- Debug Stop Mode
DBG_STOP : Boolean := False;
-- Debug Standby Mode
DBG_STANDBY : Boolean := False;
-- unspecified
Reserved_3_4 : HAL.UInt2 := 16#0#;
-- Trace pin assignment control
TRACE_IOEN : Boolean := False;
-- Trace pin assignment control
TRACE_MODE : CR_TRACE_MODE_Field := 16#0#;
-- unspecified
Reserved_8_31 : HAL.UInt24 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for CR_Register use record
DBG_SLEEP at 0 range 0 .. 0;
DBG_STOP at 0 range 1 .. 1;
DBG_STANDBY at 0 range 2 .. 2;
Reserved_3_4 at 0 range 3 .. 4;
TRACE_IOEN at 0 range 5 .. 5;
TRACE_MODE at 0 range 6 .. 7;
Reserved_8_31 at 0 range 8 .. 31;
end record;
-- APB Low Freeze Register 1
type APB1L_FZ_Register is record
-- Debug Timer 2 stopped when Core is halted
DBG_TIMER2_STOP : Boolean := False;
-- TIM3 counter stopped when core is halted
DBG_TIM3_STOP : Boolean := False;
-- TIM4 counter stopped when core is halted
DBG_TIM4_STOP : Boolean := False;
-- TIM5 counter stopped when core is halted
DBG_TIM5_STOP : Boolean := False;
-- Debug Timer 6 stopped when Core is halted
DBG_TIMER6_STOP : Boolean := False;
-- TIM7 counter stopped when core is halted
DBG_TIM7_STOP : Boolean := False;
-- unspecified
Reserved_6_9 : HAL.UInt4 := 16#0#;
-- Debug RTC stopped when Core is halted
DBG_RTC_STOP : Boolean := False;
-- Debug Window Wachdog stopped when Core is halted
DBG_WWDG_STOP : Boolean := False;
-- Debug Independent Wachdog stopped when Core is halted
DBG_IWDG_STOP : Boolean := False;
-- unspecified
Reserved_13_20 : HAL.UInt8 := 16#0#;
-- I2C1 SMBUS timeout mode stopped when core is halted
DBG_I2C1_STOP : Boolean := False;
-- I2C2 SMBUS timeout mode stopped when core is halted
DBG_I2C2_STOP : Boolean := False;
-- unspecified
Reserved_23_29 : HAL.UInt7 := 16#0#;
-- I2C3 SMBUS timeout mode stopped when core is halted
DBG_I2C3_STOP : Boolean := False;
-- LPTIM1 counter stopped when core is halted
DBG_LPTIMER_STOP : Boolean := False;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for APB1L_FZ_Register use record
DBG_TIMER2_STOP at 0 range 0 .. 0;
DBG_TIM3_STOP at 0 range 1 .. 1;
DBG_TIM4_STOP at 0 range 2 .. 2;
DBG_TIM5_STOP at 0 range 3 .. 3;
DBG_TIMER6_STOP at 0 range 4 .. 4;
DBG_TIM7_STOP at 0 range 5 .. 5;
Reserved_6_9 at 0 range 6 .. 9;
DBG_RTC_STOP at 0 range 10 .. 10;
DBG_WWDG_STOP at 0 range 11 .. 11;
DBG_IWDG_STOP at 0 range 12 .. 12;
Reserved_13_20 at 0 range 13 .. 20;
DBG_I2C1_STOP at 0 range 21 .. 21;
DBG_I2C2_STOP at 0 range 22 .. 22;
Reserved_23_29 at 0 range 23 .. 29;
DBG_I2C3_STOP at 0 range 30 .. 30;
DBG_LPTIMER_STOP at 0 range 31 .. 31;
end record;
-- APB Low Freeze Register 2
type APB1H_FZ_Register is record
-- unspecified
Reserved_0_0 : HAL.Bit := 16#0#;
-- DBG_I2C4_STOP
DBG_I2C4_STOP : Boolean := False;
-- unspecified
Reserved_2_31 : HAL.UInt30 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for APB1H_FZ_Register use record
Reserved_0_0 at 0 range 0 .. 0;
DBG_I2C4_STOP at 0 range 1 .. 1;
Reserved_2_31 at 0 range 2 .. 31;
end record;
-- APB High Freeze Register
type APB2_FZ_Register is record
-- unspecified
Reserved_0_10 : HAL.UInt11 := 16#0#;
-- TIM1 counter stopped when core is halted
DBG_TIM1_STOP : Boolean := False;
-- unspecified
Reserved_12_12 : HAL.Bit := 16#0#;
-- TIM8 counter stopped when core is halted
DBG_TIM8_STOP : Boolean := False;
-- unspecified
Reserved_14_15 : HAL.UInt2 := 16#0#;
-- TIM15 counter stopped when core is halted
DBG_TIM15_STOP : Boolean := False;
-- TIM16 counter stopped when core is halted
DBG_TIM16_STOP : Boolean := False;
-- TIM17 counter stopped when core is halted
DBG_TIM17_STOP : Boolean := False;
-- unspecified
Reserved_19_19 : HAL.Bit := 16#0#;
-- TIM20counter stopped when core is halted
DBG_TIM20_STOP : Boolean := False;
-- unspecified
Reserved_21_25 : HAL.UInt5 := 16#0#;
-- DBG_HRTIM0_STOP
DBG_HRTIM0_STOP : Boolean := False;
-- DBG_HRTIM0_STOP
DBG_HRTIM1_STOP : Boolean := False;
-- DBG_HRTIM0_STOP
DBG_HRTIM2_STOP : Boolean := False;
-- DBG_HRTIM0_STOP
DBG_HRTIM3_STOP : Boolean := False;
-- unspecified
Reserved_30_31 : HAL.UInt2 := 16#0#;
end record
with Volatile_Full_Access, Object_Size => 32,
Bit_Order => System.Low_Order_First;
for APB2_FZ_Register use record
Reserved_0_10 at 0 range 0 .. 10;
DBG_TIM1_STOP at 0 range 11 .. 11;
Reserved_12_12 at 0 range 12 .. 12;
DBG_TIM8_STOP at 0 range 13 .. 13;
Reserved_14_15 at 0 range 14 .. 15;
DBG_TIM15_STOP at 0 range 16 .. 16;
DBG_TIM16_STOP at 0 range 17 .. 17;
DBG_TIM17_STOP at 0 range 18 .. 18;
Reserved_19_19 at 0 range 19 .. 19;
DBG_TIM20_STOP at 0 range 20 .. 20;
Reserved_21_25 at 0 range 21 .. 25;
DBG_HRTIM0_STOP at 0 range 26 .. 26;
DBG_HRTIM1_STOP at 0 range 27 .. 27;
DBG_HRTIM2_STOP at 0 range 28 .. 28;
DBG_HRTIM3_STOP at 0 range 29 .. 29;
Reserved_30_31 at 0 range 30 .. 31;
end record;
-----------------
-- Peripherals --
-----------------
-- Debug support
type DBGMCU_Peripheral is record
-- MCU Device ID Code Register
IDCODE : aliased IDCODE_Register;
-- Debug MCU Configuration Register
CR : aliased CR_Register;
-- APB Low Freeze Register 1
APB1L_FZ : aliased APB1L_FZ_Register;
-- APB Low Freeze Register 2
APB1H_FZ : aliased APB1H_FZ_Register;
-- APB High Freeze Register
APB2_FZ : aliased APB2_FZ_Register;
end record
with Volatile;
for DBGMCU_Peripheral use record
IDCODE at 16#0# range 0 .. 31;
CR at 16#4# range 0 .. 31;
APB1L_FZ at 16#8# range 0 .. 31;
APB1H_FZ at 16#C# range 0 .. 31;
APB2_FZ at 16#10# range 0 .. 31;
end record;
-- Debug support
DBGMCU_Periph : aliased DBGMCU_Peripheral
with Import, Address => DBGMCU_Base;
end STM32_SVD.DBGMCU;
|
pragma License (Unrestricted); -- BSD 3-Clause
-- translated unit from MT19937 (mtTest.c)
--
-- A C-program for MT19937, with initialization improved 2002/1/26.
-- Coded by Takuji Nishimura and Makoto Matsumoto.
--
-- Before using, initialize the state by using init_genrand(seed)
-- or init_by_array(init_key, key_length).
--
-- Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura,
-- All rights reserved.
-- Copyright (C) 2005, Mutsuo Saito,
-- All rights reserved.
--
-- 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. The names of its contributors may not 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 OWNER 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.
--
--
-- Any feedback is very welcome.
-- http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html
-- email: m-mat @ math.sci.hiroshima-u.ac.jp (remove space)
--
--
-- Ada version by yt
--
with Ada.Long_Long_Float_Text_IO;
with Ada.Numerics.MT19937;
with Ada.Text_IO;
procedure random_mt19937 is
use Ada.Numerics.MT19937;
package Unsigned_32_IO is new Ada.Text_IO.Modular_IO (Unsigned_32);
init : Unsigned_32_Array (0 .. 3) := (16#123#, 16#234#, 16#345#, 16#456#);
Gen : aliased Generator := Initialize (init);
begin
Ada.Text_IO.Put_Line ("1000 outputs of genrand_int32()");
for i in 0 .. 1000 - 1 loop
Unsigned_32_IO.Put (
Random_32 (Gen),
Width => 10);
Ada.Text_IO.Put (' ');
if i rem 5 = 4 then
Ada.Text_IO.New_Line;
end if;
end loop;
Ada.Text_IO.New_Line;
Ada.Text_IO.Put_Line ("1000 outputs of genrand_real2()");
for i in 0 .. 1000 - 1 loop
Ada.Long_Long_Float_Text_IO.Put (
Random_0_To_Less_Than_1 (Gen),
Fore => 0,
Aft => 8,
Exp => 0);
Ada.Text_IO.Put (' ');
if i rem 5 = 4 then
Ada.Text_IO.New_Line;
end if;
end loop;
end random_mt19937;
|
-----------------------------------------------------------------------
-- html-selects -- ASF HTML UISelectOne and UISelectMany components
-- Copyright (C) 2011, 2013, 2014, 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 Util.Strings;
with ASF.Utils;
package body ASF.Components.Html.Selects is
-- ------------------------------
-- UISelectItem Component
-- ------------------------------
ITEM_LABEL_NAME : constant String := "itemLabel";
ITEM_VALUE_NAME : constant String := "itemValue";
ITEM_DESCRIPTION_NAME : constant String := "itemDescription";
ITEM_DISABLED_NAME : constant String := "itemDisabled";
SELECT_ATTRIBUTE_NAMES : Util.Strings.String_Set.Set;
-- ------------------------------
-- UISelectBoolean Component
-- ------------------------------
-- Render the checkbox element.
overriding
procedure Render_Input (UI : in UISelectBoolean;
Context : in out Faces_Context'Class;
Write_Id : in Boolean := True) is
use ASF.Components.Html.Forms;
Writer : constant Response_Writer_Access := Context.Get_Response_Writer;
Value : constant EL.Objects.Object := UIInput'Class (UI).Get_Value;
begin
Writer.Start_Element ("input");
Writer.Write_Attribute (Name => "type", Value => "checkbox");
UI.Render_Attributes (Context, SELECT_ATTRIBUTE_NAMES, Writer, Write_Id);
Writer.Write_Attribute (Name => "name", Value => UI.Get_Client_Id);
if not EL.Objects.Is_Null (Value) and then EL.Objects.To_Boolean (Value) then
Writer.Write_Attribute (Name => "checked", Value => "true");
end if;
Writer.End_Element ("input");
end Render_Input;
-- ------------------------------
-- Convert the string into a value. If a converter is specified on the component,
-- use it to convert the value. Make sure the result is a boolean.
-- ------------------------------
overriding
function Convert_Value (UI : in UISelectBoolean;
Value : in String;
Context : in Faces_Context'Class) return EL.Objects.Object is
use type EL.Objects.Data_Type;
Result : constant EL.Objects.Object := Forms.UIInput (UI).Convert_Value (Value, Context);
begin
case EL.Objects.Get_Type (Result) is
when EL.Objects.TYPE_BOOLEAN =>
return Result;
when EL.Objects.TYPE_INTEGER =>
return EL.Objects.To_Object (EL.Objects.To_Boolean (Result));
when others =>
if Value = "on" then
return EL.Objects.To_Object (True);
else
return EL.Objects.To_Object (False);
end if;
end case;
end Convert_Value;
-- ------------------------------
-- Iterator over the Select_Item elements
-- ------------------------------
-- ------------------------------
-- Get an iterator to scan the component children.
-- ------------------------------
procedure First (UI : in UISelectOne'Class;
Context : in Faces_Context'Class;
Iterator : out Cursor) is
begin
Iterator.Component := UI.First;
Iterator.Pos := 0;
Iterator.Last := 0;
while ASF.Components.Base.Has_Element (Iterator.Component) loop
Iterator.Current := ASF.Components.Base.Element (Iterator.Component);
if Iterator.Current.all in UISelectItem'Class then
return;
end if;
if Iterator.Current.all in UISelectItems'Class then
Iterator.List := UISelectItems'Class (Iterator.Current.all)
.Get_Select_Item_List (Context);
Iterator.Last := Iterator.List.Length;
Iterator.Pos := 1;
if Iterator.Last > 0 then
return;
end if;
end if;
ASF.Components.Base.Next (Iterator.Component);
end loop;
Iterator.Pos := 0;
Iterator.Current := null;
end First;
-- ------------------------------
-- Returns True if the iterator points to a valid child.
-- ------------------------------
function Has_Element (Pos : in Cursor) return Boolean is
use type ASF.Components.Base.UIComponent_Access;
begin
if Pos.Pos > 0 and Pos.Pos <= Pos.Last then
return True;
else
return Pos.Current /= null;
end if;
end Has_Element;
-- ------------------------------
-- Get the child component pointed to by the iterator.
-- ------------------------------
function Element (Pos : in Cursor;
Context : in Faces_Context'Class) return ASF.Models.Selects.Select_Item is
begin
if Pos.Pos > 0 and Pos.Pos <= Pos.Last then
return Pos.List.Get_Select_Item (Pos.Pos);
else
return UISelectItem'Class (Pos.Current.all).Get_Select_Item (Context);
end if;
end Element;
-- ------------------------------
-- Move to the next child.
-- ------------------------------
procedure Next (Pos : in out Cursor;
Context : in Faces_Context'Class) is
begin
if Pos.Pos > 0 and Pos.Pos < Pos.Last then
Pos.Pos := Pos.Pos + 1;
else
Pos.Pos := 0;
loop
Pos.Current := null;
ASF.Components.Base.Next (Pos.Component);
exit when not ASF.Components.Base.Has_Element (Pos.Component);
Pos.Current := ASF.Components.Base.Element (Pos.Component);
exit when Pos.Current.all in UISelectItem'Class;
if Pos.Current.all in UISelectItems'Class then
Pos.List := UISelectItems'Class (Pos.Current.all).Get_Select_Item_List (Context);
Pos.Last := Pos.List.Length;
Pos.Pos := 1;
exit when Pos.Last > 0;
Pos.Pos := 0;
end if;
end loop;
end if;
end Next;
-- ------------------------------
-- Get the <b>Select_Item</b> represented by the component.
-- ------------------------------
function Get_Select_Item (From : in UISelectItem;
Context : in Faces_Context'Class)
return ASF.Models.Selects.Select_Item is
use Util.Beans.Objects;
Val : constant Object := From.Get_Attribute (Name => VALUE_NAME,
Context => Context);
begin
if not Is_Null (Val) then
return ASF.Models.Selects.To_Select_Item (Val);
end if;
declare
Label : constant Object := From.Get_Attribute (Name => ITEM_LABEL_NAME,
Context => Context);
Value : constant Object := From.Get_Attribute (Name => ITEM_VALUE_NAME,
Context => Context);
Description : constant Object := From.Get_Attribute (Name => ITEM_DESCRIPTION_NAME,
Context => Context);
Disabled : constant Boolean := From.Get_Attribute (Name => ITEM_DISABLED_NAME,
Context => Context);
begin
if Is_Null (Label) then
return ASF.Models.Selects.Create_Select_Item (Value, Value, Description, Disabled);
else
return ASF.Models.Selects.Create_Select_Item (Label, Value, Description, Disabled);
end if;
end;
end Get_Select_Item;
-- ------------------------------
-- UISelectItems Component
-- ------------------------------
-- ------------------------------
-- Get the <b>Select_Item</b> represented by the component.
-- ------------------------------
function Get_Select_Item_List (From : in UISelectItems;
Context : in Faces_Context'Class)
return ASF.Models.Selects.Select_Item_List is
use Util.Beans.Objects;
Value : constant Object := From.Get_Attribute (Name => VALUE_NAME,
Context => Context);
begin
return ASF.Models.Selects.To_Select_Item_List (Value);
end Get_Select_Item_List;
-- ------------------------------
-- SelectOne Component
-- ------------------------------
-- ------------------------------
-- Render the <b>select</b> element.
-- ------------------------------
overriding
procedure Encode_Begin (UI : in UISelectOne;
Context : in out Faces_Context'Class) is
begin
if UI.Is_Rendered (Context) then
UISelectOne'Class (UI).Render_Select (Context);
end if;
end Encode_Begin;
-- ------------------------------
-- Renders the <b>select</b> element. This is called by <b>Encode_Begin</b> if
-- the component is rendered.
-- ------------------------------
procedure Render_Select (UI : in UISelectOne;
Context : in out Faces_Context'Class) is
Writer : constant Response_Writer_Access := Context.Get_Response_Writer;
Value : constant EL.Objects.Object := UISelectOne'Class (UI).Get_Value;
begin
Writer.Start_Element ("select");
Writer.Write_Attribute (Name => "name", Value => UI.Get_Client_Id);
UI.Render_Attributes (Context, SELECT_ATTRIBUTE_NAMES, Writer);
UISelectOne'Class (UI).Render_Options (Value, Context);
Writer.End_Element ("select");
end Render_Select;
-- ------------------------------
-- Renders the <b>option</b> element. This is called by <b>Render_Select</b> to
-- generate the component options.
-- ------------------------------
procedure Render_Options (UI : in UISelectOne;
Value : in Util.Beans.Objects.Object;
Context : in out Faces_Context'Class) is
Writer : constant Response_Writer_Access := Context.Get_Response_Writer;
Selected : constant Wide_Wide_String := Util.Beans.Objects.To_Wide_Wide_String (Value);
Iter : Cursor;
begin
UI.First (Context, Iter);
while Has_Element (Iter) loop
declare
Item : constant ASF.Models.Selects.Select_Item := Element (Iter, Context);
Item_Value : constant Wide_Wide_String := Item.Get_Value;
begin
Writer.Start_Element ("option");
Writer.Write_Wide_Attribute ("value", Item_Value);
if Item_Value = Selected then
Writer.Write_Attribute ("selected", "selected");
end if;
if Item.Is_Escaped then
Writer.Write_Wide_Text (Item.Get_Label);
else
Writer.Write_Wide_Text (Item.Get_Label);
end if;
Writer.End_Element ("option");
Next (Iter, Context);
end;
end loop;
end Render_Options;
-- ------------------------------
-- Returns True if the radio options must be rendered vertically.
-- ------------------------------
function Is_Vertical (UI : in UISelectOneRadio;
Context : in Faces_Context'Class) return Boolean is
Dir : constant String := UI.Get_Attribute (Context => Context,
Name => "layout",
Default => "");
begin
return Dir = "pageDirection";
end Is_Vertical;
-- ------------------------------
-- Renders the <b>select</b> element. This is called by <b>Encode_Begin</b> if
-- the component is rendered.
-- ------------------------------
overriding
procedure Render_Select (UI : in UISelectOneRadio;
Context : in out Faces_Context'Class) is
Writer : constant Response_Writer_Access := Context.Get_Response_Writer;
Value : constant EL.Objects.Object := UISelectOne'Class (UI).Get_Value;
Vertical : constant Boolean := UI.Is_Vertical (Context);
Selected : constant Wide_Wide_String := Util.Beans.Objects.To_Wide_Wide_String (Value);
Iter : Cursor;
Id : constant String := To_String (UI.Get_Client_Id);
N : Natural := 0;
Disabled_Class : constant EL.Objects.Object := UI.Get_Attribute (Context => Context,
Name => "disabledClass");
Enabled_Class : constant EL.Objects.Object := UI.Get_Attribute (Context => Context,
Name => "enabledClass");
begin
Writer.Start_Element ("table");
UI.Render_Attributes (Context, Writer);
if not Vertical then
Writer.Start_Element ("tr");
end if;
UI.First (Context, Iter);
while Has_Element (Iter) loop
declare
Item : constant ASF.Models.Selects.Select_Item := Element (Iter, Context);
Item_Value : constant Wide_Wide_String := Item.Get_Value;
begin
if Vertical then
Writer.Start_Element ("tr");
end if;
Writer.Start_Element ("td");
-- Render the input radio checkbox.
Writer.Start_Element ("input");
Writer.Write_Attribute ("type", "radio");
Writer.Write_Attribute ("name", Id);
if Item.Is_Disabled then
Writer.Write_Attribute ("disabled", "disabled");
end if;
Writer.Write_Attribute ("id", Id & "_" & Util.Strings.Image (N));
Writer.Write_Wide_Attribute ("value", Item_Value);
if Item_Value = Selected then
Writer.Write_Attribute ("checked", "checked");
end if;
Writer.End_Element ("input");
-- Render the label associated with the checkbox.
Writer.Start_Element ("label");
if Item.Is_Disabled then
if not Util.Beans.Objects.Is_Null (Disabled_Class) then
Writer.Write_Attribute ("class", Disabled_Class);
end if;
else
if not Util.Beans.Objects.Is_Null (Enabled_Class) then
Writer.Write_Attribute ("class", Enabled_Class);
end if;
end if;
Writer.Write_Attribute ("for", Id & "_" & Util.Strings.Image (N));
if Item.Is_Escaped then
Writer.Write_Wide_Text (Item.Get_Label);
else
Writer.Write_Wide_Text (Item.Get_Label);
end if;
Writer.End_Element ("label");
Writer.End_Element ("td");
if Vertical then
Writer.End_Element ("tr");
end if;
Next (Iter, Context);
N := N + 1;
end;
end loop;
if not Vertical then
Writer.End_Element ("tr");
end if;
Writer.End_Element ("table");
end Render_Select;
begin
ASF.Utils.Set_Text_Attributes (SELECT_ATTRIBUTE_NAMES);
ASF.Utils.Set_Interactive_Attributes (SELECT_ATTRIBUTE_NAMES);
end ASF.Components.Html.Selects;
|
pragma License (Unrestricted);
-- runtime unit
package System.Synchronous_Control is
pragma Preelaborate;
-- no-operation
procedure Nop is null;
-- yield
type Yield_Handler is access procedure;
pragma Favor_Top_Level (Yield_Handler);
Yield_Hook : not null Yield_Handler := Nop'Access;
procedure Yield;
-- abortable region control
type Unlock_Abort_Handler is access procedure;
pragma Favor_Top_Level (Unlock_Abort_Handler);
Unlock_Abort_Hook : not null Unlock_Abort_Handler := Nop'Access;
-- enter abortable region (default is unabortable)
-- also, implementation of System.Standard_Library.Abort_Undefer_Direct
procedure Unlock_Abort
with Export,
Convention => Ada,
External_Name => "system__standard_library__abort_undefer_direct";
type Lock_Abort_Handler is access procedure;
pragma Favor_Top_Level (Lock_Abort_Handler);
Lock_Abort_Hook : not null Lock_Abort_Handler := Nop'Access;
-- leave abortable region
procedure Lock_Abort;
end System.Synchronous_Control;
|
-- Shoot'n'loot
-- Copyright (c) 2020 Fabien Chouteau
with Interfaces;
with VirtAPU; use VirtAPU;
with PyGamer.Audio; use PyGamer.Audio;
with Music_2;
package body Sound is
C_32nd : constant Command := (Wait_Ticks, 1);
C_16th : constant Command := (Wait_Ticks, C_32nd.Ticks * 2);
C_8th : constant Command := (Wait_Ticks, C_16th.Ticks * 2);
C_Quarter : constant Command := (Wait_Ticks, C_8th.Ticks * 2);
C_Half : constant Command := (Wait_Ticks, C_Quarter.Ticks * 2);
C_Whole : constant Command := (Wait_Ticks, C_Half.Ticks * 2);
C_Double : constant Command := (Wait_Ticks, C_Whole.Ticks * 2);
Coin_Seq : aliased constant Command_Array :=
((Set_Decay, 10),
(Set_Mode, Pulse),
(Set_Width, 25),
(Set_Sweep, None, 1, 0),
B4,
(Wait_Ticks, 3),
E5,
(Wait_Ticks, 5),
Off
);
Monster_Dead_Seq : aliased constant Command_Array :=
((Set_Decay, 20),
(Set_Mode, Pulse),
(Set_Width, 25),
(Set_Sweep, Down, 10, 1),
C3, C_Quarter, Off
);
Game_Over_Seq : aliased constant Command_Array :=
((Set_Decay, 20),
(Set_Mode, Pulse),
(Set_Width, 25),
Fs3, C_Quarter, Off,
C_Half,
Cs3, C_8th, Off, C_8th,
C_Quarter,
C3, Off, C_8th,
Cs3, Off, C_8th,
C3, C_Half, Off
);
Exit_Open_Seq : aliased constant Command_Array :=
((Set_Decay, 20),
(Set_Mode, Pulse),
(Set_Width, 25),
(Set_Sweep, None, 1, 0),
C4, C_16th, Off, C_16th,
Ds4, C_16th, Off, C_16th,
G4, C_16th, Off, C_16th,
As4, C_16th, Off
);
Exit_Taken_Seq : aliased constant Command_Array :=
((Set_Decay, 20),
(Set_Mode, Pulse),
(Set_Width, 25),
(Set_Sweep, None, 1, 0),
As4, C_16th, Off, C_16th,
G4, C_16th, Off, C_16th,
Ds4, C_16th, Off, C_16th,
C4, C_16th, Off
);
Victory_Seq : aliased constant Command_Array :=
((Set_Decay, 20),
(Set_Mode, Pulse),
(Set_Width, 25),
C_Double,
C4, C_16th, Off, C_16th,
Ds4, C_16th, Off, C_16th,
G4, C_16th, Off, C_16th,
As4, C_16th, Off, C_16th,
As4, C_16th, Off, C_16th,
As4, C_16th, Off, C_16th,
Ds5, C_16th, Off, C_16th,
As4, C_16th, Off, C_16th
);
Jump_Seq : aliased constant Command_Array :=
((Set_Decay, 20),
(Set_Mode, Pulse),
(Set_Sweep, Up, 7, 2),
(Note_On, 220.0),
C_8th,
Off
);
Gun_Seq : aliased constant Command_Array :=
((Set_Mode, Noise_1),
(Set_Decay, 15),
(Set_Sweep, Up, 13, 0),
(Set_Mode, Noise_1),
(Note_On, 2000.0),
Off
);
Kick : aliased constant Command_Array :=
((Set_Decay, 6),
(Set_Sweep, Up, 7, 0),
(Set_Mode, Noise_2),
(Note_On, 150.0),
Off
);
Snare : aliased constant Command_Array :=
((Set_Decay, 6),
(Set_Mode, Noise_1),
(Note_On, 2000.0),
Off
);
Hi_Hat : aliased constant Command_Array :=
((Set_Decay, 2),
(Set_Mode, Noise_1),
(Note_On, 10000.0),
Off
);
Beat_1 : constant Command_Array :=
Kick & C_Half &
Hi_Hat & C_Half &
Snare & C_Half &
Hi_Hat & C_Half &
Kick & C_Half &
Hi_Hat & C_Half &
Snare & C_Half &
Hi_Hat & C_Half;
Beat_2 : constant Command_Array :=
Kick & C_Half &
Hi_Hat & C_Half &
Snare & C_Half &
Hi_Hat & C_Half &
Kick & C_Half &
Hi_Hat & C_Half &
Snare & C_Half &
Snare & C_Half;
Beat_3 : constant Command_Array :=
Kick & C_Half &
Hi_Hat & C_Half &
Snare & C_Half &
Hi_Hat & C_Half &
Kick & C_Half &
Hi_Hat & C_Half &
Snare & C_Half &
Snare & C_Quarter &
Snare & C_Quarter;
Drums_Seq : aliased constant Command_Array :=
Beat_1 & Beat_2 & Beat_3 & Beat_2;
Bass_1 : constant Command_Array :=
C2 & C_Half & Off &
C_Half &
C2 & C_Half & Off &
C_Half &
C2 & C_Half & Off &
Ds2 & C_Half & Off &
C_Half &
Gs2 & C_Half & Off;
Bass_2 : constant Command_Array :=
C_Half &
Ds2 & C_Half & Off &
C_Half &
Fs2 & C_Half & Off &
C_Half &
Ds2 & C_Half & Off &
Fs2 & C_Half & Off &
Ds2 & C_Half & Off;
Bass_3 : constant Command_Array :=
C_Half &
Ds2 & C_Half & Off &
C_Half &
Fs2 & C_Half & Off &
C_Half &
Gs2 & C_Half & Off &
Fs2 & C_Half & Off &
C_Half;
Bass_Seq : aliased constant Command_Array :=
Bass_1 & Bass_2 & Bass_1 & Bass_3;
Lead_1 : constant Command_Array :=
C4 & Off &
C_Whole & C_Whole & C_Half &
Ds4 & Off &
C_Whole &
G4 & Off &
C_Whole & C_Whole & C_Whole &
Fs4 & Off &
C_Half &
Gs4 & Off &
C_Half &
Ds4 & Off &
C_Half;
Lead_2 : constant Command_Array :=
C4 & Off &
C_Whole & C_Whole & C_Half &
Ds4 & Off &
C_Whole &
Gs3 & Off &
C_Whole & C_Whole & C_Whole &
G3 & Off &
C_Half &
As3 & Off &
C_Half &
B3 & Off &
C_Half;
Lead_3 : constant Command_Array :=
C4 & Off &
C_Whole & C_Whole & C_Half &
G4 & Off &
C_Half &
As4 & Off &
C_Half &
Fs4 & Off &
C_Whole & C_Whole & C_Whole &
Gs4 & Off &
C_Half &
G4 & Off &
C_Half &
Ds4 & Off &
C_Half;
Lead_Seq : aliased constant Command_Array :=
Lead_1 & Lead_2 & Lead_3 & Lead_2;
Sample_Rate : constant Sample_Rate_Kind := SR_22050;
APU : VirtAPU.Instance (5, 22_050);
Player_FX : constant VirtAPU.Channel_ID := 1;
World_FX : constant VirtAPU.Channel_ID := 2;
Drums : constant VirtAPU.Channel_ID := 3;
Bass : constant VirtAPU.Channel_ID := 4;
Lead : constant VirtAPU.Channel_ID := 5;
procedure Next_Samples is new VirtAPU.Next_Samples_UInt
(Interfaces.Unsigned_16, PyGamer.Audio.Data_Array);
procedure Audio_Callback (Left, Right : out PyGamer.Audio.Data_Array);
--------------------
-- Audio_Callback --
--------------------
procedure Audio_Callback (Left, Right : out PyGamer.Audio.Data_Array) is
begin
Next_Samples (APU, Left);
Right := Left;
end Audio_Callback;
----------
-- Tick --
----------
procedure Tick is
begin
APU.Tick;
end Tick;
---------------
-- Play_Coin --
---------------
procedure Play_Coin is
begin
APU.Run (World_FX, Coin_Seq'Access);
end Play_Coin;
-----------------------
-- Play_Monster_Dead --
-----------------------
procedure Play_Monster_Dead is
begin
APU.Run (World_FX, Monster_Dead_Seq'Access);
end Play_Monster_Dead;
--------------
-- Play_Gun --
--------------
procedure Play_Gun is
begin
APU.Run (Player_FX, Gun_Seq'Access);
end Play_Gun;
---------------
-- Play_Jump --
---------------
procedure Play_Jump is
begin
APU.Run (Player_FX, Jump_Seq'Access);
end Play_Jump;
--------------------
-- Play_Exit_Open --
--------------------
procedure Play_Exit_Open is
begin
APU.Run (World_FX, Exit_Open_Seq'Access);
end Play_Exit_Open;
---------------------
-- Play_Exit_Taken --
---------------------
procedure Play_Exit_Taken is
begin
APU.Run (World_FX, Exit_Taken_Seq'Access);
end Play_Exit_Taken;
-------------------
-- Play_Gameover --
-------------------
procedure Play_Gameover is
begin
APU.Set_Volume (Drums, 0);
APU.Note_Off (Bass);
APU.Run (Bass, Empty_Seq, Looping => False);
APU.Set_Volume (Bass, 0);
APU.Note_Off (Bass);
APU.Run (Bass, Empty_Seq, Looping => False);
APU.Set_Volume (Lead, 50);
APU.Run (Lead, Game_Over_Seq'Access, Looping => False);
end Play_Gameover;
------------------
-- Play_Victory --
------------------
procedure Play_Victory is
begin
APU.Set_Volume (Drums, 0);
APU.Note_Off (Bass);
APU.Run (Bass, Empty_Seq, Looping => False);
APU.Set_Volume (Bass, 0);
APU.Note_Off (Bass);
APU.Run (Bass, Empty_Seq, Looping => False);
APU.Set_Volume (Lead, 50);
APU.Run (Lead, Victory_Seq'Access, Looping => False);
end Play_Victory;
---------------------
-- Play_Main_Theme --
---------------------
procedure Play_Main_Theme is
begin
APU.Run (Drums, Drums_Seq'Access, Looping => True);
APU.Set_Volume (Drums, 50);
APU.Set_Mode (Bass, Triangle);
APU.Set_Decay (Bass, 7);
APU.Set_Volume (Bass, 50);
APU.Run (Bass, Bass_Seq'Access, Looping => True);
APU.Set_Mode (Lead, Pulse);
APU.Set_Decay (Lead, 40);
APU.Set_Width (Lead, 25);
APU.Set_Volume (Lead, 50);
APU.Run (Lead, Lead_Seq'Access, Looping => True);
end Play_Main_Theme;
-------------------
-- Play_Gameplay --
-------------------
procedure Play_Gameplay is
begin
APU.Run (Drums, Music_2.Drums'Access, Looping => True);
APU.Set_Volume (Drums, 50);
APU.Set_Mode (Bass, Triangle);
APU.Set_Decay (Bass, 7);
APU.Set_Volume (Bass, 50);
APU.Run (Bass, Music_2.Bass'Access, Looping => True);
APU.Set_Volume (Lead, 0);
APU.Note_Off (Lead);
APU.Run (Lead, Empty_Seq, Looping => False);
end Play_Gameplay;
begin
PyGamer.Audio.Set_Callback (Audio_Callback'Access, Sample_Rate);
APU.Set_Rhythm (120, 60);
end Sound;
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- P A R . L O A D --
-- --
-- B o d y --
-- --
-- Copyright (C) 1992-2015, 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. 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 COPYING3. If not, go to --
-- http://www.gnu.org/licenses for a complete copy of the license. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
-- The Par.Load procedure loads all units that are definitely required before
-- it makes any sense at all to proceed with semantic analysis, including
-- with'ed units, corresponding specs for bodies, parents of child specs,
-- and parents of subunits. All these units are loaded and pointers installed
-- in the tree as described in the spec of package Lib.
with Fname.UF; use Fname.UF;
with Lib.Load; use Lib.Load;
with Namet.Sp; use Namet.Sp;
with Uname; use Uname;
with Osint; use Osint;
with Sinput.L; use Sinput.L;
with Stylesw; use Stylesw;
with Validsw; use Validsw;
with GNAT.Spelling_Checker; use GNAT.Spelling_Checker;
separate (Par)
procedure Load is
File_Name : File_Name_Type;
-- Name of file for current unit, derived from unit name
Cur_Unum : constant Unit_Number_Type := Current_Source_Unit;
-- Unit number of unit that we just finished parsing. Note that we need
-- to capture this, because Source_Unit will change as we parse new
-- source files in the multiple main source file case.
Curunit : constant Node_Id := Cunit (Cur_Unum);
-- Compilation unit node for current compilation unit
Loc : Source_Ptr := Sloc (Curunit);
-- Source location for compilation unit node
Save_Style_Check : Boolean;
Save_Style_Checks : Style_Check_Options;
-- Save style check so it can be restored later
Save_Validity_Check : Boolean;
Save_Validity_Checks : Validity_Check_Options;
-- Save validity check so it can be restored later
With_Cunit : Node_Id;
-- Compilation unit node for withed unit
Context_Node : Node_Id;
-- Next node in context items list
With_Node : Node_Id;
-- N_With_Clause node
Spec_Name : Unit_Name_Type;
-- Unit name of required spec
Body_Name : Unit_Name_Type;
-- Unit name of corresponding body
Unum : Unit_Number_Type;
-- Unit number of loaded unit
Limited_With_Found : Boolean := False;
-- We load the context items in two rounds: the first round handles normal
-- withed units and the second round handles Ada 2005 limited-withed units.
-- This is required to allow the low-level circuitry that detects circular
-- dependencies of units the correct notification of errors (see comment
-- bellow). This variable is used to indicate that the second round is
-- required.
function Same_File_Name_Except_For_Case
(Expected_File_Name : File_Name_Type;
Actual_File_Name : File_Name_Type) return Boolean;
-- Given an actual file name and an expected file name (the latter being
-- derived from the unit name), determine if they are the same except for
-- possibly different casing of letters.
------------------------------------
-- Same_File_Name_Except_For_Case --
------------------------------------
function Same_File_Name_Except_For_Case
(Expected_File_Name : File_Name_Type;
Actual_File_Name : File_Name_Type) return Boolean
is
begin
Get_Name_String (Actual_File_Name);
Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
declare
Lower_Case_Actual_File_Name : String (1 .. Name_Len);
begin
Lower_Case_Actual_File_Name := Name_Buffer (1 .. Name_Len);
Get_Name_String (Expected_File_Name);
Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
return Lower_Case_Actual_File_Name = Name_Buffer (1 .. Name_Len);
end;
end Same_File_Name_Except_For_Case;
-- Start of processing for Load
begin
-- Don't do any loads if we already had a fatal error
if Fatal_Error (Cur_Unum) = Error_Detected then
return;
end if;
Save_Style_Check_Options (Save_Style_Checks);
Save_Style_Check := Opt.Style_Check;
Save_Validity_Check_Options (Save_Validity_Checks);
Save_Validity_Check := Opt.Validity_Checks_On;
-- If main unit, set Main_Unit_Entity (this will get overwritten if
-- the main unit has a separate spec, that happens later on in Load)
if Cur_Unum = Main_Unit then
Main_Unit_Entity := Cunit_Entity (Main_Unit);
end if;
-- If we have no unit name, things are seriously messed up by previous
-- errors, and we should not try to continue compilation.
if Unit_Name (Cur_Unum) = No_Unit_Name then
raise Unrecoverable_Error;
end if;
-- Next step, make sure that the unit name matches the file name
-- and issue a warning message if not. We only output this for the
-- main unit, since for other units it is more serious and is
-- caught in a separate test below. We also inhibit the message in
-- multiple unit per file mode, because in this case the relation
-- between file name and unit name is broken.
File_Name :=
Get_File_Name
(Unit_Name (Cur_Unum),
Subunit => Nkind (Unit (Cunit (Cur_Unum))) = N_Subunit);
if Cur_Unum = Main_Unit
and then Multiple_Unit_Index = 0
and then File_Name /= Unit_File_Name (Cur_Unum)
and then (File_Names_Case_Sensitive
or not Same_File_Name_Except_For_Case
(File_Name, Unit_File_Name (Cur_Unum)))
then
Error_Msg_File_1 := File_Name;
Error_Msg
("??file name does not match unit name, should be{", Sloc (Curunit));
end if;
-- For units other than the main unit, the expected unit name is set and
-- must be the same as the actual unit name, or we are in big trouble, and
-- abandon the compilation since there are situations where this really
-- gets us into bad trouble (e.g. some subunit situations).
if Cur_Unum /= Main_Unit
and then Expected_Unit (Cur_Unum) /= Unit_Name (Cur_Unum)
then
Loc := Error_Location (Cur_Unum);
Error_Msg_File_1 := Unit_File_Name (Cur_Unum);
Get_Name_String (Error_Msg_File_1);
-- Check for predefined file case
if Name_Len > 1
and then Name_Buffer (2) = '-'
and then (Name_Buffer (1) = 'a'
or else
Name_Buffer (1) = 's'
or else
Name_Buffer (1) = 'i'
or else
Name_Buffer (1) = 'g')
then
declare
Expect_Name : constant Unit_Name_Type := Expected_Unit (Cur_Unum);
Actual_Name : constant Unit_Name_Type := Unit_Name (Cur_Unum);
begin
Error_Msg_Unit_1 := Expect_Name;
Error_Msg -- CODEFIX
("$$ is not a predefined library unit!", Loc);
-- In the predefined file case, we know the user did not
-- construct their own package, but we got the wrong one.
-- This means that the name supplied by the user crunched
-- to something we recognized, but then the file did not
-- contain the unit expected. Most likely this is due to
-- a misspelling, e.g.
-- with Ada.Calender;
-- This crunches to a-calend, which indeed contains the unit
-- Ada.Calendar, and we can diagnose the misspelling. This
-- is a simple heuristic, but it catches many common cases
-- of misspelling of predefined unit names without needing
-- a full list of them.
-- Before actually issuing the message, we will check that the
-- unit name is indeed a plausible misspelling of the one we got.
if Is_Bad_Spelling_Of
(Name_Id (Expect_Name), Name_Id (Actual_Name))
then
Error_Msg_Unit_1 := Actual_Name;
Error_Msg -- CODEFIX
("possible misspelling of $$!", Loc);
end if;
end;
-- Non-predefined file name case. In this case we generate a message
-- and then we quit, because we are in big trouble, and if we try
-- to continue compilation, we get into some nasty situations
-- (for example in some subunit cases).
else
Error_Msg ("file { does not contain expected unit!", Loc);
Error_Msg_Unit_1 := Expected_Unit (Cur_Unum);
Error_Msg ("\\expected unit $!", Loc);
Error_Msg_Unit_1 := Unit_Name (Cur_Unum);
Error_Msg ("\\found unit $!", Loc);
end if;
-- In both cases, remove the unit if it is the last unit (which it
-- normally (always?) will be) so that it is out of the way later.
Remove_Unit (Cur_Unum);
end if;
-- If current unit is a body, load its corresponding spec
if Nkind (Unit (Curunit)) = N_Package_Body
or else Nkind (Unit (Curunit)) = N_Subprogram_Body
then
Spec_Name := Get_Spec_Name (Unit_Name (Cur_Unum));
Unum :=
Load_Unit
(Load_Name => Spec_Name,
Required => False,
Subunit => False,
Error_Node => Curunit,
Corr_Body => Cur_Unum,
PMES => (Cur_Unum = Main_Unit));
-- If we successfully load the unit, then set the spec/body pointers.
-- Once again note that if the loaded unit has a fatal error, Load will
-- have set our Fatal_Error flag to propagate this condition.
if Unum /= No_Unit then
Set_Library_Unit (Curunit, Cunit (Unum));
Set_Library_Unit (Cunit (Unum), Curunit);
-- If this is a separate spec for the main unit, then we reset
-- Main_Unit_Entity to point to the entity for this separate spec
-- and this is also where we generate the SCO's for this spec.
if Cur_Unum = Main_Unit then
Main_Unit_Entity := Cunit_Entity (Unum);
if Generate_SCO then
SCO_Record_Raw (Unum);
end if;
end if;
-- If we don't find the spec, then if we have a subprogram body, we
-- are still OK, we just have a case of a body acting as its own spec
elsif Nkind (Unit (Curunit)) = N_Subprogram_Body then
Set_Acts_As_Spec (Curunit, True);
Set_Library_Unit (Curunit, Curunit);
-- Otherwise we do have an error, repeat the load request for the spec
-- with Required set True to generate an appropriate error message.
else
Unum :=
Load_Unit
(Load_Name => Spec_Name,
Required => True,
Subunit => False,
Error_Node => Curunit);
return;
end if;
-- If current unit is a child unit spec, load its parent. If the child unit
-- is loaded through a limited with, the parent must be as well.
elsif Nkind (Unit (Curunit)) = N_Package_Declaration
or else Nkind (Unit (Curunit)) = N_Subprogram_Declaration
or else Nkind (Unit (Curunit)) in N_Generic_Declaration
or else Nkind (Unit (Curunit)) in N_Generic_Instantiation
or else Nkind (Unit (Curunit)) in N_Renaming_Declaration
then
-- Turn style and validity checks off for parent unit
if not GNAT_Mode then
Reset_Style_Check_Options;
Reset_Validity_Check_Options;
end if;
Spec_Name := Get_Parent_Spec_Name (Unit_Name (Cur_Unum));
if Spec_Name /= No_Unit_Name then
Unum :=
Load_Unit
(Load_Name => Spec_Name,
Required => True,
Subunit => False,
Error_Node => Curunit);
if Unum /= No_Unit then
Set_Parent_Spec (Unit (Curunit), Cunit (Unum));
end if;
end if;
-- If current unit is a subunit, then load its parent body
elsif Nkind (Unit (Curunit)) = N_Subunit then
Body_Name := Get_Parent_Body_Name (Unit_Name (Cur_Unum));
Unum :=
Load_Unit
(Load_Name => Body_Name,
Required => True,
Subunit => False,
Error_Node => Name (Unit (Curunit)));
if Unum /= No_Unit then
Set_Library_Unit (Curunit, Cunit (Unum));
end if;
end if;
-- Now we load with'ed units, with style/validity checks turned off
if not GNAT_Mode then
Reset_Style_Check_Options;
Reset_Validity_Check_Options;
end if;
-- Load the context items in two rounds: the first round handles normal
-- withed units and the second round handles Ada 2005 limited-withed units.
-- This is required to allow the low-level circuitry that detects circular
-- dependencies of units the correct notification of the following error:
-- limited with D;
-- with D; with C;
-- package C is ... package D is ...
for Round in 1 .. 2 loop
Context_Node := First (Context_Items (Curunit));
while Present (Context_Node) loop
-- During the first round we check if there is some limited-with
-- context clause; otherwise the second round will be skipped
if Nkind (Context_Node) = N_With_Clause
and then Round = 1
and then Limited_Present (Context_Node)
then
Limited_With_Found := True;
end if;
if Nkind (Context_Node) = N_With_Clause
and then ((Round = 1 and then not Limited_Present (Context_Node))
or else
(Round = 2 and then Limited_Present (Context_Node)))
then
With_Node := Context_Node;
Spec_Name := Get_Unit_Name (With_Node);
Unum :=
Load_Unit
(Load_Name => Spec_Name,
Required => False,
Subunit => False,
Error_Node => With_Node,
Renamings => True,
With_Node => Context_Node);
-- If we find the unit, then set spec pointer in the N_With_Clause
-- to point to the compilation unit for the spec. Remember that
-- the Load routine itself sets our Fatal_Error flag if the loaded
-- unit gets a fatal error, so we don't need to worry about that.
if Unum /= No_Unit then
Set_Library_Unit (With_Node, Cunit (Unum));
-- If the spec isn't found, then try finding the corresponding
-- body, since it is possible that we have a subprogram body
-- that is acting as a spec (since no spec is present).
else
Body_Name := Get_Body_Name (Spec_Name);
Unum :=
Load_Unit
(Load_Name => Body_Name,
Required => False,
Subunit => False,
Error_Node => With_Node,
Renamings => True);
-- If we got a subprogram body, then mark that we are using
-- the body as a spec in the file table, and set the spec
-- pointer in the N_With_Clause to point to the body entity.
if Unum /= No_Unit
and then Nkind (Unit (Cunit (Unum))) = N_Subprogram_Body
then
With_Cunit := Cunit (Unum);
Set_Library_Unit (With_Node, With_Cunit);
Set_Acts_As_Spec (With_Cunit, True);
Set_Library_Unit (With_Cunit, With_Cunit);
-- If we couldn't find the body, or if it wasn't a body spec
-- then we are in trouble. We make one more call to Load to
-- require the spec. We know it will fail of course, the
-- purpose is to generate the required error message (we prefer
-- that this message refer to the missing spec, not the body)
else
Unum :=
Load_Unit
(Load_Name => Spec_Name,
Required => True,
Subunit => False,
Error_Node => With_Node,
Renamings => True);
-- Here we create a dummy package unit for the missing unit
Unum := Create_Dummy_Package_Unit (With_Node, Spec_Name);
Set_Library_Unit (With_Node, Cunit (Unum));
end if;
end if;
end if;
Next (Context_Node);
end loop;
exit when not Limited_With_Found;
end loop;
-- Restore style/validity check mode for main unit
Set_Style_Check_Options (Save_Style_Checks);
Opt.Style_Check := Save_Style_Check;
Set_Validity_Check_Options (Save_Validity_Checks);
Opt.Validity_Checks_On := Save_Validity_Check;
end Load;
|
----------------------------csc410/prog5/as5.adb----------------------------
-- Author: Matthew Bennett
-- Class: CSC410 Burgess
-- Date: 11-01-04 Modified: 11-15-04
-- Due: 11-16-04
-- Desc: Assignment 5: LAMPORT'S ALGORITHM FOR VIRTUAL TOPOLOGY NETWORKS
--
-- a nonproduction implementation of
-- LAMPORT's "bakery" algorithm which utilizes clocks (a 'ticketing' system
-- like IN the bakery or at the dept of motor vehicles) to determine which
-- process may go into the critical section next.
--
-- LAMPORT implemented as described IN
-- "Algorithms FOR Mutual Exclusion", M. Raynal
-- MIT PRESS Cambridge, 1986 ISBN: 0-262-18119-3
-- with additional revisions due to message passing across a virtual topology
----------------------------------------------------------------------------
----------------------------------------------------------------
-- dependencies
WITH ADA.TEXT_IO; USE ADA.TEXT_IO;
WITH ADA.INTEGER_TEXT_IO; USE ADA.INTEGER_TEXT_IO;
WITH ADA.NUMERICS.FLOAT_RANDOM; USE ADA.NUMERICS.FLOAT_RANDOM;
WITH ADA.CALENDAR; -- (provides cast: natural -> time FOR input into delay)
WITH ADA.STRINGS; USE ADA.STRINGS;
WITH ADA.STRINGS.UNBOUNDED; USE ADA.STRINGS.UNBOUNDED;
PROCEDURE Main IS
--GLOBALS VARS: randomPool, taskarray, go, stop
randomPool : ADA.NUMERICS.FLOAT_RANDOM.GENERATOR;
--random number pool FOR generating
go, stop: Boolean := FALSE; --allow FOR graceful execution and termination
TYPE MESG IS (REQ, ACK, REL);
PACKAGE MESG_IO IS NEW Enumeration_IO(MESG); USE MESG_IO;
--so that we can natively output enumerated type
MAX_NEIGHBORS : CONSTANT := 30;
--maximum number of neighbors, FOR efficiency IN array passing
-- 1/2 of this num is the same as euler # FOR a graph
MAX_TASKS : CONSTANT := 20;
--maximum number of neighbors, FOR efficiency IN array passing
TYPE type_message IS (REQ, ACK, REL); --request, acknowledge, release
PACKAGE ENUM_IO IS NEW Enumeration_IO(type_message); Use ENUM_IO;
--allow input and output of our enumerated names
TYPE RX_TASK;
TYPE RX_Ptr IS ACCESS RX_TASK;
--forward declaration needed FOR access type to RX_TASK FOR array of access es
TYPE passableArray IS ARRAY (0..MAX_NEIGHBORS) OF Integer;
--this is needed bc anonymous types are not allowed IN declarations
--specifically, so that we can pass arrays around between entries as arguments
taskArray : ARRAY (0..MAX_NEIGHBORS) OF RX_Ptr;
--keep up with tasks thrown off
-- Receive/listener task
TASK TYPE RX_TASK IS
ENTRY Start( id_IN : IN Integer; Neighbors_IN : IN passableArray);
--initialize variables
ENTRY FWD(dest: Integer; msg: type_message; k: Integer; j: Integer);
--method used to propogate messages through the network until dest = self
ENTRY kill;
--kill off the task, politely ask it to die
ENTRY REQUEST;
ENTRY ACKNOWLEDGE;
ENTRY RELEASE;
END RX_TASK;
-- BEGIN Receive TASK Definition --
TASK BODY RX_TASK IS
TYPE message IS
RECORD
mestype: type_message := rel;
clock: Integer := 0;
id: Integer;
END RECORD;
queue: ARRAY (0 .. MAX_TASKS) OF message;
--the distributed queue of messages
Neighbors : passableArray;
--keeps track of who task can send to, receive from
id : Integer;
--self identification
outp : Unbounded_String := Null_Unbounded_String;
--temporary string variable FOR uninterrupted output
friends : ARRAY(0..MAX_NEIGHBORS) OF RX_PTR;
--used FOR calling on receiver tasks
osn, tempOSN : Integer := 0;
--"own sequence number", Lamport clock FOR task
temp1, temp2: message;
FOR_all: boolean := TRUE;
dead: boolean := FALSE;
--temporary variables
TASK TYPE TX_TASK (
--seperate task, so it can be spawned any time!
dest: Integer; --destination IN network
mess: MESG; --the message itself
clock: Integer; --the sequence number of the sending process
i: Integer --sending process id #
)
IS --seperate task, so we can spawn a send -whenever- asynchronously
--ge that was short
END TX_TASK;
TYPE TX_PTR IS ACCESS TX_TASK;
myTX : TX_PTR; --so we can launch transmit task anytime
TASK BODY TX_TASK IS
BEGIN
null;
END TX_TASK; --definition
TASK TYPE AL_TASK
--gee, that was short
IS END AL_TASK;
--internal task, FOR lamport's algorithm
TASK BODY AL_TASK IS
BEGIN
LOOP
FOR index IN 0 .. MAX_NEIGHBORS LOOP
queue(index).id := index;
END LOOP;
EXIT WHEN (go);
END LOOP;
--intitialize the queue so that each element stores the proper process id
LOOP
--broadcast
FOR I IN 0..n
LOOP
IF(I /= id)THEN tsk_TX := new transmit(I, req, local_clock, id); END IF;
END LOOP;
q(id) := (req, local_clock, id);
osn := osn + 1;
tempOSN := osn;
wait:
LOOP
FOR j IN 0..n
LOOP
IF j /= id THEN
IF((q(id).clock < q(j).clock)
OR ((q(id).clock = q(j).clock) AND (q(id).id < q(j).id)))
THEN null;
ELSE FOR_all := FALSE;
END IF;
END IF;
END LOOP;
EXIT wait WHEN (FOR_all = TRUE);
FOR_all := TRUE;
END LOOP wait;
EXIT WHEN dead = TRUE;
outp := (((80/6)*id) * " ") & Integer'Image(id) & " IN CS.";
Put(To_String(outp)); New_line;
delay Duration(float(random(G)) + float(10));
st := (((80/(n+1))*id) * " ") & Integer'Image(id) & " out CS.";
Put_line(To_String(st));
-- broadcast
local_clock := osn;
FOR I IN 0..n
LOOP
IF(I /= id)THEN
tsk_TX := new transmit(I, rel, local_clock, id);
END IF;
END LOOP;
q(id) := (rel, local_clock, id);
osn := osn + 1;
local_clock := osn;
EXIT WHEN dead = TRUE;
END LOOP;
END AL_TASK;
TYPE AL_Ptr IS ACCESS AL_TASK;
aPtr : AL_Ptr;
--END of internal task, FOR lamport's algorithm
-- beginnig of RX_TASK definition
BEGIN
-- ACCEPT creation messages --
ACCEPT Start (
id_IN : IN Integer;
Neighbors_IN : IN passableArray
)
DO
--initialize neighbors array
FOR I IN Neighbors'First .. Neighbors'Last
LOOP
Neighbors(I) := Neighbors_IN(I);
END LOOP;
id := id_IN;
END Start;
ACCEPT KILL
DO
null;
END KILL;
ACCEPT FWD(dest: Integer; msg: type_message; k: Integer; j: Integer)
DO
null;
END FWD;
SELECT
ACCEPT REQUEST
DO
null;
END REQUEST;
ACCEPT ACKNOWLEDGE --acknkowledge
DO
null;
END ACKNOWLEDGE;
ACCEPT RELEASE
DO
null;
END RELEASE;
END SELECT;
-- RX_TASK definition
aPtr := new AL_TASK; -- spin off lamport task
-- Start Message Receiving LOOP --
--LOOP
null;
--END LOOP; -- RX LOOP
END RX_TASK;
PROCEDURE Driver IS
seedUser : Integer;
--user input random seed FOR random number generator
infile : FILE_TYPE;
--ada.standard.textIO type FOR reading ascii and iso-8XXX
filename : string(1..5);
--what file should we read from?
--Following are variables FOR building logical network topologies
taskId : Integer;
--temporary FOR keeping track of which task we are reading IN
neighbors : passableArray;
--array of neighbors to be passed into a node upon initialization
neighborCount : Integer;
--temporary to keep up with number of neighbors FOR a certain task/node
--killing time variables
toKill : Integer;
--assigned a random ID to determine which process to kill next
dead : ARRAY (0..MAX_TASKS) of Boolean := (Others => FALSE);
--keeps track of which processes have been slain, so we dont try to kill a
--process twice , which would raise an exception
BEGIN
put_line("Lamport's Algorithm");
put("# random seed: ");
get(seedUser); --to ensure a significantly random series, a seed is needed
-- to generate pseudo-random numbers
Ada.Numerics.Float_Random.Reset(randomPool,seedUser);
--seed the random number pool
put("Filename: ");
get(filename);
--first lets read IN the
Open (File=> inFile, Mode => IN_FILE, Name => filename);
--open as read only ascii and use reference infile
--file format is: nodeID neighbor neighbor neighbor...neighbor[MAX_NEIGHBORS]
WHILE NOT END_OF_FILE(infile)
LOOP
neighborCount := 0;
--receive file input
Get(infile, TASKId);
WHILE NOT END_OF_LINE(infile) --there is routing information on the line
LOOP
Get(infile, neighbors(neighborCount) );
neighborCount := neighborCount + 1;
END LOOP;
--we can have one tight LOOP now since this time
-- all neighbors are known ahead of time
--create and initialize part FOR nodes/tasks
taskArray(TASKId) := new RX_TASK;
taskArray(TASKId).start(taskId, neighbors);
END LOOP; --END of file reading LOOP
go := TRUE;
-- DELAY Duration(60.0); --allow things to run 1 minute before doom
Put("Number of tasks: "); Put (taskID); new_line;
--kill off random processes
FOR kill_index IN 0 .. (TaskID) --FOR as many as there are tasks
LOOP
delay (1.0);
Put ("Going to kill random process ... ");
toKill := (Integer(random(randomPool)) MOD TaskID);
WHILE (dead(toKill))
LOOP --iterate until process toKill isn't one that is already dead!
toKill := toKill + 1 MOD TaskID; --random didnt cut it, try the next one
END LOOP;
Put (toKill); new_line;
taskArray(toKill).kill; --kill off our random process
dead(toKill) := TRUE;
END LOOP; --END LOOP to kill out all processes
stop := TRUE;
Close(infile);
EXCEPTION
WHEN Name_Error =>
Put(Item => "File not found.");
WHEN Status_Error =>
Put(Item => "File already open.");
WHEN Use_Error =>
Put(Item => "You lack permission to open file");
-- WHEN constraint_Error =>
-- Put(Item => "problem IN code! constraint error thrown");
END Driver;
BEGIN Driver; END Main; --seperation of global vars
|
------------------------------------------------------------------------------
-- Copyright (c) 2016, Natacha Porté --
-- --
-- Permission to use, copy, modify, and 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. --
------------------------------------------------------------------------------
------------------------------------------------------------------------------
-- Natools.Smaz is a re-implementation of the short string compression --
-- algorithm "Smaz" by Salvatore Sanfilippo --
-- (see https://github.com/antirez/smaz). --
-- Its main selling point is its simplicity and CPU performance. However --
-- the implementation here emphasizes correctness (which greatly benefits --
-- from simplicity) over performance (so no benchmarks have been made). --
-- --
-- The basic idea behind the algorithm is that bytes in the encoded (and --
-- hopefully compressed) message are indexes in a static compiled-in --
-- dictionary, and two special byte values to mark verbatim data. --
-- --
-- For example, using original Smaz dictionary, the string "Athe33" is --
-- encoded as (254, 65, 1, 255, 1, 51, 51), which can be broken down as: --
-- * 254 to mark the following byte as verbatim --
-- * 65 which is verbatim byte for 'A' --
-- * 1 to mark the second word in the dictionary: "the" --
-- * 255 to mark variable-length verbatim escape --
-- * 1 to encoding the length of the verbatim fragment: 2 bytes --
-- * 51, 51 the verbatim bytes for "33". --
-- --
-- Note that the encoder has been improved over the original Smaz encoder, --
-- in that it merges adjacent verbatim fragments when it makes the output --
-- smaller. For example, with the input 5-byte string "33 33", the original --
-- naive encoder would produce the 9-byte output --
-- (255, 1, 51, 51, 0, 255, 1, 51, 51), while encoder here would encode the --
-- whole string in a single verbatim fragment, leading to the 7-byte output --
-- (255, 4, 51, 51, 32, 51, 51). --
------------------------------------------------------------------------------
with Ada.Streams;
package Natools.Smaz is
pragma Pure (Natools.Smaz);
use type Ada.Streams.Stream_Element;
type Offset_Array is
array (Ada.Streams.Stream_Element range <>) of Positive;
type Dictionary
(Dict_Last : Ada.Streams.Stream_Element;
String_Size : Natural)
is record
Variable_Length_Verbatim : Boolean;
Max_Word_Length : Positive;
Offsets : Offset_Array (0 .. Dict_Last);
Values : String (1 .. String_Size);
Hash : not null access function (Value : String) return Natural;
end record with
Dynamic_Predicate => (for all I in Dictionary.Offsets'Range
=> Dictionary.Offsets (I) in Dictionary.Values'Range
and then ((if I = Dictionary.Offsets'Last
then Dictionary.Values'Last + 1
else Dictionary.Offsets (I + 1))
- Dictionary.Offsets (I)
in 1 .. Dictionary.Max_Word_Length));
function Dict_Entry
(Dict : in Dictionary;
Index : in Ada.Streams.Stream_Element)
return String
with Pre => Index <= Dict.Dict_Last;
-- Return the string for at the given Index in Dict
function Compressed_Upper_Bound
(Dict : in Dictionary;
Input : in String)
return Ada.Streams.Stream_Element_Count;
-- Return the maximum number of bytes needed to encode Input
procedure Compress
(Dict : in Dictionary;
Input : in String;
Output_Buffer : out Ada.Streams.Stream_Element_Array;
Output_Last : out Ada.Streams.Stream_Element_Offset);
-- Encode Input into Output_Buffer
function Compress (Dict : in Dictionary; Input : in String)
return Ada.Streams.Stream_Element_Array;
-- Return an encoded buffer for Input
function Decompressed_Length
(Dict : in Dictionary;
Input : in Ada.Streams.Stream_Element_Array)
return Natural;
-- Return the exact length when Input is decoded
procedure Decompress
(Dict : in Dictionary;
Input : in Ada.Streams.Stream_Element_Array;
Output_Buffer : out String;
Output_Last : out Natural);
-- Decode Input into Output_Buffer
function Decompress
(Dict : in Dictionary; Input : in Ada.Streams.Stream_Element_Array)
return String;
-- Return a decoded buffer for Input
end Natools.Smaz;
|
package body Stack is
procedure Push(Object:Integer) is
begin
-- implementation goes here
end;
function Pull return Integer;
begin
-- implementation goes here
end;
end Stack;
|
package GESTE_Fonts.FreeSerifItalic5pt7b is
Font : constant Bitmap_Font_Ref;
private
FreeSerifItalic5pt7bBitmaps : aliased constant Font_Bitmap := (
16#00#, 16#00#, 16#00#, 16#00#, 16#02#, 16#01#, 16#01#, 16#00#, 16#80#,
16#40#, 16#00#, 16#20#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#05#, 16#02#, 16#80#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#02#, 16#81#, 16#41#, 16#E0#,
16#A0#, 16#F8#, 16#50#, 16#28#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#03#, 16#02#, 16#C1#, 16#80#, 16#60#, 16#28#, 16#68#, 16#1C#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#03#, 16#02#, 16#61#,
16#60#, 16#B6#, 16#75#, 16#0C#, 16#89#, 16#80#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#C0#, 16#A0#, 16#60#, 16#6C#, 16#4C#, 16#24#,
16#1D#, 16#80#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#04#, 16#02#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#02#, 16#01#, 16#01#, 16#00#, 16#80#,
16#40#, 16#20#, 16#10#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#02#, 16#00#, 16#80#, 16#40#, 16#20#, 16#10#, 16#10#, 16#08#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#02#, 16#03#, 16#40#, 16#C0#, 16#F0#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#20#, 16#7C#, 16#08#, 16#04#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#20#, 16#10#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#60#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#20#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#01#, 16#00#, 16#80#, 16#80#, 16#40#, 16#40#, 16#40#,
16#20#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#03#, 16#02#,
16#41#, 16#21#, 16#10#, 16#88#, 16#48#, 16#18#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#03#, 16#00#, 16#80#, 16#40#, 16#40#, 16#20#,
16#10#, 16#38#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#03#,
16#06#, 16#80#, 16#40#, 16#20#, 16#20#, 16#20#, 16#3C#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#03#, 16#00#, 16#41#, 16#C0#, 16#20#,
16#10#, 16#08#, 16#38#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#80#, 16#81#, 16#C1#, 16#20#, 16#F0#, 16#10#, 16#08#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#03#, 16#82#, 16#00#, 16#C0#,
16#20#, 16#10#, 16#08#, 16#38#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#03#, 16#03#, 16#03#, 16#01#, 16#C1#, 16#90#, 16#88#, 16#48#, 16#1C#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#07#, 16#80#, 16#40#,
16#40#, 16#40#, 16#20#, 16#20#, 16#10#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#06#, 16#04#, 16#82#, 16#40#, 16#C1#, 16#A0#, 16#90#, 16#48#,
16#1C#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#06#, 16#04#, 16#82#,
16#41#, 16#20#, 16#90#, 16#70#, 16#10#, 16#30#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#01#, 16#80#, 16#00#, 16#00#,
16#00#, 16#10#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#80#, 16#00#, 16#00#, 16#00#, 16#10#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#30#, 16#60#,
16#40#, 16#18#, 16#03#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#F8#, 16#00#, 16#3E#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#01#, 16#00#,
16#70#, 16#04#, 16#1C#, 16#10#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#03#, 16#00#, 16#40#, 16#20#, 16#20#, 16#20#, 16#00#, 16#10#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#03#, 16#C3#, 16#71#,
16#54#, 16#CA#, 16#6A#, 16#3B#, 16#0F#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#40#, 16#E0#, 16#50#, 16#38#, 16#24#,
16#33#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#07#, 16#81#,
16#20#, 16#90#, 16#70#, 16#48#, 16#24#, 16#3E#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#01#, 16#E3#, 16#21#, 16#01#, 16#80#, 16#C0#,
16#22#, 16#1E#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#07#,
16#C1#, 16#30#, 16#88#, 16#44#, 16#42#, 16#26#, 16#3E#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#07#, 16#C1#, 16#00#, 16#80#, 16#70#,
16#40#, 16#22#, 16#3E#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#07#, 16#C1#, 16#00#, 16#80#, 16#70#, 16#40#, 16#20#, 16#38#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#01#, 16#C1#, 16#11#, 16#00#,
16#9C#, 16#C4#, 16#22#, 16#0F#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#07#, 16#71#, 16#10#, 16#88#, 16#78#, 16#44#, 16#22#, 16#33#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#07#, 16#01#, 16#00#,
16#80#, 16#40#, 16#40#, 16#20#, 16#30#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#03#, 16#80#, 16#80#, 16#40#, 16#20#, 16#20#, 16#10#,
16#30#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#07#, 16#61#,
16#20#, 16#E0#, 16#60#, 16#50#, 16#24#, 16#37#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#07#, 16#01#, 16#00#, 16#80#, 16#40#, 16#40#,
16#24#, 16#3E#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#02#,
16#19#, 16#19#, 16#54#, 16#AA#, 16#5A#, 16#49#, 16#35#, 16#C0#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#06#, 16#61#, 16#91#, 16#50#, 16#A8#,
16#4C#, 16#24#, 16#32#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#01#, 16#C1#, 16#31#, 16#09#, 16#8C#, 16#84#, 16#26#, 16#1C#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#07#, 16#C1#, 16#20#, 16#90#,
16#70#, 16#40#, 16#20#, 16#30#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#01#, 16#C1#, 16#31#, 16#08#, 16#84#, 16#84#, 16#42#, 16#12#,
16#0E#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#07#, 16#C1#, 16#20#,
16#90#, 16#70#, 16#50#, 16#24#, 16#33#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#03#, 16#02#, 16#41#, 16#00#, 16#60#, 16#90#, 16#48#,
16#18#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#07#, 16#E0#,
16#80#, 16#40#, 16#20#, 16#10#, 16#10#, 16#1C#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#07#, 16#31#, 16#10#, 16#88#, 16#48#, 16#44#,
16#22#, 16#0E#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#07#,
16#21#, 16#10#, 16#90#, 16#50#, 16#28#, 16#08#, 16#08#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#07#, 16#E9#, 16#24#, 16#94#, 16#5A#,
16#36#, 16#1B#, 16#09#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#07#, 16#61#, 16#20#, 16#A0#, 16#20#, 16#30#, 16#24#, 16#37#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#07#, 16#61#, 16#20#, 16#A0#,
16#20#, 16#10#, 16#10#, 16#1C#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#07#, 16#C0#, 16#40#, 16#40#, 16#40#, 16#20#, 16#20#, 16#3E#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#03#, 16#01#, 16#01#,
16#00#, 16#80#, 16#40#, 16#20#, 16#20#, 16#10#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#04#, 16#02#, 16#00#, 16#80#, 16#40#, 16#10#, 16#08#,
16#04#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#03#, 16#01#,
16#00#, 16#80#, 16#40#, 16#20#, 16#10#, 16#10#, 16#08#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#02#, 16#03#, 16#02#, 16#41#, 16#20#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#1F#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#04#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#E0#, 16#A0#, 16#90#, 16#48#, 16#3C#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#06#, 16#02#, 16#01#, 16#40#,
16#D0#, 16#48#, 16#48#, 16#38#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#C0#, 16#80#, 16#80#, 16#48#, 16#18#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#80#, 16#40#,
16#E0#, 16#A0#, 16#90#, 16#48#, 16#3C#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#C0#, 16#A0#, 16#A0#, 16#68#,
16#18#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#03#, 16#02#, 16#01#,
16#01#, 16#C0#, 16#40#, 16#40#, 16#20#, 16#10#, 16#08#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#01#, 16#C0#, 16#A0#, 16#90#,
16#30#, 16#10#, 16#16#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#06#,
16#02#, 16#01#, 16#40#, 16#E0#, 16#50#, 16#4C#, 16#24#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#02#, 16#00#, 16#01#, 16#00#, 16#80#,
16#40#, 16#40#, 16#30#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#02#, 16#00#, 16#01#, 16#80#, 16#40#, 16#40#, 16#20#, 16#10#, 16#08#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#06#, 16#02#, 16#01#, 16#60#,
16#C0#, 16#60#, 16#50#, 16#24#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#06#, 16#02#, 16#01#, 16#00#, 16#80#, 16#40#, 16#40#, 16#30#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#03#,
16#58#, 16#F4#, 16#54#, 16#4A#, 16#29#, 16#80#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#03#, 16#40#, 16#E0#, 16#50#, 16#4C#,
16#24#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#C0#, 16#90#, 16#88#, 16#48#, 16#18#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#01#, 16#40#, 16#D0#, 16#48#,
16#48#, 16#38#, 16#10#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#C0#, 16#90#, 16#90#, 16#48#, 16#3C#, 16#04#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#03#, 16#40#, 16#C0#,
16#40#, 16#40#, 16#20#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#01#, 16#80#, 16#80#, 16#60#, 16#50#, 16#10#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#01#, 16#80#,
16#80#, 16#40#, 16#40#, 16#30#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#03#, 16#40#, 16#A0#, 16#90#, 16#5C#, 16#34#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#01#,
16#40#, 16#90#, 16#50#, 16#30#, 16#10#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#01#, 16#08#, 16#A4#, 16#6C#, 16#16#,
16#12#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#01#, 16#40#, 16#E0#, 16#20#, 16#30#, 16#2C#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#01#, 16#20#, 16#90#, 16#30#,
16#18#, 16#08#, 16#08#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#01#, 16#C0#, 16#40#, 16#40#, 16#40#, 16#30#, 16#04#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#01#, 16#01#, 16#00#, 16#80#, 16#80#,
16#40#, 16#20#, 16#10#, 16#08#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#04#, 16#02#, 16#01#, 16#00#, 16#80#, 16#40#, 16#20#, 16#10#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#04#, 16#02#, 16#01#, 16#00#, 16#80#,
16#40#, 16#20#, 16#20#, 16#10#, 16#08#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#D0#, 16#18#, 16#00#, 16#00#,
16#00#, 16#00#);
Font_D : aliased constant Bitmap_Font :=
(
Bytes_Per_Glyph => 14,
Glyph_Width => 9,
Glyph_Height => 12,
Data => FreeSerifItalic5pt7bBitmaps'Access);
Font : constant Bitmap_Font_Ref := Font_D'Access;
end GESTE_Fonts.FreeSerifItalic5pt7b;
|
------------------------------------------------------------------------------
-- AGAR CORE LIBRARY --
-- A G A R . C O N F I G --
-- S p e c --
-- --
-- Copyright (c) 2018-2020, Julien Nadeau Carriere (vedge@csoft.net) --
-- Copyright (c) 2010, coreland (mark@coreland.ath.cx) --
-- --
-- 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 Interfaces.C;
with Interfaces.C.Strings;
--
-- Interface to Agar "application preferences" object. For a list of the
-- built-in settings, see AG_Config(3), "CONFIGURATION PARAMETERS". Extra,
-- application-specific settings can be defined using Agar.Variable.
--
package Agar.Config is
function Load return Boolean;
-- Load previously saved configuration settings from the data directory.
function Save return Boolean;
-- Save configuration settings to the application data directory.
private
package C renames Interfaces.C;
package CS renames Interfaces.C.Strings;
function AG_ConfigFind
(Name : in CS.chars_ptr;
Dest_Path : in CS.chars_ptr;
Dest_Len : in C.size_t) return C.int
with Import, Convention => C, Link_Name => "AG_ConfigFind";
function AG_ConfigLoad return C.int
with Import, Convention => C, Link_Name => "AG_ConfigLoad";
function AG_ConfigSave return C.int
with Import, Convention => C, Link_Name => "AG_ConfigSave";
end Agar.Config;
|
with System.Address_To_Constant_Access_Conversions;
with System.Address_To_Named_Access_Conversions;
with System.Environment_Block;
with System.Storage_Elements;
with System.Zero_Terminated_Strings;
with C.stdlib;
package body System.Native_Environment_Variables is
use type Storage_Elements.Storage_Offset;
use type C.char_const_ptr;
use type C.char_ptr;
use type C.char_ptr_ptr;
use type C.signed_int;
use type C.ptrdiff_t;
use type C.size_t;
function strlen (s : not null access constant C.char) return C.size_t
with Import,
Convention => Intrinsic, External_Name => "__builtin_strlen";
function strchr (
s : not null access constant C.char;
c : Standard.C.signed_int)
return Standard.C.char_const_ptr
with Import,
Convention => Intrinsic, External_Name => "__builtin_strchr";
package char_const_ptr_Conv is
new Address_To_Constant_Access_Conversions (C.char, C.char_const_ptr);
package char_ptr_ptr_Conv is
new Address_To_Named_Access_Conversions (C.char_ptr, C.char_ptr_ptr);
function getenv (Name : String) return C.char_ptr;
function getenv (Name : String) return C.char_ptr is
C_Name : C.char_array (
0 ..
Name'Length * Zero_Terminated_Strings.Expanding);
begin
Zero_Terminated_Strings.To_C (Name, C_Name (0)'Access);
return C.stdlib.getenv (C_Name (0)'Access);
end getenv;
procedure Do_Separate (
Item : not null C.char_const_ptr;
Name_Length : out C.size_t;
Value : out C.char_const_ptr);
procedure Do_Separate (
Item : not null C.char_const_ptr;
Name_Length : out C.size_t;
Value : out C.char_const_ptr)
is
P : C.char_const_ptr;
begin
P := strchr (Item, C.char'Pos ('='));
if P /= null then
Name_Length :=
C.size_t (
char_const_ptr_Conv.To_Address (P)
- char_const_ptr_Conv.To_Address (Item));
Value :=
char_const_ptr_Conv.To_Pointer (
char_const_ptr_Conv.To_Address (P)
+ Storage_Elements.Storage_Offset'(1));
else
Name_Length := strlen (Item);
Value :=
char_const_ptr_Conv.To_Pointer (
char_const_ptr_Conv.To_Address (C.char_const_ptr (Item))
+ Storage_Elements.Storage_Offset (Name_Length));
end if;
end Do_Separate;
-- implementation
function Value (Name : String) return String is
Result : C.char_ptr;
begin
Result := getenv (Name);
if Result = null then
raise Constraint_Error;
else
return Zero_Terminated_Strings.Value (Result);
end if;
end Value;
function Value (Name : String; Default : String) return String is
Result : C.char_ptr;
begin
Result := getenv (Name);
if Result = null then
return Default;
else
return Zero_Terminated_Strings.Value (Result);
end if;
end Value;
function Exists (Name : String) return Boolean is
Item : C.char_ptr;
begin
Item := getenv (Name);
return Item /= null;
end Exists;
procedure Set (Name : String; Value : String) is
C_Name : C.char_array (
0 ..
Name'Length * Zero_Terminated_Strings.Expanding);
C_Value : C.char_array (
0 ..
Value'Length * Zero_Terminated_Strings.Expanding);
begin
Zero_Terminated_Strings.To_C (Name, C_Name (0)'Access);
Zero_Terminated_Strings.To_C (Value, C_Value (0)'Access);
if C.stdlib.setenv (C_Name (0)'Access, C_Value (0)'Access, 1) < 0 then
raise Constraint_Error;
end if;
end Set;
procedure Clear (Name : String) is
C_Name : C.char_array (
0 ..
Name'Length * Zero_Terminated_Strings.Expanding);
begin
Zero_Terminated_Strings.To_C (Name, C_Name (0)'Access);
if C.stdlib.unsetenv (C_Name (0)'Access) < 0 then
raise Constraint_Error;
end if;
end Clear;
procedure Clear is
Block : constant C.char_ptr_ptr := Environment_Block;
I : C.char_ptr_ptr := Block;
begin
while I.all /= null loop
I :=
char_ptr_ptr_Conv.To_Pointer (
char_ptr_ptr_Conv.To_Address (I)
+ Storage_Elements.Storage_Offset'(
C.char_ptr'Size / Standard'Storage_Unit));
end loop;
while I /= Block loop
I :=
char_ptr_ptr_Conv.To_Pointer (
char_ptr_ptr_Conv.To_Address (I)
- Storage_Elements.Storage_Offset'(
C.char_ptr'Size / Standard'Storage_Unit));
declare
Item : constant C.char_const_ptr := C.char_const_ptr (I.all);
Name_Length : C.size_t;
Value : C.char_const_ptr;
begin
Do_Separate (Item, Name_Length, Value);
declare
Name : aliased C.char_array (0 .. Name_Length);
begin
declare
Item_All : C.char_array (0 .. Name_Length - 1);
for Item_All'Address use
char_const_ptr_Conv.To_Address (Item);
begin
Name (0 .. Name_Length - 1) := Item_All;
Name (Name_Length) := C.char'Val (0);
end;
if C.stdlib.unsetenv (Name (0)'Access) < 0 then
raise Constraint_Error;
end if;
end;
end;
end loop;
end Clear;
function Has_Element (Position : Cursor) return Boolean is
begin
return char_ptr_ptr_Conv.To_Pointer (Address (Position)).all /= null;
end Has_Element;
function Name (Position : Cursor) return String is
Item : constant C.char_const_ptr :=
C.char_const_ptr (
char_ptr_ptr_Conv.To_Pointer (Address (Position)).all);
Name_Length : C.size_t;
Value : C.char_const_ptr;
begin
Do_Separate (Item, Name_Length, Value);
return Zero_Terminated_Strings.Value (Item, Name_Length);
end Name;
function Value (Position : Cursor) return String is
Item : constant C.char_const_ptr :=
C.char_const_ptr (
char_ptr_ptr_Conv.To_Pointer (Address (Position)).all);
Name_Length : C.size_t;
Value : C.char_const_ptr;
begin
Do_Separate (Item, Name_Length, Value);
return Zero_Terminated_Strings.Value (Value);
end Value;
function First (Block : Address) return Cursor is
pragma Unreferenced (Block);
begin
return Cursor (char_ptr_ptr_Conv.To_Address (Environment_Block));
end First;
function Next (Block : Address; Position : Cursor) return Cursor is
pragma Unreferenced (Block);
begin
return Cursor (
Address (Position)
+ Storage_Elements.Storage_Offset'(
C.char_ptr'Size / Standard'Storage_Unit));
end Next;
end System.Native_Environment_Variables;
|
-----------------------------------------------------------------------
-- keystore-repository-entries -- Repository management for the keystore
-- Copyright (C) 2019 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 Ada.IO_Exceptions;
with Ada.Unchecked_Deallocation;
with Keystore.Logs;
with Keystore.Marshallers;
-- === Directory Entries ===
-- The wallet repository block is encrypted with the wallet directory key.
--
-- ```
-- +------------------+
-- | 02 02 | 2b
-- | Encrypt size | 2b = BT_DATA_LENGTH
-- | Wallet id | 4b
-- | PAD 0 | 4b
-- | PAD 0 | 4b
-- +------------------+
-- | Next block ID | 4b Block number for next repository block with same storage
-- | Data key offset | 2b Starts at IO.Block_Index'Last, decreasing
-- +------------------+
-- | Entry ID | 4b ^
-- | Entry type | 2b | = T_STRING, T_BINARY
-- | Name size | 2b |
-- | Name | Nb | DATA_NAME_ENTRY_SIZE + Name'Length
-- | Create date | 8b |
-- | Update date | 8b |
-- | Entry size | 8b v
-- +------------------+
-- | Entry ID | 4b ^
-- | Entry type | 2b | = T_WALLET
-- | Name size | 2b |
-- | Name | Nb | DATA_NAME_ENTRY_SIZE + Name'Length
-- | Create date | 8b |
-- | Update date | 8b |
-- | Wallet lid | 4b |
-- | Wallet master ID | 4b v
-- +------------------+
-- | ... |
-- +------------------+--
-- | 0 0 0 0 | 16b (End of name entry list)
-- +------------------+--
-- | ... | (random or zero)
-- +------------------+--
-- | 0 0 0 0 | 16b (End of data key list)
-- +------------------+--
-- | ... |
-- +------------------+
-- | Storage ID | 4b ^ Repeats "Data key count" times
-- | Data block ID | 4b |
-- | Data size | 2b | DATA_KEY_ENTRY_SIZE = 58b
-- | Content IV | 16b |
-- | Content key | 32b v
-- +------------------+
-- | Entry ID | 4b ^
-- | Data key count | 2b | DATA_KEY_HEADER_SIZE = 10b
-- | Data offset | 4b v
-- +------------------+
-- | Block HMAC-256 | 32b
-- +------------------+--
-- ```
--
package body Keystore.Repository.Entries is
use type Interfaces.Unsigned_16;
use type Interfaces.Unsigned_32;
Log : constant Util.Log.Loggers.Logger
:= Util.Log.Loggers.Create ("Keystore.Repository.Entries");
procedure Free is
new Ada.Unchecked_Deallocation (Object => Wallet_Entry,
Name => Wallet_Entry_Access);
-- ------------------------------
-- Load the wallet directory block in the wallet manager buffer.
-- Extract the directory if this is the first time the data block is read.
-- ------------------------------
procedure Load_Directory (Manager : in out Wallet_Manager;
Directory : in Wallet_Directory_Entry_Access;
Into : in out IO.Marshaller) is
Btype : Interfaces.Unsigned_16;
Wid : Interfaces.Unsigned_32;
Size : IO.Block_Index;
begin
Keystore.Logs.Debug (Log, "Load directory block{0}", Directory.Block);
-- Get the directory block from the cache.
Into.Buffer := Buffers.Find (Manager.Cache, Directory.Block);
if not Buffers.Is_Null (Into.Buffer) then
return;
end if;
-- Get it from the modified list in case it has some pending changes not written yet.
Into.Buffer := Buffers.Find (Manager.Modified, Directory.Block);
if not Buffers.Is_Null (Into.Buffer) then
return;
end if;
-- Allocate block storage.
Into.Buffer := Buffers.Allocate (Directory.Block);
-- Read wallet meta data block.
Keys.Set_IV (Manager.Config.Dir, Directory.Block.Block);
Manager.Stream.Read (Decipher => Manager.Config.Dir.Decipher,
Sign => Manager.Config.Dir.Sign,
Decrypt_Size => Size,
Into => Into.Buffer);
-- Check block type.
Btype := Marshallers.Get_Header_16 (Into);
if Btype /= IO.BT_WALLET_DIRECTORY then
Logs.Error (Log, "Block{0} invalid block type", Directory.Block);
raise Keystore.Corrupted;
end if;
Marshallers.Skip (Into, 2);
-- Check that this is a block for the current wallet.
Wid := Marshallers.Get_Unsigned_32 (Into);
if Wid /= Interfaces.Unsigned_32 (Manager.Id) then
Logs.Error (Log, "Block{0} invalid block wallet identifier", Directory.Block);
raise Keystore.Corrupted;
end if;
-- This is the first time we load this directory block, scan the directory.
if not Directory.Ready then
Marshallers.Skip (Into, 8);
declare
Item : Wallet_Entry_Access;
Index : Interfaces.Unsigned_32;
Count : Interfaces.Unsigned_16;
Offset : IO.Block_Index;
Pos : Wallet_Indexs.Cursor;
Data_Key : Wallet_Data_Key_Entry;
begin
Directory.Next_Block := Marshallers.Get_Unsigned_32 (Into);
Directory.Key_Pos := Marshallers.Get_Block_Index (Into);
-- Scan each named entry
loop
Offset := Into.Pos;
Index := Marshallers.Get_Unsigned_32 (Into);
exit when Index = 0;
declare
Kind : constant Entry_Type := Marshallers.Get_Kind (Into);
Len : constant Natural := Natural (Marshallers.Get_Unsigned_16 (Into));
Name : constant String := Marshallers.Get_String (Into, Len);
begin
Item := new Wallet_Entry (Length => Len, Is_Wallet => Kind = T_WALLET);
Item.Entry_Offset := Offset;
Item.Kind := Kind;
Item.Id := Wallet_Entry_Index (Index);
Item.Create_Date := Marshallers.Get_Date (Into);
Item.Update_Date := Marshallers.Get_Date (Into);
if Kind = T_WALLET then
Item.Wallet_Id := Wallet_Identifier (Marshallers.Get_Unsigned_32 (Into));
Item.Master := Marshallers.Get_Block_Number (Into);
else
Item.Size := Marshallers.Get_Unsigned_64 (Into);
end if;
Item.Header := Directory;
Item.Name := Name;
if Item.Id >= Manager.Next_Id then
Manager.Next_Id := Item.Id + 1;
end if;
Manager.Map.Insert (Key => Name, New_Item => Item);
Manager.Entry_Indexes.Insert (Key => Item.Id, New_Item => Item);
Directory.Count := Directory.Count + 1;
exception
when others =>
Free (Item);
Logs.Error (Log, "Block{0} contains invalid data entry", Directory.Block);
raise Keystore.Corrupted;
end;
end loop;
Directory.Last_Pos := Into.Pos - 4;
-- Scan each data key entry starting from the end of the directory block
-- moving backward until we reach the directory key position. For each data entry
-- add a link to the directory block in 'Data_Blocks' list so that we can iterate
-- over that list to get the whole data content for the data entry.
Data_Key.Directory := Directory;
Offset := IO.Block_Index'Last;
while Offset > Directory.Key_Pos loop
Offset := Offset - DATA_KEY_HEADER_SIZE;
Into.Pos := Offset;
Index := Marshallers.Get_Unsigned_32 (Into);
Count := Marshallers.Get_Unsigned_16 (Into);
if Index /= 0 then
Pos := Manager.Entry_Indexes.Find (Wallet_Entry_Index (Index));
if Wallet_Indexs.Has_Element (Pos) then
Item := Wallet_Indexs.Element (Pos);
Item.Data_Blocks.Append (Data_Key);
Item.Block_Count := Item.Block_Count + Natural (Count);
end if;
end if;
-- Compute sum of sizes of every data block.
Data_Key.Size := 0;
while Count > 0 and Offset > Directory.Key_Pos loop
Offset := Offset - DATA_KEY_ENTRY_SIZE;
-- Set marshaller to the data key size position.
Into.Pos := Offset + 8;
Data_Key.Size := Data_Key.Size + Marshallers.Get_Buffer_Size (Into);
Count := Count - 1;
end loop;
end loop;
end;
if Directory.Last_Pos + 4 < Directory.Key_Pos then
Directory.Available := Directory.Key_Pos - Directory.Last_Pos - 4;
else
Directory.Available := 0;
end if;
Directory.Ready := True;
end if;
exception
when Ada.IO_Exceptions.End_Error | Ada.IO_Exceptions.Data_Error =>
Logs.Error (Log, "Block{0} cannot be read", Directory.Block);
raise Keystore.Corrupted;
end Load_Directory;
-- ------------------------------
-- Load the complete wallet directory by starting at the given block.
-- ------------------------------
procedure Load_Complete_Directory (Manager : in out Wallet_Manager;
Block : in Keystore.IO.Storage_Block) is
Next : Interfaces.Unsigned_32;
Directory : Wallet_Directory_Entry_Access;
begin
Manager.Root := Block;
Manager.Next_Id := Wallet_Entry_Index'First;
Next := Interfaces.Unsigned_32 (Block.Block);
while Next /= 0 loop
Directory := new Wallet_Directory_Entry;
Directory.Block := IO.Storage_Block '(Storage => Block.Storage,
Block => IO.Block_Number (Next));
Manager.Directory_List.Append (Directory);
Load_Directory (Manager, Directory, Manager.Current);
Next := Directory.Next_Block;
end loop;
end Load_Complete_Directory;
procedure Initialize_Directory_Block (Manager : in out Wallet_Manager;
Block : in IO.Storage_Block;
Space : in IO.Buffer_Size;
Directory : out Wallet_Directory_Entry_Access) is
begin
-- We need a new wallet directory block.
Directory := new Wallet_Directory_Entry;
Directory.Available := IO.Block_Index'Last - IO.BT_DATA_START - Space - 4 - 2;
Directory.Count := 0;
Directory.Key_Pos := IO.Block_Index'Last;
Directory.Last_Pos := IO.BT_DATA_START + 4 + 2 - 1;
Directory.Ready := True;
Directory.Block := Block;
Logs.Info (Log, "Adding directory block{0}", Directory.Block);
if not Manager.Directory_List.Is_Empty then
declare
Last : constant Wallet_Directory_Entry_Access := Manager.Directory_List.Last_Element;
begin
-- Update the last directory block to link to the new one.
Load_Directory (Manager, Last, Manager.Current);
Last.Next_Block := Interfaces.Unsigned_32 (Directory.Block.Block);
Manager.Current.Pos := IO.BT_DATA_START - 1;
Marshallers.Put_Block_Number (Manager.Current, Directory.Block.Block);
Manager.Modified.Include (Manager.Current.Buffer.Block, Manager.Current.Buffer.Data);
end;
end if;
Manager.Directory_List.Append (Directory);
end Initialize_Directory_Block;
-- ------------------------------
-- Find and load a directory block to hold a new entry that occupies the given space.
-- The first directory block that has enough space is used otherwise a new block
-- is allocated and initialized.
-- ------------------------------
procedure Find_Directory_Block (Manager : in out Wallet_Manager;
Space : in IO.Block_Index;
Directory : out Wallet_Directory_Entry_Access) is
Block : IO.Storage_Block;
begin
-- Scan for a block having enough space for us.
for Block of Manager.Directory_List loop
if Block.Available >= Space then
Block.Available := Block.Available - Space;
Block.Count := Block.Count + 1;
Directory := Block;
return;
end if;
end loop;
Manager.Stream.Allocate (IO.DIRECTORY_BLOCK, Block);
Initialize_Directory_Block (Manager, Block, Space, Directory);
Manager.Current.Buffer := Buffers.Allocate (Block);
-- Prepare the new directory block.
-- Fill the new block with random values or with zeros.
if Manager.Config.Randomize then
Manager.Random.Generate (Manager.Current.Buffer.Data.Value.Data);
else
Manager.Current.Buffer.Data.Value.Data := (others => 0);
end if;
Marshallers.Set_Header (Into => Manager.Current,
Tag => IO.BT_WALLET_DIRECTORY,
Id => Manager.Id);
Marshallers.Put_Unsigned_32 (Manager.Current, 0);
Marshallers.Put_Block_Index (Manager.Current, IO.Block_Index'Last);
Marshallers.Put_Unsigned_32 (Manager.Current, 0);
Manager.Modified.Include (Manager.Current.Buffer.Block, Manager.Current.Buffer.Data);
end Find_Directory_Block;
-- ------------------------------
-- Add a new entry in the wallet directory.
-- ------------------------------
procedure Add_Entry (Manager : in out Wallet_Manager;
Name : in String;
Kind : in Entry_Type;
Item : out Wallet_Entry_Access) is
begin
if Manager.Map.Contains (Name) then
Log.Info ("Name '{0}' is already used", Name);
raise Name_Exist;
end if;
Log.Info ("Adding data entry {0}", Name);
-- Create the new wallet entry.
Item := new Wallet_Entry (Length => Name'Length, Is_Wallet => Kind = T_WALLET);
Item.Name := Name;
Item.Create_Date := Ada.Calendar.Clock;
Item.Update_Date := Item.Create_Date;
Item.Id := Manager.Next_Id;
Item.Kind := Kind;
Manager.Next_Id := Manager.Next_Id + 1;
if Item.Is_Wallet then
Item.Wallet_Id := Manager.Next_Wallet_Id;
Manager.Next_Wallet_Id := Manager.Next_Wallet_Id + 1;
end if;
-- Find and load the directory block that can hold the new entry.
Find_Directory_Block (Manager, Entry_Size (Item), Item.Header);
-- Write the new entry at end of existing entries.
Item.Entry_Offset := Item.Header.Last_Pos;
-- Remember the last valid position for the next entry to add.
Item.Header.Last_Pos := Item.Entry_Offset + Entry_Size (Item);
Item.Header.Count := Item.Header.Count + 1;
-- Register it in the local repository.
Manager.Map.Insert (Name, Item);
Manager.Entry_Indexes.Insert (Item.Id, Item);
end Add_Entry;
-- ------------------------------
-- Update an existing entry in the wallet directory.
-- ------------------------------
procedure Update_Entry (Manager : in out Wallet_Manager;
Item : in Wallet_Entry_Access;
Kind : in Entry_Type;
Size : in Interfaces.Unsigned_64) is
begin
Item.Kind := Kind;
if not Item.Is_Wallet then
Item.Size := Size;
end if;
Item.Update_Date := Ada.Calendar.Clock;
Item.Access_Date := Item.Update_Date;
if Item.Header.Count > 0 then
-- Find and load the directory block that can hold the new entry.
Load_Directory (Manager, Item.Header, Manager.Current);
end if;
-- Write the new entry.
Manager.Current.Pos := Item.Entry_Offset;
Marshallers.Put_Unsigned_32 (Manager.Current, Interfaces.Unsigned_32 (Item.Id));
Marshallers.Put_Kind (Manager.Current, Item.Kind);
Marshallers.Put_String (Manager.Current, Item.Name);
Marshallers.Put_Date (Manager.Current, Item.Create_Date);
Marshallers.Put_Date (Manager.Current, Item.Update_Date);
if Item.Is_Wallet then
Marshallers.Put_Unsigned_32 (Manager.Current, Interfaces.Unsigned_32 (Item.Wallet_Id));
Marshallers.Put_Block_Number (Manager.Current, Item.Master);
else
Marshallers.Put_Unsigned_64 (Manager.Current, Item.Size);
end if;
pragma Assert (Check => Manager.Current.Pos = Item.Entry_Offset + Entry_Size (Item));
if Manager.Current.Pos = Item.Header.Last_Pos then
Marshallers.Put_Unsigned_32 (Manager.Current, 0);
end if;
Manager.Modified.Include (Manager.Current.Buffer.Block, Manager.Current.Buffer.Data);
end Update_Entry;
-- ------------------------------
-- Delete the entry from the repository.
-- ------------------------------
procedure Delete_Entry (Manager : in out Wallet_Manager;
Item : in Wallet_Entry_Access) is
Directory : constant Wallet_Directory_Entry_Access := Item.Header;
Size : IO.Block_Index;
End_Entry : IO.Block_Index;
begin
Keystore.Logs.Debug (Log, "Delete entry from block{0}", Directory.Block);
Directory.Count := Directory.Count - 1;
-- Load the directory block .
Load_Directory (Manager, Directory, Manager.Current);
declare
Buf : constant Buffers.Buffer_Accessor := Manager.Current.Buffer.Data.Value;
begin
-- Move the data entry.
Size := Entry_Size (Item);
End_Entry := Item.Entry_Offset + Size;
if End_Entry /= Directory.Last_Pos then
Buf.Data (Item.Entry_Offset + 1 .. Directory.Last_Pos - Size)
:= Buf.Data (End_Entry + 1 .. Directory.Last_Pos);
end if;
if Manager.Config.Randomize then
-- When strong security is necessary, fill with random values
-- (except the first 4 bytes).
Buf.Data (Directory.Last_Pos - Size + 1 .. Directory.Last_Pos - Size + 3)
:= (others => 0);
Manager.Random.Generate
(Buf.Data (Directory.Last_Pos - Size + 4 .. Directory.Last_Pos));
else
Buf.Data (Directory.Last_Pos - Size .. Directory.Last_Pos) := (others => 0);
end if;
Directory.Last_Pos := Directory.Last_Pos - Size;
Manager.Modified.Include (Manager.Current.Buffer.Block, Manager.Current.Buffer.Data);
end;
end Delete_Entry;
-- ------------------------------
-- Save the directory blocks that have been modified.
-- ------------------------------
procedure Save (Manager : in out Wallet_Manager) is
Buffer : Buffers.Storage_Buffer;
begin
while not Manager.Modified.Is_Empty loop
Buffer.Block := Manager.Modified.First_Key;
Buffer.Data := Manager.Modified.First_Element;
Manager.Modified.Delete_First;
Keys.Set_IV (Manager.Config.Dir, Buffer.Block.Block);
Manager.Stream.Write (From => Buffer,
Cipher => Manager.Config.Dir.Cipher,
Sign => Manager.Config.Dir.Sign);
end loop;
end Save;
end Keystore.Repository.Entries;
|
package Giza.Bitmap_Fonts.FreeMono24pt7b is
Font : constant Giza.Font.Ref_Const;
private
FreeMono24pt7bBitmaps : aliased constant Font_Bitmap := (
16#73#, 16#9C#, 16#E7#, 16#39#, 16#CE#, 16#73#, 16#9C#, 16#C6#, 16#30#,
16#84#, 16#21#, 16#08#, 16#00#, 16#00#, 16#00#, 16#03#, 16#BF#, 16#FF#,
16#B8#, 16#FE#, 16#7F#, 16#7C#, 16#7E#, 16#7C#, 16#7E#, 16#7C#, 16#3E#,
16#7C#, 16#3E#, 16#7C#, 16#3E#, 16#7C#, 16#3E#, 16#7C#, 16#3E#, 16#3C#,
16#3E#, 16#38#, 16#1C#, 16#38#, 16#1C#, 16#38#, 16#1C#, 16#38#, 16#1C#,
16#38#, 16#1C#, 16#01#, 16#86#, 16#00#, 16#30#, 16#C0#, 16#06#, 16#18#,
16#00#, 16#C3#, 16#00#, 16#18#, 16#60#, 16#03#, 16#0C#, 16#00#, 16#61#,
16#80#, 16#0C#, 16#30#, 16#01#, 16#8C#, 16#00#, 16#61#, 16#80#, 16#0C#,
16#30#, 16#3F#, 16#FF#, 16#F7#, 16#FF#, 16#FE#, 16#06#, 16#18#, 16#00#,
16#C3#, 16#00#, 16#18#, 16#60#, 16#03#, 16#0C#, 16#00#, 16#61#, 16#80#,
16#0C#, 16#30#, 16#7F#, 16#FF#, 16#EF#, 16#FF#, 16#FC#, 16#06#, 16#18#,
16#00#, 16#C3#, 16#00#, 16#38#, 16#C0#, 16#06#, 16#18#, 16#00#, 16#C3#,
16#00#, 16#18#, 16#60#, 16#03#, 16#0C#, 16#00#, 16#61#, 16#80#, 16#0C#,
16#30#, 16#01#, 16#86#, 16#00#, 16#30#, 16#C0#, 16#00#, 16#C0#, 16#00#,
16#30#, 16#00#, 16#0C#, 16#00#, 16#0F#, 16#C0#, 16#0F#, 16#FD#, 16#87#,
16#03#, 16#E3#, 16#80#, 16#39#, 16#C0#, 16#06#, 16#60#, 16#01#, 16#98#,
16#00#, 16#06#, 16#00#, 16#01#, 16#C0#, 16#00#, 16#38#, 16#00#, 16#07#,
16#C0#, 16#00#, 16#7F#, 16#80#, 16#03#, 16#F8#, 16#00#, 16#0F#, 16#80#,
16#00#, 16#60#, 16#00#, 16#1C#, 16#00#, 16#03#, 16#80#, 16#00#, 16#F0#,
16#00#, 16#3C#, 16#00#, 16#1F#, 16#80#, 16#0E#, 16#FC#, 16#0F#, 16#37#,
16#FF#, 16#80#, 16#7F#, 16#80#, 16#03#, 16#00#, 16#00#, 16#C0#, 16#00#,
16#30#, 16#00#, 16#0C#, 16#00#, 16#03#, 16#00#, 16#00#, 16#C0#, 16#00#,
16#07#, 16#80#, 16#01#, 16#FE#, 16#00#, 16#38#, 16#70#, 16#03#, 16#03#,
16#00#, 16#60#, 16#18#, 16#06#, 16#01#, 16#80#, 16#60#, 16#18#, 16#06#,
16#01#, 16#80#, 16#30#, 16#30#, 16#03#, 16#87#, 16#00#, 16#1F#, 16#E0#,
16#30#, 16#78#, 16#1F#, 16#00#, 16#1F#, 16#80#, 16#0F#, 16#C0#, 16#07#,
16#E0#, 16#03#, 16#F0#, 16#00#, 16#F8#, 16#00#, 16#0C#, 16#01#, 16#E0#,
16#00#, 16#7F#, 16#80#, 16#0E#, 16#1C#, 16#00#, 16#C0#, 16#C0#, 16#18#,
16#06#, 16#01#, 16#80#, 16#60#, 16#18#, 16#06#, 16#01#, 16#80#, 16#60#,
16#0C#, 16#0E#, 16#00#, 16#E1#, 16#C0#, 16#07#, 16#F8#, 16#00#, 16#1E#,
16#00#, 16#03#, 16#EC#, 16#01#, 16#FF#, 16#00#, 16#E1#, 16#00#, 16#70#,
16#00#, 16#18#, 16#00#, 16#06#, 16#00#, 16#01#, 16#80#, 16#00#, 16#30#,
16#00#, 16#0C#, 16#00#, 16#01#, 16#80#, 16#00#, 16#60#, 16#00#, 16#7C#,
16#00#, 16#3B#, 16#83#, 16#D8#, 16#60#, 16#FE#, 16#0C#, 16#33#, 16#03#,
16#98#, 16#C0#, 16#66#, 16#30#, 16#0D#, 16#8C#, 16#03#, 16#C3#, 16#00#,
16#70#, 16#60#, 16#1C#, 16#1C#, 16#0F#, 16#03#, 16#87#, 16#7C#, 16#7F#,
16#9F#, 16#07#, 16#80#, 16#00#, 16#FE#, 16#F9#, 16#F3#, 16#E7#, 16#CF#,
16#9F#, 16#3E#, 16#3C#, 16#70#, 16#E1#, 16#C3#, 16#87#, 16#00#, 16#06#,
16#1C#, 16#30#, 16#E1#, 16#87#, 16#0E#, 16#18#, 16#70#, 16#E1#, 16#C3#,
16#0E#, 16#1C#, 16#38#, 16#70#, 16#E1#, 16#C3#, 16#87#, 16#0E#, 16#0C#,
16#1C#, 16#38#, 16#70#, 16#60#, 16#E1#, 16#C1#, 16#83#, 16#83#, 16#06#,
16#06#, 16#04#, 16#C1#, 16#C1#, 16#83#, 16#83#, 16#07#, 16#0E#, 16#0C#,
16#1C#, 16#38#, 16#70#, 16#E0#, 16#E1#, 16#C3#, 16#87#, 16#0E#, 16#1C#,
16#38#, 16#70#, 16#E1#, 16#87#, 16#0E#, 16#1C#, 16#30#, 16#61#, 16#C3#,
16#0E#, 16#18#, 16#70#, 16#C1#, 16#00#, 16#00#, 16#C0#, 16#00#, 16#30#,
16#00#, 16#0C#, 16#00#, 16#03#, 16#00#, 16#00#, 16#C0#, 16#10#, 16#30#,
16#3F#, 16#8C#, 16#7C#, 16#FF#, 16#FC#, 16#07#, 16#F8#, 16#00#, 16#78#,
16#00#, 16#1F#, 16#00#, 16#0C#, 16#C0#, 16#06#, 16#18#, 16#03#, 16#87#,
16#00#, 16#C0#, 16#C0#, 16#60#, 16#18#, 16#00#, 16#60#, 16#00#, 16#06#,
16#00#, 16#00#, 16#60#, 16#00#, 16#06#, 16#00#, 16#00#, 16#60#, 16#00#,
16#06#, 16#00#, 16#00#, 16#60#, 16#00#, 16#06#, 16#00#, 16#00#, 16#60#,
16#00#, 16#06#, 16#00#, 16#FF#, 16#FF#, 16#FF#, 16#FF#, 16#FF#, 16#00#,
16#60#, 16#00#, 16#06#, 16#00#, 16#00#, 16#60#, 16#00#, 16#06#, 16#00#,
16#00#, 16#60#, 16#00#, 16#06#, 16#00#, 16#00#, 16#60#, 16#00#, 16#06#,
16#00#, 16#00#, 16#60#, 16#00#, 16#06#, 16#00#, 16#1F#, 16#8F#, 16#87#,
16#C7#, 16#C3#, 16#E1#, 16#E1#, 16#F0#, 16#F0#, 16#78#, 16#38#, 16#3C#,
16#1C#, 16#0E#, 16#06#, 16#00#, 16#7F#, 16#FF#, 16#FD#, 16#FF#, 16#FF#,
16#F0#, 16#7D#, 16#FF#, 16#FF#, 16#FF#, 16#EF#, 16#80#, 16#00#, 16#00#,
16#C0#, 16#00#, 16#30#, 16#00#, 16#18#, 16#00#, 16#06#, 16#00#, 16#03#,
16#00#, 16#00#, 16#C0#, 16#00#, 16#60#, 16#00#, 16#18#, 16#00#, 16#0C#,
16#00#, 16#03#, 16#00#, 16#01#, 16#80#, 16#00#, 16#60#, 16#00#, 16#30#,
16#00#, 16#0C#, 16#00#, 16#06#, 16#00#, 16#01#, 16#80#, 16#00#, 16#C0#,
16#00#, 16#30#, 16#00#, 16#18#, 16#00#, 16#06#, 16#00#, 16#01#, 16#00#,
16#00#, 16#C0#, 16#00#, 16#20#, 16#00#, 16#18#, 16#00#, 16#04#, 16#00#,
16#03#, 16#00#, 16#00#, 16#80#, 16#00#, 16#60#, 16#00#, 16#10#, 16#00#,
16#0C#, 16#00#, 16#02#, 16#00#, 16#01#, 16#80#, 16#00#, 16#40#, 16#00#,
16#30#, 16#00#, 16#0C#, 16#00#, 16#00#, 16#03#, 16#F0#, 16#03#, 16#FF#,
16#01#, 16#E1#, 16#E0#, 16#E0#, 16#18#, 16#30#, 16#03#, 16#1C#, 16#00#,
16#E6#, 16#00#, 16#19#, 16#80#, 16#06#, 16#E0#, 16#01#, 16#F0#, 16#00#,
16#3C#, 16#00#, 16#0F#, 16#00#, 16#03#, 16#C0#, 16#00#, 16#F0#, 16#00#,
16#3C#, 16#00#, 16#0F#, 16#00#, 16#03#, 16#C0#, 16#00#, 16#F0#, 16#00#,
16#3C#, 16#00#, 16#0F#, 16#00#, 16#03#, 16#C0#, 16#00#, 16#F8#, 16#00#,
16#76#, 16#00#, 16#19#, 16#80#, 16#06#, 16#70#, 16#03#, 16#8C#, 16#00#,
16#C3#, 16#80#, 16#60#, 16#78#, 16#78#, 16#0F#, 16#FC#, 16#00#, 16#FC#,
16#00#, 16#03#, 16#80#, 16#07#, 16#80#, 16#0F#, 16#80#, 16#1D#, 16#80#,
16#39#, 16#80#, 16#71#, 16#80#, 16#E1#, 16#80#, 16#C1#, 16#80#, 16#01#,
16#80#, 16#01#, 16#80#, 16#01#, 16#80#, 16#01#, 16#80#, 16#01#, 16#80#,
16#01#, 16#80#, 16#01#, 16#80#, 16#01#, 16#80#, 16#01#, 16#80#, 16#01#,
16#80#, 16#01#, 16#80#, 16#01#, 16#80#, 16#01#, 16#80#, 16#01#, 16#80#,
16#01#, 16#80#, 16#01#, 16#80#, 16#01#, 16#80#, 16#01#, 16#80#, 16#01#,
16#80#, 16#FF#, 16#FF#, 16#FF#, 16#FF#, 16#03#, 16#F0#, 16#03#, 16#FF#,
16#01#, 16#C0#, 16#E0#, 16#C0#, 16#1C#, 16#60#, 16#03#, 16#B8#, 16#00#,
16#6C#, 16#00#, 16#0F#, 16#00#, 16#03#, 16#00#, 16#00#, 16#C0#, 16#00#,
16#30#, 16#00#, 16#18#, 16#00#, 16#06#, 16#00#, 16#03#, 16#00#, 16#01#,
16#80#, 16#00#, 16#C0#, 16#00#, 16#60#, 16#00#, 16#30#, 16#00#, 16#18#,
16#00#, 16#0C#, 16#00#, 16#06#, 16#00#, 16#03#, 16#00#, 16#01#, 16#80#,
16#00#, 16#C0#, 16#00#, 16#60#, 16#00#, 16#20#, 16#00#, 16#D0#, 16#00#,
16#38#, 16#00#, 16#0F#, 16#FF#, 16#FF#, 16#FF#, 16#FF#, 16#C0#, 16#03#,
16#F8#, 16#01#, 16#FF#, 16#C0#, 16#70#, 16#3C#, 16#18#, 16#01#, 16#C6#,
16#00#, 16#18#, 16#00#, 16#01#, 16#80#, 16#00#, 16#30#, 16#00#, 16#06#,
16#00#, 16#00#, 16#C0#, 16#00#, 16#18#, 16#00#, 16#06#, 16#00#, 16#01#,
16#C0#, 16#00#, 16#70#, 16#01#, 16#FC#, 16#00#, 16#3F#, 16#00#, 16#00#,
16#78#, 16#00#, 16#03#, 16#80#, 16#00#, 16#38#, 16#00#, 16#03#, 16#00#,
16#00#, 16#30#, 16#00#, 16#06#, 16#00#, 16#00#, 16#C0#, 16#00#, 16#18#,
16#00#, 16#03#, 16#00#, 16#00#, 16#D8#, 16#00#, 16#3B#, 16#80#, 16#0E#,
16#3E#, 16#07#, 16#81#, 16#FF#, 16#E0#, 16#07#, 16#E0#, 16#00#, 16#00#,
16#3C#, 16#00#, 16#3C#, 16#00#, 16#6C#, 16#00#, 16#CC#, 16#00#, 16#8C#,
16#01#, 16#8C#, 16#01#, 16#0C#, 16#03#, 16#0C#, 16#06#, 16#0C#, 16#04#,
16#0C#, 16#0C#, 16#0C#, 16#08#, 16#0C#, 16#10#, 16#0C#, 16#30#, 16#0C#,
16#20#, 16#0C#, 16#60#, 16#0C#, 16#40#, 16#0C#, 16#80#, 16#0C#, 16#FF#,
16#FF#, 16#FF#, 16#FF#, 16#00#, 16#0C#, 16#00#, 16#0C#, 16#00#, 16#0C#,
16#00#, 16#0C#, 16#00#, 16#0C#, 16#00#, 16#0C#, 16#00#, 16#FF#, 16#00#,
16#FF#, 16#3F#, 16#FF#, 16#07#, 16#FF#, 16#E0#, 16#C0#, 16#00#, 16#18#,
16#00#, 16#03#, 16#00#, 16#00#, 16#60#, 16#00#, 16#0C#, 16#00#, 16#01#,
16#80#, 16#00#, 16#30#, 16#00#, 16#06#, 16#00#, 16#00#, 16#C7#, 16#E0#,
16#1F#, 16#FF#, 16#03#, 16#80#, 16#70#, 16#00#, 16#03#, 16#00#, 16#00#,
16#30#, 16#00#, 16#06#, 16#00#, 16#00#, 16#60#, 16#00#, 16#0C#, 16#00#,
16#01#, 16#80#, 16#00#, 16#30#, 16#00#, 16#06#, 16#00#, 16#00#, 16#C0#,
16#00#, 16#30#, 16#00#, 16#06#, 16#C0#, 16#01#, 16#DC#, 16#00#, 16#71#,
16#F0#, 16#3C#, 16#0F#, 16#FF#, 16#00#, 16#3F#, 16#00#, 16#00#, 16#3F#,
16#80#, 16#3F#, 16#F0#, 16#3E#, 16#00#, 16#1E#, 16#00#, 16#0E#, 16#00#,
16#07#, 16#00#, 16#03#, 16#80#, 16#00#, 16#C0#, 16#00#, 16#70#, 16#00#,
16#18#, 16#00#, 16#06#, 16#00#, 16#03#, 16#80#, 16#00#, 16#C1#, 16#F8#,
16#31#, 16#FF#, 16#0C#, 16#F0#, 16#F3#, 16#70#, 16#0C#, 16#D8#, 16#01#,
16#BC#, 16#00#, 16#6E#, 16#00#, 16#0F#, 16#80#, 16#03#, 16#C0#, 16#00#,
16#D8#, 16#00#, 16#36#, 16#00#, 16#0D#, 16#80#, 16#03#, 16#30#, 16#01#,
16#8E#, 16#00#, 16#61#, 16#C0#, 16#30#, 16#38#, 16#38#, 16#07#, 16#FC#,
16#00#, 16#7C#, 16#00#, 16#FF#, 16#FF#, 16#FF#, 16#FF#, 16#FC#, 16#00#,
16#0F#, 16#00#, 16#03#, 16#C0#, 16#00#, 16#C0#, 16#00#, 16#60#, 16#00#,
16#18#, 16#00#, 16#06#, 16#00#, 16#03#, 16#00#, 16#00#, 16#C0#, 16#00#,
16#30#, 16#00#, 16#18#, 16#00#, 16#06#, 16#00#, 16#01#, 16#80#, 16#00#,
16#C0#, 16#00#, 16#30#, 16#00#, 16#0C#, 16#00#, 16#06#, 16#00#, 16#01#,
16#80#, 16#00#, 16#60#, 16#00#, 16#30#, 16#00#, 16#0C#, 16#00#, 16#03#,
16#00#, 16#01#, 16#80#, 16#00#, 16#60#, 16#00#, 16#18#, 16#00#, 16#0C#,
16#00#, 16#03#, 16#00#, 16#03#, 16#F0#, 16#03#, 16#FF#, 16#03#, 16#C0#,
16#F1#, 16#C0#, 16#0E#, 16#60#, 16#01#, 16#B8#, 16#00#, 16#7C#, 16#00#,
16#0F#, 16#00#, 16#03#, 16#C0#, 16#00#, 16#F0#, 16#00#, 16#36#, 16#00#,
16#18#, 16#C0#, 16#0C#, 16#1C#, 16#0E#, 16#03#, 16#FF#, 16#00#, 16#FF#,
16#C0#, 16#70#, 16#38#, 16#30#, 16#03#, 16#18#, 16#00#, 16#66#, 16#00#,
16#1B#, 16#00#, 16#03#, 16#C0#, 16#00#, 16#F0#, 16#00#, 16#3C#, 16#00#,
16#0F#, 16#00#, 16#03#, 16#60#, 16#01#, 16#98#, 16#00#, 16#E3#, 16#00#,
16#70#, 16#70#, 16#38#, 16#0F#, 16#FC#, 16#00#, 16#FC#, 16#00#, 16#07#,
16#E0#, 16#03#, 16#FE#, 16#01#, 16#C1#, 16#C0#, 16#C0#, 16#38#, 16#60#,
16#07#, 16#18#, 16#00#, 16#CC#, 16#00#, 16#1B#, 16#00#, 16#06#, 16#C0#,
16#01#, 16#B0#, 16#00#, 16#3C#, 16#00#, 16#1F#, 16#00#, 16#07#, 16#60#,
16#03#, 16#D8#, 16#01#, 16#B3#, 16#00#, 16#CC#, 16#F0#, 16#F3#, 16#0F#,
16#F8#, 16#C1#, 16#F8#, 16#30#, 16#00#, 16#1C#, 16#00#, 16#06#, 16#00#,
16#01#, 16#80#, 16#00#, 16#E0#, 16#00#, 16#30#, 16#00#, 16#1C#, 16#00#,
16#0E#, 16#00#, 16#07#, 16#00#, 16#07#, 16#80#, 16#07#, 16#C0#, 16#FF#,
16#C0#, 16#1F#, 16#C0#, 16#00#, 16#7D#, 16#FF#, 16#FF#, 16#FF#, 16#EF#,
16#80#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#3E#,
16#FF#, 16#FF#, 16#FF#, 16#F7#, 16#C0#, 16#0F#, 16#87#, 16#F1#, 16#FC#,
16#7F#, 16#1F#, 16#C3#, 16#E0#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#07#, 16#F1#, 16#F8#, 16#7C#, 16#1F#, 16#0F#,
16#83#, 16#E0#, 16#F0#, 16#7C#, 16#1E#, 16#07#, 16#81#, 16#C0#, 16#F0#,
16#38#, 16#04#, 16#00#, 16#00#, 16#00#, 16#18#, 16#00#, 16#01#, 16#E0#,
16#00#, 16#1E#, 16#00#, 16#00#, 16#E0#, 16#00#, 16#0F#, 16#00#, 16#00#,
16#F0#, 16#00#, 16#0F#, 16#00#, 16#00#, 16#F0#, 16#00#, 16#07#, 16#00#,
16#00#, 16#78#, 16#00#, 16#07#, 16#80#, 16#00#, 16#0F#, 16#00#, 16#00#,
16#1E#, 16#00#, 16#00#, 16#1E#, 16#00#, 16#00#, 16#1E#, 16#00#, 16#00#,
16#1E#, 16#00#, 16#00#, 16#1E#, 16#00#, 16#00#, 16#3C#, 16#00#, 16#00#,
16#3C#, 16#00#, 16#00#, 16#3C#, 16#00#, 16#00#, 16#38#, 16#00#, 16#00#,
16#20#, 16#7F#, 16#FF#, 16#FF#, 16#7F#, 16#FF#, 16#FF#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#7F#, 16#FF#, 16#FF#, 16#7F#, 16#FF#,
16#FF#, 16#C0#, 16#00#, 16#07#, 16#80#, 16#00#, 16#0F#, 16#00#, 16#00#,
16#1E#, 16#00#, 16#00#, 16#3C#, 16#00#, 16#00#, 16#F0#, 16#00#, 16#01#,
16#E0#, 16#00#, 16#03#, 16#C0#, 16#00#, 16#07#, 16#80#, 16#00#, 16#0F#,
16#00#, 16#00#, 16#3C#, 16#00#, 16#01#, 16#E0#, 16#00#, 16#3C#, 16#00#,
16#07#, 16#80#, 16#00#, 16#F0#, 16#00#, 16#1E#, 16#00#, 16#01#, 16#E0#,
16#00#, 16#3C#, 16#00#, 16#07#, 16#80#, 16#00#, 16#F0#, 16#00#, 16#0E#,
16#00#, 16#00#, 16#60#, 16#00#, 16#00#, 16#07#, 16#F0#, 16#1F#, 16#FE#,
16#3E#, 16#07#, 16#98#, 16#00#, 16#EC#, 16#00#, 16#36#, 16#00#, 16#0F#,
16#00#, 16#06#, 16#00#, 16#03#, 16#00#, 16#01#, 16#80#, 16#01#, 16#C0#,
16#00#, 16#C0#, 16#01#, 16#C0#, 16#03#, 16#C0#, 16#07#, 16#C0#, 16#07#,
16#00#, 16#03#, 16#00#, 16#01#, 16#80#, 16#00#, 16#C0#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#07#, 16#80#, 16#07#, 16#E0#, 16#03#, 16#F0#, 16#01#, 16#F8#, 16#00#,
16#78#, 16#00#, 16#03#, 16#F0#, 16#03#, 16#FF#, 16#01#, 16#E0#, 16#E0#,
16#E0#, 16#1C#, 16#30#, 16#03#, 16#1C#, 16#00#, 16#66#, 16#00#, 16#19#,
16#80#, 16#06#, 16#C0#, 16#01#, 16#B0#, 16#07#, 16#EC#, 16#07#, 16#FB#,
16#03#, 16#C6#, 16#C1#, 16#C1#, 16#B0#, 16#E0#, 16#6C#, 16#30#, 16#1B#,
16#0C#, 16#06#, 16#C3#, 16#01#, 16#B0#, 16#C0#, 16#6C#, 16#18#, 16#1B#,
16#07#, 16#86#, 16#C0#, 16#FF#, 16#F0#, 16#0F#, 16#FC#, 16#00#, 16#03#,
16#00#, 16#00#, 16#60#, 16#00#, 16#18#, 16#00#, 16#07#, 16#00#, 16#00#,
16#C0#, 16#00#, 16#38#, 16#00#, 16#07#, 16#80#, 16#C0#, 16#FF#, 16#F0#,
16#0F#, 16#E0#, 16#07#, 16#FF#, 16#00#, 16#00#, 16#7F#, 16#F0#, 16#00#,
16#00#, 16#1B#, 16#80#, 16#00#, 16#01#, 16#98#, 16#00#, 16#00#, 16#11#,
16#80#, 16#00#, 16#03#, 16#1C#, 16#00#, 16#00#, 16#30#, 16#C0#, 16#00#,
16#06#, 16#0E#, 16#00#, 16#00#, 16#60#, 16#60#, 16#00#, 16#06#, 16#06#,
16#00#, 16#00#, 16#C0#, 16#30#, 16#00#, 16#0C#, 16#03#, 16#00#, 16#00#,
16#80#, 16#38#, 16#00#, 16#18#, 16#01#, 16#80#, 16#01#, 16#80#, 16#18#,
16#00#, 16#3F#, 16#FF#, 16#C0#, 16#03#, 16#FF#, 16#FC#, 16#00#, 16#20#,
16#00#, 16#E0#, 16#06#, 16#00#, 16#06#, 16#00#, 16#60#, 16#00#, 16#60#,
16#0C#, 16#00#, 16#07#, 16#00#, 16#C0#, 16#00#, 16#30#, 16#0C#, 16#00#,
16#03#, 16#81#, 16#80#, 16#00#, 16#18#, 16#7F#, 16#C0#, 16#3F#, 16#F7#,
16#FC#, 16#03#, 16#FF#, 16#FF#, 16#FF#, 16#03#, 16#FF#, 16#FF#, 16#01#,
16#80#, 16#0E#, 16#06#, 16#00#, 16#1C#, 16#18#, 16#00#, 16#38#, 16#60#,
16#00#, 16#61#, 16#80#, 16#01#, 16#86#, 16#00#, 16#06#, 16#18#, 16#00#,
16#38#, 16#60#, 16#01#, 16#C1#, 16#80#, 16#1E#, 16#07#, 16#FF#, 16#E0#,
16#1F#, 16#FF#, 16#C0#, 16#60#, 16#03#, 16#C1#, 16#80#, 16#03#, 16#86#,
16#00#, 16#06#, 16#18#, 16#00#, 16#1C#, 16#60#, 16#00#, 16#31#, 16#80#,
16#00#, 16#C6#, 16#00#, 16#03#, 16#18#, 16#00#, 16#0C#, 16#60#, 16#00#,
16#61#, 16#80#, 16#03#, 16#86#, 16#00#, 16#1C#, 16#FF#, 16#FF#, 16#E3#,
16#FF#, 16#FE#, 16#00#, 16#00#, 16#FC#, 16#00#, 16#0F#, 16#FE#, 16#60#,
16#F0#, 16#3D#, 16#87#, 16#00#, 16#3E#, 16#38#, 16#00#, 16#38#, 16#C0#,
16#00#, 16#E7#, 16#00#, 16#01#, 16#98#, 16#00#, 16#06#, 16#60#, 16#00#,
16#03#, 16#00#, 16#00#, 16#0C#, 16#00#, 16#00#, 16#30#, 16#00#, 16#00#,
16#C0#, 16#00#, 16#03#, 16#00#, 16#00#, 16#0C#, 16#00#, 16#00#, 16#30#,
16#00#, 16#00#, 16#C0#, 16#00#, 16#03#, 16#00#, 16#00#, 16#0C#, 16#00#,
16#00#, 16#18#, 16#00#, 16#00#, 16#60#, 16#00#, 16#01#, 16#C0#, 16#00#,
16#03#, 16#80#, 16#00#, 16#C7#, 16#00#, 16#06#, 16#0E#, 16#00#, 16#70#,
16#1E#, 16#07#, 16#80#, 16#3F#, 16#FC#, 16#00#, 16#1F#, 16#80#, 16#FF#,
16#FE#, 16#03#, 16#FF#, 16#FE#, 16#03#, 16#00#, 16#3C#, 16#0C#, 16#00#,
16#38#, 16#30#, 16#00#, 16#70#, 16#C0#, 16#00#, 16#C3#, 16#00#, 16#03#,
16#8C#, 16#00#, 16#06#, 16#30#, 16#00#, 16#1C#, 16#C0#, 16#00#, 16#33#,
16#00#, 16#00#, 16#CC#, 16#00#, 16#03#, 16#30#, 16#00#, 16#0C#, 16#C0#,
16#00#, 16#33#, 16#00#, 16#00#, 16#CC#, 16#00#, 16#03#, 16#30#, 16#00#,
16#0C#, 16#C0#, 16#00#, 16#33#, 16#00#, 16#01#, 16#8C#, 16#00#, 16#06#,
16#30#, 16#00#, 16#30#, 16#C0#, 16#01#, 16#C3#, 16#00#, 16#0E#, 16#0C#,
16#00#, 16#F0#, 16#FF#, 16#FF#, 16#83#, 16#FF#, 16#F8#, 16#00#, 16#FF#,
16#FF#, 16#FB#, 16#FF#, 16#FF#, 16#E1#, 16#80#, 16#01#, 16#86#, 16#00#,
16#06#, 16#18#, 16#00#, 16#18#, 16#60#, 16#00#, 16#61#, 16#80#, 16#01#,
16#86#, 16#00#, 16#00#, 16#18#, 16#0C#, 16#00#, 16#60#, 16#30#, 16#01#,
16#80#, 16#C0#, 16#07#, 16#FF#, 16#00#, 16#1F#, 16#FC#, 16#00#, 16#60#,
16#30#, 16#01#, 16#80#, 16#C0#, 16#06#, 16#03#, 16#00#, 16#18#, 16#00#,
16#00#, 16#60#, 16#00#, 16#01#, 16#80#, 16#00#, 16#C6#, 16#00#, 16#03#,
16#18#, 16#00#, 16#0C#, 16#60#, 16#00#, 16#31#, 16#80#, 16#00#, 16#C6#,
16#00#, 16#03#, 16#FF#, 16#FF#, 16#FF#, 16#FF#, 16#FF#, 16#F0#, 16#FF#,
16#FF#, 16#FF#, 16#FF#, 16#FF#, 16#F1#, 16#80#, 16#00#, 16#C6#, 16#00#,
16#03#, 16#18#, 16#00#, 16#0C#, 16#60#, 16#00#, 16#31#, 16#80#, 16#00#,
16#C6#, 16#00#, 16#00#, 16#18#, 16#0C#, 16#00#, 16#60#, 16#30#, 16#01#,
16#80#, 16#C0#, 16#07#, 16#FF#, 16#00#, 16#1F#, 16#FC#, 16#00#, 16#60#,
16#30#, 16#01#, 16#80#, 16#C0#, 16#06#, 16#03#, 16#00#, 16#18#, 16#00#,
16#00#, 16#60#, 16#00#, 16#01#, 16#80#, 16#00#, 16#06#, 16#00#, 16#00#,
16#18#, 16#00#, 16#00#, 16#60#, 16#00#, 16#01#, 16#80#, 16#00#, 16#06#,
16#00#, 16#00#, 16#FF#, 16#F0#, 16#03#, 16#FF#, 16#C0#, 16#00#, 16#00#,
16#FF#, 16#00#, 16#07#, 16#FF#, 16#98#, 16#1E#, 16#03#, 16#F0#, 16#70#,
16#01#, 16#E1#, 16#80#, 16#01#, 16#C6#, 16#00#, 16#01#, 16#9C#, 16#00#,
16#03#, 16#30#, 16#00#, 16#00#, 16#60#, 16#00#, 16#01#, 16#C0#, 16#00#,
16#03#, 16#00#, 16#00#, 16#06#, 16#00#, 16#00#, 16#0C#, 16#00#, 16#00#,
16#18#, 16#00#, 16#00#, 16#30#, 16#00#, 16#00#, 16#60#, 16#03#, 16#FF#,
16#C0#, 16#07#, 16#FF#, 16#80#, 16#00#, 16#1B#, 16#00#, 16#00#, 16#37#,
16#00#, 16#00#, 16#66#, 16#00#, 16#00#, 16#CC#, 16#00#, 16#01#, 16#8C#,
16#00#, 16#03#, 16#1C#, 16#00#, 16#06#, 16#1E#, 16#00#, 16#0C#, 16#0F#,
16#00#, 16#F8#, 16#0F#, 16#FF#, 16#C0#, 16#03#, 16#FC#, 16#00#, 16#7F#,
16#01#, 16#FC#, 16#FE#, 16#03#, 16#F8#, 16#60#, 16#00#, 16#C0#, 16#C0#,
16#01#, 16#81#, 16#80#, 16#03#, 16#03#, 16#00#, 16#06#, 16#06#, 16#00#,
16#0C#, 16#0C#, 16#00#, 16#18#, 16#18#, 16#00#, 16#30#, 16#30#, 16#00#,
16#60#, 16#60#, 16#00#, 16#C0#, 16#FF#, 16#FF#, 16#81#, 16#FF#, 16#FF#,
16#03#, 16#00#, 16#06#, 16#06#, 16#00#, 16#0C#, 16#0C#, 16#00#, 16#18#,
16#18#, 16#00#, 16#30#, 16#30#, 16#00#, 16#60#, 16#60#, 16#00#, 16#C0#,
16#C0#, 16#01#, 16#81#, 16#80#, 16#03#, 16#03#, 16#00#, 16#06#, 16#06#,
16#00#, 16#0C#, 16#0C#, 16#00#, 16#18#, 16#FF#, 16#01#, 16#FF#, 16#FE#,
16#03#, 16#FC#, 16#FF#, 16#FF#, 16#FF#, 16#FF#, 16#01#, 16#80#, 16#01#,
16#80#, 16#01#, 16#80#, 16#01#, 16#80#, 16#01#, 16#80#, 16#01#, 16#80#,
16#01#, 16#80#, 16#01#, 16#80#, 16#01#, 16#80#, 16#01#, 16#80#, 16#01#,
16#80#, 16#01#, 16#80#, 16#01#, 16#80#, 16#01#, 16#80#, 16#01#, 16#80#,
16#01#, 16#80#, 16#01#, 16#80#, 16#01#, 16#80#, 16#01#, 16#80#, 16#01#,
16#80#, 16#01#, 16#80#, 16#01#, 16#80#, 16#FF#, 16#FF#, 16#FF#, 16#FF#,
16#00#, 16#FF#, 16#FE#, 16#01#, 16#FF#, 16#FC#, 16#00#, 16#03#, 16#00#,
16#00#, 16#06#, 16#00#, 16#00#, 16#0C#, 16#00#, 16#00#, 16#18#, 16#00#,
16#00#, 16#30#, 16#00#, 16#00#, 16#60#, 16#00#, 16#00#, 16#C0#, 16#00#,
16#01#, 16#80#, 16#00#, 16#03#, 16#00#, 16#00#, 16#06#, 16#00#, 16#00#,
16#0C#, 16#00#, 16#00#, 16#18#, 16#00#, 16#00#, 16#30#, 16#60#, 16#00#,
16#60#, 16#C0#, 16#00#, 16#C1#, 16#80#, 16#01#, 16#83#, 16#00#, 16#03#,
16#06#, 16#00#, 16#06#, 16#0C#, 16#00#, 16#0C#, 16#18#, 16#00#, 16#30#,
16#38#, 16#00#, 16#60#, 16#38#, 16#01#, 16#80#, 16#3C#, 16#0E#, 16#00#,
16#3F#, 16#F8#, 16#00#, 16#0F#, 16#C0#, 16#00#, 16#FF#, 16#81#, 16#FE#,
16#FF#, 16#81#, 16#FE#, 16#18#, 16#00#, 16#30#, 16#18#, 16#00#, 16#E0#,
16#18#, 16#01#, 16#C0#, 16#18#, 16#03#, 16#80#, 16#18#, 16#07#, 16#00#,
16#18#, 16#0C#, 16#00#, 16#18#, 16#18#, 16#00#, 16#18#, 16#70#, 16#00#,
16#18#, 16#E0#, 16#00#, 16#19#, 16#E0#, 16#00#, 16#1B#, 16#F8#, 16#00#,
16#1F#, 16#1C#, 16#00#, 16#1C#, 16#06#, 16#00#, 16#18#, 16#03#, 16#00#,
16#18#, 16#03#, 16#80#, 16#18#, 16#01#, 16#80#, 16#18#, 16#00#, 16#C0#,
16#18#, 16#00#, 16#C0#, 16#18#, 16#00#, 16#60#, 16#18#, 16#00#, 16#60#,
16#18#, 16#00#, 16#70#, 16#18#, 16#00#, 16#30#, 16#FF#, 16#80#, 16#3F#,
16#FF#, 16#80#, 16#1F#, 16#FF#, 16#F0#, 16#07#, 16#FF#, 16#80#, 16#01#,
16#80#, 16#00#, 16#0C#, 16#00#, 16#00#, 16#60#, 16#00#, 16#03#, 16#00#,
16#00#, 16#18#, 16#00#, 16#00#, 16#C0#, 16#00#, 16#06#, 16#00#, 16#00#,
16#30#, 16#00#, 16#01#, 16#80#, 16#00#, 16#0C#, 16#00#, 16#00#, 16#60#,
16#00#, 16#03#, 16#00#, 16#00#, 16#18#, 16#00#, 16#00#, 16#C0#, 16#00#,
16#06#, 16#00#, 16#18#, 16#30#, 16#00#, 16#C1#, 16#80#, 16#06#, 16#0C#,
16#00#, 16#30#, 16#60#, 16#01#, 16#83#, 16#00#, 16#0C#, 16#18#, 16#00#,
16#60#, 16#C0#, 16#03#, 16#FF#, 16#FF#, 16#FF#, 16#FF#, 16#FF#, 16#C0#,
16#FC#, 16#00#, 16#0F#, 16#FF#, 16#00#, 16#03#, 16#F3#, 16#60#, 16#01#,
16#B0#, 16#D8#, 16#00#, 16#6C#, 16#33#, 16#00#, 16#33#, 16#0C#, 16#C0#,
16#0C#, 16#C3#, 16#38#, 16#06#, 16#30#, 16#C6#, 16#01#, 16#8C#, 16#31#,
16#C0#, 16#E3#, 16#0C#, 16#30#, 16#30#, 16#C3#, 16#0E#, 16#0C#, 16#30#,
16#C1#, 16#86#, 16#0C#, 16#30#, 16#71#, 16#83#, 16#0C#, 16#0C#, 16#C0#,
16#C3#, 16#03#, 16#B0#, 16#30#, 16#C0#, 16#78#, 16#0C#, 16#30#, 16#1E#,
16#03#, 16#0C#, 16#03#, 16#00#, 16#C3#, 16#00#, 16#00#, 16#30#, 16#C0#,
16#00#, 16#0C#, 16#30#, 16#00#, 16#03#, 16#0C#, 16#00#, 16#00#, 16#C3#,
16#00#, 16#00#, 16#30#, 16#C0#, 16#00#, 16#0C#, 16#FF#, 16#00#, 16#3F#,
16#FF#, 16#C0#, 16#0F#, 16#F0#, 16#FC#, 16#00#, 16#FF#, 16#FC#, 16#00#,
16#FF#, 16#1E#, 16#00#, 16#0C#, 16#1F#, 16#00#, 16#0C#, 16#1B#, 16#00#,
16#0C#, 16#19#, 16#80#, 16#0C#, 16#19#, 16#C0#, 16#0C#, 16#18#, 16#C0#,
16#0C#, 16#18#, 16#60#, 16#0C#, 16#18#, 16#60#, 16#0C#, 16#18#, 16#30#,
16#0C#, 16#18#, 16#38#, 16#0C#, 16#18#, 16#18#, 16#0C#, 16#18#, 16#0C#,
16#0C#, 16#18#, 16#0E#, 16#0C#, 16#18#, 16#06#, 16#0C#, 16#18#, 16#03#,
16#0C#, 16#18#, 16#03#, 16#0C#, 16#18#, 16#01#, 16#8C#, 16#18#, 16#01#,
16#CC#, 16#18#, 16#00#, 16#CC#, 16#18#, 16#00#, 16#6C#, 16#18#, 16#00#,
16#7C#, 16#18#, 16#00#, 16#3C#, 16#7F#, 16#80#, 16#1C#, 16#7F#, 16#80#,
16#1C#, 16#00#, 16#7E#, 16#00#, 16#01#, 16#FF#, 16#C0#, 16#07#, 16#81#,
16#E0#, 16#0E#, 16#00#, 16#70#, 16#1C#, 16#00#, 16#38#, 16#38#, 16#00#,
16#1C#, 16#30#, 16#00#, 16#0C#, 16#70#, 16#00#, 16#0E#, 16#60#, 16#00#,
16#06#, 16#60#, 16#00#, 16#06#, 16#C0#, 16#00#, 16#03#, 16#C0#, 16#00#,
16#03#, 16#C0#, 16#00#, 16#03#, 16#C0#, 16#00#, 16#03#, 16#C0#, 16#00#,
16#03#, 16#C0#, 16#00#, 16#03#, 16#C0#, 16#00#, 16#03#, 16#C0#, 16#00#,
16#03#, 16#60#, 16#00#, 16#06#, 16#60#, 16#00#, 16#06#, 16#70#, 16#00#,
16#0E#, 16#30#, 16#00#, 16#0C#, 16#38#, 16#00#, 16#1C#, 16#1C#, 16#00#,
16#38#, 16#0E#, 16#00#, 16#70#, 16#07#, 16#81#, 16#E0#, 16#03#, 16#FF#,
16#C0#, 16#00#, 16#7E#, 16#00#, 16#FF#, 16#FF#, 16#07#, 16#FF#, 16#FE#,
16#06#, 16#00#, 16#78#, 16#30#, 16#00#, 16#E1#, 16#80#, 16#03#, 16#0C#,
16#00#, 16#0C#, 16#60#, 16#00#, 16#63#, 16#00#, 16#03#, 16#18#, 16#00#,
16#18#, 16#C0#, 16#01#, 16#C6#, 16#00#, 16#0C#, 16#30#, 16#00#, 16#C1#,
16#80#, 16#1E#, 16#0F#, 16#FF#, 16#C0#, 16#7F#, 16#F8#, 16#03#, 16#00#,
16#00#, 16#18#, 16#00#, 16#00#, 16#C0#, 16#00#, 16#06#, 16#00#, 16#00#,
16#30#, 16#00#, 16#01#, 16#80#, 16#00#, 16#0C#, 16#00#, 16#00#, 16#60#,
16#00#, 16#03#, 16#00#, 16#00#, 16#FF#, 16#F0#, 16#07#, 16#FF#, 16#80#,
16#00#, 16#00#, 16#7E#, 16#00#, 16#01#, 16#FF#, 16#80#, 16#07#, 16#81#,
16#E0#, 16#0E#, 16#00#, 16#70#, 16#1C#, 16#00#, 16#38#, 16#38#, 16#00#,
16#1C#, 16#30#, 16#00#, 16#0C#, 16#70#, 16#00#, 16#0E#, 16#60#, 16#00#,
16#06#, 16#60#, 16#00#, 16#06#, 16#C0#, 16#00#, 16#03#, 16#C0#, 16#00#,
16#03#, 16#C0#, 16#00#, 16#03#, 16#C0#, 16#00#, 16#03#, 16#C0#, 16#00#,
16#03#, 16#C0#, 16#00#, 16#03#, 16#C0#, 16#00#, 16#03#, 16#C0#, 16#00#,
16#03#, 16#60#, 16#00#, 16#06#, 16#60#, 16#00#, 16#06#, 16#70#, 16#00#,
16#0E#, 16#30#, 16#00#, 16#0C#, 16#18#, 16#00#, 16#1C#, 16#0C#, 16#00#,
16#38#, 16#06#, 16#00#, 16#70#, 16#03#, 16#81#, 16#E0#, 16#00#, 16#FF#,
16#C0#, 16#00#, 16#7E#, 16#00#, 16#00#, 16#E0#, 16#00#, 16#03#, 16#FF#,
16#87#, 16#07#, 16#FF#, 16#FE#, 16#07#, 16#00#, 16#F8#, 16#FF#, 16#FE#,
16#00#, 16#FF#, 16#FF#, 16#80#, 16#18#, 16#03#, 16#C0#, 16#18#, 16#00#,
16#E0#, 16#18#, 16#00#, 16#60#, 16#18#, 16#00#, 16#30#, 16#18#, 16#00#,
16#30#, 16#18#, 16#00#, 16#30#, 16#18#, 16#00#, 16#30#, 16#18#, 16#00#,
16#70#, 16#18#, 16#00#, 16#60#, 16#18#, 16#01#, 16#C0#, 16#18#, 16#07#,
16#80#, 16#1F#, 16#FF#, 16#00#, 16#1F#, 16#FC#, 16#00#, 16#18#, 16#0E#,
16#00#, 16#18#, 16#07#, 16#00#, 16#18#, 16#03#, 16#80#, 16#18#, 16#01#,
16#C0#, 16#18#, 16#00#, 16#E0#, 16#18#, 16#00#, 16#60#, 16#18#, 16#00#,
16#30#, 16#18#, 16#00#, 16#30#, 16#18#, 16#00#, 16#18#, 16#FF#, 16#80#,
16#1F#, 16#FF#, 16#80#, 16#0F#, 16#03#, 16#F8#, 16#00#, 16#FF#, 16#E6#,
16#1E#, 16#07#, 16#E3#, 16#80#, 16#1E#, 16#30#, 16#00#, 16#E6#, 16#00#,
16#06#, 16#60#, 16#00#, 16#66#, 16#00#, 16#06#, 16#60#, 16#00#, 16#07#,
16#00#, 16#00#, 16#30#, 16#00#, 16#01#, 16#C0#, 16#00#, 16#0F#, 16#C0#,
16#00#, 16#3F#, 16#C0#, 16#00#, 16#3F#, 16#80#, 16#00#, 16#1C#, 16#00#,
16#00#, 16#E0#, 16#00#, 16#07#, 16#00#, 16#00#, 16#30#, 16#00#, 16#03#,
16#C0#, 16#00#, 16#3C#, 16#00#, 16#03#, 16#E0#, 16#00#, 16#7E#, 16#00#,
16#06#, 16#F8#, 16#01#, 16#ED#, 16#E0#, 16#7C#, 16#CF#, 16#FF#, 16#00#,
16#3F#, 16#C0#, 16#FF#, 16#FF#, 16#FF#, 16#FF#, 16#FF#, 16#FC#, 16#03#,
16#00#, 16#F0#, 16#0C#, 16#03#, 16#C0#, 16#30#, 16#0F#, 16#00#, 16#C0#,
16#3C#, 16#03#, 16#00#, 16#C0#, 16#0C#, 16#00#, 16#00#, 16#30#, 16#00#,
16#00#, 16#C0#, 16#00#, 16#03#, 16#00#, 16#00#, 16#0C#, 16#00#, 16#00#,
16#30#, 16#00#, 16#00#, 16#C0#, 16#00#, 16#03#, 16#00#, 16#00#, 16#0C#,
16#00#, 16#00#, 16#30#, 16#00#, 16#00#, 16#C0#, 16#00#, 16#03#, 16#00#,
16#00#, 16#0C#, 16#00#, 16#00#, 16#30#, 16#00#, 16#00#, 16#C0#, 16#00#,
16#03#, 16#00#, 16#00#, 16#0C#, 16#00#, 16#0F#, 16#FF#, 16#C0#, 16#3F#,
16#FF#, 16#00#, 16#FF#, 16#01#, 16#FF#, 16#FE#, 16#03#, 16#FC#, 16#C0#,
16#00#, 16#61#, 16#80#, 16#00#, 16#C3#, 16#00#, 16#01#, 16#86#, 16#00#,
16#03#, 16#0C#, 16#00#, 16#06#, 16#18#, 16#00#, 16#0C#, 16#30#, 16#00#,
16#18#, 16#60#, 16#00#, 16#30#, 16#C0#, 16#00#, 16#61#, 16#80#, 16#00#,
16#C3#, 16#00#, 16#01#, 16#86#, 16#00#, 16#03#, 16#0C#, 16#00#, 16#06#,
16#18#, 16#00#, 16#0C#, 16#30#, 16#00#, 16#18#, 16#60#, 16#00#, 16#30#,
16#C0#, 16#00#, 16#61#, 16#80#, 16#00#, 16#C3#, 16#80#, 16#03#, 16#83#,
16#00#, 16#06#, 16#07#, 16#00#, 16#1C#, 16#07#, 16#00#, 16#70#, 16#07#,
16#83#, 16#C0#, 16#07#, 16#FF#, 16#00#, 16#03#, 16#F8#, 16#00#, 16#7F#,
16#C0#, 16#3F#, 16#F7#, 16#FC#, 16#03#, 16#FF#, 16#18#, 16#00#, 16#01#,
16#80#, 16#C0#, 16#00#, 16#30#, 16#0C#, 16#00#, 16#03#, 16#00#, 16#60#,
16#00#, 16#30#, 16#06#, 16#00#, 16#06#, 16#00#, 16#60#, 16#00#, 16#60#,
16#03#, 16#00#, 16#0C#, 16#00#, 16#30#, 16#00#, 16#C0#, 16#03#, 16#80#,
16#0C#, 16#00#, 16#18#, 16#01#, 16#80#, 16#01#, 16#80#, 16#18#, 16#00#,
16#0C#, 16#03#, 16#00#, 16#00#, 16#C0#, 16#30#, 16#00#, 16#0E#, 16#03#,
16#00#, 16#00#, 16#60#, 16#60#, 16#00#, 16#06#, 16#06#, 16#00#, 16#00#,
16#30#, 16#C0#, 16#00#, 16#03#, 16#0C#, 16#00#, 16#00#, 16#30#, 16#80#,
16#00#, 16#01#, 16#98#, 16#00#, 16#00#, 16#19#, 16#80#, 16#00#, 16#00#,
16#F0#, 16#00#, 16#00#, 16#0F#, 16#00#, 16#00#, 16#00#, 16#E0#, 16#00#,
16#FF#, 16#80#, 16#7F#, 16#FF#, 16#E0#, 16#1F#, 16#F3#, 16#00#, 16#00#,
16#10#, 16#C0#, 16#00#, 16#04#, 16#30#, 16#00#, 16#03#, 16#0C#, 16#03#,
16#80#, 16#C3#, 16#01#, 16#E0#, 16#30#, 16#60#, 16#78#, 16#0C#, 16#18#,
16#1F#, 16#02#, 16#06#, 16#05#, 16#C0#, 16#81#, 16#83#, 16#30#, 16#20#,
16#60#, 16#CC#, 16#18#, 16#18#, 16#33#, 16#86#, 16#06#, 16#18#, 16#61#,
16#81#, 16#86#, 16#18#, 16#60#, 16#71#, 16#87#, 16#10#, 16#0C#, 16#40#,
16#C4#, 16#03#, 16#30#, 16#31#, 16#00#, 16#CC#, 16#0E#, 16#40#, 16#33#,
16#03#, 16#B0#, 16#0D#, 16#80#, 16#6C#, 16#03#, 16#60#, 16#1B#, 16#00#,
16#D8#, 16#07#, 16#80#, 16#34#, 16#00#, 16#E0#, 16#07#, 16#00#, 16#38#,
16#01#, 16#C0#, 16#0E#, 16#00#, 16#7F#, 16#00#, 16#FF#, 16#7F#, 16#00#,
16#FF#, 16#18#, 16#00#, 16#18#, 16#0C#, 16#00#, 16#38#, 16#0E#, 16#00#,
16#70#, 16#07#, 16#00#, 16#60#, 16#03#, 16#00#, 16#C0#, 16#01#, 16#81#,
16#80#, 16#01#, 16#C3#, 16#80#, 16#00#, 16#E7#, 16#00#, 16#00#, 16#76#,
16#00#, 16#00#, 16#3C#, 16#00#, 16#00#, 16#18#, 16#00#, 16#00#, 16#3C#,
16#00#, 16#00#, 16#7E#, 16#00#, 16#00#, 16#67#, 16#00#, 16#00#, 16#C3#,
16#00#, 16#01#, 16#81#, 16#80#, 16#03#, 16#81#, 16#C0#, 16#07#, 16#00#,
16#E0#, 16#06#, 16#00#, 16#70#, 16#0C#, 16#00#, 16#30#, 16#18#, 16#00#,
16#18#, 16#38#, 16#00#, 16#1C#, 16#FF#, 16#00#, 16#FF#, 16#FF#, 16#00#,
16#FF#, 16#FF#, 16#00#, 16#FF#, 16#FF#, 16#00#, 16#FF#, 16#18#, 16#00#,
16#18#, 16#1C#, 16#00#, 16#30#, 16#0E#, 16#00#, 16#70#, 16#06#, 16#00#,
16#60#, 16#03#, 16#00#, 16#C0#, 16#03#, 16#81#, 16#C0#, 16#01#, 16#81#,
16#80#, 16#00#, 16#C3#, 16#00#, 16#00#, 16#E7#, 16#00#, 16#00#, 16#66#,
16#00#, 16#00#, 16#3C#, 16#00#, 16#00#, 16#3C#, 16#00#, 16#00#, 16#18#,
16#00#, 16#00#, 16#18#, 16#00#, 16#00#, 16#18#, 16#00#, 16#00#, 16#18#,
16#00#, 16#00#, 16#18#, 16#00#, 16#00#, 16#18#, 16#00#, 16#00#, 16#18#,
16#00#, 16#00#, 16#18#, 16#00#, 16#00#, 16#18#, 16#00#, 16#00#, 16#18#,
16#00#, 16#07#, 16#FF#, 16#E0#, 16#07#, 16#FF#, 16#E0#, 16#7F#, 16#FF#,
16#9F#, 16#FF#, 16#E6#, 16#00#, 16#19#, 16#80#, 16#0C#, 16#60#, 16#07#,
16#18#, 16#03#, 16#86#, 16#00#, 16#C1#, 16#80#, 16#70#, 16#00#, 16#38#,
16#00#, 16#0C#, 16#00#, 16#06#, 16#00#, 16#03#, 16#80#, 16#00#, 16#C0#,
16#00#, 16#60#, 16#00#, 16#30#, 16#00#, 16#1C#, 16#00#, 16#06#, 16#00#,
16#03#, 16#00#, 16#31#, 16#C0#, 16#0C#, 16#60#, 16#03#, 16#30#, 16#00#,
16#D8#, 16#00#, 16#3E#, 16#00#, 16#0F#, 16#00#, 16#03#, 16#FF#, 16#FF#,
16#FF#, 16#FF#, 16#F0#, 16#FF#, 16#FF#, 16#06#, 16#0C#, 16#18#, 16#30#,
16#60#, 16#C1#, 16#83#, 16#06#, 16#0C#, 16#18#, 16#30#, 16#60#, 16#C1#,
16#83#, 16#06#, 16#0C#, 16#18#, 16#30#, 16#60#, 16#C1#, 16#83#, 16#06#,
16#0C#, 16#18#, 16#30#, 16#60#, 16#FF#, 16#FC#, 16#C0#, 16#00#, 16#38#,
16#00#, 16#0E#, 16#00#, 16#01#, 16#C0#, 16#00#, 16#70#, 16#00#, 16#0E#,
16#00#, 16#03#, 16#80#, 16#00#, 16#60#, 16#00#, 16#1C#, 16#00#, 16#03#,
16#00#, 16#00#, 16#E0#, 16#00#, 16#18#, 16#00#, 16#07#, 16#00#, 16#00#,
16#C0#, 16#00#, 16#38#, 16#00#, 16#06#, 16#00#, 16#01#, 16#C0#, 16#00#,
16#30#, 16#00#, 16#0E#, 16#00#, 16#01#, 16#80#, 16#00#, 16#70#, 16#00#,
16#0C#, 16#00#, 16#03#, 16#80#, 16#00#, 16#60#, 16#00#, 16#1C#, 16#00#,
16#03#, 16#00#, 16#00#, 16#E0#, 16#00#, 16#18#, 16#00#, 16#07#, 16#00#,
16#00#, 16#C0#, 16#00#, 16#38#, 16#00#, 16#06#, 16#00#, 16#01#, 16#C0#,
16#00#, 16#30#, 16#00#, 16#0C#, 16#FF#, 16#FC#, 16#18#, 16#30#, 16#60#,
16#C1#, 16#83#, 16#06#, 16#0C#, 16#18#, 16#30#, 16#60#, 16#C1#, 16#83#,
16#06#, 16#0C#, 16#18#, 16#30#, 16#60#, 16#C1#, 16#83#, 16#06#, 16#0C#,
16#18#, 16#30#, 16#60#, 16#C1#, 16#83#, 16#FF#, 16#FC#, 16#00#, 16#40#,
16#00#, 16#30#, 16#00#, 16#1E#, 16#00#, 16#0E#, 16#C0#, 16#07#, 16#38#,
16#01#, 16#87#, 16#00#, 16#C0#, 16#C0#, 16#60#, 16#18#, 16#30#, 16#03#,
16#1C#, 16#00#, 16#E6#, 16#00#, 16#1F#, 16#00#, 16#03#, 16#FF#, 16#FF#,
16#FF#, 16#FF#, 16#FF#, 16#FF#, 16#FF#, 16#C0#, 16#E0#, 16#70#, 16#3C#,
16#0E#, 16#07#, 16#03#, 16#01#, 16#FC#, 16#00#, 16#7F#, 16#FC#, 16#01#,
16#C0#, 16#3C#, 16#00#, 16#00#, 16#30#, 16#00#, 16#00#, 16#60#, 16#00#,
16#01#, 16#80#, 16#00#, 16#06#, 16#00#, 16#00#, 16#18#, 16#00#, 16#00#,
16#60#, 16#0F#, 16#F9#, 16#81#, 16#FF#, 16#FE#, 16#0F#, 16#80#, 16#38#,
16#70#, 16#00#, 16#63#, 16#80#, 16#01#, 16#8C#, 16#00#, 16#06#, 16#30#,
16#00#, 16#18#, 16#C0#, 16#00#, 16#E3#, 16#00#, 16#07#, 16#86#, 16#00#,
16#76#, 16#1E#, 16#07#, 16#9F#, 16#3F#, 16#F8#, 16#7C#, 16#3F#, 16#80#,
16#00#, 16#F8#, 16#00#, 16#01#, 16#F0#, 16#00#, 16#00#, 16#60#, 16#00#,
16#00#, 16#C0#, 16#00#, 16#01#, 16#80#, 16#00#, 16#03#, 16#00#, 16#00#,
16#06#, 16#00#, 16#00#, 16#0C#, 16#1F#, 16#80#, 16#18#, 16#FF#, 16#C0#,
16#33#, 16#81#, 16#C0#, 16#6E#, 16#01#, 16#C0#, 16#F0#, 16#00#, 16#C1#,
16#E0#, 16#01#, 16#C3#, 16#80#, 16#01#, 16#87#, 16#00#, 16#03#, 16#8C#,
16#00#, 16#03#, 16#18#, 16#00#, 16#06#, 16#30#, 16#00#, 16#0C#, 16#60#,
16#00#, 16#18#, 16#C0#, 16#00#, 16#31#, 16#80#, 16#00#, 16#63#, 16#80#,
16#01#, 16#87#, 16#00#, 16#03#, 16#0F#, 16#00#, 16#0E#, 16#1F#, 16#00#,
16#38#, 16#37#, 16#00#, 16#E3#, 16#E7#, 16#03#, 16#87#, 16#C7#, 16#FE#,
16#00#, 16#03#, 16#F0#, 16#00#, 16#01#, 16#FC#, 16#00#, 16#3F#, 16#F9#,
16#83#, 16#C0#, 16#FC#, 16#38#, 16#01#, 16#E3#, 16#00#, 16#07#, 16#38#,
16#00#, 16#19#, 16#80#, 16#00#, 16#DC#, 16#00#, 16#06#, 16#C0#, 16#00#,
16#06#, 16#00#, 16#00#, 16#30#, 16#00#, 16#01#, 16#80#, 16#00#, 16#0C#,
16#00#, 16#00#, 16#60#, 16#00#, 16#03#, 16#80#, 16#00#, 16#0C#, 16#00#,
16#00#, 16#70#, 16#00#, 16#01#, 16#80#, 16#00#, 16#C7#, 16#00#, 16#1E#,
16#1E#, 16#03#, 16#C0#, 16#7F#, 16#FC#, 16#00#, 16#FF#, 16#00#, 16#00#,
16#00#, 16#F8#, 16#00#, 16#00#, 16#F8#, 16#00#, 16#00#, 16#18#, 16#00#,
16#00#, 16#18#, 16#00#, 16#00#, 16#18#, 16#00#, 16#00#, 16#18#, 16#00#,
16#00#, 16#18#, 16#01#, 16#F8#, 16#18#, 16#07#, 16#FE#, 16#18#, 16#0F#,
16#07#, 16#98#, 16#1C#, 16#01#, 16#D8#, 16#38#, 16#00#, 16#F8#, 16#70#,
16#00#, 16#78#, 16#60#, 16#00#, 16#38#, 16#E0#, 16#00#, 16#38#, 16#C0#,
16#00#, 16#18#, 16#C0#, 16#00#, 16#18#, 16#C0#, 16#00#, 16#18#, 16#C0#,
16#00#, 16#18#, 16#C0#, 16#00#, 16#18#, 16#C0#, 16#00#, 16#18#, 16#60#,
16#00#, 16#38#, 16#60#, 16#00#, 16#38#, 16#70#, 16#00#, 16#78#, 16#38#,
16#00#, 16#D8#, 16#1C#, 16#01#, 16#D8#, 16#0F#, 16#07#, 16#9F#, 16#07#,
16#FE#, 16#1F#, 16#01#, 16#F8#, 16#00#, 16#01#, 16#FC#, 16#00#, 16#3F#,
16#F8#, 16#07#, 16#80#, 16#F0#, 16#70#, 16#01#, 16#C3#, 16#00#, 16#07#,
16#30#, 16#00#, 16#19#, 16#80#, 16#00#, 16#78#, 16#00#, 16#03#, 16#C0#,
16#00#, 16#1F#, 16#FF#, 16#FF#, 16#FF#, 16#FF#, 16#FF#, 16#80#, 16#00#,
16#0C#, 16#00#, 16#00#, 16#60#, 16#00#, 16#01#, 16#80#, 16#00#, 16#0C#,
16#00#, 16#00#, 16#30#, 16#00#, 16#01#, 16#C0#, 16#00#, 16#C7#, 16#00#,
16#0E#, 16#1E#, 16#03#, 16#E0#, 16#3F#, 16#FC#, 16#00#, 16#7F#, 16#00#,
16#00#, 16#7F#, 16#C0#, 16#3F#, 16#FC#, 16#0E#, 16#00#, 16#03#, 16#80#,
16#00#, 16#60#, 16#00#, 16#0C#, 16#00#, 16#01#, 16#80#, 16#00#, 16#30#,
16#00#, 16#FF#, 16#FF#, 16#9F#, 16#FF#, 16#F0#, 16#18#, 16#00#, 16#03#,
16#00#, 16#00#, 16#60#, 16#00#, 16#0C#, 16#00#, 16#01#, 16#80#, 16#00#,
16#30#, 16#00#, 16#06#, 16#00#, 16#00#, 16#C0#, 16#00#, 16#18#, 16#00#,
16#03#, 16#00#, 16#00#, 16#60#, 16#00#, 16#0C#, 16#00#, 16#01#, 16#80#,
16#00#, 16#30#, 16#00#, 16#06#, 16#00#, 16#00#, 16#C0#, 16#03#, 16#FF#,
16#FC#, 16#7F#, 16#FF#, 16#80#, 16#01#, 16#F8#, 16#00#, 16#0F#, 16#FC#,
16#7C#, 16#38#, 16#1C#, 16#F8#, 16#E0#, 16#0D#, 16#83#, 16#00#, 16#0F#,
16#0E#, 16#00#, 16#1E#, 16#18#, 16#00#, 16#1C#, 16#70#, 16#00#, 16#38#,
16#C0#, 16#00#, 16#31#, 16#80#, 16#00#, 16#63#, 16#00#, 16#00#, 16#C6#,
16#00#, 16#01#, 16#8C#, 16#00#, 16#03#, 16#18#, 16#00#, 16#06#, 16#18#,
16#00#, 16#1C#, 16#30#, 16#00#, 16#38#, 16#30#, 16#00#, 16#F0#, 16#70#,
16#03#, 16#60#, 16#78#, 16#1C#, 16#C0#, 16#3F#, 16#F1#, 16#80#, 16#1F#,
16#83#, 16#00#, 16#00#, 16#06#, 16#00#, 16#00#, 16#0C#, 16#00#, 16#00#,
16#18#, 16#00#, 16#00#, 16#30#, 16#00#, 16#00#, 16#C0#, 16#00#, 16#03#,
16#80#, 16#00#, 16#0E#, 16#00#, 16#3F#, 16#F8#, 16#00#, 16#7F#, 16#C0#,
16#00#, 16#F8#, 16#00#, 16#01#, 16#F0#, 16#00#, 16#00#, 16#60#, 16#00#,
16#00#, 16#C0#, 16#00#, 16#01#, 16#80#, 16#00#, 16#03#, 16#00#, 16#00#,
16#06#, 16#00#, 16#00#, 16#0C#, 16#3F#, 16#00#, 16#18#, 16#FF#, 16#80#,
16#37#, 16#03#, 16#80#, 16#7C#, 16#03#, 16#80#, 16#F0#, 16#03#, 16#81#,
16#C0#, 16#03#, 16#03#, 16#00#, 16#06#, 16#06#, 16#00#, 16#0C#, 16#0C#,
16#00#, 16#18#, 16#18#, 16#00#, 16#30#, 16#30#, 16#00#, 16#60#, 16#60#,
16#00#, 16#C0#, 16#C0#, 16#01#, 16#81#, 16#80#, 16#03#, 16#03#, 16#00#,
16#06#, 16#06#, 16#00#, 16#0C#, 16#0C#, 16#00#, 16#18#, 16#18#, 16#00#,
16#30#, 16#30#, 16#00#, 16#63#, 16#FC#, 16#07#, 16#FF#, 16#F8#, 16#0F#,
16#F0#, 16#01#, 16#C0#, 16#00#, 16#70#, 16#00#, 16#1C#, 16#00#, 16#07#,
16#00#, 16#01#, 16#C0#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#00#, 16#00#, 16#0F#, 16#F0#, 16#03#, 16#FC#, 16#00#, 16#03#,
16#00#, 16#00#, 16#C0#, 16#00#, 16#30#, 16#00#, 16#0C#, 16#00#, 16#03#,
16#00#, 16#00#, 16#C0#, 16#00#, 16#30#, 16#00#, 16#0C#, 16#00#, 16#03#,
16#00#, 16#00#, 16#C0#, 16#00#, 16#30#, 16#00#, 16#0C#, 16#00#, 16#03#,
16#00#, 16#00#, 16#C0#, 16#00#, 16#30#, 16#00#, 16#0C#, 16#03#, 16#FF#,
16#FF#, 16#FF#, 16#FF#, 16#C0#, 16#00#, 16#70#, 16#01#, 16#C0#, 16#07#,
16#00#, 16#1C#, 16#00#, 16#70#, 16#00#, 16#00#, 16#00#, 16#00#, 16#00#,
16#00#, 16#03#, 16#FF#, 16#FF#, 16#FF#, 16#C0#, 16#03#, 16#00#, 16#0C#,
16#00#, 16#30#, 16#00#, 16#C0#, 16#03#, 16#00#, 16#0C#, 16#00#, 16#30#,
16#00#, 16#C0#, 16#03#, 16#00#, 16#0C#, 16#00#, 16#30#, 16#00#, 16#C0#,
16#03#, 16#00#, 16#0C#, 16#00#, 16#30#, 16#00#, 16#C0#, 16#03#, 16#00#,
16#0C#, 16#00#, 16#30#, 16#00#, 16#C0#, 16#03#, 16#00#, 16#0C#, 16#00#,
16#70#, 16#03#, 16#80#, 16#1C#, 16#FF#, 16#E3#, 16#FF#, 16#00#, 16#F8#,
16#00#, 16#03#, 16#E0#, 16#00#, 16#01#, 16#80#, 16#00#, 16#06#, 16#00#,
16#00#, 16#18#, 16#00#, 16#00#, 16#60#, 16#00#, 16#01#, 16#80#, 16#00#,
16#06#, 16#00#, 16#00#, 16#18#, 16#1F#, 16#E0#, 16#60#, 16#7F#, 16#81#,
16#80#, 16#60#, 16#06#, 16#07#, 16#00#, 16#18#, 16#38#, 16#00#, 16#61#,
16#C0#, 16#01#, 16#8E#, 16#00#, 16#06#, 16#60#, 16#00#, 16#1B#, 16#80#,
16#00#, 16#7F#, 16#00#, 16#01#, 16#CE#, 16#00#, 16#06#, 16#1C#, 16#00#,
16#18#, 16#38#, 16#00#, 16#60#, 16#70#, 16#01#, 16#80#, 16#E0#, 16#06#,
16#01#, 16#C0#, 16#18#, 16#03#, 16#80#, 16#60#, 16#07#, 16#0F#, 16#80#,
16#7F#, 16#FE#, 16#01#, 16#FF#, 16#3F#, 16#C0#, 16#0F#, 16#F0#, 16#00#,
16#0C#, 16#00#, 16#03#, 16#00#, 16#00#, 16#C0#, 16#00#, 16#30#, 16#00#,
16#0C#, 16#00#, 16#03#, 16#00#, 16#00#, 16#C0#, 16#00#, 16#30#, 16#00#,
16#0C#, 16#00#, 16#03#, 16#00#, 16#00#, 16#C0#, 16#00#, 16#30#, 16#00#,
16#0C#, 16#00#, 16#03#, 16#00#, 16#00#, 16#C0#, 16#00#, 16#30#, 16#00#,
16#0C#, 16#00#, 16#03#, 16#00#, 16#00#, 16#C0#, 16#00#, 16#30#, 16#00#,
16#0C#, 16#00#, 16#03#, 16#00#, 16#00#, 16#C0#, 16#00#, 16#30#, 16#0F#,
16#FF#, 16#FF#, 16#FF#, 16#FF#, 16#00#, 16#F0#, 16#3C#, 16#0F#, 16#9F#,
16#87#, 16#E0#, 16#FB#, 16#1C#, 16#C7#, 16#01#, 16#E0#, 16#D8#, 16#38#,
16#1C#, 16#07#, 16#01#, 16#81#, 16#80#, 16#60#, 16#18#, 16#18#, 16#06#,
16#01#, 16#81#, 16#80#, 16#60#, 16#18#, 16#18#, 16#06#, 16#01#, 16#81#,
16#80#, 16#60#, 16#18#, 16#18#, 16#06#, 16#01#, 16#81#, 16#80#, 16#60#,
16#18#, 16#18#, 16#06#, 16#01#, 16#81#, 16#80#, 16#60#, 16#18#, 16#18#,
16#06#, 16#01#, 16#81#, 16#80#, 16#60#, 16#18#, 16#18#, 16#06#, 16#01#,
16#81#, 16#80#, 16#60#, 16#18#, 16#18#, 16#06#, 16#01#, 16#8F#, 16#E0#,
16#7C#, 16#1F#, 16#FE#, 16#07#, 16#C1#, 16#F0#, 16#00#, 16#1F#, 16#00#,
16#F8#, 16#FF#, 16#81#, 16#F3#, 16#83#, 16#80#, 16#6C#, 16#03#, 16#80#,
16#F0#, 16#03#, 16#81#, 16#C0#, 16#03#, 16#03#, 16#00#, 16#06#, 16#06#,
16#00#, 16#0C#, 16#0C#, 16#00#, 16#18#, 16#18#, 16#00#, 16#30#, 16#30#,
16#00#, 16#60#, 16#60#, 16#00#, 16#C0#, 16#C0#, 16#01#, 16#81#, 16#80#,
16#03#, 16#03#, 16#00#, 16#06#, 16#06#, 16#00#, 16#0C#, 16#0C#, 16#00#,
16#18#, 16#18#, 16#00#, 16#30#, 16#30#, 16#00#, 16#67#, 16#FC#, 16#03#,
16#FF#, 16#F8#, 16#07#, 16#E0#, 16#00#, 16#FC#, 16#00#, 16#1F#, 16#FE#,
16#00#, 16#F0#, 16#3C#, 16#07#, 16#00#, 16#38#, 16#38#, 16#00#, 16#71#,
16#C0#, 16#00#, 16#E6#, 16#00#, 16#01#, 16#98#, 16#00#, 16#06#, 16#C0#,
16#00#, 16#0F#, 16#00#, 16#00#, 16#3C#, 16#00#, 16#00#, 16#F0#, 16#00#,
16#03#, 16#C0#, 16#00#, 16#0F#, 16#00#, 16#00#, 16#36#, 16#00#, 16#01#,
16#98#, 16#00#, 16#06#, 16#70#, 16#00#, 16#38#, 16#E0#, 16#01#, 16#C1#,
16#C0#, 16#0E#, 16#03#, 16#C0#, 16#F0#, 16#07#, 16#FF#, 16#80#, 16#03#,
16#F0#, 16#00#, 16#00#, 16#3F#, 16#01#, 16#F1#, 16#FF#, 16#83#, 16#E7#,
16#03#, 16#80#, 16#D8#, 16#01#, 16#81#, 16#E0#, 16#01#, 16#83#, 16#C0#,
16#03#, 16#87#, 16#00#, 16#03#, 16#0E#, 16#00#, 16#07#, 16#18#, 16#00#,
16#06#, 16#30#, 16#00#, 16#0C#, 16#60#, 16#00#, 16#18#, 16#C0#, 16#00#,
16#31#, 16#80#, 16#00#, 16#63#, 16#00#, 16#00#, 16#C7#, 16#00#, 16#03#,
16#0E#, 16#00#, 16#06#, 16#1E#, 16#00#, 16#18#, 16#36#, 16#00#, 16#70#,
16#67#, 16#03#, 16#C0#, 16#C7#, 16#FE#, 16#01#, 16#83#, 16#F0#, 16#03#,
16#00#, 16#00#, 16#06#, 16#00#, 16#00#, 16#0C#, 16#00#, 16#00#, 16#18#,
16#00#, 16#00#, 16#30#, 16#00#, 16#00#, 16#60#, 16#00#, 16#00#, 16#C0#,
16#00#, 16#0F#, 16#FC#, 16#00#, 16#1F#, 16#F8#, 16#00#, 16#00#, 16#01#,
16#F8#, 16#00#, 16#07#, 16#FF#, 16#1F#, 16#0F#, 16#07#, 16#9F#, 16#1C#,
16#01#, 16#D8#, 16#38#, 16#00#, 16#78#, 16#70#, 16#00#, 16#78#, 16#60#,
16#00#, 16#38#, 16#E0#, 16#00#, 16#38#, 16#C0#, 16#00#, 16#18#, 16#C0#,
16#00#, 16#18#, 16#C0#, 16#00#, 16#18#, 16#C0#, 16#00#, 16#18#, 16#C0#,
16#00#, 16#18#, 16#C0#, 16#00#, 16#18#, 16#60#, 16#00#, 16#38#, 16#70#,
16#00#, 16#78#, 16#30#, 16#00#, 16#78#, 16#1C#, 16#01#, 16#D8#, 16#0F#,
16#07#, 16#98#, 16#07#, 16#FF#, 16#18#, 16#01#, 16#FC#, 16#18#, 16#00#,
16#00#, 16#18#, 16#00#, 16#00#, 16#18#, 16#00#, 16#00#, 16#18#, 16#00#,
16#00#, 16#18#, 16#00#, 16#00#, 16#18#, 16#00#, 16#00#, 16#18#, 16#00#,
16#00#, 16#18#, 16#00#, 16#03#, 16#FF#, 16#00#, 16#03#, 16#FF#, 16#7E#,
16#03#, 16#C3#, 16#F0#, 16#7F#, 16#81#, 16#8F#, 16#0E#, 16#0C#, 16#E0#,
16#00#, 16#7E#, 16#00#, 16#03#, 16#C0#, 16#00#, 16#1C#, 16#00#, 16#00#,
16#C0#, 16#00#, 16#06#, 16#00#, 16#00#, 16#30#, 16#00#, 16#01#, 16#80#,
16#00#, 16#0C#, 16#00#, 16#00#, 16#60#, 16#00#, 16#03#, 16#00#, 16#00#,
16#18#, 16#00#, 16#00#, 16#C0#, 16#00#, 16#06#, 16#00#, 16#00#, 16#30#,
16#00#, 16#3F#, 16#FF#, 16#C1#, 16#FF#, 16#FE#, 16#00#, 16#07#, 16#F0#,
16#07#, 16#FF#, 16#63#, 16#C0#, 16#F9#, 16#C0#, 16#0E#, 16#60#, 16#01#,
16#98#, 16#00#, 16#66#, 16#00#, 16#19#, 16#C0#, 16#00#, 16#38#, 16#00#,
16#07#, 16#C0#, 16#00#, 16#7F#, 16#C0#, 16#00#, 16#7C#, 16#00#, 16#03#,
16#80#, 16#00#, 16#70#, 16#00#, 16#0F#, 16#00#, 16#03#, 16#C0#, 16#00#,
16#F8#, 16#00#, 16#7F#, 16#00#, 16#3B#, 16#F0#, 16#3C#, 16#DF#, 16#FE#,
16#00#, 16#FE#, 16#00#, 16#0C#, 16#00#, 16#00#, 16#60#, 16#00#, 16#03#,
16#00#, 16#00#, 16#18#, 16#00#, 16#00#, 16#C0#, 16#00#, 16#06#, 16#00#,
16#03#, 16#FF#, 16#FE#, 16#1F#, 16#FF#, 16#F0#, 16#0C#, 16#00#, 16#00#,
16#60#, 16#00#, 16#03#, 16#00#, 16#00#, 16#18#, 16#00#, 16#00#, 16#C0#,
16#00#, 16#06#, 16#00#, 16#00#, 16#30#, 16#00#, 16#01#, 16#80#, 16#00#,
16#0C#, 16#00#, 16#00#, 16#60#, 16#00#, 16#03#, 16#00#, 16#00#, 16#18#,
16#00#, 16#00#, 16#C0#, 16#00#, 16#06#, 16#00#, 16#00#, 16#30#, 16#00#,
16#00#, 16#C0#, 16#07#, 16#07#, 16#01#, 16#F0#, 16#1F#, 16#FF#, 16#00#,
16#3F#, 16#80#, 16#F8#, 16#03#, 16#F1#, 16#F0#, 16#07#, 16#E0#, 16#60#,
16#00#, 16#C0#, 16#C0#, 16#01#, 16#81#, 16#80#, 16#03#, 16#03#, 16#00#,
16#06#, 16#06#, 16#00#, 16#0C#, 16#0C#, 16#00#, 16#18#, 16#18#, 16#00#,
16#30#, 16#30#, 16#00#, 16#60#, 16#60#, 16#00#, 16#C0#, 16#C0#, 16#01#,
16#81#, 16#80#, 16#03#, 16#03#, 16#00#, 16#06#, 16#06#, 16#00#, 16#0C#,
16#0C#, 16#00#, 16#38#, 16#18#, 16#00#, 16#F0#, 16#18#, 16#03#, 16#60#,
16#38#, 16#3C#, 16#F8#, 16#3F#, 16#F1#, 16#F0#, 16#1F#, 16#00#, 16#00#,
16#7F#, 16#C0#, 16#FF#, 16#DF#, 16#F0#, 16#3F#, 16#F0#, 16#C0#, 16#00#,
16#40#, 16#30#, 16#00#, 16#30#, 16#06#, 16#00#, 16#08#, 16#01#, 16#80#,
16#06#, 16#00#, 16#30#, 16#01#, 16#80#, 16#0C#, 16#00#, 16#C0#, 16#03#,
16#80#, 16#30#, 16#00#, 16#60#, 16#18#, 16#00#, 16#18#, 16#06#, 16#00#,
16#03#, 16#01#, 16#00#, 16#00#, 16#C0#, 16#C0#, 16#00#, 16#18#, 16#20#,
16#00#, 16#06#, 16#18#, 16#00#, 16#00#, 16#C6#, 16#00#, 16#00#, 16#33#,
16#00#, 16#00#, 16#0E#, 16#C0#, 16#00#, 16#01#, 16#E0#, 16#00#, 16#00#,
16#78#, 16#00#, 16#7F#, 16#00#, 16#3F#, 16#DF#, 16#C0#, 16#0F#, 16#F1#,
16#80#, 16#00#, 16#20#, 16#60#, 16#00#, 16#18#, 16#18#, 16#00#, 16#06#,
16#06#, 16#03#, 16#01#, 16#80#, 16#81#, 16#E0#, 16#60#, 16#30#, 16#78#,
16#10#, 16#0C#, 16#1E#, 16#0C#, 16#03#, 16#0C#, 16#C3#, 16#00#, 16#C3#,
16#30#, 16#C0#, 16#10#, 16#CE#, 16#30#, 16#06#, 16#61#, 16#98#, 16#01#,
16#98#, 16#66#, 16#00#, 16#66#, 16#1D#, 16#80#, 16#0B#, 16#03#, 16#60#,
16#03#, 16#C0#, 16#D0#, 16#00#, 16#F0#, 16#1C#, 16#00#, 16#38#, 16#07#,
16#00#, 16#0E#, 16#01#, 16#C0#, 16#3F#, 16#81#, 16#FE#, 16#3F#, 16#81#,
16#FE#, 16#0C#, 16#00#, 16#38#, 16#06#, 16#00#, 16#70#, 16#03#, 16#00#,
16#E0#, 16#01#, 16#81#, 16#C0#, 16#00#, 16#C3#, 16#80#, 16#00#, 16#67#,
16#00#, 16#00#, 16#3C#, 16#00#, 16#00#, 16#18#, 16#00#, 16#00#, 16#3C#,
16#00#, 16#00#, 16#67#, 16#00#, 16#00#, 16#C3#, 16#80#, 16#01#, 16#81#,
16#C0#, 16#03#, 16#00#, 16#E0#, 16#06#, 16#00#, 16#70#, 16#0C#, 16#00#,
16#38#, 16#18#, 16#00#, 16#1C#, 16#7F#, 16#81#, 16#FF#, 16#7F#, 16#81#,
16#FF#, 16#7F#, 16#00#, 16#FF#, 16#7F#, 16#00#, 16#FF#, 16#18#, 16#00#,
16#0C#, 16#18#, 16#00#, 16#18#, 16#0C#, 16#00#, 16#18#, 16#0C#, 16#00#,
16#30#, 16#06#, 16#00#, 16#30#, 16#06#, 16#00#, 16#60#, 16#03#, 16#00#,
16#60#, 16#03#, 16#00#, 16#C0#, 16#01#, 16#80#, 16#C0#, 16#01#, 16#81#,
16#80#, 16#00#, 16#C1#, 16#80#, 16#00#, 16#C3#, 16#00#, 16#00#, 16#63#,
16#00#, 16#00#, 16#66#, 16#00#, 16#00#, 16#36#, 16#00#, 16#00#, 16#34#,
16#00#, 16#00#, 16#3C#, 16#00#, 16#00#, 16#18#, 16#00#, 16#00#, 16#18#,
16#00#, 16#00#, 16#10#, 16#00#, 16#00#, 16#30#, 16#00#, 16#00#, 16#20#,
16#00#, 16#00#, 16#60#, 16#00#, 16#00#, 16#40#, 16#00#, 16#00#, 16#C0#,
16#00#, 16#7F#, 16#FC#, 16#00#, 16#7F#, 16#FC#, 16#00#, 16#FF#, 16#FF#,
16#7F#, 16#FF#, 16#B0#, 16#01#, 16#98#, 16#01#, 16#CC#, 16#01#, 16#C0#,
16#00#, 16#C0#, 16#00#, 16#C0#, 16#00#, 16#C0#, 16#00#, 16#C0#, 16#00#,
16#C0#, 16#00#, 16#E0#, 16#00#, 16#60#, 16#00#, 16#60#, 16#00#, 16#60#,
16#00#, 16#60#, 16#00#, 16#60#, 16#03#, 16#70#, 16#01#, 16#B0#, 16#00#,
16#FF#, 16#FF#, 16#FF#, 16#FF#, 16#F0#, 16#00#, 16#E0#, 16#7C#, 16#0C#,
16#03#, 16#00#, 16#60#, 16#0C#, 16#01#, 16#80#, 16#30#, 16#06#, 16#00#,
16#C0#, 16#18#, 16#03#, 16#00#, 16#60#, 16#0C#, 16#03#, 16#00#, 16#E0#,
16#F0#, 16#1E#, 16#00#, 16#70#, 16#06#, 16#00#, 16#60#, 16#0C#, 16#01#,
16#80#, 16#30#, 16#06#, 16#00#, 16#C0#, 16#18#, 16#03#, 16#00#, 16#60#,
16#0C#, 16#01#, 16#80#, 16#18#, 16#03#, 16#E0#, 16#1C#, 16#FF#, 16#FF#,
16#FF#, 16#FF#, 16#FF#, 16#FF#, 16#FF#, 16#FF#, 16#F0#, 16#E0#, 16#1F#,
16#00#, 16#60#, 16#06#, 16#00#, 16#C0#, 16#18#, 16#03#, 16#00#, 16#60#,
16#0C#, 16#01#, 16#80#, 16#30#, 16#06#, 16#00#, 16#C0#, 16#18#, 16#01#,
16#80#, 16#38#, 16#01#, 16#E0#, 16#3C#, 16#1C#, 16#03#, 16#00#, 16#C0#,
16#18#, 16#03#, 16#00#, 16#60#, 16#0C#, 16#01#, 16#80#, 16#30#, 16#06#,
16#00#, 16#C0#, 16#18#, 16#03#, 16#00#, 16#C0#, 16#F8#, 16#1C#, 16#00#,
16#0F#, 16#00#, 16#03#, 16#FC#, 16#03#, 16#70#, 16#E0#, 16#76#, 16#07#,
16#8E#, 16#C0#, 16#1F#, 16#C0#, 16#00#, 16#F0#);
FreeMono24pt7bGlyphs : aliased constant Glyph_Array := (
(0, 0, 0, 28, 0, 1), -- 0x20 ' '
(0, 5, 30, 28, 11, -28), -- 0x21 '!'
(19, 16, 14, 28, 6, -28), -- 0x22 '"'
(47, 19, 32, 28, 4, -29), -- 0x23 '#'
(123, 18, 33, 28, 5, -29), -- 0x24 '$'
(198, 20, 29, 28, 4, -27), -- 0x25 '%'
(271, 18, 25, 28, 5, -23), -- 0x26 '&'
(328, 7, 14, 28, 11, -28), -- 0x27 '''
(341, 7, 34, 28, 14, -27), -- 0x28 '('
(371, 7, 34, 28, 8, -27), -- 0x29 ')'
(401, 18, 16, 28, 5, -27), -- 0x2A '*'
(437, 20, 22, 28, 4, -23), -- 0x2B '+'
(492, 9, 14, 28, 6, -6), -- 0x2C ','
(508, 22, 2, 28, 3, -13), -- 0x2D '-'
(514, 7, 6, 28, 11, -4), -- 0x2E '.'
(520, 18, 35, 28, 5, -30), -- 0x2F '/'
(599, 18, 30, 28, 5, -28), -- 0x30 '0'
(667, 16, 29, 28, 6, -28), -- 0x31 '1'
(725, 18, 29, 28, 5, -28), -- 0x32 '2'
(791, 19, 30, 28, 5, -28), -- 0x33 '3'
(863, 16, 28, 28, 6, -27), -- 0x34 '4'
(919, 19, 29, 28, 5, -27), -- 0x35 '5'
(988, 18, 30, 28, 6, -28), -- 0x36 '6'
(1056, 18, 28, 28, 5, -27), -- 0x37 '7'
(1119, 18, 30, 28, 5, -28), -- 0x38 '8'
(1187, 18, 30, 28, 6, -28), -- 0x39 '9'
(1255, 7, 21, 28, 11, -19), -- 0x3A ':'
(1274, 10, 27, 28, 7, -19), -- 0x3B ';'
(1308, 22, 22, 28, 3, -23), -- 0x3C '<'
(1369, 24, 9, 28, 2, -17), -- 0x3D '='
(1396, 21, 22, 28, 4, -23), -- 0x3E '>'
(1454, 17, 28, 28, 6, -26), -- 0x3F '?'
(1514, 18, 32, 28, 5, -28), -- 0x40 '@'
(1586, 28, 26, 28, 0, -25), -- 0x41 'A'
(1677, 22, 26, 28, 3, -25), -- 0x42 'B'
(1749, 22, 28, 28, 3, -26), -- 0x43 'C'
(1826, 22, 26, 28, 3, -25), -- 0x44 'D'
(1898, 22, 26, 28, 3, -25), -- 0x45 'E'
(1970, 22, 26, 28, 3, -25), -- 0x46 'F'
(2042, 23, 28, 28, 3, -26), -- 0x47 'G'
(2123, 23, 26, 28, 3, -25), -- 0x48 'H'
(2198, 16, 26, 28, 6, -25), -- 0x49 'I'
(2250, 23, 27, 28, 4, -25), -- 0x4A 'J'
(2328, 24, 26, 28, 3, -25), -- 0x4B 'K'
(2406, 21, 26, 28, 4, -25), -- 0x4C 'L'
(2475, 26, 26, 28, 1, -25), -- 0x4D 'M'
(2560, 24, 26, 28, 2, -25), -- 0x4E 'N'
(2638, 24, 28, 28, 2, -26), -- 0x4F 'O'
(2722, 21, 26, 28, 3, -25), -- 0x50 'P'
(2791, 24, 32, 28, 2, -26), -- 0x51 'Q'
(2887, 24, 26, 28, 3, -25), -- 0x52 'R'
(2965, 20, 28, 28, 4, -26), -- 0x53 'S'
(3035, 22, 26, 28, 3, -25), -- 0x54 'T'
(3107, 23, 27, 28, 3, -25), -- 0x55 'U'
(3185, 28, 26, 28, 0, -25), -- 0x56 'V'
(3276, 26, 26, 28, 1, -25), -- 0x57 'W'
(3361, 24, 26, 28, 2, -25), -- 0x58 'X'
(3439, 24, 26, 28, 2, -25), -- 0x59 'Y'
(3517, 18, 26, 28, 5, -25), -- 0x5A 'Z'
(3576, 7, 34, 28, 13, -27), -- 0x5B '['
(3606, 18, 35, 28, 5, -30), -- 0x5C '\'
(3685, 7, 34, 28, 8, -27), -- 0x5D ']'
(3715, 18, 12, 28, 5, -28), -- 0x5E '^'
(3742, 28, 2, 28, 0, 5), -- 0x5F '_'
(3749, 8, 7, 28, 7, -29), -- 0x60 '`'
(3756, 22, 22, 28, 3, -20), -- 0x61 'a'
(3817, 23, 29, 28, 2, -27), -- 0x62 'b'
(3901, 21, 22, 28, 4, -20), -- 0x63 'c'
(3959, 24, 29, 28, 3, -27), -- 0x64 'd'
(4046, 21, 22, 28, 3, -20), -- 0x65 'e'
(4104, 19, 28, 28, 6, -27), -- 0x66 'f'
(4171, 23, 30, 28, 3, -20), -- 0x67 'g'
(4258, 23, 28, 28, 3, -27), -- 0x68 'h'
(4339, 18, 29, 28, 5, -28), -- 0x69 'i'
(4405, 14, 38, 28, 6, -28), -- 0x6A 'j'
(4472, 22, 28, 28, 4, -27), -- 0x6B 'k'
(4549, 18, 28, 28, 5, -27), -- 0x6C 'l'
(4612, 28, 21, 28, 0, -20), -- 0x6D 'm'
(4686, 23, 21, 28, 2, -20), -- 0x6E 'n'
(4747, 22, 22, 28, 3, -20), -- 0x6F 'o'
(4808, 23, 30, 28, 2, -20), -- 0x70 'p'
(4895, 24, 30, 28, 3, -20), -- 0x71 'q'
(4985, 21, 20, 28, 5, -19), -- 0x72 'r'
(5038, 18, 22, 28, 5, -20), -- 0x73 's'
(5088, 21, 27, 28, 3, -25), -- 0x74 't'
(5159, 23, 21, 28, 3, -19), -- 0x75 'u'
(5220, 26, 20, 28, 1, -19), -- 0x76 'v'
(5285, 26, 20, 28, 1, -19), -- 0x77 'w'
(5350, 24, 20, 28, 2, -19), -- 0x78 'x'
(5410, 24, 29, 28, 2, -19), -- 0x79 'y'
(5497, 17, 20, 28, 6, -19), -- 0x7A 'z'
(5540, 11, 34, 28, 8, -27), -- 0x7B '{'
(5587, 2, 34, 28, 13, -27), -- 0x7C '|'
(5596, 11, 34, 28, 9, -27), -- 0x7D '}'
(5643, 20, 6, 28, 4, -15)); -- 0x7E '~'
Font_D : aliased constant Bitmap_Font :=
(FreeMono24pt7bBitmaps'Access,
FreeMono24pt7bGlyphs'Access,
47);
Font : constant Giza.Font.Ref_Const := Font_D'Access;
end Giza.Bitmap_Fonts.FreeMono24pt7b;
|
--
-- Short demo of the bug inducing code: tagged hierarchy as a field of discriminated record
--
-- This program 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.
--
with Ada.Command_Line, GNAT.Command_Line;
with Ada.Text_IO, Ada.Integer_Text_IO;
use Ada.Text_IO;
with Ada.Containers.Vectors;
with lists.Fixed;
with lists.Dynamic;
procedure bug_03 is
type Element_Type is new Integer;
package ACV is new Ada.Containers.Vectors(Positive, Element_Type);
package PL is new Lists(Natural, Element_Type);
package PLF is new PL.Fixed;
package PLD is new PL.Dynamic;
begin
Put_Line("Ada.Containers.Vectors..");
declare
v : ACV.Vector := ACV.To_Vector(5);
type VRec is record
f : ACV.Vector;
end record;
vr : VRec := (f => ACV.To_Vector(5));
begin
v(1) := 1;
vr.f(1) := 1;
end;
--
Put_Line("Lists.Dynamic..");
declare
ld : PLD.List := PLD.To_Vector(5);
type DRec is record
f : PLD.List;
end record;
ldr : DRec := (f => PLD.To_Vector(5));
--
type DDRec (N : Positive) is record
f : PLD.List := PLD.To_Vector(N);
end record;
lddr : DDRec(5);
begin
ld(1) := 1;
ldr.f(1) := 1;
lddr.f(1) := 1;
end;
--
Put_Line("Lists.Fixed (discriminated record)");
declare
type FRec5 is record
f : PLF.List(5);
end record;
--
type FRec (N : Positive) is record
f : PLF.List(N);
end record;
--
lf : PLF.List(5);
lfr5 : FRec5;
lfr : FRec(5);
begin
lf(1) := 1;
lfr5.f(1) := 1; -- this is still fine
lfr.f(1) := 1; -- this triggers the bug
end;
end bug_03;
|
------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Localization, Internationalization, Globalization for Ada --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2010, 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. --
-- --
------------------------------------------------------------------------------
-- UTF-8 decoding algoriphm is based on work: --
------------------------------------------------------------------------------
-- --
-- Copyright (c) 2008-2009 Bjoern Hoehrmann <bjoern@hoehrmann.de> --
-- --
-- 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. --
-- --
------------------------------------------------------------------------------
-- $Revision$ $Date$
------------------------------------------------------------------------------
with Ada.Streams.Stream_IO;
with Interfaces;
with League.Strings.Internals;
with Matreshka.Internals.Strings.Operations;
with Matreshka.Internals.Text_Codecs;
with Matreshka.Internals.Unicode;
function Read_File (Name : String) return League.Strings.Universal_String is
use Interfaces;
use type Matreshka.Internals.Unicode.Code_Point;
Buffer : Ada.Streams.Stream_Element_Array (1 .. 1024);
Last : Ada.Streams.Stream_Element_Offset;
File : Ada.Streams.Stream_IO.File_Type;
Data : Matreshka.Internals.Strings.Shared_String_Access
:= Matreshka.Internals.Strings.Shared_Empty'Access;
Factory : Matreshka.Internals.Text_Codecs.Decoder_Factory
:= Matreshka.Internals.Text_Codecs.Decoder
(Matreshka.Internals.Text_Codecs.MIB_UTF8);
Decoder : Matreshka.Internals.Text_Codecs.Abstract_Decoder'Class
:= Factory (Matreshka.Internals.Text_Codecs.Raw);
begin
Ada.Streams.Stream_IO.Open (File, Ada.Streams.Stream_IO.In_File, Name);
while not Ada.Streams.Stream_IO.End_Of_File (File) loop
Ada.Streams.Stream_IO.Read (File, Buffer, Last);
Decoder.Decode_Append (Buffer (Buffer'First .. Last), Data);
end loop;
Ada.Streams.Stream_IO.Close (File);
if Decoder.Is_Error then
Matreshka.Internals.Strings.Dereference (Data);
raise Constraint_Error with "mailformed UTF-8 file";
end if;
return League.Strings.Internals.Wrap (Data);
end Read_File;
|
with Ada.Text_IO, Ada.Containers.Indefinite_Doubly_Linked_Lists; use Ada.Text_IO;
procedure Swallow_Fly is
package Strings is new Ada.Containers.Indefinite_Doubly_Linked_Lists(String);
Lines, Animals: Strings.List;
procedure Swallow(Animal: String;
Second_Line: String;
Permanent_Second_Line: Boolean := True) is
procedure Print(C: Strings.Cursor) is
begin
Put_Line(Strings.Element(C));
end Print;
begin
Put_Line("There was an old lady who swallowed a " & Animal & ",");
Put_Line(Second_Line);
if not Animals.Is_Empty then
Lines.Prepend("She swallowed the " & Animal & " to catch the " &
Animals.Last_Element & ",");
end if;
Lines.Iterate(Print'Access);
New_Line;
if Permanent_Second_Line then
Lines.Prepend(Second_Line);
end if;
Animals.Append(Animal); -- you need "to catch the " most recent animal
end Swallow;
procedure Swallow_TSA(Animal: String; Part_Of_Line_2: String) is
begin
Swallow(Animal, Part_Of_Line_2 &", to swallow a " & Animal & ";", False);
end Swallow_TSA;
procedure Swallow_SSA(Animal: String; Part_Of_Line_2: String) is
begin
Swallow(Animal, Part_Of_Line_2 &" she swallowed a " & Animal & ";", False);
end Swallow_SSA;
begin
Lines.Append("Perhaps she'll die!");
Swallow("fly", "But I don't know why she swallowed the fly,");
Swallow("spider", "That wriggled and jiggled and tickled inside her;");
Swallow_TSA("bird", "Quite absurd");
Swallow_TSA("cat", "Fancy that");
Swallow_TSA("dog", "What a hog");
Swallow_TSA("pig", "Her mouth was so big");
Swallow_TSA("goat","She just opened her throat");
Swallow_SSA("cow", "I don't know how");
Swallow_TSA("donkey", "It was rather wonky");
Put_Line("There was an old lady who swallowed a horse ...");
Put_Line("She's dead, of course!");
end Swallow_Fly;
|
------------------------------------------------------------
--
-- GNAT RUN-TIME EXTENSIONS
--
-- XADA . DISPATCHING . TIME-TRIGGERED SCHEDULING
--
-- @file x-distts.adb / xada-dispatching-tts.adb
--
-- @package XAda.Dispatching.TTS (BODY)
--
-- @author Jorge Real <jorge@disca.upv.es>
-- @author Sergio Saez <ssaez@disca.upv.es>
--
------------------------------------------------------------
with Ada.Task_Identification; use Ada.Task_Identification;
with Ada.Synchronous_Task_Control; use Ada.Synchronous_Task_Control;
with Ada.Real_Time; use Ada.Real_Time;
with Ada.Real_Time.Timing_Events; use Ada.Real_Time.Timing_Events;
with Ada.Text_IO; use Ada.Text_IO;
with System.BB.Threads; use System.BB.Threads;
with System.TTS_Support; use System.TTS_Support;
package body XAda.Dispatching.TTS is
-- Conservative bound of measured overhead on a STM32F4 Discovery
-- Since release jitter is very predictable in this platform (between
-- 23 and 24 us) we charge that overhead at the end of the slot, by
-- effectively advancing the slot start time by the Overhead time.
-- This reduces the release jitter even further for TT tasks, to about 3 us
Overhead : constant Time_Span := Microseconds (0);
-- Run time TT work info
type Work_Control_Block is record
Has_Completed : Boolean := True; -- TT part has completed
Is_Waiting : Boolean := False; -- Task is waiting for release
Is_Sliced : Boolean := False; -- Task is in a sliced sequence
Work_Thread_Id : Thread_Id := Null_Thread_Id; -- Underlying thread id
Last_Release : Time := Time_Last; -- Time of last release
end record;
-- Array of Work_Control_Blocks
WCB : array (TT_Work_Id) of aliased Work_Control_Block;
-- Array of suspension objects for TT tasks to wait for activation
Release_Point : array (TT_Work_Id) of Suspension_Object;
-- Run time TT sync info
type Sync_Control_Block is record
Sync_Thread_Id : Thread_Id := Null_Thread_Id; -- Underlying thread id
Last_Release : Time := Time_Last; -- Time of last release
end record;
-- Array of Work_Control_Blocks
SCB : array (TT_Sync_Id) of aliased Sync_Control_Block;
-- Array of suspension objects for ET tasks to wait for synchronization
Sync_Point : array (TT_Sync_Id) of Suspension_Object;
----------------
-- Set_Plan --
----------------
procedure Set_Plan (TTP : Time_Triggered_Plan_Access) is
begin
Time_Triggered_Scheduler.Set_Plan (TTP);
end Set_Plan;
--------------------------
-- Wait_For_Activation --
--------------------------
procedure Wait_For_Activation
(Work_Id : TT_Work_Id;
When_Was_Released : out Time) is
begin
-- Raise own priority, before getting blocked. This is to recover the TT
-- priority when the calling task has previuosly called Leave_TT_Level
Set_Priority (TT_Priority);
-- Inform the TT scheduler the task is going to wait for activation
Time_Triggered_Scheduler.Prepare_For_Activation (Work_Id);
-- Suspend until the next slot for Work_Id starts
Suspend_Until_True (Release_Point (Work_Id));
-- Scheduler updated Last_Release when it released the worker task
When_Was_Released := WCB (Work_Id).Last_Release;
end Wait_For_Activation;
---------------------
-- Continue_Sliced --
---------------------
procedure Continue_Sliced is
begin
Time_Triggered_Scheduler.Continue_Sliced;
end Continue_Sliced;
--------------------
-- Leave_TT_Level --
--------------------
procedure Leave_TT_Level is
begin
Time_Triggered_Scheduler.Leave_TT_Level;
end Leave_TT_Level;
----------------------------
-- Get_First_Plan_Release --
----------------------------
function Get_First_Plan_Release return Ada.Real_Time.Time is
begin
return Time_Triggered_Scheduler.Get_First_Plan_Release;
end Get_First_Plan_Release;
---------------------------
-- Get_Last_Plan_Release --
---------------------------
function Get_Last_Plan_Release return Ada.Real_Time.Time is
begin
return Time_Triggered_Scheduler.Get_Last_Plan_Release;
end Get_Last_Plan_Release;
--------------------
-- Wait_For_Sync --
--------------------
procedure Wait_For_Sync
(Sync_Id : TT_Sync_Id;
When_Was_Released : out Time) is
begin
-- Inform the TT scheduler the ET task has reached the sync point
Time_Triggered_Scheduler.Prepare_For_Sync (Sync_Id);
-- Suspend until the next sync slot for Sync_Id starts
-- If the sync point has been already reached in the plan,
-- the SO is open and the ET task will not suspend
Suspend_Until_True (Sync_Point (Sync_Id));
-- Scheduler updated Last_Release when it released the sync'ed task
When_Was_Released := SCB (Sync_Id).Last_Release;
end Wait_For_Sync;
------------------------------
-- Time_Triggered_Scheduler --
------------------------------
protected body Time_Triggered_Scheduler is
--------------
-- Set_Plan --
--------------
procedure Set_Plan (TTP : Time_Triggered_Plan_Access) is
Now : constant Time := Clock;
begin
-- Take note of next plan to execute
Next_Plan := TTP;
-- Start new plan now if none is set. Otherwise, the scheduler will
-- change to the Next_Plan at the end of the next mode change slot
if Current_Plan = null then
-- The extra 'overhead' delay is to bypass the exception we get
-- if we don't add it. We still have to debug this. Note that the
-- delay only affects the first mode change, because Current_Plan
-- is null.
Change_Plan (Now + Milliseconds(1));
elsif Current_Plan (Current_Slot_Index).all in Mode_Change_Slot'Class then
-- Accept Set_Plan requests during a mode change slot (coming
-- from PB tasks) and enforce the mode change at the end of it.
Change_Plan (Next_Slot_Release);
end if;
end Set_Plan;
----------------------------
-- Prepare_For_Activation --
----------------------------
procedure Prepare_For_Activation (Work_Id : TT_Work_Id) is
Current_Slot : Time_Slot_Access;
Current_Work_Slot : Work_Slot_Access;
Cancelled : Boolean;
begin
-- Register the Work_Id with the first task using it.
-- Use of the Work_Id by another task breaks the model and causes PE
if WCB (Work_Id).Work_Thread_Id = Null_Thread_Id then
-- First time WFA called with this Work_Id -> Register caller
-- WCB (Work_Id).Work_Task_Id := Current_Task;
WCB (Work_Id).Work_Thread_Id := Thread_Self;
elsif WCB (Work_Id).Work_Thread_Id /= Thread_Self then
-- Caller was not registered with this Work_Id
raise Program_Error with ("Work_Id misuse");
end if;
if Current_Plan /= null then
Current_Slot := Current_Plan (Current_Slot_Index);
if Current_Slot.all in Work_Slot'Class then
Current_Work_Slot := Work_Slot_Access(Current_Slot);
-- If the invoking thread is the owner of the current Work Slot
-- then the slot is considered completed.
if WCB (Current_Work_Slot.Work_Id).Work_Thread_Id = Thread_Self then
WCB (Current_Work_Slot.Work_Id).Has_Completed := True;
end if;
end if;
end if;
-- Work has been completed and the caller is about to be suspended
WCB (Work_Id).Is_Waiting := True;
Hold_Event.Cancel_Handler(Cancelled);
-- The task has to execute Suspend_Until_True after this point
end Prepare_For_Activation;
---------------------
-- Continue_Sliced --
---------------------
procedure Continue_Sliced is
Current_Slot : constant Time_Slot_Access :=
Current_Plan (Current_Slot_Index);
Current_Work_Slot : Work_Slot_Access;
begin
if Current_Slot.all not in Work_Slot'Class then
raise Program_Error
with ("Continue_Sliced called from a non-TT task");
end if;
Current_Work_Slot := Work_Slot_Access(Current_Slot);
if WCB (Current_Work_Slot.Work_Id).Work_Thread_Id /= Thread_Self then
raise Program_Error
with ("Running Task does not correspond to Work_Id " &
Current_Work_Slot.Work_Id'Image);
end if;
WCB (Current_Work_Slot.Work_Id).Is_Sliced := True;
if Current_Work_Slot.Padding > Time_Span_Zero then
Hold_Event.Set_Handler (Next_Slot_Release - Current_Work_Slot.Padding,
Hold_Handler_Access);
end if;
end Continue_Sliced;
--------------------
-- Leave_TT_Level --
--------------------
procedure Leave_TT_Level is -- (Work_Id : Regular_Work_Id) is
Current_Slot : constant Time_Slot_Access :=
Current_Plan (Current_Slot_Index);
Current_Work_Slot : Work_Slot_Access;
Base_Priority : System.Priority;
Cancelled : Boolean;
begin
if Current_Slot.all not in Work_Slot'Class then
raise Program_Error
with ("Leave_TT_Level called from a non-TT task");
end if;
Current_Work_Slot := Work_Slot_Access(Current_Slot);
if WCB (Current_Work_Slot.Work_Id).Work_Thread_Id /= Thread_Self then
raise Program_Error
with ("Leave_TT_Level called from Work_Id different to " &
Current_Work_Slot.Work_Id'Image);
end if;
WCB (Current_Work_Slot.Work_Id).Has_Completed := True;
Hold_Event.Cancel_Handler(Cancelled);
Base_Priority :=
WCB (Current_Work_Slot.Work_Id).Work_Thread_Id.Base_Priority;
Set_Priority (Base_Priority);
end Leave_TT_Level;
-----------------
-- Change_Plan --
-----------------
procedure Change_Plan (At_Time : Time) is
begin
Current_Plan := Next_Plan;
Next_Plan := null;
-- Setting both Current_ and Next_Slot_Index to 'First is consistent
-- with the new slot TE handler for the first slot of a new plan.
Current_Slot_Index := Current_Plan.all'First;
Next_Slot_Index := Current_Plan.all'First;
Next_Slot_Release := At_Time;
Plan_Start_Pending := True;
NS_Event.Set_Handler (At_Time - Overhead, NS_Handler_Access);
end Change_Plan;
----------------------------
-- Get_Last_First_Release --
----------------------------
function Get_First_Plan_Release return Ada.Real_Time.Time is
begin
return First_Plan_Release;
end Get_First_Plan_Release;
---------------------------
-- Get_Last_Plan_Release --
---------------------------
function Get_Last_Plan_Release return Ada.Real_Time.Time is
begin
return First_Slot_Release;
end Get_Last_Plan_Release;
----------------------
-- Prepare_For_Sync --
----------------------
procedure Prepare_For_Sync (Sync_Id : TT_Sync_Id) is
Current_Slot : Time_Slot_Access;
Current_Work_Slot : Work_Slot_Access;
begin
-- Register the Sync_Id with the first task using it.
-- Use of the Sync_Id by another task breaks the model and causes PE
if SCB (Sync_Id).Sync_Thread_Id = Null_Thread_Id then
-- First time WFS called with this Sync_Id -> Register caller
-- SCB (Sync_Id).Work_Task_Id := Current_Task;
SCB (Sync_Id).Sync_Thread_Id := Thread_Self;
elsif SCB (Sync_Id).Sync_Thread_Id /= Thread_Self then
-- Caller was not registered with this Sync_Id
raise Program_Error with ("Sync_Id misuse");
end if;
if Current_Plan /= null then
Current_Slot := Current_Plan (Current_Slot_Index);
if Current_Slot.all in Work_Slot'Class then
Current_Work_Slot := Work_Slot_Access(Current_Slot);
-- If the invoking thread is the owner of the current Work Slot
-- then the slot is considered completed.
if WCB (Current_Work_Slot.Work_Id).Work_Thread_Id = Thread_Self then
WCB (Current_Work_Slot.Work_Id).Has_Completed := True;
end if;
end if;
end if;
-- The task has to execute Suspend_Until_True after this point
end Prepare_For_Sync;
------------------
-- Hold_Handler --
------------------
procedure Hold_Handler (Event : in out Timing_Event) is
pragma Unreferenced (Event);
Current_Slot : constant Time_Slot_Access :=
Current_Plan (Current_Slot_Index);
Current_Work_Slot : Work_Slot_Access;
Current_WCB : Work_Control_Block;
Current_Thread_Id : Thread_Id;
begin
if Current_Slot.all not in Work_Slot'Class then
raise Program_Error
with ("Hold handler called for a non-TT task");
end if;
Current_Work_Slot := Work_Slot_Access(Current_Slot);
Current_WCB := WCB (Current_Work_Slot.Work_Id);
Current_Thread_Id := Current_WCB.Work_Thread_Id;
if not Current_WCB.Has_Completed then
Hold (Current_Thread_Id);
end if;
end Hold_Handler;
----------------
-- NS_Handler --
----------------
procedure NS_Handler (Event : in out Timing_Event) is
pragma Unreferenced (Event);
Current_Slot : Time_Slot_Access;
Current_Work_Slot : Work_Slot_Access;
Current_WCB : Work_Control_Block;
Current_Sync_Slot : Sync_Slot_Access;
Current_Thread_Id : Thread_Id;
Now : Time;
begin
-- This is the current time, according to the plan
Now := Next_Slot_Release;
--------------------------
-- PROCESS ENDING SLOT --
--------------------------
-- Check for overrun in the ending slot, if it is a TT_Work_Slot.
-- If this happens to be the first slot after a plan change, then
-- we come from a mode-change slot, so there is no overrun to check,
-- because it was checked before that mode-change slot
Current_Slot := Current_Plan (Current_Slot_Index);
-- Nothing to be done unless the ending slot was a TT_Work_Slot
if Current_Slot.all in Work_Slot'Class then
Current_Work_Slot := Work_Slot_Access(Current_Slot);
Current_WCB := WCB (Current_Work_Slot.Work_Id);
if not Current_WCB.Has_Completed then
-- Possible overrun detected, unless task is running sliced.
-- First check that all is going well
Current_Thread_Id := Current_WCB.Work_Thread_Id;
-- Check whether the task is running sliced or this is
-- a real overrun situation
if Current_WCB.Is_Sliced then
if Current_Work_Slot.Padding > Time_Span_Zero then
if Current_Thread_Id.Hold_Signaled then
raise Program_Error
with ("Overrun in PA of Sliced TT task " &
Current_Work_Slot.Work_Id'Image);
end if;
else
-- Thread_Self is the currently running thread on this CPU.
-- If this assertion fails, the running TT task is using a
-- wrong slot, which should never happen
pragma Assert (Current_Thread_Id = Thread_Self);
Hold (Current_Thread_Id, True);
end if;
-- Context switch occurs after executing this handler
else
-- Overrun detected, raise Program_Error
raise Program_Error
with ("Overrun in TT task " &
Current_Work_Slot.Work_Id'Image);
end if;
end if;
end if;
---------------------------
-- PROCESS STARTING SLOT --
---------------------------
-- Update current slot index
Current_Slot_Index := Next_Slot_Index;
if Current_Slot_Index = Current_Plan.all'First then
First_Slot_Release := Now;
if Plan_Start_Pending then
First_Plan_Release := Now;
Plan_Start_Pending := False;
end if;
end if;
-- Obtain next slot index. The plan is repeated circularly
if Next_Slot_Index < Current_Plan.all'Last then
Next_Slot_Index := Next_Slot_Index + 1;
else
Next_Slot_Index := Current_Plan.all'First;
end if;
-- Obtain current slot
Current_Slot := Current_Plan (Current_Slot_Index);
-- Compute next slot start time
Next_Slot_Release := Now + Current_Slot.Slot_Duration;
if Current_Slot.all in Mode_Change_Slot'Class then
----------------------------------
-- Process a Mode_Change_Slot --
----------------------------------
if Next_Plan /= null then
-- There's a pending plan change.
-- It takes effect at the end of the MC slot
Change_Plan (Next_Slot_Release);
else
-- Set the handler for the next scheduling point
NS_Event.Set_Handler (Next_Slot_Release - Overhead,
NS_Handler_Access);
end if;
elsif Current_Slot.all in Empty_Slot'Class then
-----------------------------
-- Process an Empty_Slot --
-----------------------------
-- Just set the handler for the next scheduling point
NS_Event.Set_Handler (Next_Slot_Release - Overhead,
NS_Handler_Access);
elsif Current_Slot.all in Sync_Slot'Class then
----------------------------
-- Process a Sync_Slot --
----------------------------
Current_Sync_Slot := Sync_Slot_Access(Current_Slot);
SCB (Current_Sync_Slot.Sync_Id).Last_Release := Now;
Set_True (Sync_Point (Current_Sync_Slot.Sync_Id));
-- Set the handler for the next scheduling point
NS_Event.Set_Handler (Next_Slot_Release - Overhead,
NS_Handler_Access);
elsif Current_Slot.all in Work_Slot'Class then
-----------------------------
-- Process a Work_Slot --
-----------------------------
Current_Work_Slot := Work_Slot_Access(Current_Slot);
Current_WCB := WCB (Current_Work_Slot.Work_Id);
Current_Thread_Id := Current_WCB.Work_Thread_Id;
-- Check what needs be done to the TT task of the new slot
if Current_WCB.Has_Completed then
-- The TT task has abandoned the TT level or has called
-- Wait_For_Activation
if Current_WCB.Is_Sliced then
-- The completed TT task was running sliced and it has
-- completed, so this slot is not needed by the task.
null;
elsif Current_WCB.Is_Waiting then
-- TT task is waiting in Wait_For_Activation
-- Update WCB and release TT task
WCB (Current_Work_Slot.Work_Id).Last_Release := Now;
WCB (Current_Work_Slot.Work_Id).Has_Completed := False;
WCB (Current_Work_Slot.Work_Id).Is_Waiting := False;
Set_True (Release_Point (Current_Work_Slot.Work_Id));
if Current_Work_Slot.Is_Continuation and then
Current_Work_Slot.Padding > Time_Span_Zero then
Hold_Event.Set_Handler (Next_Slot_Release -
Current_Work_Slot.Padding,
Hold_Handler_Access);
end if;
elsif Current_Work_Slot.all in Optional_Slot'Class then
-- If the slot is optional, it is not an error if the TT
-- task has not invoked Wait_For_Activation
null;
else
-- Task is not waiting for its next activation.
-- It must have abandoned the TT Level or it is waiting in
-- a different work slot
raise Program_Error
with ("Task is late to next activation for Work_Id " &
Current_Work_Slot.Work_Id'Image);
end if;
else
-- The TT task has not completed and no overrun has been
-- detected so far, so it must be running sliced and is
-- currently held from a previous exhausted slot, so it
-- must be resumed
pragma Assert (Current_WCB.Is_Sliced);
-- Change thread state to runnable and insert it at the tail
-- of its active priority, which here implies that the
-- thread will be the next to execute
Continue (Current_Thread_Id);
if Current_Work_Slot.Is_Continuation and then
Current_Work_Slot.Padding > Time_Span_Zero then
Hold_Event.Set_Handler (Next_Slot_Release -
Current_Work_Slot.Padding,
Hold_Handler_Access);
end if;
end if;
-- Common actions to process the new slot --
-- The work inherits its Is_Sliced condition from the
-- Is_Continuation property of the new slot
WCB (Current_Work_Slot.Work_Id).Is_Sliced :=
Current_Work_Slot.Is_Continuation;
-- Set timing event for the next scheduling point
NS_Event.Set_Handler (Next_Slot_Release - Overhead,
NS_Handler_Access);
end if;
end NS_Handler;
end Time_Triggered_Scheduler;
end XAda.Dispatching.TTS;
|
-- ----------------------------------------------------------------- --
-- AdaSDL --
-- Binding to Simple Direct Media Layer --
-- Copyright (C) 2001 A.M.F.Vargas --
-- Antonio M. F. Vargas --
-- Ponta Delgada - Azores - Portugal --
-- http://www.adapower.net/~avargas --
-- E-mail: avargas@adapower.net --
-- ----------------------------------------------------------------- --
-- --
-- This library 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. --
-- --
-- This 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 --
-- General Public License for more details. --
-- --
-- You should have received a copy of the GNU General Public --
-- License along with this library; if not, write to the --
-- Free Software Foundation, Inc., 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. --
-- ----------------------------------------------------------------- --
-- **************************************************************** --
-- This is an Ada binding to SDL ( Simple DirectMedia Layer from --
-- Sam Lantinga - www.libsld.org ) --
-- **************************************************************** --
-- In order to help the Ada programmer, the comments in this file --
-- are, in great extent, a direct copy of the original text in the --
-- SDL header files. --
-- **************************************************************** --
----------------------------------------------
-- This package is here for compatibility --
-- with SDL. The Ada programming language --
-- has far better portable multithread and --
-- sincronization mechanisms. --
----------------------------------------------
with SDL.Types; use SDL.Types;
with Interfaces.C;
with System;
package SDL.Mutex is
package C renames Interfaces.C;
MUTEX_TIMEDOUT : constant := 1;
MUTEX_MAXWAIT : constant := 16#FFFFFFFF#;
------------------------
-- Mutex subprograms --
------------------------
-- A pointer to the SDL mutex structure defined
-- in SDL_mutex.c
type mutex_ptr is new System.Address;
null_mutex_ptr : constant mutex_ptr := mutex_ptr (System.Null_Address);
-- Create a mutex, initialized unlocked
function CreateMutex return mutex_ptr;
pragma Import (C, CreateMutex, "SDL_CreateMutex");
-- Lock the mutex (Returns 0 or -1 on error)
function mutexP (mutex : mutex_ptr) return C.int;
pragma Import (C, mutexP, "SDL_mutexP");
-- The same as MutexP
function LockMutex (mutex : mutex_ptr) return C.int;
pragma Inline (LockMutex);
-- Unlock the mutex (Returns 0 or -1 on error)
function mutexV (mutex : mutex_ptr) return C.int;
pragma Import (C, mutexV, "SDL_mutexV");
-- The same as MutexV
function UnlockMutex (mutex : mutex_ptr) return C.int;
pragma Inline (UnlockMutex);
-- Destroy a mutex
procedure DestroyMutex (mutex : mutex_ptr);
pragma Import (C, DestroyMutex, "SDL_DestroyMutex");
---------------------------
-- Semaphore subprograms --
---------------------------
-- A pointer to the SDL semaphore structure defined
-- in SDL_sem.c
type sem_ptr is new System.Address;
-- Create a semaphore, initialized with value, returns
-- NULL on failure.
function CreateSemaphore (initial_value : Uint32)
return sem_ptr;
pragma Import (C, CreateSemaphore, "SDL_CreateSemaphore");
-- Destroy a semaphore
procedure DestroySemaphore (sem : sem_ptr);
pragma Import (C, DestroySemaphore, "SDL_DestroySemaphore");
-- This function suspends the calling thread until the semaphore
-- pointed to by sem has a positive count. It then atomically
-- decreases the semaphore count.
function SemWait (sem : sem_ptr) return C.int;
procedure SemWait (sem : sem_ptr);
pragma Import (C, SemWait, "SDL_SemWait");
-- Non-blocking variant of Sem_Wait, returns 0 if the wait
-- succeeds, SDL_MUTEX_TIMEDOUT if the wait would block, and -1
-- on error.
function SemTryWait (sem : sem_ptr) return C.int;
pragma Import (C, SemTryWait, "SDL_SemTryWait");
-- Varian of Sem_Wait with timeout in miliseconds, returns 0
-- if the wait succeeds, SDL_MUTEX_TIMEDOUT if the whait does
-- not succeed in the allotted time, and -1 in error.
-- On some platforms this function is implemented by looping
-- with a delay of 1 ms, and so should be avoided if possible.
function SemWaitTimeout (sem : sem_ptr; ms : Uint32)
return C.int;
pragma Import (C, SemWaitTimeout, "SDL_SemWaitTimeout");
-- Atomically increases the semaphore's count (not blocking),
-- returns 0, or -1 on error.
function SemPost (sem : sem_ptr) return C.int;
procedure SemPost (sem : sem_ptr);
pragma Import (C, SemPost, "SDL_SemPost");
-- Returns the current count of the semaphore
function SemValue (sem : sem_ptr) return Uint32;
pragma Import (C, SemValue, "SDL_SemValue");
------------------------------------
-- Condition variable functions --
------------------------------------
-- The SDL condition variable structure, defined in SDL_cond.c
type cond_ptr is new System.Address;
-- Create a condition variable
function CreateCond return cond_ptr;
pragma Import (C, CreateCond, "SDL_CreateCond");
-- Destroy a condition variable
procedure DestroyCond (cond : cond_ptr);
pragma Import (C, DestroyCond, "SDL_DestroyCond");
-- Restart one of the threads that are waiting on the
-- condition variable, returns 0, or -1 on error.
function CondSignal (cond : cond_ptr) return C.int;
pragma Import (C, CondSignal, "SDL_CondSignal");
-- Restart all threads that are waiting on the condition
-- variable, returns 0, or -1 on error.
function CondBroadcast (cond : cond_ptr) return C.int;
pragma Import (C, CondBroadcast, "SDL_CondBroadcast");
-- Wait on the condition variable, unlocking the provided
-- mutex. The mutex must be locked before entering this
-- function! returns 0 when it is signaled, or -1 on error.
function CondWait (cond : cond_ptr; mut : mutex_ptr)
return C.int;
pragma Import (C, CondWait, "SDL_CondWait");
-- Waits for at most 'ms' milliseconds, and returns 0 if the
-- condition variable is signaled, SDL_MUTEX_TIMEDOUT if the
-- condition is not signaled in the allocated time, and -1
-- on error.
-- On some platforms this function is implemented by looping
-- with a delay of 1 ms, and so should be avoided if possible.
function CondWaitTimeout (
cond : cond_ptr;
mut : mutex_ptr;
ms : Uint32)
return C.int;
pragma Import (C, CondWaitTimeout, "SDL_CondWaitTimeout");
end SDL.Mutex;
|
Pragma Ada_2012;
Pragma Wide_Character_Encoding( UTF8 );
With
Ada.Strings.UTF_Encoding.Conversions,
Ada.strings.UTF_Encoding.Wide_Wide_Strings,
EPL.Types;
Use
EPL.Types;
-- Edward Parse Library.
--
-- ©2015 E. Fish; All Rights Reserved.
Package EPL.Brackets is
Function Bracket( Data : UTF_08; Style : Types.Bracket ) return UTF_08;
Function Bracket( Data : UTF_16; Style : Types.Bracket ) return UTF_16;
Function Bracket( Data : UTF_32; Style : Types.Bracket ) return UTF_32;
Private
Item : constant Array( Types.Bracket, Side ) of Wide_Wide_Character :=
(
Types.Parentheses => ('(',')'),
Types.Brackets => ('[',']'),
Types.Braces => ('{','}'),
Types.Chevrons => ('⟨','⟩'),
Types.Angle => ('<','>'),
Types.Corner => ('「','」')
);
Function Left return Side renames Ada.Strings.Left;
Function Right return Side renames Ada.Strings.Right;
Use Ada.Strings.UTF_Encoding.Conversions, Ada.Strings.UTF_Encoding;
Function Bracket( Data : UTF_08; Style : Types.Bracket ) return UTF_08 is
( Convert( Input_Scheme => UTF_8, Item => Bracket(Data,Style)) );
Function Bracket( Data : UTF_16; Style : Types.Bracket ) return UTF_16 is
("");
Function Bracket( Data : UTF_32; Style : Types.Bracket ) return UTF_32 is
( Item(Style, Left) & Data & Item(Style, Right) );
End EPL.Brackets;
|
package body Benchmark.Stride is
function Create_Stride return Benchmark_Pointer is
begin
return new Stride_Type;
end Create_Stride;
procedure Set_Argument(benchmark : in out Stride_Type;
arg : in String) is
value : constant String := Extract_Argument(arg);
begin
if Check_Argument(arg, "size") then
benchmark.size := Positive'Value(value);
elsif Check_Argument(arg, "stride") then
benchmark.stride := Integer'Value(value);
elsif Check_Argument(arg, "iterations") then
benchmark.iterations := Positive'Value(value);
else
Set_Argument(Benchmark_Type(benchmark), arg);
end if;
exception
when others =>
raise Invalid_Argument;
end Set_Argument;
procedure Run(benchmark : in Stride_Type) is
begin
for i in 1 .. benchmark.iterations loop
for offset in 0 .. Address_Type(benchmark.size - 1) loop
Read(benchmark, offset * 4, 4);
if benchmark.spacing > 0 then
Idle(benchmark, benchmark.spacing);
end if;
end loop;
end loop;
end Run;
end Benchmark.Stride;
|
with NPC_PC; use NPC_PC;
with ada.text_io;
use ada.text_io;
with enemy_BST; use enemy_bst;
package Combat_package is
-------------------------------
-- Name: Jon Spohn
-- David Rogina
-- Combat Package Specification
-------------------------------
--Combat procedure
Procedure Combat(Hero : in out HeroClass; Enemy : in out EnemyClass;ET : in out EnemyTree; Run : in out integer);
--Draw Monster picture
procedure draw_enemy(file:in file_type);
end Combat_package;
|
-- { dg-excess-errors "no code generated" }
generic
type Length_T is range <>;
with function Next return Length_T is <>;
type Value_T is private;
with function Value (L : Length_T) return Value_T is <>;
package Renaming2_Pkg4 is
generic
type T is private;
package Inner is
type Slave_T is tagged null record;
function Next_Value return Value_T;
end Inner;
end Renaming2_Pkg4;
|
-- Cyclic redundancy check to verify archived data integrity
package Zip.CRC is
use Interfaces;
procedure Init (Current_CRC : out Unsigned_32);
function Final (Current_CRC : Unsigned_32) return Unsigned_32;
procedure Update (Current_CRC : in out Unsigned_32; InBuf : Zip.Byte_Buffer);
pragma Inline (Update);
end Zip.CRC;
|
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- G N A T . A W K --
-- --
-- S p e c --
-- --
-- Copyright (C) 2000-2020, AdaCore --
-- --
-- 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. --
-- --
-- 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/>. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
-- This is an AWK-like unit. It provides an easy interface for parsing one
-- or more files containing formatted data. The file can be viewed seen as
-- a database where each record is a line and a field is a data element in
-- this line. In this implementation an AWK record is a line. This means
-- that a record cannot span multiple lines. The operating procedure is to
-- read files line by line, with each line being presented to the user of
-- the package. The interface provides services to access specific fields
-- in the line. Thus it is possible to control actions taken on a line based
-- on values of some fields. This can be achieved directly or by registering
-- callbacks triggered on programmed conditions.
--
-- The state of an AWK run is recorded in an object of type session.
-- The following is the procedure for using a session to control an
-- AWK run:
--
-- 1) Specify which session is to be used. It is possible to use the
-- default session or to create a new one by declaring an object of
-- type Session_Type. For example:
--
-- Computers : Session_Type;
--
-- 2) Specify how to cut a line into fields. There are two modes: using
-- character fields separators or column width. This is done by using
-- Set_Fields_Separators or Set_Fields_Width. For example by:
--
-- AWK.Set_Field_Separators (";,", Computers);
--
-- or by using iterators' Separators parameter.
--
-- 3) Specify which files to parse. This is done with Add_File/Add_Files
-- services, or by using the iterators' Filename parameter. For
-- example:
--
-- AWK.Add_File ("myfile.db", Computers);
--
-- 4) Run the AWK session using one of the provided iterators.
--
-- Parse
-- This is the most automated iterator. You can gain control on
-- the session only by registering one or more callbacks (see
-- Register).
--
-- Get_Line/End_Of_Data
-- This is a manual iterator to be used with a loop. You have
-- complete control on the session. You can use callbacks but
-- this is not required.
--
-- For_Every_Line
-- This provides a mixture of manual/automated iterator action.
--
-- Examples of these three approaches appear below
--
-- There are many ways to use this package. The following discussion shows
-- three approaches to using this package, using the three iterator forms.
-- All examples will use the following file (computer.db):
--
-- Pluton;Windows-NT;Pentium III
-- Mars;Linux;Pentium Pro
-- Venus;Solaris;Sparc
-- Saturn;OS/2;i486
-- Jupiter;MacOS;PPC
--
-- 1) Using Parse iterator
--
-- Here the first step is to register some action associated to a pattern
-- and then to call the Parse iterator (this is the simplest way to use
-- this unit). The default session is used here. For example to output the
-- second field (the OS) of computer "Saturn".
--
-- procedure Action is
-- begin
-- Put_Line (AWK.Field (2));
-- end Action;
--
-- begin
-- AWK.Register (1, "Saturn", Action'Access);
-- AWK.Parse (";", "computer.db");
--
--
-- 2) Using the Get_Line/End_Of_Data iterator
--
-- Here you have full control. For example to do the same as
-- above but using a specific session, you could write:
--
-- Computer_File : Session_Type;
--
-- begin
-- AWK.Set_Current (Computer_File);
-- AWK.Open (Separators => ";",
-- Filename => "computer.db");
--
-- -- Display Saturn OS
--
-- while not AWK.End_Of_File loop
-- AWK.Get_Line;
--
-- if AWK.Field (1) = "Saturn" then
-- Put_Line (AWK.Field (2));
-- end if;
-- end loop;
--
-- AWK.Close (Computer_File);
--
--
-- 3) Using For_Every_Line iterator
--
-- In this case you use a provided iterator and you pass the procedure
-- that must be called for each record. You could code the previous
-- example could be coded as follows (using the iterator quick interface
-- but without using the current session):
--
-- Computer_File : Session_Type;
--
-- procedure Action (Quit : in out Boolean) is
-- begin
-- if AWK.Field (1, Computer_File) = "Saturn" then
-- Put_Line (AWK.Field (2, Computer_File));
-- end if;
-- end Action;
--
-- procedure Look_For_Saturn is
-- new AWK.For_Every_Line (Action);
--
-- begin
-- Look_For_Saturn (Separators => ";",
-- Filename => "computer.db",
-- Session => Computer_File);
--
-- Integer_Text_IO.Put
-- (Integer (AWK.NR (Session => Computer_File)));
-- Put_Line (" line(s) have been processed.");
--
-- You can also use a regular expression for the pattern. Let us output
-- the computer name for all computer for which the OS has a character
-- O in its name.
--
-- Regexp : String := ".*O.*";
--
-- Matcher : Regpat.Pattern_Matcher := Regpat.Compile (Regexp);
--
-- procedure Action is
-- begin
-- Text_IO.Put_Line (AWK.Field (2));
-- end Action;
--
-- begin
-- AWK.Register (2, Matcher, Action'Unrestricted_Access);
-- AWK.Parse (";", "computer.db");
--
with Ada.Finalization;
with GNAT.Regpat;
package GNAT.AWK is
Session_Error : exception;
-- Raised when a Session is reused but is not closed
File_Error : exception;
-- Raised when there is a file problem (see below)
End_Error : exception;
-- Raised when an attempt is made to read beyond the end of the last
-- file of a session.
Field_Error : exception;
-- Raised when accessing a field value which does not exist
Data_Error : exception;
-- Raised when it is impossible to convert a field value to a specific type
type Count is new Natural;
type Widths_Set is array (Positive range <>) of Positive;
-- Used to store a set of columns widths
Default_Separators : constant String := " " & ASCII.HT;
Use_Current : constant String := "";
-- Value used when no separator or filename is specified in iterators
type Session_Type is limited private;
-- This is the main exported type. A session is used to keep the state of
-- a full AWK run. The state comprises a list of files, the current file,
-- the number of line processed, the current line, the number of fields in
-- the current line... A default session is provided (see Set_Current,
-- Current_Session and Default_Session below).
----------------------------
-- Package initialization --
----------------------------
-- To be thread safe it is not possible to use the default provided
-- session. Each task must used a specific session and specify it
-- explicitly for every services.
procedure Set_Current (Session : Session_Type);
-- Set the session to be used by default. This file will be used when the
-- Session parameter in following services is not specified.
function Current_Session return not null access Session_Type;
-- Returns the session used by default by all services. This is the
-- latest session specified by Set_Current service or the session
-- provided by default with this implementation.
function Default_Session return not null access Session_Type;
-- Returns the default session provided by this package. Note that this is
-- the session return by Current_Session if Set_Current has not been used.
procedure Set_Field_Separators
(Separators : String := Default_Separators;
Session : Session_Type);
procedure Set_Field_Separators
(Separators : String := Default_Separators);
-- Set the field separators. Each character in the string is a field
-- separator. When a line is read it will be split by field using the
-- separators set here. Separators can be changed at any point and in this
-- case the current line is split according to the new separators. In the
-- special case that Separators is a space and a tabulation
-- (Default_Separators), fields are separated by runs of spaces and/or
-- tabs.
procedure Set_FS
(Separators : String := Default_Separators;
Session : Session_Type)
renames Set_Field_Separators;
procedure Set_FS
(Separators : String := Default_Separators)
renames Set_Field_Separators;
-- FS is the AWK abbreviation for above service
procedure Set_Field_Widths
(Field_Widths : Widths_Set;
Session : Session_Type);
procedure Set_Field_Widths
(Field_Widths : Widths_Set);
-- This is another way to split a line by giving the length (in number of
-- characters) of each field in a line. Field widths can be changed at any
-- point and in this case the current line is split according to the new
-- field lengths. A line split with this method must have a length equal or
-- greater to the total of the field widths. All characters remaining on
-- the line after the latest field are added to a new automatically
-- created field.
procedure Add_File
(Filename : String;
Session : Session_Type);
procedure Add_File
(Filename : String);
-- Add Filename to the list of file to be processed. There is no limit on
-- the number of files that can be added. Files are processed in the order
-- they have been added (i.e. the filename list is FIFO). If Filename does
-- not exist or if it is not readable, File_Error is raised.
procedure Add_Files
(Directory : String;
Filenames : String;
Number_Of_Files_Added : out Natural;
Session : Session_Type);
procedure Add_Files
(Directory : String;
Filenames : String;
Number_Of_Files_Added : out Natural);
-- Add all files matching the regular expression Filenames in the specified
-- directory to the list of file to be processed. There is no limit on
-- the number of files that can be added. Each file is processed in
-- the same order they have been added (i.e. the filename list is FIFO).
-- The number of files (possibly 0) added is returned in
-- Number_Of_Files_Added.
-------------------------------------
-- Information about current state --
-------------------------------------
function Number_Of_Fields
(Session : Session_Type) return Count;
function Number_Of_Fields
return Count;
pragma Inline (Number_Of_Fields);
-- Returns the number of fields in the current record. It returns 0 when
-- no file is being processed.
function NF
(Session : Session_Type) return Count
renames Number_Of_Fields;
function NF
return Count
renames Number_Of_Fields;
-- AWK abbreviation for above service
function Number_Of_File_Lines
(Session : Session_Type) return Count;
function Number_Of_File_Lines
return Count;
pragma Inline (Number_Of_File_Lines);
-- Returns the current line number in the processed file. It returns 0 when
-- no file is being processed.
function FNR (Session : Session_Type) return Count
renames Number_Of_File_Lines;
function FNR return Count
renames Number_Of_File_Lines;
-- AWK abbreviation for above service
function Number_Of_Lines
(Session : Session_Type) return Count;
function Number_Of_Lines
return Count;
pragma Inline (Number_Of_Lines);
-- Returns the number of line processed until now. This is equal to number
-- of line in each already processed file plus FNR. It returns 0 when
-- no file is being processed.
function NR (Session : Session_Type) return Count
renames Number_Of_Lines;
function NR return Count
renames Number_Of_Lines;
-- AWK abbreviation for above service
function Number_Of_Files
(Session : Session_Type) return Natural;
function Number_Of_Files
return Natural;
pragma Inline (Number_Of_Files);
-- Returns the number of files associated with Session. This is the total
-- number of files added with Add_File and Add_Files services.
function File (Session : Session_Type) return String;
function File return String;
-- Returns the name of the file being processed. It returns the empty
-- string when no file is being processed.
---------------------
-- Field accessors --
---------------------
function Field
(Rank : Count;
Session : Session_Type) return String;
function Field
(Rank : Count) return String;
-- Returns field number Rank value of the current record. If Rank = 0 it
-- returns the current record (i.e. the line as read in the file). It
-- raises Field_Error if Rank > NF or if Session is not open.
function Field
(Rank : Count;
Session : Session_Type) return Integer;
function Field
(Rank : Count) return Integer;
-- Returns field number Rank value of the current record as an integer. It
-- raises Field_Error if Rank > NF or if Session is not open. It
-- raises Data_Error if the field value cannot be converted to an integer.
function Field
(Rank : Count;
Session : Session_Type) return Float;
function Field
(Rank : Count) return Float;
-- Returns field number Rank value of the current record as a float. It
-- raises Field_Error if Rank > NF or if Session is not open. It
-- raises Data_Error if the field value cannot be converted to a float.
generic
type Discrete is (<>);
function Discrete_Field
(Rank : Count;
Session : Session_Type) return Discrete;
generic
type Discrete is (<>);
function Discrete_Field_Current_Session
(Rank : Count) return Discrete;
-- Returns field number Rank value of the current record as a type
-- Discrete. It raises Field_Error if Rank > NF. It raises Data_Error if
-- the field value cannot be converted to type Discrete.
--------------------
-- Pattern/Action --
--------------------
-- AWK defines rules like "PATTERN { ACTION }". Which means that ACTION
-- will be executed if PATTERN match. A pattern in this implementation can
-- be a simple string (match function is equality), a regular expression,
-- a function returning a boolean. An action is associated to a pattern
-- using the Register services.
--
-- Each procedure Register will add a rule to the set of rules for the
-- session. Rules are examined in the order they have been added.
type Pattern_Callback is access function return Boolean;
-- This is a pattern function pointer. When it returns True the associated
-- action will be called.
type Action_Callback is access procedure;
-- A simple action pointer
type Match_Action_Callback is
access procedure (Matches : GNAT.Regpat.Match_Array);
-- An advanced action pointer used with a regular expression pattern. It
-- returns an array of all the matches. See GNAT.Regpat for further
-- information.
procedure Register
(Field : Count;
Pattern : String;
Action : Action_Callback;
Session : Session_Type);
procedure Register
(Field : Count;
Pattern : String;
Action : Action_Callback);
-- Register an Action associated with a Pattern. The pattern here is a
-- simple string that must match exactly the field number specified.
procedure Register
(Field : Count;
Pattern : GNAT.Regpat.Pattern_Matcher;
Action : Action_Callback;
Session : Session_Type);
procedure Register
(Field : Count;
Pattern : GNAT.Regpat.Pattern_Matcher;
Action : Action_Callback);
-- Register an Action associated with a Pattern. The pattern here is a
-- simple regular expression which must match the field number specified.
procedure Register
(Field : Count;
Pattern : GNAT.Regpat.Pattern_Matcher;
Action : Match_Action_Callback;
Session : Session_Type);
procedure Register
(Field : Count;
Pattern : GNAT.Regpat.Pattern_Matcher;
Action : Match_Action_Callback);
-- Same as above but it pass the set of matches to the action
-- procedure. This is useful to analyze further why and where a regular
-- expression did match.
procedure Register
(Pattern : Pattern_Callback;
Action : Action_Callback;
Session : Session_Type);
procedure Register
(Pattern : Pattern_Callback;
Action : Action_Callback);
-- Register an Action associated with a Pattern. The pattern here is a
-- function that must return a boolean. Action callback will be called if
-- the pattern callback returns True and nothing will happen if it is
-- False. This version is more general, the two other register services
-- trigger an action based on the value of a single field only.
procedure Register
(Action : Action_Callback;
Session : Session_Type);
procedure Register
(Action : Action_Callback);
-- Register an Action that will be called for every line. This is
-- equivalent to a Pattern_Callback function always returning True.
--------------------
-- Parse iterator --
--------------------
procedure Parse
(Separators : String := Use_Current;
Filename : String := Use_Current;
Session : Session_Type);
procedure Parse
(Separators : String := Use_Current;
Filename : String := Use_Current);
-- Launch the iterator, it will read every line in all specified
-- session's files. Registered callbacks are then called if the associated
-- pattern match. It is possible to specify a filename and a set of
-- separators directly. This offer a quick way to parse a single
-- file. These parameters will override those specified by Set_FS and
-- Add_File. The Session will be opened and closed automatically.
-- File_Error is raised if there is no file associated with Session, or if
-- a file associated with Session is not longer readable. It raises
-- Session_Error is Session is already open.
-----------------------------------
-- Get_Line/End_Of_Data Iterator --
-----------------------------------
type Callback_Mode is (None, Only, Pass_Through);
-- These mode are used for Get_Line/End_Of_Data and For_Every_Line
-- iterators. The associated semantic is:
--
-- None
-- callbacks are not active. This is the default mode for
-- Get_Line/End_Of_Data and For_Every_Line iterators.
--
-- Only
-- callbacks are active, if at least one pattern match, the associated
-- action is called and this line will not be passed to the user. In
-- the Get_Line case the next line will be read (if there is some
-- line remaining), in the For_Every_Line case Action will
-- not be called for this line.
--
-- Pass_Through
-- callbacks are active, for patterns which match the associated
-- action is called. Then the line is passed to the user. It means
-- that Action procedure is called in the For_Every_Line case and
-- that Get_Line returns with the current line active.
--
procedure Open
(Separators : String := Use_Current;
Filename : String := Use_Current;
Session : Session_Type);
procedure Open
(Separators : String := Use_Current;
Filename : String := Use_Current);
-- Open the first file and initialize the unit. This must be called once
-- before using Get_Line. It is possible to specify a filename and a set of
-- separators directly. This offer a quick way to parse a single file.
-- These parameters will override those specified by Set_FS and Add_File.
-- File_Error is raised if there is no file associated with Session, or if
-- the first file associated with Session is no longer readable. It raises
-- Session_Error is Session is already open.
procedure Get_Line
(Callbacks : Callback_Mode := None;
Session : Session_Type);
procedure Get_Line
(Callbacks : Callback_Mode := None);
-- Read a line from the current input file. If the file index is at the
-- end of the current input file (i.e. End_Of_File is True) then the
-- following file is opened. If there is no more file to be processed,
-- exception End_Error will be raised. File_Error will be raised if Open
-- has not been called. Next call to Get_Line will return the following
-- line in the file. By default the registered callbacks are not called by
-- Get_Line, this can activated by setting Callbacks (see Callback_Mode
-- description above). File_Error may be raised if a file associated with
-- Session is not readable.
--
-- When Callbacks is not None, it is possible to exhaust all the lines
-- of all the files associated with Session. In this case, File_Error
-- is not raised.
--
-- This procedure can be used from a subprogram called by procedure Parse
-- or by an instantiation of For_Every_Line (see below).
function End_Of_Data
(Session : Session_Type) return Boolean;
function End_Of_Data
return Boolean;
pragma Inline (End_Of_Data);
-- Returns True if there is no more data to be processed in Session. It
-- means that the latest session's file is being processed and that
-- there is no more data to be read in this file (End_Of_File is True).
function End_Of_File
(Session : Session_Type) return Boolean;
function End_Of_File
return Boolean;
pragma Inline (End_Of_File);
-- Returns True when there is no more data to be processed on the current
-- session's file.
procedure Close (Session : Session_Type);
-- Release all associated data with Session. All memory allocated will
-- be freed, the current file will be closed if needed, the callbacks
-- will be unregistered. Close is convenient in reestablishing a session
-- for new use. Get_Line is no longer usable (will raise File_Error)
-- except after a successful call to Open, Parse or an instantiation
-- of For_Every_Line.
-----------------------------
-- For_Every_Line iterator --
-----------------------------
generic
with procedure Action (Quit : in out Boolean);
procedure For_Every_Line
(Separators : String := Use_Current;
Filename : String := Use_Current;
Callbacks : Callback_Mode := None;
Session : Session_Type);
generic
with procedure Action (Quit : in out Boolean);
procedure For_Every_Line_Current_Session
(Separators : String := Use_Current;
Filename : String := Use_Current;
Callbacks : Callback_Mode := None);
-- This is another iterator. Action will be called for each new
-- record. The iterator's termination can be controlled by setting Quit
-- to True. It is by default set to False. It is possible to specify a
-- filename and a set of separators directly. This offer a quick way to
-- parse a single file. These parameters will override those specified by
-- Set_FS and Add_File. By default the registered callbacks are not called
-- by For_Every_Line, this can activated by setting Callbacks (see
-- Callback_Mode description above). The Session will be opened and
-- closed automatically. File_Error is raised if there is no file
-- associated with Session. It raises Session_Error is Session is already
-- open.
private
type Session_Data;
type Session_Data_Access is access Session_Data;
type Session_Type is new Ada.Finalization.Limited_Controlled with record
Data : Session_Data_Access;
Self : not null access Session_Type := Session_Type'Unchecked_Access;
end record;
procedure Initialize (Session : in out Session_Type);
procedure Finalize (Session : in out Session_Type);
end GNAT.AWK;
|
------------------------------------------------------------------------------
-- --
-- GNAT RUN-TIME COMPONENTS --
-- --
-- ADA.NUMERICS.BIG_NUMBERS.BIG_INTEGERS --
-- --
-- B o d y --
-- --
-- Copyright (C) 2019-2020, 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. --
-- --
-- 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/>. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
with Ada.Unchecked_Deallocation;
with Ada.Strings.Text_Output.Utils;
with Interfaces; use Interfaces;
with System.Generic_Bignums;
with System.Shared_Bignums; use System.Shared_Bignums;
package body Ada.Numerics.Big_Numbers.Big_Integers is
function Allocate_Bignum (D : Digit_Vector; Neg : Boolean) return Bignum;
-- Allocate Bignum value with the given contents
procedure Free_Bignum (X : in out Bignum);
-- Free memory associated with X
function To_Bignum (X : aliased in out Bignum) return Bignum is (X);
procedure Free is new Ada.Unchecked_Deallocation (Bignum_Data, Bignum);
---------------------
-- Allocate_Bignum --
---------------------
function Allocate_Bignum (D : Digit_Vector; Neg : Boolean) return Bignum is
begin
return new Bignum_Data'(D'Length, Neg, D);
end Allocate_Bignum;
-----------------
-- Free_Bignum --
-----------------
procedure Free_Bignum (X : in out Bignum) is
begin
Free (X);
end Free_Bignum;
package Bignums is new System.Generic_Bignums
(Bignum, Allocate_Bignum, Free_Bignum, To_Bignum);
use Bignums, System;
function Get_Bignum (Arg : Big_Integer) return Bignum is
(if Arg.Value.C = System.Null_Address
then raise Constraint_Error with "invalid big integer"
else To_Bignum (Arg.Value.C));
-- Check for validity of Arg and return the Bignum value stored in Arg.
-- Raise Constraint_Error if Arg is uninitialized.
procedure Set_Bignum (Arg : out Big_Integer; Value : Bignum)
with Inline;
-- Set the Bignum value stored in Arg to Value
----------------
-- Set_Bignum --
----------------
procedure Set_Bignum (Arg : out Big_Integer; Value : Bignum) is
begin
Arg.Value.C := To_Address (Value);
end Set_Bignum;
--------------
-- Is_Valid --
--------------
function Is_Valid (Arg : Big_Integer) return Boolean is
(Arg.Value.C /= System.Null_Address);
---------
-- "=" --
---------
function "=" (L, R : Valid_Big_Integer) return Boolean is
begin
return Big_EQ (Get_Bignum (L), Get_Bignum (R));
end "=";
---------
-- "<" --
---------
function "<" (L, R : Valid_Big_Integer) return Boolean is
begin
return Big_LT (Get_Bignum (L), Get_Bignum (R));
end "<";
----------
-- "<=" --
----------
function "<=" (L, R : Valid_Big_Integer) return Boolean is
begin
return Big_LE (Get_Bignum (L), Get_Bignum (R));
end "<=";
---------
-- ">" --
---------
function ">" (L, R : Valid_Big_Integer) return Boolean is
begin
return Big_GT (Get_Bignum (L), Get_Bignum (R));
end ">";
----------
-- ">=" --
----------
function ">=" (L, R : Valid_Big_Integer) return Boolean is
begin
return Big_GE (Get_Bignum (L), Get_Bignum (R));
end ">=";
--------------------
-- To_Big_Integer --
--------------------
function To_Big_Integer (Arg : Integer) return Valid_Big_Integer is
Result : Big_Integer;
begin
Set_Bignum (Result, To_Bignum (Long_Long_Integer (Arg)));
return Result;
end To_Big_Integer;
----------------
-- To_Integer --
----------------
function To_Integer (Arg : Valid_Big_Integer) return Integer is
begin
return Integer (From_Bignum (Get_Bignum (Arg)));
end To_Integer;
------------------------
-- Signed_Conversions --
------------------------
package body Signed_Conversions is
--------------------
-- To_Big_Integer --
--------------------
function To_Big_Integer (Arg : Int) return Valid_Big_Integer is
Result : Big_Integer;
begin
Set_Bignum (Result, To_Bignum (Long_Long_Integer (Arg)));
return Result;
end To_Big_Integer;
----------------------
-- From_Big_Integer --
----------------------
function From_Big_Integer (Arg : Valid_Big_Integer) return Int is
begin
return Int (From_Bignum (Get_Bignum (Arg)));
end From_Big_Integer;
end Signed_Conversions;
--------------------------
-- Unsigned_Conversions --
--------------------------
package body Unsigned_Conversions is
--------------------
-- To_Big_Integer --
--------------------
function To_Big_Integer (Arg : Int) return Valid_Big_Integer is
Result : Big_Integer;
begin
Set_Bignum (Result, To_Bignum (Unsigned_64 (Arg)));
return Result;
end To_Big_Integer;
----------------------
-- From_Big_Integer --
----------------------
function From_Big_Integer (Arg : Valid_Big_Integer) return Int is
begin
return Int (From_Bignum (Get_Bignum (Arg)));
end From_Big_Integer;
end Unsigned_Conversions;
---------------
-- To_String --
---------------
function To_String
(Arg : Valid_Big_Integer; Width : Field := 0; Base : Number_Base := 10)
return String is
begin
return To_String (Get_Bignum (Arg), Natural (Width), Positive (Base));
end To_String;
-----------------
-- From_String --
-----------------
function From_String (Arg : String) return Big_Integer is
Result : Big_Integer;
begin
-- ??? only support Long_Long_Integer, good enough for now
Set_Bignum (Result, To_Bignum (Long_Long_Integer'Value (Arg)));
return Result;
end From_String;
---------------
-- Put_Image --
---------------
procedure Put_Image (S : in out Sink'Class; V : Big_Integer) is
-- This is implemented in terms of To_String. It might be more elegant
-- and more efficient to do it the other way around, but this is the
-- most expedient implementation for now.
begin
Strings.Text_Output.Utils.Put_UTF_8 (S, To_String (V));
end Put_Image;
---------
-- "+" --
---------
function "+" (L : Valid_Big_Integer) return Valid_Big_Integer is
Result : Big_Integer;
begin
Set_Bignum (Result, new Bignum_Data'(Get_Bignum (L).all));
return Result;
end "+";
---------
-- "-" --
---------
function "-" (L : Valid_Big_Integer) return Valid_Big_Integer is
Result : Big_Integer;
begin
Set_Bignum (Result, Big_Neg (Get_Bignum (L)));
return Result;
end "-";
-----------
-- "abs" --
-----------
function "abs" (L : Valid_Big_Integer) return Valid_Big_Integer is
Result : Big_Integer;
begin
Set_Bignum (Result, Big_Abs (Get_Bignum (L)));
return Result;
end "abs";
---------
-- "+" --
---------
function "+" (L, R : Valid_Big_Integer) return Valid_Big_Integer is
Result : Big_Integer;
begin
Set_Bignum (Result, Big_Add (Get_Bignum (L), Get_Bignum (R)));
return Result;
end "+";
---------
-- "-" --
---------
function "-" (L, R : Valid_Big_Integer) return Valid_Big_Integer is
Result : Big_Integer;
begin
Set_Bignum (Result, Big_Sub (Get_Bignum (L), Get_Bignum (R)));
return Result;
end "-";
---------
-- "*" --
---------
function "*" (L, R : Valid_Big_Integer) return Valid_Big_Integer is
Result : Big_Integer;
begin
Set_Bignum (Result, Big_Mul (Get_Bignum (L), Get_Bignum (R)));
return Result;
end "*";
---------
-- "/" --
---------
function "/" (L, R : Valid_Big_Integer) return Valid_Big_Integer is
Result : Big_Integer;
begin
Set_Bignum (Result, Big_Div (Get_Bignum (L), Get_Bignum (R)));
return Result;
end "/";
-----------
-- "mod" --
-----------
function "mod" (L, R : Valid_Big_Integer) return Valid_Big_Integer is
Result : Big_Integer;
begin
Set_Bignum (Result, Big_Mod (Get_Bignum (L), Get_Bignum (R)));
return Result;
end "mod";
-----------
-- "rem" --
-----------
function "rem" (L, R : Valid_Big_Integer) return Valid_Big_Integer is
Result : Big_Integer;
begin
Set_Bignum (Result, Big_Rem (Get_Bignum (L), Get_Bignum (R)));
return Result;
end "rem";
----------
-- "**" --
----------
function "**"
(L : Valid_Big_Integer; R : Natural) return Valid_Big_Integer is
begin
declare
Exp : Bignum := To_Bignum (Long_Long_Integer (R));
Result : Big_Integer;
begin
Set_Bignum (Result, Big_Exp (Get_Bignum (L), Exp));
Free (Exp);
return Result;
end;
end "**";
---------
-- Min --
---------
function Min (L, R : Valid_Big_Integer) return Valid_Big_Integer is
(if L < R then L else R);
---------
-- Max --
---------
function Max (L, R : Valid_Big_Integer) return Valid_Big_Integer is
(if L > R then L else R);
-----------------------------
-- Greatest_Common_Divisor --
-----------------------------
function Greatest_Common_Divisor
(L, R : Valid_Big_Integer) return Big_Positive
is
function GCD (A, B : Big_Integer) return Big_Integer;
-- Recursive internal version
---------
-- GCD --
---------
function GCD (A, B : Big_Integer) return Big_Integer is
begin
if Is_Zero (Get_Bignum (B)) then
return A;
else
return GCD (B, A rem B);
end if;
end GCD;
begin
return GCD (abs L, abs R);
end Greatest_Common_Divisor;
------------
-- Adjust --
------------
procedure Adjust (This : in out Controlled_Bignum) is
begin
if This.C /= System.Null_Address then
This.C := To_Address (new Bignum_Data'(To_Bignum (This.C).all));
end if;
end Adjust;
--------------
-- Finalize --
--------------
procedure Finalize (This : in out Controlled_Bignum) is
Tmp : Bignum := To_Bignum (This.C);
begin
Free (Tmp);
This.C := System.Null_Address;
end Finalize;
end Ada.Numerics.Big_Numbers.Big_Integers;
|
-- Abstract :
--
-- Generic unbounded red-black tree with definite elements.
--
-- Copyright (C) 2017, 2018 Free Software Foundation, Inc.
--
-- This library 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. This library is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN-
-- TABILITY 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.
pragma License (Modified_GPL);
package body SAL.Gen_Unbounded_Definite_Red_Black_Trees is
-- Local declarations (alphabetical order)
function Count_Tree (Item : in Node_Access; Nil : in Node_Access) return Ada.Containers.Count_Type
with Pre => Nil /= null;
procedure Delete_Fixup (T : in out Tree; X : in out Node_Access);
function Find (Root : in Node_Access; Key : in Key_Type; Nil : in Node_Access) return Node_Access
with Pre => Nil /= null;
procedure Left_Rotate (Tree : in out Pkg.Tree; X : in Node_Access)
with Pre => X /= null;
procedure Right_Rotate (Tree : in out Pkg.Tree; X : in Node_Access)
with Pre => X /= null;
procedure Transplant (T : in out Pkg.Tree; U, V : in Node_Access)
with Pre => U /= null and T.Root /= null;
----------
-- local bodies (alphabetical order)
function Count_Tree (Item : in Node_Access; Nil : in Node_Access) return Ada.Containers.Count_Type
is
use all type Ada.Containers.Count_Type;
Result : Ada.Containers.Count_Type := 0;
begin
if Item.Left /= Nil then
Result := Result + Count_Tree (Item.Left, Nil);
end if;
if Item.Right /= Nil then
Result := Result + Count_Tree (Item.Right, Nil);
end if;
return Result + 1;
end Count_Tree;
procedure Delete_Fixup (T : in out Tree; X : in out Node_Access)
is
W : Node_Access;
begin
-- [1] 13.3 RB-Delete-Fixup
-- X is either "doubly black" or "red and black"
-- X.Parent is set, even if X = Nil.
-- In all cases, Nil.Left = null.Right = null.
while X /= T.Root and X.Color = Black loop
if X = X.Parent.Left then
W := X.Parent.Right;
if W.Color = Red then
W.Color := Black;
X.Parent.Color := Red;
Left_Rotate (T, X.Parent);
W := X.Parent.Right;
end if;
if W.Left.Color = Black and W.Right.Color = Black then
W.Color := Red;
X := X.Parent;
else
if W.Right.Color = Black then
W.Left.Color := Black;
W.Color := Red;
Right_Rotate (T, W);
W := X.Parent.Right;
end if;
W.Color := X.Parent.Color;
X.Parent.Color := Black;
W.Right.Color := Black;
Left_Rotate (T, X.Parent);
X := T.Root;
end if;
else
W := X.Parent.Left;
if W.Color = Red then
W.Color := Black;
X.Parent.Color := Red;
Right_Rotate (T, X.Parent);
W := X.Parent.Left;
end if;
if W.Right.Color = Black and W.Left.Color = Black then
W.Color := Red;
X := X.Parent;
else
if W.Left.Color = Black then
W.Right.Color := Black;
W.Color := Red;
Left_Rotate (T, W);
W := X.Parent.Left;
end if;
W.Color := X.Parent.Color;
X.Parent.Color := Black;
W.Left.Color := Black;
Right_Rotate (T, X.Parent);
X := T.Root;
end if;
end if;
end loop;
X.Color := Black;
end Delete_Fixup;
function Find (Root : in Node_Access; Key : in Key_Type; Nil : in Node_Access) return Node_Access
is
Node : Node_Access := Root;
begin
while Node /= Nil loop
case Key_Compare (Key, Pkg.Key (Node.Element)) is
when Equal =>
return Node;
when Less =>
Node := Node.Left;
when Greater =>
Node := Node.Right;
end case;
end loop;
return null;
end Find;
procedure Free_Tree (Item : in out Node_Access; Nil : in Node_Access)
is begin
if Item = Nil or Item = null then
raise Programmer_Error;
end if;
if Item.Left /= Nil then
Free_Tree (Item.Left, Nil);
end if;
if Item.Right /= Nil then
Free_Tree (Item.Right, Nil);
end if;
Free (Item);
end Free_Tree;
procedure Insert_Fixup (Tree : in out Pkg.Tree; Z : in out Node_Access)
is
-- [1] 13.3 RB-Insert-Fixup (T, z)
Nil : Node_Access renames Tree.Nil;
Y : Node_Access;
begin
while Z.Parent /= Nil and then Z.Parent.Color = Red loop
if Z.Parent = Z.Parent.Parent.Left then
Y := Z.Parent.Parent.Right;
if Y /= Nil and then Y.Color = Red then
Z.Parent.Color := Black;
Y.Color := Black;
Z.Parent.Parent.Color := Red;
Z := Z.Parent.Parent;
else
if Z = Z.Parent.Right then
Z := Z.Parent;
Left_Rotate (Tree, Z);
end if;
Z.Parent.Color := Black;
Z.Parent.Parent.Color := Red;
Right_Rotate (Tree, Z.Parent.Parent);
end if;
else
Y := Z.Parent.Parent.Left;
if Y /= Nil and then Y.Color = Red then
Z.Parent.Color := Black;
Y.Color := Black;
Z.Parent.Parent.Color := Red;
Z := Z.Parent.Parent;
else
if Z = Z.Parent.Left then
Z := Z.Parent;
Right_Rotate (Tree, Z);
end if;
Z.Parent.Color := Black;
Z.Parent.Parent.Color := Red;
Left_Rotate (Tree, Z.Parent.Parent);
end if;
end if;
end loop;
Tree.Root.Color := Black;
end Insert_Fixup;
procedure Left_Rotate (Tree : in out Pkg.Tree; X : in Node_Access)
is
-- [1] 13.2 Left-Rotate (T, x)
Nil : Node_Access renames Tree.Nil;
Y : constant Node_Access := X.Right;
begin
X.Right := Y.Left;
if Y.Left /= Nil then
Y.Left.Parent := X;
end if;
Y.Parent := X.Parent;
if X.Parent = Nil then
Tree.Root := Y;
elsif X = X.Parent.Left then
X.Parent.Left := Y;
else
X.Parent.Right := Y;
end if;
Y.Left := X;
X.Parent := Y;
end Left_Rotate;
function Minimum (Node : in Node_Access; Nil : in Node_Access) return Node_Access
is begin
return Result : Node_Access := Node
do
while Result.Left /= Nil loop
Result := Result.Left;
end loop;
end return;
end Minimum;
procedure Right_Rotate (Tree : in out Pkg.Tree; X : in Node_Access)
is
-- [1] 13.2 Right-Rotate (T, x)
Nil : Node_Access renames Tree.Nil;
Y : constant Node_Access := X.Left;
begin
X.Left := Y.Right;
if Y.Right /= Nil then
Y.Right.Parent := X;
end if;
Y.Parent := X.Parent;
if X.Parent = Nil then
Tree.Root := Y;
elsif X = X.Parent.Right then
X.Parent.Right := Y;
else
X.Parent.Left := Y;
end if;
Y.Right := X;
X.Parent := Y;
end Right_Rotate;
procedure Transplant (T : in out Pkg.Tree; U, V : in Node_Access)
is
Nil : Node_Access renames T.Nil;
begin
-- [1] 13.4 RB-Transplant, 12.3 Transplant
if U.Parent = Nil then
T.Root := V;
elsif U = U.Parent.Left then
U.Parent.Left := V;
else
U.Parent.Right := V;
end if;
V.Parent := U.Parent;
end Transplant;
----------
-- Public subprograms, spec order
overriding procedure Finalize (Object : in out Tree)
is begin
if Object.Root /= null then
if Object.Root = Object.Nil then
Free (Object.Nil);
Object.Root := null;
else
Free_Tree (Object.Root, Object.Nil);
Free (Object.Nil);
end if;
end if;
end Finalize;
overriding procedure Initialize (Object : in out Tree)
is begin
Object.Nil := new Node;
Object.Nil.Color := Black;
Object.Root := Object.Nil;
end Initialize;
function Has_Element (Cursor : in Pkg.Cursor) return Boolean
is begin
return Cursor.Node /= null;
end Has_Element;
function Constant_Ref
(Container : aliased in Tree;
Position : in Cursor)
return Constant_Ref_Type
is
pragma Unreferenced (Container);
begin
return (Element => Position.Node.all.Element'Access);
end Constant_Ref;
function Constant_Ref
(Container : aliased in Tree;
Key : in Key_Type)
return Constant_Ref_Type
is
Node : constant Node_Access := Find (Container.Root, Key, Container.Nil);
begin
if Node = null then
raise Not_Found;
else
return (Element => Node.all.Element'Access);
end if;
end Constant_Ref;
function Variable_Ref
(Container : aliased in Tree;
Position : in Cursor)
return Variable_Ref_Type
is
pragma Unreferenced (Container);
begin
return (Element => Position.Node.all.Element'Access);
end Variable_Ref;
function Variable_Ref
(Container : aliased in Tree;
Key : in Key_Type)
return Variable_Ref_Type
is
Node : constant Node_Access := Find (Container.Root, Key, Container.Nil);
begin
if Node = null then
raise Not_Found;
else
return (Element => Node.all.Element'Access);
end if;
end Variable_Ref;
function Iterate (Tree : in Pkg.Tree'Class) return Iterator
is begin
return (Tree.Root, Tree.Nil);
end Iterate;
overriding function First (Iterator : in Pkg.Iterator) return Cursor
is
Nil : Node_Access renames Iterator.Nil;
Node : Node_Access := Iterator.Root;
begin
if Node = Nil then
return
(Node => null,
Direction => Unknown,
Left_Done => True,
Right_Done => True);
else
loop
exit when Node.Left = Nil;
Node := Node.Left;
end loop;
return
(Node => Node,
Direction => Ascending,
Left_Done => True,
Right_Done => False);
end if;
end First;
overriding function Next (Iterator : in Pkg.Iterator; Position : in Cursor) return Cursor
is
Nil : Node_Access renames Iterator.Nil;
begin
if Position.Direction /= Ascending then
raise Programmer_Error;
end if;
if Position.Node = null then
return
(Node => null,
Direction => Unknown,
Left_Done => True,
Right_Done => True);
elsif Position.Left_Done or Position.Node.Left = Nil then
if Position.Right_Done or Position.Node.Right = Nil then
if Position.Node.Parent = Nil then
return
(Node => null,
Direction => Unknown,
Left_Done => True,
Right_Done => True);
else
declare
Node : constant Node_Access := Position.Node.Parent;
Temp : constant Cursor :=
(Node => Node,
Direction => Ascending,
Left_Done => Node.Right = Position.Node or Node.Left = Position.Node,
Right_Done => Node.Right = Position.Node);
begin
if Temp.Right_Done then
return Next (Iterator, Temp);
else
return Temp;
end if;
end;
end if;
else
declare
Node : constant Node_Access := Position.Node.Right;
Temp : constant Cursor :=
(Node => Node,
Direction => Ascending,
Left_Done => Node.Left = Nil,
Right_Done => False);
begin
if Temp.Left_Done then
return Temp;
else
return Next (Iterator, Temp);
end if;
end;
end if;
else
declare
Node : constant Node_Access := Position.Node.Left;
Temp : constant Cursor :=
(Node => Node,
Direction => Ascending,
Left_Done => Node.Left = Nil,
Right_Done => False);
begin
if Temp.Left_Done then
return Temp;
else
return Next (Iterator, Temp);
end if;
end;
end if;
end Next;
overriding function Last (Iterator : in Pkg.Iterator) return Cursor
is
Nil : Node_Access renames Iterator.Nil;
Node : Node_Access := Iterator.Root;
begin
if Node = Nil then
return
(Node => null,
Direction => Unknown,
Left_Done => True,
Right_Done => True);
else
loop
exit when Node.Right = Nil;
Node := Node.Right;
end loop;
return
(Node => Node,
Direction => Descending,
Right_Done => True,
Left_Done => False);
end if;
end Last;
overriding function Previous (Iterator : in Pkg.Iterator; Position : in Cursor) return Cursor
is
Nil : Node_Access renames Iterator.Nil;
begin
if Position.Direction /= Descending then
raise Programmer_Error;
end if;
if Position.Node = null then
return
(Node => null,
Direction => Unknown,
Left_Done => True,
Right_Done => True);
elsif Position.Right_Done or Position.Node.Right = Nil then
if Position.Left_Done or Position.Node.Left = Nil then
if Position.Node.Parent = Nil then
return
(Node => null,
Direction => Unknown,
Left_Done => True,
Right_Done => True);
else
declare
Node : constant Node_Access := Position.Node.Parent;
Temp : constant Cursor :=
(Node => Node,
Direction => Descending,
Right_Done => Node.Left = Position.Node or Node.Right = Position.Node,
Left_Done => Node.Left = Position.Node);
begin
if Temp.Left_Done then
return Previous (Iterator, Temp);
else
return Temp;
end if;
end;
end if;
else
declare
Node : constant Node_Access := Position.Node.Left;
Temp : constant Cursor :=
(Node => Node,
Direction => Descending,
Right_Done => Node.Right = Nil,
Left_Done => False);
begin
if Temp.Right_Done then
return Temp;
else
return Previous (Iterator, Temp);
end if;
end;
end if;
else
declare
Node : constant Node_Access := Position.Node.Right;
Temp : constant Cursor :=
(Node => Node,
Direction => Descending,
Right_Done => Node.Right = Nil,
Left_Done => False);
begin
if Temp.Right_Done then
return Temp;
else
return Previous (Iterator, Temp);
end if;
end;
end if;
end Previous;
function Previous (Iterator : in Pkg.Iterator; Key : in Key_Type) return Cursor
is
Nil : Node_Access renames Iterator.Nil;
Node : Node_Access := Iterator.Root;
begin
while Node /= Nil loop
declare
Current_Key : Key_Type renames Pkg.Key (Node.Element);
begin
case Key_Compare (Key, Current_Key) is
when Equal =>
return Previous (Iterator, (Node, Descending, Right_Done => True, Left_Done => False));
when Less =>
if Node.Left = Nil then
return Previous (Iterator, (Node, Descending, Right_Done => True, Left_Done => True));
else
Node := Node.Left;
end if;
when Greater =>
if Node.Right = Nil then
return (Node, Descending, Right_Done => True, Left_Done => False);
else
Node := Node.Right;
end if;
end case;
end;
end loop;
return
(Node => null,
Direction => Unknown,
Left_Done => True,
Right_Done => True);
end Previous;
function Find
(Iterator : in Pkg.Iterator;
Key : in Key_Type;
Direction : in Direction_Type := Ascending)
return Cursor
is
Nil : Node_Access renames Iterator.Nil;
Node : constant Node_Access := Find (Iterator.Root, Key, Nil);
begin
if Node = null then
return
(Node => null,
Direction => Unknown,
Left_Done => True,
Right_Done => True);
else
return
(Node => Node,
Direction => Direction,
Left_Done =>
(case Direction is
when Ascending | Unknown => True,
when Descending => Node.Left = Nil),
Right_Done =>
(case Direction is
when Ascending => Node.Right = Nil,
when Descending | Unknown => True));
end if;
end Find;
function Find_In_Range
(Iterator : in Pkg.Iterator;
Direction : in Known_Direction_Type;
First, Last : in Key_Type)
return Cursor
is
Nil : Node_Access renames Iterator.Nil;
Node : Node_Access := Iterator.Root;
Candidate : Node_Access := null; -- best result found so far
begin
while Node /= Nil loop
declare
Current_Key : Key_Type renames Key (Node.Element);
begin
case Direction is
when Ascending =>
case Key_Compare (First, Current_Key) is
when Equal =>
return (Node, Ascending, Right_Done => False, Left_Done => True);
when Less =>
if Node.Left = Nil then
case Key_Compare (Current_Key, Last) is
when Less | Equal =>
return (Node, Ascending, Right_Done => False, Left_Done => True);
when Greater =>
if Candidate = null then
return No_Element;
else
return (Candidate, Ascending, Right_Done => False, Left_Done => True);
end if;
end case;
else
case Key_Compare (Last, Current_Key) is
when Greater | Equal =>
Candidate := Node;
when Less =>
null;
end case;
Node := Node.Left;
end if;
when Greater =>
if Node.Right = Nil then
if Candidate = null then
return No_Element;
else
return (Candidate, Ascending, Right_Done => False, Left_Done => True);
end if;
else
Node := Node.Right;
end if;
end case;
when Descending =>
if Last = Current_Key then
return (Node, Descending, Right_Done => True, Left_Done => False);
else
case Key_Compare (Last, Current_Key) is
when Greater =>
if Node.Right = Nil then
case Key_Compare (Current_Key, First) is
when Greater | Equal =>
return (Node, Descending, Right_Done => True, Left_Done => False);
when Less =>
if Candidate = null then
return No_Element;
else
return (Candidate, Ascending, Right_Done => False, Left_Done => True);
end if;
end case;
else
case Key_Compare (First, Current_Key) is
when Less | Equal =>
Candidate := Node;
when Greater =>
null;
end case;
Node := Node.Right;
end if;
when Equal | Less =>
if Node.Left = Nil then
if Candidate = null then
return No_Element;
else
return (Candidate, Ascending, Right_Done => False, Left_Done => True);
end if;
else
Node := Node.Left;
end if;
end case;
end if;
end case;
end;
end loop;
return No_Element;
end Find_In_Range;
function Count (Tree : in Pkg.Tree) return Ada.Containers.Count_Type
is begin
if Tree.Root = Tree.Nil then
return 0;
else
return Count_Tree (Tree.Root, Tree.Nil);
end if;
end Count;
function Present (Container : in Tree; Key : in Key_Type) return Boolean
is
Nil : Node_Access renames Container.Nil;
Node : Node_Access := Container.Root;
begin
while Node /= Nil loop
case Key_Compare (Key, Pkg.Key (Node.Element)) is
when Equal =>
return True;
when Less =>
Node := Node.Left;
when Greater =>
Node := Node.Right;
end case;
end loop;
return False;
end Present;
function Insert (Tree : in out Pkg.Tree; Element : in Element_Type) return Cursor
is
-- [1] 13.3 RB-Insert (T, z)
Nil : Node_Access renames Tree.Nil;
Z : Node_Access := new Node'(Element, Nil, Nil, Nil, Red);
Key_Z : constant Key_Type := Key (Z.Element);
Y : Node_Access := Nil;
X : Node_Access := Tree.Root;
Result : Node_Access;
Compare_Z_Y : Compare_Result;
begin
Nil.Parent := null;
Nil.Left := null;
Nil.Right := null;
while X /= Nil loop
Y := X;
Compare_Z_Y := Key_Compare (Key_Z, Key (X.Element));
case Compare_Z_Y is
when Less =>
X := X.Left;
when Equal | Greater =>
X := X.Right;
end case;
end loop;
Z.Parent := Y;
if Y = Nil then
Tree.Root := Z;
else
case Compare_Z_Y is
when Less =>
Y.Left := Z;
when Equal | Greater =>
Y.Right := Z;
end case;
end if;
Result := Z;
if Z = Tree.Root then
Z.Color := Black;
else
Insert_Fixup (Tree, Z);
end if;
return
(Node => Result,
Direction => Unknown,
Left_Done => True,
Right_Done => True);
end Insert;
procedure Insert (Tree : in out Pkg.Tree; Element : in Element_Type)
is
Temp : Cursor := Insert (Tree, Element);
pragma Unreferenced (Temp);
begin
null;
end Insert;
procedure Delete (Tree : in out Pkg.Tree; Position : in out Cursor)
is
Nil : Node_Access renames Tree.Nil;
T : Pkg.Tree renames Tree;
Z : constant Node_Access :=
(if Position.Node = null then raise Parameter_Error else Position.Node);
Y : Node_Access := Z;
Y_Orig_Color : Color := Y.Color;
X : Node_Access;
begin
-- Catch logic errors in use of Nil
Nil.Parent := null;
Nil.Left := null;
Nil.Right := null;
-- [1] 13.4 RB-Delete.
if Z.Left = Nil then
X := Z.Right;
Transplant (T, Z, Z.Right);
elsif Z.Right = Nil then
X := Z.Left;
Transplant (T, Z, Z.Left);
else
Y := Minimum (Z.Right, Nil);
Y_Orig_Color := Y.Color;
X := Y.Right;
if Y.Parent = Z then
X.Parent := Y;
-- This is already true unless X = Nil, in which case delete_fixup
-- needs the info.
else
Transplant (T, Y, Y.Right);
Y.Right := Z.Right;
Y.Right.Parent := Y;
-- This is already true unless Y.Right = Nil, in which case
-- delete_fixup needs the info.
end if;
Transplant (T, Z, Y);
Y.Left := Z.Left;
Y.Left.Parent := Y;
-- This is already true unless Y.Left = Nil, in which case
-- delete_fixup needs the info.
Y.Color := Z.Color;
end if;
if Y_Orig_Color = Black then
Delete_Fixup (T, X);
end if;
Free (Position.Node);
end Delete;
end SAL.Gen_Unbounded_Definite_Red_Black_Trees;
|
--
-- Copyright 2018 The wookey project team <wookey@ssi.gouv.fr>
-- - Ryad Benadjila
-- - Arnauld Michelizza
-- - Mathieu Renard
-- - Philippe Thierry
-- - Philippe Trebuchet
--
-- 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 ada.unchecked_conversion;
with ewok.ipc; use ewok.ipc;
with ewok.tasks; use ewok.tasks;
with ewok.tasks_shared; use ewok.tasks_shared;
with ewok.sanitize;
with ewok.perm;
with ewok.sleep;
with ewok.debug;
with ewok.mpu;
with types.c; use types.c;
package body ewok.syscalls.ipc
with spark_mode => off
is
--pragma debug_policy (IGNORE);
procedure ipc_do_recv
(caller_id : in ewok.tasks_shared.t_task_id;
params : in t_parameters;
blocking : in boolean;
mode : in ewok.tasks_shared.t_task_mode)
is
ep : ewok.ipc.t_endpoint_access;
sender_a : ewok.tasks.t_task_access;
----------------
-- Parameters --
----------------
-- Who is the sender ?
expected_sender : ewok.ipc.t_extended_task_id
with address => to_address (params(1));
-- Listening to any id ?
listen_any : boolean;
-- Listening to a specific id ?
id_sender : ewok.tasks_shared.t_task_id;
-- Buffer size
size : unsigned_8
with address => to_address (params(2));
-- Input buffer
buf : c_buffer (1 .. unsigned_32 (size))
with address => to_address (params(3));
begin
--if expected_sender = ewok.ipc.ANY_APP then
-- pragma DEBUG (debug.log (debug.DEBUG, "recv(): "
-- & ewok.tasks.tasks_list(caller_id).name & " <- ANY");
--else
-- pragma DEBUG (debug.log (debug.DEBUG, "recv(): "
-- & ewok.tasks.tasks_list(caller_id).name & " <- "
-- & ewok.tasks.tasks_list(ewok.ipc.to_task_id(expected_sender)).name);
--end if;
--------------------------
-- Verifying parameters --
--------------------------
if mode /= TASK_MODE_MAINTHREAD then
pragma DEBUG (debug.log (debug.ERROR,
ewok.tasks.tasks_list(caller_id).name
& ": recv(): IPCs in ISR mode not allowed!"));
goto ret_denied;
end if;
if not expected_sender'valid then
pragma DEBUG (debug.log (debug.ERROR,
ewok.tasks.tasks_list(caller_id).name
& ": recv(): invalid id_sender"));
goto ret_inval;
end if;
-- Task initialization is complete ?
if not ewok.tasks.is_init_done (caller_id) then
pragma DEBUG (debug.log (debug.ERROR,
ewok.tasks.tasks_list(caller_id).name
& ": recv(): initialization not completed"));
goto ret_denied;
end if;
-- Does &size is in the caller address space ?
if not ewok.sanitize.is_word_in_data_slot
(to_system_address (size'address), caller_id, mode)
then
pragma DEBUG (debug.log (debug.ERROR,
ewok.tasks.tasks_list(caller_id).name
& ": recv(): 'size' parameter not in task's address space"));
goto ret_inval;
end if;
-- Does &expected_sender is in the caller address space ?
if not ewok.sanitize.is_word_in_data_slot
(to_system_address (expected_sender'address), caller_id, mode)
then
pragma DEBUG (debug.log (debug.ERROR,
ewok.tasks.tasks_list(caller_id).name
& ": recv(): 'expected_sender' parameter not in task's address space"));
goto ret_inval;
end if;
-- Does &buf is in the caller address space ?
if not ewok.sanitize.is_range_in_data_slot
(to_system_address (buf'address), unsigned_32 (size), caller_id, mode)
then
pragma DEBUG (debug.log (debug.ERROR,
ewok.tasks.tasks_list(caller_id).name
& ": recv(): 'buffer' parameter not in task's address space"));
goto ret_inval;
end if;
-- The expected sender might be a particular task or any of them
if expected_sender = ewok.ipc.ANY_APP then
listen_any := true;
else
id_sender := ewok.ipc.to_task_id (expected_sender);
listen_any := false;
end if;
-- When the sender is a task, we have to do some additional checks
if not listen_any then
-- Is the sender is an existing user task?
if not ewok.tasks.is_real_user (id_sender) then
pragma DEBUG (debug.log (debug.ERROR,
ewok.tasks.tasks_list(caller_id).name
& ": recv(): invalid id_sender"));
goto ret_inval;
end if;
-- Defensive programming test: should *never* be true
if ewok.tasks.get_state (id_sender, TASK_MODE_MAINTHREAD)
= TASK_STATE_EMPTY
then
raise program_error;
end if;
-- A task can't send a message to itself
if caller_id = id_sender then
pragma DEBUG (debug.log (debug.ERROR,
ewok.tasks.tasks_list(caller_id).name
& ": recv(): sender and receiver are the same"));
goto ret_inval;
end if;
-- Is the sender in the same domain?
#if CONFIG_KERNEL_DOMAIN
if not ewok.perm.is_same_domain (id_sender, caller_id) then
pragma DEBUG (debug.log (debug.ERROR,
ewok.tasks.tasks_list(caller_id).name
& ": recv(): sender's domain not granted"));
goto ret_denied;
end if;
#end if;
-- Are ipc granted?
if not ewok.perm.ipc_is_granted (id_sender, caller_id) then
pragma DEBUG (debug.log (debug.ERROR,
ewok.tasks.tasks_list(caller_id).name
& ": recv(): not granted to listen task "
& ewok.tasks.tasks_list(id_sender).name));
goto ret_denied;
end if;
-- Checks are ok
sender_a := ewok.tasks.get_task (id_sender);
end if;
------------------------------
-- Defining an IPC EndPoint --
------------------------------
ep := NULL;
-- Special case: listening to ANY_APP and already have a pending message
if listen_any then
for i in ewok.tasks.tasks_list(caller_id).ipc_endpoints'range loop
if ewok.tasks.tasks_list(caller_id).ipc_endpoints(i) /= NULL
and then
ewok.tasks.tasks_list(caller_id).ipc_endpoints(i).state
= ewok.ipc.WAIT_FOR_RECEIVER
and then
ewok.ipc.to_task_id
(ewok.tasks.tasks_list(caller_id).ipc_endpoints(i).to)
= caller_id
then
ep := ewok.tasks.tasks_list(caller_id).ipc_endpoints(i);
exit;
end if;
end loop;
-- Special case: listening to a given sender and already have a pending
-- message
else
if ewok.tasks.tasks_list(caller_id).ipc_endpoints(id_sender) /= NULL
and then
ewok.tasks.tasks_list(caller_id).ipc_endpoints(id_sender).state
= ewok.ipc.WAIT_FOR_RECEIVER
and then
ewok.ipc.to_task_id (ewok.tasks.tasks_list(caller_id).ipc_endpoints(id_sender).to)
= caller_id
then
ep := ewok.tasks.tasks_list(caller_id).ipc_endpoints(id_sender);
end if;
end if;
-------------------------
-- Reading the message --
-------------------------
--
-- No pending message to read: we terminate here
--
if ep = NULL then
-- Waking up idle senders
if not listen_any and then
ewok.tasks.get_state (sender_a.all.id, TASK_MODE_MAINTHREAD)
= TASK_STATE_IDLE
then
ewok.tasks.set_state
(sender_a.all.id, TASK_MODE_MAINTHREAD, TASK_STATE_RUNNABLE);
end if;
-- Receiver is blocking until it receives a message or it returns
-- E_SYS_BUSY
if blocking then
ewok.tasks.set_state (caller_id,
TASK_MODE_MAINTHREAD,
TASK_STATE_IPC_RECV_BLOCKED);
return;
else
goto ret_busy;
end if;
end if;
-- The syscall returns the sender ID
expected_sender := ep.all.from;
id_sender := ewok.ipc.to_task_id (ep.all.from);
-- Defensive programming test: should *never* happen
if not ewok.tasks.is_real_user (id_sender) then
raise program_error;
end if;
sender_a := ewok.tasks.get_task (id_sender);
-- Copying the message in the receiver's buffer
if ep.all.size > size then
pragma DEBUG (debug.log (debug.ERROR,
ewok.tasks.tasks_list(caller_id).name
& ": recv(): IPC message overflows, buffer is too small"));
goto ret_inval;
end if;
-- Returning the data size
size := ep.all.size;
-- Copying data
-- Note: we don't use 'first attribute. By convention, array indexes
-- begin with '1' value
buf(1 .. unsigned_32 (size)) := ep.all.data(1 .. unsigned_32 (size));
-- The EndPoint is ready for another use
ep.all.state := ewok.ipc.READY;
ep.all.size := 0;
-- Free sender from it's blocking state
case ewok.tasks.get_state (id_sender, TASK_MODE_MAINTHREAD) is
when TASK_STATE_IPC_WAIT_ACK =>
-- The kernel need to update sender syscall's return value, but
-- as we are currently managing the receiver's syscall, sender's
-- data region in memory can not be accessed (even by the kernel).
-- The following temporary open the access to every task's data
-- region, perform the writing, and then restore the MPU.
ewok.mpu.enable_unrestricted_kernel_access;
set_return_value (id_sender, TASK_MODE_MAINTHREAD, SYS_E_DONE);
ewok.mpu.disable_unrestricted_kernel_access;
ewok.tasks.set_state
(id_sender, TASK_MODE_MAINTHREAD, TASK_STATE_RUNNABLE);
when TASK_STATE_IPC_SEND_BLOCKED =>
-- The sender will reexecute the SVC instruction to fulfill its syscall
ewok.tasks.set_state
(id_sender, TASK_MODE_MAINTHREAD, TASK_STATE_FORCED);
sender_a.all.ctx.frame_a.all.PC :=
sender_a.all.ctx.frame_a.all.PC - 2;
when others =>
null;
end case;
set_return_value (caller_id, mode, SYS_E_DONE);
ewok.tasks.set_state (caller_id, mode, TASK_STATE_RUNNABLE);
return;
<<ret_inval>>
set_return_value (caller_id, mode, SYS_E_INVAL);
ewok.tasks.set_state (caller_id, mode, TASK_STATE_RUNNABLE);
return;
<<ret_busy>>
set_return_value (caller_id, mode, SYS_E_BUSY);
ewok.tasks.set_state (caller_id, mode, TASK_STATE_RUNNABLE);
return;
<<ret_denied>>
set_return_value (caller_id, mode, SYS_E_DENIED);
ewok.tasks.set_state (caller_id, mode, TASK_STATE_RUNNABLE);
return;
end ipc_do_recv;
procedure ipc_do_send
(caller_id : in ewok.tasks_shared.t_task_id;
params : in out t_parameters;
blocking : in boolean;
mode : in ewok.tasks_shared.t_task_mode)
is
ep : ewok.ipc.t_endpoint_access;
receiver_a : ewok.tasks.t_task_access;
ok : boolean;
----------------
-- Parameters --
----------------
-- Who is the receiver ?
id_receiver : ewok.tasks_shared.t_task_id
with address => params(1)'address;
-- Buffer size
size : unsigned_8
with address => params(2)'address;
-- Output buffer
buf : c_buffer (1 .. unsigned_32 (size))
with address => to_address (params(3));
begin
--pragma DEBUG (debug.log (debug.DEBUG, "send(): "
-- & ewok.tasks.tasks_list(caller_id).name & " -> "
-- & ewok.tasks.tasks_list(id_receiver).name);
--------------------------
-- Verifying parameters --
--------------------------
if mode /= TASK_MODE_MAINTHREAD then
pragma DEBUG (debug.log (debug.ERROR,
ewok.tasks.tasks_list(caller_id).name
& ": send(): making IPCs while in ISR mode is not allowed!"));
goto ret_denied;
end if;
if not id_receiver'valid then
pragma DEBUG (debug.log (debug.ERROR,
ewok.tasks.tasks_list(caller_id).name
& ": send(): invalid id_receiver"));
goto ret_inval;
end if;
-- Task initialization is complete ?
if not is_init_done (caller_id) then
pragma DEBUG (debug.log (debug.ERROR,
ewok.tasks.tasks_list(caller_id).name
& ": send(): initialization not completed"));
goto ret_denied;
end if;
-- Does &buf is in the caller address space ?
if not ewok.sanitize.is_range_in_data_slot
(to_unsigned_32 (buf'address), unsigned_32 (size), caller_id, mode)
then
pragma DEBUG (debug.log (debug.ERROR,
ewok.tasks.tasks_list(caller_id).name
& ": send(): 'buffer' not in caller space"));
goto ret_inval;
end if;
-- Verifying that the receiver id corresponds to a user application
if not ewok.tasks.is_real_user (id_receiver) then
pragma DEBUG (debug.log (debug.ERROR,
ewok.tasks.tasks_list(caller_id).name
& ": send(): id_receiver must be a user task"));
goto ret_inval;
end if;
receiver_a := ewok.tasks.get_task (id_receiver);
-- Defensive programming test: should *never* be true
if ewok.tasks.get_state (id_receiver, TASK_MODE_MAINTHREAD)
= TASK_STATE_EMPTY
then
raise program_error;
end if;
-- A task can't send a message to itself
if caller_id = id_receiver then
pragma DEBUG (debug.log (debug.ERROR,
ewok.tasks.tasks_list(caller_id).name
& ": send(): receiver and sender are the same"));
goto ret_inval;
end if;
-- Is size valid ?
if size > ewok.ipc.MAX_IPC_MSG_SIZE then
pragma DEBUG (debug.log (debug.ERROR,
ewok.tasks.tasks_list(caller_id).name
& ": send(): invalid size"));
goto ret_inval;
end if;
--
-- Verifying permissions
--
#if CONFIG_KERNEL_DOMAIN
if not ewok.perm.is_same_domain (id_receiver, caller_id) then
pragma DEBUG (debug.log (debug.ERROR,
ewok.tasks.tasks_list(caller_id).name
& ": send() to "
& ewok.tasks.tasks_list(id_receiver).name
& ": domain not granted"));
goto ret_denied;
end if;
#end if;
if not ewok.perm.ipc_is_granted (caller_id, id_receiver) then
pragma DEBUG (debug.log (debug.ERROR,
ewok.tasks.tasks_list(caller_id).name
& ": send() to "
& ewok.tasks.tasks_list(id_receiver).name
& " not granted"));
goto ret_denied;
end if;
------------------------------
-- Defining an IPC EndPoint --
------------------------------
ep := NULL;
-- Creating a new EndPoint between the sender and the receiver
if ewok.tasks.tasks_list(caller_id).ipc_endpoints(id_receiver) = NULL
then
-- Defensive programming test: should *never* happen
if receiver_a.all.ipc_endpoints(caller_id) /= NULL then
raise program_error;
end if;
ewok.ipc.get_endpoint (ep, ok);
if not ok then
-- FIXME
debug.panic ("send(): EndPoint starvation !O_+");
end if;
ewok.tasks.tasks_list(caller_id).ipc_endpoints(id_receiver) := ep;
receiver_a.all.ipc_endpoints(caller_id) := ep;
else
ep := ewok.tasks.tasks_list(caller_id).ipc_endpoints(id_receiver);
end if;
-----------------------
-- Sending a message --
-----------------------
-- Wake up idle receivers
if ewok.sleep.is_sleeping (receiver_a.id) then
ewok.sleep.try_waking_up (receiver_a.id);
elsif receiver_a.all.state = TASK_STATE_IDLE then
ewok.tasks.set_state
(receiver_a.all.id, TASK_MODE_MAINTHREAD, TASK_STATE_RUNNABLE);
end if;
-- The receiver has already a pending message and the endpoint is already
-- in use.
if ep.all.state = ewok.ipc.WAIT_FOR_RECEIVER and
ewok.ipc.to_task_id (ep.all.to) = receiver_a.all.id
then
if blocking then
ewok.tasks.set_state
(caller_id, TASK_MODE_MAINTHREAD, TASK_STATE_IPC_SEND_BLOCKED);
#if CONFIG_IPC_SCHED_VIOL
if ewok.tasks.get_state (receiver_a.all.id, TASK_MODE_MAINTHREAD)
= TASK_STATE_RUNNABLE
or
ewok.tasks.get_state (receiver_a.all.id, TASK_MODE_MAINTHREAD)
= TASK_STATE_IDLE
then
ewok.tasks.set_state
(receiver_a.all.id, TASK_MODE_MAINTHREAD, TASK_STATE_FORCED);
end if;
#end if;
return;
else
goto ret_busy;
end if;
end if;
if ep.all.state /= ewok.ipc.READY then
pragma DEBUG (debug.log (debug.ERROR,
ewok.tasks.tasks_list(caller_id).name
& ": send(): invalid endpoint state - maybe a dead lock"));
goto ret_denied;
end if;
ep.all.from := ewok.ipc.to_ext_task_id (caller_id);
ep.all.to := ewok.ipc.to_ext_task_id (receiver_a.all.id);
-- We copy the message in the IPC buffer
-- Note: we don't use 'first attribute. By convention, array indexes
-- begin with '1' value
ep.all.size := size;
ep.all.data(1 .. unsigned_32 (size)) := buf(1 .. unsigned_32 (size));
-- Adjusting the EndPoint state
ep.all.state := ewok.ipc.WAIT_FOR_RECEIVER;
-- If the receiver was blocking, it can be 'freed' from its blocking
-- state.
if ewok.tasks.get_state (receiver_a.all.id, TASK_MODE_MAINTHREAD)
= TASK_STATE_IPC_RECV_BLOCKED
then
-- The receiver will reexecute the SVC instruction to fulfill its syscall
ewok.tasks.set_state
(receiver_a.all.id, TASK_MODE_MAINTHREAD, TASK_STATE_FORCED);
-- Unrestrict kernel access to memory to change a value located
-- in the receiver's stack frame
ewok.mpu.enable_unrestricted_kernel_access;
receiver_a.all.ctx.frame_a.all.PC :=
receiver_a.all.ctx.frame_a.all.PC - 2;
ewok.mpu.disable_unrestricted_kernel_access;
end if;
if blocking then
ewok.tasks.set_state
(caller_id, TASK_MODE_MAINTHREAD, TASK_STATE_IPC_WAIT_ACK);
#if CONFIG_IPC_SCHED_VIOL
if receiver_a.all.state = TASK_STATE_RUNNABLE or
receiver_a.all.state = TASK_STATE_IDLE
then
ewok.tasks.set_state
(receiver_a.all.id, TASK_MODE_MAINTHREAD, TASK_STATE_FORCED);
end if;
#end if;
return;
else
set_return_value (caller_id, mode, SYS_E_DONE);
ewok.tasks.set_state (caller_id, mode, TASK_STATE_RUNNABLE);
return;
end if;
<<ret_inval>>
set_return_value (caller_id, mode, SYS_E_INVAL);
ewok.tasks.set_state (caller_id, mode, TASK_STATE_RUNNABLE);
return;
<<ret_busy>>
set_return_value (caller_id, mode, SYS_E_BUSY);
ewok.tasks.set_state (caller_id, mode, TASK_STATE_RUNNABLE);
return;
<<ret_denied>>
set_return_value (caller_id, mode, SYS_E_DENIED);
ewok.tasks.set_state (caller_id, mode, TASK_STATE_RUNNABLE);
return;
end ipc_do_send;
procedure sys_ipc
(caller_id : in ewok.tasks_shared.t_task_id;
params : in out t_parameters;
mode : in ewok.tasks_shared.t_task_mode)
is
syscall : t_syscalls_ipc
with address => params(0)'address;
begin
if not syscall'valid then
set_return_value (caller_id, mode, SYS_E_INVAL);
ewok.tasks.set_state (caller_id, mode, TASK_STATE_RUNNABLE);
return;
end if;
case syscall is
when IPC_RECV_SYNC =>
ipc_do_recv (caller_id, params, true, mode);
when IPC_SEND_SYNC =>
ipc_do_send (caller_id, params, true, mode);
when IPC_RECV_ASYNC =>
ipc_do_recv (caller_id, params, false, mode);
when IPC_SEND_ASYNC =>
ipc_do_send (caller_id, params, false, mode);
end case;
end sys_ipc;
end ewok.syscalls.ipc;
|
-- -----------------------------------------------------------------------------
-- smk, the smart make
-- © 2018 Lionel Draghi <lionel.draghi@free.fr>
-- SPDX-License-Identifier: APSL-2.0
-- -----------------------------------------------------------------------------
-- 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: Smk.Cmd_Line body
--
-- Implementation Notes:
--
-- Portability Issues:
--
-- Anticipated Changes:
--
-- -----------------------------------------------------------------------------
with Smk.IO;
with Smk.Settings;
with Ada.Command_Line;
with Ada.Directories;
separate (Smk.Main)
procedure Analyze_Cmd_Line is
-- --------------------------------------------------------------------------
Arg_Counter : Positive := 1;
-- --------------------------------------------------------------------------
-- Procedure: Next_Arg
-- --------------------------------------------------------------------------
procedure Next_Arg is
begin
Arg_Counter := Arg_Counter + 1;
end Next_Arg;
-- --------------------------------------------------------------------------
-- Procedure: Put_Version
-- --------------------------------------------------------------------------
procedure Put_Version is
begin
IO.Put_Line (Settings.Smk_Version);
end Put_Version;
begin
if Ada.Command_Line.Argument_Count < 1 then
Put_Help;
return;
end if;
while Arg_Counter <= Ada.Command_Line.Argument_Count loop
declare
Opt : constant String := Ada.Command_Line.Argument (Arg_Counter);
begin
if Opt = "-a" or Opt = "--always-make" then
Settings.Always_Make := True;
Next_Arg;
elsif Opt = "-e" or Opt = "--explain" then
Settings.Explain := True;
Next_Arg;
elsif Opt = "-n" or Opt = "--dry-run" then
Settings.Dry_Run := True;
Next_Arg;
elsif Opt = "-i" or Opt = "--ignore-errors" then
Settings.Ignore_Errors := True;
Next_Arg;
elsif Opt = "-lm" or Opt = "--list_makefile" then
Settings.List_Makefile := True;
Next_Arg;
elsif Opt = "-ls" or Opt = "--list_saved_run" then
Settings.List_Saved_Run := True;
Next_Arg;
elsif Opt = "-lt" or Opt = "--list_targets" then
Settings.List_Targets := True;
Next_Arg;
elsif Opt = "--clean" then
Settings.Clean_Smk_Files := True;
Next_Arg;
elsif Opt = "-We" or Opt = "--Warnings=error" then
Settings.Warnings_As_Errors := True;
Next_Arg;
elsif Opt = "-v" or Opt = "--verbose" then
Settings.Verbosity := Verbose;
Next_Arg;
elsif Opt = "-q" or Opt = "--quiet" then
Settings.Verbosity := Quiet;
Next_Arg;
elsif Opt = "--version" then
Put_Version;
Next_Arg;
elsif Opt = "-h" or Opt = "--help" then
Put_Help;
Next_Arg;
elsif Opt = "-d" then
-- undocumented option
Settings.Verbosity := Debug;
Next_Arg;
elsif Ada.Directories.Exists (Opt) then
-- should be the Makefile
Settings.Set_Makefile_Name (Opt);
Next_Arg;
else
Put_Error ("Unknown Makefile or unknow option "
& Opt, With_Help => False);
end if;
if IO.Some_Error then return; end if;
-- No need to further analyze command line, or to do
-- Options_Coherency_Tests.
end;
end loop;
-- Options_Coherency_Tests;
end Analyze_Cmd_Line;
|
-- SPDX-FileCopyrightText: 2019-2021 Max Reznik <reznikmm@gmail.com>
--
-- SPDX-License-Identifier: MIT
-------------------------------------------------------------
with Program.Compilation_Units;
with Program.Elements.Expressions;
with Program.Library_Environments;
with Program.Symbol_Lists;
with Program.Visibility;
with Program.Cross_Reference_Updaters;
with Program.Simple_Resolvers;
private package Program.Resolvers is
pragma Preelaborate;
procedure Resolve_Names
(Unit : not null Program.Compilation_Units.Compilation_Unit_Access;
Unit_Name_Resolver : not null
Program.Simple_Resolvers.Simple_Resolver_Access;
Lists : in out Program.Symbol_Lists.Symbol_List_Table'Class;
Context : not null Program.Visibility.Context_Access;
Library : in out Program.Library_Environments.Library_Environment;
Setter : not null
Program.Cross_Reference_Updaters.Cross_Reference_Updater_Access);
end Program.Resolvers;
|
-- License: ISC
with Ada.Text_IO;
package body JSA.Generic_Optional_Value is
function "+" (Item : in Element) return Instance is
begin
return (Set => True,
Value => Item);
end "+";
function "+" (Item : in Instance) return Element is
begin
return Item.Value;
end "+";
function "=" (Left : in Element;
Right : in Instance) return Boolean is
begin
return Right.Set and then Left = Right.Value;
end "=";
function "=" (Left : in Instance;
Right : in Element) return Boolean is
begin
return Left.Set and then Left.Value = Right;
end "=";
function Image (Item : in Instance) return String is
begin
case Item.Set is
when True =>
return Image (Item.Value);
when False =>
return "";
end case;
end Image;
function Value (Item : in String) return Instance is
begin
if Item = "" then
return (Set => False);
else
return (Set => True,
Value => Value (Item));
end if;
exception
when others =>
Ada.Text_IO.Put
(File => Ada.Text_IO.Current_Error,
Item => "JSA.Generic_Optional_Value.Value (""" & Item & """);");
raise;
end Value;
protected body Buffer is separate;
end JSA.Generic_Optional_Value;
|
pragma Ada_2012;
pragma Style_Checks (Off);
with Interfaces.C; use Interfaces.C;
with bits_types_struct_FILE_h;
package bits_types_u_FILE_h is
subtype uu_FILE is bits_types_struct_FILE_h.u_IO_FILE; -- /usr/include/bits/types/__FILE.h:5
end bits_types_u_FILE_h;
|
pragma Ada_2012;
with Ada.Text_IO; use Ada.Text_IO;
package body Base is
procedure caller (BC : Base_Interface'Class) is
begin
Put_Line("BC.caller, calling print");
BC.print; -- should dispatch here
end caller;
overriding procedure print (BF : Base_Fixed) is
begin
Put(" fixed.print, elements = [");
for i in 1 .. BF.N - 1 loop
Put(BF.elements(i)'Img & ", ");
end loop;
Put_Line(BF.elements(BF.N)'Img & "];");
end print;
function "=" (Left, Right : Base_Fixed) return Boolean is
begin
if Left.N /= Right.N then
return False;
else
for i in 1 .. Left.N loop
if Left.elements(i) /= Right.elements(i) then
return False;
end if;
end loop;
end if;
return True;
end "=";
function set_idx_fixed (e : Index) return Base_Fixed5 is
begin
return BF : Base_Fixed5 do
for i in Index range 1 .. 5 loop
BF.elements(i) := Element_Type(e);
end loop;
end return;
end set_idx_fixed;
----------------------------
-- Vector
overriding procedure print(BD : Base_Dynamic) is
N : Index := Index(BD.vec.Length);
begin
Put(" vector.print, elements = [");
for i in 1 .. N - 1 loop
Put(Element_Type'Image(BD.vec(i)) & ", ");
end loop;
Put_Line(Element_Type'Image(BD.vec(N)) & "];");
end print;
function set_idx_dynamic (e : Index) return Base_Dynamic is
BD : Base_Dynamic := (vec => ACV.To_Vector(5));
begin
Put(" set, e=");
for i in Index range 1 .. 5 loop
Put(i'Img);
BD.vec(i) := Element_Type(e);
end loop;
Put(";");
return BD;
end set_idx_dynamic;
----------------------------
-- Vector
overriding procedure print (BV : Base_Vector) is
N : Index := Index(BV.Length);
begin
Put(" vector.print, elements = [");
for i in 1 .. N - 1 loop
Put(Element_Type'Image(BV(i)) & ", ");
end loop;
Put_Line(Element_Type'Image(BV(N)) & "];");
end print;
function set_idx_vector (e : Index) return Base_Vector is
BV : Base_Vector := To_Vector(5);
begin
Put(" set, e=");
for i in Index range 1 .. 5 loop
Put(i'Img);
BV(i) := Element_Type(e);
end loop;
Put(";");
return BV;
end set_idx_vector;
end Base;
|
with
Ada.Unchecked_Conversion;
Package Body Aids.Utilities is
Generic
Type Source_Index is (<>);
Type Source_Element is limited private;
Type Source_Array is Array (Source_Index range <>) of Source_Element;
Type Target_Index is (<>);
Type Target_Element is limited private;
Type Target_Array is Array (Target_Index range <>) of Target_Element;
Function Convert_Array(Object : Source_Array) return Target_Array;
Function Convert_Array(Object : Source_Array) return Target_Array is
Pragma Assert( Target_Element'Size = Source_Element'Size,
"Target and Source element-sizes must match." );
--- WARNING: NULL RANGE, this is incorrect. ---
Subtype Target_Range is Target_Index range
Target_Index'Last..Target_Index'First;
Subtype Constrained_Source is Source_Array(Object'Range);
Subtype Constrained_Target is Target_Array(Target_Range);
Function Convert is new Ada.Unchecked_Conversion(
Source => Constrained_Source,
Target => Constrained_Target
);
Begin
Return Item : Constant Target_Array := Convert( Object ) do
Raise Program_Error with
"I've forgotten how to grab the Target range via Source's range.";
-- TODO: Fix this and make
end return;
End Convert_Array;
function Chunk_Image(Chunk: Stream_Element_Array) return String
renames Chunk_To_String;
function String_To_Chunk(S: in String) return Stream_Element_Array is
First : Constant Stream_Element_Offset:= Stream_Element_Offset(S'First);
Last : Constant Stream_Element_Offset:= Stream_Element_Offset(S'Last);
begin
Return Result: Stream_Element_Array(First..Last) do
for Index in Result'Range loop
Result(Index) :=
Stream_Element(Character'Pos(S(Positive(Index))));
end loop;
end return;
end;
function Chunk_To_String(C: in Stream_Element_Array) return String is
Pragma Assert( Stream_Element'Size = Character'Size,
"Stream_Element and Character nust have equal sizes."
);
Subtype Constrained_Array is Stream_Element_Array(C'Range);
Subtype Constrained_String is String(1..C'Length);
Function Convert is new Ada.Unchecked_Conversion(
Source => Constrained_Array,
Target => Constrained_String
);
begin
return Convert( C );
end;
Function Chunk_Debug(C: in Stream_Element_Array) return String is
Pragma Assert( Stream_Element'Size = Character'Size,
"Stream_Element and Character nust have equal sizes."
);
Pragma Assert( Character'Size = 8,
"Assuming 8-bit character."
);
Type Nybble is range 16#0#..16#F#
with Size => 4;
Function Hex( Item : Nybble ) return Character is
(case Item is
when 16#0#..16#9# =>
Character'Val(Character'Pos('0') + Natural(Item)),
when 16#A#..16#F# =>
Character'Val(Character'Pos('A') + Natural(Item-16#A#))
);
Type Char is record
Hi, Lo : Nybble;
end record
with Pack, Size => 8;
Function Convert is new Ada.Unchecked_Conversion(
Source => Stream_Element,
Target => Char
);
Begin
Return Result : String(1..2*C'Length) do
For Index in C'Range loop
Declare
Nybbles : Char renames Convert( C(Index) );
Result_Index : Constant Positive := 2*Natural(Index-C'First) + Result'First;
Hi : Character renames Result(Result_Index);
Lo : Character renames Result(Result_Index+1);
Begin
Hi:= Hex( Nybbles.Hi );
Lo:= Hex( Nybbles.Lo );
End;
End loop;
End return;
End Chunk_Debug;
End Aids.Utilities;
|
with GNAT.Command_Line;
use GNAT.Command_Line;
with GNAT.Strings;
with Ada.Directories;
use Ada.Directories;
with Ada.Command_Line;
with Ada.Text_IO; use Ada.Text_IO;
procedure GPR_Tools.Pkg2gpr.Main is
OutputFolder : aliased GNAT.Strings.String_Access := new String'(Ada.Directories.Current_Directory);
Version : constant String := $VERSION;
Command_Name : constant String := Ada.Directories.Base_Name (Ada.Command_Line.Command_Name);
procedure Show (S : String) is
D : Descr;
begin
D.Read_Pkg (S);
D.Write_GPR (Ada.Directories.Compose (OutputFolder.all, D.Get_GPR));
end Show;
procedure Print_Help is
use ASCII;
begin
Put_Line
(Command_Name & " " & Version & LF &
"Syntax:" & LF &
" " & Command_Name & " [OPtions] pkg-FILEs" & LF &
"Options:" & LF &
" -OFolder Define output folder." & LF &
" --version Printversion and exit." & LF &
" -h -? --help Print this text.");
end Print_Help;
begin
loop
case GNAT.Command_Line.Getopt ("O: ? h -help") is
when ASCII.NUL => exit;
when '?' | 'h' =>
Print_Help;
return;
when '-' =>
if Full_Switch = "-version" then
Put_Line (Version);
return;
elsif Full_Switch = "-help" then
Print_Help;
return;
end if;
when 'O' =>
OutputFolder := new String'(GNAT.Command_Line.Parameter);
when others =>
raise Program_Error; -- cannot occur
end case;
end loop;
if not Exists (OutputFolder.all) then
Create_Path (OutputFolder.all);
end if;
loop
declare
S : constant String := Get_Argument (Do_Expansion => True);
begin
exit when S'Length = 0;
Show (S);
end;
end loop;
exception
when Invalid_Switch => Put_Line ("Invalid Switch " & Full_Switch);
when Invalid_Parameter => Put_Line ("No parameter for " & Full_Switch);
end GPR_Tools.Pkg2gpr.Main;
|
package Opt64_PKG is
type Hash is new string (1 .. 1);
Last_Hash : Hash;
procedure Encode (X : Integer);
end;
|
pragma restrictions (no_secondary_stack);
pragma restrictions (no_elaboration_code);
pragma restrictions (no_finalization);
pragma restrictions (no_exception_handlers);
pragma restrictions (no_recursion);
pragma restrictions (no_wide_characters);
with system;
with ada.unchecked_conversion;
with interfaces; use interfaces;
package types
with spark_mode => on
is
KBYTE : constant := 2 ** 10;
MBYTE : constant := 2 ** 20;
GBYTE : constant := 2 ** 30;
subtype byte is unsigned_8;
subtype short is unsigned_16;
subtype word is unsigned_32;
subtype milliseconds is unsigned_64;
subtype microseconds is unsigned_64;
subtype system_address is unsigned_32;
function to_address is new ada.unchecked_conversion
(system_address, system.address);
function to_system_address is new ada.unchecked_conversion
(system.address, system_address);
function to_word is new ada.unchecked_conversion
(system.address, word);
function to_unsigned_32 is new ada.unchecked_conversion
(system.address, unsigned_32);
pragma warnings (off);
function to_unsigned_32 is new ada.unchecked_conversion
(unsigned_8, unsigned_32);
function to_unsigned_32 is new ada.unchecked_conversion
(unsigned_16, unsigned_32);
pragma warnings (on);
type byte_array is array (unsigned_32 range <>) of byte;
for byte_array'component_size use byte'size;
type short_array is array (unsigned_32 range <>) of short;
for short_array'component_size use short'size;
type word_array is array (unsigned_32 range <>) of word;
for word_array'component_size use word'size;
type unsigned_8_array is new byte_array;
type unsigned_16_array is new short_array;
type unsigned_32_array is new word_array;
nul : constant character := character'First;
type bit is mod 2**1 with size => 1;
type bits_2 is mod 2**2 with size => 2;
type bits_3 is mod 2**3 with size => 3;
type bits_4 is mod 2**4 with size => 4;
type bits_5 is mod 2**5 with size => 5;
type bits_6 is mod 2**6 with size => 6;
type bits_7 is mod 2**7 with size => 7;
--
type bits_9 is mod 2**9 with size => 9;
type bits_10 is mod 2**10 with size => 10;
type bits_11 is mod 2**11 with size => 11;
type bits_12 is mod 2**12 with size => 12;
--
type bits_17 is mod 2**17 with size => 17;
--
type bits_24 is mod 2**24 with size => 24;
--
type bits_27 is mod 2**27 with size => 27;
type bool is new boolean with size => 1;
for bool use (true => 1, false => 0);
function to_bit
(u : unsigned_8) return types.bit
with pre => u <= 1;
function to_bit
(u : unsigned_32) return types.bit
with pre => u <= 1;
end types;
|
------------------------------------------------------------------------------
-- --
-- Unicode Utilities --
-- --
-- Unicode Character Database (UCD) Facilities --
-- --
-- ------------------------------------------------------------------------ --
-- --
-- Copyright (C) 2019, ANNEXI-STRAYLINE Trans-Human Ltd. --
-- All rights reserved. --
-- --
-- Original Contributors: --
-- * Richard Wai (ANNEXI-STRAYLINE) --
-- --
-- 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 copyright holder 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 --
-- OWNER 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. --
-- --
------------------------------------------------------------------------------
with Ada.Unchecked_Deallocation;
with Ada.Characters.Latin_1;
with Ada.Streams.Stream_IO;
with Hex;
with Hex.Unsigned_8;
with Hex.Unsigned_24;
with Unicode.General_Category; use Unicode.General_Category;
with Unicode.General_Category.Alias;
procedure Unicode.UCD.Generate_General_Category_Body
(UnicodeData_Path: in String := "UnicodeData.txt";
Body_Path : in String := "aura-unicode-general_category.adb")
is
package SIO renames Ada.Streams.Stream_IO;
package GC_Alias renames Unicode.General_Category.Alias;
subtype Set_Case is Hex.Set_Case;
use all type Set_Case;
subtype General_Category_Type
is Unicode.General_Category.General_Category_Type;
use all type General_Category_Type;
-- Codepoint Value (0 - 16#10FFFF#, (up to FFFFFF is fine also in this
-- implementation)
use type Hex.Unsigned_24.Unsigned_24;
subtype Codepoint_Value is Hex.Unsigned_24.Unsigned_24;
procedure Encode_Codepoint (Value : in Codepoint_Value;
Buffer : out String;
Use_Case: in Set_Case := Upper_Case)
renames Hex.Unsigned_24.Encode;
-- Hash Key
use type Hex.Unsigned_8.Unsigned_8;
subtype Key_Hash is Hex.Unsigned_8.Unsigned_8
range 0 .. 16#10#;
procedure Encode_Hash (Value : in Key_Hash;
Buffer : out String;
Use_Case: in Set_Case := Upper_Case)
renames Hex.Unsigned_8.Encode;
-- Reference Hash Table ----------------------------------------------------
type Bucket_Item;
type Bucket_Item_Access is access Bucket_Item;
type Codepoint_Range is
record
First: Codepoint_Value;
Last : Codepoint_Value;
end record;
type Bucket_Item is
record
Codepoints: Codepoint_Range;
Category : General_Category_Type;
Next : Bucket_Item_Access := null;
end record;
procedure Free is new Ada.Unchecked_Deallocation
(Object => Bucket_Item,
Name => Bucket_Item_Access);
type Bucket is
record
First, Last: Bucket_Item_Access := null;
end record;
type Hash_Table is array (Key_Hash) of Bucket;
----------------------
-- Deallocate_Table --
----------------------
procedure Deallocate_Table (Table: in out Hash_Table) is
I,N: Bucket_Item_Access;
begin
for B of Table loop
I := B.First;
while I /= null loop
N := I.Next;
Free (I);
I := N;
end loop;
B.First := null;
B.Last := null;
end loop;
end Deallocate_Table;
----------
-- Hash --
----------
-- Numerous approaches were tried, but simply going by Unicode planes as the
-- hash keeps the rages as cohesive as possible (no wonder)
function Hash (Codepoint: Codepoint_Value) return Key_Hash
is (Key_Hash (Codepoint / 16#1_0000#))
with Inline;
-----------------
-- Append_Item --
-----------------
procedure Append_Item (To : in out Bucket;
Codepoint: in Codepoint_Value;
Category : in General_Category_Type)
with Inline is
New_Item: Bucket_Item_Access
:= new Bucket_Item'
(Codepoints => (others => Codepoint),
Category => Category,
Next => null);
begin
if To.First = null then
To.First := New_Item;
To.Last := New_Item;
else
To.Last.Next := New_Item;
To.Last := New_Item;
end if;
end Append_Item;
-- UnicodeData.txt Parsing -------------------------------------------------
type UnicodeData_Range is (First, Last, Single);
--------------------------
-- Identify_Point_Range --
--------------------------
-- UnicodeData.txt encodes codepoint ranges unusually. Instead of having a
-- range in Property 0 (P0), it has a special tag in P1, where the tag is
-- in angle brackets, and always ends with either ", First>" or, ", Last>".
--
-- This subprogram gives a quick answer to for each entry
function Identify_Point_Range (E: UCD_Entry) return UnicodeData_Range
with Inline is
P1: constant String := E.Property(1);
P_First: constant String := ", First>";
P_Last : constant String := ", Last>";
begin
if P1(P1'Last) = '>'
and then P1'Length >= P_First'Length
then
if P1(P1'Last - P_First'Length + 1 .. P1'Last) = P_First then
return First;
elsif P1(P1'Last - P_Last'Length + 1 .. P1'Last) = P_Last then
return Last;
else
return Single;
end if;
else
return Single;
end if;
end Identify_Point_Range;
----------------
-- Load_Table --
----------------
-- Parses the UnicodeData.txt file and loads the data into the hash table,
-- including filling in any ranges encountered
procedure Load_Table (File : in SIO.File_Type;
Table: in out Hash_Table;
Total: out Natural)
is
E: UCD_Entry;
Stream: constant SIO.Stream_Access := SIO.Stream (File);
Codepoint: Codepoint_Value;
Category : General_Category_Type;
pragma Assertion_Policy (Check);
begin
Total := 0;
while not SIO.End_Of_File (File) loop
E := Next_Entry (Stream);
pragma Assert (E.First_Codepoint = E.Last_Codepoint);
-- If this fails, the data is either bad, or Unicode changed the
-- format, either way we wouldn't handle this properly, since
-- we're expecting ranges to be expressed via P1
Codepoint := Codepoint_Value
(Wide_Wide_Character'Pos (E.First_Codepoint));
Category := GC_Alias.Category_By_Alias (E.Property(2));
Append_Item (To => Table(Hash (Codepoint)),
Codepoint => Codepoint,
Category => Category);
Total := Total + 1;
-- Check for a range and add those too
if Identify_Point_Range (E) = First then
declare
Start, Finish: Codepoint_Value;
begin
Start := Codepoint_Value
(Wide_Wide_Character'Pos
(Wide_Wide_Character'Succ (E.First_Codepoint)));
-- The next entry had better be a "Last" range
E := Next_Entry (Stream);
pragma Assert (Identify_Point_Range (E) = Last);
Finish := Codepoint_Value
(Wide_Wide_Character'Pos (E.First_Codepoint));
for C in Start .. Finish loop
Append_Item (To => Table(Hash (C)),
Codepoint => C,
Category => Category);
Total := Total + 1;
end loop;
end;
end if;
end loop;
end Load_Table;
---------------------
-- Collapse_Ranges --
---------------------
-- Scans each bucket of contiguous ranges of the same category and collapses
-- them into single entries
procedure Collapse_Ranges (Table: in out Hash_Table) is
begin
for K in Key_Hash loop
declare
B: Bucket renames Table(K);
Base : Bucket_Item_Access := B.First;
Reach: Bucket_Item_Access;
begin
while Base /= null loop
Reach := Base.Next;
while Reach /= null loop
exit when
(Reach.Category /= Base.category
or else (Reach.Codepoints.First
/= (Base.Codepoints.Last + 1)));
-- Absorb Reach
Base.Codepoints.Last := Reach.Codepoints.Last;
-- Isolate & Free Reach
Base.Next := Reach.Next;
Free (Reach);
Reach := Base.Next;
end loop;
Base := Reach;
end loop;
end;
end loop;
end Collapse_Ranges;
-- Main --------------------------------------------------------------------
UnicodeData: SIO.File_Type;
Ada_File : SIO.File_Type;
Ada_Stream : SIO.Stream_Access;
Table: Hash_Table;
Loaded_Codepoints: Natural;
-- Formatting
Tab : constant String := (1 .. 3 => ' ');
New_Line_Sequence: constant String := (1 => Ada.Characters.Latin_1.LF);
Indent: Natural := 0;
procedure Put (S: in String) with Inline is
begin
String'Write (Ada_Stream, S);
end Put;
procedure Do_Indent with Inline is
begin
for I in 1 .. Indent loop
Put (Tab);
end loop;
end Do_Indent;
procedure Put_Line (S: in String) with Inline is
begin
Do_Indent;
Put (S & New_Line_Sequence);
end Put_Line;
procedure New_Line (Count: Natural := 1) with Inline is
begin
for I in 1 .. Count loop
Put (New_Line_Sequence);
end loop;
end New_Line;
begin
declare
use SIO;
begin
Open (File => UnicodeData,
Mode => In_File,
Name => UnicodeData_Path);
end;
Load_Table (File => UnicodeData,
Table => Table,
Total => Loaded_Codepoints);
SIO.Close (UnicodeData);
-- Let's get to it
SIO.Create (File => Ada_File,
Name => Body_Path);
Ada_Stream := SIO.Stream (Ada_File);
-- Some stats
Put_Line ("-- ******* "
& "THIS FILE IS AUTOMATICALLY GENERATED "
& "******* --");
Put_Line ("-- "
& "- See Unicode.UCD.Generate_General_Category_Body -"
& " --");
New_Line (2);
Put_Line ("-- UnicodeData.txt Load Statistics --");
declare
Totals: array (General_Category_Type) of Natural := (others => 0);
Loaded_Calc: Natural := 0;
Grand_Total: Natural := 0;
I: Bucket_Item_Access;
begin
for B of Table loop
I := B.First;
while I /= null loop
Totals(I.Category) := Totals(I.Category) + 1;
I := I.Next;
end loop;
end loop;
-- Confirm our totals
for N of Totals loop
Loaded_Calc := Loaded_Calc + N;
end loop;
-- UnicodeData.txt does not contain "Other_Not_Assigned (Cn)"
-- so we need to calculate it ourselves
Totals(Other_Not_Assigned) := 16#110000# - Loaded_Calc;
for N of Totals loop
Grand_Total := Grand_Total + N;
end loop;
declare
Target_Length: constant := 26;
begin
for C in General_Category_Type loop
declare
C_Image: constant String := General_Category_Type'Image (C);
Padding: constant String(1 .. (Target_Length - C_Image'Length))
:= (others => ' ');
begin
Put_Line ("-- " & C_Image
& Padding
& '(' & GC_Alias.General_Category_Aliases(C)
& ") ="
& Natural'Image (Totals(C)));
end;
end loop;
declare
GT: constant String := "Grand Total";
Padding: constant String(1 .. (Target_Length - GT'Length))
:= (others => ' ');
begin
Put_Line (String'(1 .. Target_Length + 20 => '-'));
Put_Line ("-- " & GT & Padding & " ="
& Natural'Image(Grand_Total));
end;
end;
Put_Line ("--");
Put_Line ("-- Sanity Checks --");
if Grand_Total = 16#110000# then
Put ("-- [PASS] ");
else
Put ("-- [FAIL] ");
end if;
Put_Line ("Grand total = 16#110000# (U+000000 .. U+10FFFF)");
if Loaded_Codepoints = Loaded_Calc then
Put ("-- [PASS] ");
else
Put ("-- [FAIL] ");
end if;
Put_Line ("Total loaded (" & Natural'Image (Loaded_Codepoints)
& " ) = Hash table totals excluding Cn ("
& Natural'Image (Loaded_Calc)
& " )");
end;
-- Collapse the table
Collapse_Ranges (Table);
-- OK, now lets do the actual file
New_Line (2);
Put_Line ("package body Unicode.General_Category is");
Indent := 1;
-- Types and hash function
Put_Line ("type Codepoint is mod 2**24;");
New_Line;
-- Now we need to insert a function for each plane (bucket) with it's own
-- case statement for all the ranges in that bucket
declare
procedure Generate_Plane_Table (Table: Hash_Table; Key: Key_Hash) is
B: Bucket renames Table(Key);
Hash_Hex: String (1 .. 4);
Plane: String renames Hash_Hex (3 .. 4);
Codepoint_Hex: String (1 .. 6);
I: Bucket_Item_Access := B.First;
begin
Encode_Hash (Value => Key,
Buffer => Hash_Hex);
Indent := 1;
New_Line;
Put_Line ("function Plane_" & Plane
& "_Lookup (C: Codepoint) "
& "return General_Category_Type is");
Indent := 2;
if I = null then
-- Nothing here, this is just a direct return
Put_Line ("(" & General_Category_Type'Image (Other_Not_Assigned)
& ") with Inline;");
return;
end if;
Put_Line ("(case C is");
Indent := 3;
while I /= null loop
Do_Indent;
Put ("when ");
Encode_Codepoint (Value => I.Codepoints.First,
Buffer => Codepoint_Hex);
Put ("16#" & Codepoint_Hex & "# ");
if I.Codepoints.Last > I.Codepoints.First then
Encode_Codepoint (Value => I.Codepoints.Last,
Buffer => Codepoint_Hex);
Put (".. 16#" & Codepoint_Hex & "# ");
else
Put (" " & " " & " ");
end if;
Put ("=> " & General_Category_Type'Image (I.Category) & ',');
New_Line;
I := I.Next;
end loop;
New_Line;
Put_Line ("when others => "
& General_Category_Type'Image (Other_Not_Assigned)
& ")");
Indent := 2;
Put_Line ("with Inline;");
end Generate_Plane_Table;
begin
for K in Key_Hash loop
Generate_Plane_Table (Table, K);
end loop;
end;
-- Finally, The actual body for General_Category
Indent := 1;
New_Line (2);
Put_Line ("----------------------");
Put_Line ("-- General_Category --");
Put_Line ("----------------------");
Indent := 1;
Put_Line ("function General_Category (C: Wide_Wide_Character)");
Put_Line (" return General_Category_Type");
Put_Line ("is");
Indent := 2;
Put_Line ("CP: constant Codepoint "
& ":= Codepoint (Wide_Wide_Character'Pos(C));");
Indent := 1;
Put_Line ("begin");
Indent := 2;
Put_Line ("return");
Indent := 3;
Put_Line ("(case CP is");
declare
procedure Generate_Dispatch_Line (Key: Key_Hash) is
Hash_Hex: String (1 .. 4);
Plane: String renames Hash_Hex (3 .. 4);
Start_Hex, End_Hex: String (1 .. 6);
C: Codepoint_Value := ((Codepoint_Value(Key) + 1) * 16#1_0000#) - 1;
begin
Encode_Hash (Value => Key,
Buffer => Hash_Hex);
Encode_Codepoint (Value => C and 16#FF_0000#,
Buffer => Start_Hex);
Encode_Codepoint (Value => C,
Buffer => End_Hex);
Indent := 4;
Put_Line ("when 16#" & Start_Hex
& "# .. "
& "16#" & End_Hex
& "# => "
& "Plane_" & Plane & "_Lookup (CP),");
end Generate_Dispatch_Line;
begin
for K in Key_Hash loop
Generate_Dispatch_Line (K);
end loop;
New_Line;
Put_Line ("when others => "
& General_Category_Type'Image (Other_Not_Assigned)
& ");");
end;
Indent := 1;
Put_Line ("end General_Category;");
Indent := 0;
New_Line;
Put_Line ("end Unicode.General_Category;");
SIO.Close (Ada_File);
Deallocate_Table (Table);
exception
when others =>
Deallocate_Table (Table);
SIO.Close (UnicodeData);
SIO.Close (Ada_File);
raise;
end Unicode.UCD.Generate_General_Category_Body;
|
with Ada.Text_Io; use Ada.Text_Io;
procedure Sum_Series is
function F(X : Long_Float) return Long_Float is
begin
return 1.0 / X**2;
end F;
package Lf_Io is new Ada.Text_Io.Float_Io(Long_Float);
use Lf_Io;
Sum : Long_Float := 0.0;
subtype Param_Range is Integer range 1..1000;
begin
for I in Param_Range loop
Sum := Sum + F(Long_Float(I));
end loop;
Put("Sum of F(x) from" & Integer'Image(Param_Range'First) &
" to" & Integer'Image(Param_Range'Last) & " is ");
Put(Item => Sum, Aft => 10, Exp => 0);
New_Line;
end Sum_Series;
|
package body Ada.Numerics.SFMT.Generating is
-- no SIMD version
use type Unsigned_32;
use type Unsigned_64;
procedure rshift128 (
Out_Item : out w128_t;
In_Item : w128_t;
shift : Integer)
with Convention => Intrinsic;
procedure lshift128 (
Out_Item : out w128_t;
In_Item : w128_t;
shift : Integer)
with Convention => Intrinsic;
pragma Inline_Always (rshift128);
pragma Inline_Always (lshift128);
procedure do_recursion (r : out w128_t; a, b, c, d : w128_t)
with Convention => Intrinsic;
pragma Inline_Always (do_recursion);
-- This function simulates SIMD 128-bit right shift by the standard C.
-- The 128-bit integer given in in is shifted by (shift * 8) bits.
-- This function simulates the LITTLE ENDIAN SIMD.
procedure rshift128 (
Out_Item : out w128_t;
In_Item : w128_t;
shift : Integer)
is
th, tl, oh, ol : Unsigned_64;
begin
th := Interfaces.Shift_Left (Unsigned_64 (In_Item (3)), 32)
or Unsigned_64 (In_Item (2));
tl := Interfaces.Shift_Left (Unsigned_64 (In_Item (1)), 32)
or Unsigned_64 (In_Item (0));
oh := Interfaces.Shift_Right (th, shift * 8);
ol := Interfaces.Shift_Right (tl, shift * 8);
ol := ol or Interfaces.Shift_Left (th, 64 - shift * 8);
Out_Item (1) := Unsigned_32'Mod (Interfaces.Shift_Right (ol, 32));
Out_Item (0) := Unsigned_32'Mod (ol);
Out_Item (3) := Unsigned_32'Mod (Interfaces.Shift_Right (oh, 32));
Out_Item (2) := Unsigned_32'Mod (oh);
end rshift128;
-- This function simulates SIMD 128-bit left shift by the standard C.
-- The 128-bit integer given in in is shifted by (shift * 8) bits.
-- This function simulates the LITTLE ENDIAN SIMD.
procedure lshift128 (
Out_Item : out w128_t;
In_Item : w128_t;
shift : Integer)
is
th, tl, oh, ol : Unsigned_64;
begin
th := Interfaces.Shift_Left (Unsigned_64 (In_Item (3)), 32)
or Unsigned_64 (In_Item (2));
tl := Interfaces.Shift_Left (Unsigned_64 (In_Item (1)), 32)
or Unsigned_64 (In_Item (0));
oh := Interfaces.Shift_Left (th, shift * 8);
ol := Interfaces.Shift_Left (tl, shift * 8);
oh := oh or Interfaces.Shift_Right (tl, 64 - shift * 8);
Out_Item (1) := Unsigned_32'Mod (Interfaces.Shift_Right (ol, 32));
Out_Item (0) := Unsigned_32'Mod (ol);
Out_Item (3) := Unsigned_32'Mod (Interfaces.Shift_Right (oh, 32));
Out_Item (2) := Unsigned_32'Mod (oh);
end lshift128;
-- This function represents the recursion formula.
procedure do_recursion (r : out w128_t; a, b, c, d : w128_t) is
x : w128_t;
y : w128_t;
begin
lshift128 (x, a, SL2);
rshift128 (y, c, SR2);
r (0) := a (0) xor x (0)
xor (Interfaces.Shift_Right (b (0), SR1) and MSK1) xor y (0)
xor Interfaces.Shift_Left (d (0), SL1);
r (1) := a (1) xor x (1)
xor (Interfaces.Shift_Right (b (1), SR1) and MSK2) xor y (1)
xor Interfaces.Shift_Left (d (1), SL1);
r (2) := a (2) xor x (2)
xor (Interfaces.Shift_Right (b (2), SR1) and MSK3) xor y (2)
xor Interfaces.Shift_Left (d (2), SL1);
r (3) := a (3) xor x (3)
xor (Interfaces.Shift_Right (b (3), SR1) and MSK4) xor y (3)
xor Interfaces.Shift_Left (d (3), SL1);
end do_recursion;
-- implementation
-- This function fills the internal state array with pseudorandom
-- integers.
procedure gen_rand_all (
sfmt : in out w128_t_Array_N)
is
i : Integer;
r1, r2 : access w128_t;
begin
r1 := sfmt (N - 2)'Access;
r2 := sfmt (N - 1)'Access;
i := 0;
while i < N - POS1 loop
do_recursion (
sfmt (i),
sfmt (i),
sfmt (i + POS1),
r1.all,
r2.all);
r1 := r2;
r2 := sfmt (i)'Access;
i := i + 1;
end loop;
while i < N loop
do_recursion (
sfmt (i),
sfmt (i),
sfmt (i - (N - POS1)),
r1.all,
r2.all);
r1 := r2;
r2 := sfmt (i)'Access;
i := i + 1;
end loop;
end gen_rand_all;
-- This function fills the user-specified array with pseudorandom
-- integers.
procedure gen_rand_array (
sfmt : in out w128_t_Array_N;
Item : in out w128_t_Array_1;
size : Integer)
is
the_array : w128_t_Array (0 .. size - 1);
for the_array'Address use Item'Address;
i, j : Integer;
r1, r2 : access w128_t;
begin
r1 := sfmt (N - 2)'Access;
r2 := sfmt (N - 1)'Access;
i := 0;
while i < N - POS1 loop
do_recursion (
the_array (i),
sfmt (i),
sfmt (i + POS1),
r1.all,
r2.all);
r1 := r2;
r2 := the_array (i)'Access;
i := i + 1;
end loop;
while i < N loop
do_recursion (
the_array (i),
sfmt (i),
the_array (i - (N - POS1)),
r1.all,
r2.all);
r1 := r2;
r2 := the_array (i)'Access;
i := i + 1;
end loop;
while i < size - N loop
do_recursion (
the_array (i),
the_array (i - N),
the_array (i - (N - POS1)),
r1.all,
r2.all);
r1 := r2;
r2 := the_array (i)'Access;
i := i + 1;
end loop;
j := 0;
while j < N - (size - N) loop
sfmt (j) := the_array (j + (size - N));
j := j + 1;
end loop;
while i < size loop
do_recursion (
the_array (i),
the_array (i - N),
the_array (i - (N - POS1)),
r1.all,
r2.all);
r1 := r2;
r2 := the_array (i)'Access;
sfmt (j) := the_array (i);
i := i + 1;
j := j + 1;
end loop;
end gen_rand_array;
end Ada.Numerics.SFMT.Generating;
|
------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Localization, Internationalization, Globalization for Ada --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2013, 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 Ada.Unchecked_Deallocation;
package body Matreshka.JSON_Types is
-----------------
-- Dereference --
-----------------
procedure Dereference (Self : in out Shared_JSON_Array_Access) is
procedure Free is
new Ada.Unchecked_Deallocation
(Shared_JSON_Array, Shared_JSON_Array_Access);
begin
if Self /= Empty_Shared_JSON_Array'Access
and then Matreshka.Atomics.Counters.Decrement (Self.Counter)
then
for Value of Self.Values loop
Dereference (Value);
end loop;
Free (Self);
else
Self := null;
end if;
end Dereference;
-----------------
-- Dereference --
-----------------
procedure Dereference (Self : in out Shared_JSON_Object_Access) is
procedure Free is
new Ada.Unchecked_Deallocation
(Shared_JSON_Object, Shared_JSON_Object_Access);
begin
if Self /= Empty_Shared_JSON_Object'Access
and then Matreshka.Atomics.Counters.Decrement (Self.Counter)
then
for Value of Self.Values loop
Dereference (Value);
end loop;
Free (Self);
else
Self := null;
end if;
end Dereference;
-----------------
-- Dereference --
-----------------
procedure Dereference (Self : in out Shared_JSON_Value_Access) is
procedure Free is
new Ada.Unchecked_Deallocation
(Shared_JSON_Value, Shared_JSON_Value_Access);
begin
if Self /= Empty_Shared_JSON_Value'Access
and then Self /= Null_Shared_JSON_Value'Access
and then Matreshka.Atomics.Counters.Decrement (Self.Counter)
then
case Self.Value.Kind is
when Empty_Value =>
null;
when Boolean_Value =>
null;
when Integer_Value =>
null;
when Float_Value =>
null;
when String_Value =>
Matreshka.Internals.Strings.Dereference (Self.Value.String_Value);
when Array_Value =>
Dereference (Self.Value.Array_Value);
when Object_Value =>
Dereference (Self.Value.Object_Value);
when Null_Value =>
null;
end case;
Free (Self);
else
Self := null;
end if;
end Dereference;
------------
-- Mutate --
------------
procedure Mutate (Self : in out not null Shared_JSON_Array_Access) is
Source : not null Shared_JSON_Array_Access := Self;
begin
if Self = Empty_Shared_JSON_Array'Access
or else not Matreshka.Atomics.Counters.Is_One (Self.Counter)
then
Self :=
new Shared_JSON_Array'(Counter => <>, Values => Source.Values);
-- Update reference counters for values.
for Value of Self.Values loop
Reference (Value);
end loop;
-- Release source shared object.
Dereference (Source);
end if;
end Mutate;
------------
-- Mutate --
------------
procedure Mutate (Self : in out not null Shared_JSON_Object_Access) is
Source : not null Shared_JSON_Object_Access := Self;
begin
if Self = Empty_Shared_JSON_Object'Access
or else not Matreshka.Atomics.Counters.Is_One (Self.Counter)
then
Self :=
new Shared_JSON_Object'(Counter => <>, Values => Source.Values);
-- Update reference counters for values.
for Value of Self.Values loop
Reference (Value);
end loop;
-- Release source shared object.
Dereference (Source);
end if;
end Mutate;
------------
-- Mutate --
------------
procedure Mutate (Self : in out not null Shared_JSON_Value_Access) is
begin
-- Mutate object: new shared object is allocated when reference counter
-- is greater than one, reference counter of original object is
-- decremented and original value is copied. Otherwise, shared object is
-- unchanged.
null;
end Mutate;
------------
-- Mutate --
------------
procedure Mutate
(Self : in out not null Shared_JSON_Value_Access;
Kind : Value_Kinds) is
begin
-- Mutate object: allocate new shared then reference counter is greater
-- than one, and decrement reference counter of original object. Value
-- of the object is reset to default value of specifid kind.
null;
end Mutate;
---------------
-- Reference --
---------------
procedure Reference (Self : not null Shared_JSON_Array_Access) is
begin
if Self /= Empty_Shared_JSON_Array'Access then
Matreshka.Atomics.Counters.Increment (Self.Counter);
end if;
end Reference;
---------------
-- Reference --
---------------
procedure Reference (Self : not null Shared_JSON_Object_Access) is
begin
if Self /= Empty_Shared_JSON_Object'Access then
Matreshka.Atomics.Counters.Increment (Self.Counter);
end if;
end Reference;
---------------
-- Reference --
---------------
procedure Reference (Self : not null Shared_JSON_Value_Access) is
begin
if Self /= Empty_Shared_JSON_Value'Access
and Self /= Null_Shared_JSON_Value'Access
then
Matreshka.Atomics.Counters.Increment (Self.Counter);
end if;
end Reference;
end Matreshka.JSON_Types;
|
<ADSWorkspace Revision="10" Version="100">
<Workspace Name="">
<LibraryDefs Name="lib.defs" />
<Library Name="ads_standard_layers_ic" />
<Library Name="ads_schematic_layers_ic" />
<Library Name="ads_schematic_ports_ic" />
<Library Name="ads_sources" />
<Library Name="ads_tlines" />
<Library Name="ads_bondwires" />
<Library Name="ads_behavioral" />
<Library Name="ads_textfonts" />
<Library Name="ads_common_cmps" />
<Library Name="ads_designs" />
<Library Name="ads_pelib" />
<Library Name="ads_standard_layers" />
<Library Name="ads_schematic_layers" />
<Library Name="empro_standard_layers" />
<Library Name="ads_builtin" />
<Library Name="ads_rflib" />
<Library Name="ads_simulation" />
<Library Name="ads_datacmps" />
<Library Name="1xEV" />
<Library Name="3GPPFDD" />
<Library Name="3GPPFDD_10_99" />
<Library Name="Antennas_and_Propagation" />
<Library Name="CDMA" />
<Library Name="cdma2000" />
<Library Name="Circuit_Cosimulation" />
<Library Name="CMMB" />
<Library Name="Controllers" />
<Library Name="DTMB" />
<Library Name="DTV" />
<Library Name="EDGE" />
<Library Name="GSM" />
<Library Name="HDL_Blocks" />
<Library Name="HSDPA" />
<Library Name="HSUPA" />
<Library Name="Instruments" />
<Library Name="Interactive_Controls_and_Displays" />
<Library Name="LTE" />
<Library Name="Numeric" />
<Library Name="Obsolete" />
<Library Name="Signal_Converters" />
<Library Name="Simulation_Sequencing" />
<Library Name="Sinks" />
<Library Name="SystemVue_Cosimulation" />
<Library Name="TDSCDMA" />
<Library Name="Timed" />
<Library Name="UMB" />
<Library Name="UWB" />
<Library Name="WLAN" />
<Library Name="WLAN_11n" />
<Library Name="WMAN" />
<Library Name="WMAN_16e" />
<ConfigFile Name="de_sim.cfg" />
<ConfigFile Name="hpeesofsim.cfg" />
<Preferences Name="layout.prf" />
<Preferences Name="schematic.prf" />
<Library Name="MyLibrary1_lib" />
<Substrate Name="MyLibrary1_lib:tech.subst" />
<Log Name="netlist.log" />
<Dataset Name="cell_1.ds" />
<Data_Files Name="cell_1.ds" />
<Data_Files Name="cell_1_data\logFile.txt" />
<ConfigFile Name="dds.cfg" />
<Dataset Name="cell_2.ds" />
<Data_Files Name="cell_2.ds" />
<Data_Files Name="cell_2_data\logFile.txt" />
<Log Name="search_history.log" />
<Dataset Name="cell_3.ds" />
<Data_Files Name="cell_3.ds" />
<Data_Files Name="cell_3_data\logFile.txt" />
<Cell Name="MyLibrary1_lib:Total" />
<Data_Display Name="Total.dds" />
<Cell Name="MyLibrary1_lib:Entree" />
<Dataset Name="Total.ds" />
<Data_Files Name="Total.ds" />
<Data_Files Name="Total_data\logFile.txt" />
<Dataset Name="Sorite.ds" />
<Data_Files Name="Sorite.ds" />
<Data_Files Name="Sorite_data\logFile.txt" />
<Cell Name="MyLibrary1_lib:Sortie" />
<Dataset Name="Sortie.ds" />
<Data_Files Name="Sortie.ds" />
<Data_Files Name="Sortie_data\logFile.txt" />
<Data_Display Name="Sortie.dds" />
</Workspace>
</ADSWorkspace>
|
pragma License (Unrestricted);
with Ada.Strings.Maps;
package Ada.Strings.Wide_Maps is
pragma Preelaborate;
-- Representation for a set of Wide_Character values:
-- modified
-- type Wide_Character_Set is private;
subtype Wide_Character_Set is Maps.Character_Set;
-- modified
-- Null_Set : constant Wide_Character_Set;
function Null_Set return Wide_Character_Set
renames Maps.Null_Set;
-- type Wide_Character_Range is record
-- Low : Wide_Character;
-- High : Wide_Character;
-- end record;
subtype Wide_Character_Range is Maps.Wide_Character_Range;
-- Represents Wide_Character range Low..High
-- type Wide_Character_Ranges is
-- array (Positive range <>) of Wide_Character_Range;
subtype Wide_Character_Ranges is Maps.Wide_Character_Ranges;
function To_Set (Ranges : Wide_Character_Ranges)
return Wide_Character_Set
renames Maps.Overloaded_To_Set;
function To_Set (Span : Wide_Character_Range)
return Wide_Character_Set
renames Maps.Overloaded_To_Set;
function To_Ranges (Set : Wide_Character_Set)
return Wide_Character_Ranges
renames Maps.Overloaded_To_Ranges;
function "=" (Left, Right : Wide_Character_Set) return Boolean
renames Maps."=";
function "not" (Right : Wide_Character_Set)
return Wide_Character_Set
renames Maps."not";
function "and" (Left, Right : Wide_Character_Set)
return Wide_Character_Set
renames Maps."and";
function "or" (Left, Right : Wide_Character_Set)
return Wide_Character_Set
renames Maps."or";
function "xor" (Left, Right : Wide_Character_Set)
return Wide_Character_Set
renames Maps."xor";
function "-" (Left, Right : Wide_Character_Set)
return Wide_Character_Set
renames Maps."-";
function Is_In (
Element : Wide_Character;
Set : Wide_Character_Set)
return Boolean
renames Maps.Overloaded_Is_In;
function Is_Subset (
Elements : Wide_Character_Set;
Set : Wide_Character_Set)
return Boolean
renames Maps.Is_Subset;
function "<=" (
Left : Wide_Character_Set;
Right : Wide_Character_Set)
return Boolean
renames Maps.Is_Subset;
-- Alternative representation for a set of Wide_Character values:
subtype Wide_Character_Sequence is Wide_String;
function To_Set (Sequence : Wide_Character_Sequence)
return Wide_Character_Set
renames Maps.Overloaded_To_Set;
function To_Set (Singleton : Wide_Character)
return Wide_Character_Set
renames Maps.Overloaded_To_Set;
function To_Sequence (Set : Wide_Character_Set)
return Wide_Character_Sequence
renames Maps.Overloaded_To_Sequence;
-- Representation for a Wide_Character to
-- Wide_Character mapping:
-- modified
-- type Wide_Character_Mapping is private;
subtype Wide_Character_Mapping is Maps.Character_Mapping;
function Value (
Map : Wide_Character_Mapping;
Element : Wide_Character)
return Wide_Character
renames Maps.Overloaded_Value;
-- modified
-- Identity : constant Wide_Character_Mapping;
function Identity return Wide_Character_Mapping
renames Maps.Identity;
function To_Mapping (From, To : Wide_Character_Sequence)
return Wide_Character_Mapping
renames Maps.Overloaded_To_Mapping;
function To_Domain (Map : Wide_Character_Mapping)
return Wide_Character_Sequence
renames Maps.Overloaded_To_Domain;
function To_Range (Map : Wide_Character_Mapping)
return Wide_Character_Sequence
renames Maps.Overloaded_To_Range;
type Wide_Character_Mapping_Function is
access function (From : Wide_Character) return Wide_Character;
end Ada.Strings.Wide_Maps;
|
-- Institution: Technische Universitaet Muenchen
-- Department: Realtime Computer Systems (RCS)
-- Project: StratoX
-- XXX! Nothing here is thread-safe!
--
-- Authors: Martin Becker (becker@rcs.ei.tum.de)
with FAT_Filesystem;
with FAT_Filesystem.Directories; use FAT_Filesystem.Directories;
-- @summary File handling for FAT FS
package FAT_Filesystem.Directories.Files with SPARK_Mode => Off is
type File_Handle is private;
type File_Mode is (Read_Mode, Write_Mode);
subtype File_Data is Media_Reader.Block;
function File_Create
(Parent : in out Directory_Handle;
newname : String;
Overwrite : Boolean := False;
File : out File_Handle) return Status_Code;
-- create a new file in the given directory, and return
-- handle for write access
function File_Write
(File : in out File_Handle;
Data : File_Data;
Status : out Status_Code) return Integer;
-- @return number of bytes written (at most Data'Length), or -1 on error.
function File_Flush
(File : in out File_Handle) return Status_Code;
-- force writing file to disk at this very moment (slow!)
function File_Size (File : File_Handle) return Unsigned_32;
function File_Open_Readonly
(Ent : in out Directory_Entry;
File : in out File_Data) return Status_Code
with Pre => Is_System_File (Ent);
-- open the file given by the directory entry and return
-- handle for read access;
function File_Read
(File : in out File_Handle;
Data : out File_Data) return Integer;
-- @return number of bytes read (at most Data'Length), or -1 on error.
procedure File_Close (File : in out File_Handle);
-- invalidates the handle, and ensures that
-- everything is flushed to the disk
private
pragma SPARK_Mode (Off);
type File_Handle is record
Is_Open : Boolean := False;
FS : FAT_Filesystem_Access;
Mode : File_Mode := Read_Mode;
Start_Cluster : Unsigned_32 := INVALID_CLUSTER; -- first cluster; file begin
Current_Cluster : Unsigned_32 := 0; -- where we are currently reading/writing
Current_Block : Unsigned_32 := 0; -- same, but block
Buffer : File_Data (1 .. 512); -- size of one block in FAT/SD card
Buffer_Level : Natural := 0; -- how much data in Buffer is meaningful
Bytes_Total : Unsigned_32 := 0; -- how many bytes were read/written
D_Entry : Directory_Entry; -- the associated directory entry
end record;
-- used to access files
function Update_Entry (File : in out File_Handle) return Status_Code;
-- maintain the directory entry (file size)
end FAT_Filesystem.Directories.Files;
|
------------------------------------------------------------------------------
-- --
-- GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS --
-- --
-- S Y S T E M . O S _ P R I M I T I V E S --
-- --
-- B o d y --
-- --
-- Copyright (C) 1998-2019, 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 is the NT version of this package
with System.Task_Lock;
with System.Win32.Ext;
package body System.OS_Primitives is
use System.Task_Lock;
use System.Win32;
use System.Win32.Ext;
----------------------------------------
-- Data for the high resolution clock --
----------------------------------------
Tick_Frequency : aliased LARGE_INTEGER;
-- Holds frequency of high-performance counter used by Clock
-- Windows NT uses a 1_193_182 Hz counter on PCs.
Base_Monotonic_Ticks : LARGE_INTEGER;
-- Holds the Tick count for the base monotonic time
Base_Monotonic_Clock : Duration;
-- Holds the current clock for monotonic clock's base time
type Clock_Data is record
Base_Ticks : LARGE_INTEGER;
-- Holds the Tick count for the base time
Base_Time : Long_Long_Integer;
-- Holds the base time used to check for system time change, used with
-- the standard clock.
Base_Clock : Duration;
-- Holds the current clock for the standard clock's base time
end record;
type Clock_Data_Access is access all Clock_Data;
-- Two base clock buffers. This is used to be able to update a buffer while
-- the other buffer is read. The point is that we do not want to use a lock
-- inside the Clock routine for performance reasons. We still use a lock
-- in the Get_Base_Time which is called very rarely. Current is a pointer,
-- the pragma Atomic is there to ensure that the value can be set or read
-- atomically. That's it, when Get_Base_Time has updated a buffer the
-- switch to the new value is done by changing Current pointer.
First, Second : aliased Clock_Data;
Current : Clock_Data_Access := First'Access;
pragma Atomic (Current);
-- The following signature is to detect change on the base clock data
-- above. The signature is a modular type, it will wrap around without
-- raising an exception. We would need to have exactly 2**32 updates of
-- the base data for the changes to get undetected.
type Signature_Type is mod 2**32;
Signature : Signature_Type := 0;
pragma Atomic (Signature);
function Monotonic_Clock return Duration;
pragma Export (Ada, Monotonic_Clock, "__gnat_monotonic_clock");
-- Return "absolute" time, represented as an offset relative to "the Unix
-- Epoch", which is Jan 1, 1970 00:00:00 UTC. This clock implementation is
-- immune to the system's clock changes. Export this function so that it
-- can be imported from s-taprop-mingw.adb without changing the shared
-- spec (s-osprim.ads).
procedure Get_Base_Time (Data : in out Clock_Data);
-- Retrieve the base time and base ticks. These values will be used by
-- clock to compute the current time by adding to it a fraction of the
-- performance counter. This is for the implementation of a high-resolution
-- clock. Note that this routine does not change the base monotonic values
-- used by the monotonic clock.
-----------
-- Clock --
-----------
-- This implementation of clock provides high resolution timer values
-- using QueryPerformanceCounter. This call return a 64 bits values (based
-- on the 8253 16 bits counter). This counter is updated every 1/1_193_182
-- times per seconds. The call to QueryPerformanceCounter takes 6
-- microsecs to complete.
function Clock return Duration is
Max_Shift : constant Duration := 2.0;
Hundreds_Nano_In_Sec : constant Long_Long_Float := 1.0E7;
Data : Clock_Data;
Current_Ticks : aliased LARGE_INTEGER;
Elap_Secs_Tick : Duration;
Elap_Secs_Sys : Duration;
Now : aliased Long_Long_Integer;
Sig1, Sig2 : Signature_Type;
begin
-- Try ten times to get a coherent set of base data. For this we just
-- check that the signature hasn't changed during the copy of the
-- current data.
--
-- This loop will always be done once if there is no interleaved call
-- to Get_Base_Time.
for K in 1 .. 10 loop
Sig1 := Signature;
Data := Current.all;
Sig2 := Signature;
exit when Sig1 = Sig2;
end loop;
if QueryPerformanceCounter (Current_Ticks'Access) = Win32.FALSE then
return 0.0;
end if;
GetSystemTimeAsFileTime (Now'Access);
Elap_Secs_Sys :=
Duration (Long_Long_Float (abs (Now - Data.Base_Time)) /
Hundreds_Nano_In_Sec);
Elap_Secs_Tick :=
Duration (Long_Long_Float (Current_Ticks - Data.Base_Ticks) /
Long_Long_Float (Tick_Frequency));
-- If we have a shift of more than Max_Shift seconds we resynchronize
-- the Clock. This is probably due to a manual Clock adjustment, a DST
-- adjustment or an NTP synchronisation. And we want to adjust the time
-- for this system (non-monotonic) clock.
if abs (Elap_Secs_Sys - Elap_Secs_Tick) > Max_Shift then
Get_Base_Time (Data);
Elap_Secs_Tick :=
Duration (Long_Long_Float (Current_Ticks - Data.Base_Ticks) /
Long_Long_Float (Tick_Frequency));
end if;
return Data.Base_Clock + Elap_Secs_Tick;
end Clock;
-------------------
-- Get_Base_Time --
-------------------
procedure Get_Base_Time (Data : in out Clock_Data) is
-- The resolution for GetSystemTime is 1 millisecond
-- The time to get both base times should take less than 1 millisecond.
-- Therefore, the elapsed time reported by GetSystemTime between both
-- actions should be null.
epoch_1970 : constant := 16#19D_B1DE_D53E_8000#; -- win32 UTC epoch
system_time_ns : constant := 100; -- 100 ns per tick
Sec_Unit : constant := 10#1#E9;
Max_Elapsed : constant LARGE_INTEGER :=
LARGE_INTEGER (Tick_Frequency / 100_000);
-- Look for a precision of 0.01 ms
Sig : constant Signature_Type := Signature;
Loc_Ticks, Ctrl_Ticks : aliased LARGE_INTEGER;
Loc_Time, Ctrl_Time : aliased Long_Long_Integer;
Elapsed : LARGE_INTEGER;
Current_Max : LARGE_INTEGER := LARGE_INTEGER'Last;
New_Data : Clock_Data_Access;
begin
-- Here we must be sure that both of these calls are done in a short
-- amount of time. Both are base time and should in theory be taken
-- at the very same time.
-- The goal of the following loop is to synchronize the system time
-- with the Win32 performance counter by getting a base offset for both.
-- Using these offsets it is then possible to compute actual time using
-- a performance counter which has a better precision than the Win32
-- time API.
-- Try at most 10 times to reach the best synchronisation (below 1
-- millisecond) otherwise the runtime will use the best value reached
-- during the runs.
Lock;
-- First check that the current value has not been updated. This
-- could happen if another task has called Clock at the same time
-- and that Max_Shift has been reached too.
--
-- But if the current value has been changed just before we entered
-- into the critical section, we can safely return as the current
-- base data (time, clock, ticks) have already been updated.
if Sig /= Signature then
Unlock;
return;
end if;
-- Check for the unused data buffer and set New_Data to point to it
if Current = First'Access then
New_Data := Second'Access;
else
New_Data := First'Access;
end if;
for K in 1 .. 10 loop
if QueryPerformanceCounter (Loc_Ticks'Access) = Win32.FALSE then
pragma Assert
(Standard.False,
"Could not query high performance counter in Clock");
null;
end if;
GetSystemTimeAsFileTime (Ctrl_Time'Access);
-- Scan for clock tick, will take up to 16ms/1ms depending on PC.
-- This cannot be an infinite loop or the system hardware is badly
-- damaged.
loop
GetSystemTimeAsFileTime (Loc_Time'Access);
if QueryPerformanceCounter (Ctrl_Ticks'Access) = Win32.FALSE then
pragma Assert
(Standard.False,
"Could not query high performance counter in Clock");
null;
end if;
exit when Loc_Time /= Ctrl_Time;
Loc_Ticks := Ctrl_Ticks;
end loop;
-- Check elapsed Performance Counter between samples
-- to choose the best one.
Elapsed := Ctrl_Ticks - Loc_Ticks;
if Elapsed < Current_Max then
New_Data.Base_Time := Loc_Time;
New_Data.Base_Ticks := Loc_Ticks;
Current_Max := Elapsed;
-- Exit the loop when we have reached the expected precision
exit when Elapsed <= Max_Elapsed;
end if;
end loop;
New_Data.Base_Clock :=
Duration
(Long_Long_Float
((New_Data.Base_Time - epoch_1970) * system_time_ns) /
Long_Long_Float (Sec_Unit));
-- At this point all the base values have been set into the new data
-- record. Change the pointer (atomic operation) to these new values.
Current := New_Data;
Data := New_Data.all;
-- Set new signature for this data set
Signature := Signature + 1;
Unlock;
exception
when others =>
Unlock;
raise;
end Get_Base_Time;
---------------------
-- Monotonic_Clock --
---------------------
function Monotonic_Clock return Duration is
Current_Ticks : aliased LARGE_INTEGER;
Elap_Secs_Tick : Duration;
begin
if QueryPerformanceCounter (Current_Ticks'Access) = Win32.FALSE then
return 0.0;
else
Elap_Secs_Tick :=
Duration (Long_Long_Float (Current_Ticks - Base_Monotonic_Ticks) /
Long_Long_Float (Tick_Frequency));
return Base_Monotonic_Clock + Elap_Secs_Tick;
end if;
end Monotonic_Clock;
-----------------
-- Timed_Delay --
-----------------
procedure Timed_Delay (Time : Duration; Mode : Integer) is
function Mode_Clock return Duration;
pragma Inline (Mode_Clock);
-- Return the current clock value using either the monotonic clock or
-- standard clock depending on the Mode value.
----------------
-- Mode_Clock --
----------------
function Mode_Clock return Duration is
begin
case Mode is
when Absolute_RT => return Monotonic_Clock;
when others => return Clock;
end case;
end Mode_Clock;
-- Local Variables
Base_Time : constant Duration := Mode_Clock;
-- Base_Time is used to detect clock set backward, in this case we
-- cannot ensure the delay accuracy.
Rel_Time : Duration;
Abs_Time : Duration;
Check_Time : Duration := Base_Time;
-- Start of processing for Timed Delay
begin
if Mode = Relative then
Rel_Time := Time;
Abs_Time := Time + Check_Time;
else
Rel_Time := Time - Check_Time;
Abs_Time := Time;
end if;
if Rel_Time > 0.0 then
loop
Sleep (DWORD (Rel_Time * 1000.0));
Check_Time := Mode_Clock;
exit when Abs_Time <= Check_Time or else Check_Time < Base_Time;
Rel_Time := Abs_Time - Check_Time;
end loop;
end if;
end Timed_Delay;
----------------
-- Initialize --
----------------
Initialized : Boolean := False;
procedure Initialize is
begin
if Initialized then
return;
end if;
Initialized := True;
-- Get starting time as base
if QueryPerformanceFrequency (Tick_Frequency'Access) = Win32.FALSE then
raise Program_Error with
"cannot get high performance counter frequency";
end if;
Get_Base_Time (Current.all);
-- Keep base clock and ticks for the monotonic clock. These values
-- should never be changed to ensure proper behavior of the monotonic
-- clock.
Base_Monotonic_Clock := Current.Base_Clock;
Base_Monotonic_Ticks := Current.Base_Ticks;
end Initialize;
end System.OS_Primitives;
|
with Ada.Text_Io, Ada.Integer_Text_Io, Datos;
with Crear_Lista_Vacia, Ins, Esc, Longitud;
use Datos;
use Ada.Text_Io, Ada.Integer_Text_Io;
procedure Prueba_Longitud is
Lis : Lista; -- variable del programa principal
procedure Pedir_Return is
begin
Put_Line("pulsa return para continuar ");
Skip_Line;
end Pedir_Return;
begin -- programa principal
-- Casos de prueba:
-- 1. Lista vacia. Resultado: cero
-- 2. Lista no vacia. Lista de un elemento
-- 3. Lista no vacia. Varios elementos
-- 4. Lista no vacia. Muchos elementos
Put_Line("Programa de prueba: ");
Put_Line("*********");
Crear_Lista_Vacia(Lis);
Put_Line("Caso de prueba 1: Lista vacia ");
Put_Line("Ahora deberia escribir cero: ");
Put(Longitud(Lis));
New_Line;
New_Line;
Pedir_Return;
Crear_Lista_Vacia(Lis);
Ins(Lis, 4);
Put_Line("Caso de prueba 2: lista de un solo elemento.");
Put_Line("La lista inicial contiene ");
Esc(Lis);
Put_Line("Ahora deberia escribir 1: ");
Put(Longitud(Lis));
New_Line;
New_Line;
Pedir_Return;
Crear_Lista_Vacia(Lis);
Ins(Lis, 6);
Ins(Lis, 8);
Ins(Lis, 9);
Ins(Lis, 10);
Put_Line("Caso de prueba 3: lista de varios elementos.");
Put_Line("La lista inicial contiene ");
Esc(Lis);
Put_Line("Ahora deberia escribir 4: ");
Put(Longitud(Lis));
New_Line;
New_Line;
Pedir_Return;
Crear_Lista_Vacia(Lis);
Ins(Lis, 6);
Ins(Lis, 8);
Ins(Lis, 9);
Ins(Lis, 10);
Ins(Lis, 6);
Ins(Lis, 8);
Ins(Lis, 9);
Ins(Lis, 10);
Ins(Lis, 6);
Ins(Lis, 8);
Ins(Lis, 9);
Ins(Lis, 10);
Ins(Lis, 6);
Ins(Lis, 8);
Ins(Lis, 9);
Ins(Lis, 10);
Ins(Lis, 6);
Ins(Lis, 8);
Ins(Lis, 9);
Ins(Lis, 10);
Ins(Lis, 6);
Ins(Lis, 8);
Ins(Lis, 9);
Ins(Lis, 10);
Ins(Lis, 6);
Ins(Lis, 8);
Ins(Lis, 9);
Ins(Lis, 10);
Put_Line("Caso de prueba 3: lista de varios elementos.");
Put_Line("La lista inicial contiene ");
Esc(Lis);
Put_Line("Ahora deberia escribir 28: ");
Put(Longitud(Lis));
New_Line;
New_Line;
Pedir_Return;
Put_Line("Se acabo la prueba. AGURTZ ");
end Prueba_Longitud;
|
pragma Ada_2012;
package body SAM.SERCOM.USART is
---------------
-- Configure --
---------------
procedure Configure (This : in out USART_Device;
Baud : UInt16;
MSB_First : Boolean;
TX_Fall_RX_Rise : Boolean;
Parity : Boolean;
Synchronous_Com : Boolean;
RXPO : Pad_Id;
TXPO : Pad_Id;
Run_In_Standby : Boolean)
is
begin
This.Reset;
This.Periph.SERCOM_USART.CTRLA :=
(MODE => 1, -- USART with internal clock
RUNSTDBY => Run_In_Standby,
TXPO => UInt2 (TXPO),
RXPO => UInt2 (RXPO),
FORM => (if Parity then 1 else 0),
CMODE => Synchronous_Com,
CPOL => TX_Fall_RX_Rise,
DORD => not MSB_First,
others => <>);
This.Periph.SERCOM_USART.BAUD := Baud;
This.Config_Done := True;
end Configure;
---------------------
-- Enable_Receiver --
---------------------
procedure Enable_Receiver (This : in out USART_Device) is
begin
This.Periph.SERCOM_USART.CTRLB.RXEN := True;
end Enable_Receiver;
----------------------
-- Disable_Receiver --
----------------------
procedure Disable_Receiver (This : in out USART_Device) is
begin
This.Periph.SERCOM_USART.CTRLB.RXEN := False;
end Disable_Receiver;
------------------------
-- Enable_Transmitter --
------------------------
procedure Enable_Transmitter (This : in out USART_Device) is
begin
This.Periph.SERCOM_USART.CTRLB.TXEN := True;
end Enable_Transmitter;
-------------------------
-- Disable_Transmitter --
-------------------------
procedure Disable_Transmitter (This : in out USART_Device) is
begin
This.Periph.SERCOM_USART.CTRLB.TXEN := False;
end Disable_Transmitter;
------------------
-- Data_Address --
------------------
function Data_Address (This : USART_Device) return System.Address is
begin
return This.Periph.SERCOM_USART.DATA'Address;
end Data_Address;
---------------
-- Data_Size --
---------------
function Data_Size (Port : USART_Device) return UART_Data_Size is
begin
return HAL.UART.Data_Size_8b;
end Data_Size;
--------------
-- Transmit --
--------------
overriding
procedure Transmit (This : in out USART_Device;
Data : HAL.UART.UART_Data_8b;
Status : out HAL.UART.UART_Status;
Timeout : Natural := 1_000)
is
begin
for Elt of Data loop
This.Periph.SERCOM_USART.DATA := UInt32 (Elt);
while not This.Periph.SERCOM_USART.INTFLAG.DRE loop
null;
end loop;
end loop;
Status := Ok;
end Transmit;
--------------
-- Transmit --
--------------
overriding
procedure Transmit (This : in out USART_Device;
Data : HAL.UART.UART_Data_9b;
Status : out HAL.UART.UART_Status;
Timeout : Natural := 1_000)
is
begin
raise Program_Error with "Unimplemented procedure Transmit";
end Transmit;
-------------
-- Receive --
-------------
overriding
procedure Receive (This : in out USART_Device;
Data : out HAL.UART.UART_Data_8b;
Status : out HAL.UART.UART_Status;
Timeout : Natural := 1_000)
is
begin
for Elt of Data loop
while not This.Periph.SERCOM_USART.INTFLAG.RXC loop
null;
end loop;
Elt := UInt8 (This.Periph.SERCOM_USART.DATA);
end loop;
Status := Ok;
end Receive;
-------------
-- Receive --
-------------
overriding
procedure Receive (This : in out USART_Device;
Data : out HAL.UART.UART_Data_9b;
Status : out HAL.UART.UART_Status;
Timeout : Natural := 1_000)
is
begin
raise Program_Error with "Unimplemented procedure Receive";
end Receive;
end SAM.SERCOM.USART;
|
with
gel.Window.setup,
gel.Applet.gui_world,
gel.Forge,
gel.World,
gel.Camera,
Physics;
pragma Unreferenced (gel.Window.setup);
procedure launch_Pong_Tute
--
-- Basic pong game.
--
is
use gel.Applet,
gel.Applet.gui_world;
--- Applet
--
the_Applet : gel.Applet.gui_world.view
:= gel.Forge.new_gui_Applet (Named => "Pong Tutorial",
window_Width => 800,
window_Height => 600,
space_Kind => physics.Box2d);
--- Controls
--
Cycle : Natural := 0;
begin
the_Applet.Camera.Site_is ((0.0, 0.0, 20.0));
--- Main loop.
--
while the_Applet.is_open
loop
Cycle := Cycle + 1;
the_Applet.World.evolve; -- Advance the world.
the_Applet.freshen; -- Handle any new events and update the screen.
end loop;
free (the_Applet);
end launch_Pong_Tute;
|
with Text_Io, Strings, Idents;
use Text_Io, Strings, Idents;
procedure identsdr is
procedure do_it is
s : tString;
i : tIdent;
begin
Put ("enter strings, one per line, - terminates"); New_Line;
loop
ReadS (Standard_Input, s);
i := MakeIdent (s);
WriteIdent (Standard_Output, i); New_Line;
if Length (s) = 0 or else Element (s, 1) = '-' then exit; end if;
end loop;
New_Line;
WriteIdents;
end do_it;
begin
do_it;
InitIdents;
do_it;
end identsdr;
|
------------------------------------------------------------------------------
-- --
-- Copyright (C) 2017, 2020, 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 X-CUBE-53L0A1 STM32Cube expansion, with some --
-- input from Crazyflie source. --
-- --
-- COPYRIGHT(c) 2016 STMicroelectronics --
------------------------------------------------------------------------------
with Ada.Unchecked_Conversion;
with HAL; use HAL;
package body VL53L0X is
Start_Overhead : constant := 1910;
End_Overhead : constant := 960;
Msrc_Overhead : constant := 660;
Tcc_Overhead : constant := 590;
Dss_Overhead : constant := 690;
Pre_Range_Overhead : constant := 660;
Final_Range_Overhead : constant := 550;
function Decode_Timeout (Encoded : UInt16) return UInt32;
function Encode_Timeout (Timeout : UInt32) return UInt16;
function To_Timeout_Microseconds
(Timeout_Period_Mclks : UInt32;
VCSel_Period_Pclks : UInt8) return UInt32;
function To_Timeout_Mclks
(Timeout_Period_us : UInt32;
VCSel_Period_Pclks : UInt8) return UInt32;
procedure Perform_Single_Ref_Calibration
(This : VL53L0X_Ranging_Sensor;
VHV_Init : UInt8;
Status : out Boolean);
----------------------------
-- Get_GPIO_Functionality --
----------------------------
function Get_GPIO_Functionality (This : VL53L0X_Ranging_Sensor)
return VL53L0X_GPIO_Functionality
is
Data : UInt8;
Status : Boolean;
Result : VL53L0X_GPIO_Functionality := No_Interrupt;
begin
Read (This, REG_SYSTEM_INTERRUPT_CONFIG_GPIO, Data, Status);
if Status and then Data in 1 .. 4 then
case Data is
when 1 => Result := Level_Low;
when 2 => Result := Level_High;
when 3 => Result := Out_Of_Window;
when 4 => Result := New_Sample_Ready;
when others => null;
end case;
end if;
return Result;
end Get_GPIO_Functionality;
---------------
-- I2C_Write --
---------------
procedure I2C_Write
(This : VL53L0X_Ranging_Sensor;
Data : HAL.UInt8_Array;
Status : out Boolean)
is
use type HAL.I2C.I2C_Status;
Ret : HAL.I2C.I2C_Status;
begin
HAL.I2C.Master_Transmit
(This => This.Port.all,
Addr => This.I2C_Address,
Data => Data,
Status => Ret);
Status := Ret = HAL.I2C.Ok;
end I2C_Write;
--------------
-- I2C_Read --
--------------
procedure I2C_Read
(This : VL53L0X_Ranging_Sensor;
Data : out HAL.UInt8_Array;
Status : out Boolean)
is
use type HAL.I2C.I2C_Status;
Ret : HAL.I2C.I2C_Status;
begin
HAL.I2C.Master_Receive
(This => This.Port.all,
Addr => This.I2C_Address,
Data => Data,
Status => Ret);
Status := Ret = HAL.I2C.Ok;
end I2C_Read;
-----------
-- Write --
-----------
procedure Write
(This : VL53L0X_Ranging_Sensor;
Index : HAL.UInt8;
Data : HAL.UInt8_Array;
Status : out Boolean)
is
Buf : constant HAL.UInt8_Array := (1 => Index) & Data;
begin
I2C_Write (This, Buf, Status);
end Write;
-----------
-- Write --
-----------
procedure Write
(This : VL53L0X_Ranging_Sensor;
Index : HAL.UInt8;
Data : HAL.UInt8;
Status : out Boolean)
is
begin
I2C_Write (This, (Index, Data), Status);
end Write;
-----------
-- Write --
-----------
procedure Write
(This : VL53L0X_Ranging_Sensor;
Index : HAL.UInt8;
Data : HAL.UInt16;
Status : out Boolean)
is
begin
I2C_Write
(This,
(Index,
HAL.UInt8 (Shift_Right (Data, 8)),
HAL.UInt8 (Data and 16#FF#)),
Status);
end Write;
-----------
-- Write --
-----------
procedure Write
(This : VL53L0X_Ranging_Sensor;
Index : HAL.UInt8;
Data : HAL.UInt32;
Status : out Boolean)
is
begin
I2C_Write
(This,
(Index,
HAL.UInt8 (Shift_Right (Data, 24)),
HAL.UInt8 (Shift_Right (Data, 16) and 16#FF#),
HAL.UInt8 (Shift_Right (Data, 8) and 16#FF#),
HAL.UInt8 (Data and 16#FF#)),
Status);
end Write;
----------
-- Read --
----------
procedure Read
(This : VL53L0X_Ranging_Sensor;
Index : HAL.UInt8;
Data : out HAL.UInt8_Array;
Status : out Boolean)
is
begin
I2C_Write (This, (1 => Index), Status);
if Status then
I2C_Read (This, Data, Status);
end if;
end Read;
----------
-- Read --
----------
procedure Read
(This : VL53L0X_Ranging_Sensor;
Index : HAL.UInt8;
Data : out HAL.UInt8;
Status : out Boolean)
is
Buf : UInt8_Array (1 .. 1);
begin
I2C_Write (This, (1 => Index), Status);
if Status then
I2C_Read (This, Buf, Status);
Data := Buf (1);
end if;
end Read;
----------
-- Read --
----------
procedure Read
(This : VL53L0X_Ranging_Sensor;
Index : HAL.UInt8;
Data : out HAL.UInt16;
Status : out Boolean)
is
Buf : UInt8_Array (1 .. 2);
begin
I2C_Write (This, (1 => Index), Status);
if Status then
I2C_Read (This, Buf, Status);
Data := Shift_Left (UInt16 (Buf (1)), 8) or UInt16 (Buf (2));
end if;
end Read;
----------
-- Read --
----------
procedure Read
(This : VL53L0X_Ranging_Sensor;
Index : HAL.UInt8;
Data : out HAL.UInt32;
Status : out Boolean)
is
Buf : UInt8_Array (1 .. 4);
begin
I2C_Write (This, (1 => Index), Status);
if Status then
I2C_Read (This, Buf, Status);
Data := Shift_Left (UInt32 (Buf (1)), 24) or
Shift_Left (UInt32 (Buf (2)), 16) or
Shift_Left (UInt32 (Buf (3)), 8) or
UInt32 (Buf (4));
end if;
end Read;
--------------------
-- Decode_Timeout --
--------------------
function Decode_Timeout (Encoded : UInt16) return UInt32
is
LSByte : constant UInt32 := UInt32 (Encoded and 16#00_FF#);
MSByte : constant Natural :=
Natural (Shift_Right (Encoded and 16#FF_00#, 8));
begin
return LSByte * 2 ** MSByte + 1;
end Decode_Timeout;
--------------------
-- Encode_Timeout --
--------------------
function Encode_Timeout (Timeout : UInt32) return UInt16
is
LSByte : UInt32;
MSByte : UInt32 := 0;
begin
LSByte := Timeout - 1;
while (LSByte and 16#FFFF_FF00#) > 0 loop
LSByte := Shift_Right (LSByte, 1);
MSByte := MSByte + 1;
end loop;
return UInt16 (Shift_Left (MSByte, 8) or LSByte);
end Encode_Timeout;
----------------------
-- To_Timeout_Mclks --
----------------------
function To_Timeout_Mclks
(Timeout_Period_us : UInt32;
VCSel_Period_Pclks : UInt8) return UInt32
is
PLL_Period_Ps : constant := 1655;
Macro_Period_Vclks : constant := 2304;
Macro_Period_Ps : UInt32;
Macro_Period_Ns : UInt32;
begin
Macro_Period_Ps :=
UInt32 (VCSel_Period_Pclks) * PLL_Period_Ps * Macro_Period_Vclks;
Macro_Period_Ns := (Macro_Period_Ps + 500) / 1000;
return
(Timeout_Period_us * 1000 + Macro_Period_Ns / 2) / Macro_Period_Ns;
end To_Timeout_Mclks;
-----------------------------
-- To_Timeout_Microseconds --
-----------------------------
function To_Timeout_Microseconds
(Timeout_Period_Mclks : UInt32;
VCSel_Period_Pclks : UInt8) return UInt32
is
PLL_Period_Ps : constant := 1655;
Macro_Period_Vclks : constant := 2304;
Macro_Period_Ps : UInt32;
Macro_Period_Ns : UInt32;
begin
Macro_Period_Ps :=
UInt32 (VCSel_Period_Pclks) * PLL_Period_Ps * Macro_Period_Vclks;
Macro_Period_Ns := (Macro_Period_Ps + 500) / 1000;
return (Timeout_Period_Mclks * Macro_Period_Ns + 500) / 1000;
end To_Timeout_Microseconds;
----------------
-- Initialize --
----------------
procedure Initialize
(This : in out VL53L0X_Ranging_Sensor)
is
begin
This.I2C_Address := 16#52#;
end Initialize;
-------------
-- Read_Id --
-------------
function Read_Id (This : VL53L0X_Ranging_Sensor) return HAL.UInt16
is
Ret : UInt16;
Status : Boolean;
begin
Read (This, REG_IDENTIFICATION_MODEL_ID, Ret, Status);
if not Status then
return 0;
else
return Ret;
end if;
end Read_Id;
-------------------
-- Read_Revision --
-------------------
function Read_Revision (This : VL53L0X_Ranging_Sensor) return HAL.UInt8
is
Ret : UInt8;
Status : Boolean;
begin
Read (This, REG_IDENTIFICATION_REVISION_ID, Ret, Status);
if not Status then
return 0;
else
return Ret;
end if;
end Read_Revision;
------------------------
-- Set_Device_Address --
------------------------
procedure Set_Device_Address
(This : in out VL53L0X_Ranging_Sensor;
Addr : HAL.I2C.I2C_Address;
Status : out Boolean)
is
begin
Write (This, REG_I2C_SLAVE_DEVICE_ADDRESS, UInt8 (Addr / 2), Status);
if Status then
This.I2C_Address := Addr;
end if;
end Set_Device_Address;
---------------
-- Data_Init --
---------------
procedure Data_Init
(This : in out VL53L0X_Ranging_Sensor;
Status : out Boolean)
is
Regval : UInt8;
begin
-- Set I2C Standard mode
Write (This, 16#88#, UInt8'(16#00#), Status);
if not Status then
return;
end if;
-- This.Device_Specific_Params.Read_Data_From_Device_Done := False;
--
-- -- Set default static parameters:
-- -- set first temporary value 9.44MHz * 65536 = 618_660
-- This.Device_Specific_Params.Osc_Frequency := 618_660;
--
-- -- Set default cross talk compenstation rate to 0
-- This.Device_Params.X_Talk_Compensation_Rate_Mcps := 0.0;
--
-- This.Device_Params.Device_Mode := Single_Ranging;
-- This.Device_Params.Histogram_Mode := Disabled;
-- TODO: Sigma estimator variable
if Status then
Write (This, 16#80#, UInt8'(16#01#), Status);
end if;
if Status then
Write (This, 16#FF#, UInt8'(16#01#), Status);
end if;
if Status then
Write (This, 16#00#, UInt8'(16#00#), Status);
end if;
if Status then
Read (This, 16#91#, This.Stop_Variable, Status);
end if;
if Status then
Write (This, 16#00#, UInt8'(16#01#), Status);
end if;
if Status then
Write (This, 16#FF#, UInt8'(16#00#), Status);
end if;
if Status then
Write (This, 16#80#, UInt8'(16#00#), Status);
end if;
-- disable SIGNAL_RATE_MSRC (bit 1) and SIGNAL_RATE_PRE_RANGE (bit 4)
-- limit checks
if Status then
Read (This, REG_MSRC_CONFIG_CONTROL, Regval, Status);
end if;
if Status then
Write (This, REG_MSRC_CONFIG_CONTROL, Regval or 16#12#, Status);
end if;
if Status then
-- Set final range signal rate limit to 0.25 MCPS
Status := Set_Signal_Rate_Limit (This, 0.25);
end if;
if Status then
Write (This, REG_SYSTEM_SEQUENCE_CONFIG, UInt8'(16#FF#), Status);
end if;
end Data_Init;
-----------------
-- Static_Init --
-----------------
procedure Static_Init
(This : in out VL53L0X_Ranging_Sensor;
GPIO_Function : VL53L0X_GPIO_Functionality;
Status : out Boolean)
is
type SPAD_Map is array (UInt8 range 1 .. 48) of Boolean
with Pack, Size => 48;
subtype SPAD_Map_Bytes is UInt8_Array (1 .. 6);
function To_Map is new Ada.Unchecked_Conversion
(SPAD_Map_Bytes, SPAD_Map);
function To_Bytes is new Ada.Unchecked_Conversion
(SPAD_Map, SPAD_Map_Bytes);
SPAD_Count : UInt8;
SPAD_Is_Aperture : Boolean;
Ref_SPAD_Map_Bytes : SPAD_Map_Bytes;
Ref_SPAD_Map : SPAD_Map;
First_SPAD : UInt8;
SPADS_Enabled : UInt8;
Timing_Budget : UInt32;
begin
Status := SPAD_Info (This, SPAD_Count, SPAD_Is_Aperture);
if not Status then
return;
end if;
Read
(This, REG_GLOBAL_CONFIG_SPAD_ENABLES_REF_0,
Ref_SPAD_Map_Bytes, Status);
Ref_SPAD_Map := To_Map (Ref_SPAD_Map_Bytes);
-- Set reference spads
if Status then
Write (This, 16#FF#, UInt8'(16#01#), Status);
end if;
if Status then
Write (This, REG_DYNAMIC_SPAD_REF_EN_START_OFFSET,
UInt8'(16#00#), Status);
end if;
if Status then
Write (This, REG_DYNAMIC_SPAD_NUM_REQUESTED_REF_SPAD,
UInt8'(16#2C#), Status);
end if;
if Status then
Write (This, 16#FF#, UInt8'(16#00#), Status);
end if;
if Status then
Write (This, REG_GLOBAL_CONFIG_REF_EN_START_SELECT,
UInt8'(16#B4#), Status);
end if;
if Status then
if SPAD_Is_Aperture then
First_SPAD := 13;
else
First_SPAD := 1;
end if;
SPADS_Enabled := 0;
for J in UInt8 range 1 .. 48 loop
if J < First_SPAD or else SPADS_Enabled = SPAD_Count then
-- This bit is lower than the first one that should be enabled,
-- or SPAD_Count bits have already been enabled, so zero this
-- bit
Ref_SPAD_Map (J) := False;
elsif Ref_SPAD_Map (J) then
SPADS_Enabled := SPADS_Enabled + 1;
end if;
end loop;
end if;
if Status then
Ref_SPAD_Map_Bytes := To_Bytes (Ref_SPAD_Map);
Write (This, REG_GLOBAL_CONFIG_SPAD_ENABLES_REF_0,
Ref_SPAD_Map_Bytes, Status);
end if;
-- Load tuning Settings
-- default tuning settings from vl53l0x_tuning.h
if Status then
Write (This, 16#FF#, UInt8'(16#01#), Status);
Write (This, 16#00#, UInt8'(16#00#), Status);
Write (This, 16#FF#, UInt8'(16#00#), Status);
Write (This, 16#09#, UInt8'(16#00#), Status);
Write (This, 16#10#, UInt8'(16#00#), Status);
Write (This, 16#11#, UInt8'(16#00#), Status);
Write (This, 16#24#, UInt8'(16#01#), Status);
Write (This, 16#25#, UInt8'(16#FF#), Status);
Write (This, 16#75#, UInt8'(16#00#), Status);
Write (This, 16#FF#, UInt8'(16#01#), Status);
Write (This, 16#4E#, UInt8'(16#2C#), Status);
Write (This, 16#48#, UInt8'(16#00#), Status);
Write (This, 16#30#, UInt8'(16#20#), Status);
Write (This, 16#FF#, UInt8'(16#00#), Status);
Write (This, 16#30#, UInt8'(16#09#), Status);
Write (This, 16#54#, UInt8'(16#00#), Status);
Write (This, 16#31#, UInt8'(16#04#), Status);
Write (This, 16#32#, UInt8'(16#03#), Status);
Write (This, 16#40#, UInt8'(16#83#), Status);
Write (This, 16#46#, UInt8'(16#25#), Status);
Write (This, 16#60#, UInt8'(16#00#), Status);
Write (This, 16#27#, UInt8'(16#00#), Status);
Write (This, 16#50#, UInt8'(16#06#), Status);
Write (This, 16#51#, UInt8'(16#00#), Status);
Write (This, 16#52#, UInt8'(16#96#), Status);
Write (This, 16#56#, UInt8'(16#08#), Status);
Write (This, 16#57#, UInt8'(16#30#), Status);
Write (This, 16#61#, UInt8'(16#00#), Status);
Write (This, 16#62#, UInt8'(16#00#), Status);
Write (This, 16#64#, UInt8'(16#00#), Status);
Write (This, 16#65#, UInt8'(16#00#), Status);
Write (This, 16#66#, UInt8'(16#A0#), Status);
Write (This, 16#FF#, UInt8'(16#01#), Status);
Write (This, 16#22#, UInt8'(16#32#), Status);
Write (This, 16#47#, UInt8'(16#14#), Status);
Write (This, 16#49#, UInt8'(16#FF#), Status);
Write (This, 16#4A#, UInt8'(16#00#), Status);
Write (This, 16#FF#, UInt8'(16#00#), Status);
Write (This, 16#7A#, UInt8'(16#0A#), Status);
Write (This, 16#7B#, UInt8'(16#00#), Status);
Write (This, 16#78#, UInt8'(16#21#), Status);
Write (This, 16#FF#, UInt8'(16#01#), Status);
Write (This, 16#23#, UInt8'(16#34#), Status);
Write (This, 16#42#, UInt8'(16#00#), Status);
Write (This, 16#44#, UInt8'(16#FF#), Status);
Write (This, 16#45#, UInt8'(16#26#), Status);
Write (This, 16#46#, UInt8'(16#05#), Status);
Write (This, 16#40#, UInt8'(16#40#), Status);
Write (This, 16#0E#, UInt8'(16#06#), Status);
Write (This, 16#20#, UInt8'(16#1A#), Status);
Write (This, 16#43#, UInt8'(16#40#), Status);
Write (This, 16#FF#, UInt8'(16#00#), Status);
Write (This, 16#34#, UInt8'(16#03#), Status);
Write (This, 16#35#, UInt8'(16#44#), Status);
Write (This, 16#FF#, UInt8'(16#01#), Status);
Write (This, 16#31#, UInt8'(16#04#), Status);
Write (This, 16#4B#, UInt8'(16#09#), Status);
Write (This, 16#4C#, UInt8'(16#05#), Status);
Write (This, 16#4D#, UInt8'(16#04#), Status);
Write (This, 16#FF#, UInt8'(16#00#), Status);
Write (This, 16#44#, UInt8'(16#00#), Status);
Write (This, 16#45#, UInt8'(16#20#), Status);
Write (This, 16#47#, UInt8'(16#08#), Status);
Write (This, 16#48#, UInt8'(16#28#), Status);
Write (This, 16#67#, UInt8'(16#00#), Status);
Write (This, 16#70#, UInt8'(16#04#), Status);
Write (This, 16#71#, UInt8'(16#01#), Status);
Write (This, 16#72#, UInt8'(16#FE#), Status);
Write (This, 16#76#, UInt8'(16#00#), Status);
Write (This, 16#77#, UInt8'(16#00#), Status);
Write (This, 16#FF#, UInt8'(16#01#), Status);
Write (This, 16#0D#, UInt8'(16#01#), Status);
Write (This, 16#FF#, UInt8'(16#00#), Status);
Write (This, 16#80#, UInt8'(16#01#), Status);
Write (This, 16#01#, UInt8'(16#F8#), Status);
Write (This, 16#FF#, UInt8'(16#01#), Status);
Write (This, 16#8E#, UInt8'(16#01#), Status);
Write (This, 16#00#, UInt8'(16#01#), Status);
Write (This, 16#FF#, UInt8'(16#00#), Status);
Write (This, 16#80#, UInt8'(16#00#), Status);
end if;
Set_GPIO_Config (This, GPIO_Function, Polarity_High, Status);
if Status then
Timing_Budget := Measurement_Timing_Budget (This);
-- Disable MSRC and TCC by default
-- MSRC = Minimum Signal Rate Check
-- TCC = Target CenterCheck
Write (This, REG_SYSTEM_SEQUENCE_CONFIG, UInt8'(16#E8#), Status);
end if;
-- Recalculate the timing Budget
if Status then
Set_Measurement_Timing_Budget (This, Timing_Budget, Status);
end if;
end Static_Init;
------------------------------------
-- Perform_Single_Ref_Calibration --
------------------------------------
procedure Perform_Single_Ref_Calibration
(This : VL53L0X_Ranging_Sensor;
VHV_Init : UInt8;
Status : out Boolean)
is
Val : UInt8;
begin
Write (This, REG_SYSRANGE_START, VHV_Init or 16#01#, Status);
if not Status then
return;
end if;
loop
Read (This, REG_RESULT_INTERRUPT_STATUS, Val, Status);
exit when not Status;
exit when (Val and 16#07#) /= 0;
end loop;
if not Status then
return;
end if;
Write (This, REG_SYSTEM_INTERRUPT_CLEAR, UInt8'(16#01#), Status);
if not Status then
return;
end if;
Write (This, REG_SYSRANGE_START, UInt8'(16#00#), Status);
end Perform_Single_Ref_Calibration;
-----------------------------
-- Perform_Ref_Calibration --
-----------------------------
procedure Perform_Ref_Calibration
(This : in out VL53L0X_Ranging_Sensor;
Status : out Boolean)
is
begin
-- VHV calibration
Write (This, REG_SYSTEM_SEQUENCE_CONFIG, UInt8'(16#01#), Status);
if Status then
Perform_Single_Ref_Calibration (This, 16#40#, Status);
end if;
-- Phase calibration
if Status then
Write (This, REG_SYSTEM_SEQUENCE_CONFIG, UInt8'(16#02#), Status);
end if;
if Status then
Perform_Single_Ref_Calibration (This, 16#00#, Status);
end if;
-- Restore the sequence config
if Status then
Write (This, REG_SYSTEM_SEQUENCE_CONFIG, UInt8'(16#E8#), Status);
end if;
end Perform_Ref_Calibration;
----------------------
-- Start_Continuous --
----------------------
procedure Start_Continuous (This : VL53L0X.VL53L0X_Ranging_Sensor;
Period_Ms : HAL.UInt32;
Status : out Boolean) is
-- From vl53l0xStartContinuous() in
-- crazyflie-firmware/src/drivers/src/vl53l0x.c
begin
Write (This, 16#80#, UInt8'(16#01#), Status);
if Status then
Write (This, 16#ff#, UInt8'(16#01#), Status);
end if;
if Status then
Write (This, 16#00#, UInt8'(16#00#), Status);
end if;
if Status then
Write (This, 16#91#, UInt8'(This.Stop_Variable), Status);
end if;
if Status then
Write (This, 16#00#, UInt8'(16#01#), Status);
end if;
if Status then
Write (This, 16#ff#, UInt8'(16#00#), Status);
end if;
if Status then
Write (This, 16#80#, UInt8'(16#00#), Status);
end if;
if not Status then
return;
end if;
if Period_Ms /= 0 then
-- continuous timed mode
declare
procedure Set_Inter_Measurement_Period_Milliseconds;
-- The Crazyflie code indicates that this is a missing
-- function that they've inlined.
procedure Set_Inter_Measurement_Period_Milliseconds is
Osc_Calibrate_Val : UInt16;
Period : UInt32 := Period_Ms;
begin
Read (This, REG_OSC_CALIBRATE_VAL, Osc_Calibrate_Val, Status);
if Status and then Osc_Calibrate_Val /= 0 then
Period := Period * UInt32 (Osc_Calibrate_Val);
end if;
if Status then
Write
(This, REG_SYSTEM_INTERMEASUREMENT_PERIOD, Period, Status);
end if;
end Set_Inter_Measurement_Period_Milliseconds;
begin
Set_Inter_Measurement_Period_Milliseconds;
if Status then
Write (This,
REG_SYSRANGE_START,
UInt8'(REG_SYSRANGE_MODE_TIMED),
Status);
end if;
end;
else
-- continuous back-to-back mode
Write (This,
REG_SYSRANGE_START,
UInt8'(REG_SYSRANGE_MODE_BACKTOBACK),
Status);
end if;
end Start_Continuous;
------------------------------------
-- Start_Range_Single_Millimeters --
------------------------------------
procedure Start_Range_Single_Millimeters
(This : VL53L0X_Ranging_Sensor;
Status : out Boolean)
is
Val : UInt8;
begin
Write (This, 16#80#, UInt8'(16#01#), Status);
if Status then
Write (This, 16#FF#, UInt8'(16#01#), Status);
end if;
if Status then
Write (This, 16#00#, UInt8'(16#00#), Status);
end if;
if Status then
Write (This, 16#91#, This.Stop_Variable, Status);
end if;
if Status then
Write (This, 16#00#, UInt8'(16#01#), Status);
end if;
if Status then
Write (This, 16#FF#, UInt8'(16#00#), Status);
end if;
if Status then
Write (This, 16#80#, UInt8'(16#00#), Status);
end if;
if Status then
Write (This, REG_SYSRANGE_START, UInt8'(16#01#), Status);
end if;
if not Status then
return;
end if;
loop
Read (This, REG_SYSRANGE_START, Val, Status);
exit when not Status;
exit when (Val and 16#01#) = 0;
end loop;
end Start_Range_Single_Millimeters;
---------------------------
-- Range_Value_Available --
---------------------------
function Range_Value_Available
(This : VL53L0X_Ranging_Sensor) return Boolean
is
Status : Boolean with Unreferenced;
Val : UInt8;
begin
Read (This, REG_RESULT_INTERRUPT_STATUS, Val, Status);
return (Val and 16#07#) /= 0;
end Range_Value_Available;
----------------------------
-- Read_Range_Millimeters --
----------------------------
function Read_Range_Millimeters
(This : VL53L0X_Ranging_Sensor) return HAL.UInt16
is
Status : Boolean with Unreferenced;
Ret : HAL.UInt16;
begin
Read (This, REG_RESULT_RANGE_STATUS + 10, Ret, Status);
Write (This, REG_SYSTEM_INTERRUPT_CLEAR, UInt8'(16#01#), Status);
return Ret;
end Read_Range_Millimeters;
-----------------------------------
-- Read_Range_Single_Millimeters --
-----------------------------------
function Read_Range_Single_Millimeters
(This : VL53L0X_Ranging_Sensor) return HAL.UInt16
is
Status : Boolean;
begin
Start_Range_Single_Millimeters (This, Status);
if not Status then
return 4000;
end if;
while not Range_Value_Available (This) loop
This.Timing.Delay_Milliseconds (1);
end loop;
return Read_Range_Millimeters (This);
end Read_Range_Single_Millimeters;
---------------------
-- Set_GPIO_Config --
---------------------
procedure Set_GPIO_Config
(This : in out VL53L0X_Ranging_Sensor;
Functionality : VL53L0X_GPIO_Functionality;
Polarity : VL53L0X_Interrupt_Polarity;
Status : out Boolean)
is
Data : UInt8;
Tmp : UInt8;
begin
case Functionality is
when No_Interrupt =>
Data := 0;
when Level_Low =>
Data := 1;
when Level_High =>
Data := 2;
when Out_Of_Window =>
Data := 3;
when New_Sample_Ready =>
Data := 4;
end case;
-- 16#04#: interrupt on new measure ready
Write (This, REG_SYSTEM_INTERRUPT_CONFIG_GPIO, Data, Status);
-- Interrupt polarity
if Status then
case Polarity is
when Polarity_Low =>
Data := 16#10#;
when Polarity_High =>
Data := 16#00#;
end case;
Read (This, REG_GPIO_HV_MUX_ACTIVE_HIGH, Tmp, Status);
Tmp := (Tmp and 16#EF#) or Data;
Write (This, REG_GPIO_HV_MUX_ACTIVE_HIGH, Tmp, Status);
end if;
if Status then
Clear_Interrupt_Mask (This);
end if;
end Set_GPIO_Config;
--------------------------
-- Clear_Interrupt_Mask --
--------------------------
procedure Clear_Interrupt_Mask
(This : VL53L0X_Ranging_Sensor)
is
Status : Boolean with Unreferenced;
-- Tmp : UInt8;
begin
-- for J in 1 .. 3 loop
Write (This, REG_SYSTEM_INTERRUPT_CLEAR, UInt8'(16#01#), Status);
-- exit when not Status;
-- Write (This, REG_SYSTEM_INTERRUPT_CLEAR, UInt8'(16#00#), Status);
-- exit when not Status;
-- Read (This, REG_RESULT_INTERRUPT_STATUS, Tmp, Status);
-- exit when not Status;
-- exit when (Tmp and 16#07#) /= 0;
-- end loop;
end Clear_Interrupt_Mask;
---------------------------
-- Sequence_Step_Enabled --
---------------------------
function Sequence_Step_Enabled
(This : VL53L0X_Ranging_Sensor) return VL53L0x_Sequence_Step_Enabled
is
Sequence_Steps : VL53L0x_Sequence_Step_Enabled;
Sequence_Config : UInt8 := 0;
Status : Boolean;
function Sequence_Step_Enabled
(Step : VL53L0x_Sequence_Step;
Sequence_Config : UInt8) return Boolean;
---------------------------
-- Sequence_Step_Enabled --
---------------------------
function Sequence_Step_Enabled
(Step : VL53L0x_Sequence_Step;
Sequence_Config : UInt8) return Boolean
is
begin
case Step is
when TCC =>
return (Sequence_Config and 16#10#) /= 0;
when DSS =>
return (Sequence_Config and 16#08#) /= 0;
when MSRC =>
return (Sequence_Config and 16#04#) /= 0;
when Pre_Range =>
return (Sequence_Config and 16#40#) /= 0;
when Final_Range =>
return (Sequence_Config and 16#80#) /= 0;
end case;
end Sequence_Step_Enabled;
begin
Read (This, REG_SYSTEM_SEQUENCE_CONFIG, Sequence_Config, Status);
if not Status then
return (others => False);
end if;
for Step in Sequence_Steps'Range loop
Sequence_Steps (Step) :=
Sequence_Step_Enabled (Step, Sequence_Config);
end loop;
return Sequence_Steps;
end Sequence_Step_Enabled;
---------------------------
-- Sequence_Step_Timeout --
---------------------------
function Sequence_Step_Timeout
(This : VL53L0X_Ranging_Sensor;
Step : VL53L0x_Sequence_Step;
As_Mclks : Boolean := False) return UInt32
is
VCSel_Pulse_Period_Pclk : UInt8;
Encoded_UInt8 : UInt8;
Encoded_UInt16 : UInt16;
Status : Boolean;
Timeout_Mclks : UInt32;
Sequence_Steps : VL53L0x_Sequence_Step_Enabled;
begin
case Step is
when TCC | DSS | MSRC =>
Read (This, REG_MSRC_CONFIG_TIMEOUT_MACROP,
Encoded_UInt8, Status);
if Status then
Timeout_Mclks := Decode_Timeout (UInt16 (Encoded_UInt8));
end if;
if As_Mclks then
return Timeout_Mclks;
else
VCSel_Pulse_Period_Pclk :=
VCSel_Pulse_Period (This, Pre_Range);
return To_Timeout_Microseconds
(Timeout_Mclks, VCSel_Pulse_Period_Pclk);
end if;
when Pre_Range =>
Read (This, REG_PRE_RANGE_CONFIG_TIMEOUT_MACROP_HI,
Encoded_UInt16, Status);
if Status then
Timeout_Mclks := Decode_Timeout (Encoded_UInt16);
end if;
if As_Mclks then
return Timeout_Mclks;
else
VCSel_Pulse_Period_Pclk :=
VCSel_Pulse_Period (This, Pre_Range);
return To_Timeout_Microseconds
(Timeout_Mclks, VCSel_Pulse_Period_Pclk);
end if;
when Final_Range =>
Sequence_Steps := Sequence_Step_Enabled (This);
if Sequence_Steps (Pre_Range) then
VCSel_Pulse_Period_Pclk :=
VCSel_Pulse_Period (This, Pre_Range);
Read (This, REG_PRE_RANGE_CONFIG_TIMEOUT_MACROP_HI,
Encoded_UInt16, Status);
if Status then
Timeout_Mclks := Decode_Timeout (Encoded_UInt16);
end if;
else
Timeout_Mclks := 0;
end if;
VCSel_Pulse_Period_Pclk :=
VCSel_Pulse_Period (This, Final_Range);
Read (This, REG_FINAL_RANGE_CONFIG_TIMEOUT_MACROP_HI,
Encoded_UInt16, Status);
Timeout_Mclks :=
Decode_Timeout (Encoded_UInt16) - Timeout_Mclks;
if As_Mclks then
return Timeout_Mclks;
else
return To_Timeout_Microseconds
(Timeout_Mclks, VCSel_Pulse_Period_Pclk);
end if;
end case;
end Sequence_Step_Timeout;
-------------------------------
-- Measurement_Timing_Budget --
-------------------------------
function Measurement_Timing_Budget
(This : VL53L0X_Ranging_Sensor) return HAL.UInt32
is
Ret : UInt32;
Pre_Range_Timeout : UInt32;
Final_Range_Timeout : UInt32;
Sequence_Steps : VL53L0x_Sequence_Step_Enabled;
Msrc_Dcc_Tcc_Timeout : UInt32;
begin
Ret := Start_Overhead + End_Overhead;
Sequence_Steps := Sequence_Step_Enabled (This);
if Sequence_Steps (TCC)
or else Sequence_Steps (MSRC)
or else Sequence_Steps (DSS)
then
Msrc_Dcc_Tcc_Timeout := Sequence_Step_Timeout (This, MSRC);
if Sequence_Steps (TCC) then
Ret := Ret + Msrc_Dcc_Tcc_Timeout + Tcc_Overhead;
end if;
if Sequence_Steps (DSS) then
Ret := Ret + 2 * (Msrc_Dcc_Tcc_Timeout + Dss_Overhead);
elsif Sequence_Steps (MSRC) then
Ret := Ret + Msrc_Dcc_Tcc_Timeout + Msrc_Overhead;
end if;
end if;
if Sequence_Steps (Pre_Range) then
Pre_Range_Timeout := Sequence_Step_Timeout (This, Pre_Range);
Ret := Ret + Pre_Range_Timeout + Pre_Range_Overhead;
end if;
if Sequence_Steps (Final_Range) then
Final_Range_Timeout := Sequence_Step_Timeout (This, Final_Range);
Ret := Ret + Final_Range_Timeout + Final_Range_Overhead;
end if;
return Ret;
end Measurement_Timing_Budget;
-----------------------------------
-- Set_Measurement_Timing_Budget --
-----------------------------------
procedure Set_Measurement_Timing_Budget
(This : VL53L0X_Ranging_Sensor;
Budget_Micro_Seconds : HAL.UInt32;
Status : out Boolean)
is
Final_Range_Timing_Budget_us : UInt32;
Sequence_Steps : VL53L0x_Sequence_Step_Enabled;
Pre_Range_Timeout_us : UInt32 := 0;
Sub_Timeout : UInt32 := 0;
Msrc_Dcc_Tcc_Timeout : UInt32;
begin
Status := True;
Final_Range_Timing_Budget_us :=
Budget_Micro_Seconds - Start_Overhead - End_Overhead
- Final_Range_Overhead;
Sequence_Steps := Sequence_Step_Enabled (This);
if not Sequence_Steps (Final_Range) then
return;
end if;
if Sequence_Steps (TCC)
or else Sequence_Steps (MSRC)
or else Sequence_Steps (DSS)
then
Msrc_Dcc_Tcc_Timeout := Sequence_Step_Timeout (This, MSRC);
if Sequence_Steps (TCC) then
Sub_Timeout := Msrc_Dcc_Tcc_Timeout + Tcc_Overhead;
end if;
if Sequence_Steps (DSS) then
Sub_Timeout :=
Sub_Timeout + 2 * (Msrc_Dcc_Tcc_Timeout + Dss_Overhead);
elsif Sequence_Steps (MSRC) then
Sub_Timeout := Sub_Timeout + Msrc_Dcc_Tcc_Timeout + Msrc_Overhead;
end if;
end if;
if Sequence_Steps (Pre_Range) then
Pre_Range_Timeout_us := Sequence_Step_Timeout (This, Pre_Range);
Sub_Timeout :=
Sub_Timeout + Pre_Range_Timeout_us + Pre_Range_Overhead;
end if;
if Sub_Timeout < Final_Range_Timing_Budget_us then
Final_Range_Timing_Budget_us :=
Final_Range_Timing_Budget_us - Sub_Timeout;
else
-- Requested timeout too big
Status := False;
return;
end if;
declare
VCSel_Pulse_Period_Pclk : UInt8;
Encoded_UInt16 : UInt16;
Timeout_Mclks : UInt32;
begin
if Sequence_Steps (Pre_Range) then
VCSel_Pulse_Period_Pclk :=
VCSel_Pulse_Period (This, Pre_Range);
Read (This, REG_PRE_RANGE_CONFIG_TIMEOUT_MACROP_HI,
Encoded_UInt16, Status);
if Status then
Timeout_Mclks := Decode_Timeout (Encoded_UInt16);
end if;
else
Timeout_Mclks := 0;
end if;
VCSel_Pulse_Period_Pclk :=
VCSel_Pulse_Period (This, Final_Range);
Timeout_Mclks := Timeout_Mclks + To_Timeout_Mclks
(Final_Range_Timing_Budget_us,
VCSel_Pulse_Period_Pclk);
Write (This, REG_FINAL_RANGE_CONFIG_TIMEOUT_MACROP_HI,
Encode_Timeout (Timeout_Mclks), Status);
end;
return;
end Set_Measurement_Timing_Budget;
---------------------------
-- Set_Signal_Rate_Limit --
---------------------------
function Set_Signal_Rate_Limit
(This : VL53L0X_Ranging_Sensor;
Limit_Mcps : Fix_Point_16_16) return Boolean
is
function To_U32 is new Ada.Unchecked_Conversion
(Fix_Point_16_16, UInt32);
Val : UInt16;
Status : Boolean;
begin
-- Expecting Fixed Point 9.7
Val := UInt16 (Shift_Right (To_U32 (Limit_Mcps), 9) and 16#FF_FF#);
Write (This,
REG_FINAL_RANGE_CONFIG_MIN_COUNT_RATE_RTN_LIMIT,
Val,
Status);
return Status;
end Set_Signal_Rate_Limit;
---------------
-- SPAD_Info --
---------------
function SPAD_Info
(This : VL53L0X_Ranging_Sensor;
SPAD_Count : out HAL.UInt8;
Is_Aperture : out Boolean) return Boolean
is
Status : Boolean;
Tmp : UInt8;
begin
Write (This, 16#80#, UInt8'(16#01#), Status);
if Status then
Write (This, 16#FF#, UInt8'(16#01#), Status);
end if;
if Status then
Write (This, 16#00#, UInt8'(16#00#), Status);
end if;
if Status then
Write (This, 16#FF#, UInt8'(16#06#), Status);
end if;
if Status then
Read (This, 16#83#, Tmp, Status);
end if;
if Status then
Write (This, 16#83#, Tmp or 16#04#, Status);
end if;
if Status then
Write (This, 16#FF#, UInt8'(16#07#), Status);
end if;
if Status then
Write (This, 16#81#, UInt8'(16#01#), Status);
end if;
if Status then
Write (This, 16#80#, UInt8'(16#01#), Status);
end if;
if Status then
Write (This, 16#94#, UInt8'(16#6B#), Status);
end if;
if Status then
Write (This, 16#83#, UInt8'(16#00#), Status);
end if;
loop
exit when not Status;
Read (This, 16#83#, Tmp, Status);
exit when Tmp /= 0;
end loop;
if Status then
Write (This, 16#83#, UInt8'(16#01#), Status);
end if;
if Status then
Read (This, 16#92#, Tmp, Status);
end if;
if Status then
SPAD_Count := Tmp and 16#7F#;
Is_Aperture := (Tmp and 16#80#) /= 0;
Write (This, 16#81#, UInt8'(16#00#), Status);
end if;
if Status then
Write (This, 16#FF#, UInt8'(16#06#), Status);
end if;
if Status then
Read (This, 16#83#, Tmp, Status);
end if;
if Status then
Write (This, 16#83#, Tmp and not 16#04#, Status);
end if;
if Status then
Write (This, 16#FF#, UInt8'(16#01#), Status);
end if;
if Status then
Write (This, 16#00#, UInt8'(16#01#), Status);
end if;
if Status then
Write (This, 16#FF#, UInt8'(16#00#), Status);
end if;
if Status then
Write (This, 16#80#, UInt8'(16#00#), Status);
end if;
return Status;
end SPAD_Info;
---------------------------
-- Set_Signal_Rate_Limit --
---------------------------
procedure Set_Signal_Rate_Limit
(This : VL53L0X_Ranging_Sensor;
Rate_Limit : Fix_Point_16_16)
is
function To_U32 is new Ada.Unchecked_Conversion
(Fix_Point_16_16, UInt32);
Reg : UInt16;
Status : Boolean with Unreferenced;
begin
-- Encoded as Fixed Point 9.7. Let's translate.
Reg := UInt16 (Shift_Right (To_U32 (Rate_Limit), 9) and 16#FFFF#);
Write (This, REG_FINAL_RANGE_CONFIG_MIN_COUNT_RATE_RTN_LIMIT,
Reg, Status);
end Set_Signal_Rate_Limit;
--------------------------------------
-- Set_Vcsel_Pulse_Period_Pre_Range --
--------------------------------------
procedure Set_VCSEL_Pulse_Period_Pre_Range
(This : VL53L0X_Ranging_Sensor;
Period : UInt8;
Status : out Boolean)
is
begin
Set_VCSel_Pulse_Period (This, Period, Pre_Range, Status);
end Set_VCSEL_Pulse_Period_Pre_Range;
----------------------------------------
-- Set_Vcsel_Pulse_Period_Final_Range --
----------------------------------------
procedure Set_VCSEL_Pulse_Period_Final_Range
(This : VL53L0X_Ranging_Sensor;
Period : UInt8;
Status : out Boolean)
is
begin
Set_VCSel_Pulse_Period (This, Period, Final_Range, Status);
end Set_VCSEL_Pulse_Period_Final_Range;
----------------------------
-- Set_VCSel_Pulse_Period --
----------------------------
procedure Set_VCSel_Pulse_Period
(This : VL53L0X_Ranging_Sensor;
Period : UInt8;
Sequence : VL53L0x_Sequence_Step;
Status : out Boolean)
is
Encoded : constant UInt8 := Shift_Right (Period, 1) - 1;
Phase_High : UInt8;
Pre_Timeout : UInt32;
Final_Timeout : UInt32;
Msrc_Timeout : UInt32;
Timeout_Mclks : UInt32;
Steps_Enabled : constant VL53L0x_Sequence_Step_Enabled :=
Sequence_Step_Enabled (This);
Budget : UInt32;
Sequence_Cfg : UInt8;
begin
-- Save the measurement timing budget
Budget := Measurement_Timing_Budget (This);
case Sequence is
when Pre_Range =>
Pre_Timeout := Sequence_Step_Timeout (This, Pre_Range);
Msrc_Timeout := Sequence_Step_Timeout (This, MSRC);
case Period is
when 12 =>
Phase_High := 16#18#;
when 14 =>
Phase_High := 16#30#;
when 16 =>
Phase_High := 16#40#;
when 18 =>
Phase_High := 16#50#;
when others =>
Status := False;
return;
end case;
Write (This, REG_PRE_RANGE_CONFIG_VALID_PHASE_HIGH,
Phase_High, Status);
if not Status then
return;
end if;
Write (This, REG_PRE_RANGE_CONFIG_VALID_PHASE_LOW,
UInt8'(16#08#), Status);
if not Status then
return;
end if;
Write (This, REG_PRE_RANGE_CONFIG_VCSEL_PERIOD,
Encoded, Status);
if not Status then
return;
end if;
-- Update the timeouts
Timeout_Mclks := To_Timeout_Mclks (Pre_Timeout, Period);
Write (This, REG_PRE_RANGE_CONFIG_TIMEOUT_MACROP_HI,
UInt16 (Timeout_Mclks), Status);
Timeout_Mclks := To_Timeout_Mclks (Msrc_Timeout, Period);
if Timeout_Mclks > 256 then
Timeout_Mclks := 255;
else
Timeout_Mclks := Timeout_Mclks - 1;
end if;
Write (This, REG_MSRC_CONFIG_TIMEOUT_MACROP,
UInt8 (Timeout_Mclks), Status);
when Final_Range =>
Pre_Timeout := Sequence_Step_Timeout
(This, Pre_Range, As_Mclks => True);
Final_Timeout := Sequence_Step_Timeout (This, Final_Range);
declare
Phase_High : UInt8;
Width : UInt8;
Cal_Timeout : UInt8;
Cal_Lim : UInt8;
begin
case Period is
when 8 =>
Phase_High := 16#10#;
Width := 16#02#;
Cal_Timeout := 16#0C#;
Cal_Lim := 16#30#;
when 10 =>
Phase_High := 16#28#;
Width := 16#03#;
Cal_Timeout := 16#09#;
Cal_Lim := 16#20#;
when 12 =>
Phase_High := 16#38#;
Width := 16#03#;
Cal_Timeout := 16#08#;
Cal_Lim := 16#20#;
when 14 =>
Phase_High := 16#48#;
Width := 16#03#;
Cal_Timeout := 16#07#;
Cal_Lim := 16#20#;
when others =>
return;
end case;
Write (This, REG_FINAL_RANGE_CONFIG_VALID_PHASE_HIGH,
Phase_High, Status);
if not Status then
return;
end if;
Write (This, REG_FINAL_RANGE_CONFIG_VALID_PHASE_LOW,
UInt8'(16#08#), Status);
if not Status then
return;
end if;
Write (This, REG_GLOBAL_CONFIG_VCSEL_WIDTH,
Width, Status);
if not Status then
return;
end if;
Write (This, REG_ALGO_PHASECAL_CONFIG_TIMEOUT,
Cal_Timeout, Status);
if not Status then
return;
end if;
Write (This, 16#FF#, UInt8'(16#01#), Status);
Write (This, REG_ALGO_PHASECAL_LIM,
Cal_Lim, Status);
Write (This, 16#FF#, UInt8'(16#00#), Status);
if not Status then
return;
end if;
end;
-- Apply new VCSEL period
Write (This, REG_FINAL_RANGE_CONFIG_VCSEL_PERIOD,
Encoded, Status);
-- Update timeouts
Timeout_Mclks := To_Timeout_Mclks (Final_Timeout, Period);
if Steps_Enabled (Pre_Range) then
-- the pre-range timeout must be added in this case
Timeout_Mclks := Timeout_Mclks + Pre_Timeout;
end if;
Write (This, REG_FINAL_RANGE_CONFIG_TIMEOUT_MACROP_HI,
Encode_Timeout (Timeout_Mclks), Status);
when others =>
Status := False;
return;
end case;
if Status then
-- Restore the measurement timing budget
Set_Measurement_Timing_Budget (This, Budget, Status);
end if;
-- And finally perform the phase calibration.
Read (This, REG_SYSTEM_SEQUENCE_CONFIG, Sequence_Cfg, Status);
if Status then
Write (This, REG_SYSTEM_SEQUENCE_CONFIG, UInt8'(16#02#), Status);
end if;
if Status then
Perform_Single_Ref_Calibration (This, 16#00#, Status);
end if;
if Status then
Write (This, REG_SYSTEM_SEQUENCE_CONFIG, Sequence_Cfg, Status);
end if;
end Set_VCSel_Pulse_Period;
------------------------
-- VCSel_Pulse_Period --
------------------------
function VCSel_Pulse_Period
(This : VL53L0X_Ranging_Sensor;
Sequence : VL53L0x_Sequence_Step) return UInt8
is
Ret : UInt8;
Status : Boolean;
begin
case Sequence is
when Pre_Range =>
Read (This, REG_PRE_RANGE_CONFIG_VCSEL_PERIOD,
Ret, Status);
when Final_Range =>
Read (This, REG_FINAL_RANGE_CONFIG_VCSEL_PERIOD,
Ret, Status);
when others =>
Status := False;
end case;
if Status then
return Shift_Left (Ret + 1, 1);
else
return 0;
end if;
end VCSel_Pulse_Period;
end VL53L0X;
|
------------------------------------------------------------------------------
-- G P S --
-- --
-- Copyright (C) 2001-2016, AdaCore --
-- --
-- This 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. This software is distributed in the hope that it will be useful, --
-- but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- --
-- TABILITY 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 this software; see file --
-- COPYING3. If not, go to http://www.gnu.org/licenses for a complete copy --
-- of the license. --
------------------------------------------------------------------------------
-- This package provides a set of subprograms for manipulating and parsing
-- strings.
with GNAT.Strings;
with Interfaces.C.Strings;
with Basic_Types; use Basic_Types;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
package String_Utils is
function "+"
(S : String) return Unbounded_String renames To_Unbounded_String;
function "+"
(S : Unbounded_String) return String renames To_String;
-- Utility conversion operators from String to Unbounded_String
function Hex_Value (Hex : String) return Natural;
-- Return the value for the hexadecimal number Hex. Raises
-- Constraint_Error is Hex is not an hexadecimal number.
procedure Skip_To_Blank
(Type_Str : String;
Index : in out Natural);
-- Skip to the next blank character
procedure Skip_To_Index
(Buffer : String;
Columns : out Visible_Column_Type;
Index_In_Line : String_Index_Type;
Index : in out String_Index_Type;
Tab_Width : Positive := 8);
procedure Skip_To_Index
(Buffer : Unbounded_String;
Columns : out Visible_Column_Type;
Index_In_Line : String_Index_Type;
Index : in out String_Index_Type;
Tab_Width : Positive := 8);
-- Assuming Index points to the begining of a line, move the index by
-- "Index_In_Line" characters, and give the new column value.
procedure Skip_Hexa_Digit
(Type_Str : String;
Index : in out Natural);
-- Move Index to the first character that can not be part of an hexadecimal
-- digit. Note that an hexadecimal digit can optionally start with '0x',
-- which is the only case where x is recognized as part of the digit.
procedure Skip_To_Char
(Type_Str : String;
Index : in out Natural;
Char : Character;
Step : Integer := 1);
procedure Skip_To_Char
(Type_Str : Unbounded_String;
Index : in out Natural;
Char : Character;
Step : Integer := 1);
-- Skip every character up to the first occurence of Char in the string.
-- If no occurrence found, then Index is set over Type_Str'Last.
procedure Skip_Word
(Type_Str : String;
Index : in out Natural;
Step : Integer := 1);
-- Skip the word starting at Index (at least one character, even if there
-- is no word).
-- Currently, a word is defined as any string made of alphanumeric
-- character or underscore.
procedure Skip_CPP_Token
(Type_Str : String;
Index : in out Natural;
Step : Integer := 1);
-- Skip the cpp token starting at Index (at least one character, even if
-- there is no cpp token).
-- Currently, a cpp token is defined as any string made of alphanumeric
-- character, underscore or period.
function Tab_Width return Positive;
pragma Inline (Tab_Width);
-- Default value of tab width in the text editor (current value is 8)
function Lines_Count (Text : String) return Natural;
-- Return the number of lines in Text
function Blank_Slice
(Count : Integer;
Use_Tabs : Boolean := False;
Tab_Width : Positive := 8) return String;
-- Return a string representing count blanks.
-- If Use_Tabs is True, use ASCII.HT characters as much as possible,
-- otherwise use only spaces.
-- Return a null string if Count is negative.
function Is_Blank (C : Character) return Boolean;
-- Return True if C is a blank character: CR, LF, HT or ' '
procedure Next_Line
(Buffer : String;
P : Natural;
Next : out Natural;
Success : out Boolean);
-- Return the start of the next line in Next or Buffer'Last if the end of
-- the buffer is reached.
-- Success is set to True if a new line was found, false otherwise (end of
-- buffer reached).
procedure Parse_Num
(Type_Str : String;
Index : in out Natural;
Result : out Long_Integer);
-- Parse the integer found at position Index in Type_Str.
-- Index is set to the position of the first character that does not
-- belong to the integer.
function Looking_At
(Type_Str : String;
Index : Natural;
Substring : String) return Boolean;
-- Return True if the characters starting at Index in Type_Str are
-- equivalent to Substring.
procedure Parse_Cst_String
(Type_Str : String;
Index : in out Natural;
Str : out String;
Str_Last : out Natural;
Backslash_Special : Boolean := True);
-- Parse the string pointed to by Index, and copy the result in Str.
-- Index must point to the opening " character, and will be set to
-- point after the closing " character.
-- Special characters, as output by gdb (["0a"]) are also interpreted
-- and converted to the equivalent Character value.
-- Str must be long enough to contain the string, not check is done. As a
-- special case, if Str'Length = 0 then no attempt is done to fill up
-- the string, and only Length is computed. Str_Last is set to the last
-- meaningful character in Str.
--
-- Index is set to the number of characters parsed in the string.
procedure Skip_Simple_Value
(Type_Str : String;
Index : in out Natural;
Array_Item_Separator : Character := ',';
End_Of_Array : Character := ')';
Repeat_Item_Start : Character := '<');
-- Skip the value of a simple value ("65 'A'" for instance).
-- This stops at the first special character.
--
-- Array_Item_Separator is the separator in an array value (ie "5, 2, 3").
-- End_Of_Array is the array that indicates the end of an array value, as
-- in "((1, 2), (3, 4))".
-- Repeat_Item_Start if the character that starts a repeat statements, as
-- in "<repeats .. times>"
function Reduce
(S : String;
Max_Length : Positive := Positive'Last;
Continuation : String := "...") return String;
-- Replace in string S all ASCII.LF and ASCII.HT characters with a space,
-- and replace multiple spaces with a single one. Return the resulting
-- string with at most Max_Length character including the continuation
-- characters. S should be encoded in UTF-8.
function Krunch
(S : String;
Max_String_Length : Positive := 20) return String;
-- If String is less than Max_String_Length characters long, return it,
-- otherwise return a krunched string no longer than Max_String_Length.
procedure Strip_CR
(Text : in out String;
Last : out Integer;
CR_Found : out Boolean);
-- Same as above, but works on Text, and more efficient
-- Text (Text'First .. Last) contains the new result.
-- CR_Found is set to True if a CR was found in Text.
procedure Strip_CR_And_NUL
(Text : in out String;
Last : out Integer;
CR_Found : out Boolean;
NUL_Found : out Boolean;
Trailing_Space_Found : out Boolean);
-- Same as Strip_CR, and strip also ASCII.NUL characters
-- Note that CR chars alone are not replaced by LF chars.
-- Also check if Text has trailing spaces in a line.
function Strip_Ending_Linebreaks (Text : String) return String;
-- Return a version of Text after stripping all ending CR and LF
-- characters.
function Do_Tab_Expansion
(Text : String; Tab_Size : Integer) return String;
-- Return a version of Text after all tabs have been correctly expanded
-- depending on the value of Tab_Size.
-- This function works correctly with multiple-line strings.
function Strip_Quotes (S : String) return String;
-- Remove the quotes and the spaces at the beginning and end of S
function Strip_Single_Underscores (S : String) return String;
-- Return S stripped of single underscores, and with multiple underscores
-- concatenated into one.
-- This is used to process menu shortcuts, for example
-- Strip_Single_Underscores ("/_Project/C_lean") returns "/Project/Clean"
function Image (N : Integer) return String;
-- Create a string image of the given Integer
function Safe_Value (S : String; Default : Integer := 1) return Integer;
-- Convert S to a Natural, making sure there is no exception raised.
-- If S doesn't contain a valid number, Default is returned.
function Number_Of_Digits (N : Integer) return Natural;
-- Return the number of digits for the given Integer number;
function Is_Entity_Letter (Char : Wide_Wide_Character) return Boolean;
pragma Inline (Is_Entity_Letter);
-- Return True if the given letter is a valid letter for an entity name
-- (ie if the letter is either alphanumeric or an '_').
function Is_Operator_Letter (Char : Wide_Wide_Character) return Boolean;
-- Return True if the given letter is a valid operator
function Is_File_Letter (Char : Wide_Wide_Character) return Boolean;
pragma Inline (Is_File_Letter);
-- Return True if the given letter is a valid letter for a file name.
procedure Replace
(S : in out GNAT.Strings.String_Access;
Value : String);
-- Set S to Value, free previous content if any
procedure Replace
(S : in out GNAT.Strings.String_Access;
Value : GNAT.Strings.String_Access);
-- Idem, but does nothing if Value is null
function Has_Include_Directive (Str : String) return Boolean;
-- Return True is Str contains an #include directive
-------------------
-- Argument_List --
-------------------
function Clone
(List : GNAT.Strings.String_List) return GNAT.Strings.String_List;
-- Return a deep-copy of List. The returned value must be freed by the
-- caller.
procedure Append
(List : in out GNAT.Strings.String_List_Access;
List2 : GNAT.Strings.String_List);
procedure Append
(List : in out GNAT.Strings.String_List_Access;
Item : String);
-- Append all the strings in List2 to the end of List.
-- The strings in List2 are not duplicated.
-- List might be null initially.
---------------------------
-- C String manipulation --
---------------------------
procedure Copy_String
(Item : Interfaces.C.Strings.chars_ptr;
Str : out String;
Len : Natural);
-- Copy Len characters from Item to Str
----------------------------
-- Arguments manipulation --
----------------------------
function Protect
(S : String;
Protect_Quotes : Boolean := True;
Protect_Spaces : Boolean := False;
Protect_Backslashes : Boolean := True) return String;
-- Escape special characters in S.
-- Quotes are only escaped when Protect_Quotes is true.
-- Spaces are only escaped when Protect_Spaces is true.
function Unprotect (S : String) return String;
-- Unprotect an argument: remove the leading and ending '"',
-- and un-escape the "\" when necessary.
function Unquote (S : String) return String;
-- Remove the leading and ending '"' if present
function Revert (S : String; Separator : String := ".") return String;
-- Given a string S composed of names separated with Separator
-- (e.g. Put_Line.Text_IO.Ada), return the names reversed
-- (e.g. Ada.Text_IO.Put_Line).
----------------------
-- URL manipulation --
----------------------
function URL_Decode (URL : String) return String;
-- Decode URL into a regular string. Many characters are forbiden into an
-- URL and needs to be encoded. A character is encoded by %XY where XY is
-- the character's ASCII hexadecimal code. For example a space is encoded
-- as %20.
function Compare (A, B : String) return Integer;
function Compare (A, B : Integer) return Integer;
-- Return -1 if A<B, 1 if A>B and 0 otherwise. This routine is useful for
-- model specific sorting. The second version does the same comparing
-- integers. Even if not using string, it is better to keep this routine
-- next to the compare based on strings.
----------
-- Hash --
----------
generic
type Header_Num is range <>;
function Hash (Key : String) return Header_Num;
-- A generic hashing function working on String keys
generic
type Header_Num is range <>;
function Case_Insensitive_Hash (Key : String) return Header_Num;
-- A generic hashing function working on case insensitive String keys
private
pragma Inline (Is_Blank);
pragma Inline (Looking_At);
pragma Inline (Skip_To_Char);
pragma Inline (Copy_String);
pragma Inline (Replace);
pragma Inline (Compare);
end String_Utils;
|
package openGL.Model.sphere
--
-- Provides an abstract model of a sphere.
--
is
type Item is abstract new Model.item with private;
type View is access all Item'Class;
default_latitude_Count : constant := 26;
default_longitude_Count : constant := 52;
---------
--- Forge
--
procedure define (Self : out Item; Radius : Real);
--------------
--- Attributes
--
overriding
function Bounds (Self : in Item) return openGL.Bounds;
private
type Item is abstract new Model.item with
record
Radius : Real;
lat_Count : Positive;
long_Count : Positive;
end record;
Degrees_180 : constant := Pi;
Degrees_360 : constant := Pi * 2.0;
end openGL.Model.sphere;
|
-- { dg-do compile }
-- { dg-options "-O" }
procedure Opt19 is
type Enum is (One, Two);
type Vector_T is array (Enum) of Integer;
Zero_Vector : constant Vector_T := (Enum => 0);
type T is record
Vector : Vector_T;
end record;
procedure Nested (Value : in out T; E : Enum; B : out Boolean) is
I : Integer renames Value.Vector(E);
begin
B := I /= 0;
end;
Obj : T := (Vector => Zero_Vector);
B : Boolean;
begin
Nested (Obj, One, B);
end;
|
------------------------------------------------------------------------------
-- --
-- ASIS-for-GNAT IMPLEMENTATION COMPONENTS --
-- --
-- A 4 G . A S I S _ T A B L E S --
-- --
-- B o d y --
-- --
-- Copyright (C) 1995-2009, 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). --
-- --
------------------------------------------------------------------------------
with Asis.Elements; use Asis.Elements;
with Atree; use Atree;
with Sinput; use Sinput;
with Einfo; use Einfo;
with Nlists; use Nlists;
package body A4G.Asis_Tables is
---------------------
-- Add_New_Element --
---------------------
procedure Add_New_Element (Element : Asis.Element) is
Found : Boolean := False;
begin
for J in 1 .. Asis_Element_Table.Last loop
if Is_Equal (Element, Asis_Element_Table.Table (J)) then
Found := True;
exit;
end if;
end loop;
if not Found then
Asis_Element_Table.Append (Element);
end if;
end Add_New_Element;
-----------------------
-- Create_Node_Trace --
-----------------------
procedure Create_Node_Trace (N : Node_Id) is
Next_Node : Node_Id;
Next_Sloc : Source_Ptr;
Next_Node_Rec : Node_Trace_Rec;
begin
Node_Trace.Init;
Next_Node := N;
while Present (Next_Node) loop
Next_Sloc := Sloc (Next_Node);
Next_Node_Rec.Kind := Nkind (Next_Node);
Next_Node_Rec.Node_Line := Get_Physical_Line_Number (Next_Sloc);
Next_Node_Rec.Node_Col := Get_Column_Number (Next_Sloc);
Node_Trace.Append (Next_Node_Rec);
Next_Node := Enclosing_Scope (Next_Node);
end loop;
end Create_Node_Trace;
---------------------
-- Enclosing_Scope --
---------------------
function Enclosing_Scope (N : Node_Id) return Node_Id is
Result : Node_Id := N;
Entity_Node : Entity_Id := Empty;
begin
if Nkind (Result) = N_Package_Declaration then
Entity_Node := Defining_Unit_Name (Sinfo.Specification (Result));
elsif Nkind (Result) = N_Package_Body then
Entity_Node := Defining_Unit_Name (Result);
end if;
if Nkind (Entity_Node) = N_Defining_Program_Unit_Name then
Entity_Node := Sinfo.Defining_Identifier (Entity_Node);
end if;
if Present (Entity_Node) and then
Is_Generic_Instance (Entity_Node)
then
-- going to the corresponding instantiation
if Nkind (Parent (Result)) = N_Compilation_Unit then
-- We are at the top/ and we do not need a library-level
-- instantiation - it is always unique in the compilation
-- unit
Result := Empty;
else
-- "local" instantiation, therefore - one or two steps down the
-- declaration list to get in the instantiation node:
Result := Next_Non_Pragma (Result);
if Nkind (Result) = N_Package_Body then
-- This is an expanded generic body
Result := Next_Non_Pragma (Result);
end if;
end if;
else
-- One step up to the enclosing scope
Result := Parent (Result);
while not (Nkind (Result) = N_Package_Specification or else
Nkind (Result) = N_Package_Body or else
Nkind (Result) = N_Compilation_Unit or else
Nkind (Result) = N_Subprogram_Body or else
Nkind (Result) = N_Block_Statement)
loop
Result := Parent (Result);
end loop;
if Nkind (Result) = N_Package_Specification then
Result := Parent (Result);
elsif Nkind (Result) = N_Compilation_Unit then
Result := Empty;
end if;
end if;
return Result;
end Enclosing_Scope;
--------------
-- Is_Equal --
--------------
function Is_Equal
(N : Node_Id;
Trace_Rec : Node_Trace_Rec)
return Boolean
is
begin
return Nkind (N) = Trace_Rec.Kind and then
Get_Physical_Line_Number (Sloc (N)) = Trace_Rec.Node_Line and then
Get_Column_Number (Sloc (N)) = Trace_Rec.Node_Col;
end Is_Equal;
end A4G.Asis_Tables;
|
--------------------------------------------------------------------------------
-- Copyright (C) 2020 by Heisenbug Ltd. (gh+owm@heisenbug.eu)
--
-- This work is free. You can redistribute it and/or modify it under the
-- terms of the Do What The Fuck You Want To Public License, Version 2,
-- as published by Sam Hocevar. See the LICENSE file for more details.
--------------------------------------------------------------------------------
pragma License (Unrestricted);
with Ada.Directories;
with Ada.Environment_Variables;
package body Open_Weather_Map is
-- Application files are expected to reside in the home directory under an
-- application specific subdirectory. Under Unixoids the home directory is
-- denoted by the environment variable HOME, under Windows this is
-- USERPROFILE.
-- So we try HOME first, if that fails, we try USERPROFILE.
Home_Unix : constant String := "HOME";
Home_Windows : constant String := "USERPROFILE";
App_Dir_Name : constant String := "openweathermap";
Full_Application_Directory : constant String :=
Ada.Directories.Compose
(Containing_Directory =>
Ada.Directories.Compose
(Containing_Directory =>
(if Ada.Environment_Variables.Exists (Name => Home_Unix) then
Ada.Environment_Variables.Value (Name => Home_Unix)
elsif Ada.Environment_Variables.Exists (Name => Home_Windows) then
Ada.Environment_Variables.Value (Name => Home_Windows)
else Ada.Directories.Current_Directory),
Name => ".config"),
Name => App_Dir_Name);
-----------------------------------------------------------------------------
-- Application_Directory
-----------------------------------------------------------------------------
function Application_Directory return String is
begin
return Full_Application_Directory;
end Application_Directory;
end Open_Weather_Map;
|
------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- XML Processor --
-- --
-- Runtime Library Component --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2010-2011, 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 Ada.Unchecked_Deallocation;
with League.Strings.Internals;
with Matreshka.Internals.Strings.Configuration;
package body XML.SAX.Attributes is
use League.Strings;
use Matreshka.Internals.Strings.Configuration;
procedure Free is
new Ada.Unchecked_Deallocation
(Shared_Attributes, Shared_Attributes_Access);
------------
-- Adjust --
------------
overriding procedure Adjust (Self : in out SAX_Attributes) is
begin
Reference (Self.Data);
end Adjust;
-------------------
-- Can_Be_Reused --
-------------------
function Can_Be_Reused (Self : Shared_Attributes_Access) return Boolean is
begin
return Matreshka.Atomics.Counters.Is_One (Self.Counter);
end Can_Be_Reused;
-----------
-- Clear --
-----------
procedure Clear (Self : in out SAX_Attributes'Class) is
begin
if Can_Be_Reused (Self.Data) then
for J in 1 .. Self.Data.Length loop
Matreshka.Internals.Strings.Dereference
(Self.Data.Values (J).Namespace_URI);
Matreshka.Internals.Strings.Dereference
(Self.Data.Values (J).Local_Name);
Matreshka.Internals.Strings.Dereference
(Self.Data.Values (J).Qualified_Name);
Matreshka.Internals.Strings.Dereference
(Self.Data.Values (J).Value);
Matreshka.Internals.Strings.Dereference
(Self.Data.Values (J).Value_Type);
end loop;
Self.Data.Length := 0;
else
Dereference (Self.Data);
Self.Data := new Shared_Attributes (8);
end if;
end Clear;
-----------------
-- Dereference --
-----------------
procedure Dereference (Self : in out Shared_Attributes_Access) is
begin
if Self /= Shared_Empty'Access then
if Matreshka.Atomics.Counters.Decrement (Self.Counter) then
for J in 1 .. Self.Length loop
Matreshka.Internals.Strings.Dereference
(Self.Values (J).Namespace_URI);
Matreshka.Internals.Strings.Dereference
(Self.Values (J).Local_Name);
Matreshka.Internals.Strings.Dereference
(Self.Values (J).Qualified_Name);
Matreshka.Internals.Strings.Dereference
(Self.Values (J).Value);
Matreshka.Internals.Strings.Dereference
(Self.Values (J).Value_Type);
end loop;
Free (Self);
else
Self := null;
end if;
end if;
end Dereference;
------------
-- Detach --
------------
procedure Detach (Self : in out Shared_Attributes_Access; Size : Natural) is
begin
-- Reallocate shared object when necessary.
if not Can_Be_Reused (Self)
-- Object can't be mutated because someone else use it. Allocate
-- new shared object and copy data.
or else Self.Last < Size
-- There are no enought space to store new attribute. Reallocate new
-- object and copy data.
then
declare
Aux : constant Shared_Attributes_Access
:= new Shared_Attributes ((Size + 8) / 8 * 8);
begin
Aux.Values (1 .. Self.Length) := Self.Values (1 .. Self.Length);
Aux.Length := Self.Length;
for J in 1 .. Aux.Length loop
Matreshka.Internals.Strings.Reference
(Aux.Values (J).Namespace_URI);
Matreshka.Internals.Strings.Reference
(Aux.Values (J).Local_Name);
Matreshka.Internals.Strings.Reference
(Aux.Values (J).Qualified_Name);
Matreshka.Internals.Strings.Reference
(Aux.Values (J).Value);
Matreshka.Internals.Strings.Reference
(Aux.Values (J).Value_Type);
end loop;
Dereference (Self);
Self := Aux;
end;
end if;
end Detach;
--------------
-- Finalize --
--------------
overriding procedure Finalize (Self : in out SAX_Attributes) is
begin
if Self.Data /= null then
Dereference (Self.Data);
end if;
end Finalize;
-----------
-- Index --
-----------
function Index
(Self : SAX_Attributes'Class;
Qualified_Name : League.Strings.Universal_String) return Natural is
begin
for J in 1 .. Self.Data.Length loop
if String_Handler.Is_Equal
(Self.Data.Values (J).Qualified_Name,
League.Strings.Internals.Internal (Qualified_Name))
then
return J;
end if;
end loop;
return 0;
end Index;
-----------
-- Index --
-----------
function Index
(Self : SAX_Attributes'Class;
Namespace_URI : League.Strings.Universal_String;
Local_Name : League.Strings.Universal_String) return Natural is
begin
for J in 1 .. Self.Data.Length loop
if String_Handler.Is_Equal
(Self.Data.Values (J).Namespace_URI,
League.Strings.Internals.Internal (Namespace_URI))
and String_Handler.Is_Equal
(Self.Data.Values (J).Local_Name,
League.Strings.Internals.Internal (Local_Name))
then
return J;
end if;
end loop;
return 0;
end Index;
-----------------
-- Is_Declared --
-----------------
function Is_Declared
(Self : SAX_Attributes'Class;
Index : Positive) return Boolean is
begin
if Index > Self.Data.Length then
raise Constraint_Error;
end if;
return Self.Data.Values (Index).Is_Declared;
end Is_Declared;
-----------------
-- Is_Declared --
-----------------
function Is_Declared
(Self : SAX_Attributes'Class;
Qualified_Name : League.Strings.Universal_String)
return Boolean is
begin
for J in 1 .. Self.Data.Length loop
if String_Handler.Is_Equal
(Self.Data.Values (J).Qualified_Name,
League.Strings.Internals.Internal (Qualified_Name))
then
return Self.Data.Values (J).Is_Declared;
end if;
end loop;
return False;
end Is_Declared;
-----------------
-- Is_Declared --
-----------------
function Is_Declared
(Self : SAX_Attributes'Class;
Namespace_URI : League.Strings.Universal_String;
Local_Name : League.Strings.Universal_String)
return Boolean is
begin
for J in 1 .. Self.Data.Length loop
if String_Handler.Is_Equal
(Self.Data.Values (J).Namespace_URI,
League.Strings.Internals.Internal (Namespace_URI))
and String_Handler.Is_Equal
(Self.Data.Values (J).Local_Name,
League.Strings.Internals.Internal (Local_Name))
then
return Self.Data.Values (J).Is_Declared;
end if;
end loop;
return False;
end Is_Declared;
--------------
-- Is_Empty --
--------------
function Is_Empty (Self : SAX_Attributes'Class) return Boolean is
begin
return Self.Data.Length = 0;
end Is_Empty;
------------------
-- Is_Specified --
------------------
function Is_Specified
(Self : SAX_Attributes'Class;
Index : Positive) return Boolean is
begin
if Index > Self.Data.Length then
raise Constraint_Error;
end if;
return Self.Data.Values (Index).Is_Specified;
end Is_Specified;
------------------
-- Is_Specified --
------------------
function Is_Specified
(Self : SAX_Attributes'Class;
Qualified_Name : League.Strings.Universal_String)
return Boolean is
begin
for J in 1 .. Self.Data.Length loop
if String_Handler.Is_Equal
(Self.Data.Values (J).Qualified_Name,
League.Strings.Internals.Internal (Qualified_Name))
then
return Self.Data.Values (J).Is_Specified;
end if;
end loop;
return False;
end Is_Specified;
------------------
-- Is_Specified --
------------------
function Is_Specified
(Self : SAX_Attributes'Class;
Namespace_URI : League.Strings.Universal_String;
Local_Name : League.Strings.Universal_String)
return Boolean is
begin
for J in 1 .. Self.Data.Length loop
if String_Handler.Is_Equal
(Self.Data.Values (J).Namespace_URI,
League.Strings.Internals.Internal (Namespace_URI))
and String_Handler.Is_Equal
(Self.Data.Values (J).Local_Name,
League.Strings.Internals.Internal (Local_Name))
then
return Self.Data.Values (J).Is_Specified;
end if;
end loop;
return False;
end Is_Specified;
------------
-- Length --
------------
function Length (Self : SAX_Attributes'Class) return Natural is
begin
return Self.Data.Length;
end Length;
----------------
-- Local_Name --
----------------
function Local_Name
(Self : SAX_Attributes'Class;
Index : Positive) return League.Strings.Universal_String is
begin
if Index > Self.Data.Length then
raise Constraint_Error;
end if;
return
League.Strings.Internals.Create (Self.Data.Values (Index).Local_Name);
end Local_Name;
-------------------
-- Namespace_URI --
-------------------
function Namespace_URI
(Self : SAX_Attributes'Class;
Index : Positive) return League.Strings.Universal_String is
begin
if Index > Self.Data.Length then
raise Constraint_Error;
end if;
return
League.Strings.Internals.Create
(Self.Data.Values (Index).Namespace_URI);
end Namespace_URI;
--------------------
-- Qualified_Name --
--------------------
function Qualified_Name
(Self : SAX_Attributes'Class;
Index : Positive) return League.Strings.Universal_String is
begin
if Index > Self.Data.Length then
raise Constraint_Error;
end if;
return
League.Strings.Internals.Create
(Self.Data.Values (Index).Qualified_Name);
end Qualified_Name;
---------------
-- Reference --
---------------
procedure Reference (Self : Shared_Attributes_Access) is
begin
if Self /= Shared_Empty'Access then
Matreshka.Atomics.Counters.Increment (Self.Counter);
end if;
end Reference;
---------------
-- Set_Value --
---------------
procedure Set_Value
(Self : in out SAX_Attributes'Class;
Qualified_Name : League.Strings.Universal_String;
Value : League.Strings.Universal_String)
is
use type Matreshka.Internals.Strings.Shared_String_Access;
Shared_Value : constant Matreshka.Internals.Strings.Shared_String_Access
:= League.Strings.Internals.Internal (Value);
Index : constant Natural := Self.Index (Qualified_Name);
CDATA_Name : constant Universal_String
:= To_Universal_String ("CDATA");
begin
if Index = 0 then
Detach (Self.Data, Self.Data.Length + 1);
Self.Data.Length := Self.Data.Length + 1;
Self.Data.Values (Self.Data.Length) :=
(Namespace_URI => Matreshka.Internals.Strings.Shared_Empty'Access,
Local_Name => Matreshka.Internals.Strings.Shared_Empty'Access,
Qualified_Name =>
League.Strings.Internals.Internal (Qualified_Name),
Value => League.Strings.Internals.Internal (Value),
Value_Type => League.Strings.Internals.Internal (CDATA_Name),
Is_Declared => False,
Is_Specified => True);
Matreshka.Internals.Strings.Reference
(Self.Data.Values (Self.Data.Length).Qualified_Name);
Matreshka.Internals.Strings.Reference
(Self.Data.Values (Self.Data.Length).Value);
Matreshka.Internals.Strings.Reference
(Self.Data.Values (Self.Data.Length).Value_Type);
else
Detach (Self.Data, Self.Data.Length);
if Shared_Value /= Self.Data.Values (Index).Value then
Matreshka.Internals.Strings.Dereference
(Self.Data.Values (Index).Value);
Matreshka.Internals.Strings.Reference (Shared_Value);
Self.Data.Values (Index).Value := Shared_Value;
end if;
end if;
end Set_Value;
---------------
-- Set_Value --
---------------
procedure Set_Value
(Self : in out SAX_Attributes'Class;
Namespace_URI : League.Strings.Universal_String;
Local_Name : League.Strings.Universal_String;
Value : League.Strings.Universal_String)
is
use type Matreshka.Internals.Strings.Shared_String_Access;
Shared_Value : constant Matreshka.Internals.Strings.Shared_String_Access
:= League.Strings.Internals.Internal (Value);
Index : constant Natural
:= Self.Index (Namespace_URI, Local_Name);
CDATA_Name : constant Universal_String
:= To_Universal_String ("CDATA");
begin
if Index = 0 then
Detach (Self.Data, Self.Data.Length + 1);
Self.Data.Length := Self.Data.Length + 1;
Self.Data.Values (Self.Data.Length) :=
(Namespace_URI => League.Strings.Internals.Internal (Namespace_URI),
Local_Name => League.Strings.Internals.Internal (Local_Name),
Qualified_Name => Matreshka.Internals.Strings.Shared_Empty'Access,
Value => League.Strings.Internals.Internal (Value),
Value_Type => League.Strings.Internals.Internal (CDATA_Name),
Is_Declared => False,
Is_Specified => True);
Matreshka.Internals.Strings.Reference
(Self.Data.Values (Self.Data.Length).Namespace_URI);
Matreshka.Internals.Strings.Reference
(Self.Data.Values (Self.Data.Length).Local_Name);
Matreshka.Internals.Strings.Reference
(Self.Data.Values (Self.Data.Length).Value);
Matreshka.Internals.Strings.Reference
(Self.Data.Values (Self.Data.Length).Value_Type);
else
Detach (Self.Data, Self.Data.Length);
if Shared_Value /= Self.Data.Values (Index).Value then
Matreshka.Internals.Strings.Dereference
(Self.Data.Values (Index).Value);
Matreshka.Internals.Strings.Reference (Shared_Value);
Self.Data.Values (Index).Value := Shared_Value;
end if;
end if;
end Set_Value;
-----------
-- Value --
-----------
function Value
(Self : SAX_Attributes'Class;
Index : Positive) return League.Strings.Universal_String is
begin
if Index > Self.Data.Length then
raise Constraint_Error;
end if;
return League.Strings.Internals.Create (Self.Data.Values (Index).Value);
end Value;
-----------
-- Value --
-----------
function Value
(Self : SAX_Attributes'Class;
Qualified_Name : League.Strings.Universal_String)
return League.Strings.Universal_String is
begin
for J in 1 .. Self.Data.Length loop
if String_Handler.Is_Equal
(Self.Data.Values (J).Qualified_Name,
League.Strings.Internals.Internal (Qualified_Name))
then
return
League.Strings.Internals.Create (Self.Data.Values (J).Value);
end if;
end loop;
return Empty_Universal_String;
end Value;
-----------
-- Value --
-----------
function Value
(Self : SAX_Attributes'Class;
Namespace_URI : League.Strings.Universal_String;
Local_Name : League.Strings.Universal_String)
return League.Strings.Universal_String is
begin
for J in 1 .. Self.Data.Length loop
if String_Handler.Is_Equal
(Self.Data.Values (J).Namespace_URI,
League.Strings.Internals.Internal (Namespace_URI))
and String_Handler.Is_Equal
(Self.Data.Values (J).Local_Name,
League.Strings.Internals.Internal (Local_Name))
then
return
League.Strings.Internals.Create (Self.Data.Values (J).Value);
end if;
end loop;
return Empty_Universal_String;
end Value;
----------------
-- Value_Type --
----------------
function Value_Type
(Self : SAX_Attributes'Class;
Index : Positive) return League.Strings.Universal_String is
begin
if Index > Self.Data.Length then
raise Constraint_Error;
end if;
return
League.Strings.Internals.Create (Self.Data.Values (Index).Value_Type);
end Value_Type;
----------------
-- Value_Type --
----------------
function Value_Type
(Self : SAX_Attributes'Class;
Qualified_Name : League.Strings.Universal_String)
return League.Strings.Universal_String is
begin
for J in 1 .. Self.Data.Length loop
if String_Handler.Is_Equal
(Self.Data.Values (J).Qualified_Name,
League.Strings.Internals.Internal (Qualified_Name))
then
return
League.Strings.Internals.Create
(Self.Data.Values (J).Value_Type);
end if;
end loop;
return Empty_Universal_String;
end Value_Type;
----------------
-- Value_Type --
----------------
function Value_Type
(Self : SAX_Attributes'Class;
Namespace_URI : League.Strings.Universal_String;
Local_Name : League.Strings.Universal_String)
return League.Strings.Universal_String is
begin
for J in 1 .. Self.Data.Length loop
if String_Handler.Is_Equal
(Self.Data.Values (J).Namespace_URI,
League.Strings.Internals.Internal (Namespace_URI))
and String_Handler.Is_Equal
(Self.Data.Values (J).Local_Name,
League.Strings.Internals.Internal (Local_Name))
then
return
League.Strings.Internals.Create
(Self.Data.Values (J).Value_Type);
end if;
end loop;
return Empty_Universal_String;
end Value_Type;
end XML.SAX.Attributes;
|
-- SPDX-FileCopyrightText: 2020 Max Reznik <reznikmm@gmail.com>
--
-- SPDX-License-Identifier: MIT
-------------------------------------------------------------
with Program.Elements.Defining_Identifiers;
with Program.Elements.Package_Declarations;
with Program.Node_Symbols;
with Program.Safe_Element_Visitors;
package body Program.Plain_Contexts.Unit_Name_Resolvers is
type Getter is new Program.Safe_Element_Visitors.Safe_Element_Visitor with
record
Value : Program.Elements.Defining_Names.Defining_Name_Access;
end record;
overriding procedure Defining_Identifier
(Self : in out Getter;
Element : not null Program.Elements.Defining_Identifiers
.Defining_Identifier_Access);
overriding procedure Package_Declaration
(Self : in out Getter;
Element : not null Program.Elements.Package_Declarations
.Package_Declaration_Access);
-------------------------
-- Defining_Identifier --
-------------------------
overriding procedure Defining_Identifier
(Self : in out Getter;
Element : not null Program.Elements.Defining_Identifiers
.Defining_Identifier_Access) is
begin
Self.Value := Element.To_Defining_Name;
end Defining_Identifier;
-------------------------
-- Package_Declaration --
-------------------------
overriding procedure Package_Declaration
(Self : in out Getter;
Element : not null Program.Elements.Package_Declarations
.Package_Declaration_Access) is
begin
Element.Name.Visit (Self);
end Package_Declaration;
------------------------
-- Resolve_Identifier --
------------------------
overriding procedure Resolve_Identifier
(Self : Unit_Name_Resolver;
Name : not null Program.Elements.Identifiers.Identifier_Access;
Setter : not null
Program.Cross_Reference_Updaters.Cross_Reference_Updater_Access)
is
V : Getter;
List : Program.Symbol_Lists.Symbol_List;
Unit : Program.Compilation_Units.Compilation_Unit_Access;
begin
Program.Node_Symbols.Name_Symbol
(Self.Lists.all, Name.To_Expression, List);
if Self.Declarations.Map.Contains (List) then
Unit := Self.Declarations.Map (List).Unit;
elsif Self.Bodies.Map.Contains (List) then
Unit := Self.Bodies.Map (List).Unit;
else
Self.Errors.No_Such_Unit (Self.Lists.Symbol_List_Text (List));
return;
end if;
Unit.Unit_Declaration.Visit (V);
Setter.Set_Corresponding_Defining_Name
(Name.To_Element, V.Value);
end Resolve_Identifier;
end Program.Plain_Contexts.Unit_Name_Resolvers;
|
-- with Ada.Strings.Unbounded;
with Ada.Text_IO; use Ada.Text_IO;
with GL.Culling;
with GL.Objects.Programs;
-- with GL.Text;
with GL.Toggles;
with GL.Types; use GL.Types;
with GL.Types.Colors;
with GL.Window;
with Glfw;
with Glfw.Input;
with Glfw.Input.Keys;
with Glfw.Windows.Context;
with Maths;
with Utilities;
-- with Blade_Types;
with E3GA;
with C3GA_Utilities;
with GA_Maths;
-- with GA_Utilities;
with Geosphere;
-- with GL_Util;
with Multivectors;
-- with Multivector_Utilities;
with Palet;
with Pick_Manager;
with Draw_1_1;
with Shader_Manager;
-- with Silo;
-- with Text_Management;
with Points;
procedure Main_Loop (Main_Window : in out Glfw.Windows.Window) is
-- Black : constant Colors.Color := (0.0, 0.0, 0.0, 1.0);
Red : constant GL.Types.Singles.Vector4 := (1.0, 0.0, 0.0, 1.0);
Green : constant GL.Types.Singles.Vector4 := (0.0, 0.5, 0.0, 1.0);
Blue : constant GL.Types.Singles.Vector4 := (0.0, 0.0, 0.5, 1.0);
Magenta : constant GL.Types.Singles.Vector4 := (1.0, 0.0, 1.0, 1.0);
Yellow : constant GL.Types.Singles.Vector4 := (1.0, 1.0, 0.0, 0.5);
White : constant Colors.Color := (1.0, 1.0, 1.0, 0.0);
Key_Pressed : boolean := False;
-- Rotate_Model : boolean := False;
-- Rotate_Model_Out_Of_Plane : boolean := False;
-- Pick : GL_Util.GL_Pick;
-- procedure Draw_Text (Window_Width, Window_Height : Glfw.Size;
-- theText : String;
-- Render_Program : GL.Objects.Programs.Program;
-- Text_X, Text_Y : GL.Types.Single;
-- Text_Scale : GL.Types.Single);
-- procedure Text_Shader_Locations (Render_Text_Program : GL.Objects.Programs.Program;
-- Projection_Matrix_ID, Texture_ID, Text_Dimesions_ID,
-- Colour_ID : out GL.Uniforms.Uniform);
-- -------------------------------------------------------------------------
procedure Display (Window : in out Glfw.Windows.Window;
Render_Graphic_Program : GL.Objects.Programs.Program) is
-- Render_Text_Program : GL.Objects.Programs.Program) is
-- use GL.Objects.Buffers;
-- use GL.Types.Colors;
use GL.Types.Singles; -- for matrix multiplicatio
-- use Metric;
use Multivectors;
-- Position_X : integer := 0;
-- Position_Y : single := 160.0;
-- Label : Silo.Label_Data;
-- Label_Position : GL.Types.Singles.Vector2 := (0.0, 0.0);
-- E11 : constant float := E3GA.Get_Coord_1 (E3GA.e1);
-- E12 : constant float := E3GA.Get_Coord_2 (E3GA.e1);
-- E21 : constant float := E3GA.Get_Coord_1 (E3GA.e2);
-- E22 : constant float := E3GA.Get_Coord_2 (E3GA.e2);
-- V1 : Multivectors.M_Vector; -- 2D M_Vector (0, 0), (1, 0)
-- V2 : Multivectors.M_Vector;
-- Point_Position : Normalized_Point := New_Normalized_Point;
aLine : Multivectors.Line;
aCircle : Circle;
Rotated_Circle : Circle;
aDual_Plane : Dual_Plane;
-- Text_Coords : GA_Maths.Array_3D := (0.0, 0.0, 0.0);
Window_Width : Glfw.Size;
Window_Height : Glfw.Size;
-- Pick : GL_Util.GL_Pick;
Width : GL.Types.Single;
Height : GL.Types.Single;
-- rotor g_modelRotor(_rotor(1.0f))
-- Model_Rotor : constant Rotor := New_Rotor (1.0);
Translation_Matrix : Matrix4 := Identity4;
Projection_Matrix : Matrix4 := Identity4;
View_Matrix : Matrix4 := Identity4;
View_Angle : constant Maths.Degree := 50.0;
-- View_Matrix : Matrix4 := Identity4;
-- Camera_Position : constant Vector3 := (0.0, 0.0, 5.0);
-- Half_Pi : constant Single := 0.5 * Ada.Numerics.Pi;
-- Horizontal_Angle : constant Single := Ada.Numerics.Pi;
-- Vertical_Angle : constant Single := 0.0;
-- Direction : Vector3;
-- Right : Vector3;
-- Up : Vector3;
N_E3_Vec : constant E3GA.E3_Vector := (0.0, 1.0, 0.0);
Phi : constant Float := 0.5 * GA_Maths.Pi;
R_Versor : TR_Versor;
DL : Dual_Line;
LR : Multivector;
Alpha : Float;
begin
Window.Get_Framebuffer_Size (Window_Width, Window_Height);
Width := Single (Window_Width);
Height := Single (Window_Height);
GL.Window.Set_Viewport (0, 0, Int (Width), Int (Height));
-- GL_Util.Load_Pick_Matrix;
Maths.Init_Perspective_Transform
(View_Angle, Width, Height, 0.1, -100.0, Projection_Matrix);
Shader_Manager.Set_Projection_Matrix (Projection_Matrix);
Translation_Matrix := Maths.Translation_Matrix ((0.0, 0.0, -20.0));
View_Matrix := Translation_Matrix * View_Matrix;
Shader_Manager.Set_View_Matrix (View_Matrix);
-- View_Matrix := Translation_Matrix * View_Matrix;
-- Shader_Manager.Set_View_Matrix (View_Matrix);
-- View and model matrices are initilized to identity by
-- shader initialization.
Utilities.Clear_Background_Colour_And_Depth (White);
GL.Toggles.Enable (GL.Toggles.Depth_Test);
GL.Toggles.Enable (GL.Toggles.Cull_Face);
GL.Culling.Set_Cull_Face (GL.Culling.Back);
Shader_Manager.Set_Line_Width (2.0);
-- GL_Util.Rotor_GL_Multiply (Model_Rotor, Model_Matrix);
Palet.Set_Draw_Mode_Off (Palet.OD_Magnitude);
Palet.Set_Point_Size (0.1);
-- GL_Util.GL_Color_3fm (1.0, 0.0, 0.0);
-- Direction := (Cos (Vertical_Angle) * Sin (Horizontal_Angle),
-- Sin (Vertical_Angle),
-- Cos (Vertical_Angle) * Cos (Horizontal_Angle));
-- Right := (Sin (Horizontal_Angle - Half_Pi), 0.0,
-- Cos (Horizontal_Angle - Half_Pi));
-- Up := Singles.Cross_Product (Right, Direction);
-- Maths.Init_Lookat_Transform (Camera_Position, Direction, Up, View_Matrix);
-- Shader_Manager.Set_Light_Position_Vector ((0.0, 0.0, 10.0));
-- Shader_Manager.Set_Drawing_Colour (Red);
-- Shader_Manager.Set_Ambient_Colour (Green);
-- Shader_Manager.Set_Diffuse_Colour (BLue);
-- Test_MV := Multivectors.New_Vector;
-- GA_Utilities.Print_Multivector ("Display, Test_MV:", Test_MV);
-- for count in 1 .. Points.Num_Points loop
-- Label := Silo.Set_Data (Ada.Strings.Unbounded.To_Unbounded_String (Integer'Image (count)),
-- Label_Position);
-- Silo.Push (Label);
-- Point_Position := Points.Normalized_Points (count);
-- Point_Position (L1, L2, C1, C2, C3, P1)
-- C3GA_Draw.Draw (Render_Graphic_Program, Point_Position);
-- end loop;
-- GA_Utilities.Print_Multivector ("Display, Point_Position 1:", Points.L0_Normalized_Points (1));
-- GA_Utilities.Print_Multivector ("Display, Point_Position 2:", Points.L0_Normalized_Points (2));
-- GA_Utilities.Print_Multivector ("Display, L1.L1 ", Dot (Points.L1, Points.L1));
-- GA_Utilities.Print_Multivector ("Display, L2.L2 ", Dot (Points.L1, Points.L2));
-- GA_Utilities.Print_Multivector ("Display, L1 ", Points.L1);
-- GA_Utilities.Print_Multivector ("Display, L2 ", Points.L2);
if not Pick_Manager.Pick_Active then
Shader_Manager.Set_Model_Matrix (Identity4);
New_Line;
Put_Line ("Main_Loop.Display drawing a Line.");
Shader_Manager.Set_Ambient_Colour (Red);
aLine := Draw_1_1.Draw_Line (Render_Graphic_Program,
Points.L1, Points.L2);
New_Line;
Put_Line ("Main_Loop.Display drawing a Circle.");
Shader_Manager.Set_Ambient_Colour (Green);
Palet.Set_Draw_Mode_On (Palet.OD_Orientation);
aCircle := Draw_1_1.Draw_Circle (Render_Graphic_Program,
Points.C1, Points.C2, Points.C3);
Palet.Set_Draw_Mode_Off (Palet.OD_Orientation);
-- N_E3_Vec is a direction vector
aDual_Plane := Draw_1_1.New_Dual_Plane (Points.P1, N_E3_Vec);
-- draw reflected line (magenta)
New_Line;
Put_Line ("Main_Loop.Display drawing a reflected line.");
Shader_Manager.Set_Ambient_Colour (Magenta);
Draw_1_1.Draw_Reflected_Line (Render_Graphic_Program, aLine, aDual_Plane);
New_Line;
Put_Line ("Main_Loop.Display drawing reflected circle.");
-- draw reflected circle (blue)
Shader_Manager.Set_Ambient_Colour (Blue);
Palet.Set_Draw_Mode_On (Palet.OD_Orientation);
Draw_1_1.Draw_Reflected_Circle
(Render_Graphic_Program, aCircle, aDual_Plane);
Palet.Set_Draw_Mode_Off (Palet.OD_Orientation);
-- compute rotation versor
DL := 0.5 * Phi * To_Dual_Line (Dual (aLine));
R_Versor := To_TRversor (Multivectors.Exp (DL));
New_Line;
Put_Line ("Main_Loop.Display drawing rotated circle.");
-- draw rotated circle
Shader_Manager.Set_Ambient_Colour (Green);
Translation_Matrix := Maths.Translation_Matrix ((0.0, 2.0, 0.0)) *
Translation_Matrix;
Shader_Manager.Set_Translation_Matrix (Translation_Matrix);
Palet.Set_Draw_Mode_On (Palet.OD_Orientation);
Rotated_Circle := Draw_1_1.Draw_Rotated_Circle
(Render_Graphic_Program, aCircle, R_Versor);
New_Line;
Put_Line ("Main_Loop.Display drawing reflected, rotated circle.");
-- draw reflected, rotated circle (blue)
Shader_Manager.Set_Ambient_Colour (Blue);
Draw_1_1.Draw_Reflected_Circle
(Render_Graphic_Program, Rotated_Circle, aDual_Plane);
Palet.Set_Draw_Mode_Off (Palet.OD_Orientation);
-- Draw interpolated circles
LR := C3GA_Utilities.Log_TR_Versor (R_Versor);
Alpha := 0.0;
while Alpha < 1.0 loop
-- compute interpolated rotor
R_Versor := To_TRversor (Multivectors.Exp (Alpha * LR));
-- draw rotated circle (light green)
Shader_Manager.Set_Ambient_Colour ((0.5, 1.0, 0.5, 1.0));
Rotated_Circle := Draw_1_1.Draw_Rotated_Circle
(Render_Graphic_Program, aCircle, R_Versor);
-- draw reflected, rotated circle (light blue)
Shader_Manager.Set_Ambient_Colour ((0.5, 0.5, 1.0, 1.0));
Draw_1_1.Draw_Reflected_Circle
(Render_Graphic_Program, Rotated_Circle, aDual_Plane);
Alpha := Alpha + 0.1;
end loop;
Translation_Matrix := Maths.Translation_Matrix ((0.0, -2.0, 0.0)) *
Translation_Matrix;
Shader_Manager.Set_Translation_Matrix (Translation_Matrix);
-- Draw plane (yellow)
New_Line;
Put_Line ("Main_Loop.Display drawing plane.");
Shader_Manager.Set_Ambient_Colour (Yellow);
Draw_1_1.Draw_Plane (Render_Graphic_Program, aDual_Plane);
end if;
exception
when others =>
Put_Line ("An exception occurred in Main_Loop.Display.");
raise;
end Display;
-- ------------------------------------------------------------------------
-- procedure Draw_Text (Window_Width, Window_Height : Glfw.Size;
-- theText : String;
-- Render_Program : GL.Objects.Programs.Program;
-- Text_X, Text_Y : GL.Types.Single;
-- Text_Scale : GL.Types.Single) is
-- Text_Dimesions_ID : GL.Uniforms.Uniform;
-- Text_Proj_Matrix_ID : GL.Uniforms.Uniform;
-- Text_Texture_ID : GL.Uniforms.Uniform;
-- Text_Colour_ID : GL.Uniforms.Uniform;
-- Text_Projection_Matrix : GL.Types.Singles.Matrix4;
-- Text_Colour : constant Colors.Color := Black;
-- begin
-- Text_Shader_Locations (Render_Program, Text_Proj_Matrix_ID,
-- Text_Texture_ID, Text_Dimesions_ID, Text_Colour_ID);
-- Maths.Init_Orthographic_Transform (Single (Window_Height), 0.0, 0.0,
-- Single (Window_Width), 0.1, -100.0,
-- Text_Projection_Matrix);
-- Text_Management.Render_Text (Render_Program, theText, Text_X, Text_Y,
-- Text_Scale, Text_Colour, Text_Texture_ID,
-- Text_Proj_Matrix_ID, Text_Dimesions_ID,
-- Text_Colour_ID, Text_Projection_Matrix);
-- exception
-- when anError : others =>
-- Put_Line ("An exception occurred in Main_Loop.Draw_Text.");
-- raise;
-- end Draw_Text;
-- ------------------------------------------------------------------------
procedure Setup_Graphic (Render_Program : out GL.Objects.Programs.Program) is
-- Render_Text_Program : out GL.Objects.Programs.Program) is;
-- use GL.Objects.Buffers;
-- Font_File : string := "../fonts/Helvetica.ttc";
Sphere : Geosphere.Geosphere;
-- Depth : constant integer := 3;
begin
Shader_Manager.Init (Render_Program);
Palet.Set_Point_Size (1.0);
-- Put_Line ("Main_Loop.Setup_Graphic calling GS_Compute.");
-- Geosphere.GS_Compute (Sphere, Depth);
-- Put_Line ("Main_Loop.Setup_Graphic calling Set_Current_Sphere.");
Palet.Set_Current_Sphere (Sphere);
-- Render_Text_Program := Program_Loader.Program_From
-- ((Src ("src/shaders/text_vertex_shader.glsl", Vertex_Shader),
-- Src ("src/shaders/text_fragment_shader.glsl", Fragment_Shader)));
--
-- Text_Management.Setup (Font_File);
exception
when others =>
Put_Line ("An exception occurred in Main_Loop.Setup_Graphic.");
raise;
end Setup_Graphic;
-- ----------------------------------------------------------------------------
-- procedure Text_Shader_Locations (Render_Text_Program : GL.Objects.Programs.Program;
-- Projection_Matrix_ID, Texture_ID,
-- Text_Dimesions_ID, Colour_ID : out GL.Uniforms.Uniform) is
-- begin
-- Projection_Matrix_ID := GL.Objects.Programs.Uniform_Location
-- (Render_Text_Program, "mvp_matrix");
-- Texture_ID := GL.Objects.Programs.Uniform_Location
-- (Render_Text_Program, "text_sampler");
-- Text_Dimesions_ID := GL.Objects.Programs.Uniform_Location
-- (Render_Text_Program, "dimensions");
-- Colour_ID := GL.Objects.Programs.Uniform_Location
-- (Render_Text_Program, "text_colour");
-- end Text_Shader_Locations;
-- -------------------------------------------------------------------------
use Glfw.Input;
Render_Graphic_Program : GL.Objects.Programs.Program;
-- Render_Text_Program : GL.Objects.Programs.Program;
Running : Boolean := True;
Key_Now : Button_State;
begin
Multivectors.Set_Geometry (Multivectors.C3_Geometry);
Utilities.Clear_Background_Colour_And_Depth (White);
Main_Window.Set_Input_Toggle (Sticky_Keys, True);
Glfw.Input.Poll_Events;
Setup_Graphic (Render_Graphic_Program);
-- Setup_Graphic (Main_Window, Render_Graphic_Program, Render_Text_Program);
while Running loop
-- Swap_Buffers first to display background colour on start up.
Glfw.Windows.Context.Swap_Buffers (Main_Window'Access);
Display (Main_Window, Render_Graphic_Program);
-- Display (Main_Window, Render_Graphic_Program, Render_Text_Program);
-- Delay (0.2);
Glfw.Input.Poll_Events;
Key_Now := Main_Window.Key_State (Glfw.Input.Keys.Space);
if not Key_Pressed and Key_Now = Glfw.Input.Pressed then
Key_Pressed := True;
else
Key_Pressed := Key_Now = Glfw.Input.Pressed;
end if;
-- Delay (3.0);
Running := Running and then
not (Main_Window.Key_State (Glfw.Input.Keys.Escape) = Glfw.Input.Pressed);
Running := Running and then not Main_Window.Should_Close;
end loop;
end Main_Loop;
|
with HAL; use HAL;
with System; use System;
pragma Warnings (Off, "* is an internal GNAT unit");
with System.BB.Parameters;
pragma Warnings (On, "* is an internal GNAT unit");
package body NXP.Device is
-- SYSCON : aliased SYSCON_Peripheral
-- with Import, Address => S_NS_Periph (SYSCON_Base);
Secure_Code : UInt32;
pragma Import (C, Secure_Code, "secure_code");
------------------
-- Enable_Clock --
------------------
procedure Enable_Clock (This : aliased in out GPIO_Port; Port : Ports)
is
Idx : Integer := Port'Enum_Rep;
begin
SYSCON.AHBCLKCTRL0.GPIO.Arr (Idx) := Enable;
end Enable_Clock;
procedure Disable_Clock (This : aliased in out GPIO_Port; Port : Ports)
is
Idx : Integer := Port'Enum_Rep;
begin
SYSCON.AHBCLKCTRL0.GPIO.Arr (Idx) := Disable;
end Disable_Clock;
------------------
-- Enable_Clock --
------------------
procedure Enable_Clock (Point : GPIO_Point)
is
begin
Enable_Clock (Point.Periph.all, Point.Port);
end Enable_Clock;
procedure Disable_Clock (Point : GPIO_Point)
is
begin
Disable_Clock (Point.Periph.all, Point.Port);
end Disable_Clock;
------------------
-- Enable_Clock --
------------------
procedure Enable_Clock (Points : GPIO_Points)
is
begin
for Point of Points loop
Enable_Clock (Point.Periph.all, Point.Port);
end loop;
end Enable_Clock;
procedure Disable_Clock (Points : GPIO_Points)
is
begin
for Point of Points loop
Disable_Clock (Point.Periph.all, Point.Port);
end loop;
end Disable_Clock;
-----------
-- Reset --
-----------
procedure Reset (This : aliased in out GPIO_Port) is
begin
null;
end Reset;
-----------
-- Reset --
-----------
procedure Reset (Point : GPIO_Point) is
begin
Reset (Point.Periph.all);
end Reset;
-----------
-- Reset --
-----------
procedure Reset (Points : GPIO_Points)
is
Do_Reset : Boolean;
begin
for J in Points'Range loop
Do_Reset := True;
for K in Points'First .. J - 1 loop
if Points (K).Periph = Points (J).Periph then
Do_Reset := False;
exit;
end if;
end loop;
if Do_Reset then
Reset (Points (J).Periph.all);
end if;
end loop;
end Reset;
function S_NS_Periph (Addr : System.Address) return System.Address
is
X : UInt32;
LAddr : System.Address;
for X'Address use LAddr'Address;
begin
LAddr := Addr;
if Secure_Code > 0 then
X := X + 16#1000_0000#;
end if;
return LAddr;
end S_NS_Periph;
end NXP.Device;
|
package Solar_System.Graphics is
procedure Draw_Body (Object : Body_T; Canvas : Canvas_ID);
end Solar_System.Graphics;
|
-----------------------------------------------------------------------
-- Util.Locales -- Locale
-- Copyright (C) 2001, 2002, 2003, 2009, 2010, 2011 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 Ada.Strings.Hash;
-- The <b>Locales</b> package defines the <b>Locale</b> type to represent
-- the language, country and variant.
--
-- The language is a valid <b>ISO language code</b>. This is a two-letter
-- lower case code defined by IS-639
-- See http://www.loc.gov/standards/iso639-2/englangn.html
--
-- The country is a valid <b>ISO country code</b>. These codes are
-- a two letter upper-case code defined by ISO-3166.
-- See http://www.iso.ch/iso/en/prods-services/iso3166ma/02iso-3166-code-lists/list-en1.html
--
-- The variant part is a vendor or browser specific code.
--
-- The <b>Locales</b> package tries to follow the Java <b>Locale</b> class.
package body Util.Locales is
-- ------------------------------
-- Get the lowercase two-letter ISO-639 code.
-- ------------------------------
function Get_Language (Loc : in Locale) return String is
begin
if Loc = null then
return "";
else
return Loc (1 .. 2);
end if;
end Get_Language;
-- ------------------------------
-- Get the ISO 639-2 language code.
-- ------------------------------
function Get_ISO3_Language (Loc : in Locale) return String is
begin
if Loc = null or else Loc'Length <= 3 then
return "";
end if;
if Loc'Length <= 6 then
return Loc (4 .. 6);
end if;
return Loc (7 .. 9);
end Get_ISO3_Language;
-- ------------------------------
-- Get the uppercase two-letter ISO-3166 code.
-- ------------------------------
function Get_Country (Loc : in Locale) return String is
begin
if Loc = null or else Loc'Length <= 2 or else Loc (3) /= '_' then
return "";
else
return Loc (4 .. 5);
end if;
end Get_Country;
-- ------------------------------
-- Get the ISO-3166-2 country code.
-- ------------------------------
function Get_ISO3_Country (Loc : in Locale) return String is
begin
if Loc = null or else Loc'Length <= 5 then
return "";
else
return Loc (10 .. Loc'Last);
end if;
end Get_ISO3_Country;
-- ------------------------------
-- Get the variant code
-- ------------------------------
function Get_Variant (Loc : in Locale) return String is
begin
if Loc = null or else Loc'Length <= 13 then
return "";
else
return Loc (7 .. 8);
end if;
end Get_Variant;
-- ------------------------------
-- Get the locale for the given language code
-- ------------------------------
function Get_Locale (Language : in String) return Locale is
Length : constant Natural := Language'Length;
Lower : Natural := Locales'First;
Upper : Natural := Locales'Last;
Pos : Natural;
Result : Locale;
begin
while Lower <= Upper loop
Pos := (Lower + Upper) / 2;
Result := Locales (Pos);
if Result'Length < Length then
if Result.all < Language (Language'First .. Language'First + Result'Length - 1) then
Lower := Pos + 1;
else
Upper := Pos - 1;
end if;
elsif Result'Length > Length and then Result (Length + 1) = '.'
and then Result (1 .. Length) = Language then
return Result;
elsif Result (1 .. Length) < Language then
Lower := Pos + 1;
else
Upper := Pos - 1;
end if;
end loop;
return NULL_LOCALE;
end Get_Locale;
-- ------------------------------
-- Get the locale for the given language and country code
-- ------------------------------
function Get_Locale (Language : in String;
Country : in String) return Locale is
begin
if Language'Length /= 2 or else (Country'Length /= 0 and Country'Length /= 2) then
return NULL_LOCALE;
elsif Country'Length = 0 then
return Get_Locale (Language);
else
return Get_Locale (Language & "_" & Country);
end if;
end Get_Locale;
-- ------------------------------
-- Get the locale for the given language, country and variant code
-- ------------------------------
function Get_Locale (Language : in String;
Country : in String;
Variant : in String) return Locale is
begin
if Language'Length /= 2
or else (Country'Length /= 0 and Country'Length /= 2)
or else (Variant'Length /= 0 and Variant'Length /= 2) then
return NULL_LOCALE;
end if;
if Country'Length = 0 and Variant'Length = 0 then
return Get_Locale (Language);
elsif Variant'Length = 0 then
return Get_Locale (Language, Country);
else
return Get_Locale (Language & "_" & Country & "_" & Variant);
end if;
end Get_Locale;
-- ------------------------------
-- Get the locale code in the form <i>language</i>_<i>country</i>_<i>variant</i>.
-- ------------------------------
function To_String (Loc : in Locale) return String is
begin
if Loc = null then
return "";
elsif Loc'Length > 3 and Loc (3) = '.' then
return Loc (1 .. 2);
elsif Loc'Length > 6 and Loc (6) = '.' then
return Loc (1 .. 5);
else
return Loc (1 .. 8);
end if;
end To_String;
-- ------------------------------
-- Compute the hash value of the locale.
-- ------------------------------
function Hash (Loc : in Locale) return Ada.Containers.Hash_Type is
use type Ada.Containers.Hash_Type;
begin
return Ada.Strings.Hash (Loc.all);
end Hash;
end Util.Locales;
|
package Tagged_Definition is
type Tagged_Record is tagged record
Component_1 : Integer;
end record;
end Tagged_Definition;
|
-----------------------------------------------------------------------
-- dns -- DNS Example
-- Copyright (C) 2016, 2017 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 Ada.Real_Time;
with Interfaces;
with STM32.Board;
with HAL.Bitmap;
with Net.Buffers;
with Net.Utils;
with Net.Protos.Arp;
with Net.DNS;
with Net.DHCP;
with Receiver;
with Dns_List;
with Demos;
pragma Unreferenced (Receiver);
-- == DNS Application ==
-- The <b>DNS</b> application resolves several domain names by using the DNS client and it
-- displays the IPv4 address that was resolved. It periodically resolve the names and
-- also displays the TTL associated with the response.
--
-- The application has two tasks. The main task loops to manage the refresh of the STM32
-- display and send the DNS resolution requests regularly. The second task is responsible for
-- waiting of Ethernet packets, analyzing them to handle ARP and DNS response packets.
procedure Dns is
use type Interfaces.Unsigned_32;
use type Net.Ip_Addr;
use type Ada.Real_Time.Time;
use type Ada.Real_Time.Time_Span;
procedure Refresh;
procedure Header;
function Get_Status (Query : in Net.DNS.Query) return String;
function Get_Status (Query : in Net.DNS.Query) return String is
use type Net.DNS.Status_Type;
S : constant Net.DNS.Status_Type := Query.Get_Status;
begin
if S = Net.DNS.PENDING then
return "...";
elsif S = Net.DNS.NOERROR then
return "OK";
elsif S = Net.DNS.NOQUERY then
return "";
else
return "FAIL";
end if;
end Get_Status;
procedure Refresh is
use type Net.DHCP.State_Type;
Y : Natural := 90;
Status : Net.Error_Code;
pragma Unreferenced (Status);
begin
for I in Dns_List.Queries'Range loop
if Dns_List.Queries (I).Get_Name'Length > 0 then
Demos.Put (0, Y, Dns_List.Queries (I).Get_Name);
Demos.Put (180, Y, Net.Utils.To_String (Dns_List.Queries (I).Get_Ip));
Demos.Put (330, Y, Get_Status (Dns_List.Queries (I)));
Demos.Put (400, Y, Net.Uint32'Image (Dns_List.Queries (I).Get_Ttl));
-- Put (250, Y, Net.Uint64 (Hosts (I).Seq));
-- Demos.Put (400, Y, Net.Uint64 (Dns_List.Queries (I).));
Y := Y + 16;
end if;
end loop;
Demos.Refresh_Ifnet_Stats;
STM32.Board.Display.Update_Layer (1);
if Demos.Dhcp.Get_State = Net.DHCP.STATE_BOUND then
Dns_List.Queries (1).Resolve (Demos.Ifnet'Access, "www.google.com", Status);
Dns_List.Queries (2).Resolve (Demos.Ifnet'Access, "www.facebook.com", Status);
Dns_List.Queries (3).Resolve (Demos.Ifnet'Access, "www.apple.com", Status);
Dns_List.Queries (4).Resolve (Demos.Ifnet'Access, "www.adacore.com", Status);
Dns_List.Queries (5).Resolve (Demos.Ifnet'Access, "github.com", Status);
Dns_List.Queries (6).Resolve (Demos.Ifnet'Access, "www.twitter.com", Status);
Dns_List.Queries (7).Resolve (Demos.Ifnet'Access, "www.kalabosse.com", Status);
end if;
end Refresh;
procedure Header is null;
procedure Initialize is new Demos.Initialize (Header);
-- The display refresh period.
REFRESH_PERIOD : constant Ada.Real_Time.Time_Span := Ada.Real_Time.Milliseconds (1000);
-- Refresh display deadline.
Display_Deadline : Ada.Real_Time.Time;
Dhcp_Deadline : Ada.Real_Time.Time;
begin
Initialize ("STM32 DNS");
Display_Deadline := Ada.Real_Time.Clock;
loop
Net.Protos.Arp.Timeout (Demos.Ifnet);
Demos.Dhcp.Process (Dhcp_Deadline);
if Display_Deadline < Ada.Real_Time.Clock then
Refresh;
Display_Deadline := Display_Deadline + REFRESH_PERIOD;
end if;
if Dhcp_Deadline < Display_Deadline then
delay until Dhcp_Deadline;
else
delay until Display_Deadline;
end if;
end loop;
end Dns;
|
-- SPDX-FileCopyrightText: 2020 Max Reznik <reznikmm@gmail.com>
--
-- SPDX-License-Identifier: MIT
----------------------------------------------------------------
with Ada.Tags;
with League.String_Vectors;
with League.Strings;
with Markdown.Blocks;
limited with Markdown.Visitors;
package Markdown.Fenced_Code_Blocks is
type Fenced_Code_Block is new Markdown.Blocks.Block with private;
function Lines (Self : Fenced_Code_Block'Class)
return League.String_Vectors.Universal_String_Vector;
function Info_String (Self : Fenced_Code_Block'Class)
return League.Strings.Universal_String;
overriding function Create
(Line : not null access Markdown.Blocks.Text_Line)
return Fenced_Code_Block;
overriding procedure Append_Line
(Self : in out Fenced_Code_Block;
Line : Markdown.Blocks.Text_Line;
CIP : Can_Interrupt_Paragraph;
Ok : in out Boolean);
overriding procedure Visit
(Self : in out Fenced_Code_Block;
Visitor : in out Markdown.Visitors.Visitor'Class);
procedure Filter
(Line : Markdown.Blocks.Text_Line;
Tag : in out Ada.Tags.Tag;
CIP : out Can_Interrupt_Paragraph);
private
type Fenced_Code_Block is new Markdown.Blocks.Block with record
Is_Tick_Fence : Boolean;
Fence_Length : Positive;
Fence_Indent : Natural;
Closed : Boolean := False;
Lines : League.String_Vectors.Universal_String_Vector;
Blank : League.String_Vectors.Universal_String_Vector;
Info_String : League.Strings.Universal_String;
end record;
end Markdown.Fenced_Code_Blocks;
|
------------------------------------------------------------------------------
-- EMAIL: <darkestkhan@gmail.com> --
-- License: ISC License (see COPYING file) --
-- --
-- Copyright © 2015 darkestkhan --
------------------------------------------------------------------------------
-- 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 Ada.Containers.Indefinite_Vectors;
------------------------------------------------------------------------------
-- Small and simple callback based library for processing program arguments --
------------------------------------------------------------------------------
---------------------------------------------------------------------------
-- U S A G E --
---------------------------------------------------------------------------
-- First register all callbacks you are interested in, then call
-- Process_Arguments.
--
-- NOTE: "=" sign can't be part of argument name for registered callback.
--
-- Only one callback can be registered per argument, otherwise
-- Constraint_Error is propagated.
---------------------------------------------------------------------------
---------------------------------------------------------------------------
-- Leading single hyphen and double hyphen are stripped (if present) when
-- processing arguments that are placed before first "--" argument,
-- so e.g. "--help", "-help" and "help" are functionally
-- equivalent, treated as if "help" was actually passed in all 3 cases.
-- (you should register callback just for "help", if you register it for
-- "--help" then actually passed argument would have to be "----help" in order
-- for it to trigger said callback)
--
-- In addition if you registered callback as case insensitive, then
-- (using above example) "Help", "HELP", "help" and "HeLp" all would result in
-- call to said callback.
--
-- If Argument_Type is Variable then callback will receive part of argument
-- that is after "=" sign. (ie. "OS=Linux" argument would result in callback
-- receiving only "Linux" as its argument), otherwise actual argument will be
-- passed.
--
-- For Variable, case insensitive callbacks simple rule applies:
-- only variable name is case insensitive, with actual value (when passed to
-- program) being unchanged.
--
-- If argument for which callback is registered is passed few times
-- (ie. ./program help help help) then callback is triggered however many
-- times said argument is detected.
--
-- NOTE that Check for case insensitive callback is being performed first,
-- thus if you happen to register callback for "help" (case insensitive) and
-- "HeLp" (case sensitive) then only the case insensitive one will be called
-- (i.e. "help").
--
-- All arguments with no associated callback are added to Unknown_Arguments
-- vector as long as they appear before first "--" argument.
--
-- All arguments after first "--" (standalone double hyphen) are added to
-- Input_Argument vector (this includes another "--"), w/o any kind of
-- hyphen stripping being performed on them.
--
-- NOTE: No care is taken to ensure that all Input_Arguments
-- (or Unknown_Arguments) are unique.
---------------------------------------------------------------------------
package CBAP is
---------------------------------------------------------------------------
-- Yes, I do realize this is actually vector...
package Argument_Lists is new
Ada.Containers.Indefinite_Vectors (Positive, String);
-- List of all arguments (before first "--" argument) for which callbacks
-- where not registered.
Unknown_Arguments : Argument_Lists.Vector := Argument_Lists.Empty_Vector;
-- List of all arguments after first "--" argument.
Input_Arguments : Argument_Lists.Vector := Argument_Lists.Empty_Vector;
-- Argument_Types decides if argument is just a simple value, or a variable
-- with value assigned to it (difference between "--val" and "--var=val")
type Argument_Types is (Value, Variable);
-- Argument is useful mostly for Variable type of arguments.
type Callbacks is not null access procedure (Argument: in String);
---------------------------------------------------------------------------
-- Register callbacks for processing arguments.
-- @Callback : Action to be performed in case appropriate argument is
-- detected.
-- @Called_On : Argument for which callback is to be performed.
-- @Argument_Type : {Value, Variable}. Value is simple argument that needs no
-- additional parsing. Variable is argument of "Arg_Name=Some_Val" form.
-- When callback is triggered, Value is passed to callback as input, in
-- case of Variable it is content of argument after first "=" that is
-- passed to callback.
-- @Case_Sensitive: Whether or not case is significant. When False all forms
-- of argument are treated as if written in lower case.
procedure Register
( Callback : in Callbacks;
Called_On : in String;
Argument_Type : in Argument_Types := Value;
Case_Sensitive: in Boolean := True
);
-- Raised if Called_On contains "=".
Incorrect_Called_On: exception;
---------------------------------------------------------------------------
-- Parse arguments supplied to program, calling callbacks when argument with
-- associated callback is detected.
-- NOTE: Process_Arguments will call callbacks however many times argument
-- with associated callback is called. So if you have callback for "help",
-- then ./program help help help
-- will result in 3 calls to said callback.
procedure Process_Arguments;
---------------------------------------------------------------------------
end CBAP;
|
-----------------------------------------------------------------------
-- wiki-writers-builders -- Wiki writer to a string builder
-- Copyright (C) 2011, 2012, 2013, 2015, 2016 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 GNAT.Encode_UTF8_String;
package body Wiki.Streams.Builders is
-- use Wiki.Strings;
package WBS renames Wiki.Strings.Wide_Wide_Builders;
-- ------------------------------
-- Write the content to the string builder.
-- ------------------------------
overriding
procedure Write (Stream : in out Output_Builder_Stream;
Content : in Wiki.Strings.WString) is
begin
WBS.Append (Stream.Content, Content);
end Write;
-- ------------------------------
-- Write the content to the string builder.
-- ------------------------------
overriding
procedure Write (Stream : in out Output_Builder_Stream;
Content : in Wiki.Strings.WChar) is
begin
WBS.Append (Stream.Content, Content);
end Write;
-- Write the string to the string builder.
procedure Write_String (Stream : in out Output_Builder_Stream;
Content : in String) is
begin
for I in Content'Range loop
WBS.Append (Stream.Content, Wiki.Strings.To_WChar (Content (I)));
end loop;
end Write_String;
-- ------------------------------
-- Iterate over the buffer content calling the <tt>Process</tt> procedure with each
-- chunk.
-- ------------------------------
procedure Iterate (Source : in Output_Builder_Stream;
Process : not null access procedure (Chunk : in Wiki.Strings.WString)) is
begin
Strings.Wide_Wide_Builders.Iterate (Source.Content, Process);
end Iterate;
-- ------------------------------
-- Convert what was collected in the writer builder to a string and return it.
-- ------------------------------
function To_String (Source : in Output_Builder_Stream) return String is
procedure Convert (Chunk : in Wiki.Strings.WString);
Pos : Natural := 1;
Result : String (1 .. 5 * Strings.Wide_Wide_Builders.Length (Source.Content));
procedure Convert (Chunk : in Wiki.Strings.WString) is
begin
for I in Chunk'Range loop
GNAT.Encode_UTF8_String.Encode_Wide_Wide_Character (Char => Chunk (I),
Result => Result,
Ptr => Pos);
end loop;
end Convert;
begin
Strings.Wide_Wide_Builders.Iterate (Source.Content, Convert'Access);
return Result (1 .. Pos - 1);
end To_String;
end Wiki.Streams.Builders;
|
-- This file is covered by the Internet Software Consortium (ISC) License
-- Reference: ../License.txt
with GNAT.OS_Lib;
with Ada.Text_IO;
with Parameters;
with System;
package body Unix is
package OSL renames GNAT.OS_Lib;
package TIO renames Ada.Text_IO;
package PM renames Parameters;
----------------------
-- process_status --
----------------------
function process_status (pid : pid_t) return process_exit
is
result : constant uInt8 := nohang_waitpid (pid);
begin
case result is
when 0 => return still_running;
when 1 => return exited_normally;
when others => return exited_with_error;
end case;
end process_status;
-----------------------
-- screen_attached --
-----------------------
function screen_attached return Boolean is
begin
return CSM.isatty (handle => CSM.fileno (CSM.stdin)) = 1;
end screen_attached;
-----------------------
-- cone_of_silence --
-----------------------
procedure cone_of_silence (deploy : Boolean)
is
result : uInt8;
begin
if not screen_attached then
return;
end if;
if deploy then
result := silent_control;
if result > 0 then
TIO.Put_Line ("Notice: tty echo+control OFF command failed");
end if;
else
result := chatty_control;
if result > 0 then
TIO.Put_Line ("Notice: tty echo+control ON command failed");
end if;
end if;
end cone_of_silence;
-----------------------------
-- ignore_background_tty --
-----------------------------
procedure ignore_background_tty
is
result : uInt8;
begin
result := ignore_tty_write;
if result > 0 then
TIO.Put_Line ("Notice: ignoring background tty write signal failed");
end if;
result := ignore_tty_read;
if result > 0 then
TIO.Put_Line ("Notice: ignoring background tty read signal failed");
end if;
end ignore_background_tty;
-------------------------
-- kill_process_tree --
-------------------------
procedure kill_process_tree (process_group : pid_t)
is
use type IC.int;
result : constant IC.int := signal_runaway (process_group);
begin
if result /= 0 then
TIO.Put_Line ("Notice: failed to signal pid " & process_group'Img);
end if;
end kill_process_tree;
------------------------
-- external_command --
------------------------
function external_command (command : String) return Boolean
is
Args : OSL.Argument_List_Access;
Exit_Status : Integer;
begin
Args := OSL.Argument_String_To_List (command);
Exit_Status := OSL.Spawn (Program_Name => Args (Args'First).all,
Args => Args (Args'First + 1 .. Args'Last));
OSL.Free (Args);
return Exit_Status = 0;
end external_command;
-------------------
-- fork_failed --
-------------------
function fork_failed (pid : pid_t) return Boolean is
begin
if pid < 0 then
return True;
end if;
return False;
end fork_failed;
----------------------
-- launch_process --
----------------------
function launch_process (command : String) return pid_t
is
procid : OSL.Process_Id;
Args : OSL.Argument_List_Access;
begin
Args := OSL.Argument_String_To_List (command);
procid := OSL.Non_Blocking_Spawn
(Program_Name => Args (Args'First).all,
Args => Args (Args'First + 1 .. Args'Last));
OSL.Free (Args);
return pid_t (OSL.Pid_To_Integer (procid));
end launch_process;
----------------------------
-- env_variable_defined --
----------------------------
function env_variable_defined (variable : String) return Boolean
is
test : String := OSL.Getenv (variable).all;
begin
return (test /= "");
end env_variable_defined;
--------------------------
-- env_variable_value --
--------------------------
function env_variable_value (variable : String) return String is
begin
return OSL.Getenv (variable).all;
end env_variable_value;
------------------
-- pipe_close --
------------------
function pipe_close (OpenFile : CSM.FILEs) return Integer
is
res : constant CSM.int := pclose (FileStream => OpenFile);
u16 : Interfaces.Unsigned_16;
begin
u16 := Interfaces.Shift_Right (Interfaces.Unsigned_16 (res), 8);
if Integer (u16) > 0 then
return Integer (u16);
end if;
return Integer (res);
end pipe_close;
---------------------
-- piped_command --
---------------------
function piped_command (command : String; status : out Integer)
return JT.Text
is
redirect : constant String := " 2>&1";
filestream : CSM.FILEs;
result : JT.Text;
begin
filestream := popen (IC.To_C (command & redirect), IC.To_C ("re"));
result := pipe_read (OpenFile => filestream);
status := pipe_close (OpenFile => filestream);
return result;
end piped_command;
--------------------------
-- piped_mute_command --
--------------------------
function piped_mute_command (command : String; abnormal : out JT.Text) return Boolean
is
redirect : constant String := " 2>&1";
filestream : CSM.FILEs;
status : Integer;
begin
filestream := popen (IC.To_C (command & redirect), IC.To_C ("re"));
abnormal := pipe_read (OpenFile => filestream);
status := pipe_close (OpenFile => filestream);
return status = 0;
end piped_mute_command;
-----------------
-- pipe_read --
-----------------
function pipe_read (OpenFile : CSM.FILEs) return JT.Text
is
-- Allocate 2kb at a time
buffer : String (1 .. 2048) := (others => ' ');
result : JT.Text := JT.blank;
charbuf : CSM.int;
marker : Natural := 0;
begin
loop
charbuf := CSM.fgetc (OpenFile);
if charbuf = CSM.EOF then
if marker >= buffer'First then
JT.SU.Append (result, buffer (buffer'First .. marker));
end if;
exit;
end if;
if marker = buffer'Last then
JT.SU.Append (result, buffer);
marker := buffer'First;
else
marker := marker + 1;
end if;
buffer (marker) := Character'Val (charbuf);
end loop;
return result;
end pipe_read;
-----------------
-- true_path --
-----------------
function true_path (provided_path : String) return String
is
use type ICS.chars_ptr;
buffer : IC.char_array (0 .. 1024) := (others => IC.nul);
result : ICS.chars_ptr;
path : IC.char_array := IC.To_C (provided_path);
begin
result := realpath (pathname => path, resolved_path => buffer);
if result = ICS.Null_Ptr then
return "";
end if;
return ICS.Value (result);
exception
when others => return "";
end true_path;
end Unix;
|
with Ada.Text_Io; use Ada.Text_Io;
generic
SortName : in String;
type DataType is (<>);
type SortArrayType is array (Integer range <>) of DataType;
with procedure Sort (SortArray : in out SortArrayType;
Comp, Write, Ex : in out Natural);
package Instrument is
-- This generic package essentially accomplishes turning the sort
-- procedures into first-class functions for this limited purpose.
-- Obviously it doesn't change the way that Ada works with them;
-- the same thing would have been much more straightforward to
-- program in a language that had true first-class functions
package Dur_Io is new Fixed_Io(Duration);
procedure TimeSort (Arr : in out SortArrayType);
procedure Put;
procedure Put (File : in out File_Type);
end Instrument;
|
------------------------------------------------------------------------------
-- --
-- Matreshka Project --
-- --
-- Web Framework --
-- --
-- Web API Definition --
-- --
------------------------------------------------------------------------------
-- --
-- Copyright © 2015-2016, 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 WebAPI.DOM.Event_Targets;
package WebAPI.UI_Events.Mouse is
pragma Preelaborate;
type Mouse_Event is limited interface and WebAPI.UI_Events.UI_Event;
not overriding function Get_Screen_X
(Self : not null access constant Mouse_Event)
return WebAPI.DOM_Long is abstract
with Import => True,
Convention => JavaScript_Property_Getter,
Link_Name => "screenX";
-- The horizontal coordinate at which the event occurred relative to the
-- origin of the screen coordinate system.
not overriding function Get_Screen_Y
(Self : not null access constant Mouse_Event)
return WebAPI.DOM_Long is abstract
with Import => True,
Convention => JavaScript_Property_Getter,
Link_Name => "screenY";
-- The vertical coordinate at which the event occurred relative to the
-- origin of the screen coordinate system.
not overriding function Get_Client_X
(Self : not null access constant Mouse_Event)
return WebAPI.DOM_Long is abstract
with Import => True,
Convention => JavaScript_Property_Getter,
Link_Name => "clientX";
-- The horizontal coordinate at which the event occurred relative to the
-- viewport associated with the event.
not overriding function Get_Client_Y
(Self : not null access constant Mouse_Event)
return WebAPI.DOM_Long is abstract
with Import => True,
Convention => JavaScript_Property_Getter,
Link_Name => "clientY";
-- The vertical coordinate at which the event occurred relative to the
-- viewport associated with the event.
not overriding function Get_Ctrl_Key
(Self : not null access constant Mouse_Event) return Boolean is abstract
with Import => True,
Convention => JavaScript_Property_Getter,
Link_Name => "ctrlKey";
-- True if the 'Control' (control) key modifier was active.
not overriding function Get_Shift_Key
(Self : not null access constant Mouse_Event) return Boolean is abstract
with Import => True,
Convention => JavaScript_Property_Getter,
Link_Name => "shiftKey";
-- True if the shift ('Shift') key modifier was active.
not overriding function Get_Alt_Key
(Self : not null access constant Mouse_Event) return Boolean is abstract
with Import => True,
Convention => JavaScript_Property_Getter,
Link_Name => "altKey";
-- True if the 'Alt' (alternative) (or 'Option') key modifier was active.
not overriding function Get_Meta_Key
(Self : not null access constant Mouse_Event) return Boolean is abstract
with Import => True,
Convention => JavaScript_Property_Getter,
Link_Name => "metaKey";
-- True if the meta ('Meta') key modifier was active.
not overriding function Get_Button
(Self : not null access constant Mouse_Event)
return WebAPI.DOM_Long is abstract
with Import => True,
Convention => JavaScript_Property_Getter,
Link_Name => "button";
-- During mouse events caused by the depression or release of a mouse
-- button, button MUST be used to indicate which pointer device button
-- changed state.
not overriding function Get_Related_Target
(Self : not null access constant Mouse_Event)
return WebAPI.DOM.Event_Targets.Event_Target_Access is abstract
with Import => True,
Convention => JavaScript_Property_Getter,
Link_Name => "relatedTarget";
-- Used to identify a secondary EventTarget related to a UI event,
-- depending on the type of event.
not overriding function Get_Buttons
(Self : not null access constant Mouse_Event)
return WebAPI.DOM_Unsigned_Short is abstract
with Import => True,
Convention => JavaScript_Property_Getter,
Link_Name => "buttons";
-- During any mouse events, buttons MUST be used to indicate which
-- combination of mouse buttons are currently being pressed, expressed as a
-- bitmask.
not overriding function Get_Modifier_State
(Self : not null access constant Mouse_Event;
Key_Arg : WebAPI.DOM_String) return Boolean is abstract
with Import => True,
Convention => JavaScript_Property_Getter,
Link_Name => "getModifierState";
-- Queries the state of a modifier using a key value.
--
-- Returns true if it is a modifier key and the modifier is activated,
-- false otherwise.
end WebAPI.UI_Events.Mouse;
|
-- BinToAsc.Base64
-- Binary data to ASCII codecs - Base64 codec as in RFC4648
-- Copyright (c) 2015, James Humphry - see LICENSE file for details
generic
Alphabet : Alphabet_64;
Padding : Character;
package BinToAsc.Base64 is
type Base64_To_String is new Codec_To_String with private;
overriding
procedure Reset (C : out Base64_To_String);
overriding
function Input_Group_Size (C : in Base64_To_String) return Positive is (3);
overriding
function Output_Group_Size (C : in Base64_To_String) return Positive is (4);
overriding
procedure Process (C : in out Base64_To_String;
Input : in Bin;
Output : out String;
Output_Length : out Natural)
with Post => (Output_Length = 0 or Output_Length = 4);
overriding
procedure Process (C : in out Base64_To_String;
Input : in Bin_Array;
Output : out String;
Output_Length : out Natural)
with Post => (Output_Length / 4 = Input'Length / 3 or
Output_Length / 4 = Input'Length / 3 + 1);
overriding
procedure Complete (C : in out Base64_To_String;
Output : out String;
Output_Length : out Natural)
with Post => (Output_Length = 0 or Output_Length = 4);
function To_String (Input : in Bin_Array) return String;
type Base64_To_Bin is new Codec_To_Bin with private;
overriding
procedure Reset (C : out Base64_To_Bin);
overriding
function Input_Group_Size (C : in Base64_To_Bin) return Positive is (4);
overriding
function Output_Group_Size (C : in Base64_To_Bin) return Positive is (3);
overriding
procedure Process (C : in out Base64_To_Bin;
Input : in Character;
Output : out Bin_Array;
Output_Length : out Bin_Array_Index)
with Post => (Output_Length >= 0 and Output_Length <= 3);
overriding
procedure Process (C : in out Base64_To_Bin;
Input : in String;
Output : out Bin_Array;
Output_Length : out Bin_Array_Index)
with Post => ((Output_Length / 3 >= Input'Length / 4 - 1 and
Output_Length / 3 <= Input'Length / 4 + 1) or
C.State = Failed);
-- Re: the postcondition. If the input is a given number four character
-- groups but with the last containing padding, the output may be less than
-- that number of three character groups. As usual, if the codec contained
-- some partially decoded data, the number of output groups can be one more
-- than otherwise expected.
overriding
procedure Complete (C : in out Base64_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
type Base64_Bin_Index is range 0..2;
type Base64_Bin_Buffer is array (Base64_Bin_Index) of Bin;
type Base64_To_String is new Codec_To_String with
record
Next_Index : Base64_Bin_Index := 0;
Buffer : Base64_Bin_Buffer := (others => 0);
end record;
type Base64_Reverse_Index is range 0..3;
type Base64_Reverse_Buffer is array (Base64_Reverse_Index) of Bin;
type Base64_To_Bin is new Codec_To_Bin with
record
Next_Index : Base64_Reverse_Index := 0;
Buffer : Base64_Reverse_Buffer := (others => 0);
Padding_Length : Bin_Array_Index := 0;
end record;
end BinToAsc.Base64;
|
-- This file is covered by the Internet Software Consortium (ISC) License
-- Reference: ../License.txt
with Ada.Text_IO;
with Ada.Characters.Latin_1;
package body Signals is
package TIO renames Ada.Text_IO;
package LAT renames Ada.Characters.Latin_1;
-----------------------------------
-- graceful_shutdown_requested --
-----------------------------------
function graceful_shutdown_requested return Boolean
is
caught_char : Character;
got_one : Boolean;
begin
TIO.Get_Immediate (Item => caught_char, Available => got_one);
-- Although the variable is called control_c, it's Control-Q that
-- we are catching. It was the ESCAPE key after control-C, but that
-- one was getting triggered by terminal ANSI codes. Control-Q
-- requires the IXON TTY flag off (disabled output flow control).
if got_one and then caught_char = LAT.DC1 then
control_c_break := True;
end if;
return control_c_break;
exception
when others => return control_c_break;
end graceful_shutdown_requested;
---------------------------------------
-- immediate_termination_requested --
---------------------------------------
function immediate_termination_requested return Boolean is
begin
return seriously_break;
end immediate_termination_requested;
-- ----------------------
-- -- Signal_Handler --
-- ----------------------
-- protected body Signal_Handler is
--
-- -------------------------
-- -- capture_control_c --
-- -------------------------
-- procedure capture_control_c is
-- begin
-- if control_c_break then
-- seriously_break := True;
-- else
-- control_c_break := True;
-- end if;
-- end capture_control_c;
--
-- end Signal_Handler;
end Signals;
|
--
-- One writer, one reader at a time, using
-- protected object.
--
-- Output can be intermixed (can another
-- protected object be used to streamline output?)
--
-- Each task has its reference start time; shouldn't it be
-- the same for all? (Another protected object, again;
-- anyway the differences should be small)
--
-------------------
-- OUTPUT EXAMPLE
--
-- 0.000004000 R1 reading...
-- 0.000222000 OAT starts reading...
-- 0.000033000 0.000128000 ET writes 1...
-- R2 works for 2s
-- 2.000336000 R2 reading...
-- 3.000359000 OAT ended read
-- 3.000268000 3.000418000 OAT starts writing...
-- ...R1 read 0
-- 8.000543000 OAT ended writing...
-- 8.000542000 ET has written 1
-- 8.000588000 OAT starts reading...
-- 11.000725000 OAT ended read
-- 11.000623000 ...R2 read 1
-- *** R2 exit ***
-- 11.000794000 OAT starts reading...
-- 14.000952000 OAT ended read
-- 14.000848000*** R1 exit ***
--
-- R1 reads at 0, end reading at 3
-- ET starts writing at 0, but OAT is already reading,
-- so it really begins writing at 3, hence ending at 8
-- R2 starts reading at 2, and ends at 11
--
-- ..........1.
-- 0....5....0.
-- R1 RRR-----rrrRRR
-- R2 --rrrrrrRRR
-- ET wwwWWWWW____
--
-- When using a function, which isn't allowed to modify the data
-- of the protected object, Barnes (Programming in Ada 2012) says:
-- "The implementation is consequently permitted to perform the
-- useful optimization of allowing multiple calls of functions
-- at the same time thus automatically solving the basic classic
-- readers and writers problem".
--
-- The results are consistent with the implementation NOT doing
-- anything like this, even if I've used a function for reading.
--
-- BUT, I am also using a delay, gnat warns me so
-- potentially blocking operation in protected operation
-- for both the function and the procedure. Anyway, could the
-- delay be the bottleneck? (The delay waits itself...?)
--
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Calendar; use Ada.Calendar;
procedure Protect is
procedure Put_Time_Diff (D : in Time) is
T : Duration := Clock - D;
begin
Put (Duration'Image (T));
end Put_Time_Diff;
protected One_A_Time is
function Read return Integer;
-- Reading takes 3s
procedure Write (X : Integer);
-- Writing takes 5s
private
V : Integer := 0;
T : Time := Clock;
end One_A_Time;
protected body One_A_Time is
function Read return Integer is
begin
Put_Time_Diff (T); Put_Line (" OAT starts reading...");
delay 3.0;
Put_Time_Diff (T); Put_Line (" OAT ended read");
return V;
end Read;
procedure Write (X : Integer) is
begin
Put_Time_Diff (T); Put_Line (" OAT starts writing...");
delay 5.0;
V := X;
Put_Time_Diff (T); Put_Line (" OAT ended writing...");
end Write;
end One_A_Time;
task Reader1;
task Reader2;
task body Reader1 is
I : Integer;
T : Time := Clock;
begin
Put_Time_Diff (T);
Put_Line (" R1 reading...");
I := One_A_Time.Read;
Put_Time_Diff (T);
Put_Line (" ...R1 read" & Integer'Image (I));
delay 5.0;
-- try to read with R2
I := One_A_Time.Read;
Put_Time_Diff (T); Put_Line ("*** R1 exit ***");
end Reader1;
task body Reader2 is
I : Integer;
T : Time := Clock;
begin
Put_Time_Diff (T);
Put_Line (" R2 works for 2s");
delay 2.0;
Put_Time_Diff (T);
Put_Line (" R2 reading...");
I := One_A_Time.Read;
Put_Time_Diff (T);
Put_Line (" ...R2 read" & Integer'Image (I));
Put_Line ("*** R2 exit ***");
end Reader2;
T : Time := Clock;
begin
-- The main writes
Put_Time_Diff (T);
Put_Line (" ET writes 1...");
One_A_Time.Write (1);
Put_Time_Diff (T);
Put_Line (" ET has written 1");
end;
|
with Get_Line;
with Solitaire_Operations.Text_Representation;
with Ada.Characters.Handling;
with Ada.Strings.Unbounded;
with Ada.Text_IO;
use Ada;
use Ada.Characters;
use Ada.Strings.Unbounded;
procedure Encrypt is
Deck_Text : constant Solitaire_Operations.Text_Representation.Short_Card_Deck_String := Get_Line;
Deck : Solitaire_Operations.Deck_List;
Plain : Unbounded_String := To_Unbounded_String (Handling.To_Upper (Get_Line) );
subtype Letter is Character range 'A' .. 'Z';
begin -- Encrypt
Solitaire_Operations.Text_Representation.Set_Deck (Deck => Deck, To => Deck_Text);
Compress : for I in reverse 1 .. Length (Plain) loop -- Remove non-letters from plaintext
if Element (Plain, I) not in Letter then
Delete (Source => Plain, From => I, Through => I);
end if;
end loop Compress;
Expand : loop -- Make plaintext a multiple of 5 characters long by adding Xs to the end
exit Expand when Length (Plain) rem 5 = 0;
Append (Source => Plain, New_Item => 'X');
end loop Expand;
Create : declare
Crypto : String (1 .. Length (Plain) );
begin -- Create
Solitaire_Operations.Encrypt (Deck => Deck, Plain => To_String (Plain), Crypto => Crypto);
Text_IO.Put_Line (Item => Crypto);
end Create;
exception -- Encrypt
when Solitaire_Operations.Text_Representation.Card_Not_Found =>
Text_IO.Put_Line (Item => "Invalid deck");
end Encrypt;
|
with Type_Lib; use Type_Lib;
package PID_Functionality is
-- Procedures
procedure Position_Controller (K_PP : in Float; Pos_Error : in Float; Vel_Ref : out Float);
procedure Velocity_Controller (K_PV : in Float; Vel_Error : in Float; Torq_Ref : out Float);
procedure Map_To_RPM (Torq_Ref : in Float; RPM_Value : out RPM);
end PID_Functionality;
|
------------------------------------------------------------------------------
-- --
-- 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 lis3dsh.h --
-- @author MCD Application Team --
-- @version V1.1.0 --
-- @date 19-June-2014 --
-- @brief This file contains all the functions prototypes for the --
-- lis3dsh.c firmware driver. --
-- --
-- COPYRIGHT(c) 2014 STMicroelectronics --
------------------------------------------------------------------------------
-- This package provides an interface to the LIS3DSH accelerometer chip used
-- on later versions of the STM32F4 Discovery boards.
with Interfaces;
with HAL; use HAL;
package LIS3DSH is
type Three_Axis_Accelerometer is abstract tagged limited private;
-- This device can be connected through I2C or SPI. This package implements
-- an abstract driver with abstact IO subprograms, child packages will
-- provide I2C or SPI specific implementation.
type Axis_Acceleration is new Interfaces.Integer_16;
type Axes_Accelerations is record
X, Y, Z : Axis_Acceleration;
end record;
procedure Get_Accelerations
(This : Three_Axis_Accelerometer;
Axes : out Axes_Accelerations)
with Pre => Configured (This);
-- Note that the axes are orientated relative to the accelerometer chip
-- itself, of course. According to the LIS3DSH datasheet (Doc ID 022405
-- Rev 1, figure 2, page 10), pin 1 on the chip is marked on the top of
-- the package with a white/gray dot. That dot will be in the upper left
-- quadrant of the chip package when the board is oriented such that the
-- text on the board is right-side up and can be read normally, with the
-- power/debug USB connector CN1 at the top and the blue User button on the
-- left. Given that board orientation, the X axis runs left-right through
-- the User and Reset buttons. The Y axis is then orthogonal to that. The Z
-- axis runs through the chip itself, orthogonal to the plane of the board,
-- and will indicate 1G when the board is resting level.
function Device_Id (This : Three_Axis_Accelerometer) return UInt8;
I_Am_LIS3DSH : constant := 16#3F#;
-- For the values assigned to the enumerals in the following types,
-- see the LIS3DSH datasheet DM00040962. The values are their numerical
-- bit patterns, shifted into the proper bit positions to be used for
-- bit-masking into the control registers.
--
-- We assume nobody will want to use these as array type indexes, nor
-- will they want to use them as the type of for-loop parameters.
type Full_Scale_Selection is
(Fullscale_2g, -- 2 g
Fullscale_4g, -- 4 g
Fullscale_6g, -- 6 g
Fullscale_8g, -- 8 g
Fullscale_16g) -- 16 g
with Size => UInt8'Size;
for Full_Scale_Selection use -- bits 3..5 of CTRL5
(Fullscale_2g => 16#00#,
Fullscale_4g => 16#08#,
Fullscale_6g => 16#10#,
Fullscale_8g => 16#18#,
Fullscale_16g => 16#20#);
type Data_Rate_Power_Mode_Selection is
(Data_Rate_Powerdown, -- Power Down Mode
Data_Rate_3_125Hz, -- 3.125 Hz Normal Mode
Data_Rate_6_25Hz, -- 6.25 Hz Normal Mode
Data_Rate_12_5Hz, -- 12.5 Hz Normal Mode
Data_Rate_25Hz, -- 25 Hz Normal Mode
Data_Rate_50Hz, -- 50 Hz Normal Mode
Data_Rate_100Hz, -- 100 Hz Normal Mode
Data_Rate_400Hz, -- 400 Hz Normal Mode
Data_Rate_800Hz, -- 800 Hz Normal Mode
Data_Rate_1600Hz); -- 1600 Hz Normal Mode
for Data_Rate_Power_Mode_Selection use -- bits 4..6 of CTRL4
(Data_Rate_Powerdown => 16#00#,
Data_Rate_3_125Hz => 16#10#,
Data_Rate_6_25Hz => 16#20#,
Data_Rate_12_5Hz => 16#30#,
Data_Rate_25Hz => 16#40#,
Data_Rate_50Hz => 16#50#,
Data_Rate_100Hz => 16#60#,
Data_Rate_400Hz => 16#70#,
Data_Rate_800Hz => 16#80#,
Data_Rate_1600Hz => 16#90#);
type Anti_Aliasing_Filter_Bandwidth is
(Filter_800Hz,
Filter_400Hz,
Filter_200Hz,
Filter_50Hz);
for Anti_Aliasing_Filter_Bandwidth use -- bits 6..7 of CTRL5
(Filter_800Hz => 16#00#,
Filter_400Hz => 16#08#,
Filter_200Hz => 16#10#,
Filter_50Hz => 16#18#);
type Self_Test_Selection is
(Self_Test_Normal,
Self_Test_Positive,
Self_Test_Negative);
for Self_Test_Selection use -- bits 1..2 of CTRL5
(Self_Test_Normal => 16#00#,
Self_Test_Positive => 16#02#,
Self_Test_Negative => 16#04#);
type Direction_XYZ_Selection is
(X_Enabled,
Y_Enabled,
Z_Enabled,
XYZ_Enabled);
for Direction_XYZ_Selection use -- bits 0..2 of CTRL4
(X_Enabled => 16#01#,
Y_Enabled => 16#02#,
Z_Enabled => 16#04#,
XYZ_Enabled => 16#07#);
type SPI_Serial_Interface_Mode_Selection is
(Serial_Interface_4Wire,
Serial_Interface_3Wire);
for SPI_Serial_Interface_Mode_Selection use -- bit 0 of CTRL5
(Serial_Interface_4Wire => 16#00#,
Serial_Interface_3Wire => 16#01#);
procedure Configure
(This : in out Three_Axis_Accelerometer;
Output_DataRate : Data_Rate_Power_Mode_Selection;
Axes_Enable : Direction_XYZ_Selection;
SPI_Wire : SPI_Serial_Interface_Mode_Selection;
Self_Test : Self_Test_Selection;
Full_Scale : Full_Scale_Selection;
Filter_BW : Anti_Aliasing_Filter_Bandwidth)
with Post => Configured (This);
procedure Set_Full_Scale
(This : in out Three_Axis_Accelerometer;
Scale : Full_Scale_Selection)
with Pre => Configured (This);
procedure Set_Low_Power
(This : in out Three_Axis_Accelerometer;
Mode : Data_Rate_Power_Mode_Selection)
with Pre => Configured (This);
procedure Set_Data_Rate
(This : in out Three_Axis_Accelerometer;
DataRate : Data_Rate_Power_Mode_Selection)
with Pre => Configured (This);
function Selected_Sensitivity (This : Three_Axis_Accelerometer) return Float
with Pre => Configured (This);
-- The value determined by the current setting of Full_Scale, as set by
-- a prior call to Configure_Accelerometer.
-- Values return by function Selected_Sensitivity will be one of the
-- following:
Sensitivity_0_06mg : constant := 0.06; -- 0.06 mg/digit
Sensitivity_0_12mg : constant := 0.12; -- 0.12 mg/digit
Sensitivity_0_18mg : constant := 0.18; -- 0.18 mg/digit
Sensitivity_0_24mg : constant := 0.24; -- 0.24 mg/digit
Sensitivity_0_73mg : constant := 0.73; -- 0.73 mg/digit
procedure Reboot (This : in out Three_Axis_Accelerometer);
type State_Machine_Routed_Interrupt is
(SM_INT1,
SM_INT2);
for State_Machine_Routed_Interrupt use -- bit 3 of CTRL1/CTRL2
(SM_INT1 => 2#0000_0000#,
SM_INT2 => 2#0000_1000#);
type Interrupt_Request_Selection is
(Interrupt_Request_Latched,
Interrupt_Request_Pulsed);
for Interrupt_Request_Selection use -- bit 5 of CTRL3
(Interrupt_Request_Latched => 16#00#,
Interrupt_Request_Pulsed => 16#20#);
type Interrupt_Selection_Enablers is
(Interrupt_2_Enable,
Interrupt_1_Enable,
Interrupt_1_2_Enable);
for Interrupt_Selection_Enablers use -- values in bits 3..4 of CTRL3
(Interrupt_1_Enable => 2#1000_1000#,
-- Also enables Data Ready Enable bit in bit 7
Interrupt_2_Enable => 2#0001_0000#,
Interrupt_1_2_Enable => 2#1001_1000#);
-- Also enables Data Ready Enable bit in bit 7
-- NB lis3dsh.h uses different values???
type Interrupt_Signal_Active_Selection is
(Interrupt_Signal_Low,
Interrupt_Signal_High);
for Interrupt_Signal_Active_Selection use -- values in bit 6 of CTRL3
(Interrupt_Signal_Low => 2#0000_0000#,
Interrupt_Signal_High => 2#0100_0000#);
procedure Configure_Interrupts
(This : in out Three_Axis_Accelerometer;
Interrupt_Request : Interrupt_Request_Selection;
Interrupt_Selection_Enable : Interrupt_Selection_Enablers;
Interrupt_Signal : Interrupt_Signal_Active_Selection;
State_Machine1_Enable : Boolean;
State_Machine1_Interrupt : State_Machine_Routed_Interrupt;
State_Machine2_Enable : Boolean;
State_Machine2_Interrupt : State_Machine_Routed_Interrupt)
with Pre => Configured (This);
procedure Configure_Click_Interrupt (This : in out Three_Axis_Accelerometer)
with Pre => Configured (This);
function Temperature (This : Three_Axis_Accelerometer) return UInt8;
-- Zero corresponds to approx. 25 degrees Celsius
function Configured (This : Three_Axis_Accelerometer) return Boolean;
type Register_Address is new UInt8;
-- Prevent accidentally mixing addresses and data in I/O calls
-----------------------------
-- IO abstract subprograms --
-----------------------------
procedure IO_Write
(This : in out Three_Axis_Accelerometer;
Value : UInt8;
WriteAddr : Register_Address) is abstract;
procedure IO_Read
(This : Three_Axis_Accelerometer;
Value : out UInt8;
ReadAddr : Register_Address) is abstract;
private
type Three_Axis_Accelerometer is abstract tagged limited record
-- Ensures the device has been configured via some prior call to
-- Configure_Accelerometer. In addition, this flag also ensures that
-- the I/O facility has been initialized because Configure_Accelerometer
-- does that initialization too. Those routines that do NOT require
-- prior configuration explicitly initialize the I/O facility.
Device_Configured : Boolean := False;
-- The value determined by the current setting of Full_Scale, as set
-- by a prior call to Configure_Accelerometer. Storing this value is
-- an optimization over querying the chip, which is what the function
-- Selected_Sensitivity actually does. This component should always
-- provide the same value as that function.
Sensitivity : Float;
end record;
----------------------------------------------------------------------------
-- OUT_T: Temperature Output Register
-- Read only register
-- Default value: 0x21
-- 7:0 Temp7-Temp0: Temperature output Data
----------------------------------------------------------------------------
Out_T : constant Register_Address := 16#0C#;
----------------------------------------------------------------------------
-- INFO1 : Information Register 1
-- Read only register
-- Default value: 0x21
----------------------------------------------------------------------------
INFO1 : constant Register_Address := 16#0D#;
----------------------------------------------------------------------------
-- INFO2 : Information Register 2
-- Read only register
-- Default value: 0x00
----------------------------------------------------------------------------
INFO2 : constant Register_Address := 16#0E#;
----------------------------------------------------------------------------
-- WHO_AM_I : Device Identification Register
-- Read only register
-- Default value: 0x3F
----------------------------------------------------------------------------
WHO_AM_I : constant Register_Address := 16#0F#;
----------------------------------------------------------------------------
-- OFF_X : X-axis Offset Compensation Register
-- Read Write register
-- Default value: 0x00
-- 7:0 OFFx_7-OFFx_0: X-axis Offset Compensation Value
----------------------------------------------------------------------------
OFF_X : constant Register_Address := 16#10#;
----------------------------------------------------------------------------
-- OFF_Y : Y-axis Offset Compensation Register
-- Read Write register
-- Default value: 0x00
-- 7:0 OFFy_7-OFFy_0: Y-axis Offset Compensation Value
----------------------------------------------------------------------------
OFF_Y : constant Register_Address := 16#11#;
----------------------------------------------------------------------------
-- OFF_Z : Z-axis Offset Compensation Register
-- Read Write register
-- Default value: 0x00
-- 7:0 OFFz_7-OFFz_0: Z-axis Offset Compensation Value
----------------------------------------------------------------------------
OFF_Z : constant Register_Address := 16#12#;
----------------------------------------------------------------------------
-- CS_X : X-axis Constant Shift Register
-- Read Write register
-- Default value: 0x00
-- 7:0 CS_7-CS_0: X-axis Constant Shift Value
----------------------------------------------------------------------------
CS_X : constant Register_Address := 16#13#;
----------------------------------------------------------------------------
-- CS_Y : Y-axis Constant Shift Register
-- Read Write register
-- Default value: 0x00
-- 7:0 CS_7-CS_0: Y-axis Constant Shift Value
----------------------------------------------------------------------------
CS_Y : constant Register_Address := 16#14#;
----------------------------------------------------------------------------
-- CS_Z : Z-axis Constant Shift Value Register
-- Read Write register
-- Default value: 0x00
-- 7:0 CS_7-CS_0: Z-axis Constant Shift Value
----------------------------------------------------------------------------
CS_Z : constant Register_Address := 16#15#;
----------------------------------------------------------------------------
-- LC_L : Long Counter Low Register
-- Read Write register
-- Default value: 0x01
-- 7:0 LC_L_7-LC_L_0: Long Counter Low Value
----------------------------------------------------------------------------
LC_L : constant Register_Address := 16#16#;
----------------------------------------------------------------------------
-- LC_H : Long Counter High Register
-- Read Write register
-- Default value: 0x00
-- 7:0 LC_H_7-LC_H_0: Long Counter Low Value
----------------------------------------------------------------------------
LC_H : constant Register_Address := 16#17#;
----------------------------------------------------------------------------
-- STAT : State Machine Register
-- Read only register
-- Default value: 0x00
-- 7 LONG: LONG flag common to both State Machines
-- 0 - no interrupt
-- 1 - LongCounter interrupt flag
-- 6 SYNCW: Common information for OUTW host action waiting
-- 0 - no action waiting from Host
-- 1 - Host action is waiting after OUTW command
-- 5 SYNC1:
-- 0 - State Machine 1 running normally
-- 1 - SM1 stopped and waiting for restart request from SM2
-- 4 SYNC2:
-- 0 - State Machine 2 running normally
-- 1 - SM2 stopped and waiting for restart request from SM1
-- 3 INT_SM1: Interrupt signal on SM1 is reset when OUTS1 register is read
-- 0 - no interrupt on State Machine 1
-- 1 - State Machine 1 interrupt happened
-- 2 INT_SM2: Interrupt signal on SM2 is reset when OUTS2 register is read
-- 0 - no interrupt on State Machine 2
-- 1 - State Machine 2 interrupt happened
-- 1 DOR: Data OverRun bit
-- 0 - no overrun
-- 1 - data overrun
-- 0 DRDY: New data are ready in output registers
-- 0 - data not ready
-- 1 - data ready
----------------------------------------------------------------------------
STAT : constant Register_Address := 16#18#;
----------------------------------------------------------------------------
-- PEAK1 : Peak 1 Register
-- Read only register
-- Default value: 0x00
-- 7:0 PKx_7-PKx_0: Peak 1 Value for SM1
----------------------------------------------------------------------------
PEAK1 : constant Register_Address := 16#19#;
----------------------------------------------------------------------------
-- PEAK2 : Peak 2 Register
-- Read only register
-- Default value: 0x00
-- 7:0 PKx_7-PKx_0: Peak 2 value for SM2
----------------------------------------------------------------------------
PEAK2 : constant Register_Address := 16#1A#;
----------------------------------------------------------------------------
-- VFC_1 : Vector Filter Coefficient 1 Register
-- Read Write register
-- Default value: 0x00
-- 7:0 VFC1_7-VFC1_0: Vector Filter Coefficient 1 Value
----------------------------------------------------------------------------
VFC_1 : constant Register_Address := 16#1B#;
----------------------------------------------------------------------------
-- VFC_2 : Vector Filter Coefficient 2 Register
-- Read Write register
-- Default value: 0x00
-- 7:0 VFC2_7-VFC2_0: Vector Filter Coefficient 2 Value
----------------------------------------------------------------------------
VFC_2 : constant Register_Address := 16#1C#;
----------------------------------------------------------------------------
-- VFC_3 : Vector Filter Coefficient 3 Register
-- Read Write register
-- Default value: 0x00
-- 7:0 VFC3_7-VFC3_0: Vector Filter Coefficient 3 Value
----------------------------------------------------------------------------
VFC_3 : constant Register_Address := 16#1D#;
----------------------------------------------------------------------------
-- VFC_4 : Vector Filter Coefficient 4 Register
-- Read Write register
-- Default value: 0x00
-- 7:0 VFC4_7-VFC4_0: Vector Filter Coefficient 4 Value
----------------------------------------------------------------------------
VFC_4 : constant Register_Address := 16#1E#;
----------------------------------------------------------------------------
-- THRS3 : Threshold Value 3 Register
-- Read Write register
-- Default value: 0x00
-- 7:0 THRS3_7-THRS3_0: Common Threshold for Overrun Detection Value
----------------------------------------------------------------------------
THRS3 : constant Register_Address := 16#1F#;
----------------------------------------------------------------------------
-- CTRL_REG4 : Control Register 4
-- Read Write register
-- Default value: 0x07
-- 7:4 ODR3-ODR0: Data rate selection
-- ODR3 | ODR2 | ODR1 | ORD0 | ORD Selection
-- -------------------------------------------
-- 0 | 0 | 0 | 0 | Power Down (Default)
-- 0 | 0 | 0 | 1 | 3.125 Hz
-- 0 | 0 | 1 | 0 | 6.25 Hz
-- 0 | 0 | 1 | 1 | 12.5 Hz
-- 0 | 1 | 0 | 0 | 25 Hz
-- 0 | 1 | 0 | 1 | 50 Hz
-- 0 | 1 | 1 | 0 | 100 Hz
-- 0 | 1 | 1 | 1 | 400 Hz
-- 1 | 0 | 0 | 0 | 800 Hz
-- 1 | 0 | 0 | 1 | 1600 Hz
-- *
-- 3 BDU: Block data update
-- 0: Output register not updated until High and Low reading
-- (Default)
-- 1: Continuous update
-- 2 ZEN:
-- 0: Z-axis disable (Default)
-- 1: Z-axis enable
-- 1 YEN:
-- 0: Y-axis disable (Default)
-- 1: Y-axis enable
-- 0 XEN:
-- 0: Y-axis disable (Default)
-- 1: Y-axis enable
----------------------------------------------------------------------------
CTRL_REG4 : constant Register_Address := 16#20#;
----------------------------------------------------------------------------
-- CTRL_REG1 : Control Register 1 (SM1 interrupt configuration register)
-- Read Write register
-- Default value: 0x00
-- 7:5 HYST1_2-HYST1_0: Hysteresis which is added or subtracted from the
-- threshold values (THRS1_1 and THRS2_1) of SM1.
-- 000 = 0 (Default)
-- 111 = 7 (maximum Hysteresis)
-- 4 Reserved
-- 3 SM1_INT:
-- 0: State Machine 1 interrupt routed to INT1 (Default)
-- 1: State Machine 1 interrupt routed to INT2
-- 2 Reserved
-- 1 Reserved
-- 0 SM1_EN:
-- 0: State Machine 1 disabled. Temporary memories and registers
-- related to this State Machine are left intact. (Default)
-- 1: State Machine 1 enabled.
----------------------------------------------------------------------------
CTRL_REG1 : constant Register_Address := 16#21#;
----------------------------------------------------------------------------
-- CTRL_REG2 : Control Register 2 (SM2 interrupt configuration register)
-- Read Write register
-- Default value: 0x00
-- 7:5 HYST2_2-HYST2_0: Hysteresis which is added or subtracted from the
-- threshold values (THRS1_2 and THRS2_2) of SM1.
-- 000 = 0 (Default)
-- 111 = 7 (maximum Hysteresis)
-- 4 Reserved
-- 3 SM2_INT:
-- 0: State Machine 2 interrupt routed to INT1 (Default)
-- 1: State Machine 2 interrupt routed to INT2
-- 2 Reserved
-- 1 Reserved
-- 0 SM2_EN:
-- 0: State Machine 2 disabled. Temporary memories and registers
-- related to this State Machine are left intact. (Default)
-- 1: State Machine 2 enabled.
----------------------------------------------------------------------------
CTRL_REG2 : constant Register_Address := 16#22#;
----------------------------------------------------------------------------
-- CTRL_REG3 : Control Register 3 Read Write register Default value: 0x00 7
-- DR_EN: Data-ready interrupt
-- 0 - Data-ready interrupt disabled (Default)
-- 1 - Data-ready interrupt enabled and routed to INT1
-- 6 IEA:
-- 0 - Interrupt signal active LOW (Default)
-- 1 - Interrupt signal active HIGH
-- 5 IEL:
-- 0 - Interrupt latched (Default)
-- 1 - Interrupt pulsed
-- 4 INT2_EN:
-- 0 - INT2 signal disabled (High-Z state) (Default)
-- 1 - INT2 signal enabled (signal pin fully functional)
-- 3 INT1_EN:
-- 0 - INT1 (DRDY) signal disabled (High-Z state) (Default)
-- 1 - INT1 (DRDY) signal enabled (signal pin fully functional)
-- DR_EN bit in CTRL_REG3 should be taken into account too
-- 2 VLIFT:
-- 0 - Vector filter disabled (Default)
-- 1 - Vector filter enabled
-- 1 Reserved 0 STRT: Soft Reset
-- 0 - (Default)
-- 1 - it resets the whole internal logic circuitry.
----------------------------------------------------------------------------
CTRL_REG3 : constant Register_Address := 16#23#;
----------------------------------------------------------------------------
-- CTRL_REG5 : Control Register 5
-- Read Write register
-- Default value: 0x00
-- 7:6 BW2-BW1: Anti aliasing filter bandwidth
-- BW2 | BW1 | BW Selection
-- -------------------------
-- 0 | 0 | 800 Hz (Default)
-- 0 | 1 | 40 Hz
-- 1 | 0 | 200 Hz
-- 1 | 1 | 50 Hz
-- *
-- 5:3 FSCALE2-FSCALE0: Full scale selection
-- FSCALE2 | FSCALE1 | FSCALE0 | Full scale selection
-- --------------------------------------------------
-- 0 | 0 | 0 | +/-2g (Default)
-- 0 | 0 | 1 | +/-4g
-- 0 | 1 | 0 | +/-6g
-- 0 | 1 | 1 | +/-8g
-- 1 | 0 | 0 | +/-16g
-- *
-- 2:1 ST2_ST1: Self-test Enable
-- ST2 | ST1 | ST Selection
-- -------------------------
-- 0 | 0 | Normal Mode (Default)
-- 0 | 1 | Positive sign self-test
-- 1 | 0 | Negative sign-test
-- 1 | 1 | Not Allowed
-- *
-- 0 SIM: SPI serial internal interface mode selection
-- 0: 4-wire interface (Default)
-- 1: 3-wire interface
----------------------------------------------------------------------------
CTRL_REG5 : constant Register_Address := 16#24#;
----------------------------------------------------------------------------
-- CTRL_REG6 : Control Register 6
-- Read Write register
-- Default value: 0x00
-- 7 BOOT: Force reboot, cleared as soon as the reboot is finished. Active
-- High.
-- 6 FIFO_EN: FIFO Enable
-- 0: disable (Default)
-- 1: enable
-- 0: disable (Default)
-- 1: enable
-- 4 IF_ADD_INC: Register address automatically increased during a
-- multiple UInt8 access with a serial interface (I2C or SPI)
-- 0: disable (Default)
-- 1: enable
-- 3 I1_EMPTY: Enable FIFO Empty indication on INT1 pin.
-- 0: disable (Default)
-- 1: enable
-- 2 I1_WTM: FIFO Watermark interrupt on INT1 pin.
-- 0: disable (Default)
-- 1: enable
-- 1 I1_OVERRUN: FIFO Overrun interrupt on INT1 pin.
-- 0: disable (Default)
-- 1: enable
-- 0 I2_BOOT: BOOT interrupt on INT2 pin.
-- 0: disable (Default)
-- 1: enable
----------------------------------------------------------------------------
CTRL_REG6 : constant Register_Address := 16#25#;
----------------------------------------------------------------------------
-- STATUS : Status Data Register
-- Read only register
-- Default value: 0x00
-- 7 ZYXOR: X, Y and Z-axis Data Overrun.
-- 0: no Overrun has occurred (Default)
-- 1: a new set of data has overwritten the previous ones
-- 6 ZOR: Z-axis Data Overrun.
-- 0: no Overrun has occurred (Default)
-- 1: a new data for the Z-axis has overwritten the previous ones
-- 5 YOR: Y-axis Data Overrun.
-- 0: no Overrun has occurred (Default)
-- 1: a new data for the Y-axis has overwritten the previous ones
-- 4 XOR: X-axis Data Overrun.
-- 0: no Overrun has occurred (Default)
-- 1: a new data for the X-axis has overwritten the previous ones
-- 3 ZYXDA: X, Y and Z-axis new Data Available.
-- 0: a new set of data is not yet available (Default)
-- 1: a new set of data is available
-- 2 ZDA: Z-axis new data available.
-- 0: a new data for the Z-axis is not yet available (Default)
-- 1: a new data for Z-axis is available
-- 1 YDA: Y-axis new data available.
-- 0: a new data for the Y-axis is not yet available (Default)
-- 1: a new data for Y-axis is available
-- 0 XDA: X-axis new data available.
-- 0: a new data for the X-axis is not yet available (Default)
-- 1: a new data for X-axis is available
----------------------------------------------------------------------------
STATUS : constant Register_Address := 16#27#;
----------------------------------------------------------------------------
-- OUT_X_L : X-axis Output Acceleration Low Data
-- Read only register
-- Default value: output
-- 7:0 XD7-XD0: X-axis output Data
----------------------------------------------------------------------------
OUT_X_L : constant Register_Address := 16#28#;
----------------------------------------------------------------------------
-- OUT_X_H : X-axis Output Acceleration High Data
-- Read only register
-- Default value: output
-- 15:8 XD15-XD8: X-axis output Data
----------------------------------------------------------------------------
OUT_X_H : constant Register_Address := 16#29#;
----------------------------------------------------------------------------
-- OUT_Y_L : Y-axis Output Acceleration Low Data
-- Read only register
-- Default value: output
-- 7:0 YD7-YD0: Y-axis output Data
----------------------------------------------------------------------------
OUT_Y_L : constant Register_Address := 16#2A#;
----------------------------------------------------------------------------
-- OUT_Y_H : Y-axis Output Acceleration High Data
-- Read only register
-- Default value: output
-- 15:8 YD15-YD8: Y-axis output Data
----------------------------------------------------------------------------
OUT_Y_H : constant Register_Address := 16#2B#;
----------------------------------------------------------------------------
-- OUT_Z_L : Z-axis Output Acceleration Low Data
-- Read only register
-- Default value: output
-- 7:0 ZD7-ZD0: Z-axis output Data
----------------------------------------------------------------------------
OUT_Z_L : constant Register_Address := 16#2C#;
----------------------------------------------------------------------------
-- OUT_Z_H : Z-axis Output Acceleration High Data
-- Read only register
-- Default value: output
-- 15:8 ZD15-ZD8: Z-axis output Data
----------------------------------------------------------------------------
OUT_Z_H : constant Register_Address := 16#2D#;
----------------------------------------------------------------------------
-- FIFO_CTRL : FIFO Control Register
-- Read/Write register
-- Default value: 0x00
-- 7:5 FMODE2-FMODE0: FIFO mode
-- FMODE2 | FMODE1 | FMODE0 | Mode description
-- --------------------------------------------------
-- 0 | 0 | 0 | Bypass mode. FIFO turned off. (Default)
-- 0 | 0 | 1 | FIFO mode. Stop collecting data
-- when FIFO is full.
-- 0 | 1 | 0 | Stream mode. If the FIFO is full, the
-- new sample overwrites the older one
-- (circular buffer).
-- 0 | 1 | 1 | Stream mode until trigger is
-- de-asserted, then FIFO mode.
-- 1 | 0 | 0 | Bypass mode until trigger is
-- de-asserted, then Stream mode.
-- 1 | 0 | 1 | Not to use.
-- 1 | 1 | 0 | Not to use.
-- 1 | 1 | 1 | Bypass mode until trigger is
-- de-asserted, then FIFO mode.
-- *
-- 4:0 WTMP4-WTMP0: FIFO Watermark pointer. It is the FIFO depth when the
-- Watermark is enabled
----------------------------------------------------------------------------
FIFO_CTRL : constant Register_Address := 16#2E#;
----------------------------------------------------------------------------
-- FIFO_SRC : FIFO Source Register
-- Read only register
-- Default value: 0x00
-- 7 WTM: Watermark status.
-- 0: FIFO filling is lower than WTM level (Default)
-- 1: FIFO filling is equal or higher than WTM level
-- 6 OVRN_FIFO: Overrun bit status.
-- 0: FIFO is not completely filled (Default)
-- 1: FIFO is completely filled
-- 5 EMPTY: Overrun bit status.
-- 0: FIFO not empty (Default)
-- 1: FIFO empty
-- 4:0 FSS: Number of samples stored in the FIFO - 1
----------------------------------------------------------------------------
FIFO_SRC : constant Register_Address := 16#2F#;
----------------------------------------------------------------------------
-- ST1_X : State Machine 1 Code Registers
-- Write only register
-- Default value: 0x00
-- 7:0 ST1_7-ST1_0: State Machine 1 Code Registers
----------------------------------------------------------------------------
ST1_1 : constant Register_Address := 16#40#;
ST1_2 : constant Register_Address := 16#41#;
ST1_3 : constant Register_Address := 16#42#;
ST1_4 : constant Register_Address := 16#43#;
ST1_5 : constant Register_Address := 16#44#;
ST1_6 : constant Register_Address := 16#45#;
ST1_7 : constant Register_Address := 16#46#;
ST1_8 : constant Register_Address := 16#47#;
ST1_9 : constant Register_Address := 16#48#;
ST1_10 : constant Register_Address := 16#49#;
ST1_11 : constant Register_Address := 16#4A#;
ST1_12 : constant Register_Address := 16#4B#;
ST1_13 : constant Register_Address := 16#4C#;
ST1_14 : constant Register_Address := 16#4D#;
ST1_15 : constant Register_Address := 16#4E#;
ST1_16 : constant Register_Address := 16#4F#;
----------------------------------------------------------------------------
-- TIM4_1 : SM1 General Timer 4 Register
-- Write only register
-- Default value: 0x00
-- 7:0 TM_7-TM_0: SM1 Timer 4 Counter 1 Value
----------------------------------------------------------------------------
TIM4_1 : constant Register_Address := 16#50#;
----------------------------------------------------------------------------
-- TIM3_1 : SM1 General Timer 3 Register
-- Write only register
-- Default value: 0x00
-- 7:0 TM_7-TM_0: SM1 Timer 3 Counter 1 Value
----------------------------------------------------------------------------
TIM3_1 : constant Register_Address := 16#51#;
----------------------------------------------------------------------------
-- TIM2_1_L : SM1 General Timer 2 Low Register
-- Write only register
-- Default value: 0x00
-- 7:0 TM_7-TM_0: SM1 Timer 2 Counter 1 Low Value
----------------------------------------------------------------------------
TIM2_1_L : constant Register_Address := 16#52#;
----------------------------------------------------------------------------
-- TIM2_1_H : SM1 General Timer 2 High Register
-- Write only register
-- Default value: 0x00
-- 15:8 TM_15-TM_8: SM1 Timer 2 Counter 1 High Value
----------------------------------------------------------------------------
TIM2_1_H : constant Register_Address := 16#53#;
----------------------------------------------------------------------------
-- TIM1_1_L : SM1 General Timer 1 Low Register
-- Write only register
-- Default value: 0x00
-- 7:0 TM_7-TM_0: SM1 Timer 1 Counter 1 Low Value
----------------------------------------------------------------------------
TIM1_1_L : constant Register_Address := 16#54#;
----------------------------------------------------------------------------
-- TIM1_1_H : SM1 General Timer 1 High Register
-- Write only register
-- Default value: 0x00
-- 15:8 TM_15-TM_8: SM1 Timer 1 Counter 1 High Value
----------------------------------------------------------------------------
TIM1_1_H : constant Register_Address := 16#55#;
----------------------------------------------------------------------------
-- THRS2_1 : SM1 Threshold Value 1 Register
-- Write only register
-- Default value: 0x00
-- 7:0 THS7-THS0: SM1 Threshold Value 1
----------------------------------------------------------------------------
THRS2_1 : constant Register_Address := 16#56#;
----------------------------------------------------------------------------
-- THRS1_1 : SM1 Threshold Value 2 Register
-- Write only register
-- Default value: 0x00
-- 7:0 THS7-THS0: SM1 Threshold Value 2
----------------------------------------------------------------------------
THRS1_1 : constant Register_Address := 16#57#;
----------------------------------------------------------------------------
-- MASK1_B : SM1 Swap Axis and Sign Mask Register
-- Write only register
-- Default value: 0x00
-- 7 P_X: X-Axis Positive Motion Detection
-- 0: X+ disabled
-- 1: X+ enabled
-- 6 N_X: X-Axis Negative Motion Detection
-- 0: X- disabled
-- 1: X- enabled
-- 5 P_Y: Y-Axis Positive Motion Detection
-- 0: Y+ disabled
-- 1: Y+ enabled
-- 4 N_Y: Y-Axis Negative Motion Detection
-- 0: Y- disabled
-- 1: Y- enabled
-- 3 P_Z: X-Axis Positive Motion Detection
-- 0: Z+ disabled
-- 1: Z+ enabled
-- 2 N_Z: X-Axis Negative Motion Detection
-- 0: Z- disabled
-- 1: Z- enabled
-- 1 P_V:
-- 0: V+ disabled
-- 1: V+ enabled
-- 0 N_V:
-- 0: V- disabled
-- 1: V- enabled
----------------------------------------------------------------------------
MASK1_B : constant Register_Address := 16#59#;
----------------------------------------------------------------------------
-- MASK1_A : SM1 Default Axis and Sign Mask Register
-- Write only register
-- Default value: 0x00
-- 7 P_X: X-Axis Positive Motion Detection
-- 0: X+ disabled
-- 1: X+ enabled
-- 6 N_X: X-Axis Negative Motion Detection
-- 0: X- disabled
-- 1: X- enabled
-- 5 P_Y: Y-Axis Positive Motion Detection
-- 0: Y+ disabled
-- 1: Y+ enabled
-- 4 N_Y: Y-Axis Negative Motion Detection
-- 0: Y- disabled
-- 1: Y- enabled
-- 3 P_Z: X-Axis Positive Motion Detection
-- 0: Z+ disabled
-- 1: Z+ enabled
-- 2 N_Z: X-Axis Negative Motion Detection
-- 0: Z- disabled
-- 1: Z- enabled
-- 1 P_V:
-- 0: V+ disabled
-- 1: V+ enabled
-- 0 N_V:
-- 0: V- disabled
-- 1: V- enabled
----------------------------------------------------------------------------
MASK1_A : constant Register_Address := 16#5A#;
----------------------------------------------------------------------------
-- SETT1 : SM1 Detection Settings Register
-- Write only register
-- Default value: 0x00
-- 7 P_DET: SM1 peak detection bit
-- 0: peak detection disabled (Default)
-- 1: peak detection enabled
-- 6 THR3_SA:
-- 0: no action (Default)
-- 1: threshold 3 enabled for axis and sign mask reset (MASK1_B)
-- 5 ABS:
-- 0: unsigned thresholds THRSx (Default)
-- 1: signed thresholds THRSx
-- 4 Reserved
-- 3 Reserved
-- 2 THR3_MA:
-- 0: no action (Default)
-- 1: threshold 3 enabled for axis and sign mask reset (MASK1_A)
-- 1 R_TAM: Next condition validation flag
-- 0: mask frozen on axis that triggers the condition (Default)
-- 1: standard mask always evaluated
-- 0 SITR:
-- 0: no actions (Default)
-- 1: STOP and CONT commands generate an interrupt and perform
-- output actions as OUTC command.
----------------------------------------------------------------------------
SETT1 : constant Register_Address := 16#5B#;
----------------------------------------------------------------------------
-- PR1 : SM1 Program and Reset Pointers Register
-- Read only register
-- Default value: 0x00
-- 7:4 PP3-PP0: SM1 program pointer address
-- 3:0 RP3-RP0: SM1 reset pointer address
----------------------------------------------------------------------------
PR1 : constant Register_Address := 16#5C#;
----------------------------------------------------------------------------
-- TC1_L : SM1 General Timer Counter Low Register
-- Read only register
-- Default value: 0x00
-- 7:0 TC1_7-TC1_0: SM1 General Timer Counter Low Value
----------------------------------------------------------------------------
TC1_L : constant Register_Address := 16#5D#;
----------------------------------------------------------------------------
-- TC1_H : SM1 General Timer Counter High Register
-- Read only register
-- Default value: 0x00
-- 15:8 TC1_15-TC1_8: SM1 General Timer Counter High Value
----------------------------------------------------------------------------
TC1_H : constant Register_Address := 16#5E#;
----------------------------------------------------------------------------
-- OUTS1 : SM1 Output Set Flag Register
-- Read only register
-- Default value: 0x00
-- 7 P_X:
-- 0: X+ noshow
-- 1: X+ show
-- 6 N_X:
-- 0: X- noshow
-- 1: X- show
-- 5 P_Y:
-- 0: Y+ noshow
-- 1: Y+ show
-- 4 N_Y:
-- 0: Y- noshow
-- 1: Y- show
-- 3 P_Z:
-- 0: Z+ noshow
-- 1: Z+ show
-- 2 N_Z:
-- 0: Z- noshow
-- 1: Z- show
-- 1 P_V:
-- 0: V+ noshow
-- 1: V+ show
-- 0 N_V:
-- 0: V- noshow
-- 1: V- show
----------------------------------------------------------------------------
OUTS1 : constant Register_Address := 16#5F#;
----------------------------------------------------------------------------
-- ST2_X : State Machine 2 Code Registers
-- Write only register
-- Default value: 0x00
-- 7:0 ST2_7-ST2_0: State Machine 2 Code Registers
----------------------------------------------------------------------------
ST2_1 : constant Register_Address := 16#60#;
ST2_2 : constant Register_Address := 16#61#;
ST2_3 : constant Register_Address := 16#62#;
ST2_4 : constant Register_Address := 16#63#;
ST2_5 : constant Register_Address := 16#64#;
ST2_6 : constant Register_Address := 16#65#;
ST2_7 : constant Register_Address := 16#66#;
ST2_8 : constant Register_Address := 16#67#;
ST2_9 : constant Register_Address := 16#68#;
ST2_10 : constant Register_Address := 16#69#;
ST2_11 : constant Register_Address := 16#6A#;
ST2_12 : constant Register_Address := 16#6B#;
ST2_13 : constant Register_Address := 16#6C#;
ST2_14 : constant Register_Address := 16#6D#;
ST2_15 : constant Register_Address := 16#6E#;
ST2_16 : constant Register_Address := 16#6F#;
----------------------------------------------------------------------------
-- TIM4_2 : SM2 General Timer 4 Register
-- Write only register
-- Default value: 0x00
-- 7:0 TM_7-TM_0: SM2 Timer 4 Counter 1 Value
----------------------------------------------------------------------------
TIM4_2 : constant Register_Address := 16#70#;
----------------------------------------------------------------------------
-- TIM3_2 : SM2 General Timer 3 Register
-- Write only register
-- Default value: 0x00
-- 7:0 TM_7-TM_0: SM2 Timer 3 Counter 2 Value
----------------------------------------------------------------------------
TIM3_2 : constant Register_Address := 16#71#;
----------------------------------------------------------------------------
-- TIM2_2_L : SM2 General Timer 2 Low Register
-- Write only register
-- Default value: 0x00
-- 7:0 TM_7-TM_0: SM2 Timer 2 Counter 2 Low Value
----------------------------------------------------------------------------
TIM2_2_L : constant Register_Address := 16#72#;
----------------------------------------------------------------------------
-- TIM2_2_H : SM2 General Timer 2 High Register
-- Write only register
-- Default value: 0x00
-- 15:8 TM_15-TM_8: SM2 Timer 2 Counter 2 High Value
----------------------------------------------------------------------------
TIM2_2_H : constant Register_Address := 16#73#;
----------------------------------------------------------------------------
-- TIM1_2_L : SM2 General Timer 1 Low Register
-- Write only register
-- Default value: 0x00
-- 7:0 TM_7-TM_0: SM2 Timer 1 Counter 2 Low Value
----------------------------------------------------------------------------
TIM1_2_L : constant Register_Address := 16#74#;
----------------------------------------------------------------------------
-- TIM1_2_H : SM2 General Timer 1 High Register
-- Write only register
-- Default value: 0x00
-- 15:8 TM_15-TM_8: SM2 Timer 1 Counter 2 High Value
----------------------------------------------------------------------------
TIM1_2_H : constant Register_Address := 16#75#;
----------------------------------------------------------------------------
-- THRS2_2 : SM2 Threshold Value 1 Register
-- Write only register
-- Default value: 0x00
-- 7:0 THS7-THS0: SM2 Threshold Value
----------------------------------------------------------------------------
THRS2_2 : constant Register_Address := 16#76#;
----------------------------------------------------------------------------
-- THRS1_2 : SM2 Threshold Value 2 Register
-- Write only register
-- Default value: 0x00
-- 7:0 THS7-THS0: SM2 Threshold Value
----------------------------------------------------------------------------
THRS1_2 : constant Register_Address := 16#77#;
----------------------------------------------------------------------------
-- DES2 : SM2 Decimation Counter Value Register
-- Write only register
-- Default value: 0x00
-- 7:0 D7-D0: SM2 Decimation Counter Value
----------------------------------------------------------------------------
DES2 : constant Register_Address := 16#78#;
----------------------------------------------------------------------------
-- MASK2_B : SM2 Axis and Sign Mask Register
-- Write only register
-- Default value: 0x00
-- 7 P_X: X-Axis Positive Motion Detection
-- 0: X+ disabled
-- 1: X+ enabled
-- 6 N_X: X-Axis Negative Motion Detection
-- 0: X- disabled
-- 1: X- enabled
-- 5 P_Y: Y-Axis Positive Motion Detection
-- 0: Y+ disabled
-- 1: Y+ enabled
-- 4 N_Y: Y-Axis Negative Motion Detection
-- 0: Y- disabled
-- 1: Y- enabled
-- 3 P_Z: X-Axis Positive Motion Detection
-- 0: Z+ disabled
-- 1: Z+ enabled
-- 2 N_Z: X-Axis Negative Motion Detection
-- 0: Z- disabled
-- 1: Z- enabled
-- 1 P_V:
-- 0: V+ disabled
-- 1: V+ enabled
-- 0 N_V:
-- 0: V- disabled
-- 1: V- enabled
----------------------------------------------------------------------------
MASK2_B : constant Register_Address := 16#79#;
----------------------------------------------------------------------------
-- MASK2_A : SM2 Axis and Sign Mask Register
-- Write only register
-- Default value: 0x00
-- 7 P_X: X-Axis Positive Motion Detection
-- 0: X+ disabled
-- 1: X+ enabled
-- 6 N_X: X-Axis Negative Motion Detection
-- 0: X- disabled
-- 1: X- enabled
-- 5 P_Y: Y-Axis Positive Motion Detection
-- 0: Y+ disabled
-- 1: Y+ enabled
-- 4 N_Y: Y-Axis Negative Motion Detection
-- 0: Y- disabled
-- 1: Y- enabled
-- 3 P_Z: X-Axis Positive Motion Detection
-- 0: Z+ disabled
-- 1: Z+ enabled
-- 2 N_Z: X-Axis Negative Motion Detection
-- 0: Z- disabled
-- 1: Z- enabled
-- 1 P_V:
-- 0: V+ disabled
-- 1: V+ enabled
-- 0 N_V:
-- 0: V- disabled
-- 1: V- enabled
----------------------------------------------------------------------------
MASK2_A : constant Register_Address := 16#7A#;
----------------------------------------------------------------------------
-- SETT2 : SM2 Detection Settings Register
-- Write only register
-- Default value: 0x00
-- 7 P_DET: SM2 peak detection
-- 0: peak detection disabled (Default)
-- 1: peak detection enabled
-- 6 THR3_SA:
-- 0: no action (Default)
-- 1: threshold 3 limit value for axis and sign mask reset
-- (MASK2_B)
-- 5 ABS:
-- 0: unsigned thresholds (Default)
-- 1: signed thresholds
-- 4 RADI:
-- 0: raw data
-- 1: diff data for State Machine 2
-- 3 D_CS:
-- 0: DIFF2 enabled (difference between current data and previous
-- data)
-- 1: constant shift enabled (difference between current data and
-- constant values)
-- 2 THR3_MA:
-- 0: no action (Default)
-- 1: threshold 3 enabled for axis and sign mask reset (MASK2_A)
-- 1 R_TAM: Next condition validation flag
-- 0: mask frozen on the axis that triggers the condition
-- (Default)
-- 1: standard mask always evaluated
-- 0 SITR:
-- 0: no actions (Default)
-- 1: STOP and CONT commands generate an interrupt and perform
-- output actions as OUTC command.
----------------------------------------------------------------------------
SETT2 : constant Register_Address := 16#7B#;
----------------------------------------------------------------------------
-- PR2 : SM2 Program and Reset Pointers Register
-- Read only register
-- Default value: 0x00
-- 7:4 PP3-PP0: SM1 program pointer address
-- 3:0 RP3-RP0: SM1 reset pointer address
----------------------------------------------------------------------------
PR2 : constant Register_Address := 16#7C#;
----------------------------------------------------------------------------
-- TC2_L : SM2 General Timer Counter Low Register
-- Read only register
-- Default value: 0x00
-- 7:0 TC2_7-TC2_0: SM2 General Timer Counter Low Value
----------------------------------------------------------------------------
TC2_L : constant Register_Address := 16#7D#;
----------------------------------------------------------------------------
-- TC2_H : SM2 General Timer Counter High Register
-- Read only register
-- Default value: 0x00
-- 15:8 TC2_15-TC2_8: SM2 General Timer Counter High Value
----------------------------------------------------------------------------
TC2_H : constant Register_Address := 16#7E#;
----------------------------------------------------------------------------
-- OUTS2 : SM2 Output Set Flag Register
-- Read only register
-- Default value: 0x00
-- 7 P_X:
-- 0: X+ noshow
-- 1: X+ show
-- 6 N_X:
-- 0: X- noshow
-- 1: X- show
-- 5 P_Y:
-- 0: Y+ noshow
-- 1: Y+ show
-- 4 N_Y:
-- 0: Y- noshow
-- 1: Y- show
-- 3 P_Z:
-- 0: Z+ noshow
-- 1: Z+ show
-- 2 N_Z:
-- 0: Z- noshow
-- 1: Z- show
-- 1 P_V:
-- 0: V+ noshow
-- 1: V+ show
-- 0 N_V:
-- 0: V- noshow
-- 1: V- show
----------------------------------------------------------------------------
OUTS2 : constant Register_Address := 16#7F#;
-- During SPI communication, the most significant bit of the register
-- address specifies if the operation is read or write.
SPI_Read_Flag : constant Register_Address := 16#80#;
SPI_Write_Flag : constant Register_Address := 16#00#;
end LIS3DSH;
|
package Constant_Declaration is
The_Constant : constant Integer := 1;
end Constant_Declaration;
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.