1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-04-30 11:50:28 +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:
Andy Wingo 2017-09-26 21:56:31 +02:00
parent f32500acca
commit 214e887dbd
6 changed files with 112 additions and 226 deletions

View file

@ -441,12 +441,12 @@
#define VM_VALIDATE_INDEX(u64, size, proc) \
VM_ASSERT (u64 < size, vm_error_out_of_range_uint64 (proc, u64))
#define VM_VALIDATE_BOXED_STRUCT_FIELD(layout, i, proc) \
VM_ASSERT (scm_i_symbol_ref (layout, i * 2) == 'p', \
#define VM_VALIDATE_BOXED_STRUCT_FIELD(obj, i, proc) \
VM_ASSERT (!SCM_STRUCT_FIELD_IS_UNBOXED (obj, i), \
vm_error_boxed_struct_field (proc, i))
#define VM_VALIDATE_UNBOXED_STRUCT_FIELD(obj, i, proc) \
VM_ASSERT (SCM_STRUCT_FIELD_IS_UNBOXED (obj, i), \
vm_error_boxed_struct_field (proc, i))
#define VM_VALIDATE_UNBOXED_STRUCT_FIELD(layout, i, proc) \
VM_ASSERT (scm_i_symbol_ref (layout, i * 2) == 'u', \
vm_error_unboxed_struct_field (proc, i))
/* Return true (non-zero) if PTR has suitable alignment for TYPE. */
#define ALIGNED_P(ptr, type) \
@ -2775,8 +2775,8 @@ VM_NAME (scm_i_thread *thread, struct scm_vm *vp,
VM_DEFINE_OP (108, struct_ref, "struct-ref", OP1 (X8_S8_S8_S8) | OP_DST)
{
scm_t_uint8 dst, src, idx;
SCM obj, vtable;
scm_t_uint64 index, nfields;
SCM obj;
scm_t_uint64 index;
UNPACK_8_8_8 (op, dst, src, idx);
@ -2784,11 +2784,8 @@ VM_NAME (scm_i_thread *thread, struct scm_vm *vp,
index = SP_REF_U64 (idx);
VM_VALIDATE_STRUCT (obj, "struct-ref");
vtable = SCM_STRUCT_VTABLE (obj);
nfields = SCM_STRUCT_DATA_REF (vtable, scm_vtable_index_size);
VM_VALIDATE_INDEX (index, nfields, "struct-ref");
VM_VALIDATE_BOXED_STRUCT_FIELD (SCM_VTABLE_LAYOUT (vtable),
index, "struct-ref");
VM_VALIDATE_INDEX (index, SCM_STRUCT_SIZE (obj), "struct-ref");
VM_VALIDATE_BOXED_STRUCT_FIELD (obj, index, "struct-ref");
RETURN (SCM_STRUCT_SLOT_REF (obj, index));
}
@ -2800,8 +2797,8 @@ VM_NAME (scm_i_thread *thread, struct scm_vm *vp,
VM_DEFINE_OP (109, struct_set, "struct-set!", OP1 (X8_S8_S8_S8))
{
scm_t_uint8 dst, idx, src;
SCM obj, vtable, val;
scm_t_uint64 index, nfields;
SCM obj, val;
scm_t_uint64 index;
UNPACK_8_8_8 (op, dst, idx, src);
@ -2810,11 +2807,8 @@ VM_NAME (scm_i_thread *thread, struct scm_vm *vp,
index = SP_REF_U64 (idx);
VM_VALIDATE_STRUCT (obj, "struct-set!");
vtable = SCM_STRUCT_VTABLE (obj);
nfields = SCM_STRUCT_DATA_REF (vtable, scm_vtable_index_size);
VM_VALIDATE_INDEX (index, nfields, "struct-set!");
VM_VALIDATE_BOXED_STRUCT_FIELD (SCM_VTABLE_LAYOUT (vtable),
index, "struct-set!");
VM_VALIDATE_INDEX (index, SCM_STRUCT_SIZE (obj), "struct-set!");
VM_VALIDATE_BOXED_STRUCT_FIELD (obj, index, "struct-set!");
SCM_STRUCT_SLOT_SET (obj, index, val);
NEXT (1);
@ -2848,8 +2842,8 @@ VM_NAME (scm_i_thread *thread, struct scm_vm *vp,
VM_DEFINE_OP (111, struct_ref_immediate, "struct-ref/immediate", OP1 (X8_S8_S8_C8) | OP_DST)
{
scm_t_uint8 dst, src, idx;
SCM obj, vtable;
scm_t_uint64 index, nfields;
SCM obj;
scm_t_uint64 index;
UNPACK_8_8_8 (op, dst, src, idx);
@ -2857,11 +2851,8 @@ VM_NAME (scm_i_thread *thread, struct scm_vm *vp,
index = idx;
VM_VALIDATE_STRUCT (obj, "struct-ref");
vtable = SCM_STRUCT_VTABLE (obj);
nfields = SCM_STRUCT_DATA_REF (vtable, scm_vtable_index_size);
VM_VALIDATE_INDEX (index, nfields, "struct-ref");
VM_VALIDATE_BOXED_STRUCT_FIELD (SCM_VTABLE_LAYOUT (vtable),
index, "struct-ref");
VM_VALIDATE_INDEX (index, SCM_STRUCT_SIZE (obj), "struct-ref");
VM_VALIDATE_BOXED_STRUCT_FIELD (obj, index, "struct-ref");
RETURN (SCM_STRUCT_SLOT_REF (obj, index));
}
@ -2874,8 +2865,8 @@ VM_NAME (scm_i_thread *thread, struct scm_vm *vp,
VM_DEFINE_OP (112, struct_set_immediate, "struct-set!/immediate", OP1 (X8_S8_C8_S8))
{
scm_t_uint8 dst, idx, src;
SCM obj, vtable, val;
scm_t_uint64 index, nfields;
SCM obj, val;
scm_t_uint64 index;
UNPACK_8_8_8 (op, dst, idx, src);
@ -2884,11 +2875,8 @@ VM_NAME (scm_i_thread *thread, struct scm_vm *vp,
index = idx;
VM_VALIDATE_STRUCT (obj, "struct-set!");
vtable = SCM_STRUCT_VTABLE (obj);
nfields = SCM_STRUCT_DATA_REF (vtable, scm_vtable_index_size);
VM_VALIDATE_INDEX (index, nfields, "struct-set!");
VM_VALIDATE_BOXED_STRUCT_FIELD (SCM_VTABLE_LAYOUT (vtable),
index, "struct-set!");
VM_VALIDATE_INDEX (index, SCM_STRUCT_SIZE (obj), "struct-set!");
VM_VALIDATE_BOXED_STRUCT_FIELD (obj, index, "struct-set!");
SCM_STRUCT_SLOT_SET (obj, index, val);
NEXT (1);