<div dir="ltr"><div>Arghh... I forgot this one which is preempting my asUnsignedInteger cast:<br><br><br>generateIntegerObjectOf: msgNode on: aStream indent: level<br>    &quot;Generate the C code for this message onto the given stream.&quot;<br>    | expr castToSqint |<br>    expr := msgNode args first.<br>    aStream nextPutAll: &#39;((&#39;.<br>    &quot;Note that the default type of an integer constant in C is int.  Hence we /must/<br>     cast constants to long if in the 64-bit world, since e.g. in 64-bits<br>        (int)(16r1FFFFF &lt;&lt; 3) = (int)16rFFFFFFF8 = -8<br>     whereas<br>        (long)(16r1FFFFF &lt;&lt; 3) = (long) 16rFFFFFFF8 = 4294967288.&quot;<br>    castToSqint := expr isConstant and: [vmClass isNil or: [vmClass objectMemoryClass wordSize = 8]].<br>    castToSqint ifTrue:<br>        [aStream nextPutAll: &#39;(sqInt)&#39;].<br>    self emitCExpression: expr on: aStream.<br>    aStream<br>        nextPutAll: &#39; &lt;&lt; &#39;;<br>        print: vmClass objectMemoryClass numSmallIntegerTagBits;<br>        nextPutAll: &#39;) | 1)&#39;<br><br></div>I think we should completely remove this from translationDictionary... It&#39;s not object oriented.<br><br><div><div><div class="gmail_extra"><div class="gmail_quote">2016-08-18 3:19 GMT+02:00 Nicolas Cellier <span dir="ltr">&lt;<a href="mailto:nicolas.cellier.aka.nice@gmail.com" target="_blank">nicolas.cellier.aka.nice@gmail.com</a>&gt;</span>:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">The test fails with -2^31 and 2^31-1<br>It&#39;s not so amazing, because when I debug, I find this incorrect version:<br><div><br>   64769    sqInt<br>   64770    signed32BitIntegerFor(sqInt integerValue)<br>   64771    {<br>-&gt; 64772        return (((((int) integerValue)) &lt;&lt; 3) | 1);<br>   64773    <br>   64774    }<br>   64775<br><br></div><div>of course, the shift will overflow for large positive or large negative 32bits int.<br></div><div>But I don&#39;t understand how it&#39;s been generated...<br></div><div>I would expect<br>    return ((((usqInt)((int) integerValue)) &lt;&lt; 3) | 1);</div><div><br>Indeed:<br><br>signed32BitIntegerFor: integerValue<br>    &quot;Answer a full 32 bit integer object for the given integer value.<br>     N.B.  Returning in each arm separately enables Slang inlining.<br>     /Don&#39;t/ return the ifTrue:ifFalse: unless Slang inlining of conditionals is fixed.&quot;<br>    &lt;inline: true&gt;<br>    objectMemory hasSixtyFourBitImmediates<br>        ifTrue:<br>            [^objectMemory integerObjectOf: <br>                (self cCode: [self cCoerceSimple: integerValue to: #int]<br>                    inSmalltalk: [(integerValue bitAnd: 16r7FFFFFFF)<br>                                - ((integerValue &gt;&gt; 31 anyMask: 1)<br>                                    ifTrue: [-16r100000000]<br>                                    ifFalse: [0])])]<br>        ifFalse:<br>            [^self noInlineSigned32BitIntegerFor: integerValue]<br><br></div><div>has the cast to int.<br></div><div>Then there is another cast here:<br><br>integerObjectOf: value<br>    &quot;Convert the integer value, assumed to be in SmallInteger range, into a tagged SmallInteger object.<br>     In C, use a shift and an add to set the tag bit.<br>     In Smalltalk we have to work harder because the simulator works with strictly positive bit patterns.&quot;<br>    &lt;returnTypeC: #sqInt&gt;<br>    ^self<br>        cCode: [value asUnsignedInteger &lt;&lt; self numTagBits + 1]<br>        inSmalltalk: [value &lt;&lt; self numTagBits<br>                    + (value &gt;= 0<br>                        ifTrue: [1]<br>                        ifFalse: [16r10000000000000001])]<br><br></div><div>and asUnsignedInteger is translated like this by CCodeGenerator:<br><br>generateAsUnsignedInteger: msgNode on: aStream indent: level<br>    &quot;Generate the C code for this message onto the given stream.&quot;<br><br>    aStream nextPutAll:&#39;((usqInt)&#39;.<br>    self emitCExpression: msgNode receiver on: aStream.<br>    aStream nextPut: $)<br></div><div><br></div><div>How the hell could the hardcoded (usqInt) be not generated?<br></div></div>
</blockquote></div><br></div></div></div></div>