[Pharo-dev] [Pharo4] First Class Global Variables

Eliot Miranda eliot.miranda at gmail.com
Fri Jul 4 16:01:35 EDT 2014

Hi Marcus,

On Thu, Jul 3, 2014 at 8:51 AM, Marcus Denker <marcus.denker at inria.fr>

> Hi,
> If we have meta-object describing (and thus having the power to change the
> semantics of) instance variables,
> we need the same for Globals.
> I think the easiest is to just re-use the object hat is already there: the
> “binding”, that is, the association from
> the dictionary where the global lives (e.g. the classPool for class vars,
> Smalltalk globals for true globals, and so on).
>         SystemVersion bindingOf: ‘Current'
> The VM just cares that it is an assoiation (actually, it just care that
> there are two fields, but the rest of the image cares
> about value and key…)
> -> we can make a subclass of Association
> -> we can have the compiler forward code generation to the object that
> describes the global
> -> we can add a nice MOP API: #read and #write:  (instead of #value and
> #value:)
> -> Programmers can subclass the GlobalVariable and change #read and #write
> like they want (or override
> the code gen methods) as in Slots.

One thing I think is worth-while is having the compiler inline read-only
globals, especially classes.  Most classes never change, and even if they
do, become: means that references to them (including in machine code) get
updated, so there's little downside.

The only drawback is that you can not add an instance variables, I think,
> to check… maybe it even works?
> If not, there are ways around that e.g. using some fancy Slot that does
> not need an ivar but uses a weak dictionary
> in a class variable, for example).

Since the VM doesn't look beyond the second field it doesn't care if you
add inst vars.  It only expects the value field to be the second inst var;
it never asks for the size of the association or anything like that.
 Remember that both key and value are fixed inst vars.

Thus: it would be fairly easy to have the class vars be as flexible as the
> slots… and then e.g. you will be able
> to  put breakpoints and watchers on class vars. You could even define
> globals with special behaviour the same
> way as you do with Slots.
>         Marcus

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.pharo.org/pipermail/pharo-dev_lists.pharo.org/attachments/20140704/f8d306b7/attachment-0002.html>

More information about the Pharo-dev mailing list