[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Guile-commits] 53/88: goops.c no longer knows about <class> slot alloca
From: |
Andy Wingo |
Subject: |
[Guile-commits] 53/88: goops.c no longer knows about <class> slot allocation |
Date: |
Fri, 23 Jan 2015 15:25:48 +0000 |
wingo pushed a commit to branch master
in repository guile.
commit 2025a02793282b5548372939e43c72d13933853d
Author: Andy Wingo <address@hidden>
Date: Sun Jan 11 21:31:51 2015 +0100
goops.c no longer knows about <class> slot allocation
* libguile/goops.c (scm_class_of): Access "redefined" slot by name in
the case where we need to change the class of an instance.
(scm_sys_goops_early_init): Move up capture of class-precedence-list
so SCM_SUBCLASSP can use it.
* libguile/goops.h (SCM_CLASS_CLASS_LAYOUT, scm_si_redefined)
(scm_si_direct_supers, scm_si_direct_slots, scm_si_direct_subclasses)
(scm_si_direct_methods, scm_si_cpl scm_si_slots)
(scm_si_getters_n_setters, SCM_N_CLASS_SLOTS, SCM_OBJ_CLASS_REDEF):
Remove. Now C code has no special knowledge about the layout of
GOOPS classes.
(SCM_SUBCLASSP): Use scm_class_precedence_list to get CPL.
(SCM_INST, SCM_ACCESSORS_OF): Remove unused macros that were
undocumented and nonsensical.
---
libguile/goops.c | 17 +++++++++++------
libguile/goops.h | 32 ++------------------------------
2 files changed, 13 insertions(+), 36 deletions(-)
diff --git a/libguile/goops.c b/libguile/goops.c
index 070b6bc..aabd6ad 100644
--- a/libguile/goops.c
+++ b/libguile/goops.c
@@ -69,6 +69,7 @@
SCM_KEYWORD (k_name, "name");
SCM_KEYWORD (k_setter, "setter");
+SCM_SYMBOL (sym_redefined, "redefined");
SCM_GLOBAL_SYMBOL (scm_sym_args, "args");
static int goops_loaded_p = 0;
@@ -254,14 +255,16 @@ SCM_DEFINE (scm_class_of, "class-of", 1, 0, 0,
: SCM_IN_PCLASS_INDEX | SCM_PTOBNUM (x))];
case scm_tcs_struct:
if (SCM_OBJ_CLASS_FLAGS (x) & SCM_CLASSF_GOOPS_VALID)
+ /* A GOOPS object with a valid class. */
return SCM_CLASS_OF (x);
else if (SCM_OBJ_CLASS_FLAGS (x) & SCM_CLASSF_GOOPS)
+ /* A GOOPS object whose class might have been redefined. */
{
- /* Goops object */
- if (! scm_is_false (SCM_OBJ_CLASS_REDEF (x)))
- scm_change_object_class (x,
- SCM_CLASS_OF (x), /* old */
- SCM_OBJ_CLASS_REDEF (x)); /* new */
+ SCM class = SCM_CLASS_OF (x);
+ SCM new_class = scm_slot_ref (class, sym_redefined);
+ if (!scm_is_false (new_class))
+ scm_change_object_class (x, class, new_class);
+ /* Re-load class from instance. */
return SCM_CLASS_OF (x);
}
else
@@ -1060,6 +1063,9 @@ SCM_DEFINE (scm_sys_goops_early_init,
"%goops-early-init", 0, 0, 0,
var_make = scm_c_lookup ("make");
var_inherit_applicable = scm_c_lookup ("inherit-applicable!");
+ /* For SCM_SUBCLASSP. */
+ var_class_precedence_list = scm_c_lookup ("class-precedence-list");
+
var_slot_ref_using_class = scm_c_lookup ("slot-ref-using-class");
var_slot_set_using_class_x = scm_c_lookup ("slot-set-using-class!");
var_slot_bound_using_class_p = scm_c_lookup ("slot-bound-using-class?");
@@ -1159,7 +1165,6 @@ SCM_DEFINE (scm_sys_goops_loaded, "%goops-loaded", 0, 0,
0,
var_class_direct_slots = scm_c_lookup ("class-direct-slots");
var_class_direct_subclasses = scm_c_lookup ("class-direct-subclasses");
var_class_direct_methods = scm_c_lookup ("class-direct-methods");
- var_class_precedence_list = scm_c_lookup ("class-precedence-list");
var_class_slots = scm_c_lookup ("class-slots");
var_generic_function_methods = scm_c_lookup ("generic-function-methods");
diff --git a/libguile/goops.h b/libguile/goops.h
index f7233cb..fafd7fa 100644
--- a/libguile/goops.h
+++ b/libguile/goops.h
@@ -54,36 +54,7 @@
#define SCM_CLASSF_GOOPS SCM_VTABLE_FLAG_GOOPS_CLASS
#define SCM_CLASSF_GOOPS_OR_VALID (SCM_CLASSF_GOOPS | SCM_CLASSF_GOOPS_VALID)
-/*
- * scm_class_class
- */
-
-/* see also, SCM_VTABLE_BASE_LAYOUT, and build_class_class_slots */
-#define SCM_CLASS_CLASS_LAYOUT \
- "pw" /* redefined */ \
- "pw" /* direct supers */ \
- "pw" /* direct slots */ \
- "pw" /* direct subclasses */ \
- "pw" /* direct methods */ \
- "pw" /* cpl */ \
- "pw" /* slots */ \
- "pw" /* getters-n-setters */
-
-#define scm_si_redefined (scm_vtable_offset_user + 0)
-#define scm_si_direct_supers (scm_vtable_offset_user + 1) /* (class ...) */
-#define scm_si_direct_slots (scm_vtable_offset_user + 2) /* ((name .
options) ...) */
-#define scm_si_direct_subclasses (scm_vtable_offset_user + 3) /* (class ...) */
-#define scm_si_direct_methods (scm_vtable_offset_user + 4) /* (methods ...)
*/
-#define scm_si_cpl (scm_vtable_offset_user + 5) /* (class ...) */
-#define scm_si_slots (scm_vtable_offset_user + 6) /* ((name .
options) ...) */
-#define scm_si_getters_n_setters (scm_vtable_offset_user + 7)
-#define SCM_N_CLASS_SLOTS (scm_vtable_offset_user + 8)
-
-#define SCM_OBJ_CLASS_REDEF(x) (SCM_PACK (SCM_STRUCT_VTABLE_DATA (x)
[scm_si_redefined]))
-#define SCM_INST(x) SCM_STRUCT_DATA (x)
-
#define SCM_CLASS_OF(x) SCM_STRUCT_VTABLE (x)
-#define SCM_ACCESSORS_OF(x) (SCM_PACK (SCM_STRUCT_VTABLE_DATA
(x)[scm_si_getters_n_setters]))
#define SCM_CLASSP(x) \
(SCM_STRUCTP (x) && SCM_STRUCT_VTABLE_FLAGS (x) & SCM_CLASSF_METACLASS)
@@ -96,7 +67,8 @@
#define SCM_SLOT(x, i) (SCM_STRUCT_SLOT_REF (x, i))
#define SCM_SET_SLOT(x, i, v) (SCM_STRUCT_SLOT_SET (x, i, v))
-#define SCM_SUBCLASSP(c1, c2) (scm_is_true (scm_c_memq (c2, SCM_SLOT (c1,
scm_si_cpl))))
+#define SCM_SUBCLASSP(c1, c2) \
+ (scm_is_true (scm_c_memq (c2, scm_class_precedence_list (c1))))
#define SCM_IS_A_P(x, c) \
(SCM_INSTANCEP (x) && SCM_SUBCLASSP (SCM_CLASS_OF (x), c))
- [Guile-commits] 46/88: Minor goops.c tidying, (continued)
- [Guile-commits] 46/88: Minor goops.c tidying, Andy Wingo, 2015/01/23
- [Guile-commits] 37/88: goops: use computed class slot offsets; untabify and fix whitepace, Andy Wingo, 2015/01/23
- [Guile-commits] 50/88: Re-use the vtable "size" field for GOOPS nfields, Andy Wingo, 2015/01/23
- [Guile-commits] 52/88: Reimplement inherit-applicable! in Scheme, Andy Wingo, 2015/01/23
- [Guile-commits] 54/88: Incorporate %inherit-magic! into %init-layout!, Andy Wingo, 2015/01/23
- [Guile-commits] 49/88: Move <class> initialization to Scheme, Andy Wingo, 2015/01/23
- [Guile-commits] 56/88: GOOPS cleanup to use SRFI-1 better, Andy Wingo, 2015/01/23
- [Guile-commits] 57/88: append-map rather than mapappend, Andy Wingo, 2015/01/23
- [Guile-commits] 58/88: GOOPS utils module cleanups, Andy Wingo, 2015/01/23
- [Guile-commits] 55/88: Cosmetic goops refactors., Andy Wingo, 2015/01/23
- [Guile-commits] 53/88: goops.c no longer knows about <class> slot allocation,
Andy Wingo <=
- [Guile-commits] 61/88: scm_make cleanup, Andy Wingo, 2015/01/23
- [Guile-commits] 64/88: More GOOPS comments, Andy Wingo, 2015/01/23
- [Guile-commits] 59/88: Fold (oop goops util) into (oop goops), Andy Wingo, 2015/01/23
- [Guile-commits] 51/88: Reimplement %allocate-instance in Scheme, Andy Wingo, 2015/01/23
- [Guile-commits] 62/88: Narrative reordering in goops.scm, Andy Wingo, 2015/01/23
- [Guile-commits] 66/88: More GOOPS cleanups, Andy Wingo, 2015/01/23
- [Guile-commits] 67/88: Convert emit-linear-dispatch to use match, Andy Wingo, 2015/01/23
- [Guile-commits] 60/88: Add compute-cpl tests, Andy Wingo, 2015/01/23
- [Guile-commits] 72/88: change-object-class refactor, Andy Wingo, 2015/01/23
- [Guile-commits] 69/88: GOOPS class slot indices defined as inline values, Andy Wingo, 2015/01/23