poke-devel
[Top][All Lists]
Advanced

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

Re: [PATCH] Added struct functionality on pk-val


From: Konstantinos Chasialis
Subject: Re: [PATCH] Added struct functionality on pk-val
Date: Fri, 29 May 2020 01:31:23 +0300
User-agent: SquirrelMail/1.4.23 [email.uoa.gr]

Author: kostasch <sdi1600195@di.uoa.gr>
Date:   Thu May 29 01:27:25 2020

Sending this patch as a fix to the previous one after discussing with
jemarch on IRC.

* libpoke/pk-val.c: Fixed the struct interface
* libpoke/libpoke.h: Added the associative headers

diff --git a/libpoke/libpoke.h b/libpoke/libpoke.h
index 5289a310..8df50625 100644
--- a/libpoke/libpoke.h
+++ b/libpoke/libpoke.h
@@ -487,6 +487,111 @@ 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 ulong<64> PVM value specifying the number of fields
+   in the struct.  This can be ulong<64>0 for an empty struct.
+
+   NMETHODS is an ulong<64> PVM vlaue specifying the number of methods
+   in the struct.
+
+   TYPE is a type PVM value specifying the type of the array.
+
+   The fields and methods in the created struct are initialized to
+   PVM_NULL.*/
+
+pk_val pk_make_struct (pk_val nfields, pk_val nmethods, pk_val type);
+
+/* Get the number of fields of a struct. */
+
+pk_val pk_struct_nfields (pk_val sct);
+
+/* Get the number of methods in a struct.
+
+   SCT is the struct value. */
+
+pk_val pk_struct_nmethods (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>.  */
+
+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.  */
+
+void pk_struct_set_field_boffset (pk_val sct, uint64_t idx, pk_val offset);
+
+/* Get the NAME of the struct field.
+
+   SCT is the struct value.
+   IDX is the index of the field in the struct. */
+
+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. */
+
+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. */
+
+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. */
+
+void pk_struct_set_field_value (pk_val sct, uint64_t idx, pk_val value);
+
+/* Get the NAME of the struct method.
+
+   SCT is the struct value.
+   IDX is the index of the method in the struct. */
+
+pk_val pk_struct_method_name (pk_val sct, uint64_t idx);
+
+/* Set the NAME of the struct method.
+
+   SCT is the struct value.
+   IDX is the index of the method in the struct.
+   NAME is the string name for this method. */
+
+void pk_struct_set_method_name (pk_val sct, uint64_t idx, pk_val name);
+
+/* Get the VALUE of the struct method.
+
+   SCT is the struct value.
+   IDX is the index of the method in the struct. */
+
+pk_val pk_struct_method_value (pk_val sct, uint64_t idx);
+
+/* Set the VALUE of the struct method.
+
+   SCT is the struct value.
+   IDX is the index of the method in the struct.
+   VALUE is a PVM closure. */
+
+void pk_struct_set_method_value (pk_val sct, uint64_t idx, pk_val value);
+

diff --git a/libpoke/pk-val.c b/libpoke/pk-val.c
index 1722a4e6..4769f9b5 100644
--- a/libpoke/pk-val.c
+++ b/libpoke/pk-val.c
@@ -183,6 +183,74 @@ pk_type_code (pk_val val)
 }

 pk_val
+pk_make_struct (pk_val nfields, pk_val nmethods, pk_val type)
+{
+  return pvm_make_struct(nfields, nmethods, type);
+}
+
+pk_val
+pk_struct_nfields (pk_val sct)
+{
+  return PVM_VAL_SCT_NFIELDS (sct);
+}
+
+pk_val
+pk_struct_nmethods (pk_val sct)
+{
+  return PVM_VAL_SCT_NMETHODS (sct);
+}
+
+pk_val pk_struct_field_boffset (pk_val sct, uint64_t idx)
+{
+  return PVM_VAL_SCT_FIELD_OFFSET (sct, idx);
+}
+
+void pk_struct_set_field_boffset (pk_val sct, uint64_t idx, pk_val offset)
+{
+  PVM_VAL_SCT_FIELD_OFFSET (sct, idx) = offset;
+}
+
+pk_val pk_struct_field_name (pk_val sct, uint64_t idx)
+{
+  return PVM_VAL_SCT_FIELD_NAME (sct, idx);
+}
+
+void pk_struct_set_field_name (pk_val sct, uint64_t idx, pk_val name)
+{
+  PVM_VAL_SCT_FIELD_NAME (sct, idx) = name;
+}
+
+pk_val pk_struct_field_value (pk_val sct, uint64_t idx)
+{
+  return PVM_VAL_SCT_FIELD_VALUE (sct, idx);
+}
+
+void pk_struct_set_field_value (pk_val sct, uint64_t idx, pk_val value)
+{
+  PVM_VAL_SCT_FIELD_VALUE (sct, idx) = value;
+}
+
+pk_val pk_struct_method_name (pk_val sct, uint64_t idx)
+{
+  return PVM_VAL_SCT_METHOD_NAME (sct, idx);
+}
+
+void pk_struct_set_method_name (pk_val sct, uint64_t idx, pk_val name)
+{
+  PVM_VAL_SCT_METHOD_NAME (sct, idx) = name;
+}
+
+pk_val pk_struct_method_value (pk_val sct, uint64_t idx)
+{
+  return PVM_VAL_SCT_METHOD_VALUE (sct, idx);
+}
+
+void pk_struct_set_method_value (pk_val sct, uint64_t idx, pk_val value)
+{
+  PVM_VAL_SCT_METHOD_VALUE (sct, idx) = value;
+}
+




reply via email to

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