<div dir="ltr"><br><br><div class="gmail_quote">On Sun, Jul 20, 2008 at 11:59 AM, stephane ducasse &lt;<a href="mailto:stephane.ducasse@free.fr">stephane.ducasse@free.fr</a>&gt; wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Hello<br>
<br>
I would like to know how the VM defines on:do:<br>
<br>
on: exception do: handlerAction<br>
 &nbsp; &nbsp; &nbsp; &nbsp;&quot;Evaluate the receiver in the scope of an exception handler.&quot;<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp;| handlerActive |<br>
 &nbsp; &nbsp; &nbsp; &nbsp;&lt;primitive: 199&gt; &nbsp;&quot;just a marker, fail and execute the following&quot;<br>
 &nbsp; &nbsp; &nbsp; &nbsp;handlerActive _ true.<br>
 &nbsp; &nbsp; &nbsp; &nbsp;^ self value<br>
<br>
<br>
I&#39;m on a rather non existent internet connexion and I do not have the<br>
vm code and I would like to know where how the exception and handlerAction block<br>
are stored.</blockquote><div><br></div><div>As the other posters have pointed out primitive 199 is simply a primitive that aways fails. &nbsp;So exception and handlerAction are stored in the activation of on:do: in its first and second argument, e.g. see</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;| exception handler |</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;[exception := thisContext sender at: 1.</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; handler := thisContext sender at: 2.</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; 1 / 0]</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; on: Error</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; do: [:ex| ].</div>
<div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; { exception. handler }</div><div><br></div><div>The primitive doesn&#39;t set any bits in the context. &nbsp;It merely fails, ad the method is activated exactly as if on:do: did not have a primitive.</div><div><br>
</div><div>The VM finds activations of on:do: by examining the header of each context&#39;s compiled method (no bits are set in the context). &nbsp;Methods with primitives have the primitive number stored in a field in the method header. &nbsp;The VM&#39;s primitive is merely an optimization of the Smalltalk code you see:</div>
<div><br></div><div><div><div>findNextHandlerContextStarting</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>&quot;Return the next handler marked context, returning nil if there</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; is none. &nbsp;Search starts with self and proceeds up to nil.&quot;</div>
<div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>| ctx |</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>&lt;primitive: 197&gt;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>ctx := self.</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>[ctx isHandlerContext ifTrue:[^ctx].</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>(ctx := ctx sender) == nil ] whileFalse.</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>^nil</div><div><br></div><div><div>isHandlerContext</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&quot;is this context for &nbsp;method that is marked?&quot;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>^method primitive = 199</div>
<div><br></div><div>and similarly for finding unwind contexts (marked with primitive 198).</div><div><br></div><div>BTW, this is a really nice implementation by Andreas and Dan. &nbsp;In VW there are bits in the method header because primitives are not stored in the method header but in the bytecode. &nbsp;But this means we need a little bit more machinery. &nbsp;Using the primitive field is very simple and just as effective</div>
</div></div><div><div><br></div></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><br>
<br>
I was imagining that may be the vm stores them in the previous context.<br>
<br>
Stef<br>
<br>
</blockquote></div><br></div>