[Vm-dev] primitiveBitShift

Igor Stasenko siguctua at gmail.com
Mon Apr 15 09:55:15 UTC 2013


On 15 April 2013 11:46, Helmut Rohregger <helmut.rohregger at gmail.com> wrote:
>
> Am 15.04.2013 11:40, schrieb Igor Stasenko:
>
>>   On 15 April 2013 11:31, Helmut Rohregger <helmut.rohregger at gmail.com>
>> wrote:
>>>
>>> Hi all,
>>>
>>> i am interested in the implementations of primitives in the VMMaker
>>> package
>>> and found some code, which i think may be implemented incorrectly.
>>> Maybe some of you can help me out and correct me if i am wrong.
>>>
>>> Its located in InterpreterPrimitives>>#primitiveBitShift
>>> (VMMaker-dtl.319):
>>> the code: "self success: integerArgument <= 31" checks, if we lose bits
>>> by
>>> shifting to the left. This is because of processing SmallIntegers here,
>>> isn't it? But a "1 bitShift: 31" will produce a LargePositiveInteger
>>> instead
>>> of a SmallInteger. In fact a left shift of 30 will produce a
>>> LargePositiveInteger too.
>>>
>>> I know the code works, because the resulting object gets checked being a
>>> SmallInteger and fails if not. But the correct check would be "self
>>> success:
>>> integerArgument <= 29", isn't it?
>>> What do you think?
>>>
>> hmm., how do you know if shifted result will fit into smallint, if you
>> don't check both operands?
>>
>> "1 << 29 " fits
>> "SmallInteger maxVal << 29 " doesnt.
>> even
>> "SmallInteger maxVal << 1 " doesnt.
>
>
> but " x << 30 " does never fit, no matter which value 'x' has.

0 << 30 = 0.
fits.


-- 
Best regards,
Igor Stasenko.


More information about the Vm-dev mailing list