[Newbies] Testing = and == in workspace

Bert Freudenberg bert at freudenbergs.de
Sun Jan 8 13:16:48 UTC 2012

On 08.01.2012, at 00:48, Ben Coman wrote:

> For some naive reason I thought that the SmallIntegers would stop at 64k. 

No, SmallIntegers currently use the full 31 bit range:

	{SmallInteger maxVal hex. SmallInteger minVal hex}
	==> #('16r3FFFFFFF' '-16r40000000')

>  Is it platform dependent on whether the CPU is 16/32/64 bit ?

Squeak is independent of the CPU word size. All images in general use are 32 bits. That means an object pointer (aka "oop") is a 32 bit word. Squeak's ancestor, Smalltalk-80, used 16 bit oops. For Squeak there is an experimental 64 bit image format, where each object pointer uses 64 bits. (1)

Normally an oop references a chunk of memory, which has one to three header words, and zero or more words for the "contents" of the object. 

Only SmallIntegers are special: their oops do not reference memory, but the value is taken from the bits of the oop itself. Each oop has one "tag" bit which determines if it is a normal oop (a reference) or an "immediate" object. The other 31 bits determine the value of the SmallInteger. (2)

That's why two SmallIntegers with the same value are always identical. "==" simply compares oops.

- Bert -

(1) "64 bit VM" means a VM compiled for a 64 bit processor, "64 bit image" means an image that use 64 bit oops. These are independent concepts, a 64 bit VM may run a 32 bit image. See http://squeakvm.org/squeak64/faq.html

(2) There have been proposals to use more tag bits, which would reduce the range of SmallIntegers, but add more immediate classes. There have been experiments but nothing has been officially adopted yet. But in particular with 64 bit oops there are so many bits that we may see more immediate classes.

More information about the Beginners mailing list