Compilation and SourceCode Generation

In order to create an own source code generator one should be aware about the possibilities of using the Smalltalk compiler within VASmalltalk in our own application.

I’ve seen a Smalltalk application once, which created some kind of Smalltalk spreadsheet application – but within the cells were user definable blocks to evaluate. The user entered source code and therefore was able to build an amazing calculation system.

Within VASmalltalk one could use instances of BlockContextTemplate to create these definable blocks. You create these blocks by:

aBlockContextTemplateOrCompilerError := EsCompiler  evaluate: '[ :a :b | a + b ]'.
aBlockContextTemplateOrCompilerError  class == CompilerError
	 ifTrue:[ aBlockContextTemplateOrCompilerError inspect ]
	ifFalse: [ (aBlockContextTemplateOrCompilerError value: 2 value: 2) inspect ]

In a spreadsheet each cell would have its own instance of BlockContextTemplate and you may use it again and again just by evaluating the instance with parameters – you can use the normal “Block” protocol.

If you build a source code generator you might do this within the Smalltalk IDE. Therefore you also want to store the source code within the structure of classes, categories and name spaces.

      (class, which is the target of the method)
		compile: 'squareXXYY ^(x * x) + (y * y).'
		notifying: nil
		ifNewAddTo: (appplication, which controls the source code of the compiled method)
		categorizeIn: #('accessing' 'adding')
		compile: 'squareXXYY ^(x * x) + (y * y).'
		notifying: nil
		ifNewAddTo: CLDT
		categorizeIn: #('calculation' 'calc-protocol')
This entry was posted in Smalltalk. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s