Code Generation

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Code Generation

Keith R. Fieldhouse
Hello,

For a project I have in mind, I'd like to do some in-image code
generation.  I actually do this quite a bit in other languages for one
reason and another but it seems as though it'd be a somewhat different
beast inside a Squeak image.

So, of the various packages available on
SqueakMap/SqueakSource/Monticello is there one that you'd consider a
good example of code generation techniques with Squeak?   Or is there
something already in the image that's worth looking at? I'm interested
in generating new classes and methods on both sides.    Something that
uses some sort of templating facility would be interesting as well.

Thanks for your help,

Keith

Reply | Threaded
Open this post in threaded view
|

Re: Code Generation

tblanchard
In general, I avoid code generation as much as possible, but it is  
fairly easy in Squeak.  The text you see in a browser when you define  
a new subclass is, in fact, an executable statement that sends a  
message to a class to create a subclass.  IOW:

Set subclass: #Dictionary
        instanceVariableNames: ''
        classVariableNames: ''
        poolDictionaries: ''
        category: 'Collections-Unordered'

sends a message to Set to create a subclass called Dictionary.

To add methods, you can ask the class to compile a string - basically  
the same string you see in the browser.  Look at  
Behavior>>compile:notifying:
If you dig around Class, Behavior, MetaClass, and similar, you'll  
find all sorts of nifty meta manipulation goodies for removing  
methods, fiddling with ivars, etc.


On Jul 30, 2006, at 4:25 PM, Keith R. Fieldhouse wrote:

> Hello,
>
> For a project I have in mind, I'd like to do some in-image code  
> generation.  I actually do this quite a bit in other languages for  
> one reason and another but it seems as though it'd be a somewhat  
> different beast inside a Squeak image.
>
> So, of the various packages available on SqueakMap/SqueakSource/
> Monticello is there one that you'd consider a good example of code  
> generation techniques with Squeak?   Or is there something already  
> in the image that's worth looking at? I'm interested in generating  
> new classes and methods on both sides.    Something that uses some  
> sort of templating facility would be interesting as well.
>
> Thanks for your help,
>
> Keith
>


Reply | Threaded
Open this post in threaded view
|

Re: Code Generation

Brent Pinkney
In reply to this post by Keith R. Fieldhouse
Hi,

> For a project I have in mind, I'd like to do some in-image code
> generation.  
>
> So, of the various packages available on
> SqueakMap/SqueakSource/Monticello is there one that you'd consider a
> good example of code generation techniques with Squeak?  

Have a look at the Lava SQL engine for the Magma OODB. This parses
a SQL string using Smacc and then emits a Smalltalk class and methods
which is compiled by the Standard Smalltalk compiler.

When instantiated and executed it interogates the Magma database for the
desired results.

It is on SqueakSource. Contact me if you need help.

Cheers

Brent


Reply | Threaded
Open this post in threaded view
|

Re: Code Generation

Lukas Renggli
In reply to this post by Keith R. Fieldhouse
Hi Keith,

the following package on SqueakMap does quite a bit of automatic code
generation and transformation. It uses the model of the refactoring
browser to compose multiple methods into one and to allow pattern
matching on arguments and receiver of the method. Have a look at the
source code:

Functional Pattern Matching
http://map.squeak.org/package/3772b420-ba02-4fbd-ae30-8eadfc323b7b

Hope this helps,
Lukas

--
Lukas Renggli
http://www.lukas-renggli.ch