poke-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[COMMITTED] pkl: support indexing arrays and strings by offset


From: Jose E. Marchesi
Subject: [COMMITTED] pkl: support indexing arrays and strings by offset
Date: Mon, 31 Oct 2022 09:52:09 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)


This patch adds support for indexing Poke arrays and strings with
offsets.

When an expression that evaluates to an offset is used as the
index in an array or string, it refers to the element in the
array (or character in the string) occupying _exactly_ the given
offset inside the array.  If no such element exists then
E_out_of_bounds is raised.  Examples:

  (poke) [1,2,3][4#B]
  2
  (poke) [1,2,3][5#B]
  unhandled out of bounds exception

The canonical use case for this feature is to implement string
tables:

  type COFF_Strtab =
    struct
    {
      offset<uint<32>,B> size;
      string[size] entries;

      method get_string = (offset<uint<32>,B> offset) string:
      {
        return entries[offset];
      }
    };

Note that the above works for both mapped and non-mapped COFF
string tables.  This is unlike the previous implementation:

  type COFF_Strtab =
    struct
    {
      offset<uint<32>,B> size;
      string[size] entries;

      method get_string = (offset<uint<32>,B> offset) string:
      {
        /* XXX use indexing by size whenever available, it is
           better because it is agnostic to mapping.  */
        return string @ entries'offset + offset;
      }
    };

Which only worked for mapped values.

2022-10-31  Jose E. Marchesi  <jemarch@gnu.org>

        * libpoke/pkl-typify.c (pkl_typify1_ps_indexer): Allow offsets as
        indexes in indexers.
        * libpoke/pkl-promo.c (pkl_promo_ps_indexer): Promote offset
        indexes.
        * libpoke/pkl-gen.c (pkl_gen_pr_indexer): Handle offset indexes.
        * libpoke/pkl-gen.pks (aoref): New macro.
        (stroref): Likewise.
        * libpoke/pkl-rt.pk (_pkl_aoref): New function.
        (_pkl_aoref_complete): Likewise.
        * testsuite/poke.pkl/arrays-index-4.pk: New test.
        * testsuite/poke.pkl/arrays-index-5.pk: Likewise.
        * testsuite/poke.pkl/arrays-index-6.pk: Likewise.
        * testsuite/poke.pkl/arrays-index-7.pk: Likewise.
        * testsuite/poke.pkl/arrays-index-8.pk: Likewise.
        * testsuite/poke.pkl/arrays-index-9.pk: Likewise.
        * testsuite/poke.pkl/arrays-index-10.pk: Likewise.
        * testsuite/poke.pkl/arrays-index-11.pk: Likewise.
        * testsuite/poke.pkl/arrays-index-12.pk: Likewise.
        * testsuite/poke.pkl/arrays-index-13.pk: Likewise.
        * testsuite/poke.pkl/arrays-index-14.pk: Likewise.
        * testsuite/poke.pkl/strings-index-3.pk: Likewise.
        * testsuite/poke.pkl/strings-index-4.pk: likewise.
        * testsuite/poke.pkl/strings-index-5.pk: Likewise.
        * testsuite/Makefile.am (EXTRA_DIST): Add new tests.
        * doc/poke.texi (Array Indexing): Document indexing by offset.
        (String Indexing): Likewise.
---
 ChangeLog                             | 29 ++++++++++++++
 doc/poke.texi                         | 29 ++++++++++++--
 libpoke/pkl-ast.h                     |  6 ++-
 libpoke/pkl-gen.c                     | 20 ++++++++--
 libpoke/pkl-gen.pks                   | 56 +++++++++++++++++++++++++++
 libpoke/pkl-promo.c                   | 31 ++++++++++++---
 libpoke/pkl-rt.pk                     | 55 ++++++++++++++++++++++++++
 libpoke/pkl-typify.c                  | 10 +++--
 testsuite/Makefile.am                 | 14 +++++++
 testsuite/poke.pkl/arrays-index-10.pk |  5 +++
 testsuite/poke.pkl/arrays-index-11.pk |  5 +++
 testsuite/poke.pkl/arrays-index-12.pk |  5 +++
 testsuite/poke.pkl/arrays-index-13.pk |  5 +++
 testsuite/poke.pkl/arrays-index-14.pk |  7 ++++
 testsuite/poke.pkl/arrays-index-4.pk  |  5 +++
 testsuite/poke.pkl/arrays-index-5.pk  |  5 +++
 testsuite/poke.pkl/arrays-index-6.pk  |  5 +++
 testsuite/poke.pkl/arrays-index-7.pk  |  5 +++
 testsuite/poke.pkl/arrays-index-8.pk  |  5 +++
 testsuite/poke.pkl/arrays-index-9.pk  |  5 +++
 testsuite/poke.pkl/strings-index-3.pk |  5 +++
 testsuite/poke.pkl/strings-index-4.pk |  5 +++
 testsuite/poke.pkl/strings-index-5.pk |  5 +++
 23 files changed, 305 insertions(+), 17 deletions(-)
 create mode 100644 testsuite/poke.pkl/arrays-index-10.pk
 create mode 100644 testsuite/poke.pkl/arrays-index-11.pk
 create mode 100644 testsuite/poke.pkl/arrays-index-12.pk
 create mode 100644 testsuite/poke.pkl/arrays-index-13.pk
 create mode 100644 testsuite/poke.pkl/arrays-index-14.pk
 create mode 100644 testsuite/poke.pkl/arrays-index-4.pk
 create mode 100644 testsuite/poke.pkl/arrays-index-5.pk
 create mode 100644 testsuite/poke.pkl/arrays-index-6.pk
 create mode 100644 testsuite/poke.pkl/arrays-index-7.pk
 create mode 100644 testsuite/poke.pkl/arrays-index-8.pk
 create mode 100644 testsuite/poke.pkl/arrays-index-9.pk
 create mode 100644 testsuite/poke.pkl/strings-index-3.pk
 create mode 100644 testsuite/poke.pkl/strings-index-4.pk
 create mode 100644 testsuite/poke.pkl/strings-index-5.pk

diff --git a/ChangeLog b/ChangeLog
index 1ecedfe5..0a5d0e18 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,32 @@
+2022-10-31  Jose E. Marchesi  <jemarch@gnu.org>
+
+       * libpoke/pkl-typify.c (pkl_typify1_ps_indexer): Allow offsets as
+       indexes in indexers.
+       * libpoke/pkl-promo.c (pkl_promo_ps_indexer): Promote offset
+       indexes.
+       * libpoke/pkl-gen.c (pkl_gen_pr_indexer): Handle offset indexes.
+       * libpoke/pkl-gen.pks (aoref): New macro.
+       (stroref): Likewise.
+       * libpoke/pkl-rt.pk (_pkl_aoref): New function.
+       (_pkl_aoref_complete): Likewise.
+       * testsuite/poke.pkl/arrays-index-4.pk: New test.
+       * testsuite/poke.pkl/arrays-index-5.pk: Likewise.
+       * testsuite/poke.pkl/arrays-index-6.pk: Likewise.
+       * testsuite/poke.pkl/arrays-index-7.pk: Likewise.
+       * testsuite/poke.pkl/arrays-index-8.pk: Likewise.
+       * testsuite/poke.pkl/arrays-index-9.pk: Likewise.
+       * testsuite/poke.pkl/arrays-index-10.pk: Likewise.
+       * testsuite/poke.pkl/arrays-index-11.pk: Likewise.
+       * testsuite/poke.pkl/arrays-index-12.pk: Likewise.
+       * testsuite/poke.pkl/arrays-index-13.pk: Likewise.
+       * testsuite/poke.pkl/arrays-index-14.pk: Likewise.
+       * testsuite/poke.pkl/strings-index-3.pk: Likewise.
+       * testsuite/poke.pkl/strings-index-4.pk: likewise.
+       * testsuite/poke.pkl/strings-index-5.pk: Likewise.
+       * testsuite/Makefile.am (EXTRA_DIST): Add new tests.
+       * doc/poke.texi (Array Indexing): Document indexing by offset.
+       (String Indexing): Likewise.
+
 2022-10-30  Jose E. Marchesi  <jemarch@gnu.org>
 
        * libpoke/pkl-tab.y: Make unary operators take precedence over AS
diff --git a/doc/poke.texi b/doc/poke.texi
index 69efac10..685f94f7 100644
--- a/doc/poke.texi
+++ b/doc/poke.texi
@@ -10058,6 +10058,14 @@ unhandled out of bounds exception
 unhandled out of bounds exception
 @end example
 
+@noindent
+Poke also provides a way to refer to a character in a string by the
+offset the character occupies in the string.  This is done by using as
+index an expression that evaluates to an offset value.  This value is
+then implicitly promoted to have an unsigned 64-bit magnitude and unit
+bits whenever needed.  If no character starts @emph{exactly} at the
+provided offset then an @code{E_out_of_bounds} exception is raised.
+
 @node String Concatenation
 @subsection String Concatenation
 @cindex concatenation, strings
@@ -10544,12 +10552,15 @@ enclosed between square brackets with @code{[} and 
@code{]}:
 @example
 (poke) [1,2,3][0]
 1
-(poke) [1,2,3][1]
+(poke) [1,2,3][8#B]
 2
 @end example
 
-The index should be an expression that evaluates to an integer value,
-and it is promoted to an unsigned 64-bit integer when needed.
+@subsubsection Indexing an array by number of element
+
+Indexing by number of element is performed by providing as index an
+expression that evaluates to an integral value.  This value is then
+implicitly promoted to an unsigned 64-bit integer when needed.
 
 @cindex exceptions
 The valid range for the index is @code{[0,@var{n}]} where @var{n} is
@@ -10564,6 +10575,18 @@ unhandled out of bounds exception
 unhandled out of bounds exception
 @end example
 
+@subsubsection Indexing an array by offset of element
+
+Poke also provides a way to refer to the element of an array by the
+offset where the element appears inside the array.  This is done by
+providing as index an expression that evaluates to an offset value.
+This value is then implicitly promoted to an offset with magnitude
+unsigned 64-bit integer and bit unit when needed.
+
+If there is not element in the indexed array that starts
+@emph{exactly} at the given offset then an @code{E_out_of_bounds}
+exception is raised.
+
 @node Array Trimming
 @subsection Array Trimming
 
diff --git a/libpoke/pkl-ast.h b/libpoke/pkl-ast.h
index 1d98245d..3cf12d18 100644
--- a/libpoke/pkl-ast.h
+++ b/libpoke/pkl-ast.h
@@ -718,8 +718,10 @@ pkl_ast_node pkl_ast_make_trimmer (pkl_ast ast,
 
    BASE must point to a PKL_AST_ARRAY node.
 
-   INDEX must point to an expression whose evaluation is the offset of
-   the element into the field, in units of the field's SIZE.
+   INDEX must point to an expression whose evaluation is either an
+   integer with the 0 base index of the indexed element, or an offset
+   indicating the exact offset from the beginning of the array to the
+   indexed element.
 
    IS_INDEXED is a boolean indicating whether the indexer is
    immediately indexed with another [] operator.  This is used in the
diff --git a/libpoke/pkl-gen.c b/libpoke/pkl-gen.c
index be7e2c23..d1b3fd6c 100644
--- a/libpoke/pkl-gen.c
+++ b/libpoke/pkl-gen.c
@@ -2661,12 +2661,19 @@ PKL_PHASE_BEGIN_HANDLER (pkl_gen_pr_indexer)
       pkl_ast_node indexer_type = PKL_AST_TYPE (indexer);
       pkl_ast_node container = PKL_AST_INDEXER_ENTITY (indexer);
       pkl_ast_node container_type = PKL_AST_TYPE (container);
+      pkl_ast_node index = PKL_AST_INDEXER_INDEX (indexer);
+      pkl_ast_node index_type = PKL_AST_TYPE (index);
 
       switch (PKL_AST_TYPE_CODE (container_type))
         {
         case PKL_TYPE_ARRAY:
-          pkl_asm_insn (PKL_GEN_ASM, PKL_INSN_AREF);
-          pkl_asm_insn (PKL_GEN_ASM, PKL_INSN_NIP2);
+          if (PKL_AST_TYPE_CODE (index_type) == PKL_TYPE_INTEGRAL)
+            {
+              pkl_asm_insn (PKL_GEN_ASM, PKL_INSN_AREF);
+              pkl_asm_insn (PKL_GEN_ASM, PKL_INSN_NIP2);
+            }
+          else
+            RAS_MACRO_AOREF (container_type, index_type);
 
           /* To cover cases where the referenced array is not mapped, but
              the value stored in it is a mapped value, we issue a
@@ -2690,8 +2697,13 @@ PKL_PHASE_BEGIN_HANDLER (pkl_gen_pr_indexer)
             }
           break;
         case PKL_TYPE_STRING:
-          pkl_asm_insn (PKL_GEN_ASM, PKL_INSN_STRREF);
-          pkl_asm_insn (PKL_GEN_ASM, PKL_INSN_NIP2);
+          if (PKL_AST_TYPE_CODE (index_type) == PKL_TYPE_INTEGRAL)
+            {
+              pkl_asm_insn (PKL_GEN_ASM, PKL_INSN_STRREF);
+              pkl_asm_insn (PKL_GEN_ASM, PKL_INSN_NIP2);
+            }
+          else
+            RAS_MACRO_STROREF (index_type);
           break;
         default:
           assert (0);
diff --git a/libpoke/pkl-gen.pks b/libpoke/pkl-gen.pks
index 2c77268d..d58b2b27 100644
--- a/libpoke/pkl-gen.pks
+++ b/libpoke/pkl-gen.pks
@@ -3195,3 +3195,59 @@
         sset
         return
         .end
+
+;;; RAS_MACRO_AOREF @array_type @index_type
+;;; ( ARR IDX -- ARR IDX VAL )
+;;;
+;;; Generate code for indexing the array ARR by offset IDX.
+;;;
+;;; The offset in IDX should be of type offset<ulong<64>,1>.
+;;;
+;;; If there is not an element in ARR whose offset is _exactly_
+;;; IDX then the E_out_of_bounds exception is raised.
+;;;
+;;; Macro arguments:
+;;; @array_type
+;;;   AST node with the type of the array being indexed.
+;;; @index_type
+;;;   AST node with the type of the index, which must be
+;;;   an integer or an offset.
+
+        .macro aoref @array_type @index_type
+        .let @etype = PKL_AST_TYPE_A_ETYPE (@array_type)
+  .c if (PKL_AST_TYPE_COMPLETE (@etype) == PKL_AST_TYPE_COMPLETE_YES)
+  .c {
+        ;; If the size all the array elements is constant and known
+        ;; at compile-time, then we can just calculate the index
+        ;; corresponding to the given offset.
+        .let @esize = pkl_ast_sizeof_type (PKL_PASS_AST, @etype)
+  .c    assert (PKL_AST_CODE (@esize) == PKL_AST_INTEGER);
+        .let #esizeval = pvm_make_ulong (PKL_AST_INTEGER_VALUE (@esize), 64);
+        push #esizeval            ; ARR IDX ESIZE
+        .call _pkl_aoref_complete ; VAL
+  .c }
+  .c else
+  .c {
+        ;; Otherwise, slow path.
+        .call _pkl_aoref        ; VAL
+  .c }
+        .end
+
+;;; RAS_MACRO_STROREF @indexer_type
+;;; ( STR IDX -- STR IDX VAL )
+;;;
+;;; Generate code for indexing the array ARR by offset IDX.
+;;;
+;;; The offset in IDX should be of type offset<ulong<64>,1>.
+;;;
+;;; If the given offset is past the end of the string then the
+;;; E_out_of_bound exception is raised.
+;;;
+;;; Macro arguments:
+;;; @index_type
+;;;   AST node with the type of the index, which must be
+;;;   an integer or an offset.
+
+        .macro stroref @index_type
+        .call _pkl_stroref
+        .end
diff --git a/libpoke/pkl-promo.c b/libpoke/pkl-promo.c
index 0d8c662e..2b189fbf 100644
--- a/libpoke/pkl-promo.c
+++ b/libpoke/pkl-promo.c
@@ -833,22 +833,43 @@ PKL_PHASE_BEGIN_HANDLER (pkl_promo_ps_op_unary)
 }
 PKL_PHASE_END_HANDLER
 
-/* Handler for promoting indexes in indexers to unsigned 64 bit
-   values.  */
+/* Handler for promoting integral indexes in indexers:
+
+   - Integral indexes are promoted to uint<64>.
+   - Offset indexes are promoted to offset<uint<64>,1>.  */
 
 PKL_PHASE_BEGIN_HANDLER (pkl_promo_ps_indexer)
 {
   int restart;
   pkl_ast_node node = PKL_PASS_NODE;
+  pkl_ast_node index = PKL_AST_INDEXER_INDEX (node);
+  pkl_ast_node index_type = PKL_AST_TYPE (index);
 
-  if (!promote_integral (PKL_PASS_AST, 64, 0,
-                         &PKL_AST_INDEXER_INDEX (node), &restart))
+  if (PKL_AST_TYPE_CODE (index_type) == PKL_TYPE_INTEGRAL
+      && !promote_integral (PKL_PASS_AST, 64, 0,
+                            &PKL_AST_INDEXER_INDEX (node), &restart))
     {
       PKL_ICE (PKL_AST_LOC (node),
-               "couldn't promote indexer subscript");
+               "couldn't promote integral indexer subscript");
       PKL_PASS_ERROR;
     }
 
+  if (PKL_AST_TYPE_CODE (index_type) == PKL_TYPE_OFFSET)
+    {
+      pkl_ast_node unit_bit = pkl_ast_make_integer (PKL_PASS_AST, 1);
+      unit_bit = ASTREF (unit_bit);
+
+      if (!promote_offset (PKL_PASS_AST, 64, 0, unit_bit,
+                           &PKL_AST_INDEXER_INDEX (node), &restart))
+        {
+          PKL_ICE (PKL_AST_LOC (node),
+                   "couldn't promote offset indexer subscript");
+          PKL_PASS_ERROR;
+        }
+
+      pkl_ast_node_free (unit_bit);
+    }
+
   PKL_PASS_RESTART = restart;
 }
 PKL_PHASE_END_HANDLER
diff --git a/libpoke/pkl-rt.pk b/libpoke/pkl-rt.pk
index fc461f93..07bafa8b 100644
--- a/libpoke/pkl-rt.pk
+++ b/libpoke/pkl-rt.pk
@@ -552,6 +552,61 @@ immutable fun _pkl_assert = (uint<64> cond, string msg, 
string filename,
     };
   }
 
+/* The following function implements the fast path of the aoref macro
+   in pkl-gen.pks.  Given an array whose elements have all the same
+   size, which is known at compile-time, and an offset, return the
+   element stored in the array at that exact offset.  If no such
+   element exists in the array then raise E_out_of_bounds.  */
+
+fun _pkl_aoref_complete = (any[] array, offset<uint<64>,1> idx,
+                           uint<64> elem_bsize) any:
+{
+  var len = array'length;
+
+  /* Corner case to avoid division by zero below.  */
+  if (elem_bsize == 0 && idx == 0#1 && len > 0)
+    return array'elem (0);
+
+  if (idx'magnitude % elem_bsize == 0)
+    return array'elem (idx'magnitude / elem_bsize);
+  raise E_out_of_bounds;
+}
+
+/* The following function implements the slow path of the aoref macro
+   in pkl-gen.pks.  Given an array and an offset, return the element
+   stored in the array at that exact offset.  If no such element exists
+   in the array then raise E_out_of_bounds.  */
+
+fun _pkl_aoref = (any[] array, offset<uint<64>,1> idx) any:
+{
+  var len = array'length;
+
+  for (var i = 0UL; i < len; ++i)
+    {
+      if (array'eoffset (i) > idx)
+        break;
+
+      if (array'eoffset (i) == idx)
+        return array'elem (i);
+    }
+
+  raise E_out_of_bounds;
+}
+
+/* The following function implements the stroref macro in pkl-gen.pks.
+   Given a string and an offset, return the character occupying the
+   position at the given offset in the string.  If the given offset is
+   past the end of the string or the offset is not byte-aligned then
+   raise E_out_of_bounds.  */
+
+fun _pkl_stroref = (string str, offset<uint<64>,1> idx) uint<8>:
+{
+  if (idx'magnitude % 8 != 0 || idx >= str'size)
+    raise E_out_of_bounds;
+
+  return str[idx'magnitude / 8];
+}
+
 /* The Pk_Type struct below describes the values returned by the
    `typeof' language construction.  This type is used in the compiler
    phases, so pretty please do not use `typeof' until the compiler has
diff --git a/libpoke/pkl-typify.c b/libpoke/pkl-typify.c
index e17a0ad0..dfbc349b 100644
--- a/libpoke/pkl-typify.c
+++ b/libpoke/pkl-typify.c
@@ -1161,7 +1161,10 @@ PKL_PHASE_END_HANDLER
 
 /* The type of an INDEXER is the type of the elements of the array
    it references.  If the referenced container is a string, the type
-   of the INDEXER is uint<8>.  */
+   of the INDEXER is uint<8>.
+
+   Also, the type of the index should be either integral or
+   offset.  */
 
 PKL_PHASE_BEGIN_HANDLER (pkl_typify1_ps_indexer)
 {
@@ -1201,13 +1204,14 @@ PKL_PHASE_BEGIN_HANDLER (pkl_typify1_ps_indexer)
       }
     }
 
-  if (PKL_AST_TYPE_CODE (index_type) != PKL_TYPE_INTEGRAL)
+  if (PKL_AST_TYPE_CODE (index_type) != PKL_TYPE_INTEGRAL
+      && PKL_AST_TYPE_CODE (index_type) != PKL_TYPE_OFFSET)
     {
       char *type_str = pkl_type_str (index_type, 1);
 
       PKL_ERROR (PKL_AST_LOC (index),
                  "invalid index in array indexer\n"
-                 "expected integral, got %s",
+                 "expected integral or offset, got %s",
                  type_str);
       free (type_str);
       PKL_TYPIFY_PAYLOAD->errors++;
diff --git a/testsuite/Makefile.am b/testsuite/Makefile.am
index cdd4d779..08b5f97b 100644
--- a/testsuite/Makefile.am
+++ b/testsuite/Makefile.am
@@ -756,6 +756,17 @@ EXTRA_DIST = \
   poke.pkl/arrays-index-1.pk \
   poke.pkl/arrays-index-2.pk \
   poke.pkl/arrays-index-3.pk \
+  poke.pkl/arrays-index-4.pk \
+  poke.pkl/arrays-index-5.pk \
+  poke.pkl/arrays-index-6.pk \
+  poke.pkl/arrays-index-7.pk \
+  poke.pkl/arrays-index-8.pk \
+  poke.pkl/arrays-index-9.pk \
+  poke.pkl/arrays-index-10.pk \
+  poke.pkl/arrays-index-11.pk \
+  poke.pkl/arrays-index-12.pk \
+  poke.pkl/arrays-index-13.pk \
+  poke.pkl/arrays-index-14.pk \
   poke.pkl/arrays-index-diag-1.pk \
   poke.pkl/arrays-index-diag-2.pk \
   poke.pkl/arrays-index-diag-3.pk \
@@ -2262,6 +2273,9 @@ EXTRA_DIST = \
   poke.pkl/strings-esc-diag-4.pk \
   poke.pkl/strings-index-1.pk \
   poke.pkl/strings-index-2.pk \
+  poke.pkl/strings-index-3.pk \
+  poke.pkl/strings-index-4.pk \
+  poke.pkl/strings-index-5.pk \
   poke.pkl/strings-index-diag-1.pk \
   poke.pkl/strings-index-diag-2.pk \
   poke.pkl/strings-index-diag-3.pk \
diff --git a/testsuite/poke.pkl/arrays-index-10.pk 
b/testsuite/poke.pkl/arrays-index-10.pk
new file mode 100644
index 00000000..ca11bfbc
--- /dev/null
+++ b/testsuite/poke.pkl/arrays-index-10.pk
@@ -0,0 +1,5 @@
+/* { dg-do run } */
+
+/* { dg-command {.set obase 10} } */
+/* { dg-command {["foo","x","bar"][8#N]} } */
+/* { dg-output {"x"} } */
diff --git a/testsuite/poke.pkl/arrays-index-11.pk 
b/testsuite/poke.pkl/arrays-index-11.pk
new file mode 100644
index 00000000..6021c919
--- /dev/null
+++ b/testsuite/poke.pkl/arrays-index-11.pk
@@ -0,0 +1,5 @@
+/* { dg-do run } */
+
+/* { dg-command {.set obase 10} } */
+/* { dg-command {["foo","x","bar"][5#B + 8#b]} } */
+/* { dg-output {"bar"} } */
diff --git a/testsuite/poke.pkl/arrays-index-12.pk 
b/testsuite/poke.pkl/arrays-index-12.pk
new file mode 100644
index 00000000..14740ad5
--- /dev/null
+++ b/testsuite/poke.pkl/arrays-index-12.pk
@@ -0,0 +1,5 @@
+/* { dg-do run } */
+
+/* { dg-command {.set obase 10} } */
+/* { dg-command {try ["foo","x","bar"][8#B]; catch if E_out_of_bounds { print 
"caught\n"; } } } */
+/* { dg-output {caught} } */
diff --git a/testsuite/poke.pkl/arrays-index-13.pk 
b/testsuite/poke.pkl/arrays-index-13.pk
new file mode 100644
index 00000000..14740ad5
--- /dev/null
+++ b/testsuite/poke.pkl/arrays-index-13.pk
@@ -0,0 +1,5 @@
+/* { dg-do run } */
+
+/* { dg-command {.set obase 10} } */
+/* { dg-command {try ["foo","x","bar"][8#B]; catch if E_out_of_bounds { print 
"caught\n"; } } } */
+/* { dg-output {caught} } */
diff --git a/testsuite/poke.pkl/arrays-index-14.pk 
b/testsuite/poke.pkl/arrays-index-14.pk
new file mode 100644
index 00000000..f1549e3f
--- /dev/null
+++ b/testsuite/poke.pkl/arrays-index-14.pk
@@ -0,0 +1,7 @@
+/* { dg-do run } */
+
+type Empty = struct {};
+
+/* { dg-command {.set obase 10} } */
+/* { dg-command {[Empty{},Empty{},Empty{}][0#N]} } */
+/* { dg-output {Empty \{\}} } */
diff --git a/testsuite/poke.pkl/arrays-index-4.pk 
b/testsuite/poke.pkl/arrays-index-4.pk
new file mode 100644
index 00000000..3f0db3f6
--- /dev/null
+++ b/testsuite/poke.pkl/arrays-index-4.pk
@@ -0,0 +1,5 @@
+/* { dg-do run } */
+
+/* { dg-command {.set obase 10} } */
+/* { dg-command {[1,2,3][0#B]} } */
+/* { dg-output "1" } */
diff --git a/testsuite/poke.pkl/arrays-index-5.pk 
b/testsuite/poke.pkl/arrays-index-5.pk
new file mode 100644
index 00000000..f5ed9e81
--- /dev/null
+++ b/testsuite/poke.pkl/arrays-index-5.pk
@@ -0,0 +1,5 @@
+/* { dg-do run } */
+
+/* { dg-command {.set obase 10} } */
+/* { dg-command {[1,2,3][8UB#N]} } */
+/* { dg-output "2" } */
diff --git a/testsuite/poke.pkl/arrays-index-6.pk 
b/testsuite/poke.pkl/arrays-index-6.pk
new file mode 100644
index 00000000..18e5b753
--- /dev/null
+++ b/testsuite/poke.pkl/arrays-index-6.pk
@@ -0,0 +1,5 @@
+/* { dg-do run } */
+
+/* { dg-command {.set obase 10} } */
+/* { dg-command {[1,2,3][14UB#N + 1#B]} } */
+/* { dg-output "3" } */
diff --git a/testsuite/poke.pkl/arrays-index-7.pk 
b/testsuite/poke.pkl/arrays-index-7.pk
new file mode 100644
index 00000000..e7f6ca2c
--- /dev/null
+++ b/testsuite/poke.pkl/arrays-index-7.pk
@@ -0,0 +1,5 @@
+/* { dg-do run } */
+
+/* { dg-command {.set obase 10} } */
+/* { dg-command {try [1,2,3][16UB#N + 2#B]; catch if E_out_of_bounds { print 
"caught\n"; } } } */
+/* { dg-output "caught" } */
diff --git a/testsuite/poke.pkl/arrays-index-8.pk 
b/testsuite/poke.pkl/arrays-index-8.pk
new file mode 100644
index 00000000..8afb7439
--- /dev/null
+++ b/testsuite/poke.pkl/arrays-index-8.pk
@@ -0,0 +1,5 @@
+/* { dg-do run } */
+
+/* { dg-command {.set obase 10} } */
+/* { dg-command {try [1,2,3][3#B]; catch if E_out_of_bounds { print 
"caught\n"; } } } */
+/* { dg-output "caught" } */
diff --git a/testsuite/poke.pkl/arrays-index-9.pk 
b/testsuite/poke.pkl/arrays-index-9.pk
new file mode 100644
index 00000000..426fea20
--- /dev/null
+++ b/testsuite/poke.pkl/arrays-index-9.pk
@@ -0,0 +1,5 @@
+/* { dg-do run } */
+
+/* { dg-command {.set obase 10} } */
+/* { dg-command {["foo","x","bar"][0#B]} } */
+/* { dg-output {"foo"} } */
diff --git a/testsuite/poke.pkl/strings-index-3.pk 
b/testsuite/poke.pkl/strings-index-3.pk
new file mode 100644
index 00000000..dab29da9
--- /dev/null
+++ b/testsuite/poke.pkl/strings-index-3.pk
@@ -0,0 +1,5 @@
+/* { dg-do run } */
+
+/* { dg-command {.set obase 16} } */
+/* { dg-command {"foo"[0#KB]} } */
+/* { dg-output "0x66UB" } */
diff --git a/testsuite/poke.pkl/strings-index-4.pk 
b/testsuite/poke.pkl/strings-index-4.pk
new file mode 100644
index 00000000..9af00b4b
--- /dev/null
+++ b/testsuite/poke.pkl/strings-index-4.pk
@@ -0,0 +1,5 @@
+/* { dg-do run } */
+
+/* { dg-command {.set obase 16} } */
+/* { dg-command {"foo"[2#N]} } */
+/* { dg-output "0x6fUB" } */
diff --git a/testsuite/poke.pkl/strings-index-5.pk 
b/testsuite/poke.pkl/strings-index-5.pk
new file mode 100644
index 00000000..958b15dd
--- /dev/null
+++ b/testsuite/poke.pkl/strings-index-5.pk
@@ -0,0 +1,5 @@
+/* { dg-do run } */
+
+/* { dg-command {.set obase 16} } */
+/* { dg-command {try "foo"[3#B]; catch if E_out_of_bounds { print "caught\n"; 
} } } */
+/* { dg-output "caught" } */
-- 
2.30.2




reply via email to

[Prev in Thread] Current Thread [Next in Thread]