<br><br><div class="gmail_quote">On Mon, May 3, 2010 at 1:58 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;">
<div><div></div><div class="h5"><br>
On 3 May 2010 03:43, Eliot Miranda &lt;<a href="mailto:eliot.miranda@gmail.com">eliot.miranda@gmail.com</a>&gt; wrote:<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; On Sun, May 2, 2010 at 11:47 AM, Igor Stasenko &lt;<a href="mailto:siguctua@gmail.com">siguctua@gmail.com</a>&gt; wrote:<br>
&gt;&gt;<br>
&gt;&gt; On 2 May 2010 21:23, Eliot Miranda &lt;<a href="mailto:eliot.miranda@gmail.com">eliot.miranda@gmail.com</a>&gt; wrote:<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; On Fri, Apr 30, 2010 at 10:56 PM, Igor Stasenko &lt;<a href="mailto:siguctua@gmail.com">siguctua@gmail.com</a>&gt; wrote:<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; Hello,<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; Alien adds a new primitive pragma:<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; &lt;primitive: &#39;foo&#39; error: tempName module: &#39;bar&#39; &gt;<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; where tempName is auto-declared during parsing as a special temp which<br>
&gt;&gt; &gt;&gt; will be used to retrieve primitive error code. i.e.<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; myMethod<br>
&gt;&gt; &gt;&gt;  &lt;primitive: &#39;foo&#39; error: code module: &#39;bar&#39; &gt;<br>
&gt;&gt; &gt;&gt; &quot;prim failed , check the error code&quot;<br>
&gt;&gt; &gt;&gt;  code = 5 ifTrue: [ self error: &#39;you wrong&#39; ]<br>
&gt;&gt; &gt;&gt;  code = 666 ifTrue: [ self error: &#39;you are wrong as hell&#39; ]<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; The problem is, that i found that while its integrated in parser<br>
&gt;&gt; &gt;&gt; (through Alien package overrides),<br>
&gt;&gt; &gt;&gt; it leads to nowhere in current Interpreter. :(<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; But it&#39;s fully supported in the Newspeak VM and in the Cog VMs.  Please don&#39;t delete this.<br>
&gt;&gt;<br>
&gt;&gt; i won&#39;t. I like being told by prim, _why_ its failed.<br>
&gt;&gt; I just don&#39;t like that this is currently dormant.<br>
&gt;&gt;<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; The sole reference to primFailCode is only in #primitiveFailFor: ,<br>
&gt;&gt; &gt;&gt; which actually should be used by prims to set the failure code:<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; Interpreter&gt;&gt;primitiveFailFor: reasonCode<br>
&gt;&gt; &gt;&gt;        &quot;Set specific primitive failure.&quot;<br>
&gt;&gt; &gt;&gt;        primFailCode := reasonCode.<br>
&gt;&gt; &gt;&gt;        self primitiveFail.<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; I&#39;d like to propose an alternative implementation:<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; - at VM side , add only a single primitive:<br>
&gt;&gt; &gt;&gt; primitiveLastFailureCode<br>
&gt;&gt; &gt;&gt;        self export: true.<br>
&gt;&gt; &gt;&gt;        self pop: 1 thenPush: (self integerObjectOf: primFailCode).<br>
&gt;&gt; &gt;&gt;        &quot;reset the code&quot;<br>
&gt;&gt; &gt;&gt;        primFailCode := 0.<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; At language side, we can support both, old and new format:<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; Add the method , which will retrieve the code:<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; Object&gt;&gt;lastFailureCode<br>
&gt;&gt; &gt;&gt;  &quot;Primitive: answer the last primitive failure code. Resets the failure code.<br>
&gt;&gt; &gt;&gt;  Note: it can fail only if we&#39;re running on older VMs, which has no<br>
&gt;&gt; &gt;&gt; support of this primitive, if so, answer the generic failure code&quot;<br>
&gt;&gt; &gt;&gt;  &lt;primitive: &#39;primitiveLastFailureCode&#39; module: &#39;&#39;&gt;<br>
&gt;&gt; &gt;&gt;  ^ 0<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; And then, to handle things manually, one could use:<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; Myclass&gt;&gt; foo<br>
&gt;&gt; &gt;&gt;   &lt;primitive: &#39;myprimitive&#39; module: &#39;mymodule&gt;<br>
&gt;&gt; &gt;&gt;   &quot;we&#39;re failed&quot;<br>
&gt;&gt; &gt;&gt;   | code |<br>
&gt;&gt; &gt;&gt;   code := self lastFailureCode.<br>
&gt;&gt; &gt;&gt;   ... handle the error code...<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; And to support the Alien&#39;s new pragma pattern (primitive:error:module:)<br>
&gt;&gt; &gt;&gt; it can simply instruct the encoder to generate an implicit bytecode<br>
&gt;&gt; &gt;&gt; sequence (at method&#39;s beginning), which equals to:<br>
&gt;&gt; &gt;&gt;   temp := self lastFailureCode.<br>
&gt;&gt; &gt;&gt; (where temp, is one, which used in pragma)<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; What you think?<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; This is bad for a number of reasons, primarily thread-safety.  There&#39;s nothing to guarantee that the prim fail code is accessed before a process switch which could cause the error code to get overwritten.  Instead if you wanted to do something in this area you could get the Newspeak VM and start integrating the code there-from.<br>

&gt;&gt;<br>
&gt;&gt; Yes. This might be an issue.<br>
&gt;&gt; I thought, there is no chance interrupting it between<br>
&gt;&gt; - current prim fail - enter a method - do a #lastFailureCode send<br>
&gt;&gt;<br>
&gt;&gt; or it is?<br>
&gt;&gt; If i remember, an interrupt check performed only on a normal return<br>
&gt;&gt; from method.<br>
&gt;<br>
&gt; Going by the old Teleplace interpreter interrupts are checked on activating a method, which includes a failing method.  See senders of internalQuickCheckForInterrupts &amp; quickCheckForInterrupts. i.e whenever a frame is built for a send. This is indeed between the primitive invocation and the send of lastFailureCode.<br>

&gt;<br>
<br>
</div></div>Aha, so its unsafe. Then, of course, your variant is better.<br>
<div class="im"><br>
&gt;&gt;<br>
&gt;&gt; And a normal return can&#39;t happen anywhere between the above stages.<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; I remember your description of setting a temp value with failure code.<br>
&gt;&gt; Its cool from language side perspective, but ugly &amp; complex at VM side<br>
&gt;&gt; (i can imagine how ugly and complex that code may look like where have<br>
&gt;&gt; to crunch a lot of bits and do many various checks before attempting<br>
&gt;&gt; to store code into temp).<br>
&gt;<br>
&gt; Its not at all complicated.  Find the code in the Newspeak VM.  The code to load the temp is likely also in the Closure compiler already.  Here&#39;s the code in internalActivateNewMethod as described on my blog:<br>

<br>
</div>Where i can get NewSpeak VM sources?<br></blockquote><div><br></div><div><a href="http://newspeaklanguage.org/the-newspeak-programming-language/downloads/">http://newspeaklanguage.org/the-newspeak-programming-language/downloads/</a> &amp; on that page <a href="https://sourceforge.net/projects/newspeakpl/files/newspeak/2010-02-23/newspeak-source-2010-02-23.zip/download">newspeak-source-2010-02-23.zip</a></div>
<div> </div><div><br></div><div>In there you&#39;ll find a directory newspeak-source-2010-02-23/ns-squeak/squeakpackages/VMMaker/ which contains all the VMMaker source broken out by class (e.g. newspeak-source-2010-02-23/ns-squeak/squeakpackages/VMMaker/Interpreter.st)</div>
<div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im"><br>
&gt;<br>
&gt;         “Pass primitive error code to last temp if method receives it (indicated<br>
&gt;          by an initial long store temp bytecode). Protect against obsolete values<br>
&gt;          in primFailCode by checking that newMethod actually has a primitive.”<br>
&gt;         primFailCode ~= 0 ifTrue:<br>
&gt;                  [((self methodHeaderHasPrimitive: methodHeader)<br>
&gt;                   and: [(self byteAtPointer: localIP + 1) = 129 &quot;long store temp&quot;]) ifTrue:<br>
&gt;                           [errorCode := self getErrorObjectFromPrimFailCode.<br>
&gt;                            self longAt: localSP put: errorCode &quot;nil if primFailCode == 1, or primFailCode&quot;].<br>
&gt;                  primFailCode := 0].<br>
&gt;&gt;<br>
&gt;&gt; &gt; But I&#39;m now in a position to put some effort into open sourcing Cog, having completed my current Teleplace assignment, and so perhaps being patient and waiting a little longer is the best approach.  In the mean time please don&#39;t change any of the primitive fail code stuff.  Its fully functional in the code we&#39;re using at Teleplace and in Newspeak and it would be good to avoid incompatibilities.<br>

&gt;&gt;<br>
&gt;&gt; well, my proposal actually don&#39;t requires altering existing code.<br>
&gt;&gt; It just adds a prim, which exposing the failure code value to language side.<br>
&gt;<br>
&gt; Alas in a way that can&#39;t provide reliable access given the VM&#39;s current interrupt response.  I don&#39;t mean to frustrate you, but I do hope to get my code out soon.<br>
<br>
</div>I see not reason , why i should be frustrated :)<br>
You shown me that my approach is unreliable. So, even if its simpler,<br>
it can&#39;t be used.<br>
<br>
And there is a NewSpeak code, which waits to be integrated. So, its a<br>
work to do, not to get frustrated :)<br></blockquote><div><br></div><div>Good :)</div><div><br></div><div>best,</div><div>Eliot</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

<div><div></div><div class="h5"><br>
<br>
&gt; best<br>
&gt; Eliot<br>
&gt;<br>
&gt;&gt;<br>
<br>
<br>
--<br>
Best regards,<br>
Igor Stasenko AKA sig.<br>
</div></div></blockquote></div><br>