[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Getting hold of the method object currently executed



  Redistributed: CommonLoops.PA
  Date: Wed, 15 Nov 89 09:51:13 EST
  From: Martin Boyer <gamin@moe.mcrcim.mcgill.edu>
  To: CommonLoops.PA@xerox.com
  Subject: Getting hold of the method object currently executed
  
  In Victoria Day PCL, is it possible, from the body of a method, to
  reference the method object itself?
  
Why do you want this?  Loop optimization?

  I could use something like
  
  (get-method generic-function () (mapcar 'find-class arglist))
  
  but that seems to be a waste of time since, being in the body of a method,
  it is obvious that the proper method has just been looked up.
  I guess I am more or less looking for a special variable that could
  be named *current-method* and that this variable would be bound by the
  generic dispatch mechanism.

You could just climb up the stack.  Here is Symbolics code:

(defun current-function ()
  (si:frame-function
    (si:frame-previous-active-frame (si:%stack-frame-pointer))))

(pcl:defmethod goo (x) (current-function))

  I tried looking for the call-method macro, but it doesn't seem to exist
  in Victoria Day PCL; the name is used, but the code is a bit too complex
  for a neophyte like me.

Here is a portable, but slow way to do it.
(defmethod generic-function-effective-method
  ((gf standard-generic-function) &rest args)
  ;; Returns a function that is the effective method when GF
  ;; is applied to ARGS.
  (cdr (last (apply #'lookup-method-internal gf
                    (generic-function-combined-methods gf)
		    #'car args))))

  
  I also thought of using a defadvice on get-method, to cache the return
  value, but it seems that some other mechanism (in dcode.lisp?) is
  used from within generic functions.
  
  I am willing to modify the PCL sources if somebody can give me pointers;
  this is really important for my application, and getting a bit pressing.
  
  Thanks a lot,
  
  Martin