Sorry if this repeats ...

"Florian Gross" <flgr / ccan.de> wrote in message
news:34fqajF4bd0lhU1 / individual.net...
> Eustaquio Rangel de Oliveira Jr. wrote:
>
> > Forgive me if I misunderstood, but so VALUEs are variables?
> >
> > a = 1
> >
> > a is the VALUE, with 32 bit length?
>
> a is mapped to a VALUE. VALUEs are pointers to Ruby Object Structs.
> Immediate objects are not represented by any Ruby Object Struct -- they
> are identified directly by the pointer's destination. If Ruby sees such
> a special pointer it does not need to resolve it.

Fine. As long as we understand that the immediate object is not the value
stored in variable a, but the _implicit_ object that resides at the
destination pointed to by 'a'. This is just to have a consistent underlying
explanation:

x = y
# x and y refer to the _same_ object

u = 5
v = u
# u and v refer to the _same_ object

u + v
# special pointer, no need to de-reference; + knows how to interpret these
special pointers to do integer arithmetic, returning other special pointers.

Otherwise we would have needless tricky problems:
u = 5 # one immediate object
v = u # another immediate object ??
v.instance_variable_get "@foo" #=> nil
u.instance_variable_set "@foo", 20 # the 1st immediate object
v.instance_variable_get "@foo" #=> 20 ??? how come ?

> Because there is no actual Ruby Object Struct there are no flags (which
> means you can't (un)taint them), no instance variables

No instance variables ... unless created by Ruby code would be better.

> Floats and Bignums are not actually immediate values, but they are
> immutable and act as if they were immediate by default in some other
> contexts. (You can't define singleton methods on them because they use a
>   custom singleton_method_added callback that raises an exception. It's
> implemented by Numeric#singleton_method_added.)

How are floats and bignums represented? I guess bignums are heap allocated
and gc'd. Floats too?
x = 2.5
y = 100 ** 100

> false, nil and true and the special undef value that is not visible
> anywhere in Ruby are represented by VALUEs of 0, 2, 4 and 6.

false, true, and nil are objects _referred to_ by 0, 2, 4, 6. Same reason as
above.
x = false; y = x
# x and y refer to the same object

Does object.id generally correspond to the way a reference to object is
represented? What are the exceptions?

> Symbols are represented by VALUEs with bit 0 to 7 set to 01110000. This
> means that there can be up to 16777216 different Symbols on 32 bit and
> up to 72057594037927936 different Symbols on 64 bit systems.

Presumably the symbols themselves (or their corresponding strings) are
allocated somewhere within, or mapped from, the address block with that
0...7bit mask?

Thanks for sharing your very useful insights on these!