<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Jan 21, 2014 at 2:26 AM, Frank Shearar <span dir="ltr"><<a href="mailto:frank.shearar@gmail.com" target="_blank">frank.shearar@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">On 20 January 2014 23:47, Eliot Miranda <<a href="mailto:eliot.miranda@gmail.com">eliot.miranda@gmail.com</a>> wrote:<br>
> Hi Frank,<br>
><br>
><br>
> On Mon, Jan 20, 2014 at 2:01 PM, Frank Shearar <<a href="mailto:frank.shearar@gmail.com">frank.shearar@gmail.com</a>><br>
> wrote:<br>
>><br>
>> I often use Blocks for holding tiny bits of state not worth<br>
>> formalising as a class. As a result, I often get this error because I<br>
>> also spend a lot of time developing in the Debugger.<br>
>><br>
>> Is the following a completely crazy idea?<br>
>><br>
>> self selectedContext activeHome ifNil: [ |ctxt|<br>
>> ctxt := self selectedContext.<br>
>> "look up ctxt method methodClass >> ctxt selector."<br>
>> "Save the code as normal"<br>
>> ctxt method become: ctxt method methodClass >> ctxt selector].<br>
><br>
><br>
> All but the last line is sane ;-) You can't expect a become: to do the<br>
> right thing. It'll leave the context's pc wrong, and perhaps its stack<br>
> pointer too. You're looking for<br>
><br>
> ctxt privRefreshWith: ctxt method methodClass >> ctxt selector<br>
><br>
> But what do you want to do? Are you rewriting a block as a block or as a<br>
> method? What yu have above will do the latter, not the former.<br>
<br>
</div>Surely the wrongness of the pc doesn't matter? When you<br>
edit-and-continue a method (as opposed to a block in a method), the<br>
"continue" part resumes at the start of the method. Unless you mean<br>
that, with this block, you'd need to position the pc _at the start of<br>
the block_, or similar?<br></blockquote><div><br></div><div>Right. That's what privRefresh does; reset the pc and the stack pointer to the relevant values for the beginning of the method or block.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
But the use case is this: I have a method that returns a block that<br>
generates values. I don't have the source to hand right now, but it<br>
goes something like this:<br>
<br>
makeGeneratorFrom: aSymbol<br>
| base current |<br>
base := aSymbol. current := -1.<br>
^ [current := current + 1.<br>
(base , current asStringg) asSymbol]<br>
<br>
and then in the class I can say<br>
genny := self makeGeneratorFrom: #z.<br>
{genny value. genny value} "=> {#z0. #z1}"<br>
<br>
If I see a bug - the deliberate #asStringg typo - the debugger pops<br>
up, I correct the code, and then can't save the change because<br>
#makeGeneratorFrom: isn't in the call stack. What I'd like is to (a)<br>
save my change at all (rather than copy all the source, open a<br>
Browser, find the right method, paste the source, accept), and (b)<br>
have execution continue with the new version of the block.<br>
<br>
(And a "wrinkle" (he says naively) is that to edit-and-continue here,<br>
the new BlockContext (or whatever) would need to have references to<br>
the variables closed over by the old BlockContext.)<br></blockquote><div><br></div><div>[BTW, BlockContext isn't used any more. Only MethodContext, which is now misnamed and should be renamed to Context. Block and method activations are differentiated by blocks having a non-nil closureOrNil inst var].</div>
<div><br></div><div><br></div><div>So the change to the method is easy, but replacing the activation more difficult, simply because of the necessary UI plumbing. BlockClosure>>asContextWithSender: does almost all you need (it doesn't push arguments) tio generate the activation. You'll have to figure otu how to plumb that nto the debugger.</div>
<div><br></div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Even if I can't edit-and-continue this, at the least I'd like to save<br>
the source from within the Debugger, and possibly abandon the Process.<br></blockquote><div><br></div><div>Sure. That's all about hacking out the warning in some way you can live with.</div><div><br></div><div>Please report back. This is intriguing :)</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<span class="HOEnZb"><font color="#888888"><br>
frank<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
>> You'd need to fiddle the stack pointer, but that you have to do anyway<br>
>> in edit-and-continue.<br>
>><br>
>> frank<br>
>><br>
><br>
><br>
><br>
> --<br>
> best,<br>
> Eliot<br>
<br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br>best,<div>Eliot</div>
</div></div>