> Excerpts from Jose E. Marchesi's message of Januar 31, 2026 6:58 pm:
>> This patch adds support for a TEST operator for L bits.  Documentation
>> and tests are included.
>> 
>> Signed-off-by: Jose E. Marchesi <[email protected]>
>> 
>> gcc/algol68/ChangeLog
>> 
>>      * a68.h: Prototypes for a68_bits_test and a68_lower_test3.
>>      * a68-low-bits.cc (a68_bits_test): New function.
>>      * a68-low-prelude.cc (a68_lower_test3): Likewise.
>>      * a68-parser-prelude.cc (gnu_prelude): Declare TEST operators and
>>      their priority.
>>      * ga68.texi (Extended bits operators): New section.
>> 
>> gcc/testsuite/ChangeLog
>> 
>>      * algol68/execute/bits-test-1.a68: New test.
>> ---
>>  gcc/algol68/a68-low-bits.cc                   | 40 +++++++++++++++++++
>>  gcc/algol68/a68-low-prelude.cc                |  8 ++++
>>  gcc/algol68/a68-parser-prelude.cc             | 11 +++++
>>  gcc/algol68/a68.h                             |  2 +
>>  gcc/algol68/ga68.texi                         |  6 +++
>>  gcc/testsuite/algol68/execute/bits-test-1.a68 |  5 +++
>>  6 files changed, 72 insertions(+)
>>  create mode 100644 gcc/testsuite/algol68/execute/bits-test-1.a68
>> 
>> diff --git a/gcc/algol68/a68-low-bits.cc b/gcc/algol68/a68-low-bits.cc
>> index 6a272ca633d..16205fa6351 100644
>> --- a/gcc/algol68/a68-low-bits.cc
>> +++ b/gcc/algol68/a68-low-bits.cc
>> @@ -367,3 +367,43 @@ a68_bits_clear (MOID_T *m, tree bits, tree numbit, 
>> location_t loc)
>>                        bits_type,
>>                        in_range, res, bits);
>>  }
>> +
>> +/* Test the bit NUMBIT in BITS.
>> +
>> +   NUMBIT is one based and counts bits from least significative to most
>> +   significative, i.e. from "right" to "left".  If NUMBIT is not in range 
>> then
>> +   the operator yields false.  */
>> +
>> +tree
>> +a68_bits_test (MOID_T *m ATTRIBUTE_UNUSED,
>> +           tree bits, tree numbit, location_t loc)
>> +{
>> +  tree bits_type = TREE_TYPE (bits);
>> +  tree int_type = TREE_TYPE (numbit);
>> +
>> +  bits = save_expr (bits);
>> +  numbit = save_expr (numbit);
>> +
>> +  tree numbit_minus_one = fold_build2 (MINUS_EXPR, int_type,
>> +                                   numbit, build_one_cst (int_type));
>> +  tree mask = fold_build2 (BIT_AND_EXPR, bits_type,
>> +                       bits,
>> +                       fold_build2 (LSHIFT_EXPR,
>> +                                    bits_type,
>> +                                    build_one_cst (bits_type),
>> +                                    fold_convert (bits_type, 
>> numbit_minus_one)));
>> +  tree res = fold_build2 (NE_EXPR,
>> +                      a68_bool_type,
>
> LGTM.
>
> Should the use of a68_bool_type be replaced with CTYPE (m)?

I just pushed the patch below that just removes the unneeded parameter.
The result of a bits test operation is always a68_bool_type regardless
of the type of `bits'.

Thanks.

gcc/algol68/ChangeLog

        * a68-low-bits.cc (a68_bits_test): Do not get a parameter with the
        result moid.
        * a68.h: Adapt prototype of a68_bits_test accordingly.
        * a68-low-prelude.cc (a68_lower_test3): Adjust call accordingly.
---
 gcc/algol68/a68-low-bits.cc    | 3 +--
 gcc/algol68/a68-low-prelude.cc | 2 +-
 gcc/algol68/a68.h              | 2 +-
 3 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/gcc/algol68/a68-low-bits.cc b/gcc/algol68/a68-low-bits.cc
index 16205fa6351..cfe84fbff33 100644
--- a/gcc/algol68/a68-low-bits.cc
+++ b/gcc/algol68/a68-low-bits.cc
@@ -375,8 +375,7 @@ a68_bits_clear (MOID_T *m, tree bits, tree numbit, 
location_t loc)
    the operator yields false.  */
 
 tree
-a68_bits_test (MOID_T *m ATTRIBUTE_UNUSED,
-              tree bits, tree numbit, location_t loc)
+a68_bits_test (tree bits, tree numbit, location_t loc)
 {
   tree bits_type = TREE_TYPE (bits);
   tree int_type = TREE_TYPE (numbit);
diff --git a/gcc/algol68/a68-low-prelude.cc b/gcc/algol68/a68-low-prelude.cc
index 331e865ffff..9bc03cff48f 100644
--- a/gcc/algol68/a68-low-prelude.cc
+++ b/gcc/algol68/a68-low-prelude.cc
@@ -771,7 +771,7 @@ a68_lower_test3 (NODE_T *p, LOW_CTX_T ctx)
 {
   tree op1 = a68_lower_tree (SUB (p), ctx);
   tree op2 = a68_lower_tree (NEXT (NEXT (SUB (p))), ctx);
-  return a68_bits_test (MOID (p), op1, op2, a68_get_node_location (p));
+  return a68_bits_test (op1, op2, a68_get_node_location (p));
 }
 
 tree
diff --git a/gcc/algol68/a68.h b/gcc/algol68/a68.h
index c0fc8bedb94..3e3442f668a 100644
--- a/gcc/algol68/a68.h
+++ b/gcc/algol68/a68.h
@@ -539,7 +539,7 @@ tree a68_bits_eq (tree a, tree b, location_t loc = 
UNKNOWN_LOCATION);
 tree a68_bits_ne (tree a, tree b, location_t loc = UNKNOWN_LOCATION);
 tree a68_bits_set (MOID_T *m, tree bits, tree numbit, location_t loc = 
UNKNOWN_LOCATION);
 tree a68_bits_clear (MOID_T *m, tree bits, tree numbit, location_t loc = 
UNKNOWN_LOCATION);
-tree a68_bits_test (MOID_T *m, tree bits, tree numbit, location_t loc = 
UNKNOWN_LOCATION);
+tree a68_bits_test (tree bits, tree numbit, location_t loc = UNKNOWN_LOCATION);
 
 /* a68-low_bools.cc  */
 
-- 
2.39.5

Reply via email to