https://gcc.gnu.org/g:f2cdddef40c6a094f47ea349a7806be0af55b491

commit r16-6674-gf2cdddef40c6a094f47ea349a7806be0af55b491
Author: Pietro Monteiro <[email protected]>
Date:   Fri Jan 9 20:52:13 2026 -0500

    a68: Add exit function to POSIX prelude
    
    Add the procedure `posixexit'.
    
    gcc/algol68/ChangeLog:
    
            * a68-low-posix.cc (a68_posix_setexitstatus): Delete function.
            (a68_posix_exit): New function.
            * a68-low-prelude.cc (a68_lower_setexitstatus): Delete function.
            (a68_lower_posixexit): New function.
            * a68-low-runtime.def (SET_EXIT_STATUS): Delete definition.
            (POSIX_EXIT): Add definition for posixexit.
            * a68-parser-prelude.cc (posix_prelude): Remove setexitstatus
            identifier from and add posixexit identifier to standenv.
            * a68.h (a68_posix_setexitstatus): Delete prototype.
            (a68_lower_setexitstatus): Likewise.
            (a68_posix_exit): New prototype.
            (a68_lower_posixexit): Likewise.
            * ga68.texi:
    
    libga68/ChangeLog:
    
            * ga68-posix.c (_libga68_posixexit): New function.
            * ga68.h (_libga68_posixexit): New prototype.
            (_libga68_set_exit_status): Delete prototype.
            * ga68.map: Remove _libga68_set_exit_status from and add
            _libga68_posixexit to the global map.
            * libga68.c: include <stdlib.h>.
            (_libga68_set_exit_status): Delete function.
            (main): Return EXIT_SUCCESS.
    
    gcc/testsuite/ChangeLog:
    
            * algol68/execute/posix-exit-1.a68: New test.
    
    Signed-off-by: Pietro Monteiro <[email protected]>

Diff:
---
 gcc/algol68/a68-low-posix.cc                   | 15 ++++++---------
 gcc/algol68/a68-low-prelude.cc                 | 19 ++++++++++---------
 gcc/algol68/a68-low-runtime.def                |  2 +-
 gcc/algol68/a68-parser-prelude.cc              |  2 +-
 gcc/algol68/a68.h                              |  4 ++--
 gcc/algol68/ga68.texi                          | 24 +++++++++++-------------
 gcc/testsuite/algol68/execute/posix-exit-1.a68 |  3 +++
 libga68/ga68-posix.c                           |  8 ++++++++
 libga68/ga68.h                                 |  3 +--
 libga68/ga68.map                               |  2 +-
 libga68/libga68.c                              | 13 ++-----------
 11 files changed, 46 insertions(+), 49 deletions(-)

diff --git a/gcc/algol68/a68-low-posix.cc b/gcc/algol68/a68-low-posix.cc
index 6b6ae76cf375..1a9d5eb1b631 100644
--- a/gcc/algol68/a68-low-posix.cc
+++ b/gcc/algol68/a68-low-posix.cc
@@ -42,15 +42,6 @@
 
 #include "a68.h"
 
-/* Set the exit status of the running process, to be returned to the OS upon
-   exit.  */
-
-tree
-a68_posix_setexitstatus (void)
-{
-  return a68_get_libcall (A68_LIBCALL_SET_EXIT_STATUS);
-}
-
 /* Number of command line arguments passed to the program.  */
 
 tree
@@ -341,6 +332,12 @@ a68_posix_errno (void)
   return a68_get_libcall (A68_LIBCALL_POSIX_ERRNO);
 }
 
+tree
+a68_posix_exit (void)
+{
+  return a68_get_libcall (A68_LIBCALL_POSIX_EXIT);
+}
+
 tree
 a68_posix_perror (void)
 {
diff --git a/gcc/algol68/a68-low-prelude.cc b/gcc/algol68/a68-low-prelude.cc
index bd54b207fbe2..170da5a5c3cd 100644
--- a/gcc/algol68/a68-low-prelude.cc
+++ b/gcc/algol68/a68-low-prelude.cc
@@ -1902,15 +1902,6 @@ a68_lower_longlongrandom (NODE_T *p ATTRIBUTE_UNUSED, 
LOW_CTX_T ctx ATTRIBUTE_UN
 
 /********* POSIX prelude.  ***************/
 
-tree
-a68_lower_setexitstatus (NODE_T *p, LOW_CTX_T ctx ATTRIBUTE_UNUSED)
-{
-  tree t = a68_posix_setexitstatus ();
-  if (CAN_HAVE_LOCATION_P (t))
-    SET_EXPR_LOCATION (t, a68_get_node_location (p));
-  return t;
-}
-
 tree
 a68_lower_posixargc (NODE_T *p ATTRIBUTE_UNUSED, LOW_CTX_T ctx 
ATTRIBUTE_UNUSED)
 {
@@ -2112,6 +2103,16 @@ a68_lower_posixerrno (NODE_T *p ATTRIBUTE_UNUSED,
   return t;
 }
 
+tree
+a68_lower_posixexit (NODE_T *p ATTRIBUTE_UNUSED,
+                    LOW_CTX_T ctx ATTRIBUTE_UNUSED)
+{
+  tree t = a68_posix_exit ();
+  if (CAN_HAVE_LOCATION_P (t))
+    SET_EXPR_LOCATION (t, a68_get_node_location (p));
+  return t;
+}
+
 tree
 a68_lower_posixperror (NODE_T *p ATTRIBUTE_UNUSED,
                       LOW_CTX_T ctx ATTRIBUTE_UNUSED)
diff --git a/gcc/algol68/a68-low-runtime.def b/gcc/algol68/a68-low-runtime.def
index 04cca03ca51b..ecb8553238d1 100644
--- a/gcc/algol68/a68-low-runtime.def
+++ b/gcc/algol68/a68-low-runtime.def
@@ -42,7 +42,6 @@ along with GCC; see the file COPYING3.  If not see
    Used for declaring functions that are called by generated code.  */
 
 DEF_A68_RUNTIME (ASSERT, "_libga68_assert", RT(VOID), P2(CONSTCHARPTR, UINT), 
ECF_NORETURN)
-DEF_A68_RUNTIME (SET_EXIT_STATUS, "_libga68_set_exit_status", RT(VOID), 
P1(INT), 0)
 DEF_A68_RUNTIME (MALLOC, "_libga68_malloc", RT(VOIDPTR), P1(SIZE), ECF_NOTHROW 
| ECF_LEAF | ECF_MALLOC)
 DEF_A68_RUNTIME (DEREFNIL, "_libga68_derefnil", RT(VOID), P2(CONSTCHARPTR, 
UINT), ECF_NORETURN)
 DEF_A68_RUNTIME (UNREACHABLE, "_libga68_unreachable", RT(VOID), 
P2(CONSTCHARPTR, UINT), ECF_NORETURN)
@@ -78,6 +77,7 @@ DEF_A68_RUNTIME (POSIX_GETS, "_libga68_posixgets", 
RT(UNISTRPTR), P2(INT,SIZEPTR
 DEF_A68_RUNTIME (POSIX_FGETS, "_libga68_posixfgets", RT(UNISTRPTR), 
P3(INT,INT,SIZEPTR), 0)
 DEF_A68_RUNTIME (POSIX_GETENV, "_libga68_posixgetenv", RT(VOID), 
P5(UNISTR,SIZE,SIZE,UNISTRPTR,SIZEPTR), 0)
 DEF_A68_RUNTIME (POSIX_ERRNO, "_libga68_posixerrno", RT(INT), P0(), 0)
+DEF_A68_RUNTIME (POSIX_EXIT, "_libga68_posixexit", RT(VOID), P1(INT), 0)
 DEF_A68_RUNTIME (POSIX_PERROR, "_libga68_posixperror", RT(VOID), 
P3(UNISTR,SIZE,SIZE), 0)
 DEF_A68_RUNTIME (POSIX_STRERROR, "_libga68_posixstrerror", RT(UNISTRPTR), 
P2(INT, SIZEPTR), 0)
 DEF_A68_RUNTIME (POSIX_LSEEK, "_libga68_posixlseek", RT(LONGLONGINT), 
P3(INT,LONGLONGINT,INT), 0)
diff --git a/gcc/algol68/a68-parser-prelude.cc 
b/gcc/algol68/a68-parser-prelude.cc
index cb899873f357..87d087734505 100644
--- a/gcc/algol68/a68-parser-prelude.cc
+++ b/gcc/algol68/a68-parser-prelude.cc
@@ -1378,7 +1378,7 @@ posix_prelude (void)
   a68_idf (A68_EXT, "getenv", m, a68_lower_posixgetenv);
   /* Exit status handling.  */
   m = a68_proc (M_VOID, M_INT, NO_MOID);
-  a68_idf (A68_EXT, "setexitstatus", m, a68_lower_setexitstatus);
+  a68_idf (A68_EXT, "posixexit", m, a68_lower_posixexit);
   /* Argument handling.  */
   m = A68_MCACHE (proc_int);
   a68_idf (A68_EXT, "argc", m, a68_lower_posixargc);
diff --git a/gcc/algol68/a68.h b/gcc/algol68/a68.h
index dc73277038c9..7c6d51bd0646 100644
--- a/gcc/algol68/a68.h
+++ b/gcc/algol68/a68.h
@@ -578,7 +578,6 @@ tree a68_complex_widen_from_real (MOID_T *mode, tree r);
 
 /* a68-low-posix.cc  */
 
-tree a68_posix_setexitstatus (void);
 tree a68_posix_argc (void);
 tree a68_posix_argv (void);
 tree a68_posix_getenv (void);
@@ -591,6 +590,7 @@ tree a68_posix_fclose (void);
 tree a68_posix_fsize (void);
 tree a68_posix_lseek (void);
 tree a68_posix_errno (void);
+tree a68_posix_exit (void);
 tree a68_posix_perror (void);
 tree a68_posix_strerror (void);
 tree a68_posix_getchar (void);
@@ -1067,7 +1067,6 @@ tree a68_lower_shortenreal2 (NODE_T *p, LOW_CTX_T ctx);
 tree a68_lower_random (NODE_T *p, LOW_CTX_T ctx);
 tree a68_lower_longrandom (NODE_T *p, LOW_CTX_T ctx);
 tree a68_lower_longlongrandom (NODE_T *p, LOW_CTX_T ctx);
-tree a68_lower_setexitstatus (NODE_T *p, LOW_CTX_T ctx);
 tree a68_lower_posixargc (NODE_T *p, LOW_CTX_T ctx);
 tree a68_lower_posixargv (NODE_T *p, LOW_CTX_T ctx);
 tree a68_lower_posixputchar (NODE_T *p, LOW_CTX_T ctx);
@@ -1093,6 +1092,7 @@ tree a68_lower_posixfileordonly (NODE_T *p, LOW_CTX_T 
ctx);
 tree a68_lower_posixfileowronly (NODE_T *p, LOW_CTX_T ctx);
 tree a68_lower_posixfileotrunc (NODE_T *p, LOW_CTX_T ctx);
 tree a68_lower_posixerrno (NODE_T *p, LOW_CTX_T ctx);
+tree a68_lower_posixexit (NODE_T *p, LOW_CTX_T ctx);
 tree a68_lower_posixperror (NODE_T *p, LOW_CTX_T ctx);
 tree a68_lower_posixstrerror (NODE_T *p, LOW_CTX_T ctx);
 tree a68_lower_posixgetchar (NODE_T *p, LOW_CTX_T ctx);
diff --git a/gcc/algol68/ga68.texi b/gcc/algol68/ga68.texi
index 83fcf92e71e9..9811a291be2c 100644
--- a/gcc/algol68/ga68.texi
+++ b/gcc/algol68/ga68.texi
@@ -1032,19 +1032,19 @@ Some operating systems have the notion of @dfn{exit 
status} of a
 process.  In such systems, by default the execution of the particular
 program results in an exit status of success.  It is possible for the
 program to specify an explicit exit status by using the standard
-procedure @code{set exit status}, like:
+procedure @code{posix exit}, like:
 
 @example
 @b{begin} # ... program code ... #
      @B{if} error found;
-     @B{then} set exit status (1) @B{fi}
+     @B{then} posix exit (1) @B{fi}
 @b{end}
 @end example
 
 In POSIX systems the status is an integer, and the system interprets a
 value other than zero as a run-time error.  In other systems the
-status may be of some other type.  To support this, the @code{set
-error status} procedure accepts as an argument an united value that
+status may be of some other type.  To support this, the @code{posix
+exit} procedure accepts as an argument an united value that
 accommodates all the supported systems.
 
 The following example shows a very simple program that prints ``Hello
@@ -2894,17 +2894,15 @@ which is the default.
 @node POSIX process
 @section POSIX process
 
-The Algol 68 program can report an exit status to the operating system
-once they stop running.  The exit status reported by default is zero,
-which corresponds to success.
+The Algol 68 program reports an exit status to the operating system once
+it stops running.  The exit status reported by default is zero, which
+corresponds to success.
 
-@deftypefn Procedure {} {set exit status} {= (@B{int} status)}
+@deftypefn Procedure {} {posix exit} {= (@B{int} status)}
 Procedure that sets the exit status to report to the operating system
-once the program stop executing.  The default exit status is 0 which,
-by convention, is interpreted by POSIX systems as success.  A value
-different to zero is interpreted as an error status.  This procedure
-can be invoked more than one, the previous exit status being
-overwritten.
+and immediately stops executing the program.  The default exit status is
+0 which, by convention, is interpreted by POSIX systems as success.  A
+value different to zero is interpreted as an error status.
 @end deftypefn
 
 @node POSIX command line
diff --git a/gcc/testsuite/algol68/execute/posix-exit-1.a68 
b/gcc/testsuite/algol68/execute/posix-exit-1.a68
new file mode 100644
index 000000000000..f62f61332ca8
--- /dev/null
+++ b/gcc/testsuite/algol68/execute/posix-exit-1.a68
@@ -0,0 +1,3 @@
+begin posix_exit (0);
+      assert (false) { if this assert triggers then posix_exit is broken }
+end
diff --git a/libga68/ga68-posix.c b/libga68/ga68-posix.c
index 47038d6e39fd..a671dd61d16c 100644
--- a/libga68/ga68-posix.c
+++ b/libga68/ga68-posix.c
@@ -461,3 +461,11 @@ _libga68_posixlseek (int fd, long long int offset, int 
whence)
   _libga68_errno = errno;
   return ret;
 }
+
+/* Implementation of the posix prelude `exit'.  */
+
+void
+_libga68_posixexit (int status)
+{
+  exit (status);
+}
diff --git a/libga68/ga68.h b/libga68/ga68.h
index 18f3a5631126..008ce05282a4 100644
--- a/libga68/ga68.h
+++ b/libga68/ga68.h
@@ -84,6 +84,7 @@ long double _libga68_longlongrandom (void);
 /* ga68-posix.c  */
 
 int _libga68_posixerrno (void);
+void _libga68_posixexit (int) __attribute__ ((__noreturn__));
 void _libga68_posixperror (uint32_t *s, size_t len, size_t stride);
 uint32_t *_libga68_posixstrerror (int errnum, size_t *len);
 long long int _libga68_posixfsize (int fd);
@@ -125,6 +126,4 @@ uint32_t *_libga68_u8_to_u32 (const uint8_t *s, size_t n,
 extern int _libga68_argc;
 extern char **_libga68_argv;
 
-void _libga68_set_exit_status (int status);
-
 #endif /* ! GA68_H */
diff --git a/libga68/ga68.map b/libga68/ga68.map
index f956655de031..6917e7905aec 100644
--- a/libga68/ga68.map
+++ b/libga68/ga68.map
@@ -16,6 +16,7 @@ LIBGA68_2.0 {
     _libga68_posixclose;
     _libga68_posixcreat;
     _libga68_posixerrno;
+    _libga68_posixexit;
     _libga68_posixfconnect;
     _libga68_posixfgetc;
     _libga68_posixfgets;
@@ -32,7 +33,6 @@ LIBGA68_2.0 {
     _libga68_posixputs;
     _libga68_posixstrerror;
     _libga68_random;
-    _libga68_set_exit_status;
     _libga68_u32_cmp2;
     _libga68_unreachable;
     _libga68_upper_bound;
diff --git a/libga68/libga68.c b/libga68/libga68.c
index 60f930a53334..d9496933a0f1 100644
--- a/libga68/libga68.c
+++ b/libga68/libga68.c
@@ -20,22 +20,13 @@
    <http://www.gnu.org/licenses/>.  */
 
 #include "ga68.h"
+#include <stdlib.h> /* for EXIT_SUCCESS */
 
 /* argc and argv are preserved in the following objects.  */
 
 int _libga68_argc;
 char **_libga68_argv;
 
-/* Exit status of the program reported to the OS upon exit.  */
-
-static int exit_status;
-
-void
-_libga68_set_exit_status (int status)
-{
-  exit_status = status;
-}
-
 /* Entry point for Algol 68 programs.  */
 
 void __algol68_main (void);
@@ -48,5 +39,5 @@ main (int argc, char **argv)
 
   _libga68_init_heap ();
   __algol68_main ();
-  return exit_status;
+  return EXIT_SUCCESS;
 }

Reply via email to