Re: Using asm from jruby

Charles Oliver Nutter <[email protected]>
Newsgroups gmane.comp.java.objectweb.asm
Message-ID <[email protected]>
Have you seen my BiteScript toolkit? It is a JRuby DSL around ASM.

http://github.com/headius/bitescript

I believe there are a few languages (including Mirah) using it for their JVM backend.

- Charlie (mobile)

On Sep 23, 2011, at 15:32, <[email protected]> wrote:

> I'm a novice asm user, and I've been using jruby for a long time.  When I
> started using asm, it seemed like there might be some things that would be
> simpler in jruby than in Java.
> 
> If you haven't played with asm + jruby, take a look.  You can do some
> interesting things with not much code.    For example, here's the jruby to visit
> a set of class files (given on the command line), printing out every call to
> visit*:
> 
> (You'll need to specify a -I option to tell jruby where to find the asm-3.3.1
> jar - in my case: jruby -I /Users/james/experimements/AsmSample/libs
> SomeFile.class)
> 
> require 'java'
> require 'asm-3.3.1'
> 
> # This lets me type org.objectweb.asm::... instead of
> Java::OrgObjectwebAsm::...
> def org
>  Java::Org
> end
> 
> class SampleVisitor
>  include org.objectweb.asm::MethodVisitor
>  include org.objectweb.asm::ClassVisitor
>  include org.objectweb.asm::FieldVisitor
>  include org.objectweb.asm::AnnotationVisitor
>  include org.objectweb.asm.signature::SignatureVisitor
> 
>  def method_missing name, *args
>    name_string = name.to_s
>    if name_string =~ /visit.*/
>      puts "#{name}\t#{args}"
>      self
>    else
>      super
>    end
>  end
> end
> 
> # Loop through each .class file given on the command line
> ARGV.each do |classfile|
>  puts " ---------------- Reading file #{classfile}"
>  f = java.io.File.new classfile
>  fis = java.io.FileInputStream.new f
> 
>  class_reader = org.objectweb.asm::ClassReader.new fis
> 
>  v = SampleVisitor.new
> 
>  class_reader.accept v, 0
> 
>  puts
> end
> 
> -- 
> James Moore
> [email protected]
> http://blog.restphone.com/
> 
> -- 
> You receive this message as a subscriber of the [email protected] mailing list.
> To unsubscribe: mailto:[email protected]
> For general help: mailto:[email protected]?subject=help
> OW2 mailing lists service home page: http://www.ow2.org/wws
message-footer.txt (text/plain, 238 B)
-- 
You receive this message as a subscriber of the [email protected] mailing list.
To unsubscribe: mailto:[email protected]
For general help: mailto:[email protected]?subject=help
OW2 mailing lists service home page: http://www.ow2.org/wws
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.