On Tue, 2006-10-10 at 23:09 +0900, Charles Oliver Nutter wrote:
> Ross Bamford wrote:
> > For anyone who's interested in this kind of stuff, I just uploaded my
> > pure-ruby toy JVM to Rubyforge. It's obviously very slow, but can be
> 
> I tried to play with it a bit but I don't have Classpath installed. Is 
> there a way to read in classes for inspection without Classpath?
> 

Sure is. This gets a dump of a class just as it's read in (before it's
resolved):

pp
Ruva::VM::Class::Reader.file("test/java_classes/TestFunctional10.class")

The unresolved class returned by Reader.file is visitable too - there's
a bit of a basic TraceClassVisitor in ruva/utils/class_visitor.rb but it
gives too much output most of the time...

If you're after the code, it's easier to get the class resolved or
you'll have to find the code attributes yourself, so try something like:

loader = Ruva::VM::ClassLoader.new(nil, 'test/java_classes')
# => #<Ruva::VM::ClassLoader:0xb7dac098 ... >

clz = loader.load_class('TestFunctional10')
# => TestFunctional10

clz.methods.each { |m| puts m; Ruva::Utils::CodeDumper.print(m.code) }
# public void <init>(int)
#   seq |     bytes      |        mnemonic | operands
# ----------------------------------------------------------
#     0 | 0x0000..0x0000 |         ALOAD_0 | []
#     1 | 0x0001..0x0003 |   INVOKESPECIAL | [0, 1]
#	[ ... etc ... ]

Also, have a look at the bottom of class_loader.rb and a few others,
there are small test programs there sometimes...

Hope that helps,
-- 
Ross Bamford - rosco / roscopeco.REMOVE.co.uk