]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
a68: Add exit function to POSIX prelude
authorPietro Monteiro <pietro@sociotechnical.xyz>
Sat, 10 Jan 2026 01:52:13 +0000 (20:52 -0500)
committerPietro Monteiro <pietro@sociotechnical.xyz>
Sat, 10 Jan 2026 05:26:49 +0000 (00:26 -0500)
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 <pietro@sociotechnical.xyz>
gcc/algol68/a68-low-posix.cc
gcc/algol68/a68-low-prelude.cc
gcc/algol68/a68-low-runtime.def
gcc/algol68/a68-parser-prelude.cc
gcc/algol68/a68.h
gcc/algol68/ga68.texi
gcc/testsuite/algol68/execute/posix-exit-1.a68 [new file with mode: 0644]
libga68/ga68-posix.c
libga68/ga68.h
libga68/ga68.map
libga68/libga68.c

index 6b6ae76cf375fb4acb10f71450fe0e59192c3808..1a9d5eb1b6315014c711da48ad00d5c4aa384262 100644 (file)
 
 #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)
 {
index bd54b207fbe27ae45535a88a33c1b027d21acf65..170da5a5c3cd329b54225a157c29e7b0df85dd99 100644 (file)
@@ -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)
index 04cca03ca51b35b6949e1e7ad04b8b60685ec1af..ecb8553238d1e43e4907ac700428e7a36569f2f6 100644 (file)
@@ -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)
index cb899873f35744ac086787c39dfda5d3d217ca7c..87d08773450519d3990bdb214cde4d2d6aa93df8 100644 (file)
@@ -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);
index dc73277038c988117de6f29cd21fd17feaab199a..7c6d51bd0646c9d0798a7065727b6bc9ce08fa7b 100644 (file)
@@ -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);
index 83fcf92e71e9ab83d5b42348df03d61512fdf578..9811a291be2caf5dac1cefbdbc0a12790788762a 100644 (file)
@@ -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 (file)
index 0000000..f62f613
--- /dev/null
@@ -0,0 +1,3 @@
+begin posix_exit (0);
+      assert (false) { if this assert triggers then posix_exit is broken }
+end
index 47038d6e39fd7e42bbbe4b024bf47d2eccbae77b..a671dd61d16c463a32017a91ad3f5c40d5d64819 100644 (file)
@@ -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);
+}
index 18f3a56311265eaf8d0304d8ef09d55196557de7..008ce05282a44cb187f364ca147f76c261e6acd1 100644 (file)
@@ -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 */
index f956655de031a05ae0683cc790832bfb110769d4..6917e7905aecfa93ceb91792fba12ef0be0d190b 100644 (file)
@@ -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;
index 60f930a53334f90e3f71487fcb4a1be345beef50..d9496933a0f156832ebf96a63569463b28c73a7e 100644 (file)
    <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;
 }