Search code examples
smalltalk

Strange Cuis quit behaviour


Experimenting with Cuis, i've found that:

If I evaluate separately, in a work space, the following statements, Smalltalks correctly saves it image and then it quits.

Smalltalk saveSession.
Smalltalk quitPrimitive.

However, If I select both statements and then I try to do them together, Smalltalks saves the image, but it does not quit.

The same thing happens if I try to do the following statement :

Smalltalk saveSession; quitPrimitive.

Any explanation ?


Solution

  • Resuming a Smalltalk image means to continue whatever it was doing when it was saved. "Saving" means taking a "snapshot" of the current object memory.

    Smalltalk saveSession.
    "<-- execution frozen here, this is what happens at startup"
    Smalltalk quitPrimitive.
    

    If you invoke save and quit in one expression, then it will snapshot first, and when starting up, execute the quit. If you do the snapshot separately, it will resume running the user interface on startup:

    Smalltalk saveSession.
    "<-- execution frozen here, nothing more happens at startup"
    

    The second expression was not evaluated, so it is not "in the snapshot".

    Basically Smalltalk starts up exactly where it left off - there is no main function as in other programming languages that is executed first. Smalltalk execution is simply "frozen" in the middle of the snapshot method, and when starting the image again, it is still in the snapshot method and just returns normally.

    See SystemDictionary>>snapshot:andQuit:embedded:.

    Startup happens in that method when the snapshotPrimitive returns. You can see that the startup list is processed after the snapshot, which will happen as the first thing when the image is "started".