poke-devel
[Top][All Lists]
Advanced

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

[COMMITTED] pvm: new functions pvm_make_{signed,unsigned}_integral


From: Jose E. Marchesi
Subject: [COMMITTED] pvm: new functions pvm_make_{signed,unsigned}_integral
Date: Sun, 26 Dec 2021 20:51:25 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

2021-12-26  Jose E. Marchesi  <jemarch@gnu.org>

        * libpoke/pvm.h (pvm_make_signed_integral): New prototype.
        (pvm_make_unsigned_integral): Likewise.
        * libpoke/pvm-val.c (pvm_make_signed_integral): New function.
        (pvm_make_unsigned_integral): Likewise.
---
 ChangeLog         |  7 +++++++
 libpoke/pvm-val.c | 23 +++++++++++++++++++++++
 libpoke/pvm.h     |  8 +++++++-
 3 files changed, 37 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index 515ca918..b6b323da 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2021-12-26  Jose E. Marchesi  <jemarch@gnu.org>
 
+       * libpoke/pvm.h (pvm_make_signed_integral): New prototype.
+       (pvm_make_unsigned_integral): Likewise.
+       * libpoke/pvm-val.c (pvm_make_signed_integral): New function.
+       (pvm_make_unsigned_integral): Likewise.
+
+2021-12-26  Jose E. Marchesi  <jemarch@gnu.org>
+
        * libpoke/pkl-insn.def: Define PKL_INSN_SSETI.
        * libpoke/pvm.jitter (sseti): New instruction.
 
diff --git a/libpoke/pvm-val.c b/libpoke/pvm-val.c
index 07cbf651..fe617ae3 100644
--- a/libpoke/pvm-val.c
+++ b/libpoke/pvm-val.c
@@ -84,6 +84,29 @@ pvm_make_ulong (uint64_t value, int size)
   return PVM_MAKE_LONG_ULONG (value, size, PVM_VAL_TAG_ULONG);
 }
 
+
+pvm_val
+pvm_make_signed_integral (int64_t value, int size)
+{
+  assert (0 < size && size <= 64);
+
+  if (size <= 32)
+    return PVM_MAKE_INT ((int32_t) value, size);
+  else
+    return PVM_MAKE_LONG (value, size);
+}
+
+pvm_val
+pvm_make_unsigned_integral (uint64_t value, int size)
+{
+  assert (0 < size && size <= 64);
+
+  if (size <= 32)
+    return PVM_MAKE_UINT ((uint32_t) value, size);
+  else
+    return PVM_MAKE_ULONG (value, size);
+}
+
 static pvm_val_box
 pvm_make_box (uint8_t tag)
 {
diff --git a/libpoke/pvm.h b/libpoke/pvm.h
index 80e388d8..4c58696e 100644
--- a/libpoke/pvm.h
+++ b/libpoke/pvm.h
@@ -210,6 +210,13 @@ pvm_val pvm_make_long (int64_t value, int size);
 
 pvm_val pvm_make_ulong (uint64_t value, int size);
 
+/* Make signed and unsigned integral values.
+   SIZE is measured in bits and should be in the range 1 to 64.  */
+
+pvm_val pvm_make_signed_integral (int64_t value, int size);
+
+pvm_val pvm_make_unsigned_integral (uint64_t value, int size);
+
 /* Make a string PVM value.  */
 
 pvm_val pvm_make_string (const char *value);
@@ -373,7 +380,6 @@ void pvm_val_unmap (pvm_val val);
 pvm_val pvm_make_exception (int code, const char *name, int exit_status,
                             const char *location, const char *message);
 
-
 /* **************** The Run-Time Environment ****************  */
 
 /* The poke virtual machine (PVM) maintains a data structure called
-- 
2.11.0





reply via email to

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