poke-devel
[Top][All Lists]
Advanced

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

[COMMITTED] libpoke: pk_typeof is the identity function when passed type


From: Jose E. Marchesi
Subject: [COMMITTED] libpoke: pk_typeof is the identity function when passed types
Date: Wed, 12 Jan 2022 11:49:31 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

2022-01-11  Jose E. Marchesi  <jemarch@gnu.org>

        * libpoke/pvm-val.c (pvm_typeof): If given a type value, return
        the value.
        * libpoke/pvm.jitter (typof): Change documentation accordingly.
        * libpoke/libpoke.h (pk_typeof): Likewise.
        * testsuite/poke.libpoke/values.c (test_pk_typeof): New function.
        (main): Call test_pk_typeof.
---
 ChangeLog                       |  9 +++++++++
 libpoke/libpoke.h               |  3 ++-
 libpoke/pvm-val.c               |  2 ++
 libpoke/pvm.jitter              |  3 ++-
 testsuite/poke.libpoke/values.c | 18 ++++++++++++++++++
 5 files changed, 33 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index ced3a8b0..b34f1b41 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,14 @@
 2022-01-11  Jose E. Marchesi  <jemarch@gnu.org>
 
+       * libpoke/pvm-val.c (pvm_typeof): If given a type value, return
+       the value.
+       * libpoke/pvm.jitter (typof): Change documentation accordingly.
+       * libpoke/libpoke.h (pk_typeof): Likewise.
+       * testsuite/poke.libpoke/values.c (test_pk_typeof): New function.
+       (main): Call test_pk_typeof.
+
+2022-01-11  Jose E. Marchesi  <jemarch@gnu.org>
+
        * poke/pk-cmd-vm.c (pk_cmd_vm_disas_fun): Likewise.
        * libpoke/pkl.c (pkl_execute_buffer): Get an argument exit_status.
        (pkl_execute_statement): Likewise.
diff --git a/libpoke/libpoke.h b/libpoke/libpoke.h
index 65c2b38d..dd164172 100644
--- a/libpoke/libpoke.h
+++ b/libpoke/libpoke.h
@@ -1027,7 +1027,8 @@ void pk_val_set_boffset (pk_val val, pk_val boffset) 
LIBPOKE_API;
 
 /* Other operations on values.  */
 
-/* Return the type of the given value.  */
+/* Return the type of the given value.  If the value is itself a type,
+   return it.  */
 
 pk_val pk_typeof (pk_val val) LIBPOKE_API;
 
diff --git a/libpoke/pvm-val.c b/libpoke/pvm-val.c
index 68ce272c..6ae2ea72 100644
--- a/libpoke/pvm-val.c
+++ b/libpoke/pvm-val.c
@@ -1619,6 +1619,8 @@ pvm_typeof (pvm_val val)
     type = PVM_VAL_ARR_TYPE (val);
   else if (PVM_IS_SCT (val))
     type = PVM_VAL_SCT_TYPE (val);
+  else if (PVM_IS_TYP (val))
+    type = val;
   else
     assert (0);
 
diff --git a/libpoke/pvm.jitter b/libpoke/pvm.jitter
index 69ad6383..1ff133fe 100644
--- a/libpoke/pvm.jitter
+++ b/libpoke/pvm.jitter
@@ -5472,7 +5472,8 @@ end
 
 # Instruction: typof
 #
-# Given a value, push its type on the stack.
+# Given a value that is not itself a type, push its type on the stack.
+# Given a value that is a type, push the value on the stack.
 #
 # Stack: ( VAL -- VAL TYPE )
 
diff --git a/testsuite/poke.libpoke/values.c b/testsuite/poke.libpoke/values.c
index bfe38106..9bed7da6 100644
--- a/testsuite/poke.libpoke/values.c
+++ b/testsuite/poke.libpoke/values.c
@@ -277,6 +277,23 @@ error:
 }
 
 void
+test_pk_typeof ()
+{
+  pk_val uint32_type = pk_make_integral_type (pk_make_uint (32, 64),
+                                              pk_make_int (1, 32));
+  pk_val res;
+
+  /* If given a type, pk_typeof should return the type itself.  */
+#define TEST "pk_typeof of uint<32>"
+  res = pk_typeof (uint32_type);
+  if (pk_val_equal_p (uint32_type, res))
+    pass (TEST);
+  else
+    fail (TEST);
+#undef TEST
+}
+
+void
 test_pk_val_equal_p ()
 {
   DIR *directory;
@@ -331,6 +348,7 @@ main (int argc, char *argv[])
   test_simple_values ();
   test_simple_values_mapping ();
   test_pk_val_equal_p ();
+  test_pk_typeof ();
 
   totals ();
   return 0;
-- 
2.11.0




reply via email to

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