mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-04-30 03:40:34 +02:00
Struct vtables store bitmask of unboxed fields
* libguile/struct.h (scm_vtable_index_unboxed_fields): Allocate slot for bitmask of which fields are unboxed. (SCM_VTABLE_FLAG_SIMPLE, SCM_VTABLE_FLAG_SIMPLE_RW): Remove flags. Renumber other flags. (SCM_VTABLE_SIZE, SCM_STRUCT_SIZE): New helpers; long overdue. (SCM_VTABLE_UNBOXED_FIELDS, SCM_VTABLE_FIELD_IS_UNBOXED): (SCM_STRUCT_FIELD_IS_UNBOXED): New macros. * libguile/struct.c (set_vtable_access_fields): Rename from set_vtable_layout_flags, and initialize the unboxed flags bitmask instead of computing vtable flags. (scm_struct_init, scm_c_make_structv, scm_allocate_struct): Simplify. (scm_i_make_vtable_vtable): Adapt. (scm_i_struct_equalp, scm_struct_ref, scm_struct_set_x) (scm_struct_ref_unboxed, scm_struct_set_x_unboxed): Simplify. * libguile/vm-engine.c (VM_VALIDATE_BOXED_STRUCT_FIELD): (VM_VALIDATE_UNBOXED_STRUCT_FIELD): Adapt definitions. (struct-ref, struct-set!, struct-ref/immediate) (struct-set!/immediate): Simplify definitions. * libguile/hash.c (scm_i_struct_hash): Simplify. * libguile/goops.c (scm_sys_clear_fields_x): Simplify. * libguile/foreign-object.c (scm_make_foreign_object_n): (scm_foreign_object_unsigned_ref, scm_foreign_object_unsigned_set_x): Simplify.
This commit is contained in:
parent
f32500acca
commit
214e887dbd
6 changed files with 112 additions and 226 deletions
|
@ -227,36 +227,21 @@ static unsigned long scm_raw_ihash (SCM obj, size_t depth);
|
|||
static unsigned long
|
||||
scm_i_struct_hash (SCM obj, size_t depth)
|
||||
{
|
||||
SCM layout;
|
||||
scm_t_bits *data;
|
||||
size_t struct_size, field_num;
|
||||
unsigned long hash;
|
||||
|
||||
layout = SCM_STRUCT_LAYOUT (obj);
|
||||
struct_size = scm_i_symbol_length (layout) / 2;
|
||||
data = SCM_STRUCT_DATA (obj);
|
||||
struct_size = SCM_STRUCT_SIZE (obj);
|
||||
|
||||
hash = scm_raw_ihashq (SCM_UNPACK (SCM_STRUCT_VTABLE (obj)));
|
||||
if (depth > 0)
|
||||
for (field_num = 0; field_num < struct_size; field_num++)
|
||||
{
|
||||
int type;
|
||||
type = scm_i_symbol_ref (layout, field_num * 2);
|
||||
switch (type)
|
||||
{
|
||||
case 'p':
|
||||
hash ^= scm_raw_ihash (SCM_PACK (data[field_num]),
|
||||
depth / 2);
|
||||
break;
|
||||
case 'u':
|
||||
hash ^= scm_raw_ihashq (data[field_num]);
|
||||
break;
|
||||
default:
|
||||
abort ();
|
||||
}
|
||||
}
|
||||
|
||||
/* FIXME: Tail elements should be taken into account. */
|
||||
{
|
||||
for (field_num = 0; field_num < struct_size; field_num++)
|
||||
if (SCM_STRUCT_FIELD_IS_UNBOXED (obj, field_num))
|
||||
hash ^= scm_raw_ihashq (SCM_STRUCT_DATA_REF (obj, field_num));
|
||||
else
|
||||
hash ^= scm_raw_ihash (SCM_STRUCT_SLOT_REF (obj, field_num),
|
||||
depth / 2);
|
||||
}
|
||||
|
||||
return hash;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue