From d13a5af72aaaf608cd5d434edac4fe6fbdf2748a Mon Sep 17 00:00:00 2001 From: Ernie Pasveer Date: Mon, 8 May 2023 20:44:46 -0500 Subject: [PATCH] Add calling of a subprograms (soubroutines) to the Ada test program. --- tests/helloada/Makefile | 2 +- tests/helloada/README.build | 12 +++++++++++ tests/helloada/helloada.adb | 38 +++++++++++++++++++++++++++++++++ tests/helloada/increment_by.adb | 6 ++++++ tests/helloada/increment_by.ads | 4 ++++ 5 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 tests/helloada/README.build create mode 100644 tests/helloada/increment_by.adb create mode 100644 tests/helloada/increment_by.ads diff --git a/tests/helloada/Makefile b/tests/helloada/Makefile index c3a24ec..db58a1e 100644 --- a/tests/helloada/Makefile +++ b/tests/helloada/Makefile @@ -6,5 +6,5 @@ helloada: helloada.adb .PHONY: clean clean: - rm -f helloada helloada.o helloada.ali b~* + rm -f helloada helloada.o helloada.ali b~* increment_by.ali increment_by.o diff --git a/tests/helloada/README.build b/tests/helloada/README.build new file mode 100644 index 0000000..d4c7663 --- /dev/null +++ b/tests/helloada/README.build @@ -0,0 +1,12 @@ + +$ gnatmake -c --GCC=/usr/bin/gcc-7 -O3 increment_by.adb +$ gnatmake -c --GCC=/usr/bin/gcc-7 -g helloada.adb +$ gnatmake -b --GCC=/usr/bin/gcc-7 -g helloada.adb +$ gnatlink helloada + +$ file helloada helloada.o increment_by.o +helloada: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=dfc77b85b759a22a42ddaa75c050d4458b3175a4, for GNU/Linux 3.2.0, with debug_info, not stripped +helloada.o: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), with debug_info, not stripped +increment_by.o: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), not stripped + + diff --git a/tests/helloada/helloada.adb b/tests/helloada/helloada.adb index 4638dd7..84f03e3 100644 --- a/tests/helloada/helloada.adb +++ b/tests/helloada/helloada.adb @@ -2,6 +2,7 @@ with Text_IO; use Text_IO; with System; with System.Address_Image; with System.Address_To_Access_Conversions; +with Increment_By; procedure HelloAda is @@ -23,6 +24,9 @@ procedure HelloAda is My_Float_Array_Access : Float_Array_Access_T; My_Float_Array_Obj_Ptr : Conversions.Object_Pointer; + -- some increment variables. + A, B, C : Integer; + begin -- Fill My_Float_Array with data for i in 0 .. 64 loop @@ -36,5 +40,39 @@ begin Put_Line(System.Address_Image(My_Float_Array_Address)); Put_Line(Float'Image(My_Float_Array(3))); + + C := Increment_By; + -- ^ Parameterless call, + -- value of I is 0 + -- and Incr is 1 + + Put_Line ("Using defaults for Increment_By is " + & Integer'Image (C)); + + A := 10; + B := 3; + C := Increment_By (A, B); + -- ^ Regular parameter passing + + Put_Line ("Increment of " + & Integer'Image (A) + & " with " + & Integer'Image (B) + & " is " + & Integer'Image (C)); + + A := 20; + B := 5; + C := Increment_By (I => A, + Incr => B); + -- ^ Named parameter passing + + Put_Line ("Increment of " + & Integer'Image (A) + & " with " + & Integer'Image (B) + & " is " + & Integer'Image (C)); + end HelloAda; diff --git a/tests/helloada/increment_by.adb b/tests/helloada/increment_by.adb new file mode 100644 index 0000000..f29d1b4 --- /dev/null +++ b/tests/helloada/increment_by.adb @@ -0,0 +1,6 @@ +function Increment_By + (I : Integer := 0; + Incr : Integer := 1) return Integer is +begin + return I + Incr; +end Increment_By; diff --git a/tests/helloada/increment_by.ads b/tests/helloada/increment_by.ads new file mode 100644 index 0000000..1f409b6 --- /dev/null +++ b/tests/helloada/increment_by.ads @@ -0,0 +1,4 @@ +function Increment_By + (I : Integer := 0; + Incr : Integer := 1) return Integer; +-- ^ Default value for parameters