Jrubyc AOT Java compilation fails

Hi,

I’m trying to compile a Ruby script to Java source code but the
compilation
fails with the following error message.
The same script successfully compiles to JVM bytecode.
Are there any known restrictions as to what kind of scripts can be
compiled
to Java?
I’ve tried reading the compiler page
JRubyCompiler · jruby/jruby Wiki · GitHub but it doesn’t seem to
contain any discussion on this matter.

Here’s the error message:

jrubyc --verbose --java ruby

Failure during compilation of file src/main/ruby/foo.rb:
org.jruby.parser.ParserSyntaxException: syntax error, unexpected
QUESTION
org/jruby/parser/JavaSignatureParser.java:324:in yyerror' org/jruby/parser/JavaSignatureParser.java:431:in yyparse’
org/jruby/parser/JavaSignatureParser.java:28:in parse' /Users/aspluma/projects/jruby/jruby-1.6.7/lib/ruby/site_ruby/shared/jruby/compiler/java_class.rb:142:in build_signature’
/Users/aspluma/projects/jruby/jruby-1.6.7/lib/ruby/site_ruby/shared/jruby/compiler/java_class.rb:219:in
ClassNodeWalker' org/jruby/RubyKernel.java:2045:in instance_eval’
/Users/aspluma/projects/jruby/jruby-1.6.7/lib/ruby/site_ruby/shared/jruby/compiler/java_class.rb:35:in
visit_args_node' /Users/aspluma/projects/jruby/jruby-1.6.7/lib/ruby/site_ruby/shared/jruby/compiler/java_class.rb:179:in with_node’
/Users/aspluma/projects/jruby/jruby-1.6.7/lib/ruby/site_ruby/shared/jruby/compiler/java_class.rb:34:in
visit_args_node' org/jruby/RubyProc.java:270:in call’
/Users/aspluma/projects/jruby/jruby-1.6.7/lib/ruby/site_ruby/shared/jruby/compiler/java_class.rb:231:in
ClassNodeWalker' org/jruby/RubyKernel.java:2045:in instance_eval’
/Users/aspluma/projects/jruby/jruby-1.6.7/lib/ruby/site_ruby/shared/jruby/compiler/java_class.rb:35:in
visit_defn_node' /Users/aspluma/projects/jruby/jruby-1.6.7/lib/ruby/site_ruby/shared/jruby/compiler/java_class.rb:179:in with_node’
/Users/aspluma/projects/jruby/jruby-1.6.7/lib/ruby/site_ruby/shared/jruby/compiler/java_class.rb:34:in
visit_defn_node' org/jruby/RubyProc.java:270:in call’
/Users/aspluma/projects/jruby/jruby-1.6.7/lib/ruby/site_ruby/shared/jruby/compiler/java_class.rb:263:in
ClassNodeWalker' org/jruby/RubyKernel.java:2045:in instance_eval’
/Users/aspluma/projects/jruby/jruby-1.6.7/lib/ruby/site_ruby/shared/jruby/compiler/java_class.rb:35:in
visit_newline_node' /Users/aspluma/projects/jruby/jruby-1.6.7/lib/ruby/site_ruby/shared/jruby/compiler/java_class.rb:179:in with_node’
/Users/aspluma/projects/jruby/jruby-1.6.7/lib/ruby/site_ruby/shared/jruby/compiler/java_class.rb:34:in
visit_newline_node' org/jruby/RubyProc.java:270:in call’
/Users/aspluma/projects/jruby/jruby-1.6.7/lib/ruby/site_ruby/shared/jruby/compiler/java_class.rb:259:in
ClassNodeWalker' /Users/aspluma/projects/jruby/jruby-1.6.7/lib/ruby/site_ruby/shared/builtin/java/java.util.rb:7:in each’
/Users/aspluma/projects/jruby/jruby-1.6.7/lib/ruby/site_ruby/shared/jruby/compiler/java_class.rb:259:in
ClassNodeWalker' org/jruby/RubyKernel.java:2045:in instance_eval’
/Users/aspluma/projects/jruby/jruby-1.6.7/lib/ruby/site_ruby/shared/jruby/compiler/java_class.rb:35:in
visit_block_node' /Users/aspluma/projects/jruby/jruby-1.6.7/lib/ruby/site_ruby/shared/jruby/compiler/java_class.rb:179:in with_node’
/Users/aspluma/projects/jruby/jruby-1.6.7/lib/ruby/site_ruby/shared/jruby/compiler/java_class.rb:34:in
visit_block_node' org/jruby/RubyProc.java:270:in call’
/Users/aspluma/projects/jruby/jruby-1.6.7/lib/ruby/site_ruby/shared/jruby/compiler/java_class.rb:225:in
ClassNodeWalker' org/jruby/RubyKernel.java:2045:in instance_eval’
/Users/aspluma/projects/jruby/jruby-1.6.7/lib/ruby/site_ruby/shared/jruby/compiler/java_class.rb:35:in
visit_class_node' /Users/aspluma/projects/jruby/jruby-1.6.7/lib/ruby/site_ruby/shared/jruby/compiler/java_class.rb:179:in with_node’
/Users/aspluma/projects/jruby/jruby-1.6.7/lib/ruby/site_ruby/shared/jruby/compiler/java_class.rb:34:in
visit_class_node' org/jruby/RubyProc.java:270:in call’
/Users/aspluma/projects/jruby/jruby-1.6.7/lib/ruby/site_ruby/shared/jruby/compiler/java_class.rb:263:in
ClassNodeWalker' org/jruby/RubyKernel.java:2045:in instance_eval’
/Users/aspluma/projects/jruby/jruby-1.6.7/lib/ruby/site_ruby/shared/jruby/compiler/java_class.rb:35:in
visit_newline_node' /Users/aspluma/projects/jruby/jruby-1.6.7/lib/ruby/site_ruby/shared/jruby/compiler/java_class.rb:179:in with_node’
/Users/aspluma/projects/jruby/jruby-1.6.7/lib/ruby/site_ruby/shared/jruby/compiler/java_class.rb:34:in
visit_newline_node' org/jruby/RubyProc.java:270:in call’
/Users/aspluma/projects/jruby/jruby-1.6.7/lib/ruby/site_ruby/shared/jruby/compiler/java_class.rb:259:in
ClassNodeWalker' /Users/aspluma/projects/jruby/jruby-1.6.7/lib/ruby/site_ruby/shared/builtin/java/java.util.rb:7:in each’
/Users/aspluma/projects/jruby/jruby-1.6.7/lib/ruby/site_ruby/shared/jruby/compiler/java_class.rb:259:in
ClassNodeWalker' org/jruby/RubyKernel.java:2045:in instance_eval’
/Users/aspluma/projects/jruby/jruby-1.6.7/lib/ruby/site_ruby/shared/jruby/compiler/java_class.rb:35:in
visit_block_node' /Users/aspluma/projects/jruby/jruby-1.6.7/lib/ruby/site_ruby/shared/jruby/compiler/java_class.rb:179:in with_node’
/Users/aspluma/projects/jruby/jruby-1.6.7/lib/ruby/site_ruby/shared/jruby/compiler/java_class.rb:34:in
visit_block_node' org/jruby/RubyProc.java:270:in call’
/Users/aspluma/projects/jruby/jruby-1.6.7/lib/ruby/site_ruby/shared/jruby/compiler/java_class.rb:270:in
ClassNodeWalker' org/jruby/RubyKernel.java:2045:in instance_eval’
/Users/aspluma/projects/jruby/jruby-1.6.7/lib/ruby/site_ruby/shared/jruby/compiler/java_class.rb:35:in
visit_root_node' /Users/aspluma/projects/jruby/jruby-1.6.7/lib/ruby/site_ruby/shared/jruby/compiler/java_class.rb:179:in with_node’
/Users/aspluma/projects/jruby/jruby-1.6.7/lib/ruby/site_ruby/shared/jruby/compiler/java_class.rb:34:in
visit_root_node' org/jruby/RubyProc.java:270:in call’
/Users/aspluma/projects/jruby/jruby-1.6.7/lib/ruby/site_ruby/shared/jruby/compiler/java_class.rb:8:in
generate_java' /Users/aspluma/projects/jruby/jruby-1.6.7/lib/ruby/site_ruby/shared/jruby/compiler.rb:138:in compile_files_with_options’
org/jruby/RubyProc.java:270:in call' org/jruby/RubyProc.java:220:in call’
/Users/aspluma/projects/jruby/jruby-1.6.7/lib/ruby/site_ruby/shared/jruby/compiler.rb:208:in
compile_files_with_options' org/jruby/RubyArray.java:1615:in each’
/Users/aspluma/projects/jruby/jruby-1.6.7/lib/ruby/site_ruby/shared/jruby/compiler.rb:207:in
compile_files_with_options' org/jruby/RubyArray.java:1615:in each’
/Users/aspluma/projects/jruby/jruby-1.6.7/lib/ruby/site_ruby/shared/jruby/compiler.rb:198:in
compile_files_with_options' /Users/aspluma/projects/jruby/jruby-1.6.7/lib/ruby/site_ruby/shared/jruby/compiler.rb:90:in compile_argv’
/Users/aspluma/projects/jruby/jruby-1.6.7/bin/jrubyc:5:in `(root)’
Compilation FAILED: 1 error(s) encountered

marko

Hi,

yes, there are a lot of restrictions. Everything what Ruby is capable
of,
but Java not.
For example, declaring Methods with an question mark. Java won’t allow
that.
That’s also what the error is trying to point out.
It would be great if the erroneous line would be indicated…somebody
should file a ticket for that ^^

Kind regards
Peter

2012/5/1 Marko A. [email protected]

Hi,

I’m having trouble identifying the erroneous line from the compiler
error output:
it doesn’t seem to include any reference to the script being compiled.
the verbose flag doesn’t seem to help.
How do I find out which line is causing the compiler to fail?

best regards,

marko

I think you won’t. Try to request this at http://jira.codehaus.org ,
maybe
they will add it.
What you can do is to refactor every method with a question mark.

2012/5/4 Marko A. [email protected]

filed an improvement request JRUBY-6643 for this.

thanks, marko