Declaring pool dictionaries, pool constants and globals
In VisualAge Smalltalk 3.0, a Smalltalk Application could declare Application globals in the Application's toBeLoadedCode. For example, the typical toBeLoadedCode string would look something like this:
| poolDictionary |
poolDictionary := Dictionary new.
poolDictionary
at: 'Constant01' put: MyClass new;
at: 'Constant02' put: 42;
at: 'Constant03' put: MyOtherClass new.
Smalltalk at: #MyPoolDictionary put: poolDictionary.
Smalltalk at: #MyGlobal put: MyClass new.
This created a pool dictionary with three constants as well as a global variable.
In earlier releases of VA Smalltalk Server, some restrictions were placed on the creation of Application globals. Specifically, only literal values could be set in the toBeLoadedCode and the code had to be sure to update the Smalltalk dictionary in the correct image:
| poolDictionary |
System image globalNamespace
declarePoolDictionary: #MyPoolDictionary;
declareVariable: 'Constant01' poolName: #MyPoolDictionary;
declareConstant: 'Constant02' poolName: #MyPoolDictionary value: 42;
declareVariable: 'Constant03' poolName: #MyPoolDictionary;
declareVariable: '#MyGlobal' poolName: #MyPoolDictionary.
The Application's loaded method could be used to set the values of the non-literal globals and constants:
loaded
"Set the non-literal application globals"
Constant01 := MyClass new.
Constant03 := MyOtherClass new.
MyGlobal := MyClass new.
Since Version 4.0 of VisualAge Smalltalk Server, further restrictions have been placed on the declaration of Application globals. The image builder must know which globals are associated with each Application so that when an image component containing an Application is unloaded, the globals with the components' Applications can be removed from the image. Globals are no longer declared in toBeLoadedCode. Instead, they are declared in Application class methods called namespace pragmas.
Namespace pragmas are methods whose names start with '_PRAGMA_' and end with the name of the pool dictionary they declare. The body of the method is a single comment that contains statements declaring the pool and its constants. In the example above, the Application would have the following namespace pragma as a class method:
_PRAGMA_MyPoolDictionary
"%%PRAGMA DECLARE
(name: MyPoolDictionary isPool: true isConstant: false)
(pool: MyPoolDictionary declarations: (
(name: Constant01 isConstant: false)
(name: Constant02 isConstant: true valueExpression: '42')
(name: Constant03 isConstant: false)
(name: MyGlobal isConstant: false)
))"
Note that the entire body of the method is a single comment. The Application's loaded method can still be used to set the non-constant entries in MyPoolDictionary.
For more information on pragmas, refer to the chapter on Namespace pragmas support in the Programmer Reference.
Last modified date: 07/24/2020