[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] pk_struct interface for libpoke.
From: |
Jose E. Marchesi |
Subject: |
Re: [PATCH] pk_struct interface for libpoke. |
Date: |
Thu, 02 Jul 2020 23:05:49 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) |
Hi Kostas.
Hello, this is the pk_struct* interface for libpoke.
This is OK for master.
Thanks!
From: kostasch <sdi1600195@di.uoa.gr>
Date: Thu, 2 Jul 2020 23:48:20 +0300
Subject: [PATCH] pk_struct interface for libpoke.
2020-07-02 Kostas Chasialis <sdi1600195@di.uoa.gr>
* libpoke/libpoke.h (pk_make_struct): Prototype.
(pk_struct_nfields): Likewise.
(pk_struct_field_boffset): Likewise.
(pk_struct_set_field_boffset): Likewise.
(pk_struct_field_name): Likewise.
(pk_struct_set_field_name): Likewise.
(pk_struct_field_value): Likewise.
(pk_struct_set_field_value): Likewise.
* libpoke/pk-val.c (pk_make_struct): Define.
(pk_struct_nfields): Likewise.
(pk_struct_field_boffset): Likewise.
(pk_struct_set_field_boffset): Likewise.
(pk_struct_field_name): Likewise.
(pk_struct_set_field_name): Likewise.
(pk_struct_field_value): Likewise.
(pk_struct_set_field_value): Likewise.
---
ChangeLog | 19 ++++++++++
libpoke/libpoke.h | 89 ++++++++++++++++++++++++++++++++++++++++++++++-
libpoke/pk-val.c | 54 ++++++++++++++++++++++++++++
3 files changed, 161 insertions(+), 1 deletion(-)
diff --git a/ChangeLog b/ChangeLog
index 36fcdadb..8acc6882 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,22 @@
+2020-07-02 Kostas Chasialis <sdi1600195@di.uoa.gr>
+
+ * libpoke/libpoke.h (pk_make_struct): Prototype.
+ (pk_struct_nfields): Likewise.
+ (pk_struct_field_boffset): Likewise.
+ (pk_struct_set_field_boffset): Likewise.
+ (pk_struct_field_name): Likewise.
+ (pk_struct_set_field_name): Likewise.
+ (pk_struct_field_value): Likewise.
+ (pk_struct_set_field_value): Likewise.
+ * libpoke/pk-val.c (pk_make_struct): Define.
+ (pk_struct_nfields): Likewise.
+ (pk_struct_field_boffset): Likewise.
+ (pk_struct_set_field_boffset): Likewise.
+ (pk_struct_field_name): Likewise.
+ (pk_struct_set_field_name): Likewise.
+ (pk_struct_field_value): Likewise.
+ (pk_struct_set_field_value): Likewise.
+
2020-07-02 Kostas Chasialis <sdi1600195@di.uoa.gr>
* libpoke/libpoke.h (pk_array_elem_val): Prototype documentation
diff --git a/libpoke/libpoke.h b/libpoke/libpoke.h
index 7b2c6691..a0d4c23b 100644
--- a/libpoke/libpoke.h
+++ b/libpoke/libpoke.h
@@ -488,6 +488,93 @@ pk_val pk_offset_magnitude (pk_val val);
pk_val pk_offset_unit (pk_val val);
+/* Structs. */
+
+/* Build and return a poke struct.
+
+ NFIELDS is an uint<64> PK value specifying the number of fields
+ in the struct. This can be uint<64>0 for an empty struct.
+
+ TYPE is a type PK value specifying the type of the struct.
+
+ The fields and methods in the created struct are initialized to
+ PK_NULL.*/
+
+pk_val pk_make_struct (pk_val nfields, pk_val type);
+
+/* Get the number of fields of a struct. */
+
+pk_val pk_struct_nfields (pk_val sct);
+
+/* Get the bit-offset of the field of a struct, relative to the
+ beginning of the struct.
+
+ SCT is the struct value.
+ IDX is the index of the field in the struct.
+
+ The returned bit-offset is an uint<64>.
+
+ If IDX is invalid, PK_NULL is returned. */
+
+pk_val pk_struct_field_boffset (pk_val sct, uint64_t idx);
+
+/* Set the bit-offset of the field of an struct, relative to the
+ beginning of the struct.
+
+ ARRAY is the struct value.
+
+ IDX is the index of the field in the struct.
+
+ BOFFSET is an uint<64> value with the bit-offset of the field.
+
+ If IDX is invalid, struct remains unchanged. */
+
+void pk_struct_set_field_boffset (pk_val sct, uint64_t idx, pk_val
boffset);
+
+/* Get the NAME of the struct field.
+
+ SCT is the struct value.
+
+ IDX is the index of the field in the struct.
+
+ If IDX is invalid, PK_NULL is returned. */
+
+pk_val pk_struct_field_name (pk_val sct, uint64_t idx);
+
+/* Set the NAME of the struct field.
+
+ SCT is the struct value.
+
+ IDX is the index of the field in the struct.
+
+ NAME is the string name for this field.
+
+ If IDX is invalid, struct remains unchanged. */
+
+void pk_struct_set_field_name (pk_val sct, uint64_t idx, pk_val name);
+
+/* Get the VALUE of the struct field.
+
+ SCT is the struct value.
+
+ IDX is the index of the field in the struct.
+
+ If IDX is invalid, PK_NULL is returned. */
+
+pk_val pk_struct_field_value (pk_val sct, uint64_t idx);
+
+/* Set the VALUE of the struct field.
+
+ SCT is the struct value.
+
+ IDX is the index of the field in the struct.
+
+ VALUE is the new value for this field.
+
+ If IDX is invalid, struct remains unchanged. */
+
+void pk_struct_set_field_value (pk_val sct, uint64_t idx, pk_val value);
+
/* Arrays. */
/* Build and return a poke array.
@@ -629,7 +716,7 @@ pk_val pk_array_type_bound (pk_val type);
int pk_val_mapped_p (pk_val val);
/* Return the IOS identifier, an int<32>, in which the given value is
- mapped. If the value is not mapped, PK_NULL. */
+ mapped. If the value is not mapped, return PK_NULL. */
pk_val pk_val_ios (pk_val val);
diff --git a/libpoke/pk-val.c b/libpoke/pk-val.c
index 3c333911..e65b6f08 100644
--- a/libpoke/pk-val.c
+++ b/libpoke/pk-val.c
@@ -182,6 +182,60 @@ pk_type_code (pk_val val)
}
}
+pk_val
+pk_make_struct (pk_val nfields, pk_val type)
+{
+ return pvm_make_struct(nfields, pvm_make_ulong (0, 64), type);
+}
+
+pk_val
+pk_struct_nfields (pk_val sct)
+{
+ return PVM_VAL_SCT_NFIELDS (sct);
+}
+
+pk_val pk_struct_field_boffset (pk_val sct, uint64_t idx)
+{
+ if (idx < pk_uint_value (pk_struct_nfields (sct)))
+ return PVM_VAL_SCT_FIELD_OFFSET (sct, idx);
+ else
+ return PK_NULL;
+}
+
+void pk_struct_set_field_boffset (pk_val sct, uint64_t idx, pk_val boffset)
+{
+ if (idx < pk_uint_value (pk_struct_nfields (sct)))
+ PVM_VAL_SCT_FIELD_OFFSET (sct, idx) = boffset;
+}
+
+pk_val pk_struct_field_name (pk_val sct, uint64_t idx)
+{
+ if (idx < pk_uint_value (pk_struct_nfields (sct)))
+ return PVM_VAL_SCT_FIELD_NAME (sct, idx);
+ else
+ return PK_NULL;
+}
+
+void pk_struct_set_field_name (pk_val sct, uint64_t idx, pk_val name)
+{
+ if (idx < pk_uint_value (pk_struct_nfields (sct)))
+ PVM_VAL_SCT_FIELD_NAME (sct, idx) = name;
+}
+
+pk_val pk_struct_field_value (pk_val sct, uint64_t idx)
+{
+ if (idx < pk_uint_value (pk_struct_nfields (sct)))
+ return PVM_VAL_SCT_FIELD_VALUE (sct, idx);
+ else
+ return PK_NULL;
+}
+
+void pk_struct_set_field_value (pk_val sct, uint64_t idx, pk_val value)
+{
+ if (idx < pk_uint_value (pk_struct_nfields (sct)))
+ PVM_VAL_SCT_FIELD_VALUE (sct, idx) = value;
+}
+
pk_val
pk_make_array (pk_val nelem, pk_val array_type)
{