mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-21 16:04:09 -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 classSimpleNameOffset;
|
||||
private int classCanonicalNameOffset;
|
||||
private int classParentOffset;
|
||||
private int classParentOffset = -1;
|
||||
private int classArrayOffset;
|
||||
private int classArrayItemOffset;
|
||||
private int classNewArrayOffset;
|
||||
|
@ -1438,12 +1438,14 @@ public class WasmGCClassGenerator implements WasmGCClassInfoProvider, WasmGCInit
|
|||
classTagOffset,
|
||||
new WasmInt32Constant(0)
|
||||
));
|
||||
function.getBody().add(new WasmStructSet(
|
||||
standardClasses.classClass().getStructure(),
|
||||
new WasmGetLocal(targetVar),
|
||||
classParentOffset,
|
||||
new WasmGetGlobal(standardClasses.objectClass().pointer)
|
||||
));
|
||||
if (classParentOffset >= 0) {
|
||||
function.getBody().add(new WasmStructSet(
|
||||
standardClasses.classClass().getStructure(),
|
||||
new WasmGetLocal(targetVar),
|
||||
classParentOffset,
|
||||
new WasmGetGlobal(standardClasses.objectClass().pointer)
|
||||
));
|
||||
}
|
||||
return function;
|
||||
}
|
||||
|
||||
|
|
|
@ -480,9 +480,10 @@ public class WasmGCGenerationVisitor extends BaseWasmGenerationVisitor {
|
|||
canInsertCast = false;
|
||||
} else if (!sourceStruct.isSupertypeOf(targetStruct)) {
|
||||
var block = new WasmBlock(false);
|
||||
block.setType(targetType);
|
||||
block.setLocation(expr.getLocation());
|
||||
block.getBody().add(result);
|
||||
block.getBody().add(new WasmUnreachable());
|
||||
block.getBody().add(new WasmDrop(result));
|
||||
block.getBody().add(new WasmNullConstant(targetType));
|
||||
result = block;
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -878,7 +878,15 @@ public class CompositeMethodGenerator {
|
|||
case "get": {
|
||||
Variable var = program.createVariable();
|
||||
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.setField(field.getBackingField().getReference());
|
||||
insn.setFieldType(field.getBackingField().getType());
|
||||
|
@ -895,7 +903,15 @@ public class CompositeMethodGenerator {
|
|||
}
|
||||
case "set": {
|
||||
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.setField(field.getBackingField().getReference());
|
||||
insn.setFieldType(field.getBackingField().getType());
|
||||
|
@ -930,7 +946,15 @@ public class CompositeMethodGenerator {
|
|||
switch (method.getName()) {
|
||||
case "invoke": {
|
||||
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
|
||||
: InvocationType.VIRTUAL);
|
||||
insn.setMethod(reflectMethod.method.getReference());
|
||||
|
|
Loading…
Reference in New Issue
Block a user