Appendix 3: TOOL program format

TOOL is not Smalltalk. This document is provided to demonstrate an approach to representing an object oriented program in a textual format, and may contain ideas adaptable to such a representation for Smalltalk.


Each program or program fragment is called a package or package file. A package file consists of ASCII text (extended to include the printable characters added by the IBM PC implementation -- those with codes 128 through 254).

A package is a sequence of literal methods. Each literal method in turn is read in, compiled, and either:

A literal method may specify the immediate processing of another package. When this occurs, processing of the current package is suspended until the other package has been completely processed, at which time processing of the suspended package resumes. There is no implementation limit on the depth to which such processing can be nested. However, there is an emergent, difficult to predict, limit on the nesting depth, based on the size of the run-time stack.

Any characters, including white space, between literal methods is treated as a comment and completely ignored.

3.B.Literal Methods

A literal method consists of

If a literal method in a package contains a class name and a method pattern, it is compiled and installed into the method dictionary of the named class.

If a literal method in a package contains neither a class name nor a method pattern, it is compiled and immediately executed. Such methods are called anonymous methods.

Other literal methods are ignored.


The system guarantees only that the literal methods will be processed in the order they appear in the package. Over time, a conventional order has been adopted by TOOL programmers. By convention, a package consists of literal methods doing the following:

1. anonymous methods which define new global variables (other than classes) or which assign new values to pre-existing global variables.

	{.Tool globals at: 'Vectors' put: Table new;
	   at: 'Methods' put: Table new}

2. anonymous methods which define new classes, or which redefine pre-existing ones. These are ordered by the inheritance relation, superclasses appearing before their subclasses.

	{.Class newClass: 'ClassVector'
	  arrayType: #Object
	  superclass: Collection
	  instanceVariableNames: 'freeSlot'
	  poolDictionaries: ''}

3. methods for each of the newly introduced classes. Note that since all classes are defined before all methods, circular references among classes from within their methods are possible.

	  freeSlot := 0.
	  Return: self.}

4. methods added to pre-existing classes.

	{Table>>where: conditionBlock do: actionBlock.
	  From: 1
	    to: self basicSize
	    by: 2
	    do: [ :b1.
	      If: (conditionBlock value: (self basicAt: b1))
	        isTrue: [
	          actionBlock value:
	            (self basicAt: b1 + 1)]].
	  Return: self.}

5. anonymous methods which open a Workspace on the screen containing method code which can be highlighted and executed to launch the application in the package.

	{.Workspace new openOn: '; t1.
	Object withAllSubclasses do: [ :c.
	  t1 := If: c superclass isNil: [List new]
	    isNotNil: [(Vectors at: c superclass name)
	  c selectors do: [ :s. t1 addIfAbsent: s].
	  Vectors at: c name put: t1].
	Vectors keys do: [ :cn.
	  (Vectors at: cn) do: [ :s.
	    (Methods at: s ifAbsent: [
	        Methods at: s put: List new.
	        Methods at: s])
	      add: cn]].
	  initialExtent: (51,16)
	  label: 'Compute Vectors and Methods'}.

Note that this is optional -- a literal method in this position in a package may do other things, such as:

Copyright © March 8, 1995 Bruce Conrad