mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2025-01-03 05:44:10 -08:00
frontend: fix support of Integer.TYPE, Long.TYPE, etc.
This commit is contained in:
parent
ed7e8ff7f4
commit
8bfcb5f086
|
@ -263,6 +263,7 @@ public class JavaScriptTarget implements TeaVMTarget, TeaVMJavaScriptHost {
|
||||||
renderer.renderRuntime();
|
renderer.renderRuntime();
|
||||||
renderer.render(clsNodes);
|
renderer.render(clsNodes);
|
||||||
renderer.renderStringPool();
|
renderer.renderStringPool();
|
||||||
|
renderer.renderStringConstants();
|
||||||
for (Map.Entry<String, TeaVMEntryPoint> entry : controller.getEntryPoints().entrySet()) {
|
for (Map.Entry<String, TeaVMEntryPoint> entry : controller.getEntryPoints().entrySet()) {
|
||||||
sourceWriter.append("var ").append(entry.getKey()).ws().append("=").ws();
|
sourceWriter.append("var ").append(entry.getKey()).ws().append("=").ws();
|
||||||
MethodReference ref = entry.getValue().getReference();
|
MethodReference ref = entry.getValue().getReference();
|
||||||
|
|
|
@ -147,7 +147,7 @@ public class Renderer implements RenderingManager {
|
||||||
try {
|
try {
|
||||||
for (PostponedFieldInitializer initializer : postponedFieldInitializers) {
|
for (PostponedFieldInitializer initializer : postponedFieldInitializers) {
|
||||||
writer.appendStaticField(initializer.field).ws().append("=").ws()
|
writer.appendStaticField(initializer.field).ws().append("=").ws()
|
||||||
.append(constantToString(initializer.value)).append(";").softNewLine();
|
.append(context.constantToString(initializer.value)).append(";").softNewLine();
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RenderingException("IO error", e);
|
throw new RenderingException("IO error", e);
|
||||||
|
@ -331,7 +331,7 @@ public class Renderer implements RenderingManager {
|
||||||
}
|
}
|
||||||
FieldReference fieldRef = new FieldReference(cls.getName(), field.getName());
|
FieldReference fieldRef = new FieldReference(cls.getName(), field.getName());
|
||||||
if (value instanceof String) {
|
if (value instanceof String) {
|
||||||
constantToString(value);
|
context.constantToString(value);
|
||||||
postponedFieldInitializers.add(new PostponedFieldInitializer(fieldRef, (String) value));
|
postponedFieldInitializers.add(new PostponedFieldInitializer(fieldRef, (String) value));
|
||||||
value = null;
|
value = null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,6 @@ import org.teavm.model.Phi;
|
||||||
import org.teavm.model.PrimitiveType;
|
import org.teavm.model.PrimitiveType;
|
||||||
import org.teavm.model.Program;
|
import org.teavm.model.Program;
|
||||||
import org.teavm.model.ReferenceCache;
|
import org.teavm.model.ReferenceCache;
|
||||||
import org.teavm.model.TryCatchJoint;
|
|
||||||
import org.teavm.model.ValueType;
|
import org.teavm.model.ValueType;
|
||||||
import org.teavm.model.Variable;
|
import org.teavm.model.Variable;
|
||||||
import org.teavm.model.optimization.UnreachableBasicBlockEliminator;
|
import org.teavm.model.optimization.UnreachableBasicBlockEliminator;
|
||||||
|
@ -122,12 +121,10 @@ public class Parser {
|
||||||
debugNames = newDebugNames;
|
debugNames = newDebugNames;
|
||||||
}
|
}
|
||||||
for (Variable definedVar : defExtractor.getDefinedVariables()) {
|
for (Variable definedVar : defExtractor.getDefinedVariables()) {
|
||||||
/*
|
|
||||||
int sourceVar = phiUpdater.getSourceVariable(definedVar.getIndex());
|
int sourceVar = phiUpdater.getSourceVariable(definedVar.getIndex());
|
||||||
if (sourceVar >= 0) {
|
if (sourceVar >= 0) {
|
||||||
varMap.put(sourceVar, definedVar.getIndex());
|
varMap.put(sourceVar, definedVar.getIndex());
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
for (Map.Entry<Integer, String> debugName : debugNames.entrySet()) {
|
for (Map.Entry<Integer, String> debugName : debugNames.entrySet()) {
|
||||||
int receiver = varMap.getOrDefault(debugName.getKey(), -1);
|
int receiver = varMap.getOrDefault(debugName.getKey(), -1);
|
||||||
|
@ -175,12 +172,10 @@ public class Parser {
|
||||||
|
|
||||||
for (Phi phi : block.getPhis()) {
|
for (Phi phi : block.getPhis()) {
|
||||||
int receiver = phi.getReceiver().getIndex();
|
int receiver = phi.getReceiver().getIndex();
|
||||||
/*
|
|
||||||
int sourceVar = phiUpdater.getSourceVariable(receiver);
|
int sourceVar = phiUpdater.getSourceVariable(receiver);
|
||||||
if (sourceVar >= 0) {
|
if (sourceVar >= 0) {
|
||||||
varMap.put(sourceVar, receiver);
|
varMap.put(sourceVar, receiver);
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
result[node] = new IntIntOpenHashMap(varMap);
|
result[node] = new IntIntOpenHashMap(varMap);
|
||||||
|
@ -188,12 +183,10 @@ public class Parser {
|
||||||
for (Instruction insn : block.getInstructions()) {
|
for (Instruction insn : block.getInstructions()) {
|
||||||
insn.acceptVisitor(defExtractor);
|
insn.acceptVisitor(defExtractor);
|
||||||
for (Variable definedVar : defExtractor.getDefinedVariables()) {
|
for (Variable definedVar : defExtractor.getDefinedVariables()) {
|
||||||
/*
|
|
||||||
int sourceVar = phiUpdater.getSourceVariable(definedVar.getIndex());
|
int sourceVar = phiUpdater.getSourceVariable(definedVar.getIndex());
|
||||||
if (sourceVar >= 0) {
|
if (sourceVar >= 0) {
|
||||||
varMap.put(sourceVar, definedVar.getIndex());
|
varMap.put(sourceVar, definedVar.getIndex());
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1682,13 +1682,21 @@ public class ProgramParser {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Opcodes.GETSTATIC: {
|
case Opcodes.GETSTATIC: {
|
||||||
ValueType type = referenceCache.parseValueTypeCached(desc);
|
ValueType primitiveClassLiteral = getPrimitiveTypeField(owner + "." + name);
|
||||||
int value = desc.equals("D") || desc.equals("J") ? pushDouble() : pushSingle();
|
if (primitiveClassLiteral != null) {
|
||||||
GetFieldInstruction insn = new GetFieldInstruction();
|
ClassConstantInstruction insn = new ClassConstantInstruction();
|
||||||
insn.setField(referenceCache.getCached(new FieldReference(ownerCls, name)));
|
insn.setConstant(primitiveClassLiteral);
|
||||||
insn.setFieldType(type);
|
insn.setReceiver(getVariable(pushSingle()));
|
||||||
insn.setReceiver(getVariable(value));
|
addInstruction(insn);
|
||||||
addInstruction(insn);
|
} else {
|
||||||
|
ValueType type = referenceCache.parseValueTypeCached(desc);
|
||||||
|
int value = desc.equals("D") || desc.equals("J") ? pushDouble() : pushSingle();
|
||||||
|
GetFieldInstruction insn = new GetFieldInstruction();
|
||||||
|
insn.setField(referenceCache.getCached(new FieldReference(ownerCls, name)));
|
||||||
|
insn.setFieldType(type);
|
||||||
|
insn.setReceiver(getVariable(value));
|
||||||
|
addInstruction(insn);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Opcodes.PUTSTATIC: {
|
case Opcodes.PUTSTATIC: {
|
||||||
|
@ -1763,4 +1771,29 @@ public class ProgramParser {
|
||||||
throw new IllegalArgumentException("Unknown handle tag: " + handle.getTag());
|
throw new IllegalArgumentException("Unknown handle tag: " + handle.getTag());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static ValueType getPrimitiveTypeField(String fieldName) {
|
||||||
|
switch (fieldName) {
|
||||||
|
case "java/lang/Boolean.TYPE":
|
||||||
|
return ValueType.BOOLEAN;
|
||||||
|
case "java/lang/Byte.TYPE":
|
||||||
|
return ValueType.BYTE;
|
||||||
|
case "java/lang/Short.TYPE":
|
||||||
|
return ValueType.SHORT;
|
||||||
|
case "java/lang/Character.TYPE":
|
||||||
|
return ValueType.CHARACTER;
|
||||||
|
case "java/lang/Integer.TYPE":
|
||||||
|
return ValueType.INTEGER;
|
||||||
|
case "java/lang/Long.TYPE":
|
||||||
|
return ValueType.LONG;
|
||||||
|
case "java/lang/Float.TYPE":
|
||||||
|
return ValueType.FLOAT;
|
||||||
|
case "java/lang/Double.TYPE":
|
||||||
|
return ValueType.DOUBLE;
|
||||||
|
case "java/lang/Void.TYPE":
|
||||||
|
return ValueType.VOID;
|
||||||
|
default:
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user