How can I disassemble Scala code? Can it be done without first building the Jar and decompiling the resulting .class files? Is there an alternative, faster way to do this?
For Python there is dis which can be used as follows:
def myfunc(alist):
return len(alist)
>>> dis.dis(myfunc)
2 0 LOAD_GLOBAL 0 (len)
3 LOAD_FAST 0 (alist)
6 CALL_FUNCTION 1
9 RETURN_VALUE
You know you can do this in the REPL:
scala> def foo[A](xs: Seq[A]) = xs.size
foo: [A](xs: Seq[A])Int
scala> :javap foo
Size 714 bytes
...
public <A extends java/lang/Object> int foo(scala.collection.Seq<A>);
flags: ACC_PUBLIC
Code:
stack=1, locals=2, args_size=2
0: aload_1
1: invokeinterface #20, 1 // InterfaceMethod scala/collection/Seq.size:()I
6: ireturn
...
You have crawl a bit through the output because it contains the outer module and many more information.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With