Hi,
nowhereface doesn't seem like your real name, so anonymous...
There are two ways to do this. One is by using a special perform: in vw
that is undocumented and unsupported. Use at your own risk :)
Define this in Object:
perform: selector withArguments: anArray startingAbove: aBehavior
"Send the receiver the message indicated by the arguments, starting
the lookup in the superclass of aBehavior. The argument selector is
the selector of the message. The arguments of the message are the
elements of anArray. Invoke messageNotUnderstood: if the selector
is not understood by the receiver. Fail the primitive if aBehavior
is not the class of anObject or any of its superclasses, or if
anArray is not an Array with the same number of elements as the
number of arguments expected by the looked-up method."
<primitive: 515 errorCode: ec>
^self primitiveFailed
The other way would require you to define some syntax and modify the
compiler. The VW bytecode that implements super sends takes the class
in which to start the lookup as one of its arguments. So for example
super printOn: aStream
typically compiles to
1 <44> push self
2 <10> push local 0
3 <1C> push {TheClassInWhichThisMethodIsDefined}
4 <F2 21> super send printOn:
so the top of stack contains the class above which to begin the method
lookup.
As far as syntax goes, in the Borning Ingalls Smalltalk-80 multiple
inheritance scheme one could write directed sends as
self.ClassName foo
I'm not sure of the semantics anymore (its a long time ago) but it
probably didn't work the way you'd expect because the scheme relied
heavily on doesNotUnderstand: and method copying/selector-renaming.
But you could use this syntax and compile
self.ClassName foo
to
push self
push {Class named ClassName}
super send foo
The compiler could check that ClassName is a superclass. But a thorough
job would also put checks in the class builder because if ever the class
was moved out from under ClassName the VM could easily crash. The super
send bytecode doesn't check that the receiver inherits from the class
above which the lookup is to begin. This isn't a problem with super;
the class to start above is the class containing the method so ergo the
receiver must inherit. But with these directed sends that isn't
necessarily the case.
So buyer beware :)
HTH
nowheref
...@aol.com wrote:
> Consider this (simple enough) class heirarchy:
> Class1->Class2->Class3.
> In the above situation, Class2 overrode a method that was defined in
> Class1. Class3 inherited this overrode method from Class2, but it was
> inadequate -- what Class3 actually needed was the original Class1
> method which was just overrode in Class2. I found that I had to copy
> the method from Class1 down into Class3, which to me is a
> less-than-desirable solution.
> What I needed was an "arbitrary super" that would allow me to "skip a
> level" so to speak, by doing something on the order of a "super super,"
> or even a "super:2." Thus instead of copying an entire method down to
> Class3, I could have done something on the order of "self (super:2)
> method: object". I was told that this was simply not possible, and
> just to be happy with copying code down from Class1 to Class3.
> I believe that what I want to do is possible, just not something easily
> done in 5 minutes. Obviously the VM method binding engine binds
> methods, and searches class heirarchies in doing so. It seems to me
> that if I knew where to "poke around and look," I could possibly
> implement some sort of arbitrary super. My intuition tells me that
> this should not take an act of congress to do, but who knows --
> depending on the implementation I could be opening up a serious can of
> worms here (and probably am).
> Anyway, are there any virtual machine/method binding gurus out there
> that could sort of point me in a direction and give me some advice?
> I'm using VisualWorks 7.3.1, so I'd like advice on this particular
> product, but I assume this example would apply to any Smalltalk out
> there, and any general advice would be useful as well.
> Thanks..
--
_______________,,,^..^,,,____________________________
Eliot Miranda Smalltalk - Scene not herd