I'm writing a compiler to compile a subset of Java to Java bytecode using the Jasmin assembler
I'm having trouble with the 'l2d' instruction (and related ones - but I think they will all work once I have figured out why this one isn't working).
Instruction Reference:
http://cs.au.dk/~mis/dOvs/jvmspec/ref-_l2d.html
The code I'm compiling is:
{
double d = 10L;
}
So essentially I'm trying to mirror the way that javac does implicit type conversions between primitive numerical types.
The output Jasmin assembly code is:
.source test3.jml
.class Test3
.super java/lang/Object
.method public static main([Ljava/lang/String;)V
.limit stack 10
.limit locals 100
ldc2_w 10 ;Load constant numerical value 10
l2d ;Convert left hand side to match the type of the right
dstore 0 ;Store top of stack in 0 (d)
.end method
The important lines which are the three before .end method
.
Text after ';' is a comment.
The exact error I get when I try and run the compiled code is:
Exception in thread "main" java.lang.VerifyError:(class: Test3, method: main signature: ([java/lang/String;)V) Attempt to split long or double on the stack
Could not find the main class: Test3. Program will exit.
I reckon it must be something to do with the fact that longs and doubles take up 2 slots on the stack and 2 local variables (explained here), it still perplexes me though.