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>
#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
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)
{
/********* 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)
{
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)
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)
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)
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);
/* a68-low-posix.cc */
-tree a68_posix_setexitstatus (void);
tree a68_posix_argc (void);
tree a68_posix_argv (void);
tree a68_posix_getenv (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);
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);
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);
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
@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
--- /dev/null
+begin posix_exit (0);
+ assert (false) { if this assert triggers then posix_exit is broken }
+end
_libga68_errno = errno;
return ret;
}
+
+/* Implementation of the posix prelude `exit'. */
+
+void
+_libga68_posixexit (int status)
+{
+ exit (status);
+}
/* 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);
extern int _libga68_argc;
extern char **_libga68_argv;
-void _libga68_set_exit_status (int status);
-
#endif /* ! GA68_H */
_libga68_posixclose;
_libga68_posixcreat;
_libga68_posixerrno;
+ _libga68_posixexit;
_libga68_posixfconnect;
_libga68_posixfgetc;
_libga68_posixfgets;
_libga68_posixputs;
_libga68_posixstrerror;
_libga68_random;
- _libga68_set_exit_status;
_libga68_u32_cmp2;
_libga68_unreachable;
_libga68_upper_bound;
<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);
_libga68_init_heap ();
__algol68_main ();
- return exit_status;
+ return EXIT_SUCCESS;
}