[jruby] Compiling to bytecode w/ 9.0.4.0?

Thomas E Enebo tom.enebo at gmail.com
Mon Jan 25 22:46:56 JST 2016


If you leave off --java this will generate an AOT java class.  --java
cannot work because we cannot generate a method name containing '?' that is
valid java syntax.  Java bytecode format does not have this restriction
though.

-Tom


On Mon, Jan 25, 2016 at 5:48 AM, Hugh Sasse <hgs at dmu.ac.uk> wrote:

> [I sent this on Friday, but clearly it didn't actually leave here...]
> I can reproduce this with this:
>
>
> C:\hgs_documents\progs\jruby>type qmark.rb
> #
> # Test case with a ? method for Jruby
> #
>
> class Table < Hash
>   def has_key?(args)
>     if key.respond_to? :upcase
>       super key.upcase()
>     else
>       super
>     end
>   end
> end
>
>
>
> C:\hgs_documents\progs\jruby>jrubyc --java qmark.rb
> Unhandled Java exception: org.jruby.parser.ParserSyntaxException: syntax
> error,
> unexpected QUESTION
>
> org.jruby.parser.ParserSyntaxException: syntax error, unexpected QUESTION
>
>                       build_signature at
> C:/jruby-9.0.4.0/lib/ruby/stdlib/jruby/
> compiler/java_class.rb:142
>              block in ClassNodeWalker at
> C:/jruby-9.0.4.0/lib/ruby/stdlib/jruby/
> compiler/java_class.rb:228
>              block in visit_args_node at
> C:/jruby-9.0.4.0/lib/ruby/stdlib/jruby/
> compiler/java_class.rb:35
>                             with_node at
> C:/jruby-9.0.4.0/lib/ruby/stdlib/jruby/
> compiler/java_class.rb:188
>              block in visit_args_node at
> C:/jruby-9.0.4.0/lib/ruby/stdlib/jruby/
> compiler/java_class.rb:34
>                         visitArgsNode at
> JRuby$$Compiler$$ClassNodeWalker_385928
> 906.gen:13
>              block in ClassNodeWalker at
> C:/jruby-9.0.4.0/lib/ruby/stdlib/jruby/
> compiler/java_class.rb:240
>              block in visit_defn_node at
> C:/jruby-9.0.4.0/lib/ruby/stdlib/jruby/
> compiler/java_class.rb:35
>                             with_node at
> C:/jruby-9.0.4.0/lib/ruby/stdlib/jruby/
> compiler/java_class.rb:188
>              block in visit_defn_node at
> C:/jruby-9.0.4.0/lib/ruby/stdlib/jruby/
> compiler/java_class.rb:34
>                         visitDefnNode at
> JRuby$$Compiler$$ClassNodeWalker_385928
> 906.gen:13
>              block in ClassNodeWalker at
> C:/jruby-9.0.4.0/lib/ruby/stdlib/jruby/
> compiler/java_class.rb:234
>             block in visit_class_node at
> C:/jruby-9.0.4.0/lib/ruby/stdlib/jruby/
> compiler/java_class.rb:35
>                             with_node at
> C:/jruby-9.0.4.0/lib/ruby/stdlib/jruby/
> compiler/java_class.rb:188
>             block in visit_class_node at
> C:/jruby-9.0.4.0/lib/ruby/stdlib/jruby/
> compiler/java_class.rb:34
>                        visitClassNode at
> JRuby$$Compiler$$ClassNodeWalker_385928
> 906.gen:13
>              block in ClassNodeWalker at
> C:/jruby-9.0.4.0/lib/ruby/stdlib/jruby/
> compiler/java_class.rb:281
>              block in visit_root_node at
> C:/jruby-9.0.4.0/lib/ruby/stdlib/jruby/
> compiler/java_class.rb:35
>                             with_node at
> C:/jruby-9.0.4.0/lib/ruby/stdlib/jruby/
> compiler/java_class.rb:188
>              block in visit_root_node at
> C:/jruby-9.0.4.0/lib/ruby/stdlib/jruby/
> compiler/java_class.rb:34
>                         visitRootNode at
> JRuby$$Compiler$$ClassNodeWalker_385928
> 906.gen:13
>                         generate_java at
> C:/jruby-9.0.4.0/lib/ruby/stdlib/jruby/
> compiler/java_class.rb:8
>   block in compile_files_with_options at
> C:/jruby-9.0.4.0/lib/ruby/stdlib/jruby/
> compiler.rb:141
>   block in compile_files_with_options at
> C:/jruby-9.0.4.0/lib/ruby/stdlib/jruby/
> compiler.rb:291
>                                  each at org/jruby/RubyArray.java:1560
>            compile_files_with_options at
> C:/jruby-9.0.4.0/lib/ruby/stdlib/jruby/
> compiler.rb:275
>                          compile_argv at
> C:/jruby-9.0.4.0/lib/ruby/stdlib/jruby/
> compiler.rb:94
>                                 <top> at
> C_3a_/jruby_minus_9_dot_0_dot_4_dot_0/b
> in/C:/jruby-9.0.4.0/bin/jrubyc:5
>
> C:\hgs_documents\progs\jruby>jruby --version
> jruby 9.0.4.0 (2.2.2) 2015-11-12 b9fb7aa Java HotSpot(TM) Client VM
> 25.71-b15 on
>  1.8.0_71-b15 +jit [Windows 7-x86]
>
> C:\hgs_documents\progs\jruby>
>
>
> As I said, I think I'm probably taking the wrong approach to this,
> but can't find the correct approach so far...
>
> Thank you,
> Hugh.
>
>
> On 21/01/2016 21:49, Christian MICHON wrote:
> > What exact set of commands did you use to compile to bytecode?
> >
> > Please share some code not compiling properly, even a 1 or 2 liners will
> > suffice.
> >
> > On Thu, Jan 21, 2016 at 2:13 PM, Hugh Sasse <hgs at dmu.ac.uk
> > <mailto:hgs at dmu.ac.uk>> wrote:
> >
> >     Hello,
> >     I'm using JRuby 9.0.4.0 on Windows 32 bit.
> >     I have not got any further with trying to get my code compiled to an
> >     executable jar file.  I have worked around my subclass of Hash
> >     needing the []() and []=() methods using fetch() and store() instead.
> >     However, has_key?() has me stumped, because jrubyc gives me
> >     errors relating to the unexpected '?' character, which cannot be
> >     name mangled into Java.  My attempts to solve this run into using
> >     things like member? which would need to be redefined.
> >
> >     I read on https://github.com/jruby/jruby/wiki/JRubyCompiler
> >     that :
> >     """As of late September 2007, the JRuby compiler is considered
> >     complete. Any features missing are to be considered bugs. As part of
> >     JRuby's test run, the entire Ruby standard library is compiled to
> >     Java bytecode."""
> >
> >     So, since I can't seem to use functions called member? or has_key?
> >     or include?,
> >     but the ones in the standard library are being used and converted
> >     into bytecode
> >     successfully, I am obviously doing this incorrectly.  My ability to
> >     find the correct
> >     way to do this by searching the web appears inadequate as well.
> >
> >     So my question is, what should I have read that tells me how to get
> >     these methods
> >     that I redefine myself into bytecode, and thus into an executable
> >     jar file, please?
> >
> >     Thank you,
> >     Hugh
> >
> >
> >
> >
> >
> > --
> > Christian
>
>
>


-- 
blog: http://blog.enebo.com       twitter: tom_enebo
mail: tom.enebo at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ruby-lang.org/pipermail/jruby/attachments/20160125/1f5a2db1/attachment-0001.html>


More information about the JRuby mailing list