<div dir="ltr"><div class="gmail_default" style="font-size:small">oops, 296 => 196</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Feb 12, 2023 at 7:53 AM Eliot Miranda <<a href="mailto:eliot.miranda@gmail.com">eliot.miranda@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="auto">Hi Jaromir,<div dir="ltr"><br><blockquote type="cite">On Feb 12, 2023, at 5:13 AM, Jaromir Matas <<a href="mailto:mail@jaromir.net" target="_blank">mail@jaromir.net</a>> wrote:<br><br></blockquote></div><blockquote type="cite"><div dir="ltr">






<div>
<p class="MsoNormal">Hi,</p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">>> What is the purpose of the primitive 196 Context>>#terminateTo:?
</p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">> Strongly related to prim 195 & 197. You have to check each context up the chain to see what exceptions might be dealt with & by which context.</p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">My understanding is prim 195 (#findNextUnwindContextUpTo:) searches for unwind contexts and prim 197 (#findNextHandlerContextStarting) searches for handler context. But prim 195 (#terminateTo:) is unclear to me. #terminateTo comment says:</p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">"Terminate all the Contexts between me and previousContext, if previousContext is on my Context stack. Make previousContext my sender."</p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Which doesn't say much except it's nilling all context's pc and sender between self and the argument. I wonder what else it does behind the scenes and why :)</p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">In a paper from 2009 Eliot wrote:</p>
<p class="MsoNormal">"[...] there’s a primitive terminateTo: that does something similar to the context nilling in non-local return. It is a little simpler than non-local return (although not much) but it is just a variation on the same theme so I’ll spare
 you."</p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">I wish Eliot didn't spare us :) Other than that I haven't found any further info.</p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Because the primitive 196 dates back to 2001 I'm unable to judge whether it's still essential to nil the intermediate contexts (to free stack pages or something).
</p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">In particular I'm trying to understand whether the use of #terminateTo *<b>primitive</b>* in #resumeEvaluating: and #resume:through: is essential or not.</p></div></div></blockquote><div><br></div>There are three things that primitive 296, Context>>terminateTo: does, or rather there are two things it does, and it does them in a particular way. It sets senders and pcs of intervening contexts to nil. It sets the sender of the receiver to the argument. If does this atomically.<div><br></div><div>I can’t say whether the last of these is necessary. If it is, then the primitive is needed, essential. But the primitive merely optimized the former two operations.</div><div><br></div><div>In the StackInterpreter & CoInterpreter it provides a significant optimization because</div><div><br></div><div>- the primitive avoids creating any contexts; if if were not implemented primitively then  contexts would have to be created for all intervening frames, merely to throw unreferenced ones away</div><div><br></div><div>- intervening stack pages can be freed without looking at their contents </div><div><br></div><div>So the primitive is an important optimization for Stack/CoInterpreter.</div><div><br></div><div>But I suspect that atomicity is not crucial and that therefore the terminateTo: primitive is only an optimization.</div><div><br><blockquote type="cite"><div dir="ltr"><div>
<p class="MsoNormal"><u></u> <u></u><span style="font-size:11pt">Any additional info greatly appreciated.</span></p></div></div></blockquote><div><br></div>HTH</div><div><br><blockquote type="cite"><div dir="ltr"><div>
<p class="MsoNormal">Thanks,</p>
<p class="MsoNormal">Jaromir</p>
<p class="MsoNormal"><u></u> <u></u></p>
<p><span lang="CS">--</span></p>
<p><strong><span style="font-family:"Calibri Light",sans-serif;color:rgb(51,51,51);font-weight:normal">Jaromír Matas</span></strong><span style="font-family:"Calibri Light",sans-serif;color:rgb(85,85,85)"><u></u><u></u></span></p>
<p><span style="font-family:"Calibri Light",sans-serif;color:rgb(46,117,182)"><a href="mailto:mail@jaromir.net" target="_blank">mail@jaromir.net</a><u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:rgb(143,170,220)"><u></u> <u></u></span></p>
<p class="MsoNormal"><u></u> <u></u></p>
<div style="border-style:solid none none;border-top-width:1pt;border-top-color:rgb(225,225,225);padding:3pt 0in 0in">
<p class="MsoNormal" style="border:none;padding:0in"><b>From: </b><a href="mailto:tim@rowledge.org" target="_blank">tim Rowledge</a><br>
<b>Sent: </b>Sunday, February 12, 2023 5:18<br>
<b>To: </b><a href="mailto:squeak-dev@lists.squeakfoundation.org" target="_blank">The general-purpose Squeak developers list</a><br>
<b>Subject: </b>Re: [squeak-dev] Questions about FullBlock closures</p>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal" style="margin-bottom:12pt"><br>
<br>
> On 2023-02-11, at 4:04 PM, Jaromir Matas <<a href="mailto:mail@jaromir.net" target="_blank">mail@jaromir.net</a>> wrote:<br>
> <br>
> If I may, I have a question here: What is the purpose of the primitive 196 Context>>#terminateTo:? Why primitive and why terminating each context along the way? Naively, I'd think checking the two contexts are in the same sender chain and patching them via
 privSender should do but I'm sure I'm missing something here :)<br>
>  <br>
<br>
Exception handling stuff. Strongly related to prim 195 & 197. You have to check each context up the chain to see what exceptions might be dealt with & by which context. Look at e.g. Process>>#terminate for some context.<br>
<br>
<br>
tim<br>
--<br>
tim Rowledge; <a href="mailto:tim@rowledge.org" target="_blank">tim@rowledge.org</a>; <a href="http://www.rowledge.org/tim" target="_blank">http://www.rowledge.org/tim</a><br>
When flying inverted, remember that down is up and up is expensive<br></p></div></div></blockquote></div></div></blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><span style="font-size:small;border-collapse:separate"><div>_,,,^..^,,,_<br></div><div>best, Eliot</div></span></div></div></div>