mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 00:04:10 -08:00
wasm gc: fix issues in Java 17 switch expression and metaprogramming API
This commit is contained in:
parent
f85aa977eb
commit
f8022f9465
|
@ -134,7 +134,7 @@ public class WasmGCClassGenerator implements WasmGCClassInfoProvider, WasmGCInit
|
||||||
private int classNameOffset;
|
private int classNameOffset;
|
||||||
private int classSimpleNameOffset;
|
private int classSimpleNameOffset;
|
||||||
private int classCanonicalNameOffset;
|
private int classCanonicalNameOffset;
|
||||||
private int classParentOffset;
|
private int classParentOffset = -1;
|
||||||
private int classArrayOffset;
|
private int classArrayOffset;
|
||||||
private int classArrayItemOffset;
|
private int classArrayItemOffset;
|
||||||
private int classNewArrayOffset;
|
private int classNewArrayOffset;
|
||||||
|
@ -1438,12 +1438,14 @@ public class WasmGCClassGenerator implements WasmGCClassInfoProvider, WasmGCInit
|
||||||
classTagOffset,
|
classTagOffset,
|
||||||
new WasmInt32Constant(0)
|
new WasmInt32Constant(0)
|
||||||
));
|
));
|
||||||
|
if (classParentOffset >= 0) {
|
||||||
function.getBody().add(new WasmStructSet(
|
function.getBody().add(new WasmStructSet(
|
||||||
standardClasses.classClass().getStructure(),
|
standardClasses.classClass().getStructure(),
|
||||||
new WasmGetLocal(targetVar),
|
new WasmGetLocal(targetVar),
|
||||||
classParentOffset,
|
classParentOffset,
|
||||||
new WasmGetGlobal(standardClasses.objectClass().pointer)
|
new WasmGetGlobal(standardClasses.objectClass().pointer)
|
||||||
));
|
));
|
||||||
|
}
|
||||||
return function;
|
return function;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -480,9 +480,10 @@ public class WasmGCGenerationVisitor extends BaseWasmGenerationVisitor {
|
||||||
canInsertCast = false;
|
canInsertCast = false;
|
||||||
} else if (!sourceStruct.isSupertypeOf(targetStruct)) {
|
} else if (!sourceStruct.isSupertypeOf(targetStruct)) {
|
||||||
var block = new WasmBlock(false);
|
var block = new WasmBlock(false);
|
||||||
|
block.setType(targetType);
|
||||||
block.setLocation(expr.getLocation());
|
block.setLocation(expr.getLocation());
|
||||||
block.getBody().add(result);
|
block.getBody().add(new WasmDrop(result));
|
||||||
block.getBody().add(new WasmUnreachable());
|
block.getBody().add(new WasmNullConstant(targetType));
|
||||||
result = block;
|
result = block;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -878,7 +878,15 @@ public class CompositeMethodGenerator {
|
||||||
case "get": {
|
case "get": {
|
||||||
Variable var = program.createVariable();
|
Variable var = program.createVariable();
|
||||||
GetFieldInstruction insn = new GetFieldInstruction();
|
GetFieldInstruction insn = new GetFieldInstruction();
|
||||||
insn.setInstance(!field.field.hasModifier(ElementModifier.STATIC) ? var(arguments.get(0)) : null);
|
if (!field.field.hasModifier(ElementModifier.STATIC)) {
|
||||||
|
var cast = new CastInstruction();
|
||||||
|
cast.setReceiver(program.createVariable());
|
||||||
|
cast.setValue(var(arguments.get(0)));
|
||||||
|
cast.setWeak(true);
|
||||||
|
cast.setTargetType(ValueType.object(field.field.getOwnerName()));
|
||||||
|
add(cast);
|
||||||
|
insn.setInstance(cast.getReceiver());
|
||||||
|
}
|
||||||
insn.setReceiver(var);
|
insn.setReceiver(var);
|
||||||
insn.setField(field.getBackingField().getReference());
|
insn.setField(field.getBackingField().getReference());
|
||||||
insn.setFieldType(field.getBackingField().getType());
|
insn.setFieldType(field.getBackingField().getType());
|
||||||
|
@ -895,7 +903,15 @@ public class CompositeMethodGenerator {
|
||||||
}
|
}
|
||||||
case "set": {
|
case "set": {
|
||||||
PutFieldInstruction insn = new PutFieldInstruction();
|
PutFieldInstruction insn = new PutFieldInstruction();
|
||||||
insn.setInstance(!field.field.hasModifier(ElementModifier.STATIC) ? var(arguments.get(0)) : null);
|
if (!field.field.hasModifier(ElementModifier.STATIC)) {
|
||||||
|
var cast = new CastInstruction();
|
||||||
|
cast.setReceiver(program.createVariable());
|
||||||
|
cast.setValue(var(arguments.get(0)));
|
||||||
|
cast.setWeak(true);
|
||||||
|
cast.setTargetType(ValueType.object(field.field.getOwnerName()));
|
||||||
|
add(cast);
|
||||||
|
insn.setInstance(cast.getReceiver());
|
||||||
|
}
|
||||||
insn.setValue(unbox(var(arguments.get(1)), field.getBackingField().getType()));
|
insn.setValue(unbox(var(arguments.get(1)), field.getBackingField().getType()));
|
||||||
insn.setField(field.getBackingField().getReference());
|
insn.setField(field.getBackingField().getReference());
|
||||||
insn.setFieldType(field.getBackingField().getType());
|
insn.setFieldType(field.getBackingField().getType());
|
||||||
|
@ -930,7 +946,15 @@ public class CompositeMethodGenerator {
|
||||||
switch (method.getName()) {
|
switch (method.getName()) {
|
||||||
case "invoke": {
|
case "invoke": {
|
||||||
InvokeInstruction insn = new InvokeInstruction();
|
InvokeInstruction insn = new InvokeInstruction();
|
||||||
insn.setInstance(!Modifier.isStatic(reflectMethod.getModifiers()) ? var(arguments.get(0)) : null);
|
if (!Modifier.isStatic(reflectMethod.getModifiers())) {
|
||||||
|
var cast = new CastInstruction();
|
||||||
|
cast.setReceiver(program.createVariable());
|
||||||
|
cast.setValue(var(arguments.get(0)));
|
||||||
|
cast.setWeak(true);
|
||||||
|
cast.setTargetType(ValueType.object(reflectMethod.method.getOwnerName()));
|
||||||
|
add(cast);
|
||||||
|
insn.setInstance(cast.getReceiver());
|
||||||
|
}
|
||||||
insn.setType(Modifier.isStatic(reflectMethod.getModifiers()) ? InvocationType.SPECIAL
|
insn.setType(Modifier.isStatic(reflectMethod.getModifiers()) ? InvocationType.SPECIAL
|
||||||
: InvocationType.VIRTUAL);
|
: InvocationType.VIRTUAL);
|
||||||
insn.setMethod(reflectMethod.method.getReference());
|
insn.setMethod(reflectMethod.method.getReference());
|
||||||
|
|
Loading…
Reference in New Issue
Block a user