[Seaside] Jtalk, a Smalltalk for web developers

Nicolas Petton petton.nicolas at gmail.com
Sun Mar 20 14:08:07 UTC 2011


Le samedi 19 mars 2011 à 14:08 +0100, Norbert Hartl a écrit :
> Am 19.03.2011 um 13:55 schrieb Hannes Hirzel:
> 
> > Hello Nicolas
> > 
> > You mentioned the jtalk is a compiler.
> > 
> > I did in the workspace
> > 
> > 1 to: 10 do: [ :i | Transcript show: (i printString, ' ',(i*i)
> > printString, ' ', (i*i*i) printString); cr]. Transcript cr.
> > 
> > And the result showed in the Transcript.
> > 
> > Is there a place to see the translation of the Smalltalk code?
> > 
> > Or put the question otherwise: how do I use the compiler?
> > 
> To see the code I would use
> 
> Compiler new compileExpression: '3 + 4'
> 
> in the workspace. If you print it you get 
> 
>  'smalltalk.method({
> selector: "doIt",
> source: unescape("doIt%20%5E%5B3%20+%204%5D%20value"),
> fn: function(){
> var self=this;
> return (function(){return (3).__plus((4));})._value();
> return self;}
> })' 
> 
> If you execute it you use
> 
> Compiler new loadExpression: '3 + 4'

Yes, that's exactly how te compiler is used. I would just add that you
can get the Smalltalk source of any compiledMethod with:

(Behavior methodDictionary at: 'new') source

And the JS code with:

(Behavior methodDictionary at: 'new') fn compiledSource

Also, if you want to compile a method for a class you can use:

compiler := Compiler new.
compiledJS := compiler compile: aString forClass: aClass.
compiler eval: compiledJS.

Cheers,
Nicolas



More information about the seaside mailing list