[Vm-dev] primitiveBitShift

Helmut Rohregger helmut.rohregger at gmail.com
Mon Apr 15 17:39:43 UTC 2013


Hi Nicolas,

Am 15.04.2013 19:22, schrieb Nicolas Cellier:
> If you look at the terminal instructions in primitiveBitShift you'll see:
>
>     self push: (self positive32BitIntegerFor: shifted)
>
> If you inquire a bit, you will see that positive32BitIntegerFor: will 
> create a LargePositiveInteger instead of failing the primitive.

ok, i have assumed, that "positive32BitIntegerFor" will return a small 
integer because of "32 bit" in its name :-)
well, it does return a 32 bit integer but if to big for small integer, a 
largePositiveInteger gets built...

> The balance between purity and efficiency I guess...
>

this makes sense!
thank you!

> Nicolas
>
>
> 2013/4/15 Helmut Rohregger <helmut.rohregger at gmail.com 
> <mailto:helmut.rohregger at gmail.com>>
>
>
>     Am 15.04.2013 11:55, schrieb Igor Stasenko:
>
>           On 15 April 2013 11:46, Helmut Rohregger
>         <helmut.rohregger at gmail.com
>         <mailto: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
>                 <mailto: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.
>
>
>     hehe i know.
>     and "0 << SmallInteger maxVal" fits too, but will fail with the
>     implemented primitive.
>
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/vm-dev/attachments/20130415/c88ad2a9/attachment-0001.htm


More information about the Vm-dev mailing list