poke-devel
[Top][All Lists]
Advanced

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

[PATCH 3/3] pkl: Add array integrator


From: Mohammad-Reza Nabipoor
Subject: [PATCH 3/3] pkl: Add array integrator
Date: Sat, 8 Jan 2022 21:44:52 +0330

2022-01-08  Mohammad-Reza Nabipoor  <mnabipoor@gnu.org>

        * libpoke/pkl-ast.h (pkl_ast_type_integrable_p): New function.
        (struct pkl_ast_type): Add field for array integrator closure.
        (PKL_AST_TYPE_A_INTEGRATOR): New accessor macro.
        * libpoke/pkl-ast.c (pkl_ast_make_array_type): Add integrator field.
        (pkl_ast_type_integrable_p): New function.
        * libpoke/pkl-typify.c (pkl_typify1_ps_cast): Handle cast from
        array to integer.
        * libpoke/pkl-gen.c (pkl_gen_pr_decl): Add array integrator.
        (pkl_gen_pr_cast): Likewise.
        (pkl_gen_pr_type_array): Likewise.
        * libpoke/pkl-gen.pks (array_integrator): Add implementation of
        array integrator.
        * testsuite/poke.pkl/array-integ-1.pk: New test.
        * testsuite/poke.pkl/array-integ-1.pk: Likewise.
        * testsuite/poke.pkl/array-integ-2.pk: Likewise.
        * testsuite/poke.pkl/array-integ-3.pk: Likewise.
        * testsuite/poke.pkl/array-integ-4.pk: Likewise.
        * testsuite/poke.pkl/array-integ-5.pk: Likewise.
        * testsuite/poke.pkl/array-integ-6.pk: Likewise.
        * testsuite/poke.pkl/array-integ-7.pk: Likewise.
        * testsuite/poke.pkl/array-integ-8.pk: Likewise.
        * testsuite/poke.pkl/array-integ-9.pk: Likewise.
        * testsuite/poke.pkl/array-integ-10.pk: Likewise.
        * testsuite/poke.pkl/array-integ-11.pk: Likewise.
        * testsuite/poke.pkl/array-integ-12.pk: Likewise.
        * testsuite/poke.pkl/array-integ-13.pk: Likewise.
        * testsuite/poke.pkl/array-integ-14.pk: Likewise.
        * testsuite/poke.pkl/array-integ-15.pk: Likewise.
        * testsuite/poke.pkl/array-integ-16.pk: Likewise.
        * testsuite/poke.pkl/array-integ-17.pk: Likewise.
        * testsuite/poke.pkl/array-integ-18.pk: Likewise.
        * testsuite/poke.pkl/array-integ-19.pk: Likewise.
        * testsuite/poke.pkl/array-integ-20.pk: Likewise.
        * testsuite/poke.pkl/array-integ-21.pk: Likewise.
        * testsuite/poke.pkl/array-integ-22.pk: Likewise.
        * testsuite/poke.pkl/array-integ-23.pk: Likewise.
        * testsuite/poke.pkl/array-integ-24.pk: Likewise.
        * testsuite/poke.pkl/array-integ-25.pk: Likewise.
        * testsuite/poke.pkl/array-integ-26.pk: Likewise.
        * testsuite/poke.pkl/array-integ-27.pk: Likewise.
        * testsuite/poke.pkl/array-integ-28.pk: Likewise.
        * testsuite/poke.pkl/array-integ-29.pk: Likewise.
        * testsuite/poke.pkl/array-integ-30.pk: Likewise.
        * testsuite/poke.pkl/array-integ-31.pk: Likewise.
        * testsuite/poke.pkl/array-integ-32.pk: Likewise.
        * testsuite/poke.pkl/array-integ-33.pk: Likewise.
        * testsuite/poke.pkl/array-integ-34.pk: Likewise.
        * testsuite/Makefile.am (EXTRA_DIST): Update.
---
 ChangeLog                               |  51 +++++++++++
 libpoke/pkl-ast.c                       |  33 ++++++-
 libpoke/pkl-ast.h                       |  11 ++-
 libpoke/pkl-gen.c                       |  52 ++++++++++-
 libpoke/pkl-gen.pks                     | 109 ++++++++++++++++++++++++
 libpoke/pkl-typify.c                    |  31 ++++---
 testsuite/poke.pkl/array-integ-1.pk     |  10 +++
 testsuite/poke.pkl/array-integ-10.pk    |  10 +++
 testsuite/poke.pkl/array-integ-11.pk    |  10 +++
 testsuite/poke.pkl/array-integ-12.pk    |  10 +++
 testsuite/poke.pkl/array-integ-13.pk    |  10 +++
 testsuite/poke.pkl/array-integ-14.pk    |  10 +++
 testsuite/poke.pkl/array-integ-15.pk    |  10 +++
 testsuite/poke.pkl/array-integ-16.pk    |  10 +++
 testsuite/poke.pkl/array-integ-17.pk    |  10 +++
 testsuite/poke.pkl/array-integ-18.pk    |  10 +++
 testsuite/poke.pkl/array-integ-19.pk    |  10 +++
 testsuite/poke.pkl/array-integ-2.pk     |  10 +++
 testsuite/poke.pkl/array-integ-20.pk    |  10 +++
 testsuite/poke.pkl/array-integ-21.pk    |  10 +++
 testsuite/poke.pkl/array-integ-22.pk    |  10 +++
 testsuite/poke.pkl/array-integ-23.pk    |  10 +++
 testsuite/poke.pkl/array-integ-24.pk    |  10 +++
 testsuite/poke.pkl/array-integ-25.pk    |  10 +++
 testsuite/poke.pkl/array-integ-26.pk    |  10 +++
 testsuite/poke.pkl/array-integ-27.pk    |  10 +++
 testsuite/poke.pkl/array-integ-28.pk    |  10 +++
 testsuite/poke.pkl/array-integ-29.pk    |  10 +++
 testsuite/poke.pkl/array-integ-3.pk     |  10 +++
 testsuite/poke.pkl/array-integ-30.pk    |  19 +++++
 testsuite/poke.pkl/array-integ-31.pk    |  10 +++
 testsuite/poke.pkl/array-integ-32.pk    |  10 +++
 testsuite/poke.pkl/array-integ-33.pk    |  10 +++
 testsuite/poke.pkl/array-integ-34.pk    |  10 +++
 testsuite/poke.pkl/array-integ-4.pk     |  10 +++
 testsuite/poke.pkl/array-integ-5.pk     |  10 +++
 testsuite/poke.pkl/array-integ-6.pk     |  10 +++
 testsuite/poke.pkl/array-integ-7.pk     |  10 +++
 testsuite/poke.pkl/array-integ-8.pk     |  10 +++
 testsuite/poke.pkl/array-integ-9.pk     |  10 +++
 testsuite/poke.pkl/cast-array-diag-8.pk |   2 +-
 41 files changed, 619 insertions(+), 19 deletions(-)
 create mode 100644 testsuite/poke.pkl/array-integ-1.pk
 create mode 100644 testsuite/poke.pkl/array-integ-10.pk
 create mode 100644 testsuite/poke.pkl/array-integ-11.pk
 create mode 100644 testsuite/poke.pkl/array-integ-12.pk
 create mode 100644 testsuite/poke.pkl/array-integ-13.pk
 create mode 100644 testsuite/poke.pkl/array-integ-14.pk
 create mode 100644 testsuite/poke.pkl/array-integ-15.pk
 create mode 100644 testsuite/poke.pkl/array-integ-16.pk
 create mode 100644 testsuite/poke.pkl/array-integ-17.pk
 create mode 100644 testsuite/poke.pkl/array-integ-18.pk
 create mode 100644 testsuite/poke.pkl/array-integ-19.pk
 create mode 100644 testsuite/poke.pkl/array-integ-2.pk
 create mode 100644 testsuite/poke.pkl/array-integ-20.pk
 create mode 100644 testsuite/poke.pkl/array-integ-21.pk
 create mode 100644 testsuite/poke.pkl/array-integ-22.pk
 create mode 100644 testsuite/poke.pkl/array-integ-23.pk
 create mode 100644 testsuite/poke.pkl/array-integ-24.pk
 create mode 100644 testsuite/poke.pkl/array-integ-25.pk
 create mode 100644 testsuite/poke.pkl/array-integ-26.pk
 create mode 100644 testsuite/poke.pkl/array-integ-27.pk
 create mode 100644 testsuite/poke.pkl/array-integ-28.pk
 create mode 100644 testsuite/poke.pkl/array-integ-29.pk
 create mode 100644 testsuite/poke.pkl/array-integ-3.pk
 create mode 100644 testsuite/poke.pkl/array-integ-30.pk
 create mode 100644 testsuite/poke.pkl/array-integ-31.pk
 create mode 100644 testsuite/poke.pkl/array-integ-32.pk
 create mode 100644 testsuite/poke.pkl/array-integ-33.pk
 create mode 100644 testsuite/poke.pkl/array-integ-34.pk
 create mode 100644 testsuite/poke.pkl/array-integ-4.pk
 create mode 100644 testsuite/poke.pkl/array-integ-5.pk
 create mode 100644 testsuite/poke.pkl/array-integ-6.pk
 create mode 100644 testsuite/poke.pkl/array-integ-7.pk
 create mode 100644 testsuite/poke.pkl/array-integ-8.pk
 create mode 100644 testsuite/poke.pkl/array-integ-9.pk

diff --git a/ChangeLog b/ChangeLog
index 95ff7fc9..97c7712c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,54 @@
+2022-01-08  Mohammad-Reza Nabipoor  <mnabipoor@gnu.org>
+
+       * libpoke/pkl-ast.h (pkl_ast_type_integrable_p): New function.
+       (struct pkl_ast_type): Add field for array integrator closure.
+       (PKL_AST_TYPE_A_INTEGRATOR): New accessor macro.
+       * libpoke/pkl-ast.c (pkl_ast_make_array_type): Add integrator field.
+       (pkl_ast_type_integrable_p): New function.
+       * libpoke/pkl-typify.c (pkl_typify1_ps_cast): Handle cast from
+       array to integer.
+       * libpoke/pkl-gen.c (pkl_gen_pr_decl): Add array integrator.
+       (pkl_gen_pr_cast): Likewise.
+       (pkl_gen_pr_type_array): Likewise.
+       * libpoke/pkl-gen.pks (array_integrator): Add implementation of
+       array integrator.
+       * testsuite/poke.pkl/array-integ-1.pk: New test.
+       * testsuite/poke.pkl/array-integ-1.pk: Likewise.
+       * testsuite/poke.pkl/array-integ-2.pk: Likewise.
+       * testsuite/poke.pkl/array-integ-3.pk: Likewise.
+       * testsuite/poke.pkl/array-integ-4.pk: Likewise.
+       * testsuite/poke.pkl/array-integ-5.pk: Likewise.
+       * testsuite/poke.pkl/array-integ-6.pk: Likewise.
+       * testsuite/poke.pkl/array-integ-7.pk: Likewise.
+       * testsuite/poke.pkl/array-integ-8.pk: Likewise.
+       * testsuite/poke.pkl/array-integ-9.pk: Likewise.
+       * testsuite/poke.pkl/array-integ-10.pk: Likewise.
+       * testsuite/poke.pkl/array-integ-11.pk: Likewise.
+       * testsuite/poke.pkl/array-integ-12.pk: Likewise.
+       * testsuite/poke.pkl/array-integ-13.pk: Likewise.
+       * testsuite/poke.pkl/array-integ-14.pk: Likewise.
+       * testsuite/poke.pkl/array-integ-15.pk: Likewise.
+       * testsuite/poke.pkl/array-integ-16.pk: Likewise.
+       * testsuite/poke.pkl/array-integ-17.pk: Likewise.
+       * testsuite/poke.pkl/array-integ-18.pk: Likewise.
+       * testsuite/poke.pkl/array-integ-19.pk: Likewise.
+       * testsuite/poke.pkl/array-integ-20.pk: Likewise.
+       * testsuite/poke.pkl/array-integ-21.pk: Likewise.
+       * testsuite/poke.pkl/array-integ-22.pk: Likewise.
+       * testsuite/poke.pkl/array-integ-23.pk: Likewise.
+       * testsuite/poke.pkl/array-integ-24.pk: Likewise.
+       * testsuite/poke.pkl/array-integ-25.pk: Likewise.
+       * testsuite/poke.pkl/array-integ-26.pk: Likewise.
+       * testsuite/poke.pkl/array-integ-27.pk: Likewise.
+       * testsuite/poke.pkl/array-integ-28.pk: Likewise.
+       * testsuite/poke.pkl/array-integ-29.pk: Likewise.
+       * testsuite/poke.pkl/array-integ-30.pk: Likewise.
+       * testsuite/poke.pkl/array-integ-31.pk: Likewise.
+       * testsuite/poke.pkl/array-integ-32.pk: Likewise.
+       * testsuite/poke.pkl/array-integ-33.pk: Likewise.
+       * testsuite/poke.pkl/array-integ-34.pk: Likewise.
+       * testsuite/Makefile.am (EXTRA_DIST): Update.
+
 2022-01-08  Mohammad-Reza Nabipoor  <mnabipoor@gnu.org>
 
        * libpoke/pkl-gen.pks (struct_field_inserter): Use `zero_extend_64`.
diff --git a/libpoke/pkl-ast.c b/libpoke/pkl-ast.c
index 86944065..78f88c06 100644
--- a/libpoke/pkl-ast.c
+++ b/libpoke/pkl-ast.c
@@ -371,7 +371,8 @@ pkl_ast_make_array_type (pkl_ast ast, pkl_ast_node etype, 
pkl_ast_node bound)
 {
   pkl_ast_node type = pkl_ast_make_type (ast);
   const int nclosures
-      = 6; /* mapper, writer, bounder, constructor, printer, formater. */
+      = 7; /* mapper, writer, bounder, constructor, integrator, printer,
+              formater. */
 
   assert (etype);
 
@@ -387,6 +388,7 @@ pkl_ast_make_array_type (pkl_ast ast, pkl_ast_node etype, 
pkl_ast_node bound)
   PKL_AST_TYPE_A_WRITER (type) = PVM_NULL;
   PKL_AST_TYPE_A_BOUNDER (type) = PVM_NULL;
   PKL_AST_TYPE_A_CONSTRUCTOR (type) = PVM_NULL;
+  PKL_AST_TYPE_A_INTEGRATOR (type) = PVM_NULL;
   PKL_AST_TYPE_A_FORMATER (type) = PVM_NULL;
   PKL_AST_TYPE_A_PRINTER (type) = PVM_NULL;
 
@@ -948,6 +950,35 @@ pkl_ast_type_promoteable_p (pkl_ast_node ft, pkl_ast_node 
tt,
   return 0;
 }
 
+/* Return whether the type TYPE is integrable or not.  */
+
+int
+pkl_ast_type_integrable_p (pkl_ast_node type)
+{
+  if (PKL_AST_TYPE_CODE (type) == PKL_TYPE_INTEGRAL)
+    return 1;
+  if (PKL_AST_TYPE_CODE (type) == PKL_TYPE_ARRAY)
+    {
+      pkl_ast_node etype = PKL_AST_TYPE_A_ETYPE (type);
+
+      switch (PKL_AST_TYPE_CODE (etype))
+        {
+        case PKL_TYPE_INTEGRAL:
+          return 1;
+        case PKL_TYPE_ARRAY:
+        case PKL_TYPE_STRUCT:
+          return pkl_ast_type_integrable_p (etype);
+        default:
+          return 0;
+        }
+    }
+  /* Integral structs are integrable.  */
+  if (PKL_AST_TYPE_CODE (type) == PKL_TYPE_STRUCT
+      && PKL_AST_TYPE_S_ITYPE (type) != NULL)
+    return 1;
+  return 0;
+}
+
 /* Build and return an expression that computes the size of TYPE in
    bits, as an unsigned 64-bit value.  */
 
diff --git a/libpoke/pkl-ast.h b/libpoke/pkl-ast.h
index 31066b9e..ee003e9d 100644
--- a/libpoke/pkl-ast.h
+++ b/libpoke/pkl-ast.h
@@ -852,8 +852,8 @@ pkl_ast_node pkl_ast_make_func_type_arg (pkl_ast ast,
    to an integer.  If the array type is bounded by size, then BOUND is
    an expression that must evaluate to an offset.  If the array type
    is unbounded, then BOUND is NULL.  MAPPER, WRITER, FORMATER,
-   PRINTER, CONSTRUCTOR and BOUNDCLS are used to hold closures, or
-   PVM_NULL. The field LEX_CORRECTED is used by the transl phase, to
+   PRINTER, CONSTRUCTOR, INTEGRATOR and BOUNDCLS are used to hold closures,
+   or PVM_NULL. The field LEX_CORRECTED is used by the transl phase, to
    keep record of array types that have been lexically corrected; this
    is to avoid processing the same type more than once.
 
@@ -863,7 +863,7 @@ pkl_ast_node pkl_ast_make_func_type_arg (pkl_ast ast,
    PKL_AST_STRUCT_TYPE_FIELD or PKL_AST_DECL nodes, potentially mixed.
    PINNED_P is 1 if the struct is pinned, 0 otherwise.  MAPPER, WRITER
    CONSTRUCTOR, FORMATER, PRINTER, COMPARATOR, INTEGRATOR and
-   DEINTEGRATOR are used to hold closures, or PVM_NULL.  INT_TYPE, if
+   DEINTEGRATOR are used to hold closures, or PVM_NULL.  ITYPE, if
    not NULL, is an AST node with an integral type, that defines the
    nature of this struct type as integral.
 
@@ -900,6 +900,7 @@ pkl_ast_node pkl_ast_make_func_type_arg (pkl_ast ast,
 #define PKL_AST_TYPE_A_CONSTRUCTOR(AST) ((AST)->type.val.array.closures[3])
 #define PKL_AST_TYPE_A_PRINTER(AST) ((AST)->type.val.array.closures[4])
 #define PKL_AST_TYPE_A_FORMATER(AST) ((AST)->type.val.array.closures[5])
+#define PKL_AST_TYPE_A_INTEGRATOR(AST) ((AST)->type.val.array.closures[6])
 #define PKL_AST_TYPE_S_NFIELD(AST) ((AST)->type.val.sct.nfield)
 #define PKL_AST_TYPE_S_NDECL(AST) ((AST)->type.val.sct.ndecl)
 #define PKL_AST_TYPE_S_NELEM(AST) ((AST)->type.val.sct.nelem)
@@ -950,7 +951,7 @@ struct pkl_ast_type
       union pkl_ast_node *bound;
       union pkl_ast_node *etype;
       /* Uncollectable array for MAPPER, BOUNDER, WRITER, CONSTRUCTOR,
-         PRINTER and FORMATER.  */
+         INTEGRATOR, PRINTER and FORMATER.  */
       pvm_val *closures;
     } array;
 
@@ -1021,6 +1022,8 @@ int pkl_ast_type_is_exception (pkl_ast_node type);
 int pkl_ast_type_promoteable_p (pkl_ast_node ft, pkl_ast_node tt,
                                 int promote_array_of_any);
 
+int pkl_ast_type_integrable_p (pkl_ast_node type);
+
 pkl_ast_node pkl_ast_sizeof_type (pkl_ast ast, pkl_ast_node type);
 
 size_t pkl_ast_sizeof_integral_type (pkl_ast_node type);
diff --git a/libpoke/pkl-gen.c b/libpoke/pkl-gen.c
index 846155ad..0d1bebbb 100644
--- a/libpoke/pkl-gen.c
+++ b/libpoke/pkl-gen.c
@@ -370,12 +370,29 @@ PKL_PHASE_BEGIN_HANDLER (pkl_gen_pr_decl)
                 PKL_GEN_POP_CONTEXT;
                 PKL_AST_TYPE_A_CONSTRUCTOR (array_type) = constructor_closure;
               }
-
             pkl_asm_insn (PKL_GEN_ASM, PKL_INSN_PUSH,
                           PKL_AST_TYPE_A_CONSTRUCTOR (array_type)); /* CLS */
             pkl_asm_insn (PKL_GEN_ASM, PKL_INSN_PEC);               /* CLS */
             pkl_asm_insn (PKL_GEN_ASM, PKL_INSN_DROP);              /* _ */
 
+            if (pkl_ast_type_integrable_p (array_type))
+              {
+                if (PKL_AST_TYPE_A_INTEGRATOR (array_type) == PVM_NULL)
+                  {
+                    pvm_val integrator_closure;
+
+                    PKL_GEN_PUSH_SET_CONTEXT (PKL_GEN_CTX_IN_INTEGRATOR);
+                    RAS_FUNCTION_ARRAY_INTEGRATOR (integrator_closure,
+                                                   array_type);
+                    PKL_GEN_POP_CONTEXT;
+                    PKL_AST_TYPE_A_INTEGRATOR (array_type) = 
integrator_closure;
+                  }
+                pkl_asm_insn (PKL_GEN_ASM, PKL_INSN_PUSH,
+                              PKL_AST_TYPE_A_INTEGRATOR (array_type)); /* CLS 
*/
+                pkl_asm_insn (PKL_GEN_ASM, PKL_INSN_PEC);              /* CLS 
*/
+                pkl_asm_insn (PKL_GEN_ASM, PKL_INSN_DROP);             /* _ */
+              }
+
             PKL_PASS_BREAK;
             break;
           }
@@ -2245,6 +2262,20 @@ PKL_PHASE_BEGIN_HANDLER (pkl_gen_pr_cast)
       pkl_asm_insn (pasm, PKL_INSN_NTON, itype, to_type);
       pkl_asm_insn (pasm, PKL_INSN_NIP);
     }
+  else if (PKL_AST_TYPE_CODE (from_type) == PKL_TYPE_ARRAY
+           && PKL_AST_TYPE_CODE (to_type) == PKL_TYPE_INTEGRAL)
+    {
+      PKL_GEN_PUSH_SET_CONTEXT (PKL_GEN_CTX_IN_INTEGRATOR);
+      PKL_PASS_SUBPASS (from_type);
+      PKL_GEN_POP_CONTEXT;
+
+                                          /* IVAL(ULONG) WIDTH(UINT) */
+      pkl_asm_insn (pasm, PKL_INSN_DROP); /* IVAL(ULONG) */
+      pkl_asm_insn (pasm, PKL_INSN_NTON,
+                    pkl_ast_make_integral_type (PKL_PASS_AST, 64, 0),
+                    to_type);             /* IVAL(ULONG) IVAL */
+      pkl_asm_insn (pasm, PKL_INSN_NIP);  /* IVAL */
+    }
   else
     assert (0);
 
@@ -3150,6 +3181,25 @@ PKL_PHASE_BEGIN_HANDLER (pkl_gen_pr_type_array)
       pkl_asm_insn (PKL_GEN_ASM, PKL_INSN_CALL); /* _ */
       PKL_PASS_BREAK;
     }
+  else if (PKL_GEN_IN_CTX_P (PKL_GEN_CTX_IN_INTEGRATOR))
+    {
+      /* Stack: ARR */
+
+      pkl_ast_node array_type = PKL_PASS_NODE;
+      pvm_val integrator_closure = PKL_AST_TYPE_A_INTEGRATOR (array_type);
+
+      /* If the array type doesn't have a integrator, compile one.  */
+      if (integrator_closure == PVM_NULL)
+        RAS_FUNCTION_ARRAY_INTEGRATOR (integrator_closure, array_type);
+      pkl_asm_insn (PKL_GEN_ASM, PKL_INSN_PUSH, integrator_closure); /* CLS */
+      if (!PKL_AST_TYPE_NAME (array_type))
+        pkl_asm_insn (PKL_GEN_ASM, PKL_INSN_PEC);                    /* CLS */
+
+      /* Invoke the integrator.  IVAL is either ULONG or an offset with
+         ULONG as the base type.  */
+      pkl_asm_insn (PKL_GEN_ASM, PKL_INSN_CALL); /* IVAL(ULONG) WIDTH(UINT) */
+      PKL_PASS_BREAK;
+    }
   else if (PKL_GEN_IN_CTX_P (PKL_GEN_CTX_IN_CONSTRUCTOR))
     {
       /* Stack: null */
diff --git a/libpoke/pkl-gen.pks b/libpoke/pkl-gen.pks
index 2b874788..600d70b3 100644
--- a/libpoke/pkl-gen.pks
+++ b/libpoke/pkl-gen.pks
@@ -460,6 +460,115 @@
    .c }
         .end
 
+;;; RAS_FUNCTION_ARRAY_INTEGRATOR @array_type
+;;; ( ARR -- IVAL(ULONG) IVALSZ(UINT) )
+;;;
+;;; Assemble a function that, given an integrable array, returns
+;;; the corresponding integral value and its width in bits.
+;;;
+;;; Macro-arguments:
+;;;
+;;; @type_array is a pkl_ast_node with the type of the array
+;;; passed in the stack.
+
+        .function array_integrator @array_type
+        prolog
+        pushf 3
+        siz                     ; ARR ARRSZ
+        push ulong<64>64        ; ARR ARRSZ 64
+        gtlu                    ; ARR ARRSZ 64 (ARRSZ>64)
+        bnzi .too_wide
+        drop3                   ; ARR
+        ;; We start from the most significant bit (BOFF) in a ulong<64>,
+        ;; and put integral value of elements there. On each iteration,
+        ;; we increase the BOFF by element size.
+        ;; +--------+--------------+-----+
+        ;; | Elem 1 | ... | Elem N |     |
+        ;; +--------+-----+--------+-----+
+        ;; ^                       ^
+        ;; BOFF at start (64)      BOFF at the end of loop
+        push ulong<64>0         ; ARR IVAL
+        push uint<32>64         ; ARR IVAL BOFF
+        .let @array_elem_type = PKL_AST_TYPE_A_ETYPE (@array_type)
+        regvar $boff            ; ARR IVAL
+        regvar $ival            ; ARR
+        sel                     ; ARR NELEM
+        regvar $nelem           ; ARR
+        push ulong<64>0         ; ARR IDX
+     .while
+        pushvar $nelem          ; ARR IDX NELEM
+        over                    ; ARR IDX NELEM IDX
+        swap                    ; ARR IDX IDX NELEM
+        ltlu                    ; ARR IDX IDX NELEM (IDX<NELEM)
+        nip2                    ; ARR IDX (IDX<NELEM)
+     .loop
+        aref                    ; ARR IDX ELEM
+   .c if (PKL_AST_TYPE_CODE (@array_elem_type) == PKL_TYPE_ARRAY
+   .c     || PKL_AST_TYPE_CODE (@array_elem_type) == PKL_TYPE_STRUCT)
+   .c {
+   .c   PKL_GEN_PUSH_SET_CONTEXT (PKL_GEN_CTX_IN_INTEGRATOR);
+   .c   PKL_PASS_SUBPASS (@array_elem_type);
+   .c   PKL_GEN_POP_CONTEXT;
+   .c }
+        ;; Integrator of arrays, leaves two values on the stack, the
+        ;; IVAL with type ulong<64> and WIDTH with type uint<32>.
+        ;; So we have to "fix" other cases (integers and integral structs).
+   .c if (PKL_AST_TYPE_CODE (@array_elem_type) == PKL_TYPE_INTEGRAL)
+   .c {
+        .e zero_extend_64 @array_elem_type
+        .let #elem_size \
+            = pvm_make_uint (PKL_AST_TYPE_I_SIZE (@array_elem_type), 32);
+        push #elem_size
+   .c }
+   .c else if (PKL_AST_TYPE_CODE (@array_elem_type) == PKL_TYPE_STRUCT)
+   .c {
+        .let @itype = PKL_AST_TYPE_S_ITYPE (@array_elem_type);
+        .e zero_extend_64 @itype
+        .let #elem_size = pvm_make_uint (                                     \
+            PKL_AST_TYPE_I_SIZE (PKL_AST_TYPE_S_ITYPE (@array_elem_type)),    \
+            32);
+        push #elem_size
+   .c }
+                                ; ARR IDX ELEM_UL ELEMSZ
+        pushvar $boff           ; ARR IDX ELEM_UL ELEMSZ BOFF
+        swap
+        subiu                   ; ARR IDX ELEM_UL BOFF ELEMSZ (BOFF-ELEMSZ)
+        nip2
+        dup                     ; ARR IDX ELEM_UL (BOFF-ELEMSZ) (BOFF-ELEMSZ)
+        quake                   ; ARR IDX (BOFF-ELEMSZ) ELEM_UL (BOFF-ELEMSZ)
+        bsllu
+        nip2                    ; ARR IDX (BOFF-ELEMSZ) (ELEM_UL<<BOFF)
+        pushvar $ival           ; ARR IDX (BOFF-ELEMSZ) (ELEM_UL<<BOFF) IVAL
+        borlu
+        nip2                    ; ARR IDX (BOFF-ELEMSZ) ((ELEM_UL<<BOFF)|IVAL)
+        popvar $ival            ; ARR IDX (BOFF-ELEMSZ)
+        popvar $boff            ; ARR IDX
+        push ulong<64>1
+        addlu
+        nip2
+     .endloop
+        drop2
+        pushvar $ival           ; IVAL
+        pushvar $boff           ; IVAL BOFF
+        ;; To create the final integral value (IVAL) and bit width (BOFF),
+        ;; we have to shift the IVAl to the right, and update the BOFF.
+        bsrlu                   ; IVAL BOFF (IVAL>>BOFF)
+        quake
+        nip                     ; BOFF (IVAL>>BOFF)
+        push uint<32>64         ; BOFF (IVAL>>BOFF) 64
+        rot                     ; (IVAL>>BOFF) 64 BOFF
+        subiu
+        nip2                    ; (IVAL>>BOFF) (BOFF-64)
+        popf 1
+        return
+.too_wide:
+        push PVM_E_CONV
+        push "msg"
+        push "arrays bigger than 64-bit cannot be casted to integral types"
+        sset
+        raise
+        .end
+
 ;;; RAS_MACRO_HANDLE_STRUCT_FIELD_LABEL @field
 ;;; ( BOFF SBOFF - BOFF )
 ;;;
diff --git a/libpoke/pkl-typify.c b/libpoke/pkl-typify.c
index 25fbff8c..1b9fad18 100644
--- a/libpoke/pkl-typify.c
+++ b/libpoke/pkl-typify.c
@@ -542,20 +542,27 @@ PKL_PHASE_BEGIN_HANDLER (pkl_typify1_ps_cast)
     }
 
   /* Arrays can only be casted to other arrays of the right type,
-     i.e. only array boundaries may differ.  */
-  if (PKL_AST_TYPE_CODE (exp_type) == PKL_TYPE_ARRAY
-      && !pkl_ast_type_equal_p (type, exp_type))
+     i.e. only array boundaries may differ, or if integrable to
+     integral types.  */
+  if (PKL_AST_TYPE_CODE (exp_type) == PKL_TYPE_ARRAY)
     {
-      char *type_str = pkl_type_str (type, 1);
-      char *found_type_str = pkl_type_str (exp_type, 1);
+      if (pkl_ast_type_equal_p (type, exp_type)
+          || ((PKL_AST_TYPE_CODE (type) == PKL_TYPE_INTEGRAL
+               && pkl_ast_type_integrable_p (exp_type))))
+        ;
+      else
+        {
+          char *type_str = pkl_type_str (type, 1);
+          char *found_type_str = pkl_type_str (exp_type, 1);
 
-      PKL_ERROR (PKL_AST_LOC (cast),
-                 "invalid cast\nexpected %s, got %s",
-                 type_str, found_type_str);
-      free (type_str);
-      free (found_type_str);
-      PKL_TYPIFY_PAYLOAD->errors++;
-      PKL_PASS_ERROR;
+          PKL_ERROR (PKL_AST_LOC (cast),
+                     "invalid cast\nexpected %s, got %s",
+                     type_str, found_type_str);
+          free (type_str);
+          free (found_type_str);
+          PKL_TYPIFY_PAYLOAD->errors++;
+          PKL_PASS_ERROR;
+        }
     }
 
  done:
diff --git a/testsuite/poke.pkl/array-integ-1.pk 
b/testsuite/poke.pkl/array-integ-1.pk
new file mode 100644
index 00000000..f1a20f49
--- /dev/null
+++ b/testsuite/poke.pkl/array-integ-1.pk
@@ -0,0 +1,10 @@
+/* { dg-do run } */
+
+var a = [0xffUB,0xffUB];
+
+/* { dg-command {.set obase 16} } */
+/* { dg-command {a as uint<16>} } */
+/* { dg-output {0xffffUH\n} } */
+/* { dg-command {[0xffUB,0xffUB] as uint<16>} } */
+/* { dg-output {0xffffUH} } */
+
diff --git a/testsuite/poke.pkl/array-integ-10.pk 
b/testsuite/poke.pkl/array-integ-10.pk
new file mode 100644
index 00000000..428337df
--- /dev/null
+++ b/testsuite/poke.pkl/array-integ-10.pk
@@ -0,0 +1,10 @@
+/* { dg-do run } */
+
+var a = [0x12UB,0x34UB,0x56UB];
+
+/* { dg-command {.set obase 16} } */
+/* { dg-command {a as uint<24>} } */
+/* { dg-output {\(uint<24>\) 0x123456\n} } */
+/* { dg-command {[0x12UB,0x34UB,0x56UB] as uint<24>} } */
+/* { dg-output {\(uint<24>\) 0x123456} } */
+
diff --git a/testsuite/poke.pkl/array-integ-11.pk 
b/testsuite/poke.pkl/array-integ-11.pk
new file mode 100644
index 00000000..90e0ac6f
--- /dev/null
+++ b/testsuite/poke.pkl/array-integ-11.pk
@@ -0,0 +1,10 @@
+/* { dg-do run } */
+
+var a = [0x12UB,0x34UB,0x56UB];
+
+/* { dg-command {.set obase 16} } */
+/* { dg-command {a as int<24>} } */
+/* { dg-output {\(int<24>\) 0x123456\n} } */
+/* { dg-command {[0x12UB,0x34UB,0x56UB] as int<24>} } */
+/* { dg-output {\(int<24>\) 0x123456} } */
+
diff --git a/testsuite/poke.pkl/array-integ-12.pk 
b/testsuite/poke.pkl/array-integ-12.pk
new file mode 100644
index 00000000..f5bf7bff
--- /dev/null
+++ b/testsuite/poke.pkl/array-integ-12.pk
@@ -0,0 +1,10 @@
+/* { dg-do run } */
+
+var a = [0x12UB,0x34UB,0x56UB,0x78UB];
+
+/* { dg-command {.set obase 16} } */
+/* { dg-command {a as uint<32>} } */
+/* { dg-output {0x12345678U\n} } */
+/* { dg-command {[0x12UB,0x34UB,0x56UB,0x78UB] as uint<32>} } */
+/* { dg-output {0x12345678U} } */
+
diff --git a/testsuite/poke.pkl/array-integ-13.pk 
b/testsuite/poke.pkl/array-integ-13.pk
new file mode 100644
index 00000000..39de6d47
--- /dev/null
+++ b/testsuite/poke.pkl/array-integ-13.pk
@@ -0,0 +1,10 @@
+/* { dg-do run } */
+
+var a = [0x12UB,0x34UB,0x56UB,0x78UB];
+
+/* { dg-command {.set obase 16} } */
+/* { dg-command {a as int<32>} } */
+/* { dg-output {0x12345678\n} } */
+/* { dg-command {[0x12UB,0x34UB,0x56UB,0x78UB] as int<32>} } */
+/* { dg-output {0x12345678} } */
+
diff --git a/testsuite/poke.pkl/array-integ-14.pk 
b/testsuite/poke.pkl/array-integ-14.pk
new file mode 100644
index 00000000..be464d03
--- /dev/null
+++ b/testsuite/poke.pkl/array-integ-14.pk
@@ -0,0 +1,10 @@
+/* { dg-do run } */
+
+var a = [0x12UB,0x34UB,0x56UB,0x78UB,0x9aUB];
+
+/* { dg-command {.set obase 16} } */
+/* { dg-command {a as uint<40>} } */
+/* { dg-output {\(uint<40>\) 0x123456789a\n} } */
+/* { dg-command {[0x12UB,0x34UB,0x56UB,0x78UB,0x9aUB] as uint<40>} } */
+/* { dg-output {\(uint<40>\) 0x123456789a} } */
+
diff --git a/testsuite/poke.pkl/array-integ-15.pk 
b/testsuite/poke.pkl/array-integ-15.pk
new file mode 100644
index 00000000..0bdd219c
--- /dev/null
+++ b/testsuite/poke.pkl/array-integ-15.pk
@@ -0,0 +1,10 @@
+/* { dg-do run } */
+
+var a = [0x12UB,0x34UB,0x56UB,0x78UB,0x9aUB];
+
+/* { dg-command {.set obase 16} } */
+/* { dg-command {a as int<40>} } */
+/* { dg-output {\(int<40>\) 0x123456789a\n} } */
+/* { dg-command {[0x12UB,0x34UB,0x56UB,0x78UB,0x9aUB] as int<40>} } */
+/* { dg-output {\(int<40>\) 0x123456789a} } */
+
diff --git a/testsuite/poke.pkl/array-integ-16.pk 
b/testsuite/poke.pkl/array-integ-16.pk
new file mode 100644
index 00000000..094167e8
--- /dev/null
+++ b/testsuite/poke.pkl/array-integ-16.pk
@@ -0,0 +1,10 @@
+/* { dg-do run } */
+
+var a = [[[[0x12UB]]],[[[0x34UB]]],[[[0x56UB]]],[[[0x78UB]]],[[[0x9aUB]]]];
+
+/* { dg-command {.set obase 16} } */
+/* { dg-command {a as uint<40>} } */
+/* { dg-output {\(uint<40>\) 0x123456789a\n} } */
+/* { dg-command 
{[[[[0x12UB]]],[[[0x34UB]]],[[[0x56UB]]],[[[0x78UB]]],[[[0x9aUB]]]] as 
uint<40>} } */
+/* { dg-output {\(uint<40>\) 0x123456789a} } */
+
diff --git a/testsuite/poke.pkl/array-integ-17.pk 
b/testsuite/poke.pkl/array-integ-17.pk
new file mode 100644
index 00000000..55b2a0db
--- /dev/null
+++ b/testsuite/poke.pkl/array-integ-17.pk
@@ -0,0 +1,10 @@
+/* { dg-do run } */
+
+var a = [[[[0x12UB]]],[[[0x34UB]]],[[[0x56UB]]],[[[0x78UB]]],[[[0x9aUB]]]];
+
+/* { dg-command {.set obase 16} } */
+/* { dg-command {a as int<40>} } */
+/* { dg-output {\(int<40>\) 0x123456789a\n} } */
+/* { dg-command 
{[[[[0x12UB]]],[[[0x34UB]]],[[[0x56UB]]],[[[0x78UB]]],[[[0x9aUB]]]] as int<40>} 
} */
+/* { dg-output {\(int<40>\) 0x123456789a} } */
+
diff --git a/testsuite/poke.pkl/array-integ-18.pk 
b/testsuite/poke.pkl/array-integ-18.pk
new file mode 100644
index 00000000..1b9abec9
--- /dev/null
+++ b/testsuite/poke.pkl/array-integ-18.pk
@@ -0,0 +1,10 @@
+/* { dg-do run } */
+
+var a = [0x12UB,0x34UB,0x56UB,0x78UB,0x9aUB,0xbcUB];
+
+/* { dg-command {.set obase 16} } */
+/* { dg-command {a as uint<48>} } */
+/* { dg-output {\(uint<48>\) 0x123456789abc\n} } */
+/* { dg-command {[0x12UB,0x34UB,0x56UB,0x78UB,0x9aUB,0xbcUB] as uint<48>} } */
+/* { dg-output {\(uint<48>\) 0x123456789abc} } */
+
diff --git a/testsuite/poke.pkl/array-integ-19.pk 
b/testsuite/poke.pkl/array-integ-19.pk
new file mode 100644
index 00000000..406652dd
--- /dev/null
+++ b/testsuite/poke.pkl/array-integ-19.pk
@@ -0,0 +1,10 @@
+/* { dg-do run } */
+
+var a = [0x12UB,0x34UB,0x56UB,0x78UB,0x9aUB,0xbcUB];
+
+/* { dg-command {.set obase 16} } */
+/* { dg-command {a as int<48>} } */
+/* { dg-output {\(int<48>\) 0x123456789abc\n} } */
+/* { dg-command {[0x12UB,0x34UB,0x56UB,0x78UB,0x9aUB,0xbcUB] as int<48>} } */
+/* { dg-output {\(int<48>\) 0x123456789abc} } */
+
diff --git a/testsuite/poke.pkl/array-integ-2.pk 
b/testsuite/poke.pkl/array-integ-2.pk
new file mode 100644
index 00000000..ecdeceb2
--- /dev/null
+++ b/testsuite/poke.pkl/array-integ-2.pk
@@ -0,0 +1,10 @@
+/* { dg-do run } */
+
+var a = [0xffUB,0x0fUB];
+
+/* { dg-command {.set obase 16} } */
+/* { dg-command {a as uint<16>} } */
+/* { dg-output {0xff0fUH\n} } */
+/* { dg-command {[0xffUB,0x0fUB] as uint<16>} } */
+/* { dg-output {0xff0fUH} } */
+
diff --git a/testsuite/poke.pkl/array-integ-20.pk 
b/testsuite/poke.pkl/array-integ-20.pk
new file mode 100644
index 00000000..629f082a
--- /dev/null
+++ b/testsuite/poke.pkl/array-integ-20.pk
@@ -0,0 +1,10 @@
+/* { dg-do run } */
+
+var a = [0x12UB,0x34UB,0x56UB,0x78UB,0x9aUB,0xbcUB,0xdeUB];
+
+/* { dg-command {.set obase 16} } */
+/* { dg-command {a as uint<56>} } */
+/* { dg-output {\(uint<56>\) 0x123456789abcde\n} } */
+/* { dg-command {[0x12UB,0x34UB,0x56UB,0x78UB,0x9aUB,0xbcUB,0xdeUB] as 
uint<56>} } */
+/* { dg-output {\(uint<56>\) 0x123456789abcde} } */
+
diff --git a/testsuite/poke.pkl/array-integ-21.pk 
b/testsuite/poke.pkl/array-integ-21.pk
new file mode 100644
index 00000000..67c3c6bf
--- /dev/null
+++ b/testsuite/poke.pkl/array-integ-21.pk
@@ -0,0 +1,10 @@
+/* { dg-do run } */
+
+var a = [0x12UB,0x34UB,0x56UB,0x78UB,0x9aUB,0xbcUB,0xdeUB,0xf0UB];
+
+/* { dg-command {.set obase 16} } */
+/* { dg-command {a as uint<64>} } */
+/* { dg-output {0x123456789abcdef0UL\n} } */
+/* { dg-command {[0x12UB,0x34UB,0x56UB,0x78UB,0x9aUB,0xbcUB,0xdeUB,0xf0UB] as 
uint<64>} } */
+/* { dg-output {0x123456789abcdef0UL} } */
+
diff --git a/testsuite/poke.pkl/array-integ-22.pk 
b/testsuite/poke.pkl/array-integ-22.pk
new file mode 100644
index 00000000..99ce1f86
--- /dev/null
+++ b/testsuite/poke.pkl/array-integ-22.pk
@@ -0,0 +1,10 @@
+/* { dg-do run } */
+
+var a = [0xffUB,0x0fUB];
+
+/* { dg-command {.set obase 16} } */
+/* { dg-command {a as uint<12>} } */
+/* { dg-output {\(uint<12>\) 0xf0f\n} } */
+/* { dg-command {[0xffUB,0x0fUB] as uint<12>} } */
+/* { dg-output {\(uint<12>\) 0xf0f} } */
+
diff --git a/testsuite/poke.pkl/array-integ-23.pk 
b/testsuite/poke.pkl/array-integ-23.pk
new file mode 100644
index 00000000..ecdeceb2
--- /dev/null
+++ b/testsuite/poke.pkl/array-integ-23.pk
@@ -0,0 +1,10 @@
+/* { dg-do run } */
+
+var a = [0xffUB,0x0fUB];
+
+/* { dg-command {.set obase 16} } */
+/* { dg-command {a as uint<16>} } */
+/* { dg-output {0xff0fUH\n} } */
+/* { dg-command {[0xffUB,0x0fUB] as uint<16>} } */
+/* { dg-output {0xff0fUH} } */
+
diff --git a/testsuite/poke.pkl/array-integ-24.pk 
b/testsuite/poke.pkl/array-integ-24.pk
new file mode 100644
index 00000000..99ce1f86
--- /dev/null
+++ b/testsuite/poke.pkl/array-integ-24.pk
@@ -0,0 +1,10 @@
+/* { dg-do run } */
+
+var a = [0xffUB,0x0fUB];
+
+/* { dg-command {.set obase 16} } */
+/* { dg-command {a as uint<12>} } */
+/* { dg-output {\(uint<12>\) 0xf0f\n} } */
+/* { dg-command {[0xffUB,0x0fUB] as uint<12>} } */
+/* { dg-output {\(uint<12>\) 0xf0f} } */
+
diff --git a/testsuite/poke.pkl/array-integ-25.pk 
b/testsuite/poke.pkl/array-integ-25.pk
new file mode 100644
index 00000000..5b91ca64
--- /dev/null
+++ b/testsuite/poke.pkl/array-integ-25.pk
@@ -0,0 +1,10 @@
+/* { dg-do run } */
+
+var a = ['1', '2', '3', '4'];
+
+/* { dg-command {.set obase 16} } */
+/* { dg-command {a as uint<32>} } */
+/* { dg-output {0x31323334U\n} } */
+/* { dg-command {['1', '2', '3', '4'] as uint<32>} } */
+/* { dg-output {0x31323334U} } */
+
diff --git a/testsuite/poke.pkl/array-integ-26.pk 
b/testsuite/poke.pkl/array-integ-26.pk
new file mode 100644
index 00000000..f19a23b7
--- /dev/null
+++ b/testsuite/poke.pkl/array-integ-26.pk
@@ -0,0 +1,10 @@
+/* { dg-do run } */
+
+var a = [[0xffUB,0xffUB],[0x00UB,0x00UB]];
+
+/* { dg-command {.set obase 16} } */
+/* { dg-command {a as uint<32>} } */
+/* { dg-output {0xffff0000U\n} } */
+/* { dg-command {[[0xffUB,0xffUB],[0x00UB,0x00UB]] as uint<32>} } */
+/* { dg-output {0xffff0000U} } */
+
diff --git a/testsuite/poke.pkl/array-integ-27.pk 
b/testsuite/poke.pkl/array-integ-27.pk
new file mode 100644
index 00000000..d0a6a2e2
--- /dev/null
+++ b/testsuite/poke.pkl/array-integ-27.pk
@@ -0,0 +1,10 @@
+/* { dg-do run } */
+
+var a = [[0xffUB,0x00UB],[0x00UB,0xffUB]];
+
+/* { dg-command {.set obase 16} } */
+/* { dg-command {a as uint<32>} } */
+/* { dg-output {0xff0000ffU\n} } */
+/* { dg-command {[[0xffUB,0x00UB],[0x00UB,0xffUB]] as uint<32>} } */
+/* { dg-output {0xff0000ffU} } */
+
diff --git a/testsuite/poke.pkl/array-integ-28.pk 
b/testsuite/poke.pkl/array-integ-28.pk
new file mode 100644
index 00000000..2259450b
--- /dev/null
+++ b/testsuite/poke.pkl/array-integ-28.pk
@@ -0,0 +1,10 @@
+/* { dg-do run } */
+
+var a = [[0xffUB,0x00UB],[0xffUB,0xffUB]];
+
+/* { dg-command {.set obase 16} } */
+/* { dg-command {a as uint<32>} } */
+/* { dg-output {0xff00ffffU\n} } */
+/* { dg-command {[[0xffUB,0x00UB],[0xffUB,0xffUB]] as uint<32>} } */
+/* { dg-output {0xff00ffffU} } */
+
diff --git a/testsuite/poke.pkl/array-integ-29.pk 
b/testsuite/poke.pkl/array-integ-29.pk
new file mode 100644
index 00000000..eb760115
--- /dev/null
+++ b/testsuite/poke.pkl/array-integ-29.pk
@@ -0,0 +1,10 @@
+/* { dg-do run } */
+
+var a = [1 as bit, 0 as bit, 1 as bit];
+
+/* { dg-command {.set obase 16} } */
+/* { dg-command {a as int<13>} } */
+/* { dg-output {\(int<13>\) 0x5\n} } */
+/* { dg-command {[1 as bit, 0 as bit, 1 as bit] as int<13>} } */
+/* { dg-output {\(int<13>\) 0x5} } */
+
diff --git a/testsuite/poke.pkl/array-integ-3.pk 
b/testsuite/poke.pkl/array-integ-3.pk
new file mode 100644
index 00000000..cd7b9702
--- /dev/null
+++ b/testsuite/poke.pkl/array-integ-3.pk
@@ -0,0 +1,10 @@
+/* { dg-do run } */
+
+var a = [0xffUB,0x0fUB];
+
+/* { dg-command {.set obase 16} } */
+/* { dg-command {a as int<16>} } */
+/* { dg-output {0xff0fH\n} } */
+/* { dg-command {[0xffUB,0x0fUB] as int<16>} } */
+/* { dg-output {0xff0fH} } */
+
diff --git a/testsuite/poke.pkl/array-integ-30.pk 
b/testsuite/poke.pkl/array-integ-30.pk
new file mode 100644
index 00000000..964490df
--- /dev/null
+++ b/testsuite/poke.pkl/array-integ-30.pk
@@ -0,0 +1,19 @@
+/* { dg-do run } */
+
+type T = struct int<32>
+  {
+    int<16> a;
+    int<16> b;
+  };
+var a = [T {a=0xdead,b=0xbeef}];
+
+/* { dg-command {.set obase 16} } */
+/* { dg-command {a as int<32>} } */
+/* { dg-output {0xdeadbeef\n} } */
+/* { dg-command {a as int<16>} } */
+/* { dg-output {0xbeefH\n} } */
+/* { dg-command {a as int<17>} } */
+/* { dg-output {\(int<17>\) 0x1beef\n} } */
+/* { dg-command {a as int<64>} } */
+/* { dg-output {0xdeadbeefL\n} } */
+
diff --git a/testsuite/poke.pkl/array-integ-31.pk 
b/testsuite/poke.pkl/array-integ-31.pk
new file mode 100644
index 00000000..15897904
--- /dev/null
+++ b/testsuite/poke.pkl/array-integ-31.pk
@@ -0,0 +1,10 @@
+/* { dg-do run } */
+
+var a = [5 as uint<3>, 7 as uint<3>, 5 as uint<3>];
+
+/* { dg-command {.set obase 16} } */
+/* { dg-command {a as int<9>} } */
+/* { dg-output {\(int<9>\) 0x17d\n} } */
+/* { dg-command {[5 as uint<3>, 7 as uint<3>, 5 as uint<3>] as int<9>} } */
+/* { dg-output {\(int<9>\) 0x17d} } */
+
diff --git a/testsuite/poke.pkl/array-integ-32.pk 
b/testsuite/poke.pkl/array-integ-32.pk
new file mode 100644
index 00000000..47899c75
--- /dev/null
+++ b/testsuite/poke.pkl/array-integ-32.pk
@@ -0,0 +1,10 @@
+/* { dg-do run } */
+
+var a = [[5 as uint<3>], [7 as uint<3>], [5 as uint<3>]];
+
+/* { dg-command {.set obase 16} } */
+/* { dg-command {a as int<9>} } */
+/* { dg-output {\(int<9>\) 0x17d\n} } */
+/* { dg-command {[[5 as uint<3>], [7 as uint<3>], [5 as uint<3>]] as int<9>} } 
*/
+/* { dg-output {\(int<9>\) 0x17d} } */
+
diff --git a/testsuite/poke.pkl/array-integ-33.pk 
b/testsuite/poke.pkl/array-integ-33.pk
new file mode 100644
index 00000000..838a77be
--- /dev/null
+++ b/testsuite/poke.pkl/array-integ-33.pk
@@ -0,0 +1,10 @@
+/* { dg-do run } */
+
+var a = [[[[[[[[0xdeadH,0xbeefH]]]]]]]];
+
+/* { dg-command {.set obase 16} } */
+/* { dg-command {a as int<32>} } */
+/* { dg-output {0xdeadbeef\n} } */
+/* { dg-command {[[[[[[[[0xdeadH,0xbeefH]]]]]]]] as int<32>} } */
+/* { dg-output {0xdeadbeef} } */
+
diff --git a/testsuite/poke.pkl/array-integ-34.pk 
b/testsuite/poke.pkl/array-integ-34.pk
new file mode 100644
index 00000000..40a4ee56
--- /dev/null
+++ b/testsuite/poke.pkl/array-integ-34.pk
@@ -0,0 +1,10 @@
+/* { dg-do run } */
+
+var a = [[[[[[[[0xdeadUH]]],[[[0xbabeUH]]]]]]]];
+
+/* { dg-command {.set obase 16} } */
+/* { dg-command {a as int<33>} } */
+/* { dg-output {\(int<33>\) 0xdeadbabe\n} } */
+/* { dg-command {[[[[[[[[0xdeadUH]]],[[[0xbabeUH]]]]]]]] as int<33>} } */
+/* { dg-output {\(int<33>\) 0xdeadbabe} } */
+
diff --git a/testsuite/poke.pkl/array-integ-4.pk 
b/testsuite/poke.pkl/array-integ-4.pk
new file mode 100644
index 00000000..d682f573
--- /dev/null
+++ b/testsuite/poke.pkl/array-integ-4.pk
@@ -0,0 +1,10 @@
+/* { dg-do run } */
+
+var a = [[0xffUB],[0xf0UB]];
+
+/* { dg-command {.set obase 16} } */
+/* { dg-command {a as uint<16>} } */
+/* { dg-output {0xfff0UH\n} } */
+/* { dg-command {[[0xffUB],[0xf0UB]] as uint<16>} } */
+/* { dg-output {0xfff0UH} } */
+
diff --git a/testsuite/poke.pkl/array-integ-5.pk 
b/testsuite/poke.pkl/array-integ-5.pk
new file mode 100644
index 00000000..ee58974b
--- /dev/null
+++ b/testsuite/poke.pkl/array-integ-5.pk
@@ -0,0 +1,10 @@
+/* { dg-do run } */
+
+var a = [[0xffUB],[0xf0UB]];
+
+/* { dg-command {.set obase 16} } */
+/* { dg-command {a as int<16>} } */
+/* { dg-output {0xfff0H\n} } */
+/* { dg-command {[[0xffUB],[0xf0UB]] as int<16>} } */
+/* { dg-output {0xfff0H} } */
+
diff --git a/testsuite/poke.pkl/array-integ-6.pk 
b/testsuite/poke.pkl/array-integ-6.pk
new file mode 100644
index 00000000..b479a132
--- /dev/null
+++ b/testsuite/poke.pkl/array-integ-6.pk
@@ -0,0 +1,10 @@
+/* { dg-do run } */
+
+var a = [0xffUB,0xffUB];
+
+/* { dg-command {.set obase 16} } */
+/* { dg-command {a as uint<12>} } */
+/* { dg-output {\(uint<12>\) 0xfff\n} } */
+/* { dg-command {[0xffUB,0xffUB] as uint<12>} } */
+/* { dg-output {\(uint<12>\) 0xfff} } */
+
diff --git a/testsuite/poke.pkl/array-integ-7.pk 
b/testsuite/poke.pkl/array-integ-7.pk
new file mode 100644
index 00000000..bc90af1c
--- /dev/null
+++ b/testsuite/poke.pkl/array-integ-7.pk
@@ -0,0 +1,10 @@
+/* { dg-do run } */
+
+var a = [0xffUB,0xffUB];
+
+/* { dg-command {.set obase 16} } */
+/* { dg-command {a as int<12>} } */
+/* { dg-output {\(int<12>\) 0xfff\n} } */
+/* { dg-command {[0xffUB,0xffUB] as int<12>} } */
+/* { dg-output {\(int<12>\) 0xfff} } */
+
diff --git a/testsuite/poke.pkl/array-integ-8.pk 
b/testsuite/poke.pkl/array-integ-8.pk
new file mode 100644
index 00000000..16433e77
--- /dev/null
+++ b/testsuite/poke.pkl/array-integ-8.pk
@@ -0,0 +1,10 @@
+/* { dg-do run } */
+
+var a = [0x00UB,0xaaUB];
+
+/* { dg-command {.set obase 16} } */
+/* { dg-command {a as uint<16>} } */
+/* { dg-output {0xaaUH\n} } */
+/* { dg-command {[0x00UB,0xaaUB] as uint<16>} } */
+/* { dg-output {0xaaUH} } */
+
diff --git a/testsuite/poke.pkl/array-integ-9.pk 
b/testsuite/poke.pkl/array-integ-9.pk
new file mode 100644
index 00000000..5255083d
--- /dev/null
+++ b/testsuite/poke.pkl/array-integ-9.pk
@@ -0,0 +1,10 @@
+/* { dg-do run } */
+
+var a = [0x00UB,0xaaUB];
+
+/* { dg-command {.set obase 16} } */
+/* { dg-command {a as int<16>} } */
+/* { dg-output {0xaaH\n} } */
+/* { dg-command {[0x00UB,0xaaUB] as int<16>} } */
+/* { dg-output {0xaaH} } */
+
diff --git a/testsuite/poke.pkl/cast-array-diag-8.pk 
b/testsuite/poke.pkl/cast-array-diag-8.pk
index ffb88e05..727e22de 100644
--- a/testsuite/poke.pkl/cast-array-diag-8.pk
+++ b/testsuite/poke.pkl/cast-array-diag-8.pk
@@ -1,3 +1,3 @@
 /* { dg-do compile } */
 
-var a = [1,2] as int; /* { dg-error "" } */
+var a = [1,2] as offset<int,B>; /* { dg-error "" } */
-- 
2.34.1




reply via email to

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