<br><br><div class="gmail_quote">On Sun, Apr 11, 2010 at 1:33 AM, Igor Stasenko <span dir="ltr">&lt;<a href="mailto:siguctua@gmail.com">siguctua@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Hello,<br>
<br>
suppose you having a method:<br>
<br>
foo<br>
  &lt;primitive: ... &gt;<br>
  self recompileAndRetry<br>
<br>
<br>
a #recompileAndRetry should do following:<br>
 1) recompile method #foo and install new version of #foo into class<br>
 2) restart execution from callee of #foo, so that it will call the<br>
same method again (but its renewed version)<br>
<br>
<br>
This is similar to what debugger does, when you changing a method in<br>
code pane and accepting it, except that it restarting a<br>
context of called method, instead of restarting from a point where<br>
caller context did a message send (and so, if a new method contains a<br>
primitive,<br>
it will be called by VM).<br>
<br>
Any ideas, how i can do (2) easily?<br></blockquote><div><br></div><div>One trick is to return the result of compileAndRetry, e.g.</div><div><br></div><div><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; ">foo<br>
 &lt;primitive: ... &gt;<br> ^self recompileAndRetry</span></div><div><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse;"><br></span></font></div><div>
<font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse;">or e.g.</span></font></div><div><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse;"><br>
</span></font></div><div><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; ">foo<br> &lt;primitive: ... error: error&gt;<br> (self shouldRecompileAndRetry: error) ifTrue:</span></div>
<div><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; ">      [^self recompileAndRetry].</span></div><div><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse;">  self primitiveFailed</span></font></div>
<div> </div><div>you then don&#39;t need to worry about munging the stack to get it right.  You simply answer the result of tail-calling the primitive again at the end of recompileAndRetry.  That&#39;s what VisualWorks does with FFI and user primitive calls that can fail because they&#39;re not yet linked.  Searching for symbols in libraries and loading libraries is all done with image code invoked from e.g. ^self externalCallError: errorCode.</div>
<div><br></div><div>HTH</div><div>Eliot</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<br>
My own thoughts is following:<br>
<br>
recompileAndRetry<br>
   | retryCtx retryMethod caller method rcvr |<br>
   retryCtx := thisContext sender.<br>
   caller := retryCtx sender.<br>
<br>
   method := retryCtx method.<br>
   &quot;here we recompile a method, like following: &quot;<br>
   method := method methodClass recompile: method selector.<br>
<br>
   &quot;now we&#39;re resending the same message&quot;<br>
   args := Array new: method numArgs.<br>
   1 to: args size do: [ :i |  args at: i put: (retryCtx tempAt: i) ].<br>
<br>
<br>
   thisContext terminateTo: caller.<br>
   ^ retryCtx receiver perform: method selector arguments: args<br>
<font color="#888888"><br>
<br>
--<br>
Best regards,<br>
Igor Stasenko AKA sig.<br>
<br>
</font></blockquote></div><br>