fattigra remove_this mail.ru wrote:
> Yes, on VW ot work fine :)
> Method wrapper was ported to Dolphin 5 by Andres Otaduy
> (
http://www.smalltalking.net/goodies/Dolphin/ ).
>
> But... I not make ReplaceMethodWrapper and CallMethodWrapper. :-(
> Adding instance variable to subclass of MethodWrapper crash method
> wrapper behavior.
If those wrappers are based on my method wrappers, then they can
probably be modified to work with instance variables. The base problem
is that the VM is assuming that the method's literals start at some
offset from the object. When you add instance variables to a subclass
you are invalidating this assumption. Here are two different solutions
that work for VA and VSE, and could likely be adapted to work with Dolphin.
*) You get the compiler to insert an unused literal for each instance
variable at the beginning of the method's literals. You then create your
method wrapper object based on the compiler's CompiledMethod object, but
don't copy the unused literals at the beginning of the method. Your code
will see something like:
MyMethodWrapper
header=...
methodClass=...
selector=...
sourceDescriptor=...
byteCodes=...
myInstVar=???
1=...
2=...
However, the VM will see it as:
CompiledMethod
header=...
methodClass=...
selector=...
sourceDescriptor=...
byteCodes=...
1=???
2=...
3=...
*) The other approach is to create a MethodWrapper object separate from
the CompiledMethod object. Since your method wrappers are separate from
the compiled methods, the VM will not have problems with you adding
variables to the method wrappers -- they will just be some other object.
Now instead of inserting the method wrapper in the method dictionary,
you'll insert another CompiledMethod that just calls your method wrapper.
John Brant