Ideas to use ruby2java on Red Bridge

Hi there,

I’ve been thinking about how Red Bridge (embedding API) can use
ruby2java (http://kenai.com/projects/ruby2java) compiler and load
compiled Ruby scripts. When ruby2java compiler is used, Ruby scripts
are converted into Java bytecode. Probably, we can expect better
performance on Red Bridge since it is Java API. However, there is no
way to use ruby2java compiler from Java right now. We need some
mechanism to be invented.

Currently, three ways to use compiler are come up with in my mind.

The first plan is compile ruby2java itself by ruby2java so that Red
Bridge can invoke a compiler method in a Java way. Good side of this
plan is that the performance is not bad, and changes to ruby2java can
be reflected immediately. The problem is I couldn’t compile ruby2java
because of the error below:

$ bin/ruby2java Ruby2Java lib/ruby2java.rb lib/compiler.rb
lib/compilable.rb lib/compilable/annotation.rb
lib/compilable/extends_class.rb lib/compilable/interface.rb
lib/compilable/package.rb lib/compilable/signature.rb

./lib/compiler.rb:33:in process_class': undefined method ruby2java_compilable?’ for Ruby2Java:Module (NoMethodError)
from bin/ruby2java:19

The second plan is just to evaluate ruby2java script using Red
Bridge’s embedding API. This would be the easiest but maybe the
slowest.

The third plan is to implement ruby2java in Java. This might be the
most effective for Red Bridge, but is not easy. Besides,
implementation in Java must catch up with the changes of ruby2java.

In any plan, compilation of a Java code that uses compiled Ruby
scripts might have a problem because *.class files are not exist
before Ruby scripts are dynamically compiled. Maybe a Java interface
helps to solve the problem.

If somebody has opinions, ideas or thoughts, let me know about that.

-Yoko


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

On Fri, Oct 16, 2009 at 2:54 PM, Yoko H. [email protected] wrote:

Currently, three ways to use compiler are come up with in my mind.
lib/compilable/package.rb lib/compilable/signature.rb
most effective for Red Bridge, but is not easy. Besides,
implementation in Java must catch up with the changes of ruby2java.

In any plan, compilation of a Java code that uses compiled Ruby
scripts might have a problem because *.class files are not exist
before Ruby scripts are dynamically compiled. Maybe a Java interface
helps to solve the problem.

If somebody has opinions, ideas or thoughts, let me know about that.

I like the idea in general. I’d lean toward option 1 or 2, and not
spend too much effort trying to port the whole of ruby2java to Java,
unless there’s some big benefit that I’m not seeing.

Be aware that we also have an evolving “jruby/ext” API
(Class#add_method_signature, Class#add_method_annotation,
Class#become_java! etc.) for defining Java classes. I think Charlie’s
plan was to reconcile and possibly merge ruby2java and jruby/ext, but
I don’t know the latest status. I’d personally like to see something
like ruby2java make it into JRuby core eventually.

/Nick


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

2009/10/16 Yoko H. [email protected]:

Hi there,

I’ve been thinking about how Red Bridge (embedding API) can use
ruby2java (http://kenai.com/projects/ruby2java) compiler and load
compiled Ruby scripts. When ruby2java compiler is used, Ruby scripts
are converted into Java bytecode.

Afaik, that’s not absolutely true. What it gives you is a nice Java
API wrapper. It stills run JRuby underneath.

Probably, we can expect better
performance on Red Bridge since it is Java API. However, there is no
way to use ruby2java compiler from Java right now. We need some
mechanism to be invented.

Well, I’ll consider it for the ruby2java’s companion project “siesta”.
If I remember it right, Charles want ruby2java be just the compiler,
without any sugar in it. I would like to hear from him on this subject
too.

Currently, three ways to use compiler are come up with in my mind.

The first plan is compile ruby2java itself by ruby2java so that Red
Bridge can invoke a compiler method in a Java way. Good side of this
plan is that the performance is not bad, and changes to ruby2java can
be reflected immediately. The problem is I couldn’t compile ruby2java
because of the error below:

One idea is wrong with this approach:

ruby2java does not create classes from scripts, in the sense that,
having a ruby2java script, you don’t get a Java class with, for
example, a main method that runs it. Consider jrubyc instead for this.
Furthermore, ruby2java will look for a Ruby2Java constant and take it
like a class (maybe we need to test it?). In this example, Ruby2Java
is a module and we do not compile neither modules nor just scripts,
just classes. Cannot figure out how it should work for modules, I’ll
think about it.

The third plan is to implement ruby2java in Java. This might be the
most effective for Red Bridge, but is not easy. Besides,
implementation in Java must catch up with the changes of ruby2java.

In any plan, compilation of a Java code that uses compiled Ruby
scripts might have a problem because *.class files are not exist
before Ruby scripts are dynamically compiled. Maybe a Java interface
helps to solve the problem.

Could you explain this a little bit more?

If somebody has opinions, ideas or thoughts, let me know about that.

I’m interested on it too.

Cheers,

Serabe


http://sergio.arbeo.net
http://www.serabe.com


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email