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 Gwen _______________________________________________ help-smalltalk mailing list [hidden email] http://lists.gnu.org/mailman/listinfo/help-smalltalk |
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 _______________________________________________ help-smalltalk mailing list [hidden email] http://lists.gnu.org/mailman/listinfo/help-smalltalk |
Good but shouldn't we put them in the kernel or a package ?
Also, we shouldn't inherit from CompiledCode (ok that's a detail) since this is a small patch. On Tue, Oct 19, 2010 at 11:16 AM, Paolo Bonzini <[hidden email]> wrote: > 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 > _______________________________________________ help-smalltalk mailing list [hidden email] http://lists.gnu.org/mailman/listinfo/help-smalltalk |
In reply to this post by Paolo Bonzini-2
Wow, thats cool!
Is it portable between dialects? Best, Dmitry 2010/10/19, Paolo Bonzini <[hidden email]>: > 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 > > _______________________________________________ > help-smalltalk mailing list > [hidden email] > http://lists.gnu.org/mailman/listinfo/help-smalltalk > _______________________________________________ help-smalltalk mailing list [hidden email] http://lists.gnu.org/mailman/listinfo/help-smalltalk |
In reply to this post by MrGwen
On 10/19/2010 11:25 AM, Gwenaël Casaccio wrote:
> Good but shouldn't we put them in the kernel or a package ? Your patch also didn't do that. :) > Also, we shouldn't inherit from CompiledCode (ok > that's a detail) since this is a small patch. Well, they have a MethodInfo with a selector and class, and a method header, so they are CompiledMethods. Paolo _______________________________________________ help-smalltalk mailing list [hidden email] http://lists.gnu.org/mailman/listinfo/help-smalltalk |
In reply to this post by Dmitry Matveev
On 10/19/2010 11:53 AM, Dmitry Matveev wrote:
> Wow, thats cool! > > Is it portable between dialects? The devil is in the details, but the basic ideas are there in all dialects. Paolo _______________________________________________ help-smalltalk mailing list [hidden email] http://lists.gnu.org/mailman/listinfo/help-smalltalk |
Free forum by Nabble | Edit this page |