About the new compiler, Part I

Paolo Bonzini bonzini at gnu.org
Sun Jan 20 09:35:45 UTC 2008


>> Since you have the transformations available, you could use them as 
>> macros to eliminate some of the cases here. For example, #ifNil: can 
>> be transformed into "isNil ifTrue:".

Stephen Compall has been working on "message macros" for GNU Smalltalk 
with his Presource package, living at 
http://smalltalk.gnu.org/project/presource (Stephen is CCed).

In Presource, code is created from CodeTemplate objects like this:

     ^(CodeTemplate fromExpr:
	  '[:`testVar | `@branch] value: `@testValue') expand:
	(LookupTable from: {'`testVar' -> testVar.
			    '`@testValue' -> testValue.
			    '`@branch' -> elseBranch})

Examples of macros include changing the #from: method call (Squeak's 
#newFrom:) to

     LookupTable new
	at: '`testVar' put: testVar;
         ...;
	yourself

or things like "{ a. ' '. b } join" to a Stream, like

     a copy writeStream
	nextPutAll: ' ';
	nextPutAll: b;
	contents

Macros are often used in combination with the {...} array syntax or 
class methods, because it allows an easy way to know the receiver's 
class (and thus to know if the macro applies).

By the way, his work led to the discovery of a couple of RBParser bugs. 
  See http://snipurl.com/1xu6y for a c.l.s post describing them.

Paolo



More information about the Squeak-dev mailing list