1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-24 20:30:28 +02:00

remove code-table slot from methods

* libguile/goops.c (scm_sys_invalidate_method_cache_x, scm_make)
  (create_standard_classes): Remove code-table slot from methods. The
  generic cache completely does its job, afaict.

* libguile/goops.h (scm_si_formals, scm_si_body, scm_si_make_procedure):
  Renumber slots.

* module/oop/goops.scm (initialize on <method>): No more code-table
  slot.

* module/oop/goops/compile.scm: Always "compile" a method, instead of
  looking for a hit in an always-empty cache.
This commit is contained in:
Andy Wingo 2009-11-05 12:54:41 +01:00
parent 6d33e90f0c
commit c40944c9ff
4 changed files with 8 additions and 43 deletions

View file

@ -1911,16 +1911,11 @@ SCM_DEFINE (scm_sys_invalidate_method_cache_x, "%invalidate-method-cache!", 1, 0
"") "")
#define FUNC_NAME s_scm_sys_invalidate_method_cache_x #define FUNC_NAME s_scm_sys_invalidate_method_cache_x
{ {
SCM methods, n;
SCM_ASSERT (SCM_PUREGENERICP (gf), gf, SCM_ARG1, FUNC_NAME); SCM_ASSERT (SCM_PUREGENERICP (gf), gf, SCM_ARG1, FUNC_NAME);
methods = SCM_SLOT (gf, scm_si_methods);
clear_method_cache (gf); clear_method_cache (gf);
for (; scm_is_pair (methods); methods = SCM_CDR (methods)) /* The sign of n-specialized is a flag indicating rest args. */
SCM_SET_SLOT (SCM_CAR (methods), scm_si_code_table, SCM_EOL); SCM_SET_MCACHE_N_SPECIALIZED (SCM_GENERIC_METHOD_CACHE (gf),
n = SCM_SLOT (gf, scm_si_n_specialized); SCM_SLOT (gf, scm_si_n_specialized));
/* The sign of n is a flag indicating rest args. */
SCM_SET_MCACHE_N_SPECIALIZED (SCM_GENERIC_METHOD_CACHE (gf), n);
return SCM_UNSPECIFIED; return SCM_UNSPECIFIED;
} }
#undef FUNC_NAME #undef FUNC_NAME
@ -2397,7 +2392,6 @@ SCM_DEFINE (scm_make, "make", 0, 0, 1,
len - 1, len - 1,
SCM_BOOL_F, SCM_BOOL_F,
FUNC_NAME)); FUNC_NAME));
SCM_SET_SLOT (z, scm_si_code_table, SCM_EOL);
SCM_SET_SLOT (z, scm_si_formals, SCM_SET_SLOT (z, scm_si_formals,
scm_i_get_keyword (k_formals, scm_i_get_keyword (k_formals,
args, args,
@ -2558,7 +2552,6 @@ create_standard_classes (void)
SCM method_slots = scm_list_n (scm_from_locale_symbol ("generic-function"), SCM method_slots = scm_list_n (scm_from_locale_symbol ("generic-function"),
scm_from_locale_symbol ("specializers"), scm_from_locale_symbol ("specializers"),
sym_procedure, sym_procedure,
scm_from_locale_symbol ("code-table"),
scm_from_locale_symbol ("formals"), scm_from_locale_symbol ("formals"),
scm_from_locale_symbol ("body"), scm_from_locale_symbol ("body"),
scm_from_locale_symbol ("make-procedure"), scm_from_locale_symbol ("make-procedure"),

View file

@ -186,10 +186,9 @@ typedef struct scm_t_method {
#define scm_si_generic_function 0 /* offset of gf slot in a <method> */ #define scm_si_generic_function 0 /* offset of gf slot in a <method> */
#define scm_si_specializers 1 /* offset of spec. slot in a <method> */ #define scm_si_specializers 1 /* offset of spec. slot in a <method> */
#define scm_si_procedure 2 /* offset of proc. slot in a <method> */ #define scm_si_procedure 2 /* offset of proc. slot in a <method> */
#define scm_si_code_table 3 /* offset of code. slot in a <method> */ #define scm_si_formals 3 /* offset of form. slot in a <method> */
#define scm_si_formals 4 /* offset of form. slot in a <method> */ #define scm_si_body 4 /* offset of body slot in a <method> */
#define scm_si_body 5 /* offset of body slot in a <method> */ #define scm_si_make_procedure 5 /* offset of makep.slot in a <method> */
#define scm_si_make_procedure 6 /* offset of makep.slot in a <method> */
/* C interface */ /* C interface */
SCM_API SCM scm_class_boolean; SCM_API SCM scm_class_boolean;

View file

@ -1517,7 +1517,6 @@
(slot-set! method 'specializers (get-keyword #:specializers initargs '())) (slot-set! method 'specializers (get-keyword #:specializers initargs '()))
(slot-set! method 'procedure (slot-set! method 'procedure
(get-keyword #:procedure initargs #f)) (get-keyword #:procedure initargs #f))
(slot-set! method 'code-table '())
(slot-set! method 'formals (get-keyword #:formals initargs '())) (slot-set! method 'formals (get-keyword #:formals initargs '()))
(slot-set! method 'body (get-keyword #:body initargs '())) (slot-set! method 'body (get-keyword #:body initargs '()))
(slot-set! method 'make-procedure (get-keyword #:make-procedure initargs #f))) (slot-set! method 'make-procedure (get-keyword #:make-procedure initargs #f)))

View file

@ -1,4 +1,4 @@
;;;; Copyright (C) 1999, 2001, 2006 Free Software Foundation, Inc. ;;;; Copyright (C) 1999, 2001, 2006, 2009 Free Software Foundation, Inc.
;;;; ;;;;
;;;; This library is free software; you can redistribute it and/or ;;;; This library is free software; you can redistribute it and/or
;;;; modify it under the terms of the GNU Lesser General Public ;;;; modify it under the terms of the GNU Lesser General Public
@ -28,32 +28,6 @@
:no-backtrace :no-backtrace
) )
;;;
;;; Method entries
;;;
(define code-table-lookup
(letrec ((check-entry (lambda (entry types)
(cond
((not (pair? entry)) (and (null? types) entry))
((null? types) #f)
(else
(and (eq? (car entry) (car types))
(check-entry (cdr entry) (cdr types))))))))
(lambda (code-table types)
(cond ((null? code-table) #f)
((check-entry (car code-table) types))
(else (code-table-lookup (cdr code-table) types))))))
(define (compute-cmethod methods types)
(or (code-table-lookup (slot-ref (car methods) 'code-table) types)
(let* ((method (car methods))
(cmethod (compile-method methods types))
(entry (append types cmethod)))
(slot-set! method 'code-table
(cons entry (slot-ref method 'code-table)))
cmethod)))
;;; ;;;
;;; Compiling next methods into method bodies ;;; Compiling next methods into method bodies
;;; ;;;
@ -70,7 +44,7 @@
;;; I think this whole generic application mess would benefit from a ;;; I think this whole generic application mess would benefit from a
;;; strict MOP. ;;; strict MOP.
(define (compile-method methods types) (define (compute-cmethod methods types)
(let ((make-procedure (slot-ref (car methods) 'make-procedure))) (let ((make-procedure (slot-ref (car methods) 'make-procedure)))
(if make-procedure (if make-procedure
(make-procedure (make-procedure