[Vm-dev] positive32BitValueOf: fail with LargePositiveInteger

Mariano Martinez Peck marianopeck at gmail.com
Fri Oct 8 17:13:09 UTC 2010


Hi. I am trying to call #primitiveBitOr which inside calls
#popPos32BitInteger which calls  #positive32BitValueOf , with two
LargePositiveInteger. Example:

9999999999 bitOr: 8888888888.

Now, this seems to fail since the #bitOr: of LargePositiveInteger is
failing, and thus, super (Integer) is being used. Now, I don't understand
why it fails.

If I read the comment of positive32BitValueOf it says "Convert the given
object into an integer value.
    The object may be either a positive ST integer or a four-byte
LargePositiveInteger."

Its code is:

positive32BitValueOf: oop
    "Convert the given object into an integer value.
    The object may be either a positive ST integer or a four-byte
LargePositiveInteger."

    | sz value |
    (self isIntegerObject: oop) ifTrue: [
        value := self integerValueOf: oop.
        value < 0 ifTrue: [^ self primitiveFail].
        ^ value].

    self assertClassOf: oop is: (self splObj: ClassLargePositiveInteger).
    successFlag ifTrue: [
        sz := self lengthOf: oop.
        sz = 4 ifFalse: [^ self primitiveFail]].
    successFlag ifTrue: [
        ^ (self fetchByte: 0 ofObject: oop) +
          ((self fetchByte: 1 ofObject: oop) <<  8) +
          ((self fetchByte: 2 ofObject: oop) << 16) +
          ((self fetchByte: 3 ofObject: oop) << 24) ].



as you can see, I am supposed to use ClassLargePositiveInteger.

But, in addition, LargePositiveInteger >> #bitOr comment says: "Primitive.
Answer an Integer whose bits are the logical OR of the
    receiver's bits and those of the argument. Fail if the receiver or
argument
    is greater than 32 bits. See Object documentation whatIsAPrimitive."

So....I don't understand...how can I have a LargePositiveInteger but that is
less than 32 bits?  Wouldn't that  be a SmallInteger?

I put some printf in the VM and seems that with my numbers (9999999999 and
8888888888.)  when I sent positive32BitValueOf:    I got : -65536 and 65535

Thanks in advance for any help.

Mariano
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/vm-dev/attachments/20101008/8f5c8552/attachment.htm


More information about the Vm-dev mailing list