wingo pushed a commit to branch wip-whippet
in repository guile.

commit 38c22e77a0b3df33b5a8a3412075eaa93be30a1a
Author: Andy Wingo <wi...@pobox.com>
AuthorDate: Mon Jun 30 14:49:35 2025 +0200

    Add new typed struct helpers to get size and unboxed fields
    
    * libguile/struct.h (scm_i_vtable_size):
    (scm_i_vtable_unboxed_fields): New helpers.
---
 libguile/struct.h | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/libguile/struct.h b/libguile/struct.h
index 38a4dcebb..2c473a13d 100644
--- a/libguile/struct.h
+++ b/libguile/struct.h
@@ -186,6 +186,18 @@ scm_i_struct_set_raw (struct scm_struct *x, size_t idx, 
scm_t_bits val)
 
 /* The SCM_VTABLE_* macros assume that you're passing them a struct which is a
    valid vtable. */
+static inline size_t
+scm_i_vtable_size (struct scm_struct *vtable)
+{
+  return scm_i_struct_ref_raw (vtable, scm_vtable_index_size);
+}
+
+static inline SCM
+scm_i_vtable_unboxed_fields (struct scm_struct *vtable)
+{
+  return scm_i_struct_ref_scm (vtable, scm_vtable_index_unboxed_fields);
+}
+
 #define SCM_VTABLE_LAYOUT(X)            (SCM_STRUCT_SLOT_REF ((X), 
scm_vtable_index_layout))
 #define SCM_SET_VTABLE_LAYOUT(X,L)      (SCM_STRUCT_SLOT_SET ((X), 
scm_vtable_index_layout, L))
 #define SCM_VTABLE_FLAGS(X)             (SCM_STRUCT_DATA_REF (X, 
scm_vtable_index_flags))
@@ -199,8 +211,8 @@ scm_i_struct_set_raw (struct scm_struct *x, size_t idx, 
scm_t_bits val)
 #define SCM_SET_VTABLE_INSTANCE_PRINTER(X,P) (SCM_STRUCT_SLOT_SET (X, 
scm_vtable_index_instance_printer, (P)))
 #define SCM_VTABLE_NAME(X)              (SCM_STRUCT_SLOT_REF (X, 
scm_vtable_index_name))
 #define SCM_SET_VTABLE_NAME(X,V)        (SCM_STRUCT_SLOT_SET (X, 
scm_vtable_index_name, V))
-#define SCM_VTABLE_SIZE(X)              (SCM_STRUCT_DATA_REF (X, 
scm_vtable_index_size))
-#define SCM_VTABLE_UNBOXED_FIELDS(X)    (SCM_STRUCT_SLOT_REF (X, 
scm_vtable_index_unboxed_fields))
+#define SCM_VTABLE_SIZE(X)              (scm_i_vtable_size (scm_to_struct (X)))
+#define SCM_VTABLE_UNBOXED_FIELDS(X)    (scm_i_vtable_unboxed_fields 
(scm_to_struct (X)))
 #define SCM_VTABLE_FIELD_IS_UNBOXED(X,F) (scm_is_true (scm_logbit_p 
(SCM_I_MAKINUM (F), SCM_VTABLE_UNBOXED_FIELDS (X))))
 
 #define SCM_STRUCT_VTABLE(X)            (SCM_PACK (SCM_CELL_WORD_0 (X) - 
scm_tc3_struct))

Reply via email to