Basic question about globals variables

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Basic question about globals variables

Mariano Martinez Peck
Hi. I know this is a newbie question, but there is something I don't understand about globals.

I am writing a piece of code, and I refer to "a class" that does exist. Suppose:

testSomething

    NonExistenteClass


Whem I accept the method, a popup brings saying it doesn't exist...etc. Then, I can define as global.
   
If I then evaluate:   Smalltalk globals at: #NonExistenteClass

the key exist and it has nil as value. Perfect.

So..if I understand well, all these globals variables AND classes are stored in this globals, which is the only instance of SystemDictionary (for the moment).

Now my question is, where are nil, true, false, etc stored? 

I know there are only one instance of  UndefinedObject, False, True, etc have only one instance...but WHERE are they stored? who keep them?  They don't seem to be in SystemDictionary. Why no?

I did a "chase pointers" to nil for example, and it says 
"CLASS: SmalltalkImage class
subclasses: UndefinedObject"

I still don't understand :(

Thanks for any hints

Mariano


_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: Basic question about globals variables

Lukas Renggli
On Thursday, August 5, 2010, Mariano Martinez Peck
<[hidden email]> wrote:

> Hi. I know this is a newbie question, but there is something I don't understand about globals.
>
> I am writing a piece of code, and I refer to "a class" that does exist. Suppose:
>
> testSomething
>
>     NonExistenteClass
>
>
> Whem I accept the method, a popup brings saying it doesn't exist...etc. Then, I can define as global.
>
> If I then evaluate:   Smalltalk globals at: #NonExistenteClass
>
> the key exist and it has nil as value. Perfect.
>
> So..if I understand well, all these globals variables AND classes are stored in this globals, which is the only instance of SystemDictionary (for the moment).
>
> Now my question is, where are nil, true, false, etc stored?

Magic in the compiler. They are also referenced  in the special objects array.

> I know there are only one instance of  UndefinedObject, False, True, etc have only one instance...but WHERE are they stored? who keep them?  They don't seem to be in SystemDictionary. Why no?

Efficiency. There are special bytecodes to push them.

AFAIK Gemstone is the only Smalltalk that has them in the "SystemDictionary".

Lukas

>
> I did a "chase pointers" to nil for example, and it says
> "CLASS: SmalltalkImage class
> subclasses: UndefinedObject"
>
> I still don't understand :(
>
> Thanks for any hints
>
> Mariano
>
>

--
Lukas Renggli
www.lukas-renggli.ch

_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: Basic question about globals variables

Hernan Wilkinson-3
nil, false and true are special objects that are well know by the vm, and they have a specific location on the vm... if you look at the class ObjectMemory and Interpreter (and InterpreterSimulator) you will see that (not sure they are still in pharo, if not, look for an old version of squeak, like 2.8... if you need an image to make the simulator work, let me know)

BTW, there are a lot of well know objects by the vm, like Class, Behavior, Message, I think Object too... for example, not only the vm knows about the Behavior hierarchy but also the structure its instances... try to add inst var to Behavior  and see what happens :-)... try it with an old version of squeak and it will be more interesting... (other interesting things to do is to remove #doesNotUnderstand: from Object and ProtoObject and send an invalid message... save the image before!!!)

Anyway, there are interesting things you can see from the vm implementation in Interpreter...

On Thu, Aug 5, 2010 at 10:58 AM, Lukas Renggli <[hidden email]> wrote:
On Thursday, August 5, 2010, Mariano Martinez Peck
<[hidden email]> wrote:
> Hi. I know this is a newbie question, but there is something I don't understand about globals.
>
> I am writing a piece of code, and I refer to "a class" that does exist. Suppose:
>
> testSomething
>
>     NonExistenteClass
>
>
> Whem I accept the method, a popup brings saying it doesn't exist...etc. Then, I can define as global.
>
> If I then evaluate:   Smalltalk globals at: #NonExistenteClass
>
> the key exist and it has nil as value. Perfect.
>
> So..if I understand well, all these globals variables AND classes are stored in this globals, which is the only instance of SystemDictionary (for the moment).
>
> Now my question is, where are nil, true, false, etc stored?

Magic in the compiler. They are also referenced  in the special objects array.

> I know there are only one instance of  UndefinedObject, False, True, etc have only one instance...but WHERE are they stored? who keep them?  They don't seem to be in SystemDictionary. Why no?

Efficiency. There are special bytecodes to push them.

AFAIK Gemstone is the only Smalltalk that has them in the "SystemDictionary".

Lukas

>
> I did a "chase pointers" to nil for example, and it says
> "CLASS: SmalltalkImage class
> subclasses: UndefinedObject"
>
> I still don't understand :(
>
> Thanks for any hints
>
> Mariano
>
>

--
Lukas Renggli
www.lukas-renggli.ch

_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project



--
Hernán Wilkinson
Agile Software Development, Teaching & Coaching
Mobile: +54 - 11 - 4470 - 7207
email: [hidden email]
site: http://www.10Pines.com


_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: Basic question about globals variables

Igor Stasenko
What makes me admired, is that smalltalk (and its family) is maybe a
sole language, where
behavior and properties of "undefined object" is well defined, and
what more important can be changed.
Unlike C++, for instance, where NULL (or nil pointer) is nothing else,
but a plague for developers :)

In Squeak, i think the 'root' references to the nil, true, false is
stored in special objects array, due to VM implementation.
At language side, they can be retrieved using #initializedInstance (if
i remember correctly) message, sent to corresponding class,
or directly from special objects array (but that will be dialect specific).


--
Best regards,
Igor Stasenko AKA sig.

_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project