[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Java compatibility [compilers, etc.]
On Mon, Mar 13, 2000 at 11:35:20PM +0100, Max Gilead wrote:
> There were talk about making BeanShell bytecode-compatible with Java by
> writing bytecode compiler. While it is good solution, I thought that
> there is another one, maybe simpler and more flexible.
> Do you know what NetRexx does when it compiles its source code? It first
> translates it to regular .java file and then invokes java compiler for
> it. BeanShell is much more similar to Java than NetRexx so writing such
> a translator would be even better solution.
Well, any kind of compilation that we would consider would have to produce
valid .class format output... so even if we use it internally in some
cases we would have the capability to write classes out to disk if that were
desired. (Tangentially, saving serialized BeanShell objects does save the
internal parsed format, not the script text).
As far as using the JDK compiler the only reason I'd shy away from that is
that we can't freely distribute it... If we can find an alternative we might
consider that. But in actuality, if all we need to do is produce static
Java types (e.g. non-interface types or extend a superclass) then the
byte-code production for that should be fairly simple (I'd imagine). That is
assuming we left the body of the code as interpreted. On the other hand if
you want to be able to compile out scripts to byte-code in their entirety
(for use without bsh) we'd need a fully featured compiler...
Another option that I've thought about in the past would be to have bsh be
capable of reading a bsh script and spewing compilable Java code. Of course
bsh is mostly Java compatible, but some of the scripty features aren't
(loose types, the method/closure stuff). It might be easy to modify the
parser to have it simply spew the correct casts and type info upon parsing
a script. That would provide an easy path from prototyping to compilation.
> Pros and cons:
> + (important) allows people to write prototype code in BeanShell and
> then automatically convert it to Java (note that I think of translator
> which would produce well-looking Java code, or ugly code + some
> beautifier :-)
Yes, this is what I was getting at in the last bit above.