• R/O
  • SSH

AdaMagic_Experiments: Commit

Experiments aiming to become more familiar with AdaMagic. Porting System.Atomic_Counters to AdaMagic.


Commit MetaInfo

Revisióne91cb0062fb0c534f473493f8b9ccef314632bd4 (tree)
Tiempo2019-01-13 01:42:42
AutorLevashev Ivan <bu_ <gen@octa...>
CommiterLevashev Ivan <bu_

Log Message

Implementing atomic counters

Cambiar Resumen

Diferencia

diff -r 000000000000 -r e91cb0062fb0 .hgignore
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/.hgignore Sat Jan 12 19:42:42 2019 +0300
@@ -0,0 +1,5 @@
1+syntax: glob
2+*.exe
3+*.link_o
4+Intermediate/
5+UNIT.MAP
diff -r 000000000000 -r e91cb0062fb0 ADA.LIB
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/ADA.LIB Sat Jan 12 19:42:42 2019 +0300
@@ -0,0 +1,24 @@
1+MSGSUB: ------------------------------------------------------------------------------
2+MSGSUB: -- Copyright 2019 Levashev Ivan Aleksandrovich --
3+MSGSUB: -- --
4+MSGSUB: -- Licensed under the Apache License, Version 2.0 (the "License"); --
5+MSGSUB: -- you may not use this file except in compliance with the License. --
6+MSGSUB: -- You may obtain a copy of the License at --
7+MSGSUB: -- --
8+MSGSUB: -- http://www.apache.org/licenses/LICENSE-2.0 --
9+MSGSUB: -- --
10+MSGSUB: -- Unless required by applicable law or agreed to in writing, software --
11+MSGSUB: -- distributed under the License is distributed on an "AS IS" BASIS, --
12+MSGSUB: -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --
13+MSGSUB: -- See the License for the specific language governing permissions and --
14+MSGSUB: -- limitations under the License. --
15+MSGSUB: ------------------------------------------------------------------------------
16+
17+ILSUB: Intermediate/Source
18+XILSUB: Intermediate/Include
19+OBJSUB: Intermediate/Objects
20+INFSUB: Intermediate/Information
21+XREFSUB: Intermediate/Reference
22+PATH
23+ PATHNAME: D:\MapuSoft\AppCOE_x32\Tools\Ada\windows\rtl.windows
24+ENDPATH
diff -r 000000000000 -r e91cb0062fb0 Compile.cmd
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Compile.cmd Sat Jan 12 19:42:42 2019 +0300
@@ -0,0 +1,18 @@
1+@echo off
2+rem ------------------------------------------------------------------------------
3+rem -- Copyright 2019 Levashev Ivan Aleksandrovich --
4+rem -- --
5+rem -- Licensed under the Apache License, Version 2.0 (the "License"); --
6+rem -- you may not use this file except in compliance with the License. --
7+rem -- You may obtain a copy of the License at --
8+rem -- --
9+rem -- http://www.apache.org/licenses/LICENSE-2.0 --
10+rem -- --
11+rem -- Unless required by applicable law or agreed to in writing, software --
12+rem -- distributed under the License is distributed on an "AS IS" BASIS, --
13+rem -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --
14+rem -- See the License for the specific language governing permissions and --
15+rem -- limitations under the License. --
16+rem ------------------------------------------------------------------------------
17+
18+adabgen -ke -kt -kc -kh -xr -g -ga -gc -trace -2005 Experiments.Hello
diff -r 000000000000 -r e91cb0062fb0 README.txt
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/README.txt Sat Jan 12 19:42:42 2019 +0300
@@ -0,0 +1,16 @@
1+AdaMagic experiments
2+
3+AdaMagic is almost the only way to target many platforms like
4+WebAssembly and Elbrus e2k without compromising quality. It
5+makes sense to get familiar with it.
6+
7+AdaMagic is stuck at Ada 95. Little to no Ada 2005 support.
8+Some compatibility code should be implemented.
9+
10+AdaMagic lacks documentation. It uses either C or C++, but
11+that is sometimes tricky. Sometimes tricky things are desired
12+to be expressed, and this project is about achieving it.
13+
14+The first thing to do was to backport atomic counters.
15+
16+2019, Levashev Ivan Aleksandrovich, Saint Petersburg
diff -r 000000000000 -r e91cb0062fb0 Redo_Registration.cmd
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Redo_Registration.cmd Sat Jan 12 19:42:42 2019 +0300
@@ -0,0 +1,19 @@
1+@echo off
2+rem ------------------------------------------------------------------------------
3+rem -- Copyright 2019 Levashev Ivan Aleksandrovich --
4+rem -- --
5+rem -- Licensed under the Apache License, Version 2.0 (the "License"); --
6+rem -- you may not use this file except in compliance with the License. --
7+rem -- You may obtain a copy of the License at --
8+rem -- --
9+rem -- http://www.apache.org/licenses/LICENSE-2.0 --
10+rem -- --
11+rem -- Unless required by applicable law or agreed to in writing, software --
12+rem -- distributed under the License is distributed on an "AS IS" BASIS, --
13+rem -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --
14+rem -- See the License for the specific language governing permissions and --
15+rem -- limitations under the License. --
16+rem ------------------------------------------------------------------------------
17+
18+del UNIT.MAP
19+adareg Source
diff -r 000000000000 -r e91cb0062fb0 Source/Experiments.Hello.adb
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Source/Experiments.Hello.adb Sat Jan 12 19:42:42 2019 +0300
@@ -0,0 +1,34 @@
1+------------------------------------------------------------------------------
2+-- Copyright 2019 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 Ada.Text_IO;
18+with System.Atomic_Counters;
19+
20+procedure Experiments.Hello is
21+ use Ada.Text_IO;
22+ use System.Atomic_Counters;
23+
24+ X : aliased Atomic_Counter;
25+begin
26+ Increment (X);
27+ if Decrement (X'Access) then
28+ Put_Line ("Hello, world.");
29+ else
30+ if Decrement (X'Access) then
31+ Put_Line ("Hello, world 2.");
32+ end if;
33+ end if;
34+end Experiments.Hello;
diff -r 000000000000 -r e91cb0062fb0 Source/Experiments.Referencing.ads
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Source/Experiments.Referencing.ads Sat Jan 12 19:42:42 2019 +0300
@@ -0,0 +1,19 @@
1+------------------------------------------------------------------------------
2+-- Copyright 2019 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 Experiments.Referencing is
18+
19+end Experiments.Referencing;
diff -r 000000000000 -r e91cb0062fb0 Source/Experiments.ads
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Source/Experiments.ads Sat Jan 12 19:42:42 2019 +0300
@@ -0,0 +1,19 @@
1+------------------------------------------------------------------------------
2+-- Copyright 2019 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 Experiments is
18+
19+end Experiments;
diff -r 000000000000 -r e91cb0062fb0 Source/System.Atomic_Counters.ads
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Source/System.Atomic_Counters.ads Sat Jan 12 19:42:42 2019 +0300
@@ -0,0 +1,72 @@
1+------------------------------------------------------------------------------
2+-- Copyright 2019 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 System.Atomic_Counters is
18+
19+ pragma Pure;
20+ pragma Preelaborate;
21+
22+ type Atomic_Counter is limited private;
23+ -- Type for atomic counter objects. Note, initial value of the counter is
24+ -- one. This allows using an atomic counter as member of record types when
25+ -- object of these types are created at library level in preelaborable
26+ -- compilation units.
27+ --
28+ -- Atomic_Counter is declared as private limited type to provide highest
29+ -- level of protection from unexpected use. All available operations are
30+ -- declared below, and this set should be as small as possible.
31+ -- Increment/Decrement operations for this type raise Program_Error on
32+ -- platforms not supporting the atomic primitives.
33+
34+ procedure Increment (Item : in out Atomic_Counter);
35+ -- Increments value of atomic counter.
36+
37+ function Decrement (Item : access Atomic_Counter) return Boolean;
38+ -- Decrements value of atomic counter, returns True when value reach zero
39+
40+ function Is_One (Item : Atomic_Counter) return Boolean;
41+ -- Returns True when value of the atomic counter is one
42+
43+ procedure Initialize (Item : out Atomic_Counter);
44+ -- Initialize counter by setting its value to one. This subprogram is
45+ -- intended to be used in special cases when the counter object cannot be
46+ -- initialized in standard way.
47+
48+private
49+
50+ type Atomic_Unsigned is mod 2 ** 32;
51+ pragma Default_Value (Atomic_Unsigned, 0);
52+ pragma Atomic (Atomic_Unsigned);
53+
54+ -- pragma Inline_Always (Is_One);
55+ -- pragma Inline_Always (Initialize);
56+ -- pragma Inline_Always (Increment);
57+ -- pragma Inline_Always (Decrement);
58+
59+ type Atomic_Counter is record
60+ Value : aliased Atomic_Unsigned := 1;
61+ pragma Atomic (Value);
62+ end record;
63+
64+ type Include_Atomic_Counters is new Integer;
65+ pragma Import (C, Include_Atomic_Counters, "#include <Source/System.Atomic_Counters.h>", "int");
66+
67+ pragma Import (Intrinsic, Increment, "System__Atomic_Counters__Increment");
68+ pragma Import (Intrinsic, Decrement, "System__Atomic_Counters__Decrement");
69+ pragma Import (Intrinsic, Is_One, "System__Atomic_Counters__Is_One");
70+ pragma Import (Intrinsic, Initialize, "System__Atomic_Counters__Initialize");
71+
72+end System.Atomic_Counters;
diff -r 000000000000 -r e91cb0062fb0 Source/System.Atomic_Counters.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Source/System.Atomic_Counters.h Sat Jan 12 19:42:42 2019 +0300
@@ -0,0 +1,40 @@
1+/****************************************************************************\
2+** Copyright 2019 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+#ifndef H__system__atomic_counters_h
18+#define H__system__atomic_counters_h
19+
20+#include <stdint.h>
21+
22+typedef uint32_t System__Atomic_Counters__Atomic_Counter;
23+
24+#ifdef __cplusplus
25+
26+#define System__Atomic_Counters__Increment(Item) __sync_add_and_fetch(&(((System::Atomic_counters::Atomic_counter *)(Item))->Value), 1U)
27+#define System__Atomic_Counters__Decrement(Item, Item___accessibility) ((Boolean )(__sync_sub_and_fetch(&(((System::Atomic_counters::Atomic_counter *)(Item))->Value), 1U) == 0U))
28+#define System__Atomic_Counters__Is_One(Item) ((Boolean )(((System::Atomic_counters::Atomic_counter *)(Item))->Value == 1U))
29+#define System__Atomic_Counters__Initialize(Item) ((System::Atomic_counters::Atomic_counter *)(Item))->Value = 1U
30+
31+#else
32+
33+#define System__Atomic_Counters__Increment(Item) __sync_add_and_fetch(&(((System_Atomic_counters_Atomic_counter *)(Item))->Value), 1U)
34+#define System__Atomic_Counters__Decrement(Item, Item___accessibility) ((Boolean )(__sync_sub_and_fetch(&(((System_Atomic_counters_Atomic_counter *)(Item))->Value), 1U) == 0U))
35+#define System__Atomic_Counters__Is_One(Item) ((Boolean )(((System_Atomic_counters_Atomic_counter *)(Item))->Value == 1U))
36+#define System__Atomic_Counters__Initialize(Item) ((System_Atomic_counters_Atomic_counter *)(Item))->Value = 1U
37+
38+#endif
39+
40+#endif
Show on old repository browser