[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-smalltalk] MethodWrapper
From: |
Paolo Bonzini |
Subject: |
Re: [Help-smalltalk] MethodWrapper |
Date: |
Tue, 19 Oct 2010 11:16:20 +0200 |
User-agent: |
Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.9) Gecko/20100907 Fedora/3.1.3-1.fc13 Lightning/1.0b3pre Mnenhy/0.8.3 Thunderbird/3.1.3 |
On 10/19/2010 11:00 AM, Gwenaël Casaccio wrote:
> Hi,
>
> I've made (very) small patch for the VM to support methodWrapper.
> MethodWrapper are objects used to add behavior before and after
> the method evaluation.
>
> This patch ensure that the vm doesn't cast the object to the class format and
> thus having wrong ivar offset. It also avoids the method check.
>
> It is useful for pre and post conditions, test coverage.
>
> You could find the patch at
>
> git://github.com/MrGwen/smalltalk.git commit 660a66613e62f8d5236f
This is already supported (see examples/Methods.st), you only need
to subclass from CompiledMethod (you saw why :)) and create the
instance with the class method #numArgs:.
The method will be sent #valueWithReceiver:withArguments:.
examples/Methods.st even includes a basic port of MethodWrapper
itself. You need this to fix bitrot:
diff --git a/examples/Methods.st b/examples/Methods.st
index 67bdbcf..d80d9a6 100644
--- a/examples/Methods.st
+++ b/examples/Methods.st
@@ -45,6 +45,7 @@ test
"InterpretedMethod test"
| b |
b := Behavior new.
+ b superclass: Object.
b interpretedMethodAt: #testInterp1 put: #(#push 3 #push 4 #add #return).
b interpretedMethodAt: #testInterp2 put: #(#push 6 #push 7 #mul #return).
Transcript show: '3 + 4 = '. b new testInterp1 printNl.
Paolo