[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: goops and memoization
From: |
Neil Jerram |
Subject: |
Re: goops and memoization |
Date: |
29 Nov 2002 23:31:51 +0000 |
User-agent: |
Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7 |
>>>>> "Neil" == Neil Jerram <address@hidden> writes:
Neil> If this is correct, the fix is to pass `x' through your memoizer just
Neil> before `goto nontoplevel_begin;', like this:
Neil> apply_cmethod: /* inputs: z, arg1 */
Neil> {
Neil> SCM formals = SCM_CMETHOD_FORMALS (z);
Neil> env = EXTEND_ENV (formals, arg1, SCM_CMETHOD_ENV (z));
Neil> x = SCM_CMETHOD_BODY (z);
Neil> x = memoize (x); /* ADDED */
Neil> goto nontoplevel_begin;
Neil> }
And to follow up immediately to myself ... actually this is suboptimal
because it means that even a cached method is memoized every time it
is called. (Also I was wrong about the lambda; the expression
returned by scm_memoize_method doesn't begin with a lambda.)
What we should really do is memoize before the method is installed
into the method cache. I think the place for this is in
compute-entry-with-cmethod in oop/goops/compile.scm: just before
`(cons entry place-holder)':
(define (compute-entry-with-cmethod methods types)
(or (code-table-lookup (slot-ref (car methods) 'code-table) types)
(let* ((method (car methods))
(place-holder (list #f))
(entry (append types place-holder)))
;; In order to handle recursion nicely, put the entry
;; into the code-table before compiling the method
(slot-set! (car methods) 'code-table
(cons entry (slot-ref (car methods) 'code-table)))
(let ((cmethod (compile-method methods types)))
(set-car! place-holder (car cmethod))
(set-cdr! place-holder (cdr cmethod)))
(set-cdr! (cdr place-holder) ; ADDED
(memoize (cdr place-holder))) ; ADDED
(cons entry place-holder))))
Neil
- Re: goops and memoization, (continued)
- Re: goops and memoization, Mikael Djurfeldt, 2002/11/20
- Re: goops and memoization, Mikael Djurfeldt, 2002/11/20
- Re: goops and memoization, Neil Jerram, 2002/11/21
- Re: goops and memoization, Mikael Djurfeldt, 2002/11/21
- Re: goops and memoization, Mikael Djurfeldt, 2002/11/21
- Re: goops and memoization, Neil Jerram, 2002/11/24
- Re: goops and memoization, Mikael Djurfeldt, 2002/11/24
- Re: goops and memoization, Neil Jerram, 2002/11/21
- Re: goops and memoization, Mikael Djurfeldt, 2002/11/21
- Re: goops and memoization, Neil Jerram, 2002/11/29
- Re: goops and memoization,
Neil Jerram <=
- Re: goops and memoization, Neil Jerram, 2002/11/21
- Re: goops and memoization, Dirk Herrmann, 2002/11/24