"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.

That works better if readers understand that the immediate object is not the
pointer value in 'a', but _implicitly_ lives at the destination referred to
by 'a'. This is what I meant by references to Fixnums are encoded in an
optimized way e.g. 2's complement bit strings.

Otherwise
    x = 5
    y = 5
Would mean two immediate objects. How then to explain
    x.instance_variable_set "@foo", 20
    y.instance_variable_get "@foo" #=> 20 ??

x = y # x refers to the same object y referred to

u = 5 # u refers to the fixnum 5
v = u # v refers to the same object that u referred to
C = v # C refers to the same object that u and v refer to

> 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? You probably mean "no instance variables unless
created by Ruby code".

> Floats and Bignums are not actually immediate values, but they are
> immutable

How are Floats and Bignums represented?
x = 2.5
y = 10 ** 10

> 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.

Great to know. That is what I guessed from false.id. I would say that
_references_ to the objects false, true, and nil are represented by the bit
strings 0, 2, and 4 (since all Ruby code can do is handle references to
objects).

Is the stored reference to an object generally the same as object.id ? How
do they correspond?

> Fixnums are represented by VALUEs with bit 0 set to 1.

_references_ to Fixnums ?

Good to know. So some fixnums might need some bit manipulation before
passing off to, say, C-routines for integer arithmetic.

> Symbols are represented by VALUEs with bit 0 to 7 set to 01110000.

_references_ to Symbols ? Presumably symbols (or their associated strings)
are actually allocated somewhere within (or mapped from) a block of memory
addresses with the bits 0..7 mask.

> If I'm wrong with any of those please correct me. It would also be
> interesting if somebody could find out what values VALUEs that are not
> immediate Objects can have.

_references_ to non-immediate Objects?

Thanks for sharing all these valuable insights!