forked from JavaTX/JavaCompilerCore
Fix some type conversions
This commit is contained in:
parent
a660d7a295
commit
b4e1be0fb7
@ -58,8 +58,10 @@ public class Codegen {
|
|||||||
Scope scope = new Scope(null);
|
Scope scope = new Scope(null);
|
||||||
int localCounter;
|
int localCounter;
|
||||||
MethodVisitor mv;
|
MethodVisitor mv;
|
||||||
|
TargetType returnType;
|
||||||
|
|
||||||
State(MethodVisitor mv, int localCounter) {
|
State(TargetType returnType, MethodVisitor mv, int localCounter) {
|
||||||
|
this.returnType = returnType;
|
||||||
this.mv = mv;
|
this.mv = mv;
|
||||||
this.localCounter = localCounter;
|
this.localCounter = localCounter;
|
||||||
}
|
}
|
||||||
@ -832,13 +834,15 @@ public class Codegen {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case TargetFieldVar dot: {
|
case TargetFieldVar dot: {
|
||||||
|
var fieldType = dot.type();
|
||||||
generate(state, dot.left());
|
generate(state, dot.left());
|
||||||
generate(state, assign.right());
|
generate(state, assign.right());
|
||||||
boxPrimitive(state, assign.right().type());
|
convertTo(state, assign.right().type(), fieldType);
|
||||||
|
boxPrimitive(state, fieldType);
|
||||||
if (dot.isStatic())
|
if (dot.isStatic())
|
||||||
mv.visitInsn(DUP);
|
mv.visitInsn(DUP);
|
||||||
else mv.visitInsn(DUP_X1);
|
else mv.visitInsn(DUP_X1);
|
||||||
mv.visitFieldInsn(dot.isStatic() ? PUTSTATIC : PUTFIELD, dot.owner().getInternalName(), dot.right(), dot.type().toSignature());
|
mv.visitFieldInsn(dot.isStatic() ? PUTSTATIC : PUTFIELD, dot.owner().getInternalName(), dot.right(), fieldType.toSignature());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
@ -911,7 +915,8 @@ public class Codegen {
|
|||||||
case TargetReturn ret: {
|
case TargetReturn ret: {
|
||||||
if (ret.expression() != null) {
|
if (ret.expression() != null) {
|
||||||
generate(state, ret.expression());
|
generate(state, ret.expression());
|
||||||
boxPrimitive(state, ret.expression().type());
|
convertTo(state, ret.expression().type(), state.returnType);
|
||||||
|
boxPrimitive(state, state.returnType);
|
||||||
mv.visitInsn(ARETURN);
|
mv.visitInsn(ARETURN);
|
||||||
} else mv.visitInsn(RETURN);
|
} else mv.visitInsn(RETURN);
|
||||||
break;
|
break;
|
||||||
@ -975,7 +980,7 @@ public class Codegen {
|
|||||||
private void generateConstructor(TargetConstructor constructor) {
|
private void generateConstructor(TargetConstructor constructor) {
|
||||||
MethodVisitor mv = cw.visitMethod(constructor.access() | ACC_PUBLIC, "<init>", constructor.getDescriptor(), constructor.getSignature(), null);
|
MethodVisitor mv = cw.visitMethod(constructor.access() | ACC_PUBLIC, "<init>", constructor.getDescriptor(), constructor.getSignature(), null);
|
||||||
mv.visitCode();
|
mv.visitCode();
|
||||||
var state = new State(mv, 1);
|
var state = new State(null, mv, 1);
|
||||||
for (var param: constructor.parameters())
|
for (var param: constructor.parameters())
|
||||||
state.createVariable(param.name(), param.type());
|
state.createVariable(param.name(), param.type());
|
||||||
|
|
||||||
@ -999,7 +1004,7 @@ public class Codegen {
|
|||||||
// TODO The older codegen has set ACC_PUBLIC for all methods, good for testing but bad for everything else
|
// TODO The older codegen has set ACC_PUBLIC for all methods, good for testing but bad for everything else
|
||||||
MethodVisitor mv = cw.visitMethod(method.access() | ACC_PUBLIC, method.name(), method.getDescriptor(), method.getSignature(), null);
|
MethodVisitor mv = cw.visitMethod(method.access() | ACC_PUBLIC, method.name(), method.getDescriptor(), method.getSignature(), null);
|
||||||
mv.visitCode();
|
mv.visitCode();
|
||||||
var state = new State(mv, method.isStatic() ? 0 : 1);
|
var state = new State(method.returnType(), mv, method.isStatic() ? 0 : 1);
|
||||||
for (var param: method.parameters())
|
for (var param: method.parameters())
|
||||||
state.createVariable(param.name(), param.type());
|
state.createVariable(param.name(), param.type());
|
||||||
generate(state, method.block());
|
generate(state, method.block());
|
||||||
|
0
src/test/resources/bytecode/javFiles/Box.java
Normal file
0
src/test/resources/bytecode/javFiles/Box.java
Normal file
Loading…
Reference in New Issue
Block a user