mirror of
https://gcc.gnu.org/git/gcc.git
synced 2026-02-21 19:35:28 -05:00
This big commit: * Adds support to the FFI mechanism to map Algol 68 procedures returning strings to an equivalent C interface. * Adds a new command-line option -fbuilding-libga68. * Adds support for having modules in libga68 implicitly invoked in user-written programs and modules. * Using the infrastructure agove, removes the compiler-generated glue to call the standard POSIX prelude shipped in libga68 to, instead, use the formal holes mechanism for FFI. * Adds posix.a68 to libga68. * Adds standard.a68 to libga68. Signed-off-by: Jose E. Marchesi <jemarch@gnu.org> gcc/algol68/ChangeLog * a68-moids-misc.cc (a68_is_c_mode): Allow C formal holes for routines yielding strings. * a68-low-holes.cc (a68_wrap_formal_proc_hole): Support wrappers that yield strings. * a68.h: Remove a68_posix_* and a68_lower_posix* prototypes. * a68-low-posix.cc: Remove. * a68-imports.cc (a68_open_packet): Get argument filename. * Make-lang.in (ALGOL68_OBJS): Remove algol68/a68-low-posix.o. * a68-low-runtime.def: Remove POSIX_*. * lang.opt (-fcheck): Add new undocumented option -fbuilding-libga68. * a68-parser-prelude.cc (stand_transput): New function. (posix_prelude): Remove hardcoded additions to the top-level environment and use a68_extract_revelations instead. * a68-parser-extract.cc (a68_extract_revelation): Renamed from extract_revelation and made accessible externally. * a68-low.cc (a68_make_formal_hole_decl): Remove unneeded check. (lower_lude_decl): New function. (lower_module_text): Add calls to preludes and postludes of standard modules if not building libga68. (a68_lower_particular_program): Likewise. * a68-low-prelude.cc (a68_lower_posixargc): Remove. (a68_lower_posixargv): Likewise. (a68_lower_posixgetenv): Likewise. (a68_lower_posixputchar): Likewise. (a68_lower_posixputs): Likewise. (a68_lower_posixfconnect): Likewise. (a68_lower_posixfopen): Likewise. (a68_lower_posixfcreate): Likewise. (a68_lower_posixfclose): Likewise. (a68_lower_posixfsize): Likewise. (a68_lower_posixlseek): Likewise. (a68_lower_posixseekcur): Likewise. (a68_lower_posixseekend): Likewise. (a68_lower_posixseekset): Likewise. (a68_lower_posixstdinfiledes): Likewise. (a68_lower_posixstdoutfiledes): Likewise. (a68_lower_posixstderrfiledes): Likewise. (a68_lower_posixfileodefault): Likewise. (a68_lower_posixfileordwr): Likewise. (a68_lower_posixfileordonly): Likewise. (a68_lower_posixfileowronly): Likewise. (a68_lower_posixfileotrunc): Likewise. (a68_lower_posixerrno): Likewise. (a68_lower_posixexit): Likewise. (a68_lower_posixperror): Likewise. (a68_lower_posixstrerror): Likewise. (a68_lower_posixfputc): Likewise. (a68_lower_posixfputs): Likewise. (a68_lower_posixgetchar): Likewise. (a68_lower_posixfgetc): Likewise. (a68_lower_posixgets): Likewise. (a68_lower_posixfgets): Likewise. gcc/testsuite/ChangeLog * lib/algol68.exp (algol68_init): Add -I options to ALGOL68_UNDER_TEST so exports in libga68.{a,so} are found. * algol68/compile/warning-hidding-6.a68: Likewise. * algol68/compile/warning-hidding-5.a68: Use maxint instead of getchar to trigger the warning. * algol68/compile/error-nest-4.a68: Procedures yielding strings are now on in C formal holes. libga68/ChangeLog * posix.a68: New file. * standard.a68.in: Likewise. * ga68-posix.c (_libga68_stdin): Define. (_libga68_stdout): Likewise. (_libga68_stderr): Likewise. (_libga68_file_o_default): Likewise. (_libga68_file_o_rdonly): Likewise. (_libga68_file_o_rdwr): Likewise. (_libga68_file_o_trunc): Likewise. (_libga68_seek_cur): Likewise. (_libga68_seek_end): Likewise. (_libga68_seek_set): Likewise. (_libga68_posixstrerror): Update interface to new way of returning Algol 68 strings. (_libga68_posixargv): Likewise. (_libga68_posixfgets): Likewise. (_libga68_posixgets): Likewise. (_libga68_posixfopen): Use _libga68_file_o_default rather than FILE_O_DEFAULT. (_libga68_posixfopen): Ditto for other FILE_O_* values. * ga68.h: Update prototypes. * Makefile.am (libga68_la_LIBADD): Add standard.lo. (libga68_la_DEPENDENCIES): Likeise. (.a68.o): Pass -fbuilding-libga68. (.a68.lo): Likewise. (standard.a68): New rule. * Makefile.in: Regenerate. * transput.a68.in: Add Emacs -*- mode: a68 -*- comment.
132 lines
5.0 KiB
C
132 lines
5.0 KiB
C
/* Definitions for libga68.
|
|
Copyright (C) 2025 Jose E. Marchesi.
|
|
|
|
GCC is free software; you can redistribute it and/or modify it under the
|
|
terms of the GNU General Public License as published by the Free Software
|
|
Foundation; either version 3, or (at your option) any later version.
|
|
|
|
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
details.
|
|
|
|
Under Section 7 of GPL version 3, you are granted additional permissions
|
|
described in the GCC Runtime Library Exception, version 3.1, as published by
|
|
the Free Software Foundation.
|
|
|
|
You should have received a copy of the GNU General Public License and a copy
|
|
of the GCC Runtime Library Exception along with this program; see the files
|
|
COPYING3 and COPYING.RUNTIME respectively. If not, see
|
|
<http://www.gnu.org/licenses/>. */
|
|
|
|
#ifndef GA68_H
|
|
#define GA68_H
|
|
|
|
#include "config.h"
|
|
|
|
#include <stddef.h> /* For size_t. */
|
|
#include <stdint.h>
|
|
#include <stdarg.h>
|
|
#ifdef __has_include
|
|
# if __has_include (<sys/types.h>)
|
|
# include <sys/types.h> /* For ssize_t. */
|
|
# endif
|
|
#endif
|
|
|
|
#ifdef HAVE_ATTRIBUTE_VISIBILITY
|
|
# define GA68_HIDDEN __attribute__ ((__visibility__ ("hidden")))
|
|
#else
|
|
# define GA68_HIDDEN
|
|
#endif
|
|
|
|
/* ga68-error.c */
|
|
|
|
void _libga68_abort (const char *fmt, ...)
|
|
GA68_HIDDEN
|
|
__attribute__ ((__format__ (__printf__, 1, 2), __nonnull__ (1),
|
|
__noreturn__));
|
|
|
|
void _libga68_assert (const char *filename, unsigned int lineno);
|
|
void _libga68_derefnil (const char *filename, unsigned int lineno);
|
|
void _libga68_invalidcharerror (const char *filename, unsigned int lineno,
|
|
int c);
|
|
|
|
void _libga68_bitsboundserror (const char *filename, unsigned int lineno,
|
|
ssize_t pos);
|
|
void _libga68_unreachable (const char *filename, unsigned int lineno);
|
|
void _libga68_lower_bound (const char *filename, unsigned int lineno,
|
|
ssize_t index, ssize_t lower_bound);
|
|
void _libga68_upper_bound (const char *filename, unsigned int lineno,
|
|
ssize_t index, ssize_t upper_bound);
|
|
void _libga68_bounds (const char *filename, unsigned int lineno,
|
|
ssize_t index, ssize_t lower_bound, ssize_t upper_bound);
|
|
void _libga68_dim (const char *filename, unsigned int lineno,
|
|
size_t dim, size_t index);
|
|
void _libga68_bounds_mismatch (const char *filename, unsigned int lineno,
|
|
size_t dim, ssize_t lb1, ssize_t ub1,
|
|
ssize_t lb2, ssize_t ub2);
|
|
|
|
/* ga68-alloc.c */
|
|
|
|
void _libga68_init_heap (void) GA68_HIDDEN;
|
|
void *_libga68_malloc (size_t size);
|
|
void *_libga68_malloc_leaf (size_t size);
|
|
void *_libga68_malloc_internal (size_t size) GA68_HIDDEN;
|
|
void *_libga68_realloc (void *ptr, size_t size) GA68_HIDDEN;
|
|
void *_libga68_realloc_internal (void *ptr, size_t size) GA68_HIDDEN;
|
|
void *_libga68_realloc_unchecked (void *ptr, size_t size) GA68_HIDDEN;
|
|
void _libga68_free_internal (void *ptr) GA68_HIDDEN;
|
|
|
|
/* ga68-standenv.c */
|
|
|
|
float _libga68_random (void);
|
|
double _libga68_longrandom (void);
|
|
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);
|
|
void _libga68_posixstrerror (int errnum, uint32_t **r, size_t *rlen);
|
|
long long int _libga68_posixfsize (int fd);
|
|
int _libga68_posixfopen (const uint32_t *pathname, size_t len, size_t stride,
|
|
unsigned int flags);
|
|
int _libga68_posixcreat (uint32_t *pathname, size_t len, size_t stride, uint32_t mode);
|
|
int _libga68_posixclose (int fd);
|
|
int _libga68_posixargc (void);
|
|
void _libga68_posixargv (int n, uint32_t **r, size_t *rlen);
|
|
void _libga68_posixgetenv (uint32_t *s, size_t len, size_t stride,
|
|
uint32_t **r, size_t *rlen);
|
|
void _libga68_posixputs (uint32_t *s, size_t len, size_t stride);
|
|
uint32_t _libga68_posixputchar (uint32_t c);
|
|
uint32_t _libga68_posixfputc (int fd, uint32_t c);
|
|
int _libga68_posixfputs (int fd, uint32_t *s, size_t len, size_t stride);
|
|
|
|
uint32_t _libga68_posixgetchar (void);
|
|
uint32_t _libga68_posixfgetc (int fd);
|
|
void _libga68_posixfgets (int fd, int nchars, uint32_t **r, size_t *rlen);
|
|
void _libga68_posixgets (int nchars, uint32_t **r, size_t *rlen);
|
|
|
|
int _libga68_posixfconnect (uint32_t *str, size_t len, size_t stride,
|
|
int port);
|
|
long long int _libga68_posixlseek (int fd, long long int offset, int whence);
|
|
|
|
/* ga68-unistr.c */
|
|
|
|
int _libga68_u32_cmp2 (const uint32_t *s1, size_t n1, size_t stride1,
|
|
const uint32_t *s2, size_t n2, size_t stride2);
|
|
int _libga68_u8_uctomb (uint8_t *s, uint32_t uc, ptrdiff_t n) GA68_HIDDEN;
|
|
int _libga68_u8_mbtouc (uint32_t *puc, const uint8_t *s, size_t n) GA68_HIDDEN;
|
|
char *_libga68_u32_to_u8 (const uint32_t *s, size_t n, size_t stride,
|
|
size_t *lengthp) GA68_HIDDEN;
|
|
uint32_t *_libga68_u8_to_u32 (const uint8_t *s, size_t n,
|
|
uint32_t *resultbuf, size_t *lengthp);
|
|
|
|
/* libga68.c */
|
|
|
|
extern int _libga68_argc;
|
|
extern char **_libga68_argv;
|
|
|
|
#endif /* ! GA68_H */
|