Alright, I've done a bit more research from the JRuby end of things. It looks like this challenge shares some similarity to bringing JRuby to J2ME (java micro edition): for example, both omit reflection. As luck would have it, some work has been done here, but unfortunately just enough to show what would need to be done.
Apparently there are two possible java specs, CDC and CLDC. CLDC is the more basic, with essential File io and not a whole lot else, whereas CDC is the more useful. In 2007, Roy Ben Hayun did some work on discovering what would be required to put this together. This is based on very old versions on JRuby (0.8.2, as opposed to the current: 1.7)
http://www.slideshare.net/pehrlich/intr ... -to-jrubmehttps://github.com/jruby/jruby/wiki/JRu ... croEditionhttp://www.coderanch.com/t/272622/java/ ... ReflectionIn 2009, this project was revitalized in a blog post by Charles Nutter, one of the JRuby core team members. This is off a fork of JRuby 0.9.8.
CDC is probably about the smallest ME profile JRuby could reasonably run in, since anything lower (like CLDC, the Connected Limited Device Configuration) and you're reduced to the most basic collections, IO, and utility APIs.
http://blog.headius.com/2009/02/jruby-on-java-me.htmlhttps://github.com/headius/jruby-cdchttps://github.com/headius/jruby-cdc/commits/masterSeeing this, my question is how close LeJos is to the Java ME-CDC spec (
http://en.wikipedia.org/wiki/Connected_ ... figuration). If it is close, I might ask some of the JRuby team members about the status of the project, and if there's any lingering interest or updates. Perhaps a more universal solution would be applicable in other situations, and get demand & support accordingly.
There was some other interesting reading as well:
http://kenai.com/projects/jruby/pages/JRubyCompilerDirect Invocation, Binding Into the MOP, and Reflection
Only class bodies, rescue/ensure bodies, and chained top-level script methods get directly invoked during script execution. The others are bound into the MetaObject Protocol (MOP) at runtime.
Binding occurs in one of two ways:
- By generating a small stub class that implements DynamicMethod and invokes the target method on the target script directly
- By doing the same with reflection
Finally, how did you get the printout of java bytecode in your previous post? Here's what I got:
- Code: Select all
$ javap -c Index.rb
ERROR:Could not find Index.rb
I did find an online class decompiler, which resulted in this code. (Which more or less matches the description given in the JRubyCompiler link above)
- Code: Select all
// Mobilefish.com Online Java Class Decompiler
// Author: Robert Lie
// Version: 0.1 (pre-alpha)
// http://www.mobilefish.com/services/java_decompiler/java_decompiler.php
// JVM version: 50.0
// File: Index.rb
import java.net.URL;
import org.jcodings.Encoding;
import org.jruby.Ruby;
import org.jruby.RubyClass;
import org.jruby.RubyInstanceConfig;
import org.jruby.RubyModule;
import org.jruby.RubyString;
import org.jruby.ast.executable.AbstractScript;
import org.jruby.ast.executable.RuntimeCache;
import org.jruby.internal.runtime.methods.CallConfiguration;
import org.jruby.javasupport.util.RuntimeHelpers;
import org.jruby.parser.StaticScope;
import org.jruby.runtime.Arity;
import org.jruby.runtime.Block;
import org.jruby.runtime.CallSite;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;
public class Index extends AbstractScript {
private static void setPosition(ThreadContext, int)
public Index ()
public static IRubyObject __file__(Index, ThreadContext, IRubyObject, IRubyObject[], Block)
public IRubyObject __file__(ThreadContext, IRubyObject, IRubyObject[], Block)
public static IRubyObject class_0$RUBY$Index(Index, ThreadContext, IRubyObject, Block)
public static IRubyObject method__1$RUBY$main(Index, ThreadContext, IRubyObject, IRubyObject, Block)
public static IRubyObject method__1$RUBY$main(Index, ThreadContext, IRubyObject, IRubyObject[], Block)
public static IRubyObject class_0$RUBY$Index(Index, ThreadContext, IRubyObject, IRubyObject[], Block)
public IRubyObject load(ThreadContext, IRubyObject, boolean)
public static void main(String[])
}
I guess its not valid Java though, because I tried then compiling this with nxjc, and got about 20 errors like this:
- Code: Select all
index.java:29: <identifier> expected
private static void setPosition(ThreadContext, int)
Thoughts on this?
Cheers!
--Peter