From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Neil Jerram Newsgroups: gmane.lisp.guile.devel Subject: Re: goops and memoization Date: 29 Nov 2002 23:31:51 +0000 Sender: guile-devel-admin@gnu.org Message-ID: References: NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: main.gmane.org 1038612967 3204 80.91.224.249 (29 Nov 2002 23:36:07 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Fri, 29 Nov 2002 23:36:07 +0000 (UTC) Cc: djurfeldt@nada.kth.se, guile-devel@gnu.org Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 18Hug0-0000pP-00 for ; Sat, 30 Nov 2002 00:36:04 +0100 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.10) id 18Huh1-0002lO-00; Fri, 29 Nov 2002 18:37:07 -0500 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.10) id 18HugA-00019q-00 for guile-devel@gnu.org; Fri, 29 Nov 2002 18:36:14 -0500 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.10) id 18Hug7-00017h-00 for guile-devel@gnu.org; Fri, 29 Nov 2002 18:36:13 -0500 Original-Received: from mail.uklinux.net ([80.84.72.21] helo=s1.uklinux.net) by monty-python.gnu.org with esmtp (Exim 4.10) id 18Hug6-00014u-00 for guile-devel@gnu.org; Fri, 29 Nov 2002 18:36:10 -0500 Original-Received: from laruns.ossau.uklinux.net (bts-0219.dialup.zetnet.co.uk [194.247.48.219]) by s1.uklinux.net (8.11.6/8.11.6) with ESMTP id gATNa5D22622; Fri, 29 Nov 2002 23:36:05 GMT Original-Received: from laruns.ossau.uklinux.net.ossau.uklinux.net (localhost [127.0.0.1]) by laruns.ossau.uklinux.net (Postfix on SuSE Linux 7.2 (i386)) with ESMTP id 75E69DC12B; Fri, 29 Nov 2002 23:31:51 +0000 (GMT) Original-To: Dirk Herrmann In-Reply-To: Original-Lines: 41 User-Agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7 Errors-To: guile-devel-admin@gnu.org X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.0.11 Precedence: bulk List-Help: List-Post: List-Subscribe: , List-Id: Developers list for Guile, the GNU extensibility library List-Unsubscribe: , List-Archive: Xref: main.gmane.org gmane.lisp.guile.devel:1764 X-Report-Spam: http://spam.gmane.org/gmane.lisp.guile.devel:1764 >>>>> "Neil" == Neil Jerram 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 _______________________________________________ Guile-devel mailing list Guile-devel@gnu.org http://mail.gnu.org/mailman/listinfo/guile-devel