[squeak-dev] Retrying a message send

Igor Stasenko siguctua at gmail.com
Sun Apr 11 08:33:40 UTC 2010


suppose you having a method:

  <primitive: ... >
  self recompileAndRetry

a #recompileAndRetry should do following:
 1) recompile method #foo and install new version of #foo into class
 2) restart execution from callee of #foo, so that it will call the
same method again (but its renewed version)

This is similar to what debugger does, when you changing a method in
code pane and accepting it, except that it restarting a
context of called method, instead of restarting from a point where
caller context did a message send (and so, if a new method contains a
it will be called by VM).

Any ideas, how i can do (2) easily?

My own thoughts is following:

   | retryCtx retryMethod caller method rcvr |
   retryCtx := thisContext sender.
   caller := retryCtx sender.

   method := retryCtx method.
   "here we recompile a method, like following: "
   method := method methodClass recompile: method selector.

   "now we're resending the same message"
   args := Array new: method numArgs.
   1 to: args size do: [ :i |  args at: i put: (retryCtx tempAt: i) ].

   thisContext terminateTo: caller.
   ^ retryCtx receiver perform: method selector arguments: args

Best regards,
Igor Stasenko AKA sig.

More information about the Squeak-dev mailing list