[Vm-dev] positive32BitValueOf: fail with LargePositiveInteger
Nicolas Cellier
nicolas.cellier.aka.nice at gmail.com
Fri Oct 8 21:21:01 UTC 2010
2010/10/8 Mariano Martinez Peck <marianopeck at gmail.com>:
>
> 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?
>
If you don't want to read the blue book, maybe you should try this:
^SmallInteger maxVal highBit
Then observe how the low bits of an oop are used to distinguish a true
object pointer from an immediate SmallInteger value in the VM.
Nicolas
> 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
>
>
>
More information about the Vm-dev
mailing list