This is an old revision of the document!


Smalltalk Transform Project

Transforming Smalltalk code from one dialect to another.

Transformations are declared for each package, class and method. The transformations are applied to some code to generate the target Smalltalk code.

This is the next more general version of the Gemstone Fileout project.

The only working example is the PDFtalk port from VisualWorks to Gemstone.

It is intended to cover other dialects (Squeak, Pharo, VAST, (Smalltalk/X; has namespaces)) as well.

[Begin of 2022] There is the possibility for a project to implement a general port for non-namespace Smalltalk dialects. A project page is setup here.

Load bundle {Smalltalk Transform Project} from the Public Store into VisualWorks.

As Example, load package [Gemstone Fileout PDFtalk] from the Public Store.

While all Smalltalk dialects share the same message sending paradigm with the same basic syntax. Many dialects extended the syntax (VW: namespace and literal bindings, Squeak: dynamic array, Amber: literal dictionaries, etc.).

The basic class library (Object, Number, Collection, Class etc.) with standardized selectors are the same in all dialects. But each one extends the library and classes with their own ways of doing things.

There are some cross dialect libraries like Glorp.

The UI, at the other end, is very different in all dialects, so that porting is almost impossible.

Methods

The source code is in methods which syntax may be different in the target system.

There are 3 kinds of changes concerning methods:

  • Ignore This method of the source system should not be written to the target system.
    Ignore method: #asPDF
  • Add This method is added to the target system. The method does not exist in the target system.
    Add method: #asPDF code: #_gs_asPDF
  • Replace This method of the source system is replaced by the body of the target method
    Replace method: #asString code: #_gs_asString
    • Rewrite The body of the source method is transformed by a Rewrite rule
      Rewrite method: #pdfVersion rule: #replaceDottedName

Add and Replace refer to code in a method private for the target dialect. The body of the #code method is combined with the selector given by #method.

Example:

The VW method #isLiteral in Object is:

isLiteral
	"Answer whether the receiver has a literal text form 
	recognized by the compiler."
	^false

But in Gemstone, the method should be: (this method is defined as extension to Object in package [Gemstone Fileout PDFtalk])

_gs_isLiteral
	^self literalString notNil

With the transformation

ClassChange
	classReference: #{Object}
	instanceChanges: (Array with: (Add method: #isLiteral code: #_gs_isLiteral))

the following is written out as new method for Object in Gemstone:

isLiteral
	^self literalString notNil

In case that the target class is not in the source system, the code is defined in a special placeholder class: CodeHolder. The methods here should have the proper protocol and be on the class or instance side.

Classes

Changes related to classes.

Packages

Changes related to a package or bundle.

PackageChange
	unusedClasses: 		<Array of: class reference>
	newSuperclasses: 	<Dictionary key: class reference value: Symbol>
	newClassNames: 		<???>
	hierarchyChanges: 	<Array of: ClassChange>
	localChanges: 		<Array of: ClassChange>
	extensions: 		<Array of: SystemClassChange>

unusedClasses :: classes not to be filed out

newSuperclasses :: classes with their target dialect superclass

newClassNames :: (preparation for class renamings - not done or used yet)

hierarchyChanges :: class changes for a class hierarchy

localChanges :: class changes for classes defined or extended in the package

extensions :: system class changes for classes only defined in the target system

(to be continued…)

The code transformations are done with the rewrite tool.

Notes for myself for changes in the next version.

  • Class renamings. A project scoped operation where all references to a class must be rewritten
  • multiple rewrites. Serveral rewrites should be applied to one method source
  • Dialect namespaces. Each dialect should have it's own namespace so that target code loads without warnings
  • Usage detection. For recuring transformations, I want to find out which rules are not used anymore
  • Define classes first. References to unloaded classes cause an error in Gemstone. Allows forward references.
  • smalltalktransform.1643627251.txt.gz
  • Last modified: 2022/01/31 12:07
  • by christian