[COMMITTED] algol68: add function fsize to the posix prelude

Jose E. Marchesi jemarch@gnu.org
Thu Apr 24 19:39:34 GMT 2025


---
 gcc/algol68/a68-low-posix.cc              |  6 ++++++
 gcc/algol68/a68-low-prelude.cc            | 10 ++++++++++
 gcc/algol68/a68-low-runtime.cc            |  3 +++
 gcc/algol68/a68-low-runtime.def           |  1 +
 gcc/algol68/a68-parser-prelude.cc         |  3 +++
 gcc/algol68/a68.h                         |  2 ++
 gcc/algol68/ga68.texi                     | 11 +++++++++++
 gcc/testsuite/algol68/execute/fsize-1.a68 |  2 ++
 8 files changed, 38 insertions(+)
 create mode 100644 gcc/testsuite/algol68/execute/fsize-1.a68

diff --git a/gcc/algol68/a68-low-posix.cc b/gcc/algol68/a68-low-posix.cc
index c8b7bbf7232..c2c92fa27e3 100644
--- a/gcc/algol68/a68-low-posix.cc
+++ b/gcc/algol68/a68-low-posix.cc
@@ -323,6 +323,12 @@ a68_posix_fclose (void)
   return a68_get_libcall (A68_LIBCALL_POSIX_FCLOSE);
 }
 
+tree
+a68_posix_fsize (void)
+{
+  return a68_get_libcall (A68_LIBCALL_POSIX_FSIZE);
+}
+
 tree
 a68_posix_errno (void)
 {
diff --git a/gcc/algol68/a68-low-prelude.cc b/gcc/algol68/a68-low-prelude.cc
index 2d6b3fc9dfb..a8d989319ab 100644
--- a/gcc/algol68/a68-low-prelude.cc
+++ b/gcc/algol68/a68-low-prelude.cc
@@ -1989,6 +1989,16 @@ a68_lower_posixfclose (NODE_T *p ATTRIBUTE_UNUSED,
   return t;
 }
 
+tree
+a68_lower_posixfsize (NODE_T *p ATTRIBUTE_UNUSED,
+		      LOW_CTX_T ctx ATTRIBUTE_UNUSED)
+{
+  tree t = a68_posix_fsize ();
+  if (CAN_HAVE_LOCATION_P (t))
+    SET_EXPR_LOCATION (t, a68_get_node_location (p));
+  return t;
+}
+
 tree
 a68_lower_posixstdinfiledes (NODE_T *p ATTRIBUTE_UNUSED,
 			     LOW_CTX_T ctx ATTRIBUTE_UNUSED)
diff --git a/gcc/algol68/a68-low-runtime.cc b/gcc/algol68/a68-low-runtime.cc
index 9e4eb73dfc1..4ea93e991e1 100644
--- a/gcc/algol68/a68-low-runtime.cc
+++ b/gcc/algol68/a68-low-runtime.cc
@@ -61,6 +61,7 @@ enum a68_libcall_type
   LCT_SIZEPTR,
   LCT_UINT,
   LCT_INT,
+  LCT_LONGLONGINT,
   LCT_FLOAT,
   LCT_DOUBLE,
   LCT_LONGDOUBLE,
@@ -106,6 +107,8 @@ get_libcall_type (a68_libcall_type type)
     libcall_types[type] = unsigned_type_node;
   else if (type == LCT_INT)
     libcall_types[type] = integer_type_node;
+  else if (type == LCT_LONGLONGINT)
+    libcall_types[type] = long_long_integer_type_node;
   else if (type == LCT_FLOAT)
     libcall_types[type] = float_type_node;
   else if (type == LCT_DOUBLE)
diff --git a/gcc/algol68/a68-low-runtime.def b/gcc/algol68/a68-low-runtime.def
index 7fde40ce3aa..d4abb429d2a 100644
--- a/gcc/algol68/a68-low-runtime.def
+++ b/gcc/algol68/a68-low-runtime.def
@@ -65,6 +65,7 @@ DEF_A68_RUNTIME (POSIX_FCONNECT, "_libga68_posixfconnect", RT(INT), P4(UNISTRPTR
 DEF_A68_RUNTIME (POSIX_FOPEN, "_libga68_posixfopen", RT(INT), P4(UNISTRPTR,SIZE,SIZE,UINT), 0)
 DEF_A68_RUNTIME (POSIX_FCREATE, "_libga68_posixcreat", RT(INT), P4(UNISTRPTR,SIZE,SIZE,UINT), 0)
 DEF_A68_RUNTIME (POSIX_FCLOSE, "_libga68_posixclose", RT(INT), P0(), 0)
+DEF_A68_RUNTIME (POSIX_FSIZE, "_libga68_posixfsize", RT(LONGLONGINT), P1(INT), 0)
 DEF_A68_RUNTIME (POSIX_ARGC, "_libga68_posixargc", RT(INT), P0(), 0)
 DEF_A68_RUNTIME (POSIX_ARGV, "_libga68_posixargv", RT(UNISTRPTR), P2(INT, SIZEPTR), 0)
 DEF_A68_RUNTIME (POSIX_PUTCHAR, "_libga68_posixputchar", RT(CHAR), P1(CHAR), 0)
diff --git a/gcc/algol68/a68-parser-prelude.cc b/gcc/algol68/a68-parser-prelude.cc
index 00efbbc1be4..019bff1f2c8 100644
--- a/gcc/algol68/a68-parser-prelude.cc
+++ b/gcc/algol68/a68-parser-prelude.cc
@@ -1409,6 +1409,9 @@ posix_prelude (void)
   a68_idf (A68_EXT, "fcreate", m, a68_lower_posixfcreate);
   m = A68_MCACHE (proc_int_int);
   a68_idf (A68_EXT, "fclose", m, a68_lower_posixfclose);
+  /* Getting properties of files.  */
+  m = a68_proc (M_LONG_LONG_INT, M_INT, NO_MOID);
+  a68_idf (A68_EXT, "fsize", m, a68_lower_posixfsize);
   /* Sockets.  */
   m = a68_proc (M_INT, M_STRING, M_INT, NO_MOID);
   a68_idf (A68_EXT, "fconnect", m, a68_lower_posixfconnect);
diff --git a/gcc/algol68/a68.h b/gcc/algol68/a68.h
index b6cdbfc4fdc..dadae44172d 100644
--- a/gcc/algol68/a68.h
+++ b/gcc/algol68/a68.h
@@ -537,6 +537,7 @@ tree a68_posix_fconnect (void);
 tree a68_posix_fcreate (void);
 tree a68_posix_fopen (void);
 tree a68_posix_fclose (void);
+tree a68_posix_fsize (void);
 tree a68_posix_errno (void);
 tree a68_posix_perror (void);
 tree a68_posix_strerror (void);
@@ -1005,6 +1006,7 @@ tree a68_lower_posixfconnect (NODE_T *p, LOW_CTX_T ctx);
 tree a68_lower_posixfopen (NODE_T *p, LOW_CTX_T ctx);
 tree a68_lower_posixfcreate (NODE_T *p, LOW_CTX_T ctx);
 tree a68_lower_posixfclose (NODE_T *p, LOW_CTX_T ctx);
+tree a68_lower_posixfsize (NODE_T *p, LOW_CTX_T ctx);
 tree a68_lower_posixstdinfiledes (NODE_T *p, LOW_CTX_T ctx);
 tree a68_lower_posixstdoutfiledes (NODE_T *p, LOW_CTX_T ctx);
 tree a68_lower_posixstderrfiledes (NODE_T *p, LOW_CTX_T ctx);
diff --git a/gcc/algol68/ga68.texi b/gcc/algol68/ga68.texi
index 05566472649..8f78341503a 100644
--- a/gcc/algol68/ga68.texi
+++ b/gcc/algol68/ga68.texi
@@ -2760,6 +2760,17 @@ to take effect.  The effect of combining @code{file o trunc} and
 @code{file o rdonly} is undefined and varies among implementations.
 @end deftypevr
 
+@subsection Getting file properties
+
+@deftypefn Procedure {} {fsize} {= (@B{int} fd) @B{long} @B{long} @B{int}}
+Return the size in bytes of the file characterized by the file
+descriptor @code{fd}.  If the system entity characterized by the given
+file descriptor doesn't have a size, if the size of the file cannot be
+stored in a @code{@B{long} @B{long} @B{int}}, or if there is any other
+error condition, this procedure yields -1 and @code{errno} is set
+appropriately.
+@end deftypefn
+
 @node POSIX sockets
 @section POSIX sockets
 
diff --git a/gcc/testsuite/algol68/execute/fsize-1.a68 b/gcc/testsuite/algol68/execute/fsize-1.a68
new file mode 100644
index 00000000000..17e3ef2ba9e
--- /dev/null
+++ b/gcc/testsuite/algol68/execute/fsize-1.a68
@@ -0,0 +1,2 @@
+begin assert (fsize (-1) = - long long 1)
+end
-- 
2.30.2



More information about the Algol68 mailing list