<br><br><div class="gmail_quote">On Fri, Apr 30, 2010 at 10:56 PM, 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;">
 <br>Hello,<br>
<br>
Alien adds a new primitive pragma:<br>
<br>
&lt;primitive: &#39;foo&#39; error: tempName module: &#39;bar&#39; &gt;<br>
<br>
where tempName is auto-declared during parsing as a special temp which<br>
will be used to retrieve primitive error code. i.e.<br>
<br>
myMethod<br>
  &lt;primitive: &#39;foo&#39; error: code module: &#39;bar&#39; &gt;<br>
&quot;prim failed , check the error code&quot;<br>
  code = 5 ifTrue: [ self error: &#39;you wrong&#39; ]<br>
  code = 666 ifTrue: [ self error: &#39;you are wrong as hell&#39; ]<br>
<br>
<br>
The problem is, that i found that while its integrated in parser<br>
(through Alien package overrides),<br>
it leads to nowhere in current Interpreter. :(<br></blockquote><div><br></div><div>But it&#39;s fully supported in the Newspeak VM and in the Cog VMs.  Please don&#39;t delete this.</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

<br>
The sole reference to primFailCode is only in #primitiveFailFor: ,<br>
which actually should be used by prims to set the failure code:<br>
<br>
Interpreter&gt;&gt;primitiveFailFor: reasonCode<br>
        &quot;Set specific primitive failure.&quot;<br>
        primFailCode := reasonCode.<br>
        self primitiveFail.<br>
<br>
<br>
I&#39;d like to propose an alternative implementation:<br>
<br>
- at VM side , add only a single primitive:<br>
primitiveLastFailureCode<br>
        self export: true.<br>
        self pop: 1 thenPush: (self integerObjectOf: primFailCode).<br>
        &quot;reset the code&quot;<br>
        primFailCode := 0.<br>
<br>
At language side, we can support both, old and new format:<br>
<br>
Add the method , which will retrieve the code:<br>
<br>
Object&gt;&gt;lastFailureCode<br>
  &quot;Primitive: answer the last primitive failure code. Resets the failure code.<br>
  Note: it can fail only if we&#39;re running on older VMs, which has no<br>
support of this primitive, if so, answer the generic failure code&quot;<br>
  &lt;primitive: &#39;primitiveLastFailureCode&#39; module: &#39;&#39;&gt;<br>
  ^ 0<br>
<br>
<br>
<br>
And then, to handle things manually, one could use:<br>
<br>
Myclass&gt;&gt; foo<br>
   &lt;primitive: &#39;myprimitive&#39; module: &#39;mymodule&gt;<br>
   &quot;we&#39;re failed&quot;<br>
   | code |<br>
   code := self lastFailureCode.<br>
   ... handle the error code...<br>
<br>
And to support the Alien&#39;s new pragma pattern (primitive:error:module:)<br>
it can simply instruct the encoder to generate an implicit bytecode<br>
sequence (at method&#39;s beginning), which equals to:<br>
   temp := self lastFailureCode.<br>
(where temp, is one, which used in pragma)<br>
<br>
What you think?<br></blockquote><div><br></div><div>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.</div>
<div><br></div><div>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.</div>
<div><br></div><div>best</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>
--<br>
Best regards,<br>
Igor Stasenko AKA sig.<br>
<br></blockquote></div><br>