New main repository
Revision | 36a147b87f3f202af761be75bab2da5bbffd22a9 (tree) |
---|---|
Time | 2023-01-08 19:22:23 |
Author | Ivan Levashev 卜根 <bu_ <gen@octa...> |
Commiter | Ivan Levashev 卜根 <bu_ |
Type information: initialization
@@ -15,7 +15,7 @@ | ||
15 | 15 | ------------------------------------------------------------------------------ |
16 | 16 | |
17 | 17 | with PAF.Storage_Pools.Reallocatable; |
18 | -with PAF.Storage_Pools.Default_Instance; | |
18 | +with PAF.Storage_Pools.Default_Internal; | |
19 | 19 | |
20 | 20 | package PAF.Storage_Pools.Default is |
21 | 21 | pragma Preelaborate (PAF.Storage_Pools.Default); |
@@ -23,6 +23,6 @@ | ||
23 | 23 | -- Classwide reference to the default pool |
24 | 24 | |
25 | 25 | Pool : Reallocatable.Reallocatable_Pool'Class |
26 | - renames Default_Instance.Pool_Access.all; | |
26 | + renames Default_Internal.Pool_Access.all; | |
27 | 27 | |
28 | 28 | end PAF.Storage_Pools.Default; |
@@ -1,34 +0,0 @@ | ||
1 | ------------------------------------------------------------------------------- | |
2 | --- Copyright 2023 Levashev Ivan Aleksandrovich -- | |
3 | --- -- | |
4 | --- Licensed under the Apache License, Version 2.0 (the "License"); -- | |
5 | --- you may not use this file except in compliance with the License. -- | |
6 | --- You may obtain a copy of the License at -- | |
7 | --- -- | |
8 | --- http://www.apache.org/licenses/LICENSE-2.0 -- | |
9 | --- -- | |
10 | --- Unless required by applicable law or agreed to in writing, software -- | |
11 | --- distributed under the License is distributed on an "AS IS" BASIS, -- | |
12 | --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- | |
13 | --- See the License for the specific language governing permissions and -- | |
14 | --- limitations under the License. -- | |
15 | ------------------------------------------------------------------------------- | |
16 | - | |
17 | -with PAF.Storage_Pools.Reallocatable; | |
18 | -with PAF.Storage_Pools.Default_Types; | |
19 | - | |
20 | -package PAF.Storage_Pools.Default_Instance is | |
21 | - pragma Preelaborate (PAF.Storage_Pools.Default_Instance); | |
22 | - | |
23 | - -- Moved to separate package to workaround error in renaming declaration: | |
24 | - -- deferred constant is frozen before completion | |
25 | - | |
26 | - Pool_Access : constant Reallocatable.Reallocatable_Pool_Access; | |
27 | - | |
28 | -private | |
29 | - | |
30 | - Pool_Instance : aliased Default_Types.Default_Pool; | |
31 | - Pool_Access : constant Reallocatable.Reallocatable_Pool_Access := | |
32 | - Pool_Instance'Access; | |
33 | - | |
34 | -end PAF.Storage_Pools.Default_Instance; |
@@ -0,0 +1,34 @@ | ||
1 | +------------------------------------------------------------------------------ | |
2 | +-- Copyright 2023 Levashev Ivan Aleksandrovich -- | |
3 | +-- -- | |
4 | +-- Licensed under the Apache License, Version 2.0 (the "License"); -- | |
5 | +-- you may not use this file except in compliance with the License. -- | |
6 | +-- You may obtain a copy of the License at -- | |
7 | +-- -- | |
8 | +-- http://www.apache.org/licenses/LICENSE-2.0 -- | |
9 | +-- -- | |
10 | +-- Unless required by applicable law or agreed to in writing, software -- | |
11 | +-- distributed under the License is distributed on an "AS IS" BASIS, -- | |
12 | +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- | |
13 | +-- See the License for the specific language governing permissions and -- | |
14 | +-- limitations under the License. -- | |
15 | +------------------------------------------------------------------------------ | |
16 | + | |
17 | +with PAF.Storage_Pools.Reallocatable; | |
18 | +with PAF.Storage_Pools.Default_Types; | |
19 | + | |
20 | +package PAF.Storage_Pools.Default_Internal is | |
21 | + pragma Preelaborate (PAF.Storage_Pools.Default_Internal); | |
22 | + | |
23 | + -- Moved to separate package to workaround error in renaming declaration: | |
24 | + -- deferred constant is frozen before completion | |
25 | + | |
26 | + Pool_Access : constant Reallocatable.Reallocatable_Pool_Access; | |
27 | + | |
28 | +private | |
29 | + | |
30 | + Pool_Instance : aliased Default_Types.Default_Pool; | |
31 | + Pool_Access : constant Reallocatable.Reallocatable_Pool_Access := | |
32 | + Pool_Instance'Access; | |
33 | + | |
34 | +end PAF.Storage_Pools.Default_Internal; |
@@ -0,0 +1,57 @@ | ||
1 | +------------------------------------------------------------------------------ | |
2 | +-- Copyright 2023 Levashev Ivan Aleksandrovich -- | |
3 | +-- -- | |
4 | +-- Licensed under the Apache License, Version 2.0 (the "License"); -- | |
5 | +-- you may not use this file except in compliance with the License. -- | |
6 | +-- You may obtain a copy of the License at -- | |
7 | +-- -- | |
8 | +-- http://www.apache.org/licenses/LICENSE-2.0 -- | |
9 | +-- -- | |
10 | +-- Unless required by applicable law or agreed to in writing, software -- | |
11 | +-- distributed under the License is distributed on an "AS IS" BASIS, -- | |
12 | +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- | |
13 | +-- See the License for the specific language governing permissions and -- | |
14 | +-- limitations under the License. -- | |
15 | +------------------------------------------------------------------------------ | |
16 | + | |
17 | +package PAF.Type_Information.Default is | |
18 | + pragma Preelaborate (PAF.Type_Information.Default); | |
19 | + | |
20 | + -- It may make sense to have additional support for character, integral, | |
21 | + -- enumeration and Boolean types. But not yet | |
22 | + | |
23 | + package Boolean_Type_Information is | |
24 | + new Default_Ordinal_Type_Information (Boolean); | |
25 | + | |
26 | + package Character_8_Type_Information is new Default_Ordinal_Type_Information | |
27 | + (Character_8, | |
28 | + Default_Value => Character_8'Val (16#20#)); | |
29 | + package Character_16_Type_Information is new Default_Ordinal_Type_Information | |
30 | + (Character_16, | |
31 | + Default_Value => Character_16'Val (16#20#)); | |
32 | + package Character_32_Type_Information is new Default_Ordinal_Type_Information | |
33 | + (Character_32, | |
34 | + Default_Value => Character_32'Val (16#20#)); | |
35 | + | |
36 | + package Integer_Type_Information is | |
37 | + new Default_Ordinal_Type_Information (Integer); | |
38 | + package Natural_Type_Information is | |
39 | + new Default_Ordinal_Type_Information (Natural); | |
40 | + package Positive_Type_Information is | |
41 | + new Default_Ordinal_Type_Information (Positive); | |
42 | + | |
43 | + package Integer_32_Type_Information is | |
44 | + new Default_Ordinal_Type_Information (Integer_32); | |
45 | + package Natural_32_Type_Information is | |
46 | + new Default_Ordinal_Type_Information (Natural_32); | |
47 | + package Positive_32_Type_Information is | |
48 | + new Default_Ordinal_Type_Information (Positive_32); | |
49 | + | |
50 | + package Integer_64_Type_Information is | |
51 | + new Default_Ordinal_Type_Information (Integer_64); | |
52 | + package Natural_64_Type_Information is | |
53 | + new Default_Ordinal_Type_Information (Natural_64); | |
54 | + package Positive_64_Type_Information is | |
55 | + new Default_Ordinal_Type_Information (Positive_64); | |
56 | + | |
57 | +end PAF.Type_Information.Default; |
@@ -0,0 +1,65 @@ | ||
1 | +------------------------------------------------------------------------------ | |
2 | +-- Copyright 2023 Levashev Ivan Aleksandrovich -- | |
3 | +-- -- | |
4 | +-- Licensed under the Apache License, Version 2.0 (the "License"); -- | |
5 | +-- you may not use this file except in compliance with the License. -- | |
6 | +-- You may obtain a copy of the License at -- | |
7 | +-- -- | |
8 | +-- http://www.apache.org/licenses/LICENSE-2.0 -- | |
9 | +-- -- | |
10 | +-- Unless required by applicable law or agreed to in writing, software -- | |
11 | +-- distributed under the License is distributed on an "AS IS" BASIS, -- | |
12 | +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -- | |
13 | +-- See the License for the specific language governing permissions and -- | |
14 | +-- limitations under the License. -- | |
15 | +------------------------------------------------------------------------------ | |
16 | + | |
17 | +with System.Storage_Elements; | |
18 | +with PAF.Memory_Operations; | |
19 | + | |
20 | +package body PAF.Type_Information is | |
21 | + | |
22 | + -------------------------------------- | |
23 | + -- Default_Ordinal_Type_Information -- | |
24 | + -------------------------------------- | |
25 | + | |
26 | + package body Default_Ordinal_Type_Information is | |
27 | + | |
28 | + use System.Storage_Elements; | |
29 | + | |
30 | + ---------------------- | |
31 | + -- Initialize_Array -- | |
32 | + ---------------------- | |
33 | + | |
34 | + procedure Initialize_Array | |
35 | + (Array_Address : System.Address; Count : Natural) | |
36 | + is | |
37 | + Elements : array (Positive range 1 .. Count) of Element_Type; | |
38 | + pragma Import (Ada, Elements); | |
39 | + for Elements'Address use Array_Address; | |
40 | + begin | |
41 | + if Default_Is_Zeroed_Memory then | |
42 | + Memory_Operations.Fill | |
43 | + (Target => Array_Address, Item => 0, | |
44 | + Count => (Elements'Size + System.Storage_Unit - 1) / System.Storage_Unit); | |
45 | + else | |
46 | + for Index in Elements'Range loop | |
47 | + Elements (Index) := Default_Value; | |
48 | + end loop; | |
49 | + end if; | |
50 | + end Initialize_Array; | |
51 | + | |
52 | + -------------------- | |
53 | + -- Finalize_Array -- | |
54 | + -------------------- | |
55 | + | |
56 | + procedure Finalize_Array | |
57 | + (Array_Address : System.Address; Count : Natural) is | |
58 | + begin | |
59 | + null; | |
60 | + end Finalize_Array; | |
61 | + | |
62 | + end Default_Ordinal_Type_Information; | |
63 | + | |
64 | + | |
65 | +end PAF.Type_Information; |
@@ -14,8 +14,10 @@ | ||
14 | 14 | -- limitations under the License. -- |
15 | 15 | ------------------------------------------------------------------------------ |
16 | 16 | |
17 | +with System; | |
18 | + | |
17 | 19 | package PAF.Type_Information is |
18 | - pragma Pure (PAF.Type_Information); | |
20 | + pragma Preelaborate (PAF.Type_Information); | |
19 | 21 | |
20 | 22 | -- Element type is nonlimited and definite |
21 | 23 | -- Is_Controlled means some RAII is required |
@@ -28,61 +30,36 @@ | ||
28 | 30 | Default_Is_Zeroed_Memory : Boolean := False; |
29 | 31 | Is_Controlled : Boolean := True; |
30 | 32 | Is_Tracked : Boolean := Is_Controlled; |
33 | + with procedure Initialize_Array (Array_Address : System.Address; Count : Natural); | |
34 | + with procedure Finalize_Array (Array_Address : System.Address; Count : Natural); | |
31 | 35 | package Element_Type_Information is |
32 | 36 | pragma Assert (Is_Controlled >= Is_Tracked); |
37 | + end Element_Type_Information; | |
33 | 38 | |
34 | - end Element_Type_Information; | |
39 | + -- There can be formal package Ordinal_Type_Information, but not yet | |
35 | 40 | |
36 | 41 | generic |
37 | 42 | type Element_Type is (<>); |
43 | + Default_Value : Element_Type := | |
44 | + Element_Type'Val (Integer_64'Max | |
45 | + (0, Element_Type'Pos (Element_Type'First))); | |
38 | 46 | Default_Is_Zeroed_Memory : Boolean := |
39 | - Element_Type'Pos (Element_Type'First) <= 0; | |
40 | - package Ordinal_Type_Information is | |
47 | + Element_Type'Pos (Default_Value) = 0; | |
48 | + package Default_Ordinal_Type_Information is | |
49 | + | |
50 | + procedure Initialize_Array (Array_Address : System.Address; Count : Natural); | |
51 | + procedure Finalize_Array (Array_Address : System.Address; Count : Natural); | |
41 | 52 | |
42 | 53 | package As_Element is new Element_Type_Information |
43 | - (Element_Type => Ordinal_Type_Information.Element_Type, | |
54 | + (Element_Type => Default_Ordinal_Type_Information.Element_Type, | |
44 | 55 | Default_Is_Zeroed_Memory => Default_Is_Zeroed_Memory, |
45 | - Is_Controlled => False, | |
46 | - Is_Tracked => False); | |
47 | - end Ordinal_Type_Information; | |
48 | - | |
49 | - -- It may make sense to have additional support for character, integral, | |
50 | - -- enumeration and Boolean types. But not yet | |
51 | - | |
52 | - package Boolean_Type_Information is | |
53 | - new Ordinal_Type_Information (Boolean); | |
54 | - | |
55 | - -- Default character is space | |
56 | - | |
57 | - package Character_8_Type_Information is new Ordinal_Type_Information | |
58 | - (Character_8, | |
59 | - Default_Is_Zeroed_Memory => False); | |
60 | - package Character_16_Type_Information is new Ordinal_Type_Information | |
61 | - (Character_16, | |
62 | - Default_Is_Zeroed_Memory => False); | |
63 | - package Character_32_Type_Information is new Ordinal_Type_Information | |
64 | - (Character_32, | |
65 | - Default_Is_Zeroed_Memory => False); | |
66 | - | |
67 | - package Integer_Type_Information is | |
68 | - new Ordinal_Type_Information (Integer); | |
69 | - package Natural_Type_Information is | |
70 | - new Ordinal_Type_Information (Natural); | |
71 | - package Positive_Type_Information is | |
72 | - new Ordinal_Type_Information (Positive); | |
73 | - | |
74 | - package Integer_32_Type_Information is | |
75 | - new Ordinal_Type_Information (Integer_32); | |
76 | - package Natural_32_Type_Information is | |
77 | - new Ordinal_Type_Information (Natural_32); | |
78 | - package Positive_32_Type_Information is | |
79 | - new Ordinal_Type_Information (Positive_32); | |
80 | - | |
81 | - package Integer_64_Type_Information is | |
82 | - new Ordinal_Type_Information (Integer_64); | |
83 | - package Natural_64_Type_Information is | |
84 | - new Ordinal_Type_Information (Natural_64); | |
85 | - package Positive_64_Type_Information is | |
86 | - new Ordinal_Type_Information (Positive_64); | |
56 | + Is_Controlled => False, | |
57 | + Is_Tracked => False, | |
58 | + Initialize_Array => Initialize_Array, | |
59 | + Finalize_Array => Finalize_Array); | |
60 | + private | |
61 | + pragma Inline (Initialize_Array); | |
62 | + pragma Inline (Finalize_Array); | |
63 | + end Default_Ordinal_Type_Information; | |
87 | 64 | |
88 | 65 | end PAF.Type_Information; |
@@ -14,6 +14,9 @@ | ||
14 | 14 | -- limitations under the License. -- |
15 | 15 | ------------------------------------------------------------------------------ |
16 | 16 | |
17 | +with System; | |
18 | +with PAF.Type_Information.Default; | |
19 | + | |
17 | 20 | package body PAF.Type_Information.Test is |
18 | 21 | |
19 | 22 | procedure Test_Boolean; |
@@ -21,6 +24,7 @@ | ||
21 | 24 | procedure Test_Characters_Zeroed_Memory; |
22 | 25 | procedure Test_Integers; |
23 | 26 | procedure Test_Integers_Zeroed_Memory; |
27 | + procedure Test_Initialize; | |
24 | 28 | |
25 | 29 | -------------------------------------- |
26 | 30 | -- Type_Information_Test.Initialize -- |
@@ -43,6 +47,8 @@ | ||
43 | 47 | (Object, Test_Integers'Access, "Test_Integers"); |
44 | 48 | Ahven.Framework.Add_Test_Routine |
45 | 49 | (Object, Test_Integers_Zeroed_Memory'Access, "Test_Integers_Zeroed_Memory"); |
50 | + Ahven.Framework.Add_Test_Routine | |
51 | + (Object, Test_Initialize'Access, "Test_Initialize"); | |
46 | 52 | end Initialize; |
47 | 53 | |
48 | 54 | ---------------------------------- |
@@ -82,10 +88,14 @@ | ||
82 | 88 | Default_Is_Zeroed_Memory : Boolean renames Element_Information.Default_Is_Zeroed_Memory; |
83 | 89 | Is_Controlled : Boolean renames Element_Information.Is_Controlled; |
84 | 90 | Is_Tracked : Boolean renames Element_Information.Is_Tracked; |
91 | + procedure Initialize_Array (Array_Address : System.Address; Count : Natural) | |
92 | + renames Element_Information.Initialize_Array; | |
93 | + procedure Finalize_Array (Array_Address : System.Address; Count : Natural) | |
94 | + renames Element_Information.Finalize_Array; | |
85 | 95 | end Extract_Information; |
86 | 96 | |
87 | 97 | package Extract_Boolean is new Extract_Information |
88 | - (Boolean_Type_Information.As_Element); | |
98 | + (Default.Boolean_Type_Information.As_Element); | |
89 | 99 | |
90 | 100 | ------------------ |
91 | 101 | -- Test_Boolean -- |
@@ -102,11 +112,11 @@ | ||
102 | 112 | end Test_Boolean; |
103 | 113 | |
104 | 114 | package Extract_Character_8 is new Extract_Information |
105 | - (Character_8_Type_Information.As_Element); | |
115 | + (Default.Character_8_Type_Information.As_Element); | |
106 | 116 | package Extract_Character_16 is new Extract_Information |
107 | - (Character_16_Type_Information.As_Element); | |
117 | + (Default.Character_16_Type_Information.As_Element); | |
108 | 118 | package Extract_Character_32 is new Extract_Information |
109 | - (Character_32_Type_Information.As_Element); | |
119 | + (Default.Character_32_Type_Information.As_Element); | |
110 | 120 | |
111 | 121 | --------------------- |
112 | 122 | -- Test_Characters -- |
@@ -147,25 +157,25 @@ | ||
147 | 157 | end Test_Characters_Zeroed_Memory; |
148 | 158 | |
149 | 159 | package Extract_Integer is new Extract_Information |
150 | - (Integer_Type_Information.As_Element); | |
160 | + (Default.Integer_Type_Information.As_Element); | |
151 | 161 | package Extract_Natural is new Extract_Information |
152 | - (Natural_Type_Information.As_Element); | |
162 | + (Default.Natural_Type_Information.As_Element); | |
153 | 163 | package Extract_Positive is new Extract_Information |
154 | - (Positive_Type_Information.As_Element); | |
164 | + (Default.Positive_Type_Information.As_Element); | |
155 | 165 | |
156 | 166 | package Extract_Integer_32 is new Extract_Information |
157 | - (Integer_32_Type_Information.As_Element); | |
167 | + (Default.Integer_32_Type_Information.As_Element); | |
158 | 168 | package Extract_Natural_32 is new Extract_Information |
159 | - (Natural_32_Type_Information.As_Element); | |
169 | + (Default.Natural_32_Type_Information.As_Element); | |
160 | 170 | package Extract_Positive_32 is new Extract_Information |
161 | - (Positive_32_Type_Information.As_Element); | |
171 | + (Default.Positive_32_Type_Information.As_Element); | |
162 | 172 | |
163 | 173 | package Extract_Integer_64 is new Extract_Information |
164 | - (Integer_64_Type_Information.As_Element); | |
174 | + (Default.Integer_64_Type_Information.As_Element); | |
165 | 175 | package Extract_Natural_64 is new Extract_Information |
166 | - (Natural_64_Type_Information.As_Element); | |
176 | + (Default.Natural_64_Type_Information.As_Element); | |
167 | 177 | package Extract_Positive_64 is new Extract_Information |
168 | - (Positive_64_Type_Information.As_Element); | |
178 | + (Default.Positive_64_Type_Information.As_Element); | |
169 | 179 | |
170 | 180 | ------------------- |
171 | 181 | -- Test_Integers -- |
@@ -241,4 +251,29 @@ | ||
241 | 251 | "not Extract_Positive_64.Default_Is_Zeroed_Memory"); |
242 | 252 | end Test_Integers_Zeroed_Memory; |
243 | 253 | |
254 | + --------------------- | |
255 | + -- Test_Initialize -- | |
256 | + --------------------- | |
257 | + | |
258 | + procedure Test_Initialize is | |
259 | + Default_Integer : aliased Integer := -6768; | |
260 | + Default_Natural : aliased Natural := 995; | |
261 | + Default_Positive : aliased Positive := 547; | |
262 | + Default_Character_32 : aliased Character_32 := Character_32'Val (81134); | |
263 | + Default_Boolean : aliased Boolean := True; | |
264 | + begin | |
265 | + Extract_Integer.Initialize_Array (Default_Integer'Address, 1); | |
266 | + Extract_Natural.Initialize_Array (Default_Natural'Address, 1); | |
267 | + Extract_Positive.Initialize_Array (Default_Positive'Address, 1); | |
268 | + Extract_Character_32.Initialize_Array (Default_Character_32'Address, 1); | |
269 | + Extract_Boolean.Initialize_Array (Default_Boolean'Address, 1); | |
270 | + | |
271 | + Ahven.Assert (Default_Integer = 0, "Default_Integer = 0"); | |
272 | + Ahven.Assert (Default_Natural = 0, "Default_Natural = 0"); | |
273 | + Ahven.Assert (Default_Positive = 1, "Default_Positive = 1"); | |
274 | + Ahven.Assert (Default_Character_32 = Character_32'Val (16#20#), | |
275 | + "Default_Character_32 = Character_32'Val (16#20#)"); | |
276 | + Ahven.Assert (not Default_Boolean, "not Default_Boolean"); | |
277 | + end Test_Initialize; | |
278 | + | |
244 | 279 | end PAF.Type_Information.Test; |