Typesafe ASM — problems solved?March 26th, 2008 | by Jevgeni Kabanov | |
OK, I think I managed to solve both the primitive and the double slot problem introduced in the previous post. Basically I introduced another parametrized class — InvokeBuilder, which builds method invocations. The example now looks like this:
-
ClassWriter cw = new ClassWriter(COMPUTE_MAXS);
-
-
new ClassBuilder(cw, V1_4, ACC_PUBLIC, “HelloWorld”, “java/lang/Object”, null)
-
.beginMethod(ACC_PUBLIC, “<init>”, void.class)
-
.loadVar0(Self.class)
-
.returnVoid()
-
.endMethod()
-
-
.push(0)
-
.returnVoid()
-
.endMethod();
Of course InvokeBuilder contains methods only for building invocation. The only inconvenience is that you have to specify parameters in reverse order to coincide with the way they are laid out on the stack. However it’s easy to add a bit of sugar for the most common cases.
Now all I have to do is overload the param() method for each primitive as well as make a paramTwoCell(), which consumes two stack slots (for long/double). Seems that only tedious work in implementing each and every instruction remains.
P.S. Thanks to Christian Vest Hansen for his input. It definitely helped me get this (last?) piece of the puzzle in place.