Igor,<div><br></div><div> the code in the VM has to be written to answer error codes. Primitive 1 is SmallInteger addition and that primitive's body doesn't fail with an error code, hence the error code is nil. There's nothing wrong here, simply that only some primitives answer error codes. Look at e.g.</div>
<div><br></div><div><div>primitiveAdd</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>self pop2AndPushIntegerIfOK: (self stackIntegerValue: 1) + (self stackIntegerValue: 0)</div><div>
<br></div><div><div>stackIntegerValue: offset</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>"In the StackInterpreter stacks grow down."</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>| integerPointer |</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>integerPointer := stackPages longAt: stackPointer + (offset*BytesPerWord).</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>^self checkedIntegerValueOf: integerPointer</div>
</div><div><br></div><div><br></div><div><div>checkedIntegerValueOf: intOop</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>"Note: May be called by translated primitive code."</div><div><br>
</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>(objectMemory isIntegerObject: intOop)</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>ifTrue: [ ^ objectMemory integerValueOf: intOop ]</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>ifFalse: [ self primitiveFail. ^ 0 ]</div></div><div><br></div><div>pop2AndPushIntegerIfOK: integerResult</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>self successful ifTrue:</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>[(objectMemory isIntegerValue: integerResult)</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>ifTrue: [self pop: 2 thenPush: (objectMemory integerObjectOf: integerResult)]</div>
<div><span class="Apple-tab-span" style="white-space:pre">                        </span>ifFalse: [self success: false]]</div><div><br></div><div>as opposed to</div><div><br></div><div><div>primitiveAt</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>self commonAt: false.</div>
</div><div><br></div><div><div>commonAt: stringy</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>"This code is called if the receiver responds primitively to at:.</div><div><span class="Apple-tab-span" style="white-space:pre">        </span> If this is so, it will be installed in the atCache so that subsequent calls of at:</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span> or next may be handled immediately in bytecode primitive routines."</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>| index rcvr atIx result |</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>self initPrimCall.</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>rcvr := self stackValue: 1.</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>(objectMemory isNonIntegerObject: rcvr) ifFalse:</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>[^self primitiveFailFor: PrimErrInappropriate].</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>index := self stackTop.</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>"No need to test for large positive integers here. No object has 1g elements"</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>(objectMemory isIntegerObject: index) ifFalse:</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>[^self primitiveFailFor: PrimErrBadArgument].</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>index := objectMemory integerValueOf: index.</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>"NOTE: The at-cache, since it is specific to the non-super response to #at:.</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>Therefore we must determine that the message is #at: (not, eg, #basicAt:),</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>and that the send is not a super-send, before using the at-cache."</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>(messageSelector = (self specialSelector: 16)</div><div><span class="Apple-tab-span" style="white-space:pre">        </span> and: [lkupClass = (objectMemory fetchClassOfNonInt: rcvr)])</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>ifTrue:</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>["OK -- look in the at-cache"</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>atIx := rcvr bitAnd: AtCacheMask. "Index into atCache = 4N, for N = 0 ... 7"</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>(atCache at: atIx+AtCacheOop) = rcvr ifFalse:</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>["Rcvr not in cache. Attempt to install it..."</div>
<div><span class="Apple-tab-span" style="white-space:pre">                        </span>(self install: rcvr inAtCache: atCache at: atIx string: stringy) ifFalse:</div><div><span class="Apple-tab-span" style="white-space:pre">                                </span>[self assert: (objectMemory isContextNonInt: rcvr).</div>
<div><span class="Apple-tab-span" style="white-space:pre">                                </span>self initPrimCall.</div><div><span class="Apple-tab-span" style="white-space:pre">                                </span>^self primitiveContextAt]].</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>self successful ifTrue:</div>
<div><span class="Apple-tab-span" style="white-space:pre">                        </span>[result := self commonVariable: rcvr at: index cacheIndex: atIx].</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>self successful ifTrue:</div>
<div><span class="Apple-tab-span" style="white-space:pre">                        </span>[^ self pop: argumentCount+1 thenPush: result]].</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>"The slow but sure way..."</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>self initPrimCall.</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>result := self stObject: rcvr at: index.</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>self successful ifTrue:</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>[stringy ifTrue: [result := self characterForAscii: (objectMemory integerValueOf: result)].</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>^ self pop: argumentCount+1 thenPush: result]</div>
</div><div class="gmail_quote">On Fri, Mar 16, 2012 at 11:11 AM, Igor Stasenko <span dir="ltr"><<a href="mailto:siguctua@gmail.com">siguctua@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
SmallInteger>>++ aNumber<br>
"Primitive. Add the receiver to the argument and answer with the result<br>
if it is a SmallInteger. Fail if the argument or the result is not a<br>
SmallInteger Essential No Lookup. See Object documentation whatIsAPrimitive."<br>
<br>
<primitive: 1 error: code ><br>
^ code<br>
<br>
11 ++ 'ww' => nil<br>
<br>
(i tried different numbered primitives, and it seems like all of them<br>
not using error codes, it always returns nil)<br>
<br>
Named prims, however working ok:<br>
<br>
SmallInteger>>+++ aNumber<br>
"Primitive. Add the receiver to the argument and answer with the result<br>
if it is a SmallInteger. Fail if the argument or the result is not a<br>
SmallInteger Essential No Lookup. See Object documentation whatIsAPrimitive."<br>
<br>
<primitive: 'qweqw' error: code ><br>
^ code<br>
<br>
11 +++ 'ww' => #'not found'<br>
<br>
<br>
'CoInterpreter VMMaker.oscog-eem.152 uuid:<br>
d39d62b0-45ca-4621-8f67-e3981bbe1875 Mar 3 2012,<br>
StackToRegisterMappingCogit VMMaker.oscog-eem.148 uuid:<br>
bb53aa60-4173-48ed-874b-dc0ff5a48992 Mar 3 2012, r2538<br>
<a href="http://www.squeakvm.org/svn/squeak/branches/Cog" target="_blank">http://www.squeakvm.org/svn/squeak/branches/Cog</a>'<br>
<font color="#888888"><br>
--<br>
Best regards,<br>
Igor Stasenko.<br>
</font></blockquote></div><br><br clear="all"><div><br></div>-- <br>best,<div>Eliot</div><br>
</div>