[RFC 0/7 V2] GNU Algol 68 extension: fixed sized modes
Jose E. Marchesi
jemarch@gnu.org
Mon Sep 21 10:26:24 GMT 2026
[Changes from V1:
- Many bug fixes.
- More tests.
- Support for fixed sized modes in modules export.
- Support for word compl.]
[This series has been force-pushed to jemarch/fixety in the forge
gcc/gcc-a68 repo.]
Hello people!
The way Algol 68 provides support for sized modes is by allowing to
specify a "longsety" or a "shortsety" as part of integral, bits, bytes
and real modes, where a longsety is zero or more `long' and a
shortsety is zero or more `short'. At some point, depending on the
target, adding additional longs or shorts stop increasing or
decreasing the size of the mode.
For example, `int' is an integral mode with default size, whereas
`short int' is an integral mode with less than default size, and `long
int' is an integral mode with more than default size.
The particular size assigned to a "sizety" (either a longsety or a
shortsety) is up to the compiler and, in principle, none of the
business of the programmer. The programmer can check the range of
values allowed by each mode by using environment enquiries like
max_int, short_short_min_int or long_max_real.
Now, the GNU Algol 68 compiler provides some guarantees about the size
of the modes, in order to ease integration in the system and
communicating with programs written in other programming languages:
- The size of `short short int' is the same than the size of C
`unsigned char'.
- The size of `int' is the same than the C int.
- The size of `long int' is the same than the size of the next C type
with higher size than `int'.
- The size of `real' is the same than the C `float'.
- The size of `long real' is the same than the C `doubled'.
- The size of `long long real' is the same than the C `long double'.
- etc
This works well. However, there is still the need for modes with the
same size than the target's word size, or memory address.
An alternative that we have considered at some point is to make the compiler
define an additional standard mode like:
mode Word = long int; { Or short int, or int, or long long int,
depending on the target. }
This approach wouldn't require extending the language itself, but it has the
big problem of denotations which, in Algol 68, also contain sizetys.
Depending on the target, you might have to write:
Word base = 16r0;
or
Word base = long 16r0;
or even
Word base = short 16r0;
This patch series implements an alternative approach: rather than having the
compiler defining an additional standard modes for word sized bits, ints,
reals, etc, the syntax of the language is expanded to allow specifying `word'
as a sizety, and so:
word bits base = word 16r0;
The above will work in any target. Corresponding integral, real and bytes
modes of size `word' are also available, and the whole plethora of standard
(and extended standard) identifier, operators and procedures are also
available:
word int counter = word 0;
word real num = 1.23;
word bits numbits = BIN 1.23;
This new `word' size is one of potentially multiple "fixety". The same
strategy can be used in order to provide modes of a fixed size independently
of the target, like `byte' or others.
A possible caveat, however, is that fixetys are not accumulative, unlike
longsetys and shortsetys. Therefore LENG and SHORTEN operators don't make
sense for values of these modes. This means that it is not possible to
convert, say, a `word int' to a `long long int'. This might or might not be a
problem in practice.
Jose E. Marchesi (7):
a68: ga68.vw: add syntax for fixed precision modes
a68: parser: support fixed sized modes
a68: low: support for fixed sized modes
a68: prelude: definitions for fixed sized modes
a68: imports: support fixed sized modes
a68: testsuite: tests for fixed sized modes
a68: manual: document fixed sized modes
gcc/algol68/a68-imports.cc | 5 +
gcc/algol68/a68-lang.cc | 39 +-
gcc/algol68/a68-low-bits.cc | 2 +
gcc/algol68/a68-low-coercions.cc | 16 +-
gcc/algol68/a68-low-complex.cc | 2 +
gcc/algol68/a68-low-decls.cc | 1 +
gcc/algol68/a68-low-ints.cc | 2 +
gcc/algol68/a68-low-moids.cc | 11 +-
gcc/algol68/a68-low-prelude.cc | 130 ++++++
gcc/algol68/a68-low-reals.cc | 39 ++
gcc/algol68/a68-low-units.cc | 34 +-
gcc/algol68/a68-moids-misc.cc | 35 ++
gcc/algol68/a68-moids-to-string.cc | 18 +-
gcc/algol68/a68-parser-attrs.def | 2 +
gcc/algol68/a68-parser-bottom-up.cc | 28 ++
gcc/algol68/a68-parser-keywords.cc | 1 +
gcc/algol68/a68-parser-modes.cc | 34 +-
gcc/algol68/a68-parser-moids-check.cc | 15 +
gcc/algol68/a68-parser-prelude.cc | 218 +++++++++
gcc/algol68/a68-parser-victal.cc | 2 +-
gcc/algol68/a68-types.h | 20 +-
gcc/algol68/a68.h | 25 ++
gcc/algol68/ga68.texi | 412 +++++++++++++++++-
gcc/algol68/ga68.vw | 40 +-
.../algol68/compile/error-word-bits-1.a68 | 4 +
.../algol68/compile/error-word-bits-2.a68 | 4 +
.../algol68/compile/error-word-bits-3.a68 | 4 +
.../algol68/compile/error-word-bits-4.a68 | 3 +
.../algol68/compile/error-word-bits-5.a68 | 3 +
.../algol68/compile/error-word-bits-6.a68 | 3 +
gcc/testsuite/algol68/execute/abs-int-1.a68 | 4 +-
gcc/testsuite/algol68/execute/abs-real-1.a68 | 3 +
gcc/testsuite/algol68/execute/acos-1.a68 | 4 +-
.../algol68/execute/affirm-int-1.a68 | 4 +-
.../algol68/execute/affirm-real-1.a68 | 3 +
.../algol68/execute/and-word-bits-1.a68 | 4 +
gcc/testsuite/algol68/execute/asin-1.a68 | 4 +-
gcc/testsuite/algol68/execute/atan-1.a68 | 4 +-
gcc/testsuite/algol68/execute/bin-word-1.a68 | 2 +
.../algol68/execute/bits-clear-1.a68 | 9 +-
.../execute/bits-environment-enquiries-1.a68 | 7 +
gcc/testsuite/algol68/execute/bits-set-1.a68 | 9 +-
gcc/testsuite/algol68/execute/bits-test-1.a68 | 1 +
gcc/testsuite/algol68/execute/conj-1.a68 | 2 +
gcc/testsuite/algol68/execute/cos-1.a68 | 4 +-
gcc/testsuite/algol68/execute/div-int-1.a68 | 4 +-
.../algol68/execute/divab-real-1.a68 | 5 +-
.../algol68/execute/elem-word-bits-1.a68 | 4 +
gcc/testsuite/algol68/execute/entier-1.a68 | 4 +-
gcc/testsuite/algol68/execute/eq-int-1.a68 | 5 +-
.../algol68/execute/eq-word-bits-1.a68 | 5 +
gcc/testsuite/algol68/execute/ge-int-1.a68 | 5 +-
.../algol68/execute/ge-word-bits-1.a68 | 5 +
gcc/testsuite/algol68/execute/gt-int-1.a68 | 5 +-
gcc/testsuite/algol68/execute/i-1.a68 | 3 +-
gcc/testsuite/algol68/execute/i-2.a68 | 1 +
gcc/testsuite/algol68/execute/le-int-1.a68 | 5 +-
.../algol68/execute/le-word-bits-1.a68 | 5 +
gcc/testsuite/algol68/execute/ln-1.a68 | 4 +-
gcc/testsuite/algol68/execute/log-1.a68 | 4 +-
gcc/testsuite/algol68/execute/lt-int-1.a68 | 5 +-
gcc/testsuite/algol68/execute/minus-int-1.a68 | 4 +-
gcc/testsuite/algol68/execute/minusab-1.a68 | 8 +-
gcc/testsuite/algol68/execute/minusab-2.a68 | 6 +
gcc/testsuite/algol68/execute/mod-int-1.a68 | 5 +-
gcc/testsuite/algol68/execute/modab-1.a68 | 3 +-
.../algol68/execute/modules/module27.a68 | 9 +
.../algol68/execute/modules/program-27.a68 | 9 +
gcc/testsuite/algol68/execute/mult-int-1.a68 | 4 +-
gcc/testsuite/algol68/execute/ne-int-1.a68 | 5 +-
.../algol68/execute/ne-word-bits-1.a68 | 5 +
gcc/testsuite/algol68/execute/neg-int-1.a68 | 4 +-
gcc/testsuite/algol68/execute/neg-real-1.a68 | 3 +
.../algol68/execute/not-word-bits-1.a68 | 5 +
gcc/testsuite/algol68/execute/odd-1.a68 | 4 +-
.../algol68/execute/or-word-bits-1.a68 | 4 +
gcc/testsuite/algol68/execute/over-int-1.a68 | 4 +-
gcc/testsuite/algol68/execute/overab-1.a68 | 3 +-
gcc/testsuite/algol68/execute/plus-int-1.a68 | 4 +-
gcc/testsuite/algol68/execute/plusab-1.a68 | 10 +-
gcc/testsuite/algol68/execute/plusab-2.a68 | 6 +
gcc/testsuite/algol68/execute/pow-int-1.a68 | 5 +-
gcc/testsuite/algol68/execute/pow-real-1.a68 | 2 +
gcc/testsuite/algol68/execute/re-im-1.a68 | 4 +-
gcc/testsuite/algol68/execute/round-1.a68 | 4 +-
gcc/testsuite/algol68/execute/sign-int-1.a68 | 5 +-
gcc/testsuite/algol68/execute/sign-real-1.a68 | 5 +-
gcc/testsuite/algol68/execute/sin-1.a68 | 4 +-
gcc/testsuite/algol68/execute/sqrt-1.a68 | 4 +-
gcc/testsuite/algol68/execute/tan-1.a68 | 4 +-
gcc/testsuite/algol68/execute/timesab-1.a68 | 37 ++
.../algol68/execute/widening-compl-1.a68 | 4 +
gcc/testsuite/algol68/execute/word-bits-1.a68 | 4 +
.../algol68/execute/word-bits-shift-1.a68 | 7 +
gcc/testsuite/algol68/execute/xor-bits-1.a68 | 5 +-
95 files changed, 1406 insertions(+), 78 deletions(-)
create mode 100644 gcc/testsuite/algol68/compile/error-word-bits-1.a68
create mode 100644 gcc/testsuite/algol68/compile/error-word-bits-2.a68
create mode 100644 gcc/testsuite/algol68/compile/error-word-bits-3.a68
create mode 100644 gcc/testsuite/algol68/compile/error-word-bits-4.a68
create mode 100644 gcc/testsuite/algol68/compile/error-word-bits-5.a68
create mode 100644 gcc/testsuite/algol68/compile/error-word-bits-6.a68
create mode 100644 gcc/testsuite/algol68/execute/abs-real-1.a68
create mode 100644 gcc/testsuite/algol68/execute/affirm-real-1.a68
create mode 100644 gcc/testsuite/algol68/execute/and-word-bits-1.a68
create mode 100644 gcc/testsuite/algol68/execute/bin-word-1.a68
create mode 100644 gcc/testsuite/algol68/execute/bits-environment-enquiries-1.a68
create mode 100644 gcc/testsuite/algol68/execute/elem-word-bits-1.a68
create mode 100644 gcc/testsuite/algol68/execute/eq-word-bits-1.a68
create mode 100644 gcc/testsuite/algol68/execute/ge-word-bits-1.a68
create mode 100644 gcc/testsuite/algol68/execute/le-word-bits-1.a68
create mode 100644 gcc/testsuite/algol68/execute/modules/module27.a68
create mode 100644 gcc/testsuite/algol68/execute/modules/program-27.a68
create mode 100644 gcc/testsuite/algol68/execute/ne-word-bits-1.a68
create mode 100644 gcc/testsuite/algol68/execute/neg-real-1.a68
create mode 100644 gcc/testsuite/algol68/execute/not-word-bits-1.a68
create mode 100644 gcc/testsuite/algol68/execute/or-word-bits-1.a68
create mode 100644 gcc/testsuite/algol68/execute/timesab-1.a68
create mode 100644 gcc/testsuite/algol68/execute/widening-compl-1.a68
create mode 100644 gcc/testsuite/algol68/execute/word-bits-1.a68
create mode 100644 gcc/testsuite/algol68/execute/word-bits-shift-1.a68
--
2.39.5
More information about the Algol68
mailing list