In a previous message on this list, you said that using reflection
intead of generating byte-codes allows the BeanShell implementation
to be simpler. Simple is good.
How much complexity would it add to allow BeanShell to emit
Java source code that javac could compile?
This lends itself to a more type-safe interface that seems
very natural when calling BeanShell from Java. I'm thinking
about something along the lines of this method:
Object compile(Class interfaces, String bshSource);
where the Object returned implements the given interfaces.
If no Java compiler is available, then BeanShell would know the
user intended to re-use the code, but would be unable to compile it.
So, the "compiled" code would run the same, only more slowly.
Also, an implicit compiling interface could be used ala HotSpot.
More specifically, source code given to the interpreter for evaluation
could be compared against previously evaluated code. Frequently
evaluated code could be sent to javac.
I'm sure this means adding a large amount of code, but it seems
that with some careful design, the impact to the current BeanShell
code could be minimal. The distribution might even be split into
versions with and without the compiler included.
How hard would this be?
Would it be worth the effort?
On Thu, Jul 04, 2002 at 12:46:35PM -0400, Curt Cox wrote:
> How much complexity would it add to allow BeanShell to emit
> Java source code that javac could compile?
This is on the wish-list... It's something that I hope to do at some point.
I think it would be relatively straightforward to use the BeanShell parser
to output Java code instead of build the parse tree... Although I was
thinking this would be something of a utility you could use to translate
your bsh script into Java when you want to...
> This lends itself to a more type-safe interface that seems
> very natural when calling BeanShell from Java. I'm thinking
> about something along the lines of this method:
> Object compile(Class interfaces, String bshSource);
You know you can have this kind of type-safe interface now by having your
script implement the Java interface and fetching a reference to your script
as that interface type. (e.g. using Interpreter getInterface() or any return
Object obj = interpreter.getInterface( interfClass );
> How hard would this be?
> Would it be worth the effort?
It actually might not be that hard... 98% of it would be trivially spewing
the Java that we just parsed, with the necessary casts for loose types.
The only trick would be coming up with a compileable pattern to handle the
method closures (nested methods), and a few other things...
If you're interested in this I will be happy to help you get started and
work on some of these issues... I suggest starting as a stand-alone
utility based on the BeanShell parser and then seeing how we could integrate
From: Artur Biesiadowski <abies@pg...> - 2002-07-05 07:10:38
> It actually might not be that hard... 98% of it would be trivially spewing
> the Java that we just parsed, with the necessary casts for loose types.
> The only trick would be coming up with a compileable pattern to handle the
> method closures (nested methods), and a few other things...
For me, most interesting part would be how do you plan to implement
method.field bsh expression. Depending on type of object (dynamic), it
can be array access or one of two or three method calls. Would you like
to handle this in java source also as such kind of mega-search ?